Re: [PATCH v3 03/12] dump_stack: Add vmlinux build ID to stack traces

From: Stephen Boyd
Date: Thu Apr 08 2021 - 02:20:47 EST


Quoting Petr Mladek (2021-04-07 07:03:19)
> # readelf -Wn vmlinux-5.12.0-rc6-default+
>
> Displaying notes found in: .notes
> Owner Data size Description
> Xen 0x00000006 Unknown note type: (0x00000006) description data: 6c 69 6e 75 78 00
> Xen 0x00000004 Unknown note type: (0x00000007) description data: 32 2e 36 00
> Xen 0x00000008 Unknown note type: (0x00000005) description data: 78 65 6e 2d 33 2e 30 00
> Xen 0x00000008 Unknown note type: (0x00000003) description data: 00 00 00 ffffff80 ffffffff ffffffff ffffffff ffffffff
>

Thanks for the readelf output. That was most helpful to see what's going
on. The buildid code isn't prepared for this it seems. We'll need to
check the note data to see if it starts with "GNU\0" and if it does then
we use it as the buildid. I'm not sure what this Xen note is that has a
type of 3 but I think that's OK, it won't have "GNU" in there so we
should ignore it. Does this patch work?

----8<----
diff --git a/lib/buildid.c b/lib/buildid.c
index 483abf71eeec..f281dbe6fb83 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -25,6 +25,7 @@ static int parse_build_id_buf(unsigned char *build_id,

if (nhdr->n_type == BUILD_ID &&
nhdr->n_namesz == sizeof("GNU") &&
+ !strcmp((char *)(nhdr + 1), "GNU") &&
nhdr->n_descsz > 0 &&
nhdr->n_descsz <= BUILD_ID_SIZE_MAX) {
memcpy(build_id,