[PATCH 3/3] kconfig: Add "ld-option-str"

From: Kees Cook

Date: Fri Sep 18 2026 - 21:00:31 EST


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 <kees@xxxxxxxxxx>
---
Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
Cc: Nicolas Schier <nsc@xxxxxxxxxx>
Cc: Julian Braha <julianbraha@xxxxxxxxx>
Cc: Matthew Maurer <mmaurer@xxxxxxxxxx>
Cc: Masahiro Yamada <masahiroy@xxxxxxxxxx>
Cc: Miguel Ojeda <ojeda@xxxxxxxxxx>
Cc: "Thomas Weißschuh" <thomas.weissschuh@xxxxxxxxxxxxx>
Cc: Gary Guo <gary@xxxxxxxxxxx>
Cc: <linux-kbuild@xxxxxxxxxxxxxxx>
---
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