This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[mach-o/committed]: Add Lion new load commands


Hi,

the latest (and recently released) version of Darwin added a few new load commands that are
decoded by this patch.

Committed on trunk.

Tristan.

bfd/
2011-08-08  Tristan Gingold  <gingold@adacore.com>

	* mach-o.h (bfd_mach_o_version_min_command): New structure.
	(bfd_mach_o_load_command): Add version_min.
	(mach_o_data_struct): Fix comment.
	* mach-o.c (bfd_mach_o_read_version_min): New function.
	(bfd_mach_o_read_command): Handle BFD_MACH_O_LC_FUNCTION_STARTS,
	BFD_MACH_O_LC_VERSION_MIN_MACOSX and
	BFD_MACH_O_LC_VERSION_MIN_IPHONEOS.
	(bfd_mach_o_get_name_or_null): New function.
	(bfd_mach_o_get_name): Use the above new one.
	(bfd_mach_o_load_command_name): Add the above new commands.
	(bfd_mach_o_bfd_print_private_bfd_data): Display numerically
	unknown commands.  Handle BFD_MACH_O_LC_FUNCTION_STARTS,
	BFD_MACH_O_LC_VERSION_MIN_MACOSX and
	BFD_MACH_O_LC_VERSION_MIN_IPHONEOS.

include/mach-o/
2011-08-08  Tristan Gingold  <gingold@adacore.com>

	* loader.h (bfd_mach_o_load_command_type): Add
	BFD_MACH_O_LC_LOAD_UPWARD_DYLIB, BFD_MACH_O_LC_VERSION_MIN_MACOSX,
	BFD_MACH_O_LC_VERSION_MIN_IPHONEOS, BFD_MACH_O_LC_FUNCTION_STARTS,
	and BFD_MACH_O_LC_DYLD_ENVIRONMENT.
	* external.h (mach_o_version_min_command_external): New structure.

Index: bfd/mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.61
diff -c -r1.61 mach-o.c
*** bfd/mach-o.c	8 Aug 2011 08:59:32 -0000	1.61
--- bfd/mach-o.c	8 Aug 2011 10:19:54 -0000
***************
*** 2433,2438 ****
--- 2433,2457 ----
    return 0;
  }
  
+ static bfd_boolean
+ bfd_mach_o_read_version_min (bfd *abfd, bfd_mach_o_load_command *command)
+ {
+   bfd_mach_o_version_min_command *cmd = &command->command.version_min;
+   struct mach_o_version_min_command_external raw;
+   unsigned int ver;
+ 
+   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
+       || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+     return FALSE;
+ 
+   ver = bfd_get_32 (abfd, raw.version);
+   cmd->rel = ver >> 16;
+   cmd->maj = ver >> 8;
+   cmd->min = ver;
+   cmd->reserved = bfd_get_32 (abfd, raw.reserved);
+   return TRUE;
+ }
+ 
  static int
  bfd_mach_o_read_segment (bfd *abfd,
                           bfd_mach_o_load_command *command,
***************
*** 2606,2611 ****
--- 2625,2631 ----
        break;
      case BFD_MACH_O_LC_CODE_SIGNATURE:
      case BFD_MACH_O_LC_SEGMENT_SPLIT_INFO:
+     case BFD_MACH_O_LC_FUNCTION_STARTS:
        if (bfd_mach_o_read_linkedit (abfd, command) != 0)
  	return -1;
        break;
***************
*** 2613,2618 ****
--- 2633,2643 ----
        if (bfd_mach_o_read_dyld_info (abfd, command) != 0)
  	return -1;
        break;
+     case BFD_MACH_O_LC_VERSION_MIN_MACOSX:
+     case BFD_MACH_O_LC_VERSION_MIN_IPHONEOS:
+       if (!bfd_mach_o_read_version_min (abfd, command))
+ 	return -1;
+       break;
      default:
        (*_bfd_error_handler) (_("unable to read unknown load command 0x%lx"),
  			     (unsigned long) command->type);
***************
*** 3308,3319 ****
  }
  
  static const char *
