<div dir="ltr">On Tue, Nov 5, 2013 at 4:11 AM, Daniel Albuschat <span dir="ltr"><<a href="mailto:d.albuschat@gmail.com" target="_blank">d.albuschat@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">2013/11/4 Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>>:<br>
> Awesome! As far as I know you are the first person outside Google to try out<br>
> LLD on Windows. :) Glad to hear that it worked.<br>
<br>
Hey Rui,<br>
<br>
glad that I can help out.<br>
<br>
I was going to use lld in the following scenario:<br>
I'm writing a programming language and started with unit-tests that<br>
build ASTs for small test cases.<br>
I then want to generate code from the AST, write it to a DLL with an<br>
exported "test" function that contains the generated code from the<br>
test-case. I could then load the DLL, run the test function and verify<br>
the result just inside the unit test-case.<br>
<br>
I noticed that, while linking an .exe file worked for a simple main<br>
function that calls another function, linking a DLL does not work.<br>
The /DLL parameter is not implemented (nor is /NOENTRY).<br>
<br>
I managed to add handling of the /DLL and /NOENTRY parameters to lld.<br>
/DLL successfully sets the imageType to ImageType::DLL. I added code<br>
to change the file extension from .exe to .dll. That far it worked<br>
fine and a .dll file was created. It was just then that I realized<br>
that lld does not seem to write an export section. ;-) Opening the<br>
file in Depedency Walker, I did not see my exported function.<br>
<br>
>From what I could spot by comparing the result of dumpbin of dll files<br>
generated by link.exe and by lld, the missing export section might be<br>
the only thing missing to support rudimentary dll support to lld.<br>
Maybe adding this is not such a big deal and you can give me a few<br>
pointers as to where/how I could implement this? Is there any<br>
documentation of the PECOFF file format that I could rely on?<br></blockquote><div><br></div><div>Yes, the only missing feature for DLL suuport (except /DLL and /NOENTRY command line options) is the export table. LLD already supports the import table to import symbols from DLL. We can support the export table in a similar way as we did for the import table.</div>
<div><br></div><div>The code location for the import table is lib/ReaderWriter/PECOFF/IdataPass.h. It's a little bit complicated, but essentially we create "atoms" representing the import table in this pass, and write it by WriterPECOFF. I'd think you could add code to the file or create a new pass for the export table.</div>
<div><br></div><div>As to the documentation, you could rely on "Microsoft Portable Executable and Common Object File Format Specification" which you can download at <a href="http://microsoft.com">microsoft.com</a>.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On a side note:<br>
One day, someone could even implement an lld::File writer for LLVM to<br>
make it possible to go directly from llvm AST to an .exe/.dll file (or<br>
UNIX/Linux binary/shared object file) without temporary .obj files.<br>
That would be awesome. ;-) And it would make cross-compiling possible<br>
as soon as a few dependencies are removed from lld.<br>
(And actually, when I started investigating into LLVM, I thought this<br>
was already possible until I learned that I could only create .obj<br>
files with llc and had to link them "manually".)<br></blockquote><div><br></div><div>I believe that's planned. The API of LLD is designed to take a memory buffer for input files -- to allow you to pass files without storing it onto the file system. :)</div>
</div></div></div>