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

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