kconfig: unify cc-option and as-option
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 14 Jun 2020 14:43:41 +0000 (23:43 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Wed, 17 Jun 2020 01:38:42 +0000 (10:38 +0900)
cc-option and as-option are almost the same; both pass the flag to
$(CC). The main difference is the cc-option stops before the assemble
stage (-S option) whereas as-option stops after (-c option).

I chose -S because it is slightly faster, but $(cc-option,-gz=zlib)
returns a wrong result (https://lkml.org/lkml/2020/6/9/1529).
It has been fixed by commit 7b16994437c7 ("Makefile: Improve compressed
debug info support detection"), but the assembler should always be
invoked for more reliable compiler option tests.

However, you cannot simply replace -S with -c because the following
code in lib/Kconfig.debug would break:

    depends on $(cc-option,-gsplit-dwarf)

The combination of -c and -gsplit-dwarf does not accept /dev/null as
output.

  $ cat /dev/null | gcc -gsplit-dwarf -S -x c - -o /dev/null
  $ echo $?
  0

  $ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o /dev/null
  objcopy: Warning: '/dev/null' is not an ordinary file
  $ echo $?
  1

  $ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o tmp.o
  $ echo $?
  0

There is another flag that creates an separate file based on the
object file path:

  $ cat /dev/null | gcc -ftest-coverage -c -x c - -o /dev/null
  <stdin>:1: error: cannot open /dev/null.gcno

So, we cannot use /dev/null to sink the output.

Align the cc-option implementation with scripts/Kbuild.include.

With -c option used in cc-option, as-option is unneeded.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Will Deacon <will@kernel.org>
arch/arm64/Kconfig
lib/Kconfig.debug
scripts/Kconfig.include

index 31380da536894a2287cef1c77f72b1a28ce1910a..6eb18f45258e546a9ea0796a3993e2208ad504a6 100644 (file)
@@ -1564,7 +1564,7 @@ config CC_HAS_SIGN_RETURN_ADDRESS
        def_bool $(cc-option,-msign-return-address=all)
 
 config AS_HAS_PAC
-       def_bool $(as-option,-Wa$(comma)-march=armv8.3-a)
+       def_bool $(cc-option,-Wa$(comma)-march=armv8.3-a)
 
 config AS_HAS_CFI_NEGATE_RA_STATE
        def_bool $(as-instr,.cfi_startproc\n.cfi_negate_ra_state\n.cfi_endproc\n)
index 96999d4d2ddad2697963e11a2a1ac7c3b27baa17..9ad9210d70a135732ad6d12ec320f8f1e13aa131 100644 (file)
@@ -229,7 +229,6 @@ config DEBUG_INFO_COMPRESSED
        bool "Compressed debugging information"
        depends on DEBUG_INFO
        depends on $(cc-option,-gz=zlib)
-       depends on $(as-option,-gz=zlib)
        depends on $(ld-option,--compress-debug-sections=zlib)
        help
          Compress the debug information using zlib.  Requires GCC 5.0+ or Clang
index c264da2b9b3083738eb6bb67d513a76634dca572..a5fe72c504ffb86fc31368927b29dd4bfc434b22 100644 (file)
@@ -25,18 +25,12 @@ 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) -S -x c /dev/null -o /dev/null)
+cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
 
 # $(ld-option,<flag>)
 # Return y if the linker supports <flag>, n otherwise
 ld-option = $(success,$(LD) -v $(1))
 
-# $(as-option,<flag>)
-# /dev/zero is used as output instead of /dev/null as some assembler cribs when
-# both input and output are same. Also both of them have same write behaviour so
-# can be easily substituted.
-as-option = $(success, $(CC) $(CLANG_FLAGS) $(1) -c -x assembler /dev/null -o /dev/zero)
-
 # $(as-instr,<instr>)
 # Return y if the assembler supports <instr>, n otherwise
 as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)