* elf32-i386.c (elf_i386_finish_dynamic_sections): Add output_offset
authorAlan Modra <amodra@gmail.com>
Thu, 12 Dec 2002 10:17:14 +0000 (10:17 +0000)
committerAlan Modra <amodra@gmail.com>
Thu, 12 Dec 2002 10:17:14 +0000 (10:17 +0000)
to DT_JMPREL.  Use srelplt input section size for DT_PLTRELSZ and
DT_RELSZ adjustment, not output section.  Avoid writing tags when
unchanged.  Don't assume linker script is sane, adjust DT_REL too.
* elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Just use raw
size of srelplt for DT_PLTRELSZ.  Use srelplt input section size for
DT_RELASZ adjustment, not output section.  Avoid writing tags when
unchanged.  Adjust DT_RELA.
* elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Tweaks for better
formatting.  Avoid writing tags when unchanged.  Adjust DT_RELA.

bfd/ChangeLog
bfd/elf32-hppa.c
bfd/elf32-i386.c
bfd/elf64-ppc.c

index c78a2d79b053d0ad37168c0154f30064f3d7aabd..89da4f21d9f24c9f78797647874e874191ae5984 100644 (file)
@@ -1,3 +1,16 @@
+2002-12-12  Alan Modra  <amodra@bigpond.net.au>
+
+       * elf32-i386.c (elf_i386_finish_dynamic_sections): Add output_offset
+       to DT_JMPREL.  Use srelplt input section size for DT_PLTRELSZ and
+       DT_RELSZ adjustment, not output section.  Avoid writing tags when
+       unchanged.  Don't assume linker script is sane, adjust DT_REL too.
+       * elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Just use raw
+       size of srelplt for DT_PLTRELSZ.  Use srelplt input section size for
+       DT_RELASZ adjustment, not output section.  Avoid writing tags when
+       unchanged.  Adjust DT_RELA.
+       * elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Tweaks for better
+       formatting.  Avoid writing tags when unchanged.  Adjust DT_RELA.
+
 2002-12-12  Alexandre Oliva  <aoliva@redhat.com>
 
        * elfxx-mips.c (mips_elf_calculate_relocation): Don't divide
index 80c39cea554b649f9b02c923b894c053d3c2cf0e..f8c88b15583b455802bb73c11d8ee4ae47ae161f 100644 (file)
@@ -4314,23 +4314,28 @@ elf32_hppa_finish_dynamic_sections (output_bfd, info)
 
            case DT_PLTRELSZ:
              s = htab->srelplt;
-             if (s->_cooked_size != 0)
-               dyn.d_un.d_val = s->_cooked_size;
-             else
-               dyn.d_un.d_val = s->_raw_size;
+             dyn.d_un.d_val = s->_raw_size;
              break;
 
            case DT_RELASZ:
              /* Don't count procedure linkage table relocs in the
                 overall reloc count.  */
-             if (htab->srelplt != NULL)
-               {
-                 s = htab->srelplt->output_section;
-                 if (s->_cooked_size != 0)
-                   dyn.d_un.d_val -= s->_cooked_size;
-                 else
-                   dyn.d_un.d_val -= s->_raw_size;
-               }
+             s = htab->srelplt;
+             if (s == NULL)
+               continue;
+             dyn.d_un.d_val -= s->_raw_size;
+             break;
+
+           case DT_RELA:
+             /* We may not be using the standard ELF linker script.
+                If .rela.plt is the first .rela section, we adjust
+                DT_RELA to not include it.  */
+             s = htab->srelplt;
+             if (s == NULL)
+               continue;
+             if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
+               continue;
+             dyn.d_un.d_ptr += s->_raw_size;
              break;
            }
 
index a6e39932ca1881ce75a8c9b29134e629435ec290..9c94887b4bfb74f8e35b5031c9e2052d3adb608a 100644 (file)
@@ -3265,15 +3265,13 @@ elf_i386_finish_dynamic_sections (output_bfd, info)
              break;
 
            case DT_JMPREL:
-             dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
+             s = htab->srelplt;
+             dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              break;
 
            case DT_PLTRELSZ:
