diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/X86/X86AsmPrinter.cpp | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp index d74438df60f..6ce404449e0 100644 --- a/llvm/lib/Target/X86/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp @@ -608,6 +608,29 @@ void X86AsmPrinter::EmitStartOfAsmFile(Module &M) { OutStreamer->EmitAssemblerFlag(MCAF_Code16); } +MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const { + if (Subtarget->isTargetKnownWindowsMSVC()) { + const MachineConstantPoolEntry &CPE = + MF->getConstantPool()->getConstants()[CPID]; + if (!CPE.isMachineConstantPoolEntry()) { + const DataLayout &DL = MF->getDataLayout(); + SectionKind Kind = CPE.getSectionKind(&DL); + const Constant *C = CPE.Val.ConstVal; + unsigned Align = CPE.Alignment; + if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>( + getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) { + if (MCSymbol *Sym = S->getCOMDATSymbol()) { + if (Sym->isUndefined()) + OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global); + return Sym; + } + } + } + } + + return AsmPrinter::GetCPISymbol(CPID); +} + static void emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, MachineModuleInfoImpl::StubValueTy &MCSym) { @@ -631,55 +654,38 @@ emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, 4 /*size*/); } -MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const { - if (Subtarget->isTargetKnownWindowsMSVC()) { - const MachineConstantPoolEntry &CPE = - MF->getConstantPool()->getConstants()[CPID]; - if (!CPE.isMachineConstantPoolEntry()) { - const DataLayout &DL = MF->getDataLayout(); - SectionKind Kind = CPE.getSectionKind(&DL); - const Constant *C = CPE.Val.ConstVal; - unsigned Align = CPE.Alignment; - if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>( - getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) { - if (MCSymbol *Sym = S->getCOMDATSymbol()) { - if (Sym->isUndefined()) - OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global); - return Sym; - } - } - } - } +static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer) { - return AsmPrinter::GetCPISymbol(CPID); + MachineModuleInfoMachO &MMIMacho = + MMI->getObjFileInfo<MachineModuleInfoMachO>(); + + // Output stubs for dynamically-linked functions. + MachineModuleInfoMachO::SymbolListTy Stubs; + + // Output stubs for external and common global variables. + Stubs = MMIMacho.GetGVStubList(); + if (!Stubs.empty()) { + OutStreamer.SwitchSection(MMI->getContext().getMachOSection( + "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS, + SectionKind::getMetadata())); + + for (auto &Stub : Stubs) + emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second); + + Stubs.clear(); + OutStreamer.AddBlankLine(); + } } void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { const Triple &TT = TM.getTargetTriple(); if (TT.isOSBinFormatMachO()) { - // All darwin targets use mach-o. - MachineModuleInfoMachO &MMIMacho = - MMI->getObjFileInfo<MachineModuleInfoMachO>(); - - // Output stubs for dynamically-linked functions. - MachineModuleInfoMachO::SymbolListTy Stubs; - - // Output stubs for external and common global variables. - Stubs = MMIMacho.GetGVStubList(); - if (!Stubs.empty()) { - MCSection *TheSection = OutContext.getMachOSection( - "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS, - SectionKind::getMetadata()); - OutStreamer->SwitchSection(TheSection); - - for (auto &Stub : Stubs) - emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second); - - Stubs.clear(); - OutStreamer->AddBlankLine(); - } + // Mach-O uses non-lazy symbol stubs to encode per-TU information into + // global table for symbol lookup. + emitNonLazyStubs(MMI, *OutStreamer); + // Emit stack and fault map information. SM.serializeToStackMapSection(); FM.serializeToFaultMapSection(); |

