This is the mail archive of the binutils@sourceware.org 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]

[AArch64, Committed] Fix the placement of _DYNAMIC in the GOT.


This patch fixes an issue in the static linker highlighted by this thread:

http://sourceware.org/ml/libc-ports/2013-06/msg00043.html

This patch fixes the location of &_DYNAMIC in the GOT.

We currently emit:
got[0] ...    <- _GLOBAL_OFFSET_TABLE_
...
gotplt[0] &_DYNAMIC  <- DT_PLTGOT
gotplt[1] reserved
gotplt[2] reserved
gotplt[3] first real plt

The purpose of placing &_DYNAMIC in a dedicated GOT slot is to allow the dynamic loader to easily locate its own dynamic section before it has relocated itself. This current layout is broken, the _DYNAMIC entry should be placed at a reserved slot pointed to by _GLOBAL_OFFSET_TABLE_.

This patch switches to this layout:
got[0]    &_DYNAMIC  <- _GLOBAL_OFFSET_TABLE_
...
gotplt[0] reserved  <- DT_PLTGOT
gotplt[1] reserved
gotplt[2] reserved
gotplt[3] first real plt

This change is safe because the only use of gotplt[0] is the ld.so and currently ld.so uses an alternative (broken) mechanism to find _DYNAMIC.

Once this fix is in the static linker we can have the behaviour of ld.so corrected to find _DYNAMIC by dereferencing _GLOBAL_OFFSET_TABLE_.

/Marcus

2013-06-27  Marcus Shawcroft  <marcus.shawcroft@arm.com>

	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Reserve one slot
	in sgot.
	(elfNN_aarch64_finish_dynamic_sections): Place the &_DYNAMIC reference
	in sgot[0] rather than sgotplt[0].
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 3e96c1c..1eda859 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -4886,6 +4886,7 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		  htab->root.dynobj = abfd;
 		if (!_bfd_elf_create_got_section (htab->root.dynobj, info))
 		  return FALSE;
+		htab->root.sgot->size += GOT_ENTRY_SIZE;
 	      }
 	    break;
 	  }
@@ -6501,15 +6502,8 @@ elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
       /* Fill in the first three entries in the global offset table.  */
       if (htab->root.sgotplt->size > 0)
 	{
-	  /* Set the first entry in the global offset table to the address of
-	     the dynamic section.  */
-	  if (sdyn == NULL)
-	    bfd_put_NN (output_bfd, (bfd_vma) 0,
-			htab->root.sgotplt->contents);
-	  else
-	    bfd_put_NN (output_bfd,
-			sdyn->output_section->vma + sdyn->output_offset,
-			htab->root.sgotplt->contents);
+	  bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
+
 	  /* Write GOT[1] and GOT[2], needed for the dynamic linker.  */
 	  bfd_put_NN (output_bfd,
 		      (bfd_vma) 0,
@@ -6519,6 +6513,16 @@ elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
 		      htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
 	}
 
+      if (htab->root.sgot)
+	{
+	  if (htab->root.sgot->size > 0)
+	    {
+	      bfd_vma addr =
+		sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
+	      bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
+	    }
+	}
+
       elf_section_data (htab->root.sgotplt->output_section)->
 	this_hdr.sh_entsize = GOT_ENTRY_SIZE;
     }

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