<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 2, 2016 at 2:56 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, May 2, 2016 at 2:30 PM, Rui Ueyama 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: ruiu<br>
Date: Mon May  2 16:30:42 2016<br>
New Revision: 268310<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=268310&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=268310&view=rev</a><br>
Log:<br>
Teach Undefined symbols from which file they are created from.<br>
<br>
This patch increases the size of Undefined by the size of a pointer,<br>
but it wouldn't actually increase the size of memory that LLD uses<br>
because we are not allocating the exact size but the size of the<br>
largest SymbolBody.<br>
<br>
Modified:<br>
    lld/trunk/ELF/SymbolTable.cpp<br>
    lld/trunk/ELF/Symbols.cpp<br>
    lld/trunk/ELF/Symbols.h<br>
    lld/trunk/test/ELF/lto/combined-lto-object-name.ll<br>
<br>
Modified: lld/trunk/ELF/SymbolTable.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=268310&r1=268309&r2=268310&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=268310&r1=268309&r2=268310&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/SymbolTable.cpp (original)<br>
+++ lld/trunk/ELF/SymbolTable.cpp Mon May  2 16:30:42 2016<br>
@@ -166,7 +166,6 @@ template <class ELFT> void SymbolTable<E<br>
<br>
 // Returns a file from which symbol B was created.<br>
 // If B does not belong to any file, returns a nullptr.<br>
-// This function is slow, but it's okay as it is used only for error messages.<br>
 template <class ELFT> InputFile *SymbolTable<ELFT>::findFile(SymbolBody *B) {<br>
   // If this symbol has a definition, follow pointers in the symbol to its<br>
   // defining file.<br>
@@ -177,21 +176,8 @@ template <class ELFT> InputFile *SymbolT<br>
     return SS->File;<br>
   if (auto *BC = dyn_cast<DefinedBitcode>(B))<br>
     return BC->File;<br>
-  // If not, we might be able to find it by searching symbol tables of files.<br>
-  // This code is generally only used for undefined symbols. Note that we can't<br>
-  // rely exclusively on a file search because we may find what was originally<br>
-  // an undefined symbol that was later replaced with a defined symbol, and we<br>
-  // want to return the file that defined the symbol.<br>
-  for (const std::unique_ptr<ObjectFile<ELFT>> &F : ObjectFiles) {<br>
-    ArrayRef<SymbolBody *> Syms = F->getSymbols();<br>
-    if (std::find(Syms.begin(), Syms.end(), B) != Syms.end())<br>
-      return F.get();<br>
-  }<br>
-  for (const std::unique_ptr<BitcodeFile> &F : BitcodeFiles) {<br>
-    ArrayRef<Symbol *> Syms = F->getSymbols();<br>
-    if (std::find(Syms.begin(), Syms.end(), B->symbol()) != Syms.end())<br>
-      return F.get();<br>
-  }<br>
+  if (auto *U = dyn_cast<Undefined>(B))<br>
+    return U->File;<br>
   return nullptr;<br>
 }<br>
<br>
@@ -253,8 +239,8 @@ template <typename ELFT><br>
 std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Existing,<br>
                                            InputFile *NewFile) {<br>
   StringRef Sym = Existing->getName();<br>
-  return demangle(Sym) + " in " + getFilename(findFile(Existing)) + " and " +<br>
-         getFilename(NewFile);<br>
+  return demangle(Sym) + " in " + getFilename(Existing->getSourceFile<ELFT>()) +<br>
+         " and " + getFilename(NewFile);<br>
 }<br>
