ARMClang: Option --cpu to armlink is problematic
I have a project with the following toochain defined:
#Cross compiling toolchain:
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER_TARGET aarch64-arm-none-eabi)
set(CMAKE_CXX_COMPILER_TARGET aarch64-arm-none-eabi)
set(CMAKE_ASM_COMPILER_TARGET aarch64-arm-none-eabi)
set(CMAKE_SYSTEM_PROCESSOR cortex-a53)
set(CMAKE_C_COMPILER armclang)
set(CMAKE_CXX_COMPILER armclang)
When run cmake, I got this error:
The C compiler
"/opt/arm/DS-5_v5.29.2/sw/ARMCompiler6.10.1/bin/armclang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/oscarh/data/temp/fooPrj/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_4a0d6/fast && /usr/bin/make -f CMakeFiles/cmTC_4a0d6.dir/build.make CMakeFiles/cmTC_4a0d6.dir/build
make[1]: Entering directory '/home/oscarh/data/temp/fooPrj/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_4a0d6.dir/testCCompiler.o
/opt/arm/DS-5_v5.29.2/sw/ARMCompiler6.10.1/bin/armclang --target=arm-arm-none-eabi -mcpu=cortex-a53 -o CMakeFiles/cmTC_4a0d6.dir/testCCompiler.o -c /home/oscarh/data/temp/fooPrj/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_4a0d6.elf
/opt/cmake-3.16.0-rc3/bin/cmake -E cmake_link_script CMakeFiles/cmTC_4a0d6.dir/link.txt --verbose=1
/opt/arm/DS-5_v5.29.2/sw/ARMCompiler6.10.1/bin/armlink --cpu=cortex-a53 CMakeFiles/cmTC_4a0d6.dir/testCCompiler.o -o cmTC_4a0d6.elf --list cmTC_4a0d6.map
Fatal error: L3903U: Argument 'cortex-a53' not permitted for option 'cpu'.
Finished: 0 information, 0 warning, 0 error and 1 fatal error messages.
CMakeFiles/cmTC_4a0d6.dir/build.make:86: recipe for target 'cmTC_4a0d6.elf' failed
I think the problem is, cmake passed ${CMAKE_SYSTEM_PROCESSOR} directly to the --cpu option of armlink. In this case cortex-a53 is recognizable by armclang, but not by armlink. Actually, armlink cannot have --cpu at all for some targets, see this statement from armlink document:
You cannot specify targets with Armv8.4-A or later architectures on the armlink command-line. To link for such targets, you must not specify the --cpu option when invoking armlink directly
See original discussion at https://discourse.cmake.org/t/possible-bugs-with-armclang-toolchain/168
Edited by Brad King