[Bug c++/55800] Link failure with thread_local in unnamed namespace
linedot at xcpp dot org
gcc-bugzilla@gcc.gnu.org
Fri Oct 18 17:05:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55800
linedot at xcpp dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |linedot at xcpp dot org
--- Comment #2 from linedot at xcpp dot org ---
I have encountered a similar problem
output of gcc -v:
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.1/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-4.8.1-r1/work/gcc-4.8.1/configure --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.1
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.1/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.1
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.1/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.1/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.1/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --with-cloog --disable-isl-version-check --enable-lto
--enable-nls --without-included-gettext --with-system-zlib --enable-obsolete
--disable-werror --enable-secureplt --enable-multilib
--with-multilib-list=m32,m64 --enable-libmudflap --disable-libssp
--enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.8.1/python
--enable-checking=release --disable-libgcj --enable-libstdcxx-time
--enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.8.1-r1 p1.2,
pie-0.5.7'
Thread model: posix
gcc version 4.8.1 (Gentoo 4.8.1-r1 p1.2, pie-0.5.7)
=========================================================================
Here's a simplified version of the code I was using:
=========================================================================
main.cpp:
#include "xyz.hpp"
int main()
{
return *xyz::getBla();
}
=========================================================================
xyz.hpp:
#include <memory>
class xyz
{
private:
static thread_local std::unique_ptr<int> bla;
public:
static int* getBla()
{
if(!bla.get())
{
bla.reset(new int(4));
}
return bla.get();
}
};
=========================================================================
xyz.cpp:
#include "xyz.hpp"
thread_local std::unique_ptr<int> xyz::bla;
=========================================================================
If I try to compile this with
g++ -std=c++11 main.cpp xyz.cpp
/tmp/ccLJmEUa.o: In function `_ZTWN3xyz3blaE':
main.cpp:(.text._ZTWN3xyz3blaE[_ZTWN3xyz3blaE]+0x5): undefined reference to
`_ZTHN3xyz3blaE'
collect2: error: ld returned 1 exit status
I don't know if the following is any help:
I messed with the assembly output of g++ when compiling xyz.cpp and it looks
that _ZTWN3xyz3blaE should be where __tls_init begins - at least adding
.globl _ZTWN3xyz3blaE
_ZTWN3xyz3blaE = __tls_init
manually at the end of the assembly seems to make the code do what it is
supposed to.
More information about the Gcc-bugs
mailing list