]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - binutils/readelf.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / binutils / readelf.c
CommitLineData
252b5132 1/* readelf.c -- display contents of an ELF format file
82704155 2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
252b5132
RH
3
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
12ab83a9 5 Modifications by Nick Clifton <nickc@redhat.com>
252b5132
RH
6
7 This file is part of GNU Binutils.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
32866df7 11 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
b43b5d5f
NC
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 02110-1301, USA. */
252b5132 23\f
9eb20dd8 24/* The difference between readelf and objdump:
252b5132 25
74013231 26 Both programs are capable of displaying the contents of ELF format files,
9eb20dd8 27 so why does the binutils project have two file dumpers ?
0de14b54 28
9eb20dd8
NC
29 The reason is that objdump sees an ELF file through a BFD filter of the
30 world; if BFD has a bug where, say, it disagrees about a machine constant
31 in e_flags, then the odds are good that it will remain internally
32 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
33 GAS sees it the BFD way. There was need for a tool to go find out what
34 the file actually says.
35
36 This is why the readelf program does not link against the BFD library - it
37 exists as an independent program to help verify the correct working of BFD.
38
39 There is also the case that readelf can provide more information about an
40 ELF file than is provided by objdump. In particular it can display DWARF
41 debugging information which (at the moment) objdump cannot. */
42\f
3db64b00 43#include "sysdep.h"
252b5132 44#include <assert.h>
252b5132 45#include <time.h>
1b315056 46#include <zlib.h>
3bfcb652 47#ifdef HAVE_WCHAR_H
7bfd842d 48#include <wchar.h>
3bfcb652 49#endif
252b5132 50
a952a375 51#if __GNUC__ >= 2
19936277 52/* Define BFD64 here, even if our default architecture is 32 bit ELF
a952a375 53 as this will allow us to read in and parse 64bit and 32bit ELF files.
b34976b6 54 Only do this if we believe that the compiler can support a 64 bit
a952a375 55 data type. For now we only rely on GCC being able to do this. */
19936277 56#define BFD64
a952a375
NC
57#endif
58
3db64b00
AM
59#include "bfd.h"
60#include "bucomm.h"
3284fe0c 61#include "elfcomm.h"
19e6b90e 62#include "dwarf.h"
90bd5423 63#ifdef HAVE_LIBCTF
7d9813f1 64#include "ctf-api.h"
90bd5423 65#endif
252b5132
RH
66
67#include "elf/common.h"
68#include "elf/external.h"
69#include "elf/internal.h"
252b5132 70
4b78141a
NC
71
72/* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
73 we can obtain the H8 reloc numbers. We need these for the
74 get_reloc_size() function. We include h8.h again after defining
75 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
76
77#include "elf/h8.h"
78#undef _ELF_H8_H
79
80/* Undo the effects of #including reloc-macros.h. */
81
82#undef START_RELOC_NUMBERS
83#undef RELOC_NUMBER
84#undef FAKE_RELOC
85#undef EMPTY_RELOC
86#undef END_RELOC_NUMBERS
87#undef _RELOC_MACROS_H
88
252b5132
RH
89/* The following headers use the elf/reloc-macros.h file to
90 automatically generate relocation recognition functions
91 such as elf_mips_reloc_type() */
92
93#define RELOC_MACROS_GEN_FUNC
94
a06ea964 95#include "elf/aarch64.h"
252b5132 96#include "elf/alpha.h"
3b16e843 97#include "elf/arc.h"
252b5132 98#include "elf/arm.h"
3b16e843 99#include "elf/avr.h"
1d65ded4 100#include "elf/bfin.h"
60bca95a 101#include "elf/cr16.h"
3b16e843 102#include "elf/cris.h"
1c0d3aa6 103#include "elf/crx.h"
b8891f8d 104#include "elf/csky.h"
252b5132
RH
105#include "elf/d10v.h"
106#include "elf/d30v.h"
d172d4ba 107#include "elf/dlx.h"
aca4efc7 108#include "elf/bpf.h"
cfb8c092 109#include "elf/epiphany.h"
252b5132 110#include "elf/fr30.h"
5c70f934 111#include "elf/frv.h"
3f8107ab 112#include "elf/ft32.h"
3b16e843
NC
113#include "elf/h8.h"
114#include "elf/hppa.h"
115#include "elf/i386.h"
f954747f
AM
116#include "elf/i370.h"
117#include "elf/i860.h"
118#include "elf/i960.h"
3b16e843 119#include "elf/ia64.h"
1e4cf259 120#include "elf/ip2k.h"
84e94c90 121#include "elf/lm32.h"
1c0d3aa6 122#include "elf/iq2000.h"
49f58d10 123#include "elf/m32c.h"
3b16e843
NC
124#include "elf/m32r.h"
125#include "elf/m68k.h"
75751cd9 126#include "elf/m68hc11.h"
7b4ae824 127#include "elf/s12z.h"
252b5132 128#include "elf/mcore.h"
15ab5209 129#include "elf/mep.h"
a3c62988 130#include "elf/metag.h"
7ba29e2a 131#include "elf/microblaze.h"
3b16e843 132#include "elf/mips.h"
3c3bdf30 133#include "elf/mmix.h"
3b16e843
NC
134#include "elf/mn10200.h"
135#include "elf/mn10300.h"
5506d11a 136#include "elf/moxie.h"
4970f871 137#include "elf/mt.h"
2469cfa2 138#include "elf/msp430.h"
35c08157 139#include "elf/nds32.h"
fe944acf 140#include "elf/nfp.h"
13761a11 141#include "elf/nios2.h"
73589c9d 142#include "elf/or1k.h"
7d466069 143#include "elf/pj.h"
3b16e843 144#include "elf/ppc.h"
c833c019 145#include "elf/ppc64.h"
2b100bb5 146#include "elf/pru.h"
03336641 147#include "elf/riscv.h"
99c513f6 148#include "elf/rl78.h"
c7927a3c 149#include "elf/rx.h"
a85d7ed0 150#include "elf/s390.h"
1c0d3aa6 151#include "elf/score.h"
3b16e843
NC
152#include "elf/sh.h"
153#include "elf/sparc.h"
e9f53129 154#include "elf/spu.h"
40b36596 155#include "elf/tic6x.h"
aa137e4d
NC
156#include "elf/tilegx.h"
157#include "elf/tilepro.h"
3b16e843 158#include "elf/v850.h"
179d3252 159#include "elf/vax.h"
619ed720 160#include "elf/visium.h"
f96bd6c2 161#include "elf/wasm32.h"
3b16e843 162#include "elf/x86-64.h"
c29aca4a 163#include "elf/xc16x.h"
f6c1a2d5 164#include "elf/xgate.h"
93fbbb04 165#include "elf/xstormy16.h"
88da6820 166#include "elf/xtensa.h"
252b5132 167
252b5132 168#include "getopt.h"
566b0d53 169#include "libiberty.h"
09c11c86 170#include "safe-ctype.h"
2cf0635d 171#include "filenames.h"
252b5132 172
15b42fb0
AM
173#ifndef offsetof
174#define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
175#endif
176
6a40cf0c
NC
177typedef struct elf_section_list
178{
dda8d76d
NC
179 Elf_Internal_Shdr * hdr;
180 struct elf_section_list * next;
6a40cf0c
NC
181} elf_section_list;
182
dda8d76d
NC
183/* Flag bits indicating particular types of dump. */
184#define HEX_DUMP (1 << 0) /* The -x command line switch. */
185#define DISASS_DUMP (1 << 1) /* The -i command line switch. */
186#define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
187#define STRING_DUMP (1 << 3) /* The -p command line switch. */
188#define RELOC_DUMP (1 << 4) /* The -R command line switch. */
90bd5423 189#ifdef HAVE_LIBCTF
7d9813f1 190#define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
90bd5423 191#endif
dda8d76d
NC
192
193typedef unsigned char dump_type;
194
195/* A linked list of the section names for which dumps were requested. */
196struct dump_list_entry
197{
198 char * name;
199 dump_type type;
200 struct dump_list_entry * next;
201};
202
203typedef struct filedata
204{
205 const char * file_name;
206 FILE * handle;
207 bfd_size_type file_size;
208 Elf_Internal_Ehdr file_header;
209 Elf_Internal_Shdr * section_headers;
210 Elf_Internal_Phdr * program_headers;
211 char * string_table;
212 unsigned long string_table_length;
213 /* A dynamic array of flags indicating for which sections a dump of
214 some kind has been requested. It is reset on a per-object file
215 basis and then initialised from the cmdline_dump_sects array,
216 the results of interpreting the -w switch, and the
217 dump_sects_byname list. */
218 dump_type * dump_sects;
219 unsigned int num_dump_sects;
220} Filedata;
221
2cf0635d 222char * program_name = "readelf";
dda8d76d 223
c9c1d674 224static unsigned long archive_file_offset;
85b1c36d
BE
225static unsigned long archive_file_size;
226static unsigned long dynamic_addr;
227static bfd_size_type dynamic_size;
8b73c356 228static size_t dynamic_nent;
2cf0635d 229static char * dynamic_strings;
85b1c36d 230static unsigned long dynamic_strings_length;
85b1c36d 231static unsigned long num_dynamic_syms;
2cf0635d
NC
232static Elf_Internal_Sym * dynamic_symbols;
233static Elf_Internal_Syminfo * dynamic_syminfo;
85b1c36d
BE
234static unsigned long dynamic_syminfo_offset;
235static unsigned int dynamic_syminfo_nent;
f8eae8b2 236static char program_interpreter[PATH_MAX];
bb8a0291 237static bfd_vma dynamic_info[DT_ENCODING];
fdc90cb4 238static bfd_vma dynamic_info_DT_GNU_HASH;
85b1c36d 239static bfd_vma version_info[16];
2cf0635d 240static Elf_Internal_Dyn * dynamic_section;
6a40cf0c 241static elf_section_list * symtab_shndx_list;
32ec8896
NC
242static bfd_boolean show_name = FALSE;
243static bfd_boolean do_dynamic = FALSE;
244static bfd_boolean do_syms = FALSE;
245static bfd_boolean do_dyn_syms = FALSE;
246static bfd_boolean do_reloc = FALSE;
247static bfd_boolean do_sections = FALSE;
248static bfd_boolean do_section_groups = FALSE;
249static bfd_boolean do_section_details = FALSE;
250static bfd_boolean do_segments = FALSE;
251static bfd_boolean do_unwind = FALSE;
252static bfd_boolean do_using_dynamic = FALSE;
253static bfd_boolean do_header = FALSE;
254static bfd_boolean do_dump = FALSE;
255static bfd_boolean do_version = FALSE;
256static bfd_boolean do_histogram = FALSE;
257static bfd_boolean do_debugging = FALSE;
90bd5423 258#ifdef HAVE_LIBCTF
7d9813f1 259static bfd_boolean do_ctf = FALSE;
90bd5423 260#endif
32ec8896
NC
261static bfd_boolean do_arch = FALSE;
262static bfd_boolean do_notes = FALSE;
263static bfd_boolean do_archive_index = FALSE;
264static bfd_boolean is_32bit_elf = FALSE;
265static bfd_boolean decompress_dumps = FALSE;
252b5132 266
90bd5423 267#ifdef HAVE_LIBCTF
7d9813f1
NA
268static char *dump_ctf_parent_name;
269static char *dump_ctf_symtab_name;
270static char *dump_ctf_strtab_name;
90bd5423 271#endif
7d9813f1 272
e4b17d5c
L
273struct group_list
274{
dda8d76d
NC
275 struct group_list * next;
276 unsigned int section_index;
e4b17d5c
L
277};
278
279struct group
280{
dda8d76d
NC
281 struct group_list * root;
282 unsigned int group_index;
e4b17d5c
L
283};
284
dda8d76d
NC
285static size_t group_count;
286static struct group * section_groups;
287static struct group ** section_headers_groups;
aef1f6d0 288
09c11c86
NC
289/* A dynamic array of flags indicating for which sections a dump
290 has been requested via command line switches. */
dda8d76d 291static Filedata cmdline;
252b5132 292
dda8d76d 293static struct dump_list_entry * dump_sects_byname;
252b5132 294
c256ffe7 295/* How to print a vma value. */
843dd992
NC
296typedef enum print_mode
297{
298 HEX,
299 DEC,
300 DEC_5,
301 UNSIGNED,
302 PREFIX_HEX,
303 FULL_HEX,
304 LONG_HEX
305}
306print_mode;
307
bb4d2ac2
L
308/* Versioned symbol info. */
309enum versioned_symbol_info
310{
311 symbol_undefined,
312 symbol_hidden,
313 symbol_public
314};
315
32ec8896 316static const char * get_symbol_version_string
dda8d76d 317 (Filedata *, bfd_boolean, const char *, unsigned long, unsigned,
32ec8896 318 Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *);
bb4d2ac2 319
9c19a809
NC
320#define UNKNOWN -1
321
2b692964
NC
322#define SECTION_NAME(X) \
323 ((X) == NULL ? _("<none>") \
dda8d76d
NC
324 : filedata->string_table == NULL ? _("<no-strings>") \
325 : ((X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
326 : filedata->string_table + (X)->sh_name))
252b5132 327
ee42cf8c 328#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
252b5132 329
ba5cdace
NC
330#define GET_ELF_SYMBOLS(file, section, sym_count) \
331 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
332 : get_64bit_elf_symbols (file, section, sym_count))
9ea033b2 333
d79b3d50
NC
334#define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
335/* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
336 already been called and verified that the string exists. */
337#define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
18bd398b 338
61865e30
NC
339#define REMOVE_ARCH_BITS(ADDR) \
340 do \
341 { \
dda8d76d 342 if (filedata->file_header.e_machine == EM_ARM) \
61865e30
NC
343 (ADDR) &= ~1; \
344 } \
345 while (0)
d79b3d50 346\f
66cfc0fd
AM
347/* Print a BFD_VMA to an internal buffer, for use in error messages.
348 BFD_FMA_FMT can't be used in translated strings. */
349
350static const char *
351bfd_vmatoa (char *fmtch, bfd_vma value)
352{
353 /* bfd_vmatoa is used more then once in a printf call for output.
354 Cycle through an array of buffers. */
355 static int buf_pos = 0;
356 static struct bfd_vmatoa_buf
357 {
358 char place[64];
359 } buf[4];
360 char *ret;
361 char fmt[32];
362
363 ret = buf[buf_pos++].place;
364 buf_pos %= ARRAY_SIZE (buf);
365
366 sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
367 snprintf (ret, sizeof (buf[0].place), fmt, value);
368 return ret;
369}
370
dda8d76d
NC
371/* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
372 OFFSET + the offset of the current archive member, if we are examining an
373 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
374 allocate a buffer using malloc and fill that. In either case return the
375 pointer to the start of the retrieved data or NULL if something went wrong.
376 If something does go wrong and REASON is not NULL then emit an error
377 message using REASON as part of the context. */
59245841 378
c256ffe7 379static void *
dda8d76d
NC
380get_data (void * var,
381 Filedata * filedata,
382 unsigned long offset,
383 bfd_size_type size,
384 bfd_size_type nmemb,
385 const char * reason)
a6e9f9df 386{
2cf0635d 387 void * mvar;
57028622 388 bfd_size_type amt = size * nmemb;
a6e9f9df 389
c256ffe7 390 if (size == 0 || nmemb == 0)
a6e9f9df
AM
391 return NULL;
392
57028622
NC
393 /* If the size_t type is smaller than the bfd_size_type, eg because
394 you are building a 32-bit tool on a 64-bit host, then make sure
395 that when the sizes are cast to (size_t) no information is lost. */
396 if (sizeof (size_t) < sizeof (bfd_size_type)
397 && ( (bfd_size_type) ((size_t) size) != size
398 || (bfd_size_type) ((size_t) nmemb) != nmemb))
399 {
400 if (reason)
66cfc0fd
AM
401 error (_("Size truncation prevents reading %s"
402 " elements of size %s for %s\n"),
403 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
57028622
NC
404 return NULL;
405 }
406
407 /* Check for size overflow. */
408 if (amt < nmemb)
409 {
410 if (reason)
66cfc0fd
AM
411 error (_("Size overflow prevents reading %s"
412 " elements of size %s for %s\n"),
413 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
57028622
NC
414 return NULL;
415 }
416
c22b42ce 417 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
c9c1d674 418 attempting to allocate memory when the read is bound to fail. */
c22b42ce
AM
419 if (archive_file_offset > filedata->file_size
420 || offset > filedata->file_size - archive_file_offset
421 || amt > filedata->file_size - archive_file_offset - offset)
a6e9f9df 422 {
049b0c3a 423 if (reason)
66cfc0fd
AM
424 error (_("Reading %s bytes extends past end of file for %s\n"),
425 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
426 return NULL;
427 }
428
dda8d76d 429 if (fseek (filedata->handle, archive_file_offset + offset, SEEK_SET))
071436c6
NC
430 {
431 if (reason)
c9c1d674 432 error (_("Unable to seek to 0x%lx for %s\n"),
ed754a13 433 archive_file_offset + offset, reason);
071436c6
NC
434 return NULL;
435 }
436
a6e9f9df
AM
437 mvar = var;
438 if (mvar == NULL)
439 {
c256ffe7 440 /* Check for overflow. */
57028622 441 if (nmemb < (~(bfd_size_type) 0 - 1) / size)
c256ffe7 442 /* + 1 so that we can '\0' terminate invalid string table sections. */
57028622 443 mvar = malloc ((size_t) amt + 1);
a6e9f9df
AM
444
445 if (mvar == NULL)
446 {
049b0c3a 447 if (reason)
66cfc0fd
AM
448 error (_("Out of memory allocating %s bytes for %s\n"),
449 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
450 return NULL;
451 }
c256ffe7 452
c9c1d674 453 ((char *) mvar)[amt] = '\0';
a6e9f9df
AM
454 }
455
dda8d76d 456 if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb)
a6e9f9df 457 {
049b0c3a 458 if (reason)
66cfc0fd
AM
459 error (_("Unable to read in %s bytes of %s\n"),
460 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
461 if (mvar != var)
462 free (mvar);
463 return NULL;
464 }
465
466 return mvar;
467}
468
32ec8896
NC
469/* Print a VMA value in the MODE specified.
470 Returns the number of characters displayed. */
cb8f3167 471
32ec8896 472static unsigned int
14a91970 473print_vma (bfd_vma vma, print_mode mode)
66543521 474{
32ec8896 475 unsigned int nc = 0;
66543521 476
14a91970 477 switch (mode)
66543521 478 {
14a91970
AM
479 case FULL_HEX:
480 nc = printf ("0x");
1a0670f3 481 /* Fall through. */
14a91970 482 case LONG_HEX:
f7a99963 483#ifdef BFD64
14a91970 484 if (is_32bit_elf)
437c2fb7 485 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
f7a99963 486#endif
14a91970
AM
487 printf_vma (vma);
488 return nc + 16;
b19aac67 489
14a91970
AM
490 case DEC_5:
491 if (vma <= 99999)
492 return printf ("%5" BFD_VMA_FMT "d", vma);
1a0670f3 493 /* Fall through. */
14a91970
AM
494 case PREFIX_HEX:
495 nc = printf ("0x");
1a0670f3 496 /* Fall through. */
14a91970
AM
497 case HEX:
498 return nc + printf ("%" BFD_VMA_FMT "x", vma);
b19aac67 499
14a91970
AM
500 case DEC:
501 return printf ("%" BFD_VMA_FMT "d", vma);
b19aac67 502
14a91970
AM
503 case UNSIGNED:
504 return printf ("%" BFD_VMA_FMT "u", vma);
32ec8896
NC
505
506 default:
507 /* FIXME: Report unrecognised mode ? */
508 return 0;
f7a99963 509 }
f7a99963
NC
510}
511
7bfd842d 512/* Display a symbol on stdout. Handles the display of control characters and
3bfcb652 513 multibye characters (assuming the host environment supports them).
31104126 514
7bfd842d
NC
515 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
516
517 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
518 padding as necessary.
171191ba
NC
519
520 Returns the number of emitted characters. */
521
522static unsigned int
32ec8896 523print_symbol (signed int width, const char *symbol)
31104126 524{
171191ba 525 bfd_boolean extra_padding = FALSE;
32ec8896 526 signed int num_printed = 0;
3bfcb652 527#ifdef HAVE_MBSTATE_T
7bfd842d 528 mbstate_t state;
3bfcb652 529#endif
32ec8896 530 unsigned int width_remaining;
961c521f 531
7bfd842d 532 if (width < 0)
961c521f 533 {
88305e1b 534 /* Keep the width positive. This helps the code below. */
961c521f 535 width = - width;
171191ba 536 extra_padding = TRUE;
0b4362b0 537 }
56d8f8a9
NC
538 else if (width == 0)
539 return 0;
961c521f 540
7bfd842d
NC
541 if (do_wide)
542 /* Set the remaining width to a very large value.
543 This simplifies the code below. */
544 width_remaining = INT_MAX;
545 else
546 width_remaining = width;
cb8f3167 547
3bfcb652 548#ifdef HAVE_MBSTATE_T
7bfd842d
NC
549 /* Initialise the multibyte conversion state. */
550 memset (& state, 0, sizeof (state));
3bfcb652 551#endif
961c521f 552
7bfd842d
NC
553 while (width_remaining)
554 {
555 size_t n;
7bfd842d 556 const char c = *symbol++;
961c521f 557
7bfd842d 558 if (c == 0)
961c521f
NC
559 break;
560
7bfd842d
NC
561 /* Do not print control characters directly as they can affect terminal
562 settings. Such characters usually appear in the names generated
563 by the assembler for local labels. */
564 if (ISCNTRL (c))
961c521f 565 {
7bfd842d 566 if (width_remaining < 2)
961c521f
NC
567 break;
568
7bfd842d
NC
569 printf ("^%c", c + 0x40);
570 width_remaining -= 2;
171191ba 571 num_printed += 2;
961c521f 572 }
7bfd842d
NC
573 else if (ISPRINT (c))
574 {
575 putchar (c);
576 width_remaining --;
577 num_printed ++;
578 }
961c521f
NC
579 else
580 {
3bfcb652
NC
581#ifdef HAVE_MBSTATE_T
582 wchar_t w;
583#endif
7bfd842d
NC
584 /* Let printf do the hard work of displaying multibyte characters. */
585 printf ("%.1s", symbol - 1);
586 width_remaining --;
587 num_printed ++;
588
3bfcb652 589#ifdef HAVE_MBSTATE_T
7bfd842d
NC
590 /* Try to find out how many bytes made up the character that was
591 just printed. Advance the symbol pointer past the bytes that
592 were displayed. */
593 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
3bfcb652
NC
594#else
595 n = 1;
596#endif
7bfd842d
NC
597 if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
598 symbol += (n - 1);
961c521f 599 }
961c521f 600 }
171191ba 601
7bfd842d 602 if (extra_padding && num_printed < width)
171191ba
NC
603 {
604 /* Fill in the remaining spaces. */
7bfd842d
NC
605 printf ("%-*s", width - num_printed, " ");
606 num_printed = width;
171191ba
NC
607 }
608
609 return num_printed;
31104126
NC
610}
611
1449284b 612/* Returns a pointer to a static buffer containing a printable version of
74e1a04b
NC
613 the given section's name. Like print_symbol, except that it does not try
614 to print multibyte characters, it just interprets them as hex values. */
615
616static const char *
dda8d76d 617printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec)
74e1a04b
NC
618{
619#define MAX_PRINT_SEC_NAME_LEN 128
620 static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
621 const char * name = SECTION_NAME (sec);
622 char * buf = sec_name_buf;
623 char c;
624 unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
625
626 while ((c = * name ++) != 0)
627 {
628 if (ISCNTRL (c))
629 {
630 if (remaining < 2)
631 break;
948f632f 632
74e1a04b
NC
633 * buf ++ = '^';
634 * buf ++ = c + 0x40;
635 remaining -= 2;
636 }
637 else if (ISPRINT (c))
638 {
639 * buf ++ = c;
640 remaining -= 1;
641 }
642 else
643 {
644 static char hex[17] = "0123456789ABCDEF";
645
646 if (remaining < 4)
647 break;
648 * buf ++ = '<';
649 * buf ++ = hex[(c & 0xf0) >> 4];
650 * buf ++ = hex[c & 0x0f];
651 * buf ++ = '>';
652 remaining -= 4;
653 }
654
655 if (remaining == 0)
656 break;
657 }
658
659 * buf = 0;
660 return sec_name_buf;
661}
662
663static const char *
dda8d76d 664printable_section_name_from_index (Filedata * filedata, unsigned long ndx)
74e1a04b 665{
dda8d76d 666 if (ndx >= filedata->file_header.e_shnum)
74e1a04b
NC
667 return _("<corrupt>");
668
dda8d76d 669 return printable_section_name (filedata, filedata->section_headers + ndx);
74e1a04b
NC
670}
671
89fac5e3
RS
672/* Return a pointer to section NAME, or NULL if no such section exists. */
673
674static Elf_Internal_Shdr *
dda8d76d 675find_section (Filedata * filedata, const char * name)
89fac5e3
RS
676{
677 unsigned int i;
678
68807c3c
NC
679 if (filedata->section_headers == NULL)
680 return NULL;
dda8d76d
NC
681
682 for (i = 0; i < filedata->file_header.e_shnum; i++)
683 if (streq (SECTION_NAME (filedata->section_headers + i), name))
684 return filedata->section_headers + i;
89fac5e3
RS
685
686 return NULL;
687}
688
0b6ae522
DJ
689/* Return a pointer to a section containing ADDR, or NULL if no such
690 section exists. */
691
692static Elf_Internal_Shdr *
dda8d76d 693find_section_by_address (Filedata * filedata, bfd_vma addr)
0b6ae522
DJ
694{
695 unsigned int i;
696
68807c3c
NC
697 if (filedata->section_headers == NULL)
698 return NULL;
699
dda8d76d 700 for (i = 0; i < filedata->file_header.e_shnum; i++)
0b6ae522 701 {
dda8d76d
NC
702 Elf_Internal_Shdr *sec = filedata->section_headers + i;
703
0b6ae522
DJ
704 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
705 return sec;
706 }
707
708 return NULL;
709}
710
071436c6 711static Elf_Internal_Shdr *
dda8d76d 712find_section_by_type (Filedata * filedata, unsigned int type)
071436c6
NC
713{
714 unsigned int i;
715
68807c3c
NC
716 if (filedata->section_headers == NULL)
717 return NULL;
718
dda8d76d 719 for (i = 0; i < filedata->file_header.e_shnum; i++)
071436c6 720 {
dda8d76d
NC
721 Elf_Internal_Shdr *sec = filedata->section_headers + i;
722
071436c6
NC
723 if (sec->sh_type == type)
724 return sec;
725 }
726
727 return NULL;
728}
729
657d0d47
CC
730/* Return a pointer to section NAME, or NULL if no such section exists,
731 restricted to the list of sections given in SET. */
732
733static Elf_Internal_Shdr *
dda8d76d 734find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
657d0d47
CC
735{
736 unsigned int i;
737
68807c3c
NC
738 if (filedata->section_headers == NULL)
739 return NULL;
740
657d0d47
CC
741 if (set != NULL)
742 {
743 while ((i = *set++) > 0)
b814a36d
NC
744 {
745 /* See PR 21156 for a reproducer. */
dda8d76d 746 if (i >= filedata->file_header.e_shnum)
b814a36d
NC
747 continue; /* FIXME: Should we issue an error message ? */
748
dda8d76d
NC
749 if (streq (SECTION_NAME (filedata->section_headers + i), name))
750 return filedata->section_headers + i;
b814a36d 751 }
657d0d47
CC
752 }
753
dda8d76d 754 return find_section (filedata, name);
657d0d47
CC
755}
756
32ec8896
NC
757/* Read an unsigned LEB128 encoded value from DATA.
758 Set *LENGTH_RETURN to the number of bytes read. */
0b6ae522 759
f6f0e17b 760static inline unsigned long
32ec8896
NC
761read_uleb128 (unsigned char * data,
762 unsigned int * length_return,
f6f0e17b 763 const unsigned char * const end)
0b6ae522 764{
f6f0e17b 765 return read_leb128 (data, length_return, FALSE, end);
0b6ae522
DJ
766}
767
32ec8896 768/* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
28f997cf
TG
769 This OS has so many departures from the ELF standard that we test it at
770 many places. */
771
32ec8896 772static inline bfd_boolean
dda8d76d 773is_ia64_vms (Filedata * filedata)
28f997cf 774{
dda8d76d
NC
775 return filedata->file_header.e_machine == EM_IA_64
776 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
28f997cf
TG
777}
778
bcedfee6 779/* Guess the relocation size commonly used by the specific machines. */
252b5132 780
32ec8896 781static bfd_boolean
2dc4cec1 782guess_is_rela (unsigned int e_machine)
252b5132 783{
9c19a809 784 switch (e_machine)
252b5132
RH
785 {
786 /* Targets that use REL relocations. */
252b5132 787 case EM_386:
22abe556 788 case EM_IAMCU:
f954747f 789 case EM_960:
e9f53129 790 case EM_ARM:
2b0337b0 791 case EM_D10V:
252b5132 792 case EM_CYGNUS_D10V:
e9f53129 793 case EM_DLX:
252b5132 794 case EM_MIPS:
4fe85591 795 case EM_MIPS_RS3_LE:
e9f53129 796 case EM_CYGNUS_M32R:
1c0d3aa6 797 case EM_SCORE:
f6c1a2d5 798 case EM_XGATE:
fe944acf 799 case EM_NFP:
aca4efc7 800 case EM_BPF:
9c19a809 801 return FALSE;
103f02d3 802
252b5132
RH
803 /* Targets that use RELA relocations. */
804 case EM_68K:
f954747f 805 case EM_860:
a06ea964 806 case EM_AARCH64:
cfb8c092 807 case EM_ADAPTEVA_EPIPHANY:
e9f53129
AM
808 case EM_ALPHA:
809 case EM_ALTERA_NIOS2:
886a2506
NC
810 case EM_ARC:
811 case EM_ARC_COMPACT:
812 case EM_ARC_COMPACT2:
e9f53129
AM
813 case EM_AVR:
814 case EM_AVR_OLD:
815 case EM_BLACKFIN:
60bca95a 816 case EM_CR16:
e9f53129
AM
817 case EM_CRIS:
818 case EM_CRX:
b8891f8d 819 case EM_CSKY:
2b0337b0 820 case EM_D30V:
252b5132 821 case EM_CYGNUS_D30V:
2b0337b0 822 case EM_FR30:
3f8107ab 823 case EM_FT32:
252b5132 824 case EM_CYGNUS_FR30:
5c70f934 825 case EM_CYGNUS_FRV:
e9f53129
AM
826 case EM_H8S:
827 case EM_H8_300:
828 case EM_H8_300H:
800eeca4 829 case EM_IA_64:
1e4cf259
NC
830 case EM_IP2K:
831 case EM_IP2K_OLD:
3b36097d 832 case EM_IQ2000:
84e94c90 833 case EM_LATTICEMICO32:
ff7eeb89 834 case EM_M32C_OLD:
49f58d10 835 case EM_M32C:
e9f53129
AM
836 case EM_M32R:
837 case EM_MCORE:
15ab5209 838 case EM_CYGNUS_MEP:
a3c62988 839 case EM_METAG:
e9f53129
AM
840 case EM_MMIX:
841 case EM_MN10200:
842 case EM_CYGNUS_MN10200:
843 case EM_MN10300:
844 case EM_CYGNUS_MN10300:
5506d11a 845 case EM_MOXIE:
e9f53129
AM
846 case EM_MSP430:
847 case EM_MSP430_OLD:
d031aafb 848 case EM_MT:
35c08157 849 case EM_NDS32:
64fd6348 850 case EM_NIOS32:
73589c9d 851 case EM_OR1K:
e9f53129
AM
852 case EM_PPC64:
853 case EM_PPC:
2b100bb5 854 case EM_TI_PRU:
e23eba97 855 case EM_RISCV:
99c513f6 856 case EM_RL78:
c7927a3c 857 case EM_RX:
e9f53129
AM
858 case EM_S390:
859 case EM_S390_OLD:
860 case EM_SH:
861 case EM_SPARC:
862 case EM_SPARC32PLUS:
863 case EM_SPARCV9:
864 case EM_SPU:
40b36596 865 case EM_TI_C6000:
aa137e4d
NC
866 case EM_TILEGX:
867 case EM_TILEPRO:
708e2187 868 case EM_V800:
e9f53129
AM
869 case EM_V850:
870 case EM_CYGNUS_V850:
871 case EM_VAX:
619ed720 872 case EM_VISIUM:
e9f53129 873 case EM_X86_64:
8a9036a4 874 case EM_L1OM:
7a9068fe 875 case EM_K1OM:
e9f53129
AM
876 case EM_XSTORMY16:
877 case EM_XTENSA:
878 case EM_XTENSA_OLD:
7ba29e2a
NC
879 case EM_MICROBLAZE:
880 case EM_MICROBLAZE_OLD:
f96bd6c2 881 case EM_WEBASSEMBLY:
9c19a809 882 return TRUE;
103f02d3 883
e9f53129
AM
884 case EM_68HC05:
885 case EM_68HC08:
886 case EM_68HC11:
887 case EM_68HC16:
888 case EM_FX66:
889 case EM_ME16:
d1133906 890 case EM_MMA:
d1133906
NC
891 case EM_NCPU:
892 case EM_NDR1:
e9f53129 893 case EM_PCP:
d1133906 894 case EM_ST100:
e9f53129 895 case EM_ST19:
d1133906 896 case EM_ST7:
e9f53129
AM
897 case EM_ST9PLUS:
898 case EM_STARCORE:
d1133906 899 case EM_SVX:
e9f53129 900 case EM_TINYJ:
9c19a809
NC
901 default:
902 warn (_("Don't know about relocations on this machine architecture\n"));
903 return FALSE;
904 }
905}
252b5132 906
dda8d76d 907/* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
32ec8896
NC
908 Returns TRUE upon success, FALSE otherwise. If successful then a
909 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
910 and the number of relocs loaded is placed in *NRELASP. It is the caller's
911 responsibility to free the allocated buffer. */
912
913static bfd_boolean
dda8d76d
NC
914slurp_rela_relocs (Filedata * filedata,
915 unsigned long rel_offset,
916 unsigned long rel_size,
917 Elf_Internal_Rela ** relasp,
918 unsigned long * nrelasp)
9c19a809 919{
2cf0635d 920 Elf_Internal_Rela * relas;
8b73c356 921 size_t nrelas;
4d6ed7c8 922 unsigned int i;
252b5132 923
4d6ed7c8
NC
924 if (is_32bit_elf)
925 {
2cf0635d 926 Elf32_External_Rela * erelas;
103f02d3 927
dda8d76d 928 erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 929 rel_size, _("32-bit relocation data"));
a6e9f9df 930 if (!erelas)
32ec8896 931 return FALSE;
252b5132 932
4d6ed7c8 933 nrelas = rel_size / sizeof (Elf32_External_Rela);
103f02d3 934
3f5e193b
NC
935 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
936 sizeof (Elf_Internal_Rela));
103f02d3 937
4d6ed7c8
NC
938 if (relas == NULL)
939 {
c256ffe7 940 free (erelas);
591a748a 941 error (_("out of memory parsing relocs\n"));
32ec8896 942 return FALSE;
4d6ed7c8 943 }
103f02d3 944
4d6ed7c8
NC
945 for (i = 0; i < nrelas; i++)
946 {
947 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
948 relas[i].r_info = BYTE_GET (erelas[i].r_info);
598aaa76 949 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
4d6ed7c8 950 }
103f02d3 951
4d6ed7c8
NC
952 free (erelas);
953 }
954 else
955 {
2cf0635d 956 Elf64_External_Rela * erelas;
103f02d3 957
dda8d76d 958 erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 959 rel_size, _("64-bit relocation data"));
a6e9f9df 960 if (!erelas)
32ec8896 961 return FALSE;
4d6ed7c8
NC
962
963 nrelas = rel_size / sizeof (Elf64_External_Rela);
103f02d3 964
3f5e193b
NC
965 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
966 sizeof (Elf_Internal_Rela));
103f02d3 967
4d6ed7c8
NC
968 if (relas == NULL)
969 {
c256ffe7 970 free (erelas);
591a748a 971 error (_("out of memory parsing relocs\n"));
32ec8896 972 return FALSE;
9c19a809 973 }
4d6ed7c8
NC
974
975 for (i = 0; i < nrelas; i++)
9c19a809 976 {
66543521
AM
977 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
978 relas[i].r_info = BYTE_GET (erelas[i].r_info);
598aaa76 979 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
861fb55a
DJ
980
981 /* The #ifdef BFD64 below is to prevent a compile time
982 warning. We know that if we do not have a 64 bit data
983 type that we will never execute this code anyway. */
984#ifdef BFD64
dda8d76d
NC
985 if (filedata->file_header.e_machine == EM_MIPS
986 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
861fb55a
DJ
987 {
988 /* In little-endian objects, r_info isn't really a
989 64-bit little-endian value: it has a 32-bit
990 little-endian symbol index followed by four
991 individual byte fields. Reorder INFO
992 accordingly. */
91d6fa6a
NC
993 bfd_vma inf = relas[i].r_info;
994 inf = (((inf & 0xffffffff) << 32)
995 | ((inf >> 56) & 0xff)
996 | ((inf >> 40) & 0xff00)
997 | ((inf >> 24) & 0xff0000)
998 | ((inf >> 8) & 0xff000000));
999 relas[i].r_info = inf;
861fb55a
DJ
1000 }
1001#endif /* BFD64 */
4d6ed7c8 1002 }
103f02d3 1003
4d6ed7c8
NC
1004 free (erelas);
1005 }
32ec8896 1006
4d6ed7c8
NC
1007 *relasp = relas;
1008 *nrelasp = nrelas;
32ec8896 1009 return TRUE;
4d6ed7c8 1010}
103f02d3 1011
dda8d76d 1012/* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
32ec8896
NC
1013 Returns TRUE upon success, FALSE otherwise. If successful then a
1014 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1015 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1016 responsibility to free the allocated buffer. */
1017
1018static bfd_boolean
dda8d76d
NC
1019slurp_rel_relocs (Filedata * filedata,
1020 unsigned long rel_offset,
1021 unsigned long rel_size,
1022 Elf_Internal_Rela ** relsp,
1023 unsigned long * nrelsp)
4d6ed7c8 1024{
2cf0635d 1025 Elf_Internal_Rela * rels;
8b73c356 1026 size_t nrels;
4d6ed7c8 1027 unsigned int i;
103f02d3 1028
4d6ed7c8
NC
1029 if (is_32bit_elf)
1030 {
2cf0635d 1031 Elf32_External_Rel * erels;
103f02d3 1032
dda8d76d 1033 erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 1034 rel_size, _("32-bit relocation data"));
a6e9f9df 1035 if (!erels)
32ec8896 1036 return FALSE;
103f02d3 1037
4d6ed7c8 1038 nrels = rel_size / sizeof (Elf32_External_Rel);
103f02d3 1039
3f5e193b 1040 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
103f02d3 1041
4d6ed7c8
NC
1042 if (rels == NULL)
1043 {
c256ffe7 1044 free (erels);
591a748a 1045 error (_("out of memory parsing relocs\n"));
32ec8896 1046 return FALSE;
4d6ed7c8
NC
1047 }
1048
1049 for (i = 0; i < nrels; i++)
1050 {
1051 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1052 rels[i].r_info = BYTE_GET (erels[i].r_info);
c8286bd1 1053 rels[i].r_addend = 0;
9ea033b2 1054 }
4d6ed7c8
NC
1055
1056 free (erels);
9c19a809
NC
1057 }
1058 else
1059 {
2cf0635d 1060 Elf64_External_Rel * erels;
9ea033b2 1061
dda8d76d 1062 erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 1063 rel_size, _("64-bit relocation data"));
a6e9f9df 1064 if (!erels)
32ec8896 1065 return FALSE;
103f02d3 1066
4d6ed7c8 1067 nrels = rel_size / sizeof (Elf64_External_Rel);
103f02d3 1068
3f5e193b 1069 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
103f02d3 1070
4d6ed7c8 1071 if (rels == NULL)
9c19a809 1072 {
c256ffe7 1073 free (erels);
591a748a 1074 error (_("out of memory parsing relocs\n"));
32ec8896 1075 return FALSE;
4d6ed7c8 1076 }
103f02d3 1077
4d6ed7c8
NC
1078 for (i = 0; i < nrels; i++)
1079 {
66543521
AM
1080 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1081 rels[i].r_info = BYTE_GET (erels[i].r_info);
c8286bd1 1082 rels[i].r_addend = 0;
861fb55a
DJ
1083
1084 /* The #ifdef BFD64 below is to prevent a compile time
1085 warning. We know that if we do not have a 64 bit data
1086 type that we will never execute this code anyway. */
1087#ifdef BFD64
dda8d76d
NC
1088 if (filedata->file_header.e_machine == EM_MIPS
1089 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
861fb55a
DJ
1090 {
1091 /* In little-endian objects, r_info isn't really a
1092 64-bit little-endian value: it has a 32-bit
1093 little-endian symbol index followed by four
1094 individual byte fields. Reorder INFO
1095 accordingly. */
91d6fa6a
NC
1096 bfd_vma inf = rels[i].r_info;
1097 inf = (((inf & 0xffffffff) << 32)
1098 | ((inf >> 56) & 0xff)
1099 | ((inf >> 40) & 0xff00)
1100 | ((inf >> 24) & 0xff0000)
1101 | ((inf >> 8) & 0xff000000));
1102 rels[i].r_info = inf;
861fb55a
DJ
1103 }
1104#endif /* BFD64 */
4d6ed7c8 1105 }
103f02d3 1106
4d6ed7c8
NC
1107 free (erels);
1108 }
32ec8896 1109
4d6ed7c8
NC
1110 *relsp = rels;
1111 *nrelsp = nrels;
32ec8896 1112 return TRUE;
4d6ed7c8 1113}
103f02d3 1114
aca88567
NC
1115/* Returns the reloc type extracted from the reloc info field. */
1116
1117static unsigned int
dda8d76d 1118get_reloc_type (Filedata * filedata, bfd_vma reloc_info)
aca88567
NC
1119{
1120 if (is_32bit_elf)
1121 return ELF32_R_TYPE (reloc_info);
1122
dda8d76d 1123 switch (filedata->file_header.e_machine)
aca88567
NC
1124 {
1125 case EM_MIPS:
1126 /* Note: We assume that reloc_info has already been adjusted for us. */
1127 return ELF64_MIPS_R_TYPE (reloc_info);
1128
1129 case EM_SPARCV9:
1130 return ELF64_R_TYPE_ID (reloc_info);
1131
1132 default:
1133 return ELF64_R_TYPE (reloc_info);
1134 }
1135}
1136
1137/* Return the symbol index extracted from the reloc info field. */
1138
1139static bfd_vma
1140get_reloc_symindex (bfd_vma reloc_info)
1141{
1142 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
1143}
1144
13761a11 1145static inline bfd_boolean
dda8d76d 1146uses_msp430x_relocs (Filedata * filedata)
13761a11
NC
1147{
1148 return
dda8d76d 1149 filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */
13761a11 1150 /* GCC uses osabi == ELFOSBI_STANDALONE. */
dda8d76d 1151 && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
13761a11 1152 /* TI compiler uses ELFOSABI_NONE. */
dda8d76d 1153 || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
13761a11
NC
1154}
1155
d3ba0551
AM
1156/* Display the contents of the relocation data found at the specified
1157 offset. */
ee42cf8c 1158
32ec8896 1159static bfd_boolean
dda8d76d
NC
1160dump_relocations (Filedata * filedata,
1161 unsigned long rel_offset,
1162 unsigned long rel_size,
1163 Elf_Internal_Sym * symtab,
1164 unsigned long nsyms,
1165 char * strtab,
1166 unsigned long strtablen,
1167 int is_rela,
1168 bfd_boolean is_dynsym)
4d6ed7c8 1169{
32ec8896 1170 unsigned long i;
2cf0635d 1171 Elf_Internal_Rela * rels;
32ec8896 1172 bfd_boolean res = TRUE;
103f02d3 1173
4d6ed7c8 1174 if (is_rela == UNKNOWN)
dda8d76d 1175 is_rela = guess_is_rela (filedata->file_header.e_machine);
103f02d3 1176
4d6ed7c8
NC
1177 if (is_rela)
1178 {
dda8d76d 1179 if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
32ec8896 1180 return FALSE;
4d6ed7c8
NC
1181 }
1182 else
1183 {
dda8d76d 1184 if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
32ec8896 1185 return FALSE;
252b5132
RH
1186 }
1187
410f7a12
L
1188 if (is_32bit_elf)
1189 {
1190 if (is_rela)
2c71103e
NC
1191 {
1192 if (do_wide)
1193 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1194 else
1195 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1196 }
410f7a12 1197 else
2c71103e
NC
1198 {
1199 if (do_wide)
1200 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1201 else
1202 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1203 }
410f7a12 1204 }
252b5132 1205 else
410f7a12
L
1206 {
1207 if (is_rela)
2c71103e
NC
1208 {
1209 if (do_wide)
8beeaeb7 1210 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
2c71103e
NC
1211 else
1212 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1213 }
410f7a12 1214 else
2c71103e
NC
1215 {
1216 if (do_wide)
8beeaeb7 1217 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
2c71103e
NC
1218 else
1219 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1220 }
410f7a12 1221 }
252b5132
RH
1222
1223 for (i = 0; i < rel_size; i++)
1224 {
2cf0635d 1225 const char * rtype;
b34976b6 1226 bfd_vma offset;
91d6fa6a 1227 bfd_vma inf;
b34976b6
AM
1228 bfd_vma symtab_index;
1229 bfd_vma type;
103f02d3 1230
b34976b6 1231 offset = rels[i].r_offset;
91d6fa6a 1232 inf = rels[i].r_info;
103f02d3 1233
dda8d76d 1234 type = get_reloc_type (filedata, inf);
91d6fa6a 1235 symtab_index = get_reloc_symindex (inf);
252b5132 1236
410f7a12
L
1237 if (is_32bit_elf)
1238 {
39dbeff8
AM
1239 printf ("%8.8lx %8.8lx ",
1240 (unsigned long) offset & 0xffffffff,
91d6fa6a 1241 (unsigned long) inf & 0xffffffff);
410f7a12
L
1242 }
1243 else
1244 {
39dbeff8
AM
1245#if BFD_HOST_64BIT_LONG
1246 printf (do_wide
1247 ? "%16.16lx %16.16lx "
1248 : "%12.12lx %12.12lx ",
91d6fa6a 1249 offset, inf);
39dbeff8 1250#elif BFD_HOST_64BIT_LONG_LONG
6e3d6dc1 1251#ifndef __MSVCRT__
39dbeff8
AM
1252 printf (do_wide
1253 ? "%16.16llx %16.16llx "
1254 : "%12.12llx %12.12llx ",
91d6fa6a 1255 offset, inf);
6e3d6dc1
NC
1256#else
1257 printf (do_wide
1258 ? "%16.16I64x %16.16I64x "
1259 : "%12.12I64x %12.12I64x ",
91d6fa6a 1260 offset, inf);
6e3d6dc1 1261#endif
39dbeff8 1262#else
2c71103e
NC
1263 printf (do_wide
1264 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1265 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
410f7a12
L
1266 _bfd_int64_high (offset),
1267 _bfd_int64_low (offset),
91d6fa6a
NC
1268 _bfd_int64_high (inf),
1269 _bfd_int64_low (inf));
9ea033b2 1270#endif
410f7a12 1271 }
103f02d3 1272
dda8d76d 1273 switch (filedata->file_header.e_machine)
252b5132
RH
1274 {
1275 default:
1276 rtype = NULL;
1277 break;
1278
a06ea964
NC
1279 case EM_AARCH64:
1280 rtype = elf_aarch64_reloc_type (type);
1281 break;
1282
2b0337b0 1283 case EM_M32R:
252b5132 1284 case EM_CYGNUS_M32R:
9ea033b2 1285 rtype = elf_m32r_reloc_type (type);
252b5132
RH
1286 break;
1287
1288 case EM_386:
22abe556 1289 case EM_IAMCU:
9ea033b2 1290 rtype = elf_i386_reloc_type (type);
252b5132
RH
1291 break;
1292
ba2685cc
AM
1293 case EM_68HC11:
1294 case EM_68HC12:
1295 rtype = elf_m68hc11_reloc_type (type);
1296 break;
75751cd9 1297
7b4ae824
JD
1298 case EM_S12Z:
1299 rtype = elf_s12z_reloc_type (type);
1300 break;
1301
252b5132 1302 case EM_68K:
9ea033b2 1303 rtype = elf_m68k_reloc_type (type);
252b5132
RH
1304 break;
1305
f954747f
AM
1306 case EM_960:
1307 rtype = elf_i960_reloc_type (type);
1308 break;
1309
adde6300 1310 case EM_AVR:
2b0337b0 1311 case EM_AVR_OLD:
adde6300
AM
1312 rtype = elf_avr_reloc_type (type);
1313 break;
1314
9ea033b2
NC
1315 case EM_OLD_SPARCV9:
1316 case EM_SPARC32PLUS:
1317 case EM_SPARCV9:
252b5132 1318 case EM_SPARC:
9ea033b2 1319 rtype = elf_sparc_reloc_type (type);
252b5132
RH
1320 break;
1321
e9f53129
AM
1322 case EM_SPU:
1323 rtype = elf_spu_reloc_type (type);
1324 break;
1325
708e2187
NC
1326 case EM_V800:
1327 rtype = v800_reloc_type (type);
1328 break;
2b0337b0 1329 case EM_V850:
252b5132 1330 case EM_CYGNUS_V850:
9ea033b2 1331 rtype = v850_reloc_type (type);
252b5132
RH
1332 break;
1333
2b0337b0 1334 case EM_D10V:
252b5132 1335 case EM_CYGNUS_D10V:
9ea033b2 1336 rtype = elf_d10v_reloc_type (type);
252b5132
RH
1337 break;
1338
2b0337b0 1339 case EM_D30V:
252b5132 1340 case EM_CYGNUS_D30V:
9ea033b2 1341 rtype = elf_d30v_reloc_type (type);
252b5132
RH
1342 break;
1343
d172d4ba
NC
1344 case EM_DLX:
1345 rtype = elf_dlx_reloc_type (type);
1346 break;
1347
252b5132 1348 case EM_SH:
9ea033b2 1349 rtype = elf_sh_reloc_type (type);
252b5132
RH
1350 break;
1351
2b0337b0 1352 case EM_MN10300:
252b5132 1353 case EM_CYGNUS_MN10300:
9ea033b2 1354 rtype = elf_mn10300_reloc_type (type);
252b5132
RH
1355 break;
1356
2b0337b0 1357 case EM_MN10200:
252b5132 1358 case EM_CYGNUS_MN10200:
9ea033b2 1359 rtype = elf_mn10200_reloc_type (type);
252b5132
RH
1360 break;
1361
2b0337b0 1362 case EM_FR30:
252b5132 1363 case EM_CYGNUS_FR30:
9ea033b2 1364 rtype = elf_fr30_reloc_type (type);
252b5132
RH
1365 break;
1366
ba2685cc
AM
1367 case EM_CYGNUS_FRV:
1368 rtype = elf_frv_reloc_type (type);
1369 break;
5c70f934 1370
b8891f8d
AJ
1371 case EM_CSKY:
1372 rtype = elf_csky_reloc_type (type);
1373 break;
1374
3f8107ab
AM
1375 case EM_FT32:
1376 rtype = elf_ft32_reloc_type (type);
1377 break;
1378
252b5132 1379 case EM_MCORE:
9ea033b2 1380 rtype = elf_mcore_reloc_type (type);
252b5132
RH
1381 break;
1382
3c3bdf30
NC
1383 case EM_MMIX:
1384 rtype = elf_mmix_reloc_type (type);
1385 break;
1386
5506d11a
AM
1387 case EM_MOXIE:
1388 rtype = elf_moxie_reloc_type (type);
1389 break;
1390
2469cfa2 1391 case EM_MSP430:
dda8d76d 1392 if (uses_msp430x_relocs (filedata))
13761a11
NC
1393 {
1394 rtype = elf_msp430x_reloc_type (type);
1395 break;
1396 }
1a0670f3 1397 /* Fall through. */
2469cfa2
NC
1398 case EM_MSP430_OLD:
1399 rtype = elf_msp430_reloc_type (type);
1400 break;
1401
35c08157
KLC
1402 case EM_NDS32:
1403 rtype = elf_nds32_reloc_type (type);
1404 break;
1405
252b5132 1406 case EM_PPC:
9ea033b2 1407 rtype = elf_ppc_reloc_type (type);
252b5132
RH
1408 break;
1409
c833c019
AM
1410 case EM_PPC64:
1411 rtype = elf_ppc64_reloc_type (type);
1412 break;
1413
252b5132 1414 case EM_MIPS:
4fe85591 1415 case EM_MIPS_RS3_LE:
9ea033b2 1416 rtype = elf_mips_reloc_type (type);
252b5132
RH
1417 break;
1418
e23eba97
NC
1419 case EM_RISCV:
1420 rtype = elf_riscv_reloc_type (type);
1421 break;
1422
252b5132 1423 case EM_ALPHA:
9ea033b2 1424 rtype = elf_alpha_reloc_type (type);
252b5132
RH
1425 break;
1426
1427 case EM_ARM:
9ea033b2 1428 rtype = elf_arm_reloc_type (type);
252b5132
RH
1429 break;
1430
584da044 1431 case EM_ARC:
886a2506
NC
1432 case EM_ARC_COMPACT:
1433 case EM_ARC_COMPACT2:
9ea033b2 1434 rtype = elf_arc_reloc_type (type);
252b5132
RH
1435 break;
1436
1437 case EM_PARISC:
69e617ca 1438 rtype = elf_hppa_reloc_type (type);
252b5132 1439 break;
7d466069 1440
b8720f9d
JL
1441 case EM_H8_300:
1442 case EM_H8_300H:
1443 case EM_H8S:
1444 rtype = elf_h8_reloc_type (type);
1445 break;
1446
73589c9d
CS
1447 case EM_OR1K:
1448 rtype = elf_or1k_reloc_type (type);
3b16e843
NC
1449 break;
1450
7d466069 1451 case EM_PJ:
2b0337b0 1452 case EM_PJ_OLD:
7d466069
ILT
1453 rtype = elf_pj_reloc_type (type);
1454 break;
800eeca4
JW
1455 case EM_IA_64:
1456 rtype = elf_ia64_reloc_type (type);
1457 break;
1b61cf92
HPN
1458
1459 case EM_CRIS:
1460 rtype = elf_cris_reloc_type (type);
1461 break;
535c37ff 1462
f954747f
AM
1463 case EM_860:
1464 rtype = elf_i860_reloc_type (type);
1465 break;
1466
bcedfee6 1467 case EM_X86_64:
8a9036a4 1468 case EM_L1OM:
7a9068fe 1469 case EM_K1OM:
bcedfee6
NC
1470 rtype = elf_x86_64_reloc_type (type);
1471 break;
a85d7ed0 1472
f954747f
AM
1473 case EM_S370:
1474 rtype = i370_reloc_type (type);
1475 break;
1476
53c7db4b
KH
1477 case EM_S390_OLD:
1478 case EM_S390:
1479 rtype = elf_s390_reloc_type (type);
1480 break;
93fbbb04 1481
1c0d3aa6
NC
1482 case EM_SCORE:
1483 rtype = elf_score_reloc_type (type);
1484 break;
1485
93fbbb04
GK
1486 case EM_XSTORMY16:
1487 rtype = elf_xstormy16_reloc_type (type);
1488 break;
179d3252 1489
1fe1f39c
NC
1490 case EM_CRX:
1491 rtype = elf_crx_reloc_type (type);
1492 break;
1493
179d3252
JT
1494 case EM_VAX:
1495 rtype = elf_vax_reloc_type (type);
1496 break;
1e4cf259 1497
619ed720
EB
1498 case EM_VISIUM:
1499 rtype = elf_visium_reloc_type (type);
1500 break;
1501
aca4efc7
JM
1502 case EM_BPF:
1503 rtype = elf_bpf_reloc_type (type);
1504 break;
1505
cfb8c092
NC
1506 case EM_ADAPTEVA_EPIPHANY:
1507 rtype = elf_epiphany_reloc_type (type);
1508 break;
1509
1e4cf259
NC
1510 case EM_IP2K:
1511 case EM_IP2K_OLD:
1512 rtype = elf_ip2k_reloc_type (type);
1513 break;
3b36097d
SC
1514
1515 case EM_IQ2000:
1516 rtype = elf_iq2000_reloc_type (type);
1517 break;
88da6820
NC
1518
1519 case EM_XTENSA_OLD:
1520 case EM_XTENSA:
1521 rtype = elf_xtensa_reloc_type (type);
1522 break;
a34e3ecb 1523
84e94c90
NC
1524 case EM_LATTICEMICO32:
1525 rtype = elf_lm32_reloc_type (type);
1526 break;
1527
ff7eeb89 1528 case EM_M32C_OLD:
49f58d10
JB
1529 case EM_M32C:
1530 rtype = elf_m32c_reloc_type (type);
1531 break;
1532
d031aafb
NS
1533 case EM_MT:
1534 rtype = elf_mt_reloc_type (type);
a34e3ecb 1535 break;
1d65ded4
CM
1536
1537 case EM_BLACKFIN:
1538 rtype = elf_bfin_reloc_type (type);
1539 break;
15ab5209
DB
1540
1541 case EM_CYGNUS_MEP:
1542 rtype = elf_mep_reloc_type (type);
1543 break;
60bca95a
NC
1544
1545 case EM_CR16:
1546 rtype = elf_cr16_reloc_type (type);
1547 break;
dd24e3da 1548
7ba29e2a
NC
1549 case EM_MICROBLAZE:
1550 case EM_MICROBLAZE_OLD:
1551 rtype = elf_microblaze_reloc_type (type);
1552 break;
c7927a3c 1553
99c513f6
DD
1554 case EM_RL78:
1555 rtype = elf_rl78_reloc_type (type);
1556 break;
1557
c7927a3c
NC
1558 case EM_RX:
1559 rtype = elf_rx_reloc_type (type);
1560 break;
c29aca4a 1561
a3c62988
NC
1562 case EM_METAG:
1563 rtype = elf_metag_reloc_type (type);
1564 break;
1565
c29aca4a
NC
1566 case EM_XC16X:
1567 case EM_C166:
1568 rtype = elf_xc16x_reloc_type (type);
1569 break;
40b36596
JM
1570
1571 case EM_TI_C6000:
1572 rtype = elf_tic6x_reloc_type (type);
1573 break;
aa137e4d
NC
1574
1575 case EM_TILEGX:
1576 rtype = elf_tilegx_reloc_type (type);
1577 break;
1578
1579 case EM_TILEPRO:
1580 rtype = elf_tilepro_reloc_type (type);
1581 break;
f6c1a2d5 1582
f96bd6c2
PC
1583 case EM_WEBASSEMBLY:
1584 rtype = elf_wasm32_reloc_type (type);
1585 break;
1586
f6c1a2d5
NC
1587 case EM_XGATE:
1588 rtype = elf_xgate_reloc_type (type);
1589 break;
36591ba1
SL
1590
1591 case EM_ALTERA_NIOS2:
1592 rtype = elf_nios2_reloc_type (type);
1593 break;
2b100bb5
DD
1594
1595 case EM_TI_PRU:
1596 rtype = elf_pru_reloc_type (type);
1597 break;
fe944acf
FT
1598
1599 case EM_NFP:
1600 if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200)
1601 rtype = elf_nfp3200_reloc_type (type);
1602 else
1603 rtype = elf_nfp_reloc_type (type);
1604 break;
252b5132
RH
1605 }
1606
1607 if (rtype == NULL)
39dbeff8 1608 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
252b5132 1609 else
5c144731 1610 printf (do_wide ? "%-22s" : "%-17.17s", rtype);
252b5132 1611
dda8d76d 1612 if (filedata->file_header.e_machine == EM_ALPHA
157c2599 1613 && rtype != NULL
7ace3541
RH
1614 && streq (rtype, "R_ALPHA_LITUSE")
1615 && is_rela)
1616 {
1617 switch (rels[i].r_addend)
1618 {
1619 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1620 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1621 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1622 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1623 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1624 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1625 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1626 default: rtype = NULL;
1627 }
32ec8896 1628
7ace3541
RH
1629 if (rtype)
1630 printf (" (%s)", rtype);
1631 else
1632 {
1633 putchar (' ');
1634 printf (_("<unknown addend: %lx>"),
1635 (unsigned long) rels[i].r_addend);
32ec8896 1636 res = FALSE;
7ace3541
RH
1637 }
1638 }
1639 else if (symtab_index)
252b5132 1640 {
af3fc3bc 1641 if (symtab == NULL || symtab_index >= nsyms)
32ec8896
NC
1642 {
1643 error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index);
1644 res = FALSE;
1645 }
af3fc3bc 1646 else
19936277 1647 {
2cf0635d 1648 Elf_Internal_Sym * psym;
bb4d2ac2
L
1649 const char * version_string;
1650 enum versioned_symbol_info sym_info;
1651 unsigned short vna_other;
19936277 1652
af3fc3bc 1653 psym = symtab + symtab_index;
103f02d3 1654
bb4d2ac2 1655 version_string
dda8d76d 1656 = get_symbol_version_string (filedata, is_dynsym,
bb4d2ac2
L
1657 strtab, strtablen,
1658 symtab_index,
1659 psym,
1660 &sym_info,
1661 &vna_other);
1662
af3fc3bc 1663 printf (" ");
171191ba 1664
d8045f23
NC
1665 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
1666 {
1667 const char * name;
1668 unsigned int len;
1669 unsigned int width = is_32bit_elf ? 8 : 14;
1670
1671 /* Relocations against GNU_IFUNC symbols do not use the value
1672 of the symbol as the address to relocate against. Instead
1673 they invoke the function named by the symbol and use its
1674 result as the address for relocation.
1675
1676 To indicate this to the user, do not display the value of
1677 the symbol in the "Symbols's Value" field. Instead show
1678 its name followed by () as a hint that the symbol is
1679 invoked. */
1680
1681 if (strtab == NULL
1682 || psym->st_name == 0
1683 || psym->st_name >= strtablen)
1684 name = "??";
1685 else
1686 name = strtab + psym->st_name;
1687
1688 len = print_symbol (width, name);
bb4d2ac2
L
1689 if (version_string)
1690 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1691 version_string);
d8045f23
NC
1692 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
1693 }
1694 else
1695 {
1696 print_vma (psym->st_value, LONG_HEX);
171191ba 1697
d8045f23
NC
1698 printf (is_32bit_elf ? " " : " ");
1699 }
103f02d3 1700
af3fc3bc 1701 if (psym->st_name == 0)
f1ef08cb 1702 {
2cf0635d 1703 const char * sec_name = "<null>";
f1ef08cb
AM
1704 char name_buf[40];
1705
1706 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1707 {
dda8d76d
NC
1708 if (psym->st_shndx < filedata->file_header.e_shnum)
1709 sec_name = SECTION_NAME (filedata->section_headers + psym->st_shndx);
f1ef08cb
AM
1710 else if (psym->st_shndx == SHN_ABS)
1711 sec_name = "ABS";
1712 else if (psym->st_shndx == SHN_COMMON)
1713 sec_name = "COMMON";
dda8d76d 1714 else if ((filedata->file_header.e_machine == EM_MIPS
ac145307 1715 && psym->st_shndx == SHN_MIPS_SCOMMON)
dda8d76d 1716 || (filedata->file_header.e_machine == EM_TI_C6000
ac145307 1717 && psym->st_shndx == SHN_TIC6X_SCOMMON))
172553c7 1718 sec_name = "SCOMMON";
dda8d76d 1719 else if (filedata->file_header.e_machine == EM_MIPS
172553c7
TS
1720 && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1721 sec_name = "SUNDEF";
dda8d76d
NC
1722 else if ((filedata->file_header.e_machine == EM_X86_64
1723 || filedata->file_header.e_machine == EM_L1OM
1724 || filedata->file_header.e_machine == EM_K1OM)
3b22753a
L
1725 && psym->st_shndx == SHN_X86_64_LCOMMON)
1726 sec_name = "LARGE_COMMON";
dda8d76d
NC
1727 else if (filedata->file_header.e_machine == EM_IA_64
1728 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
9ce701e2
L
1729 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1730 sec_name = "ANSI_COM";
dda8d76d 1731 else if (is_ia64_vms (filedata)
148b93f2
NC
1732 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
1733 sec_name = "VMS_SYMVEC";
f1ef08cb
AM
1734 else
1735 {
1736 sprintf (name_buf, "<section 0x%x>",
1737 (unsigned int) psym->st_shndx);
1738 sec_name = name_buf;
1739 }
1740 }
1741 print_symbol (22, sec_name);
1742 }
af3fc3bc 1743 else if (strtab == NULL)
d79b3d50 1744 printf (_("<string table index: %3ld>"), psym->st_name);
c256ffe7 1745 else if (psym->st_name >= strtablen)
32ec8896
NC
1746 {
1747 error (_("<corrupt string table index: %3ld>"), psym->st_name);
1748 res = FALSE;
1749 }
af3fc3bc 1750 else
bb4d2ac2
L
1751 {
1752 print_symbol (22, strtab + psym->st_name);
1753 if (version_string)
1754 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1755 version_string);
1756 }
103f02d3 1757
af3fc3bc 1758 if (is_rela)
171191ba 1759 {
7360e63f 1760 bfd_vma off = rels[i].r_addend;
171191ba 1761
7360e63f 1762 if ((bfd_signed_vma) off < 0)
598aaa76 1763 printf (" - %" BFD_VMA_FMT "x", - off);
171191ba 1764 else
598aaa76 1765 printf (" + %" BFD_VMA_FMT "x", off);
171191ba 1766 }
19936277 1767 }
252b5132 1768 }
1b228002 1769 else if (is_rela)
f7a99963 1770 {
7360e63f 1771 bfd_vma off = rels[i].r_addend;
e04d7088
L
1772
1773 printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
7360e63f 1774 if ((bfd_signed_vma) off < 0)
e04d7088
L
1775 printf ("-%" BFD_VMA_FMT "x", - off);
1776 else
1777 printf ("%" BFD_VMA_FMT "x", off);
f7a99963 1778 }
252b5132 1779
dda8d76d 1780 if (filedata->file_header.e_machine == EM_SPARCV9
157c2599
NC
1781 && rtype != NULL
1782 && streq (rtype, "R_SPARC_OLO10"))
91d6fa6a 1783 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
351b4b40 1784
252b5132 1785 putchar ('\n');
2c71103e 1786
aca88567 1787#ifdef BFD64
dda8d76d 1788 if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
2c71103e 1789 {
91d6fa6a
NC
1790 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
1791 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
2cf0635d
NC
1792 const char * rtype2 = elf_mips_reloc_type (type2);
1793 const char * rtype3 = elf_mips_reloc_type (type3);
aca88567 1794
2c71103e
NC
1795 printf (" Type2: ");
1796
1797 if (rtype2 == NULL)
39dbeff8
AM
1798 printf (_("unrecognized: %-7lx"),
1799 (unsigned long) type2 & 0xffffffff);
2c71103e
NC
1800 else
1801 printf ("%-17.17s", rtype2);
1802
18bd398b 1803 printf ("\n Type3: ");
2c71103e
NC
1804
1805 if (rtype3 == NULL)
39dbeff8
AM
1806 printf (_("unrecognized: %-7lx"),
1807 (unsigned long) type3 & 0xffffffff);
2c71103e
NC
1808 else
1809 printf ("%-17.17s", rtype3);
1810
53c7db4b 1811 putchar ('\n');
2c71103e 1812 }
aca88567 1813#endif /* BFD64 */
252b5132
RH
1814 }
1815
c8286bd1 1816 free (rels);
32ec8896
NC
1817
1818 return res;
252b5132
RH
1819}
1820
37c18eed
SD
1821static const char *
1822get_aarch64_dynamic_type (unsigned long type)
1823{
1824 switch (type)
1825 {
1826 case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT";
1dbade74 1827 case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT";
2301ed1c 1828 case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS";
37c18eed
SD
1829 default:
1830 return NULL;
1831 }
1832}
1833
252b5132 1834static const char *
d3ba0551 1835get_mips_dynamic_type (unsigned long type)
252b5132
RH
1836{
1837 switch (type)
1838 {
1839 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1840 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1841 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1842 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1843 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1844 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1845 case DT_MIPS_MSYM: return "MIPS_MSYM";
1846 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1847 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1848 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1849 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1850 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1851 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1852 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1853 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1854 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1855 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
a5499fa4 1856 case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
252b5132
RH
1857 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1858 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1859 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1860 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1861 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1862 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1863 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1864 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1865 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1866 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1867 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1868 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1869 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1870 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1871 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1872 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1873 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1874 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1875 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1876 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1877 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1878 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1879 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1880 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1881 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1882 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
861fb55a
DJ
1883 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
1884 case DT_MIPS_RWPLT: return "MIPS_RWPLT";
252b5132
RH
1885 default:
1886 return NULL;
1887 }
1888}
1889
9a097730 1890static const char *
d3ba0551 1891get_sparc64_dynamic_type (unsigned long type)
9a097730
RH
1892{
1893 switch (type)
1894 {
1895 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1896 default:
1897 return NULL;
1898 }
103f02d3
UD
1899}
1900
7490d522
AM
1901static const char *
1902get_ppc_dynamic_type (unsigned long type)
1903{
1904 switch (type)
1905 {
a7f2871e 1906 case DT_PPC_GOT: return "PPC_GOT";
e8910a83 1907 case DT_PPC_OPT: return "PPC_OPT";
7490d522
AM
1908 default:
1909 return NULL;
1910 }
1911}
1912
f1cb7e17 1913static const char *
d3ba0551 1914get_ppc64_dynamic_type (unsigned long type)
f1cb7e17
AM
1915{
1916 switch (type)
1917 {
a7f2871e
AM
1918 case DT_PPC64_GLINK: return "PPC64_GLINK";
1919 case DT_PPC64_OPD: return "PPC64_OPD";
1920 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
e8910a83 1921 case DT_PPC64_OPT: return "PPC64_OPT";
f1cb7e17
AM
1922 default:
1923 return NULL;
1924 }
1925}
1926
103f02d3 1927static const char *
d3ba0551 1928get_parisc_dynamic_type (unsigned long type)
103f02d3
UD
1929{
1930 switch (type)
1931 {
1932 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1933 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1934 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1935 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1936 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1937 case DT_HP_PREINIT: return "HP_PREINIT";
1938 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1939 case DT_HP_NEEDED: return "HP_NEEDED";
1940 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1941 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1942 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1943 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1944 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
eec8f817
DA
1945 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1946 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1947 case DT_HP_FILTERED: return "HP_FILTERED";
1948 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1949 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1950 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1951 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1952 case DT_PLT: return "PLT";
1953 case DT_PLT_SIZE: return "PLT_SIZE";
1954 case DT_DLT: return "DLT";
1955 case DT_DLT_SIZE: return "DLT_SIZE";
103f02d3
UD
1956 default:
1957 return NULL;
1958 }
1959}
9a097730 1960
ecc51f48 1961static const char *
d3ba0551 1962get_ia64_dynamic_type (unsigned long type)
ecc51f48
NC
1963{
1964 switch (type)
1965 {
148b93f2
NC
1966 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1967 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
1968 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
1969 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
1970 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
1971 case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
1972 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
1973 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
1974 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
1975 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
1976 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
1977 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
1978 case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
1979 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
1980 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
1981 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
1982 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
1983 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
1984 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
1985 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
1986 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
1987 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
1988 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
1989 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
1990 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
1991 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
1992 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
1993 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
1994 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
1995 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
1996 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
ecc51f48
NC
1997 default:
1998 return NULL;
1999 }
2000}
2001
fd85a6a1
NC
2002static const char *
2003get_solaris_section_type (unsigned long type)
2004{
2005 switch (type)
2006 {
2007 case 0x6fffffee: return "SUNW_ancillary";
2008 case 0x6fffffef: return "SUNW_capchain";
2009 case 0x6ffffff0: return "SUNW_capinfo";
2010 case 0x6ffffff1: return "SUNW_symsort";
2011 case 0x6ffffff2: return "SUNW_tlssort";
2012 case 0x6ffffff3: return "SUNW_LDYNSYM";
2013 case 0x6ffffff4: return "SUNW_dof";
2014 case 0x6ffffff5: return "SUNW_cap";
2015 case 0x6ffffff6: return "SUNW_SIGNATURE";
2016 case 0x6ffffff7: return "SUNW_ANNOTATE";
2017 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2018 case 0x6ffffff9: return "SUNW_DEBUG";
2019 case 0x6ffffffa: return "SUNW_move";
2020 case 0x6ffffffb: return "SUNW_COMDAT";
2021 case 0x6ffffffc: return "SUNW_syminfo";
2022 case 0x6ffffffd: return "SUNW_verdef";
2023 case 0x6ffffffe: return "SUNW_verneed";
2024 case 0x6fffffff: return "SUNW_versym";
2025 case 0x70000000: return "SPARC_GOTDATA";
2026 default: return NULL;
2027 }
2028}
2029
fabcb361
RH
2030static const char *
2031get_alpha_dynamic_type (unsigned long type)
2032{
2033 switch (type)
2034 {
2035 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
32ec8896 2036 default: return NULL;
fabcb361
RH
2037 }
2038}
2039
1c0d3aa6
NC
2040static const char *
2041get_score_dynamic_type (unsigned long type)
2042{
2043 switch (type)
2044 {
2045 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
2046 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
2047 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
2048 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
2049 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
2050 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
32ec8896 2051 default: return NULL;
1c0d3aa6
NC
2052 }
2053}
2054
40b36596
JM
2055static const char *
2056get_tic6x_dynamic_type (unsigned long type)
2057{
2058 switch (type)
2059 {
2060 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
2061 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
2062 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
2063 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
2064 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
2065 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
32ec8896 2066 default: return NULL;
40b36596
JM
2067 }
2068}
1c0d3aa6 2069
36591ba1
SL
2070static const char *
2071get_nios2_dynamic_type (unsigned long type)
2072{
2073 switch (type)
2074 {
2075 case DT_NIOS2_GP: return "NIOS2_GP";
32ec8896 2076 default: return NULL;
36591ba1
SL
2077 }
2078}
2079
fd85a6a1
NC
2080static const char *
2081get_solaris_dynamic_type (unsigned long type)
2082{
2083 switch (type)
2084 {
2085 case 0x6000000d: return "SUNW_AUXILIARY";
2086 case 0x6000000e: return "SUNW_RTLDINF";
2087 case 0x6000000f: return "SUNW_FILTER";
2088 case 0x60000010: return "SUNW_CAP";
2089 case 0x60000011: return "SUNW_SYMTAB";
2090 case 0x60000012: return "SUNW_SYMSZ";
2091 case 0x60000013: return "SUNW_SORTENT";
2092 case 0x60000014: return "SUNW_SYMSORT";
2093 case 0x60000015: return "SUNW_SYMSORTSZ";
2094 case 0x60000016: return "SUNW_TLSSORT";
2095 case 0x60000017: return "SUNW_TLSSORTSZ";
2096 case 0x60000018: return "SUNW_CAPINFO";
2097 case 0x60000019: return "SUNW_STRPAD";
2098 case 0x6000001a: return "SUNW_CAPCHAIN";
2099 case 0x6000001b: return "SUNW_LDMACH";
2100 case 0x6000001d: return "SUNW_CAPCHAINENT";
2101 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2102 case 0x60000021: return "SUNW_PARENT";
2103 case 0x60000023: return "SUNW_ASLR";
2104 case 0x60000025: return "SUNW_RELAX";
2105 case 0x60000029: return "SUNW_NXHEAP";
2106 case 0x6000002b: return "SUNW_NXSTACK";
2107
2108 case 0x70000001: return "SPARC_REGISTER";
2109 case 0x7ffffffd: return "AUXILIARY";
2110 case 0x7ffffffe: return "USED";
2111 case 0x7fffffff: return "FILTER";
2112
15f205b1 2113 default: return NULL;
fd85a6a1
NC
2114 }
2115}
2116
252b5132 2117static const char *
dda8d76d 2118get_dynamic_type (Filedata * filedata, unsigned long type)
252b5132 2119{
e9e44622 2120 static char buff[64];
252b5132
RH
2121
2122 switch (type)
2123 {
2124 case DT_NULL: return "NULL";
2125 case DT_NEEDED: return "NEEDED";
2126 case DT_PLTRELSZ: return "PLTRELSZ";
2127 case DT_PLTGOT: return "PLTGOT";
2128 case DT_HASH: return "HASH";
2129 case DT_STRTAB: return "STRTAB";
2130 case DT_SYMTAB: return "SYMTAB";
2131 case DT_RELA: return "RELA";
2132 case DT_RELASZ: return "RELASZ";
2133 case DT_RELAENT: return "RELAENT";
2134 case DT_STRSZ: return "STRSZ";
2135 case DT_SYMENT: return "SYMENT";
2136 case DT_INIT: return "INIT";
2137 case DT_FINI: return "FINI";
2138 case DT_SONAME: return "SONAME";
2139 case DT_RPATH: return "RPATH";
2140 case DT_SYMBOLIC: return "SYMBOLIC";
2141 case DT_REL: return "REL";
2142 case DT_RELSZ: return "RELSZ";
2143 case DT_RELENT: return "RELENT";
2144 case DT_PLTREL: return "PLTREL";
2145 case DT_DEBUG: return "DEBUG";
2146 case DT_TEXTREL: return "TEXTREL";
2147 case DT_JMPREL: return "JMPREL";
2148 case DT_BIND_NOW: return "BIND_NOW";
2149 case DT_INIT_ARRAY: return "INIT_ARRAY";
2150 case DT_FINI_ARRAY: return "FINI_ARRAY";
2151 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
2152 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
d1133906
NC
2153 case DT_RUNPATH: return "RUNPATH";
2154 case DT_FLAGS: return "FLAGS";
2d0e6f43 2155
d1133906
NC
2156 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2157 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
6d913794 2158 case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX";
103f02d3 2159
05107a46 2160 case DT_CHECKSUM: return "CHECKSUM";
252b5132
RH
2161 case DT_PLTPADSZ: return "PLTPADSZ";
2162 case DT_MOVEENT: return "MOVEENT";
2163 case DT_MOVESZ: return "MOVESZ";
dcefbbbd 2164 case DT_FEATURE: return "FEATURE";
252b5132
RH
2165 case DT_POSFLAG_1: return "POSFLAG_1";
2166 case DT_SYMINSZ: return "SYMINSZ";
2167 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
103f02d3 2168
252b5132 2169 case DT_ADDRRNGLO: return "ADDRRNGLO";
dcefbbbd
L
2170 case DT_CONFIG: return "CONFIG";
2171 case DT_DEPAUDIT: return "DEPAUDIT";
2172 case DT_AUDIT: return "AUDIT";
2173 case DT_PLTPAD: return "PLTPAD";
2174 case DT_MOVETAB: return "MOVETAB";
252b5132 2175 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
103f02d3 2176
252b5132 2177 case DT_VERSYM: return "VERSYM";
103f02d3 2178
67a4f2b7
AO
2179 case DT_TLSDESC_GOT: return "TLSDESC_GOT";
2180 case DT_TLSDESC_PLT: return "TLSDESC_PLT";
252b5132
RH
2181 case DT_RELACOUNT: return "RELACOUNT";
2182 case DT_RELCOUNT: return "RELCOUNT";
2183 case DT_FLAGS_1: return "FLAGS_1";
2184 case DT_VERDEF: return "VERDEF";
2185 case DT_VERDEFNUM: return "VERDEFNUM";
2186 case DT_VERNEED: return "VERNEED";
2187 case DT_VERNEEDNUM: return "VERNEEDNUM";
103f02d3 2188
019148e4 2189 case DT_AUXILIARY: return "AUXILIARY";
252b5132
RH
2190 case DT_USED: return "USED";
2191 case DT_FILTER: return "FILTER";
103f02d3 2192
047b2264
JJ
2193 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
2194 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
2195 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
2196 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
2197 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
fdc90cb4 2198 case DT_GNU_HASH: return "GNU_HASH";
047b2264 2199
252b5132
RH
2200 default:
2201 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
2202 {
2cf0635d 2203 const char * result;
103f02d3 2204
dda8d76d 2205 switch (filedata->file_header.e_machine)
252b5132 2206 {
37c18eed
SD
2207 case EM_AARCH64:
2208 result = get_aarch64_dynamic_type (type);
2209 break;
252b5132 2210 case EM_MIPS:
4fe85591 2211 case EM_MIPS_RS3_LE:
252b5132
RH
2212 result = get_mips_dynamic_type (type);
2213 break;
9a097730
RH
2214 case EM_SPARCV9:
2215 result = get_sparc64_dynamic_type (type);
2216 break;
7490d522
AM
2217 case EM_PPC:
2218 result = get_ppc_dynamic_type (type);
2219 break;
f1cb7e17
AM
2220 case EM_PPC64:
2221 result = get_ppc64_dynamic_type (type);
2222 break;
ecc51f48
NC
2223 case EM_IA_64:
2224 result = get_ia64_dynamic_type (type);
2225 break;
fabcb361
RH
2226 case EM_ALPHA:
2227 result = get_alpha_dynamic_type (type);
2228 break;
1c0d3aa6
NC
2229 case EM_SCORE:
2230 result = get_score_dynamic_type (type);
2231 break;
40b36596
JM
2232 case EM_TI_C6000:
2233 result = get_tic6x_dynamic_type (type);
2234 break;
36591ba1
SL
2235 case EM_ALTERA_NIOS2:
2236 result = get_nios2_dynamic_type (type);
2237 break;
252b5132 2238 default:
dda8d76d 2239 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
2240 result = get_solaris_dynamic_type (type);
2241 else
2242 result = NULL;
252b5132
RH
2243 break;
2244 }
2245
2246 if (result != NULL)
2247 return result;
2248
e9e44622 2249 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
252b5132 2250 }
eec8f817 2251 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
dda8d76d 2252 || (filedata->file_header.e_machine == EM_PARISC
eec8f817 2253 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
103f02d3 2254 {
2cf0635d 2255 const char * result;
103f02d3 2256
dda8d76d 2257 switch (filedata->file_header.e_machine)
103f02d3
UD
2258 {
2259 case EM_PARISC:
2260 result = get_parisc_dynamic_type (type);
2261 break;
148b93f2
NC
2262 case EM_IA_64:
2263 result = get_ia64_dynamic_type (type);
2264 break;
103f02d3 2265 default:
dda8d76d 2266 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
2267 result = get_solaris_dynamic_type (type);
2268 else
2269 result = NULL;
103f02d3
UD
2270 break;
2271 }
2272
2273 if (result != NULL)
2274 return result;
2275
e9e44622
JJ
2276 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
2277 type);
103f02d3 2278 }
252b5132 2279 else
e9e44622 2280 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
103f02d3 2281
252b5132
RH
2282 return buff;
2283 }
2284}
2285
2286static char *
d3ba0551 2287get_file_type (unsigned e_type)
252b5132 2288{
b34976b6 2289 static char buff[32];
252b5132
RH
2290
2291 switch (e_type)
2292 {
32ec8896
NC
2293 case ET_NONE: return _("NONE (None)");
2294 case ET_REL: return _("REL (Relocatable file)");
2295 case ET_EXEC: return _("EXEC (Executable file)");
2296 case ET_DYN: return _("DYN (Shared object file)");
2297 case ET_CORE: return _("CORE (Core file)");
252b5132
RH
2298
2299 default:
2300 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
e9e44622 2301 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
252b5132 2302 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
e9e44622 2303 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
252b5132 2304 else
e9e44622 2305 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
252b5132
RH
2306 return buff;
2307 }
2308}
2309
2310static char *
d3ba0551 2311get_machine_name (unsigned e_machine)
252b5132 2312{
b34976b6 2313 static char buff[64]; /* XXX */
252b5132
RH
2314
2315 switch (e_machine)
2316 {
55e22ca8
NC
2317 /* Please keep this switch table sorted by increasing EM_ value. */
2318 /* 0 */
c45021f2
NC
2319 case EM_NONE: return _("None");
2320 case EM_M32: return "WE32100";
2321 case EM_SPARC: return "Sparc";
2322 case EM_386: return "Intel 80386";
2323 case EM_68K: return "MC68000";
2324 case EM_88K: return "MC88000";
22abe556 2325 case EM_IAMCU: return "Intel MCU";
fb70ec17 2326 case EM_860: return "Intel 80860";
c45021f2
NC
2327 case EM_MIPS: return "MIPS R3000";
2328 case EM_S370: return "IBM System/370";
55e22ca8 2329 /* 10 */
7036c0e1 2330 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
252b5132 2331 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
c45021f2 2332 case EM_PARISC: return "HPPA";
55e22ca8 2333 case EM_VPP550: return "Fujitsu VPP500";
7036c0e1 2334 case EM_SPARC32PLUS: return "Sparc v8+" ;
d7867d17 2335 case EM_960: return "Intel 80960";
c45021f2 2336 case EM_PPC: return "PowerPC";
55e22ca8 2337 /* 20 */
285d1771 2338 case EM_PPC64: return "PowerPC64";
55e22ca8
NC
2339 case EM_S390_OLD:
2340 case EM_S390: return "IBM S/390";
2341 case EM_SPU: return "SPU";
2342 /* 30 */
2343 case EM_V800: return "Renesas V850 (using RH850 ABI)";
c45021f2
NC
2344 case EM_FR20: return "Fujitsu FR20";
2345 case EM_RH32: return "TRW RH32";
b34976b6 2346 case EM_MCORE: return "MCORE";
55e22ca8 2347 /* 40 */
7036c0e1
AJ
2348 case EM_ARM: return "ARM";
2349 case EM_OLD_ALPHA: return "Digital Alpha (old)";
ef230218 2350 case EM_SH: return "Renesas / SuperH SH";
c45021f2
NC
2351 case EM_SPARCV9: return "Sparc v9";
2352 case EM_TRICORE: return "Siemens Tricore";
584da044 2353 case EM_ARC: return "ARC";
c2dcd04e
NC
2354 case EM_H8_300: return "Renesas H8/300";
2355 case EM_H8_300H: return "Renesas H8/300H";
2356 case EM_H8S: return "Renesas H8S";
2357 case EM_H8_500: return "Renesas H8/500";
55e22ca8 2358 /* 50 */
30800947 2359 case EM_IA_64: return "Intel IA-64";
252b5132
RH
2360 case EM_MIPS_X: return "Stanford MIPS-X";
2361 case EM_COLDFIRE: return "Motorola Coldfire";
55e22ca8 2362 case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
7036c0e1
AJ
2363 case EM_MMA: return "Fujitsu Multimedia Accelerator";
2364 case EM_PCP: return "Siemens PCP";
2365 case EM_NCPU: return "Sony nCPU embedded RISC processor";
2366 case EM_NDR1: return "Denso NDR1 microprocesspr";
2367 case EM_STARCORE: return "Motorola Star*Core processor";
2368 case EM_ME16: return "Toyota ME16 processor";
55e22ca8 2369 /* 60 */
7036c0e1
AJ
2370 case EM_ST100: return "STMicroelectronics ST100 processor";
2371 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
55e22ca8 2372 case EM_X86_64: return "Advanced Micro Devices X86-64";
11636f9e
JM
2373 case EM_PDSP: return "Sony DSP processor";
2374 case EM_PDP10: return "Digital Equipment Corp. PDP-10";
2375 case EM_PDP11: return "Digital Equipment Corp. PDP-11";
7036c0e1
AJ
2376 case EM_FX66: return "Siemens FX66 microcontroller";
2377 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2378 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
2379 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
55e22ca8 2380 /* 70 */
7036c0e1
AJ
2381 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
2382 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
2383 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
2384 case EM_SVX: return "Silicon Graphics SVx";
2385 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
2386 case EM_VAX: return "Digital VAX";
1b61cf92 2387 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
c45021f2
NC
2388 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
2389 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
2390 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
55e22ca8 2391 /* 80 */
b34976b6 2392 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
c45021f2 2393 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
3b36097d 2394 case EM_PRISM: return "Vitesse Prism";
55e22ca8
NC
2395 case EM_AVR_OLD:
2396 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
2397 case EM_CYGNUS_FR30:
2398 case EM_FR30: return "Fujitsu FR30";
2399 case EM_CYGNUS_D10V:
2400 case EM_D10V: return "d10v";
2401 case EM_CYGNUS_D30V:
2402 case EM_D30V: return "d30v";
2403 case EM_CYGNUS_V850:
2404 case EM_V850: return "Renesas V850";
2405 case EM_CYGNUS_M32R:
2406 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
2407 case EM_CYGNUS_MN10300:
2408 case EM_MN10300: return "mn10300";
2409 /* 90 */
2410 case EM_CYGNUS_MN10200:
2411 case EM_MN10200: return "mn10200";
2412 case EM_PJ: return "picoJava";
73589c9d 2413 case EM_OR1K: return "OpenRISC 1000";
55e22ca8 2414 case EM_ARC_COMPACT: return "ARCompact";
88da6820
NC
2415 case EM_XTENSA_OLD:
2416 case EM_XTENSA: return "Tensilica Xtensa Processor";
11636f9e
JM
2417 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
2418 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
2419 case EM_NS32K: return "National Semiconductor 32000 series";
2420 case EM_TPC: return "Tenor Network TPC processor";
55e22ca8
NC
2421 case EM_SNP1K: return "Trebia SNP 1000 processor";
2422 /* 100 */
2423 case EM_ST200: return "STMicroelectronics ST200 microcontroller";
2424 case EM_IP2K_OLD:
2425 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
11636f9e
JM
2426 case EM_MAX: return "MAX Processor";
2427 case EM_CR: return "National Semiconductor CompactRISC";
2428 case EM_F2MC16: return "Fujitsu F2MC16";
2429 case EM_MSP430: return "Texas Instruments msp430 microcontroller";
7bbe5bc5 2430 case EM_BLACKFIN: return "Analog Devices Blackfin";
11636f9e
JM
2431 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
2432 case EM_SEP: return "Sharp embedded microprocessor";
2433 case EM_ARCA: return "Arca RISC microprocessor";
55e22ca8 2434 /* 110 */
11636f9e
JM
2435 case EM_UNICORE: return "Unicore";
2436 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
2437 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
64fd6348 2438 case EM_ALTERA_NIOS2: return "Altera Nios II";
55e22ca8
NC
2439 case EM_CRX: return "National Semiconductor CRX microprocessor";
2440 case EM_XGATE: return "Motorola XGATE embedded processor";
c29aca4a 2441 case EM_C166:
d70c5fc7 2442 case EM_XC16X: return "Infineon Technologies xc16x";
11636f9e
JM
2443 case EM_M16C: return "Renesas M16C series microprocessors";
2444 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
2445 case EM_CE: return "Freescale Communication Engine RISC core";
55e22ca8
NC
2446 /* 120 */
2447 case EM_M32C: return "Renesas M32c";
2448 /* 130 */
11636f9e
JM
2449 case EM_TSK3000: return "Altium TSK3000 core";
2450 case EM_RS08: return "Freescale RS08 embedded processor";
2451 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
55e22ca8 2452 case EM_SCORE: return "SUNPLUS S+Core";
11636f9e
JM
2453 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
2454 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
55e22ca8 2455 case EM_LATTICEMICO32: return "Lattice Mico32";
11636f9e 2456 case EM_SE_C17: return "Seiko Epson C17 family";
55e22ca8 2457 /* 140 */
11636f9e
JM
2458 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
2459 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
2460 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
55e22ca8
NC
2461 case EM_TI_PRU: return "TI PRU I/O processor";
2462 /* 160 */
11636f9e
JM
2463 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2464 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
2465 case EM_R32C: return "Renesas R32C series microprocessors";
2466 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
2467 case EM_QDSP6: return "QUALCOMM DSP6 Processor";
2468 case EM_8051: return "Intel 8051 and variants";
2469 case EM_STXP7X: return "STMicroelectronics STxP7x family";
2470 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
2471 case EM_ECOG1X: return "Cyan Technology eCOG1X family";
2472 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
55e22ca8 2473 /* 170 */
11636f9e
JM
2474 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
2475 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
2476 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
c7927a3c 2477 case EM_RX: return "Renesas RX";
a3c62988 2478 case EM_METAG: return "Imagination Technologies Meta processor architecture";
11636f9e
JM
2479 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
2480 case EM_ECOG16: return "Cyan Technology eCOG16 family";
55e22ca8
NC
2481 case EM_CR16:
2482 case EM_MICROBLAZE:
2483 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
11636f9e
JM
2484 case EM_ETPU: return "Freescale Extended Time Processing Unit";
2485 case EM_SLE9X: return "Infineon Technologies SLE9X core";
55e22ca8
NC
2486 /* 180 */
2487 case EM_L1OM: return "Intel L1OM";
2488 case EM_K1OM: return "Intel K1OM";
2489 case EM_INTEL182: return "Intel (reserved)";
2490 case EM_AARCH64: return "AArch64";
2491 case EM_ARM184: return "ARM (reserved)";
2492 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor";
11636f9e
JM
2493 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
2494 case EM_TILE64: return "Tilera TILE64 multicore architecture family";
2495 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
55e22ca8 2496 /* 190 */
11636f9e 2497 case EM_CUDA: return "NVIDIA CUDA architecture";
55e22ca8 2498 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
6d913794
NC
2499 case EM_CLOUDSHIELD: return "CloudShield architecture family";
2500 case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family";
2501 case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family";
55e22ca8 2502 case EM_ARC_COMPACT2: return "ARCv2";
6d913794 2503 case EM_OPEN8: return "Open8 8-bit RISC soft processor core";
55e22ca8 2504 case EM_RL78: return "Renesas RL78";
6d913794 2505 case EM_VIDEOCORE5: return "Broadcom VideoCore V processor";
55e22ca8
NC
2506 case EM_78K0R: return "Renesas 78K0R";
2507 /* 200 */
6d913794 2508 case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)";
15f205b1
NC
2509 case EM_BA1: return "Beyond BA1 CPU architecture";
2510 case EM_BA2: return "Beyond BA2 CPU architecture";
6d913794
NC
2511 case EM_XCORE: return "XMOS xCORE processor family";
2512 case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family";
55e22ca8 2513 /* 210 */
6d913794
NC
2514 case EM_KM32: return "KM211 KM32 32-bit processor";
2515 case EM_KMX32: return "KM211 KMX32 32-bit processor";
2516 case EM_KMX16: return "KM211 KMX16 16-bit processor";
2517 case EM_KMX8: return "KM211 KMX8 8-bit processor";
2518 case EM_KVARC: return "KM211 KVARC processor";
15f205b1 2519 case EM_CDP: return "Paneve CDP architecture family";
6d913794
NC
2520 case EM_COGE: return "Cognitive Smart Memory Processor";
2521 case EM_COOL: return "Bluechip Systems CoolEngine";
2522 case EM_NORC: return "Nanoradio Optimized RISC";
2523 case EM_CSR_KALIMBA: return "CSR Kalimba architecture family";
55e22ca8 2524 /* 220 */
15f205b1 2525 case EM_Z80: return "Zilog Z80";
55e22ca8
NC
2526 case EM_VISIUM: return "CDS VISIUMcore processor";
2527 case EM_FT32: return "FTDI Chip FT32";
2528 case EM_MOXIE: return "Moxie";
2529 case EM_AMDGPU: return "AMD GPU";
2530 case EM_RISCV: return "RISC-V";
2531 case EM_LANAI: return "Lanai 32-bit processor";
2532 case EM_BPF: return "Linux BPF";
fe944acf 2533 case EM_NFP: return "Netronome Flow Processor";
55e22ca8
NC
2534
2535 /* Large numbers... */
2536 case EM_MT: return "Morpho Techologies MT processor";
2537 case EM_ALPHA: return "Alpha";
2538 case EM_WEBASSEMBLY: return "Web Assembly";
2539 case EM_DLX: return "OpenDLX";
2540 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
2541 case EM_IQ2000: return "Vitesse IQ2000";
2542 case EM_M32C_OLD:
2543 case EM_NIOS32: return "Altera Nios";
2544 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
2545 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
2546 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
637b1970 2547 case EM_S12Z: return "Freescale S12Z";
b8891f8d 2548 case EM_CSKY: return "C-SKY";
55e22ca8 2549
252b5132 2550 default:
35d9dd2f 2551 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
252b5132
RH
2552 return buff;
2553 }
2554}
2555
a9522a21
AB
2556static void
2557decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
2558{
2559 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2560 other compilers don't a specific architecture type in the e_flags, and
2561 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2562 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2563 architectures.
2564
2565 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2566 but also sets a specific architecture type in the e_flags field.
2567
2568 However, when decoding the flags we don't worry if we see an
2569 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2570 ARCEM architecture type. */
2571
2572 switch (e_flags & EF_ARC_MACH_MSK)
2573 {
2574 /* We only expect these to occur for EM_ARC_COMPACT2. */
2575 case EF_ARC_CPU_ARCV2EM:
2576 strcat (buf, ", ARC EM");
2577 break;
2578 case EF_ARC_CPU_ARCV2HS:
2579 strcat (buf, ", ARC HS");
2580 break;
2581
2582 /* We only expect these to occur for EM_ARC_COMPACT. */
2583 case E_ARC_MACH_ARC600:
2584 strcat (buf, ", ARC600");
2585 break;
2586 case E_ARC_MACH_ARC601:
2587 strcat (buf, ", ARC601");
2588 break;
2589 case E_ARC_MACH_ARC700:
2590 strcat (buf, ", ARC700");
2591 break;
2592
2593 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2594 new ELF with new architecture being read by an old version of
2595 readelf, or (c) An ELF built with non-GNU compiler that does not
2596 set the architecture in the e_flags. */
2597 default:
2598 if (e_machine == EM_ARC_COMPACT)
2599 strcat (buf, ", Unknown ARCompact");
2600 else
2601 strcat (buf, ", Unknown ARC");
2602 break;
2603 }
2604
2605 switch (e_flags & EF_ARC_OSABI_MSK)
2606 {
2607 case E_ARC_OSABI_ORIG:
2608 strcat (buf, ", (ABI:legacy)");
2609 break;
2610 case E_ARC_OSABI_V2:
2611 strcat (buf, ", (ABI:v2)");
2612 break;
2613 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2614 case E_ARC_OSABI_V3:
2615 strcat (buf, ", v3 no-legacy-syscalls ABI");
2616 break;
53a346d8
CZ
2617 case E_ARC_OSABI_V4:
2618 strcat (buf, ", v4 ABI");
2619 break;
a9522a21
AB
2620 default:
2621 strcat (buf, ", unrecognised ARC OSABI flag");
2622 break;
2623 }
2624}
2625
f3485b74 2626static void
d3ba0551 2627decode_ARM_machine_flags (unsigned e_flags, char buf[])
f3485b74
NC
2628{
2629 unsigned eabi;
32ec8896 2630 bfd_boolean unknown = FALSE;
f3485b74
NC
2631
2632 eabi = EF_ARM_EABI_VERSION (e_flags);
2633 e_flags &= ~ EF_ARM_EABIMASK;
2634
2635 /* Handle "generic" ARM flags. */
2636 if (e_flags & EF_ARM_RELEXEC)
2637 {
2638 strcat (buf, ", relocatable executable");
2639 e_flags &= ~ EF_ARM_RELEXEC;
2640 }
76da6bbe 2641
18a20338
CL
2642 if (e_flags & EF_ARM_PIC)
2643 {
2644 strcat (buf, ", position independent");
2645 e_flags &= ~ EF_ARM_PIC;
2646 }
2647
f3485b74
NC
2648 /* Now handle EABI specific flags. */
2649 switch (eabi)
2650 {
2651 default:
2c71103e 2652 strcat (buf, ", <unrecognized EABI>");
f3485b74 2653 if (e_flags)
32ec8896 2654 unknown = TRUE;
f3485b74
NC
2655 break;
2656
2657 case EF_ARM_EABI_VER1:
a5bcd848 2658 strcat (buf, ", Version1 EABI");
f3485b74
NC
2659 while (e_flags)
2660 {
2661 unsigned flag;
76da6bbe 2662
f3485b74
NC
2663 /* Process flags one bit at a time. */
2664 flag = e_flags & - e_flags;
2665 e_flags &= ~ flag;
76da6bbe 2666
f3485b74
NC
2667 switch (flag)
2668 {
a5bcd848 2669 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
f3485b74
NC
2670 strcat (buf, ", sorted symbol tables");
2671 break;
76da6bbe 2672
f3485b74 2673 default:
32ec8896 2674 unknown = TRUE;
f3485b74
NC
2675 break;
2676 }
2677 }
2678 break;
76da6bbe 2679
a5bcd848
PB
2680 case EF_ARM_EABI_VER2:
2681 strcat (buf, ", Version2 EABI");
2682 while (e_flags)
2683 {
2684 unsigned flag;
2685
2686 /* Process flags one bit at a time. */
2687 flag = e_flags & - e_flags;
2688 e_flags &= ~ flag;
2689
2690 switch (flag)
2691 {
2692 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2693 strcat (buf, ", sorted symbol tables");
2694 break;
2695
2696 case EF_ARM_DYNSYMSUSESEGIDX:
2697 strcat (buf, ", dynamic symbols use segment index");
2698 break;
2699
2700 case EF_ARM_MAPSYMSFIRST:
2701 strcat (buf, ", mapping symbols precede others");
2702 break;
2703
2704 default:
32ec8896 2705 unknown = TRUE;
a5bcd848
PB
2706 break;
2707 }
2708 }
2709 break;
2710
d507cf36
PB
2711 case EF_ARM_EABI_VER3:
2712 strcat (buf, ", Version3 EABI");
8cb51566
PB
2713 break;
2714
2715 case EF_ARM_EABI_VER4:
2716 strcat (buf, ", Version4 EABI");
3bfcb652
NC
2717 while (e_flags)
2718 {
2719 unsigned flag;
2720
2721 /* Process flags one bit at a time. */
2722 flag = e_flags & - e_flags;
2723 e_flags &= ~ flag;
2724
2725 switch (flag)
2726 {
2727 case EF_ARM_BE8:
2728 strcat (buf, ", BE8");
2729 break;
2730
2731 case EF_ARM_LE8:
2732 strcat (buf, ", LE8");
2733 break;
2734
2735 default:
32ec8896 2736 unknown = TRUE;
3bfcb652
NC
2737 break;
2738 }
3bfcb652
NC
2739 }
2740 break;
3a4a14e9
PB
2741
2742 case EF_ARM_EABI_VER5:
2743 strcat (buf, ", Version5 EABI");
d507cf36
PB
2744 while (e_flags)
2745 {
2746 unsigned flag;
2747
2748 /* Process flags one bit at a time. */
2749 flag = e_flags & - e_flags;
2750 e_flags &= ~ flag;
2751
2752 switch (flag)
2753 {
2754 case EF_ARM_BE8:
2755 strcat (buf, ", BE8");
2756 break;
2757
2758 case EF_ARM_LE8:
2759 strcat (buf, ", LE8");
2760 break;
2761
3bfcb652
NC
2762 case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2763 strcat (buf, ", soft-float ABI");
2764 break;
2765
2766 case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
2767 strcat (buf, ", hard-float ABI");
2768 break;
2769
d507cf36 2770 default:
32ec8896 2771 unknown = TRUE;
d507cf36
PB
2772 break;
2773 }
2774 }
2775 break;
2776
f3485b74 2777 case EF_ARM_EABI_UNKNOWN:
a5bcd848 2778 strcat (buf, ", GNU EABI");
f3485b74
NC
2779 while (e_flags)
2780 {
2781 unsigned flag;
76da6bbe 2782
f3485b74
NC
2783 /* Process flags one bit at a time. */
2784 flag = e_flags & - e_flags;
2785 e_flags &= ~ flag;
76da6bbe 2786
f3485b74
NC
2787 switch (flag)
2788 {
a5bcd848 2789 case EF_ARM_INTERWORK:
f3485b74
NC
2790 strcat (buf, ", interworking enabled");
2791 break;
76da6bbe 2792
a5bcd848 2793 case EF_ARM_APCS_26:
f3485b74
NC
2794 strcat (buf, ", uses APCS/26");
2795 break;
76da6bbe 2796
a5bcd848 2797 case EF_ARM_APCS_FLOAT:
f3485b74
NC
2798 strcat (buf, ", uses APCS/float");
2799 break;
76da6bbe 2800
a5bcd848 2801 case EF_ARM_PIC:
f3485b74
NC
2802 strcat (buf, ", position independent");
2803 break;
76da6bbe 2804
a5bcd848 2805 case EF_ARM_ALIGN8:
f3485b74
NC
2806 strcat (buf, ", 8 bit structure alignment");
2807 break;
76da6bbe 2808
a5bcd848 2809 case EF_ARM_NEW_ABI:
f3485b74
NC
2810 strcat (buf, ", uses new ABI");
2811 break;
76da6bbe 2812
a5bcd848 2813 case EF_ARM_OLD_ABI:
f3485b74
NC
2814 strcat (buf, ", uses old ABI");
2815 break;
76da6bbe 2816
a5bcd848 2817 case EF_ARM_SOFT_FLOAT:
f3485b74
NC
2818 strcat (buf, ", software FP");
2819 break;
76da6bbe 2820
90e01f86
ILT
2821 case EF_ARM_VFP_FLOAT:
2822 strcat (buf, ", VFP");
2823 break;
2824
fde78edd
NC
2825 case EF_ARM_MAVERICK_FLOAT:
2826 strcat (buf, ", Maverick FP");
2827 break;
2828
f3485b74 2829 default:
32ec8896 2830 unknown = TRUE;
f3485b74
NC
2831 break;
2832 }
2833 }
2834 }
f3485b74
NC
2835
2836 if (unknown)
2b692964 2837 strcat (buf,_(", <unknown>"));
f3485b74
NC
2838}
2839
343433df
AB
2840static void
2841decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
2842{
2843 --size; /* Leave space for null terminator. */
2844
2845 switch (e_flags & EF_AVR_MACH)
2846 {
2847 case E_AVR_MACH_AVR1:
2848 strncat (buf, ", avr:1", size);
2849 break;
2850 case E_AVR_MACH_AVR2:
2851 strncat (buf, ", avr:2", size);
2852 break;
2853 case E_AVR_MACH_AVR25:
2854 strncat (buf, ", avr:25", size);
2855 break;
2856 case E_AVR_MACH_AVR3:
2857 strncat (buf, ", avr:3", size);
2858 break;
2859 case E_AVR_MACH_AVR31:
2860 strncat (buf, ", avr:31", size);
2861 break;
2862 case E_AVR_MACH_AVR35:
2863 strncat (buf, ", avr:35", size);
2864 break;
2865 case E_AVR_MACH_AVR4:
2866 strncat (buf, ", avr:4", size);
2867 break;
2868 case E_AVR_MACH_AVR5:
2869 strncat (buf, ", avr:5", size);
2870 break;
2871 case E_AVR_MACH_AVR51:
2872 strncat (buf, ", avr:51", size);
2873 break;
2874 case E_AVR_MACH_AVR6:
2875 strncat (buf, ", avr:6", size);
2876 break;
2877 case E_AVR_MACH_AVRTINY:
2878 strncat (buf, ", avr:100", size);
2879 break;
2880 case E_AVR_MACH_XMEGA1:
2881 strncat (buf, ", avr:101", size);
2882 break;
2883 case E_AVR_MACH_XMEGA2:
2884 strncat (buf, ", avr:102", size);
2885 break;
2886 case E_AVR_MACH_XMEGA3:
2887 strncat (buf, ", avr:103", size);
2888 break;
2889 case E_AVR_MACH_XMEGA4:
2890 strncat (buf, ", avr:104", size);
2891 break;
2892 case E_AVR_MACH_XMEGA5:
2893 strncat (buf, ", avr:105", size);
2894 break;
2895 case E_AVR_MACH_XMEGA6:
2896 strncat (buf, ", avr:106", size);
2897 break;
2898 case E_AVR_MACH_XMEGA7:
2899 strncat (buf, ", avr:107", size);
2900 break;
2901 default:
2902 strncat (buf, ", avr:<unknown>", size);
2903 break;
2904 }
2905
2906 size -= strlen (buf);
2907 if (e_flags & EF_AVR_LINKRELAX_PREPARED)
2908 strncat (buf, ", link-relax", size);
2909}
2910
35c08157
KLC
2911static void
2912decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
2913{
2914 unsigned abi;
2915 unsigned arch;
2916 unsigned config;
2917 unsigned version;
32ec8896
NC
2918 bfd_boolean has_fpu = FALSE;
2919 unsigned int r = 0;
35c08157
KLC
2920
2921 static const char *ABI_STRINGS[] =
2922 {
2923 "ABI v0", /* use r5 as return register; only used in N1213HC */
2924 "ABI v1", /* use r0 as return register */
2925 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2926 "ABI v2fp", /* for FPU */
40c7a7cb
KLC
2927 "AABI",
2928 "ABI2 FP+"
35c08157
KLC
2929 };
2930 static const char *VER_STRINGS[] =
2931 {
2932 "Andes ELF V1.3 or older",
2933 "Andes ELF V1.3.1",
2934 "Andes ELF V1.4"
2935 };
2936 static const char *ARCH_STRINGS[] =
2937 {
2938 "",
2939 "Andes Star v1.0",
2940 "Andes Star v2.0",
2941 "Andes Star v3.0",
2942 "Andes Star v3.0m"
2943 };
2944
2945 abi = EF_NDS_ABI & e_flags;
2946 arch = EF_NDS_ARCH & e_flags;
2947 config = EF_NDS_INST & e_flags;
2948 version = EF_NDS32_ELF_VERSION & e_flags;
2949
2950 memset (buf, 0, size);
2951
2952 switch (abi)
2953 {
2954 case E_NDS_ABI_V0:
2955 case E_NDS_ABI_V1:
2956 case E_NDS_ABI_V2:
2957 case E_NDS_ABI_V2FP:
2958 case E_NDS_ABI_AABI:
40c7a7cb 2959 case E_NDS_ABI_V2FP_PLUS:
35c08157
KLC
2960 /* In case there are holes in the array. */
2961 r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
2962 break;
2963
2964 default:
2965 r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
2966 break;
2967 }
2968
2969 switch (version)
2970 {
2971 case E_NDS32_ELF_VER_1_2:
2972 case E_NDS32_ELF_VER_1_3:
2973 case E_NDS32_ELF_VER_1_4:
2974 r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
2975 break;
2976
2977 default:
2978 r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
2979 break;
2980 }
2981
2982 if (E_NDS_ABI_V0 == abi)
2983 {
2984 /* OLD ABI; only used in N1213HC, has performance extension 1. */
2985 r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
2986 if (arch == E_NDS_ARCH_STAR_V1_0)
2987 r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
2988 return;
2989 }
2990
2991 switch (arch)
2992 {
2993 case E_NDS_ARCH_STAR_V1_0:
2994 case E_NDS_ARCH_STAR_V2_0:
2995 case E_NDS_ARCH_STAR_V3_0:
2996 case E_NDS_ARCH_STAR_V3_M:
2997 r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
2998 break;
2999
3000 default:
3001 r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
3002 /* ARCH version determines how the e_flags are interpreted.
3003 If it is unknown, we cannot proceed. */
3004 return;
3005 }
3006
3007 /* Newer ABI; Now handle architecture specific flags. */
3008 if (arch == E_NDS_ARCH_STAR_V1_0)
3009 {
3010 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3011 r += snprintf (buf + r, size -r, ", MFUSR_PC");
3012
3013 if (!(config & E_NDS32_HAS_NO_MAC_INST))
3014 r += snprintf (buf + r, size -r, ", MAC");
3015
3016 if (config & E_NDS32_HAS_DIV_INST)
3017 r += snprintf (buf + r, size -r, ", DIV");
3018
3019 if (config & E_NDS32_HAS_16BIT_INST)
3020 r += snprintf (buf + r, size -r, ", 16b");
3021 }
3022 else
3023 {
3024 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3025 {
3026 if (version <= E_NDS32_ELF_VER_1_3)
3027 r += snprintf (buf + r, size -r, ", [B8]");
3028 else
3029 r += snprintf (buf + r, size -r, ", EX9");
3030 }
3031
3032 if (config & E_NDS32_HAS_MAC_DX_INST)
3033 r += snprintf (buf + r, size -r, ", MAC_DX");
3034
3035 if (config & E_NDS32_HAS_DIV_DX_INST)
3036 r += snprintf (buf + r, size -r, ", DIV_DX");
3037
3038 if (config & E_NDS32_HAS_16BIT_INST)
3039 {
3040 if (version <= E_NDS32_ELF_VER_1_3)
3041 r += snprintf (buf + r, size -r, ", 16b");
3042 else
3043 r += snprintf (buf + r, size -r, ", IFC");
3044 }
3045 }
3046
3047 if (config & E_NDS32_HAS_EXT_INST)
3048 r += snprintf (buf + r, size -r, ", PERF1");
3049
3050 if (config & E_NDS32_HAS_EXT2_INST)
3051 r += snprintf (buf + r, size -r, ", PERF2");
3052
3053 if (config & E_NDS32_HAS_FPU_INST)
3054 {
32ec8896 3055 has_fpu = TRUE;
35c08157
KLC
3056 r += snprintf (buf + r, size -r, ", FPU_SP");
3057 }
3058
3059 if (config & E_NDS32_HAS_FPU_DP_INST)
3060 {
32ec8896 3061 has_fpu = TRUE;
35c08157
KLC
3062 r += snprintf (buf + r, size -r, ", FPU_DP");
3063 }
3064
3065 if (config & E_NDS32_HAS_FPU_MAC_INST)
3066 {
32ec8896 3067 has_fpu = TRUE;
35c08157
KLC
3068 r += snprintf (buf + r, size -r, ", FPU_MAC");
3069 }
3070
3071 if (has_fpu)
3072 {
3073 switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
3074 {
3075 case E_NDS32_FPU_REG_8SP_4DP:
3076 r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
3077 break;
3078 case E_NDS32_FPU_REG_16SP_8DP:
3079 r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
3080 break;
3081 case E_NDS32_FPU_REG_32SP_16DP:
3082 r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
3083 break;
3084 case E_NDS32_FPU_REG_32SP_32DP:
3085 r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
3086 break;
3087 }
3088 }
3089
3090 if (config & E_NDS32_HAS_AUDIO_INST)
3091 r += snprintf (buf + r, size -r, ", AUDIO");
3092
3093 if (config & E_NDS32_HAS_STRING_INST)
3094 r += snprintf (buf + r, size -r, ", STR");
3095
3096 if (config & E_NDS32_HAS_REDUCED_REGS)
3097 r += snprintf (buf + r, size -r, ", 16REG");
3098
3099 if (config & E_NDS32_HAS_VIDEO_INST)
3100 {
3101 if (version <= E_NDS32_ELF_VER_1_3)
3102 r += snprintf (buf + r, size -r, ", VIDEO");
3103 else
3104 r += snprintf (buf + r, size -r, ", SATURATION");
3105 }
3106
3107 if (config & E_NDS32_HAS_ENCRIPT_INST)
3108 r += snprintf (buf + r, size -r, ", ENCRP");
3109
3110 if (config & E_NDS32_HAS_L2C_INST)
3111 r += snprintf (buf + r, size -r, ", L2C");
3112}
3113
252b5132 3114static char *
dda8d76d 3115get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
252b5132 3116{
b34976b6 3117 static char buf[1024];
252b5132
RH
3118
3119 buf[0] = '\0';
76da6bbe 3120
252b5132
RH
3121 if (e_flags)
3122 {
3123 switch (e_machine)
3124 {
3125 default:
3126 break;
3127
886a2506 3128 case EM_ARC_COMPACT2:
886a2506 3129 case EM_ARC_COMPACT:
a9522a21
AB
3130 decode_ARC_machine_flags (e_flags, e_machine, buf);
3131 break;
886a2506 3132
f3485b74
NC
3133 case EM_ARM:
3134 decode_ARM_machine_flags (e_flags, buf);
3135 break;
76da6bbe 3136
343433df
AB
3137 case EM_AVR:
3138 decode_AVR_machine_flags (e_flags, buf, sizeof buf);
3139 break;
3140
781303ce
MF
3141 case EM_BLACKFIN:
3142 if (e_flags & EF_BFIN_PIC)
3143 strcat (buf, ", PIC");
3144
3145 if (e_flags & EF_BFIN_FDPIC)
3146 strcat (buf, ", FDPIC");
3147
3148 if (e_flags & EF_BFIN_CODE_IN_L1)
3149 strcat (buf, ", code in L1");
3150
3151 if (e_flags & EF_BFIN_DATA_IN_L1)
3152 strcat (buf, ", data in L1");
3153
3154 break;
3155
ec2dfb42
AO
3156 case EM_CYGNUS_FRV:
3157 switch (e_flags & EF_FRV_CPU_MASK)
3158 {
3159 case EF_FRV_CPU_GENERIC:
3160 break;
3161
3162 default:
3163 strcat (buf, ", fr???");
3164 break;
57346661 3165
ec2dfb42
AO
3166 case EF_FRV_CPU_FR300:
3167 strcat (buf, ", fr300");
3168 break;
3169
3170 case EF_FRV_CPU_FR400:
3171 strcat (buf, ", fr400");
3172 break;
3173 case EF_FRV_CPU_FR405:
3174 strcat (buf, ", fr405");
3175 break;
3176
3177 case EF_FRV_CPU_FR450:
3178 strcat (buf, ", fr450");
3179 break;
3180
3181 case EF_FRV_CPU_FR500:
3182 strcat (buf, ", fr500");
3183 break;
3184 case EF_FRV_CPU_FR550:
3185 strcat (buf, ", fr550");
3186 break;
3187
3188 case EF_FRV_CPU_SIMPLE:
3189 strcat (buf, ", simple");
3190 break;
3191 case EF_FRV_CPU_TOMCAT:
3192 strcat (buf, ", tomcat");
3193 break;
3194 }
1c877e87 3195 break;
ec2dfb42 3196
53c7db4b 3197 case EM_68K:
425c6cb0 3198 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
76f57f3a 3199 strcat (buf, ", m68000");
425c6cb0 3200 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
3bdcfdf4
KH
3201 strcat (buf, ", cpu32");
3202 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
3203 strcat (buf, ", fido_a");
425c6cb0 3204 else
266abb8f 3205 {
2cf0635d
NC
3206 char const * isa = _("unknown");
3207 char const * mac = _("unknown mac");
3208 char const * additional = NULL;
0112cd26 3209
c694fd50 3210 switch (e_flags & EF_M68K_CF_ISA_MASK)
266abb8f 3211 {
c694fd50 3212 case EF_M68K_CF_ISA_A_NODIV:
0b2e31dc
NS
3213 isa = "A";
3214 additional = ", nodiv";
3215 break;
c694fd50 3216 case EF_M68K_CF_ISA_A:
266abb8f
NS
3217 isa = "A";
3218 break;
c694fd50 3219 case EF_M68K_CF_ISA_A_PLUS:
266abb8f
NS
3220 isa = "A+";
3221 break;
c694fd50 3222 case EF_M68K_CF_ISA_B_NOUSP:
0b2e31dc
NS
3223 isa = "B";
3224 additional = ", nousp";
3225 break;
c694fd50 3226 case EF_M68K_CF_ISA_B:
266abb8f
NS
3227 isa = "B";
3228 break;
f608cd77
NS
3229 case EF_M68K_CF_ISA_C:
3230 isa = "C";
3231 break;
3232 case EF_M68K_CF_ISA_C_NODIV:
3233 isa = "C";
3234 additional = ", nodiv";
3235 break;
266abb8f
NS
3236 }
3237 strcat (buf, ", cf, isa ");
3238 strcat (buf, isa);
0b2e31dc
NS
3239 if (additional)
3240 strcat (buf, additional);
c694fd50 3241 if (e_flags & EF_M68K_CF_FLOAT)
0b2e31dc 3242 strcat (buf, ", float");
c694fd50 3243 switch (e_flags & EF_M68K_CF_MAC_MASK)
266abb8f
NS
3244 {
3245 case 0:
3246 mac = NULL;
3247 break;
c694fd50 3248 case EF_M68K_CF_MAC:
266abb8f
NS
3249 mac = "mac";
3250 break;
c694fd50 3251 case EF_M68K_CF_EMAC:
266abb8f
NS
3252 mac = "emac";
3253 break;
f608cd77
NS
3254 case EF_M68K_CF_EMAC_B:
3255 mac = "emac_b";
3256 break;
266abb8f
NS
3257 }
3258 if (mac)
3259 {
3260 strcat (buf, ", ");
3261 strcat (buf, mac);
3262 }
266abb8f 3263 }
53c7db4b 3264 break;
33c63f9d 3265
153a2776
NC
3266 case EM_CYGNUS_MEP:
3267 switch (e_flags & EF_MEP_CPU_MASK)
3268 {
3269 case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
3270 case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
3271 case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
3272 case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
3273 case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
3274 case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
3275 default: strcat (buf, _(", <unknown MeP cpu type>")); break;
3276 }
3277
3278 switch (e_flags & EF_MEP_COP_MASK)
3279 {
3280 case EF_MEP_COP_NONE: break;
3281 case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
3282 case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
3283 case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
3284 case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
3285 default: strcat (buf, _("<unknown MeP copro type>")); break;
3286 }
3287
3288 if (e_flags & EF_MEP_LIBRARY)
3289 strcat (buf, ", Built for Library");
3290
3291 if (e_flags & EF_MEP_INDEX_MASK)
3292 sprintf (buf + strlen (buf), ", Configuration Index: %#x",
3293 e_flags & EF_MEP_INDEX_MASK);
3294
3295 if (e_flags & ~ EF_MEP_ALL_FLAGS)
3296 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
3297 e_flags & ~ EF_MEP_ALL_FLAGS);
3298 break;
3299
252b5132
RH
3300 case EM_PPC:
3301 if (e_flags & EF_PPC_EMB)
3302 strcat (buf, ", emb");
3303
3304 if (e_flags & EF_PPC_RELOCATABLE)
2b692964 3305 strcat (buf, _(", relocatable"));
252b5132
RH
3306
3307 if (e_flags & EF_PPC_RELOCATABLE_LIB)
2b692964 3308 strcat (buf, _(", relocatable-lib"));
252b5132
RH
3309 break;
3310
ee67d69a
AM
3311 case EM_PPC64:
3312 if (e_flags & EF_PPC64_ABI)
3313 {
3314 char abi[] = ", abiv0";
3315
3316 abi[6] += e_flags & EF_PPC64_ABI;
3317 strcat (buf, abi);
3318 }
3319 break;
3320
708e2187
NC
3321 case EM_V800:
3322 if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
3323 strcat (buf, ", RH850 ABI");
0b4362b0 3324
708e2187
NC
3325 if (e_flags & EF_V800_850E3)
3326 strcat (buf, ", V3 architecture");
3327
3328 if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
3329 strcat (buf, ", FPU not used");
3330
3331 if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
3332 strcat (buf, ", regmode: COMMON");
3333
3334 if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
3335 strcat (buf, ", r4 not used");
3336
3337 if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
3338 strcat (buf, ", r30 not used");
3339
3340 if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
3341 strcat (buf, ", r5 not used");
3342
3343 if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
3344 strcat (buf, ", r2 not used");
3345
3346 for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
3347 {
3348 switch (e_flags & - e_flags)
3349 {
3350 case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
3351 case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
708e2187
NC
3352 case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
3353 case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
708e2187
NC
3354 case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
3355 case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
3356 case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
3357 case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
3358 case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
3359 case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
3360 case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
3361 case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
3362 default: break;
3363 }
3364 }
3365 break;
3366
2b0337b0 3367 case EM_V850:
252b5132
RH
3368 case EM_CYGNUS_V850:
3369 switch (e_flags & EF_V850_ARCH)
3370 {
78c8d46c
NC
3371 case E_V850E3V5_ARCH:
3372 strcat (buf, ", v850e3v5");
3373 break;
1cd986c5
NC
3374 case E_V850E2V3_ARCH:
3375 strcat (buf, ", v850e2v3");
3376 break;
3377 case E_V850E2_ARCH:
3378 strcat (buf, ", v850e2");
3379 break;
3380 case E_V850E1_ARCH:
3381 strcat (buf, ", v850e1");
8ad30312 3382 break;
252b5132
RH
3383 case E_V850E_ARCH:
3384 strcat (buf, ", v850e");
3385 break;
252b5132
RH
3386 case E_V850_ARCH:
3387 strcat (buf, ", v850");
3388 break;
3389 default:
2b692964 3390 strcat (buf, _(", unknown v850 architecture variant"));
252b5132
RH
3391 break;
3392 }
3393 break;
3394
2b0337b0 3395 case EM_M32R:
252b5132
RH
3396 case EM_CYGNUS_M32R:
3397 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3398 strcat (buf, ", m32r");
252b5132
RH
3399 break;
3400
3401 case EM_MIPS:
4fe85591 3402 case EM_MIPS_RS3_LE:
252b5132
RH
3403 if (e_flags & EF_MIPS_NOREORDER)
3404 strcat (buf, ", noreorder");
3405
3406 if (e_flags & EF_MIPS_PIC)
3407 strcat (buf, ", pic");
3408
3409 if (e_flags & EF_MIPS_CPIC)
3410 strcat (buf, ", cpic");
3411
d1bdd336
TS
3412 if (e_flags & EF_MIPS_UCODE)
3413 strcat (buf, ", ugen_reserved");
3414
252b5132
RH
3415 if (e_flags & EF_MIPS_ABI2)
3416 strcat (buf, ", abi2");
3417
43521d43
TS
3418 if (e_flags & EF_MIPS_OPTIONS_FIRST)
3419 strcat (buf, ", odk first");
3420
a5d22d2a
TS
3421 if (e_flags & EF_MIPS_32BITMODE)
3422 strcat (buf, ", 32bitmode");
3423
ba92f887
MR
3424 if (e_flags & EF_MIPS_NAN2008)
3425 strcat (buf, ", nan2008");
3426
fef1b0b3
SE
3427 if (e_flags & EF_MIPS_FP64)
3428 strcat (buf, ", fp64");
3429
156c2f8b
NC
3430 switch ((e_flags & EF_MIPS_MACH))
3431 {
3432 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
3433 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
3434 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
156c2f8b 3435 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
810dfa6e
L
3436 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
3437 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
3438 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
3439 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
ef272caa 3440 case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break;
c6c98b38 3441 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
ebcb91b7 3442 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
350cc38d
MS
3443 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
3444 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
ac8cb70f 3445 case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break;
bd782c07 3446 case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break;
9108bc33 3447 case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break;
05c6f050 3448 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
67c2a3e8 3449 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
d32e5c54 3450 case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
52b6b6b9 3451 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
38bf472a 3452 case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break;
43521d43
TS
3453 case 0:
3454 /* We simply ignore the field in this case to avoid confusion:
3455 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3456 extension. */
3457 break;
2b692964 3458 default: strcat (buf, _(", unknown CPU")); break;
156c2f8b 3459 }
43521d43
TS
3460
3461 switch ((e_flags & EF_MIPS_ABI))
3462 {
3463 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
3464 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
3465 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
3466 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
3467 case 0:
3468 /* We simply ignore the field in this case to avoid confusion:
3469 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3470 This means it is likely to be an o32 file, but not for
3471 sure. */
3472 break;
2b692964 3473 default: strcat (buf, _(", unknown ABI")); break;
43521d43
TS
3474 }
3475
3476 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
3477 strcat (buf, ", mdmx");
3478
3479 if (e_flags & EF_MIPS_ARCH_ASE_M16)
3480 strcat (buf, ", mips16");
3481
df58fc94
RS
3482 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
3483 strcat (buf, ", micromips");
3484
43521d43
TS
3485 switch ((e_flags & EF_MIPS_ARCH))
3486 {
3487 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
3488 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
3489 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
3490 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
3491 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
3492 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
cb44e358 3493 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
7361da2c 3494 case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
43521d43 3495 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
5f74bc13 3496 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
7361da2c 3497 case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
2b692964 3498 default: strcat (buf, _(", unknown ISA")); break;
43521d43 3499 }
252b5132 3500 break;
351b4b40 3501
35c08157
KLC
3502 case EM_NDS32:
3503 decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
3504 break;
3505
fe944acf
FT
3506 case EM_NFP:
3507 switch (EF_NFP_MACH (e_flags))
3508 {
3509 case E_NFP_MACH_3200:
3510 strcat (buf, ", NFP-32xx");
3511 break;
3512 case E_NFP_MACH_6000:
3513 strcat (buf, ", NFP-6xxx");
3514 break;
3515 }
3516 break;
3517
e23eba97
NC
3518 case EM_RISCV:
3519 if (e_flags & EF_RISCV_RVC)
3520 strcat (buf, ", RVC");
2922d21d 3521
7f999549
JW
3522 if (e_flags & EF_RISCV_RVE)
3523 strcat (buf, ", RVE");
3524
2922d21d
AW
3525 switch (e_flags & EF_RISCV_FLOAT_ABI)
3526 {
3527 case EF_RISCV_FLOAT_ABI_SOFT:
3528 strcat (buf, ", soft-float ABI");
3529 break;
3530
3531 case EF_RISCV_FLOAT_ABI_SINGLE:
3532 strcat (buf, ", single-float ABI");
3533 break;
3534
3535 case EF_RISCV_FLOAT_ABI_DOUBLE:
3536 strcat (buf, ", double-float ABI");
3537 break;
3538
3539 case EF_RISCV_FLOAT_ABI_QUAD:
3540 strcat (buf, ", quad-float ABI");
3541 break;
3542 }
e23eba97
NC
3543 break;
3544
ccde1100
AO
3545 case EM_SH:
3546 switch ((e_flags & EF_SH_MACH_MASK))
3547 {
3548 case EF_SH1: strcat (buf, ", sh1"); break;
3549 case EF_SH2: strcat (buf, ", sh2"); break;
3550 case EF_SH3: strcat (buf, ", sh3"); break;
3551 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
3552 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
3553 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
3554 case EF_SH3E: strcat (buf, ", sh3e"); break;
3555 case EF_SH4: strcat (buf, ", sh4"); break;
3556 case EF_SH5: strcat (buf, ", sh5"); break;
3557 case EF_SH2E: strcat (buf, ", sh2e"); break;
3558 case EF_SH4A: strcat (buf, ", sh4a"); break;
1d70c7fb 3559 case EF_SH2A: strcat (buf, ", sh2a"); break;
ccde1100
AO
3560 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
3561 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
1d70c7fb 3562 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
0b92ab21
NH
3563 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
3564 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
3565 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3566 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
3567 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
3568 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
2b692964 3569 default: strcat (buf, _(", unknown ISA")); break;
ccde1100
AO
3570 }
3571
cec6a5b8
MR
3572 if (e_flags & EF_SH_PIC)
3573 strcat (buf, ", pic");
3574
3575 if (e_flags & EF_SH_FDPIC)
3576 strcat (buf, ", fdpic");
ccde1100 3577 break;
948f632f 3578
73589c9d
CS
3579 case EM_OR1K:
3580 if (e_flags & EF_OR1K_NODELAY)
3581 strcat (buf, ", no delay");
3582 break;
57346661 3583
351b4b40
RH
3584 case EM_SPARCV9:
3585 if (e_flags & EF_SPARC_32PLUS)
3586 strcat (buf, ", v8+");
3587
3588 if (e_flags & EF_SPARC_SUN_US1)
d07faca2
RH
3589 strcat (buf, ", ultrasparcI");
3590
3591 if (e_flags & EF_SPARC_SUN_US3)
3592 strcat (buf, ", ultrasparcIII");
351b4b40
RH
3593
3594 if (e_flags & EF_SPARC_HAL_R1)
3595 strcat (buf, ", halr1");
3596
3597 if (e_flags & EF_SPARC_LEDATA)
3598 strcat (buf, ", ledata");
3599
3600 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
3601 strcat (buf, ", tso");
3602
3603 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
3604 strcat (buf, ", pso");
3605
3606 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
3607 strcat (buf, ", rmo");
3608 break;
7d466069 3609
103f02d3
UD
3610 case EM_PARISC:
3611 switch (e_flags & EF_PARISC_ARCH)
3612 {
3613 case EFA_PARISC_1_0:
3614 strcpy (buf, ", PA-RISC 1.0");
3615 break;
3616 case EFA_PARISC_1_1:
3617 strcpy (buf, ", PA-RISC 1.1");
3618 break;
3619 case EFA_PARISC_2_0:
3620 strcpy (buf, ", PA-RISC 2.0");
3621 break;
3622 default:
3623 break;
3624 }
3625 if (e_flags & EF_PARISC_TRAPNIL)
3626 strcat (buf, ", trapnil");
3627 if (e_flags & EF_PARISC_EXT)
3628 strcat (buf, ", ext");
3629 if (e_flags & EF_PARISC_LSB)
3630 strcat (buf, ", lsb");
3631 if (e_flags & EF_PARISC_WIDE)
3632 strcat (buf, ", wide");
3633 if (e_flags & EF_PARISC_NO_KABP)
3634 strcat (buf, ", no kabp");
3635 if (e_flags & EF_PARISC_LAZYSWAP)
3636 strcat (buf, ", lazyswap");
30800947 3637 break;
76da6bbe 3638
7d466069 3639 case EM_PJ:
2b0337b0 3640 case EM_PJ_OLD:
7d466069
ILT
3641 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
3642 strcat (buf, ", new calling convention");
3643
3644 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
3645 strcat (buf, ", gnu calling convention");
3646 break;
4d6ed7c8
NC
3647
3648 case EM_IA_64:
3649 if ((e_flags & EF_IA_64_ABI64))
3650 strcat (buf, ", 64-bit");
3651 else
3652 strcat (buf, ", 32-bit");
3653 if ((e_flags & EF_IA_64_REDUCEDFP))
3654 strcat (buf, ", reduced fp model");
3655 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
3656 strcat (buf, ", no function descriptors, constant gp");
3657 else if ((e_flags & EF_IA_64_CONS_GP))
3658 strcat (buf, ", constant gp");
3659 if ((e_flags & EF_IA_64_ABSOLUTE))
3660 strcat (buf, ", absolute");
dda8d76d 3661 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
28f997cf
TG
3662 {
3663 if ((e_flags & EF_IA_64_VMS_LINKAGES))
3664 strcat (buf, ", vms_linkages");
3665 switch ((e_flags & EF_IA_64_VMS_COMCOD))
3666 {
3667 case EF_IA_64_VMS_COMCOD_SUCCESS:
3668 break;
3669 case EF_IA_64_VMS_COMCOD_WARNING:
3670 strcat (buf, ", warning");
3671 break;
3672 case EF_IA_64_VMS_COMCOD_ERROR:
3673 strcat (buf, ", error");
3674 break;
3675 case EF_IA_64_VMS_COMCOD_ABORT:
3676 strcat (buf, ", abort");
3677 break;
3678 default:
bee0ee85
NC
3679 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3680 e_flags & EF_IA_64_VMS_COMCOD);
3681 strcat (buf, ", <unknown>");
28f997cf
TG
3682 }
3683 }
4d6ed7c8 3684 break;
179d3252
JT
3685
3686 case EM_VAX:
3687 if ((e_flags & EF_VAX_NONPIC))
3688 strcat (buf, ", non-PIC");
3689 if ((e_flags & EF_VAX_DFLOAT))
3690 strcat (buf, ", D-Float");
3691 if ((e_flags & EF_VAX_GFLOAT))
3692 strcat (buf, ", G-Float");
3693 break;
c7927a3c 3694
619ed720
EB
3695 case EM_VISIUM:
3696 if (e_flags & EF_VISIUM_ARCH_MCM)
3697 strcat (buf, ", mcm");
3698 else if (e_flags & EF_VISIUM_ARCH_MCM24)
3699 strcat (buf, ", mcm24");
3700 if (e_flags & EF_VISIUM_ARCH_GR6)
3701 strcat (buf, ", gr6");
3702 break;
3703
4046d87a 3704 case EM_RL78:
1740ba0c
NC
3705 switch (e_flags & E_FLAG_RL78_CPU_MASK)
3706 {
3707 case E_FLAG_RL78_ANY_CPU: break;
3708 case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
3709 case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
3710 case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
3711 }
856ea05c
KP
3712 if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
3713 strcat (buf, ", 64-bit doubles");
4046d87a 3714 break;
0b4362b0 3715
c7927a3c
NC
3716 case EM_RX:
3717 if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
3718 strcat (buf, ", 64-bit doubles");
3719 if (e_flags & E_FLAG_RX_DSP)
dd24e3da 3720 strcat (buf, ", dsp");
d4cb0ea0 3721 if (e_flags & E_FLAG_RX_PID)
0b4362b0 3722 strcat (buf, ", pid");
708e2187
NC
3723 if (e_flags & E_FLAG_RX_ABI)
3724 strcat (buf, ", RX ABI");
3525236c
NC
3725 if (e_flags & E_FLAG_RX_SINSNS_SET)
3726 strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
3727 ? ", uses String instructions" : ", bans String instructions");
a117b0a5
YS
3728 if (e_flags & E_FLAG_RX_V2)
3729 strcat (buf, ", V2");
f87673e0
YS
3730 if (e_flags & E_FLAG_RX_V3)
3731 strcat (buf, ", V3");
d4cb0ea0 3732 break;
55786da2
AK
3733
3734 case EM_S390:
3735 if (e_flags & EF_S390_HIGH_GPRS)
3736 strcat (buf, ", highgprs");
d4cb0ea0 3737 break;
40b36596
JM
3738
3739 case EM_TI_C6000:
3740 if ((e_flags & EF_C6000_REL))
3741 strcat (buf, ", relocatable module");
d4cb0ea0 3742 break;
13761a11
NC
3743
3744 case EM_MSP430:
3745 strcat (buf, _(": architecture variant: "));
3746 switch (e_flags & EF_MSP430_MACH)
3747 {
3748 case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
3749 case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
3750 case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
3751 case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
3752 case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
3753 case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
3754 case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
3755 case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
3756 case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
3757 case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
3758 case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
3759 case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
3760 case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
3761 case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
3762 case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
3763 default:
3764 strcat (buf, _(": unknown")); break;
3765 }
3766
3767 if (e_flags & ~ EF_MSP430_MACH)
3768 strcat (buf, _(": unknown extra flag bits also present"));
252b5132
RH
3769 }
3770 }
3771
3772 return buf;
3773}
3774
252b5132 3775static const char *
dda8d76d 3776get_osabi_name (Filedata * filedata, unsigned int osabi)
d3ba0551
AM
3777{
3778 static char buff[32];
3779
3780 switch (osabi)
3781 {
3782 case ELFOSABI_NONE: return "UNIX - System V";
3783 case ELFOSABI_HPUX: return "UNIX - HP-UX";
3784 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
9c55345c 3785 case ELFOSABI_GNU: return "UNIX - GNU";
d3ba0551
AM
3786 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
3787 case ELFOSABI_AIX: return "UNIX - AIX";
3788 case ELFOSABI_IRIX: return "UNIX - IRIX";
3789 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
3790 case ELFOSABI_TRU64: return "UNIX - TRU64";
3791 case ELFOSABI_MODESTO: return "Novell - Modesto";
3792 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
3793 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
3794 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
3b26c801 3795 case ELFOSABI_AROS: return "AROS";
11636f9e 3796 case ELFOSABI_FENIXOS: return "FenixOS";
6d913794
NC
3797 case ELFOSABI_CLOUDABI: return "Nuxi CloudABI";
3798 case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS";
d3ba0551 3799 default:
40b36596 3800 if (osabi >= 64)
dda8d76d 3801 switch (filedata->file_header.e_machine)
40b36596
JM
3802 {
3803 case EM_ARM:
3804 switch (osabi)
3805 {
3806 case ELFOSABI_ARM: return "ARM";
18a20338 3807 case ELFOSABI_ARM_FDPIC: return "ARM FDPIC";
40b36596
JM
3808 default:
3809 break;
3810 }
3811 break;
3812
3813 case EM_MSP430:
3814 case EM_MSP430_OLD:
619ed720 3815 case EM_VISIUM:
40b36596
JM
3816 switch (osabi)
3817 {
3818 case ELFOSABI_STANDALONE: return _("Standalone App");
3819 default:
3820 break;
3821 }
3822 break;
3823
3824 case EM_TI_C6000:
3825 switch (osabi)
3826 {
3827 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
3828 case ELFOSABI_C6000_LINUX: return "Linux C6000";
3829 default:
3830 break;
3831 }
3832 break;
3833
3834 default:
3835 break;
3836 }
e9e44622 3837 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
d3ba0551
AM
3838 return buff;
3839 }
3840}
3841
a06ea964
NC
3842static const char *
3843get_aarch64_segment_type (unsigned long type)
3844{
3845 switch (type)
3846 {
32ec8896
NC
3847 case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT";
3848 default: return NULL;
a06ea964 3849 }
a06ea964
NC
3850}
3851
b294bdf8
MM
3852static const char *
3853get_arm_segment_type (unsigned long type)
3854{
3855 switch (type)
3856 {
32ec8896
NC
3857 case PT_ARM_EXIDX: return "EXIDX";
3858 default: return NULL;
b294bdf8 3859 }
b294bdf8
MM
3860}
3861
b4cbbe8f
AK
3862static const char *
3863get_s390_segment_type (unsigned long type)
3864{
3865 switch (type)
3866 {
3867 case PT_S390_PGSTE: return "S390_PGSTE";
3868 default: return NULL;
3869 }
3870}
3871
d3ba0551
AM
3872static const char *
3873get_mips_segment_type (unsigned long type)
252b5132
RH
3874{
3875 switch (type)
3876 {
32ec8896
NC
3877 case PT_MIPS_REGINFO: return "REGINFO";
3878 case PT_MIPS_RTPROC: return "RTPROC";
3879 case PT_MIPS_OPTIONS: return "OPTIONS";
3880 case PT_MIPS_ABIFLAGS: return "ABIFLAGS";
3881 default: return NULL;
252b5132 3882 }
252b5132
RH
3883}
3884
103f02d3 3885static const char *
d3ba0551 3886get_parisc_segment_type (unsigned long type)
103f02d3
UD
3887{
3888 switch (type)
3889 {
3890 case PT_HP_TLS: return "HP_TLS";
3891 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
3892 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
3893 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
3894 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
3895 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
3896 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
3897 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
3898 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
3899 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
3900 case PT_HP_PARALLEL: return "HP_PARALLEL";
3901 case PT_HP_FASTBIND: return "HP_FASTBIND";
eec8f817
DA
3902 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
3903 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
3904 case PT_HP_STACK: return "HP_STACK";
3905 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
103f02d3
UD
3906 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
3907 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
61472819 3908 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
32ec8896 3909 default: return NULL;
103f02d3 3910 }
103f02d3
UD
3911}
3912
4d6ed7c8 3913static const char *
d3ba0551 3914get_ia64_segment_type (unsigned long type)
4d6ed7c8
NC
3915{
3916 switch (type)
3917 {
3918 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
3919 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
00428cca
AM
3920 case PT_HP_TLS: return "HP_TLS";
3921 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
3922 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
3923 case PT_IA_64_HP_STACK: return "HP_STACK";
32ec8896 3924 default: return NULL;
4d6ed7c8 3925 }
4d6ed7c8
NC
3926}
3927
40b36596
JM
3928static const char *
3929get_tic6x_segment_type (unsigned long type)
3930{
3931 switch (type)
3932 {
32ec8896
NC
3933 case PT_C6000_PHATTR: return "C6000_PHATTR";
3934 default: return NULL;
40b36596 3935 }
40b36596
JM
3936}
3937
5522f910
NC
3938static const char *
3939get_solaris_segment_type (unsigned long type)
3940{
3941 switch (type)
3942 {
3943 case 0x6464e550: return "PT_SUNW_UNWIND";
3944 case 0x6474e550: return "PT_SUNW_EH_FRAME";
3945 case 0x6ffffff7: return "PT_LOSUNW";
3946 case 0x6ffffffa: return "PT_SUNWBSS";
3947 case 0x6ffffffb: return "PT_SUNWSTACK";
3948 case 0x6ffffffc: return "PT_SUNWDTRACE";
3949 case 0x6ffffffd: return "PT_SUNWCAP";
3950 case 0x6fffffff: return "PT_HISUNW";
32ec8896 3951 default: return NULL;
5522f910
NC
3952 }
3953}
3954
252b5132 3955static const char *
dda8d76d 3956get_segment_type (Filedata * filedata, unsigned long p_type)
252b5132 3957{
b34976b6 3958 static char buff[32];
252b5132
RH
3959
3960 switch (p_type)
3961 {
b34976b6
AM
3962 case PT_NULL: return "NULL";
3963 case PT_LOAD: return "LOAD";
252b5132 3964 case PT_DYNAMIC: return "DYNAMIC";
b34976b6
AM
3965 case PT_INTERP: return "INTERP";
3966 case PT_NOTE: return "NOTE";
3967 case PT_SHLIB: return "SHLIB";
3968 case PT_PHDR: return "PHDR";
13ae64f3 3969 case PT_TLS: return "TLS";
32ec8896 3970 case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
2b05f1b7 3971 case PT_GNU_STACK: return "GNU_STACK";
8c37241b 3972 case PT_GNU_RELRO: return "GNU_RELRO";
0a59decb 3973 case PT_GNU_PROPERTY: return "GNU_PROPERTY";
65765700 3974
252b5132 3975 default:
a91e1603
L
3976 if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
3977 {
3978 sprintf (buff, "GNU_MBIND+%#lx",
3979 p_type - PT_GNU_MBIND_LO);
3980 }
3981 else if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
252b5132 3982 {
2cf0635d 3983 const char * result;
103f02d3 3984
dda8d76d 3985 switch (filedata->file_header.e_machine)
252b5132 3986 {
a06ea964
NC
3987 case EM_AARCH64:
3988 result = get_aarch64_segment_type (p_type);
3989 break;
b294bdf8
MM
3990 case EM_ARM:
3991 result = get_arm_segment_type (p_type);
3992 break;
252b5132 3993 case EM_MIPS:
4fe85591 3994 case EM_MIPS_RS3_LE:
252b5132
RH
3995 result = get_mips_segment_type (p_type);
3996 break;
103f02d3
UD
3997 case EM_PARISC:
3998 result = get_parisc_segment_type (p_type);
3999 break;
4d6ed7c8
NC
4000 case EM_IA_64:
4001 result = get_ia64_segment_type (p_type);
4002 break;
40b36596
JM
4003 case EM_TI_C6000:
4004 result = get_tic6x_segment_type (p_type);
4005 break;
b4cbbe8f
AK
4006 case EM_S390:
4007 case EM_S390_OLD:
4008 result = get_s390_segment_type (p_type);
4009 break;
252b5132
RH
4010 default:
4011 result = NULL;
4012 break;
4013 }
103f02d3 4014
252b5132
RH
4015 if (result != NULL)
4016 return result;
103f02d3 4017
1a9ccd70 4018 sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC);
252b5132
RH
4019 }
4020 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
103f02d3 4021 {
2cf0635d 4022 const char * result;
103f02d3 4023
dda8d76d 4024 switch (filedata->file_header.e_machine)
103f02d3
UD
4025 {
4026 case EM_PARISC:
4027 result = get_parisc_segment_type (p_type);
4028 break;
00428cca
AM
4029 case EM_IA_64:
4030 result = get_ia64_segment_type (p_type);
4031 break;
103f02d3 4032 default:
dda8d76d 4033 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
5522f910
NC
4034 result = get_solaris_segment_type (p_type);
4035 else
4036 result = NULL;
103f02d3
UD
4037 break;
4038 }
4039
4040 if (result != NULL)
4041 return result;
4042
1a9ccd70 4043 sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS);
103f02d3 4044 }
252b5132 4045 else
e9e44622 4046 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
252b5132
RH
4047
4048 return buff;
4049 }
4050}
4051
53a346d8
CZ
4052static const char *
4053get_arc_section_type_name (unsigned int sh_type)
4054{
4055 switch (sh_type)
4056 {
4057 case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES";
4058 default:
4059 break;
4060 }
4061 return NULL;
4062}
4063
252b5132 4064static const char *
d3ba0551 4065get_mips_section_type_name (unsigned int sh_type)
252b5132
RH
4066{
4067 switch (sh_type)
4068 {
b34976b6
AM
4069 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
4070 case SHT_MIPS_MSYM: return "MIPS_MSYM";
4071 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
4072 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
4073 case SHT_MIPS_UCODE: return "MIPS_UCODE";
4074 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
4075 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
4076 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
4077 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
4078 case SHT_MIPS_RELD: return "MIPS_RELD";
4079 case SHT_MIPS_IFACE: return "MIPS_IFACE";
4080 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
4081 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
4082 case SHT_MIPS_SHDR: return "MIPS_SHDR";
4083 case SHT_MIPS_FDESC: return "MIPS_FDESC";
4084 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
4085 case SHT_MIPS_DENSE: return "MIPS_DENSE";
4086 case SHT_MIPS_PDESC: return "MIPS_PDESC";
4087 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
4088 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
4089 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
4090 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
4091 case SHT_MIPS_LINE: return "MIPS_LINE";
4092 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
4093 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
4094 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
4095 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
4096 case SHT_MIPS_DWARF: return "MIPS_DWARF";
4097 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
4098 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
4099 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
4100 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
4101 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
4102 case SHT_MIPS_XLATE: return "MIPS_XLATE";
4103 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
4104 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
4105 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
4106 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
252b5132 4107 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
351cdf24 4108 case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
252b5132
RH
4109 default:
4110 break;
4111 }
4112 return NULL;
4113}
4114
103f02d3 4115static const char *
d3ba0551 4116get_parisc_section_type_name (unsigned int sh_type)
103f02d3
UD
4117{
4118 switch (sh_type)
4119 {
4120 case SHT_PARISC_EXT: return "PARISC_EXT";
4121 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
4122 case SHT_PARISC_DOC: return "PARISC_DOC";
eec8f817
DA
4123 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
4124 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
4125 case SHT_PARISC_STUBS: return "PARISC_STUBS";
61472819 4126 case SHT_PARISC_DLKM: return "PARISC_DLKM";
32ec8896 4127 default: return NULL;
103f02d3 4128 }
103f02d3
UD
4129}
4130
4d6ed7c8 4131static const char *
dda8d76d 4132get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type)
4d6ed7c8 4133{
18bd398b 4134 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
ecc51f48 4135 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
dda8d76d 4136 return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16);
0de14b54 4137
4d6ed7c8
NC
4138 switch (sh_type)
4139 {
148b93f2
NC
4140 case SHT_IA_64_EXT: return "IA_64_EXT";
4141 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
4142 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
4143 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
4144 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
4145 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
4146 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
4147 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
4148 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
4149 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
4d6ed7c8
NC
4150 default:
4151 break;
4152 }
4153 return NULL;
4154}
4155
d2b2c203
DJ
4156static const char *
4157get_x86_64_section_type_name (unsigned int sh_type)
4158{
4159 switch (sh_type)
4160 {
4161 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
32ec8896 4162 default: return NULL;
d2b2c203 4163 }
d2b2c203
DJ
4164}
4165
a06ea964
NC
4166static const char *
4167get_aarch64_section_type_name (unsigned int sh_type)
4168{
4169 switch (sh_type)
4170 {
32ec8896
NC
4171 case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES";
4172 default: return NULL;
a06ea964 4173 }
a06ea964
NC
4174}
4175
40a18ebd
NC
4176static const char *
4177get_arm_section_type_name (unsigned int sh_type)
4178{
4179 switch (sh_type)
4180 {
7f6fed87
NC
4181 case SHT_ARM_EXIDX: return "ARM_EXIDX";
4182 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
4183 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
4184 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
4185 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
32ec8896 4186 default: return NULL;
40a18ebd 4187 }
40a18ebd
NC
4188}
4189
40b36596
JM
4190static const char *
4191get_tic6x_section_type_name (unsigned int sh_type)
4192{
4193 switch (sh_type)
4194 {
32ec8896
NC
4195 case SHT_C6000_UNWIND: return "C6000_UNWIND";
4196 case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
4197 case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES";
4198 case SHT_TI_ICODE: return "TI_ICODE";
4199 case SHT_TI_XREF: return "TI_XREF";
4200 case SHT_TI_HANDLER: return "TI_HANDLER";
4201 case SHT_TI_INITINFO: return "TI_INITINFO";
4202 case SHT_TI_PHATTRS: return "TI_PHATTRS";
4203 default: return NULL;
40b36596 4204 }
40b36596
JM
4205}
4206
13761a11
NC
4207static const char *
4208get_msp430x_section_type_name (unsigned int sh_type)
4209{
4210 switch (sh_type)
4211 {
32ec8896
NC
4212 case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
4213 case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
4214 case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
4215 default: return NULL;
13761a11
NC
4216 }
4217}
4218
fe944acf
FT
4219static const char *
4220get_nfp_section_type_name (unsigned int sh_type)
4221{
4222 switch (sh_type)
4223 {
4224 case SHT_NFP_MECONFIG: return "NFP_MECONFIG";
4225 case SHT_NFP_INITREG: return "NFP_INITREG";
4226 case SHT_NFP_UDEBUG: return "NFP_UDEBUG";
4227 default: return NULL;
4228 }
4229}
4230
685080f2
NC
4231static const char *
4232get_v850_section_type_name (unsigned int sh_type)
4233{
4234 switch (sh_type)
4235 {
32ec8896
NC
4236 case SHT_V850_SCOMMON: return "V850 Small Common";
4237 case SHT_V850_TCOMMON: return "V850 Tiny Common";
4238 case SHT_V850_ZCOMMON: return "V850 Zero Common";
4239 case SHT_RENESAS_IOP: return "RENESAS IOP";
4240 case SHT_RENESAS_INFO: return "RENESAS INFO";
4241 default: return NULL;
685080f2
NC
4242 }
4243}
4244
2dc8dd17
JW
4245static const char *
4246get_riscv_section_type_name (unsigned int sh_type)
4247{
4248 switch (sh_type)
4249 {
4250 case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES";
4251 default: return NULL;
4252 }
4253}
4254
252b5132 4255static const char *
dda8d76d 4256get_section_type_name (Filedata * filedata, unsigned int sh_type)
252b5132 4257{
b34976b6 4258 static char buff[32];
9fb71ee4 4259 const char * result;
252b5132
RH
4260
4261 switch (sh_type)
4262 {
4263 case SHT_NULL: return "NULL";
4264 case SHT_PROGBITS: return "PROGBITS";
4265 case SHT_SYMTAB: return "SYMTAB";
4266 case SHT_STRTAB: return "STRTAB";
4267 case SHT_RELA: return "RELA";
4268 case SHT_HASH: return "HASH";
4269 case SHT_DYNAMIC: return "DYNAMIC";
4270 case SHT_NOTE: return "NOTE";
4271 case SHT_NOBITS: return "NOBITS";
4272 case SHT_REL: return "REL";
4273 case SHT_SHLIB: return "SHLIB";
4274 case SHT_DYNSYM: return "DYNSYM";
d1133906
NC
4275 case SHT_INIT_ARRAY: return "INIT_ARRAY";
4276 case SHT_FINI_ARRAY: return "FINI_ARRAY";
4277 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
fdc90cb4 4278 case SHT_GNU_HASH: return "GNU_HASH";
93ebe586 4279 case SHT_GROUP: return "GROUP";
67ce483b 4280 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES";
252b5132
RH
4281 case SHT_GNU_verdef: return "VERDEF";
4282 case SHT_GNU_verneed: return "VERNEED";
4283 case SHT_GNU_versym: return "VERSYM";
b34976b6
AM
4284 case 0x6ffffff0: return "VERSYM";
4285 case 0x6ffffffc: return "VERDEF";
252b5132
RH
4286 case 0x7ffffffd: return "AUXILIARY";
4287 case 0x7fffffff: return "FILTER";
047b2264 4288 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
252b5132
RH
4289
4290 default:
4291 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
4292 {
dda8d76d 4293 switch (filedata->file_header.e_machine)
252b5132 4294 {
53a346d8
CZ
4295 case EM_ARC:
4296 case EM_ARC_COMPACT:
4297 case EM_ARC_COMPACT2:
4298 result = get_arc_section_type_name (sh_type);
4299 break;
252b5132 4300 case EM_MIPS:
4fe85591 4301 case EM_MIPS_RS3_LE:
252b5132
RH
4302 result = get_mips_section_type_name (sh_type);
4303 break;
103f02d3
UD
4304 case EM_PARISC:
4305 result = get_parisc_section_type_name (sh_type);
4306 break;
4d6ed7c8 4307 case EM_IA_64:
dda8d76d 4308 result = get_ia64_section_type_name (filedata, sh_type);
4d6ed7c8 4309 break;
d2b2c203 4310 case EM_X86_64:
8a9036a4 4311 case EM_L1OM:
7a9068fe 4312 case EM_K1OM:
d2b2c203
DJ
4313 result = get_x86_64_section_type_name (sh_type);
4314 break;
a06ea964
NC
4315 case EM_AARCH64:
4316 result = get_aarch64_section_type_name (sh_type);
4317 break;
40a18ebd
NC
4318 case EM_ARM:
4319 result = get_arm_section_type_name (sh_type);
4320 break;
40b36596
JM
4321 case EM_TI_C6000:
4322 result = get_tic6x_section_type_name (sh_type);
4323 break;
13761a11
NC
4324 case EM_MSP430:
4325 result = get_msp430x_section_type_name (sh_type);
4326 break;
fe944acf
FT
4327 case EM_NFP:
4328 result = get_nfp_section_type_name (sh_type);
4329 break;
685080f2
NC
4330 case EM_V800:
4331 case EM_V850:
4332 case EM_CYGNUS_V850:
4333 result = get_v850_section_type_name (sh_type);
4334 break;
2dc8dd17
JW
4335 case EM_RISCV:
4336 result = get_riscv_section_type_name (sh_type);
4337 break;
252b5132
RH
4338 default:
4339 result = NULL;
4340 break;
4341 }
4342
4343 if (result != NULL)
4344 return result;
4345
9fb71ee4 4346 sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
252b5132
RH
4347 }
4348 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
148b93f2 4349 {
dda8d76d 4350 switch (filedata->file_header.e_machine)
148b93f2
NC
4351 {
4352 case EM_IA_64:
dda8d76d 4353 result = get_ia64_section_type_name (filedata, sh_type);
148b93f2
NC
4354 break;
4355 default:
dda8d76d 4356 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
4357 result = get_solaris_section_type (sh_type);
4358 else
1b4b80bf
NC
4359 {
4360 switch (sh_type)
4361 {
4362 case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break;
4363 case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break;
4364 case SHT_GNU_HASH: result = "GNU_HASH"; break;
4365 case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break;
4366 default:
4367 result = NULL;
4368 break;
4369 }
4370 }
148b93f2
NC
4371 break;
4372 }
4373
4374 if (result != NULL)
4375 return result;
4376
9fb71ee4 4377 sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
148b93f2 4378 }
252b5132 4379 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
685080f2 4380 {
dda8d76d 4381 switch (filedata->file_header.e_machine)
685080f2
NC
4382 {
4383 case EM_V800:
4384 case EM_V850:
4385 case EM_CYGNUS_V850:
9fb71ee4 4386 result = get_v850_section_type_name (sh_type);
a9fb83be 4387 break;
685080f2 4388 default:
9fb71ee4 4389 result = NULL;
685080f2
NC
4390 break;
4391 }
4392
9fb71ee4
NC
4393 if (result != NULL)
4394 return result;
4395
4396 sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
685080f2 4397 }
252b5132 4398 else
a7dbfd1c
NC
4399 /* This message is probably going to be displayed in a 15
4400 character wide field, so put the hex value first. */
4401 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
103f02d3 4402
252b5132
RH
4403 return buff;
4404 }
4405}
4406
2979dc34 4407#define OPTION_DEBUG_DUMP 512
2c610e4b 4408#define OPTION_DYN_SYMS 513
fd2f0033
TT
4409#define OPTION_DWARF_DEPTH 514
4410#define OPTION_DWARF_START 515
4723351a 4411#define OPTION_DWARF_CHECK 516
90bd5423 4412#ifdef HAVE_LIBCTF
7d9813f1
NA
4413#define OPTION_CTF_DUMP 517
4414#define OPTION_CTF_PARENT 518
4415#define OPTION_CTF_SYMBOLS 519
4416#define OPTION_CTF_STRINGS 520
90bd5423 4417#endif
2979dc34 4418
85b1c36d 4419static struct option options[] =
252b5132 4420{
b34976b6 4421 {"all", no_argument, 0, 'a'},
252b5132
RH
4422 {"file-header", no_argument, 0, 'h'},
4423 {"program-headers", no_argument, 0, 'l'},
b34976b6
AM
4424 {"headers", no_argument, 0, 'e'},
4425 {"histogram", no_argument, 0, 'I'},
4426 {"segments", no_argument, 0, 'l'},
4427 {"sections", no_argument, 0, 'S'},
252b5132 4428 {"section-headers", no_argument, 0, 'S'},
f5842774 4429 {"section-groups", no_argument, 0, 'g'},
5477e8a0 4430 {"section-details", no_argument, 0, 't'},
595cf52e 4431 {"full-section-name",no_argument, 0, 'N'},
b34976b6
AM
4432 {"symbols", no_argument, 0, 's'},
4433 {"syms", no_argument, 0, 's'},
2c610e4b 4434 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
b34976b6
AM
4435 {"relocs", no_argument, 0, 'r'},
4436 {"notes", no_argument, 0, 'n'},
4437 {"dynamic", no_argument, 0, 'd'},
a952a375 4438 {"arch-specific", no_argument, 0, 'A'},
252b5132
RH
4439 {"version-info", no_argument, 0, 'V'},
4440 {"use-dynamic", no_argument, 0, 'D'},
09c11c86 4441 {"unwind", no_argument, 0, 'u'},
4145f1d5 4442 {"archive-index", no_argument, 0, 'c'},
b34976b6 4443 {"hex-dump", required_argument, 0, 'x'},
cf13d699 4444 {"relocated-dump", required_argument, 0, 'R'},
09c11c86 4445 {"string-dump", required_argument, 0, 'p'},
0e602686 4446 {"decompress", no_argument, 0, 'z'},
252b5132
RH
4447#ifdef SUPPORT_DISASSEMBLY
4448 {"instruction-dump", required_argument, 0, 'i'},
4449#endif
cf13d699 4450 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
252b5132 4451
fd2f0033
TT
4452 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
4453 {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
4723351a 4454 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
fd2f0033 4455
90bd5423 4456#ifdef HAVE_LIBCTF
7d9813f1
NA
4457 {"ctf", required_argument, 0, OPTION_CTF_DUMP},
4458
4459 {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS},
4460 {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS},
4461 {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT},
90bd5423 4462#endif
7d9813f1 4463
b34976b6
AM
4464 {"version", no_argument, 0, 'v'},
4465 {"wide", no_argument, 0, 'W'},
4466 {"help", no_argument, 0, 'H'},
4467 {0, no_argument, 0, 0}
252b5132
RH
4468};
4469
4470static void
2cf0635d 4471usage (FILE * stream)
252b5132 4472{
92f01d61
JM
4473 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
4474 fprintf (stream, _(" Display information about the contents of ELF format files\n"));
4475 fprintf (stream, _(" Options are:\n\
8b53311e
NC
4476 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4477 -h --file-header Display the ELF file header\n\
4478 -l --program-headers Display the program headers\n\
4479 --segments An alias for --program-headers\n\
4480 -S --section-headers Display the sections' header\n\
4481 --sections An alias for --section-headers\n\
f5842774 4482 -g --section-groups Display the section groups\n\
5477e8a0 4483 -t --section-details Display the section details\n\
8b53311e
NC
4484 -e --headers Equivalent to: -h -l -S\n\
4485 -s --syms Display the symbol table\n\
3f08eb35 4486 --symbols An alias for --syms\n\
2c610e4b 4487 --dyn-syms Display the dynamic symbol table\n\
8b53311e
NC
4488 -n --notes Display the core notes (if present)\n\
4489 -r --relocs Display the relocations (if present)\n\
4490 -u --unwind Display the unwind info (if present)\n\
b2d38a17 4491 -d --dynamic Display the dynamic section (if present)\n\
8b53311e 4492 -V --version-info Display the version sections (if present)\n\
1b31d05e 4493 -A --arch-specific Display architecture specific information (if any)\n\
4145f1d5 4494 -c --archive-index Display the symbol/file index in an archive\n\
8b53311e 4495 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
09c11c86
NC
4496 -x --hex-dump=<number|name>\n\
4497 Dump the contents of section <number|name> as bytes\n\
4498 -p --string-dump=<number|name>\n\
4499 Dump the contents of section <number|name> as strings\n\
cf13d699
NC
4500 -R --relocated-dump=<number|name>\n\
4501 Dump the contents of section <number|name> as relocated bytes\n\
0e602686 4502 -z --decompress Decompress section before dumping it\n\
dda8d76d 4503 -w[lLiaprmfFsoRtUuTgAckK] or\n\
1ed06042 4504 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
6f875884 4505 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
657d0d47 4506 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
dda8d76d
NC
4507 =addr,=cu_index,=links,=follow-links]\n\
4508 Display the contents of DWARF debug sections\n"));
fd2f0033
TT
4509 fprintf (stream, _("\
4510 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4511 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4512 or deeper\n"));
90bd5423 4513#ifdef HAVE_LIBCTF
7d9813f1
NA
4514 fprintf (stream, _("\
4515 --ctf=<number|name> Display CTF info from section <number|name>\n\
4516 --ctf-parent=<number|name>\n\
4517 Use section <number|name> as the CTF parent\n\n\
4518 --ctf-symbols=<number|name>\n\
4519 Use section <number|name> as the CTF external symtab\n\n\
4520 --ctf-strings=<number|name>\n\
4521 Use section <number|name> as the CTF external strtab\n\n"));
90bd5423 4522#endif
7d9813f1 4523
252b5132 4524#ifdef SUPPORT_DISASSEMBLY
92f01d61 4525 fprintf (stream, _("\
09c11c86
NC
4526 -i --instruction-dump=<number|name>\n\
4527 Disassemble the contents of section <number|name>\n"));
252b5132 4528#endif
92f01d61 4529 fprintf (stream, _("\
8b53311e
NC
4530 -I --histogram Display histogram of bucket list lengths\n\
4531 -W --wide Allow output width to exceed 80 characters\n\
07012eee 4532 @<file> Read options from <file>\n\
8b53311e
NC
4533 -H --help Display this information\n\
4534 -v --version Display the version number of readelf\n"));
1118d252 4535
92f01d61
JM
4536 if (REPORT_BUGS_TO[0] && stream == stdout)
4537 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
252b5132 4538
92f01d61 4539 exit (stream == stdout ? 0 : 1);
252b5132
RH
4540}
4541
18bd398b
NC
4542/* Record the fact that the user wants the contents of section number
4543 SECTION to be displayed using the method(s) encoded as flags bits
4544 in TYPE. Note, TYPE can be zero if we are creating the array for
4545 the first time. */
4546
252b5132 4547static void
dda8d76d 4548request_dump_bynumber (Filedata * filedata, unsigned int section, dump_type type)
252b5132 4549{
dda8d76d 4550 if (section >= filedata->num_dump_sects)
252b5132 4551 {
2cf0635d 4552 dump_type * new_dump_sects;
252b5132 4553
3f5e193b 4554 new_dump_sects = (dump_type *) calloc (section + 1,
dda8d76d 4555 sizeof (* new_dump_sects));
252b5132
RH
4556
4557 if (new_dump_sects == NULL)
591a748a 4558 error (_("Out of memory allocating dump request table.\n"));
252b5132
RH
4559 else
4560 {
dda8d76d 4561 if (filedata->dump_sects)
21b65bac
NC
4562 {
4563 /* Copy current flag settings. */
dda8d76d
NC
4564 memcpy (new_dump_sects, filedata->dump_sects,
4565 filedata->num_dump_sects * sizeof (* new_dump_sects));
252b5132 4566
dda8d76d 4567 free (filedata->dump_sects);
21b65bac 4568 }
252b5132 4569
dda8d76d
NC
4570 filedata->dump_sects = new_dump_sects;
4571 filedata->num_dump_sects = section + 1;
252b5132
RH
4572 }
4573 }
4574
dda8d76d
NC
4575 if (filedata->dump_sects)
4576 filedata->dump_sects[section] |= type;
252b5132
RH
4577}
4578
aef1f6d0
DJ
4579/* Request a dump by section name. */
4580
4581static void
2cf0635d 4582request_dump_byname (const char * section, dump_type type)
aef1f6d0 4583{
2cf0635d 4584 struct dump_list_entry * new_request;
aef1f6d0 4585
3f5e193b
NC
4586 new_request = (struct dump_list_entry *)
4587 malloc (sizeof (struct dump_list_entry));
aef1f6d0 4588 if (!new_request)
591a748a 4589 error (_("Out of memory allocating dump request table.\n"));
aef1f6d0
DJ
4590
4591 new_request->name = strdup (section);
4592 if (!new_request->name)
591a748a 4593 error (_("Out of memory allocating dump request table.\n"));
aef1f6d0
DJ
4594
4595 new_request->type = type;
4596
4597 new_request->next = dump_sects_byname;
4598 dump_sects_byname = new_request;
4599}
4600
cf13d699 4601static inline void
dda8d76d 4602request_dump (Filedata * filedata, dump_type type)
cf13d699
NC
4603{
4604 int section;
4605 char * cp;
4606
4607 do_dump++;
4608 section = strtoul (optarg, & cp, 0);
4609
4610 if (! *cp && section >= 0)
dda8d76d 4611 request_dump_bynumber (filedata, section, type);
cf13d699
NC
4612 else
4613 request_dump_byname (optarg, type);
4614}
4615
252b5132 4616static void
dda8d76d 4617parse_args (Filedata * filedata, int argc, char ** argv)
252b5132
RH
4618{
4619 int c;
4620
4621 if (argc < 2)
92f01d61 4622 usage (stderr);
252b5132
RH
4623
4624 while ((c = getopt_long
0e602686 4625 (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
252b5132 4626 {
252b5132
RH
4627 switch (c)
4628 {
4629 case 0:
4630 /* Long options. */
4631 break;
4632 case 'H':
92f01d61 4633 usage (stdout);
252b5132
RH
4634 break;
4635
4636 case 'a':
32ec8896
NC
4637 do_syms = TRUE;
4638 do_reloc = TRUE;
4639 do_unwind = TRUE;
4640 do_dynamic = TRUE;
4641 do_header = TRUE;
4642 do_sections = TRUE;
4643 do_section_groups = TRUE;
4644 do_segments = TRUE;
4645 do_version = TRUE;
4646 do_histogram = TRUE;
4647 do_arch = TRUE;
4648 do_notes = TRUE;
252b5132 4649 break;
f5842774 4650 case 'g':
32ec8896 4651 do_section_groups = TRUE;
f5842774 4652 break;
5477e8a0 4653 case 't':
595cf52e 4654 case 'N':
32ec8896
NC
4655 do_sections = TRUE;
4656 do_section_details = TRUE;
595cf52e 4657 break;
252b5132 4658 case 'e':
32ec8896
NC
4659 do_header = TRUE;
4660 do_sections = TRUE;
4661 do_segments = TRUE;
252b5132 4662 break;
a952a375 4663 case 'A':
32ec8896 4664 do_arch = TRUE;
a952a375 4665 break;
252b5132 4666 case 'D':
32ec8896 4667 do_using_dynamic = TRUE;
252b5132
RH
4668 break;
4669 case 'r':
32ec8896 4670 do_reloc = TRUE;
252b5132 4671 break;
4d6ed7c8 4672 case 'u':
32ec8896 4673 do_unwind = TRUE;
4d6ed7c8 4674 break;
252b5132 4675 case 'h':
32ec8896 4676 do_header = TRUE;
252b5132
RH
4677 break;
4678 case 'l':
32ec8896 4679 do_segments = TRUE;
252b5132
RH
4680 break;
4681 case 's':
32ec8896 4682 do_syms = TRUE;
252b5132
RH
4683 break;
4684 case 'S':
32ec8896 4685 do_sections = TRUE;
252b5132
RH
4686 break;
4687 case 'd':
32ec8896 4688 do_dynamic = TRUE;
252b5132 4689 break;
a952a375 4690 case 'I':
32ec8896 4691 do_histogram = TRUE;
a952a375 4692 break;
779fe533 4693 case 'n':
32ec8896 4694 do_notes = TRUE;
779fe533 4695 break;
4145f1d5 4696 case 'c':
32ec8896 4697 do_archive_index = TRUE;
4145f1d5 4698 break;
252b5132 4699 case 'x':
dda8d76d 4700 request_dump (filedata, HEX_DUMP);
aef1f6d0 4701 break;
09c11c86 4702 case 'p':
dda8d76d 4703 request_dump (filedata, STRING_DUMP);
cf13d699
NC
4704 break;
4705 case 'R':
dda8d76d 4706 request_dump (filedata, RELOC_DUMP);
09c11c86 4707 break;
0e602686 4708 case 'z':
32ec8896 4709 decompress_dumps = TRUE;
0e602686 4710 break;
252b5132 4711 case 'w':
32ec8896 4712 do_dump = TRUE;
252b5132 4713 if (optarg == 0)
613ff48b 4714 {
32ec8896 4715 do_debugging = TRUE;
613ff48b
CC
4716 dwarf_select_sections_all ();
4717 }
252b5132
RH
4718 else
4719 {
32ec8896 4720 do_debugging = FALSE;
4cb93e3b 4721 dwarf_select_sections_by_letters (optarg);
252b5132
RH
4722 }
4723 break;
2979dc34 4724 case OPTION_DEBUG_DUMP:
32ec8896 4725 do_dump = TRUE;
2979dc34 4726 if (optarg == 0)
32ec8896 4727 do_debugging = TRUE;
2979dc34
JJ
4728 else
4729 {
32ec8896 4730 do_debugging = FALSE;
4cb93e3b 4731 dwarf_select_sections_by_names (optarg);
2979dc34
JJ
4732 }
4733 break;
fd2f0033
TT
4734 case OPTION_DWARF_DEPTH:
4735 {
4736 char *cp;
4737
4738 dwarf_cutoff_level = strtoul (optarg, & cp, 0);
4739 }
4740 break;
4741 case OPTION_DWARF_START:
4742 {
4743 char *cp;
4744
4745 dwarf_start_die = strtoul (optarg, & cp, 0);
4746 }
4747 break;
4723351a 4748 case OPTION_DWARF_CHECK:
32ec8896 4749 dwarf_check = TRUE;
4723351a 4750 break;
90bd5423 4751#ifdef HAVE_LIBCTF
7d9813f1
NA
4752 case OPTION_CTF_DUMP:
4753 do_ctf = TRUE;
4754 request_dump (filedata, CTF_DUMP);
4755 break;
4756 case OPTION_CTF_SYMBOLS:
4757 dump_ctf_symtab_name = strdup (optarg);
4758 break;
4759 case OPTION_CTF_STRINGS:
4760 dump_ctf_strtab_name = strdup (optarg);
4761 break;
4762 case OPTION_CTF_PARENT:
4763 dump_ctf_parent_name = strdup (optarg);
4764 break;
90bd5423 4765#endif
2c610e4b 4766 case OPTION_DYN_SYMS:
32ec8896 4767 do_dyn_syms = TRUE;
2c610e4b 4768 break;
252b5132
RH
4769#ifdef SUPPORT_DISASSEMBLY
4770 case 'i':
dda8d76d 4771 request_dump (filedata, DISASS_DUMP);
cf13d699 4772 break;
252b5132
RH
4773#endif
4774 case 'v':
4775 print_version (program_name);
4776 break;
4777 case 'V':
32ec8896 4778 do_version = TRUE;
252b5132 4779 break;
d974e256 4780 case 'W':
32ec8896 4781 do_wide = TRUE;
d974e256 4782 break;
252b5132 4783 default:
252b5132
RH
4784 /* xgettext:c-format */
4785 error (_("Invalid option '-%c'\n"), c);
1a0670f3 4786 /* Fall through. */
252b5132 4787 case '?':
92f01d61 4788 usage (stderr);
252b5132
RH
4789 }
4790 }
4791
4d6ed7c8 4792 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
252b5132 4793 && !do_segments && !do_header && !do_dump && !do_version
f5842774 4794 && !do_histogram && !do_debugging && !do_arch && !do_notes
2c610e4b
L
4795 && !do_section_groups && !do_archive_index
4796 && !do_dyn_syms)
92f01d61 4797 usage (stderr);
252b5132
RH
4798}
4799
4800static const char *
d3ba0551 4801get_elf_class (unsigned int elf_class)
252b5132 4802{
b34976b6 4803 static char buff[32];
103f02d3 4804
252b5132
RH
4805 switch (elf_class)
4806 {
4807 case ELFCLASSNONE: return _("none");
e3c8793a
NC
4808 case ELFCLASS32: return "ELF32";
4809 case ELFCLASS64: return "ELF64";
ab5e7794 4810 default:
e9e44622 4811 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
ab5e7794 4812 return buff;
252b5132
RH
4813 }
4814}
4815
4816static const char *
d3ba0551 4817get_data_encoding (unsigned int encoding)
252b5132 4818{
b34976b6 4819 static char buff[32];
103f02d3 4820
252b5132
RH
4821 switch (encoding)
4822 {
4823 case ELFDATANONE: return _("none");
33c63f9d
CM
4824 case ELFDATA2LSB: return _("2's complement, little endian");
4825 case ELFDATA2MSB: return _("2's complement, big endian");
103f02d3 4826 default:
e9e44622 4827 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
ab5e7794 4828 return buff;
252b5132
RH
4829 }
4830}
4831
dda8d76d 4832/* Decode the data held in 'filedata->file_header'. */
ee42cf8c 4833
32ec8896 4834static bfd_boolean
dda8d76d 4835process_file_header (Filedata * filedata)
252b5132 4836{
dda8d76d
NC
4837 Elf_Internal_Ehdr * header = & filedata->file_header;
4838
4839 if ( header->e_ident[EI_MAG0] != ELFMAG0
4840 || header->e_ident[EI_MAG1] != ELFMAG1
4841 || header->e_ident[EI_MAG2] != ELFMAG2
4842 || header->e_ident[EI_MAG3] != ELFMAG3)
252b5132
RH
4843 {
4844 error
4845 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
32ec8896 4846 return FALSE;
252b5132
RH
4847 }
4848
dda8d76d 4849 init_dwarf_regnames (header->e_machine);
2dc4cec1 4850
252b5132
RH
4851 if (do_header)
4852 {
32ec8896 4853 unsigned i;
252b5132
RH
4854
4855 printf (_("ELF Header:\n"));
4856 printf (_(" Magic: "));
b34976b6 4857 for (i = 0; i < EI_NIDENT; i++)
dda8d76d 4858 printf ("%2.2x ", header->e_ident[i]);
252b5132
RH
4859 printf ("\n");
4860 printf (_(" Class: %s\n"),
dda8d76d 4861 get_elf_class (header->e_ident[EI_CLASS]));
252b5132 4862 printf (_(" Data: %s\n"),
dda8d76d 4863 get_data_encoding (header->e_ident[EI_DATA]));
e8a64888 4864 printf (_(" Version: %d%s\n"),
dda8d76d
NC
4865 header->e_ident[EI_VERSION],
4866 (header->e_ident[EI_VERSION] == EV_CURRENT
e8a64888 4867 ? _(" (current)")
dda8d76d 4868 : (header->e_ident[EI_VERSION] != EV_NONE
e8a64888 4869 ? _(" <unknown>")
789be9f7 4870 : "")));
252b5132 4871 printf (_(" OS/ABI: %s\n"),
dda8d76d 4872 get_osabi_name (filedata, header->e_ident[EI_OSABI]));
252b5132 4873 printf (_(" ABI Version: %d\n"),
dda8d76d 4874 header->e_ident[EI_ABIVERSION]);
252b5132 4875 printf (_(" Type: %s\n"),
dda8d76d 4876 get_file_type (header->e_type));
252b5132 4877 printf (_(" Machine: %s\n"),
dda8d76d 4878 get_machine_name (header->e_machine));
252b5132 4879 printf (_(" Version: 0x%lx\n"),
e8a64888 4880 header->e_version);
76da6bbe 4881
f7a99963 4882 printf (_(" Entry point address: "));
e8a64888 4883 print_vma (header->e_entry, PREFIX_HEX);
f7a99963 4884 printf (_("\n Start of program headers: "));
e8a64888 4885 print_vma (header->e_phoff, DEC);
f7a99963 4886 printf (_(" (bytes into file)\n Start of section headers: "));
e8a64888 4887 print_vma (header->e_shoff, DEC);
f7a99963 4888 printf (_(" (bytes into file)\n"));
76da6bbe 4889
252b5132 4890 printf (_(" Flags: 0x%lx%s\n"),
e8a64888 4891 header->e_flags,
dda8d76d 4892 get_machine_flags (filedata, header->e_flags, header->e_machine));
e8a64888
AM
4893 printf (_(" Size of this header: %u (bytes)\n"),
4894 header->e_ehsize);
4895 printf (_(" Size of program headers: %u (bytes)\n"),
4896 header->e_phentsize);
4897 printf (_(" Number of program headers: %u"),
4898 header->e_phnum);
dda8d76d
NC
4899 if (filedata->section_headers != NULL
4900 && header->e_phnum == PN_XNUM
4901 && filedata->section_headers[0].sh_info != 0)
e8a64888
AM
4902 {
4903 header->e_phnum = filedata->section_headers[0].sh_info;
4904 printf (" (%u)", header->e_phnum);
4905 }
2046a35d 4906 putc ('\n', stdout);
e8a64888
AM
4907 printf (_(" Size of section headers: %u (bytes)\n"),
4908 header->e_shentsize);
4909 printf (_(" Number of section headers: %u"),
4910 header->e_shnum);
dda8d76d 4911 if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF)
e8a64888
AM
4912 {
4913 header->e_shnum = filedata->section_headers[0].sh_size;
4914 printf (" (%u)", header->e_shnum);
4915 }
560f3c1c 4916 putc ('\n', stdout);
e8a64888
AM
4917 printf (_(" Section header string table index: %u"),
4918 header->e_shstrndx);
dda8d76d
NC
4919 if (filedata->section_headers != NULL
4920 && header->e_shstrndx == (SHN_XINDEX & 0xffff))
e8a64888
AM
4921 {
4922 header->e_shstrndx = filedata->section_headers[0].sh_link;
4923 printf (" (%u)", header->e_shstrndx);
4924 }
4925 if (header->e_shstrndx != SHN_UNDEF
4926 && header->e_shstrndx >= header->e_shnum)
4927 {
4928 header->e_shstrndx = SHN_UNDEF;
4929 printf (_(" <corrupt: out of range>"));
4930 }
560f3c1c
AM
4931 putc ('\n', stdout);
4932 }
4933
dda8d76d 4934 if (filedata->section_headers != NULL)
560f3c1c 4935 {
dda8d76d
NC
4936 if (header->e_phnum == PN_XNUM
4937 && filedata->section_headers[0].sh_info != 0)
4938 header->e_phnum = filedata->section_headers[0].sh_info;
4939 if (header->e_shnum == SHN_UNDEF)
4940 header->e_shnum = filedata->section_headers[0].sh_size;
4941 if (header->e_shstrndx == (SHN_XINDEX & 0xffff))
4942 header->e_shstrndx = filedata->section_headers[0].sh_link;
9c1ce108 4943 if (header->e_shstrndx >= header->e_shnum)
dda8d76d
NC
4944 header->e_shstrndx = SHN_UNDEF;
4945 free (filedata->section_headers);
4946 filedata->section_headers = NULL;
252b5132 4947 }
103f02d3 4948
32ec8896 4949 return TRUE;
9ea033b2
NC
4950}
4951
dda8d76d
NC
4952/* Read in the program headers from FILEDATA and store them in PHEADERS.
4953 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
4954
e0a31db1 4955static bfd_boolean
dda8d76d 4956get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
9ea033b2 4957{
2cf0635d
NC
4958 Elf32_External_Phdr * phdrs;
4959 Elf32_External_Phdr * external;
4960 Elf_Internal_Phdr * internal;
b34976b6 4961 unsigned int i;
dda8d76d
NC
4962 unsigned int size = filedata->file_header.e_phentsize;
4963 unsigned int num = filedata->file_header.e_phnum;
e0a31db1
NC
4964
4965 /* PR binutils/17531: Cope with unexpected section header sizes. */
4966 if (size == 0 || num == 0)
4967 return FALSE;
4968 if (size < sizeof * phdrs)
4969 {
4970 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
4971 return FALSE;
4972 }
4973 if (size > sizeof * phdrs)
4974 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
103f02d3 4975
dda8d76d 4976 phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
e0a31db1
NC
4977 size, num, _("program headers"));
4978 if (phdrs == NULL)
4979 return FALSE;
9ea033b2 4980
91d6fa6a 4981 for (i = 0, internal = pheaders, external = phdrs;
dda8d76d 4982 i < filedata->file_header.e_phnum;
b34976b6 4983 i++, internal++, external++)
252b5132 4984 {
9ea033b2
NC
4985 internal->p_type = BYTE_GET (external->p_type);
4986 internal->p_offset = BYTE_GET (external->p_offset);
4987 internal->p_vaddr = BYTE_GET (external->p_vaddr);
4988 internal->p_paddr = BYTE_GET (external->p_paddr);
4989 internal->p_filesz = BYTE_GET (external->p_filesz);
4990 internal->p_memsz = BYTE_GET (external->p_memsz);
4991 internal->p_flags = BYTE_GET (external->p_flags);
4992 internal->p_align = BYTE_GET (external->p_align);
252b5132
RH
4993 }
4994
9ea033b2 4995 free (phdrs);
e0a31db1 4996 return TRUE;
252b5132
RH
4997}
4998
dda8d76d
NC
4999/* Read in the program headers from FILEDATA and store them in PHEADERS.
5000 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5001
e0a31db1 5002static bfd_boolean
dda8d76d 5003get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
9ea033b2 5004{
2cf0635d
NC
5005 Elf64_External_Phdr * phdrs;
5006 Elf64_External_Phdr * external;
5007 Elf_Internal_Phdr * internal;
b34976b6 5008 unsigned int i;
dda8d76d
NC
5009 unsigned int size = filedata->file_header.e_phentsize;
5010 unsigned int num = filedata->file_header.e_phnum;
e0a31db1
NC
5011
5012 /* PR binutils/17531: Cope with unexpected section header sizes. */
5013 if (size == 0 || num == 0)
5014 return FALSE;
5015 if (size < sizeof * phdrs)
5016 {
5017 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5018 return FALSE;
5019 }
5020 if (size > sizeof * phdrs)
5021 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
103f02d3 5022
dda8d76d 5023 phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
e0a31db1 5024 size, num, _("program headers"));
a6e9f9df 5025 if (!phdrs)
e0a31db1 5026 return FALSE;
9ea033b2 5027
91d6fa6a 5028 for (i = 0, internal = pheaders, external = phdrs;
dda8d76d 5029 i < filedata->file_header.e_phnum;
b34976b6 5030 i++, internal++, external++)
9ea033b2
NC
5031 {
5032 internal->p_type = BYTE_GET (external->p_type);
5033 internal->p_flags = BYTE_GET (external->p_flags);
66543521
AM
5034 internal->p_offset = BYTE_GET (external->p_offset);
5035 internal->p_vaddr = BYTE_GET (external->p_vaddr);
5036 internal->p_paddr = BYTE_GET (external->p_paddr);
5037 internal->p_filesz = BYTE_GET (external->p_filesz);
5038 internal->p_memsz = BYTE_GET (external->p_memsz);
5039 internal->p_align = BYTE_GET (external->p_align);
9ea033b2
NC
5040 }
5041
5042 free (phdrs);
e0a31db1 5043 return TRUE;
9ea033b2 5044}
252b5132 5045
32ec8896 5046/* Returns TRUE if the program headers were read into `program_headers'. */
d93f0186 5047
32ec8896 5048static bfd_boolean
dda8d76d 5049get_program_headers (Filedata * filedata)
d93f0186 5050{
2cf0635d 5051 Elf_Internal_Phdr * phdrs;
d93f0186
NC
5052
5053 /* Check cache of prior read. */
dda8d76d 5054 if (filedata->program_headers != NULL)
32ec8896 5055 return TRUE;
d93f0186 5056
82156ab7
NC
5057 /* Be kind to memory checkers by looking for
5058 e_phnum values which we know must be invalid. */
dda8d76d 5059 if (filedata->file_header.e_phnum
82156ab7 5060 * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr))
dda8d76d 5061 >= filedata->file_size)
82156ab7
NC
5062 {
5063 error (_("Too many program headers - %#x - the file is not that big\n"),
dda8d76d 5064 filedata->file_header.e_phnum);
82156ab7
NC
5065 return FALSE;
5066 }
d93f0186 5067
dda8d76d 5068 phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum,
82156ab7 5069 sizeof (Elf_Internal_Phdr));
d93f0186
NC
5070 if (phdrs == NULL)
5071 {
8b73c356 5072 error (_("Out of memory reading %u program headers\n"),
dda8d76d 5073 filedata->file_header.e_phnum);
32ec8896 5074 return FALSE;
d93f0186
NC
5075 }
5076
5077 if (is_32bit_elf
dda8d76d
NC
5078 ? get_32bit_program_headers (filedata, phdrs)
5079 : get_64bit_program_headers (filedata, phdrs))
d93f0186 5080 {
dda8d76d 5081 filedata->program_headers = phdrs;
32ec8896 5082 return TRUE;
d93f0186
NC
5083 }
5084
5085 free (phdrs);
32ec8896 5086 return FALSE;
d93f0186
NC
5087}
5088
32ec8896 5089/* Returns TRUE if the program headers were loaded. */
2f62977e 5090
32ec8896 5091static bfd_boolean
dda8d76d 5092process_program_headers (Filedata * filedata)
252b5132 5093{
2cf0635d 5094 Elf_Internal_Phdr * segment;
b34976b6 5095 unsigned int i;
1a9ccd70 5096 Elf_Internal_Phdr * previous_load = NULL;
252b5132 5097
dda8d76d 5098 if (filedata->file_header.e_phnum == 0)
252b5132 5099 {
82f2dbf7 5100 /* PR binutils/12467. */
dda8d76d 5101 if (filedata->file_header.e_phoff != 0)
32ec8896
NC
5102 {
5103 warn (_("possibly corrupt ELF header - it has a non-zero program"
5104 " header offset, but no program headers\n"));
5105 return FALSE;
5106 }
82f2dbf7 5107 else if (do_segments)
252b5132 5108 printf (_("\nThere are no program headers in this file.\n"));
32ec8896 5109 return TRUE;
252b5132
RH
5110 }
5111
5112 if (do_segments && !do_header)
5113 {
dda8d76d
NC
5114 printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type));
5115 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry));
d3a49aa8
AM
5116 printf (ngettext ("There is %d program header, starting at offset %s\n",
5117 "There are %d program headers, starting at offset %s\n",
dda8d76d
NC
5118 filedata->file_header.e_phnum),
5119 filedata->file_header.e_phnum,
5120 bfd_vmatoa ("u", filedata->file_header.e_phoff));
252b5132
RH
5121 }
5122
dda8d76d 5123 if (! get_program_headers (filedata))
6b4bf3bc 5124 return TRUE;
103f02d3 5125
252b5132
RH
5126 if (do_segments)
5127 {
dda8d76d 5128 if (filedata->file_header.e_phnum > 1)
3a1a2036
NC
5129 printf (_("\nProgram Headers:\n"));
5130 else
5131 printf (_("\nProgram Headers:\n"));
76da6bbe 5132
f7a99963
NC
5133 if (is_32bit_elf)
5134 printf
5135 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
d974e256
JJ
5136 else if (do_wide)
5137 printf
5138 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
f7a99963
NC
5139 else
5140 {
5141 printf
5142 (_(" Type Offset VirtAddr PhysAddr\n"));
5143 printf
5144 (_(" FileSiz MemSiz Flags Align\n"));
5145 }
252b5132
RH
5146 }
5147
252b5132 5148 dynamic_addr = 0;
1b228002 5149 dynamic_size = 0;
252b5132 5150
dda8d76d
NC
5151 for (i = 0, segment = filedata->program_headers;
5152 i < filedata->file_header.e_phnum;
b34976b6 5153 i++, segment++)
252b5132
RH
5154 {
5155 if (do_segments)
5156 {
dda8d76d 5157 printf (" %-14.14s ", get_segment_type (filedata, segment->p_type));
f7a99963
NC
5158
5159 if (is_32bit_elf)
5160 {
5161 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5162 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
5163 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
5164 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
5165 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
5166 printf ("%c%c%c ",
5167 (segment->p_flags & PF_R ? 'R' : ' '),
5168 (segment->p_flags & PF_W ? 'W' : ' '),
5169 (segment->p_flags & PF_X ? 'E' : ' '));
5170 printf ("%#lx", (unsigned long) segment->p_align);
5171 }
d974e256
JJ
5172 else if (do_wide)
5173 {
5174 if ((unsigned long) segment->p_offset == segment->p_offset)
5175 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5176 else
5177 {
5178 print_vma (segment->p_offset, FULL_HEX);
5179 putchar (' ');
5180 }
5181
5182 print_vma (segment->p_vaddr, FULL_HEX);
5183 putchar (' ');
5184 print_vma (segment->p_paddr, FULL_HEX);
5185 putchar (' ');
5186
5187 if ((unsigned long) segment->p_filesz == segment->p_filesz)
5188 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
5189 else
5190 {
5191 print_vma (segment->p_filesz, FULL_HEX);
5192 putchar (' ');
5193 }
5194
5195 if ((unsigned long) segment->p_memsz == segment->p_memsz)
5196 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
5197 else
5198 {
f48e6c45 5199 print_vma (segment->p_memsz, FULL_HEX);
d974e256
JJ
5200 }
5201
5202 printf (" %c%c%c ",
5203 (segment->p_flags & PF_R ? 'R' : ' '),
5204 (segment->p_flags & PF_W ? 'W' : ' '),
5205 (segment->p_flags & PF_X ? 'E' : ' '));
5206
5207 if ((unsigned long) segment->p_align == segment->p_align)
5208 printf ("%#lx", (unsigned long) segment->p_align);
5209 else
5210 {
5211 print_vma (segment->p_align, PREFIX_HEX);
5212 }
5213 }
f7a99963
NC
5214 else
5215 {
5216 print_vma (segment->p_offset, FULL_HEX);
5217 putchar (' ');
5218 print_vma (segment->p_vaddr, FULL_HEX);
5219 putchar (' ');
5220 print_vma (segment->p_paddr, FULL_HEX);
5221 printf ("\n ");
5222 print_vma (segment->p_filesz, FULL_HEX);
5223 putchar (' ');
5224 print_vma (segment->p_memsz, FULL_HEX);
5225 printf (" %c%c%c ",
5226 (segment->p_flags & PF_R ? 'R' : ' '),
5227 (segment->p_flags & PF_W ? 'W' : ' '),
5228 (segment->p_flags & PF_X ? 'E' : ' '));
1d262527 5229 print_vma (segment->p_align, PREFIX_HEX);
f7a99963 5230 }
252b5132 5231
1a9ccd70
NC
5232 putc ('\n', stdout);
5233 }
f54498b4 5234
252b5132
RH
5235 switch (segment->p_type)
5236 {
1a9ccd70 5237 case PT_LOAD:
502d895c
NC
5238#if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5239 required by the ELF standard, several programs, including the Linux
5240 kernel, make use of non-ordered segments. */
1a9ccd70
NC
5241 if (previous_load
5242 && previous_load->p_vaddr > segment->p_vaddr)
5243 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
502d895c 5244#endif
1a9ccd70
NC
5245 if (segment->p_memsz < segment->p_filesz)
5246 error (_("the segment's file size is larger than its memory size\n"));
5247 previous_load = segment;
5248 break;
5249
5250 case PT_PHDR:
5251 /* PR 20815 - Verify that the program header is loaded into memory. */
5252 if (i > 0 && previous_load != NULL)
5253 error (_("the PHDR segment must occur before any LOAD segment\n"));
dda8d76d 5254 if (filedata->file_header.e_machine != EM_PARISC)
1a9ccd70
NC
5255 {
5256 unsigned int j;
5257
dda8d76d
NC
5258 for (j = 1; j < filedata->file_header.e_phnum; j++)
5259 if (filedata->program_headers[j].p_vaddr <= segment->p_vaddr
5260 && (filedata->program_headers[j].p_vaddr
5261 + filedata->program_headers[j].p_memsz)
1a9ccd70
NC
5262 >= (segment->p_vaddr + segment->p_filesz))
5263 break;
dda8d76d 5264 if (j == filedata->file_header.e_phnum)
1a9ccd70
NC
5265 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5266 }
5267 break;
5268
252b5132
RH
5269 case PT_DYNAMIC:
5270 if (dynamic_addr)
5271 error (_("more than one dynamic segment\n"));
5272
20737c13
AM
5273 /* By default, assume that the .dynamic section is the first
5274 section in the DYNAMIC segment. */
5275 dynamic_addr = segment->p_offset;
5276 dynamic_size = segment->p_filesz;
5277
b2d38a17
NC
5278 /* Try to locate the .dynamic section. If there is
5279 a section header table, we can easily locate it. */
dda8d76d 5280 if (filedata->section_headers != NULL)
b2d38a17 5281 {
2cf0635d 5282 Elf_Internal_Shdr * sec;
b2d38a17 5283
dda8d76d 5284 sec = find_section (filedata, ".dynamic");
89fac5e3 5285 if (sec == NULL || sec->sh_size == 0)
b2d38a17 5286 {
28f997cf
TG
5287 /* A corresponding .dynamic section is expected, but on
5288 IA-64/OpenVMS it is OK for it to be missing. */
dda8d76d 5289 if (!is_ia64_vms (filedata))
28f997cf 5290 error (_("no .dynamic section in the dynamic segment\n"));
b2d38a17
NC
5291 break;
5292 }
5293
42bb2e33 5294 if (sec->sh_type == SHT_NOBITS)
20737c13
AM
5295 {
5296 dynamic_size = 0;
5297 break;
5298 }
42bb2e33 5299
b2d38a17
NC
5300 dynamic_addr = sec->sh_offset;
5301 dynamic_size = sec->sh_size;
5302
5303 if (dynamic_addr < segment->p_offset
5304 || dynamic_addr > segment->p_offset + segment->p_filesz)
20737c13
AM
5305 warn (_("the .dynamic section is not contained"
5306 " within the dynamic segment\n"));
b2d38a17 5307 else if (dynamic_addr > segment->p_offset)
20737c13
AM
5308 warn (_("the .dynamic section is not the first section"
5309 " in the dynamic segment.\n"));
b2d38a17 5310 }
39e224f6
MW
5311
5312 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5313 segment. Check this after matching against the section headers
5314 so we don't warn on debuginfo file (which have NOBITS .dynamic
5315 sections). */
c22b42ce
AM
5316 if (dynamic_addr > filedata->file_size
5317 || dynamic_size > filedata->file_size - dynamic_addr)
39e224f6
MW
5318 {
5319 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5320 dynamic_addr = dynamic_size = 0;
5321 }
252b5132
RH
5322 break;
5323
5324 case PT_INTERP:
dda8d76d 5325 if (fseek (filedata->handle, archive_file_offset + (long) segment->p_offset,
fb52b2f4 5326 SEEK_SET))
252b5132
RH
5327 error (_("Unable to find program interpreter name\n"));
5328 else
5329 {
f8eae8b2 5330 char fmt [32];
9495b2e6 5331 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
f8eae8b2
L
5332
5333 if (ret >= (int) sizeof (fmt) || ret < 0)
591a748a 5334 error (_("Internal error: failed to create format string to display program interpreter\n"));
f8eae8b2 5335
252b5132 5336 program_interpreter[0] = 0;
dda8d76d 5337 if (fscanf (filedata->handle, fmt, program_interpreter) <= 0)
7bd7b3ef 5338 error (_("Unable to read program interpreter name\n"));
252b5132
RH
5339
5340 if (do_segments)
f54498b4 5341 printf (_(" [Requesting program interpreter: %s]\n"),
252b5132
RH
5342 program_interpreter);
5343 }
5344 break;
5345 }
252b5132
RH
5346 }
5347
dda8d76d
NC
5348 if (do_segments
5349 && filedata->section_headers != NULL
5350 && filedata->string_table != NULL)
252b5132
RH
5351 {
5352 printf (_("\n Section to Segment mapping:\n"));
5353 printf (_(" Segment Sections...\n"));
5354
dda8d76d 5355 for (i = 0; i < filedata->file_header.e_phnum; i++)
252b5132 5356 {
9ad5cbcf 5357 unsigned int j;
2cf0635d 5358 Elf_Internal_Shdr * section;
252b5132 5359
dda8d76d
NC
5360 segment = filedata->program_headers + i;
5361 section = filedata->section_headers + 1;
252b5132
RH
5362
5363 printf (" %2.2d ", i);
5364
dda8d76d 5365 for (j = 1; j < filedata->file_header.e_shnum; j++, section++)
252b5132 5366 {
f4638467
AM
5367 if (!ELF_TBSS_SPECIAL (section, segment)
5368 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
dda8d76d 5369 printf ("%s ", printable_section_name (filedata, section));
252b5132
RH
5370 }
5371
5372 putc ('\n',stdout);
5373 }
5374 }
5375
32ec8896 5376 return TRUE;
252b5132
RH
5377}
5378
5379
d93f0186
NC
5380/* Find the file offset corresponding to VMA by using the program headers. */
5381
5382static long
dda8d76d 5383offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size)
d93f0186 5384{
2cf0635d 5385 Elf_Internal_Phdr * seg;
d93f0186 5386
dda8d76d 5387 if (! get_program_headers (filedata))
d93f0186
NC
5388 {
5389 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5390 return (long) vma;
5391 }
5392
dda8d76d
NC
5393 for (seg = filedata->program_headers;
5394 seg < filedata->program_headers + filedata->file_header.e_phnum;
d93f0186
NC
5395 ++seg)
5396 {
5397 if (seg->p_type != PT_LOAD)
5398 continue;
5399
5400 if (vma >= (seg->p_vaddr & -seg->p_align)
5401 && vma + size <= seg->p_vaddr + seg->p_filesz)
5402 return vma - seg->p_vaddr + seg->p_offset;
5403 }
5404
5405 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
0af1713e 5406 (unsigned long) vma);
d93f0186
NC
5407 return (long) vma;
5408}
5409
5410
dda8d76d
NC
5411/* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5412 If PROBE is true, this is just a probe and we do not generate any error
5413 messages if the load fails. */
049b0c3a
NC
5414
5415static bfd_boolean
dda8d76d 5416get_32bit_section_headers (Filedata * filedata, bfd_boolean probe)
252b5132 5417{
2cf0635d
NC
5418 Elf32_External_Shdr * shdrs;
5419 Elf_Internal_Shdr * internal;
dda8d76d
NC
5420 unsigned int i;
5421 unsigned int size = filedata->file_header.e_shentsize;
5422 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
049b0c3a
NC
5423
5424 /* PR binutils/17531: Cope with unexpected section header sizes. */
5425 if (size == 0 || num == 0)
5426 return FALSE;
5427 if (size < sizeof * shdrs)
5428 {
5429 if (! probe)
5430 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5431 return FALSE;
5432 }
5433 if (!probe && size > sizeof * shdrs)
5434 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
252b5132 5435
dda8d76d 5436 shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff,
049b0c3a
NC
5437 size, num,
5438 probe ? NULL : _("section headers"));
5439 if (shdrs == NULL)
5440 return FALSE;
252b5132 5441
dda8d76d
NC
5442 free (filedata->section_headers);
5443 filedata->section_headers = (Elf_Internal_Shdr *)
5444 cmalloc (num, sizeof (Elf_Internal_Shdr));
5445 if (filedata->section_headers == NULL)
252b5132 5446 {
049b0c3a 5447 if (!probe)
8b73c356 5448 error (_("Out of memory reading %u section headers\n"), num);
e3d39609 5449 free (shdrs);
049b0c3a 5450 return FALSE;
252b5132
RH
5451 }
5452
dda8d76d 5453 for (i = 0, internal = filedata->section_headers;
560f3c1c 5454 i < num;
b34976b6 5455 i++, internal++)
252b5132
RH
5456 {
5457 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5458 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
5459 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5460 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5461 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5462 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5463 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5464 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5465 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
5466 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
315350be
NC
5467 if (!probe && internal->sh_link > num)
5468 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5469 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5470 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
252b5132
RH
5471 }
5472
5473 free (shdrs);
049b0c3a 5474 return TRUE;
252b5132
RH
5475}
5476
dda8d76d
NC
5477/* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5478
049b0c3a 5479static bfd_boolean
dda8d76d 5480get_64bit_section_headers (Filedata * filedata, bfd_boolean probe)
9ea033b2 5481{
dda8d76d
NC
5482 Elf64_External_Shdr * shdrs;
5483 Elf_Internal_Shdr * internal;
5484 unsigned int i;
5485 unsigned int size = filedata->file_header.e_shentsize;
5486 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
049b0c3a
NC
5487
5488 /* PR binutils/17531: Cope with unexpected section header sizes. */
5489 if (size == 0 || num == 0)
5490 return FALSE;
dda8d76d 5491
049b0c3a
NC
5492 if (size < sizeof * shdrs)
5493 {
5494 if (! probe)
5495 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5496 return FALSE;
5497 }
dda8d76d 5498
049b0c3a
NC
5499 if (! probe && size > sizeof * shdrs)
5500 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
9ea033b2 5501
dda8d76d
NC
5502 shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata,
5503 filedata->file_header.e_shoff,
049b0c3a
NC
5504 size, num,
5505 probe ? NULL : _("section headers"));
5506 if (shdrs == NULL)
5507 return FALSE;
9ea033b2 5508
dda8d76d
NC
5509 free (filedata->section_headers);
5510 filedata->section_headers = (Elf_Internal_Shdr *)
5511 cmalloc (num, sizeof (Elf_Internal_Shdr));
5512 if (filedata->section_headers == NULL)
9ea033b2 5513 {
049b0c3a 5514 if (! probe)
8b73c356 5515 error (_("Out of memory reading %u section headers\n"), num);
e3d39609 5516 free (shdrs);
049b0c3a 5517 return FALSE;
9ea033b2
NC
5518 }
5519
dda8d76d 5520 for (i = 0, internal = filedata->section_headers;
560f3c1c 5521 i < num;
b34976b6 5522 i++, internal++)
9ea033b2
NC
5523 {
5524 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5525 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
66543521
AM
5526 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5527 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5528 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5529 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
9ea033b2
NC
5530 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5531 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5532 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5533 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
315350be
NC
5534 if (!probe && internal->sh_link > num)
5535 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5536 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5537 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
9ea033b2
NC
5538 }
5539
5540 free (shdrs);
049b0c3a 5541 return TRUE;
9ea033b2
NC
5542}
5543
252b5132 5544static Elf_Internal_Sym *
dda8d76d
NC
5545get_32bit_elf_symbols (Filedata * filedata,
5546 Elf_Internal_Shdr * section,
5547 unsigned long * num_syms_return)
252b5132 5548{
ba5cdace 5549 unsigned long number = 0;
dd24e3da 5550 Elf32_External_Sym * esyms = NULL;
ba5cdace 5551 Elf_External_Sym_Shndx * shndx = NULL;
dd24e3da 5552 Elf_Internal_Sym * isyms = NULL;
2cf0635d 5553 Elf_Internal_Sym * psym;
b34976b6 5554 unsigned int j;
e3d39609 5555 elf_section_list * entry;
252b5132 5556
c9c1d674
EG
5557 if (section->sh_size == 0)
5558 {
5559 if (num_syms_return != NULL)
5560 * num_syms_return = 0;
5561 return NULL;
5562 }
5563
dd24e3da 5564 /* Run some sanity checks first. */
c9c1d674 5565 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
dd24e3da 5566 {
c9c1d674 5567 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
dda8d76d
NC
5568 printable_section_name (filedata, section),
5569 (unsigned long) section->sh_entsize);
ba5cdace 5570 goto exit_point;
dd24e3da
NC
5571 }
5572
dda8d76d 5573 if (section->sh_size > filedata->file_size)
f54498b4
NC
5574 {
5575 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
dda8d76d
NC
5576 printable_section_name (filedata, section),
5577 (unsigned long) section->sh_size);
f54498b4
NC
5578 goto exit_point;
5579 }
5580
dd24e3da
NC
5581 number = section->sh_size / section->sh_entsize;
5582
5583 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
5584 {
c9c1d674 5585 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
8066deb1 5586 (unsigned long) section->sh_size,
dda8d76d 5587 printable_section_name (filedata, section),
8066deb1 5588 (unsigned long) section->sh_entsize);
ba5cdace 5589 goto exit_point;
dd24e3da
NC
5590 }
5591
dda8d76d 5592 esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
3f5e193b 5593 section->sh_size, _("symbols"));
dd24e3da 5594 if (esyms == NULL)
ba5cdace 5595 goto exit_point;
252b5132 5596
e3d39609
NC
5597 shndx = NULL;
5598 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5599 {
5600 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5601 continue;
5602
5603 if (shndx != NULL)
5604 {
5605 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5606 free (shndx);
5607 }
5608
5609 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5610 entry->hdr->sh_offset,
5611 1, entry->hdr->sh_size,
5612 _("symbol table section indices"));
5613 if (shndx == NULL)
5614 goto exit_point;
5615
5616 /* PR17531: file: heap-buffer-overflow */
5617 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5618 {
5619 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5620 printable_section_name (filedata, entry->hdr),
5621 (unsigned long) entry->hdr->sh_size,
5622 (unsigned long) section->sh_size);
5623 goto exit_point;
c9c1d674 5624 }
e3d39609 5625 }
9ad5cbcf 5626
3f5e193b 5627 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
252b5132
RH
5628
5629 if (isyms == NULL)
5630 {
8b73c356
NC
5631 error (_("Out of memory reading %lu symbols\n"),
5632 (unsigned long) number);
dd24e3da 5633 goto exit_point;
252b5132
RH
5634 }
5635
dd24e3da 5636 for (j = 0, psym = isyms; j < number; j++, psym++)
252b5132
RH
5637 {
5638 psym->st_name = BYTE_GET (esyms[j].st_name);
5639 psym->st_value = BYTE_GET (esyms[j].st_value);
5640 psym->st_size = BYTE_GET (esyms[j].st_size);
5641 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
4fbb74a6 5642 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
9ad5cbcf
AM
5643 psym->st_shndx
5644 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4fbb74a6
AM
5645 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5646 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
252b5132
RH
5647 psym->st_info = BYTE_GET (esyms[j].st_info);
5648 psym->st_other = BYTE_GET (esyms[j].st_other);
5649 }
5650
dd24e3da 5651 exit_point:
e3d39609
NC
5652 free (shndx);
5653 free (esyms);
252b5132 5654
ba5cdace
NC
5655 if (num_syms_return != NULL)
5656 * num_syms_return = isyms == NULL ? 0 : number;
5657
252b5132
RH
5658 return isyms;
5659}
5660
9ea033b2 5661static Elf_Internal_Sym *
dda8d76d
NC
5662get_64bit_elf_symbols (Filedata * filedata,
5663 Elf_Internal_Shdr * section,
5664 unsigned long * num_syms_return)
9ea033b2 5665{
ba5cdace
NC
5666 unsigned long number = 0;
5667 Elf64_External_Sym * esyms = NULL;
5668 Elf_External_Sym_Shndx * shndx = NULL;
5669 Elf_Internal_Sym * isyms = NULL;
2cf0635d 5670 Elf_Internal_Sym * psym;
b34976b6 5671 unsigned int j;
e3d39609 5672 elf_section_list * entry;
9ea033b2 5673
c9c1d674
EG
5674 if (section->sh_size == 0)
5675 {
5676 if (num_syms_return != NULL)
5677 * num_syms_return = 0;
5678 return NULL;
5679 }
5680
dd24e3da 5681 /* Run some sanity checks first. */
c9c1d674 5682 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
dd24e3da 5683 {
c9c1d674 5684 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
dda8d76d 5685 printable_section_name (filedata, section),
8066deb1 5686 (unsigned long) section->sh_entsize);
ba5cdace 5687 goto exit_point;
dd24e3da
NC
5688 }
5689
dda8d76d 5690 if (section->sh_size > filedata->file_size)
f54498b4
NC
5691 {
5692 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
dda8d76d 5693 printable_section_name (filedata, section),
8066deb1 5694 (unsigned long) section->sh_size);
f54498b4
NC
5695 goto exit_point;
5696 }
5697
dd24e3da
NC
5698 number = section->sh_size / section->sh_entsize;
5699
5700 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
5701 {
c9c1d674 5702 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
8066deb1 5703 (unsigned long) section->sh_size,
dda8d76d 5704 printable_section_name (filedata, section),
8066deb1 5705 (unsigned long) section->sh_entsize);
ba5cdace 5706 goto exit_point;
dd24e3da
NC
5707 }
5708
dda8d76d 5709 esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
3f5e193b 5710 section->sh_size, _("symbols"));
a6e9f9df 5711 if (!esyms)
ba5cdace 5712 goto exit_point;
9ea033b2 5713
e3d39609
NC
5714 shndx = NULL;
5715 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5716 {
5717 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5718 continue;
5719
5720 if (shndx != NULL)
5721 {
5722 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5723 free (shndx);
c9c1d674 5724 }
e3d39609
NC
5725
5726 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5727 entry->hdr->sh_offset,
5728 1, entry->hdr->sh_size,
5729 _("symbol table section indices"));
5730 if (shndx == NULL)
5731 goto exit_point;
5732
5733 /* PR17531: file: heap-buffer-overflow */
5734 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5735 {
5736 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5737 printable_section_name (filedata, entry->hdr),
5738 (unsigned long) entry->hdr->sh_size,
5739 (unsigned long) section->sh_size);
5740 goto exit_point;
5741 }
5742 }
9ad5cbcf 5743
3f5e193b 5744 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
9ea033b2
NC
5745
5746 if (isyms == NULL)
5747 {
8b73c356
NC
5748 error (_("Out of memory reading %lu symbols\n"),
5749 (unsigned long) number);
ba5cdace 5750 goto exit_point;
9ea033b2
NC
5751 }
5752
ba5cdace 5753 for (j = 0, psym = isyms; j < number; j++, psym++)
9ea033b2
NC
5754 {
5755 psym->st_name = BYTE_GET (esyms[j].st_name);
5756 psym->st_info = BYTE_GET (esyms[j].st_info);
5757 psym->st_other = BYTE_GET (esyms[j].st_other);
5758 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
ba5cdace 5759
4fbb74a6 5760 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
9ad5cbcf
AM
5761 psym->st_shndx
5762 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4fbb74a6
AM
5763 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5764 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
ba5cdace 5765
66543521
AM
5766 psym->st_value = BYTE_GET (esyms[j].st_value);
5767 psym->st_size = BYTE_GET (esyms[j].st_size);
9ea033b2
NC
5768 }
5769
ba5cdace 5770 exit_point:
e3d39609
NC
5771 free (shndx);
5772 free (esyms);
ba5cdace
NC
5773
5774 if (num_syms_return != NULL)
5775 * num_syms_return = isyms == NULL ? 0 : number;
9ea033b2
NC
5776
5777 return isyms;
5778}
5779
d1133906 5780static const char *
dda8d76d 5781get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
d1133906 5782{
5477e8a0 5783 static char buff[1024];
2cf0635d 5784 char * p = buff;
32ec8896
NC
5785 unsigned int field_size = is_32bit_elf ? 8 : 16;
5786 signed int sindex;
5787 unsigned int size = sizeof (buff) - (field_size + 4 + 1);
8d5ff12c
L
5788 bfd_vma os_flags = 0;
5789 bfd_vma proc_flags = 0;
5790 bfd_vma unknown_flags = 0;
148b93f2 5791 static const struct
5477e8a0 5792 {
2cf0635d 5793 const char * str;
32ec8896 5794 unsigned int len;
5477e8a0
L
5795 }
5796 flags [] =
5797 {
cfcac11d
NC
5798 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
5799 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
5800 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
5801 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
5802 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
5803 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
5804 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
5805 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
5806 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
5807 /* 9 */ { STRING_COMMA_LEN ("TLS") },
5808 /* IA-64 specific. */
5809 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
5810 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
5811 /* IA-64 OpenVMS specific. */
5812 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
5813 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
5814 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
5815 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
5816 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
5817 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
18ae9cc1 5818 /* Generic. */
cfcac11d 5819 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
18ae9cc1 5820 /* SPARC specific. */
77115a4a 5821 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
ac4c9b04
MG
5822 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
5823 /* ARM specific. */
5824 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
f0728ee3 5825 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
a91e1603
L
5826 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
5827 /* GNU specific. */
5828 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
83eef883
AFB
5829 /* VLE specific. */
5830 /* 25 */ { STRING_COMMA_LEN ("VLE") },
5477e8a0
L
5831 };
5832
5833 if (do_section_details)
5834 {
8d5ff12c
L
5835 sprintf (buff, "[%*.*lx]: ",
5836 field_size, field_size, (unsigned long) sh_flags);
5837 p += field_size + 4;
5477e8a0 5838 }
76da6bbe 5839
d1133906
NC
5840 while (sh_flags)
5841 {
5842 bfd_vma flag;
5843
5844 flag = sh_flags & - sh_flags;
5845 sh_flags &= ~ flag;
76da6bbe 5846
5477e8a0 5847 if (do_section_details)
d1133906 5848 {
5477e8a0
L
5849 switch (flag)
5850 {
91d6fa6a
NC
5851 case SHF_WRITE: sindex = 0; break;
5852 case SHF_ALLOC: sindex = 1; break;
5853 case SHF_EXECINSTR: sindex = 2; break;
5854 case SHF_MERGE: sindex = 3; break;
5855 case SHF_STRINGS: sindex = 4; break;
5856 case SHF_INFO_LINK: sindex = 5; break;
5857 case SHF_LINK_ORDER: sindex = 6; break;
5858 case SHF_OS_NONCONFORMING: sindex = 7; break;
5859 case SHF_GROUP: sindex = 8; break;
5860 case SHF_TLS: sindex = 9; break;
18ae9cc1 5861 case SHF_EXCLUDE: sindex = 18; break;
77115a4a 5862 case SHF_COMPRESSED: sindex = 20; break;
a91e1603 5863 case SHF_GNU_MBIND: sindex = 24; break;
76da6bbe 5864
5477e8a0 5865 default:
91d6fa6a 5866 sindex = -1;
dda8d76d 5867 switch (filedata->file_header.e_machine)
148b93f2 5868 {
cfcac11d 5869 case EM_IA_64:
148b93f2 5870 if (flag == SHF_IA_64_SHORT)
91d6fa6a 5871 sindex = 10;
148b93f2 5872 else if (flag == SHF_IA_64_NORECOV)
91d6fa6a 5873 sindex = 11;
148b93f2 5874#ifdef BFD64
dda8d76d 5875 else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
148b93f2
NC
5876 switch (flag)
5877 {
91d6fa6a
NC
5878 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
5879 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
5880 case SHF_IA_64_VMS_SHARED: sindex = 14; break;
5881 case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
5882 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
5883 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
148b93f2
NC
5884 default: break;
5885 }
5886#endif
cfcac11d
NC
5887 break;
5888
caa83f8b 5889 case EM_386:
22abe556 5890 case EM_IAMCU:
caa83f8b 5891 case EM_X86_64:
7f502d6c 5892 case EM_L1OM:
7a9068fe 5893 case EM_K1OM:
cfcac11d
NC
5894 case EM_OLD_SPARCV9:
5895 case EM_SPARC32PLUS:
5896 case EM_SPARCV9:
5897 case EM_SPARC:
18ae9cc1 5898 if (flag == SHF_ORDERED)
91d6fa6a 5899 sindex = 19;
cfcac11d 5900 break;
ac4c9b04
MG
5901
5902 case EM_ARM:
5903 switch (flag)
5904 {
5905 case SHF_ENTRYSECT: sindex = 21; break;
f0728ee3 5906 case SHF_ARM_PURECODE: sindex = 22; break;
ac4c9b04
MG
5907 case SHF_COMDEF: sindex = 23; break;
5908 default: break;
5909 }
5910 break;
83eef883
AFB
5911 case EM_PPC:
5912 if (flag == SHF_PPC_VLE)
5913 sindex = 25;
5914 break;
ac4c9b04 5915
cfcac11d
NC
5916 default:
5917 break;
148b93f2 5918 }
5477e8a0
L
5919 }
5920
91d6fa6a 5921 if (sindex != -1)
5477e8a0 5922 {
8d5ff12c
L
5923 if (p != buff + field_size + 4)
5924 {
5925 if (size < (10 + 2))
bee0ee85
NC
5926 {
5927 warn (_("Internal error: not enough buffer room for section flag info"));
5928 return _("<unknown>");
5929 }
8d5ff12c
L
5930 size -= 2;
5931 *p++ = ',';
5932 *p++ = ' ';
5933 }
5934
91d6fa6a
NC
5935 size -= flags [sindex].len;
5936 p = stpcpy (p, flags [sindex].str);
5477e8a0 5937 }
3b22753a 5938 else if (flag & SHF_MASKOS)
8d5ff12c 5939 os_flags |= flag;
d1133906 5940 else if (flag & SHF_MASKPROC)
8d5ff12c 5941 proc_flags |= flag;
d1133906 5942 else
8d5ff12c 5943 unknown_flags |= flag;
5477e8a0
L
5944 }
5945 else
5946 {
5947 switch (flag)
5948 {
5949 case SHF_WRITE: *p = 'W'; break;
5950 case SHF_ALLOC: *p = 'A'; break;
5951 case SHF_EXECINSTR: *p = 'X'; break;
5952 case SHF_MERGE: *p = 'M'; break;
5953 case SHF_STRINGS: *p = 'S'; break;
5954 case SHF_INFO_LINK: *p = 'I'; break;
5955 case SHF_LINK_ORDER: *p = 'L'; break;
5956 case SHF_OS_NONCONFORMING: *p = 'O'; break;
5957 case SHF_GROUP: *p = 'G'; break;
5958 case SHF_TLS: *p = 'T'; break;
18ae9cc1 5959 case SHF_EXCLUDE: *p = 'E'; break;
77115a4a 5960 case SHF_COMPRESSED: *p = 'C'; break;
a91e1603 5961 case SHF_GNU_MBIND: *p = 'D'; break;
5477e8a0
L
5962
5963 default:
dda8d76d
NC
5964 if ((filedata->file_header.e_machine == EM_X86_64
5965 || filedata->file_header.e_machine == EM_L1OM
5966 || filedata->file_header.e_machine == EM_K1OM)
5477e8a0
L
5967 && flag == SHF_X86_64_LARGE)
5968 *p = 'l';
dda8d76d 5969 else if (filedata->file_header.e_machine == EM_ARM
f0728ee3 5970 && flag == SHF_ARM_PURECODE)
91f68a68 5971 *p = 'y';
dda8d76d 5972 else if (filedata->file_header.e_machine == EM_PPC
83eef883
AFB
5973 && flag == SHF_PPC_VLE)
5974 *p = 'v';
5477e8a0
L
5975 else if (flag & SHF_MASKOS)
5976 {
5977 *p = 'o';
5978 sh_flags &= ~ SHF_MASKOS;
5979 }
5980 else if (flag & SHF_MASKPROC)
5981 {
5982 *p = 'p';
5983 sh_flags &= ~ SHF_MASKPROC;
5984 }
5985 else
5986 *p = 'x';
5987 break;
5988 }
5989 p++;
d1133906
NC
5990 }
5991 }
76da6bbe 5992
8d5ff12c
L
5993 if (do_section_details)
5994 {
5995 if (os_flags)
5996 {
5997 size -= 5 + field_size;
5998 if (p != buff + field_size + 4)
5999 {
6000 if (size < (2 + 1))
bee0ee85
NC
6001 {
6002 warn (_("Internal error: not enough buffer room for section flag info"));
6003 return _("<unknown>");
6004 }
8d5ff12c
L
6005 size -= 2;
6006 *p++ = ',';
6007 *p++ = ' ';
6008 }
6009 sprintf (p, "OS (%*.*lx)", field_size, field_size,
6010 (unsigned long) os_flags);
6011 p += 5 + field_size;
6012 }
6013 if (proc_flags)
6014 {
6015 size -= 7 + field_size;
6016 if (p != buff + field_size + 4)
6017 {
6018 if (size < (2 + 1))
bee0ee85
NC
6019 {
6020 warn (_("Internal error: not enough buffer room for section flag info"));
6021 return _("<unknown>");
6022 }
8d5ff12c
L
6023 size -= 2;
6024 *p++ = ',';
6025 *p++ = ' ';
6026 }
6027 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
6028 (unsigned long) proc_flags);
6029 p += 7 + field_size;
6030 }
6031 if (unknown_flags)
6032 {
6033 size -= 10 + field_size;
6034 if (p != buff + field_size + 4)
6035 {
6036 if (size < (2 + 1))
bee0ee85
NC
6037 {
6038 warn (_("Internal error: not enough buffer room for section flag info"));
6039 return _("<unknown>");
6040 }
8d5ff12c
L
6041 size -= 2;
6042 *p++ = ',';
6043 *p++ = ' ';
6044 }
2b692964 6045 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
8d5ff12c
L
6046 (unsigned long) unknown_flags);
6047 p += 10 + field_size;
6048 }
6049 }
6050
e9e44622 6051 *p = '\0';
d1133906
NC
6052 return buff;
6053}
6054
77115a4a 6055static unsigned int
ebdf1ebf 6056get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size)
77115a4a
L
6057{
6058 if (is_32bit_elf)
6059 {
6060 Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
d8024a91 6061
ebdf1ebf
NC
6062 if (size < sizeof (* echdr))
6063 {
6064 error (_("Compressed section is too small even for a compression header\n"));
6065 return 0;
6066 }
6067
77115a4a
L
6068 chdr->ch_type = BYTE_GET (echdr->ch_type);
6069 chdr->ch_size = BYTE_GET (echdr->ch_size);
6070 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6071 return sizeof (*echdr);
6072 }
6073 else
6074 {
6075 Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
d8024a91 6076
ebdf1ebf
NC
6077 if (size < sizeof (* echdr))
6078 {
6079 error (_("Compressed section is too small even for a compression header\n"));
6080 return 0;
6081 }
6082
77115a4a
L
6083 chdr->ch_type = BYTE_GET (echdr->ch_type);
6084 chdr->ch_size = BYTE_GET (echdr->ch_size);
6085 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6086 return sizeof (*echdr);
6087 }
6088}
6089
32ec8896 6090static bfd_boolean
dda8d76d 6091process_section_headers (Filedata * filedata)
252b5132 6092{
2cf0635d 6093 Elf_Internal_Shdr * section;
b34976b6 6094 unsigned int i;
252b5132 6095
dda8d76d 6096 filedata->section_headers = NULL;
252b5132 6097
dda8d76d 6098 if (filedata->file_header.e_shnum == 0)
252b5132 6099 {
82f2dbf7 6100 /* PR binutils/12467. */
dda8d76d 6101 if (filedata->file_header.e_shoff != 0)
32ec8896
NC
6102 {
6103 warn (_("possibly corrupt ELF file header - it has a non-zero"
6104 " section header offset, but no section headers\n"));
6105 return FALSE;
6106 }
82f2dbf7 6107 else if (do_sections)
252b5132
RH
6108 printf (_("\nThere are no sections in this file.\n"));
6109
32ec8896 6110 return TRUE;
252b5132
RH
6111 }
6112
6113 if (do_sections && !do_header)
d3a49aa8
AM
6114 printf (ngettext ("There is %d section header, "
6115 "starting at offset 0x%lx:\n",
6116 "There are %d section headers, "
6117 "starting at offset 0x%lx:\n",
dda8d76d
NC
6118 filedata->file_header.e_shnum),
6119 filedata->file_header.e_shnum,
6120 (unsigned long) filedata->file_header.e_shoff);
252b5132 6121
9ea033b2
NC
6122 if (is_32bit_elf)
6123 {
dda8d76d 6124 if (! get_32bit_section_headers (filedata, FALSE))
32ec8896
NC
6125 return FALSE;
6126 }
6127 else
6128 {
dda8d76d 6129 if (! get_64bit_section_headers (filedata, FALSE))
32ec8896 6130 return FALSE;
9ea033b2 6131 }
252b5132
RH
6132
6133 /* Read in the string table, so that we have names to display. */
dda8d76d
NC
6134 if (filedata->file_header.e_shstrndx != SHN_UNDEF
6135 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
252b5132 6136 {
dda8d76d 6137 section = filedata->section_headers + filedata->file_header.e_shstrndx;
d40ac9bd 6138
c256ffe7
JJ
6139 if (section->sh_size != 0)
6140 {
dda8d76d
NC
6141 filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset,
6142 1, section->sh_size,
6143 _("string table"));
0de14b54 6144
dda8d76d 6145 filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0;
c256ffe7 6146 }
252b5132
RH
6147 }
6148
6149 /* Scan the sections for the dynamic symbol table
e3c8793a 6150 and dynamic string table and debug sections. */
252b5132
RH
6151 dynamic_symbols = NULL;
6152 dynamic_strings = NULL;
6153 dynamic_syminfo = NULL;
6a40cf0c 6154 symtab_shndx_list = NULL;
103f02d3 6155
89fac5e3 6156 eh_addr_size = is_32bit_elf ? 4 : 8;
dda8d76d 6157 switch (filedata->file_header.e_machine)
89fac5e3
RS
6158 {
6159 case EM_MIPS:
6160 case EM_MIPS_RS3_LE:
6161 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6162 FDE addresses. However, the ABI also has a semi-official ILP32
6163 variant for which the normal FDE address size rules apply.
6164
6165 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6166 section, where XX is the size of longs in bits. Unfortunately,
6167 earlier compilers provided no way of distinguishing ILP32 objects
6168 from LP64 objects, so if there's any doubt, we should assume that
6169 the official LP64 form is being used. */
dda8d76d
NC
6170 if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
6171 && find_section (filedata, ".gcc_compiled_long32") == NULL)
89fac5e3
RS
6172 eh_addr_size = 8;
6173 break;
0f56a26a
DD
6174
6175 case EM_H8_300:
6176 case EM_H8_300H:
dda8d76d 6177 switch (filedata->file_header.e_flags & EF_H8_MACH)
0f56a26a
DD
6178 {
6179 case E_H8_MACH_H8300:
6180 case E_H8_MACH_H8300HN:
6181 case E_H8_MACH_H8300SN:
6182 case E_H8_MACH_H8300SXN:
6183 eh_addr_size = 2;
6184 break;
6185 case E_H8_MACH_H8300H:
6186 case E_H8_MACH_H8300S:
6187 case E_H8_MACH_H8300SX:
6188 eh_addr_size = 4;
6189 break;
6190 }
f4236fe4
DD
6191 break;
6192
ff7eeb89 6193 case EM_M32C_OLD:
f4236fe4 6194 case EM_M32C:
dda8d76d 6195 switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK)
f4236fe4
DD
6196 {
6197 case EF_M32C_CPU_M16C:
6198 eh_addr_size = 2;
6199 break;
6200 }
6201 break;
89fac5e3
RS
6202 }
6203
76ca31c0
NC
6204#define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6205 do \
6206 { \
6207 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6208 if (section->sh_entsize != expected_entsize) \
9dd3a467 6209 { \
76ca31c0
NC
6210 char buf[40]; \
6211 sprintf_vma (buf, section->sh_entsize); \
6212 /* Note: coded this way so that there is a single string for \
6213 translation. */ \
6214 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6215 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6216 (unsigned) expected_entsize); \
9dd3a467 6217 section->sh_entsize = expected_entsize; \
76ca31c0
NC
6218 } \
6219 } \
08d8fa11 6220 while (0)
9dd3a467
NC
6221
6222#define CHECK_ENTSIZE(section, i, type) \
08d8fa11
JJ
6223 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6224 sizeof (Elf64_External_##type))
6225
dda8d76d
NC
6226 for (i = 0, section = filedata->section_headers;
6227 i < filedata->file_header.e_shnum;
b34976b6 6228 i++, section++)
252b5132 6229 {
2cf0635d 6230 char * name = SECTION_NAME (section);
252b5132
RH
6231
6232 if (section->sh_type == SHT_DYNSYM)
6233 {
6234 if (dynamic_symbols != NULL)
6235 {
6236 error (_("File contains multiple dynamic symbol tables\n"));
6237 continue;
6238 }
6239
08d8fa11 6240 CHECK_ENTSIZE (section, i, Sym);
dda8d76d 6241 dynamic_symbols = GET_ELF_SYMBOLS (filedata, section, & num_dynamic_syms);
252b5132
RH
6242 }
6243 else if (section->sh_type == SHT_STRTAB
18bd398b 6244 && streq (name, ".dynstr"))
252b5132
RH
6245 {
6246 if (dynamic_strings != NULL)
6247 {
6248 error (_("File contains multiple dynamic string tables\n"));
6249 continue;
6250 }
6251
dda8d76d 6252 dynamic_strings = (char *) get_data (NULL, filedata, section->sh_offset,
3f5e193b
NC
6253 1, section->sh_size,
6254 _("dynamic strings"));
59245841 6255 dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
252b5132 6256 }
9ad5cbcf
AM
6257 else if (section->sh_type == SHT_SYMTAB_SHNDX)
6258 {
6a40cf0c 6259 elf_section_list * entry = xmalloc (sizeof * entry);
dda8d76d 6260
6a40cf0c
NC
6261 entry->hdr = section;
6262 entry->next = symtab_shndx_list;
6263 symtab_shndx_list = entry;
9ad5cbcf 6264 }
08d8fa11
JJ
6265 else if (section->sh_type == SHT_SYMTAB)
6266 CHECK_ENTSIZE (section, i, Sym);
6267 else if (section->sh_type == SHT_GROUP)
6268 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
6269 else if (section->sh_type == SHT_REL)
6270 CHECK_ENTSIZE (section, i, Rel);
6271 else if (section->sh_type == SHT_RELA)
6272 CHECK_ENTSIZE (section, i, Rela);
252b5132 6273 else if ((do_debugging || do_debug_info || do_debug_abbrevs
f9f0e732 6274 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
cb8f3167 6275 || do_debug_aranges || do_debug_frames || do_debug_macinfo
657d0d47 6276 || do_debug_str || do_debug_loc || do_debug_ranges
d85bf2ba 6277 || do_debug_addr || do_debug_cu_index || do_debug_links)
1b315056
CS
6278 && (const_strneq (name, ".debug_")
6279 || const_strneq (name, ".zdebug_")))
252b5132 6280 {
1b315056
CS
6281 if (name[1] == 'z')
6282 name += sizeof (".zdebug_") - 1;
6283 else
6284 name += sizeof (".debug_") - 1;
252b5132
RH
6285
6286 if (do_debugging
4723351a
CC
6287 || (do_debug_info && const_strneq (name, "info"))
6288 || (do_debug_info && const_strneq (name, "types"))
6289 || (do_debug_abbrevs && const_strneq (name, "abbrev"))
b40bf0a2
NC
6290 || (do_debug_lines && strcmp (name, "line") == 0)
6291 || (do_debug_lines && const_strneq (name, "line."))
4723351a
CC
6292 || (do_debug_pubnames && const_strneq (name, "pubnames"))
6293 || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
459d52c8
DE
6294 || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
6295 || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
4723351a
CC
6296 || (do_debug_aranges && const_strneq (name, "aranges"))
6297 || (do_debug_ranges && const_strneq (name, "ranges"))
77145576 6298 || (do_debug_ranges && const_strneq (name, "rnglists"))
4723351a
CC
6299 || (do_debug_frames && const_strneq (name, "frame"))
6300 || (do_debug_macinfo && const_strneq (name, "macinfo"))
6301 || (do_debug_macinfo && const_strneq (name, "macro"))
6302 || (do_debug_str && const_strneq (name, "str"))
6303 || (do_debug_loc && const_strneq (name, "loc"))
77145576 6304 || (do_debug_loc && const_strneq (name, "loclists"))
657d0d47
CC
6305 || (do_debug_addr && const_strneq (name, "addr"))
6306 || (do_debug_cu_index && const_strneq (name, "cu_index"))
6307 || (do_debug_cu_index && const_strneq (name, "tu_index"))
252b5132 6308 )
dda8d76d 6309 request_dump_bynumber (filedata, i, DEBUG_DUMP);
252b5132 6310 }
a262ae96 6311 /* Linkonce section to be combined with .debug_info at link time. */
09fd7e38 6312 else if ((do_debugging || do_debug_info)
0112cd26 6313 && const_strneq (name, ".gnu.linkonce.wi."))
dda8d76d 6314 request_dump_bynumber (filedata, i, DEBUG_DUMP);
18bd398b 6315 else if (do_debug_frames && streq (name, ".eh_frame"))
dda8d76d 6316 request_dump_bynumber (filedata, i, DEBUG_DUMP);
61364358
JK
6317 else if (do_gdb_index && (streq (name, ".gdb_index")
6318 || streq (name, ".debug_names")))
dda8d76d 6319 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6f875884
TG
6320 /* Trace sections for Itanium VMS. */
6321 else if ((do_debugging || do_trace_info || do_trace_abbrevs
6322 || do_trace_aranges)
6323 && const_strneq (name, ".trace_"))
6324 {
6325 name += sizeof (".trace_") - 1;
6326
6327 if (do_debugging
6328 || (do_trace_info && streq (name, "info"))
6329 || (do_trace_abbrevs && streq (name, "abbrev"))
6330 || (do_trace_aranges && streq (name, "aranges"))
6331 )
dda8d76d 6332 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6f875884 6333 }
dda8d76d
NC
6334 else if ((do_debugging || do_debug_links)
6335 && (const_strneq (name, ".gnu_debuglink")
6336 || const_strneq (name, ".gnu_debugaltlink")))
6337 request_dump_bynumber (filedata, i, DEBUG_DUMP);
252b5132
RH
6338 }
6339
6340 if (! do_sections)
32ec8896 6341 return TRUE;
252b5132 6342
dda8d76d 6343 if (filedata->file_header.e_shnum > 1)
3a1a2036
NC
6344 printf (_("\nSection Headers:\n"));
6345 else
6346 printf (_("\nSection Header:\n"));
76da6bbe 6347
f7a99963 6348 if (is_32bit_elf)
595cf52e 6349 {
5477e8a0 6350 if (do_section_details)
595cf52e
L
6351 {
6352 printf (_(" [Nr] Name\n"));
5477e8a0 6353 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
595cf52e
L
6354 }
6355 else
6356 printf
6357 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6358 }
d974e256 6359 else if (do_wide)
595cf52e 6360 {
5477e8a0 6361 if (do_section_details)
595cf52e
L
6362 {
6363 printf (_(" [Nr] Name\n"));
5477e8a0 6364 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
595cf52e
L
6365 }
6366 else
6367 printf
6368 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6369 }
f7a99963
NC
6370 else
6371 {
5477e8a0 6372 if (do_section_details)
595cf52e
L
6373 {
6374 printf (_(" [Nr] Name\n"));
5477e8a0
L
6375 printf (_(" Type Address Offset Link\n"));
6376 printf (_(" Size EntSize Info Align\n"));
595cf52e
L
6377 }
6378 else
6379 {
6380 printf (_(" [Nr] Name Type Address Offset\n"));
6381 printf (_(" Size EntSize Flags Link Info Align\n"));
6382 }
f7a99963 6383 }
252b5132 6384
5477e8a0
L
6385 if (do_section_details)
6386 printf (_(" Flags\n"));
6387
dda8d76d
NC
6388 for (i = 0, section = filedata->section_headers;
6389 i < filedata->file_header.e_shnum;
b34976b6 6390 i++, section++)
252b5132 6391 {
dd905818
NC
6392 /* Run some sanity checks on the section header. */
6393
6394 /* Check the sh_link field. */
6395 switch (section->sh_type)
6396 {
285e3f99
AM
6397 case SHT_REL:
6398 case SHT_RELA:
6399 if (section->sh_link == 0
6400 && (filedata->file_header.e_type == ET_EXEC
6401 || filedata->file_header.e_type == ET_DYN))
6402 /* A dynamic relocation section where all entries use a
6403 zero symbol index need not specify a symtab section. */
6404 break;
6405 /* Fall through. */
dd905818
NC
6406 case SHT_SYMTAB_SHNDX:
6407 case SHT_GROUP:
6408 case SHT_HASH:
6409 case SHT_GNU_HASH:
6410 case SHT_GNU_versym:
285e3f99 6411 if (section->sh_link == 0
dda8d76d
NC
6412 || section->sh_link >= filedata->file_header.e_shnum
6413 || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB
6414 && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM))
dd905818
NC
6415 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6416 i, section->sh_link);
6417 break;
6418
6419 case SHT_DYNAMIC:
6420 case SHT_SYMTAB:
6421 case SHT_DYNSYM:
6422 case SHT_GNU_verneed:
6423 case SHT_GNU_verdef:
6424 case SHT_GNU_LIBLIST:
285e3f99 6425 if (section->sh_link == 0
dda8d76d
NC
6426 || section->sh_link >= filedata->file_header.e_shnum
6427 || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB)
dd905818
NC
6428 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6429 i, section->sh_link);
6430 break;
6431
6432 case SHT_INIT_ARRAY:
6433 case SHT_FINI_ARRAY:
6434 case SHT_PREINIT_ARRAY:
6435 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6436 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6437 i, section->sh_link);
6438 break;
6439
6440 default:
6441 /* FIXME: Add support for target specific section types. */
6442#if 0 /* Currently we do not check other section types as there are too
6443 many special cases. Stab sections for example have a type
6444 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6445 section. */
6446 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6447 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6448 i, section->sh_link);
6449#endif
6450 break;
6451 }
6452
6453 /* Check the sh_info field. */
6454 switch (section->sh_type)
6455 {
6456 case SHT_REL:
6457 case SHT_RELA:
285e3f99
AM
6458 if (section->sh_info == 0
6459 && (filedata->file_header.e_type == ET_EXEC
6460 || filedata->file_header.e_type == ET_DYN))
6461 /* Dynamic relocations apply to segments, so they do not
6462 need to specify the section they relocate. */
6463 break;
6464 if (section->sh_info == 0
dda8d76d
NC
6465 || section->sh_info >= filedata->file_header.e_shnum
6466 || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS
6467 && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
6468 && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
6469 && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
385e5b90
L
6470 && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY
6471 && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY
dd905818 6472 /* FIXME: Are other section types valid ? */
dda8d76d 6473 && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
285e3f99
AM
6474 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6475 i, section->sh_info);
dd905818
NC
6476 break;
6477
6478 case SHT_DYNAMIC:
6479 case SHT_HASH:
6480 case SHT_SYMTAB_SHNDX:
6481 case SHT_INIT_ARRAY:
6482 case SHT_FINI_ARRAY:
6483 case SHT_PREINIT_ARRAY:
6484 if (section->sh_info != 0)
6485 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6486 i, section->sh_info);
6487 break;
6488
6489 case SHT_GROUP:
6490 case SHT_SYMTAB:
6491 case SHT_DYNSYM:
6492 /* A symbol index - we assume that it is valid. */
6493 break;
6494
6495 default:
6496 /* FIXME: Add support for target specific section types. */
6497 if (section->sh_type == SHT_NOBITS)
6498 /* NOBITS section headers with non-zero sh_info fields can be
6499 created when a binary is stripped of everything but its debug
1a9ccd70
NC
6500 information. The stripped sections have their headers
6501 preserved but their types set to SHT_NOBITS. So do not check
6502 this type of section. */
dd905818
NC
6503 ;
6504 else if (section->sh_flags & SHF_INFO_LINK)
6505 {
dda8d76d 6506 if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum)
dd905818
NC
6507 warn (_("[%2u]: Expected link to another section in info field"), i);
6508 }
a91e1603
L
6509 else if (section->sh_type < SHT_LOOS
6510 && (section->sh_flags & SHF_GNU_MBIND) == 0
6511 && section->sh_info != 0)
dd905818
NC
6512 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6513 i, section->sh_info);
6514 break;
6515 }
6516
3e6b6445 6517 /* Check the sh_size field. */
dda8d76d 6518 if (section->sh_size > filedata->file_size
3e6b6445
NC
6519 && section->sh_type != SHT_NOBITS
6520 && section->sh_type != SHT_NULL
6521 && section->sh_type < SHT_LOOS)
6522 warn (_("Size of section %u is larger than the entire file!\n"), i);
6523
7bfd842d 6524 printf (" [%2u] ", i);
5477e8a0 6525 if (do_section_details)
dda8d76d 6526 printf ("%s\n ", printable_section_name (filedata, section));
595cf52e 6527 else
74e1a04b 6528 print_symbol (-17, SECTION_NAME (section));
0b4362b0 6529
ea52a088 6530 printf (do_wide ? " %-15s " : " %-15.15s ",
dda8d76d 6531 get_section_type_name (filedata, section->sh_type));
0b4362b0 6532
f7a99963
NC
6533 if (is_32bit_elf)
6534 {
cfcac11d
NC
6535 const char * link_too_big = NULL;
6536
f7a99963 6537 print_vma (section->sh_addr, LONG_HEX);
76da6bbe 6538
f7a99963
NC
6539 printf ( " %6.6lx %6.6lx %2.2lx",
6540 (unsigned long) section->sh_offset,
6541 (unsigned long) section->sh_size,
6542 (unsigned long) section->sh_entsize);
d1133906 6543
5477e8a0
L
6544 if (do_section_details)
6545 fputs (" ", stdout);
6546 else
dda8d76d 6547 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
76da6bbe 6548
dda8d76d 6549 if (section->sh_link >= filedata->file_header.e_shnum)
cfcac11d
NC
6550 {
6551 link_too_big = "";
6552 /* The sh_link value is out of range. Normally this indicates
caa83f8b 6553 an error but it can have special values in Solaris binaries. */
dda8d76d 6554 switch (filedata->file_header.e_machine)
cfcac11d 6555 {
caa83f8b 6556 case EM_386:
22abe556 6557 case EM_IAMCU:
caa83f8b 6558 case EM_X86_64:
7f502d6c 6559 case EM_L1OM:
7a9068fe 6560 case EM_K1OM:
cfcac11d
NC
6561 case EM_OLD_SPARCV9:
6562 case EM_SPARC32PLUS:
6563 case EM_SPARCV9:
6564 case EM_SPARC:
6565 if (section->sh_link == (SHN_BEFORE & 0xffff))
6566 link_too_big = "BEFORE";
6567 else if (section->sh_link == (SHN_AFTER & 0xffff))
6568 link_too_big = "AFTER";
6569 break;
6570 default:
6571 break;
6572 }
6573 }
6574
6575 if (do_section_details)
6576 {
6577 if (link_too_big != NULL && * link_too_big)
6578 printf ("<%s> ", link_too_big);
6579 else
6580 printf ("%2u ", section->sh_link);
6581 printf ("%3u %2lu\n", section->sh_info,
6582 (unsigned long) section->sh_addralign);
6583 }
6584 else
6585 printf ("%2u %3u %2lu\n",
6586 section->sh_link,
6587 section->sh_info,
6588 (unsigned long) section->sh_addralign);
6589
6590 if (link_too_big && ! * link_too_big)
6591 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6592 i, section->sh_link);
f7a99963 6593 }
d974e256
JJ
6594 else if (do_wide)
6595 {
6596 print_vma (section->sh_addr, LONG_HEX);
6597
6598 if ((long) section->sh_offset == section->sh_offset)
6599 printf (" %6.6lx", (unsigned long) section->sh_offset);
6600 else
6601 {
6602 putchar (' ');
6603 print_vma (section->sh_offset, LONG_HEX);
6604 }
6605
6606 if ((unsigned long) section->sh_size == section->sh_size)
6607 printf (" %6.6lx", (unsigned long) section->sh_size);
6608 else
6609 {
6610 putchar (' ');
6611 print_vma (section->sh_size, LONG_HEX);
6612 }
6613
6614 if ((unsigned long) section->sh_entsize == section->sh_entsize)
6615 printf (" %2.2lx", (unsigned long) section->sh_entsize);
6616 else
6617 {
6618 putchar (' ');
6619 print_vma (section->sh_entsize, LONG_HEX);
6620 }
6621
5477e8a0
L
6622 if (do_section_details)
6623 fputs (" ", stdout);
6624 else
dda8d76d 6625 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
d974e256 6626
72de5009 6627 printf ("%2u %3u ", section->sh_link, section->sh_info);
d974e256
JJ
6628
6629 if ((unsigned long) section->sh_addralign == section->sh_addralign)
72de5009 6630 printf ("%2lu\n", (unsigned long) section->sh_addralign);
d974e256
JJ
6631 else
6632 {
6633 print_vma (section->sh_addralign, DEC);
6634 putchar ('\n');
6635 }
6636 }
5477e8a0 6637 else if (do_section_details)
595cf52e 6638 {
55cc53e9 6639 putchar (' ');
595cf52e
L
6640 print_vma (section->sh_addr, LONG_HEX);
6641 if ((long) section->sh_offset == section->sh_offset)
5477e8a0 6642 printf (" %16.16lx", (unsigned long) section->sh_offset);
595cf52e
L
6643 else
6644 {
6645 printf (" ");
6646 print_vma (section->sh_offset, LONG_HEX);
6647 }
72de5009 6648 printf (" %u\n ", section->sh_link);
595cf52e 6649 print_vma (section->sh_size, LONG_HEX);
5477e8a0 6650 putchar (' ');
595cf52e
L
6651 print_vma (section->sh_entsize, LONG_HEX);
6652
72de5009
AM
6653 printf (" %-16u %lu\n",
6654 section->sh_info,
595cf52e
L
6655 (unsigned long) section->sh_addralign);
6656 }
f7a99963
NC
6657 else
6658 {
6659 putchar (' ');
6660 print_vma (section->sh_addr, LONG_HEX);
53c7db4b
KH
6661 if ((long) section->sh_offset == section->sh_offset)
6662 printf (" %8.8lx", (unsigned long) section->sh_offset);
6663 else
6664 {
6665 printf (" ");
6666 print_vma (section->sh_offset, LONG_HEX);
6667 }
f7a99963
NC
6668 printf ("\n ");
6669 print_vma (section->sh_size, LONG_HEX);
6670 printf (" ");
6671 print_vma (section->sh_entsize, LONG_HEX);
76da6bbe 6672
dda8d76d 6673 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
76da6bbe 6674
72de5009
AM
6675 printf (" %2u %3u %lu\n",
6676 section->sh_link,
6677 section->sh_info,
f7a99963
NC
6678 (unsigned long) section->sh_addralign);
6679 }
5477e8a0
L
6680
6681 if (do_section_details)
77115a4a 6682 {
dda8d76d 6683 printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags));
77115a4a
L
6684 if ((section->sh_flags & SHF_COMPRESSED) != 0)
6685 {
6686 /* Minimum section size is 12 bytes for 32-bit compression
6687 header + 12 bytes for compressed data header. */
6688 unsigned char buf[24];
d8024a91 6689
77115a4a 6690 assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
dda8d76d 6691 if (get_data (&buf, filedata, section->sh_offset, 1,
77115a4a
L
6692 sizeof (buf), _("compression header")))
6693 {
6694 Elf_Internal_Chdr chdr;
d8024a91 6695
ebdf1ebf 6696 (void) get_compression_header (&chdr, buf, sizeof (buf));
d8024a91 6697
77115a4a
L
6698 if (chdr.ch_type == ELFCOMPRESS_ZLIB)
6699 printf (" ZLIB, ");
6700 else
6701 printf (_(" [<unknown>: 0x%x], "),
6702 chdr.ch_type);
6703 print_vma (chdr.ch_size, LONG_HEX);
6704 printf (", %lu\n", (unsigned long) chdr.ch_addralign);
6705 }
6706 }
6707 }
252b5132
RH
6708 }
6709
5477e8a0 6710 if (!do_section_details)
3dbcc61d 6711 {
9fb71ee4
NC
6712 /* The ordering of the letters shown here matches the ordering of the
6713 corresponding SHF_xxx values, and hence the order in which these
6714 letters will be displayed to the user. */
6715 printf (_("Key to Flags:\n\
6716 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
6717 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
fd85a6a1 6718 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
dda8d76d
NC
6719 if (filedata->file_header.e_machine == EM_X86_64
6720 || filedata->file_header.e_machine == EM_L1OM
6721 || filedata->file_header.e_machine == EM_K1OM)
9fb71ee4 6722 printf (_("l (large), "));
dda8d76d 6723 else if (filedata->file_header.e_machine == EM_ARM)
f0728ee3 6724 printf (_("y (purecode), "));
dda8d76d 6725 else if (filedata->file_header.e_machine == EM_PPC)
83eef883 6726 printf (_("v (VLE), "));
9fb71ee4 6727 printf ("p (processor specific)\n");
0b4362b0 6728 }
d1133906 6729
32ec8896 6730 return TRUE;
252b5132
RH
6731}
6732
f5842774
L
6733static const char *
6734get_group_flags (unsigned int flags)
6735{
1449284b 6736 static char buff[128];
220453ec 6737
6d913794
NC
6738 if (flags == 0)
6739 return "";
6740 else if (flags == GRP_COMDAT)
6741 return "COMDAT ";
f5842774 6742
6d913794
NC
6743 snprintf (buff, 14, _("[0x%x: "), flags);
6744
6745 flags &= ~ GRP_COMDAT;
6746 if (flags & GRP_MASKOS)
6747 {
6748 strcat (buff, "<OS specific>");
6749 flags &= ~ GRP_MASKOS;
f5842774 6750 }
6d913794
NC
6751
6752 if (flags & GRP_MASKPROC)
6753 {
6754 strcat (buff, "<PROC specific>");
6755 flags &= ~ GRP_MASKPROC;
6756 }
6757
6758 if (flags)
6759 strcat (buff, "<unknown>");
6760
6761 strcat (buff, "]");
f5842774
L
6762 return buff;
6763}
6764
32ec8896 6765static bfd_boolean
dda8d76d 6766process_section_groups (Filedata * filedata)
f5842774 6767{
2cf0635d 6768 Elf_Internal_Shdr * section;
f5842774 6769 unsigned int i;
2cf0635d
NC
6770 struct group * group;
6771 Elf_Internal_Shdr * symtab_sec;
6772 Elf_Internal_Shdr * strtab_sec;
6773 Elf_Internal_Sym * symtab;
ba5cdace 6774 unsigned long num_syms;
2cf0635d 6775 char * strtab;
c256ffe7 6776 size_t strtab_size;
d1f5c6e3
L
6777
6778 /* Don't process section groups unless needed. */
6779 if (!do_unwind && !do_section_groups)
32ec8896 6780 return TRUE;
f5842774 6781
dda8d76d 6782 if (filedata->file_header.e_shnum == 0)
f5842774
L
6783 {
6784 if (do_section_groups)
82f2dbf7 6785 printf (_("\nThere are no sections to group in this file.\n"));
f5842774 6786
32ec8896 6787 return TRUE;
f5842774
L
6788 }
6789
dda8d76d 6790 if (filedata->section_headers == NULL)
f5842774
L
6791 {
6792 error (_("Section headers are not available!\n"));
fa1908fd 6793 /* PR 13622: This can happen with a corrupt ELF header. */
32ec8896 6794 return FALSE;
f5842774
L
6795 }
6796
dda8d76d 6797 section_headers_groups = (struct group **) calloc (filedata->file_header.e_shnum,
3f5e193b 6798 sizeof (struct group *));
e4b17d5c
L
6799
6800 if (section_headers_groups == NULL)
6801 {
8b73c356 6802 error (_("Out of memory reading %u section group headers\n"),
dda8d76d 6803 filedata->file_header.e_shnum);
32ec8896 6804 return FALSE;
e4b17d5c
L
6805 }
6806
f5842774 6807 /* Scan the sections for the group section. */
d1f5c6e3 6808 group_count = 0;
dda8d76d
NC
6809 for (i = 0, section = filedata->section_headers;
6810 i < filedata->file_header.e_shnum;
f5842774 6811 i++, section++)
e4b17d5c
L
6812 if (section->sh_type == SHT_GROUP)
6813 group_count++;
6814
d1f5c6e3
L
6815 if (group_count == 0)
6816 {
6817 if (do_section_groups)
6818 printf (_("\nThere are no section groups in this file.\n"));
6819
32ec8896 6820 return TRUE;
d1f5c6e3
L
6821 }
6822
3f5e193b 6823 section_groups = (struct group *) calloc (group_count, sizeof (struct group));
e4b17d5c
L
6824
6825 if (section_groups == NULL)
6826 {
8b73c356
NC
6827 error (_("Out of memory reading %lu groups\n"),
6828 (unsigned long) group_count);
32ec8896 6829 return FALSE;
e4b17d5c
L
6830 }
6831
d1f5c6e3
L
6832 symtab_sec = NULL;
6833 strtab_sec = NULL;
6834 symtab = NULL;
ba5cdace 6835 num_syms = 0;
d1f5c6e3 6836 strtab = NULL;
c256ffe7 6837 strtab_size = 0;
dda8d76d
NC
6838 for (i = 0, section = filedata->section_headers, group = section_groups;
6839 i < filedata->file_header.e_shnum;
e4b17d5c 6840 i++, section++)
f5842774
L
6841 {
6842 if (section->sh_type == SHT_GROUP)
6843 {
dda8d76d 6844 const char * name = printable_section_name (filedata, section);
74e1a04b 6845 const char * group_name;
2cf0635d
NC
6846 unsigned char * start;
6847 unsigned char * indices;
f5842774 6848 unsigned int entry, j, size;
2cf0635d
NC
6849 Elf_Internal_Shdr * sec;
6850 Elf_Internal_Sym * sym;
f5842774
L
6851
6852 /* Get the symbol table. */
dda8d76d
NC
6853 if (section->sh_link >= filedata->file_header.e_shnum
6854 || ((sec = filedata->section_headers + section->sh_link)->sh_type
c256ffe7 6855 != SHT_SYMTAB))
f5842774
L
6856 {
6857 error (_("Bad sh_link in group section `%s'\n"), name);
6858 continue;
6859 }
d1f5c6e3
L
6860
6861 if (symtab_sec != sec)
6862 {
6863 symtab_sec = sec;
6864 if (symtab)
6865 free (symtab);
dda8d76d 6866 symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms);
d1f5c6e3 6867 }
f5842774 6868
dd24e3da
NC
6869 if (symtab == NULL)
6870 {
6871 error (_("Corrupt header in group section `%s'\n"), name);
6872 continue;
6873 }
6874
ba5cdace
NC
6875 if (section->sh_info >= num_syms)
6876 {
6877 error (_("Bad sh_info in group section `%s'\n"), name);
6878 continue;
6879 }
6880
f5842774
L
6881 sym = symtab + section->sh_info;
6882
6883 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6884 {
4fbb74a6 6885 if (sym->st_shndx == 0
dda8d76d 6886 || sym->st_shndx >= filedata->file_header.e_shnum)
f5842774
L
6887 {
6888 error (_("Bad sh_info in group section `%s'\n"), name);
6889 continue;
6890 }
ba2685cc 6891
dda8d76d 6892 group_name = SECTION_NAME (filedata->section_headers + sym->st_shndx);
c256ffe7
JJ
6893 strtab_sec = NULL;
6894 if (strtab)
6895 free (strtab);
f5842774 6896 strtab = NULL;
c256ffe7 6897 strtab_size = 0;
f5842774
L
6898 }
6899 else
6900 {
6901 /* Get the string table. */
dda8d76d 6902 if (symtab_sec->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
6903 {
6904 strtab_sec = NULL;
6905 if (strtab)
6906 free (strtab);
6907 strtab = NULL;
6908 strtab_size = 0;
6909 }
6910 else if (strtab_sec
dda8d76d 6911 != (sec = filedata->section_headers + symtab_sec->sh_link))
d1f5c6e3
L
6912 {
6913 strtab_sec = sec;
6914 if (strtab)
6915 free (strtab);
071436c6 6916
dda8d76d 6917 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
071436c6
NC
6918 1, strtab_sec->sh_size,
6919 _("string table"));
c256ffe7 6920 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
d1f5c6e3 6921 }
c256ffe7 6922 group_name = sym->st_name < strtab_size
2b692964 6923 ? strtab + sym->st_name : _("<corrupt>");
f5842774
L
6924 }
6925
c9c1d674
EG
6926 /* PR 17531: file: loop. */
6927 if (section->sh_entsize > section->sh_size)
6928 {
6929 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
dda8d76d 6930 printable_section_name (filedata, section),
8066deb1
AM
6931 (unsigned long) section->sh_entsize,
6932 (unsigned long) section->sh_size);
61dd8e19 6933 continue;
c9c1d674
EG
6934 }
6935
dda8d76d 6936 start = (unsigned char *) get_data (NULL, filedata, section->sh_offset,
3f5e193b
NC
6937 1, section->sh_size,
6938 _("section data"));
59245841
NC
6939 if (start == NULL)
6940 continue;
f5842774
L
6941
6942 indices = start;
6943 size = (section->sh_size / section->sh_entsize) - 1;
6944 entry = byte_get (indices, 4);
6945 indices += 4;
e4b17d5c
L
6946
6947 if (do_section_groups)
6948 {
2b692964 6949 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
391cb864 6950 get_group_flags (entry), i, name, group_name, size);
ba2685cc 6951
e4b17d5c
L
6952 printf (_(" [Index] Name\n"));
6953 }
6954
6955 group->group_index = i;
6956
f5842774
L
6957 for (j = 0; j < size; j++)
6958 {
2cf0635d 6959 struct group_list * g;
e4b17d5c 6960
f5842774
L
6961 entry = byte_get (indices, 4);
6962 indices += 4;
6963
dda8d76d 6964 if (entry >= filedata->file_header.e_shnum)
391cb864 6965 {
57028622
NC
6966 static unsigned num_group_errors = 0;
6967
6968 if (num_group_errors ++ < 10)
6969 {
6970 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
dda8d76d 6971 entry, i, filedata->file_header.e_shnum - 1);
57028622 6972 if (num_group_errors == 10)
67ce483b 6973 warn (_("Further error messages about overlarge group section indices suppressed\n"));
57028622 6974 }
391cb864
L
6975 continue;
6976 }
391cb864 6977
4fbb74a6 6978 if (section_headers_groups [entry] != NULL)
e4b17d5c 6979 {
d1f5c6e3
L
6980 if (entry)
6981 {
57028622
NC
6982 static unsigned num_errs = 0;
6983
6984 if (num_errs ++ < 10)
6985 {
6986 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
6987 entry, i,
6988 section_headers_groups [entry]->group_index);
6989 if (num_errs == 10)
6990 warn (_("Further error messages about already contained group sections suppressed\n"));
6991 }
d1f5c6e3
L
6992 continue;
6993 }
6994 else
6995 {
6996 /* Intel C/C++ compiler may put section 0 in a
32ec8896 6997 section group. We just warn it the first time
d1f5c6e3 6998 and ignore it afterwards. */
32ec8896 6999 static bfd_boolean warned = FALSE;
d1f5c6e3
L
7000 if (!warned)
7001 {
7002 error (_("section 0 in group section [%5u]\n"),
4fbb74a6 7003 section_headers_groups [entry]->group_index);
32ec8896 7004 warned = TRUE;
d1f5c6e3
L
7005 }
7006 }
e4b17d5c
L
7007 }
7008
4fbb74a6 7009 section_headers_groups [entry] = group;
e4b17d5c
L
7010
7011 if (do_section_groups)
7012 {
dda8d76d
NC
7013 sec = filedata->section_headers + entry;
7014 printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec));
ba2685cc
AM
7015 }
7016
3f5e193b 7017 g = (struct group_list *) xmalloc (sizeof (struct group_list));
e4b17d5c
L
7018 g->section_index = entry;
7019 g->next = group->root;
7020 group->root = g;
f5842774
L
7021 }
7022
f5842774
L
7023 if (start)
7024 free (start);
e4b17d5c
L
7025
7026 group++;
f5842774
L
7027 }
7028 }
7029
d1f5c6e3
L
7030 if (symtab)
7031 free (symtab);
7032 if (strtab)
7033 free (strtab);
32ec8896 7034 return TRUE;
f5842774
L
7035}
7036
28f997cf
TG
7037/* Data used to display dynamic fixups. */
7038
7039struct ia64_vms_dynfixup
7040{
7041 bfd_vma needed_ident; /* Library ident number. */
7042 bfd_vma needed; /* Index in the dstrtab of the library name. */
7043 bfd_vma fixup_needed; /* Index of the library. */
7044 bfd_vma fixup_rela_cnt; /* Number of fixups. */
7045 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
7046};
7047
7048/* Data used to display dynamic relocations. */
7049
7050struct ia64_vms_dynimgrela
7051{
7052 bfd_vma img_rela_cnt; /* Number of relocations. */
7053 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
7054};
7055
7056/* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7057 library). */
7058
32ec8896 7059static bfd_boolean
dda8d76d
NC
7060dump_ia64_vms_dynamic_fixups (Filedata * filedata,
7061 struct ia64_vms_dynfixup * fixup,
7062 const char * strtab,
7063 unsigned int strtab_sz)
28f997cf 7064{
32ec8896 7065 Elf64_External_VMS_IMAGE_FIXUP * imfs;
28f997cf 7066 long i;
32ec8896 7067 const char * lib_name;
28f997cf 7068
dda8d76d 7069 imfs = get_data (NULL, filedata, dynamic_addr + fixup->fixup_rela_off,
28f997cf
TG
7070 1, fixup->fixup_rela_cnt * sizeof (*imfs),
7071 _("dynamic section image fixups"));
7072 if (!imfs)
32ec8896 7073 return FALSE;
28f997cf
TG
7074
7075 if (fixup->needed < strtab_sz)
7076 lib_name = strtab + fixup->needed;
7077 else
7078 {
32ec8896 7079 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7f01b0c6 7080 (unsigned long) fixup->needed);
28f997cf
TG
7081 lib_name = "???";
7082 }
7083 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7084 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
7085 printf
7086 (_("Seg Offset Type SymVec DataType\n"));
7087
7088 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
7089 {
7090 unsigned int type;
7091 const char *rtype;
7092
7093 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
7094 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
7095 type = BYTE_GET (imfs [i].type);
7096 rtype = elf_ia64_reloc_type (type);
7097 if (rtype == NULL)
7098 printf (" 0x%08x ", type);
7099 else
7100 printf (" %-32s ", rtype);
7101 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
7102 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
7103 }
7104
7105 free (imfs);
32ec8896 7106 return TRUE;
28f997cf
TG
7107}
7108
7109/* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7110
32ec8896 7111static bfd_boolean
dda8d76d 7112dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela)
28f997cf
TG
7113{
7114 Elf64_External_VMS_IMAGE_RELA *imrs;
7115 long i;
7116
dda8d76d 7117 imrs = get_data (NULL, filedata, dynamic_addr + imgrela->img_rela_off,
28f997cf 7118 1, imgrela->img_rela_cnt * sizeof (*imrs),
9cf03b7e 7119 _("dynamic section image relocations"));
28f997cf 7120 if (!imrs)
32ec8896 7121 return FALSE;
28f997cf
TG
7122
7123 printf (_("\nImage relocs\n"));
7124 printf
7125 (_("Seg Offset Type Addend Seg Sym Off\n"));
7126
7127 for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
7128 {
7129 unsigned int type;
7130 const char *rtype;
7131
7132 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
7133 printf ("%08" BFD_VMA_FMT "x ",
7134 (bfd_vma) BYTE_GET (imrs [i].rela_offset));
7135 type = BYTE_GET (imrs [i].type);
7136 rtype = elf_ia64_reloc_type (type);
7137 if (rtype == NULL)
7138 printf ("0x%08x ", type);
7139 else
7140 printf ("%-31s ", rtype);
7141 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
7142 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
7143 printf ("%08" BFD_VMA_FMT "x\n",
7144 (bfd_vma) BYTE_GET (imrs [i].sym_offset));
7145 }
7146
7147 free (imrs);
32ec8896 7148 return TRUE;
28f997cf
TG
7149}
7150
7151/* Display IA-64 OpenVMS dynamic relocations and fixups. */
7152
32ec8896 7153static bfd_boolean
dda8d76d 7154process_ia64_vms_dynamic_relocs (Filedata * filedata)
28f997cf
TG
7155{
7156 struct ia64_vms_dynfixup fixup;
7157 struct ia64_vms_dynimgrela imgrela;
7158 Elf_Internal_Dyn *entry;
28f997cf
TG
7159 bfd_vma strtab_off = 0;
7160 bfd_vma strtab_sz = 0;
7161 char *strtab = NULL;
32ec8896 7162 bfd_boolean res = TRUE;
28f997cf
TG
7163
7164 memset (&fixup, 0, sizeof (fixup));
7165 memset (&imgrela, 0, sizeof (imgrela));
7166
7167 /* Note: the order of the entries is specified by the OpenVMS specs. */
7168 for (entry = dynamic_section;
7169 entry < dynamic_section + dynamic_nent;
7170 entry++)
7171 {
7172 switch (entry->d_tag)
7173 {
7174 case DT_IA_64_VMS_STRTAB_OFFSET:
7175 strtab_off = entry->d_un.d_val;
7176 break;
7177 case DT_STRSZ:
7178 strtab_sz = entry->d_un.d_val;
7179 if (strtab == NULL)
dda8d76d 7180 strtab = get_data (NULL, filedata, dynamic_addr + strtab_off,
28f997cf
TG
7181 1, strtab_sz, _("dynamic string section"));
7182 break;
7183
7184 case DT_IA_64_VMS_NEEDED_IDENT:
7185 fixup.needed_ident = entry->d_un.d_val;
7186 break;
7187 case DT_NEEDED:
7188 fixup.needed = entry->d_un.d_val;
7189 break;
7190 case DT_IA_64_VMS_FIXUP_NEEDED:
7191 fixup.fixup_needed = entry->d_un.d_val;
7192 break;
7193 case DT_IA_64_VMS_FIXUP_RELA_CNT:
7194 fixup.fixup_rela_cnt = entry->d_un.d_val;
7195 break;
7196 case DT_IA_64_VMS_FIXUP_RELA_OFF:
7197 fixup.fixup_rela_off = entry->d_un.d_val;
dda8d76d 7198 if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz))
32ec8896 7199 res = FALSE;
28f997cf 7200 break;
28f997cf
TG
7201 case DT_IA_64_VMS_IMG_RELA_CNT:
7202 imgrela.img_rela_cnt = entry->d_un.d_val;
7203 break;
7204 case DT_IA_64_VMS_IMG_RELA_OFF:
7205 imgrela.img_rela_off = entry->d_un.d_val;
dda8d76d 7206 if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela))
32ec8896 7207 res = FALSE;
28f997cf
TG
7208 break;
7209
7210 default:
7211 break;
7212 }
7213 }
7214
7215 if (strtab != NULL)
7216 free (strtab);
7217
7218 return res;
7219}
7220
85b1c36d 7221static struct
566b0d53 7222{
2cf0635d 7223 const char * name;
566b0d53
L
7224 int reloc;
7225 int size;
7226 int rela;
32ec8896
NC
7227}
7228 dynamic_relocations [] =
566b0d53 7229{
32ec8896
NC
7230 { "REL", DT_REL, DT_RELSZ, FALSE },
7231 { "RELA", DT_RELA, DT_RELASZ, TRUE },
7232 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
566b0d53
L
7233};
7234
252b5132 7235/* Process the reloc section. */
18bd398b 7236
32ec8896 7237static bfd_boolean
dda8d76d 7238process_relocs (Filedata * filedata)
252b5132 7239{
b34976b6
AM
7240 unsigned long rel_size;
7241 unsigned long rel_offset;
252b5132 7242
252b5132 7243 if (!do_reloc)
32ec8896 7244 return TRUE;
252b5132
RH
7245
7246 if (do_using_dynamic)
7247 {
32ec8896 7248 int is_rela;
2cf0635d 7249 const char * name;
32ec8896 7250 bfd_boolean has_dynamic_reloc;
566b0d53 7251 unsigned int i;
0de14b54 7252
32ec8896 7253 has_dynamic_reloc = FALSE;
252b5132 7254
566b0d53 7255 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
252b5132 7256 {
566b0d53
L
7257 is_rela = dynamic_relocations [i].rela;
7258 name = dynamic_relocations [i].name;
7259 rel_size = dynamic_info [dynamic_relocations [i].size];
7260 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
103f02d3 7261
32ec8896
NC
7262 if (rel_size)
7263 has_dynamic_reloc = TRUE;
566b0d53
L
7264
7265 if (is_rela == UNKNOWN)
aa903cfb 7266 {
566b0d53
L
7267 if (dynamic_relocations [i].reloc == DT_JMPREL)
7268 switch (dynamic_info[DT_PLTREL])
7269 {
7270 case DT_REL:
7271 is_rela = FALSE;
7272 break;
7273 case DT_RELA:
7274 is_rela = TRUE;
7275 break;
7276 }
aa903cfb 7277 }
252b5132 7278
566b0d53
L
7279 if (rel_size)
7280 {
7281 printf
7282 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7283 name, rel_offset, rel_size);
252b5132 7284
dda8d76d
NC
7285 dump_relocations (filedata,
7286 offset_from_vma (filedata, rel_offset, rel_size),
d93f0186 7287 rel_size,
566b0d53 7288 dynamic_symbols, num_dynamic_syms,
bb4d2ac2 7289 dynamic_strings, dynamic_strings_length,
32ec8896 7290 is_rela, TRUE /* is_dynamic */);
566b0d53 7291 }
252b5132 7292 }
566b0d53 7293
dda8d76d
NC
7294 if (is_ia64_vms (filedata))
7295 if (process_ia64_vms_dynamic_relocs (filedata))
32ec8896 7296 has_dynamic_reloc = TRUE;
28f997cf 7297
566b0d53 7298 if (! has_dynamic_reloc)
252b5132
RH
7299 printf (_("\nThere are no dynamic relocations in this file.\n"));
7300 }
7301 else
7302 {
2cf0635d 7303 Elf_Internal_Shdr * section;
b34976b6 7304 unsigned long i;
32ec8896 7305 bfd_boolean found = FALSE;
252b5132 7306
dda8d76d
NC
7307 for (i = 0, section = filedata->section_headers;
7308 i < filedata->file_header.e_shnum;
b34976b6 7309 i++, section++)
252b5132
RH
7310 {
7311 if ( section->sh_type != SHT_RELA
7312 && section->sh_type != SHT_REL)
7313 continue;
7314
7315 rel_offset = section->sh_offset;
7316 rel_size = section->sh_size;
7317
7318 if (rel_size)
7319 {
2cf0635d 7320 Elf_Internal_Shdr * strsec;
b34976b6 7321 int is_rela;
d3a49aa8 7322 unsigned long num_rela;
103f02d3 7323
252b5132
RH
7324 printf (_("\nRelocation section "));
7325
dda8d76d 7326 if (filedata->string_table == NULL)
19936277 7327 printf ("%d", section->sh_name);
252b5132 7328 else
dda8d76d 7329 printf ("'%s'", printable_section_name (filedata, section));
252b5132 7330
d3a49aa8
AM
7331 num_rela = rel_size / section->sh_entsize;
7332 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7333 " at offset 0x%lx contains %lu entries:\n",
7334 num_rela),
7335 rel_offset, num_rela);
252b5132 7336
d79b3d50
NC
7337 is_rela = section->sh_type == SHT_RELA;
7338
4fbb74a6 7339 if (section->sh_link != 0
dda8d76d 7340 && section->sh_link < filedata->file_header.e_shnum)
af3fc3bc 7341 {
2cf0635d
NC
7342 Elf_Internal_Shdr * symsec;
7343 Elf_Internal_Sym * symtab;
d79b3d50 7344 unsigned long nsyms;
c256ffe7 7345 unsigned long strtablen = 0;
2cf0635d 7346 char * strtab = NULL;
57346661 7347
dda8d76d 7348 symsec = filedata->section_headers + section->sh_link;
08d8fa11
JJ
7349 if (symsec->sh_type != SHT_SYMTAB
7350 && symsec->sh_type != SHT_DYNSYM)
7351 continue;
7352
dda8d76d 7353 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
252b5132 7354
af3fc3bc
AM
7355 if (symtab == NULL)
7356 continue;
252b5132 7357
4fbb74a6 7358 if (symsec->sh_link != 0
dda8d76d 7359 && symsec->sh_link < filedata->file_header.e_shnum)
c256ffe7 7360 {
dda8d76d 7361 strsec = filedata->section_headers + symsec->sh_link;
103f02d3 7362
dda8d76d 7363 strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
071436c6
NC
7364 1, strsec->sh_size,
7365 _("string table"));
c256ffe7
JJ
7366 strtablen = strtab == NULL ? 0 : strsec->sh_size;
7367 }
252b5132 7368
dda8d76d 7369 dump_relocations (filedata, rel_offset, rel_size,
bb4d2ac2
L
7370 symtab, nsyms, strtab, strtablen,
7371 is_rela,
7372 symsec->sh_type == SHT_DYNSYM);
d79b3d50
NC
7373 if (strtab)
7374 free (strtab);
7375 free (symtab);
7376 }
7377 else
dda8d76d 7378 dump_relocations (filedata, rel_offset, rel_size,
32ec8896
NC
7379 NULL, 0, NULL, 0, is_rela,
7380 FALSE /* is_dynamic */);
252b5132 7381
32ec8896 7382 found = TRUE;
252b5132
RH
7383 }
7384 }
7385
7386 if (! found)
45ac8f4f
NC
7387 {
7388 /* Users sometimes forget the -D option, so try to be helpful. */
7389 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
7390 {
7391 if (dynamic_info [dynamic_relocations [i].size])
7392 {
7393 printf (_("\nThere are no static relocations in this file."));
7394 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7395
7396 break;
7397 }
7398 }
7399 if (i == ARRAY_SIZE (dynamic_relocations))
7400 printf (_("\nThere are no relocations in this file.\n"));
7401 }
252b5132
RH
7402 }
7403
32ec8896 7404 return TRUE;
252b5132
RH
7405}
7406
4d6ed7c8
NC
7407/* An absolute address consists of a section and an offset. If the
7408 section is NULL, the offset itself is the address, otherwise, the
7409 address equals to LOAD_ADDRESS(section) + offset. */
7410
7411struct absaddr
948f632f
DA
7412{
7413 unsigned short section;
7414 bfd_vma offset;
7415};
4d6ed7c8 7416
1949de15
L
7417#define ABSADDR(a) \
7418 ((a).section \
dda8d76d 7419 ? filedata->section_headers [(a).section].sh_addr + (a).offset \
1949de15
L
7420 : (a).offset)
7421
948f632f
DA
7422/* Find the nearest symbol at or below ADDR. Returns the symbol
7423 name, if found, and the offset from the symbol to ADDR. */
4d6ed7c8 7424
4d6ed7c8 7425static void
dda8d76d
NC
7426find_symbol_for_address (Filedata * filedata,
7427 Elf_Internal_Sym * symtab,
7428 unsigned long nsyms,
7429 const char * strtab,
7430 unsigned long strtab_size,
7431 struct absaddr addr,
7432 const char ** symname,
7433 bfd_vma * offset)
4d6ed7c8 7434{
d3ba0551 7435 bfd_vma dist = 0x100000;
2cf0635d 7436 Elf_Internal_Sym * sym;
948f632f
DA
7437 Elf_Internal_Sym * beg;
7438 Elf_Internal_Sym * end;
2cf0635d 7439 Elf_Internal_Sym * best = NULL;
4d6ed7c8 7440
0b6ae522 7441 REMOVE_ARCH_BITS (addr.offset);
948f632f
DA
7442 beg = symtab;
7443 end = symtab + nsyms;
0b6ae522 7444
948f632f 7445 while (beg < end)
4d6ed7c8 7446 {
948f632f
DA
7447 bfd_vma value;
7448
7449 sym = beg + (end - beg) / 2;
0b6ae522 7450
948f632f 7451 value = sym->st_value;
0b6ae522
DJ
7452 REMOVE_ARCH_BITS (value);
7453
948f632f 7454 if (sym->st_name != 0
4d6ed7c8 7455 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
0b6ae522
DJ
7456 && addr.offset >= value
7457 && addr.offset - value < dist)
4d6ed7c8
NC
7458 {
7459 best = sym;
0b6ae522 7460 dist = addr.offset - value;
4d6ed7c8
NC
7461 if (!dist)
7462 break;
7463 }
948f632f
DA
7464
7465 if (addr.offset < value)
7466 end = sym;
7467 else
7468 beg = sym + 1;
4d6ed7c8 7469 }
1b31d05e 7470
4d6ed7c8
NC
7471 if (best)
7472 {
57346661 7473 *symname = (best->st_name >= strtab_size
2b692964 7474 ? _("<corrupt>") : strtab + best->st_name);
4d6ed7c8
NC
7475 *offset = dist;
7476 return;
7477 }
1b31d05e 7478
4d6ed7c8
NC
7479 *symname = NULL;
7480 *offset = addr.offset;
7481}
7482
32ec8896 7483static /* signed */ int
948f632f
DA
7484symcmp (const void *p, const void *q)
7485{
7486 Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
7487 Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
7488
7489 return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
7490}
7491
7492/* Process the unwind section. */
7493
7494#include "unwind-ia64.h"
7495
7496struct ia64_unw_table_entry
7497{
7498 struct absaddr start;
7499 struct absaddr end;
7500 struct absaddr info;
7501};
7502
7503struct ia64_unw_aux_info
7504{
32ec8896
NC
7505 struct ia64_unw_table_entry * table; /* Unwind table. */
7506 unsigned long table_len; /* Length of unwind table. */
7507 unsigned char * info; /* Unwind info. */
7508 unsigned long info_size; /* Size of unwind info. */
7509 bfd_vma info_addr; /* Starting address of unwind info. */
7510 bfd_vma seg_base; /* Starting address of segment. */
7511 Elf_Internal_Sym * symtab; /* The symbol table. */
7512 unsigned long nsyms; /* Number of symbols. */
7513 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
7514 unsigned long nfuns; /* Number of entries in funtab. */
7515 char * strtab; /* The string table. */
7516 unsigned long strtab_size; /* Size of string table. */
948f632f
DA
7517};
7518
32ec8896 7519static bfd_boolean
dda8d76d 7520dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux)
4d6ed7c8 7521{
2cf0635d 7522 struct ia64_unw_table_entry * tp;
948f632f 7523 unsigned long j, nfuns;
4d6ed7c8 7524 int in_body;
32ec8896 7525 bfd_boolean res = TRUE;
7036c0e1 7526
948f632f
DA
7527 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
7528 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
7529 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
7530 aux->funtab[nfuns++] = aux->symtab[j];
7531 aux->nfuns = nfuns;
7532 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
7533
4d6ed7c8
NC
7534 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
7535 {
7536 bfd_vma stamp;
7537 bfd_vma offset;
2cf0635d
NC
7538 const unsigned char * dp;
7539 const unsigned char * head;
53774b7e 7540 const unsigned char * end;
2cf0635d 7541 const char * procname;
4d6ed7c8 7542
dda8d76d 7543 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
57346661 7544 aux->strtab_size, tp->start, &procname, &offset);
4d6ed7c8
NC
7545
7546 fputs ("\n<", stdout);
7547
7548 if (procname)
7549 {
7550 fputs (procname, stdout);
7551
7552 if (offset)
7553 printf ("+%lx", (unsigned long) offset);
7554 }
7555
7556 fputs (">: [", stdout);
7557 print_vma (tp->start.offset, PREFIX_HEX);
7558 fputc ('-', stdout);
7559 print_vma (tp->end.offset, PREFIX_HEX);
86f55779 7560 printf ("], info at +0x%lx\n",
4d6ed7c8
NC
7561 (unsigned long) (tp->info.offset - aux->seg_base));
7562
53774b7e
NC
7563 /* PR 17531: file: 86232b32. */
7564 if (aux->info == NULL)
7565 continue;
7566
7567 /* PR 17531: file: 0997b4d1. */
7568 if ((ABSADDR (tp->info) - aux->info_addr) >= aux->info_size)
7569 {
7570 warn (_("Invalid offset %lx in table entry %ld\n"),
7571 (long) tp->info.offset, (long) (tp - aux->table));
32ec8896 7572 res = FALSE;
53774b7e
NC
7573 continue;
7574 }
7575
1949de15 7576 head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
a4a00738 7577 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
4d6ed7c8 7578
86f55779 7579 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4d6ed7c8
NC
7580 (unsigned) UNW_VER (stamp),
7581 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
7582 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
7583 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
89fac5e3 7584 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
4d6ed7c8
NC
7585
7586 if (UNW_VER (stamp) != 1)
7587 {
2b692964 7588 printf (_("\tUnknown version.\n"));
4d6ed7c8
NC
7589 continue;
7590 }
7591
7592 in_body = 0;
53774b7e
NC
7593 end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
7594 /* PR 17531: file: 16ceda89. */
7595 if (end > aux->info + aux->info_size)
7596 end = aux->info + aux->info_size;
7597 for (dp = head + 8; dp < end;)
b4477bc8 7598 dp = unw_decode (dp, in_body, & in_body, end);
4d6ed7c8 7599 }
948f632f
DA
7600
7601 free (aux->funtab);
32ec8896
NC
7602
7603 return res;
4d6ed7c8
NC
7604}
7605
53774b7e 7606static bfd_boolean
dda8d76d
NC
7607slurp_ia64_unwind_table (Filedata * filedata,
7608 struct ia64_unw_aux_info * aux,
7609 Elf_Internal_Shdr * sec)
4d6ed7c8 7610{
89fac5e3 7611 unsigned long size, nrelas, i;
2cf0635d
NC
7612 Elf_Internal_Phdr * seg;
7613 struct ia64_unw_table_entry * tep;
7614 Elf_Internal_Shdr * relsec;
7615 Elf_Internal_Rela * rela;
7616 Elf_Internal_Rela * rp;
7617 unsigned char * table;
7618 unsigned char * tp;
7619 Elf_Internal_Sym * sym;
7620 const char * relname;
4d6ed7c8 7621
53774b7e
NC
7622 aux->table_len = 0;
7623
4d6ed7c8
NC
7624 /* First, find the starting address of the segment that includes
7625 this section: */
7626
dda8d76d 7627 if (filedata->file_header.e_phnum)
4d6ed7c8 7628 {
dda8d76d 7629 if (! get_program_headers (filedata))
53774b7e 7630 return FALSE;
4d6ed7c8 7631
dda8d76d
NC
7632 for (seg = filedata->program_headers;
7633 seg < filedata->program_headers + filedata->file_header.e_phnum;
d93f0186 7634 ++seg)
4d6ed7c8
NC
7635 {
7636 if (seg->p_type != PT_LOAD)
7637 continue;
7638
7639 if (sec->sh_addr >= seg->p_vaddr
7640 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
7641 {
7642 aux->seg_base = seg->p_vaddr;
7643 break;
7644 }
7645 }
4d6ed7c8
NC
7646 }
7647
7648 /* Second, build the unwind table from the contents of the unwind section: */
7649 size = sec->sh_size;
dda8d76d 7650 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
3f5e193b 7651 _("unwind table"));
a6e9f9df 7652 if (!table)
53774b7e 7653 return FALSE;
4d6ed7c8 7654
53774b7e 7655 aux->table_len = size / (3 * eh_addr_size);
3f5e193b 7656 aux->table = (struct ia64_unw_table_entry *)
53774b7e 7657 xcmalloc (aux->table_len, sizeof (aux->table[0]));
89fac5e3 7658 tep = aux->table;
53774b7e
NC
7659
7660 for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
4d6ed7c8
NC
7661 {
7662 tep->start.section = SHN_UNDEF;
7663 tep->end.section = SHN_UNDEF;
7664 tep->info.section = SHN_UNDEF;
c6a0c689
AM
7665 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7666 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7667 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
4d6ed7c8
NC
7668 tep->start.offset += aux->seg_base;
7669 tep->end.offset += aux->seg_base;
7670 tep->info.offset += aux->seg_base;
7671 }
7672 free (table);
7673
41e92641 7674 /* Third, apply any relocations to the unwind table: */
dda8d76d
NC
7675 for (relsec = filedata->section_headers;
7676 relsec < filedata->section_headers + filedata->file_header.e_shnum;
4d6ed7c8
NC
7677 ++relsec)
7678 {
7679 if (relsec->sh_type != SHT_RELA
dda8d76d
NC
7680 || relsec->sh_info >= filedata->file_header.e_shnum
7681 || filedata->section_headers + relsec->sh_info != sec)
4d6ed7c8
NC
7682 continue;
7683
dda8d76d 7684 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
4d6ed7c8 7685 & rela, & nrelas))
53774b7e
NC
7686 {
7687 free (aux->table);
7688 aux->table = NULL;
7689 aux->table_len = 0;
7690 return FALSE;
7691 }
4d6ed7c8
NC
7692
7693 for (rp = rela; rp < rela + nrelas; ++rp)
7694 {
4770fb94 7695 unsigned int sym_ndx;
726bd37d
AM
7696 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
7697 relname = elf_ia64_reloc_type (r_type);
4d6ed7c8 7698
82b1b41b
NC
7699 /* PR 17531: file: 9fa67536. */
7700 if (relname == NULL)
7701 {
726bd37d 7702 warn (_("Skipping unknown relocation type: %u\n"), r_type);
82b1b41b
NC
7703 continue;
7704 }
948f632f 7705
0112cd26 7706 if (! const_strneq (relname, "R_IA64_SEGREL"))
4d6ed7c8 7707 {
82b1b41b 7708 warn (_("Skipping unexpected relocation type: %s\n"), relname);
4d6ed7c8
NC
7709 continue;
7710 }
7711
89fac5e3 7712 i = rp->r_offset / (3 * eh_addr_size);
4d6ed7c8 7713
53774b7e
NC
7714 /* PR 17531: file: 5bc8d9bf. */
7715 if (i >= aux->table_len)
7716 {
7717 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
7718 continue;
7719 }
7720
4770fb94
AM
7721 sym_ndx = get_reloc_symindex (rp->r_info);
7722 if (sym_ndx >= aux->nsyms)
7723 {
7724 warn (_("Skipping reloc with invalid symbol index: %u\n"),
7725 sym_ndx);
7726 continue;
7727 }
7728 sym = aux->symtab + sym_ndx;
7729
53774b7e 7730 switch (rp->r_offset / eh_addr_size % 3)
4d6ed7c8
NC
7731 {
7732 case 0:
7733 aux->table[i].start.section = sym->st_shndx;
e466bc6e 7734 aux->table[i].start.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
7735 break;
7736 case 1:
7737 aux->table[i].end.section = sym->st_shndx;
e466bc6e 7738 aux->table[i].end.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
7739 break;
7740 case 2:
7741 aux->table[i].info.section = sym->st_shndx;
e466bc6e 7742 aux->table[i].info.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
7743 break;
7744 default:
7745 break;
7746 }
7747 }
7748
7749 free (rela);
7750 }
7751
53774b7e 7752 return TRUE;
4d6ed7c8
NC
7753}
7754
32ec8896 7755static bfd_boolean
dda8d76d 7756ia64_process_unwind (Filedata * filedata)
4d6ed7c8 7757{
2cf0635d
NC
7758 Elf_Internal_Shdr * sec;
7759 Elf_Internal_Shdr * unwsec = NULL;
7760 Elf_Internal_Shdr * strsec;
89fac5e3 7761 unsigned long i, unwcount = 0, unwstart = 0;
57346661 7762 struct ia64_unw_aux_info aux;
32ec8896 7763 bfd_boolean res = TRUE;
f1467e33 7764
4d6ed7c8
NC
7765 memset (& aux, 0, sizeof (aux));
7766
dda8d76d 7767 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
4d6ed7c8 7768 {
c256ffe7 7769 if (sec->sh_type == SHT_SYMTAB
dda8d76d 7770 && sec->sh_link < filedata->file_header.e_shnum)
4d6ed7c8 7771 {
dda8d76d 7772 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
4d6ed7c8 7773
dda8d76d 7774 strsec = filedata->section_headers + sec->sh_link;
4082ef84
NC
7775 if (aux.strtab != NULL)
7776 {
7777 error (_("Multiple auxillary string tables encountered\n"));
7778 free (aux.strtab);
32ec8896 7779 res = FALSE;
4082ef84 7780 }
dda8d76d 7781 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
3f5e193b
NC
7782 1, strsec->sh_size,
7783 _("string table"));
c256ffe7 7784 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
4d6ed7c8
NC
7785 }
7786 else if (sec->sh_type == SHT_IA_64_UNWIND)
579f31ac
JJ
7787 unwcount++;
7788 }
7789
7790 if (!unwcount)
7791 printf (_("\nThere are no unwind sections in this file.\n"));
7792
7793 while (unwcount-- > 0)
7794 {
2cf0635d 7795 char * suffix;
579f31ac
JJ
7796 size_t len, len2;
7797
dda8d76d
NC
7798 for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL;
7799 i < filedata->file_header.e_shnum; ++i, ++sec)
579f31ac
JJ
7800 if (sec->sh_type == SHT_IA_64_UNWIND)
7801 {
7802 unwsec = sec;
7803 break;
7804 }
4082ef84
NC
7805 /* We have already counted the number of SHT_IA64_UNWIND
7806 sections so the loop above should never fail. */
7807 assert (unwsec != NULL);
579f31ac
JJ
7808
7809 unwstart = i + 1;
7810 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
7811
e4b17d5c
L
7812 if ((unwsec->sh_flags & SHF_GROUP) != 0)
7813 {
7814 /* We need to find which section group it is in. */
4082ef84 7815 struct group_list * g;
e4b17d5c 7816
4082ef84
NC
7817 if (section_headers_groups == NULL
7818 || section_headers_groups [i] == NULL)
dda8d76d 7819 i = filedata->file_header.e_shnum;
4082ef84 7820 else
e4b17d5c 7821 {
4082ef84 7822 g = section_headers_groups [i]->root;
18bd398b 7823
4082ef84
NC
7824 for (; g != NULL; g = g->next)
7825 {
dda8d76d 7826 sec = filedata->section_headers + g->section_index;
e4b17d5c 7827
4082ef84
NC
7828 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
7829 break;
7830 }
7831
7832 if (g == NULL)
dda8d76d 7833 i = filedata->file_header.e_shnum;
4082ef84 7834 }
e4b17d5c 7835 }
18bd398b 7836 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
579f31ac 7837 {
18bd398b 7838 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
579f31ac
JJ
7839 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
7840 suffix = SECTION_NAME (unwsec) + len;
dda8d76d 7841 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
579f31ac 7842 ++i, ++sec)
18bd398b
NC
7843 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
7844 && streq (SECTION_NAME (sec) + len2, suffix))
579f31ac
JJ
7845 break;
7846 }
7847 else
7848 {
7849 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
18bd398b 7850 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
579f31ac
JJ
7851 len = sizeof (ELF_STRING_ia64_unwind) - 1;
7852 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
7853 suffix = "";
18bd398b 7854 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
579f31ac 7855 suffix = SECTION_NAME (unwsec) + len;
dda8d76d 7856 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
579f31ac 7857 ++i, ++sec)
18bd398b
NC
7858 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
7859 && streq (SECTION_NAME (sec) + len2, suffix))
579f31ac
JJ
7860 break;
7861 }
7862
dda8d76d 7863 if (i == filedata->file_header.e_shnum)
579f31ac
JJ
7864 {
7865 printf (_("\nCould not find unwind info section for "));
7866
dda8d76d 7867 if (filedata->string_table == NULL)
579f31ac
JJ
7868 printf ("%d", unwsec->sh_name);
7869 else
dda8d76d 7870 printf ("'%s'", printable_section_name (filedata, unwsec));
579f31ac
JJ
7871 }
7872 else
4d6ed7c8 7873 {
4d6ed7c8 7874 aux.info_addr = sec->sh_addr;
dda8d76d 7875 aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1,
4082ef84
NC
7876 sec->sh_size,
7877 _("unwind info"));
59245841 7878 aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
4d6ed7c8 7879
579f31ac 7880 printf (_("\nUnwind section "));
4d6ed7c8 7881
dda8d76d 7882 if (filedata->string_table == NULL)
579f31ac
JJ
7883 printf ("%d", unwsec->sh_name);
7884 else
dda8d76d 7885 printf ("'%s'", printable_section_name (filedata, unwsec));
4d6ed7c8 7886
579f31ac 7887 printf (_(" at offset 0x%lx contains %lu entries:\n"),
e59b4dfb 7888 (unsigned long) unwsec->sh_offset,
89fac5e3 7889 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
4d6ed7c8 7890
dda8d76d 7891 if (slurp_ia64_unwind_table (filedata, & aux, unwsec)
53774b7e 7892 && aux.table_len > 0)
dda8d76d 7893 dump_ia64_unwind (filedata, & aux);
579f31ac
JJ
7894
7895 if (aux.table)
7896 free ((char *) aux.table);
7897 if (aux.info)
7898 free ((char *) aux.info);
7899 aux.table = NULL;
7900 aux.info = NULL;
7901 }
4d6ed7c8 7902 }
4d6ed7c8 7903
4d6ed7c8
NC
7904 if (aux.symtab)
7905 free (aux.symtab);
7906 if (aux.strtab)
7907 free ((char *) aux.strtab);
32ec8896
NC
7908
7909 return res;
4d6ed7c8
NC
7910}
7911
3f5e193b 7912struct hppa_unw_table_entry
32ec8896
NC
7913{
7914 struct absaddr start;
7915 struct absaddr end;
7916 unsigned int Cannot_unwind:1; /* 0 */
7917 unsigned int Millicode:1; /* 1 */
7918 unsigned int Millicode_save_sr0:1; /* 2 */
7919 unsigned int Region_description:2; /* 3..4 */
7920 unsigned int reserved1:1; /* 5 */
7921 unsigned int Entry_SR:1; /* 6 */
7922 unsigned int Entry_FR:4; /* Number saved 7..10 */
7923 unsigned int Entry_GR:5; /* Number saved 11..15 */
7924 unsigned int Args_stored:1; /* 16 */
7925 unsigned int Variable_Frame:1; /* 17 */
7926 unsigned int Separate_Package_Body:1; /* 18 */
7927 unsigned int Frame_Extension_Millicode:1; /* 19 */
7928 unsigned int Stack_Overflow_Check:1; /* 20 */
7929 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
7930 unsigned int Ada_Region:1; /* 22 */
7931 unsigned int cxx_info:1; /* 23 */
7932 unsigned int cxx_try_catch:1; /* 24 */
7933 unsigned int sched_entry_seq:1; /* 25 */
7934 unsigned int reserved2:1; /* 26 */
7935 unsigned int Save_SP:1; /* 27 */
7936 unsigned int Save_RP:1; /* 28 */
7937 unsigned int Save_MRP_in_frame:1; /* 29 */
7938 unsigned int extn_ptr_defined:1; /* 30 */
7939 unsigned int Cleanup_defined:1; /* 31 */
7940
7941 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
7942 unsigned int HP_UX_interrupt_marker:1; /* 1 */
7943 unsigned int Large_frame:1; /* 2 */
7944 unsigned int Pseudo_SP_Set:1; /* 3 */
7945 unsigned int reserved4:1; /* 4 */
7946 unsigned int Total_frame_size:27; /* 5..31 */
7947};
3f5e193b 7948
57346661 7949struct hppa_unw_aux_info
948f632f 7950{
32ec8896
NC
7951 struct hppa_unw_table_entry * table; /* Unwind table. */
7952 unsigned long table_len; /* Length of unwind table. */
7953 bfd_vma seg_base; /* Starting address of segment. */
7954 Elf_Internal_Sym * symtab; /* The symbol table. */
7955 unsigned long nsyms; /* Number of symbols. */
7956 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
7957 unsigned long nfuns; /* Number of entries in funtab. */
7958 char * strtab; /* The string table. */
7959 unsigned long strtab_size; /* Size of string table. */
948f632f 7960};
57346661 7961
32ec8896 7962static bfd_boolean
dda8d76d 7963dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux)
57346661 7964{
2cf0635d 7965 struct hppa_unw_table_entry * tp;
948f632f 7966 unsigned long j, nfuns;
32ec8896 7967 bfd_boolean res = TRUE;
948f632f
DA
7968
7969 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
7970 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
7971 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
7972 aux->funtab[nfuns++] = aux->symtab[j];
7973 aux->nfuns = nfuns;
7974 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
57346661 7975
57346661
AM
7976 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
7977 {
7978 bfd_vma offset;
2cf0635d 7979 const char * procname;
57346661 7980
dda8d76d 7981 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
57346661
AM
7982 aux->strtab_size, tp->start, &procname,
7983 &offset);
7984
7985 fputs ("\n<", stdout);
7986
7987 if (procname)
7988 {
7989 fputs (procname, stdout);
7990
7991 if (offset)
7992 printf ("+%lx", (unsigned long) offset);
7993 }
7994
7995 fputs (">: [", stdout);
7996 print_vma (tp->start.offset, PREFIX_HEX);
7997 fputc ('-', stdout);
7998 print_vma (tp->end.offset, PREFIX_HEX);
7999 printf ("]\n\t");
8000
18bd398b
NC
8001#define PF(_m) if (tp->_m) printf (#_m " ");
8002#define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
57346661
AM
8003 PF(Cannot_unwind);
8004 PF(Millicode);
8005 PF(Millicode_save_sr0);
18bd398b 8006 /* PV(Region_description); */
57346661
AM
8007 PF(Entry_SR);
8008 PV(Entry_FR);
8009 PV(Entry_GR);
8010 PF(Args_stored);
8011 PF(Variable_Frame);
8012 PF(Separate_Package_Body);
8013 PF(Frame_Extension_Millicode);
8014 PF(Stack_Overflow_Check);
8015 PF(Two_Instruction_SP_Increment);
8016 PF(Ada_Region);
8017 PF(cxx_info);
8018 PF(cxx_try_catch);
8019 PF(sched_entry_seq);
8020 PF(Save_SP);
8021 PF(Save_RP);
8022 PF(Save_MRP_in_frame);
8023 PF(extn_ptr_defined);
8024 PF(Cleanup_defined);
8025 PF(MPE_XL_interrupt_marker);
8026 PF(HP_UX_interrupt_marker);
8027 PF(Large_frame);
8028 PF(Pseudo_SP_Set);
8029 PV(Total_frame_size);
8030#undef PF
8031#undef PV
8032 }
8033
18bd398b 8034 printf ("\n");
948f632f
DA
8035
8036 free (aux->funtab);
32ec8896
NC
8037
8038 return res;
57346661
AM
8039}
8040
32ec8896 8041static bfd_boolean
dda8d76d
NC
8042slurp_hppa_unwind_table (Filedata * filedata,
8043 struct hppa_unw_aux_info * aux,
8044 Elf_Internal_Shdr * sec)
57346661 8045{
1c0751b2 8046 unsigned long size, unw_ent_size, nentries, nrelas, i;
2cf0635d
NC
8047 Elf_Internal_Phdr * seg;
8048 struct hppa_unw_table_entry * tep;
8049 Elf_Internal_Shdr * relsec;
8050 Elf_Internal_Rela * rela;
8051 Elf_Internal_Rela * rp;
8052 unsigned char * table;
8053 unsigned char * tp;
8054 Elf_Internal_Sym * sym;
8055 const char * relname;
57346661 8056
57346661
AM
8057 /* First, find the starting address of the segment that includes
8058 this section. */
dda8d76d 8059 if (filedata->file_header.e_phnum)
57346661 8060 {
dda8d76d 8061 if (! get_program_headers (filedata))
32ec8896 8062 return FALSE;
57346661 8063
dda8d76d
NC
8064 for (seg = filedata->program_headers;
8065 seg < filedata->program_headers + filedata->file_header.e_phnum;
57346661
AM
8066 ++seg)
8067 {
8068 if (seg->p_type != PT_LOAD)
8069 continue;
8070
8071 if (sec->sh_addr >= seg->p_vaddr
8072 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
8073 {
8074 aux->seg_base = seg->p_vaddr;
8075 break;
8076 }
8077 }
8078 }
8079
8080 /* Second, build the unwind table from the contents of the unwind
8081 section. */
8082 size = sec->sh_size;
dda8d76d 8083 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
3f5e193b 8084 _("unwind table"));
57346661 8085 if (!table)
32ec8896 8086 return FALSE;
57346661 8087
1c0751b2
DA
8088 unw_ent_size = 16;
8089 nentries = size / unw_ent_size;
8090 size = unw_ent_size * nentries;
57346661 8091
3f5e193b
NC
8092 tep = aux->table = (struct hppa_unw_table_entry *)
8093 xcmalloc (nentries, sizeof (aux->table[0]));
57346661 8094
1c0751b2 8095 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
57346661
AM
8096 {
8097 unsigned int tmp1, tmp2;
8098
8099 tep->start.section = SHN_UNDEF;
8100 tep->end.section = SHN_UNDEF;
8101
1c0751b2
DA
8102 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
8103 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
8104 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
8105 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
8106
8107 tep->start.offset += aux->seg_base;
8108 tep->end.offset += aux->seg_base;
57346661
AM
8109
8110 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
8111 tep->Millicode = (tmp1 >> 30) & 0x1;
8112 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
8113 tep->Region_description = (tmp1 >> 27) & 0x3;
8114 tep->reserved1 = (tmp1 >> 26) & 0x1;
8115 tep->Entry_SR = (tmp1 >> 25) & 0x1;
8116 tep->Entry_FR = (tmp1 >> 21) & 0xf;
8117 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
8118 tep->Args_stored = (tmp1 >> 15) & 0x1;
8119 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
8120 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
8121 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
8122 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
8123 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
8124 tep->Ada_Region = (tmp1 >> 9) & 0x1;
8125 tep->cxx_info = (tmp1 >> 8) & 0x1;
8126 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
8127 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
8128 tep->reserved2 = (tmp1 >> 5) & 0x1;
8129 tep->Save_SP = (tmp1 >> 4) & 0x1;
8130 tep->Save_RP = (tmp1 >> 3) & 0x1;
8131 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
8132 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
8133 tep->Cleanup_defined = tmp1 & 0x1;
8134
8135 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
8136 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
8137 tep->Large_frame = (tmp2 >> 29) & 0x1;
8138 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
8139 tep->reserved4 = (tmp2 >> 27) & 0x1;
8140 tep->Total_frame_size = tmp2 & 0x7ffffff;
57346661
AM
8141 }
8142 free (table);
8143
8144 /* Third, apply any relocations to the unwind table. */
dda8d76d
NC
8145 for (relsec = filedata->section_headers;
8146 relsec < filedata->section_headers + filedata->file_header.e_shnum;
57346661
AM
8147 ++relsec)
8148 {
8149 if (relsec->sh_type != SHT_RELA
dda8d76d
NC
8150 || relsec->sh_info >= filedata->file_header.e_shnum
8151 || filedata->section_headers + relsec->sh_info != sec)
57346661
AM
8152 continue;
8153
dda8d76d 8154 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
57346661 8155 & rela, & nrelas))
32ec8896 8156 return FALSE;
57346661
AM
8157
8158 for (rp = rela; rp < rela + nrelas; ++rp)
8159 {
4770fb94 8160 unsigned int sym_ndx;
726bd37d
AM
8161 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
8162 relname = elf_hppa_reloc_type (r_type);
57346661 8163
726bd37d
AM
8164 if (relname == NULL)
8165 {
8166 warn (_("Skipping unknown relocation type: %u\n"), r_type);
8167 continue;
8168 }
8169
57346661 8170 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
0112cd26 8171 if (! const_strneq (relname, "R_PARISC_SEGREL"))
57346661 8172 {
726bd37d 8173 warn (_("Skipping unexpected relocation type: %s\n"), relname);
57346661
AM
8174 continue;
8175 }
8176
8177 i = rp->r_offset / unw_ent_size;
726bd37d
AM
8178 if (i >= aux->table_len)
8179 {
8180 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
8181 continue;
8182 }
57346661 8183
4770fb94
AM
8184 sym_ndx = get_reloc_symindex (rp->r_info);
8185 if (sym_ndx >= aux->nsyms)
8186 {
8187 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8188 sym_ndx);
8189 continue;
8190 }
8191 sym = aux->symtab + sym_ndx;
8192
43f6cd05 8193 switch ((rp->r_offset % unw_ent_size) / 4)
57346661
AM
8194 {
8195 case 0:
8196 aux->table[i].start.section = sym->st_shndx;
1e456d54 8197 aux->table[i].start.offset = sym->st_value + rp->r_addend;
57346661
AM
8198 break;
8199 case 1:
8200 aux->table[i].end.section = sym->st_shndx;
1e456d54 8201 aux->table[i].end.offset = sym->st_value + rp->r_addend;
57346661
AM
8202 break;
8203 default:
8204 break;
8205 }
8206 }
8207
8208 free (rela);
8209 }
8210
1c0751b2 8211 aux->table_len = nentries;
57346661 8212
32ec8896 8213 return TRUE;
57346661
AM
8214}
8215
32ec8896 8216static bfd_boolean
dda8d76d 8217hppa_process_unwind (Filedata * filedata)
57346661 8218{
57346661 8219 struct hppa_unw_aux_info aux;
2cf0635d
NC
8220 Elf_Internal_Shdr * unwsec = NULL;
8221 Elf_Internal_Shdr * strsec;
8222 Elf_Internal_Shdr * sec;
18bd398b 8223 unsigned long i;
32ec8896 8224 bfd_boolean res = TRUE;
57346661 8225
dda8d76d 8226 if (filedata->string_table == NULL)
32ec8896 8227 return FALSE;
1b31d05e
NC
8228
8229 memset (& aux, 0, sizeof (aux));
57346661 8230
dda8d76d 8231 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
57346661 8232 {
c256ffe7 8233 if (sec->sh_type == SHT_SYMTAB
dda8d76d 8234 && sec->sh_link < filedata->file_header.e_shnum)
57346661 8235 {
dda8d76d 8236 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
57346661 8237
dda8d76d 8238 strsec = filedata->section_headers + sec->sh_link;
4082ef84
NC
8239 if (aux.strtab != NULL)
8240 {
8241 error (_("Multiple auxillary string tables encountered\n"));
8242 free (aux.strtab);
32ec8896 8243 res = FALSE;
4082ef84 8244 }
dda8d76d 8245 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
3f5e193b
NC
8246 1, strsec->sh_size,
8247 _("string table"));
c256ffe7 8248 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
57346661 8249 }
18bd398b 8250 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
57346661
AM
8251 unwsec = sec;
8252 }
8253
8254 if (!unwsec)
8255 printf (_("\nThere are no unwind sections in this file.\n"));
8256
dda8d76d 8257 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
57346661 8258 {
18bd398b 8259 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
57346661 8260 {
43f6cd05 8261 unsigned long num_unwind = sec->sh_size / 16;
dda8d76d 8262
d3a49aa8
AM
8263 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8264 "contains %lu entry:\n",
8265 "\nUnwind section '%s' at offset 0x%lx "
8266 "contains %lu entries:\n",
8267 num_unwind),
dda8d76d 8268 printable_section_name (filedata, sec),
57346661 8269 (unsigned long) sec->sh_offset,
d3a49aa8 8270 num_unwind);
57346661 8271
dda8d76d 8272 if (! slurp_hppa_unwind_table (filedata, &aux, sec))
32ec8896 8273 res = FALSE;
66b09c7e
S
8274
8275 if (res && aux.table_len > 0)
32ec8896 8276 {
dda8d76d 8277 if (! dump_hppa_unwind (filedata, &aux))
32ec8896
NC
8278 res = FALSE;
8279 }
57346661
AM
8280
8281 if (aux.table)
8282 free ((char *) aux.table);
8283 aux.table = NULL;
8284 }
8285 }
8286
8287 if (aux.symtab)
8288 free (aux.symtab);
8289 if (aux.strtab)
8290 free ((char *) aux.strtab);
32ec8896
NC
8291
8292 return res;
57346661
AM
8293}
8294
0b6ae522
DJ
8295struct arm_section
8296{
a734115a
NC
8297 unsigned char * data; /* The unwind data. */
8298 Elf_Internal_Shdr * sec; /* The cached unwind section header. */
8299 Elf_Internal_Rela * rela; /* The cached relocations for this section. */
8300 unsigned long nrelas; /* The number of relocations. */
8301 unsigned int rel_type; /* REL or RELA ? */
8302 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
0b6ae522
DJ
8303};
8304
8305struct arm_unw_aux_info
8306{
dda8d76d 8307 Filedata * filedata; /* The file containing the unwind sections. */
a734115a
NC
8308 Elf_Internal_Sym * symtab; /* The file's symbol table. */
8309 unsigned long nsyms; /* Number of symbols. */
948f632f
DA
8310 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8311 unsigned long nfuns; /* Number of these symbols. */
a734115a
NC
8312 char * strtab; /* The file's string table. */
8313 unsigned long strtab_size; /* Size of string table. */
0b6ae522
DJ
8314};
8315
8316static const char *
dda8d76d
NC
8317arm_print_vma_and_name (Filedata * filedata,
8318 struct arm_unw_aux_info * aux,
8319 bfd_vma fn,
8320 struct absaddr addr)
0b6ae522
DJ
8321{
8322 const char *procname;
8323 bfd_vma sym_offset;
8324
8325 if (addr.section == SHN_UNDEF)
8326 addr.offset = fn;
8327
dda8d76d 8328 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
0b6ae522
DJ
8329 aux->strtab_size, addr, &procname,
8330 &sym_offset);
8331
8332 print_vma (fn, PREFIX_HEX);
8333
8334 if (procname)
8335 {
8336 fputs (" <", stdout);
8337 fputs (procname, stdout);
8338
8339 if (sym_offset)
8340 printf ("+0x%lx", (unsigned long) sym_offset);
8341 fputc ('>', stdout);
8342 }
8343
8344 return procname;
8345}
8346
8347static void
8348arm_free_section (struct arm_section *arm_sec)
8349{
8350 if (arm_sec->data != NULL)
8351 free (arm_sec->data);
8352
8353 if (arm_sec->rela != NULL)
8354 free (arm_sec->rela);
8355}
8356
a734115a
NC
8357/* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8358 cached section and install SEC instead.
8359 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8360 and return its valued in * WORDP, relocating if necessary.
1b31d05e 8361 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
a734115a 8362 relocation's offset in ADDR.
1b31d05e
NC
8363 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8364 into the string table of the symbol associated with the reloc. If no
8365 reloc was applied store -1 there.
8366 5) Return TRUE upon success, FALSE otherwise. */
a734115a
NC
8367
8368static bfd_boolean
dda8d76d
NC
8369get_unwind_section_word (Filedata * filedata,
8370 struct arm_unw_aux_info * aux,
1b31d05e
NC
8371 struct arm_section * arm_sec,
8372 Elf_Internal_Shdr * sec,
8373 bfd_vma word_offset,
8374 unsigned int * wordp,
8375 struct absaddr * addr,
8376 bfd_vma * sym_name)
0b6ae522
DJ
8377{
8378 Elf_Internal_Rela *rp;
8379 Elf_Internal_Sym *sym;
8380 const char * relname;
8381 unsigned int word;
8382 bfd_boolean wrapped;
8383
e0a31db1
NC
8384 if (sec == NULL || arm_sec == NULL)
8385 return FALSE;
8386
0b6ae522
DJ
8387 addr->section = SHN_UNDEF;
8388 addr->offset = 0;
8389
1b31d05e
NC
8390 if (sym_name != NULL)
8391 *sym_name = (bfd_vma) -1;
8392
a734115a 8393 /* If necessary, update the section cache. */
0b6ae522
DJ
8394 if (sec != arm_sec->sec)
8395 {
8396 Elf_Internal_Shdr *relsec;
8397
8398 arm_free_section (arm_sec);
8399
8400 arm_sec->sec = sec;
dda8d76d 8401 arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1,
0b6ae522 8402 sec->sh_size, _("unwind data"));
0b6ae522
DJ
8403 arm_sec->rela = NULL;
8404 arm_sec->nrelas = 0;
8405
dda8d76d
NC
8406 for (relsec = filedata->section_headers;
8407 relsec < filedata->section_headers + filedata->file_header.e_shnum;
0b6ae522
DJ
8408 ++relsec)
8409 {
dda8d76d
NC
8410 if (relsec->sh_info >= filedata->file_header.e_shnum
8411 || filedata->section_headers + relsec->sh_info != sec
1ae40aa4
NC
8412 /* PR 15745: Check the section type as well. */
8413 || (relsec->sh_type != SHT_REL
8414 && relsec->sh_type != SHT_RELA))
0b6ae522
DJ
8415 continue;
8416
a734115a 8417 arm_sec->rel_type = relsec->sh_type;
0b6ae522
DJ
8418 if (relsec->sh_type == SHT_REL)
8419 {
dda8d76d 8420 if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset,
0b6ae522
DJ
8421 relsec->sh_size,
8422 & arm_sec->rela, & arm_sec->nrelas))
a734115a 8423 return FALSE;
0b6ae522 8424 }
1ae40aa4 8425 else /* relsec->sh_type == SHT_RELA */
0b6ae522 8426 {
dda8d76d 8427 if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset,
0b6ae522
DJ
8428 relsec->sh_size,
8429 & arm_sec->rela, & arm_sec->nrelas))
a734115a 8430 return FALSE;
0b6ae522 8431 }
1ae40aa4 8432 break;
0b6ae522
DJ
8433 }
8434
8435 arm_sec->next_rela = arm_sec->rela;
8436 }
8437
a734115a 8438 /* If there is no unwind data we can do nothing. */
0b6ae522 8439 if (arm_sec->data == NULL)
a734115a 8440 return FALSE;
0b6ae522 8441
e0a31db1 8442 /* If the offset is invalid then fail. */
f32ba729
NC
8443 if (/* PR 21343 *//* PR 18879 */
8444 sec->sh_size < 4
8445 || word_offset > (sec->sh_size - 4)
1a915552 8446 || ((bfd_signed_vma) word_offset) < 0)
e0a31db1
NC
8447 return FALSE;
8448
a734115a 8449 /* Get the word at the required offset. */
0b6ae522
DJ
8450 word = byte_get (arm_sec->data + word_offset, 4);
8451
0eff7165
NC
8452 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8453 if (arm_sec->rela == NULL)
8454 {
8455 * wordp = word;
8456 return TRUE;
8457 }
8458
a734115a 8459 /* Look through the relocs to find the one that applies to the provided offset. */
0b6ae522
DJ
8460 wrapped = FALSE;
8461 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
8462 {
8463 bfd_vma prelval, offset;
8464
8465 if (rp->r_offset > word_offset && !wrapped)
8466 {
8467 rp = arm_sec->rela;
8468 wrapped = TRUE;
8469 }
8470 if (rp->r_offset > word_offset)
8471 break;
8472
8473 if (rp->r_offset & 3)
8474 {
8475 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8476 (unsigned long) rp->r_offset);
8477 continue;
8478 }
8479
8480 if (rp->r_offset < word_offset)
8481 continue;
8482
74e1a04b
NC
8483 /* PR 17531: file: 027-161405-0.004 */
8484 if (aux->symtab == NULL)
8485 continue;
8486
0b6ae522
DJ
8487 if (arm_sec->rel_type == SHT_REL)
8488 {
8489 offset = word & 0x7fffffff;
8490 if (offset & 0x40000000)
8491 offset |= ~ (bfd_vma) 0x7fffffff;
8492 }
a734115a 8493 else if (arm_sec->rel_type == SHT_RELA)
0b6ae522 8494 offset = rp->r_addend;
a734115a 8495 else
74e1a04b
NC
8496 {
8497 error (_("Unknown section relocation type %d encountered\n"),
8498 arm_sec->rel_type);
8499 break;
8500 }
0b6ae522 8501
071436c6
NC
8502 /* PR 17531 file: 027-1241568-0.004. */
8503 if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
8504 {
8505 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8506 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
8507 break;
8508 }
8509
8510 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
0b6ae522
DJ
8511 offset += sym->st_value;
8512 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
8513
a734115a 8514 /* Check that we are processing the expected reloc type. */
dda8d76d 8515 if (filedata->file_header.e_machine == EM_ARM)
a734115a
NC
8516 {
8517 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
071436c6
NC
8518 if (relname == NULL)
8519 {
8520 warn (_("Skipping unknown ARM relocation type: %d\n"),
8521 (int) ELF32_R_TYPE (rp->r_info));
8522 continue;
8523 }
a734115a
NC
8524
8525 if (streq (relname, "R_ARM_NONE"))
8526 continue;
0b4362b0 8527
a734115a
NC
8528 if (! streq (relname, "R_ARM_PREL31"))
8529 {
071436c6 8530 warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
a734115a
NC
8531 continue;
8532 }
8533 }
dda8d76d 8534 else if (filedata->file_header.e_machine == EM_TI_C6000)
a734115a
NC
8535 {
8536 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
071436c6
NC
8537 if (relname == NULL)
8538 {
8539 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8540 (int) ELF32_R_TYPE (rp->r_info));
8541 continue;
8542 }
0b4362b0 8543
a734115a
NC
8544 if (streq (relname, "R_C6000_NONE"))
8545 continue;
8546
8547 if (! streq (relname, "R_C6000_PREL31"))
8548 {
071436c6 8549 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
a734115a
NC
8550 continue;
8551 }
8552
8553 prelval >>= 1;
8554 }
8555 else
74e1a04b
NC
8556 {
8557 /* This function currently only supports ARM and TI unwinders. */
8558 warn (_("Only TI and ARM unwinders are currently supported\n"));
8559 break;
8560 }
fa197c1c 8561
0b6ae522
DJ
8562 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
8563 addr->section = sym->st_shndx;
8564 addr->offset = offset;
74e1a04b 8565
1b31d05e
NC
8566 if (sym_name)
8567 * sym_name = sym->st_name;
0b6ae522
DJ
8568 break;
8569 }
8570
8571 *wordp = word;
8572 arm_sec->next_rela = rp;
8573
a734115a 8574 return TRUE;
0b6ae522
DJ
8575}
8576
a734115a
NC
8577static const char *tic6x_unwind_regnames[16] =
8578{
0b4362b0
RM
8579 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8580 "A14", "A13", "A12", "A11", "A10",
a734115a
NC
8581 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8582};
fa197c1c 8583
0b6ae522 8584static void
fa197c1c 8585decode_tic6x_unwind_regmask (unsigned int mask)
0b6ae522 8586{
fa197c1c
PB
8587 int i;
8588
8589 for (i = 12; mask; mask >>= 1, i--)
8590 {
8591 if (mask & 1)
8592 {
8593 fputs (tic6x_unwind_regnames[i], stdout);
8594 if (mask > 1)
8595 fputs (", ", stdout);
8596 }
8597 }
8598}
0b6ae522
DJ
8599
8600#define ADVANCE \
8601 if (remaining == 0 && more_words) \
8602 { \
8603 data_offset += 4; \
dda8d76d 8604 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
1b31d05e 8605 data_offset, & word, & addr, NULL)) \
32ec8896 8606 return FALSE; \
0b6ae522
DJ
8607 remaining = 4; \
8608 more_words--; \
8609 } \
8610
8611#define GET_OP(OP) \
8612 ADVANCE; \
8613 if (remaining) \
8614 { \
8615 remaining--; \
8616 (OP) = word >> 24; \
8617 word <<= 8; \
8618 } \
8619 else \
8620 { \
2b692964 8621 printf (_("[Truncated opcode]\n")); \
32ec8896 8622 return FALSE; \
0b6ae522 8623 } \
cc5914eb 8624 printf ("0x%02x ", OP)
0b6ae522 8625
32ec8896 8626static bfd_boolean
dda8d76d
NC
8627decode_arm_unwind_bytecode (Filedata * filedata,
8628 struct arm_unw_aux_info * aux,
948f632f
DA
8629 unsigned int word,
8630 unsigned int remaining,
8631 unsigned int more_words,
8632 bfd_vma data_offset,
8633 Elf_Internal_Shdr * data_sec,
8634 struct arm_section * data_arm_sec)
fa197c1c
PB
8635{
8636 struct absaddr addr;
32ec8896 8637 bfd_boolean res = TRUE;
0b6ae522
DJ
8638
8639 /* Decode the unwinding instructions. */
8640 while (1)
8641 {
8642 unsigned int op, op2;
8643
8644 ADVANCE;
8645 if (remaining == 0)
8646 break;
8647 remaining--;
8648 op = word >> 24;
8649 word <<= 8;
8650
cc5914eb 8651 printf (" 0x%02x ", op);
0b6ae522
DJ
8652
8653 if ((op & 0xc0) == 0x00)
8654 {
8655 int offset = ((op & 0x3f) << 2) + 4;
61865e30 8656
cc5914eb 8657 printf (" vsp = vsp + %d", offset);
0b6ae522
DJ
8658 }
8659 else if ((op & 0xc0) == 0x40)
8660 {
8661 int offset = ((op & 0x3f) << 2) + 4;
61865e30 8662
cc5914eb 8663 printf (" vsp = vsp - %d", offset);
0b6ae522
DJ
8664 }
8665 else if ((op & 0xf0) == 0x80)
8666 {
8667 GET_OP (op2);
8668 if (op == 0x80 && op2 == 0)
8669 printf (_("Refuse to unwind"));
8670 else
8671 {
8672 unsigned int mask = ((op & 0x0f) << 8) | op2;
32ec8896 8673 bfd_boolean first = TRUE;
0b6ae522 8674 int i;
2b692964 8675
0b6ae522
DJ
8676 printf ("pop {");
8677 for (i = 0; i < 12; i++)
8678 if (mask & (1 << i))
8679 {
8680 if (first)
32ec8896 8681 first = FALSE;
0b6ae522
DJ
8682 else
8683 printf (", ");
8684 printf ("r%d", 4 + i);
8685 }
8686 printf ("}");
8687 }
8688 }
8689 else if ((op & 0xf0) == 0x90)
8690 {
8691 if (op == 0x9d || op == 0x9f)
8692 printf (_(" [Reserved]"));
8693 else
cc5914eb 8694 printf (" vsp = r%d", op & 0x0f);
0b6ae522
DJ
8695 }
8696 else if ((op & 0xf0) == 0xa0)
8697 {
8698 int end = 4 + (op & 0x07);
32ec8896 8699 bfd_boolean first = TRUE;
0b6ae522 8700 int i;
61865e30 8701
0b6ae522
DJ
8702 printf (" pop {");
8703 for (i = 4; i <= end; i++)
8704 {
8705 if (first)
32ec8896 8706 first = FALSE;
0b6ae522
DJ
8707 else
8708 printf (", ");
8709 printf ("r%d", i);
8710 }
8711 if (op & 0x08)
8712 {
1b31d05e 8713 if (!first)
0b6ae522
DJ
8714 printf (", ");
8715 printf ("r14");
8716 }
8717 printf ("}");
8718 }
8719 else if (op == 0xb0)
8720 printf (_(" finish"));
8721 else if (op == 0xb1)
8722 {
8723 GET_OP (op2);
8724 if (op2 == 0 || (op2 & 0xf0) != 0)
8725 printf (_("[Spare]"));
8726 else
8727 {
8728 unsigned int mask = op2 & 0x0f;
32ec8896 8729 bfd_boolean first = TRUE;
0b6ae522 8730 int i;
61865e30 8731
0b6ae522
DJ
8732 printf ("pop {");
8733 for (i = 0; i < 12; i++)
8734 if (mask & (1 << i))
8735 {
8736 if (first)
32ec8896 8737 first = FALSE;
0b6ae522
DJ
8738 else
8739 printf (", ");
8740 printf ("r%d", i);
8741 }
8742 printf ("}");
8743 }
8744 }
8745 else if (op == 0xb2)
8746 {
b115cf96 8747 unsigned char buf[9];
0b6ae522
DJ
8748 unsigned int i, len;
8749 unsigned long offset;
61865e30 8750
b115cf96 8751 for (i = 0; i < sizeof (buf); i++)
0b6ae522
DJ
8752 {
8753 GET_OP (buf[i]);
8754 if ((buf[i] & 0x80) == 0)
8755 break;
8756 }
4082ef84 8757 if (i == sizeof (buf))
32ec8896
NC
8758 {
8759 error (_("corrupt change to vsp"));
8760 res = FALSE;
8761 }
4082ef84
NC
8762 else
8763 {
8764 offset = read_uleb128 (buf, &len, buf + i + 1);
8765 assert (len == i + 1);
8766 offset = offset * 4 + 0x204;
8767 printf ("vsp = vsp + %ld", offset);
8768 }
0b6ae522 8769 }
61865e30 8770 else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
0b6ae522 8771 {
61865e30
NC
8772 unsigned int first, last;
8773
8774 GET_OP (op2);
8775 first = op2 >> 4;
8776 last = op2 & 0x0f;
8777 if (op == 0xc8)
8778 first = first + 16;
8779 printf ("pop {D%d", first);
8780 if (last)
8781 printf ("-D%d", first + last);
8782 printf ("}");
8783 }
8784 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
8785 {
8786 unsigned int count = op & 0x07;
8787
8788 printf ("pop {D8");
8789 if (count)
8790 printf ("-D%d", 8 + count);
8791 printf ("}");
8792 }
8793 else if (op >= 0xc0 && op <= 0xc5)
8794 {
8795 unsigned int count = op & 0x07;
8796
8797 printf (" pop {wR10");
8798 if (count)
8799 printf ("-wR%d", 10 + count);
8800 printf ("}");
8801 }
8802 else if (op == 0xc6)
8803 {
8804 unsigned int first, last;
8805
8806 GET_OP (op2);
8807 first = op2 >> 4;
8808 last = op2 & 0x0f;
8809 printf ("pop {wR%d", first);
8810 if (last)
8811 printf ("-wR%d", first + last);
8812 printf ("}");
8813 }
8814 else if (op == 0xc7)
8815 {
8816 GET_OP (op2);
8817 if (op2 == 0 || (op2 & 0xf0) != 0)
8818 printf (_("[Spare]"));
0b6ae522
DJ
8819 else
8820 {
61865e30 8821 unsigned int mask = op2 & 0x0f;
32ec8896 8822 bfd_boolean first = TRUE;
61865e30
NC
8823 int i;
8824
8825 printf ("pop {");
8826 for (i = 0; i < 4; i++)
8827 if (mask & (1 << i))
8828 {
8829 if (first)
32ec8896 8830 first = FALSE;
61865e30
NC
8831 else
8832 printf (", ");
8833 printf ("wCGR%d", i);
8834 }
8835 printf ("}");
0b6ae522
DJ
8836 }
8837 }
61865e30 8838 else
32ec8896
NC
8839 {
8840 printf (_(" [unsupported opcode]"));
8841 res = FALSE;
8842 }
8843
0b6ae522
DJ
8844 printf ("\n");
8845 }
32ec8896
NC
8846
8847 return res;
fa197c1c
PB
8848}
8849
32ec8896 8850static bfd_boolean
dda8d76d
NC
8851decode_tic6x_unwind_bytecode (Filedata * filedata,
8852 struct arm_unw_aux_info * aux,
948f632f
DA
8853 unsigned int word,
8854 unsigned int remaining,
8855 unsigned int more_words,
8856 bfd_vma data_offset,
8857 Elf_Internal_Shdr * data_sec,
8858 struct arm_section * data_arm_sec)
fa197c1c
PB
8859{
8860 struct absaddr addr;
8861
8862 /* Decode the unwinding instructions. */
8863 while (1)
8864 {
8865 unsigned int op, op2;
8866
8867 ADVANCE;
8868 if (remaining == 0)
8869 break;
8870 remaining--;
8871 op = word >> 24;
8872 word <<= 8;
8873
9cf03b7e 8874 printf (" 0x%02x ", op);
fa197c1c
PB
8875
8876 if ((op & 0xc0) == 0x00)
8877 {
8878 int offset = ((op & 0x3f) << 3) + 8;
9cf03b7e 8879 printf (" sp = sp + %d", offset);
fa197c1c
PB
8880 }
8881 else if ((op & 0xc0) == 0x80)
8882 {
8883 GET_OP (op2);
8884 if (op == 0x80 && op2 == 0)
8885 printf (_("Refuse to unwind"));
8886 else
8887 {
8888 unsigned int mask = ((op & 0x1f) << 8) | op2;
8889 if (op & 0x20)
8890 printf ("pop compact {");
8891 else
8892 printf ("pop {");
8893
8894 decode_tic6x_unwind_regmask (mask);
8895 printf("}");
8896 }
8897 }
8898 else if ((op & 0xf0) == 0xc0)
8899 {
8900 unsigned int reg;
8901 unsigned int nregs;
8902 unsigned int i;
8903 const char *name;
a734115a
NC
8904 struct
8905 {
32ec8896
NC
8906 unsigned int offset;
8907 unsigned int reg;
fa197c1c
PB
8908 } regpos[16];
8909
8910 /* Scan entire instruction first so that GET_OP output is not
8911 interleaved with disassembly. */
8912 nregs = 0;
8913 for (i = 0; nregs < (op & 0xf); i++)
8914 {
8915 GET_OP (op2);
8916 reg = op2 >> 4;
8917 if (reg != 0xf)
8918 {
8919 regpos[nregs].offset = i * 2;
8920 regpos[nregs].reg = reg;
8921 nregs++;
8922 }
8923
8924 reg = op2 & 0xf;
8925 if (reg != 0xf)
8926 {
8927 regpos[nregs].offset = i * 2 + 1;
8928 regpos[nregs].reg = reg;
8929 nregs++;
8930 }
8931 }
8932
8933 printf (_("pop frame {"));
18344509 8934 if (nregs == 0)
fa197c1c 8935 {
18344509
NC
8936 printf (_("*corrupt* - no registers specified"));
8937 }
8938 else
8939 {
8940 reg = nregs - 1;
8941 for (i = i * 2; i > 0; i--)
fa197c1c 8942 {
18344509
NC
8943 if (regpos[reg].offset == i - 1)
8944 {
8945 name = tic6x_unwind_regnames[regpos[reg].reg];
8946 if (reg > 0)
8947 reg--;
8948 }
8949 else
8950 name = _("[pad]");
fa197c1c 8951
18344509
NC
8952 fputs (name, stdout);
8953 if (i > 1)
8954 printf (", ");
8955 }
fa197c1c
PB
8956 }
8957
8958 printf ("}");
8959 }
8960 else if (op == 0xd0)
8961 printf (" MOV FP, SP");
8962 else if (op == 0xd1)
8963 printf (" __c6xabi_pop_rts");
8964 else if (op == 0xd2)
8965 {
8966 unsigned char buf[9];
8967 unsigned int i, len;
8968 unsigned long offset;
a734115a 8969
fa197c1c
PB
8970 for (i = 0; i < sizeof (buf); i++)
8971 {
8972 GET_OP (buf[i]);
8973 if ((buf[i] & 0x80) == 0)
8974 break;
8975 }
0eff7165
NC
8976 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
8977 if (i == sizeof (buf))
8978 {
0eff7165 8979 warn (_("Corrupt stack pointer adjustment detected\n"));
32ec8896 8980 return FALSE;
0eff7165 8981 }
948f632f 8982
f6f0e17b 8983 offset = read_uleb128 (buf, &len, buf + i + 1);
fa197c1c
PB
8984 assert (len == i + 1);
8985 offset = offset * 8 + 0x408;
8986 printf (_("sp = sp + %ld"), offset);
8987 }
8988 else if ((op & 0xf0) == 0xe0)
8989 {
8990 if ((op & 0x0f) == 7)
8991 printf (" RETURN");
8992 else
8993 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
8994 }
8995 else
8996 {
8997 printf (_(" [unsupported opcode]"));
8998 }
8999 putchar ('\n');
9000 }
32ec8896
NC
9001
9002 return TRUE;
fa197c1c
PB
9003}
9004
9005static bfd_vma
dda8d76d 9006arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where)
fa197c1c
PB
9007{
9008 bfd_vma offset;
9009
9010 offset = word & 0x7fffffff;
9011 if (offset & 0x40000000)
9012 offset |= ~ (bfd_vma) 0x7fffffff;
9013
dda8d76d 9014 if (filedata->file_header.e_machine == EM_TI_C6000)
fa197c1c
PB
9015 offset <<= 1;
9016
9017 return offset + where;
9018}
9019
32ec8896 9020static bfd_boolean
dda8d76d
NC
9021decode_arm_unwind (Filedata * filedata,
9022 struct arm_unw_aux_info * aux,
1b31d05e
NC
9023 unsigned int word,
9024 unsigned int remaining,
9025 bfd_vma data_offset,
9026 Elf_Internal_Shdr * data_sec,
9027 struct arm_section * data_arm_sec)
fa197c1c
PB
9028{
9029 int per_index;
9030 unsigned int more_words = 0;
37e14bc3 9031 struct absaddr addr;
1b31d05e 9032 bfd_vma sym_name = (bfd_vma) -1;
97953bab 9033 bfd_boolean res = TRUE;
fa197c1c
PB
9034
9035 if (remaining == 0)
9036 {
1b31d05e
NC
9037 /* Fetch the first word.
9038 Note - when decoding an object file the address extracted
9039 here will always be 0. So we also pass in the sym_name
9040 parameter so that we can find the symbol associated with
9041 the personality routine. */
dda8d76d 9042 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset,
1b31d05e 9043 & word, & addr, & sym_name))
32ec8896 9044 return FALSE;
1b31d05e 9045
fa197c1c
PB
9046 remaining = 4;
9047 }
9048
9049 if ((word & 0x80000000) == 0)
9050 {
9051 /* Expand prel31 for personality routine. */
9052 bfd_vma fn;
9053 const char *procname;
9054
dda8d76d 9055 fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset);
fa197c1c 9056 printf (_(" Personality routine: "));
1b31d05e
NC
9057 if (fn == 0
9058 && addr.section == SHN_UNDEF && addr.offset == 0
9059 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
9060 {
9061 procname = aux->strtab + sym_name;
9062 print_vma (fn, PREFIX_HEX);
9063 if (procname)
9064 {
9065 fputs (" <", stdout);
9066 fputs (procname, stdout);
9067 fputc ('>', stdout);
9068 }
9069 }
9070 else
dda8d76d 9071 procname = arm_print_vma_and_name (filedata, aux, fn, addr);
fa197c1c
PB
9072 fputc ('\n', stdout);
9073
9074 /* The GCC personality routines use the standard compact
9075 encoding, starting with one byte giving the number of
9076 words. */
9077 if (procname != NULL
9078 && (const_strneq (procname, "__gcc_personality_v0")
9079 || const_strneq (procname, "__gxx_personality_v0")
9080 || const_strneq (procname, "__gcj_personality_v0")
9081 || const_strneq (procname, "__gnu_objc_personality_v0")))
9082 {
9083 remaining = 0;
9084 more_words = 1;
9085 ADVANCE;
9086 if (!remaining)
9087 {
9088 printf (_(" [Truncated data]\n"));
32ec8896 9089 return FALSE;
fa197c1c
PB
9090 }
9091 more_words = word >> 24;
9092 word <<= 8;
9093 remaining--;
9094 per_index = -1;
9095 }
9096 else
32ec8896 9097 return TRUE;
fa197c1c
PB
9098 }
9099 else
9100 {
1b31d05e 9101 /* ARM EHABI Section 6.3:
0b4362b0 9102
1b31d05e 9103 An exception-handling table entry for the compact model looks like:
0b4362b0 9104
1b31d05e
NC
9105 31 30-28 27-24 23-0
9106 -- ----- ----- ----
9107 1 0 index Data for personalityRoutine[index] */
9108
dda8d76d 9109 if (filedata->file_header.e_machine == EM_ARM
1b31d05e 9110 && (word & 0x70000000))
32ec8896
NC
9111 {
9112 warn (_("Corrupt ARM compact model table entry: %x \n"), word);
9113 res = FALSE;
9114 }
1b31d05e 9115
fa197c1c 9116 per_index = (word >> 24) & 0x7f;
1b31d05e 9117 printf (_(" Compact model index: %d\n"), per_index);
fa197c1c
PB
9118 if (per_index == 0)
9119 {
9120 more_words = 0;
9121 word <<= 8;
9122 remaining--;
9123 }
9124 else if (per_index < 3)
9125 {
9126 more_words = (word >> 16) & 0xff;
9127 word <<= 16;
9128 remaining -= 2;
9129 }
9130 }
9131
dda8d76d 9132 switch (filedata->file_header.e_machine)
fa197c1c
PB
9133 {
9134 case EM_ARM:
9135 if (per_index < 3)
9136 {
dda8d76d 9137 if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words,
32ec8896
NC
9138 data_offset, data_sec, data_arm_sec))
9139 res = FALSE;
fa197c1c
PB
9140 }
9141 else
1b31d05e
NC
9142 {
9143 warn (_("Unknown ARM compact model index encountered\n"));
9144 printf (_(" [reserved]\n"));
32ec8896 9145 res = FALSE;
1b31d05e 9146 }
fa197c1c
PB
9147 break;
9148
9149 case EM_TI_C6000:
9150 if (per_index < 3)
9151 {
dda8d76d 9152 if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words,
32ec8896
NC
9153 data_offset, data_sec, data_arm_sec))
9154 res = FALSE;
fa197c1c
PB
9155 }
9156 else if (per_index < 5)
9157 {
9158 if (((word >> 17) & 0x7f) == 0x7f)
9159 printf (_(" Restore stack from frame pointer\n"));
9160 else
9161 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
9162 printf (_(" Registers restored: "));
9163 if (per_index == 4)
9164 printf (" (compact) ");
9165 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
9166 putchar ('\n');
9167 printf (_(" Return register: %s\n"),
9168 tic6x_unwind_regnames[word & 0xf]);
9169 }
9170 else
1b31d05e 9171 printf (_(" [reserved (%d)]\n"), per_index);
fa197c1c
PB
9172 break;
9173
9174 default:
74e1a04b 9175 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
dda8d76d 9176 filedata->file_header.e_machine);
32ec8896 9177 res = FALSE;
fa197c1c 9178 }
0b6ae522
DJ
9179
9180 /* Decode the descriptors. Not implemented. */
32ec8896
NC
9181
9182 return res;
0b6ae522
DJ
9183}
9184
32ec8896 9185static bfd_boolean
dda8d76d
NC
9186dump_arm_unwind (Filedata * filedata,
9187 struct arm_unw_aux_info * aux,
9188 Elf_Internal_Shdr * exidx_sec)
0b6ae522
DJ
9189{
9190 struct arm_section exidx_arm_sec, extab_arm_sec;
9191 unsigned int i, exidx_len;
948f632f 9192 unsigned long j, nfuns;
32ec8896 9193 bfd_boolean res = TRUE;
0b6ae522
DJ
9194
9195 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
9196 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
9197 exidx_len = exidx_sec->sh_size / 8;
9198
948f632f
DA
9199 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
9200 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
9201 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
9202 aux->funtab[nfuns++] = aux->symtab[j];
9203 aux->nfuns = nfuns;
9204 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
9205
0b6ae522
DJ
9206 for (i = 0; i < exidx_len; i++)
9207 {
9208 unsigned int exidx_fn, exidx_entry;
9209 struct absaddr fn_addr, entry_addr;
9210 bfd_vma fn;
9211
9212 fputc ('\n', stdout);
9213
dda8d76d 9214 if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
1b31d05e 9215 8 * i, & exidx_fn, & fn_addr, NULL)
dda8d76d 9216 || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
1b31d05e 9217 8 * i + 4, & exidx_entry, & entry_addr, NULL))
0b6ae522 9218 {
948f632f 9219 free (aux->funtab);
1b31d05e
NC
9220 arm_free_section (& exidx_arm_sec);
9221 arm_free_section (& extab_arm_sec);
32ec8896 9222 return FALSE;
0b6ae522
DJ
9223 }
9224
83c257ca
NC
9225 /* ARM EHABI, Section 5:
9226 An index table entry consists of 2 words.
9227 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9228 if (exidx_fn & 0x80000000)
32ec8896
NC
9229 {
9230 warn (_("corrupt index table entry: %x\n"), exidx_fn);
9231 res = FALSE;
9232 }
83c257ca 9233
dda8d76d 9234 fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i);
0b6ae522 9235
dda8d76d 9236 arm_print_vma_and_name (filedata, aux, fn, fn_addr);
0b6ae522
DJ
9237 fputs (": ", stdout);
9238
9239 if (exidx_entry == 1)
9240 {
9241 print_vma (exidx_entry, PREFIX_HEX);
9242 fputs (" [cantunwind]\n", stdout);
9243 }
9244 else if (exidx_entry & 0x80000000)
9245 {
9246 print_vma (exidx_entry, PREFIX_HEX);
9247 fputc ('\n', stdout);
dda8d76d 9248 decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL);
0b6ae522
DJ
9249 }
9250 else
9251 {
8f73510c 9252 bfd_vma table, table_offset = 0;
0b6ae522
DJ
9253 Elf_Internal_Shdr *table_sec;
9254
9255 fputs ("@", stdout);
dda8d76d 9256 table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
0b6ae522
DJ
9257 print_vma (table, PREFIX_HEX);
9258 printf ("\n");
9259
9260 /* Locate the matching .ARM.extab. */
9261 if (entry_addr.section != SHN_UNDEF
dda8d76d 9262 && entry_addr.section < filedata->file_header.e_shnum)
0b6ae522 9263 {
dda8d76d 9264 table_sec = filedata->section_headers + entry_addr.section;
0b6ae522 9265 table_offset = entry_addr.offset;
1a915552
NC
9266 /* PR 18879 */
9267 if (table_offset > table_sec->sh_size
9268 || ((bfd_signed_vma) table_offset) < 0)
9269 {
9270 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9271 (unsigned long) table_offset,
dda8d76d 9272 printable_section_name (filedata, table_sec));
32ec8896 9273 res = FALSE;
1a915552
NC
9274 continue;
9275 }
0b6ae522
DJ
9276 }
9277 else
9278 {
dda8d76d 9279 table_sec = find_section_by_address (filedata, table);
0b6ae522
DJ
9280 if (table_sec != NULL)
9281 table_offset = table - table_sec->sh_addr;
9282 }
32ec8896 9283
0b6ae522
DJ
9284 if (table_sec == NULL)
9285 {
9286 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9287 (unsigned long) table);
32ec8896 9288 res = FALSE;
0b6ae522
DJ
9289 continue;
9290 }
32ec8896 9291
dda8d76d 9292 if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec,
32ec8896
NC
9293 &extab_arm_sec))
9294 res = FALSE;
0b6ae522
DJ
9295 }
9296 }
9297
9298 printf ("\n");
9299
948f632f 9300 free (aux->funtab);
0b6ae522
DJ
9301 arm_free_section (&exidx_arm_sec);
9302 arm_free_section (&extab_arm_sec);
32ec8896
NC
9303
9304 return res;
0b6ae522
DJ
9305}
9306
fa197c1c 9307/* Used for both ARM and C6X unwinding tables. */
1b31d05e 9308
32ec8896 9309static bfd_boolean
dda8d76d 9310arm_process_unwind (Filedata * filedata)
0b6ae522
DJ
9311{
9312 struct arm_unw_aux_info aux;
9313 Elf_Internal_Shdr *unwsec = NULL;
9314 Elf_Internal_Shdr *strsec;
9315 Elf_Internal_Shdr *sec;
9316 unsigned long i;
fa197c1c 9317 unsigned int sec_type;
32ec8896 9318 bfd_boolean res = TRUE;
0b6ae522 9319
dda8d76d 9320 switch (filedata->file_header.e_machine)
fa197c1c
PB
9321 {
9322 case EM_ARM:
9323 sec_type = SHT_ARM_EXIDX;
9324 break;
9325
9326 case EM_TI_C6000:
9327 sec_type = SHT_C6000_UNWIND;
9328 break;
9329
0b4362b0 9330 default:
74e1a04b 9331 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
dda8d76d 9332 filedata->file_header.e_machine);
32ec8896 9333 return FALSE;
fa197c1c
PB
9334 }
9335
dda8d76d 9336 if (filedata->string_table == NULL)
32ec8896 9337 return FALSE;
1b31d05e
NC
9338
9339 memset (& aux, 0, sizeof (aux));
dda8d76d 9340 aux.filedata = filedata;
0b6ae522 9341
dda8d76d 9342 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
0b6ae522 9343 {
dda8d76d 9344 if (sec->sh_type == SHT_SYMTAB && sec->sh_link < filedata->file_header.e_shnum)
0b6ae522 9345 {
dda8d76d 9346 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
0b6ae522 9347
dda8d76d 9348 strsec = filedata->section_headers + sec->sh_link;
74e1a04b
NC
9349
9350 /* PR binutils/17531 file: 011-12666-0.004. */
9351 if (aux.strtab != NULL)
9352 {
4082ef84 9353 error (_("Multiple string tables found in file.\n"));
74e1a04b 9354 free (aux.strtab);
32ec8896 9355 res = FALSE;
74e1a04b 9356 }
dda8d76d 9357 aux.strtab = get_data (NULL, filedata, strsec->sh_offset,
0b6ae522
DJ
9358 1, strsec->sh_size, _("string table"));
9359 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
9360 }
fa197c1c 9361 else if (sec->sh_type == sec_type)
0b6ae522
DJ
9362 unwsec = sec;
9363 }
9364
1b31d05e 9365 if (unwsec == NULL)
0b6ae522 9366 printf (_("\nThere are no unwind sections in this file.\n"));
1b31d05e 9367 else
dda8d76d 9368 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
1b31d05e
NC
9369 {
9370 if (sec->sh_type == sec_type)
9371 {
d3a49aa8
AM
9372 unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size);
9373 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9374 "contains %lu entry:\n",
9375 "\nUnwind section '%s' at offset 0x%lx "
9376 "contains %lu entries:\n",
9377 num_unwind),
dda8d76d 9378 printable_section_name (filedata, sec),
1b31d05e 9379 (unsigned long) sec->sh_offset,
d3a49aa8 9380 num_unwind);
0b6ae522 9381
dda8d76d 9382 if (! dump_arm_unwind (filedata, &aux, sec))
32ec8896 9383 res = FALSE;
1b31d05e
NC
9384 }
9385 }
0b6ae522
DJ
9386
9387 if (aux.symtab)
9388 free (aux.symtab);
9389 if (aux.strtab)
9390 free ((char *) aux.strtab);
32ec8896
NC
9391
9392 return res;
0b6ae522
DJ
9393}
9394
32ec8896 9395static bfd_boolean
dda8d76d 9396process_unwind (Filedata * filedata)
57346661 9397{
2cf0635d
NC
9398 struct unwind_handler
9399 {
32ec8896 9400 unsigned int machtype;
dda8d76d 9401 bfd_boolean (* handler)(Filedata *);
2cf0635d
NC
9402 } handlers[] =
9403 {
0b6ae522 9404 { EM_ARM, arm_process_unwind },
57346661
AM
9405 { EM_IA_64, ia64_process_unwind },
9406 { EM_PARISC, hppa_process_unwind },
fa197c1c 9407 { EM_TI_C6000, arm_process_unwind },
32ec8896 9408 { 0, NULL }
57346661
AM
9409 };
9410 int i;
9411
9412 if (!do_unwind)
32ec8896 9413 return TRUE;
57346661
AM
9414
9415 for (i = 0; handlers[i].handler != NULL; i++)
dda8d76d
NC
9416 if (filedata->file_header.e_machine == handlers[i].machtype)
9417 return handlers[i].handler (filedata);
57346661 9418
1b31d05e 9419 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
dda8d76d 9420 get_machine_name (filedata->file_header.e_machine));
32ec8896 9421 return TRUE;
57346661
AM
9422}
9423
37c18eed
SD
9424static void
9425dynamic_section_aarch64_val (Elf_Internal_Dyn * entry)
9426{
9427 switch (entry->d_tag)
9428 {
9429 case DT_AARCH64_BTI_PLT:
1dbade74 9430 case DT_AARCH64_PAC_PLT:
37c18eed
SD
9431 break;
9432 default:
9433 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9434 break;
9435 }
9436 putchar ('\n');
9437}
9438
252b5132 9439static void
2cf0635d 9440dynamic_section_mips_val (Elf_Internal_Dyn * entry)
252b5132
RH
9441{
9442 switch (entry->d_tag)
9443 {
9444 case DT_MIPS_FLAGS:
9445 if (entry->d_un.d_val == 0)
4b68bca3 9446 printf (_("NONE"));
252b5132
RH
9447 else
9448 {
9449 static const char * opts[] =
9450 {
9451 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9452 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9453 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9454 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9455 "RLD_ORDER_SAFE"
9456 };
9457 unsigned int cnt;
32ec8896 9458 bfd_boolean first = TRUE;
2b692964 9459
60bca95a 9460 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
252b5132
RH
9461 if (entry->d_un.d_val & (1 << cnt))
9462 {
9463 printf ("%s%s", first ? "" : " ", opts[cnt]);
32ec8896 9464 first = FALSE;
252b5132 9465 }
252b5132
RH
9466 }
9467 break;
103f02d3 9468
252b5132 9469 case DT_MIPS_IVERSION:
d79b3d50 9470 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
4b68bca3 9471 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
252b5132 9472 else
76ca31c0
NC
9473 {
9474 char buf[40];
9475 sprintf_vma (buf, entry->d_un.d_ptr);
9476 /* Note: coded this way so that there is a single string for translation. */
9477 printf (_("<corrupt: %s>"), buf);
9478 }
252b5132 9479 break;
103f02d3 9480
252b5132
RH
9481 case DT_MIPS_TIME_STAMP:
9482 {
d5b07ef4 9483 char timebuf[128];
2cf0635d 9484 struct tm * tmp;
91d6fa6a 9485 time_t atime = entry->d_un.d_val;
82b1b41b 9486
91d6fa6a 9487 tmp = gmtime (&atime);
82b1b41b
NC
9488 /* PR 17531: file: 6accc532. */
9489 if (tmp == NULL)
9490 snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
9491 else
9492 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
9493 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9494 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
4b68bca3 9495 printf (_("Time Stamp: %s"), timebuf);
252b5132
RH
9496 }
9497 break;
103f02d3 9498
252b5132
RH
9499 case DT_MIPS_RLD_VERSION:
9500 case DT_MIPS_LOCAL_GOTNO:
9501 case DT_MIPS_CONFLICTNO:
9502 case DT_MIPS_LIBLISTNO:
9503 case DT_MIPS_SYMTABNO:
9504 case DT_MIPS_UNREFEXTNO:
9505 case DT_MIPS_HIPAGENO:
9506 case DT_MIPS_DELTA_CLASS_NO:
9507 case DT_MIPS_DELTA_INSTANCE_NO:
9508 case DT_MIPS_DELTA_RELOC_NO:
9509 case DT_MIPS_DELTA_SYM_NO:
9510 case DT_MIPS_DELTA_CLASSSYM_NO:
9511 case DT_MIPS_COMPACT_SIZE:
c69075ac 9512 print_vma (entry->d_un.d_val, DEC);
252b5132 9513 break;
103f02d3
UD
9514
9515 default:
4b68bca3 9516 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
103f02d3 9517 }
4b68bca3 9518 putchar ('\n');
103f02d3
UD
9519}
9520
103f02d3 9521static void
2cf0635d 9522dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
103f02d3
UD
9523{
9524 switch (entry->d_tag)
9525 {
9526 case DT_HP_DLD_FLAGS:
9527 {
9528 static struct
9529 {
9530 long int bit;
2cf0635d 9531 const char * str;
5e220199
NC
9532 }
9533 flags[] =
9534 {
9535 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
9536 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
9537 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
9538 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
9539 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
9540 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
9541 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
9542 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
9543 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
9544 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
eec8f817
DA
9545 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
9546 { DT_HP_GST, "HP_GST" },
9547 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
9548 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
9549 { DT_HP_NODELETE, "HP_NODELETE" },
9550 { DT_HP_GROUP, "HP_GROUP" },
9551 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
5e220199 9552 };
32ec8896 9553 bfd_boolean first = TRUE;
5e220199 9554 size_t cnt;
f7a99963 9555 bfd_vma val = entry->d_un.d_val;
103f02d3 9556
60bca95a 9557 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
103f02d3 9558 if (val & flags[cnt].bit)
30800947
NC
9559 {
9560 if (! first)
9561 putchar (' ');
9562 fputs (flags[cnt].str, stdout);
32ec8896 9563 first = FALSE;
30800947
NC
9564 val ^= flags[cnt].bit;
9565 }
76da6bbe 9566
103f02d3 9567 if (val != 0 || first)
f7a99963
NC
9568 {
9569 if (! first)
9570 putchar (' ');
9571 print_vma (val, HEX);
9572 }
103f02d3
UD
9573 }
9574 break;
76da6bbe 9575
252b5132 9576 default:
f7a99963
NC
9577 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9578 break;
252b5132 9579 }
35b1837e 9580 putchar ('\n');
252b5132
RH
9581}
9582
28f997cf
TG
9583#ifdef BFD64
9584
9585/* VMS vs Unix time offset and factor. */
9586
9587#define VMS_EPOCH_OFFSET 35067168000000000LL
9588#define VMS_GRANULARITY_FACTOR 10000000
9589
9590/* Display a VMS time in a human readable format. */
9591
9592static void
9593print_vms_time (bfd_int64_t vmstime)
9594{
9595 struct tm *tm;
9596 time_t unxtime;
9597
9598 unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
9599 tm = gmtime (&unxtime);
9600 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
9601 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
9602 tm->tm_hour, tm->tm_min, tm->tm_sec);
9603}
9604#endif /* BFD64 */
9605
ecc51f48 9606static void
2cf0635d 9607dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
ecc51f48
NC
9608{
9609 switch (entry->d_tag)
9610 {
0de14b54 9611 case DT_IA_64_PLT_RESERVE:
bdf4d63a 9612 /* First 3 slots reserved. */
ecc51f48
NC
9613 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9614 printf (" -- ");
9615 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
bdf4d63a
JJ
9616 break;
9617
28f997cf
TG
9618 case DT_IA_64_VMS_LINKTIME:
9619#ifdef BFD64
9620 print_vms_time (entry->d_un.d_val);
9621#endif
9622 break;
9623
9624 case DT_IA_64_VMS_LNKFLAGS:
9625 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9626 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
9627 printf (" CALL_DEBUG");
9628 if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
9629 printf (" NOP0BUFS");
9630 if (entry->d_un.d_val & VMS_LF_P0IMAGE)
9631 printf (" P0IMAGE");
9632 if (entry->d_un.d_val & VMS_LF_MKTHREADS)
9633 printf (" MKTHREADS");
9634 if (entry->d_un.d_val & VMS_LF_UPCALLS)
9635 printf (" UPCALLS");
9636 if (entry->d_un.d_val & VMS_LF_IMGSTA)
9637 printf (" IMGSTA");
9638 if (entry->d_un.d_val & VMS_LF_INITIALIZE)
9639 printf (" INITIALIZE");
9640 if (entry->d_un.d_val & VMS_LF_MAIN)
9641 printf (" MAIN");
9642 if (entry->d_un.d_val & VMS_LF_EXE_INIT)
9643 printf (" EXE_INIT");
9644 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
9645 printf (" TBK_IN_IMG");
9646 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
9647 printf (" DBG_IN_IMG");
9648 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
9649 printf (" TBK_IN_DSF");
9650 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
9651 printf (" DBG_IN_DSF");
9652 if (entry->d_un.d_val & VMS_LF_SIGNATURES)
9653 printf (" SIGNATURES");
9654 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
9655 printf (" REL_SEG_OFF");
9656 break;
9657
bdf4d63a
JJ
9658 default:
9659 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9660 break;
ecc51f48 9661 }
bdf4d63a 9662 putchar ('\n');
ecc51f48
NC
9663}
9664
32ec8896 9665static bfd_boolean
dda8d76d 9666get_32bit_dynamic_section (Filedata * filedata)
252b5132 9667{
2cf0635d
NC
9668 Elf32_External_Dyn * edyn;
9669 Elf32_External_Dyn * ext;
9670 Elf_Internal_Dyn * entry;
103f02d3 9671
dda8d76d 9672 edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
3f5e193b 9673 dynamic_size, _("dynamic section"));
a6e9f9df 9674 if (!edyn)
32ec8896 9675 return FALSE;
103f02d3 9676
071436c6
NC
9677 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9678 might not have the luxury of section headers. Look for the DT_NULL
9679 terminator to determine the number of entries. */
ba2685cc 9680 for (ext = edyn, dynamic_nent = 0;
53c3012c 9681 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
ba2685cc
AM
9682 ext++)
9683 {
9684 dynamic_nent++;
9685 if (BYTE_GET (ext->d_tag) == DT_NULL)
9686 break;
9687 }
252b5132 9688
3f5e193b
NC
9689 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9690 sizeof (* entry));
b2d38a17 9691 if (dynamic_section == NULL)
252b5132 9692 {
8b73c356
NC
9693 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9694 (unsigned long) dynamic_nent);
9ea033b2 9695 free (edyn);
32ec8896 9696 return FALSE;
9ea033b2 9697 }
252b5132 9698
fb514b26 9699 for (ext = edyn, entry = dynamic_section;
ba2685cc 9700 entry < dynamic_section + dynamic_nent;
fb514b26 9701 ext++, entry++)
9ea033b2 9702 {
fb514b26
AM
9703 entry->d_tag = BYTE_GET (ext->d_tag);
9704 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
252b5132
RH
9705 }
9706
9ea033b2
NC
9707 free (edyn);
9708
32ec8896 9709 return TRUE;
9ea033b2
NC
9710}
9711
32ec8896 9712static bfd_boolean
dda8d76d 9713get_64bit_dynamic_section (Filedata * filedata)
9ea033b2 9714{
2cf0635d
NC
9715 Elf64_External_Dyn * edyn;
9716 Elf64_External_Dyn * ext;
9717 Elf_Internal_Dyn * entry;
103f02d3 9718
071436c6 9719 /* Read in the data. */
dda8d76d 9720 edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
3f5e193b 9721 dynamic_size, _("dynamic section"));
a6e9f9df 9722 if (!edyn)
32ec8896 9723 return FALSE;
103f02d3 9724
071436c6
NC
9725 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9726 might not have the luxury of section headers. Look for the DT_NULL
9727 terminator to determine the number of entries. */
ba2685cc 9728 for (ext = edyn, dynamic_nent = 0;
53c3012c
AM
9729 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
9730 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
ba2685cc
AM
9731 ext++)
9732 {
9733 dynamic_nent++;
66543521 9734 if (BYTE_GET (ext->d_tag) == DT_NULL)
ba2685cc
AM
9735 break;
9736 }
252b5132 9737
3f5e193b
NC
9738 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9739 sizeof (* entry));
b2d38a17 9740 if (dynamic_section == NULL)
252b5132 9741 {
8b73c356
NC
9742 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9743 (unsigned long) dynamic_nent);
252b5132 9744 free (edyn);
32ec8896 9745 return FALSE;
252b5132
RH
9746 }
9747
071436c6 9748 /* Convert from external to internal formats. */
fb514b26 9749 for (ext = edyn, entry = dynamic_section;
ba2685cc 9750 entry < dynamic_section + dynamic_nent;
fb514b26 9751 ext++, entry++)
252b5132 9752 {
66543521
AM
9753 entry->d_tag = BYTE_GET (ext->d_tag);
9754 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
252b5132
RH
9755 }
9756
9757 free (edyn);
9758
32ec8896 9759 return TRUE;
9ea033b2
NC
9760}
9761
e9e44622
JJ
9762static void
9763print_dynamic_flags (bfd_vma flags)
d1133906 9764{
32ec8896 9765 bfd_boolean first = TRUE;
13ae64f3 9766
d1133906
NC
9767 while (flags)
9768 {
9769 bfd_vma flag;
9770
9771 flag = flags & - flags;
9772 flags &= ~ flag;
9773
e9e44622 9774 if (first)
32ec8896 9775 first = FALSE;
e9e44622
JJ
9776 else
9777 putc (' ', stdout);
13ae64f3 9778
d1133906
NC
9779 switch (flag)
9780 {
e9e44622
JJ
9781 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
9782 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
9783 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
9784 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
9785 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
2b692964 9786 default: fputs (_("unknown"), stdout); break;
d1133906
NC
9787 }
9788 }
e9e44622 9789 puts ("");
d1133906
NC
9790}
9791
b2d38a17
NC
9792/* Parse and display the contents of the dynamic section. */
9793
32ec8896 9794static bfd_boolean
dda8d76d 9795process_dynamic_section (Filedata * filedata)
9ea033b2 9796{
2cf0635d 9797 Elf_Internal_Dyn * entry;
9ea033b2
NC
9798
9799 if (dynamic_size == 0)
9800 {
9801 if (do_dynamic)
b2d38a17 9802 printf (_("\nThere is no dynamic section in this file.\n"));
9ea033b2 9803
32ec8896 9804 return TRUE;
9ea033b2
NC
9805 }
9806
9807 if (is_32bit_elf)
9808 {
dda8d76d 9809 if (! get_32bit_dynamic_section (filedata))
32ec8896
NC
9810 return FALSE;
9811 }
9812 else
9813 {
dda8d76d 9814 if (! get_64bit_dynamic_section (filedata))
32ec8896 9815 return FALSE;
9ea033b2 9816 }
9ea033b2 9817
252b5132
RH
9818 /* Find the appropriate symbol table. */
9819 if (dynamic_symbols == NULL)
9820 {
86dba8ee
AM
9821 for (entry = dynamic_section;
9822 entry < dynamic_section + dynamic_nent;
9823 ++entry)
252b5132 9824 {
c8286bd1 9825 Elf_Internal_Shdr section;
252b5132
RH
9826
9827 if (entry->d_tag != DT_SYMTAB)
9828 continue;
9829
9830 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
9831
9832 /* Since we do not know how big the symbol table is,
9833 we default to reading in the entire file (!) and
9834 processing that. This is overkill, I know, but it
e3c8793a 9835 should work. */
dda8d76d
NC
9836 section.sh_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
9837 if ((bfd_size_type) section.sh_offset > filedata->file_size)
7296a62a
NC
9838 {
9839 /* See PR 21379 for a reproducer. */
9840 error (_("Invalid DT_SYMTAB entry: %lx"), (long) section.sh_offset);
9841 return FALSE;
9842 }
252b5132 9843
fb52b2f4
NC
9844 if (archive_file_offset != 0)
9845 section.sh_size = archive_file_size - section.sh_offset;
9846 else
dda8d76d 9847 section.sh_size = filedata->file_size - section.sh_offset;
252b5132 9848
9ea033b2 9849 if (is_32bit_elf)
9ad5cbcf 9850 section.sh_entsize = sizeof (Elf32_External_Sym);
9ea033b2 9851 else
9ad5cbcf 9852 section.sh_entsize = sizeof (Elf64_External_Sym);
dda8d76d 9853 section.sh_name = filedata->string_table_length;
252b5132 9854
e3d39609
NC
9855 if (dynamic_symbols != NULL)
9856 {
9857 error (_("Multiple dynamic symbol table sections found\n"));
9858 free (dynamic_symbols);
9859 }
dda8d76d 9860 dynamic_symbols = GET_ELF_SYMBOLS (filedata, &section, & num_dynamic_syms);
19936277 9861 if (num_dynamic_syms < 1)
252b5132
RH
9862 {
9863 error (_("Unable to determine the number of symbols to load\n"));
9864 continue;
9865 }
252b5132
RH
9866 }
9867 }
9868
9869 /* Similarly find a string table. */
9870 if (dynamic_strings == NULL)
9871 {
86dba8ee
AM
9872 for (entry = dynamic_section;
9873 entry < dynamic_section + dynamic_nent;
9874 ++entry)
252b5132
RH
9875 {
9876 unsigned long offset;
b34976b6 9877 long str_tab_len;
252b5132
RH
9878
9879 if (entry->d_tag != DT_STRTAB)
9880 continue;
9881
9882 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
9883
9884 /* Since we do not know how big the string table is,
9885 we default to reading in the entire file (!) and
9886 processing that. This is overkill, I know, but it
e3c8793a 9887 should work. */
252b5132 9888
dda8d76d 9889 offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
fb52b2f4
NC
9890
9891 if (archive_file_offset != 0)
9892 str_tab_len = archive_file_size - offset;
9893 else
86c6c6df 9894 str_tab_len = filedata->file_size - offset;
252b5132
RH
9895
9896 if (str_tab_len < 1)
9897 {
9898 error
9899 (_("Unable to determine the length of the dynamic string table\n"));
9900 continue;
9901 }
9902
e3d39609
NC
9903 if (dynamic_strings != NULL)
9904 {
9905 error (_("Multiple dynamic string tables found\n"));
9906 free (dynamic_strings);
9907 }
9908
dda8d76d 9909 dynamic_strings = (char *) get_data (NULL, filedata, offset, 1,
3f5e193b
NC
9910 str_tab_len,
9911 _("dynamic string table"));
59245841 9912 dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
252b5132
RH
9913 }
9914 }
9915
9916 /* And find the syminfo section if available. */
9917 if (dynamic_syminfo == NULL)
9918 {
3e8bba36 9919 unsigned long syminsz = 0;
252b5132 9920
86dba8ee
AM
9921 for (entry = dynamic_section;
9922 entry < dynamic_section + dynamic_nent;
9923 ++entry)
252b5132
RH
9924 {
9925 if (entry->d_tag == DT_SYMINENT)
9926 {
9927 /* Note: these braces are necessary to avoid a syntax
9928 error from the SunOS4 C compiler. */
049b0c3a
NC
9929 /* PR binutils/17531: A corrupt file can trigger this test.
9930 So do not use an assert, instead generate an error message. */
9931 if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
071436c6 9932 error (_("Bad value (%d) for SYMINENT entry\n"),
049b0c3a 9933 (int) entry->d_un.d_val);
252b5132
RH
9934 }
9935 else if (entry->d_tag == DT_SYMINSZ)
9936 syminsz = entry->d_un.d_val;
9937 else if (entry->d_tag == DT_SYMINFO)
dda8d76d 9938 dynamic_syminfo_offset = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 9939 syminsz);
252b5132
RH
9940 }
9941
9942 if (dynamic_syminfo_offset != 0 && syminsz != 0)
9943 {
2cf0635d
NC
9944 Elf_External_Syminfo * extsyminfo;
9945 Elf_External_Syminfo * extsym;
9946 Elf_Internal_Syminfo * syminfo;
252b5132
RH
9947
9948 /* There is a syminfo section. Read the data. */
3f5e193b 9949 extsyminfo = (Elf_External_Syminfo *)
dda8d76d 9950 get_data (NULL, filedata, dynamic_syminfo_offset, 1, syminsz,
3f5e193b 9951 _("symbol information"));
a6e9f9df 9952 if (!extsyminfo)
32ec8896 9953 return FALSE;
252b5132 9954
e3d39609
NC
9955 if (dynamic_syminfo != NULL)
9956 {
9957 error (_("Multiple dynamic symbol information sections found\n"));
9958 free (dynamic_syminfo);
9959 }
3f5e193b 9960 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
252b5132
RH
9961 if (dynamic_syminfo == NULL)
9962 {
8b73c356
NC
9963 error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
9964 (unsigned long) syminsz);
32ec8896 9965 return FALSE;
252b5132
RH
9966 }
9967
9968 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
86dba8ee
AM
9969 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
9970 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
9971 ++syminfo, ++extsym)
252b5132 9972 {
86dba8ee
AM
9973 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
9974 syminfo->si_flags = BYTE_GET (extsym->si_flags);
252b5132
RH
9975 }
9976
9977 free (extsyminfo);
9978 }
9979 }
9980
9981 if (do_dynamic && dynamic_addr)
d3a49aa8
AM
9982 printf (ngettext ("\nDynamic section at offset 0x%lx "
9983 "contains %lu entry:\n",
9984 "\nDynamic section at offset 0x%lx "
9985 "contains %lu entries:\n",
9986 dynamic_nent),
8b73c356 9987 dynamic_addr, (unsigned long) dynamic_nent);
252b5132
RH
9988 if (do_dynamic)
9989 printf (_(" Tag Type Name/Value\n"));
9990
86dba8ee
AM
9991 for (entry = dynamic_section;
9992 entry < dynamic_section + dynamic_nent;
9993 entry++)
252b5132
RH
9994 {
9995 if (do_dynamic)
f7a99963 9996 {
2cf0635d 9997 const char * dtype;
e699b9ff 9998
f7a99963
NC
9999 putchar (' ');
10000 print_vma (entry->d_tag, FULL_HEX);
dda8d76d 10001 dtype = get_dynamic_type (filedata, entry->d_tag);
e699b9ff 10002 printf (" (%s)%*s", dtype,
32ec8896 10003 ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " ");
f7a99963 10004 }
252b5132
RH
10005
10006 switch (entry->d_tag)
10007 {
d1133906
NC
10008 case DT_FLAGS:
10009 if (do_dynamic)
e9e44622 10010 print_dynamic_flags (entry->d_un.d_val);
d1133906 10011 break;
76da6bbe 10012
252b5132
RH
10013 case DT_AUXILIARY:
10014 case DT_FILTER:
019148e4
L
10015 case DT_CONFIG:
10016 case DT_DEPAUDIT:
10017 case DT_AUDIT:
252b5132
RH
10018 if (do_dynamic)
10019 {
019148e4 10020 switch (entry->d_tag)
b34976b6 10021 {
019148e4
L
10022 case DT_AUXILIARY:
10023 printf (_("Auxiliary library"));
10024 break;
10025
10026 case DT_FILTER:
10027 printf (_("Filter library"));
10028 break;
10029
b34976b6 10030 case DT_CONFIG:
019148e4
L
10031 printf (_("Configuration file"));
10032 break;
10033
10034 case DT_DEPAUDIT:
10035 printf (_("Dependency audit library"));
10036 break;
10037
10038 case DT_AUDIT:
10039 printf (_("Audit library"));
10040 break;
10041 }
252b5132 10042
d79b3d50
NC
10043 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
10044 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
252b5132 10045 else
f7a99963
NC
10046 {
10047 printf (": ");
10048 print_vma (entry->d_un.d_val, PREFIX_HEX);
10049 putchar ('\n');
10050 }
252b5132
RH
10051 }
10052 break;
10053
dcefbbbd 10054 case DT_FEATURE:
252b5132
RH
10055 if (do_dynamic)
10056 {
10057 printf (_("Flags:"));
86f55779 10058
252b5132
RH
10059 if (entry->d_un.d_val == 0)
10060 printf (_(" None\n"));
10061 else
10062 {
10063 unsigned long int val = entry->d_un.d_val;
86f55779 10064
252b5132
RH
10065 if (val & DTF_1_PARINIT)
10066 {
10067 printf (" PARINIT");
10068 val ^= DTF_1_PARINIT;
10069 }
dcefbbbd
L
10070 if (val & DTF_1_CONFEXP)
10071 {
10072 printf (" CONFEXP");
10073 val ^= DTF_1_CONFEXP;
10074 }
252b5132
RH
10075 if (val != 0)
10076 printf (" %lx", val);
10077 puts ("");
10078 }
10079 }
10080 break;
10081
10082 case DT_POSFLAG_1:
10083 if (do_dynamic)
10084 {
10085 printf (_("Flags:"));
86f55779 10086
252b5132
RH
10087 if (entry->d_un.d_val == 0)
10088 printf (_(" None\n"));
10089 else
10090 {
10091 unsigned long int val = entry->d_un.d_val;
86f55779 10092
252b5132
RH
10093 if (val & DF_P1_LAZYLOAD)
10094 {
10095 printf (" LAZYLOAD");
10096 val ^= DF_P1_LAZYLOAD;
10097 }
10098 if (val & DF_P1_GROUPPERM)
10099 {
10100 printf (" GROUPPERM");
10101 val ^= DF_P1_GROUPPERM;
10102 }
10103 if (val != 0)
10104 printf (" %lx", val);
10105 puts ("");
10106 }
10107 }
10108 break;
10109
10110 case DT_FLAGS_1:
10111 if (do_dynamic)
10112 {
10113 printf (_("Flags:"));
10114 if (entry->d_un.d_val == 0)
10115 printf (_(" None\n"));
10116 else
10117 {
10118 unsigned long int val = entry->d_un.d_val;
86f55779 10119
252b5132
RH
10120 if (val & DF_1_NOW)
10121 {
10122 printf (" NOW");
10123 val ^= DF_1_NOW;
10124 }
10125 if (val & DF_1_GLOBAL)
10126 {
10127 printf (" GLOBAL");
10128 val ^= DF_1_GLOBAL;
10129 }
10130 if (val & DF_1_GROUP)
10131 {
10132 printf (" GROUP");
10133 val ^= DF_1_GROUP;
10134 }
10135 if (val & DF_1_NODELETE)
10136 {
10137 printf (" NODELETE");
10138 val ^= DF_1_NODELETE;
10139 }
10140 if (val & DF_1_LOADFLTR)
10141 {
10142 printf (" LOADFLTR");
10143 val ^= DF_1_LOADFLTR;
10144 }
10145 if (val & DF_1_INITFIRST)
10146 {
10147 printf (" INITFIRST");
10148 val ^= DF_1_INITFIRST;
10149 }
10150 if (val & DF_1_NOOPEN)
10151 {
10152 printf (" NOOPEN");
10153 val ^= DF_1_NOOPEN;
10154 }
10155 if (val & DF_1_ORIGIN)
10156 {
10157 printf (" ORIGIN");
10158 val ^= DF_1_ORIGIN;
10159 }
10160 if (val & DF_1_DIRECT)
10161 {
10162 printf (" DIRECT");
10163 val ^= DF_1_DIRECT;
10164 }
10165 if (val & DF_1_TRANS)
10166 {
10167 printf (" TRANS");
10168 val ^= DF_1_TRANS;
10169 }
10170 if (val & DF_1_INTERPOSE)
10171 {
10172 printf (" INTERPOSE");
10173 val ^= DF_1_INTERPOSE;
10174 }
f7db6139 10175 if (val & DF_1_NODEFLIB)
dcefbbbd 10176 {
f7db6139
L
10177 printf (" NODEFLIB");
10178 val ^= DF_1_NODEFLIB;
dcefbbbd
L
10179 }
10180 if (val & DF_1_NODUMP)
10181 {
10182 printf (" NODUMP");
10183 val ^= DF_1_NODUMP;
10184 }
34b60028 10185 if (val & DF_1_CONFALT)
dcefbbbd 10186 {
34b60028
L
10187 printf (" CONFALT");
10188 val ^= DF_1_CONFALT;
10189 }
10190 if (val & DF_1_ENDFILTEE)
10191 {
10192 printf (" ENDFILTEE");
10193 val ^= DF_1_ENDFILTEE;
10194 }
10195 if (val & DF_1_DISPRELDNE)
10196 {
10197 printf (" DISPRELDNE");
10198 val ^= DF_1_DISPRELDNE;
10199 }
10200 if (val & DF_1_DISPRELPND)
10201 {
10202 printf (" DISPRELPND");
10203 val ^= DF_1_DISPRELPND;
10204 }
10205 if (val & DF_1_NODIRECT)
10206 {
10207 printf (" NODIRECT");
10208 val ^= DF_1_NODIRECT;
10209 }
10210 if (val & DF_1_IGNMULDEF)
10211 {
10212 printf (" IGNMULDEF");
10213 val ^= DF_1_IGNMULDEF;
10214 }
10215 if (val & DF_1_NOKSYMS)
10216 {
10217 printf (" NOKSYMS");
10218 val ^= DF_1_NOKSYMS;
10219 }
10220 if (val & DF_1_NOHDR)
10221 {
10222 printf (" NOHDR");
10223 val ^= DF_1_NOHDR;
10224 }
10225 if (val & DF_1_EDITED)
10226 {
10227 printf (" EDITED");
10228 val ^= DF_1_EDITED;
10229 }
10230 if (val & DF_1_NORELOC)
10231 {
10232 printf (" NORELOC");
10233 val ^= DF_1_NORELOC;
10234 }
10235 if (val & DF_1_SYMINTPOSE)
10236 {
10237 printf (" SYMINTPOSE");
10238 val ^= DF_1_SYMINTPOSE;
10239 }
10240 if (val & DF_1_GLOBAUDIT)
10241 {
10242 printf (" GLOBAUDIT");
10243 val ^= DF_1_GLOBAUDIT;
10244 }
10245 if (val & DF_1_SINGLETON)
10246 {
10247 printf (" SINGLETON");
10248 val ^= DF_1_SINGLETON;
dcefbbbd 10249 }
5c383f02
RO
10250 if (val & DF_1_STUB)
10251 {
10252 printf (" STUB");
10253 val ^= DF_1_STUB;
10254 }
10255 if (val & DF_1_PIE)
10256 {
10257 printf (" PIE");
10258 val ^= DF_1_PIE;
10259 }
b1202ffa
L
10260 if (val & DF_1_KMOD)
10261 {
10262 printf (" KMOD");
10263 val ^= DF_1_KMOD;
10264 }
10265 if (val & DF_1_WEAKFILTER)
10266 {
10267 printf (" WEAKFILTER");
10268 val ^= DF_1_WEAKFILTER;
10269 }
10270 if (val & DF_1_NOCOMMON)
10271 {
10272 printf (" NOCOMMON");
10273 val ^= DF_1_NOCOMMON;
10274 }
252b5132
RH
10275 if (val != 0)
10276 printf (" %lx", val);
10277 puts ("");
10278 }
10279 }
10280 break;
10281
10282 case DT_PLTREL:
566b0d53 10283 dynamic_info[entry->d_tag] = entry->d_un.d_val;
252b5132 10284 if (do_dynamic)
dda8d76d 10285 puts (get_dynamic_type (filedata, entry->d_un.d_val));
252b5132
RH
10286 break;
10287
10288 case DT_NULL :
10289 case DT_NEEDED :
10290 case DT_PLTGOT :
10291 case DT_HASH :
10292 case DT_STRTAB :
10293 case DT_SYMTAB :
10294 case DT_RELA :
10295 case DT_INIT :
10296 case DT_FINI :
10297 case DT_SONAME :
10298 case DT_RPATH :
10299 case DT_SYMBOLIC:
10300 case DT_REL :
10301 case DT_DEBUG :
10302 case DT_TEXTREL :
10303 case DT_JMPREL :
019148e4 10304 case DT_RUNPATH :
252b5132
RH
10305 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10306
10307 if (do_dynamic)
10308 {
2cf0635d 10309 char * name;
252b5132 10310
d79b3d50
NC
10311 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
10312 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
252b5132 10313 else
d79b3d50 10314 name = NULL;
252b5132
RH
10315
10316 if (name)
10317 {
10318 switch (entry->d_tag)
10319 {
10320 case DT_NEEDED:
10321 printf (_("Shared library: [%s]"), name);
10322
18bd398b 10323 if (streq (name, program_interpreter))
f7a99963 10324 printf (_(" program interpreter"));
252b5132
RH
10325 break;
10326
10327 case DT_SONAME:
f7a99963 10328 printf (_("Library soname: [%s]"), name);
252b5132
RH
10329 break;
10330
10331 case DT_RPATH:
f7a99963 10332 printf (_("Library rpath: [%s]"), name);
252b5132
RH
10333 break;
10334
019148e4
L
10335 case DT_RUNPATH:
10336 printf (_("Library runpath: [%s]"), name);
10337 break;
10338
252b5132 10339 default:
f7a99963
NC
10340 print_vma (entry->d_un.d_val, PREFIX_HEX);
10341 break;
252b5132
RH
10342 }
10343 }
10344 else
f7a99963
NC
10345 print_vma (entry->d_un.d_val, PREFIX_HEX);
10346
10347 putchar ('\n');
252b5132
RH
10348 }
10349 break;
10350
10351 case DT_PLTRELSZ:
10352 case DT_RELASZ :
10353 case DT_STRSZ :
10354 case DT_RELSZ :
10355 case DT_RELAENT :
10356 case DT_SYMENT :
10357 case DT_RELENT :
566b0d53 10358 dynamic_info[entry->d_tag] = entry->d_un.d_val;
1a0670f3 10359 /* Fall through. */
252b5132
RH
10360 case DT_PLTPADSZ:
10361 case DT_MOVEENT :
10362 case DT_MOVESZ :
10363 case DT_INIT_ARRAYSZ:
10364 case DT_FINI_ARRAYSZ:
047b2264
JJ
10365 case DT_GNU_CONFLICTSZ:
10366 case DT_GNU_LIBLISTSZ:
252b5132 10367 if (do_dynamic)
f7a99963
NC
10368 {
10369 print_vma (entry->d_un.d_val, UNSIGNED);
2b692964 10370 printf (_(" (bytes)\n"));
f7a99963 10371 }
252b5132
RH
10372 break;
10373
10374 case DT_VERDEFNUM:
10375 case DT_VERNEEDNUM:
10376 case DT_RELACOUNT:
10377 case DT_RELCOUNT:
10378 if (do_dynamic)
f7a99963
NC
10379 {
10380 print_vma (entry->d_un.d_val, UNSIGNED);
10381 putchar ('\n');
10382 }
252b5132
RH
10383 break;
10384
10385 case DT_SYMINSZ:
10386 case DT_SYMINENT:
10387 case DT_SYMINFO:
10388 case DT_USED:
10389 case DT_INIT_ARRAY:
10390 case DT_FINI_ARRAY:
10391 if (do_dynamic)
10392 {
d79b3d50
NC
10393 if (entry->d_tag == DT_USED
10394 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
252b5132 10395 {
2cf0635d 10396 char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
252b5132 10397
b34976b6 10398 if (*name)
252b5132
RH
10399 {
10400 printf (_("Not needed object: [%s]\n"), name);
10401 break;
10402 }
10403 }
103f02d3 10404
f7a99963
NC
10405 print_vma (entry->d_un.d_val, PREFIX_HEX);
10406 putchar ('\n');
252b5132
RH
10407 }
10408 break;
10409
10410 case DT_BIND_NOW:
10411 /* The value of this entry is ignored. */
35b1837e
AM
10412 if (do_dynamic)
10413 putchar ('\n');
252b5132 10414 break;
103f02d3 10415
047b2264
JJ
10416 case DT_GNU_PRELINKED:
10417 if (do_dynamic)
10418 {
2cf0635d 10419 struct tm * tmp;
91d6fa6a 10420 time_t atime = entry->d_un.d_val;
047b2264 10421
91d6fa6a 10422 tmp = gmtime (&atime);
071436c6
NC
10423 /* PR 17533 file: 041-1244816-0.004. */
10424 if (tmp == NULL)
5a2cbcf4
L
10425 printf (_("<corrupt time val: %lx"),
10426 (unsigned long) atime);
071436c6
NC
10427 else
10428 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
10429 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
10430 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
047b2264
JJ
10431
10432 }
10433 break;
10434
fdc90cb4
JJ
10435 case DT_GNU_HASH:
10436 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
10437 if (do_dynamic)
10438 {
10439 print_vma (entry->d_un.d_val, PREFIX_HEX);
10440 putchar ('\n');
10441 }
10442 break;
10443
252b5132
RH
10444 default:
10445 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
b34976b6 10446 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
252b5132
RH
10447 entry->d_un.d_val;
10448
10449 if (do_dynamic)
10450 {
dda8d76d 10451 switch (filedata->file_header.e_machine)
252b5132 10452 {
37c18eed
SD
10453 case EM_AARCH64:
10454 dynamic_section_aarch64_val (entry);
10455 break;
252b5132 10456 case EM_MIPS:
4fe85591 10457 case EM_MIPS_RS3_LE:
b2d38a17 10458 dynamic_section_mips_val (entry);
252b5132 10459 break;
103f02d3 10460 case EM_PARISC:
b2d38a17 10461 dynamic_section_parisc_val (entry);
103f02d3 10462 break;
ecc51f48 10463 case EM_IA_64:
b2d38a17 10464 dynamic_section_ia64_val (entry);
ecc51f48 10465 break;
252b5132 10466 default:
f7a99963
NC
10467 print_vma (entry->d_un.d_val, PREFIX_HEX);
10468 putchar ('\n');
252b5132
RH
10469 }
10470 }
10471 break;
10472 }
10473 }
10474
32ec8896 10475 return TRUE;
252b5132
RH
10476}
10477
10478static char *
d3ba0551 10479get_ver_flags (unsigned int flags)
252b5132 10480{
6d4f21f6 10481 static char buff[128];
252b5132
RH
10482
10483 buff[0] = 0;
10484
10485 if (flags == 0)
10486 return _("none");
10487
10488 if (flags & VER_FLG_BASE)
7bb1ad17 10489 strcat (buff, "BASE");
252b5132
RH
10490
10491 if (flags & VER_FLG_WEAK)
10492 {
10493 if (flags & VER_FLG_BASE)
7bb1ad17 10494 strcat (buff, " | ");
252b5132 10495
7bb1ad17 10496 strcat (buff, "WEAK");
252b5132
RH
10497 }
10498
44ec90b9
RO
10499 if (flags & VER_FLG_INFO)
10500 {
10501 if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
7bb1ad17 10502 strcat (buff, " | ");
44ec90b9 10503
7bb1ad17 10504 strcat (buff, "INFO");
44ec90b9
RO
10505 }
10506
10507 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
7bb1ad17
MR
10508 {
10509 if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
10510 strcat (buff, " | ");
10511
10512 strcat (buff, _("<unknown>"));
10513 }
252b5132
RH
10514
10515 return buff;
10516}
10517
10518/* Display the contents of the version sections. */
98fb390a 10519
32ec8896 10520static bfd_boolean
dda8d76d 10521process_version_sections (Filedata * filedata)
252b5132 10522{
2cf0635d 10523 Elf_Internal_Shdr * section;
b34976b6 10524 unsigned i;
32ec8896 10525 bfd_boolean found = FALSE;
252b5132
RH
10526
10527 if (! do_version)
32ec8896 10528 return TRUE;
252b5132 10529
dda8d76d
NC
10530 for (i = 0, section = filedata->section_headers;
10531 i < filedata->file_header.e_shnum;
b34976b6 10532 i++, section++)
252b5132
RH
10533 {
10534 switch (section->sh_type)
10535 {
10536 case SHT_GNU_verdef:
10537 {
2cf0635d 10538 Elf_External_Verdef * edefs;
452bf675
AM
10539 unsigned long idx;
10540 unsigned long cnt;
2cf0635d 10541 char * endbuf;
252b5132 10542
32ec8896 10543 found = TRUE;
252b5132 10544
d3a49aa8
AM
10545 printf (ngettext ("\nVersion definition section '%s' "
10546 "contains %u entry:\n",
10547 "\nVersion definition section '%s' "
10548 "contains %u entries:\n",
10549 section->sh_info),
dda8d76d 10550 printable_section_name (filedata, section),
74e1a04b 10551 section->sh_info);
252b5132
RH
10552
10553 printf (_(" Addr: 0x"));
10554 printf_vma (section->sh_addr);
233f82cf 10555 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 10556 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 10557 printable_section_name_from_index (filedata, section->sh_link));
252b5132 10558
3f5e193b 10559 edefs = (Elf_External_Verdef *)
dda8d76d 10560 get_data (NULL, filedata, section->sh_offset, 1,section->sh_size,
3f5e193b 10561 _("version definition section"));
a6e9f9df
AM
10562 if (!edefs)
10563 break;
59245841 10564 endbuf = (char *) edefs + section->sh_size;
252b5132 10565
1445030f 10566 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
252b5132 10567 {
2cf0635d
NC
10568 char * vstart;
10569 Elf_External_Verdef * edef;
b34976b6 10570 Elf_Internal_Verdef ent;
2cf0635d 10571 Elf_External_Verdaux * eaux;
b34976b6 10572 Elf_Internal_Verdaux aux;
452bf675 10573 unsigned long isum;
b34976b6 10574 int j;
103f02d3 10575
252b5132 10576 vstart = ((char *) edefs) + idx;
54806181
AM
10577 if (vstart + sizeof (*edef) > endbuf)
10578 break;
252b5132
RH
10579
10580 edef = (Elf_External_Verdef *) vstart;
10581
10582 ent.vd_version = BYTE_GET (edef->vd_version);
10583 ent.vd_flags = BYTE_GET (edef->vd_flags);
10584 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
10585 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
10586 ent.vd_hash = BYTE_GET (edef->vd_hash);
10587 ent.vd_aux = BYTE_GET (edef->vd_aux);
10588 ent.vd_next = BYTE_GET (edef->vd_next);
10589
452bf675 10590 printf (_(" %#06lx: Rev: %d Flags: %s"),
252b5132
RH
10591 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
10592
10593 printf (_(" Index: %d Cnt: %d "),
10594 ent.vd_ndx, ent.vd_cnt);
10595
452bf675 10596 /* Check for overflow. */
1445030f 10597 if (ent.vd_aux > (size_t) (endbuf - vstart))
dd24e3da
NC
10598 break;
10599
252b5132
RH
10600 vstart += ent.vd_aux;
10601
1445030f
AM
10602 if (vstart + sizeof (*eaux) > endbuf)
10603 break;
252b5132
RH
10604 eaux = (Elf_External_Verdaux *) vstart;
10605
10606 aux.vda_name = BYTE_GET (eaux->vda_name);
10607 aux.vda_next = BYTE_GET (eaux->vda_next);
10608
d79b3d50
NC
10609 if (VALID_DYNAMIC_NAME (aux.vda_name))
10610 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
252b5132
RH
10611 else
10612 printf (_("Name index: %ld\n"), aux.vda_name);
10613
10614 isum = idx + ent.vd_aux;
10615
b34976b6 10616 for (j = 1; j < ent.vd_cnt; j++)
252b5132 10617 {
1445030f
AM
10618 if (aux.vda_next < sizeof (*eaux)
10619 && !(j == ent.vd_cnt - 1 && aux.vda_next == 0))
10620 {
10621 warn (_("Invalid vda_next field of %lx\n"),
10622 aux.vda_next);
10623 j = ent.vd_cnt;
10624 break;
10625 }
dd24e3da 10626 /* Check for overflow. */
7e26601c 10627 if (aux.vda_next > (size_t) (endbuf - vstart))
dd24e3da
NC
10628 break;
10629
252b5132
RH
10630 isum += aux.vda_next;
10631 vstart += aux.vda_next;
10632
54806181
AM
10633 if (vstart + sizeof (*eaux) > endbuf)
10634 break;
1445030f 10635 eaux = (Elf_External_Verdaux *) vstart;
252b5132
RH
10636
10637 aux.vda_name = BYTE_GET (eaux->vda_name);
10638 aux.vda_next = BYTE_GET (eaux->vda_next);
10639
d79b3d50 10640 if (VALID_DYNAMIC_NAME (aux.vda_name))
452bf675 10641 printf (_(" %#06lx: Parent %d: %s\n"),
d79b3d50 10642 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
252b5132 10643 else
452bf675 10644 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
252b5132
RH
10645 isum, j, aux.vda_name);
10646 }
dd24e3da 10647
54806181
AM
10648 if (j < ent.vd_cnt)
10649 printf (_(" Version def aux past end of section\n"));
252b5132 10650
c9f02c3e
MR
10651 /* PR 17531:
10652 file: id:000001,src:000172+005151,op:splice,rep:2. */
1445030f
AM
10653 if (ent.vd_next < sizeof (*edef)
10654 && !(cnt == section->sh_info - 1 && ent.vd_next == 0))
10655 {
10656 warn (_("Invalid vd_next field of %lx\n"), ent.vd_next);
10657 cnt = section->sh_info;
10658 break;
10659 }
452bf675 10660 if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx)))
5d921cbd
NC
10661 break;
10662
252b5132
RH
10663 idx += ent.vd_next;
10664 }
dd24e3da 10665
54806181
AM
10666 if (cnt < section->sh_info)
10667 printf (_(" Version definition past end of section\n"));
252b5132
RH
10668
10669 free (edefs);
10670 }
10671 break;
103f02d3 10672
252b5132
RH
10673 case SHT_GNU_verneed:
10674 {
2cf0635d 10675 Elf_External_Verneed * eneed;
452bf675
AM
10676 unsigned long idx;
10677 unsigned long cnt;
2cf0635d 10678 char * endbuf;
252b5132 10679
32ec8896 10680 found = TRUE;
252b5132 10681
d3a49aa8
AM
10682 printf (ngettext ("\nVersion needs section '%s' "
10683 "contains %u entry:\n",
10684 "\nVersion needs section '%s' "
10685 "contains %u entries:\n",
10686 section->sh_info),
dda8d76d 10687 printable_section_name (filedata, section), section->sh_info);
252b5132
RH
10688
10689 printf (_(" Addr: 0x"));
10690 printf_vma (section->sh_addr);
72de5009 10691 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 10692 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 10693 printable_section_name_from_index (filedata, section->sh_link));
252b5132 10694
dda8d76d 10695 eneed = (Elf_External_Verneed *) get_data (NULL, filedata,
3f5e193b
NC
10696 section->sh_offset, 1,
10697 section->sh_size,
9cf03b7e 10698 _("Version Needs section"));
a6e9f9df
AM
10699 if (!eneed)
10700 break;
59245841 10701 endbuf = (char *) eneed + section->sh_size;
252b5132
RH
10702
10703 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
10704 {
2cf0635d 10705 Elf_External_Verneed * entry;
b34976b6 10706 Elf_Internal_Verneed ent;
452bf675 10707 unsigned long isum;
b34976b6 10708 int j;
2cf0635d 10709 char * vstart;
252b5132
RH
10710
10711 vstart = ((char *) eneed) + idx;
54806181
AM
10712 if (vstart + sizeof (*entry) > endbuf)
10713 break;
252b5132
RH
10714
10715 entry = (Elf_External_Verneed *) vstart;
10716
10717 ent.vn_version = BYTE_GET (entry->vn_version);
10718 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
10719 ent.vn_file = BYTE_GET (entry->vn_file);
10720 ent.vn_aux = BYTE_GET (entry->vn_aux);
10721 ent.vn_next = BYTE_GET (entry->vn_next);
10722
452bf675 10723 printf (_(" %#06lx: Version: %d"), idx, ent.vn_version);
252b5132 10724
d79b3d50
NC
10725 if (VALID_DYNAMIC_NAME (ent.vn_file))
10726 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
252b5132
RH
10727 else
10728 printf (_(" File: %lx"), ent.vn_file);
10729
10730 printf (_(" Cnt: %d\n"), ent.vn_cnt);
10731
dd24e3da 10732 /* Check for overflow. */
7e26601c 10733 if (ent.vn_aux > (size_t) (endbuf - vstart))
dd24e3da 10734 break;
252b5132
RH
10735 vstart += ent.vn_aux;
10736
10737 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
10738 {
2cf0635d 10739 Elf_External_Vernaux * eaux;
b34976b6 10740 Elf_Internal_Vernaux aux;
252b5132 10741
54806181
AM
10742 if (vstart + sizeof (*eaux) > endbuf)
10743 break;
252b5132
RH
10744 eaux = (Elf_External_Vernaux *) vstart;
10745
10746 aux.vna_hash = BYTE_GET (eaux->vna_hash);
10747 aux.vna_flags = BYTE_GET (eaux->vna_flags);
10748 aux.vna_other = BYTE_GET (eaux->vna_other);
10749 aux.vna_name = BYTE_GET (eaux->vna_name);
10750 aux.vna_next = BYTE_GET (eaux->vna_next);
10751
d79b3d50 10752 if (VALID_DYNAMIC_NAME (aux.vna_name))
452bf675 10753 printf (_(" %#06lx: Name: %s"),
d79b3d50 10754 isum, GET_DYNAMIC_NAME (aux.vna_name));
252b5132 10755 else
452bf675 10756 printf (_(" %#06lx: Name index: %lx"),
252b5132
RH
10757 isum, aux.vna_name);
10758
10759 printf (_(" Flags: %s Version: %d\n"),
10760 get_ver_flags (aux.vna_flags), aux.vna_other);
10761
1445030f
AM
10762 if (aux.vna_next < sizeof (*eaux)
10763 && !(j == ent.vn_cnt - 1 && aux.vna_next == 0))
53774b7e
NC
10764 {
10765 warn (_("Invalid vna_next field of %lx\n"),
10766 aux.vna_next);
10767 j = ent.vn_cnt;
10768 break;
10769 }
1445030f
AM
10770 /* Check for overflow. */
10771 if (aux.vna_next > (size_t) (endbuf - vstart))
10772 break;
252b5132
RH
10773 isum += aux.vna_next;
10774 vstart += aux.vna_next;
10775 }
9cf03b7e 10776
54806181 10777 if (j < ent.vn_cnt)
9cf03b7e 10778 warn (_("Missing Version Needs auxillary information\n"));
252b5132 10779
1445030f
AM
10780 if (ent.vn_next < sizeof (*entry)
10781 && !(cnt == section->sh_info - 1 && ent.vn_next == 0))
c24cf8b6 10782 {
452bf675 10783 warn (_("Invalid vn_next field of %lx\n"), ent.vn_next);
c24cf8b6
NC
10784 cnt = section->sh_info;
10785 break;
10786 }
1445030f
AM
10787 if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx)))
10788 break;
252b5132
RH
10789 idx += ent.vn_next;
10790 }
9cf03b7e 10791
54806181 10792 if (cnt < section->sh_info)
9cf03b7e 10793 warn (_("Missing Version Needs information\n"));
103f02d3 10794
252b5132
RH
10795 free (eneed);
10796 }
10797 break;
10798
10799 case SHT_GNU_versym:
10800 {
2cf0635d 10801 Elf_Internal_Shdr * link_section;
8b73c356
NC
10802 size_t total;
10803 unsigned int cnt;
2cf0635d
NC
10804 unsigned char * edata;
10805 unsigned short * data;
10806 char * strtab;
10807 Elf_Internal_Sym * symbols;
10808 Elf_Internal_Shdr * string_sec;
ba5cdace 10809 unsigned long num_syms;
d3ba0551 10810 long off;
252b5132 10811
dda8d76d 10812 if (section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
10813 break;
10814
dda8d76d 10815 link_section = filedata->section_headers + section->sh_link;
08d8fa11 10816 total = section->sh_size / sizeof (Elf_External_Versym);
252b5132 10817
dda8d76d 10818 if (link_section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
10819 break;
10820
32ec8896 10821 found = TRUE;
252b5132 10822
dda8d76d 10823 symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms);
dd24e3da
NC
10824 if (symbols == NULL)
10825 break;
252b5132 10826
dda8d76d 10827 string_sec = filedata->section_headers + link_section->sh_link;
252b5132 10828
dda8d76d 10829 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
3f5e193b
NC
10830 string_sec->sh_size,
10831 _("version string table"));
a6e9f9df 10832 if (!strtab)
0429c154
MS
10833 {
10834 free (symbols);
10835 break;
10836 }
252b5132 10837
d3a49aa8
AM
10838 printf (ngettext ("\nVersion symbols section '%s' "
10839 "contains %lu entry:\n",
10840 "\nVersion symbols section '%s' "
10841 "contains %lu entries:\n",
10842 total),
dda8d76d 10843 printable_section_name (filedata, section), (unsigned long) total);
252b5132
RH
10844
10845 printf (_(" Addr: "));
10846 printf_vma (section->sh_addr);
72de5009 10847 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 10848 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 10849 printable_section_name (filedata, link_section));
252b5132 10850
dda8d76d 10851 off = offset_from_vma (filedata,
d3ba0551
AM
10852 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
10853 total * sizeof (short));
dda8d76d 10854 edata = (unsigned char *) get_data (NULL, filedata, off, total,
3f5e193b
NC
10855 sizeof (short),
10856 _("version symbol data"));
a6e9f9df
AM
10857 if (!edata)
10858 {
10859 free (strtab);
0429c154 10860 free (symbols);
a6e9f9df
AM
10861 break;
10862 }
252b5132 10863
3f5e193b 10864 data = (short unsigned int *) cmalloc (total, sizeof (short));
252b5132
RH
10865
10866 for (cnt = total; cnt --;)
b34976b6
AM
10867 data[cnt] = byte_get (edata + cnt * sizeof (short),
10868 sizeof (short));
252b5132
RH
10869
10870 free (edata);
10871
10872 for (cnt = 0; cnt < total; cnt += 4)
10873 {
10874 int j, nn;
ab273396
AM
10875 char *name;
10876 char *invalid = _("*invalid*");
252b5132
RH
10877
10878 printf (" %03x:", cnt);
10879
10880 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
b34976b6 10881 switch (data[cnt + j])
252b5132
RH
10882 {
10883 case 0:
10884 fputs (_(" 0 (*local*) "), stdout);
10885 break;
10886
10887 case 1:
10888 fputs (_(" 1 (*global*) "), stdout);
10889 break;
10890
10891 default:
c244d050
NC
10892 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
10893 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
252b5132 10894
dd24e3da 10895 /* If this index value is greater than the size of the symbols
ba5cdace
NC
10896 array, break to avoid an out-of-bounds read. */
10897 if ((unsigned long)(cnt + j) >= num_syms)
dd24e3da
NC
10898 {
10899 warn (_("invalid index into symbol array\n"));
10900 break;
10901 }
10902
ab273396
AM
10903 name = NULL;
10904 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
252b5132 10905 {
b34976b6
AM
10906 Elf_Internal_Verneed ivn;
10907 unsigned long offset;
252b5132 10908
d93f0186 10909 offset = offset_from_vma
dda8d76d 10910 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
d93f0186 10911 sizeof (Elf_External_Verneed));
252b5132 10912
b34976b6 10913 do
252b5132 10914 {
b34976b6
AM
10915 Elf_Internal_Vernaux ivna;
10916 Elf_External_Verneed evn;
10917 Elf_External_Vernaux evna;
10918 unsigned long a_off;
252b5132 10919
dda8d76d 10920 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
59245841
NC
10921 _("version need")) == NULL)
10922 break;
0b4362b0 10923
252b5132
RH
10924 ivn.vn_aux = BYTE_GET (evn.vn_aux);
10925 ivn.vn_next = BYTE_GET (evn.vn_next);
10926
10927 a_off = offset + ivn.vn_aux;
10928
10929 do
10930 {
dda8d76d 10931 if (get_data (&evna, filedata, a_off, sizeof (evna),
59245841
NC
10932 1, _("version need aux (2)")) == NULL)
10933 {
10934 ivna.vna_next = 0;
10935 ivna.vna_other = 0;
10936 }
10937 else
10938 {
10939 ivna.vna_next = BYTE_GET (evna.vna_next);
10940 ivna.vna_other = BYTE_GET (evna.vna_other);
10941 }
252b5132
RH
10942
10943 a_off += ivna.vna_next;
10944 }
b34976b6 10945 while (ivna.vna_other != data[cnt + j]
252b5132
RH
10946 && ivna.vna_next != 0);
10947
b34976b6 10948 if (ivna.vna_other == data[cnt + j])
252b5132
RH
10949 {
10950 ivna.vna_name = BYTE_GET (evna.vna_name);
10951
54806181 10952 if (ivna.vna_name >= string_sec->sh_size)
ab273396 10953 name = invalid;
54806181
AM
10954 else
10955 name = strtab + ivna.vna_name;
252b5132
RH
10956 break;
10957 }
10958
10959 offset += ivn.vn_next;
10960 }
10961 while (ivn.vn_next);
10962 }
00d93f34 10963
ab273396 10964 if (data[cnt + j] != 0x8001
b34976b6 10965 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
252b5132 10966 {
b34976b6
AM
10967 Elf_Internal_Verdef ivd;
10968 Elf_External_Verdef evd;
10969 unsigned long offset;
252b5132 10970
d93f0186 10971 offset = offset_from_vma
dda8d76d 10972 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
d93f0186 10973 sizeof evd);
252b5132
RH
10974
10975 do
10976 {
dda8d76d 10977 if (get_data (&evd, filedata, offset, sizeof (evd), 1,
59245841
NC
10978 _("version def")) == NULL)
10979 {
10980 ivd.vd_next = 0;
948f632f 10981 /* PR 17531: file: 046-1082287-0.004. */
3102e897
NC
10982 ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
10983 break;
59245841
NC
10984 }
10985 else
10986 {
10987 ivd.vd_next = BYTE_GET (evd.vd_next);
10988 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
10989 }
252b5132
RH
10990
10991 offset += ivd.vd_next;
10992 }
c244d050 10993 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
252b5132
RH
10994 && ivd.vd_next != 0);
10995
c244d050 10996 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
252b5132 10997 {
b34976b6
AM
10998 Elf_External_Verdaux evda;
10999 Elf_Internal_Verdaux ivda;
252b5132
RH
11000
11001 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11002
dda8d76d 11003 if (get_data (&evda, filedata,
59245841
NC
11004 offset - ivd.vd_next + ivd.vd_aux,
11005 sizeof (evda), 1,
11006 _("version def aux")) == NULL)
11007 break;
252b5132
RH
11008
11009 ivda.vda_name = BYTE_GET (evda.vda_name);
11010
54806181 11011 if (ivda.vda_name >= string_sec->sh_size)
ab273396
AM
11012 name = invalid;
11013 else if (name != NULL && name != invalid)
11014 name = _("*both*");
54806181
AM
11015 else
11016 name = strtab + ivda.vda_name;
252b5132
RH
11017 }
11018 }
ab273396
AM
11019 if (name != NULL)
11020 nn += printf ("(%s%-*s",
11021 name,
11022 12 - (int) strlen (name),
11023 ")");
252b5132
RH
11024
11025 if (nn < 18)
11026 printf ("%*c", 18 - nn, ' ');
11027 }
11028
11029 putchar ('\n');
11030 }
11031
11032 free (data);
11033 free (strtab);
11034 free (symbols);
11035 }
11036 break;
103f02d3 11037
252b5132
RH
11038 default:
11039 break;
11040 }
11041 }
11042
11043 if (! found)
11044 printf (_("\nNo version information found in this file.\n"));
11045
32ec8896 11046 return TRUE;
252b5132
RH
11047}
11048
d1133906 11049static const char *
dda8d76d 11050get_symbol_binding (Filedata * filedata, unsigned int binding)
252b5132 11051{
b34976b6 11052 static char buff[32];
252b5132
RH
11053
11054 switch (binding)
11055 {
b34976b6
AM
11056 case STB_LOCAL: return "LOCAL";
11057 case STB_GLOBAL: return "GLOBAL";
11058 case STB_WEAK: return "WEAK";
252b5132
RH
11059 default:
11060 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
e9e44622
JJ
11061 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
11062 binding);
252b5132 11063 else if (binding >= STB_LOOS && binding <= STB_HIOS)
3e7a7d11
NC
11064 {
11065 if (binding == STB_GNU_UNIQUE
dda8d76d 11066 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
9c55345c 11067 /* GNU is still using the default value 0. */
dda8d76d 11068 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
3e7a7d11
NC
11069 return "UNIQUE";
11070 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
11071 }
252b5132 11072 else
e9e44622 11073 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
252b5132
RH
11074 return buff;
11075 }
11076}
11077
d1133906 11078static const char *
dda8d76d 11079get_symbol_type (Filedata * filedata, unsigned int type)
252b5132 11080{
b34976b6 11081 static char buff[32];
252b5132
RH
11082
11083 switch (type)
11084 {
b34976b6
AM
11085 case STT_NOTYPE: return "NOTYPE";
11086 case STT_OBJECT: return "OBJECT";
11087 case STT_FUNC: return "FUNC";
11088 case STT_SECTION: return "SECTION";
11089 case STT_FILE: return "FILE";
11090 case STT_COMMON: return "COMMON";
11091 case STT_TLS: return "TLS";
15ab5209
DB
11092 case STT_RELC: return "RELC";
11093 case STT_SRELC: return "SRELC";
252b5132
RH
11094 default:
11095 if (type >= STT_LOPROC && type <= STT_HIPROC)
df75f1af 11096 {
dda8d76d 11097 if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
3510a7b8 11098 return "THUMB_FUNC";
103f02d3 11099
dda8d76d 11100 if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
103f02d3
UD
11101 return "REGISTER";
11102
dda8d76d 11103 if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
103f02d3
UD
11104 return "PARISC_MILLI";
11105
e9e44622 11106 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
df75f1af 11107 }
252b5132 11108 else if (type >= STT_LOOS && type <= STT_HIOS)
103f02d3 11109 {
dda8d76d 11110 if (filedata->file_header.e_machine == EM_PARISC)
103f02d3
UD
11111 {
11112 if (type == STT_HP_OPAQUE)
11113 return "HP_OPAQUE";
11114 if (type == STT_HP_STUB)
11115 return "HP_STUB";
11116 }
11117
d8045f23 11118 if (type == STT_GNU_IFUNC
dda8d76d
NC
11119 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
11120 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD
9c55345c 11121 /* GNU is still using the default value 0. */
dda8d76d 11122 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
d8045f23
NC
11123 return "IFUNC";
11124
e9e44622 11125 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
103f02d3 11126 }
252b5132 11127 else
e9e44622 11128 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
252b5132
RH
11129 return buff;
11130 }
11131}
11132
d1133906 11133static const char *
d3ba0551 11134get_symbol_visibility (unsigned int visibility)
d1133906
NC
11135{
11136 switch (visibility)
11137 {
b34976b6
AM
11138 case STV_DEFAULT: return "DEFAULT";
11139 case STV_INTERNAL: return "INTERNAL";
11140 case STV_HIDDEN: return "HIDDEN";
d1133906 11141 case STV_PROTECTED: return "PROTECTED";
bee0ee85
NC
11142 default:
11143 error (_("Unrecognized visibility value: %u"), visibility);
11144 return _("<unknown>");
d1133906
NC
11145 }
11146}
11147
fd85a6a1
NC
11148static const char *
11149get_solaris_symbol_visibility (unsigned int visibility)
11150{
11151 switch (visibility)
11152 {
11153 case 4: return "EXPORTED";
11154 case 5: return "SINGLETON";
11155 case 6: return "ELIMINATE";
11156 default: return get_symbol_visibility (visibility);
11157 }
11158}
11159
2301ed1c
SN
11160static const char *
11161get_aarch64_symbol_other (unsigned int other)
11162{
11163 static char buf[32];
11164
11165 if (other & STO_AARCH64_VARIANT_PCS)
11166 {
11167 other &= ~STO_AARCH64_VARIANT_PCS;
11168 if (other == 0)
11169 return "VARIANT_PCS";
11170 snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other);
11171 return buf;
11172 }
11173 return NULL;
11174}
11175
5e2b0d47
NC
11176static const char *
11177get_mips_symbol_other (unsigned int other)
11178{
11179 switch (other)
11180 {
32ec8896
NC
11181 case STO_OPTIONAL: return "OPTIONAL";
11182 case STO_MIPS_PLT: return "MIPS PLT";
11183 case STO_MIPS_PIC: return "MIPS PIC";
11184 case STO_MICROMIPS: return "MICROMIPS";
11185 case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC";
11186 case STO_MIPS16: return "MIPS16";
11187 default: return NULL;
5e2b0d47
NC
11188 }
11189}
11190
28f997cf 11191static const char *
dda8d76d 11192get_ia64_symbol_other (Filedata * filedata, unsigned int other)
28f997cf 11193{
dda8d76d 11194 if (is_ia64_vms (filedata))
28f997cf
TG
11195 {
11196 static char res[32];
11197
11198 res[0] = 0;
11199
11200 /* Function types is for images and .STB files only. */
dda8d76d 11201 switch (filedata->file_header.e_type)
28f997cf
TG
11202 {
11203 case ET_DYN:
11204 case ET_EXEC:
11205 switch (VMS_ST_FUNC_TYPE (other))
11206 {
11207 case VMS_SFT_CODE_ADDR:
11208 strcat (res, " CA");
11209 break;
11210 case VMS_SFT_SYMV_IDX:
11211 strcat (res, " VEC");
11212 break;
11213 case VMS_SFT_FD:
11214 strcat (res, " FD");
11215 break;
11216 case VMS_SFT_RESERVE:
11217 strcat (res, " RSV");
11218 break;
11219 default:
bee0ee85
NC
11220 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
11221 VMS_ST_FUNC_TYPE (other));
11222 strcat (res, " <unknown>");
11223 break;
28f997cf
TG
11224 }
11225 break;
11226 default:
11227 break;
11228 }
11229 switch (VMS_ST_LINKAGE (other))
11230 {
11231 case VMS_STL_IGNORE:
11232 strcat (res, " IGN");
11233 break;
11234 case VMS_STL_RESERVE:
11235 strcat (res, " RSV");
11236 break;
11237 case VMS_STL_STD:
11238 strcat (res, " STD");
11239 break;
11240 case VMS_STL_LNK:
11241 strcat (res, " LNK");
11242 break;
11243 default:
bee0ee85
NC
11244 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
11245 VMS_ST_LINKAGE (other));
11246 strcat (res, " <unknown>");
11247 break;
28f997cf
TG
11248 }
11249
11250 if (res[0] != 0)
11251 return res + 1;
11252 else
11253 return res;
11254 }
11255 return NULL;
11256}
11257
6911b7dc
AM
11258static const char *
11259get_ppc64_symbol_other (unsigned int other)
11260{
14732552
AM
11261 if ((other & ~STO_PPC64_LOCAL_MASK) != 0)
11262 return NULL;
11263
11264 other >>= STO_PPC64_LOCAL_BIT;
11265 if (other <= 6)
6911b7dc
AM
11266 {
11267 static char buf[32];
14732552
AM
11268 if (other >= 2)
11269 other = ppc64_decode_local_entry (other);
11270 snprintf (buf, sizeof buf, _("<localentry>: %d"), other);
6911b7dc
AM
11271 return buf;
11272 }
11273 return NULL;
11274}
11275
5e2b0d47 11276static const char *
dda8d76d 11277get_symbol_other (Filedata * filedata, unsigned int other)
5e2b0d47
NC
11278{
11279 const char * result = NULL;
11280 static char buff [32];
11281
11282 if (other == 0)
11283 return "";
11284
dda8d76d 11285 switch (filedata->file_header.e_machine)
5e2b0d47 11286 {
2301ed1c
SN
11287 case EM_AARCH64:
11288 result = get_aarch64_symbol_other (other);
11289 break;
5e2b0d47
NC
11290 case EM_MIPS:
11291 result = get_mips_symbol_other (other);
28f997cf
TG
11292 break;
11293 case EM_IA_64:
dda8d76d 11294 result = get_ia64_symbol_other (filedata, other);
28f997cf 11295 break;
6911b7dc
AM
11296 case EM_PPC64:
11297 result = get_ppc64_symbol_other (other);
11298 break;
5e2b0d47 11299 default:
fd85a6a1 11300 result = NULL;
5e2b0d47
NC
11301 break;
11302 }
11303
11304 if (result)
11305 return result;
11306
11307 snprintf (buff, sizeof buff, _("<other>: %x"), other);
11308 return buff;
11309}
11310
d1133906 11311static const char *
dda8d76d 11312get_symbol_index_type (Filedata * filedata, unsigned int type)
252b5132 11313{
b34976b6 11314 static char buff[32];
5cf1065c 11315
252b5132
RH
11316 switch (type)
11317 {
b34976b6
AM
11318 case SHN_UNDEF: return "UND";
11319 case SHN_ABS: return "ABS";
11320 case SHN_COMMON: return "COM";
252b5132 11321 default:
9ce701e2 11322 if (type == SHN_IA_64_ANSI_COMMON
dda8d76d
NC
11323 && filedata->file_header.e_machine == EM_IA_64
11324 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
9ce701e2 11325 return "ANSI_COM";
dda8d76d
NC
11326 else if ((filedata->file_header.e_machine == EM_X86_64
11327 || filedata->file_header.e_machine == EM_L1OM
11328 || filedata->file_header.e_machine == EM_K1OM)
3b22753a
L
11329 && type == SHN_X86_64_LCOMMON)
11330 return "LARGE_COM";
ac145307 11331 else if ((type == SHN_MIPS_SCOMMON
dda8d76d 11332 && filedata->file_header.e_machine == EM_MIPS)
ac145307 11333 || (type == SHN_TIC6X_SCOMMON
dda8d76d 11334 && filedata->file_header.e_machine == EM_TI_C6000))
172553c7
TS
11335 return "SCOM";
11336 else if (type == SHN_MIPS_SUNDEFINED
dda8d76d 11337 && filedata->file_header.e_machine == EM_MIPS)
172553c7 11338 return "SUND";
9ce701e2 11339 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4fbb74a6 11340 sprintf (buff, "PRC[0x%04x]", type & 0xffff);
252b5132 11341 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4fbb74a6
AM
11342 sprintf (buff, "OS [0x%04x]", type & 0xffff);
11343 else if (type >= SHN_LORESERVE)
11344 sprintf (buff, "RSV[0x%04x]", type & 0xffff);
dda8d76d 11345 else if (type >= filedata->file_header.e_shnum)
e0a31db1 11346 sprintf (buff, _("bad section index[%3d]"), type);
252b5132 11347 else
232e7cb8 11348 sprintf (buff, "%3d", type);
5cf1065c 11349 break;
252b5132 11350 }
5cf1065c
NC
11351
11352 return buff;
252b5132
RH
11353}
11354
66543521 11355static bfd_vma *
dda8d76d 11356get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size)
252b5132 11357{
2cf0635d
NC
11358 unsigned char * e_data;
11359 bfd_vma * i_data;
252b5132 11360
57028622
NC
11361 /* If the size_t type is smaller than the bfd_size_type, eg because
11362 you are building a 32-bit tool on a 64-bit host, then make sure
11363 that when (number) is cast to (size_t) no information is lost. */
11364 if (sizeof (size_t) < sizeof (bfd_size_type)
11365 && (bfd_size_type) ((size_t) number) != number)
11366 {
66cfc0fd
AM
11367 error (_("Size truncation prevents reading %s elements of size %u\n"),
11368 bfd_vmatoa ("u", number), ent_size);
57028622
NC
11369 return NULL;
11370 }
948f632f 11371
3102e897
NC
11372 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
11373 attempting to allocate memory when the read is bound to fail. */
dda8d76d 11374 if (ent_size * number > filedata->file_size)
3102e897 11375 {
66cfc0fd
AM
11376 error (_("Invalid number of dynamic entries: %s\n"),
11377 bfd_vmatoa ("u", number));
3102e897
NC
11378 return NULL;
11379 }
11380
57028622 11381 e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
252b5132
RH
11382 if (e_data == NULL)
11383 {
66cfc0fd
AM
11384 error (_("Out of memory reading %s dynamic entries\n"),
11385 bfd_vmatoa ("u", number));
252b5132
RH
11386 return NULL;
11387 }
11388
dda8d76d 11389 if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number)
252b5132 11390 {
66cfc0fd
AM
11391 error (_("Unable to read in %s bytes of dynamic data\n"),
11392 bfd_vmatoa ("u", number * ent_size));
3102e897 11393 free (e_data);
252b5132
RH
11394 return NULL;
11395 }
11396
57028622 11397 i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
252b5132
RH
11398 if (i_data == NULL)
11399 {
66cfc0fd
AM
11400 error (_("Out of memory allocating space for %s dynamic entries\n"),
11401 bfd_vmatoa ("u", number));
252b5132
RH
11402 free (e_data);
11403 return NULL;
11404 }
11405
11406 while (number--)
66543521 11407 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
252b5132
RH
11408
11409 free (e_data);
11410
11411 return i_data;
11412}
11413
6bd1a22c 11414static void
dda8d76d 11415print_dynamic_symbol (Filedata * filedata, bfd_vma si, unsigned long hn)
6bd1a22c 11416{
2cf0635d 11417 Elf_Internal_Sym * psym;
6bd1a22c
L
11418 int n;
11419
6bd1a22c
L
11420 n = print_vma (si, DEC_5);
11421 if (n < 5)
0b4362b0 11422 fputs (&" "[n], stdout);
6bd1a22c 11423 printf (" %3lu: ", hn);
e0a31db1
NC
11424
11425 if (dynamic_symbols == NULL || si >= num_dynamic_syms)
11426 {
3102e897
NC
11427 printf (_("<No info available for dynamic symbol number %lu>\n"),
11428 (unsigned long) si);
e0a31db1
NC
11429 return;
11430 }
11431
11432 psym = dynamic_symbols + si;
6bd1a22c
L
11433 print_vma (psym->st_value, LONG_HEX);
11434 putchar (' ');
11435 print_vma (psym->st_size, DEC_5);
11436
dda8d76d
NC
11437 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
11438 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
fd85a6a1 11439
dda8d76d 11440 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
11441 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
11442 else
11443 {
11444 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
11445
11446 printf (" %-7s", get_symbol_visibility (vis));
11447 /* Check to see if any other bits in the st_other field are set.
11448 Note - displaying this information disrupts the layout of the
11449 table being generated, but for the moment this case is very
11450 rare. */
11451 if (psym->st_other ^ vis)
dda8d76d 11452 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
fd85a6a1
NC
11453 }
11454
dda8d76d 11455 printf (" %3.3s ", get_symbol_index_type (filedata, psym->st_shndx));
6bd1a22c
L
11456 if (VALID_DYNAMIC_NAME (psym->st_name))
11457 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
11458 else
2b692964 11459 printf (_(" <corrupt: %14ld>"), psym->st_name);
6bd1a22c
L
11460 putchar ('\n');
11461}
11462
bb4d2ac2 11463static const char *
dda8d76d 11464get_symbol_version_string (Filedata * filedata,
1449284b
NC
11465 bfd_boolean is_dynsym,
11466 const char * strtab,
11467 unsigned long int strtab_size,
11468 unsigned int si,
11469 Elf_Internal_Sym * psym,
11470 enum versioned_symbol_info * sym_info,
11471 unsigned short * vna_other)
bb4d2ac2 11472{
ab273396
AM
11473 unsigned char data[2];
11474 unsigned short vers_data;
11475 unsigned long offset;
7a815dd5 11476 unsigned short max_vd_ndx;
bb4d2ac2 11477
ab273396
AM
11478 if (!is_dynsym
11479 || version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
11480 return NULL;
bb4d2ac2 11481
dda8d76d 11482 offset = offset_from_vma (filedata, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
ab273396 11483 sizeof data + si * sizeof (vers_data));
bb4d2ac2 11484
dda8d76d 11485 if (get_data (&data, filedata, offset + si * sizeof (vers_data),
ab273396
AM
11486 sizeof (data), 1, _("version data")) == NULL)
11487 return NULL;
11488
11489 vers_data = byte_get (data, 2);
bb4d2ac2 11490
1f6f5dba 11491 if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0)
ab273396 11492 return NULL;
bb4d2ac2 11493
7a815dd5
L
11494 max_vd_ndx = 0;
11495
ab273396
AM
11496 /* Usually we'd only see verdef for defined symbols, and verneed for
11497 undefined symbols. However, symbols defined by the linker in
11498 .dynbss for variables copied from a shared library in order to
11499 avoid text relocations are defined yet have verneed. We could
11500 use a heuristic to detect the special case, for example, check
11501 for verneed first on symbols defined in SHT_NOBITS sections, but
11502 it is simpler and more reliable to just look for both verdef and
11503 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
bb4d2ac2 11504
ab273396
AM
11505 if (psym->st_shndx != SHN_UNDEF
11506 && vers_data != 0x8001
11507 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
11508 {
11509 Elf_Internal_Verdef ivd;
11510 Elf_Internal_Verdaux ivda;
11511 Elf_External_Verdaux evda;
11512 unsigned long off;
bb4d2ac2 11513
dda8d76d 11514 off = offset_from_vma (filedata,
ab273396
AM
11515 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
11516 sizeof (Elf_External_Verdef));
11517
11518 do
bb4d2ac2 11519 {
ab273396
AM
11520 Elf_External_Verdef evd;
11521
dda8d76d 11522 if (get_data (&evd, filedata, off, sizeof (evd), 1,
ab273396
AM
11523 _("version def")) == NULL)
11524 {
11525 ivd.vd_ndx = 0;
11526 ivd.vd_aux = 0;
11527 ivd.vd_next = 0;
1f6f5dba 11528 ivd.vd_flags = 0;
ab273396
AM
11529 }
11530 else
bb4d2ac2 11531 {
ab273396
AM
11532 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
11533 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11534 ivd.vd_next = BYTE_GET (evd.vd_next);
1f6f5dba 11535 ivd.vd_flags = BYTE_GET (evd.vd_flags);
ab273396 11536 }
bb4d2ac2 11537
7a815dd5
L
11538 if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx)
11539 max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION;
11540
ab273396
AM
11541 off += ivd.vd_next;
11542 }
11543 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
bb4d2ac2 11544
ab273396
AM
11545 if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
11546 {
1f6f5dba
L
11547 if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE)
11548 return NULL;
11549
ab273396
AM
11550 off -= ivd.vd_next;
11551 off += ivd.vd_aux;
bb4d2ac2 11552
dda8d76d 11553 if (get_data (&evda, filedata, off, sizeof (evda), 1,
ab273396
AM
11554 _("version def aux")) != NULL)
11555 {
11556 ivda.vda_name = BYTE_GET (evda.vda_name);
bb4d2ac2 11557
ab273396
AM
11558 if (psym->st_name != ivda.vda_name)
11559 {
11560 *sym_info = ((vers_data & VERSYM_HIDDEN) != 0
11561 ? symbol_hidden : symbol_public);
11562 return (ivda.vda_name < strtab_size
11563 ? strtab + ivda.vda_name : _("<corrupt>"));
11564 }
11565 }
11566 }
11567 }
bb4d2ac2 11568
ab273396
AM
11569 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
11570 {
11571 Elf_External_Verneed evn;
11572 Elf_Internal_Verneed ivn;
11573 Elf_Internal_Vernaux ivna;
bb4d2ac2 11574
dda8d76d 11575 offset = offset_from_vma (filedata,
ab273396
AM
11576 version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
11577 sizeof evn);
11578 do
11579 {
11580 unsigned long vna_off;
bb4d2ac2 11581
dda8d76d 11582 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
ab273396
AM
11583 _("version need")) == NULL)
11584 {
11585 ivna.vna_next = 0;
11586 ivna.vna_other = 0;
11587 ivna.vna_name = 0;
11588 break;
11589 }
bb4d2ac2 11590
ab273396
AM
11591 ivn.vn_aux = BYTE_GET (evn.vn_aux);
11592 ivn.vn_next = BYTE_GET (evn.vn_next);
bb4d2ac2 11593
ab273396 11594 vna_off = offset + ivn.vn_aux;
bb4d2ac2 11595
ab273396
AM
11596 do
11597 {
11598 Elf_External_Vernaux evna;
bb4d2ac2 11599
dda8d76d 11600 if (get_data (&evna, filedata, vna_off, sizeof (evna), 1,
ab273396 11601 _("version need aux (3)")) == NULL)
bb4d2ac2 11602 {
ab273396
AM
11603 ivna.vna_next = 0;
11604 ivna.vna_other = 0;
11605 ivna.vna_name = 0;
bb4d2ac2 11606 }
bb4d2ac2 11607 else
bb4d2ac2 11608 {
ab273396
AM
11609 ivna.vna_other = BYTE_GET (evna.vna_other);
11610 ivna.vna_next = BYTE_GET (evna.vna_next);
11611 ivna.vna_name = BYTE_GET (evna.vna_name);
11612 }
bb4d2ac2 11613
ab273396
AM
11614 vna_off += ivna.vna_next;
11615 }
11616 while (ivna.vna_other != vers_data && ivna.vna_next != 0);
bb4d2ac2 11617
ab273396
AM
11618 if (ivna.vna_other == vers_data)
11619 break;
bb4d2ac2 11620
ab273396
AM
11621 offset += ivn.vn_next;
11622 }
11623 while (ivn.vn_next != 0);
bb4d2ac2 11624
ab273396
AM
11625 if (ivna.vna_other == vers_data)
11626 {
11627 *sym_info = symbol_undefined;
11628 *vna_other = ivna.vna_other;
11629 return (ivna.vna_name < strtab_size
11630 ? strtab + ivna.vna_name : _("<corrupt>"));
bb4d2ac2 11631 }
7a815dd5
L
11632 else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1)
11633 && (vers_data & VERSYM_VERSION) > max_vd_ndx)
11634 return _("<corrupt>");
bb4d2ac2 11635 }
ab273396 11636 return NULL;
bb4d2ac2
L
11637}
11638
e3c8793a 11639/* Dump the symbol table. */
32ec8896 11640static bfd_boolean
dda8d76d 11641process_symbol_table (Filedata * filedata)
252b5132 11642{
2cf0635d 11643 Elf_Internal_Shdr * section;
8b73c356
NC
11644 bfd_size_type nbuckets = 0;
11645 bfd_size_type nchains = 0;
2cf0635d
NC
11646 bfd_vma * buckets = NULL;
11647 bfd_vma * chains = NULL;
fdc90cb4 11648 bfd_vma ngnubuckets = 0;
2cf0635d
NC
11649 bfd_vma * gnubuckets = NULL;
11650 bfd_vma * gnuchains = NULL;
6bd1a22c 11651 bfd_vma gnusymidx = 0;
071436c6 11652 bfd_size_type ngnuchains = 0;
252b5132 11653
2c610e4b 11654 if (!do_syms && !do_dyn_syms && !do_histogram)
32ec8896 11655 return TRUE;
252b5132 11656
6bd1a22c
L
11657 if (dynamic_info[DT_HASH]
11658 && (do_histogram
2c610e4b
L
11659 || (do_using_dynamic
11660 && !do_dyn_syms
11661 && dynamic_strings != NULL)))
252b5132 11662 {
66543521
AM
11663 unsigned char nb[8];
11664 unsigned char nc[8];
8b73c356 11665 unsigned int hash_ent_size = 4;
66543521 11666
dda8d76d
NC
11667 if ((filedata->file_header.e_machine == EM_ALPHA
11668 || filedata->file_header.e_machine == EM_S390
11669 || filedata->file_header.e_machine == EM_S390_OLD)
11670 && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64)
66543521
AM
11671 hash_ent_size = 8;
11672
dda8d76d 11673 if (fseek (filedata->handle,
fb52b2f4 11674 (archive_file_offset
dda8d76d 11675 + offset_from_vma (filedata, dynamic_info[DT_HASH],
fb52b2f4 11676 sizeof nb + sizeof nc)),
d93f0186 11677 SEEK_SET))
252b5132 11678 {
591a748a 11679 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11680 goto no_hash;
252b5132
RH
11681 }
11682
dda8d76d 11683 if (fread (nb, hash_ent_size, 1, filedata->handle) != 1)
252b5132
RH
11684 {
11685 error (_("Failed to read in number of buckets\n"));
d3a44ec6 11686 goto no_hash;
252b5132
RH
11687 }
11688
dda8d76d 11689 if (fread (nc, hash_ent_size, 1, filedata->handle) != 1)
252b5132
RH
11690 {
11691 error (_("Failed to read in number of chains\n"));
d3a44ec6 11692 goto no_hash;
252b5132
RH
11693 }
11694
66543521
AM
11695 nbuckets = byte_get (nb, hash_ent_size);
11696 nchains = byte_get (nc, hash_ent_size);
252b5132 11697
dda8d76d
NC
11698 buckets = get_dynamic_data (filedata, nbuckets, hash_ent_size);
11699 chains = get_dynamic_data (filedata, nchains, hash_ent_size);
252b5132 11700
d3a44ec6 11701 no_hash:
252b5132 11702 if (buckets == NULL || chains == NULL)
d3a44ec6
JJ
11703 {
11704 if (do_using_dynamic)
32ec8896 11705 return FALSE;
d3a44ec6
JJ
11706 free (buckets);
11707 free (chains);
11708 buckets = NULL;
11709 chains = NULL;
11710 nbuckets = 0;
11711 nchains = 0;
11712 }
252b5132
RH
11713 }
11714
6bd1a22c
L
11715 if (dynamic_info_DT_GNU_HASH
11716 && (do_histogram
2c610e4b
L
11717 || (do_using_dynamic
11718 && !do_dyn_syms
11719 && dynamic_strings != NULL)))
252b5132 11720 {
6bd1a22c
L
11721 unsigned char nb[16];
11722 bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
11723 bfd_vma buckets_vma;
11724
dda8d76d 11725 if (fseek (filedata->handle,
6bd1a22c 11726 (archive_file_offset
dda8d76d 11727 + offset_from_vma (filedata, dynamic_info_DT_GNU_HASH,
6bd1a22c
L
11728 sizeof nb)),
11729 SEEK_SET))
11730 {
11731 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11732 goto no_gnu_hash;
6bd1a22c 11733 }
252b5132 11734
dda8d76d 11735 if (fread (nb, 16, 1, filedata->handle) != 1)
6bd1a22c
L
11736 {
11737 error (_("Failed to read in number of buckets\n"));
d3a44ec6 11738 goto no_gnu_hash;
6bd1a22c
L
11739 }
11740
11741 ngnubuckets = byte_get (nb, 4);
11742 gnusymidx = byte_get (nb + 4, 4);
11743 bitmaskwords = byte_get (nb + 8, 4);
11744 buckets_vma = dynamic_info_DT_GNU_HASH + 16;
f7a99963 11745 if (is_32bit_elf)
6bd1a22c 11746 buckets_vma += bitmaskwords * 4;
f7a99963 11747 else
6bd1a22c 11748 buckets_vma += bitmaskwords * 8;
252b5132 11749
dda8d76d 11750 if (fseek (filedata->handle,
6bd1a22c 11751 (archive_file_offset
dda8d76d 11752 + offset_from_vma (filedata, buckets_vma, 4)),
6bd1a22c 11753 SEEK_SET))
252b5132 11754 {
6bd1a22c 11755 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11756 goto no_gnu_hash;
6bd1a22c
L
11757 }
11758
dda8d76d 11759 gnubuckets = get_dynamic_data (filedata, ngnubuckets, 4);
252b5132 11760
6bd1a22c 11761 if (gnubuckets == NULL)
d3a44ec6 11762 goto no_gnu_hash;
6bd1a22c
L
11763
11764 for (i = 0; i < ngnubuckets; i++)
11765 if (gnubuckets[i] != 0)
11766 {
11767 if (gnubuckets[i] < gnusymidx)
32ec8896 11768 return FALSE;
6bd1a22c
L
11769
11770 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
11771 maxchain = gnubuckets[i];
11772 }
11773
11774 if (maxchain == 0xffffffff)
d3a44ec6 11775 goto no_gnu_hash;
6bd1a22c
L
11776
11777 maxchain -= gnusymidx;
11778
dda8d76d 11779 if (fseek (filedata->handle,
6bd1a22c 11780 (archive_file_offset
dda8d76d 11781 + offset_from_vma (filedata, buckets_vma
6bd1a22c
L
11782 + 4 * (ngnubuckets + maxchain), 4)),
11783 SEEK_SET))
11784 {
11785 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11786 goto no_gnu_hash;
6bd1a22c
L
11787 }
11788
11789 do
11790 {
dda8d76d 11791 if (fread (nb, 4, 1, filedata->handle) != 1)
252b5132 11792 {
6bd1a22c 11793 error (_("Failed to determine last chain length\n"));
d3a44ec6 11794 goto no_gnu_hash;
6bd1a22c 11795 }
252b5132 11796
6bd1a22c 11797 if (maxchain + 1 == 0)
d3a44ec6 11798 goto no_gnu_hash;
252b5132 11799
6bd1a22c
L
11800 ++maxchain;
11801 }
11802 while ((byte_get (nb, 4) & 1) == 0);
76da6bbe 11803
dda8d76d 11804 if (fseek (filedata->handle,
6bd1a22c 11805 (archive_file_offset
dda8d76d 11806 + offset_from_vma (filedata, buckets_vma + 4 * ngnubuckets, 4)),
6bd1a22c
L
11807 SEEK_SET))
11808 {
11809 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11810 goto no_gnu_hash;
6bd1a22c
L
11811 }
11812
dda8d76d 11813 gnuchains = get_dynamic_data (filedata, maxchain, 4);
071436c6 11814 ngnuchains = maxchain;
6bd1a22c 11815
d3a44ec6 11816 no_gnu_hash:
6bd1a22c 11817 if (gnuchains == NULL)
d3a44ec6
JJ
11818 {
11819 free (gnubuckets);
d3a44ec6
JJ
11820 gnubuckets = NULL;
11821 ngnubuckets = 0;
f64fddf1 11822 if (do_using_dynamic)
32ec8896 11823 return FALSE;
d3a44ec6 11824 }
6bd1a22c
L
11825 }
11826
11827 if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
11828 && do_syms
11829 && do_using_dynamic
3102e897
NC
11830 && dynamic_strings != NULL
11831 && dynamic_symbols != NULL)
6bd1a22c
L
11832 {
11833 unsigned long hn;
11834
11835 if (dynamic_info[DT_HASH])
11836 {
11837 bfd_vma si;
6bd6a03d 11838 char *visited;
6bd1a22c
L
11839
11840 printf (_("\nSymbol table for image:\n"));
11841 if (is_32bit_elf)
11842 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11843 else
11844 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11845
6bd6a03d
AM
11846 visited = xcmalloc (nchains, 1);
11847 memset (visited, 0, nchains);
6bd1a22c
L
11848 for (hn = 0; hn < nbuckets; hn++)
11849 {
6bd6a03d
AM
11850 for (si = buckets[hn]; si > 0; si = chains[si])
11851 {
dda8d76d 11852 print_dynamic_symbol (filedata, si, hn);
6bd6a03d
AM
11853 if (si >= nchains || visited[si])
11854 {
11855 error (_("histogram chain is corrupt\n"));
11856 break;
11857 }
11858 visited[si] = 1;
11859 }
252b5132 11860 }
6bd6a03d 11861 free (visited);
252b5132 11862 }
6bd1a22c
L
11863
11864 if (dynamic_info_DT_GNU_HASH)
11865 {
11866 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
11867 if (is_32bit_elf)
11868 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11869 else
11870 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11871
11872 for (hn = 0; hn < ngnubuckets; ++hn)
11873 if (gnubuckets[hn] != 0)
11874 {
11875 bfd_vma si = gnubuckets[hn];
11876 bfd_vma off = si - gnusymidx;
11877
11878 do
11879 {
dda8d76d 11880 print_dynamic_symbol (filedata, si, hn);
6bd1a22c
L
11881 si++;
11882 }
071436c6 11883 while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
6bd1a22c
L
11884 }
11885 }
252b5132 11886 }
8b73c356 11887 else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
dda8d76d 11888 && filedata->section_headers != NULL)
252b5132 11889 {
b34976b6 11890 unsigned int i;
252b5132 11891
dda8d76d
NC
11892 for (i = 0, section = filedata->section_headers;
11893 i < filedata->file_header.e_shnum;
252b5132
RH
11894 i++, section++)
11895 {
b34976b6 11896 unsigned int si;
2cf0635d 11897 char * strtab = NULL;
c256ffe7 11898 unsigned long int strtab_size = 0;
2cf0635d
NC
11899 Elf_Internal_Sym * symtab;
11900 Elf_Internal_Sym * psym;
ba5cdace 11901 unsigned long num_syms;
252b5132 11902
2c610e4b
L
11903 if ((section->sh_type != SHT_SYMTAB
11904 && section->sh_type != SHT_DYNSYM)
11905 || (!do_syms
11906 && section->sh_type == SHT_SYMTAB))
252b5132
RH
11907 continue;
11908
dd24e3da
NC
11909 if (section->sh_entsize == 0)
11910 {
11911 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
dda8d76d 11912 printable_section_name (filedata, section));
dd24e3da
NC
11913 continue;
11914 }
11915
d3a49aa8
AM
11916 num_syms = section->sh_size / section->sh_entsize;
11917 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
11918 "\nSymbol table '%s' contains %lu entries:\n",
11919 num_syms),
dda8d76d 11920 printable_section_name (filedata, section),
d3a49aa8 11921 num_syms);
dd24e3da 11922
f7a99963 11923 if (is_32bit_elf)
ca47b30c 11924 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
f7a99963 11925 else
ca47b30c 11926 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
252b5132 11927
dda8d76d 11928 symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms);
252b5132
RH
11929 if (symtab == NULL)
11930 continue;
11931
dda8d76d 11932 if (section->sh_link == filedata->file_header.e_shstrndx)
c256ffe7 11933 {
dda8d76d
NC
11934 strtab = filedata->string_table;
11935 strtab_size = filedata->string_table_length;
c256ffe7 11936 }
dda8d76d 11937 else if (section->sh_link < filedata->file_header.e_shnum)
252b5132 11938 {
2cf0635d 11939 Elf_Internal_Shdr * string_sec;
252b5132 11940
dda8d76d 11941 string_sec = filedata->section_headers + section->sh_link;
252b5132 11942
dda8d76d 11943 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset,
3f5e193b
NC
11944 1, string_sec->sh_size,
11945 _("string table"));
c256ffe7 11946 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
252b5132
RH
11947 }
11948
ba5cdace 11949 for (si = 0, psym = symtab; si < num_syms; si++, psym++)
252b5132 11950 {
bb4d2ac2
L
11951 const char *version_string;
11952 enum versioned_symbol_info sym_info;
11953 unsigned short vna_other;
11954
5e220199 11955 printf ("%6d: ", si);
f7a99963
NC
11956 print_vma (psym->st_value, LONG_HEX);
11957 putchar (' ');
11958 print_vma (psym->st_size, DEC_5);
dda8d76d
NC
11959 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
11960 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
11961 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
11962 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
11963 else
11964 {
11965 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
11966
11967 printf (" %-7s", get_symbol_visibility (vis));
11968 /* Check to see if any other bits in the st_other field are set.
11969 Note - displaying this information disrupts the layout of the
11970 table being generated, but for the moment this case is very rare. */
11971 if (psym->st_other ^ vis)
dda8d76d 11972 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
fd85a6a1 11973 }
dda8d76d 11974 printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
c256ffe7 11975 print_symbol (25, psym->st_name < strtab_size
2b692964 11976 ? strtab + psym->st_name : _("<corrupt>"));
252b5132 11977
bb4d2ac2 11978 version_string
dda8d76d 11979 = get_symbol_version_string (filedata,
bb4d2ac2
L
11980 section->sh_type == SHT_DYNSYM,
11981 strtab, strtab_size, si,
11982 psym, &sym_info, &vna_other);
11983 if (version_string)
252b5132 11984 {
bb4d2ac2
L
11985 if (sym_info == symbol_undefined)
11986 printf ("@%s (%d)", version_string, vna_other);
11987 else
11988 printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
11989 version_string);
252b5132
RH
11990 }
11991
11992 putchar ('\n');
52c3c391
NC
11993
11994 if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
dd905818
NC
11995 && si >= section->sh_info
11996 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
dda8d76d 11997 && filedata->file_header.e_machine != EM_MIPS
dd905818
NC
11998 /* Solaris binaries have been found to violate this requirement as
11999 well. Not sure if this is a bug or an ABI requirement. */
dda8d76d 12000 && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS)
52c3c391 12001 warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"),
dda8d76d 12002 si, printable_section_name (filedata, section), section->sh_info);
252b5132
RH
12003 }
12004
12005 free (symtab);
dda8d76d 12006 if (strtab != filedata->string_table)
252b5132
RH
12007 free (strtab);
12008 }
12009 }
12010 else if (do_syms)
12011 printf
12012 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
12013
12014 if (do_histogram && buckets != NULL)
12015 {
2cf0635d
NC
12016 unsigned long * lengths;
12017 unsigned long * counts;
66543521
AM
12018 unsigned long hn;
12019 bfd_vma si;
12020 unsigned long maxlength = 0;
12021 unsigned long nzero_counts = 0;
12022 unsigned long nsyms = 0;
6bd6a03d 12023 char *visited;
252b5132 12024
d3a49aa8
AM
12025 printf (ngettext ("\nHistogram for bucket list length "
12026 "(total of %lu bucket):\n",
12027 "\nHistogram for bucket list length "
12028 "(total of %lu buckets):\n",
12029 (unsigned long) nbuckets),
66543521 12030 (unsigned long) nbuckets);
252b5132 12031
3f5e193b 12032 lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
252b5132
RH
12033 if (lengths == NULL)
12034 {
8b73c356 12035 error (_("Out of memory allocating space for histogram buckets\n"));
32ec8896 12036 return FALSE;
252b5132 12037 }
6bd6a03d
AM
12038 visited = xcmalloc (nchains, 1);
12039 memset (visited, 0, nchains);
8b73c356
NC
12040
12041 printf (_(" Length Number %% of total Coverage\n"));
252b5132
RH
12042 for (hn = 0; hn < nbuckets; ++hn)
12043 {
6bd6a03d 12044 for (si = buckets[hn]; si > 0; si = chains[si])
252b5132 12045 {
b34976b6 12046 ++nsyms;
252b5132 12047 if (maxlength < ++lengths[hn])
b34976b6 12048 ++maxlength;
6bd6a03d
AM
12049 if (si >= nchains || visited[si])
12050 {
12051 error (_("histogram chain is corrupt\n"));
12052 break;
12053 }
12054 visited[si] = 1;
252b5132
RH
12055 }
12056 }
6bd6a03d 12057 free (visited);
252b5132 12058
3f5e193b 12059 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
252b5132
RH
12060 if (counts == NULL)
12061 {
b2e951ec 12062 free (lengths);
8b73c356 12063 error (_("Out of memory allocating space for histogram counts\n"));
32ec8896 12064 return FALSE;
252b5132
RH
12065 }
12066
12067 for (hn = 0; hn < nbuckets; ++hn)
b34976b6 12068 ++counts[lengths[hn]];
252b5132 12069
103f02d3 12070 if (nbuckets > 0)
252b5132 12071 {
66543521
AM
12072 unsigned long i;
12073 printf (" 0 %-10lu (%5.1f%%)\n",
103f02d3 12074 counts[0], (counts[0] * 100.0) / nbuckets);
66543521 12075 for (i = 1; i <= maxlength; ++i)
103f02d3 12076 {
66543521
AM
12077 nzero_counts += counts[i] * i;
12078 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12079 i, counts[i], (counts[i] * 100.0) / nbuckets,
103f02d3
UD
12080 (nzero_counts * 100.0) / nsyms);
12081 }
252b5132
RH
12082 }
12083
12084 free (counts);
12085 free (lengths);
12086 }
12087
12088 if (buckets != NULL)
12089 {
12090 free (buckets);
12091 free (chains);
12092 }
12093
d3a44ec6 12094 if (do_histogram && gnubuckets != NULL)
fdc90cb4 12095 {
2cf0635d
NC
12096 unsigned long * lengths;
12097 unsigned long * counts;
fdc90cb4
JJ
12098 unsigned long hn;
12099 unsigned long maxlength = 0;
12100 unsigned long nzero_counts = 0;
12101 unsigned long nsyms = 0;
fdc90cb4 12102
d3a49aa8
AM
12103 printf (ngettext ("\nHistogram for `.gnu.hash' bucket list length "
12104 "(total of %lu bucket):\n",
12105 "\nHistogram for `.gnu.hash' bucket list length "
12106 "(total of %lu buckets):\n",
12107 (unsigned long) ngnubuckets),
8b73c356
NC
12108 (unsigned long) ngnubuckets);
12109
3f5e193b 12110 lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
fdc90cb4
JJ
12111 if (lengths == NULL)
12112 {
8b73c356 12113 error (_("Out of memory allocating space for gnu histogram buckets\n"));
32ec8896 12114 return FALSE;
fdc90cb4
JJ
12115 }
12116
fdc90cb4
JJ
12117 printf (_(" Length Number %% of total Coverage\n"));
12118
12119 for (hn = 0; hn < ngnubuckets; ++hn)
12120 if (gnubuckets[hn] != 0)
12121 {
12122 bfd_vma off, length = 1;
12123
6bd1a22c 12124 for (off = gnubuckets[hn] - gnusymidx;
071436c6
NC
12125 /* PR 17531 file: 010-77222-0.004. */
12126 off < ngnuchains && (gnuchains[off] & 1) == 0;
12127 ++off)
fdc90cb4
JJ
12128 ++length;
12129 lengths[hn] = length;
12130 if (length > maxlength)
12131 maxlength = length;
12132 nsyms += length;
12133 }
12134
3f5e193b 12135 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
fdc90cb4
JJ
12136 if (counts == NULL)
12137 {
b2e951ec 12138 free (lengths);
8b73c356 12139 error (_("Out of memory allocating space for gnu histogram counts\n"));
32ec8896 12140 return FALSE;
fdc90cb4
JJ
12141 }
12142
12143 for (hn = 0; hn < ngnubuckets; ++hn)
12144 ++counts[lengths[hn]];
12145
12146 if (ngnubuckets > 0)
12147 {
12148 unsigned long j;
12149 printf (" 0 %-10lu (%5.1f%%)\n",
12150 counts[0], (counts[0] * 100.0) / ngnubuckets);
12151 for (j = 1; j <= maxlength; ++j)
12152 {
12153 nzero_counts += counts[j] * j;
12154 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12155 j, counts[j], (counts[j] * 100.0) / ngnubuckets,
12156 (nzero_counts * 100.0) / nsyms);
12157 }
12158 }
12159
12160 free (counts);
12161 free (lengths);
12162 free (gnubuckets);
12163 free (gnuchains);
12164 }
12165
32ec8896 12166 return TRUE;
252b5132
RH
12167}
12168
32ec8896 12169static bfd_boolean
dda8d76d 12170process_syminfo (Filedata * filedata ATTRIBUTE_UNUSED)
252b5132 12171{
b4c96d0d 12172 unsigned int i;
252b5132
RH
12173
12174 if (dynamic_syminfo == NULL
12175 || !do_dynamic)
12176 /* No syminfo, this is ok. */
32ec8896 12177 return TRUE;
252b5132
RH
12178
12179 /* There better should be a dynamic symbol section. */
12180 if (dynamic_symbols == NULL || dynamic_strings == NULL)
32ec8896 12181 return FALSE;
252b5132
RH
12182
12183 if (dynamic_addr)
d3a49aa8
AM
12184 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
12185 "contains %d entry:\n",
12186 "\nDynamic info segment at offset 0x%lx "
12187 "contains %d entries:\n",
12188 dynamic_syminfo_nent),
252b5132
RH
12189 dynamic_syminfo_offset, dynamic_syminfo_nent);
12190
12191 printf (_(" Num: Name BoundTo Flags\n"));
12192 for (i = 0; i < dynamic_syminfo_nent; ++i)
12193 {
12194 unsigned short int flags = dynamic_syminfo[i].si_flags;
12195
31104126 12196 printf ("%4d: ", i);
4082ef84
NC
12197 if (i >= num_dynamic_syms)
12198 printf (_("<corrupt index>"));
12199 else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
d79b3d50
NC
12200 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
12201 else
2b692964 12202 printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
31104126 12203 putchar (' ');
252b5132
RH
12204
12205 switch (dynamic_syminfo[i].si_boundto)
12206 {
12207 case SYMINFO_BT_SELF:
12208 fputs ("SELF ", stdout);
12209 break;
12210 case SYMINFO_BT_PARENT:
12211 fputs ("PARENT ", stdout);
12212 break;
12213 default:
12214 if (dynamic_syminfo[i].si_boundto > 0
d79b3d50
NC
12215 && dynamic_syminfo[i].si_boundto < dynamic_nent
12216 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
31104126 12217 {
d79b3d50 12218 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
31104126
NC
12219 putchar (' ' );
12220 }
252b5132
RH
12221 else
12222 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
12223 break;
12224 }
12225
12226 if (flags & SYMINFO_FLG_DIRECT)
12227 printf (" DIRECT");
12228 if (flags & SYMINFO_FLG_PASSTHRU)
12229 printf (" PASSTHRU");
12230 if (flags & SYMINFO_FLG_COPY)
12231 printf (" COPY");
12232 if (flags & SYMINFO_FLG_LAZYLOAD)
12233 printf (" LAZYLOAD");
12234
12235 puts ("");
12236 }
12237
32ec8896 12238 return TRUE;
252b5132
RH
12239}
12240
b32e566b
NC
12241#define IN_RANGE(START,END,ADDR,OFF) \
12242 (((ADDR) >= (START)) && ((ADDR) + (OFF) < (END)))
12243
cf13d699
NC
12244/* Check to see if the given reloc needs to be handled in a target specific
12245 manner. If so then process the reloc and return TRUE otherwise return
f84ce13b
NC
12246 FALSE.
12247
12248 If called with reloc == NULL, then this is a signal that reloc processing
12249 for the current section has finished, and any saved state should be
12250 discarded. */
09c11c86 12251
cf13d699 12252static bfd_boolean
dda8d76d
NC
12253target_specific_reloc_handling (Filedata * filedata,
12254 Elf_Internal_Rela * reloc,
12255 unsigned char * start,
12256 unsigned char * end,
12257 Elf_Internal_Sym * symtab,
12258 unsigned long num_syms)
252b5132 12259{
f84ce13b
NC
12260 unsigned int reloc_type = 0;
12261 unsigned long sym_index = 0;
12262
12263 if (reloc)
12264 {
dda8d76d 12265 reloc_type = get_reloc_type (filedata, reloc->r_info);
f84ce13b
NC
12266 sym_index = get_reloc_symindex (reloc->r_info);
12267 }
252b5132 12268
dda8d76d 12269 switch (filedata->file_header.e_machine)
252b5132 12270 {
13761a11
NC
12271 case EM_MSP430:
12272 case EM_MSP430_OLD:
12273 {
12274 static Elf_Internal_Sym * saved_sym = NULL;
12275
f84ce13b
NC
12276 if (reloc == NULL)
12277 {
12278 saved_sym = NULL;
12279 return TRUE;
12280 }
12281
13761a11
NC
12282 switch (reloc_type)
12283 {
12284 case 10: /* R_MSP430_SYM_DIFF */
dda8d76d 12285 if (uses_msp430x_relocs (filedata))
13761a11 12286 break;
1a0670f3 12287 /* Fall through. */
13761a11 12288 case 21: /* R_MSP430X_SYM_DIFF */
f84ce13b
NC
12289 /* PR 21139. */
12290 if (sym_index >= num_syms)
12291 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
12292 sym_index);
12293 else
12294 saved_sym = symtab + sym_index;
13761a11
NC
12295 return TRUE;
12296
12297 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
12298 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
12299 goto handle_sym_diff;
0b4362b0 12300
13761a11
NC
12301 case 5: /* R_MSP430_16_BYTE */
12302 case 9: /* R_MSP430_8 */
dda8d76d 12303 if (uses_msp430x_relocs (filedata))
13761a11
NC
12304 break;
12305 goto handle_sym_diff;
12306
12307 case 2: /* R_MSP430_ABS16 */
12308 case 15: /* R_MSP430X_ABS16 */
dda8d76d 12309 if (! uses_msp430x_relocs (filedata))
13761a11
NC
12310 break;
12311 goto handle_sym_diff;
0b4362b0 12312
13761a11
NC
12313 handle_sym_diff:
12314 if (saved_sym != NULL)
12315 {
03f7786e 12316 int reloc_size = reloc_type == 1 ? 4 : 2;
13761a11
NC
12317 bfd_vma value;
12318
f84ce13b
NC
12319 if (sym_index >= num_syms)
12320 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
12321 sym_index);
03f7786e 12322 else
f84ce13b
NC
12323 {
12324 value = reloc->r_addend + (symtab[sym_index].st_value
12325 - saved_sym->st_value);
12326
b32e566b 12327 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
f84ce13b 12328 byte_put (start + reloc->r_offset, value, reloc_size);
b32e566b
NC
12329 else
12330 /* PR 21137 */
12331 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
12332 (long) reloc->r_offset);
f84ce13b 12333 }
13761a11
NC
12334
12335 saved_sym = NULL;
12336 return TRUE;
12337 }
12338 break;
12339
12340 default:
12341 if (saved_sym != NULL)
071436c6 12342 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
13761a11
NC
12343 break;
12344 }
12345 break;
12346 }
12347
cf13d699
NC
12348 case EM_MN10300:
12349 case EM_CYGNUS_MN10300:
12350 {
12351 static Elf_Internal_Sym * saved_sym = NULL;
252b5132 12352
f84ce13b
NC
12353 if (reloc == NULL)
12354 {
12355 saved_sym = NULL;
12356 return TRUE;
12357 }
12358
cf13d699
NC
12359 switch (reloc_type)
12360 {
12361 case 34: /* R_MN10300_ALIGN */
12362 return TRUE;
12363 case 33: /* R_MN10300_SYM_DIFF */
f84ce13b
NC
12364 if (sym_index >= num_syms)
12365 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
12366 sym_index);
12367 else
12368 saved_sym = symtab + sym_index;
cf13d699 12369 return TRUE;
f84ce13b 12370
cf13d699
NC
12371 case 1: /* R_MN10300_32 */
12372 case 2: /* R_MN10300_16 */
12373 if (saved_sym != NULL)
12374 {
03f7786e 12375 int reloc_size = reloc_type == 1 ? 4 : 2;
cf13d699 12376 bfd_vma value;
252b5132 12377
f84ce13b
NC
12378 if (sym_index >= num_syms)
12379 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
12380 sym_index);
03f7786e 12381 else
f84ce13b
NC
12382 {
12383 value = reloc->r_addend + (symtab[sym_index].st_value
12384 - saved_sym->st_value);
12385
b32e566b 12386 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
f84ce13b 12387 byte_put (start + reloc->r_offset, value, reloc_size);
b32e566b
NC
12388 else
12389 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
12390 (long) reloc->r_offset);
f84ce13b 12391 }
252b5132 12392
cf13d699
NC
12393 saved_sym = NULL;
12394 return TRUE;
12395 }
12396 break;
12397 default:
12398 if (saved_sym != NULL)
071436c6 12399 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
cf13d699
NC
12400 break;
12401 }
12402 break;
12403 }
6ff71e76
NC
12404
12405 case EM_RL78:
12406 {
12407 static bfd_vma saved_sym1 = 0;
12408 static bfd_vma saved_sym2 = 0;
12409 static bfd_vma value;
12410
f84ce13b
NC
12411 if (reloc == NULL)
12412 {
12413 saved_sym1 = saved_sym2 = 0;
12414 return TRUE;
12415 }
12416
6ff71e76
NC
12417 switch (reloc_type)
12418 {
12419 case 0x80: /* R_RL78_SYM. */
12420 saved_sym1 = saved_sym2;
f84ce13b
NC
12421 if (sym_index >= num_syms)
12422 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
12423 sym_index);
12424 else
12425 {
12426 saved_sym2 = symtab[sym_index].st_value;
12427 saved_sym2 += reloc->r_addend;
12428 }
6ff71e76
NC
12429 return TRUE;
12430
12431 case 0x83: /* R_RL78_OPsub. */
12432 value = saved_sym1 - saved_sym2;
12433 saved_sym2 = saved_sym1 = 0;
12434 return TRUE;
12435 break;
12436
12437 case 0x41: /* R_RL78_ABS32. */
b32e566b 12438 if (IN_RANGE (start, end, start + reloc->r_offset, 4))
03f7786e 12439 byte_put (start + reloc->r_offset, value, 4);
b32e566b
NC
12440 else
12441 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12442 (long) reloc->r_offset);
6ff71e76
NC
12443 value = 0;
12444 return TRUE;
12445
12446 case 0x43: /* R_RL78_ABS16. */
b32e566b 12447 if (IN_RANGE (start, end, start + reloc->r_offset, 2))
03f7786e 12448 byte_put (start + reloc->r_offset, value, 2);
b32e566b
NC
12449 else
12450 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12451 (long) reloc->r_offset);
6ff71e76
NC
12452 value = 0;
12453 return TRUE;
12454
12455 default:
12456 break;
12457 }
12458 break;
12459 }
252b5132
RH
12460 }
12461
cf13d699 12462 return FALSE;
252b5132
RH
12463}
12464
aca88567
NC
12465/* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
12466 DWARF debug sections. This is a target specific test. Note - we do not
12467 go through the whole including-target-headers-multiple-times route, (as
12468 we have already done with <elf/h8.h>) because this would become very
12469 messy and even then this function would have to contain target specific
12470 information (the names of the relocs instead of their numeric values).
12471 FIXME: This is not the correct way to solve this problem. The proper way
12472 is to have target specific reloc sizing and typing functions created by
12473 the reloc-macros.h header, in the same way that it already creates the
12474 reloc naming functions. */
12475
12476static bfd_boolean
dda8d76d 12477is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 12478{
d347c9df 12479 /* Please keep this table alpha-sorted for ease of visual lookup. */
dda8d76d 12480 switch (filedata->file_header.e_machine)
aca88567 12481 {
41e92641 12482 case EM_386:
22abe556 12483 case EM_IAMCU:
41e92641 12484 return reloc_type == 1; /* R_386_32. */
aca88567
NC
12485 case EM_68K:
12486 return reloc_type == 1; /* R_68K_32. */
f954747f
AM
12487 case EM_860:
12488 return reloc_type == 1; /* R_860_32. */
12489 case EM_960:
12490 return reloc_type == 2; /* R_960_32. */
a06ea964 12491 case EM_AARCH64:
9282b95a
JW
12492 return (reloc_type == 258
12493 || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
aca4efc7
JM
12494 case EM_BPF:
12495 return reloc_type == 11; /* R_BPF_DATA_32 */
d347c9df
PS
12496 case EM_ADAPTEVA_EPIPHANY:
12497 return reloc_type == 3;
aca88567 12498 case EM_ALPHA:
137b6b5f 12499 return reloc_type == 1; /* R_ALPHA_REFLONG. */
41e92641
NC
12500 case EM_ARC:
12501 return reloc_type == 1; /* R_ARC_32. */
886a2506
NC
12502 case EM_ARC_COMPACT:
12503 case EM_ARC_COMPACT2:
12504 return reloc_type == 4; /* R_ARC_32. */
41e92641
NC
12505 case EM_ARM:
12506 return reloc_type == 2; /* R_ARM_ABS32 */
cb8f3167 12507 case EM_AVR_OLD:
aca88567
NC
12508 case EM_AVR:
12509 return reloc_type == 1;
12510 case EM_BLACKFIN:
12511 return reloc_type == 0x12; /* R_byte4_data. */
12512 case EM_CRIS:
12513 return reloc_type == 3; /* R_CRIS_32. */
12514 case EM_CR16:
12515 return reloc_type == 3; /* R_CR16_NUM32. */
12516 case EM_CRX:
12517 return reloc_type == 15; /* R_CRX_NUM32. */
b8891f8d
AJ
12518 case EM_CSKY:
12519 return reloc_type == 1; /* R_CKCORE_ADDR32. */
aca88567
NC
12520 case EM_CYGNUS_FRV:
12521 return reloc_type == 1;
41e92641
NC
12522 case EM_CYGNUS_D10V:
12523 case EM_D10V:
12524 return reloc_type == 6; /* R_D10V_32. */
aca88567
NC
12525 case EM_CYGNUS_D30V:
12526 case EM_D30V:
12527 return reloc_type == 12; /* R_D30V_32_NORMAL. */
41e92641
NC
12528 case EM_DLX:
12529 return reloc_type == 3; /* R_DLX_RELOC_32. */
aca88567
NC
12530 case EM_CYGNUS_FR30:
12531 case EM_FR30:
12532 return reloc_type == 3; /* R_FR30_32. */
3f8107ab
AM
12533 case EM_FT32:
12534 return reloc_type == 1; /* R_FT32_32. */
aca88567
NC
12535 case EM_H8S:
12536 case EM_H8_300:
12537 case EM_H8_300H:
12538 return reloc_type == 1; /* R_H8_DIR32. */
3730236a 12539 case EM_IA_64:
262cdac7
AM
12540 return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */
12541 || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */
12542 || reloc_type == 0x24 /* R_IA64_DIR32MSB. */
12543 || reloc_type == 0x25 /* R_IA64_DIR32LSB. */);
aca88567
NC
12544 case EM_IP2K_OLD:
12545 case EM_IP2K:
12546 return reloc_type == 2; /* R_IP2K_32. */
12547 case EM_IQ2000:
12548 return reloc_type == 2; /* R_IQ2000_32. */
84e94c90
NC
12549 case EM_LATTICEMICO32:
12550 return reloc_type == 3; /* R_LM32_32. */
ff7eeb89 12551 case EM_M32C_OLD:
aca88567
NC
12552 case EM_M32C:
12553 return reloc_type == 3; /* R_M32C_32. */
12554 case EM_M32R:
12555 return reloc_type == 34; /* R_M32R_32_RELA. */
adec12c1
AM
12556 case EM_68HC11:
12557 case EM_68HC12:
12558 return reloc_type == 6; /* R_M68HC11_32. */
7b4ae824 12559 case EM_S12Z:
2849d19f
JD
12560 return reloc_type == 7 || /* R_S12Z_EXT32 */
12561 reloc_type == 6; /* R_S12Z_CW32. */
aca88567
NC
12562 case EM_MCORE:
12563 return reloc_type == 1; /* R_MCORE_ADDR32. */
12564 case EM_CYGNUS_MEP:
12565 return reloc_type == 4; /* R_MEP_32. */
a3c62988
NC
12566 case EM_METAG:
12567 return reloc_type == 2; /* R_METAG_ADDR32. */
137b6b5f
AM
12568 case EM_MICROBLAZE:
12569 return reloc_type == 1; /* R_MICROBLAZE_32. */
aca88567
NC
12570 case EM_MIPS:
12571 return reloc_type == 2; /* R_MIPS_32. */
12572 case EM_MMIX:
12573 return reloc_type == 4; /* R_MMIX_32. */
12574 case EM_CYGNUS_MN10200:
12575 case EM_MN10200:
12576 return reloc_type == 1; /* R_MN10200_32. */
12577 case EM_CYGNUS_MN10300:
12578 case EM_MN10300:
12579 return reloc_type == 1; /* R_MN10300_32. */
5506d11a
AM
12580 case EM_MOXIE:
12581 return reloc_type == 1; /* R_MOXIE_32. */
aca88567
NC
12582 case EM_MSP430_OLD:
12583 case EM_MSP430:
13761a11 12584 return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
aca88567
NC
12585 case EM_MT:
12586 return reloc_type == 2; /* R_MT_32. */
35c08157
KLC
12587 case EM_NDS32:
12588 return reloc_type == 20; /* R_NDS32_RELA. */
3e0873ac 12589 case EM_ALTERA_NIOS2:
36591ba1 12590 return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
3e0873ac
NC
12591 case EM_NIOS32:
12592 return reloc_type == 1; /* R_NIOS_32. */
73589c9d
CS
12593 case EM_OR1K:
12594 return reloc_type == 1; /* R_OR1K_32. */
aca88567 12595 case EM_PARISC:
0df8ad28
NC
12596 return (reloc_type == 1 /* R_PARISC_DIR32. */
12597 || reloc_type == 2 /* R_PARISC_DIR21L. */
5fda8eca 12598 || reloc_type == 41); /* R_PARISC_SECREL32. */
aca88567
NC
12599 case EM_PJ:
12600 case EM_PJ_OLD:
12601 return reloc_type == 1; /* R_PJ_DATA_DIR32. */
12602 case EM_PPC64:
12603 return reloc_type == 1; /* R_PPC64_ADDR32. */
12604 case EM_PPC:
12605 return reloc_type == 1; /* R_PPC_ADDR32. */
2b100bb5
DD
12606 case EM_TI_PRU:
12607 return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
e23eba97
NC
12608 case EM_RISCV:
12609 return reloc_type == 1; /* R_RISCV_32. */
99c513f6
DD
12610 case EM_RL78:
12611 return reloc_type == 1; /* R_RL78_DIR32. */
c7927a3c
NC
12612 case EM_RX:
12613 return reloc_type == 1; /* R_RX_DIR32. */
f954747f
AM
12614 case EM_S370:
12615 return reloc_type == 1; /* R_I370_ADDR31. */
aca88567
NC
12616 case EM_S390_OLD:
12617 case EM_S390:
12618 return reloc_type == 4; /* R_S390_32. */
41e92641
NC
12619 case EM_SCORE:
12620 return reloc_type == 8; /* R_SCORE_ABS32. */
aca88567
NC
12621 case EM_SH:
12622 return reloc_type == 1; /* R_SH_DIR32. */
12623 case EM_SPARC32PLUS:
12624 case EM_SPARCV9:
12625 case EM_SPARC:
12626 return reloc_type == 3 /* R_SPARC_32. */
12627 || reloc_type == 23; /* R_SPARC_UA32. */
a7dd7d05
AM
12628 case EM_SPU:
12629 return reloc_type == 6; /* R_SPU_ADDR32 */
40b36596
JM
12630 case EM_TI_C6000:
12631 return reloc_type == 1; /* R_C6000_ABS32. */
aa137e4d
NC
12632 case EM_TILEGX:
12633 return reloc_type == 2; /* R_TILEGX_32. */
12634 case EM_TILEPRO:
12635 return reloc_type == 1; /* R_TILEPRO_32. */
aca88567
NC
12636 case EM_CYGNUS_V850:
12637 case EM_V850:
12638 return reloc_type == 6; /* R_V850_ABS32. */
708e2187
NC
12639 case EM_V800:
12640 return reloc_type == 0x33; /* R_V810_WORD. */
aca88567
NC
12641 case EM_VAX:
12642 return reloc_type == 1; /* R_VAX_32. */
619ed720
EB
12643 case EM_VISIUM:
12644 return reloc_type == 3; /* R_VISIUM_32. */
f96bd6c2
PC
12645 case EM_WEBASSEMBLY:
12646 return reloc_type == 1; /* R_WASM32_32. */
aca88567 12647 case EM_X86_64:
8a9036a4 12648 case EM_L1OM:
7a9068fe 12649 case EM_K1OM:
aca88567 12650 return reloc_type == 10; /* R_X86_64_32. */
c29aca4a
NC
12651 case EM_XC16X:
12652 case EM_C166:
12653 return reloc_type == 3; /* R_XC16C_ABS_32. */
f6c1a2d5
NC
12654 case EM_XGATE:
12655 return reloc_type == 4; /* R_XGATE_32. */
aca88567
NC
12656 case EM_XSTORMY16:
12657 return reloc_type == 1; /* R_XSTROMY16_32. */
12658 case EM_XTENSA_OLD:
12659 case EM_XTENSA:
12660 return reloc_type == 1; /* R_XTENSA_32. */
aca88567 12661 default:
bee0ee85
NC
12662 {
12663 static unsigned int prev_warn = 0;
12664
12665 /* Avoid repeating the same warning multiple times. */
dda8d76d 12666 if (prev_warn != filedata->file_header.e_machine)
bee0ee85 12667 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
dda8d76d
NC
12668 filedata->file_header.e_machine);
12669 prev_warn = filedata->file_header.e_machine;
bee0ee85
NC
12670 return FALSE;
12671 }
aca88567
NC
12672 }
12673}
12674
12675/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12676 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
12677
12678static bfd_boolean
dda8d76d 12679is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 12680{
dda8d76d 12681 switch (filedata->file_header.e_machine)
d347c9df 12682 /* Please keep this table alpha-sorted for ease of visual lookup. */
aca88567 12683 {
41e92641 12684 case EM_386:
22abe556 12685 case EM_IAMCU:
3e0873ac 12686 return reloc_type == 2; /* R_386_PC32. */
aca88567 12687 case EM_68K:
3e0873ac 12688 return reloc_type == 4; /* R_68K_PC32. */
a06ea964
NC
12689 case EM_AARCH64:
12690 return reloc_type == 261; /* R_AARCH64_PREL32 */
cfb8c092
NC
12691 case EM_ADAPTEVA_EPIPHANY:
12692 return reloc_type == 6;
aca88567
NC
12693 case EM_ALPHA:
12694 return reloc_type == 10; /* R_ALPHA_SREL32. */
726c18e1
CZ
12695 case EM_ARC_COMPACT:
12696 case EM_ARC_COMPACT2:
12697 return reloc_type == 49; /* R_ARC_32_PCREL. */
41e92641 12698 case EM_ARM:
3e0873ac 12699 return reloc_type == 3; /* R_ARM_REL32 */
d347c9df
PS
12700 case EM_AVR_OLD:
12701 case EM_AVR:
12702 return reloc_type == 36; /* R_AVR_32_PCREL. */
137b6b5f
AM
12703 case EM_MICROBLAZE:
12704 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
73589c9d
CS
12705 case EM_OR1K:
12706 return reloc_type == 9; /* R_OR1K_32_PCREL. */
aca88567 12707 case EM_PARISC:
85acf597 12708 return reloc_type == 9; /* R_PARISC_PCREL32. */
aca88567
NC
12709 case EM_PPC:
12710 return reloc_type == 26; /* R_PPC_REL32. */
12711 case EM_PPC64:
3e0873ac 12712 return reloc_type == 26; /* R_PPC64_REL32. */
25cbdcbb
AS
12713 case EM_RISCV:
12714 return reloc_type == 57; /* R_RISCV_32_PCREL. */
aca88567
NC
12715 case EM_S390_OLD:
12716 case EM_S390:
3e0873ac 12717 return reloc_type == 5; /* R_390_PC32. */
aca88567 12718 case EM_SH:
3e0873ac 12719 return reloc_type == 2; /* R_SH_REL32. */
aca88567
NC
12720 case EM_SPARC32PLUS:
12721 case EM_SPARCV9:
12722 case EM_SPARC:
3e0873ac 12723 return reloc_type == 6; /* R_SPARC_DISP32. */
a7dd7d05
AM
12724 case EM_SPU:
12725 return reloc_type == 13; /* R_SPU_REL32. */
aa137e4d
NC
12726 case EM_TILEGX:
12727 return reloc_type == 6; /* R_TILEGX_32_PCREL. */
12728 case EM_TILEPRO:
12729 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
619ed720
EB
12730 case EM_VISIUM:
12731 return reloc_type == 6; /* R_VISIUM_32_PCREL */
aca88567 12732 case EM_X86_64:
8a9036a4 12733 case EM_L1OM:
7a9068fe 12734 case EM_K1OM:
3e0873ac 12735 return reloc_type == 2; /* R_X86_64_PC32. */
2fcb9706
BW
12736 case EM_XTENSA_OLD:
12737 case EM_XTENSA:
12738 return reloc_type == 14; /* R_XTENSA_32_PCREL. */
aca88567
NC
12739 default:
12740 /* Do not abort or issue an error message here. Not all targets use
12741 pc-relative 32-bit relocs in their DWARF debug information and we
12742 have already tested for target coverage in is_32bit_abs_reloc. A
cf13d699
NC
12743 more helpful warning message will be generated by apply_relocations
12744 anyway, so just return. */
aca88567
NC
12745 return FALSE;
12746 }
12747}
12748
12749/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12750 a 64-bit absolute RELA relocation used in DWARF debug sections. */
12751
12752static bfd_boolean
dda8d76d 12753is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 12754{
dda8d76d 12755 switch (filedata->file_header.e_machine)
aca88567 12756 {
a06ea964
NC
12757 case EM_AARCH64:
12758 return reloc_type == 257; /* R_AARCH64_ABS64. */
aca88567
NC
12759 case EM_ALPHA:
12760 return reloc_type == 2; /* R_ALPHA_REFQUAD. */
3730236a 12761 case EM_IA_64:
262cdac7
AM
12762 return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */
12763 || reloc_type == 0x27 /* R_IA64_DIR64LSB. */);
3e0873ac
NC
12764 case EM_PARISC:
12765 return reloc_type == 80; /* R_PARISC_DIR64. */
aca88567
NC
12766 case EM_PPC64:
12767 return reloc_type == 38; /* R_PPC64_ADDR64. */
e23eba97
NC
12768 case EM_RISCV:
12769 return reloc_type == 2; /* R_RISCV_64. */
aca88567
NC
12770 case EM_SPARC32PLUS:
12771 case EM_SPARCV9:
12772 case EM_SPARC:
714da62f
NC
12773 return reloc_type == 32 /* R_SPARC_64. */
12774 || reloc_type == 54; /* R_SPARC_UA64. */
aca88567 12775 case EM_X86_64:
8a9036a4 12776 case EM_L1OM:
7a9068fe 12777 case EM_K1OM:
aca88567 12778 return reloc_type == 1; /* R_X86_64_64. */
e819ade1
AS
12779 case EM_S390_OLD:
12780 case EM_S390:
aa137e4d
NC
12781 return reloc_type == 22; /* R_S390_64. */
12782 case EM_TILEGX:
12783 return reloc_type == 1; /* R_TILEGX_64. */
85a82265 12784 case EM_MIPS:
aa137e4d 12785 return reloc_type == 18; /* R_MIPS_64. */
aca88567
NC
12786 default:
12787 return FALSE;
12788 }
12789}
12790
85acf597
RH
12791/* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
12792 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
12793
12794static bfd_boolean
dda8d76d 12795is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
85acf597 12796{
dda8d76d 12797 switch (filedata->file_header.e_machine)
85acf597 12798 {
a06ea964
NC
12799 case EM_AARCH64:
12800 return reloc_type == 260; /* R_AARCH64_PREL64. */
85acf597 12801 case EM_ALPHA:
aa137e4d 12802 return reloc_type == 11; /* R_ALPHA_SREL64. */
85acf597 12803 case EM_IA_64:
262cdac7
AM
12804 return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */
12805 || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */);
85acf597 12806 case EM_PARISC:
aa137e4d 12807 return reloc_type == 72; /* R_PARISC_PCREL64. */
85acf597 12808 case EM_PPC64:
aa137e4d 12809 return reloc_type == 44; /* R_PPC64_REL64. */
85acf597
RH
12810 case EM_SPARC32PLUS:
12811 case EM_SPARCV9:
12812 case EM_SPARC:
aa137e4d 12813 return reloc_type == 46; /* R_SPARC_DISP64. */
85acf597 12814 case EM_X86_64:
8a9036a4 12815 case EM_L1OM:
7a9068fe 12816 case EM_K1OM:
aa137e4d 12817 return reloc_type == 24; /* R_X86_64_PC64. */
85acf597
RH
12818 case EM_S390_OLD:
12819 case EM_S390:
aa137e4d
NC
12820 return reloc_type == 23; /* R_S390_PC64. */
12821 case EM_TILEGX:
12822 return reloc_type == 5; /* R_TILEGX_64_PCREL. */
85acf597
RH
12823 default:
12824 return FALSE;
12825 }
12826}
12827
4dc3c23d
AM
12828/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12829 a 24-bit absolute RELA relocation used in DWARF debug sections. */
12830
12831static bfd_boolean
dda8d76d 12832is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
4dc3c23d 12833{
dda8d76d 12834 switch (filedata->file_header.e_machine)
4dc3c23d
AM
12835 {
12836 case EM_CYGNUS_MN10200:
12837 case EM_MN10200:
12838 return reloc_type == 4; /* R_MN10200_24. */
3ee6e4fb
NC
12839 case EM_FT32:
12840 return reloc_type == 5; /* R_FT32_20. */
4dc3c23d
AM
12841 default:
12842 return FALSE;
12843 }
12844}
12845
aca88567
NC
12846/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12847 a 16-bit absolute RELA relocation used in DWARF debug sections. */
12848
12849static bfd_boolean
dda8d76d 12850is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
4b78141a 12851{
d347c9df 12852 /* Please keep this table alpha-sorted for ease of visual lookup. */
dda8d76d 12853 switch (filedata->file_header.e_machine)
4b78141a 12854 {
886a2506
NC
12855 case EM_ARC:
12856 case EM_ARC_COMPACT:
12857 case EM_ARC_COMPACT2:
12858 return reloc_type == 2; /* R_ARC_16. */
d347c9df
PS
12859 case EM_ADAPTEVA_EPIPHANY:
12860 return reloc_type == 5;
aca88567
NC
12861 case EM_AVR_OLD:
12862 case EM_AVR:
12863 return reloc_type == 4; /* R_AVR_16. */
41e92641
NC
12864 case EM_CYGNUS_D10V:
12865 case EM_D10V:
12866 return reloc_type == 3; /* R_D10V_16. */
81b42bca
JB
12867 case EM_FT32:
12868 return reloc_type == 2; /* R_FT32_16. */
4b78141a
NC
12869 case EM_H8S:
12870 case EM_H8_300:
12871 case EM_H8_300H:
aca88567
NC
12872 return reloc_type == R_H8_DIR16;
12873 case EM_IP2K_OLD:
12874 case EM_IP2K:
12875 return reloc_type == 1; /* R_IP2K_16. */
ff7eeb89 12876 case EM_M32C_OLD:
f4236fe4
DD
12877 case EM_M32C:
12878 return reloc_type == 1; /* R_M32C_16 */
d347c9df
PS
12879 case EM_CYGNUS_MN10200:
12880 case EM_MN10200:
12881 return reloc_type == 2; /* R_MN10200_16. */
12882 case EM_CYGNUS_MN10300:
12883 case EM_MN10300:
12884 return reloc_type == 2; /* R_MN10300_16. */
aca88567 12885 case EM_MSP430:
dda8d76d 12886 if (uses_msp430x_relocs (filedata))
13761a11 12887 return reloc_type == 2; /* R_MSP430_ABS16. */
1a0670f3 12888 /* Fall through. */
78c8d46c 12889 case EM_MSP430_OLD:
aca88567 12890 return reloc_type == 5; /* R_MSP430_16_BYTE. */
35c08157
KLC
12891 case EM_NDS32:
12892 return reloc_type == 19; /* R_NDS32_RELA. */
3e0873ac 12893 case EM_ALTERA_NIOS2:
36591ba1 12894 return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
3e0873ac
NC
12895 case EM_NIOS32:
12896 return reloc_type == 9; /* R_NIOS_16. */
73589c9d
CS
12897 case EM_OR1K:
12898 return reloc_type == 2; /* R_OR1K_16. */
39e07931
AS
12899 case EM_RISCV:
12900 return reloc_type == 55; /* R_RISCV_SET16. */
2b100bb5
DD
12901 case EM_TI_PRU:
12902 return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */
40b36596
JM
12903 case EM_TI_C6000:
12904 return reloc_type == 2; /* R_C6000_ABS16. */
d347c9df
PS
12905 case EM_VISIUM:
12906 return reloc_type == 2; /* R_VISIUM_16. */
c29aca4a
NC
12907 case EM_XC16X:
12908 case EM_C166:
12909 return reloc_type == 2; /* R_XC16C_ABS_16. */
f6c1a2d5
NC
12910 case EM_XGATE:
12911 return reloc_type == 3; /* R_XGATE_16. */
4b78141a 12912 default:
aca88567 12913 return FALSE;
4b78141a
NC
12914 }
12915}
12916
39e07931
AS
12917/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12918 a 8-bit absolute RELA relocation used in DWARF debug sections. */
12919
12920static bfd_boolean
12921is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12922{
12923 switch (filedata->file_header.e_machine)
12924 {
12925 case EM_RISCV:
12926 return reloc_type == 54; /* R_RISCV_SET8. */
12927 default:
12928 return FALSE;
12929 }
12930}
12931
12932/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12933 a 6-bit absolute RELA relocation used in DWARF debug sections. */
12934
12935static bfd_boolean
12936is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12937{
12938 switch (filedata->file_header.e_machine)
12939 {
12940 case EM_RISCV:
12941 return reloc_type == 53; /* R_RISCV_SET6. */
12942 default:
12943 return FALSE;
12944 }
12945}
12946
03336641
JW
12947/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12948 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
12949
12950static bfd_boolean
12951is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
12952{
12953 /* Please keep this table alpha-sorted for ease of visual lookup. */
12954 switch (filedata->file_header.e_machine)
12955 {
12956 case EM_RISCV:
12957 return reloc_type == 35; /* R_RISCV_ADD32. */
12958 default:
12959 return FALSE;
12960 }
12961}
12962
12963/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12964 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
12965
12966static bfd_boolean
12967is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
12968{
12969 /* Please keep this table alpha-sorted for ease of visual lookup. */
12970 switch (filedata->file_header.e_machine)
12971 {
12972 case EM_RISCV:
12973 return reloc_type == 39; /* R_RISCV_SUB32. */
12974 default:
12975 return FALSE;
12976 }
12977}
12978
12979/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12980 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
12981
12982static bfd_boolean
12983is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
12984{
12985 /* Please keep this table alpha-sorted for ease of visual lookup. */
12986 switch (filedata->file_header.e_machine)
12987 {
12988 case EM_RISCV:
12989 return reloc_type == 36; /* R_RISCV_ADD64. */
12990 default:
12991 return FALSE;
12992 }
12993}
12994
12995/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12996 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
12997
12998static bfd_boolean
12999is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13000{
13001 /* Please keep this table alpha-sorted for ease of visual lookup. */
13002 switch (filedata->file_header.e_machine)
13003 {
13004 case EM_RISCV:
13005 return reloc_type == 40; /* R_RISCV_SUB64. */
13006 default:
13007 return FALSE;
13008 }
13009}
13010
13011/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13012 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
13013
13014static bfd_boolean
13015is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13016{
13017 /* Please keep this table alpha-sorted for ease of visual lookup. */
13018 switch (filedata->file_header.e_machine)
13019 {
13020 case EM_RISCV:
13021 return reloc_type == 34; /* R_RISCV_ADD16. */
13022 default:
13023 return FALSE;
13024 }
13025}
13026
13027/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13028 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
13029
13030static bfd_boolean
13031is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13032{
13033 /* Please keep this table alpha-sorted for ease of visual lookup. */
13034 switch (filedata->file_header.e_machine)
13035 {
13036 case EM_RISCV:
13037 return reloc_type == 38; /* R_RISCV_SUB16. */
13038 default:
13039 return FALSE;
13040 }
13041}
13042
13043/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13044 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
13045
13046static bfd_boolean
13047is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13048{
13049 /* Please keep this table alpha-sorted for ease of visual lookup. */
13050 switch (filedata->file_header.e_machine)
13051 {
13052 case EM_RISCV:
13053 return reloc_type == 33; /* R_RISCV_ADD8. */
13054 default:
13055 return FALSE;
13056 }
13057}
13058
13059/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13060 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
13061
13062static bfd_boolean
13063is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13064{
13065 /* Please keep this table alpha-sorted for ease of visual lookup. */
13066 switch (filedata->file_header.e_machine)
13067 {
13068 case EM_RISCV:
13069 return reloc_type == 37; /* R_RISCV_SUB8. */
13070 default:
13071 return FALSE;
13072 }
13073}
13074
39e07931
AS
13075/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13076 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
13077
13078static bfd_boolean
13079is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13080{
13081 switch (filedata->file_header.e_machine)
13082 {
13083 case EM_RISCV:
13084 return reloc_type == 52; /* R_RISCV_SUB6. */
13085 default:
13086 return FALSE;
13087 }
13088}
13089
2a7b2e88
JK
13090/* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
13091 relocation entries (possibly formerly used for SHT_GROUP sections). */
13092
13093static bfd_boolean
dda8d76d 13094is_none_reloc (Filedata * filedata, unsigned int reloc_type)
2a7b2e88 13095{
dda8d76d 13096 switch (filedata->file_header.e_machine)
2a7b2e88 13097 {
cb8f3167 13098 case EM_386: /* R_386_NONE. */
d347c9df 13099 case EM_68K: /* R_68K_NONE. */
cfb8c092 13100 case EM_ADAPTEVA_EPIPHANY:
d347c9df
PS
13101 case EM_ALPHA: /* R_ALPHA_NONE. */
13102 case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
886a2506 13103 case EM_ARC: /* R_ARC_NONE. */
886a2506 13104 case EM_ARC_COMPACT2: /* R_ARC_NONE. */
d347c9df 13105 case EM_ARC_COMPACT: /* R_ARC_NONE. */
cb8f3167 13106 case EM_ARM: /* R_ARM_NONE. */
d347c9df 13107 case EM_C166: /* R_XC16X_NONE. */
cb8f3167 13108 case EM_CRIS: /* R_CRIS_NONE. */
d347c9df
PS
13109 case EM_FT32: /* R_FT32_NONE. */
13110 case EM_IA_64: /* R_IA64_NONE. */
7a9068fe 13111 case EM_K1OM: /* R_X86_64_NONE. */
d347c9df
PS
13112 case EM_L1OM: /* R_X86_64_NONE. */
13113 case EM_M32R: /* R_M32R_NONE. */
13114 case EM_MIPS: /* R_MIPS_NONE. */
cb8f3167 13115 case EM_MN10300: /* R_MN10300_NONE. */
5506d11a 13116 case EM_MOXIE: /* R_MOXIE_NONE. */
d347c9df
PS
13117 case EM_NIOS32: /* R_NIOS_NONE. */
13118 case EM_OR1K: /* R_OR1K_NONE. */
13119 case EM_PARISC: /* R_PARISC_NONE. */
13120 case EM_PPC64: /* R_PPC64_NONE. */
13121 case EM_PPC: /* R_PPC_NONE. */
e23eba97 13122 case EM_RISCV: /* R_RISCV_NONE. */
d347c9df
PS
13123 case EM_S390: /* R_390_NONE. */
13124 case EM_S390_OLD:
13125 case EM_SH: /* R_SH_NONE. */
13126 case EM_SPARC32PLUS:
13127 case EM_SPARC: /* R_SPARC_NONE. */
13128 case EM_SPARCV9:
aa137e4d
NC
13129 case EM_TILEGX: /* R_TILEGX_NONE. */
13130 case EM_TILEPRO: /* R_TILEPRO_NONE. */
d347c9df
PS
13131 case EM_TI_C6000:/* R_C6000_NONE. */
13132 case EM_X86_64: /* R_X86_64_NONE. */
c29aca4a 13133 case EM_XC16X:
f96bd6c2 13134 case EM_WEBASSEMBLY: /* R_WASM32_NONE. */
cb8f3167 13135 return reloc_type == 0;
d347c9df 13136
a06ea964
NC
13137 case EM_AARCH64:
13138 return reloc_type == 0 || reloc_type == 256;
d347c9df
PS
13139 case EM_AVR_OLD:
13140 case EM_AVR:
13141 return (reloc_type == 0 /* R_AVR_NONE. */
13142 || reloc_type == 30 /* R_AVR_DIFF8. */
13143 || reloc_type == 31 /* R_AVR_DIFF16. */
13144 || reloc_type == 32 /* R_AVR_DIFF32. */);
13145 case EM_METAG:
13146 return reloc_type == 3; /* R_METAG_NONE. */
35c08157
KLC
13147 case EM_NDS32:
13148 return (reloc_type == 0 /* R_XTENSA_NONE. */
13149 || reloc_type == 204 /* R_NDS32_DIFF8. */
13150 || reloc_type == 205 /* R_NDS32_DIFF16. */
13151 || reloc_type == 206 /* R_NDS32_DIFF32. */
13152 || reloc_type == 207 /* R_NDS32_ULEB128. */);
2b100bb5
DD
13153 case EM_TI_PRU:
13154 return (reloc_type == 0 /* R_PRU_NONE. */
13155 || reloc_type == 65 /* R_PRU_DIFF8. */
13156 || reloc_type == 66 /* R_PRU_DIFF16. */
13157 || reloc_type == 67 /* R_PRU_DIFF32. */);
58332dda
JK
13158 case EM_XTENSA_OLD:
13159 case EM_XTENSA:
4dc3c23d
AM
13160 return (reloc_type == 0 /* R_XTENSA_NONE. */
13161 || reloc_type == 17 /* R_XTENSA_DIFF8. */
13162 || reloc_type == 18 /* R_XTENSA_DIFF16. */
13163 || reloc_type == 19 /* R_XTENSA_DIFF32. */);
2a7b2e88
JK
13164 }
13165 return FALSE;
13166}
13167
d1c4b12b
NC
13168/* Returns TRUE if there is a relocation against
13169 section NAME at OFFSET bytes. */
13170
13171bfd_boolean
13172reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
13173{
13174 Elf_Internal_Rela * relocs;
13175 Elf_Internal_Rela * rp;
13176
13177 if (dsec == NULL || dsec->reloc_info == NULL)
13178 return FALSE;
13179
13180 relocs = (Elf_Internal_Rela *) dsec->reloc_info;
13181
13182 for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
13183 if (rp->r_offset == offset)
13184 return TRUE;
13185
13186 return FALSE;
13187}
13188
cf13d699 13189/* Apply relocations to a section.
32ec8896
NC
13190 Returns TRUE upon success, FALSE otherwise.
13191 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
13192 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
13193 will be set to the number of relocs loaded.
13194
cf13d699 13195 Note: So far support has been added only for those relocations
32ec8896
NC
13196 which can be found in debug sections. FIXME: Add support for
13197 more relocations ? */
1b315056 13198
32ec8896 13199static bfd_boolean
dda8d76d 13200apply_relocations (Filedata * filedata,
d1c4b12b
NC
13201 const Elf_Internal_Shdr * section,
13202 unsigned char * start,
13203 bfd_size_type size,
1449284b 13204 void ** relocs_return,
d1c4b12b 13205 unsigned long * num_relocs_return)
1b315056 13206{
cf13d699 13207 Elf_Internal_Shdr * relsec;
0d2a7a93 13208 unsigned char * end = start + size;
cb8f3167 13209
d1c4b12b
NC
13210 if (relocs_return != NULL)
13211 {
13212 * (Elf_Internal_Rela **) relocs_return = NULL;
13213 * num_relocs_return = 0;
13214 }
13215
dda8d76d 13216 if (filedata->file_header.e_type != ET_REL)
32ec8896
NC
13217 /* No relocs to apply. */
13218 return TRUE;
1b315056 13219
cf13d699 13220 /* Find the reloc section associated with the section. */
dda8d76d
NC
13221 for (relsec = filedata->section_headers;
13222 relsec < filedata->section_headers + filedata->file_header.e_shnum;
5b18a4bc 13223 ++relsec)
252b5132 13224 {
41e92641
NC
13225 bfd_boolean is_rela;
13226 unsigned long num_relocs;
2cf0635d
NC
13227 Elf_Internal_Rela * relocs;
13228 Elf_Internal_Rela * rp;
13229 Elf_Internal_Shdr * symsec;
13230 Elf_Internal_Sym * symtab;
ba5cdace 13231 unsigned long num_syms;
2cf0635d 13232 Elf_Internal_Sym * sym;
252b5132 13233
41e92641 13234 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
13235 || relsec->sh_info >= filedata->file_header.e_shnum
13236 || filedata->section_headers + relsec->sh_info != section
c256ffe7 13237 || relsec->sh_size == 0
dda8d76d 13238 || relsec->sh_link >= filedata->file_header.e_shnum)
5b18a4bc 13239 continue;
428409d5 13240
41e92641
NC
13241 is_rela = relsec->sh_type == SHT_RELA;
13242
13243 if (is_rela)
13244 {
dda8d76d 13245 if (!slurp_rela_relocs (filedata, relsec->sh_offset,
3f5e193b 13246 relsec->sh_size, & relocs, & num_relocs))
32ec8896 13247 return FALSE;
41e92641
NC
13248 }
13249 else
13250 {
dda8d76d 13251 if (!slurp_rel_relocs (filedata, relsec->sh_offset,
3f5e193b 13252 relsec->sh_size, & relocs, & num_relocs))
32ec8896 13253 return FALSE;
41e92641
NC
13254 }
13255
13256 /* SH uses RELA but uses in place value instead of the addend field. */
dda8d76d 13257 if (filedata->file_header.e_machine == EM_SH)
41e92641 13258 is_rela = FALSE;
428409d5 13259
dda8d76d 13260 symsec = filedata->section_headers + relsec->sh_link;
1449284b
NC
13261 if (symsec->sh_type != SHT_SYMTAB
13262 && symsec->sh_type != SHT_DYNSYM)
32ec8896 13263 return FALSE;
dda8d76d 13264 symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms);
103f02d3 13265
41e92641 13266 for (rp = relocs; rp < relocs + num_relocs; ++rp)
252b5132 13267 {
41e92641
NC
13268 bfd_vma addend;
13269 unsigned int reloc_type;
13270 unsigned int reloc_size;
03336641
JW
13271 bfd_boolean reloc_inplace = FALSE;
13272 bfd_boolean reloc_subtract = FALSE;
91d6fa6a 13273 unsigned char * rloc;
ba5cdace 13274 unsigned long sym_index;
4b78141a 13275
dda8d76d 13276 reloc_type = get_reloc_type (filedata, rp->r_info);
41e92641 13277
dda8d76d 13278 if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms))
2a7b2e88 13279 continue;
dda8d76d 13280 else if (is_none_reloc (filedata, reloc_type))
98fb390a 13281 continue;
dda8d76d
NC
13282 else if (is_32bit_abs_reloc (filedata, reloc_type)
13283 || is_32bit_pcrel_reloc (filedata, reloc_type))
aca88567 13284 reloc_size = 4;
dda8d76d
NC
13285 else if (is_64bit_abs_reloc (filedata, reloc_type)
13286 || is_64bit_pcrel_reloc (filedata, reloc_type))
aca88567 13287 reloc_size = 8;
dda8d76d 13288 else if (is_24bit_abs_reloc (filedata, reloc_type))
4dc3c23d 13289 reloc_size = 3;
dda8d76d 13290 else if (is_16bit_abs_reloc (filedata, reloc_type))
aca88567 13291 reloc_size = 2;
39e07931
AS
13292 else if (is_8bit_abs_reloc (filedata, reloc_type)
13293 || is_6bit_abs_reloc (filedata, reloc_type))
13294 reloc_size = 1;
03336641
JW
13295 else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
13296 reloc_type))
13297 || is_32bit_inplace_add_reloc (filedata, reloc_type))
13298 {
13299 reloc_size = 4;
13300 reloc_inplace = TRUE;
13301 }
13302 else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata,
13303 reloc_type))
13304 || is_64bit_inplace_add_reloc (filedata, reloc_type))
13305 {
13306 reloc_size = 8;
13307 reloc_inplace = TRUE;
13308 }
13309 else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata,
13310 reloc_type))
13311 || is_16bit_inplace_add_reloc (filedata, reloc_type))
13312 {
13313 reloc_size = 2;
13314 reloc_inplace = TRUE;
13315 }
13316 else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata,
13317 reloc_type))
13318 || is_8bit_inplace_add_reloc (filedata, reloc_type))
13319 {
13320 reloc_size = 1;
13321 reloc_inplace = TRUE;
13322 }
39e07931
AS
13323 else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata,
13324 reloc_type)))
13325 {
13326 reloc_size = 1;
13327 reloc_inplace = TRUE;
13328 }
aca88567 13329 else
4b78141a 13330 {
bee0ee85 13331 static unsigned int prev_reloc = 0;
dda8d76d 13332
bee0ee85
NC
13333 if (reloc_type != prev_reloc)
13334 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
dda8d76d 13335 reloc_type, printable_section_name (filedata, section));
bee0ee85 13336 prev_reloc = reloc_type;
4b78141a
NC
13337 continue;
13338 }
103f02d3 13339
91d6fa6a 13340 rloc = start + rp->r_offset;
c8da6823 13341 if ((rloc + reloc_size) > end || (rloc < start))
700dd8b7
L
13342 {
13343 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
13344 (unsigned long) rp->r_offset,
dda8d76d 13345 printable_section_name (filedata, section));
700dd8b7
L
13346 continue;
13347 }
103f02d3 13348
ba5cdace
NC
13349 sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
13350 if (sym_index >= num_syms)
13351 {
13352 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
dda8d76d 13353 sym_index, printable_section_name (filedata, section));
ba5cdace
NC
13354 continue;
13355 }
13356 sym = symtab + sym_index;
41e92641
NC
13357
13358 /* If the reloc has a symbol associated with it,
55f25fc3
L
13359 make sure that it is of an appropriate type.
13360
13361 Relocations against symbols without type can happen.
13362 Gcc -feliminate-dwarf2-dups may generate symbols
13363 without type for debug info.
13364
13365 Icc generates relocations against function symbols
13366 instead of local labels.
13367
13368 Relocations against object symbols can happen, eg when
13369 referencing a global array. For an example of this see
13370 the _clz.o binary in libgcc.a. */
aca88567 13371 if (sym != symtab
b8871f35 13372 && ELF_ST_TYPE (sym->st_info) != STT_COMMON
55f25fc3 13373 && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
5b18a4bc 13374 {
d3a49aa8 13375 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
dda8d76d
NC
13376 get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)),
13377 printable_section_name (filedata, relsec),
d3a49aa8 13378 (long int)(rp - relocs));
aca88567 13379 continue;
5b18a4bc 13380 }
252b5132 13381
4dc3c23d
AM
13382 addend = 0;
13383 if (is_rela)
13384 addend += rp->r_addend;
c47320c3
AM
13385 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
13386 partial_inplace. */
4dc3c23d 13387 if (!is_rela
dda8d76d 13388 || (filedata->file_header.e_machine == EM_XTENSA
4dc3c23d 13389 && reloc_type == 1)
dda8d76d
NC
13390 || ((filedata->file_header.e_machine == EM_PJ
13391 || filedata->file_header.e_machine == EM_PJ_OLD)
c47320c3 13392 && reloc_type == 1)
dda8d76d
NC
13393 || ((filedata->file_header.e_machine == EM_D30V
13394 || filedata->file_header.e_machine == EM_CYGNUS_D30V)
03336641
JW
13395 && reloc_type == 12)
13396 || reloc_inplace)
39e07931
AS
13397 {
13398 if (is_6bit_inplace_sub_reloc (filedata, reloc_type))
13399 addend += byte_get (rloc, reloc_size) & 0x3f;
13400 else
13401 addend += byte_get (rloc, reloc_size);
13402 }
cb8f3167 13403
dda8d76d
NC
13404 if (is_32bit_pcrel_reloc (filedata, reloc_type)
13405 || is_64bit_pcrel_reloc (filedata, reloc_type))
85acf597
RH
13406 {
13407 /* On HPPA, all pc-relative relocations are biased by 8. */
dda8d76d 13408 if (filedata->file_header.e_machine == EM_PARISC)
85acf597 13409 addend -= 8;
91d6fa6a 13410 byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
85acf597
RH
13411 reloc_size);
13412 }
39e07931
AS
13413 else if (is_6bit_abs_reloc (filedata, reloc_type)
13414 || is_6bit_inplace_sub_reloc (filedata, reloc_type))
13415 {
13416 if (reloc_subtract)
13417 addend -= sym->st_value;
13418 else
13419 addend += sym->st_value;
13420 addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0);
13421 byte_put (rloc, addend, reloc_size);
13422 }
03336641
JW
13423 else if (reloc_subtract)
13424 byte_put (rloc, addend - sym->st_value, reloc_size);
41e92641 13425 else
91d6fa6a 13426 byte_put (rloc, addend + sym->st_value, reloc_size);
5b18a4bc 13427 }
252b5132 13428
5b18a4bc 13429 free (symtab);
f84ce13b
NC
13430 /* Let the target specific reloc processing code know that
13431 we have finished with these relocs. */
dda8d76d 13432 target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0);
d1c4b12b
NC
13433
13434 if (relocs_return)
13435 {
13436 * (Elf_Internal_Rela **) relocs_return = relocs;
13437 * num_relocs_return = num_relocs;
13438 }
13439 else
13440 free (relocs);
13441
5b18a4bc
NC
13442 break;
13443 }
32ec8896 13444
dfc616fa 13445 return TRUE;
5b18a4bc 13446}
103f02d3 13447
cf13d699 13448#ifdef SUPPORT_DISASSEMBLY
32ec8896 13449static bfd_boolean
dda8d76d 13450disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 13451{
dda8d76d 13452 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section));
cf13d699 13453
74e1a04b 13454 /* FIXME: XXX -- to be done --- XXX */
cf13d699 13455
32ec8896 13456 return TRUE;
cf13d699
NC
13457}
13458#endif
13459
13460/* Reads in the contents of SECTION from FILE, returning a pointer
13461 to a malloc'ed buffer or NULL if something went wrong. */
13462
13463static char *
dda8d76d 13464get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 13465{
dda8d76d 13466 bfd_size_type num_bytes = section->sh_size;
cf13d699
NC
13467
13468 if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
13469 {
c6b78c96 13470 printf (_("Section '%s' has no data to dump.\n"),
dda8d76d 13471 printable_section_name (filedata, section));
cf13d699
NC
13472 return NULL;
13473 }
13474
dda8d76d 13475 return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes,
3f5e193b 13476 _("section contents"));
cf13d699
NC
13477}
13478
0e602686
NC
13479/* Uncompresses a section that was compressed using zlib, in place. */
13480
13481static bfd_boolean
dda8d76d
NC
13482uncompress_section_contents (unsigned char ** buffer,
13483 dwarf_size_type uncompressed_size,
13484 dwarf_size_type * size)
0e602686
NC
13485{
13486 dwarf_size_type compressed_size = *size;
13487 unsigned char * compressed_buffer = *buffer;
13488 unsigned char * uncompressed_buffer;
13489 z_stream strm;
13490 int rc;
13491
13492 /* It is possible the section consists of several compressed
13493 buffers concatenated together, so we uncompress in a loop. */
13494 /* PR 18313: The state field in the z_stream structure is supposed
13495 to be invisible to the user (ie us), but some compilers will
13496 still complain about it being used without initialisation. So
13497 we first zero the entire z_stream structure and then set the fields
13498 that we need. */
13499 memset (& strm, 0, sizeof strm);
13500 strm.avail_in = compressed_size;
13501 strm.next_in = (Bytef *) compressed_buffer;
13502 strm.avail_out = uncompressed_size;
13503 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
13504
13505 rc = inflateInit (& strm);
13506 while (strm.avail_in > 0)
13507 {
13508 if (rc != Z_OK)
13509 goto fail;
13510 strm.next_out = ((Bytef *) uncompressed_buffer
13511 + (uncompressed_size - strm.avail_out));
13512 rc = inflate (&strm, Z_FINISH);
13513 if (rc != Z_STREAM_END)
13514 goto fail;
13515 rc = inflateReset (& strm);
13516 }
13517 rc = inflateEnd (& strm);
13518 if (rc != Z_OK
13519 || strm.avail_out != 0)
13520 goto fail;
13521
13522 *buffer = uncompressed_buffer;
13523 *size = uncompressed_size;
13524 return TRUE;
13525
13526 fail:
13527 free (uncompressed_buffer);
13528 /* Indicate decompression failure. */
13529 *buffer = NULL;
13530 return FALSE;
13531}
dd24e3da 13532
32ec8896 13533static bfd_boolean
dda8d76d 13534dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 13535{
0e602686
NC
13536 Elf_Internal_Shdr * relsec;
13537 bfd_size_type num_bytes;
fd8008d8
L
13538 unsigned char * data;
13539 unsigned char * end;
13540 unsigned char * real_start;
13541 unsigned char * start;
0e602686 13542 bfd_boolean some_strings_shown;
cf13d699 13543
dda8d76d 13544 real_start = start = (unsigned char *) get_section_contents (section, filedata);
cf13d699 13545 if (start == NULL)
c6b78c96
NC
13546 /* PR 21820: Do not fail if the section was empty. */
13547 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
13548
0e602686 13549 num_bytes = section->sh_size;
cf13d699 13550
dda8d76d 13551 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata, section));
cf13d699 13552
0e602686
NC
13553 if (decompress_dumps)
13554 {
13555 dwarf_size_type new_size = num_bytes;
13556 dwarf_size_type uncompressed_size = 0;
13557
13558 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13559 {
13560 Elf_Internal_Chdr chdr;
13561 unsigned int compression_header_size
ebdf1ebf
NC
13562 = get_compression_header (& chdr, (unsigned char *) start,
13563 num_bytes);
0e602686 13564
813dabb9 13565 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
0e602686 13566 {
813dabb9 13567 warn (_("section '%s' has unsupported compress type: %d\n"),
dda8d76d 13568 printable_section_name (filedata, section), chdr.ch_type);
32ec8896 13569 return FALSE;
813dabb9 13570 }
813dabb9
L
13571 uncompressed_size = chdr.ch_size;
13572 start += compression_header_size;
13573 new_size -= compression_header_size;
0e602686
NC
13574 }
13575 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13576 {
13577 /* Read the zlib header. In this case, it should be "ZLIB"
13578 followed by the uncompressed section size, 8 bytes in
13579 big-endian order. */
13580 uncompressed_size = start[4]; uncompressed_size <<= 8;
13581 uncompressed_size += start[5]; uncompressed_size <<= 8;
13582 uncompressed_size += start[6]; uncompressed_size <<= 8;
13583 uncompressed_size += start[7]; uncompressed_size <<= 8;
13584 uncompressed_size += start[8]; uncompressed_size <<= 8;
13585 uncompressed_size += start[9]; uncompressed_size <<= 8;
13586 uncompressed_size += start[10]; uncompressed_size <<= 8;
13587 uncompressed_size += start[11];
13588 start += 12;
13589 new_size -= 12;
13590 }
13591
1835f746
NC
13592 if (uncompressed_size)
13593 {
13594 if (uncompress_section_contents (& start,
13595 uncompressed_size, & new_size))
13596 num_bytes = new_size;
13597 else
13598 {
13599 error (_("Unable to decompress section %s\n"),
dda8d76d 13600 printable_section_name (filedata, section));
32ec8896 13601 return FALSE;
1835f746
NC
13602 }
13603 }
bc303e5d
NC
13604 else
13605 start = real_start;
0e602686 13606 }
fd8008d8 13607
cf13d699
NC
13608 /* If the section being dumped has relocations against it the user might
13609 be expecting these relocations to have been applied. Check for this
13610 case and issue a warning message in order to avoid confusion.
13611 FIXME: Maybe we ought to have an option that dumps a section with
13612 relocs applied ? */
dda8d76d
NC
13613 for (relsec = filedata->section_headers;
13614 relsec < filedata->section_headers + filedata->file_header.e_shnum;
cf13d699
NC
13615 ++relsec)
13616 {
13617 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
13618 || relsec->sh_info >= filedata->file_header.e_shnum
13619 || filedata->section_headers + relsec->sh_info != section
cf13d699 13620 || relsec->sh_size == 0
dda8d76d 13621 || relsec->sh_link >= filedata->file_header.e_shnum)
cf13d699
NC
13622 continue;
13623
13624 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13625 break;
13626 }
13627
cf13d699
NC
13628 data = start;
13629 end = start + num_bytes;
13630 some_strings_shown = FALSE;
13631
13632 while (data < end)
13633 {
13634 while (!ISPRINT (* data))
13635 if (++ data >= end)
13636 break;
13637
13638 if (data < end)
13639 {
071436c6
NC
13640 size_t maxlen = end - data;
13641
cf13d699 13642#ifndef __MSVCRT__
c975cc98
NC
13643 /* PR 11128: Use two separate invocations in order to work
13644 around bugs in the Solaris 8 implementation of printf. */
13645 printf (" [%6tx] ", data - start);
cf13d699 13646#else
071436c6 13647 printf (" [%6Ix] ", (size_t) (data - start));
cf13d699 13648#endif
4082ef84
NC
13649 if (maxlen > 0)
13650 {
fd8008d8 13651 print_symbol ((int) maxlen, (const char *) data);
4082ef84 13652 putchar ('\n');
fd8008d8 13653 data += strnlen ((const char *) data, maxlen);
4082ef84
NC
13654 }
13655 else
13656 {
13657 printf (_("<corrupt>\n"));
13658 data = end;
13659 }
cf13d699
NC
13660 some_strings_shown = TRUE;
13661 }
13662 }
13663
13664 if (! some_strings_shown)
13665 printf (_(" No strings found in this section."));
13666
0e602686 13667 free (real_start);
cf13d699
NC
13668
13669 putchar ('\n');
32ec8896 13670 return TRUE;
cf13d699
NC
13671}
13672
32ec8896 13673static bfd_boolean
dda8d76d
NC
13674dump_section_as_bytes (Elf_Internal_Shdr * section,
13675 Filedata * filedata,
13676 bfd_boolean relocate)
cf13d699
NC
13677{
13678 Elf_Internal_Shdr * relsec;
0e602686
NC
13679 bfd_size_type bytes;
13680 bfd_size_type section_size;
13681 bfd_vma addr;
13682 unsigned char * data;
13683 unsigned char * real_start;
13684 unsigned char * start;
13685
dda8d76d 13686 real_start = start = (unsigned char *) get_section_contents (section, filedata);
cf13d699 13687 if (start == NULL)
c6b78c96
NC
13688 /* PR 21820: Do not fail if the section was empty. */
13689 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
32ec8896 13690
0e602686 13691 section_size = section->sh_size;
cf13d699 13692
dda8d76d 13693 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata, section));
cf13d699 13694
0e602686
NC
13695 if (decompress_dumps)
13696 {
13697 dwarf_size_type new_size = section_size;
13698 dwarf_size_type uncompressed_size = 0;
13699
13700 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13701 {
13702 Elf_Internal_Chdr chdr;
13703 unsigned int compression_header_size
ebdf1ebf 13704 = get_compression_header (& chdr, start, section_size);
0e602686 13705
813dabb9 13706 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
0e602686 13707 {
813dabb9 13708 warn (_("section '%s' has unsupported compress type: %d\n"),
dda8d76d 13709 printable_section_name (filedata, section), chdr.ch_type);
32ec8896 13710 return FALSE;
0e602686 13711 }
813dabb9
L
13712 uncompressed_size = chdr.ch_size;
13713 start += compression_header_size;
13714 new_size -= compression_header_size;
0e602686
NC
13715 }
13716 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13717 {
13718 /* Read the zlib header. In this case, it should be "ZLIB"
13719 followed by the uncompressed section size, 8 bytes in
13720 big-endian order. */
13721 uncompressed_size = start[4]; uncompressed_size <<= 8;
13722 uncompressed_size += start[5]; uncompressed_size <<= 8;
13723 uncompressed_size += start[6]; uncompressed_size <<= 8;
13724 uncompressed_size += start[7]; uncompressed_size <<= 8;
13725 uncompressed_size += start[8]; uncompressed_size <<= 8;
13726 uncompressed_size += start[9]; uncompressed_size <<= 8;
13727 uncompressed_size += start[10]; uncompressed_size <<= 8;
13728 uncompressed_size += start[11];
13729 start += 12;
13730 new_size -= 12;
13731 }
13732
f055032e
NC
13733 if (uncompressed_size)
13734 {
13735 if (uncompress_section_contents (& start, uncompressed_size,
13736 & new_size))
bc303e5d
NC
13737 {
13738 section_size = new_size;
13739 }
f055032e
NC
13740 else
13741 {
13742 error (_("Unable to decompress section %s\n"),
dda8d76d 13743 printable_section_name (filedata, section));
bc303e5d 13744 /* FIXME: Print the section anyway ? */
32ec8896 13745 return FALSE;
f055032e
NC
13746 }
13747 }
bc303e5d
NC
13748 else
13749 start = real_start;
0e602686 13750 }
14ae95f2 13751
cf13d699
NC
13752 if (relocate)
13753 {
dda8d76d 13754 if (! apply_relocations (filedata, section, start, section_size, NULL, NULL))
32ec8896 13755 return FALSE;
cf13d699
NC
13756 }
13757 else
13758 {
13759 /* If the section being dumped has relocations against it the user might
13760 be expecting these relocations to have been applied. Check for this
13761 case and issue a warning message in order to avoid confusion.
13762 FIXME: Maybe we ought to have an option that dumps a section with
13763 relocs applied ? */
dda8d76d
NC
13764 for (relsec = filedata->section_headers;
13765 relsec < filedata->section_headers + filedata->file_header.e_shnum;
cf13d699
NC
13766 ++relsec)
13767 {
13768 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
13769 || relsec->sh_info >= filedata->file_header.e_shnum
13770 || filedata->section_headers + relsec->sh_info != section
cf13d699 13771 || relsec->sh_size == 0
dda8d76d 13772 || relsec->sh_link >= filedata->file_header.e_shnum)
cf13d699
NC
13773 continue;
13774
13775 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13776 break;
13777 }
13778 }
13779
13780 addr = section->sh_addr;
0e602686 13781 bytes = section_size;
cf13d699
NC
13782 data = start;
13783
13784 while (bytes)
13785 {
13786 int j;
13787 int k;
13788 int lbytes;
13789
13790 lbytes = (bytes > 16 ? 16 : bytes);
13791
13792 printf (" 0x%8.8lx ", (unsigned long) addr);
13793
13794 for (j = 0; j < 16; j++)
13795 {
13796 if (j < lbytes)
13797 printf ("%2.2x", data[j]);
13798 else
13799 printf (" ");
13800
13801 if ((j & 3) == 3)
13802 printf (" ");
13803 }
13804
13805 for (j = 0; j < lbytes; j++)
13806 {
13807 k = data[j];
13808 if (k >= ' ' && k < 0x7f)
13809 printf ("%c", k);
13810 else
13811 printf (".");
13812 }
13813
13814 putchar ('\n');
13815
13816 data += lbytes;
13817 addr += lbytes;
13818 bytes -= lbytes;
13819 }
13820
0e602686 13821 free (real_start);
cf13d699
NC
13822
13823 putchar ('\n');
32ec8896 13824 return TRUE;
cf13d699
NC
13825}
13826
90bd5423 13827#ifdef HAVE_LIBCTF
7d9813f1
NA
13828static ctf_sect_t *
13829shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata)
13830{
90bd5423 13831 buf->cts_name = SECTION_NAME (shdr);
7d9813f1
NA
13832 buf->cts_type = shdr->sh_type;
13833 buf->cts_flags = shdr->sh_flags;
13834 buf->cts_size = shdr->sh_size;
13835 buf->cts_entsize = shdr->sh_entsize;
13836 buf->cts_offset = (off64_t) shdr->sh_offset;
13837
13838 return buf;
13839}
13840
13841/* Formatting callback function passed to ctf_dump. Returns either the pointer
13842 it is passed, or a pointer to newly-allocated storage, in which case
13843 dump_ctf() will free it when it no longer needs it. */
13844
13845static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
13846 char *s, void *arg)
13847{
13848 char *spaces = arg;
13849 char *new_s;
13850
13851 if (asprintf (&new_s, "%s%s", spaces, s) < 0)
13852 return s;
13853 return new_s;
13854}
13855
13856static bfd_boolean
13857dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
13858{
13859 Elf_Internal_Shdr * parent_sec = NULL;
13860 Elf_Internal_Shdr * symtab_sec = NULL;
13861 Elf_Internal_Shdr * strtab_sec = NULL;
13862 void * data = NULL;
13863 void * symdata = NULL;
13864 void * strdata = NULL;
13865 void * parentdata = NULL;
13866 ctf_sect_t ctfsect, symsect, strsect, parentsect;
13867 ctf_sect_t * symsectp = NULL;
13868 ctf_sect_t * strsectp = NULL;
13869 ctf_file_t * ctf = NULL;
13870 ctf_file_t * parent = NULL;
13871
13872 const char *things[] = {"Labels", "Data objects", "Function objects",
13873 "Variables", "Types", "Strings", ""};
13874 const char **thing;
13875 int err;
13876 bfd_boolean ret = FALSE;
13877 size_t i;
13878
13879 shdr_to_ctf_sect (&ctfsect, section, filedata);
13880 data = get_section_contents (section, filedata);
13881 ctfsect.cts_data = data;
13882
13883 if (dump_ctf_symtab_name)
13884 {
13885 if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL)
13886 {
13887 error (_("No symbol section named %s\n"), dump_ctf_symtab_name);
13888 goto fail;
13889 }
13890 if ((symdata = (void *) get_data (NULL, filedata,
13891 symtab_sec->sh_offset, 1,
13892 symtab_sec->sh_size,
13893 _("symbols"))) == NULL)
13894 goto fail;
13895 symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata);
13896 symsect.cts_data = symdata;
13897 }
13898 if (dump_ctf_strtab_name)
13899 {
13900 if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL)
13901 {
13902 error (_("No string table section named %s\n"),
13903 dump_ctf_strtab_name);
13904 goto fail;
13905 }
13906 if ((strdata = (void *) get_data (NULL, filedata,
13907 strtab_sec->sh_offset, 1,
13908 strtab_sec->sh_size,
13909 _("strings"))) == NULL)
13910 goto fail;
13911 strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata);
13912 strsect.cts_data = strdata;
13913 }
13914 if (dump_ctf_parent_name)
13915 {
13916 if ((parent_sec = find_section (filedata, dump_ctf_parent_name)) == NULL)
13917 {
13918 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name);
13919 goto fail;
13920 }
13921 if ((parentdata = (void *) get_data (NULL, filedata,
13922 parent_sec->sh_offset, 1,
13923 parent_sec->sh_size,
13924 _("CTF parent"))) == NULL)
13925 goto fail;
13926 shdr_to_ctf_sect (&parentsect, parent_sec, filedata);
13927 parentsect.cts_data = parentdata;
13928 }
13929
13930 /* Load the CTF file and dump it. */
13931
13932 if ((ctf = ctf_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
13933 {
13934 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
13935 goto fail;
13936 }
13937
13938 if (parentdata)
13939 {
13940 if ((parent = ctf_bufopen (&parentsect, symsectp, strsectp, &err)) == NULL)
13941 {
13942 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
13943 goto fail;
13944 }
13945
13946 ctf_import (ctf, parent);
13947 }
13948
13949 ret = TRUE;
13950
13951 printf (_("\nDump of CTF section '%s':\n"),
13952 printable_section_name (filedata, section));
13953
13954 for (i = 1, thing = things; *thing[0]; thing++, i++)
13955 {
13956 ctf_dump_state_t *s = NULL;
13957 char *item;
13958
13959 printf ("\n %s:\n", *thing);
13960 while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
13961 (void *) " ")) != NULL)
13962 {
13963 printf ("%s\n", item);
13964 free (item);
13965 }
13966
13967 if (ctf_errno (ctf))
13968 {
13969 error (_("Iteration failed: %s, %s\n"), *thing,
13970 ctf_errmsg (ctf_errno (ctf)));
13971 ret = FALSE;
13972 }
13973 }
13974
13975 fail:
13976 ctf_file_close (ctf);
13977 ctf_file_close (parent);
13978 free (parentdata);
13979 free (data);
13980 free (symdata);
13981 free (strdata);
13982 return ret;
13983}
90bd5423 13984#endif /* HAVE_LIBCTF */
7d9813f1 13985
32ec8896 13986static bfd_boolean
dda8d76d
NC
13987load_specific_debug_section (enum dwarf_section_display_enum debug,
13988 const Elf_Internal_Shdr * sec,
13989 void * data)
1007acb3 13990{
2cf0635d 13991 struct dwarf_section * section = &debug_displays [debug].section;
19e6b90e 13992 char buf [64];
dda8d76d
NC
13993 Filedata * filedata = (Filedata *) data;
13994
19e6b90e 13995 if (section->start != NULL)
dda8d76d
NC
13996 {
13997 /* If it is already loaded, do nothing. */
13998 if (streq (section->filename, filedata->file_name))
13999 return TRUE;
14000 free (section->start);
14001 }
1007acb3 14002
19e6b90e
L
14003 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
14004 section->address = sec->sh_addr;
06614111 14005 section->user_data = NULL;
dda8d76d
NC
14006 section->filename = filedata->file_name;
14007 section->start = (unsigned char *) get_data (NULL, filedata,
3f5e193b
NC
14008 sec->sh_offset, 1,
14009 sec->sh_size, buf);
59245841
NC
14010 if (section->start == NULL)
14011 section->size = 0;
14012 else
14013 {
77115a4a
L
14014 unsigned char *start = section->start;
14015 dwarf_size_type size = sec->sh_size;
dab394de 14016 dwarf_size_type uncompressed_size = 0;
77115a4a
L
14017
14018 if ((sec->sh_flags & SHF_COMPRESSED) != 0)
14019 {
14020 Elf_Internal_Chdr chdr;
d8024a91
NC
14021 unsigned int compression_header_size;
14022
f53be977
L
14023 if (size < (is_32bit_elf
14024 ? sizeof (Elf32_External_Chdr)
14025 : sizeof (Elf64_External_Chdr)))
d8024a91
NC
14026 {
14027 warn (_("compressed section %s is too small to contain a compression header"),
14028 section->name);
32ec8896 14029 return FALSE;
d8024a91
NC
14030 }
14031
ebdf1ebf 14032 compression_header_size = get_compression_header (&chdr, start, size);
d8024a91 14033
813dabb9
L
14034 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
14035 {
14036 warn (_("section '%s' has unsupported compress type: %d\n"),
14037 section->name, chdr.ch_type);
32ec8896 14038 return FALSE;
813dabb9 14039 }
dab394de 14040 uncompressed_size = chdr.ch_size;
77115a4a
L
14041 start += compression_header_size;
14042 size -= compression_header_size;
14043 }
dab394de
L
14044 else if (size > 12 && streq ((char *) start, "ZLIB"))
14045 {
14046 /* Read the zlib header. In this case, it should be "ZLIB"
14047 followed by the uncompressed section size, 8 bytes in
14048 big-endian order. */
14049 uncompressed_size = start[4]; uncompressed_size <<= 8;
14050 uncompressed_size += start[5]; uncompressed_size <<= 8;
14051 uncompressed_size += start[6]; uncompressed_size <<= 8;
14052 uncompressed_size += start[7]; uncompressed_size <<= 8;
14053 uncompressed_size += start[8]; uncompressed_size <<= 8;
14054 uncompressed_size += start[9]; uncompressed_size <<= 8;
14055 uncompressed_size += start[10]; uncompressed_size <<= 8;
14056 uncompressed_size += start[11];
14057 start += 12;
14058 size -= 12;
14059 }
14060
1835f746 14061 if (uncompressed_size)
77115a4a 14062 {
1835f746
NC
14063 if (uncompress_section_contents (&start, uncompressed_size,
14064 &size))
14065 {
14066 /* Free the compressed buffer, update the section buffer
14067 and the section size if uncompress is successful. */
14068 free (section->start);
14069 section->start = start;
14070 }
14071 else
14072 {
14073 error (_("Unable to decompress section %s\n"),
dda8d76d 14074 printable_section_name (filedata, sec));
32ec8896 14075 return FALSE;
1835f746 14076 }
77115a4a 14077 }
bc303e5d 14078
77115a4a 14079 section->size = size;
59245841 14080 }
4a114e3e 14081
1b315056 14082 if (section->start == NULL)
32ec8896 14083 return FALSE;
1b315056 14084
19e6b90e 14085 if (debug_displays [debug].relocate)
32ec8896 14086 {
dda8d76d 14087 if (! apply_relocations (filedata, sec, section->start, section->size,
32ec8896
NC
14088 & section->reloc_info, & section->num_relocs))
14089 return FALSE;
14090 }
d1c4b12b
NC
14091 else
14092 {
14093 section->reloc_info = NULL;
14094 section->num_relocs = 0;
14095 }
1007acb3 14096
32ec8896 14097 return TRUE;
1007acb3
L
14098}
14099
657d0d47
CC
14100/* If this is not NULL, load_debug_section will only look for sections
14101 within the list of sections given here. */
32ec8896 14102static unsigned int * section_subset = NULL;
657d0d47 14103
32ec8896 14104bfd_boolean
dda8d76d 14105load_debug_section (enum dwarf_section_display_enum debug, void * data)
d966045b 14106{
2cf0635d
NC
14107 struct dwarf_section * section = &debug_displays [debug].section;
14108 Elf_Internal_Shdr * sec;
dda8d76d
NC
14109 Filedata * filedata = (Filedata *) data;
14110
f425ec66
NC
14111 /* Without section headers we cannot find any sections. */
14112 if (filedata->section_headers == NULL)
14113 return FALSE;
14114
9c1ce108
AM
14115 if (filedata->string_table == NULL
14116 && filedata->file_header.e_shstrndx != SHN_UNDEF
14117 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
dda8d76d
NC
14118 {
14119 Elf_Internal_Shdr * strs;
14120
14121 /* Read in the string table, so that we have section names to scan. */
14122 strs = filedata->section_headers + filedata->file_header.e_shstrndx;
14123
4dff97b2 14124 if (strs != NULL && strs->sh_size != 0)
dda8d76d 14125 {
9c1ce108
AM
14126 filedata->string_table
14127 = (char *) get_data (NULL, filedata, strs->sh_offset,
14128 1, strs->sh_size, _("string table"));
dda8d76d 14129
9c1ce108
AM
14130 filedata->string_table_length
14131 = filedata->string_table != NULL ? strs->sh_size : 0;
dda8d76d
NC
14132 }
14133 }
d966045b
DJ
14134
14135 /* Locate the debug section. */
dda8d76d 14136 sec = find_section_in_set (filedata, section->uncompressed_name, section_subset);
d966045b
DJ
14137 if (sec != NULL)
14138 section->name = section->uncompressed_name;
14139 else
14140 {
dda8d76d 14141 sec = find_section_in_set (filedata, section->compressed_name, section_subset);
d966045b
DJ
14142 if (sec != NULL)
14143 section->name = section->compressed_name;
14144 }
14145 if (sec == NULL)
32ec8896 14146 return FALSE;
d966045b 14147
657d0d47
CC
14148 /* If we're loading from a subset of sections, and we've loaded
14149 a section matching this name before, it's likely that it's a
14150 different one. */
14151 if (section_subset != NULL)
14152 free_debug_section (debug);
14153
dda8d76d 14154 return load_specific_debug_section (debug, sec, data);
d966045b
DJ
14155}
14156
19e6b90e
L
14157void
14158free_debug_section (enum dwarf_section_display_enum debug)
1007acb3 14159{
2cf0635d 14160 struct dwarf_section * section = &debug_displays [debug].section;
1007acb3 14161
19e6b90e
L
14162 if (section->start == NULL)
14163 return;
1007acb3 14164
19e6b90e
L
14165 free ((char *) section->start);
14166 section->start = NULL;
14167 section->address = 0;
14168 section->size = 0;
1007acb3
L
14169}
14170
32ec8896 14171static bfd_boolean
dda8d76d 14172display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata)
1007acb3 14173{
2cf0635d 14174 char * name = SECTION_NAME (section);
dda8d76d 14175 const char * print_name = printable_section_name (filedata, section);
19e6b90e 14176 bfd_size_type length;
32ec8896 14177 bfd_boolean result = TRUE;
3f5e193b 14178 int i;
1007acb3 14179
19e6b90e
L
14180 length = section->sh_size;
14181 if (length == 0)
1007acb3 14182 {
74e1a04b 14183 printf (_("\nSection '%s' has no debugging data.\n"), print_name);
32ec8896 14184 return TRUE;
1007acb3 14185 }
5dff79d8
NC
14186 if (section->sh_type == SHT_NOBITS)
14187 {
14188 /* There is no point in dumping the contents of a debugging section
14189 which has the NOBITS type - the bits in the file will be random.
14190 This can happen when a file containing a .eh_frame section is
14191 stripped with the --only-keep-debug command line option. */
74e1a04b
NC
14192 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
14193 print_name);
32ec8896 14194 return FALSE;
5dff79d8 14195 }
1007acb3 14196
0112cd26 14197 if (const_strneq (name, ".gnu.linkonce.wi."))
19e6b90e 14198 name = ".debug_info";
1007acb3 14199
19e6b90e
L
14200 /* See if we know how to display the contents of this section. */
14201 for (i = 0; i < max; i++)
d85bf2ba
NC
14202 {
14203 enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i;
14204 struct dwarf_section_display * display = debug_displays + i;
14205 struct dwarf_section * sec = & display->section;
d966045b 14206
d85bf2ba
NC
14207 if (streq (sec->uncompressed_name, name)
14208 || (id == line && const_strneq (name, ".debug_line."))
14209 || streq (sec->compressed_name, name))
14210 {
14211 bfd_boolean secondary = (section != find_section (filedata, name));
1007acb3 14212
d85bf2ba
NC
14213 if (secondary)
14214 free_debug_section (id);
dda8d76d 14215
d85bf2ba
NC
14216 if (i == line && const_strneq (name, ".debug_line."))
14217 sec->name = name;
14218 else if (streq (sec->uncompressed_name, name))
14219 sec->name = sec->uncompressed_name;
14220 else
14221 sec->name = sec->compressed_name;
657d0d47 14222
d85bf2ba
NC
14223 if (load_specific_debug_section (id, section, filedata))
14224 {
14225 /* If this debug section is part of a CU/TU set in a .dwp file,
14226 restrict load_debug_section to the sections in that set. */
14227 section_subset = find_cu_tu_set (filedata, shndx);
1007acb3 14228
d85bf2ba 14229 result &= display->display (sec, filedata);
657d0d47 14230
d85bf2ba 14231 section_subset = NULL;
1007acb3 14232
d85bf2ba
NC
14233 if (secondary || (id != info && id != abbrev))
14234 free_debug_section (id);
14235 }
14236 break;
14237 }
14238 }
1007acb3 14239
19e6b90e 14240 if (i == max)
1007acb3 14241 {
74e1a04b 14242 printf (_("Unrecognized debug section: %s\n"), print_name);
32ec8896 14243 result = FALSE;
1007acb3
L
14244 }
14245
19e6b90e 14246 return result;
5b18a4bc 14247}
103f02d3 14248
aef1f6d0
DJ
14249/* Set DUMP_SECTS for all sections where dumps were requested
14250 based on section name. */
14251
14252static void
dda8d76d 14253initialise_dumps_byname (Filedata * filedata)
aef1f6d0 14254{
2cf0635d 14255 struct dump_list_entry * cur;
aef1f6d0
DJ
14256
14257 for (cur = dump_sects_byname; cur; cur = cur->next)
14258 {
14259 unsigned int i;
32ec8896 14260 bfd_boolean any = FALSE;
aef1f6d0 14261
dda8d76d
NC
14262 for (i = 0; i < filedata->file_header.e_shnum; i++)
14263 if (streq (SECTION_NAME (filedata->section_headers + i), cur->name))
aef1f6d0 14264 {
dda8d76d 14265 request_dump_bynumber (filedata, i, cur->type);
32ec8896 14266 any = TRUE;
aef1f6d0
DJ
14267 }
14268
14269 if (!any)
14270 warn (_("Section '%s' was not dumped because it does not exist!\n"),
14271 cur->name);
14272 }
14273}
14274
32ec8896 14275static bfd_boolean
dda8d76d 14276process_section_contents (Filedata * filedata)
5b18a4bc 14277{
2cf0635d 14278 Elf_Internal_Shdr * section;
19e6b90e 14279 unsigned int i;
32ec8896 14280 bfd_boolean res = TRUE;
103f02d3 14281
19e6b90e 14282 if (! do_dump)
32ec8896 14283 return TRUE;
103f02d3 14284
dda8d76d 14285 initialise_dumps_byname (filedata);
aef1f6d0 14286
dda8d76d
NC
14287 for (i = 0, section = filedata->section_headers;
14288 i < filedata->file_header.e_shnum && i < filedata->num_dump_sects;
19e6b90e
L
14289 i++, section++)
14290 {
dda8d76d
NC
14291 dump_type dump = filedata->dump_sects[i];
14292
19e6b90e 14293#ifdef SUPPORT_DISASSEMBLY
dda8d76d
NC
14294 if (dump & DISASS_DUMP)
14295 {
14296 if (! disassemble_section (section, filedata))
14297 res = FALSE;
14298 }
19e6b90e 14299#endif
dda8d76d 14300 if (dump & HEX_DUMP)
32ec8896 14301 {
dda8d76d 14302 if (! dump_section_as_bytes (section, filedata, FALSE))
32ec8896
NC
14303 res = FALSE;
14304 }
103f02d3 14305
dda8d76d 14306 if (dump & RELOC_DUMP)
32ec8896 14307 {
dda8d76d 14308 if (! dump_section_as_bytes (section, filedata, TRUE))
32ec8896
NC
14309 res = FALSE;
14310 }
09c11c86 14311
dda8d76d 14312 if (dump & STRING_DUMP)
32ec8896 14313 {
dda8d76d 14314 if (! dump_section_as_strings (section, filedata))
32ec8896
NC
14315 res = FALSE;
14316 }
cf13d699 14317
dda8d76d 14318 if (dump & DEBUG_DUMP)
32ec8896 14319 {
dda8d76d 14320 if (! display_debug_section (i, section, filedata))
32ec8896
NC
14321 res = FALSE;
14322 }
7d9813f1 14323
90bd5423 14324#ifdef HAVE_LIBCTF
7d9813f1
NA
14325 if (dump & CTF_DUMP)
14326 {
14327 if (! dump_section_as_ctf (section, filedata))
14328 res = FALSE;
14329 }
90bd5423 14330#endif
5b18a4bc 14331 }
103f02d3 14332
19e6b90e
L
14333 /* Check to see if the user requested a
14334 dump of a section that does not exist. */
dda8d76d 14335 while (i < filedata->num_dump_sects)
0ee3043f 14336 {
dda8d76d 14337 if (filedata->dump_sects[i])
32ec8896
NC
14338 {
14339 warn (_("Section %d was not dumped because it does not exist!\n"), i);
14340 res = FALSE;
14341 }
0ee3043f
NC
14342 i++;
14343 }
32ec8896
NC
14344
14345 return res;
5b18a4bc 14346}
103f02d3 14347
5b18a4bc 14348static void
19e6b90e 14349process_mips_fpe_exception (int mask)
5b18a4bc 14350{
19e6b90e
L
14351 if (mask)
14352 {
32ec8896
NC
14353 bfd_boolean first = TRUE;
14354
19e6b90e 14355 if (mask & OEX_FPU_INEX)
32ec8896 14356 fputs ("INEX", stdout), first = FALSE;
19e6b90e 14357 if (mask & OEX_FPU_UFLO)
32ec8896 14358 printf ("%sUFLO", first ? "" : "|"), first = FALSE;
19e6b90e 14359 if (mask & OEX_FPU_OFLO)
32ec8896 14360 printf ("%sOFLO", first ? "" : "|"), first = FALSE;
19e6b90e 14361 if (mask & OEX_FPU_DIV0)
32ec8896 14362 printf ("%sDIV0", first ? "" : "|"), first = FALSE;
19e6b90e
L
14363 if (mask & OEX_FPU_INVAL)
14364 printf ("%sINVAL", first ? "" : "|");
14365 }
5b18a4bc 14366 else
19e6b90e 14367 fputs ("0", stdout);
5b18a4bc 14368}
103f02d3 14369
f6f0e17b
NC
14370/* Display's the value of TAG at location P. If TAG is
14371 greater than 0 it is assumed to be an unknown tag, and
14372 a message is printed to this effect. Otherwise it is
14373 assumed that a message has already been printed.
14374
14375 If the bottom bit of TAG is set it assumed to have a
14376 string value, otherwise it is assumed to have an integer
14377 value.
14378
14379 Returns an updated P pointing to the first unread byte
14380 beyond the end of TAG's value.
14381
14382 Reads at or beyond END will not be made. */
14383
14384static unsigned char *
60abdbed 14385display_tag_value (signed int tag,
f6f0e17b
NC
14386 unsigned char * p,
14387 const unsigned char * const end)
14388{
14389 unsigned long val;
14390
14391 if (tag > 0)
14392 printf (" Tag_unknown_%d: ", tag);
14393
14394 if (p >= end)
14395 {
4082ef84 14396 warn (_("<corrupt tag>\n"));
f6f0e17b
NC
14397 }
14398 else if (tag & 1)
14399 {
071436c6
NC
14400 /* PR 17531 file: 027-19978-0.004. */
14401 size_t maxlen = (end - p) - 1;
14402
14403 putchar ('"');
4082ef84
NC
14404 if (maxlen > 0)
14405 {
14406 print_symbol ((int) maxlen, (const char *) p);
14407 p += strnlen ((char *) p, maxlen) + 1;
14408 }
14409 else
14410 {
14411 printf (_("<corrupt string tag>"));
14412 p = (unsigned char *) end;
14413 }
071436c6 14414 printf ("\"\n");
f6f0e17b
NC
14415 }
14416 else
14417 {
14418 unsigned int len;
14419
14420 val = read_uleb128 (p, &len, end);
14421 p += len;
14422 printf ("%ld (0x%lx)\n", val, val);
14423 }
14424
4082ef84 14425 assert (p <= end);
f6f0e17b
NC
14426 return p;
14427}
14428
53a346d8
CZ
14429/* ARC ABI attributes section. */
14430
14431static unsigned char *
14432display_arc_attribute (unsigned char * p,
14433 const unsigned char * const end)
14434{
14435 unsigned int tag;
14436 unsigned int len;
14437 unsigned int val;
14438
14439 tag = read_uleb128 (p, &len, end);
14440 p += len;
14441
14442 switch (tag)
14443 {
14444 case Tag_ARC_PCS_config:
14445 val = read_uleb128 (p, &len, end);
14446 p += len;
14447 printf (" Tag_ARC_PCS_config: ");
14448 switch (val)
14449 {
14450 case 0:
14451 printf (_("Absent/Non standard\n"));
14452 break;
14453 case 1:
14454 printf (_("Bare metal/mwdt\n"));
14455 break;
14456 case 2:
14457 printf (_("Bare metal/newlib\n"));
14458 break;
14459 case 3:
14460 printf (_("Linux/uclibc\n"));
14461 break;
14462 case 4:
14463 printf (_("Linux/glibc\n"));
14464 break;
14465 default:
14466 printf (_("Unknown\n"));
14467 break;
14468 }
14469 break;
14470
14471 case Tag_ARC_CPU_base:
14472 val = read_uleb128 (p, &len, end);
14473 p += len;
14474 printf (" Tag_ARC_CPU_base: ");
14475 switch (val)
14476 {
14477 default:
14478 case TAG_CPU_NONE:
14479 printf (_("Absent\n"));
14480 break;
14481 case TAG_CPU_ARC6xx:
14482 printf ("ARC6xx\n");
14483 break;
14484 case TAG_CPU_ARC7xx:
14485 printf ("ARC7xx\n");
14486 break;
14487 case TAG_CPU_ARCEM:
14488 printf ("ARCEM\n");
14489 break;
14490 case TAG_CPU_ARCHS:
14491 printf ("ARCHS\n");
14492 break;
14493 }
14494 break;
14495
14496 case Tag_ARC_CPU_variation:
14497 val = read_uleb128 (p, &len, end);
14498 p += len;
14499 printf (" Tag_ARC_CPU_variation: ");
14500 switch (val)
14501 {
14502 default:
14503 if (val > 0 && val < 16)
53a346d8 14504 printf ("Core%d\n", val);
d8cbc93b
JL
14505 else
14506 printf ("Unknown\n");
14507 break;
14508
53a346d8
CZ
14509 case 0:
14510 printf (_("Absent\n"));
14511 break;
14512 }
14513 break;
14514
14515 case Tag_ARC_CPU_name:
14516 printf (" Tag_ARC_CPU_name: ");
14517 p = display_tag_value (-1, p, end);
14518 break;
14519
14520 case Tag_ARC_ABI_rf16:
14521 val = read_uleb128 (p, &len, end);
14522 p += len;
14523 printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
14524 break;
14525
14526 case Tag_ARC_ABI_osver:
14527 val = read_uleb128 (p, &len, end);
14528 p += len;
14529 printf (" Tag_ARC_ABI_osver: v%d\n", val);
14530 break;
14531
14532 case Tag_ARC_ABI_pic:
14533 case Tag_ARC_ABI_sda:
14534 val = read_uleb128 (p, &len, end);
14535 p += len;
14536 printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
14537 : " Tag_ARC_ABI_pic: ");
14538 switch (val)
14539 {
14540 case 0:
14541 printf (_("Absent\n"));
14542 break;
14543 case 1:
14544 printf ("MWDT\n");
14545 break;
14546 case 2:
14547 printf ("GNU\n");
14548 break;
14549 default:
14550 printf (_("Unknown\n"));
14551 break;
14552 }
14553 break;
14554
14555 case Tag_ARC_ABI_tls:
14556 val = read_uleb128 (p, &len, end);
14557 p += len;
14558 printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
14559 break;
14560
14561 case Tag_ARC_ABI_enumsize:
14562 val = read_uleb128 (p, &len, end);
14563 p += len;
14564 printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
14565 _("smallest"));
14566 break;
14567
14568 case Tag_ARC_ABI_exceptions:
14569 val = read_uleb128 (p, &len, end);
14570 p += len;
14571 printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
14572 : _("default"));
14573 break;
14574
14575 case Tag_ARC_ABI_double_size:
14576 val = read_uleb128 (p, &len, end);
14577 p += len;
14578 printf (" Tag_ARC_ABI_double_size: %d\n", val);
14579 break;
14580
14581 case Tag_ARC_ISA_config:
14582 printf (" Tag_ARC_ISA_config: ");
14583 p = display_tag_value (-1, p, end);
14584 break;
14585
14586 case Tag_ARC_ISA_apex:
14587 printf (" Tag_ARC_ISA_apex: ");
14588 p = display_tag_value (-1, p, end);
14589 break;
14590
14591 case Tag_ARC_ISA_mpy_option:
14592 val = read_uleb128 (p, &len, end);
14593 p += len;
14594 printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
14595 break;
14596
db1e1b45 14597 case Tag_ARC_ATR_version:
14598 val = read_uleb128 (p, &len, end);
14599 p += len;
14600 printf (" Tag_ARC_ATR_version: %d\n", val);
14601 break;
14602
53a346d8
CZ
14603 default:
14604 return display_tag_value (tag & 1, p, end);
14605 }
14606
14607 return p;
14608}
14609
11c1ff18
PB
14610/* ARM EABI attributes section. */
14611typedef struct
14612{
70e99720 14613 unsigned int tag;
2cf0635d 14614 const char * name;
11c1ff18 14615 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
70e99720 14616 unsigned int type;
2cf0635d 14617 const char ** table;
11c1ff18
PB
14618} arm_attr_public_tag;
14619
2cf0635d 14620static const char * arm_attr_tag_CPU_arch[] =
11c1ff18 14621 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
ced40572 14622 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
031254f2 14623 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
2cf0635d
NC
14624static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
14625static const char * arm_attr_tag_THUMB_ISA_use[] =
4ed7ed8d 14626 {"No", "Thumb-1", "Thumb-2", "Yes"};
75375b3e 14627static const char * arm_attr_tag_FP_arch[] =
bca38921 14628 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
a715796b 14629 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
2cf0635d 14630static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
dd24e3da 14631static const char * arm_attr_tag_Advanced_SIMD_arch[] =
9411fd44
MW
14632 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
14633 "NEON for ARMv8.1"};
2cf0635d 14634static const char * arm_attr_tag_PCS_config[] =
11c1ff18
PB
14635 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
14636 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
2cf0635d 14637static const char * arm_attr_tag_ABI_PCS_R9_use[] =
11c1ff18 14638 {"V6", "SB", "TLS", "Unused"};
2cf0635d 14639static const char * arm_attr_tag_ABI_PCS_RW_data[] =
11c1ff18 14640 {"Absolute", "PC-relative", "SB-relative", "None"};
2cf0635d 14641static const char * arm_attr_tag_ABI_PCS_RO_data[] =
11c1ff18 14642 {"Absolute", "PC-relative", "None"};
2cf0635d 14643static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
11c1ff18 14644 {"None", "direct", "GOT-indirect"};
2cf0635d 14645static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
11c1ff18 14646 {"None", "??? 1", "2", "??? 3", "4"};
2cf0635d
NC
14647static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
14648static const char * arm_attr_tag_ABI_FP_denormal[] =
f5f53991 14649 {"Unused", "Needed", "Sign only"};
2cf0635d
NC
14650static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
14651static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
14652static const char * arm_attr_tag_ABI_FP_number_model[] =
11c1ff18 14653 {"Unused", "Finite", "RTABI", "IEEE 754"};
2cf0635d 14654static const char * arm_attr_tag_ABI_enum_size[] =
11c1ff18 14655 {"Unused", "small", "int", "forced to int"};
2cf0635d 14656static const char * arm_attr_tag_ABI_HardFP_use[] =
99654aaf 14657 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
2cf0635d 14658static const char * arm_attr_tag_ABI_VFP_args[] =
5c294fee 14659 {"AAPCS", "VFP registers", "custom", "compatible"};
2cf0635d 14660static const char * arm_attr_tag_ABI_WMMX_args[] =
11c1ff18 14661 {"AAPCS", "WMMX registers", "custom"};
2cf0635d 14662static const char * arm_attr_tag_ABI_optimization_goals[] =
11c1ff18
PB
14663 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14664 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
2cf0635d 14665static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
11c1ff18
PB
14666 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14667 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
2cf0635d 14668static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
75375b3e 14669static const char * arm_attr_tag_FP_HP_extension[] =
8e79c3df 14670 {"Not Allowed", "Allowed"};
2cf0635d 14671static const char * arm_attr_tag_ABI_FP_16bit_format[] =
8e79c3df 14672 {"None", "IEEE 754", "Alternative Format"};
15afaa63
TP
14673static const char * arm_attr_tag_DSP_extension[] =
14674 {"Follow architecture", "Allowed"};
dd24e3da 14675static const char * arm_attr_tag_MPextension_use[] =
cd21e546
MGD
14676 {"Not Allowed", "Allowed"};
14677static const char * arm_attr_tag_DIV_use[] =
dd24e3da 14678 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
cd21e546 14679 "Allowed in v7-A with integer division extension"};
2cf0635d
NC
14680static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
14681static const char * arm_attr_tag_Virtualization_use[] =
dd24e3da 14682 {"Not Allowed", "TrustZone", "Virtualization Extensions",
cd21e546 14683 "TrustZone and Virtualization Extensions"};
dd24e3da 14684static const char * arm_attr_tag_MPextension_use_legacy[] =
f5f53991 14685 {"Not Allowed", "Allowed"};
11c1ff18 14686
a7ad558c
AV
14687static const char * arm_attr_tag_MVE_arch[] =
14688 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
14689
11c1ff18
PB
14690#define LOOKUP(id, name) \
14691 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
d70c5fc7 14692static arm_attr_public_tag arm_attr_public_tags[] =
11c1ff18
PB
14693{
14694 {4, "CPU_raw_name", 1, NULL},
14695 {5, "CPU_name", 1, NULL},
14696 LOOKUP(6, CPU_arch),
14697 {7, "CPU_arch_profile", 0, NULL},
14698 LOOKUP(8, ARM_ISA_use),
14699 LOOKUP(9, THUMB_ISA_use),
75375b3e 14700 LOOKUP(10, FP_arch),
11c1ff18 14701 LOOKUP(11, WMMX_arch),
f5f53991
AS
14702 LOOKUP(12, Advanced_SIMD_arch),
14703 LOOKUP(13, PCS_config),
11c1ff18
PB
14704 LOOKUP(14, ABI_PCS_R9_use),
14705 LOOKUP(15, ABI_PCS_RW_data),
f5f53991 14706 LOOKUP(16, ABI_PCS_RO_data),
11c1ff18
PB
14707 LOOKUP(17, ABI_PCS_GOT_use),
14708 LOOKUP(18, ABI_PCS_wchar_t),
14709 LOOKUP(19, ABI_FP_rounding),
14710 LOOKUP(20, ABI_FP_denormal),
14711 LOOKUP(21, ABI_FP_exceptions),
14712 LOOKUP(22, ABI_FP_user_exceptions),
14713 LOOKUP(23, ABI_FP_number_model),
75375b3e
MGD
14714 {24, "ABI_align_needed", 0, NULL},
14715 {25, "ABI_align_preserved", 0, NULL},
11c1ff18
PB
14716 LOOKUP(26, ABI_enum_size),
14717 LOOKUP(27, ABI_HardFP_use),
14718 LOOKUP(28, ABI_VFP_args),
14719 LOOKUP(29, ABI_WMMX_args),
14720 LOOKUP(30, ABI_optimization_goals),
14721 LOOKUP(31, ABI_FP_optimization_goals),
8e79c3df 14722 {32, "compatibility", 0, NULL},
f5f53991 14723 LOOKUP(34, CPU_unaligned_access),
75375b3e 14724 LOOKUP(36, FP_HP_extension),
8e79c3df 14725 LOOKUP(38, ABI_FP_16bit_format),
cd21e546
MGD
14726 LOOKUP(42, MPextension_use),
14727 LOOKUP(44, DIV_use),
15afaa63 14728 LOOKUP(46, DSP_extension),
a7ad558c 14729 LOOKUP(48, MVE_arch),
f5f53991
AS
14730 {64, "nodefaults", 0, NULL},
14731 {65, "also_compatible_with", 0, NULL},
14732 LOOKUP(66, T2EE_use),
14733 {67, "conformance", 1, NULL},
14734 LOOKUP(68, Virtualization_use),
cd21e546 14735 LOOKUP(70, MPextension_use_legacy)
11c1ff18
PB
14736};
14737#undef LOOKUP
14738
11c1ff18 14739static unsigned char *
f6f0e17b
NC
14740display_arm_attribute (unsigned char * p,
14741 const unsigned char * const end)
11c1ff18 14742{
70e99720 14743 unsigned int tag;
11c1ff18 14744 unsigned int len;
70e99720 14745 unsigned int val;
2cf0635d 14746 arm_attr_public_tag * attr;
11c1ff18 14747 unsigned i;
70e99720 14748 unsigned int type;
11c1ff18 14749
f6f0e17b 14750 tag = read_uleb128 (p, &len, end);
11c1ff18
PB
14751 p += len;
14752 attr = NULL;
2cf0635d 14753 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
11c1ff18
PB
14754 {
14755 if (arm_attr_public_tags[i].tag == tag)
14756 {
14757 attr = &arm_attr_public_tags[i];
14758 break;
14759 }
14760 }
14761
14762 if (attr)
14763 {
14764 printf (" Tag_%s: ", attr->name);
14765 switch (attr->type)
14766 {
14767 case 0:
14768 switch (tag)
14769 {
14770 case 7: /* Tag_CPU_arch_profile. */
f6f0e17b 14771 val = read_uleb128 (p, &len, end);
11c1ff18
PB
14772 p += len;
14773 switch (val)
14774 {
2b692964
NC
14775 case 0: printf (_("None\n")); break;
14776 case 'A': printf (_("Application\n")); break;
14777 case 'R': printf (_("Realtime\n")); break;
14778 case 'M': printf (_("Microcontroller\n")); break;
14779 case 'S': printf (_("Application or Realtime\n")); break;
11c1ff18
PB
14780 default: printf ("??? (%d)\n", val); break;
14781 }
14782 break;
14783
75375b3e 14784 case 24: /* Tag_align_needed. */
f6f0e17b 14785 val = read_uleb128 (p, &len, end);
75375b3e
MGD
14786 p += len;
14787 switch (val)
14788 {
2b692964
NC
14789 case 0: printf (_("None\n")); break;
14790 case 1: printf (_("8-byte\n")); break;
14791 case 2: printf (_("4-byte\n")); break;
75375b3e
MGD
14792 case 3: printf ("??? 3\n"); break;
14793 default:
14794 if (val <= 12)
dd24e3da 14795 printf (_("8-byte and up to %d-byte extended\n"),
75375b3e
MGD
14796 1 << val);
14797 else
14798 printf ("??? (%d)\n", val);
14799 break;
14800 }
14801 break;
14802
14803 case 25: /* Tag_align_preserved. */
f6f0e17b 14804 val = read_uleb128 (p, &len, end);
75375b3e
MGD
14805 p += len;
14806 switch (val)
14807 {
2b692964
NC
14808 case 0: printf (_("None\n")); break;
14809 case 1: printf (_("8-byte, except leaf SP\n")); break;
14810 case 2: printf (_("8-byte\n")); break;
75375b3e
MGD
14811 case 3: printf ("??? 3\n"); break;
14812 default:
14813 if (val <= 12)
dd24e3da 14814 printf (_("8-byte and up to %d-byte extended\n"),
75375b3e
MGD
14815 1 << val);
14816 else
14817 printf ("??? (%d)\n", val);
14818 break;
14819 }
14820 break;
14821
11c1ff18 14822 case 32: /* Tag_compatibility. */
071436c6 14823 {
071436c6
NC
14824 val = read_uleb128 (p, &len, end);
14825 p += len;
071436c6 14826 printf (_("flag = %d, vendor = "), val);
4082ef84
NC
14827 if (p < end - 1)
14828 {
14829 size_t maxlen = (end - p) - 1;
14830
14831 print_symbol ((int) maxlen, (const char *) p);
14832 p += strnlen ((char *) p, maxlen) + 1;
14833 }
14834 else
14835 {
14836 printf (_("<corrupt>"));
14837 p = (unsigned char *) end;
14838 }
071436c6 14839 putchar ('\n');
071436c6 14840 }
11c1ff18
PB
14841 break;
14842
f5f53991 14843 case 64: /* Tag_nodefaults. */
541a3cbd
NC
14844 /* PR 17531: file: 001-505008-0.01. */
14845 if (p < end)
14846 p++;
2b692964 14847 printf (_("True\n"));
f5f53991
AS
14848 break;
14849
14850 case 65: /* Tag_also_compatible_with. */
f6f0e17b 14851 val = read_uleb128 (p, &len, end);
f5f53991
AS
14852 p += len;
14853 if (val == 6 /* Tag_CPU_arch. */)
14854 {
f6f0e17b 14855 val = read_uleb128 (p, &len, end);
f5f53991 14856 p += len;
071436c6 14857 if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
f5f53991
AS
14858 printf ("??? (%d)\n", val);
14859 else
14860 printf ("%s\n", arm_attr_tag_CPU_arch[val]);
14861 }
14862 else
14863 printf ("???\n");
071436c6
NC
14864 while (p < end && *(p++) != '\0' /* NUL terminator. */)
14865 ;
f5f53991
AS
14866 break;
14867
11c1ff18 14868 default:
bee0ee85
NC
14869 printf (_("<unknown: %d>\n"), tag);
14870 break;
11c1ff18
PB
14871 }
14872 return p;
14873
14874 case 1:
f6f0e17b 14875 return display_tag_value (-1, p, end);
11c1ff18 14876 case 2:
f6f0e17b 14877 return display_tag_value (0, p, end);
11c1ff18
PB
14878
14879 default:
14880 assert (attr->type & 0x80);
f6f0e17b 14881 val = read_uleb128 (p, &len, end);
11c1ff18
PB
14882 p += len;
14883 type = attr->type & 0x7f;
14884 if (val >= type)
14885 printf ("??? (%d)\n", val);
14886 else
14887 printf ("%s\n", attr->table[val]);
14888 return p;
14889 }
14890 }
11c1ff18 14891
f6f0e17b 14892 return display_tag_value (tag, p, end);
11c1ff18
PB
14893}
14894
104d59d1 14895static unsigned char *
60bca95a 14896display_gnu_attribute (unsigned char * p,
60abdbed 14897 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
f6f0e17b 14898 const unsigned char * const end)
104d59d1
JM
14899{
14900 int tag;
14901 unsigned int len;
60abdbed 14902 unsigned int val;
104d59d1 14903
f6f0e17b 14904 tag = read_uleb128 (p, &len, end);
104d59d1
JM
14905 p += len;
14906
14907 /* Tag_compatibility is the only generic GNU attribute defined at
14908 present. */
14909 if (tag == 32)
14910 {
f6f0e17b 14911 val = read_uleb128 (p, &len, end);
104d59d1 14912 p += len;
071436c6
NC
14913
14914 printf (_("flag = %d, vendor = "), val);
f6f0e17b
NC
14915 if (p == end)
14916 {
071436c6 14917 printf (_("<corrupt>\n"));
f6f0e17b
NC
14918 warn (_("corrupt vendor attribute\n"));
14919 }
14920 else
14921 {
4082ef84
NC
14922 if (p < end - 1)
14923 {
14924 size_t maxlen = (end - p) - 1;
071436c6 14925
4082ef84
NC
14926 print_symbol ((int) maxlen, (const char *) p);
14927 p += strnlen ((char *) p, maxlen) + 1;
14928 }
14929 else
14930 {
14931 printf (_("<corrupt>"));
14932 p = (unsigned char *) end;
14933 }
071436c6 14934 putchar ('\n');
f6f0e17b 14935 }
104d59d1
JM
14936 return p;
14937 }
14938
14939 if ((tag & 2) == 0 && display_proc_gnu_attribute)
f6f0e17b 14940 return display_proc_gnu_attribute (p, tag, end);
104d59d1 14941
f6f0e17b 14942 return display_tag_value (tag, p, end);
104d59d1
JM
14943}
14944
34c8bcba 14945static unsigned char *
f6f0e17b 14946display_power_gnu_attribute (unsigned char * p,
60abdbed 14947 unsigned int tag,
f6f0e17b 14948 const unsigned char * const end)
34c8bcba 14949{
34c8bcba 14950 unsigned int len;
005d79fd 14951 unsigned int val;
34c8bcba
JM
14952
14953 if (tag == Tag_GNU_Power_ABI_FP)
14954 {
f6f0e17b 14955 val = read_uleb128 (p, &len, end);
34c8bcba
JM
14956 p += len;
14957 printf (" Tag_GNU_Power_ABI_FP: ");
005d79fd
AM
14958 if (len == 0)
14959 {
14960 printf (_("<corrupt>\n"));
14961 return p;
14962 }
60bca95a 14963
005d79fd
AM
14964 if (val > 15)
14965 printf ("(%#x), ", val);
14966
14967 switch (val & 3)
34c8bcba
JM
14968 {
14969 case 0:
005d79fd 14970 printf (_("unspecified hard/soft float, "));
34c8bcba
JM
14971 break;
14972 case 1:
005d79fd 14973 printf (_("hard float, "));
34c8bcba
JM
14974 break;
14975 case 2:
005d79fd 14976 printf (_("soft float, "));
34c8bcba 14977 break;
3c7b9897 14978 case 3:
005d79fd 14979 printf (_("single-precision hard float, "));
3c7b9897 14980 break;
005d79fd
AM
14981 }
14982
14983 switch (val & 0xC)
14984 {
14985 case 0:
14986 printf (_("unspecified long double\n"));
14987 break;
14988 case 4:
14989 printf (_("128-bit IBM long double\n"));
14990 break;
14991 case 8:
14992 printf (_("64-bit long double\n"));
14993 break;
14994 case 12:
14995 printf (_("128-bit IEEE long double\n"));
34c8bcba
JM
14996 break;
14997 }
14998 return p;
005d79fd 14999 }
34c8bcba 15000
c6e65352
DJ
15001 if (tag == Tag_GNU_Power_ABI_Vector)
15002 {
f6f0e17b 15003 val = read_uleb128 (p, &len, end);
c6e65352
DJ
15004 p += len;
15005 printf (" Tag_GNU_Power_ABI_Vector: ");
005d79fd
AM
15006 if (len == 0)
15007 {
15008 printf (_("<corrupt>\n"));
15009 return p;
15010 }
15011
15012 if (val > 3)
15013 printf ("(%#x), ", val);
15014
15015 switch (val & 3)
c6e65352
DJ
15016 {
15017 case 0:
005d79fd 15018 printf (_("unspecified\n"));
c6e65352
DJ
15019 break;
15020 case 1:
005d79fd 15021 printf (_("generic\n"));
c6e65352
DJ
15022 break;
15023 case 2:
15024 printf ("AltiVec\n");
15025 break;
15026 case 3:
15027 printf ("SPE\n");
15028 break;
c6e65352
DJ
15029 }
15030 return p;
005d79fd 15031 }
c6e65352 15032
f82e0623
NF
15033 if (tag == Tag_GNU_Power_ABI_Struct_Return)
15034 {
005d79fd
AM
15035 val = read_uleb128 (p, &len, end);
15036 p += len;
15037 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
15038 if (len == 0)
f6f0e17b 15039 {
005d79fd 15040 printf (_("<corrupt>\n"));
f6f0e17b
NC
15041 return p;
15042 }
0b4362b0 15043
005d79fd
AM
15044 if (val > 2)
15045 printf ("(%#x), ", val);
15046
15047 switch (val & 3)
15048 {
15049 case 0:
15050 printf (_("unspecified\n"));
15051 break;
15052 case 1:
15053 printf ("r3/r4\n");
15054 break;
15055 case 2:
15056 printf (_("memory\n"));
15057 break;
15058 case 3:
15059 printf ("???\n");
15060 break;
15061 }
f82e0623
NF
15062 return p;
15063 }
15064
f6f0e17b 15065 return display_tag_value (tag & 1, p, end);
34c8bcba
JM
15066}
15067
643f7afb
AK
15068static unsigned char *
15069display_s390_gnu_attribute (unsigned char * p,
60abdbed 15070 unsigned int tag,
643f7afb
AK
15071 const unsigned char * const end)
15072{
15073 unsigned int len;
15074 int val;
15075
15076 if (tag == Tag_GNU_S390_ABI_Vector)
15077 {
15078 val = read_uleb128 (p, &len, end);
15079 p += len;
15080 printf (" Tag_GNU_S390_ABI_Vector: ");
15081
15082 switch (val)
15083 {
15084 case 0:
15085 printf (_("any\n"));
15086 break;
15087 case 1:
15088 printf (_("software\n"));
15089 break;
15090 case 2:
15091 printf (_("hardware\n"));
15092 break;
15093 default:
15094 printf ("??? (%d)\n", val);
15095 break;
15096 }
15097 return p;
15098 }
15099
15100 return display_tag_value (tag & 1, p, end);
15101}
15102
9e8c70f9 15103static void
60abdbed 15104display_sparc_hwcaps (unsigned int mask)
9e8c70f9
DM
15105{
15106 if (mask)
15107 {
32ec8896 15108 bfd_boolean first = TRUE;
071436c6 15109
9e8c70f9 15110 if (mask & ELF_SPARC_HWCAP_MUL32)
32ec8896 15111 fputs ("mul32", stdout), first = FALSE;
9e8c70f9 15112 if (mask & ELF_SPARC_HWCAP_DIV32)
32ec8896 15113 printf ("%sdiv32", first ? "" : "|"), first = FALSE;
9e8c70f9 15114 if (mask & ELF_SPARC_HWCAP_FSMULD)
32ec8896 15115 printf ("%sfsmuld", first ? "" : "|"), first = FALSE;
9e8c70f9 15116 if (mask & ELF_SPARC_HWCAP_V8PLUS)
32ec8896 15117 printf ("%sv8plus", first ? "" : "|"), first = FALSE;
9e8c70f9 15118 if (mask & ELF_SPARC_HWCAP_POPC)
32ec8896 15119 printf ("%spopc", first ? "" : "|"), first = FALSE;
9e8c70f9 15120 if (mask & ELF_SPARC_HWCAP_VIS)
32ec8896 15121 printf ("%svis", first ? "" : "|"), first = FALSE;
9e8c70f9 15122 if (mask & ELF_SPARC_HWCAP_VIS2)
32ec8896 15123 printf ("%svis2", first ? "" : "|"), first = FALSE;
9e8c70f9 15124 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
32ec8896 15125 printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE;
9e8c70f9 15126 if (mask & ELF_SPARC_HWCAP_FMAF)
32ec8896 15127 printf ("%sfmaf", first ? "" : "|"), first = FALSE;
9e8c70f9 15128 if (mask & ELF_SPARC_HWCAP_VIS3)
32ec8896 15129 printf ("%svis3", first ? "" : "|"), first = FALSE;
9e8c70f9 15130 if (mask & ELF_SPARC_HWCAP_HPC)
32ec8896 15131 printf ("%shpc", first ? "" : "|"), first = FALSE;
9e8c70f9 15132 if (mask & ELF_SPARC_HWCAP_RANDOM)
32ec8896 15133 printf ("%srandom", first ? "" : "|"), first = FALSE;
9e8c70f9 15134 if (mask & ELF_SPARC_HWCAP_TRANS)
32ec8896 15135 printf ("%strans", first ? "" : "|"), first = FALSE;
9e8c70f9 15136 if (mask & ELF_SPARC_HWCAP_FJFMAU)
32ec8896 15137 printf ("%sfjfmau", first ? "" : "|"), first = FALSE;
9e8c70f9 15138 if (mask & ELF_SPARC_HWCAP_IMA)
32ec8896 15139 printf ("%sima", first ? "" : "|"), first = FALSE;
9e8c70f9 15140 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
32ec8896 15141 printf ("%scspare", first ? "" : "|"), first = FALSE;
9e8c70f9
DM
15142 }
15143 else
071436c6
NC
15144 fputc ('0', stdout);
15145 fputc ('\n', stdout);
9e8c70f9
DM
15146}
15147
3d68f91c 15148static void
60abdbed 15149display_sparc_hwcaps2 (unsigned int mask)
3d68f91c
JM
15150{
15151 if (mask)
15152 {
32ec8896 15153 bfd_boolean first = TRUE;
071436c6 15154
3d68f91c 15155 if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
32ec8896 15156 fputs ("fjathplus", stdout), first = FALSE;
3d68f91c 15157 if (mask & ELF_SPARC_HWCAP2_VIS3B)
32ec8896 15158 printf ("%svis3b", first ? "" : "|"), first = FALSE;
3d68f91c 15159 if (mask & ELF_SPARC_HWCAP2_ADP)
32ec8896 15160 printf ("%sadp", first ? "" : "|"), first = FALSE;
3d68f91c 15161 if (mask & ELF_SPARC_HWCAP2_SPARC5)
32ec8896 15162 printf ("%ssparc5", first ? "" : "|"), first = FALSE;
3d68f91c 15163 if (mask & ELF_SPARC_HWCAP2_MWAIT)
32ec8896 15164 printf ("%smwait", first ? "" : "|"), first = FALSE;
3d68f91c 15165 if (mask & ELF_SPARC_HWCAP2_XMPMUL)
32ec8896 15166 printf ("%sxmpmul", first ? "" : "|"), first = FALSE;
3d68f91c 15167 if (mask & ELF_SPARC_HWCAP2_XMONT)
32ec8896 15168 printf ("%sxmont2", first ? "" : "|"), first = FALSE;
3d68f91c 15169 if (mask & ELF_SPARC_HWCAP2_NSEC)
32ec8896 15170 printf ("%snsec", first ? "" : "|"), first = FALSE;
3d68f91c 15171 if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
32ec8896 15172 printf ("%sfjathhpc", first ? "" : "|"), first = FALSE;
3d68f91c 15173 if (mask & ELF_SPARC_HWCAP2_FJDES)
32ec8896 15174 printf ("%sfjdes", first ? "" : "|"), first = FALSE;
3d68f91c 15175 if (mask & ELF_SPARC_HWCAP2_FJAES)
32ec8896 15176 printf ("%sfjaes", first ? "" : "|"), first = FALSE;
3d68f91c
JM
15177 }
15178 else
071436c6
NC
15179 fputc ('0', stdout);
15180 fputc ('\n', stdout);
3d68f91c
JM
15181}
15182
9e8c70f9 15183static unsigned char *
f6f0e17b 15184display_sparc_gnu_attribute (unsigned char * p,
60abdbed 15185 unsigned int tag,
f6f0e17b 15186 const unsigned char * const end)
9e8c70f9 15187{
3d68f91c
JM
15188 unsigned int len;
15189 int val;
15190
9e8c70f9
DM
15191 if (tag == Tag_GNU_Sparc_HWCAPS)
15192 {
f6f0e17b 15193 val = read_uleb128 (p, &len, end);
9e8c70f9
DM
15194 p += len;
15195 printf (" Tag_GNU_Sparc_HWCAPS: ");
9e8c70f9
DM
15196 display_sparc_hwcaps (val);
15197 return p;
3d68f91c
JM
15198 }
15199 if (tag == Tag_GNU_Sparc_HWCAPS2)
15200 {
15201 val = read_uleb128 (p, &len, end);
15202 p += len;
15203 printf (" Tag_GNU_Sparc_HWCAPS2: ");
15204 display_sparc_hwcaps2 (val);
15205 return p;
15206 }
9e8c70f9 15207
f6f0e17b 15208 return display_tag_value (tag, p, end);
9e8c70f9
DM
15209}
15210
351cdf24 15211static void
32ec8896 15212print_mips_fp_abi_value (unsigned int val)
351cdf24
MF
15213{
15214 switch (val)
15215 {
15216 case Val_GNU_MIPS_ABI_FP_ANY:
15217 printf (_("Hard or soft float\n"));
15218 break;
15219 case Val_GNU_MIPS_ABI_FP_DOUBLE:
15220 printf (_("Hard float (double precision)\n"));
15221 break;
15222 case Val_GNU_MIPS_ABI_FP_SINGLE:
15223 printf (_("Hard float (single precision)\n"));
15224 break;
15225 case Val_GNU_MIPS_ABI_FP_SOFT:
15226 printf (_("Soft float\n"));
15227 break;
15228 case Val_GNU_MIPS_ABI_FP_OLD_64:
15229 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
15230 break;
15231 case Val_GNU_MIPS_ABI_FP_XX:
15232 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
15233 break;
15234 case Val_GNU_MIPS_ABI_FP_64:
15235 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
15236 break;
15237 case Val_GNU_MIPS_ABI_FP_64A:
15238 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
15239 break;
3350cc01
CM
15240 case Val_GNU_MIPS_ABI_FP_NAN2008:
15241 printf (_("NaN 2008 compatibility\n"));
15242 break;
351cdf24
MF
15243 default:
15244 printf ("??? (%d)\n", val);
15245 break;
15246 }
15247}
15248
2cf19d5c 15249static unsigned char *
f6f0e17b 15250display_mips_gnu_attribute (unsigned char * p,
60abdbed 15251 unsigned int tag,
f6f0e17b 15252 const unsigned char * const end)
2cf19d5c 15253{
2cf19d5c
JM
15254 if (tag == Tag_GNU_MIPS_ABI_FP)
15255 {
f6f0e17b 15256 unsigned int len;
32ec8896 15257 unsigned int val;
f6f0e17b
NC
15258
15259 val = read_uleb128 (p, &len, end);
2cf19d5c
JM
15260 p += len;
15261 printf (" Tag_GNU_MIPS_ABI_FP: ");
60bca95a 15262
351cdf24
MF
15263 print_mips_fp_abi_value (val);
15264
2cf19d5c
JM
15265 return p;
15266 }
15267
a9f58168
CF
15268 if (tag == Tag_GNU_MIPS_ABI_MSA)
15269 {
15270 unsigned int len;
32ec8896 15271 unsigned int val;
a9f58168
CF
15272
15273 val = read_uleb128 (p, &len, end);
15274 p += len;
15275 printf (" Tag_GNU_MIPS_ABI_MSA: ");
15276
15277 switch (val)
15278 {
15279 case Val_GNU_MIPS_ABI_MSA_ANY:
15280 printf (_("Any MSA or not\n"));
15281 break;
15282 case Val_GNU_MIPS_ABI_MSA_128:
15283 printf (_("128-bit MSA\n"));
15284 break;
15285 default:
15286 printf ("??? (%d)\n", val);
15287 break;
15288 }
15289 return p;
15290 }
15291
f6f0e17b 15292 return display_tag_value (tag & 1, p, end);
2cf19d5c
JM
15293}
15294
59e6276b 15295static unsigned char *
f6f0e17b
NC
15296display_tic6x_attribute (unsigned char * p,
15297 const unsigned char * const end)
59e6276b 15298{
60abdbed 15299 unsigned int tag;
59e6276b
JM
15300 unsigned int len;
15301 int val;
15302
f6f0e17b 15303 tag = read_uleb128 (p, &len, end);
59e6276b
JM
15304 p += len;
15305
15306 switch (tag)
15307 {
75fa6dc1 15308 case Tag_ISA:
f6f0e17b 15309 val = read_uleb128 (p, &len, end);
59e6276b 15310 p += len;
75fa6dc1 15311 printf (" Tag_ISA: ");
59e6276b
JM
15312
15313 switch (val)
15314 {
75fa6dc1 15315 case C6XABI_Tag_ISA_none:
59e6276b
JM
15316 printf (_("None\n"));
15317 break;
75fa6dc1 15318 case C6XABI_Tag_ISA_C62X:
59e6276b
JM
15319 printf ("C62x\n");
15320 break;
75fa6dc1 15321 case C6XABI_Tag_ISA_C67X:
59e6276b
JM
15322 printf ("C67x\n");
15323 break;
75fa6dc1 15324 case C6XABI_Tag_ISA_C67XP:
59e6276b
JM
15325 printf ("C67x+\n");
15326 break;
75fa6dc1 15327 case C6XABI_Tag_ISA_C64X:
59e6276b
JM
15328 printf ("C64x\n");
15329 break;
75fa6dc1 15330 case C6XABI_Tag_ISA_C64XP:
59e6276b
JM
15331 printf ("C64x+\n");
15332 break;
75fa6dc1 15333 case C6XABI_Tag_ISA_C674X:
59e6276b
JM
15334 printf ("C674x\n");
15335 break;
15336 default:
15337 printf ("??? (%d)\n", val);
15338 break;
15339 }
15340 return p;
15341
87779176 15342 case Tag_ABI_wchar_t:
f6f0e17b 15343 val = read_uleb128 (p, &len, end);
87779176
JM
15344 p += len;
15345 printf (" Tag_ABI_wchar_t: ");
15346 switch (val)
15347 {
15348 case 0:
15349 printf (_("Not used\n"));
15350 break;
15351 case 1:
15352 printf (_("2 bytes\n"));
15353 break;
15354 case 2:
15355 printf (_("4 bytes\n"));
15356 break;
15357 default:
15358 printf ("??? (%d)\n", val);
15359 break;
15360 }
15361 return p;
15362
15363 case Tag_ABI_stack_align_needed:
f6f0e17b 15364 val = read_uleb128 (p, &len, end);
87779176
JM
15365 p += len;
15366 printf (" Tag_ABI_stack_align_needed: ");
15367 switch (val)
15368 {
15369 case 0:
15370 printf (_("8-byte\n"));
15371 break;
15372 case 1:
15373 printf (_("16-byte\n"));
15374 break;
15375 default:
15376 printf ("??? (%d)\n", val);
15377 break;
15378 }
15379 return p;
15380
15381 case Tag_ABI_stack_align_preserved:
f6f0e17b 15382 val = read_uleb128 (p, &len, end);
87779176
JM
15383 p += len;
15384 printf (" Tag_ABI_stack_align_preserved: ");
15385 switch (val)
15386 {
15387 case 0:
15388 printf (_("8-byte\n"));
15389 break;
15390 case 1:
15391 printf (_("16-byte\n"));
15392 break;
15393 default:
15394 printf ("??? (%d)\n", val);
15395 break;
15396 }
15397 return p;
15398
b5593623 15399 case Tag_ABI_DSBT:
f6f0e17b 15400 val = read_uleb128 (p, &len, end);
b5593623
JM
15401 p += len;
15402 printf (" Tag_ABI_DSBT: ");
15403 switch (val)
15404 {
15405 case 0:
15406 printf (_("DSBT addressing not used\n"));
15407 break;
15408 case 1:
15409 printf (_("DSBT addressing used\n"));
15410 break;
15411 default:
15412 printf ("??? (%d)\n", val);
15413 break;
15414 }
15415 return p;
15416
87779176 15417 case Tag_ABI_PID:
f6f0e17b 15418 val = read_uleb128 (p, &len, end);
87779176
JM
15419 p += len;
15420 printf (" Tag_ABI_PID: ");
15421 switch (val)
15422 {
15423 case 0:
15424 printf (_("Data addressing position-dependent\n"));
15425 break;
15426 case 1:
15427 printf (_("Data addressing position-independent, GOT near DP\n"));
15428 break;
15429 case 2:
15430 printf (_("Data addressing position-independent, GOT far from DP\n"));
15431 break;
15432 default:
15433 printf ("??? (%d)\n", val);
15434 break;
15435 }
15436 return p;
15437
15438 case Tag_ABI_PIC:
f6f0e17b 15439 val = read_uleb128 (p, &len, end);
87779176
JM
15440 p += len;
15441 printf (" Tag_ABI_PIC: ");
15442 switch (val)
15443 {
15444 case 0:
15445 printf (_("Code addressing position-dependent\n"));
15446 break;
15447 case 1:
15448 printf (_("Code addressing position-independent\n"));
15449 break;
15450 default:
15451 printf ("??? (%d)\n", val);
15452 break;
15453 }
15454 return p;
15455
15456 case Tag_ABI_array_object_alignment:
f6f0e17b 15457 val = read_uleb128 (p, &len, end);
87779176
JM
15458 p += len;
15459 printf (" Tag_ABI_array_object_alignment: ");
15460 switch (val)
15461 {
15462 case 0:
15463 printf (_("8-byte\n"));
15464 break;
15465 case 1:
15466 printf (_("4-byte\n"));
15467 break;
15468 case 2:
15469 printf (_("16-byte\n"));
15470 break;
15471 default:
15472 printf ("??? (%d)\n", val);
15473 break;
15474 }
15475 return p;
15476
15477 case Tag_ABI_array_object_align_expected:
f6f0e17b 15478 val = read_uleb128 (p, &len, end);
87779176
JM
15479 p += len;
15480 printf (" Tag_ABI_array_object_align_expected: ");
15481 switch (val)
15482 {
15483 case 0:
15484 printf (_("8-byte\n"));
15485 break;
15486 case 1:
15487 printf (_("4-byte\n"));
15488 break;
15489 case 2:
15490 printf (_("16-byte\n"));
15491 break;
15492 default:
15493 printf ("??? (%d)\n", val);
15494 break;
15495 }
15496 return p;
15497
3cbd1c06 15498 case Tag_ABI_compatibility:
071436c6 15499 {
071436c6
NC
15500 val = read_uleb128 (p, &len, end);
15501 p += len;
15502 printf (" Tag_ABI_compatibility: ");
071436c6 15503 printf (_("flag = %d, vendor = "), val);
4082ef84
NC
15504 if (p < end - 1)
15505 {
15506 size_t maxlen = (end - p) - 1;
15507
15508 print_symbol ((int) maxlen, (const char *) p);
15509 p += strnlen ((char *) p, maxlen) + 1;
15510 }
15511 else
15512 {
15513 printf (_("<corrupt>"));
15514 p = (unsigned char *) end;
15515 }
071436c6 15516 putchar ('\n');
071436c6
NC
15517 return p;
15518 }
87779176
JM
15519
15520 case Tag_ABI_conformance:
071436c6 15521 {
4082ef84
NC
15522 printf (" Tag_ABI_conformance: \"");
15523 if (p < end - 1)
15524 {
15525 size_t maxlen = (end - p) - 1;
071436c6 15526
4082ef84
NC
15527 print_symbol ((int) maxlen, (const char *) p);
15528 p += strnlen ((char *) p, maxlen) + 1;
15529 }
15530 else
15531 {
15532 printf (_("<corrupt>"));
15533 p = (unsigned char *) end;
15534 }
071436c6 15535 printf ("\"\n");
071436c6
NC
15536 return p;
15537 }
59e6276b
JM
15538 }
15539
f6f0e17b
NC
15540 return display_tag_value (tag, p, end);
15541}
59e6276b 15542
f6f0e17b 15543static void
60abdbed 15544display_raw_attribute (unsigned char * p, unsigned char const * const end)
f6f0e17b
NC
15545{
15546 unsigned long addr = 0;
15547 size_t bytes = end - p;
15548
feceaa59 15549 assert (end >= p);
f6f0e17b 15550 while (bytes)
87779176 15551 {
f6f0e17b
NC
15552 int j;
15553 int k;
15554 int lbytes = (bytes > 16 ? 16 : bytes);
15555
15556 printf (" 0x%8.8lx ", addr);
15557
15558 for (j = 0; j < 16; j++)
15559 {
15560 if (j < lbytes)
15561 printf ("%2.2x", p[j]);
15562 else
15563 printf (" ");
15564
15565 if ((j & 3) == 3)
15566 printf (" ");
15567 }
15568
15569 for (j = 0; j < lbytes; j++)
15570 {
15571 k = p[j];
15572 if (k >= ' ' && k < 0x7f)
15573 printf ("%c", k);
15574 else
15575 printf (".");
15576 }
15577
15578 putchar ('\n');
15579
15580 p += lbytes;
15581 bytes -= lbytes;
15582 addr += lbytes;
87779176 15583 }
59e6276b 15584
f6f0e17b 15585 putchar ('\n');
59e6276b
JM
15586}
15587
13761a11
NC
15588static unsigned char *
15589display_msp430x_attribute (unsigned char * p,
15590 const unsigned char * const end)
15591{
15592 unsigned int len;
60abdbed
NC
15593 unsigned int val;
15594 unsigned int tag;
13761a11
NC
15595
15596 tag = read_uleb128 (p, & len, end);
15597 p += len;
0b4362b0 15598
13761a11
NC
15599 switch (tag)
15600 {
15601 case OFBA_MSPABI_Tag_ISA:
15602 val = read_uleb128 (p, &len, end);
15603 p += len;
15604 printf (" Tag_ISA: ");
15605 switch (val)
15606 {
15607 case 0: printf (_("None\n")); break;
15608 case 1: printf (_("MSP430\n")); break;
15609 case 2: printf (_("MSP430X\n")); break;
15610 default: printf ("??? (%d)\n", val); break;
15611 }
15612 break;
15613
15614 case OFBA_MSPABI_Tag_Code_Model:
15615 val = read_uleb128 (p, &len, end);
15616 p += len;
15617 printf (" Tag_Code_Model: ");
15618 switch (val)
15619 {
15620 case 0: printf (_("None\n")); break;
15621 case 1: printf (_("Small\n")); break;
15622 case 2: printf (_("Large\n")); break;
15623 default: printf ("??? (%d)\n", val); break;
15624 }
15625 break;
15626
15627 case OFBA_MSPABI_Tag_Data_Model:
15628 val = read_uleb128 (p, &len, end);
15629 p += len;
15630 printf (" Tag_Data_Model: ");
15631 switch (val)
15632 {
15633 case 0: printf (_("None\n")); break;
15634 case 1: printf (_("Small\n")); break;
15635 case 2: printf (_("Large\n")); break;
15636 case 3: printf (_("Restricted Large\n")); break;
15637 default: printf ("??? (%d)\n", val); break;
15638 }
15639 break;
15640
15641 default:
15642 printf (_(" <unknown tag %d>: "), tag);
15643
15644 if (tag & 1)
15645 {
071436c6 15646 putchar ('"');
4082ef84
NC
15647 if (p < end - 1)
15648 {
15649 size_t maxlen = (end - p) - 1;
15650
15651 print_symbol ((int) maxlen, (const char *) p);
15652 p += strnlen ((char *) p, maxlen) + 1;
15653 }
15654 else
15655 {
15656 printf (_("<corrupt>"));
15657 p = (unsigned char *) end;
15658 }
071436c6 15659 printf ("\"\n");
13761a11
NC
15660 }
15661 else
15662 {
15663 val = read_uleb128 (p, &len, end);
15664 p += len;
15665 printf ("%d (0x%x)\n", val, val);
15666 }
15667 break;
15668 }
15669
4082ef84 15670 assert (p <= end);
13761a11
NC
15671 return p;
15672}
15673
2dc8dd17
JW
15674struct riscv_attr_tag_t {
15675 const char *name;
15676 int tag;
15677};
15678
15679static struct riscv_attr_tag_t riscv_attr_tag[] =
15680{
15681#define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
15682 T(arch),
15683 T(priv_spec),
15684 T(priv_spec_minor),
15685 T(priv_spec_revision),
15686 T(unaligned_access),
15687 T(stack_align),
15688#undef T
15689};
15690
15691static unsigned char *
15692display_riscv_attribute (unsigned char *p,
15693 const unsigned char * const end)
15694{
15695 unsigned int len;
15696 int val;
15697 int tag;
15698 struct riscv_attr_tag_t *attr = NULL;
15699 unsigned i;
15700
15701 tag = read_uleb128 (p, &len, end);
15702 p += len;
15703
15704 /* Find the name of attribute. */
15705 for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++)
15706 {
15707 if (riscv_attr_tag[i].tag == tag)
15708 {
15709 attr = &riscv_attr_tag[i];
15710 break;
15711 }
15712 }
15713
15714 if (attr)
15715 printf (" %s: ", attr->name);
15716 else
15717 return display_tag_value (tag, p, end);
15718
15719 switch (tag)
15720 {
15721 case Tag_RISCV_priv_spec:
15722 case Tag_RISCV_priv_spec_minor:
15723 case Tag_RISCV_priv_spec_revision:
15724 val = read_uleb128 (p, &len, end);
15725 p += len;
15726 printf (_("%d\n"), val);
15727 break;
15728 case Tag_RISCV_unaligned_access:
15729 val = read_uleb128 (p, &len, end);
15730 p += len;
15731 switch (val)
15732 {
15733 case 0:
15734 printf (_("No unaligned access\n"));
15735 break;
15736 case 1:
15737 printf (_("Unaligned access\n"));
15738 break;
15739 }
15740 break;
15741 case Tag_RISCV_stack_align:
15742 val = read_uleb128 (p, &len, end);
15743 p += len;
15744 printf (_("%d-bytes\n"), val);
15745 break;
15746 case Tag_RISCV_arch:
15747 p = display_tag_value (-1, p, end);
15748 break;
15749 default:
15750 return display_tag_value (tag, p, end);
15751 }
15752
15753 return p;
15754}
15755
32ec8896 15756static bfd_boolean
dda8d76d 15757process_attributes (Filedata * filedata,
60bca95a 15758 const char * public_name,
104d59d1 15759 unsigned int proc_type,
f6f0e17b 15760 unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
60abdbed 15761 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
11c1ff18 15762{
2cf0635d 15763 Elf_Internal_Shdr * sect;
11c1ff18 15764 unsigned i;
32ec8896 15765 bfd_boolean res = TRUE;
11c1ff18
PB
15766
15767 /* Find the section header so that we get the size. */
dda8d76d
NC
15768 for (i = 0, sect = filedata->section_headers;
15769 i < filedata->file_header.e_shnum;
11c1ff18
PB
15770 i++, sect++)
15771 {
071436c6
NC
15772 unsigned char * contents;
15773 unsigned char * p;
15774
104d59d1 15775 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
11c1ff18
PB
15776 continue;
15777
dda8d76d 15778 contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1,
3f5e193b 15779 sect->sh_size, _("attributes"));
60bca95a 15780 if (contents == NULL)
32ec8896
NC
15781 {
15782 res = FALSE;
15783 continue;
15784 }
60bca95a 15785
11c1ff18 15786 p = contents;
60abdbed
NC
15787 /* The first character is the version of the attributes.
15788 Currently only version 1, (aka 'A') is recognised here. */
15789 if (*p != 'A')
32ec8896
NC
15790 {
15791 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
15792 res = FALSE;
15793 }
60abdbed 15794 else
11c1ff18 15795 {
071436c6
NC
15796 bfd_vma section_len;
15797
15798 section_len = sect->sh_size - 1;
11c1ff18 15799 p++;
60bca95a 15800
071436c6 15801 while (section_len > 0)
11c1ff18 15802 {
071436c6 15803 bfd_vma attr_len;
e9847026 15804 unsigned int namelen;
11c1ff18 15805 bfd_boolean public_section;
104d59d1 15806 bfd_boolean gnu_section;
11c1ff18 15807
071436c6 15808 if (section_len <= 4)
e0a31db1
NC
15809 {
15810 error (_("Tag section ends prematurely\n"));
32ec8896 15811 res = FALSE;
e0a31db1
NC
15812 break;
15813 }
071436c6 15814 attr_len = byte_get (p, 4);
11c1ff18 15815 p += 4;
60bca95a 15816
071436c6 15817 if (attr_len > section_len)
11c1ff18 15818 {
071436c6
NC
15819 error (_("Bad attribute length (%u > %u)\n"),
15820 (unsigned) attr_len, (unsigned) section_len);
15821 attr_len = section_len;
32ec8896 15822 res = FALSE;
11c1ff18 15823 }
74e1a04b 15824 /* PR 17531: file: 001-101425-0.004 */
071436c6 15825 else if (attr_len < 5)
74e1a04b 15826 {
071436c6 15827 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
32ec8896 15828 res = FALSE;
74e1a04b
NC
15829 break;
15830 }
e9847026 15831
071436c6
NC
15832 section_len -= attr_len;
15833 attr_len -= 4;
15834
15835 namelen = strnlen ((char *) p, attr_len) + 1;
15836 if (namelen == 0 || namelen >= attr_len)
e9847026
NC
15837 {
15838 error (_("Corrupt attribute section name\n"));
32ec8896 15839 res = FALSE;
e9847026
NC
15840 break;
15841 }
15842
071436c6
NC
15843 printf (_("Attribute Section: "));
15844 print_symbol (INT_MAX, (const char *) p);
15845 putchar ('\n');
60bca95a
NC
15846
15847 if (public_name && streq ((char *) p, public_name))
11c1ff18
PB
15848 public_section = TRUE;
15849 else
15850 public_section = FALSE;
60bca95a
NC
15851
15852 if (streq ((char *) p, "gnu"))
104d59d1
JM
15853 gnu_section = TRUE;
15854 else
15855 gnu_section = FALSE;
60bca95a 15856
11c1ff18 15857 p += namelen;
071436c6 15858 attr_len -= namelen;
e0a31db1 15859
071436c6 15860 while (attr_len > 0 && p < contents + sect->sh_size)
11c1ff18 15861 {
e0a31db1 15862 int tag;
11c1ff18
PB
15863 int val;
15864 bfd_vma size;
071436c6 15865 unsigned char * end;
60bca95a 15866
e0a31db1 15867 /* PR binutils/17531: Safe handling of corrupt files. */
071436c6 15868 if (attr_len < 6)
e0a31db1
NC
15869 {
15870 error (_("Unused bytes at end of section\n"));
32ec8896 15871 res = FALSE;
e0a31db1
NC
15872 section_len = 0;
15873 break;
15874 }
15875
15876 tag = *(p++);
11c1ff18 15877 size = byte_get (p, 4);
071436c6 15878 if (size > attr_len)
11c1ff18 15879 {
e9847026 15880 error (_("Bad subsection length (%u > %u)\n"),
071436c6 15881 (unsigned) size, (unsigned) attr_len);
32ec8896 15882 res = FALSE;
071436c6 15883 size = attr_len;
11c1ff18 15884 }
e0a31db1
NC
15885 /* PR binutils/17531: Safe handling of corrupt files. */
15886 if (size < 6)
15887 {
15888 error (_("Bad subsection length (%u < 6)\n"),
15889 (unsigned) size);
32ec8896 15890 res = FALSE;
e0a31db1
NC
15891 section_len = 0;
15892 break;
15893 }
60bca95a 15894
071436c6 15895 attr_len -= size;
11c1ff18 15896 end = p + size - 1;
071436c6 15897 assert (end <= contents + sect->sh_size);
11c1ff18 15898 p += 4;
60bca95a 15899
11c1ff18
PB
15900 switch (tag)
15901 {
15902 case 1:
2b692964 15903 printf (_("File Attributes\n"));
11c1ff18
PB
15904 break;
15905 case 2:
2b692964 15906 printf (_("Section Attributes:"));
11c1ff18
PB
15907 goto do_numlist;
15908 case 3:
2b692964 15909 printf (_("Symbol Attributes:"));
1a0670f3 15910 /* Fall through. */
11c1ff18
PB
15911 do_numlist:
15912 for (;;)
15913 {
91d6fa6a 15914 unsigned int j;
60bca95a 15915
f6f0e17b 15916 val = read_uleb128 (p, &j, end);
91d6fa6a 15917 p += j;
11c1ff18
PB
15918 if (val == 0)
15919 break;
15920 printf (" %d", val);
15921 }
15922 printf ("\n");
15923 break;
15924 default:
2b692964 15925 printf (_("Unknown tag: %d\n"), tag);
11c1ff18
PB
15926 public_section = FALSE;
15927 break;
15928 }
60bca95a 15929
071436c6 15930 if (public_section && display_pub_attribute != NULL)
11c1ff18
PB
15931 {
15932 while (p < end)
f6f0e17b 15933 p = display_pub_attribute (p, end);
60abdbed 15934 assert (p == end);
104d59d1 15935 }
071436c6 15936 else if (gnu_section && display_proc_gnu_attribute != NULL)
104d59d1
JM
15937 {
15938 while (p < end)
15939 p = display_gnu_attribute (p,
f6f0e17b
NC
15940 display_proc_gnu_attribute,
15941 end);
60abdbed 15942 assert (p == end);
11c1ff18 15943 }
071436c6 15944 else if (p < end)
11c1ff18 15945 {
071436c6 15946 printf (_(" Unknown attribute:\n"));
f6f0e17b 15947 display_raw_attribute (p, end);
11c1ff18
PB
15948 p = end;
15949 }
071436c6
NC
15950 else
15951 attr_len = 0;
11c1ff18
PB
15952 }
15953 }
15954 }
d70c5fc7 15955
60bca95a 15956 free (contents);
11c1ff18 15957 }
32ec8896
NC
15958
15959 return res;
11c1ff18
PB
15960}
15961
ccb4c951
RS
15962/* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
15963 Print the Address, Access and Initial fields of an entry at VMA ADDR
82b1b41b
NC
15964 and return the VMA of the next entry, or -1 if there was a problem.
15965 Does not read from DATA_END or beyond. */
ccb4c951
RS
15966
15967static bfd_vma
82b1b41b
NC
15968print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
15969 unsigned char * data_end)
ccb4c951
RS
15970{
15971 printf (" ");
15972 print_vma (addr, LONG_HEX);
15973 printf (" ");
15974 if (addr < pltgot + 0xfff0)
15975 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
15976 else
15977 printf ("%10s", "");
15978 printf (" ");
15979 if (data == NULL)
2b692964 15980 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
ccb4c951
RS
15981 else
15982 {
15983 bfd_vma entry;
82b1b41b 15984 unsigned char * from = data + addr - pltgot;
ccb4c951 15985
82b1b41b
NC
15986 if (from + (is_32bit_elf ? 4 : 8) > data_end)
15987 {
15988 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
15989 printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
15990 return (bfd_vma) -1;
15991 }
15992 else
15993 {
15994 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
15995 print_vma (entry, LONG_HEX);
15996 }
ccb4c951
RS
15997 }
15998 return addr + (is_32bit_elf ? 4 : 8);
15999}
16000
861fb55a
DJ
16001/* DATA points to the contents of a MIPS PLT GOT that starts at VMA
16002 PLTGOT. Print the Address and Initial fields of an entry at VMA
16003 ADDR and return the VMA of the next entry. */
16004
16005static bfd_vma
2cf0635d 16006print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
861fb55a
DJ
16007{
16008 printf (" ");
16009 print_vma (addr, LONG_HEX);
16010 printf (" ");
16011 if (data == NULL)
2b692964 16012 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
861fb55a
DJ
16013 else
16014 {
16015 bfd_vma entry;
16016
16017 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
16018 print_vma (entry, LONG_HEX);
16019 }
16020 return addr + (is_32bit_elf ? 4 : 8);
16021}
16022
351cdf24
MF
16023static void
16024print_mips_ases (unsigned int mask)
16025{
16026 if (mask & AFL_ASE_DSP)
16027 fputs ("\n\tDSP ASE", stdout);
16028 if (mask & AFL_ASE_DSPR2)
16029 fputs ("\n\tDSP R2 ASE", stdout);
8f4f9071
MF
16030 if (mask & AFL_ASE_DSPR3)
16031 fputs ("\n\tDSP R3 ASE", stdout);
351cdf24
MF
16032 if (mask & AFL_ASE_EVA)
16033 fputs ("\n\tEnhanced VA Scheme", stdout);
16034 if (mask & AFL_ASE_MCU)
16035 fputs ("\n\tMCU (MicroController) ASE", stdout);
16036 if (mask & AFL_ASE_MDMX)
16037 fputs ("\n\tMDMX ASE", stdout);
16038 if (mask & AFL_ASE_MIPS3D)
16039 fputs ("\n\tMIPS-3D ASE", stdout);
16040 if (mask & AFL_ASE_MT)
16041 fputs ("\n\tMT ASE", stdout);
16042 if (mask & AFL_ASE_SMARTMIPS)
16043 fputs ("\n\tSmartMIPS ASE", stdout);
16044 if (mask & AFL_ASE_VIRT)
16045 fputs ("\n\tVZ ASE", stdout);
16046 if (mask & AFL_ASE_MSA)
16047 fputs ("\n\tMSA ASE", stdout);
16048 if (mask & AFL_ASE_MIPS16)
16049 fputs ("\n\tMIPS16 ASE", stdout);
16050 if (mask & AFL_ASE_MICROMIPS)
16051 fputs ("\n\tMICROMIPS ASE", stdout);
16052 if (mask & AFL_ASE_XPA)
16053 fputs ("\n\tXPA ASE", stdout);
25499ac7
MR
16054 if (mask & AFL_ASE_MIPS16E2)
16055 fputs ("\n\tMIPS16e2 ASE", stdout);
730c3174
SE
16056 if (mask & AFL_ASE_CRC)
16057 fputs ("\n\tCRC ASE", stdout);
6f20c942
FS
16058 if (mask & AFL_ASE_GINV)
16059 fputs ("\n\tGINV ASE", stdout);
8095d2f7
CX
16060 if (mask & AFL_ASE_LOONGSON_MMI)
16061 fputs ("\n\tLoongson MMI ASE", stdout);
716c08de
CX
16062 if (mask & AFL_ASE_LOONGSON_CAM)
16063 fputs ("\n\tLoongson CAM ASE", stdout);
bdc6c06e
CX
16064 if (mask & AFL_ASE_LOONGSON_EXT)
16065 fputs ("\n\tLoongson EXT ASE", stdout);
a693765e
CX
16066 if (mask & AFL_ASE_LOONGSON_EXT2)
16067 fputs ("\n\tLoongson EXT2 ASE", stdout);
351cdf24
MF
16068 if (mask == 0)
16069 fprintf (stdout, "\n\t%s", _("None"));
00ac7aa0
MF
16070 else if ((mask & ~AFL_ASE_MASK) != 0)
16071 fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
351cdf24
MF
16072}
16073
16074static void
16075print_mips_isa_ext (unsigned int isa_ext)
16076{
16077 switch (isa_ext)
16078 {
16079 case 0:
16080 fputs (_("None"), stdout);
16081 break;
16082 case AFL_EXT_XLR:
16083 fputs ("RMI XLR", stdout);
16084 break;
2c629856
N
16085 case AFL_EXT_OCTEON3:
16086 fputs ("Cavium Networks Octeon3", stdout);
16087 break;
351cdf24
MF
16088 case AFL_EXT_OCTEON2:
16089 fputs ("Cavium Networks Octeon2", stdout);
16090 break;
16091 case AFL_EXT_OCTEONP:
16092 fputs ("Cavium Networks OcteonP", stdout);
16093 break;
351cdf24
MF
16094 case AFL_EXT_OCTEON:
16095 fputs ("Cavium Networks Octeon", stdout);
16096 break;
16097 case AFL_EXT_5900:
16098 fputs ("Toshiba R5900", stdout);
16099 break;
16100 case AFL_EXT_4650:
16101 fputs ("MIPS R4650", stdout);
16102 break;
16103 case AFL_EXT_4010:
16104 fputs ("LSI R4010", stdout);
16105 break;
16106 case AFL_EXT_4100:
16107 fputs ("NEC VR4100", stdout);
16108 break;
16109 case AFL_EXT_3900:
16110 fputs ("Toshiba R3900", stdout);
16111 break;
16112 case AFL_EXT_10000:
16113 fputs ("MIPS R10000", stdout);
16114 break;
16115 case AFL_EXT_SB1:
16116 fputs ("Broadcom SB-1", stdout);
16117 break;
16118 case AFL_EXT_4111:
16119 fputs ("NEC VR4111/VR4181", stdout);
16120 break;
16121 case AFL_EXT_4120:
16122 fputs ("NEC VR4120", stdout);
16123 break;
16124 case AFL_EXT_5400:
16125 fputs ("NEC VR5400", stdout);
16126 break;
16127 case AFL_EXT_5500:
16128 fputs ("NEC VR5500", stdout);
16129 break;
16130 case AFL_EXT_LOONGSON_2E:
16131 fputs ("ST Microelectronics Loongson 2E", stdout);
16132 break;
16133 case AFL_EXT_LOONGSON_2F:
16134 fputs ("ST Microelectronics Loongson 2F", stdout);
16135 break;
38bf472a
MR
16136 case AFL_EXT_INTERAPTIV_MR2:
16137 fputs ("Imagination interAptiv MR2", stdout);
16138 break;
351cdf24 16139 default:
00ac7aa0 16140 fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
351cdf24
MF
16141 }
16142}
16143
32ec8896 16144static signed int
351cdf24
MF
16145get_mips_reg_size (int reg_size)
16146{
16147 return (reg_size == AFL_REG_NONE) ? 0
16148 : (reg_size == AFL_REG_32) ? 32
16149 : (reg_size == AFL_REG_64) ? 64
16150 : (reg_size == AFL_REG_128) ? 128
16151 : -1;
16152}
16153
32ec8896 16154static bfd_boolean
dda8d76d 16155process_mips_specific (Filedata * filedata)
5b18a4bc 16156{
2cf0635d 16157 Elf_Internal_Dyn * entry;
351cdf24 16158 Elf_Internal_Shdr *sect = NULL;
19e6b90e
L
16159 size_t liblist_offset = 0;
16160 size_t liblistno = 0;
16161 size_t conflictsno = 0;
16162 size_t options_offset = 0;
16163 size_t conflicts_offset = 0;
861fb55a
DJ
16164 size_t pltrelsz = 0;
16165 size_t pltrel = 0;
ccb4c951 16166 bfd_vma pltgot = 0;
861fb55a
DJ
16167 bfd_vma mips_pltgot = 0;
16168 bfd_vma jmprel = 0;
ccb4c951
RS
16169 bfd_vma local_gotno = 0;
16170 bfd_vma gotsym = 0;
16171 bfd_vma symtabno = 0;
32ec8896 16172 bfd_boolean res = TRUE;
103f02d3 16173
dda8d76d 16174 if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
32ec8896
NC
16175 display_mips_gnu_attribute))
16176 res = FALSE;
2cf19d5c 16177
dda8d76d 16178 sect = find_section (filedata, ".MIPS.abiflags");
351cdf24
MF
16179
16180 if (sect != NULL)
16181 {
16182 Elf_External_ABIFlags_v0 *abiflags_ext;
16183 Elf_Internal_ABIFlags_v0 abiflags_in;
16184
16185 if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
32ec8896
NC
16186 {
16187 error (_("Corrupt MIPS ABI Flags section.\n"));
16188 res = FALSE;
16189 }
351cdf24
MF
16190 else
16191 {
dda8d76d 16192 abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
351cdf24
MF
16193 sect->sh_size, _("MIPS ABI Flags section"));
16194 if (abiflags_ext)
16195 {
16196 abiflags_in.version = BYTE_GET (abiflags_ext->version);
16197 abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
16198 abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
16199 abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
16200 abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
16201 abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
16202 abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
16203 abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
16204 abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
16205 abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
16206 abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
16207
16208 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
16209 printf ("\nISA: MIPS%d", abiflags_in.isa_level);
16210 if (abiflags_in.isa_rev > 1)
16211 printf ("r%d", abiflags_in.isa_rev);
16212 printf ("\nGPR size: %d",
16213 get_mips_reg_size (abiflags_in.gpr_size));
16214 printf ("\nCPR1 size: %d",
16215 get_mips_reg_size (abiflags_in.cpr1_size));
16216 printf ("\nCPR2 size: %d",
16217 get_mips_reg_size (abiflags_in.cpr2_size));
16218 fputs ("\nFP ABI: ", stdout);
16219 print_mips_fp_abi_value (abiflags_in.fp_abi);
16220 fputs ("ISA Extension: ", stdout);
16221 print_mips_isa_ext (abiflags_in.isa_ext);
16222 fputs ("\nASEs:", stdout);
16223 print_mips_ases (abiflags_in.ases);
16224 printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
16225 printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
16226 fputc ('\n', stdout);
16227 free (abiflags_ext);
16228 }
16229 }
16230 }
16231
19e6b90e
L
16232 /* We have a lot of special sections. Thanks SGI! */
16233 if (dynamic_section == NULL)
bbdd9a68
MR
16234 {
16235 /* No dynamic information available. See if there is static GOT. */
dda8d76d 16236 sect = find_section (filedata, ".got");
bbdd9a68
MR
16237 if (sect != NULL)
16238 {
16239 unsigned char *data_end;
16240 unsigned char *data;
16241 bfd_vma ent, end;
16242 int addr_size;
16243
16244 pltgot = sect->sh_addr;
16245
16246 ent = pltgot;
16247 addr_size = (is_32bit_elf ? 4 : 8);
16248 end = pltgot + sect->sh_size;
16249
dda8d76d 16250 data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset,
bbdd9a68
MR
16251 end - pltgot, 1,
16252 _("Global Offset Table data"));
16253 /* PR 12855: Null data is handled gracefully throughout. */
16254 data_end = data + (end - pltgot);
16255
16256 printf (_("\nStatic GOT:\n"));
16257 printf (_(" Canonical gp value: "));
16258 print_vma (ent + 0x7ff0, LONG_HEX);
16259 printf ("\n\n");
16260
16261 /* In a dynamic binary GOT[0] is reserved for the dynamic
16262 loader to store the lazy resolver pointer, however in
16263 a static binary it may well have been omitted and GOT
16264 reduced to a table of addresses.
16265 PR 21344: Check for the entry being fully available
16266 before fetching it. */
16267 if (data
16268 && data + ent - pltgot + addr_size <= data_end
16269 && byte_get (data + ent - pltgot, addr_size) == 0)
16270 {
16271 printf (_(" Reserved entries:\n"));
16272 printf (_(" %*s %10s %*s\n"),
16273 addr_size * 2, _("Address"), _("Access"),
16274 addr_size * 2, _("Value"));
16275 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16276 printf ("\n");
16277 if (ent == (bfd_vma) -1)
16278 goto sgot_print_fail;
16279
16280 /* Check for the MSB of GOT[1] being set, identifying a
16281 GNU object. This entry will be used by some runtime
16282 loaders, to store the module pointer. Otherwise this
16283 is an ordinary local entry.
16284 PR 21344: Check for the entry being fully available
16285 before fetching it. */
16286 if (data
16287 && data + ent - pltgot + addr_size <= data_end
16288 && (byte_get (data + ent - pltgot, addr_size)
16289 >> (addr_size * 8 - 1)) != 0)
16290 {
16291 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16292 printf ("\n");
16293 if (ent == (bfd_vma) -1)
16294 goto sgot_print_fail;
16295 }
16296 printf ("\n");
16297 }
16298
f17e9d8a 16299 if (data != NULL && ent < end)
bbdd9a68
MR
16300 {
16301 printf (_(" Local entries:\n"));
16302 printf (" %*s %10s %*s\n",
16303 addr_size * 2, _("Address"), _("Access"),
16304 addr_size * 2, _("Value"));
16305 while (ent < end)
16306 {
16307 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16308 printf ("\n");
16309 if (ent == (bfd_vma) -1)
16310 goto sgot_print_fail;
16311 }
16312 printf ("\n");
16313 }
16314
16315 sgot_print_fail:
16316 if (data)
16317 free (data);
16318 }
16319 return res;
16320 }
252b5132 16321
071436c6
NC
16322 for (entry = dynamic_section;
16323 /* PR 17531 file: 012-50589-0.004. */
16324 entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
16325 ++entry)
252b5132
RH
16326 switch (entry->d_tag)
16327 {
16328 case DT_MIPS_LIBLIST:
d93f0186 16329 liblist_offset
dda8d76d 16330 = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 16331 liblistno * sizeof (Elf32_External_Lib));
252b5132
RH
16332 break;
16333 case DT_MIPS_LIBLISTNO:
16334 liblistno = entry->d_un.d_val;
16335 break;
16336 case DT_MIPS_OPTIONS:
dda8d76d 16337 options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
252b5132
RH
16338 break;
16339 case DT_MIPS_CONFLICT:
d93f0186 16340 conflicts_offset
dda8d76d 16341 = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 16342 conflictsno * sizeof (Elf32_External_Conflict));
252b5132
RH
16343 break;
16344 case DT_MIPS_CONFLICTNO:
16345 conflictsno = entry->d_un.d_val;
16346 break;
ccb4c951 16347 case DT_PLTGOT:
861fb55a
DJ
16348 pltgot = entry->d_un.d_ptr;
16349 break;
ccb4c951
RS
16350 case DT_MIPS_LOCAL_GOTNO:
16351 local_gotno = entry->d_un.d_val;
16352 break;
16353 case DT_MIPS_GOTSYM:
16354 gotsym = entry->d_un.d_val;
16355 break;
16356 case DT_MIPS_SYMTABNO:
16357 symtabno = entry->d_un.d_val;
16358 break;
861fb55a
DJ
16359 case DT_MIPS_PLTGOT:
16360 mips_pltgot = entry->d_un.d_ptr;
16361 break;
16362 case DT_PLTREL:
16363 pltrel = entry->d_un.d_val;
16364 break;
16365 case DT_PLTRELSZ:
16366 pltrelsz = entry->d_un.d_val;
16367 break;
16368 case DT_JMPREL:
16369 jmprel = entry->d_un.d_ptr;
16370 break;
252b5132
RH
16371 default:
16372 break;
16373 }
16374
16375 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
16376 {
2cf0635d 16377 Elf32_External_Lib * elib;
252b5132
RH
16378 size_t cnt;
16379
dda8d76d 16380 elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset,
3f5e193b
NC
16381 liblistno,
16382 sizeof (Elf32_External_Lib),
9cf03b7e 16383 _("liblist section data"));
a6e9f9df 16384 if (elib)
252b5132 16385 {
d3a49aa8
AM
16386 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
16387 "\nSection '.liblist' contains %lu entries:\n",
16388 (unsigned long) liblistno),
a6e9f9df 16389 (unsigned long) liblistno);
2b692964 16390 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
a6e9f9df
AM
16391 stdout);
16392
16393 for (cnt = 0; cnt < liblistno; ++cnt)
252b5132 16394 {
a6e9f9df 16395 Elf32_Lib liblist;
91d6fa6a 16396 time_t atime;
d5b07ef4 16397 char timebuf[128];
2cf0635d 16398 struct tm * tmp;
a6e9f9df
AM
16399
16400 liblist.l_name = BYTE_GET (elib[cnt].l_name);
91d6fa6a 16401 atime = BYTE_GET (elib[cnt].l_time_stamp);
a6e9f9df
AM
16402 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
16403 liblist.l_version = BYTE_GET (elib[cnt].l_version);
16404 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
16405
91d6fa6a 16406 tmp = gmtime (&atime);
e9e44622
JJ
16407 snprintf (timebuf, sizeof (timebuf),
16408 "%04u-%02u-%02uT%02u:%02u:%02u",
16409 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
16410 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
a6e9f9df 16411
31104126 16412 printf ("%3lu: ", (unsigned long) cnt);
d79b3d50
NC
16413 if (VALID_DYNAMIC_NAME (liblist.l_name))
16414 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
16415 else
2b692964 16416 printf (_("<corrupt: %9ld>"), liblist.l_name);
31104126
NC
16417 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
16418 liblist.l_version);
a6e9f9df
AM
16419
16420 if (liblist.l_flags == 0)
2b692964 16421 puts (_(" NONE"));
a6e9f9df
AM
16422 else
16423 {
16424 static const struct
252b5132 16425 {
2cf0635d 16426 const char * name;
a6e9f9df 16427 int bit;
252b5132 16428 }
a6e9f9df
AM
16429 l_flags_vals[] =
16430 {
16431 { " EXACT_MATCH", LL_EXACT_MATCH },
16432 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
16433 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
16434 { " EXPORTS", LL_EXPORTS },
16435 { " DELAY_LOAD", LL_DELAY_LOAD },
16436 { " DELTA", LL_DELTA }
16437 };
16438 int flags = liblist.l_flags;
16439 size_t fcnt;
16440
60bca95a 16441 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
a6e9f9df
AM
16442 if ((flags & l_flags_vals[fcnt].bit) != 0)
16443 {
16444 fputs (l_flags_vals[fcnt].name, stdout);
16445 flags ^= l_flags_vals[fcnt].bit;
16446 }
16447 if (flags != 0)
16448 printf (" %#x", (unsigned int) flags);
252b5132 16449
a6e9f9df
AM
16450 puts ("");
16451 }
252b5132 16452 }
252b5132 16453
a6e9f9df
AM
16454 free (elib);
16455 }
32ec8896
NC
16456 else
16457 res = FALSE;
252b5132
RH
16458 }
16459
16460 if (options_offset != 0)
16461 {
2cf0635d 16462 Elf_External_Options * eopt;
2cf0635d
NC
16463 Elf_Internal_Options * iopt;
16464 Elf_Internal_Options * option;
252b5132
RH
16465 size_t offset;
16466 int cnt;
dda8d76d 16467 sect = filedata->section_headers;
252b5132
RH
16468
16469 /* Find the section header so that we get the size. */
dda8d76d 16470 sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS);
948f632f 16471 /* PR 17533 file: 012-277276-0.004. */
071436c6
NC
16472 if (sect == NULL)
16473 {
16474 error (_("No MIPS_OPTIONS header found\n"));
32ec8896 16475 return FALSE;
071436c6 16476 }
7fc0c668
NC
16477 /* PR 24243 */
16478 if (sect->sh_size < sizeof (* eopt))
16479 {
16480 error (_("The MIPS options section is too small.\n"));
16481 return FALSE;
16482 }
252b5132 16483
dda8d76d 16484 eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1,
3f5e193b 16485 sect->sh_size, _("options"));
a6e9f9df 16486 if (eopt)
252b5132 16487 {
3f5e193b
NC
16488 iopt = (Elf_Internal_Options *)
16489 cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
a6e9f9df
AM
16490 if (iopt == NULL)
16491 {
fb324ee9 16492 error (_("Out of memory allocating space for MIPS options\n"));
32ec8896 16493 return FALSE;
a6e9f9df 16494 }
76da6bbe 16495
a6e9f9df
AM
16496 offset = cnt = 0;
16497 option = iopt;
252b5132 16498
82b1b41b 16499 while (offset <= sect->sh_size - sizeof (* eopt))
a6e9f9df 16500 {
2cf0635d 16501 Elf_External_Options * eoption;
252b5132 16502
a6e9f9df 16503 eoption = (Elf_External_Options *) ((char *) eopt + offset);
252b5132 16504
a6e9f9df
AM
16505 option->kind = BYTE_GET (eoption->kind);
16506 option->size = BYTE_GET (eoption->size);
16507 option->section = BYTE_GET (eoption->section);
16508 option->info = BYTE_GET (eoption->info);
76da6bbe 16509
82b1b41b
NC
16510 /* PR 17531: file: ffa0fa3b. */
16511 if (option->size < sizeof (* eopt)
16512 || offset + option->size > sect->sh_size)
16513 {
55325047 16514 error (_("Invalid size (%u) for MIPS option\n"), option->size);
32ec8896 16515 return FALSE;
82b1b41b 16516 }
a6e9f9df 16517 offset += option->size;
14ae95f2 16518
a6e9f9df
AM
16519 ++option;
16520 ++cnt;
16521 }
252b5132 16522
d3a49aa8
AM
16523 printf (ngettext ("\nSection '%s' contains %d entry:\n",
16524 "\nSection '%s' contains %d entries:\n",
16525 cnt),
dda8d76d 16526 printable_section_name (filedata, sect), cnt);
76da6bbe 16527
a6e9f9df 16528 option = iopt;
82b1b41b 16529 offset = 0;
252b5132 16530
a6e9f9df 16531 while (cnt-- > 0)
252b5132 16532 {
a6e9f9df
AM
16533 size_t len;
16534
16535 switch (option->kind)
252b5132 16536 {
a6e9f9df
AM
16537 case ODK_NULL:
16538 /* This shouldn't happen. */
16539 printf (" NULL %d %lx", option->section, option->info);
16540 break;
16541 case ODK_REGINFO:
16542 printf (" REGINFO ");
dda8d76d 16543 if (filedata->file_header.e_machine == EM_MIPS)
a6e9f9df
AM
16544 {
16545 /* 32bit form. */
2cf0635d 16546 Elf32_External_RegInfo * ereg;
b34976b6 16547 Elf32_RegInfo reginfo;
a6e9f9df
AM
16548
16549 ereg = (Elf32_External_RegInfo *) (option + 1);
16550 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
16551 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
16552 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
16553 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
16554 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
16555 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
16556
16557 printf ("GPR %08lx GP 0x%lx\n",
16558 reginfo.ri_gprmask,
16559 (unsigned long) reginfo.ri_gp_value);
16560 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16561 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
16562 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
16563 }
16564 else
16565 {
16566 /* 64 bit form. */
2cf0635d 16567 Elf64_External_RegInfo * ereg;
a6e9f9df
AM
16568 Elf64_Internal_RegInfo reginfo;
16569
16570 ereg = (Elf64_External_RegInfo *) (option + 1);
16571 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
16572 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
16573 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
16574 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
16575 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
66543521 16576 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
a6e9f9df
AM
16577
16578 printf ("GPR %08lx GP 0x",
16579 reginfo.ri_gprmask);
16580 printf_vma (reginfo.ri_gp_value);
16581 printf ("\n");
16582
16583 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16584 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
16585 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
16586 }
16587 ++option;
16588 continue;
16589 case ODK_EXCEPTIONS:
16590 fputs (" EXCEPTIONS fpe_min(", stdout);
16591 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
16592 fputs (") fpe_max(", stdout);
16593 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
16594 fputs (")", stdout);
16595
16596 if (option->info & OEX_PAGE0)
16597 fputs (" PAGE0", stdout);
16598 if (option->info & OEX_SMM)
16599 fputs (" SMM", stdout);
16600 if (option->info & OEX_FPDBUG)
16601 fputs (" FPDBUG", stdout);
16602 if (option->info & OEX_DISMISS)
16603 fputs (" DISMISS", stdout);
16604 break;
16605 case ODK_PAD:
16606 fputs (" PAD ", stdout);
16607 if (option->info & OPAD_PREFIX)
16608 fputs (" PREFIX", stdout);
16609 if (option->info & OPAD_POSTFIX)
16610 fputs (" POSTFIX", stdout);
16611 if (option->info & OPAD_SYMBOL)
16612 fputs (" SYMBOL", stdout);
16613 break;
16614 case ODK_HWPATCH:
16615 fputs (" HWPATCH ", stdout);
16616 if (option->info & OHW_R4KEOP)
16617 fputs (" R4KEOP", stdout);
16618 if (option->info & OHW_R8KPFETCH)
16619 fputs (" R8KPFETCH", stdout);
16620 if (option->info & OHW_R5KEOP)
16621 fputs (" R5KEOP", stdout);
16622 if (option->info & OHW_R5KCVTL)
16623 fputs (" R5KCVTL", stdout);
16624 break;
16625 case ODK_FILL:
16626 fputs (" FILL ", stdout);
16627 /* XXX Print content of info word? */
16628 break;
16629 case ODK_TAGS:
16630 fputs (" TAGS ", stdout);
16631 /* XXX Print content of info word? */
16632 break;
16633 case ODK_HWAND:
16634 fputs (" HWAND ", stdout);
16635 if (option->info & OHWA0_R4KEOP_CHECKED)
16636 fputs (" R4KEOP_CHECKED", stdout);
16637 if (option->info & OHWA0_R4KEOP_CLEAN)
16638 fputs (" R4KEOP_CLEAN", stdout);
16639 break;
16640 case ODK_HWOR:
16641 fputs (" HWOR ", stdout);
16642 if (option->info & OHWA0_R4KEOP_CHECKED)
16643 fputs (" R4KEOP_CHECKED", stdout);
16644 if (option->info & OHWA0_R4KEOP_CLEAN)
16645 fputs (" R4KEOP_CLEAN", stdout);
16646 break;
16647 case ODK_GP_GROUP:
16648 printf (" GP_GROUP %#06lx self-contained %#06lx",
16649 option->info & OGP_GROUP,
16650 (option->info & OGP_SELF) >> 16);
16651 break;
16652 case ODK_IDENT:
16653 printf (" IDENT %#06lx self-contained %#06lx",
16654 option->info & OGP_GROUP,
16655 (option->info & OGP_SELF) >> 16);
16656 break;
16657 default:
16658 /* This shouldn't happen. */
16659 printf (" %3d ??? %d %lx",
16660 option->kind, option->section, option->info);
16661 break;
252b5132 16662 }
a6e9f9df 16663
2cf0635d 16664 len = sizeof (* eopt);
a6e9f9df 16665 while (len < option->size)
82b1b41b 16666 {
7e27a9d5 16667 unsigned char datum = * ((unsigned char *) eopt + offset + len);
a6e9f9df 16668
82b1b41b
NC
16669 if (ISPRINT (datum))
16670 printf ("%c", datum);
16671 else
16672 printf ("\\%03o", datum);
16673 len ++;
16674 }
a6e9f9df 16675 fputs ("\n", stdout);
82b1b41b
NC
16676
16677 offset += option->size;
252b5132 16678 ++option;
252b5132
RH
16679 }
16680
a6e9f9df 16681 free (eopt);
252b5132 16682 }
32ec8896
NC
16683 else
16684 res = FALSE;
252b5132
RH
16685 }
16686
16687 if (conflicts_offset != 0 && conflictsno != 0)
16688 {
2cf0635d 16689 Elf32_Conflict * iconf;
252b5132
RH
16690 size_t cnt;
16691
16692 if (dynamic_symbols == NULL)
16693 {
591a748a 16694 error (_("conflict list found without a dynamic symbol table\n"));
32ec8896 16695 return FALSE;
252b5132
RH
16696 }
16697
7296a62a
NC
16698 /* PR 21345 - print a slightly more helpful error message
16699 if we are sure that the cmalloc will fail. */
dda8d76d 16700 if (conflictsno * sizeof (* iconf) > filedata->file_size)
7296a62a
NC
16701 {
16702 error (_("Overlarge number of conflicts detected: %lx\n"),
16703 (long) conflictsno);
16704 return FALSE;
16705 }
16706
3f5e193b 16707 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
252b5132
RH
16708 if (iconf == NULL)
16709 {
8b73c356 16710 error (_("Out of memory allocating space for dynamic conflicts\n"));
32ec8896 16711 return FALSE;
252b5132
RH
16712 }
16713
9ea033b2 16714 if (is_32bit_elf)
252b5132 16715 {
2cf0635d 16716 Elf32_External_Conflict * econf32;
a6e9f9df 16717
3f5e193b 16718 econf32 = (Elf32_External_Conflict *)
dda8d76d 16719 get_data (NULL, filedata, conflicts_offset, conflictsno,
3f5e193b 16720 sizeof (* econf32), _("conflict"));
a6e9f9df 16721 if (!econf32)
32ec8896 16722 return FALSE;
252b5132
RH
16723
16724 for (cnt = 0; cnt < conflictsno; ++cnt)
16725 iconf[cnt] = BYTE_GET (econf32[cnt]);
a6e9f9df
AM
16726
16727 free (econf32);
252b5132
RH
16728 }
16729 else
16730 {
2cf0635d 16731 Elf64_External_Conflict * econf64;
a6e9f9df 16732
3f5e193b 16733 econf64 = (Elf64_External_Conflict *)
dda8d76d 16734 get_data (NULL, filedata, conflicts_offset, conflictsno,
3f5e193b 16735 sizeof (* econf64), _("conflict"));
a6e9f9df 16736 if (!econf64)
32ec8896 16737 return FALSE;
252b5132
RH
16738
16739 for (cnt = 0; cnt < conflictsno; ++cnt)
16740 iconf[cnt] = BYTE_GET (econf64[cnt]);
a6e9f9df
AM
16741
16742 free (econf64);
252b5132
RH
16743 }
16744
d3a49aa8
AM
16745 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
16746 "\nSection '.conflict' contains %lu entries:\n",
16747 (unsigned long) conflictsno),
c7e7ca54 16748 (unsigned long) conflictsno);
252b5132
RH
16749 puts (_(" Num: Index Value Name"));
16750
16751 for (cnt = 0; cnt < conflictsno; ++cnt)
16752 {
b34976b6 16753 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
e0a31db1
NC
16754
16755 if (iconf[cnt] >= num_dynamic_syms)
16756 printf (_("<corrupt symbol index>"));
d79b3d50 16757 else
e0a31db1
NC
16758 {
16759 Elf_Internal_Sym * psym;
16760
16761 psym = & dynamic_symbols[iconf[cnt]];
16762 print_vma (psym->st_value, FULL_HEX);
16763 putchar (' ');
16764 if (VALID_DYNAMIC_NAME (psym->st_name))
16765 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
16766 else
16767 printf (_("<corrupt: %14ld>"), psym->st_name);
16768 }
31104126 16769 putchar ('\n');
252b5132
RH
16770 }
16771
252b5132
RH
16772 free (iconf);
16773 }
16774
ccb4c951
RS
16775 if (pltgot != 0 && local_gotno != 0)
16776 {
91d6fa6a 16777 bfd_vma ent, local_end, global_end;
bbeee7ea 16778 size_t i, offset;
2cf0635d 16779 unsigned char * data;
82b1b41b 16780 unsigned char * data_end;
bbeee7ea 16781 int addr_size;
ccb4c951 16782
91d6fa6a 16783 ent = pltgot;
ccb4c951
RS
16784 addr_size = (is_32bit_elf ? 4 : 8);
16785 local_end = pltgot + local_gotno * addr_size;
ccb4c951 16786
74e1a04b
NC
16787 /* PR binutils/17533 file: 012-111227-0.004 */
16788 if (symtabno < gotsym)
16789 {
16790 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
82b1b41b 16791 (unsigned long) gotsym, (unsigned long) symtabno);
32ec8896 16792 return FALSE;
74e1a04b 16793 }
82b1b41b 16794
74e1a04b 16795 global_end = local_end + (symtabno - gotsym) * addr_size;
82b1b41b
NC
16796 /* PR 17531: file: 54c91a34. */
16797 if (global_end < local_end)
16798 {
16799 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
32ec8896 16800 return FALSE;
82b1b41b 16801 }
948f632f 16802
dda8d76d
NC
16803 offset = offset_from_vma (filedata, pltgot, global_end - pltgot);
16804 data = (unsigned char *) get_data (NULL, filedata, offset,
9cf03b7e
NC
16805 global_end - pltgot, 1,
16806 _("Global Offset Table data"));
919383ac 16807 /* PR 12855: Null data is handled gracefully throughout. */
82b1b41b 16808 data_end = data + (global_end - pltgot);
59245841 16809
ccb4c951
RS
16810 printf (_("\nPrimary GOT:\n"));
16811 printf (_(" Canonical gp value: "));
16812 print_vma (pltgot + 0x7ff0, LONG_HEX);
16813 printf ("\n\n");
16814
16815 printf (_(" Reserved entries:\n"));
16816 printf (_(" %*s %10s %*s Purpose\n"),
2b692964
NC
16817 addr_size * 2, _("Address"), _("Access"),
16818 addr_size * 2, _("Initial"));
82b1b41b 16819 ent = print_mips_got_entry (data, pltgot, ent, data_end);
2b692964 16820 printf (_(" Lazy resolver\n"));
82b1b41b
NC
16821 if (ent == (bfd_vma) -1)
16822 goto got_print_fail;
75ec1fdb 16823
c4ab9505
MR
16824 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
16825 This entry will be used by some runtime loaders, to store the
16826 module pointer. Otherwise this is an ordinary local entry.
16827 PR 21344: Check for the entry being fully available before
16828 fetching it. */
16829 if (data
16830 && data + ent - pltgot + addr_size <= data_end
16831 && (byte_get (data + ent - pltgot, addr_size)
16832 >> (addr_size * 8 - 1)) != 0)
16833 {
16834 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16835 printf (_(" Module pointer (GNU extension)\n"));
16836 if (ent == (bfd_vma) -1)
16837 goto got_print_fail;
ccb4c951
RS
16838 }
16839 printf ("\n");
16840
f17e9d8a 16841 if (data != NULL && ent < local_end)
ccb4c951
RS
16842 {
16843 printf (_(" Local entries:\n"));
cc5914eb 16844 printf (" %*s %10s %*s\n",
2b692964
NC
16845 addr_size * 2, _("Address"), _("Access"),
16846 addr_size * 2, _("Initial"));
91d6fa6a 16847 while (ent < local_end)
ccb4c951 16848 {
82b1b41b 16849 ent = print_mips_got_entry (data, pltgot, ent, data_end);
ccb4c951 16850 printf ("\n");
82b1b41b
NC
16851 if (ent == (bfd_vma) -1)
16852 goto got_print_fail;
ccb4c951
RS
16853 }
16854 printf ("\n");
16855 }
16856
f17e9d8a 16857 if (data != NULL && gotsym < symtabno)
ccb4c951
RS
16858 {
16859 int sym_width;
16860
16861 printf (_(" Global entries:\n"));
cc5914eb 16862 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
9cf03b7e
NC
16863 addr_size * 2, _("Address"),
16864 _("Access"),
2b692964 16865 addr_size * 2, _("Initial"),
9cf03b7e
NC
16866 addr_size * 2, _("Sym.Val."),
16867 _("Type"),
16868 /* Note for translators: "Ndx" = abbreviated form of "Index". */
16869 _("Ndx"), _("Name"));
0b4362b0 16870
ccb4c951 16871 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
e0a31db1 16872
ccb4c951
RS
16873 for (i = gotsym; i < symtabno; i++)
16874 {
82b1b41b 16875 ent = print_mips_got_entry (data, pltgot, ent, data_end);
ccb4c951 16876 printf (" ");
e0a31db1
NC
16877
16878 if (dynamic_symbols == NULL)
16879 printf (_("<no dynamic symbols>"));
16880 else if (i < num_dynamic_syms)
16881 {
16882 Elf_Internal_Sym * psym = dynamic_symbols + i;
16883
16884 print_vma (psym->st_value, LONG_HEX);
16885 printf (" %-7s %3s ",
dda8d76d
NC
16886 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
16887 get_symbol_index_type (filedata, psym->st_shndx));
e0a31db1
NC
16888
16889 if (VALID_DYNAMIC_NAME (psym->st_name))
16890 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
16891 else
16892 printf (_("<corrupt: %14ld>"), psym->st_name);
16893 }
ccb4c951 16894 else
7fc5ac57
JBG
16895 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
16896 (unsigned long) i);
e0a31db1 16897
ccb4c951 16898 printf ("\n");
82b1b41b
NC
16899 if (ent == (bfd_vma) -1)
16900 break;
ccb4c951
RS
16901 }
16902 printf ("\n");
16903 }
16904
82b1b41b 16905 got_print_fail:
ccb4c951
RS
16906 if (data)
16907 free (data);
16908 }
16909
861fb55a
DJ
16910 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
16911 {
91d6fa6a 16912 bfd_vma ent, end;
861fb55a
DJ
16913 size_t offset, rel_offset;
16914 unsigned long count, i;
2cf0635d 16915 unsigned char * data;
861fb55a 16916 int addr_size, sym_width;
2cf0635d 16917 Elf_Internal_Rela * rels;
861fb55a 16918
dda8d76d 16919 rel_offset = offset_from_vma (filedata, jmprel, pltrelsz);
861fb55a
DJ
16920 if (pltrel == DT_RELA)
16921 {
dda8d76d 16922 if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
32ec8896 16923 return FALSE;
861fb55a
DJ
16924 }
16925 else
16926 {
dda8d76d 16927 if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
32ec8896 16928 return FALSE;
861fb55a
DJ
16929 }
16930
91d6fa6a 16931 ent = mips_pltgot;
861fb55a
DJ
16932 addr_size = (is_32bit_elf ? 4 : 8);
16933 end = mips_pltgot + (2 + count) * addr_size;
16934
dda8d76d
NC
16935 offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot);
16936 data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot,
9cf03b7e 16937 1, _("Procedure Linkage Table data"));
59245841 16938 if (data == NULL)
32ec8896 16939 return FALSE;
59245841 16940
9cf03b7e 16941 printf ("\nPLT GOT:\n\n");
861fb55a
DJ
16942 printf (_(" Reserved entries:\n"));
16943 printf (_(" %*s %*s Purpose\n"),
2b692964 16944 addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
91d6fa6a 16945 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
2b692964 16946 printf (_(" PLT lazy resolver\n"));
91d6fa6a 16947 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
2b692964 16948 printf (_(" Module pointer\n"));
861fb55a
DJ
16949 printf ("\n");
16950
16951 printf (_(" Entries:\n"));
cc5914eb 16952 printf (" %*s %*s %*s %-7s %3s %s\n",
2b692964
NC
16953 addr_size * 2, _("Address"),
16954 addr_size * 2, _("Initial"),
16955 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
861fb55a
DJ
16956 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
16957 for (i = 0; i < count; i++)
16958 {
df97ab2a 16959 unsigned long idx = get_reloc_symindex (rels[i].r_info);
861fb55a 16960
91d6fa6a 16961 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
861fb55a 16962 printf (" ");
e0a31db1 16963
df97ab2a
MF
16964 if (idx >= num_dynamic_syms)
16965 printf (_("<corrupt symbol index: %lu>"), idx);
861fb55a 16966 else
e0a31db1 16967 {
df97ab2a 16968 Elf_Internal_Sym * psym = dynamic_symbols + idx;
e0a31db1
NC
16969
16970 print_vma (psym->st_value, LONG_HEX);
16971 printf (" %-7s %3s ",
dda8d76d
NC
16972 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
16973 get_symbol_index_type (filedata, psym->st_shndx));
e0a31db1
NC
16974 if (VALID_DYNAMIC_NAME (psym->st_name))
16975 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
16976 else
16977 printf (_("<corrupt: %14ld>"), psym->st_name);
16978 }
861fb55a
DJ
16979 printf ("\n");
16980 }
16981 printf ("\n");
16982
16983 if (data)
16984 free (data);
16985 free (rels);
16986 }
16987
32ec8896 16988 return res;
252b5132
RH
16989}
16990
32ec8896 16991static bfd_boolean
dda8d76d 16992process_nds32_specific (Filedata * filedata)
35c08157
KLC
16993{
16994 Elf_Internal_Shdr *sect = NULL;
16995
dda8d76d 16996 sect = find_section (filedata, ".nds32_e_flags");
35c08157
KLC
16997 if (sect != NULL)
16998 {
16999 unsigned int *flag;
17000
17001 printf ("\nNDS32 elf flags section:\n");
dda8d76d 17002 flag = get_data (NULL, filedata, sect->sh_offset, 1,
35c08157
KLC
17003 sect->sh_size, _("NDS32 elf flags section"));
17004
32ec8896
NC
17005 if (! flag)
17006 return FALSE;
17007
35c08157
KLC
17008 switch ((*flag) & 0x3)
17009 {
17010 case 0:
17011 printf ("(VEC_SIZE):\tNo entry.\n");
17012 break;
17013 case 1:
17014 printf ("(VEC_SIZE):\t4 bytes\n");
17015 break;
17016 case 2:
17017 printf ("(VEC_SIZE):\t16 bytes\n");
17018 break;
17019 case 3:
17020 printf ("(VEC_SIZE):\treserved\n");
17021 break;
17022 }
17023 }
17024
17025 return TRUE;
17026}
17027
32ec8896 17028static bfd_boolean
dda8d76d 17029process_gnu_liblist (Filedata * filedata)
047b2264 17030{
2cf0635d
NC
17031 Elf_Internal_Shdr * section;
17032 Elf_Internal_Shdr * string_sec;
17033 Elf32_External_Lib * elib;
17034 char * strtab;
c256ffe7 17035 size_t strtab_size;
047b2264 17036 size_t cnt;
d3a49aa8 17037 unsigned long num_liblist;
047b2264 17038 unsigned i;
32ec8896 17039 bfd_boolean res = TRUE;
047b2264
JJ
17040
17041 if (! do_arch)
32ec8896 17042 return TRUE;
047b2264 17043
dda8d76d
NC
17044 for (i = 0, section = filedata->section_headers;
17045 i < filedata->file_header.e_shnum;
b34976b6 17046 i++, section++)
047b2264
JJ
17047 {
17048 switch (section->sh_type)
17049 {
17050 case SHT_GNU_LIBLIST:
dda8d76d 17051 if (section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
17052 break;
17053
3f5e193b 17054 elib = (Elf32_External_Lib *)
dda8d76d 17055 get_data (NULL, filedata, section->sh_offset, 1, section->sh_size,
9cf03b7e 17056 _("liblist section data"));
047b2264
JJ
17057
17058 if (elib == NULL)
32ec8896
NC
17059 {
17060 res = FALSE;
17061 break;
17062 }
047b2264 17063
dda8d76d
NC
17064 string_sec = filedata->section_headers + section->sh_link;
17065 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
3f5e193b
NC
17066 string_sec->sh_size,
17067 _("liblist string table"));
047b2264
JJ
17068 if (strtab == NULL
17069 || section->sh_entsize != sizeof (Elf32_External_Lib))
17070 {
17071 free (elib);
2842702f 17072 free (strtab);
32ec8896 17073 res = FALSE;
047b2264
JJ
17074 break;
17075 }
59245841 17076 strtab_size = string_sec->sh_size;
047b2264 17077
d3a49aa8
AM
17078 num_liblist = section->sh_size / sizeof (Elf32_External_Lib);
17079 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
17080 "\nLibrary list section '%s' contains %lu entries:\n",
17081 num_liblist),
dda8d76d 17082 printable_section_name (filedata, section),
d3a49aa8 17083 num_liblist);
047b2264 17084
2b692964 17085 puts (_(" Library Time Stamp Checksum Version Flags"));
047b2264
JJ
17086
17087 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
17088 ++cnt)
17089 {
17090 Elf32_Lib liblist;
91d6fa6a 17091 time_t atime;
d5b07ef4 17092 char timebuf[128];
2cf0635d 17093 struct tm * tmp;
047b2264
JJ
17094
17095 liblist.l_name = BYTE_GET (elib[cnt].l_name);
91d6fa6a 17096 atime = BYTE_GET (elib[cnt].l_time_stamp);
047b2264
JJ
17097 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
17098 liblist.l_version = BYTE_GET (elib[cnt].l_version);
17099 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
17100
91d6fa6a 17101 tmp = gmtime (&atime);
e9e44622
JJ
17102 snprintf (timebuf, sizeof (timebuf),
17103 "%04u-%02u-%02uT%02u:%02u:%02u",
17104 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
17105 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
047b2264
JJ
17106
17107 printf ("%3lu: ", (unsigned long) cnt);
17108 if (do_wide)
c256ffe7 17109 printf ("%-20s", liblist.l_name < strtab_size
2b692964 17110 ? strtab + liblist.l_name : _("<corrupt>"));
047b2264 17111 else
c256ffe7 17112 printf ("%-20.20s", liblist.l_name < strtab_size
2b692964 17113 ? strtab + liblist.l_name : _("<corrupt>"));
047b2264
JJ
17114 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
17115 liblist.l_version, liblist.l_flags);
17116 }
17117
17118 free (elib);
2842702f 17119 free (strtab);
047b2264
JJ
17120 }
17121 }
17122
32ec8896 17123 return res;
047b2264
JJ
17124}
17125
9437c45b 17126static const char *
dda8d76d 17127get_note_type (Filedata * filedata, unsigned e_type)
779fe533
NC
17128{
17129 static char buff[64];
103f02d3 17130
dda8d76d 17131 if (filedata->file_header.e_type == ET_CORE)
1ec5cd37
NC
17132 switch (e_type)
17133 {
57346661 17134 case NT_AUXV:
1ec5cd37 17135 return _("NT_AUXV (auxiliary vector)");
57346661 17136 case NT_PRSTATUS:
1ec5cd37 17137 return _("NT_PRSTATUS (prstatus structure)");
57346661 17138 case NT_FPREGSET:
1ec5cd37 17139 return _("NT_FPREGSET (floating point registers)");
57346661 17140 case NT_PRPSINFO:
1ec5cd37 17141 return _("NT_PRPSINFO (prpsinfo structure)");
57346661 17142 case NT_TASKSTRUCT:
1ec5cd37 17143 return _("NT_TASKSTRUCT (task structure)");
57346661 17144 case NT_PRXFPREG:
1ec5cd37 17145 return _("NT_PRXFPREG (user_xfpregs structure)");
e1e95dec
AM
17146 case NT_PPC_VMX:
17147 return _("NT_PPC_VMX (ppc Altivec registers)");
89eeb0bc
LM
17148 case NT_PPC_VSX:
17149 return _("NT_PPC_VSX (ppc VSX registers)");
66c3b5f8
GR
17150 case NT_PPC_TAR:
17151 return _("NT_PPC_TAR (ppc TAR register)");
17152 case NT_PPC_PPR:
17153 return _("NT_PPC_PPR (ppc PPR register)");
17154 case NT_PPC_DSCR:
17155 return _("NT_PPC_DSCR (ppc DSCR register)");
17156 case NT_PPC_EBB:
17157 return _("NT_PPC_EBB (ppc EBB registers)");
17158 case NT_PPC_PMU:
17159 return _("NT_PPC_PMU (ppc PMU registers)");
17160 case NT_PPC_TM_CGPR:
17161 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
17162 case NT_PPC_TM_CFPR:
17163 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
17164 case NT_PPC_TM_CVMX:
17165 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
17166 case NT_PPC_TM_CVSX:
3fd21718 17167 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
66c3b5f8
GR
17168 case NT_PPC_TM_SPR:
17169 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
17170 case NT_PPC_TM_CTAR:
17171 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
17172 case NT_PPC_TM_CPPR:
17173 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
17174 case NT_PPC_TM_CDSCR:
17175 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
ff826ef3
TT
17176 case NT_386_TLS:
17177 return _("NT_386_TLS (x86 TLS information)");
17178 case NT_386_IOPERM:
17179 return _("NT_386_IOPERM (x86 I/O permissions)");
4339cae0
L
17180 case NT_X86_XSTATE:
17181 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
0675e188
UW
17182 case NT_S390_HIGH_GPRS:
17183 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
d7eeb400
MS
17184 case NT_S390_TIMER:
17185 return _("NT_S390_TIMER (s390 timer register)");
17186 case NT_S390_TODCMP:
17187 return _("NT_S390_TODCMP (s390 TOD comparator register)");
17188 case NT_S390_TODPREG:
17189 return _("NT_S390_TODPREG (s390 TOD programmable register)");
17190 case NT_S390_CTRS:
17191 return _("NT_S390_CTRS (s390 control registers)");
17192 case NT_S390_PREFIX:
17193 return _("NT_S390_PREFIX (s390 prefix register)");
a367d729
AK
17194 case NT_S390_LAST_BREAK:
17195 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
17196 case NT_S390_SYSTEM_CALL:
17197 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
abb3f6cc
NC
17198 case NT_S390_TDB:
17199 return _("NT_S390_TDB (s390 transaction diagnostic block)");
4ef9f41a
AA
17200 case NT_S390_VXRS_LOW:
17201 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
17202 case NT_S390_VXRS_HIGH:
17203 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
88ab90e8
AA
17204 case NT_S390_GS_CB:
17205 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
17206 case NT_S390_GS_BC:
17207 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
faa9a424
UW
17208 case NT_ARM_VFP:
17209 return _("NT_ARM_VFP (arm VFP registers)");
652451f8
YZ
17210 case NT_ARM_TLS:
17211 return _("NT_ARM_TLS (AArch TLS registers)");
17212 case NT_ARM_HW_BREAK:
17213 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
17214 case NT_ARM_HW_WATCH:
17215 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
57346661 17216 case NT_PSTATUS:
1ec5cd37 17217 return _("NT_PSTATUS (pstatus structure)");
57346661 17218 case NT_FPREGS:
1ec5cd37 17219 return _("NT_FPREGS (floating point registers)");
57346661 17220 case NT_PSINFO:
1ec5cd37 17221 return _("NT_PSINFO (psinfo structure)");
57346661 17222 case NT_LWPSTATUS:
1ec5cd37 17223 return _("NT_LWPSTATUS (lwpstatus_t structure)");
57346661 17224 case NT_LWPSINFO:
1ec5cd37 17225 return _("NT_LWPSINFO (lwpsinfo_t structure)");
57346661 17226 case NT_WIN32PSTATUS:
1ec5cd37 17227 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9ece1fa9
TT
17228 case NT_SIGINFO:
17229 return _("NT_SIGINFO (siginfo_t data)");
17230 case NT_FILE:
17231 return _("NT_FILE (mapped files)");
1ec5cd37
NC
17232 default:
17233 break;
17234 }
17235 else
17236 switch (e_type)
17237 {
17238 case NT_VERSION:
17239 return _("NT_VERSION (version)");
17240 case NT_ARCH:
17241 return _("NT_ARCH (architecture)");
9ef920e9 17242 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
6f156d7a 17243 return _("OPEN");
9ef920e9 17244 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
6f156d7a 17245 return _("func");
1ec5cd37
NC
17246 default:
17247 break;
17248 }
17249
e9e44622 17250 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
1ec5cd37 17251 return buff;
779fe533
NC
17252}
17253
32ec8896 17254static bfd_boolean
9ece1fa9
TT
17255print_core_note (Elf_Internal_Note *pnote)
17256{
17257 unsigned int addr_size = is_32bit_elf ? 4 : 8;
17258 bfd_vma count, page_size;
17259 unsigned char *descdata, *filenames, *descend;
17260
17261 if (pnote->type != NT_FILE)
04ac15ab
AS
17262 {
17263 if (do_wide)
17264 printf ("\n");
17265 return TRUE;
17266 }
9ece1fa9
TT
17267
17268#ifndef BFD64
17269 if (!is_32bit_elf)
17270 {
17271 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
17272 /* Still "successful". */
32ec8896 17273 return TRUE;
9ece1fa9
TT
17274 }
17275#endif
17276
17277 if (pnote->descsz < 2 * addr_size)
17278 {
32ec8896
NC
17279 error (_(" Malformed note - too short for header\n"));
17280 return FALSE;
9ece1fa9
TT
17281 }
17282
17283 descdata = (unsigned char *) pnote->descdata;
17284 descend = descdata + pnote->descsz;
17285
17286 if (descdata[pnote->descsz - 1] != '\0')
17287 {
32ec8896
NC
17288 error (_(" Malformed note - does not end with \\0\n"));
17289 return FALSE;
9ece1fa9
TT
17290 }
17291
17292 count = byte_get (descdata, addr_size);
17293 descdata += addr_size;
17294
17295 page_size = byte_get (descdata, addr_size);
17296 descdata += addr_size;
17297
5396a86e
AM
17298 if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size)
17299 || pnote->descsz < 2 * addr_size + count * 3 * addr_size)
9ece1fa9 17300 {
32ec8896
NC
17301 error (_(" Malformed note - too short for supplied file count\n"));
17302 return FALSE;
9ece1fa9
TT
17303 }
17304
17305 printf (_(" Page size: "));
17306 print_vma (page_size, DEC);
17307 printf ("\n");
17308
17309 printf (_(" %*s%*s%*s\n"),
17310 (int) (2 + 2 * addr_size), _("Start"),
17311 (int) (4 + 2 * addr_size), _("End"),
17312 (int) (4 + 2 * addr_size), _("Page Offset"));
17313 filenames = descdata + count * 3 * addr_size;
595712bb 17314 while (count-- > 0)
9ece1fa9
TT
17315 {
17316 bfd_vma start, end, file_ofs;
17317
17318 if (filenames == descend)
17319 {
32ec8896
NC
17320 error (_(" Malformed note - filenames end too early\n"));
17321 return FALSE;
9ece1fa9
TT
17322 }
17323
17324 start = byte_get (descdata, addr_size);
17325 descdata += addr_size;
17326 end = byte_get (descdata, addr_size);
17327 descdata += addr_size;
17328 file_ofs = byte_get (descdata, addr_size);
17329 descdata += addr_size;
17330
17331 printf (" ");
17332 print_vma (start, FULL_HEX);
17333 printf (" ");
17334 print_vma (end, FULL_HEX);
17335 printf (" ");
17336 print_vma (file_ofs, FULL_HEX);
17337 printf ("\n %s\n", filenames);
17338
17339 filenames += 1 + strlen ((char *) filenames);
17340 }
17341
32ec8896 17342 return TRUE;
9ece1fa9
TT
17343}
17344
1118d252
RM
17345static const char *
17346get_gnu_elf_note_type (unsigned e_type)
17347{
1449284b 17348 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
1118d252
RM
17349 switch (e_type)
17350 {
17351 case NT_GNU_ABI_TAG:
17352 return _("NT_GNU_ABI_TAG (ABI version tag)");
17353 case NT_GNU_HWCAP:
17354 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
17355 case NT_GNU_BUILD_ID:
17356 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
0297aed6
DM
17357 case NT_GNU_GOLD_VERSION:
17358 return _("NT_GNU_GOLD_VERSION (gold version)");
9ef920e9
NC
17359 case NT_GNU_PROPERTY_TYPE_0:
17360 return _("NT_GNU_PROPERTY_TYPE_0");
17361 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
17362 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
17363 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
17364 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
1118d252 17365 default:
1449284b
NC
17366 {
17367 static char buff[64];
1118d252 17368
1449284b
NC
17369 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17370 return buff;
17371 }
17372 }
1118d252
RM
17373}
17374
a9eafb08
L
17375static void
17376decode_x86_compat_isa (unsigned int bitmask)
17377{
17378 while (bitmask)
17379 {
17380 unsigned int bit = bitmask & (- bitmask);
17381
17382 bitmask &= ~ bit;
17383 switch (bit)
17384 {
17385 case GNU_PROPERTY_X86_COMPAT_ISA_1_486:
17386 printf ("i486");
17387 break;
17388 case GNU_PROPERTY_X86_COMPAT_ISA_1_586:
17389 printf ("586");
17390 break;
17391 case GNU_PROPERTY_X86_COMPAT_ISA_1_686:
17392 printf ("686");
17393 break;
17394 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE:
17395 printf ("SSE");
17396 break;
17397 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2:
17398 printf ("SSE2");
17399 break;
17400 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3:
17401 printf ("SSE3");
17402 break;
17403 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3:
17404 printf ("SSSE3");
17405 break;
17406 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1:
17407 printf ("SSE4_1");
17408 break;
17409 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2:
17410 printf ("SSE4_2");
17411 break;
17412 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX:
17413 printf ("AVX");
17414 break;
17415 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2:
17416 printf ("AVX2");
17417 break;
17418 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F:
17419 printf ("AVX512F");
17420 break;
17421 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD:
17422 printf ("AVX512CD");
17423 break;
17424 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER:
17425 printf ("AVX512ER");
17426 break;
17427 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF:
17428 printf ("AVX512PF");
17429 break;
17430 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL:
17431 printf ("AVX512VL");
17432 break;
17433 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ:
17434 printf ("AVX512DQ");
17435 break;
17436 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW:
17437 printf ("AVX512BW");
17438 break;
65b3d26e
L
17439 default:
17440 printf (_("<unknown: %x>"), bit);
17441 break;
a9eafb08
L
17442 }
17443 if (bitmask)
17444 printf (", ");
17445 }
17446}
17447
9ef920e9 17448static void
1fc87489 17449decode_x86_isa (unsigned int bitmask)
9ef920e9 17450{
0a59decb 17451 if (!bitmask)
90c745dc
L
17452 {
17453 printf (_("<None>"));
17454 return;
17455 }
90c745dc 17456
9ef920e9
NC
17457 while (bitmask)
17458 {
1fc87489 17459 unsigned int bit = bitmask & (- bitmask);
9ef920e9
NC
17460
17461 bitmask &= ~ bit;
17462 switch (bit)
17463 {
a9eafb08
L
17464 case GNU_PROPERTY_X86_ISA_1_CMOV:
17465 printf ("CMOV");
17466 break;
17467 case GNU_PROPERTY_X86_ISA_1_SSE:
17468 printf ("SSE");
17469 break;
17470 case GNU_PROPERTY_X86_ISA_1_SSE2:
17471 printf ("SSE2");
17472 break;
17473 case GNU_PROPERTY_X86_ISA_1_SSE3:
17474 printf ("SSE3");
17475 break;
17476 case GNU_PROPERTY_X86_ISA_1_SSSE3:
17477 printf ("SSSE3");
17478 break;
17479 case GNU_PROPERTY_X86_ISA_1_SSE4_1:
17480 printf ("SSE4_1");
17481 break;
17482 case GNU_PROPERTY_X86_ISA_1_SSE4_2:
17483 printf ("SSE4_2");
17484 break;
17485 case GNU_PROPERTY_X86_ISA_1_AVX:
17486 printf ("AVX");
17487 break;
17488 case GNU_PROPERTY_X86_ISA_1_AVX2:
17489 printf ("AVX2");
17490 break;
17491 case GNU_PROPERTY_X86_ISA_1_FMA:
17492 printf ("FMA");
17493 break;
17494 case GNU_PROPERTY_X86_ISA_1_AVX512F:
17495 printf ("AVX512F");
17496 break;
17497 case GNU_PROPERTY_X86_ISA_1_AVX512CD:
17498 printf ("AVX512CD");
17499 break;
17500 case GNU_PROPERTY_X86_ISA_1_AVX512ER:
17501 printf ("AVX512ER");
17502 break;
17503 case GNU_PROPERTY_X86_ISA_1_AVX512PF:
17504 printf ("AVX512PF");
17505 break;
17506 case GNU_PROPERTY_X86_ISA_1_AVX512VL:
17507 printf ("AVX512VL");
17508 break;
17509 case GNU_PROPERTY_X86_ISA_1_AVX512DQ:
17510 printf ("AVX512DQ");
17511 break;
17512 case GNU_PROPERTY_X86_ISA_1_AVX512BW:
17513 printf ("AVX512BW");
17514 break;
17515 case GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS:
17516 printf ("AVX512_4FMAPS");
17517 break;
17518 case GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW:
17519 printf ("AVX512_4VNNIW");
17520 break;
17521 case GNU_PROPERTY_X86_ISA_1_AVX512_BITALG:
17522 printf ("AVX512_BITALG");
17523 break;
17524 case GNU_PROPERTY_X86_ISA_1_AVX512_IFMA:
17525 printf ("AVX512_IFMA");
17526 break;
17527 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI:
17528 printf ("AVX512_VBMI");
17529 break;
17530 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2:
17531 printf ("AVX512_VBMI2");
17532 break;
17533 case GNU_PROPERTY_X86_ISA_1_AVX512_VNNI:
17534 printf ("AVX512_VNNI");
17535 break;
462cac58
L
17536 case GNU_PROPERTY_X86_ISA_1_AVX512_BF16:
17537 printf ("AVX512_BF16");
17538 break;
65b3d26e
L
17539 default:
17540 printf (_("<unknown: %x>"), bit);
17541 break;
9ef920e9
NC
17542 }
17543 if (bitmask)
17544 printf (", ");
17545 }
17546}
17547
ee2fdd6f 17548static void
a9eafb08 17549decode_x86_feature_1 (unsigned int bitmask)
ee2fdd6f 17550{
0a59decb 17551 if (!bitmask)
90c745dc
L
17552 {
17553 printf (_("<None>"));
17554 return;
17555 }
90c745dc 17556
ee2fdd6f
L
17557 while (bitmask)
17558 {
17559 unsigned int bit = bitmask & (- bitmask);
17560
17561 bitmask &= ~ bit;
17562 switch (bit)
17563 {
17564 case GNU_PROPERTY_X86_FEATURE_1_IBT:
a9eafb08 17565 printf ("IBT");
ee2fdd6f 17566 break;
48580982 17567 case GNU_PROPERTY_X86_FEATURE_1_SHSTK:
a9eafb08 17568 printf ("SHSTK");
48580982 17569 break;
ee2fdd6f
L
17570 default:
17571 printf (_("<unknown: %x>"), bit);
17572 break;
17573 }
17574 if (bitmask)
17575 printf (", ");
17576 }
17577}
17578
a9eafb08
L
17579static void
17580decode_x86_feature_2 (unsigned int bitmask)
17581{
0a59decb 17582 if (!bitmask)
90c745dc
L
17583 {
17584 printf (_("<None>"));
17585 return;
17586 }
90c745dc 17587
a9eafb08
L
17588 while (bitmask)
17589 {
17590 unsigned int bit = bitmask & (- bitmask);
17591
17592 bitmask &= ~ bit;
17593 switch (bit)
17594 {
17595 case GNU_PROPERTY_X86_FEATURE_2_X86:
17596 printf ("x86");
17597 break;
17598 case GNU_PROPERTY_X86_FEATURE_2_X87:
17599 printf ("x87");
17600 break;
17601 case GNU_PROPERTY_X86_FEATURE_2_MMX:
17602 printf ("MMX");
17603 break;
17604 case GNU_PROPERTY_X86_FEATURE_2_XMM:
17605 printf ("XMM");
17606 break;
17607 case GNU_PROPERTY_X86_FEATURE_2_YMM:
17608 printf ("YMM");
17609 break;
17610 case GNU_PROPERTY_X86_FEATURE_2_ZMM:
17611 printf ("ZMM");
17612 break;
17613 case GNU_PROPERTY_X86_FEATURE_2_FXSR:
17614 printf ("FXSR");
17615 break;
17616 case GNU_PROPERTY_X86_FEATURE_2_XSAVE:
17617 printf ("XSAVE");
17618 break;
17619 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT:
17620 printf ("XSAVEOPT");
17621 break;
17622 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC:
17623 printf ("XSAVEC");
17624 break;
65b3d26e
L
17625 default:
17626 printf (_("<unknown: %x>"), bit);
17627 break;
a9eafb08
L
17628 }
17629 if (bitmask)
17630 printf (", ");
17631 }
17632}
17633
cd702818
SD
17634static void
17635decode_aarch64_feature_1_and (unsigned int bitmask)
17636{
17637 while (bitmask)
17638 {
17639 unsigned int bit = bitmask & (- bitmask);
17640
17641 bitmask &= ~ bit;
17642 switch (bit)
17643 {
17644 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI:
17645 printf ("BTI");
17646 break;
17647
17648 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC:
17649 printf ("PAC");
17650 break;
17651
17652 default:
17653 printf (_("<unknown: %x>"), bit);
17654 break;
17655 }
17656 if (bitmask)
17657 printf (", ");
17658 }
17659}
17660
9ef920e9 17661static void
dda8d76d 17662print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
9ef920e9
NC
17663{
17664 unsigned char * ptr = (unsigned char *) pnote->descdata;
17665 unsigned char * ptr_end = ptr + pnote->descsz;
17666 unsigned int size = is_32bit_elf ? 4 : 8;
17667
17668 printf (_(" Properties: "));
17669
1fc87489 17670 if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
9ef920e9
NC
17671 {
17672 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
17673 return;
17674 }
17675
6ab2c4ed 17676 while (ptr < ptr_end)
9ef920e9 17677 {
1fc87489 17678 unsigned int j;
6ab2c4ed
MC
17679 unsigned int type;
17680 unsigned int datasz;
17681
17682 if ((size_t) (ptr_end - ptr) < 8)
17683 {
17684 printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
17685 break;
17686 }
17687
17688 type = byte_get (ptr, 4);
17689 datasz = byte_get (ptr + 4, 4);
9ef920e9 17690
1fc87489 17691 ptr += 8;
9ef920e9 17692
6ab2c4ed 17693 if (datasz > (size_t) (ptr_end - ptr))
9ef920e9 17694 {
1fc87489
L
17695 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
17696 type, datasz);
9ef920e9 17697 break;
1fc87489 17698 }
9ef920e9 17699
1fc87489
L
17700 if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
17701 {
dda8d76d
NC
17702 if (filedata->file_header.e_machine == EM_X86_64
17703 || filedata->file_header.e_machine == EM_IAMCU
17704 || filedata->file_header.e_machine == EM_386)
1fc87489 17705 {
aa7bca9b
L
17706 unsigned int bitmask;
17707
17708 if (datasz == 4)
0a59decb 17709 bitmask = byte_get (ptr, 4);
aa7bca9b
L
17710 else
17711 bitmask = 0;
17712
1fc87489
L
17713 switch (type)
17714 {
17715 case GNU_PROPERTY_X86_ISA_1_USED:
1fc87489 17716 if (datasz != 4)
aa7bca9b
L
17717 printf (_("x86 ISA used: <corrupt length: %#x> "),
17718 datasz);
1fc87489 17719 else
aa7bca9b
L
17720 {
17721 printf ("x86 ISA used: ");
17722 decode_x86_isa (bitmask);
17723 }
1fc87489 17724 goto next;
9ef920e9 17725
1fc87489 17726 case GNU_PROPERTY_X86_ISA_1_NEEDED:
1fc87489 17727 if (datasz != 4)
aa7bca9b
L
17728 printf (_("x86 ISA needed: <corrupt length: %#x> "),
17729 datasz);
1fc87489 17730 else
aa7bca9b
L
17731 {
17732 printf ("x86 ISA needed: ");
17733 decode_x86_isa (bitmask);
17734 }
1fc87489 17735 goto next;
9ef920e9 17736
ee2fdd6f 17737 case GNU_PROPERTY_X86_FEATURE_1_AND:
ee2fdd6f 17738 if (datasz != 4)
aa7bca9b
L
17739 printf (_("x86 feature: <corrupt length: %#x> "),
17740 datasz);
ee2fdd6f 17741 else
aa7bca9b
L
17742 {
17743 printf ("x86 feature: ");
a9eafb08
L
17744 decode_x86_feature_1 (bitmask);
17745 }
17746 goto next;
17747
17748 case GNU_PROPERTY_X86_FEATURE_2_USED:
17749 if (datasz != 4)
17750 printf (_("x86 feature used: <corrupt length: %#x> "),
17751 datasz);
17752 else
17753 {
17754 printf ("x86 feature used: ");
17755 decode_x86_feature_2 (bitmask);
17756 }
17757 goto next;
17758
17759 case GNU_PROPERTY_X86_FEATURE_2_NEEDED:
17760 if (datasz != 4)
17761 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz);
17762 else
17763 {
17764 printf ("x86 feature needed: ");
17765 decode_x86_feature_2 (bitmask);
17766 }
17767 goto next;
17768
17769 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
17770 if (datasz != 4)
17771 printf (_("x86 ISA used: <corrupt length: %#x> "),
17772 datasz);
17773 else
17774 {
17775 printf ("x86 ISA used: ");
17776 decode_x86_compat_isa (bitmask);
17777 }
17778 goto next;
17779
17780 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
17781 if (datasz != 4)
17782 printf (_("x86 ISA needed: <corrupt length: %#x> "),
17783 datasz);
17784 else
17785 {
17786 printf ("x86 ISA needed: ");
17787 decode_x86_compat_isa (bitmask);
aa7bca9b 17788 }
ee2fdd6f
L
17789 goto next;
17790
1fc87489
L
17791 default:
17792 break;
17793 }
17794 }
cd702818
SD
17795 else if (filedata->file_header.e_machine == EM_AARCH64)
17796 {
17797 if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
17798 {
17799 printf ("AArch64 feature: ");
17800 if (datasz != 4)
17801 printf (_("<corrupt length: %#x> "), datasz);
17802 else
17803 decode_aarch64_feature_1_and (byte_get (ptr, 4));
17804 goto next;
17805 }
17806 }
1fc87489
L
17807 }
17808 else
17809 {
17810 switch (type)
9ef920e9 17811 {
1fc87489
L
17812 case GNU_PROPERTY_STACK_SIZE:
17813 printf (_("stack size: "));
17814 if (datasz != size)
17815 printf (_("<corrupt length: %#x> "), datasz);
17816 else
17817 printf ("%#lx", (unsigned long) byte_get (ptr, size));
17818 goto next;
17819
17820 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
17821 printf ("no copy on protected ");
17822 if (datasz)
17823 printf (_("<corrupt length: %#x> "), datasz);
17824 goto next;
17825
17826 default:
9ef920e9
NC
17827 break;
17828 }
9ef920e9
NC
17829 }
17830
1fc87489
L
17831 if (type < GNU_PROPERTY_LOPROC)
17832 printf (_("<unknown type %#x data: "), type);
17833 else if (type < GNU_PROPERTY_LOUSER)
17834 printf (_("<procesor-specific type %#x data: "), type);
17835 else
17836 printf (_("<application-specific type %#x data: "), type);
17837 for (j = 0; j < datasz; ++j)
17838 printf ("%02x ", ptr[j] & 0xff);
17839 printf (">");
17840
17841next:
9ef920e9 17842 ptr += ((datasz + (size - 1)) & ~ (size - 1));
1fc87489
L
17843 if (ptr == ptr_end)
17844 break;
1fc87489 17845
6ab2c4ed
MC
17846 if (do_wide)
17847 printf (", ");
17848 else
17849 printf ("\n\t");
9ef920e9
NC
17850 }
17851
17852 printf ("\n");
17853}
17854
32ec8896 17855static bfd_boolean
dda8d76d 17856print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote)
664f90a3 17857{
1449284b 17858 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
664f90a3
TT
17859 switch (pnote->type)
17860 {
17861 case NT_GNU_BUILD_ID:
17862 {
17863 unsigned long i;
17864
17865 printf (_(" Build ID: "));
17866 for (i = 0; i < pnote->descsz; ++i)
17867 printf ("%02x", pnote->descdata[i] & 0xff);
9cf03b7e 17868 printf ("\n");
664f90a3
TT
17869 }
17870 break;
17871
17872 case NT_GNU_ABI_TAG:
17873 {
17874 unsigned long os, major, minor, subminor;
17875 const char *osname;
17876
3102e897
NC
17877 /* PR 17531: file: 030-599401-0.004. */
17878 if (pnote->descsz < 16)
17879 {
17880 printf (_(" <corrupt GNU_ABI_TAG>\n"));
17881 break;
17882 }
17883
664f90a3
TT
17884 os = byte_get ((unsigned char *) pnote->descdata, 4);
17885 major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
17886 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
17887 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
17888
17889 switch (os)
17890 {
17891 case GNU_ABI_TAG_LINUX:
17892 osname = "Linux";
17893 break;
17894 case GNU_ABI_TAG_HURD:
17895 osname = "Hurd";
17896 break;
17897 case GNU_ABI_TAG_SOLARIS:
17898 osname = "Solaris";
17899 break;
17900 case GNU_ABI_TAG_FREEBSD:
17901 osname = "FreeBSD";
17902 break;
17903 case GNU_ABI_TAG_NETBSD:
17904 osname = "NetBSD";
17905 break;
14ae95f2
RM
17906 case GNU_ABI_TAG_SYLLABLE:
17907 osname = "Syllable";
17908 break;
17909 case GNU_ABI_TAG_NACL:
17910 osname = "NaCl";
17911 break;
664f90a3
TT
17912 default:
17913 osname = "Unknown";
17914 break;
17915 }
17916
17917 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
17918 major, minor, subminor);
17919 }
17920 break;
926c5385
CC
17921
17922 case NT_GNU_GOLD_VERSION:
17923 {
17924 unsigned long i;
17925
17926 printf (_(" Version: "));
17927 for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
17928 printf ("%c", pnote->descdata[i]);
17929 printf ("\n");
17930 }
17931 break;
1449284b
NC
17932
17933 case NT_GNU_HWCAP:
17934 {
17935 unsigned long num_entries, mask;
17936
17937 /* Hardware capabilities information. Word 0 is the number of entries.
17938 Word 1 is a bitmask of enabled entries. The rest of the descriptor
17939 is a series of entries, where each entry is a single byte followed
17940 by a nul terminated string. The byte gives the bit number to test
17941 if enabled in the bitmask. */
17942 printf (_(" Hardware Capabilities: "));
17943 if (pnote->descsz < 8)
17944 {
32ec8896
NC
17945 error (_("<corrupt GNU_HWCAP>\n"));
17946 return FALSE;
1449284b
NC
17947 }
17948 num_entries = byte_get ((unsigned char *) pnote->descdata, 4);
17949 mask = byte_get ((unsigned char *) pnote->descdata + 4, 4);
17950 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask);
17951 /* FIXME: Add code to display the entries... */
17952 }
17953 break;
17954
9ef920e9 17955 case NT_GNU_PROPERTY_TYPE_0:
dda8d76d 17956 print_gnu_property_note (filedata, pnote);
9ef920e9
NC
17957 break;
17958
1449284b
NC
17959 default:
17960 /* Handle unrecognised types. An error message should have already been
17961 created by get_gnu_elf_note_type(), so all that we need to do is to
17962 display the data. */
17963 {
17964 unsigned long i;
17965
17966 printf (_(" Description data: "));
17967 for (i = 0; i < pnote->descsz; ++i)
17968 printf ("%02x ", pnote->descdata[i] & 0xff);
17969 printf ("\n");
17970 }
17971 break;
664f90a3
TT
17972 }
17973
32ec8896 17974 return TRUE;
664f90a3
TT
17975}
17976
685080f2
NC
17977static const char *
17978get_v850_elf_note_type (enum v850_notes n_type)
17979{
17980 static char buff[64];
17981
17982 switch (n_type)
17983 {
17984 case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects");
17985 case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double");
17986 case V850_NOTE_FPU_INFO: return _("Type of FPU support needed");
17987 case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions");
17988 case V850_NOTE_CACHE_INFO: return _("Use of cache");
17989 case V850_NOTE_MMU_INFO: return _("Use of MMU");
17990 default:
17991 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
17992 return buff;
17993 }
17994}
17995
32ec8896 17996static bfd_boolean
685080f2
NC
17997print_v850_note (Elf_Internal_Note * pnote)
17998{
17999 unsigned int val;
18000
18001 if (pnote->descsz != 4)
32ec8896
NC
18002 return FALSE;
18003
685080f2
NC
18004 val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
18005
18006 if (val == 0)
18007 {
18008 printf (_("not set\n"));
32ec8896 18009 return TRUE;
685080f2
NC
18010 }
18011
18012 switch (pnote->type)
18013 {
18014 case V850_NOTE_ALIGNMENT:
18015 switch (val)
18016 {
32ec8896
NC
18017 case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE;
18018 case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE;
685080f2
NC
18019 }
18020 break;
14ae95f2 18021
685080f2
NC
18022 case V850_NOTE_DATA_SIZE:
18023 switch (val)
18024 {
32ec8896
NC
18025 case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE;
18026 case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE;
685080f2
NC
18027 }
18028 break;
14ae95f2 18029
685080f2
NC
18030 case V850_NOTE_FPU_INFO:
18031 switch (val)
18032 {
32ec8896
NC
18033 case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE;
18034 case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE;
685080f2
NC
18035 }
18036 break;
14ae95f2 18037
685080f2
NC
18038 case V850_NOTE_MMU_INFO:
18039 case V850_NOTE_CACHE_INFO:
18040 case V850_NOTE_SIMD_INFO:
18041 if (val == EF_RH850_SIMD)
18042 {
18043 printf (_("yes\n"));
32ec8896 18044 return TRUE;
685080f2
NC
18045 }
18046 break;
18047
18048 default:
18049 /* An 'unknown note type' message will already have been displayed. */
18050 break;
18051 }
18052
18053 printf (_("unknown value: %x\n"), val);
32ec8896 18054 return FALSE;
685080f2
NC
18055}
18056
32ec8896 18057static bfd_boolean
c6056a74
SF
18058process_netbsd_elf_note (Elf_Internal_Note * pnote)
18059{
18060 unsigned int version;
18061
18062 switch (pnote->type)
18063 {
18064 case NT_NETBSD_IDENT:
18065 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
18066 if ((version / 10000) % 100)
18067 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
18068 version, version / 100000000, (version / 1000000) % 100,
18069 (version / 10000) % 100 > 26 ? "Z" : "",
15f205b1 18070 'A' + (version / 10000) % 26);
c6056a74
SF
18071 else
18072 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
18073 version, version / 100000000, (version / 1000000) % 100,
15f205b1 18074 (version / 100) % 100);
32ec8896 18075 return TRUE;
c6056a74
SF
18076
18077 case NT_NETBSD_MARCH:
18078 printf (" NetBSD\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
18079 pnote->descdata);
32ec8896 18080 return TRUE;
c6056a74
SF
18081
18082 default:
32ec8896
NC
18083 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
18084 pnote->type);
18085 return FALSE;
c6056a74 18086 }
c6056a74
SF
18087}
18088
f4ddf30f 18089static const char *
dda8d76d 18090get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
f4ddf30f 18091{
f4ddf30f
JB
18092 switch (e_type)
18093 {
18094 case NT_FREEBSD_THRMISC:
18095 return _("NT_THRMISC (thrmisc structure)");
18096 case NT_FREEBSD_PROCSTAT_PROC:
18097 return _("NT_PROCSTAT_PROC (proc data)");
18098 case NT_FREEBSD_PROCSTAT_FILES:
18099 return _("NT_PROCSTAT_FILES (files data)");
18100 case NT_FREEBSD_PROCSTAT_VMMAP:
18101 return _("NT_PROCSTAT_VMMAP (vmmap data)");
18102 case NT_FREEBSD_PROCSTAT_GROUPS:
18103 return _("NT_PROCSTAT_GROUPS (groups data)");
18104 case NT_FREEBSD_PROCSTAT_UMASK:
18105 return _("NT_PROCSTAT_UMASK (umask data)");
18106 case NT_FREEBSD_PROCSTAT_RLIMIT:
18107 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
18108 case NT_FREEBSD_PROCSTAT_OSREL:
18109 return _("NT_PROCSTAT_OSREL (osreldate data)");
18110 case NT_FREEBSD_PROCSTAT_PSSTRINGS:
18111 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
18112 case NT_FREEBSD_PROCSTAT_AUXV:
18113 return _("NT_PROCSTAT_AUXV (auxv data)");
0b9305ed
JB
18114 case NT_FREEBSD_PTLWPINFO:
18115 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
f4ddf30f 18116 }
dda8d76d 18117 return get_note_type (filedata, e_type);
f4ddf30f
JB
18118}
18119
9437c45b 18120static const char *
dda8d76d 18121get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
9437c45b
JT
18122{
18123 static char buff[64];
18124
b4db1224 18125 if (e_type == NT_NETBSDCORE_PROCINFO)
dda8d76d 18126 return _("NetBSD procinfo structure");
9437c45b
JT
18127
18128 /* As of Jan 2002 there are no other machine-independent notes
18129 defined for NetBSD core files. If the note type is less
18130 than the start of the machine-dependent note types, we don't
18131 understand it. */
18132
b4db1224 18133 if (e_type < NT_NETBSDCORE_FIRSTMACH)
9437c45b 18134 {
e9e44622 18135 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
9437c45b
JT
18136 return buff;
18137 }
18138
dda8d76d 18139 switch (filedata->file_header.e_machine)
9437c45b
JT
18140 {
18141 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
18142 and PT_GETFPREGS == mach+2. */
18143
18144 case EM_OLD_ALPHA:
18145 case EM_ALPHA:
18146 case EM_SPARC:
18147 case EM_SPARC32PLUS:
18148 case EM_SPARCV9:
18149 switch (e_type)
18150 {
2b692964 18151 case NT_NETBSDCORE_FIRSTMACH + 0:
b4db1224 18152 return _("PT_GETREGS (reg structure)");
2b692964 18153 case NT_NETBSDCORE_FIRSTMACH + 2:
b4db1224 18154 return _("PT_GETFPREGS (fpreg structure)");
9437c45b
JT
18155 default:
18156 break;
18157 }
18158 break;
18159
18160 /* On all other arch's, PT_GETREGS == mach+1 and
18161 PT_GETFPREGS == mach+3. */
18162 default:
18163 switch (e_type)
18164 {
2b692964 18165 case NT_NETBSDCORE_FIRSTMACH + 1:
b4db1224 18166 return _("PT_GETREGS (reg structure)");
2b692964 18167 case NT_NETBSDCORE_FIRSTMACH + 3:
b4db1224 18168 return _("PT_GETFPREGS (fpreg structure)");
9437c45b
JT
18169 default:
18170 break;
18171 }
18172 }
18173
9cf03b7e 18174 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
e9e44622 18175 e_type - NT_NETBSDCORE_FIRSTMACH);
9437c45b
JT
18176 return buff;
18177}
18178
70616151
TT
18179static const char *
18180get_stapsdt_note_type (unsigned e_type)
18181{
18182 static char buff[64];
18183
18184 switch (e_type)
18185 {
18186 case NT_STAPSDT:
18187 return _("NT_STAPSDT (SystemTap probe descriptors)");
18188
18189 default:
18190 break;
18191 }
18192
18193 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18194 return buff;
18195}
18196
32ec8896 18197static bfd_boolean
c6a9fc58
TT
18198print_stapsdt_note (Elf_Internal_Note *pnote)
18199{
3ca60c57
NC
18200 size_t len, maxlen;
18201 unsigned long addr_size = is_32bit_elf ? 4 : 8;
c6a9fc58
TT
18202 char *data = pnote->descdata;
18203 char *data_end = pnote->descdata + pnote->descsz;
18204 bfd_vma pc, base_addr, semaphore;
18205 char *provider, *probe, *arg_fmt;
18206
3ca60c57
NC
18207 if (pnote->descsz < (addr_size * 3))
18208 goto stapdt_note_too_small;
18209
c6a9fc58
TT
18210 pc = byte_get ((unsigned char *) data, addr_size);
18211 data += addr_size;
3ca60c57 18212
c6a9fc58
TT
18213 base_addr = byte_get ((unsigned char *) data, addr_size);
18214 data += addr_size;
3ca60c57 18215
c6a9fc58
TT
18216 semaphore = byte_get ((unsigned char *) data, addr_size);
18217 data += addr_size;
18218
3ca60c57
NC
18219 if (data >= data_end)
18220 goto stapdt_note_too_small;
18221 maxlen = data_end - data;
18222 len = strnlen (data, maxlen);
18223 if (len < maxlen)
18224 {
18225 provider = data;
18226 data += len + 1;
18227 }
18228 else
18229 goto stapdt_note_too_small;
18230
18231 if (data >= data_end)
18232 goto stapdt_note_too_small;
18233 maxlen = data_end - data;
18234 len = strnlen (data, maxlen);
18235 if (len < maxlen)
18236 {
18237 probe = data;
18238 data += len + 1;
18239 }
18240 else
18241 goto stapdt_note_too_small;
18242
18243 if (data >= data_end)
18244 goto stapdt_note_too_small;
18245 maxlen = data_end - data;
18246 len = strnlen (data, maxlen);
18247 if (len < maxlen)
18248 {
18249 arg_fmt = data;
18250 data += len + 1;
18251 }
18252 else
18253 goto stapdt_note_too_small;
c6a9fc58
TT
18254
18255 printf (_(" Provider: %s\n"), provider);
18256 printf (_(" Name: %s\n"), probe);
18257 printf (_(" Location: "));
18258 print_vma (pc, FULL_HEX);
18259 printf (_(", Base: "));
18260 print_vma (base_addr, FULL_HEX);
18261 printf (_(", Semaphore: "));
18262 print_vma (semaphore, FULL_HEX);
9cf03b7e 18263 printf ("\n");
c6a9fc58
TT
18264 printf (_(" Arguments: %s\n"), arg_fmt);
18265
18266 return data == data_end;
3ca60c57
NC
18267
18268 stapdt_note_too_small:
18269 printf (_(" <corrupt - note is too small>\n"));
18270 error (_("corrupt stapdt note - the data size is too small\n"));
18271 return FALSE;
c6a9fc58
TT
18272}
18273
00e98fc7
TG
18274static const char *
18275get_ia64_vms_note_type (unsigned e_type)
18276{
18277 static char buff[64];
18278
18279 switch (e_type)
18280 {
18281 case NT_VMS_MHD:
18282 return _("NT_VMS_MHD (module header)");
18283 case NT_VMS_LNM:
18284 return _("NT_VMS_LNM (language name)");
18285 case NT_VMS_SRC:
18286 return _("NT_VMS_SRC (source files)");
18287 case NT_VMS_TITLE:
9cf03b7e 18288 return "NT_VMS_TITLE";
00e98fc7
TG
18289 case NT_VMS_EIDC:
18290 return _("NT_VMS_EIDC (consistency check)");
18291 case NT_VMS_FPMODE:
18292 return _("NT_VMS_FPMODE (FP mode)");
18293 case NT_VMS_LINKTIME:
9cf03b7e 18294 return "NT_VMS_LINKTIME";
00e98fc7
TG
18295 case NT_VMS_IMGNAM:
18296 return _("NT_VMS_IMGNAM (image name)");
18297 case NT_VMS_IMGID:
18298 return _("NT_VMS_IMGID (image id)");
18299 case NT_VMS_LINKID:
18300 return _("NT_VMS_LINKID (link id)");
18301 case NT_VMS_IMGBID:
18302 return _("NT_VMS_IMGBID (build id)");
18303 case NT_VMS_GSTNAM:
18304 return _("NT_VMS_GSTNAM (sym table name)");
18305 case NT_VMS_ORIG_DYN:
9cf03b7e 18306 return "NT_VMS_ORIG_DYN";
00e98fc7 18307 case NT_VMS_PATCHTIME:
9cf03b7e 18308 return "NT_VMS_PATCHTIME";
00e98fc7
TG
18309 default:
18310 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18311 return buff;
18312 }
18313}
18314
32ec8896 18315static bfd_boolean
00e98fc7
TG
18316print_ia64_vms_note (Elf_Internal_Note * pnote)
18317{
8d18bf79
NC
18318 int maxlen = pnote->descsz;
18319
18320 if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz)
18321 goto desc_size_fail;
18322
00e98fc7
TG
18323 switch (pnote->type)
18324 {
18325 case NT_VMS_MHD:
8d18bf79
NC
18326 if (maxlen <= 36)
18327 goto desc_size_fail;
18328
18329 int l = (int) strnlen (pnote->descdata + 34, maxlen - 34);
18330
18331 printf (_(" Creation date : %.17s\n"), pnote->descdata);
18332 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
18333 if (l + 34 < maxlen)
18334 {
18335 printf (_(" Module name : %s\n"), pnote->descdata + 34);
18336 if (l + 35 < maxlen)
18337 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
18338 else
18339 printf (_(" Module version : <missing>\n"));
18340 }
00e98fc7 18341 else
8d18bf79
NC
18342 {
18343 printf (_(" Module name : <missing>\n"));
18344 printf (_(" Module version : <missing>\n"));
18345 }
00e98fc7 18346 break;
8d18bf79 18347
00e98fc7 18348 case NT_VMS_LNM:
8d18bf79 18349 printf (_(" Language: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18350 break;
8d18bf79 18351
00e98fc7
TG
18352#ifdef BFD64
18353 case NT_VMS_FPMODE:
9cf03b7e 18354 printf (_(" Floating Point mode: "));
8d18bf79
NC
18355 if (maxlen < 8)
18356 goto desc_size_fail;
18357 /* FIXME: Generate an error if descsz > 8 ? */
18358
4a5cb34f 18359 printf ("0x%016" BFD_VMA_FMT "x\n",
8d18bf79 18360 (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7 18361 break;
8d18bf79 18362
00e98fc7
TG
18363 case NT_VMS_LINKTIME:
18364 printf (_(" Link time: "));
8d18bf79
NC
18365 if (maxlen < 8)
18366 goto desc_size_fail;
18367 /* FIXME: Generate an error if descsz > 8 ? */
18368
00e98fc7 18369 print_vms_time
8d18bf79 18370 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7
TG
18371 printf ("\n");
18372 break;
8d18bf79 18373
00e98fc7
TG
18374 case NT_VMS_PATCHTIME:
18375 printf (_(" Patch time: "));
8d18bf79
NC
18376 if (maxlen < 8)
18377 goto desc_size_fail;
18378 /* FIXME: Generate an error if descsz > 8 ? */
18379
00e98fc7 18380 print_vms_time
8d18bf79 18381 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7
TG
18382 printf ("\n");
18383 break;
8d18bf79 18384
00e98fc7 18385 case NT_VMS_ORIG_DYN:
8d18bf79
NC
18386 if (maxlen < 34)
18387 goto desc_size_fail;
18388
00e98fc7
TG
18389 printf (_(" Major id: %u, minor id: %u\n"),
18390 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
18391 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
9cf03b7e 18392 printf (_(" Last modified : "));
00e98fc7
TG
18393 print_vms_time
18394 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
9cf03b7e 18395 printf (_("\n Link flags : "));
4a5cb34f 18396 printf ("0x%016" BFD_VMA_FMT "x\n",
948f632f 18397 (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
00e98fc7 18398 printf (_(" Header flags: 0x%08x\n"),
948f632f 18399 (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
8d18bf79 18400 printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32);
00e98fc7
TG
18401 break;
18402#endif
8d18bf79 18403
00e98fc7 18404 case NT_VMS_IMGNAM:
8d18bf79 18405 printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18406 break;
8d18bf79 18407
00e98fc7 18408 case NT_VMS_GSTNAM:
8d18bf79 18409 printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18410 break;
8d18bf79 18411
00e98fc7 18412 case NT_VMS_IMGID:
8d18bf79 18413 printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18414 break;
8d18bf79 18415
00e98fc7 18416 case NT_VMS_LINKID:
8d18bf79 18417 printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18418 break;
8d18bf79 18419
00e98fc7 18420 default:
32ec8896 18421 return FALSE;
00e98fc7 18422 }
8d18bf79 18423
32ec8896 18424 return TRUE;
8d18bf79
NC
18425
18426 desc_size_fail:
18427 printf (_(" <corrupt - data size is too small>\n"));
18428 error (_("corrupt IA64 note: data size is too small\n"));
18429 return FALSE;
00e98fc7
TG
18430}
18431
6f156d7a
NC
18432/* Find the symbol associated with a build attribute that is attached
18433 to address OFFSET. If PNAME is non-NULL then store the name of
18434 the symbol (if found) in the provided pointer, Returns NULL if a
18435 symbol could not be found. */
c799a79d 18436
6f156d7a
NC
18437static Elf_Internal_Sym *
18438get_symbol_for_build_attribute (Filedata * filedata,
18439 unsigned long offset,
18440 bfd_boolean is_open_attr,
18441 const char ** pname)
9ef920e9 18442{
dda8d76d 18443 static Filedata * saved_filedata = NULL;
c799a79d
NC
18444 static char * strtab;
18445 static unsigned long strtablen;
18446 static Elf_Internal_Sym * symtab;
18447 static unsigned long nsyms;
7296a62a
NC
18448 Elf_Internal_Sym * saved_sym = NULL;
18449 Elf_Internal_Sym * sym;
9ef920e9 18450
dda8d76d
NC
18451 if (filedata->section_headers != NULL
18452 && (saved_filedata == NULL || filedata != saved_filedata))
9ef920e9 18453 {
c799a79d 18454 Elf_Internal_Shdr * symsec;
9ef920e9 18455
c799a79d 18456 /* Load the symbol and string sections. */
dda8d76d
NC
18457 for (symsec = filedata->section_headers;
18458 symsec < filedata->section_headers + filedata->file_header.e_shnum;
c799a79d 18459 symsec ++)
9ef920e9 18460 {
c799a79d 18461 if (symsec->sh_type == SHT_SYMTAB)
9ef920e9 18462 {
dda8d76d 18463 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
9ef920e9 18464
dda8d76d 18465 if (symsec->sh_link < filedata->file_header.e_shnum)
c799a79d 18466 {
dda8d76d 18467 Elf_Internal_Shdr * strtab_sec = filedata->section_headers + symsec->sh_link;
c799a79d 18468
dda8d76d 18469 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
c799a79d
NC
18470 1, strtab_sec->sh_size,
18471 _("string table"));
18472 strtablen = strtab != NULL ? strtab_sec->sh_size : 0;
18473 }
9ef920e9
NC
18474 }
18475 }
dda8d76d 18476 saved_filedata = filedata;
9ef920e9
NC
18477 }
18478
c799a79d 18479 if (symtab == NULL || strtab == NULL)
6f156d7a 18480 return NULL;
9ef920e9 18481
c799a79d
NC
18482 /* Find a symbol whose value matches offset. */
18483 for (sym = symtab; sym < symtab + nsyms; sym ++)
18484 if (sym->st_value == offset)
18485 {
18486 if (sym->st_name >= strtablen)
18487 /* Huh ? This should not happen. */
18488 continue;
9ef920e9 18489
c799a79d
NC
18490 if (strtab[sym->st_name] == 0)
18491 continue;
9ef920e9 18492
8fd75781
NC
18493 /* The AArch64 and ARM architectures define mapping symbols
18494 (eg $d, $x, $t) which we want to ignore. */
18495 if (strtab[sym->st_name] == '$'
18496 && strtab[sym->st_name + 1] != 0
18497 && strtab[sym->st_name + 2] == 0)
18498 continue;
18499
c799a79d
NC
18500 if (is_open_attr)
18501 {
18502 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
18503 and FILE or OBJECT symbols over NOTYPE symbols. We skip
18504 FUNC symbols entirely. */
18505 switch (ELF_ST_TYPE (sym->st_info))
18506 {
c799a79d 18507 case STT_OBJECT:
6f156d7a 18508 case STT_FILE:
c799a79d 18509 saved_sym = sym;
6f156d7a
NC
18510 if (sym->st_size)
18511 {
18512 /* If the symbol has a size associated
18513 with it then we can stop searching. */
18514 sym = symtab + nsyms;
18515 }
c799a79d 18516 continue;
9ef920e9 18517
c799a79d
NC
18518 case STT_FUNC:
18519 /* Ignore function symbols. */
18520 continue;
18521
18522 default:
18523 break;
18524 }
18525
18526 switch (ELF_ST_BIND (sym->st_info))
9ef920e9 18527 {
c799a79d
NC
18528 case STB_GLOBAL:
18529 if (saved_sym == NULL
18530 || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT)
18531 saved_sym = sym;
18532 break;
c871dade 18533
c799a79d
NC
18534 case STB_LOCAL:
18535 if (saved_sym == NULL)
18536 saved_sym = sym;
18537 break;
18538
18539 default:
9ef920e9
NC
18540 break;
18541 }
18542 }
c799a79d
NC
18543 else
18544 {
18545 if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
18546 continue;
18547
18548 saved_sym = sym;
18549 break;
18550 }
18551 }
18552
6f156d7a
NC
18553 if (saved_sym && pname)
18554 * pname = strtab + saved_sym->st_name;
18555
18556 return saved_sym;
c799a79d
NC
18557}
18558
d20e98ab
NC
18559/* Returns true iff addr1 and addr2 are in the same section. */
18560
18561static bfd_boolean
18562same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2)
18563{
18564 Elf_Internal_Shdr * a1;
18565 Elf_Internal_Shdr * a2;
18566
18567 a1 = find_section_by_address (filedata, addr1);
18568 a2 = find_section_by_address (filedata, addr2);
18569
18570 return a1 == a2 && a1 != NULL;
18571}
18572
c799a79d 18573static bfd_boolean
dda8d76d
NC
18574print_gnu_build_attribute_description (Elf_Internal_Note * pnote,
18575 Filedata * filedata)
c799a79d 18576{
6f156d7a
NC
18577 static unsigned long global_offset = 0;
18578 static unsigned long global_end = 0;
18579 static unsigned long func_offset = 0;
18580 static unsigned long func_end = 0;
c871dade 18581
6f156d7a
NC
18582 Elf_Internal_Sym * sym;
18583 const char * name;
18584 unsigned long start;
18585 unsigned long end;
18586 bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
18587
18588 switch (pnote->descsz)
c799a79d 18589 {
6f156d7a
NC
18590 case 0:
18591 /* A zero-length description means that the range of
18592 the previous note of the same type should be used. */
c799a79d 18593 if (is_open_attr)
c871dade 18594 {
6f156d7a
NC
18595 if (global_end > global_offset)
18596 printf (_(" Applies to region from %#lx to %#lx\n"),
18597 global_offset, global_end);
18598 else
18599 printf (_(" Applies to region from %#lx\n"), global_offset);
c799a79d
NC
18600 }
18601 else
18602 {
6f156d7a
NC
18603 if (func_end > func_offset)
18604 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end);
18605 else
18606 printf (_(" Applies to region from %#lx\n"), func_offset);
c871dade 18607 }
6f156d7a 18608 return TRUE;
9ef920e9 18609
6f156d7a
NC
18610 case 4:
18611 start = byte_get ((unsigned char *) pnote->descdata, 4);
18612 end = 0;
18613 break;
18614
18615 case 8:
18616 if (is_32bit_elf)
18617 {
18618 /* FIXME: We should check that version 3+ notes are being used here... */
18619 start = byte_get ((unsigned char *) pnote->descdata, 4);
18620 end = byte_get ((unsigned char *) pnote->descdata + 4, 4);
18621 }
18622 else
18623 {
18624 start = byte_get ((unsigned char *) pnote->descdata, 8);
18625 end = 0;
18626 }
18627 break;
18628
18629 case 16:
18630 start = byte_get ((unsigned char *) pnote->descdata, 8);
18631 end = byte_get ((unsigned char *) pnote->descdata + 8, 8);
18632 break;
18633
18634 default:
c799a79d
NC
18635 error (_(" <invalid description size: %lx>\n"), pnote->descsz);
18636 printf (_(" <invalid descsz>"));
18637 return FALSE;
18638 }
18639
6f156d7a
NC
18640 name = NULL;
18641 sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name);
8fd75781
NC
18642 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
18643 in order to avoid them being confused with the start address of the
18644 first function in the file... */
18645 if (sym == NULL && is_open_attr)
18646 sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr,
18647 & name);
6f156d7a
NC
18648
18649 if (end == 0 && sym != NULL && sym->st_size > 0)
18650 end = start + sym->st_size;
c799a79d
NC
18651
18652 if (is_open_attr)
18653 {
d20e98ab
NC
18654 /* FIXME: Need to properly allow for section alignment.
18655 16 is just the alignment used on x86_64. */
18656 if (global_end > 0
18657 && start > BFD_ALIGN (global_end, 16)
18658 /* Build notes are not guaranteed to be organised in order of
18659 increasing address, but we should find the all of the notes
18660 for one section in the same place. */
18661 && same_section (filedata, start, global_end))
6f156d7a
NC
18662 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
18663 global_end + 1, start - 1);
18664
18665 printf (_(" Applies to region from %#lx"), start);
18666 global_offset = start;
18667
18668 if (end)
18669 {
18670 printf (_(" to %#lx"), end);
18671 global_end = end;
18672 }
c799a79d
NC
18673 }
18674 else
18675 {
6f156d7a
NC
18676 printf (_(" Applies to region from %#lx"), start);
18677 func_offset = start;
18678
18679 if (end)
18680 {
18681 printf (_(" to %#lx"), end);
18682 func_end = end;
18683 }
c799a79d
NC
18684 }
18685
6f156d7a
NC
18686 if (sym && name)
18687 printf (_(" (%s)"), name);
18688
18689 printf ("\n");
18690 return TRUE;
9ef920e9
NC
18691}
18692
18693static bfd_boolean
18694print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
18695{
1d15e434
NC
18696 static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 };
18697 static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 };
18698 static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 };
9ef920e9
NC
18699 char name_type;
18700 char name_attribute;
1d15e434 18701 const char * expected_types;
9ef920e9
NC
18702 const char * name = pnote->namedata;
18703 const char * text;
88305e1b 18704 signed int left;
9ef920e9
NC
18705
18706 if (name == NULL || pnote->namesz < 2)
18707 {
18708 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
7296a62a 18709 print_symbol (-20, _(" <corrupt name>"));
9ef920e9
NC
18710 return FALSE;
18711 }
18712
6f156d7a
NC
18713 if (do_wide)
18714 left = 28;
18715 else
18716 left = 20;
88305e1b
NC
18717
18718 /* Version 2 of the spec adds a "GA" prefix to the name field. */
18719 if (name[0] == 'G' && name[1] == 'A')
18720 {
6f156d7a
NC
18721 if (pnote->namesz < 4)
18722 {
18723 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
18724 print_symbol (-20, _(" <corrupt name>"));
18725 return FALSE;
18726 }
18727
88305e1b
NC
18728 printf ("GA");
18729 name += 2;
18730 left -= 2;
18731 }
18732
9ef920e9
NC
18733 switch ((name_type = * name))
18734 {
18735 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
18736 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
18737 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
18738 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
18739 printf ("%c", * name);
88305e1b 18740 left --;
9ef920e9
NC
18741 break;
18742 default:
18743 error (_("unrecognised attribute type in name field: %d\n"), name_type);
18744 print_symbol (-20, _("<unknown name type>"));
18745 return FALSE;
18746 }
18747
9ef920e9
NC
18748 ++ name;
18749 text = NULL;
18750
18751 switch ((name_attribute = * name))
18752 {
18753 case GNU_BUILD_ATTRIBUTE_VERSION:
18754 text = _("<version>");
1d15e434 18755 expected_types = string_expected;
9ef920e9
NC
18756 ++ name;
18757 break;
18758 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
18759 text = _("<stack prot>");
75d7d298 18760 expected_types = "!+*";
9ef920e9
NC
18761 ++ name;
18762 break;
18763 case GNU_BUILD_ATTRIBUTE_RELRO:
18764 text = _("<relro>");
1d15e434 18765 expected_types = bool_expected;
9ef920e9
NC
18766 ++ name;
18767 break;
18768 case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
18769 text = _("<stack size>");
1d15e434 18770 expected_types = number_expected;
9ef920e9
NC
18771 ++ name;
18772 break;
18773 case GNU_BUILD_ATTRIBUTE_TOOL:
18774 text = _("<tool>");
1d15e434 18775 expected_types = string_expected;
9ef920e9
NC
18776 ++ name;
18777 break;
18778 case GNU_BUILD_ATTRIBUTE_ABI:
18779 text = _("<ABI>");
18780 expected_types = "$*";
18781 ++ name;
18782 break;
18783 case GNU_BUILD_ATTRIBUTE_PIC:
18784 text = _("<PIC>");
1d15e434 18785 expected_types = number_expected;
9ef920e9
NC
18786 ++ name;
18787 break;
a8be5506
NC
18788 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
18789 text = _("<short enum>");
1d15e434 18790 expected_types = bool_expected;
a8be5506
NC
18791 ++ name;
18792 break;
9ef920e9
NC
18793 default:
18794 if (ISPRINT (* name))
18795 {
18796 int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1;
18797
18798 if (len > left && ! do_wide)
18799 len = left;
75d7d298 18800 printf ("%.*s:", len, name);
9ef920e9 18801 left -= len;
0dd6ae21 18802 name += len;
9ef920e9
NC
18803 }
18804 else
18805 {
3e6b6445 18806 static char tmpbuf [128];
88305e1b 18807
3e6b6445
NC
18808 error (_("unrecognised byte in name field: %d\n"), * name);
18809 sprintf (tmpbuf, _("<unknown:_%d>"), * name);
18810 text = tmpbuf;
18811 name ++;
9ef920e9
NC
18812 }
18813 expected_types = "*$!+";
18814 break;
18815 }
18816
18817 if (text)
88305e1b 18818 left -= printf ("%s", text);
9ef920e9
NC
18819
18820 if (strchr (expected_types, name_type) == NULL)
75d7d298 18821 warn (_("attribute does not have an expected type (%c)\n"), name_type);
9ef920e9
NC
18822
18823 if ((unsigned long)(name - pnote->namedata) > pnote->namesz)
18824 {
18825 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
18826 (unsigned long) pnote->namesz,
18827 (long) (name - pnote->namedata));
18828 return FALSE;
18829 }
18830
18831 if (left < 1 && ! do_wide)
18832 return TRUE;
18833
18834 switch (name_type)
18835 {
18836 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
18837 {
b06b2c92 18838 unsigned int bytes;
ddef72cd
NC
18839 unsigned long long val = 0;
18840 unsigned int shift = 0;
18841 char * decoded = NULL;
18842
b06b2c92
NC
18843 bytes = pnote->namesz - (name - pnote->namedata);
18844 if (bytes > 0)
18845 /* The -1 is because the name field is always 0 terminated, and we
18846 want to be able to ensure that the shift in the while loop below
18847 will not overflow. */
18848 -- bytes;
18849
ddef72cd
NC
18850 if (bytes > sizeof (val))
18851 {
3e6b6445
NC
18852 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
18853 bytes);
18854 bytes = sizeof (val);
ddef72cd 18855 }
3e6b6445
NC
18856 /* We do not bother to warn if bytes == 0 as this can
18857 happen with some early versions of the gcc plugin. */
9ef920e9
NC
18858
18859 while (bytes --)
18860 {
79a964dc
NC
18861 unsigned long byte = (* name ++) & 0xff;
18862
18863 val |= byte << shift;
9ef920e9
NC
18864 shift += 8;
18865 }
18866
75d7d298 18867 switch (name_attribute)
9ef920e9 18868 {
75d7d298 18869 case GNU_BUILD_ATTRIBUTE_PIC:
9ef920e9
NC
18870 switch (val)
18871 {
75d7d298
NC
18872 case 0: decoded = "static"; break;
18873 case 1: decoded = "pic"; break;
18874 case 2: decoded = "PIC"; break;
18875 case 3: decoded = "pie"; break;
18876 case 4: decoded = "PIE"; break;
18877 default: break;
9ef920e9 18878 }
75d7d298
NC
18879 break;
18880 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
18881 switch (val)
9ef920e9 18882 {
75d7d298
NC
18883 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
18884 case 0: decoded = "off"; break;
18885 case 1: decoded = "on"; break;
18886 case 2: decoded = "all"; break;
18887 case 3: decoded = "strong"; break;
18888 case 4: decoded = "explicit"; break;
18889 default: break;
9ef920e9 18890 }
75d7d298
NC
18891 break;
18892 default:
18893 break;
9ef920e9
NC
18894 }
18895
75d7d298 18896 if (decoded != NULL)
3e6b6445
NC
18897 {
18898 print_symbol (-left, decoded);
18899 left = 0;
18900 }
18901 else if (val == 0)
18902 {
18903 printf ("0x0");
18904 left -= 3;
18905 }
9ef920e9 18906 else
75d7d298
NC
18907 {
18908 if (do_wide)
ddef72cd 18909 left -= printf ("0x%llx", val);
75d7d298 18910 else
ddef72cd 18911 left -= printf ("0x%-.*llx", left, val);
75d7d298 18912 }
9ef920e9
NC
18913 }
18914 break;
18915 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
18916 left -= print_symbol (- left, name);
18917 break;
18918 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
18919 left -= print_symbol (- left, "true");
18920 break;
18921 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
18922 left -= print_symbol (- left, "false");
18923 break;
18924 }
18925
18926 if (do_wide && left > 0)
18927 printf ("%-*s", left, " ");
18928
18929 return TRUE;
18930}
18931
6d118b09
NC
18932/* Note that by the ELF standard, the name field is already null byte
18933 terminated, and namesz includes the terminating null byte.
18934 I.E. the value of namesz for the name "FSF" is 4.
18935
e3c8793a 18936 If the value of namesz is zero, there is no name present. */
9ef920e9 18937
32ec8896 18938static bfd_boolean
9ef920e9 18939process_note (Elf_Internal_Note * pnote,
dda8d76d 18940 Filedata * filedata)
779fe533 18941{
2cf0635d
NC
18942 const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
18943 const char * nt;
9437c45b
JT
18944
18945 if (pnote->namesz == 0)
1ec5cd37
NC
18946 /* If there is no note name, then use the default set of
18947 note type strings. */
dda8d76d 18948 nt = get_note_type (filedata, pnote->type);
1ec5cd37 18949
1118d252
RM
18950 else if (const_strneq (pnote->namedata, "GNU"))
18951 /* GNU-specific object file notes. */
18952 nt = get_gnu_elf_note_type (pnote->type);
f4ddf30f
JB
18953
18954 else if (const_strneq (pnote->namedata, "FreeBSD"))
18955 /* FreeBSD-specific core file notes. */
dda8d76d 18956 nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
1118d252 18957
0112cd26 18958 else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
1ec5cd37 18959 /* NetBSD-specific core file notes. */
dda8d76d 18960 nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
1ec5cd37 18961
c6056a74
SF
18962 else if (const_strneq (pnote->namedata, "NetBSD"))
18963 /* NetBSD-specific core file notes. */
18964 return process_netbsd_elf_note (pnote);
18965
b15fa79e
AM
18966 else if (strneq (pnote->namedata, "SPU/", 4))
18967 {
18968 /* SPU-specific core file notes. */
18969 nt = pnote->namedata + 4;
18970 name = "SPU";
18971 }
18972
00e98fc7
TG
18973 else if (const_strneq (pnote->namedata, "IPF/VMS"))
18974 /* VMS/ia64-specific file notes. */
18975 nt = get_ia64_vms_note_type (pnote->type);
18976
70616151
TT
18977 else if (const_strneq (pnote->namedata, "stapsdt"))
18978 nt = get_stapsdt_note_type (pnote->type);
18979
9437c45b 18980 else
1ec5cd37
NC
18981 /* Don't recognize this note name; just use the default set of
18982 note type strings. */
dda8d76d 18983 nt = get_note_type (filedata, pnote->type);
9437c45b 18984
1449284b 18985 printf (" ");
9ef920e9 18986
483767a3
AM
18987 if (((const_strneq (pnote->namedata, "GA")
18988 && strchr ("*$!+", pnote->namedata[2]) != NULL)
18989 || strchr ("*$!+", pnote->namedata[0]) != NULL)
18990 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
18991 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
9ef920e9
NC
18992 print_gnu_build_attribute_name (pnote);
18993 else
18994 print_symbol (-20, name);
18995
18996 if (do_wide)
18997 printf (" 0x%08lx\t%s\t", pnote->descsz, nt);
18998 else
18999 printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
00e98fc7
TG
19000
19001 if (const_strneq (pnote->namedata, "IPF/VMS"))
19002 return print_ia64_vms_note (pnote);
664f90a3 19003 else if (const_strneq (pnote->namedata, "GNU"))
dda8d76d 19004 return print_gnu_note (filedata, pnote);
c6a9fc58
TT
19005 else if (const_strneq (pnote->namedata, "stapsdt"))
19006 return print_stapsdt_note (pnote);
9ece1fa9
TT
19007 else if (const_strneq (pnote->namedata, "CORE"))
19008 return print_core_note (pnote);
483767a3
AM
19009 else if (((const_strneq (pnote->namedata, "GA")
19010 && strchr ("*$!+", pnote->namedata[2]) != NULL)
19011 || strchr ("*$!+", pnote->namedata[0]) != NULL)
19012 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
19013 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
dda8d76d 19014 return print_gnu_build_attribute_description (pnote, filedata);
779fe533 19015
9ef920e9 19016 if (pnote->descsz)
1449284b
NC
19017 {
19018 unsigned long i;
19019
19020 printf (_(" description data: "));
19021 for (i = 0; i < pnote->descsz; i++)
19022 printf ("%02x ", pnote->descdata[i]);
04ac15ab
AS
19023 if (!do_wide)
19024 printf ("\n");
1449284b
NC
19025 }
19026
9ef920e9
NC
19027 if (do_wide)
19028 printf ("\n");
19029
32ec8896 19030 return TRUE;
1449284b 19031}
6d118b09 19032
32ec8896 19033static bfd_boolean
dda8d76d
NC
19034process_notes_at (Filedata * filedata,
19035 Elf_Internal_Shdr * section,
19036 bfd_vma offset,
82ed9683
L
19037 bfd_vma length,
19038 bfd_vma align)
779fe533 19039{
2cf0635d
NC
19040 Elf_External_Note * pnotes;
19041 Elf_External_Note * external;
4dff97b2
NC
19042 char * end;
19043 bfd_boolean res = TRUE;
103f02d3 19044
779fe533 19045 if (length <= 0)
32ec8896 19046 return FALSE;
103f02d3 19047
1449284b
NC
19048 if (section)
19049 {
dda8d76d 19050 pnotes = (Elf_External_Note *) get_section_contents (section, filedata);
1449284b 19051 if (pnotes)
32ec8896 19052 {
dda8d76d 19053 if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL))
32ec8896
NC
19054 return FALSE;
19055 }
1449284b
NC
19056 }
19057 else
82ed9683 19058 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
1449284b 19059 _("notes"));
4dff97b2 19060
dd24e3da 19061 if (pnotes == NULL)
32ec8896 19062 return FALSE;
779fe533 19063
103f02d3 19064 external = pnotes;
103f02d3 19065
1449284b 19066 if (section)
dda8d76d 19067 printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (filedata, section));
1449284b
NC
19068 else
19069 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
19070 (unsigned long) offset, (unsigned long) length);
19071
82ed9683
L
19072 /* NB: Some note sections may have alignment value of 0 or 1. gABI
19073 specifies that notes should be aligned to 4 bytes in 32-bit
19074 objects and to 8 bytes in 64-bit objects. As a Linux extension,
19075 we also support 4 byte alignment in 64-bit objects. If section
19076 alignment is less than 4, we treate alignment as 4 bytes. */
19077 if (align < 4)
19078 align = 4;
19079 else if (align != 4 && align != 8)
19080 {
19081 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
19082 (long) align);
19083 return FALSE;
19084 }
19085
2aee03ae 19086 printf (_(" %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
103f02d3 19087
c8071705
NC
19088 end = (char *) pnotes + length;
19089 while ((char *) external < end)
779fe533 19090 {
b34976b6 19091 Elf_Internal_Note inote;
15b42fb0 19092 size_t min_notesz;
4dff97b2 19093 char * next;
2cf0635d 19094 char * temp = NULL;
c8071705 19095 size_t data_remaining = end - (char *) external;
6d118b09 19096
dda8d76d 19097 if (!is_ia64_vms (filedata))
15b42fb0 19098 {
9dd3a467
NC
19099 /* PR binutils/15191
19100 Make sure that there is enough data to read. */
15b42fb0
AM
19101 min_notesz = offsetof (Elf_External_Note, name);
19102 if (data_remaining < min_notesz)
9dd3a467 19103 {
d3a49aa8
AM
19104 warn (ngettext ("Corrupt note: only %ld byte remains, "
19105 "not enough for a full note\n",
19106 "Corrupt note: only %ld bytes remain, "
19107 "not enough for a full note\n",
19108 data_remaining),
19109 (long) data_remaining);
9dd3a467
NC
19110 break;
19111 }
5396a86e
AM
19112 data_remaining -= min_notesz;
19113
15b42fb0
AM
19114 inote.type = BYTE_GET (external->type);
19115 inote.namesz = BYTE_GET (external->namesz);
19116 inote.namedata = external->name;
19117 inote.descsz = BYTE_GET (external->descsz);
276da9b3 19118 inote.descdata = ((char *) external
4dff97b2 19119 + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
15b42fb0 19120 inote.descpos = offset + (inote.descdata - (char *) pnotes);
276da9b3 19121 next = ((char *) external
4dff97b2 19122 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
15b42fb0 19123 }
00e98fc7 19124 else
15b42fb0
AM
19125 {
19126 Elf64_External_VMS_Note *vms_external;
00e98fc7 19127
9dd3a467
NC
19128 /* PR binutils/15191
19129 Make sure that there is enough data to read. */
15b42fb0
AM
19130 min_notesz = offsetof (Elf64_External_VMS_Note, name);
19131 if (data_remaining < min_notesz)
9dd3a467 19132 {
d3a49aa8
AM
19133 warn (ngettext ("Corrupt note: only %ld byte remains, "
19134 "not enough for a full note\n",
19135 "Corrupt note: only %ld bytes remain, "
19136 "not enough for a full note\n",
19137 data_remaining),
19138 (long) data_remaining);
9dd3a467
NC
19139 break;
19140 }
5396a86e 19141 data_remaining -= min_notesz;
3e55a963 19142
15b42fb0
AM
19143 vms_external = (Elf64_External_VMS_Note *) external;
19144 inote.type = BYTE_GET (vms_external->type);
19145 inote.namesz = BYTE_GET (vms_external->namesz);
19146 inote.namedata = vms_external->name;
19147 inote.descsz = BYTE_GET (vms_external->descsz);
19148 inote.descdata = inote.namedata + align_power (inote.namesz, 3);
19149 inote.descpos = offset + (inote.descdata - (char *) pnotes);
19150 next = inote.descdata + align_power (inote.descsz, 3);
19151 }
19152
5396a86e
AM
19153 /* PR 17531: file: 3443835e. */
19154 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
19155 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
19156 || (size_t) (inote.descdata - inote.namedata) > data_remaining
19157 || (size_t) (next - inote.descdata) < inote.descsz
19158 || ((size_t) (next - inote.descdata)
19159 > data_remaining - (size_t) (inote.descdata - inote.namedata)))
3e55a963 19160 {
15b42fb0 19161 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
0af1713e 19162 (unsigned long) ((char *) external - (char *) pnotes));
4dff97b2
NC
19163 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
19164 inote.type, inote.namesz, inote.descsz, (int) align);
3e55a963
NC
19165 break;
19166 }
19167
15b42fb0 19168 external = (Elf_External_Note *) next;
dd24e3da 19169
6d118b09
NC
19170 /* Verify that name is null terminated. It appears that at least
19171 one version of Linux (RedHat 6.0) generates corefiles that don't
19172 comply with the ELF spec by failing to include the null byte in
19173 namesz. */
18344509 19174 if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0')
6d118b09 19175 {
5396a86e 19176 if ((size_t) (inote.descdata - inote.namedata) == inote.namesz)
6d118b09 19177 {
5396a86e
AM
19178 temp = (char *) malloc (inote.namesz + 1);
19179 if (temp == NULL)
19180 {
19181 error (_("Out of memory allocating space for inote name\n"));
19182 res = FALSE;
19183 break;
19184 }
76da6bbe 19185
5396a86e
AM
19186 memcpy (temp, inote.namedata, inote.namesz);
19187 inote.namedata = temp;
19188 }
19189 inote.namedata[inote.namesz] = 0;
6d118b09
NC
19190 }
19191
dda8d76d 19192 if (! process_note (& inote, filedata))
6b4bf3bc 19193 res = FALSE;
103f02d3 19194
6d118b09
NC
19195 if (temp != NULL)
19196 {
19197 free (temp);
19198 temp = NULL;
19199 }
779fe533
NC
19200 }
19201
19202 free (pnotes);
103f02d3 19203
779fe533
NC
19204 return res;
19205}
19206
32ec8896 19207static bfd_boolean
dda8d76d 19208process_corefile_note_segments (Filedata * filedata)
779fe533 19209{
2cf0635d 19210 Elf_Internal_Phdr * segment;
b34976b6 19211 unsigned int i;
32ec8896 19212 bfd_boolean res = TRUE;
103f02d3 19213
dda8d76d 19214 if (! get_program_headers (filedata))
6b4bf3bc 19215 return TRUE;
103f02d3 19216
dda8d76d
NC
19217 for (i = 0, segment = filedata->program_headers;
19218 i < filedata->file_header.e_phnum;
b34976b6 19219 i++, segment++)
779fe533
NC
19220 {
19221 if (segment->p_type == PT_NOTE)
dda8d76d 19222 if (! process_notes_at (filedata, NULL,
32ec8896 19223 (bfd_vma) segment->p_offset,
82ed9683
L
19224 (bfd_vma) segment->p_filesz,
19225 (bfd_vma) segment->p_align))
32ec8896 19226 res = FALSE;
779fe533 19227 }
103f02d3 19228
779fe533
NC
19229 return res;
19230}
19231
32ec8896 19232static bfd_boolean
dda8d76d 19233process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length)
685080f2
NC
19234{
19235 Elf_External_Note * pnotes;
19236 Elf_External_Note * external;
c8071705 19237 char * end;
32ec8896 19238 bfd_boolean res = TRUE;
685080f2
NC
19239
19240 if (length <= 0)
32ec8896 19241 return FALSE;
685080f2 19242
dda8d76d 19243 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
685080f2
NC
19244 _("v850 notes"));
19245 if (pnotes == NULL)
32ec8896 19246 return FALSE;
685080f2
NC
19247
19248 external = pnotes;
c8071705 19249 end = (char*) pnotes + length;
685080f2
NC
19250
19251 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
19252 (unsigned long) offset, (unsigned long) length);
19253
c8071705 19254 while ((char *) external + sizeof (Elf_External_Note) < end)
685080f2
NC
19255 {
19256 Elf_External_Note * next;
19257 Elf_Internal_Note inote;
19258
19259 inote.type = BYTE_GET (external->type);
19260 inote.namesz = BYTE_GET (external->namesz);
19261 inote.namedata = external->name;
19262 inote.descsz = BYTE_GET (external->descsz);
19263 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
19264 inote.descpos = offset + (inote.descdata - (char *) pnotes);
19265
c8071705
NC
19266 if (inote.descdata < (char *) pnotes || inote.descdata >= end)
19267 {
19268 warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
19269 inote.descdata = inote.namedata;
19270 inote.namesz = 0;
19271 }
19272
685080f2
NC
19273 next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
19274
c8071705 19275 if ( ((char *) next > end)
685080f2
NC
19276 || ((char *) next < (char *) pnotes))
19277 {
19278 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
19279 (unsigned long) ((char *) external - (char *) pnotes));
19280 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19281 inote.type, inote.namesz, inote.descsz);
19282 break;
19283 }
19284
19285 external = next;
19286
19287 /* Prevent out-of-bounds indexing. */
c8071705 19288 if ( inote.namedata + inote.namesz > end
685080f2
NC
19289 || inote.namedata + inote.namesz < inote.namedata)
19290 {
19291 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
19292 (unsigned long) ((char *) external - (char *) pnotes));
19293 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19294 inote.type, inote.namesz, inote.descsz);
19295 break;
19296 }
19297
19298 printf (" %s: ", get_v850_elf_note_type (inote.type));
19299
19300 if (! print_v850_note (& inote))
19301 {
32ec8896 19302 res = FALSE;
685080f2
NC
19303 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
19304 inote.namesz, inote.descsz);
19305 }
19306 }
19307
19308 free (pnotes);
19309
19310 return res;
19311}
19312
32ec8896 19313static bfd_boolean
dda8d76d 19314process_note_sections (Filedata * filedata)
1ec5cd37 19315{
2cf0635d 19316 Elf_Internal_Shdr * section;
1ec5cd37 19317 unsigned long i;
32ec8896
NC
19318 unsigned int n = 0;
19319 bfd_boolean res = TRUE;
1ec5cd37 19320
dda8d76d
NC
19321 for (i = 0, section = filedata->section_headers;
19322 i < filedata->file_header.e_shnum && section != NULL;
1ec5cd37 19323 i++, section++)
685080f2
NC
19324 {
19325 if (section->sh_type == SHT_NOTE)
19326 {
dda8d76d 19327 if (! process_notes_at (filedata, section,
32ec8896 19328 (bfd_vma) section->sh_offset,
82ed9683
L
19329 (bfd_vma) section->sh_size,
19330 (bfd_vma) section->sh_addralign))
32ec8896 19331 res = FALSE;
685080f2
NC
19332 n++;
19333 }
19334
dda8d76d
NC
19335 if (( filedata->file_header.e_machine == EM_V800
19336 || filedata->file_header.e_machine == EM_V850
19337 || filedata->file_header.e_machine == EM_CYGNUS_V850)
685080f2
NC
19338 && section->sh_type == SHT_RENESAS_INFO)
19339 {
dda8d76d 19340 if (! process_v850_notes (filedata,
32ec8896
NC
19341 (bfd_vma) section->sh_offset,
19342 (bfd_vma) section->sh_size))
19343 res = FALSE;
685080f2
NC
19344 n++;
19345 }
19346 }
df565f32
NC
19347
19348 if (n == 0)
19349 /* Try processing NOTE segments instead. */
dda8d76d 19350 return process_corefile_note_segments (filedata);
1ec5cd37
NC
19351
19352 return res;
19353}
19354
32ec8896 19355static bfd_boolean
dda8d76d 19356process_notes (Filedata * filedata)
779fe533
NC
19357{
19358 /* If we have not been asked to display the notes then do nothing. */
19359 if (! do_notes)
32ec8896 19360 return TRUE;
103f02d3 19361
dda8d76d
NC
19362 if (filedata->file_header.e_type != ET_CORE)
19363 return process_note_sections (filedata);
103f02d3 19364
779fe533 19365 /* No program headers means no NOTE segment. */
dda8d76d
NC
19366 if (filedata->file_header.e_phnum > 0)
19367 return process_corefile_note_segments (filedata);
779fe533 19368
1ec5cd37 19369 printf (_("No note segments present in the core file.\n"));
32ec8896 19370 return TRUE;
779fe533
NC
19371}
19372
60abdbed
NC
19373static unsigned char *
19374display_public_gnu_attributes (unsigned char * start,
19375 const unsigned char * const end)
19376{
19377 printf (_(" Unknown GNU attribute: %s\n"), start);
19378
19379 start += strnlen ((char *) start, end - start);
19380 display_raw_attribute (start, end);
19381
19382 return (unsigned char *) end;
19383}
19384
19385static unsigned char *
19386display_generic_attribute (unsigned char * start,
19387 unsigned int tag,
19388 const unsigned char * const end)
19389{
19390 if (tag == 0)
19391 return (unsigned char *) end;
19392
19393 return display_tag_value (tag, start, end);
19394}
19395
32ec8896 19396static bfd_boolean
dda8d76d 19397process_arch_specific (Filedata * filedata)
252b5132 19398{
a952a375 19399 if (! do_arch)
32ec8896 19400 return TRUE;
a952a375 19401
dda8d76d 19402 switch (filedata->file_header.e_machine)
252b5132 19403 {
53a346d8
CZ
19404 case EM_ARC:
19405 case EM_ARC_COMPACT:
19406 case EM_ARC_COMPACT2:
dda8d76d 19407 return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES,
53a346d8
CZ
19408 display_arc_attribute,
19409 display_generic_attribute);
11c1ff18 19410 case EM_ARM:
dda8d76d 19411 return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES,
60abdbed
NC
19412 display_arm_attribute,
19413 display_generic_attribute);
19414
252b5132 19415 case EM_MIPS:
4fe85591 19416 case EM_MIPS_RS3_LE:
dda8d76d 19417 return process_mips_specific (filedata);
60abdbed
NC
19418
19419 case EM_MSP430:
dda8d76d
NC
19420 return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
19421 display_msp430x_attribute,
19422 display_generic_attribute);
60abdbed 19423
2dc8dd17
JW
19424 case EM_RISCV:
19425 return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES,
19426 display_riscv_attribute,
19427 display_generic_attribute);
19428
35c08157 19429 case EM_NDS32:
dda8d76d 19430 return process_nds32_specific (filedata);
60abdbed 19431
34c8bcba 19432 case EM_PPC:
b82317dd 19433 case EM_PPC64:
dda8d76d 19434 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
19435 display_power_gnu_attribute);
19436
643f7afb
AK
19437 case EM_S390:
19438 case EM_S390_OLD:
dda8d76d 19439 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
19440 display_s390_gnu_attribute);
19441
9e8c70f9
DM
19442 case EM_SPARC:
19443 case EM_SPARC32PLUS:
19444 case EM_SPARCV9:
dda8d76d 19445 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
19446 display_sparc_gnu_attribute);
19447
59e6276b 19448 case EM_TI_C6000:
dda8d76d 19449 return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES,
60abdbed
NC
19450 display_tic6x_attribute,
19451 display_generic_attribute);
19452
252b5132 19453 default:
dda8d76d 19454 return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES,
60abdbed
NC
19455 display_public_gnu_attributes,
19456 display_generic_attribute);
252b5132 19457 }
252b5132
RH
19458}
19459
32ec8896 19460static bfd_boolean
dda8d76d 19461get_file_header (Filedata * filedata)
252b5132 19462{
9ea033b2 19463 /* Read in the identity array. */
dda8d76d 19464 if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 19465 return FALSE;
252b5132 19466
9ea033b2 19467 /* Determine how to read the rest of the header. */
dda8d76d 19468 switch (filedata->file_header.e_ident[EI_DATA])
9ea033b2 19469 {
1a0670f3
AM
19470 default:
19471 case ELFDATANONE:
adab8cdc
AO
19472 case ELFDATA2LSB:
19473 byte_get = byte_get_little_endian;
19474 byte_put = byte_put_little_endian;
19475 break;
19476 case ELFDATA2MSB:
19477 byte_get = byte_get_big_endian;
19478 byte_put = byte_put_big_endian;
19479 break;
9ea033b2
NC
19480 }
19481
19482 /* For now we only support 32 bit and 64 bit ELF files. */
dda8d76d 19483 is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64);
9ea033b2
NC
19484
19485 /* Read in the rest of the header. */
19486 if (is_32bit_elf)
19487 {
19488 Elf32_External_Ehdr ehdr32;
252b5132 19489
dda8d76d 19490 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 19491 return FALSE;
103f02d3 19492
dda8d76d
NC
19493 filedata->file_header.e_type = BYTE_GET (ehdr32.e_type);
19494 filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine);
19495 filedata->file_header.e_version = BYTE_GET (ehdr32.e_version);
19496 filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry);
19497 filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
19498 filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
19499 filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags);
19500 filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
19501 filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
19502 filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
19503 filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
19504 filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
19505 filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9ea033b2 19506 }
252b5132 19507 else
9ea033b2
NC
19508 {
19509 Elf64_External_Ehdr ehdr64;
a952a375
NC
19510
19511 /* If we have been compiled with sizeof (bfd_vma) == 4, then
19512 we will not be able to cope with the 64bit data found in
19513 64 ELF files. Detect this now and abort before we start
50c2245b 19514 overwriting things. */
a952a375
NC
19515 if (sizeof (bfd_vma) < 8)
19516 {
e3c8793a
NC
19517 error (_("This instance of readelf has been built without support for a\n\
1951864 bit data type and so it cannot read 64 bit ELF files.\n"));
32ec8896 19519 return FALSE;
a952a375 19520 }
103f02d3 19521
dda8d76d 19522 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 19523 return FALSE;
103f02d3 19524
dda8d76d
NC
19525 filedata->file_header.e_type = BYTE_GET (ehdr64.e_type);
19526 filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine);
19527 filedata->file_header.e_version = BYTE_GET (ehdr64.e_version);
19528 filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry);
19529 filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
19530 filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
19531 filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags);
19532 filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
19533 filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
19534 filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
19535 filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
19536 filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
19537 filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9ea033b2 19538 }
252b5132 19539
dda8d76d 19540 if (filedata->file_header.e_shoff)
7ece0d85
JJ
19541 {
19542 /* There may be some extensions in the first section header. Don't
19543 bomb if we can't read it. */
19544 if (is_32bit_elf)
dda8d76d 19545 get_32bit_section_headers (filedata, TRUE);
7ece0d85 19546 else
dda8d76d 19547 get_64bit_section_headers (filedata, TRUE);
7ece0d85 19548 }
560f3c1c 19549
32ec8896 19550 return TRUE;
252b5132
RH
19551}
19552
dda8d76d
NC
19553static void
19554close_file (Filedata * filedata)
19555{
19556 if (filedata)
19557 {
19558 if (filedata->handle)
19559 fclose (filedata->handle);
19560 free (filedata);
19561 }
19562}
19563
19564void
19565close_debug_file (void * data)
19566{
19567 close_file ((Filedata *) data);
19568}
19569
19570static Filedata *
19571open_file (const char * pathname)
19572{
19573 struct stat statbuf;
19574 Filedata * filedata = NULL;
19575
19576 if (stat (pathname, & statbuf) < 0
19577 || ! S_ISREG (statbuf.st_mode))
19578 goto fail;
19579
19580 filedata = calloc (1, sizeof * filedata);
19581 if (filedata == NULL)
19582 goto fail;
19583
19584 filedata->handle = fopen (pathname, "rb");
19585 if (filedata->handle == NULL)
19586 goto fail;
19587
19588 filedata->file_size = (bfd_size_type) statbuf.st_size;
19589 filedata->file_name = pathname;
19590
19591 if (! get_file_header (filedata))
19592 goto fail;
19593
19594 if (filedata->file_header.e_shoff)
19595 {
19596 bfd_boolean res;
19597
19598 /* Read the section headers again, this time for real. */
19599 if (is_32bit_elf)
19600 res = get_32bit_section_headers (filedata, FALSE);
19601 else
19602 res = get_64bit_section_headers (filedata, FALSE);
19603
19604 if (!res)
19605 goto fail;
19606 }
19607
19608 return filedata;
19609
19610 fail:
19611 if (filedata)
19612 {
19613 if (filedata->handle)
19614 fclose (filedata->handle);
19615 free (filedata);
19616 }
19617 return NULL;
19618}
19619
19620void *
19621open_debug_file (const char * pathname)
19622{
19623 return open_file (pathname);
19624}
19625
fb52b2f4
NC
19626/* Process one ELF object file according to the command line options.
19627 This file may actually be stored in an archive. The file is
32ec8896
NC
19628 positioned at the start of the ELF object. Returns TRUE if no
19629 problems were encountered, FALSE otherwise. */
fb52b2f4 19630
32ec8896 19631static bfd_boolean
dda8d76d 19632process_object (Filedata * filedata)
252b5132 19633{
24841daa 19634 bfd_boolean have_separate_files;
252b5132 19635 unsigned int i;
32ec8896 19636 bfd_boolean res = TRUE;
252b5132 19637
dda8d76d 19638 if (! get_file_header (filedata))
252b5132 19639 {
dda8d76d 19640 error (_("%s: Failed to read file header\n"), filedata->file_name);
32ec8896 19641 return FALSE;
252b5132
RH
19642 }
19643
19644 /* Initialise per file variables. */
60bca95a 19645 for (i = ARRAY_SIZE (version_info); i--;)
252b5132
RH
19646 version_info[i] = 0;
19647
60bca95a 19648 for (i = ARRAY_SIZE (dynamic_info); i--;)
252b5132 19649 dynamic_info[i] = 0;
5115b233 19650 dynamic_info_DT_GNU_HASH = 0;
252b5132
RH
19651
19652 /* Process the file. */
19653 if (show_name)
dda8d76d 19654 printf (_("\nFile: %s\n"), filedata->file_name);
252b5132 19655
18bd398b
NC
19656 /* Initialise the dump_sects array from the cmdline_dump_sects array.
19657 Note we do this even if cmdline_dump_sects is empty because we
19658 must make sure that the dump_sets array is zeroed out before each
19659 object file is processed. */
dda8d76d
NC
19660 if (filedata->num_dump_sects > cmdline.num_dump_sects)
19661 memset (filedata->dump_sects, 0, filedata->num_dump_sects * sizeof (* filedata->dump_sects));
18bd398b 19662
dda8d76d 19663 if (cmdline.num_dump_sects > 0)
18bd398b 19664 {
dda8d76d 19665 if (filedata->num_dump_sects == 0)
18bd398b 19666 /* A sneaky way of allocating the dump_sects array. */
dda8d76d 19667 request_dump_bynumber (filedata, cmdline.num_dump_sects, 0);
18bd398b 19668
dda8d76d
NC
19669 assert (filedata->num_dump_sects >= cmdline.num_dump_sects);
19670 memcpy (filedata->dump_sects, cmdline.dump_sects,
19671 cmdline.num_dump_sects * sizeof (* filedata->dump_sects));
18bd398b 19672 }
d70c5fc7 19673
dda8d76d 19674 if (! process_file_header (filedata))
32ec8896 19675 return FALSE;
252b5132 19676
dda8d76d 19677 if (! process_section_headers (filedata))
2f62977e 19678 {
32ec8896
NC
19679 /* Without loaded section headers we cannot process lots of things. */
19680 do_unwind = do_version = do_dump = do_arch = FALSE;
252b5132 19681
2f62977e 19682 if (! do_using_dynamic)
32ec8896 19683 do_syms = do_dyn_syms = do_reloc = FALSE;
2f62977e 19684 }
252b5132 19685
dda8d76d 19686 if (! process_section_groups (filedata))
32ec8896
NC
19687 /* Without loaded section groups we cannot process unwind. */
19688 do_unwind = FALSE;
d1f5c6e3 19689
dda8d76d
NC
19690 if (process_program_headers (filedata))
19691 process_dynamic_section (filedata);
32ec8896
NC
19692 else
19693 res = FALSE;
252b5132 19694
dda8d76d 19695 if (! process_relocs (filedata))
32ec8896 19696 res = FALSE;
252b5132 19697
dda8d76d 19698 if (! process_unwind (filedata))
32ec8896 19699 res = FALSE;
4d6ed7c8 19700
dda8d76d 19701 if (! process_symbol_table (filedata))
32ec8896 19702 res = FALSE;
252b5132 19703
dda8d76d 19704 if (! process_syminfo (filedata))
32ec8896 19705 res = FALSE;
252b5132 19706
dda8d76d 19707 if (! process_version_sections (filedata))
32ec8896 19708 res = FALSE;
252b5132 19709
82ed9683 19710 if (filedata->file_header.e_shstrndx != SHN_UNDEF)
24841daa 19711 have_separate_files = load_separate_debug_files (filedata, filedata->file_name);
82ed9683 19712 else
24841daa 19713 have_separate_files = FALSE;
dda8d76d
NC
19714
19715 if (! process_section_contents (filedata))
32ec8896 19716 res = FALSE;
f5842774 19717
24841daa 19718 if (have_separate_files)
dda8d76d 19719 {
24841daa
NC
19720 separate_info * d;
19721
19722 for (d = first_separate_info; d != NULL; d = d->next)
19723 {
19724 if (! process_section_headers (d->handle))
19725 res = FALSE;
19726 else if (! process_section_contents (d->handle))
19727 res = FALSE;
19728 }
19729
19730 /* The file handles are closed by the call to free_debug_memory() below. */
dda8d76d
NC
19731 }
19732
19733 if (! process_notes (filedata))
32ec8896 19734 res = FALSE;
103f02d3 19735
dda8d76d 19736 if (! process_gnu_liblist (filedata))
32ec8896 19737 res = FALSE;
047b2264 19738
dda8d76d 19739 if (! process_arch_specific (filedata))
32ec8896 19740 res = FALSE;
252b5132 19741
dda8d76d
NC
19742 free (filedata->program_headers);
19743 filedata->program_headers = NULL;
d93f0186 19744
dda8d76d
NC
19745 free (filedata->section_headers);
19746 filedata->section_headers = NULL;
252b5132 19747
dda8d76d
NC
19748 free (filedata->string_table);
19749 filedata->string_table = NULL;
19750 filedata->string_table_length = 0;
252b5132
RH
19751
19752 if (dynamic_strings)
19753 {
19754 free (dynamic_strings);
19755 dynamic_strings = NULL;
d79b3d50 19756 dynamic_strings_length = 0;
252b5132
RH
19757 }
19758
19759 if (dynamic_symbols)
19760 {
19761 free (dynamic_symbols);
19762 dynamic_symbols = NULL;
19936277 19763 num_dynamic_syms = 0;
252b5132
RH
19764 }
19765
19766 if (dynamic_syminfo)
19767 {
19768 free (dynamic_syminfo);
19769 dynamic_syminfo = NULL;
19770 }
ff78d6d6 19771
293c573e
MR
19772 if (dynamic_section)
19773 {
19774 free (dynamic_section);
19775 dynamic_section = NULL;
19776 }
19777
e4b17d5c
L
19778 if (section_headers_groups)
19779 {
19780 free (section_headers_groups);
19781 section_headers_groups = NULL;
19782 }
19783
19784 if (section_groups)
19785 {
2cf0635d
NC
19786 struct group_list * g;
19787 struct group_list * next;
e4b17d5c
L
19788
19789 for (i = 0; i < group_count; i++)
19790 {
19791 for (g = section_groups [i].root; g != NULL; g = next)
19792 {
19793 next = g->next;
19794 free (g);
19795 }
19796 }
19797
19798 free (section_groups);
19799 section_groups = NULL;
19800 }
19801
19e6b90e 19802 free_debug_memory ();
18bd398b 19803
32ec8896 19804 return res;
252b5132
RH
19805}
19806
2cf0635d 19807/* Process an ELF archive.
32ec8896
NC
19808 On entry the file is positioned just after the ARMAG string.
19809 Returns TRUE upon success, FALSE otherwise. */
2cf0635d 19810
32ec8896 19811static bfd_boolean
dda8d76d 19812process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
2cf0635d
NC
19813{
19814 struct archive_info arch;
19815 struct archive_info nested_arch;
19816 size_t got;
32ec8896 19817 bfd_boolean ret = TRUE;
2cf0635d 19818
32ec8896 19819 show_name = TRUE;
2cf0635d
NC
19820
19821 /* The ARCH structure is used to hold information about this archive. */
19822 arch.file_name = NULL;
19823 arch.file = NULL;
19824 arch.index_array = NULL;
19825 arch.sym_table = NULL;
19826 arch.longnames = NULL;
19827
19828 /* The NESTED_ARCH structure is used as a single-item cache of information
19829 about a nested archive (when members of a thin archive reside within
19830 another regular archive file). */
19831 nested_arch.file_name = NULL;
19832 nested_arch.file = NULL;
19833 nested_arch.index_array = NULL;
19834 nested_arch.sym_table = NULL;
19835 nested_arch.longnames = NULL;
19836
dda8d76d
NC
19837 if (setup_archive (&arch, filedata->file_name, filedata->handle,
19838 is_thin_archive, do_archive_index) != 0)
2cf0635d 19839 {
32ec8896 19840 ret = FALSE;
2cf0635d 19841 goto out;
4145f1d5 19842 }
fb52b2f4 19843
4145f1d5
NC
19844 if (do_archive_index)
19845 {
2cf0635d 19846 if (arch.sym_table == NULL)
dda8d76d 19847 error (_("%s: unable to dump the index as none was found\n"), filedata->file_name);
4145f1d5
NC
19848 else
19849 {
591f7597 19850 unsigned long i, l;
4145f1d5
NC
19851 unsigned long current_pos;
19852
591f7597 19853 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
dda8d76d
NC
19854 filedata->file_name, (unsigned long) arch.index_num, arch.sym_size);
19855
19856 current_pos = ftell (filedata->handle);
4145f1d5 19857
2cf0635d 19858 for (i = l = 0; i < arch.index_num; i++)
4145f1d5 19859 {
2cf0635d
NC
19860 if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
19861 {
19862 char * member_name;
4145f1d5 19863
2cf0635d
NC
19864 member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
19865
19866 if (member_name != NULL)
19867 {
19868 char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
19869
19870 if (qualified_name != NULL)
19871 {
c2a7d3f5
NC
19872 printf (_("Contents of binary %s at offset "), qualified_name);
19873 (void) print_vma (arch.index_array[i], PREFIX_HEX);
19874 putchar ('\n');
2cf0635d
NC
19875 free (qualified_name);
19876 }
4145f1d5
NC
19877 }
19878 }
2cf0635d
NC
19879
19880 if (l >= arch.sym_size)
4145f1d5
NC
19881 {
19882 error (_("%s: end of the symbol table reached before the end of the index\n"),
dda8d76d 19883 filedata->file_name);
32ec8896 19884 ret = FALSE;
cb8f3167 19885 break;
4145f1d5 19886 }
591f7597
NC
19887 /* PR 17531: file: 0b6630b2. */
19888 printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l);
19889 l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
4145f1d5
NC
19890 }
19891
67ce483b 19892 if (arch.uses_64bit_indices)
c2a7d3f5
NC
19893 l = (l + 7) & ~ 7;
19894 else
19895 l += l & 1;
19896
2cf0635d 19897 if (l < arch.sym_size)
32ec8896 19898 {
d3a49aa8
AM
19899 error (ngettext ("%s: %ld byte remains in the symbol table, "
19900 "but without corresponding entries in "
19901 "the index table\n",
19902 "%s: %ld bytes remain in the symbol table, "
19903 "but without corresponding entries in "
19904 "the index table\n",
19905 arch.sym_size - l),
dda8d76d 19906 filedata->file_name, arch.sym_size - l);
32ec8896
NC
19907 ret = FALSE;
19908 }
4145f1d5 19909
dda8d76d 19910 if (fseek (filedata->handle, current_pos, SEEK_SET) != 0)
4145f1d5 19911 {
dda8d76d
NC
19912 error (_("%s: failed to seek back to start of object files in the archive\n"),
19913 filedata->file_name);
32ec8896 19914 ret = FALSE;
2cf0635d 19915 goto out;
4145f1d5 19916 }
fb52b2f4 19917 }
4145f1d5
NC
19918
19919 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
19920 && !do_segments && !do_header && !do_dump && !do_version
19921 && !do_histogram && !do_debugging && !do_arch && !do_notes
2c610e4b 19922 && !do_section_groups && !do_dyn_syms)
2cf0635d 19923 {
32ec8896 19924 ret = TRUE; /* Archive index only. */
2cf0635d
NC
19925 goto out;
19926 }
fb52b2f4
NC
19927 }
19928
fb52b2f4
NC
19929 while (1)
19930 {
2cf0635d
NC
19931 char * name;
19932 size_t namelen;
19933 char * qualified_name;
19934
19935 /* Read the next archive header. */
dda8d76d 19936 if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0)
2cf0635d 19937 {
28e817cc 19938 error (_("%s: failed to seek to next archive header\n"), arch.file_name);
32ec8896 19939 return FALSE;
2cf0635d 19940 }
dda8d76d 19941 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle);
2cf0635d
NC
19942 if (got != sizeof arch.arhdr)
19943 {
19944 if (got == 0)
19945 break;
28e817cc
NC
19946 /* PR 24049 - we cannot use filedata->file_name as this will
19947 have already been freed. */
19948 error (_("%s: failed to read archive header\n"), arch.file_name);
19949
32ec8896 19950 ret = FALSE;
2cf0635d
NC
19951 break;
19952 }
19953 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
19954 {
19955 error (_("%s: did not find a valid archive header\n"), arch.file_name);
32ec8896 19956 ret = FALSE;
2cf0635d
NC
19957 break;
19958 }
19959
19960 arch.next_arhdr_offset += sizeof arch.arhdr;
19961
19962 archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
19963 if (archive_file_size & 01)
19964 ++archive_file_size;
19965
19966 name = get_archive_member_name (&arch, &nested_arch);
19967 if (name == NULL)
fb52b2f4 19968 {
28e817cc 19969 error (_("%s: bad archive file name\n"), arch.file_name);
32ec8896 19970 ret = FALSE;
d989285c 19971 break;
fb52b2f4 19972 }
2cf0635d 19973 namelen = strlen (name);
fb52b2f4 19974
2cf0635d
NC
19975 qualified_name = make_qualified_name (&arch, &nested_arch, name);
19976 if (qualified_name == NULL)
fb52b2f4 19977 {
28e817cc 19978 error (_("%s: bad archive file name\n"), arch.file_name);
32ec8896 19979 ret = FALSE;
d989285c 19980 break;
fb52b2f4
NC
19981 }
19982
2cf0635d
NC
19983 if (is_thin_archive && arch.nested_member_origin == 0)
19984 {
19985 /* This is a proxy for an external member of a thin archive. */
dda8d76d
NC
19986 Filedata * member_filedata;
19987 char * member_file_name = adjust_relative_path
19988 (filedata->file_name, name, namelen);
32ec8896 19989
2cf0635d
NC
19990 if (member_file_name == NULL)
19991 {
32ec8896 19992 ret = FALSE;
2cf0635d
NC
19993 break;
19994 }
19995
dda8d76d
NC
19996 member_filedata = open_file (member_file_name);
19997 if (member_filedata == NULL)
2cf0635d
NC
19998 {
19999 error (_("Input file '%s' is not readable.\n"), member_file_name);
20000 free (member_file_name);
32ec8896 20001 ret = FALSE;
2cf0635d
NC
20002 break;
20003 }
20004
20005 archive_file_offset = arch.nested_member_origin;
dda8d76d 20006 member_filedata->file_name = qualified_name;
2cf0635d 20007
dda8d76d 20008 if (! process_object (member_filedata))
32ec8896 20009 ret = FALSE;
2cf0635d 20010
dda8d76d 20011 close_file (member_filedata);
2cf0635d
NC
20012 free (member_file_name);
20013 }
20014 else if (is_thin_archive)
20015 {
eb02c04d
PK
20016 Filedata thin_filedata;
20017
20018 memset (&thin_filedata, 0, sizeof (thin_filedata));
dda8d76d 20019
a043396b
NC
20020 /* PR 15140: Allow for corrupt thin archives. */
20021 if (nested_arch.file == NULL)
20022 {
20023 error (_("%s: contains corrupt thin archive: %s\n"),
28e817cc 20024 qualified_name, name);
32ec8896 20025 ret = FALSE;
a043396b
NC
20026 break;
20027 }
20028
2cf0635d
NC
20029 /* This is a proxy for a member of a nested archive. */
20030 archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
20031
20032 /* The nested archive file will have been opened and setup by
20033 get_archive_member_name. */
20034 if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
20035 {
20036 error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
32ec8896 20037 ret = FALSE;
2cf0635d
NC
20038 break;
20039 }
20040
dda8d76d
NC
20041 thin_filedata.handle = nested_arch.file;
20042 thin_filedata.file_name = qualified_name;
20043
20044 if (! process_object (& thin_filedata))
32ec8896 20045 ret = FALSE;
2cf0635d
NC
20046 }
20047 else
20048 {
20049 archive_file_offset = arch.next_arhdr_offset;
20050 arch.next_arhdr_offset += archive_file_size;
fb52b2f4 20051
6a6196fc 20052 filedata->file_name = qualified_name;
dda8d76d 20053 if (! process_object (filedata))
32ec8896 20054 ret = FALSE;
2cf0635d 20055 }
fb52b2f4 20056
dda8d76d 20057 if (filedata->dump_sects != NULL)
2b52916e 20058 {
dda8d76d
NC
20059 free (filedata->dump_sects);
20060 filedata->dump_sects = NULL;
20061 filedata->num_dump_sects = 0;
2b52916e
L
20062 }
20063
2cf0635d 20064 free (qualified_name);
fb52b2f4
NC
20065 }
20066
4145f1d5 20067 out:
2cf0635d
NC
20068 if (nested_arch.file != NULL)
20069 fclose (nested_arch.file);
20070 release_archive (&nested_arch);
20071 release_archive (&arch);
fb52b2f4 20072
d989285c 20073 return ret;
fb52b2f4
NC
20074}
20075
32ec8896 20076static bfd_boolean
2cf0635d 20077process_file (char * file_name)
fb52b2f4 20078{
dda8d76d 20079 Filedata * filedata = NULL;
fb52b2f4
NC
20080 struct stat statbuf;
20081 char armag[SARMAG];
32ec8896 20082 bfd_boolean ret = TRUE;
fb52b2f4
NC
20083
20084 if (stat (file_name, &statbuf) < 0)
20085 {
f24ddbdd
NC
20086 if (errno == ENOENT)
20087 error (_("'%s': No such file\n"), file_name);
20088 else
20089 error (_("Could not locate '%s'. System error message: %s\n"),
20090 file_name, strerror (errno));
32ec8896 20091 return FALSE;
f24ddbdd
NC
20092 }
20093
20094 if (! S_ISREG (statbuf.st_mode))
20095 {
20096 error (_("'%s' is not an ordinary file\n"), file_name);
32ec8896 20097 return FALSE;
fb52b2f4
NC
20098 }
20099
dda8d76d
NC
20100 filedata = calloc (1, sizeof * filedata);
20101 if (filedata == NULL)
20102 {
20103 error (_("Out of memory allocating file data structure\n"));
20104 return FALSE;
20105 }
20106
20107 filedata->file_name = file_name;
20108 filedata->handle = fopen (file_name, "rb");
20109 if (filedata->handle == NULL)
fb52b2f4 20110 {
f24ddbdd 20111 error (_("Input file '%s' is not readable.\n"), file_name);
dda8d76d 20112 free (filedata);
32ec8896 20113 return FALSE;
fb52b2f4
NC
20114 }
20115
dda8d76d 20116 if (fread (armag, SARMAG, 1, filedata->handle) != 1)
fb52b2f4 20117 {
4145f1d5 20118 error (_("%s: Failed to read file's magic number\n"), file_name);
dda8d76d
NC
20119 fclose (filedata->handle);
20120 free (filedata);
32ec8896 20121 return FALSE;
fb52b2f4
NC
20122 }
20123
dda8d76d 20124 filedata->file_size = (bfd_size_type) statbuf.st_size;
f54498b4 20125
fb52b2f4 20126 if (memcmp (armag, ARMAG, SARMAG) == 0)
32ec8896 20127 {
dda8d76d 20128 if (! process_archive (filedata, FALSE))
32ec8896
NC
20129 ret = FALSE;
20130 }
2cf0635d 20131 else if (memcmp (armag, ARMAGT, SARMAG) == 0)
32ec8896 20132 {
dda8d76d 20133 if ( ! process_archive (filedata, TRUE))
32ec8896
NC
20134 ret = FALSE;
20135 }
fb52b2f4
NC
20136 else
20137 {
4145f1d5
NC
20138 if (do_archive_index)
20139 error (_("File %s is not an archive so its index cannot be displayed.\n"),
20140 file_name);
20141
dda8d76d 20142 rewind (filedata->handle);
fb52b2f4 20143 archive_file_size = archive_file_offset = 0;
32ec8896 20144
dda8d76d 20145 if (! process_object (filedata))
32ec8896 20146 ret = FALSE;
fb52b2f4
NC
20147 }
20148
dda8d76d
NC
20149 fclose (filedata->handle);
20150 free (filedata);
32ec8896 20151
fb52b2f4
NC
20152 return ret;
20153}
20154
252b5132
RH
20155#ifdef SUPPORT_DISASSEMBLY
20156/* Needed by the i386 disassembler. For extra credit, someone could
9ea033b2 20157 fix this so that we insert symbolic addresses here, esp for GOT/PLT
e3c8793a 20158 symbols. */
252b5132
RH
20159
20160void
2cf0635d 20161print_address (unsigned int addr, FILE * outfile)
252b5132
RH
20162{
20163 fprintf (outfile,"0x%8.8x", addr);
20164}
20165
e3c8793a 20166/* Needed by the i386 disassembler. */
dda8d76d 20167
252b5132
RH
20168void
20169db_task_printsym (unsigned int addr)
20170{
20171 print_address (addr, stderr);
20172}
20173#endif
20174
20175int
2cf0635d 20176main (int argc, char ** argv)
252b5132 20177{
ff78d6d6
L
20178 int err;
20179
252b5132
RH
20180#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
20181 setlocale (LC_MESSAGES, "");
3882b010
L
20182#endif
20183#if defined (HAVE_SETLOCALE)
20184 setlocale (LC_CTYPE, "");
252b5132
RH
20185#endif
20186 bindtextdomain (PACKAGE, LOCALEDIR);
20187 textdomain (PACKAGE);
20188
869b9d07
MM
20189 expandargv (&argc, &argv);
20190
dda8d76d
NC
20191 cmdline.file_name = "<cmdline>";
20192 parse_args (& cmdline, argc, argv);
59f14fc0 20193
18bd398b 20194 if (optind < (argc - 1))
32ec8896 20195 show_name = TRUE;
5656ba2c
L
20196 else if (optind >= argc)
20197 {
20198 warn (_("Nothing to do.\n"));
20199 usage (stderr);
20200 }
18bd398b 20201
32ec8896 20202 err = FALSE;
252b5132 20203 while (optind < argc)
32ec8896
NC
20204 if (! process_file (argv[optind++]))
20205 err = TRUE;
252b5132 20206
dda8d76d
NC
20207 if (cmdline.dump_sects != NULL)
20208 free (cmdline.dump_sects);
252b5132 20209
90bd5423 20210#ifdef HAVE_LIBCTF
7d9813f1
NA
20211 free (dump_ctf_symtab_name);
20212 free (dump_ctf_strtab_name);
20213 free (dump_ctf_parent_name);
90bd5423 20214#endif
7d9813f1 20215
32ec8896 20216 return err ? EXIT_FAILURE : EXIT_SUCCESS;
252b5132 20217}