- for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
- if (I->hasInitializer()) { // External global require no code
- O << '\n';
- std::string name = Mang->getValueName(I);
- Constant *C = I->getInitializer();
- unsigned Size = TD.getTypeSize(C->getType());
- unsigned Align = TD.getTypeAlignmentShift(C->getType());
-
- if (C->isNullValue() && /* FIXME: Verify correct */
- (I->hasInternalLinkage() || I->hasWeakLinkage() ||
- I->hasLinkOnceLinkage())) {
- SwitchSection(O, CurSection, ".data");
- if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
- if (I->hasInternalLinkage())
- O << ".lcomm " << name << "," << Size << "," << Align;
- else
- O << ".comm " << name << "," << Size;
- O << "\t\t; '" << I->getName() << "'\n";
- } else {
- switch (I->getLinkage()) {
- case GlobalValue::LinkOnceLinkage:
- O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n"
- << ".weak_definition " << name << '\n'
- << ".private_extern " << name << '\n'
- << ".section __DATA,__datacoal_nt,coalesced,no_toc\n";
- LinkOnceStubs.insert(name);
- break;
- case GlobalValue::WeakLinkage:
- O << ".weak_definition " << name << '\n'
- << ".private_extern " << 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::ExternalLinkage:
- // If external or appending, declare as a global symbol
- O << "\t.globl " << name << "\n";
- // FALL THROUGH
- case GlobalValue::InternalLinkage:
- SwitchSection(O, CurSection, ".data");
- break;
- case GlobalValue::GhostLinkage:
- std::cerr << "Error: unmaterialized (GhostLinkage) function in asm!";
- abort();
- }
-
- emitAlignment(Align);
- O << name << ":\t\t\t\t; '" << I->getName() << "'\n";
- emitGlobalConstant(C);
+ 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
+
+ // Check to see if this is a special global used by LLVM, if so, emit it.
+ if (I->hasAppendingLinkage() && EmitSpecialLLVMGlobal(I))
+ continue;
+
+ O << '\n';
+ std::string name = Mang->getValueName(I);
+ Constant *C = I->getInitializer();
+ unsigned Size = TD.getTypeSize(C->getType());
+ unsigned Align = TD.getTypeAlignmentShift(C->getType());
+
+ if (C->isNullValue() && /* FIXME: Verify correct */
+ (I->hasInternalLinkage() || I->hasWeakLinkage() ||
+ I->hasLinkOnceLinkage())) {
+ SwitchSection(".data", I);
+ if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
+ if (I->hasInternalLinkage())
+ O << LCOMMDirective << name << "," << Size << "," << Align;
+ else
+ O << ".comm " << name << "," << Size;
+ O << "\t\t; '" << I->getName() << "'\n";
+ } else {
+ switch (I->getLinkage()) {
+ case GlobalValue::LinkOnceLinkage:
+ case GlobalValue::WeakLinkage:
+ O << ".globl " << name << '\n'
+ << ".weak_definition " << name << '\n'
+ << ".private_extern " << name << '\n';
+ SwitchSection(".section __DATA,__datacoal_nt,coalesced", I);
+ 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::ExternalLinkage:
+ // If external or appending, declare as a global symbol
+ O << "\t.globl " << name << "\n";
+ // FALL THROUGH
+ case GlobalValue::InternalLinkage:
+ SwitchSection(".data", I);
+ break;
+ default:
+ std::cerr << "Unknown linkage type!";
+ abort();