Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | /* readelf.c -- display contents of an ELF format file |
2 | Copyright (C) 1998, 1999 Free Software Foundation, Inc. | |
3 | ||
4 | Originally developed by Eric Youngdale <eric@andante.jic.com> | |
5 | Modifications by Nick Clifton <nickc@cygnus.com> | |
6 | ||
7 | This file is part of GNU Binutils. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
22 | 02111-1307, USA. */ | |
23 | \f | |
24 | ||
25 | #include <assert.h> | |
26 | #include <sys/stat.h> | |
27 | #include <stdio.h> | |
28 | #include <time.h> | |
29 | ||
a952a375 | 30 | #if __GNUC__ >= 2 |
19936277 | 31 | /* Define BFD64 here, even if our default architecture is 32 bit ELF |
a952a375 NC |
32 | as this will allow us to read in and parse 64bit and 32bit ELF files. |
33 | Only do this if we belive that the compiler can support a 64 bit | |
34 | data type. For now we only rely on GCC being able to do this. */ | |
19936277 | 35 | #define BFD64 |
a952a375 NC |
36 | #endif |
37 | ||
252b5132 RH |
38 | #include "bfd.h" |
39 | ||
40 | #include "elf/common.h" | |
41 | #include "elf/external.h" | |
42 | #include "elf/internal.h" | |
43 | #include "elf/dwarf2.h" | |
44 | ||
45 | /* The following headers use the elf/reloc-macros.h file to | |
46 | automatically generate relocation recognition functions | |
47 | such as elf_mips_reloc_type() */ | |
48 | ||
49 | #define RELOC_MACROS_GEN_FUNC | |
50 | ||
51 | #include "elf/i386.h" | |
52 | #include "elf/v850.h" | |
53 | #include "elf/ppc.h" | |
54 | #include "elf/mips.h" | |
55 | #include "elf/alpha.h" | |
56 | #include "elf/arm.h" | |
57 | #include "elf/m68k.h" | |
58 | #include "elf/sparc.h" | |
59 | #include "elf/m32r.h" | |
60 | #include "elf/d10v.h" | |
61 | #include "elf/d30v.h" | |
62 | #include "elf/sh.h" | |
63 | #include "elf/mn10200.h" | |
64 | #include "elf/mn10300.h" | |
65 | #include "elf/hppa.h" | |
66 | #include "elf/arc.h" | |
67 | #include "elf/fr30.h" | |
68 | #include "elf/mcore.h" | |
63fcb9e9 | 69 | #include "elf/i960.h" |
252b5132 RH |
70 | |
71 | #include "bucomm.h" | |
72 | #include "getopt.h" | |
73 | ||
74 | #ifdef ANSI_PROTOTYPES | |
75 | #include <stdarg.h> | |
76 | #else | |
77 | #include <varargs.h> | |
78 | #endif | |
79 | ||
80 | char * program_name = "readelf"; | |
81 | unsigned int dynamic_addr; | |
9ea033b2 | 82 | bfd_size_type dynamic_size; |
252b5132 RH |
83 | unsigned int rela_addr; |
84 | unsigned int rela_size; | |
85 | char * dynamic_strings; | |
86 | char * string_table; | |
19936277 | 87 | unsigned long num_dynamic_syms; |
252b5132 RH |
88 | Elf_Internal_Sym * dynamic_symbols; |
89 | Elf_Internal_Syminfo * dynamic_syminfo; | |
90 | unsigned long dynamic_syminfo_offset; | |
91 | unsigned int dynamic_syminfo_nent; | |
92 | char program_interpreter [64]; | |
93 | int dynamic_info[DT_JMPREL + 1]; | |
94 | int version_info[16]; | |
95 | int loadaddr = 0; | |
96 | Elf_Internal_Ehdr elf_header; | |
97 | Elf_Internal_Shdr * section_headers; | |
98 | Elf_Internal_Dyn * dynamic_segment; | |
99 | int show_name; | |
100 | int do_dynamic; | |
101 | int do_syms; | |
102 | int do_reloc; | |
103 | int do_sections; | |
104 | int do_segments; | |
105 | int do_using_dynamic; | |
106 | int do_header; | |
107 | int do_dump; | |
108 | int do_version; | |
109 | int do_histogram; | |
110 | int do_debugging; | |
111 | int do_debug_info; | |
112 | int do_debug_abbrevs; | |
113 | int do_debug_lines; | |
114 | int do_debug_pubnames; | |
115 | int do_debug_aranges; | |
a952a375 | 116 | int do_arch; |
9ea033b2 | 117 | int is_32bit_elf; |
252b5132 RH |
118 | |
119 | /* A dynamic array of flags indicating which sections require dumping. */ | |
120 | char * dump_sects = NULL; | |
121 | unsigned int num_dump_sects = 0; | |
122 | ||
123 | #define HEX_DUMP (1 << 0) | |
124 | #define DISASS_DUMP (1 << 1) | |
125 | #define DEBUG_DUMP (1 << 2) | |
126 | ||
127 | /* Forward declarations for dumb compilers. */ | |
9ea033b2 NC |
128 | static bfd_vma (* byte_get) PARAMS ((unsigned char *, int)); |
129 | static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int)); | |
130 | static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int)); | |
131 | static const char * get_mips_dynamic_type PARAMS ((unsigned long)); | |
9a097730 | 132 | static const char * get_sparc64_dynamic_type PARAMS ((unsigned long)); |
9ea033b2 | 133 | static const char * get_dynamic_type PARAMS ((unsigned long)); |
19936277 | 134 | static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int)); |
9ea033b2 NC |
135 | static char * get_file_type PARAMS ((unsigned)); |
136 | static char * get_machine_name PARAMS ((unsigned)); | |
137 | static char * get_machine_flags PARAMS ((unsigned, unsigned)); | |
138 | static const char * get_mips_segment_type PARAMS ((unsigned long)); | |
139 | static const char * get_segment_type PARAMS ((unsigned long)); | |
140 | static const char * get_mips_section_type_name PARAMS ((unsigned int)); | |
141 | static const char * get_section_type_name PARAMS ((unsigned int)); | |
142 | static char * get_symbol_binding PARAMS ((unsigned int)); | |
143 | static char * get_symbol_type PARAMS ((unsigned int)); | |
252b5132 | 144 | static void usage PARAMS ((void)); |
9ea033b2 | 145 | static void parse_args PARAMS ((int, char **)); |
252b5132 RH |
146 | static int process_file_header PARAMS ((void)); |
147 | static int process_program_headers PARAMS ((FILE *)); | |
148 | static int process_section_headers PARAMS ((FILE *)); | |
9ea033b2 | 149 | static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *)); |
252b5132 RH |
150 | static int process_dynamic_segment PARAMS ((FILE *)); |
151 | static int process_symbol_table PARAMS ((FILE *)); | |
152 | static int process_section_contents PARAMS ((FILE *)); | |
9ea033b2 | 153 | static void process_file PARAMS ((char *)); |
252b5132 RH |
154 | static int process_relocs PARAMS ((FILE *)); |
155 | static int process_version_sections PARAMS ((FILE *)); | |
9ea033b2 NC |
156 | static char * get_ver_flags PARAMS ((unsigned int)); |
157 | static char * get_symbol_index_type PARAMS ((unsigned int)); | |
158 | static int get_32bit_section_headers PARAMS ((FILE *)); | |
159 | static int get_64bit_section_headers PARAMS ((FILE *)); | |
160 | static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *)); | |
161 | static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *)); | |
162 | static int get_file_header PARAMS ((FILE *)); | |
163 | static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long)); | |
164 | static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long)); | |
165 | static int * get_dynamic_data PARAMS ((FILE *, unsigned int)); | |
166 | static int get_32bit_dynamic_segment PARAMS ((FILE *)); | |
167 | static int get_64bit_dynamic_segment PARAMS ((FILE *)); | |
252b5132 RH |
168 | #ifdef SUPPORT_DISASSEMBLY |
169 | static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); | |
170 | #endif | |
171 | static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); | |
172 | static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); | |
173 | static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
174 | static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
175 | static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
176 | static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
177 | static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
178 | static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *)); | |
179 | static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int)); | |
3590ea00 | 180 | static int process_extended_line_op PARAMS ((unsigned char *, int, int)); |
252b5132 RH |
181 | static void reset_state_machine PARAMS ((int)); |
182 | static char * get_TAG_name PARAMS ((unsigned long)); | |
183 | static char * get_AT_name PARAMS ((unsigned long)); | |
184 | static char * get_FORM_name PARAMS ((unsigned long)); | |
185 | static void free_abbrevs PARAMS ((void)); | |
186 | static void add_abbrev PARAMS ((unsigned long, unsigned long, int)); | |
187 | static void add_abbrev_attr PARAMS ((unsigned long, unsigned long)); | |
188 | static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long)); | |
189 | static unsigned char * display_block PARAMS ((unsigned char *, unsigned long)); | |
190 | static void decode_location_expression PARAMS ((unsigned char *, unsigned int)); | |
191 | static void request_dump PARAMS ((unsigned int, char)); | |
192 | static const char * get_elf_class PARAMS ((unsigned char)); | |
193 | static const char * get_data_encoding PARAMS ((unsigned char)); | |
194 | static const char * get_osabi_name PARAMS ((unsigned char)); | |
9c19a809 | 195 | static int guess_is_rela PARAMS ((unsigned long)); |
252b5132 RH |
196 | |
197 | typedef int Elf32_Word; | |
198 | ||
9c19a809 NC |
199 | #ifndef TRUE |
200 | #define TRUE 1 | |
201 | #define FALSE 0 | |
202 | #endif | |
203 | #define UNKNOWN -1 | |
204 | ||
252b5132 RH |
205 | #define SECTION_NAME(X) (string_table + (X)->sh_name) |
206 | ||
207 | #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ | |
208 | ||
209 | #define BYTE_GET(field) byte_get (field, sizeof (field)) | |
a952a375 NC |
210 | |
211 | /* If we can support a 64 bit data type then BFD64 should be defined | |
212 | and sizeof (bfd_vma) == 8. In this case when translating from an | |
213 | external 8 byte field to an internal field, we can assume that the | |
214 | internal field is also 8 bytes wide and so we can extact all the data. | |
215 | If, however, BFD64 is not defined, then we must assume that the | |
216 | internal data structure only has 4 byte wide fields that are the | |
217 | equivalent of the 8 byte wide external counterparts, and so we must | |
218 | truncate the data. */ | |
219 | #ifdef BFD64 | |
9ea033b2 | 220 | #define BYTE_GET8(field) byte_get (field, -8) |
a952a375 NC |
221 | #else |
222 | #define BYTE_GET8(field) byte_get (field, 8) | |
223 | #endif | |
252b5132 RH |
224 | |
225 | #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0])) | |
226 | ||
227 | #define GET_DATA_ALLOC(offset, size, var, type, reason) \ | |
228 | if (fseek (file, offset, SEEK_SET)) \ | |
229 | { \ | |
230 | error (_("Unable to seek to start of %s at %x\n"), reason, offset); \ | |
231 | return 0; \ | |
232 | } \ | |
233 | \ | |
234 | var = (type) malloc (size); \ | |
235 | \ | |
236 | if (var == NULL) \ | |
237 | { \ | |
238 | error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \ | |
239 | return 0; \ | |
240 | } \ | |
241 | \ | |
242 | if (fread (var, size, 1, file) != 1) \ | |
243 | { \ | |
244 | error (_("Unable to read in %d bytes of %s\n"), size, reason); \ | |
245 | free (var); \ | |
246 | var = NULL; \ | |
247 | return 0; \ | |
248 | } | |
249 | ||
250 | ||
251 | #define GET_DATA(offset, var, reason) \ | |
252 | if (fseek (file, offset, SEEK_SET)) \ | |
253 | { \ | |
254 | error (_("Unable to seek to %x for %s\n"), offset, reason); \ | |
255 | return 0; \ | |
256 | } \ | |
257 | else if (fread (& var, sizeof (var), 1, file) != 1) \ | |
258 | { \ | |
259 | error (_("Unable to read data at %x for %s\n"), offset, reason); \ | |
260 | return 0; \ | |
261 | } | |
262 | ||
9ea033b2 NC |
263 | #define GET_ELF_SYMBOLS(file, offset, size) \ |
264 | (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \ | |
265 | : get_64bit_elf_symbols (file, offset, size)) | |
266 | ||
267 | ||
252b5132 RH |
268 | #ifdef ANSI_PROTOTYPES |
269 | static void | |
270 | error (const char * message, ...) | |
271 | { | |
272 | va_list args; | |
273 | ||
274 | fprintf (stderr, _("%s: Error: "), program_name); | |
275 | va_start (args, message); | |
276 | vfprintf (stderr, message, args); | |
277 | va_end (args); | |
278 | return; | |
279 | } | |
280 | ||
281 | static void | |
282 | warn (const char * message, ...) | |
283 | { | |
284 | va_list args; | |
285 | ||
286 | fprintf (stderr, _("%s: Warning: "), program_name); | |
287 | va_start (args, message); | |
288 | vfprintf (stderr, message, args); | |
289 | va_end (args); | |
290 | return; | |
291 | } | |
292 | #else | |
293 | static void | |
294 | error (va_alist) | |
295 | va_dcl | |
296 | { | |
297 | char * message; | |
298 | va_list args; | |
299 | ||
300 | fprintf (stderr, _("%s: Error: "), program_name); | |
301 | va_start (args); | |
302 | message = va_arg (args, char *); | |
303 | vfprintf (stderr, message, args); | |
304 | va_end (args); | |
305 | return; | |
306 | } | |
307 | ||
308 | static void | |
309 | warn (va_alist) | |
310 | va_dcl | |
311 | { | |
312 | char * message; | |
313 | va_list args; | |
314 | ||
315 | fprintf (stderr, _("%s: Warning: "), program_name); | |
316 | va_start (args); | |
317 | message = va_arg (args, char *); | |
318 | vfprintf (stderr, message, args); | |
319 | va_end (args); | |
320 | return; | |
321 | } | |
322 | #endif | |
323 | ||
9ea033b2 | 324 | static bfd_vma |
252b5132 RH |
325 | byte_get_little_endian (field, size) |
326 | unsigned char * field; | |
327 | int size; | |
328 | { | |
329 | switch (size) | |
330 | { | |
331 | case 1: | |
332 | return * field; | |
333 | ||
334 | case 2: | |
335 | return ((unsigned int) (field [0])) | |
336 | | (((unsigned int) (field [1])) << 8); | |
337 | ||
9ea033b2 NC |
338 | case 8: |
339 | /* We want to extract data from an 8 byte wide field and | |
340 | place it into a 4 byte wide field. Since this is a little | |
341 | endian source we can juts use the 4 byte extraction code. */ | |
342 | /* Fall through. */ | |
252b5132 RH |
343 | case 4: |
344 | return ((unsigned long) (field [0])) | |
345 | | (((unsigned long) (field [1])) << 8) | |
346 | | (((unsigned long) (field [2])) << 16) | |
347 | | (((unsigned long) (field [3])) << 24); | |
348 | ||
a952a375 | 349 | #ifdef BFD64 |
9ea033b2 NC |
350 | case -8: |
351 | /* This is a special case, generated by the BYTE_GET8 macro. | |
352 | It means that we are loading an 8 byte value from a field | |
353 | in an external structure into an 8 byte value in a field | |
354 | in an internal strcuture. */ | |
355 | return ((bfd_vma) (field [0])) | |
356 | | (((bfd_vma) (field [1])) << 8) | |
357 | | (((bfd_vma) (field [2])) << 16) | |
358 | | (((bfd_vma) (field [3])) << 24) | |
359 | | (((bfd_vma) (field [4])) << 32) | |
360 | | (((bfd_vma) (field [5])) << 40) | |
361 | | (((bfd_vma) (field [6])) << 48) | |
362 | | (((bfd_vma) (field [7])) << 56); | |
a952a375 | 363 | #endif |
252b5132 RH |
364 | default: |
365 | error (_("Unhandled data length: %d\n"), size); | |
9ea033b2 | 366 | abort (); |
252b5132 RH |
367 | } |
368 | } | |
369 | ||
9ea033b2 | 370 | static bfd_vma |
252b5132 RH |
371 | byte_get_big_endian (field, size) |
372 | unsigned char * field; | |
373 | int size; | |
374 | { | |
375 | switch (size) | |
376 | { | |
377 | case 1: | |
378 | return * field; | |
379 | ||
380 | case 2: | |
381 | return ((unsigned int) (field [1])) | (((int) (field [0])) << 8); | |
382 | ||
383 | case 4: | |
384 | return ((unsigned long) (field [3])) | |
385 | | (((unsigned long) (field [2])) << 8) | |
386 | | (((unsigned long) (field [1])) << 16) | |
387 | | (((unsigned long) (field [0])) << 24); | |
388 | ||
9ea033b2 NC |
389 | case 8: |
390 | /* Although we are extracing data from an 8 byte wide field, we | |
391 | are returning only 4 bytes of data. */ | |
392 | return ((unsigned long) (field [7])) | |
393 | | (((unsigned long) (field [6])) << 8) | |
394 | | (((unsigned long) (field [5])) << 16) | |
395 | | (((unsigned long) (field [4])) << 24); | |
396 | ||
a952a375 | 397 | #ifdef BFD64 |
9ea033b2 NC |
398 | case -8: |
399 | /* This is a special case, generated by the BYTE_GET8 macro. | |
400 | It means that we are loading an 8 byte value from a field | |
401 | in an external structure into an 8 byte value in a field | |
402 | in an internal strcuture. */ | |
403 | return ((bfd_vma) (field [7])) | |
404 | | (((bfd_vma) (field [6])) << 8) | |
405 | | (((bfd_vma) (field [5])) << 16) | |
406 | | (((bfd_vma) (field [4])) << 24) | |
407 | | (((bfd_vma) (field [3])) << 32) | |
408 | | (((bfd_vma) (field [2])) << 40) | |
409 | | (((bfd_vma) (field [1])) << 48) | |
410 | | (((bfd_vma) (field [0])) << 56); | |
a952a375 | 411 | #endif |
9ea033b2 | 412 | |
252b5132 RH |
413 | default: |
414 | error (_("Unhandled data length: %d\n"), size); | |
9ea033b2 | 415 | abort (); |
252b5132 RH |
416 | } |
417 | } | |
418 | ||
419 | ||
9c19a809 | 420 | /* Guess the relocation sized based on the sized commonly used by the specific machine. */ |
252b5132 | 421 | static int |
9c19a809 NC |
422 | guess_is_rela (e_machine) |
423 | unsigned long e_machine; | |
252b5132 | 424 | { |
9c19a809 | 425 | switch (e_machine) |
252b5132 RH |
426 | { |
427 | /* Targets that use REL relocations. */ | |
428 | case EM_ARM: | |
429 | case EM_386: | |
430 | case EM_486: | |
63fcb9e9 | 431 | case EM_960: |
252b5132 RH |
432 | case EM_CYGNUS_M32R: |
433 | case EM_CYGNUS_D10V: | |
434 | case EM_MIPS: | |
435 | case EM_MIPS_RS4_BE: | |
9c19a809 NC |
436 | return FALSE; |
437 | ||
252b5132 RH |
438 | /* Targets that use RELA relocations. */ |
439 | case EM_68K: | |
351b4b40 RH |
440 | case EM_SPARC32PLUS: |
441 | case EM_SPARCV9: | |
252b5132 RH |
442 | case EM_SPARC: |
443 | case EM_PPC: | |
444 | case EM_CYGNUS_V850: | |
445 | case EM_CYGNUS_D30V: | |
446 | case EM_CYGNUS_MN10200: | |
447 | case EM_CYGNUS_MN10300: | |
448 | case EM_CYGNUS_FR30: | |
449 | case EM_SH: | |
450 | case EM_ALPHA: | |
451 | case EM_MCORE: | |
9c19a809 NC |
452 | return TRUE; |
453 | ||
454 | default: | |
455 | warn (_("Don't know about relocations on this machine architecture\n")); | |
456 | return FALSE; | |
457 | } | |
458 | } | |
252b5132 | 459 | |
9ea033b2 | 460 | /* Display the contents of the relocation data found at the specified offset. */ |
9c19a809 | 461 | static int |
19936277 | 462 | dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela) |
9ea033b2 NC |
463 | FILE * file; |
464 | unsigned long rel_offset; | |
465 | unsigned long rel_size; | |
466 | Elf_Internal_Sym * symtab; | |
19936277 | 467 | unsigned long nsyms; |
9ea033b2 NC |
468 | char * strtab; |
469 | int is_rela; | |
9c19a809 NC |
470 | { |
471 | unsigned int i; | |
472 | Elf_Internal_Rel * rels; | |
473 | Elf_Internal_Rela * relas; | |
252b5132 | 474 | |
9c19a809 NC |
475 | |
476 | if (is_rela == UNKNOWN) | |
477 | is_rela = guess_is_rela (elf_header.e_machine); | |
252b5132 | 478 | |
9c19a809 NC |
479 | if (is_rela) |
480 | { | |
9ea033b2 NC |
481 | if (is_32bit_elf) |
482 | { | |
483 | Elf32_External_Rela * erelas; | |
484 | ||
485 | GET_DATA_ALLOC (rel_offset, rel_size, erelas, | |
486 | Elf32_External_Rela *, "relocs"); | |
487 | ||
488 | rel_size = rel_size / sizeof (Elf32_External_Rela); | |
489 | ||
490 | relas = (Elf_Internal_Rela *) | |
491 | malloc (rel_size * sizeof (Elf_Internal_Rela)); | |
9c19a809 | 492 | |
9ea033b2 NC |
493 | if (relas == NULL) |
494 | { | |
495 | error(_("out of memory parsing relocs")); | |
496 | return 0; | |
497 | } | |
498 | ||
499 | for (i = 0; i < rel_size; i++) | |
500 | { | |
501 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
502 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
503 | relas[i].r_addend = BYTE_GET (erelas[i].r_addend); | |
504 | } | |
9c19a809 | 505 | |
9ea033b2 | 506 | free (erelas); |
9c19a809 | 507 | |
9ea033b2 | 508 | rels = (Elf_Internal_Rel *) relas; |
9c19a809 | 509 | } |
9ea033b2 | 510 | else |
9c19a809 | 511 | { |
9ea033b2 NC |
512 | Elf64_External_Rela * erelas; |
513 | ||
514 | GET_DATA_ALLOC (rel_offset, rel_size, erelas, | |
515 | Elf64_External_Rela *, "relocs"); | |
516 | ||
517 | rel_size = rel_size / sizeof (Elf64_External_Rela); | |
518 | ||
519 | relas = (Elf_Internal_Rela *) | |
520 | malloc (rel_size * sizeof (Elf_Internal_Rela)); | |
521 | ||
522 | if (relas == NULL) | |
523 | { | |
524 | error(_("out of memory parsing relocs")); | |
525 | return 0; | |
526 | } | |
527 | ||
528 | for (i = 0; i < rel_size; i++) | |
529 | { | |
530 | relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset); | |
531 | relas[i].r_info = BYTE_GET8 (erelas[i].r_info); | |
532 | relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend); | |
533 | } | |
9c19a809 | 534 | |
9ea033b2 | 535 | free (erelas); |
9c19a809 | 536 | |
9ea033b2 NC |
537 | rels = (Elf_Internal_Rel *) relas; |
538 | } | |
9c19a809 NC |
539 | } |
540 | else | |
541 | { | |
9ea033b2 | 542 | if (is_32bit_elf) |
9c19a809 | 543 | { |
9ea033b2 NC |
544 | Elf32_External_Rel * erels; |
545 | ||
546 | GET_DATA_ALLOC (rel_offset, rel_size, erels, | |
547 | Elf32_External_Rel *, "relocs"); | |
548 | ||
549 | rel_size = rel_size / sizeof (Elf32_External_Rel); | |
550 | ||
551 | rels = (Elf_Internal_Rel *) | |
552 | malloc (rel_size * sizeof (Elf_Internal_Rel)); | |
553 | ||
554 | if (rels == NULL) | |
555 | { | |
556 | error(_("out of memory parsing relocs")); | |
557 | return 0; | |
558 | } | |
559 | ||
560 | for (i = 0; i < rel_size; i++) | |
561 | { | |
562 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
563 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
564 | } | |
565 | ||
566 | free (erels); | |
567 | ||
568 | relas = (Elf_Internal_Rela *) rels; | |
9c19a809 | 569 | } |
9ea033b2 | 570 | else |
9c19a809 | 571 | { |
9ea033b2 NC |
572 | Elf64_External_Rel * erels; |
573 | ||
574 | GET_DATA_ALLOC (rel_offset, rel_size, erels, | |
575 | Elf64_External_Rel *, "relocs"); | |
576 | ||
577 | rel_size = rel_size / sizeof (Elf64_External_Rel); | |
578 | ||
579 | rels = (Elf_Internal_Rel *) | |
580 | malloc (rel_size * sizeof (Elf_Internal_Rel)); | |
581 | ||
582 | if (rels == NULL) | |
583 | { | |
584 | error(_("out of memory parsing relocs")); | |
585 | return 0; | |
586 | } | |
587 | ||
588 | for (i = 0; i < rel_size; i++) | |
589 | { | |
590 | rels[i].r_offset = BYTE_GET8 (erels[i].r_offset); | |
591 | rels[i].r_info = BYTE_GET8 (erels[i].r_info); | |
592 | } | |
593 | ||
594 | free (erels); | |
595 | ||
596 | relas = (Elf_Internal_Rela *) rels; | |
9c19a809 | 597 | } |
252b5132 RH |
598 | } |
599 | ||
600 | if (is_rela) | |
601 | printf | |
602 | (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n")); | |
603 | else | |
604 | printf | |
605 | (_(" Offset Info Type Symbol's Value Symbol's Name\n")); | |
606 | ||
607 | for (i = 0; i < rel_size; i++) | |
608 | { | |
9ea033b2 NC |
609 | const char * rtype; |
610 | bfd_vma offset; | |
611 | bfd_vma info; | |
612 | bfd_vma symtab_index; | |
613 | bfd_vma type; | |
614 | ||
252b5132 RH |
615 | if (is_rela) |
616 | { | |
617 | offset = relas [i].r_offset; | |
618 | info = relas [i].r_info; | |
619 | } | |
620 | else | |
621 | { | |
622 | offset = rels [i].r_offset; | |
623 | info = rels [i].r_info; | |
624 | } | |
9ea033b2 NC |
625 | |
626 | if (is_32bit_elf) | |
627 | { | |
628 | type = ELF32_R_TYPE (info); | |
629 | symtab_index = ELF32_R_SYM (info); | |
630 | } | |
631 | else | |
632 | { | |
351b4b40 RH |
633 | if (elf_header.e_machine == EM_SPARCV9) |
634 | type = ELF64_R_TYPE_ID (info); | |
635 | else | |
636 | type = ELF64_R_TYPE (info); | |
a952a375 NC |
637 | /* The #ifdef BFD64 below is to prevent a compile time warning. |
638 | We know that if we do not have a 64 bit data type that we | |
639 | will never execute this code anyway. */ | |
640 | #ifdef BFD64 | |
9ea033b2 | 641 | symtab_index = ELF64_R_SYM (info); |
a952a375 | 642 | #endif |
9ea033b2 | 643 | } |
252b5132 | 644 | |
9ea033b2 NC |
645 | #ifdef _bfd_int64_low |
646 | printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info)); | |
647 | #else | |
648 | printf (" %8.8lx %5.5lx ", offset, info); | |
649 | #endif | |
650 | ||
252b5132 RH |
651 | switch (elf_header.e_machine) |
652 | { | |
653 | default: | |
654 | rtype = NULL; | |
655 | break; | |
656 | ||
657 | case EM_CYGNUS_M32R: | |
9ea033b2 | 658 | rtype = elf_m32r_reloc_type (type); |
252b5132 RH |
659 | break; |
660 | ||
661 | case EM_386: | |
662 | case EM_486: | |
9ea033b2 | 663 | rtype = elf_i386_reloc_type (type); |
252b5132 RH |
664 | break; |
665 | ||
666 | case EM_68K: | |
9ea033b2 | 667 | rtype = elf_m68k_reloc_type (type); |
252b5132 RH |
668 | break; |
669 | ||
63fcb9e9 | 670 | case EM_960: |
9ea033b2 | 671 | rtype = elf_i960_reloc_type (type); |
63fcb9e9 ILT |
672 | break; |
673 | ||
9ea033b2 NC |
674 | case EM_OLD_SPARCV9: |
675 | case EM_SPARC32PLUS: | |
676 | case EM_SPARCV9: | |
252b5132 | 677 | case EM_SPARC: |
9ea033b2 | 678 | rtype = elf_sparc_reloc_type (type); |
252b5132 RH |
679 | break; |
680 | ||
681 | case EM_CYGNUS_V850: | |
9ea033b2 | 682 | rtype = v850_reloc_type (type); |
252b5132 RH |
683 | break; |
684 | ||
685 | case EM_CYGNUS_D10V: | |
9ea033b2 | 686 | rtype = elf_d10v_reloc_type (type); |
252b5132 RH |
687 | break; |
688 | ||
689 | case EM_CYGNUS_D30V: | |
9ea033b2 | 690 | rtype = elf_d30v_reloc_type (type); |
252b5132 RH |
691 | break; |
692 | ||
693 | case EM_SH: | |
9ea033b2 | 694 | rtype = elf_sh_reloc_type (type); |
252b5132 RH |
695 | break; |
696 | ||
697 | case EM_CYGNUS_MN10300: | |
9ea033b2 | 698 | rtype = elf_mn10300_reloc_type (type); |
252b5132 RH |
699 | break; |
700 | ||
701 | case EM_CYGNUS_MN10200: | |
9ea033b2 | 702 | rtype = elf_mn10200_reloc_type (type); |
252b5132 RH |
703 | break; |
704 | ||
705 | case EM_CYGNUS_FR30: | |
9ea033b2 | 706 | rtype = elf_fr30_reloc_type (type); |
252b5132 RH |
707 | break; |
708 | ||
709 | case EM_MCORE: | |
9ea033b2 | 710 | rtype = elf_mcore_reloc_type (type); |
252b5132 RH |
711 | break; |
712 | ||
713 | case EM_PPC: | |
9ea033b2 | 714 | rtype = elf_ppc_reloc_type (type); |
252b5132 RH |
715 | break; |
716 | ||
717 | case EM_MIPS: | |
718 | case EM_MIPS_RS4_BE: | |
9ea033b2 | 719 | rtype = elf_mips_reloc_type (type); |
252b5132 RH |
720 | break; |
721 | ||
722 | case EM_ALPHA: | |
9ea033b2 | 723 | rtype = elf_alpha_reloc_type (type); |
252b5132 RH |
724 | break; |
725 | ||
726 | case EM_ARM: | |
9ea033b2 | 727 | rtype = elf_arm_reloc_type (type); |
252b5132 RH |
728 | break; |
729 | ||
730 | case EM_CYGNUS_ARC: | |
9ea033b2 | 731 | rtype = elf_arc_reloc_type (type); |
252b5132 RH |
732 | break; |
733 | ||
734 | case EM_PARISC: | |
69e617ca | 735 | rtype = elf_hppa_reloc_type (type); |
252b5132 RH |
736 | break; |
737 | } | |
738 | ||
739 | if (rtype == NULL) | |
9ea033b2 NC |
740 | #ifdef _bfd_int64_low |
741 | printf (_("unrecognised: %-7lx"), _bfd_int64_low (type)); | |
742 | #else | |
743 | printf (_("unrecognised: %-7lx"), type); | |
744 | #endif | |
252b5132 RH |
745 | else |
746 | printf ("%-21.21s", rtype); | |
747 | ||
19936277 | 748 | if (symtab_index) |
252b5132 | 749 | { |
19936277 NC |
750 | if (symtab != NULL) |
751 | { | |
752 | if (symtab_index >= nsyms) | |
753 | printf (" bad symbol index: %08lx", (unsigned long) symtab_index); | |
754 | else | |
755 | { | |
756 | Elf_Internal_Sym * psym; | |
757 | ||
758 | psym = symtab + symtab_index; | |
759 | ||
760 | printf (" %08lx ", (unsigned long) psym->st_value); | |
761 | ||
762 | if (psym->st_name == 0) | |
763 | printf ("%-25.25s", | |
764 | SECTION_NAME (section_headers + psym->st_shndx)); | |
765 | else if (strtab == NULL) | |
766 | printf (_("<string table index %3ld>"), psym->st_name); | |
767 | else | |
768 | printf ("%-25.25s", strtab + psym->st_name); | |
769 | ||
770 | if (is_rela) | |
771 | printf (" + %lx", (unsigned long) relas [i].r_addend); | |
772 | } | |
773 | } | |
252b5132 | 774 | } |
1b228002 AS |
775 | else if (is_rela) |
776 | printf ("%34c%lx", ' ', (unsigned long) relas[i].r_addend); | |
252b5132 | 777 | |
351b4b40 RH |
778 | if (elf_header.e_machine == EM_SPARCV9 |
779 | && !strcmp (rtype, "R_SPARC_OLO10")) | |
780 | printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info)); | |
781 | ||
252b5132 RH |
782 | putchar ('\n'); |
783 | } | |
784 | ||
785 | free (relas); | |
786 | ||
787 | return 1; | |
788 | } | |
789 | ||
790 | static const char * | |
791 | get_mips_dynamic_type (type) | |
792 | unsigned long type; | |
793 | { | |
794 | switch (type) | |
795 | { | |
796 | case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; | |
797 | case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; | |
798 | case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; | |
799 | case DT_MIPS_IVERSION: return "MIPS_IVERSION"; | |
800 | case DT_MIPS_FLAGS: return "MIPS_FLAGS"; | |
801 | case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; | |
802 | case DT_MIPS_MSYM: return "MIPS_MSYM"; | |
803 | case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
804 | case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
805 | case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; | |
806 | case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; | |
807 | case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; | |
808 | case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; | |
809 | case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; | |
810 | case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; | |
811 | case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; | |
812 | case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; | |
813 | case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; | |
814 | case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; | |
815 | case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; | |
816 | case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; | |
817 | case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; | |
818 | case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; | |
819 | case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; | |
820 | case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; | |
821 | case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; | |
822 | case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; | |
823 | case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; | |
824 | case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; | |
825 | case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
826 | case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; | |
827 | case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; | |
828 | case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; | |
829 | case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; | |
830 | case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
831 | case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; | |
832 | case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; | |
833 | case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; | |
834 | case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; | |
835 | case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; | |
836 | case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; | |
837 | case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; | |
838 | case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; | |
839 | default: | |
840 | return NULL; | |
841 | } | |
842 | } | |
843 | ||
9a097730 RH |
844 | static const char * |
845 | get_sparc64_dynamic_type (type) | |
846 | unsigned long type; | |
847 | { | |
848 | switch (type) | |
849 | { | |
850 | case DT_SPARC_REGISTER: return "SPARC_REGISTER"; | |
851 | default: | |
852 | return NULL; | |
853 | } | |
854 | } | |
855 | ||
252b5132 RH |
856 | static const char * |
857 | get_dynamic_type (type) | |
858 | unsigned long type; | |
859 | { | |
860 | static char buff [32]; | |
861 | ||
862 | switch (type) | |
863 | { | |
864 | case DT_NULL: return "NULL"; | |
865 | case DT_NEEDED: return "NEEDED"; | |
866 | case DT_PLTRELSZ: return "PLTRELSZ"; | |
867 | case DT_PLTGOT: return "PLTGOT"; | |
868 | case DT_HASH: return "HASH"; | |
869 | case DT_STRTAB: return "STRTAB"; | |
870 | case DT_SYMTAB: return "SYMTAB"; | |
871 | case DT_RELA: return "RELA"; | |
872 | case DT_RELASZ: return "RELASZ"; | |
873 | case DT_RELAENT: return "RELAENT"; | |
874 | case DT_STRSZ: return "STRSZ"; | |
875 | case DT_SYMENT: return "SYMENT"; | |
876 | case DT_INIT: return "INIT"; | |
877 | case DT_FINI: return "FINI"; | |
878 | case DT_SONAME: return "SONAME"; | |
879 | case DT_RPATH: return "RPATH"; | |
880 | case DT_SYMBOLIC: return "SYMBOLIC"; | |
881 | case DT_REL: return "REL"; | |
882 | case DT_RELSZ: return "RELSZ"; | |
883 | case DT_RELENT: return "RELENT"; | |
884 | case DT_PLTREL: return "PLTREL"; | |
885 | case DT_DEBUG: return "DEBUG"; | |
886 | case DT_TEXTREL: return "TEXTREL"; | |
887 | case DT_JMPREL: return "JMPREL"; | |
888 | case DT_BIND_NOW: return "BIND_NOW"; | |
889 | case DT_INIT_ARRAY: return "INIT_ARRAY"; | |
890 | case DT_FINI_ARRAY: return "FINI_ARRAY"; | |
891 | case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; | |
892 | case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; | |
893 | ||
894 | case DT_PLTPADSZ: return "PLTPADSZ"; | |
895 | case DT_MOVEENT: return "MOVEENT"; | |
896 | case DT_MOVESZ: return "MOVESZ"; | |
897 | case DT_FEATURE_1: return "FEATURE_1"; | |
898 | case DT_POSFLAG_1: return "POSFLAG_1"; | |
899 | case DT_SYMINSZ: return "SYMINSZ"; | |
900 | case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ | |
901 | ||
902 | case DT_ADDRRNGLO: return "ADDRRNGLO"; | |
903 | case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ | |
904 | ||
905 | case DT_VERSYM: return "VERSYM"; | |
906 | ||
907 | case DT_RELACOUNT: return "RELACOUNT"; | |
908 | case DT_RELCOUNT: return "RELCOUNT"; | |
909 | case DT_FLAGS_1: return "FLAGS_1"; | |
910 | case DT_VERDEF: return "VERDEF"; | |
911 | case DT_VERDEFNUM: return "VERDEFNUM"; | |
912 | case DT_VERNEED: return "VERNEED"; | |
913 | case DT_VERNEEDNUM: return "VERNEEDNUM"; | |
914 | ||
915 | case DT_AUXILIARY: return "AUXILARY"; | |
916 | case DT_USED: return "USED"; | |
917 | case DT_FILTER: return "FILTER"; | |
918 | ||
919 | default: | |
920 | if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) | |
921 | { | |
922 | const char * result; | |
923 | ||
924 | switch (elf_header.e_machine) | |
925 | { | |
926 | case EM_MIPS: | |
927 | case EM_MIPS_RS4_BE: | |
928 | result = get_mips_dynamic_type (type); | |
929 | break; | |
9a097730 RH |
930 | case EM_SPARCV9: |
931 | result = get_sparc64_dynamic_type (type); | |
932 | break; | |
252b5132 RH |
933 | default: |
934 | result = NULL; | |
935 | break; | |
936 | } | |
937 | ||
938 | if (result != NULL) | |
939 | return result; | |
940 | ||
941 | sprintf (buff, _("Processor Specific: %lx"), type); | |
942 | } | |
943 | else if ((type >= DT_LOOS) && (type <= DT_HIOS)) | |
944 | sprintf (buff, _("Operating System specific: %lx"), type); | |
945 | else | |
946 | sprintf (buff, _("<unknown>: %lx"), type); | |
947 | ||
948 | return buff; | |
949 | } | |
950 | } | |
951 | ||
952 | static char * | |
953 | get_file_type (e_type) | |
954 | unsigned e_type; | |
955 | { | |
956 | static char buff [32]; | |
957 | ||
958 | switch (e_type) | |
959 | { | |
960 | case ET_NONE: return _("NONE (None)"); | |
961 | case ET_REL: return _("REL (Relocatable file)"); | |
962 | case ET_EXEC: return _("EXEC (Executable file)"); | |
963 | case ET_DYN: return _("DYN (Shared object file)"); | |
964 | case ET_CORE: return _("CORE (Core file)"); | |
965 | ||
966 | default: | |
967 | if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) | |
968 | sprintf (buff, _("Processor Specific: (%x)"), e_type); | |
969 | else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) | |
970 | sprintf (buff, _("OS Specific: (%x)"), e_type); | |
971 | else | |
972 | sprintf (buff, _("<unknown>: %x"), e_type); | |
973 | return buff; | |
974 | } | |
975 | } | |
976 | ||
977 | static char * | |
978 | get_machine_name (e_machine) | |
979 | unsigned e_machine; | |
980 | { | |
981 | static char buff [32]; | |
982 | ||
983 | switch (e_machine) | |
984 | { | |
985 | case EM_NONE: return _("None"); | |
986 | case EM_M32: return "WE32100"; | |
987 | case EM_SPARC: return "Sparc"; | |
988 | case EM_386: return "Intel 80386"; | |
989 | case EM_68K: return "MC68000"; | |
990 | case EM_88K: return "MC88000"; | |
991 | case EM_486: return "Intel 80486"; | |
992 | case EM_860: return "Intel 80860"; | |
993 | case EM_MIPS: return "MIPS R3000 big-endian"; | |
994 | case EM_S370: return "Amdahl"; | |
995 | case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian"; | |
996 | case EM_OLD_SPARCV9: return "Sparc v9 (old)"; | |
997 | case EM_PARISC: return "HPPA"; | |
998 | case EM_PPC_OLD: return "Power PC (old)"; | |
999 | case EM_SPARC32PLUS: return "Sparc v8+" ; | |
1000 | case EM_960: return "Intel 90860"; | |
1001 | case EM_PPC: return "PowerPC"; | |
1002 | case EM_V800: return "NEC V800"; | |
1003 | case EM_FR20: return "Fujitsu FR20"; | |
1004 | case EM_RH32: return "TRW RH32"; | |
1005 | case EM_MCORE: return "MCORE"; | |
1006 | case EM_ARM: return "ARM"; | |
1007 | case EM_OLD_ALPHA: return "Digital Alpha (old)"; | |
1008 | case EM_SH: return "Hitachi SH"; | |
1009 | case EM_SPARCV9: return "Sparc v9"; | |
1010 | case EM_TRICORE: return "Siemens Tricore"; | |
1011 | case EM_ARC: return "Argonaut RISC Core"; | |
1012 | case EM_H8_300: return "Hitachi H8/300"; | |
1013 | case EM_H8_300H: return "Hitachi H8/300H"; | |
1014 | case EM_H8S: return "Hitachi H8S"; | |
1015 | case EM_H8_500: return "Hitachi H8/500"; | |
1016 | case EM_IA_64: return "Intel Merced"; | |
1017 | case EM_MIPS_X: return "Stanford MIPS-X"; | |
1018 | case EM_COLDFIRE: return "Motorola Coldfire"; | |
1019 | case EM_68HC12: return "Motorola M68HC12"; | |
1020 | case EM_ALPHA: return "Alpha"; | |
1021 | case EM_CYGNUS_D10V: return "d10v"; | |
1022 | case EM_CYGNUS_D30V: return "d30v"; | |
1023 | case EM_CYGNUS_ARC: return "Arc"; | |
1024 | case EM_CYGNUS_M32R: return "Mitsubishi M32r"; | |
1025 | case EM_CYGNUS_V850: return "NEC v850"; | |
1026 | case EM_CYGNUS_MN10300: return "mn10300"; | |
1027 | case EM_CYGNUS_MN10200: return "mn10200"; | |
1028 | case EM_CYGNUS_FR30: return "Fujitsu FR30"; | |
1029 | ||
1030 | default: | |
1031 | sprintf (buff, _("<unknown>: %x"), e_machine); | |
1032 | return buff; | |
1033 | } | |
1034 | } | |
1035 | ||
1036 | static char * | |
1037 | get_machine_flags (e_flags, e_machine) | |
1038 | unsigned e_flags; | |
1039 | unsigned e_machine; | |
1040 | { | |
1041 | static char buf [1024]; | |
1042 | ||
1043 | buf[0] = '\0'; | |
1044 | if (e_flags) | |
1045 | { | |
1046 | switch (e_machine) | |
1047 | { | |
1048 | default: | |
1049 | break; | |
1050 | ||
33c63f9d CM |
1051 | case EM_68K: |
1052 | if (e_flags & EF_CPU32) | |
1053 | strcat (buf, ", cpu32"); | |
1054 | break; | |
1055 | ||
252b5132 RH |
1056 | case EM_PPC: |
1057 | if (e_flags & EF_PPC_EMB) | |
1058 | strcat (buf, ", emb"); | |
1059 | ||
1060 | if (e_flags & EF_PPC_RELOCATABLE) | |
1061 | strcat (buf, ", relocatable"); | |
1062 | ||
1063 | if (e_flags & EF_PPC_RELOCATABLE_LIB) | |
1064 | strcat (buf, ", relocatable-lib"); | |
1065 | break; | |
1066 | ||
1067 | case EM_CYGNUS_V850: | |
1068 | switch (e_flags & EF_V850_ARCH) | |
1069 | { | |
1070 | case E_V850E_ARCH: | |
1071 | strcat (buf, ", v850e"); | |
1072 | break; | |
1073 | case E_V850EA_ARCH: | |
1074 | strcat (buf, ", v850ea"); | |
1075 | break; | |
1076 | case E_V850_ARCH: | |
1077 | strcat (buf, ", v850"); | |
1078 | break; | |
1079 | default: | |
1080 | strcat (buf, ", unknown v850 architecture variant"); | |
1081 | break; | |
1082 | } | |
1083 | break; | |
1084 | ||
1085 | case EM_CYGNUS_M32R: | |
1086 | if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) | |
1087 | strcat (buf, ", m32r"); | |
1088 | ||
1089 | break; | |
1090 | ||
1091 | case EM_MIPS: | |
1092 | case EM_MIPS_RS4_BE: | |
1093 | if (e_flags & EF_MIPS_NOREORDER) | |
1094 | strcat (buf, ", noreorder"); | |
1095 | ||
1096 | if (e_flags & EF_MIPS_PIC) | |
1097 | strcat (buf, ", pic"); | |
1098 | ||
1099 | if (e_flags & EF_MIPS_CPIC) | |
1100 | strcat (buf, ", cpic"); | |
1101 | ||
1102 | if (e_flags & EF_MIPS_ABI2) | |
1103 | strcat (buf, ", abi2"); | |
1104 | ||
1105 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1) | |
1106 | strcat (buf, ", mips1"); | |
1107 | ||
1108 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2) | |
1109 | strcat (buf, ", mips2"); | |
1110 | ||
1111 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3) | |
1112 | strcat (buf, ", mips3"); | |
1113 | ||
1114 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4) | |
1115 | strcat (buf, ", mips4"); | |
1116 | break; | |
351b4b40 RH |
1117 | |
1118 | case EM_SPARCV9: | |
1119 | if (e_flags & EF_SPARC_32PLUS) | |
1120 | strcat (buf, ", v8+"); | |
1121 | ||
1122 | if (e_flags & EF_SPARC_SUN_US1) | |
d07faca2 RH |
1123 | strcat (buf, ", ultrasparcI"); |
1124 | ||
1125 | if (e_flags & EF_SPARC_SUN_US3) | |
1126 | strcat (buf, ", ultrasparcIII"); | |
351b4b40 RH |
1127 | |
1128 | if (e_flags & EF_SPARC_HAL_R1) | |
1129 | strcat (buf, ", halr1"); | |
1130 | ||
1131 | if (e_flags & EF_SPARC_LEDATA) | |
1132 | strcat (buf, ", ledata"); | |
1133 | ||
1134 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) | |
1135 | strcat (buf, ", tso"); | |
1136 | ||
1137 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) | |
1138 | strcat (buf, ", pso"); | |
1139 | ||
1140 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) | |
1141 | strcat (buf, ", rmo"); | |
1142 | break; | |
252b5132 RH |
1143 | } |
1144 | } | |
1145 | ||
1146 | return buf; | |
1147 | } | |
1148 | ||
252b5132 RH |
1149 | static const char * |
1150 | get_mips_segment_type (type) | |
1151 | unsigned long type; | |
1152 | { | |
1153 | switch (type) | |
1154 | { | |
1155 | case PT_MIPS_REGINFO: | |
1156 | return "REGINFO"; | |
1157 | case PT_MIPS_RTPROC: | |
1158 | return "RTPROC"; | |
1159 | case PT_MIPS_OPTIONS: | |
1160 | return "OPTIONS"; | |
1161 | default: | |
1162 | break; | |
1163 | } | |
1164 | ||
1165 | return NULL; | |
1166 | } | |
1167 | ||
1168 | static const char * | |
1169 | get_segment_type (p_type) | |
1170 | unsigned long p_type; | |
1171 | { | |
1172 | static char buff [32]; | |
1173 | ||
1174 | switch (p_type) | |
1175 | { | |
1176 | case PT_NULL: return "NULL"; | |
1177 | case PT_LOAD: return "LOAD"; | |
1178 | case PT_DYNAMIC: return "DYNAMIC"; | |
1179 | case PT_INTERP: return "INTERP"; | |
1180 | case PT_NOTE: return "NOTE"; | |
1181 | case PT_SHLIB: return "SHLIB"; | |
1182 | case PT_PHDR: return "PHDR"; | |
1183 | ||
1184 | default: | |
1185 | if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) | |
1186 | { | |
1187 | const char * result; | |
1188 | ||
1189 | switch (elf_header.e_machine) | |
1190 | { | |
1191 | case EM_MIPS: | |
1192 | case EM_MIPS_RS4_BE: | |
1193 | result = get_mips_segment_type (p_type); | |
1194 | break; | |
1195 | default: | |
1196 | result = NULL; | |
1197 | break; | |
1198 | } | |
1199 | ||
1200 | if (result != NULL) | |
1201 | return result; | |
1202 | ||
1203 | sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC); | |
1204 | } | |
1205 | else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) | |
1206 | sprintf (buff, "LOOS+%lx", p_type - PT_LOOS); | |
1207 | else | |
1208 | sprintf (buff, _("<unknown>: %lx"), p_type); | |
1209 | ||
1210 | return buff; | |
1211 | } | |
1212 | } | |
1213 | ||
1214 | static const char * | |
1215 | get_mips_section_type_name (sh_type) | |
1216 | unsigned int sh_type; | |
1217 | { | |
1218 | switch (sh_type) | |
1219 | { | |
1220 | case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
1221 | case SHT_MIPS_MSYM: return "MIPS_MSYM"; | |
1222 | case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
1223 | case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; | |
1224 | case SHT_MIPS_UCODE: return "MIPS_UCODE"; | |
1225 | case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; | |
1226 | case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; | |
1227 | case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; | |
1228 | case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; | |
1229 | case SHT_MIPS_RELD: return "MIPS_RELD"; | |
1230 | case SHT_MIPS_IFACE: return "MIPS_IFACE"; | |
1231 | case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; | |
1232 | case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
1233 | case SHT_MIPS_SHDR: return "MIPS_SHDR"; | |
1234 | case SHT_MIPS_FDESC: return "MIPS_FDESC"; | |
1235 | case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; | |
1236 | case SHT_MIPS_DENSE: return "MIPS_DENSE"; | |
1237 | case SHT_MIPS_PDESC: return "MIPS_PDESC"; | |
1238 | case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; | |
1239 | case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; | |
1240 | case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; | |
1241 | case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; | |
1242 | case SHT_MIPS_LINE: return "MIPS_LINE"; | |
1243 | case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; | |
1244 | case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; | |
1245 | case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; | |
1246 | case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; | |
1247 | case SHT_MIPS_DWARF: return "MIPS_DWARF"; | |
1248 | case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; | |
1249 | case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
1250 | case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; | |
1251 | case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; | |
1252 | case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; | |
1253 | case SHT_MIPS_XLATE: return "MIPS_XLATE"; | |
1254 | case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; | |
1255 | case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; | |
1256 | case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; | |
1257 | case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; | |
1258 | case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; | |
1259 | default: | |
1260 | break; | |
1261 | } | |
1262 | return NULL; | |
1263 | } | |
1264 | ||
1265 | static const char * | |
1266 | get_section_type_name (sh_type) | |
1267 | unsigned int sh_type; | |
1268 | { | |
1269 | static char buff [32]; | |
1270 | ||
1271 | switch (sh_type) | |
1272 | { | |
1273 | case SHT_NULL: return "NULL"; | |
1274 | case SHT_PROGBITS: return "PROGBITS"; | |
1275 | case SHT_SYMTAB: return "SYMTAB"; | |
1276 | case SHT_STRTAB: return "STRTAB"; | |
1277 | case SHT_RELA: return "RELA"; | |
1278 | case SHT_HASH: return "HASH"; | |
1279 | case SHT_DYNAMIC: return "DYNAMIC"; | |
1280 | case SHT_NOTE: return "NOTE"; | |
1281 | case SHT_NOBITS: return "NOBITS"; | |
1282 | case SHT_REL: return "REL"; | |
1283 | case SHT_SHLIB: return "SHLIB"; | |
1284 | case SHT_DYNSYM: return "DYNSYM"; | |
1285 | case SHT_GNU_verdef: return "VERDEF"; | |
1286 | case SHT_GNU_verneed: return "VERNEED"; | |
1287 | case SHT_GNU_versym: return "VERSYM"; | |
1288 | case 0x6ffffff0: return "VERSYM"; | |
1289 | case 0x6ffffffc: return "VERDEF"; | |
1290 | case 0x7ffffffd: return "AUXILIARY"; | |
1291 | case 0x7fffffff: return "FILTER"; | |
1292 | ||
1293 | default: | |
1294 | if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) | |
1295 | { | |
1296 | const char * result; | |
1297 | ||
1298 | switch (elf_header.e_machine) | |
1299 | { | |
1300 | case EM_MIPS: | |
1301 | case EM_MIPS_RS4_BE: | |
1302 | result = get_mips_section_type_name (sh_type); | |
1303 | break; | |
1304 | default: | |
1305 | result = NULL; | |
1306 | break; | |
1307 | } | |
1308 | ||
1309 | if (result != NULL) | |
1310 | return result; | |
1311 | ||
1312 | sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC); | |
1313 | } | |
1314 | else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) | |
1315 | sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS); | |
1316 | else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) | |
1317 | sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER); | |
1318 | else | |
1319 | sprintf (buff, _("<unknown>: %x"), sh_type); | |
1320 | ||
1321 | return buff; | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | struct option options [] = | |
1326 | { | |
1327 | {"all", no_argument, 0, 'a'}, | |
1328 | {"file-header", no_argument, 0, 'h'}, | |
1329 | {"program-headers", no_argument, 0, 'l'}, | |
1330 | {"headers", no_argument, 0, 'e'}, | |
a952a375 | 1331 | {"histogram", no_argument, 0, 'I'}, |
252b5132 RH |
1332 | {"segments", no_argument, 0, 'l'}, |
1333 | {"sections", no_argument, 0, 'S'}, | |
1334 | {"section-headers", no_argument, 0, 'S'}, | |
1335 | {"symbols", no_argument, 0, 's'}, | |
1336 | {"syms", no_argument, 0, 's'}, | |
1337 | {"relocs", no_argument, 0, 'r'}, | |
1338 | {"dynamic", no_argument, 0, 'd'}, | |
a952a375 | 1339 | {"arch-specific", no_argument, 0, 'A'}, |
252b5132 RH |
1340 | {"version-info", no_argument, 0, 'V'}, |
1341 | {"use-dynamic", no_argument, 0, 'D'}, | |
1342 | {"hex-dump", required_argument, 0, 'x'}, | |
1343 | {"debug-dump", optional_argument, 0, 'w'}, | |
1344 | #ifdef SUPPORT_DISASSEMBLY | |
1345 | {"instruction-dump", required_argument, 0, 'i'}, | |
1346 | #endif | |
1347 | ||
1348 | {"version", no_argument, 0, 'v'}, | |
1349 | {"help", no_argument, 0, 'H'}, | |
1350 | {0, no_argument, 0, 0} | |
1351 | }; | |
1352 | ||
1353 | static void | |
1354 | usage () | |
1355 | { | |
1356 | fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n")); | |
1357 | fprintf (stdout, _(" Options are:\n")); | |
a952a375 | 1358 | fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n")); |
252b5132 RH |
1359 | fprintf (stdout, _(" -h or --file-header Display the ELF file header\n")); |
1360 | fprintf (stdout, _(" -l or --program-headers or --segments\n")); | |
1361 | fprintf (stdout, _(" Display the program headers\n")); | |
1362 | fprintf (stdout, _(" -S or --section-headers or --sections\n")); | |
1363 | fprintf (stdout, _(" Display the sections' header\n")); | |
1364 | fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n")); | |
1365 | fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n")); | |
1366 | fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n")); | |
1367 | fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n")); | |
1368 | fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n")); | |
a952a375 | 1369 | fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n")); |
252b5132 RH |
1370 | fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n")); |
1371 | fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n")); | |
1372 | fprintf (stdout, _(" Dump the contents of section <number>\n")); | |
1373 | fprintf (stdout, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n")); | |
1374 | fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n")); | |
1375 | #ifdef SUPPORT_DISASSEMBLY | |
1376 | fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n")); | |
1377 | fprintf (stdout, _(" Disassemble the contents of section <number>\n")); | |
1378 | #endif | |
a952a375 | 1379 | fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n")); |
252b5132 RH |
1380 | fprintf (stdout, _(" -v or --version Display the version number of readelf\n")); |
1381 | fprintf (stdout, _(" -H or --help Display this information\n")); | |
1382 | fprintf (stdout, _("Report bugs to bug-gnu-utils@gnu.org\n")); | |
1383 | ||
1384 | exit (0); | |
1385 | } | |
1386 | ||
1387 | static void | |
1388 | request_dump (section, type) | |
1389 | unsigned int section; | |
1390 | char type; | |
1391 | { | |
1392 | if (section >= num_dump_sects) | |
1393 | { | |
1394 | char * new_dump_sects; | |
1395 | ||
1396 | new_dump_sects = (char *) calloc (section + 1, 1); | |
1397 | ||
1398 | if (new_dump_sects == NULL) | |
1399 | error (_("Out of memory allocating dump request table.")); | |
1400 | else | |
1401 | { | |
1402 | /* Copy current flag settings. */ | |
1403 | memcpy (new_dump_sects, dump_sects, num_dump_sects); | |
1404 | ||
1405 | free (dump_sects); | |
1406 | ||
1407 | dump_sects = new_dump_sects; | |
1408 | num_dump_sects = section + 1; | |
1409 | } | |
1410 | } | |
1411 | ||
1412 | if (dump_sects) | |
1413 | dump_sects [section] |= type; | |
1414 | ||
1415 | return; | |
1416 | } | |
1417 | ||
1418 | static void | |
1419 | parse_args (argc, argv) | |
1420 | int argc; | |
1421 | char ** argv; | |
1422 | { | |
1423 | int c; | |
1424 | ||
1425 | if (argc < 2) | |
1426 | usage (); | |
1427 | ||
1428 | while ((c = getopt_long | |
a952a375 | 1429 | (argc, argv, "ersahldSDAIw::x:i:vV", options, NULL)) != EOF) |
252b5132 RH |
1430 | { |
1431 | char * cp; | |
1432 | int section; | |
1433 | ||
1434 | switch (c) | |
1435 | { | |
1436 | case 0: | |
1437 | /* Long options. */ | |
1438 | break; | |
1439 | case 'H': | |
1440 | usage (); | |
1441 | break; | |
1442 | ||
1443 | case 'a': | |
1444 | do_syms ++; | |
1445 | do_reloc ++; | |
1446 | do_dynamic ++; | |
1447 | do_header ++; | |
1448 | do_sections ++; | |
1449 | do_segments ++; | |
1450 | do_version ++; | |
1451 | do_histogram ++; | |
a952a375 | 1452 | do_arch ++; |
252b5132 RH |
1453 | break; |
1454 | case 'e': | |
1455 | do_header ++; | |
1456 | do_sections ++; | |
1457 | do_segments ++; | |
1458 | break; | |
a952a375 NC |
1459 | case 'A': |
1460 | do_arch ++; | |
1461 | break; | |
252b5132 RH |
1462 | case 'D': |
1463 | do_using_dynamic ++; | |
1464 | break; | |
1465 | case 'r': | |
1466 | do_reloc ++; | |
1467 | break; | |
1468 | case 'h': | |
1469 | do_header ++; | |
1470 | break; | |
1471 | case 'l': | |
1472 | do_segments ++; | |
1473 | break; | |
1474 | case 's': | |
1475 | do_syms ++; | |
1476 | break; | |
1477 | case 'S': | |
1478 | do_sections ++; | |
1479 | break; | |
1480 | case 'd': | |
1481 | do_dynamic ++; | |
1482 | break; | |
a952a375 NC |
1483 | case 'I': |
1484 | do_histogram ++; | |
1485 | break; | |
252b5132 RH |
1486 | case 'x': |
1487 | do_dump ++; | |
1488 | section = strtoul (optarg, & cp, 0); | |
1489 | if (! * cp && section >= 0) | |
1490 | { | |
1491 | request_dump (section, HEX_DUMP); | |
1492 | break; | |
1493 | } | |
1494 | goto oops; | |
1495 | case 'w': | |
1496 | do_dump ++; | |
1497 | if (optarg == 0) | |
1498 | do_debugging = 1; | |
1499 | else | |
1500 | { | |
1501 | do_debugging = 0; | |
1502 | switch (optarg[0]) | |
1503 | { | |
1504 | case 'i': | |
1505 | case 'I': | |
1506 | do_debug_info = 1; | |
1507 | break; | |
1508 | ||
1509 | case 'a': | |
1510 | case 'A': | |
1511 | do_debug_abbrevs = 1; | |
1512 | break; | |
1513 | ||
1514 | case 'l': | |
1515 | case 'L': | |
1516 | do_debug_lines = 1; | |
1517 | break; | |
1518 | ||
1519 | case 'p': | |
1520 | case 'P': | |
1521 | do_debug_pubnames = 1; | |
1522 | break; | |
1523 | ||
1524 | case 'r': | |
1525 | case 'R': | |
1526 | do_debug_aranges = 1; | |
1527 | break; | |
1528 | ||
1529 | default: | |
1530 | warn (_("Unrecognised debug option '%s'\n"), optarg); | |
1531 | break; | |
1532 | } | |
1533 | } | |
1534 | break; | |
1535 | #ifdef SUPPORT_DISASSEMBLY | |
1536 | case 'i': | |
1537 | do_dump ++; | |
1538 | section = strtoul (optarg, & cp, 0); | |
1539 | if (! * cp && section >= 0) | |
1540 | { | |
1541 | request_dump (section, DISASS_DUMP); | |
1542 | break; | |
1543 | } | |
1544 | goto oops; | |
1545 | #endif | |
1546 | case 'v': | |
1547 | print_version (program_name); | |
1548 | break; | |
1549 | case 'V': | |
1550 | do_version ++; | |
1551 | break; | |
1552 | default: | |
1553 | oops: | |
1554 | /* xgettext:c-format */ | |
1555 | error (_("Invalid option '-%c'\n"), c); | |
1556 | /* Drop through. */ | |
1557 | case '?': | |
1558 | usage (); | |
1559 | } | |
1560 | } | |
1561 | ||
1562 | if (!do_dynamic && !do_syms && !do_reloc && !do_sections | |
1563 | && !do_segments && !do_header && !do_dump && !do_version | |
a952a375 | 1564 | && !do_histogram && !do_debugging && !do_arch) |
252b5132 RH |
1565 | usage (); |
1566 | else if (argc < 3) | |
1567 | { | |
1568 | warn (_("Nothing to do.\n")); | |
1569 | usage(); | |
1570 | } | |
1571 | } | |
1572 | ||
1573 | static const char * | |
1574 | get_elf_class (elf_class) | |
1575 | unsigned char elf_class; | |
1576 | { | |
ab5e7794 NC |
1577 | static char buff [32]; |
1578 | ||
252b5132 RH |
1579 | switch (elf_class) |
1580 | { | |
1581 | case ELFCLASSNONE: return _("none"); | |
1582 | case ELFCLASS32: return _("ELF32"); | |
1583 | case ELFCLASS64: return _("ELF64"); | |
ab5e7794 | 1584 | default: |
789be9f7 | 1585 | sprintf (buff, _("<unknown: %x>"), elf_class); |
ab5e7794 | 1586 | return buff; |
252b5132 RH |
1587 | } |
1588 | } | |
1589 | ||
1590 | static const char * | |
1591 | get_data_encoding (encoding) | |
1592 | unsigned char encoding; | |
1593 | { | |
ab5e7794 NC |
1594 | static char buff [32]; |
1595 | ||
252b5132 RH |
1596 | switch (encoding) |
1597 | { | |
1598 | case ELFDATANONE: return _("none"); | |
33c63f9d CM |
1599 | case ELFDATA2LSB: return _("2's complement, little endian"); |
1600 | case ELFDATA2MSB: return _("2's complement, big endian"); | |
ab5e7794 | 1601 | default: |
789be9f7 | 1602 | sprintf (buff, _("<unknown: %x>"), encoding); |
ab5e7794 | 1603 | return buff; |
252b5132 RH |
1604 | } |
1605 | } | |
1606 | ||
1607 | static const char * | |
1608 | get_osabi_name (osabi) | |
1609 | unsigned char osabi; | |
1610 | { | |
ab5e7794 NC |
1611 | static char buff [32]; |
1612 | ||
252b5132 RH |
1613 | switch (osabi) |
1614 | { | |
1615 | case ELFOSABI_SYSV: return _("UNIX - System V"); | |
1616 | case ELFOSABI_HPUX: return _("UNIX - HP-UX"); | |
1617 | case ELFOSABI_STANDALONE: return _("Standalone App"); | |
ab5e7794 | 1618 | default: |
789be9f7 | 1619 | sprintf (buff, _("<unknown: %x>"), osabi); |
ab5e7794 | 1620 | return buff; |
252b5132 RH |
1621 | } |
1622 | } | |
1623 | ||
1624 | /* Decode the data held in 'elf_header'. */ | |
1625 | static int | |
1626 | process_file_header () | |
1627 | { | |
1628 | if ( elf_header.e_ident [EI_MAG0] != ELFMAG0 | |
1629 | || elf_header.e_ident [EI_MAG1] != ELFMAG1 | |
1630 | || elf_header.e_ident [EI_MAG2] != ELFMAG2 | |
1631 | || elf_header.e_ident [EI_MAG3] != ELFMAG3) | |
1632 | { | |
1633 | error | |
1634 | (_("Not an ELF file - it has the wrong magic bytes at the start\n")); | |
1635 | return 0; | |
1636 | } | |
1637 | ||
1638 | if (do_header) | |
1639 | { | |
1640 | int i; | |
1641 | ||
1642 | printf (_("ELF Header:\n")); | |
1643 | printf (_(" Magic: ")); | |
1644 | for (i = 0; i < EI_NIDENT; i ++) | |
1645 | printf ("%2.2x ", elf_header.e_ident [i]); | |
1646 | printf ("\n"); | |
1647 | printf (_(" Class: %s\n"), | |
1648 | get_elf_class (elf_header.e_ident [EI_CLASS])); | |
1649 | printf (_(" Data: %s\n"), | |
1650 | get_data_encoding (elf_header.e_ident [EI_DATA])); | |
1651 | printf (_(" Version: %d %s\n"), | |
1652 | elf_header.e_ident [EI_VERSION], | |
789be9f7 ILT |
1653 | (elf_header.e_ident [EI_VERSION] == EV_CURRENT |
1654 | ? "(current)" | |
1655 | : (elf_header.e_ident [EI_VERSION] != EV_NONE | |
1656 | ? "<unknown: %lx>" | |
1657 | : ""))); | |
252b5132 RH |
1658 | printf (_(" OS/ABI: %s\n"), |
1659 | get_osabi_name (elf_header.e_ident [EI_OSABI])); | |
1660 | printf (_(" ABI Version: %d\n"), | |
1661 | elf_header.e_ident [EI_ABIVERSION]); | |
1662 | printf (_(" Type: %s\n"), | |
1663 | get_file_type (elf_header.e_type)); | |
1664 | printf (_(" Machine: %s\n"), | |
1665 | get_machine_name (elf_header.e_machine)); | |
1666 | printf (_(" Version: 0x%lx\n"), | |
1667 | (unsigned long) elf_header.e_version); | |
252b5132 RH |
1668 | printf (_(" Entry point address: 0x%lx\n"), |
1669 | (unsigned long) elf_header.e_entry); | |
1670 | printf (_(" Start of program headers: %ld (bytes into file)\n"), | |
1671 | (long) elf_header.e_phoff); | |
1672 | printf (_(" Start of section headers: %ld (bytes into file)\n"), | |
1673 | (long) elf_header.e_shoff); | |
1674 | printf (_(" Flags: 0x%lx%s\n"), | |
1675 | (unsigned long) elf_header.e_flags, | |
1676 | get_machine_flags (elf_header.e_flags, elf_header.e_machine)); | |
1677 | printf (_(" Size of this header: %ld (bytes)\n"), | |
1678 | (long) elf_header.e_ehsize); | |
1679 | printf (_(" Size of program headers: %ld (bytes)\n"), | |
1680 | (long) elf_header.e_phentsize); | |
1681 | printf (_(" Number of program headers: %ld\n"), | |
1682 | (long) elf_header.e_phnum); | |
1683 | printf (_(" Size of section headers: %ld (bytes)\n"), | |
1684 | (long) elf_header.e_shentsize); | |
1685 | printf (_(" Number of section headers: %ld\n"), | |
1686 | (long) elf_header.e_shnum); | |
1687 | printf (_(" Section header string table index: %ld\n"), | |
1688 | (long) elf_header.e_shstrndx); | |
1689 | } | |
9ea033b2 NC |
1690 | |
1691 | return 1; | |
1692 | } | |
1693 | ||
252b5132 | 1694 | |
9ea033b2 NC |
1695 | static int |
1696 | get_32bit_program_headers (file, program_headers) | |
1697 | FILE * file; | |
1698 | Elf_Internal_Phdr * program_headers; | |
1699 | { | |
1700 | Elf32_External_Phdr * phdrs; | |
1701 | Elf32_External_Phdr * external; | |
1702 | Elf32_Internal_Phdr * internal; | |
1703 | unsigned int i; | |
252b5132 | 1704 | |
9ea033b2 NC |
1705 | GET_DATA_ALLOC (elf_header.e_phoff, |
1706 | elf_header.e_phentsize * elf_header.e_phnum, | |
1707 | phdrs, Elf32_External_Phdr *, "program headers"); | |
1708 | ||
1709 | for (i = 0, internal = program_headers, external = phdrs; | |
1710 | i < elf_header.e_phnum; | |
1711 | i ++, internal ++, external ++) | |
252b5132 | 1712 | { |
9ea033b2 NC |
1713 | internal->p_type = BYTE_GET (external->p_type); |
1714 | internal->p_offset = BYTE_GET (external->p_offset); | |
1715 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
1716 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
1717 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
1718 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
1719 | internal->p_flags = BYTE_GET (external->p_flags); | |
1720 | internal->p_align = BYTE_GET (external->p_align); | |
252b5132 RH |
1721 | } |
1722 | ||
9ea033b2 NC |
1723 | free (phdrs); |
1724 | ||
252b5132 RH |
1725 | return 1; |
1726 | } | |
1727 | ||
9ea033b2 NC |
1728 | static int |
1729 | get_64bit_program_headers (file, program_headers) | |
1730 | FILE * file; | |
1731 | Elf_Internal_Phdr * program_headers; | |
1732 | { | |
1733 | Elf64_External_Phdr * phdrs; | |
1734 | Elf64_External_Phdr * external; | |
1735 | Elf64_Internal_Phdr * internal; | |
1736 | unsigned int i; | |
1737 | ||
1738 | GET_DATA_ALLOC (elf_header.e_phoff, | |
1739 | elf_header.e_phentsize * elf_header.e_phnum, | |
1740 | phdrs, Elf64_External_Phdr *, "program headers"); | |
1741 | ||
1742 | for (i = 0, internal = program_headers, external = phdrs; | |
1743 | i < elf_header.e_phnum; | |
1744 | i ++, internal ++, external ++) | |
1745 | { | |
1746 | internal->p_type = BYTE_GET (external->p_type); | |
1747 | internal->p_flags = BYTE_GET (external->p_flags); | |
1748 | internal->p_offset = BYTE_GET8 (external->p_offset); | |
1749 | internal->p_vaddr = BYTE_GET8 (external->p_vaddr); | |
1750 | internal->p_paddr = BYTE_GET8 (external->p_paddr); | |
1751 | internal->p_filesz = BYTE_GET8 (external->p_filesz); | |
1752 | internal->p_memsz = BYTE_GET8 (external->p_memsz); | |
1753 | internal->p_align = BYTE_GET8 (external->p_align); | |
1754 | } | |
1755 | ||
1756 | free (phdrs); | |
1757 | ||
1758 | return 1; | |
1759 | } | |
252b5132 RH |
1760 | |
1761 | static int | |
1762 | process_program_headers (file) | |
1763 | FILE * file; | |
1764 | { | |
9ea033b2 NC |
1765 | Elf_Internal_Phdr * program_headers; |
1766 | Elf_Internal_Phdr * segment; | |
1767 | unsigned int i; | |
252b5132 RH |
1768 | |
1769 | if (elf_header.e_phnum == 0) | |
1770 | { | |
1771 | if (do_segments) | |
1772 | printf (_("\nThere are no program headers in this file.\n")); | |
1773 | return 1; | |
1774 | } | |
1775 | ||
1776 | if (do_segments && !do_header) | |
1777 | { | |
1778 | printf (_("\nElf file is %s\n"), get_file_type (elf_header.e_type)); | |
1779 | printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header.e_entry); | |
1780 | printf (_("There are %d program headers, starting at offset %lx:\n"), | |
1781 | elf_header.e_phnum, (unsigned long) elf_header.e_phoff); | |
1782 | } | |
1783 | ||
9ea033b2 NC |
1784 | program_headers = (Elf_Internal_Phdr *) malloc |
1785 | (elf_header.e_phnum * sizeof (Elf_Internal_Phdr)); | |
252b5132 RH |
1786 | |
1787 | if (program_headers == NULL) | |
1788 | { | |
1789 | error (_("Out of memory\n")); | |
1790 | return 0; | |
1791 | } | |
1792 | ||
9ea033b2 NC |
1793 | if (is_32bit_elf) |
1794 | i = get_32bit_program_headers (file, program_headers); | |
1795 | else | |
1796 | i = get_64bit_program_headers (file, program_headers); | |
1797 | ||
1798 | if (i == 0) | |
252b5132 | 1799 | { |
9ea033b2 NC |
1800 | free (program_headers); |
1801 | return 0; | |
252b5132 | 1802 | } |
9ea033b2 | 1803 | |
252b5132 RH |
1804 | if (do_segments) |
1805 | { | |
1806 | printf | |
1807 | (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : ""); | |
1808 | printf | |
1809 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
1810 | } | |
1811 | ||
1812 | loadaddr = -1; | |
1813 | dynamic_addr = 0; | |
1b228002 | 1814 | dynamic_size = 0; |
252b5132 RH |
1815 | |
1816 | for (i = 0, segment = program_headers; | |
1817 | i < elf_header.e_phnum; | |
1818 | i ++, segment ++) | |
1819 | { | |
1820 | if (do_segments) | |
1821 | { | |
1822 | printf (" %-11.11s ", get_segment_type (segment->p_type)); | |
1823 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
1824 | printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); | |
1825 | printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); | |
1826 | printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); | |
1827 | printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); | |
1828 | printf ("%c%c%c ", | |
1829 | (segment->p_flags & PF_R ? 'R' : ' '), | |
1830 | (segment->p_flags & PF_W ? 'W' : ' '), | |
1831 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
1832 | printf ("%#lx", (unsigned long) segment->p_align); | |
1833 | } | |
1834 | ||
1835 | switch (segment->p_type) | |
1836 | { | |
1837 | case PT_LOAD: | |
1838 | if (loadaddr == -1) | |
1839 | loadaddr = (segment->p_vaddr & 0xfffff000) | |
1840 | - (segment->p_offset & 0xfffff000); | |
1841 | break; | |
1842 | ||
1843 | case PT_DYNAMIC: | |
1844 | if (dynamic_addr) | |
1845 | error (_("more than one dynamic segment\n")); | |
1846 | ||
1847 | dynamic_addr = segment->p_offset; | |
1848 | dynamic_size = segment->p_filesz; | |
1849 | break; | |
1850 | ||
1851 | case PT_INTERP: | |
1852 | if (fseek (file, segment->p_offset, SEEK_SET)) | |
1853 | error (_("Unable to find program interpreter name\n")); | |
1854 | else | |
1855 | { | |
1856 | program_interpreter[0] = 0; | |
1857 | fscanf (file, "%63s", program_interpreter); | |
1858 | ||
1859 | if (do_segments) | |
1860 | printf (_("\n [Requesting program interpreter: %s]"), | |
1861 | program_interpreter); | |
1862 | } | |
1863 | break; | |
1864 | } | |
1865 | ||
1866 | if (do_segments) | |
1867 | putc ('\n', stdout); | |
1868 | } | |
1869 | ||
1870 | if (loadaddr == -1) | |
1871 | { | |
1872 | /* Very strange. */ | |
1873 | loadaddr = 0; | |
1874 | } | |
1875 | ||
1876 | if (do_segments && section_headers != NULL) | |
1877 | { | |
1878 | printf (_("\n Section to Segment mapping:\n")); | |
1879 | printf (_(" Segment Sections...\n")); | |
1880 | ||
1881 | assert (string_table != NULL); | |
1882 | ||
1883 | for (i = 0; i < elf_header.e_phnum; i++) | |
1884 | { | |
9ea033b2 NC |
1885 | int j; |
1886 | Elf_Internal_Shdr * section; | |
252b5132 RH |
1887 | |
1888 | segment = program_headers + i; | |
1889 | section = section_headers; | |
1890 | ||
1891 | printf (" %2.2d ", i); | |
1892 | ||
1893 | for (j = 0; j < elf_header.e_shnum; j++, section ++) | |
1894 | { | |
1895 | if (section->sh_size > 0 | |
1896 | /* Compare allocated sections by VMA, unallocated | |
1897 | sections by file offset. */ | |
1898 | && (section->sh_flags & SHF_ALLOC | |
1899 | ? (section->sh_addr >= segment->p_vaddr | |
1900 | && section->sh_addr + section->sh_size | |
1901 | <= segment->p_vaddr + segment->p_memsz) | |
b4c96d0d | 1902 | : ((bfd_vma) section->sh_offset >= segment->p_offset |
252b5132 RH |
1903 | && (section->sh_offset + section->sh_size |
1904 | <= segment->p_offset + segment->p_filesz)))) | |
1905 | printf ("%s ", SECTION_NAME (section)); | |
1906 | } | |
1907 | ||
1908 | putc ('\n',stdout); | |
1909 | } | |
1910 | } | |
1911 | ||
1912 | free (program_headers); | |
1913 | ||
1914 | return 1; | |
1915 | } | |
1916 | ||
1917 | ||
1918 | static int | |
9ea033b2 | 1919 | get_32bit_section_headers (file) |
252b5132 RH |
1920 | FILE * file; |
1921 | { | |
1922 | Elf32_External_Shdr * shdrs; | |
1923 | Elf32_Internal_Shdr * internal; | |
1924 | unsigned int i; | |
1925 | ||
1926 | GET_DATA_ALLOC (elf_header.e_shoff, | |
1927 | elf_header.e_shentsize * elf_header.e_shnum, | |
1928 | shdrs, Elf32_External_Shdr *, "section headers"); | |
1929 | ||
9ea033b2 NC |
1930 | section_headers = (Elf_Internal_Shdr *) malloc |
1931 | (elf_header.e_shnum * sizeof (Elf_Internal_Shdr)); | |
252b5132 RH |
1932 | |
1933 | if (section_headers == NULL) | |
1934 | { | |
1935 | error (_("Out of memory\n")); | |
1936 | return 0; | |
1937 | } | |
1938 | ||
1939 | for (i = 0, internal = section_headers; | |
1940 | i < elf_header.e_shnum; | |
1941 | i ++, internal ++) | |
1942 | { | |
1943 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
1944 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
1945 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
1946 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
1947 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
1948 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
1949 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
1950 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
1951 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
1952 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
1953 | } | |
1954 | ||
1955 | free (shdrs); | |
1956 | ||
1957 | return 1; | |
1958 | } | |
1959 | ||
9ea033b2 NC |
1960 | static int |
1961 | get_64bit_section_headers (file) | |
1962 | FILE * file; | |
1963 | { | |
1964 | Elf64_External_Shdr * shdrs; | |
1965 | Elf64_Internal_Shdr * internal; | |
1966 | unsigned int i; | |
1967 | ||
1968 | GET_DATA_ALLOC (elf_header.e_shoff, | |
1969 | elf_header.e_shentsize * elf_header.e_shnum, | |
1970 | shdrs, Elf64_External_Shdr *, "section headers"); | |
1971 | ||
1972 | section_headers = (Elf_Internal_Shdr *) malloc | |
1973 | (elf_header.e_shnum * sizeof (Elf_Internal_Shdr)); | |
1974 | ||
1975 | if (section_headers == NULL) | |
1976 | { | |
1977 | error (_("Out of memory\n")); | |
1978 | return 0; | |
1979 | } | |
1980 | ||
1981 | for (i = 0, internal = section_headers; | |
1982 | i < elf_header.e_shnum; | |
1983 | i ++, internal ++) | |
1984 | { | |
1985 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
1986 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
1987 | internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags); | |
1988 | internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr); | |
1989 | internal->sh_size = BYTE_GET8 (shdrs[i].sh_size); | |
1990 | internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize); | |
1991 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
1992 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
1993 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
1994 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
1995 | } | |
1996 | ||
1997 | free (shdrs); | |
1998 | ||
1999 | return 1; | |
2000 | } | |
2001 | ||
252b5132 | 2002 | static Elf_Internal_Sym * |
9ea033b2 | 2003 | get_32bit_elf_symbols (file, offset, number) |
252b5132 RH |
2004 | FILE * file; |
2005 | unsigned long offset; | |
2006 | unsigned long number; | |
2007 | { | |
2008 | Elf32_External_Sym * esyms; | |
2009 | Elf_Internal_Sym * isyms; | |
2010 | Elf_Internal_Sym * psym; | |
2011 | unsigned int j; | |
2012 | ||
2013 | GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym), | |
2014 | esyms, Elf32_External_Sym *, "symbols"); | |
2015 | ||
2016 | isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym)); | |
2017 | ||
2018 | if (isyms == NULL) | |
2019 | { | |
2020 | error (_("Out of memory\n")); | |
2021 | free (esyms); | |
2022 | ||
2023 | return NULL; | |
2024 | } | |
2025 | ||
2026 | for (j = 0, psym = isyms; | |
2027 | j < number; | |
2028 | j ++, psym ++) | |
2029 | { | |
2030 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
2031 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
2032 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
2033 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
2034 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
2035 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
2036 | } | |
2037 | ||
2038 | free (esyms); | |
2039 | ||
2040 | return isyms; | |
2041 | } | |
2042 | ||
9ea033b2 NC |
2043 | static Elf_Internal_Sym * |
2044 | get_64bit_elf_symbols (file, offset, number) | |
2045 | FILE * file; | |
2046 | unsigned long offset; | |
2047 | unsigned long number; | |
2048 | { | |
2049 | Elf64_External_Sym * esyms; | |
2050 | Elf_Internal_Sym * isyms; | |
2051 | Elf_Internal_Sym * psym; | |
2052 | unsigned int j; | |
2053 | ||
2054 | GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym), | |
2055 | esyms, Elf64_External_Sym *, "symbols"); | |
2056 | ||
2057 | isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym)); | |
2058 | ||
2059 | if (isyms == NULL) | |
2060 | { | |
2061 | error (_("Out of memory\n")); | |
2062 | free (esyms); | |
2063 | ||
2064 | return NULL; | |
2065 | } | |
2066 | ||
2067 | for (j = 0, psym = isyms; | |
2068 | j < number; | |
2069 | j ++, psym ++) | |
2070 | { | |
2071 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
2072 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
2073 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
2074 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
2075 | psym->st_value = BYTE_GET8 (esyms[j].st_value); | |
2076 | psym->st_size = BYTE_GET8 (esyms[j].st_size); | |
2077 | } | |
2078 | ||
2079 | free (esyms); | |
2080 | ||
2081 | return isyms; | |
2082 | } | |
2083 | ||
252b5132 RH |
2084 | static int |
2085 | process_section_headers (file) | |
2086 | FILE * file; | |
2087 | { | |
9ea033b2 NC |
2088 | Elf_Internal_Shdr * section; |
2089 | int i; | |
252b5132 RH |
2090 | |
2091 | section_headers = NULL; | |
2092 | ||
2093 | if (elf_header.e_shnum == 0) | |
2094 | { | |
2095 | if (do_sections) | |
2096 | printf (_("\nThere are no sections in this file.\n")); | |
2097 | ||
2098 | return 1; | |
2099 | } | |
2100 | ||
2101 | if (do_sections && !do_header) | |
9ea033b2 | 2102 | printf (_("There are %d section headers, starting at offset 0x%lx:\n"), |
252b5132 RH |
2103 | elf_header.e_shnum, (unsigned long) elf_header.e_shoff); |
2104 | ||
9ea033b2 NC |
2105 | if (is_32bit_elf) |
2106 | { | |
2107 | if (! get_32bit_section_headers (file)) | |
2108 | return 0; | |
2109 | } | |
2110 | else if (! get_64bit_section_headers (file)) | |
252b5132 RH |
2111 | return 0; |
2112 | ||
2113 | /* Read in the string table, so that we have names to display. */ | |
2114 | section = section_headers + elf_header.e_shstrndx; | |
2115 | ||
2116 | if (section->sh_size != 0) | |
2117 | { | |
2118 | unsigned long string_table_offset; | |
2119 | ||
2120 | string_table_offset = section->sh_offset; | |
2121 | ||
2122 | GET_DATA_ALLOC (section->sh_offset, section->sh_size, | |
2123 | string_table, char *, "string table"); | |
2124 | } | |
2125 | ||
2126 | /* Scan the sections for the dynamic symbol table | |
2127 | and dynamic string table and debug sections. */ | |
2128 | dynamic_symbols = NULL; | |
2129 | dynamic_strings = NULL; | |
2130 | dynamic_syminfo = NULL; | |
9ea033b2 | 2131 | |
252b5132 RH |
2132 | for (i = 0, section = section_headers; |
2133 | i < elf_header.e_shnum; | |
2134 | i ++, section ++) | |
2135 | { | |
2136 | char * name = SECTION_NAME (section); | |
2137 | ||
2138 | if (section->sh_type == SHT_DYNSYM) | |
2139 | { | |
2140 | if (dynamic_symbols != NULL) | |
2141 | { | |
2142 | error (_("File contains multiple dynamic symbol tables\n")); | |
2143 | continue; | |
2144 | } | |
2145 | ||
19936277 | 2146 | num_dynamic_syms = section->sh_size / section->sh_entsize; |
9ea033b2 | 2147 | dynamic_symbols = |
19936277 | 2148 | GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms); |
252b5132 RH |
2149 | } |
2150 | else if (section->sh_type == SHT_STRTAB | |
2151 | && strcmp (name, ".dynstr") == 0) | |
2152 | { | |
2153 | if (dynamic_strings != NULL) | |
2154 | { | |
2155 | error (_("File contains multiple dynamic string tables\n")); | |
2156 | continue; | |
2157 | } | |
2158 | ||
2159 | GET_DATA_ALLOC (section->sh_offset, section->sh_size, | |
2160 | dynamic_strings, char *, "dynamic strings"); | |
2161 | } | |
2162 | else if ((do_debugging || do_debug_info || do_debug_abbrevs | |
2163 | || do_debug_lines || do_debug_pubnames || do_debug_aranges) | |
2164 | && strncmp (name, ".debug_", 7) == 0) | |
2165 | { | |
2166 | name += 7; | |
2167 | ||
2168 | if (do_debugging | |
2169 | || (do_debug_info && (strcmp (name, "info") == 0)) | |
2170 | || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0)) | |
2171 | || (do_debug_lines && (strcmp (name, "line") == 0)) | |
2172 | || (do_debug_pubnames && (strcmp (name, "pubnames") == 0)) | |
2173 | || (do_debug_aranges && (strcmp (name, "aranges") == 0)) | |
2174 | ) | |
2175 | request_dump (i, DEBUG_DUMP); | |
2176 | } | |
2177 | } | |
2178 | ||
2179 | if (! do_sections) | |
2180 | return 1; | |
2181 | ||
2182 | printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : ""); | |
2183 | printf | |
2184 | (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); | |
2185 | ||
2186 | for (i = 0, section = section_headers; | |
2187 | i < elf_header.e_shnum; | |
2188 | i ++, section ++) | |
2189 | { | |
2190 | printf (" [%2d] %-17.17s %-15.15s ", | |
2191 | i, | |
2192 | SECTION_NAME (section), | |
2193 | get_section_type_name (section->sh_type)); | |
2194 | ||
2195 | printf ( "%8.8lx %6.6lx %6.6lx %2.2lx", | |
2196 | (unsigned long) section->sh_addr, | |
2197 | (unsigned long) section->sh_offset, | |
2198 | (unsigned long) section->sh_size, | |
2199 | (unsigned long) section->sh_entsize); | |
2200 | ||
2201 | printf (" %c%c%c %2ld %3lx %ld\n", | |
2202 | (section->sh_flags & SHF_WRITE ? 'W' : ' '), | |
2203 | (section->sh_flags & SHF_ALLOC ? 'A' : ' '), | |
2204 | (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '), | |
2205 | (unsigned long) section->sh_link, | |
2206 | (unsigned long) section->sh_info, | |
2207 | (unsigned long) section->sh_addralign); | |
2208 | } | |
2209 | ||
2210 | return 1; | |
2211 | } | |
2212 | ||
2213 | /* Process the reloc section. */ | |
2214 | static int | |
2215 | process_relocs (file) | |
2216 | FILE * file; | |
2217 | { | |
2218 | unsigned long rel_size; | |
2219 | unsigned long rel_offset; | |
2220 | ||
2221 | ||
2222 | if (!do_reloc) | |
2223 | return 1; | |
2224 | ||
2225 | if (do_using_dynamic) | |
2226 | { | |
b4c96d0d | 2227 | int is_rela = FALSE; |
9c19a809 | 2228 | |
252b5132 RH |
2229 | rel_size = 0; |
2230 | rel_offset = 0; | |
2231 | ||
2232 | if (dynamic_info[DT_REL]) | |
2233 | { | |
2234 | rel_offset = dynamic_info[DT_REL]; | |
2235 | rel_size = dynamic_info[DT_RELSZ]; | |
9c19a809 | 2236 | is_rela = FALSE; |
252b5132 RH |
2237 | } |
2238 | else if (dynamic_info [DT_RELA]) | |
2239 | { | |
2240 | rel_offset = dynamic_info[DT_RELA]; | |
2241 | rel_size = dynamic_info[DT_RELASZ]; | |
9c19a809 | 2242 | is_rela = TRUE; |
252b5132 RH |
2243 | } |
2244 | else if (dynamic_info[DT_JMPREL]) | |
2245 | { | |
2246 | rel_offset = dynamic_info[DT_JMPREL]; | |
2247 | rel_size = dynamic_info[DT_PLTRELSZ]; | |
19936277 | 2248 | |
aa903cfb AS |
2249 | switch (dynamic_info[DT_PLTREL]) |
2250 | { | |
2251 | case DT_REL: | |
2252 | is_rela = FALSE; | |
2253 | break; | |
2254 | case DT_RELA: | |
2255 | is_rela = TRUE; | |
2256 | break; | |
2257 | default: | |
2258 | is_rela = UNKNOWN; | |
2259 | break; | |
2260 | } | |
252b5132 RH |
2261 | } |
2262 | ||
2263 | if (rel_size) | |
2264 | { | |
2265 | printf | |
2266 | (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"), | |
2267 | rel_offset, rel_size); | |
2268 | ||
2269 | dump_relocations (file, rel_offset - loadaddr, rel_size, | |
19936277 | 2270 | dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela); |
252b5132 RH |
2271 | } |
2272 | else | |
2273 | printf (_("\nThere are no dynamic relocations in this file.\n")); | |
2274 | } | |
2275 | else | |
2276 | { | |
2277 | Elf32_Internal_Shdr * section; | |
2278 | unsigned long i; | |
2279 | int found = 0; | |
2280 | ||
2281 | for (i = 0, section = section_headers; | |
2282 | i < elf_header.e_shnum; | |
2283 | i++, section ++) | |
2284 | { | |
2285 | if ( section->sh_type != SHT_RELA | |
2286 | && section->sh_type != SHT_REL) | |
2287 | continue; | |
2288 | ||
2289 | rel_offset = section->sh_offset; | |
2290 | rel_size = section->sh_size; | |
2291 | ||
2292 | if (rel_size) | |
2293 | { | |
2294 | Elf32_Internal_Shdr * strsec; | |
2295 | Elf32_Internal_Shdr * symsec; | |
2296 | Elf_Internal_Sym * symtab; | |
2297 | char * strtab; | |
9c19a809 | 2298 | int is_rela; |
19936277 | 2299 | unsigned long nsyms; |
9c19a809 | 2300 | |
252b5132 RH |
2301 | printf (_("\nRelocation section ")); |
2302 | ||
2303 | if (string_table == NULL) | |
19936277 | 2304 | printf ("%d", section->sh_name); |
252b5132 | 2305 | else |
19936277 | 2306 | printf ("'%s'", SECTION_NAME (section)); |
252b5132 RH |
2307 | |
2308 | printf (_(" at offset 0x%lx contains %lu entries:\n"), | |
2309 | rel_offset, (unsigned long) (rel_size / section->sh_entsize)); | |
2310 | ||
2311 | symsec = section_headers + section->sh_link; | |
2312 | ||
19936277 NC |
2313 | nsyms = symsec->sh_size / symsec->sh_entsize; |
2314 | symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms); | |
252b5132 RH |
2315 | |
2316 | if (symtab == NULL) | |
2317 | continue; | |
2318 | ||
2319 | strsec = section_headers + symsec->sh_link; | |
2320 | ||
2321 | GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab, | |
2322 | char *, "string table"); | |
aa903cfb AS |
2323 | |
2324 | is_rela = section->sh_type == SHT_RELA; | |
252b5132 | 2325 | |
19936277 | 2326 | dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela); |
252b5132 RH |
2327 | |
2328 | free (strtab); | |
2329 | free (symtab); | |
2330 | ||
2331 | found = 1; | |
2332 | } | |
2333 | } | |
2334 | ||
2335 | if (! found) | |
2336 | printf (_("\nThere are no relocations in this file.\n")); | |
2337 | } | |
2338 | ||
2339 | return 1; | |
2340 | } | |
2341 | ||
2342 | ||
2343 | static void | |
2344 | dynamic_segment_mips_val (entry) | |
2345 | Elf_Internal_Dyn * entry; | |
2346 | { | |
2347 | switch (entry->d_tag) | |
2348 | { | |
2349 | case DT_MIPS_FLAGS: | |
2350 | if (entry->d_un.d_val == 0) | |
2351 | printf ("NONE\n"); | |
2352 | else | |
2353 | { | |
2354 | static const char * opts[] = | |
2355 | { | |
2356 | "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", | |
2357 | "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", | |
2358 | "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", | |
2359 | "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", | |
2360 | "RLD_ORDER_SAFE" | |
2361 | }; | |
2362 | unsigned int cnt; | |
2363 | int first = 1; | |
2364 | for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt) | |
2365 | if (entry->d_un.d_val & (1 << cnt)) | |
2366 | { | |
2367 | printf ("%s%s", first ? "" : " ", opts[cnt]); | |
2368 | first = 0; | |
2369 | } | |
2370 | puts (""); | |
2371 | } | |
2372 | break; | |
2373 | ||
2374 | case DT_MIPS_IVERSION: | |
2375 | if (dynamic_strings != NULL) | |
2376 | printf ("Interface Version: %s\n", | |
2377 | dynamic_strings + entry->d_un.d_val); | |
2378 | else | |
2379 | printf ("%ld\n", (long) entry->d_un.d_ptr); | |
2380 | break; | |
2381 | ||
2382 | case DT_MIPS_TIME_STAMP: | |
2383 | { | |
2384 | char timebuf[20]; | |
2385 | time_t time = entry->d_un.d_val; | |
2386 | strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time)); | |
2387 | printf ("Time Stamp: %s\n", timebuf); | |
2388 | } | |
2389 | break; | |
2390 | ||
2391 | case DT_MIPS_RLD_VERSION: | |
2392 | case DT_MIPS_LOCAL_GOTNO: | |
2393 | case DT_MIPS_CONFLICTNO: | |
2394 | case DT_MIPS_LIBLISTNO: | |
2395 | case DT_MIPS_SYMTABNO: | |
2396 | case DT_MIPS_UNREFEXTNO: | |
2397 | case DT_MIPS_HIPAGENO: | |
2398 | case DT_MIPS_DELTA_CLASS_NO: | |
2399 | case DT_MIPS_DELTA_INSTANCE_NO: | |
2400 | case DT_MIPS_DELTA_RELOC_NO: | |
2401 | case DT_MIPS_DELTA_SYM_NO: | |
2402 | case DT_MIPS_DELTA_CLASSSYM_NO: | |
2403 | case DT_MIPS_COMPACT_SIZE: | |
2404 | printf ("%ld\n", (long) entry->d_un.d_ptr); | |
2405 | break; | |
2406 | ||
2407 | default: | |
2408 | printf ("%#lx\n", (long) entry->d_un.d_ptr); | |
2409 | } | |
2410 | } | |
2411 | ||
252b5132 | 2412 | static int |
9ea033b2 | 2413 | get_32bit_dynamic_segment (file) |
252b5132 RH |
2414 | FILE * file; |
2415 | { | |
9ea033b2 NC |
2416 | Elf32_External_Dyn * edyn; |
2417 | Elf_Internal_Dyn * entry; | |
2418 | bfd_size_type i; | |
2419 | ||
2420 | GET_DATA_ALLOC (dynamic_addr, dynamic_size, | |
2421 | edyn, Elf32_External_Dyn *, "dynamic segment"); | |
2422 | ||
2423 | /* SGI's ELF has more than one section in the DYNAMIC segment. Determine | |
2424 | how large this .dynamic is now. We can do this even before the byte | |
2425 | swapping since the DT_NULL tag is recognizable. */ | |
2426 | dynamic_size = 0; | |
2427 | while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL) | |
2428 | ; | |
252b5132 | 2429 | |
9ea033b2 NC |
2430 | dynamic_segment = (Elf_Internal_Dyn *) |
2431 | malloc (dynamic_size * sizeof (Elf_Internal_Dyn)); | |
2432 | ||
2433 | if (dynamic_segment == NULL) | |
252b5132 | 2434 | { |
9ea033b2 NC |
2435 | error (_("Out of memory\n")); |
2436 | free (edyn); | |
2437 | return 0; | |
2438 | } | |
252b5132 | 2439 | |
9ea033b2 NC |
2440 | for (i = 0, entry = dynamic_segment; |
2441 | i < dynamic_size; | |
2442 | i ++, entry ++) | |
2443 | { | |
2444 | entry->d_tag = BYTE_GET (edyn [i].d_tag); | |
2445 | entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val); | |
252b5132 RH |
2446 | } |
2447 | ||
9ea033b2 NC |
2448 | free (edyn); |
2449 | ||
2450 | return 1; | |
2451 | } | |
2452 | ||
2453 | static int | |
2454 | get_64bit_dynamic_segment (file) | |
2455 | FILE * file; | |
2456 | { | |
2457 | Elf64_External_Dyn * edyn; | |
2458 | Elf_Internal_Dyn * entry; | |
2459 | bfd_size_type i; | |
2460 | ||
252b5132 | 2461 | GET_DATA_ALLOC (dynamic_addr, dynamic_size, |
9ea033b2 | 2462 | edyn, Elf64_External_Dyn *, "dynamic segment"); |
252b5132 RH |
2463 | |
2464 | /* SGI's ELF has more than one section in the DYNAMIC segment. Determine | |
9ea033b2 | 2465 | how large this .dynamic is now. We can do this even before the byte |
252b5132 RH |
2466 | swapping since the DT_NULL tag is recognizable. */ |
2467 | dynamic_size = 0; | |
9ea033b2 | 2468 | while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL) |
252b5132 RH |
2469 | ; |
2470 | ||
2471 | dynamic_segment = (Elf_Internal_Dyn *) | |
2472 | malloc (dynamic_size * sizeof (Elf_Internal_Dyn)); | |
2473 | ||
2474 | if (dynamic_segment == NULL) | |
2475 | { | |
2476 | error (_("Out of memory\n")); | |
2477 | free (edyn); | |
2478 | return 0; | |
2479 | } | |
2480 | ||
2481 | for (i = 0, entry = dynamic_segment; | |
2482 | i < dynamic_size; | |
2483 | i ++, entry ++) | |
2484 | { | |
9ea033b2 NC |
2485 | entry->d_tag = BYTE_GET8 (edyn [i].d_tag); |
2486 | entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val); | |
252b5132 RH |
2487 | } |
2488 | ||
2489 | free (edyn); | |
2490 | ||
9ea033b2 NC |
2491 | return 1; |
2492 | } | |
2493 | ||
2494 | /* Parse and display the contents of the dynamic segment. */ | |
2495 | static int | |
2496 | process_dynamic_segment (file) | |
2497 | FILE * file; | |
2498 | { | |
2499 | Elf_Internal_Dyn * entry; | |
2500 | bfd_size_type i; | |
2501 | ||
2502 | if (dynamic_size == 0) | |
2503 | { | |
2504 | if (do_dynamic) | |
2505 | printf (_("\nThere is no dynamic segment in this file.\n")); | |
2506 | ||
2507 | return 1; | |
2508 | } | |
2509 | ||
2510 | if (is_32bit_elf) | |
2511 | { | |
2512 | if (! get_32bit_dynamic_segment (file)) | |
2513 | return 0; | |
2514 | } | |
2515 | else if (! get_64bit_dynamic_segment (file)) | |
2516 | return 0; | |
2517 | ||
252b5132 RH |
2518 | /* Find the appropriate symbol table. */ |
2519 | if (dynamic_symbols == NULL) | |
2520 | { | |
2521 | for (i = 0, entry = dynamic_segment; | |
2522 | i < dynamic_size; | |
2523 | ++i, ++ entry) | |
2524 | { | |
2525 | unsigned long offset; | |
252b5132 RH |
2526 | |
2527 | if (entry->d_tag != DT_SYMTAB) | |
2528 | continue; | |
2529 | ||
2530 | dynamic_info[DT_SYMTAB] = entry->d_un.d_val; | |
2531 | ||
2532 | /* Since we do not know how big the symbol table is, | |
2533 | we default to reading in the entire file (!) and | |
2534 | processing that. This is overkill, I know, but it | |
2535 | should work. */ | |
252b5132 RH |
2536 | offset = entry->d_un.d_val - loadaddr; |
2537 | ||
2538 | if (fseek (file, 0, SEEK_END)) | |
2539 | error (_("Unable to seek to end of file!")); | |
2540 | ||
9ea033b2 | 2541 | if (is_32bit_elf) |
19936277 | 2542 | num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym); |
9ea033b2 | 2543 | else |
19936277 | 2544 | num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym); |
252b5132 | 2545 | |
19936277 | 2546 | if (num_dynamic_syms < 1) |
252b5132 RH |
2547 | { |
2548 | error (_("Unable to determine the number of symbols to load\n")); | |
2549 | continue; | |
2550 | } | |
2551 | ||
19936277 | 2552 | dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms); |
252b5132 RH |
2553 | } |
2554 | } | |
2555 | ||
2556 | /* Similarly find a string table. */ | |
2557 | if (dynamic_strings == NULL) | |
2558 | { | |
2559 | for (i = 0, entry = dynamic_segment; | |
2560 | i < dynamic_size; | |
2561 | ++i, ++ entry) | |
2562 | { | |
2563 | unsigned long offset; | |
2564 | long str_tab_len; | |
2565 | ||
2566 | if (entry->d_tag != DT_STRTAB) | |
2567 | continue; | |
2568 | ||
2569 | dynamic_info[DT_STRTAB] = entry->d_un.d_val; | |
2570 | ||
2571 | /* Since we do not know how big the string table is, | |
2572 | we default to reading in the entire file (!) and | |
2573 | processing that. This is overkill, I know, but it | |
2574 | should work. */ | |
2575 | ||
2576 | offset = entry->d_un.d_val - loadaddr; | |
2577 | if (fseek (file, 0, SEEK_END)) | |
2578 | error (_("Unable to seek to end of file\n")); | |
2579 | str_tab_len = ftell (file) - offset; | |
2580 | ||
2581 | if (str_tab_len < 1) | |
2582 | { | |
2583 | error | |
2584 | (_("Unable to determine the length of the dynamic string table\n")); | |
2585 | continue; | |
2586 | } | |
2587 | ||
2588 | GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *, | |
2589 | "dynamic string table"); | |
2590 | ||
2591 | break; | |
2592 | } | |
2593 | } | |
2594 | ||
2595 | /* And find the syminfo section if available. */ | |
2596 | if (dynamic_syminfo == NULL) | |
2597 | { | |
2598 | unsigned int syminsz = 0; | |
2599 | ||
2600 | for (i = 0, entry = dynamic_segment; | |
2601 | i < dynamic_size; | |
2602 | ++i, ++ entry) | |
2603 | { | |
2604 | if (entry->d_tag == DT_SYMINENT) | |
2605 | { | |
2606 | /* Note: these braces are necessary to avoid a syntax | |
2607 | error from the SunOS4 C compiler. */ | |
2608 | assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val); | |
2609 | } | |
2610 | else if (entry->d_tag == DT_SYMINSZ) | |
2611 | syminsz = entry->d_un.d_val; | |
2612 | else if (entry->d_tag == DT_SYMINFO) | |
2613 | dynamic_syminfo_offset = entry->d_un.d_val - loadaddr; | |
2614 | } | |
2615 | ||
2616 | if (dynamic_syminfo_offset != 0 && syminsz != 0) | |
2617 | { | |
9ea033b2 NC |
2618 | Elf_External_Syminfo * extsyminfo; |
2619 | Elf_Internal_Syminfo * syminfo; | |
252b5132 RH |
2620 | |
2621 | /* There is a syminfo section. Read the data. */ | |
2622 | GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo, | |
2623 | Elf_External_Syminfo *, "symbol information"); | |
2624 | ||
2625 | dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); | |
2626 | if (dynamic_syminfo == NULL) | |
2627 | { | |
2628 | error (_("Out of memory\n")); | |
2629 | return 0; | |
2630 | } | |
2631 | ||
2632 | dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo); | |
2633 | for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent; | |
2634 | ++i, ++syminfo) | |
2635 | { | |
2636 | syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto); | |
2637 | syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags); | |
2638 | } | |
2639 | ||
2640 | free (extsyminfo); | |
2641 | } | |
2642 | } | |
2643 | ||
2644 | if (do_dynamic && dynamic_addr) | |
789be9f7 ILT |
2645 | printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"), |
2646 | dynamic_addr, (long) dynamic_size); | |
252b5132 RH |
2647 | if (do_dynamic) |
2648 | printf (_(" Tag Type Name/Value\n")); | |
2649 | ||
2650 | for (i = 0, entry = dynamic_segment; | |
2651 | i < dynamic_size; | |
2652 | i++, entry ++) | |
2653 | { | |
2654 | if (do_dynamic) | |
2655 | printf (_(" 0x%-8.8lx (%s)%*s"), | |
2656 | (unsigned long) entry->d_tag, | |
2657 | get_dynamic_type (entry->d_tag), | |
2658 | 27 - strlen (get_dynamic_type (entry->d_tag)), | |
2659 | " "); | |
2660 | ||
2661 | switch (entry->d_tag) | |
2662 | { | |
2663 | case DT_AUXILIARY: | |
2664 | case DT_FILTER: | |
2665 | if (do_dynamic) | |
2666 | { | |
2667 | if (entry->d_tag == DT_AUXILIARY) | |
2668 | printf (_("Auxiliary library")); | |
2669 | else | |
2670 | printf (_("Filter library")); | |
2671 | ||
2672 | if (dynamic_strings) | |
2673 | printf (": [%s]\n", dynamic_strings + entry->d_un.d_val); | |
2674 | else | |
2675 | printf (": %#lx\n", (long) entry->d_un.d_val); | |
2676 | } | |
2677 | break; | |
2678 | ||
2679 | case DT_FEATURE_1: | |
2680 | if (do_dynamic) | |
2681 | { | |
2682 | printf (_("Flags:")); | |
2683 | if (entry->d_un.d_val == 0) | |
2684 | printf (_(" None\n")); | |
2685 | else | |
2686 | { | |
2687 | unsigned long int val = entry->d_un.d_val; | |
2688 | if (val & DTF_1_PARINIT) | |
2689 | { | |
2690 | printf (" PARINIT"); | |
2691 | val ^= DTF_1_PARINIT; | |
2692 | } | |
2693 | if (val != 0) | |
2694 | printf (" %lx", val); | |
2695 | puts (""); | |
2696 | } | |
2697 | } | |
2698 | break; | |
2699 | ||
2700 | case DT_POSFLAG_1: | |
2701 | if (do_dynamic) | |
2702 | { | |
2703 | printf (_("Flags:")); | |
2704 | if (entry->d_un.d_val == 0) | |
2705 | printf (_(" None\n")); | |
2706 | else | |
2707 | { | |
2708 | unsigned long int val = entry->d_un.d_val; | |
2709 | if (val & DF_P1_LAZYLOAD) | |
2710 | { | |
2711 | printf (" LAZYLOAD"); | |
2712 | val ^= DF_P1_LAZYLOAD; | |
2713 | } | |
2714 | if (val & DF_P1_GROUPPERM) | |
2715 | { | |
2716 | printf (" GROUPPERM"); | |
2717 | val ^= DF_P1_GROUPPERM; | |
2718 | } | |
2719 | if (val != 0) | |
2720 | printf (" %lx", val); | |
2721 | puts (""); | |
2722 | } | |
2723 | } | |
2724 | break; | |
2725 | ||
2726 | case DT_FLAGS_1: | |
2727 | if (do_dynamic) | |
2728 | { | |
2729 | printf (_("Flags:")); | |
2730 | if (entry->d_un.d_val == 0) | |
2731 | printf (_(" None\n")); | |
2732 | else | |
2733 | { | |
2734 | unsigned long int val = entry->d_un.d_val; | |
2735 | if (val & DF_1_NOW) | |
2736 | { | |
2737 | printf (" NOW"); | |
2738 | val ^= DF_1_NOW; | |
2739 | } | |
2740 | if (val & DF_1_GLOBAL) | |
2741 | { | |
2742 | printf (" GLOBAL"); | |
2743 | val ^= DF_1_GLOBAL; | |
2744 | } | |
2745 | if (val & DF_1_GROUP) | |
2746 | { | |
2747 | printf (" GROUP"); | |
2748 | val ^= DF_1_GROUP; | |
2749 | } | |
2750 | if (val & DF_1_NODELETE) | |
2751 | { | |
2752 | printf (" NODELETE"); | |
2753 | val ^= DF_1_NODELETE; | |
2754 | } | |
2755 | if (val & DF_1_LOADFLTR) | |
2756 | { | |
2757 | printf (" LOADFLTR"); | |
2758 | val ^= DF_1_LOADFLTR; | |
2759 | } | |
2760 | if (val & DF_1_INITFIRST) | |
2761 | { | |
2762 | printf (" INITFIRST"); | |
2763 | val ^= DF_1_INITFIRST; | |
2764 | } | |
2765 | if (val & DF_1_NOOPEN) | |
2766 | { | |
2767 | printf (" NOOPEN"); | |
2768 | val ^= DF_1_NOOPEN; | |
2769 | } | |
2770 | if (val & DF_1_ORIGIN) | |
2771 | { | |
2772 | printf (" ORIGIN"); | |
2773 | val ^= DF_1_ORIGIN; | |
2774 | } | |
2775 | if (val & DF_1_DIRECT) | |
2776 | { | |
2777 | printf (" DIRECT"); | |
2778 | val ^= DF_1_DIRECT; | |
2779 | } | |
2780 | if (val & DF_1_TRANS) | |
2781 | { | |
2782 | printf (" TRANS"); | |
2783 | val ^= DF_1_TRANS; | |
2784 | } | |
2785 | if (val & DF_1_INTERPOSE) | |
2786 | { | |
2787 | printf (" INTERPOSE"); | |
2788 | val ^= DF_1_INTERPOSE; | |
2789 | } | |
2790 | if (val != 0) | |
2791 | printf (" %lx", val); | |
2792 | puts (""); | |
2793 | } | |
2794 | } | |
2795 | break; | |
2796 | ||
2797 | case DT_PLTREL: | |
2798 | if (do_dynamic) | |
2799 | puts (get_dynamic_type (entry->d_un.d_val)); | |
2800 | break; | |
2801 | ||
2802 | case DT_NULL : | |
2803 | case DT_NEEDED : | |
2804 | case DT_PLTGOT : | |
2805 | case DT_HASH : | |
2806 | case DT_STRTAB : | |
2807 | case DT_SYMTAB : | |
2808 | case DT_RELA : | |
2809 | case DT_INIT : | |
2810 | case DT_FINI : | |
2811 | case DT_SONAME : | |
2812 | case DT_RPATH : | |
2813 | case DT_SYMBOLIC: | |
2814 | case DT_REL : | |
2815 | case DT_DEBUG : | |
2816 | case DT_TEXTREL : | |
2817 | case DT_JMPREL : | |
2818 | dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
2819 | ||
2820 | if (do_dynamic) | |
2821 | { | |
2822 | char * name; | |
2823 | ||
2824 | if (dynamic_strings == NULL) | |
2825 | name = NULL; | |
2826 | else | |
2827 | name = dynamic_strings + entry->d_un.d_val; | |
2828 | ||
2829 | if (name) | |
2830 | { | |
2831 | switch (entry->d_tag) | |
2832 | { | |
2833 | case DT_NEEDED: | |
2834 | printf (_("Shared library: [%s]"), name); | |
2835 | ||
2836 | if (strcmp (name, program_interpreter)) | |
2837 | printf ("\n"); | |
2838 | else | |
2839 | printf (_(" program interpreter\n")); | |
2840 | break; | |
2841 | ||
2842 | case DT_SONAME: | |
2843 | printf (_("Library soname: [%s]\n"), name); | |
2844 | break; | |
2845 | ||
2846 | case DT_RPATH: | |
2847 | printf (_("Library rpath: [%s]\n"), name); | |
2848 | break; | |
2849 | ||
2850 | default: | |
2851 | printf ("%#lx\n", (long) entry->d_un.d_val); | |
2852 | } | |
2853 | } | |
2854 | else | |
2855 | printf ("%#lx\n", (long) entry->d_un.d_val); | |
2856 | } | |
2857 | break; | |
2858 | ||
2859 | case DT_PLTRELSZ: | |
2860 | case DT_RELASZ : | |
2861 | case DT_STRSZ : | |
2862 | case DT_RELSZ : | |
2863 | case DT_RELAENT : | |
2864 | case DT_SYMENT : | |
2865 | case DT_RELENT : | |
2866 | case DT_PLTPADSZ: | |
2867 | case DT_MOVEENT : | |
2868 | case DT_MOVESZ : | |
2869 | case DT_INIT_ARRAYSZ: | |
2870 | case DT_FINI_ARRAYSZ: | |
2871 | if (do_dynamic) | |
2872 | printf ("%lu (bytes)\n", (unsigned long) entry->d_un.d_val); | |
2873 | break; | |
2874 | ||
2875 | case DT_VERDEFNUM: | |
2876 | case DT_VERNEEDNUM: | |
2877 | case DT_RELACOUNT: | |
2878 | case DT_RELCOUNT: | |
2879 | if (do_dynamic) | |
2880 | printf ("%lu\n", (unsigned long) entry->d_un.d_val); | |
2881 | break; | |
2882 | ||
2883 | case DT_SYMINSZ: | |
2884 | case DT_SYMINENT: | |
2885 | case DT_SYMINFO: | |
2886 | case DT_USED: | |
2887 | case DT_INIT_ARRAY: | |
2888 | case DT_FINI_ARRAY: | |
2889 | if (do_dynamic) | |
2890 | { | |
2891 | if (dynamic_strings != NULL && entry->d_tag == DT_USED) | |
2892 | { | |
2893 | char * name; | |
2894 | ||
2895 | name = dynamic_strings + entry->d_un.d_val; | |
2896 | ||
2897 | if (* name) | |
2898 | { | |
2899 | printf (_("Not needed object: [%s]\n"), name); | |
2900 | break; | |
2901 | } | |
2902 | } | |
2903 | ||
2904 | printf ("%#lx\n", (long) entry->d_un.d_val); | |
2905 | } | |
2906 | break; | |
2907 | ||
2908 | case DT_BIND_NOW: | |
2909 | /* The value of this entry is ignored. */ | |
2910 | break; | |
2911 | ||
2912 | default: | |
2913 | if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) | |
2914 | version_info [DT_VERSIONTAGIDX (entry->d_tag)] = | |
2915 | entry->d_un.d_val; | |
2916 | ||
2917 | if (do_dynamic) | |
2918 | { | |
2919 | switch (elf_header.e_machine) | |
2920 | { | |
2921 | case EM_MIPS: | |
2922 | case EM_MIPS_RS4_BE: | |
2923 | dynamic_segment_mips_val (entry); | |
2924 | break; | |
2925 | default: | |
2926 | printf ("%#lx\n", (long) entry->d_un.d_ptr); | |
2927 | } | |
2928 | } | |
2929 | break; | |
2930 | } | |
2931 | } | |
2932 | ||
2933 | return 1; | |
2934 | } | |
2935 | ||
2936 | static char * | |
2937 | get_ver_flags (flags) | |
2938 | unsigned int flags; | |
2939 | { | |
2940 | static char buff [32]; | |
2941 | ||
2942 | buff[0] = 0; | |
2943 | ||
2944 | if (flags == 0) | |
2945 | return _("none"); | |
2946 | ||
2947 | if (flags & VER_FLG_BASE) | |
2948 | strcat (buff, "BASE "); | |
2949 | ||
2950 | if (flags & VER_FLG_WEAK) | |
2951 | { | |
2952 | if (flags & VER_FLG_BASE) | |
2953 | strcat (buff, "| "); | |
2954 | ||
2955 | strcat (buff, "WEAK "); | |
2956 | } | |
2957 | ||
2958 | if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK)) | |
2959 | strcat (buff, "| <unknown>"); | |
2960 | ||
2961 | return buff; | |
2962 | } | |
2963 | ||
2964 | /* Display the contents of the version sections. */ | |
2965 | static int | |
2966 | process_version_sections (file) | |
2967 | FILE * file; | |
2968 | { | |
2969 | Elf32_Internal_Shdr * section; | |
2970 | unsigned i; | |
2971 | int found = 0; | |
2972 | ||
2973 | if (! do_version) | |
2974 | return 1; | |
2975 | ||
2976 | for (i = 0, section = section_headers; | |
2977 | i < elf_header.e_shnum; | |
2978 | i++, section ++) | |
2979 | { | |
2980 | switch (section->sh_type) | |
2981 | { | |
2982 | case SHT_GNU_verdef: | |
2983 | { | |
2984 | Elf_External_Verdef * edefs; | |
2985 | unsigned int idx; | |
2986 | unsigned int cnt; | |
2987 | ||
2988 | found = 1; | |
2989 | ||
2990 | printf | |
2991 | (_("\nVersion definition section '%s' contains %ld entries:\n"), | |
2992 | SECTION_NAME (section), section->sh_info); | |
2993 | ||
2994 | printf (_(" Addr: 0x")); | |
2995 | printf_vma (section->sh_addr); | |
2996 | printf (_(" Offset: %#08lx Link: %lx (%s)\n"), | |
1b228002 | 2997 | (unsigned long) section->sh_offset, section->sh_link, |
252b5132 RH |
2998 | SECTION_NAME (section_headers + section->sh_link)); |
2999 | ||
3000 | GET_DATA_ALLOC (section->sh_offset, section->sh_size, | |
3001 | edefs, Elf_External_Verdef *, | |
3002 | "version definition section"); | |
3003 | ||
3004 | for (idx = cnt = 0; cnt < section->sh_info; ++ cnt) | |
3005 | { | |
3006 | char * vstart; | |
3007 | Elf_External_Verdef * edef; | |
3008 | Elf_Internal_Verdef ent; | |
3009 | Elf_External_Verdaux * eaux; | |
3010 | Elf_Internal_Verdaux aux; | |
3011 | int j; | |
3012 | int isum; | |
3013 | ||
3014 | vstart = ((char *) edefs) + idx; | |
3015 | ||
3016 | edef = (Elf_External_Verdef *) vstart; | |
3017 | ||
3018 | ent.vd_version = BYTE_GET (edef->vd_version); | |
3019 | ent.vd_flags = BYTE_GET (edef->vd_flags); | |
3020 | ent.vd_ndx = BYTE_GET (edef->vd_ndx); | |
3021 | ent.vd_cnt = BYTE_GET (edef->vd_cnt); | |
3022 | ent.vd_hash = BYTE_GET (edef->vd_hash); | |
3023 | ent.vd_aux = BYTE_GET (edef->vd_aux); | |
3024 | ent.vd_next = BYTE_GET (edef->vd_next); | |
3025 | ||
3026 | printf (_(" %#06x: Rev: %d Flags: %s"), | |
3027 | idx, ent.vd_version, get_ver_flags (ent.vd_flags)); | |
3028 | ||
3029 | printf (_(" Index: %d Cnt: %d "), | |
3030 | ent.vd_ndx, ent.vd_cnt); | |
3031 | ||
3032 | vstart += ent.vd_aux; | |
3033 | ||
3034 | eaux = (Elf_External_Verdaux *) vstart; | |
3035 | ||
3036 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
3037 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
3038 | ||
3039 | if (dynamic_strings) | |
3040 | printf (_("Name: %s\n"), dynamic_strings + aux.vda_name); | |
3041 | else | |
3042 | printf (_("Name index: %ld\n"), aux.vda_name); | |
3043 | ||
3044 | isum = idx + ent.vd_aux; | |
3045 | ||
3046 | for (j = 1; j < ent.vd_cnt; j ++) | |
3047 | { | |
3048 | isum += aux.vda_next; | |
3049 | vstart += aux.vda_next; | |
3050 | ||
3051 | eaux = (Elf_External_Verdaux *) vstart; | |
3052 | ||
3053 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
3054 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
3055 | ||
3056 | if (dynamic_strings) | |
3057 | printf (_(" %#06x: Parent %d: %s\n"), | |
3058 | isum, j, dynamic_strings + aux.vda_name); | |
3059 | else | |
3060 | printf (_(" %#06x: Parent %d, name index: %ld\n"), | |
3061 | isum, j, aux.vda_name); | |
3062 | } | |
3063 | ||
3064 | idx += ent.vd_next; | |
3065 | } | |
3066 | ||
3067 | free (edefs); | |
3068 | } | |
3069 | break; | |
3070 | ||
3071 | case SHT_GNU_verneed: | |
3072 | { | |
3073 | Elf_External_Verneed * eneed; | |
3074 | unsigned int idx; | |
3075 | unsigned int cnt; | |
3076 | ||
3077 | found = 1; | |
3078 | ||
3079 | printf (_("\nVersion needs section '%s' contains %ld entries:\n"), | |
3080 | SECTION_NAME (section), section->sh_info); | |
3081 | ||
3082 | printf (_(" Addr: 0x")); | |
3083 | printf_vma (section->sh_addr); | |
3084 | printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"), | |
1b228002 | 3085 | (unsigned long) section->sh_offset, section->sh_link, |
252b5132 RH |
3086 | SECTION_NAME (section_headers + section->sh_link)); |
3087 | ||
3088 | GET_DATA_ALLOC (section->sh_offset, section->sh_size, | |
3089 | eneed, Elf_External_Verneed *, | |
3090 | "version need section"); | |
3091 | ||
3092 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
3093 | { | |
3094 | Elf_External_Verneed * entry; | |
3095 | Elf_Internal_Verneed ent; | |
3096 | int j; | |
3097 | int isum; | |
3098 | char * vstart; | |
3099 | ||
3100 | vstart = ((char *) eneed) + idx; | |
3101 | ||
3102 | entry = (Elf_External_Verneed *) vstart; | |
3103 | ||
3104 | ent.vn_version = BYTE_GET (entry->vn_version); | |
3105 | ent.vn_cnt = BYTE_GET (entry->vn_cnt); | |
3106 | ent.vn_file = BYTE_GET (entry->vn_file); | |
3107 | ent.vn_aux = BYTE_GET (entry->vn_aux); | |
3108 | ent.vn_next = BYTE_GET (entry->vn_next); | |
3109 | ||
3110 | printf (_(" %#06x: Version: %d"), idx, ent.vn_version); | |
3111 | ||
3112 | if (dynamic_strings) | |
3113 | printf (_(" File: %s"), dynamic_strings + ent.vn_file); | |
3114 | else | |
3115 | printf (_(" File: %lx"), ent.vn_file); | |
3116 | ||
3117 | printf (_(" Cnt: %d\n"), ent.vn_cnt); | |
3118 | ||
3119 | vstart += ent.vn_aux; | |
3120 | ||
3121 | for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) | |
3122 | { | |
3123 | Elf_External_Vernaux * eaux; | |
3124 | Elf_Internal_Vernaux aux; | |
3125 | ||
3126 | eaux = (Elf_External_Vernaux *) vstart; | |
3127 | ||
3128 | aux.vna_hash = BYTE_GET (eaux->vna_hash); | |
3129 | aux.vna_flags = BYTE_GET (eaux->vna_flags); | |
3130 | aux.vna_other = BYTE_GET (eaux->vna_other); | |
3131 | aux.vna_name = BYTE_GET (eaux->vna_name); | |
3132 | aux.vna_next = BYTE_GET (eaux->vna_next); | |
3133 | ||
3134 | if (dynamic_strings) | |
3135 | printf (_(" %#06x: Name: %s"), | |
3136 | isum, dynamic_strings + aux.vna_name); | |
3137 | else | |
3138 | printf (_(" %#06x: Name index: %lx"), | |
3139 | isum, aux.vna_name); | |
3140 | ||
3141 | printf (_(" Flags: %s Version: %d\n"), | |
3142 | get_ver_flags (aux.vna_flags), aux.vna_other); | |
3143 | ||
3144 | isum += aux.vna_next; | |
3145 | vstart += aux.vna_next; | |
3146 | } | |
3147 | ||
3148 | idx += ent.vn_next; | |
3149 | } | |
3150 | ||
3151 | free (eneed); | |
3152 | } | |
3153 | break; | |
3154 | ||
3155 | case SHT_GNU_versym: | |
3156 | { | |
3157 | Elf32_Internal_Shdr * link_section; | |
3158 | int total; | |
3159 | int cnt; | |
3160 | unsigned char * edata; | |
3161 | unsigned short * data; | |
3162 | char * strtab; | |
3163 | Elf_Internal_Sym * symbols; | |
3164 | Elf32_Internal_Shdr * string_sec; | |
3165 | ||
3166 | link_section = section_headers + section->sh_link; | |
3167 | total = section->sh_size / section->sh_entsize; | |
3168 | ||
3169 | found = 1; | |
3170 | ||
9ea033b2 NC |
3171 | symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset, |
3172 | link_section->sh_size / link_section->sh_entsize); | |
252b5132 RH |
3173 | |
3174 | string_sec = section_headers + link_section->sh_link; | |
3175 | ||
3176 | GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size, | |
3177 | strtab, char *, "version string table"); | |
3178 | ||
3179 | printf (_("\nVersion symbols section '%s' contains %d entries:\n"), | |
3180 | SECTION_NAME (section), total); | |
3181 | ||
3182 | printf (_(" Addr: ")); | |
3183 | printf_vma (section->sh_addr); | |
3184 | printf (_(" Offset: %#08lx Link: %lx (%s)\n"), | |
1b228002 | 3185 | (unsigned long) section->sh_offset, section->sh_link, |
252b5132 RH |
3186 | SECTION_NAME (link_section)); |
3187 | ||
3188 | GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)] | |
3189 | - loadaddr, | |
3190 | total * sizeof (short), edata, | |
3191 | unsigned char *, "version symbol data"); | |
3192 | ||
3193 | data = (unsigned short *) malloc (total * sizeof (short)); | |
3194 | ||
3195 | for (cnt = total; cnt --;) | |
3196 | data [cnt] = byte_get (edata + cnt * sizeof (short), | |
3197 | sizeof (short)); | |
3198 | ||
3199 | free (edata); | |
3200 | ||
3201 | for (cnt = 0; cnt < total; cnt += 4) | |
3202 | { | |
3203 | int j, nn; | |
3204 | ||
3205 | printf (" %03x:", cnt); | |
3206 | ||
3207 | for (j = 0; (j < 4) && (cnt + j) < total; ++j) | |
3208 | switch (data [cnt + j]) | |
3209 | { | |
3210 | case 0: | |
3211 | fputs (_(" 0 (*local*) "), stdout); | |
3212 | break; | |
3213 | ||
3214 | case 1: | |
3215 | fputs (_(" 1 (*global*) "), stdout); | |
3216 | break; | |
3217 | ||
3218 | default: | |
3219 | nn = printf ("%4x%c", data [cnt + j] & 0x7fff, | |
3220 | data [cnt + j] & 0x8000 ? 'h' : ' '); | |
3221 | ||
3222 | if (symbols [cnt + j].st_shndx < SHN_LORESERVE | |
3223 | && section_headers[symbols [cnt + j].st_shndx].sh_type | |
3224 | == SHT_NOBITS) | |
3225 | { | |
3226 | /* We must test both. */ | |
3227 | Elf_Internal_Verneed ivn; | |
3228 | unsigned long offset; | |
3229 | ||
3230 | offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)] | |
3231 | - loadaddr; | |
3232 | ||
3233 | do | |
3234 | { | |
3235 | Elf_External_Verneed evn; | |
3236 | Elf_External_Vernaux evna; | |
3237 | Elf_Internal_Vernaux ivna; | |
3238 | unsigned long vna_off; | |
3239 | ||
3240 | GET_DATA (offset, evn, "version need"); | |
3241 | ||
3242 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
3243 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
3244 | ||
3245 | vna_off = offset + ivn.vn_aux; | |
3246 | ||
3247 | do | |
3248 | { | |
3249 | GET_DATA (vna_off, evna, | |
3250 | "version need aux (1)"); | |
3251 | ||
3252 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
3253 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
3254 | ||
3255 | vna_off += ivna.vna_next; | |
3256 | } | |
3257 | while (ivna.vna_other != data [cnt + j] | |
3258 | && ivna.vna_next != 0); | |
3259 | ||
3260 | if (ivna.vna_other == data [cnt + j]) | |
3261 | { | |
3262 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
3263 | ||
3264 | nn += printf ("(%s%-*s", | |
3265 | strtab + ivna.vna_name, | |
3266 | 12 - strlen (strtab | |
3267 | + ivna.vna_name), | |
3268 | ")"); | |
3269 | break; | |
3270 | } | |
3271 | else if (ivn.vn_next == 0) | |
3272 | { | |
3273 | if (data [cnt + j] != 0x8001) | |
3274 | { | |
3275 | Elf_Internal_Verdef ivd; | |
3276 | Elf_External_Verdef evd; | |
3277 | ||
3278 | offset = version_info | |
3279 | [DT_VERSIONTAGIDX (DT_VERDEF)] | |
3280 | - loadaddr; | |
3281 | ||
3282 | do | |
3283 | { | |
3284 | GET_DATA (offset, evd, | |
3285 | "version definition"); | |
3286 | ||
3287 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
3288 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
3289 | ||
3290 | offset += ivd.vd_next; | |
3291 | } | |
3292 | while (ivd.vd_ndx | |
3293 | != (data [cnt + j] & 0x7fff) | |
3294 | && ivd.vd_next != 0); | |
3295 | ||
3296 | if (ivd.vd_ndx | |
3297 | == (data [cnt + j] & 0x7fff)) | |
3298 | { | |
3299 | Elf_External_Verdaux evda; | |
3300 | Elf_Internal_Verdaux ivda; | |
3301 | ||
3302 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
3303 | ||
3304 | GET_DATA (offset + ivd.vd_aux, evda, | |
3305 | "version definition aux"); | |
3306 | ||
3307 | ivda.vda_name = | |
3308 | BYTE_GET (evda.vda_name); | |
3309 | ||
3310 | nn += | |
3311 | printf ("(%s%-*s", | |
3312 | strtab + ivda.vda_name, | |
3313 | 12 | |
3314 | - strlen (strtab | |
3315 | + ivda.vda_name), | |
3316 | ")"); | |
3317 | } | |
3318 | } | |
3319 | ||
3320 | break; | |
3321 | } | |
3322 | else | |
3323 | offset += ivn.vn_next; | |
3324 | } | |
3325 | while (ivn.vn_next); | |
3326 | } | |
3327 | else if (symbols [cnt + j].st_shndx == SHN_UNDEF) | |
3328 | { | |
3329 | Elf_Internal_Verneed ivn; | |
3330 | unsigned long offset; | |
3331 | ||
3332 | offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)] | |
3333 | - loadaddr; | |
3334 | ||
3335 | do | |
3336 | { | |
3337 | Elf_Internal_Vernaux ivna; | |
3338 | Elf_External_Verneed evn; | |
3339 | Elf_External_Vernaux evna; | |
3340 | unsigned long a_off; | |
3341 | ||
3342 | GET_DATA (offset, evn, "version need"); | |
3343 | ||
3344 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
3345 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
3346 | ||
3347 | a_off = offset + ivn.vn_aux; | |
3348 | ||
3349 | do | |
3350 | { | |
3351 | GET_DATA (a_off, evna, | |
3352 | "version need aux (2)"); | |
3353 | ||
3354 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
3355 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
3356 | ||
3357 | a_off += ivna.vna_next; | |
3358 | } | |
3359 | while (ivna.vna_other != data [cnt + j] | |
3360 | && ivna.vna_next != 0); | |
3361 | ||
3362 | if (ivna.vna_other == data [cnt + j]) | |
3363 | { | |
3364 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
3365 | ||
3366 | nn += printf ("(%s%-*s", | |
3367 | strtab + ivna.vna_name, | |
3368 | 12 - strlen (strtab | |
3369 | + ivna.vna_name), | |
3370 | ")"); | |
3371 | break; | |
3372 | } | |
3373 | ||
3374 | offset += ivn.vn_next; | |
3375 | } | |
3376 | while (ivn.vn_next); | |
3377 | } | |
3378 | else if (data [cnt + j] != 0x8001) | |
3379 | { | |
3380 | Elf_Internal_Verdef ivd; | |
3381 | Elf_External_Verdef evd; | |
3382 | unsigned long offset; | |
3383 | ||
3384 | offset = version_info | |
3385 | [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr; | |
3386 | ||
3387 | do | |
3388 | { | |
3389 | GET_DATA (offset, evd, "version def"); | |
3390 | ||
3391 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
3392 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
3393 | ||
3394 | offset += ivd.vd_next; | |
3395 | } | |
3396 | while (ivd.vd_ndx != (data [cnt + j] & 0x7fff) | |
3397 | && ivd.vd_next != 0); | |
3398 | ||
3399 | if (ivd.vd_ndx == (data [cnt + j] & 0x7fff)) | |
3400 | { | |
3401 | Elf_External_Verdaux evda; | |
3402 | Elf_Internal_Verdaux ivda; | |
3403 | ||
3404 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
3405 | ||
3406 | GET_DATA (offset - ivd.vd_next + ivd.vd_aux, | |
3407 | evda, "version def aux"); | |
3408 | ||
3409 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
3410 | ||
3411 | nn += printf ("(%s%-*s", | |
3412 | strtab + ivda.vda_name, | |
3413 | 12 - strlen (strtab | |
3414 | + ivda.vda_name), | |
3415 | ")"); | |
3416 | } | |
3417 | } | |
3418 | ||
3419 | if (nn < 18) | |
3420 | printf ("%*c", 18 - nn, ' '); | |
3421 | } | |
3422 | ||
3423 | putchar ('\n'); | |
3424 | } | |
3425 | ||
3426 | free (data); | |
3427 | free (strtab); | |
3428 | free (symbols); | |
3429 | } | |
3430 | break; | |
3431 | ||
3432 | default: | |
3433 | break; | |
3434 | } | |
3435 | } | |
3436 | ||
3437 | if (! found) | |
3438 | printf (_("\nNo version information found in this file.\n")); | |
3439 | ||
3440 | return 1; | |
3441 | } | |
3442 | ||
3443 | static char * | |
3444 | get_symbol_binding (binding) | |
3445 | unsigned int binding; | |
3446 | { | |
3447 | static char buff [32]; | |
3448 | ||
3449 | switch (binding) | |
3450 | { | |
3451 | case STB_LOCAL: return _("LOCAL"); | |
3452 | case STB_GLOBAL: return _("GLOBAL"); | |
3453 | case STB_WEAK: return _("WEAK"); | |
3454 | default: | |
3455 | if (binding >= STB_LOPROC && binding <= STB_HIPROC) | |
3456 | sprintf (buff, _("<processor specific>: %d"), binding); | |
3457 | else if (binding >= STB_LOOS && binding <= STB_HIOS) | |
3458 | sprintf (buff, _("<OS specific>: %d"), binding); | |
3459 | else | |
3460 | sprintf (buff, _("<unknown>: %d"), binding); | |
3461 | return buff; | |
3462 | } | |
3463 | } | |
3464 | ||
3465 | static char * | |
3466 | get_symbol_type (type) | |
3467 | unsigned int type; | |
3468 | { | |
3469 | static char buff [32]; | |
3470 | ||
3471 | switch (type) | |
3472 | { | |
3473 | case STT_NOTYPE: return _("NOTYPE"); | |
3474 | case STT_OBJECT: return _("OBJECT"); | |
3475 | case STT_FUNC: return _("FUNC"); | |
3476 | case STT_SECTION: return _("SECTION"); | |
3477 | case STT_FILE: return _("FILE"); | |
3478 | default: | |
3479 | if (type >= STT_LOPROC && type <= STT_HIPROC) | |
df75f1af NC |
3480 | { |
3481 | if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) | |
3482 | return _("THUMB_FUNC"); | |
351b4b40 RH |
3483 | |
3484 | if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) | |
3485 | return _("REGISTER"); | |
df75f1af NC |
3486 | |
3487 | sprintf (buff, _("<processor specific>: %d"), type); | |
3488 | } | |
252b5132 RH |
3489 | else if (type >= STT_LOOS && type <= STT_HIOS) |
3490 | sprintf (buff, _("<OS specific>: %d"), type); | |
3491 | else | |
3492 | sprintf (buff, _("<unknown>: %d"), type); | |
3493 | return buff; | |
3494 | } | |
3495 | } | |
3496 | ||
3497 | static char * | |
3498 | get_symbol_index_type (type) | |
3499 | unsigned int type; | |
3500 | { | |
3501 | switch (type) | |
3502 | { | |
3503 | case SHN_UNDEF: return "UND"; | |
3504 | case SHN_ABS: return "ABS"; | |
3505 | case SHN_COMMON: return "COM"; | |
3506 | default: | |
3507 | if (type >= SHN_LOPROC && type <= SHN_HIPROC) | |
3508 | return "PRC"; | |
3509 | else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE) | |
3510 | return "RSV"; | |
3511 | else if (type >= SHN_LOOS && type <= SHN_HIOS) | |
3512 | return "OS "; | |
3513 | else | |
3514 | { | |
3515 | static char buff [32]; | |
3516 | ||
3517 | sprintf (buff, "%3d", type); | |
3518 | return buff; | |
3519 | } | |
3520 | } | |
3521 | } | |
3522 | ||
3523 | ||
3524 | static int * | |
3525 | get_dynamic_data (file, number) | |
3526 | FILE * file; | |
3527 | unsigned int number; | |
3528 | { | |
3529 | char * e_data; | |
3530 | int * i_data; | |
3531 | ||
3532 | e_data = (char *) malloc (number * 4); | |
3533 | ||
3534 | if (e_data == NULL) | |
3535 | { | |
3536 | error (_("Out of memory\n")); | |
3537 | return NULL; | |
3538 | } | |
3539 | ||
3540 | if (fread (e_data, 4, number, file) != number) | |
3541 | { | |
3542 | error (_("Unable to read in dynamic data\n")); | |
3543 | return NULL; | |
3544 | } | |
3545 | ||
3546 | i_data = (int *) malloc (number * sizeof (* i_data)); | |
3547 | ||
3548 | if (i_data == NULL) | |
3549 | { | |
3550 | error (_("Out of memory\n")); | |
3551 | free (e_data); | |
3552 | return NULL; | |
3553 | } | |
3554 | ||
3555 | while (number--) | |
3556 | i_data [number] = byte_get (e_data + number * 4, 4); | |
3557 | ||
3558 | free (e_data); | |
3559 | ||
3560 | return i_data; | |
3561 | } | |
3562 | ||
3563 | /* Dump the symbol table */ | |
3564 | static int | |
3565 | process_symbol_table (file) | |
3566 | FILE * file; | |
3567 | { | |
3568 | Elf32_Internal_Shdr * section; | |
3569 | char nb [4]; | |
3570 | char nc [4]; | |
b4c96d0d | 3571 | int nbuckets = 0; |
252b5132 RH |
3572 | int nchains; |
3573 | int * buckets = NULL; | |
3574 | int * chains = NULL; | |
3575 | ||
3576 | if (! do_syms && !do_histogram) | |
3577 | return 1; | |
3578 | ||
3579 | if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL) | |
3580 | || do_histogram)) | |
3581 | { | |
3582 | if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET)) | |
3583 | { | |
3584 | error (_("Unable to seek to start of dynamic information")); | |
3585 | return 0; | |
3586 | } | |
3587 | ||
3588 | if (fread (nb, sizeof (nb), 1, file) != 1) | |
3589 | { | |
3590 | error (_("Failed to read in number of buckets\n")); | |
3591 | return 0; | |
3592 | } | |
3593 | ||
3594 | if (fread (nc, sizeof (nc), 1, file) != 1) | |
3595 | { | |
3596 | error (_("Failed to read in number of chains\n")); | |
3597 | return 0; | |
3598 | } | |
3599 | ||
3600 | nbuckets = byte_get (nb, 4); | |
3601 | nchains = byte_get (nc, 4); | |
3602 | ||
3603 | buckets = get_dynamic_data (file, nbuckets); | |
3604 | chains = get_dynamic_data (file, nchains); | |
3605 | ||
3606 | if (buckets == NULL || chains == NULL) | |
3607 | return 0; | |
3608 | } | |
3609 | ||
3610 | if (do_syms | |
3611 | && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL) | |
3612 | { | |
3613 | int hn; | |
3614 | int si; | |
3615 | ||
3616 | printf (_("\nSymbol table for image:\n")); | |
3617 | printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n")); | |
3618 | ||
3619 | for (hn = 0; hn < nbuckets; hn++) | |
3620 | { | |
3621 | if (! buckets [hn]) | |
3622 | continue; | |
3623 | ||
3624 | for (si = buckets [hn]; si; si = chains [si]) | |
3625 | { | |
3626 | Elf_Internal_Sym * psym; | |
3627 | ||
3628 | psym = dynamic_symbols + si; | |
3629 | ||
3630 | printf (" %3d %3d: %8lx %5ld %6s %6s %2d ", | |
3631 | si, hn, | |
3632 | (unsigned long) psym->st_value, | |
3633 | (unsigned long) psym->st_size, | |
3634 | get_symbol_type (ELF_ST_TYPE (psym->st_info)), | |
3635 | get_symbol_binding (ELF_ST_BIND (psym->st_info)), | |
3636 | psym->st_other); | |
3637 | ||
3638 | printf ("%3.3s", get_symbol_index_type (psym->st_shndx)); | |
3639 | ||
3640 | printf (" %s\n", dynamic_strings + psym->st_name); | |
3641 | } | |
3642 | } | |
3643 | } | |
3644 | else if (do_syms && !do_using_dynamic) | |
3645 | { | |
3646 | unsigned int i; | |
3647 | ||
3648 | for (i = 0, section = section_headers; | |
3649 | i < elf_header.e_shnum; | |
3650 | i++, section++) | |
3651 | { | |
3652 | unsigned int si; | |
3653 | char * strtab; | |
3654 | Elf_Internal_Sym * symtab; | |
3655 | Elf_Internal_Sym * psym; | |
3656 | ||
3657 | ||
3658 | if ( section->sh_type != SHT_SYMTAB | |
3659 | && section->sh_type != SHT_DYNSYM) | |
3660 | continue; | |
3661 | ||
3662 | printf (_("\nSymbol table '%s' contains %lu entries:\n"), | |
3663 | SECTION_NAME (section), | |
3664 | (unsigned long) (section->sh_size / section->sh_entsize)); | |
3665 | fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"), | |
3666 | stdout); | |
3667 | ||
9ea033b2 | 3668 | symtab = GET_ELF_SYMBOLS (file, section->sh_offset, |
252b5132 RH |
3669 | section->sh_size / section->sh_entsize); |
3670 | if (symtab == NULL) | |
3671 | continue; | |
3672 | ||
3673 | if (section->sh_link == elf_header.e_shstrndx) | |
3674 | strtab = string_table; | |
3675 | else | |
3676 | { | |
3677 | Elf32_Internal_Shdr * string_sec; | |
3678 | ||
3679 | string_sec = section_headers + section->sh_link; | |
3680 | ||
3681 | GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size, | |
3682 | strtab, char *, "string table"); | |
3683 | } | |
3684 | ||
3685 | for (si = 0, psym = symtab; | |
3686 | si < section->sh_size / section->sh_entsize; | |
3687 | si ++, psym ++) | |
3688 | { | |
3689 | printf (" %3d: %8lx %5ld %-7s %-6s %2d ", | |
3690 | si, | |
3691 | (unsigned long) psym->st_value, | |
3692 | (unsigned long) psym->st_size, | |
3693 | get_symbol_type (ELF_ST_TYPE (psym->st_info)), | |
3694 | get_symbol_binding (ELF_ST_BIND (psym->st_info)), | |
3695 | psym->st_other); | |
3696 | ||
1b228002 | 3697 | printf ("%4s", get_symbol_index_type (psym->st_shndx)); |
252b5132 RH |
3698 | |
3699 | printf (" %s", strtab + psym->st_name); | |
3700 | ||
3701 | if (section->sh_type == SHT_DYNSYM && | |
3702 | version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0) | |
3703 | { | |
3704 | unsigned char data[2]; | |
3705 | unsigned short vers_data; | |
3706 | unsigned long offset; | |
3707 | int is_nobits; | |
3708 | int check_def; | |
3709 | ||
3710 | offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)] | |
3711 | - loadaddr; | |
3712 | ||
3713 | GET_DATA (offset + si * sizeof (vers_data), data, | |
3714 | "version data"); | |
3715 | ||
3716 | vers_data = byte_get (data, 2); | |
3717 | ||
3718 | is_nobits = psym->st_shndx < SHN_LORESERVE ? | |
3719 | (section_headers [psym->st_shndx].sh_type == SHT_NOBITS) | |
3720 | : 0; | |
3721 | ||
3722 | check_def = (psym->st_shndx != SHN_UNDEF); | |
3723 | ||
3724 | if ((vers_data & 0x8000) || vers_data > 1) | |
3725 | { | |
3726 | if (is_nobits || ! check_def) | |
3727 | { | |
3728 | Elf_External_Verneed evn; | |
3729 | Elf_Internal_Verneed ivn; | |
3730 | Elf_Internal_Vernaux ivna; | |
3731 | ||
3732 | /* We must test both. */ | |
3733 | offset = version_info | |
3734 | [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr; | |
3735 | ||
3736 | GET_DATA (offset, evn, "version need"); | |
3737 | ||
3738 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
3739 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
3740 | ||
3741 | do | |
3742 | { | |
3743 | unsigned long vna_off; | |
3744 | ||
3745 | vna_off = offset + ivn.vn_aux; | |
3746 | ||
3747 | do | |
3748 | { | |
3749 | Elf_External_Vernaux evna; | |
3750 | ||
3751 | GET_DATA (vna_off, evna, | |
3752 | "version need aux (3)"); | |
3753 | ||
3754 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
3755 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
3756 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
3757 | ||
3758 | vna_off += ivna.vna_next; | |
3759 | } | |
3760 | while (ivna.vna_other != vers_data | |
3761 | && ivna.vna_next != 0); | |
3762 | ||
3763 | if (ivna.vna_other == vers_data) | |
3764 | break; | |
3765 | ||
3766 | offset += ivn.vn_next; | |
3767 | } | |
3768 | while (ivn.vn_next != 0); | |
3769 | ||
3770 | if (ivna.vna_other == vers_data) | |
3771 | { | |
3772 | printf ("@%s (%d)", | |
3773 | strtab + ivna.vna_name, ivna.vna_other); | |
3774 | check_def = 0; | |
3775 | } | |
3776 | else if (! is_nobits) | |
3777 | error (_("bad dynamic symbol")); | |
3778 | else | |
3779 | check_def = 1; | |
3780 | } | |
3781 | ||
3782 | if (check_def) | |
3783 | { | |
3784 | if (vers_data != 0x8001) | |
3785 | { | |
3786 | Elf_Internal_Verdef ivd; | |
3787 | Elf_Internal_Verdaux ivda; | |
3788 | Elf_External_Verdaux evda; | |
3789 | unsigned long offset; | |
3790 | ||
3791 | offset = | |
3792 | version_info [DT_VERSIONTAGIDX (DT_VERDEF)] | |
3793 | - loadaddr; | |
3794 | ||
3795 | do | |
3796 | { | |
3797 | Elf_External_Verdef evd; | |
3798 | ||
3799 | GET_DATA (offset, evd, "version def"); | |
3800 | ||
3801 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
3802 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
3803 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
3804 | ||
3805 | offset += ivd.vd_next; | |
3806 | } | |
3807 | while (ivd.vd_ndx != (vers_data & 0x7fff) | |
3808 | && ivd.vd_next != 0); | |
3809 | ||
3810 | offset -= ivd.vd_next; | |
3811 | offset += ivd.vd_aux; | |
3812 | ||
3813 | GET_DATA (offset, evda, "version def aux"); | |
3814 | ||
3815 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
3816 | ||
3817 | if (psym->st_name != ivda.vda_name) | |
3818 | printf ((vers_data & 0x8000) | |
3819 | ? "@%s" : "@@%s", | |
3820 | strtab + ivda.vda_name); | |
3821 | } | |
3822 | } | |
3823 | } | |
3824 | } | |
3825 | ||
3826 | putchar ('\n'); | |
3827 | } | |
3828 | ||
3829 | free (symtab); | |
3830 | if (strtab != string_table) | |
3831 | free (strtab); | |
3832 | } | |
3833 | } | |
3834 | else if (do_syms) | |
3835 | printf | |
3836 | (_("\nDynamic symbol information is not available for displaying symbols.\n")); | |
3837 | ||
3838 | if (do_histogram && buckets != NULL) | |
3839 | { | |
3840 | int *lengths; | |
3841 | int *counts; | |
3842 | int hn; | |
3843 | int si; | |
3844 | int maxlength = 0; | |
3845 | int nzero_counts = 0; | |
3846 | int nsyms = 0; | |
3847 | ||
3848 | printf (_("\nHistogram for bucket list length (total of %d buckets):\n"), | |
3849 | nbuckets); | |
3850 | printf (_(" Length Number %% of total Coverage\n")); | |
3851 | ||
3852 | lengths = (int *) calloc (nbuckets, sizeof (int)); | |
3853 | if (lengths == NULL) | |
3854 | { | |
3855 | error (_("Out of memory")); | |
3856 | return 0; | |
3857 | } | |
3858 | for (hn = 0; hn < nbuckets; ++hn) | |
3859 | { | |
3860 | if (! buckets [hn]) | |
3861 | continue; | |
3862 | ||
3863 | for (si = buckets[hn]; si; si = chains[si]) | |
3864 | { | |
3865 | ++nsyms; | |
3866 | if (maxlength < ++lengths[hn]) | |
3867 | ++maxlength; | |
3868 | } | |
3869 | } | |
3870 | ||
3871 | counts = (int *) calloc (maxlength + 1, sizeof (int)); | |
3872 | if (counts == NULL) | |
3873 | { | |
3874 | error (_("Out of memory")); | |
3875 | return 0; | |
3876 | } | |
3877 | ||
3878 | for (hn = 0; hn < nbuckets; ++hn) | |
3879 | ++ counts [lengths [hn]]; | |
3880 | ||
3881 | printf (" 0 %-10d (%5.1f%%)\n", | |
3882 | counts[0], (counts[0] * 100.0) / nbuckets); | |
3883 | for (si = 1; si <= maxlength; ++si) | |
3884 | { | |
3885 | nzero_counts += counts[si] * si; | |
3886 | printf ("%7d %-10d (%5.1f%%) %5.1f%%\n", | |
3887 | si, counts[si], (counts[si] * 100.0) / nbuckets, | |
3888 | (nzero_counts * 100.0) / nsyms); | |
3889 | } | |
3890 | ||
3891 | free (counts); | |
3892 | free (lengths); | |
3893 | } | |
3894 | ||
3895 | if (buckets != NULL) | |
3896 | { | |
3897 | free (buckets); | |
3898 | free (chains); | |
3899 | } | |
3900 | ||
3901 | return 1; | |
3902 | } | |
3903 | ||
3904 | static int | |
3905 | process_syminfo (file) | |
b4c96d0d | 3906 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 | 3907 | { |
b4c96d0d | 3908 | unsigned int i; |
252b5132 RH |
3909 | |
3910 | if (dynamic_syminfo == NULL | |
3911 | || !do_dynamic) | |
3912 | /* No syminfo, this is ok. */ | |
3913 | return 1; | |
3914 | ||
3915 | /* There better should be a dynamic symbol section. */ | |
3916 | if (dynamic_symbols == NULL || dynamic_strings == NULL) | |
3917 | return 0; | |
3918 | ||
3919 | if (dynamic_addr) | |
3920 | printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"), | |
3921 | dynamic_syminfo_offset, dynamic_syminfo_nent); | |
3922 | ||
3923 | printf (_(" Num: Name BoundTo Flags\n")); | |
3924 | for (i = 0; i < dynamic_syminfo_nent; ++i) | |
3925 | { | |
3926 | unsigned short int flags = dynamic_syminfo[i].si_flags; | |
3927 | ||
3928 | printf ("%4d: %-30s ", i, | |
3929 | dynamic_strings + dynamic_symbols[i].st_name); | |
3930 | ||
3931 | switch (dynamic_syminfo[i].si_boundto) | |
3932 | { | |
3933 | case SYMINFO_BT_SELF: | |
3934 | fputs ("SELF ", stdout); | |
3935 | break; | |
3936 | case SYMINFO_BT_PARENT: | |
3937 | fputs ("PARENT ", stdout); | |
3938 | break; | |
3939 | default: | |
3940 | if (dynamic_syminfo[i].si_boundto > 0 | |
3941 | && dynamic_syminfo[i].si_boundto < dynamic_size) | |
3942 | printf ("%-10s ", | |
3943 | dynamic_strings | |
3944 | + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val); | |
3945 | else | |
3946 | printf ("%-10d ", dynamic_syminfo[i].si_boundto); | |
3947 | break; | |
3948 | } | |
3949 | ||
3950 | if (flags & SYMINFO_FLG_DIRECT) | |
3951 | printf (" DIRECT"); | |
3952 | if (flags & SYMINFO_FLG_PASSTHRU) | |
3953 | printf (" PASSTHRU"); | |
3954 | if (flags & SYMINFO_FLG_COPY) | |
3955 | printf (" COPY"); | |
3956 | if (flags & SYMINFO_FLG_LAZYLOAD) | |
3957 | printf (" LAZYLOAD"); | |
3958 | ||
3959 | puts (""); | |
3960 | } | |
3961 | ||
3962 | return 1; | |
3963 | } | |
3964 | ||
3965 | #ifdef SUPPORT_DISASSEMBLY | |
3966 | static void | |
3967 | disassemble_section (section, file) | |
3968 | Elf32_Internal_Shdr * section; | |
3969 | FILE * file; | |
3970 | { | |
3971 | printf (_("\nAssembly dump of section %s\n"), | |
3972 | SECTION_NAME (section)); | |
3973 | ||
3974 | /* XXX -- to be done --- XXX */ | |
3975 | ||
3976 | return 1; | |
3977 | } | |
3978 | #endif | |
3979 | ||
3980 | static int | |
3981 | dump_section (section, file) | |
3982 | Elf32_Internal_Shdr * section; | |
3983 | FILE * file; | |
3984 | { | |
9ea033b2 NC |
3985 | bfd_size_type bytes; |
3986 | bfd_vma addr; | |
252b5132 RH |
3987 | unsigned char * data; |
3988 | unsigned char * start; | |
3989 | ||
3990 | bytes = section->sh_size; | |
3991 | ||
3992 | if (bytes == 0) | |
3993 | { | |
3994 | printf (_("\nSection '%s' has no data to dump.\n"), | |
3995 | SECTION_NAME (section)); | |
3996 | return 0; | |
3997 | } | |
3998 | else | |
3999 | printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section)); | |
4000 | ||
4001 | addr = section->sh_addr; | |
4002 | ||
4003 | GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *, | |
4004 | "section data"); | |
4005 | ||
4006 | data = start; | |
4007 | ||
4008 | while (bytes) | |
4009 | { | |
4010 | int j; | |
4011 | int k; | |
4012 | int lbytes; | |
4013 | ||
4014 | lbytes = (bytes > 16 ? 16 : bytes); | |
4015 | ||
148d3c43 | 4016 | printf (" 0x%8.8lx ", (unsigned long) addr); |
252b5132 RH |
4017 | |
4018 | switch (elf_header.e_ident [EI_DATA]) | |
4019 | { | |
9ea033b2 | 4020 | default: |
252b5132 RH |
4021 | case ELFDATA2LSB: |
4022 | for (j = 15; j >= 0; j --) | |
4023 | { | |
4024 | if (j < lbytes) | |
4025 | printf ("%2.2x", data [j]); | |
4026 | else | |
4027 | printf (" "); | |
4028 | ||
4029 | if (!(j & 0x3)) | |
4030 | printf (" "); | |
4031 | } | |
4032 | break; | |
4033 | ||
4034 | case ELFDATA2MSB: | |
4035 | for (j = 0; j < 16; j++) | |
4036 | { | |
4037 | if (j < lbytes) | |
4038 | printf ("%2.2x", data [j]); | |
4039 | else | |
4040 | printf (" "); | |
4041 | ||
4042 | if ((j & 3) == 3) | |
4043 | printf (" "); | |
4044 | } | |
4045 | break; | |
4046 | } | |
4047 | ||
4048 | for (j = 0; j < lbytes; j++) | |
4049 | { | |
4050 | k = data [j]; | |
4051 | if (k >= ' ' && k < 0x80) | |
4052 | printf ("%c", k); | |
4053 | else | |
4054 | printf ("."); | |
4055 | } | |
4056 | ||
4057 | putchar ('\n'); | |
4058 | ||
4059 | data += lbytes; | |
4060 | addr += lbytes; | |
4061 | bytes -= lbytes; | |
4062 | } | |
4063 | ||
4064 | free (start); | |
4065 | ||
4066 | return 1; | |
4067 | } | |
4068 | ||
4069 | ||
4070 | static unsigned long int | |
4071 | read_leb128 (data, length_return, sign) | |
4072 | unsigned char * data; | |
4073 | int * length_return; | |
4074 | int sign; | |
4075 | { | |
4076 | unsigned long int result = 0; | |
4077 | unsigned int num_read = 0; | |
4078 | int shift = 0; | |
4079 | unsigned char byte; | |
4080 | ||
4081 | do | |
4082 | { | |
4083 | byte = * data ++; | |
4084 | num_read ++; | |
4085 | ||
4086 | result |= (byte & 0x7f) << shift; | |
4087 | ||
4088 | shift += 7; | |
4089 | ||
4090 | } | |
4091 | while (byte & 0x80); | |
4092 | ||
4093 | if (length_return != NULL) | |
4094 | * length_return = num_read; | |
4095 | ||
4096 | if (sign && (shift < 32) && (byte & 0x40)) | |
4097 | result |= -1 << shift; | |
4098 | ||
4099 | return result; | |
4100 | } | |
4101 | ||
4102 | typedef struct State_Machine_Registers | |
4103 | { | |
4104 | unsigned long address; | |
4105 | unsigned int file; | |
4106 | unsigned int line; | |
4107 | unsigned int column; | |
4108 | int is_stmt; | |
4109 | int basic_block; | |
4110 | int end_sequence; | |
4111 | /* This variable hold the number of the last entry seen | |
4112 | in the File Table. */ | |
4113 | unsigned int last_file_entry; | |
4114 | } SMR; | |
4115 | ||
4116 | static SMR state_machine_regs; | |
4117 | ||
4118 | static void | |
4119 | reset_state_machine (is_stmt) | |
4120 | int is_stmt; | |
4121 | { | |
4122 | state_machine_regs.address = 0; | |
4123 | state_machine_regs.file = 1; | |
4124 | state_machine_regs.line = 1; | |
4125 | state_machine_regs.column = 0; | |
4126 | state_machine_regs.is_stmt = is_stmt; | |
4127 | state_machine_regs.basic_block = 0; | |
4128 | state_machine_regs.end_sequence = 0; | |
4129 | state_machine_regs.last_file_entry = 0; | |
4130 | } | |
4131 | ||
4132 | /* Handled an extend line op. Returns true if this is the end | |
4133 | of sequence. */ | |
4134 | static int | |
3590ea00 | 4135 | process_extended_line_op (data, is_stmt, pointer_size) |
252b5132 RH |
4136 | unsigned char * data; |
4137 | int is_stmt; | |
3590ea00 | 4138 | int pointer_size; |
252b5132 RH |
4139 | { |
4140 | unsigned char op_code; | |
4141 | int bytes_read; | |
4142 | unsigned int len; | |
4143 | unsigned char * name; | |
4144 | unsigned long adr; | |
4145 | ||
4146 | len = read_leb128 (data, & bytes_read, 0); | |
4147 | data += bytes_read; | |
4148 | ||
4149 | if (len == 0) | |
4150 | { | |
4151 | warn (_("badly formed extended line op encountered!")); | |
4152 | return bytes_read; | |
4153 | } | |
4154 | ||
4155 | len += bytes_read; | |
4156 | op_code = * data ++; | |
4157 | ||
4158 | printf (_(" Extended opcode %d: "), op_code); | |
4159 | ||
4160 | switch (op_code) | |
4161 | { | |
4162 | case DW_LNE_end_sequence: | |
4163 | printf (_("End of Sequence\n\n")); | |
4164 | reset_state_machine (is_stmt); | |
4165 | break; | |
4166 | ||
4167 | case DW_LNE_set_address: | |
3590ea00 | 4168 | adr = byte_get (data, pointer_size); |
252b5132 RH |
4169 | printf (_("set Address to 0x%lx\n"), adr); |
4170 | state_machine_regs.address = adr; | |
4171 | break; | |
4172 | ||
4173 | case DW_LNE_define_file: | |
4174 | printf (_(" define new File Table entry\n")); | |
4175 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
4176 | ||
4177 | printf (_(" %d\t"), ++ state_machine_regs.last_file_entry); | |
4178 | name = data; | |
4179 | data += strlen (data) + 1; | |
4180 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
4181 | data += bytes_read; | |
4182 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
4183 | data += bytes_read; | |
4184 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
4185 | printf (_("%s\n\n"), name); | |
4186 | break; | |
4187 | ||
4188 | default: | |
4189 | printf (_("UNKNOWN: length %d\n"), len - bytes_read); | |
4190 | break; | |
4191 | } | |
4192 | ||
4193 | return len; | |
4194 | } | |
4195 | ||
3590ea00 NC |
4196 | /* Size of pointers in the .debug_line section. This information is not |
4197 | really present in that section. It's obtained before dumping the debug | |
4198 | sections by doing some pre-scan of the .debug_info section. */ | |
4199 | static int debug_line_pointer_size = 4; | |
252b5132 RH |
4200 | |
4201 | static int | |
4202 | display_debug_lines (section, start, file) | |
4203 | Elf32_Internal_Shdr * section; | |
4204 | unsigned char * start; | |
b4c96d0d | 4205 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 RH |
4206 | { |
4207 | DWARF2_External_LineInfo * external; | |
4208 | DWARF2_Internal_LineInfo info; | |
4209 | unsigned char * standard_opcodes; | |
4210 | unsigned char * data = start; | |
4211 | unsigned char * end = start + section->sh_size; | |
4212 | unsigned char * end_of_sequence; | |
4213 | int i; | |
4214 | ||
4215 | printf (_("\nDump of debug contents of section %s:\n\n"), | |
4216 | SECTION_NAME (section)); | |
4217 | ||
4218 | while (data < end) | |
4219 | { | |
4220 | external = (DWARF2_External_LineInfo *) data; | |
4221 | ||
4222 | /* Check the length of the block. */ | |
4223 | info.li_length = BYTE_GET (external->li_length); | |
4224 | if (info.li_length > section->sh_size) | |
4225 | { | |
4226 | warn | |
4227 | (_("The line info appears to be corrupt - the section is too small\n")); | |
4228 | return 0; | |
4229 | } | |
4230 | ||
4231 | /* Check its version number. */ | |
4232 | info.li_version = BYTE_GET (external->li_version); | |
4233 | if (info.li_version != 2) | |
4234 | { | |
4235 | warn (_("Only DWARF version 2 line info is currently supported.\n")); | |
4236 | return 0; | |
4237 | } | |
4238 | ||
4239 | info.li_prologue_length = BYTE_GET (external->li_prologue_length); | |
4240 | info.li_min_insn_length = BYTE_GET (external->li_min_insn_length); | |
4241 | info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt); | |
4242 | info.li_line_base = BYTE_GET (external->li_line_base); | |
4243 | info.li_line_range = BYTE_GET (external->li_line_range); | |
4244 | info.li_opcode_base = BYTE_GET (external->li_opcode_base); | |
4245 | ||
4246 | /* Sign extend the line base field. */ | |
4247 | info.li_line_base <<= 24; | |
4248 | info.li_line_base >>= 24; | |
4249 | ||
4250 | printf (_(" Length: %ld\n"), info.li_length); | |
4251 | printf (_(" DWARF Version: %d\n"), info.li_version); | |
4252 | printf (_(" Prolgue Length: %d\n"), info.li_prologue_length); | |
4253 | printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length); | |
4254 | printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt); | |
4255 | printf (_(" Line Base: %d\n"), info.li_line_base); | |
4256 | printf (_(" Line Range: %d\n"), info.li_line_range); | |
4257 | printf (_(" Opcode Base: %d\n"), info.li_opcode_base); | |
4258 | ||
4259 | end_of_sequence = data + info.li_length + sizeof (info.li_length); | |
4260 | ||
4261 | reset_state_machine (info.li_default_is_stmt); | |
4262 | ||
4263 | /* Display the contents of the Opcodes table. */ | |
4264 | standard_opcodes = data + sizeof (* external); | |
4265 | ||
4266 | printf (_("\n Opcodes:\n")); | |
4267 | ||
4268 | for (i = 1; i < info.li_opcode_base; i++) | |
7a4b7442 | 4269 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); |
252b5132 RH |
4270 | |
4271 | /* Display the contents of the Directory table. */ | |
4272 | data = standard_opcodes + info.li_opcode_base - 1; | |
4273 | ||
4274 | if (* data == 0) | |
4275 | printf (_("\n The Directory Table is empty.\n")); | |
4276 | else | |
4277 | { | |
4278 | printf (_("\n The Directory Table:\n")); | |
4279 | ||
4280 | while (* data != 0) | |
4281 | { | |
4282 | printf (_(" %s\n"), data); | |
4283 | ||
4284 | data += strlen (data) + 1; | |
4285 | } | |
4286 | } | |
4287 | ||
4288 | /* Skip the NUL at the end of the table. */ | |
4289 | data ++; | |
4290 | ||
4291 | /* Display the contents of the File Name table. */ | |
4292 | if (* data == 0) | |
4293 | printf (_("\n The File Name Table is empty.\n")); | |
4294 | else | |
4295 | { | |
4296 | printf (_("\n The File Name Table:\n")); | |
4297 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
4298 | ||
4299 | while (* data != 0) | |
4300 | { | |
4301 | char * name; | |
4302 | int bytes_read; | |
4303 | ||
4304 | printf (_(" %d\t"), ++ state_machine_regs.last_file_entry); | |
4305 | name = data; | |
4306 | ||
4307 | data += strlen (data) + 1; | |
4308 | ||
4309 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
4310 | data += bytes_read; | |
4311 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
4312 | data += bytes_read; | |
4313 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
4314 | data += bytes_read; | |
4315 | printf (_("%s\n"), name); | |
4316 | } | |
4317 | } | |
4318 | ||
4319 | /* Skip the NUL at the end of the table. */ | |
4320 | data ++; | |
4321 | ||
4322 | /* Now display the statements. */ | |
4323 | printf (_("\n Line Number Statements:\n")); | |
4324 | ||
4325 | ||
4326 | while (data < end_of_sequence) | |
4327 | { | |
4328 | unsigned char op_code; | |
4329 | int adv; | |
4330 | int bytes_read; | |
4331 | ||
4332 | op_code = * data ++; | |
4333 | ||
4334 | switch (op_code) | |
4335 | { | |
4336 | case DW_LNS_extended_op: | |
3590ea00 NC |
4337 | data += process_extended_line_op (data, info.li_default_is_stmt, |
4338 | debug_line_pointer_size); | |
252b5132 RH |
4339 | break; |
4340 | ||
4341 | case DW_LNS_copy: | |
4342 | printf (_(" Copy\n")); | |
4343 | break; | |
4344 | ||
4345 | case DW_LNS_advance_pc: | |
4346 | adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0); | |
4347 | data += bytes_read; | |
4348 | state_machine_regs.address += adv; | |
4349 | printf (_(" Advance PC by %d to %lx\n"), adv, | |
4350 | state_machine_regs.address); | |
4351 | break; | |
4352 | ||
4353 | case DW_LNS_advance_line: | |
4354 | adv = read_leb128 (data, & bytes_read, 1); | |
4355 | data += bytes_read; | |
4356 | state_machine_regs.line += adv; | |
4357 | printf (_(" Advance Line by %d to %d\n"), adv, | |
4358 | state_machine_regs.line); | |
4359 | break; | |
4360 | ||
4361 | case DW_LNS_set_file: | |
4362 | adv = read_leb128 (data, & bytes_read, 0); | |
4363 | data += bytes_read; | |
4364 | printf (_(" Set File Name to entry %d in the File Name Table\n"), | |
4365 | adv); | |
4366 | state_machine_regs.file = adv; | |
4367 | break; | |
4368 | ||
4369 | case DW_LNS_set_column: | |
4370 | adv = read_leb128 (data, & bytes_read, 0); | |
4371 | data += bytes_read; | |
4372 | printf (_(" Set column to %d\n"), adv); | |
4373 | state_machine_regs.column = adv; | |
4374 | break; | |
4375 | ||
4376 | case DW_LNS_negate_stmt: | |
4377 | adv = state_machine_regs.is_stmt; | |
4378 | adv = ! adv; | |
4379 | printf (_(" Set is_stmt to %d\n"), adv); | |
4380 | state_machine_regs.is_stmt = adv; | |
4381 | break; | |
4382 | ||
4383 | case DW_LNS_set_basic_block: | |
4384 | printf (_(" Set basic block\n")); | |
4385 | state_machine_regs.basic_block = 1; | |
4386 | break; | |
4387 | ||
4388 | case DW_LNS_const_add_pc: | |
2366453a NC |
4389 | adv = (((255 - info.li_opcode_base) / info.li_line_range) |
4390 | * info.li_min_insn_length); | |
252b5132 RH |
4391 | state_machine_regs.address += adv; |
4392 | printf (_(" Advance PC by constant %d to 0x%lx\n"), adv, | |
4393 | state_machine_regs.address); | |
4394 | break; | |
4395 | ||
4396 | case DW_LNS_fixed_advance_pc: | |
4397 | adv = byte_get (data, 2); | |
4398 | data += 2; | |
4399 | state_machine_regs.address += adv; | |
4400 | printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"), | |
4401 | adv, state_machine_regs.address); | |
4402 | break; | |
4403 | ||
4404 | default: | |
4405 | op_code -= info.li_opcode_base; | |
4406 | adv = (op_code / info.li_line_range) * info.li_min_insn_length; | |
4407 | state_machine_regs.address += adv; | |
4408 | printf (_(" Special opcode %d: advance Address by %d to 0x%lx"), | |
4409 | op_code, adv, state_machine_regs.address); | |
75d74c48 | 4410 | adv = (op_code % info.li_line_range) + info.li_line_base; |
252b5132 RH |
4411 | state_machine_regs.line += adv; |
4412 | printf (_(" and Line by %d to %d\n"), | |
4413 | adv, state_machine_regs.line); | |
4414 | break; | |
4415 | } | |
4416 | } | |
4417 | printf ("\n"); | |
4418 | } | |
4419 | ||
4420 | return 1; | |
4421 | } | |
4422 | ||
4423 | static int | |
4424 | display_debug_pubnames (section, start, file) | |
4425 | Elf32_Internal_Shdr * section; | |
4426 | unsigned char * start; | |
b4c96d0d | 4427 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 RH |
4428 | { |
4429 | DWARF2_External_PubNames * external; | |
4430 | DWARF2_Internal_PubNames pubnames; | |
4431 | unsigned char * end; | |
4432 | ||
4433 | end = start + section->sh_size; | |
4434 | ||
4435 | printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); | |
4436 | ||
4437 | while (start < end) | |
4438 | { | |
4439 | unsigned char * data; | |
4440 | unsigned long offset; | |
4441 | ||
4442 | external = (DWARF2_External_PubNames *) start; | |
4443 | ||
4444 | pubnames.pn_length = BYTE_GET (external->pn_length); | |
4445 | pubnames.pn_version = BYTE_GET (external->pn_version); | |
4446 | pubnames.pn_offset = BYTE_GET (external->pn_offset); | |
4447 | pubnames.pn_size = BYTE_GET (external->pn_size); | |
4448 | ||
4449 | data = start + sizeof (* external); | |
4450 | start += pubnames.pn_length + sizeof (external->pn_length); | |
4451 | ||
4452 | if (pubnames.pn_version != 2) | |
4453 | { | |
4454 | warn (_("Only DWARF 2 pubnames are currently supported")); | |
4455 | continue; | |
4456 | } | |
4457 | ||
4458 | printf (_(" Length: %ld\n"), | |
4459 | pubnames.pn_length); | |
4460 | printf (_(" Version: %d\n"), | |
4461 | pubnames.pn_version); | |
4462 | printf (_(" Offset into .debug_info section: %ld\n"), | |
4463 | pubnames.pn_offset); | |
4464 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
4465 | pubnames.pn_size); | |
4466 | ||
4467 | printf (_("\n Offset\tName\n")); | |
4468 | ||
4469 | do | |
4470 | { | |
4471 | offset = byte_get (data, 4); | |
4472 | ||
4473 | if (offset != 0) | |
4474 | { | |
4475 | data += 4; | |
4476 | printf (" %ld\t\t%s\n", offset, data); | |
4477 | data += strlen (data) + 1; | |
4478 | } | |
4479 | } | |
4480 | while (offset != 0); | |
4481 | } | |
4482 | ||
4483 | printf ("\n"); | |
4484 | return 1; | |
4485 | } | |
4486 | ||
4487 | static char * | |
4488 | get_TAG_name (tag) | |
4489 | unsigned long tag; | |
4490 | { | |
4491 | switch (tag) | |
4492 | { | |
4493 | case DW_TAG_padding: return "DW_TAG_padding"; | |
4494 | case DW_TAG_array_type: return "DW_TAG_array_type"; | |
4495 | case DW_TAG_class_type: return "DW_TAG_class_type"; | |
4496 | case DW_TAG_entry_point: return "DW_TAG_entry_point"; | |
4497 | case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type"; | |
4498 | case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter"; | |
4499 | case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration"; | |
4500 | case DW_TAG_label: return "DW_TAG_label"; | |
4501 | case DW_TAG_lexical_block: return "DW_TAG_lexical_block"; | |
4502 | case DW_TAG_member: return "DW_TAG_member"; | |
4503 | case DW_TAG_pointer_type: return "DW_TAG_pointer_type"; | |
4504 | case DW_TAG_reference_type: return "DW_TAG_reference_type"; | |
4505 | case DW_TAG_compile_unit: return "DW_TAG_compile_unit"; | |
4506 | case DW_TAG_string_type: return "DW_TAG_string_type"; | |
4507 | case DW_TAG_structure_type: return "DW_TAG_structure_type"; | |
4508 | case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type"; | |
4509 | case DW_TAG_typedef: return "DW_TAG_typedef"; | |
4510 | case DW_TAG_union_type: return "DW_TAG_union_type"; | |
4511 | case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters"; | |
4512 | case DW_TAG_variant: return "DW_TAG_variant"; | |
4513 | case DW_TAG_common_block: return "DW_TAG_common_block"; | |
4514 | case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion"; | |
4515 | case DW_TAG_inheritance: return "DW_TAG_inheritance"; | |
4516 | case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine"; | |
4517 | case DW_TAG_module: return "DW_TAG_module"; | |
4518 | case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type"; | |
4519 | case DW_TAG_set_type: return "DW_TAG_set_type"; | |
4520 | case DW_TAG_subrange_type: return "DW_TAG_subrange_type"; | |
4521 | case DW_TAG_with_stmt: return "DW_TAG_with_stmt"; | |
4522 | case DW_TAG_access_declaration: return "DW_TAG_access_declaration"; | |
4523 | case DW_TAG_base_type: return "DW_TAG_base_type"; | |
4524 | case DW_TAG_catch_block: return "DW_TAG_catch_block"; | |
4525 | case DW_TAG_const_type: return "DW_TAG_const_type"; | |
4526 | case DW_TAG_constant: return "DW_TAG_constant"; | |
4527 | case DW_TAG_enumerator: return "DW_TAG_enumerator"; | |
4528 | case DW_TAG_file_type: return "DW_TAG_file_type"; | |
4529 | case DW_TAG_friend: return "DW_TAG_friend"; | |
4530 | case DW_TAG_namelist: return "DW_TAG_namelist"; | |
4531 | case DW_TAG_namelist_item: return "DW_TAG_namelist_item"; | |
4532 | case DW_TAG_packed_type: return "DW_TAG_packed_type"; | |
4533 | case DW_TAG_subprogram: return "DW_TAG_subprogram"; | |
4534 | case DW_TAG_template_type_param: return "DW_TAG_template_type_param"; | |
4535 | case DW_TAG_template_value_param: return "DW_TAG_template_value_param"; | |
4536 | case DW_TAG_thrown_type: return "DW_TAG_thrown_type"; | |
4537 | case DW_TAG_try_block: return "DW_TAG_try_block"; | |
4538 | case DW_TAG_variant_part: return "DW_TAG_variant_part"; | |
4539 | case DW_TAG_variable: return "DW_TAG_variable"; | |
4540 | case DW_TAG_volatile_type: return "DW_TAG_volatile_type"; | |
4541 | case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop"; | |
4542 | case DW_TAG_format_label: return "DW_TAG_format_label"; | |
4543 | case DW_TAG_function_template: return "DW_TAG_function_template"; | |
4544 | case DW_TAG_class_template: return "DW_TAG_class_template"; | |
4545 | default: | |
4546 | { | |
4547 | static char buffer [100]; | |
4548 | ||
4549 | sprintf (buffer, _("Unknown TAG value: %lx"), tag); | |
4550 | return buffer; | |
4551 | } | |
4552 | } | |
4553 | } | |
4554 | ||
4555 | static char * | |
4556 | get_AT_name (attribute) | |
4557 | unsigned long attribute; | |
4558 | { | |
4559 | switch (attribute) | |
4560 | { | |
4561 | case DW_AT_sibling: return "DW_AT_sibling"; | |
4562 | case DW_AT_location: return "DW_AT_location"; | |
4563 | case DW_AT_name: return "DW_AT_name"; | |
4564 | case DW_AT_ordering: return "DW_AT_ordering"; | |
4565 | case DW_AT_subscr_data: return "DW_AT_subscr_data"; | |
4566 | case DW_AT_byte_size: return "DW_AT_byte_size"; | |
4567 | case DW_AT_bit_offset: return "DW_AT_bit_offset"; | |
4568 | case DW_AT_bit_size: return "DW_AT_bit_size"; | |
4569 | case DW_AT_element_list: return "DW_AT_element_list"; | |
4570 | case DW_AT_stmt_list: return "DW_AT_stmt_list"; | |
4571 | case DW_AT_low_pc: return "DW_AT_low_pc"; | |
4572 | case DW_AT_high_pc: return "DW_AT_high_pc"; | |
4573 | case DW_AT_language: return "DW_AT_language"; | |
4574 | case DW_AT_member: return "DW_AT_member"; | |
4575 | case DW_AT_discr: return "DW_AT_discr"; | |
4576 | case DW_AT_discr_value: return "DW_AT_discr_value"; | |
4577 | case DW_AT_visibility: return "DW_AT_visibility"; | |
4578 | case DW_AT_import: return "DW_AT_import"; | |
4579 | case DW_AT_string_length: return "DW_AT_string_length"; | |
4580 | case DW_AT_common_reference: return "DW_AT_common_reference"; | |
4581 | case DW_AT_comp_dir: return "DW_AT_comp_dir"; | |
4582 | case DW_AT_const_value: return "DW_AT_const_value"; | |
4583 | case DW_AT_containing_type: return "DW_AT_containing_type"; | |
4584 | case DW_AT_default_value: return "DW_AT_default_value"; | |
4585 | case DW_AT_inline: return "DW_AT_inline"; | |
4586 | case DW_AT_is_optional: return "DW_AT_is_optional"; | |
4587 | case DW_AT_lower_bound: return "DW_AT_lower_bound"; | |
4588 | case DW_AT_producer: return "DW_AT_producer"; | |
4589 | case DW_AT_prototyped: return "DW_AT_prototyped"; | |
4590 | case DW_AT_return_addr: return "DW_AT_return_addr"; | |
4591 | case DW_AT_start_scope: return "DW_AT_start_scope"; | |
4592 | case DW_AT_stride_size: return "DW_AT_stride_size"; | |
4593 | case DW_AT_upper_bound: return "DW_AT_upper_bound"; | |
4594 | case DW_AT_abstract_origin: return "DW_AT_abstract_origin"; | |
4595 | case DW_AT_accessibility: return "DW_AT_accessibility"; | |
4596 | case DW_AT_address_class: return "DW_AT_address_class"; | |
4597 | case DW_AT_artificial: return "DW_AT_artificial"; | |
4598 | case DW_AT_base_types: return "DW_AT_base_types"; | |
4599 | case DW_AT_calling_convention: return "DW_AT_calling_convention"; | |
4600 | case DW_AT_count: return "DW_AT_count"; | |
4601 | case DW_AT_data_member_location: return "DW_AT_data_member_location"; | |
4602 | case DW_AT_decl_column: return "DW_AT_decl_column"; | |
4603 | case DW_AT_decl_file: return "DW_AT_decl_file"; | |
4604 | case DW_AT_decl_line: return "DW_AT_decl_line"; | |
4605 | case DW_AT_declaration: return "DW_AT_declaration"; | |
4606 | case DW_AT_discr_list: return "DW_AT_discr_list"; | |
4607 | case DW_AT_encoding: return "DW_AT_encoding"; | |
4608 | case DW_AT_external: return "DW_AT_external"; | |
4609 | case DW_AT_frame_base: return "DW_AT_frame_base"; | |
4610 | case DW_AT_friend: return "DW_AT_friend"; | |
4611 | case DW_AT_identifier_case: return "DW_AT_identifier_case"; | |
4612 | case DW_AT_macro_info: return "DW_AT_macro_info"; | |
4613 | case DW_AT_namelist_items: return "DW_AT_namelist_items"; | |
4614 | case DW_AT_priority: return "DW_AT_priority"; | |
4615 | case DW_AT_segment: return "DW_AT_segment"; | |
4616 | case DW_AT_specification: return "DW_AT_specification"; | |
4617 | case DW_AT_static_link: return "DW_AT_static_link"; | |
4618 | case DW_AT_type: return "DW_AT_type"; | |
4619 | case DW_AT_use_location: return "DW_AT_use_location"; | |
4620 | case DW_AT_variable_parameter: return "DW_AT_variable_parameter"; | |
4621 | case DW_AT_virtuality: return "DW_AT_virtuality"; | |
4622 | case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location"; | |
4623 | case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde"; | |
4624 | case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin"; | |
4625 | case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin"; | |
4626 | case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin"; | |
4627 | case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor"; | |
4628 | case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth"; | |
4629 | case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name"; | |
4630 | case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride"; | |
4631 | case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name"; | |
4632 | case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin"; | |
4633 | case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines"; | |
4634 | case DW_AT_sf_names: return "DW_AT_sf_names"; | |
4635 | case DW_AT_src_info: return "DW_AT_src_info"; | |
4636 | case DW_AT_mac_info: return "DW_AT_mac_info"; | |
4637 | case DW_AT_src_coords: return "DW_AT_src_coords"; | |
4638 | case DW_AT_body_begin: return "DW_AT_body_begin"; | |
4639 | case DW_AT_body_end: return "DW_AT_body_end"; | |
4640 | default: | |
4641 | { | |
4642 | static char buffer [100]; | |
4643 | ||
4644 | sprintf (buffer, _("Unknown AT value: %lx"), attribute); | |
4645 | return buffer; | |
4646 | } | |
4647 | } | |
4648 | } | |
4649 | ||
4650 | static char * | |
4651 | get_FORM_name (form) | |
4652 | unsigned long form; | |
4653 | { | |
4654 | switch (form) | |
4655 | { | |
4656 | case DW_FORM_addr: return "DW_FORM_addr"; | |
4657 | case DW_FORM_block2: return "DW_FORM_block2"; | |
4658 | case DW_FORM_block4: return "DW_FORM_block4"; | |
4659 | case DW_FORM_data2: return "DW_FORM_data2"; | |
4660 | case DW_FORM_data4: return "DW_FORM_data4"; | |
4661 | case DW_FORM_data8: return "DW_FORM_data8"; | |
4662 | case DW_FORM_string: return "DW_FORM_string"; | |
4663 | case DW_FORM_block: return "DW_FORM_block"; | |
4664 | case DW_FORM_block1: return "DW_FORM_block1"; | |
4665 | case DW_FORM_data1: return "DW_FORM_data1"; | |
4666 | case DW_FORM_flag: return "DW_FORM_flag"; | |
4667 | case DW_FORM_sdata: return "DW_FORM_sdata"; | |
4668 | case DW_FORM_strp: return "DW_FORM_strp"; | |
4669 | case DW_FORM_udata: return "DW_FORM_udata"; | |
4670 | case DW_FORM_ref_addr: return "DW_FORM_ref_addr"; | |
4671 | case DW_FORM_ref1: return "DW_FORM_ref1"; | |
4672 | case DW_FORM_ref2: return "DW_FORM_ref2"; | |
4673 | case DW_FORM_ref4: return "DW_FORM_ref4"; | |
4674 | case DW_FORM_ref8: return "DW_FORM_ref8"; | |
4675 | case DW_FORM_ref_udata: return "DW_FORM_ref_udata"; | |
4676 | case DW_FORM_indirect: return "DW_FORM_indirect"; | |
4677 | default: | |
4678 | { | |
4679 | static char buffer [100]; | |
4680 | ||
4681 | sprintf (buffer, _("Unknown FORM value: %lx"), form); | |
4682 | return buffer; | |
4683 | } | |
4684 | } | |
4685 | } | |
4686 | ||
4687 | /* FIXME: There are better and more effiecint ways to handle | |
4688 | these structures. For now though, I just want something that | |
4689 | is simple to implement. */ | |
4690 | typedef struct abbrev_attr | |
4691 | { | |
4692 | unsigned long attribute; | |
4693 | unsigned long form; | |
4694 | struct abbrev_attr * next; | |
4695 | } | |
4696 | abbrev_attr; | |
4697 | ||
4698 | typedef struct abbrev_entry | |
4699 | { | |
4700 | unsigned long entry; | |
4701 | unsigned long tag; | |
4702 | int children; | |
4703 | struct abbrev_attr * first_attr; | |
4704 | struct abbrev_attr * last_attr; | |
4705 | struct abbrev_entry * next; | |
4706 | } | |
4707 | abbrev_entry; | |
4708 | ||
4709 | static abbrev_entry * first_abbrev = NULL; | |
4710 | static abbrev_entry * last_abbrev = NULL; | |
4711 | ||
4712 | static void | |
4713 | free_abbrevs PARAMS ((void)) | |
4714 | { | |
4715 | abbrev_entry * abbrev; | |
4716 | ||
4717 | for (abbrev = first_abbrev; abbrev;) | |
4718 | { | |
4719 | abbrev_entry * next = abbrev->next; | |
4720 | abbrev_attr * attr; | |
4721 | ||
4722 | for (attr = abbrev->first_attr; attr;) | |
4723 | { | |
4724 | abbrev_attr * next = attr->next; | |
4725 | ||
4726 | free (attr); | |
4727 | attr = next; | |
4728 | } | |
4729 | ||
4730 | free (abbrev); | |
4731 | abbrev = next; | |
4732 | } | |
4733 | ||
4734 | last_abbrev = first_abbrev = NULL; | |
4735 | } | |
4736 | ||
4737 | static void | |
4738 | add_abbrev (number, tag, children) | |
4739 | unsigned long number; | |
4740 | unsigned long tag; | |
4741 | int children; | |
4742 | { | |
4743 | abbrev_entry * entry; | |
4744 | ||
4745 | entry = (abbrev_entry *) malloc (sizeof (* entry)); | |
4746 | ||
4747 | if (entry == NULL) | |
4748 | /* ugg */ | |
4749 | return; | |
4750 | ||
4751 | entry->entry = number; | |
4752 | entry->tag = tag; | |
4753 | entry->children = children; | |
4754 | entry->first_attr = NULL; | |
4755 | entry->last_attr = NULL; | |
4756 | entry->next = NULL; | |
4757 | ||
4758 | if (first_abbrev == NULL) | |
4759 | first_abbrev = entry; | |
4760 | else | |
4761 | last_abbrev->next = entry; | |
4762 | ||
4763 | last_abbrev = entry; | |
4764 | } | |
4765 | ||
4766 | static void | |
4767 | add_abbrev_attr (attribute, form) | |
4768 | unsigned long attribute; | |
4769 | unsigned long form; | |
4770 | { | |
4771 | abbrev_attr * attr; | |
4772 | ||
4773 | attr = (abbrev_attr *) malloc (sizeof (* attr)); | |
4774 | ||
4775 | if (attr == NULL) | |
4776 | /* ugg */ | |
4777 | return; | |
4778 | ||
4779 | attr->attribute = attribute; | |
4780 | attr->form = form; | |
4781 | attr->next = NULL; | |
4782 | ||
4783 | if (last_abbrev->first_attr == NULL) | |
4784 | last_abbrev->first_attr = attr; | |
4785 | else | |
4786 | last_abbrev->last_attr->next = attr; | |
4787 | ||
4788 | last_abbrev->last_attr = attr; | |
4789 | } | |
4790 | ||
4791 | /* Processes the (partial) contents of a .debug_abbrev section. | |
4792 | Returns NULL if the end of the section was encountered. | |
4793 | Returns the address after the last byte read if the end of | |
4794 | an abbreviation set was found. */ | |
4795 | ||
4796 | static unsigned char * | |
4797 | process_abbrev_section (start, end) | |
4798 | unsigned char * start; | |
4799 | unsigned char * end; | |
4800 | { | |
4801 | if (first_abbrev != NULL) | |
4802 | return NULL; | |
4803 | ||
4804 | while (start < end) | |
4805 | { | |
4806 | int bytes_read; | |
4807 | unsigned long entry; | |
4808 | unsigned long tag; | |
4809 | unsigned long attribute; | |
4810 | int children; | |
4811 | ||
4812 | entry = read_leb128 (start, & bytes_read, 0); | |
4813 | start += bytes_read; | |
4814 | ||
a3f779db NC |
4815 | /* A single zero is supposed to end the section according |
4816 | to the standard. If there's more, then signal that to | |
4817 | the caller. */ | |
252b5132 | 4818 | if (entry == 0) |
a3f779db | 4819 | return start == end ? NULL : start; |
252b5132 RH |
4820 | |
4821 | tag = read_leb128 (start, & bytes_read, 0); | |
4822 | start += bytes_read; | |
4823 | ||
4824 | children = * start ++; | |
4825 | ||
4826 | add_abbrev (entry, tag, children); | |
4827 | ||
4828 | do | |
4829 | { | |
4830 | unsigned long form; | |
4831 | ||
4832 | attribute = read_leb128 (start, & bytes_read, 0); | |
4833 | start += bytes_read; | |
4834 | ||
4835 | form = read_leb128 (start, & bytes_read, 0); | |
4836 | start += bytes_read; | |
4837 | ||
4838 | if (attribute != 0) | |
4839 | add_abbrev_attr (attribute, form); | |
4840 | } | |
4841 | while (attribute != 0); | |
4842 | } | |
4843 | ||
4844 | return NULL; | |
4845 | } | |
4846 | ||
4847 | ||
4848 | static int | |
4849 | display_debug_abbrev (section, start, file) | |
4850 | Elf32_Internal_Shdr * section; | |
4851 | unsigned char * start; | |
b4c96d0d | 4852 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 RH |
4853 | { |
4854 | abbrev_entry * entry; | |
4855 | unsigned char * end = start + section->sh_size; | |
4856 | ||
4857 | printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); | |
4858 | ||
4859 | do | |
4860 | { | |
4861 | start = process_abbrev_section (start, end); | |
4862 | ||
4863 | printf (_(" Number TAG\n")); | |
4864 | ||
4865 | for (entry = first_abbrev; entry; entry = entry->next) | |
4866 | { | |
4867 | abbrev_attr * attr; | |
4868 | ||
4869 | printf (_(" %ld %s [%s]\n"), | |
4870 | entry->entry, | |
4871 | get_TAG_name (entry->tag), | |
4872 | entry->children ? _("has children") : _("no children")); | |
4873 | ||
4874 | for (attr = entry->first_attr; attr; attr = attr->next) | |
4875 | { | |
4876 | printf (_(" %-18s %s\n"), | |
4877 | get_AT_name (attr->attribute), | |
4878 | get_FORM_name (attr->form)); | |
4879 | } | |
4880 | } | |
4881 | } | |
4882 | while (start); | |
4883 | ||
4884 | printf ("\n"); | |
4885 | ||
4886 | return 1; | |
4887 | } | |
4888 | ||
4889 | ||
4890 | static unsigned char * | |
4891 | display_block (data, length) | |
4892 | unsigned char * data; | |
4893 | unsigned long length; | |
4894 | { | |
4895 | printf (_(" %lu byte block: "), length); | |
4896 | ||
4897 | while (length --) | |
148d3c43 | 4898 | printf ("%lx ", (unsigned long) byte_get (data ++, 1)); |
252b5132 RH |
4899 | |
4900 | return data; | |
4901 | } | |
4902 | ||
4903 | static void | |
4904 | decode_location_expression (data, pointer_size) | |
4905 | unsigned char * data; | |
4906 | unsigned int pointer_size; | |
4907 | { | |
4908 | unsigned char op; | |
4909 | int bytes_read; | |
148d3c43 | 4910 | unsigned long uvalue; |
252b5132 RH |
4911 | |
4912 | op = * data ++; | |
4913 | ||
4914 | switch (op) | |
4915 | { | |
148d3c43 AS |
4916 | case DW_OP_addr: |
4917 | printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data, pointer_size)); | |
4918 | break; | |
4919 | case DW_OP_deref: | |
4920 | printf ("DW_OP_deref"); | |
4921 | break; | |
4922 | case DW_OP_const1u: | |
4923 | printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data, 1)); | |
4924 | break; | |
4925 | case DW_OP_const1s: | |
4926 | printf ("DW_OP_const1s: %ld", (long) byte_get (data, 1)); | |
4927 | break; | |
4928 | case DW_OP_const2u: | |
4929 | printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2)); | |
4930 | break; | |
4931 | case DW_OP_const2s: | |
4932 | printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2)); | |
4933 | break; | |
4934 | case DW_OP_const4u: | |
4935 | printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4)); | |
4936 | break; | |
4937 | case DW_OP_const4s: | |
4938 | printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4)); | |
4939 | break; | |
4940 | case DW_OP_const8u: | |
4941 | printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4), | |
4942 | (unsigned long) byte_get (data + 4, 4)); | |
4943 | break; | |
4944 | case DW_OP_const8s: | |
4945 | printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4), | |
4946 | (long) byte_get (data + 4, 4)); | |
4947 | break; | |
4948 | case DW_OP_constu: | |
4949 | printf ("DW_OP_constu: %lu", read_leb128 (data, NULL, 0)); | |
4950 | break; | |
4951 | case DW_OP_consts: | |
4952 | printf ("DW_OP_consts: %ld", read_leb128 (data, NULL, 1)); | |
4953 | break; | |
4954 | case DW_OP_dup: | |
4955 | printf ("DW_OP_dup"); | |
4956 | break; | |
4957 | case DW_OP_drop: | |
4958 | printf ("DW_OP_drop"); | |
4959 | break; | |
4960 | case DW_OP_over: | |
4961 | printf ("DW_OP_over"); | |
4962 | break; | |
4963 | case DW_OP_pick: | |
4964 | printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data, 1)); | |
4965 | break; | |
4966 | case DW_OP_swap: | |
4967 | printf ("DW_OP_swap"); | |
4968 | break; | |
4969 | case DW_OP_rot: | |
4970 | printf ("DW_OP_rot"); | |
4971 | break; | |
4972 | case DW_OP_xderef: | |
4973 | printf ("DW_OP_xderef"); | |
4974 | break; | |
4975 | case DW_OP_abs: | |
4976 | printf ("DW_OP_abs"); | |
4977 | break; | |
4978 | case DW_OP_and: | |
4979 | printf ("DW_OP_and"); | |
4980 | break; | |
4981 | case DW_OP_div: | |
4982 | printf ("DW_OP_div"); | |
4983 | break; | |
4984 | case DW_OP_minus: | |
4985 | printf ("DW_OP_minus"); | |
4986 | break; | |
4987 | case DW_OP_mod: | |
4988 | printf ("DW_OP_mod"); | |
4989 | break; | |
4990 | case DW_OP_mul: | |
4991 | printf ("DW_OP_mul"); | |
4992 | break; | |
4993 | case DW_OP_neg: | |
4994 | printf ("DW_OP_neg"); | |
4995 | break; | |
4996 | case DW_OP_not: | |
4997 | printf ("DW_OP_not"); | |
4998 | break; | |
4999 | case DW_OP_or: | |
5000 | printf ("DW_OP_or"); | |
5001 | break; | |
5002 | case DW_OP_plus: | |
5003 | printf ("DW_OP_plus"); | |
5004 | break; | |
5005 | case DW_OP_plus_uconst: | |
5006 | printf ("DW_OP_plus_uconst: %lu", read_leb128 (data, NULL, 0)); | |
5007 | break; | |
5008 | case DW_OP_shl: | |
5009 | printf ("DW_OP_shl"); | |
5010 | break; | |
5011 | case DW_OP_shr: | |
5012 | printf ("DW_OP_shr"); | |
5013 | break; | |
5014 | case DW_OP_shra: | |
5015 | printf ("DW_OP_shra"); | |
5016 | break; | |
5017 | case DW_OP_xor: | |
5018 | printf ("DW_OP_xor"); | |
5019 | break; | |
5020 | case DW_OP_bra: | |
789be9f7 | 5021 | printf ("DW_OP_bra: %ld", (long) byte_get (data, 2)); |
148d3c43 AS |
5022 | break; |
5023 | case DW_OP_eq: | |
5024 | printf ("DW_OP_eq"); | |
5025 | break; | |
5026 | case DW_OP_ge: | |
5027 | printf ("DW_OP_ge"); | |
5028 | break; | |
5029 | case DW_OP_gt: | |
5030 | printf ("DW_OP_gt"); | |
5031 | break; | |
5032 | case DW_OP_le: | |
5033 | printf ("DW_OP_le"); | |
5034 | break; | |
5035 | case DW_OP_lt: | |
5036 | printf ("DW_OP_lt"); | |
5037 | break; | |
5038 | case DW_OP_ne: | |
5039 | printf ("DW_OP_ne"); | |
5040 | break; | |
5041 | case DW_OP_skip: | |
5042 | printf ("DW_OP_skip: %ld", (long) byte_get (data, 2)); | |
5043 | break; | |
5044 | case DW_OP_lit0: | |
5045 | printf ("DW_OP_lit0"); | |
5046 | break; | |
5047 | case DW_OP_lit1: | |
5048 | printf ("DW_OP_lit1"); | |
5049 | break; | |
5050 | case DW_OP_lit2: | |
5051 | printf ("DW_OP_lit2"); | |
5052 | break; | |
5053 | case DW_OP_lit3: | |
5054 | printf ("DW_OP_lit3"); | |
5055 | break; | |
5056 | case DW_OP_lit4: | |
5057 | printf ("DW_OP_lit4"); | |
5058 | break; | |
5059 | case DW_OP_lit5: | |
5060 | printf ("DW_OP_lit5"); | |
5061 | break; | |
5062 | case DW_OP_lit6: | |
5063 | printf ("DW_OP_lit6"); | |
5064 | break; | |
5065 | case DW_OP_lit7: | |
5066 | printf ("DW_OP_lit7"); | |
5067 | break; | |
5068 | case DW_OP_lit8: | |
5069 | printf ("DW_OP_lit8"); | |
5070 | break; | |
5071 | case DW_OP_lit9: | |
5072 | printf ("DW_OP_lit9"); | |
5073 | break; | |
5074 | case DW_OP_lit10: | |
5075 | printf ("DW_OP_lit10"); | |
5076 | break; | |
5077 | case DW_OP_lit11: | |
5078 | printf ("DW_OP_lit11"); | |
5079 | break; | |
5080 | case DW_OP_lit12: | |
5081 | printf ("DW_OP_lit12"); | |
5082 | break; | |
5083 | case DW_OP_lit13: | |
5084 | printf ("DW_OP_lit13"); | |
5085 | break; | |
5086 | case DW_OP_lit14: | |
5087 | printf ("DW_OP_lit14"); | |
5088 | break; | |
5089 | case DW_OP_lit15: | |
5090 | printf ("DW_OP_lit15"); | |
5091 | break; | |
5092 | case DW_OP_lit16: | |
5093 | printf ("DW_OP_lit16"); | |
5094 | break; | |
5095 | case DW_OP_lit17: | |
5096 | printf ("DW_OP_lit17"); | |
5097 | break; | |
5098 | case DW_OP_lit18: | |
5099 | printf ("DW_OP_lit18"); | |
5100 | break; | |
5101 | case DW_OP_lit19: | |
5102 | printf ("DW_OP_lit19"); | |
5103 | break; | |
5104 | case DW_OP_lit20: | |
5105 | printf ("DW_OP_lit20"); | |
5106 | break; | |
5107 | case DW_OP_lit21: | |
5108 | printf ("DW_OP_lit21"); | |
5109 | break; | |
5110 | case DW_OP_lit22: | |
5111 | printf ("DW_OP_lit22"); | |
5112 | break; | |
5113 | case DW_OP_lit23: | |
5114 | printf ("DW_OP_lit23"); | |
5115 | break; | |
5116 | case DW_OP_lit24: | |
5117 | printf ("DW_OP_lit24"); | |
5118 | break; | |
5119 | case DW_OP_lit25: | |
5120 | printf ("DW_OP_lit25"); | |
5121 | break; | |
5122 | case DW_OP_lit26: | |
5123 | printf ("DW_OP_lit26"); | |
5124 | break; | |
5125 | case DW_OP_lit27: | |
5126 | printf ("DW_OP_lit27"); | |
5127 | break; | |
5128 | case DW_OP_lit28: | |
5129 | printf ("DW_OP_lit28"); | |
5130 | break; | |
5131 | case DW_OP_lit29: | |
5132 | printf ("DW_OP_lit29"); | |
5133 | break; | |
5134 | case DW_OP_lit30: | |
5135 | printf ("DW_OP_lit30"); | |
5136 | break; | |
5137 | case DW_OP_lit31: | |
5138 | printf ("DW_OP_lit31"); | |
5139 | break; | |
5140 | case DW_OP_reg0: | |
5141 | printf ("DW_OP_reg0"); | |
5142 | break; | |
5143 | case DW_OP_reg1: | |
5144 | printf ("DW_OP_reg1"); | |
5145 | break; | |
5146 | case DW_OP_reg2: | |
5147 | printf ("DW_OP_reg2"); | |
5148 | break; | |
5149 | case DW_OP_reg3: | |
5150 | printf ("DW_OP_reg3"); | |
5151 | break; | |
5152 | case DW_OP_reg4: | |
5153 | printf ("DW_OP_reg4"); | |
5154 | break; | |
5155 | case DW_OP_reg5: | |
5156 | printf ("DW_OP_reg5"); | |
5157 | break; | |
5158 | case DW_OP_reg6: | |
5159 | printf ("DW_OP_reg6"); | |
5160 | break; | |
5161 | case DW_OP_reg7: | |
5162 | printf ("DW_OP_reg7"); | |
5163 | break; | |
5164 | case DW_OP_reg8: | |
5165 | printf ("DW_OP_reg8"); | |
5166 | break; | |
5167 | case DW_OP_reg9: | |
5168 | printf ("DW_OP_reg9"); | |
5169 | break; | |
5170 | case DW_OP_reg10: | |
5171 | printf ("DW_OP_reg10"); | |
5172 | break; | |
5173 | case DW_OP_reg11: | |
5174 | printf ("DW_OP_reg11"); | |
5175 | break; | |
5176 | case DW_OP_reg12: | |
5177 | printf ("DW_OP_reg12"); | |
5178 | break; | |
5179 | case DW_OP_reg13: | |
5180 | printf ("DW_OP_reg13"); | |
5181 | break; | |
5182 | case DW_OP_reg14: | |
5183 | printf ("DW_OP_reg14"); | |
5184 | break; | |
5185 | case DW_OP_reg15: | |
5186 | printf ("DW_OP_reg15"); | |
5187 | break; | |
5188 | case DW_OP_reg16: | |
5189 | printf ("DW_OP_reg16"); | |
5190 | break; | |
5191 | case DW_OP_reg17: | |
5192 | printf ("DW_OP_reg17"); | |
5193 | break; | |
5194 | case DW_OP_reg18: | |
5195 | printf ("DW_OP_reg18"); | |
5196 | break; | |
5197 | case DW_OP_reg19: | |
5198 | printf ("DW_OP_reg19"); | |
5199 | break; | |
5200 | case DW_OP_reg20: | |
5201 | printf ("DW_OP_reg20"); | |
5202 | break; | |
5203 | case DW_OP_reg21: | |
5204 | printf ("DW_OP_reg21"); | |
5205 | break; | |
5206 | case DW_OP_reg22: | |
5207 | printf ("DW_OP_reg22"); | |
5208 | break; | |
5209 | case DW_OP_reg23: | |
5210 | printf ("DW_OP_reg23"); | |
5211 | break; | |
5212 | case DW_OP_reg24: | |
5213 | printf ("DW_OP_reg24"); | |
5214 | break; | |
5215 | case DW_OP_reg25: | |
5216 | printf ("DW_OP_reg25"); | |
5217 | break; | |
5218 | case DW_OP_reg26: | |
5219 | printf ("DW_OP_reg26"); | |
5220 | break; | |
5221 | case DW_OP_reg27: | |
5222 | printf ("DW_OP_reg27"); | |
5223 | break; | |
5224 | case DW_OP_reg28: | |
5225 | printf ("DW_OP_reg28"); | |
5226 | break; | |
5227 | case DW_OP_reg29: | |
5228 | printf ("DW_OP_reg29"); | |
5229 | break; | |
5230 | case DW_OP_reg30: | |
5231 | printf ("DW_OP_reg30"); | |
5232 | break; | |
5233 | case DW_OP_reg31: | |
5234 | printf ("DW_OP_reg31"); | |
5235 | break; | |
5236 | case DW_OP_breg0: | |
5237 | printf ("DW_OP_breg0: %ld", read_leb128 (data, NULL, 1)); | |
5238 | break; | |
5239 | case DW_OP_breg1: | |
5240 | printf ("DW_OP_breg1: %ld", read_leb128 (data, NULL, 1)); | |
5241 | break; | |
5242 | case DW_OP_breg2: | |
5243 | printf ("DW_OP_breg2: %ld", read_leb128 (data, NULL, 1)); | |
5244 | break; | |
5245 | case DW_OP_breg3: | |
5246 | printf ("DW_OP_breg3: %ld", read_leb128 (data, NULL, 1)); | |
5247 | break; | |
5248 | case DW_OP_breg4: | |
5249 | printf ("DW_OP_breg4: %ld", read_leb128 (data, NULL, 1)); | |
5250 | break; | |
5251 | case DW_OP_breg5: | |
5252 | printf ("DW_OP_breg5: %ld", read_leb128 (data, NULL, 1)); | |
5253 | break; | |
5254 | case DW_OP_breg6: | |
5255 | printf ("DW_OP_breg6: %ld", read_leb128 (data, NULL, 1)); | |
5256 | break; | |
5257 | case DW_OP_breg7: | |
5258 | printf ("DW_OP_breg7: %ld", read_leb128 (data, NULL, 1)); | |
5259 | break; | |
5260 | case DW_OP_breg8: | |
5261 | printf ("DW_OP_breg8: %ld", read_leb128 (data, NULL, 1)); | |
5262 | break; | |
5263 | case DW_OP_breg9: | |
5264 | printf ("DW_OP_breg9: %ld", read_leb128 (data, NULL, 1)); | |
5265 | break; | |
5266 | case DW_OP_breg10: | |
5267 | printf ("DW_OP_breg10: %ld", read_leb128 (data, NULL, 1)); | |
5268 | break; | |
5269 | case DW_OP_breg11: | |
5270 | printf ("DW_OP_breg11: %ld", read_leb128 (data, NULL, 1)); | |
5271 | break; | |
5272 | case DW_OP_breg12: | |
5273 | printf ("DW_OP_breg12: %ld", read_leb128 (data, NULL, 1)); | |
5274 | break; | |
5275 | case DW_OP_breg13: | |
5276 | printf ("DW_OP_breg13: %ld", read_leb128 (data, NULL, 1)); | |
5277 | break; | |
5278 | case DW_OP_breg14: | |
5279 | printf ("DW_OP_breg14: %ld", read_leb128 (data, NULL, 1)); | |
5280 | break; | |
5281 | case DW_OP_breg15: | |
5282 | printf ("DW_OP_breg15: %ld", read_leb128 (data, NULL, 1)); | |
5283 | break; | |
5284 | case DW_OP_breg16: | |
5285 | printf ("DW_OP_breg16: %ld", read_leb128 (data, NULL, 1)); | |
5286 | break; | |
5287 | case DW_OP_breg17: | |
5288 | printf ("DW_OP_breg17: %ld", read_leb128 (data, NULL, 1)); | |
5289 | break; | |
5290 | case DW_OP_breg18: | |
5291 | printf ("DW_OP_breg18: %ld", read_leb128 (data, NULL, 1)); | |
5292 | break; | |
5293 | case DW_OP_breg19: | |
5294 | printf ("DW_OP_breg19: %ld", read_leb128 (data, NULL, 1)); | |
5295 | break; | |
5296 | case DW_OP_breg20: | |
5297 | printf ("DW_OP_breg20: %ld", read_leb128 (data, NULL, 1)); | |
5298 | break; | |
5299 | case DW_OP_breg21: | |
5300 | printf ("DW_OP_breg21: %ld", read_leb128 (data, NULL, 1)); | |
5301 | break; | |
5302 | case DW_OP_breg22: | |
5303 | printf ("DW_OP_breg22: %ld", read_leb128 (data, NULL, 1)); | |
5304 | break; | |
5305 | case DW_OP_breg23: | |
5306 | printf ("DW_OP_breg23: %ld", read_leb128 (data, NULL, 1)); | |
5307 | break; | |
5308 | case DW_OP_breg24: | |
5309 | printf ("DW_OP_breg24: %ld", read_leb128 (data, NULL, 1)); | |
5310 | break; | |
5311 | case DW_OP_breg25: | |
5312 | printf ("DW_OP_breg25: %ld", read_leb128 (data, NULL, 1)); | |
5313 | break; | |
5314 | case DW_OP_breg26: | |
5315 | printf ("DW_OP_breg26: %ld", read_leb128 (data, NULL, 1)); | |
5316 | break; | |
5317 | case DW_OP_breg27: | |
5318 | printf ("DW_OP_breg27: %ld", read_leb128 (data, NULL, 1)); | |
5319 | break; | |
5320 | case DW_OP_breg28: | |
5321 | printf ("DW_OP_breg28: %ld", read_leb128 (data, NULL, 1)); | |
5322 | break; | |
5323 | case DW_OP_breg29: | |
5324 | printf ("DW_OP_breg29: %ld", read_leb128 (data, NULL, 1)); | |
5325 | break; | |
5326 | case DW_OP_breg30: | |
5327 | printf ("DW_OP_breg30: %ld", read_leb128 (data, NULL, 1)); | |
5328 | break; | |
5329 | case DW_OP_breg31: | |
5330 | printf ("DW_OP_breg31: %ld", read_leb128 (data, NULL, 1)); | |
5331 | break; | |
5332 | case DW_OP_regx: | |
5333 | printf ("DW_OP_regx: %lu", read_leb128 (data, NULL, 0)); | |
5334 | break; | |
5335 | case DW_OP_fbreg: | |
5336 | printf ("DW_OP_fbreg: %ld", read_leb128 (data, NULL, 1)); | |
5337 | break; | |
5338 | case DW_OP_bregx: | |
5339 | uvalue = read_leb128 (data, &bytes_read, 0); | |
5340 | printf ("DW_OP_bregx: %lu %ld", uvalue, | |
5341 | read_leb128 (data + bytes_read, NULL, 1)); | |
5342 | break; | |
5343 | case DW_OP_piece: | |
5344 | printf ("DW_OP_piece: %lu", read_leb128 (data, NULL, 0)); | |
5345 | break; | |
5346 | case DW_OP_deref_size: | |
5347 | printf ("DW_OP_deref_size: %ld", (long) byte_get (data, 1)); | |
5348 | break; | |
5349 | case DW_OP_xderef_size: | |
5350 | printf ("DW_OP_xderef_size: %ld", (long) byte_get (data, 1)); | |
5351 | break; | |
5352 | case DW_OP_nop: | |
5353 | printf ("DW_OP_nop"); | |
5354 | break; | |
252b5132 RH |
5355 | |
5356 | default: | |
5357 | if (op >= DW_OP_lo_user | |
5358 | && op <= DW_OP_hi_user) | |
5359 | printf (_("(User defined location op)")); | |
5360 | else | |
5361 | printf (_("(Unknown location op)")); | |
5362 | break; | |
5363 | } | |
5364 | } | |
5365 | ||
5366 | ||
5367 | static unsigned char * | |
5368 | read_and_display_attr (attribute, form, data, pointer_size) | |
5369 | unsigned long attribute; | |
5370 | unsigned long form; | |
5371 | unsigned char * data; | |
5372 | unsigned long pointer_size; | |
5373 | { | |
b4c96d0d ILT |
5374 | unsigned long uvalue = 0; |
5375 | unsigned char * block_start = NULL; | |
252b5132 RH |
5376 | int bytes_read; |
5377 | int is_ref = 0; | |
5378 | ||
5379 | printf (" %-18s:", get_AT_name (attribute)); | |
5380 | ||
5381 | switch (form) | |
5382 | { | |
5383 | case DW_FORM_ref_addr: | |
5384 | case DW_FORM_ref1: | |
5385 | case DW_FORM_ref2: | |
5386 | case DW_FORM_ref4: | |
5387 | case DW_FORM_ref8: | |
5388 | case DW_FORM_ref_udata: | |
5389 | is_ref = 1; | |
5390 | } | |
5391 | ||
5392 | switch (form) | |
5393 | { | |
5394 | case DW_FORM_ref_addr: | |
5395 | case DW_FORM_addr: | |
5396 | uvalue = byte_get (data, pointer_size); | |
5397 | printf (is_ref ? " <%x>" : " %#x", uvalue); | |
5398 | data += pointer_size; | |
5399 | break; | |
5400 | ||
5401 | case DW_FORM_ref1: | |
5402 | case DW_FORM_flag: | |
5403 | case DW_FORM_data1: | |
5404 | uvalue = byte_get (data ++, 1); | |
5405 | printf (is_ref ? " <%x>" : " %d", uvalue); | |
5406 | break; | |
5407 | ||
5408 | case DW_FORM_ref2: | |
5409 | case DW_FORM_data2: | |
5410 | uvalue = byte_get (data, 2); | |
5411 | data += 2; | |
5412 | printf (is_ref ? " <%x>" : " %d", uvalue); | |
5413 | break; | |
5414 | ||
5415 | case DW_FORM_ref4: | |
5416 | case DW_FORM_data4: | |
5417 | uvalue = byte_get (data, 4); | |
5418 | data += 4; | |
5419 | printf (is_ref ? " <%x>" : " %d", uvalue); | |
5420 | break; | |
5421 | ||
5422 | case DW_FORM_ref8: | |
5423 | case DW_FORM_data8: | |
5424 | uvalue = byte_get (data, 4); | |
5425 | printf (" %lx", uvalue); | |
148d3c43 | 5426 | printf (" %lx", (unsigned long) byte_get (data + 4, 4)); |
252b5132 RH |
5427 | data += 8; |
5428 | break; | |
5429 | ||
5430 | case DW_FORM_string: | |
5431 | printf (" %s", data); | |
5432 | data += strlen (data) + 1; | |
5433 | break; | |
5434 | ||
5435 | case DW_FORM_sdata: | |
5436 | uvalue = read_leb128 (data, & bytes_read, 1); | |
5437 | data += bytes_read; | |
5438 | printf (" %ld", (long) uvalue); | |
5439 | break; | |
5440 | ||
5441 | case DW_FORM_ref_udata: | |
5442 | case DW_FORM_udata: | |
5443 | uvalue = read_leb128 (data, & bytes_read, 0); | |
5444 | data += bytes_read; | |
5445 | printf (is_ref ? " <%lx>" : " %ld", uvalue); | |
5446 | break; | |
5447 | ||
5448 | case DW_FORM_block: | |
5449 | uvalue = read_leb128 (data, & bytes_read, 0); | |
5450 | block_start = data + bytes_read; | |
5451 | data = display_block (block_start, uvalue); | |
5452 | uvalue = * block_start; | |
5453 | break; | |
5454 | ||
5455 | case DW_FORM_block1: | |
5456 | uvalue = byte_get (data, 1); | |
5457 | block_start = data + 1; | |
5458 | data = display_block (block_start, uvalue); | |
5459 | uvalue = * block_start; | |
5460 | break; | |
5461 | ||
5462 | case DW_FORM_block2: | |
5463 | uvalue = byte_get (data, 2); | |
5464 | block_start = data + 2; | |
5465 | data = display_block (block_start, uvalue); | |
5466 | uvalue = * block_start; | |
5467 | break; | |
5468 | ||
5469 | case DW_FORM_block4: | |
5470 | uvalue = byte_get (data, 4); | |
5471 | block_start = data + 4; | |
5472 | data = display_block (block_start, uvalue); | |
5473 | uvalue = * block_start; | |
5474 | break; | |
5475 | ||
5476 | case DW_FORM_strp: | |
5477 | case DW_FORM_indirect: | |
5478 | warn (_("Unable to handle FORM: %d"), form); | |
5479 | break; | |
5480 | ||
5481 | default: | |
5482 | warn (_("Unrecognised form: %d"), form); | |
5483 | break; | |
5484 | } | |
5485 | ||
5486 | /* For some attributes we can display futher information. */ | |
5487 | ||
5488 | printf ("\t"); | |
5489 | ||
5490 | switch (attribute) | |
5491 | { | |
5492 | case DW_AT_inline: | |
5493 | switch (uvalue) | |
5494 | { | |
5495 | case DW_INL_not_inlined: printf (_("(not inlined)")); break; | |
5496 | case DW_INL_inlined: printf (_("(inlined)")); break; | |
5497 | case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break; | |
5498 | case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break; | |
5499 | default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break; | |
5500 | } | |
5501 | break; | |
5502 | ||
5503 | case DW_AT_frame_base: | |
5504 | if (uvalue >= DW_OP_reg0 && uvalue <= DW_OP_reg31) | |
5505 | printf ("(reg %ld)", uvalue - DW_OP_reg0); | |
5506 | break; | |
5507 | ||
5508 | case DW_AT_language: | |
5509 | switch (uvalue) | |
5510 | { | |
5511 | case DW_LANG_C: printf ("(non-ANSI C)"); break; | |
5512 | case DW_LANG_C89: printf ("(ANSI C)"); break; | |
5513 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; | |
5514 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; | |
5515 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
5516 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; | |
5517 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; | |
5518 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
5519 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; | |
5520 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
5521 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
5522 | default: printf ("(Unknown: %lx)", uvalue); break; | |
5523 | } | |
5524 | break; | |
5525 | ||
5526 | case DW_AT_encoding: | |
5527 | switch (uvalue) | |
5528 | { | |
5529 | case DW_ATE_void: printf ("(void)"); break; | |
5530 | case DW_ATE_address: printf ("(machine address)"); break; | |
5531 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
5532 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
5533 | case DW_ATE_float: printf ("(float)"); break; | |
5534 | case DW_ATE_signed: printf ("(signed)"); break; | |
5535 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
5536 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
5537 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
5538 | default: | |
5539 | if (uvalue >= DW_ATE_lo_user | |
5540 | && uvalue <= DW_ATE_hi_user) | |
5541 | printf ("(user defined type)"); | |
5542 | else | |
5543 | printf ("(unknown type)"); | |
5544 | break; | |
5545 | } | |
5546 | break; | |
5547 | ||
5548 | case DW_AT_accessibility: | |
5549 | switch (uvalue) | |
5550 | { | |
5551 | case DW_ACCESS_public: printf ("(public)"); break; | |
5552 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
5553 | case DW_ACCESS_private: printf ("(private)"); break; | |
5554 | default: printf ("(unknown accessibility)"); break; | |
5555 | } | |
5556 | break; | |
5557 | ||
5558 | case DW_AT_visibility: | |
5559 | switch (uvalue) | |
5560 | { | |
5561 | case DW_VIS_local: printf ("(local)"); break; | |
5562 | case DW_VIS_exported: printf ("(exported)"); break; | |
5563 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
5564 | default: printf ("(unknown visibility)"); break; | |
5565 | } | |
5566 | break; | |
5567 | ||
5568 | case DW_AT_virtuality: | |
5569 | switch (uvalue) | |
5570 | { | |
5571 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
5572 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
5573 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
5574 | default: printf ("(unknown virtuality)"); break; | |
5575 | } | |
5576 | break; | |
5577 | ||
5578 | case DW_AT_identifier_case: | |
5579 | switch (uvalue) | |
5580 | { | |
5581 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
5582 | case DW_ID_up_case: printf ("(up_case)"); break; | |
5583 | case DW_ID_down_case: printf ("(down_case)"); break; | |
5584 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
5585 | default: printf ("(unknown case)"); break; | |
5586 | } | |
5587 | break; | |
5588 | ||
5589 | case DW_AT_calling_convention: | |
5590 | switch (uvalue) | |
5591 | { | |
5592 | case DW_CC_normal: printf ("(normal)"); break; | |
5593 | case DW_CC_program: printf ("(program)"); break; | |
5594 | case DW_CC_nocall: printf ("(nocall)"); break; | |
5595 | default: | |
5596 | if (uvalue >= DW_CC_lo_user | |
5597 | && uvalue <= DW_CC_hi_user) | |
5598 | printf ("(user defined)"); | |
5599 | else | |
5600 | printf ("(unknown convention)"); | |
5601 | } | |
5602 | break; | |
5603 | ||
5604 | case DW_AT_location: | |
5605 | case DW_AT_data_member_location: | |
5606 | case DW_AT_vtable_elem_location: | |
5607 | printf ("("); | |
5608 | decode_location_expression (block_start, pointer_size); | |
5609 | printf (")"); | |
5610 | break; | |
5611 | ||
5612 | default: | |
5613 | break; | |
5614 | } | |
5615 | ||
5616 | printf ("\n"); | |
5617 | return data; | |
5618 | } | |
5619 | ||
5620 | static int | |
5621 | display_debug_info (section, start, file) | |
5622 | Elf32_Internal_Shdr * section; | |
5623 | unsigned char * start; | |
5624 | FILE * file; | |
5625 | { | |
5626 | unsigned char * end = start + section->sh_size; | |
5627 | unsigned char * section_begin = start; | |
5628 | ||
5629 | printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); | |
5630 | ||
5631 | while (start < end) | |
5632 | { | |
5633 | DWARF2_External_CompUnit * external; | |
5634 | DWARF2_Internal_CompUnit compunit; | |
5635 | unsigned char * tags; | |
5636 | int i; | |
5637 | int level; | |
5638 | ||
5639 | external = (DWARF2_External_CompUnit *) start; | |
5640 | ||
5641 | compunit.cu_length = BYTE_GET (external->cu_length); | |
5642 | compunit.cu_version = BYTE_GET (external->cu_version); | |
5643 | compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset); | |
5644 | compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size); | |
5645 | ||
5646 | tags = start + sizeof (* external); | |
5647 | start += compunit.cu_length + sizeof (external->cu_length); | |
5648 | ||
5649 | if (compunit.cu_version != 2) | |
5650 | { | |
5651 | warn (_("Only version 2 DWARF debug information is currently supported.\n")); | |
5652 | continue; | |
5653 | } | |
5654 | ||
5655 | printf (_(" Compilation Unit:\n")); | |
5656 | printf (_(" Length: %ld\n"), compunit.cu_length); | |
5657 | printf (_(" Version: %d\n"), compunit.cu_version); | |
5658 | printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset); | |
5659 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); | |
5660 | ||
5661 | if (first_abbrev != NULL) | |
5662 | free_abbrevs (); | |
5663 | ||
5664 | /* Read in the abbrevs used by this compilation unit. */ | |
5665 | ||
5666 | { | |
5667 | Elf32_Internal_Shdr * sec; | |
5668 | unsigned char * begin; | |
5669 | ||
5670 | /* Locate the .debug_abbrev section and process it. */ | |
5671 | for (i = 0, sec = section_headers; | |
5672 | i < elf_header.e_shnum; | |
5673 | i ++, sec ++) | |
5674 | if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0) | |
5675 | break; | |
5676 | ||
5677 | if (i == -1 || sec->sh_size == 0) | |
5678 | { | |
5679 | warn (_("Unable to locate .debug_abbrev section!\n")); | |
5680 | return 0; | |
5681 | } | |
5682 | ||
5683 | GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *, | |
5684 | "debug_abbrev section data"); | |
5685 | ||
5686 | process_abbrev_section (begin + compunit.cu_abbrev_offset, | |
5687 | begin + sec->sh_size); | |
5688 | ||
5689 | free (begin); | |
5690 | } | |
5691 | ||
5692 | level = 0; | |
5693 | while (tags < start) | |
5694 | { | |
5695 | int bytes_read; | |
b4c96d0d | 5696 | unsigned long abbrev_number; |
252b5132 RH |
5697 | abbrev_entry * entry; |
5698 | abbrev_attr * attr; | |
5699 | ||
5700 | abbrev_number = read_leb128 (tags, & bytes_read, 0); | |
5701 | tags += bytes_read; | |
5702 | ||
5703 | /* A null DIE marks the end of a list of children. */ | |
5704 | if (abbrev_number == 0) | |
5705 | { | |
5706 | --level; | |
5707 | continue; | |
5708 | } | |
5709 | ||
5710 | /* Scan through the abbreviation list until we reach the | |
5711 | correct entry. */ | |
5712 | for (entry = first_abbrev; | |
5713 | entry && entry->entry != abbrev_number; | |
5714 | entry = entry->next) | |
5715 | continue; | |
5716 | ||
5717 | if (entry == NULL) | |
5718 | { | |
b4c96d0d | 5719 | warn (_("Unable to locate entry %lu in the abbreviation table\n"), |
252b5132 RH |
5720 | abbrev_number); |
5721 | return 0; | |
5722 | } | |
5723 | ||
b4c96d0d | 5724 | printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"), |
252b5132 RH |
5725 | level, tags - section_begin - bytes_read, |
5726 | abbrev_number, | |
5727 | get_TAG_name (entry->tag)); | |
5728 | ||
5729 | for (attr = entry->first_attr; attr; attr = attr->next) | |
5730 | tags = read_and_display_attr (attr->attribute, | |
5731 | attr->form, | |
5732 | tags, | |
5733 | compunit.cu_pointer_size); | |
5734 | ||
5735 | if (entry->children) | |
5736 | ++level; | |
5737 | } | |
5738 | } | |
5739 | ||
5740 | printf ("\n"); | |
5741 | ||
5742 | return 1; | |
5743 | } | |
5744 | ||
5745 | static int | |
5746 | display_debug_aranges (section, start, file) | |
5747 | Elf32_Internal_Shdr * section; | |
5748 | unsigned char * start; | |
b4c96d0d | 5749 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 RH |
5750 | { |
5751 | unsigned char * end = start + section->sh_size; | |
5752 | ||
5753 | printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); | |
5754 | ||
5755 | while (start < end) | |
5756 | { | |
5757 | DWARF2_External_ARange * external; | |
5758 | DWARF2_Internal_ARange arange; | |
5759 | unsigned char * ranges; | |
5760 | unsigned long length; | |
5761 | unsigned long address; | |
7a4b7442 | 5762 | int excess; |
252b5132 RH |
5763 | |
5764 | external = (DWARF2_External_ARange *) start; | |
5765 | ||
5766 | arange.ar_length = BYTE_GET (external->ar_length); | |
5767 | arange.ar_version = BYTE_GET (external->ar_version); | |
5768 | arange.ar_info_offset = BYTE_GET (external->ar_info_offset); | |
5769 | arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size); | |
5770 | arange.ar_segment_size = BYTE_GET (external->ar_segment_size); | |
5771 | ||
5772 | printf (_(" Length: %ld\n"), arange.ar_length); | |
5773 | printf (_(" Version: %d\n"), arange.ar_version); | |
5774 | printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset); | |
5775 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); | |
5776 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
5777 | ||
5778 | printf (_("\n Address Length\n")); | |
5779 | ||
5780 | ranges = start + sizeof (* external); | |
5781 | ||
7a4b7442 NC |
5782 | /* Must pad to an alignment boundary that is twice the pointer size. */ |
5783 | excess = sizeof (*external) % (2 * arange.ar_pointer_size); | |
5784 | if (excess) | |
5785 | ranges += (2 * arange.ar_pointer_size) - excess; | |
5786 | ||
252b5132 RH |
5787 | for (;;) |
5788 | { | |
5789 | address = byte_get (ranges, arange.ar_pointer_size); | |
5790 | ||
252b5132 RH |
5791 | ranges += arange.ar_pointer_size; |
5792 | ||
5793 | length = byte_get (ranges, arange.ar_pointer_size); | |
5794 | ||
5795 | ranges += arange.ar_pointer_size; | |
5796 | ||
7a4b7442 NC |
5797 | /* A pair of zeros marks the end of the list. */ |
5798 | if (address == 0 && length == 0) | |
5799 | break; | |
5800 | ||
252b5132 RH |
5801 | printf (" %8.8lx %lu\n", address, length); |
5802 | } | |
5803 | ||
5804 | start += arange.ar_length + sizeof (external->ar_length); | |
5805 | } | |
5806 | ||
5807 | printf ("\n"); | |
5808 | ||
5809 | return 1; | |
5810 | } | |
5811 | ||
5812 | ||
5813 | static int | |
5814 | display_debug_not_supported (section, start, file) | |
5815 | Elf32_Internal_Shdr * section; | |
b4c96d0d ILT |
5816 | unsigned char * start ATTRIBUTE_UNUSED; |
5817 | FILE * file ATTRIBUTE_UNUSED; | |
252b5132 RH |
5818 | { |
5819 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
5820 | SECTION_NAME (section)); | |
5821 | ||
5822 | return 1; | |
5823 | } | |
5824 | ||
3590ea00 NC |
5825 | /* Pre-scan the .debug_info section to record the size of address. |
5826 | When dumping the .debug_line, we use that size information, assuming | |
5827 | that all compilation units have the same address size. */ | |
5828 | static int | |
5829 | prescan_debug_info (section, start, file) | |
5830 | Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED; | |
5831 | unsigned char * start; | |
5832 | FILE * file ATTRIBUTE_UNUSED; | |
5833 | { | |
5834 | DWARF2_External_CompUnit * external; | |
5835 | ||
5836 | external = (DWARF2_External_CompUnit *) start; | |
5837 | ||
5838 | debug_line_pointer_size = BYTE_GET (external->cu_pointer_size); | |
5839 | return 0; | |
5840 | } | |
5841 | ||
252b5132 | 5842 | /* A structure containing the name of a debug section and a pointer |
3590ea00 NC |
5843 | to a function that can decode it. The third field is a prescan |
5844 | function to be run over the section before displaying any of the | |
5845 | sections. */ | |
252b5132 RH |
5846 | struct |
5847 | { | |
5848 | char * name; | |
3590ea00 NC |
5849 | int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
5850 | int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
252b5132 RH |
5851 | } |
5852 | debug_displays[] = | |
5853 | { | |
3590ea00 NC |
5854 | { ".debug_info", display_debug_info, prescan_debug_info }, |
5855 | { ".debug_abbrev", display_debug_abbrev, NULL }, | |
5856 | { ".debug_line", display_debug_lines, NULL }, | |
5857 | { ".debug_aranges", display_debug_aranges, NULL }, | |
5858 | { ".debug_pubnames", display_debug_pubnames, NULL }, | |
5859 | { ".debug_macinfo", display_debug_not_supported, NULL }, | |
5860 | { ".debug_frame", display_debug_not_supported, NULL }, | |
5861 | { ".debug_str", display_debug_not_supported, NULL }, | |
5862 | { ".debug_static_func", display_debug_not_supported, NULL }, | |
5863 | { ".debug_static_vars", display_debug_not_supported, NULL }, | |
5864 | { ".debug_types", display_debug_not_supported, NULL }, | |
5865 | { ".debug_weaknames", display_debug_not_supported, NULL } | |
252b5132 RH |
5866 | }; |
5867 | ||
5868 | static int | |
5869 | display_debug_section (section, file) | |
5870 | Elf32_Internal_Shdr * section; | |
5871 | FILE * file; | |
5872 | { | |
5873 | char * name = SECTION_NAME (section); | |
5874 | bfd_size_type length; | |
5875 | unsigned char * start; | |
5876 | int i; | |
5877 | ||
5878 | length = section->sh_size; | |
5879 | if (length == 0) | |
5880 | { | |
5881 | printf (_("\nSection '%s' has no debugging data.\n"), name); | |
5882 | return 0; | |
5883 | } | |
5884 | ||
5885 | GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *, | |
5886 | "debug section data"); | |
5887 | ||
5888 | /* See if we know how to display the contents of this section. */ | |
5889 | for (i = NUM_ELEM (debug_displays); i--;) | |
5890 | if (strcmp (debug_displays[i].name, name) == 0) | |
5891 | { | |
5892 | debug_displays[i].display (section, start, file); | |
5893 | break; | |
5894 | } | |
5895 | ||
5896 | if (i == -1) | |
5897 | printf (_("Unrecognised debug section: %s\n"), name); | |
5898 | ||
5899 | free (start); | |
5900 | ||
5901 | /* If we loaded in the abbrev section at some point, | |
5902 | we must release it here. */ | |
5903 | if (first_abbrev != NULL) | |
5904 | free_abbrevs (); | |
5905 | ||
5906 | return 1; | |
5907 | } | |
5908 | ||
5909 | static int | |
5910 | process_section_contents (file) | |
5911 | FILE * file; | |
5912 | { | |
3590ea00 NC |
5913 | Elf32_Internal_Shdr * section; |
5914 | unsigned int i; | |
252b5132 RH |
5915 | |
5916 | if (! do_dump) | |
5917 | return 1; | |
5918 | ||
3590ea00 NC |
5919 | /* Pre-scan the debug sections to find some debug information not |
5920 | present in some of them. For the .debug_line, we must find out the | |
5921 | size of address (specified in .debug_info and .debug_aranges). */ | |
5922 | for (i = 0, section = section_headers; | |
5923 | i < elf_header.e_shnum && i < num_dump_sects; | |
5924 | i ++, section ++) | |
5925 | { | |
5926 | char * name = SECTION_NAME (section); | |
5927 | int j; | |
5928 | ||
5929 | if (section->sh_size == 0) | |
5930 | continue; | |
5931 | ||
5932 | /* See if there is some pre-scan operation for this section. */ | |
5933 | for (j = NUM_ELEM (debug_displays); j--;) | |
5934 | if (strcmp (debug_displays[j].name, name) == 0) | |
5935 | { | |
5936 | if (debug_displays[j].prescan != NULL) | |
5937 | { | |
5938 | bfd_size_type length; | |
5939 | unsigned char * start; | |
5940 | ||
5941 | length = section->sh_size; | |
5942 | GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *, | |
5943 | "debug section data"); | |
5944 | ||
5945 | debug_displays[j].prescan (section, start, file); | |
5946 | free (start); | |
5947 | } | |
5948 | ||
5949 | break; | |
5950 | } | |
5951 | } | |
5952 | ||
252b5132 | 5953 | for (i = 0, section = section_headers; |
3590ea00 | 5954 | i < elf_header.e_shnum && i < num_dump_sects; |
252b5132 RH |
5955 | i ++, section ++) |
5956 | { | |
5957 | #ifdef SUPPORT_DISASSEMBLY | |
5958 | if (dump_sects[i] & DISASS_DUMP) | |
5959 | disassemble_section (section, file); | |
5960 | #endif | |
5961 | if (dump_sects[i] & HEX_DUMP) | |
5962 | dump_section (section, file); | |
5963 | ||
5964 | if (dump_sects[i] & DEBUG_DUMP) | |
5965 | display_debug_section (section, file); | |
5966 | } | |
5967 | ||
5968 | if (i < num_dump_sects) | |
5969 | warn (_("Some sections were not dumped because they do not exist!\n")); | |
5970 | ||
5971 | return 1; | |
5972 | } | |
5973 | ||
5974 | static void | |
5975 | process_mips_fpe_exception (mask) | |
5976 | int mask; | |
5977 | { | |
5978 | if (mask) | |
5979 | { | |
5980 | int first = 1; | |
5981 | if (mask & OEX_FPU_INEX) | |
5982 | fputs ("INEX", stdout), first = 0; | |
5983 | if (mask & OEX_FPU_UFLO) | |
5984 | printf ("%sUFLO", first ? "" : "|"), first = 0; | |
5985 | if (mask & OEX_FPU_OFLO) | |
5986 | printf ("%sOFLO", first ? "" : "|"), first = 0; | |
5987 | if (mask & OEX_FPU_DIV0) | |
5988 | printf ("%sDIV0", first ? "" : "|"), first = 0; | |
5989 | if (mask & OEX_FPU_INVAL) | |
5990 | printf ("%sINVAL", first ? "" : "|"); | |
5991 | } | |
5992 | else | |
5993 | fputs ("0", stdout); | |
5994 | } | |
5995 | ||
5996 | static int | |
5997 | process_mips_specific (file) | |
9ea033b2 | 5998 | FILE * file; |
252b5132 | 5999 | { |
9ea033b2 | 6000 | Elf_Internal_Dyn * entry; |
252b5132 RH |
6001 | size_t liblist_offset = 0; |
6002 | size_t liblistno = 0; | |
6003 | size_t conflictsno = 0; | |
6004 | size_t options_offset = 0; | |
6005 | size_t conflicts_offset = 0; | |
6006 | ||
6007 | /* We have a lot of special sections. Thanks SGI! */ | |
6008 | if (dynamic_segment == NULL) | |
6009 | /* No information available. */ | |
6010 | return 0; | |
6011 | ||
6012 | for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry) | |
6013 | switch (entry->d_tag) | |
6014 | { | |
6015 | case DT_MIPS_LIBLIST: | |
6016 | liblist_offset = entry->d_un.d_val - loadaddr; | |
6017 | break; | |
6018 | case DT_MIPS_LIBLISTNO: | |
6019 | liblistno = entry->d_un.d_val; | |
6020 | break; | |
6021 | case DT_MIPS_OPTIONS: | |
6022 | options_offset = entry->d_un.d_val - loadaddr; | |
6023 | break; | |
6024 | case DT_MIPS_CONFLICT: | |
6025 | conflicts_offset = entry->d_un.d_val - loadaddr; | |
6026 | break; | |
6027 | case DT_MIPS_CONFLICTNO: | |
6028 | conflictsno = entry->d_un.d_val; | |
6029 | break; | |
6030 | default: | |
6031 | break; | |
6032 | } | |
6033 | ||
6034 | if (liblist_offset != 0 && liblistno != 0 && do_dynamic) | |
6035 | { | |
9ea033b2 | 6036 | Elf32_External_Lib * elib; |
252b5132 RH |
6037 | size_t cnt; |
6038 | ||
6039 | GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib), | |
6040 | elib, Elf32_External_Lib *, "liblist"); | |
6041 | ||
6042 | printf ("\nSection '.liblist' contains %d entries:\n", liblistno); | |
6043 | fputs (" Library Time Stamp Checksum Version Flags\n", | |
6044 | stdout); | |
6045 | ||
6046 | for (cnt = 0; cnt < liblistno; ++cnt) | |
6047 | { | |
6048 | Elf32_Lib liblist; | |
6049 | time_t time; | |
6050 | char timebuf[20]; | |
6051 | ||
6052 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
6053 | time = BYTE_GET (elib[cnt].l_time_stamp); | |
6054 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
6055 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
6056 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
6057 | ||
6058 | strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time)); | |
6059 | ||
6060 | printf ("%3d: %-20s %s %#10lx %-7ld", cnt, | |
6061 | dynamic_strings + liblist.l_name, timebuf, | |
6062 | liblist.l_checksum, liblist.l_version); | |
6063 | ||
6064 | if (liblist.l_flags == 0) | |
6065 | puts (" NONE"); | |
6066 | else | |
6067 | { | |
6068 | static const struct | |
6069 | { | |
6070 | const char *name; | |
6071 | int bit; | |
6072 | } l_flags_vals[] = | |
6073 | { | |
6074 | { " EXACT_MATCH", LL_EXACT_MATCH }, | |
6075 | { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, | |
6076 | { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, | |
6077 | { " EXPORTS", LL_EXPORTS }, | |
6078 | { " DELAY_LOAD", LL_DELAY_LOAD }, | |
6079 | { " DELTA", LL_DELTA } | |
6080 | }; | |
6081 | int flags = liblist.l_flags; | |
b4c96d0d | 6082 | size_t fcnt; |
252b5132 RH |
6083 | |
6084 | for (fcnt = 0; | |
6085 | fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]); | |
6086 | ++fcnt) | |
6087 | if ((flags & l_flags_vals[fcnt].bit) != 0) | |
6088 | { | |
6089 | fputs (l_flags_vals[fcnt].name, stdout); | |
6090 | flags ^= l_flags_vals[fcnt].bit; | |
6091 | } | |
6092 | if (flags != 0) | |
6093 | printf (" %#x", (unsigned int) flags); | |
6094 | ||
6095 | puts (""); | |
6096 | } | |
6097 | } | |
6098 | ||
6099 | free (elib); | |
6100 | } | |
6101 | ||
6102 | if (options_offset != 0) | |
6103 | { | |
9ea033b2 NC |
6104 | Elf_External_Options * eopt; |
6105 | Elf_Internal_Shdr * sect = section_headers; | |
6106 | Elf_Internal_Options * iopt; | |
6107 | Elf_Internal_Options * option; | |
252b5132 RH |
6108 | size_t offset; |
6109 | int cnt; | |
6110 | ||
6111 | /* Find the section header so that we get the size. */ | |
6112 | while (sect->sh_type != SHT_MIPS_OPTIONS) | |
6113 | ++sect; | |
6114 | ||
6115 | GET_DATA_ALLOC (options_offset, sect->sh_size, eopt, | |
6116 | Elf_External_Options *, "options"); | |
6117 | ||
6118 | iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt)) | |
6119 | * sizeof (*iopt)); | |
6120 | if (iopt == NULL) | |
6121 | { | |
6122 | error (_("Out of memory")); | |
6123 | return 0; | |
6124 | } | |
6125 | ||
6126 | offset = cnt = 0; | |
6127 | option = iopt; | |
6128 | while (offset < sect->sh_size) | |
6129 | { | |
9ea033b2 | 6130 | Elf_External_Options * eoption; |
252b5132 RH |
6131 | |
6132 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
6133 | ||
6134 | option->kind = BYTE_GET (eoption->kind); | |
6135 | option->size = BYTE_GET (eoption->size); | |
6136 | option->section = BYTE_GET (eoption->section); | |
6137 | option->info = BYTE_GET (eoption->info); | |
6138 | ||
6139 | offset += option->size; | |
6140 | ++option; | |
6141 | ++cnt; | |
6142 | } | |
6143 | ||
6144 | printf (_("\nSection '%s' contains %d entries:\n"), | |
6145 | string_table + sect->sh_name, cnt); | |
6146 | ||
6147 | option = iopt; | |
6148 | while (cnt-- > 0) | |
6149 | { | |
6150 | size_t len; | |
6151 | ||
6152 | switch (option->kind) | |
6153 | { | |
6154 | case ODK_NULL: | |
6155 | /* This shouldn't happen. */ | |
6156 | printf (" NULL %d %lx", option->section, option->info); | |
6157 | break; | |
6158 | case ODK_REGINFO: | |
6159 | printf (" REGINFO "); | |
6160 | if (elf_header.e_machine == EM_MIPS) | |
6161 | { | |
6162 | /* 32bit form. */ | |
6163 | Elf32_External_RegInfo *ereg; | |
6164 | Elf32_RegInfo reginfo; | |
6165 | ||
6166 | ereg = (Elf32_External_RegInfo *) (option + 1); | |
6167 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
6168 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
6169 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
6170 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
6171 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
6172 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
6173 | ||
6174 | printf ("GPR %08lx GP 0x%lx\n", | |
6175 | reginfo.ri_gprmask, | |
6176 | (unsigned long) reginfo.ri_gp_value); | |
6177 | printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", | |
6178 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
6179 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
6180 | } | |
6181 | else | |
6182 | { | |
6183 | /* 64 bit form. */ | |
9ea033b2 | 6184 | Elf64_External_RegInfo * ereg; |
252b5132 RH |
6185 | Elf64_Internal_RegInfo reginfo; |
6186 | ||
6187 | ereg = (Elf64_External_RegInfo *) (option + 1); | |
9ea033b2 | 6188 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); |
252b5132 RH |
6189 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); |
6190 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
6191 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
6192 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
9ea033b2 | 6193 | reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value); |
252b5132 RH |
6194 | |
6195 | printf ("GPR %08lx GP 0x", | |
6196 | reginfo.ri_gprmask); | |
6197 | printf_vma (reginfo.ri_gp_value); | |
6198 | printf ("\n"); | |
6199 | ||
6200 | printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", | |
6201 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
6202 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
6203 | } | |
6204 | ++option; | |
6205 | continue; | |
6206 | case ODK_EXCEPTIONS: | |
6207 | fputs (" EXCEPTIONS fpe_min(", stdout); | |
6208 | process_mips_fpe_exception (option->info & OEX_FPU_MIN); | |
6209 | fputs (") fpe_max(", stdout); | |
6210 | process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8); | |
6211 | fputs (")", stdout); | |
6212 | ||
6213 | if (option->info & OEX_PAGE0) | |
6214 | fputs (" PAGE0", stdout); | |
6215 | if (option->info & OEX_SMM) | |
6216 | fputs (" SMM", stdout); | |
6217 | if (option->info & OEX_FPDBUG) | |
6218 | fputs (" FPDBUG", stdout); | |
6219 | if (option->info & OEX_DISMISS) | |
6220 | fputs (" DISMISS", stdout); | |
6221 | break; | |
6222 | case ODK_PAD: | |
6223 | fputs (" PAD ", stdout); | |
6224 | if (option->info & OPAD_PREFIX) | |
6225 | fputs (" PREFIX", stdout); | |
6226 | if (option->info & OPAD_POSTFIX) | |
6227 | fputs (" POSTFIX", stdout); | |
6228 | if (option->info & OPAD_SYMBOL) | |
6229 | fputs (" SYMBOL", stdout); | |
6230 | break; | |
6231 | case ODK_HWPATCH: | |
6232 | fputs (" HWPATCH ", stdout); | |
6233 | if (option->info & OHW_R4KEOP) | |
6234 | fputs (" R4KEOP", stdout); | |
6235 | if (option->info & OHW_R8KPFETCH) | |
6236 | fputs (" R8KPFETCH", stdout); | |
6237 | if (option->info & OHW_R5KEOP) | |
6238 | fputs (" R5KEOP", stdout); | |
6239 | if (option->info & OHW_R5KCVTL) | |
6240 | fputs (" R5KCVTL", stdout); | |
6241 | break; | |
6242 | case ODK_FILL: | |
6243 | fputs (" FILL ", stdout); | |
6244 | /* XXX Print content of info word? */ | |
6245 | break; | |
6246 | case ODK_TAGS: | |
6247 | fputs (" TAGS ", stdout); | |
6248 | /* XXX Print content of info word? */ | |
6249 | break; | |
6250 | case ODK_HWAND: | |
6251 | fputs (" HWAND ", stdout); | |
6252 | if (option->info & OHWA0_R4KEOP_CHECKED) | |
6253 | fputs (" R4KEOP_CHECKED", stdout); | |
6254 | if (option->info & OHWA0_R4KEOP_CLEAN) | |
6255 | fputs (" R4KEOP_CLEAN", stdout); | |
6256 | break; | |
6257 | case ODK_HWOR: | |
6258 | fputs (" HWOR ", stdout); | |
6259 | if (option->info & OHWA0_R4KEOP_CHECKED) | |
6260 | fputs (" R4KEOP_CHECKED", stdout); | |
6261 | if (option->info & OHWA0_R4KEOP_CLEAN) | |
6262 | fputs (" R4KEOP_CLEAN", stdout); | |
6263 | break; | |
6264 | case ODK_GP_GROUP: | |
6265 | printf (" GP_GROUP %#06lx self-contained %#06lx", | |
6266 | option->info & OGP_GROUP, | |
6267 | (option->info & OGP_SELF) >> 16); | |
6268 | break; | |
6269 | case ODK_IDENT: | |
6270 | printf (" IDENT %#06lx self-contained %#06lx", | |
6271 | option->info & OGP_GROUP, | |
6272 | (option->info & OGP_SELF) >> 16); | |
6273 | break; | |
6274 | default: | |
6275 | /* This shouldn't happen. */ | |
6276 | printf (" %3d ??? %d %lx", | |
6277 | option->kind, option->section, option->info); | |
6278 | break; | |
6279 | } | |
6280 | ||
6281 | len = sizeof (*eopt); | |
6282 | while (len < option->size) | |
6283 | if (((char *) option)[len] >= ' ' | |
6284 | && ((char *) option)[len] < 0x7f) | |
6285 | printf ("%c", ((char *) option)[len++]); | |
6286 | else | |
6287 | printf ("\\%03o", ((char *) option)[len++]); | |
6288 | ||
6289 | fputs ("\n", stdout); | |
6290 | ++option; | |
6291 | } | |
6292 | ||
6293 | free (eopt); | |
6294 | } | |
6295 | ||
6296 | if (conflicts_offset != 0 && conflictsno != 0) | |
6297 | { | |
9ea033b2 NC |
6298 | Elf32_External_Conflict * econf32; |
6299 | Elf64_External_Conflict * econf64; | |
6300 | Elf32_Conflict * iconf; | |
252b5132 RH |
6301 | size_t cnt; |
6302 | ||
6303 | if (dynamic_symbols == NULL) | |
6304 | { | |
6305 | error (_("conflict list with without table")); | |
6306 | return 0; | |
6307 | } | |
6308 | ||
6309 | iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (*iconf)); | |
6310 | if (iconf == NULL) | |
6311 | { | |
6312 | error (_("Out of memory")); | |
6313 | return 0; | |
6314 | } | |
6315 | ||
9ea033b2 | 6316 | if (is_32bit_elf) |
252b5132 RH |
6317 | { |
6318 | GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf32), | |
6319 | econf32, Elf32_External_Conflict *, "conflict"); | |
6320 | ||
6321 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
6322 | iconf[cnt] = BYTE_GET (econf32[cnt]); | |
6323 | } | |
6324 | else | |
6325 | { | |
6326 | GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf64), | |
6327 | econf64, Elf64_External_Conflict *, "conflict"); | |
6328 | ||
6329 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
6330 | iconf[cnt] = BYTE_GET (econf64[cnt]); | |
6331 | } | |
6332 | ||
6333 | printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno); | |
6334 | puts (_(" Num: Index Value Name")); | |
6335 | ||
6336 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
6337 | { | |
19936277 | 6338 | Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]]; |
252b5132 RH |
6339 | |
6340 | printf ("%5u: %8lu %#10lx %s\n", | |
6341 | cnt, iconf[cnt], (unsigned long) psym->st_value, | |
6342 | dynamic_strings + psym->st_name); | |
6343 | } | |
6344 | ||
6345 | ||
6346 | free (iconf); | |
6347 | } | |
6348 | ||
6349 | return 1; | |
6350 | } | |
6351 | ||
6352 | static int | |
6353 | process_arch_specific (file) | |
9ea033b2 | 6354 | FILE * file; |
252b5132 | 6355 | { |
a952a375 NC |
6356 | if (! do_arch) |
6357 | return 1; | |
6358 | ||
252b5132 RH |
6359 | switch (elf_header.e_machine) |
6360 | { | |
6361 | case EM_MIPS: | |
6362 | case EM_MIPS_RS4_BE: | |
6363 | return process_mips_specific (file); | |
6364 | break; | |
6365 | default: | |
6366 | break; | |
6367 | } | |
6368 | return 1; | |
6369 | } | |
6370 | ||
6371 | static int | |
6372 | get_file_header (file) | |
6373 | FILE * file; | |
6374 | { | |
9ea033b2 NC |
6375 | /* Read in the identity array. */ |
6376 | if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1) | |
252b5132 RH |
6377 | return 0; |
6378 | ||
9ea033b2 NC |
6379 | /* Determine how to read the rest of the header. */ |
6380 | switch (elf_header.e_ident [EI_DATA]) | |
6381 | { | |
6382 | default: /* fall through */ | |
6383 | case ELFDATANONE: /* fall through */ | |
6384 | case ELFDATA2LSB: byte_get = byte_get_little_endian; break; | |
6385 | case ELFDATA2MSB: byte_get = byte_get_big_endian; break; | |
6386 | } | |
6387 | ||
6388 | /* For now we only support 32 bit and 64 bit ELF files. */ | |
6389 | is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64); | |
6390 | ||
6391 | /* Read in the rest of the header. */ | |
6392 | if (is_32bit_elf) | |
6393 | { | |
6394 | Elf32_External_Ehdr ehdr32; | |
252b5132 | 6395 | |
9ea033b2 NC |
6396 | if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1) |
6397 | return 0; | |
6398 | ||
6399 | elf_header.e_type = BYTE_GET (ehdr32.e_type); | |
6400 | elf_header.e_machine = BYTE_GET (ehdr32.e_machine); | |
6401 | elf_header.e_version = BYTE_GET (ehdr32.e_version); | |
6402 | elf_header.e_entry = BYTE_GET (ehdr32.e_entry); | |
6403 | elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff); | |
6404 | elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff); | |
6405 | elf_header.e_flags = BYTE_GET (ehdr32.e_flags); | |
6406 | elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); | |
6407 | elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); | |
6408 | elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum); | |
6409 | elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); | |
6410 | elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum); | |
6411 | elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); | |
6412 | } | |
252b5132 | 6413 | else |
9ea033b2 NC |
6414 | { |
6415 | Elf64_External_Ehdr ehdr64; | |
a952a375 NC |
6416 | |
6417 | /* If we have been compiled with sizeof (bfd_vma) == 4, then | |
6418 | we will not be able to cope with the 64bit data found in | |
6419 | 64 ELF files. Detect this now and abort before we start | |
6420 | overwritting things. */ | |
6421 | if (sizeof (bfd_vma) < 8) | |
6422 | { | |
6423 | error (_("This instance of readelf has been built without support for a\n")); | |
6424 | error (_("64 bit data type and so it cannot read 64 bit ELF files.\n")); | |
6425 | return 0; | |
6426 | } | |
9ea033b2 NC |
6427 | |
6428 | if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1) | |
6429 | return 0; | |
6430 | ||
6431 | elf_header.e_type = BYTE_GET (ehdr64.e_type); | |
6432 | elf_header.e_machine = BYTE_GET (ehdr64.e_machine); | |
6433 | elf_header.e_version = BYTE_GET (ehdr64.e_version); | |
6434 | elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry); | |
6435 | elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff); | |
6436 | elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff); | |
6437 | elf_header.e_flags = BYTE_GET (ehdr64.e_flags); | |
6438 | elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); | |
6439 | elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); | |
6440 | elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum); | |
6441 | elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); | |
6442 | elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum); | |
6443 | elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); | |
6444 | } | |
252b5132 RH |
6445 | |
6446 | return 1; | |
6447 | } | |
6448 | ||
6449 | static void | |
6450 | process_file (file_name) | |
6451 | char * file_name; | |
6452 | { | |
6453 | FILE * file; | |
6454 | struct stat statbuf; | |
6455 | unsigned int i; | |
6456 | ||
6457 | if (stat (file_name, & statbuf) < 0) | |
6458 | { | |
6459 | error (_("Cannot stat input file %s.\n"), file_name); | |
6460 | return; | |
6461 | } | |
6462 | ||
6463 | file = fopen (file_name, "rb"); | |
6464 | if (file == NULL) | |
6465 | { | |
6466 | error (_("Input file %s not found.\n"), file_name); | |
6467 | return; | |
6468 | } | |
6469 | ||
6470 | if (! get_file_header (file)) | |
6471 | { | |
6472 | error (_("%s: Failed to read file header\n"), file_name); | |
6473 | fclose (file); | |
6474 | return; | |
6475 | } | |
6476 | ||
6477 | /* Initialise per file variables. */ | |
6478 | for (i = NUM_ELEM (version_info); i--;) | |
6479 | version_info[i] = 0; | |
6480 | ||
6481 | for (i = NUM_ELEM (dynamic_info); i--;) | |
6482 | dynamic_info[i] = 0; | |
6483 | ||
6484 | /* Process the file. */ | |
6485 | if (show_name) | |
6486 | printf (_("\nFile: %s\n"), file_name); | |
6487 | ||
6488 | if (! process_file_header ()) | |
6489 | { | |
6490 | fclose (file); | |
6491 | return; | |
6492 | } | |
6493 | ||
6494 | process_section_headers (file); | |
6495 | ||
6496 | process_program_headers (file); | |
6497 | ||
6498 | process_dynamic_segment (file); | |
6499 | ||
6500 | process_relocs (file); | |
6501 | ||
6502 | process_symbol_table (file); | |
6503 | ||
6504 | process_syminfo (file); | |
6505 | ||
6506 | process_version_sections (file); | |
6507 | ||
6508 | process_section_contents (file); | |
6509 | ||
6510 | process_arch_specific (file); | |
6511 | ||
6512 | fclose (file); | |
6513 | ||
6514 | if (section_headers) | |
6515 | { | |
6516 | free (section_headers); | |
6517 | section_headers = NULL; | |
6518 | } | |
6519 | ||
6520 | if (string_table) | |
6521 | { | |
6522 | free (string_table); | |
6523 | string_table = NULL; | |
6524 | } | |
6525 | ||
6526 | if (dynamic_strings) | |
6527 | { | |
6528 | free (dynamic_strings); | |
6529 | dynamic_strings = NULL; | |
6530 | } | |
6531 | ||
6532 | if (dynamic_symbols) | |
6533 | { | |
6534 | free (dynamic_symbols); | |
6535 | dynamic_symbols = NULL; | |
19936277 | 6536 | num_dynamic_syms = 0; |
252b5132 RH |
6537 | } |
6538 | ||
6539 | if (dynamic_syminfo) | |
6540 | { | |
6541 | free (dynamic_syminfo); | |
6542 | dynamic_syminfo = NULL; | |
6543 | } | |
6544 | } | |
6545 | ||
6546 | #ifdef SUPPORT_DISASSEMBLY | |
6547 | /* Needed by the i386 disassembler. For extra credit, someone could | |
9ea033b2 NC |
6548 | fix this so that we insert symbolic addresses here, esp for GOT/PLT |
6549 | symbols */ | |
252b5132 RH |
6550 | |
6551 | void | |
6552 | print_address (unsigned int addr, FILE * outfile) | |
6553 | { | |
6554 | fprintf (outfile,"0x%8.8x", addr); | |
6555 | } | |
6556 | ||
6557 | /* Needed by the i386 disassembler. */ | |
6558 | void | |
6559 | db_task_printsym (unsigned int addr) | |
6560 | { | |
6561 | print_address (addr, stderr); | |
6562 | } | |
6563 | #endif | |
6564 | ||
6565 | int | |
6566 | main (argc, argv) | |
6567 | int argc; | |
6568 | char ** argv; | |
6569 | { | |
6570 | #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) | |
6571 | setlocale (LC_MESSAGES, ""); | |
6572 | #endif | |
6573 | bindtextdomain (PACKAGE, LOCALEDIR); | |
6574 | textdomain (PACKAGE); | |
6575 | ||
6576 | parse_args (argc, argv); | |
6577 | ||
6578 | if (optind < (argc - 1)) | |
6579 | show_name = 1; | |
6580 | ||
6581 | while (optind < argc) | |
6582 | process_file (argv [optind ++]); | |
6583 | ||
6584 | if (dump_sects != NULL) | |
6585 | free (dump_sects); | |
6586 | ||
6587 | return 0; | |
6588 | } |