Re: [PATCH 1/2] objtool/klp: Disambiguate global symbols colliding with local symbols

From: Josh Poimboeuf

Date: Sat Nov 21 2026 - 20:20:45 EST


On Tue, Nov 17, 2026 at 12:08:31AM +0000, Wilson Felipe Pereira wrote:
> klp_find_sympos() returns 0 for any non-STB_LOCAL symbol, symid_needed()
> skips non-local symbols when emitting .klp.symid entries for vmlinux.o,
> and clone_reloc_klp() hardcodes sympos = 0 when a relocation targets a
> restricted or module export.
>
> However, a global symbol in one translation unit can share its name with a
> static (STB_LOCAL) symbol in another translation unit (for example,
> cgroup_storage_lookup in kernel/bpf/local_storage.c vs
> kernel/bpf/bpf_cgrp_storage.c). At runtime, both
> kallsyms_on_each_match_symbol() and module_kallsyms_on_each_symbol() count
> local and global symbols together, so emitting sympos 0 for the global
> symbol fails module load in klp_find_object_symbol() with 'unresolvable
> ambiguity for symbol'.
>
> Allow defined non-local symbols to receive .klp.symid entries when
> duplicate names exist in vmlinux.o, compute sympos for defined non-local
> symbols in klp_find_sympos() (returning 0 when unique and skipping
> undefined and non-alloc symbols), and resolve sympos via klp_find_sympos()
> in clone_reloc_klp() when the exported target is defined in the patched
> object.
>
> Signed-off-by: Wilson Felipe Pereira <wfelipe@xxxxxxxxxx>
> ---
> tools/objtool/klp-diff.c | 11 +++++++++++
> tools/objtool/klp-symid.c | 2 +-
> tools/objtool/klp-sympos.c | 9 ++++++---
> 3 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
> index 34da55e45609..37ad315d00af 100644
> --- a/tools/objtool/klp-diff.c
> +++ b/tools/objtool/klp-diff.c
> @@ -1404,9 +1404,20 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
> */
>
> if (export) {
> + const char *modname = find_modname(e);
> +
> + if (!modname)
> + return -1;
> +
> sym_modname = export->mod;
> sym_orig_name = export->sym;
> sympos = 0;
> + if (!strcmp(export->mod, modname) &&
> + patched_sym->twin && !is_undef_sym(patched_sym->twin)) {
> + sympos = klp_find_sympos(e->orig, patched_sym->twin);
> + if (sympos == ULONG_MAX)
> + return -1;
> + }
> } else {
> sym_modname = find_modname(e);
> if (!sym_modname)

This could be simplified a bit?

if (export) {
sym_modname = export->mod;
sym_orig_name = export->sym;
} else {
sym_modname = find_modname(e);
if (!sym_modname)
return -1;

sym_orig_name = patched_sym->twin->name;
}

sympos = 0;
if (patched_sym->twin) {
sympos = klp_find_sympos(e->orig, patched_sym->twin);
if (sympos == ULONG_MAX)
return -1;
}

--
Josh