xref: /llvm-project/lld/test/MachO/tlv-dylib.s (revision 75cdab6dc2453a508157a9c383b93373a93078d6)
1# REQUIRES: x86
2# RUN: rm -rf %t; split-file %s %t
3
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libtlv.s -o %t/libtlv.o
5# RUN: %lld -dylib -install_name @executable_path/libtlv.dylib \
6# RUN:   -lSystem -o %t/libtlv.dylib %t/libtlv.o
7# RUN: llvm-objdump --macho --exports-trie --rebase %t/libtlv.dylib | \
8# RUN:   FileCheck %s --check-prefix=DYLIB
9# DYLIB-DAG: _foo [per-thread]
10# DYLIB-DAG: _bar [per-thread]
11## Make sure we don't emit rebase opcodes for relocations in __thread_vars.
12# DYLIB:       Rebase table:
13# DYLIB-NEXT:  segment  section            address     type
14# DYLIB-EMPTY:
15
16# RUN: %lld -dylib -install_name @executable_path/libtlv.dylib \
17# RUN:   -lSystem -fixup_chains -o %t/libtlv.dylib %t/libtlv.o
18## Make sure we don't emit fixups in __thread_vars.
19# RUN: llvm-objdump --macho --chained-fixups %t/libtlv.dylib | \
20# RUN:   FileCheck %s --check-prefix=CHAINED
21# CHAINED-NOT: __thread_vars
22
23# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
24# RUN: %lld -lSystem -L%t -ltlv %t/test.o -o %t/test
25# RUN: llvm-objdump --no-print-imm-hex --bind -d --no-show-raw-insn %t/test | FileCheck %s
26
27# CHECK:      movq [[#]](%rip), %rax ## 0x[[#%x, FOO:]]
28# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%x, BAR:]]
29# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%x, BAZ:]]
30
31# CHECK-LABEL: Bind table:
32# CHECK-DAG: __DATA       __thread_ptrs  0x{{0*}}[[#%x, FOO]] pointer 0   libtlv   _foo
33# CHECK-DAG: __DATA       __thread_ptrs  0x{{0*}}[[#%x, BAR]] pointer 0   libtlv   _bar
34# CHECK-DAG: __DATA_CONST __got          0x{{0*}}[[#%x, BAZ]] pointer 0   libtlv   _baz
35
36## Check `type` on the various TLV sections, and check that
37## nothing's after S_THREAD_LOCAL_ZEROFILL.
38# RUN: llvm-otool -lv %t/test | FileCheck --check-prefix=FLAGS %s
39# FLAGS:       sectname __got
40# FLAGS-NEXT:   segname __DATA_CONST
41# FLAGS-NEXT:      addr
42# FLAGS-NEXT:      size 0x0000000000000008
43# FLAGS-NEXT:    offset
44# FLAGS-NEXT:     align 2^3 (8)
45# FLAGS-NEXT:    reloff 0
46# FLAGS-NEXT:    nreloc 0
47# FLAGS-NEXT:      type S_NON_LAZY_SYMBOL_POINTERS
48# FLAGS:       sectname __thread_vars
49# FLAGS-NEXT:   segname __DATA
50# FLAGS-NEXT:      addr
51# FLAGS-NEXT:      size 0x0000000000000030
52# FLAGS-NEXT:    offset
53# FLAGS-NEXT:     align 2^3 (8)
54# FLAGS-NEXT:    reloff 0
55# FLAGS-NEXT:    nreloc 0
56# FLAGS-NEXT:      type S_THREAD_LOCAL_VARIABLES
57# FLAGS:       sectname __thread_ptrs
58# FLAGS-NEXT:   segname __DATA
59# FLAGS-NEXT:      addr
60# FLAGS-NEXT:      size 0x0000000000000010
61# FLAGS-NEXT:    offset
62# FLAGS-NEXT:     align 2^3 (8)
63# FLAGS-NEXT:    reloff 0
64# FLAGS-NEXT:    nreloc 0
65# FLAGS-NEXT:      type S_THREAD_LOCAL_VARIABLE_POINTERS
66# FLAGS:       sectname __thread_data
67# FLAGS-NEXT:   segname __DATA
68# FLAGS-NEXT:      addr
69# FLAGS-NEXT:      size 0x0000000000000008
70# FLAGS-NEXT:    offset
71# FLAGS-NEXT:     align
72# FLAGS-NEXT:    reloff 0
73# FLAGS-NEXT:    nreloc 0
74# FLAGS-NEXT:      type S_THREAD_LOCAL_REGULAR
75# FLAGS:       sectname __thread_bss
76# FLAGS-NEXT:   segname __DATA
77# FLAGS-NEXT:      addr
78# FLAGS-NEXT:      size 0x0000000000000008
79# FLAGS-NEXT:    offset 0
80# FLAGS-NEXT:     align 2^3 (8)
81# FLAGS-NEXT:    reloff 0
82# FLAGS-NEXT:    nreloc 0
83# FLAGS-NEXT:      type S_THREAD_LOCAL_ZEROFILL
84# FLAGS:       sectname __common
85# FLAGS-NEXT:   segname __DATA
86# FLAGS-NEXT:      addr
87# FLAGS-NEXT:      size 0x0000000000004000
88# FLAGS-NEXT:    offset 0
89# FLAGS-NEXT:     align 2^14 (16384)
90# FLAGS-NEXT:    reloff 0
91# FLAGS-NEXT:    nreloc 0
92# FLAGS-NEXT:      type S_ZEROFILL
93# FLAGS:       sectname __bss
94# FLAGS-NEXT:   segname __DATA
95# FLAGS-NEXT:      addr
96# FLAGS-NEXT:      size 0x0000000000002000
97# FLAGS-NEXT:    offset 0
98# FLAGS-NEXT:     align 2^0 (1)
99# FLAGS-NEXT:    reloff 0
100# FLAGS-NEXT:    nreloc 0
101# FLAGS-NEXT:      type S_ZEROFILL
102
103#--- libtlv.s
104.section __DATA,__thread_vars,thread_local_variables
105.globl _foo, _bar, _baz
106_foo:
107_bar:
108
109.text
110_baz:
111
112#--- test.s
113.globl _main
114_main:
115  mov _foo@TLVP(%rip), %rax
116  mov _bar@TLVP(%rip), %rax
117## Add a GOT entry to make sure we don't mix it up with TLVs
118  mov _baz@GOTPCREL(%rip), %rax
119  ret
120
121## Add some TLVs to test too, so that we can test the ordering
122## of __thread_ptrs, __thread_data, and __thread_bss.
123## Also add a .bss and a .comm for good measure too. Since they
124## are both zerofill, they end up after __thread_bss.
125.comm _com, 0x4000
126.bss
127.zero 0x2000
128
129.section __DATA,__thread_data,thread_local_regular
130_tfoo$tlv$init:
131  .quad 123
132
133.tbss _tbaz$tlv$init, 8, 3
134
135.section __DATA,__thread_vars,thread_local_variables
136.globl  _tfoo, _tbar
137_tfoo:
138  .quad  __tlv_bootstrap
139  .quad  0
140  .quad  _tfoo$tlv$init
141_tbaz:
142  .quad  __tlv_bootstrap
143  .quad  0
144  .quad  _tbaz$tlv$init
145