LLVM 24.0.0git
MachOObjcopy.cpp
Go to the documentation of this file.
1//===- MachOObjcopy.cpp -----------------------------------------*- 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
10#include "Archive.h"
11#include "MachOReader.h"
12#include "MachOWriter.h"
13#include "llvm/ADT/DenseSet.h"
21#include "llvm/Support/Errc.h"
22#include "llvm/Support/Error.h"
24#include "llvm/Support/Path.h"
26
27using namespace llvm;
28using namespace llvm::objcopy;
29using namespace llvm::objcopy::macho;
30using namespace llvm::object;
31
32using SectionPred = std::function<bool(const std::unique_ptr<Section> &Sec)>;
33using LoadCommandPred = std::function<bool(const LoadCommand &LC)>;
34
35#ifndef NDEBUG
37 // TODO: Add support for LC_REEXPORT_DYLIB, LC_LOAD_UPWARD_DYLIB and
38 // LC_LAZY_LOAD_DYLIB
39 return LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH ||
40 LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_ID_DYLIB ||
41 LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_LOAD_DYLIB ||
42 LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_LOAD_WEAK_DYLIB;
43}
44#endif
45
48 "unsupported load command encountered");
49
50 return StringRef(reinterpret_cast<const char *>(LC.Payload.data()),
51 LC.Payload.size())
52 .rtrim('\0');
53}
54
55static Error removeSections(const CommonConfig &Config, Object &Obj) {
56 SectionPred RemovePred = [](const std::unique_ptr<Section> &) {
57 return false;
58 };
59
60 if (!Config.ToRemove.empty()) {
61 RemovePred = [&Config, RemovePred](const std::unique_ptr<Section> &Sec) {
62 return Config.ToRemove.matches(Sec->CanonicalName);
63 };
64 }
65
66 if (Config.StripAll || Config.StripDebug) {
67 // Remove all debug sections.
68 RemovePred = [RemovePred](const std::unique_ptr<Section> &Sec) {
69 if (Sec->Segname == "__DWARF")
70 return true;
71
72 return RemovePred(Sec);
73 };
74 }
75
76 if (!Config.OnlySection.empty()) {
77 // Overwrite RemovePred because --only-section takes priority.
78 RemovePred = [&Config](const std::unique_ptr<Section> &Sec) {
79 return !Config.OnlySection.matches(Sec->CanonicalName);
80 };
81 }
82
83 return Obj.removeSections(RemovePred);
84}
85
86static void markSymbols(const CommonConfig &Config, Object &Obj) {
87 // Symbols referenced from the indirect symbol table must not be removed.
88 for (IndirectSymbolEntry &ISE : Obj.IndirectSymTable.Symbols)
89 if (ISE.Symbol)
90 (*ISE.Symbol)->Referenced = true;
91
92 // --strip-all removes relocations, so their symbols need not be preserved.
93 if (Config.StripAll)
94 return;
95
96 for (const LoadCommand &LC : Obj.LoadCommands)
97 for (const std::unique_ptr<Section> &Sec : LC.Sections)
98 for (const RelocationInfo &R : Sec->Relocations)
99 if (R.Symbol && *R.Symbol)
100 (*R.Symbol)->Referenced = true;
101}
102
103static void updateAndRemoveSymbols(const CommonConfig &Config,
105 Object &Obj) {
106 Obj.SymTable.updateSymbols([&](SymbolEntry &Sym) {
107 if (Config.SymbolsToSkip.matches(Sym.Name))
108 return;
109
110 if (!Sym.isUndefinedSymbol() && Config.SymbolsToLocalize.matches(Sym.Name))
111 Sym.n_type &= ~MachO::N_EXT;
112
113 // Note: these two globalize flags have very similar names but different
114 // meanings:
115 //
116 // --globalize-symbol: promote a symbol to global
117 // --keep-global-symbol: all symbols except for these should be made local
118 //
119 // If --globalize-symbol is specified for a given symbol, it will be
120 // global in the output file even if it is not included via
121 // --keep-global-symbol. Because of that, make sure to check
122 // --globalize-symbol second.
123 if (!Sym.isUndefinedSymbol() && !Config.SymbolsToKeepGlobal.empty() &&
124 !Config.SymbolsToKeepGlobal.matches(Sym.Name))
125 Sym.n_type &= ~MachO::N_EXT;
126
127 if (!Sym.isUndefinedSymbol() && Config.SymbolsToGlobalize.matches(Sym.Name))
128 Sym.n_type |= MachO::N_EXT;
129
130 if (Sym.isExternalSymbol() && !Sym.isUndefinedSymbol() &&
131 (Config.Weaken || Config.SymbolsToWeaken.matches(Sym.Name)))
133
134 auto I = Config.SymbolsToRename.find(Sym.Name);
135 if (I != Config.SymbolsToRename.end())
136 Sym.Name = std::string(I->getValue());
137 });
138
139 auto RemovePred = [&Config, &MachOConfig,
140 &Obj](const std::unique_ptr<SymbolEntry> &N) {
141 if (N->Referenced)
142 return false;
143 if (MachOConfig.KeepUndefined && N->isUndefinedSymbol())
144 return false;
145 if (N->n_desc & MachO::REFERENCED_DYNAMICALLY)
146 return false;
147 if (Config.StripAll)
148 return true;
149 if (Config.DiscardMode == DiscardType::All && !(N->n_type & MachO::N_EXT))
150 return true;
151 // This behavior is consistent with cctools' strip.
152 if (Config.StripDebug && (N->n_type & MachO::N_STAB))
153 return true;
154 // This behavior is consistent with cctools' strip.
156 (Obj.Header.Flags & MachO::MH_DYLDLINK) && Obj.SwiftVersion &&
157 *Obj.SwiftVersion && N->isSwiftSymbol())
158 return true;
159 return false;
160 };
161
162 Obj.SymTable.removeSymbols(RemovePred);
163}
164
165template <typename LCType>
168 "unsupported load command encountered");
169
170 uint32_t NewCmdsize = alignToPowerOf2(sizeof(LCType) + S.size() + 1, 8);
171
172 LC.MachOLoadCommand.load_command_data.cmdsize = NewCmdsize;
173 LC.Payload.assign(NewCmdsize - sizeof(LCType), 0);
174 llvm::copy(S, LC.Payload.begin());
175}
176
178 LoadCommand LC;
179 MachO::rpath_command RPathLC;
180 RPathLC.cmd = MachO::LC_RPATH;
181 RPathLC.path = sizeof(MachO::rpath_command);
182 RPathLC.cmdsize =
183 alignToPowerOf2(sizeof(MachO::rpath_command) + Path.size() + 1, 8);
184 LC.MachOLoadCommand.rpath_command_data = RPathLC;
185 LC.Payload.assign(RPathLC.cmdsize - sizeof(MachO::rpath_command), 0);
186 llvm::copy(Path, LC.Payload.begin());
187 return LC;
188}
189
191 // Remove RPaths.
192 DenseSet<StringRef> RPathsToRemove(MachOConfig.RPathsToRemove.begin(),
194
195 LoadCommandPred RemovePred = [&RPathsToRemove,
196 &MachOConfig](const LoadCommand &LC) {
197 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH) {
198 // When removing all RPaths we don't need to care
199 // about what it contains
201 return true;
202
203 StringRef RPath = getPayloadString(LC);
204 if (RPathsToRemove.count(RPath)) {
205 RPathsToRemove.erase(RPath);
206 return true;
207 }
208 }
209 return false;
210 };
211
212 if (Error E = Obj.removeLoadCommands(RemovePred))
213 return E;
214
215 // Emit an error if the Mach-O binary does not contain an rpath path name
216 // specified in -delete_rpath.
217 for (StringRef RPath : MachOConfig.RPathsToRemove) {
218 if (RPathsToRemove.count(RPath))
220 "no LC_RPATH load command with path: %s",
221 RPath.str().c_str());
222 }
223
224 DenseSet<StringRef> RPaths;
225
226 // Get all existing RPaths.
227 for (LoadCommand &LC : Obj.LoadCommands) {
228 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH)
229 RPaths.insert(getPayloadString(LC));
230 }
231
232 // Throw errors for invalid RPaths.
233 for (const auto &OldNew : MachOConfig.RPathsToUpdate) {
234 StringRef Old = OldNew.getFirst();
235 StringRef New = OldNew.getSecond();
236 if (!RPaths.contains(Old))
238 "no LC_RPATH load command with path: " + Old);
239 if (RPaths.contains(New))
241 "rpath '" + New +
242 "' would create a duplicate load command");
243 }
244
245 // Update load commands.
246 for (LoadCommand &LC : Obj.LoadCommands) {
247 switch (LC.MachOLoadCommand.load_command_data.cmd) {
248 case MachO::LC_ID_DYLIB:
252 break;
253
254 case MachO::LC_RPATH: {
255 StringRef RPath = getPayloadString(LC);
256 StringRef NewRPath = MachOConfig.RPathsToUpdate.lookup(RPath);
257 if (!NewRPath.empty())
259 break;
260 }
261
262 // TODO: Add LC_REEXPORT_DYLIB, LC_LAZY_LOAD_DYLIB, and LC_LOAD_UPWARD_DYLIB
263 // here once llvm-objcopy supports them.
264 case MachO::LC_LOAD_DYLIB:
265 case MachO::LC_LOAD_WEAK_DYLIB:
266 StringRef InstallName = getPayloadString(LC);
267 StringRef NewInstallName =
268 MachOConfig.InstallNamesToUpdate.lookup(InstallName);
269 if (!NewInstallName.empty())
271 NewInstallName);
272 break;
273 }
274 }
275
276 // Add new RPaths.
277 for (StringRef RPath : MachOConfig.RPathToAdd) {
278 if (RPaths.contains(RPath))
280 "rpath '" + RPath +
281 "' would create a duplicate load command");
282 RPaths.insert(RPath);
283 Obj.LoadCommands.push_back(buildRPathLoadCommand(RPath));
284 }
285
286 for (StringRef RPath : MachOConfig.RPathToPrepend) {
287 if (RPaths.contains(RPath))
289 "rpath '" + RPath +
290 "' would create a duplicate load command");
291
292 RPaths.insert(RPath);
293 Obj.LoadCommands.insert(Obj.LoadCommands.begin(),
294 buildRPathLoadCommand(RPath));
295 }
296
297 // Unlike appending rpaths, the indexes of subsequent load commands must
298 // be recalculated after prepending one.
299 if (!MachOConfig.RPathToPrepend.empty())
300 Obj.updateLoadCommandIndexes();
301
302 // Remove any empty segments if required.
303 if (!MachOConfig.EmptySegmentsToRemove.empty()) {
304 auto RemovePred = [&MachOConfig](const LoadCommand &LC) {
305 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_SEGMENT_64 ||
306 LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_SEGMENT) {
307 return LC.Sections.empty() &&
309 }
310 return false;
311 };
312 if (Error E = Obj.removeLoadCommands(RemovePred))
313 return E;
314 }
315
316 return Error::success();
317}
318
321 for (LoadCommand &LC : Obj.LoadCommands)
322 for (const std::unique_ptr<Section> &Sec : LC.Sections) {
323 if (Sec->CanonicalName == SecName) {
325 FileOutputBuffer::create(Filename, Sec->Content.size());
326 if (!BufferOrErr)
327 return createFileError(Filename, BufferOrErr.takeError());
328 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
329 llvm::copy(Sec->Content, Buf->getBufferStart());
330
331 if (Error E = Buf->commit())
332 return createFileError(Filename, std::move(E));
333 return Error::success();
334 }
335 }
336
338 "section '%s' not found", SecName.str().c_str());
339}
340
341static Error addSection(const NewSectionInfo &NewSection, Object &Obj) {
342 std::pair<StringRef, StringRef> Pair = NewSection.SectionName.split(',');
343 StringRef TargetSegName = Pair.first;
344 Section Sec(TargetSegName, Pair.second);
345 Sec.Content =
346 Obj.NewSectionsContents.save(NewSection.SectionData->getBuffer());
347 Sec.Size = Sec.Content.size();
348
349 // Add the a section into an existing segment.
350 for (LoadCommand &LC : Obj.LoadCommands) {
351 std::optional<StringRef> SegName = LC.getSegmentName();
352 if (SegName && SegName == TargetSegName) {
353 uint64_t Addr = *LC.getSegmentVMAddr();
354 for (const std::unique_ptr<Section> &S : LC.Sections)
355 Addr = std::max(Addr, S->Addr + S->Size);
356 LC.Sections.push_back(std::make_unique<Section>(Sec));
357 LC.Sections.back()->Addr = Addr;
358 return Error::success();
359 }
360 }
361
362 // There's no segment named TargetSegName. Create a new load command and
363 // Insert a new section into it.
364 LoadCommand &NewSegment =
365 Obj.addSegment(TargetSegName, alignToPowerOf2(Sec.Size, 16384));
366 NewSegment.Sections.push_back(std::make_unique<Section>(Sec));
367 NewSegment.Sections.back()->Addr = *NewSegment.getSegmentVMAddr();
368 return Error::success();
369}
370
372 StringRef SegName;
373 std::tie(SegName, SecName) = SecName.split(",");
374 // For compactness, intermediate object files (MH_OBJECT) contain
375 // only one segment in which all sections are placed.
376 // The static linker places each section in the named segment when building
377 // the final product (any file that is not of type MH_OBJECT).
378 //
379 // Source:
380 // https://math-atlas.sourceforge.net/devel/assembly/MachORuntime.pdf
381 // page 57
382 if (O.Header.FileType == MachO::HeaderFileType::MH_OBJECT) {
383 for (const auto& LC : O.LoadCommands)
384 for (const auto& Sec : LC.Sections)
385 if (Sec->Segname == SegName && Sec->Sectname == SecName)
386 return *Sec;
387
388 StringRef ErrMsg = "could not find section with name '%s' in '%s' segment";
389 return createStringError(errc::invalid_argument, ErrMsg.str().c_str(),
390 SecName.str().c_str(), SegName.str().c_str());
391 }
392 auto FoundSeg =
393 llvm::find_if(O.LoadCommands, [SegName](const LoadCommand &LC) {
394 return LC.getSegmentName() == SegName;
395 });
396 if (FoundSeg == O.LoadCommands.end())
398 "could not find segment with name '%s'",
399 SegName.str().c_str());
400 auto FoundSec = llvm::find_if(FoundSeg->Sections,
401 [SecName](const std::unique_ptr<Section> &Sec) {
402 return Sec->Sectname == SecName;
403 });
404 if (FoundSec == FoundSeg->Sections.end())
406 "could not find section with name '%s'",
407 SecName.str().c_str());
408
409 assert(FoundSec->get()->CanonicalName == (SegName + "," + SecName).str());
410 return **FoundSec;
411}
412
413static Error updateSection(const NewSectionInfo &NewSection, Object &O) {
414 Expected<Section &> SecToUpdateOrErr = findSection(NewSection.SectionName, O);
415
416 if (!SecToUpdateOrErr)
417 return SecToUpdateOrErr.takeError();
418 Section &Sec = *SecToUpdateOrErr;
419
420 if (NewSection.SectionData->getBufferSize() > Sec.Size)
421 return createStringError(
423 "new section cannot be larger than previous section");
424 Sec.Content = O.NewSectionsContents.save(NewSection.SectionData->getBuffer());
425 Sec.Size = Sec.Content.size();
426 return Error::success();
427}
428
429// isValidMachOCannonicalName returns success if Name is a MachO cannonical name
430// ("<segment>,<section>") and lengths of both segment and section names are
431// valid.
433 if (Name.count(',') != 1)
435 "invalid section name '%s' (should be formatted "
436 "as '<segment name>,<section name>')",
437 Name.str().c_str());
438
439 std::pair<StringRef, StringRef> Pair = Name.split(',');
440 if (Pair.first.size() > 16)
442 "too long segment name: '%s'",
443 Pair.first.str().c_str());
444 if (Pair.second.size() > 16)
446 "too long section name: '%s'",
447 Pair.second.str().c_str());
448 return Error::success();
449}
450
451static Error handleArgs(const CommonConfig &Config,
452 const MachOConfig &MachOConfig, Object &Obj) {
453 // Dump sections before add/remove for compatibility with GNU objcopy.
454 for (StringRef Flag : Config.DumpSection) {
456 StringRef FileName;
457 std::tie(SectionName, FileName) = Flag.split('=');
458 if (Error E =
459 dumpSectionToFile(SectionName, FileName, Config.InputFilename, Obj))
460 return E;
461 }
462
463 if (Error E = removeSections(Config, Obj))
464 return createFileError(Config.InputFilename, std::move(E));
465
466 // Mark symbols to determine which symbols are still needed.
467 markSymbols(Config, Obj);
468
470
471 if (Config.StripAll)
472 for (LoadCommand &LC : Obj.LoadCommands)
473 for (std::unique_ptr<Section> &Sec : LC.Sections)
474 Sec->Relocations.clear();
475
476 for (const NewSectionInfo &NewSection : Config.AddSection) {
478 return createFileError(Config.InputFilename, std::move(E));
479 if (Error E = addSection(NewSection, Obj))
480 return createFileError(Config.InputFilename, std::move(E));
481 }
482
483 for (const NewSectionInfo &NewSection : Config.UpdateSection) {
485 return createFileError(Config.InputFilename, std::move(E));
486 if (Error E = updateSection(NewSection, Obj))
487 return createFileError(Config.InputFilename, std::move(E));
488 }
489
491 return createFileError(Config.InputFilename, std::move(E));
492
493 return Error::success();
494}
495
499 raw_ostream &Out) {
502 if (!O)
503 return createFileError(Config.InputFilename, O.takeError());
504
505 if (O->get()->Header.FileType == MachO::HeaderFileType::MH_PRELOAD)
506 return createStringError(std::errc::not_supported,
507 "%s: MH_PRELOAD files are not supported",
508 Config.InputFilename.str().c_str());
509
510 if (Error E = handleArgs(Config, MachOConfig, **O))
511 return E;
512
513 // Page size used for alignment of segment sizes in Mach-O executables and
514 // dynamic libraries.
515 uint64_t PageSize;
516 switch (In.getArch()) {
520 PageSize = 16384;
521 break;
522 default:
523 PageSize = 4096;
524 }
525
526 MachOWriter Writer(**O, In.is64Bit(), In.isLittleEndian(),
528 if (auto E = Writer.finalize())
529 return E;
530 return Writer.write();
531}
532
534 const MultiFormatConfig &Config, const MachOUniversalBinary &In,
535 raw_ostream &Out) {
538 for (const auto &O : In.objects()) {
539 Expected<std::unique_ptr<Archive>> ArOrErr = O.getAsArchive();
540 if (ArOrErr) {
541 Expected<std::vector<NewArchiveMember>> NewArchiveMembersOrErr =
542 createNewArchiveMembers(Config, **ArOrErr);
543 if (!NewArchiveMembersOrErr)
544 return NewArchiveMembersOrErr.takeError();
545 auto Kind = (*ArOrErr)->kind();
548 Expected<std::unique_ptr<MemoryBuffer>> OutputBufferOrErr =
550 *NewArchiveMembersOrErr,
551 (*ArOrErr)->hasSymbolTable() ? SymtabWritingMode::NormalSymtab
554 (*ArOrErr)->isThin());
555 if (!OutputBufferOrErr)
556 return OutputBufferOrErr.takeError();
558 object::createBinary(**OutputBufferOrErr);
559 if (!BinaryOrErr)
560 return BinaryOrErr.takeError();
561 Binaries.emplace_back(std::move(*BinaryOrErr),
562 std::move(*OutputBufferOrErr));
563 Slices.emplace_back(*cast<Archive>(Binaries.back().getBinary()),
564 O.getCPUType(), O.getCPUSubType(),
565 O.getArchFlagName(), O.getAlign());
566 continue;
567 }
568 // The methods getAsArchive, getAsObjectFile, getAsIRObject of the class
569 // ObjectForArch return an Error in case of the type mismatch. We need to
570 // check each in turn to see what kind of slice this is, so ignore errors
571 // produced along the way.
572 consumeError(ArOrErr.takeError());
573
574 Expected<std::unique_ptr<MachOObjectFile>> ObjOrErr = O.getAsObjectFile();
575 if (!ObjOrErr) {
576 consumeError(ObjOrErr.takeError());
577 return createStringError(
578 std::errc::invalid_argument,
579 "slice for '%s' of the universal Mach-O binary "
580 "'%s' is not a Mach-O object or an archive",
581 O.getArchFlagName().c_str(),
582 Config.getCommonConfig().InputFilename.str().c_str());
583 }
584 std::string ArchFlagName = O.getArchFlagName();
585
587 raw_svector_ostream MemStream(Buffer);
588
590 if (!MachO)
591 return MachO.takeError();
592
594 **ObjOrErr, MemStream))
595 return E;
596
597 auto MB = std::make_unique<SmallVectorMemoryBuffer>(
598 std::move(Buffer), ArchFlagName, /*RequiresNullTerminator=*/false);
600 if (!BinaryOrErr)
601 return BinaryOrErr.takeError();
602 Binaries.emplace_back(std::move(*BinaryOrErr), std::move(MB));
603 Slices.emplace_back(*cast<MachOObjectFile>(Binaries.back().getBinary()),
604 O.getAlign());
605 }
606
607 if (Error Err = writeUniversalBinaryToStream(Slices, Out))
608 return Err;
609
610 return Error::success();
611}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
std::function< bool(const SectionBase &Sec)> SectionPred
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
#define I(x, y, z)
Definition MD5.cpp:57
static Error processLoadCommands(const MachOConfig &MachOConfig, Object &Obj)
static Expected< Section & > findSection(StringRef SecName, Object &O)
static Error isValidMachOCannonicalName(StringRef Name)
static void updateLoadCommandPayloadString(LoadCommand &LC, StringRef S)
static LoadCommand buildRPathLoadCommand(StringRef Path)
static bool isLoadCommandWithPayloadString(const LoadCommand &LC)
static void markSymbols(const CommonConfig &Config, Object &Obj)
static Error handleArgs(const CommonConfig &Config, const MachOConfig &MachOConfig, Object &Obj)
static Error removeSections(const CommonConfig &Config, Object &Obj)
std::function< bool(const LoadCommand &LC)> LoadCommandPred
static Error dumpSectionToFile(StringRef SecName, StringRef Filename, StringRef InputFilename, Object &Obj)
static Error addSection(const NewSectionInfo &NewSection, Object &Obj)
static StringRef getPayloadString(const LoadCommand &LC)
static void updateAndRemoveSymbols(const CommonConfig &Config, const MachOConfig &MachOConfig, Object &Obj)
static Error updateSection(const NewSectionInfo &NewSection, Object &O)
static cl::opt< std::string > InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"))
static constexpr StringLiteral Filename
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
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
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
static LLVM_ABI Expected< std::unique_ptr< FileOutputBuffer > > create(StringRef FilePath, size_t Size, unsigned Flags=0)
Factory method to create an OutputBuffer object which manages a read/write buffer of the specified si...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
Definition StringRef.h:838
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:209
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:182
bool erase(const ValueT &V)
Definition DenseSet.h:97
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:187
virtual Expected< const MachOConfig & > getMachOConfig() const =0
virtual const CommonConfig & getCommonConfig() const =0
bool matches(StringRef S) const
virtual Expected< std::unique_ptr< Object > > create() const =0
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
@ MH_OBJECT
Definition MachO.h:43
@ MH_PRELOAD
Definition MachO.h:47
@ MH_DYLDLINK
Definition MachO.h:62
@ N_WEAK_DEF
Definition MachO.h:346
@ REFERENCED_DYNAMICALLY
Definition MachO.h:343
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config, const MachOConfig &MachOConfig, object::MachOObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and MachOConfig to In and writes the result into Out.
LLVM_ABI Error executeObjcopyOnMachOUniversalBinary(const MultiFormatConfig &Config, const object::MachOUniversalBinary &In, raw_ostream &Out)
Apply the transformations described by Config and MachOConfig to In and writes the result into Out.
Expected< std::vector< NewArchiveMember > > createNewArchiveMembers(const MultiFormatConfig &Config, const object::Archive &Ar)
Applies the transformations described by Config to each member in archive Ar.
Definition Archive.cpp:22
LLVM_ABI Error writeUniversalBinaryToStream(ArrayRef< Slice > Slices, raw_ostream &Out, FatHeaderType FatHeader=FatHeaderType::FatHeader)
LLVM_ABI Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
Definition Binary.cpp:45
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:594
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Expected< std::unique_ptr< MemoryBuffer > > writeArchiveToBuffer(ArrayRef< NewArchiveMember > NewMembers, SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, function_ref< void(Error)> Warn=warnToStderr)
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition Error.h:1415
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
@ invalid_argument
Definition Errc.h:56
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
Definition MathExtras.h:488
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1901
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106
#define N
SmallVector< NewSectionInfo, 0 > UpdateSection
SmallVector< StringRef, 0 > DumpSection
SmallVector< NewSectionInfo, 0 > AddSection
StringMap< StringRef > SymbolsToRename
std::vector< StringRef > RPathToPrepend
Definition MachOConfig.h:25
DenseMap< StringRef, StringRef > InstallNamesToUpdate
Definition MachOConfig.h:27
std::optional< StringRef > SharedLibId
Definition MachOConfig.h:31
DenseSet< StringRef > EmptySegmentsToRemove
Definition MachOConfig.h:34
DenseSet< StringRef > RPathsToRemove
Definition MachOConfig.h:28
DenseMap< StringRef, StringRef > RPathsToUpdate
Definition MachOConfig.h:26
std::vector< StringRef > RPathToAdd
Definition MachOConfig.h:24
std::shared_ptr< MemoryBuffer > SectionData
std::optional< SymbolEntry * > Symbol
The Symbol referenced by this entry.
MachO::macho_load_command MachOLoadCommand
Definition MachOObject.h:82
std::optional< StringRef > getSegmentName() const
std::vector< std::unique_ptr< Section > > Sections
Definition MachOObject.h:93
std::optional< uint64_t > getSegmentVMAddr() const
std::vector< uint8_t > Payload
Definition MachOObject.h:87