Skip to content

Commit

Permalink
BPF: Use official ELF e_machine value
Browse files Browse the repository at this point in the history
The same value for EM_BPF is being propagated to glibc,
elfutils, and binutils.

Signed-off-by: Richard Henderson <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275633 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
4ast committed Jul 15, 2016
1 parent 6417b3c commit 36b9c09
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions include/llvm/Support/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ enum {
EM_CSR_KALIMBA = 219, // CSR Kalimba architecture family
EM_AMDGPU = 224, // AMD GPU architecture
EM_LANAI = 244, // Lanai 32-bit processor
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
Expand Down Expand Up @@ -616,6 +617,11 @@ enum {
#include "ELFRelocs/AMDGPU.def"
};

// ELF Relocation types for BPF
enum {
#include "ELFRelocs/BPF.def"
};

#undef ELF_RELOC

// Section header.
Expand Down
9 changes: 9 additions & 0 deletions include/llvm/Support/ELFRelocs/BPF.def
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BPFELFObjectWriter : public MCELFObjectTargetWriter {
}

BPFELFObjectWriter::BPFELFObjectWriter(uint8_t OSABI)
: MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_NONE,
: MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_BPF,
/*HasRelocationAddend*/ false) {}

BPFELFObjectWriter::~BPFELFObjectWriter() {}
Expand Down
1 change: 1 addition & 0 deletions tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,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:
Expand Down
1 change: 1 addition & 0 deletions tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down

0 comments on commit 36b9c09

Please sign in to comment.