ThinLTO/ModuleLinker: add a flag to not always pull-in linkonce when performing importing
Summary:
The function importer already decided what symbols need to be pulled
in. Also these magically added ones will not be in the export list
for the source module, which can confuse the internalizer for
instance.
Reviewers: tejohnson, rafael
Subscribers: joker.eph, llvm-commits
Differential Revision: http://reviews.llvm.org/D19096
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266948
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index cd3cd52..8ed8856 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -45,6 +45,9 @@
/// to Add.
void addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add);
+ bool shouldLinkReferencedLinkOnce() {
+ return !(Flags & Linker::DontForceLinkLinkonceODR);
+ }
bool shouldOverrideFromSrc() { return Flags & Linker::OverrideFromSrc; }
bool shouldLinkOnlyNeeded() { return Flags & Linker::LinkOnlyNeeded; }
bool shouldInternalizeLinkedSymbols() {
@@ -413,6 +416,12 @@
}
void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) {
+ if (!shouldLinkReferencedLinkOnce())
+ // For ThinLTO we don't import more than what was required.
+ // The client has to guarantee that the linkonce will be availabe at link
+ // time (by promoting it to weak for instance).
+ return;
+
// Add these to the internalize list
if (!GV.hasLinkOnceLinkage())
return;