This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
old patch, --redefine-syms-file
- From: cgd at broadcom dot com
- To: binutils at sources dot redhat dot com
- Date: 23 Sep 2002 22:48:24 -0700
- Subject: old patch, --redefine-syms-file
Not an RFA, a submission for assignment purposes. IIRC, by the time
i'd gotten around to wanting to submit it, i didn't need it anymore
and conflicts led me to punt.
Some of the NetBSD folks expressed interest in using it for something,
so i figured i'd send it so they could clean it up or whatever. If
they or somebody else wants to run w/ the code or the idea, great.
no docs, no warranty, don't call me i won't call you. 8-)
chris
============
2001-03-21 Chris Demetriou <cgd@broadcom.com>
* objcopy.c (redefine_list_append): Add an argument that
indicates the context from which this function is being
called. Change all callers.
* objcopy.c (copy_options): Add a new option, --redefine-syms-file.
(copy_usage): Document new option.
(add_redefine_syms_file): New function to do most of the
processing for the new option.
(copy_main): Handle the --redefine-syms-file option.
* binutils.texi (objcopy): Document new option.
Index: objcopy.c
===================================================================
RCS file: /projects/bbp/cvsroot/systemsw/tools/src/binutils/binutils/objcopy.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -p -r1.3 -r1.4
--- objcopy.c 2000/10/17 00:09:42 1.3
+++ objcopy.c 2001/03/21 20:33:28 1.4
@@ -27,6 +27,7 @@
#include "budbg.h"
#include "filenames.h"
#include <sys/stat.h>
+#include <ctype.h>
/* A list of symbols to explicitly strip out, or to keep. A linked
list is good enough for a small number from the command line, but
@@ -70,8 +71,11 @@ static void copy_file
static int strip_main PARAMS ((int, char **));
static int copy_main PARAMS ((int, char **));
static const char *lookup_sym_redefinition PARAMS((const char *));
-static void redefine_list_append PARAMS ((const char *, const char *));
+static void redefine_list_append
+ PARAMS ((const char *, const char *, const char *));
+static void add_redefine_syms_file PARAMS ((const char *));
+
#define RETURN_NONFATAL(s) {bfd_nonfatal (s); status = 1; return;}
static asymbol **isympp = NULL; /* Input symbols */
@@ -215,6 +219,7 @@ static boolean weaken = false;
#define OPTION_STRIP_UNNEEDED (OPTION_SET_START + 1)
#define OPTION_WEAKEN (OPTION_STRIP_UNNEEDED + 1)
#define OPTION_REDEFINE_SYM (OPTION_WEAKEN + 1)
+#define OPTION_REDEFINE_SYMS_FILE (OPTION_REDEFINE_SYM + 1)
/* Options to handle if running as "strip". */
@@ -290,6 +295,7 @@ static struct option copy_options[] =
{"weaken", no_argument, 0, OPTION_WEAKEN},
{"weaken-symbol", required_argument, 0, 'W'},
{"redefine-sym", required_argument, 0, OPTION_REDEFINE_SYM},
+ {"redefine-syms-file", required_argument, 0, OPTION_REDEFINE_SYMS_FILE},
{0, no_argument, 0, 0}
};
@@ -350,6 +356,7 @@ copy_usage (stream, exit_status)
--change-leading-char Force output format's leading character style\n\
--remove-leading-char Remove leading character from global symbols\n\
--redefine-sym <old>=<new> Redefine symbol name <old> to <new>\n\
+ --redefine-syms-file <file> Use <file> as a list of symbol redefinitions\n\
-v --verbose List all object files modified\n\
-V --version Display this program's version number\n\
-h --help Display this output\n\
@@ -683,7 +690,8 @@ lookup_sym_redefinition (source)
/* Add a node to a symbol redefine list */
static void
-redefine_list_append (source, target)
+redefine_list_append (cause, source, target)
+ const char *cause;
const char *source;
const char *target;
{
@@ -696,15 +704,13 @@ redefine_list_append (source, target)
if (strcmp (source, list->source) == 0)
{
fatal (_("%s: Multiple redefinition of symbol \"%s\""),
- "--redefine-sym",
- source);
+ cause, source);
}
if (strcmp (target, list->target) == 0)
{
fatal (_("%s: Symbol \"%s\" is target of more than one redefinition"),
- "--redefine-sym",
- target);
+ cause, target);
}
}
@@ -717,7 +723,93 @@ redefine_list_append (source, target)
*p = new_node;
}
+/* Handle the --redefine-syms-file option. Read lines conataining "old new"
+ from the file, and add them to the symbol redefine list. */
+void
+add_redefine_syms_file (filename)
+ const char *filename;
+{
+ FILE *file;
+ char *buf;
+ size_t bufsize, len, outsym_off;
+ int c, lineno;
+
+ file = fopen (filename, "r");
+ if (file == (FILE *) NULL)
+ fatal (_("couldn't open symbol redefinition file %s (error: %s)"),
+ filename, strerror (errno));
+
+ bufsize = 100;
+ buf = (char *) xmalloc (bufsize);
+
+ lineno = 1;
+ c = getc (file);
+ len = 0;
+ while (c != EOF)
+ {
+ /* Collect the input symbol name. */
+ while (! isspace (c) && c != EOF)
+ {
+ buf[len++] = c;
+ if (len >= bufsize)
+ {
+ bufsize *= 2;
+ buf = xrealloc (buf, bufsize);
+ }
+ c = getc (file);
+ }
+ buf[len++] = '\0';
+ if (c == EOF)
+ break;
+
+ /* Eat white space between the symbol names. */
+ while (isspace (c))
+ c = getc (file);
+ if (c == EOF)
+ break;
+
+ /* Collect the output symbol name. */
+ outsym_off = len;
+ while (! isspace (c) && c != EOF)
+ {
+ buf[len++] = c;
+ if (len >= bufsize)
+ {
+ bufsize *= 2;
+ buf = xrealloc (buf, bufsize);
+ }
+ c = getc (file);
+ }
+ buf[len++] = '\0';
+ if (c == EOF)
+ break;
+
+ /* Eat white space at end of line. */
+ while (c != '\n' && isspace (c))
+ c = getc (file);
+ if (c == EOF)
+ break;
+ else if (c == '\n')
+ {
+ /* Append the redefinition to the list. */
+ redefine_list_append (filename, &buf[0], &buf[outsym_off]);
+
+ lineno++;
+ len = 0;
+ c = getc (file);
+ continue;
+ }
+ else
+ fatal (_("%s: garbage at end of line %d"), filename, lineno);
+ }
+ if (len != 0)
+ fatal (_("%s: premature end of file at line %d"), filename, lineno);
+
+ free (buf);
+}
+
+
/* Keep only every `copy_byte'th byte in MEMHUNK, which is *SIZE bytes long.
Adjust *SIZE. */
@@ -2095,11 +2187,15 @@ copy_main (argc, argv)
target = (char *) xmalloc (len + 1);
strcpy (target, nextarg);
- redefine_list_append (source, target);
+ redefine_list_append ("--redefine-sym", source, target);
free (source);
free (target);
}
+ break;
+
+ case OPTION_REDEFINE_SYMS_FILE:
+ add_redefine_syms_file (optarg);
break;
case OPTION_SET_SECTION_FLAGS: