1 # REQUIRES: x86, llvm-64-bits
3 # RUN: rm -rf %t; split-file %s %t
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
6 # RUN: %t/basics.s -o %t/basics.o
8 ## Check that .private_extern symbols are marked as local in the symbol table
9 ## and aren't in the export trie.
10 # RUN: %lld -lSystem -dead_strip -map %t/map -u _ref_private_extern_u \
11 # RUN: %t/basics.o -o %t/basics
12 # RUN: llvm-objdump --syms --section-headers %t/basics | \
13 # RUN: FileCheck --check-prefix=EXEC --implicit-check-not _unref %s
14 # RUN: llvm-objdump --macho --section=__DATA,__ref_section \
15 # RUN: --exports-trie --indirect-symbols %t/basics | \
16 # RUN: FileCheck --check-prefix=EXECDATA --implicit-check-not _unref %s
17 # RUN: llvm-otool -l %t/basics | grep -q 'segname __PAGEZERO'
18 # EXEC-LABEL: Sections:
22 # EXEC-NEXT: __ref_section
24 # EXEC-LABEL: SYMBOL TABLE:
25 # EXEC-DAG: l {{.*}} _ref_data
26 # EXEC-DAG: l {{.*}} _ref_local
27 # EXEC-DAG: l {{.*}} _ref_from_no_dead_strip_globl
28 # EXEC-DAG: l {{.*}} _no_dead_strip_local
29 # EXEC-DAG: l {{.*}} _ref_from_no_dead_strip_local
30 # EXEC-DAG: l {{.*}} _ref_private_extern_u
31 # EXEC-DAG: l {{.*}} _main
32 # EXEC-DAG: l {{.*}} _ref_private_extern
33 # EXEC-DAG: g {{.*}} _no_dead_strip_globl
34 # EXEC-DAG: g {{.*}} _ref_com
35 # EXEC-DAG: g {{.*}} __mh_execute_header
36 # EXECDATA-LABEL: Indirect symbols
38 # EXECDATA-NEXT: LOCAL
39 # EXECDATA-LABEL: Contents of (__DATA,__ref_section) section
40 # EXECDATA-NEXT: 04 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00
41 # EXECDATA-LABEL: Exports trie:
42 # EXECDATA-DAG: _ref_com
43 # EXECDATA-DAG: _no_dead_strip_globl
44 # EXECDATA-DAG: __mh_execute_header
46 ## Check that dead stripped symbols get listed properly.
47 # RUN: FileCheck --check-prefix=MAP %s < %t/map
50 # MAP-LABEL: Dead Stripped Symbols
51 # MAP-DAG: <<dead>> 0x00000001 [ 2] _unref_com
52 # MAP-DAG: <<dead>> 0x00000008 [ 2] _unref_data
53 # MAP-DAG: <<dead>> 0x00000006 [ 2] _unref_extern
54 # MAP-DAG: <<dead>> 0x00000001 [ 2] _unref_local
55 # MAP-DAG: <<dead>> 0x00000007 [ 2] _unref_private_extern
56 # MAP-DAG: <<dead>> 0x00000008 [ 2] l_unref_data
58 ## Run dead stripping on code without any dead symbols.
59 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
60 # RUN: %t/no-dead-symbols.s -o %t/no-dead-symbols.o
61 # RUN: %lld -lSystem -dead_strip -map %t/no-dead-symbols-map \
62 # RUN: %t/no-dead-symbols.o -o %t/no-dead-symbols
63 ## Mark the end of the file with a string.
64 # RUN: FileCheck --check-prefix=NODEADSYMBOLS %s < %t/no-dead-symbols-map
66 # NODEADSYMBOLS-LABEL: # Symbols:
67 # NODEADSYMBOLS-NEXT: # Address Size File Name
68 # NODEADSYMBOLS-NEXT: _main
69 # NODEADSYMBOLS-LABEL: # Dead Stripped Symbols:
70 # NODEADSYMBOLS-NEXT: # Size File Name
71 # NODEADSYMBOLS-EMPTY:
73 # RUN: %lld -dylib -dead_strip -u _ref_private_extern_u %t/basics.o -o %t/basics.dylib
74 # RUN: llvm-objdump --syms %t/basics.dylib | \
75 # RUN: FileCheck --check-prefix=DYLIB --implicit-check-not _unref %s
76 # RUN: %lld -bundle -dead_strip -u _ref_private_extern_u %t/basics.o -o %t/basics.dylib
77 # RUN: llvm-objdump --syms %t/basics.dylib | \
78 # RUN: FileCheck --check-prefix=DYLIB --implicit-check-not _unref %s
79 # DYLIB-LABEL: SYMBOL TABLE:
80 # DYLIB-DAG: l {{.*}} _ref_data
81 # DYLIB-DAG: l {{.*}} _ref_local
82 # DYLIB-DAG: l {{.*}} _ref_from_no_dead_strip_globl
83 # DYLIB-DAG: l {{.*}} _no_dead_strip_local
84 # DYLIB-DAG: l {{.*}} _ref_from_no_dead_strip_local
85 # DYLIB-DAG: l {{.*}} _ref_private_extern_u
86 # DYLIB-DAG: l {{.*}} _ref_private_extern
87 # DYLIB-DAG: g {{.*}} _ref_com
88 # DYLIB-DAG: g {{.*}} _unref_com
89 # DYLIB-DAG: g {{.*}} _unref_extern
90 # DYLIB-DAG: g {{.*}} _no_dead_strip_globl
92 ## Extern symbols aren't stripped from executables with -export_dynamic
93 # RUN: %lld -lSystem -dead_strip -export_dynamic -u _ref_private_extern_u \
94 # RUN: %t/basics.o -o %t/basics-export-dyn
95 # RUN: llvm-objdump --syms --section-headers %t/basics-export-dyn | \
96 # RUN: FileCheck --check-prefix=EXECDYN %s
97 # EXECDYN-LABEL: Sections:
99 # EXECDYN-NEXT: __text
100 # EXECDYN-NEXT: __got
101 # EXECDYN-NEXT: __ref_section
102 # EXECDYN-NEXT: __common
103 # EXECDYN-LABEL: SYMBOL TABLE:
104 # EXECDYN-DAG: l {{.*}} _ref_data
105 # EXECDYN-DAG: l {{.*}} _ref_local
106 # EXECDYN-DAG: l {{.*}} _ref_from_no_dead_strip_globl
107 # EXECDYN-DAG: l {{.*}} _no_dead_strip_local
108 # EXECDYN-DAG: l {{.*}} _ref_from_no_dead_strip_local
109 # EXECDYN-DAG: l {{.*}} _ref_private_extern_u
110 # EXECDYN-DAG: l {{.*}} _main
111 # EXECDYN-DAG: l {{.*}} _ref_private_extern
112 # EXECDYN-DAG: g {{.*}} _ref_com
113 # EXECDYN-DAG: g {{.*}} _unref_com
114 # EXECDYN-DAG: g {{.*}} _unref_extern
115 # EXECDYN-DAG: g {{.*}} _no_dead_strip_globl
116 # EXECDYN-DAG: g {{.*}} __mh_execute_header
118 ## Absolute symbol handling.
119 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
120 # RUN: %t/abs.s -o %t/abs.o
121 # RUN: %lld -lSystem -dead_strip %t/abs.o -o %t/abs
122 # RUN: llvm-objdump --macho --syms --exports-trie %t/abs | \
123 # RUN: FileCheck --check-prefix=ABS %s
124 #ABS-LABEL: SYMBOL TABLE:
125 #ABS-NEXT: g {{.*}} _main
126 #ABS-NEXT: g *ABS* _abs1
127 #ABS-NEXT: g {{.*}} __mh_execute_header
128 #ABS-LABEL: Exports trie:
129 #ABS-NEXT: __mh_execute_header
131 #ABS-NEXT: _abs1 [absolute]
133 ## Check that symbols from -exported_symbol(s_list) are preserved.
134 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
135 # RUN: %t/exported-symbol.s -o %t/exported-symbol.o
136 # RUN: %lld -lSystem -dead_strip -exported_symbol _my_exported_symbol \
137 # RUN: %t/exported-symbol.o -o %t/exported-symbol
138 # RUN: llvm-objdump --syms %t/exported-symbol | \
139 # RUN: FileCheck --check-prefix=EXPORTEDSYMBOL --implicit-check-not _unref %s
140 # EXPORTEDSYMBOL-LABEL: SYMBOL TABLE:
141 # EXPORTEDSYMBOL-NEXT: l {{.*}} _main
142 # EXPORTEDSYMBOL-NEXT: l {{.*}} __mh_execute_header
143 # EXPORTEDSYMBOL-NEXT: g {{.*}} _my_exported_symbol
145 ## Check that mod_init_funcs and mod_term_funcs are not stripped.
146 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
147 # RUN: %t/mod-funcs.s -o %t/mod-funcs.o
148 # RUN: %lld -lSystem -dead_strip %t/mod-funcs.o -o %t/mod-funcs
149 # RUN: llvm-objdump --syms %t/mod-funcs | \
150 # RUN: FileCheck --check-prefix=MODFUNCS --implicit-check-not _unref %s
151 # MODFUNCS-LABEL: SYMBOL TABLE:
152 # MODFUNCS-NEXT: l {{.*}} _ref_from_init
153 # MODFUNCS-NEXT: l {{.*}} _ref_init
154 # MODFUNCS-NEXT: l {{.*}} _ref_from_term
155 # MODFUNCS-NEXT: l {{.*}} _ref_term
156 # MODFUNCS-NEXT: g {{.*}} _main
157 # MODFUNCS-NEXT: g {{.*}} __mh_execute_header
159 ## Check that DylibSymbols in dead subsections are stripped: They should
160 ## not be in the import table and should have no import stubs.
161 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
162 # RUN: %t/dylib.s -o %t/dylib.o
163 # RUN: %lld -dylib -dead_strip %t/dylib.o -o %t/dylib.dylib
164 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
165 # RUN: %t/strip-dylib-ref.s -o %t/strip-dylib-ref.o
166 # RUN: %lld -lSystem -dead_strip %t/strip-dylib-ref.o %t/dylib.dylib \
167 # RUN: -o %t/strip-dylib-ref -U _ref_undef_fun -U _unref_undef_fun
168 # RUN: llvm-objdump --syms --bind --lazy-bind --weak-bind %t/strip-dylib-ref | \
169 # RUN: FileCheck --check-prefix=STRIPDYLIB --implicit-check-not _unref %s
170 # STRIPDYLIB: SYMBOL TABLE:
171 # STRIPDYLIB-NEXT: l {{.*}} __dyld_private
172 # STRIPDYLIB-NEXT: g {{.*}} _main
173 # STRIPDYLIB-NEXT: g {{.*}} __mh_execute_header
174 # STRIPDYLIB-NEXT: *UND* dyld_stub_binder
175 # STRIPDYLIB-NEXT: *UND* _ref_dylib_fun
176 # STRIPDYLIB-NEXT: *UND* _ref_undef_fun
177 # STRIPDYLIB: Bind table:
178 # STRIPDYLIB: Lazy bind table:
179 # STRIPDYLIB: __DATA __la_symbol_ptr {{.*}} flat-namespace _ref_undef_fun
180 # STRIPDYLIB: __DATA __la_symbol_ptr {{.*}} dylib _ref_dylib_fun
181 # STRIPDYLIB: Weak bind table:
182 ## Stubs smoke check: There should be two stubs entries, not four, but we
183 ## don't verify that they belong to _ref_undef_fun and _ref_dylib_fun.
184 # RUN: llvm-objdump -d --section=__stubs --section=__stub_helper \
185 # RUN: %t/strip-dylib-ref |FileCheck --check-prefix=STUBS %s
186 # STUBS-LABEL: <__stubs>:
190 # STUBS-LABEL: <__stub_helper>:
195 ## An undefined symbol referenced from a dead-stripped function shouldn't
196 ## produce a diagnostic:
197 # RUN: %lld -lSystem -dead_strip %t/strip-dylib-ref.o %t/dylib.dylib \
198 # RUN: -o %t/strip-dylib-ref -U _ref_undef_fun
200 ## Check that referenced undefs are kept with -undefined dynamic_lookup.
201 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
202 # RUN: %t/ref-undef.s -o %t/ref-undef.o
203 # RUN: %lld -lSystem -dead_strip %t/ref-undef.o \
204 # RUN: -o %t/ref-undef -undefined dynamic_lookup
205 # RUN: llvm-objdump --syms --lazy-bind %t/ref-undef | \
206 # RUN: FileCheck --check-prefix=STRIPDYNLOOKUP %s
207 # STRIPDYNLOOKUP: SYMBOL TABLE:
208 # STRIPDYNLOOKUP: *UND* _ref_undef_fun
209 # STRIPDYNLOOKUP: Lazy bind table:
210 # STRIPDYNLOOKUP: __DATA __la_symbol_ptr {{.*}} flat-namespace _ref_undef_fun
212 ## S_ATTR_LIVE_SUPPORT tests.
213 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
214 # RUN: %t/live-support.s -o %t/live-support.o
215 # RUN: %lld -lSystem -dead_strip %t/live-support.o %t/dylib.dylib \
216 # RUN: -U _ref_undef_fun -U _unref_undef_fun -o %t/live-support
217 # RUN: llvm-objdump --syms %t/live-support | \
218 # RUN: FileCheck --check-prefix=LIVESUPP --implicit-check-not _unref %s
219 # LIVESUPP-LABEL: SYMBOL TABLE:
220 # LIVESUPP-NEXT: l {{.*}} _ref_ls_fun_fw
221 # LIVESUPP-NEXT: l {{.*}} _ref_ls_fun_bw
222 # LIVESUPP-NEXT: l {{.*}} _ref_ls_dylib_fun
223 # LIVESUPP-NEXT: l {{.*}} _ref_ls_undef_fun
224 # LIVESUPP-NEXT: l {{.*}} __dyld_private
225 # LIVESUPP-NEXT: g {{.*}} _main
226 # LIVESUPP-NEXT: g {{.*}} _bar
227 # LIVESUPP-NEXT: g {{.*}} _foo
228 # LIVESUPP-NEXT: g {{.*}} __mh_execute_header
229 # LIVESUPP-NEXT: *UND* dyld_stub_binder
230 # LIVESUPP-NEXT: *UND* _ref_dylib_fun
231 # LIVESUPP-NEXT: *UND* _ref_undef_fun
233 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
234 # RUN: %t/live-support-iterations.s -o %t/live-support-iterations.o
235 # RUN: %lld -lSystem -dead_strip %t/live-support-iterations.o \
236 # RUN: -o %t/live-support-iterations
237 # RUN: llvm-objdump --syms %t/live-support-iterations | \
238 # RUN: FileCheck --check-prefix=LIVESUPP2 --implicit-check-not _unref %s
239 # LIVESUPP2-LABEL: SYMBOL TABLE:
240 # LIVESUPP2-NEXT: l {{.*}} _bar
241 # LIVESUPP2-NEXT: l {{.*}} _foo_refd
242 # LIVESUPP2-NEXT: l {{.*}} _bar_refd
243 # LIVESUPP2-NEXT: l {{.*}} _baz
244 # LIVESUPP2-NEXT: l {{.*}} _baz_refd
245 # LIVESUPP2-NEXT: l {{.*}} _foo
246 # LIVESUPP2-NEXT: g {{.*}} _main
247 # LIVESUPP2-NEXT: g {{.*}} __mh_execute_header
249 ## Dead stripping should not remove the __TEXT,__unwind_info
250 ## and __TEXT,__gcc_except_tab functions, but it should still
251 ## remove the unreferenced function __Z5unref.
252 ## The reference to ___gxx_personality_v0 should also not be
254 ## (Need to use darwin19.0.0 to make -mc emit __LD,__compact_unwind.)
255 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 \
256 # RUN: %t/unwind.s -o %t/unwind.o
257 # RUN: %lld -lc++ -lSystem -dead_strip %t/unwind.o -o %t/unwind
258 # RUN: llvm-objdump --syms %t/unwind | \
259 # RUN: FileCheck --check-prefix=UNWIND --implicit-check-not unref %s
260 # RUN: llvm-otool -l %t/unwind | FileCheck --check-prefix=UNWINDSECT %s
261 # UNWINDSECT-DAG: sectname __unwind_info
262 # UNWINDSECT-DAG: sectname __gcc_except_tab
263 # UNWIND-LABEL: SYMBOL TABLE:
264 # UNWIND-NEXT: l O __TEXT,__gcc_except_tab GCC_except_table1
265 # UNWIND-NEXT: l O __DATA,__data __dyld_private
266 # UNWIND-NEXT: g F __TEXT,__text _main
267 # UNWIND-NEXT: g F __TEXT,__text __mh_execute_header
268 # UNWIND-NEXT: *UND* dyld_stub_binder
269 # UNWIND-NEXT: *UND* __ZTIi
270 # UNWIND-NEXT: *UND* ___cxa_allocate_exception
271 # UNWIND-NEXT: *UND* ___cxa_begin_catch
272 # UNWIND-NEXT: *UND* ___cxa_end_catch
273 # UNWIND-NEXT: *UND* ___cxa_throw
274 # UNWIND-NEXT: *UND* ___gxx_personality_v0
275 # UNWIND-NOT: GCC_except_table0
277 ## If a dead stripped function has a strong ref to a dylib symbol but
278 ## a live function only a weak ref, the dylib is still not a WEAK_DYLIB.
279 ## This matches ld64.
280 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
281 # RUN: %t/weak-ref.s -o %t/weak-ref.o
282 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
283 # RUN: %t/strong-dead-ref.s -o %t/strong-dead-ref.o
284 # RUN: %lld -lSystem -dead_strip %t/weak-ref.o %t/strong-dead-ref.o \
285 # RUN: %t/dylib.dylib -o %t/weak-ref
286 # RUN: llvm-otool -l %t/weak-ref | FileCheck -DDIR=%t --check-prefix=WEAK %s
287 # WEAK: cmd LC_LOAD_DYLIB
289 # WEAK-NEXT: name /usr/lib/libSystem.dylib
290 # WEAK: cmd LC_LOAD_DYLIB
292 # WEAK-NEXT: name [[DIR]]/dylib.dylib
294 ## A strong symbol that would override a weak import does not emit the
295 ## "this overrides a weak import" opcode if it is dead-stripped.
296 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
297 # RUN: %t/weak-dylib.s -o %t/weak-dylib.o
298 # RUN: %lld -dylib -dead_strip %t/weak-dylib.o -o %t/weak-dylib.dylib
299 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
300 # RUN: %t/dead-weak-override.s -o %t/dead-weak-override.o
301 # RUN: %lld -dead_strip %t/dead-weak-override.o %t/weak-dylib.dylib \
302 # RUN: -o %t/dead-weak-override
303 # RUN: llvm-objdump --macho --weak-bind --private-header \
304 # RUN: %t/dead-weak-override | FileCheck --check-prefix=DEADWEAK %s
305 # DEADWEAK-NOT: WEAK_DEFINES
306 # DEADWEAK: Weak bind table:
307 # DEADWEAK: segment section address type addend symbol
308 # DEADWEAK-NOT: strong _weak_in_dylib
310 ## Stripped symbols should not be in the debug info stabs entries.
311 # RUN: llvm-mc -g -filetype=obj -triple=x86_64-apple-macos \
312 # RUN: %t/debug.s -o %t/debug.o
313 # RUN: %lld -lSystem -dead_strip %t/debug.o -o %t/debug
314 # RUN: dsymutil -s %t/debug | FileCheck --check-prefix=EXECSTABS %s
315 # EXECSTABS-NOT: N_FUN {{.*}} '_unref'
316 # EXECSTABS: N_FUN {{.*}} '_main'
317 # EXECSTABS-NOT: N_FUN {{.*}} '_unref'
319 # RUN: llvm-mc -g -filetype=obj -triple=x86_64-apple-macos \
320 # RUN: %t/literals.s -o %t/literals.o
321 # RUN: %lld -dylib -dead_strip %t/literals.o -o %t/literals
322 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" --section="__DATA,str_ptrs" \
323 # RUN: --section="__TEXT,__literals" %t/literals | FileCheck %s --check-prefix=LIT
324 # LIT: Contents of (__TEXT,__cstring) section
326 # LIT-NEXT: Contents of (__DATA,str_ptrs) section
327 # LIT-NEXT: __TEXT:__cstring:bar
328 # LIT-NEXT: __TEXT:__cstring:bar
329 # LIT-NEXT: Contents of (__TEXT,__literals) section
330 # LIT-NEXT: ef be ad de {{$}}
332 ## Ensure that addrsig metadata does not keep unreferenced functions alive.
333 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
334 # RUN: %t/addrsig.s -o %t/addrsig.o
335 # RUN: %lld -lSystem -dead_strip --icf=safe %t/addrsig.o -o %t/addrsig
336 # RUN: llvm-objdump --syms %t/addrsig | \
337 # RUN: FileCheck --check-prefix=ADDSIG --implicit-check-not _addrsig %s
338 # ADDSIG-LABEL: SYMBOL TABLE:
339 # ADDSIG-NEXT: g F __TEXT,__text _main
340 # ADDSIG-NEXT: g F __TEXT,__text __mh_execute_header
341 # ADDSIG-NEXT: *UND* dyld_stub_binder
343 ## Duplicate symbols that will be dead stripped later should not fail when using
344 ## the --dead-stripped-duplicates flag
345 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
346 # RUN: %t/duplicate1.s -o %t/duplicate1.o
347 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
348 # RUN: %t/duplicate2.s -o %t/duplicate2.o
349 # RUN: %lld -lSystem -dead_strip --dead-strip-duplicates -map %t/stripped-duplicate-map \
350 # RUN: %t/duplicate1.o %t/duplicate2.o -o %t/duplicate
351 # RUN: llvm-objdump --syms %t/duplicate | FileCheck %s --check-prefix=DUP
352 # DUP-LABEL: SYMBOL TABLE:
353 # DUP-NEXT: g F __TEXT,__text _main
354 # DUP-NEXT: g F __TEXT,__text __mh_execute_header
355 # DUP-NEXT: *UND* dyld_stub_binder
357 ## Check that the duplicate dead stripped symbols get listed properly.
358 # RUN: FileCheck --check-prefix=DUPMAP %s < %t/stripped-duplicate-map
360 # DUPMAP-LABEL: Dead Stripped Symbols
361 # DUPMAP: <<dead>> 0x00000001 [ 3] _foo
372 .subsections_via_symbols
380 .subsections_via_symbols
386 .section __DATA,__unref_section
393 ## Referenced by no_dead_strip == S_ATTR_NO_DEAD_STRIP
394 .section __DATA,__ref_section,regular,no_dead_strip
396 ## Referenced because in no_dead_strip section.
400 ## This is a local symbol so it's not in the symbol table, but
401 ## it is still in the section data.
407 # Exported symbols should not be stripped from dylibs
408 # or bundles, but they should be stripped from executables.
414 # Unreferenced local symbols should be stripped.
418 # Same for unreferenced private externs.
419 .globl _unref_private_extern
420 .private_extern _unref_private_extern
421 _unref_private_extern
:
422 # This shouldn't create an indirect symbol since it's
423 # a reference from a dead function.
424 movb _unref_com@GOTPCREL
(%rip
), %al
427 # Referenced local symbols should not be stripped.
429 callq _ref_private_extern
432 # Same for referenced private externs.
433 # This one is referenced by a relocation.
434 .globl _ref_private_extern
435 .private_extern _ref_private_extern
439 # This one is referenced by a -u flag.
440 .globl _ref_private_extern_u
441 .private_extern _ref_private_extern_u
442 _ref_private_extern_u
:
445 # Entry point should not be stripped for executables, even if hidden.
446 # For shared libraries this is stripped since it's just a regular hidden
449 .private_extern _main
451 movb _ref_com@GOTPCREL
(%rip
), %al
455 # Things marked no_dead_strip should not be stripped either.
456 # (clang emits this e.g. for `__attribute__((used))` globals.)
457 # Both for .globl symbols...
458 .globl _no_dead_strip_globl
459 .no_dead_strip _no_dead_strip_globl
460 _no_dead_strip_globl
:
461 callq _ref_from_no_dead_strip_globl
463 _ref_from_no_dead_strip_globl
:
467 .no_dead_strip _no_dead_strip_local
468 _no_dead_strip_local
:
469 callq _ref_from_no_dead_strip_local
471 _ref_from_no_dead_strip_local
:
474 .subsections_via_symbols
476 #--- exported-symbol.s
483 .globl _my_exported_symbol
491 .subsections_via_symbols
494 .globl _abs1, _abs2, _abs3
501 .section __DATA,__foo,regular,no_dead_strip
502 # Absolute symbols are not in a section, so the no_dead_strip
503 # on the section above has no effect.
510 # This is relaxed away, so there's no relocation here and
511 # _abs3 isn't in the exported symbol table.
515 .subsections_via_symbols
518 ## Roughly based on `clang -O2 -S` output for `struct A { A(); ~A(); }; A a;`
519 ## for mod_init_funcs. mod_term_funcs then similar to that.
520 .section __TEXT,__StaticInit,regular,pure_instructions
543 .section __DATA,__mod_init_func,mod_init_funcs
546 .section __DATA,__mod_term_func,mod_term_funcs
549 .subsections_via_symbols
554 .globl _ref_dylib_fun
558 .globl _unref_dylib_fun
562 .subsections_via_symbols
564 #--- strip-dylib-ref.s
569 callq _unref_dylib_fun
571 callq _unref_undef_fun
580 .subsections_via_symbols
583 ## In practice, live_support is used for instruction profiling
584 ## data and asan. (Also for __eh_frame, but that needs special handling
585 ## in the linker anyways.)
586 ## This test isn't based on anything happening in real code though.
587 .section __TEXT,__ref_ls_fw,regular,live_support
589 # This is called by _main and is kept alive by normal
590 # forward liveness propagation, The live_support attribute
591 # does nothing in this case.
594 .section __TEXT,__unref_ls_fw,regular,live_support
598 .section __TEXT,__ref_ls_bw,regular,live_support
600 # This _calls_ something that's alive but isn't referenced itself. This is
601 # kept alive only due to this being in a live_support section.
604 # _bar on the other hand is kept alive since it's called from here.
608 ## Kept alive by a live symbol form a dynamic library.
613 ## Kept alive by a live undefined symbol.
618 ## All symbols in this live_support section reference dead symbols
619 ## and are hence dead themselves.
620 .section __TEXT,__unref_ls_bw,regular,live_support
625 _unref_ls_dylib_fun_bw
:
626 callq _unref_dylib_fun
629 _unref_ls_undef_fun_bw
:
630 callq _unref_undef_fun
655 .subsections_via_symbols
657 #--- live-support-iterations.s
658 .section __TEXT,_ls,regular,live_support
660 ## This is a live_support subsection that only becomes
661 ## live after _foo below is processed. This means the algorithm of
662 ## 1. mark things reachable from gc roots live
663 ## 2. go through live sections and mark the ones live pointing to
664 ## live symbols or sections
665 ## needs more than one iteration, since _bar won't be live when step 2
666 ## runs for the first time.
667 ## (ld64 gets this wrong -- it has different output based on if _bar is
668 ## before _foo or after it.)
674 ## Same here. This is maybe more interesting since it references a live_support
675 ## symbol instead of a "normal" symbol.
686 ## Test no_dead_strip on a symbol in a live_support section.
687 ## ld64 ignores this, but that doesn't look intentional. So lld honors it.
708 .subsections_via_symbols
711 ## This is the output of `clang -O2 -S throw.cc` where throw.cc
727 .section __TEXT,__text,regular,pure_instructions
728 .globl __Z5unrefv ## -- Begin function _Z5unrefv
730 __Z5unrefv
: ## @_Z5unrefv
733 .cfi_personality 155, ___gxx_personality_v0
734 .cfi_lsda 16, Lexception0
737 .cfi_def_cfa_offset 16
738 .cfi_offset %rbp, -16
740 .cfi_def_cfa_register %rbp
743 callq ___cxa_allocate_exception
746 movq __ZTIi@GOTPCREL
(%rip
), %rsi
759 callq __Z5unrefv.cold.1
766 .section __TEXT,__gcc_except_tab
770 .byte 255 ## @LPStart Encoding = omit
771 .byte 155 ## @TType Encoding = indirect pcrel sdata4
772 .uleb128 Lttbase0-Lttbaseref0
774 .byte 1 ## Call site Encoding = uleb128
775 .uleb128 Lcst_end0-Lcst_begin0
777 .uleb128 Lfunc_begin0-Lfunc_begin0 ## >> Call Site 1 <<
778 .uleb128 Ltmp0-Lfunc_begin0 ## Call between Lfunc_begin0 and Ltmp0
779 .byte 0 ## has no landing pad
780 .byte 0 ## On action: cleanup
781 .uleb128 Ltmp0-Lfunc_begin0 ## >> Call Site 2 <<
782 .uleb128 Ltmp1-Ltmp0 ## Call between Ltmp0 and Ltmp1
783 .uleb128 Ltmp2-Lfunc_begin0 ## jumps to Ltmp2
784 .byte 1 ## On action: 1
785 .uleb128 Ltmp1-Lfunc_begin0 ## >> Call Site 3 <<
786 .uleb128 Lfunc_end0-Ltmp1 ## Call between Ltmp1 and Lfunc_end0
787 .byte 0 ## has no landing pad
788 .byte 0 ## On action: cleanup
790 .byte 1 ## >> Action Record 1 <<
792 .byte 0 ## No further actions
794 ## >> Catch TypeInfos <<
795 .long __ZTIi@GOTPCREL+4 ## TypeInfo 1
799 .section __TEXT,__text,regular,pure_instructions
800 .globl _main ## -- Begin function main
805 .cfi_personality 155, ___gxx_personality_v0
806 .cfi_lsda 16, Lexception1
809 .cfi_def_cfa_offset 16
810 .cfi_offset %rbp, -16
812 .cfi_def_cfa_register %rbp
815 .cfi_offset %rbx, -24
817 callq ___cxa_allocate_exception
820 movq __ZTIi@GOTPCREL
(%rip
), %rsi
830 callq ___cxa_begin_catch
832 callq ___cxa_end_catch
840 .section __TEXT,__gcc_except_tab
844 .byte 255 ## @LPStart Encoding = omit
845 .byte 155 ## @TType Encoding = indirect pcrel sdata4
846 .uleb128 Lttbase1-Lttbaseref1
848 .byte 1 ## Call site Encoding = uleb128
849 .uleb128 Lcst_end1-Lcst_begin1
851 .uleb128 Lfunc_begin1-Lfunc_begin1 ## >> Call Site 1 <<
852 .uleb128 Ltmp3-Lfunc_begin1 ## Call between Lfunc_begin1 and Ltmp3
853 .byte 0 ## has no landing pad
854 .byte 0 ## On action: cleanup
855 .uleb128 Ltmp3-Lfunc_begin1 ## >> Call Site 2 <<
856 .uleb128 Ltmp4-Ltmp3 ## Call between Ltmp3 and Ltmp4
857 .uleb128 Ltmp5-Lfunc_begin1 ## jumps to Ltmp5
858 .byte 1 ## On action: 1
859 .uleb128 Ltmp4-Lfunc_begin1 ## >> Call Site 3 <<
860 .uleb128 Lfunc_end1-Ltmp4 ## Call between Ltmp4 and Lfunc_end1
861 .byte 0 ## has no landing pad
862 .byte 0 ## On action: cleanup
864 .byte 1 ## >> Action Record 1 <<
866 .byte 0 ## No further actions
868 ## >> Catch TypeInfos <<
869 .long __ZTIi@GOTPCREL+4 ## TypeInfo 1
873 .section __TEXT,__text,regular,pure_instructions
874 .p2align 4, 0x90 ## -- Begin function _Z5unrefv.cold.1
875 __Z5unrefv.cold.1
: ## @_Z5unrefv.cold.1
879 .cfi_def_cfa_offset 16
880 .cfi_offset %rbp, -16
882 .cfi_def_cfa_register %rbp
885 .cfi_offset %rbx, -24
887 callq ___cxa_begin_catch
894 jmp ___cxa_end_catch
## TAILCALL
897 .subsections_via_symbols
901 .weak_reference _ref_dylib_fun
907 .subsections_via_symbols
909 #--- strong-dead-ref.s
911 .globl _unref_dylib_fun
913 callq _unref_dylib_fun
916 .subsections_via_symbols
920 .globl _weak_in_dylib
921 .weak_definition _weak_in_dylib
925 .subsections_via_symbols
927 #--- dead-weak-override.s
929 ## Overrides the _weak_in_dylib symbol in weak-dylib, but is dead stripped.
932 #.no_dead_strip _weak_in_dylib
933 .globl _weak_in_dylib
941 .subsections_via_symbols
953 .subsections_via_symbols
955 #--- no-dead-symbols.s
980 .section __DATA,str_ptrs,literal_pointers
986 ## The output binary has these integer literals put into a section that isn't
987 ## marked with a S_*BYTE_LITERALS flag, so we don't mark word_ptrs with the
988 ## S_LITERAL_POINTERS flag in order not to confuse llvm-objdump.
989 .section __DATA,word_ptrs
995 .subsections_via_symbols
1000 callq _ref_undef_fun
1001 .subsections_via_symbols
1004 .globl _main, _addrsig
1011 .subsections_via_symbols
1014 .addrsig_sym _addrsig