[lld] r254088 - [ELF] - simplify Target interface, relocPointsToGot() removed.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 12:20:31 PST 2015


Author: grimar
Date: Wed Nov 25 14:20:31 2015
New Revision: 254088

URL: http://llvm.org/viewvc/llvm-project?rev=254088&view=rev
Log:
[ELF] - simplify Target interface, relocPointsToGot() removed.

https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-26/index.html says:
R_386_GOTPC
Resembles R_386_PC32, except that it uses the address of the global offset table in its calculation. The symbol referenced in this relocation normally is _GLOBAL_OFFSET_TABLE_, which also instructs the link-editor to create the global offset table.

Currently _GLOBAL_OFFSET_TABLE_ has value == zero. And we use GOT address to calculate the relocation. This patch does not changes that. It just removes the method which is used only for x86. So it is close to non functional change.

Differential revision: http://reviews.llvm.org/D14993

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=254088&r1=254087&r2=254088&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Nov 25 14:20:31 2015
@@ -148,9 +148,6 @@ void InputSectionBase<ELFT>::relocate(
       SymVA = Out<ELFT>::Got->getEntryAddr(Body);
       Type = Body.isTLS() ? Target->getTlsGotReloc()
                           : Target->getGotRefReloc(Type);
-    } else if (Target->relocPointsToGot(Type)) {
-      SymVA = Out<ELFT>::Got->getVA();
-      Type = Target->getPCRelReloc();
     } else if (!Target->relocNeedsCopy(Type, Body) &&
                isa<SharedSymbol<ELFT>>(Body)) {
       continue;

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=254088&r1=254087&r2=254088&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Nov 25 14:20:31 2015
@@ -53,7 +53,6 @@ public:
                      uint64_t PltEntryAddr, int32_t Index) const override;
   bool relocNeedsCopy(uint32_t Type, const SymbolBody &S) const override;
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
-  bool relocPointsToGot(uint32_t Type) const override;
   bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
   void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
                    uint64_t SA) const override;
@@ -166,8 +165,6 @@ unsigned TargetInfo::getGotRefReloc(unsi
 
 unsigned TargetInfo::getPltRefReloc(unsigned Type) const { return PCRelReloc; }
 
-bool TargetInfo::relocPointsToGot(uint32_t Type) const { return false; }
-
 bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }
 
 void TargetInfo::relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd, uint64_t P,
@@ -209,10 +206,6 @@ bool X86TargetInfo::relocNeedsGot(uint32
   return Type == R_386_GOT32 || relocNeedsPlt(Type, S);
 }
 
-bool X86TargetInfo::relocPointsToGot(uint32_t Type) const {
-  return Type == R_386_GOTPC;
-}
-
 bool X86TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
   return Type == R_386_PLT32 || (Type == R_386_PC32 && S.isShared());
 }
@@ -223,6 +216,9 @@ void X86TargetInfo::relocateOne(uint8_t
   case R_386_GOT32:
     add32le(Loc, SA - Out<ELF32LE>::Got->getVA());
     break;
+  case R_386_GOTPC:
+    add32le(Loc, SA + Out<ELF32LE>::Got->getVA() - P);
+    break;
   case R_386_PC32:
     add32le(Loc, SA - P);
     break;

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=254088&r1=254087&r2=254088&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Wed Nov 25 14:20:31 2015
@@ -24,7 +24,6 @@ public:
   unsigned getPageSize() const { return PageSize; }
   uint64_t getVAStart() const;
   unsigned getCopyReloc() const { return CopyReloc; }
-  unsigned getPCRelReloc() const { return PCRelReloc; }
   unsigned getGotReloc() const { return GotReloc; }
   unsigned getPltReloc() const { return PltReloc; }
   unsigned getRelativeReloc() const { return RelativeReloc; }
@@ -55,7 +54,6 @@ public:
   virtual bool isRelRelative(uint32_t Type) const;
   virtual bool relocNeedsCopy(uint32_t Type, const SymbolBody &S) const;
   virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0;
-  virtual bool relocPointsToGot(uint32_t Type) const;
   virtual bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const = 0;
   virtual void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
                            uint64_t P, uint64_t SA) const = 0;




More information about the llvm-commits mailing list