public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Facilitate deterministic pe executables between linker invocations
@ 2013-10-01 17:40 Cory Fields
  2013-10-09 19:08 ` Cory Fields
  2013-10-10 14:11 ` nick clifton
  0 siblings, 2 replies; 10+ messages in thread
From: Cory Fields @ 2013-10-01 17:40 UTC (permalink / raw)
  To: binutils; +Cc: Cory Fields

I'm not sure if this has been discussed before, or exactly how to propose this
behavioral change, so I'm submitting this patch with the goal of starting a
discussion.

It's currently not possible to create two byte-exact exe's due to the timestamp
in the PE header. This does not match elf behavior, where successive runs can
produce the exact same binary.

Only a tiny change is needed to avoid the random result. An
(entirely arbitrary) value of 1 is hard-coded rather than using the current
timestamp.

Is there a historical reason for the non-deterministic behavior? If so, would
it be reasonable to add an option similar to enable-deterministic-archives to
disable it?

Before:
$ ~/dev/binutils/ld/ld-new -m i386pe -o test.exe <snip>
$ md5sum test.exe
d88f78cff7e0f6cf50f4be546c2b4189  test.exe

$ ~/dev/binutils/ld/ld-new -m i386pe -o test.exe <snip>
$ md5sum test.exe
7287892f03f067940b508db830cf85ac  test.exe

After:
$ ~/dev/binutils/ld/ld-new -m i386pe -o test.exe <snip>
$ md5sum test.exe
fa0bf1a326b332f72f270ae060fa758c  test.exe

$ ~/dev/binutils/ld/ld-new -m i386pe -o test.exe <snip>
$ md5sum test.exe
fa0bf1a326b332f72f270ae060fa758c  test.exe

binutils/Changelog
10-01-2013  Cory Fields  <cory@coryfields.com>
    * bfd/peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Use a constant rather
      than a real timestamp in the PE header to ensure deterministic link
      results when invoked with identical inputs.
---
 bfd/peXXigen.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index d0f7a96..2d9f93c 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -793,7 +793,10 @@ _bfd_XXi_only_swap_filehdr_out (bfd * abfd, void * in, void * out)
   H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic);
   H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns);
 
-  H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
+  /* use a constant for the timestamp to ensure deterministic results with
+     identical inputs */
+  H_PUT_32 (abfd, 1, filehdr_out->f_timdat);
+
   PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
 		      filehdr_out->f_symptr);
   H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms);
-- 
1.8.1.2

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-11-20 17:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-01 17:40 [PATCH] Facilitate deterministic pe executables between linker invocations Cory Fields
2013-10-09 19:08 ` Cory Fields
2013-10-10 14:11 ` nick clifton
2013-10-10 14:40   ` Cory Fields
2013-10-10 18:48     ` Cory Fields
2013-10-11 11:13       ` nick clifton
2013-11-19  0:34         ` Cory Fields
2013-11-20 17:08           ` Cory Fields
2013-11-20 17:56             ` nick clifton
2013-11-20 20:18               ` Cory Fields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).