Skip to content

Commit 0de6255

Browse files
committed
Use the same tls section name as msvc.
We currently error in clang with: "error: thread-local storage is unsupported for the current target", but we can start to get the llvm level ready. When compiling template<typename T> struct foo { static __declspec(thread) int bar; }; template<typename T> __declspec(therad) int foo<T>::bar; template struct foo<int>; msvc produces SECTION HEADER brson#3 .tls$ name 0 physical address 0 virtual address 4 size of raw data 12F file pointer to raw data (0000012F to 00000132) 0 file pointer to relocation table 0 file pointer to line numbers 0 number of relocations 0 number of line numbers C0301040 flags Initialized Data COMDAT; sym= "public: static int foo<int>::bar" (?bar@?$foo@H@@2ha) 4 byte align Read Write gcc produces a ".data$__emutls_v.<symbol>" for the testcase with __declspec(thread) replaced with thread_local. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195849 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ed3eb50 commit 0de6255

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) {
744744
if (Kind.isBSS ())
745745
return ".bss";
746746
if (Kind.isThreadLocal())
747-
return ".tls";
747+
return ".tls$";
748748
if (Kind.isWriteable())
749749
return ".data";
750750
return ".rdata";

test/MC/COFF/weak-symbol.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ define weak void @f() section ".sect" {
3636
; X64: .globl a
3737
; X64: .zero 12
3838
@a = weak unnamed_addr constant { i32, i32, i32 } { i32 0, i32 0, i32 0}, section ".data"
39+
40+
; X86: .section .tls$,"w",discard,_b
41+
; X86: .globl _b
42+
; X86: .long 0
43+
;
44+
; X64: .section .tls$,"w",discard,b
45+
; X64: .globl b
46+
; X64: .long 0
47+
48+
@b = weak_odr thread_local global i32 0, align 4

0 commit comments

Comments
 (0)