LLVM: lib/ExecutionEngine/JITLink/MachO.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
14
19
20using namespace llvm;
21
22#define DEBUG_TYPE "jitlink"
23
24namespace llvm {
26
29 std::shared_ptrorc::SymbolStringPool SSP) {
31 if (Data.size() < 4)
34
36 memcpy(&Magic, Data.data(), sizeof(uint32_t));
38 dbgs() << "jitLink_MachO: magic = " << format("0x%08" PRIx32, Magic)
40 << "\"\n";
41 });
42
46
50 "\"");
51
52
54 memcpy(&CPUType, Data.data() + 4, sizeof(uint32_t));
57
59 dbgs() << "jitLink_MachO: cputype = " << format("0x%08" PRIx32, CPUType)
60 << "\n";
61 });
62
63 switch (CPUType) {
68 std::move(SSP));
69 }
71 } else
73}
74
76 std::unique_ptr Ctx) {
77
78 switch (G->getTargetTriple().getArch()) {
83 default:
85 return;
86 }
87}
88
89template
91 auto &B = G.createMutableContentBlock(Sec, sizeof(MachOHeaderType),
93 MachOHeaderType Hdr;
96 Hdr.cputype = *CPUType;
97 else
98 return CPUType.takeError();
100 Hdr.cpusubtype = *CPUSubType;
101 else
102 return CPUSubType.takeError();
104
107
108 memcpy(B.getAlreadyMutableContent().data(), &Hdr, sizeof(Hdr));
109
110 return B;
111}
112
114 StringRef LocalHeaderSectionName("__TEXT,__lcl_macho_hdr");
115 Section *Sec = G.findSectionByName(LocalHeaderSectionName);
116 if (Sec) {
117 assert(Sec->blocks_size() == 1 && "Unexpected number of blocks");
120 assert(Sym.getOffset() == 0 && "Symbol not at start of header block");
121 return Sym;
122 }
123
124
125
126 for (auto &Sec : G.sections())
128
130
132
134 switch (G.getTargetTriple().getArch()) {
138 B = &*BOrErr;
139 else
140 return BOrErr.takeError();
141 break;
142 default:
144 G.getName() + ": unsupported triple " +
145 G.getTargetTriple().str());
146 }
147
148 return G.addAnonymousSymbol(*B, 0, B->getSize(), false, false);
149}
150
151}
152}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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.
Represents an address in the executor process.
LLVM_ABI Expected< uint32_t > getCPUSubType(const Triple &T)
void swapStruct(fat_header &mh)
LLVM_ABI Expected< uint32_t > getCPUType(const Triple &T)
static Expected< Block & > createLocalHeaderBlock(LinkGraph &G, Section &Sec)
Definition MachO.cpp:90
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI Expected< Symbol & > getOrCreateLocalMachOHeader(LinkGraph &G)
Gets or creates a MachO header for the current LinkGraph.
Definition MachO.cpp:113
LLVM_ABI Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from a MachO relocatable object.
Definition MachO.cpp:28
LLVM_ABI void link_MachO_x86_64(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given LinkGraph.
LLVM_ABI Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromMachOObject_arm64(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from a MachO/arm64 relocatable object.
LLVM_ABI 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.
Definition MachO.cpp:75
This is an optimization pass for GlobalISel generic memory operations.
constexpr T byteswap(T V) noexcept
Reverses the bytes in the given integer value V.
LLVM_ABI 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.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data