Open
Description
When building a DLL for MinGW with LTO, the linker cannot resolve auto-exported emulated-TLS thread_local
variables.
// pass
// RUN: clang++ -fuse-ld=lld %s -shared -o %t.dll -target x86_64-windows-gnu -femulated-tls -flto -Wl,--exclude-all-symbols
// RUN: clang++ -fuse-ld=lld %s -shared -o %t.dll -target x86_64-windows-gnu -fno-emulated-tls -flto
// RUN: clang++ -fuse-ld=lld %s -shared -o %t.dll -target x86_64-windows-gnu -femulated-tls -flto -DUSE_DLLEXPORT
// RUN: clang++ -fuse-ld=lld %s -shared -o %t.dll -target x86_64-windows-gnu -femulated-tls -fno-lto
// RUN: llvm-readobj --coff-exports %t.dll | FileCheck %s
// RUN: clang++ -fuse-ld=lld %s -shared -o %t.dll -target x86_64-linux-gnu -femulated-tls -flto
// RUN: llvm-readobj --dt %t.dll | FileCheck %s
// CHECK: Name: __emutls_v.tls_var
// fail
// RUN: clang++ -fuse-ld=lld %s -shared -o %t.dll -target x86_64-windows-gnu -femulated-tls -flto
int thread_local tls_var;
#ifdef USE_DLLEXPORT
__declspec(dllexport) int other_var;
#endif
result:
ld.lld: error: <root>: undefined symbol: tls_var
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
The linker reports tls_var
as undefined, although __emutls_v.tls_var
should be referenced instead in emulated-TLS mode.
For Linux target, tls_var
is resolved to __emutls_v.tls_var
correctly.