From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from stravinsky.debian.org (stravinsky.debian.org [IPv6:2001:41b8:202:deb::311:108]) by sourceware.org (Postfix) with ESMTPS id B6EC53858C53 for ; Thu, 20 Jul 2023 23:15:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6EC53858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=debian.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Message-ID:Date:To:Cc:From:Subject: References:In-Reply-To:MIME-Version:Content-Type:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sZaZVxwVwm1RJ6CsQkbRBmOZs7wKxgbzJOjeoypupRY=; b=ClvFH/QXvf7ZnX5WrkLtZ91hCM KebhDug20F2qU45k8NvlIJJmpVCSyNghp2W3VQR8hDWzyp0ermJv7teDEyjfn6ILqw/EtiKy9Qehj qLCJN1jYBBH2FwFYWud2+Ac8GlXSiJ38f81qelgHZryPl2E95rxqjqIzW9wB5kFhiWQ+uZhl5FO8O 9nUZzuiu+tk5rlJ7UJtZ8a73qc1VQV8b8/Qz3sQvGR6U+E8z83GY+91co6YVjQU6CE9jPaBXlulSc aa9YtzMTf3P2uqZm/DKQovDCrhnzbooxEnf0dfBG8uWQETcIDzCibXTfh4jTBtIab/ZQyNCptEnFu OATfUNog==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1qMcrT-002mbR-4Y; Thu, 20 Jul 2023 23:15:07 +0000 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="===============2456889379327512358==" MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <89d6a4a8-dc8d-c384-9fbe-2b6daa6b015e@redhat.com> References: <168983055254.2785030.15255872242112800439@localhost> <89d6a4a8-dc8d-c384-9fbe-2b6daa6b015e@redhat.com> Subject: Re: [patch] objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unreproducible From: Johannes Schauer Marin Rodrigues Cc: Binutils To: Nick Clifton Date: Fri, 21 Jul 2023 01:15:05 +0200 Message-ID: <168989490573.2785030.15391778939927525917@localhost> User-Agent: alot/0.10 X-Debian-User: josch X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --===============2456889379327512358== Content-Type: multipart/mixed; boundary="===============6150603615862681589==" MIME-Version: 1.0 --===============6150603615862681589== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Hi, Quoting Nick Clifton (2023-07-20 13:08:35) > >> * Updating the description of the --timestamp command line option = in > >> ld/ld.texi to mention that if SOURCE_DATE_EPOCH is defined in the > >> environment then this will be used instead of the current time. > > I'm a bit confused here. I'm fixing objcopy but am supposed to edit ld/= ld.texi? > Ah - I think that we were both confused. You see the code that you are p= atching > in bfd/peXXigen.c is used by both the linker and objcopy. I was tracking= down > where the timestamp field in the pe_data_type structure was set, and I go= t diverted > to ld/emultempl/pe.em, which is why I thought about updating the linker d= ocumentation. >=20 > So anyway, both the linker documentation *and* the objcopy documentation = need to > be updated... where would you put it in the objcopy docs? I put it to the --deterministic-libraries option because that's the option I was consulting when I wanted to know how to make the timestamp reproducible. > > Also, there is another instance of something calling time(0) in ld/pe-d= ll.c. I > > don't know what that does. Does it need fixing as well? > Good catch. Yes that will need the same kind of change as peXXigen.c. Done. > If you could resubmit your patch (to the list) Whoops, seems my last mail didn't have the list in CC. > with these changes and accompanied > by a DCO then I will approve and apply it. With DCO you mean this, right? https://gcc.gnu.org/dco.html I agree to the Developer's Certificate of Origin (version 1.1 or later) and added a Signed-off-by to my commit accordingly. If only minor problems remain with the patch, feel free to correct those, depending on whether you'd spend less time with amending my patch or writing me an email about the issues you found. :) Thanks! cheers, josch --===============6150603615862681589== Content-Type: text/x-diff; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-bfd-peXXigen.c-respect-SOURCE_DATE_EPOCH-environment.patch"; maxlinelen="78" >From bdbdaf4f9dace4ba60cb3debe9afc876a6567ffa Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Thu, 20 Jul 2023 07:11:44 +0200 Subject: [PATCH] bfd/peXXigen.c: respect SOURCE_DATE_EPOCH environment variable Instead of obtaining the current time via time(0), use the seconds since Unix epoch stored in the SOURCE_DATE_EPOCH environment variable to create a reproducible timestamp. Signed-off-by: Johannes Schauer Marin Rodrigues --- bfd/peXXigen.c | 11 ++++++++++- binutils/doc/binutils.texi | 4 ++++ ld/ld.texi | 5 ++++- ld/pe-dll.c | 11 ++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index da53f349dd0..7a5e5961162 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -838,7 +838,16 @@ _bfd_XXi_only_swap_filehdr_out (bfd * abfd, void * in,= void * out) /* Use a real timestamp by default, unless the no-insert-timestamp option was chosen. */ if ((pe_data (abfd)->timestamp) =3D=3D -1) - H_PUT_32 (abfd, time (0), filehdr_out->f_timdat); + { + time_t now; + char *source_date_epoch; + source_date_epoch =3D getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch) + now =3D (time_t)strtoll(source_date_epoch, NULL, 10); + else + now =3D time(NULL); + H_PUT_32 (abfd, now, filehdr_out->f_timdat); + } else H_PUT_32 (abfd, pe_data (abfd)->timestamp, filehdr_out->f_timdat); =20 diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 309bedf6110..ab974e1d304 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -4692,6 +4692,10 @@ When creating output libraries in response to either= the the value of zero for any timestamps, user ids and group ids created (@option{--deterministic-libraries}) or the actual timestamps, user ids and group ids (@option{--non-deterministic-libraries}). +Instead of inserting a zero value for the timestamp, +an arbitrary reproducible timestamp can be inserted by setting the +@code{SOURCE_DATE_EPOCH} environment variable to the desired number of +seconds since Unix epoch. =20 @item --export-all-symbols Treat all global and weak defined symbols found in the input object diff --git a/ld/ld.texi b/ld/ld.texi index 75e82eda004..02ace7778d9 100644 --- a/ld/ld.texi +++ b/ld/ld.texi @@ -3569,7 +3569,10 @@ will result in slightly different images being produ= ced each time the same sources are linked. The option @option{--no-insert-timestamp} can be used to insert a zero value for the timestamp, this ensuring that binaries produced from identical sources will compare -identically. +identically. Instead of inserting a zero value for the timestamp, +an arbitrary reproducible timestamp can be inserted by setting the +@code{SOURCE_DATE_EPOCH} environment variable to the desired number of +seconds since Unix epoch. =20 @kindex --enable-reloc-section @item --enable-reloc-section diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 02e03d16948..e1465d4d115 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -1231,7 +1231,16 @@ fill_edata (bfd *abfd, struct bfd_link_info *info AT= TRIBUTE_UNUSED) memset (edata_d, 0, edata_sz); =20 if (pe_data (abfd)->timestamp =3D=3D -1) - H_PUT_32 (abfd, time (0), edata_d + 4); + { + time_t now; + char *source_date_epoch; + source_date_epoch =3D getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch) + now =3D (time_t)strtoll(source_date_epoch, NULL, 10); + else + now =3D time(NULL); + H_PUT_32 (abfd, now, edata_d + 4); + } else H_PUT_32 (abfd, pe_data (abfd)->timestamp, edata_d + 4); =20 --=20 2.40.0 --===============6150603615862681589==-- --===============2456889379327512358== MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Description: signature Content-Type: application/pgp-signature; name="signature.asc"; charset="us-ascii" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEElFhU6KL81LF4wVq58sulx4+9g+EFAmS5v/YACgkQ8sulx4+9 g+EJLA/+IbEAZL6siT+skoitgEPhNiuUzIDp1ZjL7oYbGKhygbfCoNZ4JTFeqedh 9homL9b7BD8AAGjmjJ8q0bI3yVkmIl3s8ZrGvrjGQfx245u2Ej2+JDoxv1PqP+b+ md2FqmU0yT7pocwaihYwnHUSNGCSRW1jkV4jQ1yPgdn1h8i32l5ijghoMOft2FIi +nG7teAOPmaMD+X//zKtbGlKL4XdOgfRwRx9EYpqwrdv6+X+n0l9/w9qWKB1gWiw sC3jTO4c/WWclKG3Dcp2I2Jobzm4HNCocigas3E69kuLPmm0vXw9b8opP0dZFkpl zWECHspvn+LuJQGAo56C/bMiSIxIYQ6uHIoMM6kO5zWHpLpQs7b913W67ZFWBS/T uc+yNVD57XBKwvgghj9IX+ePYT7hFSPJPvuhuzcikBU06ZeWGg5iuUGs4o8cGbF4 DcUoC2stdhJ7IbR7Czo+6olqwNKhAAyqEFBL9MUHecCUgrw4xd6fjHi1J5bWETUP 2lhoe5QWQJPB6AeOsYVrFQXMo7dg4Rlf1zO+zmpJLvfIJxBEf3kE6N319zgF5Jvg vGRR5iUmbWTOcWNRlos/JXVGRItlRGFxSE/baJPDxSTxCaqpHcTctBelVjMMnahZ dS9RbiO3unxfU75KJIxiTeOymOBKt5mcQr99WTPwgZKr7COwaLg= =a5wg -----END PGP SIGNATURE----- --===============2456889379327512358==--