-             s = htab->srelplt->output_section;
-             if (s->_cooked_size != 0)
-               dyn.d_un.d_val = s->_cooked_size;
-             else
-               dyn.d_un.d_val = s->_raw_size;
+             s = htab->srelplt;
+             dyn.d_un.d_val = s->_raw_size;
              break;
 
            case DT_RELSZ:
@@ -3282,18 +3280,23 @@ elf_i386_finish_dynamic_sections (output_bfd, info)
                 included in the overall relocs (DT_REL).  This is
                 what Solaris does.  However, UnixWare can not handle
                 that case.  Therefore, we override the DT_RELSZ entry
-                here to make it not include the JMPREL relocs.  Since
-                the linker script arranges for .rel.plt to follow all
-                other relocation sections, we don't have to worry
-                about changing the DT_REL entry.  */
-             if (htab->srelplt != NULL)
-               {
-                 s = htab->srelplt->output_section;
-                 if (s->_cooked_size != 0)
-                   dyn.d_un.d_val -= s->_cooked_size;
-                 else
-                   dyn.d_un.d_val -= s->_raw_size;
-               }
+                here to make it not include the JMPREL relocs.  */
+             s = htab->srelplt;
+             if (s == NULL)
+               continue;
+             dyn.d_un.d_val -= s->_raw_size;
+             break;
+
+           case DT_REL:
+             /* We may not be using the standard ELF linker script.
+                If .rel.plt is the first .rel section, we adjust
+                DT_REL to not include it.  */
+             s = htab->srelplt;
+             if (s == NULL)
+               continue;
+             if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
+               continue;
+             dyn.d_un.d_ptr += s->_raw_size;
              break;
            }
 
index ba0ad2e2525950929ef02b2d985a8688ce675781..579188397679823b790bbabee018e22b120cd8c7 100644 (file)
@@ -6227,30 +6227,32 @@ ppc64_elf_finish_dynamic_sections (output_bfd, info)
              continue;
 
            case DT_PPC64_GLINK:
-             dyn.d_un.d_ptr = (htab->sglink->output_section->vma
-                               + htab->sglink->output_offset);
+             s = htab->sglink;
+             dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              break;
 
            case DT_PPC64_OPD:
              s = bfd_get_section_by_name (output_bfd, ".opd");
-             if (s != NULL)
-               dyn.d_un.d_ptr = s->vma;
+             if (s == NULL)
+               continue;
+             dyn.d_un.d_ptr = s->vma;
              break;
 
            case DT_PPC64_OPDSZ:
              s = bfd_get_section_by_name (output_bfd, ".opd");
-             if (s != NULL)
-               dyn.d_un.d_val = s->_raw_size;
+             if (s == NULL)
+               continue;
+             dyn.d_un.d_val = s->_raw_size;
              break;
 
            case DT_PLTGOT:
-             dyn.d_un.d_ptr = (htab->splt->output_section->vma
-                               + htab->splt->output_offset);
+             s = htab->splt;
+             dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              break;
 
            case DT_JMPREL:
-             dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
-                               + htab->srelplt->output_offset);
+             s = htab->srelplt;
+             dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              break;
 
            case DT_PLTRELSZ:
@@ -6260,8 +6262,22 @@ ppc64_elf_finish_dynamic_sections (output_bfd, info)
            case DT_RELASZ:
              /* Don't count procedure linkage table relocs in the
                 overall reloc count.  */
-             if (htab->srelplt != NULL)
-               dyn.d_un.d_val -= htab->srelplt->_raw_size;
+             s = htab->srelplt;
+             if (s == NULL)
+               continue;
+             dyn.d_un.d_val -= s->_raw_size;
+             break;
+
+           case DT_RELA:
+             /* We may not be using the standard ELF linker script.
+                If .rela.plt is the first .rela section, we adjust
+                DT_RELA to not include it.  */
+             s = htab->srelplt;
+             if (s == NULL)
+               continue;
+             if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
+               continue;
+             dyn.d_un.d_ptr += s->_raw_size;
              break;
            }