> 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...@lists.llvm.org> on behalf of Arslan Khan via llvm-dev <llvm...@lists.llvm.org>
Sent: 26 February 2020 16:57
To: llvm...@lists.llvm.org
Subject: [llvm-dev] Cross compiling for ARMv7-m
Thanks,
Arslan
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
On Wed, 26 Feb 2020 at 18:37, Peter Smith via llvm-dev
<llvm...@lists.llvm.org> wrote:
>
> 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.
>
I recently tried again to build compiler-rt for cortex-m using the
info from the guide mentioned above, but it still fails for me.
Something that I don't understand is that when I call
clang --target=armv7m-none-eabi
--gcc-toolchain=/XX/gcc-linaro-7.3.1-2018.05-x86_64_arm-eabi
--sysroot=/XX/gcc-linaro-7.3.1-2018.05-x86_64_arm-eabi/arm-eabi/
-L$PWD/llvm-project/cross-install/lib hello.o -o hello.exe.arm.clang
I get:
clang-12: warning: argument unused during compilation:
'--gcc-toolchain=/XX/gcc-linaro-7.3.1-2018.05-x86_64_arm-eabi'
[-Wunused-command-line-argument]
ld.lld: error: unable to find library -lc
ld.lld: error: unable to find library -lm
clang-12: error: ld.lld command failed with exit code 1 (use -v to see
invocation)
Not sure why --gcc-toolchain isn't used, anyway libc.a and libm.a are
under $SYSROOT/libc/usr/lib
(and I did try --sysroot=...../libc --sysroot=.../libc/usr and
--sysroot=../libc/usr/lib, none of which worked)
Any idea?
Thanks,
Christophe
Hello Christophe,
When the bare metal driver is selected with --target=arm-none-eabi the --gcc-toolchain option is not checked.
From the code in clang/lib/Driver/ToolChains/BareMetal.cpp it looks like sysroot is used in the include paths but not for the library paths.
If libc.a and libm.a are under $SYSROOT/libc/usr/lib then with the bare-metal driver I think you would need to use -L $SYSROOT/libc/usr/lib
If it helps, this is what a colleague had been using recently to compile compiler-rt for bare-metal. I've not tested it myself though. The interesting parts that may be
new are -DCOMPILER_RT_BAREMETAL_BUILD=ON and -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY I expect that a lot of that can be trimmed as well.
cmake -G Ninja ../llvm-project/compiler-rt/
-DCMAKE_BUILD_TYPE=Release \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
-DCMAKE_C_COMPILER_TARGET="$TARGET" \
-DCMAKE_ASM_COMPILER_TARGET="$TARGET" \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DLLVM_CONFIG_PATH="$BUILDTOOLS/llvm-config" \
-DCMAKE_C_COMPILER="$TOOLS/clang" \
-DCMAKE_C_FLAGS="--sysroot $INSTALL/targets/$TARGET" \
-DCMAKE_AR="$TOOLS/llvm-ar" \
-DCMAKE_NM="$TOOLS/llvm-nm" \
-DCMAKE_RANLIB="$TOOLS/llvm-ranlib" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCMAKE_INSTALL_PREFIX="$INSTALL/targets/$TARGET"
Hope this gets you a bit further. Apologies if the webmail client has mangled the reply. Let me know if you are still having problems and I'll try and take a look.
Peter
Hi Peter,
Thanks, it did help. Looks like I was missing
-DCMAKE_C_FLAGS="--sysroot XXX"
so now build_and_install_compilerrt() completes.
I guess my next step is now to understand how to build a toolchain for
eg. rtems to see what I need to update to build the sanitizers for a
new "OS" (baremetal for me).
Thanks,
Christophe