! bfd_mach_o_get_name (const bfd_mach_o_xlat_name *table, unsigned long val)
  {
    for (; table->name; table++)
      if (table->val == val)
        return table->name;
!   return "*UNKNOWN*";
  }
  
  static bfd_mach_o_xlat_name bfd_mach_o_cpu_name[] =
--- 3333,3356 ----
  }
  
  static const char *
! bfd_mach_o_get_name_or_null (const bfd_mach_o_xlat_name *table,
!                              unsigned long val)
  {
    for (; table->name; table++)
      if (table->val == val)
        return table->name;
!   return NULL;
! }
! 
! static const char *
! bfd_mach_o_get_name (const bfd_mach_o_xlat_name *table, unsigned long val)
! {
!   const char *res = bfd_mach_o_get_name_or_null (table, val);
! 
!   if (res == NULL)
!     return "*UNKNOWN*";
!   else
!     return res;
  }
  
  static bfd_mach_o_xlat_name bfd_mach_o_cpu_name[] =
***************
*** 3451,3456 ****
--- 3488,3498 ----
    { "lazy_load_dylib", BFD_MACH_O_LC_LAZY_LOAD_DYLIB},
    { "encryption_info", BFD_MACH_O_LC_ENCRYPTION_INFO},
    { "dyld_info", BFD_MACH_O_LC_DYLD_INFO},
+   { "load_upward_lib", BFD_MACH_O_LC_LOAD_UPWARD_DYLIB},
+   { "version_min_macosx", BFD_MACH_O_LC_VERSION_MIN_MACOSX},
+   { "version_min_iphoneos", BFD_MACH_O_LC_VERSION_MIN_IPHONEOS},
+   { "function_starts", BFD_MACH_O_LC_FUNCTION_STARTS},
+   { "dyld_environment", BFD_MACH_O_LC_DYLD_ENVIRONMENT},
    { NULL, 0}
  };
  
