Skip to content

Commit

Permalink
linker: ld: GNULD_LINKER_IS_BFD to indicate if ld.bfd is used
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dcpleung authored and nashif committed Mar 29, 2023
1 parent fb350bc commit 04fd862
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmake/linker/ld/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions cmake/modules/FindGnuLd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)

Expand All @@ -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()

Expand Down

0 comments on commit 04fd862

Please sign in to comment.