diff options
author | Charles Davis <cdavis5x@gmail.com> | 2013-08-27 05:00:43 +0000 |
---|---|---|
committer | Charles Davis <cdavis5x@gmail.com> | 2013-08-27 05:00:43 +0000 |
commit | 9c3dd1b0d1e96ef408b68da3b06c6ebd6c943601 (patch) | |
tree | 101d9a713b5d27848e80a81ac47fd52656445110 /include/llvm/Object | |
parent | bf778d0546a4d8814339d946ca5c7e52291cc00c (diff) | |
download | external_llvm-9c3dd1b0d1e96ef408b68da3b06c6ebd6c943601.zip external_llvm-9c3dd1b0d1e96ef408b68da3b06c6ebd6c943601.tar.gz external_llvm-9c3dd1b0d1e96ef408b68da3b06c6ebd6c943601.tar.bz2 |
Move everything depending on Object/MachOFormat.h over to Support/MachO.h.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Object')
-rw-r--r-- | include/llvm/Object/MachO.h | 87 | ||||
-rw-r--r-- | include/llvm/Object/MachOFormat.h | 452 | ||||
-rw-r--r-- | include/llvm/Object/MachOUniversal.h | 6 |
3 files changed, 48 insertions, 497 deletions
diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index caa642a..f3f391e 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -18,8 +18,8 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Triple.h" -#include "llvm/Object/MachOFormat.h" #include "llvm/Object/ObjectFile.h" +#include "llvm/Support/MachO.h" namespace llvm { namespace object { @@ -53,7 +53,7 @@ class MachOObjectFile : public ObjectFile { public: struct LoadCommandInfo { const char *Ptr; // Where in memory the load command is. - macho::LoadCommand C; // The command itself. + MachO::load_command C; // The command itself. }; MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits, @@ -146,50 +146,53 @@ public: ArrayRef<char> getSectionRawFinalSegmentName(DataRefImpl Sec) const; // MachO specific Info about relocations. - bool isRelocationScattered(const macho::RelocationEntry &RE) const; - unsigned getPlainRelocationSymbolNum(const macho::RelocationEntry &RE) const; - bool getPlainRelocationExternal(const macho::RelocationEntry &RE) const; - bool getScatteredRelocationScattered(const macho::RelocationEntry &RE) const; - uint32_t getScatteredRelocationValue(const macho::RelocationEntry &RE) const; - unsigned getAnyRelocationAddress(const macho::RelocationEntry &RE) const; - unsigned getAnyRelocationPCRel(const macho::RelocationEntry &RE) const; - unsigned getAnyRelocationLength(const macho::RelocationEntry &RE) const; - unsigned getAnyRelocationType(const macho::RelocationEntry &RE) const; - SectionRef getRelocationSection(const macho::RelocationEntry &RE) const; + bool isRelocationScattered(const MachO::any_relocation_info &RE) const; + unsigned getPlainRelocationSymbolNum( + const MachO::any_relocation_info &RE) const; + bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const; + bool getScatteredRelocationScattered( + const MachO::any_relocation_info &RE) const; + uint32_t getScatteredRelocationValue( + const MachO::any_relocation_info &RE) const; + unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const; + unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const; + unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const; + unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const; + SectionRef getRelocationSection(const MachO::any_relocation_info &RE) const; // Walk load commands. LoadCommandInfo getFirstLoadCommandInfo() const; LoadCommandInfo getNextLoadCommandInfo(const LoadCommandInfo &L) const; // MachO specific structures. - macho::Section getSection(DataRefImpl DRI) const; - macho::Section64 getSection64(DataRefImpl DRI) const; - macho::Section getSection(const LoadCommandInfo &L, unsigned Index) const; - macho::Section64 getSection64(const LoadCommandInfo &L, unsigned Index) const; - macho::SymbolTableEntry getSymbolTableEntry(DataRefImpl DRI) const; - macho::Symbol64TableEntry getSymbol64TableEntry(DataRefImpl DRI) const; - - macho::LinkeditDataLoadCommand + MachO::section getSection(DataRefImpl DRI) const; + MachO::section_64 getSection64(DataRefImpl DRI) const; + MachO::section getSection(const LoadCommandInfo &L, unsigned Index) const; + MachO::section_64 getSection64(const LoadCommandInfo &L,unsigned Index) const; + MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const; + MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const; + + MachO::linkedit_data_command getLinkeditDataLoadCommand(const LoadCommandInfo &L) const; - macho::SegmentLoadCommand + MachO::segment_command getSegmentLoadCommand(const LoadCommandInfo &L) const; - macho::Segment64LoadCommand + MachO::segment_command_64 getSegment64LoadCommand(const LoadCommandInfo &L) const; - macho::LinkerOptionsLoadCommand + MachO::linker_options_command getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const; - macho::RelocationEntry getRelocation(DataRefImpl Rel) const; - macho::DataInCodeTableEntry getDice(DataRefImpl Rel) const; - macho::Header getHeader() const; - macho::Header64Ext getHeader64Ext() const; - macho::IndirectSymbolTableEntry - getIndirectSymbolTableEntry(const macho::DysymtabLoadCommand &DLC, + MachO::any_relocation_info getRelocation(DataRefImpl Rel) const; + MachO::data_in_code_entry getDice(DataRefImpl Rel) const; + MachO::mach_header getHeader() const; + MachO::mach_header_64 getHeader64() const; + uint32_t + getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const; - macho::DataInCodeTableEntry getDataInCodeTableEntry(uint32_t DataOffset, - unsigned Index) const; - macho::SymtabLoadCommand getSymtabLoadCommand() const; - macho::DysymtabLoadCommand getDysymtabLoadCommand() const; - macho::LinkeditDataLoadCommand getDataInCodeLoadCommand() const; + MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset, + unsigned Index) const; + MachO::symtab_command getSymtabLoadCommand() const; + MachO::dysymtab_command getDysymtabLoadCommand() const; + MachO::linkedit_data_command getDataInCodeLoadCommand() const; StringRef getStringTableData() const; bool is64Bit() const; @@ -223,8 +226,8 @@ inline bool DiceRef::operator<(const DiceRef &Other) const { inline error_code DiceRef::getNext(DiceRef &Result) const { DataRefImpl Rel = DicePimpl; - const macho::DataInCodeTableEntry *P = - reinterpret_cast<const macho::DataInCodeTableEntry *>(Rel.p); + const MachO::data_in_code_entry *P = + reinterpret_cast<const MachO::data_in_code_entry *>(Rel.p); Rel.p = reinterpret_cast<uintptr_t>(P + 1); Result = DiceRef(Rel, OwningObject); return object_error::success; @@ -237,24 +240,24 @@ inline error_code DiceRef::getNext(DiceRef &Result) const { inline error_code DiceRef::getOffset(uint32_t &Result) const { const MachOObjectFile *MachOOF = static_cast<const MachOObjectFile *>(OwningObject); - macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl); - Result = Dice.Offset; + MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl); + Result = Dice.offset; return object_error::success; } inline error_code DiceRef::getLength(uint16_t &Result) const { const MachOObjectFile *MachOOF = static_cast<const MachOObjectFile *>(OwningObject); - macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl); - Result = Dice.Length; + MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl); + Result = Dice.length; return object_error::success; } inline error_code DiceRef::getKind(uint16_t &Result) const { const MachOObjectFile *MachOOF = static_cast<const MachOObjectFile *>(OwningObject); - macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl); - Result = Dice.Kind; + MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl); + Result = Dice.kind; return object_error::success; } diff --git a/include/llvm/Object/MachOFormat.h b/include/llvm/Object/MachOFormat.h deleted file mode 100644 index 2bbad0a..0000000 --- a/include/llvm/Object/MachOFormat.h +++ /dev/null @@ -1,452 +0,0 @@ -//===- MachOFormat.h - Mach-O Format Structures And Constants ---*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file declares various structures and constants which are platform -// independent and can be shared by any client which wishes to interact with -// Mach object files. -// -// The definitions here are purposely chosen to match the LLVM style as opposed -// to following the platform specific definition of the format. -// -// On a Mach system, see the <mach-o/...> includes for more information, in -// particular <mach-o/loader.h>. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_OBJECT_MACHOFORMAT_H -#define LLVM_OBJECT_MACHOFORMAT_H - -#include "llvm/Support/DataTypes.h" - -namespace llvm { -namespace object { - -/// General Mach platform information. -namespace mach { - /// @name CPU Type and Subtype Information - /// { - - /// \brief Capability bits used in CPU type encoding. - enum CPUTypeFlagsMask { - CTFM_ArchMask = 0xFF000000, - CTFM_ArchABI64 = 0x01000000 - }; - - /// \brief Machine type IDs used in CPU type encoding. - enum CPUTypeMachine { - CTM_i386 = 7, - CTM_x86_64 = CTM_i386 | CTFM_ArchABI64, - CTM_ARM = 12, - CTM_SPARC = 14, - CTM_PowerPC = 18, - CTM_PowerPC64 = CTM_PowerPC | CTFM_ArchABI64 - }; - - /// \brief Capability bits used in CPU subtype encoding. - enum CPUSubtypeFlagsMask { - CSFM_SubtypeMask = 0xFF000000, - CSFM_SubtypeLib64 = 0x80000000 - }; - - /// \brief ARM Machine Subtypes. - enum CPUSubtypeARM { - CSARM_ALL = 0, - CSARM_V4T = 5, - CSARM_V6 = 6, - CSARM_V5TEJ = 7, - CSARM_XSCALE = 8, - CSARM_V7 = 9, - CSARM_V7F = 10, - CSARM_V7S = 11, - CSARM_V7K = 12, - CSARM_V6M = 14, - CSARM_V7M = 15, - CSARM_V7EM = 16 - }; - - /// \brief PowerPC Machine Subtypes. - enum CPUSubtypePowerPC { - CSPPC_ALL = 0 - }; - - /// \brief SPARC Machine Subtypes. - enum CPUSubtypeSPARC { - CSSPARC_ALL = 0 - }; - - /// \brief x86 Machine Subtypes. - enum CPUSubtypeX86 { - CSX86_ALL = 3 - }; - - /// @} - -} // end namespace mach - -/// Format information for Mach object files. -namespace macho { - /// \brief Constants for structure sizes. - enum StructureSizes { - Header32Size = 28, - Header64Size = 32, - FatHeaderSize = 8, - FatArchHeaderSize = 20, - SegmentLoadCommand32Size = 56, - SegmentLoadCommand64Size = 72, - Section32Size = 68, - Section64Size = 80, - SymtabLoadCommandSize = 24, - DysymtabLoadCommandSize = 80, - Nlist32Size = 12, - Nlist64Size = 16, - RelocationInfoSize = 8, - LinkeditLoadCommandSize = 16 - }; - - /// \brief Constants for header magic field. - enum HeaderMagic { - HM_Object32 = 0xFEEDFACE, ///< 32-bit mach object file - HM_Object64 = 0xFEEDFACF, ///< 64-bit mach object file - HM_Universal = 0xCAFEBABE ///< Universal object file - }; - - /// \brief Header common to all Mach object files. - struct Header { - uint32_t Magic; - uint32_t CPUType; - uint32_t CPUSubtype; - uint32_t FileType; - uint32_t NumLoadCommands; - uint32_t SizeOfLoadCommands; - uint32_t Flags; - }; - - /// \brief Extended header for 64-bit object files. - struct Header64Ext { - uint32_t Reserved; - }; - - /// \brief Header for universal object files. - struct FatHeader { - uint32_t Magic; - uint32_t NumFatArch; - }; - - /// \brief Header for a single-architecture object file in a - /// universal binary. - struct FatArchHeader { - uint32_t CPUType; - uint32_t CPUSubtype; - uint32_t Offset; - uint32_t Size; - uint32_t Align; - }; - - // See <mach-o/loader.h>. - enum HeaderFileType { - HFT_Object = 0x1 - }; - - enum HeaderFlags { - HF_SubsectionsViaSymbols = 0x2000 - }; - - enum LoadCommandType { - LCT_Segment = 0x1, - LCT_Symtab = 0x2, - LCT_Dysymtab = 0xb, - LCT_Segment64 = 0x19, - LCT_UUID = 0x1b, - LCT_CodeSignature = 0x1d, - LCT_SegmentSplitInfo = 0x1e, - LCT_FunctionStarts = 0x26, - LCT_DataInCode = 0x29, - LCT_LinkerOptions = 0x2D - }; - - /// \brief Load command structure. - struct LoadCommand { - uint32_t Type; - uint32_t Size; - }; - - /// @name Load Command Structures - /// @{ - - struct SegmentLoadCommand { - uint32_t Type; - uint32_t Size; - char Name[16]; - uint32_t VMAddress; - uint32_t VMSize; - uint32_t FileOffset; - uint32_t FileSize; - uint32_t MaxVMProtection; - uint32_t InitialVMProtection; - uint32_t NumSections; - uint32_t Flags; - }; - - struct Segment64LoadCommand { - uint32_t Type; - uint32_t Size; - char Name[16]; - uint64_t VMAddress; - uint64_t VMSize; - uint64_t FileOffset; - uint64_t FileSize; - uint32_t MaxVMProtection; - uint32_t InitialVMProtection; - uint32_t NumSections; - uint32_t Flags; - }; - - struct SymtabLoadCommand { - uint32_t Type; - uint32_t Size; - uint32_t SymbolTableOffset; - uint32_t NumSymbolTableEntries; - uint32_t StringTableOffset; - uint32_t StringTableSize; - }; - - struct DysymtabLoadCommand { - uint32_t Type; - uint32_t Size; - - uint32_t LocalSymbolsIndex; - uint32_t NumLocalSymbols; - - uint32_t ExternalSymbolsIndex; - uint32_t NumExternalSymbols; - - uint32_t UndefinedSymbolsIndex; - uint32_t NumUndefinedSymbols; - - uint32_t TOCOffset; - uint32_t NumTOCEntries; - - uint32_t ModuleTableOffset; - uint32_t NumModuleTableEntries; - - uint32_t ReferenceSymbolTableOffset; - uint32_t NumReferencedSymbolTableEntries; - - uint32_t IndirectSymbolTableOffset; - uint32_t NumIndirectSymbolTableEntries; - - uint32_t ExternalRelocationTableOffset; - uint32_t NumExternalRelocationTableEntries; - - uint32_t LocalRelocationTableOffset; - uint32_t NumLocalRelocationTableEntries; - }; - - struct LinkeditDataLoadCommand { - uint32_t Type; - uint32_t Size; - uint32_t DataOffset; - uint32_t DataSize; - }; - - struct LinkerOptionsLoadCommand { - uint32_t Type; - uint32_t Size; - uint32_t Count; - // Load command is followed by Count number of zero-terminated UTF8 strings, - // and then zero-filled to be 4-byte aligned. - }; - - /// @} - /// @name Section Data - /// @{ - - enum SectionFlags { - SF_PureInstructions = 0x80000000 - }; - - struct Section { - char Name[16]; - char SegmentName[16]; - uint32_t Address; - uint32_t Size; - uint32_t Offset; - uint32_t Align; - uint32_t RelocationTableOffset; - uint32_t NumRelocationTableEntries; - uint32_t Flags; - uint32_t Reserved1; - uint32_t Reserved2; - }; - struct Section64 { - char Name[16]; - char SegmentName[16]; - uint64_t Address; - uint64_t Size; - uint32_t Offset; - uint32_t Align; - uint32_t RelocationTableOffset; - uint32_t NumRelocationTableEntries; - uint32_t Flags; - uint32_t Reserved1; - uint32_t Reserved2; - uint32_t Reserved3; - }; - - /// @} - /// @name Symbol Table Entries - /// @{ - - struct SymbolTableEntry { - uint32_t StringIndex; - uint8_t Type; - uint8_t SectionIndex; - uint16_t Flags; - uint32_t Value; - }; - // Despite containing a uint64_t, this structure is only 4-byte aligned within - // a MachO file. -#pragma pack(push) -#pragma pack(4) - struct Symbol64TableEntry { - uint32_t StringIndex; - uint8_t Type; - uint8_t SectionIndex; - uint16_t Flags; - uint64_t Value; - }; -#pragma pack(pop) - - /// @} - /// @name Data-in-code Table Entry - /// @{ - - // See <mach-o/loader.h>. - enum DataRegionType { Data = 1, JumpTable8, JumpTable16, JumpTable32 }; - struct DataInCodeTableEntry { - uint32_t Offset; /* from mach_header to start of data region */ - uint16_t Length; /* number of bytes in data region */ - uint16_t Kind; /* a DataRegionType value */ - }; - - /// @} - /// @name Indirect Symbol Table - /// @{ - - struct IndirectSymbolTableEntry { - uint32_t Index; - }; - - /// @} - /// @name Relocation Data - /// @{ - - struct RelocationEntry { - uint32_t Word0; - uint32_t Word1; - }; - - /// @} - - // See <mach-o/nlist.h>. - enum SymbolTypeType { - STT_Undefined = 0x00, - STT_Absolute = 0x02, - STT_Section = 0x0e - }; - - enum SymbolTypeFlags { - // If any of these bits are set, then the entry is a stab entry number (see - // <mach-o/stab.h>. Otherwise the other masks apply. - STF_StabsEntryMask = 0xe0, - - STF_TypeMask = 0x0e, - STF_External = 0x01, - STF_PrivateExtern = 0x10 - }; - - /// IndirectSymbolFlags - Flags for encoding special values in the indirect - /// symbol entry. - enum IndirectSymbolFlags { - ISF_Local = 0x80000000, - ISF_Absolute = 0x40000000 - }; - - /// RelocationFlags - Special flags for addresses. - enum RelocationFlags { - RF_Scattered = 0x80000000 - }; - - /// Common relocation info types. - enum RelocationInfoType { - RIT_Vanilla = 0, - RIT_Pair = 1, - RIT_Difference = 2 - }; - - /// Generic relocation info types, which are shared by some (but not all) - /// platforms. - enum RelocationInfoType_Generic { - RIT_Generic_PreboundLazyPointer = 3, - RIT_Generic_LocalDifference = 4, - RIT_Generic_TLV = 5 - }; - - /// X86_64 uses its own relocation types. - enum RelocationInfoTypeX86_64 { - // Note that x86_64 doesn't even share the common relocation types. - RIT_X86_64_Unsigned = 0, - RIT_X86_64_Signed = 1, - RIT_X86_64_Branch = 2, - RIT_X86_64_GOTLoad = 3, - RIT_X86_64_GOT = 4, - RIT_X86_64_Subtractor = 5, - RIT_X86_64_Signed1 = 6, - RIT_X86_64_Signed2 = 7, - RIT_X86_64_Signed4 = 8, - RIT_X86_64_TLV = 9 - }; - - /// ARM uses its own relocation types. - enum RelocationInfoTypeARM { - RIT_ARM_LocalDifference = 3, - RIT_ARM_PreboundLazyPointer = 4, - RIT_ARM_Branch24Bit = 5, - RIT_ARM_ThumbBranch22Bit = 6, - RIT_ARM_ThumbBranch32Bit = 7, - RIT_ARM_Half = 8, - RIT_ARM_HalfDifference = 9 - - }; - - /// PPC relocation types from <mach-o/ppc/reloc.h> - enum RelocationInfoTypePPC { - RIT_PPC_BR14 = RIT_Pair +1, - RIT_PPC_BR24, - RIT_PPC_HI16, - RIT_PPC_LO16, - RIT_PPC_HA16, - RIT_PPC_LO14, - RIT_PPC_SECTDIFF, - RIT_PPC_PB_LA_PTR, - RIT_PPC_HI16_SECTDIFF, - RIT_PPC_LO16_SECTDIFF, - RIT_PPC_HA16_SECTDIFF, - RIT_PPC_JBSR, - RIT_PPC_LO14_SECTDIFF, - RIT_PPC_LOCAL_SECTDIFF, - RIT_PPC_TLV - }; - -} // end namespace macho - -} // end namespace object -} // end namespace llvm - -#endif diff --git a/include/llvm/Object/MachOUniversal.h b/include/llvm/Object/MachOUniversal.h index 5743282..c5d1359 100644 --- a/include/llvm/Object/MachOUniversal.h +++ b/include/llvm/Object/MachOUniversal.h @@ -18,7 +18,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" #include "llvm/Object/Binary.h" -#include "llvm/Object/MachOFormat.h" +#include "llvm/Support/MachO.h" namespace llvm { namespace object { @@ -35,7 +35,7 @@ public: /// \brief Index of object in the universal binary. uint32_t Index; /// \brief Descriptor of the object. - macho::FatArchHeader Header; + MachO::fat_arch Header; public: ObjectForArch(const MachOUniversalBinary *Parent, uint32_t Index); @@ -50,7 +50,7 @@ public: } ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); } - uint32_t getCPUType() const { return Header.CPUType; } + uint32_t getCPUType() const { return Header.cputype; } error_code getAsObjectFile(OwningPtr<ObjectFile> &Result) const; }; |