1 //===-------------- ELF.cpp - JIT linker function for ELF -------------===// 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 // 10 // ELF jit-link function. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/ExecutionEngine/JITLink/ELF.h" 15 16 #include "llvm/BinaryFormat/ELF.h" 17 #include "llvm/ExecutionEngine/JITLink/ELF_x86_64.h" 18 #include "llvm/Support/Endian.h" 19 #include "llvm/Support/Format.h" 20 #include "llvm/Support/MemoryBuffer.h" 21 #include <cstring> 22 23 using namespace llvm; 24 25 #define DEBUG_TYPE "jitlink" 26 27 namespace llvm { 28 namespace jitlink { 29 30 void jitLink_ELF(std::unique_ptr<JITLinkContext> Ctx) { 31 32 // We don't want to do full ELF validation here. We just verify it is elf'ish. 33 // Probably should parse into an elf header when we support more than x86 :) 34 35 StringRef Data = Ctx->getObjectBuffer().getBuffer(); 36 if (Data.size() < llvm::ELF::EI_MAG3 + 1) { 37 Ctx->notifyFailed(make_error<JITLinkError>("Truncated ELF buffer")); 38 return; 39 } 40 41 if (!memcmp(Data.data(), llvm::ELF::ElfMagic, strlen(llvm::ELF::ElfMagic))) { 42 if (Data.data()[llvm::ELF::EI_CLASS] == ELF::ELFCLASS64) { 43 return jitLink_ELF_x86_64(std::move(Ctx)); 44 } 45 } 46 47 Ctx->notifyFailed(make_error<JITLinkError>("ELF magic not valid")); 48 } 49 50 } // end namespace jitlink 51 } // end namespace llvm 52