Blame SOURCES/binutils-aa64-fix-creation-of-_got.patch

881b8e
commit cc0efaa8024bd8b8774cb9f1bea0241f81e20a67
881b8e
Author: Marcus Shawcroft <mshawcroft@sourceware.org>
881b8e
Date:   Tue Jul 2 06:39:26 2013 +0000
881b8e
881b8e
    [AArch64] Fix creation of .got and placement of _GLOBAL_OFFSET_TABLE_
881b8e
881b8e
--- binutils-2.23.52.0.1.orig/bfd/elf64-aarch64.c	2014-05-16 15:37:49.059361420 -0400
881b8e
+++ binutils-2.23.52.0.1/bfd/elf64-aarch64.c	2014-05-16 15:43:21.462207400 -0400
881b8e
@@ -5128,6 +5128,70 @@
881b8e
   return TRUE;
881b8e
 }
881b8e
 
881b8e
+/* Create the .got section to hold the global offset table.  */
881b8e
+
881b8e
+static bfd_boolean
881b8e
+aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
881b8e
+{
881b8e
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
881b8e
+  flagword flags;
881b8e
+  asection *s;
881b8e
+  struct elf_link_hash_entry *h;
881b8e
+  struct elf_link_hash_table *htab = elf_hash_table (info);
881b8e
+
881b8e
+  /* This function may be called more than once.  */
881b8e
+  s = bfd_get_linker_section (abfd, ".got");
881b8e
+  if (s != NULL)
881b8e
+    return TRUE;
881b8e
+
881b8e
+  flags = bed->dynamic_sec_flags;
881b8e
+
881b8e
+  s = bfd_make_section_anyway_with_flags (abfd,
881b8e
+					  (bed->rela_plts_and_copies_p
881b8e
+					   ? ".rela.got" : ".rel.got"),
881b8e
+					  (bed->dynamic_sec_flags
881b8e
+					   | SEC_READONLY));
881b8e
+  if (s == NULL
881b8e
+      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
881b8e
+    return FALSE;
881b8e
+  htab->srelgot = s;
881b8e
+
881b8e
+  s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
881b8e
+  if (s == NULL
881b8e
+      || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
881b8e
+    return FALSE;
881b8e
+  htab->sgot = s;
881b8e
+  htab->sgot->size += GOT_ENTRY_SIZE;
881b8e
+
881b8e
+  if (bed->want_got_sym)
881b8e
+    {
881b8e
+      /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
881b8e
+	 (or .got.plt) section.  We don't do this in the linker script
881b8e
+	 because we don't want to define the symbol if we are not creating
881b8e
+	 a global offset table.  */
881b8e
+      h = _bfd_elf_define_linkage_sym (abfd, info, s,
881b8e
+				       "_GLOBAL_OFFSET_TABLE_");
881b8e
+      elf_hash_table (info)->hgot = h;
881b8e
+      if (h == NULL)
881b8e
+	return FALSE;
881b8e
+    }
881b8e
+
881b8e
+  if (bed->want_got_plt)
881b8e
+    {
881b8e
+      s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
881b8e
+      if (s == NULL
881b8e
+	  || !bfd_set_section_alignment (abfd, s,
881b8e
+					 bed->s->log_file_align))
881b8e
+	return FALSE;
881b8e
+      htab->sgotplt = s;
881b8e
+    }
881b8e
+
881b8e
+  /* The first bit of the global offset table is the header.  */
881b8e
+  s->size += bed->got_header_size;
881b8e
+
881b8e
+  return TRUE;
881b8e
+}
881b8e
+
881b8e
 /* Look through the relocs for a section during the first phase.  */
881b8e
 
881b8e
 static bfd_boolean
881b8e
@@ -5370,14 +5434,10 @@
881b8e
 		  }
881b8e
 	      }
881b8e
 
881b8e
-	    if (htab->root.sgot == NULL)
881b8e
-	      {
881b8e
-		if (htab->root.dynobj == NULL)
881b8e
-		  htab->root.dynobj = abfd;
881b8e
-		if (!_bfd_elf_create_got_section (htab->root.dynobj, info))
881b8e
-		  return FALSE;
881b8e
-		htab->root.sgot->size += GOT_ENTRY_SIZE;
881b8e
-	      }
881b8e
+	    if (htab->root.dynobj == NULL)
881b8e
+	      htab->root.dynobj = abfd;
881b8e
+	    if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
881b8e
+	      return FALSE;
881b8e
 	    break;
881b8e
 	  }
881b8e
 
881b8e
@@ -5965,7 +6025,10 @@
881b8e
 				       struct bfd_link_info *info)
881b8e
 {
881b8e
   struct elf64_aarch64_link_hash_table *htab;
881b8e
-  struct elf_link_hash_entry *h;
881b8e
+
881b8e
+  /* We need to create .got section.  */
881b8e
+  if (!aarch64_elf_create_got_section (dynobj, info))
881b8e
+    return FALSE;
881b8e
 
881b8e
   if (!_bfd_elf_create_dynamic_sections (dynobj, info))
881b8e
     return FALSE;
881b8e
@@ -5978,16 +6041,6 @@
881b8e
   if (!htab->sdynbss || (!info->shared && !htab->srelbss))
881b8e
     abort ();
881b8e
 
881b8e
-  /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
881b8e
-     dynobj's .got section.  We don't do this in the linker script
881b8e
-     because we don't want to define the symbol if we are not creating
881b8e
-     a global offset table.  */
881b8e
-  h = _bfd_elf_define_linkage_sym (dynobj, info,
881b8e
-				   htab->root.sgot, "_GLOBAL_OFFSET_TABLE_");
881b8e
-  elf_hash_table (info)->hgot = h;
881b8e
-  if (h == NULL)
881b8e
-    return FALSE;
881b8e
-
881b8e
   return TRUE;
881b8e
 }
881b8e