[llvm] aff57ff - [JITLink][ELF] Add generic ELFLinkGraphBuilder template.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 26 04:37:58 PDT 2021


Author: Lang Hames
Date: 2021-06-26T21:37:33+10:00
New Revision: aff57ff24aca5074b427d6bbc2f3246aa97910c5

URL: https://github.com/llvm/llvm-project/commit/aff57ff24aca5074b427d6bbc2f3246aa97910c5
DIFF: https://github.com/llvm/llvm-project/commit/aff57ff24aca5074b427d6bbc2f3246aa97910c5.diff

LOG: [JITLink][ELF] Add generic ELFLinkGraphBuilder template.

ELFLinkGraphBuilder<ELFT> will hold generic parsing and LinkGraph-building code
that can be shared between JITLink ELF backends for different architectures.

For now it's just a stub. The plan is to incrementally move functionality down
from ELFLinkGraphBuilder_x86_64 into the new template.

Added: 
    llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.cpp
    llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h

Modified: 
    llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
    llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
index bb3b62267106..ab4b24abd492 100644
--- a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
@@ -15,6 +15,7 @@ add_llvm_component_library(LLVMJITLink
   # ELF
 
   ELF.cpp
+  ELFLinkGraphBuilder.cpp
   ELF_x86_64.cpp
 
   # Architectures:

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.cpp
new file mode 100644
index 000000000000..d1e221b2145b
--- /dev/null
+++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.cpp
@@ -0,0 +1,23 @@
+//=----------- ELFLinkGraphBuilder.cpp - ELF LinkGraph builder ------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Generic ELF LinkGraph buliding code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ELFLinkGraphBuilder.h"
+
+#define DEBUG_TYPE "jitlink"
+
+namespace llvm {
+namespace jitlink {
+
+ELFLinkGraphBuilderBase::~ELFLinkGraphBuilderBase() {}
+
+} // end namespace jitlink
+} // end namespace llvm

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
new file mode 100644
index 000000000000..0841bdb62165
--- /dev/null
+++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
@@ -0,0 +1,56 @@
+//===------- ELFLinkGraphBuilder.h - ELF LinkGraph builder ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Generic ELF LinkGraph building code.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LIB_EXECUTIONENGINE_JITLINK_ELFLINKGRAPHBUILDER_H
+#define LIB_EXECUTIONENGINE_JITLINK_ELFLINKGRAPHBUILDER_H
+
+#include "llvm/ExecutionEngine/JITLink/JITLink.h"
+#include "llvm/Object/ELF.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace jitlink {
+
+/// Common link-graph building code shared between all ELFFiles.
+class ELFLinkGraphBuilderBase {
+public:
+  virtual ~ELFLinkGraphBuilderBase();
+};
+
+/// Ling-graph building code that's specific to the given ELFT, but common
+/// across all architectures.
+template <typename ELFT>
+class ELFLinkGraphBuilder : public ELFLinkGraphBuilderBase {
+public:
+  ELFLinkGraphBuilder(const object::ELFFile<ELFT> &Obj, Triple TT,
+                      StringRef FileName,
+                      LinkGraph::GetEdgeKindNameFunction GetEdgeKindName);
+
+protected:
+  std::unique_ptr<LinkGraph> G;
+  const object::ELFFile<ELFT> &Obj;
+};
+
+template <typename ELFT>
+ELFLinkGraphBuilder<ELFT>::ELFLinkGraphBuilder(
+    const object::ELFFile<ELFT> &Obj, Triple TT, StringRef FileName,
+    LinkGraph::GetEdgeKindNameFunction GetEdgeKindName)
+    : G(std::make_unique<LinkGraph>(FileName.str(), Triple(std::move(TT)),
+                                    ELFT::Is64Bits ? 8 : 4,
+                                    support::endianness(ELFT::TargetEndianness),
+                                    std::move(GetEdgeKindName))),
+      Obj(Obj) {}
+
+} // end namespace jitlink
+} // end namespace llvm
+
+#endif // LIB_EXECUTIONENGINE_JITLINK_ELFLINKGRAPHBUILDER_H

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
index 41d4583de454..80f814f51fa5 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
@@ -18,6 +18,7 @@
 
 #include "DefineExternalSectionStartAndEndSymbols.h"
 #include "EHFrameSupportImpl.h"
+#include "ELFLinkGraphBuilder.h"
 #include "JITLinkGeneric.h"
 #include "PerGraphGOTAndPLTStubsBuilder.h"
 
@@ -237,7 +238,7 @@ namespace jitlink {
 
 // This should become a template as the ELFFile is so a lot of this could become
 // generic
-class ELFLinkGraphBuilder_x86_64 {
+class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
 
 private:
   Section *CommonSection = nullptr;
@@ -285,9 +286,7 @@ class ELFLinkGraphBuilder_x86_64 {
                                     formatv("{0:d}", Type));
   }
 
-  std::unique_ptr<LinkGraph> G;
   // This could be a template
-  const object::ELFFile<object::ELF64LE> &Obj;
   object::ELFFile<object::ELF64LE>::Elf_Shdr_Range sections;
   SymbolTable SymTab;
 
@@ -685,10 +684,8 @@ class ELFLinkGraphBuilder_x86_64 {
 public:
   ELFLinkGraphBuilder_x86_64(StringRef FileName,
                              const object::ELFFile<object::ELF64LE> &Obj)
-      : G(std::make_unique<LinkGraph>(
-            FileName.str(), Triple("x86_64-unknown-linux"), getPointerSize(Obj),
-            getEndianness(Obj), getELFX86RelocationKindName)),
-        Obj(Obj) {}
+      : ELFLinkGraphBuilder(Obj, Triple("x86_64-unknown-linux"), FileName,
+                            getELFX86RelocationKindName) {}
 
   Expected<std::unique_ptr<LinkGraph>> buildGraph() {
     // Sanity check: we only operate on relocatable objects.


        


More information about the llvm-commits mailing list