llvm/llvm/include/llvm/BinaryFormat/MachO.h

//===-- llvm/BinaryFormat/MachO.h - The MachO file format -------*- 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
//
//===----------------------------------------------------------------------===//
//
// This file defines manifest constants for the MachO object file format.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_BINARYFORMAT_MACHO_H
#define LLVM_BINARYFORMAT_MACHO_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/SwapByteOrder.h"

namespace llvm {

class Triple;

namespace MachO {
// Enums from <mach-o/loader.h>
enum : uint32_t {};

enum HeaderFileType {};

enum {};

enum : uint32_t {};

#define HANDLE_LOAD_COMMAND

enum LoadCommandType : uint32_t {};

#undef HANDLE_LOAD_COMMAND

enum : uint32_t {};

/// These are the section type and attributes fields.  A MachO section can
/// have only one Type, but can have any of the attributes specified.
enum SectionType : uint32_t {};

enum : uint32_t {};

enum DataRegionType {};

enum RebaseType {};

enum {};

enum RebaseOpcode {};

enum BindType {};

enum BindSpecialDylib {};

enum {};

enum BindOpcode {};

enum {};

enum ExportSymbolKind {};

enum {};

enum NListType : uint8_t {};

enum SectionOrdinal {};

enum {};

enum StabType {};

enum : uint32_t {};

enum RelocationInfoType {};

// Values for segment_command.initprot.
// From <mach/vm_prot.h>
enum {};

// Values for platform field in build_version_command.
enum PlatformType {};

// Values for tools enum in build_tool_version.
enum {};

// Structs from <mach-o/loader.h>

struct mach_header {};

struct mach_header_64 {};

struct load_command {};

struct segment_command {};

struct segment_command_64 {};

struct section {};

struct section_64 {};

inline bool isVirtualSection(uint8_t type) {}

struct fvmlib {};

// The fvmlib_command is obsolete and no longer supported.
struct fvmlib_command {};

struct dylib {};

struct dylib_command {};

struct sub_framework_command {};

struct sub_client_command {};

struct sub_umbrella_command {};

struct sub_library_command {};

// The prebound_dylib_command is obsolete and no longer supported.
struct prebound_dylib_command {};

struct dylinker_command {};

struct thread_command {};

struct routines_command {};

struct routines_command_64 {};

struct symtab_command {};

struct dysymtab_command {};

struct dylib_table_of_contents {};

struct dylib_module {};

struct dylib_module_64 {};

struct dylib_reference {};

// The twolevel_hints_command is obsolete and no longer supported.
struct twolevel_hints_command {};

// The twolevel_hints_command is obsolete and no longer supported.
struct twolevel_hint {};

// The prebind_cksum_command is obsolete and no longer supported.
struct prebind_cksum_command {};

struct uuid_command {};

struct rpath_command {};

struct linkedit_data_command {};

struct data_in_code_entry {};

struct source_version_command {};

struct encryption_info_command {};

struct encryption_info_command_64 {};

struct version_min_command {};

struct note_command {};

struct build_tool_version {};

struct build_version_command {};

struct dyld_env_command {};

struct dyld_info_command {};

struct linker_option_command {};

lc_str;

struct fileset_entry_command {};

// The symseg_command is obsolete and no longer supported.
struct symseg_command {};

// The ident_command is obsolete and no longer supported.
struct ident_command {};

// The fvmfile_command is obsolete and no longer supported.
struct fvmfile_command {};

struct tlv_descriptor_32 {};

struct tlv_descriptor_64 {};

struct tlv_descriptor {};

struct entry_point_command {};

// Structs from <mach-o/fat.h>
struct fat_header {};

struct fat_arch {};

struct fat_arch_64 {};

// Structs from <mach-o/reloc.h>
struct relocation_info {};

struct scattered_relocation_info {};

// Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
struct any_relocation_info {};

// Structs from <mach-o/nlist.h>
struct nlist_base {};

struct nlist {};

struct nlist_64 {};

// Values for dyld_chained_fixups_header::imports_format.
enum ChainedImportFormat {};

// Values for dyld_chained_fixups_header::symbols_format.
enum {};

// Values for dyld_chained_starts_in_segment::page_start.
enum {};

// Values for dyld_chained_starts_in_segment::pointer_format.
enum {};

/// Structs for dyld chained fixups.
/// dyld_chained_fixups_header is the data pointed to by LC_DYLD_CHAINED_FIXUPS
/// load command.
struct dyld_chained_fixups_header {};

/// dyld_chained_starts_in_image is embedded in LC_DYLD_CHAINED_FIXUPS payload.
/// Each seg_info_offset entry is the offset into this struct for that
/// segment followed by pool of dyld_chain_starts_in_segment data.
struct dyld_chained_starts_in_image {};

struct dyld_chained_starts_in_segment {};

// DYLD_CHAINED_IMPORT
struct dyld_chained_import {};

// DYLD_CHAINED_IMPORT_ADDEND
struct dyld_chained_import_addend {};

// DYLD_CHAINED_IMPORT_ADDEND64
struct dyld_chained_import_addend64 {};

// The `bind` field (most significant bit) of the encoded fixup determines
// whether it is dyld_chained_ptr_64_bind or dyld_chained_ptr_64_rebase.

// DYLD_CHAINED_PTR_64/DYLD_CHAINED_PTR_64_OFFSET
struct dyld_chained_ptr_64_bind {};

// DYLD_CHAINED_PTR_64/DYLD_CHAINED_PTR_64_OFFSET
struct dyld_chained_ptr_64_rebase {};

// Byte order swapping functions for MachO structs

inline void swapStruct(fat_header &mh) {}

inline void swapStruct(fat_arch &mh) {}

inline void swapStruct(fat_arch_64 &mh) {}

inline void swapStruct(mach_header &mh) {}

inline void swapStruct(mach_header_64 &H) {}

inline void swapStruct(load_command &lc) {}

inline void swapStruct(symtab_command &lc) {}

inline void swapStruct(segment_command_64 &seg) {}

inline void swapStruct(segment_command &seg) {}

inline void swapStruct(section_64 &sect) {}

inline void swapStruct(section &sect) {}

inline void swapStruct(dyld_info_command &info) {}

inline void swapStruct(dylib_command &d) {}

inline void swapStruct(sub_framework_command &s) {}

inline void swapStruct(sub_umbrella_command &s) {}

inline void swapStruct(sub_library_command &s) {}

inline void swapStruct(sub_client_command &s) {}

inline void swapStruct(routines_command &r) {}

inline void swapStruct(routines_command_64 &r) {}

inline void swapStruct(thread_command &t) {}

inline void swapStruct(dylinker_command &d) {}

inline void swapStruct(uuid_command &u) {}

inline void swapStruct(rpath_command &r) {}

inline void swapStruct(source_version_command &s) {}

inline void swapStruct(entry_point_command &e) {}

inline void swapStruct(encryption_info_command &e) {}

inline void swapStruct(encryption_info_command_64 &e) {}

inline void swapStruct(dysymtab_command &dst) {}

inline void swapStruct(any_relocation_info &reloc) {}

inline void swapStruct(nlist_base &S) {}

inline void swapStruct(nlist &sym) {}

inline void swapStruct(nlist_64 &sym) {}

inline void swapStruct(linkedit_data_command &C) {}

inline void swapStruct(linker_option_command &C) {}

inline void swapStruct(fileset_entry_command &C) {}

inline void swapStruct(version_min_command &C) {}

inline void swapStruct(note_command &C) {}

inline void swapStruct(build_version_command &C) {}

inline void swapStruct(build_tool_version &C) {}

inline void swapStruct(data_in_code_entry &C) {}

inline void swapStruct(uint32_t &C) {}

// The prebind_cksum_command is obsolete and no longer supported.
inline void swapStruct(prebind_cksum_command &C) {}

// The twolevel_hints_command is obsolete and no longer supported.
inline void swapStruct(twolevel_hints_command &C) {}

// The prebound_dylib_command is obsolete and no longer supported.
inline void swapStruct(prebound_dylib_command &C) {}

// The fvmfile_command is obsolete and no longer supported.
inline void swapStruct(fvmfile_command &C) {}

// The symseg_command is obsolete and no longer supported.
inline void swapStruct(symseg_command &C) {}

// The ident_command is obsolete and no longer supported.
inline void swapStruct(ident_command &C) {}

inline void swapStruct(fvmlib &C) {}

// The fvmlib_command is obsolete and no longer supported.
inline void swapStruct(fvmlib_command &C) {}

// Get/Set functions from <mach-o/nlist.h>

inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {}

inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {}

inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) {}

inline void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align) {}

