[lld] r267012 - Delete the needsPlt target hook.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 10:30:24 PDT 2016


Author: rafael
Date: Thu Apr 21 12:30:24 2016
New Revision: 267012

URL: http://llvm.org/viewvc/llvm-project?rev=267012&view=rev
Log:
Delete the needsPlt target hook.

It can be made redundant with getRelExpr.

Modified:
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Target.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=267012&r1=267011&r2=267012&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Apr 21 12:30:24 2016
@@ -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 T
 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
   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(uin
   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(uin
   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::isTlsLocalDynamic
          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(uint
   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 *
   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(ui
   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
   }
 }
 
-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
   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>::needsCopyRelI
   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 {

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=267012&r1=267011&r2=267012&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Thu Apr 21 12:30:24 2016
@@ -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;
 };

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=267012&r1=267011&r2=267012&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Apr 21 12:30:24 2016
@@ -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(InputSecti
     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(InputSecti
       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;




More information about the llvm-commits mailing list