public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] --enable-deterministic-archives and ar/ranlib -U
@ 2011-12-15 22:11 Roland McGrath
  2011-12-19 23:24 ` Roland McGrath
  0 siblings, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2011-12-15 22:11 UTC (permalink / raw)
  To: binutils

See http://sourceware.org/ml/binutils/2011-12/msg00066.html and its
followups for rationale.

I have no special attachment to the choice of U as the option letter if
someone prefers a different one.  It made vague sense for it to be capital
since D is, and mnemonically better choices were already taken.


Ok for trunk?


Thanks,
Roland


binutils/
2011-12-15  Roland McGrath  <mcgrathr@google.com>

	* configure.in (--enable-deterministic-archives): Grok new
	argument.  Set DEFAULT_AR_DETERMINISTIC to 1 or 0 accordingly.
	* configure: Regenerated.
	* config.in: Regenerated.
	* ar.c (deterministic): Initialize to -1.
	(decode_options, ranlib_main): Grok U option.
	(usage, ranlib_usage): Mention U; say for D and U which is the default.
	(default_deterministic): New function.
	(ranlib_main): Call it.
	(main): Likewise.  Make newer_only && deterministic error
	non-fatal if it was just DEFAULT_AR_DETERMINISTIC and not the D option.
	* doc/binutils.texi (ar cmdline, ranlib): Document U modifier and
	--enable-deterministic-archives behavior.

diff --git a/binutils/ar.c b/binutils/ar.c
index 676e92c..10fae45 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -97,7 +97,7 @@ int write_armap = 0;
 /* Operate in deterministic mode: write zero for timestamps, uids,
    and gids for archive members and the archive symbol table, and write
    consistent file modes.  */
-int deterministic = 0;
+int deterministic = -1;			/* Determinism indeterminate.  */
 
 /* Nonzero means it's the name of an existing member; position new or moved
    files with respect to this one.  */
@@ -276,7 +276,12 @@ usage (int help)
   fprintf (s, _(" command specific modifiers:\n"));
   fprintf (s, _("  [a]          - put file(s) after [member-name]\n"));
   fprintf (s, _("  [b]          - put file(s) before [member-name] (same as [i])\n"));
-  fprintf (s, _("  [D]          - use zero for timestamps and uids/gids\n"));
+  fprintf (s, _("\
+  [D]          - use zero for timestamps and uids/gids (%s)\n"),
+           DEFAULT_AR_DETERMINISTIC ? _("default") : _("not default"));
+  fprintf (s, _("\
+  [U]          - use actual timestamps and uids/gids (%s)\n"),
+           DEFAULT_AR_DETERMINISTIC ? _("not default") : _("default"));
   fprintf (s, _("  [N]          - use instance [count] of name\n"));
   fprintf (s, _("  [f]          - truncate inserted file names\n"));
   fprintf (s, _("  [P]          - use full path names when matching\n"));
@@ -324,9 +329,12 @@ ranlib_usage (int help)
 #endif
   fprintf (s, _("\
   -t                           Update the archive's symbol map timestamp\n\
-  -D                           Use zero for the symbol map timestamp\n\
+  -D                           Use zero for the symbol map timestamp (%s)\n\
+  -U                           Use an actual symbol map timestamp (%s)\n\
   -h --help                    Print this help message\n\
-  -v --version                 Print version information\n"));
+  -v --version                 Print version information\n"),
+           DEFAULT_AR_DETERMINISTIC ? _("default") : _("not default"),
+           DEFAULT_AR_DETERMINISTIC ? _("not default") : _("default"));
 
   list_supported_targets (program_name, s);
 
@@ -434,7 +442,7 @@ decode_options (int argc, char **argv)
       argv = new_argv;
     }
 
-  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTD",
+  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTDU",
 			   long_options, NULL)) != EOF)
     {
       switch (c)
@@ -531,6 +539,9 @@ decode_options (int argc, char **argv)
         case 'D':
           deterministic = TRUE;
           break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
 	  plugin_target = "plugin";
@@ -553,6 +564,15 @@ decode_options (int argc, char **argv)
   return &argv[optind];
 }
 
+/* If neither -D nor -U was not specified explicitly,
+   then use the configured default.  */
+static void
+default_deterministic (void)
+{
+  if (deterministic < 0)
+    deterministic = DEFAULT_AR_DETERMINISTIC;
+}
+
 static void
 ranlib_main (int argc, char **argv)
 {
@@ -560,13 +580,16 @@ ranlib_main (int argc, char **argv)
   bfd_boolean touch = FALSE;
   int c;
 
-  while ((c = getopt_long (argc, argv, "DhHvVt", long_options, NULL)) != EOF)
+  while ((c = getopt_long (argc, argv, "DhHUvVt", long_options, NULL)) != EOF)
     {
       switch (c)
         {
 	case 'D':
 	  deterministic = TRUE;
 	  break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case 'h':
 	case 'H':
 	  show_help = 1;
@@ -590,6 +613,8 @@ ranlib_main (int argc, char **argv)
   if (show_version)
     print_version ("ranlib");
 
+  default_deterministic ();
+
   arg_index = optind;
 
   while (arg_index < argc)
@@ -699,8 +724,14 @@ main (int argc, char **argv)
       if (newer_only && operation != replace)
 	fatal (_("`u' is only meaningful with the `r' option."));
 
