[Mach-O] Add new definitions from Darwin 12

Tristan Gingold gingold@adacore.com
Wed Nov 14 10:45:00 GMT 2012


Hi,

Mountain Lion has added a few new features for its Mach-O binary file format.
This patch adds the definitions for bfd.

Committed on trunk.

Tristan.

2012-11-14  Tristan Gingold  <gingold@adacore.com>

	* external.h (mach_o_entry_point_command_external)
	(mach_o_source_version_command_external)
	(mach_o_data_in_code_entry_external): New structures.

	* loader.h (bfd_mach_o_load_command_type): Add
	BFD_MACH_O_LC_MAIN, BFD_MACH_O_LC_DATA_IN_CODE,
	BFD_MACH_O_LC_SOURCE_VERSION and	BFD_MACH_O_LC_DYLIB_CODE_SIGN_DRS.
	(BFD_MACH_O_REFERENCE_MASK): Adjust value.
	(BFD_MACH_O_N_REF_TO_WEAK): New definition.
	(BFD_MACH_O_N_ARM_THUMB_DEF, BFD_MACH_O_N_SYMBOL_RESOLVER): Likewise.
	(bfd_mach_o_data_in_code_entry_kind): New enum.

Index: external.h
===================================================================
RCS file: /cvs/src/src/include/mach-o/external.h,v
retrieving revision 1.5
diff -c -r1.5 external.h
*** external.h	23 Feb 2012 16:29:56 -0000	1.5
--- external.h	14 Nov 2012 10:44:29 -0000
***************
*** 124,130 ****
  #define BFD_MACH_O_SR_SCATTERED		0x80000000
  
  /* For a non-scattered reloc, the relocation info is found in r_symbolnum.
!    Bytes 1 to 3 contain the symbol number (0xffffff, in a non-scattered PAIR).  
     Byte 4 contains the relocation info - but with differing bit-positions
     dependent on target endian-ness - as below.  */
  
--- 124,130 ----
  #define BFD_MACH_O_SR_SCATTERED		0x80000000
  
  /* For a non-scattered reloc, the relocation info is found in r_symbolnum.
!    Bytes 1 to 3 contain the symbol number (0xffffff, in a non-scattered PAIR).
     Byte 4 contains the relocation info - but with differing bit-positions
     dependent on target endian-ness - as below.  */
  
***************
*** 308,313 ****
--- 308,335 ----
    unsigned char header_addr[4];
  };
  
+ struct mach_o_entry_point_command_external
+ {
+   unsigned char entryoff[8];	/* File offset of the entry point.  */
+   unsigned char stacksize[8];   /* Initial stack size, if no null.  */
+ };
+ 
+ struct mach_o_source_version_command_external
+ {
+   unsigned char version[8];	/* Version A.B.C.D.E, with 10 bits for B-E,
+ 				   and 24 bits for A.  */
+ };
+ 
+ /* The LD_DATA_IN_CODE command use a linkedit_data_command that points to
+    a table of entries.  */
+ 
+ struct mach_o_data_in_code_entry_external
+ {
+   unsigned char offset[4];	/* Offset from the mach_header. */
+   unsigned char length[2];	/* Number of bytes.  */
+   unsigned char kind[2];	/* Kind.  See BFD_MACH_O_DICE_ values.  */
+ };
+ 
  struct mach_o_fat_header_external
  {
    unsigned char magic[4];
Index: loader.h
===================================================================
RCS file: /cvs/src/src/include/mach-o/loader.h,v
retrieving revision 1.6
diff -c -r1.6 loader.h
*** loader.h	12 Jan 2012 14:03:12 -0000	1.6
--- loader.h	14 Nov 2012 10:44:29 -0000
***************
*** 146,154 ****
    /* Load a dynamically linked shared library that is allowed to be
         missing (weak).  */
    BFD_MACH_O_LC_LOAD_WEAK_DYLIB = 0x18,
!   BFD_MACH_O_LC_SEGMENT_64 = 0x19,	/* 64-bit segment of this file to be 
                                             mapped.  */
!   BFD_MACH_O_LC_ROUTINES_64 = 0x1a,     /* Address of the dyld init routine 
                                             in a dylib.  */
    BFD_MACH_O_LC_UUID = 0x1b,            /* 128-bit UUID of the executable.  */
    BFD_MACH_O_LC_RPATH = 0x1c,		/* Run path addiions.  */
--- 146,154 ----
    /* Load a dynamically linked shared library that is allowed to be
         missing (weak).  */
    BFD_MACH_O_LC_LOAD_WEAK_DYLIB = 0x18,
!   BFD_MACH_O_LC_SEGMENT_64 = 0x19,	/* 64-bit segment of this file to be
                                             mapped.  */
!   BFD_MACH_O_LC_ROUTINES_64 = 0x1a,     /* Address of the dyld init routine
                                             in a dylib.  */
    BFD_MACH_O_LC_UUID = 0x1b,            /* 128-bit UUID of the executable.  */
    BFD_MACH_O_LC_RPATH = 0x1c,		/* Run path addiions.  */
***************
*** 162,168 ****
    BFD_MACH_O_LC_VERSION_MIN_MACOSX = 0x24,   /* Minimal MacOSX version.  */
    BFD_MACH_O_LC_VERSION_MIN_IPHONEOS = 0x25, /* Minimal IOS version.  */
    BFD_MACH_O_LC_FUNCTION_STARTS = 0x26,  /* Compressed table of func start.  */
!   BFD_MACH_O_LC_DYLD_ENVIRONMENT = 0x27  /* Env variable string for dyld.  */
  }
  bfd_mach_o_load_command_type;
  

