diff options
-rw-r--r-- | lld/ELF/Target.cpp | 51 | ||||
-rw-r--r-- | lld/ELF/Target.h | 4 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 18 |
3 files changed, 17 insertions, 56 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index b2ced392023..5c6834dad9a 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -92,7 +92,6 @@ public: void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; bool isRelRelative(uint32_t Type) const override; - bool needsCopyRelImpl(uint32_t Type) const override; void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; void relaxTlsGdToIe(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; @@ -115,7 +114,6 @@ public: void writePltZero(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; - bool needsCopyRelImpl(uint32_t Type) const override; void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; bool isRelRelative(uint32_t Type) const override; @@ -156,7 +154,6 @@ public: int32_t Index, unsigned RelOff) const override; uint32_t getTlsGotRel(uint32_t Type) const override; bool isRelRelative(uint32_t Type) const override; - bool needsCopyRelImpl(uint32_t Type) const override; void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; void relaxTlsGdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; void relaxTlsIeToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; @@ -184,7 +181,6 @@ public: int32_t Index, unsigned RelOff) const override; void writeGotHeader(uint8_t *Buf) const override; void writeThunk(uint8_t *Buf, uint64_t S) const override; - bool needsCopyRelImpl(uint32_t Type) const override; bool needsThunk(uint32_t Type, const InputFile &File, const SymbolBody &S) const override; void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; @@ -229,20 +225,6 @@ uint64_t TargetInfo::getImplicitAddend(const uint8_t *Buf, uint64_t TargetInfo::getVAStart() const { return Config->Pic ? 0 : VAStart; } -bool TargetInfo::needsCopyRelImpl(uint32_t Type) const { return false; } - -static bool mayNeedCopy(const SymbolBody &S) { - if (Config->Shared) - return false; - if (!S.isShared()) - return false; - return S.isObject(); -} - -bool TargetInfo::needsCopyRel(uint32_t Type, const SymbolBody &S) const { - return mayNeedCopy(S) && needsCopyRelImpl(Type); -} - bool TargetInfo::isHintRel(uint32_t Type) const { return false; } bool TargetInfo::isRelRelative(uint32_t Type) const { return true; } @@ -412,10 +394,6 @@ void X86TargetInfo::writePlt(uint8_t *Buf, uint64_t GotEntryAddr, write32le(Buf + 12, -Index * PltEntrySize - PltZeroSize - 16); } -bool X86TargetInfo::needsCopyRelImpl(uint32_t Type) const { - return Type == R_386_32 || Type == R_386_16 || Type == R_386_8; -} - uint64_t X86TargetInfo::getImplicitAddend(const uint8_t *Buf, uint32_t Type) const { switch (Type) { @@ -611,11 +589,6 @@ void X86_64TargetInfo::writePlt(uint8_t *Buf, uint64_t GotEntryAddr, write32le(Buf + 12, -Index * PltEntrySize - PltZeroSize - 16); } -bool X86_64TargetInfo::needsCopyRelImpl(uint32_t Type) const { - return Type == R_X86_64_32S || Type == R_X86_64_32 || Type == R_X86_64_PC32 || - Type == R_X86_64_64; -} - uint32_t X86_64TargetInfo::getDynRel(uint32_t Type) const { if (Type == R_X86_64_PC32 || Type == R_X86_64_32) if (Config->Shared) @@ -1141,25 +1114,6 @@ uint32_t AArch64TargetInfo::getTlsGotRel(uint32_t Type) const { return Type; } -bool AArch64TargetInfo::needsCopyRelImpl(uint32_t Type) const { - switch (Type) { - default: - return false; - case R_AARCH64_ABS16: - case R_AARCH64_ABS32: - case R_AARCH64_ABS64: - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_ADR_PREL_LO21: - case R_AARCH64_ADR_PREL_PG_HI21: - case R_AARCH64_LDST8_ABS_LO12_NC: - case R_AARCH64_LDST16_ABS_LO12_NC: - case R_AARCH64_LDST32_ABS_LO12_NC: - case R_AARCH64_LDST64_ABS_LO12_NC: - case R_AARCH64_LDST128_ABS_LO12_NC: - return true; - } -} - static void updateAArch64Addr(uint8_t *L, uint64_t Imm) { uint32_t ImmLo = (Imm & 0x3) << 29; uint32_t ImmHi = ((Imm & 0x1FFFFC) >> 2) << 5; @@ -1517,11 +1471,6 @@ void MipsTargetInfo<ELFT>::writeThunk(uint8_t *Buf, uint64_t S) const { } template <class ELFT> -bool MipsTargetInfo<ELFT>::needsCopyRelImpl(uint32_t Type) const { - return !isRelRelative(Type) || Type == R_MIPS_LO16; -} - -template <class ELFT> bool MipsTargetInfo<ELFT>::needsThunk(uint32_t Type, const InputFile &File, const SymbolBody &S) const { // Any MIPS PIC code function is invoked with its address in register $t9. diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index 3f016b59b0d..7a74e748190 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -62,7 +62,6 @@ public: virtual RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const = 0; virtual void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const = 0; - bool needsCopyRel(uint32_t Type, const SymbolBody &S) const; virtual ~TargetInfo(); unsigned TlsGdToLeSkip = 1; @@ -95,9 +94,6 @@ public: virtual void relaxTlsGdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; virtual void relaxTlsIeToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; virtual void relaxTlsLdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; - -private: - virtual bool needsCopyRelImpl(uint32_t Type) const; }; uint64_t getPPC64TocBase(); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index c1d191c2065..faf3d0bb5ba 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -473,6 +473,22 @@ static PltNeed needsPlt(RelExpr Expr, uint32_t Type, const SymbolBody &S) { return Plt_No; } +static bool needsCopyRel(RelExpr E, const SymbolBody &S) { + if (Config->Shared) + return false; + if (!S.isShared()) + return false; + if (!S.isObject()) + return false; + if (refersToGotEntry(E)) + return false; + if (needsPlt(E)) + return false; + if (E == R_SIZE) + return false; + return true; +} + // The reason we have to do this early scan is as follows // * To mmap the output file, we need to know the size // * For that, we need to know how many dynamic relocs we will have. @@ -557,7 +573,7 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) { // in a read-only section, we need to create a copy relocation for the // symbol. if (auto *B = dyn_cast<SharedSymbol<ELFT>>(&Body)) { - if (IsAlloc && !IsWrite && Target->needsCopyRel(Type, *B)) { + if (IsAlloc && !IsWrite && needsCopyRel(Expr, *B)) { if (!B->needsCopy()) addCopyRelSymbol(B); C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); |