Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / dylink.s
blob29464602d9d09c6787e097d1a5a0a3240d673a3b
1 # REQUIRES: x86
2 # RUN: mkdir -p %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s \
4 # RUN: -o %t/libhello.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
6 # RUN: -o %t/libgoodbye.o
7 # RUN: %lld -dylib -install_name @executable_path/libhello.dylib \
8 # RUN: -compatibility_version 10 -current_version 11 \
9 # RUN: %t/libhello.o -o %t/libhello.dylib
10 # RUN: %lld -dylib -install_name \
11 # RUN: @executable_path/libgoodbye.dylib %t/libgoodbye.o -o %t/libgoodbye.dylib
13 ## Make sure we are using the export trie and not the symbol table when linking
14 ## against these dylibs.
15 # RUN: llvm-strip %t/libhello.dylib
16 # RUN: llvm-strip %t/libgoodbye.dylib
17 # RUN: llvm-nm %t/libhello.dylib 2>&1 | FileCheck %s --check-prefix=NOSYM
18 # RUN: llvm-nm %t/libgoodbye.dylib 2>&1 | FileCheck %s --check-prefix=NOSYM
19 # NOSYM: no symbols
21 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/dylink.o
22 # RUN: %lld -o %t/dylink -L%t -lhello -lgoodbye %t/dylink.o
23 # RUN: llvm-objdump --no-print-imm-hex --bind -d --no-show-raw-insn %t/dylink | FileCheck %s
25 # CHECK: movq [[#%u, HELLO_OFF:]](%rip), %rsi
26 # CHECK-NEXT: [[#%x, HELLO_RIP:]]:
28 # CHECK: movq [[#%u, HELLO_ITS_ME_OFF:]](%rip), %rsi
29 # CHECK-NEXT: [[#%x, HELLO_ITS_ME_RIP:]]:
31 # CHECK: pushq [[#%u, GOODBYE_OFF:]](%rip)
32 # CHECK-NEXT: [[#%x, GOODBYE_RIP:]]: popq %rsi
34 # CHECK-LABEL: Bind table:
35 # CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, HELLO_RIP + HELLO_OFF]] pointer 0 libhello _hello_world
36 # CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, HELLO_ITS_ME_RIP + HELLO_ITS_ME_OFF]] pointer 0 libhello _hello_its_me
37 # CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, GOODBYE_RIP + GOODBYE_OFF]] pointer 0 libgoodbye _goodbye_world
38 # CHECK-DAG: __DATA __data 0x[[#%x, DATA_ADDR:]] pointer 0 libhello _hello_world
39 # CHECK-DAG: __DATA __data 0x{{0*}}[[#%x, DATA_ADDR + 8]] pointer 8 libhello _hello_its_me
40 # CHECK-DAG: __DATA __data 0x{{0*}}[[#%x, DATA_ADDR + 16]] pointer -15 libgoodbye _goodbye_world
42 # RUN: llvm-nm -m %t/dylink | FileCheck --check-prefix=NM %s
44 # NM-DAG: _goodbye_world (from libgoodbye)
45 # NM-DAG: _hello_its_me (from libhello)
46 # NM-DAG: _hello_world (from libhello)
48 # RUN: llvm-objdump --macho --all-headers %t/dylink | FileCheck %s \
49 # RUN: --check-prefix=LOAD --implicit-check-not LC_LOAD_DYLIB
50 ## Check that we don't create duplicate LC_LOAD_DYLIBs.
51 # RUN: %lld -o %t/dylink -L%t -lhello -lhello -lgoodbye -lgoodbye %t/dylink.o
52 # RUN: llvm-objdump --macho --all-headers %t/dylink | FileCheck %s \
53 # RUN: --check-prefix=LOAD --implicit-check-not LC_LOAD_DYLIB
55 # LOAD: cmd LC_LOAD_DYLIB
56 # LOAD-NEXT: cmdsize
57 # LOAD-NEXT: name /usr/lib/libSystem.dylib
58 # LOAD: cmd LC_LOAD_DYLIB
59 # LOAD-NEXT: cmdsize
60 # LOAD-NEXT: name @executable_path/libhello.dylib
61 # LOAD-NEXT: time stamp
62 # LOAD-NEXT: current version 11.0.0
63 # LOAD-NEXT: compatibility version 10.0.0
64 # LOAD: cmd LC_LOAD_DYLIB
65 # LOAD-NEXT: cmdsize
66 # LOAD-NEXT: name @executable_path/libgoodbye.dylib
68 .section __TEXT,__text
69 .globl _main
71 _main:
72 movl $0x2000004, %eax # write() syscall
73 mov $1, %rdi # stdout
74 movq _hello_world@GOTPCREL(%rip), %rsi
75 mov $13, %rdx # length of str
76 syscall
78 movl $0x2000004, %eax # write() syscall
79 mov $1, %rdi # stdout
80 movq _hello_its_me@GOTPCREL(%rip), %rsi
81 mov $15, %rdx # length of str
82 syscall
84 movl $0x2000004, %eax # write() syscall
85 mov $1, %rdi # stdout
86 pushq _goodbye_world@GOTPCREL(%rip)
87 popq %rsi
88 mov $15, %rdx # length of str
89 syscall
90 mov $0, %rax
91 ret
93 .data
94 .quad _hello_world
95 .quad _hello_its_me + 0x8
96 .quad _goodbye_world - 0xf