[cfe-dev] LLVM/Clang and getting rid of the system linker (GNU ld or MSVC link.exe)

Ruben Van Boxem vanboxem.ruben at gmail.com
Sun Apr 17 07:29:34 PDT 2011


Hi,

I've been thinking recently about how Clang can solve it's system
linker dependency problem. I've seen some proposals and thoughts on
the mailing list about this issue, so I think this will be interesting
to explore. Please excuse my non-professional language, I am not a
Computer Science master, just a very interested hobbyist.

Concretely, Clang now uses the system linker (GNU ld or MSVC link.exe)
to turn the series of object files into an executable/library. This is
not very good, because Clang depends on the whims of a completely
different project to work correctly, and this is very platform
dependent on too high a level.

So the current setup is (how I see it):
1. Clang compiles C/C++ to object files (either GNU *.o or MSVC *.obj
files). This happens through LLVM IR and accompanying optimization
runs of the LLVM toolchain.
2. The system linker is responsible for all the usual link stuff:
turning the object files into native binaries, doing some
link-time-optimizations while it works its magic.

How I would propose to have it in an ideal world:

1. Clang compiles C/C++ into LLVM IR.
2. LLVM toolchain stuff optimizes everything as well as it can.
3. LLVM linker (+Clang?)  links together the IR files into one object
file (perhaps existing GNU .o or MSVC .obj files), executing its
link-time-optimizations in the process.
4. A *simple* tool turns the complete object file into native
executable format, adding the platform-dependent parts that are
missing from the semi-platform-agnostic file created in the previous
step. This tool can in the first steps of the implementation be the
system linker, but all it would do is do the object->executable
conversion.

The "linker" may be the assembler or something else, this is what I
don't know. What I do know is that this setup (if possible) provides a
way to integrate more LLVM optimizations in a C/C++/<other language of
your choice> toolchain, remove any complicated linker applications,
and be easily extensible to new platforms.

I understand the hand-wavingness of this whole story, but any comments
or thoughts on what is wrong in my reasoning or not as simple as it
seems are very welcome.

Thanks!

Ruben



More information about the cfe-dev mailing list