From 0e4cf807aeaf54a10e02176498a7df13ac722b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 23 May 2021 01:47:04 +0300 Subject: [clang] [MinGW] Don't mark emutls variables as DSO local These actually can be automatically imported from another DLL. (This works properly as long as the actual implementation of emutls is linked dynamically from e.g. libgcc; if the implementation comes from compiler-rt or a statically linked libgcc, it doesn't work as intended.) This fixes PR50146 and https://github.com/msys2/MINGW-packages/issues/8706 (fixing calling std::call_once in a dynamically linked libstdc++); since f73183958482602c4588b0f4a1c3a096e7542947 the dso_local attribute on the TLS variable affected the actual generated code for accessing the emutls variable. The dso_local attribute on the emutls variable made those accesses to use 32 bit relative addressing in code, which requires runtime pseudo relocations in the text section, and breaks entirely if the actual other variable ends up loaded too far away in the virtual address space. Differential Revision: https://reviews.llvm.org/D102970 --- clang/lib/CodeGen/CodeGenModule.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 744ccf0fe59f..9b31ecdbd81a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -986,8 +986,13 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM, // In MinGW, variables without DLLImport can still be automatically // imported from a DLL by the linker; don't mark variables that // potentially could come from another DLL as DSO local. + + // With EmulatedTLS, TLS variables can be autoimported from other DLLs + // (and this actually happens in the public interface of libstdc++), so + // such variables can't be marked as DSO local. (Native TLS variables + // can't be dllimported at all, though.) if (GV->isDeclarationForLinker() && isa(GV) && - !GV->isThreadLocal()) + (!GV->isThreadLocal() || CGM.getCodeGenOpts().EmulatedTLS)) return false; } -- cgit v1.2.3