-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Mixing objects with thread_local
in C++ and _Thread_local
in C
#51156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
thread_local
in C++ and _Thread_local
in C
CC @hubert-reinterpretcast -- IIRC, we found that |
Hi Aaron, While this code does represent the problem discussed in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2478r0.pdf, on Linux, the problem is supposed to be avoidable (and it is normally avoided because the reference to the initialization function is declared weak). The problem in this case appears to be the
-- HT |
@llvm/issue-subscribers-clang-codegen Author: None (70e8c5c0-afb3-4429-baaf-906675eb77bb)
| | |
| --- | --- |
| Bugzilla Link | [51814](https://llvm.org/bz51814) |
| Version | 12.0 |
| OS | Linux |
| CC | @DougGregor,@zygoloid |
Extended DescriptionHi, I'm not sure that this is really a bug, but if I could at least get an explanation of what is happening I'd be really happy. With clang 12, this fails to build: $ cat tls.c extern __attribute__((visibility("hidden"))) _Thread_local const char *logger_thread_name;
__attribute__((visibility("hidden"))) _Thread_local const char *logger_thread_name; $ cat main.cpp extern "C" {
extern __attribute__((visibility("hidden")))
// Works if you use _Thread_local
// _Thread_local
thread_local
const char *logger_thread_name;
}
const char *func() {
return logger_thread_name;
} $ cat build.sh
clang++ main.cpp -c -fPIC -DPIC
clang tls.c -c -fPIC -DPIC
clang++ main.o tls.o -shared
$ bash build.sh
/usr/bin/ld: main.o: relocation R_X86_64_PC32 against undefined hidden symbol `_ZTH18logger_thread_name' can not be used when making a shared object
/usr/bin/ld: final link failed: bad value
clang-12: error: linker command failed with exit code 1 (use -v to see invocation) What we have here is:
The link is successful is you either:
Is the code above doing things that we really shouldn't do? Regardless of that, is there some bug in clang, given that it produces a |
Extended Description
Hi,
I'm not sure that this is really a bug, but if I could at least get an explanation of what is happening I'd be really happy. With clang 12, this fails to build:
$ cat tls.c
$ cat main.cpp
What we have here is:
_Thread_local
, with the attributevisibility("hidden")
extern "C"
, but usesthread_local
, and also has the attributevisibility("hidden")
-fPIC
and link them into a shared libraryThe link is successful is you either:
_Thread_local
insteadvisibility("hidden")
attributeIs the code above doing things that we really shouldn't do? Regardless of that, is there some bug in clang, given that it produces a
R_X86_64_PC32
relocation in a file built with-fPIC
?The text was updated successfully, but these errors were encountered: