Add the linker counterpart to $(cc-option-str), sharing a $(ld-probe)
with $(ld-option) the way the compiler macros share $(cc-probe). Like
$(cc-option-str), it can now be used as:

        config LD_OPT_FOO
                def_string "$(ld-option-str,--new-option,--old-option)"

An omitted fallback expands to the empty string.

Build tested ARCH=x86_64 defconfig with GCC 16.2.0, and checked against
GNU ld 2.47.

Assisted-by: LLM
Signed-off-by: Kees Cook <[email protected]>
---
Cc: Nathan Chancellor <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: Julian Braha <[email protected]>
Cc: Matthew Maurer <[email protected]>
Cc: Masahiro Yamada <[email protected]>
Cc: Miguel Ojeda <[email protected]>
Cc: "Thomas Weißschuh" <[email protected]>
Cc: Gary Guo <[email protected]>
Cc: <[email protected]>
---
 scripts/Kconfig.include | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index 4ef2b64e97be..622d21e6953f 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -37,9 +37,19 @@ cc-option = $(success,$(cc-probe,$(1)))
 # <fallback> defaults to an empty string and is returned untested.
 cc-option-str = $(if-success,$(cc-probe,$(1)),$(1),$(2))
 
+# $(ld-probe,<flag>)
+# The command $(ld-option) and $(ld-option-str) test <flag> with. Not meant
+# to be called directly; use one of those two instead.
+ld-probe = $(LD) -v $(1)
+
 # $(ld-option,<flag>)
 # Return y if the linker supports <flag>, n otherwise
-ld-option = $(success,$(LD) -v $(1))
+ld-option = $(success,$(ld-probe,$(1)))
+
+# $(ld-option-str,<flag>[,<fallback>])
+# Return <flag> if the linker supports it, <fallback> otherwise.
+# <fallback> defaults to an empty string and is returned untested.
+ld-option-str = $(if-success,$(ld-probe,$(1)),$(1),$(2))
 
 # $(as-instr,<instr>)
 # Return y if the assembler supports <instr>, n otherwise
-- 
2.34.1


Reply via email to