kbuild: upgrade the orphan section warning to an error if CONFIG_WERROR is set
Subsystems (4)
cover kbuild: upgrade the orphan section warning to an error if CONFIG_WERROR is set
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.
Xin Li (1):
kbuild: upgrade the orphan section warning to an error if
CONFIG_WERROR is set
Makefile | 2 +- arch/arm/boot/compressed/Makefile | 2 +- arch/arm64/kernel/vdso/Makefile | 2 +- arch/arm64/kernel/vdso32/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- init/Kconfig | 9 ++++++--- 6 files changed, 11 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/1 kbuild: upgrade the orphan section warning to an error if CONFIG_WERROR is set
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.
--- Makefile | 2 +- arch/arm/boot/compressed/Makefile | 2 +- arch/arm64/kernel/vdso/Makefile | 2 +- arch/arm64/kernel/vdso32/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- init/Kconfig | 9 ++++++--- 6 files changed, 11 insertions(+), 8 deletions(-)
Makefile +1 -1
@@ -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=$(if $(CONFIG_WERROR),error,warn) endif # Align the bit size of userspace programs with the kernel
arch/arm/boot/compressed/Makefile +1 -1
@@ -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=$(if $(CONFIG_WERROR),error,warn) endif # Next argument is a linker script LDFLAGS_vmlinux += -T
arch/arm64/kernel/vdso/Makefile +1 -1
@@ -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=$(if $(CONFIG_WERROR),error,warn) endif ldflags-y += -T
arch/arm64/kernel/vdso32/Makefile +1 -1
@@ -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=$(if $(CONFIG_WERROR),error,warn) # Borrow vdsomunge.c from the arm vDSO
arch/x86/boot/compressed/Makefile +1 -1
@@ -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=$(if $(CONFIG_WERROR),error,warn) endif LDFLAGS_vmlinux += -z noexecstack ifeq ($(CONFIG_LD_IS_BFD),y)
init/Kconfig +6 -3
@@ -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,7 @@ 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 SYSCTL bool
Signature · 1 line
2.34.1
Quoted 8 lines · Xin Li
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_WERRORis 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.
Quoted 6 lines
Thus upgrade the orphan section warning to a hard link error only if
CONFIG_WERRORis set.Suggested-by Andrew Cooper <[email protected]>Suggested-by Nathan Chancellor <[email protected]>Signed-off-by Xin Li <[email protected]>
Thanks for the patch!
We could deduplicate the '$(if $(CONFIG_WERROR),error,warn)' logic if we hoisted it into Kconfig by having something like
config LD_ORPHAN_WARN_LEVEL
string
depends on LD_ORPHAN_WARN
default "error" if WERROR
default "warn"
in init/Kconfig then using it everywhere like
--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
but I will let others decide if they would prefer that over the direction we went here.
Cheers,
Nathan
Quoted 106 lines
--- Makefile | 2 +- arch/arm/boot/compressed/Makefile | 2 +- arch/arm64/kernel/vdso/Makefile | 2 +- arch/arm64/kernel/vdso32/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- init/Kconfig | 9 ++++++--- 6 files changed, 11 insertions(+), 8 deletions(-)Makefile +1
-1@@ -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=$(if $(CONFIG_WERROR),error,warn) endif # Align the bit size of userspace programs with the kernelarch/arm/boot/compressed/Makefile +1
-1@@ -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=$(if $(CONFIG_WERROR),error,warn) endif # Next argument is a linker script LDFLAGS_vmlinux += -Tarch/arm64/kernel/vdso/Makefile +1
-1@@ -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=$(if $(CONFIG_WERROR),error,warn) endif ldflags-y += -Tarch/arm64/kernel/vdso32/Makefile +1
-1@@ -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=$(if $(CONFIG_WERROR),error,warn) # Borrow vdsomunge.c from the arm vDSOarch/x86/boot/compressed/Makefile +1
-1@@ -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=$(if $(CONFIG_WERROR),error,warn) endif LDFLAGS_vmlinux += -z noexecstack ifeq ($(CONFIG_LD_IS_BFD),y)init/Kconfig +6
-3@@ -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,7 @@ 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 SYSCTL boolSignature · 1 line
2.34.1
Quoted 30 lines · Nathan Chancellor
Quoted 8 lines · Xin Li
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_WERRORis 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.Quoted 6 lines
Thus upgrade the orphan section warning to a hard link error only if
CONFIG_WERRORis set.Suggested-by Andrew Cooper <[email protected]>Suggested-by Nathan Chancellor <[email protected]>Signed-off-by Xin Li <[email protected]>Thanks for the patch!
Reviewed-by Nathan Chancellor <[email protected]>Tested-by Nathan Chancellor <[email protected]>We could deduplicate the '$(if $(CONFIG_WERROR),error,warn)' logic if we hoisted it into
Kconfigby having something likeconfig
LD_ORPHAN_WARN_LEVEL
string
depends onLD_ORPHAN_WARN
default "error" if WERROR
default "warn"
Quoted 6 lines
in init/Kconfig then using it everywhere like
--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)but I will let others decide if they would prefer that over the direction we went here.
I think this makes it look cleaner, yeah.
Signature · 1 line
Kees Cook
Quoted 32 lines · Nathan Chancellor
Quoted 8 lines · Xin Li
Quoted 7 lines
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_WERRORis set. Kees Cook echoed and emphasized that the mandate from Linus is that we should avoid breaking builds. It wrecksbisection, it causes problems across compiler versions, etc.
Quoted 22 lines
Quoted 7 lines
Thus upgrade the orphan section warning to a hard link error only if
CONFIG_WERRORis set.Suggested-by Andrew Cooper <[email protected]>Suggested-by Nathan Chancellor <[email protected]>Signed-off-by Xin Li <[email protected]>Thanks for the patch!
Reviewed-by Nathan Chancellor <[email protected]>Tested-by Nathan Chancellor <[email protected]>We could deduplicate the '$(if $(CONFIG_WERROR),error,warn)' logic if we hoisted it into
Kconfigby having something likeconfig
LD_ORPHAN_WARN_LEVEL
string
depends onLD_ORPHAN_WARN
default "error" if WERROR
default "warn"
Quoted 8 lines
Quoted 6 lines
in init/Kconfig then using it everywhere like
--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)but I will let others decide if they would prefer that over the direction we went here.
I think this makes it look cleaner, yeah.
Agree this looks much cleaner.
Quoted 3 lines
--
Kees Cook