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

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