[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGXu5jJkqgAYexAq27fK75cLRaWaHwac9oTMWqgqbDVZxApVFA@mail.gmail.com>
Date: Tue, 27 Mar 2018 20:45:08 -0700
From: Kees Cook <keescook@...omium.org>
To: Masahiro Yamada <yamada.masahiro@...ionext.com>
Cc: linux-kbuild <linux-kbuild@...r.kernel.org>,
Sam Ravnborg <sam@...nborg.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Arnd Bergmann <arnd@...db.de>,
Ulf Magnusson <ulfalizer@...il.com>,
Thomas Gleixner <tglx@...utronix.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Randy Dunlap <rdunlap@...radead.org>,
"Luis R . Rodriguez" <mcgrof@...nel.org>,
Nicolas Pitre <nico@...aro.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 09/21] kconfig: add 'macro' keyword to support
user-defined function
On Mon, Mar 26, 2018 at 10:29 PM, Masahiro Yamada
<yamada.masahiro@...ionext.com> wrote:
> Now, we got a basic ability to test compiler capability in Kconfig.
>
> config CC_HAS_STACKPROTECTOR
> def_bool $(shell (($CC -Werror -fstack-protector -c -x c /dev/null -o /dev/null) && echo y) || echo n)
>
> This works, but it is ugly to repeat this long boilerplate.
>
> We want to describe like this:
>
> config CC_HAS_STACKPROTECTOR
> bool
> default $(cc-option -fstack-protector)
>
> It is straight-forward to add a new function, but I do not like to
> hard-code specialized functions like this. Hence, here is another
> feature to add functions from Kconfig files.
>
> A user-defined function is defined with a special keyword 'macro'.
> It can be referenced in the same way as built-in functions. This
> feature was also inspired by Makefile where user-defined functions
> are referenced by $(call func-name, args...), but I omitted the 'call'
> to makes it shorter.
>
> The macro definition can contain $(1), $(2), ... which will be replaced
> with arguments from the caller. The macro works just as a textual
> shorthand, which is also expanded in the lexer phase.
>
> [Example Code]
>
> macro success $(shell ($(1) && echo y) || echo n)
>
> config TRUE
> bool "true"
> default $(success true)
>
> config FALSE
> bool "false"
> default $(success false)
>
> [Result]
>
> $ make -s alldefconfig
> $ tail -n 2 .config
> CONFIG_TRUE=y
> # CONFIG_FALSE is not set
>
> [Example Code]
>
> macro success $(shell ($(1) && echo y) || echo n)
>
> macro cc-option $(success $CC -Werror $(1) -c -x c /dev/null -o /dev/null)
>
> config CC_HAS_STACKPROTECTOR
> def_bool $(cc-option -fstack-protector)
>
> [Result]
> $ make -s alldefconfig
> $ tail -n 1 .config
> CONFIG_CC_HAS_STACKPROTECTOR=y
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@...ionext.com>
Cool, I like this "macro" idea for keeping this clean.
> ---
>
> Reminder for myself:
> Update Documentation/kbuild/kconfig-language.txt
Yes please. :)
Otherwise, looks good!
-Kees
--
Kees Cook
Pixel Security
Powered by blists - more mailing lists