[binutils-gdb] ld: fold .note.GNU-stack during relocatable linking
Jan Beulich
jbeulich@sourceware.org
Fri Feb 6 07:55:32 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=126535bae49af3beed2ffd39d490d4d82a8c6ac0
commit 126535bae49af3beed2ffd39d490d4d82a8c6ac0
Author: Jan Beulich <jbeulich@suse.com>
Date: Fri Feb 6 08:52:02 2026 +0100
ld: fold .note.GNU-stack during relocatable linking
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.
Diff:
---
ld/scripttempl/misc-sections.sc | 4 ++++
ld/testsuite/ld-elf/note3.s | 1 +
ld/testsuite/ld-elf/note3a.d | 10 ++++++++++
ld/testsuite/ld-elf/note3b.d | 14 ++++++++++++++
ld/testsuite/ld-elf/note3c.d | 10 ++++++++++
ld/testsuite/ld-elf/note3d.d | 14 ++++++++++++++
6 files changed, 53 insertions(+)
diff --git a/ld/scripttempl/misc-sections.sc b/ld/scripttempl/misc-sections.sc
index 794fe70e5cb..ddcdd736fb6 100644
--- a/ld/scripttempl/misc-sections.sc
+++ b/ld/scripttempl/misc-sections.sc
@@ -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
index 00000000000..6e63bb9232c
--- /dev/null
+++ b/ld/testsuite/ld-elf/note3.s
@@ -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
index 00000000000..083665c277b
--- /dev/null
+++ b/ld/testsuite/ld-elf/note3a.d
@@ -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
index 00000000000..5ebfba15377
--- /dev/null
+++ b/ld/testsuite/ld-elf/note3b.d
@@ -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
index 00000000000..24476170aa9
--- /dev/null
+++ b/ld/testsuite/ld-elf/note3c.d
@@ -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
index 00000000000..e374403712b
--- /dev/null
+++ b/ld/testsuite/ld-elf/note3d.d
@@ -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
More information about the Binutils-cvs
mailing list