summaryrefslogtreecommitdiff
path: root/tools/objtool/objtool.c
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@kernel.org>2025-03-14 12:29:07 -0700
committerPeter Zijlstra <peterz@infradead.org>2025-03-17 11:36:01 +0100
commit5a406031d0719d146d2033ee4270310b1ca9a1e3 (patch)
tree4df3c743470970860b84a076187c45bbf9357697 /tools/objtool/objtool.c
parentfdf5ff2934f4c5c6b483c906fea6e0288df36da2 (diff)
objtool: Add --output option
Add option to allow writing the changed binary to a separate file rather than changing it in place. Libelf makes this suprisingly hard, so take the easy way out and just copy the file before editing it. Also steal the -o short option from --orc. Nobody will notice ;-) Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/0da308d42d82b3bbed16a31a72d6bde52afcd6bd.1741975349.git.jpoimboe@kernel.org
Diffstat (limited to 'tools/objtool/objtool.c')
-rw-r--r--tools/objtool/objtool.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c
index f40febdd6e36..53cd881c6b95 100644
--- a/tools/objtool/objtool.c
+++ b/tools/objtool/objtool.c
@@ -18,7 +18,6 @@
bool help;
-const char *objname;
static struct objtool_file file;
static bool objtool_create_backup(const char *_objname)
@@ -79,18 +78,14 @@ static bool objtool_create_backup(const char *_objname)
return true;
}
-struct objtool_file *objtool_open_read(const char *_objname)
+struct objtool_file *objtool_open_read(const char *filename)
{
- if (objname) {
- if (strcmp(objname, _objname)) {
- WARN("won't handle more than one file at a time");
- return NULL;
- }
- return &file;
+ if (file.elf) {
+ WARN("won't handle more than one file at a time");
+ return NULL;
}
- objname = _objname;
- file.elf = elf_open_read(objname, O_RDWR);
+ file.elf = elf_open_read(filename, O_RDWR);
if (!file.elf)
return NULL;