mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-31 10:34:17 +00:00
Move some logic to ModuleLinker::shouldLinkFromSource. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217449 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
beab873680
commit
7b1723dc85
@ -420,6 +420,8 @@ namespace {
|
|||||||
bool run();
|
bool run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool shouldLinkFromSource(const GlobalValue &Dest, const GlobalValue &Src);
|
||||||
|
|
||||||
/// emitError - Helper method for setting a message and returning an error
|
/// emitError - Helper method for setting a message and returning an error
|
||||||
/// code.
|
/// code.
|
||||||
bool emitError(const Twine &Message) {
|
bool emitError(const Twine &Message) {
|
||||||
@ -681,6 +683,48 @@ static bool isDeclaration(const GlobalValue &V) {
|
|||||||
return V.isDeclaration();
|
return V.isDeclaration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ModuleLinker::shouldLinkFromSource(const GlobalValue &Dest,
|
||||||
|
const GlobalValue &Src) {
|
||||||
|
bool SrcIsDeclaration = isDeclaration(Src);
|
||||||
|
bool DestIsDeclaration = isDeclaration(Dest);
|
||||||
|
|
||||||
|
if (SrcIsDeclaration) {
|
||||||
|
// If Src is external or if both Src & Dest are external.. Just link the
|
||||||
|
// external globals, we aren't adding anything.
|
||||||
|
if (Src.hasDLLImportStorageClass())
|
||||||
|
// If one of GVs is marked as DLLImport, result should be dllimport'ed.
|
||||||
|
return DestIsDeclaration;
|
||||||
|
// If the Dest is weak, use the source linkage.
|
||||||
|
return Dest.hasExternalWeakLinkage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DestIsDeclaration)
|
||||||
|
// If Dest is external but Src is not:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (Src.isWeakForLinker()) {
|
||||||
|
assert(!Dest.hasExternalWeakLinkage());
|
||||||
|
assert(!Dest.hasAvailableExternallyLinkage());
|
||||||
|
if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage()) &&
|
||||||
|
Src.hasCommonLinkage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Dest.isWeakForLinker()) {
|
||||||
|
assert(Src.hasExternalLinkage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(!Src.hasExternalWeakLinkage());
|
||||||
|
assert(!Dest.hasExternalWeakLinkage());
|
||||||
|
assert(Dest.hasExternalLinkage() && Src.hasExternalLinkage() &&
|
||||||
|
"Unexpected linkage type!");
|
||||||
|
return emitError("Linking globals named '" + Src.getName() +
|
||||||
|
"': symbol multiply defined!");
|
||||||
|
}
|
||||||
|
|
||||||
/// This analyzes the two global values and determines what the result will look
|
/// This analyzes the two global values and determines what the result will look
|
||||||
/// like in the destination module. In particular, it computes the resultant
|
/// like in the destination module. In particular, it computes the resultant
|
||||||
/// linkage type and visibility, computes whether the global in the source
|
/// linkage type and visibility, computes whether the global in the source
|
||||||
@ -694,57 +738,15 @@ bool ModuleLinker::getLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
|
|||||||
assert(!Src->hasLocalLinkage() &&
|
assert(!Src->hasLocalLinkage() &&
|
||||||
"If Src has internal linkage, Dest shouldn't be set!");
|
"If Src has internal linkage, Dest shouldn't be set!");
|
||||||
|
|
||||||
bool SrcIsDeclaration = isDeclaration(*Src);
|
assert(ErrorMsg.empty());
|
||||||
bool DestIsDeclaration = isDeclaration(*Dest);
|
LinkFromSrc = shouldLinkFromSource(*Dest, *Src);
|
||||||
|
if (!ErrorMsg.empty())
|
||||||
|
return true;
|
||||||
|
|
||||||
if (SrcIsDeclaration) {
|
if (LinkFromSrc)
|
||||||
// If Src is external or if both Src & Dest are external.. Just link the
|
|
||||||
// external globals, we aren't adding anything.
|
|
||||||
if (Src->hasDLLImportStorageClass()) {
|
|
||||||
// If one of GVs is marked as DLLImport, result should be dllimport'ed.
|
|
||||||
if (DestIsDeclaration) {
|
|
||||||
LinkFromSrc = true;
|
|
||||||
LT = Src->getLinkage();
|
|
||||||
} else {
|
|
||||||
LinkFromSrc = false;
|
|
||||||
LT = Dest->getLinkage();
|
|
||||||
}
|
|
||||||
} else if (Dest->hasExternalWeakLinkage()) {
|
|
||||||
// If the Dest is weak, use the source linkage.
|
|
||||||
LinkFromSrc = true;
|
|
||||||
LT = Src->getLinkage();
|
|
||||||
} else {
|
|
||||||
LinkFromSrc = false;
|
|
||||||
LT = Dest->getLinkage();
|
|
||||||
}
|
|
||||||
} else if (DestIsDeclaration) {
|
|
||||||
// If Dest is external but Src is not:
|
|
||||||
LinkFromSrc = true;
|
|
||||||
LT = Src->getLinkage();
|
LT = Src->getLinkage();
|
||||||
} else if (Src->isWeakForLinker()) {
|
else
|
||||||
assert(!Dest->hasExternalWeakLinkage());
|
LT = Dest->getLinkage();
|
||||||
assert(!Dest->hasAvailableExternallyLinkage());
|
|
||||||
if ((Dest->hasLinkOnceLinkage() && Src->hasWeakLinkage()) ||
|
|
||||||
((Dest->hasLinkOnceLinkage() || Dest->hasWeakLinkage()) &&
|
|
||||||
Src->hasCommonLinkage())) {
|
|
||||||
LinkFromSrc = true;
|
|
||||||
LT = Src->getLinkage();
|
|
||||||
} else {
|
|
||||||
LinkFromSrc = false;
|
|
||||||
LT = Dest->getLinkage();
|
|
||||||
}
|
|
||||||
} else if (Dest->isWeakForLinker()) {
|
|
||||||
assert(!Src->hasExternalWeakLinkage());
|
|
||||||
LinkFromSrc = true;
|
|
||||||
LT = GlobalValue::ExternalLinkage;
|
|
||||||
} else {
|
|
||||||
assert(!Src->hasExternalWeakLinkage());
|
|
||||||
assert(!Dest->hasExternalWeakLinkage());
|
|
||||||
assert(Dest->hasExternalLinkage() && Src->hasExternalLinkage() &&
|
|
||||||
"Unexpected linkage type!");
|
|
||||||
return emitError("Linking globals named '" + Src->getName() +
|
|
||||||
"': symbol multiply defined!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute the visibility. We follow the rules in the System V Application
|
// Compute the visibility. We follow the rules in the System V Application
|
||||||
// Binary Interface.
|
// Binary Interface.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user