1  /* coreout.h - Declarations and definitions related to
       2     BPF Compile Once - Run Everywhere (CO-RE) support.
       3     Copyright (C) 2021-2023 Free Software Foundation, Inc.
       4  
       5     This file is part of GCC.
       6  
       7     GCC is free software; you can redistribute it and/or modify it
       8     under the terms of the GNU General Public License as published by
       9     the Free Software Foundation; either version 3, or (at your option)
      10     any later version.
      11  
      12     GCC is distributed in the hope that it will be useful, but
      13     WITHOUT ANY WARRANTY; without even the implied warranty of
      14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15     General Public License for more details.
      16  
      17     You should have received a copy of the GNU General Public License
      18     along with GCC; see the file COPYING3.  If not see
      19     <http://www.gnu.org/licenses/>.  */
      20  
      21  
      22  #ifndef __COREOUT_H
      23  #define __COREOUT_H
      24  
      25  #include <stdint.h>
      26  
      27  #ifdef	__cplusplus
      28  extern "C"
      29  {
      30  #endif
      31  
      32  /* .BTF.ext information.  */
      33  
      34  struct btf_ext_section_header
      35  {
      36    uint32_t sec_name_off;
      37    uint32_t num_records;
      38  };
      39  
      40  /* A funcinfo record, in the .BTF.ext funcinfo section.  */
      41  struct btf_ext_funcinfo
      42  {
      43    uint32_t insn_off; /* Offset of the first instruction of the function.  */
      44    uint32_t type;     /* Type ID of a BTF_KIND_FUNC type.  */
      45  };
      46  
      47  /* A lineinfo record, in the .BTF.ext lineinfo section.  */
      48  struct btf_ext_lineinfo
      49  {
      50    uint32_t insn_off;      /* Offset of the instruction.  */
      51    uint32_t file_name_off; /* Offset of file name in BTF string table.  */
      52    uint32_t line_off;      /* Offset of source line in BTF string table.  */
      53    uint32_t line_col;      /* Line number (bits 31-11) and column (11-0).  */
      54  };
      55  
      56  enum btf_core_reloc_kind
      57  {
      58    BPF_RELO_FIELD_BYTE_OFFSET = 0,
      59    BPF_RELO_FIELD_BYTE_SIZE = 1,
      60    BPF_RELO_FIELD_EXISTS = 2,
      61    BPF_RELO_FIELD_SIGNED = 3,
      62    BPF_RELO_FIELD_LSHIFT_U64 = 4,
      63    BPF_RELO_FIELD_RSHIFT_U64 = 5,
      64    BPF_RELO_TYPE_ID_LOCAL = 6,
      65    BPF_RELO_TYPE_ID_TARGET = 7,
      66    BPF_RELO_TYPE_EXISTS = 8,
      67    BPF_RELO_TYPE_SIZE = 9,
      68    BPF_RELO_ENUMVAL_EXISTS = 10,
      69    BPF_RELO_ENUMVAL_VALUE = 11
      70  };
      71  
      72  struct btf_ext_reloc
      73  {
      74    uint32_t insn_off;       /* Offset of instruction to be patched. A
      75  			      section-relative label at compile time.  */
      76    uint32_t type_id;        /* Type ID of the outermost containing entity, e.g.
      77  			      the containing structure.  */
      78    uint32_t access_str_off; /* Offset of CO-RE accessor string in .BTF strings
      79  			      section.  */
      80    uint32_t kind;           /* An enum btf_core_reloc_kind. Note that it always
      81  			      takes 32 bits.  */
      82  };
      83  
      84  struct btf_ext_header
      85  {
      86    uint16_t magic;		/* Magic number (BTF_MAGIC).  */
      87    uint8_t  version;		/* Data format version (BTF_VERSION).  */
      88    uint8_t  flags;		/* Flags. Currently unused.  */
      89    uint32_t hdr_len;		/* Length of this header in bytes.  */
      90  
      91    /* Following offsets are relative to the end of this header, in bytes.
      92       Following lengths are in bytes.  */
      93    uint32_t func_info_off;	/* Offset of funcinfo section.  */
      94    uint32_t func_info_len;	/* Length of funcinfo section.  */
      95    uint32_t line_info_off;	/* Offset of lineinfo section.  */
      96    uint32_t line_info_len;	/* Length of lineinfo section.  */
      97  
      98    uint32_t core_relo_off;	/* Offset of CO-RE relocation section.  */
      99    uint32_t core_relo_len;	/* Length of CO-RE relocation section.  */
     100  };
     101  
     102  extern void btf_ext_init (void);
     103  extern void btf_ext_output (void);
     104  
     105  extern void bpf_core_reloc_add (const tree, const char *, vec<unsigned int> *,
     106  				rtx_code_label *, enum btf_core_reloc_kind);
     107  extern int bpf_core_get_sou_member_index (ctf_container_ref, const tree);
     108  
     109  #ifdef	__cplusplus
     110  }
     111  #endif
     112  
     113  #endif /* __COREOUT_H */