]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
spu: .note.spu_name
authorAlan Modra <amodra@gmail.com>
Tue, 2 Jun 2026 10:36:15 +0000 (20:06 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 3 Jun 2026 12:04:16 +0000 (21:34 +0930)
This fixes a bug with the .note.spu_name section flags, which were
made SEC_LOAD without SEC_ALLOC.  That combination doesn't really make
sense and led to odd layout behaviour.  In addition .note.spu_name
now uses the normal note alignment, with some tweaks to keep its file
offset 16 byte aligned.  This tends to work better in the testsuite
when the standard scripts are not used and the note is merged with
other notes.

bfd/
* elf32-spu.c (spu_elf_create_sections): Remove SEC_LOAD from
.note.spu_name, and align to 4 bytes.
(spu_elf_fake_sections): Tweak .note.spu_name output section
alignment for layout.
(spu_elf_final_write_processing): New function.
(elf_backend_final_write_processing): Define.
binutils/
* testsuite/binutils-all/objcopy.exp (pr25662): Don't xfail spu.
ld/
* testsuite/ld-elf/orphan-region.d: Don't xfail spu.
* testsuite/ld-elf/pr23658-1e.d: Likewise.
* testsuite/ld-scripts/provide-8.d: Likewise.
* testsuite/ld-spu/ovl.d: Remove commented out old matches.
Adjust expected overlay file offset.
* testsuite/ld-spu/ovl2.d: Likewise.

bfd/elf32-spu.c
binutils/testsuite/binutils-all/objcopy.exp
ld/testsuite/ld-elf/orphan-region.d
ld/testsuite/ld-elf/pr23658-1e.d
ld/testsuite/ld-scripts/provide-8.d
ld/testsuite/ld-spu/ovl.d
ld/testsuite/ld-spu/ovl2.d

index 5f547b65443c91caa9a6680b38f6e3d60eeb04a5..9a9d3a0401cbe8e2444967e9463e27c2920d5ece 100644 (file)
@@ -583,10 +583,10 @@ spu_elf_create_sections (struct bfd_link_info *info)
       ibfd = info->input_bfds;
       /* This should really be SEC_LINKER_CREATED, but then we'd need
         to write out the section ourselves.  */
-      flags = SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
+      flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
       s = bfd_make_section_anyway_with_flags (ibfd, SPU_PTNOTE_SPUNAME, flags);
       if (s == NULL
-         || !bfd_set_section_alignment (s, 4))
+         || !bfd_set_section_alignment (s, 2))
        return false;
       /* Because we didn't set SEC_LINKER_CREATED we need to set the
         proper section type.  */
@@ -5342,10 +5342,32 @@ spu_elf_fake_sections (bfd *obfd ATTRIBUTE_UNUSED,
                       asection *sec)
 {
   if (strcmp (sec->name, SPU_PTNOTE_SPUNAME) == 0)
-    hdr->sh_type = SHT_NOTE;
+    {
+      hdr->sh_type = SHT_NOTE;
+      hdr->sh_addralign = 16;
+    }
   return true;
 }
 
+/* .note.spu_name is read by the PPU from the object, and possibly
+   needs the file offset to be aligned to 16 bytes.  We used to simply
+   call bfd_set_section_alignment to set the alignment to 16, but if
+   left like that it triggers a readelf warning.  Now for layout we
+   tweak the alignment to 16 in spu_elf_fake_sections, and restore it
+   to 4 here.  */
+
+static bool
+spu_elf_final_write_processing (bfd *abfd)
+{
+  asection *sec = bfd_get_section_by_name (abfd, SPU_PTNOTE_SPUNAME);
+  if (sec != NULL)
+    {
+      struct bfd_elf_section_data *esd = elf_section_data (sec);
+      esd->this_hdr.sh_addralign = 4;
+    }
+  return _bfd_elf_final_write_processing (abfd);
+}
+
 /* Tweak phdrs before writing them out.  */
 
 static bool
