[V2 01/36] [SFrame-V3] readelf: testsuite: sframe: add new SFrame V2 test
Indu Bhagat
indu.bhagat@oracle.com
Wed Jan 7 08:41:52 GMT 2026
In subsequent commits, we will add support for SFrame V3. In the next
GNU Binutils release, GNU as and ld will only generate SFrame V3; SFrame
V2 will not be supported for generation nor linking.
For readelf/objdump, however, continue to support textual dump of SFrame
V2 sections. Add a binary file (with no debug data) with SFrame V2
section to keep the dumping tested.
Add ET_REL And ET_EXEC binary file based tests for x86_64 and s390x.
Check that both readelf and objdump works on the SFrame V2 sections.
binutils/testsuite/
* binutils-all/s390/README-sframe-tests: New test.
* binutils-all/s390/sframe.exp: New test.
* binutils-all/s390/test-v2-ET_EXEC.sframe.bz2: New test.
* binutils-all/s390/test-v2-ET_EXEC.sframe.dump: New test.
* binutils-all/s390/test-v2-ET_REL.sframe.bz2: New test.
* binutils-all/s390/test-v2-ET_REL.sframe.dump: New test.
* binutils-all/x86-64/README-sframe-tests: New test.
* binutils-all/x86-64/sframe.exp: New test.
* binutils-all/x86-64/test-v2-ET_EXEC.sframe.bz2: New test.
* binutils-all/x86-64/test-v2-ET_EXEC.sframe.dump: New test.
* binutils-all/x86-64/test-v2-ET_REL.sframe.bz2: New test.
* binutils-all/x86-64/test-v2-ET_REL.sframe.dump: New test.
---
[Changes in V1]
- Use regexp_diff for the testcases [Indu].
- Add binary data based (ET_REL and ET_EXEC) tests for s390x [Jan,
Jens].
- Add objdump to the testcase as well [Jan].
- Add a README-sframe-tests file containing the instructions to
recreate the binary data files [Jan].
[End of changes in V1]
[No Changes in V2]
---
.../binutils-all/s390/README-sframe-tests | 8 +++
.../testsuite/binutils-all/s390/sframe.exp | 63 ++++++++++++++++++
.../s390/test-v2-ET_EXEC.sframe.bz2 | Bin 0 -> 4094 bytes
.../s390/test-v2-ET_EXEC.sframe.dump | 41 ++++++++++++
.../s390/test-v2-ET_REL.sframe.bz2 | Bin 0 -> 748 bytes
.../s390/test-v2-ET_REL.sframe.dump | 24 +++++++
.../binutils-all/x86-64/README-sframe-tests | 53 +++++++++++++++
.../testsuite/binutils-all/x86-64/sframe.exp | 63 ++++++++++++++++++
.../x86-64/test-v2-ET_EXEC.sframe.bz2 | Bin 0 -> 2739 bytes
.../x86-64/test-v2-ET_EXEC.sframe.dump | 42 ++++++++++++
.../x86-64/test-v2-ET_REL.sframe.bz2 | Bin 0 -> 728 bytes
.../x86-64/test-v2-ET_REL.sframe.dump | 23 +++++++
12 files changed, 317 insertions(+)
create mode 100644 binutils/testsuite/binutils-all/s390/README-sframe-tests
create mode 100644 binutils/testsuite/binutils-all/s390/sframe.exp
create mode 100644 binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.bz2
create mode 100644 binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.dump
create mode 100644 binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.bz2
create mode 100644 binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.dump
create mode 100644 binutils/testsuite/binutils-all/x86-64/README-sframe-tests
create mode 100644 binutils/testsuite/binutils-all/x86-64/sframe.exp
create mode 100644 binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.bz2
create mode 100644 binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.dump
create mode 100644 binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.bz2
create mode 100644 binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.dump
diff --git a/binutils/testsuite/binutils-all/s390/README-sframe-tests b/binutils/testsuite/binutils-all/s390/README-sframe-tests
new file mode 100644
index 00000000000..38162d4e78d
--- /dev/null
+++ b/binutils/testsuite/binutils-all/s390/README-sframe-tests
@@ -0,0 +1,8 @@
+The tests in sframe.exp use binary data files:
+ - test-v2-ET_EXEC.sframe.bz2
+ - test-v2-ET_REL.sframe.bz2
+These files are generated using a as/ld supporting SFrame V2 sections (Binutils
+<= 2.45). The purpose of those tests is to make sure readelf/objdump support
+works for SFrame V2.
+
+The binary files are generated using the steps outlined in x86_64/README-sframe-tests.
diff --git a/binutils/testsuite/binutils-all/s390/sframe.exp b/binutils/testsuite/binutils-all/s390/sframe.exp
new file mode 100644
index 00000000000..569b59abcd1
--- /dev/null
+++ b/binutils/testsuite/binutils-all/s390/sframe.exp
@@ -0,0 +1,63 @@
+# Expect script for s390 object tests for SFrame.
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+if {![istarget "s390x-*-linux*"] || [is_remote host]} {
+ return
+}
+
+set tempfile tmpdir/sframe-testbin
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.sframe.bz2]]
+foreach t $test_list {
+ # We need to strip the ".bz2", but can leave the dirname.
+ set test $subdir/[file tail $t]
+ set testname [file rootname $test]
+ verbose $testname
+
+ # We will check against the expected output in file named ${dumpfile}.dump
+ set dumpfile [file rootname $t]
+
+ if {[catch "system \"bzip2 -dc $t > $tempfile\""] != 0} {
+ untested "bzip2 -dc ($tempfile)"
+ continue
+ }
+
+ # Check readelf output of SFrame V2 sections.
+ set got [remote_exec host "$READELF --sframe $tempfile" "" "/dev/null" "${tempfile}.out"]
+ if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+ fail "readelf SFrame V2 ($testname)"
+ continue
+ }
+
+ if { [regexp_diff "${tempfile}.out" "${dumpfile}.dump"] } then {
+ fail "readelf SFrame V2 ($testname)"
+ }
+ pass "readelf SFrame V2 ($testname)"
+
+ # Check objdump output of SFrame V2 sections as well.
+ set got [remote_exec host "$OBJDUMP --sframe $tempfile" "" "/dev/null" "${tempfile}.out"]
+ if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+ fail "objdump SFrame V2 ($testname)"
+ continue
+ }
+
+ if { [regexp_diff "${tempfile}.out" "${dumpfile}.dump"] } then {
+ fail "objdump SFrame V2 ($testname)"
+ }
+ pass "objdump SFrame V2 ($testname)"
+}
diff --git a/binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.bz2 b/binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.bz2
new file mode 100644
index 00000000000..00fad8bd1ce
Binary files /dev/null and b/binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.bz2 differ
diff --git a/binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.dump b/binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.dump
new file mode 100644
index 00000000000..e67dda5f8f7
--- /dev/null
+++ b/binutils/testsuite/binutils-all/s390/test-v2-ET_EXEC.sframe.dump
@@ -0,0 +1,41 @@
+#...
+Contents of the SFrame section .sframe:
+ Header :
+
+ Version: SFRAME_VERSION_2
+ Flags: SFRAME_F_FDE_SORTED,
+ SFRAME_F_FDE_FUNC_START_PCREL
+ Num FDEs: 6
+ Num FREs: 12
+
+ Function Index :
+
+ func idx \[0\]: pc = 0x10004a0, size = 32 bytes
+ STARTPC +CFA +FP +RA +
+ 00000000010004a0 +sp\+160 +u +u +
+
+ func idx \[1\]: pc = 0x10004c0, size = 64 bytes
+ STARTPC\[m\] +CFA +FP +RA +
+ 0000000000000000 +sp\+160 +u +u +
+
+ func idx \[2\]: pc = 0x1000500, size = 46 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000001000500 +sp\+160 +u +u +
+ 0000000001000506 +sp\+160 +u +c-48 +
+ 000000000100050a +sp\+320 +u +c-48 +
+ 000000000100052c +sp\+160 +u +u +
+
+ func idx \[3\]: pc = 0x1000620, size = 38 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000001000620 +sp\+160 +u +u +
+ 0000000001000626 +sp\+160 +u +c-48 +
+ 000000000100062a +sp\+832 +u +c-48 +
+ 0000000001000644 +sp\+160 +u +u +
+
+ func idx \[4\]: pc = 0x1000648, size = 10 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000001000648 +sp\+160 +u +u +
+
+ func idx \[5\]: pc = 0x1000658, size = 24 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000001000658 +sp\+160 +u +u +
diff --git a/binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.bz2 b/binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.bz2
new file mode 100644
index 00000000000..1cc0050f1e0
Binary files /dev/null and b/binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.bz2 differ
diff --git a/binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.dump b/binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.dump
new file mode 100644
index 00000000000..30b26026b8d
--- /dev/null
+++ b/binutils/testsuite/binutils-all/s390/test-v2-ET_REL.sframe.dump
@@ -0,0 +1,24 @@
+#...
+Contents of the SFrame section .sframe:
+ Header :
+
+ Version: SFRAME_VERSION_2
+ Flags: SFRAME_F_FDE_FUNC_START_PCREL
+ Num FDEs: 2
+ Num FREs: 8
+
+ Function Index :
+
+ func idx \[0\]: pc = 0x0, size = 38 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000000000 +sp\+160 +u +u +
+ 0000000000000006 +sp\+160 +u +c-48 +
+ 000000000000000a +sp\+832 +u +c-48 +
+ 0000000000000024 +sp\+160 +u +u +
+
+ func idx \[1\]: pc = 0x0, size = 46 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000000000 +sp\+160 +u +u +
+ 0000000000000006 +sp\+160 +u +c-48 +
+ 000000000000000a +sp\+320 +u +c-48 +
+ 000000000000002c +sp\+160 +u +u +
diff --git a/binutils/testsuite/binutils-all/x86-64/README-sframe-tests b/binutils/testsuite/binutils-all/x86-64/README-sframe-tests
new file mode 100644
index 00000000000..312e361d7a0
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/README-sframe-tests
@@ -0,0 +1,53 @@
+The tests in sframe.exp use binary data files:
+ - test-v2-ET_EXEC.sframe.bz2
+ - test-v2-ET_REL.sframe.bz2
+These files are generated using a as/ld supporting SFrame V2 sections (Binutils
+<= 2.45). The purpose of those tests is to make sure readelf/objdump support
+works for SFrame V2.
+
+The binary files are generated using the following steps.
+
+$ cat fake_sort.c
+/* Keep noinline to ensure a separate FDE is generated */
+void __attribute__ ((noinline))
+swapit (int *a, int *b)
+{
+ *a = *b;
+}
+
+void fake_sort (int *a, int n)
+{
+ if (n > 0)
+ swapit (&a[0], &a[n-1]);
+}
+
+$ cat sort.c
+#include <stdio.h>
+
+#define ARRAY_LEN 128
+
+void fake_sort (int *a, int n);
+
+void sort_array (void)
+{
+ volatile int data[ARRAY_LEN];
+ fake_sort ((int *)data, ARRAY_LEN);
+}
+
+int main (void)
+{
+ sort_array ();
+ /* for plt. */
+ printf ("done");
+ return 0;
+}
+
+$ gcc -c sort.c -O2 -Wa,--gsframe
+$ gcc -c fake_sort.c -O2 -Wa,--gsframe
+$ gcc sort.o fake_sort.o -o sort -O2 -Wa,--gsframe
+
+$ objcopy --dump-section .sframe=test-v2-ET_EXEC.sframe sort
+$ bzip2 test-v2-ET_EXEC.sframe
+
+$ objcopy --dump-section .sframe=test-v2-ET_REL.sframe sort.o
+$ bzip2 test-v2-ET_REL.sframe
diff --git a/binutils/testsuite/binutils-all/x86-64/sframe.exp b/binutils/testsuite/binutils-all/x86-64/sframe.exp
new file mode 100644
index 00000000000..f5c14bc326a
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/sframe.exp
@@ -0,0 +1,63 @@
+# Expect script for x86-64 object tests for SFrame.
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+if {![istarget "x86_64-*-linux*"] || [is_remote host]} {
+ return
+}
+
+set tempfile tmpdir/sframe-testbin
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.sframe.bz2]]
+foreach t $test_list {
+ # We need to strip the ".bz2", but can leave the dirname.
+ set test $subdir/[file tail $t]
+ set testname [file rootname $test]
+ verbose $testname
+
+ # We will check against the expected output in file named ${dumpfile}.dump
+ set dumpfile [file rootname $t]
+
+ if {[catch "system \"bzip2 -dc $t > $tempfile\""] != 0} {
+ untested "bzip2 -dc ($tempfile)"
+ continue
+ }
+
+ # Check readelf output of SFrame V2 sections.
+ set got [remote_exec host "$READELF --sframe $tempfile" "" "/dev/null" "${tempfile}.out"]
+ if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+ fail "readelf SFrame V2 ($testname)"
+ continue
+ }
+
+ if { [regexp_diff "${tempfile}.out" "${dumpfile}.dump"] } then {
+ fail "readelf SFrame V2 ($testname)"
+ }
+ pass "readelf SFrame V2 ($testname)"
+
+ # Check objdump output of SFrame V2 sections as well.
+ set got [remote_exec host "$OBJDUMP --sframe $tempfile" "" "/dev/null" "${tempfile}.out"]
+ if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+ fail "objdump SFrame V2 ($testname)"
+ continue
+ }
+
+ if { [regexp_diff "${tempfile}.out" "${dumpfile}.dump"] } then {
+ fail "objdump SFrame V2 ($testname)"
+ }
+ pass "objdump SFrame V2 ($testname)"
+}
diff --git a/binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.bz2 b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.bz2
new file mode 100644
index 00000000000..1c4832b2d5b
Binary files /dev/null and b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.bz2 differ
diff --git a/binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.dump b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.dump
new file mode 100644
index 00000000000..87ce8d86797
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_EXEC.sframe.dump
@@ -0,0 +1,42 @@
+#...
+Contents of the SFrame section .sframe:
+ Header :
+
+ Version: SFRAME_VERSION_2
+ Flags: SFRAME_F_FDE_SORTED,
+ SFRAME_F_FDE_FUNC_START_PCREL
+ CFA fixed RA offset: -8
+ Num FDEs: 6
+ Num FREs: 12
+
+ Function Index :
+
+ func idx \[0\]: pc = 0x401020, size = 16 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000401020 +sp\+16 +u +f +
+ 0000000000401026 +sp\+24 +u +f +
+
+ func idx \[1\]: pc = 0x401030, size = 16 bytes
+ STARTPC\[m\] +CFA +FP +RA +
+ 0000000000000000 +sp\+8 +u +f +
+ 000000000000000b +sp\+16 +u +f +
+
+ func idx \[2\]: pc = 0x401040, size = 28 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000401040 +sp\+8 +u +f +
+ 0000000000401044 +sp\+16 +u +f +
+ 000000000040105b +sp\+8 +u +f +
+
+ func idx \[3\]: pc = 0x401150, size = 28 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000401150 +sp\+8 +u +f +
+ 0000000000401157 +sp\+528 +u +f +
+ 000000000040116b +sp\+8 +u +f +
+
+ func idx \[4\]: pc = 0x401170, size = 5 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000401170 +sp\+8 +u +f +
+
+ func idx \[5\]: pc = 0x401180, size = 18 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000401180 +sp\+8 +u +f +
diff --git a/binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.bz2 b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.bz2
new file mode 100644
index 00000000000..cf27032d024
Binary files /dev/null and b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.bz2 differ
diff --git a/binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.dump b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.dump
new file mode 100644
index 00000000000..310347ba48a
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/test-v2-ET_REL.sframe.dump
@@ -0,0 +1,23 @@
+#...
+Contents of the SFrame section .sframe:
+ Header :
+
+ Version: SFRAME_VERSION_2
+ Flags: SFRAME_F_FDE_FUNC_START_PCREL
+ CFA fixed RA offset: -8
+ Num FDEs: 2
+ Num FREs: 6
+
+ Function Index :
+
+ func idx \[0\]: pc = 0x0, size = 28 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000000000 +sp\+8 +u +f +
+ 0000000000000007 +sp\+528 +u +f +
+ 000000000000001b +sp\+8 +u +f +
+
+ func idx \[1\]: pc = 0x0, size = 28 bytes
+ STARTPC +CFA +FP +RA +
+ 0000000000000000 +sp\+8 +u +f +
+ 0000000000000004 +sp\+16 +u +f +
+ 000000000000001b +sp\+8 +u +f +
--
2.43.0
More information about the Binutils
mailing list