diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
commit | 044eb2f6afba375a914ac9d8024f8f5142bb912e (patch) | |
tree | 1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /lib/MC/MCStreamer.cpp | |
parent | eb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff) | |
download | src-044eb2f6afba375a914ac9d8024f8f5142bb912e.tar.gz src-044eb2f6afba375a914ac9d8024f8f5142bb912e.zip |
Vendor import of llvm trunk r321017:vendor/llvm/llvm-trunk-r321017
Notes
Notes:
svn path=/vendor/llvm/dist/; revision=326938
svn path=/vendor/llvm/llvm-trunk-r321017/; revision=326939; tag=vendor/llvm/llvm-trunk-r321017
Diffstat (limited to 'lib/MC/MCStreamer.cpp')
-rw-r--r-- | lib/MC/MCStreamer.cpp | 362 |
1 files changed, 237 insertions, 125 deletions
diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index 2bfb9a63eedb..6f3647d61932 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -56,17 +56,12 @@ MCStreamer::MCStreamer(MCContext &Ctx) SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>()); } -MCStreamer::~MCStreamer() { - for (unsigned i = 0; i < getNumWinFrameInfos(); ++i) - delete WinFrameInfos[i]; -} +MCStreamer::~MCStreamer() {} void MCStreamer::reset() { DwarfFrameInfos.clear(); - for (unsigned i = 0; i < getNumWinFrameInfos(); ++i) - delete WinFrameInfos[i]; - WinFrameInfos.clear(); CurrentWinFrameInfo = nullptr; + WinFrameInfos.clear(); SymbolOrdering.clear(); SectionStack.clear(); SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>()); @@ -105,13 +100,17 @@ void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) { /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the /// client having to pass in a MCExpr for constant integers. -void MCStreamer::EmitULEB128IntValue(uint64_t Value, unsigned Padding) { +void MCStreamer::EmitPaddedULEB128IntValue(uint64_t Value, unsigned PadTo) { SmallString<128> Tmp; raw_svector_ostream OSE(Tmp); - encodeULEB128(Value, OSE, Padding); + encodeULEB128(Value, OSE, PadTo); EmitBytes(OSE.str()); } +void MCStreamer::EmitULEB128IntValue(uint64_t Value) { + EmitPaddedULEB128IntValue(Value, 0); +} + /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the /// client having to pass in a MCExpr for constant integers. void MCStreamer::EmitSLEB128IntValue(int64_t Value) { @@ -207,25 +206,25 @@ MCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) { return Table.getLabel(); } -MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() { - if (DwarfFrameInfos.empty()) - return nullptr; - return &DwarfFrameInfos.back(); -} - bool MCStreamer::hasUnfinishedDwarfFrameInfo() { - MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); - return CurFrame && !CurFrame->End; + return !DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End; } -void MCStreamer::EnsureValidDwarfFrame() { - MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); - if (!CurFrame || CurFrame->End) - report_fatal_error("No open frame"); +MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() { + if (!hasUnfinishedDwarfFrameInfo()) { + getContext().reportError(SMLoc(), "this directive must appear between " + ".cfi_startproc and .cfi_endproc " + "directives"); + return nullptr; + } + return &DwarfFrameInfos.back(); } -bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename) { - return getContext().getCVContext().addFile(FileNo, Filename); +bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename, + ArrayRef<uint8_t> Checksum, + unsigned ChecksumKind) { + return getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum, + ChecksumKind); } bool MCStreamer::EmitCVFuncIdDirective(unsigned FunctionId) { @@ -322,7 +321,8 @@ void MCStreamer::EmitCFISections(bool EH, bool Debug) { void MCStreamer::EmitCFIStartProc(bool IsSimple) { if (hasUnfinishedDwarfFrameInfo()) - report_fatal_error("Starting a frame before finishing the previous one!"); + getContext().reportError( + SMLoc(), "starting new .cfi frame before finishing the previous one"); MCDwarfFrameInfo Frame; Frame.IsSimple = IsSimple; @@ -345,241 +345,298 @@ void MCStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) { } void MCStreamer::EmitCFIEndProc() { - EnsureValidDwarfFrame(); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; EmitCFIEndProcImpl(*CurFrame); } void MCStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) { // Put a dummy non-null value in Frame.End to mark that this frame has been // closed. - Frame.End = (MCSymbol *) 1; + Frame.End = (MCSymbol *)1; } MCSymbol *MCStreamer::EmitCFILabel() { - MCSymbol *Label = getContext().createTempSymbol("cfi", true); - EmitLabel(Label); - return Label; -} - -MCSymbol *MCStreamer::EmitCFICommon() { - EnsureValidDwarfFrame(); - return EmitCFILabel(); + // Return a dummy non-null value so that label fields appear filled in when + // generating textual assembly. + return (MCSymbol *)1; } void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createDefCfa(Label, Register, Offset); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register); } void MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createDefCfaOffset(Label, Offset); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIDefCfaRegister(int64_t Register) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createDefCfaRegister(Label, Register); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register); } void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createOffset(Label, Register, Offset); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createRelOffset(Label, Register, Offset); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) { - EnsureValidDwarfFrame(); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Personality = Sym; CurFrame->PersonalityEncoding = Encoding; } void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) { - EnsureValidDwarfFrame(); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Lsda = Sym; CurFrame->LsdaEncoding = Encoding; } void MCStreamer::EmitCFIRememberState() { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createRememberState(Label); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIRestoreState() { // FIXME: Error if there is no matching cfi_remember_state. - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createRestoreState(Label); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFISameValue(int64_t Register) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createSameValue(Label, Register); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIRestore(int64_t Register) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createRestore(Label, Register); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIEscape(StringRef Values) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createEscape(Label, Values); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIGnuArgsSize(int64_t Size) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createGnuArgsSize(Label, Size); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFISignalFrame() { - EnsureValidDwarfFrame(); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->IsSignalFrame = true; } void MCStreamer::EmitCFIUndefined(int64_t Register) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createUndefined(Label, Register); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createRegister(Label, Register1, Register2); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIWindowSave() { - MCSymbol *Label = EmitCFICommon(); + MCSymbol *Label = EmitCFILabel(); MCCFIInstruction Instruction = MCCFIInstruction::createWindowSave(Label); MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; CurFrame->Instructions.push_back(Instruction); } -void MCStreamer::EnsureValidWinFrameInfo() { +void MCStreamer::EmitCFIReturnColumn(int64_t Register) { + MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; + CurFrame->RAReg = Register; +} + +WinEH::FrameInfo *MCStreamer::EnsureValidWinFrameInfo(SMLoc Loc) { const MCAsmInfo *MAI = Context.getAsmInfo(); - if (!MAI->usesWindowsCFI()) - report_fatal_error(".seh_* directives are not supported on this target"); - if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) - report_fatal_error("No open Win64 EH frame function!"); + if (!MAI->usesWindowsCFI()) { + getContext().reportError( + Loc, ".seh_* directives are not supported on this target"); + return nullptr; + } + if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) { + getContext().reportError( + Loc, ".seh_ directive must appear within an active frame"); + return nullptr; + } + return CurrentWinFrameInfo; } -void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) { +void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) { const MCAsmInfo *MAI = Context.getAsmInfo(); if (!MAI->usesWindowsCFI()) - report_fatal_error(".seh_* directives are not supported on this target"); + return getContext().reportError( + Loc, ".seh_* directives are not supported on this target"); if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End) - report_fatal_error("Starting a function before ending the previous one!"); + getContext().reportError( + Loc, "Starting a function before ending the previous one!"); MCSymbol *StartProc = EmitCFILabel(); - WinFrameInfos.push_back(new WinEH::FrameInfo(Symbol, StartProc)); - CurrentWinFrameInfo = WinFrameInfos.back(); + WinFrameInfos.emplace_back( + llvm::make_unique<WinEH::FrameInfo>(Symbol, StartProc)); + CurrentWinFrameInfo = WinFrameInfos.back().get(); CurrentWinFrameInfo->TextSection = getCurrentSectionOnly(); } -void MCStreamer::EmitWinCFIEndProc() { - EnsureValidWinFrameInfo(); - if (CurrentWinFrameInfo->ChainedParent) - report_fatal_error("Not all chained regions terminated!"); +void MCStreamer::EmitWinCFIEndProc(SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; + if (CurFrame->ChainedParent) + getContext().reportError(Loc, "Not all chained regions terminated!"); MCSymbol *Label = EmitCFILabel(); - CurrentWinFrameInfo->End = Label; + CurFrame->End = Label; } -void MCStreamer::EmitWinCFIStartChained() { - EnsureValidWinFrameInfo(); +void MCStreamer::EmitWinCFIStartChained(SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; MCSymbol *StartProc = EmitCFILabel(); - WinFrameInfos.push_back(new WinEH::FrameInfo(CurrentWinFrameInfo->Function, - StartProc, CurrentWinFrameInfo)); - CurrentWinFrameInfo = WinFrameInfos.back(); + WinFrameInfos.emplace_back(llvm::make_unique<WinEH::FrameInfo>( + CurFrame->Function, StartProc, CurFrame)); + CurrentWinFrameInfo = WinFrameInfos.back().get(); CurrentWinFrameInfo->TextSection = getCurrentSectionOnly(); } -void MCStreamer::EmitWinCFIEndChained() { - EnsureValidWinFrameInfo(); - if (!CurrentWinFrameInfo->ChainedParent) - report_fatal_error("End of a chained region outside a chained region!"); +void MCStreamer::EmitWinCFIEndChained(SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; + if (!CurFrame->ChainedParent) + return getContext().reportError( + Loc, "End of a chained region outside a chained region!"); MCSymbol *Label = EmitCFILabel(); - CurrentWinFrameInfo->End = Label; - CurrentWinFrameInfo = - const_cast<WinEH::FrameInfo *>(CurrentWinFrameInfo->ChainedParent); + CurFrame->End = Label; + CurrentWinFrameInfo = const_cast<WinEH::FrameInfo *>(CurFrame->ChainedParent); } -void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, - bool Except) { - EnsureValidWinFrameInfo(); - if (CurrentWinFrameInfo->ChainedParent) - report_fatal_error("Chained unwind areas can't have handlers!"); - CurrentWinFrameInfo->ExceptionHandler = Sym; +void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except, + SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; + if (CurFrame->ChainedParent) + return getContext().reportError( + Loc, "Chained unwind areas can't have handlers!"); + CurFrame->ExceptionHandler = Sym; if (!Except && !Unwind) - report_fatal_error("Don't know what kind of handler this is!"); + getContext().reportError(Loc, "Don't know what kind of handler this is!"); if (Unwind) - CurrentWinFrameInfo->HandlesUnwind = true; + CurFrame->HandlesUnwind = true; if (Except) - CurrentWinFrameInfo->HandlesExceptions = true; + CurFrame->HandlesExceptions = true; } -void MCStreamer::EmitWinEHHandlerData() { - EnsureValidWinFrameInfo(); - if (CurrentWinFrameInfo->ChainedParent) - report_fatal_error("Chained unwind areas can't have handlers!"); +void MCStreamer::EmitWinEHHandlerData(SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; + if (CurFrame->ChainedParent) + getContext().reportError(Loc, "Chained unwind areas can't have handlers!"); } static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID, @@ -616,86 +673,110 @@ MCSection *MCStreamer::getAssociatedXDataSection(const MCSection *TextSec) { void MCStreamer::EmitSyntaxDirective() {} -void MCStreamer::EmitWinCFIPushReg(unsigned Register) { - EnsureValidWinFrameInfo(); +void MCStreamer::EmitWinCFIPushReg(unsigned Register, SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; MCSymbol *Label = EmitCFILabel(); WinEH::Instruction Inst = Win64EH::Instruction::PushNonVol(Label, Register); - CurrentWinFrameInfo->Instructions.push_back(Inst); + CurFrame->Instructions.push_back(Inst); } -void MCStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) { - EnsureValidWinFrameInfo(); - if (CurrentWinFrameInfo->LastFrameInst >= 0) - report_fatal_error("Frame register and offset already specified!"); +void MCStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset, + SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; + if (CurFrame->LastFrameInst >= 0) + return getContext().reportError( + Loc, "frame register and offset can be set at most once"); if (Offset & 0x0F) - report_fatal_error("Misaligned frame pointer offset!"); + return getContext().reportError(Loc, "offset is not a multiple of 16"); if (Offset > 240) - report_fatal_error("Frame offset must be less than or equal to 240!"); + return getContext().reportError( + Loc, "frame offset must be less than or equal to 240"); MCSymbol *Label = EmitCFILabel(); WinEH::Instruction Inst = Win64EH::Instruction::SetFPReg(Label, Register, Offset); - CurrentWinFrameInfo->LastFrameInst = CurrentWinFrameInfo->Instructions.size(); - CurrentWinFrameInfo->Instructions.push_back(Inst); + CurFrame->LastFrameInst = CurFrame->Instructions.size(); + CurFrame->Instructions.push_back(Inst); } -void MCStreamer::EmitWinCFIAllocStack(unsigned Size) { - EnsureValidWinFrameInfo(); +void MCStreamer::EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; if (Size == 0) - report_fatal_error("Allocation size must be non-zero!"); + return getContext().reportError(Loc, + "stack allocation size must be non-zero"); if (Size & 7) - report_fatal_error("Misaligned stack allocation!"); + return getContext().reportError( + Loc, "stack allocation size is not a multiple of 8"); MCSymbol *Label = EmitCFILabel(); WinEH::Instruction Inst = Win64EH::Instruction::Alloc(Label, Size); - CurrentWinFrameInfo->Instructions.push_back(Inst); + CurFrame->Instructions.push_back(Inst); } -void MCStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset) { - EnsureValidWinFrameInfo(); +void MCStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset, + SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; + if (Offset & 7) - report_fatal_error("Misaligned saved register offset!"); + return getContext().reportError( + Loc, "register save offset is not 8 byte aligned"); MCSymbol *Label = EmitCFILabel(); WinEH::Instruction Inst = Win64EH::Instruction::SaveNonVol(Label, Register, Offset); - CurrentWinFrameInfo->Instructions.push_back(Inst); + CurFrame->Instructions.push_back(Inst); } -void MCStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) { - EnsureValidWinFrameInfo(); +void MCStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset, + SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; if (Offset & 0x0F) - report_fatal_error("Misaligned saved vector register offset!"); + return getContext().reportError(Loc, "offset is not a multiple of 16"); MCSymbol *Label = EmitCFILabel(); WinEH::Instruction Inst = Win64EH::Instruction::SaveXMM(Label, Register, Offset); - CurrentWinFrameInfo->Instructions.push_back(Inst); + CurFrame->Instructions.push_back(Inst); } -void MCStreamer::EmitWinCFIPushFrame(bool Code) { - EnsureValidWinFrameInfo(); - if (!CurrentWinFrameInfo->Instructions.empty()) - report_fatal_error("If present, PushMachFrame must be the first UOP"); +void MCStreamer::EmitWinCFIPushFrame(bool Code, SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; + if (!CurFrame->Instructions.empty()) + return getContext().reportError( + Loc, "If present, PushMachFrame must be the first UOP"); MCSymbol *Label = EmitCFILabel(); WinEH::Instruction Inst = Win64EH::Instruction::PushMachFrame(Label, Code); - CurrentWinFrameInfo->Instructions.push_back(Inst); + CurFrame->Instructions.push_back(Inst); } -void MCStreamer::EmitWinCFIEndProlog() { - EnsureValidWinFrameInfo(); +void MCStreamer::EmitWinCFIEndProlog(SMLoc Loc) { + WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc); + if (!CurFrame) + return; MCSymbol *Label = EmitCFILabel(); - CurrentWinFrameInfo->PrologEnd = Label; + CurFrame->PrologEnd = Label; } void MCStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) { @@ -725,7 +806,9 @@ void MCStreamer::EmitWindowsUnwindTables() { void MCStreamer::Finish() { if (!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) - report_fatal_error("Unfinished frame!"); + getContext().reportError(SMLoc(), "Unfinished frame!"); + if (!WinFrameInfos.empty() && !WinFrameInfos.back()->End) + getContext().reportError(SMLoc(), "Unfinished frame!"); MCTargetStreamer *TS = getTargetStreamer(); if (TS) @@ -876,3 +959,32 @@ MCSymbol *MCStreamer::endSection(MCSection *Section) { EmitLabel(Sym); return Sym; } + +void MCStreamer::EmitVersionForTarget(const Triple &Target) { + if (!Target.isOSBinFormatMachO() || !Target.isOSDarwin()) + return; + // Do we even know the version? + if (Target.getOSMajorVersion() == 0) + return; + + unsigned Major; + unsigned Minor; + unsigned Update; + MCVersionMinType VersionType; + if (Target.isWatchOS()) { + VersionType = MCVM_WatchOSVersionMin; + Target.getWatchOSVersion(Major, Minor, Update); + } else if (Target.isTvOS()) { + VersionType = MCVM_TvOSVersionMin; + Target.getiOSVersion(Major, Minor, Update); + } else if (Target.isMacOSX()) { + VersionType = MCVM_OSXVersionMin; + if (!Target.getMacOSXVersion(Major, Minor, Update)) + Major = 0; + } else { + VersionType = MCVM_IOSVersionMin; + Target.getiOSVersion(Major, Minor, Update); + } + if (Major != 0) + EmitVersionMin(VersionType, Major, Minor, Update); +} |