[X86][MC,LLD][NFC] Rename R_X86_64_REX2_GOTPCRELX (#116737)
[llvm-project.git] / lld / test / MachO / sub-library.s
blobed0a96aa58f90e30d40260ea5d6b8fd0ca7cd4bb
1 # REQUIRES: x86
2 # RUN: rm -rf %t; mkdir -p %t
4 ## Create a libsuper that has libgoodbye as a sub-library, which in turn has
5 ## 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.o
8 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
9 # RUN: -o %t/libgoodbye.o
10 # RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/libsuper.o
11 # RUN: %lld -dylib %t/libhello.o -o %t/libhello.dylib
12 # RUN: %lld -dylib -L%t -sub_library libhello -lhello \
13 # RUN: %t/libgoodbye.o -o %t/libgoodbye.dylib
14 # RUN: %lld -dylib -L%t -sub_library libgoodbye -lgoodbye -install_name \
15 # RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib
18 ## Check that they have the appropriate LC_REEXPORT_DYLIB commands, and that
19 ## NO_REEXPORTED_DYLIBS is (un)set as appropriate.
21 # RUN: llvm-otool -hv %t/libhello.dylib | \
22 # RUN: FileCheck --check-prefix=HELLO-HEADERS %s
23 # HELLO-HEADERS: NO_REEXPORTED_DYLIBS
25 # RUN: llvm-otool -l %t/libgoodbye.dylib | FileCheck %s \
26 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libhello.dylib
28 # RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \
29 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib
31 # RUN: %lld -dylib -L%t -reexport-lgoodbye -install_name \
32 # RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib
33 # RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \
34 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib
35 # RUN: %lld -dylib -reexport_library %t/libgoodbye.dylib -install_name \
36 # RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib
37 # RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \
38 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib
40 # REEXPORT-HEADERS-NOT: NO_REEXPORTED_DYLIBS
41 # REEXPORT-HEADERS: cmd LC_REEXPORT_DYLIB
42 # REEXPORT-HEADERS-NOT: Load command
43 # REEXPORT-HEADERS: name [[PATH]]
45 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/sub-library.o
46 # RUN: %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o
48 # RUN: llvm-objdump --macho --bind %t/sub-library | FileCheck %s
49 # CHECK-LABEL: Bind table:
50 # CHECK-DAG: __DATA_CONST __got {{.*}} libsuper _hello_world
51 # CHECK-DAG: __DATA_CONST __got {{.*}} libsuper _goodbye_world
54 ## Check that we fail gracefully if the sub-library is missing
55 # RUN: not %lld -dylib -o %t/sub-library -sub_library libmissing %t/sub-library.o 2>&1 \
56 # RUN: | FileCheck %s --check-prefix=MISSING-SUB-LIBRARY
57 # MISSING-SUB-LIBRARY: error: -sub_library libmissing does not match a supplied dylib
58 # RUN: rm -f %t/libgoodbye.dylib
59 # RUN: not %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o 2>&1 \
60 # RUN: | FileCheck %s --check-prefix=MISSING-REEXPORT -DDIR=%t
61 # MISSING-REEXPORT: error: {{.*}}libsuper.dylib: unable to locate re-export with install name [[DIR]]/libgoodbye.dylib
64 ## We can match dylibs without extensions too.
65 # RUN: mkdir -p %t/Hello.framework
66 # RUN: %lld -dylib %t/libhello.o -o %t/Hello.framework/Hello
67 # RUN: %lld -dylib -o %t/libgoodbye2.dylib -sub_library Hello %t/Hello.framework/Hello %t/libgoodbye.o
68 # RUN: llvm-otool -l %t/libgoodbye2.dylib | FileCheck %s \
69 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello
71 ## -sub_umbrella works almost identically...
72 # RUN: %lld -dylib -o %t/libgoodbye3.dylib -sub_umbrella Hello %t/Hello.framework/Hello %t/libgoodbye.o
73 # RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \
74 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello
76 # RUN: %lld -dylib -o %t/libgoodbye3.dylib -F %t -framework Hello -sub_umbrella Hello %t/libgoodbye.o
77 # RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \
78 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello
80 # RUN: %lld -dylib -o %t/libgoodbye3.dylib -F %t -reexport_framework Hello %t/libgoodbye.o
81 # RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \
82 # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello
84 ## But it doesn't match .dylib extensions:
85 # RUN: not %lld -dylib -L%t -sub_umbrella libhello -lhello %t/libgoodbye.o \
86 # RUN: -o %t/libgoodbye.dylib 2>&1 | FileCheck %s --check-prefix=MISSING-FRAMEWORK
87 # MISSING-FRAMEWORK: error: -sub_umbrella libhello does not match a supplied dylib
90 ## Check that -F (but not -L) can override the search path in install_name for
91 ## frameworks.
92 # RUN: mkdir -p %t/Hello2.framework
93 # RUN: %lld -dylib %t/libhello.o \
94 # RUN: -install_name /path/to/Hello2.framework/Hello2 \
95 # RUN: -o %t/Hello2.framework/Hello2
96 # RUN: %lld -dylib -o %t/libgoodbye4.dylib %t/libgoodbye.o \
97 # RUN: -reexport_library %t/Hello2.framework/Hello2
98 # RUN: not %lld -lSystem -o %t/hello %t/libgoodbye4.dylib %t/sub-library.o 2>&1 \
99 # RUN: | FileCheck %s --check-prefix=NOTFOUND
100 # RUN: not %lld -lSystem -o %t/hello -L%t %t/libgoodbye4.dylib %t/sub-library.o 2>&1 \
101 # RUN: | FileCheck %s --check-prefix=NOTFOUND
102 # NOTFOUND: unable to locate re-export with install name /path/to/Hello2.framework/Hello2
103 # RUN: %lld -lSystem -o %t/hello -F%t %t/libgoodbye4.dylib %t/sub-library.o
105 ## Check that -L (but not -F) can override the search path in install_name for
106 ## libraries.
107 # RUN: %lld -dylib %t/libhello.o \
108 # RUN: -install_name /path/to/libhello2.dylib \
109 # RUN: -o %t/libhello2.dylib
110 # RUN: %lld -dylib -o %t/libgoodbye5.dylib %t/libgoodbye.o \
111 # RUN: -reexport_library %t/libhello2.dylib
112 # RUN: not %lld -lSystem -o %t/hello %t/libgoodbye5.dylib %t/sub-library.o 2>&1 \
113 # RUN: | FileCheck %s --check-prefix=NOTFOUND2
114 # RUN: not %lld -lSystem -o %t/hello -F%t %t/libgoodbye5.dylib %t/sub-library.o 2>&1 \
115 # RUN: | FileCheck %s --check-prefix=NOTFOUND2
116 # NOTFOUND2: unable to locate re-export with install name /path/to/libhello2.dylib
117 # RUN: %lld -lSystem -o %t/hello -L%t %t/libgoodbye5.dylib %t/sub-library.o
119 .text
120 .globl _main
122 _main:
123 movl $0x2000004, %eax # write() syscall
124 mov $1, %rdi # stdout
125 movq _hello_world@GOTPCREL(%rip), %rsi
126 mov $13, %rdx # length of str
127 syscall
128 mov $0, %rax
130 movl $0x2000004, %eax # write() syscall
131 mov $1, %rdi # stdout
132 movq _goodbye_world@GOTPCREL(%rip), %rsi
133 mov $15, %rdx # length of str
134 syscall
135 mov $0, %rax