From 6c76c959e405c72574b7e0498ddcaee3e532ca15 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 27 Apr 2014 03:48:12 +0000 Subject: [PATCH] MC: create X86WinCOFFStreamer for target specific behaviour This introduces a target specific streamer, X86WinCOFFStreamer, which handles the target specific behaviour (e.g. WinEH). This is mostly to ensure that differences between ARM and X86 remain disjoint and do not accidentally cross boundaries. This is the final staging change for enabling object emission for Windows on ARM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207344 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCStreamer.h | 8 --- lib/MC/WinCOFFStreamer.cpp | 16 +----- lib/Target/X86/MCTargetDesc/CMakeLists.txt | 1 + .../X86/MCTargetDesc/X86MCTargetDesc.cpp | 2 +- lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h | 9 ++++ .../X86/MCTargetDesc/X86WinCOFFStreamer.cpp | 51 +++++++++++++++++++ 6 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index 88f2b71f187..06ad1465385 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -773,14 +773,6 @@ MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB, bool RelaxAll = false, bool LabelSections = false); -/// createWinCOFFStreamer - Create a machine code streamer which will -/// generate Microsoft COFF format object files. -/// -/// Takes ownership of \p TAB and \p CE. -MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB, - MCCodeEmitter &CE, raw_ostream &OS, - bool RelaxAll = false); - /// createELFStreamer - Create a machine code streamer which will generate /// ELF format object files. MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 2d8ca7eb371..ec81dff0c34 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -233,29 +233,15 @@ void MCWinCOFFStreamer::EmitIdent(StringRef IdentString) { } void MCWinCOFFStreamer::EmitWin64EHHandlerData() { - MCStreamer::EmitWin64EHHandlerData(); - - // We have to emit the unwind info now, because this directive - // actually switches to the .xdata section! - MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo()); + llvm_unreachable("not implemented"); } void MCWinCOFFStreamer::FinishImpl() { - EmitFrames(nullptr, true); - EmitW64Tables(); MCObjectStreamer::FinishImpl(); } MCSymbolData &MCWinCOFFStreamer::getOrCreateSymbolData(const MCSymbol *Symbol) { return getAssembler().getOrCreateSymbolData(*Symbol); } - -MCStreamer *createWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, - MCCodeEmitter &CE, raw_ostream &OS, - bool RelaxAll) { - MCWinCOFFStreamer *S = new MCWinCOFFStreamer(Context, MAB, CE, OS); - S->getAssembler().setRelaxAll(RelaxAll); - return S; -} } diff --git a/lib/Target/X86/MCTargetDesc/CMakeLists.txt b/lib/Target/X86/MCTargetDesc/CMakeLists.txt index 3f5a0e2bafb..129c28d804e 100644 --- a/lib/Target/X86/MCTargetDesc/CMakeLists.txt +++ b/lib/Target/X86/MCTargetDesc/CMakeLists.txt @@ -5,6 +5,7 @@ add_llvm_library(LLVMX86Desc X86MCCodeEmitter.cpp X86MachObjectWriter.cpp X86ELFObjectWriter.cpp + X86WinCOFFStreamer.cpp X86WinCOFFObjectWriter.cpp X86MachORelocationInfo.cpp X86ELFRelocationInfo.cpp diff --git a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp index fdc234d211c..e63036c1a55 100644 --- a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -364,7 +364,7 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT, return createMachOStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll); case Triple::COFF: assert(TheTriple.isOSWindows() && "only Windows COFF is supported"); - return createWinCOFFStreamer(Ctx, MAB, *_Emitter, _OS, RelaxAll); + return createX86WinCOFFStreamer(Ctx, MAB, _Emitter, _OS, RelaxAll); case Triple::ELF: return createELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack); } diff --git a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h index 41ae4354cbf..8fe40fd2362 100644 --- a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h +++ b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h @@ -26,6 +26,7 @@ class MCObjectWriter; class MCRegisterInfo; class MCSubtargetInfo; class MCRelocationInfo; +class MCStreamer; class Target; class StringRef; class raw_ostream; @@ -84,6 +85,14 @@ MCAsmBackend *createX86_32AsmBackend(const Target &T, const MCRegisterInfo &MRI, MCAsmBackend *createX86_64AsmBackend(const Target &T, const MCRegisterInfo &MRI, StringRef TT, StringRef CPU); +/// createX86WinCOFFStreamer - Construct an X86 Windows COFF machine code +/// streamer which will generate PE/COFF format object files. +/// +/// Takes ownership of \p AB and \p CE. +MCStreamer *createX86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, + MCCodeEmitter *CE, raw_ostream &OS, + bool RelaxAll); + /// createX86MachObjectWriter - Construct an X86 Mach-O object writer. MCObjectWriter *createX86MachObjectWriter(raw_ostream &OS, bool Is64Bit, diff --git a/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp b/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp new file mode 100644 index 00000000000..526868487a0 --- /dev/null +++ b/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp @@ -0,0 +1,51 @@ +//===-- X86WinCOFFStreamer.cpp - X86 Target WinCOFF Streamer ----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "X86MCTargetDesc.h" +#include "llvm/MC/MCWinCOFFStreamer.h" + +using namespace llvm; + +namespace { +class X86WinCOFFStreamer : public MCWinCOFFStreamer { +public: + X86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, MCCodeEmitter *CE, + raw_ostream &OS) + : MCWinCOFFStreamer(C, AB, *CE, OS) { } + + void EmitWin64EHHandlerData() override; + void FinishImpl() override; +}; + +void X86WinCOFFStreamer::EmitWin64EHHandlerData() { + MCStreamer::EmitWin64EHHandlerData(); + + // We have to emit the unwind info now, because this directive + // actually switches to the .xdata section! + MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo()); +} + +void X86WinCOFFStreamer::FinishImpl() { + EmitFrames(nullptr, true); + EmitW64Tables(); + + MCWinCOFFStreamer::FinishImpl(); +} +} + +namespace llvm { +MCStreamer *createX86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, + MCCodeEmitter *CE, raw_ostream &OS, + bool RelaxAll) { + X86WinCOFFStreamer *S = new X86WinCOFFStreamer(C, AB, CE, OS); + S->getAssembler().setRelaxAll(RelaxAll); + return S; +} +} +