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

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