-      if (newer_only && deterministic)
-	fatal (_("`u' is not meaningful with the `D' option."));
+      if (newer_only && deterministic > 0)
+        fatal (_("`u' is not meaningful with the `D' option."));
+
+      if (newer_only && deterministic < 0 && DEFAULT_AR_DETERMINISTIC)
+        non_fatal (_("\
+`u' modifier ignored since `D' is the default (see `U')"));
+
+      default_deterministic ();
 
       if (postype != pos_default)
 	posname = argv[arg_index++];
diff --git a/binutils/configure.in b/binutils/configure.in
index 1f3b25d..d38b677 100644
--- a/binutils/configure.in
+++ b/binutils/configure.in
@@ -28,6 +28,18 @@ AC_ARG_ENABLE(targets,
   *)        enable_targets=$enableval ;;
 esac])dnl
 
+AC_ARG_ENABLE(deterministic-archives,
+[AS_HELP_STRING([--enable-deterministic-archives],
+		[ar and ranlib default to -D behavior])], [
+if test "${enableval}" = no; then
+  default_ar_deterministic=0
+else
+  default_ar_deterministic=1
+fi], [default_ar_deterministic=0])
+
+AC_DEFINE_UNQUOTED(DEFAULT_AR_DETERMINISTIC, $default_ar_deterministic,
+		   [Should ar and ranlib use -D behavior by default?])
+
 AM_BINUTILS_WARNINGS
 		   
 AC_CONFIG_HEADERS(config.h:config.in)
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 3217a1a..9fca349 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -418,6 +418,7 @@ using this modifier.
 
 @item D
 @cindex deterministic archives
+@kindex --enable-deterministic-archives
 Operate in @emph{deterministic} mode.  When adding files and the archive
 index use zero for UIDs, GIDs, timestamps, and use consistent file modes
 for all files.  When this option is used, if @command{ar} is used with
@@ -425,6 +426,10 @@ identical options and identical input files, multiple runs will create
 identical output files regardless of the input files' owners, groups,
 file modes, or modification times.
 
+If @file{binutils} was configured with
+@option{--enable-deterministic-archives}, then this mode is on by default.
+It can be disabled with the @samp{U} modifier, below.
+
 @item f
 Truncate names in the archive.  @sc{gnu} @command{ar} will normally permit file
 names of any length.  This will cause it to create archives which are
@@ -493,6 +498,16 @@ operation @samp{r} (replace).  In particular, the combination @samp{qu} is
 not allowed, since checking the timestamps would lose any speed
 advantage from the operation @samp{q}.
 
+@item U
+@cindex deterministic archives
+@kindex --enable-deterministic-archives
+Do @emph{not} operate in @emph{deterministic} mode.  This is the inverse
+of the @samp{D} modifier, above: added files and the archive index will
+get their actual UID, GID, timestamp, and file mode values.
+
+This is the default unless @file{binutils} was configured with
+@option{--enable-deterministic-archives}.
+
 @item v
 This modifier requests the @emph{verbose} version of an operation.  Many
 operations display additional information, such as filenames processed,
@@ -2386,10 +2401,18 @@ Show the version number of @command{ranlib}.
 
 @item -D
 @cindex deterministic archives
+@kindex GNU_AR_DETERMINISTIC
 Operate in @emph{deterministic} mode.  The symbol map archive member's
 header will show zero for the UID, GID, and timestamp.  When this
 option is used, multiple runs will produce identical output files.
 
+If the environment variable @code{GNU_AR_DETERMINISTIC} is set to a nonempty
+value that is not @code{0}, then this mode is enabled by default.  If that
+environment variable is absent or has an empty value and @file{binutils} was
+configured with @option{--enable-deterministic-archives}, then this mode is
+on by default.  If @code{GNU_AR_DETERMINISTIC} is set to @code{0} then this
+mode is never enabled without the @code{D} modifier.
+
 @item -t
 Update the timestamp of the symbol map of an archive.
 @end table

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

* Re: [PATCH] --enable-deterministic-archives and ar/ranlib -U
  2011-12-15 22:11 [PATCH] --enable-deterministic-archives and ar/ranlib -U Roland McGrath
@ 2011-12-19 23:24 ` Roland McGrath
  2011-12-20  8:50   ` Tristan Gingold
  0 siblings, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2011-12-19 23:24 UTC (permalink / raw)
  To: binutils; +Cc: nick clifton

ping?

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

* Re: [PATCH] --enable-deterministic-archives and ar/ranlib -U
  2011-12-19 23:24 ` Roland McGrath
@ 2011-12-20  8:50   ` Tristan Gingold
  2011-12-20 17:23     ` Roland McGrath
  0 siblings, 1 reply; 8+ messages in thread
From: Tristan Gingold @ 2011-12-20  8:50 UTC (permalink / raw)
  To: Roland McGrath; +Cc: binutils, nick clifton


On Dec 20, 2011, at 12:23 AM, Roland McGrath wrote:

> ping?

Just a cosmetic comment from my part.  I think it would be better to display only '(default)', and not to display '(not default)'.
After all, a command line option is an option, which by default is not default :-)

Otherwise, looks sane to me.

Tristan.


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

* Re: [PATCH] --enable-deterministic-archives and ar/ranlib -U
  2011-12-20  8:50   ` Tristan Gingold