<br>
 template <class ELFT> Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name) {<br>
@@ -274,6 +260,7 @@ Symbol *SymbolTable<ELFT>::addUndefined(<br>
   if (WasInserted) {<br>
     S->Binding = Binding;<br>
     replaceBody<Undefined>(S, Name, StOther, Type);<br>
+    cast<Undefined>(S->body())->File = File;<br>
     return S;<br>
   }<br>
   if (Binding != STB_WEAK &&<br>
<br>
Modified: lld/trunk/ELF/Symbols.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=268310&r1=268309&r2=268310&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=268310&r1=268309&r2=268310&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Symbols.cpp (original)<br>
+++ lld/trunk/ELF/Symbols.cpp Mon May  2 16:30:42 2016<br>
@@ -129,6 +129,18 @@ bool SymbolBody::isPreemptible() const {<br>
   return symbol()->Visibility == STV_DEFAULT;<br>
 }<br>
<br>
+template <class ELFT> InputFile *SymbolBody::getSourceFile() {<br>
+  if (auto *S = dyn_cast<DefinedRegular<ELFT>>(this))<br>
+    return S->Section ? S->Section->getFile() : nullptr;<br>
+  if (auto *S = dyn_cast<SharedSymbol<ELFT>>(this))<br>
+    return S->File;<br>
+  if (auto *S = dyn_cast<DefinedBitcode>(this))<br>
+    return S->File;<br>
+  if (auto *S = dyn_cast<Undefined>(this))<br>
+    return S->File;<br>
+  return nullptr;<br>
+}<br>
+<br>
 template <class ELFT><br>
 typename ELFT::uint SymbolBody::getVA(typename ELFT::uint Addend) const {<br>
   typename ELFT::uint OutVA = getSymVA<ELFT>(*this, Addend);<br>
@@ -258,6 +270,11 @@ bool Symbol::includeInDynsym() const {<br>
          (body()->isUndefined() && Config->Shared);<br>
 }<br>
<br>
+template InputFile *SymbolBody::template getSourceFile<ELF32LE>();<br>
+template InputFile *SymbolBody::template getSourceFile<ELF32BE>();<br>
+template InputFile *SymbolBody::template getSourceFile<ELF64LE>();<br>
+template InputFile *SymbolBody::template getSourceFile<ELF64BE>();<br>
+<br>
 template uint32_t SymbolBody::template getVA<ELF32LE>(uint32_t) const;<br>
 template uint32_t SymbolBody::template getVA<ELF32BE>(uint32_t) const;<br>
 template uint64_t SymbolBody::template getVA<ELF64LE>(uint64_t) const;<br>
<br>
Modified: lld/trunk/ELF/Symbols.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=268310&r1=268309&r2=268310&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=268310&r1=268309&r2=268310&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Symbols.h (original)<br>
+++ lld/trunk/ELF/Symbols.h Mon May  2 16:30:42 2016<br>
@@ -108,6 +108,10 @@ public:<br>
   template <class ELFT> typename ELFT::uint getThunkVA() const;<br>
   template <class ELFT> typename ELFT::uint getSize() const;<br>
<br>
+  // Returns the file from which the symbol was created.<br>
+  // For logging purpose only.<br>
+  template <class ELFT> InputFile *getSourceFile();<br>
+<br>
 protected:<br>
   SymbolBody(Kind K, StringRef Name, uint8_t StOther, uint8_t Type);<br>
<br>
@@ -259,6 +263,10 @@ public:<br>
   static bool classof(const SymbolBody *S) {<br>
     return S->kind() == UndefinedKind;<br>
   }<br>
+<br>
+  // The file this undefined symbol was created from.<br>
+  // For logging purpose only.<br>
+  InputFile *File = nullptr;<br>
 };<br>
<br>
 template <class ELFT> class SharedSymbol : public Defined {<br>
<br>
Modified: lld/trunk/test/ELF/lto/combined-lto-object-name.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/combined-lto-object-name.ll?rev=268310&r1=268309&r2=268310&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/combined-lto-object-name.ll?rev=268310&r1=268309&r2=268310&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/lto/combined-lto-object-name.ll (original)<br>
+++ lld/trunk/test/ELF/lto/combined-lto-object-name.ll Mon May  2 16:30:42 2016<br>
@@ -11,4 +11,4 @@ define void @_start() {<br>
   ret void<br>
 }<br>
<br>
-; CHECK: undefined symbol: foo in LLD-INTERNAL-combined-lto-object<br>
+; CHECK: undefined symbol: foo in {{.*}}combined-lto-object-name.ll.tmp.o<br></blockquote><div><br></div></div></div><div>Can you please still check that the message clearly identifies this as an internal object? The check that you have replaced this with no longer does so.</div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span></div></div></div></blockquote><div><br></div><div>As Rui pointed out on IRC, we actually now point at the original object instead of the internal object, which is much more desirable (no need to reference the internal object).</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="HOEnZb"><font color="#888888"><div></div><div>-- Sean Silva</div></font></span><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">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/mailman/listinfo/llvm-commits</a><br>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>