aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorChris Demetriou <cgd@google.com>2009-03-11 04:36:40 +0000
committerChris Demetriou <cgd@google.com>2009-03-11 04:36:40 +0000
commit36e4dce69dd23bea9ea2258dea35f034b6d6351c (patch)
treeafd2a795b17ed76d0f5353a5ed752bc483c1a929 /bfd
parenta07dbd482b9c6d2c8e0e60409bfbb47f6f67c013 (diff)
downloadgdb-36e4dce69dd23bea9ea2258dea35f034b6d6351c.zip
gdb-36e4dce69dd23bea9ea2258dea35f034b6d6351c.tar.gz
gdb-36e4dce69dd23bea9ea2258dea35f034b6d6351c.tar.bz2
[bfd/ChangeLog]
2009-03-11 Chris Demetriou <cgd@google.com> * bfd.c (BFD_DETERMINISTIC_OUTPUT): New flag. * bfd-in2.h: Regenerate. * archive.c (bfd_ar_hdr_from_filesystem): If BFD_DETERMINISTIC_OUTPUT flag is set, use 0 for uid, gid, and timestamp, and use 0644 for file mode. (bsd_write_armap): Likewise. (_bfd_archive_bsd_update_armap_timestamp): If BFD_DETERMINISTIC_OUTPUT flag is set, do nothing. (coff_write_armap): If BFD_DETERMINISTIC_OUTPUT flag is set, use 0 for timestamp. [binutils/ChangeLog] 2009-03-11 Chris Demetriou <cgd@google.com> * ar.c (deterministic): New global variable. (main): Recognize new 'D' option, which enables 'deterministic mode'. (usage): Document new 'D' option. (write_archive): Set BFD_DETERMINISTIC_OUTPUT in output archive's flags if deterministic mode was requested. * doc/binutils.texi (ar): Document deterministic mode ('D' option). [binutils/testsuite/ChangeLog] 2009-03-11 Chris Demetriou <cgd@google.com> * binutils-all/ar.exp (deterministic_archive): New test.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog13
-rw-r--r--bfd/archive.c44
-rw-r--r--bfd/bfd-in2.h5
-rw-r--r--bfd/bfd.c5
4 files changed, 62 insertions, 5 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index eac0087..1a89592 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,16 @@
+2009-03-11 Chris Demetriou <cgd@google.com>
+
+ * bfd.c (BFD_DETERMINISTIC_OUTPUT): New flag.
+ * bfd-in2.h: Regenerate.
+ * archive.c (bfd_ar_hdr_from_filesystem): If BFD_DETERMINISTIC_OUTPUT
+ flag is set, use 0 for uid, gid, and timestamp, and use 0644 for file
+ mode.
+ (bsd_write_armap): Likewise.
+ (_bfd_archive_bsd_update_armap_timestamp): If BFD_DETERMINISTIC_OUTPUT
+ flag is set, do nothing.
+ (coff_write_armap): If BFD_DETERMINISTIC_OUTPUT flag is set, use 0
+ for timestamp.
+
2009-03-11 Ulrich Weigand <uweigand@de.ibm.com>
* elf32-spu.c (find_function_stack_adjust): Handle sf instruction
diff --git a/bfd/archive.c b/bfd/archive.c
index 437a085..5e0fd6b 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -1652,6 +1652,16 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member)
return NULL;
}
+ /* If the caller requested that the BFD generate deterministic output,
+ fake values for modification time, UID, GID, and file mode. */
+ if ((abfd->flags & BFD_DETERMINISTIC_OUTPUT) != 0)
+ {
+ status.st_mtime = 0;
+ status.st_uid = 0;
+ status.st_gid = 0;
+ status.st_mode = 0644;
+ }
+
amt = sizeof (struct ar_hdr) + sizeof (struct areltdata);
ared = bfd_zalloc (abfd, amt);
if (ared == NULL)
@@ -2220,20 +2230,39 @@ bsd_write_armap (bfd *arch,
unsigned int count;
struct ar_hdr hdr;
struct stat statbuf;
+ long uid, gid;
firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG;
stat (arch->filename, &statbuf);
+ if ((arch->flags & BFD_DETERMINISTIC_OUTPUT) == 0)
+ {
+ /* Remember the timestamp, to keep it holy. But fudge it a little. */
+ bfd_ardata (arch)->armap_timestamp = (statbuf.st_mtime
+ + ARMAP_TIME_OFFSET);
+ uid = getuid();
+ gid = getgid();
+ }
+ else
+ {
+ /* If deterministic, we use 0 as the timestamp in the map.
+ Some linkers may require that the archive filesystem modification
+ time is less than (or near to) the archive map timestamp. Those
+ linkers should not be used with deterministic mode. (GNU ld and
+ Gold do not have this restriction.) */
+ bfd_ardata (arch)->armap_timestamp = 0;
+ uid = 0;
+ gid = 0;
+ }
+
memset (&hdr, ' ', sizeof (struct ar_hdr));
memcpy (hdr.ar_name, RANLIBMAG, strlen (RANLIBMAG));
- /* Remember the timestamp, to keep it holy. But fudge it a little. */
- bfd_ardata (arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET;
bfd_ardata (arch)->armap_datepos = (SARMAG
+ offsetof (struct ar_hdr, ar_date[0]));
_bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
bfd_ardata (arch)->armap_timestamp);
- _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", getuid ());
- _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", getgid ());
+ _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", uid);
+ _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", gid);
_bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", mapsize);
memcpy (hdr.ar_fmag, ARFMAG, 2);
if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
@@ -2301,6 +2330,10 @@ _bfd_archive_bsd_update_armap_timestamp (bfd *arch)
struct stat archstat;
struct ar_hdr hdr;
+ /* If creating deterministic archives, just leave the timestamp as-is. */
+ if ((arch->flags & BFD_DETERMINISTIC_OUTPUT) != 0)
+ return TRUE;
+
/* Flush writes, get last-write timestamp from file, and compare it
to the timestamp IN the file. */
bfd_flush (arch);
@@ -2385,7 +2418,8 @@ coff_write_armap (bfd *arch,
_bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld",
mapsize);
_bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
- time (NULL));
+ ((arch->flags & BFD_DETERMINISTIC_OUTPUT) == 0
+ ? time (NULL) : 0));
/* This, at least, is what Intel coff sets the values to. */
_bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", 0);
_bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", 0);
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index e7942c3..7e3defd 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -4769,6 +4769,11 @@ struct bfd
to any input file. */
#define BFD_LINKER_CREATED 0x2000
+ /* This may be set before writing out a BFD to request that it
+ be written using values for UIDs, GIDs, timestamps, etc. that
+ will be consistent from run to run. */
+#define BFD_DETERMINISTIC_OUTPUT 0x4000
+
/* Currently my_archive is tested before adding origin to
anything. I believe that this can become always an add of
origin, with origin set to 0 for non archive files. */
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 847da52..9979ac6 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -145,6 +145,11 @@ CODE_FRAGMENT
. to any input file. *}
.#define BFD_LINKER_CREATED 0x2000
.
+. {* This may be set before writing out a BFD to request that it
+. be written using values for UIDs, GIDs, timestamps, etc. that
+. will be consistent from run to run. *}
+.#define BFD_DETERMINISTIC_OUTPUT 0x4000
+.
. {* Currently my_archive is tested before adding origin to
. anything. I believe that this can become always an add of
. origin, with origin set to 0 for non archive files. *}