relocations.s
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: %lld -lSystem -o %t %t.o
# RUN: llvm-objdump --section-headers --syms -d %t | FileCheck %s
# CHECK-LABEL: Sections:
# CHECK: __cstring {{[0-9a-z]+}} [[#%x, CSTRING_ADDR:]]
# CHECK-LABEL: SYMBOL TABLE:
# CHECK: [[#%x, F_ADDR:]] {{.*}} _f
# CHECK-LABEL: <_main>:
## Test X86_64_RELOC_BRANCH
# CHECK: callq 0x[[#%x, F_ADDR]] <_f>
## Test extern (symbol) X86_64_RELOC_SIGNED
# CHECK: leaq [[#%u, STR_OFF:]](%rip), %rsi
# CHECK-NEXT: [[#%x, CSTRING_ADDR - STR_OFF]]
## Test non-extern (section) X86_64_RELOC_SIGNED
# CHECK: leaq [[#%u, LSTR_OFF:]](%rip), %rsi
# CHECK-NEXT: [[#%x, CSTRING_ADDR + 22 - LSTR_OFF]]
# RUN: llvm-objdump --section=__const --full-contents %t | FileCheck %s --check-prefix=NONPCREL
# NONPCREL: Contents of section __DATA,__const:
# NONPCREL-NEXT: 100001000 f0030000 01000000 f0030000 01000000
.section __TEXT,__text
.globl _main, _f
_main:
callq _f # X86_64_RELOC_BRANCH
mov $0, %rax
ret
_f:
movl $0x2000004, %eax # write() syscall
mov $1, %rdi # stdout
leaq _str(%rip), %rsi # Generates a X86_64_RELOC_SIGNED pcrel symbol relocation
mov $21, %rdx # length of str
syscall
movl $0x2000004, %eax # write() syscall
mov $1, %rdi # stdout
leaq L_.str(%rip), %rsi # Generates a X86_64_RELOC_SIGNED pcrel section relocation
mov $15, %rdx # length of str
syscall
movl $0x2000004, %eax # write() syscall
mov $1, %rdi # stdout
movq L_.ptr_1_to_str(%rip), %rsi
mov $15, %rdx # length of str
syscall
ret
.section __TEXT,__cstring
## References to this generate a symbol relocation
_str:
.asciz "Local defined symbol\n"
## References to this generate a section relocation
L_.str:
.asciz "Private symbol\n"
.section __DATA,__const
## These generate X86_64_RELOC_UNSIGNED non-pcrel section relocations
L_.ptr_1_to_str:
.quad L_.str
L_.ptr_2_to_str:
.quad L_.str