kiwan maeng via llvm-dev
2019-Oct-10 22:19 UTC
[llvm-dev] Cross compilation to ARM bare metal is not working
I am trying to build an LLVM toolchain so that it can cross-compile code to my ARMv7EM-based STM32F7 chip (I want to compile the code on an x86 machine and run it on ARM). However, a lot of the documents in the web is outdated, pointing to different versions of LLVM (with a different folder structure!) and I am not skilled enough to deduce a right way to build with the scattered information. I am mainly looking into this: (https://llvm.org/docs/HowToCrossCompileLLVM.html), and fiddled around to build something that is partially working. This is the command I am using: 1. git clone https://github.com/llvm/llvm-project.gitllvm-v9 2. cd .. 3. mkdir llvm-install && mkdir llvm-build && cd llvm-build 4. cmake -G "Unix Makefiles" -DCMAKE_CROSSCOMPILING=True -DLLVM_OPTIMIZED_TABLEGEN=1 -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_TARGET_ARCH=ARMV7EM -DLLVM_DEFAULT_TARGET_TRIPLE=armv7em-none-eabihf -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld;polly" -DLLVM_BUILD_EXTERNAL_COMPILER_RT=On -DCMAKE_LINKER=/usr/bin/ld.gold -DCMAKE_INSTALL_PREFIX=../llvm-install/ ../llvm-v9/llvm/ 5. make && make install It compiles, and if I try to compile C code using the compiled clang, it complains about not having clang_rt on the linking stage (it generates up to assembly file). I think it is weird that clang_rt is not there because I enable compiler-rt as you can see; anyways, I tried to separately compile clang_rt by looking at (https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html) but it wasn't successful. I spent weeks trying out different flag options (some won't even compile), or using a gcc-arm-none-eabi linker at the last stage, etc., but with no luck. Can anyone guide me to a more concrete example of how to compile LLVM for ARM cross-compilation, or help me out with what is wrong with the cmake options I am using? Alternatively, I just tried downloading clang from apt-get install, but that again complained about not having clang_rt. I would not mind using a lower version of LLVM if that is easier. Any help or insight would be highly appreciated! Also, kindly let me know if this is a wrong thread to post. I am new, as you can see. Thank you, Best Regards, Kiwan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191010/3a0a8bf8/attachment.html>
Chris Bieneman via llvm-dev
2019-Oct-12 04:15 UTC
[llvm-dev] Cross compilation to ARM bare metal is not working
LLVM is natively a cross compiler. You don't need to specify `CMAKE_CROSSCOMPILING` that option wound signify if you were compiling LLVM to run on arm, not LLVM to generate arm code. You do need to build compiler-rt for your target, not your host. Cross targeting runtime libraries is a bit more complicated of a build configuration. If you want a full C++ runtime for the bare metal arm you'll need to remove libcxx, libcxxabi, and compiler-rt from `LLVM_ENABLE_PROJECTS` and instead spicy them to `LLVM_ENABLE_RUNTIMES`. You will also need to set `LLVM_BUILTIN_TARGETS` and `LLVM_RUNTIME_TARGETS` to include the triples you want to build the runtimes for. You'll also need to set the compiler options for those targets so that the proper sysroots can be found. Probably the best example of this kind of configuration is under clang/cmake/caches/Android-stage2.cmake. -Chris> On Oct 10, 2019, at 3:19 PM, kiwan maeng via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > I am trying to build an LLVM toolchain so that it can cross-compile code to my ARMv7EM-based STM32F7 chip (I want to compile the code on an x86 machine and run it on ARM). > > However, a lot of the documents in the web is outdated, pointing to different versions of LLVM (with a different folder structure!) and I am not skilled enough to deduce a right way to build with the scattered information. > > I am mainly looking into this: (https://llvm.org/docs/HowToCrossCompileLLVM.html <https://llvm.org/docs/HowToCrossCompileLLVM.html>), and fiddled around to build something that is partially working. > > This is the command I am using: > > git clone https://github.com/llvm/llvm-project.git <https://github.com/llvm/llvm-project.git> llvm-v9 > cd .. > mkdir llvm-install && mkdir llvm-build && cd llvm-build > cmake -G "Unix Makefiles" -DCMAKE_CROSSCOMPILING=True -DLLVM_OPTIMIZED_TABLEGEN=1 -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_TARGET_ARCH=ARMV7EM -DLLVM_DEFAULT_TARGET_TRIPLE=armv7em-none-eabihf -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld;polly" -DLLVM_BUILD_EXTERNAL_COMPILER_RT=On -DCMAKE_LINKER=/usr/bin/ld.gold -DCMAKE_INSTALL_PREFIX=../llvm-install/ ../llvm-v9/llvm/ > make && make install > It compiles, and if I try to compile C code using the compiled clang, it complains about not having clang_rt on the linking stage (it generates up to assembly file). > > I think it is weird that clang_rt is not there because I enable compiler-rt as you can see; anyways, I tried to separately compile clang_rt by looking at > > (https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html <https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html>) but it wasn't successful. > > I spent weeks trying out different flag options (some won't even compile), or using a gcc-arm-none-eabi linker at the last stage, etc., but with no luck. > > Can anyone guide me to a more concrete example of how to compile LLVM for ARM cross-compilation, or help me out with what is wrong with the cmake options I am using? > > Alternatively, I just tried downloading clang from apt-get install, but that again complained about not having clang_rt. > > I would not mind using a lower version of LLVM if that is easier. > > Any help or insight would be highly appreciated! > > Also, kindly let me know if this is a wrong thread to post. I am new, as you can see. > > Thank you, > > Best Regards, > > Kiwan > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191011/704649f3/attachment.html>