diff options
author | Adrian Prantl <aprantl@apple.com> | 2016-11-11 17:50:09 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2016-11-11 17:50:09 +0000 |
commit | 554fd99dd569e8a2053040f16d71894ac97e0754 (patch) | |
tree | 967624c24fe8c403715339f886662b4585cd6e93 /llvm/lib/CodeGen/GlobalMerge.cpp | |
parent | d6e85ce3c3dad517b530fcb06c4fb20ed652a4ef (diff) | |
download | bcm5719-llvm-554fd99dd569e8a2053040f16d71894ac97e0754.tar.gz bcm5719-llvm-554fd99dd569e8a2053040f16d71894ac97e0754.zip |
Revert "Use private linkage for MergedGlobals variables" on Darwin.
This is a partial revert of r244615 (http://reviews.llvm.org/D11942),
which caused a major regression in debug info quality.
Turning the artificial __MergedGlobal symbols into private symbols
(l__MergedGlobal) means that the linker will not include them in the
symbol table of the final executable. Without a symbol table entry
dsymutil is not be able to process the debug info for any of the
merged globals and thus drops the debug info for all of them.
This patch is enabling the old behavior for all MachO targets while
leaving all other targets unaffected.
rdar://problem/29160481
https://reviews.llvm.org/D26531
llvm-svn: 286607
Diffstat (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalMerge.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index 2d9e0938fea..e0ffd475e64 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -432,6 +432,8 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, std::vector<Type*> Tys; std::vector<Constant*> Inits; + bool HasExternal = false; + GlobalVariable *TheFirstExternal = nullptr; for (j = i; j != -1; j = GlobalSet.find_next(j)) { Type *Ty = Globals[j]->getValueType(); MergedSize += DL.getTypeAllocSize(Ty); @@ -440,14 +442,34 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, } Tys.push_back(Ty); Inits.push_back(Globals[j]->getInitializer()); + + if (Globals[j]->hasExternalLinkage() && !HasExternal) { + HasExternal = true; + TheFirstExternal = Globals[j]; + } } + // If merged variables doesn't have external linkage, we needn't to expose + // the symbol after merging. + GlobalValue::LinkageTypes Linkage = HasExternal + ? GlobalValue::ExternalLinkage + : GlobalValue::InternalLinkage; StructType *MergedTy = StructType::get(M.getContext(), Tys); Constant *MergedInit = ConstantStruct::get(MergedTy, Inits); - GlobalVariable *MergedGV = new GlobalVariable( - M, MergedTy, isConst, GlobalValue::PrivateLinkage, MergedInit, - "_MergedGlobals", nullptr, GlobalVariable::NotThreadLocal, AddrSpace); + // On Darwin external linkage needs to be preserved, otherwise dsymutil + // cannot preserve the debug info for the merged variables. If they have + // external linkage, use the symbol name of the first variable merged as the + // suffix of global symbol name. This avoids a link-time naming conflict + // for the _MergedGlobals symbols. + Twine MergedName = + (IsMachO && HasExternal) + ? "_MergedGlobals_" + TheFirstExternal->getName() + : "_MergedGlobals"; + auto MergedLinkage = IsMachO ? Linkage : GlobalValue::PrivateLinkage; + auto *MergedGV = new GlobalVariable( + M, MergedTy, isConst, MergedLinkage, MergedInit, MergedName, nullptr, + GlobalVariable::NotThreadLocal, AddrSpace); const StructLayout *MergedLayout = DL.getStructLayout(MergedTy); |