@ 2011-12-20 17:23     ` Roland McGrath
  2011-12-20 18:36       ` Roland McGrath
  0 siblings, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2011-12-20 17:23 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils, nick clifton

On Tue, Dec 20, 2011 at 12:49 AM, Tristan Gingold <gingold@adacore.com> wrote:
> Just a cosmetic comment from my part.  I think it would be better to
> display only '(default)', and not to display '(not default)'.

Here's a version of the patch with that change.

Maintainers?


Thanks,
Roland


binutils/
2011-12-20  Roland McGrath  <mcgrathr@google.com>

	* configure.in (--enable-deterministic-archives): Grok new
	argument.  Set DEFAULT_AR_DETERMINISTIC to 1 or 0 accordingly.
	* configure: Regenerated.
	* config.in: Regenerated.
	* ar.c (deterministic): Initialize to -1.
	(decode_options, ranlib_main): Grok U option.
	(usage, ranlib_usage): Mention U; say for D and U which is the default.
	(default_deterministic): New function.
	(ranlib_main): Call it.
	(main): Likewise.  Make newer_only && deterministic error
	non-fatal if it was just DEFAULT_AR_DETERMINISTIC and not the D option.
	* doc/binutils.texi (ar cmdline, ranlib): Document U modifier and
	--enable-deterministic-archives behavior.

diff --git a/binutils/ar.c b/binutils/ar.c
index 676e92c..2e2a742 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -97,7 +97,7 @@ int write_armap = 0;
 /* Operate in deterministic mode: write zero for timestamps, uids,
    and gids for archive members and the archive symbol table, and write
    consistent file modes.  */
-int deterministic = 0;
+int deterministic = -1;			/* Determinism indeterminate.  */

 /* Nonzero means it's the name of an existing member; position new or moved
    files with respect to this one.  */
@@ -276,7 +276,20 @@ usage (int help)
   fprintf (s, _(" command specific modifiers:\n"));
   fprintf (s, _("  [a]          - put file(s) after [member-name]\n"));
   fprintf (s, _("  [b]          - put file(s) before [member-name]
(same as [i])\n"));
-  fprintf (s, _("  [D]          - use zero for timestamps and uids/gids\n"));
+  if (DEFAULT_AR_DETERMINISTIC)
+    {
+      fprintf (s, _("\
+  [D]          - use zero for timestamps and uids/gids (default)\n"));
+      fprintf (s, _("\
+  [U]          - use actual timestamps and uids/gids\n"));
+    }
+  else
+    {
+      fprintf (s, _("\
+  [D]          - use zero for timestamps and uids/gids\n"));
+      fprintf (s, _("\
+  [U]          - use actual timestamps and uids/gids (default)\n"));
+    }
   fprintf (s, _("  [N]          - use instance [count] of name\n"));
   fprintf (s, _("  [f]          - truncate inserted file names\n"));
   fprintf (s, _("  [P]          - use full path names when matching\n"));
@@ -324,9 +337,12 @@ ranlib_usage (int help)
 #endif
   fprintf (s, _("\
   -t                           Update the archive's symbol map timestamp\n\
-  -D                           Use zero for the symbol map timestamp\n\
+  -D                           Use zero for the symbol map timestamp (%s)\n\
+  -U                           Use an actual symbol map timestamp (%s)\n\
   -h --help                    Print this help message\n\
-  -v --version                 Print version information\n"));
+  -v --version                 Print version information\n"),
+           DEFAULT_AR_DETERMINISTIC ? _("default") : _("not default"),
+           DEFAULT_AR_DETERMINISTIC ? _("not default") : _("default"));

   list_supported_targets (program_name, s);

@@ -434,7 +450,7 @@ decode_options (int argc, char **argv)
       argv = new_argv;
     }

-  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTD",
+  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTDU",
 			   long_options, NULL)) != EOF)
     {
       switch (c)
@@ -531,6 +547,9 @@ decode_options (int argc, char **argv)
         case 'D':
           deterministic = TRUE;
           break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
 	  plugin_target = "plugin";
@@ -553,6 +572,15 @@ decode_options (int argc, char **argv)
   return &argv[optind];
 }

