Skip to content

Draft: Include LLD linker in LFortran

Ondřej Čertík requested to merge certik/lfortran:exe into master

This allows the lfortran executable to link directly. There are some issues to resolve:

  • It significantly increases the lfortran executable size from 18MB to 67MB. Solution: We make LLD optional for now.
  • LFortran now depends on LLD, which is not shipped by default with LLVM, so must be installed separately. From conda-forge it is llvmdev and lld packages. In Ubuntu it is llvm-9-dev and liblld-9-dev packages. Solution: Added WITH_LLD which is off by default, thus making LLD optional
  • One must link against lldELF and lldCommon LLD libraries, which would be fine --- but these two then require to link against 37 extra LLVM libraries in Ubuntu (lto, option, target, NVPTXCodeGen, XCoreCodeGen, *CodeGen, *AsmParser where * stands for , AArch64, AMDGPU, ARM, AVR, BPF, Hexagon, Lanai, Mips, MSP430, PowerPC, RISCV, Sparc, SystemZ, WebAssembly, X86). It feels fragile, that it would fail to link properly on all platforms. For example when using LLVM/LLD from conda-forge one must remove AVRCodegen and AVRAsmParser from CMake by hand. Solution: target, CodeGen and AsmParser were not needed, and the rest of *CodeGen and AsmParser can be generated automatically from the ${LLVM_TARGETS_TO_BUILD} variable and checking that the given library exists. That makes it work everywhere.
  • The LFortran runtime library requires libc, so we would need to ship musl libc. Alternatively we can try to avoid depending on libc, but that will make it hard to use things like openlibm in the future. The best is to depend on libc and ship musl with lfortran. Solution: We make LLD optional, and we will iteratively work on shipping musl with LFortran.

Until these issues are resolved, the master branch will simply use a C compiler (such as gcc) to do the linking, which will pick up a working libc library and link everything properly.


The MR is relatively clean now, tests pass. TODO list before merging:

  • Rebase to create a nice clean set of commits
  • Make the lld command general, not hardwired
  • Add an option to lfortran to link via lld, and add a test.
Edited by Ondřej Čertík

Merge request reports