From cfca06d7963fa0909f90483b42a6d7d194d01e08 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 26 Jul 2020 19:36:28 +0000 Subject: Vendor import of llvm-project master 2e10b7a39b9, the last commit before the llvmorg-12-init tag, from which release/11.x was branched. --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'llvm/lib/Transforms/Utils/FunctionImportUtils.cpp') diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp index 26d48ee0d23fa..8df7ae9563d8a 100644 --- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -212,13 +212,6 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) { } } } - // Check the summaries to see if the symbol gets resolved to a known local - // definition. - if (VI && VI.isDSOLocal()) { - GV.setDSOLocal(true); - if (GV.hasDLLImportStorageClass()) - GV.setDLLStorageClass(GlobalValue::DefaultStorageClass); - } } // We should always have a ValueInfo (i.e. GV in index) for definitions when @@ -280,6 +273,20 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) { } else GV.setLinkage(getLinkage(&GV, /* DoPromote */ false)); + // When ClearDSOLocalOnDeclarations is true, clear dso_local if GV is + // converted to a declaration, to disable direct access. Don't do this if GV + // is implicitly dso_local due to a non-default visibility. + if (ClearDSOLocalOnDeclarations && GV.isDeclarationForLinker() && + !GV.isImplicitDSOLocal()) { + GV.setDSOLocal(false); + } else if (VI && VI.isDSOLocal()) { + // If all summaries are dso_local, symbol gets resolved to a known local + // definition. + GV.setDSOLocal(true); + if (GV.hasDLLImportStorageClass()) + GV.setDLLStorageClass(GlobalValue::DefaultStorageClass); + } + // Remove functions imported as available externally defs from comdats, // as this is a declaration for the linker, and will be dropped eventually. // It is illegal for comdats to contain declarations. @@ -319,7 +326,9 @@ bool FunctionImportGlobalProcessing::run() { } bool llvm::renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, + bool ClearDSOLocalOnDeclarations, SetVector *GlobalsToImport) { - FunctionImportGlobalProcessing ThinLTOProcessing(M, Index, GlobalsToImport); + FunctionImportGlobalProcessing ThinLTOProcessing(M, Index, GlobalsToImport, + ClearDSOLocalOnDeclarations); return ThinLTOProcessing.run(); } -- cgit v1.2.3