[lld] 0cbe49e - [ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for PPC32
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 15 22:49:23 PDT 2023
Author: Fangrui Song
Date: 2023-09-15T22:49:18-07:00
New Revision: 0cbe49eadea89ef15ea228aedc1fa644a18ae747
URL: https://github.com/llvm/llvm-project/commit/0cbe49eadea89ef15ea228aedc1fa644a18ae747
DIFF: https://github.com/llvm/llvm-project/commit/0cbe49eadea89ef15ea228aedc1fa644a18ae747.diff
LOG: [ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for PPC32
Added:
Modified:
lld/ELF/Arch/PPC.cpp
lld/ELF/Driver.cpp
lld/ELF/OutputSections.cpp
lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
Removed:
################################################################################
diff --git a/lld/ELF/Arch/PPC.cpp b/lld/ELF/Arch/PPC.cpp
index 3d21edb3453a104..1b0838456428f10 100644
--- a/lld/ELF/Arch/PPC.cpp
+++ b/lld/ELF/Arch/PPC.cpp
@@ -278,9 +278,16 @@ RelType PPC::getDynRel(RelType type) const {
int64_t PPC::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
case R_PPC_NONE:
+ case R_PPC_GLOB_DAT:
+ case R_PPC_JMP_SLOT:
return 0;
case R_PPC_ADDR32:
case R_PPC_REL32:
+ case R_PPC_RELATIVE:
+ case R_PPC_IRELATIVE:
+ case R_PPC_DTPMOD32:
+ case R_PPC_DTPREL32:
+ case R_PPC_TPREL32:
return SignExtend64<32>(read32(buf));
default:
internalLinkerError(getErrorLocation(buf),
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 4bdf8c94c94b808..f64b806aec986c9 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1714,7 +1714,7 @@ static void setConfigs(opt::InputArgList &args) {
// have support for reading Elf_Rel addends, so we only enable for a subset.
#ifndef NDEBUG
bool checkDynamicRelocsDefault =
- !llvm::is_contained({EM_AMDGPU, EM_HEXAGON, EM_PPC}, m);
+ !llvm::is_contained({EM_AMDGPU, EM_HEXAGON}, m);
#else
bool checkDynamicRelocsDefault = false;
#endif
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 5e2208d89da2700..2dc425927109403 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -746,7 +746,7 @@ void OutputSection::checkDynRelAddends(const uint8_t *bufStart) {
assert(relOsec != nullptr && "missing output section for relocation");
// Some targets have NOBITS synthetic sections with dynamic relocations
// with non-zero addends. Skip such sections.
- if (config->emachine == EM_PPC64 &&
+ if (is_contained({EM_PPC, EM_PPC64}, config->emachine) &&
(rel.inputSec == in.ppc64LongBranchTarget.get() ||
rel.inputSec == in.igotPlt.get()))
continue;
diff --git a/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s b/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
index cbf9535d68a8410..a93f3cecb0c6c10 100644
--- a/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
+++ b/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
@@ -6,6 +6,9 @@
# RUN: llvm-readelf -x .got2 %t | FileCheck --check-prefix=HEX %s
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
+# RUN: ld.lld -pie %t.o -o %t --apply-dynamic-relocs
+# RUN: llvm-readelf -x .got2 %t | FileCheck --check-prefix=HEX2 %s
+
# RELOC: .rela.dyn {
# RELOC-NEXT: 0x3024C R_PPC_RELATIVE - 0x101A0
# RELOC-NEXT: 0x30250 R_PPC_IRELATIVE - 0x10188
@@ -15,6 +18,9 @@
# HEX: Hex dump of section '.got2':
# HEX-NEXT: 0x0003024c 00000000 ....
+# HEX2: Hex dump of section '.got2':
+# HEX2-NEXT: 0x0003024c 000101a0 ....
+
.section .got2,"aw"
.long func
More information about the llvm-commits
mailing list