xref: /llvm-project/lld/test/MachO/stabs.s (revision 71de61259a513120796c294568754b0b9e2ee085)
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
11
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
16
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
23
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
50
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
57
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
69
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 ' - '
75
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
80
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
88
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:
139
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:
147
148## Check that an absolute DW_AT_name does not have DW_AT_comp_dir prepended
149## when forming N_SO.
150# RUN: llvm-mc -filetype obj -triple=x86_64-apple-darwin %t/abs-path.s -o %t/abs-path.o
151# RUN: %lld %t/abs-path.o -o %t/test
152# RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | FileCheck %s --check-prefix=ABS-PATH
153# ABS-PATH:      (N_SO         ) 00      0000   0000000000000000   '/foo.cpp'
154
155#--- test.s
156
157## Make sure we don't create STABS entries for absolute symbols.
158.globl _abs
159_abs = 0x123
160
161.section __DATA, __data
162.globl _global_var
163_global_var:
164  .quad 123
165
166.section __DATA, more_data
167_static_var:
168  .quad 123
169
170.globl  _zero
171.zerofill __DATA,__common,_zero,4,2
172
173.text
174.globl  _main, _bar, _bar2, _baz, _baz2, _qux, _quux
175.alt_entry _baz
176.alt_entry _qux
177
178_bar:
179_bar2:
180  .space 1
181
182_baz:
183_baz2:
184  .space 2
185
186_main:
187Lfunc_begin0:
188  callq _foo
189  retq
190Lfunc_end0:
191
192_qux:
193  .space 3
194
195_quux:
196  .space 4
197
198.section  __DWARF,__debug_str,regular,debug
199  .asciz  "test.cpp"             ## string offset=0
200  .asciz  "/tmp"                 ## string offset=9
201.section  __DWARF,__debug_abbrev,regular,debug
202Lsection_abbrev:
203  .byte  1                       ## Abbreviation Code
204  .byte  17                      ## DW_TAG_compile_unit
205  .byte  1                       ## DW_CHILDREN_yes
206  .byte  3                       ## DW_AT_name
207  .byte  14                      ## DW_FORM_strp
208  .byte  27                      ## DW_AT_comp_dir
209  .byte  14                      ## DW_FORM_strp
210  .byte  17                      ## DW_AT_low_pc
211  .byte  1                       ## DW_FORM_addr
212  .byte  18                      ## DW_AT_high_pc
213  .byte  6                       ## DW_FORM_data4
214  .byte  0                       ## EOM(1)
215  .byte  0                       ## EOM(2)
216  .byte  0                       ## EOM(3)
217.section  __DWARF,__debug_info,regular,debug
218.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
219  .long  Lset0
220Ldebug_info_start0:
221  .short  4                       ## DWARF version number
222.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
223  .long  Lset1
224  .byte  8                       ## Address Size (in bytes)
225  .byte  1                       ## Abbrev [1] 0xb:0x48 DW_TAG_compile_unit
226  .long  0                       ## DW_AT_name
227  .long  9                       ## DW_AT_comp_dir
228  .quad  Lfunc_begin0            ## DW_AT_low_pc
229.set Lset3, Lfunc_end0-Lfunc_begin0     ## DW_AT_high_pc
230  .long  Lset3
231  .byte  0                       ## End Of Children Mark
232Ldebug_info_end0:
233
234.section OTHER,more_text,regular,pure_instructions
235.globl _fun
236_fun:
237  ret
238
239.subsections_via_symbols
240
241#--- foo.s
242.text
243.globl  _foo
244_foo:
245Lfunc_begin0:
246  retq
247Lfunc_end0:
248
249.section  __DWARF,__debug_str,regular,debug
250  .asciz  "foo.cpp"              ## string offset=0
251  .asciz  ""                     ## string offset=8
252.section  __DWARF,__debug_abbrev,regular,debug
253Lsection_abbrev:
254  .byte  1                       ## Abbreviation Code
255  .byte  17                      ## DW_TAG_compile_unit
256  .byte  1                       ## DW_CHILDREN_yes
257  .byte  3                       ## DW_AT_name
258  .byte  14                      ## DW_FORM_strp
259  .byte  27                      ## DW_AT_comp_dir
260  .byte  14                      ## DW_FORM_strp
261  .byte  17                      ## DW_AT_low_pc
262  .byte  1                       ## DW_FORM_addr
263  .byte  18                      ## DW_AT_high_pc
264  .byte  6                       ## DW_FORM_data4
265  .byte  0                       ## EOM(1)
266  .byte  0                       ## EOM(2)
267  .byte  0                       ## EOM(3)
268.section  __DWARF,__debug_info,regular,debug
269.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
270  .long  Lset0
271Ldebug_info_start0:
272  .short  4                       ## DWARF version number
273.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
274  .long  Lset1
275  .byte  8                       ## Address Size (in bytes)
276  .byte  1                       ## Abbrev [1] 0xb:0x48 DW_TAG_compile_unit
277  .long  0                       ## DW_AT_name
278  .long  8                       ## DW_AT_comp_dir
279  .quad  Lfunc_begin0            ## DW_AT_low_pc
280.set Lset3, Lfunc_end0-Lfunc_begin0     ## DW_AT_high_pc
281  .long  Lset3
282  .byte  0                       ## End Of Children Mark
283Ldebug_info_end0:
284
285.section  __DWARF,__debug_aranges,regular,debug
286ltmp1:
287  .byte 0
288
289.subsections_via_symbols
290
291#--- no-debug.s
292## This file has no debug info.
293.text
294.globl _no_debug
295_no_debug:
296  ret
297
298#--- abs-path.s
299.text
300.globl  _main
301_main:
302Lfunc_begin0:
303  retq
304Lfunc_end0:
305
306.section  __DWARF,__debug_str,regular,debug
307  .asciz  "/foo.cpp"             ## string offset=0
308  .asciz  "/tmp"                 ## string offset=9
309.section  __DWARF,__debug_abbrev,regular,debug
310Lsection_abbrev:
311  .byte  1                       ## Abbreviation Code
312  .byte  17                      ## DW_TAG_compile_unit
313  .byte  1                       ## DW_CHILDREN_yes
314  .byte  3                       ## DW_AT_name
315  .byte  14                      ## DW_FORM_strp
316  .byte  27                      ## DW_AT_comp_dir
317  .byte  14                      ## DW_FORM_strp
318  .byte  17                      ## DW_AT_low_pc
319  .byte  1                       ## DW_FORM_addr
320  .byte  18                      ## DW_AT_high_pc
321  .byte  6                       ## DW_FORM_data4
322  .byte  0                       ## EOM(1)
323  .byte  0                       ## EOM(2)
324  .byte  0                       ## EOM(3)
325.section  __DWARF,__debug_info,regular,debug
326.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
327  .long  Lset0
328Ldebug_info_start0:
329  .short  4                       ## DWARF version number
330.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
331  .long  Lset1
332  .byte  8                       ## Address Size (in bytes)
333  .byte  1                       ## Abbrev [1] 0xb:0x48 DW_TAG_compile_unit
334  .long  0                       ## DW_AT_name
335  .long  9                       ## DW_AT_comp_dir
336  .quad  Lfunc_begin0            ## DW_AT_low_pc
337.set Lset3, Lfunc_end0-Lfunc_begin0     ## DW_AT_high_pc
338  .long  Lset3
339  .byte  0                       ## End Of Children Mark
340Ldebug_info_end0:
341
342.section  __DWARF,__debug_aranges,regular,debug
343ltmp1:
344  .byte 0
345
346.subsections_via_symbols
347