LLVM 22.0.0git
XCOFF_ppc64.cpp
Go to the documentation of this file.
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
15#include "JITLinkGeneric.h"
17#include "llvm/ADT/bit.h"
22#include "llvm/Support/Error.h"
24#include <system_error>
25
26using namespace llvm;
27
28#define DEBUG_TYPE "jitlink"
29
30namespace llvm {
31namespace jitlink {
32
34 MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
36 dbgs() << "Building jitlink graph for new input "
37 << ObjectBuffer.getBufferIdentifier() << "...\n";
38 });
39
40 auto Obj = object::ObjectFile::createObjectFile(ObjectBuffer);
41 if (!Obj)
42 return Obj.takeError();
43 assert((**Obj).isXCOFF() && "Expects and XCOFF Object");
44
45 auto Features = (*Obj)->getFeatures();
46 if (!Features)
47 return Features.takeError();
49 dbgs() << " Features: ";
50 (*Features).print(dbgs());
51 });
52
53 return XCOFFLinkGraphBuilder(cast<object::XCOFFObjectFile>(**Obj),
54 std::move(SSP), Triple("powerpc64-ibm-aix"),
55 std::move(*Features), ppc64::getEdgeKindName)
56 .buildGraph();
57}
58
59class XCOFFJITLinker_ppc64 : public JITLinker<XCOFFJITLinker_ppc64> {
61 friend JITLinkerBase;
62
63public:
64 XCOFFJITLinker_ppc64(std::unique_ptr<JITLinkContext> Ctx,
65 std::unique_ptr<LinkGraph> G,
66 PassConfiguration PassConfig)
67 : JITLinkerBase(std::move(Ctx), std::move(G), std::move(PassConfig)) {
68 // FIXME: Post allocation pass define TOC base, this is temporary to support
69 // building until we can build the required toc entries
70 defineTOCSymbol(getGraph());
71 }
72
73 Error applyFixup(LinkGraph &G, Block &B, const Edge &E) const {
74 LLVM_DEBUG(dbgs() << " Applying fixup for " << G.getName()
75 << ", address = " << B.getAddress()
76 << ", target = " << E.getTarget().getName() << ", kind = "
77 << ppc64::getEdgeKindName(E.getKind()) << "\n");
78 switch (E.getKind()) {
80 if (auto Err = ppc64::applyFixup<endianness::big>(G, B, E, TOCSymbol))
81 return Err;
82 break;
83 default:
84 return make_error<StringError>("Unsupported relocation type",
85 std::error_code());
86 }
87 return Error::success();
88 }
89
90private:
91 void defineTOCSymbol(LinkGraph &G) {
92 for (Symbol *S : G.defined_symbols()) {
93 if (S->hasName() && *S->getName() == StringRef("TOC")) {
94 TOCSymbol = S;
95 return;
96 }
97 }
98 llvm_unreachable("LinkGraph does not contan an TOC Symbol");
99 }
100
101private:
102 Symbol *TOCSymbol = nullptr;
103};
104
105void link_XCOFF_ppc64(std::unique_ptr<LinkGraph> G,
106 std::unique_ptr<JITLinkContext> Ctx) {
107 // Ctx->notifyFailed(make_error<StringError>(
108 // "link_XCOFF_ppc64 is not implemented", std::error_code()));
109
111
112 // Pass insertions
113
114 if (auto Err = Ctx->modifyPassConfig(*G, Config))
115 return Ctx->notifyFailed(std::move(Err));
116
117 XCOFFJITLinker_ppc64::link(std::move(Ctx), std::move(G), std::move(Config));
118}
119
120} // namespace jitlink
121} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
RelaxConfig Config
Definition: ELF_riscv.cpp:506
#define G(x, y, z)
Definition: MD5.cpp:56
#define LLVM_DEBUG(...)
Definition: Debug.h:119
This file implements the C++20 <bit> header.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
StringRef getBufferIdentifier() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Definition: ObjectFile.cpp:211
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856