Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions cmake/modules/FindGnuLd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@
# Note that this will use CROSS_COMPILE, if defined,
# as a prefix to the linker executable.

# GNULD_LINKER exists on repeated builds or defined manually...
if(EXISTS "${GNULD_LINKER}")
if(NOT DEFINED GNULD_LINKER_IS_BFD)
# ... issue warning if GNULD_LINKER_IS_BFD is not already set.
message(
WARNING
"GNULD_LINKER specified directly in cache, but GNULD_LINKER_IS_BFD is not "
"defined. Assuming GNULD_LINKER_IS_BFD as OFF, please set GNULD_LINKER_IS_BFD "
"to correct value in cache to silence this warning"
)
set(GNULD_LINKER_IS_BFD OFF)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the early return should happen here.

If for any reason GNULD_LINKER has been pointed out manually by a user, then we should not try to detect GNULD_LINKER_IS_BFD based on current compiler, hence I believe we should move the return here:

Suggested change
endif()
endif()
return()


# Since GNULD_LINKER already exists, there is no need to find it again (below).
return()
endif()

# See if the compiler has a preferred linker
execute_process(COMMAND ${CMAKE_C_COMPILER} --print-prog-name=ld.bfd
OUTPUT_VARIABLE GNULD_LINKER
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(EXISTS "${GNULD_LINKER}")
set(GNULD_LINKER_IS_BFD TRUE)
set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Linker BFD compatibility (compiler reported)" FORCE)
else()
# Need to clear it or else find_program() won't replace the value.
set(GNULD_LINKER)
Expand All @@ -43,10 +60,10 @@ else()

find_program(GNULD_LINKER ${CROSS_COMPILE}ld.bfd ${LD_SEARCH_PATH})
if(GNULD_LINKER)
set(GNULD_LINKER_IS_BFD TRUE)
set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Linker BFD compatibility (inferred from binary)" FORCE)
else()
find_program(GNULD_LINKER ${CROSS_COMPILE}ld ${LD_SEARCH_PATH})
set(GNULD_LINKER_IS_BFD FALSE)
set(GNULD_LINKER_IS_BFD OFF CACHE BOOL "Linker BFD compatibility (inferred from binary)" FORCE)
endif()
endif()

Expand Down