Skip to content

Commit e1789d7

Browse files
xinli-intelkees
authored andcommitted
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. Suggested-by: Andrew Cooper <[email protected]> Suggested-by: Nathan Chancellor <[email protected]> Signed-off-by: Xin Li <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5a17f04 commit e1789d7

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ endif
11181118
# We never want expected sections to be placed heuristically by the
11191119
# linker. All sections should be explicitly named in the linker script.
11201120
ifdef CONFIG_LD_ORPHAN_WARN
1121-
LDFLAGS_vmlinux += --orphan-handling=warn
1121+
LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
11221122
endif
11231123

11241124
# Align the bit size of userspace programs with the kernel

arch/arm/boot/compressed/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ LDFLAGS_vmlinux += --no-undefined
123123
LDFLAGS_vmlinux += -X
124124
# Report orphan sections
125125
ifdef CONFIG_LD_ORPHAN_WARN
126-
LDFLAGS_vmlinux += --orphan-handling=warn
126+
LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
127127
endif
128128
# Next argument is a linker script
129129
LDFLAGS_vmlinux += -T

arch/arm64/kernel/vdso/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ldflags-y := -shared -soname=linux-vdso.so.1 --hash-style=sysv \
2727
-Bsymbolic --build-id=sha1 -n $(btildflags-y)
2828

2929
ifdef CONFIG_LD_ORPHAN_WARN
30-
ldflags-y += --orphan-handling=warn
30+
ldflags-y += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
3131
endif
3232

3333
ldflags-y += -T

arch/arm64/kernel/vdso32/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ VDSO_AFLAGS += -D__ASSEMBLY__
104104
VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
105105
VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
106106
VDSO_LDFLAGS += -shared --hash-style=sysv --build-id=sha1
107-
VDSO_LDFLAGS += --orphan-handling=warn
107+
VDSO_LDFLAGS += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
108108

109109

110110
# Borrow vdsomunge.c from the arm vDSO

arch/x86/boot/compressed/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
6868
# address by the bootloader.
6969
LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
7070
ifdef CONFIG_LD_ORPHAN_WARN
71-
LDFLAGS_vmlinux += --orphan-handling=warn
71+
LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
7272
endif
7373
LDFLAGS_vmlinux += -z noexecstack
7474
ifeq ($(CONFIG_LD_IS_BFD),y)

init/Kconfig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ config WERROR
159159
help
160160
A kernel build should not cause any compiler warnings, and this
161161
enables the '-Werror' (for C) and '-Dwarnings' (for Rust) flags
162-
to enforce that rule by default.
162+
to enforce that rule by default. Certain warnings from other tools
163+
such as the linker may be upgraded to errors with this option as
164+
well.
163165

164-
However, if you have a new (or very old) compiler with odd and
165-
unusual warnings, or you have some architecture with problems,
166+
However, if you have a new (or very old) compiler or linker with odd
167+
and unusual warnings, or you have some architecture with problems,
166168
you may need to disable this config option in order to
167169
successfully build the kernel.
168170

@@ -1454,6 +1456,13 @@ config LD_ORPHAN_WARN
14541456
def_bool y
14551457
depends on ARCH_WANT_LD_ORPHAN_WARN
14561458
depends on $(ld-option,--orphan-handling=warn)
1459+
depends on $(ld-option,--orphan-handling=error)
1460+
1461+
config LD_ORPHAN_WARN_LEVEL
1462+
string
1463+
depends on LD_ORPHAN_WARN
1464+
default "error" if WERROR
1465+
default "warn"
14571466

14581467
config SYSCTL
14591468
bool

0 commit comments

Comments
 (0)