public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS
@ 2022-09-05  8:36 Masahiro Yamada
  2022-09-05  8:36 ` [PATCH 2/2] kbuild: move -Wundef " Masahiro Yamada
  2022-09-07  5:05 ` [PATCH 1/2] kbuild: move -Werror " Nick Desaulniers
  0 siblings, 2 replies; 6+ messages in thread
From: Masahiro Yamada @ 2022-09-05  8:36 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Masahiro Yamada, Michal Marek, Nick Desaulniers, linux-kernel

CONFIG_WERROR makes warnings into errors, but it only happens for *.c
files because -Werror is added to KBUILD_CFLAGS.

For example, you can put a #warning directive in any preprocessed
source file:

    #warning "blah blah ..."

If it is placed in a *.c file, it emits a warning by default, and it
is promoted to an error when CONFIG_WERROR is enabled:

    error: #warning "blah blah ..." [-Werror=cpp]

If it is placed in a *.S file, it is still a warning.

Move it to KBUILD_CPPFLAGS, so it works in the same way for *.c,
*.S, *.lds.S or whatever needs preprocessing.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index ebcb75442d7f..027d9163eff6 100644
--- a/Makefile
+++ b/Makefile
@@ -788,7 +788,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
 
 KBUILD_CFLAGS += $(stackp-flags-y)
 
-KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
 KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
 KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] kbuild: move -Wundef from KBUILD_CFLAGS to KBUILD_CPPFLAGS
  2022-09-05  8:36 [PATCH 1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS Masahiro Yamada
@ 2022-09-05  8:36 ` Masahiro Yamada
  2022-09-05 15:48   ` kernel test robot
  2022-09-12  9:56   ` kernel test robot
  2022-09-07  5:05 ` [PATCH 1/2] kbuild: move -Werror " Nick Desaulniers
  1 sibling, 2 replies; 6+ messages in thread
From: Masahiro Yamada @ 2022-09-05  8:36 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Masahiro Yamada, Michal Marek, Nick Desaulniers, linux-kernel

The use of an undefined macro in an #if directive is warned, but only
in *.c files. No warning from other files such as *.S, *.lds.S.

Since -Wundef is a preprocessor-related warning, it should be added to
KBUILD_CPPFLAGS instead of KBUILD_CFLAGS.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 027d9163eff6..898a759e314e 100644
--- a/Makefile
+++ b/Makefile
@@ -523,12 +523,12 @@ LINUXINCLUDE    := \
 		$(USERINCLUDE)
 
 KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
-KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
+KBUILD_CFLAGS   := -Wall -Werror=strict-prototypes -Wno-trigraphs \
 		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
 		   -Werror=implicit-function-declaration -Werror=implicit-int \
 		   -Werror=return-type -Wno-format-security \
 		   -std=gnu11
-KBUILD_CPPFLAGS := -D__KERNEL__
+KBUILD_CPPFLAGS := -D__KERNEL__ -Wundef
 KBUILD_AFLAGS_KERNEL :=
 KBUILD_CFLAGS_KERNEL :=
 KBUILD_AFLAGS_MODULE  := -DMODULE
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] kbuild: move -Wundef from KBUILD_CFLAGS to KBUILD_CPPFLAGS
  2022-09-05  8:36 ` [PATCH 2/2] kbuild: move -Wundef " Masahiro Yamada
@ 2022-09-05 15:48   ` kernel test robot
  2022-09-05 16:01     ` Masahiro Yamada
  2022-09-12  9:56   ` kernel test robot
  1 sibling, 1 reply; 6+ messages in thread
From: kernel test robot @ 2022-09-05 15:48 UTC (permalink / raw)
  To: Masahiro Yamada, linux-kbuild
  Cc: llvm, kbuild-all, Masahiro Yamada, Michal Marek, Nick Desaulniers,
	linux-kernel

Hi Masahiro,

I love your patch! Perhaps something to improve:

