Windows --> arm-linux cross compiler and lld
Mike Franklin
slavo5150 at yahoo.com
Wed Apr 11 00:39:23 UTC 2018
Thanks Jacob and kinke for the advice.
I've been able to piece together a Frankenstein toolchain using
LLVM 6, ldc2-1.8.0-windows-x64, and ldc2-1.8.0-linux-armhf
I compile using ldc2-1.8.0-windows-x64:
ldc2 -c main.d
I create a samba share on my ARM device use it as sysroot from
the Windows host at \\192.168.0.26\root.
I pull the `lib` folder out of ldc2-1.8.0-linux-armhf for the
following linking task.
I link with something like this (pieced together from my notes;
may not be perfect):
ld.lld.exe -static -m armelf_linux_eabi -o main
-sysroot \\192.168.0.26\root
\\192.168.0.26\root\usr\lib\arm-linux-gnueabihf\crt1.o
\\192.168.0.26\root\usr\lib\arm-linux-gnueabihf\crti.o
\\192.168.0.26\root\usr\lib\arm-linux-gnueabihf\crtbegin.o
-L \\192.168.0.26\root\usr\lib\arm-linux-gnueabihf
-L \\192.168.0.26\root\usr\lib\gcc\arm-linux-gnueabihf\4.9.2
main.o
\\192.168.0.26\root\usr\lib\arm-linux-gnueabihf\crtend.o
\\192.168.0.26\root\usr\lib\arm-linux-gnueabihf\crtn.o
-L C:\ldc2-1.8.0-linux-armhf\lib -lphobos2-ldc -ldruntime-ldc
-lrt -ldl -lpthread -lm -lc -lgcc -lgcc_eh
It works.
I couldn't get linking with clang or separate dynamic linking to
work; my binary ends up throwing a segmentation fault, but I
suspect I could probably troubleshoot and work out what I need to
do eventually.
> A while ago, I integrated LLD into LDC itself. It's currently
> only able to link MSVC binaries, so `-link-internally` only
> works for MSVC targets.
> There's a PR in which I extended it to ELF and Mach-O targets
> too; it seems to be working after a quick test (if you have the
> required libs obviously), but the needed linker flags normally
> added by gcc makes the command-line explode:
> https://github.com/ldc-developers/ldc/pull/2203#issuecomment-339167131
>
> The command-line flags could be added once to the config file
> though if your environment is stable.
That looks really nice. I see you had to patch lld; is that
going upstream?
How does clang know how to generate its linker command? Whatever
it is, can ldc be made do the same?
Mike
More information about the digitalmars-d-ldc
mailing list