diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index 2d60e8ea63d8a..bae2930d964f2 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -6,6 +6,14 @@ set(CMAKE_LINKER ${GNULD_LINKER}) set_ifndef(LINKERFLAGPREFIX -Wl) +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 + list(APPEND TOOLCHAIN_LD_FLAGS -fuse-ld=bfd) + list(APPEND CMAKE_REQUIRED_FLAGS -fuse-ld=bfd) + string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") +endif() + if(NOT "${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "host") if(CONFIG_CPP_EXCEPTIONS AND LIBGCC_DIR) # When building with C++ Exceptions, it is important that crtbegin and crtend @@ -118,16 +126,9 @@ function(toolchain_ld_link_elf) ${ARGN} # input args to parse ) - 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() - target_link_libraries( ${TOOLCHAIN_LD_LINK_ELF_TARGET_ELF} ${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_PRE_SCRIPT} - ${use_linker} ${TOPT} ${TOOLCHAIN_LD_LINK_ELF_LINKER_SCRIPT} ${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_POST_SCRIPT} diff --git a/cmake/linker/lld/target.cmake b/cmake/linker/lld/target.cmake index 5deab047100a2..d65ec4bb269ec 100644 --- a/cmake/linker/lld/target.cmake +++ b/cmake/linker/lld/target.cmake @@ -6,6 +6,10 @@ set(CMAKE_LINKER ${LLVMLLD_LINKER}) set_ifndef(LINKERFLAGPREFIX -Wl) +list(APPEND TOOLCHAIN_LD_FLAGS -fuse-ld=lld) +list(APPEND CMAKE_REQUIRED_FLAGS -fuse-ld=lld) +string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + # Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen} # NOTE: ${linker_script_gen} will be produced at build-time; not at configure-time macro(configure_linker_script linker_script_gen linker_pass_define) diff --git a/cmake/linker/lld/target_baremetal.cmake b/cmake/linker/lld/target_baremetal.cmake index 6faf8f50cace4..24e6e36122d33 100644 --- a/cmake/linker/lld/target_baremetal.cmake +++ b/cmake/linker/lld/target_baremetal.cmake @@ -12,13 +12,6 @@ macro(toolchain_ld_baremetal) ${LINKERFLAGPREFIX},-N ) - # Force LLVM to use built-in lld linker - if(NOT CONFIG_LLVM_USE_LD) - zephyr_ld_options( - -fuse-ld=lld - ) - endif() - # Funny thing is if this is set to =error, some architectures will # skip this flag even though the compiler flag check passes # (e.g. ARC and Xtensa). So warning should be the default for now.