summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-link/llvm-link.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-link/llvm-link.cpp')
-rw-r--r--llvm/tools/llvm-link/llvm-link.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 9f287e4fdb6..369f3477fe5 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -38,6 +38,11 @@ static cl::list<std::string>
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"));
@@ -108,7 +113,8 @@ static void diagnosticHandler(const DiagnosticInfo &DI) {
}
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()) {
@@ -124,7 +130,7 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
if (Verbose)
errs() << "Linking in '" << File << "'\n";
- if (L.linkInModule(M.get()))
+ if (L.linkInModule(M.get(), OverrideDuplicateSymbols))
return false;
}
@@ -143,7 +149,12 @@ int main(int argc, char **argv) {
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;
OpenPOWER on IntegriCloud