Skip to content

Commit cfb51f5

Browse files
committed
BPF: Use official ELF e_machine value
The same value for EM_BPF is being propagated to glibc, elfutils, and binutils. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org> llvm-svn: 275633
1 parent 70a65c2 commit cfb51f5

File tree

8 files changed

+33
-1
lines changed

8 files changed

+33
-1
lines changed

llvm/include/llvm/Object/ELFObjectFile.h

+5
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
886886
return (EF.getHeader()->e_ident[ELF::EI_OSABI] == ELF::ELFOSABI_AMDGPU_HSA
887887
&& IsLittleEndian) ?
888888
"ELF64-amdgpu-hsacobj" : "ELF64-amdgpu";
889+
case ELF::EM_BPF:
890+
return "ELF64-BPF";
889891
default:
890892
return "ELF64-unknown";
891893
}
@@ -948,6 +950,9 @@ unsigned ELFObjectFile<ELFT>::getArch() const {
948950
&& IsLittleEndian) ?
949951
Triple::amdgcn : Triple::UnknownArch;
950952

953+
case ELF::EM_BPF:
954+
return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
955+
951956
default:
952957
return Triple::UnknownArch;
953958
}

llvm/include/llvm/Support/ELF.h

+6
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ enum {
311311
EM_CSR_KALIMBA = 219, // CSR Kalimba architecture family
312312
EM_AMDGPU = 224, // AMD GPU architecture
313313
EM_LANAI = 244, // Lanai 32-bit processor
314+
EM_BPF = 247, // Linux kernel bpf virtual machine
314315

315316
// A request has been made to the maintainer of the official registry for
316317
// such numbers for an official value for WebAssembly. As soon as one is
@@ -616,6 +617,11 @@ enum {
616617
#include "ELFRelocs/AMDGPU.def"
617618
};
618619

620+
// ELF Relocation types for BPF
621+
enum {
622+
#include "ELFRelocs/BPF.def"
623+
};
624+
619625
#undef ELF_RELOC
620626

621627
// Section header.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef ELF_RELOC
2+
#error "ELF_RELOC must be defined"
3+
#endif
4+
5+
// No relocation
6+
ELF_RELOC(R_BPF_NONE, 0)
7+
// Map index in "maps" section to file descriptor
8+
// within ld_64 instruction.
9+
ELF_RELOC(R_BPF_MAP_FD, 1)

llvm/lib/Object/ELF.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) {
111111
default:
112112
break;
113113
}
114+
case ELF::EM_BPF:
115+
switch (Type) {
116+
#include "llvm/Support/ELFRelocs/BPF.def"
117+
default:
118+
break;
119+
}
114120
break;
115121
default:
116122
break;

llvm/lib/ObjectYAML/ELFYAML.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(IO &IO,
195195
ECase(EM_56800EX)
196196
ECase(EM_AMDGPU)
197197
ECase(EM_LANAI)
198+
ECase(EM_BPF)
198199
#undef ECase
199200
}
200201

@@ -534,6 +535,9 @@ void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
534535
case ELF::EM_AMDGPU:
535536
#include "llvm/Support/ELFRelocs/AMDGPU.def"
536537
break;
538+
case ELF::EM_BPF:
539+
#include "llvm/Support/ELFRelocs/BPF.def"
540+
break;
537541
default:
538542
llvm_unreachable("Unsupported architecture");
539543
}

llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BPFELFObjectWriter : public MCELFObjectTargetWriter {
2828
}
2929

3030
BPFELFObjectWriter::BPFELFObjectWriter(uint8_t OSABI)
31-
: MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_NONE,
31+
: MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, ELF::EM_BPF,
3232
/*HasRelocationAddend*/ false) {}
3333

3434
BPFELFObjectWriter::~BPFELFObjectWriter() {}

llvm/tools/llvm-objdump/llvm-objdump.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
589589
case ELF::EM_ARM:
590590
case ELF::EM_HEXAGON:
591591
case ELF::EM_MIPS:
592+
case ELF::EM_BPF:
592593
res = Target;
593594
break;
594595
case ELF::EM_WEBASSEMBLY:

llvm/tools/llvm-readobj/ELFDumper.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ static const EnumEntry<unsigned> ElfMachineType[] = {
956956
ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"),
957957
ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY"),
958958
ENUM_ENT(EM_LANAI, "EM_LANAI"),
959+
ENUM_ENT(EM_BPF, "EM_BPF"),
959960
};
960961

961962
static const EnumEntry<unsigned> ElfSymbolBindings[] = {

0 commit comments

Comments
 (0)