OptLinkage : INTERNAL { $$ = GlobalValue::InternalLinkage; } |
LINKONCE { $$ = GlobalValue::LinkOnceLinkage; } |
- WEAK { $$ = GlobalValue::LinkOnceLinkage; /* FIXME */ } |
+ WEAK { $$ = GlobalValue::WeakLinkage; } |
APPENDING { $$ = GlobalValue::AppendingLinkage; } |
/*empty*/ { $$ = GlobalValue::ExternalLinkage; };
} else if (DGV->isExternal()) { // If DGV is external but SGV is not...
ValueMap.insert(std::make_pair(SGV, DGV));
DGV->setLinkage(SGV->getLinkage()); // Inherit linkage!
+ } else if (SGV->hasWeakLinkage()) {
+ // At this point we know that DGV has LinkOnce, Appending, Weak, or
+ // External linkage. If DGV is Appending, this is an error.
+ if (DGV->hasAppendingLinkage())
+ return Error(Err, "Linking globals named '" + SGV->getName() +
+ " ' with 'weak' and 'appending' linkage is not allowed!");
+ // Otherwise, just perform the link.
+ ValueMap.insert(std::make_pair(SGV, DGV));
+ } else if (DGV->hasWeakLinkage()) {
+ // At this point we know that SGV has LinkOnce, Appending, or External
+ // linkage. If SGV is Appending, this is an error.
+ if (SGV->hasAppendingLinkage())
+ return Error(Err, "Linking globals named '" + SGV->getName() +
+ " ' with 'weak' and 'appending' linkage is not allowed!");
+ if (!SGV->hasLinkOnceLinkage())
+ DGV->setLinkage(SGV->getLinkage()); // Inherit linkage!
+ ValueMap.insert(std::make_pair(SGV, DGV));
+
} else if (SGV->getLinkage() != DGV->getLinkage()) {
return Error(Err, "Global variables named '" + SGV->getName() +
"' have different linkage specifiers!");
return Error(Err, "Global Variable Collision on '" +
SGV->getType()->getDescription() +"':%"+SGV->getName()+
" - Global variables have different initializers");
- } else if (DGV->hasLinkOnceLinkage()) {
+ } else if (DGV->hasLinkOnceLinkage() || DGV->hasWeakLinkage()) {
// Nothing is required, mapped values will take the new global
// automatically.
} else if (DGV->hasAppendingLinkage()) {
ValueMap.insert(std::make_pair(SF, DF));
DF->setLinkage(SF->getLinkage());
+ } else if (SF->hasWeakLinkage()) {
+ // At this point we know that DF has LinkOnce, Weak, or External linkage.
+ ValueMap.insert(std::make_pair(SF, DF));
+
+ } else if (DF->hasWeakLinkage()) {
+ // At this point we know that SF has LinkOnce or External linkage.
+ ValueMap.insert(std::make_pair(SF, DF));
+ if (!SF->hasLinkOnceLinkage()) // Don't inherit linkonce linkage
+ DF->setLinkage(SF->getLinkage());
+
} else if (SF->getLinkage() != DF->getLinkage()) {
return Error(Err, "Functions named '" + SF->getName() +
"' have different linkage specifiers!");
// DF not external SF external?
if (!DF->isExternal()) {
if (DF->hasLinkOnceLinkage()) continue; // No relinkage for link-once!
- if (Err)
- *Err = "Function '" + (SF->hasName() ? SF->getName() :std::string(""))
- + "' body multiply defined!";
- return true;
+ if (SF->hasWeakLinkage()) continue;
+ return Error(Err, "Function '" + SF->getName() +
+ "' body multiply defined!");
}
if (LinkFunctionBody(DF, SF, ValueMap, Err)) return true;
printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
if (I->hasLinkOnceLinkage())
Out << " __attribute__((common))";
+ else if (I->hasWeakLinkage())
+ Out << " __attribute__((weak))";
if (!I->getInitializer()->isNullValue()) {
Out << " = " ;
writeOperand(I->getInitializer());
FunctionInnards << ")";
// Print out the return type and the entire signature for that matter
printType(Out, F->getReturnType(), FunctionInnards.str());
+
+ if (F->hasWeakLinkage()) Out << " __attribute((weak))";
}
void CWriter::printFunction(Function *F) {
printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
if (I->hasLinkOnceLinkage())
Out << " __attribute__((common))";
+ else if (I->hasWeakLinkage())
+ Out << " __attribute__((weak))";
if (!I->getInitializer()->isNullValue()) {
Out << " = " ;
writeOperand(I->getInitializer());
FunctionInnards << ")";
// Print out the return type and the entire signature for that matter
printType(Out, F->getReturnType(), FunctionInnards.str());
+
+ if (F->hasWeakLinkage()) Out << " __attribute((weak))";
}
void CWriter::printFunction(Function *F) {
unsigned Align = TD.getTypeAlignment(C->getType());
if (C->isNullValue() &&
- (I->hasLinkOnceLinkage() || I->hasInternalLinkage())) {
+ (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
+ I->hasWeakLinkage() /* FIXME: Verify correct */)) {
SwitchSection(O, CurSection, ".data");
if (I->hasInternalLinkage())
O << "\t.local " << name << "\n";
} else {
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage:
+ case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
// Nonnull linkonce -> weak
O << "\t.weak " << name << "\n";
SwitchSection(O, CurSection, "");
unsigned Align = TD.getTypeAlignment(C->getType());
if (C->isNullValue() &&
- (I->hasLinkOnceLinkage() || I->hasInternalLinkage())) {
+ (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
+ I->hasWeakLinkage() /* FIXME: Verify correct */)) {
SwitchSection(O, CurSection, ".data");
if (I->hasInternalLinkage())
O << "\t.local " << name << "\n";
} else {
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage:
+ case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
// Nonnull linkonce -> weak
O << "\t.weak " << name << "\n";
SwitchSection(O, CurSection, "");
} else if (DGV->isExternal()) { // If DGV is external but SGV is not...
ValueMap.insert(std::make_pair(SGV, DGV));
DGV->setLinkage(SGV->getLinkage()); // Inherit linkage!
+ } else if (SGV->hasWeakLinkage()) {
+ // At this point we know that DGV has LinkOnce, Appending, Weak, or
+ // External linkage. If DGV is Appending, this is an error.
+ if (DGV->hasAppendingLinkage())
+ return Error(Err, "Linking globals named '" + SGV->getName() +
+ " ' with 'weak' and 'appending' linkage is not allowed!");
+ // Otherwise, just perform the link.
+ ValueMap.insert(std::make_pair(SGV, DGV));
+ } else if (DGV->hasWeakLinkage()) {
+ // At this point we know that SGV has LinkOnce, Appending, or External
+ // linkage. If SGV is Appending, this is an error.
+ if (SGV->hasAppendingLinkage())
+ return Error(Err, "Linking globals named '" + SGV->getName() +
+ " ' with 'weak' and 'appending' linkage is not allowed!");
+ if (!SGV->hasLinkOnceLinkage())
+ DGV->setLinkage(SGV->getLinkage()); // Inherit linkage!
+ ValueMap.insert(std::make_pair(SGV, DGV));
+
} else if (SGV->getLinkage() != DGV->getLinkage()) {
return Error(Err, "Global variables named '" + SGV->getName() +
"' have different linkage specifiers!");
return Error(Err, "Global Variable Collision on '" +
SGV->getType()->getDescription() +"':%"+SGV->getName()+
" - Global variables have different initializers");
- } else if (DGV->hasLinkOnceLinkage()) {
+ } else if (DGV->hasLinkOnceLinkage() || DGV->hasWeakLinkage()) {
// Nothing is required, mapped values will take the new global
// automatically.
} else if (DGV->hasAppendingLinkage()) {
ValueMap.insert(std::make_pair(SF, DF));
DF->setLinkage(SF->getLinkage());
+ } else if (SF->hasWeakLinkage()) {
+ // At this point we know that DF has LinkOnce, Weak, or External linkage.
+ ValueMap.insert(std::make_pair(SF, DF));
+
+ } else if (DF->hasWeakLinkage()) {
+ // At this point we know that SF has LinkOnce or External linkage.
+ ValueMap.insert(std::make_pair(SF, DF));
+ if (!SF->hasLinkOnceLinkage()) // Don't inherit linkonce linkage
+ DF->setLinkage(SF->getLinkage());
+
} else if (SF->getLinkage() != DF->getLinkage()) {
return Error(Err, "Functions named '" + SF->getName() +
"' have different linkage specifiers!");
// DF not external SF external?
if (!DF->isExternal()) {
if (DF->hasLinkOnceLinkage()) continue; // No relinkage for link-once!
- if (Err)
- *Err = "Function '" + (SF->hasName() ? SF->getName() :std::string(""))
- + "' body multiply defined!";
- return true;
+ if (SF->hasWeakLinkage()) continue;
+ return Error(Err, "Function '" + SF->getName() +
+ "' body multiply defined!");
}
if (LinkFunctionBody(DF, SF, ValueMap, Err)) return true;
Out << "external ";
else
switch (GV->getLinkage()) {
- case GlobalValue::InternalLinkage: Out << "internal "; break;
- case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
+ case GlobalValue::InternalLinkage: Out << "internal "; break;
+ case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
+ case GlobalValue::WeakLinkage: Out << "weak "; break;
case GlobalValue::AppendingLinkage: Out << "appending "; break;
case GlobalValue::ExternalLinkage: break;
}
Out << "declare ";
else
switch (F->getLinkage()) {
- case GlobalValue::InternalLinkage: Out << "internal "; break;
- case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
+ case GlobalValue::InternalLinkage: Out << "internal "; break;
+ case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
+ case GlobalValue::WeakLinkage: Out << "weak "; break;
case GlobalValue::AppendingLinkage: Out << "appending "; break;
case GlobalValue::ExternalLinkage: break;
}
} else if (DGV->isExternal()) { // If DGV is external but SGV is not...
ValueMap.insert(std::make_pair(SGV, DGV));
DGV->setLinkage(SGV->getLinkage()); // Inherit linkage!
+ } else if (SGV->hasWeakLinkage()) {
+ // At this point we know that DGV has LinkOnce, Appending, Weak, or
+ // External linkage. If DGV is Appending, this is an error.
+ if (DGV->hasAppendingLinkage())
+ return Error(Err, "Linking globals named '" + SGV->getName() +
+ " ' with 'weak' and 'appending' linkage is not allowed!");
+ // Otherwise, just perform the link.
+ ValueMap.insert(std::make_pair(SGV, DGV));
+ } else if (DGV->hasWeakLinkage()) {
+ // At this point we know that SGV has LinkOnce, Appending, or External
+ // linkage. If SGV is Appending, this is an error.
+ if (SGV->hasAppendingLinkage())
+ return Error(Err, "Linking globals named '" + SGV->getName() +
+ " ' with 'weak' and 'appending' linkage is not allowed!");
+ if (!SGV->hasLinkOnceLinkage())
+ DGV->setLinkage(SGV->getLinkage()); // Inherit linkage!
+ ValueMap.insert(std::make_pair(SGV, DGV));
+
} else if (SGV->getLinkage() != DGV->getLinkage()) {
return Error(Err, "Global variables named '" + SGV->getName() +
"' have different linkage specifiers!");
return Error(Err, "Global Variable Collision on '" +
SGV->getType()->getDescription() +"':%"+SGV->getName()+
" - Global variables have different initializers");
- } else if (DGV->hasLinkOnceLinkage()) {
+ } else if (DGV->hasLinkOnceLinkage() || DGV->hasWeakLinkage()) {
// Nothing is required, mapped values will take the new global
// automatically.
} else if (DGV->hasAppendingLinkage()) {
ValueMap.insert(std::make_pair(SF, DF));
DF->setLinkage(SF->getLinkage());
+ } else if (SF->hasWeakLinkage()) {
+ // At this point we know that DF has LinkOnce, Weak, or External linkage.
+ ValueMap.insert(std::make_pair(SF, DF));
+
+ } else if (DF->hasWeakLinkage()) {
+ // At this point we know that SF has LinkOnce or External linkage.
+ ValueMap.insert(std::make_pair(SF, DF));
+ if (!SF->hasLinkOnceLinkage()) // Don't inherit linkonce linkage
+ DF->setLinkage(SF->getLinkage());
+
} else if (SF->getLinkage() != DF->getLinkage()) {
return Error(Err, "Functions named '" + SF->getName() +
"' have different linkage specifiers!");
// DF not external SF external?
if (!DF->isExternal()) {
if (DF->hasLinkOnceLinkage()) continue; // No relinkage for link-once!
- if (Err)
- *Err = "Function '" + (SF->hasName() ? SF->getName() :std::string(""))
- + "' body multiply defined!";
- return true;
+ if (SF->hasWeakLinkage()) continue;
+ return Error(Err, "Function '" + SF->getName() +
+ "' body multiply defined!");
}
if (LinkFunctionBody(DF, SF, ValueMap, Err)) return true;