public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jlegg at feralinteractive dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-102496-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-09-27 10:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 10:37 jlegg at feralinteractive dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102496-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).