Re: [PATCH 12/13] objtool: Create backup on error and print args

From: Brendan Jackman
Date: Mon Mar 17 2025 - 05:55:17 EST


On Fri, Mar 14, 2025 at 12:29:10PM -0700, Josh Poimboeuf wrote:
> Recreating objtool errors can be a manual process. Kbuild removes the
> object, so it has to be compiled or linked again before running objtool.
> Then the objtool args need to be reversed engineered.
>
> Make that all easier by automatically making a backup of the object file
> on error, and print a modified version of the args which can be used to
> recreate.
>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> 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) {
> + perror("malloc");
> + return 1;
> + }
> +
> + strcpy(backup, objname);
> + strcat(backup, ORIG_SUFFIX);
> + if (copy_file(objname, backup))
> + return 1;
> +

I think there should be a comment here like

/*
* Dump a command line with the original filename replaced with the
* backup filename.
*/

With the context from the comment above it's obvious enough _why_
the code would do this, but it still takes a few unnecessary brain
cycles to figure out _that_ it's doing that.

Or alternatively just print "command line to reproduce:" before the
modfified argv or whatever.