Blame SOURCES/0029-Once-again-try-even-harder-to-get-binaries-without-t.patch

d1e1c8
From 10d6e3d90f1ea504a1dedaea50478c444e92951c Mon Sep 17 00:00:00 2001
d1e1c8
From: Peter Jones <pjones@redhat.com>
d1e1c8
Date: Fri, 15 Mar 2019 09:52:02 -0400
d1e1c8
Subject: [PATCH 29/62] Once again, try even harder to get binaries without
d1e1c8
 timestamps in them.
d1e1c8
MIME-Version: 1.0
d1e1c8
Content-Type: text/plain; charset=UTF-8
d1e1c8
Content-Transfer-Encoding: 8bit
d1e1c8
d1e1c8
$ objdump -x /builddir/build/BUILDROOT/shim-*/usr/share/shim/*/shimx64.efi | grep 'Time/Date'
d1e1c8
Time/Date		Thu Jan  1 00:00:08 1970
d1e1c8
$ _
d1e1c8
d1e1c8
"What is despair? I have known it—hear my song. Despair is when you’re
d1e1c8
debugging a kernel driver and you look at a memory dump and you see that
d1e1c8
a pointer has a value of 7."
d1e1c8
 - http://scholar.harvard.edu/files/mickens/files/thenightwatch.pdf
d1e1c8
d1e1c8
objcopy only knows about -D for some targets.
d1e1c8
ld only believes in --no-insert-timestamp in some versions.
d1e1c8
dd takes off and nukes the site from orbit.
d1e1c8
d1e1c8
It's the only way to be sure.
d1e1c8
d1e1c8
Signed-off-by: Peter Jones <pjones@redhat.com>
d1e1c8
Upstream-commit-id: a4a1fbe728c
d1e1c8
---
d1e1c8
 Make.defaults | 4 ++++
d1e1c8
 Makefile      | 6 ++++--
d1e1c8
 2 files changed, 8 insertions(+), 2 deletions(-)
d1e1c8
d1e1c8
diff --git a/Make.defaults b/Make.defaults
d1e1c8
index 09807bd8108..f0bfa9fd573 100644
d1e1c8
--- a/Make.defaults
d1e1c8
+++ b/Make.defaults
d1e1c8
@@ -50,6 +50,7 @@ ifeq ($(ARCH),x86_64)
d1e1c8
 	ARCH_SUFFIX		?= x64
d1e1c8
 	ARCH_SUFFIX_UPPER	?= X64
d1e1c8
 	ARCH_LDFLAGS		?=
d1e1c8
+	TIMESTAMP_LOCATION	:= 136
d1e1c8
 endif
d1e1c8
 ifeq ($(ARCH),ia32)
d1e1c8
 	ARCH_CFLAGS		?= -mno-mmx -mno-sse -mno-red-zone -nostdinc \
d1e1c8
@@ -60,6 +61,7 @@ ifeq ($(ARCH),ia32)
d1e1c8
 	ARCH_SUFFIX_UPPER	?= IA32
d1e1c8
 	ARCH_LDFLAGS		?=
d1e1c8
 	ARCH_CFLAGS		?= -m32
d1e1c8
+	TIMESTAMP_LOCATION	:= 136
d1e1c8
 endif
d1e1c8
 ifeq ($(ARCH),aarch64)
d1e1c8
 	ARCH_CFLAGS		?= -DMDE_CPU_AARCH64 -DPAGE_SIZE=4096 -mstrict-align
d1e1c8
@@ -70,6 +72,7 @@ ifeq ($(ARCH),aarch64)
d1e1c8
 	SUBSYSTEM		:= 0xa
d1e1c8
 	ARCH_LDFLAGS		+= --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)
d1e1c8
 	ARCH_CFLAGS		?=
d1e1c8
+	TIMESTAMP_LOCATION	:= 72
d1e1c8
 endif
d1e1c8
 ifeq ($(ARCH),arm)
d1e1c8
 	ARCH_CFLAGS		?= -DMDE_CPU_ARM -DPAGE_SIZE=4096 -mno-unaligned-access
d1e1c8
@@ -79,6 +82,7 @@ ifeq ($(ARCH),arm)
d1e1c8
 	FORMAT			:= -O binary
d1e1c8
 	SUBSYSTEM		:= 0xa
d1e1c8
 	ARCH_LDFLAGS		+= --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)
d1e1c8
+	TIMESTAMP_LOCATION	:= 72
d1e1c8
 endif
d1e1c8
 
d1e1c8
 CFLAGS		= -ggdb -O0 -fno-stack-protector -fno-strict-aliasing -fpic \
d1e1c8
diff --git a/Makefile b/Makefile
d1e1c8
index fd7e83dc764..49e14a26521 100644
d1e1c8
--- a/Makefile
d1e1c8
+++ b/Makefile
d1e1c8
@@ -189,11 +189,13 @@ endif
d1e1c8
 ifneq ($(OBJCOPY_GTE224),1)
d1e1c8
 	$(error objcopy >= 2.24 is required)
d1e1c8
 endif
d1e1c8
-	$(OBJCOPY) -j .text -j .sdata -j .data -j .data.ident \
d1e1c8
+	$(OBJCOPY) -D -j .text -j .sdata -j .data -j .data.ident \
d1e1c8
 		-j .dynamic -j .dynsym -j .rel* \
d1e1c8
 		-j .rela* -j .reloc -j .eh_frame \
d1e1c8
 		-j .vendor_cert \
d1e1c8
 		$(FORMAT) $^ $@
d1e1c8
+	# I am tired of wasting my time fighting binutils timestamp code.
d1e1c8
+	dd conv=notrunc bs=1 count=4 seek=$(TIMESTAMP_LOCATION) if=/dev/zero of=$@
d1e1c8
 
d1e1c8
 ifneq ($(origin ENABLE_SHIM_HASH),undefined)
d1e1c8
 %.hash : %.efi
d1e1c8
@@ -204,7 +206,7 @@ endif
d1e1c8
 ifneq ($(OBJCOPY_GTE224),1)
d1e1c8
 	$(error objcopy >= 2.24 is required)
d1e1c8
 endif
d1e1c8
-	$(OBJCOPY) -j .text -j .sdata -j .data \
d1e1c8
+	$(OBJCOPY) -D -j .text -j .sdata -j .data \
d1e1c8
 		-j .dynamic -j .dynsym -j .rel* \
d1e1c8
 		-j .rela* -j .reloc -j .eh_frame \
d1e1c8
 		-j .debug_info -j .debug_abbrev -j .debug_aranges \
d1e1c8
-- 
d1e1c8
2.26.2
d1e1c8