@@ -5539,6 +5561,7 @@ spu_elf_size_sections (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
 #define elf_backend_modify_headers             spu_elf_modify_headers
 #define elf_backend_init_file_header           spu_elf_init_file_header
 #define elf_backend_fake_sections              spu_elf_fake_sections
+#define elf_backend_final_write_processing     spu_elf_final_write_processing
 #define elf_backend_special_sections           spu_elf_special_sections
 #define bfd_elf32_bfd_final_link               spu_elf_final_link
 
index c11b911df677a11b6883b7ccaf4cf3e6566315a6..25e2a4409678560f227ad9688a93c95e826db1fe 100644 (file)
@@ -1556,7 +1556,6 @@ run_dump_test "pr23633"
 run_dump_test "set-section-alignment"
 
 setup_xfail "hppa*-*-*"
-setup_xfail "spu-*-*"
 clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"
 clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-*elf*"
 if { [istarget pdp11-*-*] } {
index 13fb31fff9f5fd218a33c3ab0fa9fec22770d0cb..7be708ddcf62ddcccabf6e7cec96a3c37a4ed0a4 100644 (file)
@@ -1,9 +1,9 @@
 #source: orphan-region.s
 #ld: -T orphan-region.ld -N -z stack-size=0 --no-warn-rwx-segments
 #readelf: -S -l --wide
-#xfail: [uses_genelf] hppa*64*-*-hpux* spu-*-*
+#xfail: [uses_genelf] hppa*64*-*-hpux*
 # if not using elf.em, you don't get fancy orphan handling
-# spu twiddles LOAD range, hppa64 adds PHDR
+# hppa64 adds PHDR
 
 #...
   \[[ 0-9]+\] \.text[ \t]+PROGBITS[ \t]+0*40000000[ \t]+.*
index dbb05e6293e03a33981419d793bf3a7a972bb99a..c331aa7c902b63c059900f7435b34a93ca00fdac 100644 (file)
@@ -14,7 +14,7 @@
 #xfail: cr16-* crx-* visium-*
 # The following targets place .note.gnu.build-id in unusual places.
 #xfail: *-*-hpux*
-#xfail: arc*-* avr-* m68hc1*-* microblaze*-* nds32*-* spu-*-* xstormy16-*-*
+#xfail: arc*-* avr-* m68hc1*-* microblaze*-* nds32*-* xstormy16-*-*
 #noxfail: microblaze*-linux*
 
 #...
index 250b0441479762b541e0749fdb90a3fbabbdc40a..a6136ad52d786ba171329b4c5ff89b645250f76b 100644 (file)
@@ -1,7 +1,7 @@
 #source: provide-5.s
 #ld: -T provide-8.t
 #nm: -B
-#xfail: mmix-*-* spu-*-*
+#xfail: mmix-*-*
 # Placing a symbol outside of the image isn't well-defined in PE.
 #notarget: *-*-pe *-*-mingw* *-*-cygwin
 
index a0372a0e2fd4026fb22de754f0f717868df51573..052a45fb0746ed5863697b8565809714bf4acf24 100644 (file)
@@ -70,30 +70,6 @@ Disassembly of section \.text:
 .*     ila     \$79,1076       # 434
 .*     bra?    .* <__ovly_load>.*
 
-#00000330 <00000000\.ovl_call\.f1_a1>:
-#.*    bra?sl  \$75,.* <__ovly_load>.*
-#.*00 04 04 00.*
-#
-#00000338 <00000000\.ovl_call\.f2_a1>:
-#.*    bra?sl  \$75,.* <__ovly_load>.*
-#.*00 04 04 04.*
-#
-#00000340 <00000000\.ovl_call\.f1_a2>:
-#.*    bra?sl  \$75,.* <__ovly_load>.*
-#.*00 08 04 00.*
-#
-#00000348 <00000000\.ovl_call\.f2_a2>:
-#.*    bra?sl  \$75,.* <__ovly_load>.*
-#.*00 08 04 24.*
-#
-#00000350 <00000000\.ovl_call\.f4_a1>:
-#.*    bra?sl  \$75,.* <__ovly_load>.*
-#.*00 04 04 10.*
-#
-#00000358 <00000000.ovl_call.14:8>:
-#.*    bra?sl  \$75,.* <__ovly_load>.*
-#.*00 08 04 34.*
-
 Disassembly of section \.ov_a1:
 
 00000400 <f1_a1>:
@@ -150,13 +126,11 @@ Disassembly of section .data:
 00000450 <_ovly_table>:
  450:  00 00 04 00 .*
  454:  00 00 00 20 .*
-# 458: 00 00 03 40 .*
- 458:  00 00 01 00 .*
+ 458:  00 00 00 e0 .*
  45c:  00 00 00 01 .*
  460:  00 00 04 00 .*
  464:  00 00 00 40 .*
-# 468: 00 00 03 60 .*
- 468:  00 00 01 20 .*
+ 468:  00 00 01 00 .*
  46c:  00 00 00 01 .*
 
 00000470 <_ovly_buf_table>:
index b8570c069d16ee0f21d7de582a40d4da908fd578..a0921828907c9507055143a2582b834582b74ad0 100644 (file)
@@ -103,13 +103,11 @@ Disassembly of section \.data:
 00000430 <_ovly_table>:
 .*00 00 04 00 .*
 .*00 00 00 20 .*
-#.*00 00 03 10 .*
-.*00 00 01 00 .*
+.*00 00 00 e0 .*
 .*00 00 00 01 .*
 .*00 00 04 00 .*
 .*00 00 00 20 .*
-#.*00 00 03 20 .*
-.*00 00 01 20 .*
+.*00 00 01 00 .*
 .*00 00 00 01 .*
 
 00000450 <_ovly_buf_table>: