Skip to content

Commit

Permalink
ELF/AMDGPU: Add support for GOT relocations
Browse files Browse the repository at this point in the history
Reviewers: arsenm, rafael, tony-tye, kzhuravl, ruiu

Subscribers: llvm-commits, kzhuravl

Differential Revision: http://reviews.llvm.org/D21481

llvm-svn: 274514
  • Loading branch information
tstellarAMD committed Jul 4, 2016
1 parent 8e51e67 commit 391e3a8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
25 changes: 19 additions & 6 deletions lld/ELF/Target.cpp
Expand Up @@ -166,7 +166,7 @@ class AArch64TargetInfo final : public TargetInfo {

class AMDGPUTargetInfo final : public TargetInfo {
public:
AMDGPUTargetInfo() {}
AMDGPUTargetInfo();
void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
};
Expand Down Expand Up @@ -1415,16 +1415,29 @@ void AArch64TargetInfo::relaxTlsIeToLe(uint8_t *Loc, uint32_t Type,
llvm_unreachable("invalid relocation for TLS IE to LE relaxation");
}

AMDGPUTargetInfo::AMDGPUTargetInfo() { GotRel = R_AMDGPU_ABS64; }

void AMDGPUTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
uint64_t Val) const {
assert(Type == R_AMDGPU_REL32);
write32le(Loc, Val);
switch (Type) {
case R_AMDGPU_GOTPCREL:
case R_AMDGPU_REL32:
write32le(Loc, Val);
break;
default:
fatal("unrecognized reloc " + Twine(Type));
}
}

RelExpr AMDGPUTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
if (Type != R_AMDGPU_REL32)
error("do not know how to handle relocation");
return R_PC;
switch (Type) {
case R_AMDGPU_REL32:
return R_PC;
case R_AMDGPU_GOTPCREL:
return R_GOT_PC;
default:
fatal("do not know how to handle relocation " + Twine(Type));
}
}

ARMTargetInfo::ARMTargetInfo() {
Expand Down
21 changes: 18 additions & 3 deletions lld/test/ELF/amdgpu-relocs.s
Expand Up @@ -4,15 +4,30 @@

# REQUIRES: amdgpu

# Make sure that the reloc for local_var is resolved by lld.

.text

kernel0:
s_mov_b32 s0, common_var@GOTPCREL+4
s_mov_b32 s0, extern_var@GOTPCREL+4
s_mov_b32 s0, local_var+4
s_mov_b32 s0, global_var@GOTPCREL+4
s_mov_b32 s0, weak_var@GOTPCREL+4
s_mov_b32 s0, weakref_var@GOTPCREL+4
s_endpgm

.local local_var
.comm common_var,1024,4
.globl global_var
.local local_var
.weak weak_var
.weakref weakref_var, weakref_alias_var

# The relocation for local_var should be resolved by the linker.
# CHECK: Relocations [
# CHECK: .rela.dyn {
# CHECK-NEXT: R_AMDGPU_ABS64 common_var 0x0
# CHECK-NEXT: R_AMDGPU_ABS64 extern_var 0x0
# CHECK-NEXT: R_AMDGPU_ABS64 global_var 0x0
# CHECK-NEXT: R_AMDGPU_ABS64 weak_var 0x0
# CHECK-NEXT: R_AMDGPU_ABS64 weakref_alias_var 0x0
# CHECK-NEXT: }
# CHECK-NEXT: ]

0 comments on commit 391e3a8

Please sign in to comment.