Skip to content

Commit 885fb9a

Browse files
kernighMaskRay
authored andcommitted
[ELF][PPC32] Make R_PPC32_PLTREL retain .got
PLT usage needs the first 12 bytes of the .got section. We need to keep .got and DT_GOT_PPC even if .got/_GLOBAL_OFFSET_TABLE_ are not referenced (large PIC code may only reference .got2), which is the case in OpenBSD's ld.so, leading to a misleading error, "unsupported insecure BSS PLT object". Fix this by adding R_PPC32_PLTREL to the list of hasGotOffRel. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D114982
1 parent 0eebe2e commit 885fb9a

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,8 +1371,8 @@ static void scanReloc(InputSectionBase &sec, OffsetGetter &getOffset, RelTy *&i,
13711371
if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_PLT_GOTPLT,
13721372
R_TLSDESC_GOTPLT, R_TLSGD_GOTPLT>(expr)) {
13731373
in.gotPlt->hasGotPltOffRel = true;
1374-
} else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC64_TOCBASE, R_PPC64_RELAX_TOC>(
1375-
expr)) {
1374+
} else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC32_PLTREL, R_PPC64_TOCBASE,
1375+
R_PPC64_RELAX_TOC>(expr)) {
13761376
in.got->hasGotOffRel = true;
13771377
}
13781378

lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
88

99
# RELOC: .rela.dyn {
10-
# RELOC-NEXT: 0x30248 R_PPC_RELATIVE - 0x101A8
11-
# RELOC-NEXT: 0x3024C R_PPC_IRELATIVE - 0x10188
10+
# RELOC-NEXT: 0x30254 R_PPC_RELATIVE - 0x101A8
11+
# RELOC-NEXT: 0x30258 R_PPC_IRELATIVE - 0x10188
1212
# RELOC-NEXT: }
1313

1414
# SYM: 000101a8 0 FUNC GLOBAL DEFAULT {{.*}} func
15-
# HEX: 0x00030248 00000000
15+
# HEX: 0x00030254 00000000
1616

1717
.section .got2,"aw"
1818
.long func

lld/test/ELF/ppc32-reloc-pltrel.s

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# REQUIRES: ppc
2+
3+
## Ensure R_PPC_PLTREL retains .got even in the absence of
4+
## .got/_GLOBAL_OFFSET_TABLE_ references.
5+
6+
# RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o
7+
# RUN: ld.lld -shared %t.o -o %t.so
8+
# RUN: llvm-readobj -Sdr %t.so | FileCheck %s
9+
10+
.section .got2,"aw",@progbits
11+
.set .LTOC, .+0x8000
12+
13+
.text
14+
.L0:
15+
addis 30,30,.LTOC-.L0@ha
16+
addi 30,30,.LTOC-.L0@l
17+
bl baz+0x8000@plt
18+
19+
## DT_PPC_GOT must point to .got, which must have the 12-byte header.
20+
## The only relocation is an R_PPC_JMP_SLOT.
21+
22+
# CHECK: Sections [
23+
# CHECK: Name: .got (
24+
# CHECK: Address:
25+
# CHECK-SAME: {{ }}[[#%x,GOT:]]
26+
# CHECK: Size:
27+
# CHECK-SAME: {{ 12$}}
28+
# CHECK: DynamicSection [
29+
# CHECK-NEXT: Tag Type Name/Value
30+
# CHECK: 0x70000000 PPC_GOT [[#GOT]]
31+
# CHECK: Relocations [
32+
# CHECK-NEXT: Section ([[#]]) .rela.plt {
33+
# CHECK-NEXT: 0x[[#%x,]] R_PPC_JMP_SLOT baz 0x0
34+
# CHECK-NEXT: }
35+
# CHECK-NEXT: ]

lld/test/ELF/ppc32-reloc-rel.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
beq 1f
1212
1:
1313
# CHECK-LABEL: section .R_PPC_REL14:
14-
# CHECK: 100100b4: bt 2, 0x100100b8
14+
# CHECK: 100100f4: bt 2, 0x100100f8
1515

1616
.section .R_PPC_REL24,"ax",@progbits
1717
b 1f
1818
1:
1919
# CHECK-LABEL: section .R_PPC_REL24:
20-
# CHECK: b 0x100100bc
20+
# CHECK: b 0x100100fc
2121

2222
.section .R_PPC_REL32,"ax",@progbits
2323
.long 1f - .
@@ -29,10 +29,10 @@
2929
b 1f@PLT+32768
3030
1:
3131
# CHECK-LABEL: section .R_PPC_PLTREL24:
32-
# CHECK: b 0x100100c4
32+
# CHECK: b 0x10010104
3333

3434
.section .R_PPC_LOCAL24PC,"ax",@progbits
3535
b 1f@local
3636
1:
3737
# CHECK-LABEL: section .R_PPC_LOCAL24PC:
38-
# CHECK: b 0x100100c8
38+
# CHECK: b 0x10010108

0 commit comments

Comments
 (0)