FnDeclareLinkage: /*default*/ |
DLLIMPORT { CurFun.Linkage = GlobalValue::DLLImportLinkage; } |
- EXTERN_WEAK { CurFun.Linkage = GlobalValue::DLLImportLinkage; };
+ EXTERN_WEAK { CurFun.Linkage = GlobalValue::ExternalWeakLinkage; };
FunctionProto : DECLARE { CurFun.isDeclare = true; } FnDeclareLinkage FunctionHeaderH {
$$ = CurFun.CurrentFunction;
// Otherwise, we know it's linkonce/weak, replace it if this is a strong
// symbol.
- if (GV->hasExternalLinkage())
+ if (GV->hasExternalLinkage() || GVEntry->hasExternalWeakLinkage())
GVEntry = GV;
}
}
// If Src is external or if both Src & Drc are external.. Just link the
// external globals, we aren't adding anything.
if (Src->hasDLLImportLinkage()) {
+ // If one of GVs has DLLImport linkage, result should be dllimport'ed.
if (Dest->isExternal()) {
LinkFromSrc = true;
LT = Src->getLinkage();
LinkFromSrc = true; // Special cased.
LT = Src->getLinkage();
} else if (Src->hasWeakLinkage() || Src->hasLinkOnceLinkage()) {
- // At this point we know that Dest has LinkOnce, External, Weak, DLL* linkage.
- if (Dest->hasLinkOnceLinkage() && Src->hasWeakLinkage()) {
+ // At this point we know that Dest has LinkOnce, External*, Weak, DLL* linkage.
+ if ((Dest->hasLinkOnceLinkage() && Src->hasWeakLinkage()) ||
+ Dest->hasExternalWeakLinkage()) {
LinkFromSrc = true;
LT = Src->getLinkage();
} else {
LT = Dest->getLinkage();
}
} else if (Dest->hasWeakLinkage() || Dest->hasLinkOnceLinkage()) {
- // At this point we know that Src has External or DLL* linkage.
- LinkFromSrc = true;
- LT = GlobalValue::ExternalLinkage;
+ // At this point we know that Src has External* or DLL* linkage.
+ if (Src->hasExternalWeakLinkage()) {
+ LinkFromSrc = false;
+ LT = Dest->getLinkage();
+ } else {
+ LinkFromSrc = true;
+ LT = GlobalValue::ExternalLinkage;
+ }
} else {
assert((Dest->hasExternalLinkage() ||
Dest->hasDLLImportLinkage() ||
- Dest->hasDLLExportLinkage()) &&
+ Dest->hasDLLExportLinkage() ||
+ Dest->hasExternalWeakLinkage()) &&
(Src->hasExternalLinkage() ||
Src->hasDLLImportLinkage() ||
- Src->hasDLLExportLinkage()) &&
+ Src->hasDLLExportLinkage() ||
+ Src->hasExternalWeakLinkage()) &&
"Unexpected linkage type!");
return Error(Err, "Linking globals named '" + Src->getName() +
"': symbol multiply defined!");
ValueMap.insert(std::make_pair(SF, DF));
DF->setLinkage(SF->getLinkage());
} else if (SF->hasWeakLinkage() || SF->hasLinkOnceLinkage()) {
- // At this point we know that DF has LinkOnce, Weak, or External linkage.
+ // At this point we know that DF has LinkOnce, Weak, or External* linkage.
ValueMap.insert(std::make_pair(SF, DF));
// Linkonce+Weak = Weak
- if (DF->hasLinkOnceLinkage() && SF->hasWeakLinkage())
+ // *+External Weak = *
+ if ((DF->hasLinkOnceLinkage() && SF->hasWeakLinkage()) ||
+ DF->hasExternalWeakLinkage())
DF->setLinkage(SF->getLinkage());
+
} else if (DF->hasWeakLinkage() || DF->hasLinkOnceLinkage()) {
- // At this point we know that SF has LinkOnce or External linkage.
+ // 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
+ 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!");
<< "#define __attribute__(X)\n"
<< "#endif\n\n";
-#if 0
- // At some point, we should support "external weak" vs. "weak" linkages.
// On Mac OS X, "external weak" is spelled "__attribute__((weak_import))".
Out << "#if defined(__GNUC__) && defined(__APPLE_CC__)\n"
<< "#define __EXTERNAL_WEAK__ __attribute__((weak_import))\n"
<< "#else\n"
<< "#define __EXTERNAL_WEAK__\n"
<< "#endif\n\n";
-#endif
// For now, turn off the weak linkage attribute on Mac OS X. (See above.)
Out << "#if defined(__GNUC__) && defined(__APPLE_CC__)\n"
Out << "__declspec(dllimport) ";
printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
Out << ";\n";
- }
+ } else if (I->hasExternalWeakLinkage()) {
+ Out << "extern ";
+ printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+ Out << " __EXTERNAL_WEAK__ ;\n";
+ }
}
}
// Don't print declarations for intrinsic functions.
if (!I->getIntrinsicID() && I->getName() != "setjmp" &&
I->getName() != "longjmp" && I->getName() != "_setjmp") {
+ if (I->hasExternalWeakLinkage())
+ Out << "extern ";
printFunctionSignature(I, true);
if (I->hasWeakLinkage() || I->hasLinkOnceLinkage())
Out << " __ATTRIBUTE_WEAK__";
+ if (I->hasExternalWeakLinkage())
+ Out << " __EXTERNAL_WEAK__";
if (StaticCtors.count(I))
Out << " __ATTRIBUTE_CTOR__";
if (StaticDtors.count(I))
Out << " __attribute__((common))";
else if (I->hasWeakLinkage())
Out << " __ATTRIBUTE_WEAK__";
+ else if (I->hasExternalWeakLinkage())
+ Out << " __EXTERNAL_WEAK__";
Out << ";\n";
}
}
<< "#define __attribute__(X)\n"
<< "#endif\n\n";
-#if 0
- // At some point, we should support "external weak" vs. "weak" linkages.
// On Mac OS X, "external weak" is spelled "__attribute__((weak_import))".
Out << "#if defined(__GNUC__) && defined(__APPLE_CC__)\n"
<< "#define __EXTERNAL_WEAK__ __attribute__((weak_import))\n"
<< "#else\n"
<< "#define __EXTERNAL_WEAK__\n"
<< "#endif\n\n";
-#endif
// For now, turn off the weak linkage attribute on Mac OS X. (See above.)
Out << "#if defined(__GNUC__) && defined(__APPLE_CC__)\n"
Out << "__declspec(dllimport) ";
printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
Out << ";\n";
- }
+ } else if (I->hasExternalWeakLinkage()) {
+ Out << "extern ";
+ printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+ Out << " __EXTERNAL_WEAK__ ;\n";
+ }
}
}
// Don't print declarations for intrinsic functions.
if (!I->getIntrinsicID() && I->getName() != "setjmp" &&
I->getName() != "longjmp" && I->getName() != "_setjmp") {
+ if (I->hasExternalWeakLinkage())
+ Out << "extern ";
printFunctionSignature(I, true);
if (I->hasWeakLinkage() || I->hasLinkOnceLinkage())
Out << " __ATTRIBUTE_WEAK__";
+ if (I->hasExternalWeakLinkage())
+ Out << " __EXTERNAL_WEAK__";
if (StaticCtors.count(I))
Out << " __ATTRIBUTE_CTOR__";
if (StaticDtors.count(I))
Out << " __attribute__((common))";
else if (I->hasWeakLinkage())
Out << " __ATTRIBUTE_WEAK__";
+ else if (I->hasExternalWeakLinkage())
+ Out << " __EXTERNAL_WEAK__";
Out << ";\n";
}
}
}
O << Name;
}
+
+ if (GV->hasExternalWeakLinkage()) {
+ ExtWeakSymbols.insert(Name);
+ }
int Offset = MO.getOffset();
if (Offset > 0)
// from how MASM does things. When making changes here don't forget to look
// at X86IntelAsmPrinter::doFinalization().
const TargetData *TD = TM.getTargetData();
-
+
// Print out module-level global variables here.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
- if (!I->hasInitializer()) continue; // External global require no code
+ if (!I->hasInitializer() && !I->hasExternalWeakLinkage())
+ continue; // External global require no code
// Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(I))
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()) {
i != e; ++i) {
O << "\t.ascii \" -export:" << *i << "\"\n";
}
-
+
+ if (Subtarget->isTargetDarwin()) {
+ if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
+ assert(0 && "External weak linkage for Darwin not implemented yet");
+ } else if (Subtarget->isTargetCygwin()) {
+ // There is no external weak linkage on Mingw32 platform.
+ // Defaulting to external
+ } else {
+ if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
+ SwitchToDataSection("");
+
+ for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
+ e = ExtWeakSymbols.end();
+ i != e; ++i) {
+ O << "\t.weak " << *i << "\n";
+ }
+ }
+
if (Subtarget->isTargetDarwin()) {
SwitchToDataSection("");
// Necessary for dllexport support
std::set<std::string> DLLExportedFns, DLLExportedGVs;
+
+ // Necessary for external weak linkage support
+ std::set<std::string> ExtWeakSymbols;
inline static bool isScale(const MachineOperand &MO) {
return MO.isImmediate() &&
case Instruction::PtrToInt:
// Cast of a global address to boolean is always true.
- if (isa<GlobalValue>(V)) {
- if (DestTy == Type::BoolTy)
- // FIXME: When we support 'external weak' references, we have to
- // prevent this transformation from happening. This code will need
- // to be updated to ignore external weak symbols when we support it.
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+ if (DestTy == Type::BoolTy && !GV->hasExternalWeakLinkage())
return ConstantBool::getTrue();
}
break;