From c5d3857912daeb84f22ab9fb849f43c0a541f7fe Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 12 Sep 2016 02:51:43 +0000 Subject: [PATCH] [MS ABI] Add /include directives for dynamic TLS MSVC emits /include directives in the .drective section for the __dyn_tls_init function (decorated as ___dyn_tls_init@12 for 32-bit). This fixes PR30347. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281189 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MicrosoftCXXABI.cpp | 8 ++++++++ test/CodeGenCXX/ms-thread_local.cpp | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp index 58fe5d39eb..7220768a48 100644 --- a/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -2211,6 +2211,14 @@ void MicrosoftCXXABI::EmitThreadLocalInitFuncs( CodeGenModule &CGM, ArrayRef CXXThreadLocals, ArrayRef CXXThreadLocalInits, ArrayRef CXXThreadLocalInitVars) { + if (CXXThreadLocalInits.empty()) + return; + + CGM.AppendLinkerOptions(CGM.getTarget().getTriple().getArch() == + llvm::Triple::x86 + ? "/include:___dyn_tls_init@12" + : "/include:__dyn_tls_init"); + // This will create a GV in the .CRT$XDU section. It will point to our // initialization function. The CRT will call all of these function // pointers at start-up time and, eventually, at thread-creation time. diff --git a/test/CodeGenCXX/ms-thread_local.cpp b/test/CodeGenCXX/ms-thread_local.cpp index c29473fd6f..5183ab5c32 100644 --- a/test/CodeGenCXX/ms-thread_local.cpp +++ b/test/CodeGenCXX/ms-thread_local.cpp @@ -26,3 +26,8 @@ A f() { (void)b; return c; } + +// CHECK: !llvm.module.flags = !{{{.*}}} +// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]} +// CHECK: ![[link_opts]] = !{![[dyn_tls_init:[0-9]+]]} +// CHECK: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"} -- 2.40.0