bfd/
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 2 Jul 2004 01:39:32 +0000 (01:39 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 2 Jul 2004 01:39:32 +0000 (01:39 +0000)
2004-07-01  H.J. Lu  <hongjiu.lu@intel.com>

* bfd.c (bfd_get_section_ident): New.

* elflink.c (elf_link_read_relocs_from_section): Call
bfd_get_section_ident to identify the section when reporting
error.
(_bfd_elf_link_output_relocs): Likewise.
(elf_link_output_extsym): Likewise.
(elf_link_input_bfd): Likewise.
(bfd_elf_gc_record_vtinherit): Likewise.

* bfd-in2.h: Regenerated.
ld/

2004-07-01  H.J. Lu  <hongjiu.lu@intel.com>

* ldmisc.c (vfinfo): Call bfd_get_section_ident to identify
the section.

bfd/ChangeLog
bfd/bfd-in2.h
bfd/bfd.c
bfd/elflink.c
ld/ChangeLog
ld/ldmisc.c

index fdd44e7b6e160ad85da6f1d5340722e3063dea23..dc07cc1d860929d0ac89052968a62f7d717a5c94 100644 (file)
@@ -1,3 +1,17 @@
+2004-07-01  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * bfd.c (bfd_get_section_ident): New.
+
+       * elflink.c (elf_link_read_relocs_from_section): Call
+       bfd_get_section_ident to identify the section when reporting
+       error.
+       (_bfd_elf_link_output_relocs): Likewise.
+       (elf_link_output_extsym): Likewise.
+       (elf_link_input_bfd): Likewise.
+       (bfd_elf_gc_record_vtinherit): Likewise.
+
+       * bfd-in2.h: Regenerated.
+
 2004-07-01  Jie Zhang  <zhangjie@magima.com.cn>
            Nick Clifton  <nickc@redhat.com>
 
index 7335774e6f7798e203f6e58cf8a67a29e5505e0b..9072d952d1cbf3833281e35fcda0d00a61aaf015 100644 (file)
@@ -4090,6 +4090,8 @@ void bfd_preserve_restore (bfd *, struct bfd_preserve *);
 
 void bfd_preserve_finish (bfd *, struct bfd_preserve *);
 
+char *bfd_get_section_ident (asection *sec);
+
 /* Extracted from archive.c.  */
 symindex bfd_get_next_mapent
    (bfd *abfd, symindex previous, carsym **sym);
index 3ead0ee5b5ac7bbd758610fe4756bdf1b27f883c..209b1b681a74f50e898c0b1c5acf71176714d0d3 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1417,3 +1417,46 @@ bfd_preserve_finish (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_preserve *preserve)
      objalloc.  */
   bfd_hash_table_free (&preserve->section_htab);
 }
+
+/*
+FUNCTION
+       bfd_get_section_ident
+
+SYNOPSIS
+       char *bfd_get_section_ident (asection *sec);
+
+DESCRIPTION
+       This function returns "section name[group name]" in a malloced
+       buffer if @var{sec} is a member of an ELF section group and
+       returns NULL otherwise. The caller should free the non-NULL
+       return after use.
+
+*/
+
+char *
+bfd_get_section_ident (asection *sec)
+{
+  char *buf;
+  bfd_size_type nlen;
+  bfd_size_type glen;
+
+  if (sec->owner == NULL
+      || bfd_get_flavour (sec->owner) != bfd_target_elf_flavour
+      || elf_next_in_group (sec) == NULL
+      || (sec->flags & SEC_GROUP) != 0)
+    return NULL;
+
+  nlen = strlen (sec->name);
+  glen = strlen (elf_group_name (sec));
+  buf = bfd_malloc (nlen + glen + 2 + 1);
+  if (buf != NULL)
+    {
+      strcpy (buf, sec->name);
+      buf [nlen] = '[';
+      strcpy (&buf [nlen + 1], elf_group_name (sec));
+      buf [nlen + 1 + glen] = ']';
+      buf [nlen + 1 + glen + 1] = '\0';
+    }
+
+  return buf;
+}
index 930438dbeba71d43a8859708ae7e41252d3723e2..c2830ff4be50df1033a62317cd5eb4e71d5c660e 100644 (file)
@@ -1859,10 +1859,14 @@ elf_link_read_relocs_from_section (bfd *abfd,
        r_symndx >>= 24;
       if ((size_t) r_symndx >= nsyms)
        {
+         char *sec_name = bfd_get_section_ident (sec);
          (*_bfd_error_handler)
            (_("%s: bad reloc symbol index (0x%lx >= 0x%lx) for offset 0x%lx in section `%s'"),
             bfd_archive_filename (abfd), (unsigned long) r_symndx,
-            (unsigned long) nsyms, irela->r_offset, sec->name);
+            (unsigned long) nsyms, irela->r_offset,
+            sec_name ? sec_name : sec->name);
+         if (sec_name)
+           free (sec_name);
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
        }
