Nick Clifton 67b290
--- binutils.orig/binutils/objcopy.c	2018-08-06 09:11:02.053503486 +0100
Nick Clifton 67b290
+++ binutils-2.30/binutils/objcopy.c	2018-08-06 09:11:23.296329566 +0100
Nick Clifton 67b290
@@ -2174,7 +2174,7 @@ merge_gnu_build_notes (bfd * abfd, asect
Nick Clifton 67b290
      3. Eliminate any NT_GNU_BUILD_ATTRIBUTE_OPEN notes that have the same
Nick Clifton 67b290
         full name field as the immediately preceeding note with the same type
Nick Clifton 67b290
 	of name and whose address ranges coincide.
Nick Clifton 67b290
-	IE - it there are gaps in the coverage of the notes, then these gaps
Nick Clifton 67b290
+	IE - if there are gaps in the coverage of the notes, then these gaps
Nick Clifton 67b290
 	must be preserved.
Nick Clifton 67b290
      4. Combine the numeric value of any NT_GNU_BUILD_ATTRIBUTE_OPEN notes
Nick Clifton 67b290
         of type GNU_BUILD_ATTRIBUTE_STACK_SIZE.
Nick Clifton 67b290
@@ -2182,16 +2182,48 @@ merge_gnu_build_notes (bfd * abfd, asect
Nick Clifton 67b290
         its description field is empty then the nearest preceeding OPEN note
Nick Clifton 67b290
 	with a non-empty description field must also be preserved *OR* the
Nick Clifton 67b290
 	description field of the note must be changed to contain the starting
Nick Clifton 67b290
-	address to which it refers.  */
Nick Clifton 67b290
+	address to which it refers.
Nick Clifton 67b290
+     6. Notes with the same start and end address can be deleted.  */
Nick Clifton 67b290
   for (pnote = pnotes + 1; pnote < pnotes_end; pnote ++)
Nick Clifton 67b290
     {
Nick Clifton 67b290
       int                      note_type;
Nick Clifton 67b290
       objcopy_internal_note *  back;
Nick Clifton 67b290
       objcopy_internal_note *  prev_open_with_range = NULL;
Nick Clifton 67b290
 
Nick Clifton 67b290
+      /* Rule 6 - delete 0-range notes.  */
Nick Clifton 67b290
+      if (pnote->start == pnote->end)
Nick Clifton 67b290
+	{
Nick Clifton 67b290
+	  duplicate_found = TRUE;
Nick Clifton 67b290
+	  pnote->note.type = 0;
Nick Clifton 67b290
+	  continue;
Nick Clifton 67b290
+	}
Nick Clifton 67b290
+
Nick Clifton 67b290
       /* Rule 2 - preserve function notes.  */
Nick Clifton 67b290
       if (! is_open_note (pnote))
Nick Clifton 67b290
-	continue;
Nick Clifton 67b290
+	{
Nick Clifton 67b290
+	  int iter;
Nick Clifton 67b290
+
Nick Clifton 67b290
+	  /* Check to see if there is an identical previous function note.
Nick Clifton 67b290
+	     This can happen with overlays for example.  */
Nick Clifton 67b290
+	  for (iter = 0, back = pnote -1; back >= pnotes; back --)
Nick Clifton 67b290
+	    {
Nick Clifton 67b290
+	      if (back->start == pnote->start
Nick Clifton 67b290
+		  && back->end == pnote->end
Nick Clifton 67b290
+		  && back->note.namesz == pnote->note.namesz
Nick Clifton 67b290
+		  && memcmp (back->note.namedata, pnote->note.namedata, pnote->note.namesz) == 0)
Nick Clifton 67b290
+		{
Nick Clifton 67b290
+ fprintf (stderr, "DUP FUNXC\n");
Nick Clifton 67b290
+		  duplicate_found = TRUE;
Nick Clifton 67b290
+		  pnote->note.type = 0;
Nick Clifton 67b290
+		  break;
Nick Clifton 67b290
+		}
Nick Clifton 67b290
+
Nick Clifton 67b290
+	      /* Don't scan too far back however.  */
Nick Clifton 67b290
+	      if (iter ++ > 16)
Nick Clifton 67b290
+		break;
Nick Clifton 67b290
+	    }
Nick Clifton 67b290
+	  continue;
Nick Clifton 67b290
+	}
Nick Clifton 67b290
 
Nick Clifton 67b290
       note_type = pnote->note.namedata[attribute_type_byte];
Nick Clifton 67b290