From: Josh Poimboeuf <jpoimboe@kernel.org>
To: live-patching@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>,
Joe Lawrence <joe.lawrence@redhat.com>,
Jiri Kosina <jikos@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Marcos Paulo de Souza <mpdesouza@suse.com>,
Song Liu <song@kernel.org>
Subject: [RFC 12/31] objtool: 'objname' refactoring
Date: Mon, 2 Sep 2024 20:59:55 -0700 [thread overview]
Message-ID: <3058a111d265e2cbcc6732e7d1a48ef4b506c8df.1725334260.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1725334260.git.jpoimboe@kernel.org>
Rename the global 'objname' variable to 'Objname' to avoid local
variable conflicts, and initialize it in elf_open_read() which is a more
natural place for that.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/builtin-check.c | 2 +-
tools/objtool/check.c | 4 ++--
tools/objtool/elf.c | 3 +++
tools/objtool/include/objtool/objtool.h | 2 +-
tools/objtool/include/objtool/warn.h | 8 +++++---
tools/objtool/objtool.c | 17 ++++++++---------
tools/objtool/orc_dump.c | 4 ++--
tools/objtool/weak.c | 2 +-
8 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 5e21cfb7661d..2f16f5ee83ae 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -204,8 +204,8 @@ static bool link_opts_valid(struct objtool_file *file)
int objtool_run(int argc, const char **argv)
{
- const char *objname;
struct objtool_file *file;
+ const char *objname;
int ret;
argc = cmd_parse_options(argc, argv, check_usage);
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 95f5de0c293d..92171ce458ec 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -4621,7 +4621,7 @@ static int disas_funcs(const char *funcs)
"}' 1>&2";
/* fake snprintf() to calculate the size */
- size = snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + 1;
+ size = snprintf(NULL, 0, objdump_str, cross_compile, Objname, funcs) + 1;
if (size <= 0) {
WARN("objdump string size calculation failed");
return -1;
@@ -4630,7 +4630,7 @@ static int disas_funcs(const char *funcs)
cmd = malloc(size);
/* real snprintf() */
- snprintf(cmd, size, objdump_str, cross_compile, objname, funcs);
+ snprintf(cmd, size, objdump_str, cross_compile, Objname, funcs);
ret = system(cmd);
if (ret) {
WARN("disassembly failed: %d", ret);
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 5301fff87bea..12dbcf425321 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -996,6 +996,9 @@ struct elf *elf_open_read(const char *name, int flags)
struct elf *elf;
Elf_Cmd cmd;
+ if (!Objname)
+ Objname = strdup(name);
+
elf_version(EV_CURRENT);
elf = malloc(sizeof(*elf));
diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/include/objtool/objtool.h
index 94a33ee7b363..ae30497e014b 100644
--- a/tools/objtool/include/objtool/objtool.h
+++ b/tools/objtool/include/objtool/objtool.h
@@ -39,7 +39,7 @@ struct objtool_file {
struct pv_state *pv_ops;
};
-struct objtool_file *objtool_open_read(const char *_objname);
+struct objtool_file *objtool_open_read(const char *objname);
void objtool_pv_add(struct objtool_file *file, int idx, struct symbol *func);
diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/objtool/warn.h
index ac04d3fe4dd9..69995f84f91b 100644
--- a/tools/objtool/include/objtool/warn.h
+++ b/tools/objtool/include/objtool/warn.h
@@ -14,7 +14,7 @@
#include <objtool/builtin.h>
#include <objtool/elf.h>
-extern const char *objname;
+extern char *Objname;
static inline char *offstr(struct section *sec, unsigned long offset)
{
@@ -41,10 +41,12 @@ static inline char *offstr(struct section *sec, unsigned long offset)
return str;
}
-#define WARN(format, ...) \
+#define WARN(...) WARN_FILENAME(Objname, ##__VA_ARGS__)
+
+#define WARN_FILENAME(filename, format, ...) \
fprintf(stderr, \
"%s: warning: objtool: " format "\n", \
- objname, ##__VA_ARGS__)
+ filename, ##__VA_ARGS__)
#define WARN_FUNC(format, sec, offset, ...) \
({ \
diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c
index f40febdd6e36..6d2102450b35 100644
--- a/tools/objtool/objtool.c
+++ b/tools/objtool/objtool.c
@@ -18,12 +18,12 @@
bool help;
-const char *objname;
+char *Objname;
static struct objtool_file file;
-static bool objtool_create_backup(const char *_objname)
+static bool objtool_create_backup(const char *objname)
{
- int len = strlen(_objname);
+ int len = strlen(objname);
char *buf, *base, *name = malloc(len+6);
int s, d, l, t;
@@ -32,7 +32,7 @@ static bool objtool_create_backup(const char *_objname)
return false;
}
- strcpy(name, _objname);
+ strcpy(name, objname);
strcpy(name + len, ".orig");
d = open(name, O_CREAT|O_WRONLY|O_TRUNC, 0644);
@@ -41,7 +41,7 @@ static bool objtool_create_backup(const char *_objname)
return false;
}
- s = open(_objname, O_RDONLY);
+ s = open(objname, O_RDONLY);
if (s < 0) {
perror("failed to open orig file");
return false;
@@ -79,16 +79,15 @@ 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 *objname)
{
- if (objname) {
- if (strcmp(objname, _objname)) {
+ if (Objname) {
+ if (strcmp(Objname, objname)) {
WARN("won't handle more than one file at a time");
return NULL;
}
return &file;
}
- objname = _objname;
file.elf = elf_open_read(objname, O_RDWR);
if (!file.elf)
diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
index a62247efb64f..9c0b9d8a34fe 100644
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -10,7 +10,7 @@
#include <objtool/warn.h>
#include <objtool/endianness.h>
-int orc_dump(const char *_objname)
+int orc_dump(const char *objname)
{
int fd, nr_entries, i, *orc_ip = NULL, orc_size = 0;
struct orc_entry *orc = NULL;
@@ -27,7 +27,7 @@ int orc_dump(const char *_objname)
struct elf dummy_elf = {};
- objname = _objname;
+ Objname = strdup(objname);
elf_version(EV_CURRENT);
diff --git a/tools/objtool/weak.c b/tools/objtool/weak.c
index d83f607733b0..b568da3c33e6 100644
--- a/tools/objtool/weak.c
+++ b/tools/objtool/weak.c
@@ -15,7 +15,7 @@
return ENOSYS; \
})
-int __weak orc_dump(const char *_objname)
+int __weak orc_dump(const char *objname)
{
UNSUPPORTED("ORC");
}
--
2.45.2
next prev parent reply other threads:[~2024-09-03 4:00 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-03 3:59 [RFC 00/31] objtool, livepatch: Livepatch module generation Josh Poimboeuf
2024-09-03 3:59 ` [RFC 01/31] x86/alternative: Refactor INT3 call emulation selftest Josh Poimboeuf
2024-09-03 3:59 ` [RFC 02/31] x86/module: Improve relocation error messages Josh Poimboeuf
2024-09-03 3:59 ` [RFC 03/31] x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotation Josh Poimboeuf
2024-09-03 3:59 ` [RFC 04/31] kernel/sys: Don't reference UTS_RELEASE directly Josh Poimboeuf
2024-09-03 3:59 ` [RFC 05/31] x86/compiler: Tweak __UNIQUE_ID naming Josh Poimboeuf
2024-09-03 7:56 ` Peter Zijlstra
2024-09-04 2:01 ` Josh Poimboeuf
2024-09-08 19:43 ` David Laight
2024-09-03 3:59 ` [RFC 06/31] elfnote: Use __UNIQUE_ID() for note symbols Josh Poimboeuf
2024-09-03 3:59 ` [RFC 07/31] kbuild: Remove "kmod" prefix from __KBUILD_MODNAME Josh Poimboeuf
2024-09-03 7:58 ` Peter Zijlstra
2024-09-04 2:11 ` Josh Poimboeuf
2024-09-04 7:53 ` Peter Zijlstra
2024-09-03 3:59 ` [RFC 08/31] objtool: Remove .parainstructions reference Josh Poimboeuf
2024-09-03 3:59 ` [RFC 09/31] objtool: Const string cleanup Josh Poimboeuf
2024-09-03 3:59 ` [RFC 10/31] objtool: Use 'struct elf' in elf macros Josh Poimboeuf
2024-09-03 3:59 ` [RFC 11/31] objtool: Add section/symbol type helpers Josh Poimboeuf
2024-09-03 3:59 ` Josh Poimboeuf [this message]
2024-09-03 3:59 ` [RFC 13/31] objtool: Support references to all symbol types in special sections Josh Poimboeuf
2024-09-03 3:59 ` [RFC 14/31] objtool: Refactor add_jump_destinations() Josh Poimboeuf
2024-09-03 3:59 ` [RFC 15/31] objtool: Interval tree cleanups Josh Poimboeuf
2024-09-03 3:59 ` [RFC 16/31] objtool: Simplify fatal error handling Josh Poimboeuf
2024-09-03 4:00 ` [RFC 17/31] objtool: Open up the elf API Josh Poimboeuf
2024-09-03 4:00 ` [RFC 18/31] objtool: Disallow duplicate prefix symbols Josh Poimboeuf
2024-09-03 4:00 ` [RFC 19/31] objtool: Add elf_create_file() Josh Poimboeuf
2024-09-03 4:00 ` [RFC 20/31] objtool: Add UD1 detection Josh Poimboeuf
2024-09-03 8:17 ` Peter Zijlstra
2024-09-04 2:25 ` Josh Poimboeuf
2024-09-03 4:00 ` [RFC 21/31] objtool: Fix x86 addend calcuation Josh Poimboeuf
2024-09-04 9:24 ` laokz
2024-09-04 16:15 ` Josh Poimboeuf
2024-09-03 4:00 ` [RFC 22/31] objtool: Make find_symbol_containing() less arbitrary Josh Poimboeuf
2024-09-03 4:00 ` [RFC 23/31] objtool: Handle __pa_symbol() relocations Josh Poimboeuf
2024-09-03 4:00 ` [RFC 24/31] objtool: Make STACK_FRAME_NON_STANDARD consistent Josh Poimboeuf
2024-09-03 4:00 ` [RFC 25/31] objtool: Fix interval tree insertion for zero-length symbols Josh Poimboeuf
2024-09-03 4:00 ` [RFC 26/31] objtool: Make interval tree functions "static inline" Josh Poimboeuf
2024-09-03 4:00 ` [RFC 27/31] objtool: Fix weak symbol detection Josh Poimboeuf
2024-09-03 8:26 ` Peter Zijlstra
2024-09-04 3:55 ` Josh Poimboeuf
2024-09-04 7:42 ` Peter Zijlstra
2024-09-04 16:03 ` Josh Poimboeuf
2024-09-03 4:00 ` [RFC 28/31] x86/alternative: Create symbols for special section entries Josh Poimboeuf
2024-09-03 8:29 ` Peter Zijlstra
2024-09-04 4:28 ` Josh Poimboeuf
2024-09-04 8:08 ` Peter Zijlstra
2024-09-04 16:13 ` Josh Poimboeuf
2024-09-04 12:39 ` Borislav Petkov
2024-09-04 16:44 ` Josh Poimboeuf
2024-09-06 10:19 ` Borislav Petkov
2024-09-06 16:53 ` Josh Poimboeuf
2024-09-06 6:51 ` [RFC 28/31] x86/alternative: Create symbols for special section entrie Weinan Liu
2024-09-07 6:28 ` Josh Poimboeuf
2024-09-03 4:00 ` [RFC 29/31] objtool: Calculate function checksums Josh Poimboeuf
2024-09-04 7:54 ` Peter Zijlstra
2024-09-04 16:11 ` Josh Poimboeuf
2024-09-03 4:00 ` [RFC 30/31] livepatch: Enable -ffunction-sections -fdata-sections Josh Poimboeuf
2024-09-03 4:00 ` [RFC 31/31] objtool, livepatch: Livepatch module generation Josh Poimboeuf
2024-09-04 21:38 ` Jeff Johnson
2024-09-05 4:15 ` Josh Poimboeuf
2024-09-12 2:39 ` laokz
2024-09-03 17:32 ` [RFC 00/31] " Song Liu
2024-09-04 4:30 ` Josh Poimboeuf
2024-09-04 5:26 ` Song Liu
2024-09-04 6:37 ` Josh Poimboeuf
2024-09-04 7:09 ` Josh Poimboeuf
2024-09-04 20:23 ` Song Liu
2024-09-04 20:59 ` Josh Poimboeuf
2024-09-04 21:32 ` Song Liu
2024-09-05 4:13 ` Josh Poimboeuf
2024-09-05 7:13 ` Josh Poimboeuf
2024-09-05 21:34 ` Song Liu
2024-09-07 6:46 ` Josh Poimboeuf
2024-09-07 17:43 ` Song Liu
2024-09-07 20:14 ` Josh Poimboeuf
2024-09-08 5:04 ` Song Liu
2024-09-09 21:19 ` Josh Poimboeuf
2024-09-09 21:43 ` Song Liu
2024-09-06 13:56 ` Joe Lawrence
2024-09-06 17:00 ` Josh Poimboeuf
2024-09-06 21:01 ` Joe Lawrence
2024-09-06 22:45 ` Josh Poimboeuf
2024-09-07 1:47 ` Josh Poimboeuf
2024-09-07 14:17 ` Joe Lawrence
2024-09-11 7:39 ` Josh Poimboeuf
2024-09-12 13:44 ` Joe Lawrence
2024-09-13 14:39 ` Joe Lawrence
2024-09-13 23:09 ` Josh Poimboeuf
2024-09-11 13:27 ` Petr Mladek
2024-09-11 16:20 ` Josh Poimboeuf
2024-09-12 16:05 ` Song Liu
2024-09-13 18:16 ` [External] " A K M Fazla Mehrab .
2024-09-17 7:12 ` Petr Mladek
2024-09-23 2:29 ` Chen Zhongjin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3058a111d265e2cbcc6732e7d1a48ef4b506c8df.1725334260.git.jpoimboe@kernel.org \
--to=jpoimboe@kernel.org \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mpdesouza@suse.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=song@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®