brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.0 KiB · ca3ad06 Raw
146 lines · plain
1# REQUIRES: x862 3# RUN: rm -rf %t; split-file %s %t4 5# RUN: llvm-mc %t/bar.s -triple=x86_64-apple-macos -filetype=obj -o %t/bar.o6# RUN: %lld -dylib %t/bar.o -o %t/bar.dylib7# RUN: %lld -dylib %t/bar.o -o %t/libbar.dylib8# RUN: %lld -dylib -mark_dead_strippable_dylib %t/bar.o -o %t/bar-strip.dylib9 10# RUN: llvm-mc %t/foo.s -triple=x86_64-apple-macos -filetype=obj -o %t/foo.o11# RUN: %lld -dylib %t/foo.o -o %t/foo_with_bar.dylib %t/bar.dylib -sub_library bar12# RUN: %lld -dylib %t/foo.o -o %t/foo.dylib13 14# RUN: llvm-mc %t/weak-foo.s -triple=x86_64-apple-macos -filetype=obj -o %t/weak-foo.o15# RUN: %lld -dylib %t/weak-foo.o -o %t/weak-foo.dylib16 17# RUN: llvm-mc %t/main.s -triple=x86_64-apple-macos -filetype=obj -o %t/main.o18 19## foo_with_bar.dylib's reexport should be dropped since it's linked implicitly.20# RUN: %lld -lSystem %t/main.o -o %t/main %t/foo_with_bar.dylib21# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOBAR %s22# NOBAR-NOT: bar.dylib23# NOBAR: /usr/lib/libSystem.dylib24# NOBAR-NOT: bar.dylib25# NOBAR: foo_with_bar.dylib26# NOBAR-NOT: bar.dylib27 28## If bar.dylib is linked explicitly, it should not be dropped.29# RUN: %lld -lSystem %t/main.o -o %t/main %t/foo_with_bar.dylib %t/bar.dylib30# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=BAR %s31# BAR: /usr/lib/libSystem.dylib32# BAR: foo_with_bar.dylib33# BAR: bar.dylib34 35## ...except if -dead-strip_dylibs is passed...36# RUN: %lld -lSystem %t/main.o -o %t/main %t/foo_with_bar.dylib %t/bar.dylib \37# RUN:      -dead_strip_dylibs38# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOBAR %s39 40## ...or bar is explicitly marked dead-strippable.41# RUN: %lld -lSystem %t/main.o -o %t/main %t/foo.dylib %t/bar-strip.dylib42# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOBARSTRIP %s43# NOBARSTRIP-NOT: bar-strip.dylib44# NOBARSTRIP: /usr/lib/libSystem.dylib45# NOBARSTRIP-NOT: bar-strip.dylib46# NOBARSTRIP: foo.dylib47# NOBARSTRIP-NOT: bar-strip.dylib48 49## Even libraries explicitly reexported with -reexport_library are stripped50## if they are not referenced.51# RUN: %lld -lSystem %t/main.o -o %t/main %t/foo_with_bar.dylib \52# RUN:     -reexport_library %t/bar.dylib -dead_strip_dylibs53# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOBAR %s54# RUN: llvm-otool -l %t/main | FileCheck --check-prefix=NOREEXPORT %s55# NOREEXPORT-NOT: LC_REEXPORT_DYLIB56 57## But -needed_library and -needed-l win over -dead_strip_dylibs again.58# RUN: %lld -lSystem %t/main.o -o %t/main %t/foo_with_bar.dylib \59# RUN:     -needed_library %t/bar.dylib -dead_strip_dylibs60# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=BAR %s61# RUN: %lld -lSystem %t/main.o -o %t/main %t/foo_with_bar.dylib \62# RUN:     -L%t -needed-lbar -dead_strip_dylibs63# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=BAR %s64 65## LC_LINKER_OPTION does not count as an explicit reference.66# RUN: llvm-mc %t/linkopt_bar.s -triple=x86_64-apple-macos -filetype=obj -o %t/linkopt_bar.o67# RUN: %lld -lSystem %t/main.o %t/linkopt_bar.o -o %t/main -L %t %t/foo.dylib68# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOLIBBAR %s69# NOLIBBAR-NOT: libbar.dylib70# NOLIBBAR: /usr/lib/libSystem.dylib71# NOLIBBAR-NOT: libbar.dylib72# NOLIBBAR: foo.dylib73# NOLIBBAR-NOT: libbar.dylib74 75## ...but with an additional explicit reference it's not stripped again.76# RUN: %lld -lSystem %t/main.o %t/linkopt_bar.o -o %t/main -L %t %t/foo.dylib -lbar77# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=LIBBAR %s78# RUN: %lld -lSystem %t/main.o -o %t/main -L %t %t/foo.dylib -lbar %t/linkopt_bar.o79# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=LIBBAR %s80# LIBBAR-DAG: /usr/lib/libSystem.dylib81# LIBBAR-DAG: libbar.dylib82# LIBBAR-DAG: foo.dylib83 84## Test that a DylibSymbol being replaced by a DefinedSymbol marks the85## dylib as unreferenced.86## (Note: Since there's no dynamic linking in this example, libSystem is87## stripped too. Since libSystem.dylib is needed to run an executable for88## LC_MAIN, the output would crash when run. This matches ld64's behavior (!)89## In practice, every executable uses dynamic linking, which uses90## dyld_stub_binder, which keeps libSystem alive.)91## Test all permutations of (Undefined, Defined, DylibSymbol).92# RUN: %lld -lSystem -dead_strip_dylibs %t/main.o %t/foo.o %t/foo.dylib -o %t/main93# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOFOO %s94# RUN: %lld -lSystem -dead_strip_dylibs %t/main.o %t/foo.dylib %t/foo.dylib %t/foo.o -o %t/main95# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOFOO %s96 97# RUN: %lld -lSystem -dead_strip_dylibs %t/foo.o %t/main.o %t/foo.dylib -o %t/main98# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOFOO %s99# RUN: %lld -lSystem -dead_strip_dylibs %t/foo.dylib %t/foo.dylib %t/main.o %t/foo.o -o %t/main100# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOFOO %s101 102# RUN: %lld -lSystem -dead_strip_dylibs %t/foo.o %t/foo.dylib %t/main.o -o %t/main103# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOFOO %s104# RUN: %lld -lSystem -dead_strip_dylibs %t/foo.dylib %t/foo.dylib %t/foo.o %t/main.o -o %t/main105# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOFOO %s106# NOFOO-NOT: foo.dylib107 108## When linking a weak and a strong symbol from two dylibs, we should keep the109## strong one.110# RUN: %lld -lSystem -dead_strip_dylibs %t/main.o %t/foo.dylib %t/weak-foo.dylib -o %t/main111# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOWEAK %s112# RUN: %lld -lSystem -dead_strip_dylibs %t/main.o %t/weak-foo.dylib %t/foo.dylib -o %t/main113# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOWEAK %s114# RUN: %lld -lSystem -dead_strip_dylibs %t/foo.dylib %t/weak-foo.dylib %t/main.o -o %t/main115# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOWEAK %s116# RUN: %lld -lSystem -dead_strip_dylibs %t/weak-foo.dylib %t/foo.dylib %t/main.o -o %t/main117# RUN: llvm-otool -L %t/main | FileCheck --check-prefix=NOWEAK %s118# NOWEAK-NOT: weak-foo.dylib119# NOWEAK: /foo.dylib120# NOWEAK-NOT: weak-foo.dylib121 122#--- main.s123.globl _foo, _main124_main:125  callq _foo126  retq127 128#--- foo.s129.globl _foo130_foo:131  retq132 133#--- bar.s134.globl _bar135_bar:136  retq137 138#--- linkopt_bar.s139.linker_option "-lbar"140 141#--- weak-foo.s142.globl _foo143.weak_definition _foo144_foo:145  retq146