+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.
+
2011-08-08 Tristan Gingold <gingold@adacore.com>
* mach-o.h: Move size macros to external.h
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,
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;
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);
}
static const char *
-bfd_mach_o_get_name (const bfd_mach_o_xlat_name *table, unsigned long val)
+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 "*UNKNOWN*";
+ 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[] =
{ "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}
};
for (i = 0; i < mdata->header.ncmds; i++)
{
bfd_mach_o_load_command *cmd = &mdata->commands[i];
+ const char *cmd_name;
- fprintf (file, "Load command %s:",
- bfd_mach_o_get_name (bfd_mach_o_load_command_name, cmd->type));
+ 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:
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
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);
}
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;
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;
}
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
+ 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;
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_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;
\f