mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: "Kees Cook" <kees@kernel.org>, "Nicolas Schier" <nsc@kernel.org>,
	"Julian Braha" <julianbraha@gmail.com>,
	"Matthew Maurer" <mmaurer@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	"Gary Guo" <gary@garyguo.net>,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	linux-kbuild@vger.kernel.org,
	"Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Vegard Nossum" <vegard.nossum@oracle.com>,
	"Nauman Sabir" <officialnaumansabir@gmail.com>,
	"Tejun Heo" <tj@kernel.org>, "Nicolas Pitre" <nico@fluxnic.net>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Andrew Jones" <andrew.jones@linux.dev>,
	"Graham Roff" <grahamr@qti.qualcomm.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: [PATCH 2/3] kconfig: Replace "cc-option-bit" with "cc-option-str"
Date: Fri, 18 Sep 2026 17:59:26 -0700	[thread overview]
Message-ID: <20260919005929.4077729-2-kees@kernel.org> (raw)
In-Reply-To: <20260919005923.i.879-kees@kernel.org>

$(cc-option-bit) returns the flag it was given when the compiler accepts
it, and an empty string otherwise. It was originally only used
internally for machine bit flags, but it is generally useful[1].

Rename it to $(cc-option-str), which says what it returns rather than
what it was first used for, and extract the probe logic from the existing
$(cc-option) macro to reuse it. Additionally add support for an optional
fallback, much like the Kbuild cc-option macro. This can be used as:

	config CC_OPT_FOO
		def_string "$(cc-option-str,-fnew-option,-fold-option)"

If the fallback is omitted, it is just an empty string.

Build tested ARCH=x86_64 defconfig with GCC 16.2.0.

Assisted-by: LLM
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nsc@kernel.org>
Cc: Julian Braha <julianbraha@gmail.com>
Cc: Matthew Maurer <mmaurer@google.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Gary Guo <gary@garyguo.net>
Cc: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: <linux-kbuild@vger.kernel.org>
---
 scripts/Kconfig.include | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index fc10671c297c..4ef2b64e97be 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -23,9 +23,19 @@ success = $(if-success,$(1),y,n)
 # Return n if <command> exits with 0, y otherwise
 failure = $(if-success,$(1),n,y)
 
+# $(cc-probe,<flag>)
+# The command $(cc-option) and $(cc-option-str) test <flag> with. Not meant
+# to be called directly; use one of those two instead.
+cc-probe = trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o
+
 # $(cc-option,<flag>)
 # Return y if the compiler supports <flag>, n otherwise
-cc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o)
+cc-option = $(success,$(cc-probe,$(1)))
+
+# $(cc-option-str,<flag>[,<fallback>])
+# Return <flag> if the compiler supports it, <fallback> otherwise.
+# <fallback> defaults to an empty string and is returned untested.
+cc-option-str = $(if-success,$(cc-probe,$(1)),$(1),$(2))
 
 # $(ld-option,<flag>)
 # Return y if the linker supports <flag>, n otherwise
@@ -61,9 +71,8 @@ ld-version := $(shell,set -- $(ld-info) && echo $2)
 # machine bit flags
 #  $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
 #  $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
-cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
-m32-flag := $(cc-option-bit,-m32)
-m64-flag := $(cc-option-bit,-m64)
+m32-flag := $(cc-option-str,-m32)
+m64-flag := $(cc-option-str,-m64)
 
 # Test whether the compiler can link userspace applications
 cc_can_link_user = $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(1))
-- 
2.34.1


  parent reply	other threads:[~2026-09-19  0:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19  0:59 [PATCH 0/3] kconfig: Introduce cc-option-str Kees Cook
2026-09-19  0:59 ` [PATCH 1/3] kconfig: Add "def_string", "def_int" and "def_hex" Kees Cook
2026-09-19 15:34   ` Julian Braha
2026-09-20  3:40     ` Kees Cook
2026-09-19  0:59 ` Kees Cook [this message]
2026-09-19  0:59 ` [PATCH 3/3] kconfig: Add "ld-option-str" Kees Cook
2026-09-19  1:25 ` [PATCH 0/3] kconfig: Introduce cc-option-str Nathan Chancellor
2026-09-19 13:31   ` Lorenzo Stoakes (ARM)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260919005929.4077729-2-kees@kernel.org \
    --to=kees@kernel.org \
    --cc=andrew.jones@linux.dev \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=gary@garyguo.net \
    --cc=grahamr@qti.qualcomm.com \
    --cc=julianbraha@gmail.com \
    --cc=krzk@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mmaurer@google.com \
    --cc=nathan@kernel.org \
    --cc=nico@fluxnic.net \
    --cc=nsc@kernel.org \
    --cc=officialnaumansabir@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=tj@kernel.org \
    --cc=vegard.nossum@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®