[ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for AMDGPU

This commit is contained in:
Fangrui Song 2023-09-15 22:59:08 -07:00
parent 0cbe49eade
commit df979228ef
3 changed files with 19 additions and 2 deletions

View File

@ -34,6 +34,7 @@ public:
RelExpr getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const override;
RelType getDynRel(RelType type) const override;
int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;
};
} // namespace
@ -183,6 +184,20 @@ RelType AMDGPU::getDynRel(RelType type) const {
return R_AMDGPU_NONE;
}
int64_t AMDGPU::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
case R_AMDGPU_NONE:
return 0;
case R_AMDGPU_ABS64:
case R_AMDGPU_RELATIVE64:
return read64(buf);
default:
internalLinkerError(getErrorLocation(buf),
"cannot read addend for relocation " + toString(type));
return 0;
}
}
TargetInfo *elf::getAMDGPUTargetInfo() {
static AMDGPU target;
return ⌖

View File

@ -1713,8 +1713,7 @@ static void setConfigs(opt::InputArgList &args) {
// enable the debug checks for all targets, but currently not all targets
// 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}, m);
bool checkDynamicRelocsDefault = m != EM_HEXAGON;
#else
bool checkDynamicRelocsDefault = false;
#endif

View File

@ -5,6 +5,9 @@
# RUN: llvm-nm %t.so | FileCheck %s --check-prefix=NM
# RUN: llvm-readelf -x .rodata -x nonalloc %t.so | FileCheck %s --check-prefix=HEX
## ABS64 and RELATIVE64 relocs do not cause --check-dynamic-relocations errors.
# RUN: ld.lld --hash-style=sysv -shared %t.o -o /dev/null --apply-dynamic-relocs
.text
kernel0: