diff options
author | Roman Bolshakov <r.bolshakov@yadro.com> | 2018-11-07 15:20:22 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2018-11-07 15:20:22 +0000 |
commit | fc7b364aba41819a5d74ae0ac69f050af282d057 (patch) | |
tree | 3822fd2dce022a7971badc51cf07800dc103786c /binutils | |
parent | 35ee2dc2e4de8b1ae73f420d5db3375f92300b70 (diff) | |
download | binutils-fc7b364aba41819a5d74ae0ac69f050af282d057.zip binutils-fc7b364aba41819a5d74ae0ac69f050af282d057.tar.gz binutils-fc7b364aba41819a5d74ae0ac69f050af282d057.tar.bz2 |
Add support for new load commands added by Apple to the MACH-O file format.
bfd * mach-o.h: Add new enums for BFD_MACH_O_PLATFORM_MACOS,
BFD_MACH_O_PLATFORM_IOS, BFD_MACH_O_PLATFORM_TVOS,
BFD_MACH_O_PLATFORM_WATCHOS, BFD_MACH_O_PLATFORM_BRIDGEOS,
BFD_MACH_O_TOOL_CLANG, BFD_MACH_O_TOOL_SWIFT, BFD_MACH_O_TOOL_LD.
(struct bfd_mach_o_note_command): New.
(struct bfd_mach_o_build_version_tool): New.
(struct bfd_mach_o_build_version_command): New.
(bfd_mach_o_read_version_min): Don't split version into
a few fields. Rename reserved to sdk.
* mach-o.c (bfd_mach_o_read_version_min): Don't split version into a
few fields. Rename reserved to sdk.
(bfd_mach_o_read_command): Handle LC_VERSION_MIN_TVOS, LC_NOTE,
LC_BUILD_VERSION.
(bfd_mach_o_read_note): New.
(bfd_mach_o_read_build_version): New.
PR 23728
binutils* od-macho.c (printf_version): New.
(dump_load_command): Use it to print version. Print sdk version. Print
version info for watchOS and tvOS. Print LC_NOTE, LC_BUILD_VERSION.
(dump_buld_version): New.
(bfd_mach_o_platform_name): New
(bfd_mach_o_tool_name): New
* mach-o/external.h (mach_o_nversion_min_command_external): Rename
reserved to sdk.
(mach_o_note_command_external): New.
(mach_o_build_version_command_external): New.
* mach-o/loader.h (BFD_MACH_O_LC_VERSION_MIN_TVOS): Define.
(BFD_MACH_O_LC_NOTE): Define.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/ChangeLog | 12 | ||||
-rw-r--r-- | binutils/od-macho.c | 121 |
2 files changed, 125 insertions, 8 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 8964c96..2eab660 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,4 +1,16 @@ +2018-11-06 Roman Bolshakov <r.bolshakov@yadro.com> + Saagar Jha <saagar@saagarjha.com> + + PR 23728 + * od-macho.c (printf_version): New. + (dump_load_command): Use it to print version. Print sdk version. Print + version info for watchOS and tvOS. Print LC_NOTE, LC_BUILD_VERSION. + (dump_buld_version): New. + (bfd_mach_o_platform_name): New + (bfd_mach_o_tool_name): New + 2018-11-07 Yoshinori Sato <ysato@users.sourceforge.jp> + * testsuite/lib/binutils-common.exp: Special section name use only rx-*-elf. diff --git a/binutils/od-macho.c b/binutils/od-macho.c index 8153ada..c5474c8 100644 --- a/binutils/od-macho.c +++ b/binutils/od-macho.c @@ -209,6 +209,10 @@ static const bfd_mach_o_xlat_name bfd_mach_o_load_command_name[] = { "encryption_info_64", BFD_MACH_O_LC_ENCRYPTION_INFO_64}, { "linker_options", BFD_MACH_O_LC_LINKER_OPTIONS}, { "linker_optimization_hint", BFD_MACH_O_LC_LINKER_OPTIMIZATION_HINT}, + { "version_min_tvos", BFD_MACH_O_LC_VERSION_MIN_TVOS}, + { "version_min_watchos", BFD_MACH_O_LC_VERSION_MIN_WATCHOS}, + { "note", BFD_MACH_O_LC_NOTE}, + { "build_version", BFD_MACH_O_LC_BUILD_VERSION}, { NULL, 0} }; @@ -229,7 +233,25 @@ static const bfd_mach_o_xlat_name bfd_mach_o_thread_x86_name[] = { "state_none", BFD_MACH_O_x86_THREAD_STATE_NONE}, { NULL, 0 } }; - + +static const bfd_mach_o_xlat_name bfd_mach_o_platform_name[] = +{ + { "macos", BFD_MACH_O_PLATFORM_MACOS}, + { "ios", BFD_MACH_O_PLATFORM_IOS}, + { "tvos", BFD_MACH_O_PLATFORM_TVOS}, + { "watchos", BFD_MACH_O_PLATFORM_WATCHOS}, + { "bridgeos", BFD_MACH_O_PLATFORM_BRIDGEOS}, + { NULL, 0 } +}; + +static const bfd_mach_o_xlat_name bfd_mach_o_tool_name[] = +{ + { "clang", BFD_MACH_O_TOOL_CLANG}, + { "swift", BFD_MACH_O_TOOL_SWIFT}, + { "ld", BFD_MACH_O_TOOL_LD}, + { NULL, 0 } +}; + static void bfd_mach_o_print_flags (const bfd_mach_o_xlat_name *table, unsigned long val) @@ -1439,6 +1461,68 @@ dump_twolevel_hints (bfd *abfd, bfd_mach_o_twolevel_hints_command *cmd) } static void +printf_version (uint32_t version) +{ + uint32_t maj, min, upd; + + maj = (version >> 16) & 0xffff; + min = (version >> 8) & 0xff; + upd = version & 0xff; + + printf ("%u.%u.%u", maj, min, upd); +} + +static void +dump_build_version (bfd *abfd, bfd_mach_o_load_command *cmd) +{ + const char *platform_name; + size_t tools_len, tools_offset; + bfd_mach_o_build_version_tool *tools, *tool; + bfd_mach_o_build_version_command *ver = &cmd->command.build_version; + uint32_t i; + + platform_name = bfd_mach_o_get_name_or_null + (bfd_mach_o_platform_name, ver->platform); + if (platform_name == NULL) + printf (" platform: 0x%08x\n", ver->platform); + else + printf (" platform: %s\n", platform_name); + printf (" os: "); + printf_version (ver->minos); + printf ("\n sdk: "); + printf_version (ver->sdk); + printf ("\n ntools: %u\n", ver->ntools); + + tools_len = sizeof (bfd_mach_o_build_version_tool) * ver->ntools; + tools_offset = cmd->offset + cmd->len - tools_len; + + tools = xmalloc (tools_len); + if (bfd_seek (abfd, tools_offset, SEEK_SET) != 0 + || bfd_bread (tools, tools_len, abfd) != tools_len) + { + non_fatal (_("cannot read build tools")); + free (tools); + return; + } + + for (i = 0, tool = tools; i < ver->ntools; i++, tool++) + { + const char * tool_name; + + tool_name = bfd_mach_o_get_name_or_null + (bfd_mach_o_tool_name, tool->tool); + if (tool_name == NULL) + printf (" tool: 0x%08x\n", tool->tool); + else + printf (" tool: %s\n", tool_name); + printf (" version: "); + printf_version (tool->version); + printf ("\n"); + } + free (tools); +} + +static void dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd, unsigned int idx, bfd_boolean verbose) { @@ -1582,10 +1666,16 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd, break; case BFD_MACH_O_LC_VERSION_MIN_MACOSX: case BFD_MACH_O_LC_VERSION_MIN_IPHONEOS: + case BFD_MACH_O_LC_VERSION_MIN_WATCHOS: + case BFD_MACH_O_LC_VERSION_MIN_TVOS: { bfd_mach_o_version_min_command *ver = &cmd->command.version_min; - printf (" %u.%u.%u\n", ver->rel, ver->maj, ver->min); + printf (" os: "); + printf_version (ver->version); + printf ("\n sdk: "); + printf_version (ver->sdk); + printf ("\n"); } break; case BFD_MACH_O_LC_SOURCE_VERSION: @@ -1643,6 +1733,21 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd, printf ("\n"); break; } + case BFD_MACH_O_LC_NOTE: + { + bfd_mach_o_note_command *note = &cmd->command.note; + printf (" data owner: %.16s\n", note->data_owner); + printf (" offset: "); + printf_uint64 (note->offset); + printf ("\n" + " size: "); + printf_uint64 (note->size); + printf ("\n"); + break; + } + case BFD_MACH_O_LC_BUILD_VERSION: + dump_build_version (abfd, cmd); + break; default: break; } @@ -2205,9 +2310,9 @@ mach_o_dump (bfd *abfd) /* Vector for Mach-O. */ const struct objdump_private_desc objdump_private_desc_mach_o = - { - mach_o_help, - mach_o_filter, - mach_o_dump, - options - }; +{ + mach_o_help, + mach_o_filter, + mach_o_dump, + options +}; |