[ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for PPC32

This commit is contained in:
Fangrui Song
2023-09-15 22:49:18 -07:00
parent 591266c56c
commit 0cbe49eade
4 changed files with 15 additions and 2 deletions

View File

@@ -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),

View File

@@ -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

View File

@@ -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;

View File

@@ -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