On Fri, May 08, 2020 at 11:27:39AM +0200, Arnd Bergmann wrote:

> Right, makes sense. It would be nice though to have a way of intentionally
> turning all objtool warnings into errors. I do my randconfig tests
> with '-Werror'
> at the moment in order to catch all new warnings, but this does not catch
> objtool errors at the moment. For now, this is probably the right thing to do,
> as there are a couple of warnings that I have no patches for, but at some 
> point
> I would prefer to trap immediately when a new warning pops up.

Completely untested, and I'm 100% unsure of the Makefile change, but
something like so, then?

---

 scripts/Makefile.build        | 2 ++
 tools/objtool/builtin-check.c | 3 ++-
 tools/objtool/builtin.h       | 2 +-
 tools/objtool/check.c         | 8 +-------
 4 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 9fcbfac15d1d..c656f114ce30 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -201,6 +201,8 @@ objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc 
generate,check)
 
 objtool_args += $(if $(part-of-module), --module,)
 
+objtool_args += $(if $(findstring $(KBUILD_CFLAGS), "-Werror "), --error,)
+
 ifndef CONFIG_FRAME_POINTER
 objtool_args += --no-fp
 endif
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index be42b716166b..3d10ae8b0b25 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -18,7 +18,7 @@
 #include "builtin.h"
 #include "check.h"
 
-bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, 
validate_dup, vmlinux;
+bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, 
validate_dup, vmlinux, error;
 
 static const char * const check_usage[] = {
        "objtool check [<options>] file.o",
@@ -35,6 +35,7 @@ const struct option check_options[] = {
        OPT_BOOLEAN('s', "stats", &stats, "print statistics"),
        OPT_BOOLEAN('d', "duplicate", &validate_dup, "duplicate validation for 
vmlinux.o"),
        OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),
+       OPT_BOOLEAN('e', "error", &error, "Return error on warnings"),
        OPT_END(),
 };
 
diff --git a/tools/objtool/builtin.h b/tools/objtool/builtin.h
index 85c979caa367..90c43c6c1e35 100644
--- a/tools/objtool/builtin.h
+++ b/tools/objtool/builtin.h
@@ -8,7 +8,7 @@
 #include <subcmd/parse-options.h>
 
 extern const struct option check_options[];
-extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, 
stats, validate_dup, vmlinux;
+extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, 
stats, validate_dup, vmlinux, error;
 
 extern int cmd_check(int argc, const char **argv);
 extern int cmd_orc(int argc, const char **argv);
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 831ffa9e68c4..eed24c584d71 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2793,14 +2793,8 @@ int check(const char *_objname, bool orc)
        }
 
 out:
-       if (ret < 0) {
-               /*
-                *  Fatal error.  The binary is corrupt or otherwise broken in
-                *  some way, or objtool itself is broken.  Fail the kernel
-                *  build.
-                */
+       if (error && ret < 0)
                return ret;
-       }
 
        return 0;
 }

Reply via email to