diff mbox series

[v2] kbuild: move -Wundef from KBUILD_CFLAGS to KBUILD_CPPFLAGS

Message ID 20220913080727.608495-1-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v2] kbuild: move -Wundef from KBUILD_CFLAGS to KBUILD_CPPFLAGS | expand

Commit Message

Masahiro Yamada Sept. 13, 2022, 8:07 a.m. UTC
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.

Fix some uncovered issues.

[1] Add -D__LINUX_ARM_ARCH__=* to KBUILD_CPPFLAGS

In file included from arch/arm/kernel/vmlinux.lds.S:13:
./arch/arm/include/asm/cache.h:23:31: warning: "__LINUX_ARM_ARCH__" is not defined, evaluates to 0 [-Wundef]
   23 | #if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
      |                               ^~~~~~~~~~~~~~~~~~

[2] Add missing #include <asm/pgtable.h>

In file included from arch/arm/mm/cache-v7.S:17:
arch/arm/mm/proc-macros.S:109:5: warning: "L_PTE_SHARED" is not defined, evaluates to 0 [-Wundef]
  109 | #if L_PTE_SHARED != PTE_EXT_SHARED
      |     ^~~~~~~~~~~~
arch/arm/mm/proc-macros.S:109:21: warning: "PTE_EXT_SHARED" is not defined, evaluates to 0 [-Wundef]
  109 | #if L_PTE_SHARED != PTE_EXT_SHARED
      |                     ^~~~~~~~~~~~~~
