bfd/
authorAlan Modra <amodra@gmail.com>
Mon, 8 Nov 2010 02:48:57 +0000 (02:48 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 8 Nov 2010 02:48:57 +0000 (02:48 +0000)
* hash.c (bfd_hash_hash): Extract from..
(bfd_hash_lookup): ..here.
(bfd_hash_rename): New function.
* section.c (bfd_rename_section): New function.
* bfd-in.h (bfd_hash_rename): Declare.
* bfd-in2.h: Regenerate.
* elf.c (_bfd_elf_make_section_from_shdr): Rename input sections
when compressing or decompressing.  Don't assert name match.
* elf64-hppa.c (get_reloc_section): Don't assert name match.
* elfxx-ia64.c (get_reloc_section): Likewise.
binutils/
* objcopy.c (copy_main): No need to rename sections when compressing
or decompressing.
binutils/testsuite/
* binutils-all/objdump.W: Adjust expected result for debug section
rename.

12 files changed:
bfd/ChangeLog
bfd/bfd-in.h
bfd/bfd-in2.h
bfd/elf.c
bfd/elf64-hppa.c
bfd/elfxx-ia64.c
bfd/hash.c
bfd/section.c
binutils/ChangeLog
binutils/objcopy.c
binutils/testsuite/ChangeLog
binutils/testsuite/binutils-all/objdump.W

index 78b904af7ca6fc527285700ae635153040048b5c..bd33568706039d6e2324e18767628193a5c24fb3 100644 (file)
@@ -1,3 +1,16 @@
+2010-11-08  Alan Modra  <amodra@gmail.com>
+
+       * hash.c (bfd_hash_hash): Extract from..
+       (bfd_hash_lookup): ..here.
+       (bfd_hash_rename): New function.
+       * section.c (bfd_rename_section): New function.
+       * bfd-in.h (bfd_hash_rename): Declare.
+       * bfd-in2.h: Regenerate.
+       * elf.c (_bfd_elf_make_section_from_shdr): Rename input sections
+       when compressing or decompressing.  Don't assert name match.
+       * elf64-hppa.c (get_reloc_section): Don't assert name match.
+       * elfxx-ia64.c (get_reloc_section): Likewise.
+
 2010-11-05  Joseph Myers  <joseph@codesourcery.com>
 
        * elf32-tic6x.c (elf32_tic6x_obj_attrs_handle_unknown): New.
index cfa5225325bf308dc2a949b93327a9397007f31d..63fcdc9bb42a12752d02be4c687a49c792eba5e6 100644 (file)
@@ -404,6 +404,10 @@ extern struct bfd_hash_entry *bfd_hash_lookup
 extern struct bfd_hash_entry *bfd_hash_insert
   (struct bfd_hash_table *, const char *, unsigned long);
 
+/* Rename an entry in a hash table.  */
+extern void bfd_hash_rename
+  (struct bfd_hash_table *, const char *, struct bfd_hash_entry *);
+
 /* Replace an entry in a hash table.  */
 extern void bfd_hash_replace
   (struct bfd_hash_table *, struct bfd_hash_entry *old,
index c6a54b5acbeeb893aee8d34e58106bcdfde1f60c..f3e2b457913fe2a4a045e3fd74871c14f4a614c2 100644 (file)
@@ -411,6 +411,10 @@ extern struct bfd_hash_entry *bfd_hash_lookup
 extern struct bfd_hash_entry *bfd_hash_insert
   (struct bfd_hash_table *, const char *, unsigned long);
 
+/* Rename an entry in a hash table.  */
+extern void bfd_hash_rename
+  (struct bfd_hash_table *, const char *, struct bfd_hash_entry *);
+
 /* Replace an entry in a hash table.  */
 extern void bfd_hash_replace
   (struct bfd_hash_table *, struct bfd_hash_entry *old,
@@ -1713,6 +1717,9 @@ asection *bfd_make_section (bfd *, const char *name);
 bfd_boolean bfd_set_section_flags
    (bfd *abfd, asection *sec, flagword flags);
 
+void bfd_rename_section
+   (bfd *abfd, asection *sec, const char *newname);
+
 void bfd_map_over_sections
    (bfd *abfd,
     void (*func) (bfd *abfd, asection *sect, void *obj),
index 4f326a7ae538d1354f4629f0bd9d6279c0998463..075a668c3089c5d09868565c305d2ea5f59dc78f 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -822,11 +822,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
   const struct elf_backend_data *bed;
 
   if (hdr->bfd_section != NULL)
-    {
-      BFD_ASSERT (strcmp (name,
-                         bfd_get_section_name (abfd, hdr->bfd_section)) == 0);
-      return TRUE;
-    }
+    return TRUE;
 
   newsect = bfd_make_section_anyway (abfd, name);
   if (newsect == NULL)
@@ -1016,6 +1012,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
          || (name[1] == 'z' && name[7] == '_')))
     {
       enum { nothing, compress, decompress } action = nothing;
+      char *new_name;
 
       if (bfd_is_section_compressed (abfd, newsect))
        {
@@ -1030,6 +1027,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
            action = compress;
        }
 
+      new_name = NULL;
       switch (action)
        {
        case nothing:
@@ -1042,6 +1040,17 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
                 abfd, name);
              return FALSE;
            }
+         if (name[1] != 'z')
+           {
+             unsigned int len = strlen (name);
+
+             new_name = bfd_alloc (abfd, len + 2);
+             if (new_name == NULL)
+               return FALSE;
+             new_name[0] = '.';
+             new_name[1] = 'z';
+             memcpy (new_name + 2, name + 1, len);
+           }
          break;
        case decompress:
          if (!bfd_init_section_decompress_status (abfd, newsect))
@@ -1051,8 +1060,20 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
                 abfd, name);
              return FALSE;
            }
