brintos

brintos / llvm-project-archived public Read only

0
0
Text · 29.6 KiB · d107dad Raw
1015 lines · plain
1# REQUIRES: x86, llvm-64-bits2 3# RUN: rm -rf %t; split-file %s %t4 5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \6# RUN:     %t/basics.s -o %t/basics.o7 8## Check that .private_extern symbols are marked as local in the symbol table9## 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/basics12# RUN: llvm-objdump --syms --section-headers %t/basics | \13# RUN:     FileCheck --check-prefix=EXEC --implicit-check-not _unref %s14# 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 %s17# RUN: llvm-otool -l %t/basics | grep -q 'segname __PAGEZERO'18# EXEC-LABEL: Sections:19# EXEC-LABEL: Name20# EXEC-NEXT:  __text21# EXEC-NEXT:  __got22# EXEC-NEXT:  __ref_section23# EXEC-NEXT:  __common24# EXEC-LABEL: SYMBOL TABLE:25# EXEC-DAG:   l {{.*}} _ref_data26# EXEC-DAG:   l {{.*}} _ref_local27# EXEC-DAG:   l {{.*}} _ref_from_no_dead_strip_globl28# EXEC-DAG:   l {{.*}} _no_dead_strip_local29# EXEC-DAG:   l {{.*}} _ref_from_no_dead_strip_local30# EXEC-DAG:   l {{.*}} _ref_private_extern_u31# EXEC-DAG:   l {{.*}} _main32# EXEC-DAG:   l {{.*}} _ref_private_extern33# EXEC-DAG:   g {{.*}} _no_dead_strip_globl34# EXEC-DAG:   g {{.*}} _ref_com35# EXEC-DAG:   g {{.*}} __mh_execute_header36# EXECDATA-LABEL: Indirect symbols37# EXECDATA-NEXT:  name38# EXECDATA-NEXT:  LOCAL39# EXECDATA-LABEL: Contents of (__DATA,__ref_section) section40# EXECDATA-NEXT:   04 00 00 00 00 00 00 00 05 00 00 00 00 00 00 0041# EXECDATA-LABEL: Exports trie:42# EXECDATA-DAG:   _ref_com43# EXECDATA-DAG:   _no_dead_strip_globl44# EXECDATA-DAG:   __mh_execute_header45 46## Check that dead stripped symbols get listed properly.47# RUN: FileCheck --check-prefix=MAP %s < %t/map48 49# MAP:        _main50# MAP-LABEL: Dead Stripped Symbols51# MAP-DAG:   <<dead>> 0x00000001 [ 2] _unref_com52# MAP-DAG:   <<dead>> 0x00000008 [ 2] _unref_data53# MAP-DAG:   <<dead>> 0x00000006 [ 2] _unref_extern54# MAP-DAG:   <<dead>> 0x00000001 [ 2] _unref_local55# MAP-DAG:   <<dead>> 0x00000007 [ 2] _unref_private_extern56# MAP-DAG:   <<dead>> 0x00000008 [ 2] l_unref_data57 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.o61# RUN: %lld -lSystem -dead_strip -map %t/no-dead-symbols-map \62# RUN:     %t/no-dead-symbols.o -o %t/no-dead-symbols63## Mark the end of the file with a string.64# RUN: FileCheck --check-prefix=NODEADSYMBOLS %s < %t/no-dead-symbols-map65 66# NODEADSYMBOLS-LABEL: # Symbols:67# NODEADSYMBOLS-NEXT:  # Address Size File Name68# NODEADSYMBOLS-NEXT:  _main69# NODEADSYMBOLS-LABEL: # Dead Stripped Symbols:70# NODEADSYMBOLS-NEXT:  # Size File Name71# NODEADSYMBOLS-EMPTY:72 73# RUN: %lld -dylib -dead_strip -u _ref_private_extern_u %t/basics.o -o %t/basics.dylib74# RUN: llvm-objdump --syms %t/basics.dylib | \75# RUN:     FileCheck --check-prefix=DYLIB --implicit-check-not _unref %s76# RUN: %lld -bundle -dead_strip -u _ref_private_extern_u %t/basics.o -o %t/basics.dylib77# RUN: llvm-objdump --syms %t/basics.dylib | \78# RUN:     FileCheck --check-prefix=DYLIB --implicit-check-not _unref %s79# DYLIB-LABEL: SYMBOL TABLE:80# DYLIB-DAG:   l {{.*}} _ref_data81# DYLIB-DAG:   l {{.*}} _ref_local82# DYLIB-DAG:   l {{.*}} _ref_from_no_dead_strip_globl83# DYLIB-DAG:   l {{.*}} _no_dead_strip_local84# DYLIB-DAG:   l {{.*}} _ref_from_no_dead_strip_local85# DYLIB-DAG:   l {{.*}} _ref_private_extern_u86# DYLIB-DAG:   l {{.*}} _ref_private_extern87# DYLIB-DAG:   g {{.*}} _ref_com88# DYLIB-DAG:   g {{.*}} _unref_com89# DYLIB-DAG:   g {{.*}} _unref_extern90# DYLIB-DAG:   g {{.*}} _no_dead_strip_globl91 92## Extern symbols aren't stripped from executables with -export_dynamic93# RUN: %lld -lSystem -dead_strip -export_dynamic -u _ref_private_extern_u \94# RUN:     %t/basics.o -o %t/basics-export-dyn95# RUN: llvm-objdump --syms --section-headers %t/basics-export-dyn | \96# RUN:     FileCheck --check-prefix=EXECDYN %s97# EXECDYN-LABEL: Sections:98# EXECDYN-LABEL: Name99# EXECDYN-NEXT:  __text100# EXECDYN-NEXT:  __got101# EXECDYN-NEXT:  __ref_section102# EXECDYN-NEXT:  __common103# EXECDYN-LABEL: SYMBOL TABLE:104# EXECDYN-DAG:   l {{.*}} _ref_data105# EXECDYN-DAG:   l {{.*}} _ref_local106# EXECDYN-DAG:   l {{.*}} _ref_from_no_dead_strip_globl107# EXECDYN-DAG:   l {{.*}} _no_dead_strip_local108# EXECDYN-DAG:   l {{.*}} _ref_from_no_dead_strip_local109# EXECDYN-DAG:   l {{.*}} _ref_private_extern_u110# EXECDYN-DAG:   l {{.*}} _main111# EXECDYN-DAG:   l {{.*}} _ref_private_extern112# EXECDYN-DAG:   g {{.*}} _ref_com113# EXECDYN-DAG:   g {{.*}} _unref_com114# EXECDYN-DAG:   g {{.*}} _unref_extern115# EXECDYN-DAG:   g {{.*}} _no_dead_strip_globl116# EXECDYN-DAG:   g {{.*}} __mh_execute_header117 118## Absolute symbol handling.119# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \120# RUN:     %t/abs.s -o %t/abs.o121# RUN: %lld -lSystem -dead_strip %t/abs.o -o %t/abs122# RUN: llvm-objdump --macho --syms --exports-trie %t/abs | \123# RUN:     FileCheck --check-prefix=ABS %s124#ABS-LABEL: SYMBOL TABLE:125#ABS-NEXT:   g {{.*}} _main126#ABS-NEXT:   g *ABS* _abs1127#ABS-NEXT:   g {{.*}} __mh_execute_header128#ABS-LABEL: Exports trie:129#ABS-NEXT:   __mh_execute_header130#ABS-NEXT:   _main131#ABS-NEXT:   _abs1 [absolute]132 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.o136# RUN: %lld -lSystem -dead_strip -exported_symbol _my_exported_symbol \137# RUN:     %t/exported-symbol.o -o %t/exported-symbol138# RUN: llvm-objdump --syms %t/exported-symbol | \139# RUN:     FileCheck --check-prefix=EXPORTEDSYMBOL --implicit-check-not _unref %s140# EXPORTEDSYMBOL-LABEL: SYMBOL TABLE:141# EXPORTEDSYMBOL-NEXT:   l {{.*}} _main142# EXPORTEDSYMBOL-NEXT:   l {{.*}} __mh_execute_header143# EXPORTEDSYMBOL-NEXT:   g {{.*}} _my_exported_symbol144 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.o148# RUN: %lld -lSystem -dead_strip %t/mod-funcs.o -o %t/mod-funcs149# RUN: llvm-objdump --syms %t/mod-funcs | \150# RUN:     FileCheck --check-prefix=MODFUNCS --implicit-check-not _unref %s151# MODFUNCS-LABEL: SYMBOL TABLE:152# MODFUNCS-NEXT:   l {{.*}} _ref_from_init153# MODFUNCS-NEXT:   l {{.*}} _ref_init154# MODFUNCS-NEXT:   l {{.*}} _ref_from_term155# MODFUNCS-NEXT:   l {{.*}} _ref_term156# MODFUNCS-NEXT:   g {{.*}} _main157# MODFUNCS-NEXT:   g {{.*}} __mh_execute_header158 159## Check that DylibSymbols in dead subsections are stripped: They should160## 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.o163# RUN: %lld -dylib -dead_strip %t/dylib.o -o %t/dylib.dylib164# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \165# RUN:     %t/strip-dylib-ref.s -o %t/strip-dylib-ref.o166# 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_fun168# RUN: llvm-objdump --syms --bind --lazy-bind --weak-bind %t/strip-dylib-ref | \169# RUN:     FileCheck --check-prefix=STRIPDYLIB --implicit-check-not _unref %s170# STRIPDYLIB:      SYMBOL TABLE:171# STRIPDYLIB-NEXT:  l {{.*}} __dyld_private172# STRIPDYLIB-NEXT:  g {{.*}} _main173# STRIPDYLIB-NEXT:  g {{.*}} __mh_execute_header174# STRIPDYLIB-NEXT:  *UND* dyld_stub_binder175# STRIPDYLIB-NEXT:  *UND* _ref_dylib_fun176# STRIPDYLIB-NEXT:  *UND* _ref_undef_fun177# STRIPDYLIB:      Bind table:178# STRIPDYLIB:      Lazy bind table:179# STRIPDYLIB:       __DATA   __la_symbol_ptr {{.*}} flat-namespace _ref_undef_fun180# STRIPDYLIB:       __DATA   __la_symbol_ptr {{.*}} dylib _ref_dylib_fun181# STRIPDYLIB:      Weak bind table:182## Stubs smoke check: There should be two stubs entries, not four, but we183## 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 %s186# STUBS-LABEL: <__stubs>:187# STUBS-NEXT:  jmpq188# STUBS-NEXT:  jmpq189# STUBS-NOT:   jmpq190# STUBS-LABEL: <__stub_helper>:191# STUBS:  pushq $0192# STUBS:  jmp193# STUBS:  jmp194# STUBS-NOT:  jmp195## An undefined symbol referenced from a dead-stripped function shouldn't196## 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_fun199 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.o203# RUN: %lld -lSystem -dead_strip %t/ref-undef.o \204# RUN:     -o %t/ref-undef -undefined dynamic_lookup205# RUN: llvm-objdump --syms --lazy-bind %t/ref-undef | \206# RUN:     FileCheck --check-prefix=STRIPDYNLOOKUP %s207# STRIPDYNLOOKUP: SYMBOL TABLE:208# STRIPDYNLOOKUP:   *UND* _ref_undef_fun209# STRIPDYNLOOKUP: Lazy bind table:210# STRIPDYNLOOKUP:   __DATA   __la_symbol_ptr {{.*}} flat-namespace _ref_undef_fun211 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.o215# 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-support217# RUN: llvm-objdump --syms %t/live-support | \218# RUN:     FileCheck --check-prefix=LIVESUPP --implicit-check-not _unref %s219# LIVESUPP-LABEL: SYMBOL TABLE:220# LIVESUPP-NEXT:   l {{.*}} _ref_ls_fun_fw221# LIVESUPP-NEXT:   l {{.*}} _ref_ls_fun_bw222# LIVESUPP-NEXT:   l {{.*}} _ref_ls_dylib_fun223# LIVESUPP-NEXT:   l {{.*}} _ref_ls_undef_fun224# LIVESUPP-NEXT:   l {{.*}} __dyld_private225# LIVESUPP-NEXT:   g {{.*}} _main226# LIVESUPP-NEXT:   g {{.*}} _bar227# LIVESUPP-NEXT:   g {{.*}} _foo228# LIVESUPP-NEXT:   g {{.*}} __mh_execute_header229# LIVESUPP-NEXT:   *UND* dyld_stub_binder230# LIVESUPP-NEXT:   *UND* _ref_dylib_fun231# LIVESUPP-NEXT:   *UND* _ref_undef_fun232 233# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \234# RUN:     %t/live-support-iterations.s -o %t/live-support-iterations.o235# RUN: %lld -lSystem -dead_strip %t/live-support-iterations.o \236# RUN:     -o %t/live-support-iterations237# RUN: llvm-objdump --syms %t/live-support-iterations | \238# RUN:     FileCheck --check-prefix=LIVESUPP2 --implicit-check-not _unref %s239# LIVESUPP2-LABEL: SYMBOL TABLE:240# LIVESUPP2-NEXT:   l {{.*}} _bar241# LIVESUPP2-NEXT:   l {{.*}} _foo_refd242# LIVESUPP2-NEXT:   l {{.*}} _bar_refd243# LIVESUPP2-NEXT:   l {{.*}} _baz244# LIVESUPP2-NEXT:   l {{.*}} _baz_refd245# LIVESUPP2-NEXT:   l {{.*}} _foo246# LIVESUPP2-NEXT:   g {{.*}} _main247# LIVESUPP2-NEXT:   g {{.*}} __mh_execute_header248 249## Dead stripping should not remove the __TEXT,__unwind_info250## and __TEXT,__gcc_except_tab functions, but it should still251## remove the unreferenced function __Z5unref.252## The reference to ___gxx_personality_v0 should also not be253## stripped.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.o257# RUN: %lld -lc++ -lSystem -dead_strip %t/unwind.o -o %t/unwind258# RUN: llvm-objdump --syms %t/unwind | \259# RUN:     FileCheck --check-prefix=UNWIND --implicit-check-not unref %s260# RUN: llvm-otool -l %t/unwind | FileCheck --check-prefix=UNWINDSECT %s261# UNWINDSECT-DAG: sectname __unwind_info262# UNWINDSECT-DAG: sectname __gcc_except_tab263# UNWIND-LABEL: SYMBOL TABLE:264# UNWIND-NEXT:   l O __TEXT,__gcc_except_tab GCC_except_table1265# UNWIND-NEXT:   l O __DATA,__data __dyld_private266# UNWIND-NEXT:   g F __TEXT,__text _main267# UNWIND-NEXT:   g F __TEXT,__text __mh_execute_header268# UNWIND-NEXT:   *UND* dyld_stub_binder269# UNWIND-NEXT:   *UND* __ZTIi270# UNWIND-NEXT:   *UND* ___cxa_allocate_exception271# UNWIND-NEXT:   *UND* ___cxa_begin_catch272# UNWIND-NEXT:   *UND* ___cxa_end_catch273# UNWIND-NEXT:   *UND* ___cxa_throw274# UNWIND-NEXT:   *UND* ___gxx_personality_v0275# UNWIND-NOT:    GCC_except_table0276 277## If a dead stripped function has a strong ref to a dylib symbol but278## 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.o282# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \283# RUN:     %t/strong-dead-ref.s -o %t/strong-dead-ref.o284# RUN: %lld -lSystem -dead_strip %t/weak-ref.o %t/strong-dead-ref.o \285# RUN:     %t/dylib.dylib -o %t/weak-ref286# RUN: llvm-otool -l %t/weak-ref | FileCheck -DDIR=%t --check-prefix=WEAK %s287# WEAK:          cmd LC_LOAD_DYLIB288# WEAK-NEXT: cmdsize289# WEAK-NEXT:    name /usr/lib/libSystem.dylib290# WEAK:          cmd LC_LOAD_DYLIB291# WEAK-NEXT: cmdsize292# WEAK-NEXT:    name [[DIR]]/dylib.dylib293 294## A strong symbol that would override a weak import does not emit the295## "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.o298# RUN: %lld -dylib -dead_strip %t/weak-dylib.o -o %t/weak-dylib.dylib299# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \300# RUN:     %t/dead-weak-override.s -o %t/dead-weak-override.o301# RUN: %lld -dead_strip %t/dead-weak-override.o %t/weak-dylib.dylib \302# RUN:     -o %t/dead-weak-override303# RUN: llvm-objdump --macho --weak-bind --private-header \304# RUN:     %t/dead-weak-override | FileCheck --check-prefix=DEADWEAK %s305# DEADWEAK-NOT: WEAK_DEFINES306# DEADWEAK:     Weak bind table:307# DEADWEAK:     segment  section            address     type       addend   symbol308# DEADWEAK-NOT: strong              _weak_in_dylib309 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.o313# RUN: %lld -lSystem -dead_strip %t/debug.o -o %t/debug314# RUN: dsymutil -s %t/debug | FileCheck --check-prefix=EXECSTABS %s315# EXECSTABS-NOT: N_FUN {{.*}} '_unref'316# EXECSTABS:     N_FUN {{.*}} '_main'317# EXECSTABS-NOT: N_FUN {{.*}} '_unref'318 319# RUN: llvm-mc -g -filetype=obj -triple=x86_64-apple-macos \320# RUN:     %t/literals.s -o %t/literals.o321# RUN: %lld -dylib -dead_strip %t/literals.o -o %t/literals322# RUN: llvm-objdump --macho --section="__TEXT,__cstring" --section="__DATA,str_ptrs" \323# RUN:   --section="__TEXT,__literals" %t/literals | FileCheck %s --check-prefix=LIT324# LIT:      Contents of (__TEXT,__cstring) section325# LIT-NEXT: foobar326# LIT-NEXT: Contents of (__DATA,str_ptrs) section327# LIT-NEXT: __TEXT:__cstring:bar328# LIT-NEXT: __TEXT:__cstring:bar329# LIT-NEXT: Contents of (__TEXT,__literals) section330# LIT-NEXT: ef be ad de {{$}}331 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.o335# RUN: %lld -lSystem -dead_strip --icf=safe %t/addrsig.o -o %t/addrsig336# RUN: llvm-objdump --syms %t/addrsig | \337# RUN:     FileCheck --check-prefix=ADDSIG --implicit-check-not _addrsig %s338# ADDSIG-LABEL: SYMBOL TABLE:339# ADDSIG-NEXT:   g F __TEXT,__text _main340# ADDSIG-NEXT:   g F __TEXT,__text __mh_execute_header341# ADDSIG-NEXT:   *UND* dyld_stub_binder342 343## Duplicate symbols that will be dead stripped later should not fail when using344## the --dead-stripped-duplicates flag345# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \346# RUN:     %t/duplicate1.s -o %t/duplicate1.o347# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \348# RUN:     %t/duplicate2.s -o %t/duplicate2.o349# RUN: %lld -lSystem -dead_strip --dead-strip-duplicates -map %t/stripped-duplicate-map \350# RUN:     %t/duplicate1.o %t/duplicate2.o -o %t/duplicate351# RUN: llvm-objdump --syms %t/duplicate | FileCheck %s --check-prefix=DUP352# DUP-LABEL: SYMBOL TABLE:353# DUP-NEXT:   g F __TEXT,__text _main354# DUP-NEXT:   g F __TEXT,__text __mh_execute_header355# DUP-NEXT:   *UND* dyld_stub_binder356 357## Check that the duplicate dead stripped symbols get listed properly.358# RUN: FileCheck --check-prefix=DUPMAP %s < %t/stripped-duplicate-map359# DUPMAP: _main360# DUPMAP-LABEL: Dead Stripped Symbols361# DUPMAP: <<dead>> 0x00000001 [ 3] _foo362 363#--- duplicate1.s364.text365.globl _main, _foo366_foo:367  retq368 369_main:370  retq371 372.subsections_via_symbols373 374#--- duplicate2.s375.text376.globl _foo377_foo:378  retq379 380.subsections_via_symbols381 382#--- basics.s383.comm _ref_com, 1384.comm _unref_com, 1385 386.section __DATA,__unref_section387_unref_data:388  .quad 4389 390l_unref_data:391  .quad 5392 393## Referenced by no_dead_strip == S_ATTR_NO_DEAD_STRIP394.section __DATA,__ref_section,regular,no_dead_strip395 396## Referenced because in no_dead_strip section.397_ref_data:398  .quad 4399 400## This is a local symbol so it's not in the symbol table, but401## it is still in the section data.402l_ref_data:403  .quad 5404 405.text406 407# Exported symbols should not be stripped from dylibs408# or bundles, but they should be stripped from executables.409.globl _unref_extern410_unref_extern:411  callq _ref_local412  retq413 414# Unreferenced local symbols should be stripped.415_unref_local:416  retq417 418# Same for unreferenced private externs.419.globl _unref_private_extern420.private_extern _unref_private_extern421_unref_private_extern:422  # This shouldn't create an indirect symbol since it's423  # a reference from a dead function.424  movb _unref_com@GOTPCREL(%rip), %al425  retq426 427# Referenced local symbols should not be stripped.428_ref_local:429  callq _ref_private_extern430  retq431 432# Same for referenced private externs.433# This one is referenced by a relocation.434.globl _ref_private_extern435.private_extern _ref_private_extern436_ref_private_extern:437  retq438 439# This one is referenced by a -u flag.440.globl _ref_private_extern_u441.private_extern _ref_private_extern_u442_ref_private_extern_u:443  retq444 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 hidden447# symbol there.448.globl _main449.private_extern _main450_main:451  movb _ref_com@GOTPCREL(%rip), %al452  callq _ref_local453  retq454 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_globl459.no_dead_strip _no_dead_strip_globl460_no_dead_strip_globl:461  callq _ref_from_no_dead_strip_globl462  retq463_ref_from_no_dead_strip_globl:464  retq465 466# ...and for locals.467.no_dead_strip _no_dead_strip_local468_no_dead_strip_local:469  callq _ref_from_no_dead_strip_local470  retq471_ref_from_no_dead_strip_local:472  retq473 474.subsections_via_symbols475 476#--- exported-symbol.s477.text478 479.globl _unref_symbol480_unref_symbol:481  retq482 483.globl _my_exported_symbol484_my_exported_symbol:485  retq486 487.globl _main488_main:489  retq490 491.subsections_via_symbols492 493#--- abs.s494.globl _abs1, _abs2, _abs3495 496.no_dead_strip _abs1497_abs1 = 1498_abs2 = 2499_abs3 = 3500 501.section __DATA,__foo,regular,no_dead_strip502# Absolute symbols are not in a section, so the no_dead_strip503# on the section above has no effect.504.globl _abs4505_abs4 = 4506 507.text508.globl _main509_main:510  # This is relaxed away, so there's no relocation here and511  # _abs3 isn't in the exported symbol table.512  mov _abs3, %rax513  retq514 515.subsections_via_symbols516 517#--- mod-funcs.s518## 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_instructions521 522__unref:523  retq524 525_ref_from_init:526  retq527 528_ref_init:529  callq _ref_from_init530  retq531 532_ref_from_term:533  retq534 535_ref_term:536  callq _ref_from_term537  retq538 539.globl _main540_main:541  retq542 543.section __DATA,__mod_init_func,mod_init_funcs544.quad _ref_init545 546.section __DATA,__mod_term_func,mod_term_funcs547.quad _ref_term548 549.subsections_via_symbols550 551#--- dylib.s552.text553 554.globl _ref_dylib_fun555_ref_dylib_fun:556  retq557 558.globl _unref_dylib_fun559_unref_dylib_fun:560  retq561 562.subsections_via_symbols563 564#--- strip-dylib-ref.s565.text566 567_unref:568  callq _ref_dylib_fun569  callq _unref_dylib_fun570  callq _ref_undef_fun571  callq _unref_undef_fun572  retq573 574.globl _main575_main:576  callq _ref_dylib_fun577  callq _ref_undef_fun578  retq579 580.subsections_via_symbols581 582#--- live-support.s583## In practice, live_support is used for instruction profiling584## data and asan. (Also for __eh_frame, but that needs special handling585## 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_support588_ref_ls_fun_fw:589  # This is called by _main and is kept alive by normal590  # forward liveness propagation, The live_support attribute591  # does nothing in this case.592  retq593 594.section __TEXT,__unref_ls_fw,regular,live_support595_unref_ls_fun_fw:596  retq597 598.section __TEXT,__ref_ls_bw,regular,live_support599_ref_ls_fun_bw:600  # This _calls_ something that's alive but isn't referenced itself. This is601  # kept alive only due to this being in a live_support section.602  callq _foo603 604  # _bar on the other hand is kept alive since it's called from here.605  callq _bar606  retq607 608## Kept alive by a live symbol form a dynamic library.609_ref_ls_dylib_fun:610  callq _ref_dylib_fun611  retq612 613## Kept alive by a live undefined symbol.614_ref_ls_undef_fun:615  callq _ref_undef_fun616  retq617 618## All symbols in this live_support section reference dead symbols619## and are hence dead themselves.620.section __TEXT,__unref_ls_bw,regular,live_support621_unref_ls_fun_bw:622  callq _unref623  retq624 625_unref_ls_dylib_fun_bw:626  callq _unref_dylib_fun627  retq628 629_unref_ls_undef_fun_bw:630  callq _unref_undef_fun631  retq632 633.text634.globl _unref635_unref:636  retq637 638.globl _bar639_bar:640  retq641 642.globl _foo643_foo:644  callq _ref_ls_fun_fw645  retq646 647.globl _main648_main:649  callq _ref_ls_fun_fw650  callq _foo651  callq _ref_dylib_fun652  callq _ref_undef_fun653  retq654 655.subsections_via_symbols656 657#--- live-support-iterations.s658.section __TEXT,_ls,regular,live_support659 660## This is a live_support subsection that only becomes661## live after _foo below is processed. This means the algorithm of662## 1. mark things reachable from gc roots live663## 2. go through live sections and mark the ones live pointing to664##    live symbols or sections665## needs more than one iteration, since _bar won't be live when step 2666## runs for the first time.667## (ld64 gets this wrong -- it has different output based on if _bar is668## before _foo or after it.)669_bar:670  callq _foo_refd671  callq _bar_refd672  retq673 674## Same here. This is maybe more interesting since it references a live_support675## symbol instead of a "normal" symbol.676_baz:677  callq _foo_refd678  callq _baz_refd679  retq680 681_foo:682  callq _main683  callq _foo_refd684  retq685 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.688.no_dead_strip689_quux:690  retq691 692 693.text694.globl _main695_main:696  movq $0, %rax697  retq698 699_foo_refd:700  retq701 702_bar_refd:703  retq704 705_baz_refd:706  retq707 708.subsections_via_symbols709 710#--- unwind.s711## This is the output of `clang -O2 -S throw.cc` where throw.cc712## looks like this:713##     int unref() {714##       try {715##         throw 0;716##       } catch (int i) {717##         return i + 1;718##       }719##     }720##     int main() {721##       try {722##         throw 0;723##       } catch (int i) {724##         return i;725##       }726##     }727.section __TEXT,__text,regular,pure_instructions728.globl __Z5unrefv                      ## -- Begin function _Z5unrefv729.p2align 4, 0x90730__Z5unrefv:                             ## @_Z5unrefv731Lfunc_begin0:732  .cfi_startproc733  .cfi_personality 155, ___gxx_personality_v0734  .cfi_lsda 16, Lexception0735## %bb.0:736  pushq  %rbp737  .cfi_def_cfa_offset 16738  .cfi_offset %rbp, -16739  movq  %rsp, %rbp740  .cfi_def_cfa_register %rbp741  subq  $16, %rsp742  movl  $4, %edi743  callq  ___cxa_allocate_exception744  movl  $0, (%rax)745Ltmp0:746  movq  __ZTIi@GOTPCREL(%rip), %rsi747  movq  %rax, %rdi748  xorl  %edx, %edx749  callq  ___cxa_throw750Ltmp1:751## %bb.1:752  ud2753LBB0_2:754Ltmp2:755  leaq  -4(%rbp), %rcx756  movq  %rax, %rdi757  movl  %edx, %esi758  movq  %rcx, %rdx759  callq  __Z5unrefv.cold.1760  movl  -4(%rbp), %eax761  addq  $16, %rsp762  popq  %rbp763  retq764Lfunc_end0:765  .cfi_endproc766  .section  __TEXT,__gcc_except_tab767  .p2align 2768GCC_except_table0:769Lexception0:770  .byte 255                             ## @LPStart Encoding = omit771  .byte 155                             ## @TType Encoding = indirect pcrel sdata4772  .uleb128 Lttbase0-Lttbaseref0773Lttbaseref0:774  .byte 1                               ## Call site Encoding = uleb128775  .uleb128 Lcst_end0-Lcst_begin0776Lcst_begin0:777  .uleb128 Lfunc_begin0-Lfunc_begin0    ## >> Call Site 1 <<778  .uleb128 Ltmp0-Lfunc_begin0           ##   Call between Lfunc_begin0 and Ltmp0779  .byte 0                               ##     has no landing pad780  .byte 0                               ##   On action: cleanup781  .uleb128 Ltmp0-Lfunc_begin0           ## >> Call Site 2 <<782  .uleb128 Ltmp1-Ltmp0                  ##   Call between Ltmp0 and Ltmp1783  .uleb128 Ltmp2-Lfunc_begin0           ##     jumps to Ltmp2784  .byte 1                               ##   On action: 1785  .uleb128 Ltmp1-Lfunc_begin0           ## >> Call Site 3 <<786  .uleb128 Lfunc_end0-Ltmp1             ##   Call between Ltmp1 and Lfunc_end0787  .byte 0                               ##     has no landing pad788  .byte 0                               ##   On action: cleanup789Lcst_end0:790  .byte 1                               ## >> Action Record 1 <<791                                        ##   Catch TypeInfo 1792  .byte 0                               ##   No further actions793  .p2align 2794                                        ## >> Catch TypeInfos <<795  .long  __ZTIi@GOTPCREL+4              ## TypeInfo 1796Lttbase0:797  .p2align 2798                                        ## -- End function799  .section  __TEXT,__text,regular,pure_instructions800  .globl  _main                         ## -- Begin function main801  .p2align 4, 0x90802_main:                                  ## @main803Lfunc_begin1:804  .cfi_startproc805  .cfi_personality 155, ___gxx_personality_v0806  .cfi_lsda 16, Lexception1807## %bb.0:808  pushq  %rbp809  .cfi_def_cfa_offset 16810  .cfi_offset %rbp, -16811  movq  %rsp, %rbp812  .cfi_def_cfa_register %rbp813  pushq  %rbx814  pushq  %rax815  .cfi_offset %rbx, -24816  movl  $4, %edi817  callq  ___cxa_allocate_exception818  movl  $0, (%rax)819Ltmp3:820  movq  __ZTIi@GOTPCREL(%rip), %rsi821  movq  %rax, %rdi822  xorl  %edx, %edx823  callq ___cxa_throw824Ltmp4:825## %bb.1:826  ud2827LBB1_2:828Ltmp5:829  movq  %rax, %rdi830  callq ___cxa_begin_catch831  movl  (%rax), %ebx832  callq ___cxa_end_catch833  movl  %ebx, %eax834  addq  $8, %rsp835  popq  %rbx836  popq  %rbp837  retq838Lfunc_end1:839  .cfi_endproc840  .section  __TEXT,__gcc_except_tab841  .p2align  2842GCC_except_table1:843Lexception1:844  .byte 255                             ## @LPStart Encoding = omit845  .byte 155                             ## @TType Encoding = indirect pcrel sdata4846  .uleb128 Lttbase1-Lttbaseref1847Lttbaseref1:848  .byte 1                               ## Call site Encoding = uleb128849  .uleb128 Lcst_end1-Lcst_begin1850Lcst_begin1:851  .uleb128 Lfunc_begin1-Lfunc_begin1    ## >> Call Site 1 <<852  .uleb128 Ltmp3-Lfunc_begin1           ##   Call between Lfunc_begin1 and Ltmp3853  .byte 0                               ##     has no landing pad854  .byte 0                               ##   On action: cleanup855  .uleb128 Ltmp3-Lfunc_begin1           ## >> Call Site 2 <<856  .uleb128 Ltmp4-Ltmp3                  ##   Call between Ltmp3 and Ltmp4857  .uleb128 Ltmp5-Lfunc_begin1           ##     jumps to Ltmp5858  .byte 1                               ##   On action: 1859  .uleb128 Ltmp4-Lfunc_begin1           ## >> Call Site 3 <<860  .uleb128 Lfunc_end1-Ltmp4             ##   Call between Ltmp4 and Lfunc_end1861  .byte 0                               ##     has no landing pad862  .byte 0                               ##   On action: cleanup863Lcst_end1:864  .byte 1                               ## >> Action Record 1 <<865                                        ##   Catch TypeInfo 1866  .byte 0                               ##   No further actions867  .p2align 2868                                        ## >> Catch TypeInfos <<869  .long __ZTIi@GOTPCREL+4               ## TypeInfo 1870Lttbase1:871  .p2align 2872                                        ## -- End function873  .section __TEXT,__text,regular,pure_instructions874  .p2align 4, 0x90                      ## -- Begin function _Z5unrefv.cold.1875__Z5unrefv.cold.1:                      ## @_Z5unrefv.cold.1876  .cfi_startproc877## %bb.0:878  pushq  %rbp879  .cfi_def_cfa_offset 16880  .cfi_offset %rbp, -16881  movq  %rsp, %rbp882  .cfi_def_cfa_register %rbp883  pushq  %rbx884  pushq  %rax885  .cfi_offset %rbx, -24886  movq  %rdx, %rbx887  callq  ___cxa_begin_catch888  movl  (%rax), %eax889  incl  %eax890  movl  %eax, (%rbx)891  addq  $8, %rsp892  popq  %rbx893  popq  %rbp894  jmp  ___cxa_end_catch                 ## TAILCALL895  .cfi_endproc896                                        ## -- End function897.subsections_via_symbols898 899#--- weak-ref.s900.text901.weak_reference _ref_dylib_fun902.globl _main903_main:904  callq _ref_dylib_fun905  retq906 907.subsections_via_symbols908 909#--- strong-dead-ref.s910.text911.globl _unref_dylib_fun912_unref:913  callq _unref_dylib_fun914  retq915 916.subsections_via_symbols917 918#--- weak-dylib.s919.text920.globl _weak_in_dylib921.weak_definition _weak_in_dylib922_weak_in_dylib:923  retq924 925.subsections_via_symbols926 927#--- dead-weak-override.s928 929## Overrides the _weak_in_dylib symbol in weak-dylib, but is dead stripped.930.text931 932#.no_dead_strip _weak_in_dylib933.globl _weak_in_dylib934_weak_in_dylib:935  retq936 937.globl _main938_main:939  retq940 941.subsections_via_symbols942 943#--- debug.s944.text945.globl _unref946_unref:947  retq948 949.globl _main950_main:951  retq952 953.subsections_via_symbols954 955#--- no-dead-symbols.s956.text957.globl _main958_main:959  retq960 961#--- literals.s962.cstring963_unref_foo:964  .ascii "foo"965_bar:966Lbar:967  .asciz "bar"968_unref_baz:969  .asciz "baz"970 971.literal4972.p2align 2973L._foo4:974  .long 0xdeadbeef975L._bar4:976  .long 0xdeadbeef977L._unref:978  .long 0xfeedface979 980.section __DATA,str_ptrs,literal_pointers981.globl _data982_data:983  .quad _bar984  .quad Lbar985 986## The output binary has these integer literals put into a section that isn't987## marked with a S_*BYTE_LITERALS flag, so we don't mark word_ptrs with the988## S_LITERAL_POINTERS flag in order not to confuse llvm-objdump.989.section __DATA,word_ptrs990.globl _more_data991_more_data:992  .quad L._foo4993  .quad L._bar4994 995.subsections_via_symbols996 997#--- ref-undef.s998.globl _main999_main:1000  callq _ref_undef_fun1001.subsections_via_symbols1002 1003#--- addrsig.s1004.globl _main, _addrsig1005_main:1006  retq1007 1008_addrsig:1009  retq1010 1011.subsections_via_symbols1012 1013.addrsig1014.addrsig_sym _addrsig1015