diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2017-03-13 18:08:11 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2017-03-13 18:08:11 +0000 |
commit | 2ebca363adc505ebdc78b7e29c78fe8b4ebf7a17 (patch) | |
tree | 29baaa1172de1445c062ae65c4dffab0301674e0 /tools/llvm-link | |
parent | 27a7060a361baaf0ad3d123c5f21b79f7a840acd (diff) |
[Linker] Provide callback for internalization
Differential Revision: https://reviews.llvm.org/D30738
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297649 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-link')
-rw-r--r-- | tools/llvm-link/llvm-link.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index e89696e7e7c..6cb647d48eb 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/SystemUtils.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Transforms/IPO/FunctionImport.h" +#include "llvm/Transforms/IPO/Internalize.h" #include "llvm/Transforms/Utils/FunctionImportUtils.h" #include <memory> @@ -272,6 +273,8 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, unsigned Flags) { // Filter out flags that don't apply to the first file we load. unsigned ApplicableFlags = Flags & Linker::Flags::OverrideFromSrc; + // Similar to some flags, internalization doesn't apply to the first file. + bool InternalizeLinkedSymbols = false; for (const auto &File : Files) { std::unique_ptr<Module> M = loadFile(argv0, File, Context); if (!M.get()) { @@ -311,8 +314,24 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, if (Verbose) errs() << "Linking in '" << File << "'\n"; - if (L.linkInModule(std::move(M), ApplicableFlags)) + bool Err = false; + if (InternalizeLinkedSymbols) { + Err = L.linkInModule( + std::move(M), ApplicableFlags, [](Module &M, const StringSet<> &GVS) { + internalizeModule(M, [&M, &GVS](const GlobalValue &GV) { + return !GV.hasName() || (GVS.count(GV.getName()) == 0); + }); + }); + } else { + Err = L.linkInModule(std::move(M), ApplicableFlags); + } + + if (Err) return false; + + // Internalization applies to linking of subsequent files. + InternalizeLinkedSymbols = Internalize; + // All linker flags apply to linking of subsequent files. ApplicableFlags = Flags; } @@ -340,8 +359,6 @@ int main(int argc, char **argv) { Linker L(*Composite); unsigned Flags = Linker::Flags::None; - if (Internalize) - Flags |= Linker::Flags::InternalizeLinkedSymbols; if (OnlyNeeded) Flags |= Linker::Flags::LinkOnlyNeeded; |