objtool: Add --Werror option
authorJosh Poimboeuf <jpoimboe@kernel.org>
Fri, 14 Mar 2025 19:29:08 +0000 (12:29 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 17 Mar 2025 10:36:01 +0000 (11:36 +0100)
Any objtool warning has the potential of reflecting (or triggering) a
major bug in the kernel or compiler which could result in crashing the
kernel or breaking the livepatch consistency model.

In preparation for failing the build on objtool errors/warnings, add a
new --Werror option.

[ jpoimboe: commit log, comments, error out on fatal errors too ]

Co-developed-by: Brendan Jackman <jackmanb@google.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/e423ea4ec297f510a108aa6c78b52b9fe30fa8c1.1741975349.git.jpoimboe@kernel.org
tools/objtool/builtin-check.c
tools/objtool/check.c
tools/objtool/include/objtool/builtin.h

index 3de3afa0a19c388e039585dcc7499f1cc947b00e..c201650efe49cfeb1919dae4e8a402cab2a3f54c 100644 (file)
@@ -101,6 +101,7 @@ 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"),
+       OPT_BOOLEAN(0,   "Werror", &opts.werror, "return error on warnings"),
 
        OPT_END(),
 };
index 2f64e46fe02d39ae8fe2d1ad1629004300964a0f..48d7bc5b473636fc602b25996152e2caf8c31453 100644 (file)
@@ -4756,9 +4756,18 @@ 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.
+        * CONFIG_OBJTOOL_WERROR upgrades all warnings (and errors) to actual
+        * errors.
+        *
+        * Note that even "fatal" type errors don't actually return an error
+        * without CONFIG_OBJTOOL_WERROR.  That probably needs improved at some
+        * point.
         */
+       if (opts.werror && (ret || warnings)) {
+               if (warnings)
+                       WARN("%d warning(s) upgraded to errors", warnings);
+               return 1;
+       }
+
        return 0;
 }
index 25cfa01758b9853b69d116ecca437954374476e6..b18f114cdaa4335e67fdb9d1e95c253e5b8eb149 100644 (file)
@@ -39,6 +39,7 @@ struct opts {
        bool sec_address;
        bool stats;
        bool verbose;
+       bool werror;
 };
 
 extern struct opts opts;