public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] Add an option to dlltool to allow the creation of deterministic libraries.
@ 2022-08-23  8:55 Nick Clifton
  0 siblings, 0 replies; only message in thread
From: Nick Clifton @ 2022-08-23  8:55 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=25ee24d990d6beb3fb01c673fcf13e0ea1522c5b

commit 25ee24d990d6beb3fb01c673fcf13e0ea1522c5b
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Aug 23 09:54:52 2022 +0100

    Add an option to dlltool to allow the creation of deterministic libraries.
    
            PR 29489
            * dlltool.c (deterministic): New variable.
            (gen_lib_file): If deterministic is true set the
            BFD_DETERMINISTIC_OUTPUT flag.
            (usage): Mention --deterministic-libraries and
            --non-deterministic-libraries.
            (long_options): Add new options.
            (main): Parse new options.
            * doc/binutils.texi: Document the new options.
            * NEWS: Mention the new feature.

Diff:
---
 binutils/ChangeLog         |  13 ++++++
 binutils/NEWS              |   5 +++
 binutils/dlltool.c         | 102 ++++++++++++++++++++++++++++-----------------
 binutils/doc/binutils.texi |   9 ++++
 4 files changed, 91 insertions(+), 38 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index e01db7db521..04ef77c5530 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,16 @@
+2022-08-23  Nick Clifton  <nickc@redhat.com>
+
+	PR 29489
+	* dlltool.c (deterministic): New variable.
+	(gen_lib_file): If deterministic is true set the
+	BFD_DETERMINISTIC_OUTPUT flag.
+	(usage): Mention --deterministic-libraries and
+	--non-deterministic-libraries.
+	(long_options): Add new options.
+	(main): Parse new options.
+	* doc/binutils.texi: Document the new options.
+	* NEWS: Mention the new feature.
+
 2022-08-22  Nick Clifton  <nickc@redhat.com>
 
 	* readelf.c (check_magic_number): New function.  Checks the magic
diff --git a/binutils/NEWS b/binutils/NEWS
index 4fdf1c3b4e8..8c2c416c17e 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,10 @@
 -*- text -*-
 
+* The dlltool program now accepts --deterministic-libraries and
+  --non-deterministic-libraries as command line options to control whether or
+  not it generates deterministic output libraries.  If neither of these options
+  are used the default is whatever was set when the binutils were configured.
+  
 Changes in 2.39:
 
 * Add --no-weak/-W option to nm to make it ignore weak symbols.
diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index e2af2084700..b4ac842212a 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -356,6 +356,7 @@ static char *imp_name;
 static char *delayimp_name;
 static char *identify_imp_name;
 static bool identify_strict;
+static bool deterministic = DEFAULT_AR_DETERMINISTIC;
 
 /* Types used to implement a linked list of dllnames associated
    with the specified import lib. Used by the identify_* code.
@@ -2942,6 +2943,9 @@ gen_lib_file (int delay)
   outarch->has_armap = 1;
   outarch->is_thin_archive = 0;
 
+  if (deterministic)
+    outarch->flags |= BFD_DETERMINISTIC_OUTPUT;
+
   /* Work out a reasonable size of things to put onto one line.  */
   if (delay)
     {
@@ -3674,6 +3678,16 @@ usage (FILE *file, int status)
   fprintf (file, _("   -e --output-exp <outname> Generate an export file.\n"));
   fprintf (file, _("   -l --output-lib <outname> Generate an interface library.\n"));
   fprintf (file, _("   -y --output-delaylib <outname> Create a delay-import library.\n"));
+  fprintf (file, _("      --deterministic-libraries\n"));
+  if (DEFAULT_AR_DETERMINISTIC)
+    fprintf (file, _("                             Use zero for timestamps and uids/gids in output libraries (default)\n"));
+  else
+    fprintf (file, _("                             Use zero for timestamps and uids/gids in output libraries\n"));
+  fprintf (file, _("      --non-deterministic-libraries\n"));
+  if (DEFAULT_AR_DETERMINISTIC)
+    fprintf (file, _("                             Use actual timestamps and uids/gids in output libraries\n"));
+  else
+    fprintf (file, _("                             Use actual timestamps and uids/gids in output libraries (default)\n"));
   fprintf (file, _("   -a --add-indirect         Add dll indirects to export file.\n"));
   fprintf (file, _("   -D --dllname <name>       Name of input dll to put into interface lib.\n"));
   fprintf (file, _("   -d --input-def <deffile>  Name of .def file to be read in.\n"));
@@ -3714,55 +3728,61 @@ usage (FILE *file, int status)
   exit (status);
 }
 
