<div dir="ltr">Hi Reid, Thanks for the heads up. I'll try to compile everything with Clang + LLD.<div><br></div><div>Peter, I am using a MinGW target, so Clang invokes ld.lld instead of lld-link. But the MinGW driver doesn't seem to support --reproduce.</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 7, 2018 at 2:52 PM Peter Collingbourne <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Can you upload a reproducer? You can create it using the /linkrepro flag.<div><br></div><div>Peter</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 7, 2018 at 2:50 PM, Reid Kleckner via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>GCC does comdats completely differently from the spec. Since you contacted me about this off of the mailing list, I started investigating what they do, and it is completely different. It's basically an alternative comdat ABI. I guess because GCC never considered it important to implement C++ ABI compatibility, they just did their own thing with comdats, since they aren't really part of the C ABI.<br></div><div><br></div><div>Anyway, if we want to be C++ ABI compatible with GCC+binutils on Windows, there will be a lot of work to do. It's not a small patch here or there, it requires more research. We should discuss it in full.</div><div><br></div><div>I support recovering from invalid COFF files to avoid crashes in any way we can, though, so this patch might still be good.</div><div><br></div><div class="gmail_quote"><div><div class="m_1008007986962180012h5"><div dir="ltr">On Thu, Jun 7, 2018 at 2:44 PM Pirama Arumuga Nainar via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_1008007986962180012h5"><div dir="ltr">I encountered a segfault when using lld to cross-compile for Windows (+MinGW) from Linux. The problem happens with objects built by gcc. The problem is that ObjFile::CreateRegular considers a PendingComdat to be valid (and later causes an illegal pointer dereference). The following patch fixes the crash:<div><br></div><div><div>diff --git a/COFF/InputFiles.cpp b/COFF/InputFiles.cpp</div><div>index 9e2345b0a..f47d612df 100644</div><div>--- a/COFF/InputFiles.cpp</div><div>+++ b/COFF/InputFiles.cpp</div><div>@@ -229,11 +229,11 @@ Symbol *ObjFile::createRegular(COFFSymbolRef Sym) {</div><div> if (Sym.isExternal()) {</div><div> StringRef Name;</div><div> COFFObj->getSymbolName(Sym, Name);</div><div>- if (SC)</div><div>+ if (SC && SC != PendingComdat)</div><div> return Symtab->addRegular(this, Name, Sym.getGeneric(), SC);</div><div> return Symtab->addUndefined(Name, this, false);</div><div> }</div><div>- if (SC)</div><div>+ if (SC && SC != PendingComdat)</div><div> return make<DefinedRegular>(this, /*Name*/ "", false,</div><div> /*IsExternal*/ false, Sym.getGeneric(), SC);</div><div> return nullptr;</div></div><div><br></div><div>I can upload this to Phabricator in case this is the right fix. If not, I'll upload a reproducer for further investigation. (I omitted it to avoid manually packaging a whole set of object files - I think --reproduce=<repro> doesn't work on Windows yet).</div><div><br></div><div>For reference, here's the segfault:</div><div><div>#0 0x0000000000500999 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /ssd2/pirama/ll$</div><div>m-upstream/llvm/lib/Support/Unix/Signals.inc:488:11 </div><div>#1 0x0000000000500b49 PrintStackTraceSignalHandler(void*) /ssd2/pirama/llvm-upstream$</div><div>llvm/lib/Support/Unix/Signals.inc:552:1 </div><div>#2 0x00000000004ff1d6 llvm::sys::RunSignalHandlers() /ssd2/pirama/llvm-upstream/llvm$</div><div>lib/Support/Signals.cpp:66:5 </div><div>#3 0x0000000000500eb7 SignalHandler(int) /ssd2/pirama/llvm-upstream/llvm/lib/Support$</div><div>Unix/Signals.inc:351:1 </div><div>#4 0x00007fc7bfaff0c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x110c0)</div><div>#5 0x00000000005fe370 lld::coff::DefinedRegular::getChunk() const /ssd2/pirama/llvm-$</div><div>pstream/llvm/tools/lld/COFF/Symbols.h:169:43 </div><div>#6 0x00000000005fe082 lld::coff::Defined::getChunk() /ssd2/pirama/llvm-upstream/llvm$</div><div>tools/lld/COFF/Symbols.h:381:5 </div><div>#7 0x0000000000656114 (anonymous namespace)::Writer::createSymbol(lld::coff::Defined$</div><div>) /ssd2/pirama/llvm-upstream/llvm/tools/lld/COFF/Writer.cpp:617:42 </div><div>#8 0x000000000064c7df (anonymous namespace)::Writer::createSymbolAndStringTable() /s$</div><div>d2/pirama/llvm-upstream/llvm/tools/lld/COFF/Writer.cpp:0:43 </div><div>#9 0x00000000006499f9 (anonymous namespace)::Writer::run() /ssd2/pirama/llvm-upstrea$</div><div>/llvm/tools/lld/COFF/Writer.cpp:342:3 </div><div>#10 0x0000000000649843 lld::coff::writeResult() /ssd2/pirama/llvm-upstream/llvm/tool$</div><div>/lld/COFF/Writer.cpp:232:31 </div><div>#11 0x00000000005d1268 lld::coff::LinkerDriver::link(llvm::ArrayRef<char const*>) /s$</div><div>d2/pirama/llvm-upstream/llvm/tools/lld/COFF/Driver.cpp:1536:3</div><div>#12 0x00000000005c8687 lld::coff::link(llvm::ArrayRef<char const*>, bool, llvm::raw_$</div><div>stream&) /ssd2/pirama/llvm-upstream/llvm/tools/lld/COFF/Driver.cpp:75:7</div><div>#13 0x0000000000946db0 lld::mingw::link(llvm::ArrayRef<char const*>, llvm::raw_ostrea</div><div>m&) /ssd2/pirama/llvm-upstream/llvm/tools/lld/MinGW/Driver.cpp:255:10</div><div>#14 0x00000000004d02a8 main /ssd2/pirama/llvm-upstream/llvm/tools/lld/tools/lld/lld.c</div><div>pp:121:14</div></div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_1008007986962180012gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div>
</blockquote></div>