objdump.c revision 95fa15e7b3af7321dc70dc453eb9cb0596b5a817
18a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Print information from ELF file in human-readable form. 244173edad1dfd24c4d98fcf032308f7df28db652Ulrich Drepper Copyright (C) 2005, 2006, 2007, 2009 Red Hat, Inc. 3361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper This file is part of Red Hat elfutils. 48a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Written by Ulrich Drepper <drepper@redhat.com>, 2005. 58a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is free software; you can redistribute it and/or modify 7361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper it under the terms of the GNU General Public License as published by the 8361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Free Software Foundation; version 2 of the License. 98a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 10361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is distributed in the hope that it will be useful, but 11361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper WITHOUT ANY WARRANTY; without even the implied warranty of 12361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper General Public License for more details. 14361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 15361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper You should have received a copy of the GNU General Public License along 16361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper with Red Hat elfutils; if not, write to the Free Software Foundation, 171e9ef50681e20ef14c2ba38aef37a71ff148be08Ulrich Drepper Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. 18361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 19361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is an included package of the Open Invention Network. 20361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper An included package of the Open Invention Network is a package for which 21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Open Invention Network licensees cross-license their patents. No patent 22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper license is granted, either expressly or impliedly, by designation as an 23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper included package. Should you wish to participate in the Open Invention 24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Network licensing program, please visit www.openinventionnetwork.com 25361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper <http://www.openinventionnetwork.com>. */ 268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#ifdef HAVE_CONFIG_H 288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper# include <config.h> 298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#endif 308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 318a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <argp.h> 328a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <error.h> 338a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <fcntl.h> 348a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <inttypes.h> 358a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <libintl.h> 368a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <locale.h> 378a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <mcheck.h> 388a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <stdbool.h> 398a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <stdio.h> 408a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <stdio_ext.h> 418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <stdlib.h> 428a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <string.h> 438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <unistd.h> 448a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <sys/param.h> 458a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 468a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include <system.h> 478a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#include "../libebl/libeblP.h" 488a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 498a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 508a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Name and version of program. */ 518a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic void print_version (FILE *stream, struct argp_state *state); 52fdc93e12a77866cafd1aae4463d89cef2c01d9b1Ulrich DrepperARGP_PROGRAM_VERSION_HOOK_DEF = print_version; 538a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 548a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Bug report address. */ 55fdc93e12a77866cafd1aae4463d89cef2c01d9b1Ulrich DrepperARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; 568a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 578a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 588a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Definitions of arguments for argp functions. */ 598a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic const struct argp_option options[] = 608a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 618a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { NULL, 0, NULL, 0, N_("Mode selection:"), 0 }, 628a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { "reloc", 'r', NULL, 0, N_("Display relocation information."), 0 }, 638a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { "full-contents", 's', NULL, 0, 648a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper N_("Display the full contents of all sections requested"), 0 }, 658a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { "disassemble", 'd', NULL, 0, 668a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper N_("Display assembler code of executable sections"), 0 }, 678a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 688a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { NULL, 0, NULL, 0, N_("Output option selection:"), 0 }, 698a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { "section", 'j', "NAME", 0, 708a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper N_("Only display information for section NAME."), 0 }, 718a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 728a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { NULL, 0, NULL, 0, NULL, 0 } 738a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper}; 748a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 758a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Short description of program. */ 768a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic const char doc[] = N_("\ 778a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich DrepperShow information from FILEs (a.out by default)."); 788a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 798a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Strings for arguments in help texts. */ 808a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic const char args_doc[] = N_("[FILE...]"); 818a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 828a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Prototype for option handler. */ 838a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic error_t parse_opt (int key, char *arg, struct argp_state *state); 848a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 858a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Data structure to communicate with argp functions. */ 868a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic struct argp argp = 878a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 888a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper options, parse_opt, args_doc, doc, NULL, NULL, NULL 898a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper}; 908a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 918a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 928a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Print symbols in file named FNAME. */ 938a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int process_file (const char *fname, bool more_than_one); 948a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 958a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Handle content of archive. */ 968a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, 978a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper const char *suffix); 988a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 998a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Handle ELF file. */ 1008a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int handle_elf (Elf *elf, const char *prefix, const char *fname, 1018a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper const char *suffix); 1028a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1038a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1048a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper#define INTERNAL_ERROR(fname) \ 1058a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper error (EXIT_FAILURE, 0, gettext ("%s: INTERNAL ERROR %d (%s-%s): %s"), \ 106b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper fname, __LINE__, PACKAGE_VERSION, __DATE__, elf_errmsg (-1)) 1078a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1088a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1098a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* List of sections which should be used. */ 1108a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic struct section_list 1118a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 1128a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper bool is_name; 1138a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper union 1148a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 1158a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper const char *name; 1168a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper uint32_t scnndx; 1178a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper }; 1188a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper struct section_list *next; 1198a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} *section_list; 1208a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1218a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1228a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* If true print archive index. */ 1238a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic bool print_relocs; 1248a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1258a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* If true print full contents of requested sections. */ 1268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic bool print_full_content; 1278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* If true print disassembled output.. */ 1298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic bool print_disasm; 1308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1318a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperint 1328a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Dreppermain (int argc, char *argv[]) 1338a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 1348a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Make memory leak detection possible. */ 1358a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper mtrace (); 1368a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1378a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* We use no threads here which can interfere with handling a stream. */ 1388a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper (void) __fsetlocking (stdin, FSETLOCKING_BYCALLER); 1398a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER); 1408a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper (void) __fsetlocking (stderr, FSETLOCKING_BYCALLER); 1418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1428a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Set locale. */ 1438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper (void) setlocale (LC_ALL, ""); 1448a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1458a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Make sure the message catalog can be found. */ 146b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper (void) bindtextdomain (PACKAGE_TARNAME, LOCALEDIR); 1478a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1488a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Initialize the message catalog. */ 149b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper (void) textdomain (PACKAGE_TARNAME); 1508a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1518a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Parse and process arguments. */ 1528a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int remaining; 1538a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper (void) argp_parse (&argp, argc, argv, 0, &remaining, NULL); 1548a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1558a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Tell the library which version we are expecting. */ 1568a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper (void) elf_version (EV_CURRENT); 1578a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1588a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int result = 0; 1598a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (remaining == argc) 1608a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* The user didn't specify a name so we use a.out. */ 1618a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result = process_file ("a.out", false); 1628a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper else 1638a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 1648a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Process all the remaining files. */ 1658a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper const bool more_than_one = remaining + 1 < argc; 1668a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1678a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper do 1688a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result |= process_file (argv[remaining], more_than_one); 1698a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper while (++remaining < argc); 1708a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 1718a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1728a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return result; 1738a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 1748a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1758a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1768a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Print the version information. */ 1778a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic void 1788a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperprint_version (FILE *stream, struct argp_state *state __attribute__ ((unused))) 1798a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 180b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper fprintf (stream, "objdump (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION); 1818a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fprintf (stream, gettext ("\ 1828a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich DrepperCopyright (C) %s Red Hat, Inc.\n\ 1838a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich DrepperThis is free software; see the source for copying conditions. There is NO\n\ 1848a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 18544173edad1dfd24c4d98fcf032308f7df28db652Ulrich Drepper"), "20089"); 1868a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); 1878a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 1888a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1898a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1908a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Handle program arguments. */ 1918a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic error_t 1928a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperparse_opt (int key, char *arg, 1938a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper struct argp_state *state __attribute__ ((unused))) 1948a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 1958a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* True if any of the control options is set. */ 1968a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper static bool any_control_option; 1978a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 1988a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper switch (key) 1998a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2008a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper case 'j': 2018a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2028a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper struct section_list *newp = xmalloc (sizeof (*newp)); 2038a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper char *endp; 2048a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper newp->scnndx = strtoul (arg, &endp, 0); 2058a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (*endp == 0) 2068a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper newp->is_name = false; 2078a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper else 2088a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2098a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper newp->name = arg; 2108a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper newp->is_name = true; 2118a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2128a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper newp->next = section_list; 2138a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper section_list = newp; 2148a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2158a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper any_control_option = true; 2168a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper break; 2178a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2188a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper case 'd': 2198a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper print_disasm = true; 2208a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper any_control_option = true; 2218a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper break; 2228a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2238a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper case 'r': 2248a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper print_relocs = true; 2258a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper any_control_option = true; 2268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper break; 2278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper case 's': 2298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper print_full_content = true; 2308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper any_control_option = true; 2318a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper break; 2328a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2338a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper case ARGP_KEY_FINI: 2348a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (! any_control_option) 2358a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2368a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputs (gettext ("No operation specified.\n"), stderr); 2375ee720c60a298352b52513d03ede85814ab63ad5Ulrich Drepper argp_help (&argp, stderr, ARGP_HELP_SEE, 2388a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper program_invocation_short_name); 2395ee720c60a298352b52513d03ede85814ab63ad5Ulrich Drepper exit (EXIT_FAILURE); 2408a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2428a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper default: 2438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return ARGP_ERR_UNKNOWN; 2448a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2458a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return 0; 2468a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 2478a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2488a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2498a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper/* Open the file and determine the type. */ 2508a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int 2518a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperprocess_file (const char *fname, bool more_than_one) 2528a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 2538a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Open the file. */ 2548a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int fd = open (fname, O_RDONLY); 2558a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (fd == -1) 2568a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2578a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper error (0, errno, gettext ("cannot open %s"), fname); 2588a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return 1; 2598a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2608a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2618a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Now get the ELF descriptor. */ 2628a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf *elf = elf_begin (fd, ELF_C_READ_MMAP, NULL); 2638a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf != NULL) 2648a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2658a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf_kind (elf) == ELF_K_ELF) 2668a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2678a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int result = handle_elf (elf, more_than_one ? "" : NULL, 2688a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fname, NULL); 2698a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2708a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf_end (elf) != 0) 2718a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper INTERNAL_ERROR (fname); 2728a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2738a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (close (fd) != 0) 2748a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper error (EXIT_FAILURE, errno, gettext ("while close `%s'"), fname); 2758a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2768a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return result; 2778a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2788a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper else if (elf_kind (elf) == ELF_K_AR) 2798a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 2808a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int result = handle_ar (fd, elf, NULL, fname, NULL); 2818a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2828a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf_end (elf) != 0) 2838a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper INTERNAL_ERROR (fname); 2848a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2858a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (close (fd) != 0) 2868a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper error (EXIT_FAILURE, errno, gettext ("while close `%s'"), fname); 2878a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2888a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return result; 2898a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2908a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2918a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* We cannot handle this type. Close the descriptor anyway. */ 2928a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf_end (elf) != 0) 2938a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper INTERNAL_ERROR (fname); 2948a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 2958a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2968a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper error (0, 0, gettext ("%s: File format not recognized"), fname); 2978a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 2988a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return 1; 2998a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 3008a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3018a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3028a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int 3038a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperhandle_ar (int fd, Elf *elf, const char *prefix, const char *fname, 3048a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper const char *suffix) 3058a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 3068a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t fname_len = strlen (fname) + 1; 3078a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t prefix_len = prefix != NULL ? strlen (prefix) : 0; 3088a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper char new_prefix[prefix_len + fname_len + 2]; 3098a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t suffix_len = suffix != NULL ? strlen (suffix) : 0; 3108a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper char new_suffix[suffix_len + 2]; 3118a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf *subelf; 3128a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Cmd cmd = ELF_C_READ_MMAP; 3138a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int result = 0; 3148a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3158a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper char *cp = new_prefix; 3168a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (prefix != NULL) 3178a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp = stpcpy (cp, prefix); 3188a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp = stpcpy (cp, fname); 3198a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper stpcpy (cp, "["); 3208a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3218a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp = new_suffix; 3228a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (suffix != NULL) 3238a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp = stpcpy (cp, suffix); 3248a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper stpcpy (cp, "]"); 3258a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Process all the files contained in the archive. */ 3278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper while ((subelf = elf_begin (fd, cmd, elf)) != NULL) 3288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 3298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* The the header for this element. */ 3308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Arhdr *arhdr = elf_getarhdr (subelf); 3318a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3328a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Skip over the index entries. */ 3338a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (strcmp (arhdr->ar_name, "/") != 0 3348a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper && strcmp (arhdr->ar_name, "//") != 0) 3358a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 3368a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf_kind (subelf) == ELF_K_ELF) 3378a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result |= handle_elf (subelf, new_prefix, arhdr->ar_name, 3388a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper new_suffix); 3398a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper else if (elf_kind (subelf) == ELF_K_AR) 3408a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result |= handle_ar (fd, subelf, new_prefix, arhdr->ar_name, 3418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper new_suffix); 3428a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper else 3438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 3448a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper error (0, 0, gettext ("%s%s%s: file format not recognized"), 3458a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper new_prefix, arhdr->ar_name, new_suffix); 3468a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result = 1; 3478a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 3488a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 3498a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3508a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Get next archive element. */ 3518a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cmd = elf_next (subelf); 3528a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf_end (subelf) != 0) 3538a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper INTERNAL_ERROR (fname); 3548a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 3558a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3568a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return result; 3578a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 3588a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3598a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 3608a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic void 36195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Dreppershow_relocs_x (Ebl *ebl, GElf_Shdr *shdr, Elf_Data *symdata, 36295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper Elf_Data *xndxdata, size_t symstrndx, size_t shstrndx, 36395fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper GElf_Addr r_offset, GElf_Xword r_info, GElf_Sxword r_addend) 36495fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper{ 36595fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper int elfclass = gelf_getclass (ebl->elf); 36695fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper char buf[128]; 36795fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper GElf_Sym symmem; 36895fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper GElf_Sym *sym; 36995fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper Elf32_Word xndx; 37095fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper 37195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper printf ("%0*" PRIx64 " %-20s ", 37295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper elfclass == ELFCLASS32 ? 8 : 16, r_offset, 37395fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper ebl_reloc_type_name (ebl, GELF_R_TYPE (r_info), buf, sizeof (buf))); 37495fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper 37595fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper sym = gelf_getsymshndx (symdata, xndxdata, GELF_R_SYM (r_info), 37695fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper &symmem, &xndx); 37795fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper 37895fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper if (sym == NULL) 37995fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper printf ("<%s %ld>", 38095fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper gettext ("INVALID SYMBOL"), (long int) GELF_R_SYM (r_info)); 38195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper else if (GELF_ST_TYPE (sym->st_info) != STT_SECTION) 38295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper printf ("%s", 38395fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper elf_strptr (ebl->elf, symstrndx, sym->st_name)); 38495fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper else 38595fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper { 38695fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper GElf_Shdr destshdr_mem; 38795fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper GElf_Shdr *destshdr; 38895fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper destshdr = gelf_getshdr (elf_getscn (ebl->elf, 38995fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper sym->st_shndx == SHN_XINDEX 39095fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper ? xndx : sym->st_shndx), 39195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper &destshdr_mem); 39295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper 39395fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper if (shdr == NULL) 39495fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper printf ("<%s %ld>", 39595fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper gettext ("INVALID SECTION"), 39695fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper (long int) (sym->st_shndx == SHN_XINDEX 39795fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper ? xndx : sym->st_shndx)); 39895fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper else 39995fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper printf ("%s", 40095fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper elf_strptr (ebl->elf, shstrndx, destshdr->sh_name)); 40195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper } 40295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper 40395fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper if (r_addend != 0) 40495fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper { 40595fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper char sign = '+'; 40695fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper if (r_addend < 0) 40795fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper { 40895fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper sign = '-'; 40995fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper r_addend = -r_addend; 41095fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper } 41195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper printf ("%c%#" PRIx64, sign, r_addend); 41295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper } 41395fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper putchar ('\n'); 41495fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper} 41595fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper 41695fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper 41795fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepperstatic void 4188a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Dreppershow_relocs_rel (Ebl *ebl, GElf_Shdr *shdr, Elf_Data *data, 4198a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Data *symdata, Elf_Data *xndxdata, size_t symstrndx, 4208a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t shstrndx) 4218a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 4228a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int nentries = shdr->sh_size / shdr->sh_entsize; 4238a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4248a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (int cnt = 0; cnt < nentries; ++cnt) 4258a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 4268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Rel relmem; 4278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Rel *rel; 4288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper rel = gelf_getrel (data, cnt, &relmem); 4308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (rel != NULL) 43195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper show_relocs_x (ebl, shdr, symdata, xndxdata, symstrndx, shstrndx, 43295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper rel->r_offset, rel->r_info, 0); 4338a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 4348a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 4358a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4368a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4378a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic void 4388a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Dreppershow_relocs_rela (Ebl *ebl, GElf_Shdr *shdr, Elf_Data *data, 4398a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Data *symdata, Elf_Data *xndxdata, size_t symstrndx, 4408a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t shstrndx) 4418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 4428a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int nentries = shdr->sh_size / shdr->sh_entsize; 4438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4448a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (int cnt = 0; cnt < nentries; ++cnt) 4458a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 4468a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Rela relmem; 4478a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Rela *rel; 4488a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4498a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper rel = gelf_getrela (data, cnt, &relmem); 4508a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (rel != NULL) 45195fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper show_relocs_x (ebl, shdr, symdata, xndxdata, symstrndx, shstrndx, 45295fa15e7b3af7321dc70dc453eb9cb0596b5a817Ulrich Drepper rel->r_offset, rel->r_info, rel->r_addend); 4538a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 4548a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 4558a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4568a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4578a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic bool 4588a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Dreppersection_match (Elf *elf, uint32_t scnndx, GElf_Shdr *shdr, size_t shstrndx) 4598a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 4608a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (section_list == NULL) 4618a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return true; 4628a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4638a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper struct section_list *runp = section_list; 4648a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4658a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper do 4668a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 4678a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (runp->is_name) 4688a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 4698a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (strcmp (runp->name, 4708a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper elf_strptr (elf, shstrndx, shdr->sh_name)) == 0) 4718a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return true; 4728a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 4738a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper else 4748a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 4758a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (runp->scnndx == scnndx) 4768a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return true; 4778a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 4788a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4798a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper runp = runp->next; 4808a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 4818a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper while (runp != NULL); 4828a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4838a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return false; 4848a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 4858a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4868a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4878a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int 4888a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Dreppershow_relocs (Ebl *ebl, const char *fname, uint32_t shstrndx) 4898a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 4908a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int elfclass = gelf_getclass (ebl->elf); 4918a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4928a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Scn *scn = NULL; 4938a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) 4948a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 4958a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr shdr_mem; 4968a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); 4978a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 4988a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (shdr == NULL) 4998a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper INTERNAL_ERROR (fname); 5008a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5018a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA) 5028a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 5038a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (! section_match (ebl->elf, elf_ndxscn (scn), shdr, shstrndx)) 5048a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper continue; 5058a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5068a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr destshdr_mem; 5078a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr *destshdr = gelf_getshdr (elf_getscn (ebl->elf, 5088a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper shdr->sh_info), 5098a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper &destshdr_mem); 5108a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 511cbb422eb102660d97209ec632e3b6572f0b0c7a6Ulrich Drepper printf (gettext ("\n\nRELOCATION RECORDS FOR [%s]:\n" 5128a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper "%-*s TYPE VALUE\n"), 5138a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper elf_strptr (ebl->elf, shstrndx, destshdr->sh_name), 5148a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper elfclass == ELFCLASS32 ? 8 : 16, gettext ("OFFSET")); 5158a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5168a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Get the data of the section. */ 5178a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Data *data = elf_getdata (scn, NULL); 5188a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (data == NULL) 5198a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper continue; 5208a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5218a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Get the symbol table information. */ 5228a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Scn *symscn = elf_getscn (ebl->elf, shdr->sh_link); 5238a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr symshdr_mem; 5248a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr *symshdr = gelf_getshdr (symscn, &symshdr_mem); 5258a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Data *symdata = elf_getdata (symscn, NULL); 5268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Search for the optional extended section index table. */ 5288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Data *xndxdata = NULL; 5298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Scn *xndxscn = NULL; 5308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper while ((xndxscn = elf_nextscn (ebl->elf, xndxscn)) != NULL) 5318a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 5328a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr xndxshdr_mem; 5338a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr *xndxshdr; 5348a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5358a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper xndxshdr = gelf_getshdr (xndxscn, &xndxshdr_mem); 5368a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (xndxshdr != NULL && xndxshdr->sh_type == SHT_SYMTAB_SHNDX 5378a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper && xndxshdr->sh_link == elf_ndxscn (symscn)) 5388a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 5398a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Found it. */ 5408a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper xndxdata = elf_getdata (xndxscn, NULL); 5418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper break; 5428a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 5438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 5448a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5458a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (shdr->sh_type == SHT_REL) 5468a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper show_relocs_rel (ebl, shdr, data, symdata, xndxdata, 5478a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper symshdr->sh_link, shstrndx); 5488a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper else 5498a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper show_relocs_rela (ebl, shdr, data, symdata, xndxdata, 5508a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper symshdr->sh_link, shstrndx); 5518a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 5528a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 5538a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5548a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputs_unlocked ("\n\n", stdout); 5558a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5568a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return 0; 5578a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 5588a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5598a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5608a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int 5618a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Dreppershow_full_content (Ebl *ebl, const char *fname, uint32_t shstrndx) 5628a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 5638a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Scn *scn = NULL; 5648a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) 5658a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 5668a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr shdr_mem; 5678a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); 5688a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5698a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (shdr == NULL) 5708a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper INTERNAL_ERROR (fname); 5718a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5728a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (shdr->sh_type == SHT_PROGBITS && shdr->sh_size > 0) 5738a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 5748a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (! section_match (ebl->elf, elf_ndxscn (scn), shdr, shstrndx)) 5758a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper continue; 5768a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5778a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper printf (gettext ("Contents of section %s:\n"), 5788a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper elf_strptr (ebl->elf, shstrndx, shdr->sh_name)); 5798a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5808a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Get the data of the section. */ 5818a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Elf_Data *data = elf_getdata (scn, NULL); 5828a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (data == NULL) 5838a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper continue; 5848a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5858a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper unsigned char *cp = data->d_buf; 5868a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t cnt; 5878a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (cnt = 0; cnt + 16 < data->d_size; cp += 16, cnt += 16) 5888a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper { 5898a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper printf (" %04zx ", cnt); 5908a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5918a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (size_t inner = 0; inner < 16; inner += 4) 5928a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper printf ("%02hhx%02hhx%02hhx%02hhx ", 5938a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp[inner], cp[inner + 1], cp[inner + 2], 5948a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp[inner + 3]); 5958a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputc_unlocked (' ', stdout); 5968a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 5978a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (size_t inner = 0; inner < 16; ++inner) 5988a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputc_unlocked (isascii (cp[inner]) && isprint (cp[inner]) 5998a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper ? cp[inner] : '.', stdout); 6008a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputc_unlocked ('\n', stdout); 6018a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 6028a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6038a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper printf (" %04zx ", cnt); 6048a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6058a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t remaining = data->d_size - cnt; 6068a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t inner; 6078a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (inner = 0; inner + 4 <= remaining; inner += 4) 6088a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper printf ("%02hhx%02hhx%02hhx%02hhx ", 6098a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp[inner], cp[inner + 1], cp[inner + 2], cp[inner + 3]); 6108a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6118a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (; inner < remaining; ++inner) 6128a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper printf ("%02hhx", cp[inner]); 6138a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6148a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (inner = 2 * (16 - inner) + (16 - inner + 3) / 4 + 1; inner > 0; 6158a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper --inner) 6168a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputc_unlocked (' ', stdout); 6178a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6188a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper for (inner = 0; inner < remaining; ++inner) 6198a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputc_unlocked (isascii (cp[inner]) && isprint (cp[inner]) 6208a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper ? cp[inner] : '.', stdout); 6218a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputc_unlocked ('\n', stdout); 6228a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6238a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fputc_unlocked ('\n', stdout); 6248a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 6258a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper } 6268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return 0; 6288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 6298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 6313cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepperstruct disasm_info 6323cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper{ 6333cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper GElf_Addr addr; 6343cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper const uint8_t *cur; 6353cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper const uint8_t *last_end; 6363cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper}; 6373cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6383cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6393cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper// XXX This is not the preferred output for all architectures. Needs 6403cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper// XXX customization, too. 6418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int 6423cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepperdisasm_output (char *buf, size_t buflen, void *arg) 6438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 6443cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper struct disasm_info *info = (struct disasm_info *) arg; 6453cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6463cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper printf ("%8" PRIx64 ": ", (uint64_t) info->addr); 6473cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper size_t cnt; 6483cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper for (cnt = 0; cnt < (size_t) MIN (info->cur - info->last_end, 8); ++cnt) 6493cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper printf (" %02" PRIx8, info->last_end[cnt]); 6503cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper printf ("%*s %.*s\n", 6513cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper (int) (8 - cnt) * 3 + 1, "", (int) buflen, buf); 6523cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6533cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper info->addr += cnt; 6543cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6553cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper /* We limit the number of bytes printed before the mnemonic to 8. 6563cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper Print the rest on a separate, following line. */ 6573cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper if (info->cur - info->last_end > 8) 6583cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper { 6593cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper printf ("%8" PRIx64 ": ", (uint64_t) info->addr); 6603cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper for (; cnt < (size_t) (info->cur - info->last_end); ++cnt) 6613cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper printf (" %02" PRIx8, info->last_end[cnt]); 6623cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper putchar_unlocked ('\n'); 6633cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper info->addr += info->cur - info->last_end - 8; 6643cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper } 6653cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6663cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper info->last_end = info->cur; 6673cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6683cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper return 0; 6693cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper} 6703cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6713cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6723cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepperstatic int 6733cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Dreppershow_disasm (Ebl *ebl, const char *fname, uint32_t shstrndx) 6743cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper{ 6753cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper DisasmCtx_t *ctx = disasm_begin (ebl, ebl->elf, NULL /* XXX TODO */); 6763cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper if (ctx == NULL) 6773cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper error (EXIT_FAILURE, 0, gettext ("cannot disassemble")); 6783cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6793cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper Elf_Scn *scn = NULL; 6803cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) 6813cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper { 6823cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper GElf_Shdr shdr_mem; 6833cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); 6843cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6853cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper if (shdr == NULL) 6863cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper INTERNAL_ERROR (fname); 6873cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6883cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper if (shdr->sh_type == SHT_PROGBITS && shdr->sh_size > 0 6893cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper && (shdr->sh_flags & SHF_EXECINSTR) != 0) 6903cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper { 6913cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper if (! section_match (ebl->elf, elf_ndxscn (scn), shdr, shstrndx)) 6923cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper continue; 6933cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6943cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper Elf_Data *data = elf_getdata (scn, NULL); 6953cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper if (data == NULL) 6963cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper continue; 6973cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 6983cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper printf ("Disassembly of section %s:\n\n", 6993cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper elf_strptr (ebl->elf, shstrndx, shdr->sh_name)); 7003cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 7013cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper struct disasm_info info; 7023cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper info.addr = shdr->sh_addr; 7033cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper info.last_end = info.cur = data->d_buf; 7043cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 7053cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper disasm_cb (ctx, &info.cur, info.cur + data->d_size, info.addr, 706fd47989094090138b0c857d067ac7ff05e7b6d91Ulrich Drepper "%7m %.1o,%.2o,%.3o%34a %l", disasm_output, &info, 7073cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper NULL /* XXX */); 7083cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper } 7093cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper } 7103cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 7113cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper (void) disasm_end (ctx); 7128a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7138a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return 0; 7148a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 7158a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7168a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7178a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperstatic int 7188a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepperhandle_elf (Elf *elf, const char *prefix, const char *fname, 7198a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper const char *suffix) 7208a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper{ 7218a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7228a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Get the backend for this object file type. */ 7238a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper Ebl *ebl = ebl_openbackend (elf); 7248a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 725fd47989094090138b0c857d067ac7ff05e7b6d91Ulrich Drepper printf ("%s: elf%d-%s\n\n", 7268a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper fname, gelf_getclass (elf) == ELFCLASS32 ? 32 : 64, 7278a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper ebl_backend_name (ebl)); 7288a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7298a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Create the full name of the file. */ 7308a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t prefix_len = prefix == NULL ? 0 : strlen (prefix); 7318a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t suffix_len = suffix == NULL ? 0 : strlen (suffix); 7328a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t fname_len = strlen (fname) + 1; 7338a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper char fullname[prefix_len + 1 + fname_len + suffix_len]; 7348a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper char *cp = fullname; 7358a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (prefix != NULL) 7368a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp = mempcpy (cp, prefix, prefix_len); 7378a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper cp = mempcpy (cp, fname, fname_len); 7388a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (suffix != NULL) 7398a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper memcpy (cp - 1, suffix, suffix_len + 1); 7408a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7418a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Get the section header string table index. */ 7428a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper size_t shstrndx; 7438a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (elf_getshstrndx (ebl->elf, &shstrndx) < 0) 7448a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper error (EXIT_FAILURE, 0, 7458a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper gettext ("cannot get section header string table index")); 7468a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7478a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper int result = 0; 7488a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (print_disasm) 7498a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result = show_disasm (ebl, fullname, shstrndx); 7508a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (print_relocs && !print_disasm) 7518a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result = show_relocs (ebl, fullname, shstrndx); 7528a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper if (print_full_content) 7538a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper result = show_full_content (ebl, fullname, shstrndx); 7548a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7558a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper /* Close the ELF backend library descriptor. */ 7568a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper ebl_closebackend (ebl); 7578a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper 7588a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper return result; 7598a68774cdbe5609c50d7ee9dad3b6040e4f5fbe1Ulrich Drepper} 7603cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 7613cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 7623cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper#include "debugpred.h" 763