LLVM  6.0.0svn
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 
11 #include "llvm/BinaryFormat/ELF.h"
13 #include "llvm/MC/MCFixup.h"
14 #include "llvm/MC/MCObjectWriter.h"
16 #include <cstdint>
17 
18 using namespace llvm;
19 
20 namespace {
21 
22 class BPFELFObjectWriter : public MCELFObjectTargetWriter {
23 public:
24  BPFELFObjectWriter(uint8_t OSABI);
25  ~BPFELFObjectWriter() override = default;
26 
27 protected:
28  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
29  const MCFixup &Fixup, bool IsPCRel) const override;
30 };
31 
32 } // end anonymous namespace
33 
34 BPFELFObjectWriter::BPFELFObjectWriter(uint8_t OSABI)
35  : MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_BPF,
36  /*HasRelocationAddend*/ false) {}
37 
39  const MCFixup &Fixup,
40  bool IsPCRel) const {
41  // determine the type of the relocation
42  switch ((unsigned)Fixup.getKind()) {
43  default:
44  llvm_unreachable("invalid fixup kind!");
45  case FK_SecRel_8:
46  return ELF::R_BPF_64_64;
47  case FK_PCRel_4:
48  case FK_SecRel_4:
49  return ELF::R_BPF_64_32;
50  case FK_Data_8:
51  return ELF::R_BPF_64_64;
52  case FK_Data_4:
53  return ELF::R_BPF_64_32;
54  }
55 }
56 
57 std::unique_ptr<MCObjectWriter>
59  bool IsLittleEndian) {
60  return createELFObjectWriter(llvm::make_unique<BPFELFObjectWriter>(OSABI), OS,
61  IsLittleEndian);
62 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
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:59
std::unique_ptr< MCObjectWriter > createELFObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A four-byte pc relative fixup.
Definition: MCFixup.h:30
std::unique_ptr< MCObjectWriter > createBPFELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI, bool IsLittleEndian)
Target - Wrapper for Target specific information.
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:337
MCFixupKind getKind() const
Definition: MCFixup.h:93