22#define DEBUG_TYPE "jitlink"
29 std::shared_ptr<orc::SymbolStringPool> SSP) {
32 return make_error<JITLinkError>(
"Truncated MachO buffer \"" +
38 dbgs() <<
"jitLink_MachO: magic = " <<
format(
"0x%08" PRIx32, Magic)
44 return make_error<JITLinkError>(
"MachO 32-bit platforms not supported");
48 return make_error<JITLinkError>(
"Truncated MachO buffer \"" +
56 CPUType = llvm::byteswap<uint32_t>(CPUType);
59 dbgs() <<
"jitLink_MachO: cputype = " <<
format(
"0x%08" PRIx32, CPUType)
70 return make_error<JITLinkError>(
"MachO-64 CPU type not valid");
72 return make_error<JITLinkError>(
"Unrecognized MachO magic value");
76 std::unique_ptr<JITLinkContext> Ctx) {
78 switch (
G->getTargetTriple().getArch()) {
84 Ctx->notifyFailed(make_error<JITLinkError>(
"MachO-64 CPU type not valid"));
89template <
typename MachOHeaderType>
91 auto &
B =
G.createMutableContentBlock(Sec,
sizeof(MachOHeaderType),
96 Hdr.cputype = *CPUType;
98 return CPUType.takeError();
100 Hdr.cpusubtype = *CPUSubType;
102 return CPUSubType.takeError();
108 memcpy(
B.getAlreadyMutableContent().data(), &Hdr,
sizeof(Hdr));
114 StringRef LocalHeaderSectionName(
"__TEXT,__lcl_macho_hdr");
115 Section *Sec =
G.findSectionByName(LocalHeaderSectionName);
126 for (
auto &Sec :
G.sections())
134 switch (
G.getTargetTriple().getArch()) {
137 if (
auto BOrErr = createLocalHeaderBlock<MachO::mach_header_64>(
G, *Sec))
140 return BOrErr.takeError();
143 return make_error<JITLinkError>(
"Cannot create local Mach-O header for " +
144 G.getName() +
": unsupported triple " +
145 G.getTargetTriple().str());
148 return G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
false);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Tagged union holding either a T or a Error.
StringRef getBufferIdentifier() const
StringRef getBuffer() const
StringRef - Represent a constant reference to a string, i.e.
An Addressable with content and edges.
Represents an object file section.
iterator_range< symbol_iterator > symbols()
Returns an iterator over the symbols defined in this section.
SectionOrdinal getOrdinal() const
Returns the ordinal for this section.
SymbolSet::size_type symbols_size() const
Return the number of symbols in this section.
BlockSet::size_type blocks_size() const
Returns the number of blocks in this section.
void setOrdinal(SectionOrdinal SecOrdinal)
Set the ordinal for this section.
orc::ExecutorAddrDiff getOffset() const
Returns the offset for this symbol within the underlying addressable.
Represents an address in the executor process.
Expected< uint32_t > getCPUSubType(const Triple &T)
void swapStruct(fat_header &mh)
Expected< uint32_t > getCPUType(const Triple &T)
static Expected< Block & > createLocalHeaderBlock(LinkGraph &G, Section &Sec)
void link_MachO_arm64(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a MachO arm64 object file.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromMachOObject_x86_64(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from a MachO/x86-64 relocatable object.
Expected< Symbol & > getOrCreateLocalMachOHeader(LinkGraph &G)
Gets or creates a MachO header for the current LinkGraph.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from a MachO relocatable object.
void link_MachO_x86_64(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given LinkGraph.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromMachOObject_arm64(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from a MachO/arm64 relocatable object.
void link_MachO(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given ObjBuffer, which must be a MachO object file.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.