Do you already do the same for exported symbols?<br><br>On Wednesday, June 3, 2015, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Wed Jun 3 21:12:16 2015<br>
New Revision: 239005<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239005-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=rjjVAgbQNWKJBK7iIguRTT0_53KnBG18srsn8_upXC8&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=239005&view=rev</a><br>
Log:<br>
COFF: /include'd symbols must be preserved.<br>
<br>
Not only entry point symbol but also symbols specified by /include<br>
option must be preserved, as they will never be dead-stripped.<br>
<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10220&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=kyZiEIMLJsxLHYh_Ui2x47uhNxQ--j8cJFOI0b1dHLM&e=" target="_blank">http://reviews.llvm.org/D10220</a><br>
<br>
Modified:<br>
lld/trunk/COFF/Config.h<br>
lld/trunk/COFF/Driver.cpp<br>
lld/trunk/COFF/SymbolTable.cpp<br>
lld/trunk/COFF/Writer.cpp<br>
lld/trunk/COFF/Writer.h<br>
lld/trunk/test/COFF/lto.ll<br>
<br>
Modified: lld/trunk/COFF/Config.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Config.h-3Frev-3D239005-26r1-3D239004-26r2-3D239005-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=K4TF_INjmEaVNgrccVC_DMnc8e7UE6lfd78hNQ0OsZk&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=239005&r1=239004&r2=239005&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/COFF/Config.h (original)<br>
+++ lld/trunk/COFF/Config.h Wed Jun 3 21:12:16 2015<br>
@@ -27,7 +27,10 @@ public:<br>
llvm::COFF::MachineTypes MachineType = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;<br>
bool Verbose = false;<br>
WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;<br>
- std::string EntryName;<br>
+ StringRef EntryName;<br>
+<br>
+ // Symbols in this set are considered as live by the garbage collector.<br>
+ std::set<StringRef> GCRoots;<br>
<br>
std::set<StringRef> NoDefaultLibs;<br>
bool NoDefaultLibAll = false;<br>
<br>
Modified: lld/trunk/COFF/Driver.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Driver.cpp-3Frev-3D239005-26r1-3D239004-26r2-3D239005-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=0qLzTyjbiszNDxcqHHV3CdleMULQu_Qt-kSGznloipU&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=239005&r1=239004&r2=239005&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/COFF/Driver.cpp (original)<br>
+++ lld/trunk/COFF/Driver.cpp Wed Jun 3 21:12:16 2015<br>
@@ -312,8 +312,11 @@ bool LinkerDriver::link(int Argc, const<br>
<br>
// Add undefined symbols given via the command line.<br>
// (/include is equivalent to Unix linker's -u option.)<br>
- for (auto *Arg : Args->filtered(OPT_incl))<br>
- Symtab.addUndefined(Arg->getValue());<br>
+ for (auto *Arg : Args->filtered(OPT_incl)) {<br>
+ StringRef Sym = Arg->getValue();<br>
+ Symtab.addUndefined(Sym);<br>
+ Config->GCRoots.insert(Sym);<br>
+ }<br>
<br>
// Parse all input files and put all symbols to the symbol table.<br>
// The symbol table will take care of name resolution.<br>
@@ -362,11 +365,14 @@ bool LinkerDriver::link(int Argc, const<br>
}<br>
Config->EntryName = EntryOrErr.get();<br>
}<br>
+ Config->GCRoots.insert(Config->EntryName);<br>
<br>
// Make sure we have resolved all symbols.<br>
if (Symtab.reportRemainingUndefines())<br>
return false;<br>
<br>
+ // Do LTO by compiling bitcode input files to a native COFF file<br>
+ // then link that file.<br>
if (auto EC = Symtab.addCombinedLTOObject()) {<br>
llvm::errs() << EC.message() << "\n";<br>
return false;<br>
<br>
Modified: lld/trunk/COFF/SymbolTable.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_SymbolTable.cpp-3Frev-3D239005-26r1-3D239004-26r2-3D239005-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=9utY6X70O6REk0KvhBdvCd6pz212nlLMARuxLBcvRQM&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=239005&r1=239004&r2=239005&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/COFF/SymbolTable.cpp (original)<br>
+++ lld/trunk/COFF/SymbolTable.cpp Wed Jun 3 21:12:16 2015<br>
@@ -227,20 +227,17 @@ std::error_code SymbolTable::addCombined<br>
return std::error_code();<br>
<br>
llvm::LTOCodeGenerator CG;<br>
- std::set<DefinedBitcode *> PreservedBitcodeSymbols;<br>
<br>
// All symbols referenced by non-bitcode objects must be preserved.<br>
for (std::unique_ptr<ObjectFile> &File : ObjectFiles)<br>
for (SymbolBody *Body : File->getSymbols())<br>
if (auto *S = dyn_cast<DefinedBitcode>(Body->getReplacement()))<br>
- PreservedBitcodeSymbols.insert(S);<br>
+ CG.addMustPreserveSymbol(S->getName());<br>
<br>
- // Likewise for the linker-generated reference to the entry point.<br>
- if (auto *S = dyn_cast<DefinedBitcode>(Symtab[Config->EntryName]->Body))<br>
- PreservedBitcodeSymbols.insert(S);<br>
-<br>
- for (DefinedBitcode *S : PreservedBitcodeSymbols)<br>
- CG.addMustPreserveSymbol(S->getName());<br>
+ // Likewise for other symbols that must be preserved.<br>
+ for (StringRef Name : Config->GCRoots)<br>
+ if (isa<DefinedBitcode>(Symtab[Name]->Body))<br>
+ CG.addMustPreserveSymbol(Name);<br>
<br>
CG.setModule(BitcodeFiles[0]->releaseModule());<br>
for (unsigned I = 1, E = BitcodeFiles.size(); I != E; ++I)<br>
<br>
Modified: lld/trunk/COFF/Writer.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Writer.cpp-3Frev-3D239005-26r1-3D239004-26r2-3D239005-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=9P-TWlCZmH10NgWE6ECJQBYtS0MVxRYtS-Nfem6FA0Q&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=239005&r1=239004&r2=239005&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/COFF/Writer.cpp (original)<br>
+++ lld/trunk/COFF/Writer.cpp Wed Jun 3 21:12:16 2015<br>
@@ -87,8 +87,8 @@ void OutputSection::writeHeader(uint8_t<br>
}<br>
<br>
void Writer::markLive() {<br>
- Entry = cast<Defined>(Symtab->find(Config->EntryName));<br>
- Entry->markLive();<br>
+ for (StringRef Name : Config->GCRoots)<br>
+ cast<Defined>(Symtab->find(Name))->markLive();<br>
for (Chunk *C : Symtab->getChunks())<br>
if (C->isRoot())<br>
C->markLive();<br>
@@ -291,6 +291,7 @@ void Writer::writeHeader() {<br>
PE->Subsystem = Config->Subsystem;<br>
PE->SizeOfImage = SizeOfImage;<br>
PE->SizeOfHeaders = SizeOfHeaders;<br>
+ Defined *Entry = cast<Defined>(Symtab->find(Config->EntryName));<br>
PE->AddressOfEntryPoint = Entry->getRVA();<br>
PE->SizeOfStackReserve = Config->StackReserve;<br>
PE->SizeOfStackCommit = Config->StackCommit;<br>
<br>
Modified: lld/trunk/COFF/Writer.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Writer.h-3Frev-3D239005-26r1-3D239004-26r2-3D239005-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=8axEGmozzhrYk-B5u41XvukAUoTVk4EMrqIJR-2AHXw&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.h?rev=239005&r1=239004&r2=239005&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/COFF/Writer.h (original)<br>
+++ lld/trunk/COFF/Writer.h Wed Jun 3 21:12:16 2015<br>
@@ -98,7 +98,6 @@ private:<br>
uint32_t ImportDirectoryTableSize = 0;<br>
uint32_t ImportAddressTableSize = 0;<br>
<br>
- Defined *Entry;<br>
uint64_t FileSize;<br>
uint64_t SizeOfImage;<br>
uint64_t SizeOfHeaders;<br>
<br>
Modified: lld/trunk/test/COFF/lto.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_test_COFF_lto.ll-3Frev-3D239005-26r1-3D239004-26r2-3D239005-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=_9ljHAvy8ftI5NWOjwR-mRFEpotI3EIJbtyYEPolKIo&s=jL0ncw3ipulSIASZt2l6Za5C7Cii62U2pjFoPG1vOvw&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lto.ll?rev=239005&r1=239004&r2=239005&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/COFF/lto.ll (original)<br>
+++ lld/trunk/test/COFF/lto.ll Wed Jun 3 21:12:16 2015<br>
@@ -8,10 +8,10 @@<br>
; RUN: rm -f %T/foo.lib<br>
; RUN: llvm-ar cru %T/foo.lib %T/foo.obj<br>
<br>
-; RUN: lld -flavor link2 /out:%T/main.exe /entry:main /subsystem:console %T/main.lto.obj %T/foo.lto.obj<br>
+; RUN: lld -flavor link2 /out:%T/main.exe /entry:main /include:f2 /subsystem:console %T/main.lto.obj %T/foo.lto.obj<br>
; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-11 %s<br>
; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-11 %s<br>
-; RUN: lld -flavor link2 /out:%T/main.exe /entry:main /subsystem:console %T/main.lto.obj %T/foo.lto.lib<br>
+; RUN: lld -flavor link2 /out:%T/main.exe /entry:main /include:f2 /subsystem:console %T/main.lto.obj %T/foo.lto.lib<br>
; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-11 %s<br>
; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-11 %s<br>
<br>
@@ -34,6 +34,21 @@<br>
; TEXT-11-NEXT: .text:<br>
; TEXT-11-NEXT: xorl %eax, %eax<br>
; TEXT-11-NEXT: retq<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: int3<br>
+; TEXT-11-NEXT: movl $2, %eax<br>
+; TEXT-11-NEXT: retq<br>
<br>
; HEADERS-01: AddressOfEntryPoint: 0x1000<br>
; TEXT-01: Disassembly of section .text:<br>
@@ -79,3 +94,13 @@ define i32 @main() {<br>
}<br>
<br>
declare void @foo()<br>
+<br>
+$f1 = comdat any<br>
+define i32 @f1() comdat($f1) {<br>
+ ret i32 1<br>
+}<br>
+<br>
+$f2 = comdat any<br>
+define i32 @f2() comdat($f2) {<br>
+ ret i32 2<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'llvm-commits@cs.uiuc.edu')">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote>