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

Daniel Albuschat d.albuschat at gmail.com
Tue Nov 5 04:11:37 PST 2013


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?

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".)

Greetings,

Daniel Albuschat



More information about the llvm-dev mailing list