Skip to contentSkip to conversation

kbuild: use -S instead of -E for precise cc-option test in Kconfig

PATCH In review Masahiro Yamada 1 participant 2 messages Jan 17, 2020 – Jan 21, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: use -S instead of -E for precise cc-option test in Kconfig

Currently, -E (stop after the preprocessing stage) is used to check whether the given compiler flag is supported.

While it is faster than -S (or -c), it can be false-positive. You need to run the compilation proper to check the flag more precisely.

For example, when testing "--param asan-instrument-allocas=1", my gcc gives a different result for -E vs -S.

$ gcc -Werror --param asan-instrument-allocas=1 -E -x c /dev/null -o /dev/null
$ echo $?
0
$ gcc -Werror --param asan-instrument-allocas=1 -S -x c /dev/null -o /dev/null
cc1: error: invalid --param name ‘asan-instrument-allocas’; did you mean ‘asan-instrument-writes’?
$ echo $?
1

---

 scripts/Kconfig.include | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kconfig.include +1 -1
index d4adfbe42690..bfb44b265a94 100644
@@ -25,7 +25,7 @@ failure = $(if-success,$(1),n,y)
 
 # $(cc-option,<flag>)
 # Return y if the compiler supports <flag>, n otherwise
-cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -E -x c /dev/null -o /dev/null)
+cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
 
 # $(ld-option,<flag>)
 # Return y if the linker supports <flag>, n otherwise
Signature · 1 line
2.17.1
#1 lore raw
Quoted 14 lines · Masahiro Yamada

Currently, -E (stop after the preprocessing stage) is used to check whether the given compiler flag is supported.

While it is faster than -S (or -c), it can be false-positive. You need to run the compilation proper to check the flag more precisely.

For example, when testing "--param asan-instrument-allocas=1", my gcc gives a different result for -E vs -S.

$ gcc -Werror --param asan-instrument-allocas=1 -E -x c /dev/null -o /dev/null
$ echo $?
0
Quoted 7 lines
$ gcc -Werror --param asan-instrument-allocas=1 -S -x c /dev/null -o /dev/null
cc1: error: invalid --param name ‘asan-instrument-allocas’; did you mean ‘asan-instrument-writes’?
$ echo $?
1

---

Applied to linux-kbuild.

Quoted 19 lines
 scripts/Kconfig.include | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kconfig.include +1 -2
index d4adfbe42690..bfb44b265a94 100644
@@ -25,7 +25,7 @@ failure = $(if-success,$(1),n,y)
 
 # $(cc-option,<flag>)
 # Return y if the compiler supports <flag>, n otherwise
-cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -E -x c /dev/null -o /dev/null)
+cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
 
 # $(ld-option,<flag>)
 # Return y if the linker supports <flag>, n otherwise
--

2.17.1

Signature · 2 lines
Best Regards
Masahiro Yamada