***************
*** 3843,3851 ****
    for (i = 0; i < mdata->header.ncmds; i++)
      {
        bfd_mach_o_load_command *cmd = &mdata->commands[i];
        
!       fprintf (file, "Load command %s:",
!                bfd_mach_o_get_name (bfd_mach_o_load_command_name, cmd->type));
        switch (cmd->type)
  	{
  	case BFD_MACH_O_LC_SEGMENT:
--- 3885,3900 ----
    for (i = 0; i < mdata->header.ncmds; i++)
      {
        bfd_mach_o_load_command *cmd = &mdata->commands[i];
+       const char *cmd_name;
        
!       cmd_name = bfd_mach_o_get_name_or_null
!         (bfd_mach_o_load_command_name, cmd->type);
!       fprintf (file, "Load command ");
!       if (cmd_name == NULL)
!         fprintf (file, "0x%02x:", cmd->type);
!       else
!         fprintf (file, "%s:", cmd_name);
! 
        switch (cmd->type)
  	{
  	case BFD_MACH_O_LC_SEGMENT:
***************
*** 3903,3908 ****
--- 3952,3958 ----
            break;
          case BFD_MACH_O_LC_CODE_SIGNATURE:
          case BFD_MACH_O_LC_SEGMENT_SPLIT_INFO:
+         case BFD_MACH_O_LC_FUNCTION_STARTS:
  	  {
  	    bfd_mach_o_linkedit_command *linkedit = &cmd->command.linkedit;
  	    fprintf
***************
*** 3957,3964 ****
--- 4007,4024 ----
            fprintf (file, "\n");
            bfd_mach_o_print_dyld_info (abfd, cmd, file);
            break;
+ 	case BFD_MACH_O_LC_VERSION_MIN_MACOSX:
+ 	case BFD_MACH_O_LC_VERSION_MIN_IPHONEOS:
+           {
+             bfd_mach_o_version_min_command *ver = &cmd->command.version_min;
+ 
+             fprintf (file, " %u.%u.%u\n", ver->rel, ver->maj, ver->min);
+           }
+           break;
  	default:
  	  fprintf (file, "\n");
+           fprintf (file, "  offset: 0x%08lx\n", (unsigned long)cmd->offset);
+           fprintf (file, "    size: 0x%08lx\n", (unsigned long)cmd->len);
  	  break;
  	}
        fputc ('\n', file);
Index: bfd/mach-o.h
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.h,v
retrieving revision 1.27
diff -c -r1.27 mach-o.h
*** bfd/mach-o.h	8 Aug 2011 08:59:32 -0000	1.27
--- bfd/mach-o.h	8 Aug 2011 10:19:54 -0000
***************
*** 453,458 ****
--- 453,467 ----
  }
  bfd_mach_o_dyld_info_command;
  
+ typedef struct bfd_mach_o_version_min_command
+ {
+   unsigned char rel;
+   unsigned char maj;
+   unsigned char min;
+   unsigned int reserved;
+ }
+ bfd_mach_o_version_min_command;
+ 
  typedef struct bfd_mach_o_load_command
  {
    bfd_mach_o_load_command_type type;
***************
*** 472,477 ****
--- 481,487 ----
      bfd_mach_o_linkedit_command linkedit;
      bfd_mach_o_str_command str;
      bfd_mach_o_dyld_info_command dyld_info;
+     bfd_mach_o_version_min_command version_min;
    }
    command;
  }
***************
*** 493,499 ****
    ufile_ptr filelen;
  
    /* As symtab is referenced by other load command, it is handy to have
!      a direct access to it.  Also it is not clearly stated, only one symtab
       is expected.  */
    bfd_mach_o_symtab_command *symtab;
    bfd_mach_o_dysymtab_command *dysymtab;
--- 503,509 ----
    ufile_ptr filelen;
  
    /* As symtab is referenced by other load command, it is handy to have
!      a direct access to it.  Although it is not clearly stated, only one symtab
       is expected.  */
    bfd_mach_o_symtab_command *symtab;
    bfd_mach_o_dysymtab_command *dysymtab;
Index: include/mach-o/external.h
===================================================================
RCS file: /cvs/src/src/include/mach-o/external.h,v
retrieving revision 1.1
diff -c -r1.1 external.h
*** include/mach-o/external.h	8 Aug 2011 08:59:33 -0000	1.1
--- include/mach-o/external.h	8 Aug 2011 10:19:55 -0000
***************
*** 249,254 ****
--- 249,260 ----
    unsigned char export_size[4];
  };
  
+ struct mach_o_version_min_command_external
+ {
+   unsigned char version[4];
+   unsigned char reserved[4];
+ };
+ 
  struct mach_o_fat_header_external
  {
    unsigned char magic[4];
Index: include/mach-o/loader.h
===================================================================
RCS file: /cvs/src/src/include/mach-o/loader.h,v
retrieving revision 1.2
diff -c -r1.2 loader.h
*** include/mach-o/loader.h	8 Aug 2011 08:59:33 -0000	1.2
--- include/mach-o/loader.h	8 Aug 2011 10:19:55 -0000
***************
    BFD_MACH_O_LC_REEXPORT_DYLIB = 0x1f,  /* Load and re-export lib.  */
    BFD_MACH_O_LC_LAZY_LOAD_DYLIB = 0x20, /* Delay load of lib until use.  */
    BFD_MACH_O_LC_ENCRYPTION_INFO = 0x21, /* Encrypted segment info.  */
!   BFD_MACH_O_LC_DYLD_INFO = 0x22	/* Compressed dyld information.  */
  }
  bfd_mach_o_load_command_type;
  

--- 148,159 ----
    BFD_MACH_O_LC_REEXPORT_DYLIB = 0x1f,  /* Load and re-export lib.  */
    BFD_MACH_O_LC_LAZY_LOAD_DYLIB = 0x20, /* Delay load of lib until use.  */
    BFD_MACH_O_LC_ENCRYPTION_INFO = 0x21, /* Encrypted segment info.  */
!   BFD_MACH_O_LC_DYLD_INFO = 0x22,	/* Compressed dyld information.  */
!   BFD_MACH_O_LC_LOAD_UPWARD_DYLIB = 0x23, /* Load upward dylib.  */
!   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;
  



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]