--- 162,172 ----
    BFD_MACH_O_LC_VERSION_MIN_MACOSX = 0x24,   /* Minimal MacOSX version.  */
    BFD_MACH_O_LC_VERSION_MIN_IPHONEOS = 0x25, /* Minimal IOS version.  */
    BFD_MACH_O_LC_FUNCTION_STARTS = 0x26,  /* Compressed table of func start.  */
!   BFD_MACH_O_LC_DYLD_ENVIRONMENT = 0x27, /* Env variable string for dyld.  */
!   BFD_MACH_O_LC_MAIN = 0x28,             /* Entry point.  */
!   BFD_MACH_O_LC_DATA_IN_CODE = 0x29,     /* Table of non-instructions.  */
!   BFD_MACH_O_LC_SOURCE_VERSION = 0x2a,   /* Source version.  */
!   BFD_MACH_O_LC_DYLIB_CODE_SIGN_DRS = 0x2b /* DRs from dylibs.  */
  }
  bfd_mach_o_load_command_type;
  

***************
*** 250,256 ****
  #define BFD_MACH_O_SECTION_ATTRIBUTES_MASK  0xffffff00
  /* System setable attributes.  */
  #define BFD_MACH_O_SECTION_ATTRIBUTES_SYS   0x00ffff00
! /* User attributes.  */   
  #define BFD_MACH_O_SECTION_ATTRIBUTES_USR   0xff000000
  
  typedef enum bfd_mach_o_section_attribute
--- 254,260 ----
  #define BFD_MACH_O_SECTION_ATTRIBUTES_MASK  0xffffff00
  /* System setable attributes.  */
  #define BFD_MACH_O_SECTION_ATTRIBUTES_SYS   0x00ffff00
! /* User attributes.  */
  #define BFD_MACH_O_SECTION_ATTRIBUTES_USR   0xff000000
  
  typedef enum bfd_mach_o_section_attribute
***************
*** 261,267 ****
    /* Section has local relocation entries.  */
    BFD_MACH_O_S_ATTR_LOC_RELOC         = 0x00000100,
  
!   /* Section has external relocation entries.  */  
    BFD_MACH_O_S_ATTR_EXT_RELOC         = 0x00000200,
  
    /* Section contains some machine instructions.  */
--- 265,271 ----
    /* Section has local relocation entries.  */
    BFD_MACH_O_S_ATTR_LOC_RELOC         = 0x00000100,
  
!   /* Section has external relocation entries.  */
    BFD_MACH_O_S_ATTR_EXT_RELOC         = 0x00000200,
  
    /* Section contains some machine instructions.  */
***************
*** 272,278 ****
  
    /* Used with i386 stubs.  */
    BFD_MACH_O_S_SELF_MODIFYING_CODE    = 0x04000000,
!   
    /* Blocks are live if they reference live blocks.  */
    BFD_MACH_O_S_ATTR_LIVE_SUPPORT      = 0x08000000,
  
--- 276,282 ----
  
    /* Used with i386 stubs.  */
    BFD_MACH_O_S_SELF_MODIFYING_CODE    = 0x04000000,
! 
    /* Blocks are live if they reference live blocks.  */
    BFD_MACH_O_S_ATTR_LIVE_SUPPORT      = 0x08000000,
  
***************
*** 307,313 ****
  #define BFD_MACH_O_NO_SECT 0	/* Symbol not in any section of the image.  */
  
  /* Symbol n_desc reference flags.  */
! #define BFD_MACH_O_REFERENCE_MASK 				0x0f
  #define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_NON_LAZY		0x00
  #define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_LAZY		0x01
  #define BFD_MACH_O_REFERENCE_FLAG_DEFINED			0x02
--- 311,317 ----
  #define BFD_MACH_O_NO_SECT 0	/* Symbol not in any section of the image.  */
  
  /* Symbol n_desc reference flags.  */
! #define BFD_MACH_O_REFERENCE_MASK 				0x07
  #define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_NON_LAZY		0x00
  #define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_LAZY		0x01
  #define BFD_MACH_O_REFERENCE_FLAG_DEFINED			0x02
***************
*** 320,329 ****
--- 324,347 ----
  #define BFD_MACH_O_N_NO_DEAD_STRIP				0x20
  #define BFD_MACH_O_N_WEAK_REF					0x40
  #define BFD_MACH_O_N_WEAK_DEF					0x80
+ #define BFD_MACH_O_N_REF_TO_WEAK				0x80
+ 
+ #define BFD_MACH_O_N_ARM_THUMB_DEF				0x08
+ #define BFD_MACH_O_N_SYMBOL_RESOLVER				0x100
  
  #define BFD_MACH_O_INDIRECT_SYM_LOCAL			0x80000000
  #define BFD_MACH_O_INDIRECT_SYM_ABS			0x40000000
  

+ /* Constants for DATA_IN_CODE entries.  */
+ typedef enum bfd_mach_o_data_in_code_entry_kind
+ {
+   BFD_MACH_O_DICE_KIND_DATA         = 0x0001, /* Data */
+   BFD_MACH_O_DICE_JUMP_TABLES8      = 0x0002, /* 1 byte jump tables.  */
+   BFD_MACH_O_DICE_JUMP_TABLES16     = 0x0003, /* 2 bytes.  */
+   BFD_MACH_O_DICE_JUMP_TABLES32     = 0x0004, /* 4 bytes.  */
+   BFD_MACH_O_DICE_ABS_JUMP_TABLES32 = 0x0005  /* Absolute jump table.  */
+ } bfd_mach_o_data_in_code_entry_kind;
+ 
  /* Thread constants.  */
  
  typedef enum bfd_mach_o_ppc_thread_flavour



More information about the Binutils mailing list