diff options
author | Chris Lattner <sabre@nondot.org> | 2004-08-04 07:05:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-08-04 07:05:54 +0000 |
commit | c003628a612d3687fb77088a5894314210a65385 (patch) | |
tree | 5e52235982b9d4b6ef05926d92541fc939c8a110 /lib/VMCore | |
parent | fe41069070f1a4b2d58a996b1f82ff747d076435 (diff) | |
download | external_llvm-c003628a612d3687fb77088a5894314210a65385.zip external_llvm-c003628a612d3687fb77088a5894314210a65385.tar.gz external_llvm-c003628a612d3687fb77088a5894314210a65385.tar.bz2 |
Factor some code out, no substantial change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Linker.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index bc1a646..cda5d71 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -378,7 +378,7 @@ static GlobalValue *FindGlobalNamed(const std::string &Name, const Type *Ty, SymbolTable *ST) { // See if an exact match exists in the symbol table... if (Value *V = ST->lookup(Ty, Name)) return cast<GlobalValue>(V); - + // It doesn't exist exactly, scan through all of the type planes in the symbol // table, checking each of them for a type-compatible version. // @@ -403,6 +403,27 @@ static GlobalValue *FindGlobalNamed(const std::string &Name, const Type *Ty, return 0; // Otherwise, nothing could be found. } +/// ForceRenaming - The LLVM SymbolTable class autorenames globals that conflict +/// in the symbol table. This is good for all clients except for us. Go +/// through the trouble to force this back. +static void ForceRenaming(GlobalValue *GV, const std::string &Name) { + assert(GV->getName() != Name && "Can't force rename to self"); + SymbolTable &ST = GV->getParent()->getSymbolTable(); + + // If there is a conflict, rename the conflict. + Value *ConflictVal = ST.lookup(GV->getType(), Name); + assert(ConflictVal&&"Why do we have to force rename if there is no conflic?"); + GlobalValue *ConflictGV = cast<GlobalValue>(ConflictVal); + assert(ConflictGV->hasInternalLinkage() && + "Not conflicting with a static global, should link instead!"); + + ConflictGV->setName(""); // Eliminate the conflict + GV->setName(Name); // Force the name back + ConflictGV->setName(Name); // This will cause ConflictGV to get renamed + assert(GV->getName() == Name() && ConflictGV->getName() != Name && + "ForceRenaming didn't work"); +} + // LinkGlobals - Loop through the global variables in the src module and merge // them into the dest module. @@ -448,15 +469,8 @@ static bool LinkGlobals(Module *Dest, const Module *Src, // If the LLVM runtime renamed the global, but it is an externally visible // symbol, DGV must be an existing global with internal linkage. Rename // it. - if (NewDGV->getName() != SGV->getName() && !NewDGV->hasInternalLinkage()){ - assert(DGV && DGV->getName() == SGV->getName() && - DGV->hasInternalLinkage()); - DGV->setName(""); - NewDGV->setName(SGV->getName()); // Force the name back - DGV->setName(SGV->getName()); // This will cause a renaming - assert(NewDGV->getName() == SGV->getName() && - DGV->getName() != SGV->getName()); - } + if (NewDGV->getName() != SGV->getName() && !NewDGV->hasInternalLinkage()) + ForceRenaming(NewDGV, SGV->getName()); // Make sure to remember this mapping... ValueMap.insert(std::make_pair(SGV, NewDGV)); @@ -622,14 +636,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src, // If the LLVM runtime renamed the function, but it is an externally // visible symbol, DF must be an existing function with internal linkage. // Rename it. - if (NewDF->getName() != SF->getName() && !NewDF->hasInternalLinkage()) { - assert(DF && DF->getName() == SF->getName() &&DF->hasInternalLinkage()); - DF->setName(""); - NewDF->setName(SF->getName()); // Force the name back - DF->setName(SF->getName()); // This will cause a renaming - assert(NewDF->getName() == SF->getName() && - DF->getName() != SF->getName()); - } + if (NewDF->getName() != SF->getName() && !NewDF->hasInternalLinkage()) + ForceRenaming(DF, SF->getName()); // ... and remember this mapping... ValueMap.insert(std::make_pair(SF, NewDF)); |