Index: ELF/Arch/AArch64.cpp =================================================================== --- ELF/Arch/AArch64.cpp +++ ELF/Arch/AArch64.cpp @@ -34,7 +34,7 @@ AArch64(); RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; - bool isPicRel(RelType Type) const override; + Optional getDynRel(RelType Type) const override; void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, @@ -144,8 +144,10 @@ } } -bool AArch64::isPicRel(RelType Type) const { - return Type == R_AARCH64_ABS32 || Type == R_AARCH64_ABS64; +Optional AArch64::getDynRel(RelType Type) const { + if (Type == R_AARCH64_ABS32 || Type == R_AARCH64_ABS64) + return Type; + return None; } void AArch64::writeGotPlt(uint8_t *Buf, const Symbol &) const { Index: ELF/Arch/ARM.cpp =================================================================== --- ELF/Arch/ARM.cpp +++ ELF/Arch/ARM.cpp @@ -29,8 +29,7 @@ uint32_t calcEFlags() const override; RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; - bool isPicRel(RelType Type) const override; - RelType getDynRel(RelType Type) const override; + Optional getDynRel(RelType Type) const override; int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override; void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writeIgotPlt(uint8_t *Buf, const Symbol &S) const override; @@ -162,18 +161,10 @@ } } -bool ARM::isPicRel(RelType Type) const { - return (Type == R_ARM_TARGET1 && !Config->Target1Rel) || - (Type == R_ARM_ABS32); -} - -RelType ARM::getDynRel(RelType Type) const { - if (Type == R_ARM_TARGET1 && !Config->Target1Rel) +Optional ARM::getDynRel(RelType Type) const { + if ((Type == R_ARM_ABS32) || (Type == R_ARM_TARGET1 && !Config->Target1Rel)) return R_ARM_ABS32; - if (Type == R_ARM_ABS32) - return Type; - // Keep it going with a dummy value so that we can find more reloc errors. - return R_ARM_ABS32; + return None; } void ARM::writeGotPlt(uint8_t *Buf, const Symbol &) const { Index: ELF/Arch/Mips.cpp =================================================================== --- ELF/Arch/Mips.cpp +++ ELF/Arch/Mips.cpp @@ -32,8 +32,7 @@ RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override; - bool isPicRel(RelType Type) const override; - RelType getDynRel(RelType Type) const override; + Optional getDynRel(RelType Type) const override; void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, @@ -184,12 +183,11 @@ } } -template bool MIPS::isPicRel(RelType Type) const { - return Type == R_MIPS_32 || Type == R_MIPS_64; -} - -template RelType MIPS::getDynRel(RelType Type) const { - return RelativeRel; +template +Optional MIPS::getDynRel(RelType Type) const { + if (Type == R_MIPS_32 || Type == R_MIPS_64) + return RelativeRel; + return None; } template Index: ELF/Arch/X86.cpp =================================================================== --- ELF/Arch/X86.cpp +++ ELF/Arch/X86.cpp @@ -28,7 +28,7 @@ const uint8_t *Loc) const override; int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override; void writeGotPltHeader(uint8_t *Buf) const override; - RelType getDynRel(RelType Type) const override; + Optional getDynRel(RelType Type) const override; void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writeIgotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; @@ -166,7 +166,7 @@ write32le(Buf, S.getVA()); } -RelType X86::getDynRel(RelType Type) const { +Optional X86::getDynRel(RelType Type) const { if (Type == R_386_TLS_LE) return R_386_TLS_TPOFF; if (Type == R_386_TLS_LE_32) Index: ELF/Arch/X86_64.cpp =================================================================== --- ELF/Arch/X86_64.cpp +++ ELF/Arch/X86_64.cpp @@ -28,7 +28,7 @@ X86_64(); RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; - bool isPicRel(RelType Type) const override; + Optional getDynRel(RelType Type) const override; void writeGotPltHeader(uint8_t *Buf) const override; void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; @@ -155,10 +155,13 @@ write32le(Buf + 12, -getPltEntryOffset(Index) - 16); } -template bool X86_64::isPicRel(RelType Type) const { - return Type != R_X86_64_8 && Type != R_X86_64_PC8 && Type != R_X86_64_16 && - Type != R_X86_64_PC16 && Type != R_X86_64_32 && - Type != R_X86_64_PC32 && Type != R_X86_64_TPOFF32; +template +Optional X86_64::getDynRel(RelType Type) const { + if (Type != R_X86_64_8 && Type != R_X86_64_PC8 && Type != R_X86_64_16 && + Type != R_X86_64_PC16 && Type != R_X86_64_32 && Type != R_X86_64_PC32 && + Type != R_X86_64_TPOFF32) + return Type; + return None; } template Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -778,9 +778,8 @@ InX::RelaDyn->addReloc(Target->RelativeRel, &Sec, Offset, &Sym, Addend, Expr, Type); return Expr; - } else if (Target->isPicRel(Type)) { - InX::RelaDyn->addReloc(Target->getDynRel(Type), &Sec, Offset, &Sym, - Addend, R_ADDEND, Type); + } else if (Optional Rel = Target->getDynRel(Type)) { + InX::RelaDyn->addReloc(*Rel, &Sec, Offset, &Sym, Addend, R_ADDEND, Type); // MIPS ABI turns using of GOT and dynamic relocations inside out. // While regular ABI uses dynamic relocations to fill up GOT entries Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -25,8 +25,7 @@ class TargetInfo { public: virtual uint32_t calcEFlags() const { return 0; } - virtual bool isPicRel(RelType Type) const { return true; } - virtual RelType getDynRel(RelType Type) const { return Type; } + virtual llvm::Optional getDynRel(RelType Type) const { return Type; } virtual void writeGotPltHeader(uint8_t *Buf) const {} virtual void writeGotHeader(uint8_t *Buf) const {} virtual void writeGotPlt(uint8_t *Buf, const Symbol &S) const {};