39 std::forward_as_tuple(
T.getArch(),
T.getOS(),
T.getEnvironment());
42 if (
I != Container.end() && *
I ==
T)
44 return Container.emplace(
I,
T);
49 auto getOSVersionStr = [](
uint32_t V) {
58 return getOSVersionStr(Vers.version);
66 std::string OSVersion;
68 case MachO::LC_VERSION_MIN_MACOSX:
69 OSVersion = getOSVersion(cmd);
70 emplace(Triples, {Arch,
"apple",
"macos" + OSVersion});
72 case MachO::LC_VERSION_MIN_IPHONEOS:
73 OSVersion = getOSVersion(cmd);
75 emplace(Triples, {Arch,
"apple",
"ios" + OSVersion,
"simulator"});
77 emplace(Triples, {Arch,
"apple",
"ios" + OSVersion});
79 case MachO::LC_VERSION_MIN_TVOS:
80 OSVersion = getOSVersion(cmd);
82 emplace(Triples, {Arch,
"apple",
"tvos" + OSVersion,
"simulator"});
84 emplace(Triples, {Arch,
"apple",
"tvos" + OSVersion});
86 case MachO::LC_VERSION_MIN_WATCHOS:
87 OSVersion = getOSVersion(cmd);
89 emplace(Triples, {Arch,
"apple",
"watchos" + OSVersion,
"simulator"});
91 emplace(Triples, {Arch,
"apple",
"watchos" + OSVersion});
93 case MachO::LC_BUILD_VERSION: {
96 case MachO::PLATFORM_MACOS:
97 emplace(Triples, {Arch,
"apple",
"macos" + OSVersion});
99 case MachO::PLATFORM_IOS:
100 emplace(Triples, {Arch,
"apple",
"ios" + OSVersion});
102 case MachO::PLATFORM_TVOS:
103 emplace(Triples, {Arch,
"apple",
"tvos" + OSVersion});
105 case MachO::PLATFORM_WATCHOS:
106 emplace(Triples, {Arch,
"apple",
"watchos" + OSVersion});
108 case MachO::PLATFORM_BRIDGEOS:
109 emplace(Triples, {Arch,
"apple",
"bridgeos" + OSVersion});
111 case MachO::PLATFORM_MACCATALYST:
112 emplace(Triples, {Arch,
"apple",
"ios" + OSVersion,
"macabi"});
114 case MachO::PLATFORM_IOSSIMULATOR:
115 emplace(Triples, {Arch,
"apple",
"ios" + OSVersion,
"simulator"});
117 case MachO::PLATFORM_TVOSSIMULATOR:
118 emplace(Triples, {Arch,
"apple",
"tvos" + OSVersion,
"simulator"});
120 case MachO::PLATFORM_WATCHOSSIMULATOR:
121 emplace(Triples, {Arch,
"apple",
"watchos" + OSVersion,
"simulator"});
123 case MachO::PLATFORM_DRIVERKIT:
124 emplace(Triples, {Arch,
"apple",
"driverkit" + OSVersion});
139 emplace(Triples, {Arch,
"apple",
"unknown"});
146 auto &BA =
Slice.getBinaryAttrs();
148 switch (
H.filetype) {
163 BA.TwoLevelNamespace =
true;
165 BA.AppExtensionSafe =
true;
169 case MachO::LC_ID_DYLIB: {
171 BA.InstallName =
Slice.copyString(LCI.Ptr + DLLC.dylib.name);
172 BA.CurrentVersion = DLLC.dylib.current_version;
173 BA.CompatVersion = DLLC.dylib.compatibility_version;
176 case MachO::LC_REEXPORT_DYLIB: {
178 BA.RexportedLibraries.emplace_back(
179 Slice.copyString(LCI.Ptr + DLLC.dylib.name));
182 case MachO::LC_SUB_FRAMEWORK: {
184 BA.ParentUmbrella =
Slice.copyString(LCI.Ptr + SFC.umbrella);
187 case MachO::LC_SUB_CLIENT: {
189 BA.AllowableClients.emplace_back(
Slice.copyString(LCI.Ptr + SCLC.client));
192 case MachO::LC_UUID: {
194 std::stringstream Stream;
195 for (
unsigned I = 0;
I < 16; ++
I) {
196 if (
I == 4 ||
I == 6 ||
I == 8 ||
I == 10)
198 Stream << std::setfill(
'0') << std::setw(2) << std::uppercase
199 << std::hex << static_cast<int>(UUIDLC.uuid[
I]);
201 BA.UUID =
Slice.copyString(Stream.str());
204 case MachO::LC_RPATH: {
206 BA.RPaths.emplace_back(
Slice.copyString(LCI.Ptr + RPLC.path));
209 case MachO::LC_SEGMENT_SPLIT_INFO: {
211 if (SSILC.datasize == 0)
212 BA.OSLibNotForSharedCache =
true;
220 for (
auto &Sect : Obj->
sections()) {
221 auto SectName = Sect.getName();
223 return SectName.takeError();
224 if (*SectName !=
"__objc_imageinfo" && *SectName !=
"__image_info")
227 auto Content = Sect.getContents();
229 return Content.takeError();
231 if ((Content->size() >= 8) && (Content->front() == 0)) {
242 BA.SwiftABI = (Flags >> 8) & 0xFF;
251 auto parseExport = [](
const auto ExportFlags,
252 auto Addr) -> std::tuple<SymbolFlags, RecordLinkage> {
276 for (
auto &Sym : Obj->
exports(Err)) {
277 auto [Flags,
Linkage] = parseExport(Sym.flags(), Sym.address());
279 Exports[Sym.name()] = {Flags,
Linkage};
282 for (
const auto &Sym : Obj->
symbols()) {
283 auto FlagsOrErr = Sym.getFlags();
285 return FlagsOrErr.takeError();
286 auto Flags = *FlagsOrErr;
288 auto NameOrErr = Sym.getName();
290 return NameOrErr.takeError();
291 auto Name = *NameOrErr;
304 auto Exp = Exports.
find(Name);
308 if (Exp != Exports.
end())
309 std::tie(RecordFlags,
Linkage) = Exp->second;
317 auto TypeOrErr = Sym.getType();
319 return TypeOrErr.takeError();
320 auto Type = *TypeOrErr;
358 return BinOrErr.takeError();
363 Obj->getHeader().cpusubtype);
368 for (
const auto &
T : Triples) {
372 if (
auto Err =
load(Obj, *
Results.back(), Opt, Arch))
373 return std::move(Err);
381 "Expected a MachO universal binary.");
384 for (
auto OI = UB->begin_objects(), OE = UB->end_objects(); OI != OE; ++OI) {
396 auto ObjOrErr = OI->getAsObjectFile();
404 auto &Obj = *ObjOrErr.get();
405 switch (Obj.getHeader().filetype) {
413 if (
auto Err =
load(&Obj, *
Results.back(), Opt, Arch))
414 return std::move(Err);
431 return SlicesOrErr.takeError();
440 const std::unique_ptr<DWARFContext> &DiCtx) {
457 const uint64_t Address = *AddressOrErr;
459 auto TypeOrErr =
Symbol.getType();
466 auto *DWARFCU = IsCode ? DiCtx->getCompileUnitForCodeAddress(Address)
467 : DiCtx->getCompileUnitForDataAddress(Address);
471 const DWARFDie &
DIE = IsCode ? DWARFCU->getSubroutineForAddress(Address)
472 : DWARFCU->getVariableForAddress(Address);
473 const std::string File =
DIE.getDeclFile(
482 auto Name = *NameOrErr;
485 if (!File.empty() && Line != 0)
501 if (DSYMsOrErr->empty())
504 const StringRef Path = DSYMsOrErr->front();
506 if (
auto Err = BufOrErr.getError())
529 auto MachOOrErr = ObjForArch->getAsObjectFile();
534 auto &Obj = **MachOOrErr;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
Function Alias Analysis Results
static TripleVec::iterator emplace(TripleVec &Container, Triple &&T)
static SymbolToSourceLocMap accumulateLocs(MachOObjectFile &Obj, const std::unique_ptr< DWARFContext > &DiCtx)
static Error readSymbols(MachOObjectFile *Obj, RecordsSlice &Slice, const ParseOption &Opt)
static Error readMachOHeader(MachOObjectFile *Obj, RecordsSlice &Slice)
static TripleVec constructTriples(MachOObjectFile *Obj, const Architecture ArchT)
std::vector< Triple > TripleVec
static void DWARFErrorHandler(Error Err)
IntervalMap< SlotIndex, DbgVariableValue, 4 > LocMap
Map of where a user value is live to that value.
Implements the TAPI Record Collection Type.
Define TAPI specific error codes.
A structured debug information entry.
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, ProcessDebugRelocations RelocAction=ProcessDebugRelocations::Process, const LoadedObjectInfo *L=nullptr, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler, bool ThreadSafe=false)
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
bool has(Architecture Arch) const
SymbolFlags getFlags() const
StringRef getName() const
StringRef getBufferIdentifier() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
OSType getOS() const
Get the parsed operating system type of this triple.
ArchType getArch() const
Get the parsed architecture type of this triple.
EnvironmentType getEnvironment() const
Get the parsed environment type of this triple.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isLittleEndian() const
MachO::sub_client_command getSubClientCommand(const LoadCommandInfo &L) const
iterator_range< export_iterator > exports(Error &Err) const
For use iterating over all exported symbols.
MachO::build_version_command getBuildVersionLoadCommand(const LoadCommandInfo &L) const
static Expected< std::vector< std::string > > findDsymObjectMembers(StringRef Path)
If the input path is a .dSYM bundle (as created by the dsymutil tool), return the paths to the object...
MachO::rpath_command getRpathCommand(const LoadCommandInfo &L) const
MachO::sub_framework_command getSubFrameworkCommand(const LoadCommandInfo &L) const
const MachO::mach_header & getHeader() const
iterator_range< load_command_iterator > load_commands() const
MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const
MachO::version_min_command getVersionMinLoadCommand(const LoadCommandInfo &L) const
MachO::linkedit_data_command getLinkeditDataLoadCommand(const LoadCommandInfo &L) const
MachO::dylib_command getDylibIDLoadCommand(const LoadCommandInfo &L) const
section_iterator_range sections() const
symbol_iterator_range symbols() const
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Defines the MachO Dynamic Library Reader.
llvm::StringMap< RecordLoc > SymbolToSourceLocMap
LLVM_ABI Expected< Records > readFile(MemoryBufferRef Buffer, const ParseOption &Opt)
Parse Mach-O dynamic libraries to extract TAPI attributes.
LLVM_ABI SymbolToSourceLocMap accumulateSourceLocFromDSYM(const StringRef DSYM, const Target &T)
Get the source location for each symbol from dylib.
LLVM_ABI Expected< std::unique_ptr< InterfaceFile > > get(MemoryBufferRef Buffer)
Get TAPI file representation of binary dylib.
@ MachO_DynamicLibrary_Stub
MachO Dynamic Library Stub file.
@ MachO_DynamicLibrary
MachO Dynamic Library file.
@ MachO_Bundle
MachO Bundle file.
@ EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL
@ EXPORT_SYMBOL_FLAGS_KIND_REGULAR
@ EXPORT_SYMBOL_FLAGS_REEXPORT
@ EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION
@ EXPORT_SYMBOL_FLAGS_KIND_MASK
LLVM_ABI StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
LLVM_ABI PlatformType mapToPlatformType(PlatformType Platform, bool WantSim)
LLVM_ABI std::unique_ptr< InterfaceFile > convertToInterfaceFile(const Records &Slices)
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
@ ThreadLocalValue
Thread-local value symbol.
@ WeakReferenced
Weak referenced symbol.
@ WeakDefined
Weak defined symbol.
LLVM_ABI Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType)
Convert a CPU Type and Subtype pair to an architecture slice.
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.
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::little, unaligned > ulittle32_t
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::big, unaligned > ubig32_t
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void consumeError(Error Err)
Consume a Error without doing anything.
bool Undefineds
Capture undefined symbols too.
bool MachOHeader
Capture Mach-O header from binary, primarily load commands.
bool SymbolTable
Capture defined symbols out of export trie and n-list.
ArchitectureSet Archs
Determines arch slice to parse.