Skip to content

[JITLink][XCOFF] Setup initial build support for XCOFF #127266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions llvm/include/llvm/ExecutionEngine/JITLink/XCOFF.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===------- XCOFF.h - Generic JIT link function for XCOFF ------*- 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 XCOFF.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_EXECUTIONENGINE_JITLINK_XCOFF_H
#define LLVM_EXECUTIONENGINE_JITLINK_XCOFF_H

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

namespace llvm {
namespace jitlink {

/// Create a LinkGraph from an XCOFF 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>>
createLinkGraphFromXCOFFObject(MemoryBufferRef ObjectBuffer,
std::shared_ptr<orc::SymbolStringPool> SSP);

/// Link the given graph.
void link_XCOFF(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx);

} // namespace jitlink
} // namespace llvm

#endif // LLVM_EXECUTIONENGINE_JITLINK_XCOFF_H
37 changes: 37 additions & 0 deletions llvm/include/llvm/ExecutionEngine/JITLink/XCOFF_ppc64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===------ XCOFF_ppc64.h - JIT link functions for XCOFF/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 XCOFF/ppc64.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_EXECUTIONENGINE_JITLINK_XCOFF_PPC64_H
#define LLVM_EXECUTIONENGINE_JITLINK_XCOFF_PPC64_H

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

namespace llvm::jitlink {

/// Create a LinkGraph from an XCOFF/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.
///
Expected<std::unique_ptr<LinkGraph>> createLinkGraphFromXCOFFObject_ppc64(
MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP);

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

} // end namespace llvm::jitlink

#endif // LLVM_EXECUTIONENGINE_JITLINK_XCOFF_PPC64_H
5 changes: 5 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ add_llvm_component_library(LLVMJITLink
COFFLinkGraphBuilder.cpp
COFF_x86_64.cpp

# XCOFF
XCOFF.cpp
XCOFF_ppc64.cpp
XCOFFLinkGraphBuilder.cpp

# Architectures:
aarch32.cpp
aarch64.cpp
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "llvm/ExecutionEngine/JITLink/COFF.h"
#include "llvm/ExecutionEngine/JITLink/ELF.h"
#include "llvm/ExecutionEngine/JITLink/MachO.h"
#include "llvm/ExecutionEngine/JITLink/XCOFF.h"
#include "llvm/ExecutionEngine/JITLink/aarch64.h"
#include "llvm/ExecutionEngine/JITLink/i386.h"
#include "llvm/ExecutionEngine/JITLink/loongarch.h"
Expand Down Expand Up @@ -501,6 +502,8 @@ createLinkGraphFromObject(MemoryBufferRef ObjectBuffer,
return createLinkGraphFromELFObject(ObjectBuffer, std::move(SSP));
case file_magic::coff_object:
return createLinkGraphFromCOFFObject(ObjectBuffer, std::move(SSP));
case file_magic::xcoff_object_64:
return createLinkGraphFromXCOFFObject(ObjectBuffer, std::move(SSP));
default:
return make_error<JITLinkError>("Unsupported file format");
};
Expand Down Expand Up @@ -532,6 +535,8 @@ void link(std::unique_ptr<LinkGraph> G, std::unique_ptr<JITLinkContext> Ctx) {
return link_ELF(std::move(G), std::move(Ctx));
case Triple::COFF:
return link_COFF(std::move(G), std::move(Ctx));
case Triple::XCOFF:
return link_XCOFF(std::move(G), std::move(Ctx));
default:
Ctx->notifyFailed(make_error<JITLinkError>("Unsupported object format"));
};
Expand Down
43 changes: 43 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/XCOFF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===-------------- XCOFF.cpp - JIT linker function for XCOFF -------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// XCOFF jit-link function.
//
//===----------------------------------------------------------------------===//

#include "llvm/ExecutionEngine/JITLink/XCOFF.h"
#include "llvm/ExecutionEngine/JITLink/XCOFF_ppc64.h"
#include "llvm/Object/XCOFFObjectFile.h"

using namespace llvm;

#define DEBUG_TYPE "jitlink"

namespace llvm {
namespace jitlink {

Expected<std::unique_ptr<LinkGraph>>
createLinkGraphFromXCOFFObject(MemoryBufferRef ObjectBuffer,
std::shared_ptr<orc::SymbolStringPool> SSP) {
// Check magic
file_magic Magic = identify_magic(ObjectBuffer.getBuffer());
if (Magic != file_magic::xcoff_object_64)
return make_error<JITLinkError>("Invalid XCOFF 64 Header");

// TODO: See if we need to add more checks
//
return createLinkGraphFromXCOFFObject_ppc64(ObjectBuffer, std::move(SSP));
}

void link_XCOFF(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx) {
link_XCOFF_ppc64(std::move(G), std::move(Ctx));
}

} // namespace jitlink
} // namespace llvm
Loading