diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2017-02-27 07:13:55 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2017-02-27 07:13:55 +0000 |
commit | 696bb10172b558e966ed153baf75fe85f5b59665 (patch) | |
tree | 7bfbd51c903a4caf1ea7129a68d83cd8c03de09e | |
parent | 0980caf195111b6eadb5fc7a50ddc0675fd904fb (diff) |
Implement D and U modifiers to ar; with D the uid/gid/mode/time on the updated
archive members are set to deterministic values. U cancels D. This should
simplify the syspatch work.
Based on a diff by daniel@
ok millert@ deraadt@ kettenis@
-rw-r--r-- | gnu/usr.bin/binutils-2.17/bfd/archive.c | 20 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/bfd/bfd-in.h | 6 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h | 6 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/binutils/ar.c | 18 |
4 files changed, 48 insertions, 2 deletions
diff --git a/gnu/usr.bin/binutils-2.17/bfd/archive.c b/gnu/usr.bin/binutils-2.17/bfd/archive.c index cb8b0c1d9f1..1831d23ce3f 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/archive.c +++ b/gnu/usr.bin/binutils-2.17/bfd/archive.c @@ -1397,6 +1397,14 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member) return NULL; } + if ((abfd->flags & BFD_DETERMINISTIC) != 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) @@ -1951,6 +1959,7 @@ bsd_write_armap (bfd *arch, unsigned int count; struct ar_hdr hdr; struct stat statbuf; + long int uid, gid; firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG; @@ -1963,8 +1972,15 @@ bsd_write_armap (bfd *arch, + offsetof (struct ar_hdr, ar_date[0])); _bfd_ar_spacepadll (hdr.ar_date, sizeof (hdr.ar_date), "%lld", 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 ()); + if ((arch->flags & BFD_DETERMINISTIC) != 0) + uid = gid = 0; + else + { + uid = getuid (); + gid = 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) diff --git a/gnu/usr.bin/binutils-2.17/bfd/bfd-in.h b/gnu/usr.bin/binutils-2.17/bfd/bfd-in.h index 908c18b4060..6a46d925f23 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/bfd-in.h +++ b/gnu/usr.bin/binutils-2.17/bfd/bfd-in.h @@ -239,6 +239,12 @@ bfd_format; /* This BFD has been created by the linker and doesn't correspond to any input file. */ #define BFD_LINKER_CREATED 0x2000 + +/* This may be set before writing out a BFD to request that the output + be as deterministic as is supported by the format. For example, + archive members may have their uid, gid, timestamp, and mode all set + to constant, 'reasonable' values. */ +#define BFD_DETERMINISTIC 0x4000 /* Symbols and relocation. */ diff --git a/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h b/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h index 453ff3c247b..d36a8a9cbec 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h +++ b/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h @@ -246,6 +246,12 @@ bfd_format; /* This BFD has been created by the linker and doesn't correspond to any input file. */ #define BFD_LINKER_CREATED 0x2000 + +/* This may be set before writing out a BFD to request that the output + be as deterministic as is supported by the format. For example, + archive members may have their uid, gid, timestamp, and mode all set + to constant, 'reasonable' values. */ +#define BFD_DETERMINISTIC 0x4000 /* Symbols and relocation. */ diff --git a/gnu/usr.bin/binutils-2.17/binutils/ar.c b/gnu/usr.bin/binutils-2.17/binutils/ar.c index 179368a7471..80a16db8b03 100644 --- a/gnu/usr.bin/binutils-2.17/binutils/ar.c +++ b/gnu/usr.bin/binutils-2.17/binutils/ar.c @@ -132,6 +132,13 @@ static bfd_boolean ar_truncate = FALSE; program. */ static bfd_boolean full_pathname = FALSE; +/* Whether archive contents should be deterministic with uid, gid, + and mtime set to zero and permissions set to 644. This breaks + later use of the 'u' option as well as make's lib(member) feature. + Note that the symbol index may have a non-zero timestamp to meet + archive format requirements. */ +static bfd_boolean deterministic = FALSE; + int interactive = 0; static void @@ -236,6 +243,8 @@ usage (int help) fprintf (s, _(" [P] - use full path names when matching\n")); fprintf (s, _(" [o] - preserve original dates\n")); fprintf (s, _(" [u] - only replace files that are newer than current archive contents\n")); + fprintf (s, _(" [D] - set deterministic attributes in archive\n")); + fprintf (s, _(" [U] - set accurate attributes in archive\n")); fprintf (s, _(" generic modifiers:\n")); fprintf (s, _(" [c] - do not warn if the library had to be created\n")); fprintf (s, _(" [s] - create an archive index (cf. ranlib)\n")); @@ -558,6 +567,12 @@ main (int argc, char **argv) case 'P': full_pathname = TRUE; break; + case 'D': + deterministic = TRUE; + break; + case 'U': + deterministic = FALSE; + break; default: /* xgettext:c-format */ non_fatal (_("illegal option -- %c"), c); @@ -949,6 +964,9 @@ write_archive (bfd *iarch) obfd->flags |= BFD_TRADITIONAL_FORMAT; } + if (deterministic) + obfd->flags |= BFD_DETERMINISTIC; + if (!bfd_set_archive_head (obfd, contents_head)) bfd_fatal (old_name); |