llvm/llvm/include/llvm/BinaryFormat/XCOFF.h

//===-- llvm/BinaryFormat/XCOFF.h - The XCOFF 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 XCOFF object file format.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_BINARYFORMAT_XCOFF_H
#define LLVM_BINARYFORMAT_XCOFF_H

#include <stddef.h>
#include <stdint.h>

namespace llvm {
class StringRef;
template <unsigned> class SmallString;
template <typename T> class Expected;

namespace XCOFF {

// Constants used in the XCOFF definition.

constexpr size_t FileNamePadSize =;
constexpr size_t NameSize =;
constexpr size_t AuxFileEntNameSize =;
constexpr size_t FileHeaderSize32 =;
constexpr size_t FileHeaderSize64 =;
constexpr size_t AuxFileHeaderSize32 =;
constexpr size_t AuxFileHeaderSize64 =;
constexpr size_t AuxFileHeaderSizeShort =;
constexpr size_t SectionHeaderSize32 =;
constexpr size_t SectionHeaderSize64 =;
constexpr size_t SymbolTableEntrySize =;
constexpr size_t RelocationSerializationSize32 =;
constexpr size_t RelocationSerializationSize64 =;
constexpr size_t ExceptionSectionEntrySize32 =;
constexpr size_t ExceptionSectionEntrySize64 =;
constexpr uint16_t RelocOverflow =;
constexpr uint8_t AllocRegNo =;

enum ReservedSectionNum : int16_t {};

enum MagicNumber : uint16_t {};

// Masks for packing/unpacking the r_rsize field of relocations.

// The msb is used to indicate if the bits being relocated are signed or
// unsigned.
static constexpr uint8_t XR_SIGN_INDICATOR_MASK =;
// The 2nd msb is used to indicate that the binder has replaced/modified the
// original instruction.
static constexpr uint8_t XR_FIXUP_INDICATOR_MASK =;
// The remaining bits specify the bit length of the relocatable reference
// minus one.
static constexpr uint8_t XR_BIASED_LENGTH_MASK =;

// This field only exists in the XCOFF64 definition.
enum AuxHeaderFlags64 : uint16_t {};

enum XCOFFInterpret : uint16_t {};

enum FileFlag : uint16_t {};

// x_smclas field of x_csect from system header: /usr/include/syms.h
/// Storage Mapping Class definitions.
enum StorageMappingClass : uint8_t {};

// Flags for defining the section type. Masks for use with the (signed, 32-bit)
// s_flags field of the section header structure, selecting for values in the
// lower 16 bits. Defined in the system header `scnhdr.h`.
enum SectionTypeFlags : int32_t {};

/// Values for defining the section subtype of sections of type STYP_DWARF as
/// they would appear in the (signed, 32-bit) s_flags field of the section
/// header structure, contributing to the 16 most significant bits. Defined in
/// the system header `scnhdr.h`.
enum DwarfSectionSubtypeFlags : int32_t {};

// STORAGE CLASSES, n_sclass field of syment.
// The values come from `storclass.h` and `dbxstclass.h`.
enum StorageClass : uint8_t {};

// Flags for defining the symbol type. Values to be encoded into the lower 3
// bits of the (unsigned, 8-bit) x_smtyp field of csect auxiliary symbol table
// entries. Defined in the system header `syms.h`.
enum SymbolType : uint8_t {};

/// Values for visibility as they would appear when encoded in the high 4 bits
/// of the 16-bit unsigned n_type field of symbol table entries. Valid for
/// 32-bit XCOFF only when the vstamp in the auxiliary header is greater than 1.
enum VisibilityType : uint16_t {};

constexpr uint16_t VISIBILITY_MASK =;

// Relocation types, defined in `/usr/include/reloc.h`.
enum RelocationType : uint8_t {};

enum CFileStringType : uint8_t {};

enum CFileLangId : uint8_t {};

enum CFileCpuId : uint8_t {};

enum SymbolAuxType : uint8_t {};                  // 64-bit XCOFF file only.

StringRef getMappingClassString(XCOFF::StorageMappingClass SMC);
StringRef getRelocationTypeString(XCOFF::RelocationType Type);
Expected<SmallString<32>> parseParmsType(uint32_t Value, unsigned FixedParmsNum,
                                         unsigned FloatingParmsNum);
Expected<SmallString<32>> parseParmsTypeWithVecInfo(uint32_t Value,
                                                    unsigned FixedParmsNum,
                                                    unsigned FloatingParmsNum,
                                                    unsigned VectorParmsNum);
Expected<SmallString<32>> parseVectorParmsType(uint32_t Value,
                                               unsigned ParmsNum);

struct TracebackTable {};

// Extended Traceback table flags.
enum ExtendedTBTableFlag : uint8_t {};

StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId);
SmallString<32> getExtendedTBTableFlagString(uint8_t Flag);

struct CsectProperties {};

} // end namespace XCOFF
} // end namespace llvm

#endif