<div dir="ltr">Well, given that link.exe does not produce deterministic output (i..e you run it twice and get different results), it would certainly be hard to make lld produce the same non-deterministic output :)<div><br></div><div>But if you just want a linker that is compatible with link.exe and produces the same output *compared to itself* every time you run it, then yes you can probably get there with lld-link (although as mentioned earlier, if you want to produce a working PDB file you will have some pretty hairy work ahead of you)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 2, 2019 at 4:59 AM Paul Moran <<a href="mailto:bankybooks@gmail.com">bankybooks@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Yeah ideally I wanted the tool chain to just produce the same binary. I suppose running a disassembly step could work to ensure that only offsets to imports have changed. But I think this would still give me issues with comparing data sections since offsets to constant strings and globals could also be swapped around too?<div><br></div><div>I believe in GCC this can be "fixed" by using a linker script. MSVC doesn't have anything like this however.</div><div><br></div><div>I haven't looked at lld-links binary output yet - but I would have imagined that the import table format and the way that global data is created must be done in the same way? It would just be orderings/lack of "rich" header and other things that lld-link does differently?</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 2, 2019 at 9:33 AM Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I think it would be quite hard to hack lld so that the linker produces the same output as Microsoft link.exe. Although lld can produce the semantically same executables as link.exe, every detail is different. If you are working on it as a long-term project, it is probably doable, but it doesn't seem like it is something you can easily hack.<div><br></div><div>Have you considered disassembling the original binary and your new binary and compare the two as text files? If only imported functions are different, the text outputs will be mostly the same, and you would be able to tell if you succeeded recovering the source code.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 2, 2019 at 5:18 PM Paul Moran <<a href="mailto:bankybooks@gmail.com" target="_blank">bankybooks@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">That isn't the case but my idea is that I can hack a copy of lld-link to produce the same output. Since the other option is to use the MSVC6 linker which will do things like randomly re-order the order of imported functions and the likes. I can't change that without doing something crazy like reverse engineering the linker and patching something in there to force a particular ordering. I suspect that the imported function order isn't the only thing that it might change on a rebuild.<div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 2, 2019 at 8:36 AM Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Tue, Oct 1, 2019 at 8:18 PM Paul Moran <<a href="mailto:bankybooks@gmail.com" target="_blank">bankybooks@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I have the most edge of edge use cases :). I am recovering the lost source code to an application built with MSVC 6. However because I want to produce byte for byte exact output I need to ensure that the import table is in the same order as the original binary.</div></blockquote><div><br></div><div>I'm not sure if I follow this part -- if you build an executable using lld-link and compare it with an executable built with MSVC linker, they are almost always different. lld-link doesn't attempt to produce the byte-wise same outputs as MSVC. So, if you want to compare lld-link-produced output, the other file needs to be built with lld-link too. But is that the case?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Since the MSVC6 linker has no way of doing this I figured I could hack this feature into lld-link. I need to also set the PDB path in the debug data but a newer version of the MS linker can do this and I believe lld-link already supports this too.<div><br></div><div> </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 1, 2019 at 8:58 AM Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Out of curiosity, why do you want to use lld-link with a compiler that was released 20 years ago?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 1, 2019 at 7:02 AM Zachary Turner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I would expect it to be able to link the object file, even if it ignored debug info. It's a bit strange that it complains about bad file magic. <div><br></div><div>It might be tricky to get debug information working and produce a valid PDB file since that is pretty old and the format has changed both with how it was stored in the object file itself as well as the format of the PDB file. </div><div><br></div><div>My guess is that the "magic" it's complaining about is not the magic of the object file itself but rather the first 4 bytes of the .debug$S (or was it the .debug$T?) section. Perhaps a simple fix in this case is that instead of erroring out if we encounter an "older" magic, we just link as if debug info was not present to begin with.</div><div><br></div><div>This will at least make it work. If you want to actually consume the debug info though, you're in for a fun ride :)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 30, 2019 at 2:19 PM Paul Moran via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">It sounds like perhaps it might mostly work with some tweaks - given its complaining about bad file magic. I'll see if I can get lld-link to build locally and hack out the magic checks to see if it works.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 30, 2019 at 10:14 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 30, 2019 at 2:07 PM Paul Moran <<a href="mailto:bankybooks@gmail.com" target="_blank">bankybooks@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">MSVC 6 is 1998 not 1989 :)<br></div></blockquote><div><br>Ah, I just glanced briefly at the Wikipedia article ( <a href="https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B" target="_blank">https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B</a> ) & misread the "C 6.0" and didn't notice it was distinct from "Visual C++ 6.0" - thanks for the catch!<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br>The latest MSVC linker can link these object files. Is this just because it has support for C13 types and some other code path for whatever MSVC6 uses? After some digging around it appears to be this format:<br><br><a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#coff-file-header-object-and-image" target="_blank">https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#coff-file-header-object-and-image</a> <div><br></div><div>Which is COFF object file format? Does lld link support this format?<br></div></div></blockquote><div><br>COFF is still the windows object file format, and the Windows support in lld is COFF support, yeah. I guess there might be some format variations that haven't been implemented in lld, though. It's mostly an "on demand" sort of approach.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 30, 2019 at 7:39 PM Alexandre Ganea <<a href="mailto:alexandre.ganea@ubisoft.com" target="_blank">alexandre.ganea@ubisoft.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="FR-CA">
<div>
<p class="MsoNormal"><span lang="EN-CA" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The CodeView library in LLVM only supports Codeview C13 types, that is, MSVC 7.0 / Visual Studio 2002 or after.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span lang="FR" style="font-size:11pt;font-family:Calibri,sans-serif">De :</span></b><span lang="FR" style="font-size:11pt;font-family:Calibri,sans-serif"> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>
<b>De la part de</b> David Blaikie via llvm-dev<br>
<b>Envoyé :</b> September 30, 2019 2:38 PM<br>
<b>À :</b> Paul Moran <<a href="mailto:bankybooks@gmail.com" target="_blank">bankybooks@gmail.com</a>>; Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>><br>
<b>Cc :</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Objet :</b> Re: [llvm-dev] lld-link with MSVC6 object files<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">MSVC 6 as in the Visual Studio released in 1989? Yes, I imagine that's a bit outside the intended support window.<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, Sep 30, 2019 at 11:18 AM Paul Moran via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:Arial,sans-serif;color:rgb(29,28,29)">Hi,</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:Arial,sans-serif;color:rgb(29,28,29)">I have a question about lld-link. What obj file formats should it support? When I try to use an obj from msvc 6.0 it complains that the file magic is not valid.</span><u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:Arial,sans-serif;color:rgb(29,28,29)">However when running </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(224,30,90)">llvm-objdump</span> it reports:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<pre style="margin-right:0cm;margin-bottom:3pt;margin-left:0cm;box-sizing:inherit;font-variant-ligatures:none;white-space:pre-wrap;border-radius:4px"><span style="font-size:9pt;font-family:Consolas;color:rgb(29,28,29)">test1.obj: file format COFF-i386<br><br>Disassembly of section .text:<br>0000000000000000 _main:<br> 0: 68 00 00 00 00 pushl $0<br> 5: e8 00 00 00 00 calll 0 <_main+0xa><br> a: 83 c4 04 addl $4, %esp<br> d: 33 c0 xorl %eax, %eax<u></u><u></u></span></pre>
<div>
<p class="MsoNormal"><span style="font-size:9pt;font-family:Consolas;color:rgb(29,28,29)"> f: c3 retl</span> <u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:Arial,sans-serif;color:rgb(29,28,29)">Thanks,</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:Arial,sans-serif;color:rgb(29,28,29)">Paul</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
<p class="MsoNormal">_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</blockquote></div>
</blockquote></div></div>
</blockquote></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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>