[llvm-dev] Problems using Clang with LLD on embedded ARM

Sean Vig via llvm-dev llvm-dev at lists.llvm.org
Sat Feb 25 21:38:37 PST 2017


I stopped into IRC to ask about a problem I've been having using Clang in
conjunction with LLD to compile and link for an embedded project on
Cortex-M ARM processor.

First, I am able to separately compile with a call to clang and link with a
call to lld, but I cannot use clang to link using lld using the
-fuse-ld=lld flag. I have the output from `clang -v -fuse-ld=lld -target
arm-none-eabi main.c -o main` here [1], where calling `clang -target
arm-none-eabi -c main.c -o main.o` and `ld.lld main.o -o main` work fine.
Doing the compiling and linking for my host computer works just fine using
-fuse-ld=lld, and I verified that it is using LLD by checking the .comments
section in the generated elf.

Second, combining LTO with specifying any specific arm architecture seems
to break linking with LLD. That is, I compile the object files with LTO
(either -flto or -flto=thin) and, in addition to specifying `-target
arm-none-eabi`, I specify an architecture specific flag (such as
-march=armv7e-m, -mcpu=cortex-m4, or -mthumb, or instead I use -target
armv7em-none-eabi), then while calling lld to link I get an error like:
ld.lld: error: main.o: could not infer e_machine from bitcode target triple
LLD 4.0.0

I am working on Linux and these two problems seem to exist on both 4.0rc2
and the current head.

I am really happy with the progress LLVM has made, with the upcoming 4.0
release, I have managed to compile and link programs for my embedded
projects without any of the gcc arm toolchain! There are still some
shortcomings with the linker scripts compared to ld that make those a bit
trickier to work with, even with the added MEMORY section parsing in the
current head. Other than the above, the only other bother I've hit is
having to re-link with `--oformat binary` to get raw binary output, since
there I haven't found an objcopy equivalent in llvm. I can add feature
requests for these missing features, as well as the bug reports for the
above two issues, on the bugzilla if that is appropriate.

Thanks for the help,


[1] https://gist.github.com/flacjacket/35d92ea619af96352d5ac06844f2f1b5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170225/2f6aa864/attachment.html>

More information about the llvm-dev mailing list