Re: [PATCH v2 1/4] perf symbol: Fix symbol loading from libbfd

From: Ian Rogers

Date: Mon Oct 12 2026 - 17:53:17 EST


On Sun, Oct 11, 2026 at 10:30 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> The dso__load() should return a positive number (number of symbols
> loaded) when it succeded to load symbols. But dso__load_bfd_symbols()
> only returns 0 and it's hard to check if it actually loaded symbols or
> not. Let's return the value of dso__has_symbol() and check it in
> dso__load() so that it can return 1 for success.
>
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Closes: https://lore.kernel.org/r/sashiko-outbox-162540@xxxxxxxxxx
> Fixes: eac9a4342e5447cad ("perf symbols: Try reading the symbol table with libbfd")
> Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks,
Ian

> ---
> tools/perf/tests/pe-file-parsing.c | 2 +-
> tools/perf/util/libbfd.c | 2 +-
> tools/perf/util/symbol.c | 4 ++--
> 3 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/tests/pe-file-parsing.c b/tools/perf/tests/pe-file-parsing.c
> index 30c7da79e109b480..3979f38bf127c218 100644
> --- a/tools/perf/tests/pe-file-parsing.c
> +++ b/tools/perf/tests/pe-file-parsing.c
> @@ -59,7 +59,7 @@ static int run_dir(const char *d)
> TEST_ASSERT_VAL("Failed to get dso", dso);
>
> ret = dso__load_bfd_symbols(dso, debugfile);
> - TEST_ASSERT_VAL("Failed to load symbols", ret == 0);
> + TEST_ASSERT_VAL("Failed to load symbols", ret > 0);
>
> dso__sort_by_name(dso);
> sym = dso__find_symbol_by_name(dso, "main", &idx);
> diff --git a/tools/perf/util/libbfd.c b/tools/perf/util/libbfd.c
> index a907d7c1ac948808..a4dcb406c79e9cee 100644
> --- a/tools/perf/util/libbfd.c
> +++ b/tools/perf/util/libbfd.c
> @@ -463,7 +463,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)
> symbols__fixup_duplicate(dso__symbols(dso));
> dso__set_adjust_symbols(dso, true);
>
> - err = 0;
> + err = dso__has_symbols(dso);
> out_free:
> free(symbols);
> out_close:
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 5d98888d068c741a..a394e742f9b18812 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -1930,8 +1930,8 @@ int dso__load(struct dso *dso, struct map *map)
> if (nsexit)
> nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
>
> - if (bfdrc == 0) {
> - ret = 0;
> + if (bfdrc > 0) {
> + ret = 1;
> break;
> }
>
> --
> 2.55.0
>