[lld] r325360 - Simplify RelocationBaseSection::addReloc.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 16 08:53:04 PST 2018


Author: rafael
Date: Fri Feb 16 08:53:04 2018
New Revision: 325360

URL: http://llvm.org/viewvc/llvm-project?rev=325360&view=rev
Log:
Simplify RelocationBaseSection::addReloc.

Now that we have R_ADDEND, UseSymVA was redundant. We only want to
write the symbol virtual address when using an expression other than
R_ADDEND.

Modified:
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=325360&r1=325359&r2=325360&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Feb 16 08:53:04 2018
@@ -725,8 +725,8 @@ template <class ELFT> static void addGot
     Type = Target->RelativeRel;
   else
     Type = Target->GotRel;
-  InX::RelaDyn->addReloc(Type, InX::Got, Off, !Sym.IsPreemptible, &Sym, 0,
-                         R_ABS, Target->GotRel);
+  InX::RelaDyn->addReloc(Type, InX::Got, Off, &Sym, 0,
+                         Sym.IsPreemptible ? R_ADDEND : R_ABS, Target->GotRel);
 }
 
 // Return true if we can define a symbol in the executable that
@@ -776,12 +776,12 @@ static RelExpr processRelocAux(InputSect
     bool IsPreemptibleValue = Sym.IsPreemptible && Expr != R_GOT;
 
     if (!IsPreemptibleValue) {
-      InX::RelaDyn->addReloc(Target->RelativeRel, &Sec, Offset, true, &Sym,
-                             Addend, Expr, Type);
+      InX::RelaDyn->addReloc(Target->RelativeRel, &Sec, Offset, &Sym, Addend,
+                             Expr, Type);
       return Expr;
     } else if (Target->isPicRel(Type)) {
-      InX::RelaDyn->addReloc(Target->getDynRel(Type), &Sec, Offset, false, &Sym,
-                             Addend, Expr, Type);
+      InX::RelaDyn->addReloc(Target->getDynRel(Type), &Sec, Offset, &Sym,
+                             Addend, R_ADDEND, Type);
 
       // MIPS ABI turns using of GOT and dynamic relocations inside out.
       // While regular ABI uses dynamic relocations to fill up GOT entries

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=325360&r1=325359&r2=325360&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Feb 16 08:53:04 2018
@@ -1209,18 +1209,14 @@ void RelocationBaseSection::addReloc(Rel
 
 void RelocationBaseSection::addReloc(RelType DynType,
                                      InputSectionBase *InputSec,
-                                     uint64_t OffsetInSec, bool UseSymVA,
-                                     Symbol *Sym, int64_t Addend, RelExpr Expr,
+                                     uint64_t OffsetInSec, Symbol *Sym,
+                                     int64_t Addend, RelExpr Expr,
                                      RelType Type) {
   // Write the addends to the relocated address if required. We skip
   // it if the written value would be zero.
-  if (Config->WriteAddends && (UseSymVA || Addend != 0)) {
-    // If UseSymVA is true we have to write the symbol address, otherwise just
-    // the addend.
-    Expr = UseSymVA ? Expr : R_ADDEND;
+  if (Config->WriteAddends && (Expr != R_ADDEND || Addend != 0))
     InputSec->Relocations.push_back({Expr, Type, OffsetInSec, Addend, Sym});
-  }
-  addReloc({DynType, InputSec, OffsetInSec, UseSymVA, Sym, Addend});
+  addReloc({DynType, InputSec, OffsetInSec, Expr != R_ADDEND, Sym, Addend});
 }
 
 void RelocationBaseSection::addReloc(const DynamicReloc &Reloc) {

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=325360&r1=325359&r2=325360&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Fri Feb 16 08:53:04 2018
@@ -366,8 +366,8 @@ public:
   // Add a dynamic relocation that might need an addend. This takes care of
   // writing the addend to the output section if needed.
   void addReloc(RelType DynType, InputSectionBase *InputSec,
-                uint64_t OffsetInSec, bool UseSymVA, Symbol *Sym,
-                int64_t Addend, RelExpr Expr, RelType Type);
+                uint64_t OffsetInSec, Symbol *Sym, int64_t Addend, RelExpr Expr,
+                RelType Type);
   void addReloc(const DynamicReloc &Reloc);
   bool empty() const override { return Relocs.empty(); }
   size_t getSize() const override { return Relocs.size() * this->Entsize; }




More information about the llvm-commits mailing list