<div dir="ltr">Nice.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 29, 2017 at 2:47 PM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Wed Nov 29 14:47:35 2017<br>
New Revision: 319378<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=319378&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=319378&view=rev</a><br>
Log:<br>
Use Symbol::File directly.<br>
<br>
We are already paying the cost of storing a InputFile in every<br>
Symbol, so use it uniformly.<br>
<br>
Modified:<br>
    lld/trunk/ELF/InputFiles.cpp<br>
    lld/trunk/ELF/LTO.cpp<br>
    lld/trunk/ELF/MapFile.cpp<br>
    lld/trunk/ELF/Relocations.cpp<br>
    lld/trunk/ELF/SymbolTable.cpp<br>
    lld/trunk/ELF/Symbols.cpp<br>
    lld/trunk/ELF/Symbols.h<br>
    lld/trunk/ELF/<wbr>SyntheticSections.cpp<br>
    lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>InputFiles.cpp?rev=319378&r1=<wbr>319377&r2=319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Wed Nov 29 14:47:35 2017<br>
@@ -635,9 +635,9 @@ template <class ELFT> Symbol *ObjFile<EL<br>
<br>
     StringRefZ Name = this->StringTable.data() + Sym->st_name;<br>
     if (Sym->st_shndx == SHN_UNDEF)<br>
-      return make<Undefined>(Name, Binding, StOther, Type);<br>
+      return make<Undefined>(this, Name, Binding, StOther, Type);<br>
<br>
-    return make<Defined>(Name, Binding, StOther, Type, Value, Size, Sec);<br>
+    return make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);<br>
   }<br>
<br>
   StringRef Name = check(Sym->getName(this-><wbr>StringTable), toString(this));<br>
<br>
Modified: lld/trunk/ELF/LTO.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/LTO.cpp?<wbr>rev=319378&r1=319377&r2=<wbr>319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LTO.cpp (original)<br>
+++ lld/trunk/ELF/LTO.cpp Wed Nov 29 14:47:35 2017<br>
@@ -145,7 +145,7 @@ void BitcodeCompiler::add(<wbr>BitcodeFile &F<br>
     // flags an undefined in IR with a definition in ASM as prevailing.<br>
     // Once IRObjectFile is fixed to report only one symbol this hack can<br>
     // be removed.<br>
-    R.Prevailing = !ObjSym.isUndefined() && Sym->getFile() == &F;<br>
+    R.Prevailing = !ObjSym.isUndefined() && Sym->File == &F;<br>
<br>
     // We ask LTO to preserve following global symbols:<br>
     // 1) All symbols when doing relocatable link, so that them can be used<br>
<br>
Modified: lld/trunk/ELF/MapFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/MapFile.<wbr>cpp?rev=319378&r1=319377&r2=<wbr>319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/MapFile.cpp (original)<br>
+++ lld/trunk/ELF/MapFile.cpp Wed Nov 29 14:47:35 2017<br>
@@ -52,7 +52,7 @@ static std::vector<Defined *> getSymbols<br>
   for (InputFile *File : ObjectFiles)<br>
     for (Symbol *B : File->getSymbols())<br>
       if (auto *DR = dyn_cast<Defined>(B))<br>
-        if (DR->getFile() == File && !DR->isSection() && DR->Section &&<br>
+        if (DR->File == File && !DR->isSection() && DR->Section &&<br>
             DR->Section->Live)<br>
           V.push_back(DR);<br>
   return V;<br>
<br>
Modified: lld/trunk/ELF/Relocations.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>Relocations.cpp?rev=319378&r1=<wbr>319377&r2=319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Relocations.cpp (original)<br>
+++ lld/trunk/ELF/Relocations.cpp Wed Nov 29 14:47:35 2017<br>
@@ -73,7 +73,7 @@ template <class ELFT><br>
 static std::string getLocation(InputSectionBase &S, const Symbol &Sym,<br>
                                uint64_t Off) {<br>
   std::string Msg =<br>
-      "\n>>> defined in " + toString(Sym.getFile()) + "\n>>> referenced by ";<br>
+      "\n>>> defined in " + toString(Sym.File) + "\n>>> referenced by ";<br>
   std::string Src = S.getSrcMsg<ELFT>(Sym, Off);<br>
   if (!Src.empty())<br>
     Msg += Src + "\n>>>               ";<br>
@@ -641,7 +641,7 @@ static RelExpr adjustExpr(Symbol &Sym, R<br>
   }<br>
<br>
   errorOrWarn("symbol '" + toString(Sym) + "' defined in " +<br>
-              toString(Sym.getFile()) + " has no type");<br>
+              toString(Sym.File) + " has no type");<br>
   return Expr;<br>
 }<br>
<br>
<br>
Modified: lld/trunk/ELF/SymbolTable.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>SymbolTable.cpp?rev=319378&r1=<wbr>319377&r2=319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/SymbolTable.cpp (original)<br>
+++ lld/trunk/ELF/SymbolTable.cpp Wed Nov 29 14:47:35 2017<br>
@@ -421,8 +421,7 @@ static void warnOrError(const Twine &Msg<br>
<br>
 static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {<br>
   warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +<br>
-              toString(Sym->getFile()) + "\n>>> defined in " +<br>
-              toString(NewFile));<br>
+              toString(Sym->File) + "\n>>> defined in " + toString(NewFile));<br>
 }<br>
