#include "Driver.h"
#include "Config.h"
#include "ICF.h"
#include "InputFiles.h"
#include "InputSection.h"
#include "LTO.h"
#include "LinkerScript.h"
#include "MarkLive.h"
#include "OutputSections.h"
#include "ScriptParser.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
#include "Writer.h"
#include "lld/Common/Args.h"
#include "lld/Common/CommonLinkerContext.h"
#include "lld/Common/Driver.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Filesystem.h"
#include "lld/Common/Memory.h"
#include "lld/Common/Strings.h"
#include "lld/Common/TargetOptionsCommandFlags.h"
#include "lld/Common/Version.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Remarks/HotnessThresholdParser.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/GlobPattern.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TarWriter.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
#include <tuple>
#include <utility>
usingnamespacellvm;
usingnamespacellvm::ELF;
usingnamespacellvm::object;
usingnamespacellvm::sys;
usingnamespacellvm::support;
usingnamespacelld;
usingnamespacelld::elf;
Ctx elf::ctx;
static void setConfigs(Ctx &ctx, opt::InputArgList &args);
static void readConfigs(Ctx &ctx, opt::InputArgList &args);
void elf::errorOrWarn(const Twine &msg) { … }
Ctx::Ctx() : … { … }
void Ctx::reset() { … }
llvm::raw_fd_ostream Ctx::openAuxiliaryFile(llvm::StringRef filename,
std::error_code &ec) { … }
namespace lld {
namespace elf {
bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput) { … }
}
}
static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef emul) { … }
std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
Ctx &ctx, MemoryBufferRef mb) { … }
static bool isBitcode(MemoryBufferRef mb) { … }
bool LinkerDriver::tryAddFatLTOFile(MemoryBufferRef mb, StringRef archiveName,
uint64_t offsetInArchive, bool lazy) { … }
void LinkerDriver::addFile(StringRef path, bool withLOption) { … }
void LinkerDriver::addLibrary(StringRef name) { … }
static void initLLVM() { … }
static void checkOptions(Ctx &ctx) { … }
static const char *getReproduceOption(opt::InputArgList &args) { … }
static bool hasZOption(opt::InputArgList &args, StringRef key) { … }
static bool getZFlag(opt::InputArgList &args, StringRef k1, StringRef k2,
bool defaultValue) { … }
static SeparateSegmentKind getZSeparate(opt::InputArgList &args) { … }
static GnuStackKind getZGnuStack(opt::InputArgList &args) { … }
static uint8_t getZStartStopVisibility(opt::InputArgList &args) { … }
static GcsPolicy getZGcs(opt::InputArgList &args) { … }
static void checkZOptions(opt::InputArgList &args) { … }
constexpr const char *saveTempsValues[] = …;
LinkerDriver::LinkerDriver(Ctx &ctx) : … { … }
void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { … }
static std::string getRpath(opt::InputArgList &args) { … }
static void setUnresolvedSymbolPolicy(Ctx &ctx, opt::InputArgList &args) { … }
static Target2Policy getTarget2(opt::InputArgList &args) { … }
static bool isOutputFormatBinary(opt::InputArgList &args) { … }
static DiscardPolicy getDiscard(opt::InputArgList &args) { … }
static StringRef getDynamicLinker(Ctx &ctx, opt::InputArgList &args) { … }
static int getMemtagMode(Ctx &ctx, opt::InputArgList &args) { … }
static ICFLevel getICF(opt::InputArgList &args) { … }
static StripPolicy getStrip(Ctx &ctx, opt::InputArgList &args) { … }
static uint64_t parseSectionAddress(StringRef s, opt::InputArgList &args,
const opt::Arg &arg) { … }
static StringMap<uint64_t> getSectionStartMap(opt::InputArgList &args) { … }
static SortSectionPolicy getSortSection(opt::InputArgList &args) { … }
static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &args) { … }
static std::pair<BuildIdKind, SmallVector<uint8_t, 0>>
getBuildId(opt::InputArgList &args) { … }
static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &args) { … }
static void readCallGraph(Ctx &ctx, MemoryBufferRef mb) { … }
template <class ELFT>
static bool
processCallGraphRelocations(Ctx &ctx, SmallVector<uint32_t, 32> &symbolIndices,
ArrayRef<typename ELFT::CGProfile> &cgProfile,
ObjFile<ELFT> *inputObj) { … }
template <class ELFT> static void readCallGraphsFromObjectFiles(Ctx &ctx) { … }
template <class ELFT>
static void ltoValidateAllVtablesHaveTypeInfos(Ctx &ctx,
opt::InputArgList &args) { … }
static CGProfileSortKind getCGProfileSortKind(opt::InputArgList &args) { … }
static DebugCompressionType getCompressionType(StringRef s, StringRef option) { … }
static StringRef getAliasSpelling(opt::Arg *arg) { … }
static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
unsigned id) { … }
static std::tuple<StringRef, StringRef, StringRef>
getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) { … }
static SmallVector<StringRef, 0> getSymbolOrderingFile(Ctx &ctx,
MemoryBufferRef mb) { … }
static bool getIsRela(Ctx &ctx, opt::InputArgList &args) { … }
static void parseClangOption(Ctx &ctx, StringRef opt, const Twine &msg) { … }
static bool isValidReportString(StringRef arg) { … }
static bool remapInputs(Ctx &ctx, StringRef line, const Twine &location) { … }
static void readConfigs(Ctx &ctx, opt::InputArgList &args) { … }
static void setConfigs(Ctx &ctx, opt::InputArgList &args) { … }
static bool isFormatBinary(StringRef s) { … }
void LinkerDriver::createFiles(opt::InputArgList &args) { … }
void LinkerDriver::inferMachineType() { … }
static uint64_t getMaxPageSize(Ctx &ctx, opt::InputArgList &args) { … }
static uint64_t getCommonPageSize(Ctx &ctx, opt::InputArgList &args) { … }
static std::optional<uint64_t> getImageBase(Ctx &ctx, opt::InputArgList &args) { … }
static DenseSet<StringRef> getExcludeLibs(opt::InputArgList &args) { … }
static void excludeLibs(Ctx &ctx, opt::InputArgList &args) { … }
static void handleUndefined(Ctx &ctx, Symbol *sym, const char *option) { … }
static void handleUndefinedGlob(Ctx &ctx, StringRef arg) { … }
static void handleLibcall(Ctx &ctx, StringRef name) { … }
static void writeArchiveStats(Ctx &ctx) { … }
static void writeWhyExtract(Ctx &ctx) { … }
static void reportBackrefs(Ctx &ctx) { … }
static void writeDependencyFile(Ctx &ctx) { … }
static void replaceCommonSymbols(Ctx &ctx) { … }
static void markAddrsig(bool icfSafe, Symbol *s) { … }
template <class ELFT>
static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) { … }
template <typename ELFT>
static void readSymbolPartitionSection(Ctx &ctx, InputSectionBase *s) { … }
static void markBuffersAsDontNeed(Ctx &ctx, bool skipLinkedOutput) { … }
template <class ELFT>
void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) { … }
struct WrappedSymbol { … };
static std::vector<WrappedSymbol> addWrappedSymbols(Ctx &ctx,
opt::InputArgList &args) { … }
static void combineVersionedSymbol(Ctx &ctx, Symbol &sym,
DenseMap<Symbol *, Symbol *> &map) { … }
static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) { … }
static void reportMissingFeature(StringRef config, const Twine &report) { … }
static void checkAndReportMissingFeature(StringRef config, uint32_t features,
uint32_t mask, const Twine &report) { … }
static void readSecurityNotes(Ctx &ctx) { … }
static void initSectionsAndLocalSyms(ELFFileBase *file, bool ignoreComdats) { … }
static void postParseObjectFile(ELFFileBase *file) { … }
template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) { … }