2 # RUN: rm -rf %t; split-file %s %t
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
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
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
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:]]
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
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
42 # FLAGS-NEXT: size 0x0000000000000008
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
51 # FLAGS-NEXT: size 0x0000000000000030
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
60 # FLAGS-NEXT: size 0x0000000000000010
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
69 # FLAGS-NEXT: size 0x0000000000000008
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
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
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
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
104 .section __DATA,__thread_vars,thread_local_variables
105 .globl _foo, _bar, _baz
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
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.
129 .section __DATA,__thread_data,thread_local_regular
133 .tbss _tbaz$tlv$init, 8, 3
135 .section __DATA,__thread_vars,thread_local_variables
138 .quad __tlv_bootstrap
142 .quad __tlv_bootstrap