Blame SOURCES/binutils-improved-note-merging.patch

66b412
diff -rupN binutils.orig/binutils/objcopy.c binutils-2.30/binutils/objcopy.c
66b412
--- binutils.orig/binutils/objcopy.c	2019-10-28 17:08:43.352324932 +0000
66b412
+++ binutils-2.30/binutils/objcopy.c	2019-10-28 17:20:26.378052081 +0000
66b412
@@ -97,8 +97,14 @@ static int deterministic = -1;		/* Enabl
66b412
 static int status = 0;			/* Exit status.  */
66b412
 
66b412
 static bfd_boolean    merge_notes = FALSE;	/* Merge note sections.  */
66b412
-static bfd_byte *     merged_notes = NULL;	/* Contents on note section undergoing a merge.  */
66b412
-static bfd_size_type  merged_size = 0;		/* New, smaller size of the merged note section.  */
66b412
+
66b412
+typedef struct merged_note_section
66b412
+{
66b412
+  asection *                    sec;	 /* The section that is being merged.  */
66b412
+  bfd_byte *                    contents;/* New contents of the section.  */
66b412
+  bfd_size_type                 size;	 /* New size of the section.  */
66b412
+  struct merged_note_section *  next;  	 /* Link to next merged note section.  */
66b412
+} merged_note_section;
66b412
 
66b412
 enum strip_action
66b412
 {
66b412
@@ -1259,7 +1265,7 @@ is_update_section (bfd *abfd ATTRIBUTE_U
66b412
 }
66b412
 
66b412
 static bfd_boolean
66b412
-is_merged_note_section (bfd * abfd, asection * sec)
66b412
+is_mergeable_note_section (bfd * abfd, asection * sec)
66b412
 {
66b412
   if (merge_notes
66b412
       && bfd_get_flavour (abfd) == bfd_target_elf_flavour
66b412
@@ -1268,9 +1274,9 @@ is_merged_note_section (bfd * abfd, asec
66b412
 	 We should add support for more note types.  */
66b412
       && ((elf_section_data (sec)->this_hdr.sh_flags & SHF_GNU_BUILD_NOTE) != 0
66b412
 	  /* Old versions of GAS (prior to 2.27) could not set the section
66b412
-	     flags to OS-specific values, so we also accept sections with the
66b412
-	     expected name.  */
66b412
-	  || (strcmp (sec->name, GNU_BUILD_ATTRS_SECTION_NAME) == 0)))
66b412
+	     flags to OS-specific values, so we also accept sections that
66b412
+	     start with the expected name.  */
66b412
+	  || (CONST_STRNEQ (sec->name, GNU_BUILD_ATTRS_SECTION_NAME))))
66b412
     return TRUE;
66b412
 
66b412
   return FALSE;
66b412
@@ -1893,56 +1899,81 @@ copy_unknown_object (bfd *ibfd, bfd *obf
66b412
   return TRUE;
66b412
 }
66b412
 
66b412
-/* Returns the number of bytes needed to store VAL.  */
66b412
-
66b412
-static inline unsigned int
66b412
-num_bytes (unsigned long val)
66b412
-{
66b412
-  unsigned int count = 0;
66b412
-
66b412
-  /* FIXME: There must be a faster way to do this.  */
66b412
-  while (val)
66b412
-    {
66b412
-      count ++;
66b412
-      val >>= 8;
66b412
-    }
66b412
-  return count;
66b412
-}
66b412
-
66b412
 typedef struct objcopy_internal_note
66b412
 {
66b412
   Elf_Internal_Note  note;
66b412
+  unsigned long      padded_namesz;
66b412
   bfd_vma            start;
66b412
   bfd_vma            end;
66b412
-  bfd_boolean        modified;
66b412
 } objcopy_internal_note;
66b412
   
66b412
-/* Returns TRUE if a gap does, or could, exist between the address range
66b412
-   covered by PNOTE1 and PNOTE2.  */
66b412
+#define DEBUG_MERGE 0
66b412
+
66b412
+#if DEBUG_MERGE
66b412
+#define merge_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
66b412
+#else
66b412
+#define merge_debug(format, ...)
66b412
+#endif
66b412
+
66b412
+/* Returns TRUE iff PNOTE1 overlaps or adjoins PNOTE2.  */
66b412
 
66b412
 static bfd_boolean
66b412
-gap_exists (objcopy_internal_note * pnote1,
66b412
-	    objcopy_internal_note * pnote2)
66b412
+overlaps_or_adjoins (objcopy_internal_note * pnote1,
66b412
+		     objcopy_internal_note * pnote2)
66b412
 {
66b412
-  /* Without range end notes, we assume that a gap might exist.  */
66b412
-  if (pnote1->end == 0 || pnote2->end == 0)
66b412
+  if (pnote1->end < pnote2->start)
66b412
+    /* FIXME: Alignment of 16 bytes taken from x86_64 binaries.
66b412
+       Really we should extract the alignment of the section
66b412
+       covered by the notes.  */
66b412
+    return BFD_ALIGN (pnote1->end, 16) < pnote2->start;
66b412
+
66b412
+  if (pnote2->end < pnote2->start)
66b412
+    return BFD_ALIGN (pnote2->end, 16) < pnote1->start;
66b412
+
66b412
+  if (pnote1->end < pnote2->end)
66b412
     return TRUE;
66b412
 
66b412
-  /* FIXME: Alignment of 16 bytes taken from x86_64 binaries.
66b412
-     Really we should extract the alignment of the section covered by the notes.  */
66b412
-  return BFD_ALIGN (pnote1->end, 16) < pnote2->start;
66b412
+  if (pnote2->end < pnote1->end)
66b412
+    return TRUE;
66b412
+
66b412
+  return FALSE;
66b412
+}
66b412
+
66b412
+/* Returns TRUE iff NEEDLE is fully contained by HAYSTACK.  */
66b412
+
66b412
+static bfd_boolean
66b412
+contained_by (objcopy_internal_note * needle,
66b412
+	      objcopy_internal_note * haystack)
66b412
+{
66b412
+  return needle->start >= haystack->start && needle->end <= haystack->end;
66b412
 }
66b412
 
66b412
 static bfd_boolean
66b412
 is_open_note (objcopy_internal_note * pnote)
66b412
 {
66b412
-  return (pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_OPEN);
66b412
+  return pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
66b412
 }
66b412
 
66b412
 static bfd_boolean
66b412
 is_func_note (objcopy_internal_note * pnote)
66b412
 {
66b412
-  return (pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_FUNC);
66b412
+  return pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_FUNC;
66b412
+}
66b412
+
66b412
+static bfd_boolean
66b412
+is_deleted_note (objcopy_internal_note * pnote)
66b412
+{
66b412
+  return pnote->note.type == 0;
66b412
+}
66b412
+
66b412
+static bfd_boolean
66b412
+is_version_note (objcopy_internal_note * pnote)
66b412
+{
66b412
+  return (pnote->note.namesz > 4
66b412
+	  && pnote->note.namedata[0] == 'G'
66b412
+	  && pnote->note.namedata[1] == 'A'
66b412
+	  && pnote->note.namedata[2] == '$'
66b412
+	  && pnote->note.namedata[3] == GNU_BUILD_ATTRIBUTE_VERSION);
66b412
 }
66b412
 
66b412
 static bfd_boolean
66b412
@@ -1955,11 +1986,97 @@ is_64bit (bfd * abfd)
66b412
   return elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64;
66b412
 }
66b412
 
66b412
+/* This sorting function is used to get the notes into an order
66b412
+   that makes merging easy.  */
66b412
+
66b412
+static int
66b412
+compare_gnu_build_notes (const void * data1, const void * data2)
66b412
+{
66b412
+  objcopy_internal_note * pnote1 = (objcopy_internal_note *) data1;
66b412
+  objcopy_internal_note * pnote2 = (objcopy_internal_note *) data2;
66b412
+
66b412
+  /* Sort notes based upon the attribute they record.  */
66b412
+  int cmp = memcmp (pnote1->note.namedata + 3,
66b412
+		    pnote2->note.namedata + 3,
66b412
+		    pnote1->note.namesz < pnote2->note.namesz ?
66b412
+		    pnote1->note.namesz - 3 : pnote2->note.namesz - 3);
66b412
+  if (cmp)
66b412
+    return cmp;
66b412
+  
66b412
+  if (pnote1->end < pnote2->start)
66b412
+    return -1;
66b412
+  if (pnote1->start > pnote2->end)
66b412
+    return 1;
66b412
+
66b412
+  /* Overlaps - we should merge the two ranges.  */
66b412
+  if (pnote1->start < pnote2->start)
66b412
+    return -1;
66b412
+  if (pnote1->end > pnote2->end)
66b412
+    return 1;
66b412
+  
66b412
+  /* Put OPEN notes before function notes.  */
66b412
+  if (is_open_note (pnote1) && ! is_open_note (pnote2))
66b412
+    return -1;
66b412
+  if (! is_open_note (pnote1) && is_open_note (pnote2))
66b412
+    return 1;
66b412
+  
66b412
+  return 0;
66b412
+}
66b412
+
66b412
+/* This sorting function is used to get the notes into an order
66b412
+   that makes eliminating address ranges easier.  */
66b412
+
66b412
+static int
66b412
+sort_gnu_build_notes (const void * data1, const void * data2)
66b412
+{
66b412
+  objcopy_internal_note * pnote1 = (objcopy_internal_note *) data1;
66b412
+  objcopy_internal_note * pnote2 = (objcopy_internal_note *) data2;
66b412
+
66b412
+  if (pnote1->note.type != pnote2->note.type)
66b412
+    {
66b412
+      /* Move deleted notes to the end.  */
66b412
+      if (is_deleted_note (pnote1))     /* 1: OFD 2: OFD */
66b412
+	return 1;
66b412
+
66b412
+      /* Move OPEN notes to the start.  */
66b412
+      if (is_open_note (pnote1))	/* 1: OF  2: OFD */
66b412
+	return -1;
66b412
+
66b412
+      if (is_deleted_note (pnote2))	/* 1: F   2: O D */
66b412
+	return 1;
66b412
+
66b412
+      return 1;				/* 1: F   2: O   */
66b412
+    }
66b412
+  
66b412
+  /* Sort by starting address.  */
66b412
+  if (pnote1->start < pnote2->start)
66b412
+    return -1;
66b412
+  if (pnote1->start > pnote2->start)
66b412
+    return 1;
66b412
+
66b412
+  /* Then by end address (bigger range first).  */
66b412
+  if (pnote1->end > pnote2->end)
66b412
+    return -1;
66b412
+  if (pnote1->end < pnote2->end)
66b412
+    return 1;
66b412
+
66b412
+  /* Then by attribute type.  */
66b412
+  if (pnote1->note.namesz > 4
66b412
+      && pnote2->note.namesz > 4
66b412
+      && pnote1->note.namedata[3] != pnote2->note.namedata[3])
66b412
+    return pnote1->note.namedata[3] - pnote2->note.namedata[3];
66b412
+  
66b412
+  return 0;
66b412
+}
66b412
+
66b412
 /* Merge the notes on SEC, removing redundant entries.
66b412
    Returns the new, smaller size of the section upon success.  */
