/// that ought be fixed soon.
DwarfWriter *DW;
- // Necessary for external weak linkage support
- std::set<const GlobalValue*> ExtWeakSymbols;
-
/// OptLevel - Generating code at a specific optimization level.
CodeGenOpt::Level OptLevel;
public:
}
bool AsmPrinter::doFinalization(Module &M) {
+ // If the target wants to know about weak references, print them all.
if (TAI->getWeakRefDirective()) {
- if (!ExtWeakSymbols.empty())
- SwitchToDataSection("");
-
- for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
- e = ExtWeakSymbols.end(); i != e; ++i)
- O << TAI->getWeakRefDirective() << Mang->getValueName(*i) << '\n';
+ // FIXME: This is not lazy, it would be nice to only print weak references
+ // to stuff that is actually used. Note that doing so would require targets
+ // to notice uses in operands (due to constant exprs etc). This should
+ // happen with the MC stuff eventually.
+ SwitchToDataSection("");
+
+ // 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->hasExternalWeakLinkage())
+ O << TAI->getWeakRefDirective() << Mang->getValueName(I) << '\n';
+ }
+
+ for (Module::const_iterator I = M.begin(), E = M.end();
+ I != E; ++I) {
+ if (I->hasExternalWeakLinkage())
+ O << TAI->getWeakRefDirective() << Mang->getValueName(I) << '\n';
+ }
}
if (TAI->getSetDirective()) {
O << '\n';
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
- I!=E; ++I) {
+ I != E; ++I) {
std::string Name = Mang->getValueName(I);
std::string Target;
// If we don't have any trampolines, then we don't require stack memory
// to be executable. Some targets have a directive to declare this.
- Function* InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
+ Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
if (TAI->getNonexecutableStackDirective())
O << TAI->getNonexecutableStackDirective() << '\n';
O << ")";
}
O << "\n";
-
- // If the constant pool value is a extern weak symbol, remember to emit
- // the weak reference.
- if (GV && GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
}
void getAnalysisUsage(AnalysisUsage &AU) const {
if (isCallOp && Subtarget->isTargetELF() &&
TM.getRelocationModel() == Reloc::PIC_)
O << "(PLT)";
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
break;
}
case MachineOperand::MO_ExternalSymbol: {
EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
} else {
EmitGlobalConstant(MCPE.Val.ConstVal);
- // remember to emit the weak reference
- if (const GlobalValue *GV = dyn_cast<GlobalValue>(MCPE.Val.ConstVal))
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
}
}
}
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';
}
case MachineOperand::MO_GlobalAddress: {
GlobalValue *GV = MO.getGlobal();
O << Mang->getValueName(GV);
- if (GV->isDeclaration() && GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
return;
}
O << name << ":\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';
}
}
}
O << Name;
-
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
return;
}
PrintUnmangledNameSafely(GVar, O);
O << "'\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';
}
std::string Name = Mang->getValueName(GV);
FnStubs.insert(Name);
printSuffixedName(Name, "$stub");
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
return;
}
}
GVStubs.insert(Name);
printSuffixedName(Name, "$non_lazy_ptr");
}
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
return;
}
}
O << Name;
printOffset(MO.getOffset());
-
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
return;
}
}
O << '\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';
}
}
O << '\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';
}
FnStubs.insert(Name);
}
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
-
printOffset(MO.getOffset());
if (needCloseParen)
O << Name;
}
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
-
printOffset(MO.getOffset());
if (needCloseParen)
if (I->hasDLLExportLinkage())
DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
-
- // If the global is a extern weak symbol, remember to emit the weak
- // reference!
- // FIXME: This is rather hacky, since we'll emit references to ALL weak
- // stuff, not used. But currently it's the only way to deal with extern weak
- // initializers hidden deep inside constant expressions.
- if (I->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(I);
}
- for (Module::const_iterator I = M.begin(), E = M.end();
- I != E; ++I) {
- // If the global is a extern weak symbol, remember to emit the weak
- // reference!
- // FIXME: This is rather hacky, since we'll emit references to ALL weak
- // stuff, not used. But currently it's the only way to deal with extern weak
- // initializers hidden deep inside constant expressions.
- if (I->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(I);
- }
-
- // Output linker support code for dllexported globals
- if (!DLLExportedGVs.empty())
- SwitchToDataSection(".section .drectve");
-
- for (StringSet<>::iterator i = DLLExportedGVs.begin(),
- e = DLLExportedGVs.end();
- i != e; ++i)
- O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
-
- if (!DLLExportedFns.empty())
- SwitchToDataSection(".section .drectve");
-
- for (StringSet<>::iterator i = DLLExportedFns.begin(),
- e = DLLExportedFns.end();
- i != e; ++i)
- O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
-
if (Subtarget->isTargetDarwin()) {
SwitchToDataSection("");
}
}
+
+ // Output linker support code for dllexported globals on windows.
+ if (!DLLExportedGVs.empty()) {
+ SwitchToDataSection(".section .drectve");
+
+ for (StringSet<>::iterator i = DLLExportedGVs.begin(),
+ e = DLLExportedGVs.end(); i != e; ++i)
+ O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
+ }
+
+ if (!DLLExportedFns.empty()) {
+ SwitchToDataSection(".section .drectve");
+
+ for (StringSet<>::iterator i = DLLExportedFns.begin(),
+ e = DLLExportedFns.end();
+ i != e; ++i)
+ O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
+ }
+
// Emit final debug information.
+ // FIXME: Sink into DoFinalization.
if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
DW->EndModule();
-
+
+ // Do common shutdown.
+ bool Changed = AsmPrinter::doFinalization(M);
if (NewAsmPrinter) {
Streamer->Finish();
Context = 0;
}
- return AsmPrinter::doFinalization(M);
+ return Changed;
}
// Include the auto-generated portion of the assembly writer.
// Mark the end of the global
O << "\t.cc_bottom " << name << ".data\n";
- } else {
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
}
}
printBasicBlockLabel(MO.getMBB());
break;
case MachineOperand::MO_GlobalAddress:
- {
- const GlobalValue *GV = MO.getGlobal();
- O << Mang->getValueName(GV);
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
- }
+ O << Mang->getValueName(MO.getGlobal());
break;
case MachineOperand::MO_ExternalSymbol:
O << MO.getSymbolName();
bool Result = AsmPrinter::doInitialization(M);
DW = getAnalysisIfAvailable<DwarfWriter>();
- if (!FileDirective.empty()) {
+ if (!FileDirective.empty())
emitFileDirective(FileDirective);
- }
-
- // Print out type strings for external functions here
- for (Module::const_iterator I = M.begin(), E = M.end();
- I != E; ++I) {
- if (I->isDeclaration() && !I->isIntrinsic()) {
- switch (I->getLinkage()) {
- default:
- assert(0 && "Unexpected linkage");
- case Function::ExternalWeakLinkage:
- ExtWeakSymbols.insert(I);
- // fallthrough
- case Function::ExternalLinkage:
- break;
- }
- }
- }
return Result;
}