Sourceware Bugzilla – Attachment 2839 Details for
Bug 6765
[PATCH] support symbol unbinding in objcopy
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to objcopy adding --unbind-symbol option
objcopy-unbind-2.19cvs.patch (text/plain), 8.19 KB, created by
Stephen Kell
on 2008-07-24 14:17:23 UTC
(
hide
)
Description:
Patch to objcopy adding --unbind-symbol option
Filename:
MIME Type:
Creator:
Stephen Kell
Created:
2008-07-24 14:17:23 UTC
Size:
8.19 KB
patch
obsolete
>--- objcopy.c 2008-06-12 12:57:40.000000000 +0100 >+++ objcopy-unbind.c 2008-07-24 14:56:07.000000000 +0100 >@@ -47,6 +47,14 @@ > struct redefine_node *next; > }; > >+struct unbind_node >+{ >+ char *sym; >+ char *ref_name; >+ char *def_name; >+ struct unbind_node *next; >+}; >+ > typedef struct section_rename > { > const char * old_name; >@@ -170,6 +178,13 @@ > asection *section; > }; > >+/* List of symbols to add. */ >+struct symbol_add >+{ >+ struct symbol_add *next; >+ asymbol *sp; >+}; >+ > /* List of sections to add to the output BFD. */ > static struct section_add *add_sections; > >@@ -202,6 +217,7 @@ > static htab_t keepglobal_specific_htab = NULL; > static htab_t weaken_specific_htab = NULL; > static struct redefine_node *redefine_sym_list = NULL; >+static struct unbind_node *unbind_sym_list = NULL; > > /* If this is TRUE, we weaken global symbols (set BSF_WEAK). */ > static bfd_boolean weaken = FALSE; >@@ -244,6 +260,7 @@ > OPTION_WEAKEN, > OPTION_REDEFINE_SYM, > OPTION_REDEFINE_SYMS, >+ OPTION_UNBIND_SYM, > OPTION_SREC_LEN, > OPTION_SREC_FORCES3, > OPTION_STRIP_SYMBOLS, >@@ -360,6 +377,7 @@ > {"readonly-text", no_argument, 0, OPTION_READONLY_TEXT}, > {"redefine-sym", required_argument, 0, OPTION_REDEFINE_SYM}, > {"redefine-syms", required_argument, 0, OPTION_REDEFINE_SYMS}, >+ {"unbind-sym", required_argument, 0, OPTION_UNBIND_SYM}, > {"remove-leading-char", no_argument, 0, OPTION_REMOVE_LEADING_CHAR}, > {"remove-section", required_argument, 0, 'R'}, > {"rename-section", required_argument, 0, OPTION_RENAME_SECTION}, >@@ -417,6 +435,8 @@ > static void mark_symbols_used_in_relocations (bfd *, asection *, void *); > static bfd_boolean write_debugging_info (bfd *, void *, long *, asymbol ***); > static const char *lookup_sym_redefinition (const char *); >+static const char *get_sym_unbound_ref_name (const char *); >+static const char *get_sym_unbound_def_name (const char *); > > static void > copy_usage (FILE *stream, int exit_status) >@@ -481,6 +501,7 @@ > --redefine-sym <old>=<new> Redefine symbol name <old> to <new>\n\ > --redefine-syms <file> --redefine-sym for all symbol pairs \n\ > listed in <file>\n\ >+ --unbind-sym <sym> Separate <sym> into __def_<sym> and __ref<sym>\n\ > --srec-len <number> Restrict the length of generated Srecords\n\ > --srec-forceS3 Restrict the type of generated Srecords to S3\n\ > --strip-symbols <file> -N for all symbols listed in <file>\n\ >@@ -947,6 +968,8 @@ > { > asymbol **from = isyms, **to = osyms; > long src_count = 0, dst_count = 0; >+ struct symbol_add *symbol_add_list = NULL; >+ struct symbol_add *sa_ptr; /* iterator for loop */ > int relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0; > > for (; src_count < symcount; src_count++) >@@ -971,6 +994,49 @@ > bfd_asymbol_name (sym) = new_name; > name = new_name; > } >+ >+ if (unbind_sym_list) >+ { >+ char *old_name, *new_name; >+ >+ old_name = (char *) bfd_asymbol_name (sym); >+ new_name = (char *) get_sym_unbound_ref_name (old_name); >+ bfd_asymbol_name (sym) = new_name; >+ name = new_name; >+ >+ if (new_name != old_name && !undefined) >+ { >+ /* We have renamed a symbol which must be unbound. >+ * Create a new symbol which is a copy of this one, >+ * renamed, and modify this one so that it is >+ * undefined. We will add the new symbols later, >+ * but keep them in a list for now. */ >+ >+ struct symbol_add *sa; >+ sa = xmalloc(sizeof (struct symbol_add)); >+ /* Make a new symbol. */ >+ sa->sp = bfd_make_empty_symbol (abfd); >+ /* Set name appropriately. */ >+ bfd_asymbol_name (sa->sp) = get_sym_unbound_def_name (old_name); >+ /* Set section, flags, value as in existing symbol. */ >+ bfd_set_section(sa->sp, bfd_get_section(sym)); >+ sa->sp->flags = sym->flags; >+ sa->sp->value = sym->value; >+ /* Copy private data. */ >+ bfd_copy_private_symbol_data(abfd, sym, obfd, sa->sp); >+ /* Add the new symbol to the list of new symbols. */ >+ sa->next = symbol_add_list; >+ symbol_add_list = sa; >+ >+ /* Update the old symbol's flags, section and value. */ >+ bfd_set_section(sym, bfd_und_section_ptr); >+ sym->value = 0; >+ sym->flags &= ~(BSF_LOCAL | BSF_GLOBAL | BSF_EXPORT | BSF_WEAK); >+ >+ /* The current symbol has now been made undefined. */ >+ undefined = 1; >+ } >+ } > > /* Check if we will remove the current leading character. */ > rem_leading_char = >@@ -1118,6 +1184,9 @@ > } > } > >+ for (sa_ptr = symbol_add_list; sa_ptr != NULL; sa_ptr = sa_ptr->next) >+ to[dst_count++] = sa_ptr->sp; >+ > to[dst_count] = NULL; > > return dst_count; >@@ -1137,6 +1206,38 @@ > return source; > } > >+/* Find the name to which the references to SOURCE should be rewritten */ >+ >+static const char * >+get_sym_unbound_ref_name (const char *sym) >+{ >+ struct unbind_node *list; >+ >+ for (list = unbind_sym_list; list != NULL; list = list->next) >+ if (strcmp (sym, list->sym) == 0) >+ { >+ return list->ref_name; >+ } >+ >+ return sym; >+} >+ >+/* Find the name to which the definition of SOURCE should be rewritten */ >+ >+static const char * >+get_sym_unbound_def_name (const char *sym) >+{ >+ struct unbind_node *list; >+ >+ for (list = unbind_sym_list; list != NULL; list = list->next) >+ if (strcmp (sym, list->sym) == 0) >+ { >+ return list->def_name; >+ } >+ >+ return sym; >+} >+ > /* Add a node to a symbol redefine list. */ > > static void >@@ -1166,6 +1267,40 @@ > *p = new_node; > } > >+static void >+unbind_list_append (const char *cause, const char *sym) >+{ >+ struct unbind_node **p; >+ struct unbind_node *list; >+ struct unbind_node *new_node; >+ const char def_prefix[] = "__def_"; >+ const char ref_prefix[] = "__ref_"; >+ size_t sym_len = strlen(sym); >+ >+ for (p = &unbind_sym_list; (list = *p) != NULL; p = &list->next) >+ { >+ if (strcmp (sym, list->sym) == 0) >+ fatal (_("%s: Multiple unbinding of symbol \"%s\""), >+ cause, sym); >+ } >+ >+ new_node = xmalloc (sizeof (struct unbind_node)); >+ >+ new_node->sym = strdup (sym); >+ >+ new_node->def_name = xmalloc (sizeof def_prefix + sym_len); >+ strncpy(new_node->def_name, def_prefix, sizeof def_prefix - 1); >+ strncpy(new_node->def_name + sizeof def_prefix - 1, sym, sym_len + 1); >+ >+ new_node->ref_name = xmalloc (sizeof ref_prefix + strlen(sym)); >+ strncpy(new_node->ref_name, ref_prefix, sizeof ref_prefix - 1); >+ strncpy(new_node->ref_name + sizeof ref_prefix - 1, sym, sym_len + 1); >+ >+ new_node->next = NULL; >+ >+ *p = new_node; >+} >+ > /* Handle the --redefine-syms option. Read lines containing "old new" > from the file, and add them to the symbol redefine list. */ > >@@ -1695,6 +1830,7 @@ > || change_leading_char > || remove_leading_char > || redefine_sym_list >+ || unbind_sym_list > || weaken) > { > /* Mark symbols used in output relocations so that they >@@ -1705,11 +1841,18 @@ > haven't been set yet. mark_symbols_used_in_relocations will > ignore input sections which have no corresponding output > section. */ >+ >+ int added_syms_upper_bound = 0; >+ struct unbind_node *n; >+ if (unbind_sym_list) >+ for (n = unbind_sym_list; n->next != NULL; n = n->next) >+ ++added_syms_upper_bound; >+ > if (strip_symbols != STRIP_ALL) > bfd_map_over_sections (ibfd, > mark_symbols_used_in_relocations, > isympp); >- osympp = xmalloc ((symcount + 1) * sizeof (asymbol *)); >+ osympp = xmalloc ((symcount + added_syms_upper_bound + 1) * sizeof (asymbol *)); > symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount); > } > >@@ -3228,7 +3371,14 @@ > case OPTION_REDEFINE_SYMS: > add_redefine_syms_file (optarg); > break; >- >+ >+ case OPTION_UNBIND_SYM: >+ { >+ /* Push this unbinding onto unbind_symbol_list. */ >+ unbind_list_append("--unbind-sym", optarg); >+ } >+ break; >+ > case OPTION_SET_SECTION_FLAGS: > { > const char *s;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 6765
: 2839