relocatable.s
4.38 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/relocatable.s -o %t2.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/relocatable2.s -o %t3.o
# RUN: ld.lld -r %t1.o %t2.o %t3.o -o %t
# RUN: llvm-readobj --file-headers --sections -l --symbols -r %t | FileCheck %s
# RUN: llvm-objdump -section-headers %t | FileCheck -check-prefix=SECTION %s
# RUN: llvm-objdump -s -d %t | FileCheck -check-prefix=CHECKTEXT %s
## Test --relocatable alias
# RUN: ld.lld --relocatable %t1.o %t2.o %t3.o -o %t
# RUN: llvm-readobj --file-headers --sections -l --symbols -r %t | FileCheck %s
# RUN: llvm-objdump -s -d %t | FileCheck -check-prefix=CHECKTEXT %s
## Verify that we can use our relocation output as input to produce executable
# RUN: ld.lld -e main %t -o %texec
# RUN: llvm-readobj --file-headers %texec | FileCheck -check-prefix=CHECKEXE %s
# CHECK: ElfHeader {
# CHECK-NEXT: Ident {
# CHECK-NEXT: Magic: (7F 45 4C 46)
# CHECK-NEXT: Class: 64-bit
# CHECK-NEXT: DataEncoding: LittleEndian
# CHECK-NEXT: FileVersion: 1
# CHECK-NEXT: OS/ABI: SystemV
# CHECK-NEXT: ABIVersion: 0
# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
# CHECK-NEXT: }
# CHECK-NEXT: Type: Relocatable
# CHECK-NEXT: Machine: EM_X86_64
# CHECK-NEXT: Version: 1
# CHECK-NEXT: Entry: 0x0
# CHECK-NEXT: ProgramHeaderOffset: 0x0
# CHECK-NEXT: SectionHeaderOffset:
# CHECK-NEXT: Flags [
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 64
# CHECK-NEXT: ProgramHeaderEntrySize: 0
# CHECK-NEXT: ProgramHeaderCount: 0
# CHECK-NEXT: SectionHeaderEntrySize: 64
# CHECK-NEXT: SectionHeaderCount: 8
# CHECK-NEXT: StringTableSectionIndex: 6
# CHECK-NEXT: }
# CHECK: Relocations [
# CHECK-NEXT: Section ({{.*}}) .rela.text {
# CHECK-NEXT: 0x3 R_X86_64_32S x 0x0
# CHECK-NEXT: 0xE R_X86_64_32S y 0x0
# CHECK-NEXT: 0x23 R_X86_64_32S xx 0x0
# CHECK-NEXT: 0x2E R_X86_64_32S yy 0x0
# CHECK-NEXT: 0x43 R_X86_64_32S xxx 0x0
# CHECK-NEXT: 0x4E R_X86_64_32S yyy 0x0
# CHECK-NEXT: }
# SECTION: Sections:
# SECTION: Idx Name Size VMA Type
# SECTION: 0 00000000 0000000000000000
# SECTION: 1 .text 00000056 0000000000000000 TEXT
# SECTION: 2 .rela.text 00000090 0000000000000000
# SECTION: 3 .bss 00000018 0000000000000000 BSS
# SECTION: 4 .note.GNU-stack 00000000 0000000000000000
# SECTION: 5 .symtab 00000168 0000000000000000
# SECTION: 6 .shstrtab 00000041 0000000000000000
# SECTION: 7 .strtab 0000002d 0000000000000000
# CHECKTEXT: Disassembly of section .text:
# CHECKTEXT-EMPTY:
# CHECKTEXT-NEXT: main:
# CHECKTEXT-NEXT: 0: c7 04 25 00 00 00 00 05 00 00 00 movl $5, 0
# CHECKTEXT-NEXT: b: c7 04 25 00 00 00 00 07 00 00 00 movl $7, 0
# CHECKTEXT: foo:
# CHECKTEXT-NEXT: 20: c7 04 25 00 00 00 00 01 00 00 00 movl $1, 0
# CHECKTEXT-NEXT: 2b: c7 04 25 00 00 00 00 02 00 00 00 movl $2, 0
# CHECKTEXT: bar:
# CHECKTEXT-NEXT: 40: c7 04 25 00 00 00 00 08 00 00 00 movl $8, 0
# CHECKTEXT-NEXT: 4b: c7 04 25 00 00 00 00 09 00 00 00 movl $9, 0
# CHECKEXE: Format: ELF64-x86-64
# CHECKEXE-NEXT: Arch: x86_64
# CHECKEXE-NEXT: AddressSize: 64bit
# CHECKEXE-NEXT: LoadName:
# CHECKEXE-NEXT: ElfHeader {
# CHECKEXE-NEXT: Ident {
# CHECKEXE-NEXT: Magic: (7F 45 4C 46)
# CHECKEXE-NEXT: Class: 64-bit
# CHECKEXE-NEXT: DataEncoding: LittleEndian
# CHECKEXE-NEXT: FileVersion: 1
# CHECKEXE-NEXT: OS/ABI: SystemV (0x0)
# CHECKEXE-NEXT: ABIVersion: 0
# CHECKEXE-NEXT: Unused: (00 00 00 00 00 00 00)
# CHECKEXE-NEXT: }
# CHECKEXE-NEXT: Type: Executable
# CHECKEXE-NEXT: Machine: EM_X86_64
# CHECKEXE-NEXT: Version: 1
# CHECKEXE-NEXT: Entry: 0x201160
# CHECKEXE-NEXT: ProgramHeaderOffset: 0x40
# CHECKEXE-NEXT: SectionHeaderOffset: 0x358
# CHECKEXE-NEXT: Flags [
# CHECKEXE-NEXT: ]
# CHECKEXE-NEXT: HeaderSize: 64
# CHECKEXE-NEXT: ProgramHeaderEntrySize: 56
# CHECKEXE-NEXT: ProgramHeaderCount: 5
# CHECKEXE-NEXT: SectionHeaderEntrySize: 64
# CHECKEXE-NEXT: SectionHeaderCount: 7
# CHECKEXE-NEXT: StringTableSectionIndex: 5
# CHECKEXE-NEXT: }
.text
.type x,@object
.bss
.globl x
.align 4
x:
.long 0
.size x, 4
.type y,@object
.globl y
.align 4
y:
.long 0
.size y, 4
.text
.globl main
.align 16, 0x90
.type main,@function
main:
movl $5, x
movl $7, y
blah:
goo:
abs = 42