From fd96b8408f73f08d67eabd3ba3444df316896b59 Mon Sep 17 00:00:00 2001 From: Simon Kuenzer Date: Fri, 6 Oct 2023 19:46:02 +0300 Subject: [PATCH] lib/uklibid: Option to store "Compiled-by" to `.uklibid_info` Adds the option to store information about the person/entity/robot that was compiling a library and unikernel. When enabled, the local system user and hostname is used as default. For this purpose, the build system provides `$(HOSTNAME)` and `$(HOSTUSER)`. Custom strings are also supported as well. Signed-off-by: Simon Kuenzer Reviewed-by: Michalis Pappas Reviewed-by: Robert Kuban Approved-by: Razvan Deaconescu GitHub-Closes: #1117 --- Makefile | 2 ++ lib/uklibid/Config.uk | 40 ++++++++++++++++++++++++++++++++++++++++ lib/uklibid/Makefile.uk | 1 + lib/uklibid/libinfo.S | 13 +++++++++++++ 4 files changed, 56 insertions(+) diff --git a/Makefile b/Makefile index 2d58e50fb..ad3af1d5e 100644 --- a/Makefile +++ b/Makefile @@ -440,6 +440,8 @@ HOSTOBJCOPY := $(shell which $(HOSTOBJCOPY) || type -p $(HOSTOBJCOPY) || echo ob HOSTRANLIB := $(shell which $(HOSTRANLIB) || type -p $(HOSTRANLIB) || echo ranlib) HOSTCC_VERSION := $(shell $(HOSTCC_NOCCACHE) --version | \ $(SED) -n -r 's/^.* ([0-9]*)\.([0-9]*)\.([0-9]*)[ ]*.*/\1 \2/p') +HOSTNAME := $(shell hostname -s) +HOSTUSER := $(shell whoami) # For gcc >= 5.x, we only need the major version. ifneq ($(firstword $(HOSTCC_VERSION)),4) diff --git a/lib/uklibid/Config.uk b/lib/uklibid/Config.uk index 36e87de30..a8599cd07 100644 --- a/lib/uklibid/Config.uk +++ b/lib/uklibid/Config.uk @@ -76,6 +76,46 @@ config LIBUKLIBID_INFO used for each library. endmenu + menuconfig LIBUKLIBID_INFO_COMPILEDBY + bool "Compiled by" + help + Name of the person/entity that did the compilation. + This information is added to each library and to the + global metadata information of a unikernel. + + if LIBUKLIBID_INFO_COMPILEDBY + config LIBUKLIBID_INFO_COMPILEDBY_HOST + bool "Auto-detect name (user@hostname)" + default y + help + Automatically retrieves "Compiled by" + information by detecting the user + and the host (user@hostname). + + config LIBUKLIBID_INFO_COMPILEDBY_CUSTOM_TEXT + string "Custom name" + depends on !LIBUKLIBID_INFO_COMPILEDBY_HOST + help + This option can be used to set a custom name + that is set as "Compiled by" information. + + # Invisible option that enables auto-detecting user from host + config LIBUKLIBID_INFO_COMPILEDBY_CUSTOM + bool + default y if LIBUKLIBID_INFO_COMPILEDBY_CUSTOM_TEXT != "" + + config LIBUKLIBID_INFO_COMPILEDBYASSOC_TEXT + string "Association" + help + Additional "Compiled by" field for setting an + association. + + config LIBUKLIBID_INFO_COMPILEDBYASSOC + bool + default y if LIBUKLIBID_INFO_COMPILEDBYASSOC_TEXT != "" + endif + endif + config LIBUKLIBID_INFO_BOOTDUMP bool "Print library summary early during boot" depends on LIBUKLIBID_INFO diff --git a/lib/uklibid/Makefile.uk b/lib/uklibid/Makefile.uk index 354930864..110b3c486 100644 --- a/lib/uklibid/Makefile.uk +++ b/lib/uklibid/Makefile.uk @@ -44,6 +44,7 @@ ASFLAGS += -D__LIBUKLIBID_COMPILER__="$(CC_INFO)" ASFLAGS-$(CONFIG_OPTIMIZE_PIE) += -D__LIBUKLIBID_COMPILEOPT_PIE__=1 ASFLAGS-$(CONFIG_OPTIMIZE_LTO) += -D__LIBUKLIBID_COMPILEOPT_LTO__=1 ASFLAGS-$(CONFIG_OPTIMIZE_DEADELIM) += -D__LIBUKLIBID_COMPILEOPT_DCE__=1 +ASFLAGS-$(CONFIG_LIBUKLIBID_INFO_COMPILEDBY_HOST) += -D__LIBUKLIBID_COMPILEDBY_HOST__="$(HOSTUSER)@$(HOSTNAME)" LIBUKLIBID_SRCS-$(CONFIG_LIBUKLIBID_INFO) += $(LIBUKLIBID_BASE)/infosec.ld LIBUKLIBID_SRCS-$(CONFIG_LIBUKLIBID_INFO) += $(LIBUKLIBID_BASE)/libinfo.S|global LIBUKLIBID_LIBINFO_GLOBAL_FLAGS-y += -D__GLOBALINFO__ diff --git a/lib/uklibid/libinfo.S b/lib/uklibid/libinfo.S index 642e2a9df..7178d1010 100644 --- a/lib/uklibid/libinfo.S +++ b/lib/uklibid/libinfo.S @@ -62,5 +62,18 @@ (!(!__LIBUKLIBID_COMPILEOPT_LTO__) * UKLI_REC_CO_LTO))) #endif /* !__GLOBALINFO__ */ +#if CONFIG_LIBUKLIBID_INFO_COMPILEDBY_HOST + RECORD(UKLI_REC_COMPILEDBY, + .asciz STRINGIFY(__LIBUKLIBID_COMPILEDBY_HOST__)) +#endif /* CONFIG_LIBUKLIBID_INFO_COMPILEDBY_HOST */ +#if CONFIG_LIBUKLIBID_INFO_COMPILEDBY_CUSTOM + RECORD(UKLI_REC_COMPILEDBY, + .asciz CONFIG_LIBUKLIBID_INFO_COMPILEDBY_CUSTOM_TEXT) +#endif /* CONFIG_LIBUKLIBID_INFO_COMPILEDBY_CUSTOM */ +#if CONFIG_LIBUKLIBID_INFO_COMPILEDBYASSOC + RECORD(UKLI_REC_COMPILEDBYASSOC, + .asciz CONFIG_LIBUKLIBID_INFO_COMPILEDBYASSOC_TEXT) +#endif /* CONFIG_LIBUKLIBID_INFO_COMPILEDBYASSOC */ + 4: .align 1 .popsection -- 2.39.5