summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/InputSection.h6
-rw-r--r--lld/ELF/Target.cpp31
-rw-r--r--lld/ELF/Target.h2
-rw-r--r--lld/ELF/Writer.cpp4
4 files changed, 11 insertions, 32 deletions
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 1e243e8b084..d182e0ae065 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -59,6 +59,12 @@ enum RelExpr {
R_TLSLD_PC
};
+inline bool refersToGotEntry(RelExpr Expr) {
+ return Expr == R_GOT || Expr == R_GOT_OFF || Expr == R_MIPS_GOT ||
+ Expr == R_MIPS_GOT_LOCAL || Expr == R_GOT_PAGE_PC ||
+ Expr == R_GOT_PC || Expr == R_GOT_FROM_END;
+}
+
struct Relocation {
RelExpr Expr;
uint32_t Type;
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index c32a6ddea32..bdfd2581e95 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -91,8 +91,6 @@ public:
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;
void relaxTlsLdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
-
- bool refersToGotEntry(uint32_t Type) const override;
};
class X86_64TargetInfo final : public TargetInfo {
@@ -110,7 +108,6 @@ public:
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;
- bool refersToGotEntry(uint32_t Type) const override;
bool needsPltImpl(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;
@@ -154,7 +151,6 @@ public:
uint32_t getTlsGotRel(uint32_t Type) const override;
bool isRelRelative(uint32_t Type) const override;
bool needsCopyRelImpl(uint32_t Type) const override;
- bool refersToGotEntry(uint32_t Type) const override;
bool needsPltImpl(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;
@@ -190,7 +186,6 @@ public:
void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
bool isHintRel(uint32_t Type) const override;
bool isRelRelative(uint32_t Type) const override;
- bool refersToGotEntry(uint32_t Type) const override;
};
} // anonymous namespace
@@ -251,8 +246,6 @@ bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }
bool TargetInfo::needsPltImpl(uint32_t Type) const { return false; }
-bool TargetInfo::refersToGotEntry(uint32_t Type) const { return false; }
-
TargetInfo::PltNeed TargetInfo::needsPlt(uint32_t Type,
const SymbolBody &S) const {
if (S.isGnuIFunc())
@@ -281,9 +274,11 @@ TargetInfo::PltNeed TargetInfo::needsPlt(uint32_t Type,
// that points to the real function is a dedicated got entry used by the
// plt. That is identified by special relocation types (R_X86_64_JUMP_SLOT,
// R_386_JMP_SLOT, etc).
- if (S.isShared())
- if (!Config->Pic && S.isFunc() && !refersToGotEntry(Type))
+ if (S.isShared() && !Config->Pic && S.isFunc()) {
+ RelExpr Expr = getRelExpr(Type, S);
+ if (!refersToGotEntry(Expr))
return Plt_Implicit;
+ }
return Plt_No;
}
@@ -461,10 +456,6 @@ bool X86TargetInfo::needsPltImpl(uint32_t Type) const {
return Type == R_386_PLT32;
}
-bool X86TargetInfo::refersToGotEntry(uint32_t Type) const {
- return Type == R_386_GOT32;
-}
-
uint64_t X86TargetInfo::getImplicitAddend(const uint8_t *Buf,
uint32_t Type) const {
switch (Type) {
@@ -672,11 +663,6 @@ bool X86_64TargetInfo::needsCopyRelImpl(uint32_t Type) const {
Type == R_X86_64_64;
}
-bool X86_64TargetInfo::refersToGotEntry(uint32_t Type) const {
- return Type == R_X86_64_GOTPCREL || Type == R_X86_64_GOTPCRELX ||
- Type == R_X86_64_REX_GOTPCRELX;
-}
-
uint32_t X86_64TargetInfo::getDynRel(uint32_t Type) const {
if (Type == R_X86_64_PC32 || Type == R_X86_64_32)
if (Config->Shared)
@@ -1236,10 +1222,6 @@ bool AArch64TargetInfo::needsCopyRelImpl(uint32_t Type) const {
}
}
-bool AArch64TargetInfo::refersToGotEntry(uint32_t Type) const {
- return Type == R_AARCH64_ADR_GOT_PAGE || Type == R_AARCH64_LD64_GOT_LO12_NC;
-}
-
bool AArch64TargetInfo::needsPltImpl(uint32_t Type) const {
switch (Type) {
default:
@@ -1612,11 +1594,6 @@ bool MipsTargetInfo<ELFT>::needsCopyRelImpl(uint32_t Type) const {
}
template <class ELFT>
-bool MipsTargetInfo<ELFT>::refersToGotEntry(uint32_t Type) const {
- return Type == R_MIPS_GOT16 || Type == R_MIPS_CALL16;
-}
-
-template <class ELFT>
bool MipsTargetInfo<ELFT>::needsPltImpl(uint32_t Type) const {
return Type == R_MIPS_26;
}
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index ac7319f391f..fd0cad1e541 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -55,8 +55,6 @@ public:
// dynamic linker if isRelRelative returns true.
virtual bool isRelRelative(uint32_t Type) const;
- virtual bool refersToGotEntry(uint32_t Type) const;
-
enum PltNeed { Plt_No, Plt_Explicit, Plt_Implicit };
PltNeed needsPlt(uint32_t Type, const SymbolBody &S) const;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 8d276ec2d65..5d98ff7c99b 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -573,9 +573,7 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
}
// If a relocation needs GOT, we create a GOT slot for the symbol.
- if (Expr == R_GOT || Expr == R_GOT_OFF || Expr == R_MIPS_GOT ||
- Expr == R_MIPS_GOT_LOCAL || Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC ||
- Expr == R_GOT_FROM_END) {
+ if (refersToGotEntry(Expr)) {
uint32_t T = Body.isTls() ? Target->getTlsGotRel(Type) : Type;
if (Config->EMachine == EM_MIPS && Expr == R_GOT_OFF)
Addend -= MipsGPOffset;
OpenPOWER on IntegriCloud