[llvm-commits] [llvm] r55997 - in /llvm/trunk: include/llvm/GlobalAlias.h lib/Linker/LinkModules.cpp lib/VMCore/Globals.cpp
Anton Korobeynikov
asl at math.spbu.ru
Tue Sep 9 11:23:48 PDT 2008
Author: asl
Date: Tue Sep 9 13:23:48 2008
New Revision: 55997
URL: http://llvm.org/viewvc/llvm-project?rev=55997&view=rev
Log:
Fix incorrect linker behaviour: we shouldn't resolve weak aliases.
Modified:
llvm/trunk/include/llvm/GlobalAlias.h
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/VMCore/Globals.cpp
Modified: llvm/trunk/include/llvm/GlobalAlias.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalAlias.h?rev=55997&r1=55996&r2=55997&view=diff
==============================================================================
--- llvm/trunk/include/llvm/GlobalAlias.h (original)
+++ llvm/trunk/include/llvm/GlobalAlias.h Tue Sep 9 13:23:48 2008
@@ -76,8 +76,10 @@
/// resolveAliasedGlobal() - This method tries to ultimately resolve the alias
/// by going through the aliasing chain and trying to find the very last
- /// global. Returns NULL if a cycle was found.
- const GlobalValue* resolveAliasedGlobal() const;
+ /// global. Returns NULL if a cycle was found. If traverseWeak is true, then
+ /// the whole chain aliasing chain is traversed, otherwise - only strong
+ /// aliases.
+ const GlobalValue* resolveAliasedGlobal(bool traverseWeak = true) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GlobalAlias *) { return true; }
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=55997&r1=55996&r2=55997&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Tue Sep 9 13:23:48 2008
@@ -1169,8 +1169,8 @@
static bool ResolveAliases(Module *Dest) {
for (Module::alias_iterator I = Dest->alias_begin(), E = Dest->alias_end();
I != E; ++I)
- if (const GlobalValue *GV = I->resolveAliasedGlobal())
- if (!GV->isDeclaration())
+ if (const GlobalValue *GV = I->resolveAliasedGlobal(/*traverseWeak*/ false))
+ if (GV != I && !GV->isDeclaration())
I->replaceAllUsesWith(const_cast<GlobalValue*>(GV));
return false;
Modified: llvm/trunk/lib/VMCore/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Globals.cpp?rev=55997&r1=55996&r2=55997&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Globals.cpp (original)
+++ llvm/trunk/lib/VMCore/Globals.cpp Tue Sep 9 13:23:48 2008
@@ -248,13 +248,21 @@
return 0;
}
-const GlobalValue *GlobalAlias::resolveAliasedGlobal() const {
+const GlobalValue *GlobalAlias::resolveAliasedGlobal(bool traverseWeak) const {
SmallPtrSet<const GlobalValue*, 3> Visited;
+ // Check if we need to stop early.
+ if (!traverseWeak && hasWeakLinkage())
+ return this;
+
const GlobalValue *GV = getAliasedGlobal();
Visited.insert(GV);
+ // Iterate over aliasing chain, stopping on weak alias if necessary.
while (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) {
+ if (traverseWeak && GA->hasWeakLinkage())
+ break;
+
GV = GA->getAliasedGlobal();
if (!Visited.insert(GV))
More information about the llvm-commits
mailing list