Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Korsgaard <peter@korsgaard.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v5 01/19] reproducible: fix DATE/TIME macros in toolchain-wrapper
Date: Tue, 07 Feb 2017 21:41:41 +0100	[thread overview]
Message-ID: <87k291rawq.fsf@dell.be.48ers.dk> (raw)
In-Reply-To: <1482241596-31688-2-git-send-email-jezz@sysmic.org> ("Jérôme Pouiller"'s message of "Tue, 20 Dec 2016 14:46:18 +0100")

>>>>> "J?r?me" == J?r?me Pouiller <jezz@sysmic.org> writes:

 > The use __DATE__ and __TIME__ are one of most common sources of

The use of.

 > non-reproducible binaries. In order to fix that, gcc begin to support
 > SOURCE_DATE_EPOCH variable. This patch take advantage of toolchain-wrapper
 > to provide support of SOURCE_DATE_EPOCH to older gcc versions.

 > Function get_source_date_epoch() come directly from gcc git.

 > This work was sponsored by `BA Robotic Systems'.

 > Signed-off-by: J?r?me Pouiller <jezz@sysmic.org>
 > ---

 > Notes:
 >     v3:
 >       - Handle $SOURCE_DATE_EPOCH at runtime (Thomas)
 >     v2:
 >       - Overload __TIME__ and __DATE__ instead of patching gcc (Thomas)

 >  toolchain/toolchain-wrapper.c | 74 ++++++++++++++++++++++++++++++++++++++++++-
 >  1 file changed, 73 insertions(+), 1 deletion(-)

 > diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c
 > index d59629b..6150574 100644
 > --- a/toolchain/toolchain-wrapper.c
 > +++ b/toolchain/toolchain-wrapper.c
 > @@ -22,12 +22,17 @@
 >  #include <unistd.h>
 >  #include <stdlib.h>
 >  #include <errno.h>
 > +#include <time.h>
 
 >  #ifdef BR_CCACHE
 >  static char ccache_path[PATH_MAX];
 >  #endif
 >  static char path[PATH_MAX];
 >  static char sysroot[PATH_MAX];
 > +// strlen("-D__TIME__=\"HH:MM:SS\"") + 1 = 22
 > +static char source_time[22];
 > +// strlen("-D__DATE__=\"MMM DD YYYY\"") + 1 = 25
 > +static char source_date[25];

It is nicer to simply use sizeof on that string, E.G.:

static char source_time[sizeof("-D__TIME__=\"HH:MM:SS\"")];

Then the comment can be dropped and the comment never gets out of sync
with the size.


 >  /**
 >   * GCC errors out with certain combinations of arguments (examples are
 > @@ -39,8 +44,11 @@ static char sysroot[PATH_MAX];
 >   * 	-mfloat-abi=
 >   * 	-march=
 >   * 	-mcpu=
 > + * 	-D__TIME__=
 > + * 	-D__DATE__=
 > + * 	-Wno-builtin-macro-redefined
 >   */
 > -#define EXCLUSIVE_ARGS	3
 > +#define EXCLUSIVE_ARGS	6
 
 >  static char *predef_args[] = {
 >  #ifdef BR_CCACHE
 > @@ -139,6 +147,47 @@ static void check_unsafe_path(const char *arg,
 >  	}
 >  }
 
 > +/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
 > + * timestamp to replace embedded current dates to get reproducible
 > + * results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.
 > + */
 > +time_t get_source_date_epoch()

This should be static.


> +{
 > +	char *source_date_epoch;
 > +	long long epoch;
 > +	char *endptr;
 > +
 > +	source_date_epoch = getenv("SOURCE_DATE_EPOCH");
 > +	if (!source_date_epoch)
 > +		return (time_t) -1;
 > +
 > +	errno = 0;
 > +	epoch = strtoll (source_date_epoch, &endptr, 10);

NIT: No space between strtoll and '('.

> +	if ((errno == ERANGE && (epoch == LLONG_MAX || epoch == LLONG_MIN))
 > +			|| (errno != 0 && epoch == 0)) {
 > +		fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
 > +				"strtoll: %s\n", strerror(errno));
 > +		exit(2);
 > +	}
 > +	if (endptr == source_date_epoch) {
 > +		fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
 > +				"no digits were found: %s\n", endptr);
 > +		exit(2);
 > +	}
 > +	if (*endptr != '\0') {
 > +		fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
 > +				"trailing garbage: %s\n", endptr);
 > +		exit(2);
 > +	}
 > +	if (epoch < 0) {
 > +		fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
 > +				"value must be nonnegative: %lld \n", epoch);
 > +		exit(2);
 > +	}

I'm not sure this detailed error handling is really needed, but OK.

Committed, thanks.

-- 
Bye, Peter Korsgaard

  parent reply	other threads:[~2017-02-07 20:41 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-20 13:46 [Buildroot] [PATCH v5 00/19] Reproducible builds Jérôme Pouiller
2016-12-20 13:46 ` [Buildroot] [PATCH v5 01/19] reproducible: fix DATE/TIME macros in toolchain-wrapper Jérôme Pouiller
2017-02-07 14:32   ` Samuel Martin
2017-02-07 20:41   ` Peter Korsgaard [this message]
2017-02-08 10:07     ` Jérôme Pouiller
2017-02-08 12:18       ` Peter Korsgaard
2017-02-08 12:20       ` Thomas Petazzoni
2017-02-08 13:46         ` Peter Korsgaard
2017-02-08 14:11           ` Jérôme Pouiller
2017-02-08 14:29             ` Peter Korsgaard
2017-02-08 14:31               ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 02/19] fakedate: new package Jérôme Pouiller
2017-02-07 14:32   ` Samuel Martin
2017-02-07 20:49   ` Peter Korsgaard
2017-02-08 14:10     ` Jérôme Pouiller
2017-02-07 21:31   ` Peter Korsgaard
2016-12-20 13:46 ` [Buildroot] [PATCH v5 03/19] core: do not reset DEPENDENCIES_HOST_PREREQ in dependencies.mk Jérôme Pouiller
2017-01-28  7:35   ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 04/19] reproducible: enable fakedate Jérôme Pouiller
2017-02-07 14:32   ` Samuel Martin
2017-02-07 22:01   ` Peter Korsgaard
2016-12-20 13:46 ` [Buildroot] [PATCH v5 05/19] pycompile: allow to force compilation Jérôme Pouiller
2017-02-07 14:51   ` Samuel Martin
2017-03-20 22:29   ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 06/19] python2: generate reproducible .pyc Jérôme Pouiller
2017-02-07 14:51   ` Samuel Martin
2017-03-20 22:30   ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 07/19] python3: " Jérôme Pouiller
2017-02-07 14:51   ` Samuel Martin
2017-03-20 22:31   ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 08/19] reproducible: try to detect most common errors Jérôme Pouiller
2017-02-07 14:52   ` Samuel Martin
2017-04-01 14:50   ` Thomas Petazzoni
2017-04-01 21:13     ` Yann E. MORIN
2017-04-01 21:48       ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 09/19] python2: remove full path from .pyc Jérôme Pouiller
2017-02-07 14:52   ` Samuel Martin
2017-04-01 16:37   ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 10/19] python3: " Jérôme Pouiller
2017-02-07 14:52   ` Samuel Martin
2017-04-01 16:37   ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 11/19] infra-libtool: pass sysroot information to libtool Jérôme Pouiller
2017-03-18 17:21   ` Arnout Vandecappelle
2017-03-20 21:52   ` Thomas Petazzoni
2017-03-21 23:57     ` Arnout Vandecappelle
2017-03-22  8:14       ` Thomas Petazzoni
2017-03-22  9:07         ` Arnout Vandecappelle
2017-03-22  9:20         ` Jérôme Pouiller
2017-03-22 10:05           ` Arnout Vandecappelle
2017-03-22 21:28             ` Arnout Vandecappelle
2017-03-22 21:40               ` Thomas Petazzoni
2017-04-01 16:39     ` Thomas Petazzoni
2016-12-20 13:46 ` [Buildroot] [PATCH v5 12/19] infra-libtool: no longer prepend STAGING_DIR to libdir Jérôme Pouiller
2017-03-18 15:37   ` Arnout Vandecappelle
2017-03-22 10:21     ` Jérôme Pouiller
2017-03-22 11:19       ` Arnout Vandecappelle
2017-03-18 17:22   ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 13/19] infra-libtool: correctly prefix $libdir with $STAGING_DIR Jérôme Pouiller
2017-03-18 17:24   ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 14/19] infra-libtool: drop original $libdir (i.e. /usr/lib) from library paths Jérôme Pouiller
2017-03-18 17:31   ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 15/19] infra-libtool: relink binaries on install Jérôme Pouiller
2017-03-18 17:36   ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 16/19] infra-libtool: inform libtool that STAGING_DIR is reachable at runtime Jérôme Pouiller
2017-02-07 15:26   ` Samuel Martin
2017-03-18 17:39   ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 17/19] infra-libtool: no longer disable install directory sanity check Jérôme Pouiller
2017-03-18 17:41   ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 18/19] infra-libtool: remove workaround for calls without `--tag' Jérôme Pouiller
2017-03-18 17:45   ` Arnout Vandecappelle
2016-12-20 13:46 ` [Buildroot] [PATCH v5 19/19] infra-libtool: no longer force sys_lib_search_path Jérôme Pouiller
2017-03-18 17:47   ` Arnout Vandecappelle
2017-02-21  8:17 ` [Buildroot] [PATCH v5 00/19] Reproducible builds Jérôme Pouiller
2017-03-18 16:33   ` Arnout Vandecappelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k291rawq.fsf@dell.be.48ers.dk \
    --to=peter@korsgaard.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox