summaryrefslogtreecommitdiff
path: root/lib/Linker
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-06-09 07:47:34 +0000
committerChris Lattner <sabre@nondot.org>2008-06-09 07:47:34 +0000
commit822143e6f7271c6546434d2d0b3da7a29711020d (patch)
tree962fbb0a95cc681e64d11fd1b440c57d194eae4d /lib/Linker
parent824684982968244050e56357e736b9940c23e77d (diff)
downloadllvm-822143e6f7271c6546434d2d0b3da7a29711020d.tar.gz
llvm-822143e6f7271c6546434d2d0b3da7a29711020d.tar.bz2
llvm-822143e6f7271c6546434d2d0b3da7a29711020d.tar.xz
use 'continue' to make the function linker simpler. When linking a strong
function into a weak function, zap the weak function body so that the strong one overrides it. This fixes PR2410 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52135 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker')
-rw-r--r--lib/Linker/LinkModules.cpp58
1 files changed, 37 insertions, 21 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index a5e9a3e3e8..2f0cda6c41 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -916,20 +916,26 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// the declarations, we aren't adding anything.
if (SF->hasDLLImportLinkage()) {
if (DF->isDeclaration()) {
- ValueMap.insert(std::make_pair(SF, DF));
+ ValueMap[SF] = DF;
DF->setLinkage(SF->getLinkage());
- }
+ }
} else {
ValueMap[SF] = DF;
- }
- } else if (DF->isDeclaration() && !DF->hasDLLImportLinkage()) {
- // If DF is external but SF is not...
- // Link the external functions, update linkage qualifiers
+ }
+ continue;
+ }
+
+ // If DF is external but SF is not, link the external functions, update
+ // linkage qualifiers.
+ if (DF->isDeclaration() && !DF->hasDLLImportLinkage()) {
ValueMap.insert(std::make_pair(SF, DF));
DF->setLinkage(SF->getLinkage());
- } else if (SF->hasWeakLinkage() || SF->hasLinkOnceLinkage() ||
- SF->hasCommonLinkage()) {
- // At this point we know that DF has LinkOnce, Weak, or External* linkage.
+ continue;
+ }
+
+ // At this point we know that DF has LinkOnce, Weak, or External* linkage.
+ if (SF->hasWeakLinkage() || SF->hasLinkOnceLinkage() ||
+ SF->hasCommonLinkage()) {
ValueMap[SF] = DF;
// Linkonce+Weak = Weak
@@ -938,24 +944,34 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
(SF->hasWeakLinkage() || SF->hasCommonLinkage())) ||
DF->hasExternalWeakLinkage())
DF->setLinkage(SF->getLinkage());
- } else if (DF->hasWeakLinkage() || DF->hasLinkOnceLinkage() ||
- DF->hasCommonLinkage()) {
+ continue;
+ }
+
+ if (DF->hasWeakLinkage() || DF->hasLinkOnceLinkage() ||
+ DF->hasCommonLinkage()) {
// At this point we know that SF has LinkOnce or External* linkage.
ValueMap[SF] = DF;
- if (!SF->hasLinkOnceLinkage() && !SF->hasExternalWeakLinkage())
- // Don't inherit linkonce & external weak linkage
+
+ // If the source function has stronger linkage than the destination,
+ // its body and linkage should override ours.
+ if (!SF->hasLinkOnceLinkage() && !SF->hasExternalWeakLinkage()) {
+ // Don't inherit linkonce & external weak linkage.
DF->setLinkage(SF->getLinkage());
- } else if (SF->getLinkage() != DF->getLinkage()) {
- return Error(Err, "Functions named '" + SF->getName() +
- "' have different linkage specifiers!");
- } else if (SF->hasExternalLinkage()) {
- // The function is defined identically in both modules!!
+ DF->deleteBody();
+ }
+ continue;
+ }
+
+ if (SF->getLinkage() != DF->getLinkage())
+ return Error(Err, "Functions named '" + SF->getName() +
+ "' have different linkage specifiers!");
+
+ // The function is defined identically in both modules!
+ if (SF->hasExternalLinkage())
return Error(Err, "Function '" +
ToStr(SF->getFunctionType(), Src) + "':\"" +
SF->getName() + "\" - Function is already defined!");
- } else {
- assert(0 && "Unknown linkage configuration found!");
- }
+ assert(0 && "Unknown linkage configuration found!");
}
return false;
}