Go to the documentation of this file.
48 "unsupported load command encountered");
56 SectionPred RemovePred = [](
const std::unique_ptr<Section> &) {
61 RemovePred = [&Config, RemovePred](
const std::unique_ptr<Section> &Sec) {
68 RemovePred = [RemovePred](
const std::unique_ptr<Section> &Sec) {
69 if (Sec->Segname ==
"__DWARF")
72 return RemovePred(Sec);
78 RemovePred = [&Config](
const std::unique_ptr<Section> &Sec) {
90 (*ISE.
Symbol)->Referenced =
true;
99 Sym.
Name = std::string(
I->getValue());
103 &Obj](
const std::unique_ptr<SymbolEntry> &
N) {
125 template <
typename LCType>
128 "unsupported load command encountered");
133 LC.
Payload.assign(NewCmdsize -
sizeof(LCType), 0);
140 RPathLC.
cmd = MachO::LC_RPATH;
156 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH) {
163 if (RPathsToRemove.
count(RPath)) {
164 RPathsToRemove.
erase(RPath);
177 if (RPathsToRemove.
count(RPath))
179 "no LC_RPATH load command with path: %s",
180 RPath.
str().c_str());
197 "no LC_RPATH load command with path: " + Old);
201 "' would create a duplicate load command");
207 case MachO::LC_ID_DYLIB:
209 updateLoadCommandPayloadString<MachO::dylib_command>(
213 case MachO::LC_RPATH: {
216 if (!NewRPath.
empty())
217 updateLoadCommandPayloadString<MachO::rpath_command>(LC, NewRPath);
223 case MachO::LC_LOAD_DYLIB:
224 case MachO::LC_LOAD_WEAK_DYLIB:
228 if (!NewInstallName.
empty())
229 updateLoadCommandPayloadString<MachO::dylib_command>(LC,
240 "' would create a duplicate load command");
249 "' would create a duplicate load command");
281 for (
const std::unique_ptr<Section> &Sec : LC.
Sections) {
282 if (Sec->CanonicalName == SecName) {
287 std::unique_ptr<FileOutputBuffer> Buf =
std::move(*BufferOrErr);
288 llvm::copy(Sec->Content, Buf->getBufferStart());
290 if (
Error E = Buf->commit())
297 SecName.
str().c_str());
303 Section Sec(TargetSegName, Pair.second);
311 if (SegName && SegName == TargetSegName) {
313 for (
const std::unique_ptr<Section> &
S : LC.
Sections)
315 LC.
Sections.push_back(std::make_unique<Section>(Sec));
325 NewSegment.
Sections.push_back(std::make_unique<Section>(Sec));
332 std::tie(SegName, SecName) = SecName.
split(
",");
335 return LC.getSegmentName() == SegName;
337 if (FoundSeg ==
O.LoadCommands.end())
339 "could not find segment with name '%s'",
340 SegName.
str().c_str());
342 [SecName](
const std::unique_ptr<Section> &Sec) {
343 return Sec->Sectname == SecName;
345 if (FoundSec == FoundSeg->Sections.end())
347 "could not find section with name '%s'",
348 SecName.
str().c_str());
350 assert(FoundSec->get()->CanonicalName == (SegName +
"," + SecName).str());
351 return *FoundSec->get();
357 if (!SecToUpdateOrErr)
359 Section &Sec = *SecToUpdateOrErr;
364 "new section cannot be larger than previous section");
374 if (
Name.count(
',') != 1)
376 "invalid section name '%s' (should be formatted "
377 "as '<segment name>,<section name>')",
380 std::pair<StringRef, StringRef> Pair =
Name.split(
',');
381 if (Pair.first.size() > 16)
383 "too long segment name: '%s'",
384 Pair.first.str().c_str());
385 if (Pair.second.size() > 16)
387 "too long section name: '%s'",
388 Pair.second.str().c_str());
414 for (std::unique_ptr<Section> &Sec : LC.
Sections)
415 Sec->Relocations.clear();
448 "%s: MH_PRELOAD files are not supported",
457 switch (
In.getArch()) {
458 case Triple::ArchType::arm:
459 case Triple::ArchType::aarch64:
460 case Triple::ArchType::aarch64_32:
471 return Writer.
write();
479 for (
const auto &
O :
In.objects()) {
484 if (!NewArchiveMembersOrErr)
485 return NewArchiveMembersOrErr.
takeError();
486 auto Kind = (*ArOrErr)->kind();
491 (*ArOrErr)->hasSymbolTable(),
Kind,
493 (*ArOrErr)->isThin());
494 if (!OutputBufferOrErr)
502 Slices.
emplace_back(*cast<Archive>(Binaries.back().getBinary()),
503 O.getCPUType(),
O.getCPUSubType(),
504 O.getArchFlagName(),
O.getAlign());
517 std::errc::invalid_argument,
518 "slice for '%s' of the universal Mach-O binary "
519 "'%s' is not a Mach-O object or an archive",
520 O.getArchFlagName().c_str(),
523 std::string ArchFlagName =
O.getArchFlagName();
533 **ObjOrErr, MemStream))
536 auto MB = std::make_unique<SmallVectorMemoryBuffer>(
542 Slices.
emplace_back(*cast<MachOObjectFile>(Binaries.back().getBinary()),
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
std::vector< StringRef > RPathToPrepend
StringSaver NewSectionsContents
This is an optimization pass for GlobalISel generic memory operations.
DenseMap< StringRef, StringRef > InstallNamesToUpdate
LLVM_NODISCARD StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
static void markSymbols(const CommonConfig &, Object &Obj)
IndirectSymbolTable IndirectSymTable
std::function< bool(const SectionBase &Sec)> SectionPred
bool matches(StringRef S) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static ErrorSuccess success()
Create a success value.
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.
void removeSymbols(function_ref< bool(const std::unique_ptr< SymbolEntry > &)> ToRemove)
static void updateLoadCommandPayloadString(LoadCommand &LC, StringRef S)
DenseSet< StringRef > EmptySegmentsToRemove
Optional< SymbolEntry * > Symbol
The Symbol referenced by this entry.
StringMap< StringRef > SymbolsToRename
static Error dumpSectionToFile(StringRef SecName, StringRef Filename, Object &Obj)
static Error addSection(const NewSectionInfo &NewSection, Object &Obj)
OutputIt copy(R &&Range, OutputIt Out)
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Tagged union holding either a T or a Error.
Optional< uint32_t > SwiftVersion
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
void consumeError(Error Err)
Consume a Error without doing anything.
static StringRef getPayloadString(const LoadCommand &LC)
std::vector< IndirectSymbolEntry > Symbols
Optional< StringRef > getSegmentName() const
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)
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Error removeLoadCommands(function_ref< bool(const LoadCommand &)> ToRemove)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::vector< NewSectionInfo > AddSection
std::vector< StringRef > RPathToAdd
std::vector< StringRef > DumpSection
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.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
This class implements an extremely fast bulk output stream that can only output to a stream.
void updateLoadCommandIndexes()
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
std::shared_ptr< MemoryBuffer > SectionData
Optional< StringRef > SharedLibId
Optional< uint64_t > getSegmentVMAddr() const
DenseSet< StringRef > RPathsToRemove
static Error updateSection(const NewSectionInfo &NewSection, Object &O)
Implements a dense probed hash-table based set.
std::vector< std::unique_ptr< Section > > Sections
bool DeterministicArchives
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Error removeSections(function_ref< bool(const std::unique_ptr< Section > &)> ToRemove)
Expected< std::vector< NewArchiveMember > > createNewArchiveMembers(const MultiFormatConfig &Config, const Archive &Ar)
Applies the transformations described by Config to each member in archive Ar.
std::vector< LoadCommand > LoadCommands
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
MachO::macho_load_command MachOLoadCommand
static Error isValidMachOCannonicalName(StringRef Name)
LoadCommand & addSegment(StringRef SegName, uint64_t SegVMSize)
Creates a new segment load command in the object and returns a reference to the newly created load co...
static LoadCommand buildRPathLoadCommand(StringRef Path)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< bool(const LoadCommand &LC)> LoadCommandPred
static Expected< Section & > findSection(StringRef SecName, Object &O)
print Print MemDeps of function
DenseMap< StringRef, StringRef > RPathsToUpdate
StringRef - Represent a constant reference to a string, i.e.
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
static void updateAndRemoveSymbols(const CommonConfig &Config, const MachOConfig &MachOConfig, Object &Obj)
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
static 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...
std::vector< uint8_t > Payload
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
static Error handleArgs(const CommonConfig &Config, const MachOConfig &MachOConfig, Object &Obj)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Error writeUniversalBinaryToStream(ArrayRef< Slice > Slices, raw_ostream &Out)
Lightweight error class with error context and mandatory checking.
std::vector< NewSectionInfo > UpdateSection
static Error removeSections(const CommonConfig &Config, Object &Obj)
static bool isLoadCommandWithPayloadString(const LoadCommand &LC)
Error takeError()
Take ownership of the stored error.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
static Error processLoadCommands(const MachOConfig &MachOConfig, Object &Obj)
StringRef save(const char *S)
A raw_ostream that writes to an SmallVector or SmallString.
Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
bool erase(const ValueT &V)
we should consider alternate ways to model stack dependencies Lots of things could be done in WebAssemblyTargetTransformInfo cpp there are numerous optimization related hooks that can be overridden in WebAssemblyTargetLowering Instead of the OptimizeReturned which should consider preserving the returned attribute through to MachineInstrs and extending the MemIntrinsicResults pass to do this optimization on calls too That would also let the WebAssemblyPeephole pass clean up dead defs for such as it does for stores Consider implementing and or getMachineCombinerPatterns Find a clean way to fix the problem which leads to the Shrink Wrapping pass being run after the WebAssembly PEI pass When setting multiple variables to the same we currently get code like const It could be done with a smaller encoding like local tee $pop5 local copy
virtual Expected< std::unique_ptr< Object > > create() const =0
reference emplace_back(ArgTypes &&... Args)
Expected< std::unique_ptr< MemoryBuffer > > writeArchiveToBuffer(ArrayRef< NewArchiveMember > NewMembers, bool WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin)