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