From 932ad51feabc4119dda978c4f147dfe1b010a95d Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 25 May 2006 21:59:08 +0000 Subject: [PATCH] X86 / Cygwin asm / alignment fixes. Patch contributed by Anton Korobeynikov! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28480 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ATTAsmPrinter.cpp | 32 ++++++++++++++++++----------- lib/Target/X86/X86AsmPrinter.cpp | 30 +++++++++++++++------------ lib/Target/X86/X86AsmPrinter.h | 8 ++++---- lib/Target/X86/X86Subtarget.cpp | 2 +- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp index 7d40c8842ae..9ca6e65e9db 100755 --- a/lib/Target/X86/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/X86ATTAsmPrinter.cpp @@ -26,11 +26,9 @@ using namespace llvm; /// method to print assembly for each instruction. /// bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) { - // if (forDarwin) { - // Let PassManager know we need debug information and relay - // the MachineDebugInfo address on to DwarfWriter. - DW.SetDebugInfo(&getAnalysis()); - // } + // Let PassManager know we need debug information and relay + // the MachineDebugInfo address on to DwarfWriter. + DW.SetDebugInfo(&getAnalysis()); SetupMachineFunction(MF); O << "\n\n"; @@ -56,11 +54,17 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) { break; case Function::WeakLinkage: case Function::LinkOnceLinkage: - if (forDarwin) { + if (Subtarget->TargetType == X86Subtarget::isDarwin) { SwitchToTextSection( ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F); O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.weak_definition\t" << CurrentFnName << "\n"; + } else if (Subtarget->TargetType == X86Subtarget::isCygwin) { + EmitAlignment(4, F); // FIXME: This should be parameterized somewhere. + O << "\t.section\t.llvm.linkonce.t." << CurrentFnName + << ",\"ax\"\n"; + SwitchToTextSection("", F); + O << "\t.weak " << CurrentFnName << "\n"; } else { EmitAlignment(4, F); // FIXME: This should be parameterized somewhere. O << "\t.section\t.llvm.linkonce.t." << CurrentFnName @@ -72,7 +76,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) { } O << CurrentFnName << ":\n"; - if (forDarwin) { + if (Subtarget->TargetType == X86Subtarget::isDarwin) { // Emit pre-function debug information. DW.BeginFunction(&MF); } @@ -95,7 +99,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) { if (HasDotTypeDotSizeDirective) O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n"; - if (forDarwin) { + if (Subtarget->TargetType == X86Subtarget::isDarwin) { // Emit post-function debug information. DW.EndFunction(); } @@ -145,7 +149,8 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, if (!isMemOp) O << '$'; O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" << MO.getConstantPoolIndex(); - if (forDarwin && TM.getRelocationModel() == Reloc::PIC) + if (Subtarget->TargetType == X86Subtarget::isDarwin && + TM.getRelocationModel() == Reloc::PIC) O << "-\"L" << getFunctionNumber() << "$pb\""; int Offset = MO.getOffset(); if (Offset > 0) @@ -159,7 +164,8 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, bool isMemOp = Modifier && !strcmp(Modifier, "mem"); if (!isMemOp && !isCallOp) O << '$'; // Darwin block shameless ripped from PPCAsmPrinter.cpp - if (forDarwin && TM.getRelocationModel() != Reloc::Static) { + if (Subtarget->TargetType == X86Subtarget::isDarwin && + TM.getRelocationModel() != Reloc::Static) { GlobalValue *GV = MO.getGlobal(); std::string Name = Mang->getValueName(GV); // Link-once, External, or Weakly-linked global variables need @@ -190,7 +196,9 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, } case MachineOperand::MO_ExternalSymbol: { bool isCallOp = Modifier && !strcmp(Modifier, "call"); - if (isCallOp && forDarwin && TM.getRelocationModel() != Reloc::Static) { + if (isCallOp && + Subtarget->TargetType == X86Subtarget::isDarwin && + TM.getRelocationModel() != Reloc::Static) { std::string Name(GlobalPrefix); Name += MO.getSymbolName(); FnStubs.insert(Name); @@ -332,7 +340,7 @@ bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; // This works around some Darwin assembler bugs. - if (forDarwin) { + if (Subtarget->TargetType == X86Subtarget::isDarwin) { switch (MI->getOpcode()) { case X86::REP_MOVSB: O << "rep/movsb (%esi),(%edi)\n"; diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index dceade47253..1880cd9dccd 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -46,9 +46,6 @@ AsmWriterFlavor("x86-asm-syntax", /// doInitialization bool X86SharedAsmPrinter::doInitialization(Module &M) { - const X86Subtarget *Subtarget = &TM.getSubtarget(); - - forDarwin = false; PrivateGlobalPrefix = ".L"; DefaultTextSection = ".text"; DefaultDataSection = ".data"; @@ -65,7 +62,6 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) { LCOMMDirective = "\t.lcomm\t"; COMMDirectiveTakesAlignment = false; HasDotTypeDotSizeDirective = false; - forDarwin = true; StaticCtorsSection = ".mod_init_func"; StaticDtorsSection = ".mod_term_func"; InlineAsmStart = "# InlineAsm Start"; @@ -75,6 +71,8 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) { GlobalPrefix = "_"; COMMDirectiveTakesAlignment = false; HasDotTypeDotSizeDirective = false; + StaticCtorsSection = "\t.section .ctors,\"aw\""; + StaticDtorsSection = "\t.section .dtors,\"aw\""; break; case X86Subtarget::isWindows: GlobalPrefix = "_"; @@ -83,7 +81,7 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) { default: break; } - if (forDarwin) { + if (Subtarget->TargetType == X86Subtarget::isDarwin) { // Emit initial debug information. DW.BeginModule(&M); } @@ -114,7 +112,8 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { if (C->isNullValue() && /* FIXME: Verify correct */ (I->hasInternalLinkage() || I->hasWeakLinkage() || I->hasLinkOnceLinkage() || - (forDarwin && I->hasExternalLinkage() && !I->hasSection()))) { + (Subtarget->TargetType == X86Subtarget::isDarwin && + I->hasExternalLinkage() && !I->hasSection()))) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (I->hasExternalLinkage()) { O << "\t.globl\t" << name << "\n"; @@ -125,13 +124,15 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { if (LCOMMDirective != NULL) { if (I->hasInternalLinkage()) { O << LCOMMDirective << name << "," << Size; - if (forDarwin) + if (Subtarget->TargetType == X86Subtarget::isDarwin) O << "," << (AlignmentIsInBytes ? (1 << Align) : Align); } else O << COMMDirective << name << "," << Size; } else { - if (I->hasInternalLinkage()) - O << "\t.local\t" << name << "\n"; + if (Subtarget->TargetType == X86Subtarget::isCygwin) { + if (I->hasInternalLinkage()) + O << "\t.local\t" << name << "\n"; + } O << COMMDirective << name << "," << Size; if (COMMDirectiveTakesAlignment) O << "," << (AlignmentIsInBytes ? (1 << Align) : Align); @@ -142,13 +143,16 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { switch (I->getLinkage()) { case GlobalValue::LinkOnceLinkage: case GlobalValue::WeakLinkage: - if (forDarwin) { + if (Subtarget->TargetType == X86Subtarget::isDarwin) { O << "\t.globl " << name << "\n" << "\t.weak_definition " << name << "\n"; SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I); + } else if (Subtarget->TargetType == X86Subtarget::isCygwin) { + O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n" + << "\t.weak " << name << "\n"; } else { - O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"; - O << "\t.weak " << name << "\n"; + O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n" + << "\t.weak " << name << "\n"; } break; case GlobalValue::AppendingLinkage: @@ -176,7 +180,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { } } - if (forDarwin) { + if (Subtarget->TargetType == X86Subtarget::isDarwin) { SwitchToDataSection("", 0); // Output stubs for dynamically-linked functions diff --git a/lib/Target/X86/X86AsmPrinter.h b/lib/Target/X86/X86AsmPrinter.h index b653b34a2f8..eee956cd43b 100755 --- a/lib/Target/X86/X86AsmPrinter.h +++ b/lib/Target/X86/X86AsmPrinter.h @@ -57,7 +57,9 @@ struct X86SharedAsmPrinter : public AsmPrinter { X86DwarfWriter DW; X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM) - : AsmPrinter(O, TM), DW(O, this), forDarwin(false) { } + : AsmPrinter(O, TM), DW(O, this) { + Subtarget = &TM.getSubtarget(); + } bool doInitialization(Module &M); bool doFinalization(Module &M); @@ -68,11 +70,9 @@ struct X86SharedAsmPrinter : public AsmPrinter { MachineFunctionPass::getAnalysisUsage(AU); } - bool forDarwin; // FIXME: eliminate. - const char *DefaultTextSection; // "_text" for MASM, ".text" for others. const char *DefaultDataSection; // "_data" for MASM, ".data" for others. - + const X86Subtarget *Subtarget; // Necessary for Darwin to print out the apprioriate types of linker stubs std::set FnStubs, GVStubs, LinkOnceStubs; diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp index 756b6b76754..cafa09cc7d9 100644 --- a/lib/Target/X86/X86Subtarget.cpp +++ b/lib/Target/X86/X86Subtarget.cpp @@ -182,6 +182,6 @@ X86Subtarget::X86Subtarget(const Module &M, const std::string &FS) { #endif } - if (TargetType == isDarwin) + if (TargetType == isDarwin || TargetType == isCygwin) stackAlignment = 16; } -- 2.34.1