Skip to content

cross-compile toolchain variant doesn't working properly with multilib toolchain #49587

@evgeniy-paltsev

Description

@evgeniy-paltsev

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):

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_COMPILE variable. I've checked the value of CROSS_COMPILE I'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/

Metadata

Metadata

Assignees

Labels

area: ToolchainsToolchainsbugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions