Skip to content

eBPF-based security platform

util: declare the version strings in one header

Daniel Borkmann8ef86f8102c1
diff --git a/Makefile.shirudo b/Makefile.shirudo
index f43b617f..0038a724 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -338,6 +338,8 @@ util/version_id.c:
echo "/* Copyright (c) 2026 Authors of shirudo */"; \
echo "/* AUTO-GENERATED. Do not edit. Do not commit. */"; \
echo ""; \
+ echo "#include \"version.h\""; \
+ echo ""; \
echo "const char shirudo_version[] = \"$$describe_c\";"; \
echo "const char shirudo_version_id[] = \"$$id\";"; \
echo "const char shirudo_extraversion[] = \"$$extra_c\";"; \
diff --git a/builtin-status.c b/builtin-status.c
index 2b5d5631..36ed84a0 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -55,8 +55,7 @@
#include "util/tamper.h"
#include "util/upatch_resolve.h"
#include "util/upatch_table.h"
-
-extern const char shirudo_version_id[];
+#include "util/version.h"
static int notdot(const struct dirent *e)
{
diff --git a/builtin-upatch.c b/builtin-upatch.c
index dfe53b32..6b5d4e7e 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -56,8 +56,7 @@
#include "util/upatch_maps.h"
#include "util/upatch_maps_otel.h"
#include "util/upatch_resolve.h"
-
-extern const char shirudo_version_id[];
+#include "util/version.h"
static bool safe_upatch_name(const char *name);
diff --git a/builtin-version.c b/builtin-version.c
index 15bdbd20..dd8467ae 100644
--- a/builtin-version.c
+++ b/builtin-version.c
@@ -11,11 +11,7 @@
#include "builtin.h"
#include "util/help.h"
#include "util/macros.h"
-
-extern const char shirudo_version[];
-extern const char shirudo_version_id[];
-extern const char shirudo_extraversion[];
-extern const char shirudo_release_name[];
+#include "util/version.h"
static const struct shirudo_help_item version_options[] = {
{ "--version-id", "print only the raw SHIRUDO_VERSION_ID, one line" },
diff --git a/testing/helper/test-otel-map.c b/testing/helper/test-otel-map.c
index 83aae952..730996ae 100644
--- a/testing/helper/test-otel-map.c
+++ b/testing/helper/test-otel-map.c
@@ -22,6 +22,7 @@
#include "malloc.h"
#include "upatch_maps.h"
#include "upatch_maps_otel.h"
+#include "version.h"
const char shirudo_version[] = "test-1";
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index bc205ccf..e0ee3a9b 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -33,6 +33,7 @@
#include "package.h"
#include "paths.h"
#include "upatch.h"
+#include "version.h"
#include "vmlinux.h"
#ifndef SHIRUDO_VMLINUX_PATH
@@ -43,8 +44,6 @@
#define BPM_BUILD_MAX_JSON (256u * 1024u)
#define BPM_BUILD_MAX_VALUE 1024
-extern const char shirudo_version[];
-
static void build_copy(char *dst, size_t cap, const char *src)
{
if (!cap)
diff --git a/util/attest.c b/util/attest.c
index d47b7f04..ed24e998 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -28,6 +28,7 @@
#include "malloc.h"
#include "paths.h"
#include "tpm.h"
+#include "version.h"
#define FIRMWARE_LOG_PATH \
"/sys/kernel/security/tpm0/binary_bios_measurements"
@@ -40,8 +41,6 @@
/* restricted | sign | fixedTPM | fixedParent | sensitiveDataOrigin */
#define AK_ATTRS_REQUIRED 0x00050032u
-extern const char shirudo_version_id[];
-
/*
* securityfs reports a size of 0 for the firmware event log, so the log
* is read to its end rather than for the size fstat() gives.
diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.c
index 2c4f77e9..6a7ed2e1 100644
--- a/util/upatch_maps_otel.c
+++ b/util/upatch_maps_otel.c
@@ -41,6 +41,7 @@
#include "tenant_id.h"
#include "upatch_decode.h"
#include "upatch_maps_otel.h"
+#include "version.h"
#define OTEL_ENDPOINT_MAX 2048
#define OTEL_RESPONSE_MAX (64U * 1024U)
@@ -58,8 +59,6 @@
#define S3_GZIP_BUFFER_SIZE (64U * 1024U)
#define S3_REFERENCE_MAX (64U * 1024U)
-extern const char shirudo_version[];
-
struct otel_response {
char buf[OTEL_RESPONSE_MAX];
size_t len;
diff --git a/util/version.h b/util/version.h
new file mode 100644
index 00000000..4b191060
--- /dev/null
+++ b/util/version.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * Build identity strings, defined in the generated util/version_id.c.
+ */
+
+#ifndef SHIRUDO_VERSION_H
+#define SHIRUDO_VERSION_H
+
+extern const char shirudo_version[];
+extern const char shirudo_version_id[];
+extern const char shirudo_extraversion[];
+extern const char shirudo_release_name[];
+
+#endif