diff options
-rw-r--r-- | lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 21 | ||||
-rw-r--r-- | lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 5 | ||||
-rw-r--r-- | test/MC/MachO/tls.s | 212 |
3 files changed, 144 insertions, 94 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index d0b48b0db8..8a5fe4d371 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -311,13 +311,26 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { return; } - // Handle the tbss directive on darwin which is a thread local bss directive - // like zerofill. - if (GVKind.isThreadBSS() && MAI->hasMachoTBSSDirective()) { + // Handle thread local data for mach-o which requires us to output an + // additional structure of data and mangle the original symbol so that we + // can reference it later. + if (GVKind.isThreadLocal() && MAI->hasMachoTBSSDirective()) { // Emit the .tbss symbol MCSymbol *MangSym = OutContext.GetOrCreateSymbol(GVSym->getName() + Twine("$tlv$init")); - OutStreamer.EmitTBSSSymbol(TheSection, MangSym, Size, 1 << AlignLog); + + if (GVKind.isThreadBSS()) + OutStreamer.EmitTBSSSymbol(TheSection, MangSym, Size, 1 << AlignLog); + else if (GVKind.isThreadData()) { + OutStreamer.SwitchSection(TheSection); + + EmitLinkage(GV->getLinkage(), MangSym); + EmitAlignment(AlignLog, GV); + OutStreamer.EmitLabel(MangSym); + + EmitGlobalConstant(GV->getInitializer()); + } + OutStreamer.AddBlankLine(); // Emit the variable struct for the runtime. diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 605e2a817b..71ad3fb6f9 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -670,11 +670,10 @@ const MCSection *TargetLoweringObjectFileMachO:: SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const { - // Handle one kind of thread local... + // Handle thread local data. if (Kind.isThreadBSS()) return TLSBSSSection; + if (Kind.isThreadData()) return TLSDataSection; - assert(!Kind.isThreadLocal() && "Darwin doesn't support TLS"); - if (Kind.isText()) return GV->isWeakForLinker() ? TextCoalSection : TextSection; diff --git a/test/MC/MachO/tls.s b/test/MC/MachO/tls.s index 92532ec632..07ea0aa16a 100644 --- a/test/MC/MachO/tls.s +++ b/test/MC/MachO/tls.s @@ -1,40 +1,56 @@ // RUN: llvm-mc -triple x86_64-apple-darwin %s -filetype=obj -o - | macho-dump --dump-section-data | FileCheck %s -.tbss _a$tlv$init, 4 + .section __TEXT,__text,regular,pure_instructions + .section __DATA,__thread_data,thread_local_regular + .globl _c$tlv$init + .align 2 +_c$tlv$init: + .long 4 + + .section __DATA,__thread_vars,thread_local_variables + .globl _c +_c: + .quad ___tlv_bootstrap + .quad 0 + .quad _c$tlv$init + + .section __DATA,__thread_data,thread_local_regular + .globl _d$tlv$init + .align 2 +_d$tlv$init: + .long 5 + + .section __DATA,__thread_vars,thread_local_variables + .globl _d +_d: + .quad ___tlv_bootstrap + .quad 0 + .quad _d$tlv$init -.tlv - .globl _a +.tbss _a$tlv$init, 4, 2 + + .globl _a _a: - .quad _tlv_bootstrap - .quad 0 - .quad _a$tlv$init + .quad ___tlv_bootstrap + .quad 0 + .quad _a$tlv$init -.tbss _b$tlv$init, 8, 4 +.tbss _b$tlv$init, 4, 2 -.tlv - .globl _b + .globl _b _b: - .quad _tlv_bootstrap - .quad 0 - .quad _b$tlv$init - -.tdata -_c$tlv$init: - .quad 8 + .quad ___tlv_bootstrap + .quad 0 + .quad _b$tlv$init -.tlv - .globl _c -_c: - .quad _tlv_bootstrap - .quad 0 - .quad _c$tlv$init +.subsections_via_symbols // CHECK: ('cputype', 16777223) // CHECK: ('cpusubtype', 3) // CHECK: ('filetype', 1) // CHECK: ('num_load_commands', 1) // CHECK: ('load_commands_size', 496) -// CHECK: ('flag', 0) +// CHECK: ('flag', 8192) // CHECK: ('reserved', 0) // CHECK: ('load_commands', [ // CHECK: # Load Command 0 @@ -42,9 +58,9 @@ _c: // CHECK: ('size', 392) // CHECK: ('segment_name', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') // CHECK: ('vm_addr', 0) -// CHECK: ('vm_size', 104) +// CHECK: ('vm_size', 112) // CHECK: ('file_offset', 528) -// CHECK: ('file_size', 80) +// CHECK: ('file_size', 104) // CHECK: ('maxprot', 7) // CHECK: ('initprot', 7) // CHECK: ('num_sections', 4) @@ -68,31 +84,31 @@ _c: // CHECK: ]) // CHECK: ('_section_data', '') // CHECK: # Section 1 -// CHECK: (('section_name', '__thread_bss\x00\x00\x00\x00') +// CHECK: (('section_name', '__thread_data\x00\x00\x00') // CHECK: ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -// CHECK: ('address', 80) -// CHECK: ('size', 24) -// CHECK: ('offset', 0) -// CHECK: ('alignment', 4) +// CHECK: ('address', 0) +// CHECK: ('size', 8) +// CHECK: ('offset', 528) +// CHECK: ('alignment', 2) // CHECK: ('reloc_offset', 0) // CHECK: ('num_reloc', 0) -// CHECK: ('flags', 0x12) +// CHECK: ('flags', 0x11) // CHECK: ('reserved1', 0) // CHECK: ('reserved2', 0) // CHECK: ('reserved3', 0) // CHECK: ), // CHECK: ('_relocations', [ // CHECK: ]) -// CHECK: ('_section_data', '\xcf\xfa\xed\xfe\x07\x00\x00\x01\x03\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\xf0\x01\x00\x00') +// CHECK: ('_section_data', '\x04\x00\x00\x00\x05\x00\x00\x00') // CHECK: # Section 2 // CHECK: (('section_name', '__thread_vars\x00\x00\x00') // CHECK: ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -// CHECK: ('address', 0) -// CHECK: ('size', 72) -// CHECK: ('offset', 528) +// CHECK: ('address', 8) +// CHECK: ('size', 96) +// CHECK: ('offset', 536) // CHECK: ('alignment', 0) -// CHECK: ('reloc_offset', 608) -// CHECK: ('num_reloc', 6) +// CHECK: ('reloc_offset', 632) +// CHECK: ('num_reloc', 8) // CHECK: ('flags', 0x13) // CHECK: ('reserved1', 0) // CHECK: ('reserved2', 0) @@ -100,108 +116,130 @@ _c: // CHECK: ), // CHECK: ('_relocations', [ // CHECK: # Relocation 0 -// CHECK: (('word-0', 0x40), -// CHECK: ('word-1', 0xe000002)), +// CHECK: (('word-0', 0x58), +// CHECK: ('word-1', 0xe000001)), // CHECK: # Relocation 1 -// CHECK: (('word-0', 0x30), -// CHECK: ('word-1', 0xe000006)), +// CHECK: (('word-0', 0x48), +// CHECK: ('word-1', 0xe000008)), // CHECK: # Relocation 2 -// CHECK: (('word-0', 0x28), -// CHECK: ('word-1', 0xe000001)), +// CHECK: (('word-0', 0x40), +// CHECK: ('word-1', 0xe000000)), // CHECK: # Relocation 3 -// CHECK: (('word-0', 0x18), -// CHECK: ('word-1', 0xe000006)), +// CHECK: (('word-0', 0x30), +// CHECK: ('word-1', 0xe000008)), // CHECK: # Relocation 4 -// CHECK: (('word-0', 0x10), -// CHECK: ('word-1', 0xe000000)), +// CHECK: (('word-0', 0x28), +// CHECK: ('word-1', 0xe000007)), // CHECK: # Relocation 5 +// CHECK: (('word-0', 0x18), +// CHECK: ('word-1', 0xe000008)), +// CHECK: # Relocation 6 +// CHECK: (('word-0', 0x10), +// CHECK: ('word-1', 0xe000005)), +// CHECK: # Relocation 7 // CHECK: (('word-0', 0x0), -// CHECK: ('word-1', 0xe000006)), +// CHECK: ('word-1', 0xe000008)), // CHECK: ]) -// CHECK: ('_section_data', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// CHECK: ('_section_data', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') // CHECK: # Section 3 -// CHECK: (('section_name', '__thread_data\x00\x00\x00') +// CHECK: (('section_name', '__thread_bss\x00\x00\x00\x00') // CHECK: ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -// CHECK: ('address', 72) +// CHECK: ('address', 104) // CHECK: ('size', 8) -// CHECK: ('offset', 600) -// CHECK: ('alignment', 0) +// CHECK: ('offset', 0) +// CHECK: ('alignment', 2) // CHECK: ('reloc_offset', 0) // CHECK: ('num_reloc', 0) -// CHECK: ('flags', 0x11) +// CHECK: ('flags', 0x12) // CHECK: ('reserved1', 0) // CHECK: ('reserved2', 0) // CHECK: ('reserved3', 0) // CHECK: ), // CHECK: ('_relocations', [ // CHECK: ]) -// CHECK: ('_section_data', '\x08\x00\x00\x00\x00\x00\x00\x00') +// CHECK: ('_section_data', '\xcf\xfa\xed\xfe\x07\x00\x00\x01') // CHECK: ]) // CHECK: ), // CHECK: # Load Command 1 // CHECK: (('command', 2) // CHECK: ('size', 24) -// CHECK: ('symoff', 656) -// CHECK: ('nsyms', 7) -// CHECK: ('stroff', 768) -// CHECK: ('strsize', 64) -// CHECK: ('_string_data', '\x00_a\x00_tlv_bootstrap\x00_b\x00_c\x00_a$tlv$init\x00_b$tlv$init\x00_c$tlv$init\x00\x00\x00\x00') +// CHECK: ('symoff', 696) +// CHECK: ('nsyms', 9) +// CHECK: ('stroff', 840) +// CHECK: ('strsize', 80) +// CHECK: ('_string_data', '\x00_c$tlv$init\x00_c\x00___tlv_bootstrap\x00_d$tlv$init\x00_d\x00_a\x00_b\x00_a$tlv$init\x00_b$tlv$init\x00\x00\x00') // CHECK: ('_symbols', [ // CHECK: # Symbol 0 -// CHECK: (('n_strx', 25) +// CHECK: (('n_strx', 54) // CHECK: ('n_type', 0xe) -// CHECK: ('n_sect', 2) +// CHECK: ('n_sect', 4) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 80) +// CHECK: ('n_value', 104) // CHECK: ('_string', '_a$tlv$init') // CHECK: ), // CHECK: # Symbol 1 -// CHECK: (('n_strx', 37) +// CHECK: (('n_strx', 66) // CHECK: ('n_type', 0xe) -// CHECK: ('n_sect', 2) +// CHECK: ('n_sect', 4) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 96) +// CHECK: ('n_value', 108) // CHECK: ('_string', '_b$tlv$init') // CHECK: ), // CHECK: # Symbol 2 -// CHECK: (('n_strx', 49) -// CHECK: ('n_type', 0xe) -// CHECK: ('n_sect', 4) +// CHECK: (('n_strx', 48) +// CHECK: ('n_type', 0xf) +// CHECK: ('n_sect', 3) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 72) -// CHECK: ('_string', '_c$tlv$init') +// CHECK: ('n_value', 56) +// CHECK: ('_string', '_a') // CHECK: ), // CHECK: # Symbol 3 -// CHECK: (('n_strx', 1) +// CHECK: (('n_strx', 51) // CHECK: ('n_type', 0xf) // CHECK: ('n_sect', 3) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 0) -// CHECK: ('_string', '_a') +// CHECK: ('n_value', 80) +// CHECK: ('_string', '_b') // CHECK: ), // CHECK: # Symbol 4 -// CHECK: (('n_strx', 19) +// CHECK: (('n_strx', 13) // CHECK: ('n_type', 0xf) // CHECK: ('n_sect', 3) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 24) -// CHECK: ('_string', '_b') +// CHECK: ('n_value', 8) +// CHECK: ('_string', '_c') // CHECK: ), // CHECK: # Symbol 5 -// CHECK: (('n_strx', 22) +// CHECK: (('n_strx', 1) // CHECK: ('n_type', 0xf) -// CHECK: ('n_sect', 3) +// CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 48) -// CHECK: ('_string', '_c') +// CHECK: ('n_value', 0) +// CHECK: ('_string', '_c$tlv$init') // CHECK: ), // CHECK: # Symbol 6 -// CHECK: (('n_strx', 4) +// CHECK: (('n_strx', 45) +// CHECK: ('n_type', 0xf) +// CHECK: ('n_sect', 3) +// CHECK: ('n_desc', 0) +// CHECK: ('n_value', 32) +// CHECK: ('_string', '_d') +// CHECK: ), +// CHECK: # Symbol 7 +// CHECK: (('n_strx', 33) +// CHECK: ('n_type', 0xf) +// CHECK: ('n_sect', 2) +// CHECK: ('n_desc', 0) +// CHECK: ('n_value', 4) +// CHECK: ('_string', '_d$tlv$init') +// CHECK: ), +// CHECK: # Symbol 8 +// CHECK: (('n_strx', 16) // CHECK: ('n_type', 0x1) // CHECK: ('n_sect', 0) // CHECK: ('n_desc', 0) // CHECK: ('n_value', 0) -// CHECK: ('_string', '_tlv_bootstrap') +// CHECK: ('_string', '___tlv_bootstrap') // CHECK: ), // CHECK: ]) // CHECK: ), @@ -209,10 +247,10 @@ _c: // CHECK: (('command', 11) // CHECK: ('size', 80) // CHECK: ('ilocalsym', 0) -// CHECK: ('nlocalsym', 3) -// CHECK: ('iextdefsym', 3) -// CHECK: ('nextdefsym', 3) -// CHECK: ('iundefsym', 6) +// CHECK: ('nlocalsym', 2) +// CHECK: ('iextdefsym', 2) +// CHECK: ('nextdefsym', 6) +// CHECK: ('iundefsym', 8) // CHECK: ('nundefsym', 1) // CHECK: ('tocoff', 0) // CHECK: ('ntoc', 0) |