Skip to content

Commit 2a76637

Browse files
dcpleungnashif
authored andcommitted
cmake: toolchain: cache property GNULD_LINKER_IS_BFD
Cache the property GNULD_LINKER_IS_BFD between cmake invocations. It is observed that, in repeated builds (2nd time and later), this property becomes true even for non-bfd compatible linker. So cache it to avoid any surprises. Fixes #56501 Signed-off-by: Daniel Leung <[email protected]>
1 parent 4a24943 commit 2a76637

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

cmake/modules/FindGnuLd.cmake

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,30 @@
2323
# Note that this will use CROSS_COMPILE, if defined,
2424
# as a prefix to the linker executable.
2525

26+
# GNULD_LINKER exists on repeated builds or defined manually...
27+
if(EXISTS "${GNULD_LINKER}")
28+
if(NOT DEFINED GNULD_LINKER_IS_BFD)
29+
# ... issue warning if GNULD_LINKER_IS_BFD is not already set.
30+
message(
31+
WARNING
32+
"GNULD_LINKER specified directly in cache, but GNULD_LINKER_IS_BFD is not "
33+
"defined. Assuming GNULD_LINKER_IS_BFD as OFF, please set GNULD_LINKER_IS_BFD "
34+
"to correct value in cache to silence this warning"
35+
)
36+
set(GNULD_LINKER_IS_BFD OFF)
37+
endif()
38+
39+
# Since GNULD_LINKER already exists, there is no need to find it again (below).
40+
return()
41+
endif()
42+
2643
# See if the compiler has a preferred linker
2744
execute_process(COMMAND ${CMAKE_C_COMPILER} --print-prog-name=ld.bfd
2845
OUTPUT_VARIABLE GNULD_LINKER
2946
OUTPUT_STRIP_TRAILING_WHITESPACE)
3047

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

4461
find_program(GNULD_LINKER ${CROSS_COMPILE}ld.bfd ${LD_SEARCH_PATH})
4562
if(GNULD_LINKER)
46-
set(GNULD_LINKER_IS_BFD TRUE)
63+
set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Linker BFD compatibility (inferred from binary)" FORCE)
4764
else()
4865
find_program(GNULD_LINKER ${CROSS_COMPILE}ld ${LD_SEARCH_PATH})
49-
set(GNULD_LINKER_IS_BFD FALSE)
66+
set(GNULD_LINKER_IS_BFD OFF CACHE BOOL "Linker BFD compatibility (inferred from binary)" FORCE)
5067
endif()
5168
endif()
5269

0 commit comments

Comments
 (0)