Index: lib/LTO/LTO.cpp =================================================================== --- lib/LTO/LTO.cpp +++ lib/LTO/LTO.cpp @@ -56,6 +56,11 @@ DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden, cl::desc("Dump the SCCs in the ThinLTO index's callgraph")); +/// Enable global value internalization in LTO. +cl::opt EnableLTOInternalization( + "enable-lto-internalization", cl::init(true), cl::Hidden, + cl::desc("Enable global value internalization in LTO")); + // Returns a unique hash for the Module considering the current list of // export/import and other global analysis results. // The hash is produced in \p Key. @@ -337,7 +342,8 @@ if (isExported(S->modulePath(), GUID)) { if (GlobalValue::isLocalLinkage(S->linkage())) S->setLinkage(GlobalValue::ExternalLinkage); - } else if (!GlobalValue::isLocalLinkage(S->linkage())) + } else if (EnableLTOInternalization && + !GlobalValue::isLocalLinkage(S->linkage())) S->setLinkage(GlobalValue::InternalLinkage); } } @@ -869,7 +875,7 @@ continue; GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global : GlobalValue::UnnamedAddr::None); - if (R.second.Partition == 0) + if (EnableLTOInternalization && R.second.Partition == 0) GV->setLinkage(GlobalValue::InternalLinkage); } Index: lib/LTO/LTOCodeGenerator.cpp =================================================================== --- lib/LTO/LTOCodeGenerator.cpp +++ lib/LTO/LTOCodeGenerator.cpp @@ -70,6 +70,9 @@ #endif } +/// Enable global value internalization in LTO. +extern cl::opt EnableLTOInternalization; + namespace llvm { cl::opt LTODiscardValueNames( "lto-discard-value-names", @@ -419,7 +422,7 @@ // Preserve linkonce value on linker request preserveDiscardableGVs(*MergedModule, mustPreserveGV); - if (!ShouldInternalize) + if (!EnableLTOInternalization || !ShouldInternalize) return; if (ShouldRestoreGlobalsLinkage) { @@ -450,7 +453,8 @@ /// Restore original linkage for symbols that may have been internalized void LTOCodeGenerator::restoreLinkageForExternals() { - if (!ShouldInternalize || !ShouldRestoreGlobalsLinkage) + if (!EnableLTOInternalization || !ShouldInternalize || + !ShouldRestoreGlobalsLinkage) return; assert(ScopeRestrictionsDone &&