llvm/lld/MachO/InputSection.h

//===- InputSection.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 LLD_MACHO_INPUT_SECTION_H
#define LLD_MACHO_INPUT_SECTION_H

#include "Config.h"
#include "Relocations.h"
#include "Symbols.h"

#include "lld/Common/LLVM.h"
#include "lld/Common/Memory.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/CachedHashString.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/BinaryFormat/MachO.h"

namespace lld {
namespace macho {

class InputFile;
class OutputSection;

class InputSection {};

// ConcatInputSections are combined into (Concat)OutputSections through simple
// concatenation, in contrast with literal sections which may have their
// contents merged before output.
class ConcatInputSection final : public InputSection {};

// Initialize a fake InputSection that does not belong to any InputFile.
// The created ConcatInputSection will always have 'live=true'
ConcatInputSection *makeSyntheticInputSection(StringRef segName,
                                              StringRef sectName,
                                              uint32_t flags = 0,
                                              ArrayRef<uint8_t> data = {};

// Helper functions to make it easy to sprinkle asserts.

inline bool shouldOmitFromOutput(InputSection *isec) {}

inline bool isCoalescedWeak(InputSection *isec) {}

// We allocate a lot of these and binary search on them, so they should be as
// compact as possible. Hence the use of 31 rather than 64 bits for the hash.
struct StringPiece {};

static_assert;

// CStringInputSections are composed of multiple null-terminated string
// literals, which we represent using StringPieces. These literals can be
// deduplicated and tail-merged, so translating offsets between the input and
// outputs sections is more complicated.
//
// NOTE: One significant difference between LLD and ld64 is that we merge all
// cstring literals, even those referenced directly by non-private symbols.
// ld64 is more conservative and does not do that. This was mostly done for
// implementation simplicity; if we find programs that need the more
// conservative behavior we can certainly implement that.
class CStringInputSection final : public InputSection {};

class WordLiteralInputSection final : public InputSection {};

inline uint8_t sectionType(uint32_t flags) {}

inline bool isZeroFill(uint32_t flags) {}

inline bool isThreadLocalVariables(uint32_t flags) {}

// These sections contain the data for initializing thread-local variables.
inline bool isThreadLocalData(uint32_t flags) {}

inline bool isDebugSection(uint32_t flags) {}

inline bool isWordLiteralSection(uint32_t flags) {}

bool isCodeSection(const InputSection *);
bool isCfStringSection(const InputSection *);
bool isClassRefsSection(const InputSection *);
bool isSelRefsSection(const InputSection *);
bool isEhFrameSection(const InputSection *);
bool isGccExceptTabSection(const InputSection *);

extern std::vector<ConcatInputSection *> inputSections;
// This is used as a counter for specyfing input order for input sections
extern int inputSectionsOrder;

namespace section_names {

constexpr const char authGot[] =;
constexpr const char authPtr[] =;
constexpr const char binding[] =;
constexpr const char bitcodeBundle[] =;
constexpr const char cString[] =;
constexpr const char cfString[] =;
constexpr const char cgProfile[] =;
constexpr const char chainFixups[] =;
constexpr const char codeSignature[] =;
constexpr const char common[] =;
constexpr const char compactUnwind[] =;
constexpr const char data[] =;
constexpr const char debugAbbrev[] =;
constexpr const char debugInfo[] =;
constexpr const char debugLine[] =;
constexpr const char debugStr[] =;
constexpr const char debugStrOffs[] =;
constexpr const char ehFrame[] =;
constexpr const char gccExceptTab[] =;
constexpr const char export_[] =;
constexpr const char dataInCode[] =;
constexpr const char functionStarts[] =;
constexpr const char got[] =;
constexpr const char header[] =;
constexpr const char indirectSymbolTable[] =;
constexpr const char initOffsets[] =;
constexpr const char const_[] =;
constexpr const char lazySymbolPtr[] =;
constexpr const char lazyBinding[] =;
constexpr const char literals[] =;
constexpr const char moduleInitFunc[] =;
constexpr const char moduleTermFunc[] =;
constexpr const char nonLazySymbolPtr[] =;
constexpr const char objcCatList[] =;
constexpr const char objcClassList[] =;
constexpr const char objcMethList[] =;
constexpr const char objcClassRefs[] =;
constexpr const char objcConst[] =;
constexpr const char objCImageInfo[] =;
constexpr const char objcStubs[] =;
constexpr const char objcSelrefs[] =;
constexpr const char objcMethname[] =;
constexpr const char objcNonLazyCatList[] =;
constexpr const char objcNonLazyClassList[] =;
constexpr const char objcProtoList[] =;
constexpr const char outlinedHashTree[] =;
constexpr const char pageZero[] =;
constexpr const char pointers[] =;
constexpr const char rebase[] =;
constexpr const char staticInit[] =;
constexpr const char stringTable[] =;
constexpr const char stubHelper[] =;
constexpr const char stubs[] =;
constexpr const char swift[] =;
constexpr const char symbolTable[] =;
constexpr const char textCoalNt[] =;
constexpr const char text[] =;
constexpr const char threadPtrs[] =;
constexpr const char threadVars[] =;
constexpr const char unwindInfo[] =;
constexpr const char weakBinding[] =;
constexpr const char zeroFill[] =;
constexpr const char addrSig[] =;

} // namespace section_names

void addInputSection(InputSection *inputSection);
} // namespace macho

std::string toString(const macho::InputSection *);

} // namespace lld

#endif