[auto build test WARNING on masahiroy-kbuild/for-next]
[also build test WARNING on linus/master v6.0-rc4]
[cannot apply to next-20220901]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/kbuild-move-Werror-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220905-164209
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
config: riscv-randconfig-r042-20220905 (https://download.01.org/0day-ci/archive/20220905/202209052329.sY4Fx2fi-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project c55b41d5199d2394dd6cdb8f52180d8b81d809d4)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/2f8ee1865d7d00ad27460d94056c7752cad8481f
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Masahiro-Yamada/kbuild-move-Werror-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220905-164209
        git checkout 2f8ee1865d7d00ad27460d94056c7752cad8481f
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash arch/riscv/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> arch/riscv/kernel/head.S:329:5: warning: 'CONFIG_RISCV_BOOT_SPINWAIT' is not defined, evaluates to 0 [-Wundef]
   #if CONFIG_RISCV_BOOT_SPINWAIT
       ^
   1 warning generated.


vim +/CONFIG_RISCV_BOOT_SPINWAIT +329 arch/riscv/kernel/head.S

76d2a0493a17d4 Palmer Dabbelt    2017-07-10  316  
76d4467a97bd8c Qiu Wenbo         2020-08-13  317  	call setup_trap_vector
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  318  	/* Restore C environment */
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  319  	la tp, init_task
c637b911e06697 Christoph Hellwig 2019-04-15  320  	la sp, init_thread_union + THREAD_SIZE
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  321  
8ad8b72721d0f0 Nick Hu           2020-01-06  322  #ifdef CONFIG_KASAN
8ad8b72721d0f0 Nick Hu           2020-01-06  323  	call kasan_early_init
8ad8b72721d0f0 Nick Hu           2020-01-06  324  #endif
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  325  	/* Start the kernel */
335b139057ef79 Damien Le Moal    2020-03-16  326  	call soc_early_init
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  327  	tail start_kernel
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  328  
2ffc48fc7071da Atish Patra       2022-01-20 @329  #if CONFIG_RISCV_BOOT_SPINWAIT
0b39eb38f85908 Atish Patra       2022-01-20  330  .Lsecondary_start:
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  331  	/* Set trap vector to spin forever to help debug */
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  332  	la a3, .Lsecondary_park
a4c3733d32a72f Christoph Hellwig 2019-10-28  333  	csrw CSR_TVEC, a3
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  334  
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  335  	slli a3, a0, LGREG
c78f94f35cf648 Atish Patra       2022-01-20  336  	la a1, __cpu_spinwait_stack_pointer
44c922572952d8 Vitaly Wool       2021-04-13  337  	XIP_FIXUP_OFFSET a1
c78f94f35cf648 Atish Patra       2022-01-20  338  	la a2, __cpu_spinwait_task_pointer
44c922572952d8 Vitaly Wool       2021-04-13  339  	XIP_FIXUP_OFFSET a2
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  340  	add a1, a3, a1
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  341  	add a2, a3, a2
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  342  
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  343  	/*
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  344  	 * This hart didn't win the lottery, so we wait for the winning hart to
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  345  	 * get far enough along the boot process that it should continue.
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  346  	 */
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  347  .Lwait_for_cpu_up:
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  348  	/* FIXME: We should WFI to save some energy here. */
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  349  	REG_L sp, (a1)
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  350  	REG_L tp, (a2)
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  351  	beqz sp, .Lwait_for_cpu_up
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  352  	beqz tp, .Lwait_for_cpu_up
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  353  	fence
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  354  
153c46faf6ae49 Jisheng Zhang     2021-11-29  355  	tail .Lsecondary_start_common
2ffc48fc7071da Atish Patra       2022-01-20  356  #endif /* CONFIG_RISCV_BOOT_SPINWAIT */
76d2a0493a17d4 Palmer Dabbelt    2017-07-10  357  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] kbuild: move -Wundef from KBUILD_CFLAGS to KBUILD_CPPFLAGS
  2022-09-05 15:48   ` kernel test robot
@ 2022-09-05 16:01     ` Masahiro Yamada
  0 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2022-09-05 16:01 UTC (permalink / raw)
  To: kernel test robot
  Cc: Linux Kbuild mailing list, clang-built-linux, kbuild-all,
	Michal Marek, Nick Desaulniers, Linux Kernel Mailing List

On Tue, Sep 6, 2022 at 12:49 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Masahiro,
>
> I love your patch! Perhaps something to improve:
>
> [auto build test WARNING on masahiroy-kbuild/for-next]
> [also build test WARNING on linus/master v6.0-rc4]
> [cannot apply to next-20220901]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/kbuild-move-Werror-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220905-164209
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
> config: riscv-randconfig-r042-20220905 (https://download.01.org/0day-ci/archive/20220905/202209052329.sY4Fx2fi-lkp@intel.com/config)
> compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project c55b41d5199d2394dd6cdb8f52180d8b81d809d4)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install riscv cross compiling tool for clang build
>         # apt-get install binutils-riscv64-linux-gnu
>         # https://github.com/intel-lab-lkp/linux/commit/2f8ee1865d7d00ad27460d94056c7752cad8481f
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Masahiro-Yamada/kbuild-move-Werror-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220905-164209
>         git checkout 2f8ee1865d7d00ad27460d94056c7752cad8481f
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash arch/riscv/
>
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
>
> All warnings (new ones prefixed by >>):
>
> >> arch/riscv/kernel/head.S:329:5: warning: 'CONFIG_RISCV_BOOT_SPINWAIT' is not defined, evaluates to 0 [-Wundef]
>    #if CONFIG_RISCV_BOOT_SPINWAIT
>        ^
>    1 warning generated.
>



Hmm, it looks like my patch started to uncover a couple of coding mistakes.






 #if CONFIG_RISCV_BOOT_SPINWAIT
          -->

  #ifdef CONFIG_RISCV_BOOT_SPINWAIT


(CONFIG_RISCV_BOOT_SPINWAIT is a bool option)





