]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: fold .note.GNU-stack during relocatable linking
authorJan Beulich <jbeulich@suse.com>
Fri, 6 Feb 2026 07:52:02 +0000 (08:52 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 6 Feb 2026 07:52:02 +0000 (08:52 +0100)
PR ld/33851

While in all binutils components we've switched the section to be of
SHT_NOTE type, assembly sources as well as other tools may still generate
SHT_PROGBITS instances. When doing relocatable links, input sections with
differing types would cause multiple output sections to be created, which
some tools choke upon. Fold incoming sections into a single one, the type
of which will be the type of the first section encountered.

ld/scripttempl/misc-sections.sc
ld/testsuite/ld-elf/note3.s [new file with mode: 0644]
ld/testsuite/ld-elf/note3a.d [new file with mode: 0644]
ld/testsuite/ld-elf/note3b.d [new file with mode: 0644]
ld/testsuite/ld-elf/note3c.d [new file with mode: 0644]
ld/testsuite/ld-elf/note3d.d [new file with mode: 0644]

index 794fe70e5cb05b9bc15a930095a0b92f9c0b60df..ddcdd736fb680f41ce663822588d07a34c0de3dc 100644 (file)
@@ -31,3 +31,7 @@ cat <<EOF
   .gnu.build.attributes : { *(.gnu.build.attributes${RELOCATING+ .gnu.build.attributes.*}) }
 
 EOF
+
+test -z "${CONSTRUCTING}" && cat <<EOF
+  .note.GNU-stack : { *(.note.GNU-stack) }
+EOF
diff --git a/ld/testsuite/ld-elf/note3.s b/ld/testsuite/ld-elf/note3.s
new file mode 100644 (file)
index 0000000..6e63bb9
--- /dev/null
@@ -0,0 +1 @@
+       .section .note.GNU-stack, "", %progbits
diff --git a/ld/testsuite/ld-elf/note3a.d b/ld/testsuite/ld-elf/note3a.d
new file mode 100644 (file)
index 0000000..083665c
--- /dev/null
@@ -0,0 +1,10 @@
+#name: .note.GNU-stack ld -r SHT_NOTE + SHT_PROGBITS (positive)
+#source: empty.s --noexecstack
+#source: note3.s
+#as: --generate-missing-build-notes=no
+#ld: -r
+#readelf: -SW
+
+#...
+ *\[[ 0-9]+\] \.note\.GNU-stack +NOTE .*
+#pass
diff --git a/ld/testsuite/ld-elf/note3b.d b/ld/testsuite/ld-elf/note3b.d
new file mode 100644 (file)
index 0000000..5ebfba1
--- /dev/null
@@ -0,0 +1,14 @@
+#name: .note.GNU-stack ld -r SHT_NOTE + SHT_PROGBITS (negative)
+#source: empty.s --noexecstack
+#source: note3.s
+#as: --generate-missing-build-notes=no
+#ld: -r
+#readelf: -SW
+#failif
+# cr16 and crx force entirely empty scripts for -r, while hppa-elf re-uses
+# a significantly shrunk down script also for -r.
+#xfail: cr16-*-elf* crx-*-elf* hppa-*-*elf* hppa*-*-lites*
+
+#...
+ *\[[ 0-9]+\] \.note\.GNU-stack +PROGBITS .*
+#pass
diff --git a/ld/testsuite/ld-elf/note3c.d b/ld/testsuite/ld-elf/note3c.d
new file mode 100644 (file)
index 0000000..2447617
--- /dev/null
@@ -0,0 +1,10 @@
+#name: .note.GNU-stack ld -r SHT_PROGBITS + SHT_NOTE (positive)
+#source: note3.s
+#source: empty.s --noexecstack
+#as: --generate-missing-build-notes=no
+#ld: -r
+#readelf: -SW
+
+#...
+ *\[[ 0-9]+\] \.note\.GNU-stack +PROGBITS .*
+#pass
diff --git a/ld/testsuite/ld-elf/note3d.d b/ld/testsuite/ld-elf/note3d.d
new file mode 100644 (file)
index 0000000..e374403
--- /dev/null
@@ -0,0 +1,14 @@
+#name: .note.GNU-stack ld -r SHT_PROGBITS + SHT_NOTE (negative)
+#source: note3.s
+#source: empty.s --noexecstack
+#as: --generate-missing-build-notes=no
+#ld: -r
+#readelf: -SW
+#failif
+# cr16 and crx force entirely empty scripts for -r, while hppa-elf re-uses
+# a significantly shrunk down script also for -r.
+#xfail: cr16-*-elf* crx-*-elf* hppa-*-*elf* hppa*-*-lites*
+
+#...
+ *\[[ 0-9]+\] \.note\.GNU-stack +NOTE .*
+#pass