148596154Schristos /* Mach-O support for BFD.
2*1424dfb3Schristos    Copyright (C) 2011-2020 Free Software Foundation, Inc.
348596154Schristos 
448596154Schristos    This file is part of BFD, the Binary File Descriptor library.
548596154Schristos 
648596154Schristos    This program is free software; you can redistribute it and/or modify
748596154Schristos    it under the terms of the GNU General Public License as published by
848596154Schristos    the Free Software Foundation; either version 3 of the License, or
948596154Schristos    (at your option) any later version.
1048596154Schristos 
1148596154Schristos    This program is distributed in the hope that it will be useful,
1248596154Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1348596154Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1448596154Schristos    GNU General Public License for more details.
1548596154Schristos 
1648596154Schristos    You should have received a copy of the GNU General Public License
1748596154Schristos    along with this program; if not, write to the Free Software
1848596154Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1948596154Schristos    MA 02110-1301, USA.  */
2048596154Schristos 
2148596154Schristos #ifndef _MACH_O_LOADER_H
2248596154Schristos #define _MACH_O_LOADER_H
2348596154Schristos 
2448596154Schristos /* Constants for header. */
2548596154Schristos 
2648596154Schristos typedef enum bfd_mach_o_mach_header_magic
2748596154Schristos {
2848596154Schristos   BFD_MACH_O_MH_MAGIC    = 0xfeedface,
2948596154Schristos   BFD_MACH_O_MH_CIGAM    = 0xcefaedfe,
3048596154Schristos   BFD_MACH_O_MH_MAGIC_64 = 0xfeedfacf,
3148596154Schristos   BFD_MACH_O_MH_CIGAM_64 = 0xcffaedfe
3248596154Schristos }
3348596154Schristos bfd_mach_o_mach_header_magic;
3448596154Schristos 
353aab8d44Schristos /* Capability bits in cpu type.  */
363aab8d44Schristos #define BFD_MACH_O_CPU_ARCH_MASK  0xff000000
373aab8d44Schristos #define BFD_MACH_O_CPU_ARCH_ABI64 0x01000000
383aab8d44Schristos #define BFD_MACH_O_CPU_IS64BIT    0x01000000
3948596154Schristos 
4048596154Schristos typedef enum bfd_mach_o_cpu_type
4148596154Schristos {
4248596154Schristos   BFD_MACH_O_CPU_TYPE_VAX = 1,
4348596154Schristos   BFD_MACH_O_CPU_TYPE_MC680x0 = 6,
4448596154Schristos   BFD_MACH_O_CPU_TYPE_I386 = 7,
4548596154Schristos   BFD_MACH_O_CPU_TYPE_MIPS = 8,
4648596154Schristos   BFD_MACH_O_CPU_TYPE_MC98000 = 10,
4748596154Schristos   BFD_MACH_O_CPU_TYPE_HPPA = 11,
4848596154Schristos   BFD_MACH_O_CPU_TYPE_ARM = 12,
4948596154Schristos   BFD_MACH_O_CPU_TYPE_MC88000 = 13,
5048596154Schristos   BFD_MACH_O_CPU_TYPE_SPARC = 14,
5148596154Schristos   BFD_MACH_O_CPU_TYPE_I860 = 15,
5248596154Schristos   BFD_MACH_O_CPU_TYPE_ALPHA = 16,
5348596154Schristos   BFD_MACH_O_CPU_TYPE_POWERPC = 18,
543aab8d44Schristos   BFD_MACH_O_CPU_TYPE_POWERPC_64 =
553aab8d44Schristos     (BFD_MACH_O_CPU_TYPE_POWERPC | BFD_MACH_O_CPU_IS64BIT),
563aab8d44Schristos   BFD_MACH_O_CPU_TYPE_X86_64 =
573aab8d44Schristos     (BFD_MACH_O_CPU_TYPE_I386 | BFD_MACH_O_CPU_IS64BIT),
583aab8d44Schristos   BFD_MACH_O_CPU_TYPE_ARM64 =
593aab8d44Schristos     (BFD_MACH_O_CPU_TYPE_ARM | BFD_MACH_O_CPU_IS64BIT)
6048596154Schristos }
6148596154Schristos bfd_mach_o_cpu_type;
6248596154Schristos 
633aab8d44Schristos /* Capability bits in cpu subtype.  */
643aab8d44Schristos #define BFD_MACH_O_CPU_SUBTYPE_MASK  0xff000000
653aab8d44Schristos #define BFD_MACH_O_CPU_SUBTYPE_LIB64 0x80000000
663aab8d44Schristos 
6748596154Schristos typedef enum bfd_mach_o_cpu_subtype
6848596154Schristos {
6948596154Schristos   /* i386.  */
7048596154Schristos   BFD_MACH_O_CPU_SUBTYPE_X86_ALL = 3,
7148596154Schristos 
7248596154Schristos   /* arm.  */
7348596154Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM_ALL = 0,
7448596154Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM_V4T = 5,
7548596154Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM_V6 = 6,
7648596154Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM_V5TEJ = 7,
7748596154Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM_XSCALE = 8,
78c03b94e9Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM_V7 = 9,
79c03b94e9Schristos 
80c03b94e9Schristos   /* arm64.  */
81c03b94e9Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM64_ALL = 0,
82c03b94e9Schristos   BFD_MACH_O_CPU_SUBTYPE_ARM64_V8 = 1
8348596154Schristos }
8448596154Schristos bfd_mach_o_cpu_subtype;
8548596154Schristos 
8648596154Schristos typedef enum bfd_mach_o_filetype
8748596154Schristos {
8848596154Schristos   BFD_MACH_O_MH_OBJECT      = 0x01,
8948596154Schristos   BFD_MACH_O_MH_EXECUTE     = 0x02,
9048596154Schristos   BFD_MACH_O_MH_FVMLIB      = 0x03,
9148596154Schristos   BFD_MACH_O_MH_CORE        = 0x04,
9248596154Schristos   BFD_MACH_O_MH_PRELOAD     = 0x05,
9348596154Schristos   BFD_MACH_O_MH_DYLIB       = 0x06,
9448596154Schristos   BFD_MACH_O_MH_DYLINKER    = 0x07,
9548596154Schristos   BFD_MACH_O_MH_BUNDLE      = 0x08,
9648596154Schristos   BFD_MACH_O_MH_DYLIB_STUB  = 0x09,
9748596154Schristos   BFD_MACH_O_MH_DSYM        = 0x0a,
9848596154Schristos   BFD_MACH_O_MH_KEXT_BUNDLE = 0x0b
9948596154Schristos }
10048596154Schristos bfd_mach_o_filetype;
10148596154Schristos 
10248596154Schristos typedef enum bfd_mach_o_header_flags
10348596154Schristos {
10448596154Schristos   BFD_MACH_O_MH_NOUNDEFS		= 0x0000001,
10548596154Schristos   BFD_MACH_O_MH_INCRLINK		= 0x0000002,
10648596154Schristos   BFD_MACH_O_MH_DYLDLINK		= 0x0000004,
10748596154Schristos   BFD_MACH_O_MH_BINDATLOAD		= 0x0000008,
10848596154Schristos   BFD_MACH_O_MH_PREBOUND		= 0x0000010,
10948596154Schristos   BFD_MACH_O_MH_SPLIT_SEGS		= 0x0000020,
11048596154Schristos   BFD_MACH_O_MH_LAZY_INIT		= 0x0000040,
11148596154Schristos   BFD_MACH_O_MH_TWOLEVEL		= 0x0000080,
11248596154Schristos   BFD_MACH_O_MH_FORCE_FLAT		= 0x0000100,
11348596154Schristos   BFD_MACH_O_MH_NOMULTIDEFS		= 0x0000200,
11448596154Schristos   BFD_MACH_O_MH_NOFIXPREBINDING		= 0x0000400,
11548596154Schristos   BFD_MACH_O_MH_PREBINDABLE		= 0x0000800,
11648596154Schristos   BFD_MACH_O_MH_ALLMODSBOUND		= 0x0001000,
11748596154Schristos   BFD_MACH_O_MH_SUBSECTIONS_VIA_SYMBOLS = 0x0002000,
11848596154Schristos   BFD_MACH_O_MH_CANONICAL		= 0x0004000,
11948596154Schristos   BFD_MACH_O_MH_WEAK_DEFINES		= 0x0008000,
12048596154Schristos   BFD_MACH_O_MH_BINDS_TO_WEAK		= 0x0010000,
12148596154Schristos   BFD_MACH_O_MH_ALLOW_STACK_EXECUTION	= 0x0020000,
12248596154Schristos   BFD_MACH_O_MH_ROOT_SAFE		= 0x0040000,
12348596154Schristos   BFD_MACH_O_MH_SETUID_SAFE		= 0x0080000,
12448596154Schristos   BFD_MACH_O_MH_NO_REEXPORTED_DYLIBS	= 0x0100000,
12548596154Schristos   BFD_MACH_O_MH_PIE			= 0x0200000,
12648596154Schristos   BFD_MACH_O_MH_DEAD_STRIPPABLE_DYLIB   = 0x0400000,
12748596154Schristos   BFD_MACH_O_MH_HAS_TLV_DESCRIPTORS     = 0x0800000,
128c03b94e9Schristos   BFD_MACH_O_MH_NO_HEAP_EXECUTION       = 0x1000000,
129c03b94e9Schristos   BFD_MACH_O_MH_APP_EXTENSION_SAFE      = 0x2000000
13048596154Schristos }
13148596154Schristos bfd_mach_o_header_flags;
13248596154Schristos 
13348596154Schristos /* Load command constants.  */
13448596154Schristos #define BFD_MACH_O_LC_REQ_DYLD 0x80000000
13548596154Schristos 
13648596154Schristos typedef enum bfd_mach_o_load_command_type
13748596154Schristos {
13848596154Schristos   BFD_MACH_O_LC_SEGMENT = 0x1,		/* File segment to be mapped.  */
13948596154Schristos   BFD_MACH_O_LC_SYMTAB = 0x2,		/* Link-edit stab symbol table info (obsolete).  */
14048596154Schristos   BFD_MACH_O_LC_SYMSEG = 0x3,		/* Link-edit gdb symbol table info.  */
14148596154Schristos   BFD_MACH_O_LC_THREAD = 0x4,		/* Thread.  */
14248596154Schristos   BFD_MACH_O_LC_UNIXTHREAD = 0x5,	/* UNIX thread (includes a stack).  */
14348596154Schristos   BFD_MACH_O_LC_LOADFVMLIB = 0x6,	/* Load a fixed VM shared library.  */
14448596154Schristos   BFD_MACH_O_LC_IDFVMLIB = 0x7,		/* Fixed VM shared library id.  */
14548596154Schristos   BFD_MACH_O_LC_IDENT = 0x8,		/* Object identification information (obsolete).  */
14648596154Schristos   BFD_MACH_O_LC_FVMFILE = 0x9,		/* Fixed VM file inclusion.  */
14748596154Schristos   BFD_MACH_O_LC_PREPAGE = 0xa,		/* Prepage command (internal use).  */
14848596154Schristos   BFD_MACH_O_LC_DYSYMTAB = 0xb,		/* Dynamic link-edit symbol table info.  */
14948596154Schristos   BFD_MACH_O_LC_LOAD_DYLIB = 0xc,	/* Load a dynamically linked shared library.  */
15048596154Schristos   BFD_MACH_O_LC_ID_DYLIB = 0xd,		/* Dynamically linked shared lib identification.  */
15148596154Schristos   BFD_MACH_O_LC_LOAD_DYLINKER = 0xe,	/* Load a dynamic linker.  */
15248596154Schristos   BFD_MACH_O_LC_ID_DYLINKER = 0xf,	/* Dynamic linker identification.  */
15348596154Schristos   BFD_MACH_O_LC_PREBOUND_DYLIB = 0x10,	/* Modules prebound for a dynamically.  */
15448596154Schristos   BFD_MACH_O_LC_ROUTINES = 0x11,	/* Image routines.  */
15548596154Schristos   BFD_MACH_O_LC_SUB_FRAMEWORK = 0x12,	/* Sub framework.  */
15648596154Schristos   BFD_MACH_O_LC_SUB_UMBRELLA = 0x13,	/* Sub umbrella.  */
15748596154Schristos   BFD_MACH_O_LC_SUB_CLIENT = 0x14,	/* Sub client.  */
15848596154Schristos   BFD_MACH_O_LC_SUB_LIBRARY = 0x15,   	/* Sub library.  */
15948596154Schristos   BFD_MACH_O_LC_TWOLEVEL_HINTS = 0x16,	/* Two-level namespace lookup hints.  */
16048596154Schristos   BFD_MACH_O_LC_PREBIND_CKSUM = 0x17, 	/* Prebind checksum.  */
16148596154Schristos   /* Load a dynamically linked shared library that is allowed to be
16248596154Schristos        missing (weak).  */
16348596154Schristos   BFD_MACH_O_LC_LOAD_WEAK_DYLIB = 0x18,
16448596154Schristos   BFD_MACH_O_LC_SEGMENT_64 = 0x19,		/* 64-bit segment of this file to be
16548596154Schristos 						   mapped.  */
16648596154Schristos   BFD_MACH_O_LC_ROUTINES_64 = 0x1a,     	/* Address of the dyld init routine
16748596154Schristos 						   in a dylib.  */
16848596154Schristos   BFD_MACH_O_LC_UUID = 0x1b,            	/* 128-bit UUID of the executable.  */
16948596154Schristos   BFD_MACH_O_LC_RPATH = 0x1c,			/* Run path addiions.  */
17048596154Schristos   BFD_MACH_O_LC_CODE_SIGNATURE = 0x1d,		/* Local of code signature.  */
17148596154Schristos   BFD_MACH_O_LC_SEGMENT_SPLIT_INFO = 0x1e,	/* Local of info to split seg.  */
17248596154Schristos   BFD_MACH_O_LC_REEXPORT_DYLIB = 0x1f,		/* Load and re-export lib.  */
17348596154Schristos   BFD_MACH_O_LC_LAZY_LOAD_DYLIB = 0x20,		/* Delay load of lib until use.  */
17448596154Schristos   BFD_MACH_O_LC_ENCRYPTION_INFO = 0x21,		/* Encrypted segment info.  */
17548596154Schristos   BFD_MACH_O_LC_DYLD_INFO = 0x22,		/* Compressed dyld information.  */
17648596154Schristos   BFD_MACH_O_LC_LOAD_UPWARD_DYLIB = 0x23,	/* Load upward dylib.  */
17707163879Schristos   BFD_MACH_O_LC_VERSION_MIN_MACOSX = 0x24,	/* Minimal macOS version.  */
17807163879Schristos   BFD_MACH_O_LC_VERSION_MIN_IPHONEOS = 0x25,	/* Minimal iOS version.  */
17948596154Schristos   BFD_MACH_O_LC_FUNCTION_STARTS = 0x26,  	/* Compressed table of func start.  */
18048596154Schristos   BFD_MACH_O_LC_DYLD_ENVIRONMENT = 0x27, 	/* Env variable string for dyld.  */
18148596154Schristos   BFD_MACH_O_LC_MAIN = 0x28,             	/* Entry point.  */
18248596154Schristos   BFD_MACH_O_LC_DATA_IN_CODE = 0x29,     	/* Table of non-instructions.  */
18348596154Schristos   BFD_MACH_O_LC_SOURCE_VERSION = 0x2a,   	/* Source version.  */
184c03b94e9Schristos   BFD_MACH_O_LC_DYLIB_CODE_SIGN_DRS = 0x2b,	/* DRs from dylibs.  */
185c03b94e9Schristos   BFD_MACH_O_LC_ENCRYPTION_INFO_64 = 0x2c,	/* Encrypted 64 bit seg info.  */
186c03b94e9Schristos   BFD_MACH_O_LC_LINKER_OPTIONS = 0x2d,		/* Linker options.  */
187c03b94e9Schristos   BFD_MACH_O_LC_LINKER_OPTIMIZATION_HINT = 0x2e,/* Optimization hints.  */
18807163879Schristos   BFD_MACH_O_LC_VERSION_MIN_TVOS = 0x2f,	/* Minimal tvOS version.  */
18907163879Schristos   BFD_MACH_O_LC_VERSION_MIN_WATCHOS = 0x30,	/* Minimal watchOS version.  */
19007163879Schristos   BFD_MACH_O_LC_NOTE = 0x31,			/* Region of arbitrary data.  */
19107163879Schristos   BFD_MACH_O_LC_BUILD_VERSION = 0x32,		/* Generic build version.  */
192*1424dfb3Schristos   BFD_MACH_O_LC_DYLD_EXPORTS_TRIE = 0x33,	/* Exports trie. */
193*1424dfb3Schristos   BFD_MACH_O_LC_DYLD_CHAINED_FIXUPS = 0x34,	/* Chained fixups. */
19448596154Schristos }
19548596154Schristos bfd_mach_o_load_command_type;
19648596154Schristos 
19748596154Schristos /* Section constants.  */
19848596154Schristos /* Constants for the type of a section.  */
19948596154Schristos 
20048596154Schristos typedef enum bfd_mach_o_section_type
20148596154Schristos {
20248596154Schristos   /* Regular section.  */
20348596154Schristos   BFD_MACH_O_S_REGULAR = 0x0,
20448596154Schristos 
20548596154Schristos   /* Zero fill on demand section.  */
20648596154Schristos   BFD_MACH_O_S_ZEROFILL = 0x1,
20748596154Schristos 
20848596154Schristos   /* Section with only literal C strings.  */
20948596154Schristos   BFD_MACH_O_S_CSTRING_LITERALS = 0x2,
21048596154Schristos 
21148596154Schristos   /* Section with only 4 byte literals.  */
21248596154Schristos   BFD_MACH_O_S_4BYTE_LITERALS = 0x3,
21348596154Schristos 
21448596154Schristos   /* Section with only 8 byte literals.  */
21548596154Schristos   BFD_MACH_O_S_8BYTE_LITERALS = 0x4,
21648596154Schristos 
21748596154Schristos   /* Section with only pointers to literals.  */
21848596154Schristos   BFD_MACH_O_S_LITERAL_POINTERS = 0x5,
21948596154Schristos 
22048596154Schristos   /* For the two types of symbol pointers sections and the symbol stubs
22148596154Schristos      section they have indirect symbol table entries.  For each of the
22248596154Schristos      entries in the section the indirect symbol table entries, in
22348596154Schristos      corresponding order in the indirect symbol table, start at the index
22448596154Schristos      stored in the reserved1 field of the section structure.  Since the
22548596154Schristos      indirect symbol table entries correspond to the entries in the
22648596154Schristos      section the number of indirect symbol table entries is inferred from
22748596154Schristos      the size of the section divided by the size of the entries in the
22848596154Schristos      section.  For symbol pointers sections the size of the entries in
22948596154Schristos      the section is 4 bytes and for symbol stubs sections the byte size
23048596154Schristos      of the stubs is stored in the reserved2 field of the section
23148596154Schristos      structure.  */
23248596154Schristos 
23348596154Schristos   /* Section with only non-lazy symbol pointers.  */
23448596154Schristos   BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS = 0x6,
23548596154Schristos 
23648596154Schristos   /* Section with only lazy symbol pointers.  */
23748596154Schristos   BFD_MACH_O_S_LAZY_SYMBOL_POINTERS = 0x7,
23848596154Schristos 
23948596154Schristos   /* Section with only symbol stubs, byte size of stub in the reserved2
24048596154Schristos      field.  */
24148596154Schristos   BFD_MACH_O_S_SYMBOL_STUBS = 0x8,
24248596154Schristos 
24348596154Schristos   /* Section with only function pointers for initialization.  */
24448596154Schristos   BFD_MACH_O_S_MOD_INIT_FUNC_POINTERS = 0x9,
24548596154Schristos 
24648596154Schristos   /* Section with only function pointers for termination.  */
24748596154Schristos   BFD_MACH_O_S_MOD_FINI_FUNC_POINTERS = 0xa,
24848596154Schristos 
24948596154Schristos   /* Section contains symbols that are coalesced by the linkers.  */
25048596154Schristos   BFD_MACH_O_S_COALESCED = 0xb,
25148596154Schristos 
25248596154Schristos   /* Zero fill on demand section (possibly larger than 4 GB).  */
25348596154Schristos   BFD_MACH_O_S_GB_ZEROFILL = 0xc,
25448596154Schristos 
25548596154Schristos   /* Section with only pairs of function pointers for interposing.  */
25648596154Schristos   BFD_MACH_O_S_INTERPOSING = 0xd,
25748596154Schristos 
25848596154Schristos   /* Section with only 16 byte literals.  */
25948596154Schristos   BFD_MACH_O_S_16BYTE_LITERALS = 0xe,
26048596154Schristos 
26148596154Schristos   /* Section contains DTrace Object Format.  */
26248596154Schristos   BFD_MACH_O_S_DTRACE_DOF = 0xf,
26348596154Schristos 
26448596154Schristos   /* Section with only lazy symbol pointers to lazy loaded dylibs.  */
26548596154Schristos   BFD_MACH_O_S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10
26648596154Schristos }
26748596154Schristos bfd_mach_o_section_type;
26848596154Schristos 
26948596154Schristos /* The flags field of a section structure is separated into two parts a section
27048596154Schristos    type and section attributes.  The section types are mutually exclusive (it
27148596154Schristos    can only have one type) but the section attributes are not (it may have more
27248596154Schristos    than one attribute).  */
27348596154Schristos 
27448596154Schristos #define BFD_MACH_O_SECTION_TYPE_MASK        0x000000ff
27548596154Schristos 
27648596154Schristos /* Constants for the section attributes part of the flags field of a section
27748596154Schristos    structure.  */
27848596154Schristos #define BFD_MACH_O_SECTION_ATTRIBUTES_MASK  0xffffff00
27948596154Schristos /* System setable attributes.  */
28048596154Schristos #define BFD_MACH_O_SECTION_ATTRIBUTES_SYS   0x00ffff00
28148596154Schristos /* User attributes.  */
28248596154Schristos #define BFD_MACH_O_SECTION_ATTRIBUTES_USR   0xff000000
28348596154Schristos 
28448596154Schristos typedef enum bfd_mach_o_section_attribute
28548596154Schristos {
28648596154Schristos   /* Section has no specified attibutes.  */
28748596154Schristos   BFD_MACH_O_S_ATTR_NONE              = 0,
28848596154Schristos 
28948596154Schristos   /* Section has local relocation entries.  */
29048596154Schristos   BFD_MACH_O_S_ATTR_LOC_RELOC         = 0x00000100,
29148596154Schristos 
29248596154Schristos   /* Section has external relocation entries.  */
29348596154Schristos   BFD_MACH_O_S_ATTR_EXT_RELOC         = 0x00000200,
29448596154Schristos 
29548596154Schristos   /* Section contains some machine instructions.  */
29648596154Schristos   BFD_MACH_O_S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
29748596154Schristos 
29848596154Schristos   /* A debug section.  */
29948596154Schristos   BFD_MACH_O_S_ATTR_DEBUG             = 0x02000000,
30048596154Schristos 
30148596154Schristos   /* Used with i386 stubs.  */
30248596154Schristos   BFD_MACH_O_S_SELF_MODIFYING_CODE    = 0x04000000,
30348596154Schristos 
30448596154Schristos   /* Blocks are live if they reference live blocks.  */
30548596154Schristos   BFD_MACH_O_S_ATTR_LIVE_SUPPORT      = 0x08000000,
30648596154Schristos 
30748596154Schristos   /* No dead stripping.  */
30848596154Schristos   BFD_MACH_O_S_ATTR_NO_DEAD_STRIP     = 0x10000000,
30948596154Schristos 
31048596154Schristos   /* Section symbols can be stripped in files with MH_DYLDLINK flag.  */
31148596154Schristos   BFD_MACH_O_S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
31248596154Schristos 
31348596154Schristos   /* Section contains coalesced symbols that are not to be in the TOC of an
31448596154Schristos      archive.  */
31548596154Schristos   BFD_MACH_O_S_ATTR_NO_TOC            = 0x40000000,
31648596154Schristos 
31748596154Schristos   /* Section contains only true machine instructions.  */
31848596154Schristos   BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS = 0x80000000
31948596154Schristos }
32048596154Schristos bfd_mach_o_section_attribute;
32148596154Schristos 
32248596154Schristos /* Symbol constants.  */
32348596154Schristos 
32448596154Schristos /* Symbol n_type values.  */
32548596154Schristos #define BFD_MACH_O_N_STAB  0xe0	/* If any of these bits set, a symbolic debugging entry.  */
32648596154Schristos #define BFD_MACH_O_N_PEXT  0x10	/* Private external symbol bit.  */
32748596154Schristos #define BFD_MACH_O_N_TYPE  0x0e	/* Mask for the type bits.  */
32848596154Schristos #define BFD_MACH_O_N_EXT   0x01	/* External symbol bit, set for external symbols.  */
32948596154Schristos #define BFD_MACH_O_N_UNDF  0x00	/* Undefined, n_sect == NO_SECT.  */
33048596154Schristos #define BFD_MACH_O_N_ABS   0x02	/* Absolute, n_sect == NO_SECT.  */
33148596154Schristos #define BFD_MACH_O_N_INDR  0x0a	/* Indirect.  */
33248596154Schristos #define BFD_MACH_O_N_PBUD  0x0c /* Prebound undefined (defined in a dylib).  */
33348596154Schristos #define BFD_MACH_O_N_SECT  0x0e	/* Defined in section number n_sect.  */
33448596154Schristos 
33548596154Schristos #define BFD_MACH_O_NO_SECT 0	/* Symbol not in any section of the image.  */
33648596154Schristos 
33748596154Schristos /* Symbol n_desc reference flags.  */
33848596154Schristos #define BFD_MACH_O_REFERENCE_MASK 				0x07
33948596154Schristos #define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_NON_LAZY		0x00
34048596154Schristos #define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_LAZY		0x01
34148596154Schristos #define BFD_MACH_O_REFERENCE_FLAG_DEFINED			0x02
34248596154Schristos #define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_DEFINED		0x03
34348596154Schristos #define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY	0x04
34448596154Schristos #define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY	0x05
34548596154Schristos 
34648596154Schristos #define BFD_MACH_O_REFERENCED_DYNAMICALLY			0x10
34748596154Schristos #define BFD_MACH_O_N_DESC_DISCARDED				0x20
34848596154Schristos #define BFD_MACH_O_N_NO_DEAD_STRIP				0x20
34948596154Schristos #define BFD_MACH_O_N_WEAK_REF					0x40
35048596154Schristos #define BFD_MACH_O_N_WEAK_DEF					0x80
35148596154Schristos #define BFD_MACH_O_N_REF_TO_WEAK				0x80
35248596154Schristos 
35348596154Schristos #define BFD_MACH_O_N_ARM_THUMB_DEF				0x08
35448596154Schristos #define BFD_MACH_O_N_SYMBOL_RESOLVER				0x100
35548596154Schristos 
35648596154Schristos #define BFD_MACH_O_INDIRECT_SYM_LOCAL			0x80000000
35748596154Schristos #define BFD_MACH_O_INDIRECT_SYM_ABS			0x40000000
35848596154Schristos 
3593aab8d44Schristos /* Constants for dyld info rebase.  */
3603aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_MASK     0xf0
3613aab8d44Schristos #define BFD_MACH_O_REBASE_IMMEDIATE_MASK  0x0f
3623aab8d44Schristos 
3633aab8d44Schristos /* The rebase opcodes.  */
3643aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_DONE                               0x00
3653aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_SET_TYPE_IMM                       0x10
3663aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB        0x20
3673aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_ADD_ADDR_ULEB                      0x30
3683aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_ADD_ADDR_IMM_SCALED                0x40
3693aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_DO_REBASE_IMM_TIMES                0x50
3703aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES               0x60
3713aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB            0x70
3723aab8d44Schristos #define BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
3733aab8d44Schristos 
3743aab8d44Schristos /* The rebase type.  */
3753aab8d44Schristos #define BFD_MACH_O_REBASE_TYPE_POINTER            1
3763aab8d44Schristos #define BFD_MACH_O_REBASE_TYPE_TEXT_ABSOLUTE32    2
3773aab8d44Schristos #define BFD_MACH_O_REBASE_TYPE_TEXT_PCREL32       3
3783aab8d44Schristos 
3793aab8d44Schristos /* Constants for dyld info bind.  */
3803aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_MASK    0xf0
3813aab8d44Schristos #define BFD_MACH_O_BIND_IMMEDIATE_MASK 0x0f
3823aab8d44Schristos 
3833aab8d44Schristos /* The bind opcodes.  */
3843aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_DONE                   	      	 0x00
3853aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_SET_DYLIB_ORDINAL_IMM  	      	 0x10
3863aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 	      	 0x20
3873aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_SET_DYLIB_SPECIAL_IMM  	      	 0x30
3883aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 	 0x40
3893aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_SET_TYPE_IMM                  	 0x50
3903aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_SET_ADDEND_SLEB               	 0x60
3913aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB   	 0x70
3923aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_ADD_ADDR_ULEB                 	 0x80
3933aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_DO_BIND                       	 0x90
3943aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB         	 0xa0
3953aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED   	 0xb0
3963aab8d44Schristos #define BFD_MACH_O_BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xc0
3973aab8d44Schristos 
3983aab8d44Schristos /* The bind types.  */
3993aab8d44Schristos #define BFD_MACH_O_BIND_TYPE_POINTER            1
4003aab8d44Schristos #define BFD_MACH_O_BIND_TYPE_TEXT_ABSOLUTE32    2
4013aab8d44Schristos #define BFD_MACH_O_BIND_TYPE_TEXT_PCREL32       3
4023aab8d44Schristos 
4033aab8d44Schristos /* The special dylib.  */
4043aab8d44Schristos #define BFD_MACH_O_BIND_SPECIAL_DYLIB_SELF             0
4053aab8d44Schristos #define BFD_MACH_O_BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
4063aab8d44Schristos #define BFD_MACH_O_BIND_SPECIAL_DYLIB_FLAT_LOOKUP     -2
4073aab8d44Schristos 
4083aab8d44Schristos /* Constants for dyld info export.  */
4093aab8d44Schristos #define BFD_MACH_O_EXPORT_SYMBOL_FLAGS_KIND_MASK            0x03
4103aab8d44Schristos #define BFD_MACH_O_EXPORT_SYMBOL_FLAGS_KIND_REGULAR         0x00
4113aab8d44Schristos #define BFD_MACH_O_EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL    0x01
4123aab8d44Schristos #define BFD_MACH_O_EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION      0x04
4133aab8d44Schristos #define BFD_MACH_O_EXPORT_SYMBOL_FLAGS_REEXPORT             0x08
4143aab8d44Schristos #define BFD_MACH_O_EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER    0x10
4153aab8d44Schristos 
41648596154Schristos /* Constants for DATA_IN_CODE entries.  */
41748596154Schristos typedef enum bfd_mach_o_data_in_code_entry_kind
41848596154Schristos {
41948596154Schristos   BFD_MACH_O_DICE_KIND_DATA         = 0x0001, /* Data */
42048596154Schristos   BFD_MACH_O_DICE_JUMP_TABLES8      = 0x0002, /* 1 byte jump tables.  */
42148596154Schristos   BFD_MACH_O_DICE_JUMP_TABLES16     = 0x0003, /* 2 bytes.  */
42248596154Schristos   BFD_MACH_O_DICE_JUMP_TABLES32     = 0x0004, /* 4 bytes.  */
42348596154Schristos   BFD_MACH_O_DICE_ABS_JUMP_TABLES32 = 0x0005  /* Absolute jump table.  */
42448596154Schristos } bfd_mach_o_data_in_code_entry_kind;
42548596154Schristos 
42648596154Schristos /* Thread constants.  */
42748596154Schristos 
42848596154Schristos typedef enum bfd_mach_o_ppc_thread_flavour
42948596154Schristos {
43048596154Schristos   BFD_MACH_O_PPC_THREAD_STATE      = 1,
43148596154Schristos   BFD_MACH_O_PPC_FLOAT_STATE       = 2,
43248596154Schristos   BFD_MACH_O_PPC_EXCEPTION_STATE   = 3,
43348596154Schristos   BFD_MACH_O_PPC_VECTOR_STATE      = 4,
43448596154Schristos   BFD_MACH_O_PPC_THREAD_STATE64    = 5,
43548596154Schristos   BFD_MACH_O_PPC_EXCEPTION_STATE64 = 6,
43648596154Schristos   BFD_MACH_O_PPC_THREAD_STATE_NONE = 7
43748596154Schristos }
43848596154Schristos bfd_mach_o_ppc_thread_flavour;
43948596154Schristos 
44048596154Schristos /* Defined in <mach/i386/thread_status.h> */
44148596154Schristos typedef enum bfd_mach_o_i386_thread_flavour
44248596154Schristos {
44348596154Schristos   BFD_MACH_O_x86_THREAD_STATE32    = 1,
44448596154Schristos   BFD_MACH_O_x86_FLOAT_STATE32     = 2,
44548596154Schristos   BFD_MACH_O_x86_EXCEPTION_STATE32 = 3,
44648596154Schristos   BFD_MACH_O_x86_THREAD_STATE64    = 4,
44748596154Schristos   BFD_MACH_O_x86_FLOAT_STATE64     = 5,
44848596154Schristos   BFD_MACH_O_x86_EXCEPTION_STATE64 = 6,
44948596154Schristos   BFD_MACH_O_x86_THREAD_STATE      = 7,
45048596154Schristos   BFD_MACH_O_x86_FLOAT_STATE       = 8,
45148596154Schristos   BFD_MACH_O_x86_EXCEPTION_STATE   = 9,
45248596154Schristos   BFD_MACH_O_x86_DEBUG_STATE32     = 10,
45348596154Schristos   BFD_MACH_O_x86_DEBUG_STATE64     = 11,
45448596154Schristos   BFD_MACH_O_x86_DEBUG_STATE       = 12,
45548596154Schristos   BFD_MACH_O_x86_THREAD_STATE_NONE = 13
45648596154Schristos }
45748596154Schristos bfd_mach_o_i386_thread_flavour;
45848596154Schristos 
45948596154Schristos #endif /* _MACH_O_LOADER_H */
460