+         if (name[1] == 'z')
+           {
+             unsigned int len = strlen (name);
+
+             new_name = bfd_alloc (abfd, len);
+             if (new_name == NULL)
+               return FALSE;
+             new_name[0] = '.';
+             memcpy (new_name + 1, name + 2, len - 1);
+           }
          break;
        }
+      if (new_name != NULL)
+       bfd_rename_section (abfd, newsect, new_name);
     }
 
   return TRUE;
index 11289b13916d06c8e70654cb33f70f5e0148b32d..d8213a01a8ac80a2cc30fa5b7b78ed5f12f1e426 100644 (file)
@@ -411,13 +411,6 @@ get_reloc_section (bfd *abfd,
   if (srel_name == NULL)
     return FALSE;
 
-  BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
-              && strcmp (bfd_get_section_name (abfd, sec),
-                         srel_name + 5) == 0)
-             || (CONST_STRNEQ (srel_name, ".rel")
-                 && strcmp (bfd_get_section_name (abfd, sec),
-                            srel_name + 4) == 0));
-
   dynobj = hppa_info->root.dynobj;
   if (!dynobj)
     hppa_info->root.dynobj = dynobj = abfd;
index 0ef1a442d9ea38e319428b61f7184c822cdffc6c..d42ad8921215647ad508a01b7e190aa3be48dc7f 100644 (file)
@@ -2602,13 +2602,6 @@ get_reloc_section (bfd *abfd,
   if (srel_name == NULL)
     return NULL;
 
-  BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
-              && strcmp (bfd_get_section_name (abfd, sec),
-                         srel_name+5) == 0)
-             || (CONST_STRNEQ (srel_name, ".rel")
-                 && strcmp (bfd_get_section_name (abfd, sec),
-                            srel_name+4) == 0));
-
   dynobj = ia64_info->root.dynobj;
   if (!dynobj)
     ia64_info->root.dynobj = dynobj = abfd;