66b412
 
66b412
 static bfd_size_type
66b412
-merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte * contents)
66b412
+merge_gnu_build_notes (bfd *          abfd,
66b412
+		       asection *     sec,
66b412
+		       bfd_size_type  size,
66b412
+		       bfd_byte *     contents)
66b412
 {
66b412
   objcopy_internal_note *  pnotes_end;
66b412
   objcopy_internal_note *  pnotes = NULL;
66b412
@@ -1968,18 +2085,14 @@ merge_gnu_build_notes (bfd * abfd, asect
66b412
   unsigned            version_1_seen = 0;
66b412
   unsigned            version_2_seen = 0;
66b412
   unsigned            version_3_seen = 0;
66b412
-  bfd_boolean         duplicate_found = FALSE;
66b412
   const char *        err = NULL;
66b412
   bfd_byte *          in = contents;
66b412
-  int                 attribute_type_byte;
66b412
-  int                 val_start;
66b412
   unsigned long       previous_func_start = 0;
66b412
   unsigned long       previous_open_start = 0;
66b412
   unsigned long       previous_func_end = 0;
66b412
   unsigned long       previous_open_end = 0;
66b412
   long                relsize;
66b412
 
66b412
-
66b412
   relsize = bfd_get_reloc_upper_bound (abfd, sec);
66b412
   if (relsize > 0)
66b412
     {
66b412
@@ -1992,19 +2105,33 @@ merge_gnu_build_notes (bfd * abfd, asect
66b412
       relcount = bfd_canonicalize_reloc (abfd, sec, relpp, isympp);
66b412
       free (relpp);
66b412
       if (relcount != 0)
66b412
-	goto done;
66b412
+	{
66b412
+	  if (! is_strip)
66b412
+	    non_fatal (_("%s[%s]: Cannot merge - there are relocations against this section"),
66b412
+		       bfd_get_filename (abfd), bfd_section_name (abfd, sec));
66b412
+	  goto done;
66b412
+	}
66b412
     }
66b412
   
66b412
   /* Make a copy of the notes and convert to our internal format.
66b412
-     Minimum size of a note is 12 bytes.  */
66b412
-  pnote = pnotes = (objcopy_internal_note *) xcalloc ((size / 12), sizeof (* pnote));
66b412
+     Minimum size of a note is 12 bytes.  Also locate the version
66b412
+     notes and check them.  */
66b412
+  pnote = pnotes = (objcopy_internal_note *)
66b412
+    xcalloc ((size / 12), sizeof (* pnote));
66b412
   while (remain >= 12)
66b412
     {
66b412
       bfd_vma start, end;
66b412
 
66b412
-      pnote->note.namesz = (bfd_get_32 (abfd, in    ) + 3) & ~3;
66b412
-      pnote->note.descsz = (bfd_get_32 (abfd, in + 4) + 3) & ~3;
66b412
-      pnote->note.type   =  bfd_get_32 (abfd, in + 8);
66b412
+      pnote->note.namesz   = bfd_get_32 (abfd, in);
66b412
+      pnote->note.descsz   = bfd_get_32 (abfd, in + 4);
66b412
+      pnote->note.type     = bfd_get_32 (abfd, in + 8);
66b412
+      pnote->padded_namesz = (pnote->note.namesz + 3) & ~3;
66b412
+
66b412
+      if (((pnote->note.descsz + 3) & ~3) != pnote->note.descsz)
66b412
+	{
66b412
+	  err = _("corrupt GNU build attribute note: description size not a factor of 4");
66b412
+	  goto done;
66b412
+	}
66b412
 
66b412
       if (pnote->note.type    != NT_GNU_BUILD_ATTRIBUTE_OPEN
66b412
 	  && pnote->note.type != NT_GNU_BUILD_ATTRIBUTE_FUNC)
66b412
@@ -2013,7 +2140,7 @@ merge_gnu_build_notes (bfd * abfd, asect
66b412
 	  goto done;
66b412
 	}
66b412
 
66b412
-      if (pnote->note.namesz + pnote->note.descsz + 12 > remain)
66b412
+      if (pnote->padded_namesz + pnote->note.descsz + 12 > remain)
66b412
 	{
66b412
 	  err = _("corrupt GNU build attribute note: note too big");
66b412
 	  goto done;
66b412
@@ -2026,21 +2153,17 @@ merge_gnu_build_notes (bfd * abfd, asect
66b412
 	}
66b412
 
66b412
       pnote->note.namedata = (char *)(in + 12);
66b412
-      pnote->note.descdata = (char *)(in + 12 + pnote->note.namesz);
66b412
+      pnote->note.descdata = (char *)(in + 12 + pnote->padded_namesz);
66b412
 
66b412
-      remain -= 12 + pnote->note.namesz + pnote->note.descsz;
66b412
-      in     += 12 + pnote->note.namesz + pnote->note.descsz;
66b412
+      remain -= 12 + pnote->padded_namesz + pnote->note.descsz;
66b412
+      in     += 12 + pnote->padded_namesz + pnote->note.descsz;
66b412
 
66b412
       if (pnote->note.namesz > 2
66b412
 	  && pnote->note.namedata[0] == '$'
66b412
 	  && pnote->note.namedata[1] == GNU_BUILD_ATTRIBUTE_VERSION
66b412
 	  && pnote->note.namedata[2] == '1')
66b412
 	++ version_1_seen;
66b412
-      else if (pnote->note.namesz > 4
66b412
-	       && pnote->note.namedata[0] == 'G'
66b412
-	       && pnote->note.namedata[1] == 'A'
66b412
-	       && pnote->note.namedata[2] == '$'
66b412
-	       && pnote->note.namedata[3] == GNU_BUILD_ATTRIBUTE_VERSION)
66b412
+      else if (is_version_note (pnote))
66b412
 	{
66b412
 	  if (pnote->note.namedata[4] == '2')
66b412
 	    ++ version_2_seen;
66b412
@@ -2146,11 +2269,18 @@ merge_gnu_build_notes (bfd * abfd, asect
66b412
 
66b412
   if (version_1_seen == 0 && version_2_seen == 0 && version_3_seen == 0)
66b412
     {
66b412
+#if 0
66b412
       err = _("bad GNU build attribute notes: no known versions detected");
66b412
       goto done;
66b412
+#else
66b412
+      /* This happens with glibc.  No idea why.  */
66b412
+      non_fatal (_("%s[%s]: Warning: version note missing - assuming version 3"),
66b412
+		 bfd_get_filename (abfd), bfd_section_name (abfd, sec));
66b412
+      version_3_seen = 2;
66b412
+#endif
66b412
     }
66b412
 
66b412
-  if ((version_1_seen > 0 && version_2_seen > 0)
66b412
+  if (   (version_1_seen > 0 && version_2_seen > 0)
66b412
       || (version_1_seen > 0 && version_3_seen > 0)
66b412
       || (version_2_seen > 0 && version_3_seen > 0))
66b412
     {
66b412
@@ -2158,271 +2288,215 @@ merge_gnu_build_notes (bfd * abfd, asect
66b412
       goto done;
66b412
     }
66b412
 
66b412
-  /* Merging is only needed if there is more than one version note...  */
66b412
-  if (version_1_seen == 1 || version_2_seen == 1 || version_3_seen == 1)
66b412
-    goto done;
66b412
-
66b412
-  attribute_type_byte = version_1_seen ? 1 : 3;
66b412
-  val_start = attribute_type_byte + 1;
66b412
-
66b412
-  /* The first note should be the first version note.  */
66b412
-  if (pnotes[0].note.namedata[attribute_type_byte] != GNU_BUILD_ATTRIBUTE_VERSION)
66b412
+  /* We are now only supporting the merging v3+ notes
66b412
+     - it makes things much simpler.  */
66b412
+  if (version_3_seen == 0)
66b412
     {
66b412
-      err = _("bad GNU build attribute notes: first note not version note");
66b412
+      merge_debug ("%s: skipping merge - not using v3 notes", bfd_section_name (sec));
66b412
       goto done;
66b412
     }
66b412
 
66b412
+  merge_debug ("Merging section %s which contains %ld notes\n",
66b412
+	       sec->name, pnotes_end - pnotes);
66b412
+
66b412
+  /* Sort the notes.  */
66b412
+  qsort (pnotes, pnotes_end - pnotes, sizeof (* pnotes),
66b412
+	 compare_gnu_build_notes);
66b412
+
66b412
+#if DEBUG_MERGE
66b412
+  merge_debug ("Results of initial sort:\n");
66b412
+  for (pnote = pnotes; pnote < pnotes_end; pnote ++)
66b412
+    merge_debug ("offset %#08lx range %#08lx..%#08lx type %ld attribute %d namesz %ld\n",
66b412
+		 (pnote->note.namedata - (char *) contents) - 12,
66b412
+		 pnote->start, pnote->end,
66b412
+		 pnote->note.type,
66b412
+		 pnote->note.namedata[3],
66b412
+		 pnote->note.namesz
66b412
+		 );
66b412
+#endif
66b412
+
66b412
   /* Now merge the notes.  The rules are:
66b412
-     1. Preserve the ordering of the notes.
66b412
-     2. Preserve any NT_GNU_BUILD_ATTRIBUTE_FUNC notes.
66b412
-     3. Eliminate any NT_GNU_BUILD_ATTRIBUTE_OPEN notes that have the same
66b412
-        full name field as the immediately preceeding note with the same type
66b412
-	of name and whose address ranges coincide.
66b412
-	IE - if there are gaps in the coverage of the notes, then these gaps
66b412
-	must be preserved.
66b412
-     4. Combine the numeric value of any NT_GNU_BUILD_ATTRIBUTE_OPEN notes
66b412
-        of type GNU_BUILD_ATTRIBUTE_STACK_SIZE.
66b412
-     5. If an NT_GNU_BUILD_ATTRIBUTE_OPEN note is going to be preserved and
66b412
-        its description field is empty then the nearest preceeding OPEN note
66b412
-	with a non-empty description field must also be preserved *OR* the
66b412
-	description field of the note must be changed to contain the starting
66b412
-	address to which it refers.
66b412
-     6. Notes with the same start and end address can be deleted.  */
66b412
+     1. If a note has a zero range, it can be eliminated.
66b412
+     2. If two notes have the same namedata then:
66b412
+        2a. If one note's range is fully covered by the other note
66b412
+	    then it can be deleted.
66b412
+	2b. If one note's range partially overlaps or adjoins the
66b412
+	    other note then if they are both of the same type (open
66b412
+	    or func) then they can be merged and one deleted.  If
66b412
+	    they are of different types then they cannot be merged.  */
66b412
   for (pnote = pnotes + 1; pnote < pnotes_end; pnote ++)
66b412
     {
66b412
-      int                      note_type;
66b412
-      objcopy_internal_note *  back;
66b412
-      objcopy_internal_note *  prev_open_with_range = NULL;
66b412
+      /* Skip already deleted notes.
66b412
+	 FIXME: Can this happen ?  We are scanning forwards and
66b412
+	 deleting backwards after all.  */
66b412
+      if (is_deleted_note (pnote))
66b412
+	continue;
66b412
 
66b412
-      /* Rule 6 - delete 0-range notes.  */
66b412
+      /* Rule 1 - delete 0-range notes.  */
66b412
       if (pnote->start == pnote->end)
66b412
 	{
66b412
-	  duplicate_found = TRUE;
66b412
+	  merge_debug ("Delete note at offset %#08lx - empty range\n",
66b412
+		       (pnote->note.namedata - (char *) contents) - 12);
66b412
 	  pnote->note.type = 0;
66b412
 	  continue;
66b412
 	}
66b412
 
66b412
-      /* Rule 2 - preserve function notes.  */
66b412
-      if (! is_open_note (pnote))
66b412
-	{
66b412
-	  int iter;
66b412
-
66b412
-	  /* Check to see if there is an identical previous function note.
66b412
-	     This can happen with overlays for example.  */
66b412
-	  for (iter = 0, back = pnote -1; back >= pnotes; back --)
66b412
-	    {
66b412
-	      if (back->start == pnote->start
66b412
-		  && back->end == pnote->end
66b412
-		  && back->note.namesz == pnote->note.namesz
66b412
-		  && memcmp (back->note.namedata, pnote->note.namedata, pnote->note.namesz) == 0)
66b412
-		{
66b412
-		  duplicate_found = TRUE;
66b412
-		  pnote->note.type = 0;
66b412
-		  break;
66b412
-		}
66b412
-
66b412
-	      /* Don't scan too far back however.  */
66b412
-	      if (iter ++ > 16)
66b412
-		break;
66b412
-	    }
66b412
-	  continue;
66b412
-	}
66b412
-
66b412
-      note_type = pnote->note.namedata[attribute_type_byte];
66b412
-
66b412
-      /* Scan backwards from pnote, looking for duplicates.
66b412
-	 Clear the type field of any found - but do not delete them just yet.  */
66b412
-      for (back = pnote - 1; back >= pnotes; back --)
66b412
-	{
66b412
-	  int back_type = back->note.namedata[attribute_type_byte];
66b412
-
66b412
-	  /* If this is the first open note with an address
66b412
-	     range that	we have encountered then record it.  */
66b412
-	  if (prev_open_with_range == NULL
66b412
-	      && back->note.descsz > 0
66b412
-	      && ! is_func_note (back))
66b412
-	    prev_open_with_range = back;
66b412
-
66b412
-	  if (! is_open_note (back))
66b412
-	    continue;
66b412
+      int iter;
66b412
+      objcopy_internal_note * back;
66b412
 
66b412
-	  /* If the two notes are different then keep on searching.  */
66b412
-	  if (back_type != note_type)
66b412
+      /* Rule 2: Check to see if there is an identical previous note.  */
66b412
+      for (iter = 0, back = pnote - 1; back >= pnotes; back --)
66b412
+	{
66b412
+	  if (is_deleted_note (back))
66b412
 	    continue;
66b412
 
66b412
-	  /* Rule 4 - combine stack size notes.  */
66b412
-	  if (back_type == GNU_BUILD_ATTRIBUTE_STACK_SIZE)
66b412
+	  /* Our sorting function should have placed all identically
66b412
+	     attributed notes together, so if we see a note of a different
66b412
+	     attribute type stop searching.  */
66b412
+	  if (back->note.namesz != pnote->note.namesz
66b412
+	      || memcmp (back->note.namedata,
66b412
+			 pnote->note.namedata, pnote->note.namesz) != 0)
66b412
+	    break;
66b412
+	  
66b412
+	  if (back->start == pnote->start
66b412
+	      && back->end == pnote->end)
66b412
 	    {
66b412
-	      unsigned char * name;
66b412
-	      unsigned long   note_val;
66b412
-	      unsigned long   back_val;
66b412
-	      unsigned int    shift;
66b412
-	      unsigned int    bytes;
66b412
-	      unsigned long   byte;
66b412
-
66b412
-	      for (shift = 0, note_val = 0,
66b412
-		     bytes = pnote->note.namesz - val_start,
66b412
-		     name = (unsigned char *) pnote->note.namedata + val_start;
66b412
-		   bytes--;)
66b412
-		{
66b412
-		  byte = (* name ++) & 0xff;
66b412
-		  note_val |= byte << shift;
66b412
-		  shift += 8;
66b412
-		}
66b412
-
66b412
-	      for (shift = 0, back_val = 0,
66b412
-		     bytes = back->note.namesz - val_start,
66b412
-		     name = (unsigned char *) back->note.namedata + val_start;
66b412
-		   bytes--;)
66b412
-		{
66b412
-		  byte = (* name ++) & 0xff;
66b412
-		  back_val |= byte << shift;
66b412
-		  shift += 8;
66b412
-		}
66b412
-
66b412
-	      back_val += note_val;
66b412
-	      if (num_bytes (back_val) >= back->note.namesz - val_start)
66b412
-		{
66b412
-		  /* We have a problem - the new value requires more bytes of
66b412
-		     storage in the name field than are available.  Currently
66b412
-		     we have no way of fixing this, so we just preserve both
66b412
-		     notes.  */
66b412
-		  continue;
66b412
-		}
66b412
-
66b412
-	      /* Write the new val into back.  */
66b412
-	      name = (unsigned char *) back->note.namedata + val_start;
66b412
-	      while (name < (unsigned char *) back->note.namedata
66b412
-		     + back->note.namesz)
66b412
-		{
66b412
-		  byte = back_val & 0xff;
66b412
-		  * name ++ = byte;
66b412
-		  if (back_val == 0)
66b412
-		    break;
66b412
-		  back_val >>= 8;
66b412
-		}
66b412
-
66b412
-	      duplicate_found = TRUE;
66b412
+	      merge_debug ("Delete note at offset %#08lx - duplicate of note at offset %#08lx\n",
66b412
+			   (pnote->note.namedata - (char *) contents) - 12,
66b412
+			   (back->note.namedata - (char *) contents) - 12);
66b412
 	      pnote->note.type = 0;
66b412
 	      break;
66b412
 	    }
66b412
 
66b412
-	  /* Rule 3 - combine identical open notes.  */
66b412
-	  if (back->note.namesz == pnote->note.namesz
66b412
-	      && memcmp (back->note.namedata,
66b412
-			 pnote->note.namedata, back->note.namesz) == 0
66b412
-	      && ! gap_exists (back, pnote))
66b412
+	  /* Rule 2a.  */
66b412
+	  if (contained_by (pnote, back))
66b412
 	    {
66b412
-	      duplicate_found = TRUE;
66b412
+	      merge_debug ("Delete note at offset %#08lx - fully contained by note at %#08lx\n",
66b412
+			   (pnote->note.namedata - (char *) contents) - 12,
66b412
+			   (back->note.namedata - (char *) contents) - 12);
66b412
 	      pnote->note.type = 0;
66b412
+	      break;
66b412
+	    }
66b412
 
66b412
-	      if (pnote->end > back->end)
66b412
-		back->end = pnote->end;
66b412
+#if DEBUG_MERGE
66b412
+	  /* This should not happen as we have sorted the
66b412
+	     notes with earlier starting addresses first.  */
66b412
+	  if (contained_by (back, pnote))
66b412
+	    merge_debug ("ERROR: UNEXPECTED CONTAINMENT\n");
66b412
+#endif
66b412
+
66b412
+	  /* Rule 2b.  */
66b412
+	  if (overlaps_or_adjoins (back, pnote)
66b412
+	      && is_func_note (back) == is_func_note (pnote))
66b412
+	    {
66b412
+	      merge_debug ("Delete note at offset %#08lx - merge into note at %#08lx\n",
66b412
+			   (pnote->note.namedata - (char *) contents) - 12,
66b412
+			   (back->note.namedata - (char *) contents) - 12);
66b412
 
66b412
-	      if (version_3_seen)
66b412
-		back->modified = TRUE;
66b412
+	      back->end   = back->end > pnote->end ? back->end : pnote->end;
66b412
+	      back->start = back->start < pnote->start ? back->start : pnote->start;
66b412
+	      pnote->note.type = 0;
66b412
 	      break;
66b412
 	    }
66b412
 
66b412
-	  /* Rule 5 - Since we are keeping this note we must check to see
66b412
-	     if its description refers back to an earlier OPEN version
66b412
-	     note that has been scheduled for deletion.  If so then we
66b412
-	     must make sure that version note is also preserved.  */
66b412
-	  if (version_3_seen)
66b412
-	    {
66b412
-	      /* As of version 3 we can just
66b412
-		 move the range into the note.  */
66b412
-	      pnote->modified = TRUE;
66b412
-	      pnote->note.type = NT_GNU_BUILD_ATTRIBUTE_FUNC;
66b412
-	      back->modified = TRUE;
66b412
-	      back->note.type = NT_GNU_BUILD_ATTRIBUTE_FUNC;
66b412
-	    }
66b412
-	  else
66b412
+	  /* Don't scan too far back however.  */
66b412
+	  if (iter ++ > 16)
66b412
 	    {
66b412
-	      if (pnote->note.descsz == 0
66b412
-		  && prev_open_with_range != NULL
66b412
-		  && prev_open_with_range->note.type == 0)
66b412
-		prev_open_with_range->note.type = NT_GNU_BUILD_ATTRIBUTE_OPEN;
66b412
+	      /* FIXME: Not sure if this can ever be triggered.  */
66b412
+	      merge_debug ("ITERATION LIMIT REACHED\n");
66b412
+	      break;
66b412
 	    }
66b412
-
66b412
-	  /* We have found a similar attribute but the details do not match.
66b412
-	     Stop searching backwards.  */
66b412
-	  break;
66b412
 	}
66b412
-    }
66b412
-
66b412
-  if (duplicate_found)
66b412
-    {
66b412
-      bfd_byte *     new_contents;
66b412
-      bfd_byte *     old;
66b412
-      bfd_byte *     new;
66b412
-      bfd_size_type  new_size;
66b412
-      bfd_vma        prev_start = 0;
66b412
-      bfd_vma        prev_end = 0;
66b412
-
66b412
-      /* Eliminate the duplicates.  */
66b412
-      new = new_contents = xmalloc (size);
66b412
-      for (pnote = pnotes, old = contents;
66b412
-	   pnote < pnotes_end;
66b412
-	   pnote ++)
66b412
-	{
66b412
-	  bfd_size_type note_size = 12 + pnote->note.namesz + pnote->note.descsz;
66b412
-
66b412
-	  if (pnote->note.type != 0)
66b412
+#if DEBUG_MERGE
66b412
+      if (! is_deleted_note (pnote))
66b412
+	merge_debug ("Unable to do anything with note at %#08lx\n",
66b412
+		     (pnote->note.namedata - (char *) contents) - 12);
66b412
+#endif		     
66b412
+    }
66b412
+
66b412
+  /* Resort the notes.  */
66b412
+  merge_debug ("Final sorting of notes\n");
66b412
+  qsort (pnotes, pnotes_end - pnotes, sizeof (* pnotes), sort_gnu_build_notes);
66b412
+
66b412
+  /* Reconstruct the ELF notes.  */
66b412
+  bfd_byte *     new_contents;
66b412
+  bfd_byte *     old;
66b412
+  bfd_byte *     new;
66b412
+  bfd_size_type  new_size;
66b412
+  bfd_vma        prev_start = 0;
66b412
+  bfd_vma        prev_end = 0;
66b412
+
66b412
+  new = new_contents = xmalloc (size);
66b412
+  for (pnote = pnotes, old = contents;
66b412
+       pnote < pnotes_end;
66b412
+       pnote ++)
66b412
+    {
66b412
+      bfd_size_type note_size = 12 + pnote->padded_namesz + pnote->note.descsz;
66b412
+
66b412
+      if (! is_deleted_note (pnote))
66b412
+	{
66b412
+	  /* Create the note, potentially using the
66b412
+	     address range of the previous note.  */
66b412
+	  if (pnote->start == prev_start && pnote->end == prev_end)
66b412
+	    {
66b412
+	      bfd_put_32 (abfd, pnote->note.namesz, new);
66b412
+	      bfd_put_32 (abfd, 0, new + 4);
66b412
+	      bfd_put_32 (abfd, pnote->note.type, new + 8);
66b412
+	      new += 12;
66b412
+	      memcpy (new, pnote->note.namedata, pnote->note.namesz);
66b412
+	      if (pnote->note.namesz < pnote->padded_namesz)
66b412
+		memset (new + pnote->note.namesz, 0, pnote->padded_namesz - pnote->note.namesz);
66b412
+	      new += pnote->padded_namesz;
66b412
+	    }
66b412
+	  else
66b412
 	    {
66b412
-	      if (pnote->modified)
66b412
+	      bfd_put_32 (abfd, pnote->note.namesz, new);
66b412
+	      bfd_put_32 (abfd, is_64bit (abfd) ? 16 : 8, new + 4);
66b412
+	      bfd_put_32 (abfd, pnote->note.type, new + 8);
66b412
+	      new += 12;
66b412
+	      memcpy (new, pnote->note.namedata, pnote->note.namesz);
66b412
+	      if (pnote->note.namesz < pnote->padded_namesz)
66b412
+		memset (new + pnote->note.namesz, 0, pnote->padded_namesz - pnote->note.namesz);
66b412
+	      new += pnote->padded_namesz;
66b412
+	      if (is_64bit (abfd))
66b412
 		{
66b412
-		  /* If the note has been modified then we must copy it by
66b412
-		     hand, potentially adding in a new description field.  */
66b412
-		  if (pnote->start == prev_start && pnote->end == prev_end)
66b412
-		    {
66b412
-		      bfd_put_32 (abfd, pnote->note.namesz, new);
66b412
-		      bfd_put_32 (abfd, 0, new + 4);
66b412
-		      bfd_put_32 (abfd, pnote->note.type, new + 8);
66b412
-		      new += 12;
66b412
-		      memcpy (new, pnote->note.namedata, pnote->note.namesz);
66b412
-		      new += pnote->note.namesz;
66b412
-		    }
66b412
-		  else
66b412
-		    {
66b412
-		      bfd_put_32 (abfd, pnote->note.namesz, new);
66b412
-		      bfd_put_32 (abfd, is_64bit (abfd) ? 16 : 8, new + 4);
66b412
-		      bfd_put_32 (abfd, pnote->note.type, new + 8);
66b412
-		      new += 12;
66b412
-		      memcpy (new, pnote->note.namedata, pnote->note.namesz);
66b412
-		      new += pnote->note.namesz;
66b412
-		      if (is_64bit (abfd))
66b412
-			{
66b412
-			  bfd_put_64 (abfd, pnote->start, new);
66b412
-			  bfd_put_64 (abfd, pnote->end, new + 8);
66b412
-			  new += 16;
66b412
-			}
66b412
-		      else
66b412
-			{
66b412
-			  bfd_put_32 (abfd, pnote->start, new);
66b412
-			  bfd_put_32 (abfd, pnote->end, new + 4);
66b412
-			  new += 8;
66b412
-			}
66b412
-		    }
66b412
+		  bfd_put_64 (abfd, pnote->start, new);
66b412
+		  bfd_put_64 (abfd, pnote->end, new + 8);
66b412
+		  new += 16;
66b412
 		}
66b412
 	      else
66b412
 		{
66b412
-		  memcpy (new, old, note_size);
66b412
-		  new += note_size;
66b412
+		  bfd_put_32 (abfd, pnote->start, new);
66b412
+		  bfd_put_32 (abfd, pnote->end, new + 4);
66b412
+		  new += 8;
66b412
 		}
66b412
+
66b412
 	      prev_start = pnote->start;
66b412
 	      prev_end = pnote->end;
66b412
 	    }
66b412
-
66b412
-	  old += note_size;
66b412
 	}
66b412
 
66b412
-      new_size = new - new_contents;
66b412
-      memcpy (contents, new_contents, new_size);
66b412
-      size = new_size;
66b412
-      free (new_contents);
66b412
+      old += note_size;
66b412
     }
66b412
 
66b412
+#if DEBUG_MERGE
66b412
+  merge_debug ("Results of merge:\n");
66b412
+  for (pnote = pnotes; pnote < pnotes_end; pnote ++)
66b412
+    if (! is_deleted_note (pnote))
66b412
+      merge_debug ("offset %#08lx range %#08lx..%#08lx type %ld attribute %d namesz %ld\n",
66b412
+		   (pnote->note.namedata - (char *) contents) - 12,
66b412
+		   pnote->start, pnote->end,
66b412
+		   pnote->note.type,
66b412
+		   pnote->note.namedata[3],
66b412
+		   pnote->note.namesz
66b412
+		   );
66b412
+#endif
66b412
+  
66b412
+  new_size = new - new_contents;
66b412
+  memcpy (contents, new_contents, new_size);
66b412
+  size = new_size;
66b412
+  free (new_contents);
66b412
+
66b412
  done:
66b412
   if (err)
66b412
     {
66b412
@@ -2761,52 +2835,61 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 	}
66b412
     }
66b412
 
66b412
+  merged_note_section * merged_note_sections = NULL;
66b412
   if (merge_notes)
66b412
     {
66b412
       /* This palaver is necessary because we must set the output
66b412
 	 section size first, before its contents are ready.  */
66b412
-      osec = bfd_get_section_by_name (ibfd, GNU_BUILD_ATTRS_SECTION_NAME);
66b412
-      if (osec && is_merged_note_section (ibfd, osec))
66b412
+      for (osec = ibfd->sections; osec != NULL; osec = osec->next)
66b412
 	{
66b412
-	  bfd_size_type size;
66b412
-	  
66b412
-	  size = bfd_get_section_size (osec);
66b412
+	  if (! is_mergeable_note_section (ibfd, osec))
66b412
+	    continue;
66b412
+
66b412
+	  bfd_size_type size = bfd_section_size (obfd, osec);
66b412
 	  if (size == 0)
66b412
 	    {
66b412
-	      bfd_nonfatal_message (NULL, ibfd, osec, _("warning: note section is empty"));
66b412
-	      merge_notes = FALSE;
66b412
+	      bfd_nonfatal_message (NULL, ibfd, osec,
66b412
+				    _("warning: note section is empty"));
66b412
+	      continue;
66b412
 	    }
66b412
-	  else if (! bfd_get_full_section_contents (ibfd, osec, & merged_notes))
66b412
+
66b412
+	  merged_note_section * merged = xmalloc (sizeof * merged);
66b412
+	  merged->contents = NULL;
66b412
+	  if (! bfd_get_full_section_contents (ibfd, osec, & merged->contents))
66b412
 	    {
66b412
-	      bfd_nonfatal_message (NULL, ibfd, osec, _("warning: could not load note section"));
66b412
-	      free (merged_notes);
66b412
-	      merged_notes = NULL;
66b412
-	      merge_notes = FALSE;
66b412
+	      bfd_nonfatal_message (NULL, ibfd, osec,
66b412
+				    _("warning: could not load note section"));
66b412
+	      free (merged->contents);
66b412
+	      free (merged);
66b412
+	      continue;
66b412
 	    }
66b412
-	  else
66b412
+
66b412
+	  merged->size = merge_gnu_build_notes (ibfd, osec, size,
66b412
+						merged->contents);
66b412
+	  if (merged->size == size)
66b412
+	    {
66b412
+	      /* Merging achieves nothing.  */
66b412
+	      merge_debug ("Merge of section %s achieved nothing - skipping\n",
66b412
+			   bfd_section_name (obfd, osec));
66b412
+	      free (merged->contents);
66b412
+	      free (merged);
66b412
+	      continue;
66b412
+	    }
66b412
+
66b412
+	  if (osec->output_section == NULL
66b412
+	      || !bfd_set_section_size (obfd, osec->output_section, merged->size))
66b412
 	    {
66b412
-	      merged_size = merge_gnu_build_notes (ibfd, osec, size, merged_notes);
66b412
-	      if (merged_size == size)
66b412
-		{
66b412
-		  /* Merging achieves nothing.  */
66b412
-		  free (merged_notes);
66b412
-		  merged_notes = NULL;
66b412
-		  merge_notes = FALSE;
66b412
-		  merged_size = 0;
66b412
-		}
66b412
-	      else
66b412
-		{
66b412
-		  if (osec->output_section == NULL
66b412
-		      || ! bfd_set_section_size (obfd, osec->output_section, merged_size))
66b412
-		    {
66b412
-		      bfd_nonfatal_message (NULL, obfd, osec, _("warning: failed to set merged notes size"));
66b412
-		      free (merged_notes);
66b412
-		      merged_notes = NULL;
66b412
-		      merge_notes = FALSE;
66b412
-		      merged_size = 0;
66b412
-		    }
66b412
-		}
66b412
+	      bfd_nonfatal_message (NULL, obfd, osec,
66b412
+				    _("warning: failed to set merged notes size"));
66b412
+	      free (merged->contents);
66b412
+	      free (merged);
66b412
+	      continue;
66b412
 	    }
66b412
+
66b412
+	  /* Add section to list of merged sections.  */
66b412
+	  merged->sec  = osec;
66b412
+	  merged->next = merged_note_sections;
66b412
+	  merged_note_sections = merged;
66b412
 	}
66b412
     }
66b412
 
66b412
@@ -3134,25 +3217,72 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 	}
66b412
     }
66b412
 
66b412
-  if (merge_notes)
66b412
+  if (merged_note_sections != NULL)
66b412
     {
66b412
-      osec = bfd_get_section_by_name (obfd, GNU_BUILD_ATTRS_SECTION_NAME);
66b412
-      if (osec && is_merged_note_section (obfd, osec))
66b412
+      merged_note_section * merged = NULL;
66b412
+
66b412
+      for (osec = obfd->sections; osec != NULL; osec = osec->next)
66b412
 	{
66b412
-	  if (! bfd_set_section_contents (obfd, osec, merged_notes, 0, merged_size))
66b412
+	  if (! is_mergeable_note_section (obfd, osec))
66b412
+	    continue;
66b412
+
66b412
+	  if (merged == NULL)
66b412
+	    merged = merged_note_sections;
66b412
+
66b412
+	  /* It is likely that output sections are in the same order
66b412
+	     as the input sections, but do not assume that this is
66b412
+	     the case.  */
66b412
+	  if (strcmp (bfd_section_name (obfd, merged->sec),
66b412
+		      bfd_section_name (obfd, osec)) != 0)
66b412
+	    {
66b412
+	      for (merged = merged_note_sections;
66b412
+		   merged != NULL;
66b412
+		   merged = merged->next)
66b412
+		if (strcmp (bfd_section_name (obfd, merged->sec),
66b412
+			    bfd_section_name (obfd, osec)) == 0)
66b412
+		  break;
66b412
+
66b412
+	      if (merged == NULL)
66b412
+		{
66b412
+		  bfd_nonfatal_message
66b412
+		    (NULL, obfd, osec,
66b412
+		     _("error: failed to copy merged notes into output"));
66b412
+		  continue;
66b412
+		}
66b412
+	    }
66b412
+
66b412
+	  if (! is_mergeable_note_section (obfd, osec))
66b412
 	    {
66b412
-	      bfd_nonfatal_message (NULL, obfd, osec, _("error: failed to copy merged notes into output"));
66b412
-	      /* There is a potential resource leak here, but it is not important.  */
66b412
-	      /* coverity[leaked_storage: FALSE] */
66b412
+	      bfd_nonfatal_message
66b412
+		(NULL, obfd, osec,
66b412
+		 _("error: failed to copy merged notes into output"));
66b412
+	      continue;
66b412
+	    }
66b412
+
66b412
+	  if (! bfd_set_section_contents (obfd, osec, merged->contents, 0,
66b412
+					  merged->size))
66b412
+	    {
66b412
+	      bfd_nonfatal_message
66b412
+		(NULL, obfd, osec,
66b412
+		 _("error: failed to copy merged notes into output"));
66b412
 	      return FALSE;
66b412
 	    }
66b412
+
66b412
+	  merged = merged->next;
66b412
+	}
66b412
+
66b412
+      /* Free the memory.  */
66b412
+      merged_note_section * next;
66b412
+      for (merged = merged_note_sections; merged != NULL; merged = next)
66b412
+	{
66b412
+	  next = merged->next;
66b412
+	  free (merged->contents);
66b412
+	  free (merged);
66b412
 	}
66b412
-      else if (! is_strip)
66b412
-	bfd_nonfatal_message (NULL, obfd, osec, _("could not find any mergeable note sections"));
66b412
-      free (merged_notes);
66b412
-      merged_notes = NULL;
66b412
-      merge_notes = FALSE;
66b412
     }
66b412
+  else if (merge_notes && ! is_strip)
66b412
+    non_fatal (_("%s: Could not find any mergeable note sections"),
66b412
+	       bfd_get_filename (ibfd));
66b412
 
66b412
   if (gnu_debuglink_filename != NULL)
66b412
     {
66b412
@@ -3915,7 +4045,7 @@ skip_section (bfd *ibfd, sec_ptr isectio
66b412
 
66b412
   /* When merging a note section we skip the copying of the contents,
66b412
      but not the copying of the relocs associated with the contents.  */
66b412
-  if (skip_copy && is_merged_note_section (ibfd, isection))
66b412
+  if (skip_copy && is_mergeable_note_section (ibfd, isection))
66b412
     return TRUE;
66b412
 
66b412
   flags = bfd_get_section_flags (ibfd, isection);
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-32.d binutils-2.30/binutils/testsuite/binutils-all/note-2-32.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-2-32.d	2019-10-28 17:08:43.358324887 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-2-32.d	2019-10-28 17:16:57.804615900 +0000
66b412
@@ -5,13 +5,12 @@
66b412
 #source: note-2-32.s
66b412
 
66b412
 #...
66b412
-  Owner                 Data size	Description
66b412
-[ 	]+\$<version>1[ 	]+0x00000004[ 	]+OPEN[ 	]+Applies to region from 0x100 \(note1.s\)
66b412
-[ 	]+\$<tool>gcc 7.0.1[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\+<stack prot>true[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\*<PIC>static[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\*<ABI>0x0[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\$<version>1[ 	]+0x00000004[ 	]+OPEN[ 	]+Applies to region from 0x104 \(note2.s\)
66b412
-[ 	]+!<stack prot>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x104
66b412
-[ 	]+\*<PIC>pic[ 	]+0x00000004[ 	]+func[ 	]+Applies to region from 0x104 \(func1\)
66b412
+[ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x10b \(note1.s\)
66b412
+[ 	]+GA\$<tool>gcc 7.0.1[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x10b
66b412
+[ 	]+GA\*<ABI>0x0[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x108 \(note1.s\)
66b412
+[ 	]+GA\+<stack prot>true[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x104 \(note1.s\)
66b412
+[ 	]+GA\*<PIC>static[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x104
66b412
+[ 	]+GA!<stack prot>false[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x104 to 0x108 \(note2.s\)
66b412
+[ 	]+GA\*<PIC>pic[ 	]+0x00000008[ 	]+func[ 	]+Applies to region from 0x104 to 0x106 \(func1\)
66b412
 #...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-32.s binutils-2.30/binutils/testsuite/binutils-all/note-2-32.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-2-32.s	2019-10-28 17:08:43.355324910 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-2-32.s	2019-10-28 17:09:04.609165478 +0000
66b412
@@ -6,32 +6,37 @@ note1.s:
66b412
 	
66b412
 	.pushsection .gnu.build.attributes, "0x100000", %note
66b412
 	.balign 4
66b412
-	.dc.l 4
66b412
-	.dc.l 4
66b412
+	.dc.l 8
66b412
+	.dc.l 8
66b412
 	.dc.l 0x100
66b412
-	.asciz "$?1"
66b412
+	.asciz "GA$?3p1"
66b412
 	.dc.l 0x100
66b412
+	.dc.l 0x104
66b412
 
66b412
-	.dc.l 12
66b412
+	.dc.l 14
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.asciz "$?gcc 7.0.1"
66b412
+	.asciz "GA$?gcc 7.0.1"
66b412
+	.dc.b 0,0
66b412
 
66b412
-	.dc.l 3
66b412
+	.dc.l 5
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.dc.b 0x2b, 0x2, 0
66b412
-	.dc.b 0
66b412
+	.dc.b 0x47, 0x41, 0x2b, 0x2, 0
66b412
+	.dc.b 0,0,0
66b412
 
66b412
-	.dc.l 4
66b412
+	.dc.l 6
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.dc.b 0x2a, 0x7, 0, 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0, 0
66b412
+	.dc.b 0,0
66b412
 
66b412
-	.dc.l 4
66b412
+	.dc.l 6
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.dc.b 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0,0
66b412
+	
66b412
 	.popsection
66b412
 
66b412
 
66b412
@@ -42,33 +47,38 @@ func1:
66b412
 	.dc.l 0x100
66b412
 	
66b412
 	.pushsection .gnu.build.attributes, "0x100000", %note
66b412
-	.dc.l 4 	
66b412
-	.dc.l 4		
66b412
+	.dc.l 8	
66b412
+	.dc.l 8		
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?1"	
66b412
+	.asciz "GA$?3p1"	
66b412
 	.dc.l 0x104	
66b412
-
66b412
-	.dc.l 12 	
66b412
+	.dc.l 0x108
66b412
+	
66b412
+	.dc.l 14 	
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?gcc 7.0.1"	
66b412
+	.asciz "GA$?gcc 7.0.1"
66b412
+	.dc.b 0,0
66b412
 
66b412
-	.dc.l 3		
66b412
+	.dc.l 5	
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.dc.b 0x21, 0x2, 0
66b412
-	.dc.b 0 	
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x2, 0
66b412
+	.dc.b 0,0,0
66b412
 
66b412
-	.dc.l 4		
66b412
-	.dc.l 4		
66b412
+	.dc.l 6	
66b412
+	.dc.l 8		
66b412
 	.dc.l 0x101	
66b412
-	.dc.b 0x2a, 0x7, 1, 0
66b412
-	.dc.l 0x104	
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 1, 0
66b412
+	.dc.b 0,0
66b412
+	.dc.l 0x104
66b412
+	.dc.l 0x106
66b412
 	
66b412
-	.dc.l 4		
66b412
+	.dc.l 6
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.dc.b 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0,0
66b412
 	.popsection
66b412
 
66b412
 	
66b412
@@ -77,16 +87,18 @@ note3.s:
66b412
 	.dc.l 0x100
66b412
 	
66b412
 	.pushsection .gnu.build.attributes, "0x100000", %note
66b412
-	.dc.l 4 	
66b412
-	.dc.l 4		
66b412
+	.dc.l 8	
66b412
+	.dc.l 8		
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?1"	
66b412
+	.asciz "GA$?3p1"	
66b412
 	.dc.l 0x108
66b412
+	.dc.l 0x10b
66b412
 
66b412
-	.dc.l 12 	
66b412
+	.dc.l 14	
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?gcc 7.0.1"	
66b412
+	.asciz "GA$?gcc 7.0.1"
66b412
+	.dc.b 0,0
66b412
 
66b412
 	.popsection
66b412
 	
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-64.d binutils-2.30/binutils/testsuite/binutils-all/note-2-64.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-2-64.d	2019-10-28 17:08:43.356324902 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-2-64.d	2019-10-28 17:17:05.724556490 +0000
66b412
@@ -3,19 +3,18 @@
66b412
 #objcopy: --merge-notes
66b412
 #name: merge notes section (64-bits)
66b412
 #source: note-2-64.s
66b412
-#not-target: sparc64-*-*
66b412
+#not-target: sparc64-*-*
66b412
 # Internally the Sparc64 backend uses two relocs for every one reloc visible externally.
66b412
 # Unfortunately the BFD library does not provide a target specific way to delete individual
66b412
 # relocs, so the note merging feature fails.
66b412
 
66b412
 #...
66b412
-  Owner                 Data size	Description
66b412
-[ 	]+\$<version>1[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x100 \(note1.s\)
66b412
-[ 	]+\$<tool>gcc 7.0.1[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\+<stack prot>true[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\*<PIC>static[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\*<ABI>0x0[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100
66b412
-[ 	]+\$<version>1[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x104 \(note2.s\)
66b412
-[ 	]+!<stack prot>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x104
66b412
-[ 	]+\*<PIC>pic[ 	]+0x00000008[ 	]+func[ 	]+Applies to region from 0x104 \(func1\)
66b412
+[ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x10b \(note1.s\)
66b412
+[ 	]+GA\$<tool>gcc 7.0.1[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x10b
66b412
+[ 	]+GA\*<ABI>0x0[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x108 \(note1.s\)
66b412
+[ 	]+GA\+<stack prot>true[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x104 \(note1.s\)
66b412
+[ 	]+GA\*<PIC>static[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x104
66b412
+[ 	]+GA!<stack prot>false[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x104 to 0x108 \(note2.s\)
66b412
+[ 	]+GA\*<PIC>pic[ 	]+0x00000010[ 	]+func[ 	]+Applies to region from 0x104 to 0x106 \(func1\)
66b412
 #...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-64.s binutils-2.30/binutils/testsuite/binutils-all/note-2-64.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-2-64.s	2019-10-28 17:08:43.354324917 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-2-64.s	2019-10-28 17:09:04.609165478 +0000
66b412
@@ -6,32 +6,43 @@ note1.s:
66b412
 	
66b412
 	.pushsection .gnu.build.attributes, "0x100000", %note
66b412
 	.balign 4
66b412
-	.dc.l 4
66b412
 	.dc.l 8
66b412
+	.dc.l 16
66b412
 	.dc.l 0x100
66b412
-	.asciz "$?1"
66b412
+	.asciz "GA$?3p1"
66b412
 	.8byte 0x100
66b412
+	.8byte 0x104
66b412
 
66b412
-	.dc.l 12
66b412
+	.dc.l 14
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.asciz "$?gcc 7.0.1"
66b412
+	.asciz "GA$?gcc 7.0.1"
66b412
+	.dc.b 0,0
66b412
+	
66b412
+	.dc.l 5
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2b, 0x2, 0
66b412
+	.dc.b 0,0,0
66b412
 
66b412
-	.dc.l 3
66b412
+	.dc.l 6
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.dc.b 0x2b, 0x2, 0
66b412
-	.dc.b 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0, 0
66b412
+	.dc.b 0,0
66b412
 
66b412
-	.dc.l 4
66b412
+	.dc.l 6
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.dc.b 0x2a, 0x7, 0, 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0,0
66b412
 
66b412
-	.dc.l 4
66b412
+	.dc.l 6
66b412
 	.dc.l 0
66b412
 	.dc.l 0x100
66b412
-	.dc.b 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0, 0
66b412
+	.dc.b 0,0
66b412
+
66b412
 	.popsection
66b412
 
66b412
 
66b412
@@ -43,33 +54,38 @@ func1:
66b412
 	.dc.l 0x100
66b412
 
66b412
 	.pushsection .gnu.build.attributes, "0x100000", %note
66b412
-	.dc.l 4 	
66b412
-	.dc.l 8		
66b412
+	.dc.l 8
66b412
+	.dc.l 16		
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?1"	
66b412
+	.asciz "GA$?3p1"
66b412
 	.8byte 0x104	
66b412
+	.8byte 0x108	
66b412
 
66b412
-	.dc.l 12 	
66b412
+	.dc.l 14 	
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?gcc 7.0.1"	
66b412
-
66b412
-	.dc.l 3		
66b412
+	.asciz "GA$?gcc 7.0.1"	
66b412
+	.dc.b 0,0
66b412
+	
66b412
+	.dc.l 5		
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.dc.b 0x21, 0x2, 0
66b412
-	.dc.b 0 	
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x2, 0
66b412
+	.dc.b 0,0,7 	
66b412
 
66b412
-	.dc.l 4
66b412
-	.dc.l 8	
66b412
+	.dc.l 6
66b412
+	.dc.l 16
66b412
 	.dc.l 0x101	
66b412
-	.dc.b 0x2a, 0x7, 1, 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 1, 0
66b412
+	.dc.b 0,0
66b412
 	.8byte 0x104	
66b412
+	.8byte 0x106	
66b412
 
66b412
-	.dc.l 4
66b412
+	.dc.l 6
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.dc.b 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0
66b412
+	.dc.b 0,0
66b412
 	.popsection
66b412
 	
66b412
 
66b412
@@ -78,15 +94,17 @@ note3.s:
66b412
 	.dc.l 0x100
66b412
 	
66b412
 	.pushsection .gnu.build.attributes, "0x100000", %note
66b412
-	.dc.l 4 	
66b412
-	.dc.l 8		
66b412
+	.dc.l 8	
66b412
+	.dc.l 16	
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?1"	
66b412
+	.asciz "GA$?3p1"
66b412
 	.8byte 0x108
66b412
+	.8byte 0x10b
66b412
 
66b412
-	.dc.l 12 	
66b412
+	.dc.l 14 	
66b412
 	.dc.l 0		
66b412
 	.dc.l 0x100	
66b412
-	.asciz "$?gcc 7.0.1"	
66b412
+	.asciz "GA$?gcc 7.0.1"
66b412
+	.dc.b 0,0
66b412
 
66b412
 	.popsection
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-32.d binutils-2.30/binutils/testsuite/binutils-all/note-3-32.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-3-32.d	2019-10-28 17:08:43.356324902 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-3-32.d	2019-10-28 17:09:04.609165478 +0000
66b412
@@ -7,12 +7,12 @@
66b412
 #...
66b412
 Displaying notes found in: .gnu.build.attributes
66b412
 [ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
-[ 	]+GA\$<version>2p1[ 	]+0x0000000.[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122 \(note_1.s\)
66b412
-[ 	]+GA\$<tool>gcc 6.3.1 20161221[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
-[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x0000000.[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122 \(note_1.s\)
66b412
 [ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
-[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\$<tool>gcc 6.3.1 20161221[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
 [ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
 [ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
-[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
 #...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-32.s binutils-2.30/binutils/testsuite/binutils-all/note-3-32.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-3-32.s	2019-10-28 17:08:43.354324917 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-3-32.s	2019-10-28 17:09:04.609165478 +0000
66b412
@@ -9,10 +9,11 @@ note_1.s:
66b412
 	.balign 4
66b412
 
66b412
 	.dc.l 8
66b412
-	.dc.l 4
66b412
+	.dc.l 8
66b412
 	.dc.l 0x100
66b412
-	.asciz "GA$?2p1"
66b412
-	.dc.l note_1.s
66b412
+	.asciz "GA$?3p1"
66b412
+	.dc.l 0x100 /* note_1.s */
66b412
+	.dc.l 0x122 /* note_1.s end */
66b412
 
66b412
 	.dc.l 23
66b412
 	.dc.l 0
66b412
@@ -55,4 +56,12 @@ note_1.s:
66b412
 	.dc.l 0x100
66b412
 	.dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0
66b412
 	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 5
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x8, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+
66b412
 	.popsection
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-64.d binutils-2.30/binutils/testsuite/binutils-all/note-3-64.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-3-64.d	2019-10-28 17:08:43.357324895 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-3-64.d	2019-10-28 17:09:04.609165478 +0000
66b412
@@ -7,12 +7,12 @@
66b412
 #...
66b412
 Displaying notes found in: .gnu.build.attributes
66b412
 [ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
-[ 	]+GA\$<version>2p1[ 	]+0x0000000.[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122 \(note_1.s\)
66b412
-[ 	]+GA\$<tool>gcc 6.3.1 20161221[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
-[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122 \(note_1.s\)
66b412
 [ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
-[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\$<tool>gcc 6.3.1 20161221[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
 [ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
 [ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
-[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
+[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x122
66b412
 #...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-64.s binutils-2.30/binutils/testsuite/binutils-all/note-3-64.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-3-64.s	2019-10-28 17:08:43.357324895 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-3-64.s	2019-10-28 17:09:04.609165478 +0000
66b412
@@ -9,10 +9,11 @@ note_1.s:
66b412
 	.balign 4
66b412
 
66b412
 	.dc.l 8
66b412
-	.dc.l 8
66b412
+	.dc.l 16
66b412
 	.dc.l 0x100
66b412
-	.asciz "GA$?2p1"
66b412
-	.8byte note_1.s
66b412
+	.asciz "GA$?3p1"
66b412
+	.8byte 0x100 /* note_1.s */
66b412
+	.8byte 0x122 /* note_1 end */
66b412
 
66b412
 	.dc.l 23
66b412
 	.dc.l 0
66b412
@@ -55,4 +56,11 @@ note_1.s:
66b412
 	.dc.l 0x100
66b412
 	.dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0
66b412
 	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
 	.popsection
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-32.d binutils-2.30/binutils/testsuite/binutils-all/note-4-32.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-4-32.d	2019-10-28 17:08:43.357324895 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-4-32.d	2019-10-28 17:17:19.515453041 +0000
66b412
@@ -7,13 +7,13 @@
66b412
 #...
66b412
 Displaying notes found in: .gnu.build.attributes
66b412
 [ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
-[ 	]+GA\$<version>3p3[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110 \(note_4.s\)
66b412
-[ 	]+GA\$<tool>gcc 7.2.1 20170915[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
66b412
-[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
66b412
-[ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
66b412
-[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
66b412
-[ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
66b412
-[ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
66b412
-[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
66b412
-[ 	]+GA\*<stack prot>strong[ 	]+0x00000008[ 	]+func[ 	]+Applies to region from 0x108 to 0x10c.*
66b412
+[ 	]+GA\$<version>3p3[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110 \(note_4.s\)
66b412
+[ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
66b412
+[ 	]+GA\$<tool>gcc 7.2.1 20170915[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
66b412
+[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
66b412
+[ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
66b412
+[ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
66b412
+[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
66b412
+[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
66b412
+[ 	]+GA\*<stack prot>strong[ 	]+0x00000008[ 	]+func[ 	]+Applies to region from 0x10. to 0x10c.*
66b412
 #...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-32.s binutils-2.30/binutils/testsuite/binutils-all/note-4-32.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-4-32.s	2019-10-28 17:08:43.355324910 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-4-32.s	2019-10-28 17:17:23.931419915 +0000
66b412
@@ -1,6 +1,6 @@
66b412
 	.text
66b412
 	.org 0x100
66b412
-note_4.s:
66b412
+	.equiv note_4.s, . + 2
66b412
 	.dc.l 0
66b412
 	.dc.l 0
66b412
 
66b412
@@ -18,8 +18,8 @@ note_4.s_end:
66b412
 	.dc.l 8
66b412
 	.dc.l 0x100
66b412
 	.asciz "GA$?3p3"
66b412
-	.dc.l note_4.s
66b412
-	.dc.l note_4.s_end
66b412
+	.dc.l 0x100 /* note_4.s - 2 */
66b412
+	.dc.l 0x110 /* note_4.s_end */
66b412
 
66b412
 	.dc.l 23
66b412
 	.dc.l 0
66b412
@@ -63,12 +63,18 @@ note_4.s_end:
66b412
 	.dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0
66b412
 	.dc.b 0, 0, 0
66b412
 
66b412
+	.dc.l 5
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x8, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
 	.dc.l 6
66b412
 	.dc.l 8
66b412
 	.dc.l 0x101
66b412
 	.dc.b 0x47, 0x41, 0x2a, 0x2, 0x3, 0
66b412
 	.dc.b 0, 0
66b412
-	.dc.l bar
66b412
-	.dc.l bar_end
66b412
+	.dc.l 0x108 /* bar */
66b412
+	.dc.l 0x10c /* bar_end */
66b412
 	
66b412
 	.popsection
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-64.d binutils-2.30/binutils/testsuite/binutils-all/note-4-64.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-4-64.d	2019-10-28 17:08:43.356324902 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-4-64.d	2019-10-28 17:09:04.609165478 +0000
66b412
@@ -8,13 +8,13 @@
66b412
 #...
66b412
 Displaying notes found in: .gnu.build.attributes
66b412
 [ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
-[ 	]+GA\$<version>3p3[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120 \(note_4.s\)
66b412
+[ 	]+GA\$<version>3p3[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120.*
66b412
-[ 	]+GA\$<tool>gcc 7.2.1 20170915[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
-[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
 [ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
-[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
+[ 	]+GA\$<tool>gcc 7.2.1 20170915[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
+[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
 [ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
 [ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
-[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
-[ 	]+GA\*<stack prot>strong[ 	]+0x00000010[ 	]+func[ 	]+Applies to region from 0x110 to 0x11c.*
66b412
+[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
+[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x120
66b412
+[ 	]+GA\*<stack prot>strong[ 	]+0x00000010[ 	]+func[ 	]+Applies to region from 0x110 to 0x120.*
66b412
 #...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-64.s binutils-2.30/binutils/testsuite/binutils-all/note-4-64.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-4-64.s	2019-10-28 17:08:43.356324902 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-4-64.s	2019-10-28 17:17:29.355379229 +0000
66b412
@@ -1,6 +1,6 @@
66b412
 	.text
66b412
 	.org 0x100
66b412
-note_4.s:
66b412
+	.equiv note_4.s, . + 2
66b412
 	.dc.l 0
66b412
 	.dc.l 0
66b412
 	.dc.l 0
66b412
@@ -22,8 +22,8 @@ note_4.s_end:
66b412
 	.dc.l 16
66b412
 	.dc.l 0x100
66b412
 	.asciz "GA$?3p3"
66b412
-	.8byte note_4.s
66b412
-	.8byte note_4.s_end
66b412
+	.8byte 0x100 /* note_4.s - 2 */
66b412
+	.8byte 0x120 /* note_4.s_end */
66b412
 
66b412
 	.dc.l 23
66b412
 	.dc.l 0
66b412
@@ -68,11 +68,17 @@ note_4.s_end:
66b412
 	.dc.b 0, 0, 0
66b412
 
66b412
 	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
 	.dc.l 16
66b412
 	.dc.l 0x101
66b412
 	.dc.b 0x47, 0x41, 0x2a, 0x2, 0x3, 0
66b412
 	.dc.b 0, 0
66b412
-	.8byte bar
66b412
-	.8byte bar_end
66b412
+	.8byte 0x110 /* bar */
66b412
+	.8byte 0x120 /* bar_end */
66b412
 	
66b412
 	.popsection
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-6-32.d binutils-2.30/binutils/testsuite/binutils-all/note-6-32.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-6-32.d	1970-01-01 01:00:00.000000000 +0100
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-6-32.d	2019-10-28 17:17:38.955307217 +0000
66b412
@@ -0,0 +1,20 @@
66b412
+#PROG: objcopy
66b412
+#readelf: --notes --wide
66b412
+#objcopy: --merge-notes
66b412
+#name: v3 gnu build attribute note merging (32-bit)
66b412
+#source: note-6-32.s
66b412
+
66b412
+#...
66b412
+Displaying notes found in: .gnu.build.attributes
66b412
+[ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106 \(note_test\)
66b412
+[ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\$<tool>gcc 8.3.1 20190507[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x00000008[ 	]+func[ 	]+Applies to region from 0x102 to 0x106
66b412
+[ 	]+GA\$<tool>hello world[ 	]+0x00000000[ 	]+func[ 	]+Applies to region from 0x102 to 0x106
66b412
+#...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-6-32.s binutils-2.30/binutils/testsuite/binutils-all/note-6-32.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-6-32.s	1970-01-01 01:00:00.000000000 +0100
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-6-32.s	2019-10-28 17:17:38.955307217 +0000
66b412
@@ -0,0 +1,145 @@
66b412
+	.text
66b412
+	.org    0x100
66b412
+	.global note_test
66b412
+note_test:	
66b412
+note_1_start:
66b412
+	.word 0
66b412
+note_1_end:
66b412
+note_2_start:
66b412
+	.word 0
66b412
+note_2_end:
66b412
+note_3_start:
66b412
+	.word 0
66b412
+note_3_end:
66b412
+note_test_end:	
66b412
+	.size   note_test, note_test_end - note_test
66b412
+	
66b412
+	.pushsection .gnu.build.attributes, "", %note
66b412
+	.balign 4
66b412
+
66b412
+	.dc.l 8
66b412
+	.dc.l 8
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?3p1"
66b412
+	.4byte 0x100  /* note_1_start */
66b412
+	.4byte 0x102  /* note_1_end */
66b412
+
66b412
+	.dc.l 23
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?gcc 8.3.1 20190507"
66b412
+	.dc.b 0
66b412
+
66b412
+	.dc.l 10
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 5
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x8, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	
66b412
+	.dc.l 8
66b412
+	.dc.l 8
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?3p1"
66b412
+	.4byte 0x102  /* note_2_start */
66b412
+	.4byte 0x106  /* note_3_end */
66b412
+
66b412
+	.dc.l 23
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?gcc 8.3.1 20190507"
66b412
+	.dc.b 0
66b412
+
66b412
+	.dc.l 10
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 5
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x8, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+
66b412
+	.dc.l 8
66b412
+	.dc.l 8
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?3p1"
66b412
+	.4byte 0x102  /* note_2_start */
66b412
+	.4byte 0x104  /* note_2_end */
66b412
+
66b412
+	.dc.l 16
66b412
+	.dc.l 0
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?hello world"
66b412
+
66b412
+
66b412
+	.dc.l 8
66b412
+	.dc.l 8
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?3p1"
66b412
+	.4byte 0x104  /* note_3_start */
66b412
+	.4byte 0x106  /* note_3_end */
66b412
+
66b412
+	.dc.l 16
66b412
+	.dc.l 0
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?hello world"
66b412
+
66b412
+	.popsection
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-6-64.d binutils-2.30/binutils/testsuite/binutils-all/note-6-64.d
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-6-64.d	1970-01-01 01:00:00.000000000 +0100
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-6-64.d	2019-10-28 17:17:43.659271931 +0000
66b412
@@ -0,0 +1,20 @@
66b412
+#PROG: objcopy
66b412
+#readelf: --notes --wide
66b412
+#objcopy: --merge-notes
66b412
+#name: v3 gnu build attribute note merging (64-bit)
66b412
+#source: note-6-64.s
66b412
+
66b412
+#...
66b412
+Displaying notes found in: .gnu.build.attributes
66b412
+[ 	]+Owner[ 	]+Data size[ 	]+Description
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x00000010[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106 \(note_test\)
66b412
+[ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\$<tool>gcc 8.3.1 20190507[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x106
66b412
+[ 	]+GA\$<version>3p1[ 	]+0x00000010[ 	]+func[ 	]+Applies to region from 0x102 to 0x106
66b412
+[ 	]+GA\$<tool>hello world[ 	]+0x00000000[ 	]+func[ 	]+Applies to region from 0x102 to 0x106
66b412
+#...
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-6-64.s binutils-2.30/binutils/testsuite/binutils-all/note-6-64.s
66b412
--- binutils.orig/binutils/testsuite/binutils-all/note-6-64.s	1970-01-01 01:00:00.000000000 +0100
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/note-6-64.s	2019-10-28 17:17:43.659271931 +0000
66b412
@@ -0,0 +1,145 @@
66b412
+	.text
66b412
+	.org    0x100
66b412
+	.global note_test
66b412
+note_test:	
66b412
+note_1_start:
66b412
+	.word 0
66b412
+note_1_end:
66b412
+note_2_start:
66b412
+	.word 0
66b412
+note_2_end:
66b412
+note_3_start:
66b412
+	.word 0
66b412
+note_3_end:
66b412
+note_test_end:	
66b412
+	.size   note_test, note_test_end - note_test
66b412
+	
66b412
+	.pushsection .gnu.build.attributes, "", %note
66b412
+	.balign 4
66b412
+
66b412
+	.dc.l 8
66b412
+	.dc.l 16
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?3p1"
66b412
+	.8byte 0x100  /* note_1_start */
66b412
+	.8byte 0x102  /* note_1_end */
66b412
+
66b412
+	.dc.l 23
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?gcc 8.3.1 20190507"
66b412
+	.dc.b 0
66b412
+
66b412
+	.dc.l 10
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 5
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x8, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+
66b412
+	.dc.l 8
66b412
+	.dc.l 16
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?3p1"
66b412
+	.8byte 0x102  /* note_2_start */
66b412
+	.8byte 0x106  /* note_3_end */
66b412
+
66b412
+	.dc.l 23
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.asciz "GA$?gcc 8.3.1 20190507"
66b412
+	.dc.b 0
66b412
+
66b412
+	.dc.l 10
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 6
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0
66b412
+	.dc.b 0, 0
66b412
+
66b412
+	.dc.l 5
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x21, 0x8, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+	.dc.l 13
66b412
+	.dc.l 0
66b412
+	.dc.l 0x100
66b412
+	.dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0
66b412
+	.dc.b 0, 0, 0
66b412
+
66b412
+
66b412
+	.dc.l 8
66b412
+	.dc.l 16
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?3p1"
66b412
+	.8byte 0x102  /* note_2_start */
66b412
+	.8byte 0x104  /* note_2_end */
66b412
+
66b412
+	.dc.l 16
66b412
+	.dc.l 0
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?hello world"
66b412
+
66b412
+
66b412
+	.dc.l 8
66b412
+	.dc.l 16
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?3p1"
66b412
+	.8byte 0x104  /* note_3_start */
66b412
+	.8byte 0x106  /* note_3_end */
66b412
+
66b412
+	.dc.l 16
66b412
+	.dc.l 0
66b412
+	.dc.l 0x101
66b412
+	.asciz "GA$?hello world"
66b412
+
66b412
+	.popsection
66b412
diff -rupN binutils.orig/binutils/testsuite/binutils-all/objcopy.exp binutils-2.30/binutils/testsuite/binutils-all/objcopy.exp
66b412
--- binutils.orig/binutils/testsuite/binutils-all/objcopy.exp	2019-10-28 17:08:43.353324925 +0000
66b412
+++ binutils-2.30/binutils/testsuite/binutils-all/objcopy.exp	2019-10-28 17:09:04.610165471 +0000
66b412
@@ -1057,10 +1057,12 @@ if [is_elf_format] {
66b412
 	run_dump_test "note-2-64"
66b412
 	run_dump_test "note-3-64"
66b412
 	run_dump_test "note-4-64"
66b412
+	run_dump_test "note-6-64"
66b412
     } else {
66b412
 	run_dump_test "note-2-32"
66b412
 	run_dump_test "note-3-32"
66b412
 	run_dump_test "note-4-32"
66b412
+	run_dump_test "note-6-32"
66b412
     }
66b412
     run_dump_test "note-5"
66b412
 }
66b412
--- binutils.orig/binutils/objcopy.c	2019-11-06 10:21:47.933091869 +0000
66b412
+++ binutils-2.30/binutils/objcopy.c	2019-11-06 15:12:26.964599817 +0000
66b412
@@ -2502,7 +2502,7 @@ merge_gnu_build_notes (bfd *          ab
66b412
     {
66b412
       bfd_set_error (bfd_error_bad_value);
66b412
       bfd_nonfatal_message (NULL, abfd, sec, err);
66b412
-      status = 1;
66b412
+      /* status = 1; */
66b412
     }
66b412
 
66b412
   free (pnotes);
66b412
@@ -2859,7 +2859,7 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 	    {
66b412
 	      bfd_nonfatal_message (NULL, ibfd, osec,
66b412
 				    _("warning: could not load note section"));
66b412
-	      free (merged->contents);
66b412
+	      /* Do NOT free merged->contents - it is cached and might be used elsewhere.  */
66b412
 	      free (merged);
66b412
 	      continue;
66b412
 	    }
66b412
@@ -2871,7 +2871,7 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 	      /* Merging achieves nothing.  */
66b412
 	      merge_debug ("Merge of section %s achieved nothing - skipping\n",
66b412
 			   bfd_section_name (obfd, osec));
66b412
-	      free (merged->contents);
66b412
+	      /* Do NOT free merged->contents - it is cached and might be used elsewhere.  */
66b412
 	      free (merged);
66b412
 	      continue;
66b412
 	    }
66b412
@@ -2881,7 +2881,7 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 	    {
66b412
 	      bfd_nonfatal_message (NULL, obfd, osec,
66b412
 				    _("warning: failed to set merged notes size"));
66b412
-	      free (merged->contents);
66b412
+	      /* Do NOT free merged->contents - it is cached and might be used elsewhere.  */
66b412
 	      free (merged);
66b412
 	      continue;
66b412
 	    }
66b412
--- binutils.orig/binutils/objcopy.c	2019-11-06 16:37:57.018843494 +0000
66b412
+++ binutils-2.30/binutils/objcopy.c	2019-11-06 16:40:52.669564222 +0000
66b412
@@ -2845,7 +2845,13 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 	  if (! is_mergeable_note_section (ibfd, osec))
66b412
 	    continue;
66b412
 
66b412
+	  /* If the section is going to be completly deleted then
66b412
+	     do not bother to merge it.  */
66b412
+	  if (osec->output_section == NULL)
66b412
+	    continue;
66b412
+
66b412
 	  bfd_size_type size = bfd_section_size (obfd, osec);
66b412
+
66b412
 	  if (size == 0)
66b412
 	    {
66b412
 	      bfd_nonfatal_message (NULL, ibfd, osec,
66b412
@@ -2859,29 +2865,22 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 	    {
66b412
 	      bfd_nonfatal_message (NULL, ibfd, osec,
66b412
 				    _("warning: could not load note section"));
66b412
-	      /* Do NOT free merged->contents - it is cached and might be used elsewhere.  */
66b412
 	      free (merged);
66b412
 	      continue;
66b412
 	    }
66b412
 
66b412
 	  merged->size = merge_gnu_build_notes (ibfd, osec, size,
66b412
 						merged->contents);
66b412
-	  if (merged->size == size)
66b412
-	    {
66b412
-	      /* Merging achieves nothing.  */
66b412
-	      merge_debug ("Merge of section %s achieved nothing - skipping\n",
66b412
-			   bfd_section_name (obfd, osec));
66b412
-	      /* Do NOT free merged->contents - it is cached and might be used elsewhere.  */
66b412
-	      free (merged);
66b412
-	      continue;
66b412
-	    }
66b412
+	  /* FIXME: Once we have read the contents in, we must write
66b412
+	     them out again.  So even if the mergeing has achieved
66b412
+	     nothing we still add this entry to the merge list.  */
66b412
 
66b412
-	  if (osec->output_section == NULL
66b412
-	      || !bfd_set_section_size (obfd, osec->output_section, merged->size))
66b412
+	  if (size != merged->size
66b412
+	      && !bfd_set_section_size (obfd, osec->output_section, merged->size))
66b412
 	    {
66b412
 	      bfd_nonfatal_message (NULL, obfd, osec,
66b412
 				    _("warning: failed to set merged notes size"));
66b412
-	      /* Do NOT free merged->contents - it is cached and might be used elsewhere.  */
66b412
+	      free (merged->contents);
66b412
 	      free (merged);
66b412
 	      continue;
66b412
 	    }
66b412
@@ -3246,16 +3245,16 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 		{
66b412
 		  bfd_nonfatal_message
66b412
 		    (NULL, obfd, osec,
66b412
-		     _("error: failed to copy merged notes into output"));
66b412
+		     _("error: failed to locate merged notes"));
66b412
 		  continue;
66b412
 		}
66b412
 	    }
66b412
 
66b412
-	  if (! is_mergeable_note_section (obfd, osec))
66b412
+	  if (merged->contents == NULL)
66b412
 	    {
66b412
 	      bfd_nonfatal_message
66b412
 		(NULL, obfd, osec,
66b412
-		 _("error: failed to copy merged notes into output"));
66b412
+		 _("error: failed to merged notes"));
66b412
 	      continue;
66b412
 	    }
66b412
 
66b412
--- binutils.orig/binutils/objcopy.c	2019-11-20 10:59:20.993888328 +0000
66b412
+++ binutils-2.30/binutils/objcopy.c	2019-11-20 16:59:50.714905419 +0000
66b412
@@ -2292,7 +2292,7 @@ merge_gnu_build_notes (bfd *          ab
66b412
      - it makes things much simpler.  */
66b412
   if (version_3_seen == 0)
66b412
     {
66b412
-      merge_debug ("%s: skipping merge - not using v3 notes", bfd_section_name (sec));
66b412
+      merge_debug ("%s: skipping merge - not using v3 notes", bfd_section_name (abfd, sec));
66b412
       goto done;
66b412
     }
66b412
 
66b412
@@ -2324,7 +2324,7 @@ merge_gnu_build_notes (bfd *          ab
66b412
 	    other note then if they are both of the same type (open
66b412
 	    or func) then they can be merged and one deleted.  If
66b412
 	    they are of different types then they cannot be merged.  */
66b412
-  for (pnote = pnotes + 1; pnote < pnotes_end; pnote ++)
66b412
+  for (pnote = pnotes; pnote < pnotes_end; pnote ++)
66b412
     {
66b412
       /* Skip already deleted notes.
66b412
 	 FIXME: Can this happen ?  We are scanning forwards and
66b412
@@ -2426,7 +2426,9 @@ merge_gnu_build_notes (bfd *          ab
66b412
   bfd_vma        prev_start = 0;
66b412
   bfd_vma        prev_end = 0;
66b412
 
66b412
-  new = new_contents = xmalloc (size);
66b412
+  /* Not sure how, but the notes might grow in size.
66b412
+     (eg see PR 1774507).  Allow for this here.  */
66b412
+  new = new_contents = xmalloc (size * 2);
66b412
   for (pnote = pnotes, old = contents;
66b412
        pnote < pnotes_end;
66b412
        pnote ++)
66b412
@@ -2493,8 +2495,11 @@ merge_gnu_build_notes (bfd *          ab
66b412
 #endif
66b412
   
66b412
   new_size = new - new_contents;
66b412
-  memcpy (contents, new_contents, new_size);
66b412
-  size = new_size;
66b412
+  if (new_size < size)
66b412
+    {
66b412
+      memcpy (contents, new_contents, new_size);
66b412
+      size = new_size;
66b412
+    }
66b412
   free (new_contents);
66b412
 
66b412
  done:
66b412
@@ -2940,6 +2945,7 @@ copy_object (bfd *ibfd, bfd *obfd, const
66b412
 			     pdump->filename,
66b412
 			     strerror (errno));
66b412
 		  free (contents);
66b412
+		  fclose (f);
66b412
 		  /* There is a potential resource leak here, but it is not important.  */
66b412
 		  /* coverity[leaked_storage: FALSE] */
66b412
 		  return FALSE;