14b169a6bSchristos\input texinfo @c -*- Texinfo -*- 24b169a6bSchristos@setfilename sframe-spec.info 34b169a6bSchristos@settitle The SFrame Format 44b169a6bSchristos 54b169a6bSchristos@copying 6*6817db7fSchristosCopyright @copyright{} 2021-2024 Free Software Foundation, Inc. 74b169a6bSchristos 84b169a6bSchristosPermission is granted to copy, distribute and/or modify this document 94b169a6bSchristosunder the terms of the GNU General Public License, Version 3 or any 104b169a6bSchristoslater version published by the Free Software Foundation. A copy of the 114b169a6bSchristoslicense is included in the section entitled ``GNU General Public 124b169a6bSchristosLicense''. 134b169a6bSchristos 144b169a6bSchristos@end copying 154b169a6bSchristos 164b169a6bSchristos@dircategory Software development 174b169a6bSchristos@direntry 184b169a6bSchristos* SFrame: (sframe-spec). The Simple Frame format. 194b169a6bSchristos@end direntry 204b169a6bSchristos 214b169a6bSchristos@titlepage 224b169a6bSchristos@title The SFrame Format 23*6817db7fSchristos@subtitle Version 2 244b169a6bSchristos@author Indu Bhagat 254b169a6bSchristos 264b169a6bSchristos@page 274b169a6bSchristos@vskip 0pt plus 1filll 284b169a6bSchristos@insertcopying 294b169a6bSchristos@end titlepage 304b169a6bSchristos@contents 314b169a6bSchristos 324b169a6bSchristos@ifnottex 334b169a6bSchristos@node Top 344b169a6bSchristos@top The SFrame format 354b169a6bSchristos 36*6817db7fSchristosThis manual describes version 2 of the SFrame file format. SFrame stands for 374b169a6bSchristosSimple Frame format. SFrame format keeps track of the minimal necessary 38*6817db7fSchristosinformation needed for generating stack traces: 394b169a6bSchristos 404b169a6bSchristos@itemize @minus 414b169a6bSchristos@item 424b169a6bSchristosCanonical Frame Address (CFA). 434b169a6bSchristos@item 444b169a6bSchristosFrame Pointer (FP). 454b169a6bSchristos@item 464b169a6bSchristosReturn Address (RA). 474b169a6bSchristos@end itemize 484b169a6bSchristos 49*6817db7fSchristosThe reason for existence of the SFrame format is to provide a simple, fast and 50*6817db7fSchristoslow-overhead mechanism to generate stack traces. 514b169a6bSchristos 524b169a6bSchristos@menu 53*6817db7fSchristos* Introduction:: 544b169a6bSchristos* SFrame section:: 554b169a6bSchristos* Index:: 564b169a6bSchristos@end menu 574b169a6bSchristos 584b169a6bSchristos@end ifnottex 594b169a6bSchristos 60*6817db7fSchristos@node Introduction 61*6817db7fSchristos@chapter Introduction 62*6817db7fSchristos@cindex Introduction 634b169a6bSchristos 64*6817db7fSchristos@menu 65*6817db7fSchristos* Overview:: 66*6817db7fSchristos* Changes from Version 1 to Version 2:: 67*6817db7fSchristos@end menu 68*6817db7fSchristos 69*6817db7fSchristos@node Overview 70*6817db7fSchristos@section Overview 71*6817db7fSchristos@cindex Overview 72*6817db7fSchristos 73*6817db7fSchristosThe SFrame stack trace information is provided in a loaded section, known as the 744b169a6bSchristos@code{.sframe} section. When available, the @code{.sframe} section appears in 754b169a6bSchristosa new segment of its own, PT_GNU_SFRAME. 764b169a6bSchristos 774b169a6bSchristosThe SFrame format is currently supported only for select ABIs, namely, AMD64 784b169a6bSchristosand AAPCS64. 794b169a6bSchristos 80*6817db7fSchristosA portion of the SFrame format follows an unaligned on-disk representation. 81*6817db7fSchristosSome data structures, however, (namely the SFrame header and the SFrame 82*6817db7fSchristosfunction descriptor entry) have elements at their natural boundaries. All data 83*6817db7fSchristosstructures are packed, unless otherwise stated. 84*6817db7fSchristos 854b169a6bSchristosThe contents of the SFrame section are stored in the target endianness, i.e., 864b169a6bSchristosin the endianness of the system on which the section is targetted to be used. 874b169a6bSchristosAn SFrame section reader may use the magic number in the SFrame header to 884b169a6bSchristosidentify the endianness of the SFrame section. 894b169a6bSchristos 904b169a6bSchristosAddresses in this specification are expressed in bytes. 914b169a6bSchristos 92*6817db7fSchristosThe rest of this specification describes the current version of the format, 93*6817db7fSchristos@code{SFRAME_VERSION_2}, in detail. Additional sections outline the major 94*6817db7fSchristoschanges made to each previously published version of the SFrame stack trace 95*6817db7fSchristosformat. 96*6817db7fSchristos 974b169a6bSchristosThe associated API to decode, probe and encode the SFrame section, provided via 984b169a6bSchristos@code{libsframe}, is not accompanied here at this time. This will be added 994b169a6bSchristoslater. 1004b169a6bSchristos 1014b169a6bSchristosThis document is intended to be in sync with the C code in @file{sframe.h}. 102*6817db7fSchristosPlease report discrepancies between the two, if any. 103*6817db7fSchristos 104*6817db7fSchristos@node Changes from Version 1 to Version 2 105*6817db7fSchristos@section Changes from Version 1 to Version 2 106*6817db7fSchristos@cindex Changes from Version 1 to Version 2 107*6817db7fSchristos 108*6817db7fSchristosThe following is a list of the changes made to the SFrame stack trace format 109*6817db7fSchristossince Version 1 was published. 110*6817db7fSchristos 111*6817db7fSchristos@itemize @bullet 112*6817db7fSchristos@item 113*6817db7fSchristosSFrame Function Descriptor Entry encodes the size of the repetitive code 114*6817db7fSchristosblocks, e.g., pltN entries for which an FDE of type SFRAME_FDE_TYPE_PCMASK is 115*6817db7fSchristosused. 116*6817db7fSchristos@item 117*6817db7fSchristosSFrame Function Descriptor Entry includes an explicit padding of two bytes to 118*6817db7fSchristosensure natural alignment for its data members. 119*6817db7fSchristos@item 120*6817db7fSchristosThe above two imply that each SFrame Function Descriptor Entry has a fixed size 121*6817db7fSchristosof 20 bytes instead of its size of 17 bytes in SFrame format version 1. 122*6817db7fSchristos@end itemize 1234b169a6bSchristos 1244b169a6bSchristos@node SFrame section 1254b169a6bSchristos@chapter SFrame section 1264b169a6bSchristos@cindex SFrame section 1274b169a6bSchristos 1284b169a6bSchristosThe SFrame section consists of an SFrame header, starting with a preamble, and 1294b169a6bSchristostwo other sub-sections, namely the SFrame Function Descriptor Entry (SFrame 1304b169a6bSchristosFDE) sub-section, and the SFrame Frame Row Entry (SFrame FRE) sub-section. 1314b169a6bSchristos 1324b169a6bSchristos@menu 1334b169a6bSchristos* SFrame Preamble:: 1344b169a6bSchristos* SFrame Header:: 1354b169a6bSchristos* SFrame Function Descriptor Entries:: 1364b169a6bSchristos* SFrame Frame Row Entries:: 1374b169a6bSchristos@end menu 1384b169a6bSchristos 1394b169a6bSchristos@node SFrame Preamble 1404b169a6bSchristos@section SFrame Preamble 1414b169a6bSchristos@cindex SFrame preamble 1424b169a6bSchristos 1434b169a6bSchristosThe preamble is a 32-bit packed structure; the only part of the SFrame whose 1444b169a6bSchristosformat cannot vary between versions. 1454b169a6bSchristos 1464b169a6bSchristos@example 1474b169a6bSchristostypedef struct sframe_preamble 1484b169a6bSchristos@{ 1494b169a6bSchristos uint16_t sfp_magic; 1504b169a6bSchristos uint8_t sfp_version; 1514b169a6bSchristos uint8_t sfp_flags; 1524b169a6bSchristos@} ATTRIBUTE_PACKED sframe_preamble; 1534b169a6bSchristos@end example 1544b169a6bSchristos 155*6817db7fSchristosEvery element of the SFrame preamble is naturally aligned. 156*6817db7fSchristos 1574b169a6bSchristosAll values are stored in the endianness of the target system for which the 1584b169a6bSchristosSFrame section is intended. Further details: 1594b169a6bSchristos 1604b169a6bSchristos@multitable {Offset} {@code{uint8_t sfp_version}} {The magic number for SFrame section: 0xdee2. Defined} 1614b169a6bSchristos@headitem Offset @tab Name @tab Description 1624b169a6bSchristos@item 0x00 1634b169a6bSchristos@tab @code{uint16_t sfp_magic} 1644b169a6bSchristos@tab The magic number for SFrame section: 0xdee2. Defined as a macro @code{SFRAME_MAGIC}. 1654b169a6bSchristos@tindex SFRAME_MAGIC 1664b169a6bSchristos 1674b169a6bSchristos@item 0x02 1684b169a6bSchristos@tab @code{uint8_t sfp_version} 1694b169a6bSchristos@tab The version number of this SFrame section. @xref{SFrame version}, for the 1704b169a6bSchristosset of valid values. Current version is 1714b169a6bSchristos@code{SFRAME_VERSION_1}. 1724b169a6bSchristos 1734b169a6bSchristos@item 0x03 1744b169a6bSchristos@tab @code{uint8_t sfp_flags} 1754b169a6bSchristos@tab Flags (section-wide) for this SFrame section. @xref{SFrame flags}, for the 1764b169a6bSchristosset of valid values. 1774b169a6bSchristos@end multitable 1784b169a6bSchristos 1794b169a6bSchristos@menu 1804b169a6bSchristos* SFrame endianness:: 1814b169a6bSchristos* SFrame version:: 1824b169a6bSchristos* SFrame flags:: 1834b169a6bSchristos@end menu 1844b169a6bSchristos 1854b169a6bSchristos@node SFrame endianness 1864b169a6bSchristos@subsection SFrame endianness 1874b169a6bSchristos 1884b169a6bSchristos@cindex endianness 1894b169a6bSchristosSFrame sections are stored in the target endianness of the system that consumes 1904b169a6bSchristosthem. The SFrame library (@code{libsframe}) can, however, detect whether to 1914b169a6bSchristosendian-flip an SFrame section at decode time, by inspecting the 1924b169a6bSchristos@code{sfp_magic} field in the SFrame header (If it appears as 0xe2de, 1934b169a6bSchristosendian-flipping is needed). 1944b169a6bSchristos 1954b169a6bSchristos@node SFrame version 1964b169a6bSchristos@subsection SFrame version 1974b169a6bSchristos 1984b169a6bSchristosThe version of the SFrame format can be determined by inspecting 1994b169a6bSchristos@code{sfp_version}. The following versions are currently valid: 2004b169a6bSchristos 2014b169a6bSchristos@tindex SFRAME_VERSION_1 2024b169a6bSchristos@cindex SFrame versions 203*6817db7fSchristos@multitable {SFRAME_VERSION_2} {Number} {Current version, under development.} 2044b169a6bSchristos@headitem Version @tab Number @tab Description 2054b169a6bSchristos@item @code{SFRAME_VERSION_1} 206*6817db7fSchristos@tab 1 @tab First version, obsolete. 207*6817db7fSchristos@item @code{SFRAME_VERSION_2} 208*6817db7fSchristos@tab 2 @tab Current version, under development. 2094b169a6bSchristos@end multitable 2104b169a6bSchristos 211*6817db7fSchristosThis document describes @code{SFRAME_VERSION_2}. 2124b169a6bSchristos 2134b169a6bSchristos@node SFrame flags 2144b169a6bSchristos@subsection SFrame flags 2154b169a6bSchristos@cindex SFrame flags 2164b169a6bSchristos@comment @vindex sfp_flags 2174b169a6bSchristos@comment @vindex SFrame section-wide flags 2184b169a6bSchristos@comment @subsection SFrame section-wide flags 2194b169a6bSchristos 2204b169a6bSchristosThe preamble contains bitflags in its @code{sfp_flags} field that 2214b169a6bSchristosdescribe various section-wide properties. 2224b169a6bSchristos 2234b169a6bSchristosThe following flags are currently defined. 2244b169a6bSchristos 2254b169a6bSchristos@multitable {@code{SFRAME_F_FRAME_POINTER}} {Versions} {Value} {Function Descriptor Entries} 2264b169a6bSchristos@headitem Flag @tab Versions @tab Value @tab Meaning 2274b169a6bSchristos@tindex SFRAME_F_FDE_SORTED 2284b169a6bSchristos@item @code{SFRAME_F_FDE_SORTED} @tab All @tab 0x1 @tab Function Descriptor 2294b169a6bSchristosEntries are sorted on PC. 2304b169a6bSchristos@tindex SFRAME_F_FRAME_POINTER 2314b169a6bSchristos@item @code{SFRAME_F_FRAME_POINTER} @tab All @tab 0x2 2324b169a6bSchristos@tab Functions preserve frame-pointer. 2334b169a6bSchristos@end multitable 2344b169a6bSchristos 2354b169a6bSchristosFurther flags may be added in future. 2364b169a6bSchristos 2374b169a6bSchristos@node SFrame Header 2384b169a6bSchristos@section SFrame Header 2394b169a6bSchristos@cindex SFrame header 2404b169a6bSchristos 2414b169a6bSchristosThe SFrame header is the first part of an SFrame section. It begins with the 2424b169a6bSchristosSFrame preamble. All parts of it other than the preamble 2434b169a6bSchristos(@pxref{SFrame Preamble}) can vary between SFrame file versions. It contains 2444b169a6bSchristosthings that apply to the section as a whole, and offsets to the various other 2454b169a6bSchristossub-sections defined in the format. As with the rest of the SFrame section, 2464b169a6bSchristosall values are stored in the endianness of the target system. 2474b169a6bSchristos 2484b169a6bSchristosThe two sub-sections tile the SFrame section: each section runs from the offset 2494b169a6bSchristosgiven until the start of the next section. An explicit length is given for the 2504b169a6bSchristoslast sub-section, the SFrame Frame Row Entry (SFrame FRE) sub-section. 2514b169a6bSchristos 2524b169a6bSchristos@example 2534b169a6bSchristostypedef struct sframe_header 2544b169a6bSchristos@{ 2554b169a6bSchristos sframe_preamble sfh_preamble; 2564b169a6bSchristos uint8_t sfh_abi_arch; 2574b169a6bSchristos int8_t sfh_cfa_fixed_fp_offset; 2584b169a6bSchristos int8_t sfh_cfa_fixed_ra_offset; 2594b169a6bSchristos uint8_t sfh_auxhdr_len; 2604b169a6bSchristos uint32_t sfh_num_fdes; 2614b169a6bSchristos uint32_t sfh_num_fres; 2624b169a6bSchristos uint32_t sfh_fre_len; 2634b169a6bSchristos uint32_t sfh_fdeoff; 2644b169a6bSchristos uint32_t sfh_freoff; 2654b169a6bSchristos@} ATTRIBUTE_PACKED sframe_header; 2664b169a6bSchristos@end example 2674b169a6bSchristos 268*6817db7fSchristosEvery element of the SFrame header is naturally aligned. 269*6817db7fSchristos 2704b169a6bSchristosThe sub-section offsets, namely @code{sfh_fdeoff} and @code{sfh_freoff}, in the 2714b169a6bSchristosSFrame header are relative to the @emph{end} of the SFrame header; they are 2724b169a6bSchristoseach an offset in bytes into the SFrame section where the SFrame FDE 2734b169a6bSchristossub-section and the SFrame FRE sub-section respectively start. 2744b169a6bSchristos 2754b169a6bSchristosSFrame header allows specifying explicitly the fixed offsets from CFA, if any, 2764b169a6bSchristosfrom which FP or RA may be recovered. For example, in AMD64, the stack offset 2774b169a6bSchristosof the return address is @code{CFA - 8}. Since this offset is in close 2784b169a6bSchristosvicinity with the CFA in most ABIs, @code{sfh_cfa_fixed_fp_offset} and 2794b169a6bSchristos@code{sfh_cfa_fixed_ra_offset} are limited to signed 8-bit integers. 2804b169a6bSchristos 281*6817db7fSchristosSFrame format has made some provisions for supporting more ABIs/architectures 282*6817db7fSchristosin the future. The @code{sframe_header} structure provides an unsigned 8-bit 283*6817db7fSchristosintegral field to denote the size of an auxiliary SFrame header. The 284*6817db7fSchristosauxiliary SFrame header follows right after the @code{sframe_header} 2854b169a6bSchristosstructure. As for the offset calculations, the @emph{end} of SFrame header 286*6817db7fSchristosmust be the end of the auxiliary SFrame header, if the latter is present. 2874b169a6bSchristos 288*6817db7fSchristosPutting it all together: 2894b169a6bSchristos 290*6817db7fSchristos@multitable {Offset} {@code{int8_t sfh_cfa_fixed_fp_offset}} {The number of SFrame FREs in the section.} 2914b169a6bSchristos@headitem Offset @tab Name @tab Description 2924b169a6bSchristos@item 0x00 2934b169a6bSchristos@tab @code{sframe_preamble sfh_preamble} 2944b169a6bSchristos@tab The SFrame preamble. @xref{SFrame Preamble}. 2954b169a6bSchristos 2964b169a6bSchristos@item 0x04 2974b169a6bSchristos@tab @code{uint8_t sfh_abi_arch} 2984b169a6bSchristos@tab The ABI/arch identifier. @xref{SFrame ABI/arch identifier}. 2994b169a6bSchristos 3004b169a6bSchristos@item 0x05 3014b169a6bSchristos@tab @code{int8_t sfh_cfa_fixed_fp_offset} 3024b169a6bSchristos@tab The CFA fixed FP offset, if any. 3034b169a6bSchristos 3044b169a6bSchristos@item 0x06 3054b169a6bSchristos@tab @code{int8_t sfh_cfa_fixed_ra_offset} 3064b169a6bSchristos@tab The CFA fixed RA offset, if any. 3074b169a6bSchristos 3084b169a6bSchristos@item 0x07 3094b169a6bSchristos@tab @code{uint8_t sfh_auxhdr_len} 310*6817db7fSchristos@tab Size in bytes of the auxiliary header that follows the 3114b169a6bSchristos@code{sframe_header} structure. 3124b169a6bSchristos 3134b169a6bSchristos@item 0x08 3144b169a6bSchristos@tab @code{uint32_t sfh_num_fdes} 3154b169a6bSchristos@tab The number of SFrame FDEs in the section. 3164b169a6bSchristos 3174b169a6bSchristos@item 0xc 3184b169a6bSchristos@tab @code{uint32_t sfh_num_fres} 3194b169a6bSchristos@tab The number of SFrame FREs in the section. 3204b169a6bSchristos 3214b169a6bSchristos@item 0x10 3224b169a6bSchristos@tab @code{uint32_t sfh_fre_len} 3234b169a6bSchristos@tab The length in bytes of the SFrame FRE sub-section. 3244b169a6bSchristos 3254b169a6bSchristos@item 0x14 3264b169a6bSchristos@tab @code{uint32_t sfh_fdeoff} 3274b169a6bSchristos@tab The offset in bytes of the SFrame FDE sub-section. This sub-section 3284b169a6bSchristoscontains @code{sfh_num_fdes} number of fixed-length array elements. The array 3294b169a6bSchristoselement is of type SFrame function desciptor entry, each providing a 3304b169a6bSchristoshigh-level function description for backtracing. 3314b169a6bSchristos@xref{SFrame Function Descriptor Entries}. 3324b169a6bSchristos 3334b169a6bSchristos@item 0x18 3344b169a6bSchristos@tab @code{uint32_t sfh_freoff} 3354b169a6bSchristos@tab The offset in bytes of the SFrame FRE sub-section, the core of the SFrame 336*6817db7fSchristossection, which describes the stack trace information using variable-length array 3374b169a6bSchristoselements. @xref{SFrame Frame Row Entries}. 3384b169a6bSchristos 3394b169a6bSchristos@end multitable 3404b169a6bSchristos 3414b169a6bSchristos@menu 3424b169a6bSchristos* SFrame ABI/arch identifier:: 3434b169a6bSchristos@end menu 3444b169a6bSchristos 3454b169a6bSchristos@node SFrame ABI/arch identifier 3464b169a6bSchristos@subsection SFrame ABI/arch identifier 3474b169a6bSchristos@cindex SFrame ABI/arch identifier 3484b169a6bSchristos 3494b169a6bSchristosSFrame header identifies the ABI/arch of the target system for which the 350*6817db7fSchristosexecutable and hence, the stack trace information contained in the SFrame 351*6817db7fSchristossection, is intended. There are currently three identifiable ABI/arch values 352*6817db7fSchristosin the format. 3534b169a6bSchristos 3544b169a6bSchristos@multitable {SFRAME_ABI_AARCH64_ENDIAN_LITTLE} {Value} {@code{AARCH64 little-endian}} 3554b169a6bSchristos@headitem ABI/arch Identifier @tab Value @tab Description 3564b169a6bSchristos 3574b169a6bSchristos@tindex SFRAME_ABI_AARCH64_ENDIAN_BIG 3584b169a6bSchristos@item @code{SFRAME_ABI_AARCH64_ENDIAN_BIG} 3594b169a6bSchristos@tab 1 @tab AARCH64 big-endian 3604b169a6bSchristos 3614b169a6bSchristos@tindex SFRAME_ABI_AARCH64_ENDIAN_LITTLE 3624b169a6bSchristos@item @code{SFRAME_ABI_AARCH64_ENDIAN_LITTLE} 3634b169a6bSchristos@tab 2 @tab AARCH64 little-endian 3644b169a6bSchristos 3654b169a6bSchristos@tindex SFRAME_ABI_AMD64_ENDIAN_LITTLE 3664b169a6bSchristos@item @code{SFRAME_ABI_AMD64_ENDIAN_LITTLE} 3674b169a6bSchristos@tab 3 @tab AMD64 little-endian 3684b169a6bSchristos 3694b169a6bSchristos@end multitable 3704b169a6bSchristos 3714b169a6bSchristosThe presence of an explicit identification of ABI/arch in SFrame may allow 372*6817db7fSchristosstack trace generators to make certain ABI-specific decisions. 3734b169a6bSchristos 3744b169a6bSchristos@node SFrame Function Descriptor Entries 3754b169a6bSchristos@section SFrame FDE 3764b169a6bSchristos@cindex SFrame FDE 3774b169a6bSchristos 3784b169a6bSchristosThe SFrame Function Descriptor Entry sub-section is a sorted array of 3794b169a6bSchristosfixed-length SFrame function descriptor entries (SFrame FDEs). Each SFrame FDE 380*6817db7fSchristosis a packed structure which contains information to describe a function's stack 381*6817db7fSchristostrace information at a high-level. 3824b169a6bSchristos 3834b169a6bSchristos@example 3844b169a6bSchristostypedef struct sframe_func_desc_entry 3854b169a6bSchristos@{ 3864b169a6bSchristos int32_t sfde_func_start_address; 3874b169a6bSchristos uint32_t sfde_func_size; 3884b169a6bSchristos uint32_t sfde_func_start_fre_off; 3894b169a6bSchristos uint32_t sfde_func_num_fres; 3904b169a6bSchristos uint8_t sfde_func_info; 391*6817db7fSchristos uint8_t sfde_func_rep_size; 392*6817db7fSchristos uint16_t sfde_func_padding2; 3934b169a6bSchristos@} ATTRIBUTE_PACKED sframe_func_desc_entry; 3944b169a6bSchristos@end example 3954b169a6bSchristos 396*6817db7fSchristosEvery element of the SFrame function descriptor entry is naturally aligned. 397*6817db7fSchristos 3984b169a6bSchristos@code{sfde_func_start_fre_off} is the offset to the first SFrame FRE for the 3994b169a6bSchristosfunction. This offset is relative to the @emph{end of the SFrame FDE} 4004b169a6bSchristossub-section (unlike the offsets in the SFrame header, which are relative to the 4014b169a6bSchristos@emph{end} of the SFrame header). 4024b169a6bSchristos 4034b169a6bSchristos@code{sfde_func_info} is the "info word", containing information on the FRE 4044b169a6bSchristostype and the FDE type for the function @xref{The SFrame FDE info word}. 4054b169a6bSchristos 4064b169a6bSchristosFollowing table describes each component of the SFrame FDE structure: 4074b169a6bSchristos 408*6817db7fSchristos@multitable {Offset} {@code{uint32_t sfde_func_start_fre_off}} {Signed 32-bit integral field denoting the} 4094b169a6bSchristos@headitem Offset @tab Name @tab Description 4104b169a6bSchristos@item 0x00 4114b169a6bSchristos@tab @code{int32_t sfde_func_start_address} 4124b169a6bSchristos@tab Signed 32-bit integral field denoting the virtual memory address of the 4134b169a6bSchristosdescribed function. 4144b169a6bSchristos 4154b169a6bSchristos@item 0x04 4164b169a6bSchristos@tab @code{uint32_t sfde_func_size} 4174b169a6bSchristos@tab Unsigned 32-bit integral field specifying the size of the function in 4184b169a6bSchristosbytes. 4194b169a6bSchristos 4204b169a6bSchristos@item 0x08 4214b169a6bSchristos@tab @code{uint32_t sfde_func_start_fre_off} 4224b169a6bSchristos@tab Unsigned 32-bit integral field specifying the offset in bytes of the 4234b169a6bSchristosfunction's first SFrame FRE in the SFrame section. 4244b169a6bSchristos 4254b169a6bSchristos@item 0x0c 4264b169a6bSchristos@tab @code{uint32_t sfde_func_num_fres} 4274b169a6bSchristos@tab Unsigned 32-bit integral field specifying the total number of SFrame FREs 4284b169a6bSchristosused for the function. 4294b169a6bSchristos 4304b169a6bSchristos@item 0x10 4314b169a6bSchristos@tab @code{uint8_t sfde_func_info} 432*6817db7fSchristos@tab Unsigned 8-bit integral field specifying the SFrame FDE info word. 433*6817db7fSchristos@xref{The SFrame FDE info word}. 434*6817db7fSchristos 435*6817db7fSchristos@item 0x11 436*6817db7fSchristos@tab @code{uint8_t sfde_func_rep_size} 437*6817db7fSchristos@tab Unsigned 8-bit integral field specifying the size of the repetitive code 438*6817db7fSchristosblock for which an SFrame FDE of type SFRAME_FDE_TYPE_PCMASK is used. For 439*6817db7fSchristosexample, in AMD64, the size of a pltN entry is 16 bytes. 440*6817db7fSchristos 441*6817db7fSchristos@item 0x12 442*6817db7fSchristos@tab @code{uint16_t sfde_func_padding2} 443*6817db7fSchristos@tab Padding of 2 bytes. Currently unused bytes. 4444b169a6bSchristos 4454b169a6bSchristos@end multitable 4464b169a6bSchristos 4474b169a6bSchristos@menu 4484b169a6bSchristos* The SFrame FDE info word:: 4494b169a6bSchristos* The SFrame FDE types:: 4504b169a6bSchristos* The SFrame FRE types:: 4514b169a6bSchristos@end menu 4524b169a6bSchristos 4534b169a6bSchristos@cindex The SFrame FDE info word 4544b169a6bSchristos@node The SFrame FDE info word 4554b169a6bSchristos@subsection The SFrame FDE info word 4564b169a6bSchristos 4574b169a6bSchristosThe info word is a bitfield split into three parts. From MSB to LSB: 4584b169a6bSchristos 459*6817db7fSchristos@multitable {Bit offset} {@code{pauth_key}} {Specify which key is used for signing the return addresses} 4604b169a6bSchristos@headitem Bit offset @tab Name @tab Description 461*6817db7fSchristos@item 7--6 4624b169a6bSchristos@tab @code{unused} 4634b169a6bSchristos@tab Unused bits. 4644b169a6bSchristos 465*6817db7fSchristos@item 5 466*6817db7fSchristos@tab @code{pauth_key} 467*6817db7fSchristos@tab Specify which key is used for signing the return addresses in the SFrame 468*6817db7fSchristosFDE. Two possible values: @* 469*6817db7fSchristosSFRAME_AARCH64_PAUTH_KEY_A (0), or @* 470*6817db7fSchristosSFRAME_AARCH64_PAUTH_KEY_B (1). 471*6817db7fSchristos 4724b169a6bSchristos@item 4 4734b169a6bSchristos@tab @code{fdetype} 474*6817db7fSchristos@tab Specify the SFrame FDE type. Two possible values: @* 475*6817db7fSchristosSFRAME_FDE_TYPE_PCMASK (1), or @* 476*6817db7fSchristosSFRAME_FDE_TYPE_PCINC (0). @* 477*6817db7fSchristos@xref{The SFrame FDE types}. 4784b169a6bSchristos 4794b169a6bSchristos@item 0--3 4804b169a6bSchristos@tab @code{fretype} 4814b169a6bSchristos@tab Choice of three SFrame FRE types. @xref{The SFrame FRE types}. 4824b169a6bSchristos@end multitable 4834b169a6bSchristos 4844b169a6bSchristos@node The SFrame FDE types 4854b169a6bSchristos@subsection The SFrame FDE types 4864b169a6bSchristos@tindex SFRAME_FDE_TYPE_PCMASK 4874b169a6bSchristos@tindex SFRAME_FDE_TYPE_PCINC 4884b169a6bSchristos 4894b169a6bSchristosSFrame format defines two types of FDE entries. The choice of which SFrame FDE 4904b169a6bSchristostype to use is made based on the instruction patterns in the relevant program 4914b169a6bSchristosstub. 4924b169a6bSchristos 4934b169a6bSchristosAn SFrame FDE of type @code{SFRAME_FDE_TYPE_PCINC} is an indication that the PCs in the 4944b169a6bSchristosFREs should be treated as increments in bytes. This is used fo the the bulk of 4954b169a6bSchristosthe executable code of a program, which contains instructions with no specific 4964b169a6bSchristospattern. 4974b169a6bSchristos 4984b169a6bSchristosIn contrast, an SFrame FDE of type @code{SFRAME_FDE_TYPE_PCMASK} is an 4994b169a6bSchristosindication that the PCs in the FREs should be treated as masks. This type is 5004b169a6bSchristosuseful for the cases where a small pattern of instructions in a program stub is 5014b169a6bSchristosused repeatedly for a specific functionality. Typical usecases are pltN 5024b169a6bSchristosentries and trampolines. 5034b169a6bSchristos 504*6817db7fSchristos@multitable {SFRAME_FDE_TYPE_PCMASK} {Value} {Unwinders perform a Unwinders perform a} 5054b169a6bSchristos@headitem Name of SFrame FDE type @tab Value @tab Description 5064b169a6bSchristos 5074b169a6bSchristos@item SFRAME_FDE_TYPE_PCINC 508*6817db7fSchristos@tab 0 @tab Unwinders perform a @* 509*6817db7fSchristos(PC >= FRE_START_ADDR) to look up a matching FRE. 5104b169a6bSchristos 5114b169a6bSchristos@item SFRAME_FDE_TYPE_PCMASK 512*6817db7fSchristos@tab 1 @tab Unwinders perform a @* 513*6817db7fSchristos(PC % REP_BLOCK_SIZE @* 514*6817db7fSchristos >= FRE_START_ADDR) 515*6817db7fSchristosto look up a matching FRE. REP_BLOCK_SIZE is the size in bytes of the 516*6817db7fSchristosrepeating block of program instructions. 5174b169a6bSchristos 5184b169a6bSchristos@end multitable 5194b169a6bSchristos 5204b169a6bSchristos@node The SFrame FRE types 5214b169a6bSchristos@subsection The SFrame FRE types 5224b169a6bSchristos 5234b169a6bSchristosA real world application can have functions of size big and small. SFrame 524*6817db7fSchristosformat defines three types of SFrame FRE entries to represent the stack trace 5254b169a6bSchristosinformation for such a variety of function sizes. These representations vary 5264b169a6bSchristosin the number of bits needed to encode the start address offset in the SFrame 5274b169a6bSchristosFRE. 5284b169a6bSchristos 5294b169a6bSchristosThe following constants are defined and used to identify the SFrame FRE types: 5304b169a6bSchristos 5314b169a6bSchristos@multitable {SFRAME_FRE_TYPE_ADDR1} {@code{Value}} {The start address offset of FRE is an} 5324b169a6bSchristos@headitem Name @tab Value @tab Description 5334b169a6bSchristos 5344b169a6bSchristos@tindex SFRAME_FRE_TYPE_ADDR1 5354b169a6bSchristos@item @code{SFRAME_FRE_TYPE_ADDR1} 5364b169a6bSchristos@tab 0 5374b169a6bSchristos@tab The start address offset (in bytes) of the SFrame FRE is an unsigned 5384b169a6bSchristos8-bit value. 5394b169a6bSchristos 5404b169a6bSchristos@tindex SFRAME_FRE_TYPE_ADDR2 5414b169a6bSchristos@item @code{SFRAME_FRE_TYPE_ADDR2} 5424b169a6bSchristos@tab 1 5434b169a6bSchristos@tab The start address offset (in bytes) of the SFrame FRE is an unsigned 5444b169a6bSchristos16-bit value. 5454b169a6bSchristos 5464b169a6bSchristos@tindex SFRAME_FRE_TYPE_ADDR4 5474b169a6bSchristos@item @code{SFRAME_FRE_TYPE_ADDR4} 5484b169a6bSchristos@tab 2 5494b169a6bSchristos@tab The start address offset (in bytes) of the SFrame FRE is an unsigned 5504b169a6bSchristos32-bit value. 5514b169a6bSchristos@end multitable 5524b169a6bSchristos 553*6817db7fSchristosA single function must use the same type of SFrame FRE throughout. An 554*6817db7fSchristosidentifier to reflect the chosen SFrame FRE type is stored in the 555*6817db7fSchristos@xref{The SFrame FDE info word}. 5564b169a6bSchristos 5574b169a6bSchristos@node SFrame Frame Row Entries 5584b169a6bSchristos@section SFrame FRE 5594b169a6bSchristos@cindex SFrame FRE 5604b169a6bSchristos 561*6817db7fSchristosThe SFrame Frame Row Entry sub-section contains the core of the stack trace 5624b169a6bSchristosinformation. 5634b169a6bSchristos 564*6817db7fSchristosAn SFrame Frame Row Entry is a self-sufficient record containing SFrame stack 565*6817db7fSchristostrace information for a range of contiguous addresses, starting at the 566*6817db7fSchristosspecified offset from the start of the function. Each SFrame Frame Row Entry 567*6817db7fSchristosis followed by S*N bytes, where: 5684b169a6bSchristos 5694b169a6bSchristos@itemize @minus 5704b169a6bSchristos@item 5714b169a6bSchristos@code{S} is the size of the stack frame offset for the FRE, and 5724b169a6bSchristos@item 5734b169a6bSchristos@code{N} is the number of stack frame offsets in the FRE 5744b169a6bSchristos@end itemize 5754b169a6bSchristos 5764b169a6bSchristosThe stack offsets, following the FRE, are interpreted in order as follows: 5774b169a6bSchristos 5784b169a6bSchristos@itemize @minus 5794b169a6bSchristos@item 5804b169a6bSchristosThe first offset is always used to locate the CFA, by interpreting it as: 5814b169a6bSchristosCFA = @code{BASE_REG} + offset1. 5824b169a6bSchristos@item 5834b169a6bSchristosIf RA is being tracked, the second offset is always used to locate the RA, by 5844b169a6bSchristosinterpreting it as: RA = CFA + offset2. If RA is @emph{not} being tracked 5854b169a6bSchristos@emph{and} FP is being tracked, the second offset will be used to locate the 5864b169a6bSchristosFP, by interpreting it as: FP = CFA + offset2. 5874b169a6bSchristos@item 5884b169a6bSchristosIf both RA and FP are being tracked, the third offset will be used to locate 5894b169a6bSchristosthe FP, by interpreting it as FP = CFA + offset3. 5904b169a6bSchristos@end itemize 5914b169a6bSchristos 5924b169a6bSchristosThe entities @code{S}, @code{N} and @code{BASE_REG} are identified using the 5934b169a6bSchristosSFrame FRE info word, a.k.a. the @code{sframe_fre_info} 5944b169a6bSchristos@xref{The SFrame FRE info word}. 5954b169a6bSchristos 5964b169a6bSchristosFollowing are the definitions of the allowed SFrame FRE: 5974b169a6bSchristos 5984b169a6bSchristos@example 5994b169a6bSchristostypedef struct sframe_frame_row_entry_addr1 6004b169a6bSchristos@{ 6014b169a6bSchristos uint8_t sfre_start_address; 6024b169a6bSchristos sframe_fre_info sfre_info; 6034b169a6bSchristos@} ATTRIBUTE_PACKED sframe_frame_row_entry_addr1; 6044b169a6bSchristos@end example 6054b169a6bSchristos 6064b169a6bSchristos@example 6074b169a6bSchristostypedef struct sframe_frame_row_entry_addr2 6084b169a6bSchristos@{ 6094b169a6bSchristos uint16_t sfre_start_address; 6104b169a6bSchristos sframe_fre_info sfre_info; 6114b169a6bSchristos@} ATTRIBUTE_PACKED sframe_frame_row_entry_addr2; 6124b169a6bSchristos@end example 6134b169a6bSchristos 6144b169a6bSchristos@example 6154b169a6bSchristostypedef struct sframe_frame_row_entry_addr4 6164b169a6bSchristos@{ 6174b169a6bSchristos uint32_t sfre_start_address; 6184b169a6bSchristos sframe_fre_info sfre_info; 6194b169a6bSchristos@} ATTRIBUTE_PACKED sframe_frame_row_entry_addr4; 6204b169a6bSchristos@end example 6214b169a6bSchristos 622*6817db7fSchristosFor ensuring compactness, SFrame frame row entries are stored unaligned on 623*6817db7fSchristosdisk. Appropriate mechanisms need to be employed, as necessary, by the 624*6817db7fSchristosserializing and deserializing entities, if unaligned accesses need to be 625*6817db7fSchristosavoided. 626*6817db7fSchristos 6274b169a6bSchristos@code{sfre_start_address} is an unsigned 8-bit/16-bit/32-bit integral field 6284b169a6bSchristosidentifies the start address of the range of program counters, for which the 6294b169a6bSchristosSFrame FRE applies. The value encoded in the @code{sfre_start_address} field 6304b169a6bSchristosis the offset in bytes of the start address of the SFrame FRE, from the start 6314b169a6bSchristosaddress of the function. 6324b169a6bSchristos 6334b169a6bSchristosFurther FRE types may be added in future. 6344b169a6bSchristos 6354b169a6bSchristos@menu 6364b169a6bSchristos* The SFrame FRE info word:: 6374b169a6bSchristos@end menu 6384b169a6bSchristos 6394b169a6bSchristos@cindex The SFrame FRE info word 6404b169a6bSchristos@node The SFrame FRE info word 6414b169a6bSchristos@subsection The SFrame FRE info word 6424b169a6bSchristos 6434b169a6bSchristosThe SFrame FRE info word is a bitfield split into four parts. From MSB to LSB: 6444b169a6bSchristos 6454b169a6bSchristos@multitable {Bit offset} {@code{fre_cfa_base_reg_id}} {Size of stack offsets in bytes. Valid values} 6464b169a6bSchristos@headitem Bit offset @tab Name @tab Description 6474b169a6bSchristos@item 7 6484b169a6bSchristos@tab @code{fre_mangled_ra_p} 6494b169a6bSchristos@tab Indicate whether the return address is mangled with any authorization bits (signed RA). 6504b169a6bSchristos 6514b169a6bSchristos@item 5-6 6524b169a6bSchristos@tab @code{fre_offset_size} 653*6817db7fSchristos@tab Size of stack offsets in bytes. Valid values are: @* 654*6817db7fSchristosSFRAME_FRE_OFFSET_1B, @* 655*6817db7fSchristosSFRAME_FRE_OFFSET_2B, and @* 656*6817db7fSchristosSFRAME_FRE_OFFSET_4B. 6574b169a6bSchristos 6584b169a6bSchristos@item 1-4 6594b169a6bSchristos@tab @code{fre_offset_count} 6604b169a6bSchristos@tab A value of upto 3 is allowed to track all three of CFA, FP and RA. 6614b169a6bSchristos 6624b169a6bSchristos@item 0 6634b169a6bSchristos@tab @code{fre_cfa_base_reg_id} 6644b169a6bSchristos@tab Distinguish between SP or FP based CFA recovery. 6654b169a6bSchristos 6664b169a6bSchristos@end multitable 6674b169a6bSchristos 6684b169a6bSchristos@multitable {SFRAME_FRE_OFFSET_4B} {@code{Value}} {All stack offsets following the fixed-length} 6694b169a6bSchristos@headitem Name @tab Value @tab Description 6704b169a6bSchristos 6714b169a6bSchristos@tindex SFRAME_FRE_OFFSET_1B 6724b169a6bSchristos@item @code{SFRAME_FRE_OFFSET_1B} 6734b169a6bSchristos@tab 0 6744b169a6bSchristos@tab All stack offsets following the fixed-length FRE structure are 1 byte 6754b169a6bSchristoslong. 6764b169a6bSchristos 6774b169a6bSchristos@tindex SFRAME_FRE_OFFSET_2B 6784b169a6bSchristos@item @code{SFRAME_FRE_OFFSET_2B} 6794b169a6bSchristos@tab 1 6804b169a6bSchristos@tab All stack offsets following the fixed-length FRE structure are 2 bytes 6814b169a6bSchristoslong. 6824b169a6bSchristos 6834b169a6bSchristos@tindex SFRAME_FRE_OFFSET_4B 6844b169a6bSchristos@item @code{SFRAME_FRE_OFFSET_4B} 6854b169a6bSchristos@tab 2 6864b169a6bSchristos@tab All stack offsets following the fixed-length FRE structure are 4 bytes 6874b169a6bSchristoslong. 6884b169a6bSchristos 6894b169a6bSchristos@end multitable 6904b169a6bSchristos 6914b169a6bSchristos@node Index 6924b169a6bSchristos@unnumbered Index 6934b169a6bSchristos 6944b169a6bSchristos@syncodeindex tp cp 6954b169a6bSchristos@printindex cp 6964b169a6bSchristos 6974b169a6bSchristos@bye 698