Skip to contentSkip to conversation

openssl_1.0.2n: improve reproducibility

PATCH In review Juro Bystricky 2 participants 4 messages Mar 10, 2018 – Jul 23, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 openssl_1.0.2n: improve reproducibility

Improve reproducible build of:

openssl-staticdev
openssl-dbg
libcrypto

There are two main causes that prevent reproducible build, both related to the generated file "buildinf.h":

1. "buildinf.h" contains build host CFLAGS, containing various build host references. We need to pass sanitized CFLAGS to the script generating this file ("mkbuildinf.pl". )

2. We also need to modify the script "mkbuildinf.pl" itsel in order to generate a build timestamp based on SOURCE_DATE_EPOCH, if present in the environment.

---
 .../openssl-1.0.2n/reproducible-cflags.patch        | 20 ++++++++++++++++++++
 .../openssl-1.0.2n/reproducible-mkbuildinf.patch    | 21 +++++++++++++++++++++
 meta/recipes-connectivity/openssl/openssl10.inc     |  3 +++
 meta/recipes-connectivity/openssl/openssl_1.0.2n.bb |  5 +++++
 4 files changed, 49 insertions(+)
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-cflags.patch
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-mkbuildinf.patch
meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-cflags.patch new file +20 -0
new file mode 100644
index 0000000..2803cb0
@@ -0,0 +1,20 @@
+Allow passing custom c-flags to mkbuildinf.pl in order to pass
+flags without any build host references
+
+Upstream-Status: Inappropriate [OE specific]
+
+Signed-off-by: Juro Bystricky <[email protected]>
+
+--- Makefile	2018-03-06 14:50:18.342138147 -0800
++++ Makefile	2018-03-06 15:24:04.794239071 -0800
+--- a/crypto/Makefile
++++ b/crypto/Makefile
+@@ -55,7 +55,7 @@
+ all: shared
+ 
+ buildinf.h: ../Makefile
+-	$(PERL) $(TOP)/util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)" >buildinf.h
++	$(PERL) $(TOP)/util/mkbuildinf.pl "$(CC_INFO)" "$(PLATFORM)" >buildinf.h
+ 
+ x86cpuid.s:	x86cpuid.pl perlasm/x86asm.pl
+ 	$(PERL) x86cpuid.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-mkbuildinf.patch new file +21 -0
new file mode 100644
index 0000000..b556731
@@ -0,0 +1,21 @@
+If SOURCE_DATE_EPOCH is present in the environment, use it as build date.
+Also make sure to use UTC time.
+
+Upstream-Status: Backport [ https://github.com/openssl/openssl/blob/master/util/mkbuildinf.pl ]
+
+Signed-off-by: Juro Bystricky <[email protected]>
+
+--- mkbuildinf.pl	2018-03-06 14:20:09.438048058 -0800
++++ mkbuildinf.pl	2018-03-06 14:19:20.722045632 -0800
+--- a/util/mkbuildinf.pl
++++ b/util/mkbuildinf.pl
+@@ -3,7 +3,8 @@
+ my ($cflags, $platform) = @ARGV;
+ 
+ $cflags = "compiler: $cflags";
+-$date = localtime();
++my $date = gmtime($ENV{'SOURCE_DATE_EPOCH'} || time()) . " UTC";
++
+ print <<"END_OUTPUT";
+ #ifndef MK1MF_BUILD
+     /* auto-generated by util/mkbuildinf.pl for crypto/cversion.c */
meta/recipes-connectivity/openssl/openssl10.inc +3 -0
index 02a0e16..0598195 100644
@@ -162,6 +162,9 @@ do_configure () {
 
 do_compile_prepend_class-target () {
     sed -i 's/\((OPENSSL=\)".*"/\1"openssl"/' Makefile
+    oe_runmake depend
+	cc_sanitized=`echo "${CC} ${CFLAG}" | sed -e 's,--sysroot=${STAGING_DIR_TARGET},,g' -e 's|${DEBUG_PREFIX_MAP}||g'`
+	oe_runmake CC_INFO="${cc_sanitized}"
 }
 
 do_compile () {
meta/recipes-connectivity/openssl/openssl_1.0.2n.bb +5 -0
index 32444c6..f07289d 100644
@@ -43,6 +43,11 @@ SRC_URI += "file://find.pl;subdir=openssl-${PV}/util/ \
            file://0001-Fix-build-with-clang-using-external-assembler.patch \
            file://0001-openssl-force-soft-link-to-avoid-rare-race.patch \
            "
+
+SRC_URI_append_class-target = "\
+           file://reproducible-cflags.patch \
+           file://reproducible-mkbuildinf.patch \
+           "
 SRC_URI[md5sum] = "13bdc1b1d1ff39b6fd42a255e74676a4"
 SRC_URI[sha256sum] = "370babb75f278c39e0c50e8c4e7493bc0f18db6867478341a832a982fd15a8fe"
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 32 lines · Juro Bystricky

Improve reproducible build of:

openssl-staticdev
openssl-dbg
libcrypto

There are two main causes that prevent reproducible build, both related to the generated file "buildinf.h":

1. "buildinf.h" contains build host CFLAGS, containing various build host references. We need to pass sanitized CFLAGS to the script generating this file ("mkbuildinf.pl". )

2. We also need to modify the script "mkbuildinf.pl" itsel in order to generate a build timestamp based on SOURCE_DATE_EPOCH, if present in the environment.

---
 .../openssl-1.0.2n/reproducible-cflags.patch        | 20 ++++++++++++++++++++
 .../openssl-1.0.2n/reproducible-mkbuildinf.patch    | 21 +++++++++++++++++++++
 meta/recipes-connectivity/openssl/openssl10.inc     |  3 +++
 meta/recipes-connectivity/openssl/openssl_1.0.2n.bb |  5 +++++
 4 files changed, 49 insertions(+)
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-cflags.patch
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-mkbuildinf.patch
meta/recipes-connectivity/openssl/openssl10.inc +0 -0
index 02a0e16..0598195 100644

meta/recipes-connectivity/openssl/openssl10.inc do_configure () { · line 167

Quoted 6 lines
meta/recipes-connectivity/openssl/openssl10.inc +3 -0
@@ -162,6 +162,9 @@ do_configure () {
 
 do_compile_prepend_class-target () {
     sed -i 's/\((OPENSSL=\)".*"/\1"openssl"/' Makefile
+    oe_runmake depend
+       cc_sanitized=`echo "${CC} ${CFLAG}" | sed -e 's,--sysroot=${STAGING_DIR_TARGET},,g' -e 's|${DEBUG_PREFIX_MAP}||g'`
+       oe_runmake CC_INFO="${cc_sanitized}"

Here calls to "oe_runmake depend" and "oe_runmake" are made from the target specific do_compile_prepend(), but the original calls (without sanitised CC_INFO) are then run again from do_compile(), ie:

  do_compile() {
    sed -i 's/\((OPENSSL=\)".*"/\1"openssl"/' Makefile
    oe_runmake depend
    cc_sanitized=`echo ...`
    oe_runmake CC_INFO="${cc_sanitized}"
    oe_runmake depend
    oe_runmake
  }

Is the intention really to run "oe_runmake depend" and "oe_runmake" twice?

Quoted 19 lines
meta/recipes-connectivity/openssl/openssl10.inc +0 -0
 }
 
 do_compile () {
meta/recipes-connectivity/openssl/openssl_1.0.2n.bb +5 -0
index 32444c6..f07289d 100644
@@ -43,6 +43,11 @@ SRC_URI += "file://find.pl;subdir=openssl-${PV}/util/ \
            file://0001-Fix-build-with-clang-using-external-assembler.patch \
            file://0001-openssl-force-soft-link-to-avoid-rare-race.patch \
            "
+
+SRC_URI_append_class-target = "\
+           file://reproducible-cflags.patch \
+           file://reproducible-mkbuildinf.patch \
+           "
 SRC_URI[md5sum] = "13bdc1b1d1ff39b6fd42a255e74676a4"
 SRC_URI[sha256sum] = "370babb75f278c39e0c50e8c4e7493bc0f18db6867478341a832a982fd15a8fe"
 
#2 lore raw

No, not on purpose, the word "prepend" should be taken out.
Although running "make" the second time does no harm (should do nothing, in fact) it needs to be fixed, I'll send in a fix.

Thanks
Juro
________________________________________
From: Andre McCurdy [[email protected]]
Sent: Friday, July 20, 2018 2:08 PM
To: Bystricky, Juro
Cc: OE Core mailing list; Juro Bystricky
Subject: Re: [OE-core] [PATCH] openssl_1.0.2n: improve reproducibility

Quoted 32 lines · Juro Bystricky

Improve reproducible build of:

openssl-staticdev
openssl-dbg
libcrypto

There are two main causes that prevent reproducible build, both related to the generated file "buildinf.h":

1. "buildinf.h" contains build host CFLAGS, containing various build host references. We need to pass sanitized CFLAGS to the script generating this file ("mkbuildinf.pl". )

2. We also need to modify the script "mkbuildinf.pl" itsel in order to generate a build timestamp based on SOURCE_DATE_EPOCH, if present in the environment.

---
 .../openssl-1.0.2n/reproducible-cflags.patch        | 20 ++++++++++++++++++++
 .../openssl-1.0.2n/reproducible-mkbuildinf.patch    | 21 +++++++++++++++++++++
 meta/recipes-connectivity/openssl/openssl10.inc     |  3 +++
 meta/recipes-connectivity/openssl/openssl_1.0.2n.bb |  5 +++++
 4 files changed, 49 insertions(+)
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-cflags.patch
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-mkbuildinf.patch
meta/recipes-connectivity/openssl/openssl10.inc +0 -0
index 02a0e16..0598195 100644

meta/recipes-connectivity/openssl/openssl10.inc do_configure () { · line 167

Quoted 6 lines
meta/recipes-connectivity/openssl/openssl10.inc +3 -0
@@ -162,6 +162,9 @@ do_configure () {
 
 do_compile_prepend_class-target () {
     sed -i 's/\((OPENSSL=\)".*"/\1"openssl"/' Makefile
+    oe_runmake depend
+       cc_sanitized=`echo "${CC} ${CFLAG}" | sed -e 's,--sysroot=${STAGING_DIR_TARGET},,g' -e 's|${DEBUG_PREFIX_MAP}||g'`
+       oe_runmake CC_INFO="${cc_sanitized}"

Here calls to "oe_runmake depend" and "oe_runmake" are made from the target specific do_compile_prepend(), but the original calls (without sanitised CC_INFO) are then run again from do_compile(), ie:

  do_compile() {
    sed -i 's/\((OPENSSL=\)".*"/\1"openssl"/' Makefile
    oe_runmake depend
    cc_sanitized=`echo ...`
    oe_runmake CC_INFO="${cc_sanitized}"
    oe_runmake depend
    oe_runmake
  }

Is the intention really to run "oe_runmake depend" and "oe_runmake" twice?

Quoted 19 lines
meta/recipes-connectivity/openssl/openssl10.inc +0 -0
 }
 
 do_compile () {
meta/recipes-connectivity/openssl/openssl_1.0.2n.bb +5 -0
index 32444c6..f07289d 100644
@@ -43,6 +43,11 @@ SRC_URI += "file://find.pl;subdir=openssl-${PV}/util/ \
            file://0001-Fix-build-with-clang-using-external-assembler.patch \
            file://0001-openssl-force-soft-link-to-avoid-rare-race.patch \
            "
+
+SRC_URI_append_class-target = "\
+           file://reproducible-cflags.patch \
+           file://reproducible-mkbuildinf.patch \
+           "
 SRC_URI[md5sum] = "13bdc1b1d1ff39b6fd42a255e74676a4"
 SRC_URI[sha256sum] = "370babb75f278c39e0c50e8c4e7493bc0f18db6867478341a832a982fd15a8fe"
 
#3 lore raw
Quoted 3 lines · Juro

No, not on purpose, the word "prepend" should be taken out.
Although running "make" the second time does no harm (should do nothing, in fact) it needs to be fixed, I'll send in a fix.

I have a fix too, as part of a series of other minor openssl recipe fixes. So maybe you could review my fix when it's sent rather than working on your own version? Up to you.

Quoted 84 lines

Thanks
Juro
________________________________________
From: Andre McCurdy [[email protected]]
Sent: Friday, July 20, 2018 2:08 PM
To: Bystricky, Juro
Cc: OE Core mailing list; Juro Bystricky
Subject: Re: [OE-core] [PATCH] openssl_1.0.2n: improve reproducibility

Quoted 32 lines · Juro Bystricky

Improve reproducible build of:

openssl-staticdev
openssl-dbg
libcrypto

There are two main causes that prevent reproducible build, both related to the generated file "buildinf.h":

1. "buildinf.h" contains build host CFLAGS, containing various build host references. We need to pass sanitized CFLAGS to the script generating this file ("mkbuildinf.pl". )

2. We also need to modify the script "mkbuildinf.pl" itsel in order to generate a build timestamp based on SOURCE_DATE_EPOCH, if present in the environment.

---
 .../openssl-1.0.2n/reproducible-cflags.patch        | 20 ++++++++++++++++++++
 .../openssl-1.0.2n/reproducible-mkbuildinf.patch    | 21 +++++++++++++++++++++
 meta/recipes-connectivity/openssl/openssl10.inc     |  3 +++
 meta/recipes-connectivity/openssl/openssl_1.0.2n.bb |  5 +++++
 4 files changed, 49 insertions(+)
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-cflags.patch
 create mode 100644 meta/recipes-connectivity/openssl/openssl-1.0.2n/reproducible-mkbuildinf.patch
meta/recipes-connectivity/openssl/openssl10.inc +0 -0
index 02a0e16..0598195 100644

meta/recipes-connectivity/openssl/openssl10.inc do_configure () { · line 167

Quoted 6 lines
meta/recipes-connectivity/openssl/openssl10.inc +3 -0
@@ -162,6 +162,9 @@ do_configure () {
 
 do_compile_prepend_class-target () {
     sed -i 's/\((OPENSSL=\)".*"/\1"openssl"/' Makefile
+    oe_runmake depend
+       cc_sanitized=`echo "${CC} ${CFLAG}" | sed -e 's,--sysroot=${STAGING_DIR_TARGET},,g' -e 's|${DEBUG_PREFIX_MAP}||g'`
+       oe_runmake CC_INFO="${cc_sanitized}"

Here calls to "oe_runmake depend" and "oe_runmake" are made from the target specific do_compile_prepend(), but the original calls (without sanitised CC_INFO) are then run again from do_compile(), ie:

  do_compile() {
    sed -i 's/\((OPENSSL=\)".*"/\1"openssl"/' Makefile
    oe_runmake depend
    cc_sanitized=`echo ...`
    oe_runmake CC_INFO="${cc_sanitized}"
    oe_runmake depend
    oe_runmake
  }

Is the intention really to run "oe_runmake depend" and "oe_runmake" twice?

Quoted 19 lines
meta/recipes-connectivity/openssl/openssl10.inc +0 -0
 }
 
 do_compile () {
meta/recipes-connectivity/openssl/openssl_1.0.2n.bb +5 -0
index 32444c6..f07289d 100644
@@ -43,6 +43,11 @@ SRC_URI += "file://find.pl;subdir=openssl-${PV}/util/ \
            file://0001-Fix-build-with-clang-using-external-assembler.patch \
            file://0001-openssl-force-soft-link-to-avoid-rare-race.patch \
            "
+
+SRC_URI_append_class-target = "\
+           file://reproducible-cflags.patch \
+           file://reproducible-mkbuildinf.patch \
+           "
 SRC_URI[md5sum] = "13bdc1b1d1ff39b6fd42a255e74676a4"
 SRC_URI[sha256sum] = "370babb75f278c39e0c50e8c4e7493bc0f18db6867478341a832a982fd15a8fe"