Skip to content

Commit 39f06e0

Browse files
tejlmandgalak
authored andcommitted
ld.bfd: ensure that ld.bfd is preferred over ld.
Fixes: #32237 When building for native_posix, then host tools are used. This means that gcc will link using `/usr/bin/ld` per default. If ld points to lld, then linking will fail. This commit will first look for ld.bfd, and if found then use -fuse-ld=bfd for linking. If ld.bfd is not found, then ld is used as fallback as that will be assumed to be the best working candidate. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent c1daae6 commit 39f06e0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cmake/linker/ld/target.cmake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
find_program(CMAKE_LINKER ${CROSS_COMPILE}ld PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
3+
if(DEFINED TOOLCHAIN_HOME)
4+
# When Toolchain home is defined, then we are cross-compiling, so only look
5+
# for linker in that path, else we are using host tools.
6+
set(LD_SEARCH_PATH PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
7+
endif()
8+
9+
find_program(CMAKE_LINKER ${CROSS_COMPILE}ld.bfd ${LD_SEARCH_PATH})
10+
if(NOT CMAKE_LINKER)
11+
find_program(CMAKE_LINKER ${CROSS_COMPILE}ld ${LD_SEARCH_PATH})
12+
endif()
413

514
set_ifndef(LINKERFLAGPREFIX -Wl)
615

@@ -82,9 +91,15 @@ function(toolchain_ld_link_elf)
8291
${ARGN} # input args to parse
8392
)
8493

94+
if(${CMAKE_LINKER} STREQUAL "${CROSS_COMPILE}ld.bfd")
95+
# ld.bfd was found so let's explicitly use that for linking, see #32237
96+
set(use_linker "-fuse-ld=bfd")
97+
endif()
98+
8599
target_link_libraries(
86100
${TOOLCHAIN_LD_LINK_ELF_TARGET_ELF}
87101
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_PRE_SCRIPT}
102+
${use_linker}
88103
${TOPT}
89104
${TOOLCHAIN_LD_LINK_ELF_LINKER_SCRIPT}
90105
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_POST_SCRIPT}

0 commit comments

Comments
 (0)