Blame SOURCES/binutils-gas-build-notes.patch

869a11
diff -rup binutils.orig/binutils/readelf.c binutils-2.30/binutils/readelf.c
869a11
--- binutils.orig/binutils/readelf.c	2018-04-26 15:14:17.220464639 +0100
869a11
+++ binutils-2.30/binutils/readelf.c	2018-04-26 15:14:31.927287474 +0100
869a11
@@ -12294,7 +12294,8 @@ is_32bit_abs_reloc (Filedata * filedata,
869a11
     case EM_OR1K:
869a11
       return reloc_type == 1; /* R_OR1K_32.  */
869a11
     case EM_PARISC:
869a11
-      return (reloc_type == 1 /* R_PARISC_DIR32.  */
869a11
+      return (reloc_type == 1 /* R_PARISC_DIR32.  */	      
869a11
+	      || reloc_type == 2 /* R_PARISC_DIR21L.  */
869a11
 	      || reloc_type == 41); /* R_PARISC_SECREL32.  */
869a11
     case EM_PJ:
869a11
     case EM_PJ_OLD:
869a11
Only in binutils-2.30/binutils: readelf.c.orig
869a11
diff -rup binutils.orig/binutils/testsuite/binutils-all/objcopy.exp binutils-2.30/binutils/testsuite/binutils-all/objcopy.exp
869a11
--- binutils.orig/binutils/testsuite/binutils-all/objcopy.exp	2018-04-26 15:14:17.215464699 +0100
869a11
+++ binutils-2.30/binutils/testsuite/binutils-all/objcopy.exp	2018-04-26 15:14:31.927287474 +0100
869a11
@@ -1062,6 +1062,7 @@ if [is_elf_format] {
869a11
 	run_dump_test "note-3-32"
869a11
 	run_dump_test "note-4-32"
869a11
     }
869a11
+    run_dump_test "note-5"
869a11
 }
869a11
 
869a11
 run_dump_test "copy-2"
869a11
Only in binutils-2.30/binutils/testsuite/binutils-all: objcopy.exp.orig
869a11
diff -rup binutils.orig/gas/as.c binutils-2.30/gas/as.c
869a11
--- binutils.orig/gas/as.c	2018-04-26 15:14:17.646459507 +0100
869a11
+++ binutils-2.30/gas/as.c	2018-04-26 15:14:31.927287474 +0100
869a11
@@ -97,6 +97,7 @@ int verbose = 0;
869a11
 
869a11
 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
869a11
 int flag_use_elf_stt_common = DEFAULT_GENERATE_ELF_STT_COMMON;
869a11
+bfd_boolean flag_generate_build_notes = DEFAULT_GENERATE_BUILD_NOTES;
869a11
 #endif
869a11
 
869a11
 /* Keep the output file.  */
869a11
@@ -304,8 +305,19 @@ Options:\n\
869a11
                           generate ELF common symbols with STT_COMMON type\n"));
869a11
   fprintf (stream, _("\
869a11
   --sectname-subst        enable section name substitution sequences\n"));
869a11
+
869a11
+  fprintf (stream, _("\
869a11
+  --generate-missing-build-notes=[no|yes] "));
869a11
+#if DEFAULT_GENERATE_BUILD_NOTES
869a11
+  fprintf (stream, _("(default: yes)\n"));
869a11
+#else
869a11
+  fprintf (stream, _("(default: no)\n"));
869a11
 #endif
869a11
   fprintf (stream, _("\
869a11
+                          generate GNU Build notes if none are present in the input\n"));
869a11
+#endif /* OBJ_ELF */
869a11
+
869a11
+  fprintf (stream, _("\
869a11
   -f                      skip whitespace and comment preprocessing\n"));
869a11
   fprintf (stream, _("\
869a11
   -g --gen-debug          generate debugging information\n"));
869a11
@@ -470,6 +482,7 @@ parse_args (int * pargc, char *** pargv)
869a11
       OPTION_NOEXECSTACK,
869a11
       OPTION_SIZE_CHECK,
869a11
       OPTION_ELF_STT_COMMON,
869a11
+      OPTION_ELF_BUILD_NOTES,
869a11
       OPTION_SECTNAME_SUBST,
869a11
       OPTION_ALTERNATE,
869a11
       OPTION_AL,
869a11
@@ -508,6 +521,7 @@ parse_args (int * pargc, char *** pargv)
869a11
     ,{"size-check", required_argument, NULL, OPTION_SIZE_CHECK}
869a11
     ,{"elf-stt-common", required_argument, NULL, OPTION_ELF_STT_COMMON}
869a11
     ,{"sectname-subst", no_argument, NULL, OPTION_SECTNAME_SUBST}
869a11
+    ,{"generate-missing-build-notes", required_argument, NULL, OPTION_ELF_BUILD_NOTES}
869a11
 #endif
869a11
     ,{"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
869a11
     ,{"gdwarf-2", no_argument, NULL, OPTION_GDWARF2}
869a11
@@ -900,7 +914,19 @@ This program has absolutely no warranty.
869a11
 	case OPTION_SECTNAME_SUBST:
869a11
 	  flag_sectname_subst = 1;
869a11
 	  break;
869a11
-#endif
869a11
+
869a11
+	case OPTION_ELF_BUILD_NOTES:
869a11
+	  if (strcasecmp (optarg, "no") == 0)
869a11
+	    flag_generate_build_notes = FALSE;
869a11
+	  else if (strcasecmp (optarg, "yes") == 0)
869a11
+	    flag_generate_build_notes = TRUE;
869a11
+	  else
869a11
+	    as_fatal (_("Invalid --generate-missing-build-notes option: `%s'"),
869a11
+		      optarg);
869a11
+	  break;
869a11
+
869a11
+#endif /* OBJ_ELF */
869a11
+
869a11
 	case 'Z':
869a11
 	  flag_always_generate_output = 1;
869a11
 	  break;
869a11
diff -rup binutils.orig/gas/as.h binutils-2.30/gas/as.h
869a11
--- binutils.orig/gas/as.h	2018-04-26 15:14:17.654459410 +0100
869a11
+++ binutils-2.30/gas/as.h	2018-04-26 15:14:31.927287474 +0100
869a11
@@ -585,6 +585,10 @@ COMMON int flag_allow_nonconst_size;
869a11
 /* If we should generate ELF common symbols with the STT_COMMON type.  */
869a11
 extern int flag_use_elf_stt_common;
869a11
 
869a11
+/* TRUE iff GNU Build attribute notes should
869a11
+   be generated if none are in the input files.  */
869a11
+extern bfd_boolean flag_generate_build_notes;
869a11
+
869a11
 /* If section name substitution sequences should be honored */
869a11
 COMMON int flag_sectname_subst;
869a11
 #endif
869a11
Only in binutils-2.30/gas: as.h.orig
869a11
diff -rup binutils.orig/gas/config.in binutils-2.30/gas/config.in
869a11
--- binutils.orig/gas/config.in	2018-04-26 15:14:17.645459519 +0100
869a11
+++ binutils-2.30/gas/config.in	2018-04-26 15:14:31.927287474 +0100
869a11
@@ -39,6 +39,10 @@
869a11
 /* Define if you want compressed debug sections by default. */
869a11
 #undef DEFAULT_FLAG_COMPRESS_DEBUG
869a11
 
869a11
+/* Define to 1 if you want to generate GNU Build attribute notes by default,
869a11
+   if none are contained in the input. */
869a11
+#undef DEFAULT_GENERATE_BUILD_NOTES
869a11
+
869a11
 /* Define to 1 if you want to generate ELF common symbols with the STT_COMMON
869a11
    type by default. */
869a11
 #undef DEFAULT_GENERATE_ELF_STT_COMMON
869a11
diff -rup binutils.orig/gas/configure binutils-2.30/gas/configure
869a11
--- binutils.orig/gas/configure	2018-04-26 15:14:17.645459519 +0100
869a11
+++ binutils-2.30/gas/configure	2018-04-26 15:14:31.928287462 +0100
869a11
@@ -771,6 +771,7 @@ enable_checking
869a11
 enable_compressed_debug_sections
869a11
 enable_x86_relax_relocations
869a11
 enable_elf_stt_common
869a11
+enable_generate_build_notes
869a11
 enable_werror
869a11
 enable_build_warnings
869a11
 with_cpu
869a11
@@ -1426,6 +1427,9 @@ Optional Features:
869a11
                           generate x86 relax relocations by default
869a11
   --enable-elf-stt-common generate ELF common symbols with STT_COMMON type by
869a11
                           default
869a11
+  --enable-generate-build-notes
869a11
+                          generate GNU Build notes if none are provided by the
869a11
+                          input
869a11
   --enable-werror         treat compile warnings as errors
869a11
   --enable-build-warnings enable build-time compiler warnings
869a11
   --disable-nls           do not use Native Language Support
869a11
@@ -11011,7 +11015,7 @@ else
869a11
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
869a11
   lt_status=$lt_dlunknown
869a11
   cat > conftest.$ac_ext <<_LT_EOF
869a11
-#line 10990 "configure"
869a11
+#line 10994 "configure"
869a11
 #include "confdefs.h"
869a11
 
869a11
 #if HAVE_DLFCN_H
869a11
@@ -11117,7 +11121,7 @@ else
869a11
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
869a11
   lt_status=$lt_dlunknown
869a11
   cat > conftest.$ac_ext <<_LT_EOF
869a11
-#line 11096 "configure"
869a11
+#line 11100 "configure"
869a11
 #include "confdefs.h"
869a11
 
869a11
 #if HAVE_DLFCN_H
869a11
@@ -11771,6 +11775,20 @@ if test "${enable_elf_stt_common+set}" =
869a11
 esac
869a11
 fi
869a11
 
869a11
+
869a11
+# Decide if the ELF assembler should default to generating
869a11
+# GNU Build notes if none are provided by the input.
869a11
+ac_default_generate_build_notes=0
869a11
+# Provide a configuration option to override the default.
869a11
+# Check whether --enable-generate_build_notes was given.
869a11
+if test "${enable_generate_build_notes+set}" = set; then :
869a11
+  enableval=$enable_generate_build_notes; case "${enableval}" in
869a11
+  yes)  ac_default_generate_build_notes=1 ;;
869a11
+  no)   ac_default_generate_build_notes=0 ;;
869a11
+esac
869a11
+fi
869a11
+
869a11
+
869a11
 using_cgen=no
869a11
 
869a11
 
869a11
@@ -12713,6 +12731,12 @@ cat >>confdefs.h <<_ACEOF
869a11
 _ACEOF
869a11
 
869a11
 
869a11
+
869a11
+cat >>confdefs.h <<_ACEOF
869a11
+#define DEFAULT_GENERATE_BUILD_NOTES $ac_default_generate_build_notes
869a11
+_ACEOF
869a11
+
869a11
+
869a11
 if test x$ac_default_compressed_debug_sections = xyes ; then
869a11
 
869a11
 $as_echo "#define DEFAULT_FLAG_COMPRESS_DEBUG 1" >>confdefs.h
869a11
diff -rup binutils.orig/gas/configure.ac binutils-2.30/gas/configure.ac
869a11
--- binutils.orig/gas/configure.ac	2018-04-26 15:14:17.645459519 +0100
869a11
+++ binutils-2.30/gas/configure.ac	2018-04-26 15:14:31.928287462 +0100
869a11
@@ -100,6 +100,20 @@ AC_ARG_ENABLE(elf_stt_common,
869a11
   yes)  ac_default_elf_stt_common=1 ;;
869a11
 esac])dnl
869a11
 
869a11
+
869a11
+# Decide if the ELF assembler should default to generating
869a11
+# GNU Build notes if none are provided by the input.
869a11
+ac_default_generate_build_notes=0
869a11
+# Provide a configuration option to override the default.
869a11
+AC_ARG_ENABLE(generate_build_notes,
869a11
+	      AS_HELP_STRING([--enable-generate-build-notes],
869a11
+	      [generate GNU Build notes if none are provided by the input]),
869a11
+[case "${enableval}" in
869a11
+  yes)  ac_default_generate_build_notes=1 ;;
869a11
+  no)   ac_default_generate_build_notes=0 ;;
869a11
+esac])dnl
869a11
+
869a11
+
869a11
 using_cgen=no
869a11
 
869a11
 AM_BINUTILS_WARNINGS
869a11
@@ -610,6 +624,11 @@ AC_DEFINE_UNQUOTED(DEFAULT_GENERATE_ELF_
869a11
   [Define to 1 if you want to generate ELF common symbols with the
869a11
    STT_COMMON type by default.])
869a11
 
869a11
+AC_DEFINE_UNQUOTED(DEFAULT_GENERATE_BUILD_NOTES,
869a11
+  $ac_default_generate_build_notes,
869a11
+  [Define to 1 if you want to generate GNU Build attribute notes
869a11
+   by default, if none are contained in the input.])
869a11
+
869a11
 if test x$ac_default_compressed_debug_sections = xyes ; then
869a11
   AC_DEFINE(DEFAULT_FLAG_COMPRESS_DEBUG, 1, [Define if you want compressed debug sections by default.])
869a11
 fi
869a11
Only in binutils-2.30/gas: configure.ac.orig
869a11
Only in binutils-2.30/gas: configure.orig
869a11
diff -rup binutils.orig/gas/doc/as.texinfo binutils-2.30/gas/doc/as.texinfo
869a11
--- binutils.orig/gas/doc/as.texinfo	2018-04-26 15:14:17.665459278 +0100
869a11
+++ binutils-2.30/gas/doc/as.texinfo	2018-04-26 15:14:31.929287450 +0100
869a11
@@ -244,6 +244,7 @@ gcc(1), ld(1), and the Info entries for
869a11
  [@b{-Z}] [@b{@@@var{FILE}}]
869a11
  [@b{--sectname-subst}] [@b{--size-check=[error|warning]}]
869a11
  [@b{--elf-stt-common=[no|yes]}]
869a11
+ [@b{--generate-missing-build-notes=[no|yes]}]
869a11
  [@b{--target-help}] [@var{target-options}]
869a11
  [@b{--}|@var{files} @dots{}]
869a11
 @c
869a11
@@ -754,6 +755,14 @@ Issue an error or warning for invalid EL
869a11
 These options control whether the ELF assembler should generate common
869a11
 symbols with the @code{STT_COMMON} type.  The default can be controlled
869a11
 by a configure option @option{--enable-elf-stt-common}.
869a11
+
869a11
+@item --generate-missing-build-notes=yes
869a11
+@itemx --generate-missing-build-notes=no
869a11
+These options control whether the ELF assembler should generate GNU Build
869a11
+attribute notes if none are present in the input sources.
869a11
+The default can be controlled by the @option{--enable-generate-build-notes}
869a11
+configure option.
869a11
+
869a11
 @end ifset
869a11
 
869a11
 @item --help
869a11
Only in binutils-2.30/gas/doc: as.texinfo.orig
869a11
diff -rup binutils.orig/gas/NEWS binutils-2.30/gas/NEWS
869a11
--- binutils.orig/gas/NEWS	2018-04-26 15:14:17.646459507 +0100
869a11
+++ binutils-2.30/gas/NEWS	2018-04-26 15:15:32.276560482 +0100
869a11
@@ -1,5 +1,11 @@
869a11
 -*- text -*-
869a11
 
869a11
+* Add --generate-missing-build-notes=[yes|no] option to create (or not) GNU
869a11
+  Build Attribute notes if none are present in the input sources.  Add a
869a11
+  --enable-generate-build-notes=[yes|no] configure time option to set the
869a11
+  default behaviour.  Set the default if the configure option is not used
869a11
+  to "no".
869a11
+
869a11
 Changes in 2.30:
869a11
 
869a11
 * Add support for loaction views in DWARF debug line information.
869a11
Only in binutils-2.30/gas: NEWS.orig
869a11
Only in binutils-2.30/gas: NEWS.rej
869a11
diff -rup binutils.orig/gas/symbols.c binutils-2.30/gas/symbols.c
869a11
--- binutils.orig/gas/symbols.c	2018-04-26 15:14:17.667459254 +0100
869a11
+++ binutils-2.30/gas/symbols.c	2018-04-26 15:14:31.929287450 +0100
869a11
@@ -108,6 +108,7 @@ save_symbol_name (const char *name)
869a11
   size_t name_length;
869a11
   char *ret;
869a11
 
869a11
+  gas_assert (name != NULL);
869a11
   name_length = strlen (name) + 1;	/* +1 for \0.  */
869a11
   obstack_grow (&notes, name, name_length);
869a11
   ret = (char *) obstack_finish (&notes);
869a11
diff -rup binutils.orig/gas/write.c binutils-2.30/gas/write.c
869a11
--- binutils.orig/gas/write.c	2018-04-26 15:14:18.296451677 +0100
869a11
+++ binutils-2.30/gas/write.c	2018-04-26 15:14:31.929287450 +0100
869a11
@@ -1822,25 +1822,200 @@ create_obj_attrs_section (void)
869a11
   const char *name;
869a11
 
869a11
   size = bfd_elf_obj_attr_size (stdoutput);
869a11
-  if (size)
869a11
+  if (size == 0)
869a11
+    return;
869a11
+
869a11
+  name = get_elf_backend_data (stdoutput)->obj_attrs_section;
869a11
+  if (!name)
869a11
+    name = ".gnu.attributes";
869a11
+  s = subseg_new (name, 0);
869a11
+  elf_section_type (s)
869a11
+    = get_elf_backend_data (stdoutput)->obj_attrs_section_type;
869a11
+  bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
869a11
+  frag_now_fix ();
869a11
+  p = frag_more (size);
869a11
+  bfd_elf_set_obj_attr_contents (stdoutput, (bfd_byte *)p, size);
869a11
+
869a11
+  subsegs_finish_section (s);
869a11
+  relax_segment (seg_info (s)->frchainP->frch_root, s, 0);
869a11
+  size_seg (stdoutput, s, NULL);
869a11
+}
869a11
+
869a11
+#include "struc-symbol.h"
869a11
+
869a11
+/* Create a relocation against an entry in a GNU Build attribute section.  */
869a11
+
869a11
+static void
869a11
+create_note_reloc (segT           sec,
869a11
+		   symbolS *      sym,
869a11
+		   bfd_size_type  offset,
869a11
+		   int            reloc_type,
869a11
+		   bfd_vma        addend,
869a11
+		   char *         note)
869a11
+{
869a11
+  struct reloc_list * reloc;
869a11
+
869a11
+  reloc = XNEW (struct reloc_list);
869a11
+
869a11
+  /* We create a .b type reloc as resolve_reloc_expr_symbols() has already been called.  */
869a11
+  reloc->u.b.sec   = sec;
869a11
+  reloc->u.b.s     = sym->bsym;
869a11
+  reloc->u.b.r.sym_ptr_ptr = & reloc->u.b.s;
869a11
+  reloc->u.b.r.address     = offset;
869a11
+  reloc->u.b.r.addend      = addend;
869a11
+  reloc->u.b.r.howto       = bfd_reloc_type_lookup (stdoutput, reloc_type);
869a11
+
869a11
+  if (reloc->u.b.r.howto == NULL)
869a11
     {
869a11
-      name = get_elf_backend_data (stdoutput)->obj_attrs_section;
869a11
-      if (!name)
869a11
-	name = ".gnu.attributes";
869a11
-      s = subseg_new (name, 0);
869a11
-      elf_section_type (s)
869a11
-	= get_elf_backend_data (stdoutput)->obj_attrs_section_type;
869a11
-      bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
869a11
-      frag_now_fix ();
869a11
-      p = frag_more (size);
869a11
-      bfd_elf_set_obj_attr_contents (stdoutput, (bfd_byte *)p, size);
869a11
-
869a11
-      subsegs_finish_section (s);
869a11
-      relax_segment (seg_info (s)->frchainP->frch_root, s, 0);
869a11
-      size_seg (stdoutput, s, NULL);
869a11
+      as_bad (_("unable to create reloc for build note"));
869a11
+      return;
869a11
+    }
869a11
+
869a11
+  reloc->file = N_("<gnu build note>");
869a11
+  reloc->line = 0;
869a11
+
869a11
+  reloc->next = reloc_list;
869a11
+  reloc_list = reloc;
869a11
+
869a11
+  /* For REL relocs, store the addend in the section.  */
869a11
+  if (! sec->use_rela_p
869a11
+      /* The SH target is a special case that uses RELA relocs
869a11
+	 but still stores the addend in the word being relocated.  */
869a11
+      || strstr (bfd_get_target (stdoutput), "-sh") != NULL)
869a11
+    {
869a11
+      if (target_big_endian)
869a11
+	{
869a11
+	  if (bfd_arch_bits_per_address (stdoutput) <= 32)
869a11
+	    note[offset + 3] = addend;
869a11
+	  else
869a11
+	    note[offset + 7] = addend;
869a11
+	}
869a11
+      else
869a11
+	note[offset] = addend;
869a11
     }
869a11
 }
869a11
-#endif
869a11
+
869a11
+static void
869a11
+maybe_generate_build_notes (void)
869a11
+{
869a11
+  segT      sec;
869a11
+  char *    note;
869a11
+  offsetT   note_size;
869a11
+  offsetT   desc_size;
869a11
+  offsetT   desc2_offset;
869a11
+  int       desc_reloc;
869a11
+  symbolS * sym;
869a11
+
869a11
+  if (! flag_generate_build_notes
869a11
+      || bfd_get_section_by_name (stdoutput,
869a11
+				  GNU_BUILD_ATTRS_SECTION_NAME) != NULL)
869a11
+    return;
869a11
+
869a11
+  /* Create a GNU Build Attribute section.  */
869a11
+  sec = subseg_new (GNU_BUILD_ATTRS_SECTION_NAME, FALSE);
869a11
+  elf_section_type (sec) = SHT_NOTE;
869a11
+  bfd_set_section_flags (stdoutput, sec,
869a11
+			 SEC_READONLY | SEC_HAS_CONTENTS | SEC_DATA);
869a11
+  bfd_set_section_alignment (stdoutput, sec, 2);
869a11
+
869a11
+  /* Create a version note.  */
869a11
+  if (bfd_arch_bits_per_address (stdoutput) <= 32)
869a11
+    {
869a11
+      note_size = 28;
869a11
+      desc_size = 8; /* Two 4-byte offsets.  */
869a11
+      desc2_offset = 24;
869a11
+
869a11
+      /* FIXME: The BFD backend for the CRX target does not support the
869a11
+	 BFD_RELOC_32, even though it really should.  Likewise for the
869a11
+	 CR16 target.  So we have special case code here...  */
869a11
+      if (strstr (bfd_get_target (stdoutput), "-crx") != NULL)
869a11
+	desc_reloc = BFD_RELOC_CRX_NUM32;
869a11
+      else if (strstr (bfd_get_target (stdoutput), "-cr16") != NULL)
869a11
+	desc_reloc = BFD_RELOC_CR16_NUM32;
869a11
+      else
869a11
+	desc_reloc = BFD_RELOC_32;
869a11
+    }
869a11
+  else
869a11
+    {
869a11
+      note_size = 36;
869a11
+      desc_size = 16; /* Two  8-byte offsets.  */
869a11
+      desc2_offset = 28;
869a11
+      /* FIXME: The BFD backend for the IA64 target does not support the
869a11
+	 BFD_RELOC_64, even though it really should.  The HPPA backend
869a11
+	 has a similar issue, although it does not support BFD_RELOCs at
869a11
+	 all!  So we have special case code to handle these targets.  */
869a11
+      if (strstr (bfd_get_target (stdoutput), "-ia64") != NULL)
869a11
+	desc_reloc = target_big_endian ? BFD_RELOC_IA64_DIR32MSB : BFD_RELOC_IA64_DIR32LSB;
869a11
+      else if (strstr (bfd_get_target (stdoutput), "-hppa") != NULL)
869a11
+	desc_reloc = 80; /* R_PARISC_DIR64.  */
869a11
+      else
869a11
+	desc_reloc = BFD_RELOC_64;
869a11
+    }
869a11
+  
869a11
+  frag_now_fix ();
869a11
+  note = frag_more (note_size);
869a11
+  memset (note, 0, note_size);
869a11
+
869a11
+  if (target_big_endian)
869a11
+    {
869a11
+      note[3] = 8; /* strlen (name) + 1.  */
869a11
+      note[7] = desc_size; /* Two 8-byte offsets.  */
869a11
+      note[10] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
869a11
+      note[11] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
869a11
+    }
869a11
+  else
869a11
+    {
869a11
+      note[0] = 8; /* strlen (name) + 1.  */
869a11
+      note[4] = desc_size; /* Two 8-byte offsets.  */
869a11
+      note[8] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
869a11
+      note[9] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
869a11
+    }
869a11
+
869a11
+  /* The a1 version number indicates that this note was
869a11
+     generated by the assembler and not the gcc annobin plugin.  */
869a11
+  memcpy (note + 12, "GA$?3a1", 8);
869a11
+
869a11
+  /* Find the first code section symbol.  */
869a11
+  for (sym = symbol_rootP; sym != NULL; sym = sym->sy_next)
869a11
+    if (sym->bsym != NULL
869a11
+	&& sym->bsym->flags & BSF_SECTION_SYM
869a11
+	&& sym->bsym->section != NULL
869a11
+	&& sym->bsym->section->flags & SEC_CODE)
869a11
+      {
869a11
+	/* Found one - now create a relocation against this symbol.  */
869a11
+	create_note_reloc (sec, sym, 20, desc_reloc, 0, note);
869a11
+	break;
869a11
+      }
869a11
+
869a11
+  /* Find the last code section symbol.  */
869a11
+  if (sym)
869a11
+    {
869a11
+      for (sym = symbol_lastP; sym != NULL; sym = sym->sy_previous)
869a11
+	if (sym->bsym != NULL
869a11
+	    && sym->bsym->flags & BSF_SECTION_SYM
869a11
+	    && sym->bsym->section != NULL
869a11
+	    && sym->bsym->section->flags & SEC_CODE)
869a11
+	  {
869a11
+	    /* Create a relocation against the end of this symbol.  */
869a11
+	    create_note_reloc (sec, sym, desc2_offset, desc_reloc,
869a11
+			       bfd_get_section_size (sym->bsym->section),
869a11
+			       note);
869a11
+	    break;
869a11
+	  }
869a11
+    }
869a11
+  /* else - if we were unable to find any code section symbols then
869a11
+     probably there is no code in the output.  So leaving the start
869a11
+     and end values as zero in the note is OK.  */
869a11
+
869a11
+  /* FIXME: Maybe add a note recording the assembler command line and version ?  */
869a11
+
869a11
+  /* Install the note(s) into the section.  */
869a11
+  bfd_set_section_contents (stdoutput, sec, (bfd_byte *) note, 0, note_size);
869a11
+  subsegs_finish_section (sec);
869a11
+  relax_segment (seg_info (sec)->frchainP->frch_root, sec, 0);
869a11
+  size_seg (stdoutput, sec, NULL);
869a11
+}
869a11
+#endif /* OBJ_ELF */
869a11
 
869a11
 /* Write the object file.  */
869a11
 
869a11
@@ -2052,6 +2227,11 @@ write_object_file (void)
869a11
   resolve_local_symbol_values ();
869a11
   resolve_reloc_expr_symbols ();
869a11
 
869a11
+#ifdef OBJ_ELF
869a11
+  if (IS_ELF)
869a11
+    maybe_generate_build_notes ();
869a11
+#endif
869a11
+  
869a11
   PROGRESS (1);
869a11
 
869a11
 #ifdef tc_frob_file_before_adjust
869a11
Only in binutils-2.30/gas: write.c.orig
869a11
Only in binutils-2.30: testsuite
869a11
--- /dev/null	2018-04-26 08:07:19.307057583 +0100
869a11
+++ binutils-2.30/binutils/testsuite/binutils-all/note-5.d	2018-04-26 15:17:06.318427614 +0100
869a11
@@ -0,0 +1,11 @@
869a11
+#PROG: objcopy
869a11
+#as: --generate-missing-build-notes=yes
869a11
+#readelf: --notes --wide
869a11
+#name: assembler generated build notes
869a11
+#source: note-5.s
869a11
+
869a11
+#...
869a11
+Displaying notes found in: .gnu.build.attributes
869a11
+[ 	]+Owner[ 	]+Data size[ 	]+Description
869a11
+[ 	]+GA\$<version>3a1[ 	]+0x000000(08|10)[ 	]+OPEN[ 	]+Applies to region from 0 to 0x.. \(note_5.s\)
869a11
+#...
869a11
--- /dev/null	2018-04-26 08:07:19.307057583 +0100
869a11
+++ binutils-2.30/binutils/testsuite/binutils-all/note-5.s	2018-04-26 15:17:06.318427614 +0100
869a11
@@ -0,0 +1,14 @@
869a11
+	.text
869a11
+	.global note_5.s
869a11
+note_5.s:
869a11
+	.dc.l	2
869a11
+	.dc.l	4
869a11
+	.dc.l	6
869a11
+	.dc.l	8
869a11
+	.dc.l	8
869a11
+	.dc.l	8
869a11
+	.dc.l	8
869a11
+	.dc.l	8
869a11
+	.dc.l	8
869a11
+	.dc.l	8
869a11
+	
869a11
\ No newline at end of file