[llvm-dev] Cross compiling for ARMv7-m

Peter Smith via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 26 09:36:55 PST 2020


Hello Arslan,

> I am guessing I can borrow libraries such as lc and lm from GCC
> arm-none-eabi*, but for clang_rt.builtins-arm.a (which I thought
> should've been built with LLVM build but I couldn't find that library
> in my build directory) I tried building it from LLVM source.

You can take these from an arm-none-eabi toolchain. The GCC equivalent of clang_rt.builtins-arm.a is libgcc.a, one way to use these with clang is use one of the options that suppress -lc -lm and -lclang_rt.builtins-arm.a I think either --nostdlib or --nodefaultlibs will do that. You'll need to tell clang where to find these in your arm-none-eabi toolchain.

> To generate the library, I tried generating builtins by following the guide at:
> https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html
> I tried with different configurations, but each one ends up in some
> error which left me wondering that this document might be obsolete.

I'd hope the information in there isn't completely obsolete, but I haven't tried the build for over a year so it may well need an update. I'll try to reproduce my steps and send a patch to update the guide if there is anything broken. I can't promise when I'll get that done by though.

> cmake -G "Unix Makefiles"
> -DBAREMETAL_ARMV6M_SYSROOT=../../gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/
> -DBAREMETAL_ARMV7M_SYSROOT=../../gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/
> -DBAREMETAL_ARMV7EM_SYSROOT=../../gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/
> -DCMAKE_BUILD_TYPE=Release -C ../clang/cmake/caches/BaremetalARM.cmake
> ../llvm

That particular recipe predates the monorepo, and relied upon compiler-rt being checked out in the runtimes subdirectory. I suspect that this will likely not work with the monorepo.

Peter

________________________________________
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Arslan Khan via llvm-dev <llvm-dev at lists.llvm.org>
Sent: 26 February 2020 16:57
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] Cross compiling for ARMv7-m

Hi,
I am trying to use LLVM/clang to build a binary for ARM Cortex M platforms.
When I build my binary the linker fails to find these libraries.

./bin/clang++ -target arm-none-eabi -mcpu=cortex-m4 ./temp.cpp -L
./lib/ -L ./libexec/ -L ../build3_v7m/lib/
ld.lld: error: unable to find library -lunwind
ld.lld: error: unable to find library -lc
ld.lld: error: unable to find library -lm
ld.lld: error: unable to find library -lclang_rt.builtins-arm.a

I am guessing I can borrow libraries such as lc and lm from GCC
arm-none-eabi*, but for clang_rt.builtins-arm.a (which I thought
should've been built with LLVM build but I couldn't find that library
in my build directory) I tried building it from LLVM source.


To generate the library, I tried generating builtins by following the guide at:
https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html
I tried with different configurations, but each one ends up in some
error which left me wondering that this document might be obsolete.

Anyhow googling things led me to this thread.

http://llvm.1065342.n5.nabble.com/llvm-dev-Compiling-for-baremetal-ARMv4-on-Ubuntu-Linux-td124226.html

After going through this I figured my best bet would be using GCC
sysroot. After which my cmake command looks like this.

cmake -G "Unix Makefiles"
-DBAREMETAL_ARMV6M_SYSROOT=../../gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/
-DBAREMETAL_ARMV7M_SYSROOT=../../gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/
-DBAREMETAL_ARMV7EM_SYSROOT=../../gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/
-DCMAKE_BUILD_TYPE=Release -C ../clang/cmake/caches/BaremetalARM.cmake
../llvm

But with this, I am getting this error attached to the email. Is there
something I am missing here? Is there any update to the
cross-compilation guide? My end goal is cross-compiling C++ programs
for ARM on x86. Any pointers for this would be helpful.

Thanks,
Arslan


More information about the llvm-dev mailing list