[PATCH v2 1/5] BPF: Use a provisional ELF e_machine value
Richard Henderson via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 23 15:52:20 PDT 2016
This same value for EM_BPF is being propagated to glibc,
elfutils, and binutils.
Signed-off-by: Richard Henderson <rth at twiddle.net>
---
include/llvm/Object/ELFObjectFile.h | 5 +++++
include/llvm/Support/ELF.h | 7 +++++++
include/llvm/Support/ELFRelocs/BPF.def | 9 +++++++++
lib/Object/ELF.cpp | 6 ++++++
lib/ObjectYAML/ELFYAML.cpp | 4 ++++
lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp | 7 ++++++-
tools/llvm-objdump/llvm-objdump.cpp | 1 +
tools/llvm-readobj/ELFDumper.cpp | 1 +
8 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 include/llvm/Support/ELFRelocs/BPF.def
diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h
index f930088..f006f06 100644
--- a/include/llvm/Object/ELFObjectFile.h
+++ b/include/llvm/Object/ELFObjectFile.h
@@ -886,6 +886,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
return (EF.getHeader()->e_ident[ELF::EI_OSABI] == ELF::ELFOSABI_AMDGPU_HSA
&& IsLittleEndian) ?
"ELF64-amdgpu-hsacobj" : "ELF64-amdgpu";
+ case ELF::EM_BPF:
+ return "ELF64-BPF";
default:
return "ELF64-unknown";
}
@@ -948,6 +950,9 @@ unsigned ELFObjectFile<ELFT>::getArch() const {
&& IsLittleEndian) ?
Triple::amdgcn : Triple::UnknownArch;
+ case ELF::EM_BPF:
+ return (IsLittleEndian ? Triple::bpfel : Triple::bpfeb);
+
default:
return Triple::UnknownArch;
}
diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h
index e3c77f4..1df8658 100644
--- a/include/llvm/Support/ELF.h
+++ b/include/llvm/Support/ELF.h
@@ -311,6 +311,8 @@ enum {
EM_CSR_KALIMBA = 219, // CSR Kalimba architecture family
EM_AMDGPU = 224, // AMD GPU architecture
+ EM_BPF = 247, // Linux kernel bpf virtual machine
+
// A request has been made to the maintainer of the official registry for
// such numbers for an official value for WebAssembly. As soon as one is
// allocated, this enum will be updated to use it.
@@ -620,6 +622,11 @@ enum {
#include "ELFRelocs/AMDGPU.def"
};
+// ELF Relocation types for BPF
+enum {
+#include "ELFRelocs/BPF.def"
+};
+
#undef ELF_RELOC
// Section header.
diff --git a/include/llvm/Support/ELFRelocs/BPF.def b/include/llvm/Support/ELFRelocs/BPF.def
new file mode 100644
index 0000000..868974d
--- /dev/null
+++ b/include/llvm/Support/ELFRelocs/BPF.def
@@ -0,0 +1,9 @@
+#ifndef ELF_RELOC
+#error "ELF_RELOC must be defined"
+#endif
+
+// No relocation
+ELF_RELOC(R_BPF_NONE, 0)
+// Map index in "maps" section to file descriptor
+// within ld_64 instruction.
+ELF_RELOC(R_BPF_MAP_FD, 1)
diff --git a/lib/Object/ELF.cpp b/lib/Object/ELF.cpp
index 4002eb7..2dde18a 100644
--- a/lib/Object/ELF.cpp
+++ b/lib/Object/ELF.cpp
@@ -111,6 +111,12 @@ StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) {
default:
break;
}
+ case ELF::EM_BPF:
+ switch (Type) {
+#include "llvm/Support/ELFRelocs/BPF.def"
+ default:
+ break;
+ }
break;
default:
break;
diff --git a/lib/ObjectYAML/ELFYAML.cpp b/lib/ObjectYAML/ELFYAML.cpp
index a480783..527fc9b 100644
--- a/lib/ObjectYAML/ELFYAML.cpp
+++ b/lib/ObjectYAML/ELFYAML.cpp
@@ -195,6 +195,7 @@ ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(IO &IO,
ECase(EM_56800EX)
ECase(EM_AMDGPU)
ECase(EM_LANAI)
+ ECase(EM_BPF)
#undef ECase
}
@@ -534,6 +535,9 @@ void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
case ELF::EM_AMDGPU:
#include "llvm/Support/ELFRelocs/AMDGPU.def"
break;
+ case ELF::EM_BPF:
+#include "llvm/Support/ELFRelocs/BPF.def"
+ break;
default:
llvm_unreachable("Unsupported architecture");
}
diff --git a/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp b/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
index 115f010..50a88b7 100644
--- a/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
+++ b/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
@@ -28,7 +28,7 @@ protected:
}
BPFELFObjectWriter::BPFELFObjectWriter(uint8_t OSABI)
- : MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_NONE,
+ : MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_BPF,
/*HasRelocationAddend*/ false) {}
BPFELFObjectWriter::~BPFELFObjectWriter() {}
@@ -37,6 +37,11 @@ unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
// determine the type of the relocation
+ // ??? Give these some proper names.
+ // ??? Note that R_BPF_MAP_FD (= R_X86_64_64) is the only relocation
+ // supported by the loader. Which others of these actually need
+ // to be emitted in the circumstances?
+
switch ((unsigned)Fixup.getKind()) {
default:
llvm_unreachable("invalid fixup kind!");
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 3beb01a..31e12f1 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -583,6 +583,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
case ELF::EM_ARM:
case ELF::EM_HEXAGON:
case ELF::EM_MIPS:
+ case ELF::EM_BPF:
res = Target;
break;
case ELF::EM_WEBASSEMBLY:
diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp
index 84e368e..06fbe8d 100644
--- a/tools/llvm-readobj/ELFDumper.cpp
+++ b/tools/llvm-readobj/ELFDumper.cpp
@@ -956,6 +956,7 @@ static const EnumEntry<unsigned> ElfMachineType[] = {
ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"),
ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY"),
ENUM_ENT(EM_LANAI, "EM_LANAI"),
+ ENUM_ENT(EM_BPF, "EM_BPF"),
};
static const EnumEntry<unsigned> ElfSymbolBindings[] = {
--
2.5.5
More information about the llvm-commits
mailing list