54953b4033d5a050a46a1dbd25d31bb35dc8d82f
[oota-llvm.git] / lib / Target / WebAssembly / MCTargetDesc / WebAssemblyELFObjectWriter.cpp
1 //===-- WebAssemblyELFObjectWriter.cpp - WebAssembly ELF Writer -----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file handles ELF-specific object emission, converting LLVM's
12 /// internal fixups into the appropriate relocations.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
17 #include "llvm/MC/MCELFObjectWriter.h"
18 #include "llvm/MC/MCFixup.h"
19 #include "llvm/Support/ErrorHandling.h"
20 using namespace llvm;
21
22 namespace {
23 class WebAssemblyELFObjectWriter final : public MCELFObjectTargetWriter {
24 public:
25   WebAssemblyELFObjectWriter(bool Is64Bit, uint8_t OSABI);
26
27   ~WebAssemblyELFObjectWriter() override;
28
29 protected:
30   unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
31                         bool IsPCRel) const override;
32 };
33 } // end anonymous namespace
34
35 // FIXME: Use EM_NONE as a temporary hack. Should we decide to pursue ELF
36 // writing seriously, we should email generic-abi@googlegroups.com and ask
37 // for our own ELF code.
38 WebAssemblyELFObjectWriter::WebAssemblyELFObjectWriter(bool Is64Bit,
39                                                        uint8_t OSABI)
40     : MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_NONE,
41                               /*HasRelocationAddend=*/true) {}
42
43 WebAssemblyELFObjectWriter::~WebAssemblyELFObjectWriter() {}
44
45 unsigned WebAssemblyELFObjectWriter::GetRelocType(const MCValue &Target,
46                                                   const MCFixup &Fixup,
47                                                   bool IsPCRel) const {
48   // FIXME: Do we need our own relocs?
49   return Fixup.getKind();
50 }
51
52 MCObjectWriter *llvm::createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
53                                                        bool Is64Bit,
54                                                        uint8_t OSABI) {
55   MCELFObjectTargetWriter *MOTW =
56       new WebAssemblyELFObjectWriter(Is64Bit, OSABI);
57   return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/true);
58 }