* elf64-mips.c (mips_elf64_write_rel): Use STN_UNDEF for relocs
[binutils-gdb.git] / bfd / elf64-mips.c
index 743444240aa7e3b23a9c09d0ad4fbaa6f84f6918..dd68f708a67a40570b600f64d0deb957f0bc67c7 100644 (file)
@@ -1588,7 +1588,6 @@ mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   bfd_vma gp;
   bfd_vma relocation;
   bfd_vma val;
-  bfd_size_type sz;
 
   /* If we're relocating, and this is an external symbol, we don't want
      to change anything.  */
@@ -1622,8 +1621,7 @@ mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   relocation += symbol->section->output_section->vma;
   relocation += symbol->section->output_offset;
 
-  sz = input_section->rawsize ? input_section->rawsize : input_section->size;
-  if (reloc_entry->address > sz)
+  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.  */
@@ -1714,7 +1712,6 @@ mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   unsigned short insn = 0;
   bfd_signed_vma val;
   bfd_vma relocation;
-  bfd_size_type sz;
 
   /* If we're relocating, and this is an external symbol with no
      addend, we don't want to change anything.  */
@@ -1739,8 +1736,7 @@ mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   if (ret != bfd_reloc_ok)
     return ret;
 
-  sz = input_section->rawsize ? input_section->rawsize : input_section->size;
-  if (reloc_entry->address > sz)
+  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
     return bfd_reloc_outofrange;
 
   if (bfd_is_com_section (symbol->section))
@@ -2356,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;
@@ -2452,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;