From: Simon Kuenzer Date: Tue, 10 Oct 2023 11:37:56 +0000 (+0200) Subject: lib/uklibid: Option to store "Compile date" to `.uklibid_info` X-Git-Tag: RELEASE-0.15.0~73 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ea050dbfea219e707dc49d6d225bd8d771291e15;p=unikraft%2Funikraft.git lib/uklibid: Option to store "Compile date" to `.uklibid_info` Adds the option to store the compile time and date for a library and unikernel. When enabled, `libinfo.S` is recompiled on every rebuild. This is achieved by handing over the current time and date as compile flag. For this purpose, the build system provides `$(HOSTUTC)`, the current time and date in UTC format. Signed-off-by: Simon Kuenzer Reviewed-by: Michalis Pappas Reviewed-by: Robert Kuban Approved-by: Razvan Deaconescu GitHub-Closes: #1117 --- diff --git a/Makefile b/Makefile index ad3af1d5e..8df14d93e 100644 --- a/Makefile +++ b/Makefile @@ -440,6 +440,7 @@ 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') +HOSTUTC := $(shell date -u) HOSTNAME := $(shell hostname -s) HOSTUSER := $(shell whoami) diff --git a/lib/uklibid/Config.uk b/lib/uklibid/Config.uk index a8599cd07..ac96c3826 100644 --- a/lib/uklibid/Config.uk +++ b/lib/uklibid/Config.uk @@ -38,6 +38,13 @@ config LIBUKLIBID_INFO used for during compilation for the unikernel image. + config LIBUKLIBID_INFO_COMPILEDATE + bool "Compile date" + default y + help + This option stores the compile date and time for + the unikernel image. + config LIBUKLIBID_INFO_UKCONFIGGZ bool "Embed gzipped configuration (.config)" help @@ -74,6 +81,12 @@ config LIBUKLIBID_INFO help Enables storing the C compiler ($(CC)) that was used for each library. + + config LIBUKLIBID_INFO_LIB_COMPILEDATE + bool "Compile date" + help + This option stores the compile date and time for + each library. endmenu menuconfig LIBUKLIBID_INFO_COMPILEDBY diff --git a/lib/uklibid/Makefile.uk b/lib/uklibid/Makefile.uk index 110b3c486..21fc52b9f 100644 --- a/lib/uklibid/Makefile.uk +++ b/lib/uklibid/Makefile.uk @@ -44,10 +44,14 @@ 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 +# NOTE: We hand-over $(HOSTUTC) instead of using __DATE__ and __TIME__ in order +# to ensure recompilation of `libinfo.S` due to changed compile flags +ASFLAGS-$(CONFIG_LIBUKLIBID_INFO_LIB_COMPILEDATE) += -D__LIBUKLIBID_UTCDATE__="$(HOSTUTC)" 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__ +LIBUKLIBID_LIBINFO_GLOBAL_FLAGS-$(CONFIG_LIBUKLIBID_INFO_COMPILEDATE) += -DUK_UTCDATE="$(HOSTUTC)" LIBUKLIBID_LIBINFO_GLOBAL_CDEPS-$(CONFIG_LIBUKLIBID_INFO_UKCONFIGGZ) += $(LIBUKLIBID_BUILD)/config.gz LIBUKLIBID_LIBINFO_GLOBAL_FLAGS-$(CONFIG_LIBUKLIBID_INFO_UKCONFIGGZ) += -DUK_CONFIGGZINC="$(LIBUKLIBID_BUILD)/config.gz" diff --git a/lib/uklibid/libinfo.S b/lib/uklibid/libinfo.S index 7178d1010..15e54ceeb 100644 --- a/lib/uklibid/libinfo.S +++ b/lib/uklibid/libinfo.S @@ -34,6 +34,10 @@ RECORD(UKLI_REC_COMPILER, .asciz STRINGIFY(__LIBUKLIBID_COMPILER__)) #endif /* CONFIG_LIBUKLIBID_INFO_COMPILER */ +#if CONFIG_LIBUKLIBID_INFO_COMPILEDATE + RECORD(UKLI_REC_COMPILEDATE, + .asciz STRINGIFY(UK_UTCDATE)) +#endif /* CONFIG_LIBUKLIBID_INFO_COMPILEDATE */ #if CONFIG_LIBUKLIBID_INFO_UKCONFIGGZ RECORD(UKLI_REC_UKCONFIGGZ, .incbin STRINGIFY(UK_CONFIGGZINC)) #endif /* CONFIG_LIBUKLIBID_INFO_UKCONFIGGZ */ @@ -56,6 +60,10 @@ RECORD(UKLI_REC_COMPILER, .asciz STRINGIFY(__LIBUKLIBID_COMPILER__)) #endif /* CONFIG_LIBUKLIBID_INFO_COMPILER */ +#if CONFIG_LIBUKLIBID_INFO_LIB_COMPILEDATE + RECORD(UKLI_REC_COMPILEDATE, + .asciz STRINGIFY(__LIBUKLIBID_UTCDATE__)) +#endif /* CONFIG_LIBUKLIBID_INFO_COMPILEDATE */ RECORD(UKLI_REC_COMPILEOPTS, .__u32 ( (!(!__LIBUKLIBID_COMPILEOPT_PIE__) * UKLI_REC_CO_PIE) |\ (!(!__LIBUKLIBID_COMPILEOPT_DCE__) * UKLI_REC_CO_DCE) |\