+/* If neither -D nor -U was not specified explicitly,
+   then use the configured default.  */
+static void
+default_deterministic (void)
+{
+  if (deterministic < 0)
+    deterministic = DEFAULT_AR_DETERMINISTIC;
+}
+
 static void
 ranlib_main (int argc, char **argv)
 {
@@ -560,13 +588,16 @@ ranlib_main (int argc, char **argv)
   bfd_boolean touch = FALSE;
   int c;

-  while ((c = getopt_long (argc, argv, "DhHvVt", long_options, NULL)) != EOF)
+  while ((c = getopt_long (argc, argv, "DhHUvVt", long_options, NULL)) != EOF)
     {
       switch (c)
         {
 	case 'D':
 	  deterministic = TRUE;
 	  break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case 'h':
 	case 'H':
 	  show_help = 1;
@@ -590,6 +621,8 @@ ranlib_main (int argc, char **argv)
   if (show_version)
     print_version ("ranlib");

+  default_deterministic ();
+
   arg_index = optind;

   while (arg_index < argc)
@@ -699,8 +732,14 @@ main (int argc, char **argv)
       if (newer_only && operation != replace)
 	fatal (_("`u' is only meaningful with the `r' option."));

-      if (newer_only && deterministic)
-	fatal (_("`u' is not meaningful with the `D' option."));
+      if (newer_only && deterministic > 0)
+        fatal (_("`u' is not meaningful with the `D' option."));
+
+      if (newer_only && deterministic < 0 && DEFAULT_AR_DETERMINISTIC)
+        non_fatal (_("\
+`u' modifier ignored since `D' is the default (see `U')"));
+
+      default_deterministic ();

       if (postype != pos_default)
 	posname = argv[arg_index++];
diff --git a/binutils/configure.in b/binutils/configure.in
index 1f3b25d..d38b677 100644
--- a/binutils/configure.in
+++ b/binutils/configure.in
@@ -28,6 +28,18 @@ AC_ARG_ENABLE(targets,
   *)        enable_targets=$enableval ;;
 esac])dnl

+AC_ARG_ENABLE(deterministic-archives,
+[AS_HELP_STRING([--enable-deterministic-archives],
+		[ar and ranlib default to -D behavior])], [
+if test "${enableval}" = no; then
+  default_ar_deterministic=0
+else
+  default_ar_deterministic=1
+fi], [default_ar_deterministic=0])
+
+AC_DEFINE_UNQUOTED(DEFAULT_AR_DETERMINISTIC, $default_ar_deterministic,
+		   [Should ar and ranlib use -D behavior by default?])
+
 AM_BINUTILS_WARNINGS
 		
 AC_CONFIG_HEADERS(config.h:config.in)
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 3217a1a..9fca349 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -418,6 +418,7 @@ using this modifier.

 @item D
 @cindex deterministic archives
+@kindex --enable-deterministic-archives
 Operate in @emph{deterministic} mode.  When adding files and the archive
 index use zero for UIDs, GIDs, timestamps, and use consistent file modes
 for all files.  When this option is used, if @command{ar} is used with
@@ -425,6 +426,10 @@ identical options and identical input files,
multiple runs will create
 identical output files regardless of the input files' owners, groups,
 file modes, or modification times.

+If @file{binutils} was configured with
+@option{--enable-deterministic-archives}, then this mode is on by default.
+It can be disabled with the @samp{U} modifier, below.
+
 @item f
 Truncate names in the archive.  @sc{gnu} @command{ar} will normally permit file
 names of any length.  This will cause it to create archives which are
@@ -493,6 +498,16 @@ operation @samp{r} (replace).  In particular, the
combination @samp{qu} is
 not allowed, since checking the timestamps would lose any speed
 advantage from the operation @samp{q}.

+@item U
+@cindex deterministic archives
+@kindex --enable-deterministic-archives
+Do @emph{not} operate in @emph{deterministic} mode.  This is the inverse
+of the @samp{D} modifier, above: added files and the archive index will
+get their actual UID, GID, timestamp, and file mode values.
+
+This is the default unless @file{binutils} was configured with
+@option{--enable-deterministic-archives}.
+
 @item v
 This modifier requests the @emph{verbose} version of an operation.  Many
 operations display additional information, such as filenames processed,
@@ -2386,10 +2401,18 @@ Show the version number of @command{ranlib}.

 @item -D
 @cindex deterministic archives
+@kindex GNU_AR_DETERMINISTIC
 Operate in @emph{deterministic} mode.  The symbol map archive member's
 header will show zero for the UID, GID, and timestamp.  When this
 option is used, multiple runs will produce identical output files.

+If the environment variable @code{GNU_AR_DETERMINISTIC} is set to a nonempty
+value that is not @code{0}, then this mode is enabled by default.  If that
+environment variable is absent or has an empty value and @file{binutils} was
+configured with @option{--enable-deterministic-archives}, then this mode is
+on by default.  If @code{GNU_AR_DETERMINISTIC} is set to @code{0} then this
+mode is never enabled without the @code{D} modifier.
+
 @item -t
 Update the timestamp of the symbol map of an archive.
 @end table

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

* Re: [PATCH] --enable-deterministic-archives and ar/ranlib -U
  2011-12-20 17:23     ` Roland McGrath
@ 2011-12-20 18:36       ` Roland McGrath
  2011-12-20 19:26         ` Roland McGrath
  0 siblings, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2011-12-20 18:36 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils, nick clifton

I forgot to change the ranlib --help bit the same way.

Ok for trunk like this?


Thanks,
Roland


binutils/
2011-12-20  Roland McGrath  <mcgrathr@google.com>

	* configure.in (--enable-deterministic-archives): Grok new
	argument.  Set DEFAULT_AR_DETERMINISTIC to 1 or 0 accordingly.
	* configure: Regenerated.
	* config.in: Regenerated.
	* ar.c (deterministic): Initialize to -1.
	(decode_options, ranlib_main): Grok U option.
	(usage, ranlib_usage): Mention U; say for D and U which is the default.
	(default_deterministic): New function.
	(ranlib_main): Call it.
	(main): Likewise.  Make newer_only && deterministic error
	non-fatal if it was just DEFAULT_AR_DETERMINISTIC and not the D option.
	* doc/binutils.texi (ar cmdline, ranlib): Document U modifier and
	--enable-deterministic-archives behavior.

diff --git a/binutils/ar.c b/binutils/ar.c
index 676e92c..0310b6f 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -97,7 +97,7 @@ int write_armap = 0;
 /* Operate in deterministic mode: write zero for timestamps, uids,
    and gids for archive members and the archive symbol table, and write
    consistent file modes.  */
-int deterministic = 0;
+int deterministic = -1;			/* Determinism indeterminate.  */

 /* Nonzero means it's the name of an existing member; position new or moved
    files with respect to this one.  */
@@ -276,7 +276,20 @@ usage (int help)
   fprintf (s, _(" command specific modifiers:\n"));
   fprintf (s, _("  [a]          - put file(s) after [member-name]\n"));
   fprintf (s, _("  [b]          - put file(s) before [member-name]
(same as [i])\n"));
-  fprintf (s, _("  [D]          - use zero for timestamps and uids/gids\n"));
+  if (DEFAULT_AR_DETERMINISTIC)
+    {
+      fprintf (s, _("\
+  [D]          - use zero for timestamps and uids/gids (default)\n"));
+      fprintf (s, _("\
+  [U]          - use actual timestamps and uids/gids\n"));
+    }
+  else
+    {
+      fprintf (s, _("\
+  [D]          - use zero for timestamps and uids/gids\n"));
+      fprintf (s, _("\
+  [U]          - use actual timestamps and uids/gids (default)\n"));
+    }
   fprintf (s, _("  [N]          - use instance [count] of name\n"));
   fprintf (s, _("  [f]          - truncate inserted file names\n"));
   fprintf (s, _("  [P]          - use full path names when matching\n"));
@@ -322,9 +335,16 @@ ranlib_usage (int help)
   fprintf (s, _("\
   --plugin <name>              Load the specified plugin\n"));
 #endif
+  if (DEFAULT_AR_DETERMINISTIC)
+    fprintf (s, _("\
+  -D                           Use zero for symbol map timestamp (default)\n\
+  -U                           Use an actual symbol map timestamp\n"));
+  else
+    fprintf (s, _("\
+  -D                           Use zero for symbol map timestamp\n\
+  -U                           Use actual symbol map timestamp (default)\n"));
   fprintf (s, _("\
   -t                           Update the archive's symbol map timestamp\n\
-  -D                           Use zero for the symbol map timestamp\n\
   -h --help                    Print this help message\n\
   -v --version                 Print version information\n"));

@@ -434,7 +454,7 @@ decode_options (int argc, char **argv)
       argv = new_argv;
     }

-  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTD",
+  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTDU",
 			   long_options, NULL)) != EOF)
     {
       switch (c)
@@ -531,6 +551,9 @@ decode_options (int argc, char **argv)
         case 'D':
           deterministic = TRUE;
           break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
 	  plugin_target = "plugin";
@@ -553,6 +576,15 @@ decode_options (int argc, char **argv)
   return &argv[optind];
 }

+/* If neither -D nor -U was not specified explicitly,
+   then use the configured default.  */
+static void
+default_deterministic (void)
+{
+  if (deterministic < 0)
+    deterministic = DEFAULT_AR_DETERMINISTIC;
+}
+
 static void
 ranlib_main (int argc, char **argv)
 {
@@ -560,13 +592,16 @@ ranlib_main (int argc, char **argv)
   bfd_boolean touch = FALSE;
   int c;

-  while ((c = getopt_long (argc, argv, "DhHvVt", long_options, NULL)) != EOF)
+  while ((c = getopt_long (argc, argv, "DhHUvVt", long_options, NULL)) != EOF)
     {
       switch (c)
         {
 	case 'D':
 	  deterministic = TRUE;
 	  break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case 'h':
 	case 'H':
 	  show_help = 1;
@@ -590,6 +625,8 @@ ranlib_main (int argc, char **argv)
   if (show_version)
     print_version ("ranlib");

+  default_deterministic ();
+
   arg_index = optind;

   while (arg_index < argc)
@@ -699,8 +736,14 @@ main (int argc, char **argv)
       if (newer_only && operation != replace)
 	fatal (_("`u' is only meaningful with the `r' option."));

-      if (newer_only && deterministic)
-	fatal (_("`u' is not meaningful with the `D' option."));
+      if (newer_only && deterministic > 0)
+        fatal (_("`u' is not meaningful with the `D' option."));
+
+      if (newer_only && deterministic < 0 && DEFAULT_AR_DETERMINISTIC)
+        non_fatal (_("\
+`u' modifier ignored since `D' is the default (see `U')"));
+
+      default_deterministic ();

       if (postype != pos_default)
 	posname = argv[arg_index++];
diff --git a/binutils/configure.in b/binutils/configure.in
index 1f3b25d..d38b677 100644
--- a/binutils/configure.in
+++ b/binutils/configure.in
@@ -28,6 +28,18 @@ AC_ARG_ENABLE(targets,
   *)        enable_targets=$enableval ;;
 esac])dnl

