1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
3# RUN: %lld -o %t %t.o
4# RUN: llvm-objdump --macho --rebase --full-contents %t | FileCheck %s
5
6# RUN: %lld -pie -o %t-pie %t.o
7# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
8# RUN: %lld -pie -no_pie -o %t-no-pie %t.o
9# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE
10# RUN: %lld -no_pie -pie -o %t-no-pie %t.o
11# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE
12
13# RUN: %lld -platform_version macos 10.6.0 11.0 -o %t-pie %t.o
14# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
15# RUN: %lld -platform_version macos 10.5.0 11.0 -o %t-no-pie %t.o
16# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE
17
18# CHECK:       Contents of section __DATA,foo:
19# CHECK-NEXT:  100001000 08100000 01000000
20# CHECK:       Contents of section __DATA,bar:
21# CHECK-NEXT:  100001008 011000f0 11211111 02000000
22# CHECK:       Rebase table:
23# CHECK-NEXT:  segment  section            address     type
24# CHECK-EMPTY:
25
26# PIE:      Rebase table:
27# PIE-NEXT: segment  section            address           type
28# PIE-DAG:  __DATA   foo                0x[[#%X,ADDR:]]   pointer
29# PIE-DAG:  __DATA   bar                0x[[#ADDR + 8]]   pointer
30# PIE-DAG:  __DATA   bar                0x[[#ADDR + 12]]  pointer
31# PIE-DAG:  __DATA   baz                0x[[#ADDR + 20]]  pointer
32
33# NO-PIE:      Rebase table:
34# NO-PIE-NEXT: segment  section            address           type
35# NO-PIE-EMPTY:
36
37.globl _main, _foo, _bar
38
39.section __DATA,foo
40_foo:
41.quad _bar
42
43.section __DATA,bar
44_bar:
45## We create a .int symbol reference here -- with non-zero data immediately
46## after -- to check that lld reads precisely 32 bits (and not more) of the
47## implicit addend when handling unsigned relocations of r_length = 2.
48## Note that __PAGEZERO occupies the lower 32 bits, so all symbols are above
49## that. To get a final relocated address that fits within 32 bits, we need to
50## subtract an offset here.
51.int _foo - 0x0fffffff
52## The unsigned relocation should support 64-bit addends too (r_length = 3).
53.quad _foo + 0x111111111
54
55.section __DATA,baz
56## Generates a section relocation.
57.quad L_.baz
58L_.baz:
59  .space 0
60
61.text
62_main:
63  mov $0, %rax
64  ret
65