Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / stabs.s
blob145e7960b6657a77f78eaf10da16ed180a57ae3d
1 # REQUIRES: x86, shell
2 # UNSUPPORTED: system-windows
3 # RUN: rm -rf %t; split-file %s %t
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
6 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-debug.s -o %t/no-debug.o
7 ## Set modtimes of the files for deterministic test output.
8 # RUN: env TZ=GMT touch -t "197001010000.16" %t/test.o
9 # RUN: env TZ=GMT touch -t "197001010000.32" %t/foo.o
10 # RUN: llvm-ar rcsU %t/foo.a %t/foo.o
12 # RUN: ZERO_AR_DATE=0 %lld -lSystem %t/test.o %t/foo.o %t/no-debug.o -o %t/test
13 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
14 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.o \
15 # RUN: -D#TEST_TIME=0x10 -D#FOO_TIME=0x20
17 ## Check that we emit the right modtime even when the object file is in an
18 ## archive.
19 # RUN: ZERO_AR_DATE=0 %lld -lSystem %t/test.o %t/foo.a %t/no-debug.o -o %t/test
20 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
21 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
22 # RUN: -D#TEST_TIME=0x10 -D#FOO_TIME=0x20
24 ## Check that we don't emit modtimes if ZERO_AR_DATE is set.
25 # RUN: env ZERO_AR_DATE=1 %lld -lSystem %t/test.o %t/foo.o %t/no-debug.o \
26 # RUN: -o %t/test
27 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
28 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.o \
29 # RUN: -D#TEST_TIME=0 -D#FOO_TIME=0
30 # RUN: env %lld -lSystem %t/test.o %t/foo.a %t/no-debug.o \
31 # RUN: -o %t/test
32 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
33 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
34 # RUN: -D#TEST_TIME=0 -D#FOO_TIME=0
35 # RUN: env %lld -lSystem %t/test.o %t/no-debug.o \
36 # RUN: -all_load %t/foo.a -o %t/test
37 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
38 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
39 # RUN: -D#TEST_TIME=0 -D#FOO_TIME=0
40 # RUN: env %lld -lSystem %t/test.o %t/no-debug.o \
41 # RUN: -force_load %t/foo.a -o %t/test
42 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
43 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
44 # RUN: -D#TEST_TIME=0 -D#FOO_TIME=0
45 # RUN: env ZERO_AR_DATE=0 %lld -lSystem -reproducible %t/test.o %t/foo.o \
46 # RUN: %t/no-debug.o -o %t/test
47 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
48 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.o \
49 # RUN: -D#TEST_TIME=0 -D#FOO_TIME=0
51 ## Check that we emit absolute paths to the object files in our OSO entries
52 ## even if our inputs are relative paths.
53 # RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -o test
54 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
55 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.o \
56 # RUN: -D#TEST_TIME=0x10 -D#FOO_TIME=0x20
58 ## Check that we emit relative path to object files in OSO entries
59 ## when -oso_prefix <path> is used.
60 # RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t" -o %t/test-rel
61 # RUN: dsymutil -s %t/test-rel | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH
62 # RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t/" -o %t/test-rel
63 # RUN: dsymutil -s %t/test-rel | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH-NO-SLASH
64 # RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "." -o %t/test-rel-dot
65 # RUN: dsymutil -s %t/test-rel-dot | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-DOT
66 ## Set HOME to %t (for ~ to expand to)
67 # RUN: cd %t && env HOME=%t ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "~" -o %t/test-rel-tilde
68 # RUN: dsymutil -s %t/test-rel-tilde | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH
70 ## Check that we don't emit DWARF or stabs when -S is used
71 # RUN: %lld -lSystem test.o foo.o no-debug.o -S -o %t/test-no-debug
72 ## grep returns an exit code of 1 if it cannot match the intended pattern. We
73 ## expect to not find any entries which requires the exit code to be negated.
74 # RUN: llvm-nm -ap %t/test-no-debug | not grep -e ' - '
76 # RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.a no-debug.o -o %t/test
77 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
78 # RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
79 # RUN: -D#TEST_TIME=0x10 -D#FOO_TIME=0x20
81 # CHECK: Sections:
82 # CHECK-NEXT: Idx Name
83 # CHECK-NEXT: [[#TEXT_ID:]] __text
84 # CHECK-NEXT: [[#DATA_ID:]] __data
85 # CHECK-NEXT: [[#MORE_DATA_ID:]] more_data
86 # CHECK-NEXT: [[#COMM_ID:]] __common
87 # CHECK-NEXT: [[#MORE_TEXT_ID:]] more_text
89 # CHECK: (N_SO ) 00 0000 0000000000000000 '/tmp/test.cpp'
90 # CHECK-NEXT: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] '[[DIR]]/test.o'
91 # REL-PATH: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] '/test.o'
92 # REL-PATH-NO-SLASH: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] 'test.o'
93 # REL-DOT: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] 'test.o'
94 # CHECK-NEXT: (N_STSYM ) [[#%.2d,MORE_DATA_ID + 1]] 0000 [[#%.16x,STATIC:]] '_static_var'
95 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,MAIN:]] '_main'
96 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000006{{$}}
97 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,BAR:]] '_bar'
98 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000000{{$}}
99 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,BAR2:]] '_bar2'
100 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000001{{$}}
101 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,BAZ:]] '_baz'
102 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000000{{$}}
103 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,BAZ2:]] '_baz2'
104 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000002{{$}}
105 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,QUX:]] '_qux'
106 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000003{{$}}
107 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,QUUX:]] '_quux'
108 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000004{{$}}
109 # CHECK-NEXT: (N_GSYM ) [[#%.2d,DATA_ID + 1]] 0000 [[#%.16x,GLOB:]] '_global_var'
110 # CHECK-NEXT: (N_GSYM ) [[#%.2d,COMM_ID + 1]] 0000 [[#%.16x,ZERO:]] '_zero'
111 # CHECK-NEXT: (N_FUN ) [[#%.2d,MORE_TEXT_ID + 1]] 0000 [[#%.16x,FUN:]] '_fun'
112 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000001{{$}}
113 # CHECK-NEXT: (N_SO ) 01 0000 0000000000000000{{$}}
114 # CHECK-NEXT: (N_SO ) 00 0000 0000000000000000 '/foo.cpp'
115 # CHECK-NEXT: (N_OSO ) 03 0001 [[#%.16x,FOO_TIME]] '[[FOO_PATH]]'
116 # REL-PATH-NEXT: (N_OSO ) 03 0001 [[#%.16x,FOO_TIME]] '/foo.o'
117 # REL-PATH-NO-SLASH-NEXT: (N_OSO ) 03 0001 [[#%.16x,FOO_TIME]] 'foo.o'
118 # REL-DOT-NEXT: (N_OSO ) 03 0001 [[#%.16x,FOO_TIME]] 'foo.o'
119 # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,FOO:]] '_foo'
120 # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000001{{$}}
121 # CHECK-NEXT: (N_SO ) 01 0000 0000000000000000{{$}}
122 # CHECK-DAG: ( SECT ) [[#%.2d,MORE_DATA_ID + 1]] 0000 [[#STATIC]] '_static_var'
123 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#MAIN]] '_main'
124 # CHECK-DAG: ( ABS EXT) 00 0000 {{[0-9af]+}} '_abs'
125 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#FOO]] '_foo'
126 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#BAR]] '_bar'
127 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#BAR2]] '_bar2'
128 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#BAZ]] '_baz'
129 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#BAZ2]] '_baz2'
130 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#QUX]] '_qux'
131 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 [[#QUUX]] '_quux'
132 # CHECK-DAG: ( SECT EXT) [[#%.2d,DATA_ID + 1]] 0000 [[#GLOB]] '_global_var'
133 # CHECK-DAG: ( SECT EXT) [[#%.2d,COMM_ID + 1]] 0000 [[#ZERO]] '_zero'
134 # CHECK-DAG: ( SECT EXT) [[#%.2d,MORE_TEXT_ID + 1]] 0000 [[#FUN]] '_fun'
135 # CHECK-DAG: ( SECT EXT) [[#%.2d,TEXT_ID + 1]] 0000 {{[0-9a-f]+}} '_no_debug'
136 # CHECK-DAG: ( {{.*}}) {{[0-9]+}} 0010 {{[0-9a-f]+}} '__mh_execute_header'
137 # CHECK-DAG: ( {{.*}}) {{[0-9]+}} 0100 0000000000000000 'dyld_stub_binder'
138 # CHECK-EMPTY:
140 ## Check that we don't attempt to emit rebase opcodes for the debug sections
141 ## when building a PIE (since we have filtered the sections out).
142 # RUN: %lld -lSystem %t/test.o %t/foo.a %t/no-debug.o -o %t/test
143 # RUN: llvm-objdump --macho --rebase %t/test | FileCheck %s --check-prefix=PIE
144 # PIE: Rebase table:
145 # PIE-NEXT: segment section address type
146 # PIE-EMPTY:
148 #--- test.s
150 ## Make sure we don't create STABS entries for absolute symbols.
151 .globl _abs
152 _abs = 0x123
154 .section __DATA, __data
155 .globl _global_var
156 _global_var:
157 .quad 123
159 .section __DATA, more_data
160 _static_var:
161 .quad 123
163 .globl _zero
164 .zerofill __DATA,__common,_zero,4,2
166 .text
167 .globl _main, _bar, _bar2, _baz, _baz2, _qux, _quux
168 .alt_entry _baz
169 .alt_entry _qux
171 _bar:
172 _bar2:
173 .space 1
175 _baz:
176 _baz2:
177 .space 2
179 _main:
180 Lfunc_begin0:
181 callq _foo
182 retq
183 Lfunc_end0:
185 _qux:
186 .space 3
188 _quux:
189 .space 4
191 .section __DWARF,__debug_str,regular,debug
192 .asciz "test.cpp" ## string offset=0
193 .asciz "/tmp" ## string offset=9
194 .section __DWARF,__debug_abbrev,regular,debug
195 Lsection_abbrev:
196 .byte 1 ## Abbreviation Code
197 .byte 17 ## DW_TAG_compile_unit
198 .byte 1 ## DW_CHILDREN_yes
199 .byte 3 ## DW_AT_name
200 .byte 14 ## DW_FORM_strp
201 .byte 27 ## DW_AT_comp_dir
202 .byte 14 ## DW_FORM_strp
203 .byte 17 ## DW_AT_low_pc
204 .byte 1 ## DW_FORM_addr
205 .byte 18 ## DW_AT_high_pc
206 .byte 6 ## DW_FORM_data4
207 .byte 0 ## EOM(1)
208 .byte 0 ## EOM(2)
209 .byte 0 ## EOM(3)
210 .section __DWARF,__debug_info,regular,debug
211 .set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
212 .long Lset0
213 Ldebug_info_start0:
214 .short 4 ## DWARF version number
215 .set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
216 .long Lset1
217 .byte 8 ## Address Size (in bytes)
218 .byte 1 ## Abbrev [1] 0xb:0x48 DW_TAG_compile_unit
219 .long 0 ## DW_AT_name
220 .long 9 ## DW_AT_comp_dir
221 .quad Lfunc_begin0 ## DW_AT_low_pc
222 .set Lset3, Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
223 .long Lset3
224 .byte 0 ## End Of Children Mark
225 Ldebug_info_end0:
227 .section OTHER,more_text,regular,pure_instructions
228 .globl _fun
229 _fun:
232 .subsections_via_symbols
234 #--- foo.s
235 .text
236 .globl _foo
237 _foo:
238 Lfunc_begin0:
239 retq
240 Lfunc_end0:
242 .section __DWARF,__debug_str,regular,debug
243 .asciz "foo.cpp" ## string offset=0
244 .asciz "" ## string offset=8
245 .section __DWARF,__debug_abbrev,regular,debug
246 Lsection_abbrev:
247 .byte 1 ## Abbreviation Code
248 .byte 17 ## DW_TAG_compile_unit
249 .byte 1 ## DW_CHILDREN_yes
250 .byte 3 ## DW_AT_name
251 .byte 14 ## DW_FORM_strp
252 .byte 27 ## DW_AT_comp_dir
253 .byte 14 ## DW_FORM_strp
254 .byte 17 ## DW_AT_low_pc
255 .byte 1 ## DW_FORM_addr
256 .byte 18 ## DW_AT_high_pc
257 .byte 6 ## DW_FORM_data4
258 .byte 0 ## EOM(1)
259 .byte 0 ## EOM(2)
260 .byte 0 ## EOM(3)
261 .section __DWARF,__debug_info,regular,debug
262 .set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
263 .long Lset0
264 Ldebug_info_start0:
265 .short 4 ## DWARF version number
266 .set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
267 .long Lset1
268 .byte 8 ## Address Size (in bytes)
269 .byte 1 ## Abbrev [1] 0xb:0x48 DW_TAG_compile_unit
270 .long 0 ## DW_AT_name
271 .long 8 ## DW_AT_comp_dir
272 .quad Lfunc_begin0 ## DW_AT_low_pc
273 .set Lset3, Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
274 .long Lset3
275 .byte 0 ## End Of Children Mark
276 Ldebug_info_end0:
278 .section __DWARF,__debug_aranges,regular,debug
279 ltmp1:
280 .byte 0
282 .subsections_via_symbols
284 #--- no-debug.s
285 ## This file has no debug info.
286 .text
287 .globl _no_debug
288 _no_debug: