]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool: Resurrect --backup option
authorJosh Poimboeuf <jpoimboe@kernel.org>
Wed, 17 Sep 2025 16:03:43 +0000 (09:03 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 14 Oct 2025 21:46:48 +0000 (14:46 -0700)
The --backup option was removed with the following commit:

  aa8b3e64fd39 ("objtool: Create backup on error and print args")

... which tied the backup functionality to --verbose, and only for
warnings/errors.

It's a bit inelegant and out of scope to tie that to --verbose.

Bring back the old --backup option, but with the new behavior: only on
warnings/errors, and print the args to make it easier to recreate.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
tools/objtool/builtin-check.c
tools/objtool/check.c
tools/objtool/include/objtool/builtin.h

index 2aa28af8fb09ee5fd949c1a72e5fbd6f93cc913d..2abac92cdaeff27c1ae1af5ae14c53f7cebd6ae7 100644 (file)
@@ -92,6 +92,7 @@ static const struct option check_options[] = {
 
        OPT_GROUP("Options:"),
        OPT_BOOLEAN(0,   "backtrace", &opts.backtrace, "unwind on error"),
+       OPT_BOOLEAN(0,   "backup", &opts.backup, "create backup (.orig) file on warning/error"),
        OPT_BOOLEAN(0,   "dry-run", &opts.dryrun, "don't write modifications"),
        OPT_BOOLEAN(0,   "link", &opts.link, "object is a linked object"),
        OPT_BOOLEAN(0,   "module", &opts.module, "object is part of a kernel module"),
@@ -246,12 +247,9 @@ static void save_argv(int argc, const char **argv)
        }
 }
 
-void print_args(void)
+int make_backup(void)
 {
-       char *backup = NULL;
-
-       if (opts.output || opts.dryrun)
-               goto print;
+       char *backup;
 
        /*
         * Make a backup before kbuild deletes the file so the error
@@ -260,33 +258,32 @@ void print_args(void)
        backup = malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1);
        if (!backup) {
                ERROR_GLIBC("malloc");
-               goto print;
+               return 1;
        }
 
        strcpy(backup, objname);
        strcat(backup, ORIG_SUFFIX);
-       if (copy_file(objname, backup)) {
-               backup = NULL;
-               goto print;
-       }
+       if (copy_file(objname, backup))
+               return 1;
 
-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.
+        * Print the cmdline args to make it easier to recreate.
         */
+
        fprintf(stderr, "%s", orig_argv[0]);
 
        for (int i = 1; i < orig_argc; i++) {
                char *arg = orig_argv[i];
 
-               if (backup && !strcmp(arg, objname))
+               /* Modify the printed args to use the backup */
+               if (!opts.output && !strcmp(arg, objname))
                        fprintf(stderr, " %s -o %s", backup, objname);
                else
                        fprintf(stderr, " %s", arg);
        }
 
        fprintf(stderr, "\n");
+       return 0;
 }
 
 int objtool_run(int argc, const char **argv)
index e567a625b9e0940b440914eb7a59cecb41669c40..b63f7c4182ef4c6180c0879b3bbe382e70134be4 100644 (file)
@@ -4824,9 +4824,11 @@ out:
        if (opts.verbose) {
                if (opts.werror && warnings)
                        WARN("%d warning(s) upgraded to errors", warnings);
-               print_args();
                disas_warned_funcs(file);
        }
 
+       if (opts.backup && make_backup())
+               return 1;
+
        return ret;
 }
index ab22673862e1b108e2922e648bb23757ad6afbb2..7d559a2c13b7b3ade34dae62c0063df912999740 100644 (file)
@@ -30,6 +30,7 @@ struct opts {
 
        /* options: */
        bool backtrace;
+       bool backup;
        bool dryrun;
        bool link;
        bool mnop;
@@ -48,6 +49,6 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
 
 int objtool_run(int argc, const char **argv);
 
-void print_args(void);
+int make_backup(void);
 
 #endif /* _BUILTIN_H */