* bfd-elf.h (elf_backend_name_local_section_symbols): New hook.
authorRichard Sandiford <rdsandiford@googlemail.com>
Mon, 9 Feb 2004 08:04:00 +0000 (08:04 +0000)
committerRichard Sandiford <rdsandiford@googlemail.com>
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 72a2e2ffa49c229861e5fc0761350576c33d43f0..19b521c742ac5bb780d4252b4c1e6d43f1587c91 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 c457a399f34f0e9157b95a2c2891590447e616d3..6bbacade36f599519f09c7563d2c10712695ae10 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 cd107bda03535f974f407348304a4d875282f83c..82f778b308bce81e8a292c16cf62f20ce92ed439 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 7bcdb1115b3f4dbfa6daabca7309f814b49f3e6c..a296458bf67785f926a7524134d09257c2ebbc6c 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 d3787e9ef96c935c0f6f42e14761a39c2f5784ac..9e5d7afe4279374a4cec034ae99d7d044377eec9 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 40fe8e76ece6162f6c616757c3548cdd48b365a6..ca0e47b32e709f12a5c3f424effd1098e74951d2 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,