+AC_ARG_ENABLE(deterministic-archives,
+[AS_HELP_STRING([--enable-deterministic-archives],
+		[ar and ranlib default to -D behavior])], [
+if test "${enableval}" = no; then
+  default_ar_deterministic=0
+else
+  default_ar_deterministic=1
+fi], [default_ar_deterministic=0])
+
+AC_DEFINE_UNQUOTED(DEFAULT_AR_DETERMINISTIC, $default_ar_deterministic,
+		   [Should ar and ranlib use -D behavior by default?])
+
 AM_BINUTILS_WARNINGS
 		
 AC_CONFIG_HEADERS(config.h:config.in)
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 3217a1a..9fca349 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -418,6 +418,7 @@ using this modifier.

 @item D
 @cindex deterministic archives
+@kindex --enable-deterministic-archives
 Operate in @emph{deterministic} mode.  When adding files and the archive
 index use zero for UIDs, GIDs, timestamps, and use consistent file modes
 for all files.  When this option is used, if @command{ar} is used with
@@ -425,6 +426,10 @@ identical options and identical input files,
multiple runs will create
 identical output files regardless of the input files' owners, groups,
 file modes, or modification times.

+If @file{binutils} was configured with
+@option{--enable-deterministic-archives}, then this mode is on by default.
+It can be disabled with the @samp{U} modifier, below.
+
 @item f
 Truncate names in the archive.  @sc{gnu} @command{ar} will normally permit file
 names of any length.  This will cause it to create archives which are
