[lld] r267047 - Remove SymPair and instead use two DefinedRegulars instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 13:50:15 PDT 2016


Author: ruiu
Date: Thu Apr 21 15:50:15 2016
New Revision: 267047

URL: http://llvm.org/viewvc/llvm-project?rev=267047&view=rev
Log:
Remove SymPair and instead use two DefinedRegulars instead.

I noticed that I was looking for the definition of SymPair when hacking
the Writer, only to find that it is just a pair of DefinedRegular symbols.
I don't think it provides more values than the cost of using brainpower
to memorize the type. I didn't roll back r266317, which introduced SymPair,
because the patch removes code repetitions. I ported that change to new
code.

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

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=267047&r1=267046&r2=267047&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Thu Apr 21 15:50:15 2016
@@ -392,16 +392,17 @@ private:
 // Some linker-generated symbols need to be created as
 // DefinedRegular symbols.
 template <class ELFT> struct ElfSym {
-  typedef std::pair<DefinedRegular<ELFT> *, DefinedRegular<ELFT> *> SymPair;
-
   // The content for _etext and etext symbols.
-  static SymPair Etext;
+  static DefinedRegular<ELFT> *Etext;
+  static DefinedRegular<ELFT> *Etext2;
 
   // The content for _edata and edata symbols.
-  static SymPair Edata;
+  static DefinedRegular<ELFT> *Edata;
+  static DefinedRegular<ELFT> *Edata2;
 
   // The content for _end and end symbols.
-  static SymPair End;
+  static DefinedRegular<ELFT> *End;
+  static DefinedRegular<ELFT> *End2;
 
   // The content for _gp symbol for MIPS target.
   static SymbolBody *MipsGp;
@@ -415,10 +416,12 @@ template <class ELFT> struct ElfSym {
   static SymbolBody *RelaIpltEnd;
 };
 
-template <class ELFT> typename ElfSym<ELFT>::SymPair ElfSym<ELFT>::Etext;
-template <class ELFT> typename ElfSym<ELFT>::SymPair ElfSym<ELFT>::Edata;
-template <class ELFT> typename ElfSym<ELFT>::SymPair ElfSym<ELFT>::End;
-
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext2;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata2;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End2;
 template <class ELFT> SymbolBody *ElfSym<ELFT>::MipsGp;
 template <class ELFT> SymbolBody *ElfSym<ELFT>::MipsLocalGp;
 template <class ELFT> SymbolBody *ElfSym<ELFT>::MipsGpDisp;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=267047&r1=267046&r2=267047&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Apr 21 15:50:15 2016
@@ -1176,8 +1176,9 @@ template <class ELFT> void Writer<ELFT>:
   if (!isOutputDynamic())
     Symtab.addIgnored("__tls_get_addr");
 
-  auto Define = [this](StringRef S, typename ElfSym<ELFT>::SymPair &Sym) {
-    Sym.first = Symtab.addIgnored(S, STV_DEFAULT);
+  auto Define = [this](StringRef S, DefinedRegular<ELFT> *&Sym1,
+                       DefinedRegular<ELFT> *&Sym2) {
+    Sym1 = Symtab.addIgnored(S, STV_DEFAULT);
 
     // The name without the underscore is not a reserved name,
     // so it is defined only when there is a reference against it.
@@ -1185,12 +1186,12 @@ template <class ELFT> void Writer<ELFT>:
     S = S.substr(1);
     if (SymbolBody *B = Symtab.find(S))
       if (B->isUndefined())
-        Sym.second = Symtab.addAbsolute(S, STV_DEFAULT);
+        Sym2 = Symtab.addAbsolute(S, STV_DEFAULT);
   };
 
-  Define("_end", ElfSym<ELFT>::End);
-  Define("_etext", ElfSym<ELFT>::Etext);
-  Define("_edata", ElfSym<ELFT>::Edata);
+  Define("_end", ElfSym<ELFT>::End, ElfSym<ELFT>::End2);
+  Define("_etext", ElfSym<ELFT>::Etext, ElfSym<ELFT>::Etext2);
+  Define("_edata", ElfSym<ELFT>::Edata, ElfSym<ELFT>::Edata2);
 }
 
 // Sort input sections by section name suffixes for
@@ -1719,18 +1720,18 @@ static uint16_t getELFType() {
   return ET_EXEC;
 }
 
-template <class ELFT, class SymPair, class uintX_t>
-static void assignSymValue(SymPair &Sym, uintX_t Val) {
-  if (Sym.first)
-    Sym.first->Value = Val;
-  if (Sym.second)
-    Sym.second->Value = Val;
-}
-
 // This function is called after we have assigned address and size
 // to each section. This function fixes some predefined absolute
 // symbol values that depend on section address and size.
 template <class ELFT> void Writer<ELFT>::fixAbsoluteSymbols() {
+  auto Set = [](DefinedRegular<ELFT> *&S1, DefinedRegular<ELFT> *&S2,
+                uintX_t V) {
+    if (S1)
+      S1->Value = V;
+    if (S2)
+      S2->Value = V;
+  };
+
   // _etext is the first location after the last read-only loadable segment.
   // _edata is the first location after the last read-write loadable segment.
   // _end is the first location after the uninitialized data region.
@@ -1738,13 +1739,13 @@ template <class ELFT> void Writer<ELFT>:
     Elf_Phdr &H = P.H;
     if (H.p_type != PT_LOAD)
       continue;
-    assignSymValue<ELFT>(ElfSym<ELFT>::End, H.p_vaddr + H.p_memsz);
+    Set(ElfSym<ELFT>::End, ElfSym<ELFT>::End2, H.p_vaddr + H.p_memsz);
 
     uintX_t Val = H.p_vaddr + H.p_filesz;
     if (H.p_flags & PF_W)
-      assignSymValue<ELFT>(ElfSym<ELFT>::Edata, Val);
+      Set(ElfSym<ELFT>::Edata, ElfSym<ELFT>::Edata2, Val);
     else
-      assignSymValue<ELFT>(ElfSym<ELFT>::Etext, Val);
+      Set(ElfSym<ELFT>::Etext, ElfSym<ELFT>::Etext2, Val);
   }
 }
 




More information about the llvm-commits mailing list