Blame SOURCES/binutils-linkonce-notes.patch

13ae24
--- binutils.orig/gas/write.c	2018-05-14 12:22:27.893671804 +0100
13ae24
+++ binutils-2.30/gas/write.c	2018-05-14 15:39:03.900509629 +0100
13ae24
@@ -1901,6 +1901,7 @@ maybe_generate_build_notes (void)
13ae24
   segT      sec;
13ae24
   char *    note;
13ae24
   offsetT   note_size;
13ae24
+  offsetT   total_size;
13ae24
   offsetT   desc_size;
13ae24
   offsetT   desc2_offset;
13ae24
   int       desc_reloc;
13ae24
@@ -1918,7 +1919,8 @@ maybe_generate_build_notes (void)
13ae24
 			 SEC_READONLY | SEC_HAS_CONTENTS | SEC_DATA);
13ae24
   bfd_set_section_alignment (stdoutput, sec, 2);
13ae24
 
13ae24
-  /* Create a version note.  */
13ae24
+  /* Work out the size of the notes that we will create,
13ae24
+     and the relocation we should use.  */
13ae24
   if (bfd_arch_bits_per_address (stdoutput) <= 32)
13ae24
     {
13ae24
       note_size = 28;
13ae24
@@ -1952,65 +1954,59 @@ maybe_generate_build_notes (void)
13ae24
 	desc_reloc = BFD_RELOC_64;
13ae24
     }
13ae24
   
13ae24
-  frag_now_fix ();
13ae24
-  note = frag_more (note_size);
13ae24
-  memset (note, 0, note_size);
13ae24
+  /* We have to create a note for *each* code section.
13ae24
+     Linker garbage collection might discard some.  */
13ae24
+  total_size = 0;
13ae24
+  note = NULL;
13ae24
 
13ae24
-  if (target_big_endian)
13ae24
-    {
13ae24
-      note[3] = 8; /* strlen (name) + 1.  */
13ae24
-      note[7] = desc_size; /* Two 8-byte offsets.  */
13ae24
-      note[10] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
13ae24
-      note[11] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
13ae24
-    }
13ae24
-  else
13ae24
-    {
13ae24
-      note[0] = 8; /* strlen (name) + 1.  */
13ae24
-      note[4] = desc_size; /* Two 8-byte offsets.  */
13ae24
-      note[8] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
13ae24
-      note[9] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
13ae24
-    }
13ae24
-
13ae24
-  /* The a1 version number indicates that this note was
13ae24
-     generated by the assembler and not the gcc annobin plugin.  */
13ae24
-  memcpy (note + 12, "GA$?3a1", 8);
13ae24
-
13ae24
-  /* Find the first code section symbol.  */
13ae24
   for (sym = symbol_rootP; sym != NULL; sym = sym->sy_next)
13ae24
     if (sym->bsym != NULL
13ae24
 	&& sym->bsym->flags & BSF_SECTION_SYM
13ae24
 	&& sym->bsym->section != NULL
13ae24
-	&& sym->bsym->section->flags & SEC_CODE)
13ae24
+	/* Skip linkonce sections - we cannot these section symbols as they may disappear.  */
13ae24
+	&& (sym->bsym->section->flags & (SEC_CODE | SEC_LINK_ONCE)) == SEC_CODE
13ae24
+	/* Not all linkonce sections are flagged...  */
13ae24
+	&& strncmp (S_GET_NAME (sym), ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) != 0)
13ae24
       {
13ae24
-	/* Found one - now create a relocation against this symbol.  */
13ae24
-	create_note_reloc (sec, sym, 20, desc_reloc, 0, note);
13ae24
-	break;
13ae24
-      }
13ae24
+	/* Create a version note.  */
13ae24
+	frag_now_fix ();
13ae24
+	note = frag_more (note_size);
13ae24
+	memset (note, 0, note_size);
13ae24
 
13ae24
-  /* Find the last code section symbol.  */
13ae24
-  if (sym)
13ae24
-    {
13ae24
-      for (sym = symbol_lastP; sym != NULL; sym = sym->sy_previous)
13ae24
-	if (sym->bsym != NULL
13ae24
-	    && sym->bsym->flags & BSF_SECTION_SYM
13ae24
-	    && sym->bsym->section != NULL
13ae24
-	    && sym->bsym->section->flags & SEC_CODE)
13ae24
+	if (target_big_endian)
13ae24
 	  {
13ae24
-	    /* Create a relocation against the end of this symbol.  */
13ae24
-	    create_note_reloc (sec, sym, desc2_offset, desc_reloc,
13ae24
-			       bfd_get_section_size (sym->bsym->section),
13ae24
-			       note);
13ae24
-	    break;
13ae24
+	    note[3] = 8; /* strlen (name) + 1.  */
13ae24
+	    note[7] = desc_size; /* Two 8-byte offsets.  */
13ae24
+	    note[10] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
13ae24
+	    note[11] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
13ae24
 	  }
13ae24
-    }
13ae24
-  /* else - if we were unable to find any code section symbols then
13ae24
-     probably there is no code in the output.  So leaving the start
13ae24
-     and end values as zero in the note is OK.  */
13ae24
+	else
13ae24
+	  {
13ae24
+	    note[0] = 8; /* strlen (name) + 1.  */
13ae24
+	    note[4] = desc_size; /* Two 8-byte offsets.  */
13ae24
+	    note[8] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
13ae24
+	    note[9] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
13ae24
+	  }
13ae24
+
13ae24
+	/* The a1 version number indicates that this note was
13ae24
+	   generated by the assembler and not the gcc annobin plugin.  */
13ae24
+	memcpy (note + 12, "GA$?3a1", 8);
13ae24
 
13ae24
-  /* FIXME: Maybe add a note recording the assembler command line and version ?  */
13ae24
+	/* Create a relocation to install the start address of the note...  */
13ae24
+	create_note_reloc (sec, sym, 20, desc_reloc, 0, note);
13ae24
+
13ae24
+	/* ...and another one to install the end address.  */
13ae24
+	create_note_reloc (sec, sym, desc2_offset, desc_reloc,
13ae24
+			   bfd_get_section_size (sym->bsym->section),
13ae24
+			   note);
13ae24
+
13ae24
+	total_size += note_size;
13ae24
+	/* FIXME: Maybe add a note recording the assembler command line and version ?  */
13ae24
+      }
13ae24
 
13ae24
   /* Install the note(s) into the section.  */
13ae24
-  bfd_set_section_contents (stdoutput, sec, (bfd_byte *) note, 0, note_size);
13ae24
+  if (total_size)
13ae24
+    bfd_set_section_contents (stdoutput, sec, (bfd_byte *) note, 0, total_size);
13ae24
   subsegs_finish_section (sec);
13ae24
   relax_segment (seg_info (sec)->frchainP->frch_root, sec, 0);
13ae24
   size_seg (stdoutput, sec, NULL);