OSDN Git Service

* bfd-elf.h (elf_backend_name_local_section_symbols): New hook.
authorRichard Sandiford <rsandifo@nildram.co.uk>
Mon, 9 Feb 2004 08:04:00 +0000 (08:04 +0000)
committerRichard Sandiford <rsandifo@nildram.co.uk>
Mon, 9 Feb 2004 08:04:00 +0000 (08:04 +0000)
* elf.c (swap_out_syms): Use it to decide whether local section
symbols should be named.
* elfxx-target.h (elf_backend_name_local_section_symbols): New macro.
* elfxx-mips.h (_bfd_mips_elf_name_local_section_symbols): Declare.
(elf_backend_name_local_section_symbols): Define.
* elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): New.

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf.c
bfd/elfxx-mips.c
bfd/elfxx-mips.h
bfd/elfxx-target.h

index 72a2e2f..19b521c 100644 (file)
@@ -1,3 +1,13 @@
+2004-02-09  Richard Sandiford  <rsandifo@redhat.com>
+
+       * bfd-elf.h (elf_backend_name_local_section_symbols): New hook.
+       * elf.c (swap_out_syms): Use it to decide whether local section
+       symbols should be named.
+       * elfxx-target.h (elf_backend_name_local_section_symbols): New macro.
+       * elfxx-mips.h (_bfd_mips_elf_name_local_section_symbols): Declare.
+       (elf_backend_name_local_section_symbols): Define.
+       * elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): New.
+
 2004-01-30  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elfxx-ia64.c (elfNN_ia64_relax_brl): New function.
index c457a39..6bbacad 100644 (file)
@@ -576,6 +576,11 @@ struct elf_backend_data
   int (*elf_backend_get_symbol_type)
     (Elf_Internal_Sym *, int);
 
+  /* Return true if local section symbols should have a non-null st_name.
+     NULL implies false.  */
+  bfd_boolean (*elf_backend_name_local_section_symbols)
+    (bfd *);
+
   /* A function to do additional processing on the ELF section header
      just before writing it out.  This is used to set the flags and
      type fields for some sections, or to actually write out data for
index cd107bd..82f778b 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5261,6 +5261,7 @@ swap_out_syms (bfd *abfd,
   char *outbound_shndx;
   int idx;
   bfd_size_type amt;
+  bfd_boolean name_local_sections;
 
   if (!elf_map_symbols (abfd))
     return FALSE;
@@ -5326,6 +5327,10 @@ swap_out_syms (bfd *abfd,
       outbound_shndx += sizeof (Elf_External_Sym_Shndx);
   }
 
+  name_local_sections
+    = (bed->elf_backend_name_local_section_symbols
+       && bed->elf_backend_name_local_section_symbols (abfd));
+
   syms = bfd_get_outsymbols (abfd);
   for (idx = 0; idx < symcount; idx++)
     {
@@ -5335,7 +5340,8 @@ swap_out_syms (bfd *abfd,
       flagword flags = syms[idx]->flags;
       int type;
 
-      if ((flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
+      if (!name_local_sections
+         && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
        {
          /* Local section symbols have no name.  */
          sym.st_name = 0;
index 7bcdb11..a296458 100644 (file)
@@ -4271,6 +4271,26 @@ _bfd_mips_elf_symbol_processing (bfd *abfd, asymbol *asym)
     }
 }
 \f
+/* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
+   relocations against two unnamed section symbols to resolve to the
+   same address.  For example, if we have code like:
+
+       lw      $4,%got_disp(.data)($gp)
+       lw      $25,%got_disp(.text)($gp)
+       jalr    $25
+
+   then the linker will resolve both relocations to .data and the program
+   will jump there rather than to .text.
+
+   We can work around this problem by giving names to local section symbols.
+   This is also what the MIPSpro tools do.  */
+
+bfd_boolean
+_bfd_mips_elf_name_local_section_symbols (bfd *abfd)
+{
+  return SGI_COMPAT (abfd);
+}
+\f
 /* Work over a section just before writing it out.  This routine is
    used by both the 32-bit and the 64-bit ABI.  FIXME: We recognize
    sections that need the SHF_MIPS_GPREL flag by name; there has to be
index d3787e9..9e5d7af 100644 (file)
@@ -24,6 +24,8 @@ extern bfd_boolean _bfd_mips_elf_new_section_hook
   (bfd *, asection *);
 extern void _bfd_mips_elf_symbol_processing
   (bfd *, asymbol *);
+extern bfd_boolean _bfd_mips_elf_name_local_section_symbols
+  (bfd *);
 extern bfd_boolean _bfd_mips_elf_section_processing
   (bfd *, Elf_Internal_Shdr *);
 extern bfd_boolean _bfd_mips_elf_section_from_shdr
@@ -119,4 +121,6 @@ extern bfd_vma _bfd_mips_elf_sign_extend
   (bfd_vma, int);
 
 extern struct bfd_elf_special_section const _bfd_mips_elf_special_sections[];
+#define elf_backend_name_local_section_symbols \
+  _bfd_mips_elf_name_local_section_symbols
 #define elf_backend_special_sections _bfd_mips_elf_special_sections
index 40fe8e7..ca0e47b 100644 (file)
 #ifndef elf_backend_get_symbol_type
 #define elf_backend_get_symbol_type 0
 #endif
+#ifndef elf_backend_name_local_section_symbols
+#define elf_backend_name_local_section_symbols 0
+#endif
 #ifndef elf_backend_section_processing
 #define elf_backend_section_processing 0
 #endif
@@ -456,6 +459,7 @@ static const struct elf_backend_data elfNN_bed =
   elf_backend_symbol_processing,
   elf_backend_symbol_table_processing,
   elf_backend_get_symbol_type,
+  elf_backend_name_local_section_symbols,
   elf_backend_section_processing,
   elf_backend_section_from_shdr,
   elf_backend_section_flags,