On Mon, Feb 23, 2026 at 04:07:23PM -0800, Song Liu wrote:
> > > +void iterate_global_symbol_by_demangled_name(const struct elf *elf,
> > > +                                          const char *demangled_name,
> > > +                                          void (*process)(struct symbol 
> > > *sym, void *data),
> > > +                                          void *data)
> > > +{
> > > +     struct symbol *sym;
> > > +
> > > +     elf_hash_for_each_possible(symbol_name, sym, name_hash, 
> > > str_hash(demangled_name)) {
> > > +             if (!strcmp(sym->demangled_name, demangled_name) && 
> > > !is_local_sym(sym))
> > > +                     process(sym, data);
> > > +     }
> > > +}
> > > +
> >
> > I think a saner interface would be something like:
> >
> > struct symbol *find_global_demangled_symbol(const struct elf *elf, const 
> > char *demangled_name)
> > {
> >         struct symbol *ret = NULL;
> >
> >         elf_hash_for_each_possible(symbol_name, sym, name_hash, 
> > str_hash(demangled_name)) {
> >                 if (!is_local_sym(sym) && !strcmp(sym->demangled_name, 
> > demangled_name)) {
> >                         if (ret)
> >                                 return ERR_PTR(-EEXIST);
> >                         ret = sym;
> >                 }
> >         }
> >
> >         return ret;
> > }
> 
> I had something similar to this initially. However, we need to check
> sym->twin, and skip symbols that already have correlations. For
> example, if we have foo.llvm.123 and foo.llvm.456 in the original
> kernel, and foo.llvm.123 and foo.llvm.789 in the patched kernel,
> we will match foo.llvm.456 to foo.llvm.789 without ambiguity.
> Since elf.c doesn't touch sym->twin at all, I think it is cleaner to
> keep this logic in klp-diff.c. If you think it is OK to have elf.c
> handle this, we can do something like:
> 
> struct symbol *find_global_demangled_symbol(const struct elf *elf,
> const char *demangled_name)
> {
>         struct symbol *ret = NULL;
> 
>         elf_hash_for_each_possible(symbol_name, sym, name_hash,
> str_hash(demangled_name)) {
>                 if (!is_local_sym(sym) &&
>                     !strcmp(sym->demangled_name, demangled_name) &&
>                     !sym->twin) {  /* We need to add this */
>                         if (ret)
>                                 return ERR_PTR(-EEXIST);
>                         ret = sym;
>                 }
>         }
> 
>         return ret;
> }
> 
> I personally like v2 patch better. But I wouldn't mind changing to the
> above version in v3.

Ah, I see.  Yeah, the v2 implementation seems ok.

-- 
Josh

Reply via email to