From 04fd862f68ba8545aad50c092fad1abceb960ac0 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Thu, 2 Mar 2023 11:09:40 -0800 Subject: [PATCH] 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 --- cmake/linker/ld/target.cmake | 3 ++- cmake/modules/FindGnuLd.cmake | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index 6a5f3c24228..52b12cd0d25 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -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() diff --git a/cmake/modules/FindGnuLd.cmake b/cmake/modules/FindGnuLd.cmake index d698cc44246..0232e3ae9b2 100644 --- a/cmake/modules/FindGnuLd.cmake +++ b/cmake/modules/FindGnuLd.cmake @@ -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()