arrfab / rpms / shim

Forked from rpms/shim 4 years ago
Clone

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

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