llvm/llvm/include/llvm/DebugInfo/BTF/BTF.h

//===-- BTF.h --------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the layout of .BTF and .BTF.ext ELF sections.
///
/// The binary layout for .BTF section:
///   struct Header
///   Type and Str subsections
/// The Type subsection is a collection of types with type id starting with 1.
/// The Str subsection is simply a collection of strings.
///
/// The binary layout for .BTF.ext section:
///   struct ExtHeader
///   FuncInfo, LineInfo, FieldReloc and ExternReloc subsections
/// The FuncInfo subsection is defined as below:
///   BTFFuncInfo Size
///   struct SecFuncInfo for ELF section #1
///   A number of struct BPFFuncInfo for ELF section #1
///   struct SecFuncInfo for ELF section #2
///   A number of struct BPFFuncInfo for ELF section #2
///   ...
/// The LineInfo subsection is defined as below:
///   BPFLineInfo Size
///   struct SecLineInfo for ELF section #1
///   A number of struct BPFLineInfo for ELF section #1
///   struct SecLineInfo for ELF section #2
///   A number of struct BPFLineInfo for ELF section #2
///   ...
/// The FieldReloc subsection is defined as below:
///   BPFFieldReloc Size
///   struct SecFieldReloc for ELF section #1
///   A number of struct BPFFieldReloc for ELF section #1
///   struct SecFieldReloc for ELF section #2
///   A number of struct BPFFieldReloc for ELF section #2
///   ...
///
/// The section formats are also defined at
///    https://github.com/torvalds/linux/blob/master/include/uapi/linux/btf.h
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_BPF_BTF_H
#define LLVM_LIB_TARGET_BPF_BTF_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/TrailingObjects.h"

namespace llvm {
namespace BTF {

enum : uint32_t {};

/// Sizes in bytes of various things in the BTF format.
enum {};

/// The .BTF section header definition.
struct Header {};

enum : uint32_t {};

enum TypeKinds : uint8_t {};

// Constants for CommonType::Info field.
constexpr uint32_t FWD_UNION_FLAG =;
constexpr uint32_t ENUM_SIGNED_FLAG =;

/// The BTF common type definition. Different kinds may have
/// additional information after this structure data.
struct CommonType {};

// For some specific BTF_KIND, "struct CommonType" is immediately
// followed by extra data.

// BTF_KIND_INT is followed by a u32 and the following
// is the 32 bits arrangement:
// BTF_INT_ENCODING(VAL) : (((VAL) & 0x0f000000) >> 24)
// BTF_INT_OFFSET(VAL) : (((VAL & 0x00ff0000)) >> 16)
// BTF_INT_BITS(VAL) : ((VAL) & 0x000000ff)

/// Attributes stored in the INT_ENCODING.
enum : uint8_t {};

/// BTF_KIND_ENUM is followed by multiple "struct BTFEnum".
/// The exact number of btf_enum is stored in the vlen (of the
/// info in "struct CommonType").
struct BTFEnum {};

/// BTF_KIND_ENUM64 is followed by multiple "struct BTFEnum64".
/// The exact number of BTFEnum64 is stored in the vlen (of the
/// info in "struct CommonType").
struct BTFEnum64 {};

/// BTF_KIND_ARRAY is followed by one "struct BTFArray".
struct BTFArray {};

/// BTF_KIND_STRUCT and BTF_KIND_UNION are followed
/// by multiple "struct BTFMember".  The exact number
/// of BTFMember is stored in the vlen (of the info in
/// "struct CommonType").
///
/// If the struct/union contains any bitfield member,
/// the Offset below represents BitOffset (bits 0 - 23)
/// and BitFieldSize(bits 24 - 31) with BitFieldSize = 0
/// for non bitfield members. Otherwise, the Offset
/// represents the BitOffset.
struct BTFMember {};

/// BTF_KIND_FUNC_PROTO are followed by multiple "struct BTFParam".
/// The exist number of BTFParam is stored in the vlen (of the info
/// in "struct CommonType").
struct BTFParam {};

/// BTF_KIND_FUNC can be global, static or extern.
enum : uint8_t {};

/// Variable scoping information.
enum : uint8_t {};

/// BTF_KIND_DATASEC are followed by multiple "struct BTFDataSecVar".
/// The exist number of BTFDataSec is stored in the vlen (of the info
/// in "struct CommonType").
struct BTFDataSec {};

/// The .BTF.ext section header definition.
struct ExtHeader {};

/// Specifying one function info.
struct BPFFuncInfo {};

/// Specifying function info's in one section.
struct SecFuncInfo {};

/// Specifying one line info.
struct BPFLineInfo {};

/// Specifying line info's in one section.
struct SecLineInfo {};

/// Specifying one offset relocation.
struct BPFFieldReloc {};

/// Specifying offset relocation's in one section.
struct SecFieldReloc {};

/// CO-RE relocation kind codes used in .BTF.ext section.
enum PatchableRelocKind : uint32_t {};

// Define a number of sub-types for CommonType, each with:
// - An accessor for a relevant "tail" information (data fields that
//   follow the CommonType record in binary format).
// - A classof() definition based on CommonType::getKind() value to
//   allow use with dyn_cast<>() function.

// For CommonType sub-types that are followed by a single entry of
// some type in the binary format.
#define BTF_DEFINE_TAIL

// For CommonType sub-types that are followed by CommonType::getVlen()
// number of entries of some type in the binary format.
#define BTF_DEFINE_TAIL_ARR

struct ArrayType final : CommonType,
                         private TrailingObjects<ArrayType, BTFArray> {};

struct StructType final : CommonType,
                          private TrailingObjects<StructType, BTFMember> {};

struct EnumType final : CommonType, private TrailingObjects<EnumType, BTFEnum> {};

struct Enum64Type final : CommonType,
                          private TrailingObjects<Enum64Type, BTFEnum64> {};

#undef BTF_DEFINE_TAIL
#undef BTF_DEFINE_TAIL_ARR

} // End namespace BTF.
} // End namespace llvm.

#endif