Index: include/llvm/Transforms/Utils/FunctionImportUtils.h =================================================================== --- include/llvm/Transforms/Utils/FunctionImportUtils.h +++ include/llvm/Transforms/Utils/FunctionImportUtils.h @@ -21,6 +21,9 @@ namespace llvm { class Module; +// Set to true depending on option -force-import-weak +extern bool ForceImportWeakFlag; + /// Class to handle necessary GlobalValue changes required by ThinLTO /// function importing, including linkage changes and any necessary renaming. class FunctionImportGlobalProcessing { Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -102,6 +102,12 @@ static cl::opt ComputeDead("compute-dead", cl::init(true), cl::Hidden, cl::desc("Compute dead symbols")); +bool llvm::ForceImportWeakFlag; +static cl::opt +ForceImportWeak("force-import-weak", cl::Hidden, + cl::desc("Allow weak functions to be imported"), + cl::location(ForceImportWeakFlag), cl::init(false)); + static cl::opt EnableImportMetadata( "enable-import-metadata", cl::init( #if !defined(NDEBUG) @@ -169,7 +175,7 @@ // filtered out. if (GVSummary->getSummaryKind() == GlobalValueSummary::GlobalVarKind) return false; - if (GlobalValue::isInterposableLinkage(GVSummary->linkage())) + if (!ForceImportWeakFlag && GlobalValue::isInterposableLinkage(GVSummary->linkage())) // There is no point in importing these, we can't inline them return false; if (isa(GVSummary)) Index: lib/Transforms/Utils/FunctionImportUtils.cpp =================================================================== --- lib/Transforms/Utils/FunctionImportUtils.cpp +++ lib/Transforms/Utils/FunctionImportUtils.cpp @@ -151,7 +151,8 @@ // program semantics, since the linker will pick the first weak_any // definition and importing would change the order they are seen by the // linker. The module linking caller needs to enforce this. - assert(!doImportAsDefinition(SGV)); + if(!ForceImportWeakFlag) + assert(!doImportAsDefinition(SGV)); // If imported as a declaration, it becomes external_weak. return SGV->getLinkage();