|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 1/2] xen/build-id: Introduce is_gnu_build_id()
Broken out of the subsequent change for legibility reasons. It will be used
to replace xen_build_id_check().
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
CC: Anthony PERARD <anthony.perard@xxxxxxxxxx>
CC: Michal Orzel <michal.orzel@xxxxxxx>
CC: Jan Beulich <jbeulich@xxxxxxxx>
CC: Julien Grall <julien@xxxxxxx>
CC: Roger Pau Monné <roger@xxxxxxxxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
---
xen/common/version.c | 33 +++++++++++++++++++++++++++++++++
xen/include/xen/elfstructs.h | 2 ++
xen/include/xen/version.h | 2 ++
3 files changed, 37 insertions(+)
diff --git a/xen/common/version.c b/xen/common/version.c
index 80e7a9b981cf..7eb8a0221d82 100644
--- a/xen/common/version.c
+++ b/xen/common/version.c
@@ -114,6 +114,37 @@ void print_version(void)
/* Defined in linker script. */
extern const Elf_Note __note_gnu_build_id_start[], __note_gnu_build_id_end[];
+/*
+ * Check whether @n is a GNU Build ID note.
+ *
+ * We check that:
+ * - type is NT_GNU_BUILD_ID
+ * - name is GNU\0
+ * - desc is non-empty and exactly covering the rest of the buffer
+ *
+ * If this returns true, the contents starts at n + NT_GNU_HDR_SIZE.
+ */
+bool is_gnu_build_id(const Elf_Note *n, unsigned int len)
+{
+ const char *name;
+
+ if ( len <= NT_GNU_HDR_SIZE )
+ return false;
+
+ if ( n->type != NT_GNU_BUILD_ID ||
+ n->namesz != 4 )
+ return false;
+
+ name = ELFNOTE_NAME(n);
+ if ( strncmp(name, "GNU", 4) != 0 )
+ return false;
+
+ if ( len != n->descsz + NT_GNU_HDR_SIZE )
+ return false;
+
+ return true;
+}
+
int xen_build_id_check(const Elf_Note *n, unsigned int n_sz,
const void **p, unsigned int *len)
{
@@ -234,6 +265,8 @@ static void __init __maybe_unused build_assertions(void)
{
BUILD_BUG_ON(sizeof(unsigned long) != sizeof(void (*)(void)));
BUILD_BUG_ON(sizeof(void *) != sizeof(void (*)(void)));
+
+ BUILD_BUG_ON(NT_GNU_HDR_SIZE != sizeof(Elf_Note) + 4);
}
/*
diff --git a/xen/include/xen/elfstructs.h b/xen/include/xen/elfstructs.h
index 8ee0d5aa5b15..1f0287aeed49 100644
--- a/xen/include/xen/elfstructs.h
+++ b/xen/include/xen/elfstructs.h
@@ -46,6 +46,8 @@ typedef uint32_t Elf64_Word;
typedef int64_t Elf64_Sxword;
typedef uint64_t Elf64_Xword;
+#define NT_GNU_HDR_SIZE 16 /* sizeof(Elf_note) + "GNU\0" */
+
/* Unique build id string format when using --build-id. */
#define NT_GNU_BUILD_ID 3
diff --git a/xen/include/xen/version.h b/xen/include/xen/version.h
index b9fa8d70520d..ee857616f9e4 100644
--- a/xen/include/xen/version.h
+++ b/xen/include/xen/version.h
@@ -2,6 +2,7 @@
#define __XEN_VERSION_H__
#include <xen/elfstructs.h>
+#include <xen/stdbool.h>
const char *xen_compile_date(void);
const char *xen_compile_time(void);
@@ -26,6 +27,7 @@ extern unsigned int xen_build_id_len; /* 0 -> No build id. */
void xen_build_init(void);
int xen_build_id_check(const Elf_Note *n, unsigned int n_sz,
const void **p, unsigned int *len);
+bool is_gnu_build_id(const Elf_Note *n, unsigned int len);
#else
static inline void xen_build_init(void) {};
#endif
base-commit: 2043d22b7e926f508cc23391b4c75325fa7211e9
--
2.39.5
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |