C++11: GCC 4.8 static thread_local std::unique_ptr undefined reference

前端 未结 2 1673
深忆病人
深忆病人 2021-02-19 03:49

I need to store a unique pointer for every thread that will be accessed through a macro. I thought I should solve this with a singleton and static thread_local std::unique_ptr o

相关标签:
2条回答
  • 2021-02-19 04:29

    For me it turned out I was linking with -Wl,--image-base,0x14000000 and removing that or changing it to -Wl,--image-base,0x10000000 and the problem went away. No idea what is actually going on here...

    I believe I was bumping up into gcc bug 64697 since it was indeed a static thread_local -std=c++11. It worked in 32 bit but not 64? Very odd...gcc 8.2.0 mingw w64 cross compile:

     librtmfp.a(IOSocket.o):IOSocket.cpp:(.text+0x46c4): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for Base::ThreadQueue::_PCurrent'
    

    Original hint here.

    0 讨论(0)
  • 2021-02-19 04:37

    I experimented with this by defining a do-nothing ctor for Yay in Yay.hpp:

    - Yay() = delete;
    + Yay() {}
    

    When I did that, the error message became:

    /tmp/cc8gDxIg.o: In function `TLS wrapper function for Yay::yay':
    main.cpp:(.text._ZTWN3Yay3yayE[_ZTWN3Yay3yayE]+0x5): undefined reference to `TLS init function for Yay::yay'
    

    That led me to GCC bug 55800. The bug exists in GCC versions up through 4.8.2, and is fixed in 4.8.3 and 4.9. In discussion threads I found on duplicate GCC bug 59364, the decision has been made not to back port the fix. Therefore, your assembler hack appears to be the only solution available until you move to 4.9.

    0 讨论(0)
提交回复
热议问题