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 -------------- next part -------------- CMake Error at cmake/modules/LLVMDistributionSupport.cmake:18 (message): Specified distribution component 'clang' doesn't have a target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:24 (message): Specified distribution component 'clang' doesn't have an install target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:30 (message): Specified distribution component 'clang' doesn't have an install-stripped target. Its installation target creation should be changed to use add_llvm_install_targets, or you should manually create the 'install-clang-stripped' target. Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:18 (message): Specified distribution component 'lld' doesn't have a target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:24 (message): Specified distribution component 'lld' doesn't have an install target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:30 (message): Specified distribution component 'lld' doesn't have an install-stripped target. Its installation target creation should be changed to use add_llvm_install_targets, or you should manually create the 'install-lld-stripped' target. Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:18 (message): Specified distribution component 'clang-resource-headers' doesn't have a target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:24 (message): Specified distribution component 'clang-resource-headers' doesn't have an install target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:30 (message): Specified distribution component 'clang-resource-headers' doesn't have an install-stripped target. Its installation target creation should be changed to use add_llvm_install_targets, or you should manually create the 'install-clang-resource-headers-stripped' target. Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:18 (message): Specified distribution component 'builtins-armv6m-none-eabi' doesn't have a target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:24 (message): Specified distribution component 'builtins-armv6m-none-eabi' doesn't have an install target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:30 (message): Specified distribution component 'builtins-armv6m-none-eabi' doesn't have an install-stripped target. Its installation target creation should be changed to use add_llvm_install_targets, or you should manually create the 'install-builtins-armv6m-none-eabi-stripped' target. Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:18 (message): Specified distribution component 'builtins-armv7m-none-eabi' doesn't have a target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:24 (message): Specified distribution component 'builtins-armv7m-none-eabi' doesn't have an install target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:30 (message): Specified distribution component 'builtins-armv7m-none-eabi' doesn't have an install-stripped target. Its installation target creation should be changed to use add_llvm_install_targets, or you should manually create the 'install-builtins-armv7m-none-eabi-stripped' target. Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:18 (message): Specified distribution component 'builtins-armv7em-none-eabi' doesn't have a target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:24 (message): Specified distribution component 'builtins-armv7em-none-eabi' doesn't have an install target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:30 (message): Specified distribution component 'builtins-armv7em-none-eabi' doesn't have an install-stripped target. Its installation target creation should be changed to use add_llvm_install_targets, or you should manually create the 'install-builtins-armv7em-none-eabi-stripped' target. Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:18 (message): Specified distribution component 'runtimes' doesn't have a target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:24 (message): Specified distribution component 'runtimes' doesn't have an install target Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets) CMake Error at cmake/modules/LLVMDistributionSupport.cmake:30 (message): Specified distribution component 'runtimes' doesn't have an install-stripped target. Its installation target creation should be changed to use add_llvm_install_targets, or you should manually create the 'install-runtimes-stripped' target. Call Stack (most recent call first): CMakeLists.txt:1080 (llvm_distribution_add_targets)
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 > ../llvmThat 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
Hi Peter, On Wed, 26 Feb 2020 at 18:37, Peter Smith via llvm-dev <llvm-dev at 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> > 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 > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev