]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
objtool: Reduce CONFIG_OBJTOOL_WERROR verbosity
authorJosh Poimboeuf <jpoimboe@kernel.org>
Mon, 24 Mar 2025 21:56:00 +0000 (14:56 -0700)
committerIngo Molnar <mingo@kernel.org>
Tue, 25 Mar 2025 08:20:27 +0000 (09:20 +0100)
Remove the following from CONFIG_OBJTOOL_WERROR:

  * backtrace

  * "upgraded warnings to errors" message

  * cmdline args

This makes the default output less cluttered and makes it easier to spot
the actual warnings.  Note the above options are still are available
with --verbose or OBJTOOL_VERBOSE=1.

Also, do the cmdline arg printing on all warnings, regardless of werror.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/d61df69f64b396fa6b2a1335588aad7a34ea9e71.1742852846.git.jpoimboe@kernel.org
scripts/Makefile.lib
tools/objtool/builtin-check.c
tools/objtool/check.c
tools/objtool/include/objtool/builtin.h

index 57620b439a1fd3732c6c3558995e248350ed0b2d..b93597420daffa85ee508ead064637ad316ba22f 100644 (file)
@@ -277,7 +277,7 @@ objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE)              += --static-call
 objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION)         += --uaccess
 objtool-args-$(CONFIG_GCOV_KERNEL)                     += --no-unreachable
 objtool-args-$(CONFIG_PREFIX_SYMBOLS)                  += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
-objtool-args-$(CONFIG_OBJTOOL_WERROR)                  += --Werror --backtrace
+objtool-args-$(CONFIG_OBJTOOL_WERROR)                  += --Werror
 
 objtool-args = $(objtool-args-y)                                       \
        $(if $(delay-objtool), --link)                                  \
index c973a751fb7d1fd1f1793778706aa12c7dcd1b56..2bdff910430e946bc070327cfc9e258356498e14 100644 (file)
 #include <objtool/objtool.h>
 #include <objtool/warn.h>
 
-const char *objname;
+#define ORIG_SUFFIX ".orig"
 
+int orig_argc;
+static char **orig_argv;
+const char *objname;
 struct opts opts;
 
 static const char * const check_usage[] = {
@@ -224,39 +227,73 @@ static int copy_file(const char *src, const char *dst)
        return 0;
 }
 
-static char **save_argv(int argc, const char **argv)
+static void save_argv(int argc, const char **argv)
 {
-       char **orig_argv;
-
        orig_argv = calloc(argc, sizeof(char *));
        if (!orig_argv) {
                WARN_GLIBC("calloc");
-               return NULL;
+               exit(1);
        }
 
        for (int i = 0; i < argc; i++) {
                orig_argv[i] = strdup(argv[i]);
                if (!orig_argv[i]) {
                        WARN_GLIBC("strdup(%s)", orig_argv[i]);
-                       return NULL;
+                       exit(1);
                }
        };
-
-       return orig_argv;
 }
 
