From 0bef27d836f2021befadc786d44bab32f066ffbd Mon Sep 17 00:00:00 2001 From: John Brawn Date: Wed, 12 Aug 2015 13:36:48 +0000 Subject: [GlobalMerge] Only emit aliases for internal linkage variables for non-Mach-O On Mach-O emitting aliases for the variables that make up a MergedGlobals variable can cause problems when linking with dead stripping enabled so don't do that, except for external variables where we must emit an alias. llvm-svn: 244748 --- llvm/lib/CodeGen/GlobalMerge.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp') diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index 3a7e2f47686..d8739c4aaac 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -459,9 +459,16 @@ bool GlobalMerge::doMerge(SmallVectorImpl &Globals, Globals[k]->replaceAllUsesWith(GEP); Globals[k]->eraseFromParent(); - // Generate a new alias... - auto *PTy = cast(GEP->getType()); - GlobalAlias::create(PTy, Linkage, Name, GEP, &M); + // When the linkage is not internal we must emit an alias for the original + // variable name as it may be accessed from another object. On non-Mach-O + // we can also emit an alias for internal linkage as it's safe to do so. + // It's not safe on Mach-O as the alias (and thus the portion of the + // MergedGlobals variable) may be dead stripped at link time. + if (Linkage != GlobalValue::InternalLinkage || + !TM->getTargetTriple().isOSBinFormatMachO()) { + auto *PTy = cast(GEP->getType()); + GlobalAlias::create(PTy, Linkage, Name, GEP, &M); + } NumMerged++; } -- cgit v1.2.3