Skip to content

Commit cdd8cca

Browse files
committed
[ELF] Support some absolute/PC-relative relocation types for REL format
ctfconvert seems to use REL-format `.rel.SUNW_dof` for 32-bit architectures. ``` Binary file usr/ports/lang/perl5.32/work/perl-5.32.1/dtrace_mini.o matches [alfredo.junior@dell-a ~/tmp/llvm-bug]$ readelf -r dtrace_mini.o Relocation section (.rel.SUNW_dof): r_offset r_info r_type st_value st_name 00000184 0000281a R_PPC_REL32 00000000 $dtrace1772974259.Perl_dtrace_probe_load ``` Support R_PPC_REL32 to fix `ld.lld: error: drti.c:(.SUNW_dof+0x4E4): internal linker error: cannot read addend for relocation R_PPC_REL32`. While here, add some common relocation types for AArch64, PPC, and PPC64. We perform minimum tests. Reviewed By: adalava, arichardson Differential Revision: https://reviews.llvm.org/D120535 (cherry picked from commit 767e64f)
1 parent e89602b commit cdd8cca

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ int64_t AArch64::getImplicitAddend(const uint8_t *buf, RelType type) const {
199199
return read64(buf + 8);
200200
case R_AARCH64_NONE:
201201
return 0;
202+
case R_AARCH64_PREL32:
203+
return SignExtend64<32>(read32(buf));
204+
case R_AARCH64_ABS64:
205+
case R_AARCH64_PREL64:
206+
return read64(buf);
202207
default:
203208
internalLinkerError(getErrorLocation(buf),
204209
"cannot read addend for relocation " + toString(type));

lld/ELF/Arch/PPC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ int64_t PPC::getImplicitAddend(const uint8_t *buf, RelType type) const {
280280
switch (type) {
281281
case R_PPC_NONE:
282282
return 0;
283+
case R_PPC_ADDR32:
284+
case R_PPC_REL32:
285+
return SignExtend64<32>(read32(buf));
283286
default:
284287
internalLinkerError(getErrorLocation(buf),
285288
"cannot read addend for relocation " + toString(type));

lld/ELF/Arch/PPC64.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,11 @@ int64_t PPC64::getImplicitAddend(const uint8_t *buf, RelType type) const {
10641064
switch (type) {
10651065
case R_PPC64_NONE:
10661066
return 0;
1067+
case R_PPC64_REL32:
1068+
return SignExtend64<32>(read32(buf));
1069+
case R_PPC64_ADDR64:
1070+
case R_PPC64_REL64:
1071+
return read64(buf);
10671072
default:
10681073
internalLinkerError(getErrorLocation(buf),
10691074
"cannot read addend for relocation " + toString(type));
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Test some relocation types for REL format.
2+
# RUN: yaml2obj -DMACHINE=AARCH64 -DR0=R_AARCH64_ABS64 -DR1=R_AARCH64_PREL32 -DR2=R_AARCH64_PREL64 %s -o %t.o
3+
# RUN: ld.lld %t.o -o /dev/null
4+
# RUN: yaml2obj -DMACHINE=PPC -DBITS=32 -DR0=R_PPC_ADDR32 -DR1=R_PPC_REL32 %s -o %t.o
5+
# RUN: ld.lld %t.o -o /dev/null
6+
# RUN: yaml2obj -DMACHINE=PPC64 -DR0=R_PPC64_ADDR64 -DR1=R_PPC64_REL32 -DR2=R_PPC64_REL64 %s -o %t.o
7+
# RUN: ld.lld %t.o -o /dev/null
8+
9+
--- !ELF
10+
FileHeader:
11+
Class: ELFCLASS[[BITS=64]]
12+
Data: ELFDATA2LSB
13+
Type: ET_REL
14+
Machine: EM_[[MACHINE]]
15+
Sections:
16+
- Name: .text
17+
Type: SHT_PROGBITS
18+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
19+
Size: 24
20+
- Name: .data
21+
Type: SHT_PROGBITS
22+
Flags: [ SHF_WRITE, SHF_ALLOC ]
23+
- Name: .rel.text
24+
Type: SHT_REL
25+
Info: .text
26+
Relocations:
27+
- Symbol: .data
28+
Type: [[R0]]
29+
- Offset: 8
30+
Symbol: .data
31+
Type: [[R1=0]]
32+
- Offset: 16
33+
Symbol: .data
34+
Type: [[R2=0]]
35+
Symbols:
36+
- Name: .data
37+
Type: STT_SECTION
38+
Section: .data
39+
- Name: _start
40+
Section: .text
41+
Binding: STB_GLOBAL
42+
...

0 commit comments

Comments
 (0)