Skip to contentSkip to conversation

ovmf: Improve reproducibility by enabling prefix mapping

PATCH Superseded Richard Purdie 1 participant 1 message May 9, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovmf: Improve reproducibility by enabling prefix mapping

We want to pass ${DEBUG_PREFIX_MAP} to gcc commands and also pass in --debug-prefix-map to nasm (we carry a patch to nasm for this). The tools commands are built by ovmf-native so we need to patch this in at target build time when we know the right values. This function also has to be able to undo what it changed and rerun. By using determininistc file paths in the ovmf build, it removes the opportunitity for gcc/ld to change the output binaries due to path lengths overflowing section sizes and causing small changes in the binary output.

This also means that if builds have reproducibility issues in future, it becomes much easier to compare intermediate build artefacts.

---
 meta/recipes-core/ovmf/ovmf_git.bb | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
meta/recipes-core/ovmf/ovmf_git.bb +27 -0
index 896b3b63202..91de742c06c 100644
@@ -104,6 +104,33 @@ fix_toolchain_append_class-native() {
         ${S}/BaseTools/Conf/tools_def.template
 }
 
+#
+# We want to pass ${DEBUG_PREFIX_MAP} to gcc commands and also pass in
+# --debug-prefix-map to nasm (we carry a patch to nasm for this). The
+# tools commands are built by ovmf-native so we need to patch this in
+# at target build time when we know the right values. This function also
+# has to be able to undo what it changed and rerun. By using determininistc
+# file paths during the ovmf build, it removes the opportunitity for gcc/ld to
+# change the output binaries due to path lengths overflowing section sizes
+# and causing small changes in the binary output. Previously we relied on 
+# the stripped output being the same which isn't always the case if the 
+# size of the debug symbols varies.
+#
+do_configure_class-target() {
+    sed -i \
+        -e 's# DEF(GCC_PREFIX_MAP)##g' \
+        -e 's# DEF(NASM_PREFIX_MAP)##g' \
+        -e '/^DEFINE \(GCC|NASM\)_PREFIX_MAP/d' \
+        -e 's#^\(DEFINE GCC_ALL_CC_FLAGS.*=.*\)\r$#\1 DEF(GCC_PREFIX_MAP)#' \
+        -e 's#^\(DEFINE GCC_PP_FLAGS.*=.*\)\r$#\1 DEF(GCC_PREFIX_MAP)#' \
+        -e 's#^\(DEFINE GCC_ASM_FLAGS.*=.*\)\r$#\1 DEF(GCC_PREFIX_MAP)#' \
+        -e 's#^\(*_GCC5_IA32_NASM_FLAGS.*=.*\)\r$#\1 DEF(NASM_PREFIX_MAP)#' \
+        -e 's#^\(*_GCC5_X64_NASM_FLAGS.*=.*\)\r$#\1 DEF(NASM_PREFIX_MAP)#' \
+        -e '1 i\DEFINE NASM_PREFIX_MAP = --debug-prefix-map=${WORKDIR}=/usr/src/debug/ovmf/${EXTENDPE}${PV}-${PR}' \
+        -e '1 i\DEFINE GCC_PREFIX_MAP = ${DEBUG_PREFIX_MAP}' \
+        ${STAGING_BINDIR_NATIVE}/${EDK_TOOLS_DIR}/BaseTools/Conf/tools_def.template
+}
+
 GCC_VER="$(${CC} -v 2>&1 | tail -n1 | awk '{print $3}')"
 
 fixup_target_tools() {
Signature · 1 line
2.30.2