Index: llvm/lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -268,18 +268,6 @@ auto GVS = dyn_cast(Summary); if (!GVS) return; - // FunctionImportGlobalProcessing::doPromoteLocalToGlobal() will always - // trigger importing the initializer for `constant unnamed addr` globals that - // are referenced. We conservatively export all the referenced symbols for - // every global to workaround this, so that the ExportList is accurate. - // FIXME: with a "isConstant" flag in the summary we could be more targetted. - for (auto &Ref : GVS->refs()) { - auto GUID = Ref.getGUID(); - auto *RefSummary = FindGlobalSummaryInModule(GUID); - if (RefSummary) - // Found a ref in the current module, mark it as exported - ExportList.insert(GUID); - } } using EdgeInfo = std::pair; Index: llvm/test/ThinLTO/X86/Inputs/reference_non_importable.ll =================================================================== --- /dev/null +++ llvm/test/ThinLTO/X86/Inputs/reference_non_importable.ll @@ -0,0 +1,8 @@ +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +declare i8 **@foo() +define i32 @main() { + call i8 **@foo() + ret i32 0 +} Index: llvm/test/ThinLTO/X86/reference_non_importable.ll =================================================================== --- /dev/null +++ llvm/test/ThinLTO/X86/reference_non_importable.ll @@ -0,0 +1,28 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/reference_non_importable.ll -o %t2.bc + +; RUN: llvm-lto2 %t1.bc %t2.bc -o %t.o -save-temps \ +; RUN: -r=%t1.bc,_foo,pxl \ +; RUN: -r=%t1.bc,_b,pxl \ +; RUN: -r=%t2.bc,_main,pxl \ +; RUN: -r=%t2.bc,_foo,xl + + + + +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +; We shouldn't promote the private because it has a section +; RUN: llvm-dis < %t.o.0.2.internalize.bc | FileCheck %s --check-prefix=PROMOTE +; PROMOTE: @a = private global i8 0, section "__TEXT,__cstring,cstring_literals" +@a = private global i8 0, section "__TEXT,__cstring,cstring_literals" +@b = global i8 *@a + + +; We want foo to be imported in the main module! +; RUN: llvm-dis < %t.o.1.3.import.bc | FileCheck %s --check-prefix=IMPORT +; IMPORT: define available_externally i8** @foo() +define i8 **@foo() { + ret i8 **@b +}