]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Support -D in ranlib as in ar.
authorRoland McGrath <roland@hack.frob.com>
Fri, 20 Jan 2012 19:40:59 +0000 (11:40 -0800)
committerRoland McGrath <roland@hack.frob.com>
Fri, 20 Jan 2012 19:40:59 +0000 (11:40 -0800)
NEWS
src/ChangeLog
src/Makefile.am
src/ar.c
src/arlib-argp.c [new file with mode: 0644]
src/arlib.c
src/arlib.h
src/ranlib.c

diff --git a/NEWS b/NEWS
index 324644dd85087ce1b77710c1071060b5cddd1258..9d62d1768bcfb3225429c32c6ab9778c40206eaa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ libdw: Support reading .zdebug_* DWARF sections compressed via zlib.
 nm: Support C++ demangling.
 
 ar: Support D modifier for "deterministic output" with no uid/gid/mtime info.
+ranlib: Support -D flag with same meaning.
 
 Version 0.152
 
index bef7f94377a259662b80aaed2b01a8b3e67eaa74..22212f9b9a568141c0b7e7175dee31798655ed81 100644 (file)
@@ -1,3 +1,18 @@
+2012-01-20  Roland McGrath  <roland@hack.frob.com>
+
+       * ranlib.c (argp): Use arlib_argp_children.
+
+       * arlib.c (arlib_init): Obey arlib_deterministic_output.
+
+       * arlib-argp.c: New file.
+       * Makefile.am (libar_a_SOURCES): Add it.
+       * arlib.h (arlib_deterministic_output, arlib_argp_children):
+       Declare new variables.
+       * ar.c (deterministic_output): Variable removed.
+       (do_oper_insert): Use arlib_deterministic_output instead.
+       (options, parse_opt): Don't handle -D here.  Add group numbers.
+       (argp): Use arlib_argp_children.
+
 2011-12-20  Roland McGrath  <roland@hack.frob.com>
 
        * readelf.c (print_debug): Initialize DUMMY_DBG.elf.
index 4d1484c2cc49c4f7ae33e18318f97bd252506424..dc835cbd9dcc0ba691984a1e745f28cb11c3ea00 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 1996-2011 Red Hat, Inc.
+## Copyright (C) 1996-2012 Red Hat, Inc.
 ## This file is part of Red Hat elfutils.
 ##
 ## Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -67,7 +67,7 @@ endif
 ld_SOURCES = ld.c ldgeneric.c ldlex.l ldscript.y symbolhash.c sectionhash.c \
             versionhash.c
 
-libar_a_SOURCES = arlib.c arlib2.c
+libar_a_SOURCES = arlib.c arlib2.c arlib-argp.c
 
 noinst_HEADERS = ld.h symbolhash.h sectionhash.h versionhash.h \
                 ldscript.h xelf.h unaligned.h
index ce5078e499efc187483b83d233d8c0eaeb26efeb..72b0237f502630e1660285a885ba2267eb60263a 100644 (file)
--- a/src/ar.c
+++ b/src/ar.c
@@ -73,7 +73,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
 /* Definitions of arguments for argp functions.  */
 static const struct argp_option options[] =
 {
-  { NULL, 0, NULL, 0, N_("Commands:"), 0 },
+  { NULL, 0, NULL, 0, N_("Commands:"), 1 },
   { NULL, 'd', NULL, 0, N_("Delete files from archive."), 0 },
   { NULL, 'm', NULL, 0, N_("Move files in archive."), 0 },
   { NULL, 'p', NULL, 0, N_("Print files in archive."), 0 },
@@ -83,7 +83,7 @@ static const struct argp_option options[] =
   { NULL, 't', NULL, 0, N_("Display content of archive."), 0 },
   { NULL, 'x', NULL, 0, N_("Extract files from archive."), 0 },
 
-  { NULL, 0, NULL, 0, N_("Command Modifiers:"), 0 },
+  { NULL, 0, NULL, 0, N_("Command Modifiers:"), 2 },
   { NULL, 'o', NULL, 0, N_("Preserve original dates."), 0 },
   { NULL, 'N', NULL, 0, N_("Use instance [COUNT] of name."), 0 },
   { NULL, 'C', NULL, 0,
@@ -95,8 +95,6 @@ static const struct argp_option options[] =
   { NULL, 'a', NULL, 0, N_("Insert file after [MEMBER]."), 0 },
   { NULL, 'b', NULL, 0, N_("Insert file before [MEMBER]."), 0 },
   { NULL, 'i', NULL, 0, N_("Same as -b."), 0 },
-  { NULL, 'D', NULL, 0,
-    N_("Use zero for uid, gid, and date in archive members."), 0 },
   { NULL, 'c', NULL, 0, N_("Suppress message when library has to be created."),
     0 },
   { NULL, 'P', NULL, 0, N_("Use full path for file matching."), 0 },
@@ -117,7 +115,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state);
 /* Data structure to communicate with argp functions.  */
 static struct argp argp =
 {
-  options, parse_opt, args_doc, doc, NULL, NULL, NULL
+  options, parse_opt, args_doc, doc, arlib_argp_children, NULL, NULL
 };
 
 
@@ -143,7 +141,6 @@ static bool allow_truncate_fname;
 static bool force_symtab;
 static bool suppress_create_msg;
 static bool full_path;
-static bool deterministic_output;
 static bool update_newer;
 static enum { ipos_none, ipos_before, ipos_after } ipos;
 
@@ -383,10 +380,6 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
       allow_truncate_fname = true;
       break;
 
-    case 'D':
-      deterministic_output = true;
-      break;
-
     case 'u':
       update_newer = true;
       break;
@@ -1302,9 +1295,9 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
                        found[cnt]->old_off == -1l ? 'a' : 'r', argv[cnt]);
 
              found[cnt]->elf = newelf;
