-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Description
Describe the bug
In case of ZEPHYR_TOOLCHAIN_VARIANT=cross-compile we don't set SYSROOT_DIR cmake variable, so we don't execute
block of code which sets LIBC_LIBRARY_DIR variable based on the toolchain C flags (including mcpu flag):
zephyr/cmake/compiler/gcc/target.cmake
Lines 74 to 88 in 88aa873
| if(SYSROOT_DIR) | |
| # The toolchain has specified a sysroot dir, pass it to the compiler | |
| list(APPEND TOOLCHAIN_C_FLAGS | |
| --sysroot=${SYSROOT_DIR} | |
| ) | |
| # Use sysroot dir to set the libc path's | |
| execute_process( | |
| COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-multi-directory | |
| OUTPUT_VARIABLE NEWLIB_DIR | |
| OUTPUT_STRIP_TRAILING_WHITESPACE | |
| ) | |
| set(LIBC_LIBRARY_DIR "\"${SYSROOT_DIR}\"/lib/${NEWLIB_DIR}") | |
| endif() |
So, in case of multilib cross-compile toolchain we always use default libraries set no mater which mcpu value we've provided. Obviously it's incorrect.
Impact
Implicit & unexpected usage of libraries which are build for different mcpu than was specified.
If we are lucky we may get compile error - for example if we got something not linkable, like 64bit libraries from toolchain and 32 bit object files from rest of zephyr. However we may get successful linkage and use some not optimal libraries (i.e built for processor which use smaller instruction set) or get runtime issues.
possible solutions
- add additional environment variable for cross-compile toolchain variant, which will be pointing to correct SYSROOT_DIR path.
- try to extract SYSROOT_DIR path from the
CROSS_COMPILEvariable. I've checked the value ofCROSS_COMPILEI've previously used - it doesn't seems to be feasible for these toolchains I.e:
CROSS_COMPILE=/home/user/dev/arc64-unknown-elf-1205/arc64-unknown-elf/bin/arc64-snps-elf-
SYSROOT_DIR should be /home/user/dev/arc64-unknown-elf-1205/arc64-unknown-elf/arc64-unknown-elf/
CROSS_COMPILE=/global/tools/Linux/arc_gnu_2021.09_prebuilt_elf32_le/bin/arc-elf32-
SYSROOT_DIR should be /global/tools/Linux/arc_gnu_2021.09_prebuilt_elf32_le/arc-snps-elf/