//===- MachO.h - MachO object file implementation ---------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file declares the MachOObjectFile class, which implement the ObjectFile // interface for MachO files. // //===----------------------------------------------------------------------===// #ifndef LLVM_OBJECT_MACHO_H #define LLVM_OBJECT_MACHO_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/BinaryFormat/Swift.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Object/SymbolicFile.h" #include "llvm/Support/Error.h" #include "llvm/Support/Format.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/SubtargetFeature.h" #include "llvm/TargetParser/Triple.h" #include <cstdint> #include <memory> #include <string> #include <system_error> namespace llvm { namespace object { /// DiceRef - This is a value type class that represents a single /// data in code entry in the table in a Mach-O object file. class DiceRef { … }; dice_iterator; /// ExportEntry encapsulates the current-state-of-the-walk used when doing a /// non-recursive walk of the trie data structure. This allows you to iterate /// across all exported symbols using: /// Error Err = Error::success(); /// for (const llvm::object::ExportEntry &AnExport : Obj->exports(&Err)) { /// } /// if (Err) { report error ... class ExportEntry { … }; export_iterator; // Segment info so SegIndex/SegOffset pairs in a Mach-O Bind or Rebase entry // can be checked and translated. Only the SegIndex/SegOffset pairs from // checked entries are to be used with the segmentName(), sectionName() and // address() methods below. class BindRebaseSegInfo { … }; /// MachORebaseEntry encapsulates the current state in the decompression of /// rebasing opcodes. This allows you to iterate through the compressed table of /// rebasing using: /// Error Err = Error::success(); /// for (const llvm::object::MachORebaseEntry &Entry : Obj->rebaseTable(&Err)) { /// } /// if (Err) { report error ... class MachORebaseEntry { … }; rebase_iterator; /// MachOBindEntry encapsulates the current state in the decompression of /// binding opcodes. This allows you to iterate through the compressed table of /// bindings using: /// Error Err = Error::success(); /// for (const llvm::object::MachOBindEntry &Entry : Obj->bindTable(&Err)) { /// } /// if (Err) { report error ... class MachOBindEntry { … }; bind_iterator; /// ChainedFixupTarget holds all the information about an external symbol /// necessary to bind this binary to that symbol. These values are referenced /// indirectly by chained fixup binds. This structure captures values from all /// import and symbol formats. /// /// Be aware there are two notions of weak here: /// WeakImport == true /// The associated bind may be set to 0 if this symbol is missing from its /// parent library. This is called a "weak import." /// LibOrdinal == BIND_SPECIAL_DYLIB_WEAK_LOOKUP /// This symbol may be coalesced with other libraries vending the same /// symbol. E.g., C++'s "operator new". This is called a "weak bind." struct ChainedFixupTarget { … }; struct ChainedFixupsSegment { … }; /// MachOAbstractFixupEntry is an abstract class representing a fixup in a /// MH_DYLDLINK file. Fixups generally represent rebases and binds. Binds also /// subdivide into additional subtypes (weak, lazy, reexport). /// /// The two concrete subclasses of MachOAbstractFixupEntry are: /// /// MachORebaseBindEntry - for dyld opcode-based tables, including threaded- /// rebase, where rebases are mixed in with other /// bind opcodes. /// MachOChainedFixupEntry - for pointer chains embedded in data pages. class MachOAbstractFixupEntry { … }; class MachOChainedFixupEntry : public MachOAbstractFixupEntry { … }; fixup_iterator; class MachOObjectFile : public ObjectFile { … }; /// DiceRef inline DiceRef::DiceRef(DataRefImpl DiceP, const ObjectFile *Owner) : … { … } inline bool DiceRef::operator==(const DiceRef &Other) const { … } inline bool DiceRef::operator<(const DiceRef &Other) const { … } inline void DiceRef::moveNext() { … } // Since a Mach-O data in code reference, a DiceRef, can only be created when // the OwningObject ObjectFile is a MachOObjectFile a static_cast<> is used for // the methods that get the values of the fields of the reference. inline std::error_code DiceRef::getOffset(uint32_t &Result) const { … } inline std::error_code DiceRef::getLength(uint16_t &Result) const { … } inline std::error_code DiceRef::getKind(uint16_t &Result) const { … } inline DataRefImpl DiceRef::getRawDataRefImpl() const { … } inline const ObjectFile *DiceRef::getObjectFile() const { … } } // end namespace object } // end namespace llvm #endif // LLVM_OBJECT_MACHO_H