-             found[cnt]->sec = deterministic_output ? 0 : newst.st_mtime;
-             found[cnt]->uid = deterministic_output ? 0 : newst.st_uid;
-             found[cnt]->gid = deterministic_output ? 0 : newst.st_gid;
+             found[cnt]->sec = arlib_deterministic_output ? 0 : newst.st_mtime;
+             found[cnt]->uid = arlib_deterministic_output ? 0 : newst.st_uid;
+             found[cnt]->gid = arlib_deterministic_output ? 0 : newst.st_gid;
              found[cnt]->mode = newst.st_mode;
              found[cnt]->name = bname;
 
diff --git a/src/arlib-argp.c b/src/arlib-argp.c
new file mode 100644 (file)
index 0000000..af19a25
--- /dev/null
@@ -0,0 +1,67 @@
+/* Options common to ar and ranlib.
+   Copyright (C) 2012 Red Hat, Inc.
+
+   Red Hat elfutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by the
+   Free Software Foundation; version 2 of the License.
+
+   Red Hat elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <argp.h>
+#include "arlib.h"
+
+bool arlib_deterministic_output;
+
+static const struct argp_option options[] =
+  {
+    { NULL, 'D', NULL, 0,
+      N_("Use zero for uid, gid, and date in archive members."), 0 },
+
+    { NULL, 0, NULL, 0, NULL, 0 }
+  };
+
+static error_t
+parse_opt (int key, char *arg __attribute__ ((unused)),
+           struct argp_state *state __attribute__ ((unused)))
+{
+  switch (key)
+    {
+    case 'D':
+      arlib_deterministic_output = true;
+      break;
+
+    default:
+      return ARGP_ERR_UNKNOWN;
+    }
+  return 0;
+}
+
+static const struct argp argp =
+  {
+    options, parse_opt, NULL, NULL, NULL, NULL, NULL
+  };
+
+const struct argp_child arlib_argp_children[] =
+  {
+    { &argp, 0, "", 2 },
+    { NULL, }
+  };
index c69a138f30b4543b4682841e52e9c0e54a53ef81..bcf9344bd4fb25fd6a6481c9b3e8b369a3ca1e7a 100644 (file)
@@ -1,5 +1,5 @@
 /* Functions to handle creation of Linux archives.
-   Copyright (C) 2007 Red Hat, Inc.
+   Copyright (C) 2007-2012 Red Hat, Inc.
    Written by Ulrich Drepper <drepper@redhat.com>, 2007.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -69,7 +69,8 @@ arlib_init (void)
   memcpy (ar_hdr.ar_date, tmpbuf,
          snprintf (tmpbuf, sizeof (tmpbuf), "%-*lld",
                    (int) sizeof (ar_hdr.ar_date),
-                   (long long int) time (NULL)));
+                    (arlib_deterministic_output ? 0
+                     : (long long int) time (NULL))));
   assert ((sizeof (struct ar_hdr)  % sizeof (uint32_t)) == 0);
 
   /* Note the string for the ar_uid and ar_gid cases is longer than
index fd26d248843c584b5b9610393d4ac8990a96f782..ea77b23ed870ab153644284a6b21a078d3822b18 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007 Red Hat, Inc.
+/* Copyright (C) 2007-2012 Red Hat, Inc.
    Written by Ulrich Drepper <drepper@redhat.com>, 2007.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
 #define _ARLIB_H       1
 
 #include <ar.h>
+#include <argp.h>
 #include <byteswap.h>
 #include <endian.h>
 #include <libelf.h>
 #include <obstack.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <sys/types.h>
 
 
+/* State of -D/-U flags.  */
+extern bool arlib_deterministic_output;
+
+/* For options common to ar and ranlib.  */
+extern const struct argp_child arlib_argp_children[];
+
+
 /* Maximum length of a file name that fits directly into the ar header.
    We cannot use the final byte since a / goes there.  */
 #define MAX_AR_NAME_LEN (sizeof (((struct ar_hdr *) NULL)->ar_name) - 1)
index e92dc89b414fa089b8929c29925843f2dfa9fcef..cf2f127065a005620e6dc025b12b8cf557621b72 100644 (file)
@@ -1,5 +1,5 @@
 /* Generate an index to speed access to archives.
-   Copyright (C) 2005, 2006, 2007, 2009 Red Hat, Inc.
+   Copyright (C) 2005-2012 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2005.
 
@@ -79,7 +79,7 @@ static const char args_doc[] = N_("ARCHIVE");
 /* Data structure to communicate with argp functions.  */
 static const struct argp argp =
 {
-  options, NULL, args_doc, doc, NULL, NULL, NULL
+  options, NULL, args_doc, doc, arlib_argp_children, NULL, NULL
 };