public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102496] New: [11 regression] extern __thread declaration in function scope produces a non-TLS reference
@ 2021-09-27 10:37 jlegg at feralinteractive dot com
  2021-09-27 10:43 ` [Bug c++/102496] [11/12 " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jlegg at feralinteractive dot com @ 2021-09-27 10:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102496

            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 = 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 following
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 with
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=/usr
--program-suffix=-11.2 --libexecdir=/usr/lib
--with-gxx-include-dir=/usr/include/c++/11.2 --libdir=/usr/lib
--with-tune=generic --enable-checking=release --disable-multilib
--enable-languages=c,c++ --build=x86_64-linux-gnu --target=x86_64-linux-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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-10-12  9:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 10:37 [Bug c++/102496] New: [11 regression] extern __thread declaration in function scope produces a non-TLS reference jlegg at feralinteractive dot com
2021-09-27 10:43 ` [Bug c++/102496] [11/12 " pinskia at gcc dot gnu.org
2021-09-27 10:52 ` [Bug c++/102496] [11/12 regression] extern __thread and thread_local " pinskia at gcc dot gnu.org
2021-09-28  8:32 ` rguenth at gcc dot gnu.org
2021-09-28 14:31 ` jakub at gcc dot gnu.org
2021-09-28 14:38 ` jakub at gcc dot gnu.org
2021-10-01  8:31 ` cvs-commit at gcc dot gnu.org
2021-10-01 12:39 ` [Bug c++/102496] [11 " jakub at gcc dot gnu.org
2021-10-05 20:30 ` cvs-commit at gcc dot gnu.org
2021-10-12  9:55 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).