Re: [PATCH v2 7/8] perf dso: Move build_id to dso_id

Ian Rogers
2025-04-28T20:22:13Z

On Mon, Apr 28, 2025 at 1:04 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Fri, Apr 25, 2025 at 11:46:40AM -0700, Ian Rogers wrote:
> > On Fri, Apr 25, 2025 at 10:15 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > > On Thu, Apr 24, 2025 at 12:58:30PM -0700, Ian Rogers wrote:
> [SNIP]
> > > > @@ -1665,18 +1675,20 @@ bool dso__build_id_equal(const struct dso *dso, struct build_id *bid)
> > > > void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
> > > > {
> > > > char path[PATH_MAX];
> > > > + struct build_id bid;
> > > >
> > > > if (machine__is_default_guest(machine))
> > > > return;
> > > > sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
> > > > - if (sysfs__read_build_id(path, dso__bid(dso)) == 0)
> > > > - dso__set_has_build_id(dso);
> > > > + sysfs__read_build_id(path, &bid);
> > > > + dso__set_build_id(dso, &bid);
> > >
> > > Why not check the return value anymore?
> >
> > Checking the return value was a mistake. For example if we have
> > libc.so with a build ID and then it is replaced with a libc.so without
> > a build ID then build ID wouldn't be updated previously as reading the
> > build ID had failed - no value found.
>
> I'm not sure if it updates the dso as a whole. This functions is to get
> build-ID of the kernel and it seems we can skip this if it already has a
> build-ID. But if sysfs__read_build_id() failed, it may have a garbage.
>
> Do I miss something?

I think there is a missing initialization, I'll add it in v2.

Thanks,
Ian

> Thanks,
> Namhyung
>
> > >
> > > > }
> > > >
> > > > int dso__kernel_module_get_build_id(struct dso *dso,
> > > > const char *root_dir)
> > > > {
> > > > char filename[PATH_MAX];
> > > > + struct build_id bid;
> > > > /*
> > > > * kernel module short names are of the form "[module]" and
> > > > * we need just "module" here.
> > > > @@ -1687,9 +1699,8 @@ int dso__kernel_module_get_build_id(struct dso *dso,
> > > > "%s/sys/module/%.*s/notes/.note.gnu.build-id",
> > > > root_dir, (int)strlen(name) - 1, name);
> > > >
> > > > - if (sysfs__read_build_id(filename, dso__bid(dso)) == 0)
> > > > - dso__set_has_build_id(dso);
> > > > -
> > > > + sysfs__read_build_id(filename, &bid);
> > > > + dso__set_build_id(dso, &bid);
> > > > return 0;
> > > > }