Skip to content

Commit f798345

Browse files
committed
Setup build support for XCOFF
1 parent 0f6c18e commit f798345

File tree

7 files changed

+193
-0
lines changed

7 files changed

+193
-0
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ add_llvm_component_library(LLVMJITLink
3535
COFFLinkGraphBuilder.cpp
3636
COFF_x86_64.cpp
3737

38+
# XCOFF
39+
XCOFF.cpp
40+
XCOFF_ppc64.cpp
41+
3842
# Architectures:
3943
aarch32.cpp
4044
aarch64.cpp

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 3 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
};
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+
llvm_unreachable("Not implmeneted for XCOFF yet");
40+
}
41+
42+
} // namespace jitlink
43+
} // namespace llvm
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//===------- XCOFF_ppc64.cpp -JIT linker implementation for XCOFF/ppc64
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+
// XCOFF/ppc64 jit-link implementation.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "llvm/ExecutionEngine/JITLink/XCOFF_ppc64.h"
15+
#include "llvm/Object/ObjectFile.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>> createLinkGraphFromXCOFFObject_ppc64(
25+
MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
26+
LLVM_DEBUG({
27+
dbgs() << "Building jitlink graph for new input "
28+
<< ObjectBuffer.getBufferIdentifier() << "...\n";
29+
});
30+
31+
auto Obj = object::ObjectFile::createObjectFile(ObjectBuffer);
32+
if (!Obj)
33+
return Obj.takeError();
34+
assert((**Obj).isXCOFF() && "Expects and XCOFF Object");
35+
36+
auto Features = (*Obj)->getFeatures();
37+
if (!Features)
38+
return Features.takeError();
39+
LLVM_DEBUG({
40+
dbgs() << " Features: ";
41+
(*Features).print(dbgs());
42+
});
43+
44+
llvm_unreachable("Graph builder not implemented for XCOFF yet");
45+
}
46+
47+
void link_XCOFF_ppc64(std::unique_ptr<LinkGraph> G,
48+
std::unique_ptr<JITLinkContext> Ctx) {
49+
llvm_unreachable("Link implemented for XCOFF yet");
50+
}
51+
52+
} // namespace jitlink
53+
} // namespace llvm

llvm/lib/ExecutionEngine/Orc/LoadLinkableFile.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ checkCOFFRelocatableObject(std::unique_ptr<MemoryBuffer> Obj,
2525
return std::move(Obj);
2626
}
2727

28+
static Expected<std::unique_ptr<MemoryBuffer>>
29+
checkXCOFFRelocatableObject(std::unique_ptr<MemoryBuffer> Obj,
30+
const Triple &TT) {
31+
// TODO: Actually check the architecture of the file.
32+
return std::move(Obj);
33+
}
34+
2835
static Expected<std::unique_ptr<MemoryBuffer>>
2936
checkELFRelocatableObject(std::unique_ptr<MemoryBuffer> Obj, const Triple &TT) {
3037
// TODO: Actually check the architecture of the file.
@@ -105,6 +112,15 @@ loadLinkableFile(StringRef Path, const Triple &TT, LoadArchives LA,
105112
return loadLinkableSliceFromMachOUniversalBinary(
106113
FD, std::move(*Buf), TT, LA, Path, *IdentifierOverride);
107114
break;
115+
case file_magic::xcoff_object_64:
116+
if (!RequireFormat || *RequireFormat == Triple::XCOFF) {
117+
auto CheckedBuf = checkXCOFFRelocatableObject(std::move(*Buf), TT);
118+
if (!CheckedBuf)
119+
return CheckedBuf.takeError();
120+
return std::make_pair(std::move(*CheckedBuf),
121+
LinkableFileKind::RelocatableObject);
122+
}
123+
break;
108124
default:
109125
break;
110126
}

0 commit comments

Comments
 (0)