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