From: Joe Lawrence <joe.lawrence@redhat.com>
To: live-patching@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@kernel.org>, Song Liu <song@kernel.org>,
Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>
Subject: [RFC 2/4] objtool/klp: allow special section entry size overrides
Date: Tue, 12 May 2026 18:11:00 -0400 [thread overview]
Message-ID: <20260512221102.2720763-3-joe.lawrence@redhat.com> (raw)
In-Reply-To: <20260512221102.2720763-1-joe.lawrence@redhat.com>
Special section entry sizes (ALT_ENTRY_SIZE, JUMP_ENTRY_SIZE,
EX_ENTRY_SIZE) are built into objtool from arch-specific headers.
When processing cached unit test objects that were built from a
different kernel version, these compiled-in sizes may not match the
objects' actual entry sizes, causing create_fake_symbols() to
incorrectly parse special sections.
Allow the user to override the compiled-in defaults via environment
variables of the same name. When unset, behavior is unchanged. This
will enable a klp-diff unit test runner to pass the correct entry sizes
from test metadata.
Assisted-by: Cursor:claude-4.6-opus
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
tools/objtool/klp-diff.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index bd8d64f2f3f6..ebe4a2a087ca 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1749,6 +1749,22 @@ static int clone_sym_relocs(struct elfs *e, struct symbol *patched_sym)
}
+static unsigned int entry_size_from_env(const char *name, unsigned int def)
+{
+ const char *str = getenv(name);
+ char *end;
+ unsigned long val;
+
+ if (!str)
+ return def;
+
+ val = strtoul(str, &end, 10);
+ if (*end || !val)
+ return def;
+
+ return val;
+}
+
static int create_fake_symbol(struct elf *elf, struct section *sec,
unsigned long offset, size_t size)
{
@@ -1871,6 +1887,21 @@ static int create_fake_symbols(struct elf *elf)
}
entry_size = sec->sh.sh_entsize;
+
+ /*
+ * Some special sections have multiple relocs per entry,
+ * so the reloc-based heuristic below doesn't work. Use
+ * the arch-defined entry sizes for known special sections.
+ */
+ if (!entry_size) {
+ if (!strcmp(sec->name, ".altinstructions"))
+ entry_size = entry_size_from_env("ALT_ENTRY_SIZE", ALT_ENTRY_SIZE);
+ else if (!strcmp(sec->name, "__jump_table"))
+ entry_size = entry_size_from_env("JUMP_ENTRY_SIZE", JUMP_ENTRY_SIZE);
+ else if (!strcmp(sec->name, "__ex_table"))
+ entry_size = entry_size_from_env("EX_ENTRY_SIZE", EX_ENTRY_SIZE);
+ }
+
if (!entry_size) {
entry_size = arch_reloc_size(sec->rsec->relocs);
if (sec_size(sec) != entry_size * sec_num_entries(sec->rsec)) {
--
2.53.0
next prev parent reply other threads:[~2026-05-12 22:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 22:10 [RFC 0/4] klp-build: simple OOT module support Joe Lawrence
2026-05-12 22:10 ` [RFC 1/4] objtool/klp: add --symvers option to klp diff Joe Lawrence
2026-05-14 20:47 ` sashiko-bot
2026-05-12 22:11 ` Joe Lawrence [this message]
2026-05-14 20:58 ` [RFC 2/4] objtool/klp: allow special section entry size overrides sashiko-bot
2026-05-12 22:11 ` [RFC 3/4] objtool/klp: add --arch option to display target architecture Joe Lawrence
2026-05-14 21:10 ` sashiko-bot
2026-05-12 22:11 ` [RFC 4/4] livepatch/klp-build: add basic out-of-tree module patching support Joe Lawrence
2026-05-14 21:20 ` sashiko-bot
2026-05-12 23:30 ` [RFC 0/4] klp-build: simple OOT module support Song Liu
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=20260512221102.2720763-3-joe.lawrence@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=song@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.