#include "SyntheticSections.h"
#include "ConcatOutputSection.h"
#include "Config.h"
#include "ExportTrie.h"
#include "InputFiles.h"
#include "MachOStructs.h"
#include "ObjC.h"
#include "OutputSegment.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "lld/Common/CommonLinkerContext.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/xxhash.h"
#if defined(__APPLE__)
#include <sys/mman.h>
#define COMMON_DIGEST_FOR_OPENSSL
#include <CommonCrypto/CommonDigest.h>
#else
#include "llvm/Support/SHA256.h"
#endif
usingnamespacellvm;
usingnamespacellvm::MachO;
usingnamespacellvm::support;
usingnamespacellvm::support::endian;
usingnamespacelld;
usingnamespacelld::macho;
static void sha256(const uint8_t *data, size_t len, uint8_t *output) { … }
InStruct macho::in;
std::vector<SyntheticSection *> macho::syntheticSections;
SyntheticSection::SyntheticSection(const char *segname, const char *name)
: … { … }
MachHeaderSection::MachHeaderSection()
: … { … }
void MachHeaderSection::addLoadCommand(LoadCommand *lc) { … }
uint64_t MachHeaderSection::getSize() const { … }
static uint32_t cpuSubtype() { … }
static bool hasWeakBinding() { … }
static bool hasNonWeakDefinition() { … }
void MachHeaderSection::writeTo(uint8_t *buf) const { … }
PageZeroSection::PageZeroSection()
: … { … }
RebaseSection::RebaseSection()
: … { … }
namespace {
struct RebaseState { … };
}
static void emitIncrement(uint64_t incr, raw_svector_ostream &os) { … }
static void flushRebase(const RebaseState &state, raw_svector_ostream &os) { … }
static void encodeRebases(const OutputSegment *seg,
MutableArrayRef<Location> locations,
raw_svector_ostream &os) { … }
void RebaseSection::finalizeContents() { … }
void RebaseSection::writeTo(uint8_t *buf) const { … }
NonLazyPointerSectionBase::NonLazyPointerSectionBase(const char *segname,
const char *name)
: … { … }
void macho::addNonLazyBindingEntries(const Symbol *sym,
const InputSection *isec, uint64_t offset,
int64_t addend) { … }
void NonLazyPointerSectionBase::addEntry(Symbol *sym) { … }
void macho::writeChainedRebase(uint8_t *buf, uint64_t targetVA) { … }
static void writeChainedBind(uint8_t *buf, const Symbol *sym, int64_t addend) { … }
void macho::writeChainedFixup(uint8_t *buf, const Symbol *sym, int64_t addend) { … }
void NonLazyPointerSectionBase::writeTo(uint8_t *buf) const { … }
GotSection::GotSection()
: … { … }
TlvPointerSection::TlvPointerSection()
: … { … }
BindingSection::BindingSection()
: … { … }
namespace {
struct Binding { … };
struct BindIR { … };
}
static void encodeBinding(const OutputSection *osec, uint64_t outSecOff,
int64_t addend, Binding &lastBinding,
std::vector<BindIR> &opcodes) { … }
static void optimizeOpcodes(std::vector<BindIR> &opcodes) { … }
static void flushOpcodes(const BindIR &op, raw_svector_ostream &os) { … }
static bool needsWeakBind(const Symbol &sym) { … }
static int16_t ordinalForDylibSymbol(const DylibSymbol &dysym) { … }
static int16_t ordinalForSymbol(const Symbol &sym) { … }
static void encodeDylibOrdinal(int16_t ordinal, raw_svector_ostream &os) { … }
static void encodeWeakOverride(const Defined *defined,
raw_svector_ostream &os) { … }
template <class Sym>
std::vector<std::pair<const Sym *, std::vector<BindingEntry>>>
sortBindings(const BindingsMap<const Sym *> &bindingsMap) { … }
void BindingSection::finalizeContents() { … }
void BindingSection::writeTo(uint8_t *buf) const { … }
WeakBindingSection::WeakBindingSection()
: … { … }
void WeakBindingSection::finalizeContents() { … }
void WeakBindingSection::writeTo(uint8_t *buf) const { … }
StubsSection::StubsSection()
: … { … }
uint64_t StubsSection::getSize() const { … }
void StubsSection::writeTo(uint8_t *buf) const { … }
void StubsSection::finalize() { … }
static void addBindingsForStub(Symbol *sym) { … }
void StubsSection::addEntry(Symbol *sym) { … }
StubHelperSection::StubHelperSection()
: … { … }
uint64_t StubHelperSection::getSize() const { … }
bool StubHelperSection::isNeeded() const { … }
void StubHelperSection::writeTo(uint8_t *buf) const { … }
void StubHelperSection::setUp() { … }
llvm::DenseMap<llvm::CachedHashStringRef, ConcatInputSection *>
ObjCSelRefsHelper::methnameToSelref;
void ObjCSelRefsHelper::initialize() { … }
void ObjCSelRefsHelper::cleanup() { … }
ConcatInputSection *ObjCSelRefsHelper::makeSelRef(StringRef methname) { … }
ConcatInputSection *ObjCSelRefsHelper::getSelRef(StringRef methname) { … }
ObjCStubsSection::ObjCStubsSection()
: … { … }
bool ObjCStubsSection::isObjCStubSymbol(Symbol *sym) { … }
StringRef ObjCStubsSection::getMethname(Symbol *sym) { … }
void ObjCStubsSection::addEntry(Symbol *sym) { … }
void ObjCStubsSection::setUp() { … }
uint64_t ObjCStubsSection::getSize() const { … }
void ObjCStubsSection::writeTo(uint8_t *buf) const { … }
LazyPointerSection::LazyPointerSection()
: … { … }
uint64_t LazyPointerSection::getSize() const { … }
bool LazyPointerSection::isNeeded() const { … }
void LazyPointerSection::writeTo(uint8_t *buf) const { … }
LazyBindingSection::LazyBindingSection()
: … { … }
void LazyBindingSection::finalizeContents() { … }
void LazyBindingSection::writeTo(uint8_t *buf) const { … }
void LazyBindingSection::addEntry(Symbol *sym) { … }
uint32_t LazyBindingSection::encode(const Symbol &sym) { … }
ExportSection::ExportSection()
: … { … }
void ExportSection::finalizeContents() { … }
void ExportSection::writeTo(uint8_t *buf) const { … }
DataInCodeSection::DataInCodeSection()
: … { … }
template <class LP>
static std::vector<MachO::data_in_code_entry> collectDataInCodeEntries() { … }
void DataInCodeSection::finalizeContents() { … }
void DataInCodeSection::writeTo(uint8_t *buf) const { … }
FunctionStartsSection::FunctionStartsSection()
: … { … }
void FunctionStartsSection::finalizeContents() { … }
void FunctionStartsSection::writeTo(uint8_t *buf) const { … }
SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: … { … }
void SymtabSection::emitBeginSourceStab(StringRef sourceFile) { … }
void SymtabSection::emitEndSourceStab() { … }
void SymtabSection::emitObjectFileStab(ObjFile *file) { … }
void SymtabSection::emitEndFunStab(Defined *defined) { … }
void SymtabSection::emitStabs() { … }
void SymtabSection::finalizeContents() { … }
uint32_t SymtabSection::getNumSymbols() const { … }
template <class LP> class SymtabSectionImpl final : public SymtabSection { … };
template <class LP> uint64_t SymtabSectionImpl<LP>::getRawSize() const { … }
template <class LP> void SymtabSectionImpl<LP>::writeTo(uint8_t *buf) const { … }
template <class LP>
SymtabSection *
macho::makeSymtabSection(StringTableSection &stringTableSection) { … }
IndirectSymtabSection::IndirectSymtabSection()
: … { … }
uint32_t IndirectSymtabSection::getNumSymbols() const { … }
bool IndirectSymtabSection::isNeeded() const { … }
void IndirectSymtabSection::finalizeContents() { … }
static uint32_t indirectValue(const Symbol *sym) { … }
void IndirectSymtabSection::writeTo(uint8_t *buf) const { … }
StringTableSection::StringTableSection()
: … { … }
uint32_t StringTableSection::addString(StringRef str) { … }
void StringTableSection::writeTo(uint8_t *buf) const { … }
static_assert …;
static_assert …;
CodeSignatureSection::CodeSignatureSection()
: … { … }
uint32_t CodeSignatureSection::getBlockCount() const { … }
uint64_t CodeSignatureSection::getRawSize() const { … }
void CodeSignatureSection::writeHashes(uint8_t *buf) const { … }
void CodeSignatureSection::writeTo(uint8_t *buf) const { … }
CStringSection::CStringSection(const char *name)
: … { … }
void CStringSection::addInput(CStringInputSection *isec) { … }
void CStringSection::writeTo(uint8_t *buf) const { … }
void CStringSection::finalizeContents() { … }
void DeduplicatedCStringSection::finalizeContents() { … }
void DeduplicatedCStringSection::writeTo(uint8_t *buf) const { … }
DeduplicatedCStringSection::StringOffset
DeduplicatedCStringSection::getStringOffset(StringRef str) const { … }
WordLiteralSection::WordLiteralSection()
: … { … }
void WordLiteralSection::addInput(WordLiteralInputSection *isec) { … }
void WordLiteralSection::finalizeContents() { … }
void WordLiteralSection::writeTo(uint8_t *buf) const { … }
ObjCImageInfoSection::ObjCImageInfoSection()
: … { … }
ObjCImageInfoSection::ImageInfo
ObjCImageInfoSection::parseImageInfo(const InputFile *file) { … }
static std::string swiftVersionString(uint8_t version) { … }
void ObjCImageInfoSection::finalizeContents() { … }
void ObjCImageInfoSection::writeTo(uint8_t *buf) const { … }
InitOffsetsSection::InitOffsetsSection()
: … { … }
uint64_t InitOffsetsSection::getSize() const { … }
void InitOffsetsSection::writeTo(uint8_t *buf) const { … }
void InitOffsetsSection::setUp() { … }
ObjCMethListSection::ObjCMethListSection()
: … { … }
void ObjCMethListSection::setUp() { … }
void ObjCMethListSection::finalize() { … }
void ObjCMethListSection::writeTo(uint8_t *bufStart) const { … }
bool ObjCMethListSection::isMethodList(const ConcatInputSection *isec) { … }
void ObjCMethListSection::writeRelativeOffsetForIsec(
const ConcatInputSection *isec, uint8_t *buf, uint32_t &inSecOff,
uint32_t &outSecOff, bool useSelRef) const { … }
uint32_t
ObjCMethListSection::writeRelativeMethodList(const ConcatInputSection *isec,
uint8_t *buf) const { … }
uint32_t ObjCMethListSection::computeRelativeMethodListSize(
uint32_t absoluteMethodListSize) const { … }
void ObjCMethListSection::readMethodListHeader(const uint8_t *buf,
uint32_t &structSizeAndFlags,
uint32_t &structCount) const { … }
void ObjCMethListSection::writeMethodListHeader(uint8_t *buf,
uint32_t structSizeAndFlags,
uint32_t structCount) const { … }
void macho::createSyntheticSymbols() { … }
ChainedFixupsSection::ChainedFixupsSection()
: … { … }
bool ChainedFixupsSection::isNeeded() const { … }
void ChainedFixupsSection::addBinding(const Symbol *sym,
const InputSection *isec, uint64_t offset,
int64_t addend) { … }
std::pair<uint32_t, uint8_t>
ChainedFixupsSection::getBinding(const Symbol *sym, int64_t addend) const { … }
static size_t writeImport(uint8_t *buf, int format, int16_t libOrdinal,
bool weakRef, uint32_t nameOffset, int64_t addend) { … }
size_t ChainedFixupsSection::SegmentInfo::getSize() const { … }
size_t ChainedFixupsSection::SegmentInfo::writeTo(uint8_t *buf) const { … }
static size_t importEntrySize(int format) { … }
void ChainedFixupsSection::writeTo(uint8_t *buf) const { … }
void ChainedFixupsSection::finalizeContents() { … }
template SymtabSection *macho::makeSymtabSection<LP64>(StringTableSection &);
template SymtabSection *macho::makeSymtabSection<ILP32>(StringTableSection &);