summaryrefslogtreecommitdiff
path: root/lib/CodeGen/GlobalMerge.cpp
diff options
context:
space:
mode:
authorJohn Brawn <john.brawn@arm.com>2015-08-12 13:36:48 +0000
committerJohn Brawn <john.brawn@arm.com>2015-08-12 13:36:48 +0000
commit1a5ed7be24acd9035006af4de59bb78d190bd0cc (patch)
tree80b8da464dec6a3fb0f9bfef96bf45b48d5abc79 /lib/CodeGen/GlobalMerge.cpp
parentf7d96a06fb36a698d9f8903b18ca2e3288019be8 (diff)
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244748 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/GlobalMerge.cpp')
-rw-r--r--lib/CodeGen/GlobalMerge.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/CodeGen/GlobalMerge.cpp b/lib/CodeGen/GlobalMerge.cpp
index 3a7e2f47686..d8739c4aaac 100644
--- a/lib/CodeGen/GlobalMerge.cpp
+++ b/lib/CodeGen/GlobalMerge.cpp
@@ -459,9 +459,16 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
Globals[k]->replaceAllUsesWith(GEP);
Globals[k]->eraseFromParent();
- // Generate a new alias...
- auto *PTy = cast<PointerType>(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<PointerType>(GEP->getType());
+ GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
+ }
NumMerged++;
}