* elf64-mips.c (mips_elf64_write_rel): Use STN_UNDEF for relocs
[binutils-gdb.git] / bfd / elf64-mips.c
index 71c3425eaa8b561a844ab17f27e101610d18b2ef..dd68f708a67a40570b600f64d0deb957f0bc67c7 100644 (file)
@@ -1,5 +1,5 @@
 /* MIPS-specific support for 64-bit ELF
-   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
    Ian Lance Taylor, Cygnus Support
    Linker support added by Mark Mitchell, CodeSourcery, LLC.
@@ -1621,7 +1621,7 @@ mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   relocation += symbol->section->output_section->vma;
   relocation += symbol->section->output_offset;
 
-  if (reloc_entry->address > input_section->_cooked_size)
+  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
     return bfd_reloc_outofrange;
 
   /* Set val to the offset into the section or symbol.  */
@@ -1736,7 +1736,7 @@ mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   if (ret != bfd_reloc_ok)
     return ret;
 
-  if (reloc_entry->address > input_section->_cooked_size)
+  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
     return bfd_reloc_outofrange;
 
   if (bfd_is_com_section (symbol->section))
@@ -1984,7 +1984,7 @@ mips_elf64_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
 
          if (! (*slurp_relocs) (abfd, s, syms, TRUE))
            return -1;
-         count = s->_raw_size / elf_section_data (s)->this_hdr.sh_entsize * 3;
+         count = s->size / elf_section_data (s)->this_hdr.sh_entsize * 3;
          p = s->relocation;
          for (i = 0; i < count; i++)
            *storage++ = p++;
@@ -2015,7 +2015,7 @@ mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
   arelent *relent;
   bfd_vma i;
   int entsize;
-  reloc_howto_type *howto_table;
+  bfd_boolean rela_p;
 
   allocated = bfd_malloc (rel_hdr->sh_size);
   if (allocated == NULL)
@@ -2033,9 +2033,9 @@ mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
              || entsize == sizeof (Elf64_Mips_External_Rela));
 
   if (entsize == sizeof (Elf64_Mips_External_Rel))
-    howto_table = mips_elf64_howto_table_rel;
+    rela_p = FALSE;
   else
-    howto_table = mips_elf64_howto_table_rela;
+    rela_p = TRUE;
 
   for (i = 0, relent = relents;
        i < reloc_count;
@@ -2148,7 +2148,7 @@ mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
 
          relent->addend = rela.r_addend;
 
-         relent->howto = &howto_table[(int) type];
+         relent->howto = mips_elf64_rtype_to_howto (type, rela_p);
 
          ++relent;
        }
@@ -2210,7 +2210,7 @@ mips_elf64_slurp_reloc_table (bfd *abfd, asection *asect,
         case because relocations against this section may use the
         dynamic symbol table, and in that case bfd_section_from_shdr
         in elf.c does not update the RELOC_COUNT.  */
-      if (asect->_raw_size == 0)
+      if (asect->size == 0)
        return TRUE;
 
       rel_hdr = &d->this_hdr;
@@ -2352,6 +2352,8 @@ mips_elf64_write_rel (bfd *abfd, asection *sec,
       sym = *ptr->sym_ptr_ptr;
       if (sym == last_sym)
        n = last_sym_idx;
+      else if (bfd_is_abs_section (sym->section) && sym->value == 0)
+       n = STN_UNDEF;
       else
        {
          last_sym = sym;
@@ -2448,6 +2450,8 @@ mips_elf64_write_rela (bfd *abfd, asection *sec,
       sym = *ptr->sym_ptr_ptr;
       if (sym == last_sym)
        n = last_sym_idx;
+      else if (bfd_is_abs_section (sym->section) && sym->value == 0)
+       n = STN_UNDEF;
       else
        {
          last_sym = sym;
@@ -2539,7 +2543,7 @@ static bfd_boolean
 elf64_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
 {
   int offset;
-  unsigned int raw_size;
+  unsigned int size;
 
   switch (note->descsz)
     {
@@ -2555,14 +2559,14 @@ elf64_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
 
        /* pr_reg */
        offset = 112;
-       raw_size = 360;
+       size = 360;
 
        break;
     }
 
   /* Make a ".reg/999" section.  */
   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
-                                         raw_size, note->descpos + offset);
+                                         size, note->descpos + offset);
 }
 
 static bfd_boolean