This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

plt dynamic tags


Some tweaks for (l)user provided linker scripts.  We can generate a
correct DT_JMPREL and DT_PLTRELSZ even when .rel.plt is merged with
other reloc sections, as the dynamic .rel.plt is the only source
of .plt relocs.  I'm also adjusting DT_REL to handle the case where
.rel.plt happens to be the first reloc section.  Strictly speaking,
I suppose we ought to zero DT_REL if .rel.plt is the only reloc
section, but that seems like too much bother.

	* 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.

Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.91
diff -u -p -r1.91 elf32-i386.c
--- bfd/elf32-i386.c	30 Nov 2002 08:39:37 -0000	1.91
+++ bfd/elf32-i386.c	10 Dec 2002 08:04:54 -0000
@@ -3265,15 +3265,13 @@ elf_i386_finish_dynamic_sections (output
 	      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
 		 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: bfd/elf32-hppa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-hppa.c,v
retrieving revision 1.91
diff -u -p -r1.91 elf32-hppa.c
--- bfd/elf32-hppa.c	30 Nov 2002 08:39:37 -0000	1.91
+++ bfd/elf32-hppa.c	10 Dec 2002 08:04:52 -0000
@@ -4314,23 +4314,28 @@ elf32_hppa_finish_dynamic_sections (outp
 
 	    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: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.75
diff -u -p -r1.75 elf64-ppc.c
--- bfd/elf64-ppc.c	4 Dec 2002 11:08:16 -0000	1.75
+++ bfd/elf64-ppc.c	10 Dec 2002 08:04:57 -0000
@@ -6227,30 +6227,32 @@ ppc64_elf_finish_dynamic_sections (outpu
 	      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 (outpu
 	    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;
 	    }
 

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]