arch/arm/mm/proc-macros.S:113:10: warning: "L_PTE_XN" is not defined, evaluates to 0 [-Wundef]
  113 |         (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
      |          ^~~~~~~~
arch/arm/mm/proc-macros.S:113:19: warning: "L_PTE_USER" is not defined, evaluates to 0 [-Wundef]
  113 |         (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
      |                   ^~~~~~~~~~
arch/arm/mm/proc-macros.S:113:30: warning: "L_PTE_RDONLY" is not defined, evaluates to 0 [-Wundef]
  113 |         (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
      |                              ^~~~~~~~~~~~
arch/arm/mm/proc-macros.S:113:43: warning: "L_PTE_DIRTY" is not defined, evaluates to 0 [-Wundef]
  113 |         (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
      |                                           ^~~~~~~~~~~
arch/arm/mm/proc-macros.S:113:55: warning: "L_PTE_YOUNG" is not defined, evaluates to 0 [-Wundef]
  113 |         (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
      |                                                       ^~~~~~~~~~~
arch/arm/mm/proc-macros.S:114:10: warning: "L_PTE_PRESENT" is not defined, evaluates to 0 [-Wundef]
  114 |          L_PTE_PRESENT) > L_PTE_SHARED
      |          ^~~~~~~~~~~~~
arch/arm/mm/proc-macros.S:114:27: warning: "L_PTE_SHARED" is not defined, evaluates to 0 [-Wundef]
  114 |          L_PTE_PRESENT) > L_PTE_SHARED
      |                           ^~~~~~~~~~~~

[3] #if -> #ifdef

arch/riscv/kernel/head.S:329:5: warning: "CONFIG_RISCV_BOOT_SPINWAIT" is not defined, evaluates to 0 [-Wundef]
  329 | #if CONFIG_RISCV_BOOT_SPINWAIT
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~

[4] #elif -> #elif defined()

arch/s390/boot/decompressor.c:28:7: warning: "CONFIG_KERNEL_ZSTD" is not defined, evaluates to 0 [-Wundef]
   28 | #elif CONFIG_KERNEL_ZSTD
      |       ^~~~~~~~~~~~~~~~~~

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

Changes in v2:
  - Fix warnings

 Makefile                      | 4 ++--
 arch/arm/Makefile             | 1 +
 arch/arm/mm/proc-macros.S     | 1 +
 arch/riscv/kernel/head.S      | 2 +-
 arch/s390/boot/decompressor.c | 2 +-
 5 files changed, 6 insertions(+), 4 deletions(-)

Comments

kernel test robot Sept. 23, 2022, 2:26 a.m. UTC | #1
Hi Masahiro,

I love your patch! Perhaps something to improve:

[auto build test WARNING on masahiroy-kbuild/for-next]
[also build test WARNING on s390/features soc/for-next linus/master v6.0-rc6]
[cannot apply to next-20220921]
[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-Wundef-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220913-161447
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
config: arm64-buildonly-randconfig-r003-20220922 (https://download.01.org/0day-ci/archive/20220923/202209231052.nj1STd5X-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0
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
        # https://github.com/intel-lab-lkp/linux/commit/ccf1a82d3dedb27a2b1b21f64e09183b197e1f6f
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Masahiro-Yamada/kbuild-move-Wundef-from-KBUILD_CFLAGS-to-KBUILD_CPPFLAGS/20220913-161447
        git checkout ccf1a82d3dedb27a2b1b21f64e09183b197e1f6f
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kernel/

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 >>):

   In file included from arch/arm64/kernel/vmlinux.lds.S:65:
>> arch/arm64/include/asm/kernel-pgtable.h:135:41: warning: "PMD_SHIFT" is not defined, evaluates to 0 [-Wundef]
     135 | #define ARM64_MEMSTART_SHIFT            PMD_SHIFT
         |                                         ^~~~~~~~~
   arch/arm64/include/asm/kernel-pgtable.h:144:5: note: in expansion of macro 'ARM64_MEMSTART_SHIFT'
     144 | #if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
         |     ^~~~~~~~~~~~~~~~~~~~


vim +/PMD_SHIFT +135 arch/arm64/include/asm/kernel-pgtable.h

87d1587bef394c Suzuki K. Poulose 2015-10-19  122  
a7f8de168ace48 Ard Biesheuvel    2016-02-16  123  /*
a7f8de168ace48 Ard Biesheuvel    2016-02-16  124   * To make optimal use of block mappings when laying out the linear
a7f8de168ace48 Ard Biesheuvel    2016-02-16  125   * mapping, round down the base of physical memory to a size that can
a7f8de168ace48 Ard Biesheuvel    2016-02-16  126   * be mapped efficiently, i.e., either PUD_SIZE (4k granule) or PMD_SIZE
a7f8de168ace48 Ard Biesheuvel    2016-02-16  127   * (64k granule), or a multiple that can be mapped using contiguous bits
a7f8de168ace48 Ard Biesheuvel    2016-02-16  128   * in the page tables: 32 * PMD_SIZE (16k granule)
a7f8de168ace48 Ard Biesheuvel    2016-02-16  129   */
06e9bf2fd9b372 Ard Biesheuvel    2016-03-30  130  #if defined(CONFIG_ARM64_4K_PAGES)
06e9bf2fd9b372 Ard Biesheuvel    2016-03-30  131  #define ARM64_MEMSTART_SHIFT		PUD_SHIFT
06e9bf2fd9b372 Ard Biesheuvel    2016-03-30  132  #elif defined(CONFIG_ARM64_16K_PAGES)
ca6ece6a76a8b5 Anshuman Khandual 2021-06-14  133  #define ARM64_MEMSTART_SHIFT		CONT_PMD_SHIFT
a7f8de168ace48 Ard Biesheuvel    2016-02-16  134  #else
06e9bf2fd9b372 Ard Biesheuvel    2016-03-30 @135  #define ARM64_MEMSTART_SHIFT		PMD_SHIFT
06e9bf2fd9b372 Ard Biesheuvel    2016-03-30  136  #endif
06e9bf2fd9b372 Ard Biesheuvel    2016-03-30  137
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 4beeb96f9d81..bf4328535cf9 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
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 29d15c9a433e..4bb5743fe3a4 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -129,6 +129,7 @@  AFLAGS_ISA	:=$(CFLAGS_ISA)
 endif
 
 # Need -Uarm for gcc < 3.x
+KBUILD_CPPFLAGS	+= $(filter -D%, $(arch-y))
 KBUILD_CFLAGS	+=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
 KBUILD_AFLAGS	+=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float
 
diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
index fa6999e24b07..e43f6d716b4b 100644
--- a/arch/arm/mm/proc-macros.S
+++ b/arch/arm/mm/proc-macros.S
@@ -6,6 +6,7 @@ 
  *  VM_EXEC
  */
 #include <asm/asm-offsets.h>
+#include <asm/pgtable.h>
 #include <asm/thread_info.h>
 
 #ifdef CONFIG_CPU_V7M
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index b865046e4dbb..4bf6c449d78b 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -326,7 +326,7 @@  clear_bss_done:
 	call soc_early_init
 	tail start_kernel
 
-#if CONFIG_RISCV_BOOT_SPINWAIT
+#ifdef CONFIG_RISCV_BOOT_SPINWAIT
 .Lsecondary_start:
 	/* Set trap vector to spin forever to help debug */
 	la a3, .Lsecondary_park
diff --git a/arch/s390/boot/decompressor.c b/arch/s390/boot/decompressor.c
index e27c2140d620..f96657faffdc 100644
--- a/arch/s390/boot/decompressor.c
+++ b/arch/s390/boot/decompressor.c
@@ -25,7 +25,7 @@ 
 
 #ifdef CONFIG_KERNEL_BZIP2
 #define BOOT_HEAP_SIZE	0x400000
-#elif CONFIG_KERNEL_ZSTD
+#elif defined(CONFIG_KERNEL_ZSTD)
 #define BOOT_HEAP_SIZE	0x30000
 #else
 #define BOOT_HEAP_SIZE	0x10000