[Bug c++/82906] New: thread_local address not uniqued across shared libraries
rafael.espindola at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Nov 8 18:55:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82906
Bug ID: 82906
Summary: thread_local address not uniqued across shared
libraries
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rafael.espindola at gmail dot com
Target Milestone: ---
Given
test.h:
inline int *foo() {
static thread_local int i = 42;
return &i;
}
test.cpp:
#include "test.h"
int *bar() { return foo(); }
test2.cpp:
#include "test.h"
#include <stdio.h>
int *bar();
int main() {
printf("%d\n", bar() == foo());
return 0;
}
If test.cpp is compiled with "gcc -c -O2 -fPIC test.c", the resulting .o has a
R_X86_64_TLSLD R_X86_64_DTPOFF32 pair.
Compiling the rest of the program with
g++ test.o -shared -o test.so"
g++ test2.cpp test.so -o t -Wl,-rpath="\$ORIGIN"
produces an executable that prints 0 when run. It should print 1, that is,
bar() and foo() should find the same address.
Changing test.o to use general dynamic instead of local dynamic solves the
problem.
More information about the Gcc-bugs
mailing list