LLVM  4.0.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"
13 #include "llvm/Support/ELF.h"
15 #include <cstdint>
16 
17 using namespace llvm;
18 
19 namespace {
20 
21 class BPFELFObjectWriter : public MCELFObjectTargetWriter {
22 public:
23  BPFELFObjectWriter(uint8_t OSABI);
24  ~BPFELFObjectWriter() override = default;
25 
26 protected:
27  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
28  const MCFixup &Fixup, bool IsPCRel) const override;
29 };
30 
31 } // end anonymous namespace
32 
33 BPFELFObjectWriter::BPFELFObjectWriter(uint8_t OSABI)
34  : MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_BPF,
35  /*HasRelocationAddend*/ false) {}
36 
38  const MCFixup &Fixup,
39  bool IsPCRel) const {
40  // determine the type of the relocation
41  switch ((unsigned)Fixup.getKind()) {
42  default:
43  llvm_unreachable("invalid fixup kind!");
44  case FK_SecRel_8:
45  return ELF::R_BPF_64_64;
46  case FK_SecRel_4:
47  return ELF::R_BPF_64_32;
48  case FK_Data_8:
49  return ELF::R_BPF_64_64;
50  case FK_Data_4:
51  return ELF::R_BPF_64_32;
52  }
53 }
54 
56  uint8_t OSABI, bool IsLittleEndian) {
57  MCELFObjectTargetWriter *MOTW = new BPFELFObjectWriter(OSABI);
58  return createELFObjectWriter(MOTW, OS, IsLittleEndian);
59 }
This represents an "assembler immediate".
Definition: MCValue.h:40
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:66
static unsigned getRelocType(const MCValue &Target, const MCFixupKind FixupKind, const bool IsPCRel)
Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
A four-byte section relative fixup.
Definition: MCFixup.h:42
A four-byte fixup.
Definition: MCFixup.h:26
Context object for machine code objects.
Definition: MCContext.h:51
Function Alias Analysis false
MCFixupKind getKind() const
Definition: MCFixup.h:93
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
Basic Alias true
A eight-byte section relative fixup.
Definition: MCFixup.h:43
A eight-byte fixup.
Definition: MCFixup.h:27
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333