1 //===-- X86WinCOFFStreamer.cpp - X86 Target WinCOFF Streamer ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "X86MCTargetDesc.h"
10 #include "X86TargetStreamer.h"
11 #include "llvm/MC/MCAsmBackend.h"
12 #include "llvm/MC/MCCodeEmitter.h"
13 #include "llvm/MC/MCObjectWriter.h"
14 #include "llvm/MC/MCWin64EH.h"
15 #include "llvm/MC/MCWinCOFFStreamer.h"
16
17 using namespace llvm;
18
19 namespace {
20 class X86WinCOFFStreamer : public MCWinCOFFStreamer {
21 Win64EH::UnwindEmitter EHStreamer;
22 public:
X86WinCOFFStreamer(MCContext & C,std::unique_ptr<MCAsmBackend> AB,std::unique_ptr<MCCodeEmitter> CE,std::unique_ptr<MCObjectWriter> OW)23 X86WinCOFFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> AB,
24 std::unique_ptr<MCCodeEmitter> CE,
25 std::unique_ptr<MCObjectWriter> OW)
26 : MCWinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW)) {}
27
28 void EmitWinEHHandlerData(SMLoc Loc) override;
29 void EmitWindowsUnwindTables(WinEH::FrameInfo *Frame) override;
30 void EmitWindowsUnwindTables() override;
31 void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) override;
32 void finishImpl() override;
33 };
34
EmitWinEHHandlerData(SMLoc Loc)35 void X86WinCOFFStreamer::EmitWinEHHandlerData(SMLoc Loc) {
36 MCStreamer::EmitWinEHHandlerData(Loc);
37
38 // We have to emit the unwind info now, because this directive
39 // actually switches to the .xdata section.
40 if (WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo())
41 EHStreamer.EmitUnwindInfo(*this, CurFrame, /* HandlerData = */ true);
42 }
43
EmitWindowsUnwindTables(WinEH::FrameInfo * Frame)44 void X86WinCOFFStreamer::EmitWindowsUnwindTables(WinEH::FrameInfo *Frame) {
45 EHStreamer.EmitUnwindInfo(*this, Frame, /* HandlerData = */ false);
46 }
47
EmitWindowsUnwindTables()48 void X86WinCOFFStreamer::EmitWindowsUnwindTables() {
49 if (!getNumWinFrameInfos())
50 return;
51 EHStreamer.Emit(*this);
52 }
53
EmitCVFPOData(const MCSymbol * ProcSym,SMLoc Loc)54 void X86WinCOFFStreamer::EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) {
55 X86TargetStreamer *XTS =
56 static_cast<X86TargetStreamer *>(getTargetStreamer());
57 XTS->emitFPOData(ProcSym, Loc);
58 }
59
finishImpl()60 void X86WinCOFFStreamer::finishImpl() {
61 emitFrames(nullptr);
62 EmitWindowsUnwindTables();
63
64 MCWinCOFFStreamer::finishImpl();
65 }
66 } // namespace
67
createX86WinCOFFStreamer(MCContext & C,std::unique_ptr<MCAsmBackend> && AB,std::unique_ptr<MCObjectWriter> && OW,std::unique_ptr<MCCodeEmitter> && CE,bool RelaxAll,bool IncrementalLinkerCompatible)68 MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C,
69 std::unique_ptr<MCAsmBackend> &&AB,
70 std::unique_ptr<MCObjectWriter> &&OW,
71 std::unique_ptr<MCCodeEmitter> &&CE,
72 bool RelaxAll,
73 bool IncrementalLinkerCompatible) {
74 X86WinCOFFStreamer *S =
75 new X86WinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW));
76 S->getAssembler().setRelaxAll(RelaxAll);
77 S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible);
78 return S;
79 }
80
81