This is the mail archive of the
crossgcc@cygnus.com
mailing list for the crossgcc project.
Re: underscore - coff vs. aout
- To: crossgcc@cygnus.com
- Subject: Re: underscore - coff vs. aout
- From: Luke Diamand <lgd@virata.com>
- Date: Tue, 13 Jul 1999 13:10:31 +0100
- References: <9269.931823117@upchuck.cygnus.com>
- Reply-To: crossgcc@cygnus.com
Jeffrey A Law wrote:
>
> In message <19990712164331.A6325@tempest.ece.uiuc.edu>you write:
> > Doesn't objcopy support symbol renaming? You could just write a script
> > to call objcopy for each symbol. If it's just a one-time shot, no big
> > deal.
> It might. I haven't looked at the guts of objcopy in a long time, it
> certainly didn't back in the early 90s when I had to do this sort of
> thing (and others) to support function virtualization in existing .o files.
>
> jeff
Regular objcopy (IIRC) doesn't do symbol renaming, but a colleague here
recently patched it to do simple renaming (the patch has gone to the
maintainer, but hasn't come back out again so far as I know).
I've attached the patch.
> _______________________________________________
> New CrossGCC FAQ: http://www.objsw.com/CrossGCC
> _______________________________________________
> To remove yourself from the crossgcc list, send
> mail to crossgcc-request@cygnus.com with the
> text 'unsubscribe' (without the quotes) in the
> body of the message.
--
Virata http://www.virata.com
Cambridge
Tel: +44 1223 566919 Fax: +44 1223 566915
Index: objcopy.c
===================================================================
RCS file: /cvsroot/tools/gnu/binutils/binutils/objcopy.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -c -r1.1 -r1.2
*** objcopy.c 1999/06/16 14:18:36 1.1
--- objcopy.c 1999/06/16 15:10:46 1.2
***************
*** 146,151 ****
--- 146,155 ----
static boolean remove_leading_char = false;
+ /* Whether to prefix global defined symbol names. */
+ static boolean prefix_defined_symbols = false;
+ static char *prefix_text = NULL;
+
/* 150 isn't special; it's just an arbitrary non-ASCII char value. */
#define OPTION_ADD_SECTION 150
***************
*** 163,168 ****
--- 167,173 ----
#define OPTION_SET_START (OPTION_SET_SECTION_FLAGS + 1)
#define OPTION_STRIP_UNNEEDED (OPTION_SET_START + 1)
#define OPTION_WEAKEN (OPTION_STRIP_UNNEEDED + 1)
+ #define OPTION_PREFIX_DEFINED_SYMBOLS (OPTION_WEAKEN + 1)
/* Options to handle if running as "strip". */
***************
*** 199,204 ****
--- 204,210 ----
{"adjust-warnings", no_argument, 0, OPTION_ADJUST_WARNINGS},
{"byte", required_argument, 0, 'b'},
{"change-leading-char", no_argument, 0, OPTION_CHANGE_LEADING_CHAR},
+ {"prefix-defined-symbols", required_argument, 0, OPTION_PREFIX_DEFINED_SYMBOLS},
{"debugging", no_argument, 0, OPTION_DEBUGGING},
{"discard-all", no_argument, 0, 'x'},
{"discard-locals", no_argument, 0, 'X'},
***************
*** 257,263 ****
[--set-section-flags=section=flags] [--add-section=sectionname=filename]\n\
[--keep-symbol symbol] [-K symbol] [--strip-symbol symbol] [-N symbol]\n\
[--change-leading-char] [--remove-leading-char] [--weaken] [--verbose]\n\
! [--version] [--help] in-file [out-file]\n");
list_supported_targets (program_name, stream);
if (exit_status == 0)
fprintf (stream, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n");
--- 263,269 ----
[--set-section-flags=section=flags] [--add-section=sectionname=filename]\n\
[--keep-symbol symbol] [-K symbol] [--strip-symbol symbol] [-N symbol]\n\
[--change-leading-char] [--remove-leading-char] [--weaken] [--verbose]\n\
! [--prefix-defined-symbols prefix] [--version] [--help] in-file [out-file]\n");
list_supported_targets (program_name, stream);
if (exit_status == 0)
fprintf (stream, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n");
***************
*** 452,457 ****
--- 458,476 ----
flagword flags = sym->flags;
int keep;
+ if (prefix_defined_symbols) {
+ if ((flags & BSF_GLOBAL) != 0 /* Global defined symbol. */
+ || (flags & BSF_WEAK) != 0
+ || bfd_is_com_section (bfd_get_section (sym))) {
+ char *n;
+
+ n = xmalloc (strlen (bfd_asymbol_name (sym)) + strlen(prefix_text) + 1);
+ strcpy(n, prefix_text);
+ strcpy(n + strlen (prefix_text), bfd_asymbol_name (sym));
+ bfd_asymbol_name (sym) = n;
+ }
+ }
+
if (change_leading_char
&& (bfd_get_symbol_leading_char (abfd)
!= bfd_get_symbol_leading_char (obfd))
***************
*** 535,540 ****
--- 554,635 ----
*size /= interleave;
}
+ /* Blah */
+ static void
+ rename_symbols (abfd, dynamic, minisyms, symcount, size)
+ bfd *abfd;
+ boolean dynamic;
+ PTR minisyms;
+ long symcount;
+ unsigned int size;
+ {
+ bfd_byte *from, *fromend, *to;
+ asymbol *store;
+
+ printf("%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__);
+
+
+
+ store = bfd_make_empty_symbol (abfd);
+ if (store == NULL)
+ bfd_fatal (bfd_get_filename (abfd));
+
+ from = (bfd_byte *) minisyms;
+ fromend = from + symcount * size;
+ to = (bfd_byte *) minisyms;
+
+ for (; from < fromend; from += size)
+ {
+ int keep = 0;
+ asymbol *sym;
+
+ sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from, store);
+ if (sym == NULL)
+ bfd_fatal (bfd_get_filename (abfd));
+
+ printf("%s\n",sym->name);
+
+ #if 0
+ if (undefined_only)
+ keep = bfd_is_und_section (sym->section);
+ else if (external_only)
+ keep = ((sym->flags & BSF_GLOBAL) != 0
+ || (sym->flags & BSF_WEAK) != 0
+ || bfd_is_und_section (sym->section)
+ || bfd_is_com_section (sym->section));
+ else
+ keep = 1;
+
+ if (keep
+ && ! print_debug_syms
+ && (sym->flags & BSF_DEBUGGING) != 0)
+ keep = 0;
+
+ if (keep
+ && sort_by_size
+ && (bfd_is_abs_section (sym->section)
+ || bfd_is_und_section (sym->section)))
+ keep = 0;
+
+ if (keep
+ && defined_only)
+ {
+ if (bfd_is_und_section (sym->section))
+ keep = 0;
+ }
+
+ if (keep)
+ {
+ memcpy (to, from, size);
+ to += size;
+ }
+ #endif
+ }
+
+ return;
+ }
+
+
/* Copy object file IBFD onto OBFD. */
static void
***************
*** 751,757 ****
if (convert_debugging)
dhandle = read_debugging_info (ibfd, isympp, symcount);
!
if (strip_symbols == strip_debug
|| strip_symbols == strip_unneeded
|| discard_locals != locals_undef
--- 846,852 ----
if (convert_debugging)
dhandle = read_debugging_info (ibfd, isympp, symcount);
!
if (strip_symbols == strip_debug
|| strip_symbols == strip_unneeded
|| discard_locals != locals_undef
***************
*** 760,766 ****
|| convert_debugging
|| change_leading_char
|| remove_leading_char
! || weaken)
{
/* Mark symbols used in output relocations so that they
are kept, even if they are local labels or static symbols.
--- 855,862 ----
|| convert_debugging
|| change_leading_char
|| remove_leading_char
! || weaken
! || prefix_defined_symbols)
{
/* Mark symbols used in output relocations so that they
are kept, even if they are local labels or static symbols.
***************
*** 1876,1881 ****
--- 1972,1987 ----
case OPTION_CHANGE_LEADING_CHAR:
change_leading_char = true;
break;
+ case OPTION_PREFIX_DEFINED_SYMBOLS:
+ prefix_defined_symbols = true;
+ {
+ char *n;
+
+ n = xmalloc(strlen(optarg) + 1);
+ strcpy(n, optarg);
+ prefix_text = n;
+ }
+ break;
case OPTION_DEBUGGING:
convert_debugging = true;
break;