Commit 8417da6f2128008c431c7d130af6cd3d9079922e

Authored by Michal Marek
1 parent bffd2020a9

kbuild: Fix passing -Wno-* options to gcc 4.4+

Starting with 4.4, gcc will happily accept -Wno-<anything> in the
cc-option test and complain later when compiling a file that has some
other warning. This rather unexpected behavior is intentional as per
http://gcc.gnu.org/PR28322, so work around it by testing for support of
the opposite option (without the no-). Introduce a new Makefile function
cc-disable-warning that does this and update two uses of cc-option in
the toplevel Makefile.

Reported-and-tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Michal Marek <mmarek@suse.cz>

Showing 3 changed files with 19 additions and 2 deletions Side-by-side Diff

Documentation/kbuild/makefiles.txt
... ... @@ -501,6 +501,18 @@
501 501 gcc >= 3.00. For gcc < 3.00, -malign-functions=4 is used.
502 502 Note: cc-option-align uses KBUILD_CFLAGS for $(CC) options
503 503  
  504 + cc-disable-warning
  505 + cc-disable-warning checks if gcc supports a given warning and returns
  506 + the commandline switch to disable it. This special function is needed,
  507 + because gcc 4.4 and later accept any unknown -Wno-* option and only
  508 + warn about it if there is another warning in the source file.
  509 +
  510 + Example:
  511 + KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
  512 +
  513 + In the above example, -Wno-unused-but-set-variable will be added to
  514 + KBUILD_CFLAGS only if gcc really accepts it.
  515 +
504 516 cc-version
505 517 cc-version returns a numerical version of the $(CC) compiler version.
506 518 The format is <major><minor> where both are two digits. So for example
... ... @@ -569,7 +569,7 @@
569 569  
570 570 # This warning generated too much noise in a regular build.
571 571 # Use make W=1 to enable this warning (see scripts/Makefile.build)
572   -KBUILD_CFLAGS += $(call cc-option, -Wno-unused-but-set-variable)
  572 +KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
573 573  
574 574 ifdef CONFIG_FRAME_POINTER
575 575 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
... ... @@ -616,7 +616,7 @@
616 616 KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
617 617  
618 618 # disable pointer signed / unsigned warnings in gcc 4.0
619   -KBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)
  619 +KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign)
620 620  
621 621 # disable invalid "can't wrap" optimizations for signed / pointers
622 622 KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
scripts/Kbuild.include
... ... @@ -118,6 +118,11 @@
118 118 cc-option-align = $(subst -functions=0,,\
119 119 $(call cc-option,-falign-functions=0,-malign-functions=0))
120 120  
  121 +# cc-disable-warning
  122 +# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
  123 +cc-disable-warning = $(call try-run,\
  124 + $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -xc /dev/null -o "$$TMP",-Wno-$(strip $(1)))
  125 +
121 126 # cc-version
122 127 # Usage gcc-ver := $(call cc-version)
123 128 cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))