llvm/llvm/lib/ObjCopy/ELF/ELFObject.h

//===- ELFObject.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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_OBJCOPY_ELF_ELFOBJECT_H
#define LLVM_LIB_OBJCOPY_ELF_ELFOBJECT_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/StringTableBuilder.h"
#include "llvm/ObjCopy/CommonConfig.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <set>
#include <vector>

namespace llvm {
enum class DebugCompressionType;
namespace objcopy {
namespace elf {

class SectionBase;
class Section;
class OwnedDataSection;
class StringTableSection;
class SymbolTableSection;
class RelocationSection;
class DynamicRelocationSection;
class GnuDebugLinkSection;
class GroupSection;
class SectionIndexSection;
class CompressedSection;
class DecompressedSection;
class Segment;
class Object;
struct Symbol;

class SectionTableRef {};

enum ElfType {};

class SectionVisitor {};

class MutableSectionVisitor {};

class SectionWriter : public SectionVisitor {};

template <class ELFT> class ELFSectionWriter : public SectionWriter {};

template <class ELFT> class ELFSectionSizer : public MutableSectionVisitor {};

#define MAKE_SEC_WRITER_FRIEND

class BinarySectionWriter : public SectionWriter {};

IHexLineData;

struct IHexRecord {};

// Base class for IHexSectionWriter. This class implements writing algorithm,
// but doesn't actually write records. It is used for output buffer size
// calculation in IHexWriter::finalize.
class IHexSectionWriterBase : public BinarySectionWriter {};

// Real IHEX section writer
class IHexSectionWriter : public IHexSectionWriterBase {};

class Writer {};

template <class ELFT> class ELFWriter : public Writer {};

class BinaryWriter : public Writer {};

// A base class for writing ascii hex formats such as srec and ihex.
class ASCIIHexWriter : public Writer {};

class IHexWriter : public ASCIIHexWriter {};

class SRECWriter : public ASCIIHexWriter {};

SRecLineData;
struct SRecord {};

class SRECSectionWriterBase : public BinarySectionWriter {};

// An SRECSectionWriterBase that visits sections but does not write anything.
// This class is only used to calculate the size of the output file.
class SRECSizeCalculator : public SRECSectionWriterBase {};

class SRECSectionWriter : public SRECSectionWriterBase {};

class SectionBase {};

class Segment {};

class Section : public SectionBase {};

class OwnedDataSection : public SectionBase {};

class CompressedSection : public SectionBase {};

class DecompressedSection : public SectionBase {};

// There are two types of string tables that can exist, dynamic and not dynamic.
// In the dynamic case the string table is allocated. Changing a dynamic string
// table would mean altering virtual addresses and thus the memory image. So
// dynamic string tables should not have an interface to modify them or
// reconstruct them. This type lets us reconstruct a string table. To avoid
// this class being used for dynamic string tables (which has happened) the
// classof method checks that the particular instance is not allocated. This
// then agrees with the makeSection method used to construct most sections.
class StringTableSection : public SectionBase {};

// Symbols have a st_shndx field that normally stores an index but occasionally
// stores a different special value. This enum keeps track of what the st_shndx
// field means. Most of the values are just copies of the special SHN_* values.
// SYMBOL_SIMPLE_INDEX means that the st_shndx is just an index of a section.
enum SymbolShndxType {};

struct Symbol {};

class SectionIndexSection : public SectionBase {};

class SymbolTableSection : public SectionBase {};

struct Relocation {};

// All relocation sections denote relocations to apply to another section.
// However, some relocation sections use a dynamic symbol table and others use
// a regular symbol table. Because the types of the two symbol tables differ in
// our system (because they should behave differently) we can't uniformly
// represent all relocations with the same base class if we expose an interface
// that mentions the symbol table type. So we split the two base types into two
// different classes, one which handles the section the relocation is applied to
// and another which handles the symbol table type. The symbol table type is
// taken as a type parameter to the class (see RelocSectionWithSymtabBase).
class RelocationSectionBase : public SectionBase {};

// Takes the symbol table type to use as a parameter so that we can deduplicate
// that code between the two symbol table types.
template <class SymTabType>
class RelocSectionWithSymtabBase : public RelocationSectionBase {};

class RelocationSection
    : public RelocSectionWithSymtabBase<SymbolTableSection> {};

// TODO: The way stripping and groups interact is complicated
// and still needs to be worked on.

class GroupSection : public SectionBase {};

class DynamicSymbolTableSection : public Section {};

class DynamicSection : public Section {};

class DynamicRelocationSection
    : public RelocSectionWithSymtabBase<DynamicSymbolTableSection> {};

class GnuDebugLinkSection : public SectionBase {};

class Reader {};

Binary;
ELFFile;
ELFObjectFile;
OwningBinary;

class BasicELFBuilder {};

class BinaryELFBuilder : public BasicELFBuilder {};

class IHexELFBuilder : public BasicELFBuilder {};

template <class ELFT> class ELFBuilder {};

class BinaryReader : public Reader {};

class IHexReader : public Reader {};

class ELFReader : public Reader {};

class Object {};

} // end namespace elf
} // end namespace objcopy
} // end namespace llvm

#endif // LLVM_LIB_OBJCOPY_ELF_ELFOBJECT_H