Index: lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt =================================================================== --- lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt +++ lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt @@ -6,6 +6,7 @@ RuntimeDyldCOFF.cpp RuntimeDyldELF.cpp RuntimeDyldMachO.cpp + Targets/RuntimeDyldELFBPF.cpp Targets/RuntimeDyldELFMips.cpp DEPENDS Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp =================================================================== --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -13,6 +13,7 @@ #include "RuntimeDyldELF.h" #include "RuntimeDyldCheckerImpl.h" +#include "Targets/RuntimeDyldELFBPF.h" #include "Targets/RuntimeDyldELFMips.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" @@ -240,6 +241,9 @@ switch (Arch) { default: return make_unique(MemMgr, Resolver); + case Triple::bpfel: + case Triple::bpfeb: + return make_unique(MemMgr, Resolver); case Triple::mips: case Triple::mipsel: case Triple::mips64: Index: lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldELFBPF.h =================================================================== --- /dev/null +++ lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldELFBPF.h @@ -0,0 +1,32 @@ +//===-- RuntimeDyldELFBPF.h ---- ELF/BPF specific code. ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDELFBPF_H +#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDELFBPF_H + +#include "../RuntimeDyldELF.h" +#include + +#define DEBUG_TYPE "dyld" + +namespace llvm { + +class RuntimeDyldELFBPF : public RuntimeDyldELF { +public: + RuntimeDyldELFBPF(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver) + : RuntimeDyldELF(MM, Resolver) {} + + Error finalizeLoad(const ObjectFile &Obj, + ObjSectionToIDMap &SectionMap) override; +}; +} // namespace llvm + +#undef DEBUG_TYPE + +#endif Index: lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldELFBPF.cpp =================================================================== --- /dev/null +++ lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldELFBPF.cpp @@ -0,0 +1,43 @@ +//===-- RuntimeDyldELFBPF.cpp ---- ELF/BPF specific code. -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "RuntimeDyldELFBPF.h" + +#define DEBUG_TYPE "dyld" + +// The .BTF section has no symbols or any relocations. Hence +// runtime dyld won't load it. Load it here. +Error RuntimeDyldELFBPF::finalizeLoad(const ObjectFile &Obj, + ObjSectionToIDMap &SectionMap) { + for (section_iterator SI = Obj.section_begin(), SE = Obj.section_end(); + SI != SE; ++SI) { + // Ignore sections already in SectionMap + if (SectionMap.find(*SI) != SectionMap.end()) + continue; + + StringRef SectionName; + SI->getName(SectionName); + + if (SectionName != ".BTF") + continue; + + // Load .BTF section. + bool IsCode = SI->isText(); + if (auto SectionIDOrErr = findOrEmitSection(Obj, *SI, IsCode, SectionMap)) { + LLVM_DEBUG(dbgs() << "\tSectionID: " << (*SectionIDOrErr) << "\n"); + } else { + return make_error( + "RuntimeDyldELFBPF load section error"); + } + + break; + } + + return RuntimeDyldELF::finalizeLoad(Obj, SectionMap); +}