LLVM 23.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 &, 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
93static void updateAndRemoveSymbols(const CommonConfig &Config,
95 Object &Obj) {
96 Obj.SymTable.updateSymbols([&](SymbolEntry &Sym) {
97 if (Config.SymbolsToSkip.matches(Sym.Name))
98 return;
99
100 if (!Sym.isUndefinedSymbol() && Config.SymbolsToLocalize.matches(Sym.Name))
101 Sym.n_type &= ~MachO::N_EXT;
102
103 // Note: these two globalize flags have very similar names but different
104 // meanings:
105 //
106 // --globalize-symbol: promote a symbol to global
107 // --keep-global-symbol: all symbols except for these should be made local
108 //
109 // If --globalize-symbol is specified for a given symbol, it will be
110 // global in the output file even if it is not included via
111 // --keep-global-symbol. Because of that, make sure to check
112 // --globalize-symbol second.
113 if (!Sym.isUndefinedSymbol() && !Config.SymbolsToKeepGlobal.empty() &&
114 !Config.SymbolsToKeepGlobal.matches(Sym.Name))
115 Sym.n_type &= ~MachO::N_EXT;
116
117 if (!Sym.isUndefinedSymbol() && Config.SymbolsToGlobalize.matches(Sym.Name))
118 Sym.n_type |= MachO::N_EXT;
119
120 if (Sym.isExternalSymbol() && !Sym.isUndefinedSymbol() &&
121 (Config.Weaken || Config.SymbolsToWeaken.matches(Sym.Name)))
123
124 auto I = Config.SymbolsToRename.find(Sym.Name);
125 if (I != Config.SymbolsToRename.end())
126 Sym.Name = std::string(I->getValue());
127 });
128
129 auto RemovePred = [&Config, &MachOConfig,
130 &Obj](const std::unique_ptr<SymbolEntry> &N) {
131 if (N->Referenced)
132 return false;
133 if (MachOConfig.KeepUndefined && N->isUndefinedSymbol())
134 return false;
135 if (N->n_desc & MachO::REFERENCED_DYNAMICALLY)
136 return false;
137 if (Config.StripAll)
138 return true;
139 if (Config.DiscardMode == DiscardType::All && !(N->n_type & MachO::N_EXT))
140 return true;
141 // This behavior is consistent with cctools' strip.
142 if (Config.StripDebug && (N->n_type & MachO::N_STAB))
143 return true;
144 // This behavior is consistent with cctools' strip.
146 (Obj.Header.Flags & MachO::MH_DYLDLINK) && Obj.SwiftVersion &&
147 *Obj.SwiftVersion && N->isSwiftSymbol())
148 return true;
149 return false;
150 };
151
152 Obj.SymTable.removeSymbols(RemovePred);
153}
154
155template <typename LCType>
158 "unsupported load command encountered");
159
160 uint32_t NewCmdsize = alignToPowerOf2(sizeof(LCType) + S.size() + 1, 8);
161
162 LC.MachOLoadCommand.load_command_data.cmdsize = NewCmdsize;
163 LC.Payload.assign(NewCmdsize - sizeof(LCType), 0);
164 llvm::copy(S, LC.Payload.begin());
165}
166
168 LoadCommand LC;
169 MachO::rpath_command RPathLC;
170 RPathLC.cmd = MachO::LC_RPATH;
171 RPathLC.path = sizeof(MachO::rpath_command);
172 RPathLC.cmdsize =
173 alignToPowerOf2(sizeof(MachO::rpath_command) + Path.size() + 1, 8);
174 LC.MachOLoadCommand.rpath_command_data = RPathLC;
175 LC.Payload.assign(RPathLC.cmdsize - sizeof(MachO::rpath_command), 0);
176 llvm::copy(Path, LC.Payload.begin());
177 return LC;
178}
179
181 // Remove RPaths.
182 DenseSet<StringRef> RPathsToRemove(MachOConfig.RPathsToRemove.begin(),
184
185 LoadCommandPred RemovePred = [&RPathsToRemove,
186 &MachOConfig](const LoadCommand &LC) {
187 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH) {
188 // When removing all RPaths we don't need to care
189 // about what it contains
191 return true;
192
193 StringRef RPath = getPayloadString(LC);
194 if (RPathsToRemove.count(RPath)) {
195 RPathsToRemove.erase(RPath);
196 return true;
197 }
198 }
199 return false;
200 };
201
202 if (Error E = Obj.removeLoadCommands(RemovePred))
203 return E;
204
205 // Emit an error if the Mach-O binary does not contain an rpath path name
206 // specified in -delete_rpath.
207 for (StringRef RPath : MachOConfig.RPathsToRemove) {
208 if (RPathsToRemove.count(RPath))
210 "no LC_RPATH load command with path: %s",
211 RPath.str().c_str());
212 }
213
214 DenseSet<StringRef> RPaths;
215
216 // Get all existing RPaths.
217 for (LoadCommand &LC : Obj.LoadCommands) {
218 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH)
219 RPaths.insert(getPayloadString(LC));
220 }
221
222 // Throw errors for invalid RPaths.
223 for (const auto &OldNew : MachOConfig.RPathsToUpdate) {
224 StringRef Old = OldNew.getFirst();
225 StringRef New = OldNew.getSecond();
226 if (!RPaths.contains(Old))
228 "no LC_RPATH load command with path: " + Old);
229 if (RPaths.contains(New))
231 "rpath '" + New +
232 "' would create a duplicate load command");
233 }
234
235 // Update load commands.
236 for (LoadCommand &LC : Obj.LoadCommands) {
237 switch (LC.MachOLoadCommand.load_command_data.cmd) {
238 case MachO::LC_ID_DYLIB:
242 break;
243
244 case MachO::LC_RPATH: {
245 StringRef RPath = getPayloadString(LC);
246 StringRef NewRPath = MachOConfig.RPathsToUpdate.lookup(RPath);
247 if (!NewRPath.empty())
249 break;
250 }
251
252 // TODO: Add LC_REEXPORT_DYLIB, LC_LAZY_LOAD_DYLIB, and LC_LOAD_UPWARD_DYLIB
253 // here once llvm-objcopy supports them.
254 case MachO::LC_LOAD_DYLIB:
255 case MachO::LC_LOAD_WEAK_DYLIB:
256 StringRef InstallName = getPayloadString(LC);
257 StringRef NewInstallName =
258 MachOConfig.InstallNamesToUpdate.lookup(InstallName);
259 if (!NewInstallName.empty())
261 NewInstallName);
262 break;
263 }
264 }
265
266 // Add new RPaths.
267 for (StringRef RPath : MachOConfig.RPathToAdd) {
268 if (RPaths.contains(RPath))
270 "rpath '" + RPath +
271 "' would create a duplicate load command");
272 RPaths.insert(RPath);
273 Obj.LoadCommands.push_back(buildRPathLoadCommand(RPath));
274 }
275
276 for (StringRef RPath : MachOConfig.RPathToPrepend) {
277 if (RPaths.contains(RPath))
279 "rpath '" + RPath +
280 "' would create a duplicate load command");
281
282 RPaths.insert(RPath);
283 Obj.LoadCommands.insert(Obj.LoadCommands.begin(),
284 buildRPathLoadCommand(RPath));
285 }
286
287 // Unlike appending rpaths, the indexes of subsequent load commands must
288 // be recalculated after prepending one.
289 if (!MachOConfig.RPathToPrepend.empty())
290 Obj.updateLoadCommandIndexes();
291
292 // Remove any empty segments if required.
293 if (!MachOConfig.EmptySegmentsToRemove.empty()) {
294 auto RemovePred = [&MachOConfig](const LoadCommand &LC) {
295 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_SEGMENT_64 ||
296 LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_SEGMENT) {
297 return LC.Sections.empty() &&
299 }
300 return false;
301 };
302 if (Error E = Obj.removeLoadCommands(RemovePred))
303 return E;
304 }
305
306 return Error::success();
307}
308
311 for (LoadCommand &LC : Obj.LoadCommands)
312 for (const std::unique_ptr<Section> &Sec : LC.Sections) {
313 if (Sec->CanonicalName == SecName) {
315 FileOutputBuffer::create(Filename, Sec->Content.size());
316 if (!BufferOrErr)
317 return createFileError(Filename, BufferOrErr.takeError());
318 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
319 llvm::copy(Sec->Content, Buf->getBufferStart());
320
321 if (Error E = Buf->commit())
322 return createFileError(Filename, std::move(E));
323 return Error::success();
324 }
325 }
326
328 "section '%s' not found", SecName.str().c_str());
329}
330
331static Error addSection(const NewSectionInfo &NewSection, Object &Obj) {
332 std::pair<StringRef, StringRef> Pair = NewSection.SectionName.split(',');
333 StringRef TargetSegName = Pair.first;
334 Section Sec(TargetSegName, Pair.second);
335 Sec.Content =
336 Obj.NewSectionsContents.save(NewSection.SectionData->getBuffer());
337 Sec.Size = Sec.Content.size();
338
339 // Add the a section into an existing segment.
340 for (LoadCommand &LC : Obj.LoadCommands) {
341 std::optional<StringRef> SegName = LC.getSegmentName();
342 if (SegName && SegName == TargetSegName) {
343 uint64_t Addr = *LC.getSegmentVMAddr();
344 for (const std::unique_ptr<Section> &S : LC.Sections)
345 Addr = std::max(Addr, S->Addr + S->Size);
346 LC.Sections.push_back(std::make_unique<Section>(Sec));
347 LC.Sections.back()->Addr = Addr;
348 return Error::success();
349 }
350 }
351
352 // There's no segment named TargetSegName. Create a new load command and
353 // Insert a new section into it.
354 LoadCommand &NewSegment =
355 Obj.addSegment(TargetSegName, alignToPowerOf2(Sec.Size, 16384));
356 NewSegment.Sections.push_back(std::make_unique<Section>(Sec));
357 NewSegment.Sections.back()->Addr = *NewSegment.getSegmentVMAddr();
358 return Error::success();
359}
360
362 StringRef SegName;
363 std::tie(SegName, SecName) = SecName.split(",");
364 // For compactness, intermediate object files (MH_OBJECT) contain
365 // only one segment in which all sections are placed.
366 // The static linker places each section in the named segment when building
367 // the final product (any file that is not of type MH_OBJECT).
368 //
369 // Source:
370 // https://math-atlas.sourceforge.net/devel/assembly/MachORuntime.pdf
371 // page 57
372 if (O.Header.FileType == MachO::HeaderFileType::MH_OBJECT) {
373 for (const auto& LC : O.LoadCommands)
374 for (const auto& Sec : LC.Sections)
375 if (Sec->Segname == SegName && Sec->Sectname == SecName)
376 return *Sec;
377
378 StringRef ErrMsg = "could not find section with name '%s' in '%s' segment";
379 return createStringError(errc::invalid_argument, ErrMsg.str().c_str(),
380 SecName.str().c_str(), SegName.str().c_str());
381 }
382 auto FoundSeg =
383 llvm::find_if(O.LoadCommands, [SegName](const LoadCommand &LC) {
384 return LC.getSegmentName() == SegName;
385 });
386 if (FoundSeg == O.LoadCommands.end())
388 "could not find segment with name '%s'",
389 SegName.str().c_str());
390 auto FoundSec = llvm::find_if(FoundSeg->Sections,
391 [SecName](const std::unique_ptr<Section> &Sec) {
392 return Sec->Sectname == SecName;
393 });
394 if (FoundSec == FoundSeg->Sections.end())
396 "could not find section with name '%s'",
397 SecName.str().c_str());
398
399 assert(FoundSec->get()->CanonicalName == (SegName + "," + SecName).str());
400 return **FoundSec;
401}
402
403static Error updateSection(const NewSectionInfo &NewSection, Object &O) {
404 Expected<Section &> SecToUpdateOrErr = findSection(NewSection.SectionName, O);
405
406 if (!SecToUpdateOrErr)
407 return SecToUpdateOrErr.takeError();
408 Section &Sec = *SecToUpdateOrErr;
409
410 if (NewSection.SectionData->getBufferSize() > Sec.Size)
411 return createStringError(
413 "new section cannot be larger than previous section");
414 Sec.Content = O.NewSectionsContents.save(NewSection.SectionData->getBuffer());
415 Sec.Size = Sec.Content.size();
416 return Error::success();
417}
418
419// isValidMachOCannonicalName returns success if Name is a MachO cannonical name
420// ("<segment>,<section>") and lengths of both segment and section names are
421// valid.
423 if (Name.count(',') != 1)
425 "invalid section name '%s' (should be formatted "
426 "as '<segment name>,<section name>')",
427 Name.str().c_str());
428
429 std::pair<StringRef, StringRef> Pair = Name.split(',');
430 if (Pair.first.size() > 16)
432 "too long segment name: '%s'",
433 Pair.first.str().c_str());
434 if (Pair.second.size() > 16)
436 "too long section name: '%s'",
437 Pair.second.str().c_str());
438 return Error::success();
439}
440
441static Error handleArgs(const CommonConfig &Config,
442 const MachOConfig &MachOConfig, Object &Obj) {
443 // Dump sections before add/remove for compatibility with GNU objcopy.
444 for (StringRef Flag : Config.DumpSection) {
446 StringRef FileName;
447 std::tie(SectionName, FileName) = Flag.split('=');
448 if (Error E =
449 dumpSectionToFile(SectionName, FileName, Config.InputFilename, Obj))
450 return E;
451 }
452
453 if (Error E = removeSections(Config, Obj))
454 return createFileError(Config.InputFilename, std::move(E));
455
456 // Mark symbols to determine which symbols are still needed.
457 if (Config.StripAll)
458 markSymbols(Config, Obj);
459
461
462 if (Config.StripAll)
463 for (LoadCommand &LC : Obj.LoadCommands)
464 for (std::unique_ptr<Section> &Sec : LC.Sections)
465 Sec->Relocations.clear();
466
467 for (const NewSectionInfo &NewSection : Config.AddSection) {
469 return createFileError(Config.InputFilename, std::move(E));
470 if (Error E = addSection(NewSection, Obj))
471 return createFileError(Config.InputFilename, std::move(E));
472 }
473
474 for (const NewSectionInfo &NewSection : Config.UpdateSection) {
476 return createFileError(Config.InputFilename, std::move(E));
477 if (Error E = updateSection(NewSection, Obj))
478 return createFileError(Config.InputFilename, std::move(E));
479 }
480
482 return createFileError(Config.InputFilename, std::move(E));
483
484 return Error::success();
485}
486
490 raw_ostream &Out) {
493 if (!O)
494 return createFileError(Config.InputFilename, O.takeError());
495
496 if (O->get()->Header.FileType == MachO::HeaderFileType::MH_PRELOAD)
497 return createStringError(std::errc::not_supported,
498 "%s: MH_PRELOAD files are not supported",
499 Config.InputFilename.str().c_str());
500
501 if (Error E = handleArgs(Config, MachOConfig, **O))
502 return E;
503
504 // Page size used for alignment of segment sizes in Mach-O executables and
505 // dynamic libraries.
507 switch (In.getArch()) {
511 PageSize = 16384;
512 break;
513 default:
514 PageSize = 4096;
515 }
516
517 MachOWriter Writer(**O, In.is64Bit(), In.isLittleEndian(),
519 if (auto E = Writer.finalize())
520 return E;
521 return Writer.write();
522}
523
525 const MultiFormatConfig &Config, const MachOUniversalBinary &In,
526 raw_ostream &Out) {
529 for (const auto &O : In.objects()) {
530 Expected<std::unique_ptr<Archive>> ArOrErr = O.getAsArchive();
531 if (ArOrErr) {
532 Expected<std::vector<NewArchiveMember>> NewArchiveMembersOrErr =
533 createNewArchiveMembers(Config, **ArOrErr);
534 if (!NewArchiveMembersOrErr)
535 return NewArchiveMembersOrErr.takeError();
536 auto Kind = (*ArOrErr)->kind();
539 Expected<std::unique_ptr<MemoryBuffer>> OutputBufferOrErr =
541 *NewArchiveMembersOrErr,
542 (*ArOrErr)->hasSymbolTable() ? SymtabWritingMode::NormalSymtab
545 (*ArOrErr)->isThin());
546 if (!OutputBufferOrErr)
547 return OutputBufferOrErr.takeError();
549 object::createBinary(**OutputBufferOrErr);
550 if (!BinaryOrErr)
551 return BinaryOrErr.takeError();
552 Binaries.emplace_back(std::move(*BinaryOrErr),
553 std::move(*OutputBufferOrErr));
554 Slices.emplace_back(*cast<Archive>(Binaries.back().getBinary()),
555 O.getCPUType(), O.getCPUSubType(),
556 O.getArchFlagName(), O.getAlign());
557 continue;
558 }
559 // The methods getAsArchive, getAsObjectFile, getAsIRObject of the class
560 // ObjectForArch return an Error in case of the type mismatch. We need to
561 // check each in turn to see what kind of slice this is, so ignore errors
562 // produced along the way.
563 consumeError(ArOrErr.takeError());
564
565 Expected<std::unique_ptr<MachOObjectFile>> ObjOrErr = O.getAsObjectFile();
566 if (!ObjOrErr) {
567 consumeError(ObjOrErr.takeError());
568 return createStringError(
569 std::errc::invalid_argument,
570 "slice for '%s' of the universal Mach-O binary "
571 "'%s' is not a Mach-O object or an archive",
572 O.getArchFlagName().c_str(),
573 Config.getCommonConfig().InputFilename.str().c_str());
574 }
575 std::string ArchFlagName = O.getArchFlagName();
576
578 raw_svector_ostream MemStream(Buffer);
579
581 if (!MachO)
582 return MachO.takeError();
583
585 **ObjOrErr, MemStream))
586 return E;
587
588 auto MB = std::make_unique<SmallVectorMemoryBuffer>(
589 std::move(Buffer), ArchFlagName, /*RequiresNullTerminator=*/false);
591 if (!BinaryOrErr)
592 return BinaryOrErr.takeError();
593 Binaries.emplace_back(std::move(*BinaryOrErr), std::move(MB));
594 Slices.emplace_back(*cast<MachOObjectFile>(Binaries.back().getBinary()),
595 O.getAlign());
596 }
597
598 if (Error Err = writeUniversalBinaryToStream(Slices, Out))
599 return Err;
600
601 return Error::success();
602}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 &, 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:289
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:730
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:832
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:212
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:185
bool erase(const ValueT &V)
Definition DenseSet.h:100
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:190
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:493
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1884
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:1771
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