diff options
| author | Artem Belevich <tra@google.com> | 2015-09-01 17:55:55 +0000 |
|---|---|---|
| committer | Artem Belevich <tra@google.com> | 2015-09-01 17:55:55 +0000 |
| commit | 020d4fb17f92410117bc858f586fead7c5088696 (patch) | |
| tree | 227c2a0a455b8d3e3e549636b4246c9cccb0cfc8 /llvm/tools/llvm-link | |
| parent | 6194363b319730e07cb081591473d1dfdad93306 (diff) | |
| download | bcm5719-llvm-020d4fb17f92410117bc858f586fead7c5088696.tar.gz bcm5719-llvm-020d4fb17f92410117bc858f586fead7c5088696.zip | |
New bitcode linker flags:
-only-needed -- link in only symbols needed by destination module
-internalize -- internalize linked symbols
Differential Revision: http://reviews.llvm.org/D12459
llvm-svn: 246561
Diffstat (limited to 'llvm/tools/llvm-link')
| -rw-r--r-- | llvm/tools/llvm-link/llvm-link.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp index 369f3477fe5..7f294f3e719 100644 --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -48,6 +48,12 @@ OutputFilename("o", cl::desc("Override output filename"), cl::init("-"), cl::value_desc("filename")); static cl::opt<bool> +Internalize("internalize", cl::desc("Internalize linked symbols")); + +static cl::opt<bool> +OnlyNeeded("only-needed", cl::desc("Link only needed symbols")); + +static cl::opt<bool> Force("f", cl::desc("Enable binary output on terminals")); static cl::opt<bool> @@ -114,7 +120,9 @@ static void diagnosticHandler(const DiagnosticInfo &DI) { static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, const cl::list<std::string> &Files, - bool OverrideDuplicateSymbols) { + unsigned Flags) { + // Filter out flags that don't apply to the first file we load. + unsigned ApplicableFlags = Flags & Linker::Flags::OverrideFromSrc; for (const auto &File : Files) { std::unique_ptr<Module> M = loadFile(argv0, File, Context); if (!M.get()) { @@ -130,8 +138,10 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, if (Verbose) errs() << "Linking in '" << File << "'\n"; - if (L.linkInModule(M.get(), OverrideDuplicateSymbols)) + if (L.linkInModule(M.get(), ApplicableFlags)) return false; + // All linker flags apply to linking of subsequent files. + ApplicableFlags = Flags; } return true; @@ -149,12 +159,19 @@ int main(int argc, char **argv) { auto Composite = make_unique<Module>("llvm-link", Context); Linker L(Composite.get(), 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, false)) + if (!linkFiles(argv[0], Context, L, InputFilenames, Flags)) return 1; // Next the -override ones. - if (!linkFiles(argv[0], Context, L, OverridingInputs, true)) + if (!linkFiles(argv[0], Context, L, OverridingInputs, + Flags | Linker::Flags::OverrideFromSrc)) return 1; if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite; |

