Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

objtool: Parse options from OBJTOOL_ARGS

Teach objtool to parse options from the OBJTOOL_ARGS environment
variable.

This enables things like:

$ OBJTOOL_ARGS="--backup" make O=defconfig-build/ kernel/ponies.o

to obtain both defconfig-build/kernel/ponies.o{,.orig} and easily
inspect what objtool actually did.

Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/20210226110004.252553847@infradead.org

authored by

Peter Zijlstra and committed by
Ingo Molnar
900b4df3 a2f605f9

+25
+25
tools/objtool/builtin-check.c
··· 15 15 16 16 #include <subcmd/parse-options.h> 17 17 #include <string.h> 18 + #include <stdlib.h> 18 19 #include <objtool/builtin.h> 19 20 #include <objtool/objtool.h> 20 21 ··· 24 23 25 24 static const char * const check_usage[] = { 26 25 "objtool check [<options>] file.o", 26 + NULL, 27 + }; 28 + 29 + static const char * const env_usage[] = { 30 + "OBJTOOL_ARGS=\"<options>\"", 27 31 NULL, 28 32 }; 29 33 ··· 50 44 51 45 int cmd_parse_options(int argc, const char **argv, const char * const usage[]) 52 46 { 47 + const char *envv[16] = { }; 48 + char *env; 49 + int envc; 50 + 51 + env = getenv("OBJTOOL_ARGS"); 52 + if (env) { 53 + envv[0] = "OBJTOOL_ARGS"; 54 + for (envc = 1; envc < ARRAY_SIZE(envv); ) { 55 + envv[envc++] = env; 56 + env = strchr(env, ' '); 57 + if (!env) 58 + break; 59 + *env = '\0'; 60 + env++; 61 + } 62 + 63 + parse_options(envc, envv, check_options, env_usage, 0); 64 + } 65 + 53 66 argc = parse_options(argc, argv, check_options, usage, 0); 54 67 if (argc != 1) 55 68 usage_with_options(usage, check_options);