@@ -493,6 +498,16 @@ operation @samp{r} (replace).  In particular, the
combination @samp{qu} is
 not allowed, since checking the timestamps would lose any speed
 advantage from the operation @samp{q}.

+@item U
+@cindex deterministic archives
+@kindex --enable-deterministic-archives
+Do @emph{not} operate in @emph{deterministic} mode.  This is the inverse
+of the @samp{D} modifier, above: added files and the archive index will
+get their actual UID, GID, timestamp, and file mode values.
+
+This is the default unless @file{binutils} was configured with
+@option{--enable-deterministic-archives}.
+
 @item v
 This modifier requests the @emph{verbose} version of an operation.  Many
 operations display additional information, such as filenames processed,
@@ -2386,10 +2401,18 @@ Show the version number of @command{ranlib}.

 @item -D
 @cindex deterministic archives
+@kindex GNU_AR_DETERMINISTIC
 Operate in @emph{deterministic} mode.  The symbol map archive member's
 header will show zero for the UID, GID, and timestamp.  When this
 option is used, multiple runs will produce identical output files.

+If the environment variable @code{GNU_AR_DETERMINISTIC} is set to a nonempty
+value that is not @code{0}, then this mode is enabled by default.  If that
+environment variable is absent or has an empty value and @file{binutils} was
+configured with @option{--enable-deterministic-archives}, then this mode is
+on by default.  If @code{GNU_AR_DETERMINISTIC} is set to @code{0} then this
+mode is never enabled without the @code{D} modifier.
+
 @item -t
 Update the timestamp of the symbol map of an archive.
 @end table

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

