Message ID | 1479460224-6119-3-git-send-email-jezz@sysmic.org |
---|---|
State | Superseded |
Headers | show |
Hello, On Fri, 18 Nov 2016 10:10:11 +0100, Jérôme Pouiller wrote: > +ifeq ($(BR2_REPRODUCIBLE),y) > +TOOLCHAIN_WRAPPER_ARGS += -DBR_REPRODUCIBLE_TIME="\"\\\"`date -d @$(SOURCE_DATE_EPOCH) "+%T"`\\\"\"" > +TOOLCHAIN_WRAPPER_ARGS += -DBR_REPRODUCIBLE_DATE="\"\\\"`date -d @$(SOURCE_DATE_EPOCH) "+%b %e %Y"`\\\"\"" > +endif Do we need to encode the dates in the wrapper, or should we have the wrapper read at runtime the SOURCE_DATE_EPOCH environment variable? I believe the latter is simpler, and matches better what future gcc versions will do. The only drawback is that people using the toolchain (through the wrapper) outside of Buildroot will not benefit from the "fixed" date, unless they define SOURCE_DATE_EPOCH in their environment. But I believe this is OK, because this is anyway the behavior that they would get by using the newest gcc versions that have this feature. It would make all the quoting mess a bit simpler :) Best regards, Thomas
On 2016-11-18 12:37, Thomas Petazzoni wrote: > On Fri, 18 Nov 2016 10:10:11 +0100, Jérôme Pouiller wrote: > >> +ifeq ($(BR2_REPRODUCIBLE),y) >> +TOOLCHAIN_WRAPPER_ARGS += -DBR_REPRODUCIBLE_TIME="\"\\\"`date -d >> @$(SOURCE_DATE_EPOCH) "+%T"`\\\"\"" >> +TOOLCHAIN_WRAPPER_ARGS += -DBR_REPRODUCIBLE_DATE="\"\\\"`date -d >> @$(SOURCE_DATE_EPOCH) "+%b %e %Y"`\\\"\"" >> +endif > > Do we need to encode the dates in the wrapper, or should we have the > wrapper read at runtime the SOURCE_DATE_EPOCH environment variable? > > I believe the latter is simpler, and matches better what future gcc > versions will do. > > The only drawback is that people using the toolchain (through the > wrapper) outside of Buildroot will not benefit from the "fixed" date, > unless they define SOURCE_DATE_EPOCH in their environment. But I > believe this is OK, because this is anyway the behavior that they would > get by using the newest gcc versions that have this feature. Agreed. -- Jérôme Pouiller
diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c index 925d013..28709ec 100644 --- a/toolchain/toolchain-wrapper.c +++ b/toolchain/toolchain-wrapper.c @@ -75,6 +75,15 @@ static char *predef_args[] = { #if defined(BR_MIPS_TARGET_BIG_ENDIAN) || defined(BR_ARC_TARGET_BIG_ENDIAN) "-EB", #endif +#if defined(BR_REPRODUCIBLE_TIME) || defined(BR_REPRODUCIBLE_DATE) + "-Wno-builtin-macro-redefined", +#endif +#ifdef BR_REPRODUCIBLE_TIME + "-D__TIME__=" BR_REPRODUCIBLE_TIME, +#endif +#ifdef BR_REPRODUCIBLE_DATE + "-D__DATE__=" BR_REPRODUCIBLE_DATE, +#endif #ifdef BR_ADDITIONAL_CFLAGS BR_ADDITIONAL_CFLAGS #endif diff --git a/toolchain/toolchain-wrapper.mk b/toolchain/toolchain-wrapper.mk index e7aa5fb..7067134 100644 --- a/toolchain/toolchain-wrapper.mk +++ b/toolchain/toolchain-wrapper.mk @@ -30,6 +30,11 @@ ifeq ($(BR2_CCACHE_USE_BASEDIR),y) TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_BASEDIR='"$(BASE_DIR)"' endif +ifeq ($(BR2_REPRODUCIBLE),y) +TOOLCHAIN_WRAPPER_ARGS += -DBR_REPRODUCIBLE_TIME="\"\\\"`date -d @$(SOURCE_DATE_EPOCH) "+%T"`\\\"\"" +TOOLCHAIN_WRAPPER_ARGS += -DBR_REPRODUCIBLE_DATE="\"\\\"`date -d @$(SOURCE_DATE_EPOCH) "+%b %e %Y"`\\\"\"" +endif + define TOOLCHAIN_WRAPPER_BUILD $(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \ -s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \
The use __DATE__ and __TIME__ are one of most common sources of non-reproducible binaries. We take advantage of toolchain-wrapper to fix these macros. Notice this workaround will be useless this next gcc versions since it will include suport for SOURCE_DATE_EPOCH variable. Note: quoting of $(TOOLCHAIN_WRAPPER_ARGS) is a mess, but I did not find easier way to do (without involving `$(shell ...)') This work was sponsored by `BA Robotic Systems'. Signed-off-by: Jérôme Pouiller <jezz@sysmic.org> --- toolchain/toolchain-wrapper.c | 9 +++++++++ toolchain/toolchain-wrapper.mk | 5 +++++ 2 files changed, 14 insertions(+)