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: _ref_com
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* ___cxa_allocate_exception
270 # UNWIND-NEXT: *UND* ___cxa_end_catch
271 # UNWIND-NEXT: *UND* __ZTIi
272 # UNWIND-NEXT: *UND* ___cxa_throw
273 # UNWIND-NEXT: *UND* ___gxx_personality_v0
274 # UNWIND-NEXT: *UND* ___cxa_begin_catch
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 ## Duplicate symbols that will be dead stripped later should not fail when using
333 ## the --dead-stripped-duplicates flag
334 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
335 # RUN: %t/duplicate1.s -o %t/duplicate1.o
336 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
337 # RUN: %t/duplicate2.s -o %t/duplicate2.o
338 # RUN: %lld -lSystem -dead_strip --dead-strip-duplicates -map %t/stripped-duplicate-map \
339 # RUN: %t/duplicate1.o %t/duplicate2.o -o %t/duplicate
340 # RUN: llvm-objdump --syms %t/duplicate | FileCheck %s --check-prefix=DUP
341 # DUP-LABEL: SYMBOL TABLE:
342 # DUP-NEXT: g F __TEXT,__text _main
343 # DUP-NEXT: g F __TEXT,__text __mh_execute_header
344 # DUP-NEXT: *UND* dyld_stub_binder
346 ## Check that the duplicate dead stripped symbols get listed properly.
347 # RUN: FileCheck --check-prefix=DUPMAP %s < %t/stripped-duplicate-map
349 # DUPMAP-LABEL: Dead Stripped Symbols
350 # DUPMAP: <<dead>> 0x00000001 [ 3] _foo
361 .subsections_via_symbols
369 .subsections_via_symbols
375 .section __DATA,__unref_section
382 ## Referenced by no_dead_strip == S_ATTR_NO_DEAD_STRIP
383 .section __DATA,__ref_section,regular,no_dead_strip
385 ## Referenced because in no_dead_strip section.
389 ## This is a local symbol so it's not in the symbol table, but
390 ## it is still in the section data.
396 # Exported symbols should not be stripped from dylibs
397 # or bundles, but they should be stripped from executables.
403 # Unreferenced local symbols should be stripped.
407 # Same for unreferenced private externs.
408 .globl _unref_private_extern
409 .private_extern _unref_private_extern
410 _unref_private_extern
:
411 # This shouldn't create an indirect symbol since it's
412 # a reference from a dead function.
413 movb _unref_com@GOTPCREL
(%rip
), %al
416 # Referenced local symbols should not be stripped.
418 callq _ref_private_extern
421 # Same for referenced private externs.
422 # This one is referenced by a relocation.
423 .globl _ref_private_extern
424 .private_extern _ref_private_extern
428 # This one is referenced by a -u flag.
429 .globl _ref_private_extern_u
430 .private_extern _ref_private_extern_u
431 _ref_private_extern_u
:
434 # Entry point should not be stripped for executables, even if hidden.
435 # For shared libraries this is stripped since it's just a regular hidden
438 .private_extern _main
440 movb _ref_com@GOTPCREL
(%rip
), %al
444 # Things marked no_dead_strip should not be stripped either.
445 # (clang emits this e.g. for `__attribute__((used))` globals.)
446 # Both for .globl symbols...
447 .globl _no_dead_strip_globl
448 .no_dead_strip _no_dead_strip_globl
449 _no_dead_strip_globl
:
450 callq _ref_from_no_dead_strip_globl
452 _ref_from_no_dead_strip_globl
:
456 .no_dead_strip _no_dead_strip_local
457 _no_dead_strip_local
:
458 callq _ref_from_no_dead_strip_local
460 _ref_from_no_dead_strip_local
:
463 .subsections_via_symbols
465 #--- exported-symbol.s
472 .globl _my_exported_symbol
480 .subsections_via_symbols
483 .globl _abs1, _abs2, _abs3
490 .section __DATA,__foo,regular,no_dead_strip
491 # Absolute symbols are not in a section, so the no_dead_strip
492 # on the section above has no effect.
499 # This is relaxed away, so there's no relocation here and
500 # _abs3 isn't in the exported symbol table.
504 .subsections_via_symbols
507 ## Roughly based on `clang -O2 -S` output for `struct A { A(); ~A(); }; A a;`
508 ## for mod_init_funcs. mod_term_funcs then similar to that.
509 .section __TEXT,__StaticInit,regular,pure_instructions
532 .section __DATA,__mod_init_func,mod_init_funcs
535 .section __DATA,__mod_term_func,mod_term_funcs
538 .subsections_via_symbols
543 .globl _ref_dylib_fun
547 .globl _unref_dylib_fun
551 .subsections_via_symbols
553 #--- strip-dylib-ref.s
558 callq _unref_dylib_fun
560 callq _unref_undef_fun
569 .subsections_via_symbols
572 ## In practice, live_support is used for instruction profiling
573 ## data and asan. (Also for __eh_frame, but that needs special handling
574 ## in the linker anyways.)
575 ## This test isn't based on anything happening in real code though.
576 .section __TEXT,__ref_ls_fw,regular,live_support
578 # This is called by _main and is kept alive by normal
579 # forward liveness propagation, The live_support attribute
580 # does nothing in this case.
583 .section __TEXT,__unref_ls_fw,regular,live_support
587 .section __TEXT,__ref_ls_bw,regular,live_support
589 # This _calls_ something that's alive but isn't referenced itself. This is
590 # kept alive only due to this being in a live_support section.
593 # _bar on the other hand is kept alive since it's called from here.
597 ## Kept alive by a live symbol form a dynamic library.
602 ## Kept alive by a live undefined symbol.
607 ## All symbols in this live_support section reference dead symbols
608 ## and are hence dead themselves.
609 .section __TEXT,__unref_ls_bw,regular,live_support
614 _unref_ls_dylib_fun_bw
:
615 callq _unref_dylib_fun
618 _unref_ls_undef_fun_bw
:
619 callq _unref_undef_fun
644 .subsections_via_symbols
646 #--- live-support-iterations.s
647 .section __TEXT,_ls,regular,live_support
649 ## This is a live_support subsection that only becomes
650 ## live after _foo below is processed. This means the algorithm of
651 ## 1. mark things reachable from gc roots live
652 ## 2. go through live sections and mark the ones live pointing to
653 ## live symbols or sections
654 ## needs more than one iteration, since _bar won't be live when step 2
655 ## runs for the first time.
656 ## (ld64 gets this wrong -- it has different output based on if _bar is
657 ## before _foo or after it.)
663 ## Same here. This is maybe more interesting since it references a live_support
664 ## symbol instead of a "normal" symbol.
675 ## Test no_dead_strip on a symbol in a live_support section.
676 ## ld64 ignores this, but that doesn't look intentional. So lld honors it.
697 .subsections_via_symbols
700 ## This is the output of `clang -O2 -S throw.cc` where throw.cc
716 .section __TEXT,__text,regular,pure_instructions
717 .globl __Z5unrefv ## -- Begin function _Z5unrefv
719 __Z5unrefv
: ## @_Z5unrefv
722 .cfi_personality 155, ___gxx_personality_v0
723 .cfi_lsda 16, Lexception0
726 .cfi_def_cfa_offset 16
727 .cfi_offset %rbp, -16
729 .cfi_def_cfa_register %rbp
732 callq ___cxa_allocate_exception
735 movq __ZTIi@GOTPCREL
(%rip
), %rsi
748 callq __Z5unrefv.cold.1
755 .section __TEXT,__gcc_except_tab
759 .byte 255 ## @LPStart Encoding = omit
760 .byte 155 ## @TType Encoding = indirect pcrel sdata4
761 .uleb128 Lttbase0-Lttbaseref0
763 .byte 1 ## Call site Encoding = uleb128
764 .uleb128 Lcst_end0-Lcst_begin0
766 .uleb128 Lfunc_begin0-Lfunc_begin0 ## >> Call Site 1 <<
767 .uleb128 Ltmp0-Lfunc_begin0 ## Call between Lfunc_begin0 and Ltmp0
768 .byte 0 ## has no landing pad
769 .byte 0 ## On action: cleanup
770 .uleb128 Ltmp0-Lfunc_begin0 ## >> Call Site 2 <<
771 .uleb128 Ltmp1-Ltmp0 ## Call between Ltmp0 and Ltmp1
772 .uleb128 Ltmp2-Lfunc_begin0 ## jumps to Ltmp2
773 .byte 1 ## On action: 1
774 .uleb128 Ltmp1-Lfunc_begin0 ## >> Call Site 3 <<
775 .uleb128 Lfunc_end0-Ltmp1 ## Call between Ltmp1 and Lfunc_end0
776 .byte 0 ## has no landing pad
777 .byte 0 ## On action: cleanup
779 .byte 1 ## >> Action Record 1 <<
781 .byte 0 ## No further actions
783 ## >> Catch TypeInfos <<
784 .long __ZTIi@GOTPCREL+4 ## TypeInfo 1
788 .section __TEXT,__text,regular,pure_instructions
789 .globl _main ## -- Begin function main
794 .cfi_personality 155, ___gxx_personality_v0
795 .cfi_lsda 16, Lexception1
798 .cfi_def_cfa_offset 16
799 .cfi_offset %rbp, -16
801 .cfi_def_cfa_register %rbp
804 .cfi_offset %rbx, -24
806 callq ___cxa_allocate_exception
809 movq __ZTIi@GOTPCREL
(%rip
), %rsi
819 callq ___cxa_begin_catch
821 callq ___cxa_end_catch
829 .section __TEXT,__gcc_except_tab
833 .byte 255 ## @LPStart Encoding = omit
834 .byte 155 ## @TType Encoding = indirect pcrel sdata4
835 .uleb128 Lttbase1-Lttbaseref1
837 .byte 1 ## Call site Encoding = uleb128
838 .uleb128 Lcst_end1-Lcst_begin1
840 .uleb128 Lfunc_begin1-Lfunc_begin1 ## >> Call Site 1 <<
841 .uleb128 Ltmp3-Lfunc_begin1 ## Call between Lfunc_begin1 and Ltmp3
842 .byte 0 ## has no landing pad
843 .byte 0 ## On action: cleanup
844 .uleb128 Ltmp3-Lfunc_begin1 ## >> Call Site 2 <<
845 .uleb128 Ltmp4-Ltmp3 ## Call between Ltmp3 and Ltmp4
846 .uleb128 Ltmp5-Lfunc_begin1 ## jumps to Ltmp5
847 .byte 1 ## On action: 1
848 .uleb128 Ltmp4-Lfunc_begin1 ## >> Call Site 3 <<
849 .uleb128 Lfunc_end1-Ltmp4 ## Call between Ltmp4 and Lfunc_end1
850 .byte 0 ## has no landing pad
851 .byte 0 ## On action: cleanup
853 .byte 1 ## >> Action Record 1 <<
855 .byte 0 ## No further actions
857 ## >> Catch TypeInfos <<
858 .long __ZTIi@GOTPCREL+4 ## TypeInfo 1
862 .section __TEXT,__text,regular,pure_instructions
863 .p2align 4, 0x90 ## -- Begin function _Z5unrefv.cold.1
864 __Z5unrefv.cold.1
: ## @_Z5unrefv.cold.1
868 .cfi_def_cfa_offset 16
869 .cfi_offset %rbp, -16
871 .cfi_def_cfa_register %rbp
874 .cfi_offset %rbx, -24
876 callq ___cxa_begin_catch
883 jmp ___cxa_end_catch
## TAILCALL
886 .subsections_via_symbols
890 .weak_reference _ref_dylib_fun
896 .subsections_via_symbols
898 #--- strong-dead-ref.s
900 .globl _unref_dylib_fun
902 callq _unref_dylib_fun
905 .subsections_via_symbols
909 .globl _weak_in_dylib
910 .weak_definition _weak_in_dylib
914 .subsections_via_symbols
916 #--- dead-weak-override.s
918 ## Overrides the _weak_in_dylib symbol in weak-dylib, but is dead stripped.
921 #.no_dead_strip _weak_in_dylib
922 .globl _weak_in_dylib
930 .subsections_via_symbols
942 .subsections_via_symbols
944 #--- no-dead-symbols.s
969 .section __DATA,str_ptrs,literal_pointers
975 ## The output binary has these integer literals put into a section that isn't
976 ## marked with a S_*BYTE_LITERALS flag, so we don't mark word_ptrs with the
977 ## S_LITERAL_POINTERS flag in order not to confuse llvm-objdump.
978 .section __DATA,word_ptrs
984 .subsections_via_symbols
990 .subsections_via_symbols