<br>
 template <class ELFT><br>
<br>
Modified: lld/trunk/ELF/Symbols.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Symbols.<wbr>cpp?rev=319378&r1=319377&r2=<wbr>319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Symbols.cpp (original)<br>
+++ lld/trunk/ELF/Symbols.cpp Wed Nov 29 14:47:35 2017<br>
@@ -93,7 +93,7 @@ static uint64_t getSymVA(const Symbol &S<br>
<br>
     if (D.isTls() && !Config->Relocatable) {<br>
       if (!Out::TlsPhdr)<br>
-        fatal(toString(D.getFile()) +<br>
+        fatal(toString(D.File) +<br>
               " has an STT_TLS symbol but doesn't have an SHF_TLS section");<br>
       return VA - Out::TlsPhdr->p_vaddr;<br>
     }<br>
@@ -123,17 +123,6 @@ bool Symbol::isUndefWeak() const {<br>
   return !isLocal() && isWeak() && (isUndefined() || isLazy());<br>
 }<br>
<br>
-InputFile *Symbol::getFile() const {<br>
-  if (isLocal()) {<br>
-    const SectionBase *Sec = cast<Defined>(this)->Section;<br>
-    // Local absolute symbols actually have a file, but that is not currently<br>
-    // used. We could support that by having a mostly redundant InputFile in<br>
-    // Symbol, or having a special absolute section if needed.<br>
-    return Sec ? cast<InputSectionBase>(Sec)-><wbr>File : nullptr;<br>
-  }<br>
-  return File;<br>
-}<br>
-<br>
 uint64_t Symbol::getVA(int64_t Addend) const {<br>
   uint64_t OutVA = getSymVA(*this, Addend);<br>
   return OutVA + Addend;<br>
@@ -226,7 +215,7 @@ void Symbol::parseSymbolVersion() {<br>
   // but we may still want to override a versioned symbol from DSO,<br>
   // so we do not report error in this case.<br>
   if (Config->Shared)<br>
-    error(toString(getFile()) + ": symbol " + S + " has undefined version " +<br>
+    error(toString(File) + ": symbol " + S + " has undefined version " +<br>
           Verstr);<br>
 }<br>
<br>
@@ -236,9 +225,7 @@ InputFile *Lazy::fetch() {<br>
   return cast<LazyObject>(this)->fetch(<wbr>);<br>
 }<br>
<br>
-ArchiveFile *LazyArchive::getFile() {<br>
-  return cast<ArchiveFile>(Symbol::<wbr>getFile());<br>
-}<br>
+ArchiveFile *LazyArchive::getFile() { return cast<ArchiveFile>(File); }<br>
<br>
 InputFile *LazyArchive::fetch() {<br>
   std::pair<MemoryBufferRef, uint64_t> MBInfo = getFile()->getMember(&Sym);<br>
@@ -250,9 +237,7 @@ InputFile *LazyArchive::fetch() {<br>
   return createObjectFile(MBInfo.first, getFile()->getName(), MBInfo.second);<br>
 }<br>
<br>
-LazyObjFile *LazyObject::getFile() {<br>
-  return cast<LazyObjFile>(Symbol::<wbr>getFile());<br>
-}<br>
+LazyObjFile *LazyObject::getFile() { return cast<LazyObjFile>(File); }<br>
<br>
 InputFile *LazyObject::fetch() { return getFile()->fetch(); }<br>
<br>
<br>
Modified: lld/trunk/ELF/Symbols.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Symbols.<wbr>h?rev=319378&r1=319377&r2=<wbr>319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Symbols.h (original)<br>
+++ lld/trunk/ELF/Symbols.h Wed Nov 29 14:47:35 2017<br>
@@ -85,7 +85,7 @@ public:<br>
   unsigned InVersionScript : 1;<br>
<br>
   // The file from which this symbol was created.<br>
-  InputFile *File = nullptr;<br>
+  InputFile *File;<br>
<br>
   bool includeInDynsym() const;<br>
   uint8_t computeBinding() const;<br>
@@ -104,7 +104,6 @@ public:<br>
   // all input files have been added.<br>
   bool isUndefWeak() const;<br>
<br>
-  InputFile *getFile() const;<br>
   StringRef getName() const { return Name; }<br>
   uint8_t getVisibility() const { return StOther & 0x3; }<br>
   void parseSymbolVersion();<br>
@@ -129,9 +128,9 @@ public:<br>
   uint32_t GlobalDynIndex = -1;<br>
<br>
 protected:<br>
-  Symbol(Kind K, StringRefZ Name, uint8_t Binding, uint8_t StOther,<br>
-         uint8_t Type)<br>
-      : Binding(Binding), SymbolKind(K), NeedsPltAddr(false),<br>
+  Symbol(Kind K, InputFile *File, StringRefZ Name, uint8_t Binding,<br>
+         uint8_t StOther, uint8_t Type)<br>
+      : Binding(Binding), File(File), SymbolKind(K), NeedsPltAddr(false),<br>
         IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false),<br>
         IsInIgot(false), IsPreemptible(false), Used(!Config->GcSections),<br>
         Type(Type), StOther(StOther), Name(Name) {}<br>
@@ -184,9 +183,9 @@ protected:<br>
 // Represents a symbol that is defined in the current output file.<br>
 class Defined : public Symbol {<br>
 public:<br>
-  Defined(StringRefZ Name, uint8_t Binding, uint8_t StOther, uint8_t Type,<br>
-          uint64_t Value, uint64_t Size, SectionBase *Section)<br>
-      : Symbol(DefinedKind, Name, Binding, StOther, Type), Value(Value),<br>
+  Defined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,<br>
+          uint8_t Type, uint64_t Value, uint64_t Size, SectionBase *Section)<br>
+      : Symbol(DefinedKind, File, Name, Binding, StOther, Type), Value(Value),<br>
         Size(Size), Section(Section) {}<br>
<br>
   static bool classof(const Symbol *S) { return S->isDefined(); }<br>
@@ -198,8 +197,9 @@ public:<br>
<br>
 class Undefined : public Symbol {<br>
 public:<br>
-  Undefined(StringRefZ Name, uint8_t Binding, uint8_t StOther, uint8_t Type)<br>
-      : Symbol(UndefinedKind, Name, Binding, StOther, Type) {}<br>
+  Undefined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,<br>
+            uint8_t Type)<br>
+      : Symbol(UndefinedKind, File, Name, Binding, StOther, Type) {}<br>
<br>
   static bool classof(const Symbol *S) { return S->kind() == UndefinedKind; }<br>
 };<br>
@@ -208,10 +208,10 @@ class SharedSymbol : public Symbol {<br>
 public:<br>
   static bool classof(const Symbol *S) { return S->kind() == SharedKind; }<br>
<br>
-  SharedSymbol(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t Type,<br>
-               uint64_t Value, uint64_t Size, uint32_t Alignment,<br>
-               const void *Verdef)<br>
-      : Symbol(SharedKind, Name, Binding, StOther, Type), Verdef(Verdef),<br>
+  SharedSymbol(InputFile *File, StringRef Name, uint8_t Binding,<br>
+               uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,<br>
+               uint32_t Alignment, const void *Verdef)<br>
+      : Symbol(SharedKind, File, Name, Binding, StOther, Type), Verdef(Verdef),<br>
         Value(Value), Size(Size), Alignment(Alignment) {<br>
     // GNU ifunc is a mechanism to allow user-supplied functions to<br>
     // resolve PLT slot values at load-time. This is contrary to the<br>
@@ -234,7 +234,7 @@ public:<br>
   }<br>
<br>
   template <class ELFT> SharedFile<ELFT> *getFile() const {<br>
-    return cast<SharedFile<ELFT>>(Symbol:<wbr>:getFile());<br>
+    return cast<SharedFile<ELFT>>(File);<br>
   }<br>
<br>
   // This field is a pointer to the symbol's version definition.<br>
@@ -266,8 +266,9 @@ public:<br>
   InputFile *fetch();<br>
<br>
 protected:<br>
-  Lazy(Kind K, StringRef Name, uint8_t Type)<br>
-      : Symbol(K, Name, llvm::ELF::STB_GLOBAL, llvm::ELF::STV_DEFAULT, Type) {}<br>
+  Lazy(Kind K, InputFile *File, StringRef Name, uint8_t Type)<br>
+      : Symbol(K, File, Name, llvm::ELF::STB_GLOBAL, llvm::ELF::STV_DEFAULT,<br>
+               Type) {}<br>
 };<br>
<br>
 // This class represents a symbol defined in an archive file. It is<br>
@@ -276,8 +277,9 @@ protected:<br>
 // symbol.<br>
 class LazyArchive : public Lazy {<br>
 public:<br>
-  LazyArchive(const llvm::object::Archive::Symbol S, uint8_t Type)<br>
-      : Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) {}<br>
+  LazyArchive(InputFile *File, const llvm::object::Archive::Symbol S,<br>
+              uint8_t Type)<br>
+      : Lazy(LazyArchiveKind, File, S.getName(), Type), Sym(S) {}<br>
<br>
   static bool classof(const Symbol *S) { return S->kind() == LazyArchiveKind; }<br>
<br>
@@ -292,7 +294,8 @@ private:<br>
 // --start-lib and --end-lib options.<br>
 class LazyObject : public Lazy {<br>
 public:<br>
-  LazyObject(StringRef Name, uint8_t Type) : Lazy(LazyObjectKind, Name, Type) {}<br>
+  LazyObject(InputFile *File, StringRef Name, uint8_t Type)<br>
+      : Lazy(LazyObjectKind, File, Name, Type) {}<br>
<br>
   static bool classof(const Symbol *S) { return S->kind() == LazyObjectKind; }<br>
<br>
@@ -343,7 +346,7 @@ union SymbolUnion {<br>
 void printTraceSymbol(Symbol *Sym);<br>
<br>
 template <typename T, typename... ArgT><br>
-void replaceSymbol(Symbol *S, InputFile *File, ArgT &&... Arg) {<br>
+void replaceSymbol(Symbol *S, ArgT &&... Arg) {<br>
   static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");<br>
   static_assert(alignof(T) <= alignof(SymbolUnion),<br>
                 "SymbolUnion not aligned enough");<br>
@@ -353,7 +356,6 @@ void replaceSymbol(Symbol *S, InputFile<br>
   Symbol Sym = *S;<br>
<br>
   new (S) T(std::forward<ArgT>(Arg)...);<br>
-  S->File = File;<br>
<br>
   S->VersionId = Sym.VersionId;<br>
   S->Visibility = Sym.Visibility;<br>
<br>
Modified: lld/trunk/ELF/<wbr>SyntheticSections.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>SyntheticSections.cpp?rev=<wbr>319378&r1=319377&r2=319378&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/<wbr>SyntheticSections.cpp (original)<br>
+++ lld/trunk/ELF/<wbr>SyntheticSections.cpp Wed Nov 29 14:47:35 2017<br>
@@ -275,8 +275,8 @@ InputSection *elf::createInterpSection()<br>
<br>
 Symbol *elf::addSyntheticLocal(<wbr>StringRef Name, uint8_t Type, uint64_t Value,<br>
                                uint64_t Size, InputSectionBase *Section) {<br>
-  auto *S =<br>
-      make<Defined>(Name, STB_LOCAL, STV_DEFAULT, Type, Value, Size, Section);<br>
+  auto *S = make<Defined>(Section->File, Name, STB_LOCAL, STV_DEFAULT, Type,<br>
+                          Value, Size, Section);<br>
   if (InX::SymTab)<br>
     InX::SymTab->addSymbol(S);<br>
   return S;<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=319378&r1=319377&r2=319378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Writer.<wbr>cpp?rev=319378&r1=319377&r2=<wbr>319378&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Wed Nov 29 14:47:35 2017<br>
@@ -508,8 +508,9 @@ template <class ELFT> void Writer<ELFT>:<br>
     if (isa<SyntheticSection>(IS) && !(IS->Flags & SHF_MERGE))<br>
       continue;<br>
<br>
-    auto *Sym = make<Defined>("", STB_LOCAL, /*StOther=*/0, STT_SECTION,<br>
-                              /*Value=*/0, /*Size=*/0, IS);<br>
+    auto *Sym =<br>
+        make<Defined>(IS->File, "", STB_LOCAL, /*StOther=*/0, STT_SECTION,<br>
+                      /*Value=*/0, /*Size=*/0, IS);<br>
     InX::SymTab->addSymbol(Sym);<br>
   }<br>
 }<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>