1 //===- MachOFormat.h - Mach-O Format Structures And Constants ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares various structures and constants which are platform
11 // independent and can be shared by any client which wishes to interact with
14 // The definitions here are purposely chosen to match the LLVM style as opposed
15 // to following the platform specific definition of the format.
17 // On a Mach system, see the <mach-o/...> includes for more information, in
18 // particular <mach-o/loader.h>.
20 //===----------------------------------------------------------------------===//
22 #ifndef LLVM_OBJECT_MACHOFORMAT_H
23 #define LLVM_OBJECT_MACHOFORMAT_H
25 #include "llvm/Support/DataTypes.h"
30 /// General Mach platform information.
32 /// @name CPU Type and Subtype Information
35 /// \brief Capability bits used in CPU type encoding.
36 enum CPUTypeFlagsMask {
37 CTFM_ArchMask = 0xFF000000,
38 CTFM_ArchABI64 = 0x01000000
41 /// \brief Machine type IDs used in CPU type encoding.
44 CTM_x86_64 = CTM_i386 | CTFM_ArchABI64,
48 CTM_PowerPC64 = CTM_PowerPC | CTFM_ArchABI64
51 /// \brief Capability bits used in CPU subtype encoding.
52 enum CPUSubtypeFlagsMask {
53 CSFM_SubtypeMask = 0xFF000000,
54 CSFM_SubtypeLib64 = 0x80000000
57 /// \brief ARM Machine Subtypes.
67 /// \brief PowerPC Machine Subtypes.
68 enum CPUSubtypePowerPC {
72 /// \brief SPARC Machine Subtypes.
73 enum CPUSubtypeSPARC {
77 /// \brief x86 Machine Subtypes.
84 } // end namespace mach
86 /// Format information for Mach object files.
88 /// \brief Constants for structure sizes.
92 SegmentLoadCommand32Size = 56,
93 SegmentLoadCommand64Size = 72,
96 SymtabLoadCommandSize = 24,
97 DysymtabLoadCommandSize = 80,
100 RelocationInfoSize = 8
103 /// \brief Constants for header magic field.
105 HM_Object32 = 0xFEEDFACE, ///< 32-bit mach object file
106 HM_Object64 = 0xFEEDFACF, ///< 64-bit mach object file
107 HM_Universal = 0xCAFEBABE ///< Universal object file
110 /// \brief Header common to all Mach object files.
116 uint32_t NumLoadCommands;
117 uint32_t SizeOfLoadCommands;
121 /// \brief Extended header for 64-bit object files.
126 // See <mach-o/loader.h>.
127 enum HeaderFileType {
132 HF_SubsectionsViaSymbols = 0x2000
135 enum LoadCommandType {
139 LCT_Segment64 = 0x19,
143 /// \brief Load command structure.
149 /// @name Load Command Structures
152 struct SegmentLoadCommand {
160 uint32_t MaxVMProtection;
161 uint32_t InitialVMProtection;
162 uint32_t NumSections;
166 struct Segment64LoadCommand {
174 uint32_t MaxVMProtection;
175 uint32_t InitialVMProtection;
176 uint32_t NumSections;
180 struct SymtabLoadCommand {
183 uint32_t SymbolTableOffset;
184 uint32_t NumSymbolTableEntries;
185 uint32_t StringTableOffset;
186 uint32_t StringTableSize;
189 struct DysymtabLoadCommand {
193 uint32_t LocalSymbolIndex;
194 uint32_t NumLocalSymbols;
196 uint32_t ExternalSymbolsIndex;
197 uint32_t NumExternalSymbols;
199 uint32_t UndefinedSymbolsIndex;
200 uint32_t NumUndefinedSymbols;
203 uint32_t NumTOCEntries;
205 uint32_t ModuleTableOffset;
206 uint32_t NumModuleTableEntries;
208 uint32_t ReferenceSymbolTableOffset;
209 uint32_t NumReferencedSymbolTableEntries;
211 uint32_t IndirectSymbolTableOffset;
212 uint32_t NumIndirectSymbolTableEntries;
214 uint32_t ExternalRelocationTableOffset;
215 uint32_t NumExternalRelocationTableEntries;
217 uint32_t LocalRelocationTableOffset;
218 uint32_t NumLocalRelocationTableEntries;
222 /// @name Section Data
227 char SegmentName[16];
232 uint32_t RelocationTableOffset;
233 uint32_t NumRelocationTableEntries;
240 char SegmentName[16];
245 uint32_t RelocationTableOffset;
246 uint32_t NumRelocationTableEntries;
254 /// @name Symbol Table Entries
257 struct SymbolTableEntry {
258 uint32_t StringIndex;
260 uint8_t SectionIndex;
264 struct Symbol64TableEntry {
265 uint32_t StringIndex;
267 uint8_t SectionIndex;
273 /// @name Indirect Symbol Table
276 struct IndirectSymbolTableEntry {
281 /// @name Relocation Data
284 struct RelocationEntry {
291 // See <mach-o/nlist.h>.
292 enum SymbolTypeType {
293 STT_Undefined = 0x00,
298 enum SymbolTypeFlags {
299 // If any of these bits are set, then the entry is a stab entry number (see
300 // <mach-o/stab.h>. Otherwise the other masks apply.
301 STF_StabsEntryMask = 0xe0,
305 STF_PrivateExtern = 0x10
308 /// IndirectSymbolFlags - Flags for encoding special values in the indirect
310 enum IndirectSymbolFlags {
311 ISF_Local = 0x80000000,
312 ISF_Absolute = 0x40000000
315 /// RelocationFlags - Special flags for addresses.
316 enum RelocationFlags {
317 RF_Scattered = 0x80000000
320 enum RelocationInfoType {
324 RIT_PreboundLazyPointer = 3,
325 RIT_LocalDifference = 4,
329 /// X86_64 uses its own relocation types.
330 enum RelocationInfoTypeX86_64 {
331 RIT_X86_64_Unsigned = 0,
332 RIT_X86_64_Signed = 1,
333 RIT_X86_64_Branch = 2,
334 RIT_X86_64_GOTLoad = 3,
336 RIT_X86_64_Subtractor = 5,
337 RIT_X86_64_Signed1 = 6,
338 RIT_X86_64_Signed2 = 7,
339 RIT_X86_64_Signed4 = 8,
343 } // end namespace macho
345 } // end namespace object
346 } // end namespace llvm