From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A08633858C3A; Mon, 27 Sep 2021 10:37:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A08633858C3A From: "jlegg at feralinteractive dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102496] New: [11 regression] extern __thread declaration in function scope produces a non-TLS reference Date: Mon, 27 Sep 2021 10:37:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jlegg at feralinteractive dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2021 10:37:26 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102496 Bug ID: 102496 Summary: [11 regression] extern __thread declaration in function scope produces a non-TLS reference Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jlegg at feralinteractive dot com Target Milestone: --- A variable declaration inside a function body qualified with extern and __thread appears to ignore the __thread qualification when compiling c++. For example: Contents of test1.cc: extern __thread int thing; __thread int thing =3D 0; Contents of test2.cc: int main() { extern __thread int thing; return thing; } When invoking g++ 11.2.0 with arguments test1.cc test2.cc, I get the follow= ing output: /usr/local/bin/ld: thing: TLS definition in /tmp/ccXxZiSY.o section .tbss mismatches non-TLS reference in /tmp/ccYXyoSR.o /usr/local/bin/ld: /tmp/ccYXyoSR.o: error adding symbols: bad value collect2: error: ld returned 1 exit status If the example code was instead in files with a .c extension and compiled w= ith gcc (as opposed to g++) 11.2.0, it does not produce an error. I also could = not reproduce the error with g++ 10.2.0. The options I used when configuring GCC are: --prefix=3D/usr --program-suffix=3D-11.2 --libexecdir=3D/usr/lib --with-gxx-include-dir=3D/usr/include/c++/11.2 --libdir=3D/usr/lib --with-tune=3Dgeneric --enable-checking=3Drelease --disable-multilib --enable-languages=3Dc,c++ --build=3Dx86_64-linux-gnu --target=3Dx86_64-lin= ux-gnu --enable-linker-build-id --enable-version-specific-runtime-libs It is possible to work around the issue by moving or copying the variable declaration to namespace scope.=