readelf/objdump: Dump SFrame CFA fixed FP and RA offsets

The SFrame format allows architectures to specify fixed offsets from the
CFA, if any, from which the frame pointer (FP) and/or return address
(RA) may be recovered. These offsets are stored in the SFrame header.

For instance the SFrame generation in the assembler for x86 AMD64
specifies a fixed offset from the CFA, from which the return address
(RA) may be recovered.

When dumping the SFrame header, for instance in readelf/objdump with
option --sframe, do also dump the specified fixed offsets from the CFA,
if any, from which the frame pointer (FP) and return address (RA) may
be recovered.

Update the common SFrame test case verification patterns to allow for
the optional dumping of the CFA fixed FP/RA offsets. Update the x86-
specific SFrame and SCFI test case verification patterns to require a
CFA fixed RA offset of -8.

libsframe/
	* sframe-dump.c: Dump CFA fixed FP and RA offsets.

gas/testsuite/
	* gas/cfi-sframe/cfi-sframe-common-1.d: Test for optional fixed
	FP and RA offsets.
	* gas/cfi-sframe/cfi-sframe-common-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-3.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-4.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-5.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-6.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-7.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-8.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-1.d: Test for fixed
	RA offset.
	* gas/cfi-sframe/common-empty-1.d: Test for optional fixed
	FP and RA offsets.
	* gas/cfi-sframe/common-empty-2.d: Likewise.
	* gas/cfi-sframe/common-empty-3.d: Likewise.
	* gas/scfi/x86_64/scfi-cfi-sections-1.d: Test for SFrame fixed
	RA offset.
	* gas/scfi/x86_64/scfi-dyn-stack-1.d: Likewise.

ld/testsuite/
	* ld-x86-64/sframe-plt-1.d: Test for SFrame fixed RA offset.
	* ld-x86-64/sframe-simple-1.d: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
This commit is contained in:
Jens Remus 2024-07-04 10:34:12 +02:00
parent 8086fe0b3d
commit 76f05e1dfb
17 changed files with 37 additions and 0 deletions

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 1

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 1

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 1

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 3

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 3

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 3

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 3

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 1
Num FREs: 2

View File

@ -8,6 +8,7 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
CFA fixed RA offset: \-8
Num FDEs: 1
Num FREs: 4

View File

@ -9,6 +9,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 0
Num FREs: 0

View File

@ -9,6 +9,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 0
Num FREs: 0

View File

@ -8,6 +8,8 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
#? CFA fixed FP offset: \-?\d+
#? CFA fixed RA offset: \-?\d+
Num FDEs: 0
Num FREs: 0

View File

@ -8,6 +8,7 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
CFA fixed RA offset: \-8
Num FDEs: 1
Num FREs: 5

View File

@ -9,6 +9,7 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: NONE
CFA fixed RA offset: \-8
Num FDEs: 1
Num FREs: 4

View File

@ -12,6 +12,7 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: SFRAME_F_FDE_SORTED
CFA fixed RA offset: \-8
#...
Function Index :

View File

@ -12,6 +12,7 @@ Contents of the SFrame section .sframe:
Version: SFRAME_VERSION_2
Flags: SFRAME_F_FDE_SORTED
CFA fixed RA offset: \-8
#...
Function Index :

View File

@ -47,6 +47,8 @@ dump_sframe_header (sframe_decoder_ctx *sfd_ctx)
uint8_t flags;
char *flags_str;
const char *ver_str = NULL;
int8_t cfa_fixed_fp_offset;
int8_t cfa_fixed_ra_offset;
const sframe_header *header = &(sfd_ctx->sfd_header);
/* Prepare SFrame section version string. */
@ -82,12 +84,20 @@ dump_sframe_header (sframe_decoder_ctx *sfd_ctx)
else
strcpy (flags_str, "NONE");
/* CFA fixed FP and RA offsets. */
cfa_fixed_fp_offset = header->sfh_cfa_fixed_fp_offset;
cfa_fixed_ra_offset = header->sfh_cfa_fixed_ra_offset;
const char* subsec_name = "Header";
printf ("\n");
printf (" %s :\n", subsec_name);
printf ("\n");
printf (" Version: %s\n", ver_str);
printf (" Flags: %s\n", flags_str);
if (cfa_fixed_fp_offset != SFRAME_CFA_FIXED_FP_INVALID)
printf (" CFA fixed FP offset: %d\n", cfa_fixed_fp_offset);
if (cfa_fixed_ra_offset != SFRAME_CFA_FIXED_RA_INVALID)
printf (" CFA fixed RA offset: %d\n", cfa_fixed_ra_offset);
printf (" Num FDEs: %d\n", sframe_decoder_get_num_fidx (sfd_ctx));
printf (" Num FREs: %d\n", header->sfh_num_fres);