unsigned Size = TD->getTypeSize(C->getType());
unsigned Align = TD->getPreferredAlignmentLog(I);
- if (C->isNullValue() && /* FIXME: Verify correct */
- !I->hasSection() &&
- (I->hasInternalLinkage() || I->hasWeakLinkage() ||
- I->hasLinkOnceLinkage() ||
- (Subtarget->isTargetDarwin() &&
- I->hasExternalLinkage()))) {
- if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
+ if (I->hasHiddenVisibility())
+ if (const char *Directive = TAI->getHiddenDirective())
+ O << Directive << name << "\n";
+ if (Subtarget->isTargetELF())
+ O << "\t.type " << name << ",@object\n";
+
+ if (C->isNullValue()) {
if (I->hasExternalLinkage()) {
+ if (const char *Directive = TAI->getZeroFillDirective()) {
O << "\t.globl\t" << name << "\n";
- O << "\t.zerofill __DATA__, __common, " << name << ", "
+ O << Directive << "__DATA__, __common, " << name << ", "
<< Size << ", " << Align;
- } else {
+ continue;
+ }
+ }
+
+ if (!I->hasSection() &&
+ (I->hasInternalLinkage() || I->hasWeakLinkage() ||
+ I->hasLinkOnceLinkage())) {
+ if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (!NoZerosInBSS && TAI->getBSSSection())
SwitchToDataSection(TAI->getBSSSection(), I);
else
if (TAI->getCOMMDirectiveTakesAlignment())
O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
}
+ O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
+ continue;
}
- O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
- } else {
- switch (I->getLinkage()) {
- case GlobalValue::LinkOnceLinkage:
- case GlobalValue::WeakLinkage:
- if (Subtarget->isTargetDarwin()) {
- O << "\t.globl " << name << "\n"
- << "\t.weak_definition " << name << "\n";
- SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
- } else if (Subtarget->isTargetCygMing()) {
- std::string SectionName(".section\t.data$linkonce." +
- name +
- ",\"aw\"");
- SwitchToDataSection(SectionName.c_str(), I);
- O << "\t.globl " << name << "\n"
- << "\t.linkonce same_size\n";
- } else {
- std::string SectionName("\t.section\t.llvm.linkonce.d." +
- name +
- ",\"aw\",@progbits");
- SwitchToDataSection(SectionName.c_str(), I);
- O << "\t.weak " << name << "\n";
- }
- break;
- case GlobalValue::AppendingLinkage:
- // FIXME: appending linkage variables should go into a section of
- // their name or something. For now, just emit them as external.
- case GlobalValue::DLLExportLinkage:
- DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
- // FALL THROUGH
- case GlobalValue::ExternalLinkage:
- // If external or appending, declare as a global symbol
- O << "\t.globl " << name << "\n";
- // FALL THROUGH
- case GlobalValue::InternalLinkage: {
- if (I->isConstant()) {
- const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
- if (TAI->getCStringSection() && CVA && CVA->isCString()) {
- SwitchToDataSection(TAI->getCStringSection(), I);
- break;
- }
- }
- // FIXME: special handling for ".ctors" & ".dtors" sections
- if (I->hasSection() &&
- (I->getSection() == ".ctors" ||
- I->getSection() == ".dtors")) {
- std::string SectionName = ".section " + I->getSection();
-
- if (Subtarget->isTargetCygMing()) {
- SectionName += ",\"aw\"";
- } else {
- assert(!Subtarget->isTargetDarwin());
- SectionName += ",\"aw\",@progbits";
- }
+ }
- SwitchToDataSection(SectionName.c_str());
- } else {
- if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
- SwitchToDataSection(TAI->getBSSSection(), I);
- else
- SwitchToDataSection(TAI->getDataSection(), I);
+ switch (I->getLinkage()) {
+ case GlobalValue::LinkOnceLinkage:
+ case GlobalValue::WeakLinkage:
+ if (Subtarget->isTargetDarwin()) {
+ O << "\t.globl " << name << "\n"
+ << "\t.weak_definition " << name << "\n";
+ SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
+ } else if (Subtarget->isTargetCygMing()) {
+ std::string SectionName(".section\t.data$linkonce." +
+ name +
+ ",\"aw\"");
+ SwitchToDataSection(SectionName.c_str(), I);
+ O << "\t.globl " << name << "\n"
+ << "\t.linkonce same_size\n";
+ } else {
+ std::string SectionName("\t.section\t.llvm.linkonce.d." +
+ name +
+ ",\"aw\",@progbits");
+ SwitchToDataSection(SectionName.c_str(), I);
+ O << "\t.weak " << name << "\n";
+ }
+ break;
+ case GlobalValue::AppendingLinkage:
+ // FIXME: appending linkage variables should go into a section of
+ // their name or something. For now, just emit them as external.
+ case GlobalValue::DLLExportLinkage:
+ DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
+ // FALL THROUGH
+ case GlobalValue::ExternalLinkage:
+ // If external or appending, declare as a global symbol
+ O << "\t.globl " << name << "\n";
+ // FALL THROUGH
+ case GlobalValue::InternalLinkage: {
+ if (I->isConstant()) {
+ const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
+ if (TAI->getCStringSection() && CVA && CVA->isCString()) {
+ SwitchToDataSection(TAI->getCStringSection(), I);
+ break;
}
-
- break;
}
- default:
- assert(0 && "Unknown linkage type!");
+ // FIXME: special handling for ".ctors" & ".dtors" sections
+ if (I->hasSection() &&
+ (I->getSection() == ".ctors" ||
+ I->getSection() == ".dtors")) {
+ std::string SectionName = ".section " + I->getSection();
+
+ if (Subtarget->isTargetCygMing()) {
+ SectionName += ",\"aw\"";
+ } else {
+ assert(!Subtarget->isTargetDarwin());
+ SectionName += ",\"aw\",@progbits";
+ }
+
+ SwitchToDataSection(SectionName.c_str());
+ } else {
+ if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
+ SwitchToDataSection(TAI->getBSSSection(), I);
+ else
+ SwitchToDataSection(TAI->getDataSection(), I);
}
+
+ break;
+ }
+ default:
+ assert(0 && "Unknown linkage type!");
+ }
- EmitAlignment(Align, I);
- O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
- << "\n";
- 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(GV);
+ EmitAlignment(Align, I);
+ O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
+ << "\n";
+ 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(GV);
- EmitGlobalConstant(C);
- O << '\n';
- }
- if (I->hasHiddenVisibility())
- if (const char *Directive = TAI->getHiddenDirective())
- O << Directive << name << "\n";
-
- if (Subtarget->isTargetELF())
- O << "\t.type " << name << ",@object\n";
+ EmitGlobalConstant(C);
+ O << '\n';
}
// Output linker support code for dllexported globals