#include "llvm/ADT/STLExtras.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Linker/Linker.h"
#include "llvm/Object/Archive.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include <memory>
#include <utility>
usingnamespacellvm;
static cl::OptionCategory LinkCategory("Link Options");
static cl::list<std::string> InputFilenames(cl::Positional, cl::OneOrMore,
cl::desc("<input bitcode files>"),
cl::cat(LinkCategory));
static cl::list<std::string> OverridingInputs(
"override", cl::value_desc("filename"),
cl::desc(
"input bitcode file which can override previously defined symbol(s)"),
cl::cat(LinkCategory));
static cl::list<std::string> Imports(
"import", cl::value_desc("function:filename"),
cl::desc("Pair of function name and filename, where function should be "
"imported from bitcode in filename"),
cl::cat(LinkCategory));
static cl::opt<std::string>
SummaryIndex("summary-index", cl::desc("Module summary index filename"),
cl::init(""), cl::value_desc("filename"),
cl::cat(LinkCategory));
static cl::opt<std::string>
OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
cl::value_desc("filename"), cl::cat(LinkCategory));
static cl::opt<bool> Internalize("internalize",
cl::desc("Internalize linked symbols"),
cl::cat(LinkCategory));
static cl::opt<bool>
DisableDITypeMap("disable-debug-info-type-map",
cl::desc("Don't use a uniquing type map for debug info"),
cl::cat(LinkCategory));
static cl::opt<bool> OnlyNeeded("only-needed",
cl::desc("Link only needed symbols"),
cl::cat(LinkCategory));
static cl::opt<bool> Force("f", cl::desc("Enable binary output on terminals"),
cl::cat(LinkCategory));
static cl::opt<bool> DisableLazyLoad("disable-lazy-loading",
cl::desc("Disable lazy module loading"),
cl::cat(LinkCategory));
static cl::opt<bool> OutputAssembly("S",
cl::desc("Write output as LLVM assembly"),
cl::Hidden, cl::cat(LinkCategory));
static cl::opt<bool> Verbose("v",
cl::desc("Print information about actions taken"),
cl::cat(LinkCategory));
static cl::opt<bool> DumpAsm("d", cl::desc("Print assembly as linked"),
cl::Hidden, cl::cat(LinkCategory));
static cl::opt<bool> SuppressWarnings("suppress-warnings",
cl::desc("Suppress all linking warnings"),
cl::init(false), cl::cat(LinkCategory));
static cl::opt<bool> PreserveBitcodeUseListOrder(
"preserve-bc-uselistorder",
cl::desc("Preserve use-list order when writing LLVM bitcode."),
cl::init(true), cl::Hidden, cl::cat(LinkCategory));
static cl::opt<bool> PreserveAssemblyUseListOrder(
"preserve-ll-uselistorder",
cl::desc("Preserve use-list order when writing LLVM assembly."),
cl::init(false), cl::Hidden, cl::cat(LinkCategory));
static cl::opt<bool> NoVerify("disable-verify",
cl::desc("Do not run the verifier"), cl::Hidden,
cl::cat(LinkCategory));
static cl::opt<bool> IgnoreNonBitcode(
"ignore-non-bitcode",
cl::desc("Do not report an error for non-bitcode files in archives"),
cl::Hidden);
static cl::opt<bool> TryUseNewDbgInfoFormat(
"try-experimental-debuginfo-iterators",
cl::desc("Enable debuginfo iterator positions, if they're built in"),
cl::init(false));
extern cl::opt<bool> UseNewDbgInfoFormat;
extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;
extern cl::opt<bool> WriteNewDbgInfoFormat;
extern bool WriteNewDbgInfoFormatToBitcode;
extern cl::opt<cl::boolOrDefault> LoadBitcodeIntoNewDbgInfoFormat;
static ExitOnError ExitOnErr;
static std::unique_ptr<Module> loadFile(const char *argv0,
std::unique_ptr<MemoryBuffer> Buffer,
LLVMContext &Context,
bool MaterializeMetadata = true) { … }
static std::unique_ptr<Module> loadArFile(const char *Argv0,
std::unique_ptr<MemoryBuffer> Buffer,
LLVMContext &Context) { … }
namespace {
class ModuleLazyLoaderCache { … };
Module &ModuleLazyLoaderCache::operator()(const char *argv0,
const std::string &Identifier) { … }
}
namespace {
struct LLVMLinkDiagnosticHandler : public DiagnosticHandler { … };
}
static bool importFunctions(const char *argv0, Module &DestModule) { … }
static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
const cl::list<std::string> &Files, unsigned Flags) { … }
int main(int argc, char **argv) { … }