+/* Get GNU property section size. */
+
+static bfd_size_type
+elf_get_gnu_property_section_size (elf_property_list *list,
+ unsigned int align_size)
+{
+ bfd_size_type size;
+ unsigned int descsz;
+
+ /* Compute the output section size. */
+ descsz = offsetof (Elf_External_Note, name[sizeof "GNU"]);
+ descsz = (descsz + 3) & -(unsigned int) 4;
+ size = descsz;
+ for (; list != NULL; list = list->next)
+ {
+ /* There are 4 byte type + 4 byte datasz for each property. */
+ unsigned int datasz;
+ if (list->property.pr_type == GNU_PROPERTY_STACK_SIZE)
+ datasz = align_size;
+ else
+ datasz = list->property.pr_datasz;
+ size += 4 + 4 + datasz;
+ /* Align each property. */
+ size = (size + (align_size - 1)) & ~(align_size - 1);
+ }
+
+ return size;
+}
+
+/* Write GNU properties. */
+
+static void
+elf_write_gnu_properties (bfd *abfd, bfd_byte *contents,
+ elf_property_list *list, unsigned int size,
+ unsigned int align_size)
+{
+ unsigned int descsz;
+ unsigned int datasz;
+ Elf_External_Note *e_note;
+
+ e_note = (Elf_External_Note *) contents;
+ descsz = offsetof (Elf_External_Note, name[sizeof "GNU"]);
+ descsz = (descsz + 3) & -(unsigned int) 4;
+ bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
+ bfd_h_put_32 (abfd, size - descsz, &e_note->descsz);
+ bfd_h_put_32 (abfd, NT_GNU_PROPERTY_TYPE_0, &e_note->type);
+ memcpy (e_note->name, "GNU", sizeof "GNU");
+
+ size = descsz;
+ for (; list != NULL; list = list->next)
+ {
+ /* There are 4 byte type + 4 byte datasz for each property. */
+ if (list->property.pr_type == GNU_PROPERTY_STACK_SIZE)
+ datasz = align_size;
+ else
+ datasz = list->property.pr_datasz;
+ bfd_h_put_32 (abfd, list->property.pr_type, contents + size);
+ bfd_h_put_32 (abfd, datasz, contents + size + 4);
+ size += 4 + 4;
+
+ /* Write out property value. */
+ switch (list->property.pr_kind)
+ {
+ case property_number:
+ switch (datasz)
+ {
+ default:
+ /* Never should happen. */
+ abort ();
+
+ case 0:
+ break;
+
+ case 4:
+ bfd_h_put_32 (abfd, list->property.u.number,
+ contents + size);
+ break;
+
+ case 8:
+ bfd_h_put_64 (abfd, list->property.u.number,
+ contents + size);
+ break;
+ }
+ break;
+
+ default:
+ /* Never should happen. */
+ abort ();
+ }
+ size += datasz;
+
+ /* Align each property. */
+ size = (size + (align_size - 1)) & ~ (align_size - 1);
+ }
+}
+