LLVM  3.7.0
BPFELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- BPFELFObjectWriter.cpp - BPF 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 
12 #include "llvm/MC/MCFixup.h"
14 
15 using namespace llvm;
16 
17 namespace {
18 class BPFELFObjectWriter : public MCELFObjectTargetWriter {
19 public:
20  BPFELFObjectWriter(uint8_t OSABI);
21 
22  ~BPFELFObjectWriter() override;
23 
24 protected:
25  unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
26  bool IsPCRel) const override;
27 };
28 }
29 
30 BPFELFObjectWriter::BPFELFObjectWriter(uint8_t OSABI)
31  : MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_NONE,
32  /*HasRelocationAddend*/ false) {}
33 
34 BPFELFObjectWriter::~BPFELFObjectWriter() {}
35 
36 unsigned BPFELFObjectWriter::GetRelocType(const MCValue &Target,
37  const MCFixup &Fixup,
38  bool IsPCRel) const {
39  // determine the type of the relocation
40  switch ((unsigned)Fixup.getKind()) {
41  default:
42  llvm_unreachable("invalid fixup kind!");
43  case FK_SecRel_8:
44  return ELF::R_X86_64_64;
45  case FK_SecRel_4:
46  return ELF::R_X86_64_PC32;
47  }
48 }
49 
51  uint8_t OSABI, bool IsLittleEndian) {
52  MCELFObjectTargetWriter *MOTW = new BPFELFObjectWriter(OSABI);
53  return createELFObjectWriter(MOTW, OS, IsLittleEndian);
54 }
This represents an "assembler immediate".
Definition: MCValue.h:44
MCObjectWriter * createBPFELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI, bool IsLittleEndian)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:62
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
A four-byte section relative fixup.
Definition: MCFixup.h:38
#define false
Definition: ConvertUTF.c:65
#define true
Definition: ConvertUTF.c:66
MCFixupKind getKind() const
Definition: MCFixup.h:89
PowerPC TLS Dynamic Call Fixup
Target - Wrapper for Target specific information.
MCObjectWriter * createELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
A eight-byte section relative fixup.
Definition: MCFixup.h:39
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321