This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Prefixing sybmols/sections with objcopy


Hi all,

I would like to submit the following patch to objcopy for review. It adds the ability to globally prefix all symbols and/or sections with a given prefix to shift the name space.

A general copyright assignment has been signed by Ubicom.

Thanks

Nick


2002-10-25  Nick Kelsey  <nick@ubicom.com>

	* objcopy.c (rename feature extension): Added --prefix-symbols <prefix>
	option to rename all symbols by adding the given prefix to the begining
	of the symbol name. This is useful to provide name space seperation
	regardless of how the object file was created. Added --prefix-sections
	<prefix> and --prefix-alloc-sections <prefix> options to rename all
	sections (or all sections with the alloc flag set) by adding the given
	prefix to the begining of the symbol name.


cvs diff -p -r1.1.1.1 objcopy.c 
Index: objcopy.c
===================================================================
RCS file: /home/cvsadmin/cvsres/toolchain/src/binutils/objcopy.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -p -r1.1.1.1 -r1.2
*** objcopy.c	15 Oct 2002 17:14:35 -0000	1.1.1.1
--- objcopy.c	16 Oct 2002 02:00:33 -0000	1.2
*************** static struct redefine_node *redefine_sy
*** 215,220 ****
--- 215,225 ----
  /* If this is true, we weaken global symbols (set BSF_WEAK).  */
  static boolean weaken = false;
  
+ /* Prefix symbols/sections */
+ static char *prefix_symbols_string = 0;
+ static char *prefix_sections_string = 0;
+ static char *prefix_alloc_sections_string = 0;
+ 
  /* 150 isn't special; it's just an arbitrary non-ASCII char value.  */
  
  #define OPTION_ADD_SECTION 150
*************** static boolean weaken = false;
*** 244,249 ****
--- 249,257 ----
  #define OPTION_WEAKEN_SYMBOLS (OPTION_KEEPGLOBAL_SYMBOLS + 1)
  #define OPTION_RENAME_SECTION (OPTION_WEAKEN_SYMBOLS + 1)
  #define OPTION_ALT_MACH_CODE (OPTION_RENAME_SECTION + 1)
+ #define OPTION_PREFIX_SYMBOLS (OPTION_ALT_MACH_CODE + 1)
+ #define OPTION_PREFIX_SECTIONS (OPTION_PREFIX_SYMBOLS + 1)
+ #define OPTION_PREFIX_ALLOC_SECTIONS (OPTION_PREFIX_SECTIONS + 1)
  
  /* Options to handle if running as "strip".  */
  
*************** static struct option copy_options[] =
*** 331,336 ****
--- 339,347 ----
    {"localize-symbols", required_argument, 0, OPTION_LOCALIZE_SYMBOLS},
    {"weaken-symbols", required_argument, 0, OPTION_WEAKEN_SYMBOLS},
    {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE},
+   {"prefix-symbols", required_argument, 0, OPTION_PREFIX_SYMBOLS},
+   {"prefix-sections", required_argument, 0, OPTION_PREFIX_SECTIONS},
+   {"prefix-alloc-sections", required_argument, 0, OPTION_PREFIX_ALLOC_SECTIONS},
    {0, no_argument, 0, 0}
  };
  
*************** copy_usage (stream, exit_status)
*** 415,420 ****
--- 426,436 ----
       --keep-global-symbols <file>  -G for all symbols listed in <file>\n\
       --weaken-symbols <file>       -W for all symbols listed in <file>\n\
       --alt-machine-code <index>    Use alternate machine code for output\n\
+      --prefix-symbols <prefix>     Add <prefix> to start of every symbol name\n\
+      --prefix-sections <prefix>    Add <prefix> to start of every section name\n\
+      --prefix-alloc-sections <prefix>\n\
+                                    Add <prefix> to start of every allocatable\n\
+                                      section name\n\
    -v --verbose                     List all object files modified\n\
    -V --version                     Display this program's version number\n\
    -h --help                        Display this output\n\
*************** filter_symbols (abfd, obfd, osyms, isyms
*** 790,795 ****
--- 806,820 ----
  	  && name[0] == bfd_get_symbol_leading_char (abfd))
  	name = bfd_asymbol_name (sym) = name + 1;
  
+       if (prefix_symbols_string)
+         {
+           char *n;
+ 	  n = xmalloc (strlen (prefix_symbols_string) + strlen (name) + 1);
+           strcpy (n, prefix_symbols_string);
+           strcat (n, name);
+ 	  name = bfd_asymbol_name (sym) = n;
+         }
+ 
        if (strip_symbols == STRIP_ALL)
  	keep = 0;
        else if ((flags & BSF_KEEP) != 0		/* Used in relocation.  */
*************** copy_object (ibfd, obfd)
*** 1159,1165 ****
        || change_leading_char
        || remove_leading_char
        || redefine_sym_list
!       || weaken)
      {
        /* Mark symbols used in output relocations so that they
  	 are kept, even if they are local labels or static symbols.
--- 1184,1191 ----
        || change_leading_char
        || remove_leading_char
        || redefine_sym_list
!       || weaken
!       || prefix_symbols_string)      
      {
        /* Mark symbols used in output relocations so that they
  	 are kept, even if they are local labels or static symbols.
*************** setup_section (ibfd, isection, obfdarg)
*** 1597,1602 ****
--- 1623,1646 ----
    /* Get the, possibly new, name of the output section.  */
    name = find_section_rename (ibfd, isection, & flags);
  
+   /* Prefix sections */
+   if (prefix_sections_string)
+     {
+       char *n;
+       n = xmalloc (strlen (prefix_sections_string) + strlen (name) + 1);
+       strcpy (n, prefix_sections_string);
+       strcat (n, name);
+       name = n;
+     }
+   else if ((prefix_alloc_sections_string) && (bfd_get_section_flags(ibfd, isection) & SEC_ALLOC))
+     {
+       char *n;
+       n = xmalloc (strlen (prefix_alloc_sections_string) + strlen (name) + 1);
+       strcpy (n, prefix_alloc_sections_string);
+       strcat (n, name);
+       name = n;
+     }
+     
    osection = bfd_make_section_anyway (obfd, name);
  
    if (osection == NULL)
*************** copy_main (argc, argv)
*** 2552,2557 ****
--- 2596,2612 ----
  	  use_alt_mach_code = atoi (optarg);
  	  if (use_alt_mach_code <= 0)
  	    fatal (_("alternate machine code index must be positive"));
+ 	  break;
+ 	case OPTION_PREFIX_SYMBOLS:
+ 	  prefix_symbols_string = optarg;
+ 	  break;
+ 
+ 	case OPTION_PREFIX_SECTIONS:
+ 	  prefix_sections_string = optarg;
+ 	  break;
+ 
+ 	case OPTION_PREFIX_ALLOC_SECTIONS:
+ 	  prefix_alloc_sections_string = optarg;
  	  break;
  
  	case 0:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]