Skip to content

Commit b922004

Browse files
committed
[RelocationResolver] Support R_PPC_REL32 & R_PPC64_REL{32,64}
This suppresses `failed to compute relocation: R_PPC_REL32, Invalid data was encountered while parsing the file` and its 64-bit variants when running llvm-dwarfdump on a PowerPC object file with .eh_frame Unfortunately it is difficult to test the computation: DWARFDataExtractor::getEncodedPointer does not use the relocated value and even if it does, we need to teach llvm-dwarfdump --eh-frame to do some linker job to report a reasonable address.
1 parent 65936fe commit b922004

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

llvm/lib/Object/RelocationResolver.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ static bool supportsPPC64(uint64_t Type) {
152152
switch (Type) {
153153
case ELF::R_PPC64_ADDR32:
154154
case ELF::R_PPC64_ADDR64:
155+
case ELF::R_PPC64_REL32:
156+
case ELF::R_PPC64_REL64:
155157
return true;
156158
default:
157159
return false;
@@ -164,6 +166,10 @@ static uint64_t resolvePPC64(RelocationRef R, uint64_t S, uint64_t A) {
164166
return (S + getELFAddend(R)) & 0xFFFFFFFF;
165167
case ELF::R_PPC64_ADDR64:
166168
return S + getELFAddend(R);
169+
case ELF::R_PPC64_REL32:
170+
return (S + getELFAddend(R) - R.getOffset()) & 0xFFFFFFFF;
171+
case ELF::R_PPC64_REL64:
172+
return S + getELFAddend(R) - R.getOffset();
167173
default:
168174
llvm_unreachable("Invalid relocation type");
169175
}
@@ -259,12 +265,22 @@ static uint64_t resolveX86(RelocationRef R, uint64_t S, uint64_t A) {
259265
}
260266

261267
static bool supportsPPC32(uint64_t Type) {
262-
return Type == ELF::R_PPC_ADDR32;
268+
switch (Type) {
269+
case ELF::R_PPC_ADDR32:
270+
case ELF::R_PPC_REL32:
271+
return true;
272+
default:
273+
return false;
274+
}
263275
}
264276

265277
static uint64_t resolvePPC32(RelocationRef R, uint64_t S, uint64_t A) {
266-
if (R.getType() == ELF::R_PPC_ADDR32)
278+
switch (R.getType()) {
279+
case ELF::R_PPC_ADDR32:
267280
return (S + getELFAddend(R)) & 0xFFFFFFFF;
281+
case ELF::R_PPC_REL32:
282+
return (S + getELFAddend(R) - R.getOffset()) & 0xFFFFFFFF;
283+
}
268284
llvm_unreachable("Invalid relocation type");
269285
}
270286

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; RUN: llc -filetype=obj -mtriple=powerpc %s -o %t32.o
2+
; RUN: llvm-readobj -r %t32.o | FileCheck %s --check-prefix=PPC_REL
3+
; RUN: llvm-dwarfdump --eh-frame %t32.o 2>&1 | FileCheck %s --check-prefix=PPC
4+
5+
; PPC_REL: R_PPC_REL32 .text 0x0
6+
; PPC_REL-NEXT: R_PPC_REL32 .text 0x4
7+
8+
; PPC-NOT: warning:
9+
; PPC: FDE cie=00000000 pc=00000000...00000004
10+
;; TODO Take relocation into consideration
11+
; PPC: FDE cie=00000000 pc=00000000...00000004
12+
13+
; RUN: llc -filetype=obj -mtriple=ppc64 %s -o %t64.o
14+
; RUN: llvm-readobj -r %t64.o | FileCheck %s --check-prefix=PPC64_REL
15+
; RUN: llvm-dwarfdump --eh-frame %t64.o 2>&1 | FileCheck %s --check-prefix=PPC64
16+
17+
; PPC64_REL: R_PPC64_REL32 .text 0x0
18+
; PPC64_REL-NEXT: R_PPC64_REL32 .text 0x10
19+
20+
; PPC64-NOT: warning:
21+
; PPC64: FDE cie=00000000 pc=00000000...00000010
22+
; PPC64: FDE cie=00000000 pc=00000000...00000010
23+
24+
; RUN: llc -filetype=obj -mtriple=ppc64le -code-model=large %s -o %t64l.o
25+
; RUN: llvm-readobj -r %t64l.o | FileCheck %s --check-prefix=PPC64L_REL
26+
; RUN: llvm-dwarfdump --eh-frame %t64l.o 2>&1 | FileCheck %s --check-prefix=PPC64
27+
28+
; PPC64L_REL: R_PPC64_REL64 .text 0x0
29+
; PPC64L_REL-NEXT: R_PPC64_REL64 .text 0x10
30+
31+
define void @foo() {
32+
entry:
33+
ret void
34+
}
35+
36+
define void @bar() {
37+
entry:
38+
ret void
39+
}

0 commit comments

Comments
 (0)