Skip to content

Commit df97922

Browse files
committed
[ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for AMDGPU
1 parent 0cbe49e commit df97922

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class AMDGPU final : public TargetInfo {
3434
RelExpr getRelExpr(RelType type, const Symbol &s,
3535
const uint8_t *loc) const override;
3636
RelType getDynRel(RelType type) const override;
37+
int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;
3738
};
3839
} // namespace
3940

@@ -183,6 +184,20 @@ RelType AMDGPU::getDynRel(RelType type) const {
183184
return R_AMDGPU_NONE;
184185
}
185186

187+
int64_t AMDGPU::getImplicitAddend(const uint8_t *buf, RelType type) const {
188+
switch (type) {
189+
case R_AMDGPU_NONE:
190+
return 0;
191+
case R_AMDGPU_ABS64:
192+
case R_AMDGPU_RELATIVE64:
193+
return read64(buf);
194+
default:
195+
internalLinkerError(getErrorLocation(buf),
196+
"cannot read addend for relocation " + toString(type));
197+
return 0;
198+
}
199+
}
200+
186201
TargetInfo *elf::getAMDGPUTargetInfo() {
187202
static AMDGPU target;
188203
return ⌖

lld/ELF/Driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,8 +1713,7 @@ static void setConfigs(opt::InputArgList &args) {
17131713
// enable the debug checks for all targets, but currently not all targets
17141714
// have support for reading Elf_Rel addends, so we only enable for a subset.
17151715
#ifndef NDEBUG
1716-
bool checkDynamicRelocsDefault =
1717-
!llvm::is_contained({EM_AMDGPU, EM_HEXAGON}, m);
1716+
bool checkDynamicRelocsDefault = m != EM_HEXAGON;
17181717
#else
17191718
bool checkDynamicRelocsDefault = false;
17201719
#endif

lld/test/ELF/amdgpu-relocs.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# RUN: llvm-nm %t.so | FileCheck %s --check-prefix=NM
66
# RUN: llvm-readelf -x .rodata -x nonalloc %t.so | FileCheck %s --check-prefix=HEX
77

8+
## ABS64 and RELATIVE64 relocs do not cause --check-dynamic-relocations errors.
9+
# RUN: ld.lld --hash-style=sysv -shared %t.o -o /dev/null --apply-dynamic-relocs
10+
811
.text
912

1013
kernel0:

0 commit comments

Comments
 (0)