summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-01-11 00:13:08 +0000
committerBill Wendling <isanbard@gmail.com>2012-01-11 00:13:08 +0000
commitc79155192d25a35cfbae5d9d474aa24713be8098 (patch)
tree85a4a55ea170929a7547ebc3ad26ddf1b567b114 /llvm/lib/Transforms
parentd9e73937412e8f837a3113efab9d4863f1f2af60 (diff)
downloadbcm5719-llvm-c79155192d25a35cfbae5d9d474aa24713be8098.tar.gz
bcm5719-llvm-c79155192d25a35cfbae5d9d474aa24713be8098.zip
If the global variable is removed by the linker, then don't constant merge it
with other symbols. An object in the __cfstring section is suppoed to be filled with CFString objects, which have a pointer to ___CFConstantStringClassReference followed by a pointer to a __cstring. If we allow the object in the __cstring section to be merged with another global, then it could end up in any section. Because the linker is going to remove these symbols in the final executable, we shouldn't bother to merge them. <rdar://problem/10564621> llvm-svn: 147899
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/ConstantMerge.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
index c3ecb7afff7..268a281aae4 100644
--- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
@@ -140,18 +140,21 @@ bool ConstantMerge::runOnModule(Module &M) {
UsedGlobals.count(GV))
continue;
+ // Ignore any constants which may be removed by the linker.
+ if (GV->mayBeRemovedByLinker())
+ continue;
+
Constant *Init = GV->getInitializer();
// Check to see if the initializer is already known.
PointerIntPair<Constant*, 1, bool> Pair(Init, hasKnownAlignment(GV));
GlobalVariable *&Slot = CMap[Pair];
- // If this is the first constant we find or if the old on is local,
- // replace with the current one. It the current is externally visible
+ // If this is the first constant we find or if the old one is local,
+ // replace with the current one. If the current is externally visible
// it cannot be replace, but can be the canonical constant we merge with.
- if (Slot == 0 || IsBetterCannonical(*GV, *Slot)) {
+ if (Slot == 0 || IsBetterCannonical(*GV, *Slot))
Slot = GV;
- }
}
// Second: identify all globals that can be merged together, filling in
@@ -169,8 +172,9 @@ bool ConstantMerge::runOnModule(Module &M) {
UsedGlobals.count(GV))
continue;
- // We can only replace constant with local linkage.
- if (!GV->hasLocalLinkage())
+ // We can only replace constants with local linkage and which aren't
+ // removed by the linker.
+ if (!GV->hasLocalLinkage() || GV->mayBeRemovedByLinker())
continue;
Constant *Init = GV->getInitializer();
OpenPOWER on IntegriCloud