[lld] r295287 - Do not overload a one-bit variable, NeedsCopyOrPltAddr.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 22:12:22 PST 2017


Author: ruiu
Date: Thu Feb 16 00:12:22 2017
New Revision: 295287

URL: http://llvm.org/viewvc/llvm-project?rev=295287&view=rev
Log:
Do not overload a one-bit variable, NeedsCopyOrPltAddr.

This patch removes NeedsCopyOrPltAddr and instead add two variables,
NeedsCopy and NeedsPltAddr. This uses one more bit in Symbol class,
but the actual size doesn't increase because we had unused bits.
This should improve code readability.

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

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=295287&r1=295286&r2=295287&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Feb 16 00:12:22 2017
@@ -458,7 +458,7 @@ template <class ELFT> static void addCop
   // interpose any aliases.
   for (SharedSymbol<ELFT> *Alias : getAliases(SS)) {
     Alias->CopySection = ISec;
-    Alias->NeedsCopyOrPltAddr = true;
+    Alias->NeedsCopy = true;
     Alias->symbol()->IsUsedInRegularObj = true;
   }
 
@@ -502,7 +502,7 @@ static RelExpr adjustExpr(const elf::Obj
   if (Body.isObject()) {
     // Produce a copy relocation.
     auto *B = cast<SharedSymbol<ELFT>>(&Body);
-    if (!B->needsCopy())
+    if (!B->NeedsCopy)
       addCopyRelSymbol(B);
     return Expr;
   }
@@ -527,7 +527,7 @@ static RelExpr adjustExpr(const elf::Obj
     // 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).
-    Body.NeedsCopyOrPltAddr = true;
+    Body.NeedsPltAddr = true;
     return toPlt(Expr);
   }
   error("symbol '" + toString(Body) + "' defined in " + toString(Body.File) +

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=295287&r1=295286&r2=295287&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Thu Feb 16 00:12:22 2017
@@ -79,12 +79,13 @@ static typename ELFT::uint getSymVA(cons
            cast<DefinedCommon>(Body).Offset;
   case SymbolBody::SharedKind: {
     auto &SS = cast<SharedSymbol<ELFT>>(Body);
-    if (!SS.NeedsCopyOrPltAddr)
-      return 0;
-    if (SS.isFunc())
+    if (SS.NeedsCopy) {
+      InputSection<ELFT> *ISec = SS.getBssSectionForCopy();
+      return ISec->OutSec->Addr + ISec->OutSecOff;
+    }
+    if (SS.NeedsPltAddr)
       return Body.getPltVA<ELFT>();
-    InputSection<ELFT> *CopyISec = SS.getBssSectionForCopy();
-    return CopyISec->OutSec->Addr + CopyISec->OutSecOff;
+    return 0;
   }
   case SymbolBody::UndefinedKind:
     return 0;
@@ -98,10 +99,9 @@ static typename ELFT::uint getSymVA(cons
 
 SymbolBody::SymbolBody(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther,
                        uint8_t Type)
-    : SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(IsLocal),
+    : SymbolKind(K), NeedsCopy(false), NeedsPltAddr(false), IsLocal(IsLocal),
       IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false),
-      IsInIgot(false), Type(Type), StOther(StOther),
-      Name(Name) {}
+      IsInIgot(false), Type(Type), StOther(StOther), Name(Name) {}
 
 // Returns true if a symbol can be replaced at load-time by a symbol
 // with the same name defined in other ELF executable or DSO.
@@ -113,7 +113,7 @@ bool SymbolBody::isPreemptible() const {
   // symbols with copy relocations (which resolve to .bss) or preempt plt
   // entries (which resolve to that plt entry).
   if (isShared())
-    return !NeedsCopyOrPltAddr;
+    return !NeedsCopy && !NeedsPltAddr;
 
   // That's all that can be preempted in a non-DSO.
   if (!Config->Shared)
@@ -232,7 +232,7 @@ Undefined::Undefined(StringRefZ Name, bo
 
 template <typename ELFT>
 InputSection<ELFT> *SharedSymbol<ELFT>::getBssSectionForCopy() const {
-  assert(needsCopy());
+  assert(NeedsCopy);
   assert(CopySection);
   return CopySection;
 }

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=295287&r1=295286&r2=295287&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Thu Feb 16 00:12:22 2017
@@ -102,9 +102,13 @@ protected:
   const unsigned SymbolKind : 8;
 
 public:
-  // True if the linker has to generate a copy relocation for this shared
-  // symbol or if the symbol should point to its plt entry.
-  unsigned NeedsCopyOrPltAddr : 1;
+  // True if the linker has to generate a copy relocation.
+  // For SharedSymbol only.
+  unsigned NeedsCopy : 1;
+
+  // True the symbol should point to its PLT entry.
+  // For SharedSymbol only.
+  unsigned NeedsPltAddr : 1;
 
   // True if this is a local symbol.
   unsigned IsLocal : 1;
@@ -270,9 +274,8 @@ public:
   // This field is a pointer to the symbol's version definition.
   const Elf_Verdef *Verdef;
 
-  // CopySection is significant only when needsCopy() is true.
+  // CopySection is significant only when NeedsCopy is true.
   InputSection<ELFT> *CopySection = nullptr;
-  bool needsCopy() const { return this->NeedsCopyOrPltAddr && !this->isFunc(); }
 
   InputSection<ELFT> *getBssSectionForCopy() const;
 };

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=295287&r1=295286&r2=295287&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Thu Feb 16 00:12:22 2017
@@ -1213,7 +1213,7 @@ void SymbolTableSection<ELFT>::writeGlob
       // pointer equality by STO_MIPS_PLT flag. That is necessary to help
       // dynamic linker distinguish such symbols and MIPS lazy-binding stubs.
       // https://sourceware.org/ml/binutils/2008-07/txt00000.txt
-      if (Body->isInPlt() && Body->NeedsCopyOrPltAddr)
+      if (Body->isInPlt() && Body->NeedsPltAddr)
         ESym->st_other |= STO_MIPS_PLT;
       if (Config->Relocatable) {
         auto *D = dyn_cast<DefinedRegular<ELFT>>(Body);
@@ -1243,7 +1243,7 @@ SymbolTableSection<ELFT>::getOutputSecti
     return In<ELFT>::Common->OutSec;
   case SymbolBody::SharedKind: {
     auto &SS = cast<SharedSymbol<ELFT>>(*Sym);
-    if (SS.needsCopy())
+    if (SS.NeedsCopy)
       return SS.getBssSectionForCopy()->OutSec;
     break;
   }




More information about the llvm-commits mailing list