[PATCH] D90860: [JITLink][ELF] Route objects to their matching linker backends based on header info
Stefan Gränitz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 8 01:56:35 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG83b52b5ba278: [JITLink][ELF] Route objects to their matching linker backends based on header… (authored by sgraenitz).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90860/new/
https://reviews.llvm.org/D90860
Files:
llvm/lib/ExecutionEngine/JITLink/ELF.cpp
Index: llvm/lib/ExecutionEngine/JITLink/ELF.cpp
===================================================================
--- llvm/lib/ExecutionEngine/JITLink/ELF.cpp
+++ llvm/lib/ExecutionEngine/JITLink/ELF.cpp
@@ -15,6 +15,7 @@
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/ExecutionEngine/JITLink/ELF_x86_64.h"
+#include "llvm/Object/ELF.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -27,24 +28,56 @@
namespace llvm {
namespace jitlink {
-void jitLink_ELF(std::unique_ptr<JITLinkContext> Ctx) {
+Expected<uint16_t> readTargetMachineArch(StringRef Buffer) {
+ const char *Data = Buffer.data();
- // We don't want to do full ELF validation here. We just verify it is elf'ish.
- // Probably should parse into an elf header when we support more than x86 :)
+ if (Data[ELF::EI_DATA] == ELF::ELFDATA2LSB) {
+ if (Data[ELF::EI_CLASS] == ELF::ELFCLASS64) {
+ if (auto File = llvm::object::ELF64LEFile::create(Buffer)) {
+ return File->getHeader().e_machine;
+ } else {
+ return File.takeError();
+ }
+ } else if (Data[ELF::EI_CLASS] == ELF::ELFCLASS32) {
+ if (auto File = llvm::object::ELF32LEFile::create(Buffer)) {
+ return File->getHeader().e_machine;
+ } else {
+ return File.takeError();
+ }
+ }
+ }
- StringRef Data = Ctx->getObjectBuffer().getBuffer();
- if (Data.size() < llvm::ELF::EI_MAG3 + 1) {
+ return ELF::EM_NONE;
+}
+
+void jitLink_ELF(std::unique_ptr<JITLinkContext> Ctx) {
+ StringRef Buffer = Ctx->getObjectBuffer().getBuffer();
+ if (Buffer.size() < ELF::EI_MAG3 + 1) {
Ctx->notifyFailed(make_error<JITLinkError>("Truncated ELF buffer"));
return;
}
- if (!memcmp(Data.data(), llvm::ELF::ElfMagic, strlen(llvm::ELF::ElfMagic))) {
- if (Data.data()[llvm::ELF::EI_CLASS] == ELF::ELFCLASS64) {
- return jitLink_ELF_x86_64(std::move(Ctx));
- }
+ if (memcmp(Buffer.data(), ELF::ElfMagic, strlen(ELF::ElfMagic)) != 0) {
+ Ctx->notifyFailed(make_error<JITLinkError>("ELF magic not valid"));
+ return;
+ }
+
+ Expected<uint16_t> TargetMachineArch = readTargetMachineArch(Buffer);
+ if (!TargetMachineArch) {
+ Ctx->notifyFailed(TargetMachineArch.takeError());
+ return;
}
- Ctx->notifyFailed(make_error<JITLinkError>("ELF magic not valid"));
+ switch (*TargetMachineArch) {
+ case ELF::EM_X86_64:
+ jitLink_ELF_x86_64(std::move(Ctx));
+ return;
+ default:
+ Ctx->notifyFailed(make_error<JITLinkError>(
+ "Unsupported target machine architecture in ELF object " +
+ Ctx->getObjectBuffer().getBufferIdentifier()));
+ return;
+ }
}
} // end namespace jitlink
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90860.310113.patch
Type: text/x-patch
Size: 2701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201208/fd2801fc/attachment.bin>
More information about the llvm-commits
mailing list