buildid: stash away kernels build ID on init
[linux-block.git] / lib / buildid.c
index 6aea1c4e5e853d9e697d4c3452f546c7d49a2442..1103ed46214f0cbda898b90b447435fdd559938f 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <linux/buildid.h>
+#include <linux/cache.h>
 #include <linux/elf.h>
 #include <linux/kernel.h>
 #include <linux/pagemap.h>
@@ -172,3 +173,17 @@ int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size)
 {
        return parse_build_id_buf(build_id, NULL, buf, buf_size);
 }
+
+unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init;
+
+/**
+ * init_vmlinux_build_id - Compute and stash the running kernel's build ID
+ */
+void __init init_vmlinux_build_id(void)
+{
+       extern const void __start_notes __weak;
+       extern const void __stop_notes __weak;
+       unsigned int size = &__stop_notes - &__start_notes;
+
+       build_id_parse_buf(&__start_notes, vmlinux_build_id, size);
+}