-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS
  2022-09-05  8:36 [PATCH 1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS Masahiro Yamada
  2022-09-05  8:36 ` [PATCH 2/2] kbuild: move -Wundef " Masahiro Yamada
@ 2022-09-07  5:05 ` Nick Desaulniers
  1 sibling, 0 replies; 6+ messages in thread
From: Nick Desaulniers @ 2022-09-07  5:05 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-kbuild, Michal Marek, linux-kernel

On Mon, Sep 5, 2022 at 1:37 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> CONFIG_WERROR makes warnings into errors, but it only happens for *.c
> files because -Werror is added to KBUILD_CFLAGS.
>
> For example, you can put a #warning directive in any preprocessed
> source file:
>
>     #warning "blah blah ..."
>
> If it is placed in a *.c file, it emits a warning by default, and it
> is promoted to an error when CONFIG_WERROR is enabled:
>
>     error: #warning "blah blah ..." [-Werror=cpp]
>
> If it is placed in a *.S file, it is still a warning.
>
> Move it to KBUILD_CPPFLAGS, so it works in the same way for *.c,
> *.S, *.lds.S or whatever needs preprocessing.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Thanks for the patch. I see in lore you sent many more cleanups but
didn't cc me explicitly...I should probably subscribe to that mailing
list! I probably won't have time to review many patches until after
Linux Plumbers Conf next week.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
>  Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index ebcb75442d7f..027d9163eff6 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -788,7 +788,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
>
>  KBUILD_CFLAGS += $(stackp-flags-y)
>
> -KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
> +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
> +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
>  KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
>  KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
>
> --
> 2.34.1
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] kbuild: move -Wundef from KBUILD_CFLAGS to KBUILD_CPPFLAGS
  2022-09-05  8:36 ` [PATCH 2/2] kbuild: move -Wundef " Masahiro Yamada
  2022-09-05 15:48   ` kernel test robot
@ 2022-09-12  9:56   ` kernel test robot
  1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-09-12  9:56 UTC (permalink / raw)
  To: Masahiro Yamada, linux-kbuild
  Cc: kbuild-all, Masahiro Yamada, Michal Marek, Nick Desaulniers,
	linux-kernel

Hi Masahiro,

I love your patch! Perhaps something to improve:

[auto build test WARNING on masahiroy-kbuild/for-next]
[also build test WARNING on linus/master v6.0-rc5]
[cannot apply to next-20220909]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/kbuild-move-Werror-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220905-164209
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
config: s390-randconfig-s052-20220911 (https://download.01.org/0day-ci/archive/20220912/202209121730.ipnGRE83-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 12.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-39-gce1a6720-dirty
        # https://github.com/intel-lab-lkp/linux/commit/2f8ee1865d7d00ad27460d94056c7752cad8481f
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Masahiro-Yamada/kbuild-move-Werror-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220905-164209
        git checkout 2f8ee1865d7d00ad27460d94056c7752cad8481f
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=s390 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

sparse warnings: (new ones prefixed by >>)
>> arch/s390/boot/decompressor.c:28:7: sparse: sparse: undefined preprocessor identifier 'CONFIG_KERNEL_ZSTD'

vim +/CONFIG_KERNEL_ZSTD +28 arch/s390/boot/decompressor.c

1844c9bc0b2fed arch/s390/boot/compressed/misc.c         Martin Schwidefsky  2010-02-26  25  
54f45214522ae7 arch/s390/boot/compressed/decompressor.c Vasily Gorbik       2021-06-16  26  #ifdef CONFIG_KERNEL_BZIP2
1b3e3faf29d3ac arch/s390/boot/compressed/decompressor.c Mikhail Zaslonko    2020-01-30  27  #define BOOT_HEAP_SIZE	0x400000
7b034d9c1b08b3 arch/s390/boot/compressed/decompressor.c Dimitri John Ledkov 2021-06-15 @28  #elif CONFIG_KERNEL_ZSTD
7b034d9c1b08b3 arch/s390/boot/compressed/decompressor.c Dimitri John Ledkov 2021-06-15  29  #define BOOT_HEAP_SIZE	0x30000
1844c9bc0b2fed arch/s390/boot/compressed/misc.c         Martin Schwidefsky  2010-02-26  30  #else
1b3e3faf29d3ac arch/s390/boot/compressed/decompressor.c Mikhail Zaslonko    2020-01-30  31  #define BOOT_HEAP_SIZE	0x10000
1844c9bc0b2fed arch/s390/boot/compressed/misc.c         Martin Schwidefsky  2010-02-26  32  #endif
1844c9bc0b2fed arch/s390/boot/compressed/misc.c         Martin Schwidefsky  2010-02-26  33  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-12  9:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05  8:36 [PATCH 1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS Masahiro Yamada
2022-09-05  8:36 ` [PATCH 2/2] kbuild: move -Wundef " Masahiro Yamada
2022-09-05 15:48   ` kernel test robot
2022-09-05 16:01     ` Masahiro Yamada
2022-09-12  9:56   ` kernel test robot
2022-09-07  5:05 ` [PATCH 1/2] kbuild: move -Werror " Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox