[binutils-gdb] Improve objcopy's ability to merge build notes.

Nick Clifton nickc@sourceware.org
Fri Aug 3 16:08:00 GMT 2018


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4aae6e5abddb84e1225cfd696b8fd2c6832f9fb6

commit 4aae6e5abddb84e1225cfd696b8fd2c6832f9fb6
Author: Nick Clifton <nickc@redhat.com>
Date:   Fri Aug 3 17:08:11 2018 +0100

    Improve objcopy's ability to merge build notes.
    
    	* objcopy.c (merge_gnu_build_notes): Delete empty notes.  Merge
    	identical function notes.

Diff:
---
 binutils/ChangeLog |  5 +++++
 binutils/objcopy.c | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index ad7a87c..d7648ef 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2018-08-03  Nick Clifton  <nickc@redhat.com>
+
+	* objcopy.c (merge_gnu_build_notes): Delete empty notes.  Merge
+	identical function notes.
+
 2018-08-01  Nick Clifton  <nickc@redhat.com>
 
 	* README-how-to-make-a-release: Add note about regenerating the
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 001cddf..6bd9339 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2177,7 +2177,7 @@ merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte
      3. Eliminate any NT_GNU_BUILD_ATTRIBUTE_OPEN notes that have the same
         full name field as the immediately preceeding note with the same type
 	of name and whose address ranges coincide.
-	IE - it there are gaps in the coverage of the notes, then these gaps
+	IE - if there are gaps in the coverage of the notes, then these gaps
 	must be preserved.
      4. Combine the numeric value of any NT_GNU_BUILD_ATTRIBUTE_OPEN notes
         of type GNU_BUILD_ATTRIBUTE_STACK_SIZE.
@@ -2185,16 +2185,48 @@ merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte
         its description field is empty then the nearest preceeding OPEN note
 	with a non-empty description field must also be preserved *OR* the
 	description field of the note must be changed to contain the starting
-	address to which it refers.  */
+	address to which it refers.
+     6. Notes with the same start and end address can be deleted.  */
   for (pnote = pnotes + 1; pnote < pnotes_end; pnote ++)
     {
       int                      note_type;
       objcopy_internal_note *  back;
       objcopy_internal_note *  prev_open_with_range = NULL;
 
+      /* Rule 6 - delete 0-range notes.  */
+      if (pnote->start == pnote->end)
+	{
+	  duplicate_found = TRUE;
+	  pnote->note.type = 0;
+	  continue;
+	}
+
       /* Rule 2 - preserve function notes.  */
       if (! is_open_note (pnote))
-	continue;
+	{
+	  int iter;
+
+	  /* Check to see if there is an identical previous function note.
+	     This can happen with overlays for example.  */
+	  for (iter = 0, back = pnote -1; back >= pnotes; back --)
+	    {
+	      if (back->start == pnote->start
+		  && back->end == pnote->end
+		  && back->note.namesz == pnote->note.namesz
+		  && memcmp (back->note.namedata, pnote->note.namedata, pnote->note.namesz) == 0)
+		{
+ fprintf (stderr, "DUP FUNXC\n");
+		  duplicate_found = TRUE;
+		  pnote->note.type = 0;
+		  break;
+		}
+
+	      /* Don't scan too far back however.  */
+	      if (iter ++ > 16)
+		break;
+	    }
+	  continue;
+	}
 
       note_type = pnote->note.namedata[attribute_type_byte];



More information about the Binutils-cvs mailing list