[PATCH 2/3] ELF: Group and sort output note sections by section alignments

Alan Modra amodra@gmail.com
Fri Oct 5 10:33:00 GMT 2018

On Mon, Oct 01, 2018 at 11:54:35AM -0700, H.J. Lu wrote:
> To support putting all adjacent SHT_NOTE sections with the same section
> alignment into a single PT_NOTE segment, lang_insert_orphan must group
> and sort output note sections by section alignments in both output
> section list as well as output section statement list.
> 	PR ld/23658
> 	* ldlang.c (lang_insert_orphan): Group and sort output note
> 	sections by section alignments.

This one also breaks the spu-elf testsuite, due to changing the
placement of the .toe section.  After applying the following patch to
fix the bug that caused the PT_NOTE segment to be omitted, I see two
sections being handled as orphans.  First, .note.spu_name is correctly
placed after .bss, then .toe is placed after the note section
apparently due to this code:
	      /* Don't place non-note sections in the middle of note
		 sections.  */
	      after_sec_note = TRUE;
	      after_sec = as;
.toe ought to be placed after .bss as it was before.

	* elf32-spu.c (spu_elf_create_sections): Make .note.spu_name

diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index c3bfbbdd03..bb3264f236 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -580,11 +580,16 @@ spu_elf_create_sections (struct bfd_link_info *info)
       flagword flags;
       ibfd = info->input_bfds;
+      /* This should really be SEC_LINKER_CREATED, but then we'd need
+	 to write out the section ourselves.  */
       s = bfd_make_section_anyway_with_flags (ibfd, SPU_PTNOTE_SPUNAME, flags);
       if (s == NULL
 	  || !bfd_set_section_alignment (ibfd, s, 4))
 	return FALSE;
+      /* Because we didn't set SEC_LINKER_CREATED we need to set the
+	 proper section type.  */
+      elf_section_type (s) = SHT_NOTE;
       name_len = strlen (bfd_get_filename (info->output_bfd)) + 1;
       size = 12 + ((sizeof (SPU_PLUGIN_NAME) + 3) & -4);

Alan Modra
Australia Development Lab, IBM

More information about the Binutils mailing list