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 \
8# RUN:   @executable_path/libhello.dylib %t/libhello.o -o %t/libhello.dylib
9# RUN: %lld -dylib -install_name \
10# RUN:   @executable_path/libgoodbye.dylib %t/libgoodbye.o -o %t/libgoodbye.dylib
11
12## Make sure we are using the export trie and not the symbol table when linking
13## against these dylibs.
14# RUN: llvm-strip %t/libhello.dylib
15# RUN: llvm-strip %t/libgoodbye.dylib
16# RUN: llvm-nm %t/libhello.dylib 2>&1 | FileCheck %s --check-prefix=NOSYM
17# RUN: llvm-nm %t/libgoodbye.dylib 2>&1 | FileCheck %s --check-prefix=NOSYM
18# NOSYM: no symbols
19
20# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/dylink.o
21# RUN: %lld -o %t/dylink -L%t -lhello -lgoodbye %t/dylink.o
22# RUN: llvm-objdump --bind -d --no-show-raw-insn %t/dylink | FileCheck %s
23
24# CHECK: movq [[#%u, HELLO_OFF:]](%rip), %rsi
25# CHECK-NEXT: [[#%x, HELLO_RIP:]]:
26
27# CHECK: movq [[#%u, HELLO_ITS_ME_OFF:]](%rip), %rsi
28# CHECK-NEXT: [[#%x, HELLO_ITS_ME_RIP:]]:
29
30# CHECK: pushq [[#%u, GOODBYE_OFF:]](%rip)
31# CHECK-NEXT: [[#%x, GOODBYE_RIP:]]: popq %rsi
32
33# CHECK-LABEL: Bind table:
34# CHECK-DAG: __DATA_CONST __got  0x{{0*}}[[#%x, HELLO_RIP + HELLO_OFF]]               pointer 0   libhello   _hello_world
35# CHECK-DAG: __DATA_CONST __got  0x{{0*}}[[#%x, HELLO_ITS_ME_RIP + HELLO_ITS_ME_OFF]] pointer 0   libhello   _hello_its_me
36# CHECK-DAG: __DATA_CONST __got  0x{{0*}}[[#%x, GOODBYE_RIP + GOODBYE_OFF]]           pointer 0   libgoodbye _goodbye_world
37# CHECK-DAG: __DATA       __data 0x[[#%x, DATA_ADDR:]]                                pointer 0   libhello   _hello_world
38# CHECK-DAG: __DATA       __data 0x{{0*}}[[#%x, DATA_ADDR + 8]]                       pointer 8   libhello   _hello_its_me
39# CHECK-DAG: __DATA       __data 0x{{0*}}[[#%x, DATA_ADDR + 16]]                      pointer -15 libgoodbye _goodbye_world
40
41.section __TEXT,__text
42.globl _main
43
44_main:
45  movl $0x2000004, %eax # write() syscall
46  mov $1, %rdi # stdout
47  movq _hello_world@GOTPCREL(%rip), %rsi
48  mov $13, %rdx # length of str
49  syscall
50
51  movl $0x2000004, %eax # write() syscall
52  mov $1, %rdi # stdout
53  movq _hello_its_me@GOTPCREL(%rip), %rsi
54  mov $15, %rdx # length of str
55  syscall
56
57  movl $0x2000004, %eax # write() syscall
58  mov $1, %rdi # stdout
59  pushq _goodbye_world@GOTPCREL(%rip)
60  popq %rsi
61  mov $15, %rdx # length of str
62  syscall
63  mov $0, %rax
64  ret
65
66.data
67.quad _hello_world
68.quad _hello_its_me + 0x8
69.quad _goodbye_world - 0xf
70