// Enums from <mach/machine.h>
enum : uint32_t {};

// Constants for the cputype field.
enum CPUType {};

enum : uint32_t {};

// Constants for the cpusubtype field.
enum CPUSubTypeX86 {};
inline int CPU_SUBTYPE_INTEL(int Family, int Model) {}
inline int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST) {}
inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) {}
enum {};

enum CPUSubTypeARM {};

enum CPUSubTypeARM64 : uint32_t {};

inline unsigned CPU_SUBTYPE_ARM64E_PTRAUTH_VERSION(uint32_t ST) {}

inline uint32_t
CPU_SUBTYPE_ARM64E_WITH_PTRAUTH_VERSION(unsigned PtrAuthABIVersion,
                                        bool PtrAuthKernelABIVersion) {}

inline bool CPU_SUBTYPE_ARM64E_IS_VERSIONED_PTRAUTH_ABI(uint32_t ST) {}

inline bool CPU_SUBTYPE_ARM64E_IS_KERNEL_PTRAUTH_ABI(uint32_t ST) {}

enum CPUSubTypeARM64_32 {};

enum CPUSubTypeSPARC {};

enum CPUSubTypePowerPC {};

Expected<uint32_t> getCPUType(const Triple &T);
Expected<uint32_t> getCPUSubType(const Triple &T);
Expected<uint32_t> getCPUSubType(const Triple &T, unsigned PtrAuthABIVersion,
                                 bool PtrAuthKernelABIVersion);

