aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorIndu Bhagat <indu.bhagat@oracle.com>2022-11-15 15:07:04 -0800
committerIndu Bhagat <indu.bhagat@oracle.com>2022-11-15 15:49:47 -0800
commitcf0e0a0ba91664b680dff1e310f24dbe6447bd4c (patch)
tree8b52c71281b7203aa148aae0c37ec1266648e9f9 /ld
parent19e559f1c91bfaedbd2f91d85ee161f3f03fda3c (diff)
downloadfsf-binutils-gdb-cf0e0a0ba91664b680dff1e310f24dbe6447bd4c.zip
fsf-binutils-gdb-cf0e0a0ba91664b680dff1e310f24dbe6447bd4c.tar.gz
fsf-binutils-gdb-cf0e0a0ba91664b680dff1e310f24dbe6447bd4c.tar.bz2
bfd: linker: merge .sframe sections
The linker merges all the input .sframe sections. When merging, the linker verifies that all the input .sframe sections have the same abi/arch. The linker uses libsframe library to perform key actions on the .sframe sections - decode, read, and create output data. This implies buildsystem changes to make and install libsframe before libbfd. The linker places the output .sframe section in a new segment of its own: PT_GNU_SFRAME. A new segment is not added, however, if the generated .sframe section is empty. When a section is discarded from the final link, the corresponding entries in the .sframe section for those functions are also deleted. The linker sorts the SFrame FDEs on start address by default and sets the SFRAME_F_FDE_SORTED flag in the .sframe section. This patch also adds support for generation of SFrame unwind information for the .plt* sections on x86_64. SFrame unwind info is generated for IBT enabled PLT, lazy/non-lazy PLT. The existing linker option --no-ld-generated-unwind-info has been adapted to include the control of whether .sframe unwind information will be generated for the linker generated sections like PLT. Changes to the linker script have been made as necessary. ChangeLog: * Makefile.def: Add install dependency on libsframe for libbfd. * Makefile.in: Regenerated. * bfd/Makefile.am: Add elf-sframe.c * bfd/Makefile.in: Regenerated. * bfd/bfd-in2.h (SEC_INFO_TYPE_SFRAME): Regenerated. * bfd/configure: Regenerate. * bfd/configure.ac: Add elf-sframe.lo. * bfd/elf-bfd.h (struct sframe_func_bfdinfo): New struct. (struct sframe_dec_info): Likewise. (struct sframe_enc_info): Likewise. (struct elf_link_hash_table): New member for encoded .sframe object. (struct output_elf_obj_tdata): New member. (elf_sframe): New access macro. (_bfd_elf_set_section_sframe): New declaration. * bfd/elf.c (get_segment_type): Handle new segment PT_GNU_SFRAME. (bfd_section_from_phdr): Likewise. (get_program_header_size): Likewise. (_bfd_elf_map_sections_to_segments): Likewise. * bfd/elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Add contents to the .sframe sections or .plt* entries. * bfd/elflink.c (elf_section_ignore_discarded_relocs): Handle SEC_INFO_TYPE_SFRAME. (_bfd_elf_default_action_discarded): Handle .sframe section. (elf_link_input_bfd): Merge .sframe section. (bfd_elf_final_link): Write the output .sframe section. (bfd_elf_discard_info): Handle discarding .sframe section. * bfd/elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Create .sframe section for .plt and .plt.sec. (_bfd_x86_elf_finish_dynamic_sections): Handle .sframe from .plt* sections. * bfd/elfxx-x86.h (PLT_SFRAME_FDE_START_OFFSET): New definition. (SFRAME_PLT0_MAX_NUM_FRES): Likewise. (SFRAME_PLTN_MAX_NUM_FRES): Likewise. (struct elf_x86_sframe_plt): New structure. (struct elf_x86_link_hash_table): New member. (struct elf_x86_init_table): New members for .sframe creation. * bfd/section.c: Add new definition SEC_INFO_TYPE_SFRAME. * binutils/readelf.c (get_segment_type): Handle new segment PT_GNU_SFRAME. * ld/ld.texi: Update documentation for --no-ld-generated-unwind-info. * ld/scripttempl/elf.sc: Support .sframe sections. * ld/Makefile.am (TESTSFRAMELIB): Use it. (check-DEJAGNU): Likewise. * ld/Makefile.in: Regenerated. * ld/configure.ac (TESTSFRAMELIB): Set to the .so or .a like TESTBFDLIB. * ld/configure: Regenerated. * bfd/elf-sframe.c: New file. include/ChangeLog: * elf/common.h (PT_GNU_SFRAME): New definition. * elf/internal.h (struct elf_segment_map): Handle new segment type PT_GNU_SFRAME. ld/testsuite/ChangeLog: * ld/testsuite/ld-bootstrap/bootstrap.exp: Add SFRAMELIB. * ld/testsuite/ld-aarch64/aarch64-elf.exp: Add new test sframe-simple-1. * ld/testsuite/ld-aarch64/sframe-bar.s: New file. * ld/testsuite/ld-aarch64/sframe-foo.s: Likewise. * ld/testsuite/ld-aarch64/sframe-simple-1.d: Likewise. * ld/testsuite/ld-sframe/sframe-empty.d: New test. * ld/testsuite/ld-sframe/sframe-empty.s: New file. * ld/testsuite/ld-sframe/sframe.exp: New testsuite. * ld/testsuite/ld-x86-64/sframe-bar.s: New file. * ld/testsuite/ld-x86-64/sframe-foo.s: Likewise. * ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise. * ld/testsuite/ld-x86-64/sframe-plt-1.d: Likewise. * ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise. * ld/testsuite/ld-x86-64/x86-64.exp: Add new tests - sframe-simple-1, sframe-plt-1. * ld/testsuite/lib/ld-lib.exp: Add new proc to check if assembler supports SFrame section. * ld/testsuite/ld-sframe/discard.d: New file. * ld/testsuite/ld-sframe/discard.ld: Likewise. * ld/testsuite/ld-sframe/discard.s: Likewise.
Diffstat (limited to 'ld')
-rw-r--r--ld/Makefile.am2
-rw-r--r--ld/Makefile.in2
-rwxr-xr-xld/configure8
-rw-r--r--ld/configure.ac3
-rw-r--r--ld/ld.texi4
-rw-r--r--ld/scripttempl/elf.sc2
-rw-r--r--ld/testsuite/ld-aarch64/aarch64-elf.exp4
-rw-r--r--ld/testsuite/ld-aarch64/sframe-bar.s7
-rw-r--r--ld/testsuite/ld-aarch64/sframe-foo.s10
-rw-r--r--ld/testsuite/ld-aarch64/sframe-simple-1.d26
-rw-r--r--ld/testsuite/ld-bootstrap/bootstrap.exp8
-rw-r--r--ld/testsuite/ld-sframe/discard.d10
-rw-r--r--ld/testsuite/ld-sframe/discard.ld9
-rw-r--r--ld/testsuite/ld-sframe/discard.s13
-rw-r--r--ld/testsuite/ld-sframe/sframe-empty.d10
-rw-r--r--ld/testsuite/ld-sframe/sframe-empty.s2
-rw-r--r--ld/testsuite/ld-sframe/sframe.exp47
-rw-r--r--ld/testsuite/ld-x86-64/sframe-bar.s31
-rw-r--r--ld/testsuite/ld-x86-64/sframe-foo.s37
-rw-r--r--ld/testsuite/ld-x86-64/sframe-plt-1.d29
-rw-r--r--ld/testsuite/ld-x86-64/sframe-simple-1.d35
-rw-r--r--ld/testsuite/ld-x86-64/x86-64.exp5
-rw-r--r--ld/testsuite/lib/ld-lib.exp45
23 files changed, 342 insertions, 7 deletions
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 66e9094..65fef4e 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -972,6 +972,7 @@ EXTRA_ld_new_SOURCES += $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES)
# This is the real libbfd.a and libctf.a created by libtool.
TESTBFDLIB = @TESTBFDLIB@
TESTCTFLIB = @TESTCTFLIB@
+TESTSFRAMELIB = @TESTSFRAMELIB@
check-DEJAGNU: site.exp
(cd .libs; test -e ldscripts || test ! -e ld-new || $(LN_S) ../ldscripts .)
@@ -989,6 +990,7 @@ check-DEJAGNU: site.exp
CXX_FOR_TARGET="$(CXX_FOR_TARGET)" \
CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
OFILES="$(OFILES)" BFDLIB="$(TESTBFDLIB)" CTFLIB="$(TESTCTFLIB) $(ZLIB)" \
+ SFRAMELIB="$(TESTSFRAMELIB)" \
LIBIBERTY="$(LIBIBERTY) $(LIBINTL)" LIBS="$(LIBS)" \
DO_COMPARE="`echo '$(do_compare)' | sed -e 's,\\$$,,g'`" \
$(RUNTESTFLAGS); \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 5e4787f..ff4c916 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -470,6 +470,7 @@ TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
# This is the real libbfd.a and libctf.a created by libtool.
TESTBFDLIB = @TESTBFDLIB@
TESTCTFLIB = @TESTCTFLIB@
+TESTSFRAMELIB = @TESTSFRAMELIB@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
WARN_CFLAGS = @WARN_CFLAGS@
@@ -2642,6 +2643,7 @@ check-DEJAGNU: site.exp
CXX_FOR_TARGET="$(CXX_FOR_TARGET)" \
CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
OFILES="$(OFILES)" BFDLIB="$(TESTBFDLIB)" CTFLIB="$(TESTCTFLIB) $(ZLIB)" \
+ SFRAMELIB="$(TESTSFRAMELIB)" \
LIBIBERTY="$(LIBIBERTY) $(LIBINTL)" LIBS="$(LIBS)" \
DO_COMPARE="`echo '$(do_compare)' | sed -e 's,\\$$,,g'`" \
$(RUNTESTFLAGS); \
diff --git a/ld/configure b/ld/configure
index 7900045..a4d30ab 100755
--- a/ld/configure
+++ b/ld/configure
@@ -634,6 +634,7 @@ ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
+TESTSFRAMELIB
TESTCTFLIB
TESTBFDLIB
EMULATION_LIBPATH
@@ -11624,7 +11625,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11627 "configure"
+#line 11628 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -11730,7 +11731,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11733 "configure"
+#line 11734 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -17487,9 +17488,11 @@ EMULATION_LIBPATH=$all_libpath
if test x${enable_static} = xno; then
TESTBFDLIB="-Wl,--rpath,../bfd/.libs ../bfd/.libs/libbfd.so"
TESTCTFLIB="-Wl,--rpath,../libctf/.libs ../libctf/.libs/libctf.so"
+ TESTSFRAMELIB="-Wl,--rpath,../libsframe/.libs ../libsframe/.libs/libsframe.so"
else
TESTBFDLIB="../bfd/.libs/libbfd.a"
TESTCTFLIB="../libctf/.libs/libctf.a"
+ TESTSFRAMELIB="../libsframe/.libs/libsframe.a"
fi
if test "${enable_libctf}" = no; then
TESTCTFLIB=
@@ -17497,6 +17500,7 @@ fi
+
target_vendor=${target_vendor=$host_vendor}
case "$target_vendor" in
hp) EXTRA_SHLIB_EXTENSION=".sl" ;;
diff --git a/ld/configure.ac b/ld/configure.ac
index 6123ea7..1ee40a5 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -628,15 +628,18 @@ AC_SUBST(EMULATION_LIBPATH)
if test x${enable_static} = xno; then
TESTBFDLIB="-Wl,--rpath,../bfd/.libs ../bfd/.libs/libbfd.so"
TESTCTFLIB="-Wl,--rpath,../libctf/.libs ../libctf/.libs/libctf.so"
+ TESTSFRAMELIB="-Wl,--rpath,../libsframe/.libs ../libsframe/.libs/libsframe.so"
else
TESTBFDLIB="../bfd/.libs/libbfd.a"
TESTCTFLIB="../libctf/.libs/libctf.a"
+ TESTSFRAMELIB="../libsframe/.libs/libsframe.a"
fi
if test "${enable_libctf}" = no; then
TESTCTFLIB=
fi
AC_SUBST(TESTBFDLIB)
AC_SUBST(TESTCTFLIB)
+AC_SUBST(TESTSFRAMELIB)
target_vendor=${target_vendor=$host_vendor}
case "$target_vendor" in
diff --git a/ld/ld.texi b/ld/ld.texi
index 82527e3..3836465 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -2837,7 +2837,9 @@ section and ELF @code{PT_GNU_EH_FRAME} segment header.
@item --no-ld-generated-unwind-info
Request creation of @code{.eh_frame} unwind info for linker
generated code sections like PLT. This option is on by default
-if linker generated unwind info is supported.
+if linker generated unwind info is supported. This option also
+controls the generation of @code{.sframe} unwind info for linker
+generated code sections like PLT.
@kindex --enable-new-dtags
@kindex --disable-new-dtags
diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
index bf2268b..5cc364b 100644
--- a/ld/scripttempl/elf.sc
+++ b/ld/scripttempl/elf.sc
@@ -601,6 +601,7 @@ cat <<EOF
${OTHER_READONLY_SECTIONS}
.eh_frame_hdr ${RELOCATING-0} : { *(.eh_frame_hdr)${RELOCATING+ *(.eh_frame_entry .eh_frame_entry.*)} }
.eh_frame ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
+ .sframe ${RELOCATING-0} : ONLY_IF_RO { *(.sframe)${RELOCATING+ *(.sframe.*)} }
.gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
.gnu_extab ${RELOCATING-0} : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
@@ -619,6 +620,7 @@ cat <<EOF
/* Exception handling */
.eh_frame ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
+ .sframe ${RELOCATING-0} : ONLY_IF_RW { *(.sframe)${RELOCATING+ *(.sframe.*)} }
.gnu_extab ${RELOCATING-0} : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
.exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges${RELOCATING+*}) }
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 337bead..0a732b5 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -457,3 +457,7 @@ run_dump_test "bti-pac-plt-2"
run_dump_test "bti-warn"
run_dump_test "weak-tls"
run_dump_test "undef-tls"
+
+if { ![skip_sframe_tests] } {
+ run_dump_test "sframe-simple-1"
+}
diff --git a/ld/testsuite/ld-aarch64/sframe-bar.s b/ld/testsuite/ld-aarch64/sframe-bar.s
new file mode 100644
index 0000000..8dd50bf
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/sframe-bar.s
@@ -0,0 +1,7 @@
+ .cfi_startproc
+ cmp w0, 1000
+ bgt .L4
+ ret
+.L4:
+ b foo
+ .cfi_endproc
diff --git a/ld/testsuite/ld-aarch64/sframe-foo.s b/ld/testsuite/ld-aarch64/sframe-foo.s
new file mode 100644
index 0000000..a2780a6
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/sframe-foo.s
@@ -0,0 +1,10 @@
+ .cfi_startproc
+ mov w1, 26215
+ movk w1, 0x6666, lsl 16
+ smull x1, w0, w1
+ asr x1, x1, 34
+ sub w1, w1, w0, asr 31
+ add w1, w1, w1, lsl 2
+ sub w0, w0, w1, lsl 1
+ ret
+ .cfi_endproc
diff --git a/ld/testsuite/ld-aarch64/sframe-simple-1.d b/ld/testsuite/ld-aarch64/sframe-simple-1.d
new file mode 100644
index 0000000..6f61715
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/sframe-simple-1.d
@@ -0,0 +1,26 @@
+#as: --gsframe
+#source: sframe-foo.s
+#source: sframe-bar.s
+#objdump: --sframe=.sframe
+#ld: -shared
+#name: SFrame Simple link
+
+.*: file format .*
+
+Contents of the SFrame section .sframe:
+ Header :
+
+ Version: SFRAME_VERSION_1
+ Flags: SFRAME_F_FDE_SORTED
+ Num FDEs: 2
+ Num FREs: 2
+
+ Function Index :
+
+#...
+ STARTPC +CFA +FP +RA +
+ 0+[0-9a-f]+ +sp\+0 +u +u +
+
+#...
+ STARTPC +CFA +FP +RA +
+ 0+[0-9a-f]+ +sp\+0 +u +u +
diff --git a/ld/testsuite/ld-bootstrap/bootstrap.exp b/ld/testsuite/ld-bootstrap/bootstrap.exp
index 99a1109..de82a2b 100644
--- a/ld/testsuite/ld-bootstrap/bootstrap.exp
+++ b/ld/testsuite/ld-bootstrap/bootstrap.exp
@@ -184,7 +184,7 @@ foreach flags $test_flags {
setup_xfail "mips*-*-irix5*"
}
- if ![ld_link $CC tmpdir/ld1 "$CFLAGS $flags tmpdir/ld-partial.o $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
+ if ![ld_link $CC tmpdir/ld1 "$CFLAGS $flags tmpdir/ld-partial.o $CTFLIB $BFDLIB $LIBIBERTY $SFRAMELIB $extralibs"] {
fail $testname
continue
}
@@ -201,13 +201,13 @@ foreach flags $test_flags {
}
regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld1/ gcc_B_opt
- if ![ld_link $CC tmpdir/ld2 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
+ if ![ld_link $CC tmpdir/ld2 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $SFRAMELIB $extralibs"] {
fail $testname
continue
}
regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld2/ gcc_B_opt
- if ![ld_link $CC tmpdir/ld3 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
+ if ![ld_link $CC tmpdir/ld3 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $SFRAMELIB $extralibs"] {
fail $testname
continue
}
@@ -220,7 +220,7 @@ foreach flags $test_flags {
# generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
# So we rebuild tmpdir/ld2 with tmpdir/ld3.
regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld3/ gcc_B_opt
- if ![ld_link $CC tmpdir/ld2 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
+ if ![ld_link $CC tmpdir/ld2 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $SFRAMELIB $extralibs"] {
fail $testname
continue
}
diff --git a/ld/testsuite/ld-sframe/discard.d b/ld/testsuite/ld-sframe/discard.d
new file mode 100644
index 0000000..cb0371e
--- /dev/null
+++ b/ld/testsuite/ld-sframe/discard.d
@@ -0,0 +1,10 @@
+#as:
+#source: discard.s
+#ld: -T discard.ld
+#objdump: -hw
+#name: Check that SFrame section can be discarded
+
+#failif
+#...
+ [0-9] .sframe .*
+#...
diff --git a/ld/testsuite/ld-sframe/discard.ld b/ld/testsuite/ld-sframe/discard.ld
new file mode 100644
index 0000000..5745cce
--- /dev/null
+++ b/ld/testsuite/ld-sframe/discard.ld
@@ -0,0 +1,9 @@
+ENTRY(_start)
+SECTIONS
+{
+ . = SIZEOF_HEADERS;
+ /* Sections to be discarded */
+ /DISCARD/ : {
+ *(.sframe)
+ }
+}
diff --git a/ld/testsuite/ld-sframe/discard.s b/ld/testsuite/ld-sframe/discard.s
new file mode 100644
index 0000000..a438b42
--- /dev/null
+++ b/ld/testsuite/ld-sframe/discard.s
@@ -0,0 +1,13 @@
+ .text
+ .cfi_sections .sframe
+ .globl foo
+ .type foo, @function
+foo:
+ .cfi_startproc
+ .cfi_def_cfa_offset 16
+ .cfi_def_cfa 7, 8
+ .cfi_endproc
+
+ .globl _start
+_start:
+ .long foo
diff --git a/ld/testsuite/ld-sframe/sframe-empty.d b/ld/testsuite/ld-sframe/sframe-empty.d
new file mode 100644
index 0000000..bad08c5
--- /dev/null
+++ b/ld/testsuite/ld-sframe/sframe-empty.d
@@ -0,0 +1,10 @@
+#as:
+#source: sframe-empty.s
+#objdump: -hw
+#ld: -shared
+#name: Empty SFrame section
+
+#failif
+#...
+ [0-9] .sframe .*
+#...
diff --git a/ld/testsuite/ld-sframe/sframe-empty.s b/ld/testsuite/ld-sframe/sframe-empty.s
new file mode 100644
index 0000000..659b3b9
--- /dev/null
+++ b/ld/testsuite/ld-sframe/sframe-empty.s
@@ -0,0 +1,2 @@
+ .cfi_startproc
+ .cfi_endproc
diff --git a/ld/testsuite/ld-sframe/sframe.exp b/ld/testsuite/ld-sframe/sframe.exp
new file mode 100644
index 0000000..392dfbd
--- /dev/null
+++ b/ld/testsuite/ld-sframe/sframe.exp
@@ -0,0 +1,47 @@
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# 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 [skip_sframe_tests] {
+ unsupported "no SFrame format support in the assembler, or SFrame disabled"
+ return 0
+}
+
+if ![is_elf_format] {
+ unsupported "SFrame not supported"
+ return 0
+}
+
+if {[info exists env(LC_ALL)]} {
+ set old_lc_all $env(LC_ALL)
+}
+set env(LC_ALL) "C"
+
+set sframe_test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+
+foreach sframe_test $sframe_test_list {
+ verbose [file rootname $sframe_test]
+ run_dump_test [file rootname $sframe_test]
+}
+
+if {[info exists old_lc_all]} {
+ set env(LC_ALL) $old_lc_all
+} else {
+ unset env(LC_ALL)
+}
diff --git a/ld/testsuite/ld-x86-64/sframe-bar.s b/ld/testsuite/ld-x86-64/sframe-bar.s
new file mode 100644
index 0000000..4d03213
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe-bar.s
@@ -0,0 +1,31 @@
+ .file "sframe-bar.c"
+ .text
+ .globl bar
+ .type bar, @function
+bar:
+.LFB0:
+ .cfi_startproc
+ pushq %rbp
+ .cfi_def_cfa_offset 16
+ .cfi_offset 6, -16
+ movq %rsp, %rbp
+ .cfi_def_cfa_register 6
+ subq $16, %rsp
+ movl %edi, -4(%rbp)
+ cmpl $1000, -4(%rbp)
+ jle .L2
+ movl -4(%rbp), %eax
+ movl %eax, %edi
+ call foo
+ jmp .L3
+.L2:
+ movl -4(%rbp), %eax
+.L3:
+ leave
+ .cfi_def_cfa 7, 8
+ ret
+ .cfi_endproc
+.LFE0:
+ .size bar, .-bar
+ .ident "GCC: (GNU) 13.0.0 20220519 (experimental)"
+ .section .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/sframe-foo.s b/ld/testsuite/ld-x86-64/sframe-foo.s
new file mode 100644
index 0000000..a871908
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe-foo.s
@@ -0,0 +1,37 @@
+ .file "sframe-foo.c"
+ .text
+ .globl foo
+ .type foo, @function
+foo:
+.LFB0:
+ .cfi_startproc
+ pushq %rbp
+ .cfi_def_cfa_offset 16
+ .cfi_offset 6, -16
+ movq %rsp, %rbp
+ .cfi_def_cfa_register 6
+ movl %edi, -4(%rbp)
+ movl -4(%rbp), %ecx
+ movslq %ecx, %rax
+ imulq $1717986919, %rax, %rax
+ shrq $32, %rax
+ movl %eax, %edx
+ sarl $2, %edx
+ movl %ecx, %eax
+ sarl $31, %eax
+ subl %eax, %edx
+ movl %edx, %eax
+ sall $2, %eax
+ addl %edx, %eax
+ addl %eax, %eax
+ subl %eax, %ecx
+ movl %ecx, %edx
+ movl %edx, %eax
+ popq %rbp
+ .cfi_def_cfa 7, 8
+ ret
+ .cfi_endproc
+.LFE0:
+ .size foo, .-foo
+ .ident "GCC: (GNU) 13.0.0 20220519 (experimental)"
+ .section .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/sframe-plt-1.d b/ld/testsuite/ld-x86-64/sframe-plt-1.d
new file mode 100644
index 0000000..06bb16b
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe-plt-1.d
@@ -0,0 +1,29 @@
+#as: --gsframe
+#source: sframe-foo.s
+#source: sframe-bar.s
+#objdump: --sframe=.sframe
+#ld: -shared
+#name: SFrame for plt0 and pltN
+
+.*: +file format .*
+
+Contents of the SFrame section .sframe:
+ Header :
+
+ Version: SFRAME_VERSION_1
+ Flags: SFRAME_F_FDE_SORTED
+#...
+
+ Function Index :
+
+ func idx \[0\]: pc = 0x1000, size = 16 bytes
+ STARTPC +CFA +FP +RA +
+ 0+1000 +sp\+16 +u +u +
+ 0+1006 +sp\+24 +u +u +
+
+ func idx \[1\]: pc = 0x1010, size = 16 bytes
+ STARTPC\[m\] +CFA +FP +RA +
+ 0+0000 +sp\+8 +u +u +
+ 0+000b +sp\+16 +u +u +
+
+#...
diff --git a/ld/testsuite/ld-x86-64/sframe-simple-1.d b/ld/testsuite/ld-x86-64/sframe-simple-1.d
new file mode 100644
index 0000000..afc0006
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe-simple-1.d
@@ -0,0 +1,35 @@
+#as: --gsframe
+#source: sframe-foo.s
+#source: sframe-bar.s
+#objdump: --sframe=.sframe
+#ld: -shared
+#name: SFrame Simple link
+
+.*: +file format .*
+
+Contents of the SFrame section .sframe:
+ Header :
+
+ Version: SFRAME_VERSION_1
+ Flags: SFRAME_F_FDE_SORTED
+#...
+
+ Function Index :
+
+#...
+
+#...
+
+ func idx \[2\]: pc = 0x1020, size = 53 bytes
+ STARTPC +CFA +FP +RA +
+ 0+1020 +sp\+8 +u +u +
+ 0+1021 +sp\+16 +c-16 +u +
+ 0+1024 +fp\+16 +c-16 +u +
+ 0+1054 +sp\+8 +c-16 +u +
+
+ func idx \[3\]: pc = 0x1055, size = 37 bytes
+ STARTPC +CFA +FP +RA +
+ 0+1055 +sp\+8 +u +u +
+ 0+1056 +sp\+16 +c-16 +u +
+ 0+1059 +fp\+16 +c-16 +u +
+ 0+1079 +sp\+8 +c-16 +u +
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index e6a834a..1782e8e 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -506,6 +506,11 @@ run_dump_test "dt-relr-1a-x32"
run_dump_test "dt-relr-1b"
run_dump_test "dt-relr-1b-x32"
+if { ![skip_sframe_tests] } {
+ run_dump_test "sframe-simple-1"
+ run_dump_test "sframe-plt-1"
+}
+
if ![istarget "x86_64-*-linux*"] {
return
}
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 2cd840c..47d1494 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1690,3 +1690,48 @@ proc skip_ctf_tests { } {
return 1
}
+
+# Check if the assembler supports SFrame.
+
+proc check_as_sframe { } {
+ global check_as_sframe_result
+ global as
+ if [info exists check_as_sframe_result] {
+ return $check_as_sframe_result
+ }
+
+ # SFrame generation needs CFI support
+ if { ![check_as_cfi] } {
+ set check_as_sframe_result 0;
+ return 0
+ }
+
+ set as_file "tmpdir/check_as_sframe.s"
+ set as_fh [open $as_file w 0666]
+ puts $as_fh "# Generated file. DO NOT EDIT"
+ puts $as_fh "\t.cfi_sections \".sframe\""
+ puts $as_fh "\t.cfi_startproc"
+ puts $as_fh "\t.cfi_endproc"
+ close $as_fh
+ remote_download host $as_file
+ verbose -log "Checking SFrame:"
+ set success [ld_assemble $as $as_file "/dev/null"]
+ #remote_file host delete $as_file
+ set check_as_sframe_result $success
+ return $success
+}
+
+proc skip_sframe_tests { } {
+# FIXME TODO
+# global enable_libsframe
+#
+# if {$enable_libsframe eq "no"} {
+# return 1
+# }
+
+ if [check_as_sframe] {
+ return 0
+ }
+
+ return 1
+}