1 /* gen-sframe.h - Support for generating SFrame. 2 Copyright (C) 2022-2025 Free Software Foundation, Inc. 3 4 This file is part of GAS, the GNU Assembler. 5 6 GAS is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3, or (at your option) 9 any later version. 10 11 GAS is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GAS; see the file COPYING. If not, write to the Free 18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 19 02110-1301, USA. */ 20 21 #ifndef GENSFRAME_H 22 #define GENSFRAME_H 23 24 #define SFRAME_FRE_ELEM_LOC_REG 0 25 #define SFRAME_FRE_ELEM_LOC_STACK 1 26 27 #define SFRAME_FRE_BASE_REG_INVAL ((unsigned int)-1) 28 29 /* SFrame Frame Row Entry (FRE). 30 31 A frame row entry is a slice of the frame and can be valid for a set of 32 program instructions. It keeps all information needed to retrieve the CFA 33 and the Return Address (RA) if tracked. 34 35 A frame row entry effectively stores accumulated information gathered by 36 interpreting multiple CFI instructions. More precisely, it is a 37 self-sufficient record in its own right. Only the subset of information 38 necessary for unwinding is stored: Given a PC, how to retrieve the CFA and 39 the RA. 40 */ 41 42 struct sframe_row_entry 43 { 44 /* A linked list. */ 45 struct sframe_row_entry *next; 46 47 /* Start and end of the frame row entry. */ 48 symbolS *pc_begin; 49 symbolS *pc_end; 50 51 /* A frame row entry is a merge candidate if new information can be updated 52 on it. */ 53 bool merge_candidate; 54 55 /* Whether the return address is mangled with pauth code. */ 56 bool mangled_ra_p; 57 58 /* Track CFA base (architectural) register ID. */ 59 unsigned int cfa_base_reg; 60 /* Offset from the CFA base register for recovering CFA. */ 61 offsetT cfa_offset; 62 63 /* Track the other register used as base register for CFA. Specify whether 64 it is in register or memory. */ 65 unsigned int base_reg; 66 unsigned int bp_loc; 67 /* If the other register is stashed on stack, note the offset. */ 68 offsetT bp_offset; 69 70 /* Track RA location. Specify whether it is in register or memory. */ 71 unsigned int ra_loc; 72 /* If RA is stashed on stack, note the offset. */ 73 offsetT ra_offset; 74 }; 75 76 /* SFrame Function Description Entry. */ 77 78 struct sframe_func_entry 79 { 80 /* A linked list. */ 81 struct sframe_func_entry *next; 82 83 /* Reference to the FDE created from CFI in dw2gencfi. Some information 84 like the start_address and the segment is made available via this 85 member. */ 86 const struct fde_entry *dw_fde; 87 88 /* Reference to the first FRE for this function. */ 89 struct sframe_row_entry *sframe_fres; 90 91 unsigned int num_fres; 92 }; 93 94 /* SFrame Function Description Entry Translation Context. */ 95 96 struct sframe_xlate_ctx 97 { 98 /* Reference to the FDE created from CFI in dw2gencfi. Information 99 like the FDE start_address, end_address and the cfi insns are 100 made available via this member. */ 101 const struct fde_entry *dw_fde; 102 103 /* List of FREs in the current FDE translation context, bounded by first_fre 104 and last_fre. */ 105 106 /* Keep track of the first FRE for the purpose of restoring state if 107 necessary (for DW_CFA_restore). */ 108 struct sframe_row_entry *first_fre; 109 /* The last FRE in the list. */ 110 struct sframe_row_entry *last_fre; 111 112 /* The current FRE under construction. */ 113 struct sframe_row_entry *cur_fre; 114 /* Remember FRE for an eventual restore. */ 115 struct sframe_row_entry *remember_fre; 116 117 unsigned num_xlate_fres; 118 }; 119 120 /* Error codes for SFrame translation context. */ 121 enum sframe_xlate_err 122 { 123 /* Success. */ 124 SFRAME_XLATE_OK = 0, 125 /* Error. */ 126 SFRAME_XLATE_ERROR = 1, 127 /* Detailed error codes. */ 128 SFRAME_XLATE_ERR_INVAL = -1, 129 SFRAME_XLATE_ERR_NOTREPRESENTED = -2, 130 }; 131 132 /* Callback to create the abi/arch identifier for SFrame section. */ 133 134 unsigned char 135 sframe_get_abi_arch_callback (const char *target_arch, 136 int big_endian_p); 137 138 /* SFrame version specific operations structure. */ 139 140 struct sframe_version_ops 141 { 142 unsigned char format_version; /* SFrame format version. */ 143 /* set SFrame FRE info. */ 144 unsigned char (*set_fre_info) (unsigned int, unsigned int, unsigned int, 145 bool); 146 /* set SFrame Func info. */ 147 unsigned char (*set_func_info) (unsigned int, unsigned int, unsigned int); 148 }; 149 150 /* Generate SFrame stack trace info and prepare contents for the output. 151 outout_sframe () is called at the end of file. */ 152 153 extern void output_sframe (segT sframe_seg); 154 155 #endif /* GENSFRAME_H */ 156