From nobody Wed Feb 14 08:21:13 2024 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TZWP663m2z5BNYH for ; Wed, 14 Feb 2024 08:21:14 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TZWP62XYTz44F4 for ; Wed, 14 Feb 2024 08:21:14 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707898874; a=rsa-sha256; cv=none; b=dvEzBQcCNMjOKogwMBQoKjBdR+A0XPUBHkaFVXfWfrc4LRA4eqvBOmtc0ZLx0avVDSqwlE JvDbgN38jljymVCoTlMIfqR9PSeNRJB9DlpZzyVdZfbLT3QxPVZ37i9QczD6P/fxq41nVR 0e36ljwnmglSquZLOfyloq73TQco/4IJqJ89u0Gd3zAJ4lEj38ecwa3mzWjuA/Dw5RlXQ/ EM3sff0AP4JQmCvyHvVzYOjo5Zwv265YeH6ZUZFCm2+NUqyByaWeCWy5BqIXQ3QP4lCgr6 tjdzPWt8//7B/jBFIsOZMLJUUJFS7fQ442FZqVU2a7i+dATL3AfeB5Y2VDjmQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707898874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7qo05FTkYK71M9BHc0FMT8vWbkCR8+8AQNsXckUeniE=; b=omUlbO5s3c3BFXHr6y2iFFNxHG1TfIjlFLD4H+cRmgMZGZ1YQ/mXL0kI+1a61rFyE8C7Ub MXLdHVFM+0Sd+fZz3eUb3PVbMjDc5kQpilN4cF3Zt1zLR9Clk2Tw3L7YrmPYxIBnb71SIS LhdZWPIQX22suS+psDWS9Sf13uuKOxur469cF1JFGQgiFW7Qgqd+bVHQ+UkKzCn0QPgvzz r11Pe57t4yaRpUCmsGWWkn3Gxv87yuU1yMNuH9dUrp4EbOF7YVIbSD+KFoDb2gqeStJQwI 5g/hThrzuyzn95KpyFO+NB8RDlwoAMJZ5fvaip27zKUbGArYEjZ5KxCly8BD8Q== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TZWP60lYtzr8J for ; Wed, 14 Feb 2024 08:21:14 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 41E8LE4s031305 for ; Wed, 14 Feb 2024 08:21:14 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 41E8LEe5031304 for bugs@FreeBSD.org; Wed, 14 Feb 2024 08:21:14 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 277047] /usr/lib/libcompiler_rt.a(atomic.o) hidden visibility causes non-atomic atomics Date: Wed, 14 Feb 2024 08:21:13 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: misc X-Bugzilla-Version: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: i@maskray.me X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D277047 Bug ID: 277047 Summary: /usr/lib/libcompiler_rt.a(atomic.o) hidden visibility causes non-atomic atomics Product: Base System Version: Unspecified Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: misc Assignee: bugs@FreeBSD.org Reporter: i@maskray.me lib/libcompiler_rt/ builds llvm-project/compiler-rt including atomics (for = arm there is additional sys/arm/arm/stdatomic.c). Many packages have a dependency on lib/libcompiler_rt. lib/libcompiler_rt is installed to /usr/lib/libcompiler_rt.a.=20 The symbols are hidden, which usually lead to benign ODR violations if both= an executable and its DT_NEEDED get a copy of libcompiler_rt.a.=20 However, atomic.o has a global lock pool, and having different lock pools w= ould lead to non-synchronized atomic operations. Prepare input files as attached at the end of this post. % zsh a.sh /tmp/b-9aaa82.o: reference to __atomic_compare_exchange /usr/lib/libcompiler_rt.a(atomic.o): definition of __atomic_compare_exchange /tmp/a-864004.o: reference to __atomic_compare_exchange /usr/lib/libcompiler_rt.a(atomic.o): definition of __atomic_compare_exchange 9470401 /tmp/b-28139a.o: reference to __atomic_compare_exchange /usr/lib/libgcc.a(atomic.o): definition of __atomic_compare_exchange /tmp/a-1dceb9.o: reference to __atomic_compare_exchange /usr/lib/libgcc.a(atomic.o): definition of __atomic_compare_exchange 9481088 The expected result is 10000000. libgcc.a has the same issue. In practice it is extremely rare when two pieces of code operating on the s= ame atomic lives in different link units. --- cat > a.cc <<'eof' #include #include #include #include using namespace std; #define REP(i, n) for (int i =3D 0; i < (n); i++) constexpr int kIterations =3D 500'000; __int128_t g; void loop_b(); void loop_a() { REP(i, kIterations) { for(;;) { auto e =3D __atomic_load_n(&g, __ATOMIC_RELAXED), desired =3D e+1; if (__atomic_compare_exchange_n(&g, &e, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED)) break; } } } int main() { vector ts; REP(i, 10) ts.emplace_back(loop_a), ts.emplace_back(loop_b); for (auto &t : ts) t.join(); cout << (int64_t)g << '\n'; } eof cat > a.sh <<'eof' clang++ -O1 -fpic -Wno-atomic-alignment b.cc -shared -lcompiler_rt -o b.so -Wl,-y,__atomic_compare_exchange clang++ -O1 -Wno-atomic-alignment a.cc ./b.so -lcompiler_rt -pthread -o a -Wl,-y,__atomic_compare_exchange ./a clang++ -O1 -fpic -Wno-atomic-alignment b.cc -shared -o b.gcc.so -Wl,-y,__atomic_compare_exchange clang++ -O1 -Wno-atomic-alignment a.cc ./b.gcc.so -pthread -o a.gcc -Wl,-y,__atomic_compare_exchange ./a.gcc eof cat > b.cc <<'eof' #define REP(i, n) for (int i =3D 0; i < (n); i++) extern __int128_t g; constexpr int kIterations =3D 500'000; void loop_b() { REP(i, kIterations) { for(;;) { auto e =3D __atomic_load_n(&g, __ATOMIC_RELAXED); auto desired =3D e + 1; if (__atomic_compare_exchange_n(&g, &e, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED)) break; } } } eof --=20 You are receiving this mail because: You are the assignee for the bug.=