Draft: Include LLD linker in LFortran
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 isllvmdev
andlld
packages. In Ubuntu it isllvm-9-dev
andliblld-9-dev
packages. Solution: AddedWITH_LLD
which is off by default, thus making LLD optional -
One must link against lldELF
andlldCommon
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 forAArch64
,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 fromconda-forge
one must removeAVRCodegen
andAVRAsmParser
from CMake by hand. Solution:target
,CodeGen
andAsmParser
were not needed, and the rest of*CodeGen
andAsmParser
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 shipmusl
libc
. Alternatively we can try to avoid depending onlibc
, but that will make it hard to use things likeopenlibm
in the future. The best is to depend onlibc
and shipmusl
withlfortran
. Solution: We make LLD optional, and we will iteratively work on shippingmusl
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