LLVM 22.0.0git
MachOBuilder.h
Go to the documentation of this file.
1//===------------ MachOBuilder.h -- Build MachO Objects ---------*- 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// Build MachO object files for interaction with the ObjC runtime and debugger.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_MACHOBUILDER_H
14#define LLVM_EXECUTIONENGINE_ORC_MACHOBUILDER_H
15
17#include "llvm/Support/Endian.h"
19
20#include <list>
21#include <map>
22#include <vector>
23
24namespace llvm {
25namespace orc {
26
27template <typename MachOStruct>
28size_t writeMachOStruct(MutableArrayRef<char> Buf, size_t Offset, MachOStruct S,
29 bool SwapStruct) {
30 if (SwapStruct)
32 assert(Offset + sizeof(MachOStruct) <= Buf.size() && "Buffer overflow");
33 memcpy(&Buf[Offset], reinterpret_cast<const char *>(&S), sizeof(MachOStruct));
34 return Offset + sizeof(MachOStruct);
35}
36
37/// Base type for MachOBuilder load command wrappers.
40 virtual size_t size() const = 0;
41 virtual size_t write(MutableArrayRef<char> Buf, size_t Offset,
42 bool SwapStruct) = 0;
43};
44
45/// MachOBuilder load command wrapper type.
46template <MachO::LoadCommandType LCType> struct MachOBuilderLoadCommandImplBase;
47
48#define HANDLE_LOAD_COMMAND(Name, Value, LCStruct) \
49 template <> \
50 struct MachOBuilderLoadCommandImplBase<MachO::Name> \
51 : public MachO::LCStruct, public MachOBuilderLoadCommandBase { \
52 using CmdStruct = LCStruct; \
53 MachOBuilderLoadCommandImplBase() { \
54 memset(&rawStruct(), 0, sizeof(CmdStruct)); \
55 cmd = Value; \
56 cmdsize = sizeof(CmdStruct); \
57 } \
58 template <typename... ArgTs> \
59 MachOBuilderLoadCommandImplBase(ArgTs &&...Args) \
60 : CmdStruct{Value, sizeof(CmdStruct), std::forward<ArgTs>(Args)...} {} \
61 CmdStruct &rawStruct() { return static_cast<CmdStruct &>(*this); } \
62 size_t size() const override { return cmdsize; } \
63 size_t write(MutableArrayRef<char> Buf, size_t Offset, \
64 bool SwapStruct) override { \
65 return writeMachOStruct(Buf, Offset, rawStruct(), SwapStruct); \
66 } \
67 };
68
69#include "llvm/BinaryFormat/MachO.def"
70
71#undef HANDLE_LOAD_COMMAND
72
73template <MachO::LoadCommandType LCType>
75 : public MachOBuilderLoadCommandImplBase<LCType> {
76public:
78
79 template <typename... ArgTs>
80 MachOBuilderLoadCommand(ArgTs &&...Args)
81 : MachOBuilderLoadCommandImplBase<LCType>(std::forward<ArgTs>(Args)...) {}
82};
83
84template <MachO::LoadCommandType LCType>
86 : public MachOBuilderLoadCommandImplBase<LCType> {
87
89 uint32_t CurrentVersion,
90 uint32_t CompatibilityVersion)
92 MachO::dylib{24, Timestamp, CurrentVersion, CompatibilityVersion}),
93 Name(std::move(Name)) {
94 this->cmdsize += (this->Name.size() + 1 + 3) & ~0x3;
95 }
96
98 bool SwapStruct) override {
99 Offset = writeMachOStruct(Buf, Offset, this->rawStruct(), SwapStruct);
100 strcpy(Buf.data() + Offset, Name.data());
101 return Offset + ((Name.size() + 1 + 3) & ~0x3);
102 }
103
104 std::string Name;
105};
106
107template <>
108struct MachOBuilderLoadCommand<MachO::LC_ID_DYLIB>
109 : public MachOBuilderDylibLoadCommand<MachO::LC_ID_DYLIB> {
111};
112
113template <>
114struct MachOBuilderLoadCommand<MachO::LC_LOAD_DYLIB>
115 : public MachOBuilderDylibLoadCommand<MachO::LC_LOAD_DYLIB> {
117};
118
119template <>
120struct MachOBuilderLoadCommand<MachO::LC_LOAD_WEAK_DYLIB>
121 : public MachOBuilderDylibLoadCommand<MachO::LC_LOAD_WEAK_DYLIB> {
123};
124
125template <>
126struct MachOBuilderLoadCommand<MachO::LC_RPATH>
127 : public MachOBuilderLoadCommandImplBase<MachO::LC_RPATH> {
128 MachOBuilderLoadCommand(std::string Path)
129 : MachOBuilderLoadCommandImplBase(12u), Path(std::move(Path)) {
130 cmdsize += (this->Path.size() + 1 + 3) & ~0x3;
131 }
132
134 bool SwapStruct) override {
135 Offset = writeMachOStruct(Buf, Offset, rawStruct(), SwapStruct);
136 strcpy(Buf.data() + Offset, Path.data());
137 return Offset + ((Path.size() + 1 + 3) & ~0x3);
138 }
139
140 std::string Path;
141};
142
143// Builds MachO objects.
144template <typename MachOTraits> class MachOBuilder {
145private:
146 struct SymbolContainer {
147 size_t SymbolIndexBase = 0;
148 std::vector<typename MachOTraits::NList> Symbols;
149 };
150
151 struct StringTableEntry {
152 StringRef S;
153 size_t Offset;
154 };
155
156 using StringTable = std::vector<StringTableEntry>;
157
158 static bool swapStruct() {
159 return MachOTraits::Endianness != llvm::endianness::native;
160 }
161
162public:
163 using StringId = size_t;
164
165 struct Section;
166
167 // Points to either an nlist entry (as a (symbol-container, index) pair), or
168 // a section.
170 public:
171 RelocTarget(const Section &S) : S(&S), Idx(~0U) {}
172 RelocTarget(SymbolContainer &SC, size_t Idx) : SC(&SC), Idx(Idx) {}
173
174 bool isSymbol() { return Idx != ~0U; }
175
177 assert(isSymbol() && "Target is not a symbol");
178 return SC->SymbolIndexBase + Idx;
179 }
180
182 assert(!isSymbol() && "Target is not a section");
183 return S->SectionNumber;
184 }
185
186 typename MachOTraits::NList &nlist() {
187 assert(isSymbol() && "Target is not a symbol");
188 return SC->Symbols[Idx];
189 }
190
191 private:
192 union {
193 const Section *S;
194 SymbolContainer *SC;
195 };
196 size_t Idx;
197 };
198
201
202 Reloc(int32_t Offset, RelocTarget Target, bool PCRel, unsigned Length,
203 unsigned Type)
204 : Target(Target) {
205 assert(Type < 16 && "Relocation type out of range");
206 r_address = Offset; // Will slide to account for sec addr during layout
207 r_symbolnum = 0;
208 r_pcrel = PCRel;
210 r_extern = Target.isSymbol();
211 r_type = Type;
212 }
213
215 return static_cast<MachO::relocation_info &>(*this);
216 }
217 };
218
220 const char *Data = nullptr;
221 size_t Size = 0;
222 };
223
224 struct Section : public MachOTraits::Section, public RelocTarget {
227 size_t SectionNumber = 0;
228 SymbolContainer SC;
229 std::vector<Reloc> Relocs;
230
232 : RelocTarget(*this), Builder(Builder) {
233 memset(&rawStruct(), 0, sizeof(typename MachOTraits::Section));
234 assert(SecName.size() <= 16 && "SecName too long");
235 assert(SegName.size() <= 16 && "SegName too long");
236 memcpy(this->sectname, SecName.data(), SecName.size());
237 memcpy(this->segname, SegName.data(), SegName.size());
238 }
239
241 uint16_t Desc) {
243 typename MachOTraits::NList Sym;
244 Sym.n_strx = SI;
245 Sym.n_type = Type | MachO::N_SECT;
246 Sym.n_sect = MachO::NO_SECT; // Will be filled in later.
247 Sym.n_desc = Desc;
248 Sym.n_value = Offset;
249 SC.Symbols.push_back(Sym);
250 return {SC, SC.Symbols.size() - 1};
251 }
252
253 void addReloc(int32_t Offset, RelocTarget Target, bool PCRel,
254 unsigned Length, unsigned Type) {
255 Relocs.push_back({Offset, Target, PCRel, Length, Type});
256 }
257
258 auto &rawStruct() {
259 return static_cast<typename MachOTraits::Section &>(*this);
260 }
261 };
262
263 struct Segment : public MachOBuilderLoadCommand<MachOTraits::SegmentCmd> {
265 std::vector<std::unique_ptr<Section>> Sections;
266
268 : MachOBuilderLoadCommand<MachOTraits::SegmentCmd>(), Builder(Builder) {
269 assert(SegName.size() <= 16 && "SegName too long");
270 memcpy(this->segname, SegName.data(), SegName.size());
271 this->maxprot =
273 this->initprot = this->maxprot;
274 }
275
277 Sections.push_back(std::make_unique<Section>(Builder, SecName, SegName));
278 return *Sections.back();
279 }
280
282 bool SwapStruct) override {
284 Buf, Offset, SwapStruct);
285 for (auto &Sec : Sections)
286 Offset = writeMachOStruct(Buf, Offset, Sec->rawStruct(), SwapStruct);
287 return Offset;
288 }
289 };
290
291 MachOBuilder(size_t PageSize) : PageSize(PageSize) {
292 memset((char *)&Header, 0, sizeof(Header));
293 Header.magic = MachOTraits::Magic;
294 }
295
296 template <MachO::LoadCommandType LCType, typename... ArgTs>
298 static_assert(LCType != MachOTraits::SegmentCmd,
299 "Use addSegment to add segment load command");
300 auto LC = std::make_unique<MachOBuilderLoadCommand<LCType>>(
301 std::forward<ArgTs>(Args)...);
302 auto &Tmp = *LC;
303 LoadCommands.push_back(std::move(LC));
304 return Tmp;
305 }
306
308 if (Strings.empty() && !Str.empty())
309 addString("");
310 return Strings.insert(std::make_pair(Str, Strings.size())).first->second;
311 }
312
314 Segments.push_back(Segment(*this, SegName));
315 return Segments.back();
316 }
317
319 uint16_t Desc, typename MachOTraits::UIntPtr Value) {
320 StringId SI = addString(Name);
321 typename MachOTraits::NList Sym;
322 Sym.n_strx = SI;
323 Sym.n_type = Type;
324 Sym.n_sect = Sect;
325 Sym.n_desc = Desc;
326 Sym.n_value = Value;
327 SC.Symbols.push_back(Sym);
328 return {SC, SC.Symbols.size() - 1};
329 }
330
331 // Call to perform layout on the MachO. Returns the total size of the
332 // resulting file.
333 // This method will automatically insert some load commands (e.g.
334 // LC_SYMTAB) and fill in load command fields.
335 size_t layout() {
336
337 // Build symbol table and add LC_SYMTAB command.
338 makeStringTable();
340 if (!StrTab.empty())
341 SymTabLC = &addLoadCommand<MachOTraits::SymTabCmd>();
342
343 // Lay out header, segment load command, and other load commands.
344 size_t Offset = sizeof(Header);
345 for (auto &Seg : Segments) {
346 Seg.cmdsize +=
347 Seg.Sections.size() * sizeof(typename MachOTraits::Section);
348 Seg.nsects = Seg.Sections.size();
349 Offset += Seg.cmdsize;
350 }
351 for (auto &LC : LoadCommands)
352 Offset += LC->size();
353
354 Header.sizeofcmds = Offset - sizeof(Header);
355
356 // Lay out content, set segment / section addrs and offsets.
357 size_t SegVMAddr = 0;
358 for (auto &Seg : Segments) {
359 Seg.vmaddr = SegVMAddr;
360 Seg.fileoff = Offset;
361 for (auto &Sec : Seg.Sections) {
362 Offset = alignTo(Offset, 1ULL << Sec->align);
363 if (Sec->Content.Size)
364 Sec->offset = Offset;
365 Sec->size = Sec->Content.Size;
366 Sec->addr = SegVMAddr + Sec->offset - Seg.fileoff;
367 Offset += Sec->Content.Size;
368 }
369 size_t SegContentSize = Offset - Seg.fileoff;
370 Seg.filesize = SegContentSize;
371 Seg.vmsize = Header.filetype == MachO::MH_OBJECT
372 ? SegContentSize
373 : alignTo(SegContentSize, PageSize);
374 SegVMAddr += Seg.vmsize;
375 }
376
377 // Set string table offsets for non-section symbols.
378 for (auto &Sym : SC.Symbols)
379 Sym.n_strx = StrTab[Sym.n_strx].Offset;
380
381 // Number sections, set symbol section numbers and string table offsets,
382 // count relocations.
383 size_t NumSymbols = SC.Symbols.size();
384 size_t SectionNumber = 0;
385 for (auto &Seg : Segments) {
386 for (auto &Sec : Seg.Sections) {
387 ++SectionNumber;
388 Sec->SectionNumber = SectionNumber;
389 Sec->SC.SymbolIndexBase = NumSymbols;
390 NumSymbols += Sec->SC.Symbols.size();
391 for (auto &Sym : Sec->SC.Symbols) {
392 Sym.n_sect = SectionNumber;
393 Sym.n_strx = StrTab[Sym.n_strx].Offset;
394 Sym.n_value += Sec->addr;
395 }
396 }
397 }
398
399 // Handle relocations
400 bool OffsetAlignedForRelocs = false;
401 for (auto &Seg : Segments) {
402 for (auto &Sec : Seg.Sections) {
403 if (!Sec->Relocs.empty()) {
404 if (!OffsetAlignedForRelocs) {
406 OffsetAlignedForRelocs = true;
407 }
408 Sec->reloff = Offset;
409 Sec->nreloc = Sec->Relocs.size();
410 Offset += Sec->Relocs.size() * sizeof(MachO::relocation_info);
411 for (auto &R : Sec->Relocs)
412 R.r_symbolnum = R.Target.isSymbol() ? R.Target.getSymbolNum()
413 : R.Target.getSectionId();
414 }
415 }
416 }
417
418 // Calculate offset to start of nlist and update symtab command.
419 if (NumSymbols > 0) {
420 Offset = alignTo(Offset, sizeof(typename MachOTraits::NList));
421 SymTabLC->symoff = Offset;
422 SymTabLC->nsyms = NumSymbols;
423
424 // Calculate string table bounds and update symtab command.
425 if (!StrTab.empty()) {
426 Offset += NumSymbols * sizeof(typename MachOTraits::NList);
427 size_t StringTableSize =
428 StrTab.back().Offset + StrTab.back().S.size() + 1;
429
430 SymTabLC->stroff = Offset;
431 SymTabLC->strsize = StringTableSize;
432 Offset += StringTableSize;
433 }
434 }
435
436 return Offset;
437 }
438
440 size_t Offset = 0;
441 Offset = writeHeader(Buffer, Offset);
442 Offset = writeSegments(Buffer, Offset);
443 Offset = writeLoadCommands(Buffer, Offset);
444 Offset = writeSectionContent(Buffer, Offset);
445 Offset = writeRelocations(Buffer, Offset);
446 Offset = writeSymbols(Buffer, Offset);
447 Offset = writeStrings(Buffer, Offset);
448 }
449
450 typename MachOTraits::Header Header;
451
452private:
453 void makeStringTable() {
454 if (Strings.empty())
455 return;
456
457 StrTab.resize(Strings.size());
458 for (auto &[Str, Idx] : Strings)
459 StrTab[Idx] = {Str, 0};
460 size_t Offset = 0;
461 for (auto &Elem : StrTab) {
462 Elem.Offset = Offset;
463 Offset += Elem.S.size() + 1;
464 }
465 }
466
467 size_t writeHeader(MutableArrayRef<char> Buf, size_t Offset) {
468 Header.ncmds = Segments.size() + LoadCommands.size();
469 return writeMachOStruct(Buf, Offset, Header, swapStruct());
470 }
471
472 size_t writeSegments(MutableArrayRef<char> Buf, size_t Offset) {
473 for (auto &Seg : Segments)
474 Offset = Seg.write(Buf, Offset, swapStruct());
475 return Offset;
476 }
477
478 size_t writeLoadCommands(MutableArrayRef<char> Buf, size_t Offset) {
479 for (auto &LC : LoadCommands)
480 Offset = LC->write(Buf, Offset, swapStruct());
481 return Offset;
482 }
483
484 size_t writeSectionContent(MutableArrayRef<char> Buf, size_t Offset) {
485 for (auto &Seg : Segments) {
486 for (auto &Sec : Seg.Sections) {
487 if (!Sec->Content.Data) {
488 assert(Sec->Relocs.empty() &&
489 "Cant' have relocs for zero-fill segment");
490 continue;
491 }
492 while (Offset != Sec->offset)
493 Buf[Offset++] = '\0';
494
495 assert(Offset + Sec->Content.Size <= Buf.size() && "Buffer overflow");
496 memcpy(&Buf[Offset], Sec->Content.Data, Sec->Content.Size);
497 Offset += Sec->Content.Size;
498 }
499 }
500 return Offset;
501 }
502
503 size_t writeRelocations(MutableArrayRef<char> Buf, size_t Offset) {
504 for (auto &Seg : Segments) {
505 for (auto &Sec : Seg.Sections) {
506 if (!Sec->Relocs.empty()) {
507 while (Offset % sizeof(MachO::relocation_info))
508 Buf[Offset++] = '\0';
509 }
510 for (auto &R : Sec->Relocs) {
511 assert(Offset + sizeof(MachO::relocation_info) <= Buf.size() &&
512 "Buffer overflow");
513 memcpy(&Buf[Offset], reinterpret_cast<const char *>(&R.rawStruct()),
514 sizeof(MachO::relocation_info));
515 Offset += sizeof(MachO::relocation_info);
516 }
517 }
518 }
519 return Offset;
520 }
521
522 size_t writeSymbols(MutableArrayRef<char> Buf, size_t Offset) {
523
524 // Count symbols.
525 size_t NumSymbols = SC.Symbols.size();
526 for (auto &Seg : Segments)
527 for (auto &Sec : Seg.Sections)
528 NumSymbols += Sec->SC.Symbols.size();
529
530 // If none then return.
531 if (NumSymbols == 0)
532 return Offset;
533
534 // Align to nlist entry size.
535 while (Offset % sizeof(typename MachOTraits::NList))
536 Buf[Offset++] = '\0';
537
538 // Write non-section symbols.
539 for (auto &Sym : SC.Symbols)
540 Offset = writeMachOStruct(Buf, Offset, Sym, swapStruct());
541
542 // Write section symbols.
543 for (auto &Seg : Segments) {
544 for (auto &Sec : Seg.Sections) {
545 for (auto &Sym : Sec->SC.Symbols) {
546 Offset = writeMachOStruct(Buf, Offset, Sym, swapStruct());
547 }
548 }
549 }
550 return Offset;
551 }
552
553 size_t writeStrings(MutableArrayRef<char> Buf, size_t Offset) {
554 for (auto &Elem : StrTab) {
555 assert(Offset + Elem.S.size() + 1 <= Buf.size() && "Buffer overflow");
556 memcpy(&Buf[Offset], Elem.S.data(), Elem.S.size());
557 Offset += Elem.S.size();
558 Buf[Offset++] = '\0';
559 }
560 return Offset;
561 }
562
563 size_t PageSize;
564 std::list<Segment> Segments;
565 std::vector<std::unique_ptr<MachOBuilderLoadCommandBase>> LoadCommands;
566 SymbolContainer SC;
567
568 // Maps strings to their "id" (addition order).
569 std::map<StringRef, size_t> Strings;
570 StringTable StrTab;
571};
572
573struct MachO64LE {
579
582 static constexpr MachO::LoadCommandType SegmentCmd = MachO::LC_SEGMENT_64;
583 static constexpr MachO::LoadCommandType SymTabCmd = MachO::LC_SYMTAB;
584};
585
586} // namespace orc
587} // namespace llvm
588
589#endif // LLVM_EXECUTIONENGINE_ORC_MACHOBUILDER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
uint64_t Timestamp
Definition: Profile.cpp:319
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:147
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
T * data() const
Definition: ArrayRef.h:345
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:154
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:148
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:75
RelocTarget(SymbolContainer &SC, size_t Idx)
Definition: MachOBuilder.h:172
MachOBuilderLoadCommand< LCType > & addLoadCommand(ArgTs &&...Args)
Definition: MachOBuilder.h:297
void write(MutableArrayRef< char > Buffer)
Definition: MachOBuilder.h:439
RelocTarget addSymbol(StringRef Name, uint8_t Type, uint8_t Sect, uint16_t Desc, typename MachOTraits::UIntPtr Value)
Definition: MachOBuilder.h:318
StringId addString(StringRef Str)
Definition: MachOBuilder.h:307
MachOBuilder(size_t PageSize)
Definition: MachOBuilder.h:291
Segment & addSegment(StringRef SegName)
Definition: MachOBuilder.h:313
MachOTraits::Header Header
Definition: MachOBuilder.h:450
@ NO_SECT
Definition: MachO.h:326
@ MH_OBJECT
Definition: MachO.h:43
@ MH_MAGIC_64
Definition: MachO.h:32
void swapStruct(fat_header &mh)
Definition: MachO.h:1140
@ VM_PROT_EXECUTE
Definition: MachO.h:497
@ VM_PROT_READ
Definition: MachO.h:497
@ VM_PROT_WRITE
Definition: MachO.h:497
@ N_SECT
Definition: MachO.h:318
LoadCommandType
Definition: MachO.h:98
size_t writeMachOStruct(MutableArrayRef< char > Buf, size_t Offset, MachOStruct S, bool SwapStruct)
Definition: MachOBuilder.h:28
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
@ Length
Definition: DWP.cpp:477
Op::Description Desc
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
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
endianness
Definition: bit.h:71
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Description of the encoding of one expression Op.
static constexpr uint32_t Magic
Definition: MachOBuilder.h:581
static constexpr llvm::endianness Endianness
Definition: MachOBuilder.h:580
static constexpr MachO::LoadCommandType SymTabCmd
Definition: MachOBuilder.h:583
static constexpr MachO::LoadCommandType SegmentCmd
Definition: MachOBuilder.h:582
MachOBuilderDylibLoadCommand(std::string Name, uint32_t Timestamp, uint32_t CurrentVersion, uint32_t CompatibilityVersion)
Definition: MachOBuilder.h:88
size_t write(MutableArrayRef< char > Buf, size_t Offset, bool SwapStruct) override
Definition: MachOBuilder.h:97
Base type for MachOBuilder load command wrappers.
Definition: MachOBuilder.h:38
virtual size_t size() const =0
virtual size_t write(MutableArrayRef< char > Buf, size_t Offset, bool SwapStruct)=0
MachOBuilder load command wrapper type.
Definition: MachOBuilder.h:46
size_t write(MutableArrayRef< char > Buf, size_t Offset, bool SwapStruct) override
Definition: MachOBuilder.h:133
MachOBuilderLoadCommand(ArgTs &&...Args)
Definition: MachOBuilder.h:80
Reloc(int32_t Offset, RelocTarget Target, bool PCRel, unsigned Length, unsigned Type)
Definition: MachOBuilder.h:202
MachO::relocation_info & rawStruct()
Definition: MachOBuilder.h:214
void addReloc(int32_t Offset, RelocTarget Target, bool PCRel, unsigned Length, unsigned Type)
Definition: MachOBuilder.h:253
std::vector< Reloc > Relocs
Definition: MachOBuilder.h:229
Section(MachOBuilder &Builder, StringRef SecName, StringRef SegName)
Definition: MachOBuilder.h:231
RelocTarget addSymbol(int32_t Offset, StringRef Name, uint8_t Type, uint16_t Desc)
Definition: MachOBuilder.h:240
Segment(MachOBuilder &Builder, StringRef SegName)
Definition: MachOBuilder.h:267
Section & addSection(StringRef SecName, StringRef SegName)
Definition: MachOBuilder.h:276
std::vector< std::unique_ptr< Section > > Sections
Definition: MachOBuilder.h:265
size_t write(MutableArrayRef< char > Buf, size_t Offset, bool SwapStruct) override
Definition: MachOBuilder.h:281