A initialized global variable cannot be extern weak. However, if a global value's initializer is itself a external weak symbol, emit the weak reference.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32069 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2006-12-01 09:13:26 +00:00
parent 1c45a66873
commit 81cf60fceb
2 changed files with 16 additions and 11 deletions

View File

@ -605,6 +605,9 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
} else {
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage:
case GlobalValue::ExternalWeakLinkage:
O << "\t.weak_reference " << name << "\n";
break;
case GlobalValue::WeakLinkage:
O << "\t.globl " << name << '\n'
<< "\t.weak_definition " << name << '\n';
@ -635,6 +638,13 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
EmitAlignment(Align, I);
O << name << ":\t\t\t\t; '" << I->getName() << "'\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(Mang->getValueName(GV));
EmitGlobalConstant(C);
O << '\n';
}

View File

@ -177,17 +177,6 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
} else {
switch (I->getLinkage()) {
case GlobalValue::ExternalWeakLinkage:
if (Subtarget->isTargetDarwin()) {
assert(0 && "External weak linkage for Darwin not implemented yet");
} else if (Subtarget->isTargetCygwin()) {
// There is no external weak linkage on Mingw32 platform.
// Defaulting just to external
O << "\t.globl " << name << "\n";
} else {
O << "\t.weak " << name << "\n";
break;
}
case GlobalValue::LinkOnceLinkage:
case GlobalValue::WeakLinkage:
if (Subtarget->isTargetDarwin()) {
@ -257,6 +246,12 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
if (TAI->hasDotTypeDotSizeDirective())
O << "\t.size " << name << ", " << Size << "\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(Mang->getValueName(GV));
EmitGlobalConstant(C);
O << '\n';
}