llvm/llvm/include/llvm/Object/ELFTypes.h

//===- ELFTypes.h - Endian specific types for ELF ---------------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_OBJECT_ELFTYPES_H
#define LLVM_OBJECT_ELFTYPES_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/BlockFrequency.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <cstdint>
#include <cstring>
#include <type_traits>

namespace llvm {
namespace object {

template <class ELFT> struct Elf_Ehdr_Impl;
template <class ELFT> struct Elf_Shdr_Impl;
template <class ELFT> struct Elf_Sym_Impl;
template <class ELFT> struct Elf_Dyn_Impl;
template <class ELFT> struct Elf_Phdr_Impl;
template <class ELFT, bool isRela> struct Elf_Rel_Impl;
template <bool Is64> struct Elf_Crel_Impl;
template <class ELFT> struct Elf_Verdef_Impl;
template <class ELFT> struct Elf_Verdaux_Impl;
template <class ELFT> struct Elf_Verneed_Impl;
template <class ELFT> struct Elf_Vernaux_Impl;
template <class ELFT> struct Elf_Versym_Impl;
template <class ELFT> struct Elf_Hash_Impl;
template <class ELFT> struct Elf_GnuHash_Impl;
template <class ELFT> struct Elf_Chdr_Impl;
template <class ELFT> struct Elf_Nhdr_Impl;
template <class ELFT> class Elf_Note_Impl;
template <class ELFT> class Elf_Note_Iterator_Impl;
template <class ELFT> struct Elf_CGProfile_Impl;

template <endianness E, bool Is64> struct ELFType {};

ELF32LE;
ELF32BE;
ELF64LE;
ELF64BE;

// Use an alignment of 2 for the typedefs since that is the worst case for
// ELF files in archives.

// I really don't like doing this, but the alternative is copypasta.
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)

#define LLVM_ELF_COMMA
#define LLVM_ELF_IMPORT_TYPES(E, W)

// Section header.
template <class ELFT> struct Elf_Shdr_Base;

Elf_Shdr_Base<ELFType<Endianness, false>>;

Elf_Shdr_Base<ELFType<Endianness, true>>;

template <class ELFT>
struct Elf_Shdr_Impl : Elf_Shdr_Base<ELFT> {};

template <class ELFT> struct Elf_Sym_Base;

Elf_Sym_Base<ELFType<Endianness, false>>;

Elf_Sym_Base<ELFType<Endianness, true>>;

template <class ELFT>
struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> {};

template <class ELFT>
Expected<StringRef> Elf_Sym_Impl<ELFT>::getName(StringRef StrTab) const {}

/// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section
/// (.gnu.version). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Versym_Impl {};

/// Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section
/// (.gnu.version_d). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Verdef_Impl {};

/// Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef
/// section (.gnu.version_d). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Verdaux_Impl {};

/// Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed
/// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Verneed_Impl {};

/// Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed
/// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Vernaux_Impl {};

/// Elf_Dyn_Base: This structure matches the form of entries in the dynamic
///               table section (.dynamic) look like.
template <class ELFT> struct Elf_Dyn_Base;

Elf_Dyn_Base<ELFType<Endianness, false>>;

Elf_Dyn_Base<ELFType<Endianness, true>>;

/// Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
template <class ELFT>
struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {};

Elf_Rel_Impl<ELFType<Endianness, false>, false>;

Elf_Rel_Impl<ELFType<Endianness, false>, true>;

Elf_Rel_Impl<ELFType<Endianness, true>, false>;

Elf_Rel_Impl<ELFType<Endianness, true>, true>;

// In-memory representation. The serialized representation uses LEB128.
template <bool Is64> struct Elf_Crel_Impl {};

template <class ELFT>
struct Elf_Ehdr_Impl {};

Elf_Phdr_Impl<ELFType<Endianness, false>>;

Elf_Phdr_Impl<ELFType<Endianness, true>>;

// ELFT needed for endianness.
template <class ELFT>
struct Elf_Hash_Impl {};

// .gnu.hash section
template <class ELFT>
struct Elf_GnuHash_Impl {};

// Compressed section headers.
// http://www.sco.com/developers/gabi/latest/ch4.sheader.html#compression_header
Elf_Chdr_Impl<ELFType<Endianness, false>>;

Elf_Chdr_Impl<ELFType<Endianness, true>>;

/// Note header
template <class ELFT>
struct Elf_Nhdr_Impl {};

/// An ELF note.
///
/// Wraps a note header, providing methods for accessing the name and
/// descriptor safely.
template <class ELFT>
class Elf_Note_Impl {};

template <class ELFT> class Elf_Note_Iterator_Impl {};

template <class ELFT> struct Elf_CGProfile_Impl {};

// MIPS .reginfo section
template <class ELFT>
struct Elf_Mips_RegInfo;

Elf_Mips_RegInfo<ELFType<Endianness, false>>;

Elf_Mips_RegInfo<ELFType<Endianness, true>>;

// .MIPS.options section
template <class ELFT> struct Elf_Mips_Options {};

// .MIPS.abiflags section content
template <class ELFT> struct Elf_Mips_ABIFlags {};

// Struct representing the BBAddrMap for one function.
struct BBAddrMap {};

/// A feature extension of BBAddrMap that holds information relevant to PGO.
struct PGOAnalysisMap {};

} // end namespace object.
} // end namespace llvm.

#endif // LLVM_OBJECT_ELFTYPES_H