InputFilenames(cl::Positional, cl::OneOrMore,
cl::desc("<input bitcode files>"));
+static cl::list<std::string> OverridingInputs(
+ "override", cl::ZeroOrMore, cl::value_desc("filename"),
+ cl::desc(
+ "input bitcode file which can override previously defined symbol(s)"));
+
static cl::opt<std::string>
OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
cl::value_desc("filename"));
}
static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
- const cl::list<std::string> &Files) {
+ const cl::list<std::string> &Files,
+ bool OverrideDuplicateSymbols) {
for (const auto &File : Files) {
std::unique_ptr<Module> M = loadFile(argv0, File, Context);
if (!M.get()) {
if (Verbose)
errs() << "Linking in '" << File << "'\n";
- if (L.linkInModule(M.get()))
+ if (L.linkInModule(M.get(), OverrideDuplicateSymbols))
return false;
}
auto Composite = make_unique<Module>("llvm-link", Context);
Linker L(Composite.get(), diagnosticHandler);
- if (!linkFiles(argv[0], Context, L, InputFilenames))
+ // First add all the regular input files
+ if (!linkFiles(argv[0], Context, L, InputFilenames, false))
+ return 1;
+
+ // Next the -override ones.
+ if (!linkFiles(argv[0], Context, L, OverridingInputs, true))
return 1;
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;