* Re: [PATCH] --enable-deterministic-archives and ar/ranlib -U
  2011-12-20 18:36       ` Roland McGrath
@ 2011-12-20 19:26         ` Roland McGrath
  2011-12-21 16:28           ` nick clifton
  0 siblings, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2011-12-20 19:26 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils, nick clifton

..and I forgot to update the ranlib part of manual changes for the new
iteration of the patch.

Maintainers, like it now?


Thanks,
Roland


binutils/
2011-12-20  Roland McGrath  <mcgrathr@google.com>

	* configure.in (--enable-deterministic-archives): Grok new
	argument.  Set DEFAULT_AR_DETERMINISTIC to 1 or 0 accordingly.
	* configure: Regenerated.
	* config.in: Regenerated.
	* ar.c (deterministic): Initialize to -1.
	(decode_options, ranlib_main): Grok U option.
	(usage, ranlib_usage): Mention U; say for D and U which is the default.
	(default_deterministic): New function.
	(ranlib_main): Call it.
	(main): Likewise.  Make newer_only && deterministic error
	non-fatal if it was just DEFAULT_AR_DETERMINISTIC and not the D option.
	* doc/binutils.texi (ar cmdline, ranlib): Document U modifier and
	--enable-deterministic-archives behavior.

diff --git a/binutils/ar.c b/binutils/ar.c
index 676e92c..0310b6f 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -97,7 +97,7 @@ int write_armap = 0;
 /* Operate in deterministic mode: write zero for timestamps, uids,
    and gids for archive members and the archive symbol table, and write
    consistent file modes.  */
-int deterministic = 0;
+int deterministic = -1;			/* Determinism indeterminate.  */

 /* Nonzero means it's the name of an existing member; position new or moved
    files with respect to this one.  */
@@ -276,7 +276,20 @@ usage (int help)
   fprintf (s, _(" command specific modifiers:\n"));
   fprintf (s, _("  [a]          - put file(s) after [member-name]\n"));
   fprintf (s, _("  [b]          - put file(s) before [member-name]
(same as [i])\n"));
-  fprintf (s, _("  [D]          - use zero for timestamps and uids/gids\n"));
+  if (DEFAULT_AR_DETERMINISTIC)
+    {
+      fprintf (s, _("\
+  [D]          - use zero for timestamps and uids/gids (default)\n"));
+      fprintf (s, _("\
+  [U]          - use actual timestamps and uids/gids\n"));
+    }
+  else
+    {
+      fprintf (s, _("\
+  [D]          - use zero for timestamps and uids/gids\n"));
+      fprintf (s, _("\
+  [U]          - use actual timestamps and uids/gids (default)\n"));
+    }
   fprintf (s, _("  [N]          - use instance [count] of name\n"));
   fprintf (s, _("  [f]          - truncate inserted file names\n"));
   fprintf (s, _("  [P]          - use full path names when matching\n"));
@@ -322,9 +335,16 @@ ranlib_usage (int help)
   fprintf (s, _("\
   --plugin <name>              Load the specified plugin\n"));
 #endif
+  if (DEFAULT_AR_DETERMINISTIC)
+    fprintf (s, _("\
+  -D                           Use zero for symbol map timestamp (default)\n\
+  -U                           Use an actual symbol map timestamp\n"));
+  else
+    fprintf (s, _("\
+  -D                           Use zero for symbol map timestamp\n\
+  -U                           Use actual symbol map timestamp (default)\n"));
   fprintf (s, _("\
   -t                           Update the archive's symbol map timestamp\n\
-  -D                           Use zero for the symbol map timestamp\n\
   -h --help                    Print this help message\n\
   -v --version                 Print version information\n"));

@@ -434,7 +454,7 @@ decode_options (int argc, char **argv)
       argv = new_argv;
     }

-  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTD",
+  while ((c = getopt_long (argc, argv, "hdmpqrtxlcoVsSuvabiMNfPTDU",
 			   long_options, NULL)) != EOF)
     {
       switch (c)
@@ -531,6 +551,9 @@ decode_options (int argc, char **argv)
         case 'D':
           deterministic = TRUE;
           break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
 	  plugin_target = "plugin";
@@ -553,6 +576,15 @@ decode_options (int argc, char **argv)
   return &argv[optind];
 }

+/* If neither -D nor -U was not specified explicitly,
+   then use the configured default.  */
+static void
+default_deterministic (void)
+{
+  if (deterministic < 0)
+    deterministic = DEFAULT_AR_DETERMINISTIC;
+}
+
 static void
 ranlib_main (int argc, char **argv)
 {
@@ -560,13 +592,16 @@ ranlib_main (int argc, char **argv)
   bfd_boolean touch = FALSE;
   int c;

-  while ((c = getopt_long (argc, argv, "DhHvVt", long_options, NULL)) != EOF)
+  while ((c = getopt_long (argc, argv, "DhHUvVt", long_options, NULL)) != EOF)
     {
       switch (c)
         {
 	case 'D':
 	  deterministic = TRUE;
 	  break;
+        case 'U':
+          deterministic = FALSE;
+          break;
 	case 'h':
 	case 'H':
 	  show_help = 1;
@@ -590,6 +625,8 @@ ranlib_main (int argc, char **argv)
   if (show_version)
     print_version ("ranlib");

+  default_deterministic ();
+
   arg_index = optind;

   while (arg_index < argc)
@@ -699,8 +736,14 @@ main (int argc, char **argv)
       if (newer_only && operation != replace)
 	fatal (_("`u' is only meaningful with the `r' option."));

-      if (newer_only && deterministic)
-	fatal (_("`u' is not meaningful with the `D' option."));
+      if (newer_only && deterministic > 0)
+        fatal (_("`u' is not meaningful with the `D' option."));
+
+      if (newer_only && deterministic < 0 && DEFAULT_AR_DETERMINISTIC)
+        non_fatal (_("\
+`u' modifier ignored since `D' is the default (see `U')"));
+
+      default_deterministic ();

       if (postype != pos_default)
 	posname = argv[arg_index++];
diff --git a/binutils/configure.in b/binutils/configure.in
index 1f3b25d..d38b677 100644
--- a/binutils/configure.in
+++ b/binutils/configure.in
@@ -28,6 +28,18 @@ AC_ARG_ENABLE(targets,
   *)        enable_targets=$enableval ;;
 esac])dnl

+AC_ARG_ENABLE(deterministic-archives,
+[AS_HELP_STRING([--enable-deterministic-archives],
+		[ar and ranlib default to -D behavior])], [
+if test "${enableval}" = no; then
+  default_ar_deterministic=0
+else
+  default_ar_deterministic=1
+fi], [default_ar_deterministic=0])
+
+AC_DEFINE_UNQUOTED(DEFAULT_AR_DETERMINISTIC, $default_ar_deterministic,
+		   [Should ar and ranlib use -D behavior by default?])
+
 AM_BINUTILS_WARNINGS
 		
 AC_CONFIG_HEADERS(config.h:config.in)
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 3217a1a..76998bc 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -418,6 +418,7 @@ using this modifier.

 @item D
 @cindex deterministic archives
