2020-04-22 04:37:57 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
# RUN: mkdir -p %t
|
2020-04-29 07:58:22 +08:00
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s \
|
|
|
|
# RUN: -o %t/libhello.o
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
|
|
|
|
# RUN: -o %t/libgoodbye.o
|
2020-12-16 04:25:15 +08:00
|
|
|
# RUN: %lld -dylib -install_name @executable_path/libhello.dylib \
|
|
|
|
# RUN: -compatibility_version 10 -current_version 11 \
|
|
|
|
# RUN: %t/libhello.o -o %t/libhello.dylib
|
2020-09-19 12:40:12 +08:00
|
|
|
# RUN: %lld -dylib -install_name \
|
2020-04-29 07:58:22 +08:00
|
|
|
# RUN: @executable_path/libgoodbye.dylib %t/libgoodbye.o -o %t/libgoodbye.dylib
|
[lld-macho] Use export trie instead of symtab when linking against dylibs
Summary:
This allows us to link against stripped dylibs. Moreover, it's simply
more correct: The symbol table includes symbols that the dylib uses but
doesn't export.
This temporarily regresses our ability to do lazy symbol binding because
dyld_stub_binder isn't in libSystem's export trie. Rather, it is in one
of the sub-libraries libSystem re-exports. (This doesn't affect our
tests since we are mocking out dyld_stub_binder there.) A follow-up diff
will address this by adding support for sub-libraries.
Depends on D79114.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: mgorny, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79226
2020-04-23 11:00:57 +08:00
|
|
|
|
|
|
|
## Make sure we are using the export trie and not the symbol table when linking
|
|
|
|
## against these dylibs.
|
|
|
|
# RUN: llvm-strip %t/libhello.dylib
|
|
|
|
# RUN: llvm-strip %t/libgoodbye.dylib
|
|
|
|
# RUN: llvm-nm %t/libhello.dylib 2>&1 | FileCheck %s --check-prefix=NOSYM
|
|
|
|
# RUN: llvm-nm %t/libgoodbye.dylib 2>&1 | FileCheck %s --check-prefix=NOSYM
|
|
|
|
# NOSYM: no symbols
|
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/dylink.o
|
2020-09-19 12:40:12 +08:00
|
|
|
# RUN: %lld -o %t/dylink -L%t -lhello -lgoodbye %t/dylink.o
|
2020-06-14 10:58:15 +08:00
|
|
|
# RUN: llvm-objdump --bind -d --no-show-raw-insn %t/dylink | FileCheck %s
|
2020-04-22 04:37:57 +08:00
|
|
|
|
|
|
|
# CHECK: movq [[#%u, HELLO_OFF:]](%rip), %rsi
|
|
|
|
# CHECK-NEXT: [[#%x, HELLO_RIP:]]:
|
|
|
|
|
2020-04-30 06:42:19 +08:00
|
|
|
# CHECK: movq [[#%u, HELLO_ITS_ME_OFF:]](%rip), %rsi
|
|
|
|
# CHECK-NEXT: [[#%x, HELLO_ITS_ME_RIP:]]:
|
|
|
|
|
2020-06-14 10:58:15 +08:00
|
|
|
# CHECK: pushq [[#%u, GOODBYE_OFF:]](%rip)
|
|
|
|
# CHECK-NEXT: [[#%x, GOODBYE_RIP:]]: popq %rsi
|
2020-04-22 04:37:57 +08:00
|
|
|
|
|
|
|
# CHECK-LABEL: Bind table:
|
2020-07-03 12:19:55 +08:00
|
|
|
# CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, HELLO_RIP + HELLO_OFF]] pointer 0 libhello _hello_world
|
|
|
|
# CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, HELLO_ITS_ME_RIP + HELLO_ITS_ME_OFF]] pointer 0 libhello _hello_its_me
|
|
|
|
# CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, GOODBYE_RIP + GOODBYE_OFF]] pointer 0 libgoodbye _goodbye_world
|
|
|
|
# CHECK-DAG: __DATA __data 0x[[#%x, DATA_ADDR:]] pointer 0 libhello _hello_world
|
|
|
|
# CHECK-DAG: __DATA __data 0x{{0*}}[[#%x, DATA_ADDR + 8]] pointer 8 libhello _hello_its_me
|
|
|
|
# CHECK-DAG: __DATA __data 0x{{0*}}[[#%x, DATA_ADDR + 16]] pointer -15 libgoodbye _goodbye_world
|
2020-04-22 04:37:57 +08:00
|
|
|
|
2020-12-16 02:36:15 +08:00
|
|
|
# RUN: llvm-nm -m %t/dylink | FileCheck --check-prefix=NM %s
|
|
|
|
|
|
|
|
# NM-DAG: _goodbye_world (from libgoodbye)
|
|
|
|
# NM-DAG: _hello_its_me (from libhello)
|
|
|
|
# NM-DAG: _hello_world (from libhello)
|
|
|
|
|
2020-12-10 14:29:28 +08:00
|
|
|
# RUN: llvm-objdump --macho --all-headers %t/dylink | FileCheck %s \
|
|
|
|
# RUN: --check-prefix=LOAD --implicit-check-not LC_LOAD_DYLIB
|
|
|
|
## Check that we don't create duplicate LC_LOAD_DYLIBs.
|
|
|
|
# RUN: %lld -o %t/dylink -L%t -lhello -lhello -lgoodbye -lgoodbye %t/dylink.o
|
|
|
|
# RUN: llvm-objdump --macho --all-headers %t/dylink | FileCheck %s \
|
|
|
|
# RUN: --check-prefix=LOAD --implicit-check-not LC_LOAD_DYLIB
|
|
|
|
|
2020-12-16 04:25:15 +08:00
|
|
|
# LOAD: cmd LC_LOAD_DYLIB
|
|
|
|
# LOAD-NEXT: cmdsize
|
|
|
|
# LOAD-NEXT: name @executable_path/libhello.dylib
|
|
|
|
# LOAD-NEXT: time stamp
|
|
|
|
# LOAD-NEXT: current version 11.0.0
|
|
|
|
# LOAD-NEXT: compatibility version 10.0.0
|
|
|
|
# LOAD: cmd LC_LOAD_DYLIB
|
|
|
|
# LOAD-NEXT: cmdsize
|
|
|
|
# LOAD-NEXT: name @executable_path/libgoodbye.dylib
|
2020-12-10 14:29:28 +08:00
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
.section __TEXT,__text
|
|
|
|
.globl _main
|
|
|
|
|
|
|
|
_main:
|
|
|
|
movl $0x2000004, %eax # write() syscall
|
|
|
|
mov $1, %rdi # stdout
|
|
|
|
movq _hello_world@GOTPCREL(%rip), %rsi
|
|
|
|
mov $13, %rdx # length of str
|
|
|
|
syscall
|
|
|
|
|
2020-04-30 06:42:19 +08:00
|
|
|
movl $0x2000004, %eax # write() syscall
|
|
|
|
mov $1, %rdi # stdout
|
|
|
|
movq _hello_its_me@GOTPCREL(%rip), %rsi
|
|
|
|
mov $15, %rdx # length of str
|
|
|
|
syscall
|
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
movl $0x2000004, %eax # write() syscall
|
|
|
|
mov $1, %rdi # stdout
|
2020-06-14 10:58:15 +08:00
|
|
|
pushq _goodbye_world@GOTPCREL(%rip)
|
|
|
|
popq %rsi
|
2020-04-22 04:37:57 +08:00
|
|
|
mov $15, %rdx # length of str
|
|
|
|
syscall
|
|
|
|
mov $0, %rax
|
|
|
|
ret
|
2020-07-03 12:19:55 +08:00
|
|
|
|
|
|
|
.data
|
|
|
|
.quad _hello_world
|
|
|
|
.quad _hello_its_me + 0x8
|
|
|
|
.quad _goodbye_world - 0xf
|