llvm-project
56 строк · 1.9 Кб
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-pie %t.o
11# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
12
13# CHECK: Contents of section __DATA,foo:
14# CHECK-NEXT: 100001000 08100000 01000000
15# CHECK: Contents of section __DATA,bar:
16# CHECK-NEXT: 100001008 011000f0 11211111 02000000
17
18# PIE: Rebase table:
19# PIE-NEXT: segment section address type
20# PIE-DAG: __DATA foo 0x[[#%X,ADDR:]] pointer
21# PIE-DAG: __DATA bar 0x[[#ADDR + 8]] pointer
22# PIE-DAG: __DATA bar 0x[[#ADDR + 12]] pointer
23# PIE-DAG: __DATA baz 0x[[#ADDR + 20]] pointer
24
25# NO-PIE: Rebase table:
26# NO-PIE-NEXT: segment section address type
27# NO-PIE-EMPTY:
28
29.globl _main, _foo, _bar
30
31.section __DATA,foo
32_foo:
33.quad _bar
34
35.section __DATA,bar
36_bar:
37## We create a .int symbol reference here -- with non-zero data immediately
38## after -- to check that lld reads precisely 32 bits (and not more) of the
39## implicit addend when handling unsigned relocations of r_length = 2.
40## Note that __PAGEZERO occupies the lower 32 bits, so all symbols are above
41## that. To get a final relocated address that fits within 32 bits, we need to
42## subtract an offset here.
43.int _foo - 0x0fffffff
44## The unsigned relocation should support 64-bit addends too (r_length = 3).
45.quad _foo + 0x111111111
46
47.section __DATA,baz
48## Generates a section relocation.
49.quad L_.baz
50L_.baz:
51.space 0
52
53.text
54_main:
55mov $0, %rax
56ret
57