public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "vhaisman at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/64697] New: C++11 thread_local: relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for N::ptd' Date: Tue, 20 Jan 2015 19:16:00 -0000 [thread overview] Message-ID: <bug-64697-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64697 Bug ID: 64697 Summary: C++11 thread_local: relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for N::ptd' Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vhaisman at gmail dot com I have hit an issue with thread-local storage variables on Cygwin/AMD64, I do not see it with Cygwin/i686. I am having linking issues when using `thread_local` keyword in Cygwin with its GCC 4.8.3 and GCC 4.9.2. This is derived from log4cplus. The test case is split into three files: File def.hxx: ~~~~ #include <string> namespace N { struct S { std::string str; }; // extern declaration in a header extern thread_local S * ptd; // accessing the extern declared ptd here inline S * get_ptd () { if (! ptd) ptd = new S; return ptd; } } // namespace N ~~~~ File def.cxx: ~~~~ #include "def.hxx" namespace N { // definition of ptd thread_local S * ptd = nullptr; } // namespace N ~~~ File use.cxx: ~~~~ #include "def.hxx" namespace N { __declspec(dllexport) void * foo () { // invoking inline get_ptd() function to get the value in ptd return get_ptd (); } } ~~~~ Now, when I compile each .cxx with `g++ -std=gnu++11 -fvisibility=hidden -c use.cxx def.cxx` and then try to link with `g++ -shared -o cygtest.dll use.o def.o`, I get the following error from linker: ~~~~ use.o:use.cxx:(.text$_ZTWN1N3ptdE[_ZTWN1N3ptdE]+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for N::ptd' collect2: error: ld returned 1 exit status ~~~~ The nm -C ./def.o output confirms that: ~~~~ `--> nm -C ./def.o 0000000000000000 b .bss 0000000000000000 d .data 0000000000000000 r .rdata 0000000000000000 r .rdata$zzz 0000000000000000 t .text 0000000000000008 r __emutls_t._ZN1N3ptdE 0000000000000000 D __emutls_v._ZN1N3ptdE 0000000000000000 r std::piecewise_construct ~~~~ As you can see, the ptd thread-local variable initialization function is not defined anywhere. The use.o references this initialization function (see bottom of the listing): ~~~~ `--> nm -C ./use.o 0000000000000000 b .bss 0000000000000000 d .data 0000000000000000 i .drectve 0000000000000000 p .pdata 0000000000000000 p .pdata$_ZN1N1SC1Ev 0000000000000000 p .pdata$_ZN1N7get_ptdEv 0000000000000000 p .pdata$_ZTWN1N3ptdE 0000000000000000 r .rdata 0000000000000000 r .rdata$.refptr.__emutls_v._ZN1N3ptdE 0000000000000000 r .rdata$.refptr._ZTHN1N3ptdE 0000000000000000 r .rdata$zzz 0000000000000000 R .refptr.__emutls_v._ZN1N3ptdE 0000000000000000 R .refptr._ZTHN1N3ptdE 0000000000000000 t .text 0000000000000000 t .text$_ZN1N1SC1Ev 0000000000000000 t .text$_ZN1N7get_ptdEv 0000000000000000 t .text$_ZTWN1N3ptdE 0000000000000000 A .weak._ZTHN1N3ptdE._ZN1N1SC1Ev 0000000000000000 r .xdata 0000000000000000 r .xdata$_ZN1N1SC1Ev 0000000000000000 r .xdata$_ZN1N7get_ptdEv 0000000000000000 r .xdata$_ZTWN1N3ptdE U __emutls_get_address U __emutls_v._ZN1N3ptdE U __gxx_personality_seh0 U __real__ZdlPv U __real__Znwm U _Unwind_Resume U operator delete(void*) 0000000000000000 T N::S::S() 0000000000000000 T N::foo() 0000000000000000 T N::get_ptd() U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() U operator new(unsigned long) 0000000000000000 r std::piecewise_construct w TLS init function for N::ptd 0000000000000000 T TLS wrapper function for N::ptd ~~~~ Now, this code seems to work well on Linux with both GCC and Clang. Is this a GCC problem on Cygwin? Am I using extern thread_local wrong? My experiments show that not using the extern keyword seems to fix the issue. But I am not sure if that does not introduce two ptd thread-local variables in two TUs. See also http://stackoverflow.com/q/28023728/341065
next reply other threads:[~2015-01-20 19:16 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-01-20 19:16 vhaisman at gmail dot com [this message] 2015-01-20 19:18 ` [Bug c++/64697] " vhaisman at gmail dot com 2020-03-26 22:03 ` wilson at gcc dot gnu.org 2020-03-26 23:02 ` vhaisman at gmail dot com 2020-03-26 23:06 ` wilson at gcc dot gnu.org 2021-10-01 8:56 ` cvs-commit at gcc dot gnu.org 2021-10-01 8:59 ` cvs-commit at gcc dot gnu.org 2021-10-01 9:02 ` cvs-commit at gcc dot gnu.org 2021-10-01 9:05 ` ebotcazou at gcc dot gnu.org 2022-10-14 10:31 ` ebotcazou 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-64697-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: linkBe 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).