PR24786, wrong LMA if first section in overlay is empty
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
index 593ef475926be71f0e277390be1d9809cfc30ddf..ae03d72241672e8c9e1a4f88af344af84c324366 100644 (file)
@@ -1077,7 +1077,9 @@ _bfd_elf_ppc_set_arch (bfd *abfd)
   if (mach == 0)
     {
       s = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
-      if (s != NULL && bfd_malloc_and_get_section (abfd, s, &contents))
+      if (s != NULL
+         && s->size >= 24
+         && bfd_malloc_and_get_section (abfd, s, &contents))
        {
          unsigned int apuinfo_size = bfd_get_32 (abfd, contents + 4);
          unsigned int i;
@@ -3316,9 +3318,7 @@ ppc_elf_check_relocs (bfd *abfd,
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_PPC_GNU_VTENTRY:
-         BFD_ASSERT (h != NULL);
-         if (h != NULL
-             && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
 
@@ -8656,6 +8656,19 @@ ppc_elf_relocate_section (bfd *output_bfd,
                addend -= SYM_VAL (sda);
              }
 
+           if (r_type == R_PPC_EMB_RELSDA)
+             break;
+
+           /* The PowerPC Embedded Application Binary Interface
+              version 1.0 insanely chose to specify R_PPC_EMB_SDA21
+              operating on a 24-bit field at r_offset.  GNU as and
+              GNU ld have always assumed R_PPC_EMB_SDA21 operates on
+              a 32-bit bit insn at r_offset.  Cope with object file
+              producers that possibly comply with the EABI in
+              generating an odd r_offset for big-endian objects.  */
+           if (r_type == R_PPC_EMB_SDA21)
+             rel->r_offset &= ~1;
+
            insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
            if (reg == 0
                && (r_type == R_PPC_VLE_SDA21
@@ -8683,13 +8696,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  goto overflow;
                goto copy_reloc;
              }
-           else if (r_type == R_PPC_EMB_SDA21
-                    || r_type == R_PPC_VLE_SDA21
-                    || r_type == R_PPC_VLE_SDA21_LO)
-             {
-               /* Fill in register field.  */
-               insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
-             }
+           /* Fill in register field.  */
+           insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
            bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
          }
          break;
@@ -9704,6 +9712,7 @@ ppc_finish_symbols (struct bfd_link_info *info)
                bfd_byte *loc;
                bfd_vma val;
                Elf_Internal_Rela rela;
+               unsigned char *p;
 
                if (!get_sym_h (NULL, &sym, &sym_sec, NULL, &local_syms,
                                lplt - local_plt, ibfd))
@@ -9748,14 +9757,9 @@ ppc_finish_symbols (struct bfd_link_info *info)
                loc = relplt->contents + (relplt->reloc_count++
                                          * sizeof (Elf32_External_Rela));
                bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
-             }
-           if ((ent->glink_offset & 1) == 0)
-             {
-               unsigned char *p = ((unsigned char *) htab->glink->contents
-                                   + ent->glink_offset);
 
+               p = (unsigned char *) htab->glink->contents + ent->glink_offset;
                write_glink_stub (NULL, ent, htab->elf.iplt, p, info);
-               ent->glink_offset |= 1;
              }
          }
 
This page took 0.025818 seconds and 4 git commands to generate.