-#define OPTION_EXPORT_ALL_SYMS		150
-#define OPTION_NO_EXPORT_ALL_SYMS	(OPTION_EXPORT_ALL_SYMS + 1)
-#define OPTION_EXCLUDE_SYMS		(OPTION_NO_EXPORT_ALL_SYMS + 1)
-#define OPTION_NO_DEFAULT_EXCLUDES	(OPTION_EXCLUDE_SYMS + 1)
-#define OPTION_ADD_STDCALL_UNDERSCORE	(OPTION_NO_DEFAULT_EXCLUDES + 1)
-#define OPTION_USE_NUL_PREFIXED_IMPORT_TABLES \
-  (OPTION_ADD_STDCALL_UNDERSCORE + 1)
-#define OPTION_IDENTIFY_STRICT		(OPTION_USE_NUL_PREFIXED_IMPORT_TABLES + 1)
-#define OPTION_NO_LEADING_UNDERSCORE	(OPTION_IDENTIFY_STRICT + 1)
-#define OPTION_LEADING_UNDERSCORE	(OPTION_NO_LEADING_UNDERSCORE + 1)
+/* 150 isn't special; it's just an arbitrary non-ASCII char value.  */
+enum command_line_switch
+{
+  OPTION_EXPORT_ALL_SYMS = 150,
+  OPTION_NO_EXPORT_ALL_SYMS,
+  OPTION_EXCLUDE_SYMS,
+  OPTION_NO_DEFAULT_EXCLUDES,
+  OPTION_ADD_STDCALL_UNDERSCORE,
+  OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
+  OPTION_IDENTIFY_STRICT,
+  OPTION_NO_LEADING_UNDERSCORE,
+  OPTION_LEADING_UNDERSCORE,
+  OPTION_DETERMINISTIC_LIBRARIES,
+  OPTION_NON_DETERMINISTIC_LIBRARIES
+};
 
 static const struct option long_options[] =
 {
-  {"no-delete", no_argument, NULL, 'n'},
+  {"add-indirect", no_argument, NULL, 'a'},
+  {"add-stdcall-alias", no_argument, NULL, 'A'},
+  {"add-stdcall-underscore", no_argument, NULL, OPTION_ADD_STDCALL_UNDERSCORE},
+  {"add-underscore", no_argument, NULL, 'U'},
+  {"as", required_argument, NULL, 'S'},
+  {"as-flags", required_argument, NULL, 'f'},
+  {"base-file", required_argument, NULL, 'b'},
+  {"compat-implib", no_argument, NULL, 'C'},
+  {"def", required_argument, NULL, 'd'},     /* For compatibility with older versions.  */
+  {"deterministic-libraries", no_argument, NULL, OPTION_DETERMINISTIC_LIBRARIES},
   {"dllname", required_argument, NULL, 'D'},
-  {"no-idata4", no_argument, NULL, 'x'},
-  {"no-idata5", no_argument, NULL, 'c'},
-  {"use-nul-prefixed-import-tables", no_argument, NULL,
-   OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
-  {"output-exp", required_argument, NULL, 'e'},
-  {"output-def", required_argument, NULL, 'z'},
-  {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL_SYMS},
-  {"no-export-all-symbols", no_argument, NULL, OPTION_NO_EXPORT_ALL_SYMS},
   {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMS},
-  {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
-  {"output-lib", required_argument, NULL, 'l'},
-  {"def", required_argument, NULL, 'd'}, /* for compatibility with older versions */
-  {"input-def", required_argument, NULL, 'd'},
-  {"add-underscore", no_argument, NULL, 'U'},
-  {"add-stdcall-underscore", no_argument, NULL, OPTION_ADD_STDCALL_UNDERSCORE},
-  {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
-  {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
-  {"kill-at", no_argument, NULL, 'k'},
-  {"add-stdcall-alias", no_argument, NULL, 'A'},
+  {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL_SYMS},
   {"ext-prefix-alias", required_argument, NULL, 'p'},
+  {"help", no_argument, NULL, 'h'},
   {"identify", required_argument, NULL, 'I'},
   {"identify-strict", no_argument, NULL, OPTION_IDENTIFY_STRICT},
-  {"verbose", no_argument, NULL, 'v'},
-  {"version", no_argument, NULL, 'V'},
-  {"help", no_argument, NULL, 'h'},
+  {"input-def", required_argument, NULL, 'd'},
+  {"kill-at", no_argument, NULL, 'k'},
+  {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
   {"machine", required_argument, NULL, 'm'},
-  {"add-indirect", no_argument, NULL, 'a'},
-  {"base-file", required_argument, NULL, 'b'},
-  {"as", required_argument, NULL, 'S'},
-  {"as-flags", required_argument, NULL, 'f'},
   {"mcore-elf", required_argument, NULL, 'M'},
-  {"compat-implib", no_argument, NULL, 'C'},
-  {"temp-prefix", required_argument, NULL, 't'},
+  {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
+  {"no-delete", no_argument, NULL, 'n'},
+  {"no-export-all-symbols", no_argument, NULL, OPTION_NO_EXPORT_ALL_SYMS},
+  {"no-idata4", no_argument, NULL, 'x'},
+  {"no-idata5", no_argument, NULL, 'c'},
+  {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
+  {"non-deterministic-libraries", no_argument, NULL, OPTION_NON_DETERMINISTIC_LIBRARIES},
+  {"output-def", required_argument, NULL, 'z'},
   {"output-delaylib", required_argument, NULL, 'y'},
+  {"output-exp", required_argument, NULL, 'e'},
+  {"output-lib", required_argument, NULL, 'l'},
+  {"temp-prefix", required_argument, NULL, 't'},
+  {"use-nul-prefixed-import-tables", no_argument, NULL, OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
+  {"verbose", no_argument, NULL, 'v'},
+  {"version", no_argument, NULL, 'V'},
   {NULL,0,NULL,0}
 };
 
@@ -3924,6 +3944,12 @@ main (int ac, char **av)
 	case 'y':
 	  delayimp_name = optarg;
 	  break;
+	case OPTION_DETERMINISTIC_LIBRARIES:
+	  deterministic = true;
+	  break;
+	case OPTION_NON_DETERMINISTIC_LIBRARIES:
+	  deterministic = false;
+	  break;
 	default:
 	  usage (stderr, 1);
 	  break;
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 41f38f479f6..f61a619ec78 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -4510,6 +4510,7 @@ dlltool [@option{-d}|@option{--input-def} @var{def-file-name}]
         [@option{-v}|@option{--verbose}]
         [@option{-h}|@option{--help}] [@option{-V}|@option{--version}]
         [@option{--no-leading-underscore}] [@option{--leading-underscore}]
+        [@option{--deterministic-libraries}] [@option{--non-deterministic-libraries}]
         [object-file @dots{}]
 @c man end
 @end smallexample
@@ -4629,6 +4630,14 @@ Specifies the name of the library file to be created by dlltool.
 @itemx --output-delaylib @var{filename}
 Specifies the name of the delay-import library file to be created by dlltool.
 
+@item --deterministic-libraries
+@itemx --non-deterministic-libraries
+When creating output libraries in response to either the
+@option{--output-lib} or @option{--output-delaylib} options either use
+the value of zero for any timestamps, user ids and group ids created
+(@option{--deterministic-libraries}) or the actual timestamps, user
+ids and group ids (@option{--non-deterministic-libraries}).
+
 @item --export-all-symbols
 Treat all global and weak defined symbols found in the input object
 files as symbols to be exported.  There is a small list of symbols which

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-23  8:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23  8:55 [binutils-gdb] Add an option to dlltool to allow the creation of deterministic libraries Nick Clifton

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