index fc05923a5ca7d59cb9122883c71a6a56bd45e941..e2fa3a91385de48fbb6d41e542dc33c326ac4b59 100644 (file)
@@ -1,6 +1,6 @@
 /* hash.c -- hash table routines for BFD
    Copyright 1993, 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007, 2009 Free Software Foundation, Inc.
+   2006, 2007, 2009, 2010 Free Software Foundation, Inc.
    Written by Steve Chamberlain <sac@cygnus.com>
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -412,20 +412,13 @@ bfd_hash_table_free (struct bfd_hash_table *table)
   table->memory = NULL;
 }
 
-/* Look up a string in a hash table.  */
-
-struct bfd_hash_entry *
-bfd_hash_lookup (struct bfd_hash_table *table,
-                const char *string,
-                bfd_boolean create,
-                bfd_boolean copy)
+static inline unsigned long
+bfd_hash_hash (const char *string, unsigned int *lenp)
 {
   const unsigned char *s;
   unsigned long hash;
-  unsigned int c;
-  struct bfd_hash_entry *hashp;
   unsigned int len;
-  unsigned int _index;
+  unsigned int c;
 
   hash = 0;
   len = 0;
@@ -438,7 +431,25 @@ bfd_hash_lookup (struct bfd_hash_table *table,
   len = (s - (const unsigned char *) string) - 1;
   hash += len + (len << 17);
   hash ^= hash >> 2;
+  if (lenp != NULL)
+    *lenp = len;
+  return hash;
+}
+
+/* Look up a string in a hash table.  */
 
+struct bfd_hash_entry *
+bfd_hash_lookup (struct bfd_hash_table *table,
+                const char *string,
+                bfd_boolean create,
+                bfd_boolean copy)
+{
+  unsigned long hash;
+  struct bfd_hash_entry *hashp;
+  unsigned int len;
+  unsigned int _index;
+
+  hash = bfd_hash_hash (string, &len);
   _index = hash % table->size;
   for (hashp = table->table[_index];
        hashp != NULL;
@@ -535,6 +546,31 @@ bfd_hash_insert (struct bfd_hash_table *table,
   return hashp;
 }
 
+/* Rename an entry in a hash table.  */
+
+void
+bfd_hash_rename (struct bfd_hash_table *table,
+                const char *string,
+                struct bfd_hash_entry *ent)
+{
+  unsigned int _index;
+  struct bfd_hash_entry **pph;
+
+  _index = ent->hash % table->size;
+  for (pph = &table->table[_index]; *pph != NULL; pph = &(*pph)->next)
+    if (*pph == ent)
+      break;
+  if (*pph == NULL)
+    abort ();
+
+  *pph = ent->next;
+  ent->string = string;
+  ent->hash = bfd_hash_hash (string, NULL);
+  _index = ent->hash % table->size;
+  ent->next = table->table[_index];
+  table->table[_index] = ent;
+}
+
 /* Replace an entry in a hash table.  */
 
 void
index 51c2196bc44519d0337977bbf9d5c2ec341c50f9..bff8adfb0784f62bfca35b111e8acad6555a18de 100644 (file)
@@ -1213,6 +1213,29 @@ bfd_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
   return TRUE;
 }
 
+/*
+FUNCTION
+       bfd_rename_section
+
+SYNOPSIS
+       void bfd_rename_section
+         (bfd *abfd, asection *sec, const char *newname);
+
+DESCRIPTION
+       Rename section @var{sec} in @var{abfd} to @var{newname}.
+*/
+
+void
+bfd_rename_section (bfd *abfd, sec_ptr sec, const char *newname)
+{
+  struct section_hash_entry *sh;
+
+  sh = (struct section_hash_entry *)
+    ((char *) sec - offsetof (struct section_hash_entry, section));
+  sh->section.name = newname;
+  bfd_hash_rename (&abfd->section_htab, newname, &sh->root);
+}
+
 /*
 FUNCTION
        bfd_map_over_sections
index 1ee503d78ad962612155ca910e418b7b5ed82ebc..97e43621fb91474a5deb20e2d31578469069d8cc 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-08  Alan Modra  <amodra@gmail.com>
+
+       * objcopy.c (copy_main): No need to rename sections when compressing
+       or decompressing.
+
 2010-11-05  Alan Modra  <amodra@gmail.com>
 
        * bin2c.c: Remove internationalization and version report.
index 2077fca481bc1bb733811c598a108e96979686fc..ac176df589641982c2c3fdcdb2e87599a8e2b01f 100644 (file)
@@ -3196,7 +3196,6 @@ copy_main (int argc, char *argv[])
   struct section_list *p;
   struct stat statbuf;
   const bfd_arch_info_type *input_arch = NULL;
-  struct dwarf_debug_section *d;
 
   while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:w",
                           copy_options, (int *) 0)) != EOF)
@@ -3912,22 +3911,6 @@ copy_main (int argc, char *argv[])
     fatal (_("warning: could not create temporary file whilst copying '%s', (error: %s)"),
           input_filename, strerror (errno));
 
-  switch (do_debug_sections)
-    {
-    case compress:
-      for (d = dwarf_debug_sections; d->uncompressed_name; d++)
-       add_section_rename (d->uncompressed_name, d->compressed_name,
-                           (flagword) -1);
-      break;
-    case decompress:
-      for (d = dwarf_debug_sections; d->uncompressed_name; d++)
-       add_section_rename (d->compressed_name, d->uncompressed_name,
-                           (flagword) -1);
-      break;
-    default:
-      break;
-    }
-
   copy_file (input_filename, tmpname, input_target, output_target, input_arch);
   if (status == 0)
     {
index dedc5f226d4121b90f7aaa08c93f2dc01da6cd42..2165aa817ab2dfe648b34413a4c64c4fa9a91de9 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-08  Alan Modra  <amodra@gmail.com>
+
+       * binutils-all/objdump.W: Adjust expected result for debug section
+       rename.
+
 2010-11-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        * binutils-all/libdw2.out: Also accept MIPS_DWARF.
index 8de584a0a832f99b108279dda88134c9751258d8..0197647f95b20f859c6358273252ae82c48dc414 100644 (file)
@@ -73,7 +73,7 @@ Raw dump of debug contents of section .debug_line:
   Extended opcode 1: End of Sequence
 
 
-Contents of the .zdebug_abbrev section:
+Contents of the .debug_abbrev section:
 
   Number TAG
    1      DW_TAG_compile_unit    \[has children\]
This page took 0.045657 seconds and 4 git commands to generate.