--- /dev/null
+//=----------- 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
--- /dev/null
+//===------- 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
#include "DefineExternalSectionStartAndEndSymbols.h"
#include "EHFrameSupportImpl.h"
+#include "ELFLinkGraphBuilder.h"
#include "JITLinkGeneric.h"
#include "PerGraphGOTAndPLTStubsBuilder.h"
// 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;
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;
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.