-#define ORIG_SUFFIX ".orig"
+void print_args(void)
+{
+       char *backup = NULL;
+
+       if (opts.output || opts.dryrun)
+               goto print;
+
+       /*
+        * Make a backup before kbuild deletes the file so the error
+        * can be recreated without recompiling or relinking.
+        */
+       backup = malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1);
+       if (!backup) {
+               WARN_GLIBC("malloc");
+               goto print;
+       }
+
+       strcpy(backup, objname);
+       strcat(backup, ORIG_SUFFIX);
+       if (copy_file(objname, backup)) {
+               backup = NULL;
+               goto print;
+       }
+
+print:
+       /*
+        * Print the cmdline args to make it easier to recreate.  If '--output'
+        * wasn't used, add it to the printed args with the backup as input.
+        */
+       fprintf(stderr, "%s", orig_argv[0]);
+
+       for (int i = 1; i < orig_argc; i++) {
+               char *arg = orig_argv[i];
+
+               if (backup && !strcmp(arg, objname))
+                       fprintf(stderr, " %s -o %s", backup, objname);
+               else
+                       fprintf(stderr, " %s", arg);
+       }
+
+       fprintf(stderr, "\n");
+}
 
 int objtool_run(int argc, const char **argv)
 {
        struct objtool_file *file;
-       char *backup = NULL;
-       char **orig_argv;
        int ret = 0;
 
-       orig_argv = save_argv(argc, argv);
-       if (!orig_argv)
-               return 1;
+       orig_argc = argc;
+       save_argv(argc, argv);
 
        cmd_parse_options(argc, argv, check_usage);
 
@@ -279,59 +316,19 @@ int objtool_run(int argc, const char **argv)
 
        file = objtool_open_read(objname);
        if (!file)
-               goto err;
+               return 1;
 
        if (!opts.link && has_multiple_files(file->elf)) {
                WARN("Linked object requires --link");
-               goto err;
+               return 1;
        }
 
        ret = check(file);
        if (ret)
-               goto err;
+               return ret;
 
        if (!opts.dryrun && file->elf->changed && elf_write(file->elf))
-               goto err;
-
-       return 0;
-
-err:
-       if (opts.dryrun)
-               goto err_msg;
-
-       if (opts.output) {
-               unlink(opts.output);
-               goto err_msg;
-       }
-
-       /*
-        * Make a backup before kbuild deletes the file so the error
-        * can be recreated without recompiling or relinking.
-        */
-       backup = malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1);
-       if (!backup) {
-               WARN_GLIBC("malloc");
                return 1;
-       }
-
-       strcpy(backup, objname);
-       strcat(backup, ORIG_SUFFIX);
-       if (copy_file(objname, backup))
-               return 1;
-
-err_msg:
-       fprintf(stderr, "%s", orig_argv[0]);
-
-       for (int i = 1; i < argc; i++) {
-               char *arg = orig_argv[i];
 
-               if (backup && !strcmp(arg, objname))
-                       fprintf(stderr, " %s -o %s", backup, objname);
-               else
-                       fprintf(stderr, " %s", arg);
-       }
-
-       fprintf(stderr, "\n");
-
-       return 1;
+       return 0;
 }
index f4e7ee8e8fb5b9b85c61e54abe42381944642a42..ac21f2846ebc06b9e31457fc7e04997f6e8adbb6 100644 (file)
@@ -4732,9 +4732,6 @@ int check(struct objtool_file *file)
 
        free_insns(file);
 
-       if (opts.verbose)
-               disas_warned_funcs(file);
-
        if (opts.stats) {
                printf("nr_insns_visited: %ld\n", nr_insns_visited);
                printf("nr_cfi: %ld\n", nr_cfi);
@@ -4743,19 +4740,25 @@ int check(struct objtool_file *file)
        }
 
 out:
+       if (!ret && !warnings)
+               return 0;
+
+       if (opts.verbose) {
+               if (opts.werror && warnings)
+                       WARN("%d warning(s) upgraded to errors", warnings);
+               print_args();
+               disas_warned_funcs(file);
+       }
+
        /*
         * 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.
+        * Note that even fatal errors don't yet actually return an error
+        * without CONFIG_OBJTOOL_WERROR.  That will be fixed soon-ish.
         */
-       if (opts.werror && (ret || warnings)) {
-               if (warnings)
-                       WARN("%d warning(s) upgraded to errors", warnings);
+       if (opts.werror)
                return 1;
-       }
 
        return 0;
 }
index 0fafd0f7a209f33f54e2ae5325845f4c2d035e23..6b08666fa69d64f6782b57db067c18b8e97cfbe3 100644 (file)
@@ -43,8 +43,10 @@ struct opts {
 
 extern struct opts opts;
 
-extern int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
+int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
 
-extern int objtool_run(int argc, const char **argv);
+int objtool_run(int argc, const char **argv);
+
+void print_args(void);
 
 #endif /* _BUILTIN_H */