This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

thread_local broken in gcc 4.8 ?


According to http://gcc.gnu.org/gcc-4.8/cxx0x_status.html
the keyword "thread_local" is supported in gcc 4.8 when using -std=c++11

However, thread_local seems broken.  Let's say we compile a multi-file
program that uses thread_local:
g++ a.cpp -c -o a.o -std=c++11
g++ b.cpp -c -o b.o -std=c++11
g++ a.o b.o -o prog -std=c++11

We get the following error:
b.o: In function `TLS wrapper function for foo_instance':
b.cpp:(.text._ZTW12foo_instance[_ZTW12foo_instance]+0x5): undefined
reference to `TLS init function for foo_instance'
collect2: error: ld returned 1 exit status

gcc --version
gcc (GCC) 4.8.2 20131212 (Red Hat 4.8.2-7)


file foo.hpp:
class foo {
  public:
  inline  foo() {}
  inline ~foo() {}
  inline double bar() { return 123.456; }
  };


file a.cpp:
#include "foo.hpp"
thread_local foo foo_instance;


file b.cpp:
#include "foo.hpp"
extern thread_local foo foo_instance;

int main(int argc, char** argv) {
  double bar = foo_instance.bar();
  return 0;
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]