objtool: Add option to fail build on vmlinux warnings
Subsystems (3)
cover objtool: Add option to fail build on vmlinux warnings
This adds an option to objtool to exit with an error when it enounters warnings.
Then, it adds a config to enable that flag on vmlinux. This enables you to fail the build e.g. when noinstr is violated.
---
Brendan Jackman (2):
objtool: Add --fail-on-warn
kbuild: Add option to fail build on vmlinux objtool issues
lib/Kconfig.debug | 11 +++++++++++ scripts/Makefile.vmlinux_o | 1 + tools/objtool/builtin-check.c | 6 ++++++ tools/objtool/check.c | 7 ++----- tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 21 insertions(+), 5 deletions(-)
---
base-commit: f932fb9b40749d1c9a539d89bb3e288c077aafe5
change-id: 20241213-objtool-strict-cb9a0a75139e
Best regards,
Signature · 1 line
Brendan Jackman <[email protected]>
PATCH 1/2 objtool: Add --fail-on-warn
At present objtool only prints to the terminal when observing "fatal warnings". This option lets you have it produce an error instead.
My use case for this is noinstr validation; so far I've never seen any false warnings here, but it quite often detects real bugs. I'd like my build to fail when I have those bugs.
--- tools/objtool/builtin-check.c | 6 ++++++ tools/objtool/check.c | 7 ++----- tools/objtool/include/objtool/builtin.h | 1 + 3 files changed, 9 insertions(+), 5 deletions(-)
tools/objtool/builtin-check.c +6 -0
@@ -94,6 +94,12 @@ static const struct option check_options[] = {OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ),OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ),OPT_BOOLEAN ('v' ,"verbose" , &opts.verbose,"verbose warnings" ), +/* +* For now, don't fail the kernel build on fatal warnings by default. +* These errors are still fairly common due to the growing matrix of +* supported toolchains and their recent pace of change. +*/ +OPT_BOOLEAN (0 ,"fail-on-warn" , &opts.fail_on_warn,"fail on fatal warnings" ), OPT_END(), };
tools/objtool/check.c +2 -5
@@ -4941,10 +4941,7 @@ int check(struct objtool_file *file) } out: -/* -* For now, don't fail the kernel build on fatal warnings. These -* errors are still fairly common due to the growing matrix of -* supported toolchains and their recent pace of change. -*/ +if (opts.fail_on_warn && warnings) +return 1 ;return 0 ; }
tools/objtool/include/objtool/builtin.h +1 -0
@@ -38,6 +38,7 @@ struct opts {bool sec_address;bool stats;bool verbose; +bool fail_on_warn; };extern struct opts opts;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Josh Poimboeuf
maintainerRe: [PATCH 1/2] objtool: Add --fail-on-warn
Quoted 19 lines · Brendan Jackman
At present objtool only prints to the terminal when observing "fatal warnings". This option lets you have it produce an error instead.
My use case for this is noinstr validation; so far I've never seen any false warnings here, but it quite often detects real bugs. I'd like my build to fail when I have those bugs.
Signed-off-by Brendan Jackman <[email protected]>--- tools/objtool/builtin-check.c | 6 ++++++ tools/objtool/check.c | 7 ++----- tools/objtool/include/objtool/builtin.h | 1 + 3 files changed, 9 insertions(+), 5 deletions(-)tools/objtool/builtin-check.c +0
-0
tools/objtool/builtin-check.c static const struct option check_options[] = { · line 102
Quoted 9 lines
tools/objtool/builtin-check.c +6
-0@@ -94,6 +94,12 @@ static const struct option check_options[] = {OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ),OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ),OPT_BOOLEAN ('v' ,"verbose" , &opts.verbose,"verbose warnings" ), +/* +* For now, don't fail the kernel build on fatal warnings by default. +* These errors are still fairly common due to the growing matrix of +* supported toolchains and their recent pace of change. +*/ + OPT_BOOLEAN(0, "fail-on-warn", &opts.fail_on_warn, "fail on fatal warnings"),
How about "--Werror" to mirror the compiler -Werror option.
Signature · 1 line
Josh
Re: [PATCH 1/2] objtool: Add --fail-on-warn
Quoted 1 line · Josh Poimboeuf
How about "--Werror" to mirror the compiler -Werror option.
Sure, --Werror sounds good to me.
PATCH 2/2 kbuild: Add option to fail build on vmlinux objtool issues
In reply to Brendan JackmanNOINSTR_VALIDATION is pretty helpful for detecting bugs, I would like my build to fail when those bugs arise.
If we wanted to we could enable this for individual warnings, it seems unlikely there's a use-case for that though. So for now I've just added a global setting for vmlinux.
--- lib/Kconfig.debug | 11 +++++++++++ scripts/Makefile.vmlinux_o | 1 + 2 files changed, 12 insertions(+)
lib/Kconfig.debug +11 -0
@@ -563,6 +563,17 @@ config NOINSTR_VALIDATION select OBJTOOL default y +config VMLINUX_OBJTOOL_STRICT + bool "Strict objtool on vmlinux" + default n + # Conditions when we run objtool on vmlinux + depends on NOINSTR_VALIDATION || LTO_CLANG || X86_KERNEL_IBT + help + Fail the build when objtool produces warnings on vmlinux. + + By default, objtool just prints warnings to the terminal without + causing a build failure. This config changes that for vmlinux. + config VMLINUX_MAP bool "Generate vmlinux.map file when linking" depends on EXPERT
scripts/Makefile.vmlinux_o +1 -0
@@ -39,6 +39,7 @@ vmlinux-objtool-args-$(delay-objtool) += $(objtool-args-y) vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr \ $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_SRSO)), --unret) +vmlinux-objtool-args-$(CONFIG_VMLINUX_OBJTOOL_STRICT) += --fail-on-warn objtool-args = $(vmlinux-objtool-args-y) --link
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Josh Poimboeuf
maintainerRe: [PATCH 2/2] kbuild: Add option to fail build on vmlinux objtool issues
Quoted 8 lines · Brendan Jackman
NOINSTR_VALIDATIONis pretty helpful for detecting bugs, I would like my build to fail when those bugs arise.If we wanted to we could enable this for individual warnings, it seems unlikely there's a use-case for that though. So for now I've just added a global setting for vmlinux.
Signed-off-by Brendan Jackman <[email protected]>
Note that *any* objtool warning has a good change of being a major bug in the kernel or compiler which could result in crashing the kernel or breaking the livepatch consistency model. So the option shouldn't be restricted to noinstr builds only. In which case it should be called CONFIG_OBJTOOL_WERROR, analagous to CONFIG_WERROR.
We definitely need this, though it will likely break a lot of robot builds, so it wouldn't be a good idea to merge it until after the holidays. Though once the patches are ready I could throw it on a git branch to see how bad the robot breakage is.
Signature · 1 line
Josh
Re: [PATCH 2/2] kbuild: Add option to fail build on vmlinux objtool issues
Quoted 5 lines · Josh Poimboeuf
Note that *any* objtool warning has a good change of being a major bug in the kernel or compiler which could result in crashing the kernel or breaking the livepatch consistency model. So the option shouldn't be restricted to noinstr builds only. In which case it should be called
CONFIG_OBJTOOL_WERROR, analagous toCONFIG_WERROR.
Sure, sounds good too.
Just to make sure I'm on the same page - are you saying I should add the flag to $(objtool-args-y) instead of $(vmlinux-objtool-args-y)?
Josh Poimboeuf
maintainerRe: [PATCH 2/2] kbuild: Add option to fail build on vmlinux objtool issues
Quoted 11 lines · Brendan Jackman
Quoted 5 lines · Josh Poimboeuf
Note that *any* objtool warning has a good change of being a major bug in the kernel or compiler which could result in crashing the kernel or breaking the livepatch consistency model. So the option shouldn't be restricted to noinstr builds only. In which case it should be called
CONFIG_OBJTOOL_WERROR, analagous toCONFIG_WERROR.Sure, sounds good too.
Just to make sure I'm on the same page - are you saying I should add the flag to $(objtool-args-y) instead of $(vmlinux-objtool-args-y)?
Yeah, that should do it.
Signature · 1 line
Josh