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

* [Bug c++/102496] [11/12 regression] extern __thread declaration in function scope produces a non-TLS reference
  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 ` 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
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-27 10:43 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
      Known to fail|                            |11.1.0
   Last reconfirmed|                            |2021-09-27
            Summary|[11 regression] extern      |[11/12 regression] extern
                   |__thread declaration in     |__thread declaration in
                   |function scope produces a   |function scope produces a
                   |non-TLS reference           |non-TLS reference
           Keywords|                            |link-failure, wrong-code
   Target Milestone|---                         |11.3
      Known to work|                            |10.3.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/102496] [11/12 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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 ` pinskia at gcc dot gnu.org
  2021-09-28  8:32 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-27 10:52 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12 regression] extern   |[11/12 regression] extern
                   |__thread declaration in     |__thread and thread_local
                   |function scope produces a   |declaration in function
                   |non-TLS reference           |scope produces a non-TLS
                   |                            |reference
           Severity|normal                      |major

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is also broken for thread_local too:
struct a
{
  operator int();
};
int main()
{
    extern thread_local a thing;
    return thing;
}

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

* [Bug c++/102496] [11/12 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-28  8:32 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/102496] [11/12 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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
                   ` (2 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-28 14:31 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 51516
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51516&action=edit
gcc12-pr102496.patch

Untested fix.

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

* [Bug c++/102496] [11/12 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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
                   ` (3 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-28 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r11-3699-g4e62aca0e0520e4ed2532f2d8153581190621c1a

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

* [Bug c++/102496] [11/12 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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
                   ` (4 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-01  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:701075864ac4d1c6cec936d10f9cfc2aeb8c1699

commit r12-4032-g701075864ac4d1c6cec936d10f9cfc2aeb8c1699
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Oct 1 10:30:16 2021 +0200

    c++: Fix handling of __thread/thread_local extern vars declared at function
scope [PR102496]

    The introduction of push_local_extern_decl_alias in
    r11-3699-g4e62aca0e0520e4ed2532f2d8153581190621c1a
    broke tls vars, while the decl they are created for has the tls model
    set properly, nothing sets it for the alias that is actually used,
    so accesses to it are done as if they were normal variables.
    This is then diagnosed at link time if the definition of the extern
    vars is __thread/thread_local.

    2021-10-01  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102496
            * name-lookup.c (push_local_extern_decl_alias): Return early even
for
            tls vars with non-dependent type when processing_template_decl. 
For
            CP_DECL_THREAD_LOCAL_P vars call set_decl_tls_model on alias.

            * g++.dg/tls/pr102496-1.C: New test.
            * g++.dg/tls/pr102496-2.C: New test.

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

* [Bug c++/102496] [11 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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
                   ` (5 preceding siblings ...)
  2021-10-01  8:31 ` cvs-commit at gcc dot gnu.org
@ 2021-10-01 12:39 ` 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
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-01 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12 regression] extern   |[11 regression] extern
                   |__thread and thread_local   |__thread and thread_local
                   |declaration in function     |declaration in function
                   |scope produces a non-TLS    |scope produces a non-TLS
                   |reference                   |reference

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.

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

* [Bug c++/102496] [11 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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
                   ` (6 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-05 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5fec46a0b4a94190209c81f4091a0369a056727d

commit r11-9073-g5fec46a0b4a94190209c81f4091a0369a056727d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Oct 1 10:30:16 2021 +0200

    c++: Fix handling of __thread/thread_local extern vars declared at function
scope [PR102496]

    The introduction of push_local_extern_decl_alias in
    r11-3699-g4e62aca0e0520e4ed2532f2d8153581190621c1a
    broke tls vars, while the decl they are created for has the tls model
    set properly, nothing sets it for the alias that is actually used,
    so accesses to it are done as if they were normal variables.
    This is then diagnosed at link time if the definition of the extern
    vars is __thread/thread_local.

    2021-10-01  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102496
            * name-lookup.c (push_local_extern_decl_alias): Return early even
for
            tls vars with non-dependent type when processing_template_decl. 
For
            CP_DECL_THREAD_LOCAL_P vars call set_decl_tls_model on alias.

            * g++.dg/tls/pr102496-1.C: New test.
            * g++.dg/tls/pr102496-2.C: New test.

    (cherry picked from commit 701075864ac4d1c6cec936d10f9cfc2aeb8c1699)

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

* [Bug c++/102496] [11 regression] extern __thread and thread_local declaration in function scope produces a non-TLS reference
  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
                   ` (7 preceding siblings ...)
  2021-10-05 20:30 ` cvs-commit at gcc dot gnu.org
@ 2021-10-12  9:55 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-12  9:55 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 11.3+.

^ 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).