[llvm-dev] Cross compiling for Baremetal ARM without using GCC (original) (raw)

Peter Smith via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 1 05:02:29 PDT 2017


Hello Daniel,

I don't have full answers but I may be able to move you slightly forward. I'm assuming that you want an answer that involves only open source tools.

I've managed to successfully build compiler-rt using Jonathan Roelofs BaremetalARM.cmake in clang/cmake/caches and an arm-none-eabi gcc installation as sysroot. One thing that I needed to do for it to work was to move compiler-rt from llvm/projects/compiler-rt to llvm/runtimes/compiler-rt. I haven't got any experience at building newlib or Musl with clang instead of gcc.

I've been working on Arm support in LLD, in theory most of the parts are there [*] and the linker script support has come a long way recently. However I've not actively tested on embedded systems yet as my focus has been on Linux/BSD like targets. At least a few people have had problems with LLD always allocating the ELF header and Program Header in the first PT_LOAD Program Header, which is definitely not what you want for an embedded system. If you do run into problems please let us know and raise bug reports if possible.

Peter

[*] There aren't any range extension thunks that work for Cortex-M0, but in the vast majority of cases you won't need these.

On 31 October 2017 at 23:55, Daniel Kang via llvm-dev <llvm-dev at lists.llvm.org> wrote:

Dear LLVM developers,

Hello, I’m trying to find a way of cross-compiling my c code against Baremetal Cortex-M device (so target triple will be arm-none-eabi) only using LLVM/Clang, and not using anything from GNU (ld or libc). I’m doing this to know which one of LLVM/clang and GCC produces smaller flash image size because saving flash is a big deal in our projects. 1) When I just follow this - https://clang.llvm.org/docs/CrossCompilation.html using LLVM/Clang Prebuilt binary 5.0.0, I got this error, daniel at daniel-VirtualBox:~/clang/crosscompile$ make clean all rm -f main *.o *.map *.a "clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin"/clang -static --target=arm-none-eabi -mcpu=cortex-m0 -c -o main.o main.c "clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin"/clang -static --target=arm-none-eabi -mcpu=cortex-m0 -c -o a.o a.c "clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin"/clang -static --target=arm-none-eabi -mcpu=cortex-m0 -c -o reset.o reset.c "clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin"/clang -v -static --target=armv6m-none-eabi -o main main.o a.o reset.o clang version 5.0.0 (tags/RELEASE500/final) Target: armv6m-none--eabi Thread model: single InstalledDir: clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin "clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin/ld.lld" main.o a.o reset.o -Bstatic -Lclang+llvm-5.0.0-linux-x8664-ubuntu16.04/lib/clang/5.0.0/lib/baremetal -lc -lm -lclangrt.builtins-armv6m.a -o main clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin/ld.lld: error: unable to find library -lc clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin/ld.lld: error: unable to find library -lm clang+llvm-5.0.0-linux-x8664-ubuntu16.04/bin/ld.lld: error: unable to find library -lclangrt.builtins-armv6m.a clang-5.0: error: ld.lld command failed with exit code 1 (use -v to see invocation) makefile:33: recipe for target 'main' failed make: *** [main] Error 1 2) To get clangrt.builtins-armv6m.a or libc, libm, I tried to build LLVM/Clang (compilerrt) from LLVM/Clang source following this - http://llvm.org/docs/HowToCrossCompileLLVM.html but I got this error, TARGETTRIPLE=arm-none-eabi MYHOSTBIN=${HOME}/clang/source/buildx64/bin MYGNUARMROOT=${HOME}/opt/gcc-arm-none-eabi-6-2017-q2-update MYCFLAGS="--specs=nosys.specs -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16" _cmake -G "Ninja" _ _-DCMAKECROSSCOMPILING=True _ _-DCMAKEBUILDTYPE=Release _ _-DCMAKEINSTALLPREFIX=${HOME}/clang/toInstall _ _-DLLVMTABLEGEN=${MYHOSTBIN}/llvm-tblgen _ _-DCLANGTABLEGEN=${MYHOSTBIN}/clang-tblgen _ _-DLLVMDEFAULTTARGETTRIPLE=arm-none-eabi _ _-DLLVMTARGETARCH=ARM _ _-DLLVMTARGETSTOBUILD=ARM _ _-DLLVMENABLELTO=Full _ _-DCMAKECFLAGS="${MYCFLAGS}" _ _-DCMAKECXXFLAGS="${MYCFLAGS}" _ _-DCMAKESYSROOT=${MYGNUARMROOT} _ _-DCMAKETOOLCHAINFILE=../toolchain.txt _ _-DCMAKECCOMPILER=${MYGNUARMROOT}/bin/arm-none-eabi-gcc _ _-DCMAKECXXCOMPILER=${MYGNUARMROOT}/bin/arm-none-eabi-g++ _ _-DCMAKEASMCOMPILER=${MYGNUARMROOT}/bin/arm-none-eabi-as _ ../llvm _-- Looking for atomicload8 in atomic _-- Looking for atomicload8 in atomic - not found CMake Error at cmake/modules/CheckAtomic.cmake:74 (message): Host compiler appears to require libatomic, but cannot find it. Call Stack (most recent call first): cmake/config-ix.cmake:350 (include) CMakeLists.txt:585 (include) arm-none-eabi toolchain doesn’t contain libatomic, but I need to build compilerrt using this tool to get the runtime for ARM, so it’s confusing. Or building compilerrt using arm-none-eabi toolchain is completely wrong idea in the first place. 3) Then I found this mail thread http://lists.llvm.org/pipermail/llvm-dev/2017-August/116134.html which seems very close to the thing I’m trying, but the mail thread is unfinished. So, my question is, Is there a way of cross-compiling c code against Baremetal Cortex-M device only using LLVM/Clang, and not using anything from GNU (ld or libc)? If so, do I have to build LLVM/Clang source code to get clangrt.builtins-armv6m.a or libc, libm for ARM? If so, the method 2) or 3) above is the right approach? Or are there any other instruction? Any advice would be a great help for me. Thank you Daniel

This message and any attachments may contain confidential information from Cypress or its subsidiaries. If it has been received in error, please advise the sender and immediately delete this message.


LLVM Developers mailing list llvm-dev at lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list