aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2016-06-23 22:11:57 +0930
committerAlan Modra <amodra@gmail.com>2016-06-24 23:26:29 +0930
commit9cc0123fea25379a1d57b700c078c7a9d0992f61 (patch)
treec6c60a576c0e646e2261abc15d3c84af7d458530 /binutils/objcopy.c
parent78da3bc1eeb8ed227f86154ef915635fe9047a64 (diff)
downloadgdb-9cc0123fea25379a1d57b700c078c7a9d0992f61.zip
gdb-9cc0123fea25379a1d57b700c078c7a9d0992f61.tar.gz
gdb-9cc0123fea25379a1d57b700c078c7a9d0992f61.tar.bz2
MIPS objcopy --rename-section fix
Some MIPS targets use a named section symbol rather than a symbol with no name as is used with most ELF targets. When renaming sections, the named section symbol needs to be renamed too. Rather than fix this bug, I'd originally intended to just correct the xfail added recently for update-1.o vs update4.o in update-section.exp, using the same set of targets for the localize-hidden-1 mips xfail. I'd extracted that target test into a new function, is_bad_symtab. It turns out to be useful in readelf.exp too. bfd/ * config.bfd: Delete mips vxworks patterns matched earlier. Combine mips*-*-none with mips*-*-elf*. binutils/ * objcopy.c (find_section_rename): Forward declare. Remove ibfd and sec_ptr param. Add old_name param. Allow for NULL returned_flags. Move read of section name and flags to.. (setup_section): ..here. Update find_section_rename call. (filter_symbols): Rename section symbols for renamed sections. (copy_object): Call filter_symbols when renamed sections. * testsuite/lib/binutils-common.exp (is_bad_symtab): New. * testsuite/binutils-all/update-section.exp: Revert 96037eb0 mips xfail. * testsuite/binutils-all/objcopy.exp (copy_executable): Use is_bad_symtab. (localize-hidden-1): xfail if is_bad_symtab. * testsuite/binutils-all/readelf.exp: Use is_bad_symtab to select between mips/tmips.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 76170cb..4bb625a 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -507,6 +507,7 @@ static int compare_section_lma (const void *, const void *);
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 *find_section_rename (const char *, flagword *);
static void
copy_usage (FILE *stream, int exit_status)
@@ -1390,12 +1391,14 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
to[dst_count++] = create_new_symbol (ptr, obfd);
}
- if (redefine_sym_list)
+ if (redefine_sym_list || section_rename_list)
{
- char *old_name, *new_name;
+ char *new_name;
- old_name = (char *) bfd_asymbol_name (sym);
- new_name = (char *) lookup_sym_redefinition (old_name);
+ new_name = (char *) lookup_sym_redefinition (name);
+ if (new_name == name
+ && (flags & BSF_SECTION_SYM) != 0)
+ new_name = (char *) find_section_rename (name, NULL);
bfd_asymbol_name (sym) = new_name;
name = new_name;
}
@@ -2357,6 +2360,7 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
|| change_leading_char
|| remove_leading_char
|| redefine_sym_list
+ || section_rename_list
|| weaken
|| add_symbols)
{
@@ -2937,24 +2941,19 @@ add_section_rename (const char * old_name, const char * new_name,
}
/* Check the section rename list for a new name of the input section
- ISECTION. Return the new name if one is found.
- Also set RETURNED_FLAGS to the flags to be used for this section. */
+ called OLD_NAME. Returns the new name if one is found and sets
+ RETURNED_FLAGS if non-NULL to the flags to be used for this section. */
static const char *
-find_section_rename (bfd * ibfd ATTRIBUTE_UNUSED, sec_ptr isection,
- flagword * returned_flags)
+find_section_rename (const char *old_name, flagword *returned_flags)
{
- const char * old_name = bfd_section_name (ibfd, isection);
- section_rename * srename;
-
- /* Default to using the flags of the input section. */
- * returned_flags = bfd_get_section_flags (ibfd, isection);
+ const section_rename *srename;
for (srename = section_rename_list; srename != NULL; srename = srename->next)
if (strcmp (srename->old_name, old_name) == 0)
{
- if (srename->flags != (flagword) -1)
- * returned_flags = srename->flags;
+ if (returned_flags != NULL && srename->flags != (flagword) -1)
+ *returned_flags = srename->flags;
return srename->new_name;
}
@@ -3004,7 +3003,9 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
return;
/* Get the, possibly new, name of the output section. */
- name = find_section_rename (ibfd, isection, & flags);
+ name = bfd_section_name (ibfd, isection);
+ flags = bfd_get_section_flags (ibfd, isection);
+ name = find_section_rename (name, &flags);
/* Prefix sections. */
if ((prefix_alloc_sections_string)