kbuild: upgrade the orphan section warning to an error if CONFIG_WERROR is set
authorXin Li <xin3.li@intel.com>
Tue, 25 Oct 2022 07:30:23 +0000 (00:30 -0700)
committerKees Cook <keescook@chromium.org>
Tue, 1 Nov 2022 17:04:52 +0000 (10:04 -0700)
Andrew Cooper suggested upgrading the orphan section warning to a hard link
error. However Nathan Chancellor said outright turning the warning into an
error with no escape hatch might be too aggressive, as we have had these
warnings triggered by new compiler generated sections, and suggested turning
orphan sections into an error only if CONFIG_WERROR is set. Kees Cook echoed
and emphasized that the mandate from Linus is that we should avoid breaking
builds. It wrecks bisection, it causes problems across compiler versions, etc.

Thus upgrade the orphan section warning to a hard link error only if
CONFIG_WERROR is set.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Xin Li <xin3.li@intel.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221025073023.16137-2-xin3.li@intel.com
Makefile
arch/arm/boot/compressed/Makefile
arch/arm64/kernel/vdso/Makefile
arch/arm64/kernel/vdso32/Makefile
arch/x86/boot/compressed/Makefile
init/Kconfig

index f41ec8c8426ba2a351ca18d003872db77ea20127..9a496bef3170c223eb3f08a35a89b3403e1ca616 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1118,7 +1118,7 @@ endif
 # We never want expected sections to be placed heuristically by the
 # linker. All sections should be explicitly named in the linker script.
 ifdef CONFIG_LD_ORPHAN_WARN
-LDFLAGS_vmlinux += --orphan-handling=warn
+LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
 endif
 
 # Align the bit size of userspace programs with the kernel
index 41bcbb460fac459c70261a2cb384b13c56ef9058..53cadc3aaff11cba8ccc516bd19fa718cfb7302d 100644 (file)
@@ -123,7 +123,7 @@ LDFLAGS_vmlinux += --no-undefined
 LDFLAGS_vmlinux += -X
 # Report orphan sections
 ifdef CONFIG_LD_ORPHAN_WARN
-LDFLAGS_vmlinux += --orphan-handling=warn
+LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
 endif
 # Next argument is a linker script
 LDFLAGS_vmlinux += -T
index 619e2dc7ee14cce1b906c1962c5429194260ad80..beaf9586338f5c10569764a9728209289a06756c 100644 (file)
@@ -27,7 +27,7 @@ ldflags-y := -shared -soname=linux-vdso.so.1 --hash-style=sysv        \
             -Bsymbolic --build-id=sha1 -n $(btildflags-y)
 
 ifdef CONFIG_LD_ORPHAN_WARN
-  ldflags-y += --orphan-handling=warn
+  ldflags-y += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
 endif
 
 ldflags-y += -T
index 36c8f66cad251ac3711f73f5b94d353311bde0b7..f59bd1a4ead6b46d31f0a7a6e3d5bf08212b1891 100644 (file)
@@ -104,7 +104,7 @@ VDSO_AFLAGS += -D__ASSEMBLY__
 VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
 VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
 VDSO_LDFLAGS += -shared --hash-style=sysv --build-id=sha1
-VDSO_LDFLAGS += --orphan-handling=warn
+VDSO_LDFLAGS += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
 
 
 # Borrow vdsomunge.c from the arm vDSO
index 3a261abb6d158d62c9592f115ec39542d23ca2ab..66b8a8cb5a0f814528eb73a5ac09be9c3f20b0f8 100644 (file)
@@ -68,7 +68,7 @@ KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
 # address by the bootloader.
 LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
 ifdef CONFIG_LD_ORPHAN_WARN
-LDFLAGS_vmlinux += --orphan-handling=warn
+LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
 endif
 LDFLAGS_vmlinux += -z noexecstack
 ifeq ($(CONFIG_LD_IS_BFD),y)
index 694f7c160c9c107e513ca69b7efe17b232570405..bb1225ef04e76b739ad947f42d0bb7da6e341d39 100644 (file)
@@ -159,10 +159,12 @@ config WERROR
        help
          A kernel build should not cause any compiler warnings, and this
          enables the '-Werror' (for C) and '-Dwarnings' (for Rust) flags
-         to enforce that rule by default.
+         to enforce that rule by default. Certain warnings from other tools
+         such as the linker may be upgraded to errors with this option as
+         well.
 
-         However, if you have a new (or very old) compiler with odd and
-         unusual warnings, or you have some architecture with problems,
+         However, if you have a new (or very old) compiler or linker with odd
+         and unusual warnings, or you have some architecture with problems,
          you may need to disable this config option in order to
          successfully build the kernel.
 
@@ -1454,6 +1456,13 @@ config LD_ORPHAN_WARN
        def_bool y
        depends on ARCH_WANT_LD_ORPHAN_WARN
        depends on $(ld-option,--orphan-handling=warn)
+       depends on $(ld-option,--orphan-handling=error)
+
+config LD_ORPHAN_WARN_LEVEL
+        string
+        depends on LD_ORPHAN_WARN
+        default "error" if WERROR
+        default "warn"
 
 config SYSCTL
        bool