Skip to content

Commit 7d3dfc8

Browse files
authored
[JITLink][XCOFF] Setup initial build support for XCOFF (llvm#127266)
This patch starts the initial implementation of JITLink for XCOFF (Object format for AIX).
1 parent 5f99e0d commit 7d3dfc8

File tree

12 files changed

+823
-3
lines changed

12 files changed

+823
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===------- XCOFF.h - Generic JIT link function for XCOFF ------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// jit-link functions for XCOFF.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_EXECUTIONENGINE_JITLINK_XCOFF_H
14+
#define LLVM_EXECUTIONENGINE_JITLINK_XCOFF_H
15+
16+
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
17+
18+
namespace llvm {
19+
namespace jitlink {
20+
21+
/// Create a LinkGraph from an XCOFF relocatable object.
22+
///
23+
/// Note: The graph does not take ownership of the underlying buffer, nor copy
24+
/// its contents. The caller is responsible for ensuring that the object buffer
25+
/// outlives the graph.
26+
Expected<std::unique_ptr<LinkGraph>>
27+
createLinkGraphFromXCOFFObject(MemoryBufferRef ObjectBuffer,
28+
std::shared_ptr<orc::SymbolStringPool> SSP);
29+
30+
/// Link the given graph.
31+
void link_XCOFF(std::unique_ptr<LinkGraph> G,
32+
std::unique_ptr<JITLinkContext> Ctx);
33+
34+
} // namespace jitlink
35+
} // namespace llvm
36+
37+
#endif // LLVM_EXECUTIONENGINE_JITLINK_XCOFF_H
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===------ XCOFF_ppc64.h - JIT link functions for XCOFF/ppc64 ------*- C++
2+
//-*-===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// jit-link functions for XCOFF/ppc64.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_EXECUTIONENGINE_JITLINK_XCOFF_PPC64_H
15+
#define LLVM_EXECUTIONENGINE_JITLINK_XCOFF_PPC64_H
16+
17+
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
18+
19+
namespace llvm::jitlink {
20+
21+
/// Create a LinkGraph from an XCOFF/ppc64 relocatable object.
22+
///
23+
/// Note: The graph does not take ownership of the underlying buffer, nor copy
24+
/// its contents. The caller is responsible for ensuring that the object buffer
25+
/// outlives the graph.
26+
///
27+
Expected<std::unique_ptr<LinkGraph>> createLinkGraphFromXCOFFObject_ppc64(
28+
MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP);
29+
30+
/// jit-link the given object buffer, which must be a XCOFF ppc64 object file.
31+
///
32+
void link_XCOFF_ppc64(std::unique_ptr<LinkGraph> G,
33+
std::unique_ptr<JITLinkContext> Ctx);
34+
35+
} // end namespace llvm::jitlink
36+
37+
#endif // LLVM_EXECUTIONENGINE_JITLINK_XCOFF_PPC64_H

llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ add_llvm_component_library(LLVMJITLink
3535
COFFLinkGraphBuilder.cpp
3636
COFF_x86_64.cpp
3737

38+
# XCOFF
39+
XCOFF.cpp
40+
XCOFF_ppc64.cpp
41+
XCOFFLinkGraphBuilder.cpp
42+
3843
# Architectures:
3944
aarch32.cpp
4045
aarch64.cpp

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ExecutionEngine/JITLink/COFF.h"
1414
#include "llvm/ExecutionEngine/JITLink/ELF.h"
1515
#include "llvm/ExecutionEngine/JITLink/MachO.h"
16+
#include "llvm/ExecutionEngine/JITLink/XCOFF.h"
1617
#include "llvm/ExecutionEngine/JITLink/aarch64.h"
1718
#include "llvm/ExecutionEngine/JITLink/i386.h"
1819
#include "llvm/ExecutionEngine/JITLink/loongarch.h"
@@ -501,6 +502,8 @@ createLinkGraphFromObject(MemoryBufferRef ObjectBuffer,
501502
return createLinkGraphFromELFObject(ObjectBuffer, std::move(SSP));
502503
case file_magic::coff_object:
503504
return createLinkGraphFromCOFFObject(ObjectBuffer, std::move(SSP));
505+
case file_magic::xcoff_object_64:
506+
return createLinkGraphFromXCOFFObject(ObjectBuffer, std::move(SSP));
504507
default:
505508
return make_error<JITLinkError>("Unsupported file format");
506509
};
@@ -532,6 +535,8 @@ void link(std::unique_ptr<LinkGraph> G, std::unique_ptr<JITLinkContext> Ctx) {
532535
return link_ELF(std::move(G), std::move(Ctx));
533536
case Triple::COFF:
534537
return link_COFF(std::move(G), std::move(Ctx));
538+
case Triple::XCOFF:
539+
return link_XCOFF(std::move(G), std::move(Ctx));
535540
default:
536541
Ctx->notifyFailed(make_error<JITLinkError>("Unsupported object format"));
537542
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-------------- XCOFF.cpp - JIT linker function for XCOFF -------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// XCOFF jit-link function.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "llvm/ExecutionEngine/JITLink/XCOFF.h"
14+
#include "llvm/ExecutionEngine/JITLink/XCOFF_ppc64.h"
15+
#include "llvm/Object/XCOFFObjectFile.h"
16+
17+
using namespace llvm;
18+
19+
#define DEBUG_TYPE "jitlink"
20+
21+
namespace llvm {
22+
namespace jitlink {
23+
24+
Expected<std::unique_ptr<LinkGraph>>
25+
createLinkGraphFromXCOFFObject(MemoryBufferRef ObjectBuffer,
26+
std::shared_ptr<orc::SymbolStringPool> SSP) {
27+
// Check magic
28+
file_magic Magic = identify_magic(ObjectBuffer.getBuffer());
29+
if (Magic != file_magic::xcoff_object_64)
30+
return make_error<JITLinkError>("Invalid XCOFF 64 Header");
31+
32+
// TODO: See if we need to add more checks
33+
//
34+
return createLinkGraphFromXCOFFObject_ppc64(ObjectBuffer, std::move(SSP));
35+
}
36+
37+
void link_XCOFF(std::unique_ptr<LinkGraph> G,
38+
std::unique_ptr<JITLinkContext> Ctx) {
39+
link_XCOFF_ppc64(std::move(G), std::move(Ctx));
40+
}
41+
42+
} // namespace jitlink
43+
} // namespace llvm

0 commit comments

Comments
 (0)