<div dir="ltr">Should be fixed by r289451.<br><div><br></div><div>Peter</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 12, 2016 at 9:36 AM, Mike Aizatsky <span dir="ltr"><<a href="mailto:aizatsky@google.com" target="_blank">aizatsky@google.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">Peter,<div><br></div><div>I think this breaks asan bot:</div><div><br></div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/414/steps/check-lld%20asan/logs/stdio" target="_blank">http://lab.llvm.org:8011/<wbr>builders/sanitizer-x86_64-<wbr>linux-bootstrap/builds/414/<wbr>steps/check-lld%20asan/logs/<wbr>stdio</a><br></div><div><pre style="font-family:"courier new",courier,monotype,monospace;font-size:medium"><span class="m_4374483495119771459inbox-inbox-stdout">==============================<wbr>==============================<wbr>=====
==6557==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 56 byte(s) in 1 object(s) allocated from:
#0 0x706540 in operator new(unsigned long) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/projects/<wbr>compiler-rt/lib/asan/asan_new_<wbr>delete.cc:82
#1 0x7a7b39 in lld::coff::DefinedImportThunk:<wbr>:DefinedImportThunk(llvm::<wbr>StringRef, lld::coff::DefinedImportData*, unsigned short) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/Symbols.cpp:64:26
#2 0x79e014 in replaceBody<lld::coff::<wbr>DefinedImportThunk, llvm::StringRef &, lld::coff::DefinedImportData *&, unsigned short &> /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/Symbols.h:417:24
#3 0x79e014 in lld::coff::SymbolTable::<wbr>addImportThunk(llvm::<wbr>StringRef, lld::coff::DefinedImportData*, unsigned short) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/SymbolTable.cpp:276
#4 0x780413 in lld::coff::ImportFile::parse() /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/InputFiles.cpp:349:15
#5 0x79719b in lld::coff::SymbolTable::<wbr>addFile(lld::coff::InputFile*) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/SymbolTable.cpp:32:9
#6 0x79b35e in lld::coff::SymbolTable::<wbr>addMemberFile(lld::coff::<wbr>ArchiveFile*, llvm::object::Archive::Symbol) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/SymbolTable.cpp:292:3
#7 0x79b715 in lld::coff::SymbolTable::<wbr>addLazy(lld::coff::<wbr>ArchiveFile*, llvm::object::Archive::Symbol) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/SymbolTable.cpp:156:3
#8 0x775f2c in lld::coff::ArchiveFile::parse(<wbr>) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/InputFiles.cpp:60:13
#9 0x79719b in lld::coff::SymbolTable::<wbr>addFile(lld::coff::InputFile*) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/SymbolTable.cpp:32:9
#10 0x735c7b in lld::coff::LinkerDriver::link(<wbr>llvm::ArrayRef<char const*>) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/Driver.cpp:580:12
#11 0x72eaa6 in lld::coff::link(llvm::<wbr>ArrayRef<char const*>) /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/COFF/Driver.cpp:49:11
#12 0x70adfd in main /mnt/b/sanitizer-buildbot2/<wbr>sanitizer-x86_64-linux-<wbr>bootstrap/build/llvm/tools/<wbr>lld/tools/lld/lld.cpp:106:13
#13 0x7f899f22af44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.<wbr>so.6+0x21f44)
SUMMARY: AddressSanitizer: 56 byte(s) leaked in 1 allocation(s).
</span></pre><br class="m_4374483495119771459inbox-inbox-Apple-interchange-newline"></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 9, 2016 at 2:05 PM Peter Collingbourne via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: pcc<br class="m_4374483495119771459gmail_msg">
Date: Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
New Revision: 289280<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=289280&view=rev" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=289280&view=rev</a><br class="m_4374483495119771459gmail_msg">
Log:<br class="m_4374483495119771459gmail_msg">
COFF: New symbol table design.<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
This ports the ELF linker's symbol table design, introduced in r268178,<br class="m_4374483495119771459gmail_msg">
to the COFF linker.<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Differential Revision: <a href="http://reviews.llvm.org/D21166" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://reviews.llvm.org/D21166</a><br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified:<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Chunks.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Chunks.h<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Config.h<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/DLL.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Driver.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Driver.h<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/DriverUtils.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/ICF.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/InputFiles.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/InputFiles.h<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/MarkLive.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/SymbolTable.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/SymbolTable.h<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Symbols.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Symbols.h<br class="m_4374483495119771459gmail_msg">
lld/trunk/COFF/Writer.cpp<br class="m_4374483495119771459gmail_msg">
lld/trunk/test/COFF/include2.<wbr>test<br class="m_4374483495119771459gmail_msg">
lld/trunk/test/COFF/order.test<br class="m_4374483495119771459gmail_msg">
lld/trunk/test/COFF/symtab.<wbr>test<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Chunks.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Chunks.<wbr>cpp?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Chunks.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Chunks.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -150,7 +150,7 @@ void SectionChunk::writeTo(uint8_t *Buf)<br class="m_4374483495119771459gmail_msg">
// Apply relocations.<br class="m_4374483495119771459gmail_msg">
for (const coff_relocation &Rel : Relocs) {<br class="m_4374483495119771459gmail_msg">
uint8_t *Off = Buf + OutputSectionOff + Rel.VirtualAddress;<br class="m_4374483495119771459gmail_msg">
- SymbolBody *Body = File->getSymbolBody(Rel.<wbr>SymbolTableIndex)->repl();<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *Body = File->getSymbolBody(Rel.<wbr>SymbolTableIndex);<br class="m_4374483495119771459gmail_msg">
Defined *Sym = cast<Defined>(Body);<br class="m_4374483495119771459gmail_msg">
uint64_t P = RVA + Rel.VirtualAddress;<br class="m_4374483495119771459gmail_msg">
switch (Config->Machine) {<br class="m_4374483495119771459gmail_msg">
@@ -203,7 +203,7 @@ void SectionChunk::getBaserels(std:<wbr>:vect<br class="m_4374483495119771459gmail_msg">
uint8_t Ty = getBaserelType(Rel);<br class="m_4374483495119771459gmail_msg">
if (Ty == IMAGE_REL_BASED_ABSOLUTE)<br class="m_4374483495119771459gmail_msg">
continue;<br class="m_4374483495119771459gmail_msg">
- SymbolBody *Body = File->getSymbolBody(Rel.<wbr>SymbolTableIndex)->repl();<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *Body = File->getSymbolBody(Rel.<wbr>SymbolTableIndex);<br class="m_4374483495119771459gmail_msg">
if (isa<DefinedAbsolute>(Body))<br class="m_4374483495119771459gmail_msg">
continue;<br class="m_4374483495119771459gmail_msg">
Res->emplace_back(RVA + Rel.VirtualAddress, Ty);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Chunks.h<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Chunks.<wbr>h?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Chunks.h (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Chunks.h Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -28,7 +28,6 @@ using llvm::object::COFFSymbolRef;<br class="m_4374483495119771459gmail_msg">
using llvm::object::SectionRef;<br class="m_4374483495119771459gmail_msg">
using llvm::object::coff_relocation;<br class="m_4374483495119771459gmail_msg">
using llvm::object::coff_section;<br class="m_4374483495119771459gmail_msg">
-using llvm::sys::fs::file_magic;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
class Baserel;<br class="m_4374483495119771459gmail_msg">
class Defined;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Config.h<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Config.<wbr>h?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Config.h (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Config.h Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -26,7 +26,8 @@ using llvm::StringRef;<br class="m_4374483495119771459gmail_msg">
class DefinedAbsolute;<br class="m_4374483495119771459gmail_msg">
class DefinedRelative;<br class="m_4374483495119771459gmail_msg">
class StringChunk;<br class="m_4374483495119771459gmail_msg">
-class Undefined;<br class="m_4374483495119771459gmail_msg">
+struct Symbol;<br class="m_4374483495119771459gmail_msg">
+class SymbolBody;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Short aliases.<br class="m_4374483495119771459gmail_msg">
static const auto AMD64 = llvm::COFF::IMAGE_FILE_<wbr>MACHINE_AMD64;<br class="m_4374483495119771459gmail_msg">
@@ -37,7 +38,7 @@ static const auto I386 = llvm::COFF::IMA<br class="m_4374483495119771459gmail_msg">
struct Export {<br class="m_4374483495119771459gmail_msg">
StringRef Name; // N in /export:N or /export:E=N<br class="m_4374483495119771459gmail_msg">
StringRef ExtName; // E in /export:E=N<br class="m_4374483495119771459gmail_msg">
- Undefined *Sym = nullptr;<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *Sym = nullptr;<br class="m_4374483495119771459gmail_msg">
uint16_t Ordinal = 0;<br class="m_4374483495119771459gmail_msg">
bool Noname = false;<br class="m_4374483495119771459gmail_msg">
bool Data = false;<br class="m_4374483495119771459gmail_msg">
@@ -76,7 +77,7 @@ struct Configuration {<br class="m_4374483495119771459gmail_msg">
llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN;<br class="m_4374483495119771459gmail_msg">
bool Verbose = false;<br class="m_4374483495119771459gmail_msg">
WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_<wbr>UNKNOWN;<br class="m_4374483495119771459gmail_msg">
- Undefined *Entry = nullptr;<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *Entry = nullptr;<br class="m_4374483495119771459gmail_msg">
bool NoEntry = false;<br class="m_4374483495119771459gmail_msg">
std::string OutputFile;<br class="m_4374483495119771459gmail_msg">
bool DoGC = true;<br class="m_4374483495119771459gmail_msg">
@@ -89,7 +90,7 @@ struct Configuration {<br class="m_4374483495119771459gmail_msg">
StringRef PDBPath;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Symbols in this set are considered as live by the garbage collector.<br class="m_4374483495119771459gmail_msg">
- std::set<Undefined *> GCRoot;<br class="m_4374483495119771459gmail_msg">
+ std::set<SymbolBody *> GCRoot;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
std::set<StringRef> NoDefaultLibs;<br class="m_4374483495119771459gmail_msg">
bool NoDefaultLibAll = false;<br class="m_4374483495119771459gmail_msg">
@@ -100,11 +101,11 @@ struct Configuration {<br class="m_4374483495119771459gmail_msg">
std::vector<Export> Exports;<br class="m_4374483495119771459gmail_msg">
std::set<std::string> DelayLoads;<br class="m_4374483495119771459gmail_msg">
std::map<std::string, int> DLLOrder;<br class="m_4374483495119771459gmail_msg">
- Undefined *DelayLoadHelper = nullptr;<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *DelayLoadHelper = nullptr;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Used for SafeSEH.<br class="m_4374483495119771459gmail_msg">
- DefinedRelative *SEHTable = nullptr;<br class="m_4374483495119771459gmail_msg">
- DefinedAbsolute *SEHCount = nullptr;<br class="m_4374483495119771459gmail_msg">
+ Symbol *SEHTable = nullptr;<br class="m_4374483495119771459gmail_msg">
+ Symbol *SEHCount = nullptr;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Used for /opt:lldlto=N<br class="m_4374483495119771459gmail_msg">
unsigned LTOOptLevel = 2;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/DLL.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DLL.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/DLL.<wbr>cpp?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/DLL.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/DLL.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -324,7 +324,7 @@ public:<br class="m_4374483495119771459gmail_msg">
if (E.ForwardChunk) {<br class="m_4374483495119771459gmail_msg">
write32le(P, E.ForwardChunk->getRVA());<br class="m_4374483495119771459gmail_msg">
} else {<br class="m_4374483495119771459gmail_msg">
- write32le(P, cast<Defined>(E.Sym->repl())-><wbr>getRVA());<br class="m_4374483495119771459gmail_msg">
+ write32le(P, cast<Defined>(E.Sym)->getRVA()<wbr>);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Driver.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Driver.<wbr>cpp?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Driver.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Driver.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -207,10 +207,10 @@ void LinkerDriver::<wbr>addLibSearchPaths() {<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-Undefined *LinkerDriver::addUndefined(<wbr>StringRef Name) {<br class="m_4374483495119771459gmail_msg">
- Undefined *U = Symtab.addUndefined(Name);<br class="m_4374483495119771459gmail_msg">
- Config->GCRoot.insert(U);<br class="m_4374483495119771459gmail_msg">
- return U;<br class="m_4374483495119771459gmail_msg">
+SymbolBody *LinkerDriver::addUndefined(<wbr>StringRef Name) {<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *B = Symtab.addUndefined(Name);<br class="m_4374483495119771459gmail_msg">
+ Config->GCRoot.insert(B);<br class="m_4374483495119771459gmail_msg">
+ return B;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Symbol names are mangled by appending "_" prefix on x86.<br class="m_4374483495119771459gmail_msg">
@@ -232,7 +232,7 @@ StringRef LinkerDriver::findDefaultEntry<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
for (auto E : Entries) {<br class="m_4374483495119771459gmail_msg">
StringRef Entry = Symtab.findMangle(mangle(E[0])<wbr>);<br class="m_4374483495119771459gmail_msg">
- if (!Entry.empty() && !isa<Undefined>(Symtab.find(<wbr>Entry)->Body))<br class="m_4374483495119771459gmail_msg">
+ if (!Entry.empty() && !isa<Undefined>(Symtab.find(<wbr>Entry)->body()))<br class="m_4374483495119771459gmail_msg">
return mangle(E[1]);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
return "";<br class="m_4374483495119771459gmail_msg">
@@ -715,7 +715,7 @@ void LinkerDriver::link(ArrayRef<<wbr>const c<br class="m_4374483495119771459gmail_msg">
Symbol *Sym = Symtab.find(From);<br class="m_4374483495119771459gmail_msg">
if (!Sym)<br class="m_4374483495119771459gmail_msg">
continue;<br class="m_4374483495119771459gmail_msg">
- if (auto *U = dyn_cast<Undefined>(Sym->Body)<wbr>)<br class="m_4374483495119771459gmail_msg">
+ if (auto *U = dyn_cast<Undefined>(Sym->body(<wbr>)))<br class="m_4374483495119771459gmail_msg">
if (!U->WeakAlias)<br class="m_4374483495119771459gmail_msg">
U->WeakAlias = Symtab.addUndefined(To);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
@@ -734,7 +734,7 @@ void LinkerDriver::link(ArrayRef<<wbr>const c<br class="m_4374483495119771459gmail_msg">
Symtab.addCombinedLTOObjects(<wbr>);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Make sure we have resolved all symbols.<br class="m_4374483495119771459gmail_msg">
- Symtab.<wbr>reportRemainingUndefines(/*<wbr>Resolve=*/true);<br class="m_4374483495119771459gmail_msg">
+ Symtab.<wbr>reportRemainingUndefines();<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Windows specific -- if no /subsystem is given, we need to infer<br class="m_4374483495119771459gmail_msg">
// that from entry point name.<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Driver.h<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Driver.<wbr>h?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Driver.h (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Driver.h Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -59,6 +59,7 @@ private:<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
class LinkerDriver {<br class="m_4374483495119771459gmail_msg">
public:<br class="m_4374483495119771459gmail_msg">
+ LinkerDriver() { coff::Symtab = &Symtab; }<br class="m_4374483495119771459gmail_msg">
void link(llvm::ArrayRef<const char *> Args);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Used by the resolver to parse .drectve section contents.<br class="m_4374483495119771459gmail_msg">
@@ -86,7 +87,7 @@ private:<br class="m_4374483495119771459gmail_msg">
std::vector<StringRef> SearchPaths;<br class="m_4374483495119771459gmail_msg">
std::set<std::string> VisitedFiles;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- Undefined *addUndefined(StringRef Sym);<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *addUndefined(StringRef Sym);<br class="m_4374483495119771459gmail_msg">
StringRef mangle(StringRef Sym);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Windows specific -- "main" is not the only main function in Windows.<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/DriverUtils.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>DriverUtils.cpp?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/DriverUtils.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/DriverUtils.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -510,13 +510,13 @@ void fixupExports() {<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
for (Export &E : Config->Exports) {<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *Sym = E.Sym;<br class="m_4374483495119771459gmail_msg">
if (!E.ForwardTo.empty()) {<br class="m_4374483495119771459gmail_msg">
E.SymbolName = E.Name;<br class="m_4374483495119771459gmail_msg">
- } else if (Undefined *U = cast_or_null<Undefined>(E.Sym-<wbr>>WeakAlias)) {<br class="m_4374483495119771459gmail_msg">
- E.SymbolName = U->getName();<br class="m_4374483495119771459gmail_msg">
- } else {<br class="m_4374483495119771459gmail_msg">
- E.SymbolName = E.Sym->getName();<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
+ } else if (auto *U = dyn_cast<Undefined>(Sym))<br class="m_4374483495119771459gmail_msg">
+ if (U->WeakAlias)<br class="m_4374483495119771459gmail_msg">
+ Sym = U->WeakAlias;<br class="m_4374483495119771459gmail_msg">
+ E.SymbolName = Sym->getName();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
for (Export &E : Config->Exports) {<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/ICF.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/ICF.<wbr>cpp?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/ICF.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/ICF.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -115,8 +115,8 @@ bool ICF::equalsConstant(const SectionCh<br class="m_4374483495119771459gmail_msg">
R1.VirtualAddress != R2.VirtualAddress) {<br class="m_4374483495119771459gmail_msg">
return false;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
- SymbolBody *B1 = A->File->getSymbolBody(R1.<wbr>SymbolTableIndex)->repl();<br class="m_4374483495119771459gmail_msg">
- SymbolBody *B2 = B->File->getSymbolBody(R2.<wbr>SymbolTableIndex)->repl();<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *B1 = A->File->getSymbolBody(R1.<wbr>SymbolTableIndex);<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *B2 = B->File->getSymbolBody(R2.<wbr>SymbolTableIndex);<br class="m_4374483495119771459gmail_msg">
if (B1 == B2)<br class="m_4374483495119771459gmail_msg">
return true;<br class="m_4374483495119771459gmail_msg">
if (auto *D1 = dyn_cast<DefinedRegular>(B1))<br class="m_4374483495119771459gmail_msg">
@@ -141,8 +141,8 @@ bool ICF::equalsConstant(const SectionCh<br class="m_4374483495119771459gmail_msg">
bool ICF::equalsVariable(const SectionChunk *A, const SectionChunk *B) {<br class="m_4374483495119771459gmail_msg">
// Compare relocations.<br class="m_4374483495119771459gmail_msg">
auto Eq = [&](const coff_relocation &R1, const coff_relocation &R2) {<br class="m_4374483495119771459gmail_msg">
- SymbolBody *B1 = A->File->getSymbolBody(R1.<wbr>SymbolTableIndex)->repl();<br class="m_4374483495119771459gmail_msg">
- SymbolBody *B2 = B->File->getSymbolBody(R2.<wbr>SymbolTableIndex)->repl();<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *B1 = A->File->getSymbolBody(R1.<wbr>SymbolTableIndex);<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *B2 = B->File->getSymbolBody(R2.<wbr>SymbolTableIndex);<br class="m_4374483495119771459gmail_msg">
if (B1 == B2)<br class="m_4374483495119771459gmail_msg">
return true;<br class="m_4374483495119771459gmail_msg">
if (auto *D1 = dyn_cast<DefinedRegular>(B1))<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/InputFiles.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>InputFiles.cpp?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/InputFiles.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/InputFiles.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -12,7 +12,9 @@<br class="m_4374483495119771459gmail_msg">
#include "Driver.h"<br class="m_4374483495119771459gmail_msg">
#include "Error.h"<br class="m_4374483495119771459gmail_msg">
#include "InputFiles.h"<br class="m_4374483495119771459gmail_msg">
+#include "SymbolTable.h"<br class="m_4374483495119771459gmail_msg">
#include "Symbols.h"<br class="m_4374483495119771459gmail_msg">
+#include "lld/Support/Memory.h"<br class="m_4374483495119771459gmail_msg">
#include "llvm/ADT/SmallVector.h"<br class="m_4374483495119771459gmail_msg">
#include "llvm/ADT/Triple.h"<br class="m_4374483495119771459gmail_msg">
#include "llvm/ADT/Twine.h"<br class="m_4374483495119771459gmail_msg">
@@ -39,13 +41,13 @@ using namespace llvm::support::endian;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
using llvm::Triple;<br class="m_4374483495119771459gmail_msg">
using llvm::support::ulittle32_t;<br class="m_4374483495119771459gmail_msg">
+using llvm::sys::fs::file_magic;<br class="m_4374483495119771459gmail_msg">
+using llvm::sys::fs::identify_magic;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
namespace lld {<br class="m_4374483495119771459gmail_msg">
namespace coff {<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-int InputFile::NextIndex = 0;<br class="m_4374483495119771459gmail_msg">
LLVMContext BitcodeFile::Context;<br class="m_4374483495119771459gmail_msg">
-std::mutex BitcodeFile::Mu;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
ArchiveFile::ArchiveFile(<wbr>MemoryBufferRef M) : InputFile(ArchiveKind, M) {}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -53,14 +55,6 @@ void ArchiveFile::parse() {<br class="m_4374483495119771459gmail_msg">
// Parse a MemoryBufferRef as an archive file.<br class="m_4374483495119771459gmail_msg">
File = check(Archive::create(MB), toString(this));<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // Allocate a buffer for Lazy objects.<br class="m_4374483495119771459gmail_msg">
- size_t NumSyms = File->getNumberOfSymbols();<br class="m_4374483495119771459gmail_msg">
- LazySymbols.reserve(NumSyms);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Read the symbol table to construct Lazy objects.<br class="m_4374483495119771459gmail_msg">
- for (const Archive::Symbol &Sym : File->symbols())<br class="m_4374483495119771459gmail_msg">
- LazySymbols.emplace_back(this, Sym);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
// Seen is a map from member files to boolean values. Initially<br class="m_4374483495119771459gmail_msg">
// all members are mapped to false, which indicates all these files<br class="m_4374483495119771459gmail_msg">
// are not read yet.<br class="m_4374483495119771459gmail_msg">
@@ -69,18 +63,22 @@ void ArchiveFile::parse() {<br class="m_4374483495119771459gmail_msg">
Seen[Child.getChildOffset()].<wbr>clear();<br class="m_4374483495119771459gmail_msg">
if (Err)<br class="m_4374483495119771459gmail_msg">
fatal(Err, toString(this));<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ // Read the symbol table to construct Lazy objects.<br class="m_4374483495119771459gmail_msg">
+ for (const Archive::Symbol &Sym : File->symbols())<br class="m_4374483495119771459gmail_msg">
+ Symtab->addLazy(this, Sym);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Returns a buffer pointing to a member file containing a given symbol.<br class="m_4374483495119771459gmail_msg">
// This function is thread-safe.<br class="m_4374483495119771459gmail_msg">
-MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) {<br class="m_4374483495119771459gmail_msg">
+InputFile *ArchiveFile::getMember(const Archive::Symbol *Sym) {<br class="m_4374483495119771459gmail_msg">
const Archive::Child &C =<br class="m_4374483495119771459gmail_msg">
check(Sym->getMember(),<br class="m_4374483495119771459gmail_msg">
"could not get the member for symbol " + Sym->getName());<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Return an empty buffer if we have already returned the same buffer.<br class="m_4374483495119771459gmail_msg">
if (Seen[C.getChildOffset()].<wbr>test_and_set())<br class="m_4374483495119771459gmail_msg">
- return MemoryBufferRef();<br class="m_4374483495119771459gmail_msg">
+ return nullptr;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
MemoryBufferRef MB =<br class="m_4374483495119771459gmail_msg">
check(C.getMemoryBufferRef(),<br class="m_4374483495119771459gmail_msg">
@@ -90,10 +88,21 @@ MemoryBufferRef ArchiveFile::getMember(c<br class="m_4374483495119771459gmail_msg">
Driver->Cpio->append(<wbr>relativeToRoot(check(C.<wbr>getFullName())),<br class="m_4374483495119771459gmail_msg">
MB.getBuffer());<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- return MB;<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
+ file_magic Magic = identify_magic(MB.getBuffer())<wbr>;<br class="m_4374483495119771459gmail_msg">
+ if (Magic == file_magic::coff_import_<wbr>library)<br class="m_4374483495119771459gmail_msg">
+ return make<ImportFile>(MB);<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ InputFile *Obj;<br class="m_4374483495119771459gmail_msg">
+ if (Magic == file_magic::coff_object)<br class="m_4374483495119771459gmail_msg">
+ Obj = make<ObjectFile>(MB);<br class="m_4374483495119771459gmail_msg">
+ else if (Magic == file_magic::bitcode)<br class="m_4374483495119771459gmail_msg">
+ Obj = make<BitcodeFile>(MB);<br class="m_4374483495119771459gmail_msg">
+ else<br class="m_4374483495119771459gmail_msg">
+ fatal("unknown file type: " + MB.getBufferIdentifier());<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-MutableArrayRef<Lazy> ArchiveFile::getLazySymbols() { return LazySymbols; }<br class="m_4374483495119771459gmail_msg">
+ Obj->ParentName = getName();<br class="m_4374483495119771459gmail_msg">
+ return Obj;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
void ObjectFile::parse() {<br class="m_4374483495119771459gmail_msg">
// Parse a memory buffer as a COFF file.<br class="m_4374483495119771459gmail_msg">
@@ -167,7 +176,7 @@ void ObjectFile::initializeSymbols(<wbr>) {<br class="m_4374483495119771459gmail_msg">
uint32_t NumSymbols = COFFObj->getNumberOfSymbols();<br class="m_4374483495119771459gmail_msg">
SymbolBodies.reserve(<wbr>NumSymbols);<br class="m_4374483495119771459gmail_msg">
SparseSymbolBodies.resize(<wbr>NumSymbols);<br class="m_4374483495119771459gmail_msg">
- SmallVector<std::pair<<wbr>Undefined *, uint32_t>, 8> WeakAliases;<br class="m_4374483495119771459gmail_msg">
+ SmallVector<std::pair<<wbr>SymbolBody *, uint32_t>, 8> WeakAliases;<br class="m_4374483495119771459gmail_msg">
int32_t LastSectionNumber = 0;<br class="m_4374483495119771459gmail_msg">
for (uint32_t I = 0; I < NumSymbols; ++I) {<br class="m_4374483495119771459gmail_msg">
// Get a COFFSymbolRef object.<br class="m_4374483495119771459gmail_msg">
@@ -188,7 +197,7 @@ void ObjectFile::initializeSymbols(<wbr>) {<br class="m_4374483495119771459gmail_msg">
Body = createUndefined(Sym);<br class="m_4374483495119771459gmail_msg">
uint32_t TagIndex =<br class="m_4374483495119771459gmail_msg">
static_cast<const coff_aux_weak_external *>(AuxP)->TagIndex;<br class="m_4374483495119771459gmail_msg">
- WeakAliases.emplace_back((<wbr>Undefined *)Body, TagIndex);<br class="m_4374483495119771459gmail_msg">
+ WeakAliases.emplace_back(Body, TagIndex);<br class="m_4374483495119771459gmail_msg">
} else {<br class="m_4374483495119771459gmail_msg">
Body = createDefined(Sym, AuxP, IsFirst);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
@@ -199,23 +208,30 @@ void ObjectFile::initializeSymbols(<wbr>) {<br class="m_4374483495119771459gmail_msg">
I += Sym.getNumberOfAuxSymbols();<br class="m_4374483495119771459gmail_msg">
LastSectionNumber = Sym.getSectionNumber();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
- for (auto WeakAlias : WeakAliases)<br class="m_4374483495119771459gmail_msg">
- WeakAlias.first->WeakAlias = SparseSymbolBodies[WeakAlias.<wbr>second];<br class="m_4374483495119771459gmail_msg">
+ for (auto WeakAlias : WeakAliases) {<br class="m_4374483495119771459gmail_msg">
+ auto *U = dyn_cast<Undefined>(WeakAlias.<wbr>first);<br class="m_4374483495119771459gmail_msg">
+ if (!U)<br class="m_4374483495119771459gmail_msg">
+ continue;<br class="m_4374483495119771459gmail_msg">
+ // Report an error if two undefined symbols have different weak aliases.<br class="m_4374483495119771459gmail_msg">
+ if (U->WeakAlias && U->WeakAlias != SparseSymbolBodies[WeakAlias.<wbr>second])<br class="m_4374483495119771459gmail_msg">
+ Symtab->reportDuplicate(U-><wbr>symbol(), this);<br class="m_4374483495119771459gmail_msg">
+ U->WeakAlias = SparseSymbolBodies[WeakAlias.<wbr>second];<br class="m_4374483495119771459gmail_msg">
+ }<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-Undefined *ObjectFile::createUndefined(<wbr>COFFSymbolRef Sym) {<br class="m_4374483495119771459gmail_msg">
+SymbolBody *ObjectFile::createUndefined(<wbr>COFFSymbolRef Sym) {<br class="m_4374483495119771459gmail_msg">
StringRef Name;<br class="m_4374483495119771459gmail_msg">
COFFObj->getSymbolName(Sym, Name);<br class="m_4374483495119771459gmail_msg">
- return new (Alloc) Undefined(Name);<br class="m_4374483495119771459gmail_msg">
+ return Symtab->addUndefined(Name, this, Sym.isWeakExternal())->body();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-Defined *ObjectFile::createDefined(<wbr>COFFSymbolRef Sym, const void *AuxP,<br class="m_4374483495119771459gmail_msg">
- bool IsFirst) {<br class="m_4374483495119771459gmail_msg">
+SymbolBody *ObjectFile::createDefined(<wbr>COFFSymbolRef Sym, const void *AuxP,<br class="m_4374483495119771459gmail_msg">
+ bool IsFirst) {<br class="m_4374483495119771459gmail_msg">
StringRef Name;<br class="m_4374483495119771459gmail_msg">
if (Sym.isCommon()) {<br class="m_4374483495119771459gmail_msg">
auto *C = new (Alloc) CommonChunk(Sym);<br class="m_4374483495119771459gmail_msg">
Chunks.push_back(C);<br class="m_4374483495119771459gmail_msg">
- return new (Alloc) DefinedCommon(this, Sym, C);<br class="m_4374483495119771459gmail_msg">
+ return Symtab->addCommon(this, Sym, C)->body();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
if (Sym.isAbsolute()) {<br class="m_4374483495119771459gmail_msg">
COFFObj->getSymbolName(Sym, Name);<br class="m_4374483495119771459gmail_msg">
@@ -228,7 +244,10 @@ Defined *ObjectFile::createDefined(<wbr>COFFS<br class="m_4374483495119771459gmail_msg">
SEHCompat = true;<br class="m_4374483495119771459gmail_msg">
return nullptr;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
- return new (Alloc) DefinedAbsolute(Name, Sym);<br class="m_4374483495119771459gmail_msg">
+ if (Sym.isExternal())<br class="m_4374483495119771459gmail_msg">
+ return Symtab->addAbsolute(Name, Sym)->body();<br class="m_4374483495119771459gmail_msg">
+ else<br class="m_4374483495119771459gmail_msg">
+ return new (Alloc) DefinedAbsolute(Name, Sym);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
int32_t SectionNumber = Sym.getSectionNumber();<br class="m_4374483495119771459gmail_msg">
if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)<br class="m_4374483495119771459gmail_msg">
@@ -258,7 +277,11 @@ Defined *ObjectFile::createDefined(<wbr>COFFS<br class="m_4374483495119771459gmail_msg">
SC->Checksum = Aux->CheckSum;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- auto *B = new (Alloc) DefinedRegular(this, Sym, SC);<br class="m_4374483495119771459gmail_msg">
+ DefinedRegular *B;<br class="m_4374483495119771459gmail_msg">
+ if (Sym.isExternal())<br class="m_4374483495119771459gmail_msg">
+ B = cast<DefinedRegular>(Symtab-><wbr>addRegular(this, Sym, SC)->body());<br class="m_4374483495119771459gmail_msg">
+ else<br class="m_4374483495119771459gmail_msg">
+ B = new (Alloc) DefinedRegular(this, Sym, SC);<br class="m_4374483495119771459gmail_msg">
if (SC->isCOMDAT() && Sym.getValue() == 0 && !AuxP)<br class="m_4374483495119771459gmail_msg">
SC->setSymbol(B);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -320,22 +343,23 @@ void ImportFile::parse() {<br class="m_4374483495119771459gmail_msg">
ExtName = ExtName.substr(0, ExtName.find('@'));<br class="m_4374483495119771459gmail_msg">
break;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
- ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExtName, Hdr);<br class="m_4374483495119771459gmail_msg">
- SymbolBodies.push_back(ImpSym)<wbr>;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ this->Hdr = Hdr;<br class="m_4374483495119771459gmail_msg">
+ ExternalName = ExtName;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ ImpSym = cast<DefinedImportData>(<br class="m_4374483495119771459gmail_msg">
+ Symtab->addImportData(ImpName, this)->body());<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// If type is function, we need to create a thunk which jump to an<br class="m_4374483495119771459gmail_msg">
// address pointed by the __imp_ symbol. (This allows you to call<br class="m_4374483495119771459gmail_msg">
// DLL functions just like regular non-DLL functions.)<br class="m_4374483495119771459gmail_msg">
if (Hdr->getType() != llvm::COFF::IMPORT_CODE)<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
- ThunkSym = new (Alloc) DefinedImportThunk(Name, ImpSym, Hdr->Machine);<br class="m_4374483495119771459gmail_msg">
- SymbolBodies.push_back(<wbr>ThunkSym);<br class="m_4374483495119771459gmail_msg">
+ ThunkSym = cast<DefinedImportThunk>(<br class="m_4374483495119771459gmail_msg">
+ Symtab->addImportThunk(Name, ImpSym, Hdr->Machine)->body());<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
void BitcodeFile::parse() {<br class="m_4374483495119771459gmail_msg">
- // Usually parse() is thread-safe, but bitcode file is an exception.<br class="m_4374483495119771459gmail_msg">
- std::lock_guard<std::mutex> Lock(Mu);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
Context.<wbr>enableDebugTypeODRUniquing();<br class="m_4374483495119771459gmail_msg">
ErrorOr<std::unique_ptr<<wbr>LTOModule>> ModOrErr = LTOModule::createFromBuffer(<br class="m_4374483495119771459gmail_msg">
Context, MB.getBufferStart(), MB.getBufferSize(), llvm::TargetOptions());<br class="m_4374483495119771459gmail_msg">
@@ -350,15 +374,15 @@ void BitcodeFile::parse() {<br class="m_4374483495119771459gmail_msg">
StringRef SymName = Saver.save(M->getSymbolName(I)<wbr>);<br class="m_4374483495119771459gmail_msg">
int SymbolDef = Attrs & LTO_SYMBOL_DEFINITION_MASK;<br class="m_4374483495119771459gmail_msg">
if (SymbolDef == LTO_SYMBOL_DEFINITION_<wbr>UNDEFINED) {<br class="m_4374483495119771459gmail_msg">
- SymbolBodies.push_back(new (Alloc) Undefined(SymName));<br class="m_4374483495119771459gmail_msg">
+ SymbolBodies.push_back(Symtab-<wbr>>addUndefined(SymName, this, false)->body());<br class="m_4374483495119771459gmail_msg">
} else {<br class="m_4374483495119771459gmail_msg">
bool Replaceable =<br class="m_4374483495119771459gmail_msg">
(SymbolDef == LTO_SYMBOL_DEFINITION_<wbr>TENTATIVE || // common<br class="m_4374483495119771459gmail_msg">
(Attrs & LTO_SYMBOL_COMDAT) || // comdat<br class="m_4374483495119771459gmail_msg">
(SymbolDef == LTO_SYMBOL_DEFINITION_WEAK && // weak external<br class="m_4374483495119771459gmail_msg">
(Attrs & LTO_SYMBOL_ALIAS)));<br class="m_4374483495119771459gmail_msg">
- SymbolBodies.push_back(new (Alloc) DefinedBitcode(this, SymName,<br class="m_4374483495119771459gmail_msg">
- Replaceable));<br class="m_4374483495119771459gmail_msg">
+ SymbolBodies.push_back(<br class="m_4374483495119771459gmail_msg">
+ Symtab->addBitcode(this, SymName, Replaceable)->body());<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/InputFiles.h<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>InputFiles.h?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/InputFiles.h (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/InputFiles.h Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -31,6 +31,7 @@ using llvm::COFF::MachineTypes;<br class="m_4374483495119771459gmail_msg">
using llvm::object::Archive;<br class="m_4374483495119771459gmail_msg">
using llvm::object::COFFObjectFile;<br class="m_4374483495119771459gmail_msg">
using llvm::object::COFFSymbolRef;<br class="m_4374483495119771459gmail_msg">
+using llvm::object::coff_import_<wbr>header;<br class="m_4374483495119771459gmail_msg">
using llvm::object::coff_section;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
class Chunk;<br class="m_4374483495119771459gmail_msg">
@@ -39,6 +40,7 @@ class DefinedImportData;<br class="m_4374483495119771459gmail_msg">
class DefinedImportThunk;<br class="m_4374483495119771459gmail_msg">
class Lazy;<br class="m_4374483495119771459gmail_msg">
class SectionChunk;<br class="m_4374483495119771459gmail_msg">
+struct Symbol;<br class="m_4374483495119771459gmail_msg">
class SymbolBody;<br class="m_4374483495119771459gmail_msg">
class Undefined;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -52,9 +54,6 @@ public:<br class="m_4374483495119771459gmail_msg">
// Returns the filename.<br class="m_4374483495119771459gmail_msg">
StringRef getName() { return MB.getBufferIdentifier(); }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // Returns symbols defined by this file.<br class="m_4374483495119771459gmail_msg">
- virtual std::vector<SymbolBody *> &getSymbols() = 0;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
// Reads a file (the constructor doesn't do that).<br class="m_4374483495119771459gmail_msg">
virtual void parse() = 0;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -67,14 +66,8 @@ public:<br class="m_4374483495119771459gmail_msg">
// Returns .drectve section contents if exist.<br class="m_4374483495119771459gmail_msg">
StringRef getDirectives() { return StringRef(Directives).trim(); }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // Each file has a unique index. The index number is used to<br class="m_4374483495119771459gmail_msg">
- // resolve ties in symbol resolution.<br class="m_4374483495119771459gmail_msg">
- int Index;<br class="m_4374483495119771459gmail_msg">
- static int NextIndex;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
protected:<br class="m_4374483495119771459gmail_msg">
- InputFile(Kind K, MemoryBufferRef M)<br class="m_4374483495119771459gmail_msg">
- : Index(NextIndex++), MB(M), FileKind(K) {}<br class="m_4374483495119771459gmail_msg">
+ InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
MemoryBufferRef MB;<br class="m_4374483495119771459gmail_msg">
std::string Directives;<br class="m_4374483495119771459gmail_msg">
@@ -90,22 +83,14 @@ public:<br class="m_4374483495119771459gmail_msg">
static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }<br class="m_4374483495119771459gmail_msg">
void parse() override;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // Returns a memory buffer for a given symbol. An empty memory buffer<br class="m_4374483495119771459gmail_msg">
- // is returned if we have already returned the same memory buffer.<br class="m_4374483495119771459gmail_msg">
- // (So that we don't instantiate same members more than once.)<br class="m_4374483495119771459gmail_msg">
- MemoryBufferRef getMember(const Archive::Symbol *Sym);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- llvm::MutableArrayRef<Lazy> getLazySymbols();<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // All symbols returned by ArchiveFiles are of Lazy type.<br class="m_4374483495119771459gmail_msg">
- std::vector<SymbolBody *> &getSymbols() override {<br class="m_4374483495119771459gmail_msg">
- llvm_unreachable("internal fatal");<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
+ // Returns an input file for a given symbol. A null pointer is returned if we<br class="m_4374483495119771459gmail_msg">
+ // have already returned the same input file. (So that we don't instantiate<br class="m_4374483495119771459gmail_msg">
+ // the same member more than once.)<br class="m_4374483495119771459gmail_msg">
+ InputFile *getMember(const Archive::Symbol *Sym);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
private:<br class="m_4374483495119771459gmail_msg">
std::unique_ptr<Archive> File;<br class="m_4374483495119771459gmail_msg">
std::string Filename;<br class="m_4374483495119771459gmail_msg">
- std::vector<Lazy> LazySymbols;<br class="m_4374483495119771459gmail_msg">
std::map<uint64_t, std::atomic_flag> Seen;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -118,7 +103,7 @@ public:<br class="m_4374483495119771459gmail_msg">
MachineTypes getMachineType() override;<br class="m_4374483495119771459gmail_msg">
std::vector<Chunk *> &getChunks() { return Chunks; }<br class="m_4374483495119771459gmail_msg">
std::vector<SectionChunk *> &getDebugChunks() { return DebugChunks; }<br class="m_4374483495119771459gmail_msg">
- std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }<br class="m_4374483495119771459gmail_msg">
+ std::vector<SymbolBody *> &getSymbols() { return SymbolBodies; }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Returns a SymbolBody object for the SymbolIndex'th symbol in the<br class="m_4374483495119771459gmail_msg">
// underlying object file.<br class="m_4374483495119771459gmail_msg">
@@ -142,8 +127,8 @@ private:<br class="m_4374483495119771459gmail_msg">
void initializeSymbols();<br class="m_4374483495119771459gmail_msg">
void initializeSEH();<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- Defined *createDefined(COFFSymbolRef Sym, const void *Aux, bool IsFirst);<br class="m_4374483495119771459gmail_msg">
- Undefined *createUndefined(COFFSymbolRef Sym);<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *createDefined(COFFSymbolRef Sym, const void *Aux, bool IsFirst);<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *createUndefined(COFFSymbolRef Sym);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
std::unique_ptr<<wbr>COFFObjectFile> COFFObj;<br class="m_4374483495119771459gmail_msg">
llvm::BumpPtrAllocator Alloc;<br class="m_4374483495119771459gmail_msg">
@@ -181,7 +166,6 @@ public:<br class="m_4374483495119771459gmail_msg">
explicit ImportFile(MemoryBufferRef M)<br class="m_4374483495119771459gmail_msg">
: InputFile(ImportKind, M), StringAlloc(StringAllocAux) {}<br class="m_4374483495119771459gmail_msg">
static bool classof(const InputFile *F) { return F->kind() == ImportKind; }<br class="m_4374483495119771459gmail_msg">
- std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
DefinedImportData *ImpSym = nullptr;<br class="m_4374483495119771459gmail_msg">
DefinedImportThunk *ThunkSym = nullptr;<br class="m_4374483495119771459gmail_msg">
@@ -190,10 +174,14 @@ public:<br class="m_4374483495119771459gmail_msg">
private:<br class="m_4374483495119771459gmail_msg">
void parse() override;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- std::vector<SymbolBody *> SymbolBodies;<br class="m_4374483495119771459gmail_msg">
llvm::BumpPtrAllocator Alloc;<br class="m_4374483495119771459gmail_msg">
llvm::BumpPtrAllocator StringAllocAux;<br class="m_4374483495119771459gmail_msg">
llvm::StringSaver StringAlloc;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+public:<br class="m_4374483495119771459gmail_msg">
+ StringRef ExternalName;<br class="m_4374483495119771459gmail_msg">
+ const coff_import_header *Hdr;<br class="m_4374483495119771459gmail_msg">
+ Chunk *Location = nullptr;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Used for LTO.<br class="m_4374483495119771459gmail_msg">
@@ -201,7 +189,7 @@ class BitcodeFile : public InputFile {<br class="m_4374483495119771459gmail_msg">
public:<br class="m_4374483495119771459gmail_msg">
explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}<br class="m_4374483495119771459gmail_msg">
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }<br class="m_4374483495119771459gmail_msg">
- std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }<br class="m_4374483495119771459gmail_msg">
+ std::vector<SymbolBody *> &getSymbols() { return SymbolBodies; }<br class="m_4374483495119771459gmail_msg">
MachineTypes getMachineType() override;<br class="m_4374483495119771459gmail_msg">
std::unique_ptr<LTOModule> takeModule() { return std::move(M); }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/MarkLive.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MarkLive.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>MarkLive.cpp?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/MarkLive.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/MarkLive.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -38,8 +38,8 @@ void markLive(const std::vector<Chunk *><br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Add GC root chunks.<br class="m_4374483495119771459gmail_msg">
- for (Undefined *U : Config->GCRoot)<br class="m_4374483495119771459gmail_msg">
- if (auto *D = dyn_cast<DefinedRegular>(U-><wbr>repl()))<br class="m_4374483495119771459gmail_msg">
+ for (SymbolBody *B : Config->GCRoot)<br class="m_4374483495119771459gmail_msg">
+ if (auto *D = dyn_cast<DefinedRegular>(B))<br class="m_4374483495119771459gmail_msg">
Enqueue(D->getChunk());<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
while (!Worklist.empty()) {<br class="m_4374483495119771459gmail_msg">
@@ -48,7 +48,7 @@ void markLive(const std::vector<Chunk *><br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Mark all symbols listed in the relocation table for this section.<br class="m_4374483495119771459gmail_msg">
for (SymbolBody *S : SC->symbols())<br class="m_4374483495119771459gmail_msg">
- if (auto *D = dyn_cast<DefinedRegular>(S-><wbr>repl()))<br class="m_4374483495119771459gmail_msg">
+ if (auto *D = dyn_cast<DefinedRegular>(S))<br class="m_4374483495119771459gmail_msg">
Enqueue(D->getChunk());<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Mark associative sections if any.<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/SymbolTable.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>SymbolTable.cpp?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/SymbolTable.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/SymbolTable.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -12,7 +12,6 @@<br class="m_4374483495119771459gmail_msg">
#include "Driver.h"<br class="m_4374483495119771459gmail_msg">
#include "Error.h"<br class="m_4374483495119771459gmail_msg">
#include "Symbols.h"<br class="m_4374483495119771459gmail_msg">
-#include "lld/Core/Parallel.h"<br class="m_4374483495119771459gmail_msg">
#include "lld/Support/Memory.h"<br class="m_4374483495119771459gmail_msg">
#include "llvm/IR/LLVMContext.h"<br class="m_4374483495119771459gmail_msg">
#include "llvm/LTO/legacy/<wbr>LTOCodeGenerator.h"<br class="m_4374483495119771459gmail_msg">
@@ -25,21 +24,15 @@ using namespace llvm;<br class="m_4374483495119771459gmail_msg">
namespace lld {<br class="m_4374483495119771459gmail_msg">
namespace coff {<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::addFile(InputFile *File) {<br class="m_4374483495119771459gmail_msg">
-#if LLVM_ENABLE_THREADS<br class="m_4374483495119771459gmail_msg">
- std::launch Policy = std::launch::async;<br class="m_4374483495119771459gmail_msg">
-#else<br class="m_4374483495119771459gmail_msg">
- std::launch Policy = std::launch::deferred;<br class="m_4374483495119771459gmail_msg">
-#endif<br class="m_4374483495119771459gmail_msg">
+SymbolTable *Symtab;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
+void SymbolTable::addFile(InputFile *File) {<br class="m_4374483495119771459gmail_msg">
Files.push_back(File);<br class="m_4374483495119771459gmail_msg">
if (auto *F = dyn_cast<ArchiveFile>(File)) {<br class="m_4374483495119771459gmail_msg">
- ArchiveQueue.push_back(<br class="m_4374483495119771459gmail_msg">
- std::async(Policy, [=]() { F->parse(); return F; }));<br class="m_4374483495119771459gmail_msg">
+ ArchiveQueue.push_back(F);<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
- ObjectQueue.push_back(<br class="m_4374483495119771459gmail_msg">
- std::async(Policy, [=]() { File->parse(); return File; }));<br class="m_4374483495119771459gmail_msg">
+ ObjectQueue.push_back(File);<br class="m_4374483495119771459gmail_msg">
if (auto *F = dyn_cast<ObjectFile>(File)) {<br class="m_4374483495119771459gmail_msg">
ObjectFiles.push_back(F);<br class="m_4374483495119771459gmail_msg">
} else if (auto *F = dyn_cast<BitcodeFile>(File)) {<br class="m_4374483495119771459gmail_msg">
@@ -53,7 +46,7 @@ void SymbolTable::step() {<br class="m_4374483495119771459gmail_msg">
if (queueEmpty())<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
readObjects();<br class="m_4374483495119771459gmail_msg">
- readArchives();<br class="m_4374483495119771459gmail_msg">
+ readArchive();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
void SymbolTable::run() {<br class="m_4374483495119771459gmail_msg">
@@ -61,26 +54,17 @@ void SymbolTable::run() {<br class="m_4374483495119771459gmail_msg">
step();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::readArchives() {<br class="m_4374483495119771459gmail_msg">
+void SymbolTable::readArchive() {<br class="m_4374483495119771459gmail_msg">
if (ArchiveQueue.empty())<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Add lazy symbols to the symbol table. Lazy symbols that conflict<br class="m_4374483495119771459gmail_msg">
// with existing undefined symbols are accumulated in LazySyms.<br class="m_4374483495119771459gmail_msg">
- std::vector<Symbol *> LazySyms;<br class="m_4374483495119771459gmail_msg">
- for (std::future<ArchiveFile *> &Future : ArchiveQueue) {<br class="m_4374483495119771459gmail_msg">
- ArchiveFile *File = Future.get();<br class="m_4374483495119771459gmail_msg">
- if (Config->Verbose)<br class="m_4374483495119771459gmail_msg">
- outs() << "Reading " << toString(File) << "\n";<br class="m_4374483495119771459gmail_msg">
- for (Lazy &Sym : File->getLazySymbols())<br class="m_4374483495119771459gmail_msg">
- addLazy(&Sym, &LazySyms);<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- ArchiveQueue.clear();<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Add archive member files to ObjectQueue that should resolve<br class="m_4374483495119771459gmail_msg">
- // existing undefined symbols.<br class="m_4374483495119771459gmail_msg">
- for (Symbol *Sym : LazySyms)<br class="m_4374483495119771459gmail_msg">
- addMemberFile(cast<Lazy>(Sym-><wbr>Body));<br class="m_4374483495119771459gmail_msg">
+ ArchiveFile *File = ArchiveQueue.front();<br class="m_4374483495119771459gmail_msg">
+ ArchiveQueue.pop_front();<br class="m_4374483495119771459gmail_msg">
+ if (Config->Verbose)<br class="m_4374483495119771459gmail_msg">
+ outs() << "Reading " << toString(File) << "\n";<br class="m_4374483495119771459gmail_msg">
+ File->parse();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
void SymbolTable::readObjects() {<br class="m_4374483495119771459gmail_msg">
@@ -90,14 +74,12 @@ void SymbolTable::readObjects() {<br class="m_4374483495119771459gmail_msg">
// Add defined and undefined symbols to the symbol table.<br class="m_4374483495119771459gmail_msg">
std::vector<StringRef> Directives;<br class="m_4374483495119771459gmail_msg">
for (size_t I = 0; I < ObjectQueue.size(); ++I) {<br class="m_4374483495119771459gmail_msg">
- InputFile *File = ObjectQueue[I].get();<br class="m_4374483495119771459gmail_msg">
+ InputFile *File = ObjectQueue[I];<br class="m_4374483495119771459gmail_msg">
if (Config->Verbose)<br class="m_4374483495119771459gmail_msg">
outs() << "Reading " << toString(File) << "\n";<br class="m_4374483495119771459gmail_msg">
+ File->parse();<br class="m_4374483495119771459gmail_msg">
// Adding symbols may add more files to ObjectQueue<br class="m_4374483495119771459gmail_msg">
// (but not to ArchiveQueue).<br class="m_4374483495119771459gmail_msg">
- for (SymbolBody *Sym : File->getSymbols())<br class="m_4374483495119771459gmail_msg">
- if (Sym->isExternal())<br class="m_4374483495119771459gmail_msg">
- addSymbol(Sym);<br class="m_4374483495119771459gmail_msg">
StringRef S = File->getDirectives();<br class="m_4374483495119771459gmail_msg">
if (!S.empty()) {<br class="m_4374483495119771459gmail_msg">
Directives.push_back(S);<br class="m_4374483495119771459gmail_msg">
@@ -117,127 +99,239 @@ bool SymbolTable::queueEmpty() {<br class="m_4374483495119771459gmail_msg">
return ArchiveQueue.empty() && ObjectQueue.empty();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::<wbr>reportRemainingUndefines(bool Resolve) {<br class="m_4374483495119771459gmail_msg">
+void SymbolTable::<wbr>reportRemainingUndefines() {<br class="m_4374483495119771459gmail_msg">
SmallPtrSet<SymbolBody *, 8> Undefs;<br class="m_4374483495119771459gmail_msg">
for (auto &I : Symtab) {<br class="m_4374483495119771459gmail_msg">
Symbol *Sym = I.second;<br class="m_4374483495119771459gmail_msg">
- auto *Undef = dyn_cast<Undefined>(Sym->Body)<wbr>;<br class="m_4374483495119771459gmail_msg">
+ auto *Undef = dyn_cast<Undefined>(Sym->body(<wbr>));<br class="m_4374483495119771459gmail_msg">
if (!Undef)<br class="m_4374483495119771459gmail_msg">
continue;<br class="m_4374483495119771459gmail_msg">
+ if (!Sym->IsUsedInRegularObj)<br class="m_4374483495119771459gmail_msg">
+ continue;<br class="m_4374483495119771459gmail_msg">
StringRef Name = Undef->getName();<br class="m_4374483495119771459gmail_msg">
// A weak alias may have been resolved, so check for that.<br class="m_4374483495119771459gmail_msg">
if (Defined *D = Undef->getWeakAlias()) {<br class="m_4374483495119771459gmail_msg">
- if (Resolve)<br class="m_4374483495119771459gmail_msg">
- Sym->Body = D;<br class="m_4374483495119771459gmail_msg">
+ // We resolve weak aliases by replacing the alias's SymbolBody with the<br class="m_4374483495119771459gmail_msg">
+ // target's SymbolBody. This causes all SymbolBody pointers referring to<br class="m_4374483495119771459gmail_msg">
+ // the old symbol to instead refer to the new symbol. However, we can't<br class="m_4374483495119771459gmail_msg">
+ // just blindly copy sizeof(Symbol::Body) bytes from D to Sym->Body<br class="m_4374483495119771459gmail_msg">
+ // because D may be an internal symbol, and internal symbols are stored as<br class="m_4374483495119771459gmail_msg">
+ // "unparented" SymbolBodies. For that reason we need to check which type<br class="m_4374483495119771459gmail_msg">
+ // of symbol we are dealing with and copy the correct number of bytes.<br class="m_4374483495119771459gmail_msg">
+ if (isa<DefinedRegular>(D))<br class="m_4374483495119771459gmail_msg">
+ memcpy(Sym->Body.buffer, D, sizeof(DefinedRegular));<br class="m_4374483495119771459gmail_msg">
+ else if (isa<DefinedAbsolute>(D))<br class="m_4374483495119771459gmail_msg">
+ memcpy(Sym->Body.buffer, D, sizeof(DefinedAbsolute));<br class="m_4374483495119771459gmail_msg">
+ else<br class="m_4374483495119771459gmail_msg">
+ // No other internal symbols are possible.<br class="m_4374483495119771459gmail_msg">
+ Sym->Body = D->symbol()->Body;<br class="m_4374483495119771459gmail_msg">
continue;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
// If we can resolve a symbol by removing __imp_ prefix, do that.<br class="m_4374483495119771459gmail_msg">
// This odd rule is for compatibility with MSVC linker.<br class="m_4374483495119771459gmail_msg">
if (Name.startswith("__imp_")) {<br class="m_4374483495119771459gmail_msg">
Symbol *Imp = find(Name.substr(strlen("__<wbr>imp_")));<br class="m_4374483495119771459gmail_msg">
- if (Imp && isa<Defined>(Imp->Body)) {<br class="m_4374483495119771459gmail_msg">
- if (!Resolve)<br class="m_4374483495119771459gmail_msg">
- continue;<br class="m_4374483495119771459gmail_msg">
- auto *D = cast<Defined>(Imp->Body);<br class="m_4374483495119771459gmail_msg">
- auto *S = make<DefinedLocalImport>(Name, D);<br class="m_4374483495119771459gmail_msg">
- LocalImportChunks.push_back(S-<wbr>>getChunk());<br class="m_4374483495119771459gmail_msg">
- Sym->Body = S;<br class="m_4374483495119771459gmail_msg">
+ if (Imp && isa<Defined>(Imp->body())) {<br class="m_4374483495119771459gmail_msg">
+ auto *D = cast<Defined>(Imp->body());<br class="m_4374483495119771459gmail_msg">
+ replaceBody<<wbr>DefinedLocalImport>(Sym, Name, D);<br class="m_4374483495119771459gmail_msg">
+ LocalImportChunks.push_back(<br class="m_4374483495119771459gmail_msg">
+ cast<DefinedLocalImport>(Sym-><wbr>body())->getChunk());<br class="m_4374483495119771459gmail_msg">
continue;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
// Remaining undefined symbols are not fatal if /force is specified.<br class="m_4374483495119771459gmail_msg">
// They are replaced with dummy defined symbols.<br class="m_4374483495119771459gmail_msg">
- if (Config->Force && Resolve)<br class="m_4374483495119771459gmail_msg">
- Sym->Body = make<DefinedAbsolute>(Name, 0);<br class="m_4374483495119771459gmail_msg">
- Undefs.insert(Sym->Body);<br class="m_4374483495119771459gmail_msg">
+ if (Config->Force)<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedAbsolute>(<wbr>Sym, Name, 0);<br class="m_4374483495119771459gmail_msg">
+ Undefs.insert(Sym->body());<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
if (Undefs.empty())<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
- for (Undefined *U : Config->GCRoot)<br class="m_4374483495119771459gmail_msg">
- if (Undefs.count(U->repl()))<br class="m_4374483495119771459gmail_msg">
- errs() << "<root>: undefined symbol: " << U->getName() << "\n";<br class="m_4374483495119771459gmail_msg">
- for (InputFile *File : Files)<br class="m_4374483495119771459gmail_msg">
- if (!isa<ArchiveFile>(File))<br class="m_4374483495119771459gmail_msg">
- for (SymbolBody *Sym : File->getSymbols())<br class="m_4374483495119771459gmail_msg">
- if (Undefs.count(Sym->repl()))<br class="m_4374483495119771459gmail_msg">
- errs() << toString(File) << ": undefined symbol: " << Sym->getName()<br class="m_4374483495119771459gmail_msg">
- << "\n";<br class="m_4374483495119771459gmail_msg">
+ for (SymbolBody *B : Config->GCRoot)<br class="m_4374483495119771459gmail_msg">
+ if (Undefs.count(B))<br class="m_4374483495119771459gmail_msg">
+ errs() << "<root>: undefined symbol: " << B->getName() << "\n";<br class="m_4374483495119771459gmail_msg">
+ for (ObjectFile *File : ObjectFiles)<br class="m_4374483495119771459gmail_msg">
+ for (SymbolBody *Sym : File->getSymbols())<br class="m_4374483495119771459gmail_msg">
+ if (Undefs.count(Sym))<br class="m_4374483495119771459gmail_msg">
+ errs() << toString(File) << ": undefined symbol: " << Sym->getName()<br class="m_4374483495119771459gmail_msg">
+ << "\n";<br class="m_4374483495119771459gmail_msg">
if (!Config->Force)<br class="m_4374483495119771459gmail_msg">
fatal("link failed");<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::addLazy(Lazy *New, std::vector<Symbol *> *Accum) {<br class="m_4374483495119771459gmail_msg">
- Symbol *Sym = insert(New);<br class="m_4374483495119771459gmail_msg">
- if (Sym->Body == New)<br class="m_4374483495119771459gmail_msg">
- return;<br class="m_4374483495119771459gmail_msg">
- SymbolBody *Existing = Sym->Body;<br class="m_4374483495119771459gmail_msg">
- if (isa<Defined>(Existing))<br class="m_4374483495119771459gmail_msg">
- return;<br class="m_4374483495119771459gmail_msg">
- if (Lazy *L = dyn_cast<Lazy>(Existing))<br class="m_4374483495119771459gmail_msg">
- if (L->getFileIndex() < New->getFileIndex())<br class="m_4374483495119771459gmail_msg">
- return;<br class="m_4374483495119771459gmail_msg">
- Sym->Body = New;<br class="m_4374483495119771459gmail_msg">
- New->setBackref(Sym);<br class="m_4374483495119771459gmail_msg">
- if (isa<Undefined>(Existing))<br class="m_4374483495119771459gmail_msg">
- Accum->push_back(Sym);<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::addSymbol(<wbr>SymbolBody *New) {<br class="m_4374483495119771459gmail_msg">
- // Find an existing symbol or create and insert a new one.<br class="m_4374483495119771459gmail_msg">
- assert(isa<Defined>(New) || isa<Undefined>(New));<br class="m_4374483495119771459gmail_msg">
- Symbol *Sym = insert(New);<br class="m_4374483495119771459gmail_msg">
- if (Sym->Body == New)<br class="m_4374483495119771459gmail_msg">
- return;<br class="m_4374483495119771459gmail_msg">
- SymbolBody *Existing = Sym->Body;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // If we have an undefined symbol and a lazy symbol,<br class="m_4374483495119771459gmail_msg">
- // let the lazy symbol to read a member file.<br class="m_4374483495119771459gmail_msg">
- if (auto *L = dyn_cast<Lazy>(Existing)) {<br class="m_4374483495119771459gmail_msg">
- // Undefined symbols with weak aliases need not to be resolved,<br class="m_4374483495119771459gmail_msg">
- // since they would be replaced with weak aliases if they remain<br class="m_4374483495119771459gmail_msg">
- // undefined.<br class="m_4374483495119771459gmail_msg">
- if (auto *U = dyn_cast<Undefined>(New)) {<br class="m_4374483495119771459gmail_msg">
- if (!U->WeakAlias) {<br class="m_4374483495119771459gmail_msg">
- addMemberFile(L);<br class="m_4374483495119771459gmail_msg">
- return;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- Sym->Body = New;<br class="m_4374483495119771459gmail_msg">
- return;<br class="m_4374483495119771459gmail_msg">
+std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *&Sym = Symtab[Name];<br class="m_4374483495119771459gmail_msg">
+ if (Sym)<br class="m_4374483495119771459gmail_msg">
+ return {Sym, false};<br class="m_4374483495119771459gmail_msg">
+ Sym = make<Symbol>();<br class="m_4374483495119771459gmail_msg">
+ Sym->IsUsedInRegularObj = false;<br class="m_4374483495119771459gmail_msg">
+ return {Sym, true};<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addUndefined(<wbr>StringRef Name, InputFile *F,<br class="m_4374483495119771459gmail_msg">
+ bool IsWeakAlias) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(Name);<br class="m_4374483495119771459gmail_msg">
+ if (!F || !isa<BitcodeFile>(F))<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || (isa<Lazy>(S->body()) && IsWeakAlias)) {<br class="m_4374483495119771459gmail_msg">
+ replaceBody<Undefined>(S, Name);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // compare() returns -1, 0, or 1 if the lhs symbol is less preferable,<br class="m_4374483495119771459gmail_msg">
- // equivalent (conflicting), or more preferable, respectively.<br class="m_4374483495119771459gmail_msg">
- int Comp = Existing->compare(New);<br class="m_4374483495119771459gmail_msg">
- if (Comp == 0)<br class="m_4374483495119771459gmail_msg">
- fatal("duplicate symbol: " + toString(*Existing) + " in " +<br class="m_4374483495119771459gmail_msg">
- toString(Existing->getFile()) + " and in " +<br class="m_4374483495119771459gmail_msg">
- toString(New->getFile()));<br class="m_4374483495119771459gmail_msg">
- if (Comp < 0)<br class="m_4374483495119771459gmail_msg">
- Sym->Body = New;<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
-Symbol *SymbolTable::insert(<wbr>SymbolBody *New) {<br class="m_4374483495119771459gmail_msg">
- Symbol *&Sym = Symtab[New->getName()];<br class="m_4374483495119771459gmail_msg">
- if (Sym) {<br class="m_4374483495119771459gmail_msg">
- New->setBackref(Sym);<br class="m_4374483495119771459gmail_msg">
- return Sym;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- Sym = make<Symbol>(New);<br class="m_4374483495119771459gmail_msg">
- New->setBackref(Sym);<br class="m_4374483495119771459gmail_msg">
- return Sym;<br class="m_4374483495119771459gmail_msg">
+ if (auto *L = dyn_cast<Lazy>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ addMemberFile(L->File, L->Sym);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+void SymbolTable::addLazy(<wbr>ArchiveFile *F, const Archive::Symbol Sym) {<br class="m_4374483495119771459gmail_msg">
+ StringRef Name = Sym.getName();<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(Name);<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted) {<br class="m_4374483495119771459gmail_msg">
+ replaceBody<Lazy>(S, F, Sym);<br class="m_4374483495119771459gmail_msg">
+ return;<br class="m_4374483495119771459gmail_msg">
+ }<br class="m_4374483495119771459gmail_msg">
+ auto *U = dyn_cast<Undefined>(S->body())<wbr>;<br class="m_4374483495119771459gmail_msg">
+ if (!U || U->WeakAlias)<br class="m_4374483495119771459gmail_msg">
+ return;<br class="m_4374483495119771459gmail_msg">
+ addMemberFile(F, Sym);<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+void SymbolTable::reportDuplicate(<wbr>Symbol *Existing, InputFile *NewFile) {<br class="m_4374483495119771459gmail_msg">
+ fatal("duplicate symbol: " + toString(*Existing->body()) + " in " +<br class="m_4374483495119771459gmail_msg">
+ toString(Existing->body()-><wbr>getFile()) + " and in " +<br class="m_4374483495119771459gmail_msg">
+ (NewFile ? toString(NewFile) : "(internal)"));<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addAbsolute(<wbr>StringRef N, COFFSymbolRef Sym) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(N);<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedAbsolute>(<wbr>S, N, Sym);<br class="m_4374483495119771459gmail_msg">
+ else if (!isa<DefinedCOFF>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, nullptr);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addAbsolute(<wbr>StringRef N, uint64_t VA) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(N);<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedAbsolute>(<wbr>S, N, VA);<br class="m_4374483495119771459gmail_msg">
+ else if (!isa<DefinedCOFF>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, nullptr);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addRelative(<wbr>StringRef N, uint64_t VA) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(N);<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedRelative>(<wbr>S, N, VA);<br class="m_4374483495119771459gmail_msg">
+ else if (!isa<DefinedCOFF>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, nullptr);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addRegular(<wbr>ObjectFile *F, COFFSymbolRef Sym,<br class="m_4374483495119771459gmail_msg">
+ SectionChunk *C) {<br class="m_4374483495119771459gmail_msg">
+ StringRef Name;<br class="m_4374483495119771459gmail_msg">
+ F->getCOFFObj()-><wbr>getSymbolName(Sym, Name);<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(Name);<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedRegular>(S, F, Sym, C);<br class="m_4374483495119771459gmail_msg">
+ else if (auto *R = dyn_cast<DefinedRegular>(S-><wbr>body())) {<br class="m_4374483495119771459gmail_msg">
+ if (!C->isCOMDAT() || !R->isCOMDAT())<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, F);<br class="m_4374483495119771459gmail_msg">
+ } else if (auto *B = dyn_cast<DefinedBitcode>(S-><wbr>body())) {<br class="m_4374483495119771459gmail_msg">
+ if (B->IsReplaceable)<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedRegular>(S, F, Sym, C);<br class="m_4374483495119771459gmail_msg">
+ else if (!C->isCOMDAT())<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, F);<br class="m_4374483495119771459gmail_msg">
+ } else<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedRegular>(S, F, Sym, C);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addBitcode(<wbr>BitcodeFile *F, StringRef N, bool IsReplaceable) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(N);<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body())) {<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedBitcode>(S, F, N, IsReplaceable);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+ }<br class="m_4374483495119771459gmail_msg">
+ if (isa<DefinedCommon>(S->body())<wbr>)<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+ if (IsReplaceable)<br class="m_4374483495119771459gmail_msg">
+ if (isa<DefinedRegular>(S->body()<wbr>) || isa<DefinedBitcode>(S->body())<wbr>)<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, F);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addCommon(<wbr>ObjectFile *F, COFFSymbolRef Sym,<br class="m_4374483495119771459gmail_msg">
+ CommonChunk *C) {<br class="m_4374483495119771459gmail_msg">
+ StringRef Name;<br class="m_4374483495119771459gmail_msg">
+ F->getCOFFObj()-><wbr>getSymbolName(Sym, Name);<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(Name);<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || !isa<DefinedCOFF>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedCommon>(S, F, Sym, C);<br class="m_4374483495119771459gmail_msg">
+ else if (auto *DC = dyn_cast<DefinedCommon>(S-><wbr>body()))<br class="m_4374483495119771459gmail_msg">
+ if (Sym.getValue() > DC->getSize())<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedCommon>(S, F, Sym, C);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addImportData(<wbr>StringRef N, ImportFile *F) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(N);<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ replaceBody<DefinedImportData><wbr>(S, N, F);<br class="m_4374483495119771459gmail_msg">
+ else if (!isa<DefinedCOFF>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, nullptr);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+Symbol *SymbolTable::addImportThunk(<wbr>StringRef Name, DefinedImportData *ID,<br class="m_4374483495119771459gmail_msg">
+ uint16_t Machine) {<br class="m_4374483495119771459gmail_msg">
+ Symbol *S;<br class="m_4374483495119771459gmail_msg">
+ bool WasInserted;<br class="m_4374483495119771459gmail_msg">
+ std::tie(S, WasInserted) = insert(Name);<br class="m_4374483495119771459gmail_msg">
+ S->IsUsedInRegularObj = true;<br class="m_4374483495119771459gmail_msg">
+ if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ replaceBody<<wbr>DefinedImportThunk>(S, Name, ID, Machine);<br class="m_4374483495119771459gmail_msg">
+ else if (!isa<DefinedCOFF>(S->body()))<br class="m_4374483495119771459gmail_msg">
+ reportDuplicate(S, nullptr);<br class="m_4374483495119771459gmail_msg">
+ return S;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Reads an archive member file pointed by a given symbol.<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::addMemberFile(<wbr>Lazy *Body) {<br class="m_4374483495119771459gmail_msg">
- InputFile *File = Body->getMember();<br class="m_4374483495119771459gmail_msg">
+void SymbolTable::addMemberFile(<wbr>ArchiveFile *F, const Archive::Symbol Sym) {<br class="m_4374483495119771459gmail_msg">
+ InputFile *File = F->getMember(&Sym);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// getMember returns an empty buffer if the member was already<br class="m_4374483495119771459gmail_msg">
// read from the library.<br class="m_4374483495119771459gmail_msg">
if (!File)<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
if (Config->Verbose)<br class="m_4374483495119771459gmail_msg">
- outs() << "Loaded " << toString(File) << " for " << Body->getName() << "\n";<br class="m_4374483495119771459gmail_msg">
+ outs() << "Loaded " << toString(File) << " for " << Sym.getName() << "\n";<br class="m_4374483495119771459gmail_msg">
addFile(File);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -274,7 +368,7 @@ StringRef SymbolTable::findByPrefix(Stri<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
StringRef SymbolTable::findMangle(<wbr>StringRef Name) {<br class="m_4374483495119771459gmail_msg">
if (Symbol *Sym = find(Name))<br class="m_4374483495119771459gmail_msg">
- if (!isa<Undefined>(Sym->Body))<br class="m_4374483495119771459gmail_msg">
+ if (!isa<Undefined>(Sym->body()))<br class="m_4374483495119771459gmail_msg">
return Name;<br class="m_4374483495119771459gmail_msg">
if (Config->Machine != I386)<br class="m_4374483495119771459gmail_msg">
return findByPrefix(("?" + Name + "@@Y").str());<br class="m_4374483495119771459gmail_msg">
@@ -288,34 +382,17 @@ StringRef SymbolTable::findMangle(String<br class="m_4374483495119771459gmail_msg">
return findByPrefix(("?" + Name.substr(1) + "@@Y").str());<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::mangleMaybe(<wbr>Undefined *U) {<br class="m_4374483495119771459gmail_msg">
- if (U->WeakAlias)<br class="m_4374483495119771459gmail_msg">
- return;<br class="m_4374483495119771459gmail_msg">
- if (!isa<Undefined>(U->repl()))<br class="m_4374483495119771459gmail_msg">
+void SymbolTable::mangleMaybe(<wbr>SymbolBody *B) {<br class="m_4374483495119771459gmail_msg">
+ auto *U = dyn_cast<Undefined>(B);<br class="m_4374483495119771459gmail_msg">
+ if (!U || U->WeakAlias)<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
StringRef Alias = findMangle(U->getName());<br class="m_4374483495119771459gmail_msg">
if (!Alias.empty())<br class="m_4374483495119771459gmail_msg">
U->WeakAlias = addUndefined(Alias);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-Undefined *SymbolTable::addUndefined(<wbr>StringRef Name) {<br class="m_4374483495119771459gmail_msg">
- auto *New = make<Undefined>(Name);<br class="m_4374483495119771459gmail_msg">
- addSymbol(New);<br class="m_4374483495119771459gmail_msg">
- if (auto *U = dyn_cast<Undefined>(New->repl(<wbr>)))<br class="m_4374483495119771459gmail_msg">
- return U;<br class="m_4374483495119771459gmail_msg">
- return New;<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
-DefinedRelative *SymbolTable::addRelative(<wbr>StringRef Name, uint64_t VA) {<br class="m_4374483495119771459gmail_msg">
- auto *New = make<DefinedRelative>(Name, VA);<br class="m_4374483495119771459gmail_msg">
- addSymbol(New);<br class="m_4374483495119771459gmail_msg">
- return New;<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
-DefinedAbsolute *SymbolTable::addAbsolute(<wbr>StringRef Name, uint64_t VA) {<br class="m_4374483495119771459gmail_msg">
- auto *New = make<DefinedAbsolute>(Name, VA);<br class="m_4374483495119771459gmail_msg">
- addSymbol(New);<br class="m_4374483495119771459gmail_msg">
- return New;<br class="m_4374483495119771459gmail_msg">
+SymbolBody *SymbolTable::addUndefined(<wbr>StringRef Name) {<br class="m_4374483495119771459gmail_msg">
+ return addUndefined(Name, nullptr, false)->body();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
void SymbolTable::printMap(llvm::<wbr>raw_ostream &OS) {<br class="m_4374483495119771459gmail_msg">
@@ -329,59 +406,19 @@ void SymbolTable::printMap(llvm::<wbr>raw_ost<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-void SymbolTable::<wbr>addCombinedLTOObject(<wbr>ObjectFile *Obj) {<br class="m_4374483495119771459gmail_msg">
- for (SymbolBody *Body : Obj->getSymbols()) {<br class="m_4374483495119771459gmail_msg">
- if (!Body->isExternal())<br class="m_4374483495119771459gmail_msg">
- continue;<br class="m_4374483495119771459gmail_msg">
- // We should not see any new undefined symbols at this point, but we'll<br class="m_4374483495119771459gmail_msg">
- // diagnose them later in reportRemainingUndefines().<br class="m_4374483495119771459gmail_msg">
- StringRef Name = Body->getName();<br class="m_4374483495119771459gmail_msg">
- Symbol *Sym = insert(Body);<br class="m_4374483495119771459gmail_msg">
- SymbolBody *Existing = Sym->Body;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- if (Existing == Body)<br class="m_4374483495119771459gmail_msg">
- continue;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- if (isa<DefinedBitcode>(Existing)<wbr>) {<br class="m_4374483495119771459gmail_msg">
- Sym->Body = Body;<br class="m_4374483495119771459gmail_msg">
- continue;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- if (isa<Undefined>(Body)) {<br class="m_4374483495119771459gmail_msg">
- if (auto *L = dyn_cast<Lazy>(Existing)) {<br class="m_4374483495119771459gmail_msg">
- // We may see new references to runtime library symbols such as __chkstk<br class="m_4374483495119771459gmail_msg">
- // here. These symbols must be wholly defined in non-bitcode files.<br class="m_4374483495119771459gmail_msg">
- addMemberFile(L);<br class="m_4374483495119771459gmail_msg">
- continue;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- int Comp = Existing->compare(Body);<br class="m_4374483495119771459gmail_msg">
- if (Comp == 0)<br class="m_4374483495119771459gmail_msg">
- fatal("LTO: unexpected duplicate symbol: " + Name);<br class="m_4374483495119771459gmail_msg">
- if (Comp < 0)<br class="m_4374483495119771459gmail_msg">
- Sym->Body = Body;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
void SymbolTable::<wbr>addCombinedLTOObjects() {<br class="m_4374483495119771459gmail_msg">
if (BitcodeFiles.empty())<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // Diagnose any undefined symbols early, but do not resolve weak externals,<br class="m_4374483495119771459gmail_msg">
- // as resolution breaks the invariant that each Symbol points to a unique<br class="m_4374483495119771459gmail_msg">
- // SymbolBody, which we rely on to replace DefinedBitcode symbols correctly.<br class="m_4374483495119771459gmail_msg">
- reportRemainingUndefines(/*<wbr>Resolve=*/false);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
// Create an object file and add it to the symbol table by replacing any<br class="m_4374483495119771459gmail_msg">
// DefinedBitcode symbols with the definitions in the object file.<br class="m_4374483495119771459gmail_msg">
LTOCodeGenerator CG(BitcodeFile::Context);<br class="m_4374483495119771459gmail_msg">
CG.setOptLevel(Config-><wbr>LTOOptLevel);<br class="m_4374483495119771459gmail_msg">
std::vector<ObjectFile *> Objs = createLTOObjects(&CG);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- for (ObjectFile *Obj : Objs)<br class="m_4374483495119771459gmail_msg">
- addCombinedLTOObject(Obj);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
size_t NumBitcodeFiles = BitcodeFiles.size();<br class="m_4374483495119771459gmail_msg">
+ for (ObjectFile *Obj : Objs)<br class="m_4374483495119771459gmail_msg">
+ Obj->parse();<br class="m_4374483495119771459gmail_msg">
run();<br class="m_4374483495119771459gmail_msg">
if (BitcodeFiles.size() != NumBitcodeFiles)<br class="m_4374483495119771459gmail_msg">
fatal("LTO: late loaded symbol created new bitcode reference");<br class="m_4374483495119771459gmail_msg">
@@ -390,25 +427,17 @@ void SymbolTable::<wbr>addCombinedLTOObjects(<br class="m_4374483495119771459gmail_msg">
// Combine and compile bitcode files and then return the result<br class="m_4374483495119771459gmail_msg">
// as a vector of regular COFF object files.<br class="m_4374483495119771459gmail_msg">
std::vector<ObjectFile *> SymbolTable::createLTOObjects(<wbr>LTOCodeGenerator *CG) {<br class="m_4374483495119771459gmail_msg">
- // All symbols referenced by non-bitcode objects must be preserved.<br class="m_4374483495119771459gmail_msg">
- for (ObjectFile *File : ObjectFiles)<br class="m_4374483495119771459gmail_msg">
- for (SymbolBody *Body : File->getSymbols())<br class="m_4374483495119771459gmail_msg">
- if (auto *S = dyn_cast<DefinedBitcode>(Body-<wbr>>repl()))<br class="m_4374483495119771459gmail_msg">
- CG->addMustPreserveSymbol(S-><wbr>getName());<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Likewise for bitcode symbols which we initially resolved to non-bitcode.<br class="m_4374483495119771459gmail_msg">
+ // All symbols referenced by non-bitcode objects, including GC roots, must be<br class="m_4374483495119771459gmail_msg">
+ // preserved. We must also replace bitcode symbols with undefined symbols so<br class="m_4374483495119771459gmail_msg">
+ // that they may be replaced with real definitions without conflicting.<br class="m_4374483495119771459gmail_msg">
for (BitcodeFile *File : BitcodeFiles)<br class="m_4374483495119771459gmail_msg">
- for (SymbolBody *Body : File->getSymbols())<br class="m_4374483495119771459gmail_msg">
- if (isa<DefinedBitcode>(Body) && !isa<DefinedBitcode>(Body-><wbr>repl()))<br class="m_4374483495119771459gmail_msg">
+ for (SymbolBody *Body : File->getSymbols()) {<br class="m_4374483495119771459gmail_msg">
+ if (!isa<DefinedBitcode>(Body))<br class="m_4374483495119771459gmail_msg">
+ continue;<br class="m_4374483495119771459gmail_msg">
+ if (Body->symbol()-><wbr>IsUsedInRegularObj)<br class="m_4374483495119771459gmail_msg">
CG->addMustPreserveSymbol(<wbr>Body->getName());<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Likewise for other symbols that must be preserved.<br class="m_4374483495119771459gmail_msg">
- for (Undefined *U : Config->GCRoot) {<br class="m_4374483495119771459gmail_msg">
- if (auto *S = dyn_cast<DefinedBitcode>(U-><wbr>repl()))<br class="m_4374483495119771459gmail_msg">
- CG->addMustPreserveSymbol(S-><wbr>getName());<br class="m_4374483495119771459gmail_msg">
- else if (auto *S = dyn_cast_or_null<<wbr>DefinedBitcode>(U-><wbr>getWeakAlias()))<br class="m_4374483495119771459gmail_msg">
- CG->addMustPreserveSymbol(S-><wbr>getName());<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
+ replaceBody<Undefined>(Body-><wbr>symbol(), Body->getName());<br class="m_4374483495119771459gmail_msg">
+ }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
CG->setModule(BitcodeFiles[0]<wbr>->takeModule());<br class="m_4374483495119771459gmail_msg">
for (unsigned I = 1, E = BitcodeFiles.size(); I != E; ++I)<br class="m_4374483495119771459gmail_msg">
@@ -438,7 +467,6 @@ std::vector<ObjectFile *> SymbolTable::c<br class="m_4374483495119771459gmail_msg">
auto *ObjFile = new ObjectFile(MemoryBufferRef(<wbr>Obj, "<LTO object>"));<br class="m_4374483495119771459gmail_msg">
Files.emplace_back(ObjFile);<br class="m_4374483495119771459gmail_msg">
ObjectFiles.push_back(<wbr>ObjFile);<br class="m_4374483495119771459gmail_msg">
- ObjFile->parse();<br class="m_4374483495119771459gmail_msg">
ObjFiles.push_back(ObjFile);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/SymbolTable.h<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>SymbolTable.h?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/SymbolTable.h (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/SymbolTable.h Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -22,6 +22,7 @@<br class="m_4374483495119771459gmail_msg">
#endif<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
#include <future><br class="m_4374483495119771459gmail_msg">
+#include <list><br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
namespace llvm {<br class="m_4374483495119771459gmail_msg">
struct LTOCodeGenerator;<br class="m_4374483495119771459gmail_msg">
@@ -31,6 +32,7 @@ namespace lld {<br class="m_4374483495119771459gmail_msg">
namespace coff {<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
class Chunk;<br class="m_4374483495119771459gmail_msg">
+class CommonChunk;<br class="m_4374483495119771459gmail_msg">
class Defined;<br class="m_4374483495119771459gmail_msg">
class DefinedAbsolute;<br class="m_4374483495119771459gmail_msg">
class DefinedRelative;<br class="m_4374483495119771459gmail_msg">
@@ -48,7 +50,9 @@ struct Symbol;<br class="m_4374483495119771459gmail_msg">
// conflicts. For example, obviously, a defined symbol is better than<br class="m_4374483495119771459gmail_msg">
// an undefined symbol. Or, if there's a conflict between a lazy and a<br class="m_4374483495119771459gmail_msg">
// undefined, it'll read an archive member to read a real definition<br class="m_4374483495119771459gmail_msg">
-// to replace the lazy symbol. The logic is implemented in resolve().<br class="m_4374483495119771459gmail_msg">
+// to replace the lazy symbol. The logic is implemented in the<br class="m_4374483495119771459gmail_msg">
+// add*() functions, which are called by input files as they are parsed.<br class="m_4374483495119771459gmail_msg">
+// There is one add* function per symbol type.<br class="m_4374483495119771459gmail_msg">
class SymbolTable {<br class="m_4374483495119771459gmail_msg">
public:<br class="m_4374483495119771459gmail_msg">
void addFile(InputFile *File);<br class="m_4374483495119771459gmail_msg">
@@ -57,9 +61,10 @@ public:<br class="m_4374483495119771459gmail_msg">
void run();<br class="m_4374483495119771459gmail_msg">
bool queueEmpty();<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // Print an error message on undefined symbols. If Resolve is true, try to<br class="m_4374483495119771459gmail_msg">
- // resolve any undefined symbols and update the symbol table accordingly.<br class="m_4374483495119771459gmail_msg">
- void reportRemainingUndefines(bool Resolve);<br class="m_4374483495119771459gmail_msg">
+ // Try to resolve any undefined symbols and update the symbol table<br class="m_4374483495119771459gmail_msg">
+ // accordingly, then print an error message for any remaining undefined<br class="m_4374483495119771459gmail_msg">
+ // symbols.<br class="m_4374483495119771459gmail_msg">
+ void reportRemainingUndefines();<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Returns a list of chunks of selected symbols.<br class="m_4374483495119771459gmail_msg">
std::vector<Chunk *> getChunks();<br class="m_4374483495119771459gmail_msg">
@@ -72,7 +77,7 @@ public:<br class="m_4374483495119771459gmail_msg">
// mangled symbol. This function tries to find a mangled name<br class="m_4374483495119771459gmail_msg">
// for U from the symbol table, and if found, set the symbol as<br class="m_4374483495119771459gmail_msg">
// a weak alias for U.<br class="m_4374483495119771459gmail_msg">
- void mangleMaybe(Undefined *U);<br class="m_4374483495119771459gmail_msg">
+ void mangleMaybe(SymbolBody *B);<br class="m_4374483495119771459gmail_msg">
StringRef findMangle(StringRef Name);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Print a layout map to OS.<br class="m_4374483495119771459gmail_msg">
@@ -91,36 +96,49 @@ public:<br class="m_4374483495119771459gmail_msg">
std::vector<ObjectFile *> ObjectFiles;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Creates an Undefined symbol for a given name.<br class="m_4374483495119771459gmail_msg">
- Undefined *addUndefined(StringRef Name);<br class="m_4374483495119771459gmail_msg">
- DefinedRelative *addRelative(StringRef Name, uint64_t VA);<br class="m_4374483495119771459gmail_msg">
- DefinedAbsolute *addAbsolute(StringRef Name, uint64_t VA);<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *addUndefined(StringRef Name);<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ Symbol *addRelative(StringRef N, uint64_t VA);<br class="m_4374483495119771459gmail_msg">
+ Symbol *addAbsolute(StringRef N, uint64_t VA);<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ Symbol *addUndefined(StringRef Name, InputFile *F, bool IsWeakAlias);<br class="m_4374483495119771459gmail_msg">
+ void addLazy(ArchiveFile *F, const Archive::Symbol Sym);<br class="m_4374483495119771459gmail_msg">
+ Symbol *addAbsolute(StringRef N, COFFSymbolRef S);<br class="m_4374483495119771459gmail_msg">
+ Symbol *addRegular(ObjectFile *F, COFFSymbolRef S, SectionChunk *C);<br class="m_4374483495119771459gmail_msg">
+ Symbol *addBitcode(BitcodeFile *F, StringRef N, bool IsReplaceable);<br class="m_4374483495119771459gmail_msg">
+ Symbol *addCommon(ObjectFile *F, COFFSymbolRef S, CommonChunk *C);<br class="m_4374483495119771459gmail_msg">
+ Symbol *addImportData(StringRef N, ImportFile *F);<br class="m_4374483495119771459gmail_msg">
+ Symbol *addImportThunk(StringRef Name, DefinedImportData *S,<br class="m_4374483495119771459gmail_msg">
+ uint16_t Machine);<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ void reportDuplicate(Symbol *Existing, InputFile *NewFile);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// A list of chunks which to be added to .rdata.<br class="m_4374483495119771459gmail_msg">
std::vector<Chunk *> LocalImportChunks;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
private:<br class="m_4374483495119771459gmail_msg">
- void readArchives();<br class="m_4374483495119771459gmail_msg">
+ void readArchive();<br class="m_4374483495119771459gmail_msg">
void readObjects();<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- void addSymbol(SymbolBody *New);<br class="m_4374483495119771459gmail_msg">
- void addLazy(Lazy *New, std::vector<Symbol *> *Accum);<br class="m_4374483495119771459gmail_msg">
- Symbol *insert(SymbolBody *New);<br class="m_4374483495119771459gmail_msg">
+ std::pair<Symbol *, bool> insert(StringRef Name);<br class="m_4374483495119771459gmail_msg">
StringRef findByPrefix(StringRef Prefix);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- void addMemberFile(Lazy *Body);<br class="m_4374483495119771459gmail_msg">
+ void addMemberFile(ArchiveFile *F, const Archive::Symbol Sym);<br class="m_4374483495119771459gmail_msg">
void addCombinedLTOObject(<wbr>ObjectFile *Obj);<br class="m_4374483495119771459gmail_msg">
std::vector<ObjectFile *> createLTOObjects(llvm::<wbr>LTOCodeGenerator *CG);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
llvm::DenseMap<StringRef, Symbol *> Symtab;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
std::vector<InputFile *> Files;<br class="m_4374483495119771459gmail_msg">
- std::vector<std::future<<wbr>ArchiveFile *>> ArchiveQueue;<br class="m_4374483495119771459gmail_msg">
- std::vector<std::future<<wbr>InputFile *>> ObjectQueue;<br class="m_4374483495119771459gmail_msg">
+ std::list<ArchiveFile *> ArchiveQueue;<br class="m_4374483495119771459gmail_msg">
+ std::vector<InputFile *> ObjectQueue;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
std::vector<BitcodeFile *> BitcodeFiles;<br class="m_4374483495119771459gmail_msg">
std::vector<SmallString<0>> Objs;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
+extern SymbolTable *Symtab;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
} // namespace coff<br class="m_4374483495119771459gmail_msg">
} // namespace lld<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Symbols.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>Symbols.cpp?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Symbols.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Symbols.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -18,8 +18,6 @@<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
using namespace llvm;<br class="m_4374483495119771459gmail_msg">
using namespace llvm::object;<br class="m_4374483495119771459gmail_msg">
-using llvm::sys::fs::identify_magic;<br class="m_4374483495119771459gmail_msg">
-using llvm::sys::fs::file_magic;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
namespace lld {<br class="m_4374483495119771459gmail_msg">
namespace coff {<br class="m_4374483495119771459gmail_msg">
@@ -49,120 +47,6 @@ InputFile *SymbolBody::getFile() {<br class="m_4374483495119771459gmail_msg">
return nullptr;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-// Returns 1, 0 or -1 if this symbol should take precedence<br class="m_4374483495119771459gmail_msg">
-// over the Other, tie or lose, respectively.<br class="m_4374483495119771459gmail_msg">
-int SymbolBody::compare(SymbolBody *Other) {<br class="m_4374483495119771459gmail_msg">
- Kind LK = kind(), RK = Other->kind();<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Normalize so that the smaller kind is on the left.<br class="m_4374483495119771459gmail_msg">
- if (LK > RK)<br class="m_4374483495119771459gmail_msg">
- return -Other->compare(this);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // First handle comparisons between two different kinds.<br class="m_4374483495119771459gmail_msg">
- if (LK != RK) {<br class="m_4374483495119771459gmail_msg">
- if (RK > LastDefinedKind) {<br class="m_4374483495119771459gmail_msg">
- if (LK == LazyKind && cast<Undefined>(Other)-><wbr>WeakAlias)<br class="m_4374483495119771459gmail_msg">
- return -1;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // The LHS is either defined or lazy and so it wins.<br class="m_4374483495119771459gmail_msg">
- assert((LK <= LastDefinedKind || LK == LazyKind) && "Bad kind!");<br class="m_4374483495119771459gmail_msg">
- return 1;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Bitcode has special complexities.<br class="m_4374483495119771459gmail_msg">
- if (RK == DefinedBitcodeKind) {<br class="m_4374483495119771459gmail_msg">
- auto *RHS = cast<DefinedBitcode>(Other);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- switch (LK) {<br class="m_4374483495119771459gmail_msg">
- case DefinedCommonKind:<br class="m_4374483495119771459gmail_msg">
- return 1;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- case DefinedRegularKind:<br class="m_4374483495119771459gmail_msg">
- // As an approximation, regular symbols win over bitcode symbols,<br class="m_4374483495119771459gmail_msg">
- // but we definitely have a conflict if the regular symbol is not<br class="m_4374483495119771459gmail_msg">
- // replaceable and neither is the bitcode symbol. We do not<br class="m_4374483495119771459gmail_msg">
- // replicate the rest of the symbol resolution logic here; symbol<br class="m_4374483495119771459gmail_msg">
- // resolution will be done accurately after lowering bitcode symbols<br class="m_4374483495119771459gmail_msg">
- // to regular symbols in addCombinedLTOObject().<br class="m_4374483495119771459gmail_msg">
- if (cast<DefinedRegular>(this)-><wbr>isCOMDAT() || RHS->IsReplaceable)<br class="m_4374483495119771459gmail_msg">
- return 1;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Fallthrough to the default of a tie otherwise.<br class="m_4374483495119771459gmail_msg">
- default:<br class="m_4374483495119771459gmail_msg">
- return 0;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Either of the object file kind will trump a higher kind.<br class="m_4374483495119771459gmail_msg">
- if (LK <= LastDefinedCOFFKind)<br class="m_4374483495119771459gmail_msg">
- return 1;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // The remaining kind pairs are ties amongst defined symbols.<br class="m_4374483495119771459gmail_msg">
- return 0;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Now handle the case where the kinds are the same.<br class="m_4374483495119771459gmail_msg">
- switch (LK) {<br class="m_4374483495119771459gmail_msg">
- case DefinedRegularKind: {<br class="m_4374483495119771459gmail_msg">
- auto *LHS = cast<DefinedRegular>(this);<br class="m_4374483495119771459gmail_msg">
- auto *RHS = cast<DefinedRegular>(Other);<br class="m_4374483495119771459gmail_msg">
- if (LHS->isCOMDAT() && RHS->isCOMDAT())<br class="m_4374483495119771459gmail_msg">
- return LHS->getFileIndex() < RHS->getFileIndex() ? 1 : -1;<br class="m_4374483495119771459gmail_msg">
- return 0;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- case DefinedCommonKind: {<br class="m_4374483495119771459gmail_msg">
- auto *LHS = cast<DefinedCommon>(this);<br class="m_4374483495119771459gmail_msg">
- auto *RHS = cast<DefinedCommon>(Other);<br class="m_4374483495119771459gmail_msg">
- if (LHS->getSize() == RHS->getSize())<br class="m_4374483495119771459gmail_msg">
- return LHS->getFileIndex() < RHS->getFileIndex() ? 1 : -1;<br class="m_4374483495119771459gmail_msg">
- return LHS->getSize() > RHS->getSize() ? 1 : -1;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- case DefinedBitcodeKind: {<br class="m_4374483495119771459gmail_msg">
- auto *LHS = cast<DefinedBitcode>(this);<br class="m_4374483495119771459gmail_msg">
- auto *RHS = cast<DefinedBitcode>(Other);<br class="m_4374483495119771459gmail_msg">
- // If both are non-replaceable, we have a tie.<br class="m_4374483495119771459gmail_msg">
- if (!LHS->IsReplaceable && !RHS->IsReplaceable)<br class="m_4374483495119771459gmail_msg">
- return 0;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Non-replaceable symbols win, but even two replaceable symboles don't<br class="m_4374483495119771459gmail_msg">
- // tie. If both symbols are replaceable, choice is arbitrary.<br class="m_4374483495119771459gmail_msg">
- if (RHS->IsReplaceable && LHS->IsReplaceable)<br class="m_4374483495119771459gmail_msg">
- return uintptr_t(LHS) < uintptr_t(RHS) ? 1 : -1;<br class="m_4374483495119771459gmail_msg">
- return LHS->IsReplaceable ? -1 : 1;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- case LazyKind: {<br class="m_4374483495119771459gmail_msg">
- // Don't tie, pick the earliest.<br class="m_4374483495119771459gmail_msg">
- auto *LHS = cast<Lazy>(this);<br class="m_4374483495119771459gmail_msg">
- auto *RHS = cast<Lazy>(Other);<br class="m_4374483495119771459gmail_msg">
- return LHS->getFileIndex() < RHS->getFileIndex() ? 1 : -1;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- case UndefinedKind: {<br class="m_4374483495119771459gmail_msg">
- auto *LHS = cast<Undefined>(this);<br class="m_4374483495119771459gmail_msg">
- auto *RHS = cast<Undefined>(Other);<br class="m_4374483495119771459gmail_msg">
- // Tie if both undefined symbols have different weak aliases.<br class="m_4374483495119771459gmail_msg">
- if (LHS->WeakAlias && RHS->WeakAlias) {<br class="m_4374483495119771459gmail_msg">
- if (LHS->WeakAlias->getName() != RHS->WeakAlias->getName())<br class="m_4374483495119771459gmail_msg">
- return 0;<br class="m_4374483495119771459gmail_msg">
- return uintptr_t(LHS) < uintptr_t(RHS) ? 1 : -1;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- return LHS->WeakAlias ? 1 : -1;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- case DefinedLocalImportKind:<br class="m_4374483495119771459gmail_msg">
- case DefinedImportThunkKind:<br class="m_4374483495119771459gmail_msg">
- case DefinedImportDataKind:<br class="m_4374483495119771459gmail_msg">
- case DefinedAbsoluteKind:<br class="m_4374483495119771459gmail_msg">
- case DefinedRelativeKind:<br class="m_4374483495119771459gmail_msg">
- // These all simply tie.<br class="m_4374483495119771459gmail_msg">
- return 0;<br class="m_4374483495119771459gmail_msg">
- }<br class="m_4374483495119771459gmail_msg">
- llvm_unreachable("unknown symbol kind");<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
COFFSymbolRef DefinedCOFF::getCOFFSymbol() {<br class="m_4374483495119771459gmail_msg">
size_t SymSize = File->getCOFFObj()-><wbr>getSymbolTableEntrySize();<br class="m_4374483495119771459gmail_msg">
if (SymSize == sizeof(coff_symbol16))<br class="m_4374483495119771459gmail_msg">
@@ -182,34 +66,10 @@ DefinedImportThunk::<wbr>DefinedImportThunk(S<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
-InputFile *Lazy::getMember() {<br class="m_4374483495119771459gmail_msg">
- MemoryBufferRef MBRef = File->getMember(&Sym);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // getMember returns an empty buffer if the member was already<br class="m_4374483495119771459gmail_msg">
- // read from the library.<br class="m_4374483495119771459gmail_msg">
- if (MBRef.getBuffer().empty())<br class="m_4374483495119771459gmail_msg">
- return nullptr;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- file_magic Magic = identify_magic(MBRef.<wbr>getBuffer());<br class="m_4374483495119771459gmail_msg">
- if (Magic == file_magic::coff_import_<wbr>library)<br class="m_4374483495119771459gmail_msg">
- return make<ImportFile>(MBRef);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- InputFile *Obj;<br class="m_4374483495119771459gmail_msg">
- if (Magic == file_magic::coff_object)<br class="m_4374483495119771459gmail_msg">
- Obj = make<ObjectFile>(MBRef);<br class="m_4374483495119771459gmail_msg">
- else if (Magic == file_magic::bitcode)<br class="m_4374483495119771459gmail_msg">
- Obj = make<BitcodeFile>(MBRef);<br class="m_4374483495119771459gmail_msg">
- else<br class="m_4374483495119771459gmail_msg">
- fatal("unknown file type: " + File->getName());<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- Obj->ParentName = File->getName();<br class="m_4374483495119771459gmail_msg">
- return Obj;<br class="m_4374483495119771459gmail_msg">
-}<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
Defined *Undefined::getWeakAlias() {<br class="m_4374483495119771459gmail_msg">
// A weak alias may be a weak alias to another symbol, so check recursively.<br class="m_4374483495119771459gmail_msg">
for (SymbolBody *A = WeakAlias; A; A = cast<Undefined>(A)->WeakAlias)<br class="m_4374483495119771459gmail_msg">
- if (auto *D = dyn_cast<Defined>(A->repl()))<br class="m_4374483495119771459gmail_msg">
+ if (auto *D = dyn_cast<Defined>(A))<br class="m_4374483495119771459gmail_msg">
return D;<br class="m_4374483495119771459gmail_msg">
return nullptr;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Symbols.h<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>Symbols.h?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Symbols.h (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Symbols.h Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -32,15 +32,8 @@ class ArchiveFile;<br class="m_4374483495119771459gmail_msg">
class BitcodeFile;<br class="m_4374483495119771459gmail_msg">
class InputFile;<br class="m_4374483495119771459gmail_msg">
class ObjectFile;<br class="m_4374483495119771459gmail_msg">
-class SymbolBody;<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
-// A real symbol object, SymbolBody, is usually accessed indirectly<br class="m_4374483495119771459gmail_msg">
-// through a Symbol. There's always one Symbol for each symbol name.<br class="m_4374483495119771459gmail_msg">
-// The resolver updates SymbolBody pointers as it resolves symbols.<br class="m_4374483495119771459gmail_msg">
-struct Symbol {<br class="m_4374483495119771459gmail_msg">
- explicit Symbol(SymbolBody *P) : Body(P) {}<br class="m_4374483495119771459gmail_msg">
- SymbolBody *Body;<br class="m_4374483495119771459gmail_msg">
-};<br class="m_4374483495119771459gmail_msg">
+struct Symbol;<br class="m_4374483495119771459gmail_msg">
+class SymbolTable;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// The base class for real symbol classes.<br class="m_4374483495119771459gmail_msg">
class SymbolBody {<br class="m_4374483495119771459gmail_msg">
@@ -78,21 +71,13 @@ public:<br class="m_4374483495119771459gmail_msg">
// Returns the file from which this symbol was created.<br class="m_4374483495119771459gmail_msg">
InputFile *getFile();<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // A SymbolBody has a backreference to a Symbol. Originally they are<br class="m_4374483495119771459gmail_msg">
- // doubly-linked. A backreference will never change. But the pointer<br class="m_4374483495119771459gmail_msg">
- // in the Symbol may be mutated by the resolver. If you have a<br class="m_4374483495119771459gmail_msg">
- // pointer P to a SymbolBody and are not sure whether the resolver<br class="m_4374483495119771459gmail_msg">
- // has chosen the object among other objects having the same name,<br class="m_4374483495119771459gmail_msg">
- // you can access P->Backref->Body to get the resolver's result.<br class="m_4374483495119771459gmail_msg">
- void setBackref(Symbol *P) { Backref = P; }<br class="m_4374483495119771459gmail_msg">
- SymbolBody *repl() { return Backref ? Backref->Body : this; }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- // Decides which symbol should "win" in the symbol table, this or<br class="m_4374483495119771459gmail_msg">
- // the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if<br class="m_4374483495119771459gmail_msg">
- // they are duplicate (conflicting) symbols.<br class="m_4374483495119771459gmail_msg">
- int compare(SymbolBody *Other);<br class="m_4374483495119771459gmail_msg">
+ Symbol *symbol();<br class="m_4374483495119771459gmail_msg">
+ const Symbol *symbol() const {<br class="m_4374483495119771459gmail_msg">
+ return const_cast<SymbolBody *>(this)->symbol();<br class="m_4374483495119771459gmail_msg">
+ }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
protected:<br class="m_4374483495119771459gmail_msg">
+ friend SymbolTable;<br class="m_4374483495119771459gmail_msg">
explicit SymbolBody(Kind K, StringRef N = "")<br class="m_4374483495119771459gmail_msg">
: SymbolKind(K), IsExternal(true), IsCOMDAT(false),<br class="m_4374483495119771459gmail_msg">
IsReplaceable(false), Name(N) {}<br class="m_4374483495119771459gmail_msg">
@@ -107,7 +92,6 @@ protected:<br class="m_4374483495119771459gmail_msg">
unsigned IsReplaceable : 1;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
StringRef Name;<br class="m_4374483495119771459gmail_msg">
- Symbol *Backref = nullptr;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// The base class for any defined symbols, including absolute symbols,<br class="m_4374483495119771459gmail_msg">
@@ -149,7 +133,6 @@ public:<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
ObjectFile *getFile() { return File; }<br class="m_4374483495119771459gmail_msg">
- int getFileIndex() { return File->Index; }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
COFFSymbolRef getCOFFSymbol();<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -195,7 +178,7 @@ public:<br class="m_4374483495119771459gmail_msg">
uint64_t getRVA() { return Data->getRVA(); }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
private:<br class="m_4374483495119771459gmail_msg">
- friend SymbolBody;<br class="m_4374483495119771459gmail_msg">
+ friend SymbolTable;<br class="m_4374483495119771459gmail_msg">
uint64_t getSize() { return Sym->Value; }<br class="m_4374483495119771459gmail_msg">
CommonChunk *Data;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
@@ -254,15 +237,12 @@ public:<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
static bool classof(const SymbolBody *S) { return S->kind() == LazyKind; }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- // Returns an object file for this symbol, or a nullptr if the file<br class="m_4374483495119771459gmail_msg">
- // was already returned.<br class="m_4374483495119771459gmail_msg">
- InputFile *getMember();<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- int getFileIndex() { return File->Index; }<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
ArchiveFile *File;<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
private:<br class="m_4374483495119771459gmail_msg">
+ friend SymbolTable;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+private:<br class="m_4374483495119771459gmail_msg">
const Archive::Symbol Sym;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -295,26 +275,22 @@ public:<br class="m_4374483495119771459gmail_msg">
// table in an output. The former has "__imp_" prefix.<br class="m_4374483495119771459gmail_msg">
class DefinedImportData : public Defined {<br class="m_4374483495119771459gmail_msg">
public:<br class="m_4374483495119771459gmail_msg">
- DefinedImportData(StringRef D, StringRef N, StringRef E,<br class="m_4374483495119771459gmail_msg">
- const coff_import_header *H)<br class="m_4374483495119771459gmail_msg">
- : Defined(DefinedImportDataKind, N), DLLName(D), ExternalName(E), Hdr(H) {<br class="m_4374483495119771459gmail_msg">
+ DefinedImportData(StringRef N, ImportFile *F)<br class="m_4374483495119771459gmail_msg">
+ : Defined(DefinedImportDataKind, N), File(F) {<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
static bool classof(const SymbolBody *S) {<br class="m_4374483495119771459gmail_msg">
return S->kind() == DefinedImportDataKind;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- uint64_t getRVA() { return Location->getRVA(); }<br class="m_4374483495119771459gmail_msg">
- StringRef getDLLName() { return DLLName; }<br class="m_4374483495119771459gmail_msg">
- StringRef getExternalName() { return ExternalName; }<br class="m_4374483495119771459gmail_msg">
- void setLocation(Chunk *AddressTable) { Location = AddressTable; }<br class="m_4374483495119771459gmail_msg">
- uint16_t getOrdinal() { return Hdr->OrdinalHint; }<br class="m_4374483495119771459gmail_msg">
+ uint64_t getRVA() { return File->Location->getRVA(); }<br class="m_4374483495119771459gmail_msg">
+ StringRef getDLLName() { return File->DLLName; }<br class="m_4374483495119771459gmail_msg">
+ StringRef getExternalName() { return File->ExternalName; }<br class="m_4374483495119771459gmail_msg">
+ void setLocation(Chunk *AddressTable) { File->Location = AddressTable; }<br class="m_4374483495119771459gmail_msg">
+ uint16_t getOrdinal() { return File->Hdr->OrdinalHint; }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
private:<br class="m_4374483495119771459gmail_msg">
- StringRef DLLName;<br class="m_4374483495119771459gmail_msg">
- StringRef ExternalName;<br class="m_4374483495119771459gmail_msg">
- const coff_import_header *Hdr;<br class="m_4374483495119771459gmail_msg">
- Chunk *Location = nullptr;<br class="m_4374483495119771459gmail_msg">
+ ImportFile *File;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// This class represents a symbol for a jump table entry which jumps<br class="m_4374483495119771459gmail_msg">
@@ -345,17 +321,17 @@ private:<br class="m_4374483495119771459gmail_msg">
class DefinedLocalImport : public Defined {<br class="m_4374483495119771459gmail_msg">
public:<br class="m_4374483495119771459gmail_msg">
DefinedLocalImport(StringRef N, Defined *S)<br class="m_4374483495119771459gmail_msg">
- : Defined(<wbr>DefinedLocalImportKind, N), Data(S) {}<br class="m_4374483495119771459gmail_msg">
+ : Defined(<wbr>DefinedLocalImportKind, N), Data(new LocalImportChunk(S)) {}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
static bool classof(const SymbolBody *S) {<br class="m_4374483495119771459gmail_msg">
return S->kind() == DefinedLocalImportKind;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
- uint64_t getRVA() { return Data.getRVA(); }<br class="m_4374483495119771459gmail_msg">
- Chunk *getChunk() { return &Data; }<br class="m_4374483495119771459gmail_msg">
+ uint64_t getRVA() { return Data->getRVA(); }<br class="m_4374483495119771459gmail_msg">
+ Chunk *getChunk() { return Data.get(); }<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
private:<br class="m_4374483495119771459gmail_msg">
- LocalImportChunk Data;<br class="m_4374483495119771459gmail_msg">
+ std::unique_ptr<<wbr>LocalImportChunk> Data;<br class="m_4374483495119771459gmail_msg">
};<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
class DefinedBitcode : public Defined {<br class="m_4374483495119771459gmail_msg">
@@ -363,6 +339,11 @@ class DefinedBitcode : public Defined {<br class="m_4374483495119771459gmail_msg">
public:<br class="m_4374483495119771459gmail_msg">
DefinedBitcode(BitcodeFile *F, StringRef N, bool IsReplaceable)<br class="m_4374483495119771459gmail_msg">
: Defined(DefinedBitcodeKind, N), File(F) {<br class="m_4374483495119771459gmail_msg">
+ // IsReplaceable tracks whether the bitcode symbol may be replaced with some<br class="m_4374483495119771459gmail_msg">
+ // other (defined, common or bitcode) symbol. This is the case for common,<br class="m_4374483495119771459gmail_msg">
+ // comdat and weak external symbols. We try to replace bitcode symbols with<br class="m_4374483495119771459gmail_msg">
+ // "real" symbols (see SymbolTable::add{Regular,<wbr>Bitcode}), and resolve the<br class="m_4374483495119771459gmail_msg">
+ // result against the real symbol from the combined LTO object.<br class="m_4374483495119771459gmail_msg">
this->IsReplaceable = IsReplaceable;<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
@@ -398,6 +379,45 @@ inline uint64_t Defined::getRVA() {<br class="m_4374483495119771459gmail_msg">
llvm_unreachable("unknown symbol kind");<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
+// A real symbol object, SymbolBody, is usually stored within a Symbol. There's<br class="m_4374483495119771459gmail_msg">
+// always one Symbol for each symbol name. The resolver updates the SymbolBody<br class="m_4374483495119771459gmail_msg">
+// stored in the Body field of this object as it resolves symbols. Symbol also<br class="m_4374483495119771459gmail_msg">
+// holds computed properties of symbol names.<br class="m_4374483495119771459gmail_msg">
+struct Symbol {<br class="m_4374483495119771459gmail_msg">
+ // True if this symbol was referenced by a regular (non-bitcode) object.<br class="m_4374483495119771459gmail_msg">
+ unsigned IsUsedInRegularObj : 1;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ // This field is used to store the Symbol's SymbolBody. This instantiation of<br class="m_4374483495119771459gmail_msg">
+ // AlignedCharArrayUnion gives us a struct with a char array field that is<br class="m_4374483495119771459gmail_msg">
+ // large and aligned enough to store any derived class of SymbolBody.<br class="m_4374483495119771459gmail_msg">
+ llvm::AlignedCharArrayUnion<<wbr>DefinedRegular, DefinedCommon, DefinedAbsolute,<br class="m_4374483495119771459gmail_msg">
+ DefinedRelative, Lazy, Undefined,<br class="m_4374483495119771459gmail_msg">
+ DefinedImportData, DefinedImportThunk,<br class="m_4374483495119771459gmail_msg">
+ DefinedLocalImport, DefinedBitcode><br class="m_4374483495119771459gmail_msg">
+ Body;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+ SymbolBody *body() {<br class="m_4374483495119771459gmail_msg">
+ return reinterpret_cast<SymbolBody *>(Body.buffer);<br class="m_4374483495119771459gmail_msg">
+ }<br class="m_4374483495119771459gmail_msg">
+ const SymbolBody *body() const { return const_cast<Symbol *>(this)->body(); }<br class="m_4374483495119771459gmail_msg">
+};<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+template <typename T, typename... ArgT><br class="m_4374483495119771459gmail_msg">
+void replaceBody(Symbol *S, ArgT &&... Arg) {<br class="m_4374483495119771459gmail_msg">
+ static_assert(sizeof(T) <= sizeof(S->Body), "Body too small");<br class="m_4374483495119771459gmail_msg">
+ static_assert(alignof(T) <= alignof(decltype(S->Body)),<br class="m_4374483495119771459gmail_msg">
+ "Body not aligned enough");<br class="m_4374483495119771459gmail_msg">
+ assert(static_cast<SymbolBody *>(static_cast<T *>(nullptr)) == nullptr &&<br class="m_4374483495119771459gmail_msg">
+ "Not a SymbolBody");<br class="m_4374483495119771459gmail_msg">
+ new (S->Body.buffer) T(std::forward<ArgT>(Arg)...);<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
+inline Symbol *SymbolBody::symbol() {<br class="m_4374483495119771459gmail_msg">
+ assert(isExternal());<br class="m_4374483495119771459gmail_msg">
+ return reinterpret_cast<Symbol *>(reinterpret_cast<char *>(this) -<br class="m_4374483495119771459gmail_msg">
+ offsetof(Symbol, Body));<br class="m_4374483495119771459gmail_msg">
+}<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
std::string toString(SymbolBody &B);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
} // namespace coff<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/COFF/Writer.cpp<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Writer.<wbr>cpp?rev=289280&r1=289279&r2=<wbr>289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/COFF/Writer.cpp (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/COFF/Writer.cpp Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -388,7 +388,7 @@ void Writer::createMiscChunks() {<br class="m_4374483495119771459gmail_msg">
if (!File->SEHCompat)<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
for (SymbolBody *B : File->SEHandlers)<br class="m_4374483495119771459gmail_msg">
- Handlers.insert(cast<Defined>(<wbr>B->repl()));<br class="m_4374483495119771459gmail_msg">
+ Handlers.insert(cast<Defined>(<wbr>B));<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
SEHTable.reset(new SEHTableChunk(Handlers));<br class="m_4374483495119771459gmail_msg">
@@ -428,7 +428,7 @@ void Writer::createImportTables() {<br class="m_4374483495119771459gmail_msg">
Sec->addChunk(C);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
if (!DelayIdata.empty()) {<br class="m_4374483495119771459gmail_msg">
- Defined *Helper = cast<Defined>(Config-><wbr>DelayLoadHelper->repl());<br class="m_4374483495119771459gmail_msg">
+ Defined *Helper = cast<Defined>(Config-><wbr>DelayLoadHelper);<br class="m_4374483495119771459gmail_msg">
DelayIdata.create(Helper);<br class="m_4374483495119771459gmail_msg">
OutputSection *Sec = createSection(".didat");<br class="m_4374483495119771459gmail_msg">
for (Chunk *C : DelayIdata.getChunks())<br class="m_4374483495119771459gmail_msg">
@@ -471,6 +471,10 @@ size_t Writer::addEntryToStringTable(<wbr>Str<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Optional<coff_symbol16> Writer::createSymbol(Defined *Def) {<br class="m_4374483495119771459gmail_msg">
+ // Relative symbols are unrepresentable in a COFF symbol table.<br class="m_4374483495119771459gmail_msg">
+ if (isa<DefinedRelative>(Def))<br class="m_4374483495119771459gmail_msg">
+ return None;<br class="m_4374483495119771459gmail_msg">
+<br class="m_4374483495119771459gmail_msg">
if (auto *D = dyn_cast<DefinedRegular>(Def))<br class="m_4374483495119771459gmail_msg">
if (!D->getChunk()->isLive())<br class="m_4374483495119771459gmail_msg">
return None;<br class="m_4374483495119771459gmail_msg">
@@ -497,7 +501,6 @@ Optional<coff_symbol16> Writer::createSy<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
switch (Def->kind()) {<br class="m_4374483495119771459gmail_msg">
case SymbolBody::<wbr>DefinedAbsoluteKind:<br class="m_4374483495119771459gmail_msg">
- case SymbolBody::<wbr>DefinedRelativeKind:<br class="m_4374483495119771459gmail_msg">
Sym.Value = Def->getRVA();<br class="m_4374483495119771459gmail_msg">
Sym.SectionNumber = IMAGE_SYM_ABSOLUTE;<br class="m_4374483495119771459gmail_msg">
break;<br class="m_4374483495119771459gmail_msg">
@@ -530,16 +533,13 @@ void Writer::<wbr>createSymbolAndStringTable(<br class="m_4374483495119771459gmail_msg">
Sec->setStringTableOff(<wbr>addEntryToStringTable(Name));<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
+ std::set<SymbolBody *> SeenSymbols;<br class="m_4374483495119771459gmail_msg">
for (lld::coff::ObjectFile *File : Symtab->ObjectFiles)<br class="m_4374483495119771459gmail_msg">
for (SymbolBody *B : File->getSymbols())<br class="m_4374483495119771459gmail_msg">
if (auto *D = dyn_cast<Defined>(B))<br class="m_4374483495119771459gmail_msg">
- if (Optional<coff_symbol16> Sym = createSymbol(D))<br class="m_4374483495119771459gmail_msg">
- OutputSymtab.push_back(*Sym);<br class="m_4374483495119771459gmail_msg">
-<br class="m_4374483495119771459gmail_msg">
- for (ImportFile *File : Symtab->ImportFiles)<br class="m_4374483495119771459gmail_msg">
- for (SymbolBody *B : File->getSymbols())<br class="m_4374483495119771459gmail_msg">
- if (Optional<coff_symbol16> Sym = createSymbol(cast<Defined>(B))<wbr>)<br class="m_4374483495119771459gmail_msg">
- OutputSymtab.push_back(*Sym);<br class="m_4374483495119771459gmail_msg">
+ if (SeenSymbols.insert(D).second)<br class="m_4374483495119771459gmail_msg">
+ if (Optional<coff_symbol16> Sym = createSymbol(D))<br class="m_4374483495119771459gmail_msg">
+ OutputSymtab.push_back(*Sym);<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
OutputSection *LastSection = OutputSections.back();<br class="m_4374483495119771459gmail_msg">
// We position the symbol table to be adjacent to the end of the last section.<br class="m_4374483495119771459gmail_msg">
@@ -630,7 +630,7 @@ template <typename PEHeaderTy> void Writ<br class="m_4374483495119771459gmail_msg">
PE->SizeOfImage = SizeOfImage;<br class="m_4374483495119771459gmail_msg">
PE->SizeOfHeaders = SizeOfHeaders;<br class="m_4374483495119771459gmail_msg">
if (!Config->NoEntry) {<br class="m_4374483495119771459gmail_msg">
- Defined *Entry = cast<Defined>(Config->Entry-><wbr>repl());<br class="m_4374483495119771459gmail_msg">
+ Defined *Entry = cast<Defined>(Config->Entry);<br class="m_4374483495119771459gmail_msg">
PE->AddressOfEntryPoint = Entry->getRVA();<br class="m_4374483495119771459gmail_msg">
// Pointer to thumb code must have the LSB set, so adjust it.<br class="m_4374483495119771459gmail_msg">
if (Config->Machine == ARMNT)<br class="m_4374483495119771459gmail_msg">
@@ -685,7 +685,7 @@ template <typename PEHeaderTy> void Writ<br class="m_4374483495119771459gmail_msg">
Dir[BASE_RELOCATION_TABLE].<wbr>Size = Sec->getVirtualSize();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
if (Symbol *Sym = Symtab->findUnderscore("_tls_<wbr>used")) {<br class="m_4374483495119771459gmail_msg">
- if (Defined *B = dyn_cast<Defined>(Sym->Body)) {<br class="m_4374483495119771459gmail_msg">
+ if (Defined *B = dyn_cast<Defined>(Sym->body())<wbr>) {<br class="m_4374483495119771459gmail_msg">
Dir[TLS_TABLE].<wbr>RelativeVirtualAddress = B->getRVA();<br class="m_4374483495119771459gmail_msg">
Dir[TLS_TABLE].Size = Config->is64()<br class="m_4374483495119771459gmail_msg">
? sizeof(object::coff_tls_<wbr>directory64)<br class="m_4374483495119771459gmail_msg">
@@ -697,7 +697,7 @@ template <typename PEHeaderTy> void Writ<br class="m_4374483495119771459gmail_msg">
Dir[DEBUG_DIRECTORY].Size = DebugDirectory->getSize();<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
if (Symbol *Sym = Symtab->findUnderscore("_load_<wbr>config_used")) {<br class="m_4374483495119771459gmail_msg">
- if (auto *B = dyn_cast<DefinedRegular>(Sym-><wbr>Body)) {<br class="m_4374483495119771459gmail_msg">
+ if (auto *B = dyn_cast<DefinedRegular>(Sym-><wbr>body())) {<br class="m_4374483495119771459gmail_msg">
SectionChunk *SC = B->getChunk();<br class="m_4374483495119771459gmail_msg">
assert(B->getRVA() >= SC->getRVA());<br class="m_4374483495119771459gmail_msg">
uint64_t OffsetInChunk = B->getRVA() - SC->getRVA();<br class="m_4374483495119771459gmail_msg">
@@ -754,8 +754,10 @@ void Writer::openFile(StringRef Path) {<br class="m_4374483495119771459gmail_msg">
void Writer::fixSafeSEHSymbols() {<br class="m_4374483495119771459gmail_msg">
if (!SEHTable)<br class="m_4374483495119771459gmail_msg">
return;<br class="m_4374483495119771459gmail_msg">
- Config->SEHTable->setRVA(<wbr>SEHTable->getRVA());<br class="m_4374483495119771459gmail_msg">
- Config->SEHCount->setVA(<wbr>SEHTable->getSize() / 4);<br class="m_4374483495119771459gmail_msg">
+ if (auto *T = dyn_cast<DefinedRelative>(<wbr>Config->SEHTable->body()))<br class="m_4374483495119771459gmail_msg">
+ T->setRVA(SEHTable->getRVA());<br class="m_4374483495119771459gmail_msg">
+ if (auto *C = dyn_cast<DefinedAbsolute>(<wbr>Config->SEHCount->body()))<br class="m_4374483495119771459gmail_msg">
+ C->setVA(SEHTable->getSize() / 4);<br class="m_4374483495119771459gmail_msg">
}<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
// Handles /section options to allow users to overwrite<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/test/COFF/include2.<wbr>test<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/include2.test?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/COFF/<wbr>include2.test?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/test/COFF/include2.<wbr>test (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/test/COFF/include2.<wbr>test Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -9,6 +9,6 @@<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
CHECK: include2.test.tmp1.obj<br class="m_4374483495119771459gmail_msg">
CHECK: include2.test.tmp2.lib<br class="m_4374483495119771459gmail_msg">
-CHECK: include2.test.tmp3.lib<br class="m_4374483495119771459gmail_msg">
CHECK: include2.test.tmp2.lib(<wbr>include2.test.tmp2.obj) for foo<br class="m_4374483495119771459gmail_msg">
+CHECK: include2.test.tmp3.lib<br class="m_4374483495119771459gmail_msg">
CHECK: include2.test.tmp3.lib(<wbr>include2.test.tmp3.obj) for bar<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/test/COFF/order.test<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/order.test?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/COFF/<wbr>order.test?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/test/COFF/order.test (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/test/COFF/order.test Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -11,5 +11,5 @@<br class="m_4374483495119771459gmail_msg">
CHECK: order.test.tmp1.obj<br class="m_4374483495119771459gmail_msg">
CHECK: order.test.tmp3.obj<br class="m_4374483495119771459gmail_msg">
CHECK: order.test.tmp2.lib<br class="m_4374483495119771459gmail_msg">
-CHECK: order.test.tmp3.lib<br class="m_4374483495119771459gmail_msg">
CHECK: order.test.tmp2.lib(order.<wbr>test.tmp2.obj) for foo<br class="m_4374483495119771459gmail_msg">
+CHECK: order.test.tmp3.lib<br class="m_4374483495119771459gmail_msg">
<br class="m_4374483495119771459gmail_msg">
Modified: lld/trunk/test/COFF/symtab.<wbr>test<br class="m_4374483495119771459gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/symtab.test?rev=289280&r1=289279&r2=289280&view=diff" rel="noreferrer" class="m_4374483495119771459gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/COFF/<wbr>symtab.test?rev=289280&r1=<wbr>289279&r2=289280&view=diff</a><br class="m_4374483495119771459gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_4374483495119771459gmail_msg">
--- lld/trunk/test/COFF/symtab.<wbr>test (original)<br class="m_4374483495119771459gmail_msg">
+++ lld/trunk/test/COFF/symtab.<wbr>test Fri Dec 9 15:55:24 2016<br class="m_4374483495119771459gmail_msg">
@@ -36,17 +36,17 @@<br class="m_4374483495119771459gmail_msg">
# CHECK-NEXT: AuxSymbolCount: 0<br class="m_4374483495119771459gmail_msg">
# CHECK-NEXT:</blockquote></div><span class="HOEnZb"><font color="#888888"><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Mike<br>Sent from phone</div></div>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div>