[PATCH 2/2] ld: fold .note.GNU-stack during relocatable linking

Jan Beulich jbeulich@suse.com
Thu Jan 29 07:18:35 GMT 2026


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.
---
cr16 and crx have empty *.xr (explicitly forced so), while hppa-elf uses
extremely shrunk down scripts. XFAIL the negative tests for all of those,
for the time being. I wonder if all of them wouldn't better use elf.sc
for -r and -Ur script generation.

--- 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
--- /dev/null
+++ b/ld/testsuite/ld-elf/note3.s
@@ -0,0 +1 @@
+	.section .note.GNU-stack, "", %progbits
--- /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
--- /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*
+
+#...
+ *\[[ 0-9]+\] \.note\.GNU-stack +PROGBITS .*
+#pass
--- /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
--- /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*
+
+#...
+ *\[[ 0-9]+\] \.note\.GNU-stack +NOTE .*
+#pass



More information about the Binutils mailing list