@@ -2048,11 +2052,14 @@ _bfd_elf_link_output_relocs (bfd *output_bfd,
     }
   else
     {
+      char *sec_name = bfd_get_section_ident (input_section);
       (*_bfd_error_handler)
        (_("%s: relocation size mismatch in %s section %s"),
         bfd_get_filename (output_bfd),
         bfd_archive_filename (input_section->owner),
-        input_section->name);
+        sec_name ? sec_name : input_section->name);
+      if (sec_name)
+       free (sec_name);
       bfd_set_error (bfd_error_wrong_object_format);
       return FALSE;
     }
@@ -6073,11 +6080,14 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
                                                 input_sec->output_section);
            if (sym.st_shndx == SHN_BAD)
              {
+               char *sec_name = bfd_get_section_ident (input_sec);
                (*_bfd_error_handler)
                  (_("%s: could not find output section %s for input section %s"),
                   bfd_get_filename (finfo->output_bfd),
                   input_sec->output_section->name,
-                  input_sec->name);
+                  sec_name ? sec_name : input_sec->name);
+               if (sec_name)
+                 free (sec_name);
                eoinfo->failed = TRUE;
                return FALSE;
              }
@@ -6638,13 +6648,21 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd)
                        }
                      else if (complain)
                        {
+                         char *r_sec
+                           = bfd_get_section_ident (o);
+                         char *d_sec
+                           = bfd_get_section_ident (sec);
                          finfo->info->callbacks->error_handler
                            (LD_DEFINITION_IN_DISCARDED_SECTION,
                             _("`%T' referenced in section `%s' of %B: "
                               "defined in discarded section `%s' of %B\n"),
-                            sym_name,
-                            sym_name, o->name, input_bfd,
-                            sec->name, sec->owner);
+                            sym_name, sym_name,
+                            r_sec ? r_sec : o->name, input_bfd,
+                            d_sec ? d_sec : sec->name, sec->owner);
+                         if (r_sec)
+                           free (r_sec);
+                         if (d_sec)
+                           free (d_sec);
                        }
 
                      /* Remove the symbol reference from the reloc, but
@@ -8567,6 +8585,7 @@ bfd_elf_gc_record_vtinherit (bfd *abfd,
   struct elf_link_hash_entry **search, *child;
   bfd_size_type extsymcount;
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  char *sec_name;
 
   /* The sh_info field of the symtab header tells us where the
      external symbols start.  We don't care about the local symbols at
@@ -8590,8 +8609,10 @@ bfd_elf_gc_record_vtinherit (bfd *abfd,
        goto win;
     }
 
+  sec_name = bfd_get_section_ident (sec);
   (*_bfd_error_handler) ("%s: %s+%lu: No symbol found for INHERIT",
-                        bfd_archive_filename (abfd), sec->name,
+                        bfd_archive_filename (abfd),
+                        sec_name ? sec_name : sec->name,
                         (unsigned long) offset);
   bfd_set_error (bfd_error_invalid_operation);
   return FALSE;
index 9d159db1ca0a58534dfb4e86b92ab98911fe0dd3..67ffbe4a46a21e959d45dc2811cef8de869287d4 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-01  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * ldmisc.c (vfinfo): Call bfd_get_section_ident to identify
+       the section.
+
 2004-06-29  Alan Modra  <amodra@bigpond.net.au>
 
        * ldlang.c (lang_reset_memory_regions): Save last relax pass section
index def598d639a208bb02e4921d9a3bd784d61632f3..3e8b3717e5af412a48a172889d69aac42daff82b 100644 (file)
@@ -241,6 +241,7 @@ vfinfo (FILE *fp, const char *fmt, va_list arg)
                const char *functionname;
                unsigned int linenumber;
                bfd_boolean discard_last;
+               char *sec_name;
 
                abfd = va_arg (arg, bfd *);
                section = va_arg (arg, asection *);
@@ -269,7 +270,11 @@ vfinfo (FILE *fp, const char *fmt, va_list arg)
                      }
                  }
 
-               lfinfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
+               sec_name = bfd_get_section_ident (section);
+               lfinfo (fp, "%B(%s+0x%v)", abfd,
+                       sec_name ? sec_name : section->name, offset);
+               if (sec_name)
+                 free (sec_name);
 
                discard_last = TRUE;
                if (bfd_find_nearest_line (abfd, section, asymbols, offset,