<div dir="ltr"><div dir="auto">Hans,</div><div dir="auto"><br></div><div>Apologies for not updating the list. I went through the formal <a href="http://reviews.llvm.org">reviews.llvm.org</a> process, and this has already been merged into trunk, I believe.</div><div><br></div><div>Regards,</div><div>Andrew<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Aug 8, 2018, 10:50 AM Hans Wennborg <<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+Rui and Peter<br>
<br>
On Wed, Jul 25, 2018 at 8:34 AM, Andrew Kelley via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" rel="noreferrer" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> Here's a fix:<br>
><br>
> --- a/lld/COFF/Driver.cpp<br>
> +++ b/lld/COFF/Driver.cpp<br>
> @@ -72,6 +72,9 @@ bool link(ArrayRef<const char *> Args, bool CanExitEarly,<br>
> raw_ostream &Diag) {<br>
> exitLld(errorCount() ? 1 : 0);<br>
><br>
> freeArena();<br>
> + ObjFile::Instances.clear();<br>
> + ImportFile::Instances.clear();<br>
> + BitcodeFile::Instances.clear();<br>
> return !errorCount();<br>
> }<br>
><br>
> I don't know how to make a test for this, since it depends on running LLD<br>
> twice in the same process.<br>
><br>
> Can I get some assistance trying to get this fix upstreamed?<br>
><br>
> On Wed, Jul 25, 2018 at 2:18 AM, Andrew Kelley <<a href="mailto:superjoe30@gmail.com" rel="noreferrer" target="_blank">superjoe30@gmail.com</a>> wrote:<br>
>><br>
>> If you call lld::coff::link twice, the second time gives this backtrace:<br>
>><br>
>> msvcp140d.dll!00007ffc35830806() Unknown<br>
>> > zig.exe!std::_Debug_pointer<lld::coff::Chunk * __ptr64<br>
>> > const>(lld::coff::Chunk * const * _Ptr, const wchar_t * _File, unsigned int<br>
>> > _Line) Line 926 C++<br>
>> zig.exe!std::_Debug_range2<lld::coff::Chunk * __ptr64 const *<br>
>> __ptr64>(lld::coff::Chunk * const * _First, lld::coff::Chunk * const *<br>
>> _Last, const wchar_t * _File, unsigned int _Line,<br>
>> std::random_access_iterator_tag __formal) Line 958 C++<br>
>> zig.exe!std::_Debug_range<lld::coff::Chunk * __ptr64 const *<br>
>> __ptr64>(lld::coff::Chunk * const * _First, lld::coff::Chunk * const *<br>
>> _Last, const wchar_t * _File, unsigned int _Line) Line 968 C++<br>
>> zig.exe!std::vector<lld::coff::Chunk *<br>
>> __ptr64,std::allocator<lld::coff::Chunk * __ptr64><br>
>> >::_Insert<lld::coff::Chunk * __ptr64 const *<br>
>> __ptr64>(std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<lld::coff::Chunk<br>
>> *> > > _Where, lld::coff::Chunk * const * _First, lld::coff::Chunk * const *<br>
>> _Last, std::forward_iterator_tag __formal) Line 1421 C++<br>
>> zig.exe!std::vector<lld::coff::Chunk *<br>
>> __ptr64,std::allocator<lld::coff::Chunk * __ptr64><br>
>> >::insert<lld::coff::Chunk * __ptr64 const *<br>
>> __ptr64>(std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<lld::coff::Chunk<br>
>> *> > > _Where, lld::coff::Chunk * const * _First, lld::coff::Chunk * const *<br>
>> _Last) Line 1376 C++<br>
>> zig.exe!lld::coff::SymbolTable::getChunks() Line 311 C++<br>
>> zig.exe!`anonymous namespace'::Writer::createSections() Line 340<br>
>> C++<br>
>> zig.exe!`anonymous namespace'::Writer::run() Line 288 C++<br>
>> zig.exe!lld::coff::writeResult() Line 166 C++<br>
>> zig.exe!lld::coff::LinkerDriver::link(llvm::ArrayRef<char const *><br>
>> ArgsArr) Line 1331 C++<br>
>> zig.exe!lld::coff::link(llvm::ArrayRef<char const *> Args, bool<br>
>> CanExitEarly, llvm::raw_ostream & Diag) Line 71 C++<br>
>> zig.exe!ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char * *<br>
>> args, unsigned __int64 arg_count, void(*)(void *, const char *, unsigned<br>
>> __int64) append_diagnostic, void * context) Line 837 C++<br>
>> zig.exe!zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char * *<br>
>> args, unsigned __int64 arg_count, Buf * diag) Line 435 C++<br>
>> zig.exe!codegen_link(CodeGen * g, const char * out_file) Line 1020<br>
>> C++<br>
>> zig.exe!main(int argc, char * * argv) Line 909 C++<br>
>> [External Code]<br>
>><br>
>> It appears that in this code, ObjFile::Instance is garbage data:<br>
>><br>
>> std::vector<Chunk *> SymbolTable::getChunks() {<br>
>> std::vector<Chunk *> Res;<br>
>> for (ObjFile *File : ObjFile::Instances) {<br>
>> ArrayRef<Chunk *> V = File->getChunks();<br>
>> Res.insert(Res.end(), V.begin(), V.end());<br>
>> }<br>
>> return Res;<br>
>> }<br>
>><br>
>> When I go to the definition of ObjFile::Instances, it appears to be static<br>
>> data:<br>
>><br>
>> static std::vector<ObjFile *> Instances;<br>
>><br>
>> It appears that LLD is not resetting this data between calls. On the other<br>
>> hand, lld::elf::link and lld::macho::link work no problem when called<br>
>> multiple times in the same process.<br>
>><br>
>> My understanding is that there is supposed to be an arena allocator, which<br>
>> is freed here:<br>
>><br>
>> bool link(ArrayRef<const char *> Args, bool CanExitEarly, raw_ostream<br>
>> &Diag) {<br>
>> // ...<br>
>><br>
>> Driver = make<LinkerDriver>();<br>
>> Driver->link(Args);<br>
>><br>
>> // Call exit() if we can to avoid calling destructors.<br>
>> if (CanExitEarly)<br>
>> exitLld(errorCount() ? 1 : 0);<br>
>><br>
>> freeArena(); // <------ here<br>
>> return !errorCount();<br>
>> }<br>
>><br>
>> Is there a simple fix for this?<br>
>><br>
>> Downstream issue reference: <a href="https://github.com/ziglang/zig/issues/1289" rel="noreferrer noreferrer" target="_blank">https://github.com/ziglang/zig/issues/1289</a><br>
>><br>
>> Thanks,<br>
>> Andrew<br>
><br>
><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" rel="noreferrer" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
</blockquote></div>