Re: [PATCH 39/48] objtool: Replace iterator callbacks with for_each_sym_by_*()

Josh Poimboeuf
2026-04-28T16:14:40Z

On Fri, Apr 24, 2026 at 05:04:08PM -0700, Song Liu wrote:
> On Wed, Apr 22, 2026 at 9:04 PM Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> >
> > Convert the callback-based iterate_sym_by_name() and
> > iterate_sym_by_demangled_name() callers to use new
> > for_each_sym_by[_demangled]_name() macros. This eliminates the callback
> > structs and functions and makes the code more compact and readable.
> >
> > Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> > ---
> > tools/objtool/elf.c | 80 ++++++-----------------------
> > tools/objtool/include/objtool/elf.h | 40 ++++++++++++---
> > tools/objtool/klp-checksum.c | 20 +++-----
> > tools/objtool/klp-diff.c | 42 +++++----------
> > 4 files changed, 73 insertions(+), 109 deletions(-)
>
> Macros are indeed cleaner. But Sashiko has a valid point on this. [1].

Ok, I'll make those an "if (mismatch) {} else":

#define for_each_sym_by_name(elf, _name, sym) \
elf_hash_for_each_possible(elf, symbol_name, sym, name_hash, \
str_hash_demangled(_name)) \
if (strcmp(sym->name, _name)) {} else
--
Josh