+
+ /* We have to create a note for *each* code section.
+ Linker garbage collection might discard some. */
+ total_size = 0;
+ note = NULL;
+
+ for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
+ if ((bsym = symbol_get_bfdsym (sym)) != NULL
+ && bsym->flags & BSF_SECTION_SYM
+ && bsym->section != NULL
+ /* Skip linkonce sections - we cannot use these section symbols as they may disappear. */
+ && (bsym->section->flags & (SEC_CODE | SEC_LINK_ONCE)) == SEC_CODE
+ /* Not all linkonce sections are flagged... */
+ && strncmp (S_GET_NAME (sym), ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) != 0)
+ {
+ /* Create a version note. */
+ frag_now_fix ();
+ note = frag_more (note_size);
+ memset (note, 0, note_size);
+
+ if (target_big_endian)
+ {
+ note[3] = 8; /* strlen (name) + 1. */
+ note[7] = desc_size; /* Two 8-byte offsets. */
+ note[10] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
+ note[11] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
+ }
+ else
+ {
+ note[0] = 8; /* strlen (name) + 1. */
+ note[4] = desc_size; /* Two 8-byte offsets. */
+ note[8] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
+ note[9] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
+ }
+
+ /* The a1 version number indicates that this note was
+ generated by the assembler and not the gcc annobin plugin. */
+ memcpy (note + 12, "GA$\ 13a1", 8);
+
+ /* Create a relocation to install the start address of the note... */
+ create_note_reloc (sec, sym, total_size, 20, desc_reloc, 0, note);
+
+ /* ...and another one to install the end address. */
+ create_note_reloc (sec, sym, total_size, desc2_offset, desc_reloc,
+ bfd_section_size (bsym->section),
+ note);
+
+ total_size += note_size;
+ /* FIXME: Maybe add a note recording the assembler command line and version ? */
+ }
+
+ /* Install the note(s) into the section. */
+ if (total_size)
+ bfd_set_section_contents (stdoutput, sec, (bfd_byte *) note, 0, total_size);
+ subsegs_finish_section (sec);
+ relax_segment (seg_info (sec)->frchainP->frch_root, sec, 0);
+ size_seg (stdoutput, sec, NULL);