+ if (Verbose)
+ errs() << "Linking in '" << File << "'\n";
+
+ if (L.linkInModule(*M, ApplicableFlags, Index.get()))
+ return false;
+ // All linker flags apply to linking of subsequent files.
+ ApplicableFlags = Flags;
+
+ // If requested for testing, preserve modules by releasing them from
+ // the unique_ptr before the are freed. This can help catch any
+ // cross-module references from e.g. unneeded metadata references
+ // that aren't properly set to null but instead mapped to the source
+ // module version. The bitcode writer will assert if it finds any such
+ // cross-module references.
+ if (PreserveModules)
+ M.release();
+ }
+
+ return true;
+}
+
+int main(int argc, char **argv) {
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ LLVMContext &Context = getGlobalContext();
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
+
+ auto Composite = make_unique<Module>("llvm-link", Context);
+ Linker L(*Composite, diagnosticHandler);
+
+ unsigned Flags = Linker::Flags::None;
+ if (Internalize)
+ Flags |= Linker::Flags::InternalizeLinkedSymbols;
+ if (OnlyNeeded)
+ Flags |= Linker::Flags::LinkOnlyNeeded;
+
+ // First add all the regular input files
+ if (!linkFiles(argv[0], Context, L, InputFilenames, Flags))
+ return 1;
+
+ // Next the -override ones.
+ if (!linkFiles(argv[0], Context, L, OverridingInputs,
+ Flags | Linker::Flags::OverrideFromSrc))
+ return 1;
+
+ // Import any functions requested via -import
+ if (!importFunctions(argv[0], Context, L))
+ return 1;