[PATCH] D114982: [ELF][PowerPC] Don't discard .got if 32-bit plt needs it
George Koehler via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 2 12:08:54 PST 2021
kernigh created this revision.
kernigh added reviewers: MaskRay, brad.
Herald added subscribers: steven.zhang, shchenz, kbarton, krytarowski, arichardson, nemanjai, emaste.
kernigh requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Add R_PPC32_PLTREL to the list of GOT-offset relocations. The plt in 32-bit PowerPC code needs the first 12 bytes of the .got section, so LLD must create the GOT.
lld had discarded .got in code from clang -fPIC; the missing .got caused OpenBSD's ld.so to give a misleading error, "unsupported insecure BSS PLT object". Code from clang -fPIC has no entries in .got (because it uses .got2); lld would add a 12-byte header to .got, but since commit 818b508 <https://reviews.llvm.org/rG818b508953c7684a6c104b89c6f6ce84e961d82e>, lld doesn't count the header as entries. So, lld counted 0 entries in .got, discarded .got, and set DT_GOT_PPC to zero. This broke ld.so, because DT_GOT_PPC must point to the 12-byte header.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114982
Files:
lld/ELF/Relocations.cpp
lld/test/ELF/ppc32-plt-got.s
Index: lld/test/ELF/ppc32-plt-got.s
===================================================================
--- /dev/null
+++ lld/test/ELF/ppc32-plt-got.s
@@ -0,0 +1,39 @@
+# REQUIRES: ppc
+
+## Ensure that, if we call a function through the plt, then the linker
+## isn't discarding the .got section.
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o
+# RUN: ld.lld -shared %t.o -o %t.so
+# RUN: llvm-readobj -Sdr %t.so | FileCheck %s
+
+## This -fPIC code sets r30 and calls the plt, but has no .got entries
+## and never references _GLOBAL_OFFSET_TABLE_. The linker must not
+## discard .got, only because the plt needs the first 12 bytes of .got.
+
+.section .got2,"aw", at progbits
+.set .LTOC, .+0x8000
+
+.text
+.L0:
+addis 30,30,.LTOC-.L0 at ha
+addi 30,30,.LTOC-.L0 at l
+bl baz+0x8000 at plt
+
+## DT_PPC_GOT must point to .got, which must have the 12-byte header.
+## The only relocation must be R_PPC_JMP_SLOT.
+
+# CHECK: Sections [
+# CHECK: Name: .got ({{[0-9]+}})
+# CHECK: Address:
+# CHECK-SAME: {{ }}[[GOT_ADDRESS:0x[0-9A-F]+]]{{$}}
+# CHECK: Size:
+# CHECK-SAME: {{ 12$}}
+# CHECK: DynamicSection [
+# CHECK-NEXT: Tag Type Name/Value
+# CHECK: 0x70000000 PPC_GOT [[GOT_ADDRESS]]
+# CHECK: Relocations [
+# CHECK-NEXT: Section ({{[0-9]+}}) .rela.plt {
+# CHECK-NEXT: 0x{{[0-9A-F]+}} R_PPC_JMP_SLOT baz 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -1365,8 +1365,8 @@
if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_PLT_GOTPLT,
R_TLSDESC_GOTPLT, R_TLSGD_GOTPLT>(expr)) {
in.gotPlt->hasGotPltOffRel = true;
- } else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC64_TOCBASE, R_PPC64_RELAX_TOC>(
- expr)) {
+ } else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC32_PLTREL, R_PPC64_TOCBASE,
+ R_PPC64_RELAX_TOC>(expr)) {
in.got->hasGotOffRel = true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114982.391392.patch
Type: text/x-patch
Size: 2036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211202/2596fbc1/attachment.bin>
More information about the llvm-commits
mailing list