Skip to content

Commit e68f640

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 (cherry picked from commit 885fb9a)
1 parent 87ca22c commit e68f640

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,8 +1409,8 @@ static void scanReloc(InputSectionBase &sec, OffsetGetter &getOffset, RelTy *&i,
14091409
// The 4 types that relative GOTPLT are all x86 and x86-64 specific.
14101410
if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_TLSGD_GOTPLT>(expr)) {
14111411
in.gotPlt->hasGotPltOffRel = true;
1412-
} else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC64_TOCBASE, R_PPC64_RELAX_TOC>(
1413-
expr)) {
1412+
} else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC32_PLTREL, R_PPC64_TOCBASE,
1413+
R_PPC64_RELAX_TOC>( expr)) {
14141414
in.got->hasGotOffRel = true;
14151415
}
14161416

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: ]

0 commit comments

Comments
 (0)