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