148 lines · plain
1# REQUIRES: x862# RUN: rm -rf %t; mkdir -p %t3 4## Create a libsuper that has libgoodbye as a sub-library, which in turn has5## libhello as another sub-library.6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s \7# RUN: -o %t/libhello.o8# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \9# RUN: -o %t/libgoodbye.o10# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/libsuper.o11# RUN: %lld -dylib %t/libhello.o -o %t/libhello.dylib12# RUN: %lld -dylib -L%t -sub_library libhello -lhello \13# RUN: %t/libgoodbye.o -o %t/libgoodbye.dylib14# RUN: %lld -dylib -L%t -sub_library libgoodbye -lgoodbye -install_name \15# RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib16 17 18## Check that they have the appropriate LC_REEXPORT_DYLIB commands, and that19## NO_REEXPORTED_DYLIBS is (un)set as appropriate.20 21# RUN: llvm-otool -hv %t/libhello.dylib | \22# RUN: FileCheck --check-prefix=HELLO-HEADERS %s23# HELLO-HEADERS: NO_REEXPORTED_DYLIBS24 25# RUN: llvm-otool -l %t/libgoodbye.dylib | FileCheck %s \26# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libhello.dylib27 28# RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \29# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib30 31# RUN: %lld -dylib -L%t -reexport-lgoodbye -install_name \32# RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib33# RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \34# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib35# RUN: %lld -dylib -reexport_library %t/libgoodbye.dylib -install_name \36# RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib37# RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \38# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib39 40# REEXPORT-HEADERS-NOT: NO_REEXPORTED_DYLIBS41# REEXPORT-HEADERS: cmd LC_REEXPORT_DYLIB42# REEXPORT-HEADERS-NOT: Load command43# REEXPORT-HEADERS: name [[PATH]]44 45## Check that specifying a library both with `l` and `reexport_library`46## doesn't emit two load commands.47# RUN: %lld -dylib -reexport_library %t/libgoodbye.dylib \48# RUN: -L%t -lgoodbye %t/libsuper.o -o %t/libsuper.dylib49# RUN: llvm-otool -L %t/libsuper.dylib | FileCheck %s \50# RUN: --check-prefix=REEXPORT-DOUBLE -DPATH=%t/libgoodbye.dylib51 52# REEXPORT-DOUBLE: [[PATH]]53# REEXPORT-DOUBLE-SAME: reexport54# REEXPORT-DOUBLE-NOT: [[PATH]]55 56# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/sub-library.o57# RUN: %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o58 59# RUN: llvm-objdump --macho --bind %t/sub-library | FileCheck %s60# CHECK-LABEL: Bind table:61# CHECK-DAG: __DATA_CONST __got {{.*}} libsuper _hello_world62# CHECK-DAG: __DATA_CONST __got {{.*}} libsuper _goodbye_world63 64 65## Check that we fail gracefully if the sub-library is missing66# RUN: not %lld -dylib -o %t/sub-library -sub_library libmissing %t/sub-library.o 2>&1 \67# RUN: | FileCheck %s --check-prefix=MISSING-SUB-LIBRARY68# MISSING-SUB-LIBRARY: error: -sub_library libmissing does not match a supplied dylib69# RUN: rm -f %t/libgoodbye.dylib70# RUN: not %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o 2>&1 \71# RUN: | FileCheck %s --check-prefix=MISSING-REEXPORT -DDIR=%t72# MISSING-REEXPORT: error: {{.*}}libsuper.dylib: unable to locate re-export with install name [[DIR]]/libgoodbye.dylib73 74 75## We can match dylibs without extensions too.76# RUN: mkdir -p %t/Hello.framework77# RUN: %lld -dylib %t/libhello.o -o %t/Hello.framework/Hello78# RUN: %lld -dylib -o %t/libgoodbye2.dylib -sub_library Hello %t/Hello.framework/Hello %t/libgoodbye.o79# RUN: llvm-otool -l %t/libgoodbye2.dylib | FileCheck %s \80# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello81 82## -sub_umbrella works almost identically...83# RUN: %lld -dylib -o %t/libgoodbye3.dylib -sub_umbrella Hello %t/Hello.framework/Hello %t/libgoodbye.o84# RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \85# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello86 87# RUN: %lld -dylib -o %t/libgoodbye3.dylib -F %t -framework Hello -sub_umbrella Hello %t/libgoodbye.o88# RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \89# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello90 91# RUN: %lld -dylib -o %t/libgoodbye3.dylib -F %t -reexport_framework Hello %t/libgoodbye.o92# RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \93# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello94 95## But it doesn't match .dylib extensions:96# RUN: not %lld -dylib -L%t -sub_umbrella libhello -lhello %t/libgoodbye.o \97# RUN: -o %t/libgoodbye.dylib 2>&1 | FileCheck %s --check-prefix=MISSING-FRAMEWORK98# MISSING-FRAMEWORK: error: -sub_umbrella libhello does not match a supplied dylib99 100 101## Check that -F (but not -L) can override the search path in install_name for102## frameworks.103# RUN: mkdir -p %t/Hello2.framework104# RUN: %lld -dylib %t/libhello.o \105# RUN: -install_name /path/to/Hello2.framework/Hello2 \106# RUN: -o %t/Hello2.framework/Hello2107# RUN: %lld -dylib -o %t/libgoodbye4.dylib %t/libgoodbye.o \108# RUN: -reexport_library %t/Hello2.framework/Hello2109# RUN: not %lld -lSystem -o %t/hello %t/libgoodbye4.dylib %t/sub-library.o 2>&1 \110# RUN: | FileCheck %s --check-prefix=NOTFOUND111# RUN: not %lld -lSystem -o %t/hello -L%t %t/libgoodbye4.dylib %t/sub-library.o 2>&1 \112# RUN: | FileCheck %s --check-prefix=NOTFOUND113# NOTFOUND: unable to locate re-export with install name /path/to/Hello2.framework/Hello2114# RUN: %lld -lSystem -o %t/hello -F%t %t/libgoodbye4.dylib %t/sub-library.o115 116## Check that -L (but not -F) can override the search path in install_name for117## libraries.118# RUN: %lld -dylib %t/libhello.o \119# RUN: -install_name /path/to/libhello2.dylib \120# RUN: -o %t/libhello2.dylib121# RUN: %lld -dylib -o %t/libgoodbye5.dylib %t/libgoodbye.o \122# RUN: -reexport_library %t/libhello2.dylib123# RUN: not %lld -lSystem -o %t/hello %t/libgoodbye5.dylib %t/sub-library.o 2>&1 \124# RUN: | FileCheck %s --check-prefix=NOTFOUND2125# RUN: not %lld -lSystem -o %t/hello -F%t %t/libgoodbye5.dylib %t/sub-library.o 2>&1 \126# RUN: | FileCheck %s --check-prefix=NOTFOUND2127# NOTFOUND2: unable to locate re-export with install name /path/to/libhello2.dylib128# RUN: %lld -lSystem -o %t/hello -L%t %t/libgoodbye5.dylib %t/sub-library.o129 130.text131.globl _main132 133_main:134 movl $0x2000004, %eax # write() syscall135 mov $1, %rdi # stdout136 movq _hello_world@GOTPCREL(%rip), %rsi137 mov $13, %rdx # length of str138 syscall139 mov $0, %rax140 141 movl $0x2000004, %eax # write() syscall142 mov $1, %rdi # stdout143 movq _goodbye_world@GOTPCREL(%rip), %rsi144 mov $15, %rdx # length of str145 syscall146 mov $0, %rax147 ret148