summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-04-21 17:30:24 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-04-21 17:30:24 +0000
commitb312a740aea5dc9254b513d31e6495def9fb0083 (patch)
tree3e5783119cdfa923b11d01d28af7e079d2cf24fa
parent1dbd582387a577ee416d22d9cc2dc957926f8035 (diff)
downloadbcm5719-llvm-b312a740aea5dc9254b513d31e6495def9fb0083.tar.gz
bcm5719-llvm-b312a740aea5dc9254b513d31e6495def9fb0083.zip
Delete the needsPlt target hook.
It can be made redundant with getRelExpr. llvm-svn: 267012
-rw-r--r--lld/ELF/Target.cpp50
-rw-r--r--lld/ELF/Target.h2
-rw-r--r--lld/ELF/Writer.cpp19
3 files changed, 26 insertions, 45 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 552799fc41e..bf66c51359d 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -84,7 +84,6 @@ public:
int32_t Index, unsigned RelOff) const override;
bool isRelRelative(uint32_t Type) const override;
bool needsCopyRelImpl(uint32_t Type) const override;
- bool needsPlt(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;
@@ -108,7 +107,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 needsPlt(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;
@@ -132,7 +130,6 @@ public:
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,
int32_t Index, unsigned RelOff) const override;
- bool needsPlt(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;
};
@@ -151,7 +148,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 needsPlt(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;
@@ -180,7 +176,6 @@ public:
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 needsPlt(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;
@@ -244,8 +239,6 @@ bool TargetInfo::needsCopyRel(uint32_t Type, const SymbolBody &S) const {
bool TargetInfo::isHintRel(uint32_t Type) const { return false; }
bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }
-bool TargetInfo::needsPlt(uint32_t Type) const { return false; }
-
bool TargetInfo::needsThunk(uint32_t Type, const InputFile &File,
const SymbolBody &S) const {
return false;
@@ -303,6 +296,7 @@ RelExpr X86TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
case R_386_TLS_LDM:
return R_TLSLD;
case R_386_PLT32:
+ return R_PLT_PC;
case R_386_PC32:
return R_PC;
case R_386_GOTPC:
@@ -415,10 +409,6 @@ bool X86TargetInfo::needsCopyRelImpl(uint32_t Type) const {
return Type == R_386_32 || Type == R_386_16 || Type == R_386_8;
}
-bool X86TargetInfo::needsPlt(uint32_t Type) const {
- return Type == R_386_PLT32;
-}
-
uint64_t X86TargetInfo::getImplicitAddend(const uint8_t *Buf,
uint32_t Type) const {
switch (Type) {
@@ -572,6 +562,7 @@ RelExpr X86_64TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
case R_X86_64_SIZE64:
return R_SIZE;
case R_X86_64_PLT32:
+ return R_PLT_PC;
case R_X86_64_PC32:
return R_PC;
case R_X86_64_GOT32:
@@ -654,10 +645,6 @@ bool X86_64TargetInfo::isTlsLocalDynamicRel(uint32_t Type) const {
Type == R_X86_64_TLSLD;
}
-bool X86_64TargetInfo::needsPlt(uint32_t Type) const {
- return Type == R_X86_64_PLT32;
-}
-
bool X86_64TargetInfo::isRelRelative(uint32_t Type) const {
switch (Type) {
default:
@@ -892,7 +879,7 @@ RelExpr PPC64TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
default:
return R_ABS;
case R_PPC64_REL24:
- return R_PPC_OPD;
+ return R_PPC_PLT_OPD;
}
}
@@ -917,11 +904,6 @@ void PPC64TargetInfo::writePlt(uint8_t *Buf, uint64_t GotEntryAddr,
write32be(Buf + 28, 0x4e800420); // bctr
}
-bool PPC64TargetInfo::needsPlt(uint32_t Type) const {
- // These are function calls that need to be redirected through a PLT stub.
- return Type == R_PPC64_REL24;
-}
-
bool PPC64TargetInfo::isRelRelative(uint32_t Type) const {
switch (Type) {
default:
@@ -1044,14 +1026,16 @@ RelExpr AArch64TargetInfo::getRelExpr(uint32_t Type,
switch (Type) {
default:
return R_ABS;
- case R_AARCH64_JUMP26:
case R_AARCH64_CALL26:
+ case R_AARCH64_CONDBR19:
+ case R_AARCH64_JUMP26:
+ case R_AARCH64_TSTBR14:
+ return R_PLT_PC;
+
case R_AARCH64_PREL16:
case R_AARCH64_PREL32:
case R_AARCH64_PREL64:
- case R_AARCH64_CONDBR19:
case R_AARCH64_ADR_PREL_LO21:
- case R_AARCH64_TSTBR14:
return R_PC;
case R_AARCH64_ADR_PREL_PG_HI21:
return R_PAGE_PC;
@@ -1185,18 +1169,6 @@ bool AArch64TargetInfo::needsCopyRelImpl(uint32_t Type) const {
}
}
-bool AArch64TargetInfo::needsPlt(uint32_t Type) const {
- switch (Type) {
- default:
- return false;
- case R_AARCH64_CALL26:
- case R_AARCH64_CONDBR19:
- case R_AARCH64_JUMP26:
- case R_AARCH64_TSTBR14:
- return true;
- }
-}
-
static void updateAArch64Addr(uint8_t *L, uint64_t Imm) {
uint32_t ImmLo = (Imm & 0x3) << 29;
uint32_t ImmHi = ((Imm & 0x1FFFFC) >> 2) << 5;
@@ -1405,6 +1377,8 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr(uint32_t Type,
switch (Type) {
default:
return R_ABS;
+ case R_MIPS_26:
+ return R_PLT;
case R_MIPS_HI16:
case R_MIPS_LO16:
// MIPS _gp_disp designates offset between start of function and 'gp'
@@ -1556,10 +1530,6 @@ bool MipsTargetInfo<ELFT>::needsCopyRelImpl(uint32_t Type) const {
return !isRelRelative(Type) || Type == R_MIPS_LO16;
}
-template <class ELFT> bool MipsTargetInfo<ELFT>::needsPlt(uint32_t Type) const {
- return Type == R_MIPS_26;
-}
-
template <class ELFT>
bool MipsTargetInfo<ELFT>::needsThunk(uint32_t Type, const InputFile &File,
const SymbolBody &S) const {
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index 1ade042db99..04704928214 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -97,8 +97,6 @@ public:
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;
- virtual bool needsPlt(uint32_t Type) const;
-
private:
virtual bool needsCopyRelImpl(uint32_t Type) const;
};
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 322e1b17a0d..13afd8027dd 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -435,10 +435,14 @@ namespace {
enum PltNeed { Plt_No, Plt_Explicit, Plt_Implicit };
}
+static bool needsPlt(RelExpr Expr) {
+ return Expr == R_PLT_PC || Expr == R_PPC_PLT_OPD || Expr == R_PLT;
+}
+
static PltNeed needsPlt(RelExpr Expr, uint32_t Type, const SymbolBody &S) {
if (S.isGnuIFunc())
return Plt_Explicit;
- if (S.isPreemptible() && Target->needsPlt(Type))
+ if (S.isPreemptible() && needsPlt(Expr))
return Plt_Explicit;
// This handles a non PIC program call to function in a shared library.
@@ -570,12 +574,12 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
if (NeedPlt) {
if (NeedPlt == Plt_Implicit)
Body.NeedsCopyOrPltAddr = true;
- RelExpr E;
+ RelExpr E = Expr;
if (Expr == R_PPC_OPD)
E = R_PPC_PLT_OPD;
else if (Expr == R_PC)
E = R_PLT_PC;
- else
+ else if (Expr == R_ABS)
E = R_PLT;
C.Relocations.push_back({E, Type, Offset, Addend, &Body});
@@ -605,6 +609,15 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
continue;
}
+ // We decided not to use a plt. Optimize a reference to the plt to a
+ // reference to the symbol itself.
+ if (Expr == R_PLT_PC)
+ Expr = R_PC;
+ if (Expr == R_PPC_PLT_OPD)
+ Expr = R_PPC_OPD;
+ if (Expr == R_PLT)
+ Expr = R_ABS;
+
if (Target->needsThunk(Type, File, Body)) {
C.Relocations.push_back({R_THUNK, Type, Offset, Addend, &Body});
continue;
OpenPOWER on IntegriCloud