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: %lld -lSystem -dylib -install_name \ 6# RUN: @executable_path/libhello.dylib %t/libhello.o -o %t/libhello.dylib 7# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o 8# RUN: %lld -lSystem -o %t/test %t/test.o -L%t -lhello 9# RUN: llvm-objdump --full-contents --rebase --bind %t/test | FileCheck %s --match-full-lines 10 11## Check that the GOT references the cstrings. --full-contents displays the 12## address offset and the contents at that address very similarly, so am using 13## --match-full-lines to make sure we match on the right thing. 14# CHECK: Contents of section __TEXT,__cstring: 15# CHECK-NEXT: 100000424 {{.*}} 16 17## 1st 8 bytes refer to the start of __cstring + 0xe, 2nd 8 bytes refer to the 18## start of __cstring 19# CHECK: Contents of section __DATA_CONST,__got: 20# CHECK-NEXT: [[#%X,ADDR:]] 32040000 01000000 24040000 01000000 {{.*}} 21# CHECK-NEXT: [[#ADDR + 16]] 00000000 00000000 {{.*}} 22 23## Check that the rebase table is empty. 24# CHECK: Rebase table: 25# CHECK-NEXT: segment section address type 26 27## Check that a non-locally-defined symbol is still bound at the correct offset: 28# CHECK-NEXT: Bind table: 29# CHECK-NEXT: segment section address type addend dylib symbol 30# CHECK-NEXT: __DATA_CONST __got 0x[[#ADDR+16]] pointer 0 libhello _hello_its_me 31 32# RUN: %lld -pie -lSystem -o %t/test %t/test.o -L%t -lhello 33# RUN: llvm-objdump --macho --rebase --bind %t/test | FileCheck %s --check-prefix=PIE --match-full-lines 34# PIE: Rebase table: 35# PIE-NEXT: segment section address type 36# PIE-NEXT: __DATA_CONST __got 0x[[#%X,ADDR:]] pointer 37# PIE-NEXT: __DATA_CONST __got 0x[[#ADDR + 8]] pointer 38 39# PIE-NEXT: Bind table: 40# PIE-NEXT: segment section address type addend dylib symbol 41# PIE-NEXT: __DATA_CONST __got 0x[[#ADDR+16]] pointer 0 libhello _hello_its_me 42 43.globl _main 44 45.text 46_main: 47 movl $0x2000004, %eax # write() syscall 48 mov $1, %rdi # stdout 49 movq _hello_its_me@GOTPCREL(%rip), %rsi 50 mov $15, %rdx # length of str 51 syscall 52 53 movl $0x2000004, %eax # write() syscall 54 mov $1, %rdi # stdout 55## We use pushq/popq here instead of movq in order to avoid relaxation. 56 pushq _hello_world@GOTPCREL(%rip) 57 popq %rsi 58 mov $13, %rdx # length of str 59 syscall 60 61 movl $0x2000004, %eax # write() syscall 62 mov $1, %rdi # stdout 63 pushq _goodbye_world@GOTPCREL(%rip) 64 popq %rsi 65 mov $15, %rdx # length of str 66 syscall 67 68 mov $0, %rax 69 ret 70 71.section __TEXT,__cstring 72_hello_world: 73 .asciz "Hello world!\n" 74 75_goodbye_world: 76 .asciz "Goodbye world!\n" 77