Both gcc and clang implement link-time optimization by allowing object files (
.o) to not only contain the machine's target code, but also intermediate representations (GIMPLE or LLVM bitcode) used by the compilers themselves. Those object files can be packed into static archives and made ready for static linking.
The norm with those lto-capable archives is that they are made "fat" by including both the normal machine code (so they can work like normal ones) and the IR. But is it possible to make a "very fat" archive with multiple types of IRs and make the compilers recognize those respective IRs? Here are a few challenges:
- Both compilers seem to recommend modified versions of
ar to make sure the IR gets included and indexed. gcc has
gcc-ar (plugin), and clang has
- Clang does not produce "fat" archives. In fact its bitcode object files cannot be interpreted by standard GNU tools.