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>,
Yafang Shao <laoar.shao@gmail.com>
Subject: [RFC PATCH v2 3/7] objtool/klp: allow special section entry size overrides
Date: Wed, 26 Aug 2026 15:49:56 -0400 [thread overview]
Message-ID: <20260826195000.455905-4-joe.lawrence@redhat.com> (raw)
In-Reply-To: <20260826195000.455905-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.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
tools/objtool/klp-diff.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index f40c128fdd49..4195b3ccff15 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -21,6 +21,8 @@
#include <linux/string.h>
#include <linux/jhash.h>
+#include <arch/special.h>
+
#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
struct elfs {
@@ -1638,6 +1640,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)
{
@@ -1781,6 +1799,27 @@ 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 && sec_size(sec) % entry_size) {
+ ERROR("%s: entry size %u doesn't divide section size %lu",
+ sec->name, entry_size, sec_size(sec));
+ return -1;
+ }
+ }
+
if (!entry_size) {
entry_size = arch_reloc_size(sec->rsec->relocs);
if (sec_size(sec) != entry_size * sec_num_entries(sec->rsec)) {
--
2.55.0
next prev parent reply other threads:[~2026-08-26 19:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 19:49 [RFC PATCH v2 0/7] klp-build: OOT module support Joe Lawrence
2026-08-26 19:49 ` [RFC PATCH v2 1/7] objtool/klp: simplify read_exports file handling Joe Lawrence
2026-08-26 23:31 ` Song Liu
2026-08-26 19:49 ` [RFC PATCH v2 2/7] objtool/klp: add --symvers option to klp diff Joe Lawrence
2026-08-26 23:31 ` Song Liu
2026-08-26 19:49 ` Joe Lawrence [this message]
2026-08-27 19:17 ` [RFC PATCH v2 3/7] objtool/klp: allow special section entry size overrides Josh Poimboeuf
2026-08-26 19:49 ` [RFC PATCH v2 4/7] objtool: add target architecture to usage Joe Lawrence
2026-08-26 19:57 ` sashiko-bot
2026-08-27 19:23 ` Josh Poimboeuf
2026-08-26 19:49 ` [RFC PATCH v2 5/7] livepatch/klp-build: add basic out-of-tree module support Joe Lawrence
2026-08-26 20:00 ` sashiko-bot
2026-08-27 21:21 ` Josh Poimboeuf
2026-08-26 19:49 ` [RFC PATCH v2 6/7] livepatch/klp-build: add pre-built object support for advanced OOT workflows Joe Lawrence
2026-08-26 20:01 ` sashiko-bot
2026-08-27 21:45 ` Josh Poimboeuf
2026-08-26 19:50 ` [RFC PATCH v2 7/7] livepatch/klp-build: add validation for user-supplied OOT objects Joe Lawrence
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=20260826195000.455905-4-joe.lawrence@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=laoar.shao@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox