mips-plt.test
8.04 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# RUN: llvm-readobj -A %p/Inputs/got-plt.exe.elf-mipsel | FileCheck %s
# RUN: llvm-readelf -A %p/Inputs/got-plt.exe.elf-mipsel | FileCheck --check-prefix=GNU %s
# CHECK: PLT GOT {
# CHECK-NEXT: Reserved entries [
# CHECK-NEXT: Entry {
# CHECK-NEXT: Address: 0x410814
# CHECK-NEXT: Initial: 0x0
# CHECK-NEXT: Purpose: PLT lazy resolver
# CHECK-NEXT: }
# CHECK-NEXT: Entry {
# CHECK-NEXT: Address: 0x410818
# CHECK-NEXT: Initial: 0x0
# CHECK-NEXT: Purpose: Module pointer
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: Entries [
# CHECK-NEXT: Entry {
# CHECK-NEXT: Address: 0x41081C
# CHECK-NEXT: Initial: 0x4007C0
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Type: Function (0x2)
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: Name: puts@GLIBC_2.0 (71)
# CHECK-NEXT: }
# CHECK-NEXT: Entry {
# CHECK-NEXT: Address: 0x410820
# CHECK-NEXT: Initial: 0x4007C0
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Type: Function (0x2)
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: Name: __libc_start_main@GLIBC_2.0 (53)
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# GNU: Primary GOT:
# GNU-NEXT: Canonical gp value: 00418840
# GNU: Reserved entries:
# GNU-NEXT: Address Access Initial Purpose
# GNU-NEXT: 00410850 -32752(gp) 00000000 Lazy resolver
# GNU-NEXT: 00410854 -32748(gp) 80000000 Module pointer (GNU extension)
# GNU: Local entries:
# GNU-NEXT: Address Access Initial
# GNU-NEXT: 00410858 -32744(gp) 004003d4
# GNU-NEXT: 0041085c -32740(gp) 00410800
# GNU-NEXT: 00410860 -32736(gp) 00000000
# GNU: Global entries:
# GNU-NEXT: Address Access Initial Sym.Val. Type Ndx Name
# GNU-NEXT: 00410864 -32732(gp) 00000000 00000000 FUNC UND __gmon_start__
# GNU-NEXT: PLT GOT:
# GNU: Reserved entries:
# GNU-NEXT: Address Initial Purpose
# GNU-NEXT: 00410814 00000000 PLT lazy resolver
# GNU-NEXT: 00410818 00000000 Module pointer
# GNU: Entries:
# GNU-NEXT: Address Initial Sym.Val. Type Ndx Name
# GNU-NEXT: 0041081c 004007c0 00000000 FUNC UND puts
# GNU-NEXT: 00410820 004007c0 00000000 FUNC UND __libc_start_main
## Check we report errors when dynamic tags, needed for dumping PLT, are missing.
# RUN: yaml2obj --docnum=1 -DTAG=DT_MIPS_PLTGOT %s -o %t.err1.o
# RUN: not llvm-readobj -A %t.err1.o 2>&1 | FileCheck %s -DFILE=%t.err1.o --check-prefix=ERR1
# ERR1: error: '[[FILE]]': cannot find JMPREL dynamic tag
# RUN: yaml2obj --docnum=1 -DTAG=DT_JMPREL %s -o %t.err2.o
# RUN: not llvm-readobj -A %t.err2.o 2>&1 | FileCheck %s -DFILE=%t.err2.o --check-prefix=ERR2
# ERR2: error: '[[FILE]]': cannot find MIPS_PLTGOT dynamic tag
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_MIPS
Sections:
- Name: .dynamic
Type: SHT_DYNAMIC
Entries:
- Tag: [[TAG]]
Value: 0
- Tag: DT_NULL
Value: 0
## Check we report errors when we are unable to find PLTGOT/JMPREL sections.
# RUN: yaml2obj --docnum=2 %s -DVAL1=0xffff -o %t.err3.o
# RUN: not llvm-readobj -A %t.err3.o 2>&1 | FileCheck %s -DFILE=%t.err3.o -check-prefix ERR3
# ERR3: error: '[[FILE]]': there is no non-empty PLTGOT section at 0xffff
# RUN: yaml2obj --docnum=2 %s -DVAL2=0xffff -o %t.err4.o
# RUN: not llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefix ERR4
# ERR4: error: '[[FILE]]': there is no non-empty RELPLT section at 0xffff
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_MIPS
Sections:
- Name: .dynamic
Type: SHT_DYNAMIC
Entries:
- Tag: DT_MIPS_PLTGOT
Value: [[VAL1=0]]
- Tag: DT_JMPREL
Value: [[VAL2=0]]
- Tag: DT_NULL
Value: 0
- Name: .foo
Type: SHT_PROGBITS
Address: 0x100
ShSize: 0xffffffff
Link: [[LINK=0x1]]
DynamicSymbols: []
## Check we report errors when we are unable to dump PLTGOT properly.
# RUN: yaml2obj --docnum=2 -DVAL1=0x100 %s -o %t.err5.o
# RUN: not llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefix ERR5
# ERR5: error: '[[FILE]]': unable to read PLTGOT section content: section [index 2] has a sh_offset (0x70) + sh_size (0xffffffff) that is greater than the file size (0x280)
# RUN: yaml2obj --docnum=2 -DVAL2=0x100 -DLINK=0xaaaaaaaa %s -o %t.err6.o
# RUN: not llvm-readobj -A %t.err6.o 2>&1 | FileCheck %s -DFILE=%t.err6.o -check-prefix ERR6
# ERR6: error: '[[FILE]]': unable to get a symbol table linked to the SHT_PROGBITS section with index 2: invalid section index: 2863311530
# RUN: yaml2obj --docnum=2 -DVAL2=0x100 %s -o %t.err7.o
# RUN: not llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o -check-prefix ERR7
# ERR7: error: '[[FILE]]': unable to get a string table for the SHT_DYNAMIC section with index 1: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
## Check how we print PLT entries when they are unnamed section symbols.
# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-readobj -A %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=SEC-SYMS-LLVM
# RUN: llvm-readelf -A %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=SEC-SYMS-GNU
# SEC-SYMS-LLVM: PLT GOT {
# SEC-SYMS-LLVM: Entries [
# SEC-SYMS-LLVM: Entry {
# SEC-SYMS-LLVM: Section: Absolute (0xFFF1)
# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
# SEC-SYMS-LLVM-NEXT: Name: <?> (0)
# SEC-SYMS-LLVM-NEXT: }
# SEC-SYMS-LLVM-NEXT: Entry {
# SEC-SYMS-LLVM: Section: .got.plt (0x2)
# SEC-SYMS-LLVM-NEXT: Name: .got.plt (0)
# SEC-SYMS-LLVM-NEXT: }
# SEC-SYMS-LLVM-NEXT: Entry {
# SEC-SYMS-LLVM: Section: Common (0xFFF2)
# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
# SEC-SYMS-LLVM-NEXT: Name: <?> (0)
# SEC-SYMS-LLVM-NEXT: }
# SEC-SYMS-LLVM-NEXT: Entry {
# SEC-SYMS-LLVM: Type: Section (0x3)
# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': extended symbol index (4) is past the end of the SHT_SYMTAB_SHNDX section of size 0
# SEC-SYMS-LLVM-NEXT: Section: Reserved (0xFFFF)
# SEC-SYMS-LLVM-NEXT: Name: <?> (0)
# SEC-SYMS-LLVM-NEXT: }
# SEC-SYMS-LLVM-NEXT: ]
# SEC-SYMS-LLVM-NEXT: }
# SEC-SYMS-GNU: PLT GOT:
# SEC-SYMS-GNU: Entries:
# SEC-SYMS-GNU-NEXT: Address {{.*}} Ndx Name
# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
# SEC-SYMS-GNU-NEXT: 0000000000002010 {{.*}} ABS <?>
# SEC-SYMS-GNU-NEXT: 0000000000002018 {{.*}} 2 .got.plt
# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
# SEC-SYMS-GNU-NEXT: 0000000000002020 {{.*}} COM <?>
# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': extended symbol index (4) is past the end of the SHT_SYMTAB_SHNDX section of size 0
# SEC-SYMS-GNU-NEXT: 0000000000002028 {{.*}} RSV[0xffff] <?>
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_MIPS
Sections:
- Name: .rel.plt
Type: SHT_REL
Flags: [ SHF_ALLOC ]
Address: 0x1000
Link: .dynsym
Relocations:
- Offset: 0x1
Symbol: 1
Type: R_MIPS_JUMP_SLOT
- Offset: 0x2
Symbol: 2
Type: R_MIPS_JUMP_SLOT
- Offset: 0x2
Symbol: 3
Type: R_MIPS_JUMP_SLOT
- Offset: 0x3
Symbol: 4
Type: R_MIPS_JUMP_SLOT
- Name: .got.plt
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
Address: 0x2000
Size: 48 ## (dynamic symbols number + 2) * 8
- Name: .dynamic
Type: SHT_DYNAMIC
Entries:
- Tag: DT_JMPREL
Value: 0x1000
- Tag: DT_MIPS_PLTGOT
Value: 0x2000
DynamicSymbols:
- Type: STT_SECTION
Index: SHN_ABS
- Type: STT_SECTION
Section: .got.plt
- Type: STT_SECTION
Index: SHN_COMMON
- Type: STT_SECTION
Index: SHN_XINDEX