Skip to content

Commit a76d493

Browse files
nickdesaulniersgregkh
authored andcommitted
kbuild: Update assembler calls to use proper flags and language target
commit d5c8d6e upstream. as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can cause as-option to fail unexpectedly when CONFIG_WERROR is set, because clang will emit -Werror,-Wunused-command-line-argument for various -m and -f flags in KBUILD_CFLAGS for assembler sources. Callers of as-option and as-instr should be adding flags to KBUILD_AFLAGS / aflags-y, not KBUILD_CFLAGS / cflags-y. Use KBUILD_AFLAGS in all macros to clear up the initial problem. Unfortunately, -Wunused-command-line-argument can still be triggered with clang by the presence of warning flags or macro definitions because '-x assembler' is used, instead of '-x assembler-with-cpp', which will consume these flags. Switch to '-x assembler-with-cpp' in places where '-x assembler' is used, as the compiler is always used as the driver for out of line assembler sources in the kernel. Finally, add -Werror to these macros so that they behave consistently whether or not CONFIG_WERROR is set. [nathan: Reworded and expanded on problems in commit message Use '-x assembler-with-cpp' in a couple more places] Link: ClangBuiltLinux/linux#1699 Suggested-by: Masahiro Yamada <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Tested-by: Linux Kernel Functional Testing <[email protected]> Tested-by: Anders Roxell <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5abcd2c commit a76d493

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

scripts/Kconfig.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ld-option = $(success,$(LD) -v $(1))
3333

3434
# $(as-instr,<instr>)
3535
# Return y if the assembler supports <instr>, n otherwise
36-
as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
36+
as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler-with-cpp -o /dev/null -)
3737

3838
# check if $(CC) and $(LD) exist
3939
$(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)

scripts/Makefile.compiler

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ try-run = $(shell set -e; \
2929
fi)
3030

3131
# as-option
32-
# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
32+
# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
3333

3434
as-option = $(call try-run,\
35-
$(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
35+
$(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2))
3636

3737
# as-instr
38-
# Usage: cflags-y += $(call as-instr,instr,option1,option2)
38+
# Usage: aflags-y += $(call as-instr,instr,option1,option2)
3939

4040
as-instr = $(call try-run,\
41-
printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
41+
printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
4242

4343
# __cc-option
4444
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)

scripts/as-version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ orig_args="$@"
4545
# Get the first line of the --version output.
4646
IFS='
4747
'
48-
set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null)
48+
set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler-with-cpp /dev/null -o /dev/null 2>/dev/null)
4949

5050
# Split the line on spaces.
5151
IFS=' '

0 commit comments

Comments
 (0)