]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/uklibid: Option to dump list of libraries during boot
authorSimon Kuenzer <simon@unikraft.io>
Fri, 15 Sep 2023 11:02:24 +0000 (13:02 +0200)
committerRazvan Deaconescu <razvand@unikraft.io>
Fri, 20 Oct 2023 16:35:55 +0000 (19:35 +0300)
This commit introduces the `CONFIG_LIBUKLIBID_INFO_BOOTDUMP` option, which
prints the name and version of each library found in the `.uk_libinfo`
section during boot.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1117

lib/uklibid/Config.uk
lib/uklibid/Makefile.uk
lib/uklibid/include/uk/libid/info.h
lib/uklibid/infodump.c [new file with mode: 0644]
lib/uklibid/infosec.ld

index c9aa633839ca234c0a40d80d8557c6623b060db5..a3887cc8dc698e50365b39949c578557124944b6 100644 (file)
@@ -68,4 +68,9 @@ config LIBUKLIBID_INFO
                                Enables storing the C compiler ($(CC)) that was
                                used for each library.
        endmenu
+
+       config LIBUKLIBID_INFO_BOOTDUMP
+               bool "Print library summary early during boot"
+               depends on LIBUKLIBID_INFO
+               default n
 endif
index 3d94d938effcc101490ee7907cc12b4518d89e70..fc0bee78aa5adeb3a362ae16b705401bbec5aff8 100644 (file)
@@ -38,6 +38,7 @@ LIBUKLIBID_SRCS-y += $(LIBUKLIBID_BASE)/exportsyms.awk>.uk
 LIBUKLIBID_EXPORTSYMS_AWKINCLUDES-y += $(LIBUKLIBID_BUILD)/libraries.in
 LIBUKLIBID_EXPORTS-y += $(LIBUKLIBID_BUILD)/exportsyms.uk
 
+LIBUKLIBID_SRCS-$(CONFIG_LIBUKLIBID_INFO_BOOTDUMP) += $(LIBUKLIBID_BASE)/infodump.c
 EACHOLIB_SRCS-$(CONFIG_LIBUKLIBID_INFO) += $(LIBUKLIBID_BASE)/libinfo.S|libuklibid
 ASFLAGS += -D__LIBUKLIBID_COMPILER__="$(CC_INFO)"
 LIBUKLIBID_SRCS-$(CONFIG_LIBUKLIBID_INFO) +=  $(LIBUKLIBID_BASE)/infosec.ld
index 9168d3b035f6649c812a280730b076c42f6ae879..08dab8e1ea1c0d48ca368082779ddf6ff2a30476 100644 (file)
@@ -86,6 +86,21 @@ struct uk_libid_info_hdr {
        struct uk_libid_info_rec recs[];
 } __packed __align(1);
 
+extern const struct uk_libid_info_hdr uk_libinfo_start[];
+extern const struct uk_libid_info_hdr uk_libinfo_end;
+
+#define uk_libinfo_hdr_foreach(hdr_itr)                                               \
+       for ((hdr_itr) = (const struct uk_libid_info_hdr *)uk_libinfo_start;   \
+            (hdr_itr) < &(uk_libinfo_end);                                    \
+            (hdr_itr) = (const struct uk_libid_info_hdr *)((__uptr)(hdr_itr)  \
+                                                           + (hdr_itr)->len))
+
+#define uk_libinfo_rec_foreach(hdr, rec_itr)                                  \
+       for ((rec_itr) = (const struct uk_libid_info_rec *) &hdr->recs[0];     \
+            (__uptr)(rec_itr) < ((__uptr)hdr + hdr->len);                     \
+            (rec_itr) = (const struct uk_libid_info_rec *)((__uptr)(rec_itr)  \
+                                                           + (rec_itr)->len))
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/uklibid/infodump.c b/lib/uklibid/infodump.c
new file mode 100644 (file)
index 0000000..0877097
--- /dev/null
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+#include <uk/libid/info.h>
+#include <uk/ctors.h>
+#include <uk/print.h>
+#include <uk/assert.h>
+
+static void libinfo_bootdump(void)
+{
+       const struct uk_libid_info_hdr *hdr;
+       const struct uk_libid_info_rec *rec;
+       const char *libname, *version, *license;
+
+       uk_pr_debug("Library info section .uk_libinfo %p - %p\n",
+                   uk_libinfo_start, &uk_libinfo_end);
+       uk_pr_info("Compiled-in libraries:\n");
+       uk_libinfo_hdr_foreach(hdr) {
+               if (hdr->version != UKLI_LAYOUT) {
+                       uk_pr_debug("Unknown library info layout at %p\n", hdr);
+                       continue;
+               }
+
+               libname = __NULL;
+               version = "<n/a>";
+               license = __NULL;
+               uk_libinfo_rec_foreach(hdr, rec) {
+                       switch (rec->type) {
+                       case UKLI_REC_LIBNAME:
+                               libname = rec->data;
+                               break;
+                       case UKLI_REC_VERSION:
+                               version = rec->data;
+                               break;
+                       case UKLI_REC_LICENSE:
+                               version = rec->data;
+                               break;
+                       default:
+                               break;
+                       }
+               }
+
+               /* Print only per library information (skip global info) */
+               if (libname) {
+                       uk_pr_info(" %s (version: %s", libname, version);
+                       if (license)
+                               uk_pr_info(", license: %s", license);
+                       uk_pr_info(")\n");
+               }
+       }
+}
+
+UK_CTOR(libinfo_bootdump);
index 7639c2b2106eb4cfbc658617dc6333df753a9248..3da0714b365ff3996cee4a61dfb816794ecbd438 100644 (file)
@@ -3,7 +3,9 @@ SECTIONS
        . = ALIGN(1);
        .uk_libinfo :
        {
+               PROVIDE(uk_libinfo_start = .);
                KEEP (*(.uk_libinfo))
+               PROVIDE(uk_libinfo_end = .);
        }
 }
 INSERT AFTER .rodata;