struct x86_thread_state32_t {};

struct x86_thread_state64_t {};

enum x86_fp_control_precis {};

enum x86_fp_control_rc {};

struct fp_control_t {};

struct fp_status_t {};

struct mmst_reg_t {};

struct xmm_reg_t {};

struct x86_float_state64_t {};

struct x86_exception_state64_t {};

inline void swapStruct(x86_thread_state32_t &x) {}

inline void swapStruct(x86_thread_state64_t &x) {}

inline void swapStruct(x86_float_state64_t &x) {}

inline void swapStruct(x86_exception_state64_t &x) {}

struct x86_state_hdr_t {};

struct x86_thread_state_t {};

struct x86_float_state_t {};

struct x86_exception_state_t {};

inline void swapStruct(x86_state_hdr_t &x) {}

enum X86ThreadFlavors {};

inline void swapStruct(x86_thread_state_t &x) {}

inline void swapStruct(x86_float_state_t &x) {}

inline void swapStruct(x86_exception_state_t &x) {}

const uint32_t x86_THREAD_STATE32_COUNT =;

const uint32_t x86_THREAD_STATE64_COUNT =;
const uint32_t x86_FLOAT_STATE64_COUNT =;
const uint32_t x86_EXCEPTION_STATE64_COUNT =;

const uint32_t x86_THREAD_STATE_COUNT =;
const uint32_t x86_FLOAT_STATE_COUNT =;
const uint32_t x86_EXCEPTION_STATE_COUNT =;

struct arm_thread_state32_t {};

inline void swapStruct(arm_thread_state32_t &x) {}

struct arm_thread_state64_t {};

inline void swapStruct(arm_thread_state64_t &x) {}

struct arm_state_hdr_t {};

struct arm_thread_state_t {};

inline void swapStruct(arm_state_hdr_t &x) {}

enum ARMThreadFlavors {};

inline void swapStruct(arm_thread_state_t &x) {}

const uint32_t ARM_THREAD_STATE_COUNT =;

const uint32_t ARM_THREAD_STATE64_COUNT =;

struct ppc_thread_state32_t {};

inline void swapStruct(ppc_thread_state32_t &x) {}

struct ppc_state_hdr_t {};

struct ppc_thread_state_t {};

inline void swapStruct(ppc_state_hdr_t &x) {}

enum PPCThreadFlavors {};

inline void swapStruct(ppc_thread_state_t &x) {}

const uint32_t PPC_THREAD_STATE_COUNT =;

// Define a union of all load command structs
#define LOAD_COMMAND_STRUCT

LLVM_PACKED_START
macho_load_command;
LLVM_PACKED_END

inline void swapStruct(dyld_chained_fixups_header &C) {}

inline void swapStruct(dyld_chained_starts_in_image &C) {}

inline void swapStruct(dyld_chained_starts_in_segment &C) {}

/* code signing attributes of a process */

enum CodeSignAttrs {};

/* executable segment flags */

enum CodeSignExecSegFlags {};

/* Magic numbers used by Code Signing */

enum CodeSignMagic {};

struct CS_CodeDirectory {};

static_assert;

struct CS_BlobIndex {};

struct CS_SuperBlob {};

enum SecCSDigestAlgorithm {};

enum LinkerOptimizationHintKind {};

} // end namespace MachO
} // end namespace llvm

#endif