[llvm-commits] [llvm] r48177 - /llvm/trunk/lib/Linker/LinkModules.cpp
Anton Korobeynikov
asl at math.spbu.ru
Mon Mar 10 15:33:53 PDT 2008
Author: asl
Date: Mon Mar 10 17:33:53 2008
New Revision: 48177
URL: http://llvm.org/viewvc/llvm-project?rev=48177&view=rev
Log:
Remove the LinkGlobal weirderness in common linking phase.
Modified:
llvm/trunk/lib/Linker/LinkModules.cpp
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=48177&r1=48176&r2=48177&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Mar 10 17:33:53 2008
@@ -374,7 +374,7 @@
/// one), and computes whether this linkage is an error or not. It also performs
/// visibility checks: we cannot link together two symbols with different
/// visibilities.
-static bool GetLinkageResult(GlobalValue *Dest, GlobalValue *Src,
+static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
GlobalValue::LinkageTypes <, bool &LinkFromSrc,
std::string *Err) {
assert((!Dest || !Src->hasInternalLinkage()) &&
@@ -454,14 +454,14 @@
// LinkGlobals - Loop through the global variables in the src module and merge
// them into the dest module.
-static bool LinkGlobals(Module *Dest, Module *Src,
+static bool LinkGlobals(Module *Dest, const Module *Src,
std::map<const Value*, Value*> &ValueMap,
std::multimap<std::string, GlobalVariable *> &AppendingVars,
std::string *Err) {
// Loop over all of the globals in the src module, mapping them over as we go
- for (Module::global_iterator I = Src->global_begin(), E = Src->global_end();
+ for (Module::const_global_iterator I = Src->global_begin(), E = Src->global_end();
I != E; ++I) {
- GlobalVariable *SGV = I;
+ const GlobalVariable *SGV = I;
GlobalVariable *DGV = 0;
// Check to see if may have to link the global.
if (SGV->hasName() && !SGV->hasInternalLinkage()) {
@@ -528,42 +528,53 @@
AppendingVars.insert(std::make_pair(SGV->getName(), NewDGV));
} else {
// Otherwise, perform the mapping as instructed by GetLinkageResult.
+ if (LinkFromSrc) {
+ // Propagate alignment, section, and visibility info.
+ CopyGVAttributes(DGV, SGV);
- // Propagate alignment, section, and visibility info.
- CopyGVAttributes(DGV, SGV);
-
- // If the types don't match, and if we are to link from the source, nuke
- // DGV and create a new one of the appropriate type.
- if (SGV->getType() != DGV->getType() && LinkFromSrc) {
- GlobalVariable *NewDGV =
- new GlobalVariable(SGV->getType()->getElementType(),
- DGV->isConstant(), DGV->getLinkage());
- CopyGVAttributes(NewDGV, DGV);
- Dest->getGlobalList().insert(DGV, NewDGV);
- DGV->replaceAllUsesWith(
- ConstantExpr::getBitCast(NewDGV, DGV->getType()));
- DGV->eraseFromParent();
- NewDGV->setName(SGV->getName());
- DGV = NewDGV;
- }
+ // If the types don't match, and if we are to link from the source, nuke
+ // DGV and create a new one of the appropriate type.
+ if (SGV->getType() != DGV->getType()) {
+ GlobalVariable *NewDGV =
+ new GlobalVariable(SGV->getType()->getElementType(),
+ DGV->isConstant(), DGV->getLinkage(),
+ /*init*/0, DGV->getName(), Dest);
+ CopyGVAttributes(NewDGV, DGV);
+ DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV,
+ DGV->getType()));
+ // DGV will conflict with NewDGV because they both had the same
+ // name. We must erase this now so ForceRenaming doesn't assert
+ // because DGV might not have internal linkage.
+ DGV->eraseFromParent();
+
+ // If the symbol table 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())
+ ForceRenaming(NewDGV, SGV->getName());
- DGV->setLinkage(NewLinkage);
+ DGV = NewDGV;
+ }
- if (LinkFromSrc) {
// Inherit const as appropriate
DGV->setConstant(SGV->isConstant());
+
+ // Set initializer to zero, so we can link the stuff later
DGV->setInitializer(0);
} else {
- if (SGV->isConstant() && !DGV->isConstant()) {
- if (DGV->isDeclaration())
- DGV->setConstant(true);
- }
- SGV->setLinkage(GlobalValue::ExternalLinkage);
- SGV->setInitializer(0);
+ // Special case for const propagation
+ if (DGV->isDeclaration() && SGV->isConstant() && !DGV->isConstant())
+ DGV->setConstant(true);
}
- ValueMap.insert(
- std::make_pair(SGV, ConstantExpr::getBitCast(DGV, SGV->getType())));
+ // Set calculated linkage
+ DGV->setLinkage(NewLinkage);
+
+ // Make sure to remember this mapping...
+ ValueMap.insert(std::make_pair(SGV,
+ ConstantExpr::getBitCast(DGV,
+ SGV->getType())));
}
}
return false;
More information about the llvm-commits
mailing list