Skip to content

Commit

Permalink
[cling] Backport jitlink ppc64 (root-project#13850)
Browse files Browse the repository at this point in the history
* Backport JITLink ppc64 backend to LLVM-16

* Backport ELF part

* Backport PCREL relocations

* Use jitlink::Section::blocks::empty instead

* Backport TLS PCREL relocation

* [llvm-project] Synchronize with LLVM monorepo fork

---------

Co-authored-by: Jonas Hahnfeld <[email protected]>
  • Loading branch information
bzEq and hahnjo authored Mar 21, 2024
1 parent 7d1dfdd commit 2706217
Show file tree
Hide file tree
Showing 10 changed files with 1,280 additions and 2 deletions.
3 changes: 2 additions & 1 deletion interpreter/cling/lib/Interpreter/IncrementalJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ static bool UseJITLink(const Triple& TT) {
// LLJITBuilderState::prepareForConstruction.
if (TT.getArch() == Triple::riscv64 ||
(TT.isOSBinFormatMachO() &&
(TT.getArch() == Triple::aarch64 || TT.getArch() == Triple::x86_64))) {
(TT.getArch() == Triple::aarch64 || TT.getArch() == Triple::x86_64)) ||
(TT.isOSBinFormatELF() && TT.getArch() == Triple::ppc64le)) {
jitLink = true;
}
// Finally, honor the user's choice by setting an environment variable.
Expand Down
2 changes: 1 addition & 1 deletion interpreter/llvm-project/llvm-project.tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ROOT-llvm16-20240223-01
ROOT-llvm16-20240321-01
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//===------ ELF_ppc64.h - JIT link functions for ELF/ppc64 ------*- 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
//
//===----------------------------------------------------------------------===//
//
// jit-link functions for ELF/ppc64{le}.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_EXECUTIONENGINE_JITLINK_ELF_PPC64_H
#define LLVM_EXECUTIONENGINE_JITLINK_ELF_PPC64_H

#include "llvm/ExecutionEngine/JITLink/JITLink.h"

namespace llvm::jitlink {

/// Create a LinkGraph from an ELF/ppc64 relocatable object.
///
/// Note: The graph does not take ownership of the underlying buffer, nor copy
/// its contents. The caller is responsible for ensuring that the object buffer
/// outlives the graph.
///
/// WARNING: The big-endian backend has not been tested yet.
Expected<std::unique_ptr<LinkGraph>>
createLinkGraphFromELFObject_ppc64(MemoryBufferRef ObjectBuffer);

/// Create a LinkGraph from an ELF/ppc64le relocatable object.
///
/// Note: The graph does not take ownership of the underlying buffer, nor copy
/// its contents. The caller is responsible for ensuring that the object buffer
/// outlives the graph.
Expected<std::unique_ptr<LinkGraph>>
createLinkGraphFromELFObject_ppc64le(MemoryBufferRef ObjectBuffer);

/// jit-link the given object buffer, which must be a ELF ppc64le object file.
///
/// WARNING: The big-endian backend has not been tested yet.
void link_ELF_ppc64(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx);

/// jit-link the given object buffer, which must be a ELF ppc64le object file.
void link_ELF_ppc64le(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx);

} // end namespace llvm::jitlink

#endif // LLVM_EXECUTIONENGINE_JITLINK_ELF_PPC64_H
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ template <typename TableManagerImplT> class TableManager {
return *EntryI->second;
}

/// Register a pre-existing entry.
///
/// Objects may include pre-existing table entries (e.g. for GOTs).
/// This method can be used to register those entries so that they will not
/// be duplicated by createEntry the first time that getEntryForTarget is
/// called.
bool registerPreExistingEntry(Symbol &Target, Symbol &Entry) {
assert(Target.hasName() && "Edge cannot point to anonymous target");
auto Res = Entries.insert({
Target.getName(),
&Entry,
});
return Res.second;
}

private:
TableManagerImplT &impl() { return static_cast<TableManagerImplT &>(*this); }
DenseMap<StringRef, Symbol *> Entries;
Expand Down
Loading

0 comments on commit 2706217

Please sign in to comment.