Skip to content

Commit 888742a

Browse files
authored
[BOLT][AArch64] Handle .plt.got section (#71216)
It seems that currently this section is only created by the mold linker if 2 conditions are met: 1. The PLT function was called directly. 2. The indirect access to PLT function was found (e.g. through ADRP relocation). Although mold created symbol for every plt entry I've removed them in yaml file to check that .plt.got was truly disassembled by bolt.
1 parent 56aa727 commit 888742a

File tree

4 files changed

+234
-3
lines changed

4 files changed

+234
-3
lines changed

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,11 @@ class RewriteInstance {
509509
};
510510

511511
/// AArch64 PLT sections.
512-
const PLTSectionInfo AArch64_PLTSections[3] = {
513-
{".plt"}, {".iplt"}, {nullptr}};
512+
const PLTSectionInfo AArch64_PLTSections[4] = {
513+
{".plt"}, {".plt.got"}, {".iplt"}, {nullptr}};
514514

515515
/// RISCV PLT sections.
516-
const PLTSectionInfo RISCV_PLTSections[3] = {{".plt"}, {nullptr}};
516+
const PLTSectionInfo RISCV_PLTSections[2] = {{".plt"}, {nullptr}};
517517

518518
/// Return PLT information for a section with \p SectionName or nullptr
519519
/// if the section is not PLT.

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,14 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
862862
/// add x16, x16, #0xbe0
863863
/// br x17
864864
///
865+
/// The other type of trampolines are located in .plt.got, that are used for
866+
/// non-lazy bindings so doesn't use x16 arg to transfer .got entry address:
867+
///
868+
/// adrp x16, 230000
869+
/// ldr x17, [x16, #3040]
870+
/// br x17
871+
/// nop
872+
///
865873
uint64_t analyzePLTEntry(MCInst &Instruction, InstructionIterator Begin,
866874
InstructionIterator End,
867875
uint64_t BeginPC) const override {

bolt/test/AArch64/Inputs/plt-got.yaml

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_DYN
6+
Machine: EM_AARCH64
7+
Entry: 0x10360
8+
ProgramHeaders:
9+
- Type: PT_PHDR
10+
Flags: [ PF_R ]
11+
VAddr: 0x40
12+
Align: 0x8
13+
Offset: 0x40
14+
- Type: PT_INTERP
15+
Flags: [ PF_R ]
16+
FirstSec: .interp
17+
LastSec: .interp
18+
VAddr: 0x270
19+
Offset: 0x270
20+
- Type: PT_LOAD
21+
Flags: [ PF_R ]
22+
FirstSec: .interp
23+
LastSec: .rela.dyn
24+
Align: 0x10000
25+
Offset: 0x0
26+
- Type: PT_LOAD
27+
Flags: [ PF_X, PF_R ]
28+
FirstSec: .plt.got
29+
LastSec: .text
30+
VAddr: 0x10350
31+
Align: 0x10000
32+
Offset: 0x2e0
33+
- Type: PT_LOAD
34+
Flags: [ PF_W, PF_R ]
35+
FirstSec: .interp
36+
LastSec: .got
37+
VAddr: 0x203B0
38+
Align: 0x10000
39+
Offset: 0x270
40+
- Type: PT_LOAD
41+
Flags: [ PF_W, PF_R ]
42+
FirstSec: .got.plt
43+
LastSec: .got.plt
44+
VAddr: 0x304E0
45+
Align: 0x10000
46+
Offset: 0x420
47+
- Type: PT_DYNAMIC
48+
Flags: [ PF_W, PF_R ]
49+
FirstSec: .dynamic
50+
LastSec: .dynamic
51+
VAddr: 0x203B0
52+
Align: 0x8
53+
Offset: 0x340
54+
- Type: PT_GNU_STACK
55+
Flags: [ PF_W, PF_R ]
56+
Offset: 0x0
57+
Sections:
58+
- Name: .interp
59+
Type: SHT_PROGBITS
60+
Flags: [ SHF_ALLOC ]
61+
Address: 0x270
62+
AddressAlign: 0x1
63+
Offset: 0x270
64+
Content: 2F6C69622F6C642D6C696E75782D616172636836342E736F2E3100
65+
- Name: .dynsym
66+
Type: SHT_DYNSYM
67+
Flags: [ SHF_ALLOC ]
68+
Address: 0x2B0
69+
Link: .dynstr
70+
AddressAlign: 0x8
71+
- Name: .dynstr
72+
Type: SHT_STRTAB
73+
Flags: [ SHF_ALLOC ]
74+
Address: 0x2E0
75+
AddressAlign: 0x1
76+
- Name: .rela.dyn
77+
Type: SHT_RELA
78+
Flags: [ SHF_ALLOC ]
79+
Address: 0x2F0
80+
Link: .dynsym
81+
AddressAlign: 0x8
82+
Relocations:
83+
- Offset: 0x204D8
84+
Symbol: abort
85+
Type: R_AARCH64_GLOB_DAT
86+
- Name: .plt.got
87+
Type: SHT_PROGBITS
88+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
89+
Address: 0x10350
90+
AddressAlign: 0x10
91+
Content: 90000090116E42F920021FD61F2003D5
92+
- Name: .text
93+
Type: SHT_PROGBITS
94+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
95+
Address: 0x10360
96+
AddressAlign: 0x4
97+
Content: FF8300D1FD7B01A9FD43009188000090086D42F9E80700F9E80740F9080100F1E8179F1AA800003701000014E80740F900013FD601000014EEFFFF97007D20D41000009010420D9100021FD61F2003D5
98+
- Name: .dynamic
99+
Type: SHT_DYNAMIC
100+
Flags: [ SHF_WRITE, SHF_ALLOC ]
101+
Address: 0x203B0
102+
Link: .dynstr
103+
AddressAlign: 0x8
104+
Entries:
105+
- Tag: DT_NEEDED
106+
Value: 0x1
107+
- Tag: DT_RELA
108+
Value: 0x2F0
109+
- Tag: DT_RELASZ
110+
Value: 0x18
111+
- Tag: DT_RELAENT
112+
Value: 0x18
113+
- Tag: DT_PLTGOT
114+
Value: 0x304E0
115+
- Tag: DT_SYMTAB
116+
Value: 0x2B0
117+
- Tag: DT_SYMENT
118+
Value: 0x18
119+
- Tag: DT_STRTAB
120+
Value: 0x2E0
121+
- Tag: DT_STRSZ
122+
Value: 0x10
123+
- Tag: DT_GNU_HASH
124+
Value: 0x290
125+
- Tag: DT_FLAGS_1
126+
Value: 0x8000000
127+
- Tag: DT_DEBUG
128+
Value: 0x0
129+
- Tag: DT_NULL
130+
Value: 0x0
131+
- Name: .got
132+
Type: SHT_PROGBITS
133+
Flags: [ SHF_WRITE, SHF_ALLOC ]
134+
Address: 0x204D0
135+
AddressAlign: 0x8
136+
Content: '00000000000000000000000000000000'
137+
- Name: .got.plt
138+
Type: SHT_PROGBITS
139+
Flags: [ SHF_WRITE, SHF_ALLOC ]
140+
Address: 0x304E0
141+
AddressAlign: 0x8
142+
Content: B00302000000000000000000000000000000000000000000
143+
- Name: .rela.text
144+
Type: SHT_RELA
145+
Flags: [ SHF_INFO_LINK ]
146+
Link: .symtab
147+
AddressAlign: 0x8
148+
Offset: 0x1268
149+
Info: .text
150+
Relocations:
151+
- Offset: 0x1036C
152+
Symbol: abort
153+
Type: R_AARCH64_ADR_GOT_PAGE
154+
- Offset: 0x10370
155+
Symbol: abort
156+
Type: R_AARCH64_LD64_GOT_LO12_NC
157+
- Offset: 0x10398
158+
Symbol: abort
159+
Type: R_AARCH64_CALL26
160+
- Type: SectionHeaderTable
161+
Sections:
162+
- Name: .interp
163+
- Name: .dynsym
164+
- Name: .dynstr
165+
- Name: .rela.dyn
166+
- Name: .plt.got
167+
- Name: .text
168+
- Name: .dynamic
169+
- Name: .got
170+
- Name: .got.plt
171+
- Name: .strtab
172+
- Name: .symtab
173+
- Name: .shstrtab
174+
- Name: .rela.text
175+
Symbols:
176+
- Name: .text
177+
Type: STT_SECTION
178+
Section: .text
179+
Value: 0x10360
180+
- Name: .dynamic
181+
Type: STT_SECTION
182+
Section: .dynamic
183+
Value: 0x203B0
184+
- Name: .got
185+
Type: STT_SECTION
186+
Section: .got
187+
Value: 0x204D0
188+
- Name: .got.plt
189+
Type: STT_SECTION
190+
Section: .got.plt
191+
Value: 0x304E0
192+
- Name: 'abort$got'
193+
Type: STT_OBJECT
194+
Section: .got
195+
Value: 0x204D8
196+
- Name: _start
197+
Type: STT_FUNC
198+
Section: .text
199+
Value: 0x10360
200+
Size: 0x3C
201+
- Name: _DYNAMIC
202+
Section: .dynamic
203+
Value: 0x203B0
204+
- Name: _GLOBAL_OFFSET_TABLE_
205+
Section: .got
206+
Value: 0x204D0
207+
- Name: abort
208+
Type: STT_FUNC
209+
Binding: STB_GLOBAL
210+
Size: 0x8
211+
DynamicSymbols:
212+
- Name: abort
213+
Type: STT_FUNC
214+
Binding: STB_GLOBAL
215+
Size: 0x8
216+
...

bolt/test/AArch64/plt-got.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This test checks .plt.got handling by BOLT
2+
3+
RUN: yaml2obj %p/Inputs/plt-got.yaml &> %t.exe
4+
RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm --print-only=_start/1 | \
5+
RUN: FileCheck %s
6+
7+
CHECK: bl abort@PLT

0 commit comments

Comments
 (0)