Blame SOURCES/binutils-x86-local-relocs.patch

869a11
--- binutils.orig/bfd/elfxx-x86.c	2018-05-14 12:22:29.149657093 +0100
869a11
+++ binutils-2.30/bfd/elfxx-x86.c	2018-05-14 12:25:16.244700009 +0100
869a11
@@ -839,6 +839,33 @@ _bfd_x86_elf_compare_relocs (const void
869a11
     return 0;
869a11
 }
869a11
 
869a11
+/* Mark symbol, NAME, as locally defined by linker if it is referenced
869a11
+   and not defined in a relocatable object file.  */
869a11
+
869a11
+static void
869a11
+elf_x86_linker_defined (struct bfd_link_info *info, const char *name)
869a11
+{
869a11
+  struct elf_link_hash_entry *h;
869a11
+
869a11
+  h = elf_link_hash_lookup (elf_hash_table (info), name,
869a11
+                           FALSE, FALSE, FALSE);
869a11
+  if (h == NULL)
869a11
+    return;
869a11
+
869a11
+  while (h->root.type == bfd_link_hash_indirect)
869a11
+    h = (struct elf_link_hash_entry *) h->root.u.i.link;
869a11
+
869a11
+  if (h->root.type == bfd_link_hash_new
869a11
+      || h->root.type == bfd_link_hash_undefined
869a11
+      || h->root.type == bfd_link_hash_undefweak
869a11
+      || h->root.type == bfd_link_hash_common
869a11
+      || (!h->def_regular && h->def_dynamic))
869a11
+    {
869a11
+      elf_x86_hash_entry (h)->local_ref = 2;
869a11
+      elf_x86_hash_entry (h)->linker_def = 1;
869a11
+    }
869a11
+}
869a11
+
869a11
 bfd_boolean
869a11
 _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
869a11
 {
869a11
@@ -869,18 +896,16 @@ _bfd_x86_elf_link_check_relocs (bfd *abf
869a11
 
869a11
 	  /* "__ehdr_start" will be defined by linker as a hidden symbol
869a11
 	     later if it is referenced and not defined.  */
869a11
-	  h = elf_link_hash_lookup (elf_hash_table (info),
869a11
-				    "__ehdr_start",
869a11
-				    FALSE, FALSE, FALSE);
869a11
-	  if (h != NULL
869a11
-	      && (h->root.type == bfd_link_hash_new
869a11
-		  || h->root.type == bfd_link_hash_undefined
869a11
-		  || h->root.type == bfd_link_hash_undefweak
869a11
-		  || h->root.type == bfd_link_hash_common))
869a11
+	  elf_x86_linker_defined (info, "__ehdr_start");
869a11
+
869a11
+	  if (bfd_link_executable (info))
869a11
 	    {
869a11
-	      elf_x86_hash_entry (h)->local_ref = 2;
869a11
-	      elf_x86_hash_entry (h)->linker_def = 1;
869a11
-	    }
869a11
+	      /* References to __bss_start, _end and _edata should be
869a11
+		 locally resolved within executables.  */
869a11
+	      elf_x86_linker_defined (info, "__bss_start");
869a11
+	      elf_x86_linker_defined (info, "_end");
869a11
+	      elf_x86_linker_defined (info, "_edata");
869a11
+            }
869a11
 	}
869a11
     }
869a11