Skip to content

Commit d39f82a

Browse files
jpoimboeingomolnar
authored andcommitted
objtool: Reduce CONFIG_OBJTOOL_WERROR verbosity
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
1 parent c5995ab commit d39f82a

4 files changed

Lines changed: 73 additions & 71 deletions

File tree

scripts/Makefile.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) += --static-call
277277
objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess
278278
objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable
279279
objtool-args-$(CONFIG_PREFIX_SYMBOLS) += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
280-
objtool-args-$(CONFIG_OBJTOOL_WERROR) += --Werror --backtrace
280+
objtool-args-$(CONFIG_OBJTOOL_WERROR) += --Werror
281281

282282
objtool-args = $(objtool-args-y) \
283283
$(if $(delay-objtool), --link) \

tools/objtool/builtin-check.c

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
#include <objtool/objtool.h>
1616
#include <objtool/warn.h>
1717

18-
const char *objname;
18+
#define ORIG_SUFFIX ".orig"
1919

20+
int orig_argc;
21+
static char **orig_argv;
22+
const char *objname;
2023
struct opts opts;
2124

2225
static const char * const check_usage[] = {
@@ -224,39 +227,73 @@ static int copy_file(const char *src, const char *dst)
224227
return 0;
225228
}
226229

227-
static char **save_argv(int argc, const char **argv)
230+
static void save_argv(int argc, const char **argv)
228231
{
229-
char **orig_argv;
230-
231232
orig_argv = calloc(argc, sizeof(char *));
232233
if (!orig_argv) {
233234
WARN_GLIBC("calloc");
234-
return NULL;
235+
exit(1);
235236
}
236237

237238
for (int i = 0; i < argc; i++) {
238239
orig_argv[i] = strdup(argv[i]);
239240
if (!orig_argv[i]) {
240241
WARN_GLIBC("strdup(%s)", orig_argv[i]);
241-
return NULL;
242+
exit(1);
242243
}
243244
};
244-
245-
return orig_argv;
246245
}
247246

248-
#define ORIG_SUFFIX ".orig"
247+
void print_args(void)
248+
{
249+
char *backup = NULL;
250+
251+
if (opts.output || opts.dryrun)
252+
goto print;
253+
254+
/*
255+
* Make a backup before kbuild deletes the file so the error
256+
* can be recreated without recompiling or relinking.
257+
*/
258+
backup = malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1);
259+
if (!backup) {
260+
WARN_GLIBC("malloc");
261+
goto print;
262+
}
263+
264+
strcpy(backup, objname);
265+
strcat(backup, ORIG_SUFFIX);
266+
if (copy_file(objname, backup)) {
267+
backup = NULL;
268+
goto print;
269+
}
270+
271+
print:
272+
/*
273+
* Print the cmdline args to make it easier to recreate. If '--output'
274+
* wasn't used, add it to the printed args with the backup as input.
275+
*/
276+
fprintf(stderr, "%s", orig_argv[0]);
277+
278+
for (int i = 1; i < orig_argc; i++) {
279+
char *arg = orig_argv[i];
280+
281+
if (backup && !strcmp(arg, objname))
282+
fprintf(stderr, " %s -o %s", backup, objname);
283+
else
284+
fprintf(stderr, " %s", arg);
285+
}
286+
287+
fprintf(stderr, "\n");
288+
}
249289

250290
int objtool_run(int argc, const char **argv)
251291
{
252292
struct objtool_file *file;
253-
char *backup = NULL;
254-
char **orig_argv;
255293
int ret = 0;
256294

257-
orig_argv = save_argv(argc, argv);
258-
if (!orig_argv)
259-
return 1;
295+
orig_argc = argc;
296+
save_argv(argc, argv);
260297

261298
cmd_parse_options(argc, argv, check_usage);
262299

@@ -279,59 +316,19 @@ int objtool_run(int argc, const char **argv)
279316

280317
file = objtool_open_read(objname);
281318
if (!file)
282-
goto err;
319+
return 1;
283320

284321
if (!opts.link && has_multiple_files(file->elf)) {
285322
WARN("Linked object requires --link");
286-
goto err;
323+
return 1;
287324
}
288325

289326
ret = check(file);
290327
if (ret)
291-
goto err;
328+
return ret;
292329

293330
if (!opts.dryrun && file->elf->changed && elf_write(file->elf))
294-
goto err;
295-
296-
return 0;
297-
298-
err:
299-
if (opts.dryrun)
300-
goto err_msg;
301-
302-
if (opts.output) {
303-
unlink(opts.output);
304-
goto err_msg;
305-
}
306-
307-
/*
308-
* Make a backup before kbuild deletes the file so the error
309-
* can be recreated without recompiling or relinking.
310-
*/
311-
backup = malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1);
312-
if (!backup) {
313-
WARN_GLIBC("malloc");
314331
return 1;
315-
}
316-
317-
strcpy(backup, objname);
318-
strcat(backup, ORIG_SUFFIX);
319-
if (copy_file(objname, backup))
320-
return 1;
321-
322-
err_msg:
323-
fprintf(stderr, "%s", orig_argv[0]);
324-
325-
for (int i = 1; i < argc; i++) {
326-
char *arg = orig_argv[i];
327332

328-
if (backup && !strcmp(arg, objname))
329-
fprintf(stderr, " %s -o %s", backup, objname);
330-
else
331-
fprintf(stderr, " %s", arg);
332-
}
333-
334-
fprintf(stderr, "\n");
335-
336-
return 1;
333+
return 0;
337334
}

tools/objtool/check.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4732,9 +4732,6 @@ int check(struct objtool_file *file)
47324732

47334733
free_insns(file);
47344734

4735-
if (opts.verbose)
4736-
disas_warned_funcs(file);
4737-
47384735
if (opts.stats) {
47394736
printf("nr_insns_visited: %ld\n", nr_insns_visited);
47404737
printf("nr_cfi: %ld\n", nr_cfi);
@@ -4743,19 +4740,25 @@ int check(struct objtool_file *file)
47434740
}
47444741

47454742
out:
4743+
if (!ret && !warnings)
4744+
return 0;
4745+
4746+
if (opts.verbose) {
4747+
if (opts.werror && warnings)
4748+
WARN("%d warning(s) upgraded to errors", warnings);
4749+
print_args();
4750+
disas_warned_funcs(file);
4751+
}
4752+
47464753
/*
47474754
* CONFIG_OBJTOOL_WERROR upgrades all warnings (and errors) to actual
47484755
* errors.
47494756
*
4750-
* Note that even "fatal" type errors don't actually return an error
4751-
* without CONFIG_OBJTOOL_WERROR. That probably needs improved at some
4752-
* point.
4757+
* Note that even fatal errors don't yet actually return an error
4758+
* without CONFIG_OBJTOOL_WERROR. That will be fixed soon-ish.
47534759
*/
4754-
if (opts.werror && (ret || warnings)) {
4755-
if (warnings)
4756-
WARN("%d warning(s) upgraded to errors", warnings);
4760+
if (opts.werror)
47574761
return 1;
4758-
}
47594762

47604763
return 0;
47614764
}

tools/objtool/include/objtool/builtin.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ struct opts {
4343

4444
extern struct opts opts;
4545

46-
extern int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
46+
int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
4747

48-
extern int objtool_run(int argc, const char **argv);
48+
int objtool_run(int argc, const char **argv);
49+
50+
void print_args(void);
4951

5052
#endif /* _BUILTIN_H */

0 commit comments

Comments
 (0)