Thread overview
Link Time Optimization Bitcode File Format
Oct 06
IGotD-
Oct 06
kinke
October 06
Hi all,

I am trying to build the druntime with the 'ldc-build-runtime' tool for microcontrollers (using the arm-none-eabi-gcc compiler) and therefore the size of the druntime should be as little as possible. One solution I had was to use Link Time Optimization (LTO) to reduce the size.

The problem now is the fact that when I compile the druntime with -flto=full or -flto=thin (as arguments for LDC2), the resulted object files (and also a big part of the runtime as it is a static library) have a different file format - LLVM IR bitcode - than I need, which is ELF 32-bit. Also, when I try to link the druntime with the application I want to write on the microcontroller, there are some link errors due to the file format.
I also tried using a different archiver - llvm-ar - but I had no luck.

Could you give me some advice about how should I fix this?

Thank you!
October 06
On Tuesday, 6 October 2020 at 16:46:28 UTC, Severin Teona wrote:
> Hi all,
>
> I am trying to build the druntime with the 'ldc-build-runtime' tool for microcontrollers (using the arm-none-eabi-gcc compiler) and therefore the size of the druntime should be as little as possible. One solution I had was to use Link Time Optimization (LTO) to reduce the size.
>
> The problem now is the fact that when I compile the druntime with -flto=full or -flto=thin (as arguments for LDC2), the resulted object files (and also a big part of the runtime as it is a static library) have a different file format - LLVM IR bitcode - than I need, which is ELF 32-bit. Also, when I try to link the druntime with the application I want to write on the microcontroller, there are some link errors due to the file format.
> I also tried using a different archiver - llvm-ar - but I had no luck.
>
> Could you give me some advice about how should I fix this?
>
> Thank you!

I have run into the same problem when using GNU ld. The problem is that my version of GNU ld, version 2.30.0.20180329 (which is ancient) cannot deal with the object file format when LTO is enabled. One way is to try llvm-ld and see if that one can handle it.


October 06
On Tuesday, 6 October 2020 at 16:46:28 UTC, Severin Teona wrote:
> Also, when I try to link the druntime with the application I want to write on the microcontroller, there are some link errors due to the file format.

This happens when you link manually, not through LDC. When running LDC with `-flto=full -O -v ...`, you'll see that it invokes gcc with extra flags, something like

-Wl,-plugin,/dlang/ldc-1.23.0/lib/LLVMgold-ldc.so -Wl,-plugin-opt=mcpu=x86-64 -Wl,-plugin-opt=O3 -Wl,-plugin-opt=-function-sections -Wl,-plugin-opt=-data-sections

so that the linker gets to know how to deal with bitcode objects via the LLVM plugin.

See http://johanengelen.github.io/ldc/2016/11/10/Link-Time-Optimization-LDC.html for more infos about LTO.