[PATCH] ar: fix deterministic usage of ar with mri scripts

Cory Fields cory@coryfields.com
Sun Sep 29 06:24:00 GMT 2013


This non-deterministic behavior was observed when building Qt 4.8.5.
The patch below provides (what I believe to be) the expected behavior.

Before:
  $ ~/dev/binutils/binutils/ar -DM < object_script.libQtCore.Release
  $ md5sum ../../lib/libQtCore.a
  2f3b883bc11350a53257ee7438862a6c  ../../lib/libQtCore.a

  $ ~/dev/binutils/binutils/ar -DM < object_script.libQtCore.Release
  $ md5sum ../../lib/libQtCore.a
  73d6138790896193795e4fdbf053c954  ../../lib/libQtCore.a

After:
  $ ~/dev/binutils/binutils/ar -DM < object_script.libQtCore.Release
    md5sum ../../lib/libQtCore.a
  96300bc8954d36043bc4ca9a7442a0c2  ../../lib/libQtCore.a

  $ ~/dev/binutils/binutils/ar -DM < object_script.libQtCore.Release
    md5sum ../../lib/libQtCore.a
  96300bc8954d36043bc4ca9a7442a0c2  ../../lib/libQtCore.a

The unspecified default (as set by --enable-deterministic-archives) is
respected as well.

I'm unsure if any documentation updates are needed here. By my reading of the
current docs, -M now behaves as i would expect it to wrt -D, -U, and
--enable-deterministic-archives.

This is my first binutils submission, please let me know if there's anything
wrong/missing.

binutils/Changelog
09-29-2013  Cory Fields  <cory@coryfields.com>

  * arsup.c: respect the deterministic setting when reading from an mri script.
  * ar.c: set the default deterministic mode when reading from an mri script
---
 binutils/ar.c    | 1 +
 binutils/arsup.c | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/binutils/ar.c b/binutils/ar.c
index 987b46c..a11ed15 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -737,6 +737,7 @@ main (int argc, char **argv)
 
   if (mri_mode)
     {
+      default_deterministic ();
       mri_emul ();
     }
   else
diff --git a/binutils/arsup.c b/binutils/arsup.c
index 9ddc55d..5e8a40a 100644
--- a/binutils/arsup.c
+++ b/binutils/arsup.c
@@ -39,6 +39,7 @@ static void ar_directory_doer (bfd *, bfd *);
 static void ar_addlib_doer (bfd *, bfd *);
 
 extern int verbose;
+extern int deterministic;
 
 static bfd *obfd;
 static char *real_name;
@@ -334,6 +335,9 @@ ar_save (void)
     {
       char *ofilename = xstrdup (bfd_get_filename (obfd));
 
+      if (deterministic > 0)
+        obfd->flags |= BFD_DETERMINISTIC_OUTPUT;
+
       bfd_close (obfd);
 
       smart_rename (ofilename, real_name, 0);
-- 
1.8.1.2



More information about the Binutils mailing list