1 //===- AMDGPU.cpp ---------------------------------------------------------===// 2 // 3 // The LLVM Linker 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "Error.h" 11 #include "InputFiles.h" 12 #include "Symbols.h" 13 #include "Target.h" 14 #include "llvm/Object/ELF.h" 15 #include "llvm/Support/Endian.h" 16 17 using namespace llvm; 18 using namespace llvm::object; 19 using namespace llvm::support::endian; 20 using namespace llvm::ELF; 21 using namespace lld; 22 using namespace lld::elf; 23 24 namespace { 25 class AMDGPU final : public TargetInfo { 26 public: 27 AMDGPU(); 28 void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; 29 RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, 30 const uint8_t *Loc) const override; 31 }; 32 } // namespace 33 34 AMDGPU::AMDGPU() { 35 RelativeRel = R_AMDGPU_REL64; 36 GotRel = R_AMDGPU_ABS64; 37 GotEntrySize = 8; 38 } 39 40 void AMDGPU::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { 41 switch (Type) { 42 case R_AMDGPU_ABS32: 43 case R_AMDGPU_GOTPCREL: 44 case R_AMDGPU_GOTPCREL32_LO: 45 case R_AMDGPU_REL32: 46 case R_AMDGPU_REL32_LO: 47 write32le(Loc, Val); 48 break; 49 case R_AMDGPU_ABS64: 50 write64le(Loc, Val); 51 break; 52 case R_AMDGPU_GOTPCREL32_HI: 53 case R_AMDGPU_REL32_HI: 54 write32le(Loc, Val >> 32); 55 break; 56 default: 57 error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); 58 } 59 } 60 61 RelExpr AMDGPU::getRelExpr(uint32_t Type, const SymbolBody &S, 62 const uint8_t *Loc) const { 63 switch (Type) { 64 case R_AMDGPU_ABS32: 65 case R_AMDGPU_ABS64: 66 return R_ABS; 67 case R_AMDGPU_REL32: 68 case R_AMDGPU_REL32_LO: 69 case R_AMDGPU_REL32_HI: 70 return R_PC; 71 case R_AMDGPU_GOTPCREL: 72 case R_AMDGPU_GOTPCREL32_LO: 73 case R_AMDGPU_GOTPCREL32_HI: 74 return R_GOT_PC; 75 default: 76 error(toString(S.File) + ": unknown relocation type: " + toString(Type)); 77 return R_HINT; 78 } 79 } 80 81 TargetInfo *elf::getAMDGPUTargetInfo() { 82 static AMDGPU Target; 83 return &Target; 84 } 85