Bug Summary

File:src/gnu/usr.bin/binutils-2.17/binutils/readelf.c
Warning:line 5266, column 38
Access to field 'st_shndx' results in a dereference of a null pointer (loaded from variable 'sym')

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name readelf.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/binutils-2.17/obj/binutils -resource-dir /usr/local/lib/clang/13.0.0 -D HAVE_CONFIG_H -I . -I /usr/src/gnu/usr.bin/binutils-2.17/binutils -I . -D _GNU_SOURCE -I . -I /usr/src/gnu/usr.bin/binutils-2.17/binutils -I ../bfd -I /usr/src/gnu/usr.bin/binutils-2.17/binutils/../bfd -I /usr/src/gnu/usr.bin/binutils-2.17/binutils/../include -I /usr/src/gnu/usr.bin/binutils-2.17/binutils/../intl -I ../intl -D LOCALEDIR="/usr/share/locale" -D bin_dummy_emulation=bin_vanilla_emulation -D PIE_DEFAULT=1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/binutils-2.17/obj/binutils -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/gnu/usr.bin/binutils-2.17/binutils/readelf.c
1/* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
7
8 This file is part of GNU Binutils.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 02110-1301, USA. */
24
25/* The difference between readelf and objdump:
26
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
29
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
36
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
39
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
43
44#include <assert.h>
45#include <sys/types.h>
46#include <sys/stat.h>
47#include <stdio.h>
48#include <time.h>
49
50#if __GNUC__4 >= 2
51/* Define BFD64 here, even if our default architecture is 32 bit ELF
52 as this will allow us to read in and parse 64bit and 32bit ELF files.
53 Only do this if we believe that the compiler can support a 64 bit
54 data type. For now we only rely on GCC being able to do this. */
55#define BFD64
56#endif
57
58#include "dwarf.h"
59
60#include "elf/common.h"
61#include "elf/external.h"
62#include "elf/internal.h"
63
64/* The following headers use the elf/reloc-macros.h file to
65 automatically generate relocation recognition functions
66 such as elf_mips_reloc_type() */
67
68#define RELOC_MACROS_GEN_FUNC
69
70#include "elf/aarch64.h"
71#include "elf/alpha.h"
72#include "elf/arc.h"
73#include "elf/arm.h"
74#include "elf/avr.h"
75#include "elf/bfin.h"
76#include "elf/cris.h"
77#include "elf/d10v.h"
78#include "elf/d30v.h"
79#include "elf/dlx.h"
80#include "elf/fr30.h"
81#include "elf/frv.h"
82#include "elf/h8.h"
83#include "elf/hppa.h"
84#include "elf/i386.h"
85#include "elf/i370.h"
86#include "elf/i860.h"
87#include "elf/i960.h"
88#include "elf/ia64.h"
89#include "elf/ip2k.h"
90#include "elf/m32c.h"
91#include "elf/m32r.h"
92#include "elf/m68k.h"
93#include "elf/m68hc11.h"
94#include "elf/m88k.h"
95#include "elf/mcore.h"
96#include "elf/mips.h"
97#include "elf/mmix.h"
98#include "elf/mn10200.h"
99#include "elf/mn10300.h"
100#include "elf/mt.h"
101#include "elf/msp430.h"
102#include "elf/or32.h"
103#include "elf/pj.h"
104#include "elf/ppc.h"
105#include "elf/ppc64.h"
106#include "elf/riscv.h"
107#include "elf/s390.h"
108#include "elf/sh.h"
109#include "elf/sparc.h"
110#include "elf/v850.h"
111#include "elf/vax.h"
112#include "elf/x86-64.h"
113#include "elf/xstormy16.h"
114#include "elf/crx.h"
115#include "elf/iq2000.h"
116#include "elf/xtensa.h"
117
118#include "aout/ar.h"
119
120#include "bucomm.h"
121#include "getopt.h"
122#include "libiberty.h"
123
124char *program_name = "readelf";
125static long archive_file_offset;
126static unsigned long archive_file_size;
127static unsigned long dynamic_addr;
128static bfd_size_type dynamic_size;
129static unsigned int dynamic_nent;
130static char *dynamic_strings;
131static unsigned long dynamic_strings_length;
132static char *string_table;
133static unsigned long string_table_length;
134static unsigned long num_dynamic_syms;
135static Elf_Internal_Sym *dynamic_symbols;
136static Elf_Internal_Syminfo *dynamic_syminfo;
137static unsigned long dynamic_syminfo_offset;
138static unsigned int dynamic_syminfo_nent;
139static char program_interpreter[64];
140static bfd_vma dynamic_info[DT_RELRENT37 + 1];
141static bfd_vma dynamic_info_DT_GNU_HASH;
142static bfd_vma version_info[16];
143static Elf_Internal_Ehdr elf_header;
144static Elf_Internal_Shdr *section_headers;
145static Elf_Internal_Phdr *program_headers;
146static Elf_Internal_Dyn *dynamic_section;
147static Elf_Internal_Shdr *symtab_shndx_hdr;
148static int show_name;
149static int do_dynamic;
150static int do_syms;
151static int do_reloc;
152static int do_raw_relr;
153static int do_sections;
154static int do_section_groups;
155static int do_section_details;
156static int do_segments;
157static int do_unwind;
158static int do_using_dynamic;
159static int do_header;
160static int do_dump;
161static int do_version;
162static int do_wide;
163static int do_histogram;
164static int do_debugging;
165static int do_arch;
166static int do_notes;
167static int is_32bit_elf;
168
169struct group_list
170{
171 struct group_list *next;
172 unsigned int section_index;
173};
174
175struct group
176{
177 struct group_list *root;
178 unsigned int group_index;
179};
180
181static size_t group_count;
182static struct group *section_groups;
183static struct group **section_headers_groups;
184
185/* A linked list of the section names for which dumps were requested
186 by name. */
187struct dump_list_entry
188{
189 char *name;
190 int type;
191 struct dump_list_entry *next;
192};
193static struct dump_list_entry *dump_sects_byname;
194
195/* A dynamic array of flags indicating for which sections a hex dump
196 has been requested (via the -x switch) and/or a disassembly dump
197 (via the -i switch). */
198char *cmdline_dump_sects = NULL((void*)0);
199unsigned num_cmdline_dump_sects = 0;
200
201/* A dynamic array of flags indicating for which sections a dump of
202 some kind has been requested. It is reset on a per-object file
203 basis and then initialised from the cmdline_dump_sects array,
204 the results of interpreting the -w switch, and the
205 dump_sects_byname list. */
206char *dump_sects = NULL((void*)0);
207unsigned int num_dump_sects = 0;
208
209#define HEX_DUMP(1 << 0) (1 << 0)
210#define DISASS_DUMP(1 << 1) (1 << 1)
211#define DEBUG_DUMP(1 << 2) (1 << 2)
212
213/* How to print a vma value. */
214typedef enum print_mode
215{
216 HEX,
217 DEC,
218 DEC_5,
219 UNSIGNED,
220 PREFIX_HEX,
221 FULL_HEX,
222 LONG_HEX
223}
224print_mode;
225
226static void (*byte_put) (unsigned char *, bfd_vma, int);
227
228#define UNKNOWN-1 -1
229#define RELR-2 -2
230
231static long offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size);
232
233#define SECTION_NAME(X)((X) == ((void*)0) ? "<none>" : ((X)->sh_name >= string_table_length
? "<corrupt>" : string_table + (X)->sh_name))
((X) == NULL((void*)0) ? "<none>" : \
234 ((X)->sh_name >= string_table_length \
235 ? "<corrupt>" : string_table + (X)->sh_name))
236
237/* Given st_shndx I, map to section_headers index. */
238#define SECTION_HEADER_INDEX(I)((I) < 0xFF00 ? (I) : ((I) <= 0xFFFF ? 0 : (I) - (0xFFFF
+ 1 - 0xFF00)))
\
239 ((I) < SHN_LORESERVE0xFF00 \
240 ? (I) \
241 : ((I) <= SHN_HIRESERVE0xFFFF \
242 ? 0 \
243 : (I) - (SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00)))
244
245/* Reverse of the above. */
246#define SECTION_HEADER_NUM(N)((N) < 0xFF00 ? (N) : (N) + (0xFFFF + 1 - 0xFF00)) \
247 ((N) < SHN_LORESERVE0xFF00 \
248 ? (N) \
249 : (N) + (SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00))
250
251#define SECTION_HEADER(I)(section_headers + ((I) < 0xFF00 ? (I) : ((I) <= 0xFFFF
? 0 : (I) - (0xFFFF + 1 - 0xFF00))))
(section_headers + SECTION_HEADER_INDEX (I)((I) < 0xFF00 ? (I) : ((I) <= 0xFFFF ? 0 : (I) - (0xFFFF
+ 1 - 0xFF00)))
)
252
253#define DT_VERSIONTAGIDX(tag)(0x6fffffff - (tag)) (DT_VERNEEDNUM0x6fffffff - (tag)) /* Reverse order! */
254
255#define BYTE_GET(field)byte_get (field, sizeof (field)) byte_get (field, sizeof (field))
256
257#define NUM_ELEM(array)(sizeof (array) / sizeof ((array)[0])) (sizeof (array) / sizeof ((array)[0]))
258
259#define GET_ELF_SYMBOLS(file, section)(is_32bit_elf ? get_32bit_elf_symbols (file, section) : get_64bit_elf_symbols
(file, section))
\
260 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
261 : get_64bit_elf_symbols (file, section))
262
263#define VALID_DYNAMIC_NAME(offset)((dynamic_strings != ((void*)0)) && (offset < dynamic_strings_length
))
((dynamic_strings != NULL((void*)0)) && (offset < dynamic_strings_length))
264/* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
265 already been called and verified that the string exists. */
266#define GET_DYNAMIC_NAME(offset)(dynamic_strings + offset) (dynamic_strings + offset)
267
268/* This is just a bit of syntatic sugar. */
269#define streq(a,b)(strcmp ((a), (b)) == 0) (strcmp ((a), (b)) == 0)
270#define strneq(a,b,n)(strncmp ((a), (b), (n)) == 0) (strncmp ((a), (b), (n)) == 0)
271
272static void *
273get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
274 const char *reason)
275{
276 void *mvar;
277
278 if (size == 0 || nmemb == 0)
279 return NULL((void*)0);
280
281 if (fseek (file, archive_file_offset + offset, SEEK_SET0))
282 {
283 error (_("Unable to seek to 0x%lx for %s\n")("Unable to seek to 0x%lx for %s\n"),
284 archive_file_offset + offset, reason);
285 return NULL((void*)0);
286 }
287
288 mvar = var;
289 if (mvar == NULL((void*)0))
290 {
291 /* Check for overflow. */
292 if (nmemb < (~(size_t) 0 - 1) / size)
293 /* + 1 so that we can '\0' terminate invalid string table sections. */
294 mvar = malloc (size * nmemb + 1);
295
296 if (mvar == NULL((void*)0))
297 {
298 error (_("Out of memory allocating 0x%lx bytes for %s\n")("Out of memory allocating 0x%lx bytes for %s\n"),
299 (unsigned long)(size * nmemb), reason);
300 return NULL((void*)0);
301 }
302
303 ((char *) mvar)[size * nmemb] = '\0';
304 }
305
306 if (fread (mvar, size, nmemb, file) != nmemb)
307 {
308 error (_("Unable to read in 0x%lx bytes of %s\n")("Unable to read in 0x%lx bytes of %s\n"),
309 (unsigned long)(size * nmemb), reason);
310 if (mvar != var)
311 free (mvar);
312 return NULL((void*)0);
313 }
314
315 return mvar;
316}
317
318static void
319byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
320{
321 switch (size)
322 {
323 case 8:
324 field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
325 field[6] = ((value >> 24) >> 24) & 0xff;
326 field[5] = ((value >> 24) >> 16) & 0xff;
327 field[4] = ((value >> 24) >> 8) & 0xff;
328 /* Fall through. */
329 case 4:
330 field[3] = (value >> 24) & 0xff;
331 field[2] = (value >> 16) & 0xff;
332 /* Fall through. */
333 case 2:
334 field[1] = (value >> 8) & 0xff;
335 /* Fall through. */
336 case 1:
337 field[0] = value & 0xff;
338 break;
339
340 default:
341 error (_("Unhandled data length: %d\n")("Unhandled data length: %d\n"), size);
342 abort ();
343 }
344}
345
346#if defined BFD64 && !BFD_HOST_64BIT_LONG1
347static int
348print_dec_vma (bfd_vma vma, int is_signed)
349{
350 char buf[40];
351 char *bufp = buf;
352 int nc = 0;
353
354 if (is_signed && (bfd_signed_vma) vma < 0)
355 {
356 vma = -vma;
357 putchar ('-')(!__isthreaded ? __sputc('-', (&__sF[1])) : (putc)('-', (
&__sF[1])))
;
358 nc = 1;
359 }
360
361 do
362 {
363 *bufp++ = '0' + vma % 10;
364 vma /= 10;
365 }
366 while (vma != 0);
367 nc += bufp - buf;
368
369 while (bufp > buf)
370 putchar (*--bufp)(!__isthreaded ? __sputc(*--bufp, (&__sF[1])) : (putc)(*--
bufp, (&__sF[1])))
;
371 return nc;
372}
373
374static int
375print_hex_vma (bfd_vma vma)
376{
377 char buf[32];
378 char *bufp = buf;
379 int nc;
380
381 do
382 {
383 char digit = '0' + (vma & 0x0f);
384 if (digit > '9')
385 digit += 'a' - '0' - 10;
386 *bufp++ = digit;
387 vma >>= 4;
388 }
389 while (vma != 0);
390 nc = bufp - buf;
391
392 while (bufp > buf)
393 putchar (*--bufp)(!__isthreaded ? __sputc(*--bufp, (&__sF[1])) : (putc)(*--
bufp, (&__sF[1])))
;
394 return nc;
395}
396#endif
397
398/* Print a VMA value. */
399static int
400print_vma (bfd_vma vma, print_mode mode)
401{
402#ifdef BFD64
403 if (is_32bit_elf)
404#endif
405 {
406 switch (mode)
407 {
408 case FULL_HEX:
409 return printf ("0x%8.8lx", (unsigned long) vma);
410
411 case LONG_HEX:
412 return printf ("%8.8lx", (unsigned long) vma);
413
414 case DEC_5:
415 if (vma <= 99999)
416 return printf ("%5ld", (long) vma);
417 /* Drop through. */
418
419 case PREFIX_HEX:
420 return printf ("0x%lx", (unsigned long) vma);
421
422 case HEX:
423 return printf ("%lx", (unsigned long) vma);
424
425 case DEC:
426 return printf ("%ld", (unsigned long) vma);
427
428 case UNSIGNED:
429 return printf ("%lu", (unsigned long) vma);
430 }
431 }
432#ifdef BFD64
433 else
434 {
435 int nc = 0;
436
437 switch (mode)
438 {
439 case FULL_HEX:
440 nc = printf ("0x");
441 /* Drop through. */
442
443 case LONG_HEX:
444 printf_vma (vma)fprintf ((&__sF[1]), "%016lx", vma);
445 return nc + 16;
446
447 case PREFIX_HEX:
448 nc = printf ("0x");
449 /* Drop through. */
450
451 case HEX:
452#if BFD_HOST_64BIT_LONG1
453 return nc + printf ("%lx", vma);
454#else
455 return nc + print_hex_vma (vma);
456#endif
457
458 case DEC:
459#if BFD_HOST_64BIT_LONG1
460 return printf ("%ld", vma);
461#else
462 return print_dec_vma (vma, 1);
463#endif
464
465 case DEC_5:
466#if BFD_HOST_64BIT_LONG1
467 if (vma <= 99999)
468 return printf ("%5ld", vma);
469 else
470 return printf ("%#lx", vma);
471#else
472 if (vma <= 99999)
473 return printf ("%5ld", _bfd_int64_low (vma));
474 else
475 return print_hex_vma (vma);
476#endif
477
478 case UNSIGNED:
479#if BFD_HOST_64BIT_LONG1
480 return printf ("%lu", vma);
481#else
482 return print_dec_vma (vma, 0);
483#endif
484 }
485 }
486#endif
487 return 0;
488}
489
490/* Display a symbol on stdout. If do_wide is not true then
491 format the symbol to be at most WIDTH characters,
492 truncating as necessary. If WIDTH is negative then
493 format the string to be exactly - WIDTH characters,
494 truncating or padding as necessary. */
495
496static void
497print_symbol (int width, const char *symbol)
498{
499 if (do_wide)
500 printf ("%s", symbol);
501 else if (width < 0)
502 printf ("%-*.*s", width, width, symbol);
503 else
504 printf ("%-.*s", width, symbol);
505}
506
507static void
508byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
509{
510 switch (size)
511 {
512 case 8:
513 field[7] = value & 0xff;
514 field[6] = (value >> 8) & 0xff;
515 field[5] = (value >> 16) & 0xff;
516 field[4] = (value >> 24) & 0xff;
517 value >>= 16;
518 value >>= 16;
519 /* Fall through. */
520 case 4:
521 field[3] = value & 0xff;
522 field[2] = (value >> 8) & 0xff;
523 value >>= 16;
524 /* Fall through. */
525 case 2:
526 field[1] = value & 0xff;
527 value >>= 8;
528 /* Fall through. */
529 case 1:
530 field[0] = value & 0xff;
531 break;
532
533 default:
534 error (_("Unhandled data length: %d\n")("Unhandled data length: %d\n"), size);
535 abort ();
536 }
537}
538
539/* Return a pointer to section NAME, or NULL if no such section exists. */
540
541static Elf_Internal_Shdr *
542find_section (const char *name)
543{
544 unsigned int i;
545
546 for (i = 0; i < elf_header.e_shnum; i++)
547 if (streq (SECTION_NAME (section_headers + i), name)(strcmp ((((section_headers + i) == ((void*)0) ? "<none>"
: ((section_headers + i)->sh_name >= string_table_length
? "<corrupt>" : string_table + (section_headers + i)->
sh_name))), (name)) == 0)
)
548 return section_headers + i;
549
550 return NULL((void*)0);
551}
552
553/* Guess the relocation size commonly used by the specific machines. */
554
555static int
556guess_is_rela (unsigned long e_machine)
557{
558 switch (e_machine)
559 {
560 /* Targets that use REL relocations. */
561 case EM_ARM40:
562 case EM_3863:
563 case EM_4866:
564 case EM_96019:
565 case EM_DLX0x5aa5:
566 case EM_OPENRISC92:
567 case EM_OR320x8472:
568 case EM_CYGNUS_M32R0x9041:
569 case EM_D10V85:
570 case EM_CYGNUS_D10V0x7650:
571 case EM_MIPS8:
572 case EM_MIPS_RS3_LE10:
573 return FALSE0;
574
575 /* Targets that use RELA relocations. */
576 case EM_68K4:
577 case EM_H8_30046:
578 case EM_H8_300H47:
579 case EM_H8S48:
580 case EM_SPARC32PLUS18:
581 case EM_SPARCV943:
582 case EM_SPARC2:
583 case EM_PPC20:
584 case EM_PPC6421:
585 case EM_V85087:
586 case EM_CYGNUS_V8500x9080:
587 case EM_D30V86:
588 case EM_CYGNUS_D30V0x7676:
589 case EM_MN1020090:
590 case EM_CYGNUS_MN102000xdead:
591 case EM_MN1030089:
592 case EM_CYGNUS_MN103000xbeef:
593 case EM_FR3084:
594 case EM_CYGNUS_FR300x3330:
595 case EM_CYGNUS_FRV0x5441:
596 case EM_SH42:
597 case EM_ALPHA0x9026:
598 case EM_MCORE39:
599 case EM_IA_6450:
600 case EM_AVR83:
601 case EM_AVR_OLD0x1057:
602 case EM_CRIS76:
603 case EM_8607:
604 case EM_X86_6462:
605 case EM_S39022:
606 case EM_S390_OLD0xa390:
607 case EM_MMIX80:
608 case EM_MSP430105:
609 case EM_MSP430_OLD0x1059:
610 case EM_XSTORMY160xad45:
611 case EM_CRX114:
612 case EM_VAX75:
613 case EM_IP2K101:
614 case EM_IP2K_OLD0x8217:
615 case EM_IQ20000xFEBA:
616 case EM_XTENSA94:
617 case EM_XTENSA_OLD0xabc7:
618 case EM_M32R88:
619 case EM_M32C0xFEB0:
620 case EM_MT0x2530:
621 case EM_BLACKFIN106:
622 case EM_NIOS320xFEBB:
623 case EM_ALTERA_NIOS2113:
624 case EM_88K5:
625 case EM_AARCH64183:
626 case EM_RISCV243:
627 return TRUE1;
628
629 case EM_MMA54:
630 case EM_PCP55:
631 case EM_NCPU56:
632 case EM_NDR157:
633 case EM_STARCORE58:
634 case EM_ME1659:
635 case EM_ST10060:
636 case EM_TINYJ61:
637 case EM_FX6666:
638 case EM_ST9PLUS67:
639 case EM_ST768:
640 case EM_68HC1669:
641 case EM_68HC1170:
642 case EM_68HC0871:
643 case EM_68HC0572:
644 case EM_SVX73:
645 case EM_ST1974:
646 default:
647 warn (_("Don't know about relocations on this machine architecture\n")("Don't know about relocations on this machine architecture\n"
)
);
648 return FALSE0;
649 }
650}
651
652static int
653slurp_rela_relocs (FILE *file,
654 unsigned long rel_offset,
655 unsigned long rel_size,
656 Elf_Internal_Rela **relasp,
657 unsigned long *nrelasp)
658{
659 Elf_Internal_Rela *relas;
660 unsigned long nrelas;
661 unsigned int i;
662
663 if (is_32bit_elf)
664 {
665 Elf32_External_Rela *erelas;
666
667 erelas = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
668 if (!erelas)
669 return 0;
670
671 nrelas = rel_size / sizeof (Elf32_External_Rela);
672
673 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
674
675 if (relas == NULL((void*)0))
676 {
677 free (erelas);
678 error (_("out of memory parsing relocs")("out of memory parsing relocs"));
679 return 0;
680 }
681
682 for (i = 0; i < nrelas; i++)
683 {
684 relas[i].r_offset = BYTE_GET (erelas[i].r_offset)byte_get (erelas[i].r_offset, sizeof (erelas[i].r_offset));
685 relas[i].r_info = BYTE_GET (erelas[i].r_info)byte_get (erelas[i].r_info, sizeof (erelas[i].r_info));
686 relas[i].r_addend = BYTE_GET (erelas[i].r_addend)byte_get (erelas[i].r_addend, sizeof (erelas[i].r_addend));
687 }
688
689 free (erelas);
690 }
691 else
692 {
693 Elf64_External_Rela *erelas;
694
695 erelas = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
696 if (!erelas)
697 return 0;
698
699 nrelas = rel_size / sizeof (Elf64_External_Rela);
700
701 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
702
703 if (relas == NULL((void*)0))
704 {
705 free (erelas);
706 error (_("out of memory parsing relocs")("out of memory parsing relocs"));
707 return 0;
708 }
709
710 for (i = 0; i < nrelas; i++)
711 {
712 relas[i].r_offset = BYTE_GET (erelas[i].r_offset)byte_get (erelas[i].r_offset, sizeof (erelas[i].r_offset));
713 relas[i].r_info = BYTE_GET (erelas[i].r_info)byte_get (erelas[i].r_info, sizeof (erelas[i].r_info));
714 relas[i].r_addend = BYTE_GET (erelas[i].r_addend)byte_get (erelas[i].r_addend, sizeof (erelas[i].r_addend));
715 }
716
717 free (erelas);
718 }
719 *relasp = relas;
720 *nrelasp = nrelas;
721 return 1;
722}
723
724static int
725slurp_rel_relocs (FILE *file,
726 unsigned long rel_offset,
727 unsigned long rel_size,
728 Elf_Internal_Rela **relsp,
729 unsigned long *nrelsp)
730{
731 Elf_Internal_Rela *rels;
732 unsigned long nrels;
733 unsigned int i;
734
735 if (is_32bit_elf)
736 {
737 Elf32_External_Rel *erels;
738
739 erels = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
740 if (!erels)
741 return 0;
742
743 nrels = rel_size / sizeof (Elf32_External_Rel);
744
745 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
746
747 if (rels == NULL((void*)0))
748 {
749 free (erels);
750 error (_("out of memory parsing relocs")("out of memory parsing relocs"));
751 return 0;
752 }
753
754 for (i = 0; i < nrels; i++)
755 {
756 rels[i].r_offset = BYTE_GET (erels[i].r_offset)byte_get (erels[i].r_offset, sizeof (erels[i].r_offset));
757 rels[i].r_info = BYTE_GET (erels[i].r_info)byte_get (erels[i].r_info, sizeof (erels[i].r_info));
758 rels[i].r_addend = 0;
759 }
760
761 free (erels);
762 }
763 else
764 {
765 Elf64_External_Rel *erels;
766
767 erels = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
768 if (!erels)
769 return 0;
770
771 nrels = rel_size / sizeof (Elf64_External_Rel);
772
773 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
774
775 if (rels == NULL((void*)0))
776 {
777 free (erels);
778 error (_("out of memory parsing relocs")("out of memory parsing relocs"));
779 return 0;
780 }
781
782 for (i = 0; i < nrels; i++)
783 {
784 rels[i].r_offset = BYTE_GET (erels[i].r_offset)byte_get (erels[i].r_offset, sizeof (erels[i].r_offset));
785 rels[i].r_info = BYTE_GET (erels[i].r_info)byte_get (erels[i].r_info, sizeof (erels[i].r_info));
786 rels[i].r_addend = 0;
787 }
788
789 free (erels);
790 }
791 *relsp = rels;
792 *nrelsp = nrels;
793 return 1;
794}
795
796static int
797dump_raw_relr (FILE *file,
798 unsigned long rel_offset,
799 unsigned long rel_size)
800{
801 unsigned long nrels;
802 unsigned int i;
803
804 printf (_(" at offset 0x%lx contains %lu entries:\n")(" at offset 0x%lx contains %lu entries:\n"),
805 rel_offset, (unsigned long) (rel_size / (is_32bit_elf ? 4 : 8)));
806 printf (" Data\n");
807
808 if (is_32bit_elf)
809 {
810 Elf32_External_Relr *erels;
811
812 erels = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
813 if (!erels)
814 return 0;
815
816 nrels = rel_size / sizeof (Elf32_External_Relr);
817
818 for (i = 0; i < nrels; i++)
819 {
820 bfd_vma val = BYTE_GET (erels[i])byte_get (erels[i], sizeof (erels[i]));
821#ifdef _bfd_int64_low
822 printf ("%8.8lx\n", _bfd_int64_low (val));
823#else
824 printf ("%8.8lx\n", val);
825#endif
826 }
827
828 free (erels);
829 }
830 else
831 {
832 Elf64_External_Relr *erels;
833
834 erels = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
835 if (!erels)
836 return 0;
837
838 nrels = rel_size / sizeof (Elf64_External_Relr);
839
840 for (i = 0; i < nrels; i++)
841 {
842 bfd_vma val = BYTE_GET (erels[i])byte_get (erels[i], sizeof (erels[i]));
843#ifdef _bfd_int64_low
844 printf ("%8.8lx%8.8lx\n", _bfd_int64_high (val), _bfd_int64_low (val));
845#else
846 printf ("%16.16lx\n", val);
847#endif
848 }
849
850 free (erels);
851 }
852
853 return 1;
854}
855
856static int
857slurp_relr_relocs (FILE *file,
858 unsigned long rel_offset,
859 unsigned long rel_size,
860 Elf_Internal_Rela **relsp,
861 unsigned long *nrelsp)
862{
863 Elf_Internal_Rela *rels;
864 unsigned long nrels;
865 unsigned int i, j;
866 bfd_vma base = 0;
867 int type;
868
869 switch (elf_header.e_machine)
870 {
871 default:
872 type = 0;
873 break;
874
875 case EM_3863:
876 case EM_4866:
877 type = 8; /* R_386_RELATIVE */
878 break;
879
880 case EM_OLD_SPARCV911:
881 case EM_SPARC32PLUS18:
882 case EM_SPARCV943:
883 case EM_SPARC2:
884 type = 22; /* R_SPARC_RELATIVE */
885 break;
886
887 case EM_SH42:
888 type = is_32bit_elf ? 165 : 196; /* R_SH_RELATIVE : R_SH_RELATIVE64 */
889 break;
890
891 case EM_PPC20:
892 type = 22; /* R_PPC_RELATIVE */
893 break;
894
895 case EM_PPC6421:
896 type = 22; /* R_PPC64_RELATIVE */
897 break;
898
899 case EM_ALPHA0x9026:
900 type = 27; /* R_ALPHA_RELATIVE */
901 break;
902
903 case EM_ARM40:
904 type = 23; /* R_ARM_RELATIVE */
905 break;
906
907 case EM_PARISC15:
908 type = 1; /* R_PARISC_DIR32 XXX */
909 break;
910
911 case EM_X86_6462:
912 type = 8; /* R_X86_64_RELATIVE */
913 break;
914
915 case EM_88K5:
916 type = 16; /* R_88K_BBASED_32 */
917 break;
918
919 case EM_AARCH64183:
920 type = 1027; /* R_AARCH64_RELATIVE */
921 break;
922
923 case EM_RISCV243:
924 type = 3; /* R_RISCV_RELATIVE */
925 break;
926 }
927
928 if (is_32bit_elf)
929 {
930 Elf32_External_Relr *erels;
931
932 erels = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
933 if (!erels)
934 return 0;
935
936 nrels = rel_size / sizeof (Elf32_External_Relr);
937
938 for (i = j = 0; i < nrels; i++)
939 {
940 bfd_vma val = BYTE_GET (erels[i])byte_get (erels[i], sizeof (erels[i]));
941 if ((val & 1) == 0)
942 {
943 j++;
944 continue;
945 }
946 while ((val >>= 1) != 0)
947 if (val & 1)
948 j++;
949 }
950
951 rels = cmalloc (j, sizeof (Elf_Internal_Rela));
952
953 if (rels == NULL((void*)0))
954 {
955 free (erels);
956 error (_("out of memory parsing relocs")("out of memory parsing relocs"));
957 return 0;
958 }
959
960 for (i = j = 0; i < nrels; i++)
961 {
962 bfd_vma val = BYTE_GET (erels[i])byte_get (erels[i], sizeof (erels[i]));
963 if ((val & 1) == 0)
964 {
965 base = val;
966 rels[j].r_offset = val;
967 rels[j].r_info = ELF32_R_INFO(0, type)(((0) << 8) + ((type) & 0xff));
968 rels[j].r_addend = 0;
969 j++;
970 }
971 else
972 {
973 bfd_vma addr = base;
974 base += 4 * 31;
975
976 while ((val >>= 1) != 0)
977 {
978 addr += 4;
979 if (val & 1)
980 {
981 rels[j].r_offset = addr;
982 rels[j].r_info = ELF32_R_INFO(0, type)(((0) << 8) + ((type) & 0xff));
983 rels[j].r_addend = 0;
984 j++;
985 }
986 }
987 }
988 }
989
990 free (erels);
991 }
992 else
993 {
994 Elf64_External_Relr *erels;
995
996 erels = get_data (NULL((void*)0), file, rel_offset, 1, rel_size, _("relocs")("relocs"));
997 if (!erels)
998 return 0;
999
1000 nrels = rel_size / sizeof (Elf64_External_Relr);
1001
1002 for (i = j = 0; i < nrels; i++)
1003 {
1004 bfd_vma val = BYTE_GET (erels[i])byte_get (erels[i], sizeof (erels[i]));
1005 if ((val & 1) == 0)
1006 {
1007 j++;
1008 continue;
1009 }
1010 while ((val >>= 1) != 0)
1011 if (val & 1)
1012 j++;
1013 }
1014
1015 rels = cmalloc (j, sizeof (Elf_Internal_Rela));
1016
1017 if (rels == NULL((void*)0))
1018 {
1019 free (erels);
1020 error (_("out of memory parsing relocs")("out of memory parsing relocs"));
1021 return 0;
1022 }
1023
1024
1025 for (i = j = 0; i < nrels; i++)
1026 {
1027 bfd_vma val = BYTE_GET (erels[i])byte_get (erels[i], sizeof (erels[i]));
1028 if ((val & 1) == 0)
1029 {
1030 base = val;
1031 rels[j].r_offset = val;
1032 rels[j].r_info = ELF64_R_INFO(0, type)(((bfd_vma) (0) << 31 << 1) + (bfd_vma) (type));
1033 rels[j].r_addend = 0;
1034 j++;
1035 }
1036 else
1037 {
1038 bfd_vma addr = base;
1039 base += 8 * 63;
1040
1041 while ((val >>= 1) != 0)
1042 {
1043 addr += 8;
1044 if (val & 1)
1045 {
1046 rels[j].r_offset = addr;
1047 rels[j].r_info = ELF64_R_INFO(0, type)(((bfd_vma) (0) << 31 << 1) + (bfd_vma) (type));
1048 rels[j].r_addend = 0;
1049 j++;
1050 }
1051 }
1052 }
1053 }
1054
1055 free (erels);
1056 }
1057
1058 *relsp = rels;
1059 *nrelsp = j;
1060 return 1;
1061}
1062
1063/* Display the contents of the relocation data found at the specified
1064 offset. */
1065
1066static int
1067dump_relocations (FILE *file,
1068 unsigned long rel_offset,
1069 unsigned long rel_size,
1070 Elf_Internal_Sym *symtab,
1071 unsigned long nsyms,
1072 char *strtab,
1073 unsigned long strtablen,
1074 int is_rela)
1075{
1076 unsigned int i;
1077 Elf_Internal_Rela *rels;
1078
1079 if (is_rela == UNKNOWN-1)
1080 is_rela = guess_is_rela (elf_header.e_machine);
1081
1082 if (is_rela == RELR-2)
1083 {
1084 if (do_raw_relr && ! do_using_dynamic)
1085 return dump_raw_relr (file, rel_offset, rel_size);
1086 if (!slurp_relr_relocs (file, rel_offset, rel_size, &rels, &rel_size))
1087 return 0;
1088 if (! do_using_dynamic)
1089 printf (_(" at offset 0x%lx contains %lu entries:\n")(" at offset 0x%lx contains %lu entries:\n"),
1090 rel_offset, rel_size);
1091 }
1092 else if (is_rela)
1093 {
1094 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
1095 return 0;
1096 }
1097 else
1098 {
1099 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
1100 return 0;
1101 }
1102
1103 if (is_32bit_elf)
1104 {
1105 if (is_rela > 0)
1106 {
1107 if (do_wide)
1108 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n")(" Offset Info Type Sym. Value Symbol's Name + Addend\n"
)
);
1109 else
1110 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n")(" Offset Info Type Sym.Value Sym. Name + Addend\n"
)
);
1111 }
1112 else
1113 {
1114 if (do_wide)
1115 printf (_(" Offset Info Type Sym. Value Symbol's Name\n")(" Offset Info Type Sym. Value Symbol's Name\n"
)
);
1116 else
1117 printf (_(" Offset Info Type Sym.Value Sym. Name\n")(" Offset Info Type Sym.Value Sym. Name\n"
)
);
1118 }
1119 }
1120 else
1121 {
1122 if (is_rela > 0)
1123 {
1124 if (do_wide)
1125 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n")(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"
)
);
1126 else
1127 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n")(" Offset Info Type Sym. Value Sym. Name + Addend\n"
)
);
1128 }
1129 else
1130 {
1131 if (do_wide)
1132 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n")(" Offset Info Type Symbol's Value Symbol's Name\n"
)
);
1133 else
1134 printf (_(" Offset Info Type Sym. Value Sym. Name\n")(" Offset Info Type Sym. Value Sym. Name\n"
)
);
1135 }
1136 }
1137
1138 for (i = 0; i < rel_size; i++)
1139 {
1140 const char *rtype;
1141 const char *rtype2 = NULL((void*)0);
1142 const char *rtype3 = NULL((void*)0);
1143 bfd_vma offset;
1144 bfd_vma info;
1145 bfd_vma symtab_index;
1146 bfd_vma type;
1147 bfd_vma type2 = 0;
1148 bfd_vma type3 = 0;
1149
1150 offset = rels[i].r_offset;
1151 info = rels[i].r_info;
1152
1153 if (is_32bit_elf)
1154 {
1155 type = ELF32_R_TYPE (info)((info) & 0xff);
1156 symtab_index = ELF32_R_SYM (info)((info) >> 8);
1157 }
1158 else
1159 {
1160 /* The #ifdef BFD64 below is to prevent a compile time warning.
1161 We know that if we do not have a 64 bit data type that we
1162 will never execute this code anyway. */
1163#ifdef BFD64
1164 if (elf_header.e_machine == EM_MIPS8)
1165 {
1166 /* In little-endian objects, r_info isn't really a 64-bit
1167 little-endian value: it has a 32-bit little-endian
1168 symbol index followed by four individual byte fields.
1169 Reorder INFO accordingly. */
1170 if (elf_header.e_ident[EI_DATA5] != ELFDATA2MSB2)
1171 info = (((info & 0xffffffff) << 32)
1172 | ((info >> 56) & 0xff)
1173 | ((info >> 40) & 0xff00)
1174 | ((info >> 24) & 0xff0000)
1175 | ((info >> 8) & 0xff000000));
1176 type = ELF64_MIPS_R_TYPE (info)((info) & 0xff);
1177 type2 = ELF64_MIPS_R_TYPE2 (info)(((info) >> 8) & 0xff);
1178 type3 = ELF64_MIPS_R_TYPE3 (info)(((info) >> 16) & 0xff);
1179 }
1180 else if (elf_header.e_machine == EM_SPARCV943)
1181 type = ELF64_R_TYPE_ID (info)((info) & 0xff);
1182 else
1183 type = ELF64_R_TYPE (info)((info) & 0xffffffff);
1184
1185 symtab_index = ELF64_R_SYM (info)((info) >> 32);
1186#endif
1187 }
1188
1189 if (is_32bit_elf)
1190 {
1191#ifdef _bfd_int64_low
1192 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
1193#else
1194 printf ("%8.8lx %8.8lx ", offset, info);
1195#endif
1196 }
1197 else
1198 {
1199#ifdef _bfd_int64_low
1200 printf (do_wide
1201 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1202 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1203 _bfd_int64_high (offset),
1204 _bfd_int64_low (offset),
1205 _bfd_int64_high (info),
1206 _bfd_int64_low (info));
1207#else
1208 printf (do_wide
1209 ? "%16.16lx %16.16lx "
1210 : "%12.12lx %12.12lx ",
1211 offset, info);
1212#endif
1213 }
1214
1215 switch (elf_header.e_machine)
1216 {
1217 default:
1218 rtype = NULL((void*)0);
1219 break;
1220
1221 case EM_M32R88:
1222 case EM_CYGNUS_M32R0x9041:
1223 rtype = elf_m32r_reloc_type (type);
1224 break;
1225
1226 case EM_3863:
1227 case EM_4866:
1228 rtype = elf_i386_reloc_type (type);
1229 break;
1230
1231 case EM_68HC1170:
1232 case EM_68HC1253:
1233 rtype = elf_m68hc11_reloc_type (type);
1234 break;
1235
1236 case EM_68K4:
1237 rtype = elf_m68k_reloc_type (type);
1238 break;
1239
1240 case EM_96019:
1241 rtype = elf_i960_reloc_type (type);
1242 break;
1243
1244 case EM_AVR83:
1245 case EM_AVR_OLD0x1057:
1246 rtype = elf_avr_reloc_type (type);
1247 break;
1248
1249 case EM_OLD_SPARCV911:
1250 case EM_SPARC32PLUS18:
1251 case EM_SPARCV943:
1252 case EM_SPARC2:
1253 rtype = elf_sparc_reloc_type (type);
1254 break;
1255
1256 case EM_V85087:
1257 case EM_CYGNUS_V8500x9080:
1258 rtype = v850_reloc_type (type);
1259 break;
1260
1261 case EM_D10V85:
1262 case EM_CYGNUS_D10V0x7650:
1263 rtype = elf_d10v_reloc_type (type);
1264 break;
1265
1266 case EM_D30V86:
1267 case EM_CYGNUS_D30V0x7676:
1268 rtype = elf_d30v_reloc_type (type);
1269 break;
1270
1271 case EM_DLX0x5aa5:
1272 rtype = elf_dlx_reloc_type (type);
1273 break;
1274
1275 case EM_SH42:
1276 rtype = elf_sh_reloc_type (type);
1277 break;
1278
1279 case EM_MN1030089:
1280 case EM_CYGNUS_MN103000xbeef:
1281 rtype = elf_mn10300_reloc_type (type);
1282 break;
1283
1284 case EM_MN1020090:
1285 case EM_CYGNUS_MN102000xdead:
1286 rtype = elf_mn10200_reloc_type (type);
1287 break;
1288
1289 case EM_FR3084:
1290 case EM_CYGNUS_FR300x3330:
1291 rtype = elf_fr30_reloc_type (type);
1292 break;
1293
1294 case EM_CYGNUS_FRV0x5441:
1295 rtype = elf_frv_reloc_type (type);
1296 break;
1297
1298 case EM_MCORE39:
1299 rtype = elf_mcore_reloc_type (type);
1300 break;
1301
1302 case EM_MMIX80:
1303 rtype = elf_mmix_reloc_type (type);
1304 break;
1305
1306 case EM_MSP430105:
1307 case EM_MSP430_OLD0x1059:
1308 rtype = elf_msp430_reloc_type (type);
1309 break;
1310
1311 case EM_PPC20:
1312 rtype = elf_ppc_reloc_type (type);
1313 break;
1314
1315 case EM_PPC6421:
1316 rtype = elf_ppc64_reloc_type (type);
1317 break;
1318
1319 case EM_MIPS8:
1320 case EM_MIPS_RS3_LE10:
1321 rtype = elf_mips_reloc_type (type);
1322 if (!is_32bit_elf)
1323 {
1324 rtype2 = elf_mips_reloc_type (type2);
1325 rtype3 = elf_mips_reloc_type (type3);
1326 }
1327 break;
1328
1329 case EM_ALPHA0x9026:
1330 rtype = elf_alpha_reloc_type (type);
1331 break;
1332
1333 case EM_ARM40:
1334 rtype = elf_arm_reloc_type (type);
1335 break;
1336
1337 case EM_ARC45:
1338 rtype = elf_arc_reloc_type (type);
1339 break;
1340
1341 case EM_PARISC15:
1342 rtype = elf_hppa_reloc_type (type);
1343 break;
1344
1345 case EM_H8_30046:
1346 case EM_H8_300H47:
1347 case EM_H8S48:
1348 rtype = elf_h8_reloc_type (type);
1349 break;
1350
1351 case EM_OPENRISC92:
1352 case EM_OR320x8472:
1353 rtype = elf_or32_reloc_type (type);
1354 break;
1355
1356 case EM_PJ91:
1357 case EM_PJ_OLD99:
1358 rtype = elf_pj_reloc_type (type);
1359 break;
1360 case EM_IA_6450:
1361 rtype = elf_ia64_reloc_type (type);
1362 break;
1363
1364 case EM_CRIS76:
1365 rtype = elf_cris_reloc_type (type);
1366 break;
1367
1368 case EM_8607:
1369 rtype = elf_i860_reloc_type (type);
1370 break;
1371
1372 case EM_X86_6462:
1373 rtype = elf_x86_64_reloc_type (type);
1374 break;
1375
1376 case EM_S3709:
1377 rtype = i370_reloc_type (type);
1378 break;
1379
1380 case EM_S390_OLD0xa390:
1381 case EM_S39022:
1382 rtype = elf_s390_reloc_type (type);
1383 break;
1384
1385 case EM_XSTORMY160xad45:
1386 rtype = elf_xstormy16_reloc_type (type);
1387 break;
1388
1389 case EM_CRX114:
1390 rtype = elf_crx_reloc_type (type);
1391 break;
1392
1393 case EM_VAX75:
1394 rtype = elf_vax_reloc_type (type);
1395 break;
1396
1397 case EM_IP2K101:
1398 case EM_IP2K_OLD0x8217:
1399 rtype = elf_ip2k_reloc_type (type);
1400 break;
1401
1402 case EM_IQ20000xFEBA:
1403 rtype = elf_iq2000_reloc_type (type);
1404 break;
1405
1406 case EM_XTENSA_OLD0xabc7:
1407 case EM_XTENSA94:
1408 rtype = elf_xtensa_reloc_type (type);
1409 break;
1410
1411 case EM_M32C0xFEB0:
1412 rtype = elf_m32c_reloc_type (type);
1413 break;
1414
1415 case EM_MT0x2530:
1416 rtype = elf_mt_reloc_type (type);
1417 break;
1418
1419 case EM_BLACKFIN106:
1420 rtype = elf_bfin_reloc_type (type);
1421 break;
1422
1423 case EM_88K5:
1424 rtype = elf_m88k_reloc_type (type);
1425 break;
1426
1427 case EM_AARCH64183:
1428 rtype = elf_aarch64_reloc_type (type);
1429 break;
1430
1431 case EM_RISCV243:
1432 rtype = elf_riscv_reloc_type (type);
1433 break;
1434 }
1435
1436 if (rtype == NULL((void*)0))
1437#ifdef _bfd_int64_low
1438 printf (_("unrecognized: %-7lx")("unrecognized: %-7lx"), _bfd_int64_low (type));
1439#else
1440 printf (_("unrecognized: %-7lx")("unrecognized: %-7lx"), type);
1441#endif
1442 else
1443 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1444
1445 if (elf_header.e_machine == EM_ALPHA0x9026
1446 && streq (rtype, "R_ALPHA_LITUSE")(strcmp ((rtype), ("R_ALPHA_LITUSE")) == 0)
1447 && is_rela > 1)
1448 {
1449 switch (rels[i].r_addend)
1450 {
1451 case LITUSE_ALPHA_ADDR0: rtype = "ADDR"; break;
1452 case LITUSE_ALPHA_BASE1: rtype = "BASE"; break;
1453 case LITUSE_ALPHA_BYTOFF2: rtype = "BYTOFF"; break;
1454 case LITUSE_ALPHA_JSR3: rtype = "JSR"; break;
1455 case LITUSE_ALPHA_TLSGD4: rtype = "TLSGD"; break;
1456 case LITUSE_ALPHA_TLSLDM5: rtype = "TLSLDM"; break;
1457 case LITUSE_ALPHA_JSRDIRECT6: rtype = "JSRDIRECT"; break;
1458 default: rtype = NULL((void*)0);
1459 }
1460 if (rtype)
1461 printf (" (%s)", rtype);
1462 else
1463 {
1464 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
1465 printf (_("<unknown addend: %lx>")("<unknown addend: %lx>"),
1466 (unsigned long) rels[i].r_addend);
1467 }
1468 }
1469 else if (symtab_index)
1470 {
1471 if (symtab == NULL((void*)0) || symtab_index >= nsyms)
1472 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1473 else
1474 {
1475 Elf_Internal_Sym *psym;
1476
1477 psym = symtab + symtab_index;
1478
1479 printf (" ");
1480 print_vma (psym->st_value, LONG_HEX);
1481 printf (is_32bit_elf ? " " : " ");
1482
1483 if (psym->st_name == 0)
1484 {
1485 const char *sec_name = "<null>";
1486 char name_buf[40];
1487
1488 if (ELF_ST_TYPE (psym->st_info)((psym->st_info) & 0xF) == STT_SECTION3)
1489 {
1490 bfd_vma sec_index = (bfd_vma) -1;
1491
1492 if (psym->st_shndx < SHN_LORESERVE0xFF00)
1493 sec_index = psym->st_shndx;
1494 else if (psym->st_shndx > SHN_HIRESERVE0xFFFF)
1495 sec_index = psym->st_shndx - (SHN_HIRESERVE0xFFFF + 1
1496 - SHN_LORESERVE0xFF00);
1497
1498 if (sec_index != (bfd_vma) -1)
1499 sec_name = SECTION_NAME (section_headers + sec_index)((section_headers + sec_index) == ((void*)0) ? "<none>"
: ((section_headers + sec_index)->sh_name >= string_table_length
? "<corrupt>" : string_table + (section_headers + sec_index
)->sh_name))
;
1500 else if (psym->st_shndx == SHN_ABS0xFFF1)
1501 sec_name = "ABS";
1502 else if (psym->st_shndx == SHN_COMMON0xFFF2)
1503 sec_name = "COMMON";
1504 else if (elf_header.e_machine == EM_X86_6462
1505 && psym->st_shndx == SHN_X86_64_LCOMMON0xff02)
1506 sec_name = "LARGE_COMMON";
1507 else if (elf_header.e_machine == EM_IA_6450
1508 && elf_header.e_ident[EI_OSABI7] == ELFOSABI_HPUX1
1509 && psym->st_shndx == SHN_IA_64_ANSI_COMMON0xFF00)
1510 sec_name = "ANSI_COM";
1511 else
1512 {
1513 sprintf (name_buf, "<section 0x%x>",
1514 (unsigned int) psym->st_shndx);
1515 sec_name = name_buf;
1516 }
1517 }
1518 print_symbol (22, sec_name);
1519 }
1520 else if (strtab == NULL((void*)0))
1521 printf (_("<string table index: %3ld>")("<string table index: %3ld>"), psym->st_name);
1522 else if (psym->st_name >= strtablen)
1523 printf (_("<corrupt string table index: %3ld>")("<corrupt string table index: %3ld>"), psym->st_name);
1524 else
1525 print_symbol (22, strtab + psym->st_name);
1526
1527 if (is_rela)
1528 printf (" + %lx", (unsigned long) rels[i].r_addend);
1529 }
1530 }
1531 else if (is_rela > 1)
1532 {
1533 printf ("%*c", is_32bit_elf ?
1534 (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1535 print_vma (rels[i].r_addend, LONG_HEX);
1536 }
1537
1538 if (elf_header.e_machine == EM_SPARCV943 && streq (rtype, "R_SPARC_OLO10")(strcmp ((rtype), ("R_SPARC_OLO10")) == 0))
1539 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info)(((bfd_signed_vma)(((info) & 0xffffffff) >> 8) ^ 0x800000
) - 0x800000)
);
1540
1541 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
1542
1543 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS8)
1544 {
1545 printf (" Type2: ");
1546
1547 if (rtype2 == NULL((void*)0))
1548#ifdef _bfd_int64_low
1549 printf (_("unrecognized: %-7lx")("unrecognized: %-7lx"), _bfd_int64_low (type2));
1550#else
1551 printf (_("unrecognized: %-7lx")("unrecognized: %-7lx"), type2);
1552#endif
1553 else
1554 printf ("%-17.17s", rtype2);
1555
1556 printf ("\n Type3: ");
1557
1558 if (rtype3 == NULL((void*)0))
1559#ifdef _bfd_int64_low
1560 printf (_("unrecognized: %-7lx")("unrecognized: %-7lx"), _bfd_int64_low (type3));
1561#else
1562 printf (_("unrecognized: %-7lx")("unrecognized: %-7lx"), type3);
1563#endif
1564 else
1565 printf ("%-17.17s", rtype3);
1566
1567 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
1568 }
1569 }
1570
1571 free (rels);
1572
1573 return 1;
1574}
1575
1576static const char *
1577get_mips_dynamic_type (unsigned long type)
1578{
1579 switch (type)
1580 {
1581 case DT_MIPS_RLD_VERSION0x70000001: return "MIPS_RLD_VERSION";
1582 case DT_MIPS_TIME_STAMP0x70000002: return "MIPS_TIME_STAMP";
1583 case DT_MIPS_ICHECKSUM0x70000003: return "MIPS_ICHECKSUM";
1584 case DT_MIPS_IVERSION0x70000004: return "MIPS_IVERSION";
1585 case DT_MIPS_FLAGS0x70000005: return "MIPS_FLAGS";
1586 case DT_MIPS_BASE_ADDRESS0x70000006: return "MIPS_BASE_ADDRESS";
1587 case DT_MIPS_MSYM0x70000007: return "MIPS_MSYM";
1588 case DT_MIPS_CONFLICT0x70000008: return "MIPS_CONFLICT";
1589 case DT_MIPS_LIBLIST0x70000009: return "MIPS_LIBLIST";
1590 case DT_MIPS_LOCAL_GOTNO0x7000000a: return "MIPS_LOCAL_GOTNO";
1591 case DT_MIPS_CONFLICTNO0x7000000b: return "MIPS_CONFLICTNO";
1592 case DT_MIPS_LIBLISTNO0x70000010: return "MIPS_LIBLISTNO";
1593 case DT_MIPS_SYMTABNO0x70000011: return "MIPS_SYMTABNO";
1594 case DT_MIPS_UNREFEXTNO0x70000012: return "MIPS_UNREFEXTNO";
1595 case DT_MIPS_GOTSYM0x70000013: return "MIPS_GOTSYM";
1596 case DT_MIPS_HIPAGENO0x70000014: return "MIPS_HIPAGENO";
1597 case DT_MIPS_RLD_MAP0x70000016: return "MIPS_RLD_MAP";
1598 case DT_MIPS_DELTA_CLASS0x70000017: return "MIPS_DELTA_CLASS";
1599 case DT_MIPS_DELTA_CLASS_NO0x70000018: return "MIPS_DELTA_CLASS_NO";
1600 case DT_MIPS_DELTA_INSTANCE0x70000019: return "MIPS_DELTA_INSTANCE";
1601 case DT_MIPS_DELTA_INSTANCE_NO0x7000001a: return "MIPS_DELTA_INSTANCE_NO";
1602 case DT_MIPS_DELTA_RELOC0x7000001b: return "MIPS_DELTA_RELOC";
1603 case DT_MIPS_DELTA_RELOC_NO0x7000001c: return "MIPS_DELTA_RELOC_NO";
1604 case DT_MIPS_DELTA_SYM0x7000001d: return "MIPS_DELTA_SYM";
1605 case DT_MIPS_DELTA_SYM_NO0x7000001e: return "MIPS_DELTA_SYM_NO";
1606 case DT_MIPS_DELTA_CLASSSYM0x70000020: return "MIPS_DELTA_CLASSSYM";
1607 case DT_MIPS_DELTA_CLASSSYM_NO0x70000021: return "MIPS_DELTA_CLASSSYM_NO";
1608 case DT_MIPS_CXX_FLAGS0x70000022: return "MIPS_CXX_FLAGS";
1609 case DT_MIPS_PIXIE_INIT0x70000023: return "MIPS_PIXIE_INIT";
1610 case DT_MIPS_SYMBOL_LIB0x70000024: return "MIPS_SYMBOL_LIB";
1611 case DT_MIPS_LOCALPAGE_GOTIDX0x70000025: return "MIPS_LOCALPAGE_GOTIDX";
1612 case DT_MIPS_LOCAL_GOTIDX0x70000026: return "MIPS_LOCAL_GOTIDX";
1613 case DT_MIPS_HIDDEN_GOTIDX0x70000027: return "MIPS_HIDDEN_GOTIDX";
1614 case DT_MIPS_PROTECTED_GOTIDX0x70000028: return "MIPS_PROTECTED_GOTIDX";
1615 case DT_MIPS_OPTIONS0x70000029: return "MIPS_OPTIONS";
1616 case DT_MIPS_INTERFACE0x7000002a: return "MIPS_INTERFACE";
1617 case DT_MIPS_DYNSTR_ALIGN0x7000002b: return "MIPS_DYNSTR_ALIGN";
1618 case DT_MIPS_INTERFACE_SIZE0x7000002c: return "MIPS_INTERFACE_SIZE";
1619 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR0x7000002d: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1620 case DT_MIPS_PERF_SUFFIX0x7000002e: return "MIPS_PERF_SUFFIX";
1621 case DT_MIPS_COMPACT_SIZE0x7000002f: return "MIPS_COMPACT_SIZE";
1622 case DT_MIPS_GP_VALUE0x70000030: return "MIPS_GP_VALUE";
1623 case DT_MIPS_AUX_DYNAMIC0x70000031: return "MIPS_AUX_DYNAMIC";
1624 default:
1625 return NULL((void*)0);
1626 }
1627}
1628
1629static const char *
1630get_sparc64_dynamic_type (unsigned long type)
1631{
1632 switch (type)
1633 {
1634 case DT_SPARC_REGISTER0x70000001: return "SPARC_REGISTER";
1635 default:
1636 return NULL((void*)0);
1637 }
1638}
1639
1640static const char *
1641get_ppc_dynamic_type (unsigned long type)
1642{
1643 switch (type)
1644 {
1645 case DT_PPC_GOT0x70000000: return "PPC_GOT";
1646 default:
1647 return NULL((void*)0);
1648 }
1649}
1650
1651static const char *
1652get_ppc64_dynamic_type (unsigned long type)
1653{
1654 switch (type)
1655 {
1656 case DT_PPC64_GLINK0x70000000: return "PPC64_GLINK";
1657 case DT_PPC64_OPD(0x70000000 + 1): return "PPC64_OPD";
1658 case DT_PPC64_OPDSZ(0x70000000 + 2): return "PPC64_OPDSZ";
1659 default:
1660 return NULL((void*)0);
1661 }
1662}
1663
1664static const char *
1665get_parisc_dynamic_type (unsigned long type)
1666{
1667 switch (type)
1668 {
1669 case DT_HP_LOAD_MAP(0x60000000 + 0x0): return "HP_LOAD_MAP";
1670 case DT_HP_DLD_FLAGS(0x60000000 + 0x1): return "HP_DLD_FLAGS";
1671 case DT_HP_DLD_HOOK(0x60000000 + 0x2): return "HP_DLD_HOOK";
1672 case DT_HP_UX10_INIT(0x60000000 + 0x3): return "HP_UX10_INIT";
1673 case DT_HP_UX10_INITSZ(0x60000000 + 0x4): return "HP_UX10_INITSZ";
1674 case DT_HP_PREINIT(0x60000000 + 0x5): return "HP_PREINIT";
1675 case DT_HP_PREINITSZ(0x60000000 + 0x6): return "HP_PREINITSZ";
1676 case DT_HP_NEEDED(0x60000000 + 0x7): return "HP_NEEDED";
1677 case DT_HP_TIME_STAMP(0x60000000 + 0x8): return "HP_TIME_STAMP";
1678 case DT_HP_CHECKSUM(0x60000000 + 0x9): return "HP_CHECKSUM";
1679 case DT_HP_GST_SIZE(0x60000000 + 0xa): return "HP_GST_SIZE";
1680 case DT_HP_GST_VERSION(0x60000000 + 0xb): return "HP_GST_VERSION";
1681 case DT_HP_GST_HASHVAL(0x60000000 + 0xc): return "HP_GST_HASHVAL";
1682 case DT_HP_EPLTREL(0x60000000 + 0xd): return "HP_GST_EPLTREL";
1683 case DT_HP_EPLTRELSZ(0x60000000 + 0xe): return "HP_GST_EPLTRELSZ";
1684 case DT_HP_FILTERED(0x60000000 + 0xf): return "HP_FILTERED";
1685 case DT_HP_FILTER_TLS(0x60000000 + 0x10): return "HP_FILTER_TLS";
1686 case DT_HP_COMPAT_FILTERED(0x60000000 + 0x11): return "HP_COMPAT_FILTERED";
1687 case DT_HP_LAZYLOAD(0x60000000 + 0x12): return "HP_LAZYLOAD";
1688 case DT_HP_BIND_NOW_COUNT(0x60000000 + 0x13): return "HP_BIND_NOW_COUNT";
1689 case DT_PLT(0x60000000 + 0x14): return "PLT";
1690 case DT_PLT_SIZE(0x60000000 + 0x15): return "PLT_SIZE";
1691 case DT_DLT(0x60000000 + 0x16): return "DLT";
1692 case DT_DLT_SIZE(0x60000000 + 0x17): return "DLT_SIZE";
1693 default:
1694 return NULL((void*)0);
1695 }
1696}
1697
1698static const char *
1699get_ia64_dynamic_type (unsigned long type)
1700{
1701 switch (type)
1702 {
1703 case DT_IA_64_PLT_RESERVE(0x70000000 + 0): return "IA_64_PLT_RESERVE";
1704 default:
1705 return NULL((void*)0);
1706 }
1707}
1708
1709static const char *
1710get_alpha_dynamic_type (unsigned long type)
1711{
1712 switch (type)
1713 {
1714 case DT_ALPHA_PLTRO0x70000000: return "ALPHA_PLTRO";
1715 default:
1716 return NULL((void*)0);
1717 }
1718}
1719
1720static const char *
1721get_m88k_dynamic_type (unsigned long type)
1722{
1723 switch (type)
1724 {
1725 case DT_88K_ADDRBASE0x70000001: return "88K_ADDRBASE";
1726 case DT_88K_PLTSTART0x70000002: return "88K_PLTSTART";
1727 case DT_88K_PLTEND0x70000003: return "88K_PLTEND";
1728 case DT_88K_TDESC0x70000004: return "88K_TDESC";
1729 default:
1730 return NULL((void*)0);
1731 }
1732}
1733
1734static const char *
1735get_dynamic_type (unsigned long type)
1736{
1737 static char buff[64];
1738
1739 switch (type)
1740 {
1741 case DT_NULL0: return "NULL";
1742 case DT_NEEDED1: return "NEEDED";
1743 case DT_PLTRELSZ2: return "PLTRELSZ";
1744 case DT_PLTGOT3: return "PLTGOT";
1745 case DT_HASH4: return "HASH";
1746 case DT_STRTAB5: return "STRTAB";
1747 case DT_SYMTAB6: return "SYMTAB";
1748 case DT_RELA7: return "RELA";
1749 case DT_RELASZ8: return "RELASZ";
1750 case DT_RELAENT9: return "RELAENT";
1751 case DT_STRSZ10: return "STRSZ";
1752 case DT_SYMENT11: return "SYMENT";
1753 case DT_INIT12: return "INIT";
1754 case DT_FINI13: return "FINI";
1755 case DT_SONAME14: return "SONAME";
1756 case DT_RPATH15: return "RPATH";
1757 case DT_SYMBOLIC16: return "SYMBOLIC";
1758 case DT_REL17: return "REL";
1759 case DT_RELSZ18: return "RELSZ";
1760 case DT_RELENT19: return "RELENT";
1761 case DT_PLTREL20: return "PLTREL";
1762 case DT_DEBUG21: return "DEBUG";
1763 case DT_TEXTREL22: return "TEXTREL";
1764 case DT_JMPREL23: return "JMPREL";
1765 case DT_BIND_NOW24: return "BIND_NOW";
1766 case DT_INIT_ARRAY25: return "INIT_ARRAY";
1767 case DT_FINI_ARRAY26: return "FINI_ARRAY";
1768 case DT_INIT_ARRAYSZ27: return "INIT_ARRAYSZ";
1769 case DT_FINI_ARRAYSZ28: return "FINI_ARRAYSZ";
1770 case DT_RUNPATH29: return "RUNPATH";
1771 case DT_FLAGS30: return "FLAGS";
1772
1773 case DT_PREINIT_ARRAY32: return "PREINIT_ARRAY";
1774 case DT_PREINIT_ARRAYSZ33: return "PREINIT_ARRAYSZ";
1775 case DT_RELRSZ35: return "RELRSZ";
1776 case DT_RELR36: return "RELR";
1777 case DT_RELRENT37: return "RELRENT";
1778
1779
1780 case DT_CHECKSUM0x6ffffdf8: return "CHECKSUM";
1781 case DT_PLTPADSZ0x6ffffdf9: return "PLTPADSZ";
1782 case DT_MOVEENT0x6ffffdfa: return "MOVEENT";
1783 case DT_MOVESZ0x6ffffdfb: return "MOVESZ";
1784 case DT_FEATURE0x6ffffdfc: return "FEATURE";
1785 case DT_POSFLAG_10x6ffffdfd: return "POSFLAG_1";
1786 case DT_SYMINSZ0x6ffffdfe: return "SYMINSZ";
1787 case DT_SYMINENT0x6ffffdff: return "SYMINENT"; /* aka VALRNGHI */
1788
1789 case DT_ADDRRNGLO0x6ffffe00: return "ADDRRNGLO";
1790 case DT_CONFIG0x6ffffefa: return "CONFIG";
1791 case DT_DEPAUDIT0x6ffffefb: return "DEPAUDIT";
1792 case DT_AUDIT0x6ffffefc: return "AUDIT";
1793 case DT_PLTPAD0x6ffffefd: return "PLTPAD";
1794 case DT_MOVETAB0x6ffffefe: return "MOVETAB";
1795 case DT_SYMINFO0x6ffffeff: return "SYMINFO"; /* aka ADDRRNGHI */
1796
1797 case DT_VERSYM0x6ffffff0: return "VERSYM";
1798
1799 case DT_TLSDESC_GOT0x6ffffef7: return "TLSDESC_GOT";
1800 case DT_TLSDESC_PLT0x6ffffef6: return "TLSDESC_PLT";
1801 case DT_RELACOUNT0x6ffffff9: return "RELACOUNT";
1802 case DT_RELCOUNT0x6ffffffa: return "RELCOUNT";
1803 case DT_FLAGS_10x6ffffffb: return "FLAGS_1";
1804 case DT_VERDEF0x6ffffffc: return "VERDEF";
1805 case DT_VERDEFNUM0x6ffffffd: return "VERDEFNUM";
1806 case DT_VERNEED0x6ffffffe: return "VERNEED";
1807 case DT_VERNEEDNUM0x6fffffff: return "VERNEEDNUM";
1808
1809 case DT_AUXILIARY0x7ffffffd: return "AUXILIARY";
1810 case DT_USED0x7ffffffe: return "USED";
1811 case DT_FILTER0x7fffffff: return "FILTER";
1812
1813 case DT_GNU_PRELINKED0x6ffffdf5: return "GNU_PRELINKED";
1814 case DT_GNU_CONFLICT0x6ffffef8: return "GNU_CONFLICT";
1815 case DT_GNU_CONFLICTSZ0x6ffffdf6: return "GNU_CONFLICTSZ";
1816 case DT_GNU_LIBLIST0x6ffffef9: return "GNU_LIBLIST";
1817 case DT_GNU_LIBLISTSZ0x6ffffdf7: return "GNU_LIBLISTSZ";
1818 case DT_GNU_HASH0x6ffffef5: return "GNU_HASH";
1819
1820 default:
1821 if ((type >= DT_LOPROC0x70000000) && (type <= DT_HIPROC0x7fffffff))
1822 {
1823 const char *result;
1824
1825 switch (elf_header.e_machine)
1826 {
1827 case EM_MIPS8:
1828 case EM_MIPS_RS3_LE10:
1829 result = get_mips_dynamic_type (type);
1830 break;
1831 case EM_SPARCV943:
1832 result = get_sparc64_dynamic_type (type);
1833 break;
1834 case EM_PPC20:
1835 result = get_ppc_dynamic_type (type);
1836 break;
1837 case EM_PPC6421:
1838 result = get_ppc64_dynamic_type (type);
1839 break;
1840 case EM_IA_6450:
1841 result = get_ia64_dynamic_type (type);
1842 break;
1843 case EM_ALPHA0x9026:
1844 result = get_alpha_dynamic_type (type);
1845 break;
1846 case EM_88K5:
1847 result = get_m88k_dynamic_type (type);
1848 break;
1849 default:
1850 result = NULL((void*)0);
1851 break;
1852 }
1853
1854 if (result != NULL((void*)0))
1855 return result;
1856
1857 snprintf (buff, sizeof (buff), _("Processor Specific: %lx")("Processor Specific: %lx"), type);
1858 }
1859 else if (((type >= DT_LOOS0x6000000d) && (type <= DT_HIOS0x6ffff000))
1860 || (elf_header.e_machine == EM_PARISC15
1861 && (type >= OLD_DT_LOOS0x60000000) && (type <= OLD_DT_HIOS0x6fffffff)))
1862 {
1863 const char *result;
1864
1865 switch (elf_header.e_machine)
1866 {
1867 case EM_PARISC15:
1868 result = get_parisc_dynamic_type (type);
1869 break;
1870 default:
1871 result = NULL((void*)0);
1872 break;
1873 }
1874
1875 if (result != NULL((void*)0))
1876 return result;
1877
1878 snprintf (buff, sizeof (buff), _("Operating System specific: %lx")("Operating System specific: %lx"),
1879 type);
1880 }
1881 else
1882 snprintf (buff, sizeof (buff), _("<unknown>: %lx")("<unknown>: %lx"), type);
1883
1884 return buff;
1885 }
1886}
1887
1888static char *
1889get_file_type (unsigned e_type)
1890{
1891 static char buff[32];
1892
1893 switch (e_type)
1894 {
1895 case ET_NONE0: return _("NONE (None)")("NONE (None)");
1896 case ET_REL1: return _("REL (Relocatable file)")("REL (Relocatable file)");
1897 case ET_EXEC2: return _("EXEC (Executable file)")("EXEC (Executable file)");
1898 case ET_DYN3: return _("DYN (Shared object file)")("DYN (Shared object file)");
1899 case ET_CORE4: return _("CORE (Core file)")("CORE (Core file)");
1900
1901 default:
1902 if ((e_type >= ET_LOPROC0xFF00) && (e_type <= ET_HIPROC0xFFFF))
1903 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)")("Processor Specific: (%x)"), e_type);
1904 else if ((e_type >= ET_LOOS0xFE00) && (e_type <= ET_HIOS0xFEFF))
1905 snprintf (buff, sizeof (buff), _("OS Specific: (%x)")("OS Specific: (%x)"), e_type);
1906 else
1907 snprintf (buff, sizeof (buff), _("<unknown>: %x")("<unknown>: %x"), e_type);
1908 return buff;
1909 }
1910}
1911
1912static char *
1913get_machine_name (unsigned e_machine)
1914{
1915 static char buff[64]; /* XXX */
1916
1917 switch (e_machine)
1918 {
1919 case EM_NONE0: return _("None")("None");
1920 case EM_M321: return "WE32100";
1921 case EM_SPARC2: return "Sparc";
1922 case EM_3863: return "Intel 80386";
1923 case EM_68K4: return "MC68000";
1924 case EM_88K5: return "MC88000";
1925 case EM_4866: return "Intel 80486";
1926 case EM_8607: return "Intel 80860";
1927 case EM_MIPS8: return "MIPS R3000";
1928 case EM_S3709: return "IBM System/370";
1929 case EM_MIPS_RS3_LE10: return "MIPS R4000 big-endian";
1930 case EM_OLD_SPARCV911: return "Sparc v9 (old)";
1931 case EM_PARISC15: return "HPPA";
1932 case EM_PPC_OLD17: return "Power PC (old)";
1933 case EM_SPARC32PLUS18: return "Sparc v8+" ;
1934 case EM_96019: return "Intel 90860";
1935 case EM_PPC20: return "PowerPC";
1936 case EM_PPC6421: return "PowerPC64";
1937 case EM_V80036: return "NEC V800";
1938 case EM_FR2037: return "Fujitsu FR20";
1939 case EM_RH3238: return "TRW RH32";
1940 case EM_MCORE39: return "MCORE";
1941 case EM_ARM40: return "ARM";
1942 case EM_OLD_ALPHA41: return "Digital Alpha (old)";
1943 case EM_SH42: return "Renesas / SuperH SH";
1944 case EM_SPARCV943: return "Sparc v9";
1945 case EM_TRICORE44: return "Siemens Tricore";
1946 case EM_ARC45: return "ARC";
1947 case EM_H8_30046: return "Renesas H8/300";
1948 case EM_H8_300H47: return "Renesas H8/300H";
1949 case EM_H8S48: return "Renesas H8S";
1950 case EM_H8_50049: return "Renesas H8/500";
1951 case EM_IA_6450: return "Intel IA-64";
1952 case EM_MIPS_X51: return "Stanford MIPS-X";
1953 case EM_COLDFIRE52: return "Motorola Coldfire";
1954 case EM_68HC1253: return "Motorola M68HC12";
1955 case EM_ALPHA0x9026: return "Alpha";
1956 case EM_CYGNUS_D10V0x7650:
1957 case EM_D10V85: return "d10v";
1958 case EM_CYGNUS_D30V0x7676:
1959 case EM_D30V86: return "d30v";
1960 case EM_CYGNUS_M32R0x9041:
1961 case EM_M32R88: return "Renesas M32R (formerly Mitsubishi M32r)";
1962 case EM_CYGNUS_V8500x9080:
1963 case EM_V85087: return "NEC v850";
1964 case EM_CYGNUS_MN103000xbeef:
1965 case EM_MN1030089: return "mn10300";
1966 case EM_CYGNUS_MN102000xdead:
1967 case EM_MN1020090: return "mn10200";
1968 case EM_CYGNUS_FR300x3330:
1969 case EM_FR3084: return "Fujitsu FR30";
1970 case EM_CYGNUS_FRV0x5441: return "Fujitsu FR-V";
1971 case EM_PJ_OLD99:
1972 case EM_PJ91: return "picoJava";
1973 case EM_MMA54: return "Fujitsu Multimedia Accelerator";
1974 case EM_PCP55: return "Siemens PCP";
1975 case EM_NCPU56: return "Sony nCPU embedded RISC processor";
1976 case EM_NDR157: return "Denso NDR1 microprocesspr";
1977 case EM_STARCORE58: return "Motorola Star*Core processor";
1978 case EM_ME1659: return "Toyota ME16 processor";
1979 case EM_ST10060: return "STMicroelectronics ST100 processor";
1980 case EM_TINYJ61: return "Advanced Logic Corp. TinyJ embedded processor";
1981 case EM_FX6666: return "Siemens FX66 microcontroller";
1982 case EM_ST9PLUS67: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1983 case EM_ST768: return "STMicroelectronics ST7 8-bit microcontroller";
1984 case EM_68HC1669: return "Motorola MC68HC16 Microcontroller";
1985 case EM_68HC1170: return "Motorola MC68HC11 Microcontroller";
1986 case EM_68HC0871: return "Motorola MC68HC08 Microcontroller";
1987 case EM_68HC0572: return "Motorola MC68HC05 Microcontroller";
1988 case EM_SVX73: return "Silicon Graphics SVx";
1989 case EM_ST1974: return "STMicroelectronics ST19 8-bit microcontroller";
1990 case EM_VAX75: return "Digital VAX";
1991 case EM_AVR_OLD0x1057:
1992 case EM_AVR83: return "Atmel AVR 8-bit microcontroller";
1993 case EM_CRIS76: return "Axis Communications 32-bit embedded processor";
1994 case EM_JAVELIN77: return "Infineon Technologies 32-bit embedded cpu";
1995 case EM_FIREPATH78: return "Element 14 64-bit DSP processor";
1996 case EM_ZSP79: return "LSI Logic's 16-bit DSP processor";
1997 case EM_MMIX80: return "Donald Knuth's educational 64-bit processor";
1998 case EM_HUANY81: return "Harvard Universitys's machine-independent object format";
1999 case EM_PRISM82: return "Vitesse Prism";
2000 case EM_X86_6462: return "Advanced Micro Devices X86-64";
2001 case EM_S390_OLD0xa390:
2002 case EM_S39022: return "IBM S/390";
2003 case EM_XSTORMY160xad45: return "Sanyo Xstormy16 CPU core";
2004 case EM_OPENRISC92:
2005 case EM_OR320x8472: return "OpenRISC";
2006 case EM_CRX114: return "National Semiconductor CRX microprocessor";
2007 case EM_DLX0x5aa5: return "OpenDLX";
2008 case EM_IP2K_OLD0x8217:
2009 case EM_IP2K101: return "Ubicom IP2xxx 8-bit microcontrollers";
2010 case EM_IQ20000xFEBA: return "Vitesse IQ2000";
2011 case EM_XTENSA_OLD0xabc7:
2012 case EM_XTENSA94: return "Tensilica Xtensa Processor";
2013 case EM_M32C0xFEB0: return "Renesas M32c";
2014 case EM_MT0x2530: return "Morpho Techologies MT processor";
2015 case EM_BLACKFIN106: return "Analog Devices Blackfin";
2016 case EM_NIOS320xFEBB: return "Altera Nios";
2017 case EM_ALTERA_NIOS2113: return "Altera Nios II";
2018 case EM_XC16X0x4688: return "Infineon Technologies xc16x";
2019 case EM_AARCH64183: return "AArch64";
2020 case EM_RISCV243: return "RISC-V";
2021 default:
2022 snprintf (buff, sizeof (buff), _("<unknown>: %x")("<unknown>: %x"), e_machine);
2023 return buff;
2024 }
2025}
2026
2027static void
2028decode_ARM_machine_flags (unsigned e_flags, char buf[])
2029{
2030 unsigned eabi;
2031 int unknown = 0;
2032
2033 eabi = EF_ARM_EABI_VERSION (e_flags)((e_flags) & 0xFF000000);
2034 e_flags &= ~ EF_ARM_EABIMASK0xFF000000;
2035
2036 /* Handle "generic" ARM flags. */
2037 if (e_flags & EF_ARM_RELEXEC0x01)
2038 {
2039 strcat (buf, ", relocatable executable");
2040 e_flags &= ~ EF_ARM_RELEXEC0x01;
2041 }
2042
2043 if (e_flags & EF_ARM_HASENTRY0x02)
2044 {
2045 strcat (buf, ", has entry point");
2046 e_flags &= ~ EF_ARM_HASENTRY0x02;
2047 }
2048
2049 /* Now handle EABI specific flags. */
2050 switch (eabi)
2051 {
2052 default:
2053 strcat (buf, ", <unrecognized EABI>");
2054 if (e_flags)
2055 unknown = 1;
2056 break;
2057
2058 case EF_ARM_EABI_VER10x01000000:
2059 strcat (buf, ", Version1 EABI");
2060 while (e_flags)
2061 {
2062 unsigned flag;
2063
2064 /* Process flags one bit at a time. */
2065 flag = e_flags & - e_flags;
2066 e_flags &= ~ flag;
2067
2068 switch (flag)
2069 {
2070 case EF_ARM_SYMSARESORTED0x04: /* Conflicts with EF_ARM_INTERWORK. */
2071 strcat (buf, ", sorted symbol tables");
2072 break;
2073
2074 default:
2075 unknown = 1;
2076 break;
2077 }
2078 }
2079 break;
2080
2081 case EF_ARM_EABI_VER20x02000000:
2082 strcat (buf, ", Version2 EABI");
2083 while (e_flags)
2084 {
2085 unsigned flag;
2086
2087 /* Process flags one bit at a time. */
2088 flag = e_flags & - e_flags;
2089 e_flags &= ~ flag;
2090
2091 switch (flag)
2092 {
2093 case EF_ARM_SYMSARESORTED0x04: /* Conflicts with EF_ARM_INTERWORK. */
2094 strcat (buf, ", sorted symbol tables");
2095 break;
2096
2097 case EF_ARM_DYNSYMSUSESEGIDX0x08:
2098 strcat (buf, ", dynamic symbols use segment index");
2099 break;
2100
2101 case EF_ARM_MAPSYMSFIRST0x10:
2102 strcat (buf, ", mapping symbols precede others");
2103 break;
2104
2105 default:
2106 unknown = 1;
2107 break;
2108 }
2109 }
2110 break;
2111
2112 case EF_ARM_EABI_VER30x03000000:
2113 strcat (buf, ", Version3 EABI");
2114 break;
2115
2116 case EF_ARM_EABI_VER40x04000000:
2117 strcat (buf, ", Version4 EABI");
2118 goto eabi;
2119
2120 case EF_ARM_EABI_VER50x05000000:
2121 strcat (buf, ", Version5 EABI");
2122 eabi:
2123 while (e_flags)
2124 {
2125 unsigned flag;
2126
2127 /* Process flags one bit at a time. */
2128 flag = e_flags & - e_flags;
2129 e_flags &= ~ flag;
2130
2131 switch (flag)
2132 {
2133 case EF_ARM_BE80x00800000:
2134 strcat (buf, ", BE8");
2135 break;
2136
2137 case EF_ARM_LE80x00400000:
2138 strcat (buf, ", LE8");
2139 break;
2140
2141 default:
2142 unknown = 1;
2143 break;
2144 }
2145 }
2146 break;
2147
2148 case EF_ARM_EABI_UNKNOWN0x00000000:
2149 strcat (buf, ", GNU EABI");
2150 while (e_flags)
2151 {
2152 unsigned flag;
2153
2154 /* Process flags one bit at a time. */
2155 flag = e_flags & - e_flags;
2156 e_flags &= ~ flag;
2157
2158 switch (flag)
2159 {
2160 case EF_ARM_INTERWORK0x04:
2161 strcat (buf, ", interworking enabled");
2162 break;
2163
2164 case EF_ARM_APCS_260x08:
2165 strcat (buf, ", uses APCS/26");
2166 break;
2167
2168 case EF_ARM_APCS_FLOAT0x10:
2169 strcat (buf, ", uses APCS/float");
2170 break;
2171
2172 case EF_ARM_PIC0x20:
2173 strcat (buf, ", position independent");
2174 break;
2175
2176 case EF_ARM_ALIGN80x40:
2177 strcat (buf, ", 8 bit structure alignment");
2178 break;
2179
2180 case EF_ARM_NEW_ABI0x80:
2181 strcat (buf, ", uses new ABI");
2182 break;
2183
2184 case EF_ARM_OLD_ABI0x100:
2185 strcat (buf, ", uses old ABI");
2186 break;
2187
2188 case EF_ARM_SOFT_FLOAT0x200:
2189 strcat (buf, ", software FP");
2190 break;
2191
2192 case EF_ARM_VFP_FLOAT0x400:
2193 strcat (buf, ", VFP");
2194 break;
2195
2196 case EF_ARM_MAVERICK_FLOAT0x800:
2197 strcat (buf, ", Maverick FP");
2198 break;
2199
2200 default:
2201 unknown = 1;
2202 break;
2203 }
2204 }
2205 }
2206
2207 if (unknown)
2208 strcat (buf,", <unknown>");
2209}
2210
2211static char *
2212get_machine_flags (unsigned e_flags, unsigned e_machine)
2213{
2214 static char buf[1024];
2215
2216 buf[0] = '\0';
2217
2218 if (e_flags)
2219 {
2220 switch (e_machine)
2221 {
2222 default:
2223 break;
2224
2225 case EM_ARM40:
2226 decode_ARM_machine_flags (e_flags, buf);
2227 break;
2228
2229 case EM_CYGNUS_FRV0x5441:
2230 switch (e_flags & EF_FRV_CPU_MASK0xff000000)
2231 {
2232 case EF_FRV_CPU_GENERIC0x00000000:
2233 break;
2234
2235 default:
2236 strcat (buf, ", fr???");
2237 break;
2238
2239 case EF_FRV_CPU_FR3000x02000000:
2240 strcat (buf, ", fr300");
2241 break;
2242
2243 case EF_FRV_CPU_FR4000x05000000:
2244 strcat (buf, ", fr400");
2245 break;
2246 case EF_FRV_CPU_FR4050x07000000:
2247 strcat (buf, ", fr405");
2248 break;
2249
2250 case EF_FRV_CPU_FR4500x08000000:
2251 strcat (buf, ", fr450");
2252 break;
2253
2254 case EF_FRV_CPU_FR5000x01000000:
2255 strcat (buf, ", fr500");
2256 break;
2257 case EF_FRV_CPU_FR5500x06000000:
2258 strcat (buf, ", fr550");
2259 break;
2260
2261 case EF_FRV_CPU_SIMPLE0x03000000:
2262 strcat (buf, ", simple");
2263 break;
2264 case EF_FRV_CPU_TOMCAT0x04000000:
2265 strcat (buf, ", tomcat");
2266 break;
2267 }
2268 break;
2269
2270 case EM_68K4:
2271 if (e_flags & EF_M68K_CPU320x00810000)
2272 strcat (buf, ", cpu32");
2273 if (e_flags & EF_M68K_M680000x01000000)
2274 strcat (buf, ", m68000");
2275 if (e_flags & EF_M68K_ISA_MASK0x0F)
2276 {
2277 char const *isa = _("unknown")("unknown");
2278 char const *mac = _("unknown mac")("unknown mac");
2279 char const *additional = NULL((void*)0);
2280
2281 switch (e_flags & EF_M68K_ISA_MASK0x0F)
2282 {
2283 case EF_M68K_ISA_A_NODIV0x01:
2284 isa = "A";
2285 additional = ", nodiv";
2286 break;
2287 case EF_M68K_ISA_A0x02:
2288 isa = "A";
2289 break;
2290 case EF_M68K_ISA_A_PLUS0x03:
2291 isa = "A+";
2292 break;
2293 case EF_M68K_ISA_B_NOUSP0x04:
2294 isa = "B";
2295 additional = ", nousp";
2296 break;
2297 case EF_M68K_ISA_B0x05:
2298 isa = "B";
2299 break;
2300 }
2301 strcat (buf, ", cf, isa ");
2302 strcat (buf, isa);
2303 if (additional)
2304 strcat (buf, additional);
2305 if (e_flags & EF_M68K_FLOAT0x40)
2306 strcat (buf, ", float");
2307 switch (e_flags & EF_M68K_MAC_MASK0x30)
2308 {
2309 case 0:
2310 mac = NULL((void*)0);
2311 break;
2312 case EF_M68K_MAC0x10:
2313 mac = "mac";
2314 break;
2315 case EF_M68K_EMAC0x20:
2316 mac = "emac";
2317 break;
2318 }
2319 if (mac)
2320 {
2321 strcat (buf, ", ");
2322 strcat (buf, mac);
2323 }
2324 }
2325 break;
2326
2327 case EM_PPC20:
2328 if (e_flags & EF_PPC_EMB0x80000000)
2329 strcat (buf, ", emb");
2330
2331 if (e_flags & EF_PPC_RELOCATABLE0x00010000)
2332 strcat (buf, ", relocatable");
2333
2334 if (e_flags & EF_PPC_RELOCATABLE_LIB0x00008000)
2335 strcat (buf, ", relocatable-lib");
2336 break;
2337
2338 case EM_V85087:
2339 case EM_CYGNUS_V8500x9080:
2340 switch (e_flags & EF_V850_ARCH0xf0000000)
2341 {
2342 case E_V850E1_ARCH0x20000000:
2343 strcat (buf, ", v850e1");
2344 break;
2345 case E_V850E_ARCH0x10000000:
2346 strcat (buf, ", v850e");
2347 break;
2348 case E_V850_ARCH0x00000000:
2349 strcat (buf, ", v850");
2350 break;
2351 default:
2352 strcat (buf, ", unknown v850 architecture variant");
2353 break;
2354 }
2355 break;
2356
2357 case EM_M32R88:
2358 case EM_CYGNUS_M32R0x9041:
2359 if ((e_flags & EF_M32R_ARCH0x30000000) == E_M32R_ARCH0x00000000)
2360 strcat (buf, ", m32r");
2361
2362 break;
2363
2364 case EM_MIPS8:
2365 case EM_MIPS_RS3_LE10:
2366 if (e_flags & EF_MIPS_NOREORDER0x00000001)
2367 strcat (buf, ", noreorder");
2368
2369 if (e_flags & EF_MIPS_PIC0x00000002)
2370 strcat (buf, ", pic");
2371
2372 if (e_flags & EF_MIPS_CPIC0x00000004)
2373 strcat (buf, ", cpic");
2374
2375 if (e_flags & EF_MIPS_UCODE0x00000010)
2376 strcat (buf, ", ugen_reserved");
2377
2378 if (e_flags & EF_MIPS_ABI20x00000020)
2379 strcat (buf, ", abi2");
2380
2381 if (e_flags & EF_MIPS_OPTIONS_FIRST0x00000080)
2382 strcat (buf, ", odk first");
2383
2384 if (e_flags & EF_MIPS_32BITMODE0x00000100)
2385 strcat (buf, ", 32bitmode");
2386
2387 switch ((e_flags & EF_MIPS_MACH0x00FF0000))
2388 {
2389 case E_MIPS_MACH_39000x00810000: strcat (buf, ", 3900"); break;
2390 case E_MIPS_MACH_40100x00820000: strcat (buf, ", 4010"); break;
2391 case E_MIPS_MACH_41000x00830000: strcat (buf, ", 4100"); break;
2392 case E_MIPS_MACH_41110x00880000: strcat (buf, ", 4111"); break;
2393 case E_MIPS_MACH_41200x00870000: strcat (buf, ", 4120"); break;
2394 case E_MIPS_MACH_46500x00850000: strcat (buf, ", 4650"); break;
2395 case E_MIPS_MACH_54000x00910000: strcat (buf, ", 5400"); break;
2396 case E_MIPS_MACH_55000x00980000: strcat (buf, ", 5500"); break;
2397 case E_MIPS_MACH_SB10x008a0000: strcat (buf, ", sb1"); break;
2398 case E_MIPS_MACH_90000x00990000: strcat (buf, ", 9000"); break;
2399 case E_MIPS_MACH_OCTEON0x008b0000: strcat (buf, ", octeon"); break;
2400 case 0:
2401 /* We simply ignore the field in this case to avoid confusion:
2402 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2403 extension. */
2404 break;
2405 default: strcat (buf, ", unknown CPU"); break;
2406 }
2407
2408 switch ((e_flags & EF_MIPS_ABI0x0000F000))
2409 {
2410 case E_MIPS_ABI_O320x00001000: strcat (buf, ", o32"); break;
2411 case E_MIPS_ABI_O640x00002000: strcat (buf, ", o64"); break;
2412 case E_MIPS_ABI_EABI320x00003000: strcat (buf, ", eabi32"); break;
2413 case E_MIPS_ABI_EABI640x00004000: strcat (buf, ", eabi64"); break;
2414 case 0:
2415 /* We simply ignore the field in this case to avoid confusion:
2416 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2417 This means it is likely to be an o32 file, but not for
2418 sure. */
2419 break;
2420 default: strcat (buf, ", unknown ABI"); break;
2421 }
2422
2423 if (e_flags & EF_MIPS_ARCH_ASE_MDMX0x08000000)
2424 strcat (buf, ", mdmx");
2425
2426 if (e_flags & EF_MIPS_ARCH_ASE_M160x04000000)
2427 strcat (buf, ", mips16");
2428
2429 switch ((e_flags & EF_MIPS_ARCH0xf0000000))
2430 {
2431 case E_MIPS_ARCH_10x00000000: strcat (buf, ", mips1"); break;
2432 case E_MIPS_ARCH_20x10000000: strcat (buf, ", mips2"); break;
2433 case E_MIPS_ARCH_30x20000000: strcat (buf, ", mips3"); break;
2434 case E_MIPS_ARCH_40x30000000: strcat (buf, ", mips4"); break;
2435 case E_MIPS_ARCH_50x40000000: strcat (buf, ", mips5"); break;
2436 case E_MIPS_ARCH_320x50000000: strcat (buf, ", mips32"); break;
2437 case E_MIPS_ARCH_32R20x70000000: strcat (buf, ", mips32r2"); break;
2438 case E_MIPS_ARCH_640x60000000: strcat (buf, ", mips64"); break;
2439 case E_MIPS_ARCH_64R20x80000000: strcat (buf, ", mips64r2"); break;
2440 default: strcat (buf, ", unknown ISA"); break;
2441 }
2442
2443 break;
2444
2445 case EM_SH42:
2446 switch ((e_flags & EF_SH_MACH_MASK0x1f))
2447 {
2448 case EF_SH11: strcat (buf, ", sh1"); break;
2449 case EF_SH22: strcat (buf, ", sh2"); break;
2450 case EF_SH33: strcat (buf, ", sh3"); break;
2451 case EF_SH_DSP4: strcat (buf, ", sh-dsp"); break;
2452 case EF_SH3_DSP5: strcat (buf, ", sh3-dsp"); break;
2453 case EF_SH4AL_DSP6: strcat (buf, ", sh4al-dsp"); break;
2454 case EF_SH3E8: strcat (buf, ", sh3e"); break;
2455 case EF_SH49: strcat (buf, ", sh4"); break;
2456 case EF_SH510: strcat (buf, ", sh5"); break;
2457 case EF_SH2E11: strcat (buf, ", sh2e"); break;
2458 case EF_SH4A12: strcat (buf, ", sh4a"); break;
2459 case EF_SH2A13: strcat (buf, ", sh2a"); break;
2460 case EF_SH4_NOFPU16: strcat (buf, ", sh4-nofpu"); break;
2461 case EF_SH4A_NOFPU17: strcat (buf, ", sh4a-nofpu"); break;
2462 case EF_SH2A_NOFPU19: strcat (buf, ", sh2a-nofpu"); break;
2463 case EF_SH3_NOMMU20: strcat (buf, ", sh3-nommu"); break;
2464 case EF_SH4_NOMMU_NOFPU18: strcat (buf, ", sh4-nommu-nofpu"); break;
2465 case EF_SH2A_SH4_NOFPU21: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2466 case EF_SH2A_SH3_NOFPU22: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
2467 case EF_SH2A_SH423: strcat (buf, ", sh2a-or-sh4"); break;
2468 case EF_SH2A_SH3E24: strcat (buf, ", sh2a-or-sh3e"); break;
2469 default: strcat (buf, ", unknown ISA"); break;
2470 }
2471
2472 break;
2473
2474 case EM_SPARCV943:
2475 if (e_flags & EF_SPARC_32PLUS0x000100)
2476 strcat (buf, ", v8+");
2477
2478 if (e_flags & EF_SPARC_SUN_US10x000200)
2479 strcat (buf, ", ultrasparcI");
2480
2481 if (e_flags & EF_SPARC_SUN_US30x000800)
2482 strcat (buf, ", ultrasparcIII");
2483
2484 if (e_flags & EF_SPARC_HAL_R10x000400)
2485 strcat (buf, ", halr1");
2486
2487 if (e_flags & EF_SPARC_LEDATA0x800000)
2488 strcat (buf, ", ledata");
2489
2490 if ((e_flags & EF_SPARCV9_MM0x3) == EF_SPARCV9_TSO0x0)
2491 strcat (buf, ", tso");
2492
2493 if ((e_flags & EF_SPARCV9_MM0x3) == EF_SPARCV9_PSO0x1)
2494 strcat (buf, ", pso");
2495
2496 if ((e_flags & EF_SPARCV9_MM0x3) == EF_SPARCV9_RMO0x2)
2497 strcat (buf, ", rmo");
2498 break;
2499
2500 case EM_PARISC15:
2501 switch (e_flags & EF_PARISC_ARCH0x0000ffff)
2502 {
2503 case EFA_PARISC_1_00x020b:
2504 strcpy (buf, ", PA-RISC 1.0");
2505 break;
2506 case EFA_PARISC_1_10x0210:
2507 strcpy (buf, ", PA-RISC 1.1");
2508 break;
2509 case EFA_PARISC_2_00x0214:
2510 strcpy (buf, ", PA-RISC 2.0");
2511 break;
2512 default:
2513 break;
2514 }
2515 if (e_flags & EF_PARISC_TRAPNIL0x00010000)
2516 strcat (buf, ", trapnil");
2517 if (e_flags & EF_PARISC_EXT0x00020000)
2518 strcat (buf, ", ext");
2519 if (e_flags & EF_PARISC_LSB0x00040000)
2520 strcat (buf, ", lsb");
2521 if (e_flags & EF_PARISC_WIDE0x00080000)
2522 strcat (buf, ", wide");
2523 if (e_flags & EF_PARISC_NO_KABP0x00100000)
2524 strcat (buf, ", no kabp");
2525 if (e_flags & EF_PARISC_LAZYSWAP0x00400000)
2526 strcat (buf, ", lazyswap");
2527 break;
2528
2529 case EM_PJ91:
2530 case EM_PJ_OLD99:
2531 if ((e_flags & EF_PICOJAVA_NEWCALLS0x00000010) == EF_PICOJAVA_NEWCALLS0x00000010)
2532 strcat (buf, ", new calling convention");
2533
2534 if ((e_flags & EF_PICOJAVA_GNUCALLS0x00000020) == EF_PICOJAVA_GNUCALLS0x00000020)
2535 strcat (buf, ", gnu calling convention");
2536 break;
2537
2538 case EM_IA_6450:
2539 if ((e_flags & EF_IA_64_ABI64(1 << 4)))
2540 strcat (buf, ", 64-bit");
2541 else
2542 strcat (buf, ", 32-bit");
2543 if ((e_flags & EF_IA_64_REDUCEDFP(1 << 5)))
2544 strcat (buf, ", reduced fp model");
2545 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP(1 << 7)))
2546 strcat (buf, ", no function descriptors, constant gp");
2547 else if ((e_flags & EF_IA_64_CONS_GP(1 << 6)))
2548 strcat (buf, ", constant gp");
2549 if ((e_flags & EF_IA_64_ABSOLUTE(1 << 8)))
2550 strcat (buf, ", absolute");
2551 break;
2552
2553 case EM_VAX75:
2554 if ((e_flags & EF_VAX_NONPIC0x0001))
2555 strcat (buf, ", non-PIC");
2556 if ((e_flags & EF_VAX_DFLOAT0x0100))
2557 strcat (buf, ", D-Float");
2558 if ((e_flags & EF_VAX_GFLOAT0x0200))
2559 strcat (buf, ", G-Float");
2560 break;
2561
2562 case EM_88K5:
2563 if ((e_flags & EF_NABI0x80000000))
2564 strcat (buf, ", not 88Open ABI compliant");
2565 if ((e_flags & EF_M881100x00000004))
2566 strcat (buf, ", m88110");
2567 break;
2568 }
2569 }
2570
2571 return buf;
2572}
2573
2574static const char *
2575get_osabi_name (unsigned int osabi)
2576{
2577 static char buff[32];
2578
2579 switch (osabi)
2580 {
2581 case ELFOSABI_NONE0: return "UNIX - System V";
2582 case ELFOSABI_HPUX1: return "UNIX - HP-UX";
2583 case ELFOSABI_NETBSD2: return "UNIX - NetBSD";
2584 case ELFOSABI_LINUX3: return "UNIX - Linux";
2585 case ELFOSABI_HURD4: return "GNU/Hurd";
2586 case ELFOSABI_SOLARIS6: return "UNIX - Solaris";
2587 case ELFOSABI_AIX7: return "UNIX - AIX";
2588 case ELFOSABI_IRIX8: return "UNIX - IRIX";
2589 case ELFOSABI_FREEBSD9: return "UNIX - FreeBSD";
2590 case ELFOSABI_TRU6410: return "UNIX - TRU64";
2591 case ELFOSABI_MODESTO11: return "Novell - Modesto";
2592 case ELFOSABI_OPENBSD12: return "UNIX - OpenBSD";
2593 case ELFOSABI_OPENVMS13: return "VMS - OpenVMS";
2594 case ELFOSABI_NSK14: return "HP - Non-Stop Kernel";
2595 case ELFOSABI_AROS15: return "Amiga Research OS";
2596 case ELFOSABI_STANDALONE255: return _("Standalone App")("Standalone App");
2597 case ELFOSABI_ARM97: return "ARM";
2598 default:
2599 snprintf (buff, sizeof (buff), _("<unknown: %x>")("<unknown: %x>"), osabi);
2600 return buff;
2601 }
2602}
2603
2604static const char *
2605get_arm_segment_type (unsigned long type)
2606{
2607 switch (type)
2608 {
2609 case PT_ARM_EXIDX(0x70000000 + 1):
2610 return "EXIDX";
2611 default:
2612 break;
2613 }
2614
2615 return NULL((void*)0);
2616}
2617
2618static const char *
2619get_mips_segment_type (unsigned long type)
2620{
2621 switch (type)
2622 {
2623 case PT_MIPS_REGINFO0x70000000:
2624 return "REGINFO";
2625 case PT_MIPS_RTPROC0x70000001:
2626 return "RTPROC";
2627 case PT_MIPS_OPTIONS0x70000002:
2628 return "OPTIONS";
2629 default:
2630 break;
2631 }
2632
2633 return NULL((void*)0);
2634}
2635
2636static const char *
2637get_parisc_segment_type (unsigned long type)
2638{
2639 switch (type)
2640 {
2641 case PT_HP_TLS(0x60000000 + 0x0): return "HP_TLS";
2642 case PT_HP_CORE_NONE(0x60000000 + 0x1): return "HP_CORE_NONE";
2643 case PT_HP_CORE_VERSION(0x60000000 + 0x2): return "HP_CORE_VERSION";
2644 case PT_HP_CORE_KERNEL(0x60000000 + 0x3): return "HP_CORE_KERNEL";
2645 case PT_HP_CORE_COMM(0x60000000 + 0x4): return "HP_CORE_COMM";
2646 case PT_HP_CORE_PROC(0x60000000 + 0x5): return "HP_CORE_PROC";
2647 case PT_HP_CORE_LOADABLE(0x60000000 + 0x6): return "HP_CORE_LOADABLE";
2648 case PT_HP_CORE_STACK(0x60000000 + 0x7): return "HP_CORE_STACK";
2649 case PT_HP_CORE_SHM(0x60000000 + 0x8): return "HP_CORE_SHM";
2650 case PT_HP_CORE_MMF(0x60000000 + 0x9): return "HP_CORE_MMF";
2651 case PT_HP_PARALLEL(0x60000000 + 0x10): return "HP_PARALLEL";
2652 case PT_HP_FASTBIND(0x60000000 + 0x11): return "HP_FASTBIND";
2653 case PT_HP_OPT_ANNOT(0x60000000 + 0x12): return "HP_OPT_ANNOT";
2654 case PT_HP_HSL_ANNOT(0x60000000 + 0x13): return "HP_HSL_ANNOT";
2655 case PT_HP_STACK(0x60000000 + 0x14): return "HP_STACK";
2656 case PT_HP_CORE_UTSNAME(0x60000000 + 0x15): return "HP_CORE_UTSNAME";
2657 case PT_PARISC_ARCHEXT0x70000000: return "PARISC_ARCHEXT";
2658 case PT_PARISC_UNWIND0x70000001: return "PARISC_UNWIND";
2659 case PT_PARISC_WEAKORDER0x70000002: return "PARISC_WEAKORDER";
2660 default:
2661 break;
2662 }
2663
2664 return NULL((void*)0);
2665}
2666
2667static const char *
2668get_ia64_segment_type (unsigned long type)
2669{
2670 switch (type)
2671 {
2672 case PT_IA_64_ARCHEXT(0x70000000 + 0): return "IA_64_ARCHEXT";
2673 case PT_IA_64_UNWIND(0x70000000 + 1): return "IA_64_UNWIND";
2674 case PT_HP_TLS(0x60000000 + 0x0): return "HP_TLS";
2675 case PT_IA_64_HP_OPT_ANOT(0x60000000 + 0x12): return "HP_OPT_ANNOT";
2676 case PT_IA_64_HP_HSL_ANOT(0x60000000 + 0x13): return "HP_HSL_ANNOT";
2677 case PT_IA_64_HP_STACK(0x60000000 + 0x14): return "HP_STACK";
2678 default:
2679 break;
2680 }
2681
2682 return NULL((void*)0);
2683}
2684
2685static const char *
2686get_segment_type (unsigned long p_type)
2687{
2688 static char buff[32];
2689
2690 switch (p_type)
2691 {
2692 case PT_NULL0: return "NULL";
2693 case PT_LOAD1: return "LOAD";
2694 case PT_DYNAMIC2: return "DYNAMIC";
2695 case PT_INTERP3: return "INTERP";
2696 case PT_NOTE4: return "NOTE";
2697 case PT_SHLIB5: return "SHLIB";
2698 case PT_PHDR6: return "PHDR";
2699 case PT_TLS7: return "TLS";
2700
2701 case PT_GNU_EH_FRAME(0x60000000 + 0x474e550):
2702 return "GNU_EH_FRAME";
2703 case PT_GNU_STACK(0x60000000 + 0x474e551): return "GNU_STACK";
2704 case PT_GNU_RELRO(0x60000000 + 0x474e552): return "GNU_RELRO";
2705 case PT_OPENBSD_RANDOMIZE0x65a3dbe6:
2706 return "OPENBSD_RANDOMIZE";
2707 case PT_OPENBSD_WXNEEDED0x65a3dbe7:
2708 return "OPENBSD_WXNEEDED";
2709 case PT_OPENBSD_BOOTDATA0x65a41be6:
2710 return "OPENBSD_BOOTDATA";
2711
2712 default:
2713 if ((p_type >= PT_LOPROC0x70000000) && (p_type <= PT_HIPROC0x7FFFFFFF))
2714 {
2715 const char *result;
2716
2717 switch (elf_header.e_machine)
2718 {
2719 case EM_ARM40:
2720 result = get_arm_segment_type (p_type);
2721 break;
2722 case EM_MIPS8:
2723 case EM_MIPS_RS3_LE10:
2724 result = get_mips_segment_type (p_type);
2725 break;
2726 case EM_PARISC15:
2727 result = get_parisc_segment_type (p_type);
2728 break;
2729 case EM_IA_6450:
2730 result = get_ia64_segment_type (p_type);
2731 break;
2732 default:
2733 result = NULL((void*)0);
2734 break;
2735 }
2736
2737 if (result != NULL((void*)0))
2738 return result;
2739
2740 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC0x70000000);
2741 }
2742 else if ((p_type >= PT_LOOS0x60000000) && (p_type <= PT_HIOS0x6fffffff))
2743 {
2744 const char *result;
2745
2746 switch (elf_header.e_machine)
2747 {
2748 case EM_PARISC15:
2749 result = get_parisc_segment_type (p_type);
2750 break;
2751 case EM_IA_6450:
2752 result = get_ia64_segment_type (p_type);
2753 break;
2754 default:
2755 result = NULL((void*)0);
2756 break;
2757 }
2758
2759 if (result != NULL((void*)0))
2760 return result;
2761
2762 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS0x60000000);
2763 }
2764 else
2765 snprintf (buff, sizeof (buff), _("<unknown>: %lx")("<unknown>: %lx"), p_type);
2766
2767 return buff;
2768 }
2769}
2770
2771static const char *
2772get_mips_section_type_name (unsigned int sh_type)
2773{
2774 switch (sh_type)
2775 {
2776 case SHT_MIPS_LIBLIST0x70000000: return "MIPS_LIBLIST";
2777 case SHT_MIPS_MSYM0x70000001: return "MIPS_MSYM";
2778 case SHT_MIPS_CONFLICT0x70000002: return "MIPS_CONFLICT";
2779 case SHT_MIPS_GPTAB0x70000003: return "MIPS_GPTAB";
2780 case SHT_MIPS_UCODE0x70000004: return "MIPS_UCODE";
2781 case SHT_MIPS_DEBUG0x70000005: return "MIPS_DEBUG";
2782 case SHT_MIPS_REGINFO0x70000006: return "MIPS_REGINFO";
2783 case SHT_MIPS_PACKAGE0x70000007: return "MIPS_PACKAGE";
2784 case SHT_MIPS_PACKSYM0x70000008: return "MIPS_PACKSYM";
2785 case SHT_MIPS_RELD0x70000009: return "MIPS_RELD";
2786 case SHT_MIPS_IFACE0x7000000b: return "MIPS_IFACE";
2787 case SHT_MIPS_CONTENT0x7000000c: return "MIPS_CONTENT";
2788 case SHT_MIPS_OPTIONS0x7000000d: return "MIPS_OPTIONS";
2789 case SHT_MIPS_SHDR0x70000010: return "MIPS_SHDR";
2790 case SHT_MIPS_FDESC0x70000011: return "MIPS_FDESC";
2791 case SHT_MIPS_EXTSYM0x70000012: return "MIPS_EXTSYM";
2792 case SHT_MIPS_DENSE0x70000013: return "MIPS_DENSE";
2793 case SHT_MIPS_PDESC0x70000014: return "MIPS_PDESC";
2794 case SHT_MIPS_LOCSYM0x70000015: return "MIPS_LOCSYM";
2795 case SHT_MIPS_AUXSYM0x70000016: return "MIPS_AUXSYM";
2796 case SHT_MIPS_OPTSYM0x70000017: return "MIPS_OPTSYM";
2797 case SHT_MIPS_LOCSTR0x70000018: return "MIPS_LOCSTR";
2798 case SHT_MIPS_LINE0x70000019: return "MIPS_LINE";
2799 case SHT_MIPS_RFDESC0x7000001a: return "MIPS_RFDESC";
2800 case SHT_MIPS_DELTASYM0x7000001b: return "MIPS_DELTASYM";
2801 case SHT_MIPS_DELTAINST0x7000001c: return "MIPS_DELTAINST";
2802 case SHT_MIPS_DELTACLASS0x7000001d: return "MIPS_DELTACLASS";
2803 case SHT_MIPS_DWARF0x7000001e: return "MIPS_DWARF";
2804 case SHT_MIPS_DELTADECL0x7000001f: return "MIPS_DELTADECL";
2805 case SHT_MIPS_SYMBOL_LIB0x70000020: return "MIPS_SYMBOL_LIB";
2806 case SHT_MIPS_EVENTS0x70000021: return "MIPS_EVENTS";
2807 case SHT_MIPS_TRANSLATE0x70000022: return "MIPS_TRANSLATE";
2808 case SHT_MIPS_PIXIE0x70000023: return "MIPS_PIXIE";
2809 case SHT_MIPS_XLATE0x70000024: return "MIPS_XLATE";
2810 case SHT_MIPS_XLATE_DEBUG0x70000025: return "MIPS_XLATE_DEBUG";
2811 case SHT_MIPS_WHIRL0x70000026: return "MIPS_WHIRL";
2812 case SHT_MIPS_EH_REGION0x70000027: return "MIPS_EH_REGION";
2813 case SHT_MIPS_XLATE_OLD0x70000028: return "MIPS_XLATE_OLD";
2814 case SHT_MIPS_PDR_EXCEPTION0x70000029: return "MIPS_PDR_EXCEPTION";
2815 default:
2816 break;
2817 }
2818 return NULL((void*)0);
2819}
2820
2821static const char *
2822get_parisc_section_type_name (unsigned int sh_type)
2823{
2824 switch (sh_type)
2825 {
2826 case SHT_PARISC_EXT0x70000000: return "PARISC_EXT";
2827 case SHT_PARISC_UNWIND0x70000001: return "PARISC_UNWIND";
2828 case SHT_PARISC_DOC0x70000002: return "PARISC_DOC";
2829 case SHT_PARISC_ANNOT0x70000003: return "PARISC_ANNOT";
2830 case SHT_PARISC_SYMEXTN0x70000000 +8: return "PARISC_SYMEXTN";
2831 case SHT_PARISC_STUBS0x70000000 +9: return "PARISC_STUBS";
2832 case SHT_PARISC_DLKM0x70000004: return "PARISC_DLKM";
2833 default:
2834 break;
2835 }
2836 return NULL((void*)0);
2837}
2838
2839static const char *
2840get_ia64_section_type_name (unsigned int sh_type)
2841{
2842 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2843 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG(0x70000000 + 0x8000000))
2844 return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
2845
2846 switch (sh_type)
2847 {
2848 case SHT_IA_64_EXT(0x70000000 + 0): return "IA_64_EXT";
2849 case SHT_IA_64_UNWIND(0x70000000 + 1): return "IA_64_UNWIND";
2850 case SHT_IA_64_PRIORITY_INIT(0x70000000 + 0x9000000): return "IA_64_PRIORITY_INIT";
2851 default:
2852 break;
2853 }
2854 return NULL((void*)0);
2855}
2856
2857static const char *
2858get_x86_64_section_type_name (unsigned int sh_type)
2859{
2860 switch (sh_type)
2861 {
2862 case SHT_X86_64_UNWIND0x70000001: return "X86_64_UNWIND";
2863 default:
2864 break;
2865 }
2866 return NULL((void*)0);
2867}
2868
2869static const char *
2870get_arm_section_type_name (unsigned int sh_type)
2871{
2872 switch (sh_type)
2873 {
2874 case SHT_ARM_EXIDX0x70000001:
2875 return "ARM_EXIDX";
2876 case SHT_ARM_PREEMPTMAP0x70000002:
2877 return "ARM_PREEMPTMAP";
2878 case SHT_ARM_ATTRIBUTES0x70000003:
2879 return "ARM_ATTRIBUTES";
2880 default:
2881 break;
2882 }
2883 return NULL((void*)0);
2884}
2885
2886static const char *
2887get_section_type_name (unsigned int sh_type)
2888{
2889 static char buff[32];
2890
2891 switch (sh_type)
2892 {
2893 case SHT_NULL0: return "NULL";
2894 case SHT_PROGBITS1: return "PROGBITS";
2895 case SHT_SYMTAB2: return "SYMTAB";
2896 case SHT_STRTAB3: return "STRTAB";
2897 case SHT_RELA4: return "RELA";
2898 case SHT_HASH5: return "HASH";
2899 case SHT_DYNAMIC6: return "DYNAMIC";
2900 case SHT_NOTE7: return "NOTE";
2901 case SHT_NOBITS8: return "NOBITS";
2902 case SHT_REL9: return "REL";
2903 case SHT_SHLIB10: return "SHLIB";
2904 case SHT_DYNSYM11: return "DYNSYM";
2905 case SHT_INIT_ARRAY14: return "INIT_ARRAY";
2906 case SHT_FINI_ARRAY15: return "FINI_ARRAY";
2907 case SHT_PREINIT_ARRAY16: return "PREINIT_ARRAY";
2908 case SHT_GNU_HASH0x6ffffff6: return "GNU_HASH";
2909 case SHT_GROUP17: return "GROUP";
2910 case SHT_SYMTAB_SHNDX18: return "SYMTAB SECTION INDICIES";
2911 case SHT_RELR19: return "RELR";
2912 case SHT_GNU_verdef0x6ffffffd: return "VERDEF";
2913 case SHT_GNU_verneed0x6ffffffe: return "VERNEED";
2914 case SHT_GNU_versym0x6fffffff: return "VERSYM";
2915 case 0x6ffffff0: return "VERSYM";
2916 case 0x6ffffffc: return "VERDEF";
2917 case 0x7ffffffd: return "AUXILIARY";
2918 case 0x7fffffff: return "FILTER";
2919 case SHT_GNU_LIBLIST0x6ffffff7: return "GNU_LIBLIST";
2920 case SHT_LLVM_LINKER_OPTIONS0x6fff4c01: return "LLVM_LINKER_OPTIONS";
2921 case SHT_LLVM_ADDRSIG0x6fff4c03: return "LLVM_ADDRSIG";
2922
2923 default:
2924 if ((sh_type >= SHT_LOPROC0x70000000) && (sh_type <= SHT_HIPROC0x7FFFFFFF))
2925 {
2926 const char *result;
2927
2928 switch (elf_header.e_machine)
2929 {
2930 case EM_MIPS8:
2931 case EM_MIPS_RS3_LE10:
2932 result = get_mips_section_type_name (sh_type);
2933 break;
2934 case EM_PARISC15:
2935 result = get_parisc_section_type_name (sh_type);
2936 break;
2937 case EM_IA_6450:
2938 result = get_ia64_section_type_name (sh_type);
2939 break;
2940 case EM_X86_6462:
2941 result = get_x86_64_section_type_name (sh_type);
2942 break;
2943 case EM_ARM40:
2944 result = get_arm_section_type_name (sh_type);
2945 break;
2946 default:
2947 result = NULL((void*)0);
2948 break;
2949 }
2950
2951 if (result != NULL((void*)0))
2952 return result;
2953
2954 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC0x70000000);
2955 }
2956 else if ((sh_type >= SHT_LOOS0x60000000) && (sh_type <= SHT_HIOS0x6fffffff))
2957 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS0x60000000);
2958 else if ((sh_type >= SHT_LOUSER0x80000000) && (sh_type <= SHT_HIUSER0xFFFFFFFF))
2959 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER0x80000000);
2960 else
2961 snprintf (buff, sizeof (buff), _("<unknown>: %x")("<unknown>: %x"), sh_type);
2962
2963 return buff;
2964 }
2965}
2966
2967#define OPTION_DEBUG_DUMP512 512
2968#define OPTION_RAW_RELR513 513
2969
2970static struct option options[] =
2971{
2972 {"all", no_argument0, 0, 'a'},
2973 {"file-header", no_argument0, 0, 'h'},
2974 {"program-headers", no_argument0, 0, 'l'},
2975 {"headers", no_argument0, 0, 'e'},
2976 {"histogram", no_argument0, 0, 'I'},
2977 {"segments", no_argument0, 0, 'l'},
2978 {"sections", no_argument0, 0, 'S'},
2979 {"section-headers", no_argument0, 0, 'S'},
2980 {"section-groups", no_argument0, 0, 'g'},
2981 {"section-details", no_argument0, 0, 't'},
2982 {"full-section-name",no_argument0, 0, 'N'},
2983 {"symbols", no_argument0, 0, 's'},
2984 {"syms", no_argument0, 0, 's'},
2985 {"relocs", no_argument0, 0, 'r'},
2986 {"notes", no_argument0, 0, 'n'},
2987 {"dynamic", no_argument0, 0, 'd'},
2988 {"arch-specific", no_argument0, 0, 'A'},
2989 {"version-info", no_argument0, 0, 'V'},
2990 {"use-dynamic", no_argument0, 0, 'D'},
2991 {"hex-dump", required_argument1, 0, 'x'},
2992 {"debug-dump", optional_argument2, 0, OPTION_DEBUG_DUMP512},
2993 {"unwind", no_argument0, 0, 'u'},
2994#ifdef SUPPORT_DISASSEMBLY
2995 {"instruction-dump", required_argument1, 0, 'i'},
2996#endif
2997 {"raw-relr", no_argument0, 0, OPTION_RAW_RELR513},
2998
2999 {"version", no_argument0, 0, 'v'},
3000 {"wide", no_argument0, 0, 'W'},
3001 {"help", no_argument0, 0, 'H'},
3002 {0, no_argument0, 0, 0}
3003};
3004
3005static void
3006usage (void)
3007{
3008 fprintf (stdout(&__sF[1]), _("Usage: readelf <option(s)> elf-file(s)\n")("Usage: readelf <option(s)> elf-file(s)\n"));
3009 fprintf (stdout(&__sF[1]), _(" Display information about the contents of ELF format files\n")(" Display information about the contents of ELF format files\n"
)
);
3010 fprintf (stdout(&__sF[1]), _(" Options are:\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3011 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3012 -h --file-header Display the ELF file header\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3013 -l --program-headers Display the program headers\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3014 --segments An alias for --program-headers\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3015 -S --section-headers Display the sections' header\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3016 --sections An alias for --section-headers\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3017 -g --section-groups Display the section groups\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3018 -t --section-details Display the section details\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3019 -e --headers Equivalent to: -h -l -S\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3020 -s --syms Display the symbol table\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3021 --symbols An alias for --syms\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3022 -n --notes Display the core notes (if present)\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3023 -r --relocs Display the relocations (if present)\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3024 --raw-relr Do not decode SHT_RELR sections, display raw content\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3025 -u --unwind Display the unwind info (if present)\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3026 -d --dynamic Display the dynamic section (if present)\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3027 -V --version-info Display the version sections (if present)\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3028 -A --arch-specific Display architecture specific information (if any).\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3029 -D --use-dynamic Use the dynamic section info when displaying symbols\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3030 -x --hex-dump=<number> Dump the contents of section <number>\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3031 -w[liaprmfFsoR] or\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3032 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
3033 Display the contents of DWARF2 debug sections\n")(" Options are:\n -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n -h --file-header Display the ELF file header\n -l --program-headers Display the program headers\n --segments An alias for --program-headers\n -S --section-headers Display the sections' header\n --sections An alias for --section-headers\n -g --section-groups Display the section groups\n -t --section-details Display the section details\n -e --headers Equivalent to: -h -l -S\n -s --syms Display the symbol table\n --symbols An alias for --syms\n -n --notes Display the core notes (if present)\n -r --relocs Display the relocations (if present)\n --raw-relr Do not decode SHT_RELR sections, display raw content\n -u --unwind Display the unwind info (if present)\n -d --dynamic Display the dynamic section (if present)\n -V --version-info Display the version sections (if present)\n -A --arch-specific Display architecture specific information (if any).\n -D --use-dynamic Use the dynamic section info when displaying symbols\n -x --hex-dump=<number> Dump the contents of section <number>\n -w[liaprmfFsoR] or\n --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n Display the contents of DWARF2 debug sections\n"
)
);
3034#ifdef SUPPORT_DISASSEMBLY
3035 fprintf (stdout(&__sF[1]), _("\(" -i --instruction-dump=<number>\n Disassemble the contents of section <number>\n"
)
3036 -i --instruction-dump=<number>\n\(" -i --instruction-dump=<number>\n Disassemble the contents of section <number>\n"
)
3037 Disassemble the contents of section <number>\n")(" -i --instruction-dump=<number>\n Disassemble the contents of section <number>\n"
)
);
3038#endif
3039 fprintf (stdout(&__sF[1]), _("\(" -I --histogram Display histogram of bucket list lengths\n -W --wide Allow output width to exceed 80 characters\n @<file> Read options from <file>\n -H --help Display this information\n -v --version Display the version number of readelf\n"
)
3040 -I --histogram Display histogram of bucket list lengths\n\(" -I --histogram Display histogram of bucket list lengths\n -W --wide Allow output width to exceed 80 characters\n @<file> Read options from <file>\n -H --help Display this information\n -v --version Display the version number of readelf\n"
)
3041 -W --wide Allow output width to exceed 80 characters\n\(" -I --histogram Display histogram of bucket list lengths\n -W --wide Allow output width to exceed 80 characters\n @<file> Read options from <file>\n -H --help Display this information\n -v --version Display the version number of readelf\n"
)
3042 @<file> Read options from <file>\n\(" -I --histogram Display histogram of bucket list lengths\n -W --wide Allow output width to exceed 80 characters\n @<file> Read options from <file>\n -H --help Display this information\n -v --version Display the version number of readelf\n"
)
3043 -H --help Display this information\n\(" -I --histogram Display histogram of bucket list lengths\n -W --wide Allow output width to exceed 80 characters\n @<file> Read options from <file>\n -H --help Display this information\n -v --version Display the version number of readelf\n"
)
3044 -v --version Display the version number of readelf\n")(" -I --histogram Display histogram of bucket list lengths\n -W --wide Allow output width to exceed 80 characters\n @<file> Read options from <file>\n -H --help Display this information\n -v --version Display the version number of readelf\n"
)
);
3045 fprintf (stdout(&__sF[1]), _("Report bugs to %s\n")("Report bugs to %s\n"), REPORT_BUGS_TO"<URL:http://www.sourceware.org/bugzilla/>");
3046
3047 exit (0);
3048}
3049
3050/* Record the fact that the user wants the contents of section number
3051 SECTION to be displayed using the method(s) encoded as flags bits
3052 in TYPE. Note, TYPE can be zero if we are creating the array for
3053 the first time. */
3054
3055static void
3056request_dump (unsigned int section, int type)
3057{
3058 if (section >= num_dump_sects)
3059 {
3060 char *new_dump_sects;
3061
3062 new_dump_sects = calloc (section + 1, 1);
3063
3064 if (new_dump_sects == NULL((void*)0))
3065 error (_("Out of memory allocating dump request table.")("Out of memory allocating dump request table."));
3066 else
3067 {
3068 /* Copy current flag settings. */
3069 memcpy (new_dump_sects, dump_sects, num_dump_sects);
3070
3071 free (dump_sects);
3072
3073 dump_sects = new_dump_sects;
3074 num_dump_sects = section + 1;
3075 }
3076 }
3077
3078 if (dump_sects)
3079 dump_sects[section] |= type;
3080
3081 return;
3082}
3083
3084/* Request a dump by section name. */
3085
3086static void
3087request_dump_byname (const char *section, int type)
3088{
3089 struct dump_list_entry *new_request;
3090
3091 new_request = malloc (sizeof (struct dump_list_entry));
3092 if (!new_request)
3093 error (_("Out of memory allocating dump request table.")("Out of memory allocating dump request table."));
3094
3095 new_request->name = strdup (section);
3096 if (!new_request->name)
3097 error (_("Out of memory allocating dump request table.")("Out of memory allocating dump request table."));
3098
3099 new_request->type = type;
3100
3101 new_request->next = dump_sects_byname;
3102 dump_sects_byname = new_request;
3103}
3104
3105static void
3106parse_args (int argc, char **argv)
3107{
3108 int c;
3109
3110 if (argc < 2)
3111 usage ();
3112
3113 while ((c = getopt_long
3114 (argc, argv, "ersuahnldSDAINtgw::x:i:vVWH", options, NULL((void*)0))) != EOF(-1))
3115 {
3116 char *cp;
3117 int section;
3118
3119 switch (c)
3120 {
3121 case 0:
3122 /* Long options. */
3123 break;
3124 case 'H':
3125 usage ();
3126 break;
3127
3128 case 'a':
3129 do_syms++;
3130 do_reloc++;
3131 do_unwind++;
3132 do_dynamic++;
3133 do_header++;
3134 do_sections++;
3135 do_section_groups++;
3136 do_segments++;
3137 do_version++;
3138 do_histogram++;
3139 do_arch++;
3140 do_notes++;
3141 break;
3142 case 'g':
3143 do_section_groups++;
3144 break;
3145 case 't':
3146 case 'N':
3147 do_sections++;
3148 do_section_details++;
3149 break;
3150 case 'e':
3151 do_header++;
3152 do_sections++;
3153 do_segments++;
3154 break;
3155 case 'A':
3156 do_arch++;
3157 break;
3158 case 'D':
3159 do_using_dynamic++;
3160 break;
3161 case 'r':
3162 do_reloc++;
3163 break;
3164 case 'u':
3165 do_unwind++;
3166 break;
3167 case 'h':
3168 do_header++;
3169 break;
3170 case 'l':
3171 do_segments++;
3172 break;
3173 case 's':
3174 do_syms++;
3175 break;
3176 case 'S':
3177 do_sections++;
3178 break;
3179 case 'd':
3180 do_dynamic++;
3181 break;
3182 case 'I':
3183 do_histogram++;
3184 break;
3185 case 'n':
3186 do_notes++;
3187 break;
3188 case 'x':
3189 do_dump++;
3190 section = strtoul (optarg, & cp, 0);
3191 if (! *cp && section >= 0)
3192 request_dump (section, HEX_DUMP(1 << 0));
3193 else
3194 request_dump_byname (optarg, HEX_DUMP(1 << 0));
3195 break;
3196 case 'w':
3197 do_dump++;
3198 if (optarg == 0)
3199 do_debugging = 1;
3200 else
3201 {
3202 unsigned int index = 0;
3203
3204 do_debugging = 0;
3205
3206 while (optarg[index])
3207 switch (optarg[index++])
3208 {
3209 case 'i':
3210 case 'I':
3211 do_debug_info = 1;
3212 break;
3213
3214 case 'a':
3215 case 'A':
3216 do_debug_abbrevs = 1;
3217 break;
3218
3219 case 'l':
3220 case 'L':
3221 do_debug_lines = 1;
3222 break;
3223
3224 case 'p':
3225 case 'P':
3226 do_debug_pubnames = 1;
3227 break;
3228
3229 case 'r':
3230 do_debug_aranges = 1;
3231 break;
3232
3233 case 'R':
3234 do_debug_ranges = 1;
3235 break;
3236
3237 case 'F':
3238 do_debug_frames_interp = 1;
3239 case 'f':
3240 do_debug_frames = 1;
3241 break;
3242
3243 case 'm':
3244 case 'M':
3245 do_debug_macinfo = 1;
3246 break;
3247
3248 case 's':
3249 case 'S':
3250 do_debug_str = 1;
3251 break;
3252
3253 case 'o':
3254 case 'O':
3255 do_debug_loc = 1;
3256 break;
3257
3258 default:
3259 warn (_("Unrecognized debug option '%s'\n")("Unrecognized debug option '%s'\n"), optarg);
3260 break;
3261 }
3262 }
3263 break;
3264 case OPTION_DEBUG_DUMP512:
3265 do_dump++;
3266 if (optarg == 0)
3267 do_debugging = 1;
3268 else
3269 {
3270 typedef struct
3271 {
3272 const char * option;
3273 int * variable;
3274 }
3275 debug_dump_long_opts;
3276
3277 debug_dump_long_opts opts_table [] =
3278 {
3279 /* Please keep this table alpha- sorted. */
3280 { "Ranges", & do_debug_ranges },
3281 { "abbrev", & do_debug_abbrevs },
3282 { "aranges", & do_debug_aranges },
3283 { "frames", & do_debug_frames },
3284 { "frames-interp", & do_debug_frames_interp },
3285 { "info", & do_debug_info },
3286 { "line", & do_debug_lines },
3287 { "loc", & do_debug_loc },
3288 { "macro", & do_debug_macinfo },
3289 { "pubnames", & do_debug_pubnames },
3290 /* This entry is for compatability
3291 with earlier versions of readelf. */
3292 { "ranges", & do_debug_aranges },
3293 { "str", & do_debug_str },
3294 { NULL((void*)0), NULL((void*)0) }
3295 };
3296
3297 const char *p;
3298
3299 do_debugging = 0;
3300
3301 p = optarg;
3302 while (*p)
3303 {
3304 debug_dump_long_opts * entry;
3305
3306 for (entry = opts_table; entry->option; entry++)
3307 {
3308 size_t len = strlen (entry->option);
3309
3310 if (strneq (p, entry->option, len)(strncmp ((p), (entry->option), (len)) == 0)
3311 && (p[len] == ',' || p[len] == '\0'))
3312 {
3313 * entry->variable = 1;
3314
3315 /* The --debug-dump=frames-interp option also
3316 enables the --debug-dump=frames option. */
3317 if (do_debug_frames_interp)
3318 do_debug_frames = 1;
3319
3320 p += len;
3321 break;
3322 }
3323 }
3324
3325 if (entry->option == NULL((void*)0))
3326 {
3327 warn (_("Unrecognized debug option '%s'\n")("Unrecognized debug option '%s'\n"), p);
3328 p = strchr (p, ',');
3329 if (p == NULL((void*)0))
3330 break;
3331 }
3332
3333 if (*p == ',')
3334 p++;
3335 }
3336 }
3337 break;
3338 case OPTION_RAW_RELR513:
3339 do_raw_relr = 1;
3340 break;
3341#ifdef SUPPORT_DISASSEMBLY
3342 case 'i':
3343 do_dump++;
3344 section = strtoul (optarg, & cp, 0);
3345 if (! *cp && section >= 0)
3346 {
3347 request_dump (section, DISASS_DUMP(1 << 1));
3348 break;
3349 }
3350 goto oops;
3351#endif
3352 case 'v':
3353 print_version (program_name);
3354 break;
3355 case 'V':
3356 do_version++;
3357 break;
3358 case 'W':
3359 do_wide++;
3360 break;
3361 default:
3362#ifdef SUPPORT_DISASSEMBLY
3363 oops:
3364#endif
3365 /* xgettext:c-format */
3366 error (_("Invalid option '-%c'\n")("Invalid option '-%c'\n"), c);
3367 /* Drop through. */
3368 case '?':
3369 usage ();
3370 }
3371 }
3372
3373 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
3374 && !do_segments && !do_header && !do_dump && !do_version
3375 && !do_histogram && !do_debugging && !do_arch && !do_notes
3376 && !do_section_groups)
3377 usage ();
3378 else if (argc < 3)
3379 {
3380 warn (_("Nothing to do.\n")("Nothing to do.\n"));
3381 usage ();
3382 }
3383}
3384
3385static const char *
3386get_elf_class (unsigned int elf_class)
3387{
3388 static char buff[32];
3389
3390 switch (elf_class)
3391 {
3392 case ELFCLASSNONE0: return _("none")("none");
3393 case ELFCLASS321: return "ELF32";
3394 case ELFCLASS642: return "ELF64";
3395 default:
3396 snprintf (buff, sizeof (buff), _("<unknown: %x>")("<unknown: %x>"), elf_class);
3397 return buff;
3398 }
3399}
3400
3401static const char *
3402get_data_encoding (unsigned int encoding)
3403{
3404 static char buff[32];
3405
3406 switch (encoding)
3407 {
3408 case ELFDATANONE0: return _("none")("none");
3409 case ELFDATA2LSB1: return _("2's complement, little endian")("2's complement, little endian");
3410 case ELFDATA2MSB2: return _("2's complement, big endian")("2's complement, big endian");
3411 default:
3412 snprintf (buff, sizeof (buff), _("<unknown: %x>")("<unknown: %x>"), encoding);
3413 return buff;
3414 }
3415}
3416
3417/* Decode the data held in 'elf_header'. */
3418
3419static int
3420process_file_header (void)
3421{
3422 if ( elf_header.e_ident[EI_MAG00] != ELFMAG00x7F
3423 || elf_header.e_ident[EI_MAG11] != ELFMAG1'E'
3424 || elf_header.e_ident[EI_MAG22] != ELFMAG2'L'
3425 || elf_header.e_ident[EI_MAG33] != ELFMAG3'F')
3426 {
3427 error
3428 (_("Not an ELF file - it has the wrong magic bytes at the start\n")("Not an ELF file - it has the wrong magic bytes at the start\n"
)
);
3429 return 0;
3430 }
3431
3432 if (do_header)
3433 {
3434 int i;
3435
3436 printf (_("ELF Header:\n")("ELF Header:\n"));
3437 printf (_(" Magic: ")(" Magic: "));
3438 for (i = 0; i < EI_NIDENT16; i++)
3439 printf ("%2.2x ", elf_header.e_ident[i]);
3440 printf ("\n");
3441 printf (_(" Class: %s\n")(" Class: %s\n"),
3442 get_elf_class (elf_header.e_ident[EI_CLASS4]));
3443 printf (_(" Data: %s\n")(" Data: %s\n"),
3444 get_data_encoding (elf_header.e_ident[EI_DATA5]));
3445 printf (_(" Version: %d %s\n")(" Version: %d %s\n"),
3446 elf_header.e_ident[EI_VERSION6],
3447 (elf_header.e_ident[EI_VERSION6] == EV_CURRENT1
3448 ? "(current)"
3449 : (elf_header.e_ident[EI_VERSION6] != EV_NONE0
3450 ? "<unknown: %lx>"
3451 : "")));
3452 printf (_(" OS/ABI: %s\n")(" OS/ABI: %s\n"),
3453 get_osabi_name (elf_header.e_ident[EI_OSABI7]));
3454 printf (_(" ABI Version: %d\n")(" ABI Version: %d\n"),
3455 elf_header.e_ident[EI_ABIVERSION8]);
3456 printf (_(" Type: %s\n")(" Type: %s\n"),
3457 get_file_type (elf_header.e_type));
3458 printf (_(" Machine: %s\n")(" Machine: %s\n"),
3459 get_machine_name (elf_header.e_machine));
3460 printf (_(" Version: 0x%lx\n")(" Version: 0x%lx\n"),
3461 (unsigned long) elf_header.e_version);
3462
3463 printf (_(" Entry point address: ")(" Entry point address: "));
3464 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3465 printf (_("\n Start of program headers: ")("\n Start of program headers: "));
3466 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3467 printf (_(" (bytes into file)\n Start of section headers: ")(" (bytes into file)\n Start of section headers: "));
3468 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
3469 printf (_(" (bytes into file)\n")(" (bytes into file)\n"));
3470
3471 printf (_(" Flags: 0x%lx%s\n")(" Flags: 0x%lx%s\n"),
3472 (unsigned long) elf_header.e_flags,
3473 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
3474 printf (_(" Size of this header: %ld (bytes)\n")(" Size of this header: %ld (bytes)\n"),
3475 (long) elf_header.e_ehsize);
3476 printf (_(" Size of program headers: %ld (bytes)\n")(" Size of program headers: %ld (bytes)\n"),
3477 (long) elf_header.e_phentsize);
3478 printf (_(" Number of program headers: %ld")(" Number of program headers: %ld"),
3479 (long) elf_header.e_phnum);
3480 if (section_headers != NULL((void*)0) && elf_header.e_phnum == PN_XNUM0xffff)
3481 printf (" (%ld)", (long) section_headers[0].sh_info);
3482 putc ('\n', stdout)(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
3483 printf (_(" Size of section headers: %ld (bytes)\n")(" Size of section headers: %ld (bytes)\n"),
3484 (long) elf_header.e_shentsize);
3485 printf (_(" Number of section headers: %ld")(" Number of section headers: %ld"),
3486 (long) elf_header.e_shnum);
3487 if (section_headers != NULL((void*)0) && elf_header.e_shnum == 0)
3488 printf (" (%ld)", (long) section_headers[0].sh_size);
3489 putc ('\n', stdout)(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
3490 printf (_(" Section header string table index: %ld")(" Section header string table index: %ld"),
3491 (long) elf_header.e_shstrndx);
3492 if (section_headers != NULL((void*)0) && elf_header.e_shstrndx == SHN_XINDEX0xFFFF)
3493 printf (" (%ld)", (long) section_headers[0].sh_link);
3494 putc ('\n', stdout)(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
3495 }
3496
3497 if (section_headers != NULL((void*)0))
3498 {
3499 if (elf_header.e_phnum == PN_XNUM0xffff)
3500 elf_header.e_phnum = section_headers[0].sh_info;
3501 if (elf_header.e_shnum == 0)
3502 elf_header.e_shnum = section_headers[0].sh_size;
3503 if (elf_header.e_shstrndx == SHN_XINDEX0xFFFF)
3504 elf_header.e_shstrndx = section_headers[0].sh_link;
3505 free (section_headers);
3506 section_headers = NULL((void*)0);
3507 }
3508
3509 return 1;
3510}
3511
3512
3513static int
3514get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3515{
3516 Elf32_External_Phdr *phdrs;
3517 Elf32_External_Phdr *external;
3518 Elf_Internal_Phdr *internal;
3519 unsigned int i;
3520
3521 phdrs = get_data (NULL((void*)0), file, elf_header.e_phoff,
3522 elf_header.e_phentsize, elf_header.e_phnum,
3523 _("program headers")("program headers"));
3524 if (!phdrs)
3525 return 0;
3526
3527 for (i = 0, internal = program_headers, external = phdrs;
3528 i < elf_header.e_phnum;
3529 i++, internal++, external++)
3530 {
3531 internal->p_type = BYTE_GET (external->p_type)byte_get (external->p_type, sizeof (external->p_type));
3532 internal->p_offset = BYTE_GET (external->p_offset)byte_get (external->p_offset, sizeof (external->p_offset
))
;
3533 internal->p_vaddr = BYTE_GET (external->p_vaddr)byte_get (external->p_vaddr, sizeof (external->p_vaddr)
)
;
3534 internal->p_paddr = BYTE_GET (external->p_paddr)byte_get (external->p_paddr, sizeof (external->p_paddr)
)
;
3535 internal->p_filesz = BYTE_GET (external->p_filesz)byte_get (external->p_filesz, sizeof (external->p_filesz
))
;
3536 internal->p_memsz = BYTE_GET (external->p_memsz)byte_get (external->p_memsz, sizeof (external->p_memsz)
)
;
3537 internal->p_flags = BYTE_GET (external->p_flags)byte_get (external->p_flags, sizeof (external->p_flags)
)
;
3538 internal->p_align = BYTE_GET (external->p_align)byte_get (external->p_align, sizeof (external->p_align)
)
;
3539 }
3540
3541 free (phdrs);
3542
3543 return 1;
3544}
3545
3546static int
3547get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3548{
3549 Elf64_External_Phdr *phdrs;
3550 Elf64_External_Phdr *external;
3551 Elf_Internal_Phdr *internal;
3552 unsigned int i;
3553
3554 phdrs = get_data (NULL((void*)0), file, elf_header.e_phoff,
3555 elf_header.e_phentsize, elf_header.e_phnum,
3556 _("program headers")("program headers"));
3557 if (!phdrs)
3558 return 0;
3559
3560 for (i = 0, internal = program_headers, external = phdrs;
3561 i < elf_header.e_phnum;
3562 i++, internal++, external++)
3563 {
3564 internal->p_type = BYTE_GET (external->p_type)byte_get (external->p_type, sizeof (external->p_type));
3565 internal->p_flags = BYTE_GET (external->p_flags)byte_get (external->p_flags, sizeof (external->p_flags)
)
;
3566 internal->p_offset = BYTE_GET (external->p_offset)byte_get (external->p_offset, sizeof (external->p_offset
))
;
3567 internal->p_vaddr = BYTE_GET (external->p_vaddr)byte_get (external->p_vaddr, sizeof (external->p_vaddr)
)
;
3568 internal->p_paddr = BYTE_GET (external->p_paddr)byte_get (external->p_paddr, sizeof (external->p_paddr)
)
;
3569 internal->p_filesz = BYTE_GET (external->p_filesz)byte_get (external->p_filesz, sizeof (external->p_filesz
))
;
3570 internal->p_memsz = BYTE_GET (external->p_memsz)byte_get (external->p_memsz, sizeof (external->p_memsz)
)
;
3571 internal->p_align = BYTE_GET (external->p_align)byte_get (external->p_align, sizeof (external->p_align)
)
;
3572 }
3573
3574 free (phdrs);
3575
3576 return 1;
3577}
3578
3579/* Returns 1 if the program headers were read into `program_headers'. */
3580
3581static int
3582get_program_headers (FILE *file)
3583{
3584 Elf_Internal_Phdr *phdrs;
3585
3586 /* Check cache of prior read. */
3587 if (program_headers != NULL((void*)0))
3588 return 1;
3589
3590 phdrs = cmalloc (elf_header.e_phnum, sizeof (Elf_Internal_Phdr));
3591
3592 if (phdrs == NULL((void*)0))
3593 {
3594 error (_("Out of memory\n")("Out of memory\n"));
3595 return 0;
3596 }
3597
3598 if (is_32bit_elf
3599 ? get_32bit_program_headers (file, phdrs)
3600 : get_64bit_program_headers (file, phdrs))
3601 {
3602 program_headers = phdrs;
3603 return 1;
3604 }
3605
3606 free (phdrs);
3607 return 0;
3608}
3609
3610/* Returns 1 if the program headers were loaded. */
3611
3612static int
3613process_program_headers (FILE *file)
3614{
3615 Elf_Internal_Phdr *segment;
3616 unsigned int i;
3617
3618 if (elf_header.e_phnum == 0)
3619 {
3620 if (do_segments)
3621 printf (_("\nThere are no program headers in this file.\n")("\nThere are no program headers in this file.\n"));
3622 return 0;
3623 }
3624
3625 if (do_segments && !do_header)
3626 {
3627 printf (_("\nElf file type is %s\n")("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
3628 printf (_("Entry point ")("Entry point "));
3629 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3630 printf (_("\nThere are %d program headers, starting at offset ")("\nThere are %d program headers, starting at offset "),
3631 elf_header.e_phnum);
3632 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3633 printf ("\n");
3634 }
3635
3636 if (! get_program_headers (file))
3637 return 0;
3638
3639 if (do_segments)
3640 {
3641 if (elf_header.e_phnum > 1)
3642 printf (_("\nProgram Headers:\n")("\nProgram Headers:\n"));
3643 else
3644 printf (_("\nProgram Headers:\n")("\nProgram Headers:\n"));
3645
3646 if (is_32bit_elf)
3647 printf
3648 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"
)
);
3649 else if (do_wide)
3650 printf
3651 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"
)
);
3652 else
3653 {
3654 printf
3655 (_(" Type Offset VirtAddr PhysAddr\n")(" Type Offset VirtAddr PhysAddr\n"
)
);
3656 printf
3657 (_(" FileSiz MemSiz Flags Align\n")(" FileSiz MemSiz Flags Align\n"
)
);
3658 }
3659 }
3660
3661 dynamic_addr = 0;
3662 dynamic_size = 0;
3663
3664 for (i = 0, segment = program_headers;
3665 i < elf_header.e_phnum;
3666 i++, segment++)
3667 {
3668 if (do_segments)
3669 {
3670 printf (" %-14.14s ", get_segment_type (segment->p_type));
3671
3672 if (is_32bit_elf)
3673 {
3674 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3675 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
3676 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
3677 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
3678 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
3679 printf ("%c%c%c ",
3680 (segment->p_flags & PF_R(1 << 2) ? 'R' : ' '),
3681 (segment->p_flags & PF_W(1 << 1) ? 'W' : ' '),
3682 (segment->p_flags & PF_X(1 << 0) ? 'E' : ' '));
3683 printf ("%#lx", (unsigned long) segment->p_align);
3684 }
3685 else if (do_wide)
3686 {
3687 if ((unsigned long) segment->p_offset == segment->p_offset)
3688 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3689 else
3690 {
3691 print_vma (segment->p_offset, FULL_HEX);
3692 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
3693 }
3694
3695 print_vma (segment->p_vaddr, FULL_HEX);
3696 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
3697 print_vma (segment->p_paddr, FULL_HEX);
3698 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
3699
3700 if ((unsigned long) segment->p_filesz == segment->p_filesz)
3701 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
3702 else
3703 {
3704 print_vma (segment->p_filesz, FULL_HEX);
3705 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
3706 }
3707
3708 if ((unsigned long) segment->p_memsz == segment->p_memsz)
3709 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
3710 else
3711 {
3712 print_vma (segment->p_offset, FULL_HEX);
3713 }
3714
3715 printf (" %c%c%c ",
3716 (segment->p_flags & PF_R(1 << 2) ? 'R' : ' '),
3717 (segment->p_flags & PF_W(1 << 1) ? 'W' : ' '),
3718 (segment->p_flags & PF_X(1 << 0) ? 'E' : ' '));
3719
3720 if ((unsigned long) segment->p_align == segment->p_align)
3721 printf ("%#lx", (unsigned long) segment->p_align);
3722 else
3723 {
3724 print_vma (segment->p_align, PREFIX_HEX);
3725 }
3726 }
3727 else
3728 {
3729 print_vma (segment->p_offset, FULL_HEX);
3730 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
3731 print_vma (segment->p_vaddr, FULL_HEX);
3732 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
3733 print_vma (segment->p_paddr, FULL_HEX);
3734 printf ("\n ");
3735 print_vma (segment->p_filesz, FULL_HEX);
3736 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
3737 print_vma (segment->p_memsz, FULL_HEX);
3738 printf (" %c%c%c ",
3739 (segment->p_flags & PF_R(1 << 2) ? 'R' : ' '),
3740 (segment->p_flags & PF_W(1 << 1) ? 'W' : ' '),
3741 (segment->p_flags & PF_X(1 << 0) ? 'E' : ' '));
3742 print_vma (segment->p_align, HEX);
3743 }
3744 }
3745
3746 switch (segment->p_type)
3747 {
3748 case PT_DYNAMIC2:
3749 if (dynamic_addr)
3750 error (_("more than one dynamic segment\n")("more than one dynamic segment\n"));
3751
3752 /* Try to locate the .dynamic section. If there is
3753 a section header table, we can easily locate it. */
3754 if (section_headers != NULL((void*)0))
3755 {
3756 Elf_Internal_Shdr *sec;
3757
3758 sec = find_section (".dynamic");
3759 if (sec == NULL((void*)0) || sec->sh_size == 0)
3760 {
3761 error (_("no .dynamic section in the dynamic segment")("no .dynamic section in the dynamic segment"));
3762 break;
3763 }
3764
3765 dynamic_addr = sec->sh_offset;
3766 dynamic_size = sec->sh_size;
3767
3768 if (dynamic_addr < segment->p_offset
3769 || dynamic_addr > segment->p_offset + segment->p_filesz)
3770 warn (_("the .dynamic section is not contained within the dynamic segment")("the .dynamic section is not contained within the dynamic segment"
)
);
3771 else if (dynamic_addr > segment->p_offset)
3772 warn (_("the .dynamic section is not the first section in the dynamic segment.")("the .dynamic section is not the first section in the dynamic segment."
)
);
3773 }
3774 else
3775 {
3776 /* Otherwise, we can only assume that the .dynamic
3777 section is the first section in the DYNAMIC segment. */
3778 dynamic_addr = segment->p_offset;
3779 dynamic_size = segment->p_filesz;
3780 }
3781 break;
3782
3783 case PT_INTERP3:
3784 if (fseek (file, archive_file_offset + (long) segment->p_offset,
3785 SEEK_SET0))
3786 error (_("Unable to find program interpreter name\n")("Unable to find program interpreter name\n"));
3787 else
3788 {
3789 program_interpreter[0] = 0;
3790 fscanf (file, "%63s", program_interpreter);
3791
3792 if (do_segments)
3793 printf (_("\n [Requesting program interpreter: %s]")("\n [Requesting program interpreter: %s]"),
3794 program_interpreter);
3795 }
3796 break;
3797 }
3798
3799 if (do_segments)
3800 putc ('\n', stdout)(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
3801 }
3802
3803 if (do_segments && section_headers != NULL((void*)0) && string_table != NULL((void*)0))
3804 {
3805 printf (_("\n Section to Segment mapping:\n")("\n Section to Segment mapping:\n"));
3806 printf (_(" Segment Sections...\n")(" Segment Sections...\n"));
3807
3808 for (i = 0; i < elf_header.e_phnum; i++)
3809 {
3810 unsigned int j;
3811 Elf_Internal_Shdr *section;
3812
3813 segment = program_headers + i;
3814 section = section_headers;
3815
3816 printf (" %2.2d ", i);
3817
3818 for (j = 1; j < elf_header.e_shnum; j++, section++)
3819 {
3820 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section, segment)((section->sh_size > 0 && (segment->p_type !=
7 || (section->sh_flags & (1 << 10)) != 0) &&
(section->sh_flags & (1 << 1) ? (section->sh_addr
>= segment->p_vaddr && section->sh_addr + section
->sh_size <= segment->p_vaddr + segment->p_memsz)
: ((bfd_vma) section->sh_offset >= segment->p_offset
&& (section->sh_offset + section->sh_size <=
segment->p_offset + segment->p_filesz)))) && (
!((section->sh_flags & (1 << 10)) != 0 &&
section->sh_type == 8) || segment->p_type == 7))
)
3821 printf ("%s ", SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
3822 }
3823
3824 putc ('\n',stdout)(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
3825 }
3826 }
3827
3828 return 1;
3829}
3830
3831
3832/* Find the file offset corresponding to VMA by using the program headers. */
3833
3834static long
3835offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
3836{
3837 Elf_Internal_Phdr *seg;
3838
3839 if (! get_program_headers (file))
3840 {
3841 warn (_("Cannot interpret virtual addresses without program headers.\n")("Cannot interpret virtual addresses without program headers.\n"
)
);
3842 return (long) vma;
3843 }
3844
3845 for (seg = program_headers;
3846 seg < program_headers + elf_header.e_phnum;
3847 ++seg)
3848 {
3849 if (seg->p_type != PT_LOAD1)
3850 continue;
3851
3852 if (vma >= (seg->p_vaddr & -seg->p_align)
3853 && vma + size <= seg->p_vaddr + seg->p_filesz)
3854 return vma - seg->p_vaddr + seg->p_offset;
3855 }
3856
3857 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n")("Virtual address 0x%lx not located in any PT_LOAD segment.\n"
)
,
3858 (long) vma);
3859 return (long) vma;
3860}
3861
3862
3863static int
3864get_32bit_section_headers (FILE *file, unsigned int num)
3865{
3866 Elf32_External_Shdr *shdrs;
3867 Elf_Internal_Shdr *internal;
3868 unsigned int i;
3869
3870 shdrs = get_data (NULL((void*)0), file, elf_header.e_shoff,
3871 elf_header.e_shentsize, num, _("section headers")("section headers"));
3872 if (!shdrs)
3873 return 0;
3874
3875 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3876
3877 if (section_headers == NULL((void*)0))
3878 {
3879 error (_("Out of memory\n")("Out of memory\n"));
3880 return 0;
3881 }
3882
3883 for (i = 0, internal = section_headers;
3884 i < num;
3885 i++, internal++)
3886 {
3887 internal->sh_name = BYTE_GET (shdrs[i].sh_name)byte_get (shdrs[i].sh_name, sizeof (shdrs[i].sh_name));
3888 internal->sh_type = BYTE_GET (shdrs[i].sh_type)byte_get (shdrs[i].sh_type, sizeof (shdrs[i].sh_type));
3889 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags)byte_get (shdrs[i].sh_flags, sizeof (shdrs[i].sh_flags));
3890 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr)byte_get (shdrs[i].sh_addr, sizeof (shdrs[i].sh_addr));
3891 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset)byte_get (shdrs[i].sh_offset, sizeof (shdrs[i].sh_offset));
3892 internal->sh_size = BYTE_GET (shdrs[i].sh_size)byte_get (shdrs[i].sh_size, sizeof (shdrs[i].sh_size));
3893 internal->sh_link = BYTE_GET (shdrs[i].sh_link)byte_get (shdrs[i].sh_link, sizeof (shdrs[i].sh_link));
3894 internal->sh_info = BYTE_GET (shdrs[i].sh_info)byte_get (shdrs[i].sh_info, sizeof (shdrs[i].sh_info));
3895 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign)byte_get (shdrs[i].sh_addralign, sizeof (shdrs[i].sh_addralign
))
;
3896 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize)byte_get (shdrs[i].sh_entsize, sizeof (shdrs[i].sh_entsize));
3897 }
3898
3899 free (shdrs);
3900
3901 return 1;
3902}
3903
3904static int
3905get_64bit_section_headers (FILE *file, unsigned int num)
3906{
3907 Elf64_External_Shdr *shdrs;
3908 Elf_Internal_Shdr *internal;
3909 unsigned int i;
3910
3911 shdrs = get_data (NULL((void*)0), file, elf_header.e_shoff,
3912 elf_header.e_shentsize, num, _("section headers")("section headers"));
3913 if (!shdrs)
3914 return 0;
3915
3916 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3917
3918 if (section_headers == NULL((void*)0))
3919 {
3920 error (_("Out of memory\n")("Out of memory\n"));
3921 return 0;
3922 }
3923
3924 for (i = 0, internal = section_headers;
3925 i < num;
3926 i++, internal++)
3927 {
3928 internal->sh_name = BYTE_GET (shdrs[i].sh_name)byte_get (shdrs[i].sh_name, sizeof (shdrs[i].sh_name));
3929 internal->sh_type = BYTE_GET (shdrs[i].sh_type)byte_get (shdrs[i].sh_type, sizeof (shdrs[i].sh_type));
3930 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags)byte_get (shdrs[i].sh_flags, sizeof (shdrs[i].sh_flags));
3931 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr)byte_get (shdrs[i].sh_addr, sizeof (shdrs[i].sh_addr));
3932 internal->sh_size = BYTE_GET (shdrs[i].sh_size)byte_get (shdrs[i].sh_size, sizeof (shdrs[i].sh_size));
3933 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize)byte_get (shdrs[i].sh_entsize, sizeof (shdrs[i].sh_entsize));
3934 internal->sh_link = BYTE_GET (shdrs[i].sh_link)byte_get (shdrs[i].sh_link, sizeof (shdrs[i].sh_link));
3935 internal->sh_info = BYTE_GET (shdrs[i].sh_info)byte_get (shdrs[i].sh_info, sizeof (shdrs[i].sh_info));
3936 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset)byte_get (shdrs[i].sh_offset, sizeof (shdrs[i].sh_offset));
3937 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign)byte_get (shdrs[i].sh_addralign, sizeof (shdrs[i].sh_addralign
))
;
3938 }
3939
3940 free (shdrs);
3941
3942 return 1;
3943}
3944
3945static Elf_Internal_Sym *
3946get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3947{
3948 unsigned long number;
3949 Elf32_External_Sym *esyms;
3950 Elf_External_Sym_Shndx *shndx;
3951 Elf_Internal_Sym *isyms;
3952 Elf_Internal_Sym *psym;
3953 unsigned int j;
3954
3955 esyms = get_data (NULL((void*)0), file, section->sh_offset, 1, section->sh_size,
3956 _("symbols")("symbols"));
3957 if (!esyms)
3958 return NULL((void*)0);
3959
3960 shndx = NULL((void*)0);
3961 if (symtab_shndx_hdr != NULL((void*)0)
3962 && (symtab_shndx_hdr->sh_link
3963 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)((section - section_headers) < 0xFF00 ? (section - section_headers
) : (section - section_headers) + (0xFFFF + 1 - 0xFF00))
))
3964 {
3965 shndx = get_data (NULL((void*)0), file, symtab_shndx_hdr->sh_offset,
3966 1, symtab_shndx_hdr->sh_size, _("symtab shndx")("symtab shndx"));
3967 if (!shndx)
3968 {
3969 free (esyms);
3970 return NULL((void*)0);
3971 }
3972 }
3973
3974 number = section->sh_size / section->sh_entsize;
3975 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3976
3977 if (isyms == NULL((void*)0))
3978 {
3979 error (_("Out of memory\n")("Out of memory\n"));
3980 if (shndx)
3981 free (shndx);
3982 free (esyms);
3983 return NULL((void*)0);
3984 }
3985
3986 for (j = 0, psym = isyms;
3987 j < number;
3988 j++, psym++)
3989 {
3990 psym->st_name = BYTE_GET (esyms[j].st_name)byte_get (esyms[j].st_name, sizeof (esyms[j].st_name));
3991 psym->st_value = BYTE_GET (esyms[j].st_value)byte_get (esyms[j].st_value, sizeof (esyms[j].st_value));
3992 psym->st_size = BYTE_GET (esyms[j].st_size)byte_get (esyms[j].st_size, sizeof (esyms[j].st_size));
3993 psym->st_shndx = BYTE_GET (esyms[j].st_shndx)byte_get (esyms[j].st_shndx, sizeof (esyms[j].st_shndx));
3994 if (psym->st_shndx == SHN_XINDEX0xFFFF && shndx != NULL((void*)0))
3995 psym->st_shndx
3996 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3997 psym->st_info = BYTE_GET (esyms[j].st_info)byte_get (esyms[j].st_info, sizeof (esyms[j].st_info));
3998 psym->st_other = BYTE_GET (esyms[j].st_other)byte_get (esyms[j].st_other, sizeof (esyms[j].st_other));
3999 }
4000
4001 if (shndx)
4002 free (shndx);
4003 free (esyms);
4004
4005 return isyms;
4006}
4007
4008static Elf_Internal_Sym *
4009get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
4010{
4011 unsigned long number;
4012 Elf64_External_Sym *esyms;
4013 Elf_External_Sym_Shndx *shndx;
4014 Elf_Internal_Sym *isyms;
4015 Elf_Internal_Sym *psym;
4016 unsigned int j;
4017
4018 esyms = get_data (NULL((void*)0), file, section->sh_offset, 1, section->sh_size,
4019 _("symbols")("symbols"));
4020 if (!esyms)
4021 return NULL((void*)0);
4022
4023 shndx = NULL((void*)0);
4024 if (symtab_shndx_hdr != NULL((void*)0)
4025 && (symtab_shndx_hdr->sh_link
4026 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)((section - section_headers) < 0xFF00 ? (section - section_headers
) : (section - section_headers) + (0xFFFF + 1 - 0xFF00))
))
4027 {
4028 shndx = get_data (NULL((void*)0), file, symtab_shndx_hdr->sh_offset,
4029 1, symtab_shndx_hdr->sh_size, _("symtab shndx")("symtab shndx"));
4030 if (!shndx)
4031 {
4032 free (esyms);
4033 return NULL((void*)0);
4034 }
4035 }
4036
4037 number = section->sh_size / section->sh_entsize;
4038 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
4039
4040 if (isyms == NULL((void*)0))
4041 {
4042 error (_("Out of memory\n")("Out of memory\n"));
4043 if (shndx)
4044 free (shndx);
4045 free (esyms);
4046 return NULL((void*)0);
4047 }
4048
4049 for (j = 0, psym = isyms;
4050 j < number;
4051 j++, psym++)
4052 {
4053 psym->st_name = BYTE_GET (esyms[j].st_name)byte_get (esyms[j].st_name, sizeof (esyms[j].st_name));
4054 psym->st_info = BYTE_GET (esyms[j].st_info)byte_get (esyms[j].st_info, sizeof (esyms[j].st_info));
4055 psym->st_other = BYTE_GET (esyms[j].st_other)byte_get (esyms[j].st_other, sizeof (esyms[j].st_other));
4056 psym->st_shndx = BYTE_GET (esyms[j].st_shndx)byte_get (esyms[j].st_shndx, sizeof (esyms[j].st_shndx));
4057 if (psym->st_shndx == SHN_XINDEX0xFFFF && shndx != NULL((void*)0))
4058 psym->st_shndx
4059 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4060 psym->st_value = BYTE_GET (esyms[j].st_value)byte_get (esyms[j].st_value, sizeof (esyms[j].st_value));
4061 psym->st_size = BYTE_GET (esyms[j].st_size)byte_get (esyms[j].st_size, sizeof (esyms[j].st_size));
4062 }
4063
4064 if (shndx)
4065 free (shndx);
4066 free (esyms);
4067
4068 return isyms;
4069}
4070
4071static const char *
4072get_elf_section_flags (bfd_vma sh_flags)
4073{
4074 static char buff[1024];
4075 char *p = buff;
4076 int field_size = is_32bit_elf ? 8 : 16;
4077 int index, size = sizeof (buff) - (field_size + 4 + 1);
4078 bfd_vma os_flags = 0;
4079 bfd_vma proc_flags = 0;
4080 bfd_vma unknown_flags = 0;
4081 const struct
4082 {
4083 const char *str;
4084 int len;
4085 }
4086 flags [] =
4087 {
4088 { "WRITE", 5 },
4089 { "ALLOC", 5 },
4090 { "EXEC", 4 },
4091 { "MERGE", 5 },
4092 { "STRINGS", 7 },
4093 { "INFO LINK", 9 },
4094 { "LINK ORDER", 10 },
4095 { "OS NONCONF", 10 },
4096 { "GROUP", 5 },
4097 { "TLS", 3 }
4098 };
4099
4100 if (do_section_details)
4101 {
4102 sprintf (buff, "[%*.*lx]: ",
4103 field_size, field_size, (unsigned long) sh_flags);
4104 p += field_size + 4;
4105 }
4106
4107 while (sh_flags)
4108 {
4109 bfd_vma flag;
4110
4111 flag = sh_flags & - sh_flags;
4112 sh_flags &= ~ flag;
4113
4114 if (do_section_details)
4115 {
4116 switch (flag)
4117 {
4118 case SHF_WRITE(1 << 0): index = 0; break;
4119 case SHF_ALLOC(1 << 1): index = 1; break;
4120 case SHF_EXECINSTR(1 << 2): index = 2; break;
4121 case SHF_MERGE(1 << 4): index = 3; break;
4122 case SHF_STRINGS(1 << 5): index = 4; break;
4123 case SHF_INFO_LINK(1 << 6): index = 5; break;
4124 case SHF_LINK_ORDER(1 << 7): index = 6; break;
4125 case SHF_OS_NONCONFORMING(1 << 8): index = 7; break;
4126 case SHF_GROUP(1 << 9): index = 8; break;
4127 case SHF_TLS(1 << 10): index = 9; break;
4128
4129 default:
4130 index = -1;
4131 break;
4132 }
4133
4134 if (index != -1)
4135 {
4136 if (p != buff + field_size + 4)
4137 {
4138 if (size < (10 + 2))
4139 abort ();
4140 size -= 2;
4141 *p++ = ',';
4142 *p++ = ' ';
4143 }
4144
4145 size -= flags [index].len;
4146#if 0
4147 p = stpcpy (p, flags [index].str);
4148#else
4149 strcpy (p, flags [index].str);
4150 p += strlen(p);
4151#endif
4152 }
4153 else if (flag & SHF_MASKOS0x0FF00000)
4154 os_flags |= flag;
4155 else if (flag & SHF_MASKPROC0xF0000000)
4156 proc_flags |= flag;
4157 else
4158 unknown_flags |= flag;
4159 }
4160 else
4161 {
4162 switch (flag)
4163 {
4164 case SHF_WRITE(1 << 0): *p = 'W'; break;
4165 case SHF_ALLOC(1 << 1): *p = 'A'; break;
4166 case SHF_EXECINSTR(1 << 2): *p = 'X'; break;
4167 case SHF_MERGE(1 << 4): *p = 'M'; break;
4168 case SHF_STRINGS(1 << 5): *p = 'S'; break;
4169 case SHF_INFO_LINK(1 << 6): *p = 'I'; break;
4170 case SHF_LINK_ORDER(1 << 7): *p = 'L'; break;
4171 case SHF_OS_NONCONFORMING(1 << 8): *p = 'O'; break;
4172 case SHF_GROUP(1 << 9): *p = 'G'; break;
4173 case SHF_TLS(1 << 10): *p = 'T'; break;
4174
4175 default:
4176 if (elf_header.e_machine == EM_X86_6462
4177 && flag == SHF_X86_64_LARGE0x10000000)
4178 *p = 'l';
4179 else if (flag & SHF_MASKOS0x0FF00000)
4180 {
4181 *p = 'o';
4182 sh_flags &= ~ SHF_MASKOS0x0FF00000;
4183 }
4184 else if (flag & SHF_MASKPROC0xF0000000)
4185 {
4186 *p = 'p';
4187 sh_flags &= ~ SHF_MASKPROC0xF0000000;
4188 }
4189 else
4190 *p = 'x';
4191 break;
4192 }
4193 p++;
4194 }
4195 }
4196
4197 if (do_section_details)
4198 {
4199 if (os_flags)
4200 {
4201 size -= 5 + field_size;
4202 if (p != buff + field_size + 4)
4203 {
4204 if (size < (2 + 1))
4205 abort ();
4206 size -= 2;
4207 *p++ = ',';
4208 *p++ = ' ';
4209 }
4210 sprintf (p, "OS (%*.*lx)", field_size, field_size,
4211 (unsigned long) os_flags);
4212 p += 5 + field_size;
4213 }
4214 if (proc_flags)
4215 {
4216 size -= 7 + field_size;
4217 if (p != buff + field_size + 4)
4218 {
4219 if (size < (2 + 1))
4220 abort ();
4221 size -= 2;
4222 *p++ = ',';
4223 *p++ = ' ';
4224 }
4225 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
4226 (unsigned long) proc_flags);
4227 p += 7 + field_size;
4228 }
4229 if (unknown_flags)
4230 {
4231 size -= 10 + field_size;
4232 if (p != buff + field_size + 4)
4233 {
4234 if (size < (2 + 1))
4235 abort ();
4236 size -= 2;
4237 *p++ = ',';
4238 *p++ = ' ';
4239 }
4240 sprintf (p, "UNKNOWN (%*.*lx)", field_size, field_size,
4241 (unsigned long) unknown_flags);
4242 p += 10 + field_size;
4243 }
4244 }
4245
4246 *p = '\0';
4247 return buff;
4248}
4249
4250static int
4251process_section_headers (FILE *file)
4252{
4253 Elf_Internal_Shdr *section;
4254 unsigned int i;
4255
4256 section_headers = NULL((void*)0);
4257
4258 if (elf_header.e_shnum == 0)
4259 {
4260 if (do_sections)
4261 printf (_("\nThere are no sections in this file.\n")("\nThere are no sections in this file.\n"));
4262
4263 return 1;
4264 }
4265
4266 if (do_sections && !do_header)
4267 printf (_("There are %d section headers, starting at offset 0x%lx:\n")("There are %d section headers, starting at offset 0x%lx:\n"),
4268 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
4269
4270 if (is_32bit_elf)
4271 {
4272 if (! get_32bit_section_headers (file, elf_header.e_shnum))
4273 return 0;
4274 }
4275 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
4276 return 0;
4277
4278 /* Read in the string table, so that we have names to display. */
4279 if (SECTION_HEADER_INDEX (elf_header.e_shstrndx)((elf_header.e_shstrndx) < 0xFF00 ? (elf_header.e_shstrndx
) : ((elf_header.e_shstrndx) <= 0xFFFF ? 0 : (elf_header.e_shstrndx
) - (0xFFFF + 1 - 0xFF00)))
< elf_header.e_shnum)
4280 {
4281 section = SECTION_HEADER (elf_header.e_shstrndx)(section_headers + ((elf_header.e_shstrndx) < 0xFF00 ? (elf_header
.e_shstrndx) : ((elf_header.e_shstrndx) <= 0xFFFF ? 0 : (elf_header
.e_shstrndx) - (0xFFFF + 1 - 0xFF00))))
;
4282
4283 if (section->sh_size != 0)
4284 {
4285 string_table = get_data (NULL((void*)0), file, section->sh_offset,
4286 1, section->sh_size, _("string table")("string table"));
4287
4288 string_table_length = string_table != NULL((void*)0) ? section->sh_size : 0;
4289 }
4290 }
4291
4292 /* Scan the sections for the dynamic symbol table
4293 and dynamic string table and debug sections. */
4294 dynamic_symbols = NULL((void*)0);
4295 dynamic_strings = NULL((void*)0);
4296 dynamic_syminfo = NULL((void*)0);
4297 symtab_shndx_hdr = NULL((void*)0);
4298
4299 eh_addr_size = is_32bit_elf ? 4 : 8;
4300 switch (elf_header.e_machine)
4301 {
4302 case EM_MIPS8:
4303 case EM_MIPS_RS3_LE10:
4304 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4305 FDE addresses. However, the ABI also has a semi-official ILP32
4306 variant for which the normal FDE address size rules apply.
4307
4308 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4309 section, where XX is the size of longs in bits. Unfortunately,
4310 earlier compilers provided no way of distinguishing ILP32 objects
4311 from LP64 objects, so if there's any doubt, we should assume that
4312 the official LP64 form is being used. */
4313 if ((elf_header.e_flags & EF_MIPS_ABI0x0000F000) == E_MIPS_ABI_EABI640x00004000
4314 && find_section (".gcc_compiled_long32") == NULL((void*)0))
4315 eh_addr_size = 8;
4316 break;
4317 }
4318
4319#define CHECK_ENTSIZE_VALUES(section, i, size32, size64)do { size_t expected_entsize = is_32bit_elf ? size32 : size64
; if (section->sh_entsize != expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
\
4320 do \
4321 { \
4322 size_t expected_entsize \
4323 = is_32bit_elf ? size32 : size64; \
4324 if (section->sh_entsize != expected_entsize) \
4325 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n")("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4326 i, (unsigned long int) section->sh_entsize, \
4327 (unsigned long int) expected_entsize); \
4328 section->sh_entsize = expected_entsize; \
4329 } \
4330 while (0)
4331#define CHECK_ENTSIZE(section, i, type)do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_type
) : sizeof (Elf64_External_type); if (section->sh_entsize !=
expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
\
4332 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_
##type) : sizeof (Elf64_External_##type); if (section->sh_entsize
!= expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
4333 sizeof (Elf64_External_##type))do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_
##type) : sizeof (Elf64_External_##type); if (section->sh_entsize
!= expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
4334
4335 for (i = 0, section = section_headers;
4336 i < elf_header.e_shnum;
4337 i++, section++)
4338 {
4339 char *name = SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
;
4340
4341 if (section->sh_type == SHT_DYNSYM11)
4342 {
4343 if (dynamic_symbols != NULL((void*)0))
4344 {
4345 error (_("File contains multiple dynamic symbol tables\n")("File contains multiple dynamic symbol tables\n"));
4346 continue;
4347 }
4348
4349 CHECK_ENTSIZE (section, i, Sym)do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_Sym
) : sizeof (Elf64_External_Sym); if (section->sh_entsize !=
expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
;
4350 num_dynamic_syms = section->sh_size / section->sh_entsize;
4351 dynamic_symbols = GET_ELF_SYMBOLS (file, section)(is_32bit_elf ? get_32bit_elf_symbols (file, section) : get_64bit_elf_symbols
(file, section))
;
4352 }
4353 else if (section->sh_type == SHT_STRTAB3
4354 && streq (name, ".dynstr")(strcmp ((name), (".dynstr")) == 0))
4355 {
4356 if (dynamic_strings != NULL((void*)0))
4357 {
4358 error (_("File contains multiple dynamic string tables\n")("File contains multiple dynamic string tables\n"));
4359 continue;
4360 }
4361
4362 dynamic_strings = get_data (NULL((void*)0), file, section->sh_offset,
4363 1, section->sh_size, _("dynamic strings")("dynamic strings"));
4364 dynamic_strings_length = section->sh_size;
4365 }
4366 else if (section->sh_type == SHT_SYMTAB_SHNDX18)
4367 {
4368 if (symtab_shndx_hdr != NULL((void*)0))
4369 {
4370 error (_("File contains multiple symtab shndx tables\n")("File contains multiple symtab shndx tables\n"));
4371 continue;
4372 }
4373 symtab_shndx_hdr = section;
4374 }
4375 else if (section->sh_type == SHT_SYMTAB2)
4376 CHECK_ENTSIZE (section, i, Sym)do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_Sym
) : sizeof (Elf64_External_Sym); if (section->sh_entsize !=
expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
;
4377 else if (section->sh_type == SHT_GROUP17)
4378 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE)do { size_t expected_entsize = is_32bit_elf ? 4 : 4; if (section
->sh_entsize != expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
;
4379 else if (section->sh_type == SHT_REL9)
4380 CHECK_ENTSIZE (section, i, Rel)do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_Rel
) : sizeof (Elf64_External_Rel); if (section->sh_entsize !=
expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
;
4381 else if (section->sh_type == SHT_RELA4)
4382 CHECK_ENTSIZE (section, i, Rela)do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_Rela
) : sizeof (Elf64_External_Rela); if (section->sh_entsize !=
expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
;
4383 else if (section->sh_type == SHT_RELR19)
4384 CHECK_ENTSIZE (section, i, Relr)do { size_t expected_entsize = is_32bit_elf ? sizeof (Elf32_External_Relr
) : sizeof (Elf64_External_Relr); if (section->sh_entsize !=
expected_entsize) error (("Section %d has invalid sh_entsize %lx (expected %lx)\n"
), i, (unsigned long int) section->sh_entsize, (unsigned long
int) expected_entsize); section->sh_entsize = expected_entsize
; } while (0)
;
4385 else if ((do_debugging || do_debug_info || do_debug_abbrevs
4386 || do_debug_lines || do_debug_pubnames || do_debug_aranges
4387 || do_debug_frames || do_debug_macinfo || do_debug_str
4388 || do_debug_loc || do_debug_ranges)
4389 && strneq (name, ".debug_", 7)(strncmp ((name), (".debug_"), (7)) == 0))
4390 {
4391 name += 7;
4392
4393 if (do_debugging
4394 || (do_debug_info && streq (name, "info")(strcmp ((name), ("info")) == 0))
4395 || (do_debug_abbrevs && streq (name, "abbrev")(strcmp ((name), ("abbrev")) == 0))
4396 || (do_debug_lines && streq (name, "line")(strcmp ((name), ("line")) == 0))
4397 || (do_debug_pubnames && streq (name, "pubnames")(strcmp ((name), ("pubnames")) == 0))
4398 || (do_debug_aranges && streq (name, "aranges")(strcmp ((name), ("aranges")) == 0))
4399 || (do_debug_ranges && streq (name, "ranges")(strcmp ((name), ("ranges")) == 0))
4400 || (do_debug_frames && streq (name, "frame")(strcmp ((name), ("frame")) == 0))
4401 || (do_debug_macinfo && streq (name, "macinfo")(strcmp ((name), ("macinfo")) == 0))
4402 || (do_debug_str && streq (name, "str")(strcmp ((name), ("str")) == 0))
4403 || (do_debug_loc && streq (name, "loc")(strcmp ((name), ("loc")) == 0))
4404 )
4405 request_dump (i, DEBUG_DUMP(1 << 2));
4406 }
4407 /* linkonce section to be combined with .debug_info at link time. */
4408 else if ((do_debugging || do_debug_info)
4409 && strneq (name, ".gnu.linkonce.wi.", 17)(strncmp ((name), (".gnu.linkonce.wi."), (17)) == 0))
4410 request_dump (i, DEBUG_DUMP(1 << 2));
4411 else if (do_debug_frames && streq (name, ".eh_frame")(strcmp ((name), (".eh_frame")) == 0))
4412 request_dump (i, DEBUG_DUMP(1 << 2));
4413 }
4414
4415 if (! do_sections)
4416 return 1;
4417
4418 if (elf_header.e_shnum > 1)
4419 printf (_("\nSection Headers:\n")("\nSection Headers:\n"));
4420 else
4421 printf (_("\nSection Header:\n")("\nSection Header:\n"));
4422
4423 if (is_32bit_elf)
4424 {
4425 if (do_section_details)
4426 {
4427 printf (_(" [Nr] Name\n")(" [Nr] Name\n"));
4428 printf (_(" Type Addr Off Size ES Lk Inf Al\n")(" Type Addr Off Size ES Lk Inf Al\n"
)
);
4429 }
4430 else
4431 printf
4432 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"
)
);
4433 }
4434 else if (do_wide)
4435 {
4436 if (do_section_details)
4437 {
4438 printf (_(" [Nr] Name\n")(" [Nr] Name\n"));
4439 printf (_(" Type Address Off Size ES Lk Inf Al\n")(" Type Address Off Size ES Lk Inf Al\n"
)
);
4440 }
4441 else
4442 printf
4443 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"
)
);
4444 }
4445 else
4446 {
4447 if (do_section_details)
4448 {
4449 printf (_(" [Nr] Name\n")(" [Nr] Name\n"));
4450 printf (_(" Type Address Offset Link\n")(" Type Address Offset Link\n"
)
);
4451 printf (_(" Size EntSize Info Align\n")(" Size EntSize Info Align\n"
)
);
4452 }
4453 else
4454 {
4455 printf (_(" [Nr] Name Type Address Offset\n")(" [Nr] Name Type Address Offset\n"
)
);
4456 printf (_(" Size EntSize Flags Link Info Align\n")(" Size EntSize Flags Link Info Align\n"
)
);
4457 }
4458 }
4459
4460 if (do_section_details)
4461 printf (_(" Flags\n")(" Flags\n"));
4462
4463 for (i = 0, section = section_headers;
4464 i < elf_header.e_shnum;
4465 i++, section++)
4466 {
4467 if (do_section_details)
4468 {
4469 printf (" [%2u] %s\n",
4470 SECTION_HEADER_NUM (i)((i) < 0xFF00 ? (i) : (i) + (0xFFFF + 1 - 0xFF00)),
4471 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
4472 if (is_32bit_elf || do_wide)
4473 printf (" %-15.15s ",
4474 get_section_type_name (section->sh_type));
4475 }
4476 else
4477 printf (" [%2u] %-17.17s %-15.15s ",
4478 SECTION_HEADER_NUM (i)((i) < 0xFF00 ? (i) : (i) + (0xFFFF + 1 - 0xFF00)),
4479 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
,
4480 get_section_type_name (section->sh_type));
4481
4482 if (is_32bit_elf)
4483 {
4484 print_vma (section->sh_addr, LONG_HEX);
4485
4486 printf ( " %6.6lx %6.6lx %2.2lx",
4487 (unsigned long) section->sh_offset,
4488 (unsigned long) section->sh_size,
4489 (unsigned long) section->sh_entsize);
4490
4491 if (do_section_details)
4492 fputs (" ", stdout(&__sF[1]));
4493 else
4494 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4495
4496 printf ("%2ld %3lu %2ld\n",
4497 (unsigned long) section->sh_link,
4498 (unsigned long) section->sh_info,
4499 (unsigned long) section->sh_addralign);
4500 }
4501 else if (do_wide)
4502 {
4503 print_vma (section->sh_addr, LONG_HEX);
4504
4505 if ((long) section->sh_offset == section->sh_offset)
4506 printf (" %6.6lx", (unsigned long) section->sh_offset);
4507 else
4508 {
4509 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
4510 print_vma (section->sh_offset, LONG_HEX);
4511 }
4512
4513 if ((unsigned long) section->sh_size == section->sh_size)
4514 printf (" %6.6lx", (unsigned long) section->sh_size);
4515 else
4516 {
4517 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
4518 print_vma (section->sh_size, LONG_HEX);
4519 }
4520
4521 if ((unsigned long) section->sh_entsize == section->sh_entsize)
4522 printf (" %2.2lx", (unsigned long) section->sh_entsize);
4523 else
4524 {
4525 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
4526 print_vma (section->sh_entsize, LONG_HEX);
4527 }
4528
4529 if (do_section_details)
4530 fputs (" ", stdout(&__sF[1]));
4531 else
4532 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4533
4534 printf ("%2ld %3lu ",
4535 (unsigned long) section->sh_link,
4536 (unsigned long) section->sh_info);
4537
4538 if ((unsigned long) section->sh_addralign == section->sh_addralign)
4539 printf ("%2ld\n", (unsigned long) section->sh_addralign);
4540 else
4541 {
4542 print_vma (section->sh_addralign, DEC);
4543 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
4544 }
4545 }
4546 else if (do_section_details)
4547 {
4548 printf (" %-15.15s ",
4549 get_section_type_name (section->sh_type));
4550 print_vma (section->sh_addr, LONG_HEX);
4551 if ((long) section->sh_offset == section->sh_offset)
4552 printf (" %16.16lx", (unsigned long) section->sh_offset);
4553 else
4554 {
4555 printf (" ");
4556 print_vma (section->sh_offset, LONG_HEX);
4557 }
4558 printf (" %ld\n ", (unsigned long) section->sh_link);
4559 print_vma (section->sh_size, LONG_HEX);
4560 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
4561 print_vma (section->sh_entsize, LONG_HEX);
4562
4563 printf (" %-16lu %ld\n",
4564 (unsigned long) section->sh_info,
4565 (unsigned long) section->sh_addralign);
4566 }
4567 else
4568 {
4569 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
4570 print_vma (section->sh_addr, LONG_HEX);
4571 if ((long) section->sh_offset == section->sh_offset)
4572 printf (" %8.8lx", (unsigned long) section->sh_offset);
4573 else
4574 {
4575 printf (" ");
4576 print_vma (section->sh_offset, LONG_HEX);
4577 }
4578 printf ("\n ");
4579 print_vma (section->sh_size, LONG_HEX);
4580 printf (" ");
4581 print_vma (section->sh_entsize, LONG_HEX);
4582
4583 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4584
4585 printf (" %2ld %3lu %ld\n",
4586 (unsigned long) section->sh_link,
4587 (unsigned long) section->sh_info,
4588 (unsigned long) section->sh_addralign);
4589 }
4590
4591 if (do_section_details)
4592 printf (" %s\n", get_elf_section_flags (section->sh_flags));
4593 }
4594
4595 if (!do_section_details)
4596 printf (_("Key to Flags:\n\("Key to Flags:\n W (write), A (alloc), X (execute), M (merge), S (strings)\n I (info), L (link order), G (group), x (unknown)\n O (extra OS processing required) o (OS specific), p (processor specific)\n"
)
4597 W (write), A (alloc), X (execute), M (merge), S (strings)\n\("Key to Flags:\n W (write), A (alloc), X (execute), M (merge), S (strings)\n I (info), L (link order), G (group), x (unknown)\n O (extra OS processing required) o (OS specific), p (processor specific)\n"
)
4598 I (info), L (link order), G (group), x (unknown)\n\("Key to Flags:\n W (write), A (alloc), X (execute), M (merge), S (strings)\n I (info), L (link order), G (group), x (unknown)\n O (extra OS processing required) o (OS specific), p (processor specific)\n"
)
4599 O (extra OS processing required) o (OS specific), p (processor specific)\n")("Key to Flags:\n W (write), A (alloc), X (execute), M (merge), S (strings)\n I (info), L (link order), G (group), x (unknown)\n O (extra OS processing required) o (OS specific), p (processor specific)\n"
)
);
4600
4601 return 1;
4602}
4603
4604static const char *
4605get_group_flags (unsigned int flags)
4606{
4607 static char buff[32];
4608 switch (flags)
4609 {
4610 case GRP_COMDAT0x1:
4611 return "COMDAT";
4612
4613 default:
4614 snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]")("[<unknown>: 0x%x]"), flags);
4615 break;
4616 }
4617 return buff;
4618}
4619
4620static int
4621process_section_groups (FILE *file)
4622{
4623 Elf_Internal_Shdr *section;
4624 unsigned int i;
4625 struct group *group;
4626 Elf_Internal_Shdr *symtab_sec, *strtab_sec;
4627 Elf_Internal_Sym *symtab;
4628 char *strtab;
4629 size_t strtab_size;
4630
4631 /* Don't process section groups unless needed. */
4632 if (!do_unwind && !do_section_groups)
4633 return 1;
4634
4635 if (elf_header.e_shnum == 0)
4636 {
4637 if (do_section_groups)
4638 printf (_("\nThere are no sections in this file.\n")("\nThere are no sections in this file.\n"));
4639
4640 return 1;
4641 }
4642
4643 if (section_headers == NULL((void*)0))
4644 {
4645 error (_("Section headers are not available!\n")("Section headers are not available!\n"));
4646 abort ();
4647 }
4648
4649 section_headers_groups = calloc (elf_header.e_shnum,
4650 sizeof (struct group *));
4651
4652 if (section_headers_groups == NULL((void*)0))
4653 {
4654 error (_("Out of memory\n")("Out of memory\n"));
4655 return 0;
4656 }
4657
4658 /* Scan the sections for the group section. */
4659 group_count = 0;
4660 for (i = 0, section = section_headers;
4661 i < elf_header.e_shnum;
4662 i++, section++)
4663 if (section->sh_type == SHT_GROUP17)
4664 group_count++;
4665
4666 if (group_count == 0)
4667 {
4668 if (do_section_groups)
4669 printf (_("\nThere are no section groups in this file.\n")("\nThere are no section groups in this file.\n"));
4670
4671 return 1;
4672 }
4673
4674 section_groups = calloc (group_count, sizeof (struct group));
4675
4676 if (section_groups == NULL((void*)0))
4677 {
4678 error (_("Out of memory\n")("Out of memory\n"));
4679 return 0;
4680 }
4681
4682 symtab_sec = NULL((void*)0);
4683 strtab_sec = NULL((void*)0);
4684 symtab = NULL((void*)0);
4685 strtab = NULL((void*)0);
4686 strtab_size = 0;
4687 for (i = 0, section = section_headers, group = section_groups;
4688 i < elf_header.e_shnum;
4689 i++, section++)
4690 {
4691 if (section->sh_type == SHT_GROUP17)
4692 {
4693 char *name = SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
;
4694 char *group_name;
4695 unsigned char *start, *indices;
4696 unsigned int entry, j, size;
4697 Elf_Internal_Shdr *sec;
4698 Elf_Internal_Sym *sym;
4699
4700 /* Get the symbol table. */
4701 if (SECTION_HEADER_INDEX (section->sh_link)((section->sh_link) < 0xFF00 ? (section->sh_link) : (
(section->sh_link) <= 0xFFFF ? 0 : (section->sh_link
) - (0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum
4702 || ((sec = SECTION_HEADER (section->sh_link)(section_headers + ((section->sh_link) < 0xFF00 ? (section
->sh_link) : ((section->sh_link) <= 0xFFFF ? 0 : (section
->sh_link) - (0xFFFF + 1 - 0xFF00))))
)->sh_type
4703 != SHT_SYMTAB2))
4704 {
4705 error (_("Bad sh_link in group section `%s'\n")("Bad sh_link in group section `%s'\n"), name);
4706 continue;
4707 }
4708
4709 if (symtab_sec != sec)
4710 {
4711 symtab_sec = sec;
4712 if (symtab)
4713 free (symtab);
4714 symtab = GET_ELF_SYMBOLS (file, symtab_sec)(is_32bit_elf ? get_32bit_elf_symbols (file, symtab_sec) : get_64bit_elf_symbols
(file, symtab_sec))
;
4715 }
4716
4717 sym = symtab + section->sh_info;
4718
4719 if (ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) == STT_SECTION3)
4720 {
4721 bfd_vma sec_index = SECTION_HEADER_INDEX (sym->st_shndx)((sym->st_shndx) < 0xFF00 ? (sym->st_shndx) : ((sym->
st_shndx) <= 0xFFFF ? 0 : (sym->st_shndx) - (0xFFFF + 1
- 0xFF00)))
;
4722 if (sec_index == 0)
4723 {
4724 error (_("Bad sh_info in group section `%s'\n")("Bad sh_info in group section `%s'\n"), name);
4725 continue;
4726 }
4727
4728 group_name = SECTION_NAME (section_headers + sec_index)((section_headers + sec_index) == ((void*)0) ? "<none>"
: ((section_headers + sec_index)->sh_name >= string_table_length
? "<corrupt>" : string_table + (section_headers + sec_index
)->sh_name))
;
4729 strtab_sec = NULL((void*)0);
4730 if (strtab)
4731 free (strtab);
4732 strtab = NULL((void*)0);
4733 strtab_size = 0;
4734 }
4735 else
4736 {
4737 /* Get the string table. */
4738 if (SECTION_HEADER_INDEX (symtab_sec->sh_link)((symtab_sec->sh_link) < 0xFF00 ? (symtab_sec->sh_link
) : ((symtab_sec->sh_link) <= 0xFFFF ? 0 : (symtab_sec->
sh_link) - (0xFFFF + 1 - 0xFF00)))
4739 >= elf_header.e_shnum)
4740 {
4741 strtab_sec = NULL((void*)0);
4742 if (strtab)
4743 free (strtab);
4744 strtab = NULL((void*)0);
4745 strtab_size = 0;
4746 }
4747 else if (strtab_sec
4748 != (sec = SECTION_HEADER (symtab_sec->sh_link)(section_headers + ((symtab_sec->sh_link) < 0xFF00 ? (symtab_sec
->sh_link) : ((symtab_sec->sh_link) <= 0xFFFF ? 0 : (
symtab_sec->sh_link) - (0xFFFF + 1 - 0xFF00))))
))
4749 {
4750 strtab_sec = sec;
4751 if (strtab)
4752 free (strtab);
4753 strtab = get_data (NULL((void*)0), file, strtab_sec->sh_offset,
4754 1, strtab_sec->sh_size,
4755 _("string table")("string table"));
4756 strtab_size = strtab != NULL((void*)0) ? strtab_sec->sh_size : 0;
4757 }
4758 group_name = sym->st_name < strtab_size
4759 ? strtab + sym->st_name : "<corrupt>";
4760 }
4761
4762 start = get_data (NULL((void*)0), file, section->sh_offset,
4763 1, section->sh_size, _("section data")("section data"));
4764
4765 indices = start;
4766 size = (section->sh_size / section->sh_entsize) - 1;
4767 entry = byte_get (indices, 4);
4768 indices += 4;
4769
4770 if (do_section_groups)
4771 {
4772 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4773 get_group_flags (entry), i, name, group_name, size);
4774
4775 printf (_(" [Index] Name\n")(" [Index] Name\n"));
4776 }
4777
4778 group->group_index = i;
4779
4780 for (j = 0; j < size; j++)
4781 {
4782 struct group_list *g;
4783
4784 entry = byte_get (indices, 4);
4785 indices += 4;
4786
4787 if (SECTION_HEADER_INDEX (entry)((entry) < 0xFF00 ? (entry) : ((entry) <= 0xFFFF ? 0 : (
entry) - (0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum)
4788 {
4789 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n")("section [%5u] in group section [%5u] > maximum section [%5u]\n"
)
,
4790 entry, i, elf_header.e_shnum - 1);
4791 continue;
4792 }
4793 else if (entry >= SHN_LORESERVE0xFF00 && entry <= SHN_HIRESERVE0xFFFF)
4794 {
4795 error (_("invalid section [%5u] in group section [%5u]\n")("invalid section [%5u] in group section [%5u]\n"),
4796 entry, i);
4797 continue;
4798 }
4799
4800 if (section_headers_groups [SECTION_HEADER_INDEX (entry)((entry) < 0xFF00 ? (entry) : ((entry) <= 0xFFFF ? 0 : (
entry) - (0xFFFF + 1 - 0xFF00)))
]
4801 != NULL((void*)0))
4802 {
4803 if (entry)
4804 {
4805 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n")("section [%5u] in group section [%5u] already in group section [%5u]\n"
)
,
4806 entry, i,
4807 section_headers_groups [SECTION_HEADER_INDEX (entry)((entry) < 0xFF00 ? (entry) : ((entry) <= 0xFFFF ? 0 : (
entry) - (0xFFFF + 1 - 0xFF00)))
]->group_index);
4808 continue;
4809 }
4810 else
4811 {
4812 /* Intel C/C++ compiler may put section 0 in a
4813 section group. We just warn it the first time
4814 and ignore it afterwards. */
4815 static int warned = 0;
4816 if (!warned)
4817 {
4818 error (_("section 0 in group section [%5u]\n")("section 0 in group section [%5u]\n"),
4819 section_headers_groups [SECTION_HEADER_INDEX (entry)((entry) < 0xFF00 ? (entry) : ((entry) <= 0xFFFF ? 0 : (
entry) - (0xFFFF + 1 - 0xFF00)))
]->group_index);
4820 warned++;
4821 }
4822 }
4823 }
4824
4825 section_headers_groups [SECTION_HEADER_INDEX (entry)((entry) < 0xFF00 ? (entry) : ((entry) <= 0xFFFF ? 0 : (
entry) - (0xFFFF + 1 - 0xFF00)))
]
4826 = group;
4827
4828 if (do_section_groups)
4829 {
4830 sec = SECTION_HEADER (entry)(section_headers + ((entry) < 0xFF00 ? (entry) : ((entry) <=
0xFFFF ? 0 : (entry) - (0xFFFF + 1 - 0xFF00))))
;
4831 printf (" [%5u] %s\n", entry, SECTION_NAME (sec)((sec) == ((void*)0) ? "<none>" : ((sec)->sh_name >=
string_table_length ? "<corrupt>" : string_table + (sec
)->sh_name))
);
4832 }
4833
4834 g = xmalloc (sizeof (struct group_list));
4835 g->section_index = entry;
4836 g->next = group->root;
4837 group->root = g;
4838 }
4839
4840 if (start)
4841 free (start);
4842
4843 group++;
4844 }
4845 }
4846
4847 if (symtab)
4848 free (symtab);
4849 if (strtab)
4850 free (strtab);
4851 return 1;
4852}
4853
4854static struct
4855{
4856 const char *name;
4857 int reloc;
4858 int size;
4859 int rela;
4860} dynamic_relocations [] =
4861{
4862 { "REL", DT_REL17, DT_RELSZ18, FALSE0 },
4863 { "RELA", DT_RELA7, DT_RELASZ8, TRUE1 },
4864 { "RELR", DT_RELR36, DT_RELRSZ35, RELR-2 },
4865 { "PLT", DT_JMPREL23, DT_PLTRELSZ2, UNKNOWN-1 }
4866};
4867
4868/* Process the reloc section. */
4869
4870static int
4871process_relocs (FILE *file)
4872{
4873 unsigned long rel_size;
4874 unsigned long rel_offset;
4875
4876
4877 if (!do_reloc)
4878 return 1;
4879
4880 if (do_using_dynamic)
4881 {
4882 int is_rela;
4883 const char *name;
4884 int has_dynamic_reloc;
4885 unsigned int i;
4886
4887 has_dynamic_reloc = 0;
4888
4889 for (i = 0; i < ARRAY_SIZE (dynamic_relocations)(sizeof (dynamic_relocations) / sizeof ((dynamic_relocations)
[0]))
; i++)
4890 {
4891 is_rela = dynamic_relocations [i].rela;
4892 name = dynamic_relocations [i].name;
4893 rel_size = dynamic_info [dynamic_relocations [i].size];
4894 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
4895
4896 has_dynamic_reloc |= rel_size;
4897
4898 if (is_rela == UNKNOWN-1)
4899 {
4900 if (dynamic_relocations [i].reloc == DT_JMPREL23)
4901 switch (dynamic_info[DT_PLTREL20])
4902 {
4903 case DT_REL17:
4904 is_rela = FALSE0;
4905 break;
4906 case DT_RELA7:
4907 is_rela = TRUE1;
4908 break;
4909 }
4910 }
4911
4912 if (rel_size)
4913 {
4914 printf
4915 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n")("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"
)
,
4916 name, rel_offset, rel_size);
4917
4918 dump_relocations (file,
4919 offset_from_vma (file, rel_offset, rel_size),
4920 rel_size,
4921 dynamic_symbols, num_dynamic_syms,
4922 dynamic_strings, dynamic_strings_length, is_rela);
4923 }
4924 }
4925
4926 if (! has_dynamic_reloc)
4927 printf (_("\nThere are no dynamic relocations in this file.\n")("\nThere are no dynamic relocations in this file.\n"));
4928 }
4929 else
4930 {
4931 Elf_Internal_Shdr *section;
4932 unsigned long i;
4933 int found = 0;
4934
4935 for (i = 0, section = section_headers;
4936 i < elf_header.e_shnum;
4937 i++, section++)
4938 {
4939 if ( section->sh_type != SHT_RELA4
4940 && section->sh_type != SHT_REL9
4941 && section->sh_type != SHT_RELR19)
4942 continue;
4943
4944 rel_offset = section->sh_offset;
4945 rel_size = section->sh_size;
4946
4947 if (rel_size)
4948 {
4949 Elf_Internal_Shdr *strsec;
4950 int is_rela;
4951
4952 printf (_("\nRelocation section ")("\nRelocation section "));
4953
4954 if (string_table == NULL((void*)0))
4955 printf ("%d", section->sh_name);
4956 else
4957 printf (_("'%s'")("'%s'"), SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
4958
4959 if (section->sh_type == SHT_RELR19)
4960 is_rela = RELR-2;
4961 else
4962 is_rela = section->sh_type == SHT_RELA4;
4963
4964 if (is_rela != RELR-2)
4965 printf (_(" at offset 0x%lx contains %lu entries:\n")(" at offset 0x%lx contains %lu entries:\n"),
4966 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
4967
4968 if (section->sh_link
4969 && SECTION_HEADER_INDEX (section->sh_link)((section->sh_link) < 0xFF00 ? (section->sh_link) : (
(section->sh_link) <= 0xFFFF ? 0 : (section->sh_link
) - (0xFFFF + 1 - 0xFF00)))
4970 < elf_header.e_shnum)
4971 {
4972 Elf_Internal_Shdr *symsec;
4973 Elf_Internal_Sym *symtab;
4974 unsigned long nsyms;
4975 unsigned long strtablen = 0;
4976 char *strtab = NULL((void*)0);
4977
4978 symsec = SECTION_HEADER (section->sh_link)(section_headers + ((section->sh_link) < 0xFF00 ? (section
->sh_link) : ((section->sh_link) <= 0xFFFF ? 0 : (section
->sh_link) - (0xFFFF + 1 - 0xFF00))))
;
4979 if (symsec->sh_type != SHT_SYMTAB2
4980 && symsec->sh_type != SHT_DYNSYM11)
4981 continue;
4982
4983 nsyms = symsec->sh_size / symsec->sh_entsize;
4984 symtab = GET_ELF_SYMBOLS (file, symsec)(is_32bit_elf ? get_32bit_elf_symbols (file, symsec) : get_64bit_elf_symbols
(file, symsec))
;
4985
4986 if (symtab == NULL((void*)0))
4987 continue;
4988
4989 if (SECTION_HEADER_INDEX (symsec->sh_link)((symsec->sh_link) < 0xFF00 ? (symsec->sh_link) : ((
symsec->sh_link) <= 0xFFFF ? 0 : (symsec->sh_link) -
(0xFFFF + 1 - 0xFF00)))
4990 < elf_header.e_shnum)
4991 {
4992 strsec = SECTION_HEADER (symsec->sh_link)(section_headers + ((symsec->sh_link) < 0xFF00 ? (symsec
->sh_link) : ((symsec->sh_link) <= 0xFFFF ? 0 : (symsec
->sh_link) - (0xFFFF + 1 - 0xFF00))))
;
4993
4994 strtab = get_data (NULL((void*)0), file, strsec->sh_offset,
4995 1, strsec->sh_size,
4996 _("string table")("string table"));
4997 strtablen = strtab == NULL((void*)0) ? 0 : strsec->sh_size;
4998 }
4999
5000 dump_relocations (file, rel_offset, rel_size,
5001 symtab, nsyms, strtab, strtablen, is_rela);
5002 if (strtab)
5003 free (strtab);
5004 free (symtab);
5005 }
5006 else
5007 dump_relocations (file, rel_offset, rel_size,
5008 NULL((void*)0), 0, NULL((void*)0), 0, is_rela);
5009
5010 found = 1;
5011 }
5012 }
5013
5014 if (! found)
5015 printf (_("\nThere are no relocations in this file.\n")("\nThere are no relocations in this file.\n"));
5016 }
5017
5018 return 1;
5019}
5020
5021/* Process the unwind section. */
5022
5023#include "unwind-ia64.h"
5024
5025/* An absolute address consists of a section and an offset. If the
5026 section is NULL, the offset itself is the address, otherwise, the
5027 address equals to LOAD_ADDRESS(section) + offset. */
5028
5029struct absaddr
5030 {
5031 unsigned short section;
5032 bfd_vma offset;
5033 };
5034
5035#define ABSADDR(a)((a).section ? section_headers [(a).section].sh_addr + (a).offset
: (a).offset)
\
5036 ((a).section \
5037 ? section_headers [(a).section].sh_addr + (a).offset \
5038 : (a).offset)
5039
5040struct ia64_unw_aux_info
5041 {
5042 struct ia64_unw_table_entry
5043 {
5044 struct absaddr start;
5045 struct absaddr end;
5046 struct absaddr info;
5047 }
5048 *table; /* Unwind table. */
5049 unsigned long table_len; /* Length of unwind table. */
5050 unsigned char *info; /* Unwind info. */
5051 unsigned long info_size; /* Size of unwind info. */
5052 bfd_vma info_addr; /* starting address of unwind info. */
5053 bfd_vma seg_base; /* Starting address of segment. */
5054 Elf_Internal_Sym *symtab; /* The symbol table. */
5055 unsigned long nsyms; /* Number of symbols. */
5056 char *strtab; /* The string table. */
5057 unsigned long strtab_size; /* Size of string table. */
5058 };
5059
5060static void
5061find_symbol_for_address (Elf_Internal_Sym *symtab,
5062 unsigned long nsyms,
5063 const char *strtab,
5064 unsigned long strtab_size,
5065 struct absaddr addr,
5066 const char **symname,
5067 bfd_vma *offset)
5068{
5069 bfd_vma dist = 0x100000;
5070 Elf_Internal_Sym *sym, *best = NULL((void*)0);
5071 unsigned long i;
5072
5073 for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
5074 {
5075 if (ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) == STT_FUNC2
5076 && sym->st_name != 0
5077 && (addr.section == SHN_UNDEF0 || addr.section == sym->st_shndx)
5078 && addr.offset >= sym->st_value
5079 && addr.offset - sym->st_value < dist)
5080 {
5081 best = sym;
5082 dist = addr.offset - sym->st_value;
5083 if (!dist)
5084 break;
5085 }
5086 }
5087 if (best)
5088 {
5089 *symname = (best->st_name >= strtab_size
5090 ? "<corrupt>" : strtab + best->st_name);
5091 *offset = dist;
5092 return;
5093 }
5094 *symname = NULL((void*)0);
5095 *offset = addr.offset;
5096}
5097
5098static void
5099dump_ia64_unwind (struct ia64_unw_aux_info *aux)
5100{
5101 struct ia64_unw_table_entry *tp;
5102 int in_body;
5103
5104 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5105 {
5106 bfd_vma stamp;
5107 bfd_vma offset;
5108 const unsigned char *dp;
5109 const unsigned char *head;
5110 const char *procname;
5111
5112 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5113 aux->strtab_size, tp->start, &procname, &offset);
5114
5115 fputs ("\n<", stdout(&__sF[1]));
5116
5117 if (procname)
5118 {
5119 fputs (procname, stdout(&__sF[1]));
5120
5121 if (offset)
5122 printf ("+%lx", (unsigned long) offset);
5123 }
5124
5125 fputs (">: [", stdout(&__sF[1]));
5126 print_vma (tp->start.offset, PREFIX_HEX);
5127 fputc ('-', stdout(&__sF[1]));
5128 print_vma (tp->end.offset, PREFIX_HEX);
5129 printf ("], info at +0x%lx\n",
5130 (unsigned long) (tp->info.offset - aux->seg_base));
5131
5132 head = aux->info + (ABSADDR (tp->info)((tp->info).section ? section_headers [(tp->info).section
].sh_addr + (tp->info).offset : (tp->info).offset)
- aux->info_addr);
5133 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
5134
5135 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
5136 (unsigned) UNW_VER (stamp)((stamp) >> 48),
5137 (unsigned long) ((stamp & UNW_FLAG_MASK0x0000ffff00000000LL) >> 32),
5138 UNW_FLAG_EHANDLER (stamp)((stamp) & 0x0000000100000000LL) ? " ehandler" : "",
5139 UNW_FLAG_UHANDLER (stamp)((stamp) & 0x0000000200000000LL) ? " uhandler" : "",
5140 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)((stamp) & 0x00000000ffffffffLL)));
5141
5142 if (UNW_VER (stamp)((stamp) >> 48) != 1)
5143 {
5144 printf ("\tUnknown version.\n");
5145 continue;
5146 }
5147
5148 in_body = 0;
5149 for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp)((stamp) & 0x00000000ffffffffLL);)
5150 dp = unw_decode (dp, in_body, & in_body);
5151 }
5152}
5153
5154static int
5155slurp_ia64_unwind_table (FILE *file,
5156 struct ia64_unw_aux_info *aux,
5157 Elf_Internal_Shdr *sec)
5158{
5159 unsigned long size, nrelas, i;
5160 Elf_Internal_Phdr *seg;
5161 struct ia64_unw_table_entry *tep;
5162 Elf_Internal_Shdr *relsec;
5163 Elf_Internal_Rela *rela, *rp;
5164 unsigned char *table, *tp;
5165 Elf_Internal_Sym *sym;
5166 const char *relname;
5167
5168 /* First, find the starting address of the segment that includes
5169 this section: */
5170
5171 if (elf_header.e_phnum)
39
Assuming field 'e_phnum' is 0
40
Taking false branch
5172 {
5173 if (! get_program_headers (file))
5174 return 0;
5175
5176 for (seg = program_headers;
5177 seg < program_headers + elf_header.e_phnum;
5178 ++seg)
5179 {
5180 if (seg->p_type != PT_LOAD1)
5181 continue;
5182
5183 if (sec->sh_addr >= seg->p_vaddr
5184 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
5185 {
5186 aux->seg_base = seg->p_vaddr;
5187 break;
5188 }
5189 }
5190 }
5191
5192 /* Second, build the unwind table from the contents of the unwind section: */
5193 size = sec->sh_size;
5194 table = get_data (NULL((void*)0), file, sec->sh_offset, 1, size, _("unwind table")("unwind table"));
5195 if (!table)
41
Assuming 'table' is non-null
42
Taking false branch
5196 return 0;
5197
5198 aux->table = xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
5199 tep = aux->table;
5200 for (tp = table; tp < table + size; tp += 3 * eh_addr_size, ++tep)
43
Assuming the condition is false
44
Loop condition is false. Execution continues on line 5221
5201 {
5202 tep->start.section = SHN_UNDEF0;
5203 tep->end.section = SHN_UNDEF0;
5204 tep->info.section = SHN_UNDEF0;
5205 if (is_32bit_elf)
5206 {
5207 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
5208 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
5209 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
5210 }
5211 else
5212 {
5213 tep->start.offset = BYTE_GET ((unsigned char *) tp + 0)byte_get ((unsigned char *) tp + 0, sizeof ((unsigned char *)
tp + 0))
;
5214 tep->end.offset = BYTE_GET ((unsigned char *) tp + 8)byte_get ((unsigned char *) tp + 8, sizeof ((unsigned char *)
tp + 8))
;
5215 tep->info.offset = BYTE_GET ((unsigned char *) tp + 16)byte_get ((unsigned char *) tp + 16, sizeof ((unsigned char *
) tp + 16))
;
5216 }
5217 tep->start.offset += aux->seg_base;
5218 tep->end.offset += aux->seg_base;
5219 tep->info.offset += aux->seg_base;
5220 }
5221 free (table);
5222
5223 /* Third, apply any relocations to the unwind table: */
5224
5225 for (relsec = section_headers;
45
Loop condition is true. Entering loop body
5226 relsec < section_headers + elf_header.e_shnum;
5227 ++relsec)
5228 {
5229 if (relsec->sh_type != SHT_RELA4
46
Assuming field 'sh_type' is equal to SHT_RELA
55
Taking false branch
5230 || SECTION_HEADER_INDEX (relsec->sh_info)((relsec->sh_info) < 0xFF00 ? (relsec->sh_info) : ((
relsec->sh_info) <= 0xFFFF ? 0 : (relsec->sh_info) -
(0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum
47
Assuming field 'sh_info' is >= 65280
48
'?' condition is false
49
Assuming field 'sh_info' is > 65535
50
'?' condition is false
51
Assuming the condition is false
5231 || SECTION_HEADER (relsec->sh_info)(section_headers + ((relsec->sh_info) < 0xFF00 ? (relsec
->sh_info) : ((relsec->sh_info) <= 0xFFFF ? 0 : (relsec
->sh_info) - (0xFFFF + 1 - 0xFF00))))
!= sec
)
52
'?' condition is false
53
'?' condition is false
54
Assuming the condition is false
5232 continue;
5233
5234 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
56
Assuming the condition is false
57
Taking false branch
5235 & rela, & nrelas))
5236 return 0;
5237
5238 for (rp = rela; rp < rela + nrelas; ++rp)
58
Loop condition is true. Entering loop body
5239 {
5240 if (is_32bit_elf)
59
Assuming 'is_32bit_elf' is 0
60
Taking false branch
5241 {
5242 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info)((rp->r_info) & 0xff));
5243 sym = aux->symtab + ELF32_R_SYM (rp->r_info)((rp->r_info) >> 8);
5244 }
5245 else
5246 {
5247 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info)((rp->r_info) & 0xffffffff));
5248 sym = aux->symtab + ELF64_R_SYM (rp->r_info)((rp->r_info) >> 32);
61
Null pointer value stored to 'sym'
5249 }
5250
5251 if (! strneq (relname, "R_IA64_SEGREL", 13)(strncmp ((relname), ("R_IA64_SEGREL"), (13)) == 0))
62
Taking false branch
5252 {
5253 warn (_("Skipping unexpected relocation type %s\n")("Skipping unexpected relocation type %s\n"), relname);
5254 continue;
5255 }
5256
5257 i = rp->r_offset / (3 * eh_addr_size);
5258
5259 switch (rp->r_offset/eh_addr_size % 3)
63
Control jumps to 'case 1:' at line 5265
5260 {
5261 case 0:
5262 aux->table[i].start.section = sym->st_shndx;
5263 aux->table[i].start.offset += rp->r_addend + sym->st_value;
5264 break;
5265 case 1:
5266 aux->table[i].end.section = sym->st_shndx;
64
Access to field 'st_shndx' results in a dereference of a null pointer (loaded from variable 'sym')
5267 aux->table[i].end.offset += rp->r_addend + sym->st_value;
5268 break;
5269 case 2:
5270 aux->table[i].info.section = sym->st_shndx;
5271 aux->table[i].info.offset += rp->r_addend + sym->st_value;
5272 break;
5273 default:
5274 break;
5275 }
5276 }
5277
5278 free (rela);
5279 }
5280
5281 aux->table_len = size / (3 * eh_addr_size);
5282 return 1;
5283}
5284
5285static int
5286ia64_process_unwind (FILE *file)
5287{
5288 Elf_Internal_Shdr *sec, *unwsec = NULL((void*)0), *strsec;
5289 unsigned long i, unwcount = 0, unwstart = 0;
5290 struct ia64_unw_aux_info aux;
5291
5292 memset (& aux, 0, sizeof (aux));
1
Null pointer value stored to 'aux.symtab'
5293
5294 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
2
Assuming 'i' is < field 'e_shnum'
3
Loop condition is true. Entering loop body
7
Assuming 'i' is >= field 'e_shnum'
8
Loop condition is false. Execution continues on line 5311
5295 {
5296 if (sec->sh_type == SHT_SYMTAB2
4
Assuming field 'sh_type' is not equal to SHT_SYMTAB
5297 && SECTION_HEADER_INDEX (sec->sh_link)((sec->sh_link) < 0xFF00 ? (sec->sh_link) : ((sec->
sh_link) <= 0xFFFF ? 0 : (sec->sh_link) - (0xFFFF + 1 -
0xFF00)))
< elf_header.e_shnum)
5298 {
5299 aux.nsyms = sec->sh_size / sec->sh_entsize;
5300 aux.symtab = GET_ELF_SYMBOLS (file, sec)(is_32bit_elf ? get_32bit_elf_symbols (file, sec) : get_64bit_elf_symbols
(file, sec))
;
5301
5302 strsec = SECTION_HEADER (sec->sh_link)(section_headers + ((sec->sh_link) < 0xFF00 ? (sec->
sh_link) : ((sec->sh_link) <= 0xFFFF ? 0 : (sec->sh_link
) - (0xFFFF + 1 - 0xFF00))))
;
5303 aux.strtab = get_data (NULL((void*)0), file, strsec->sh_offset,
5304 1, strsec->sh_size, _("string table")("string table"));
5305 aux.strtab_size = aux.strtab != NULL((void*)0) ? strsec->sh_size : 0;
5306 }
5307 else if (sec->sh_type == SHT_IA_64_UNWIND(0x70000000 + 1))
5
Assuming the condition is true
6
Taking true branch
5308 unwcount++;
5309 }
5310
5311 if (!unwcount
8.1
'unwcount' is 1
)
9
Taking false branch
5312 printf (_("\nThere are no unwind sections in this file.\n")("\nThere are no unwind sections in this file.\n"));
5313
5314 while (unwcount-- > 0)
10
Loop condition is true. Entering loop body
5315 {
5316 char *suffix;
5317 size_t len, len2;
5318
5319 for (i = unwstart, sec = section_headers + unwstart;
11
Loop condition is true. Entering loop body
5320 i < elf_header.e_shnum; ++i, ++sec)
5321 if (sec->sh_type == SHT_IA_64_UNWIND(0x70000000 + 1))
12
Taking true branch
5322 {
5323 unwsec = sec;
5324 break;
13
Execution continues on line 5327
5325 }
5326
5327 unwstart = i + 1;
5328 len = sizeof (ELF_STRING_ia64_unwind_once".gnu.linkonce.ia64unw.") - 1;
5329
5330 if ((unwsec->sh_flags & SHF_GROUP(1 << 9)) != 0)
14
Assuming the condition is false
15
Taking false branch
5331 {
5332 /* We need to find which section group it is in. */
5333 struct group_list *g = section_headers_groups [i]->root;
5334
5335 for (; g != NULL((void*)0); g = g->next)
5336 {
5337 sec = SECTION_HEADER (g->section_index)(section_headers + ((g->section_index) < 0xFF00 ? (g->
section_index) : ((g->section_index) <= 0xFFFF ? 0 : (g
->section_index) - (0xFFFF + 1 - 0xFF00))))
;
5338
5339 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)(strcmp ((((sec) == ((void*)0) ? "<none>" : ((sec)->
sh_name >= string_table_length ? "<corrupt>" : string_table
+ (sec)->sh_name))), (".IA_64.unwind_info")) == 0)
)
5340 break;
5341 }
5342
5343 if (g == NULL((void*)0))
5344 i = elf_header.e_shnum;
5345 }
5346 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len)(strncmp ((((unwsec) == ((void*)0) ? "<none>" : ((unwsec
)->sh_name >= string_table_length ? "<corrupt>" :
string_table + (unwsec)->sh_name))), (".gnu.linkonce.ia64unw."
), (len)) == 0)
)
16
'?' condition is false
17
Assuming 'string_table_length' is > field 'sh_name'
18
'?' condition is false
19
Assuming the condition is false
20
Taking false branch
5347 {
5348 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5349 len2 = sizeof (ELF_STRING_ia64_unwind_info_once".gnu.linkonce.ia64unwi.") - 1;
5350 suffix = SECTION_NAME (unwsec)((unwsec) == ((void*)0) ? "<none>" : ((unwsec)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (unwsec)->sh_name))
+ len;
5351 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
5352 ++i, ++sec)
5353 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)(strncmp ((((sec) == ((void*)0) ? "<none>" : ((sec)->
sh_name >= string_table_length ? "<corrupt>" : string_table
+ (sec)->sh_name))), (".gnu.linkonce.ia64unwi."), (len2))
== 0)
5354 && streq (SECTION_NAME (sec) + len2, suffix)(strcmp ((((sec) == ((void*)0) ? "<none>" : ((sec)->
sh_name >= string_table_length ? "<corrupt>" : string_table
+ (sec)->sh_name)) + len2), (suffix)) == 0)
)
5355 break;
5356 }
5357 else
5358 {
5359 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5360 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5361 len = sizeof (ELF_STRING_ia64_unwind".IA_64.unwind") - 1;
5362 len2 = sizeof (ELF_STRING_ia64_unwind_info".IA_64.unwind_info") - 1;
5363 suffix = "";
5364 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len)(strncmp ((((unwsec) == ((void*)0) ? "<none>" : ((unwsec
)->sh_name >= string_table_length ? "<corrupt>" :
string_table + (unwsec)->sh_name))), (".IA_64.unwind"), (
len)) == 0)
)
21
'?' condition is false
22
'?' condition is false
23
Assuming the condition is false
24
Taking false branch
5365 suffix = SECTION_NAME (unwsec)((unwsec) == ((void*)0) ? "<none>" : ((unwsec)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (unwsec)->sh_name))
+ len;
5366 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
25
Loop condition is true. Entering loop body
5367 ++i, ++sec)
5368 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)(strncmp ((((sec) == ((void*)0) ? "<none>" : ((sec)->
sh_name >= string_table_length ? "<corrupt>" : string_table
+ (sec)->sh_name))), (".IA_64.unwind_info"), (len2)) == 0
)
26
'?' condition is false
27
'?' condition is false
30
Taking true branch
5369 && streq (SECTION_NAME (sec) + len2, suffix)(strcmp ((((sec) == ((void*)0) ? "<none>" : ((sec)->
sh_name >= string_table_length ? "<corrupt>" : string_table
+ (sec)->sh_name)) + len2), (suffix)) == 0)
)
28
'?' condition is false
29
'?' condition is false
5370 break;
31
Execution continues on line 5373
5371 }
5372
5373 if (i
31.1
'i' is not equal to field 'e_shnum'
== elf_header.e_shnum)
32
Taking false branch
5374 {
5375 printf (_("\nCould not find unwind info section for ")("\nCould not find unwind info section for "));
5376
5377 if (string_table == NULL((void*)0))
5378 printf ("%d", unwsec->sh_name);
5379 else
5380 printf (_("'%s'")("'%s'"), SECTION_NAME (unwsec)((unwsec) == ((void*)0) ? "<none>" : ((unwsec)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (unwsec)->sh_name))
);
5381 }
5382 else
5383 {
5384 aux.info_size = sec->sh_size;
5385 aux.info_addr = sec->sh_addr;
5386 aux.info = get_data (NULL((void*)0), file, sec->sh_offset, 1, aux.info_size,
5387 _("unwind info")("unwind info"));
5388
5389 printf (_("\nUnwind section ")("\nUnwind section "));
5390
5391 if (string_table == NULL((void*)0))
33
Assuming 'string_table' is not equal to NULL
34
Taking false branch
5392 printf ("%d", unwsec->sh_name);
5393 else
5394 printf (_("'%s'")("'%s'"), SECTION_NAME (unwsec)((unwsec) == ((void*)0) ? "<none>" : ((unwsec)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (unwsec)->sh_name))
);
35
'?' condition is false
36
Assuming 'string_table_length' is > field 'sh_name'
37
'?' condition is false
5395
5396 printf (_(" at offset 0x%lx contains %lu entries:\n")(" at offset 0x%lx contains %lu entries:\n"),
5397 (unsigned long) unwsec->sh_offset,
5398 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
5399
5400 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
38
Calling 'slurp_ia64_unwind_table'
5401
5402 if (aux.table_len > 0)
5403 dump_ia64_unwind (& aux);
5404
5405 if (aux.table)
5406 free ((char *) aux.table);
5407 if (aux.info)
5408 free ((char *) aux.info);
5409 aux.table = NULL((void*)0);
5410 aux.info = NULL((void*)0);
5411 }
5412 }
5413
5414 if (aux.symtab)
5415 free (aux.symtab);
5416 if (aux.strtab)
5417 free ((char *) aux.strtab);
5418
5419 return 1;
5420}
5421
5422struct hppa_unw_aux_info
5423 {
5424 struct hppa_unw_table_entry
5425 {
5426 struct absaddr start;
5427 struct absaddr end;
5428 unsigned int Cannot_unwind:1; /* 0 */
5429 unsigned int Millicode:1; /* 1 */
5430 unsigned int Millicode_save_sr0:1; /* 2 */
5431 unsigned int Region_description:2; /* 3..4 */
5432 unsigned int reserved1:1; /* 5 */
5433 unsigned int Entry_SR:1; /* 6 */
5434 unsigned int Entry_FR:4; /* number saved */ /* 7..10 */
5435 unsigned int Entry_GR:5; /* number saved */ /* 11..15 */
5436 unsigned int Args_stored:1; /* 16 */
5437 unsigned int Variable_Frame:1; /* 17 */
5438 unsigned int Separate_Package_Body:1; /* 18 */
5439 unsigned int Frame_Extension_Millicode:1; /* 19 */
5440 unsigned int Stack_Overflow_Check:1; /* 20 */
5441 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
5442 unsigned int Ada_Region:1; /* 22 */
5443 unsigned int cxx_info:1; /* 23 */
5444 unsigned int cxx_try_catch:1; /* 24 */
5445 unsigned int sched_entry_seq:1; /* 25 */
5446 unsigned int reserved2:1; /* 26 */
5447 unsigned int Save_SP:1; /* 27 */
5448 unsigned int Save_RP:1; /* 28 */
5449 unsigned int Save_MRP_in_frame:1; /* 29 */
5450 unsigned int extn_ptr_defined:1; /* 30 */
5451 unsigned int Cleanup_defined:1; /* 31 */
5452
5453 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
5454 unsigned int HP_UX_interrupt_marker:1; /* 1 */
5455 unsigned int Large_frame:1; /* 2 */
5456 unsigned int Pseudo_SP_Set:1; /* 3 */
5457 unsigned int reserved4:1; /* 4 */
5458 unsigned int Total_frame_size:27; /* 5..31 */
5459 }
5460 *table; /* Unwind table. */
5461 unsigned long table_len; /* Length of unwind table. */
5462 bfd_vma seg_base; /* Starting address of segment. */
5463 Elf_Internal_Sym *symtab; /* The symbol table. */
5464 unsigned long nsyms; /* Number of symbols. */
5465 char *strtab; /* The string table. */
5466 unsigned long strtab_size; /* Size of string table. */
5467 };
5468
5469static void
5470dump_hppa_unwind (struct hppa_unw_aux_info *aux)
5471{
5472 struct hppa_unw_table_entry *tp;
5473
5474 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5475 {
5476 bfd_vma offset;
5477 const char *procname;
5478
5479 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5480 aux->strtab_size, tp->start, &procname,
5481 &offset);
5482
5483 fputs ("\n<", stdout(&__sF[1]));
5484
5485 if (procname)
5486 {
5487 fputs (procname, stdout(&__sF[1]));
5488
5489 if (offset)
5490 printf ("+%lx", (unsigned long) offset);
5491 }
5492
5493 fputs (">: [", stdout(&__sF[1]));
5494 print_vma (tp->start.offset, PREFIX_HEX);
5495 fputc ('-', stdout(&__sF[1]));
5496 print_vma (tp->end.offset, PREFIX_HEX);
5497 printf ("]\n\t");
5498
5499#define PF(_m) if (tp->_m) printf (#_m " ");
5500#define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5501 PF(Cannot_unwind);
5502 PF(Millicode);
5503 PF(Millicode_save_sr0);
5504 /* PV(Region_description); */
5505 PF(Entry_SR);
5506 PV(Entry_FR);
5507 PV(Entry_GR);
5508 PF(Args_stored);
5509 PF(Variable_Frame);
5510 PF(Separate_Package_Body);
5511 PF(Frame_Extension_Millicode);
5512 PF(Stack_Overflow_Check);
5513 PF(Two_Instruction_SP_Increment);
5514 PF(Ada_Region);
5515 PF(cxx_info);
5516 PF(cxx_try_catch);
5517 PF(sched_entry_seq);
5518 PF(Save_SP);
5519 PF(Save_RP);
5520 PF(Save_MRP_in_frame);
5521 PF(extn_ptr_defined);
5522 PF(Cleanup_defined);
5523 PF(MPE_XL_interrupt_marker);
5524 PF(HP_UX_interrupt_marker);
5525 PF(Large_frame);
5526 PF(Pseudo_SP_Set);
5527 PV(Total_frame_size);
5528#undef PF
5529#undef PV
5530 }
5531
5532 printf ("\n");
5533}
5534
5535static int
5536slurp_hppa_unwind_table (FILE *file,
5537 struct hppa_unw_aux_info *aux,
5538 Elf_Internal_Shdr *sec)
5539{
5540 unsigned long size, unw_ent_size, nentries, nrelas, i;
5541 Elf_Internal_Phdr *seg;
5542 struct hppa_unw_table_entry *tep;
5543 Elf_Internal_Shdr *relsec;
5544 Elf_Internal_Rela *rela, *rp;
5545 unsigned char *table, *tp;
5546 Elf_Internal_Sym *sym;
5547 const char *relname;
5548
5549 /* First, find the starting address of the segment that includes
5550 this section. */
5551
5552 if (elf_header.e_phnum)
5553 {
5554 if (! get_program_headers (file))
5555 return 0;
5556
5557 for (seg = program_headers;
5558 seg < program_headers + elf_header.e_phnum;
5559 ++seg)
5560 {
5561 if (seg->p_type != PT_LOAD1)
5562 continue;
5563
5564 if (sec->sh_addr >= seg->p_vaddr
5565 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
5566 {
5567 aux->seg_base = seg->p_vaddr;
5568 break;
5569 }
5570 }
5571 }
5572
5573 /* Second, build the unwind table from the contents of the unwind
5574 section. */
5575 size = sec->sh_size;
5576 table = get_data (NULL((void*)0), file, sec->sh_offset, 1, size, _("unwind table")("unwind table"));
5577 if (!table)
5578 return 0;
5579
5580 unw_ent_size = 16;
5581 nentries = size / unw_ent_size;
5582 size = unw_ent_size * nentries;
5583
5584 tep = aux->table = xcmalloc (nentries, sizeof (aux->table[0]));
5585
5586 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
5587 {
5588 unsigned int tmp1, tmp2;
5589
5590 tep->start.section = SHN_UNDEF0;
5591 tep->end.section = SHN_UNDEF0;
5592
5593 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
5594 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
5595 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
5596 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
5597
5598 tep->start.offset += aux->seg_base;
5599 tep->end.offset += aux->seg_base;
5600
5601 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
5602 tep->Millicode = (tmp1 >> 30) & 0x1;
5603 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
5604 tep->Region_description = (tmp1 >> 27) & 0x3;
5605 tep->reserved1 = (tmp1 >> 26) & 0x1;
5606 tep->Entry_SR = (tmp1 >> 25) & 0x1;
5607 tep->Entry_FR = (tmp1 >> 21) & 0xf;
5608 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
5609 tep->Args_stored = (tmp1 >> 15) & 0x1;
5610 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
5611 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
5612 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
5613 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
5614 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
5615 tep->Ada_Region = (tmp1 >> 9) & 0x1;
5616 tep->cxx_info = (tmp1 >> 8) & 0x1;
5617 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
5618 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
5619 tep->reserved2 = (tmp1 >> 5) & 0x1;
5620 tep->Save_SP = (tmp1 >> 4) & 0x1;
5621 tep->Save_RP = (tmp1 >> 3) & 0x1;
5622 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
5623 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
5624 tep->Cleanup_defined = tmp1 & 0x1;
5625
5626 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
5627 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
5628 tep->Large_frame = (tmp2 >> 29) & 0x1;
5629 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
5630 tep->reserved4 = (tmp2 >> 27) & 0x1;
5631 tep->Total_frame_size = tmp2 & 0x7ffffff;
5632 }
5633 free (table);
5634
5635 /* Third, apply any relocations to the unwind table. */
5636
5637 for (relsec = section_headers;
5638 relsec < section_headers + elf_header.e_shnum;
5639 ++relsec)
5640 {
5641 if (relsec->sh_type != SHT_RELA4
5642 || SECTION_HEADER_INDEX (relsec->sh_info)((relsec->sh_info) < 0xFF00 ? (relsec->sh_info) : ((
relsec->sh_info) <= 0xFFFF ? 0 : (relsec->sh_info) -
(0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum
5643 || SECTION_HEADER (relsec->sh_info)(section_headers + ((relsec->sh_info) < 0xFF00 ? (relsec
->sh_info) : ((relsec->sh_info) <= 0xFFFF ? 0 : (relsec
->sh_info) - (0xFFFF + 1 - 0xFF00))))
!= sec)
5644 continue;
5645
5646 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
5647 & rela, & nrelas))
5648 return 0;
5649
5650 for (rp = rela; rp < rela + nrelas; ++rp)
5651 {
5652 if (is_32bit_elf)
5653 {
5654 relname = elf_hppa_reloc_type (ELF32_R_TYPE (rp->r_info)((rp->r_info) & 0xff));
5655 sym = aux->symtab + ELF32_R_SYM (rp->r_info)((rp->r_info) >> 8);
5656 }
5657 else
5658 {
5659 relname = elf_hppa_reloc_type (ELF64_R_TYPE (rp->r_info)((rp->r_info) & 0xffffffff));
5660 sym = aux->symtab + ELF64_R_SYM (rp->r_info)((rp->r_info) >> 32);
5661 }
5662
5663 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5664 if (strncmp (relname, "R_PARISC_SEGREL", 15) != 0)
5665 {
5666 warn (_("Skipping unexpected relocation type %s\n")("Skipping unexpected relocation type %s\n"), relname);
5667 continue;
5668 }
5669
5670 i = rp->r_offset / unw_ent_size;
5671
5672 switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
5673 {
5674 case 0:
5675 aux->table[i].start.section = sym->st_shndx;
5676 aux->table[i].start.offset += sym->st_value + rp->r_addend;
5677 break;
5678 case 1:
5679 aux->table[i].end.section = sym->st_shndx;
5680 aux->table[i].end.offset += sym->st_value + rp->r_addend;
5681 break;
5682 default:
5683 break;
5684 }
5685 }
5686
5687 free (rela);
5688 }
5689
5690 aux->table_len = nentries;
5691
5692 return 1;
5693}
5694
5695static int
5696hppa_process_unwind (FILE *file)
5697{
5698 struct hppa_unw_aux_info aux;
5699 Elf_Internal_Shdr *unwsec = NULL((void*)0);
5700 Elf_Internal_Shdr *strsec;
5701 Elf_Internal_Shdr *sec;
5702 unsigned long i;
5703
5704 memset (& aux, 0, sizeof (aux));
5705
5706 if (string_table == NULL((void*)0))
5707 return 1;
5708
5709 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5710 {
5711 if (sec->sh_type == SHT_SYMTAB2
5712 && SECTION_HEADER_INDEX (sec->sh_link)((sec->sh_link) < 0xFF00 ? (sec->sh_link) : ((sec->
sh_link) <= 0xFFFF ? 0 : (sec->sh_link) - (0xFFFF + 1 -
0xFF00)))
< elf_header.e_shnum)
5713 {
5714 aux.nsyms = sec->sh_size / sec->sh_entsize;
5715 aux.symtab = GET_ELF_SYMBOLS (file, sec)(is_32bit_elf ? get_32bit_elf_symbols (file, sec) : get_64bit_elf_symbols
(file, sec))
;
5716
5717 strsec = SECTION_HEADER (sec->sh_link)(section_headers + ((sec->sh_link) < 0xFF00 ? (sec->
sh_link) : ((sec->sh_link) <= 0xFFFF ? 0 : (sec->sh_link
) - (0xFFFF + 1 - 0xFF00))))
;
5718 aux.strtab = get_data (NULL((void*)0), file, strsec->sh_offset,
5719 1, strsec->sh_size, _("string table")("string table"));
5720 aux.strtab_size = aux.strtab != NULL((void*)0) ? strsec->sh_size : 0;
5721 }
5722 else if (streq (SECTION_NAME (sec), ".PARISC.unwind")(strcmp ((((sec) == ((void*)0) ? "<none>" : ((sec)->
sh_name >= string_table_length ? "<corrupt>" : string_table
+ (sec)->sh_name))), (".PARISC.unwind")) == 0)
)
5723 unwsec = sec;
5724 }
5725
5726 if (!unwsec)
5727 printf (_("\nThere are no unwind sections in this file.\n")("\nThere are no unwind sections in this file.\n"));
5728
5729 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5730 {
5731 if (streq (SECTION_NAME (sec), ".PARISC.unwind")(strcmp ((((sec) == ((void*)0) ? "<none>" : ((sec)->
sh_name >= string_table_length ? "<corrupt>" : string_table
+ (sec)->sh_name))), (".PARISC.unwind")) == 0)
)
5732 {
5733 printf (_("\nUnwind section ")("\nUnwind section "));
5734 printf (_("'%s'")("'%s'"), SECTION_NAME (sec)((sec) == ((void*)0) ? "<none>" : ((sec)->sh_name >=
string_table_length ? "<corrupt>" : string_table + (sec
)->sh_name))
);
5735
5736 printf (_(" at offset 0x%lx contains %lu entries:\n")(" at offset 0x%lx contains %lu entries:\n"),
5737 (unsigned long) sec->sh_offset,
5738 (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
5739
5740 slurp_hppa_unwind_table (file, &aux, sec);
5741 if (aux.table_len > 0)
5742 dump_hppa_unwind (&aux);
5743
5744 if (aux.table)
5745 free ((char *) aux.table);
5746 aux.table = NULL((void*)0);
5747 }
5748 }
5749
5750 if (aux.symtab)
5751 free (aux.symtab);
5752 if (aux.strtab)
5753 free ((char *) aux.strtab);
5754
5755 return 1;
5756}
5757
5758static int
5759process_unwind (FILE *file)
5760{
5761 struct unwind_handler {
5762 int machtype;
5763 int (*handler)(FILE *file);
5764 } handlers[] = {
5765 { EM_IA_6450, ia64_process_unwind },
5766 { EM_PARISC15, hppa_process_unwind },
5767 { 0, 0 }
5768 };
5769 int i;
5770
5771 if (!do_unwind)
5772 return 1;
5773
5774 for (i = 0; handlers[i].handler != NULL((void*)0); i++)
5775 if (elf_header.e_machine == handlers[i].machtype)
5776 return handlers[i].handler (file);
5777
5778 printf (_("\nThere are no unwind sections in this file.\n")("\nThere are no unwind sections in this file.\n"));
5779 return 1;
5780}
5781
5782static void
5783dynamic_section_mips_val (Elf_Internal_Dyn *entry)
5784{
5785 switch (entry->d_tag)
5786 {
5787 case DT_MIPS_FLAGS0x70000005:
5788 if (entry->d_un.d_val == 0)
5789 printf ("NONE\n");
5790 else
5791 {
5792 static const char * opts[] =
5793 {
5794 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5795 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5796 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5797 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5798 "RLD_ORDER_SAFE"
5799 };
5800 unsigned int cnt;
5801 int first = 1;
5802 for (cnt = 0; cnt < NUM_ELEM (opts)(sizeof (opts) / sizeof ((opts)[0])); ++cnt)
5803 if (entry->d_un.d_val & (1 << cnt))
5804 {
5805 printf ("%s%s", first ? "" : " ", opts[cnt]);
5806 first = 0;
5807 }
5808 puts ("");
5809 }
5810 break;
5811
5812 case DT_MIPS_IVERSION0x70000004:
5813 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)((dynamic_strings != ((void*)0)) && (entry->d_un.d_val
< dynamic_strings_length))
)
5814 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry->d_un.d_val)(dynamic_strings + entry->d_un.d_val));
5815 else
5816 printf ("<corrupt: %ld>\n", (long) entry->d_un.d_ptr);
5817 break;
5818
5819 case DT_MIPS_TIME_STAMP0x70000002:
5820 {
5821 char timebuf[20];
5822 struct tm *tmp;
5823
5824 time_t time = entry->d_un.d_val;
5825 tmp = gmtime (&time);
5826 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
5827 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
5828 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
5829 printf ("Time Stamp: %s\n", timebuf);
5830 }
5831 break;
5832
5833 case DT_MIPS_RLD_VERSION0x70000001:
5834 case DT_MIPS_LOCAL_GOTNO0x7000000a:
5835 case DT_MIPS_CONFLICTNO0x7000000b:
5836 case DT_MIPS_LIBLISTNO0x70000010:
5837 case DT_MIPS_SYMTABNO0x70000011:
5838 case DT_MIPS_UNREFEXTNO0x70000012:
5839 case DT_MIPS_HIPAGENO0x70000014:
5840 case DT_MIPS_DELTA_CLASS_NO0x70000018:
5841 case DT_MIPS_DELTA_INSTANCE_NO0x7000001a:
5842 case DT_MIPS_DELTA_RELOC_NO0x7000001c:
5843 case DT_MIPS_DELTA_SYM_NO0x7000001e:
5844 case DT_MIPS_DELTA_CLASSSYM_NO0x70000021:
5845 case DT_MIPS_COMPACT_SIZE0x7000002f:
5846 printf ("%ld\n", (long) entry->d_un.d_ptr);
5847 break;
5848
5849 default:
5850 printf ("%#lx\n", (long) entry->d_un.d_ptr);
5851 }
5852}
5853
5854
5855static void
5856dynamic_section_parisc_val (Elf_Internal_Dyn *entry)
5857{
5858 switch (entry->d_tag)
5859 {
5860 case DT_HP_DLD_FLAGS(0x60000000 + 0x1):
5861 {
5862 static struct
5863 {
5864 long int bit;
5865 const char *str;
5866 }
5867 flags[] =
5868 {
5869 { DT_HP_DEBUG_PRIVATE0x00001, "HP_DEBUG_PRIVATE" },
5870 { DT_HP_DEBUG_CALLBACK0x00002, "HP_DEBUG_CALLBACK" },
5871 { DT_HP_DEBUG_CALLBACK_BOR0x00004, "HP_DEBUG_CALLBACK_BOR" },
5872 { DT_HP_NO_ENVVAR0x00008, "HP_NO_ENVVAR" },
5873 { DT_HP_BIND_NOW0x00010, "HP_BIND_NOW" },
5874 { DT_HP_BIND_NONFATAL0x00020, "HP_BIND_NONFATAL" },
5875 { DT_HP_BIND_VERBOSE0x00040, "HP_BIND_VERBOSE" },
5876 { DT_HP_BIND_RESTRICTED0x00080, "HP_BIND_RESTRICTED" },
5877 { DT_HP_BIND_SYMBOLIC0x00100, "HP_BIND_SYMBOLIC" },
5878 { DT_HP_RPATH_FIRST0x00200, "HP_RPATH_FIRST" },
5879 { DT_HP_BIND_DEPTH_FIRST0x00400, "HP_BIND_DEPTH_FIRST" },
5880 { DT_HP_GST0x00800, "HP_GST" },
5881 { DT_HP_SHLIB_FIXED0x01000, "HP_SHLIB_FIXED" },
5882 { DT_HP_MERGE_SHLIB_SEG0x02000, "HP_MERGE_SHLIB_SEG" },
5883 { DT_HP_NODELETE0x04000, "HP_NODELETE" },
5884 { DT_HP_GROUP0x08000, "HP_GROUP" },
5885 { DT_HP_PROTECT_LINKAGE_TABLE0x10000, "HP_PROTECT_LINKAGE_TABLE" }
5886 };
5887 int first = 1;
5888 size_t cnt;
5889 bfd_vma val = entry->d_un.d_val;
5890
5891 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
5892 if (val & flags[cnt].bit)
5893 {
5894 if (! first)
5895 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
5896 fputs (flags[cnt].str, stdout(&__sF[1]));
5897 first = 0;
5898 val ^= flags[cnt].bit;
5899 }
5900
5901 if (val != 0 || first)
5902 {
5903 if (! first)
5904 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
5905 print_vma (val, HEX);
5906 }
5907 }
5908 break;
5909
5910 default:
5911 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5912 break;
5913 }
5914 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
5915}
5916
5917static void
5918dynamic_section_ia64_val (Elf_Internal_Dyn *entry)
5919{
5920 switch (entry->d_tag)
5921 {
5922 case DT_IA_64_PLT_RESERVE(0x70000000 + 0):
5923 /* First 3 slots reserved. */
5924 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5925 printf (" -- ");
5926 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
5927 break;
5928
5929 default:
5930 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5931 break;
5932 }
5933 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
5934}
5935
5936static int
5937get_32bit_dynamic_section (FILE *file)
5938{
5939 Elf32_External_Dyn *edyn, *ext;
5940 Elf_Internal_Dyn *entry;
5941
5942 edyn = get_data (NULL((void*)0), file, dynamic_addr, 1, dynamic_size,
5943 _("dynamic section")("dynamic section"));
5944 if (!edyn)
5945 return 0;
5946
5947/* SGI's ELF has more than one section in the DYNAMIC segment, and we
5948 might not have the luxury of section headers. Look for the DT_NULL
5949 terminator to determine the number of entries. */
5950 for (ext = edyn, dynamic_nent = 0;
5951 (char *) ext < (char *) edyn + dynamic_size;
5952 ext++)
5953 {
5954 dynamic_nent++;
5955 if (BYTE_GET (ext->d_tag)byte_get (ext->d_tag, sizeof (ext->d_tag)) == DT_NULL0)
5956 break;
5957 }
5958
5959 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5960 if (dynamic_section == NULL((void*)0))
5961 {
5962 error (_("Out of memory\n")("Out of memory\n"));
5963 free (edyn);
5964 return 0;
5965 }
5966
5967 for (ext = edyn, entry = dynamic_section;
5968 entry < dynamic_section + dynamic_nent;
5969 ext++, entry++)
5970 {
5971 entry->d_tag = BYTE_GET (ext->d_tag)byte_get (ext->d_tag, sizeof (ext->d_tag));
5972 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val)byte_get (ext->d_un.d_val, sizeof (ext->d_un.d_val));
5973 }
5974
5975 free (edyn);
5976
5977 return 1;
5978}
5979
5980static int
5981get_64bit_dynamic_section (FILE *file)
5982{
5983 Elf64_External_Dyn *edyn, *ext;
5984 Elf_Internal_Dyn *entry;
5985
5986 edyn = get_data (NULL((void*)0), file, dynamic_addr, 1, dynamic_size,
5987 _("dynamic section")("dynamic section"));
5988 if (!edyn)
5989 return 0;
5990
5991/* SGI's ELF has more than one section in the DYNAMIC segment, and we
5992 might not have the luxury of section headers. Look for the DT_NULL
5993 terminator to determine the number of entries. */
5994 for (ext = edyn, dynamic_nent = 0;
5995 (char *) ext < (char *) edyn + dynamic_size;
5996 ext++)
5997 {
5998 dynamic_nent++;
5999 if (BYTE_GET (ext->d_tag)byte_get (ext->d_tag, sizeof (ext->d_tag)) == DT_NULL0)
6000 break;
6001 }
6002
6003 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
6004 if (dynamic_section == NULL((void*)0))
6005 {
6006 error (_("Out of memory\n")("Out of memory\n"));
6007 free (edyn);
6008 return 0;
6009 }
6010
6011 for (ext = edyn, entry = dynamic_section;
6012 entry < dynamic_section + dynamic_nent;
6013 ext++, entry++)
6014 {
6015 entry->d_tag = BYTE_GET (ext->d_tag)byte_get (ext->d_tag, sizeof (ext->d_tag));
6016 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val)byte_get (ext->d_un.d_val, sizeof (ext->d_un.d_val));
6017 }
6018
6019 free (edyn);
6020
6021 return 1;
6022}
6023
6024static void
6025print_dynamic_flags (bfd_vma flags)
6026{
6027 int first = 1;
6028
6029 while (flags)
6030 {
6031 bfd_vma flag;
6032
6033 flag = flags & - flags;
6034 flags &= ~ flag;
6035
6036 if (first)
6037 first = 0;
6038 else
6039 putc (' ', stdout)(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
6040
6041 switch (flag)
6042 {
6043 case DF_ORIGIN(1 << 0): fputs ("ORIGIN", stdout(&__sF[1])); break;
6044 case DF_SYMBOLIC(1 << 1): fputs ("SYMBOLIC", stdout(&__sF[1])); break;
6045 case DF_TEXTREL(1 << 2): fputs ("TEXTREL", stdout(&__sF[1])); break;
6046 case DF_BIND_NOW(1 << 3): fputs ("BIND_NOW", stdout(&__sF[1])); break;
6047 case DF_STATIC_TLS(1 << 4): fputs ("STATIC_TLS", stdout(&__sF[1])); break;
6048 default: fputs ("unknown", stdout(&__sF[1])); break;
6049 }
6050 }
6051 puts ("");
6052}
6053
6054/* Parse and display the contents of the dynamic section. */
6055
6056static int
6057process_dynamic_section (FILE *file)
6058{
6059 Elf_Internal_Dyn *entry;
6060
6061 if (dynamic_size == 0)
6062 {
6063 if (do_dynamic)
6064 printf (_("\nThere is no dynamic section in this file.\n")("\nThere is no dynamic section in this file.\n"));
6065
6066 return 1;
6067 }
6068
6069 if (is_32bit_elf)
6070 {
6071 if (! get_32bit_dynamic_section (file))
6072 return 0;
6073 }
6074 else if (! get_64bit_dynamic_section (file))
6075 return 0;
6076
6077 /* Find the appropriate symbol table. */
6078 if (dynamic_symbols == NULL((void*)0))
6079 {
6080 for (entry = dynamic_section;
6081 entry < dynamic_section + dynamic_nent;
6082 ++entry)
6083 {
6084 Elf_Internal_Shdr section;
6085
6086 if (entry->d_tag != DT_SYMTAB6)
6087 continue;
6088
6089 dynamic_info[DT_SYMTAB6] = entry->d_un.d_val;
6090
6091 /* Since we do not know how big the symbol table is,
6092 we default to reading in the entire file (!) and
6093 processing that. This is overkill, I know, but it
6094 should work. */
6095 section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
6096
6097 if (archive_file_offset != 0)
6098 section.sh_size = archive_file_size - section.sh_offset;
6099 else
6100 {
6101 if (fseek (file, 0, SEEK_END2))
6102 error (_("Unable to seek to end of file!")("Unable to seek to end of file!"));
6103
6104 section.sh_size = ftell (file) - section.sh_offset;
6105 }
6106
6107 if (is_32bit_elf)
6108 section.sh_entsize = sizeof (Elf32_External_Sym);
6109 else
6110 section.sh_entsize = sizeof (Elf64_External_Sym);
6111
6112 num_dynamic_syms = section.sh_size / section.sh_entsize;
6113 if (num_dynamic_syms < 1)
6114 {
6115 error (_("Unable to determine the number of symbols to load\n")("Unable to determine the number of symbols to load\n"));
6116 continue;
6117 }
6118
6119 dynamic_symbols = GET_ELF_SYMBOLS (file, &section)(is_32bit_elf ? get_32bit_elf_symbols (file, &section) : get_64bit_elf_symbols
(file, &section))
;
6120 }
6121 }
6122
6123 /* Similarly find a string table. */
6124 if (dynamic_strings == NULL((void*)0))
6125 {
6126 for (entry = dynamic_section;
6127 entry < dynamic_section + dynamic_nent;
6128 ++entry)
6129 {
6130 unsigned long offset;
6131 long str_tab_len;
6132
6133 if (entry->d_tag != DT_STRTAB5)
6134 continue;
6135
6136 dynamic_info[DT_STRTAB5] = entry->d_un.d_val;
6137
6138 /* Since we do not know how big the string table is,
6139 we default to reading in the entire file (!) and
6140 processing that. This is overkill, I know, but it
6141 should work. */
6142
6143 offset = offset_from_vma (file, entry->d_un.d_val, 0);
6144
6145 if (archive_file_offset != 0)
6146 str_tab_len = archive_file_size - offset;
6147 else
6148 {
6149 if (fseek (file, 0, SEEK_END2))
6150 error (_("Unable to seek to end of file\n")("Unable to seek to end of file\n"));
6151 str_tab_len = ftell (file) - offset;
6152 }
6153
6154 if (str_tab_len < 1)
6155 {
6156 error
6157 (_("Unable to determine the length of the dynamic string table\n")("Unable to determine the length of the dynamic string table\n"
)
);
6158 continue;
6159 }
6160
6161 dynamic_strings = get_data (NULL((void*)0), file, offset, 1, str_tab_len,
6162 _("dynamic string table")("dynamic string table"));
6163 dynamic_strings_length = str_tab_len;
6164 break;
6165 }
6166 }
6167
6168 /* And find the syminfo section if available. */
6169 if (dynamic_syminfo == NULL((void*)0))
6170 {
6171 unsigned long syminsz = 0;
6172
6173 for (entry = dynamic_section;
6174 entry < dynamic_section + dynamic_nent;
6175 ++entry)
6176 {
6177 if (entry->d_tag == DT_SYMINENT0x6ffffdff)
6178 {
6179 /* Note: these braces are necessary to avoid a syntax
6180 error from the SunOS4 C compiler. */
6181 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val)((sizeof (Elf_External_Syminfo) == entry->d_un.d_val) ? (void
)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/readelf.c"
, 6181, __func__, "sizeof (Elf_External_Syminfo) == entry->d_un.d_val"
))
;
6182 }
6183 else if (entry->d_tag == DT_SYMINSZ0x6ffffdfe)
6184 syminsz = entry->d_un.d_val;
6185 else if (entry->d_tag == DT_SYMINFO0x6ffffeff)
6186 dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
6187 syminsz);
6188 }
6189
6190 if (dynamic_syminfo_offset != 0 && syminsz != 0)
6191 {
6192 Elf_External_Syminfo *extsyminfo, *extsym;
6193 Elf_Internal_Syminfo *syminfo;
6194
6195 /* There is a syminfo section. Read the data. */
6196 extsyminfo = get_data (NULL((void*)0), file, dynamic_syminfo_offset, 1,
6197 syminsz, _("symbol information")("symbol information"));
6198 if (!extsyminfo)
6199 return 0;
6200
6201 dynamic_syminfo = malloc (syminsz);
6202 if (dynamic_syminfo == NULL((void*)0))
6203 {
6204 error (_("Out of memory\n")("Out of memory\n"));
6205 return 0;
6206 }
6207
6208 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
6209 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
6210 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
6211 ++syminfo, ++extsym)
6212 {
6213 syminfo->si_boundto = BYTE_GET (extsym->si_boundto)byte_get (extsym->si_boundto, sizeof (extsym->si_boundto
))
;
6214 syminfo->si_flags = BYTE_GET (extsym->si_flags)byte_get (extsym->si_flags, sizeof (extsym->si_flags));
6215 }
6216
6217 free (extsyminfo);
6218 }
6219 }
6220
6221 if (do_dynamic && dynamic_addr)
6222 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n")("\nDynamic section at offset 0x%lx contains %u entries:\n"),
6223 dynamic_addr, dynamic_nent);
6224 if (do_dynamic)
6225 printf (_(" Tag Type Name/Value\n")(" Tag Type Name/Value\n"));
6226
6227 for (entry = dynamic_section;
6228 entry < dynamic_section + dynamic_nent;
6229 entry++)
6230 {
6231 if (do_dynamic)
6232 {
6233 const char *dtype;
6234
6235 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
6236 print_vma (entry->d_tag, FULL_HEX);
6237 dtype = get_dynamic_type (entry->d_tag);
6238 printf (" (%s)%*s", dtype,
6239 ((is_32bit_elf ? 27 : 19)
6240 - (int) strlen (dtype)),
6241 " ");
6242 }
6243
6244 switch (entry->d_tag)
6245 {
6246 case DT_FLAGS30:
6247 if (do_dynamic)
6248 print_dynamic_flags (entry->d_un.d_val);
6249 break;
6250
6251 case DT_AUXILIARY0x7ffffffd:
6252 case DT_FILTER0x7fffffff:
6253 case DT_CONFIG0x6ffffefa:
6254 case DT_DEPAUDIT0x6ffffefb:
6255 case DT_AUDIT0x6ffffefc:
6256 if (do_dynamic)
6257 {
6258 switch (entry->d_tag)
6259 {
6260 case DT_AUXILIARY0x7ffffffd:
6261 printf (_("Auxiliary library")("Auxiliary library"));
6262 break;
6263
6264 case DT_FILTER0x7fffffff:
6265 printf (_("Filter library")("Filter library"));
6266 break;
6267
6268 case DT_CONFIG0x6ffffefa:
6269 printf (_("Configuration file")("Configuration file"));
6270 break;
6271
6272 case DT_DEPAUDIT0x6ffffefb:
6273 printf (_("Dependency audit library")("Dependency audit library"));
6274 break;
6275
6276 case DT_AUDIT0x6ffffefc:
6277 printf (_("Audit library")("Audit library"));
6278 break;
6279 }
6280
6281 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)((dynamic_strings != ((void*)0)) && (entry->d_un.d_val
< dynamic_strings_length))
)
6282 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val)(dynamic_strings + entry->d_un.d_val));
6283 else
6284 {
6285 printf (": ");
6286 print_vma (entry->d_un.d_val, PREFIX_HEX);
6287 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
6288 }
6289 }
6290 break;
6291
6292 case DT_FEATURE0x6ffffdfc:
6293 if (do_dynamic)
6294 {
6295 printf (_("Flags:")("Flags:"));
6296
6297 if (entry->d_un.d_val == 0)
6298 printf (_(" None\n")(" None\n"));
6299 else
6300 {
6301 unsigned long int val = entry->d_un.d_val;
6302
6303 if (val & DTF_1_PARINIT0x00000001)
6304 {
6305 printf (" PARINIT");
6306 val ^= DTF_1_PARINIT0x00000001;
6307 }
6308 if (val & DTF_1_CONFEXP0x00000002)
6309 {
6310 printf (" CONFEXP");
6311 val ^= DTF_1_CONFEXP0x00000002;
6312 }
6313 if (val != 0)
6314 printf (" %lx", val);
6315 puts ("");
6316 }
6317 }
6318 break;
6319
6320 case DT_POSFLAG_10x6ffffdfd:
6321 if (do_dynamic)
6322 {
6323 printf (_("Flags:")("Flags:"));
6324
6325 if (entry->d_un.d_val == 0)
6326 printf (_(" None\n")(" None\n"));
6327 else
6328 {
6329 unsigned long int val = entry->d_un.d_val;
6330
6331 if (val & DF_P1_LAZYLOAD0x00000001)
6332 {
6333 printf (" LAZYLOAD");
6334 val ^= DF_P1_LAZYLOAD0x00000001;
6335 }
6336 if (val & DF_P1_GROUPPERM0x00000002)
6337 {
6338 printf (" GROUPPERM");
6339 val ^= DF_P1_GROUPPERM0x00000002;
6340 }
6341 if (val != 0)
6342 printf (" %lx", val);
6343 puts ("");
6344 }
6345 }
6346 break;
6347
6348 case DT_FLAGS_10x6ffffffb:
6349 if (do_dynamic)
6350 {
6351 printf (_("Flags:")("Flags:"));
6352 if (entry->d_un.d_val == 0)
6353 printf (_(" None\n")(" None\n"));
6354 else
6355 {
6356 unsigned long int val = entry->d_un.d_val;
6357
6358 if (val & DF_1_NOW0x00000001)
6359 {
6360 printf (" NOW");
6361 val ^= DF_1_NOW0x00000001;
6362 }
6363 if (val & DF_1_GLOBAL0x00000002)
6364 {
6365 printf (" GLOBAL");
6366 val ^= DF_1_GLOBAL0x00000002;
6367 }
6368 if (val & DF_1_GROUP0x00000004)
6369 {
6370 printf (" GROUP");
6371 val ^= DF_1_GROUP0x00000004;
6372 }
6373 if (val & DF_1_NODELETE0x00000008)
6374 {
6375 printf (" NODELETE");
6376 val ^= DF_1_NODELETE0x00000008;
6377 }
6378 if (val & DF_1_LOADFLTR0x00000010)
6379 {
6380 printf (" LOADFLTR");
6381 val ^= DF_1_LOADFLTR0x00000010;
6382 }
6383 if (val & DF_1_INITFIRST0x00000020)
6384 {
6385 printf (" INITFIRST");
6386 val ^= DF_1_INITFIRST0x00000020;
6387 }
6388 if (val & DF_1_NOOPEN0x00000040)
6389 {
6390 printf (" NOOPEN");
6391 val ^= DF_1_NOOPEN0x00000040;
6392 }
6393 if (val & DF_1_ORIGIN0x00000080)
6394 {
6395 printf (" ORIGIN");
6396 val ^= DF_1_ORIGIN0x00000080;
6397 }
6398 if (val & DF_1_DIRECT0x00000100)
6399 {
6400 printf (" DIRECT");
6401 val ^= DF_1_DIRECT0x00000100;
6402 }
6403 if (val & DF_1_TRANS0x00000200)
6404 {
6405 printf (" TRANS");
6406 val ^= DF_1_TRANS0x00000200;
6407 }
6408 if (val & DF_1_INTERPOSE0x00000400)
6409 {
6410 printf (" INTERPOSE");
6411 val ^= DF_1_INTERPOSE0x00000400;
6412 }
6413 if (val & DF_1_NODEFLIB0x00000800)
6414 {
6415 printf (" NODEFLIB");
6416 val ^= DF_1_NODEFLIB0x00000800;
6417 }
6418 if (val & DF_1_NODUMP0x00001000)
6419 {
6420 printf (" NODUMP");
6421 val ^= DF_1_NODUMP0x00001000;
6422 }
6423 if (val & DF_1_CONLFAT0x00002000)
6424 {
6425 printf (" CONLFAT");
6426 val ^= DF_1_CONLFAT0x00002000;
6427 }
6428 if (val & DF_1_ENDFILTEE0x00004000)
6429 {
6430 printf (" ENDFILTEE");
6431 val ^= DF_1_ENDFILTEE0x00004000;
6432 }
6433 if (val & DF_1_DISPRELDNE0x00008000)
6434 {
6435 printf (" DISPRELDNE");
6436 val ^= DF_1_DISPRELDNE0x00008000;
6437 }
6438 if (val & DF_1_DISPRELPND0x00010000)
6439 {
6440 printf (" DISPRELPND");
6441 val ^= DF_1_DISPRELPND0x00010000;
6442 }
6443 if (val & DF_1_NODIRECT0x00020000)
6444 {
6445 printf (" NODIRECT");
6446 val ^= DF_1_NODIRECT0x00020000;
6447 }
6448 if (val & DF_1_IGNMULDEF0x00040000)
6449 {
6450 printf (" IGNMULDEF");
6451 val ^= DF_1_IGNMULDEF0x00040000;
6452 }
6453 if (val & DF_1_NOKSYMS0x00080000)
6454 {
6455 printf (" NOKSYMS");
6456 val ^= DF_1_NOKSYMS0x00080000;
6457 }
6458 if (val & DF_1_NOHDR0x00100000)
6459 {
6460 printf (" NOHDR");
6461 val ^= DF_1_NOHDR0x00100000;
6462 }
6463 if (val & DF_1_EDITED0x00200000)
6464 {
6465 printf (" EDITED");
6466 val ^= DF_1_EDITED0x00200000;
6467 }
6468 if (val & DF_1_NORELOC0x00400000)
6469 {
6470 printf (" NORELOC");
6471 val ^= DF_1_NORELOC0x00400000;
6472 }
6473 if (val & DF_1_SYMINTPOSE0x00800000)
6474 {
6475 printf (" SYMINTPOSE");
6476 val ^= DF_1_SYMINTPOSE0x00800000;
6477 }
6478 if (val & DF_1_GLOBAUDIT0x01000000)
6479 {
6480 printf (" GLOBAUDIT");
6481 val ^= DF_1_GLOBAUDIT0x01000000;
6482 }
6483 if (val & DF_1_SINGLETON0x02000000)
6484 {
6485 printf (" SINGLETON");
6486 val ^= DF_1_SINGLETON0x02000000;
6487 }
6488 if (val & DF_1_PIE0x08000000)
6489 {
6490 printf (" PIE");
6491 val ^= DF_1_PIE0x08000000;
6492 }
6493 if (val != 0)
6494 printf (" %lx", val);
6495 puts ("");
6496 }
6497 }
6498 break;
6499
6500 case DT_PLTREL20:
6501 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6502 if (do_dynamic)
6503 puts (get_dynamic_type (entry->d_un.d_val));
6504 break;
6505
6506 case DT_NULL0 :
6507 case DT_NEEDED1 :
6508 case DT_PLTGOT3 :
6509 case DT_HASH4 :
6510 case DT_STRTAB5 :
6511 case DT_SYMTAB6 :
6512 case DT_RELA7 :
6513 case DT_INIT12 :
6514 case DT_FINI13 :
6515 case DT_SONAME14 :
6516 case DT_RPATH15 :
6517 case DT_SYMBOLIC16:
6518 case DT_REL17 :
6519 case DT_DEBUG21 :
6520 case DT_TEXTREL22 :
6521 case DT_JMPREL23 :
6522 case DT_RUNPATH29 :
6523 case DT_RELR36 :
6524 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6525
6526 if (do_dynamic)
6527 {
6528 char *name;
6529
6530 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)((dynamic_strings != ((void*)0)) && (entry->d_un.d_val
< dynamic_strings_length))
)
6531 name = GET_DYNAMIC_NAME (entry->d_un.d_val)(dynamic_strings + entry->d_un.d_val);
6532 else
6533 name = NULL((void*)0);
6534
6535 if (name)
6536 {
6537 switch (entry->d_tag)
6538 {
6539 case DT_NEEDED1:
6540 printf (_("Shared library: [%s]")("Shared library: [%s]"), name);
6541
6542 if (streq (name, program_interpreter)(strcmp ((name), (program_interpreter)) == 0))
6543 printf (_(" program interpreter")(" program interpreter"));
6544 break;
6545
6546 case DT_SONAME14:
6547 printf (_("Library soname: [%s]")("Library soname: [%s]"), name);
6548 break;
6549
6550 case DT_RPATH15:
6551 printf (_("Library rpath: [%s]")("Library rpath: [%s]"), name);
6552 break;
6553
6554 case DT_RUNPATH29:
6555 printf (_("Library runpath: [%s]")("Library runpath: [%s]"), name);
6556 break;
6557
6558 default:
6559 print_vma (entry->d_un.d_val, PREFIX_HEX);
6560 break;
6561 }
6562 }
6563 else
6564 print_vma (entry->d_un.d_val, PREFIX_HEX);
6565
6566 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
6567 }
6568 break;
6569
6570 case DT_PLTRELSZ2:
6571 case DT_RELASZ8 :
6572 case DT_STRSZ10 :
6573 case DT_RELSZ18 :
6574 case DT_RELRSZ35 :
6575 case DT_RELAENT9 :
6576 case DT_SYMENT11 :
6577 case DT_RELENT19 :
6578 case DT_RELRENT37 :
6579 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6580 case DT_PLTPADSZ0x6ffffdf9:
6581 case DT_MOVEENT0x6ffffdfa :
6582 case DT_MOVESZ0x6ffffdfb :
6583 case DT_INIT_ARRAYSZ27:
6584 case DT_FINI_ARRAYSZ28:
6585 case DT_GNU_CONFLICTSZ0x6ffffdf6:
6586 case DT_GNU_LIBLISTSZ0x6ffffdf7:
6587 if (do_dynamic)
6588 {
6589 print_vma (entry->d_un.d_val, UNSIGNED);
6590 printf (" (bytes)\n");
6591 }
6592 break;
6593
6594 case DT_VERDEFNUM0x6ffffffd:
6595 case DT_VERNEEDNUM0x6fffffff:
6596 case DT_RELACOUNT0x6ffffff9:
6597 case DT_RELCOUNT0x6ffffffa:
6598 if (do_dynamic)
6599 {
6600 print_vma (entry->d_un.d_val, UNSIGNED);
6601 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
6602 }
6603 break;
6604
6605 case DT_SYMINSZ0x6ffffdfe:
6606 case DT_SYMINENT0x6ffffdff:
6607 case DT_SYMINFO0x6ffffeff:
6608 case DT_USED0x7ffffffe:
6609 case DT_INIT_ARRAY25:
6610 case DT_FINI_ARRAY26:
6611 if (do_dynamic)
6612 {
6613 if (entry->d_tag == DT_USED0x7ffffffe
6614 && VALID_DYNAMIC_NAME (entry->d_un.d_val)((dynamic_strings != ((void*)0)) && (entry->d_un.d_val
< dynamic_strings_length))
)
6615 {
6616 char *name = GET_DYNAMIC_NAME (entry->d_un.d_val)(dynamic_strings + entry->d_un.d_val);
6617
6618 if (*name)
6619 {
6620 printf (_("Not needed object: [%s]\n")("Not needed object: [%s]\n"), name);
6621 break;
6622 }
6623 }
6624
6625 print_vma (entry->d_un.d_val, PREFIX_HEX);
6626 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
6627 }
6628 break;
6629
6630 case DT_BIND_NOW24:
6631 /* The value of this entry is ignored. */
6632 if (do_dynamic)
6633 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
6634 break;
6635
6636 case DT_GNU_PRELINKED0x6ffffdf5:
6637 if (do_dynamic)
6638 {
6639 struct tm *tmp;
6640 time_t time = entry->d_un.d_val;
6641
6642 tmp = gmtime (&time);
6643 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6644 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
6645 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
6646
6647 }
6648 break;
6649
6650 case DT_GNU_HASH0x6ffffef5:
6651 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
6652 if (do_dynamic)
6653 {
6654 print_vma (entry->d_un.d_val, PREFIX_HEX);
6655 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
6656 }
6657 break;
6658
6659 default:
6660 if ((entry->d_tag >= DT_VERSYM0x6ffffff0) && (entry->d_tag <= DT_VERNEEDNUM0x6fffffff))
6661 version_info[DT_VERSIONTAGIDX (entry->d_tag)(0x6fffffff - (entry->d_tag))] =
6662 entry->d_un.d_val;
6663
6664 if (do_dynamic)
6665 {
6666 switch (elf_header.e_machine)
6667 {
6668 case EM_MIPS8:
6669 case EM_MIPS_RS3_LE10:
6670 dynamic_section_mips_val (entry);
6671 break;
6672 case EM_PARISC15:
6673 dynamic_section_parisc_val (entry);
6674 break;
6675 case EM_IA_6450:
6676 dynamic_section_ia64_val (entry);
6677 break;
6678 default:
6679 print_vma (entry->d_un.d_val, PREFIX_HEX);
6680 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
6681 }
6682 }
6683 break;
6684 }
6685 }
6686
6687 return 1;
6688}
6689
6690static char *
6691get_ver_flags (unsigned int flags)
6692{
6693 static char buff[32];
6694
6695 buff[0] = 0;
6696
6697 if (flags == 0)
6698 return _("none")("none");
6699
6700 if (flags & VER_FLG_BASE0x1)
6701 strcat (buff, "BASE ");
6702
6703 if (flags & VER_FLG_WEAK0x2)
6704 {
6705 if (flags & VER_FLG_BASE0x1)
6706 strcat (buff, "| ");
6707
6708 strcat (buff, "WEAK ");
6709 }
6710
6711 if (flags & ~(VER_FLG_BASE0x1 | VER_FLG_WEAK0x2))
6712 strcat (buff, "| <unknown>");
6713
6714 return buff;
6715}
6716
6717/* Display the contents of the version sections. */
6718static int
6719process_version_sections (FILE *file)
6720{
6721 Elf_Internal_Shdr *section;
6722 unsigned i;
6723 int found = 0;
6724
6725 if (! do_version)
6726 return 1;
6727
6728 for (i = 0, section = section_headers;
6729 i < elf_header.e_shnum;
6730 i++, section++)
6731 {
6732 switch (section->sh_type)
6733 {
6734 case SHT_GNU_verdef0x6ffffffd:
6735 {
6736 Elf_External_Verdef *edefs;
6737 unsigned int idx;
6738 unsigned int cnt;
6739
6740 found = 1;
6741
6742 printf
6743 (_("\nVersion definition section '%s' contains %ld entries:\n")("\nVersion definition section '%s' contains %ld entries:\n"),
6744 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
, section->sh_info);
6745
6746 printf (_(" Addr: 0x")(" Addr: 0x"));
6747 printf_vma (section->sh_addr)fprintf ((&__sF[1]), "%016lx", section->sh_addr);
6748 printf (_(" Offset: %#08lx Link: %lx (%s)\n")(" Offset: %#08lx Link: %lx (%s)\n"),
6749 (unsigned long) section->sh_offset, section->sh_link,
6750 SECTION_HEADER_INDEX (section->sh_link)((section->sh_link) < 0xFF00 ? (section->sh_link) : (
(section->sh_link) <= 0xFFFF ? 0 : (section->sh_link
) - (0xFFFF + 1 - 0xFF00)))
6751 < elf_header.e_shnum
6752 ? SECTION_NAME (SECTION_HEADER (section->sh_link))(((section_headers + ((section->sh_link) < 0xFF00 ? (section
->sh_link) : ((section->sh_link) <= 0xFFFF ? 0 : (section
->sh_link) - (0xFFFF + 1 - 0xFF00))))) == ((void*)0) ? "<none>"
: (((section_headers + ((section->sh_link) < 0xFF00 ? (
section->sh_link) : ((section->sh_link) <= 0xFFFF ? 0
: (section->sh_link) - (0xFFFF + 1 - 0xFF00)))))->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ ((section_headers + ((section->sh_link) < 0xFF00 ? (
section->sh_link) : ((section->sh_link) <= 0xFFFF ? 0
: (section->sh_link) - (0xFFFF + 1 - 0xFF00)))))->sh_name
))
6753 : "<corrupt>");
6754
6755 edefs = get_data (NULL((void*)0), file, section->sh_offset, 1,
6756 section->sh_size,
6757 _("version definition section")("version definition section"));
6758 if (!edefs)
6759 break;
6760
6761 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6762 {
6763 char *vstart;
6764 Elf_External_Verdef *edef;
6765 Elf_Internal_Verdef ent;
6766 Elf_External_Verdaux *eaux;
6767 Elf_Internal_Verdaux aux;
6768 int j;
6769 int isum;
6770
6771 vstart = ((char *) edefs) + idx;
6772
6773 edef = (Elf_External_Verdef *) vstart;
6774
6775 ent.vd_version = BYTE_GET (edef->vd_version)byte_get (edef->vd_version, sizeof (edef->vd_version));
6776 ent.vd_flags = BYTE_GET (edef->vd_flags)byte_get (edef->vd_flags, sizeof (edef->vd_flags));
6777 ent.vd_ndx = BYTE_GET (edef->vd_ndx)byte_get (edef->vd_ndx, sizeof (edef->vd_ndx));
6778 ent.vd_cnt = BYTE_GET (edef->vd_cnt)byte_get (edef->vd_cnt, sizeof (edef->vd_cnt));
6779 ent.vd_hash = BYTE_GET (edef->vd_hash)byte_get (edef->vd_hash, sizeof (edef->vd_hash));
6780 ent.vd_aux = BYTE_GET (edef->vd_aux)byte_get (edef->vd_aux, sizeof (edef->vd_aux));
6781 ent.vd_next = BYTE_GET (edef->vd_next)byte_get (edef->vd_next, sizeof (edef->vd_next));
6782
6783 printf (_(" %#06x: Rev: %d Flags: %s")(" %#06x: Rev: %d Flags: %s"),
6784 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
6785
6786 printf (_(" Index: %d Cnt: %d ")(" Index: %d Cnt: %d "),
6787 ent.vd_ndx, ent.vd_cnt);
6788
6789 vstart += ent.vd_aux;
6790
6791 eaux = (Elf_External_Verdaux *) vstart;
6792
6793 aux.vda_name = BYTE_GET (eaux->vda_name)byte_get (eaux->vda_name, sizeof (eaux->vda_name));
6794 aux.vda_next = BYTE_GET (eaux->vda_next)byte_get (eaux->vda_next, sizeof (eaux->vda_next));
6795
6796 if (VALID_DYNAMIC_NAME (aux.vda_name)((dynamic_strings != ((void*)0)) && (aux.vda_name <
dynamic_strings_length))
)
6797 printf (_("Name: %s\n")("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name)(dynamic_strings + aux.vda_name));
6798 else
6799 printf (_("Name index: %ld\n")("Name index: %ld\n"), aux.vda_name);
6800
6801 isum = idx + ent.vd_aux;
6802
6803 for (j = 1; j < ent.vd_cnt; j++)
6804 {
6805 isum += aux.vda_next;
6806 vstart += aux.vda_next;
6807
6808 eaux = (Elf_External_Verdaux *) vstart;
6809
6810 aux.vda_name = BYTE_GET (eaux->vda_name)byte_get (eaux->vda_name, sizeof (eaux->vda_name));
6811 aux.vda_next = BYTE_GET (eaux->vda_next)byte_get (eaux->vda_next, sizeof (eaux->vda_next));
6812
6813 if (VALID_DYNAMIC_NAME (aux.vda_name)((dynamic_strings != ((void*)0)) && (aux.vda_name <
dynamic_strings_length))
)
6814 printf (_(" %#06x: Parent %d: %s\n")(" %#06x: Parent %d: %s\n"),
6815 isum, j, GET_DYNAMIC_NAME (aux.vda_name)(dynamic_strings + aux.vda_name));
6816 else
6817 printf (_(" %#06x: Parent %d, name index: %ld\n")(" %#06x: Parent %d, name index: %ld\n"),
6818 isum, j, aux.vda_name);
6819 }
6820
6821 idx += ent.vd_next;
6822 }
6823
6824 free (edefs);
6825 }
6826 break;
6827
6828 case SHT_GNU_verneed0x6ffffffe:
6829 {
6830 Elf_External_Verneed *eneed;
6831 unsigned int idx;
6832 unsigned int cnt;
6833
6834 found = 1;
6835
6836 printf (_("\nVersion needs section '%s' contains %ld entries:\n")("\nVersion needs section '%s' contains %ld entries:\n"),
6837 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
, section->sh_info);
6838
6839 printf (_(" Addr: 0x")(" Addr: 0x"));
6840 printf_vma (section->sh_addr)fprintf ((&__sF[1]), "%016lx", section->sh_addr);
6841 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n")(" Offset: %#08lx Link to section: %ld (%s)\n"),
6842 (unsigned long) section->sh_offset, section->sh_link,
6843 SECTION_HEADER_INDEX (section->sh_link)((section->sh_link) < 0xFF00 ? (section->sh_link) : (
(section->sh_link) <= 0xFFFF ? 0 : (section->sh_link
) - (0xFFFF + 1 - 0xFF00)))
6844 < elf_header.e_shnum
6845 ? SECTION_NAME (SECTION_HEADER (section->sh_link))(((section_headers + ((section->sh_link) < 0xFF00 ? (section
->sh_link) : ((section->sh_link) <= 0xFFFF ? 0 : (section
->sh_link) - (0xFFFF + 1 - 0xFF00))))) == ((void*)0) ? "<none>"
: (((section_headers + ((section->sh_link) < 0xFF00 ? (
section->sh_link) : ((section->sh_link) <= 0xFFFF ? 0
: (section->sh_link) - (0xFFFF + 1 - 0xFF00)))))->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ ((section_headers + ((section->sh_link) < 0xFF00 ? (
section->sh_link) : ((section->sh_link) <= 0xFFFF ? 0
: (section->sh_link) - (0xFFFF + 1 - 0xFF00)))))->sh_name
))
6846 : "<corrupt>");
6847
6848 eneed = get_data (NULL((void*)0), file, section->sh_offset, 1,
6849 section->sh_size,
6850 _("version need section")("version need section"));
6851 if (!eneed)
6852 break;
6853
6854 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6855 {
6856 Elf_External_Verneed *entry;
6857 Elf_Internal_Verneed ent;
6858 int j;
6859 int isum;
6860 char *vstart;
6861
6862 vstart = ((char *) eneed) + idx;
6863
6864 entry = (Elf_External_Verneed *) vstart;
6865
6866 ent.vn_version = BYTE_GET (entry->vn_version)byte_get (entry->vn_version, sizeof (entry->vn_version)
)
;
6867 ent.vn_cnt = BYTE_GET (entry->vn_cnt)byte_get (entry->vn_cnt, sizeof (entry->vn_cnt));
6868 ent.vn_file = BYTE_GET (entry->vn_file)byte_get (entry->vn_file, sizeof (entry->vn_file));
6869 ent.vn_aux = BYTE_GET (entry->vn_aux)byte_get (entry->vn_aux, sizeof (entry->vn_aux));
6870 ent.vn_next = BYTE_GET (entry->vn_next)byte_get (entry->vn_next, sizeof (entry->vn_next));
6871
6872 printf (_(" %#06x: Version: %d")(" %#06x: Version: %d"), idx, ent.vn_version);
6873
6874 if (VALID_DYNAMIC_NAME (ent.vn_file)((dynamic_strings != ((void*)0)) && (ent.vn_file <
dynamic_strings_length))
)
6875 printf (_(" File: %s")(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file)(dynamic_strings + ent.vn_file));
6876 else
6877 printf (_(" File: %lx")(" File: %lx"), ent.vn_file);
6878
6879 printf (_(" Cnt: %d\n")(" Cnt: %d\n"), ent.vn_cnt);
6880
6881 vstart += ent.vn_aux;
6882
6883 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
6884 {
6885 Elf_External_Vernaux *eaux;
6886 Elf_Internal_Vernaux aux;
6887
6888 eaux = (Elf_External_Vernaux *) vstart;
6889
6890 aux.vna_hash = BYTE_GET (eaux->vna_hash)byte_get (eaux->vna_hash, sizeof (eaux->vna_hash));
6891 aux.vna_flags = BYTE_GET (eaux->vna_flags)byte_get (eaux->vna_flags, sizeof (eaux->vna_flags));
6892 aux.vna_other = BYTE_GET (eaux->vna_other)byte_get (eaux->vna_other, sizeof (eaux->vna_other));
6893 aux.vna_name = BYTE_GET (eaux->vna_name)byte_get (eaux->vna_name, sizeof (eaux->vna_name));
6894 aux.vna_next = BYTE_GET (eaux->vna_next)byte_get (eaux->vna_next, sizeof (eaux->vna_next));
6895
6896 if (VALID_DYNAMIC_NAME (aux.vna_name)((dynamic_strings != ((void*)0)) && (aux.vna_name <
dynamic_strings_length))
)
6897 printf (_(" %#06x: Name: %s")(" %#06x: Name: %s"),
6898 isum, GET_DYNAMIC_NAME (aux.vna_name)(dynamic_strings + aux.vna_name));
6899 else
6900 printf (_(" %#06x: Name index: %lx")(" %#06x: Name index: %lx"),
6901 isum, aux.vna_name);
6902
6903 printf (_(" Flags: %s Version: %d\n")(" Flags: %s Version: %d\n"),
6904 get_ver_flags (aux.vna_flags), aux.vna_other);
6905
6906 isum += aux.vna_next;
6907 vstart += aux.vna_next;
6908 }
6909
6910 idx += ent.vn_next;
6911 }
6912
6913 free (eneed);
6914 }
6915 break;
6916
6917 case SHT_GNU_versym0x6fffffff:
6918 {
6919 Elf_Internal_Shdr *link_section;
6920 int total;
6921 int cnt;
6922 unsigned char *edata;
6923 unsigned short *data;
6924 char *strtab;
6925 Elf_Internal_Sym *symbols;
6926 Elf_Internal_Shdr *string_sec;
6927 long off;
6928
6929 if (SECTION_HEADER_INDEX (section->sh_link)((section->sh_link) < 0xFF00 ? (section->sh_link) : (
(section->sh_link) <= 0xFFFF ? 0 : (section->sh_link
) - (0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum)
6930 break;
6931
6932 link_section = SECTION_HEADER (section->sh_link)(section_headers + ((section->sh_link) < 0xFF00 ? (section
->sh_link) : ((section->sh_link) <= 0xFFFF ? 0 : (section
->sh_link) - (0xFFFF + 1 - 0xFF00))))
;
6933 total = section->sh_size / sizeof (Elf_External_Versym);
6934
6935 if (SECTION_HEADER_INDEX (link_section->sh_link)((link_section->sh_link) < 0xFF00 ? (link_section->sh_link
) : ((link_section->sh_link) <= 0xFFFF ? 0 : (link_section
->sh_link) - (0xFFFF + 1 - 0xFF00)))
6936 >= elf_header.e_shnum)
6937 break;
6938
6939 found = 1;
6940
6941 symbols = GET_ELF_SYMBOLS (file, link_section)(is_32bit_elf ? get_32bit_elf_symbols (file, link_section) : get_64bit_elf_symbols
(file, link_section))
;
6942
6943 string_sec = SECTION_HEADER (link_section->sh_link)(section_headers + ((link_section->sh_link) < 0xFF00 ? (
link_section->sh_link) : ((link_section->sh_link) <=
0xFFFF ? 0 : (link_section->sh_link) - (0xFFFF + 1 - 0xFF00
))))
;
6944
6945 strtab = get_data (NULL((void*)0), file, string_sec->sh_offset, 1,
6946 string_sec->sh_size, _("version string table")("version string table"));
6947 if (!strtab)
6948 break;
6949
6950 printf (_("\nVersion symbols section '%s' contains %d entries:\n")("\nVersion symbols section '%s' contains %d entries:\n"),
6951 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
, total);
6952
6953 printf (_(" Addr: ")(" Addr: "));
6954 printf_vma (section->sh_addr)fprintf ((&__sF[1]), "%016lx", section->sh_addr);
6955 printf (_(" Offset: %#08lx Link: %lx (%s)\n")(" Offset: %#08lx Link: %lx (%s)\n"),
6956 (unsigned long) section->sh_offset, section->sh_link,
6957 SECTION_NAME (link_section)((link_section) == ((void*)0) ? "<none>" : ((link_section
)->sh_name >= string_table_length ? "<corrupt>" :
string_table + (link_section)->sh_name))
);
6958
6959 off = offset_from_vma (file,
6960 version_info[DT_VERSIONTAGIDX (DT_VERSYM)(0x6fffffff - (0x6ffffff0))],
6961 total * sizeof (short));
6962 edata = get_data (NULL((void*)0), file, off, total, sizeof (short),
6963 _("version symbol data")("version symbol data"));
6964 if (!edata)
6965 {
6966 free (strtab);
6967 break;
6968 }
6969
6970 data = cmalloc (total, sizeof (short));
6971
6972 for (cnt = total; cnt --;)
6973 data[cnt] = byte_get (edata + cnt * sizeof (short),
6974 sizeof (short));
6975
6976 free (edata);
6977
6978 for (cnt = 0; cnt < total; cnt += 4)
6979 {
6980 int j, nn;
6981 int check_def, check_need;
6982 char *name;
6983
6984 printf (" %03x:", cnt);
6985
6986 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
6987 switch (data[cnt + j])
6988 {
6989 case 0:
6990 fputs (_(" 0 (*local*) ")(" 0 (*local*) "), stdout(&__sF[1]));
6991 break;
6992
6993 case 1:
6994 fputs (_(" 1 (*global*) ")(" 1 (*global*) "), stdout(&__sF[1]));
6995 break;
6996
6997 default:
6998 nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
6999 data[cnt + j] & 0x8000 ? 'h' : ' ');
7000
7001 check_def = 1;
7002 check_need = 1;
7003 if (SECTION_HEADER_INDEX (symbols[cnt + j].st_shndx)((symbols[cnt + j].st_shndx) < 0xFF00 ? (symbols[cnt + j].
st_shndx) : ((symbols[cnt + j].st_shndx) <= 0xFFFF ? 0 : (
symbols[cnt + j].st_shndx) - (0xFFFF + 1 - 0xFF00)))
7004 >= elf_header.e_shnum
7005 || SECTION_HEADER (symbols[cnt + j].st_shndx)(section_headers + ((symbols[cnt + j].st_shndx) < 0xFF00 ?
(symbols[cnt + j].st_shndx) : ((symbols[cnt + j].st_shndx) <=
0xFFFF ? 0 : (symbols[cnt + j].st_shndx) - (0xFFFF + 1 - 0xFF00
))))
->sh_type
7006 != SHT_NOBITS8)
7007 {
7008 if (symbols[cnt + j].st_shndx == SHN_UNDEF0)
7009 check_def = 0;
7010 else
7011 check_need = 0;
7012 }
7013
7014 if (check_need
7015 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)(0x6fffffff - (0x6ffffffe))])
7016 {
7017 Elf_Internal_Verneed ivn;
7018 unsigned long offset;
7019
7020 offset = offset_from_vma
7021 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)(0x6fffffff - (0x6ffffffe))],
7022 sizeof (Elf_External_Verneed));
7023
7024 do
7025 {
7026 Elf_Internal_Vernaux ivna;
7027 Elf_External_Verneed evn;
7028 Elf_External_Vernaux evna;
7029 unsigned long a_off;
7030
7031 get_data (&evn, file, offset, sizeof (evn), 1,
7032 _("version need")("version need"));
7033
7034 ivn.vn_aux = BYTE_GET (evn.vn_aux)byte_get (evn.vn_aux, sizeof (evn.vn_aux));
7035 ivn.vn_next = BYTE_GET (evn.vn_next)byte_get (evn.vn_next, sizeof (evn.vn_next));
7036
7037 a_off = offset + ivn.vn_aux;
7038
7039 do
7040 {
7041 get_data (&evna, file, a_off, sizeof (evna),
7042 1, _("version need aux (2)")("version need aux (2)"));
7043
7044 ivna.vna_next = BYTE_GET (evna.vna_next)byte_get (evna.vna_next, sizeof (evna.vna_next));
7045 ivna.vna_other = BYTE_GET (evna.vna_other)byte_get (evna.vna_other, sizeof (evna.vna_other));
7046
7047 a_off += ivna.vna_next;
7048 }
7049 while (ivna.vna_other != data[cnt + j]
7050 && ivna.vna_next != 0);
7051
7052 if (ivna.vna_other == data[cnt + j])
7053 {
7054 ivna.vna_name = BYTE_GET (evna.vna_name)byte_get (evna.vna_name, sizeof (evna.vna_name));
7055
7056 name = strtab + ivna.vna_name;
7057 nn += printf ("(%s%-*s",
7058 name,
7059 12 - (int) strlen (name),
7060 ")");
7061 check_def = 0;
7062 break;
7063 }
7064
7065 offset += ivn.vn_next;
7066 }
7067 while (ivn.vn_next);
7068 }
7069
7070 if (check_def && data[cnt + j] != 0x8001
7071 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)(0x6fffffff - (0x6ffffffc))])
7072 {
7073 Elf_Internal_Verdef ivd;
7074 Elf_External_Verdef evd;
7075 unsigned long offset;
7076
7077 offset = offset_from_vma
7078 (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)(0x6fffffff - (0x6ffffffc))],
7079 sizeof evd);
7080
7081 do
7082 {
7083 get_data (&evd, file, offset, sizeof (evd), 1,
7084 _("version def")("version def"));
7085
7086 ivd.vd_next = BYTE_GET (evd.vd_next)byte_get (evd.vd_next, sizeof (evd.vd_next));
7087 ivd.vd_ndx = BYTE_GET (evd.vd_ndx)byte_get (evd.vd_ndx, sizeof (evd.vd_ndx));
7088
7089 offset += ivd.vd_next;
7090 }
7091 while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
7092 && ivd.vd_next != 0);
7093
7094 if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
7095 {
7096 Elf_External_Verdaux evda;
7097 Elf_Internal_Verdaux ivda;
7098
7099 ivd.vd_aux = BYTE_GET (evd.vd_aux)byte_get (evd.vd_aux, sizeof (evd.vd_aux));
7100
7101 get_data (&evda, file,
7102 offset - ivd.vd_next + ivd.vd_aux,
7103 sizeof (evda), 1,
7104 _("version def aux")("version def aux"));
7105
7106 ivda.vda_name = BYTE_GET (evda.vda_name)byte_get (evda.vda_name, sizeof (evda.vda_name));
7107
7108 name = strtab + ivda.vda_name;
7109 nn += printf ("(%s%-*s",
7110 name,
7111 12 - (int) strlen (name),
7112 ")");
7113 }
7114 }
7115
7116 if (nn < 18)
7117 printf ("%*c", 18 - nn, ' ');
7118 }
7119
7120 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
7121 }
7122
7123 free (data);
7124 free (strtab);
7125 free (symbols);
7126 }
7127 break;
7128
7129 default:
7130 break;
7131 }
7132 }
7133
7134 if (! found)
7135 printf (_("\nNo version information found in this file.\n")("\nNo version information found in this file.\n"));
7136
7137 return 1;
7138}
7139
7140static const char *
7141get_symbol_binding (unsigned int binding)
7142{
7143 static char buff[32];
7144
7145 switch (binding)
7146 {
7147 case STB_LOCAL0: return "LOCAL";
7148 case STB_GLOBAL1: return "GLOBAL";
7149 case STB_WEAK2: return "WEAK";
7150 default:
7151 if (binding >= STB_LOPROC13 && binding <= STB_HIPROC15)
7152 snprintf (buff, sizeof (buff), _("<processor specific>: %d")("<processor specific>: %d"),
7153 binding);
7154 else if (binding >= STB_LOOS10 && binding <= STB_HIOS12)
7155 snprintf (buff, sizeof (buff), _("<OS specific>: %d")("<OS specific>: %d"), binding);
7156 else
7157 snprintf (buff, sizeof (buff), _("<unknown>: %d")("<unknown>: %d"), binding);
7158 return buff;
7159 }
7160}
7161
7162static const char *
7163get_symbol_type (unsigned int type)
7164{
7165 static char buff[32];
7166
7167 switch (type)
7168 {
7169 case STT_NOTYPE0: return "NOTYPE";
7170 case STT_OBJECT1: return "OBJECT";
7171 case STT_FUNC2: return "FUNC";
7172 case STT_SECTION3: return "SECTION";
7173 case STT_FILE4: return "FILE";
7174 case STT_COMMON5: return "COMMON";
7175 case STT_TLS6: return "TLS";
7176 default:
7177 if (type >= STT_LOPROC13 && type <= STT_HIPROC15)
7178 {
7179 if (elf_header.e_machine == EM_ARM40 && type == STT_ARM_TFUNC13)
7180 return "THUMB_FUNC";
7181
7182 if (elf_header.e_machine == EM_SPARCV943 && type == STT_REGISTER13)
7183 return "REGISTER";
7184
7185 if (elf_header.e_machine == EM_PARISC15 && type == STT_PARISC_MILLI13)
7186 return "PARISC_MILLI";
7187
7188 snprintf (buff, sizeof (buff), _("<processor specific>: %d")("<processor specific>: %d"), type);
7189 }
7190 else if (type >= STT_LOOS10 && type <= STT_HIOS12)
7191 {
7192 if (elf_header.e_machine == EM_PARISC15)
7193 {
7194 if (type == STT_HP_OPAQUE(10 + 0x1))
7195 return "HP_OPAQUE";
7196 if (type == STT_HP_STUB(10 + 0x2))
7197 return "HP_STUB";
7198 }
7199
7200 snprintf (buff, sizeof (buff), _("<OS specific>: %d")("<OS specific>: %d"), type);
7201 }
7202 else
7203 snprintf (buff, sizeof (buff), _("<unknown>: %d")("<unknown>: %d"), type);
7204 return buff;
7205 }
7206}
7207
7208static const char *
7209get_symbol_visibility (unsigned int visibility)
7210{
7211 switch (visibility)
7212 {
7213 case STV_DEFAULT0: return "DEFAULT";
7214 case STV_INTERNAL1: return "INTERNAL";
7215 case STV_HIDDEN2: return "HIDDEN";
7216 case STV_PROTECTED3: return "PROTECTED";
7217 default: abort ();
7218 }
7219}
7220
7221static const char *
7222get_mips_symbol_other (unsigned int other)
7223{
7224 switch (other)
7225 {
7226 case STO_OPTIONAL(1 << 2): return "OPTIONAL";
7227 case STO_MIPS160xf0: return "MIPS16";
7228 default: return NULL((void*)0);
7229 }
7230}
7231
7232static const char *
7233get_symbol_other (unsigned int other)
7234{
7235 const char * result = NULL((void*)0);
7236 static char buff [32];
7237
7238 if (other == 0)
7239 return "";
7240
7241 switch (elf_header.e_machine)
7242 {
7243 case EM_MIPS8:
7244 result = get_mips_symbol_other (other);
7245 default:
7246 break;
7247 }
7248
7249 if (result)
7250 return result;
7251
7252 snprintf (buff, sizeof buff, _("<other>: %x")("<other>: %x"), other);
7253 return buff;
7254}
7255
7256static const char *
7257get_symbol_index_type (unsigned int type)
7258{
7259 static char buff[32];
7260
7261 switch (type)
7262 {
7263 case SHN_UNDEF0: return "UND";
7264 case SHN_ABS0xFFF1: return "ABS";
7265 case SHN_COMMON0xFFF2: return "COM";
7266 default:
7267 if (type == SHN_IA_64_ANSI_COMMON0xFF00
7268 && elf_header.e_machine == EM_IA_6450
7269 && elf_header.e_ident[EI_OSABI7] == ELFOSABI_HPUX1)
7270 return "ANSI_COM";
7271 else if (elf_header.e_machine == EM_X86_6462
7272 && type == SHN_X86_64_LCOMMON0xff02)
7273 return "LARGE_COM";
7274 else if (type >= SHN_LOPROC0xFF00 && type <= SHN_HIPROC0xFF1F)
7275 sprintf (buff, "PRC[0x%04x]", type);
7276 else if (type >= SHN_LOOS0xFF20 && type <= SHN_HIOS0xFF3F)
7277 sprintf (buff, "OS [0x%04x]", type);
7278 else if (type >= SHN_LORESERVE0xFF00 && type <= SHN_HIRESERVE0xFFFF)
7279 sprintf (buff, "RSV[0x%04x]", type);
7280 else
7281 sprintf (buff, "%3d", type);
7282 break;
7283 }
7284
7285 return buff;
7286}
7287
7288static bfd_vma *
7289get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
7290{
7291 unsigned char *e_data;
7292 bfd_vma *i_data;
7293
7294 e_data = cmalloc (number, ent_size);
7295
7296 if (e_data == NULL((void*)0))
7297 {
7298 error (_("Out of memory\n")("Out of memory\n"));
7299 return NULL((void*)0);
7300 }
7301
7302 if (fread (e_data, ent_size, number, file) != number)
7303 {
7304 error (_("Unable to read in dynamic data\n")("Unable to read in dynamic data\n"));
7305 return NULL((void*)0);
7306 }
7307
7308 i_data = cmalloc (number, sizeof (*i_data));
7309
7310 if (i_data == NULL((void*)0))
7311 {
7312 error (_("Out of memory\n")("Out of memory\n"));
7313 free (e_data);
7314 return NULL((void*)0);
7315 }
7316
7317 while (number--)
7318 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
7319
7320 free (e_data);
7321
7322 return i_data;
7323}
7324
7325/* Dump the symbol table. */
7326static int
7327process_symbol_table (FILE *file)
7328{
7329 Elf_Internal_Shdr *section;
7330 bfd_vma nbuckets = 0;
7331 bfd_vma nchains = 0;
7332 bfd_vma *buckets = NULL((void*)0);
7333 bfd_vma *chains = NULL((void*)0);
7334 bfd_vma ngnubuckets = 0;
7335 bfd_vma *gnubuckets = NULL((void*)0);
7336 bfd_vma *gnuchains = NULL((void*)0);
7337
7338 if (! do_syms && !do_histogram)
7339 return 1;
7340
7341 if (dynamic_info[DT_HASH4] && ((do_using_dynamic && dynamic_strings != NULL((void*)0))
7342 || do_histogram))
7343 {
7344 unsigned char nb[8];
7345 unsigned char nc[8];
7346 int hash_ent_size = 4;
7347
7348 if ((elf_header.e_machine == EM_ALPHA0x9026
7349 || elf_header.e_machine == EM_S39022
7350 || elf_header.e_machine == EM_S390_OLD0xa390)
7351 && elf_header.e_ident[EI_CLASS4] == ELFCLASS642)
7352 hash_ent_size = 8;
7353
7354 if (fseek (file,
7355 (archive_file_offset
7356 + offset_from_vma (file, dynamic_info[DT_HASH4],
7357 sizeof nb + sizeof nc)),
7358 SEEK_SET0))
7359 {
7360 error (_("Unable to seek to start of dynamic information")("Unable to seek to start of dynamic information"));
7361 return 0;
7362 }
7363
7364 if (fread (nb, hash_ent_size, 1, file) != 1)
7365 {
7366 error (_("Failed to read in number of buckets\n")("Failed to read in number of buckets\n"));
7367 return 0;
7368 }
7369
7370 if (fread (nc, hash_ent_size, 1, file) != 1)
7371 {
7372 error (_("Failed to read in number of chains\n")("Failed to read in number of chains\n"));
7373 return 0;
7374 }
7375
7376 nbuckets = byte_get (nb, hash_ent_size);
7377 nchains = byte_get (nc, hash_ent_size);
7378
7379 buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
7380 chains = get_dynamic_data (file, nchains, hash_ent_size);
7381
7382 if (buckets == NULL((void*)0) || chains == NULL((void*)0))
7383 return 0;
7384 }
7385
7386 if (do_syms
7387 && dynamic_info[DT_HASH4] && do_using_dynamic && dynamic_strings != NULL((void*)0))
7388 {
7389 unsigned long hn;
7390 bfd_vma si;
7391
7392 printf (_("\nSymbol table for image:\n")("\nSymbol table for image:\n"));
7393 if (is_32bit_elf)
7394 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")(" Num Buc: Value Size Type Bind Vis Ndx Name\n"
)
);
7395 else
7396 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")(" Num Buc: Value Size Type Bind Vis Ndx Name\n"
)
);
7397
7398 for (hn = 0; hn < nbuckets; hn++)
7399 {
7400 if (! buckets[hn])
7401 continue;
7402
7403 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
7404 {
7405 Elf_Internal_Sym *psym;
7406 int n;
7407
7408 psym = dynamic_symbols + si;
7409
7410 n = print_vma (si, DEC_5);
7411 if (n < 5)
7412 fputs (&" "[n], stdout(&__sF[1]));
7413 printf (" %3lu: ", hn);
7414 print_vma (psym->st_value, LONG_HEX);
7415 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
7416 print_vma (psym->st_size, DEC_5);
7417
7418 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)((psym->st_info) & 0xF)));
7419 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)(((unsigned int)(psym->st_info)) >> 4)));
7420 printf (" %7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)((psym->st_other) & 0x3)));
7421 /* Check to see if any other bits in the st_other field are set.
7422 Note - displaying this information disrupts the layout of the
7423 table being generated, but for the moment this case is very rare. */
7424 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)((psym->st_other) & 0x3))
7425 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)((psym->st_other) & 0x3)));
7426 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
7427 if (VALID_DYNAMIC_NAME (psym->st_name)((dynamic_strings != ((void*)0)) && (psym->st_name
< dynamic_strings_length))
)
7428 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name)(dynamic_strings + psym->st_name));
7429 else
7430 printf (" <corrupt: %14ld>", psym->st_name);
7431 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
7432 }
7433 }
7434 }
7435 else if (do_syms && !do_using_dynamic)
7436 {
7437 unsigned int i;
7438
7439 for (i = 0, section = section_headers;
7440 i < elf_header.e_shnum;
7441 i++, section++)
7442 {
7443 unsigned int si;
7444 char *strtab = NULL((void*)0);
7445 unsigned long int strtab_size = 0;
7446 Elf_Internal_Sym *symtab;
7447 Elf_Internal_Sym *psym;
7448
7449
7450 if ( section->sh_type != SHT_SYMTAB2
7451 && section->sh_type != SHT_DYNSYM11)
7452 continue;
7453
7454 printf (_("\nSymbol table '%s' contains %lu entries:\n")("\nSymbol table '%s' contains %lu entries:\n"),
7455 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
,
7456 (unsigned long) (section->sh_size / section->sh_entsize));
7457 if (is_32bit_elf)
7458 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")(" Num: Value Size Type Bind Vis Ndx Name\n"));
7459 else
7460 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")(" Num: Value Size Type Bind Vis Ndx Name\n"
)
);
7461
7462 symtab = GET_ELF_SYMBOLS (file, section)(is_32bit_elf ? get_32bit_elf_symbols (file, section) : get_64bit_elf_symbols
(file, section))
;
7463 if (symtab == NULL((void*)0))
7464 continue;
7465
7466 if (section->sh_link == elf_header.e_shstrndx)
7467 {
7468 strtab = string_table;
7469 strtab_size = string_table_length;
7470 }
7471 else if (SECTION_HEADER_INDEX (section->sh_link)((section->sh_link) < 0xFF00 ? (section->sh_link) : (
(section->sh_link) <= 0xFFFF ? 0 : (section->sh_link
) - (0xFFFF + 1 - 0xFF00)))
< elf_header.e_shnum)
7472 {
7473 Elf_Internal_Shdr *string_sec;
7474
7475 string_sec = SECTION_HEADER (section->sh_link)(section_headers + ((section->sh_link) < 0xFF00 ? (section
->sh_link) : ((section->sh_link) <= 0xFFFF ? 0 : (section
->sh_link) - (0xFFFF + 1 - 0xFF00))))
;
7476
7477 strtab = get_data (NULL((void*)0), file, string_sec->sh_offset,
7478 1, string_sec->sh_size, _("string table")("string table"));
7479 strtab_size = strtab != NULL((void*)0) ? string_sec->sh_size : 0;
7480 }
7481
7482 for (si = 0, psym = symtab;
7483 si < section->sh_size / section->sh_entsize;
7484 si++, psym++)
7485 {
7486 printf ("%6d: ", si);
7487 print_vma (psym->st_value, LONG_HEX);
7488 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
7489 print_vma (psym->st_size, DEC_5);
7490 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)((psym->st_info) & 0xF)));
7491 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)(((unsigned int)(psym->st_info)) >> 4)));
7492 printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)((psym->st_other) & 0x3)));
7493 /* Check to see if any other bits in the st_other field are set.
7494 Note - displaying this information disrupts the layout of the
7495 table being generated, but for the moment this case is very rare. */
7496 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)((psym->st_other) & 0x3))
7497 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)((psym->st_other) & 0x3)));
7498 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
7499 print_symbol (25, psym->st_name < strtab_size
7500 ? strtab + psym->st_name : "<corrupt>");
7501
7502 if (section->sh_type == SHT_DYNSYM11 &&
7503 version_info[DT_VERSIONTAGIDX (DT_VERSYM)(0x6fffffff - (0x6ffffff0))] != 0)
7504 {
7505 unsigned char data[2];
7506 unsigned short vers_data;
7507 unsigned long offset;
7508 int is_nobits;
7509 int check_def;
7510
7511 offset = offset_from_vma
7512 (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)(0x6fffffff - (0x6ffffff0))],
7513 sizeof data + si * sizeof (vers_data));
7514
7515 get_data (&data, file, offset + si * sizeof (vers_data),
7516 sizeof (data), 1, _("version data")("version data"));
7517
7518 vers_data = byte_get (data, 2);
7519
7520 is_nobits = (SECTION_HEADER_INDEX (psym->st_shndx)((psym->st_shndx) < 0xFF00 ? (psym->st_shndx) : ((psym
->st_shndx) <= 0xFFFF ? 0 : (psym->st_shndx) - (0xFFFF
+ 1 - 0xFF00)))
7521 < elf_header.e_shnum
7522 && SECTION_HEADER (psym->st_shndx)(section_headers + ((psym->st_shndx) < 0xFF00 ? (psym->
st_shndx) : ((psym->st_shndx) <= 0xFFFF ? 0 : (psym->
st_shndx) - (0xFFFF + 1 - 0xFF00))))
->sh_type
7523 == SHT_NOBITS8);
7524
7525 check_def = (psym->st_shndx != SHN_UNDEF0);
7526
7527 if ((vers_data & 0x8000) || vers_data > 1)
7528 {
7529 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)(0x6fffffff - (0x6ffffffe))]
7530 && (is_nobits || ! check_def))
7531 {
7532 Elf_External_Verneed evn;
7533 Elf_Internal_Verneed ivn;
7534 Elf_Internal_Vernaux ivna;
7535
7536 /* We must test both. */
7537 offset = offset_from_vma
7538 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)(0x6fffffff - (0x6ffffffe))],
7539 sizeof evn);
7540
7541 do
7542 {
7543 unsigned long vna_off;
7544
7545 get_data (&evn, file, offset, sizeof (evn), 1,
7546 _("version need")("version need"));
7547
7548 ivn.vn_aux = BYTE_GET (evn.vn_aux)byte_get (evn.vn_aux, sizeof (evn.vn_aux));
7549 ivn.vn_next = BYTE_GET (evn.vn_next)byte_get (evn.vn_next, sizeof (evn.vn_next));
7550
7551 vna_off = offset + ivn.vn_aux;
7552
7553 do
7554 {
7555 Elf_External_Vernaux evna;
7556
7557 get_data (&evna, file, vna_off,
7558 sizeof (evna), 1,
7559 _("version need aux (3)")("version need aux (3)"));
7560
7561 ivna.vna_other = BYTE_GET (evna.vna_other)byte_get (evna.vna_other, sizeof (evna.vna_other));
7562 ivna.vna_next = BYTE_GET (evna.vna_next)byte_get (evna.vna_next, sizeof (evna.vna_next));
7563 ivna.vna_name = BYTE_GET (evna.vna_name)byte_get (evna.vna_name, sizeof (evna.vna_name));
7564
7565 vna_off += ivna.vna_next;
7566 }
7567 while (ivna.vna_other != vers_data
7568 && ivna.vna_next != 0);
7569
7570 if (ivna.vna_other == vers_data)
7571 break;
7572
7573 offset += ivn.vn_next;
7574 }
7575 while (ivn.vn_next != 0);
7576
7577 if (ivna.vna_other == vers_data)
7578 {
7579 printf ("@%s (%d)",
7580 ivna.vna_name < strtab_size
7581 ? strtab + ivna.vna_name : "<corrupt>",
7582 ivna.vna_other);
7583 check_def = 0;
7584 }
7585 else if (! is_nobits)
7586 error (_("bad dynamic symbol")("bad dynamic symbol"));
7587 else
7588 check_def = 1;
7589 }
7590
7591 if (check_def)
7592 {
7593 if (vers_data != 0x8001
7594 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)(0x6fffffff - (0x6ffffffc))])
7595 {
7596 Elf_Internal_Verdef ivd;
7597 Elf_Internal_Verdaux ivda;
7598 Elf_External_Verdaux evda;
7599 unsigned long offset;
7600
7601 offset = offset_from_vma
7602 (file,
7603 version_info[DT_VERSIONTAGIDX (DT_VERDEF)(0x6fffffff - (0x6ffffffc))],
7604 sizeof (Elf_External_Verdef));
7605
7606 do
7607 {
7608 Elf_External_Verdef evd;
7609
7610 get_data (&evd, file, offset, sizeof (evd),
7611 1, _("version def")("version def"));
7612
7613 ivd.vd_ndx = BYTE_GET (evd.vd_ndx)byte_get (evd.vd_ndx, sizeof (evd.vd_ndx));
7614 ivd.vd_aux = BYTE_GET (evd.vd_aux)byte_get (evd.vd_aux, sizeof (evd.vd_aux));
7615 ivd.vd_next = BYTE_GET (evd.vd_next)byte_get (evd.vd_next, sizeof (evd.vd_next));
7616
7617 offset += ivd.vd_next;
7618 }
7619 while (ivd.vd_ndx != (vers_data & 0x7fff)
7620 && ivd.vd_next != 0);
7621
7622 offset -= ivd.vd_next;
7623 offset += ivd.vd_aux;
7624
7625 get_data (&evda, file, offset, sizeof (evda),
7626 1, _("version def aux")("version def aux"));
7627
7628 ivda.vda_name = BYTE_GET (evda.vda_name)byte_get (evda.vda_name, sizeof (evda.vda_name));
7629
7630 if (psym->st_name != ivda.vda_name)
7631 printf ((vers_data & 0x8000)
7632 ? "@%s" : "@@%s",
7633 ivda.vda_name < strtab_size
7634 ? strtab + ivda.vda_name : "<corrupt>");
7635 }
7636 }
7637 }
7638 }
7639
7640 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
7641 }
7642
7643 free (symtab);
7644 if (strtab != string_table)
7645 free (strtab);
7646 }
7647 }
7648 else if (do_syms)
7649 printf
7650 (_("\nDynamic symbol information is not available for displaying symbols.\n")("\nDynamic symbol information is not available for displaying symbols.\n"
)
);
7651
7652 if (do_histogram && buckets != NULL((void*)0))
7653 {
7654 unsigned long *lengths;
7655 unsigned long *counts;
7656 unsigned long hn;
7657 bfd_vma si;
7658 unsigned long maxlength = 0;
7659 unsigned long nzero_counts = 0;
7660 unsigned long nsyms = 0;
7661
7662 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n")("\nHistogram for bucket list length (total of %lu buckets):\n"
)
,
7663 (unsigned long) nbuckets);
7664 printf (_(" Length Number %% of total Coverage\n")(" Length Number %% of total Coverage\n"));
7665
7666 lengths = calloc (nbuckets, sizeof (*lengths));
7667 if (lengths == NULL((void*)0))
7668 {
7669 error (_("Out of memory")("Out of memory"));
7670 return 0;
7671 }
7672 for (hn = 0; hn < nbuckets; ++hn)
7673 {
7674 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
7675 {
7676 ++nsyms;
7677 if (maxlength < ++lengths[hn])
7678 ++maxlength;
7679 }
7680 }
7681
7682 counts = calloc (maxlength + 1, sizeof (*counts));
7683 if (counts == NULL((void*)0))
7684 {
7685 error (_("Out of memory")("Out of memory"));
7686 return 0;
7687 }
7688
7689 for (hn = 0; hn < nbuckets; ++hn)
7690 ++counts[lengths[hn]];
7691
7692 if (nbuckets > 0)
7693 {
7694 unsigned long i;
7695 printf (" 0 %-10lu (%5.1f%%)\n",
7696 counts[0], (counts[0] * 100.0) / nbuckets);
7697 for (i = 1; i <= maxlength; ++i)
7698 {
7699 nzero_counts += counts[i] * i;
7700 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7701 i, counts[i], (counts[i] * 100.0) / nbuckets,
7702 (nzero_counts * 100.0) / nsyms);
7703 }
7704 }
7705
7706 free (counts);
7707 free (lengths);
7708 }
7709
7710 if (buckets != NULL((void*)0))
7711 {
7712 free (buckets);
7713 free (chains);
7714 }
7715
7716 if (do_histogram && dynamic_info_DT_GNU_HASH)
7717 {
7718 unsigned char nb[16];
7719 bfd_vma i, maxchain = 0xffffffff, symidx, bitmaskwords;
7720 unsigned long *lengths;
7721 unsigned long *counts;
7722 unsigned long hn;
7723 unsigned long maxlength = 0;
7724 unsigned long nzero_counts = 0;
7725 unsigned long nsyms = 0;
7726 bfd_vma buckets_vma;
7727
7728 if (fseek (file,
7729 (archive_file_offset
7730 + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
7731 sizeof nb)),
7732 SEEK_SET0))
7733 {
7734 error (_("Unable to seek to start of dynamic information")("Unable to seek to start of dynamic information"));
7735 return 0;
7736 }
7737
7738 if (fread (nb, 16, 1, file) != 1)
7739 {
7740 error (_("Failed to read in number of buckets\n")("Failed to read in number of buckets\n"));
7741 return 0;
7742 }
7743
7744 ngnubuckets = byte_get (nb, 4);
7745 symidx = byte_get (nb + 4, 4);
7746 bitmaskwords = byte_get (nb + 8, 4);
7747 buckets_vma = dynamic_info_DT_GNU_HASH + 16;
7748 if (is_32bit_elf)
7749 buckets_vma += bitmaskwords * 4;
7750 else
7751 buckets_vma += bitmaskwords * 8;
7752
7753 if (fseek (file,
7754 (archive_file_offset
7755 + offset_from_vma (file, buckets_vma, 4)),
7756 SEEK_SET0))
7757 {
7758 error (_("Unable to seek to start of dynamic information")("Unable to seek to start of dynamic information"));
7759 return 0;
7760 }
7761
7762 gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
7763
7764 if (gnubuckets == NULL((void*)0))
7765 return 0;
7766
7767 for (i = 0; i < ngnubuckets; i++)
7768 if (gnubuckets[i] != 0)
7769 {
7770 if (gnubuckets[i] < symidx)
7771 return 0;
7772
7773 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
7774 maxchain = gnubuckets[i];
7775 }
7776
7777 if (maxchain == 0xffffffff)
7778 return 0;
7779
7780 maxchain -= symidx;
7781
7782 if (fseek (file,
7783 (archive_file_offset
7784 + offset_from_vma (file, buckets_vma
7785 + 4 * (ngnubuckets + maxchain), 4)),
7786 SEEK_SET0))
7787 {
7788 error (_("Unable to seek to start of dynamic information")("Unable to seek to start of dynamic information"));
7789 return 0;
7790 }
7791
7792 do
7793 {
7794 if (fread (nb, 4, 1, file) != 1)
7795 {
7796 error (_("Failed to determine last chain length\n")("Failed to determine last chain length\n"));
7797 return 0;
7798 }
7799
7800 if (maxchain + 1 == 0)
7801 return 0;
7802
7803 ++maxchain;
7804 }
7805 while ((byte_get (nb, 4) & 1) == 0);
7806
7807 if (fseek (file,
7808 (archive_file_offset
7809 + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
7810 SEEK_SET0))
7811 {
7812 error (_("Unable to seek to start of dynamic information")("Unable to seek to start of dynamic information"));
7813 return 0;
7814 }
7815
7816 gnuchains = get_dynamic_data (file, maxchain, 4);
7817
7818 if (gnuchains == NULL((void*)0))
7819 return 0;
7820
7821 lengths = calloc (ngnubuckets, sizeof (*lengths));
7822 if (lengths == NULL((void*)0))
7823 {
7824 error (_("Out of memory")("Out of memory"));
7825 return 0;
7826 }
7827
7828 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n")("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"
)
,
7829 (unsigned long) ngnubuckets);
7830 printf (_(" Length Number %% of total Coverage\n")(" Length Number %% of total Coverage\n"));
7831
7832 for (hn = 0; hn < ngnubuckets; ++hn)
7833 if (gnubuckets[hn] != 0)
7834 {
7835 bfd_vma off, length = 1;
7836
7837 for (off = gnubuckets[hn] - symidx;
7838 (gnuchains[off] & 1) == 0; ++off)
7839 ++length;
7840 lengths[hn] = length;
7841 if (length > maxlength)
7842 maxlength = length;
7843 nsyms += length;
7844 }
7845
7846 counts = calloc (maxlength + 1, sizeof (*counts));
7847 if (counts == NULL((void*)0))
7848 {
7849 error (_("Out of memory")("Out of memory"));
7850 return 0;
7851 }
7852
7853 for (hn = 0; hn < ngnubuckets; ++hn)
7854 ++counts[lengths[hn]];
7855
7856 if (ngnubuckets > 0)
7857 {
7858 unsigned long j;
7859 printf (" 0 %-10lu (%5.1f%%)\n",
7860 counts[0], (counts[0] * 100.0) / ngnubuckets);
7861 for (j = 1; j <= maxlength; ++j)
7862 {
7863 nzero_counts += counts[j] * j;
7864 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7865 j, counts[j], (counts[j] * 100.0) / ngnubuckets,
7866 (nzero_counts * 100.0) / nsyms);
7867 }
7868 }
7869
7870 free (counts);
7871 free (lengths);
7872 free (gnubuckets);
7873 free (gnuchains);
7874 }
7875
7876 return 1;
7877}
7878
7879static int
7880process_syminfo (FILE *file ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
7881{
7882 unsigned int i;
7883
7884 if (dynamic_syminfo == NULL((void*)0)
7885 || !do_dynamic)
7886 /* No syminfo, this is ok. */
7887 return 1;
7888
7889 /* There better should be a dynamic symbol section. */
7890 if (dynamic_symbols == NULL((void*)0) || dynamic_strings == NULL((void*)0))
7891 return 0;
7892
7893 if (dynamic_addr)
7894 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n")("\nDynamic info segment at offset 0x%lx contains %d entries:\n"
)
,
7895 dynamic_syminfo_offset, dynamic_syminfo_nent);
7896
7897 printf (_(" Num: Name BoundTo Flags\n")(" Num: Name BoundTo Flags\n"));
7898 for (i = 0; i < dynamic_syminfo_nent; ++i)
7899 {
7900 unsigned short int flags = dynamic_syminfo[i].si_flags;
7901
7902 printf ("%4d: ", i);
7903 if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name)((dynamic_strings != ((void*)0)) && (dynamic_symbols[
i].st_name < dynamic_strings_length))
)
7904 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name)(dynamic_strings + dynamic_symbols[i].st_name));
7905 else
7906 printf ("<corrupt: %19ld>", dynamic_symbols[i].st_name);
7907 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
7908
7909 switch (dynamic_syminfo[i].si_boundto)
7910 {
7911 case SYMINFO_BT_SELF0xffff:
7912 fputs ("SELF ", stdout(&__sF[1]));
7913 break;
7914 case SYMINFO_BT_PARENT0xfffe:
7915 fputs ("PARENT ", stdout(&__sF[1]));
7916 break;
7917 default:
7918 if (dynamic_syminfo[i].si_boundto > 0
7919 && dynamic_syminfo[i].si_boundto < dynamic_nent
7920 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val)((dynamic_strings != ((void*)0)) && (dynamic_section[
dynamic_syminfo[i].si_boundto].d_un.d_val < dynamic_strings_length
))
)
7921 {
7922 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val)(dynamic_strings + dynamic_section[dynamic_syminfo[i].si_boundto
].d_un.d_val)
);
7923 putchar (' ' )(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
7924 }
7925 else
7926 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
7927 break;
7928 }
7929
7930 if (flags & SYMINFO_FLG_DIRECT0x0001)
7931 printf (" DIRECT");
7932 if (flags & SYMINFO_FLG_PASSTHRU0x0002)
7933 printf (" PASSTHRU");
7934 if (flags & SYMINFO_FLG_COPY0x0004)
7935 printf (" COPY");
7936 if (flags & SYMINFO_FLG_LAZYLOAD0x0008)
7937 printf (" LAZYLOAD");
7938
7939 puts ("");
7940 }
7941
7942 return 1;
7943}
7944
7945#ifdef SUPPORT_DISASSEMBLY
7946static int
7947disassemble_section (Elf_Internal_Shdr *section, FILE *file)
7948{
7949 printf (_("\nAssembly dump of section %s\n")("\nAssembly dump of section %s\n"),
7950 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
7951
7952 /* XXX -- to be done --- XXX */
7953
7954 return 1;
7955}
7956#endif
7957
7958static int
7959dump_section (Elf_Internal_Shdr *section, FILE *file)
7960{
7961 bfd_size_type bytes;
7962 bfd_vma addr;
7963 unsigned char *data;
7964 unsigned char *start;
7965
7966 bytes = section->sh_size;
7967
7968 if (bytes == 0 || section->sh_type == SHT_NOBITS8)
7969 {
7970 printf (_("\nSection '%s' has no data to dump.\n")("\nSection '%s' has no data to dump.\n"),
7971 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
7972 return 0;
7973 }
7974 else
7975 printf (_("\nHex dump of section '%s':\n")("\nHex dump of section '%s':\n"), SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
7976
7977 addr = section->sh_addr;
7978
7979 start = get_data (NULL((void*)0), file, section->sh_offset, 1, bytes,
7980 _("section data")("section data"));
7981 if (!start)
7982 return 0;
7983
7984 data = start;
7985
7986 while (bytes)
7987 {
7988 int j;
7989 int k;
7990 int lbytes;
7991
7992 lbytes = (bytes > 16 ? 16 : bytes);
7993
7994 printf (" 0x%8.8lx ", (unsigned long) addr);
7995
7996 switch (elf_header.e_ident[EI_DATA5])
7997 {
7998 default:
7999 case ELFDATA2LSB1:
8000 for (j = 15; j >= 0; j --)
8001 {
8002 if (j < lbytes)
8003 printf ("%2.2x", data[j]);
8004 else
8005 printf (" ");
8006
8007 if (!(j & 0x3))
8008 printf (" ");
8009 }
8010 break;
8011
8012 case ELFDATA2MSB2:
8013 for (j = 0; j < 16; j++)
8014 {
8015 if (j < lbytes)
8016 printf ("%2.2x", data[j]);
8017 else
8018 printf (" ");
8019
8020 if ((j & 3) == 3)
8021 printf (" ");
8022 }
8023 break;
8024 }
8025
8026 for (j = 0; j < lbytes; j++)
8027 {
8028 k = data[j];
8029 if (k >= ' ' && k < 0x7f)
8030 printf ("%c", k);
8031 else
8032 printf (".");
8033 }
8034
8035 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
8036
8037 data += lbytes;
8038 addr += lbytes;
8039 bytes -= lbytes;
8040 }
8041
8042 free (start);
8043
8044 return 1;
8045}
8046
8047/* Apply addends of RELA relocations. */
8048
8049static int
8050debug_apply_rela_addends (void *file,
8051 Elf_Internal_Shdr *section,
8052 unsigned char *start)
8053{
8054 Elf_Internal_Shdr *relsec;
8055 unsigned char *end = start + section->sh_size;
8056 /* FIXME: The relocation field size is relocation type dependent. */
8057 unsigned int reloc_size = 4;
8058
8059 if (!is_relocatable)
8060 return 1;
8061
8062 if (section->sh_size < reloc_size)
8063 return 1;
8064
8065 for (relsec = section_headers;
8066 relsec < section_headers + elf_header.e_shnum;
8067 ++relsec)
8068 {
8069 unsigned long nrelas;
8070 Elf_Internal_Rela *rela, *rp;
8071 Elf_Internal_Shdr *symsec;
8072 Elf_Internal_Sym *symtab;
8073 Elf_Internal_Sym *sym;
8074
8075 if (relsec->sh_type != SHT_RELA4
8076 || SECTION_HEADER_INDEX (relsec->sh_info)((relsec->sh_info) < 0xFF00 ? (relsec->sh_info) : ((
relsec->sh_info) <= 0xFFFF ? 0 : (relsec->sh_info) -
(0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum
8077 || SECTION_HEADER (relsec->sh_info)(section_headers + ((relsec->sh_info) < 0xFF00 ? (relsec
->sh_info) : ((relsec->sh_info) <= 0xFFFF ? 0 : (relsec
->sh_info) - (0xFFFF + 1 - 0xFF00))))
!= section
8078 || relsec->sh_size == 0
8079 || SECTION_HEADER_INDEX (relsec->sh_link)((relsec->sh_link) < 0xFF00 ? (relsec->sh_link) : ((
relsec->sh_link) <= 0xFFFF ? 0 : (relsec->sh_link) -
(0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum)
8080 continue;
8081
8082 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
8083 &rela, &nrelas))
8084 return 0;
8085
8086 symsec = SECTION_HEADER (relsec->sh_link)(section_headers + ((relsec->sh_link) < 0xFF00 ? (relsec
->sh_link) : ((relsec->sh_link) <= 0xFFFF ? 0 : (relsec
->sh_link) - (0xFFFF + 1 - 0xFF00))))
;
8087 symtab = GET_ELF_SYMBOLS (file, symsec)(is_32bit_elf ? get_32bit_elf_symbols (file, symsec) : get_64bit_elf_symbols
(file, symsec))
;
8088
8089 for (rp = rela; rp < rela + nrelas; ++rp)
8090 {
8091 unsigned char *loc;
8092
8093 loc = start + rp->r_offset;
8094 if ((loc + reloc_size) > end)
8095 {
8096 warn (_("skipping invalid relocation offset 0x%lx in section %s\n")("skipping invalid relocation offset 0x%lx in section %s\n"),
8097 (unsigned long) rp->r_offset,
8098 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
8099 continue;
8100 }
8101
8102 if (is_32bit_elf)
8103 {
8104 sym = symtab + ELF32_R_SYM (rp->r_info)((rp->r_info) >> 8);
8105
8106 if (ELF32_R_SYM (rp->r_info)((rp->r_info) >> 8) != 0
8107 && ELF32_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != STT_SECTION3
8108 /* Relocations against object symbols can happen,
8109 eg when referencing a global array. For an
8110 example of this see the _clz.o binary in libgcc.a. */
8111 && ELF32_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != STT_OBJECT1)
8112 {
8113 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n")("skipping unexpected symbol type %s in relocation in section .rela%s\n"
)
,
8114 get_symbol_type (ELF32_ST_TYPE (sym->st_info)((sym->st_info) & 0xF)),
8115 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
8116 continue;
8117 }
8118 }
8119 else
8120 {
8121 /* In MIPS little-endian objects, r_info isn't really a
8122 64-bit little-endian value: it has a 32-bit little-endian
8123 symbol index followed by four individual byte fields.
8124 Reorder INFO accordingly. */
8125 if (elf_header.e_machine == EM_MIPS8
8126 && elf_header.e_ident[EI_DATA5] != ELFDATA2MSB2)
8127 rp->r_info = (((rp->r_info & 0xffffffff) << 32)
8128 | ((rp->r_info >> 56) & 0xff)
8129 | ((rp->r_info >> 40) & 0xff00)
8130 | ((rp->r_info >> 24) & 0xff0000)
8131 | ((rp->r_info >> 8) & 0xff000000));
8132
8133 sym = symtab + ELF64_R_SYM (rp->r_info)((rp->r_info) >> 32);
8134
8135 if (ELF64_R_SYM (rp->r_info)((rp->r_info) >> 32) != 0
8136 && ELF64_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != STT_SECTION3
8137 && ELF64_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != STT_OBJECT1)
8138 {
8139 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n")("skipping unexpected symbol type %s in relocation in section .rela.%s\n"
)
,
8140 get_symbol_type (ELF64_ST_TYPE (sym->st_info)((sym->st_info) & 0xF)),
8141 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
);
8142 continue;
8143 }
8144 }
8145
8146 byte_put (loc, rp->r_addend, reloc_size);
8147 }
8148
8149 free (symtab);
8150 free (rela);
8151 break;
8152 }
8153 return 1;
8154}
8155
8156int
8157load_debug_section (enum dwarf_section_display_enum debug, void *file)
8158{
8159 struct dwarf_section *section = &debug_displays [debug].section;
8160 Elf_Internal_Shdr *sec;
8161 char buf [64];
8162
8163 /* If it is already loaded, do nothing. */
8164 if (section->start != NULL((void*)0))
8165 return 1;
8166
8167 /* Locate the debug section. */
8168 sec = find_section (section->name);
8169 if (sec == NULL((void*)0))
8170 return 0;
8171
8172 snprintf (buf, sizeof (buf), _("%s section data")("%s section data"), section->name);
8173 section->address = sec->sh_addr;
8174 section->size = sec->sh_size;
8175 section->start = get_data (NULL((void*)0), file, sec->sh_offset, 1,
8176 sec->sh_size, buf);
8177
8178 if (debug_displays [debug].relocate)
8179 debug_apply_rela_addends (file, sec, section->start);
8180
8181 return section->start != NULL((void*)0);
8182}
8183
8184void
8185free_debug_section (enum dwarf_section_display_enum debug)
8186{
8187 struct dwarf_section *section = &debug_displays [debug].section;
8188
8189 if (section->start == NULL((void*)0))
8190 return;
8191
8192 free ((char *) section->start);
8193 section->start = NULL((void*)0);
8194 section->address = 0;
8195 section->size = 0;
8196}
8197
8198static int
8199display_debug_section (Elf_Internal_Shdr *section, FILE *file)
8200{
8201 char *name = SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
;
8202 bfd_size_type length;
8203 int result = 1;
8204 enum dwarf_section_display_enum i;
8205
8206 length = section->sh_size;
8207 if (length == 0)
8208 {
8209 printf (_("\nSection '%s' has no debugging data.\n")("\nSection '%s' has no debugging data.\n"), name);
8210 return 0;
8211 }
8212
8213 if (strneq (name, ".gnu.linkonce.wi.", 17)(strncmp ((name), (".gnu.linkonce.wi."), (17)) == 0))
8214 name = ".debug_info";
8215
8216 /* See if we know how to display the contents of this section. */
8217 for (i = 0; i < max; i++)
8218 if (streq (debug_displays[i].section.name, name)(strcmp ((debug_displays[i].section.name), (name)) == 0))
8219 {
8220 struct dwarf_section *sec = &debug_displays [i].section;
8221
8222 if (load_debug_section (i, file))
8223 {
8224 result &= debug_displays[i].display (sec, file);
8225
8226 if (i != info && i != abbrev)
8227 free_debug_section (i);
8228 }
8229
8230 break;
8231 }
8232
8233 if (i == max)
8234 {
8235 printf (_("Unrecognized debug section: %s\n")("Unrecognized debug section: %s\n"), name);
8236 result = 0;
8237 }
8238
8239 return result;
8240}
8241
8242/* Set DUMP_SECTS for all sections where dumps were requested
8243 based on section name. */
8244
8245static void
8246initialise_dumps_byname (void)
8247{
8248 struct dump_list_entry *cur;
8249
8250 for (cur = dump_sects_byname; cur; cur = cur->next)
8251 {
8252 unsigned int i;
8253 int any;
8254
8255 for (i = 0, any = 0; i < elf_header.e_shnum; i++)
8256 if (streq (SECTION_NAME (section_headers + i), cur->name)(strcmp ((((section_headers + i) == ((void*)0) ? "<none>"
: ((section_headers + i)->sh_name >= string_table_length
? "<corrupt>" : string_table + (section_headers + i)->
sh_name))), (cur->name)) == 0)
)
8257 {
8258 request_dump (i, cur->type);
8259 any = 1;
8260 }
8261
8262 if (!any)
8263 warn (_("Section '%s' was not dumped because it does not exist!\n")("Section '%s' was not dumped because it does not exist!\n"),
8264 cur->name);
8265 }
8266}
8267
8268static void
8269process_section_contents (FILE *file)
8270{
8271 Elf_Internal_Shdr *section;
8272 unsigned int i;
8273
8274 if (! do_dump)
8275 return;
8276
8277 initialise_dumps_byname ();
8278
8279 for (i = 0, section = section_headers;
8280 i < elf_header.e_shnum && i < num_dump_sects;
8281 i++, section++)
8282 {
8283#ifdef SUPPORT_DISASSEMBLY
8284 if (dump_sects[i] & DISASS_DUMP(1 << 1))
8285 disassemble_section (section, file);
8286#endif
8287 if (dump_sects[i] & HEX_DUMP(1 << 0))
8288 dump_section (section, file);
8289
8290 if (dump_sects[i] & DEBUG_DUMP(1 << 2))
8291 display_debug_section (section, file);
8292 }
8293
8294 /* Check to see if the user requested a
8295 dump of a section that does not exist. */
8296 while (i++ < num_dump_sects)
8297 if (dump_sects[i])
8298 warn (_("Section %d was not dumped because it does not exist!\n")("Section %d was not dumped because it does not exist!\n"), i);
8299}
8300
8301static void
8302process_mips_fpe_exception (int mask)
8303{
8304 if (mask)
8305 {
8306 int first = 1;
8307 if (mask & OEX_FPU_INEX0x01)
8308 fputs ("INEX", stdout(&__sF[1])), first = 0;
8309 if (mask & OEX_FPU_UFLO0x02)
8310 printf ("%sUFLO", first ? "" : "|"), first = 0;
8311 if (mask & OEX_FPU_OFLO0x04)
8312 printf ("%sOFLO", first ? "" : "|"), first = 0;
8313 if (mask & OEX_FPU_DIV00x08)
8314 printf ("%sDIV0", first ? "" : "|"), first = 0;
8315 if (mask & OEX_FPU_INVAL0x10)
8316 printf ("%sINVAL", first ? "" : "|");
8317 }
8318 else
8319 fputs ("0", stdout(&__sF[1]));
8320}
8321
8322/* ARM EABI attributes section. */
8323typedef struct
8324{
8325 int tag;
8326 const char *name;
8327 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8328 int type;
8329 const char **table;
8330} arm_attr_public_tag;
8331
8332static const char *arm_attr_tag_CPU_arch[] =
8333 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8334 "v6K", "v7"};
8335static const char *arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
8336static const char *arm_attr_tag_THUMB_ISA_use[] =
8337 {"No", "Thumb-1", "Thumb-2"};
8338static const char *arm_attr_tag_VFP_arch[] = {"No", "VFPv1", "VFPv2"};
8339static const char *arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1"};
8340static const char *arm_attr_tag_NEON_arch[] = {"No", "NEONv1"};
8341static const char *arm_attr_tag_ABI_PCS_config[] =
8342 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8343 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8344static const char *arm_attr_tag_ABI_PCS_R9_use[] =
8345 {"V6", "SB", "TLS", "Unused"};
8346static const char *arm_attr_tag_ABI_PCS_RW_data[] =
8347 {"Absolute", "PC-relative", "SB-relative", "None"};
8348static const char *arm_attr_tag_ABI_PCS_RO_DATA[] =
8349 {"Absolute", "PC-relative", "None"};
8350static const char *arm_attr_tag_ABI_PCS_GOT_use[] =
8351 {"None", "direct", "GOT-indirect"};
8352static const char *arm_attr_tag_ABI_PCS_wchar_t[] =
8353 {"None", "??? 1", "2", "??? 3", "4"};
8354static const char *arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
8355static const char *arm_attr_tag_ABI_FP_denormal[] = {"Unused", "Needed"};
8356static const char *arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
8357static const char *arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
8358static const char *arm_attr_tag_ABI_FP_number_model[] =
8359 {"Unused", "Finite", "RTABI", "IEEE 754"};
8360static const char *arm_attr_tag_ABI_align8_needed[] = {"No", "Yes", "4-byte"};
8361static const char *arm_attr_tag_ABI_align8_preserved[] =
8362 {"No", "Yes, except leaf SP", "Yes"};
8363static const char *arm_attr_tag_ABI_enum_size[] =
8364 {"Unused", "small", "int", "forced to int"};
8365static const char *arm_attr_tag_ABI_HardFP_use[] =
8366 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8367static const char *arm_attr_tag_ABI_VFP_args[] =
8368 {"AAPCS", "VFP registers", "custom"};
8369static const char *arm_attr_tag_ABI_WMMX_args[] =
8370 {"AAPCS", "WMMX registers", "custom"};
8371static const char *arm_attr_tag_ABI_optimization_goals[] =
8372 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8373 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8374static const char *arm_attr_tag_ABI_FP_optimization_goals[] =
8375 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8376 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8377
8378#define LOOKUP(id, name) \
8379 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name)(sizeof (arm_attr_tag_##name) / sizeof ((arm_attr_tag_##name)
[0]))
, arm_attr_tag_##name}
8380static arm_attr_public_tag arm_attr_public_tags[] =
8381{
8382 {4, "CPU_raw_name", 1, NULL((void*)0)},
8383 {5, "CPU_name", 1, NULL((void*)0)},
8384 LOOKUP(6, CPU_arch),
8385 {7, "CPU_arch_profile", 0, NULL((void*)0)},
8386 LOOKUP(8, ARM_ISA_use),
8387 LOOKUP(9, THUMB_ISA_use),
8388 LOOKUP(10, VFP_arch),
8389 LOOKUP(11, WMMX_arch),
8390 LOOKUP(12, NEON_arch),
8391 LOOKUP(13, ABI_PCS_config),
8392 LOOKUP(14, ABI_PCS_R9_use),
8393 LOOKUP(15, ABI_PCS_RW_data),
8394 LOOKUP(16, ABI_PCS_RO_DATA),
8395 LOOKUP(17, ABI_PCS_GOT_use),
8396 LOOKUP(18, ABI_PCS_wchar_t),
8397 LOOKUP(19, ABI_FP_rounding),
8398 LOOKUP(20, ABI_FP_denormal),
8399 LOOKUP(21, ABI_FP_exceptions),
8400 LOOKUP(22, ABI_FP_user_exceptions),
8401 LOOKUP(23, ABI_FP_number_model),
8402 LOOKUP(24, ABI_align8_needed),
8403 LOOKUP(25, ABI_align8_preserved),
8404 LOOKUP(26, ABI_enum_size),
8405 LOOKUP(27, ABI_HardFP_use),
8406 LOOKUP(28, ABI_VFP_args),
8407 LOOKUP(29, ABI_WMMX_args),
8408 LOOKUP(30, ABI_optimization_goals),
8409 LOOKUP(31, ABI_FP_optimization_goals),
8410 {32, "compatibility", 0, NULL((void*)0)}
8411};
8412#undef LOOKUP
8413
8414/* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8415 bytes read. */
8416static unsigned int
8417read_uleb128 (unsigned char *p, unsigned int *plen)
8418{
8419 unsigned char c;
8420 unsigned int val;
8421 int shift;
8422 int len;
8423
8424 val = 0;
8425 shift = 0;
8426 len = 0;
8427 do
8428 {
8429 c = *(p++);
8430 len++;
8431 val |= ((unsigned int)c & 0x7f) << shift;
8432 shift += 7;
8433 }
8434 while (c & 0x80);
8435
8436 *plen = len;
8437 return val;
8438}
8439
8440static unsigned char *
8441display_arm_attribute (unsigned char *p)
8442{
8443 int tag;
8444 unsigned int len;
8445 int val;
8446 arm_attr_public_tag *attr;
8447 unsigned i;
8448 int type;
8449
8450 tag = read_uleb128 (p, &len);
8451 p += len;
8452 attr = NULL((void*)0);
8453 for (i = 0; i < ARRAY_SIZE(arm_attr_public_tags)(sizeof (arm_attr_public_tags) / sizeof ((arm_attr_public_tags
)[0]))
; i++)
8454 {
8455 if (arm_attr_public_tags[i].tag == tag)
8456 {
8457 attr = &arm_attr_public_tags[i];
8458 break;
8459 }
8460 }
8461
8462 if (attr)
8463 {
8464 printf (" Tag_%s: ", attr->name);
8465 switch (attr->type)
8466 {
8467 case 0:
8468 switch (tag)
8469 {
8470 case 7: /* Tag_CPU_arch_profile. */
8471 val = read_uleb128 (p, &len);
8472 p += len;
8473 switch (val)
8474 {
8475 case 0: printf ("None\n"); break;
8476 case 'A': printf ("Application\n"); break;
8477 case 'R': printf ("Realtime\n"); break;
8478 case 'M': printf ("Microcontroller\n"); break;
8479 default: printf ("??? (%d)\n", val); break;
8480 }
8481 break;
8482
8483 case 32: /* Tag_compatibility. */
8484 val = read_uleb128 (p, &len);
8485 p += len;
8486 printf ("flag = %d, vendor = %s\n", val, p);
8487 p += strlen((char *)p) + 1;
8488 break;
8489
8490 default:
8491 abort();
8492 }
8493 return p;
8494
8495 case 1:
8496 case 2:
8497 type = attr->type;
8498 break;
8499
8500 default:
8501 assert (attr->type & 0x80)((attr->type & 0x80) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/readelf.c"
, 8501, __func__, "attr->type & 0x80"))
;
8502 val = read_uleb128 (p, &len);
8503 p += len;
8504 type = attr->type & 0x7f;
8505 if (val >= type)
8506 printf ("??? (%d)\n", val);
8507 else
8508 printf ("%s\n", attr->table[val]);
8509 return p;
8510 }
8511 }
8512 else
8513 {
8514 if (tag & 1)
8515 type = 1; /* String. */
8516 else
8517 type = 2; /* uleb128. */
8518 printf (" Tag_unknown_%d: ", tag);
8519 }
8520
8521 if (type == 1)
8522 {
8523 printf ("\"%s\"\n", p);
8524 p += strlen((char *)p) + 1;
8525 }
8526 else
8527 {
8528 val = read_uleb128 (p, &len);
8529 p += len;
8530 printf ("%d (0x%x)\n", val, val);
8531 }
8532
8533 return p;
8534}
8535
8536static int
8537process_arm_specific (FILE *file)
8538{
8539 Elf_Internal_Shdr *sect;
8540 unsigned char *contents;
8541 unsigned char *p;
8542 unsigned char *end;
8543 bfd_vma section_len;
8544 bfd_vma len;
8545 unsigned i;
8546
8547 /* Find the section header so that we get the size. */
8548 for (i = 0, sect = section_headers;
8549 i < elf_header.e_shnum;
8550 i++, sect++)
8551 {
8552 if (sect->sh_type != SHT_ARM_ATTRIBUTES0x70000003)
8553 continue;
8554
8555 contents = get_data (NULL((void*)0), file, sect->sh_offset, 1, sect->sh_size,
8556 _("attributes")("attributes"));
8557
8558 if (!contents)
8559 continue;
8560 p = contents;
8561 if (*p == 'A')
8562 {
8563 len = sect->sh_size - 1;
8564 p++;
8565 while (len > 0)
8566 {
8567 int namelen;
8568 bfd_boolean public_section;
8569
8570 section_len = byte_get (p, 4);
8571 p += 4;
8572 if (section_len > len)
8573 {
8574 printf (_("ERROR: Bad section length (%d > %d)\n")("ERROR: Bad section length (%d > %d)\n"),
8575 (int)section_len, (int)len);
8576 section_len = len;
8577 }
8578 len -= section_len;
8579 printf ("Attribute Section: %s\n", p);
8580 if (strcmp ((char *)p, "aeabi") == 0)
8581 public_section = TRUE1;
8582 else
8583 public_section = FALSE0;
8584 namelen = strlen ((char *)p) + 1;
8585 p += namelen;
8586 section_len -= namelen + 4;
8587 while (section_len > 0)
8588 {
8589 int tag = *(p++);
8590 int val;
8591 bfd_vma size;
8592 size = byte_get (p, 4);
8593 if (size > section_len)
8594 {
8595 printf (_("ERROR: Bad subsection length (%d > %d)\n")("ERROR: Bad subsection length (%d > %d)\n"),
8596 (int)size, (int)section_len);
8597 size = section_len;
8598 }
8599 section_len -= size;
8600 end = p + size - 1;
8601 p += 4;
8602 switch (tag)
8603 {
8604 case 1:
8605 printf ("File Attributes\n");
8606 break;
8607 case 2:
8608 printf ("Section Attributes:");
8609 goto do_numlist;
8610 case 3:
8611 printf ("Symbol Attributes:");
8612 do_numlist:
8613 for (;;)
8614 {
8615 unsigned int i;
8616 val = read_uleb128 (p, &i);
8617 p += i;
8618 if (val == 0)
8619 break;
8620 printf (" %d", val);
8621 }
8622 printf ("\n");
8623 break;
8624 default:
8625 printf ("Unknown tag: %d\n", tag);
8626 public_section = FALSE0;
8627 break;
8628 }
8629 if (public_section)
8630 {
8631 while (p < end)
8632 p = display_arm_attribute(p);
8633 }
8634 else
8635 {
8636 /* ??? Do something sensible, like dump hex. */
8637 printf (" Unknown section contexts\n");
8638 p = end;
8639 }
8640 }
8641 }
8642 }
8643 else
8644 {
8645 printf (_("Unknown format '%c'\n")("Unknown format '%c'\n"), *p);
8646 }
8647
8648 free(contents);
8649 }
8650 return 1;
8651}
8652
8653static int
8654process_mips_specific (FILE *file)
8655{
8656 Elf_Internal_Dyn *entry;
8657 size_t liblist_offset = 0;
8658 size_t liblistno = 0;
8659 size_t conflictsno = 0;
8660 size_t options_offset = 0;
8661 size_t conflicts_offset = 0;
8662
8663 /* We have a lot of special sections. Thanks SGI! */
8664 if (dynamic_section == NULL((void*)0))
8665 /* No information available. */
8666 return 0;
8667
8668 for (entry = dynamic_section; entry->d_tag != DT_NULL0; ++entry)
8669 switch (entry->d_tag)
8670 {
8671 case DT_MIPS_LIBLIST0x70000009:
8672 liblist_offset
8673 = offset_from_vma (file, entry->d_un.d_val,
8674 liblistno * sizeof (Elf32_External_Lib));
8675 break;
8676 case DT_MIPS_LIBLISTNO0x70000010:
8677 liblistno = entry->d_un.d_val;
8678 break;
8679 case DT_MIPS_OPTIONS0x70000029:
8680 options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
8681 break;
8682 case DT_MIPS_CONFLICT0x70000008:
8683 conflicts_offset
8684 = offset_from_vma (file, entry->d_un.d_val,
8685 conflictsno * sizeof (Elf32_External_Conflict));
8686 break;
8687 case DT_MIPS_CONFLICTNO0x7000000b:
8688 conflictsno = entry->d_un.d_val;
8689 break;
8690 default:
8691 break;
8692 }
8693
8694 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8695 {
8696 Elf32_External_Lib *elib;
8697 size_t cnt;
8698
8699 elib = get_data (NULL((void*)0), file, liblist_offset,
8700 liblistno, sizeof (Elf32_External_Lib),
8701 _("liblist")("liblist"));
8702 if (elib)
8703 {
8704 printf ("\nSection '.liblist' contains %lu entries:\n",
8705 (unsigned long) liblistno);
8706 fputs (" Library Time Stamp Checksum Version Flags\n",
8707 stdout(&__sF[1]));
8708
8709 for (cnt = 0; cnt < liblistno; ++cnt)
8710 {
8711 Elf32_Lib liblist;
8712 time_t time;
8713 char timebuf[20];
8714 struct tm *tmp;
8715
8716 liblist.l_name = BYTE_GET (elib[cnt].l_name)byte_get (elib[cnt].l_name, sizeof (elib[cnt].l_name));
8717 time = BYTE_GET (elib[cnt].l_time_stamp)byte_get (elib[cnt].l_time_stamp, sizeof (elib[cnt].l_time_stamp
))
;
8718 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum)byte_get (elib[cnt].l_checksum, sizeof (elib[cnt].l_checksum)
)
;
8719 liblist.l_version = BYTE_GET (elib[cnt].l_version)byte_get (elib[cnt].l_version, sizeof (elib[cnt].l_version));
8720 liblist.l_flags = BYTE_GET (elib[cnt].l_flags)byte_get (elib[cnt].l_flags, sizeof (elib[cnt].l_flags));
8721
8722 tmp = gmtime (&time);
8723 snprintf (timebuf, sizeof (timebuf),
8724 "%04u-%02u-%02uT%02u:%02u:%02u",
8725 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8726 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8727
8728 printf ("%3lu: ", (unsigned long) cnt);
8729 if (VALID_DYNAMIC_NAME (liblist.l_name)((dynamic_strings != ((void*)0)) && (liblist.l_name <
dynamic_strings_length))
)
8730 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name)(dynamic_strings + liblist.l_name));
8731 else
8732 printf ("<corrupt: %9ld>", liblist.l_name);
8733 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
8734 liblist.l_version);
8735
8736 if (liblist.l_flags == 0)
8737 puts (" NONE");
8738 else
8739 {
8740 static const struct
8741 {
8742 const char *name;
8743 int bit;
8744 }
8745 l_flags_vals[] =
8746 {
8747 { " EXACT_MATCH", LL_EXACT_MATCH0x00000001 },
8748 { " IGNORE_INT_VER", LL_IGNORE_INT_VER0x00000002 },
8749 { " REQUIRE_MINOR", LL_REQUIRE_MINOR0x00000004 },
8750 { " EXPORTS", LL_EXPORTS0x00000008 },
8751 { " DELAY_LOAD", LL_DELAY_LOAD0x00000010 },
8752 { " DELTA", LL_DELTA0x00000020 }
8753 };
8754 int flags = liblist.l_flags;
8755 size_t fcnt;
8756
8757 for (fcnt = 0;
8758 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8759 ++fcnt)
8760 if ((flags & l_flags_vals[fcnt].bit) != 0)
8761 {
8762 fputs (l_flags_vals[fcnt].name, stdout(&__sF[1]));
8763 flags ^= l_flags_vals[fcnt].bit;
8764 }
8765 if (flags != 0)
8766 printf (" %#x", (unsigned int) flags);
8767
8768 puts ("");
8769 }
8770 }
8771
8772 free (elib);
8773 }
8774 }
8775
8776 if (options_offset != 0)
8777 {
8778 Elf_External_Options *eopt;
8779 Elf_Internal_Shdr *sect = section_headers;
8780 Elf_Internal_Options *iopt;
8781 Elf_Internal_Options *option;
8782 size_t offset;
8783 int cnt;
8784
8785 /* Find the section header so that we get the size. */
8786 while (sect->sh_type != SHT_MIPS_OPTIONS0x7000000d)
8787 ++sect;
8788
8789 eopt = get_data (NULL((void*)0), file, options_offset, 1, sect->sh_size,
8790 _("options")("options"));
8791 if (eopt)
8792 {
8793 iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (*iopt));
8794 if (iopt == NULL((void*)0))
8795 {
8796 error (_("Out of memory")("Out of memory"));
8797 return 0;
8798 }
8799
8800 offset = cnt = 0;
8801 option = iopt;
8802
8803 while (offset < sect->sh_size)
8804 {
8805 Elf_External_Options *eoption;
8806
8807 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8808
8809 option->kind = BYTE_GET (eoption->kind)byte_get (eoption->kind, sizeof (eoption->kind));
8810 option->size = BYTE_GET (eoption->size)byte_get (eoption->size, sizeof (eoption->size));
8811 option->section = BYTE_GET (eoption->section)byte_get (eoption->section, sizeof (eoption->section));
8812 option->info = BYTE_GET (eoption->info)byte_get (eoption->info, sizeof (eoption->info));
8813
8814 offset += option->size;
8815
8816 ++option;
8817 ++cnt;
8818 }
8819
8820 printf (_("\nSection '%s' contains %d entries:\n")("\nSection '%s' contains %d entries:\n"),
8821 SECTION_NAME (sect)((sect) == ((void*)0) ? "<none>" : ((sect)->sh_name >=
string_table_length ? "<corrupt>" : string_table + (sect
)->sh_name))
, cnt);
8822
8823 option = iopt;
8824
8825 while (cnt-- > 0)
8826 {
8827 size_t len;
8828
8829 switch (option->kind)
8830 {
8831 case ODK_NULL0:
8832 /* This shouldn't happen. */
8833 printf (" NULL %d %lx", option->section, option->info);
8834 break;
8835 case ODK_REGINFO1:
8836 printf (" REGINFO ");
8837 if (elf_header.e_machine == EM_MIPS8)
8838 {
8839 /* 32bit form. */
8840 Elf32_External_RegInfo *ereg;
8841 Elf32_RegInfo reginfo;
8842
8843 ereg = (Elf32_External_RegInfo *) (option + 1);
8844 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask)byte_get (ereg->ri_gprmask, sizeof (ereg->ri_gprmask));
8845 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0])byte_get (ereg->ri_cprmask[0], sizeof (ereg->ri_cprmask
[0]))
;
8846 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1])byte_get (ereg->ri_cprmask[1], sizeof (ereg->ri_cprmask
[1]))
;
8847 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2])byte_get (ereg->ri_cprmask[2], sizeof (ereg->ri_cprmask
[2]))
;
8848 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3])byte_get (ereg->ri_cprmask[3], sizeof (ereg->ri_cprmask
[3]))
;
8849 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value)byte_get (ereg->ri_gp_value, sizeof (ereg->ri_gp_value)
)
;
8850
8851 printf ("GPR %08lx GP 0x%lx\n",
8852 reginfo.ri_gprmask,
8853 (unsigned long) reginfo.ri_gp_value);
8854 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8855 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8856 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8857 }
8858 else
8859 {
8860 /* 64 bit form. */
8861 Elf64_External_RegInfo *ereg;
8862 Elf64_Internal_RegInfo reginfo;
8863
8864 ereg = (Elf64_External_RegInfo *) (option + 1);
8865 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask)byte_get (ereg->ri_gprmask, sizeof (ereg->ri_gprmask));
8866 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0])byte_get (ereg->ri_cprmask[0], sizeof (ereg->ri_cprmask
[0]))
;
8867 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1])byte_get (ereg->ri_cprmask[1], sizeof (ereg->ri_cprmask
[1]))
;
8868 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2])byte_get (ereg->ri_cprmask[2], sizeof (ereg->ri_cprmask
[2]))
;
8869 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3])byte_get (ereg->ri_cprmask[3], sizeof (ereg->ri_cprmask
[3]))
;
8870 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value)byte_get (ereg->ri_gp_value, sizeof (ereg->ri_gp_value)
)
;
8871
8872 printf ("GPR %08lx GP 0x",
8873 reginfo.ri_gprmask);
8874 printf_vma (reginfo.ri_gp_value)fprintf ((&__sF[1]), "%016lx", reginfo.ri_gp_value);
8875 printf ("\n");
8876
8877 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8878 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8879 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8880 }
8881 ++option;
8882 continue;
8883 case ODK_EXCEPTIONS2:
8884 fputs (" EXCEPTIONS fpe_min(", stdout(&__sF[1]));
8885 process_mips_fpe_exception (option->info & OEX_FPU_MIN0x1f);
8886 fputs (") fpe_max(", stdout(&__sF[1]));
8887 process_mips_fpe_exception ((option->info & OEX_FPU_MAX0x1f00) >> 8);
8888 fputs (")", stdout(&__sF[1]));
8889
8890 if (option->info & OEX_PAGE00x10000)
8891 fputs (" PAGE0", stdout(&__sF[1]));
8892 if (option->info & OEX_SMM0x20000)
8893 fputs (" SMM", stdout(&__sF[1]));
8894 if (option->info & OEX_FPDBUG0x40000)
8895 fputs (" FPDBUG", stdout(&__sF[1]));
8896 if (option->info & OEX_DISMISS0x80000)
8897 fputs (" DISMISS", stdout(&__sF[1]));
8898 break;
8899 case ODK_PAD3:
8900 fputs (" PAD ", stdout(&__sF[1]));
8901 if (option->info & OPAD_PREFIX0x01)
8902 fputs (" PREFIX", stdout(&__sF[1]));
8903 if (option->info & OPAD_POSTFIX0x02)
8904 fputs (" POSTFIX", stdout(&__sF[1]));
8905 if (option->info & OPAD_SYMBOL0x04)
8906 fputs (" SYMBOL", stdout(&__sF[1]));
8907 break;
8908 case ODK_HWPATCH4:
8909 fputs (" HWPATCH ", stdout(&__sF[1]));
8910 if (option->info & OHW_R4KEOP0x00000001)
8911 fputs (" R4KEOP", stdout(&__sF[1]));
8912 if (option->info & OHW_R8KPFETCH0x00000002)
8913 fputs (" R8KPFETCH", stdout(&__sF[1]));
8914 if (option->info & OHW_R5KEOP0x00000004)
8915 fputs (" R5KEOP", stdout(&__sF[1]));
8916 if (option->info & OHW_R5KCVTL0x00000008)
8917 fputs (" R5KCVTL", stdout(&__sF[1]));
8918 break;
8919 case ODK_FILL5:
8920 fputs (" FILL ", stdout(&__sF[1]));
8921 /* XXX Print content of info word? */
8922 break;
8923 case ODK_TAGS6:
8924 fputs (" TAGS ", stdout(&__sF[1]));
8925 /* XXX Print content of info word? */
8926 break;
8927 case ODK_HWAND7:
8928 fputs (" HWAND ", stdout(&__sF[1]));
8929 if (option->info & OHWA0_R4KEOP_CHECKED0x00000001)
8930 fputs (" R4KEOP_CHECKED", stdout(&__sF[1]));
8931 if (option->info & OHWA0_R4KEOP_CLEAN0x00000002)
8932 fputs (" R4KEOP_CLEAN", stdout(&__sF[1]));
8933 break;
8934 case ODK_HWOR8:
8935 fputs (" HWOR ", stdout(&__sF[1]));
8936 if (option->info & OHWA0_R4KEOP_CHECKED0x00000001)
8937 fputs (" R4KEOP_CHECKED", stdout(&__sF[1]));
8938 if (option->info & OHWA0_R4KEOP_CLEAN0x00000002)
8939 fputs (" R4KEOP_CLEAN", stdout(&__sF[1]));
8940 break;
8941 case ODK_GP_GROUP9:
8942 printf (" GP_GROUP %#06lx self-contained %#06lx",
8943 option->info & OGP_GROUP0x0000ffff,
8944 (option->info & OGP_SELF0xffff0000) >> 16);
8945 break;
8946 case ODK_IDENT10:
8947 printf (" IDENT %#06lx self-contained %#06lx",
8948 option->info & OGP_GROUP0x0000ffff,
8949 (option->info & OGP_SELF0xffff0000) >> 16);
8950 break;
8951 default:
8952 /* This shouldn't happen. */
8953 printf (" %3d ??? %d %lx",
8954 option->kind, option->section, option->info);
8955 break;
8956 }
8957
8958 len = sizeof (*eopt);
8959 while (len < option->size)
8960 if (((char *) option)[len] >= ' '
8961 && ((char *) option)[len] < 0x7f)
8962 printf ("%c", ((char *) option)[len++]);
8963 else
8964 printf ("\\%03o", ((char *) option)[len++]);
8965
8966 fputs ("\n", stdout(&__sF[1]));
8967 ++option;
8968 }
8969
8970 free (eopt);
8971 }
8972 }
8973
8974 if (conflicts_offset != 0 && conflictsno != 0)
8975 {
8976 Elf32_Conflict *iconf;
8977 size_t cnt;
8978
8979 if (dynamic_symbols == NULL((void*)0))
8980 {
8981 error (_("conflict list found without a dynamic symbol table")("conflict list found without a dynamic symbol table"));
8982 return 0;
8983 }
8984
8985 iconf = cmalloc (conflictsno, sizeof (*iconf));
8986 if (iconf == NULL((void*)0))
8987 {
8988 error (_("Out of memory")("Out of memory"));
8989 return 0;
8990 }
8991
8992 if (is_32bit_elf)
8993 {
8994 Elf32_External_Conflict *econf32;
8995
8996 econf32 = get_data (NULL((void*)0), file, conflicts_offset,
8997 conflictsno, sizeof (*econf32), _("conflict")("conflict"));
8998 if (!econf32)
8999 return 0;
9000
9001 for (cnt = 0; cnt < conflictsno; ++cnt)
9002 iconf[cnt] = BYTE_GET (econf32[cnt])byte_get (econf32[cnt], sizeof (econf32[cnt]));
9003
9004 free (econf32);
9005 }
9006 else
9007 {
9008 Elf64_External_Conflict *econf64;
9009
9010 econf64 = get_data (NULL((void*)0), file, conflicts_offset,
9011 conflictsno, sizeof (*econf64), _("conflict")("conflict"));
9012 if (!econf64)
9013 return 0;
9014
9015 for (cnt = 0; cnt < conflictsno; ++cnt)
9016 iconf[cnt] = BYTE_GET (econf64[cnt])byte_get (econf64[cnt], sizeof (econf64[cnt]));
9017
9018 free (econf64);
9019 }
9020
9021 printf (_("\nSection '.conflict' contains %lu entries:\n")("\nSection '.conflict' contains %lu entries:\n"),
9022 (unsigned long) conflictsno);
9023 puts (_(" Num: Index Value Name")(" Num: Index Value Name"));
9024
9025 for (cnt = 0; cnt < conflictsno; ++cnt)
9026 {
9027 Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
9028
9029 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
9030 print_vma (psym->st_value, FULL_HEX);
9031 putchar (' ')(!__isthreaded ? __sputc(' ', (&__sF[1])) : (putc)(' ', (
&__sF[1])))
;
9032 if (VALID_DYNAMIC_NAME (psym->st_name)((dynamic_strings != ((void*)0)) && (psym->st_name
< dynamic_strings_length))
)
9033 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name)(dynamic_strings + psym->st_name));
9034 else
9035 printf ("<corrupt: %14ld>", psym->st_name);
9036 putchar ('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
9037 }
9038
9039 free (iconf);
9040 }
9041
9042 return 1;
9043}
9044
9045static int
9046process_gnu_liblist (FILE *file)
9047{
9048 Elf_Internal_Shdr *section, *string_sec;
9049 Elf32_External_Lib *elib;
9050 char *strtab;
9051 size_t strtab_size;
9052 size_t cnt;
9053 unsigned i;
9054
9055 if (! do_arch)
9056 return 0;
9057
9058 for (i = 0, section = section_headers;
9059 i < elf_header.e_shnum;
9060 i++, section++)
9061 {
9062 switch (section->sh_type)
9063 {
9064 case SHT_GNU_LIBLIST0x6ffffff7:
9065 if (SECTION_HEADER_INDEX (section->sh_link)((section->sh_link) < 0xFF00 ? (section->sh_link) : (
(section->sh_link) <= 0xFFFF ? 0 : (section->sh_link
) - (0xFFFF + 1 - 0xFF00)))
>= elf_header.e_shnum)
9066 break;
9067
9068 elib = get_data (NULL((void*)0), file, section->sh_offset, 1, section->sh_size,
9069 _("liblist")("liblist"));
9070
9071 if (elib == NULL((void*)0))
9072 break;
9073 string_sec = SECTION_HEADER (section->sh_link)(section_headers + ((section->sh_link) < 0xFF00 ? (section
->sh_link) : ((section->sh_link) <= 0xFFFF ? 0 : (section
->sh_link) - (0xFFFF + 1 - 0xFF00))))
;
9074
9075 strtab = get_data (NULL((void*)0), file, string_sec->sh_offset, 1,
9076 string_sec->sh_size, _("liblist string table")("liblist string table"));
9077 strtab_size = string_sec->sh_size;
9078
9079 if (strtab == NULL((void*)0)
9080 || section->sh_entsize != sizeof (Elf32_External_Lib))
9081 {
9082 free (elib);
9083 break;
9084 }
9085
9086 printf (_("\nLibrary list section '%s' contains %lu entries:\n")("\nLibrary list section '%s' contains %lu entries:\n"),
9087 SECTION_NAME (section)((section) == ((void*)0) ? "<none>" : ((section)->sh_name
>= string_table_length ? "<corrupt>" : string_table
+ (section)->sh_name))
,
9088 (long) (section->sh_size / sizeof (Elf32_External_Lib)));
9089
9090 puts (" Library Time Stamp Checksum Version Flags");
9091
9092 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
9093 ++cnt)
9094 {
9095 Elf32_Lib liblist;
9096 time_t time;
9097 char timebuf[20];
9098 struct tm *tmp;
9099
9100 liblist.l_name = BYTE_GET (elib[cnt].l_name)byte_get (elib[cnt].l_name, sizeof (elib[cnt].l_name));
9101 time = BYTE_GET (elib[cnt].l_time_stamp)byte_get (elib[cnt].l_time_stamp, sizeof (elib[cnt].l_time_stamp
))
;
9102 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum)byte_get (elib[cnt].l_checksum, sizeof (elib[cnt].l_checksum)
)
;
9103 liblist.l_version = BYTE_GET (elib[cnt].l_version)byte_get (elib[cnt].l_version, sizeof (elib[cnt].l_version));
9104 liblist.l_flags = BYTE_GET (elib[cnt].l_flags)byte_get (elib[cnt].l_flags, sizeof (elib[cnt].l_flags));
9105
9106 tmp = gmtime (&time);
9107 snprintf (timebuf, sizeof (timebuf),
9108 "%04u-%02u-%02uT%02u:%02u:%02u",
9109 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9110 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
9111
9112 printf ("%3lu: ", (unsigned long) cnt);
9113 if (do_wide)
9114 printf ("%-20s", liblist.l_name < strtab_size
9115 ? strtab + liblist.l_name : "<corrupt>");
9116 else
9117 printf ("%-20.20s", liblist.l_name < strtab_size
9118 ? strtab + liblist.l_name : "<corrupt>");
9119 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
9120 liblist.l_version, liblist.l_flags);
9121 }
9122
9123 free (elib);
9124 }
9125 }
9126
9127 return 1;
9128}
9129
9130static const char *
9131get_note_type (unsigned e_type)
9132{
9133 static char buff[64];
9134
9135 if (elf_header.e_type == ET_CORE4)
9136 switch (e_type)
9137 {
9138 case NT_AUXV6:
9139 return _("NT_AUXV (auxiliary vector)")("NT_AUXV (auxiliary vector)");
9140 case NT_PRSTATUS1:
9141 return _("NT_PRSTATUS (prstatus structure)")("NT_PRSTATUS (prstatus structure)");
9142 case NT_FPREGSET2:
9143 return _("NT_FPREGSET (floating point registers)")("NT_FPREGSET (floating point registers)");
9144 case NT_PRPSINFO3:
9145 return _("NT_PRPSINFO (prpsinfo structure)")("NT_PRPSINFO (prpsinfo structure)");
9146 case NT_TASKSTRUCT4:
9147 return _("NT_TASKSTRUCT (task structure)")("NT_TASKSTRUCT (task structure)");
9148 case NT_PRXFPREG0x46e62b7f:
9149 return _("NT_PRXFPREG (user_xfpregs structure)")("NT_PRXFPREG (user_xfpregs structure)");
9150 case NT_PSTATUS10:
9151 return _("NT_PSTATUS (pstatus structure)")("NT_PSTATUS (pstatus structure)");
9152 case NT_FPREGS12:
9153 return _("NT_FPREGS (floating point registers)")("NT_FPREGS (floating point registers)");
9154 case NT_PSINFO13:
9155 return _("NT_PSINFO (psinfo structure)")("NT_PSINFO (psinfo structure)");
9156 case NT_LWPSTATUS16:
9157 return _("NT_LWPSTATUS (lwpstatus_t structure)")("NT_LWPSTATUS (lwpstatus_t structure)");
9158 case NT_LWPSINFO17:
9159 return _("NT_LWPSINFO (lwpsinfo_t structure)")("NT_LWPSINFO (lwpsinfo_t structure)");
9160 case NT_WIN32PSTATUS18:
9161 return _("NT_WIN32PSTATUS (win32_pstatus structure)")("NT_WIN32PSTATUS (win32_pstatus structure)");
9162 default:
9163 break;
9164 }
9165 else
9166 switch (e_type)
9167 {
9168 case NT_VERSION1:
9169 return _("NT_VERSION (version)")("NT_VERSION (version)");
9170 case NT_ARCH2:
9171 return _("NT_ARCH (architecture)")("NT_ARCH (architecture)");
9172 default:
9173 break;
9174 }
9175
9176 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)")("Unknown note type: (0x%08x)"), e_type);
9177 return buff;
9178}
9179
9180static const char *
9181get_netbsd_elfcore_note_type (unsigned e_type)
9182{
9183 static char buff[64];
9184
9185 if (e_type == NT_NETBSDCORE_PROCINFO1)
9186 {
9187 /* NetBSD core "procinfo" structure. */
9188 return _("NetBSD procinfo structure")("NetBSD procinfo structure");
9189 }
9190
9191 /* As of Jan 2002 there are no other machine-independent notes
9192 defined for NetBSD core files. If the note type is less
9193 than the start of the machine-dependent note types, we don't
9194 understand it. */
9195
9196 if (e_type < NT_NETBSDCORE_FIRSTMACH32)
9197 {
9198 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)")("Unknown note type: (0x%08x)"), e_type);
9199 return buff;
9200 }
9201
9202 switch (elf_header.e_machine)
9203 {
9204 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9205 and PT_GETFPREGS == mach+2. */
9206
9207 case EM_OLD_ALPHA41:
9208 case EM_ALPHA0x9026:
9209 case EM_SPARC2:
9210 case EM_SPARC32PLUS18:
9211 case EM_SPARCV943:
9212 switch (e_type)
9213 {
9214 case NT_NETBSDCORE_FIRSTMACH32+0:
9215 return _("PT_GETREGS (reg structure)")("PT_GETREGS (reg structure)");
9216 case NT_NETBSDCORE_FIRSTMACH32+2:
9217 return _("PT_GETFPREGS (fpreg structure)")("PT_GETFPREGS (fpreg structure)");
9218 default:
9219 break;
9220 }
9221 break;
9222
9223 /* On all other arch's, PT_GETREGS == mach+1 and
9224 PT_GETFPREGS == mach+3. */
9225 default:
9226 switch (e_type)
9227 {
9228 case NT_NETBSDCORE_FIRSTMACH32+1:
9229 return _("PT_GETREGS (reg structure)")("PT_GETREGS (reg structure)");
9230 case NT_NETBSDCORE_FIRSTMACH32+3:
9231 return _("PT_GETFPREGS (fpreg structure)")("PT_GETFPREGS (fpreg structure)");
9232 default:
9233 break;
9234 }
9235 }
9236
9237 snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d")("PT_FIRSTMACH+%d"),
9238 e_type - NT_NETBSDCORE_FIRSTMACH32);
9239 return buff;
9240}
9241
9242/* Note that by the ELF standard, the name field is already null byte
9243 terminated, and namesz includes the terminating null byte.
9244 I.E. the value of namesz for the name "FSF" is 4.
9245
9246 If the value of namesz is zero, there is no name present. */
9247static int
9248process_note (Elf_Internal_Note *pnote)
9249{
9250 const char *nt;
9251
9252 if (pnote->namesz == 0)
9253 /* If there is no note name, then use the default set of
9254 note type strings. */
9255 nt = get_note_type (pnote->type);
9256
9257 else if (strneq (pnote->namedata, "NetBSD-CORE", 11)(strncmp ((pnote->namedata), ("NetBSD-CORE"), (11)) == 0))
9258 /* NetBSD-specific core file notes. */
9259 nt = get_netbsd_elfcore_note_type (pnote->type);
9260
9261 else
9262 /* Don't recognize this note name; just use the default set of
9263 note type strings. */
9264 nt = get_note_type (pnote->type);
9265
9266 printf (" %s\t\t0x%08lx\t%s\n",
9267 pnote->namesz ? pnote->namedata : "(NONE)",
9268 pnote->descsz, nt);
9269 return 1;
9270}
9271
9272
9273static int
9274process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
9275{
9276 Elf_External_Note *pnotes;
9277 Elf_External_Note *external;
9278 int res = 1;
9279
9280 if (length <= 0)
9281 return 0;
9282
9283 pnotes = get_data (NULL((void*)0), file, offset, 1, length, _("notes")("notes"));
9284 if (!pnotes)
9285 return 0;
9286
9287 external = pnotes;
9288
9289 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n")("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9290 (unsigned long) offset, (unsigned long) length);
9291 printf (_(" Owner\t\tData size\tDescription\n")(" Owner\t\tData size\tDescription\n"));
9292
9293 while (external < (Elf_External_Note *)((char *) pnotes + length))
9294 {
9295 Elf_External_Note *next;
9296 Elf_Internal_Note inote;
9297 char *temp = NULL((void*)0);
9298
9299 inote.type = BYTE_GET (external->type)byte_get (external->type, sizeof (external->type));
9300 inote.namesz = BYTE_GET (external->namesz)byte_get (external->namesz, sizeof (external->namesz));
9301 inote.namedata = external->name;
9302 inote.descsz = BYTE_GET (external->descsz)byte_get (external->descsz, sizeof (external->descsz));
9303 inote.descdata = inote.namedata + align_power (inote.namesz, 2)(((inote.namesz) + ((bfd_vma) 1 << (2)) - 1) & ((bfd_vma
) -1 << (2)))
;
9304 inote.descpos = offset + (inote.descdata - (char *) pnotes);
9305
9306 next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2)(((inote.descsz) + ((bfd_vma) 1 << (2)) - 1) & ((bfd_vma
) -1 << (2)))
);
9307
9308 if (((char *) next) > (((char *) pnotes) + length))
9309 {
9310 warn (_("corrupt note found at offset %lx into core notes\n")("corrupt note found at offset %lx into core notes\n"),
9311 (long)((char *)external - (char *)pnotes));
9312 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n")(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
9313 inote.type, inote.namesz, inote.descsz);
9314 break;
9315 }
9316
9317 external = next;
9318
9319 /* Verify that name is null terminated. It appears that at least
9320 one version of Linux (RedHat 6.0) generates corefiles that don't
9321 comply with the ELF spec by failing to include the null byte in
9322 namesz. */
9323 if (inote.namedata[inote.namesz] != '\0')
9324 {
9325 temp = malloc (inote.namesz + 1);
9326
9327 if (temp == NULL((void*)0))
9328 {
9329 error (_("Out of memory\n")("Out of memory\n"));
9330 res = 0;
9331 break;
9332 }
9333
9334 strncpy (temp, inote.namedata, inote.namesz);
9335 temp[inote.namesz] = 0;
9336
9337 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9338 inote.namedata = temp;
9339 }
9340
9341 res &= process_note (& inote);
9342
9343 if (temp != NULL((void*)0))
9344 {
9345 free (temp);
9346 temp = NULL((void*)0);
9347 }
9348 }
9349
9350 free (pnotes);
9351
9352 return res;
9353}
9354
9355static int
9356process_corefile_note_segments (FILE *file)
9357{
9358 Elf_Internal_Phdr *segment;
9359 unsigned int i;
9360 int res = 1;
9361
9362 if (! get_program_headers (file))
9363 return 0;
9364
9365 for (i = 0, segment = program_headers;
9366 i < elf_header.e_phnum;
9367 i++, segment++)
9368 {
9369 if (segment->p_type == PT_NOTE4)
9370 res &= process_corefile_note_segment (file,
9371 (bfd_vma) segment->p_offset,
9372 (bfd_vma) segment->p_filesz);
9373 }
9374
9375 return res;
9376}
9377
9378static int
9379process_note_sections (FILE *file)
9380{
9381 Elf_Internal_Shdr *section;
9382 unsigned long i;
9383 int res = 1;
9384
9385 for (i = 0, section = section_headers;
9386 i < elf_header.e_shnum;
9387 i++, section++)
9388 if (section->sh_type == SHT_NOTE7)
9389 res &= process_corefile_note_segment (file,
9390 (bfd_vma) section->sh_offset,
9391 (bfd_vma) section->sh_size);
9392
9393 return res;
9394}
9395
9396static int
9397process_notes (FILE *file)
9398{
9399 /* If we have not been asked to display the notes then do nothing. */
9400 if (! do_notes)
9401 return 1;
9402
9403 if (elf_header.e_type != ET_CORE4)
9404 return process_note_sections (file);
9405
9406 /* No program headers means no NOTE segment. */
9407 if (elf_header.e_phnum > 0)
9408 return process_corefile_note_segments (file);
9409
9410 printf (_("No note segments present in the core file.\n")("No note segments present in the core file.\n"));
9411 return 1;
9412}
9413
9414static int
9415process_arch_specific (FILE *file)
9416{
9417 if (! do_arch)
9418 return 1;
9419
9420 switch (elf_header.e_machine)
9421 {
9422 case EM_ARM40:
9423 return process_arm_specific (file);
9424 case EM_MIPS8:
9425 case EM_MIPS_RS3_LE10:
9426 return process_mips_specific (file);
9427 break;
9428 default:
9429 break;
9430 }
9431 return 1;
9432}
9433
9434static int
9435get_file_header (FILE *file)
9436{
9437 /* Read in the identity array. */
9438 if (fread (elf_header.e_ident, EI_NIDENT16, 1, file) != 1)
9439 return 0;
9440
9441 /* Determine how to read the rest of the header. */
9442 switch (elf_header.e_ident[EI_DATA5])
9443 {
9444 default: /* fall through */
9445 case ELFDATANONE0: /* fall through */
9446 case ELFDATA2LSB1:
9447 byte_get = byte_get_little_endian;
9448 byte_put = byte_put_little_endian;
9449 break;
9450 case ELFDATA2MSB2:
9451 byte_get = byte_get_big_endian;
9452 byte_put = byte_put_big_endian;
9453 break;
9454 }
9455
9456 /* For now we only support 32 bit and 64 bit ELF files. */
9457 is_32bit_elf = (elf_header.e_ident[EI_CLASS4] != ELFCLASS642);
9458
9459 /* Read in the rest of the header. */
9460 if (is_32bit_elf)
9461 {
9462 Elf32_External_Ehdr ehdr32;
9463 /* Temporary var to prevent the GCC -Wbounded checker from firing. */
9464 void *tmp = &ehdr32.e_type[0];
9465
9466 if (fread (tmp, sizeof (ehdr32) - EI_NIDENT16, 1, file) != 1)
9467 return 0;
9468
9469 elf_header.e_type = BYTE_GET (ehdr32.e_type)byte_get (ehdr32.e_type, sizeof (ehdr32.e_type));
9470 elf_header.e_machine = BYTE_GET (ehdr32.e_machine)byte_get (ehdr32.e_machine, sizeof (ehdr32.e_machine));
9471 elf_header.e_version = BYTE_GET (ehdr32.e_version)byte_get (ehdr32.e_version, sizeof (ehdr32.e_version));
9472 elf_header.e_entry = BYTE_GET (ehdr32.e_entry)byte_get (ehdr32.e_entry, sizeof (ehdr32.e_entry));
9473 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff)byte_get (ehdr32.e_phoff, sizeof (ehdr32.e_phoff));
9474 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff)byte_get (ehdr32.e_shoff, sizeof (ehdr32.e_shoff));
9475 elf_header.e_flags = BYTE_GET (ehdr32.e_flags)byte_get (ehdr32.e_flags, sizeof (ehdr32.e_flags));
9476 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize)byte_get (ehdr32.e_ehsize, sizeof (ehdr32.e_ehsize));
9477 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize)byte_get (ehdr32.e_phentsize, sizeof (ehdr32.e_phentsize));
9478 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum)byte_get (ehdr32.e_phnum, sizeof (ehdr32.e_phnum));
9479 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize)byte_get (ehdr32.e_shentsize, sizeof (ehdr32.e_shentsize));
9480 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum)byte_get (ehdr32.e_shnum, sizeof (ehdr32.e_shnum));
9481 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx)byte_get (ehdr32.e_shstrndx, sizeof (ehdr32.e_shstrndx));
9482 }
9483 else
9484 {
9485 Elf64_External_Ehdr ehdr64;
9486 /* Temporary var to prevent the GCC -Wbounded checker from firing. */
9487 void *tmp = &ehdr64.e_type[0];
9488
9489 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9490 we will not be able to cope with the 64bit data found in
9491 64 ELF files. Detect this now and abort before we start
9492 overwriting things. */
9493 if (sizeof (bfd_vma) < 8)
9494 {
9495 error (_("This instance of readelf has been built without support for a\n\("This instance of readelf has been built without support for a\n64 bit data type and so it cannot read 64 bit ELF files.\n"
)
949664 bit data type and so it cannot read 64 bit ELF files.\n")("This instance of readelf has been built without support for a\n64 bit data type and so it cannot read 64 bit ELF files.\n"
)
);
9497 return 0;
9498 }
9499
9500 if (fread (tmp, sizeof (ehdr64) - EI_NIDENT16, 1, file) != 1)
9501 return 0;
9502
9503 elf_header.e_type = BYTE_GET (ehdr64.e_type)byte_get (ehdr64.e_type, sizeof (ehdr64.e_type));
9504 elf_header.e_machine = BYTE_GET (ehdr64.e_machine)byte_get (ehdr64.e_machine, sizeof (ehdr64.e_machine));
9505 elf_header.e_version = BYTE_GET (ehdr64.e_version)byte_get (ehdr64.e_version, sizeof (ehdr64.e_version));
9506 elf_header.e_entry = BYTE_GET (ehdr64.e_entry)byte_get (ehdr64.e_entry, sizeof (ehdr64.e_entry));
9507 elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff)byte_get (ehdr64.e_phoff, sizeof (ehdr64.e_phoff));
9508 elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff)byte_get (ehdr64.e_shoff, sizeof (ehdr64.e_shoff));
9509 elf_header.e_flags = BYTE_GET (ehdr64.e_flags)byte_get (ehdr64.e_flags, sizeof (ehdr64.e_flags));
9510 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize)byte_get (ehdr64.e_ehsize, sizeof (ehdr64.e_ehsize));
9511 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize)byte_get (ehdr64.e_phentsize, sizeof (ehdr64.e_phentsize));
9512 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum)byte_get (ehdr64.e_phnum, sizeof (ehdr64.e_phnum));
9513 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize)byte_get (ehdr64.e_shentsize, sizeof (ehdr64.e_shentsize));
9514 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum)byte_get (ehdr64.e_shnum, sizeof (ehdr64.e_shnum));
9515 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx)byte_get (ehdr64.e_shstrndx, sizeof (ehdr64.e_shstrndx));
9516 }
9517
9518 if (elf_header.e_shoff)
9519 {
9520 /* There may be some extensions in the first section header. Don't
9521 bomb if we can't read it. */
9522 if (is_32bit_elf)
9523 get_32bit_section_headers (file, 1);
9524 else
9525 get_64bit_section_headers (file, 1);
9526 }
9527
9528 is_relocatable = elf_header.e_type == ET_REL1;
9529
9530 return 1;
9531}
9532
9533/* Process one ELF object file according to the command line options.
9534 This file may actually be stored in an archive. The file is
9535 positioned at the start of the ELF object. */
9536
9537static int
9538process_object (char *file_name, FILE *file)
9539{
9540 unsigned int i;
9541
9542 if (! get_file_header (file))
9543 {
9544 error (_("%s: Failed to read file header\n")("%s: Failed to read file header\n"), file_name);
9545 return 1;
9546 }
9547
9548 /* Initialise per file variables. */
9549 for (i = NUM_ELEM (version_info)(sizeof (version_info) / sizeof ((version_info)[0])); i--;)
9550 version_info[i] = 0;
9551
9552 for (i = NUM_ELEM (dynamic_info)(sizeof (dynamic_info) / sizeof ((dynamic_info)[0])); i--;)
9553 dynamic_info[i] = 0;
9554
9555 /* Process the file. */
9556 if (show_name)
9557 printf (_("\nFile: %s\n")("\nFile: %s\n"), file_name);
9558
9559 /* Initialise the dump_sects array from the cmdline_dump_sects array.
9560 Note we do this even if cmdline_dump_sects is empty because we
9561 must make sure that the dump_sets array is zeroed out before each
9562 object file is processed. */
9563 if (num_dump_sects > num_cmdline_dump_sects)
9564 memset (dump_sects, 0, num_dump_sects);
9565
9566 if (num_cmdline_dump_sects > 0)
9567 {
9568 if (num_dump_sects == 0)
9569 /* A sneaky way of allocating the dump_sects array. */
9570 request_dump (num_cmdline_dump_sects, 0);
9571
9572 assert (num_dump_sects >= num_cmdline_dump_sects)((num_dump_sects >= num_cmdline_dump_sects) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/readelf.c", 9572
, __func__, "num_dump_sects >= num_cmdline_dump_sects"))
;
9573 memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
9574 }
9575
9576 if (! process_file_header ())
9577 return 1;
9578
9579 if (! process_section_headers (file))
9580 {
9581 /* Without loaded section headers we cannot process lots of
9582 things. */
9583 do_unwind = do_version = do_dump = do_arch = 0;
9584
9585 if (! do_using_dynamic)
9586 do_syms = do_reloc = 0;
9587 }
9588
9589 if (! process_section_groups (file))
9590 {
9591 /* Without loaded section groups we cannot process unwind. */
9592 do_unwind = 0;
9593 }
9594
9595 if (process_program_headers (file))
9596 process_dynamic_section (file);
9597
9598 process_relocs (file);
9599
9600 process_unwind (file);
9601
9602 process_symbol_table (file);
9603
9604 process_syminfo (file);
9605
9606 process_version_sections (file);
9607
9608 process_section_contents (file);
9609
9610 process_notes (file);
9611
9612 process_gnu_liblist (file);
9613
9614 process_arch_specific (file);
9615
9616 if (program_headers)
9617 {
9618 free (program_headers);
9619 program_headers = NULL((void*)0);
9620 }
9621
9622 if (section_headers)
9623 {
9624 free (section_headers);
9625 section_headers = NULL((void*)0);
9626 }
9627
9628 if (string_table)
9629 {
9630 free (string_table);
9631 string_table = NULL((void*)0);
9632 string_table_length = 0;
9633 }
9634
9635 if (dynamic_strings)
9636 {
9637 free (dynamic_strings);
9638 dynamic_strings = NULL((void*)0);
9639 dynamic_strings_length = 0;
9640 }
9641
9642 if (dynamic_symbols)
9643 {
9644 free (dynamic_symbols);
9645 dynamic_symbols = NULL((void*)0);
9646 num_dynamic_syms = 0;
9647 }
9648
9649 if (dynamic_syminfo)
9650 {
9651 free (dynamic_syminfo);
9652 dynamic_syminfo = NULL((void*)0);
9653 }
9654
9655 if (section_headers_groups)
9656 {
9657 free (section_headers_groups);
9658 section_headers_groups = NULL((void*)0);
9659 }
9660
9661 if (section_groups)
9662 {
9663 struct group_list *g, *next;
9664
9665 for (i = 0; i < group_count; i++)
9666 {
9667 for (g = section_groups [i].root; g != NULL((void*)0); g = next)
9668 {
9669 next = g->next;
9670 free (g);
9671 }
9672 }
9673
9674 free (section_groups);
9675 section_groups = NULL((void*)0);
9676 }
9677
9678 free_debug_memory ();
9679
9680 return 0;
9681}
9682
9683/* Process an ELF archive. The file is positioned just after the
9684 ARMAG string. */
9685
9686static int
9687process_archive (char *file_name, FILE *file)
9688{
9689 struct ar_hdr arhdr;
9690 size_t got;
9691 unsigned long size;
9692 char *longnames = NULL((void*)0);
9693 unsigned long longnames_size = 0;
9694 size_t file_name_size;
9695 int ret;
9696
9697 show_name = 1;
9698
9699 got = fread (&arhdr, 1, sizeof arhdr, file);
9700 if (got != sizeof arhdr)
9701 {
9702 if (got == 0)
9703 return 0;
9704
9705 error (_("%s: failed to read archive header\n")("%s: failed to read archive header\n"), file_name);
9706 return 1;
9707 }
9708
9709 if (memcmp (arhdr.ar_name, "/ ", 16) == 0
9710 || memcmp (arhdr.ar_name, "/SYM64/ ", 16) == 0)
9711 {
9712 /* This is the archive symbol table. Skip it.
9713 FIXME: We should have an option to dump it. */
9714 size = strtoul (arhdr.ar_size, NULL((void*)0), 10);
9715 if (fseek (file, size + (size & 1), SEEK_CUR1) != 0)
9716 {
9717 error (_("%s: failed to skip archive symbol table\n")("%s: failed to skip archive symbol table\n"), file_name);
9718 return 1;
9719 }
9720
9721 got = fread (&arhdr, 1, sizeof arhdr, file);
9722 if (got != sizeof arhdr)
9723 {
9724 if (got == 0)
9725 return 0;
9726
9727 error (_("%s: failed to read archive header\n")("%s: failed to read archive header\n"), file_name);
9728 return 1;
9729 }
9730 }
9731
9732 if (memcmp (arhdr.ar_name, "// ", 16) == 0)
9733 {
9734 /* This is the archive string table holding long member
9735 names. */
9736
9737 longnames_size = strtoul (arhdr.ar_size, NULL((void*)0), 10);
9738
9739 longnames = malloc (longnames_size);
9740 if (longnames == NULL((void*)0))
9741 {
9742 error (_("Out of memory\n")("Out of memory\n"));
9743 return 1;
9744 }
9745
9746 if (fread (longnames, longnames_size, 1, file) != 1)
9747 {
9748 free (longnames);
9749 error (_("%s: failed to read string table\n")("%s: failed to read string table\n"), file_name);
9750 return 1;
9751 }
9752
9753 if ((longnames_size & 1) != 0)
9754 getc (file)(!__isthreaded ? (--(file)->_r < 0 ? __srget(file) : (int
)(*(file)->_p++)) : (getc)(file))
;
9755
9756 got = fread (&arhdr, 1, sizeof arhdr, file);
9757 if (got != sizeof arhdr)
9758 {
9759 free (longnames);
9760
9761 if (got == 0)
9762 return 0;
9763
9764 error (_("%s: failed to read archive header\n")("%s: failed to read archive header\n"), file_name);
9765 return 1;
9766 }
9767 }
9768
9769 file_name_size = strlen (file_name);
9770 ret = 0;
9771
9772 while (1)
9773 {
9774 char *name;
9775 char *nameend;
9776 char *namealc;
9777
9778 if (arhdr.ar_name[0] == '/')
9779 {
9780 unsigned long off;
9781
9782 off = strtoul (arhdr.ar_name + 1, NULL((void*)0), 10);
9783 if (off >= longnames_size)
9784 {
9785 error (_("%s: invalid archive string table offset %lu\n")("%s: invalid archive string table offset %lu\n"), file_name, off);
9786 ret = 1;
9787 break;
9788 }
9789
9790 name = longnames + off;
9791 nameend = memchr (name, '/', longnames_size - off);
9792 }
9793 else
9794 {
9795 name = arhdr.ar_name;
9796 nameend = memchr (name, '/', 16);
9797 }
9798
9799 if (nameend == NULL((void*)0))
9800 {
9801 error (_("%s: bad archive file name\n")("%s: bad archive file name\n"), file_name);
9802 ret = 1;
9803 break;
9804 }
9805
9806 namealc = malloc (file_name_size + (nameend - name) + 3);
9807 if (namealc == NULL((void*)0))
9808 {
9809 error (_("Out of memory\n")("Out of memory\n"));
9810 ret = 1;
9811 break;
9812 }
9813
9814 memcpy (namealc, file_name, file_name_size);
9815 namealc[file_name_size] = '(';
9816 memcpy (namealc + file_name_size + 1, name, nameend - name);
9817 namealc[file_name_size + 1 + (nameend - name)] = ')';
9818 namealc[file_name_size + 2 + (nameend - name)] = '\0';
9819
9820 archive_file_offset = ftell (file);
9821 archive_file_size = strtoul (arhdr.ar_size, NULL((void*)0), 10);
9822
9823 ret |= process_object (namealc, file);
9824
9825 free (namealc);
9826
9827 if (fseek (file,
9828 (archive_file_offset
9829 + archive_file_size
9830 + (archive_file_size & 1)),
9831 SEEK_SET0) != 0)
9832 {
9833 error (_("%s: failed to seek to next archive header\n")("%s: failed to seek to next archive header\n"), file_name);
9834 ret = 1;
9835 break;
9836 }
9837
9838 got = fread (&arhdr, 1, sizeof arhdr, file);
9839 if (got != sizeof arhdr)
9840 {
9841 if (got == 0)
9842 break;
9843
9844 error (_("%s: failed to read archive header\n")("%s: failed to read archive header\n"), file_name);
9845 ret = 1;
9846 break;
9847 }
9848 }
9849
9850 if (longnames != 0)
9851 free (longnames);
9852
9853 return ret;
9854}
9855
9856static int
9857process_file (char *file_name)
9858{
9859 FILE *file;
9860 struct stat statbuf;
9861 char armag[SARMAG8];
9862 int ret;
9863
9864 if (stat (file_name, &statbuf) < 0)
9865 {
9866 if (errno(*__errno()) == ENOENT2)
9867 error (_("'%s': No such file\n")("'%s': No such file\n"), file_name);
9868 else
9869 error (_("Could not locate '%s'. System error message: %s\n")("Could not locate '%s'. System error message: %s\n"),
9870 file_name, strerror (errno(*__errno())));
9871 return 1;
9872 }
9873
9874 if (! S_ISREG (statbuf.st_mode)((statbuf.st_mode & 0170000) == 0100000))
9875 {
9876 error (_("'%s' is not an ordinary file\n")("'%s' is not an ordinary file\n"), file_name);
9877 return 1;
9878 }
9879
9880 file = fopen (file_name, "rb");
9881 if (file == NULL((void*)0))
9882 {
9883 error (_("Input file '%s' is not readable.\n")("Input file '%s' is not readable.\n"), file_name);
9884 return 1;
9885 }
9886
9887 if (fread (armag, SARMAG8, 1, file) != 1)
9888 {
9889 error (_("%s: Failed to read file header\n")("%s: Failed to read file header\n"), file_name);
9890 fclose (file);
9891 return 1;
9892 }
9893
9894 if (memcmp (armag, ARMAG"!<arch>\012", SARMAG8) == 0)
9895 ret = process_archive (file_name, file);
9896 else
9897 {
9898 rewind (file);
9899 archive_file_size = archive_file_offset = 0;
9900 ret = process_object (file_name, file);
9901 }
9902
9903 fclose (file);
9904
9905 return ret;
9906}
9907
9908#ifdef SUPPORT_DISASSEMBLY
9909/* Needed by the i386 disassembler. For extra credit, someone could
9910 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9911 symbols. */
9912
9913void
9914print_address (unsigned int addr, FILE *outfile)
9915{
9916 fprintf (outfile,"0x%8.8x", addr);
9917}
9918
9919/* Needed by the i386 disassembler. */
9920void
9921db_task_printsym (unsigned int addr)
9922{
9923 print_address (addr, stderr(&__sF[2]));
9924}
9925#endif
9926
9927int
9928main (int argc, char **argv)
9929{
9930 int err;
9931
9932#if defined (HAVE_SETLOCALE1) && defined (HAVE_LC_MESSAGES1)
9933 setlocale (LC_MESSAGES6, "");
9934#endif
9935#if defined (HAVE_SETLOCALE1)
9936 setlocale (LC_CTYPE2, "");
9937#endif
9938 bindtextdomain (PACKAGE, LOCALEDIR)while (0);
9939 textdomain (PACKAGE)while (0);
9940
9941 expandargv (&argc, &argv);
9942
9943 parse_args (argc, argv);
9944
9945 if (pledge ("stdio rpath", NULL((void*)0)) == -1) {
9946 error (_("Failed to pledge\n")("Failed to pledge\n"));
9947 return 1;
9948 }
9949
9950 if (num_dump_sects > 0)
9951 {
9952 /* Make a copy of the dump_sects array. */
9953 cmdline_dump_sects = malloc (num_dump_sects);
9954 if (cmdline_dump_sects == NULL((void*)0))
9955 error (_("Out of memory allocating dump request table.")("Out of memory allocating dump request table."));
9956 else
9957 {
9958 memcpy (cmdline_dump_sects, dump_sects, num_dump_sects);
9959 num_cmdline_dump_sects = num_dump_sects;
9960 }
9961 }
9962
9963 if (optind < (argc - 1))
9964 show_name = 1;
9965
9966 err = 0;
9967 while (optind < argc)
9968 err |= process_file (argv[optind++]);
9969
9970 if (dump_sects != NULL((void*)0))
9971 free (dump_sects);
9972 if (cmdline_dump_sects != NULL((void*)0))
9973 free (cmdline_dump_sects);
9974
9975 return err;
9976}