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) {
152 BA.File = FileType::MachO_DynamicLibrary;
155 BA.File = FileType::MachO_DynamicLibrary_Stub;
158 BA.File = FileType::MachO_Bundle;
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();
242 BA.SwiftABI = (Flags >> 8) & 0xFF;
251 auto parseExport = [](
const auto ExportFlags,
252 auto Addr) -> std::tuple<SymbolFlags, RecordLinkage> {
257 Flags |= SymbolFlags::WeakDefined;
260 Flags |= SymbolFlags::ThreadLocalValue;
265 ? RecordLinkage::Rexported
266 : RecordLinkage::Exported;
267 return {Flags, Linkage};
277 auto [Flags, Linkage] = parseExport(
Sym.flags(),
Sym.address());
278 Slice.addRecord(
Sym.name(), Flags, GlobalRecord::Kind::Unknown, Linkage);
279 Exports[
Sym.name()] = {Flags, Linkage};
285 return FlagsOrErr.takeError();
286 auto Flags = *FlagsOrErr;
290 return NameOrErr.takeError();
291 auto Name = *NameOrErr;
296 if (Flags & SymbolRef::SF_Undefined) {
298 Linkage = RecordLinkage::Undefined;
301 if (Flags & SymbolRef::SF_Weak)
302 RecordFlags |= SymbolFlags::WeakReferenced;
303 }
else if (Flags & SymbolRef::SF_Exported) {
308 if (Exp != Exports.
end())
309 std::tie(RecordFlags, Linkage) = Exp->second;
311 Linkage = RecordLinkage::Exported;
312 }
else if (Flags & SymbolRef::SF_Hidden) {
313 Linkage = RecordLinkage::Internal;
317 auto TypeOrErr =
Sym.getType();
319 return TypeOrErr.takeError();
320 auto Type = *TypeOrErr;
323 ? GlobalRecord::Kind::Function
324 : GlobalRecord::Kind::Variable;
326 if (GV == GlobalRecord::Kind::Function)
327 RecordFlags |= SymbolFlags::Text;
329 RecordFlags |= SymbolFlags::Data;
331 Slice.addRecord(
Name, RecordFlags, GV, Linkage);
339 return make_error<TextAPIError>(TextAPIErrorCode::UnsupportedTarget);
358 return BinOrErr.takeError();
361 if (
auto *Obj = dyn_cast<MachOObjectFile>(&
Bin)) {
363 Obj->getHeader().cpusubtype);
365 return make_error<TextAPIError>(TextAPIErrorCode::NoSuchArchitecture);
368 for (
const auto &
T : Triples) {
370 return make_error<TextAPIError>(TextAPIErrorCode::UnsupportedTarget);
373 return std::move(Err);
380 assert(isa<MachOUniversalBinary>(&
Bin) &&
381 "Expected a MachO universal binary.");
382 auto *UB = cast<MachOUniversalBinary>(&
Bin);
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) {
414 return std::move(Err);
422 return make_error<TextAPIError>(TextAPIErrorCode::EmptyResults);
431 return SlicesOrErr.takeError();
440 const std::unique_ptr<DWARFContext> &DiCtx) {
449 if (!(*FlagsOrErr & SymbolRef::SF_Exported))
459 auto TypeOrErr =
Symbol.getType();
466 auto *DWARFCU = IsCode ? DiCtx->getCompileUnitForCodeAddress(
Address)
467 : DiCtx->getCompileUnitForDataAddress(
Address);
472 : DWARFCU->getVariableForAddress(
Address);
473 const std::string File =
DIE.getDeclFile(
474 llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
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())
515 if (
auto *Single = dyn_cast<MachOObjectFile>(BinOrErr->get())) {
517 *Single, DWARFContext::ProcessDebugRelocations::Process,
nullptr,
"",
523 if (
auto *Fat = dyn_cast<MachOUniversalBinary>(BinOrErr->get())) {
529 auto MachOOrErr = ObjForArch->getAsObjectFile();
534 auto &Obj = **MachOOrErr;
536 Obj, DWARFContext::ProcessDebugRelocations::Process,
nullptr,
"",
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.
const BasicBlock & back() const
void insert(KeyT a, KeyT b, ValT y)
insert - Add a mapping of [a;b] to y, coalesce with adjacent intervals.
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,...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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_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::StringMap< RecordLoc > SymbolToSourceLocMap
LLVM_ABI Expected< std::unique_ptr< InterfaceFile > > get(MemoryBufferRef Buffer)
Get TAPI file representation of binary dylib.
@ EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL
@ EXPORT_SYMBOL_FLAGS_KIND_REGULAR
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_ABI Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType)
Convert a CPU Type and Subtype pair to an architecture slice.
@ EXPORT_SYMBOL_FLAGS_REEXPORT
@ EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION
@ EXPORT_SYMBOL_FLAGS_KIND_MASK
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.
This is an optimization pass for GlobalISel generic memory operations.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
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.