+@kindex --enable-deterministic-archives
 Operate in @emph{deterministic} mode.  When adding files and the archive
 index use zero for UIDs, GIDs, timestamps, and use consistent file modes
 for all files.  When this option is used, if @command{ar} is used with
@@ -425,6 +426,10 @@ identical options and identical input files,
multiple runs will create
 identical output files regardless of the input files' owners, groups,
 file modes, or modification times.

+If @file{binutils} was configured with
+@option{--enable-deterministic-archives}, then this mode is on by default.
+It can be disabled with the @samp{U} modifier, below.
+
 @item f
 Truncate names in the archive.  @sc{gnu} @command{ar} will normally permit file
 names of any length.  This will cause it to create archives which are
@@ -493,6 +498,16 @@ operation @samp{r} (replace).  In particular, the
combination @samp{qu} is
 not allowed, since checking the timestamps would lose any speed
 advantage from the operation @samp{q}.

+@item U
+@cindex deterministic archives
+@kindex --enable-deterministic-archives
+Do @emph{not} operate in @emph{deterministic} mode.  This is the inverse
+of the @samp{D} modifier, above: added files and the archive index will
+get their actual UID, GID, timestamp, and file mode values.
+
+This is the default unless @file{binutils} was configured with
+@option{--enable-deterministic-archives}.
+
 @item v
 This modifier requests the @emph{verbose} version of an operation.  Many
 operations display additional information, such as filenames processed,
@@ -2386,12 +2401,26 @@ Show the version number of @command{ranlib}.

 @item -D
 @cindex deterministic archives
+@kindex --enable-deterministic-archives
 Operate in @emph{deterministic} mode.  The symbol map archive member's
 header will show zero for the UID, GID, and timestamp.  When this
 option is used, multiple runs will produce identical output files.

+This is the default unless @file{binutils} was configured with
+@option{--enable-deterministic-archives}.
+
 @item -t
 Update the timestamp of the symbol map of an archive.
+
+@item -U
+@cindex deterministic archives
+@kindex --enable-deterministic-archives
+Do @emph{not} operate in @emph{deterministic} mode.  This is the
+inverse of the @samp{-D} option, above: the archive index will get
+actual UID, GID, timestamp, and file mode values.
+
+This is the default unless @file{binutils} was configured with
+@option{--enable-deterministic-archives}.
 @end table

 @c man end

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

* Re: [PATCH] --enable-deterministic-archives and ar/ranlib -U
  2011-12-20 19:26         ` Roland McGrath
@ 2011-12-21 16:28           ` nick clifton
  2011-12-21 21:13             ` Roland McGrath
  0 siblings, 1 reply; 8+ messages in thread
From: nick clifton @ 2011-12-21 16:28 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Tristan Gingold, binutils

Hi  Roland,

> Maintainers, like it now?

Sorry, sorry  - caught up in other stuff.

> binutils/
> 2011-12-20  Roland McGrath<mcgrathr@google.com>
>
> 	* configure.in (--enable-deterministic-archives): Grok new
> 	argument.  Set DEFAULT_AR_DETERMINISTIC to 1 or 0 accordingly.
> 	* configure: Regenerated.
> 	* config.in: Regenerated.
> 	* ar.c (deterministic): Initialize to -1.
> 	(decode_options, ranlib_main): Grok U option.
> 	(usage, ranlib_usage): Mention U; say for D and U which is the default.
> 	(default_deterministic): New function.
> 	(ranlib_main): Call it.
> 	(main): Likewise.  Make newer_only&&  deterministic error
> 	non-fatal if it was just DEFAULT_AR_DETERMINISTIC and not the D option.
> 	* doc/binutils.texi (ar cmdline, ranlib): Document U modifier and
> 	--enable-deterministic-archives behavior.

Approved - please apply.

Cheers
   Nick

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

* Re: [PATCH] --enable-deterministic-archives and ar/ranlib -U
  2011-12-21 16:28           ` nick clifton
@ 2011-12-21 21:13             ` Roland McGrath
  0 siblings, 0 replies; 8+ messages in thread
From: Roland McGrath @ 2011-12-21 21:13 UTC (permalink / raw)
  To: nick clifton; +Cc: Tristan Gingold, binutils

Committed (same thing last posted).

Thanks,
Roland

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

end of thread, other threads:[~2011-12-21 21:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-15 22:11 [PATCH] --enable-deterministic-archives and ar/ranlib -U Roland McGrath
2011-12-19 23:24 ` Roland McGrath
2011-12-20  8:50   ` Tristan Gingold
2011-12-20 17:23     ` Roland McGrath
2011-12-20 18:36       ` Roland McGrath
2011-12-20 19:26         ` Roland McGrath
2011-12-21 16:28           ` nick clifton
2011-12-21 21:13             ` Roland McGrath

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).