From: Joe Lawrence <joe.lawrence@redhat.com>
To: live-patching@vger.kernel.org
Cc: Ben Procknow <bprockno@redhat.com>,
Jiri Kosina <jikos@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>,
Song Liu <song@kernel.org>
Subject: [PATCH 1/1] objtool/klp: fix symbol ordering for data symbols
Date: Fri, 10 Jul 2026 11:30:42 -0400 [thread overview]
Message-ID: <20260710153042.3156788-2-joe.lawrence@redhat.com> (raw)
In-Reply-To: <20260710153042.3156788-1-joe.lawrence@redhat.com>
The find_sympos() function calculates a sympos (symbol position) used by
livepatch to disambiguate duplicate symbol names. At runtime, kallsyms
iterates symbols sorted by address, so sympos must reflect that order.
For function symbols, there's already a workaround that counts
.text.unlikely symbols before other .text symbols, matching the linker
script's section ordering.
Data symbols suffer the same problem: the linker script places sections
in this order:
.data..ro_after_init (lowest address)
.data* sections
.bss* sections (highest address)
However, vmlinux.o's symbol table is ordered by object file link order
(kernel/ before fs/, etc.), which can differ from the final address
order.
Extend the existing section ordering workaround to handle data symbols,
counting .data..ro_after_init first, then other .data, then .bss.
Reported-by: Ben Procknow <bprockno@redhat.com>
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
tools/objtool/klp-diff.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index c2c4e4968bc2..1c6f9f6d7565 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -509,6 +509,46 @@ static unsigned long find_sympos(struct elf *elf, struct symbol *sym)
has_dup = true;
}
}
+ } else if (vmlinux && is_object_sym(sym)) {
+ /*
+ * HACK: Similarly, data symbol ordering can differ between
+ * vmlinux.o and vmlinux. The linker script places sections:
+ * .data..ro_after_init (lowest address)
+ * .data* sections
+ * .bss* sections (highest address)
+ * Count in that order.
+ */
+ for_each_sym(elf, s) {
+ if (strstarts(s->sec->name, ".data..ro_after_init") &&
+ !strcmp(s->name, sym->name)) {
+ nr_matches++;
+ if (s == sym)
+ sympos = nr_matches;
+ else
+ has_dup = true;
+ }
+ }
+ for_each_sym(elf, s) {
+ if (!strstarts(s->sec->name, ".data..ro_after_init") &&
+ !strstarts(s->sec->name, ".bss") &&
+ !strcmp(s->name, sym->name)) {
+ nr_matches++;
+ if (s == sym)
+ sympos = nr_matches;
+ else
+ has_dup = true;
+ }
+ }
+ for_each_sym(elf, s) {
+ if (strstarts(s->sec->name, ".bss") &&
+ !strcmp(s->name, sym->name)) {
+ nr_matches++;
+ if (s == sym)
+ sympos = nr_matches;
+ else
+ has_dup = true;
+ }
+ }
} else {
for_each_sym(elf, s) {
if (!strcmp(s->name, sym->name)) {
--
2.54.0
next prev parent reply other threads:[~2026-07-10 15:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 15:30 [PATCH 0/1] Mitigate klp-build data sympos bug Joe Lawrence
2026-07-10 15:30 ` Joe Lawrence [this message]
2026-07-10 15:40 ` [PATCH 1/1] objtool/klp: fix symbol ordering for data symbols sashiko-bot
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=20260710153042.3156788-2-joe.lawrence@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=bprockno@redhat.com \
--cc=jikos@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox