public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marcelotpcruz at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/102398] New: thread_local works incorrectly outside of main file
Date: Sat, 18 Sep 2021 11:19:49 +0000	[thread overview]
Message-ID: <bug-102398-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102398
           Summary: thread_local works incorrectly outside of main file
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marcelotpcruz at gmail dot com
  Target Milestone: ---

Created attachment 51479
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51479&action=edit
thread_local_work_at_main_fails_wherever

Hello,
This bug is related to: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81915

I believe above link can be closed as it's old and the specification is a bit
incorrect.

The problem is not about it being inline or inside a class var, as any of those
works if such are inside the file with the main().
Real problem is about variable definition outside of "main" file, so when it's
only declared, the problem doesn't show, that's why inline reports the bug, it
tells the compiler to define on the same line as it's defined.

-
-
-
-
-

When using thread_local in main file it works!

-------------- Clean: Debug in thread_local (compiler: GNU GCC
Compiler)---------------

Cleaned "thread_local - Debug"

-------------- Build: Debug in thread_local (compiler: GNU GCC
Compiler)---------------

g++.exe -Wall -fexceptions -g -O -save-temps  -c
C:\my_codes\thread_local\main.cpp -o obj\Debug\main.o
g++.exe  -o bin\Debug\thread_local.exe obj\Debug\main.o   
Output file is bin\Debug\thread_local.exe with size 152.48 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

-
-
-
-
-

When using thread_local outside of main file, throught #include including , it
fails:

-------------- Clean: Debug in thread_local_fail (compiler: GNU GCC
Compiler)---------------

Cleaned "thread_local_fail - Debug"

-------------- Build: Debug in thread_local_fail (compiler: GNU GCC
Compiler)---------------

g++.exe -Wall -fexceptions -g -O -save-temps  -c
C:\my_codes\thread_local_fail\extern_thread_local.cpp -o
obj\Debug\extern_thread_local.o
g++.exe -Wall -fexceptions -g -O -save-temps  -c
C:\my_codes\thread_local_fail\main.cpp -o obj\Debug\main.o
g++.exe  -o bin\Debug\thread_local_fail.exe obj\Debug\extern_thread_local.o
obj\Debug\main.o   
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
obj\Debug\main.o:C:/Users/MarceloTPC/Documents/my_codes/thread_local_fail/extern_thread_local.cpp:4:
multiple definition of `TLS init function for
does_not_work_string_located_at_main[abi:cxx11]';
obj\Debug\extern_thread_local.o:C:/Users/MarceloTPC/Documents/my_codes/thread_local_fail/extern_thread_local.cpp:4:
first defined here
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
obj\Debug\main.o:main.cpp:(.data+0x0): multiple definition of
`__emutls_v._Z36does_not_work_string_located_at_mainB5cxx11';
obj\Debug\extern_thread_local.o:extern_thread_local.cpp:(.data+0x0): first
defined here
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
2 error(s), 0 warning(s) (0 minute(s), 1 second(s))

-
-
-
-
-

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.2.0/lto-wrapper.exe
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-w64-mingw32
Configured with: ../configure
--prefix=/R/winlibs64_stage/inst_gcc-11.2.0/share/gcc
--build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32
--enable-offload-targets=nvptx-none --with-pkgversion='MinGW-W64
x86_64-posix-seh, built by Brecht Sanders' --with-tune=generic
--enable-checking=release --enable-threads=posix --disable-sjlj-exceptions
--disable-libunwind-exceptions --disable-serial-configure --disable-bootstrap
--enable-host-shared --enable-plugin --disable-default-ssp --disable-rpath
--enable-libstdcxx-pch --enable-libstdcxx-time=yes --disable-libstdcxx-debug
--disable-version-specific-runtime-libs --with-stabs --disable-symvers
--enable-languages=c,c++,fortran,lto,objc,obj-c++,d,jit --disable-gold
--disable-nls --disable-stage1-checking --disable-win32-registry
--disable-multilib --enable-ld --enable-libquadmath --enable-libada
--enable-libssp --enable-libstdcxx --enable-lto --enable-fully-dynamic-string
--enable-libgomp --enable-graphite --enable-mingw-wildcard
--with-mpc=/d/Prog/winlibs64_stage/custombuilt
--with-mpfr=/d/Prog/winlibs64_stage/custombuilt
--with-gmp=/d/Prog/winlibs64_stage/custombuilt
--with-isl=/d/Prog/winlibs64_stage/custombuilt --enable-install-libiberty
--enable-__cxa_atexit --without-included-gettext --with-diagnostics-color=auto
--enable-clocale=generic --with-libiconv --with-system-zlib
--with-build-sysroot=/R/winlibs64_stage/gcc-11.2.0/build_mingw/mingw-w64
CFLAGS=-I/d/Prog/winlibs64_stage/custombuilt/include/libdl-win32
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders)

Windows 10 Home - 20H2

             reply	other threads:[~2021-09-18 11:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18 11:19 marcelotpcruz at gmail dot com [this message]
2022-01-02 11:36 ` [Bug c++/102398] " pierre.vigier at ymail dot com
2024-06-27 18:03 ` pinskia at gcc dot gnu.org
2024-06-27 18:04 ` pinskia 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-102398-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).