linker: ld: GNULD_LINKER_IS_BFD to indicate if ld.bfd is used

This adds a new output variable to FindGnuLd.cmake to indicate
if ld.bfd is found. Since we now ask the compilers for their
preferred ld.bfd linker, it may not match using the existing
string equal test to ${CROSS_COMPILE}ld.bfd. So set the new
variable GNULD_LINKER_IS_BFD to true if ld.bfd, and use it to
pass an extra argument to compiler to make it use ld.bfd.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2023-03-02 11:09:40 -08:00 committed by Anas Nashif
parent fb350bca10
commit 04fd862f68
2 changed files with 12 additions and 3 deletions

View File

@ -113,7 +113,8 @@ function(toolchain_ld_link_elf)
${ARGN} # input args to parse
)
if(${CMAKE_LINKER} STREQUAL "${CROSS_COMPILE}ld.bfd")
if((${CMAKE_LINKER} STREQUAL "${CROSS_COMPILE}ld.bfd") OR
${GNULD_LINKER_IS_BFD})
# ld.bfd was found so let's explicitly use that for linking, see #32237
set(use_linker "-fuse-ld=bfd")
endif()

View File

@ -17,6 +17,9 @@
# 'GNULD_VERSION_STRING'
# The version of GNU ld.
#
# 'GNULD_LINKER_IS_BFD'
# True if linker is ld.bfd (or compatible)
#
# Note that this will use CROSS_COMPILE, if defined,
# as a prefix to the linker executable.
@ -25,7 +28,9 @@ execute_process(COMMAND ${CMAKE_C_COMPILER} --print-prog-name=ld.bfd
OUTPUT_VARIABLE GNULD_LINKER
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT EXISTS "${GNULD_LINKER}")
if(EXISTS "${GNULD_LINKER}")
set(GNULD_LINKER_IS_BFD TRUE)
else()
# Need to clear it or else find_program() won't replace the value.
set(GNULD_LINKER)
@ -37,8 +42,11 @@ if(NOT EXISTS "${GNULD_LINKER}")
endif()
find_program(GNULD_LINKER ${CROSS_COMPILE}ld.bfd ${LD_SEARCH_PATH})
if(NOT GNULD_LINKER)
if(GNULD_LINKER)
set(GNULD_LINKER_IS_BFD TRUE)
else()
find_program(GNULD_LINKER ${CROSS_COMPILE}ld ${LD_SEARCH_PATH})
set(GNULD_LINKER_IS_BFD FALSE)
endif()
endif()