From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2816 invoked by alias); 1 Apr 2014 10:41:10 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 2806 invoked by uid 89); 1 Apr 2014 10:41:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 01 Apr 2014 10:41:08 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6AC822720045 for ; Tue, 1 Apr 2014 12:41:05 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gi4CC_9Jh5I7 for ; Tue, 1 Apr 2014 12:41:05 +0200 (CEST) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 504922720009 for ; Tue, 1 Apr 2014 12:41:05 +0200 (CEST) From: Tristan Gingold Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: [Mach-O]: Add objdump -P data_in_code Message-Id: <6D60D2D3-1832-4322-92E7-6ED560E4CC79@adacore.com> Date: Tue, 01 Apr 2014 10:41:00 -0000 To: "binutils@sourceware.org Development" Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) X-IsSubscribed: yes X-SW-Source: 2014-04/txt/msg00001.txt.bz2 Hello, this new command display the content of data_in_code load command. Committed on trunk. Tristan. binutils/ * od-macho.c (OPT_DATA_IN_CODE): New macro. (options): Add entry for data in code. (mach_o_help): Ditto. (data_in_code_kind_name): New array. (dump_data_in_code): New function. (dump_load_command): Handle data in code. (mach_o_dump): Ditto. (dump_header): Display a terminal newline. diff --git a/binutils/od-macho.c b/binutils/od-macho.c index 80bf5c2..31cce9d 100644 --- a/binutils/od-macho.c +++ b/binutils/od-macho.c @@ -43,6 +43,7 @@ #define OPT_SEG_SPLIT_INFO 6 #define OPT_COMPACT_UNWIND 7 #define OPT_FUNCTION_STARTS 8 +#define OPT_DATA_IN_CODE 9 =20 /* List of actions. */ static struct objdump_private_option options[] =3D @@ -56,6 +57,7 @@ static struct objdump_private_option options[] =3D { "seg_split_info", 0 }, { "compact_unwind", 0 }, { "function_starts", 0 }, + { "data_in_code", 0 }, { NULL, 0 } }; =20 @@ -75,6 +77,7 @@ For Mach-O files:\n\ seg_split_info Display segment split info\n\ compact_unwind Display compact unwinding info\n\ function_starts Display start address of functions\n\ + data_in_code Display data in code entries\n\ ")); } =20 @@ -284,6 +287,7 @@ dump_header (bfd *abfd) bfd_mach_o_print_flags (bfd_mach_o_header_flags_name, h->flags); fputs (_(")\n"), stdout); printf (_(" reserved : %08x\n"), h->reserved); + putchar ('\n'); } =20 static void @@ -974,6 +978,59 @@ dump_function_starts (bfd *abfd, bfd_mach_o_linkedit_c= ommand *cmd) free (buf); } =20 +static const bfd_mach_o_xlat_name data_in_code_kind_name[] =3D +{ + { "data", BFD_MACH_O_DICE_KIND_DATA }, + { "1 byte jump table", BFD_MACH_O_DICE_JUMP_TABLES8 }, + { "2 bytes jump table", BFD_MACH_O_DICE_JUMP_TABLES16 }, + { "4 bytes jump table", BFD_MACH_O_DICE_JUMP_TABLES32 }, + { "4 bytes abs jump table", BFD_MACH_O_DICE_ABS_JUMP_TABLES32 }, + { NULL, 0 } +}; + +static void +dump_data_in_code (bfd *abfd, bfd_mach_o_linkedit_command *cmd) +{ + unsigned char *buf; + unsigned char *p; + + if (cmd->datasize =3D=3D 0) + { + printf (" no data_in_code entries\n"); + return; + } + + buf =3D xmalloc (cmd->datasize); + if (bfd_seek (abfd, cmd->dataoff, SEEK_SET) !=3D 0 + || bfd_bread (buf, cmd->datasize, abfd) !=3D cmd->datasize) + { + non_fatal (_("cannot read function starts")); + free (buf); + return; + } + + printf (" offset length kind\n"); + for (p =3D buf; p < buf + cmd->datasize; ) + { + struct mach_o_data_in_code_entry_external *dice; + unsigned int offset; + unsigned int length; + unsigned int kind; + + dice =3D (struct mach_o_data_in_code_entry_external *) p; + + offset =3D bfd_get_32 (abfd, dice->offset); + length =3D bfd_get_16 (abfd, dice->length); + kind =3D bfd_get_16 (abfd, dice->kind); + + printf (" 0x%08x 0x%04x 0x%04x %s\n", offset, length, kind, + bfd_mach_o_get_name (data_in_code_kind_name, kind)); + + p +=3D sizeof (*dice); + } + free (buf); +} + static void dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd, bfd_boolean verbose) @@ -1070,14 +1127,26 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_comma= nd *cmd, linkedit->dataoff, linkedit->datasize, linkedit->dataoff + linkedit->datasize); =20 - if (verbose && cmd->type =3D=3D BFD_MACH_O_LC_CODE_SIGNATURE) - dump_code_signature (abfd, linkedit); - else if (verbose && cmd->type =3D=3D BFD_MACH_O_LC_SEGMENT_SPLIT_I= NFO) - dump_segment_split_info (abfd, linkedit); - else if (verbose && cmd->type =3D=3D BFD_MACH_O_LC_FUNCTION_STARTS) - dump_function_starts (abfd, linkedit); - break; + if (verbose) + switch (cmd->type) + { + case BFD_MACH_O_LC_CODE_SIGNATURE: + dump_code_signature (abfd, linkedit); + break; + case BFD_MACH_O_LC_SEGMENT_SPLIT_INFO: + dump_segment_split_info (abfd, linkedit); + break; + case BFD_MACH_O_LC_FUNCTION_STARTS: + dump_function_starts (abfd, linkedit); + break; + case BFD_MACH_O_LC_DATA_IN_CODE: + dump_data_in_code (abfd, linkedit); + break; + default: + break; + } } + break; case BFD_MACH_O_LC_SUB_FRAMEWORK: case BFD_MACH_O_LC_SUB_UMBRELLA: case BFD_MACH_O_LC_SUB_LIBRARY: @@ -1617,6 +1686,8 @@ mach_o_dump (bfd *abfd) dump_load_commands (abfd, BFD_MACH_O_LC_SEGMENT_SPLIT_INFO, 0); if (options[OPT_FUNCTION_STARTS].selected) dump_load_commands (abfd, BFD_MACH_O_LC_FUNCTION_STARTS, 0); + if (options[OPT_DATA_IN_CODE].selected) + dump_load_commands (abfd, BFD_MACH_O_LC_DATA_IN_CODE, 0); if (options[OPT_COMPACT_UNWIND].selected) { dump_section_content (abfd, "__LD", "__compact_unwind",