[llvm] r334989 - Pull non-lazy stub table emission into a separate function alongside
Eric Christopher via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 18 15:21:18 PDT 2018
Author: echristo
Date: Mon Jun 18 15:21:18 2018
New Revision: 334989
URL: http://llvm.org/viewvc/llvm-project?rev=334989&view=rev
Log:
Pull non-lazy stub table emission into a separate function alongside
the individual stub creation to increase readability a bit in the
non-object file format specific function.
Modified:
llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
Modified: llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp?rev=334989&r1=334988&r2=334989&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp Mon Jun 18 15:21:18 2018
@@ -608,6 +608,29 @@ void X86AsmPrinter::EmitStartOfAsmFile(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 &Out
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();
More information about the llvm-commits
mailing list