Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / tlv.s
blobe71fe76980e2480b27eaf8cf54c2dfbd3b74f51c
1 # REQUIRES: x86
2 # RUN: rm -rf %t; split-file %s %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/regular.s -o %t/regular.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/tbss.s -o %t/tbss.o
6 # RUN: %lld -lSystem -no_pie -o %t/regular-no-pie %t/regular.o
7 # RUN: llvm-otool -hv %t/regular-no-pie | FileCheck %s --check-prefix=HEADER
8 # RUN: llvm-objdump -d --bind --rebase %t/regular-no-pie | FileCheck %s --check-prefixes=REG,LINKEDIT
9 # RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular-no-pie | \
10 # RUN: FileCheck %s --check-prefix=REG-TLVP
12 # RUN: %lld -lSystem %t/regular.o -o %t/regular-pie
13 # RUN: llvm-otool -hv %t/regular-pie | FileCheck %s --check-prefix=HEADER
14 # RUN: llvm-objdump -d --bind --rebase %t/regular-pie | FileCheck %s --check-prefixes=REG,LINKEDIT
15 # RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular-pie | \
16 # RUN: FileCheck %s --check-prefix=REG-TLVP
18 # RUN: %lld -lSystem %t/tbss.o -o %t/tbss -e _f
19 # RUN: llvm-objdump -d --bind --rebase %t/tbss | FileCheck %s --check-prefixes=TBSS,LINKEDIT
20 # RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/tbss | \
21 # RUN: FileCheck %s --check-prefix=TBSS-TLVP
23 # RUN: %lld -lSystem %t/regular.o %t/tbss.o -o %t/regular-and-tbss
24 # RUN: llvm-objdump -d --bind --rebase %t/regular-and-tbss | FileCheck %s --check-prefixes=REG,TBSS,LINKEDIT
25 # RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular-and-tbss | \
26 # RUN: FileCheck %s --check-prefix=REG-TBSS-TLVP
27 # RUN: llvm-objdump --section-headers %t/regular-and-tbss | FileCheck %s --check-prefix=SECTIONS
29 ## Check that we always put __thread_bss immediately after __thread_data,
30 ## regardless of the order of the input files.
31 # RUN: %lld -lSystem %t/tbss.o %t/regular.o -o %t/regular-and-tbss
32 # RUN: llvm-objdump --section-headers %t/regular-and-tbss | FileCheck %s --check-prefix=SECTIONS
34 # HEADER: MH_HAS_TLV_DESCRIPTORS
36 # REG: <_main>:
37 # REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_foo>
38 # REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_bar>
39 # REG-NEXT: retq
41 # TBSS: <_f>:
42 # TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_baz>
43 # TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_qux>
44 # TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_hoge>
45 # TBSS-NEXT: retq
47 # REG-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
48 # REG-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
49 # REG-TLVP-NEXT: 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00
51 # TBSS-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
52 # TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
53 # TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00
55 # REG-TBSS-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
56 # REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
57 # REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00
58 # REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
59 # REG-TBSS-TLVP-NEXT: 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
60 # REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00
61 # REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
62 # REG-TBSS-TLVP-NEXT: 30 00 00 00 00 00 00 00
64 ## Make sure we don't emit rebase opcodes for relocations in __thread_vars.
65 # LINKEDIT: Rebase table:
66 # LINKEDIT-NEXT: segment section address type
67 # LINKEDIT-EMPTY:
68 # LINKEDIT-NEXT: Bind table:
69 # LINKEDIT: __DATA __thread_vars 0x{{[0-9a-f]*}} pointer 0 libSystem __tlv_bootstrap
70 # LINKEDIT: __DATA __thread_vars 0x{{[0-9a-f]*}} pointer 0 libSystem __tlv_bootstrap
72 ## Make sure we have an odd number of tlv vars, and that the __thread_vars
73 ## section starts 16-bytes aligned. This is the setup required for __thread_data
74 ## not to be automatically 16-bytes aligned, ensuring the linker does its
75 ## expected job of aligning _hoge$tlv$init.
76 # SECTIONS: __thread_vars {{[0-9]+}}8 {{[0-9]+}}0
77 # SECTIONS: __thread_data
78 # SECTIONS: more_thread_data
79 # SECTIONS-NEXT: __thread_bss
81 #--- regular.s
82 .globl _main
83 _main:
84 mov _foo@TLVP(%rip), %rax
85 mov _bar@TLVP(%rip), %rax
86 ret
88 .section __DATA,__thread_data,thread_local_regular
89 _foo$tlv$init:
90 .quad 123
92 .section __DATA,more_thread_data,thread_local_regular
93 _bar$tlv$init:
94 .quad 123
96 .section __DATA,__thread_vars,thread_local_variables
97 .globl _foo, _bar
98 _foo:
99 .quad __tlv_bootstrap
100 .quad 0
101 .quad _foo$tlv$init
102 _bar:
103 .quad __tlv_bootstrap
104 .quad 0
105 .quad _bar$tlv$init
107 #--- tbss.s
109 .globl _f
111 mov _baz@TLVP(%rip), %rax
112 mov _qux@TLVP(%rip), %rax
113 mov _hoge@TLVP(%rip), %rax
116 .tbss _baz$tlv$init, 8, 3
117 .tbss _qux$tlv$init, 8, 3
118 .tbss _hoge$tlv$init, 16, 4
120 .section __DATA,__thread_vars,thread_local_variables
121 _baz:
122 .quad __tlv_bootstrap
123 .quad 0
124 .quad _baz$tlv$init
125 _qux:
126 .quad __tlv_bootstrap
127 .quad 0
128 .quad _qux$tlv$init
129 _hoge:
130 .quad __tlv_bootstrap
131 .quad 0
132 .quad _hoge$tlv$init