[LLVMdev] Current state of the lld project (support for writing .dll files)

Rui Ueyama ruiu at google.com
Mon Nov 11 17:29:19 PST 2013


On Tue, Nov 5, 2013 at 4:11 AM, Daniel Albuschat <d.albuschat at gmail.com>wrote:

> 2013/11/4 Rui Ueyama <ruiu at google.com>:
> > Awesome! As far as I know you are the first person outside Google to try
> out
> > LLD on Windows. :) Glad to hear that it worked.
>
> Hey Rui,
>
> glad that I can help out.
>
> I was going to use lld in the following scenario:
> I'm writing a programming language and started with unit-tests that
> build ASTs for small test cases.
> I then want to generate code from the AST, write it to a DLL with an
> exported "test" function that contains the generated code from the
> test-case. I could then load the DLL, run the test function and verify
> the result just inside the unit test-case.
>
> I noticed that, while linking an .exe file worked for a simple main
> function that calls another function, linking a DLL does not work.
> The /DLL parameter is not implemented (nor is /NOENTRY).
>
> I managed to add handling of the /DLL and /NOENTRY parameters to lld.
> /DLL successfully sets the imageType to ImageType::DLL. I added code
> to change the file extension from .exe to .dll. That far it worked
> fine and a .dll file was created. It was just then that I realized
> that lld does not seem to write an export section. ;-) Opening the
> file in Depedency Walker, I did not see my exported function.
>
> From what I could spot by comparing the result of dumpbin of dll files
> generated by link.exe and by lld, the missing export section might be
> the only thing missing to support rudimentary dll support to lld.
> Maybe adding this is not such a big deal and you can give me a few
> pointers as to where/how I could implement this? Is there any
> documentation of the PECOFF file format that I could rely on?
>

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.

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.

As to the documentation, you could rely on "Microsoft Portable Executable
and Common Object File Format Specification" which you can download at
microsoft.com.


> On a side note:
> One day, someone could even implement an lld::File writer for LLVM to
> make it possible to go directly from llvm AST to an .exe/.dll file (or
> UNIX/Linux binary/shared object file) without temporary .obj files.
> That would be awesome. ;-) And it would make cross-compiling possible
> as soon as a few dependencies are removed from lld.
> (And actually, when I started investigating into LLVM, I thought this
> was already possible until I learned that I could only create .obj
> files with llc and had to link them "manually".)
>

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. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131111/c497dee9/attachment.html>


More information about the llvm-dev mailing list