* [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
@ 2018-02-16 18:38 Masahiro Yamada
2018-02-16 18:38 ` [PATCH 21/23] gcc-plugins: move GCC version check for PowerPC " Masahiro Yamada
2018-02-18 22:13 ` [PATCH 00/23] kconfig: move compiler capability tests " Sam Ravnborg
0 siblings, 2 replies; 16+ messages in thread
From: Masahiro Yamada @ 2018-02-16 18:38 UTC (permalink / raw)
To: linux-kbuild, Linus Torvalds
Cc: Greg Kroah-Hartman, Arnd Bergmann, Kees Cook, Randy Dunlap,
Ulf Magnusson, Sam Ravnborg, Michal Marek, Masahiro Yamada,
Peter Oberparleiter, kernel-hardening, Jonathan Corbet,
sparclinux, linux-sh, x86, Thomas Gleixner, Rich Felker,
Jeff Dike, H. Peter Anvin, user-mode-linux-devel, Yoshinori Sato,
Benjamin Herrenschmidt, linuxppc-dev, Paul Mackerras,
user-mode-linux-user, Ingo Molnar, David S. Miller,
Michael Ellerman, linux-doc, linux-kernel, Richard Weinberger,
Emese Revfy
I brushed up the implementation in this version.
In the previous RFC, CC_HAS_ was described by using 'option shell=',
like this:
config CC_HAS_STACKPROTECTOR
bool
option shell="$CC -Werror -fstack-protector -c -x c /dev/null"
After I thought a bit more, the following syntax is more grammatical,
and flexible.
config CC_HAS_STACKPROTECTOR
bool
default $(shell $CC -Werror -fstack-protector -c -x c /dev/null)
This version supports cc-option, so it can be written as:
config CC_HAS_STACKPROTECTOR
bool
default $(cc-option -fstack-protector)
To support this in a clean way, I introduced a new concept 'function'
like we see in Makefiles.
$(shell ...) is a built-in function. $(cc-option ...) is implemented
as macro (user-defined function).
I also try cleaning of stack-protector, gcc-plugins since the Makefile
is so dirty.
Current limitations:
Dependency on outside scripts.
For example, scripts/gcc-x86_64-has-stack-protecter.sh is run from
Kconfig. When the shell script is updated, should Kconfig be re-run
automatically?
Inter-option dependency:
$(call cc-option,...) in Makefile accumulates added options to
KBUILD_CFLAGS, but it is difficult to do it in Kconfig.
If a compiler option check is dependent on another option,
this is a difficult case. Let's see how significant it is.
Functions are evaluated statically:
Functions are only expanded when parsing the Kconfig. So, it can
not refelect user configuration. If this is required, $(shell )
must be dynamically re-calculated depending on other symbols.
But, this is difficult, and may cause performance issue.
Masahiro Yamada (22):
kbuild: remove kbuild cache
kbuild: remove CONFIG_CROSS_COMPILE support
kconfig: add xstrdup() helper
kconfig: set SYMBOL_AUTO to the symbol marked with defconfig_list
kconfig: move and rename sym_expand_string_value()
kconfig: reference environments directly and remove 'option env='
syntax
kconfig: add function support and implement 'shell' function
kconfig: add 'macro' keyword to support user-defined function
kconfig: add 'cc-option' macro
stack-protector: test compiler capability in Kconfig and drop AUTO
mode
kconfig: add 'shell-stdout' function
kconfig: replace $UNAME_RELEASE with function call
kconfig: expand environments/functions in (main)menu, comment, prompt
kconfig: show compiler version text in the top comment
kconfig: add CC_IS_GCC and GCC_VERSION
kconfig: add CC_IS_CLANG and CLANG_VERSION
gcov: remove CONFIG_GCOV_FORMAT_AUTODETECT
kcov: imply GCC_PLUGINS and GCC_PLUGIN_SANCOV instead of select'ing
them
gcc-plugins: always build plugins with C++
gcc-plugins: move GCC version check for PowerPC to Kconfig
gcc-plugins: test GCC plugin support in Kconfig
gcc-plugins: enable GCC_PLUGINS for COMPILE_TEST
Sami Tolvanen (1):
kbuild: add clang-version.sh
Documentation/kbuild/kconfig-language.txt | 8 -
Kconfig | 4 +-
Makefile | 103 ++----------
arch/Kconfig | 43 +++--
arch/powerpc/Kconfig | 2 +-
arch/sh/Kconfig | 4 +-
arch/sparc/Kconfig | 4 +-
arch/tile/Kconfig | 2 +-
arch/um/Kconfig.common | 4 -
arch/x86/Kconfig | 12 +-
arch/x86/um/Kconfig | 4 +-
init/Kconfig | 44 +++---
kernel/gcov/Kconfig | 18 +--
kernel/gcov/Makefile | 2 -
lib/Kconfig.debug | 7 +-
scripts/Kbuild.include | 101 ++----------
scripts/Makefile.gcc-plugins | 95 ++++-------
scripts/clang-version.sh | 31 ++++
scripts/gcc-plugin.sh | 37 +----
scripts/gcc-plugins/Makefile | 15 +-
scripts/gcc-x86_32-has-stack-protector.sh | 7 +-
scripts/gcc-x86_64-has-stack-protector.sh | 5 -
scripts/kconfig/confdata.c | 33 +---
scripts/kconfig/function.c | 251 ++++++++++++++++++++++++++++++
scripts/kconfig/kconf_id.c | 2 +-
scripts/kconfig/kxgettext.c | 2 +-
scripts/kconfig/lkc.h | 6 +-
scripts/kconfig/lkc_proto.h | 7 +-
scripts/kconfig/menu.c | 6 +-
scripts/kconfig/symbol.c | 139 +++--------------
scripts/kconfig/util.c | 186 ++++++++++++++++++++--
scripts/kconfig/zconf.l | 40 ++++-
scripts/kconfig/zconf.y | 48 +++---
33 files changed, 687 insertions(+), 585 deletions(-)
create mode 100755 scripts/clang-version.sh
create mode 100644 scripts/kconfig/function.c
--
2.7.4
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 21/23] gcc-plugins: move GCC version check for PowerPC to Kconfig
2018-02-16 18:38 [PATCH 00/23] kconfig: move compiler capability tests to Kconfig Masahiro Yamada
@ 2018-02-16 18:38 ` Masahiro Yamada
2018-02-22 5:04 ` Andrew Donnellan
2018-02-18 22:13 ` [PATCH 00/23] kconfig: move compiler capability tests " Sam Ravnborg
1 sibling, 1 reply; 16+ messages in thread
From: Masahiro Yamada @ 2018-02-16 18:38 UTC (permalink / raw)
To: linux-kbuild, Linus Torvalds
Cc: Greg Kroah-Hartman, Arnd Bergmann, Kees Cook, Randy Dunlap,
Ulf Magnusson, Sam Ravnborg, Michal Marek, Masahiro Yamada,
Michael Ellerman, Benjamin Herrenschmidt, linux-kernel,
Paul Mackerras, kernel-hardening, linuxppc-dev, Emese Revfy
For PowerPC, GCC 5.2 is the requirement for GCC plugins. Move the
version check to Kconfig, and remove the ugly checker.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
arch/powerpc/Kconfig | 2 +-
scripts/Makefile.gcc-plugins | 8 --------
2 files changed, 1 insertion(+), 9 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 73ce5dd..b8474c2 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -195,7 +195,7 @@ config PPC
select HAVE_FTRACE_MCOUNT_RECORD
select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_FUNCTION_TRACER
- select HAVE_GCC_PLUGINS
+ select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200
select HAVE_GENERIC_GUP
select HAVE_HW_BREAKPOINT if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx)
select HAVE_IDE
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index b0f9108..25da4c0 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -56,14 +56,6 @@ gcc-plugins-check: FORCE
ifdef CONFIG_GCC_PLUGINS
ifeq ($(PLUGINCC),)
ifneq ($(GCC_PLUGINS_CFLAGS),)
- # Various gccs between 4.5 and 5.1 have bugs on powerpc due to missing
- # header files. gcc <= 4.6 doesn't work at all, gccs from 4.8 to 5.1 have
- # issues with 64-bit targets.
- ifeq ($(ARCH),powerpc)
- ifeq ($(call cc-ifversion, -le, 0501, y), y)
- @echo "Cannot use CONFIG_GCC_PLUGINS: plugin support on gcc <= 5.1 is buggy on powerpc, please upgrade to gcc 5.2 or newer" >&2 && exit 1
- endif
- endif
$(Q)$(srctree)/scripts/gcc-plugin.sh --show-error $(HOSTCXX) $(CC) || true
@echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1
endif
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-16 18:38 [PATCH 00/23] kconfig: move compiler capability tests to Kconfig Masahiro Yamada
2018-02-16 18:38 ` [PATCH 21/23] gcc-plugins: move GCC version check for PowerPC " Masahiro Yamada
@ 2018-02-18 22:13 ` Sam Ravnborg
2018-02-19 15:18 ` Ulf Magnusson
1 sibling, 1 reply; 16+ messages in thread
From: Sam Ravnborg @ 2018-02-18 22:13 UTC (permalink / raw)
To: Masahiro Yamada
Cc: linux-kbuild, Linus Torvalds, Greg Kroah-Hartman, Arnd Bergmann,
Kees Cook, Randy Dunlap, Ulf Magnusson, Michal Marek,
Peter Oberparleiter, kernel-hardening, Jonathan Corbet,
sparclinux, linux-sh, x86, Thomas Gleixner, Rich Felker,
Jeff Dike, H. Peter Anvin, user-mode-linux-devel, Yoshinori Sato,
Benjamin Herrenschmidt, linuxppc-dev, Paul Mackerras,
user-mode-linux-user, Ingo Molnar, David S. Miller,
Michael Ellerman, linux-doc, linux-kernel, Richard Weinberger,
Emese Revfy
Hi Masahiro.
On Sat, Feb 17, 2018 at 03:38:28AM +0900, Masahiro Yamada wrote:
> I brushed up the implementation in this version.
>
> In the previous RFC, CC_HAS_ was described by using 'option shell=',
> like this:
>
> config CC_HAS_STACKPROTECTOR
> bool
> option shell="$CC -Werror -fstack-protector -c -x c /dev/null"
>
> After I thought a bit more, the following syntax is more grammatical,
> and flexible.
>
> config CC_HAS_STACKPROTECTOR
> bool
> default $(shell $CC -Werror -fstack-protector -c -x c /dev/null)
Looks good - but maybe we should go one step further.
So we in the syntax explicit handles:
- shell commands
- other commands, defined as strings
- environment variables
- config variables
Each case is explicit - so the reader is not confused what is used when.
$(shell foo) - output of the shell command foo. Uses $SHELL as the shell.
May include optional paramters.
foo may be a config variable referenced using ${} or a config variable prefixed with $
Example:
config BUILD_DIR
string
default $(shell cd ${objtree}; pwd)
$(call bar) - output of the bar command that may take optional parameters.
bar may be a text string, a config variable or an environment variable
The definition of bar may reference the parameters using $(1), $(2)
In this context a config variable needs to be prefixed with $
Example:
config reverse
string
default $(2) $(1)
config NEW_ORDER
string
$(call $reverse, A, B) # Will assign REVERSE the value "B A"
Example2:
config CC_OPTION
string
default $(shell ${srctree}/scripts/cc-option ${CC} $(1) $(2))
config CC_OPTIMIZE
string
$(call $CC_OPTION, -Oz, -Os)
${FOO} - environment variable
The above is inspired by how make implement similar functionality.
I'm not happy that we in one context can reference CONFIG variables
directly, but inside the $(call ...) and $(shell ...) needs the $ prefix.
But I could not come up with something un-ambigious where this could be avoided.
The above proposal include the functionality of the macro stuff proposed in this patch-set.
But with a simpler syntax and we keep all the other kconfig logic (depends on etc) - so
users will not be limited in their creativity.
> Current limitations:
>
> Dependency on outside scripts.
> Inter-option dependency:
> Functions are evaluated statically:
Same limitations exists with the syntax suggested above.
Sam
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-18 22:13 ` [PATCH 00/23] kconfig: move compiler capability tests " Sam Ravnborg
@ 2018-02-19 15:18 ` Ulf Magnusson
2018-02-21 7:38 ` Masahiro Yamada
0 siblings, 1 reply; 16+ messages in thread
From: Ulf Magnusson @ 2018-02-19 15:18 UTC (permalink / raw)
To: Sam Ravnborg
Cc: Masahiro Yamada, Linux Kbuild mailing list, Linus Torvalds,
Greg Kroah-Hartman, Arnd Bergmann, Kees Cook, Randy Dunlap,
Michal Marek, Peter Oberparleiter, kernel-hardening,
Jonathan Corbet, sparclinux, linux-sh, x86, Thomas Gleixner,
Rich Felker, Jeff Dike, H. Peter Anvin, user-mode-linux-devel,
Yoshinori Sato, Benjamin Herrenschmidt, linuxppc-dev,
Paul Mackerras, user-mode-linux-user, Ingo Molnar,
David S. Miller, Michael Ellerman, linux-doc,
Linux Kernel Mailing List, Richard Weinberger, Emese Revfy
Hello,
On Sun, Feb 18, 2018 at 11:13 PM, Sam Ravnborg <sam@ravnborg.org> wrote:
> Hi Masahiro.
>
> On Sat, Feb 17, 2018 at 03:38:28AM +0900, Masahiro Yamada wrote:
>> I brushed up the implementation in this version.
>>
>> In the previous RFC, CC_HAS_ was described by using 'option shell=',
>> like this:
>>
>> config CC_HAS_STACKPROTECTOR
>> bool
>> option shell="$CC -Werror -fstack-protector -c -x c /dev/null"
>>
>> After I thought a bit more, the following syntax is more grammatical,
>> and flexible.
>>
>> config CC_HAS_STACKPROTECTOR
>> bool
>> default $(shell $CC -Werror -fstack-protector -c -x c /dev/null)
>
> Looks good - but maybe we should go one step further.
>
> So we in the syntax explicit handles:
> - shell commands
> - other commands, defined as strings
> - environment variables
> - config variables
>
> Each case is explicit - so the reader is not confused what is used when.
>
> $(shell foo) - output of the shell command foo. Uses $SHELL as the shell.
> May include optional paramters.
> foo may be a config variable referenced using ${} or a config variable prefixed with $
> Example:
>
> config BUILD_DIR
> string
> default $(shell cd ${objtree}; pwd)
>
> $(call bar) - output of the bar command that may take optional parameters.
> bar may be a text string, a config variable or an environment variable
> The definition of bar may reference the parameters using $(1), $(2)
> In this context a config variable needs to be prefixed with $
>
> Example:
>
> config reverse
> string
> default $(2) $(1)
>
> config NEW_ORDER
> string
> $(call $reverse, A, B) # Will assign REVERSE the value "B A"
>
>
> Example2:
>
> config CC_OPTION
> string
> default $(shell ${srctree}/scripts/cc-option ${CC} $(1) $(2))
>
> config CC_OPTIMIZE
> string
> $(call $CC_OPTION, -Oz, -Os)
>
>
> ${FOO} - environment variable
>
> The above is inspired by how make implement similar functionality.
>
> I'm not happy that we in one context can reference CONFIG variables
> directly, but inside the $(call ...) and $(shell ...) needs the $ prefix.
> But I could not come up with something un-ambigious where this could be avoided.
I think we should be careful about allowing references to config
symbols. It mixes up the parsing and evaluation phases, since $() is
expanded during parsing (which I consider a feature and think is
needed to retain sanity).
Patch 06/23 removes the last existing instance of symbol references in
strings by getting rid of 'option env'. That's an improvement to me.
We shouldn't add it back.
>
> The above proposal include the functionality of the macro stuff proposed in this patch-set.
> But with a simpler syntax and we keep all the other kconfig logic (depends on etc) - so
> users will not be limited in their creativity.
>
>> Current limitations:
>>
>> Dependency on outside scripts.
>> Inter-option dependency:
>> Functions are evaluated statically:
>
> Same limitations exists with the syntax suggested above.
>
> Sam
Cheers,
Ulf
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-19 15:18 ` Ulf Magnusson
@ 2018-02-21 7:38 ` Masahiro Yamada
2018-02-21 9:56 ` Arnd Bergmann
0 siblings, 1 reply; 16+ messages in thread
From: Masahiro Yamada @ 2018-02-21 7:38 UTC (permalink / raw)
To: Ulf Magnusson
Cc: Sam Ravnborg, Linux Kbuild mailing list, Linus Torvalds,
Greg Kroah-Hartman, Arnd Bergmann, Kees Cook, Randy Dunlap,
Michal Marek, Peter Oberparleiter, kernel-hardening,
Jonathan Corbet, sparclinux, Linux-sh list, X86 ML,
Thomas Gleixner, Rich Felker, Jeff Dike, H. Peter Anvin,
user-mode-linux-devel, Yoshinori Sato, Benjamin Herrenschmidt,
linuxppc-dev, Paul Mackerras, user-mode-linux-user, Ingo Molnar,
David S. Miller, Michael Ellerman, open list:DOCUMENTATION,
Linux Kernel Mailing List, Richard Weinberger, Emese Revfy
2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
>>
>> I'm not happy that we in one context can reference CONFIG variables
>> directly, but inside the $(call ...) and $(shell ...) needs the $ prefix.
>> But I could not come up with something un-ambigious where this could be avoided.
>
> I think we should be careful about allowing references to config
> symbols. It mixes up the parsing and evaluation phases, since $() is
> expanded during parsing (which I consider a feature and think is
> needed to retain sanity).
>
> Patch 06/23 removes the last existing instance of symbol references in
> strings by getting rid of 'option env'. That's an improvement to me.
> We shouldn't add it back.
This is really important design decision,
so I'd like to hear a little more from experts.
For example, x86 allows users to choose sub-arch, either 'i386' or 'x86_64'.
https://github.com/torvalds/linux/blob/v4.16-rc2/arch/x86/Kconfig#L4
If the user toggles CONFIG_64BIT,
the bi-arch compiler will work in a slightly different mode
(at least, back-end parts)
So, my question is, is there a case,
$(cc-option, -m32 -foo) is y, but
$(cc-option, -m64 -foo) is n ?
(or vice versa)
If the answer is yes, $(cc-option -foo) would have to be re-calculated
every time CONFIG_64BIT is toggled.
This is what I'd like to avoid, though.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 7:38 ` Masahiro Yamada
@ 2018-02-21 9:56 ` Arnd Bergmann
2018-02-21 10:20 ` Masahiro Yamada
0 siblings, 1 reply; 16+ messages in thread
From: Arnd Bergmann @ 2018-02-21 9:56 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Ulf Magnusson, Rich Felker, Linux-sh list, Kernel Hardening,
Paul Mackerras, H. Peter Anvin, sparclinux, Sam Ravnborg,
uml-devel, Yoshinori Sato, Jonathan Corbet, X86 ML,
Linus Torvalds, Ingo Molnar, Emese Revfy, Kees Cook,
Linux Kbuild mailing list, Peter Oberparleiter, Jeff Dike,
user-mode-linux-user, Thomas Gleixner, Michal Marek,
Greg Kroah-Hartman, Randy Dunlap, open list:DOCUMENTATION,
Linux Kernel Mailing List, Richard Weinberger, linuxppc-dev,
David S. Miller
On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
>
>>>
>>> I'm not happy that we in one context can reference CONFIG variables
>>> directly, but inside the $(call ...) and $(shell ...) needs the $ prefix.
>>> But I could not come up with something un-ambigious where this could be avoided.
>>
>> I think we should be careful about allowing references to config
>> symbols. It mixes up the parsing and evaluation phases, since $() is
>> expanded during parsing (which I consider a feature and think is
>> needed to retain sanity).
>>
>> Patch 06/23 removes the last existing instance of symbol references in
>> strings by getting rid of 'option env'. That's an improvement to me.
>> We shouldn't add it back.
>
>
> This is really important design decision,
> so I'd like to hear a little more from experts.
>
>
> For example, x86 allows users to choose sub-arch, either 'i386' or 'x86_64'.
>
> https://github.com/torvalds/linux/blob/v4.16-rc2/arch/x86/Kconfig#L4
>
>
>
> If the user toggles CONFIG_64BIT,
> the bi-arch compiler will work in a slightly different mode
> (at least, back-end parts)
>
> So, my question is, is there a case,
>
> $(cc-option, -m32 -foo) is y, but
> $(cc-option, -m64 -foo) is n ?
> (or vice versa)
>
>
> If the answer is yes, $(cc-option -foo) would have to be re-calculated
> every time CONFIG_64BIT is toggled.
>
> This is what I'd like to avoid, though.
The -m32/-m64 trick (and -mbig-endian/-mlittle-endian on other architectures
as well as a couple of other flags) only works if the compiler is configured to
support it. In other cases (e.g. big-endian xtensa), the kernel always
detects what the compiler does and silently configures itself to match
using Makefile logic.
On x86, compilers are usually built as bi-arch, but you can build one that
only allows one of them.
I can see two reasonable ways out:
- we don't use $(cc-option -foo) in a case like this, and instead require the
user to have a matching toolchain.
- we could make the 32/64 selection on x86 a 'choice' statement where
each option depends on both the ARCH= variable and the
$(cc-option, -m32)/ $(cc-option, -m64) output.
Arnd
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 9:56 ` Arnd Bergmann
@ 2018-02-21 10:20 ` Masahiro Yamada
2018-02-21 10:52 ` Arnd Bergmann
0 siblings, 1 reply; 16+ messages in thread
From: Masahiro Yamada @ 2018-02-21 10:20 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Ulf Magnusson, Rich Felker, Linux-sh list, Kernel Hardening,
Paul Mackerras, H. Peter Anvin, sparclinux, Sam Ravnborg,
uml-devel, Yoshinori Sato, Jonathan Corbet, X86 ML,
Linus Torvalds, Ingo Molnar, Emese Revfy, Kees Cook,
Linux Kbuild mailing list, Peter Oberparleiter, Jeff Dike,
user-mode-linux-user, Thomas Gleixner, Michal Marek,
Greg Kroah-Hartman, Randy Dunlap, open list:DOCUMENTATION,
Linux Kernel Mailing List, Richard Weinberger, linuxppc-dev,
David S. Miller
2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
>>
>>>>
>>>> I'm not happy that we in one context can reference CONFIG variables
>>>> directly, but inside the $(call ...) and $(shell ...) needs the $ prefix.
>>>> But I could not come up with something un-ambigious where this could be avoided.
>>>
>>> I think we should be careful about allowing references to config
>>> symbols. It mixes up the parsing and evaluation phases, since $() is
>>> expanded during parsing (which I consider a feature and think is
>>> needed to retain sanity).
>>>
>>> Patch 06/23 removes the last existing instance of symbol references in
>>> strings by getting rid of 'option env'. That's an improvement to me.
>>> We shouldn't add it back.
>>
>>
>> This is really important design decision,
>> so I'd like to hear a little more from experts.
>>
>>
>> For example, x86 allows users to choose sub-arch, either 'i386' or 'x86_64'.
>>
>> https://github.com/torvalds/linux/blob/v4.16-rc2/arch/x86/Kconfig#L4
>>
>>
>>
>> If the user toggles CONFIG_64BIT,
>> the bi-arch compiler will work in a slightly different mode
>> (at least, back-end parts)
>>
>> So, my question is, is there a case,
>>
>> $(cc-option, -m32 -foo) is y, but
>> $(cc-option, -m64 -foo) is n ?
>> (or vice versa)
>>
>>
>> If the answer is yes, $(cc-option -foo) would have to be re-calculated
>> every time CONFIG_64BIT is toggled.
>>
>> This is what I'd like to avoid, though.
>
> The -m32/-m64 trick (and -mbig-endian/-mlittle-endian on other architectures
> as well as a couple of other flags) only works if the compiler is configured to
> support it. In other cases (e.g. big-endian xtensa), the kernel always
> detects what the compiler does and silently configures itself to match
> using Makefile logic.
>
> On x86, compilers are usually built as bi-arch, but you can build one that
> only allows one of them.
>
> I can see two reasonable ways out:
>
> - we don't use $(cc-option -foo) in a case like this, and instead require the
> user to have a matching toolchain.
> - we could make the 32/64 selection on x86 a 'choice' statement where
> each option depends on both the ARCH= variable and the
> $(cc-option, -m32)/ $(cc-option, -m64) output.
>
> Arnd
Let me clarify my concern.
When we test the compiler flag, is there a case
where a particular flag depends on -m{32,64} ?
For example, is there a compiler that supports -fstack-protector
for 64bit mode, but unsupports it for 32bit mode?
$(cc-option -m32) -> y
$(cc-option -m64) -> y
$(cc-option -fstack-protector) -> y
$(cc-option -m32 -fstack-protector) -> n
$(cc-option -m64 -fstack-protector) -> y
I guess this is unlikely to happen,
but I am not whether it is zero possibility.
If this could happen,
$(cc-option ) must be evaluated together with
correct bi-arch option (either -m32 or -m64).
Currently, -m32/-m64 is specified in Makefile,
but we are moving compiler tests to Kconfig
and, CONFIG_64BIT can be dynamically toggled in Kconfig.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 10:20 ` Masahiro Yamada
@ 2018-02-21 10:52 ` Arnd Bergmann
2018-02-21 12:57 ` Masahiro Yamada
0 siblings, 1 reply; 16+ messages in thread
From: Arnd Bergmann @ 2018-02-21 10:52 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Rich Felker, Kernel Hardening, X86 ML, Paul Mackerras,
H. Peter Anvin, sparclinux, Sam Ravnborg, Yoshinori Sato,
Jonathan Corbet, Richard Weinberger, Linux-sh list, Ingo Molnar,
Emese Revfy, Kees Cook, uml-devel, Linux Kbuild mailing list,
Peter Oberparleiter, Jeff Dike, linuxppc-dev,
user-mode-linux-user, Thomas Gleixner, Michal Marek,
Ulf Magnusson, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List,
Linus Torvalds, David S. Miller
On Wed, Feb 21, 2018 at 11:20 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> 2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
>> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
>> <yamada.masahiro@socionext.com> wrote:
>>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
>
> Let me clarify my concern.
>
> When we test the compiler flag, is there a case
> where a particular flag depends on -m{32,64} ?
>
> For example, is there a compiler that supports -fstack-protector
> for 64bit mode, but unsupports it for 32bit mode?
>
> $(cc-option -m32) -> y
> $(cc-option -m64) -> y
> $(cc-option -fstack-protector) -> y
> $(cc-option -m32 -fstack-protector) -> n
> $(cc-option -m64 -fstack-protector) -> y
>
> I guess this is unlikely to happen,
> but I am not whether it is zero possibility.
>
> If this could happen,
> $(cc-option ) must be evaluated together with
> correct bi-arch option (either -m32 or -m64).
>
>
> Currently, -m32/-m64 is specified in Makefile,
> but we are moving compiler tests to Kconfig
> and, CONFIG_64BIT can be dynamically toggled in Kconfig.
I don't think it can happen for this particular combination (stack protector
and word size), but I'm sure we'll eventually run into options that
need to be tested in combination. For the current CFLAGS_KERNEL
setting, we definitely have the case of needing the variables to be
evaluated in a specific order.
Arnd
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 10:52 ` Arnd Bergmann
@ 2018-02-21 12:57 ` Masahiro Yamada
2018-02-21 16:03 ` Arnd Bergmann
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Masahiro Yamada @ 2018-02-21 12:57 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Rich Felker, Kernel Hardening, X86 ML, Paul Mackerras,
H. Peter Anvin, sparclinux, Sam Ravnborg, Yoshinori Sato,
Jonathan Corbet, Richard Weinberger, Linux-sh list, Ingo Molnar,
Emese Revfy, Kees Cook, uml-devel, Linux Kbuild mailing list,
Peter Oberparleiter, Jeff Dike, linuxppc-dev,
user-mode-linux-user, Thomas Gleixner, Michal Marek,
Ulf Magnusson, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List,
Linus Torvalds, David S. Miller
2018-02-21 19:52 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> On Wed, Feb 21, 2018 at 11:20 AM, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>> 2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
>>> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
>>> <yamada.masahiro@socionext.com> wrote:
>>>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
>>
>> Let me clarify my concern.
>>
>> When we test the compiler flag, is there a case
>> where a particular flag depends on -m{32,64} ?
>>
>> For example, is there a compiler that supports -fstack-protector
>> for 64bit mode, but unsupports it for 32bit mode?
>>
>> $(cc-option -m32) -> y
>> $(cc-option -m64) -> y
>> $(cc-option -fstack-protector) -> y
>> $(cc-option -m32 -fstack-protector) -> n
>> $(cc-option -m64 -fstack-protector) -> y
>>
>> I guess this is unlikely to happen,
>> but I am not whether it is zero possibility.
>>
>> If this could happen,
>> $(cc-option ) must be evaluated together with
>> correct bi-arch option (either -m32 or -m64).
>>
>>
>> Currently, -m32/-m64 is specified in Makefile,
>> but we are moving compiler tests to Kconfig
>> and, CONFIG_64BIT can be dynamically toggled in Kconfig.
>
> I don't think it can happen for this particular combination (stack protector
> and word size), but I'm sure we'll eventually run into options that
> need to be tested in combination. For the current CFLAGS_KERNEL
> setting, we definitely have the case of needing the variables to be
> evaluated in a specific order.
>
I was thinking of how we can handle complex cases
in the current approach.
(Case 1)
Compiler flag -foo and -bar interacts, so
we also need to check the combination of the two.
config CC_HAS_FOO
def_bool $(cc-option -foo)
config CC_HAS_BAR
def_bool $(cc-option -bar)
config CC_HAS_FOO_WITH_BAR
def_bool $(cc-option -foo -bar)
(Case 2)
Compiler flag -foo is sensitive to word-size.
So, we need to test this option together with -m32/-m64.
User can toggle CONFIG_64BIT, like i386/x86_64.
config CC_NEEDS_M64
def_bool $(cc-option -m64) && 64BIT
config CC_NEEDS_M32
def_bool $(cc-option -m32) && !64BIT
config CC_HAS_FOO
bool
default $(cc-option -m64 -foo) if CC_NEEDS_M64
default $(cc-option -m32 -foo) if CC_NEEDS_M32
default $(cc-option -foo)
(Case 3)
Compiler flag -foo is sensitive to endian-ness.
config CC_NEEDS_BIG_ENDIAN
def_bool $(cc-option -mbig-endian) && CPU_BIG_ENDIAN
config CC_NEEDS_LITTLE_ENDIAN
def_bool $(cc-option -mlittle-endian) && CPU_LITTLE_ENDIAN
config CC_HAS_FOO
bool
default $(cc-option -mbig-endian -foo) if CC_NEEDS_BIG_ENDIAN
default $(cc-option -mlittle-endian -foo) if CC_NEEDS_LITTLE_ENDIAN
default $(cc-option -foo)
Hmm, I think I can implement those somehow.
But, I hope we do not have many instances like this...
If you know more naive cases, please share your knowledge.
Thanks!
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 12:57 ` Masahiro Yamada
@ 2018-02-21 16:03 ` Arnd Bergmann
2018-02-21 21:39 ` Ulf Magnusson
2018-02-22 3:22 ` Michael Ellerman
2 siblings, 0 replies; 16+ messages in thread
From: Arnd Bergmann @ 2018-02-21 16:03 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Rich Felker, Kernel Hardening, X86 ML, Paul Mackerras,
H. Peter Anvin, sparclinux, Sam Ravnborg, Yoshinori Sato,
Jonathan Corbet, Richard Weinberger, Linux-sh list, Ingo Molnar,
Emese Revfy, Kees Cook, uml-devel, Linux Kbuild mailing list,
Peter Oberparleiter, Jeff Dike, linuxppc-dev,
user-mode-linux-user, Thomas Gleixner, Michal Marek,
Ulf Magnusson, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List,
Linus Torvalds, David S. Miller
On Wed, Feb 21, 2018 at 1:57 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> 2018-02-21 19:52 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
>> On Wed, Feb 21, 2018 at 11:20 AM, Masahiro Yamada
>> <yamada.masahiro@socionext.com> wrote:
>>> 2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
>>>> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
>>>> <yamada.masahiro@socionext.com> wrote:
>>>>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
>
> Hmm, I think I can implement those somehow.
> But, I hope we do not have many instances like this...
>
>
> If you know more naive cases, please share your knowledge.
>
One case that comes to mind would be architecture level selection on 32-bit
ARM, which is roughly this (I probably have some details wrong, but you
get the idea):
- older compilers don't support the latest architecture setting (-march=armv8
or -march=armv7ve)
- newer compilers no longer support really old architectures (-march=armv4)
- setting -mthumb requires setting one of -march=armv7-a, armv7ve, armv7-m or
armv8 if the compiler doesn't default to those
- on a compiler that defaults to -marm, setting -march=armv7-m requires
setting -mthumb (IIRC)
- really old compilers only support OABI, but not EABI
- newer compilers no longer support OABI
- mthumb requires EABI
- armv6 and higher are subtly broken with OABI, but only when using
certain inline assembly with 64-bit arguments in register pairs.
I think we just shouldn't try to capture all of the above correctly in Kconfig
conditionals.
Arnd
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 12:57 ` Masahiro Yamada
2018-02-21 16:03 ` Arnd Bergmann
@ 2018-02-21 21:39 ` Ulf Magnusson
2018-03-02 5:50 ` Masahiro Yamada
2018-02-22 3:22 ` Michael Ellerman
2 siblings, 1 reply; 16+ messages in thread
From: Ulf Magnusson @ 2018-02-21 21:39 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Arnd Bergmann, Rich Felker, Kernel Hardening, X86 ML,
Paul Mackerras, H. Peter Anvin, sparclinux, Sam Ravnborg,
Yoshinori Sato, Jonathan Corbet, Richard Weinberger,
Linux-sh list, Ingo Molnar, Emese Revfy, Kees Cook, uml-devel,
Linux Kbuild mailing list, Peter Oberparleiter, Jeff Dike,
linuxppc-dev, user-mode-linux-user, Thomas Gleixner,
Michal Marek, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List,
Linus Torvalds, David S. Miller
On Wed, Feb 21, 2018 at 09:57:03PM +0900, Masahiro Yamada wrote:
> 2018-02-21 19:52 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> > On Wed, Feb 21, 2018 at 11:20 AM, Masahiro Yamada
> > <yamada.masahiro@socionext.com> wrote:
> >> 2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> >>> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
> >>> <yamada.masahiro@socionext.com> wrote:
> >>>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
> >>
> >> Let me clarify my concern.
> >>
> >> When we test the compiler flag, is there a case
> >> where a particular flag depends on -m{32,64} ?
> >>
> >> For example, is there a compiler that supports -fstack-protector
> >> for 64bit mode, but unsupports it for 32bit mode?
> >>
> >> $(cc-option -m32) -> y
> >> $(cc-option -m64) -> y
> >> $(cc-option -fstack-protector) -> y
> >> $(cc-option -m32 -fstack-protector) -> n
> >> $(cc-option -m64 -fstack-protector) -> y
> >>
> >> I guess this is unlikely to happen,
> >> but I am not whether it is zero possibility.
> >>
> >> If this could happen,
> >> $(cc-option ) must be evaluated together with
> >> correct bi-arch option (either -m32 or -m64).
> >>
> >>
> >> Currently, -m32/-m64 is specified in Makefile,
> >> but we are moving compiler tests to Kconfig
> >> and, CONFIG_64BIT can be dynamically toggled in Kconfig.
> >
> > I don't think it can happen for this particular combination (stack protector
> > and word size), but I'm sure we'll eventually run into options that
> > need to be tested in combination. For the current CFLAGS_KERNEL
> > setting, we definitely have the case of needing the variables to be
> > evaluated in a specific order.
> >
>
>
>
>
> I was thinking of how we can handle complex cases
> in the current approach.
>
>
>
> (Case 1)
>
> Compiler flag -foo and -bar interacts, so
> we also need to check the combination of the two.
>
>
> config CC_HAS_FOO
> def_bool $(cc-option -foo)
>
> config CC_HAS_BAR
> def_bool $(cc-option -bar)
>
> config CC_HAS_FOO_WITH_BAR
> def_bool $(cc-option -foo -bar)
>
>
>
> (Case 2)
> Compiler flag -foo is sensitive to word-size.
> So, we need to test this option together with -m32/-m64.
> User can toggle CONFIG_64BIT, like i386/x86_64.
>
>
> config CC_NEEDS_M64
> def_bool $(cc-option -m64) && 64BIT
>
> config CC_NEEDS_M32
> def_bool $(cc-option -m32) && !64BIT
>
> config CC_HAS_FOO
> bool
> default $(cc-option -m64 -foo) if CC_NEEDS_M64
> default $(cc-option -m32 -foo) if CC_NEEDS_M32
> default $(cc-option -foo)
>
>
>
> (Case 3)
> Compiler flag -foo is sensitive to endian-ness.
>
>
> config CC_NEEDS_BIG_ENDIAN
> def_bool $(cc-option -mbig-endian) && CPU_BIG_ENDIAN
>
> config CC_NEEDS_LITTLE_ENDIAN
> def_bool $(cc-option -mlittle-endian) && CPU_LITTLE_ENDIAN
>
> config CC_HAS_FOO
> bool
> default $(cc-option -mbig-endian -foo) if CC_NEEDS_BIG_ENDIAN
> default $(cc-option -mlittle-endian -foo) if CC_NEEDS_LITTLE_ENDIAN
> default $(cc-option -foo)
>
>
>
>
> Hmm, I think I can implement those somehow.
> But, I hope we do not have many instances like this...
>
>
> If you know more naive cases, please share your knowledge.
>
> Thanks!
>
>
> --
> Best Regards
> Masahiro Yamada
Would get pretty bad if a test needs to consider multiple symbols.
Exponential explosion there...
I thought some more about the implementation of dynamic (post-parsing)
functions to see how bad it would get with the current implementation.
Some background on how things work now:
1. All expression operands in Kconfig are symbols.
2. Returning '$ENV' or '$(fn foo)' as a T_WORD during parsing gets
you symbols with those strings as names and S_UNKNOWN type (because
they act like references to undefined symbols).
3. For "foo-$(fn foo)", you also get a symbol with that string as its
name and S_UNKNOWN type (stored among the SYMBOL_CONST symbols)
4. Symbols with S_UNKNOWN type get their name as their string value,
and the tristate value n.
So, if you do string expansion on the names of symbols with S_UNKNOWN
type in sym_calc_value(), you're almost there with the current
implementation, except for the tristate case.
Maybe you could set the tristate value of S_UNKNOWN symbols depending on
the string value you end up with. Things are getting pretty confusing at
that point.
Could have something like S_DYNAMIC as well. More Kconfig complexity...
Then there's other complications:
1. SYMBOL_CONST is no longer constant.
2. Dependency loop detection needs to consider symbol references
within strings.
3. Dependency loop detection relies on static knowledge of what
symbols a symbol depends on. That might get messy for certain
expansions, though it might be things you wouldn't do in practice.
4. Symbols still need to be properly invalidated. It looks like at
least menuconfig just does a dumb invalidate-everything whenever
the value of a symbol is changed though, so it might not require
extra work. (Bit messier in Kconfiglib, which does minimal
invalidation to keep scripts fast, but just need to extract a few
extra deps there.)
It looks like dynamic functions could get quite messy, but might be
doable if absolutely required. There's probably more devils in the
details though.
I don't think the static function model precludes switching models later
btw, when people have more experience.
Cheers,
Ulf
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 12:57 ` Masahiro Yamada
2018-02-21 16:03 ` Arnd Bergmann
2018-02-21 21:39 ` Ulf Magnusson
@ 2018-02-22 3:22 ` Michael Ellerman
2 siblings, 0 replies; 16+ messages in thread
From: Michael Ellerman @ 2018-02-22 3:22 UTC (permalink / raw)
To: Masahiro Yamada, Arnd Bergmann
Cc: Rich Felker, Kernel Hardening, X86 ML, Paul Mackerras,
H. Peter Anvin, sparclinux, Sam Ravnborg, Yoshinori Sato,
Jonathan Corbet, Richard Weinberger, Linux-sh list,
Linus Torvalds, Ingo Molnar, Emese Revfy, Kees Cook, uml-devel,
Linux Kbuild mailing list, Peter Oberparleiter, Jeff Dike,
user-mode-linux-user, Thomas Gleixner, Michal Marek,
Ulf Magnusson, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List, linuxppc-dev,
David S. Miller
Masahiro Yamada <yamada.masahiro@socionext.com> writes:
>
<snip>
>
> (Case 3)
> Compiler flag -foo is sensitive to endian-ness.
>
>
> config CC_NEEDS_BIG_ENDIAN
> def_bool $(cc-option -mbig-endian) && CPU_BIG_ENDIAN
>
> config CC_NEEDS_LITTLE_ENDIAN
> def_bool $(cc-option -mlittle-endian) && CPU_LITTLE_ENDIAN
>
> config CC_HAS_FOO
> bool
> default $(cc-option -mbig-endian -foo) if CC_NEEDS_BIG_ENDIAN
> default $(cc-option -mlittle-endian -foo) if CC_NEEDS_LITTLE_ENDIAN
> default $(cc-option -foo)
We may do something like this on powerpc, where we have 32/64-bit and
big/little endian (on 64-bit) and then some ABI options that we
set/unset depending on endian.
The above looks like it could work though.
cheers
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 21/23] gcc-plugins: move GCC version check for PowerPC to Kconfig
2018-02-16 18:38 ` [PATCH 21/23] gcc-plugins: move GCC version check for PowerPC " Masahiro Yamada
@ 2018-02-22 5:04 ` Andrew Donnellan
0 siblings, 0 replies; 16+ messages in thread
From: Andrew Donnellan @ 2018-02-22 5:04 UTC (permalink / raw)
To: Masahiro Yamada, linux-kbuild, Linus Torvalds
Cc: Michal Marek, Ulf Magnusson, Kees Cook, Arnd Bergmann,
kernel-hardening, Greg Kroah-Hartman, Randy Dunlap, linux-kernel,
Emese Revfy, Paul Mackerras, linuxppc-dev, Sam Ravnborg
On 17/02/18 05:38, Masahiro Yamada wrote:
> For PowerPC, GCC 5.2 is the requirement for GCC plugins. Move the
> version check to Kconfig, and remove the ugly checker.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
The old checker was as non-ugly as I could make it. :)
Acked-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com IBM Australia Limited
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-02-21 21:39 ` Ulf Magnusson
@ 2018-03-02 5:50 ` Masahiro Yamada
2018-03-02 9:03 ` Ulf Magnusson
0 siblings, 1 reply; 16+ messages in thread
From: Masahiro Yamada @ 2018-03-02 5:50 UTC (permalink / raw)
To: Ulf Magnusson
Cc: Arnd Bergmann, Rich Felker, Kernel Hardening, X86 ML,
Paul Mackerras, H. Peter Anvin, sparclinux, Sam Ravnborg,
Yoshinori Sato, Jonathan Corbet, Richard Weinberger,
Linux-sh list, Ingo Molnar, Emese Revfy, Kees Cook, uml-devel,
Linux Kbuild mailing list, Peter Oberparleiter, Jeff Dike,
linuxppc-dev, user-mode-linux-user, Thomas Gleixner,
Michal Marek, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List,
Linus Torvalds, David S. Miller
2018-02-22 6:39 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
> On Wed, Feb 21, 2018 at 09:57:03PM +0900, Masahiro Yamada wrote:
>> 2018-02-21 19:52 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
>> > On Wed, Feb 21, 2018 at 11:20 AM, Masahiro Yamada
>> > <yamada.masahiro@socionext.com> wrote:
>> >> 2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
>> >>> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
>> >>> <yamada.masahiro@socionext.com> wrote:
>> >>>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
>> >>
>> >> Let me clarify my concern.
>> >>
>> >> When we test the compiler flag, is there a case
>> >> where a particular flag depends on -m{32,64} ?
>> >>
>> >> For example, is there a compiler that supports -fstack-protector
>> >> for 64bit mode, but unsupports it for 32bit mode?
>> >>
>> >> $(cc-option -m32) -> y
>> >> $(cc-option -m64) -> y
>> >> $(cc-option -fstack-protector) -> y
>> >> $(cc-option -m32 -fstack-protector) -> n
>> >> $(cc-option -m64 -fstack-protector) -> y
>> >>
>> >> I guess this is unlikely to happen,
>> >> but I am not whether it is zero possibility.
>> >>
>> >> If this could happen,
>> >> $(cc-option ) must be evaluated together with
>> >> correct bi-arch option (either -m32 or -m64).
>> >>
>> >>
>> >> Currently, -m32/-m64 is specified in Makefile,
>> >> but we are moving compiler tests to Kconfig
>> >> and, CONFIG_64BIT can be dynamically toggled in Kconfig.
>> >
>> > I don't think it can happen for this particular combination (stack protector
>> > and word size), but I'm sure we'll eventually run into options that
>> > need to be tested in combination. For the current CFLAGS_KERNEL
>> > setting, we definitely have the case of needing the variables to be
>> > evaluated in a specific order.
>> >
>>
>>
>>
>>
>> I was thinking of how we can handle complex cases
>> in the current approach.
>>
>>
>>
>> (Case 1)
>>
>> Compiler flag -foo and -bar interacts, so
>> we also need to check the combination of the two.
>>
>>
>> config CC_HAS_FOO
>> def_bool $(cc-option -foo)
>>
>> config CC_HAS_BAR
>> def_bool $(cc-option -bar)
>>
>> config CC_HAS_FOO_WITH_BAR
>> def_bool $(cc-option -foo -bar)
>>
>>
>>
>> (Case 2)
>> Compiler flag -foo is sensitive to word-size.
>> So, we need to test this option together with -m32/-m64.
>> User can toggle CONFIG_64BIT, like i386/x86_64.
>>
>>
>> config CC_NEEDS_M64
>> def_bool $(cc-option -m64) && 64BIT
>>
>> config CC_NEEDS_M32
>> def_bool $(cc-option -m32) && !64BIT
>>
>> config CC_HAS_FOO
>> bool
>> default $(cc-option -m64 -foo) if CC_NEEDS_M64
>> default $(cc-option -m32 -foo) if CC_NEEDS_M32
>> default $(cc-option -foo)
>>
>>
>>
>> (Case 3)
>> Compiler flag -foo is sensitive to endian-ness.
>>
>>
>> config CC_NEEDS_BIG_ENDIAN
>> def_bool $(cc-option -mbig-endian) && CPU_BIG_ENDIAN
>>
>> config CC_NEEDS_LITTLE_ENDIAN
>> def_bool $(cc-option -mlittle-endian) && CPU_LITTLE_ENDIAN
>>
>> config CC_HAS_FOO
>> bool
>> default $(cc-option -mbig-endian -foo) if CC_NEEDS_BIG_ENDIAN
>> default $(cc-option -mlittle-endian -foo) if CC_NEEDS_LITTLE_ENDIAN
>> default $(cc-option -foo)
>>
>>
>>
>>
>> Hmm, I think I can implement those somehow.
>> But, I hope we do not have many instances like this...
>>
>>
>> If you know more naive cases, please share your knowledge.
>>
>> Thanks!
>>
>>
>> --
>> Best Regards
>> Masahiro Yamada
>
> Would get pretty bad if a test needs to consider multiple symbols.
> Exponential explosion there...
>
>
> I thought some more about the implementation of dynamic (post-parsing)
> functions to see how bad it would get with the current implementation.
>
> Some background on how things work now:
>
> 1. All expression operands in Kconfig are symbols.
>
> 2. Returning '$ENV' or '$(fn foo)' as a T_WORD during parsing gets
> you symbols with those strings as names and S_UNKNOWN type (because
> they act like references to undefined symbols).
>
> 3. For "foo-$(fn foo)", you also get a symbol with that string as its
> name and S_UNKNOWN type (stored among the SYMBOL_CONST symbols)
>
> 4. Symbols with S_UNKNOWN type get their name as their string value,
> and the tristate value n.
>
> So, if you do string expansion on the names of symbols with S_UNKNOWN
> type in sym_calc_value(), you're almost there with the current
> implementation, except for the tristate case.
>
> Maybe you could set the tristate value of S_UNKNOWN symbols depending on
> the string value you end up with. Things are getting pretty confusing at
> that point.
>
> Could have something like S_DYNAMIC as well. More Kconfig complexity...
>
> Then there's other complications:
>
> 1. SYMBOL_CONST is no longer constant.
>
> 2. Dependency loop detection needs to consider symbol references
> within strings.
>
> 3. Dependency loop detection relies on static knowledge of what
> symbols a symbol depends on. That might get messy for certain
> expansions, though it might be things you wouldn't do in practice.
>
> 4. Symbols still need to be properly invalidated. It looks like at
> least menuconfig just does a dumb invalidate-everything whenever
> the value of a symbol is changed though, so it might not require
> extra work. (Bit messier in Kconfiglib, which does minimal
> invalidation to keep scripts fast, but just need to extract a few
> extra deps there.)
>
>
> It looks like dynamic functions could get quite messy, but might be
> doable if absolutely required. There's probably more devils in the
> details though.
>
> I don't think the static function model precludes switching models later
> btw, when people have more experience.
I really want to start with the static function model
and see if we need the dynamic function implementation.
Here is an idea for the migration path in case
we need to do that in the future.
Currently, every time user input is given,
sym_clear_all_valid() is called.
It is not efficient to blindly re-evaluate expensive $(shell ...)
So, have a list of symbols the function depends on
in its arguments.
For example,
config CC_HAS_SANE_STACKPROTECTOR
def_bool $(shell $srctree/scripts/gcc-has-stack-protector.sh
$CC $(1), CFLAGS_BASE)
Here the first argument
$srctree/scripts/gcc-x86-has-stack-protector.sh $CC $(1)
is the shell command.
$(1), $(2), ... will be replaced with the values of symbols (or expressions)
that follow when running the shell command.
The second argument
CFLAGS_BASE
is the dependency symbol (or expression).
CFLAGS_BASE can be dynamically changed like
config CFLAGS_BASE
string
default "-m64" if 64BIT
default "-m32"
When and only when CFLAGS_BASE is updated, the function should be re-calculated.
(This will require efforts to minimize the amount of re-evaluation.)
cc-option will be implemented like follows:
macro cc-option $(shell $CC -Werror $$(1) $(1) -c -x c /dev/null -o
/dev/null, CFLAGS_BASE)
Please notice the difference between $$(1) and $(1).
$(1) is immediately expanded by cc-option macro.
$$(1) is escaped since we want to expand it by $(shell ...), not by
$(cc-option ...)
For example,
$(cc-option -fstack-protector)
will be expanded to
$(shell gcc -Werror $(1) -fstack-protector -c -x c /dev/null -o
/dev/null, CFLAGS_BASE)
Since macros are just textual shorthand, so this expansion happens
during the parse phase.
Then, the evaluation phase does the following every time CFLAGS_BASE is updated.
gcc -Werror [value of CFLAGS_BASE] -fstack-protector -c -x c /dev/null
-o /dev/null
This is a new form of expression, so it will be managed in AST tree
with a flag E_SHELL (or E_FUNC) etc.
Not implemented at all. Just a rough sketch.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-03-02 5:50 ` Masahiro Yamada
@ 2018-03-02 9:03 ` Ulf Magnusson
2018-03-02 9:12 ` Ulf Magnusson
0 siblings, 1 reply; 16+ messages in thread
From: Ulf Magnusson @ 2018-03-02 9:03 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Arnd Bergmann, Rich Felker, Kernel Hardening, X86 ML,
Paul Mackerras, H. Peter Anvin, sparclinux, Sam Ravnborg,
Yoshinori Sato, Jonathan Corbet, Richard Weinberger,
Linux-sh list, Ingo Molnar, Emese Revfy, Kees Cook, uml-devel,
Linux Kbuild mailing list, Peter Oberparleiter, Jeff Dike,
linuxppc-dev, user-mode-linux-user, Thomas Gleixner,
Michal Marek, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List,
Linus Torvalds, David S. Miller
On Fri, Mar 02, 2018 at 02:50:39PM +0900, Masahiro Yamada wrote:
> 2018-02-22 6:39 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
> > On Wed, Feb 21, 2018 at 09:57:03PM +0900, Masahiro Yamada wrote:
> >> 2018-02-21 19:52 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> >> > On Wed, Feb 21, 2018 at 11:20 AM, Masahiro Yamada
> >> > <yamada.masahiro@socionext.com> wrote:
> >> >> 2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> >> >>> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
> >> >>> <yamada.masahiro@socionext.com> wrote:
> >> >>>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
> >> >>
> >> >> Let me clarify my concern.
> >> >>
> >> >> When we test the compiler flag, is there a case
> >> >> where a particular flag depends on -m{32,64} ?
> >> >>
> >> >> For example, is there a compiler that supports -fstack-protector
> >> >> for 64bit mode, but unsupports it for 32bit mode?
> >> >>
> >> >> $(cc-option -m32) -> y
> >> >> $(cc-option -m64) -> y
> >> >> $(cc-option -fstack-protector) -> y
> >> >> $(cc-option -m32 -fstack-protector) -> n
> >> >> $(cc-option -m64 -fstack-protector) -> y
> >> >>
> >> >> I guess this is unlikely to happen,
> >> >> but I am not whether it is zero possibility.
> >> >>
> >> >> If this could happen,
> >> >> $(cc-option ) must be evaluated together with
> >> >> correct bi-arch option (either -m32 or -m64).
> >> >>
> >> >>
> >> >> Currently, -m32/-m64 is specified in Makefile,
> >> >> but we are moving compiler tests to Kconfig
> >> >> and, CONFIG_64BIT can be dynamically toggled in Kconfig.
> >> >
> >> > I don't think it can happen for this particular combination (stack protector
> >> > and word size), but I'm sure we'll eventually run into options that
> >> > need to be tested in combination. For the current CFLAGS_KERNEL
> >> > setting, we definitely have the case of needing the variables to be
> >> > evaluated in a specific order.
> >> >
> >>
> >>
> >>
> >>
> >> I was thinking of how we can handle complex cases
> >> in the current approach.
> >>
> >>
> >>
> >> (Case 1)
> >>
> >> Compiler flag -foo and -bar interacts, so
> >> we also need to check the combination of the two.
> >>
> >>
> >> config CC_HAS_FOO
> >> def_bool $(cc-option -foo)
> >>
> >> config CC_HAS_BAR
> >> def_bool $(cc-option -bar)
> >>
> >> config CC_HAS_FOO_WITH_BAR
> >> def_bool $(cc-option -foo -bar)
> >>
> >>
> >>
> >> (Case 2)
> >> Compiler flag -foo is sensitive to word-size.
> >> So, we need to test this option together with -m32/-m64.
> >> User can toggle CONFIG_64BIT, like i386/x86_64.
> >>
> >>
> >> config CC_NEEDS_M64
> >> def_bool $(cc-option -m64) && 64BIT
> >>
> >> config CC_NEEDS_M32
> >> def_bool $(cc-option -m32) && !64BIT
> >>
> >> config CC_HAS_FOO
> >> bool
> >> default $(cc-option -m64 -foo) if CC_NEEDS_M64
> >> default $(cc-option -m32 -foo) if CC_NEEDS_M32
> >> default $(cc-option -foo)
> >>
> >>
> >>
> >> (Case 3)
> >> Compiler flag -foo is sensitive to endian-ness.
> >>
> >>
> >> config CC_NEEDS_BIG_ENDIAN
> >> def_bool $(cc-option -mbig-endian) && CPU_BIG_ENDIAN
> >>
> >> config CC_NEEDS_LITTLE_ENDIAN
> >> def_bool $(cc-option -mlittle-endian) && CPU_LITTLE_ENDIAN
> >>
> >> config CC_HAS_FOO
> >> bool
> >> default $(cc-option -mbig-endian -foo) if CC_NEEDS_BIG_ENDIAN
> >> default $(cc-option -mlittle-endian -foo) if CC_NEEDS_LITTLE_ENDIAN
> >> default $(cc-option -foo)
> >>
> >>
> >>
> >>
> >> Hmm, I think I can implement those somehow.
> >> But, I hope we do not have many instances like this...
> >>
> >>
> >> If you know more naive cases, please share your knowledge.
> >>
> >> Thanks!
> >>
> >>
> >> --
> >> Best Regards
> >> Masahiro Yamada
> >
> > Would get pretty bad if a test needs to consider multiple symbols.
> > Exponential explosion there...
> >
> >
> > I thought some more about the implementation of dynamic (post-parsing)
> > functions to see how bad it would get with the current implementation.
> >
> > Some background on how things work now:
> >
> > 1. All expression operands in Kconfig are symbols.
> >
> > 2. Returning '$ENV' or '$(fn foo)' as a T_WORD during parsing gets
> > you symbols with those strings as names and S_UNKNOWN type (because
> > they act like references to undefined symbols).
> >
> > 3. For "foo-$(fn foo)", you also get a symbol with that string as its
> > name and S_UNKNOWN type (stored among the SYMBOL_CONST symbols)
> >
> > 4. Symbols with S_UNKNOWN type get their name as their string value,
> > and the tristate value n.
> >
> > So, if you do string expansion on the names of symbols with S_UNKNOWN
> > type in sym_calc_value(), you're almost there with the current
> > implementation, except for the tristate case.
> >
> > Maybe you could set the tristate value of S_UNKNOWN symbols depending on
> > the string value you end up with. Things are getting pretty confusing at
> > that point.
> >
> > Could have something like S_DYNAMIC as well. More Kconfig complexity...
> >
> > Then there's other complications:
> >
> > 1. SYMBOL_CONST is no longer constant.
> >
> > 2. Dependency loop detection needs to consider symbol references
> > within strings.
> >
> > 3. Dependency loop detection relies on static knowledge of what
> > symbols a symbol depends on. That might get messy for certain
> > expansions, though it might be things you wouldn't do in practice.
> >
> > 4. Symbols still need to be properly invalidated. It looks like at
> > least menuconfig just does a dumb invalidate-everything whenever
> > the value of a symbol is changed though, so it might not require
> > extra work. (Bit messier in Kconfiglib, which does minimal
> > invalidation to keep scripts fast, but just need to extract a few
> > extra deps there.)
> >
> >
> > It looks like dynamic functions could get quite messy, but might be
> > doable if absolutely required. There's probably more devils in the
> > details though.
> >
> > I don't think the static function model precludes switching models later
> > btw, when people have more experience.
>
>
>
> I really want to start with the static function model
> and see if we need the dynamic function implementation.
Yeah, let's start with static functions, IMO.
Either we'll learn that they're powerful enough in practice, and save
ourselves some work, or we'll gain experience for later. Converting from
static to dynamic functions should be painless, if needed.
My plan would be something like:
1. Implement static functions
2. Convert as many simple cases over to them as possible
3. See how bad the bad cases get. If they get really bad, then decide
what to do next (extend Kconfig, handle them in the Makefiles,
etc.)
>
> Here is an idea for the migration path in case
> we need to do that in the future.
>
>
>
> Currently, every time user input is given,
> sym_clear_all_valid() is called.
>
> It is not efficient to blindly re-evaluate expensive $(shell ...)
I think menuconfig only reevalutes the symbols in the menu that's
currently shown in the interface (along with their dependencies).
Maybe that'd be bad enough though.
>
>
> So, have a list of symbols the function depends on
> in its arguments.
>
> For example,
>
> config CC_HAS_SANE_STACKPROTECTOR
> def_bool $(shell $srctree/scripts/gcc-has-stack-protector.sh
> $CC $(1), CFLAGS_BASE)
>
>
> Here the first argument
> $srctree/scripts/gcc-x86-has-stack-protector.sh $CC $(1)
>
> is the shell command.
> $(1), $(2), ... will be replaced with the values of symbols (or expressions)
> that follow when running the shell command.
>
>
> The second argument
> CFLAGS_BASE
> is the dependency symbol (or expression).
>
>
> CFLAGS_BASE can be dynamically changed like
>
> config CFLAGS_BASE
> string
> default "-m64" if 64BIT
> default "-m32"
>
>
> When and only when CFLAGS_BASE is updated, the function should be re-calculated.
> (This will require efforts to minimize the amount of re-evaluation.)
>
>
>
>
> cc-option will be implemented like follows:
>
> macro cc-option $(shell $CC -Werror $$(1) $(1) -c -x c /dev/null -o
> /dev/null, CFLAGS_BASE)
>
>
>
> Please notice the difference between $$(1) and $(1).
>
> $(1) is immediately expanded by cc-option macro.
>
> $$(1) is escaped since we want to expand it by $(shell ...), not by
> $(cc-option ...)
>
>
>
> For example,
>
> $(cc-option -fstack-protector)
>
> will be expanded to
>
> $(shell gcc -Werror $(1) -fstack-protector -c -x c /dev/null -o
> /dev/null, CFLAGS_BASE)
>
> Since macros are just textual shorthand, so this expansion happens
> during the parse phase.
>
>
>
> Then, the evaluation phase does the following every time CFLAGS_BASE is updated.
>
> gcc -Werror [value of CFLAGS_BASE] -fstack-protector -c -x c /dev/null
> -o /dev/null
>
>
> This is a new form of expression, so it will be managed in AST tree
> with a flag E_SHELL (or E_FUNC) etc.
>
>
> Not implemented at all. Just a rough sketch.
A simpler syntax like
$(shell $CC -Werror {CFLAGS_BASE} -c -x c /dev/null -o /dev/null)
might work as well. Then you wouldn't have to any double escaping, and
having both $(1) and the value for it appear in the same place seems a
bit redundant.
I wonder if dependency management might get messy...
Anyway, let's just go with static functions...
Cheers,
Ulf
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/23] kconfig: move compiler capability tests to Kconfig
2018-03-02 9:03 ` Ulf Magnusson
@ 2018-03-02 9:12 ` Ulf Magnusson
0 siblings, 0 replies; 16+ messages in thread
From: Ulf Magnusson @ 2018-03-02 9:12 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Arnd Bergmann, Rich Felker, Kernel Hardening, X86 ML,
Paul Mackerras, H. Peter Anvin, sparclinux, Sam Ravnborg,
Yoshinori Sato, Jonathan Corbet, Richard Weinberger,
Linux-sh list, Ingo Molnar, Emese Revfy, Kees Cook, uml-devel,
Linux Kbuild mailing list, Peter Oberparleiter, Jeff Dike,
linuxppc-dev, user-mode-linux-user, Thomas Gleixner,
Michal Marek, Greg Kroah-Hartman, Randy Dunlap,
open list:DOCUMENTATION, Linux Kernel Mailing List,
Linus Torvalds, David S. Miller
On Fri, Mar 02, 2018 at 10:03:26AM +0100, Ulf Magnusson wrote:
> On Fri, Mar 02, 2018 at 02:50:39PM +0900, Masahiro Yamada wrote:
> > 2018-02-22 6:39 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
> > > On Wed, Feb 21, 2018 at 09:57:03PM +0900, Masahiro Yamada wrote:
> > >> 2018-02-21 19:52 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> > >> > On Wed, Feb 21, 2018 at 11:20 AM, Masahiro Yamada
> > >> > <yamada.masahiro@socionext.com> wrote:
> > >> >> 2018-02-21 18:56 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> > >> >>> On Wed, Feb 21, 2018 at 8:38 AM, Masahiro Yamada
> > >> >>> <yamada.masahiro@socionext.com> wrote:
> > >> >>>> 2018-02-20 0:18 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
> > >> >>
> > >> >> Let me clarify my concern.
> > >> >>
> > >> >> When we test the compiler flag, is there a case
> > >> >> where a particular flag depends on -m{32,64} ?
> > >> >>
> > >> >> For example, is there a compiler that supports -fstack-protector
> > >> >> for 64bit mode, but unsupports it for 32bit mode?
> > >> >>
> > >> >> $(cc-option -m32) -> y
> > >> >> $(cc-option -m64) -> y
> > >> >> $(cc-option -fstack-protector) -> y
> > >> >> $(cc-option -m32 -fstack-protector) -> n
> > >> >> $(cc-option -m64 -fstack-protector) -> y
> > >> >>
> > >> >> I guess this is unlikely to happen,
> > >> >> but I am not whether it is zero possibility.
> > >> >>
> > >> >> If this could happen,
> > >> >> $(cc-option ) must be evaluated together with
> > >> >> correct bi-arch option (either -m32 or -m64).
> > >> >>
> > >> >>
> > >> >> Currently, -m32/-m64 is specified in Makefile,
> > >> >> but we are moving compiler tests to Kconfig
> > >> >> and, CONFIG_64BIT can be dynamically toggled in Kconfig.
> > >> >
> > >> > I don't think it can happen for this particular combination (stack protector
> > >> > and word size), but I'm sure we'll eventually run into options that
> > >> > need to be tested in combination. For the current CFLAGS_KERNEL
> > >> > setting, we definitely have the case of needing the variables to be
> > >> > evaluated in a specific order.
> > >> >
> > >>
> > >>
> > >>
> > >>
> > >> I was thinking of how we can handle complex cases
> > >> in the current approach.
> > >>
> > >>
> > >>
> > >> (Case 1)
> > >>
> > >> Compiler flag -foo and -bar interacts, so
> > >> we also need to check the combination of the two.
> > >>
> > >>
> > >> config CC_HAS_FOO
> > >> def_bool $(cc-option -foo)
> > >>
> > >> config CC_HAS_BAR
> > >> def_bool $(cc-option -bar)
> > >>
> > >> config CC_HAS_FOO_WITH_BAR
> > >> def_bool $(cc-option -foo -bar)
> > >>
> > >>
> > >>
> > >> (Case 2)
> > >> Compiler flag -foo is sensitive to word-size.
> > >> So, we need to test this option together with -m32/-m64.
> > >> User can toggle CONFIG_64BIT, like i386/x86_64.
> > >>
> > >>
> > >> config CC_NEEDS_M64
> > >> def_bool $(cc-option -m64) && 64BIT
> > >>
> > >> config CC_NEEDS_M32
> > >> def_bool $(cc-option -m32) && !64BIT
> > >>
> > >> config CC_HAS_FOO
> > >> bool
> > >> default $(cc-option -m64 -foo) if CC_NEEDS_M64
> > >> default $(cc-option -m32 -foo) if CC_NEEDS_M32
> > >> default $(cc-option -foo)
> > >>
> > >>
> > >>
> > >> (Case 3)
> > >> Compiler flag -foo is sensitive to endian-ness.
> > >>
> > >>
> > >> config CC_NEEDS_BIG_ENDIAN
> > >> def_bool $(cc-option -mbig-endian) && CPU_BIG_ENDIAN
> > >>
> > >> config CC_NEEDS_LITTLE_ENDIAN
> > >> def_bool $(cc-option -mlittle-endian) && CPU_LITTLE_ENDIAN
> > >>
> > >> config CC_HAS_FOO
> > >> bool
> > >> default $(cc-option -mbig-endian -foo) if CC_NEEDS_BIG_ENDIAN
> > >> default $(cc-option -mlittle-endian -foo) if CC_NEEDS_LITTLE_ENDIAN
> > >> default $(cc-option -foo)
> > >>
> > >>
> > >>
> > >>
> > >> Hmm, I think I can implement those somehow.
> > >> But, I hope we do not have many instances like this...
> > >>
> > >>
> > >> If you know more naive cases, please share your knowledge.
> > >>
> > >> Thanks!
> > >>
> > >>
> > >> --
> > >> Best Regards
> > >> Masahiro Yamada
> > >
> > > Would get pretty bad if a test needs to consider multiple symbols.
> > > Exponential explosion there...
> > >
> > >
> > > I thought some more about the implementation of dynamic (post-parsing)
> > > functions to see how bad it would get with the current implementation.
> > >
> > > Some background on how things work now:
> > >
> > > 1. All expression operands in Kconfig are symbols.
> > >
> > > 2. Returning '$ENV' or '$(fn foo)' as a T_WORD during parsing gets
> > > you symbols with those strings as names and S_UNKNOWN type (because
> > > they act like references to undefined symbols).
> > >
> > > 3. For "foo-$(fn foo)", you also get a symbol with that string as its
> > > name and S_UNKNOWN type (stored among the SYMBOL_CONST symbols)
> > >
> > > 4. Symbols with S_UNKNOWN type get their name as their string value,
> > > and the tristate value n.
> > >
> > > So, if you do string expansion on the names of symbols with S_UNKNOWN
> > > type in sym_calc_value(), you're almost there with the current
> > > implementation, except for the tristate case.
> > >
> > > Maybe you could set the tristate value of S_UNKNOWN symbols depending on
> > > the string value you end up with. Things are getting pretty confusing at
> > > that point.
> > >
> > > Could have something like S_DYNAMIC as well. More Kconfig complexity...
> > >
> > > Then there's other complications:
> > >
> > > 1. SYMBOL_CONST is no longer constant.
> > >
> > > 2. Dependency loop detection needs to consider symbol references
> > > within strings.
> > >
> > > 3. Dependency loop detection relies on static knowledge of what
> > > symbols a symbol depends on. That might get messy for certain
> > > expansions, though it might be things you wouldn't do in practice.
> > >
> > > 4. Symbols still need to be properly invalidated. It looks like at
> > > least menuconfig just does a dumb invalidate-everything whenever
> > > the value of a symbol is changed though, so it might not require
> > > extra work. (Bit messier in Kconfiglib, which does minimal
> > > invalidation to keep scripts fast, but just need to extract a few
> > > extra deps there.)
> > >
> > >
> > > It looks like dynamic functions could get quite messy, but might be
> > > doable if absolutely required. There's probably more devils in the
> > > details though.
> > >
> > > I don't think the static function model precludes switching models later
> > > btw, when people have more experience.
> >
> >
> >
> > I really want to start with the static function model
> > and see if we need the dynamic function implementation.
>
> Yeah, let's start with static functions, IMO.
>
> Either we'll learn that they're powerful enough in practice, and save
> ourselves some work, or we'll gain experience for later. Converting from
> static to dynamic functions should be painless, if needed.
>
> My plan would be something like:
>
> 1. Implement static functions
>
> 2. Convert as many simple cases over to them as possible
>
> 3. See how bad the bad cases get. If they get really bad, then decide
> what to do next (extend Kconfig, handle them in the Makefiles,
> etc.)
>
> >
> > Here is an idea for the migration path in case
> > we need to do that in the future.
> >
> >
> >
> > Currently, every time user input is given,
> > sym_clear_all_valid() is called.
> >
> > It is not efficient to blindly re-evaluate expensive $(shell ...)
>
> I think menuconfig only reevalutes the symbols in the menu that's
> currently shown in the interface (along with their dependencies).
>
> Maybe that'd be bad enough though.
>
> >
> >
> > So, have a list of symbols the function depends on
> > in its arguments.
> >
> > For example,
> >
> > config CC_HAS_SANE_STACKPROTECTOR
> > def_bool $(shell $srctree/scripts/gcc-has-stack-protector.sh
> > $CC $(1), CFLAGS_BASE)
> >
> >
> > Here the first argument
> > $srctree/scripts/gcc-x86-has-stack-protector.sh $CC $(1)
> >
> > is the shell command.
> > $(1), $(2), ... will be replaced with the values of symbols (or expressions)
> > that follow when running the shell command.
> >
> >
> > The second argument
> > CFLAGS_BASE
> > is the dependency symbol (or expression).
> >
> >
> > CFLAGS_BASE can be dynamically changed like
> >
> > config CFLAGS_BASE
> > string
> > default "-m64" if 64BIT
> > default "-m32"
> >
> >
> > When and only when CFLAGS_BASE is updated, the function should be re-calculated.
> > (This will require efforts to minimize the amount of re-evaluation.)
> >
> >
> >
> >
> > cc-option will be implemented like follows:
> >
> > macro cc-option $(shell $CC -Werror $$(1) $(1) -c -x c /dev/null -o
> > /dev/null, CFLAGS_BASE)
> >
> >
> >
> > Please notice the difference between $$(1) and $(1).
> >
> > $(1) is immediately expanded by cc-option macro.
> >
> > $$(1) is escaped since we want to expand it by $(shell ...), not by
> > $(cc-option ...)
> >
> >
> >
> > For example,
> >
> > $(cc-option -fstack-protector)
> >
> > will be expanded to
> >
> > $(shell gcc -Werror $(1) -fstack-protector -c -x c /dev/null -o
> > /dev/null, CFLAGS_BASE)
> >
> > Since macros are just textual shorthand, so this expansion happens
> > during the parse phase.
> >
> >
> >
> > Then, the evaluation phase does the following every time CFLAGS_BASE is updated.
> >
> > gcc -Werror [value of CFLAGS_BASE] -fstack-protector -c -x c /dev/null
> > -o /dev/null
> >
> >
> > This is a new form of expression, so it will be managed in AST tree
> > with a flag E_SHELL (or E_FUNC) etc.
> >
> >
> > Not implemented at all. Just a rough sketch.
>
> A simpler syntax like
>
> $(shell $CC -Werror {CFLAGS_BASE} -c -x c /dev/null -o /dev/null)
*$(shell $CC -Werror {CFLAGS_BASE} -fstack-protector -c -x c /dev/null -o /dev/null)
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2018-03-02 9:12 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-16 18:38 [PATCH 00/23] kconfig: move compiler capability tests to Kconfig Masahiro Yamada
2018-02-16 18:38 ` [PATCH 21/23] gcc-plugins: move GCC version check for PowerPC " Masahiro Yamada
2018-02-22 5:04 ` Andrew Donnellan
2018-02-18 22:13 ` [PATCH 00/23] kconfig: move compiler capability tests " Sam Ravnborg
2018-02-19 15:18 ` Ulf Magnusson
2018-02-21 7:38 ` Masahiro Yamada
2018-02-21 9:56 ` Arnd Bergmann
2018-02-21 10:20 ` Masahiro Yamada
2018-02-21 10:52 ` Arnd Bergmann
2018-02-21 12:57 ` Masahiro Yamada
2018-02-21 16:03 ` Arnd Bergmann
2018-02-21 21:39 ` Ulf Magnusson
2018-03-02 5:50 ` Masahiro Yamada
2018-03-02 9:03 ` Ulf Magnusson
2018-03-02 9:12 ` Ulf Magnusson
2018-02-22 3:22 ` Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).