Resubmiting Tests for showing various information in hip device code
[deliverable/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.
ca9af5a1 3 Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
252b5132
RH
4
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
12ab83a9 6 Modifications by Nick Clifton <nickc@redhat.com>
252b5132
RH
7
8 This file is part of GNU Binutils.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
32866df7 12 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
b43b5d5f
NC
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 02110-1301, USA. */
252b5132 24\f
9eb20dd8 25/* The difference between readelf and objdump:
252b5132 26
74013231 27 Both programs are capable of displaying the contents of ELF format files,
9eb20dd8 28 so why does the binutils project have two file dumpers ?
0de14b54 29
9eb20dd8
NC
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
36
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
39
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
43\f
3db64b00 44#include "sysdep.h"
252b5132 45#include <assert.h>
252b5132 46#include <time.h>
1b315056 47#include <zlib.h>
3bfcb652 48#ifdef HAVE_WCHAR_H
7bfd842d 49#include <wchar.h>
3bfcb652 50#endif
252b5132 51
a952a375 52#if __GNUC__ >= 2
19936277 53/* Define BFD64 here, even if our default architecture is 32 bit ELF
a952a375 54 as this will allow us to read in and parse 64bit and 32bit ELF files.
b34976b6 55 Only do this if we believe that the compiler can support a 64 bit
a952a375 56 data type. For now we only rely on GCC being able to do this. */
19936277 57#define BFD64
a952a375
NC
58#endif
59
3db64b00
AM
60#include "bfd.h"
61#include "bucomm.h"
3284fe0c 62#include "elfcomm.h"
19e6b90e 63#include "dwarf.h"
7d9813f1 64#include "ctf-api.h"
252b5132
RH
65
66#include "elf/common.h"
67#include "elf/external.h"
68#include "elf/internal.h"
252b5132 69
4b78141a
NC
70
71/* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
72 we can obtain the H8 reloc numbers. We need these for the
73 get_reloc_size() function. We include h8.h again after defining
74 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
75
76#include "elf/h8.h"
77#undef _ELF_H8_H
78
79/* Undo the effects of #including reloc-macros.h. */
80
81#undef START_RELOC_NUMBERS
82#undef RELOC_NUMBER
83#undef FAKE_RELOC
84#undef EMPTY_RELOC
85#undef END_RELOC_NUMBERS
86#undef _RELOC_MACROS_H
87
252b5132
RH
88/* The following headers use the elf/reloc-macros.h file to
89 automatically generate relocation recognition functions
90 such as elf_mips_reloc_type() */
91
92#define RELOC_MACROS_GEN_FUNC
93
a06ea964 94#include "elf/aarch64.h"
252b5132 95#include "elf/alpha.h"
abeeff98 96#include "elf/amdgcn.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. */
d344b407 189#define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
dda8d76d
NC
190
191typedef unsigned char dump_type;
192
193/* A linked list of the section names for which dumps were requested. */
194struct dump_list_entry
195{
196 char * name;
197 dump_type type;
198 struct dump_list_entry * next;
199};
200
201typedef struct filedata
202{
203 const char * file_name;
204 FILE * handle;
205 bfd_size_type file_size;
206 Elf_Internal_Ehdr file_header;
207 Elf_Internal_Shdr * section_headers;
208 Elf_Internal_Phdr * program_headers;
209 char * string_table;
210 unsigned long string_table_length;
211 /* A dynamic array of flags indicating for which sections a dump of
212 some kind has been requested. It is reset on a per-object file
213 basis and then initialised from the cmdline_dump_sects array,
214 the results of interpreting the -w switch, and the
215 dump_sects_byname list. */
216 dump_type * dump_sects;
217 unsigned int num_dump_sects;
218} Filedata;
219
2cf0635d 220char * program_name = "readelf";
dda8d76d 221
c9c1d674 222static unsigned long archive_file_offset;
85b1c36d
BE
223static unsigned long archive_file_size;
224static unsigned long dynamic_addr;
225static bfd_size_type dynamic_size;
8b73c356 226static size_t dynamic_nent;
2cf0635d 227static char * dynamic_strings;
85b1c36d 228static unsigned long dynamic_strings_length;
85b1c36d 229static unsigned long num_dynamic_syms;
2cf0635d
NC
230static Elf_Internal_Sym * dynamic_symbols;
231static Elf_Internal_Syminfo * dynamic_syminfo;
85b1c36d
BE
232static unsigned long dynamic_syminfo_offset;
233static unsigned int dynamic_syminfo_nent;
f8eae8b2 234static char program_interpreter[PATH_MAX];
bb8a0291 235static bfd_vma dynamic_info[DT_ENCODING];
fdc90cb4 236static bfd_vma dynamic_info_DT_GNU_HASH;
f16a9783 237static bfd_vma dynamic_info_DT_MIPS_XHASH;
85b1c36d 238static bfd_vma version_info[16];
2cf0635d 239static Elf_Internal_Dyn * dynamic_section;
6a40cf0c 240static elf_section_list * symtab_shndx_list;
32ec8896
NC
241static bfd_boolean show_name = FALSE;
242static bfd_boolean do_dynamic = FALSE;
243static bfd_boolean do_syms = FALSE;
244static bfd_boolean do_dyn_syms = FALSE;
245static bfd_boolean do_reloc = FALSE;
246static bfd_boolean do_sections = FALSE;
247static bfd_boolean do_section_groups = FALSE;
248static bfd_boolean do_section_details = FALSE;
249static bfd_boolean do_segments = FALSE;
250static bfd_boolean do_unwind = FALSE;
251static bfd_boolean do_using_dynamic = FALSE;
252static bfd_boolean do_header = FALSE;
253static bfd_boolean do_dump = FALSE;
254static bfd_boolean do_version = FALSE;
255static bfd_boolean do_histogram = FALSE;
256static bfd_boolean do_debugging = FALSE;
7d9813f1 257static bfd_boolean do_ctf = FALSE;
32ec8896
NC
258static bfd_boolean do_arch = FALSE;
259static bfd_boolean do_notes = FALSE;
260static bfd_boolean do_archive_index = FALSE;
261static bfd_boolean is_32bit_elf = FALSE;
262static bfd_boolean decompress_dumps = FALSE;
252b5132 263
7d9813f1
NA
264static char *dump_ctf_parent_name;
265static char *dump_ctf_symtab_name;
266static char *dump_ctf_strtab_name;
267
e4b17d5c
L
268struct group_list
269{
dda8d76d
NC
270 struct group_list * next;
271 unsigned int section_index;
e4b17d5c
L
272};
273
274struct group
275{
dda8d76d
NC
276 struct group_list * root;
277 unsigned int group_index;
e4b17d5c
L
278};
279
dda8d76d
NC
280static size_t group_count;
281static struct group * section_groups;
282static struct group ** section_headers_groups;
aef1f6d0 283
09c11c86
NC
284/* A dynamic array of flags indicating for which sections a dump
285 has been requested via command line switches. */
dda8d76d 286static Filedata cmdline;
252b5132 287
dda8d76d 288static struct dump_list_entry * dump_sects_byname;
252b5132 289
c256ffe7 290/* How to print a vma value. */
843dd992
NC
291typedef enum print_mode
292{
293 HEX,
294 DEC,
295 DEC_5,
296 UNSIGNED,
297 PREFIX_HEX,
298 FULL_HEX,
299 LONG_HEX
300}
301print_mode;
302
bb4d2ac2
L
303/* Versioned symbol info. */
304enum versioned_symbol_info
305{
306 symbol_undefined,
307 symbol_hidden,
308 symbol_public
309};
310
32ec8896 311static const char * get_symbol_version_string
dda8d76d 312 (Filedata *, bfd_boolean, const char *, unsigned long, unsigned,
32ec8896 313 Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *);
bb4d2ac2 314
9c19a809
NC
315#define UNKNOWN -1
316
2b692964
NC
317#define SECTION_NAME(X) \
318 ((X) == NULL ? _("<none>") \
dda8d76d
NC
319 : filedata->string_table == NULL ? _("<no-strings>") \
320 : ((X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
321 : filedata->string_table + (X)->sh_name))
252b5132 322
ee42cf8c 323#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
252b5132 324
ba5cdace
NC
325#define GET_ELF_SYMBOLS(file, section, sym_count) \
326 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
327 : get_64bit_elf_symbols (file, section, sym_count))
9ea033b2 328
d79b3d50
NC
329#define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
330/* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
331 already been called and verified that the string exists. */
332#define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
18bd398b 333
61865e30
NC
334#define REMOVE_ARCH_BITS(ADDR) \
335 do \
336 { \
dda8d76d 337 if (filedata->file_header.e_machine == EM_ARM) \
61865e30
NC
338 (ADDR) &= ~1; \
339 } \
340 while (0)
f16a9783
MS
341
342/* Get the correct GNU hash section name. */
343#define GNU_HASH_SECTION_NAME \
344 dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
d79b3d50 345\f
66cfc0fd
AM
346/* Print a BFD_VMA to an internal buffer, for use in error messages.
347 BFD_FMA_FMT can't be used in translated strings. */
348
349static const char *
350bfd_vmatoa (char *fmtch, bfd_vma value)
351{
352 /* bfd_vmatoa is used more then once in a printf call for output.
353 Cycle through an array of buffers. */
354 static int buf_pos = 0;
355 static struct bfd_vmatoa_buf
356 {
357 char place[64];
358 } buf[4];
359 char *ret;
360 char fmt[32];
361
362 ret = buf[buf_pos++].place;
363 buf_pos %= ARRAY_SIZE (buf);
364
365 sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
366 snprintf (ret, sizeof (buf[0].place), fmt, value);
367 return ret;
368}
369
dda8d76d
NC
370/* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
371 OFFSET + the offset of the current archive member, if we are examining an
372 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
373 allocate a buffer using malloc and fill that. In either case return the
374 pointer to the start of the retrieved data or NULL if something went wrong.
375 If something does go wrong and REASON is not NULL then emit an error
376 message using REASON as part of the context. */
59245841 377
c256ffe7 378static void *
dda8d76d
NC
379get_data (void * var,
380 Filedata * filedata,
381 unsigned long offset,
382 bfd_size_type size,
383 bfd_size_type nmemb,
384 const char * reason)
a6e9f9df 385{
2cf0635d 386 void * mvar;
57028622 387 bfd_size_type amt = size * nmemb;
a6e9f9df 388
c256ffe7 389 if (size == 0 || nmemb == 0)
a6e9f9df
AM
390 return NULL;
391
57028622
NC
392 /* If the size_t type is smaller than the bfd_size_type, eg because
393 you are building a 32-bit tool on a 64-bit host, then make sure
394 that when the sizes are cast to (size_t) no information is lost. */
7c1c1904
AM
395 if ((size_t) size != size
396 || (size_t) nmemb != nmemb
397 || (size_t) amt != amt)
57028622
NC
398 {
399 if (reason)
66cfc0fd
AM
400 error (_("Size truncation prevents reading %s"
401 " elements of size %s for %s\n"),
402 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
57028622
NC
403 return NULL;
404 }
405
406 /* Check for size overflow. */
7c1c1904 407 if (amt / size != nmemb || (size_t) amt + 1 == 0)
57028622
NC
408 {
409 if (reason)
66cfc0fd
AM
410 error (_("Size overflow prevents reading %s"
411 " elements of size %s for %s\n"),
412 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
57028622
NC
413 return NULL;
414 }
415
c22b42ce 416 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
c9c1d674 417 attempting to allocate memory when the read is bound to fail. */
c22b42ce
AM
418 if (archive_file_offset > filedata->file_size
419 || offset > filedata->file_size - archive_file_offset
420 || amt > filedata->file_size - archive_file_offset - offset)
a6e9f9df 421 {
049b0c3a 422 if (reason)
66cfc0fd
AM
423 error (_("Reading %s bytes extends past end of file for %s\n"),
424 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
425 return NULL;
426 }
427
dda8d76d 428 if (fseek (filedata->handle, archive_file_offset + offset, SEEK_SET))
071436c6
NC
429 {
430 if (reason)
c9c1d674 431 error (_("Unable to seek to 0x%lx for %s\n"),
ed754a13 432 archive_file_offset + offset, reason);
071436c6
NC
433 return NULL;
434 }
435
a6e9f9df
AM
436 mvar = var;
437 if (mvar == NULL)
438 {
7c1c1904
AM
439 /* + 1 so that we can '\0' terminate invalid string table sections. */
440 mvar = malloc ((size_t) amt + 1);
a6e9f9df
AM
441
442 if (mvar == NULL)
443 {
049b0c3a 444 if (reason)
66cfc0fd
AM
445 error (_("Out of memory allocating %s bytes for %s\n"),
446 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
447 return NULL;
448 }
c256ffe7 449
c9c1d674 450 ((char *) mvar)[amt] = '\0';
a6e9f9df
AM
451 }
452
dda8d76d 453 if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb)
a6e9f9df 454 {
049b0c3a 455 if (reason)
66cfc0fd
AM
456 error (_("Unable to read in %s bytes of %s\n"),
457 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
458 if (mvar != var)
459 free (mvar);
460 return NULL;
461 }
462
463 return mvar;
464}
465
32ec8896
NC
466/* Print a VMA value in the MODE specified.
467 Returns the number of characters displayed. */
cb8f3167 468
32ec8896 469static unsigned int
14a91970 470print_vma (bfd_vma vma, print_mode mode)
66543521 471{
32ec8896 472 unsigned int nc = 0;
66543521 473
14a91970 474 switch (mode)
66543521 475 {
14a91970
AM
476 case FULL_HEX:
477 nc = printf ("0x");
1a0670f3 478 /* Fall through. */
14a91970 479 case LONG_HEX:
f7a99963 480#ifdef BFD64
14a91970 481 if (is_32bit_elf)
437c2fb7 482 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
f7a99963 483#endif
14a91970
AM
484 printf_vma (vma);
485 return nc + 16;
b19aac67 486
14a91970
AM
487 case DEC_5:
488 if (vma <= 99999)
489 return printf ("%5" BFD_VMA_FMT "d", vma);
1a0670f3 490 /* Fall through. */
14a91970
AM
491 case PREFIX_HEX:
492 nc = printf ("0x");
1a0670f3 493 /* Fall through. */
14a91970
AM
494 case HEX:
495 return nc + printf ("%" BFD_VMA_FMT "x", vma);
b19aac67 496
14a91970
AM
497 case DEC:
498 return printf ("%" BFD_VMA_FMT "d", vma);
b19aac67 499
14a91970
AM
500 case UNSIGNED:
501 return printf ("%" BFD_VMA_FMT "u", vma);
32ec8896
NC
502
503 default:
504 /* FIXME: Report unrecognised mode ? */
505 return 0;
f7a99963 506 }
f7a99963
NC
507}
508
7bfd842d 509/* Display a symbol on stdout. Handles the display of control characters and
3bfcb652 510 multibye characters (assuming the host environment supports them).
31104126 511
7bfd842d
NC
512 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
513
514 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
515 padding as necessary.
171191ba
NC
516
517 Returns the number of emitted characters. */
518
519static unsigned int
32ec8896 520print_symbol (signed int width, const char *symbol)
31104126 521{
171191ba 522 bfd_boolean extra_padding = FALSE;
32ec8896 523 signed int num_printed = 0;
3bfcb652 524#ifdef HAVE_MBSTATE_T
7bfd842d 525 mbstate_t state;
3bfcb652 526#endif
32ec8896 527 unsigned int width_remaining;
961c521f 528
7bfd842d 529 if (width < 0)
961c521f 530 {
88305e1b 531 /* Keep the width positive. This helps the code below. */
961c521f 532 width = - width;
171191ba 533 extra_padding = TRUE;
0b4362b0 534 }
56d8f8a9
NC
535 else if (width == 0)
536 return 0;
961c521f 537
7bfd842d
NC
538 if (do_wide)
539 /* Set the remaining width to a very large value.
540 This simplifies the code below. */
541 width_remaining = INT_MAX;
542 else
543 width_remaining = width;
cb8f3167 544
3bfcb652 545#ifdef HAVE_MBSTATE_T
7bfd842d
NC
546 /* Initialise the multibyte conversion state. */
547 memset (& state, 0, sizeof (state));
3bfcb652 548#endif
961c521f 549
7bfd842d
NC
550 while (width_remaining)
551 {
552 size_t n;
7bfd842d 553 const char c = *symbol++;
961c521f 554
7bfd842d 555 if (c == 0)
961c521f
NC
556 break;
557
7bfd842d
NC
558 /* Do not print control characters directly as they can affect terminal
559 settings. Such characters usually appear in the names generated
560 by the assembler for local labels. */
561 if (ISCNTRL (c))
961c521f 562 {
7bfd842d 563 if (width_remaining < 2)
961c521f
NC
564 break;
565
7bfd842d
NC
566 printf ("^%c", c + 0x40);
567 width_remaining -= 2;
171191ba 568 num_printed += 2;
961c521f 569 }
7bfd842d
NC
570 else if (ISPRINT (c))
571 {
572 putchar (c);
573 width_remaining --;
574 num_printed ++;
575 }
961c521f
NC
576 else
577 {
3bfcb652
NC
578#ifdef HAVE_MBSTATE_T
579 wchar_t w;
580#endif
7bfd842d
NC
581 /* Let printf do the hard work of displaying multibyte characters. */
582 printf ("%.1s", symbol - 1);
583 width_remaining --;
584 num_printed ++;
585
3bfcb652 586#ifdef HAVE_MBSTATE_T
7bfd842d
NC
587 /* Try to find out how many bytes made up the character that was
588 just printed. Advance the symbol pointer past the bytes that
589 were displayed. */
590 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
3bfcb652
NC
591#else
592 n = 1;
593#endif
7bfd842d
NC
594 if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
595 symbol += (n - 1);
961c521f 596 }
961c521f 597 }
171191ba 598
7bfd842d 599 if (extra_padding && num_printed < width)
171191ba
NC
600 {
601 /* Fill in the remaining spaces. */
7bfd842d
NC
602 printf ("%-*s", width - num_printed, " ");
603 num_printed = width;
171191ba
NC
604 }
605
606 return num_printed;
31104126
NC
607}
608
1449284b 609/* Returns a pointer to a static buffer containing a printable version of
74e1a04b
NC
610 the given section's name. Like print_symbol, except that it does not try
611 to print multibyte characters, it just interprets them as hex values. */
612
613static const char *
dda8d76d 614printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec)
74e1a04b
NC
615{
616#define MAX_PRINT_SEC_NAME_LEN 128
617 static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
618 const char * name = SECTION_NAME (sec);
619 char * buf = sec_name_buf;
620 char c;
621 unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
622
623 while ((c = * name ++) != 0)
624 {
625 if (ISCNTRL (c))
626 {
627 if (remaining < 2)
628 break;
948f632f 629
74e1a04b
NC
630 * buf ++ = '^';
631 * buf ++ = c + 0x40;
632 remaining -= 2;
633 }
634 else if (ISPRINT (c))
635 {
636 * buf ++ = c;
637 remaining -= 1;
638 }
639 else
640 {
641 static char hex[17] = "0123456789ABCDEF";
642
643 if (remaining < 4)
644 break;
645 * buf ++ = '<';
646 * buf ++ = hex[(c & 0xf0) >> 4];
647 * buf ++ = hex[c & 0x0f];
648 * buf ++ = '>';
649 remaining -= 4;
650 }
651
652 if (remaining == 0)
653 break;
654 }
655
656 * buf = 0;
657 return sec_name_buf;
658}
659
660static const char *
dda8d76d 661printable_section_name_from_index (Filedata * filedata, unsigned long ndx)
74e1a04b 662{
dda8d76d 663 if (ndx >= filedata->file_header.e_shnum)
74e1a04b
NC
664 return _("<corrupt>");
665
dda8d76d 666 return printable_section_name (filedata, filedata->section_headers + ndx);
74e1a04b
NC
667}
668
89fac5e3
RS
669/* Return a pointer to section NAME, or NULL if no such section exists. */
670
671static Elf_Internal_Shdr *
dda8d76d 672find_section (Filedata * filedata, const char * name)
89fac5e3
RS
673{
674 unsigned int i;
675
68807c3c
NC
676 if (filedata->section_headers == NULL)
677 return NULL;
dda8d76d
NC
678
679 for (i = 0; i < filedata->file_header.e_shnum; i++)
680 if (streq (SECTION_NAME (filedata->section_headers + i), name))
681 return filedata->section_headers + i;
89fac5e3
RS
682
683 return NULL;
684}
685
0b6ae522
DJ
686/* Return a pointer to a section containing ADDR, or NULL if no such
687 section exists. */
688
689static Elf_Internal_Shdr *
dda8d76d 690find_section_by_address (Filedata * filedata, bfd_vma addr)
0b6ae522
DJ
691{
692 unsigned int i;
693
68807c3c
NC
694 if (filedata->section_headers == NULL)
695 return NULL;
696
dda8d76d 697 for (i = 0; i < filedata->file_header.e_shnum; i++)
0b6ae522 698 {
dda8d76d
NC
699 Elf_Internal_Shdr *sec = filedata->section_headers + i;
700
0b6ae522
DJ
701 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
702 return sec;
703 }
704
705 return NULL;
706}
707
071436c6 708static Elf_Internal_Shdr *
dda8d76d 709find_section_by_type (Filedata * filedata, unsigned int type)
071436c6
NC
710{
711 unsigned int i;
712
68807c3c
NC
713 if (filedata->section_headers == NULL)
714 return NULL;
715
dda8d76d 716 for (i = 0; i < filedata->file_header.e_shnum; i++)
071436c6 717 {
dda8d76d
NC
718 Elf_Internal_Shdr *sec = filedata->section_headers + i;
719
071436c6
NC
720 if (sec->sh_type == type)
721 return sec;
722 }
723
724 return NULL;
725}
726
657d0d47
CC
727/* Return a pointer to section NAME, or NULL if no such section exists,
728 restricted to the list of sections given in SET. */
729
730static Elf_Internal_Shdr *
dda8d76d 731find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
657d0d47
CC
732{
733 unsigned int i;
734
68807c3c
NC
735 if (filedata->section_headers == NULL)
736 return NULL;
737
657d0d47
CC
738 if (set != NULL)
739 {
740 while ((i = *set++) > 0)
b814a36d
NC
741 {
742 /* See PR 21156 for a reproducer. */
dda8d76d 743 if (i >= filedata->file_header.e_shnum)
b814a36d
NC
744 continue; /* FIXME: Should we issue an error message ? */
745
dda8d76d
NC
746 if (streq (SECTION_NAME (filedata->section_headers + i), name))
747 return filedata->section_headers + i;
b814a36d 748 }
657d0d47
CC
749 }
750
dda8d76d 751 return find_section (filedata, name);
657d0d47
CC
752}
753
32ec8896
NC
754/* Read an unsigned LEB128 encoded value from DATA.
755 Set *LENGTH_RETURN to the number of bytes read. */
0b6ae522 756
f6f0e17b 757static inline unsigned long
32ec8896
NC
758read_uleb128 (unsigned char * data,
759 unsigned int * length_return,
f6f0e17b 760 const unsigned char * const end)
0b6ae522 761{
f6f0e17b 762 return read_leb128 (data, length_return, FALSE, end);
0b6ae522
DJ
763}
764
32ec8896 765/* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
28f997cf
TG
766 This OS has so many departures from the ELF standard that we test it at
767 many places. */
768
32ec8896 769static inline bfd_boolean
dda8d76d 770is_ia64_vms (Filedata * filedata)
28f997cf 771{
dda8d76d
NC
772 return filedata->file_header.e_machine == EM_IA_64
773 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
28f997cf
TG
774}
775
bcedfee6 776/* Guess the relocation size commonly used by the specific machines. */
252b5132 777
32ec8896 778static bfd_boolean
2dc4cec1 779guess_is_rela (unsigned int e_machine)
252b5132 780{
9c19a809 781 switch (e_machine)
252b5132
RH
782 {
783 /* Targets that use REL relocations. */
252b5132 784 case EM_386:
22abe556 785 case EM_IAMCU:
f954747f 786 case EM_960:
e9f53129 787 case EM_ARM:
2b0337b0 788 case EM_D10V:
252b5132 789 case EM_CYGNUS_D10V:
e9f53129 790 case EM_DLX:
252b5132 791 case EM_MIPS:
4fe85591 792 case EM_MIPS_RS3_LE:
e9f53129 793 case EM_CYGNUS_M32R:
1c0d3aa6 794 case EM_SCORE:
f6c1a2d5 795 case EM_XGATE:
fe944acf 796 case EM_NFP:
aca4efc7 797 case EM_BPF:
9c19a809 798 return FALSE;
103f02d3 799
252b5132
RH
800 /* Targets that use RELA relocations. */
801 case EM_68K:
f954747f 802 case EM_860:
a06ea964 803 case EM_AARCH64:
cfb8c092 804 case EM_ADAPTEVA_EPIPHANY:
e9f53129
AM
805 case EM_ALPHA:
806 case EM_ALTERA_NIOS2:
886a2506
NC
807 case EM_ARC:
808 case EM_ARC_COMPACT:
809 case EM_ARC_COMPACT2:
e9f53129
AM
810 case EM_AVR:
811 case EM_AVR_OLD:
812 case EM_BLACKFIN:
60bca95a 813 case EM_CR16:
e9f53129
AM
814 case EM_CRIS:
815 case EM_CRX:
b8891f8d 816 case EM_CSKY:
2b0337b0 817 case EM_D30V:
252b5132 818 case EM_CYGNUS_D30V:
2b0337b0 819 case EM_FR30:
3f8107ab 820 case EM_FT32:
252b5132 821 case EM_CYGNUS_FR30:
5c70f934 822 case EM_CYGNUS_FRV:
e9f53129
AM
823 case EM_H8S:
824 case EM_H8_300:
825 case EM_H8_300H:
800eeca4 826 case EM_IA_64:
1e4cf259
NC
827 case EM_IP2K:
828 case EM_IP2K_OLD:
3b36097d 829 case EM_IQ2000:
84e94c90 830 case EM_LATTICEMICO32:
ff7eeb89 831 case EM_M32C_OLD:
49f58d10 832 case EM_M32C:
e9f53129
AM
833 case EM_M32R:
834 case EM_MCORE:
15ab5209 835 case EM_CYGNUS_MEP:
a3c62988 836 case EM_METAG:
e9f53129
AM
837 case EM_MMIX:
838 case EM_MN10200:
839 case EM_CYGNUS_MN10200:
840 case EM_MN10300:
841 case EM_CYGNUS_MN10300:
5506d11a 842 case EM_MOXIE:
e9f53129
AM
843 case EM_MSP430:
844 case EM_MSP430_OLD:
d031aafb 845 case EM_MT:
35c08157 846 case EM_NDS32:
64fd6348 847 case EM_NIOS32:
73589c9d 848 case EM_OR1K:
e9f53129
AM
849 case EM_PPC64:
850 case EM_PPC:
2b100bb5 851 case EM_TI_PRU:
e23eba97 852 case EM_RISCV:
99c513f6 853 case EM_RL78:
c7927a3c 854 case EM_RX:
e9f53129
AM
855 case EM_S390:
856 case EM_S390_OLD:
857 case EM_SH:
858 case EM_SPARC:
859 case EM_SPARC32PLUS:
860 case EM_SPARCV9:
861 case EM_SPU:
40b36596 862 case EM_TI_C6000:
aa137e4d
NC
863 case EM_TILEGX:
864 case EM_TILEPRO:
708e2187 865 case EM_V800:
e9f53129
AM
866 case EM_V850:
867 case EM_CYGNUS_V850:
868 case EM_VAX:
619ed720 869 case EM_VISIUM:
e9f53129 870 case EM_X86_64:
8a9036a4 871 case EM_L1OM:
7a9068fe 872 case EM_K1OM:
e9f53129
AM
873 case EM_XSTORMY16:
874 case EM_XTENSA:
875 case EM_XTENSA_OLD:
7ba29e2a
NC
876 case EM_MICROBLAZE:
877 case EM_MICROBLAZE_OLD:
f96bd6c2 878 case EM_WEBASSEMBLY:
9c19a809 879 return TRUE;
103f02d3 880
e9f53129
AM
881 case EM_68HC05:
882 case EM_68HC08:
883 case EM_68HC11:
884 case EM_68HC16:
885 case EM_FX66:
886 case EM_ME16:
d1133906 887 case EM_MMA:
d1133906
NC
888 case EM_NCPU:
889 case EM_NDR1:
e9f53129 890 case EM_PCP:
d1133906 891 case EM_ST100:
e9f53129 892 case EM_ST19:
d1133906 893 case EM_ST7:
e9f53129
AM
894 case EM_ST9PLUS:
895 case EM_STARCORE:
d1133906 896 case EM_SVX:
e9f53129 897 case EM_TINYJ:
9c19a809
NC
898 default:
899 warn (_("Don't know about relocations on this machine architecture\n"));
900 return FALSE;
901 }
902}
252b5132 903
dda8d76d 904/* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
32ec8896
NC
905 Returns TRUE upon success, FALSE otherwise. If successful then a
906 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
907 and the number of relocs loaded is placed in *NRELASP. It is the caller's
908 responsibility to free the allocated buffer. */
909
910static bfd_boolean
dda8d76d
NC
911slurp_rela_relocs (Filedata * filedata,
912 unsigned long rel_offset,
913 unsigned long rel_size,
914 Elf_Internal_Rela ** relasp,
915 unsigned long * nrelasp)
9c19a809 916{
2cf0635d 917 Elf_Internal_Rela * relas;
8b73c356 918 size_t nrelas;
4d6ed7c8 919 unsigned int i;
252b5132 920
4d6ed7c8
NC
921 if (is_32bit_elf)
922 {
2cf0635d 923 Elf32_External_Rela * erelas;
103f02d3 924
dda8d76d 925 erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 926 rel_size, _("32-bit relocation data"));
a6e9f9df 927 if (!erelas)
32ec8896 928 return FALSE;
252b5132 929
4d6ed7c8 930 nrelas = rel_size / sizeof (Elf32_External_Rela);
103f02d3 931
3f5e193b
NC
932 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
933 sizeof (Elf_Internal_Rela));
103f02d3 934
4d6ed7c8
NC
935 if (relas == NULL)
936 {
c256ffe7 937 free (erelas);
591a748a 938 error (_("out of memory parsing relocs\n"));
32ec8896 939 return FALSE;
4d6ed7c8 940 }
103f02d3 941
4d6ed7c8
NC
942 for (i = 0; i < nrelas; i++)
943 {
944 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
945 relas[i].r_info = BYTE_GET (erelas[i].r_info);
598aaa76 946 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
4d6ed7c8 947 }
103f02d3 948
4d6ed7c8
NC
949 free (erelas);
950 }
951 else
952 {
2cf0635d 953 Elf64_External_Rela * erelas;
103f02d3 954
dda8d76d 955 erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 956 rel_size, _("64-bit relocation data"));
a6e9f9df 957 if (!erelas)
32ec8896 958 return FALSE;
4d6ed7c8
NC
959
960 nrelas = rel_size / sizeof (Elf64_External_Rela);
103f02d3 961
3f5e193b
NC
962 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
963 sizeof (Elf_Internal_Rela));
103f02d3 964
4d6ed7c8
NC
965 if (relas == NULL)
966 {
c256ffe7 967 free (erelas);
591a748a 968 error (_("out of memory parsing relocs\n"));
32ec8896 969 return FALSE;
9c19a809 970 }
4d6ed7c8
NC
971
972 for (i = 0; i < nrelas; i++)
9c19a809 973 {
66543521
AM
974 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
975 relas[i].r_info = BYTE_GET (erelas[i].r_info);
598aaa76 976 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
861fb55a
DJ
977
978 /* The #ifdef BFD64 below is to prevent a compile time
979 warning. We know that if we do not have a 64 bit data
980 type that we will never execute this code anyway. */
981#ifdef BFD64
dda8d76d
NC
982 if (filedata->file_header.e_machine == EM_MIPS
983 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
861fb55a
DJ
984 {
985 /* In little-endian objects, r_info isn't really a
986 64-bit little-endian value: it has a 32-bit
987 little-endian symbol index followed by four
988 individual byte fields. Reorder INFO
989 accordingly. */
91d6fa6a
NC
990 bfd_vma inf = relas[i].r_info;
991 inf = (((inf & 0xffffffff) << 32)
992 | ((inf >> 56) & 0xff)
993 | ((inf >> 40) & 0xff00)
994 | ((inf >> 24) & 0xff0000)
995 | ((inf >> 8) & 0xff000000));
996 relas[i].r_info = inf;
861fb55a
DJ
997 }
998#endif /* BFD64 */
4d6ed7c8 999 }
103f02d3 1000
4d6ed7c8
NC
1001 free (erelas);
1002 }
32ec8896 1003
4d6ed7c8
NC
1004 *relasp = relas;
1005 *nrelasp = nrelas;
32ec8896 1006 return TRUE;
4d6ed7c8 1007}
103f02d3 1008
dda8d76d 1009/* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
32ec8896
NC
1010 Returns TRUE upon success, FALSE otherwise. If successful then a
1011 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1012 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1013 responsibility to free the allocated buffer. */
1014
1015static bfd_boolean
dda8d76d
NC
1016slurp_rel_relocs (Filedata * filedata,
1017 unsigned long rel_offset,
1018 unsigned long rel_size,
1019 Elf_Internal_Rela ** relsp,
1020 unsigned long * nrelsp)
4d6ed7c8 1021{
2cf0635d 1022 Elf_Internal_Rela * rels;
8b73c356 1023 size_t nrels;
4d6ed7c8 1024 unsigned int i;
103f02d3 1025
4d6ed7c8
NC
1026 if (is_32bit_elf)
1027 {
2cf0635d 1028 Elf32_External_Rel * erels;
103f02d3 1029
dda8d76d 1030 erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 1031 rel_size, _("32-bit relocation data"));
a6e9f9df 1032 if (!erels)
32ec8896 1033 return FALSE;
103f02d3 1034
4d6ed7c8 1035 nrels = rel_size / sizeof (Elf32_External_Rel);
103f02d3 1036
3f5e193b 1037 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
103f02d3 1038
4d6ed7c8
NC
1039 if (rels == NULL)
1040 {
c256ffe7 1041 free (erels);
591a748a 1042 error (_("out of memory parsing relocs\n"));
32ec8896 1043 return FALSE;
4d6ed7c8
NC
1044 }
1045
1046 for (i = 0; i < nrels; i++)
1047 {
1048 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1049 rels[i].r_info = BYTE_GET (erels[i].r_info);
c8286bd1 1050 rels[i].r_addend = 0;
9ea033b2 1051 }
4d6ed7c8
NC
1052
1053 free (erels);
9c19a809
NC
1054 }
1055 else
1056 {
2cf0635d 1057 Elf64_External_Rel * erels;
9ea033b2 1058
dda8d76d 1059 erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 1060 rel_size, _("64-bit relocation data"));
a6e9f9df 1061 if (!erels)
32ec8896 1062 return FALSE;
103f02d3 1063
4d6ed7c8 1064 nrels = rel_size / sizeof (Elf64_External_Rel);
103f02d3 1065
3f5e193b 1066 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
103f02d3 1067
4d6ed7c8 1068 if (rels == NULL)
9c19a809 1069 {
c256ffe7 1070 free (erels);
591a748a 1071 error (_("out of memory parsing relocs\n"));
32ec8896 1072 return FALSE;
4d6ed7c8 1073 }
103f02d3 1074
4d6ed7c8
NC
1075 for (i = 0; i < nrels; i++)
1076 {
66543521
AM
1077 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1078 rels[i].r_info = BYTE_GET (erels[i].r_info);
c8286bd1 1079 rels[i].r_addend = 0;
861fb55a
DJ
1080
1081 /* The #ifdef BFD64 below is to prevent a compile time
1082 warning. We know that if we do not have a 64 bit data
1083 type that we will never execute this code anyway. */
1084#ifdef BFD64
dda8d76d
NC
1085 if (filedata->file_header.e_machine == EM_MIPS
1086 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
861fb55a
DJ
1087 {
1088 /* In little-endian objects, r_info isn't really a
1089 64-bit little-endian value: it has a 32-bit
1090 little-endian symbol index followed by four
1091 individual byte fields. Reorder INFO
1092 accordingly. */
91d6fa6a
NC
1093 bfd_vma inf = rels[i].r_info;
1094 inf = (((inf & 0xffffffff) << 32)
1095 | ((inf >> 56) & 0xff)
1096 | ((inf >> 40) & 0xff00)
1097 | ((inf >> 24) & 0xff0000)
1098 | ((inf >> 8) & 0xff000000));
1099 rels[i].r_info = inf;
861fb55a
DJ
1100 }
1101#endif /* BFD64 */
4d6ed7c8 1102 }
103f02d3 1103
4d6ed7c8
NC
1104 free (erels);
1105 }
32ec8896 1106
4d6ed7c8
NC
1107 *relsp = rels;
1108 *nrelsp = nrels;
32ec8896 1109 return TRUE;
4d6ed7c8 1110}
103f02d3 1111
aca88567
NC
1112/* Returns the reloc type extracted from the reloc info field. */
1113
1114static unsigned int
dda8d76d 1115get_reloc_type (Filedata * filedata, bfd_vma reloc_info)
aca88567
NC
1116{
1117 if (is_32bit_elf)
1118 return ELF32_R_TYPE (reloc_info);
1119
dda8d76d 1120 switch (filedata->file_header.e_machine)
aca88567
NC
1121 {
1122 case EM_MIPS:
1123 /* Note: We assume that reloc_info has already been adjusted for us. */
1124 return ELF64_MIPS_R_TYPE (reloc_info);
1125
1126 case EM_SPARCV9:
1127 return ELF64_R_TYPE_ID (reloc_info);
1128
1129 default:
1130 return ELF64_R_TYPE (reloc_info);
1131 }
1132}
1133
1134/* Return the symbol index extracted from the reloc info field. */
1135
1136static bfd_vma
1137get_reloc_symindex (bfd_vma reloc_info)
1138{
1139 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
1140}
1141
13761a11 1142static inline bfd_boolean
dda8d76d 1143uses_msp430x_relocs (Filedata * filedata)
13761a11
NC
1144{
1145 return
dda8d76d 1146 filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */
13761a11 1147 /* GCC uses osabi == ELFOSBI_STANDALONE. */
dda8d76d 1148 && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
13761a11 1149 /* TI compiler uses ELFOSABI_NONE. */
dda8d76d 1150 || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
13761a11
NC
1151}
1152
d3ba0551
AM
1153/* Display the contents of the relocation data found at the specified
1154 offset. */
ee42cf8c 1155
32ec8896 1156static bfd_boolean
dda8d76d
NC
1157dump_relocations (Filedata * filedata,
1158 unsigned long rel_offset,
1159 unsigned long rel_size,
1160 Elf_Internal_Sym * symtab,
1161 unsigned long nsyms,
1162 char * strtab,
1163 unsigned long strtablen,
1164 int is_rela,
1165 bfd_boolean is_dynsym)
4d6ed7c8 1166{
32ec8896 1167 unsigned long i;
2cf0635d 1168 Elf_Internal_Rela * rels;
32ec8896 1169 bfd_boolean res = TRUE;
103f02d3 1170
4d6ed7c8 1171 if (is_rela == UNKNOWN)
dda8d76d 1172 is_rela = guess_is_rela (filedata->file_header.e_machine);
103f02d3 1173
4d6ed7c8
NC
1174 if (is_rela)
1175 {
dda8d76d 1176 if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
32ec8896 1177 return FALSE;
4d6ed7c8
NC
1178 }
1179 else
1180 {
dda8d76d 1181 if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
32ec8896 1182 return FALSE;
252b5132
RH
1183 }
1184
410f7a12
L
1185 if (is_32bit_elf)
1186 {
1187 if (is_rela)
2c71103e
NC
1188 {
1189 if (do_wide)
1190 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1191 else
1192 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1193 }
410f7a12 1194 else
2c71103e
NC
1195 {
1196 if (do_wide)
1197 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1198 else
1199 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1200 }
410f7a12 1201 }
252b5132 1202 else
410f7a12
L
1203 {
1204 if (is_rela)
2c71103e
NC
1205 {
1206 if (do_wide)
8beeaeb7 1207 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
2c71103e
NC
1208 else
1209 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1210 }
410f7a12 1211 else
2c71103e
NC
1212 {
1213 if (do_wide)
8beeaeb7 1214 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
2c71103e
NC
1215 else
1216 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1217 }
410f7a12 1218 }
252b5132
RH
1219
1220 for (i = 0; i < rel_size; i++)
1221 {
2cf0635d 1222 const char * rtype;
b34976b6 1223 bfd_vma offset;
91d6fa6a 1224 bfd_vma inf;
b34976b6
AM
1225 bfd_vma symtab_index;
1226 bfd_vma type;
103f02d3 1227
b34976b6 1228 offset = rels[i].r_offset;
91d6fa6a 1229 inf = rels[i].r_info;
103f02d3 1230
dda8d76d 1231 type = get_reloc_type (filedata, inf);
91d6fa6a 1232 symtab_index = get_reloc_symindex (inf);
252b5132 1233
410f7a12
L
1234 if (is_32bit_elf)
1235 {
39dbeff8
AM
1236 printf ("%8.8lx %8.8lx ",
1237 (unsigned long) offset & 0xffffffff,
91d6fa6a 1238 (unsigned long) inf & 0xffffffff);
410f7a12
L
1239 }
1240 else
1241 {
39dbeff8
AM
1242#if BFD_HOST_64BIT_LONG
1243 printf (do_wide
1244 ? "%16.16lx %16.16lx "
1245 : "%12.12lx %12.12lx ",
91d6fa6a 1246 offset, inf);
39dbeff8 1247#elif BFD_HOST_64BIT_LONG_LONG
6e3d6dc1 1248#ifndef __MSVCRT__
39dbeff8
AM
1249 printf (do_wide
1250 ? "%16.16llx %16.16llx "
1251 : "%12.12llx %12.12llx ",
91d6fa6a 1252 offset, inf);
6e3d6dc1
NC
1253#else
1254 printf (do_wide
1255 ? "%16.16I64x %16.16I64x "
1256 : "%12.12I64x %12.12I64x ",
91d6fa6a 1257 offset, inf);
6e3d6dc1 1258#endif
39dbeff8 1259#else
2c71103e
NC
1260 printf (do_wide
1261 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1262 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
410f7a12
L
1263 _bfd_int64_high (offset),
1264 _bfd_int64_low (offset),
91d6fa6a
NC
1265 _bfd_int64_high (inf),
1266 _bfd_int64_low (inf));
9ea033b2 1267#endif
410f7a12 1268 }
103f02d3 1269
dda8d76d 1270 switch (filedata->file_header.e_machine)
252b5132
RH
1271 {
1272 default:
1273 rtype = NULL;
1274 break;
1275
a06ea964
NC
1276 case EM_AARCH64:
1277 rtype = elf_aarch64_reloc_type (type);
1278 break;
1279
2b0337b0 1280 case EM_M32R:
252b5132 1281 case EM_CYGNUS_M32R:
9ea033b2 1282 rtype = elf_m32r_reloc_type (type);
252b5132
RH
1283 break;
1284
1285 case EM_386:
22abe556 1286 case EM_IAMCU:
9ea033b2 1287 rtype = elf_i386_reloc_type (type);
252b5132
RH
1288 break;
1289
ba2685cc
AM
1290 case EM_68HC11:
1291 case EM_68HC12:
1292 rtype = elf_m68hc11_reloc_type (type);
1293 break;
75751cd9 1294
7b4ae824
JD
1295 case EM_S12Z:
1296 rtype = elf_s12z_reloc_type (type);
1297 break;
1298
252b5132 1299 case EM_68K:
9ea033b2 1300 rtype = elf_m68k_reloc_type (type);
252b5132
RH
1301 break;
1302
f954747f
AM
1303 case EM_960:
1304 rtype = elf_i960_reloc_type (type);
1305 break;
1306
adde6300 1307 case EM_AVR:
2b0337b0 1308 case EM_AVR_OLD:
adde6300
AM
1309 rtype = elf_avr_reloc_type (type);
1310 break;
1311
9ea033b2
NC
1312 case EM_OLD_SPARCV9:
1313 case EM_SPARC32PLUS:
1314 case EM_SPARCV9:
252b5132 1315 case EM_SPARC:
9ea033b2 1316 rtype = elf_sparc_reloc_type (type);
252b5132
RH
1317 break;
1318
e9f53129
AM
1319 case EM_SPU:
1320 rtype = elf_spu_reloc_type (type);
1321 break;
1322
708e2187
NC
1323 case EM_V800:
1324 rtype = v800_reloc_type (type);
1325 break;
2b0337b0 1326 case EM_V850:
252b5132 1327 case EM_CYGNUS_V850:
9ea033b2 1328 rtype = v850_reloc_type (type);
252b5132
RH
1329 break;
1330
2b0337b0 1331 case EM_D10V:
252b5132 1332 case EM_CYGNUS_D10V:
9ea033b2 1333 rtype = elf_d10v_reloc_type (type);
252b5132
RH
1334 break;
1335
2b0337b0 1336 case EM_D30V:
252b5132 1337 case EM_CYGNUS_D30V:
9ea033b2 1338 rtype = elf_d30v_reloc_type (type);
252b5132
RH
1339 break;
1340
d172d4ba
NC
1341 case EM_DLX:
1342 rtype = elf_dlx_reloc_type (type);
1343 break;
1344
252b5132 1345 case EM_SH:
9ea033b2 1346 rtype = elf_sh_reloc_type (type);
252b5132
RH
1347 break;
1348
2b0337b0 1349 case EM_MN10300:
252b5132 1350 case EM_CYGNUS_MN10300:
9ea033b2 1351 rtype = elf_mn10300_reloc_type (type);
252b5132
RH
1352 break;
1353
2b0337b0 1354 case EM_MN10200:
252b5132 1355 case EM_CYGNUS_MN10200:
9ea033b2 1356 rtype = elf_mn10200_reloc_type (type);
252b5132
RH
1357 break;
1358
2b0337b0 1359 case EM_FR30:
252b5132 1360 case EM_CYGNUS_FR30:
9ea033b2 1361 rtype = elf_fr30_reloc_type (type);
252b5132
RH
1362 break;
1363
ba2685cc
AM
1364 case EM_CYGNUS_FRV:
1365 rtype = elf_frv_reloc_type (type);
1366 break;
5c70f934 1367
b8891f8d
AJ
1368 case EM_CSKY:
1369 rtype = elf_csky_reloc_type (type);
1370 break;
1371
3f8107ab
AM
1372 case EM_FT32:
1373 rtype = elf_ft32_reloc_type (type);
1374 break;
1375
252b5132 1376 case EM_MCORE:
9ea033b2 1377 rtype = elf_mcore_reloc_type (type);
252b5132
RH
1378 break;
1379
3c3bdf30
NC
1380 case EM_MMIX:
1381 rtype = elf_mmix_reloc_type (type);
1382 break;
1383
5506d11a
AM
1384 case EM_MOXIE:
1385 rtype = elf_moxie_reloc_type (type);
1386 break;
1387
2469cfa2 1388 case EM_MSP430:
dda8d76d 1389 if (uses_msp430x_relocs (filedata))
13761a11
NC
1390 {
1391 rtype = elf_msp430x_reloc_type (type);
1392 break;
1393 }
1a0670f3 1394 /* Fall through. */
2469cfa2
NC
1395 case EM_MSP430_OLD:
1396 rtype = elf_msp430_reloc_type (type);
1397 break;
1398
35c08157
KLC
1399 case EM_NDS32:
1400 rtype = elf_nds32_reloc_type (type);
1401 break;
1402
252b5132 1403 case EM_PPC:
9ea033b2 1404 rtype = elf_ppc_reloc_type (type);
252b5132
RH
1405 break;
1406
c833c019
AM
1407 case EM_PPC64:
1408 rtype = elf_ppc64_reloc_type (type);
1409 break;
1410
252b5132 1411 case EM_MIPS:
4fe85591 1412 case EM_MIPS_RS3_LE:
9ea033b2 1413 rtype = elf_mips_reloc_type (type);
252b5132
RH
1414 break;
1415
e23eba97
NC
1416 case EM_RISCV:
1417 rtype = elf_riscv_reloc_type (type);
1418 break;
1419
252b5132 1420 case EM_ALPHA:
9ea033b2 1421 rtype = elf_alpha_reloc_type (type);
252b5132
RH
1422 break;
1423
1424 case EM_ARM:
9ea033b2 1425 rtype = elf_arm_reloc_type (type);
252b5132
RH
1426 break;
1427
584da044 1428 case EM_ARC:
886a2506
NC
1429 case EM_ARC_COMPACT:
1430 case EM_ARC_COMPACT2:
9ea033b2 1431 rtype = elf_arc_reloc_type (type);
252b5132
RH
1432 break;
1433
1434 case EM_PARISC:
69e617ca 1435 rtype = elf_hppa_reloc_type (type);
252b5132 1436 break;
7d466069 1437
b8720f9d
JL
1438 case EM_H8_300:
1439 case EM_H8_300H:
1440 case EM_H8S:
1441 rtype = elf_h8_reloc_type (type);
1442 break;
1443
73589c9d
CS
1444 case EM_OR1K:
1445 rtype = elf_or1k_reloc_type (type);
3b16e843
NC
1446 break;
1447
7d466069 1448 case EM_PJ:
2b0337b0 1449 case EM_PJ_OLD:
7d466069
ILT
1450 rtype = elf_pj_reloc_type (type);
1451 break;
800eeca4
JW
1452 case EM_IA_64:
1453 rtype = elf_ia64_reloc_type (type);
1454 break;
1b61cf92
HPN
1455
1456 case EM_CRIS:
1457 rtype = elf_cris_reloc_type (type);
1458 break;
535c37ff 1459
f954747f
AM
1460 case EM_860:
1461 rtype = elf_i860_reloc_type (type);
1462 break;
1463
bcedfee6 1464 case EM_X86_64:
8a9036a4 1465 case EM_L1OM:
7a9068fe 1466 case EM_K1OM:
bcedfee6
NC
1467 rtype = elf_x86_64_reloc_type (type);
1468 break;
a85d7ed0 1469
f954747f
AM
1470 case EM_S370:
1471 rtype = i370_reloc_type (type);
1472 break;
1473
53c7db4b
KH
1474 case EM_S390_OLD:
1475 case EM_S390:
1476 rtype = elf_s390_reloc_type (type);
1477 break;
93fbbb04 1478
1c0d3aa6
NC
1479 case EM_SCORE:
1480 rtype = elf_score_reloc_type (type);
1481 break;
1482
93fbbb04
GK
1483 case EM_XSTORMY16:
1484 rtype = elf_xstormy16_reloc_type (type);
1485 break;
179d3252 1486
1fe1f39c
NC
1487 case EM_CRX:
1488 rtype = elf_crx_reloc_type (type);
1489 break;
1490
179d3252
JT
1491 case EM_VAX:
1492 rtype = elf_vax_reloc_type (type);
1493 break;
1e4cf259 1494
619ed720
EB
1495 case EM_VISIUM:
1496 rtype = elf_visium_reloc_type (type);
1497 break;
1498
aca4efc7
JM
1499 case EM_BPF:
1500 rtype = elf_bpf_reloc_type (type);
1501 break;
1502
cfb8c092
NC
1503 case EM_ADAPTEVA_EPIPHANY:
1504 rtype = elf_epiphany_reloc_type (type);
1505 break;
1506
1e4cf259
NC
1507 case EM_IP2K:
1508 case EM_IP2K_OLD:
1509 rtype = elf_ip2k_reloc_type (type);
1510 break;
3b36097d
SC
1511
1512 case EM_IQ2000:
1513 rtype = elf_iq2000_reloc_type (type);
1514 break;
88da6820
NC
1515
1516 case EM_XTENSA_OLD:
1517 case EM_XTENSA:
1518 rtype = elf_xtensa_reloc_type (type);
1519 break;
a34e3ecb 1520
84e94c90
NC
1521 case EM_LATTICEMICO32:
1522 rtype = elf_lm32_reloc_type (type);
1523 break;
1524
ff7eeb89 1525 case EM_M32C_OLD:
49f58d10
JB
1526 case EM_M32C:
1527 rtype = elf_m32c_reloc_type (type);
1528 break;
1529
d031aafb
NS
1530 case EM_MT:
1531 rtype = elf_mt_reloc_type (type);
a34e3ecb 1532 break;
1d65ded4
CM
1533
1534 case EM_BLACKFIN:
1535 rtype = elf_bfin_reloc_type (type);
1536 break;
15ab5209
DB
1537
1538 case EM_CYGNUS_MEP:
1539 rtype = elf_mep_reloc_type (type);
1540 break;
60bca95a
NC
1541
1542 case EM_CR16:
1543 rtype = elf_cr16_reloc_type (type);
1544 break;
dd24e3da 1545
7ba29e2a
NC
1546 case EM_MICROBLAZE:
1547 case EM_MICROBLAZE_OLD:
1548 rtype = elf_microblaze_reloc_type (type);
1549 break;
c7927a3c 1550
99c513f6
DD
1551 case EM_RL78:
1552 rtype = elf_rl78_reloc_type (type);
1553 break;
1554
c7927a3c
NC
1555 case EM_RX:
1556 rtype = elf_rx_reloc_type (type);
1557 break;
c29aca4a 1558
a3c62988
NC
1559 case EM_METAG:
1560 rtype = elf_metag_reloc_type (type);
1561 break;
1562
c29aca4a
NC
1563 case EM_XC16X:
1564 case EM_C166:
1565 rtype = elf_xc16x_reloc_type (type);
1566 break;
40b36596
JM
1567
1568 case EM_TI_C6000:
1569 rtype = elf_tic6x_reloc_type (type);
1570 break;
aa137e4d
NC
1571
1572 case EM_TILEGX:
1573 rtype = elf_tilegx_reloc_type (type);
1574 break;
1575
1576 case EM_TILEPRO:
1577 rtype = elf_tilepro_reloc_type (type);
1578 break;
f6c1a2d5 1579
f96bd6c2
PC
1580 case EM_WEBASSEMBLY:
1581 rtype = elf_wasm32_reloc_type (type);
1582 break;
1583
f6c1a2d5
NC
1584 case EM_XGATE:
1585 rtype = elf_xgate_reloc_type (type);
1586 break;
36591ba1
SL
1587
1588 case EM_ALTERA_NIOS2:
1589 rtype = elf_nios2_reloc_type (type);
1590 break;
2b100bb5
DD
1591
1592 case EM_TI_PRU:
1593 rtype = elf_pru_reloc_type (type);
1594 break;
fe944acf
FT
1595
1596 case EM_NFP:
1597 if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200)
1598 rtype = elf_nfp3200_reloc_type (type);
1599 else
1600 rtype = elf_nfp_reloc_type (type);
1601 break;
abeeff98
LM
1602
1603 case EM_AMDGPU:
1604 rtype = elf_amdgcn_reloc_type (type);
1605 break;
252b5132
RH
1606 }
1607
1608 if (rtype == NULL)
39dbeff8 1609 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
252b5132 1610 else
5c144731 1611 printf (do_wide ? "%-22s" : "%-17.17s", rtype);
252b5132 1612
dda8d76d 1613 if (filedata->file_header.e_machine == EM_ALPHA
157c2599 1614 && rtype != NULL
7ace3541
RH
1615 && streq (rtype, "R_ALPHA_LITUSE")
1616 && is_rela)
1617 {
1618 switch (rels[i].r_addend)
1619 {
1620 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1621 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1622 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1623 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1624 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1625 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1626 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1627 default: rtype = NULL;
1628 }
32ec8896 1629
7ace3541
RH
1630 if (rtype)
1631 printf (" (%s)", rtype);
1632 else
1633 {
1634 putchar (' ');
1635 printf (_("<unknown addend: %lx>"),
1636 (unsigned long) rels[i].r_addend);
32ec8896 1637 res = FALSE;
7ace3541
RH
1638 }
1639 }
1640 else if (symtab_index)
252b5132 1641 {
af3fc3bc 1642 if (symtab == NULL || symtab_index >= nsyms)
32ec8896
NC
1643 {
1644 error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index);
1645 res = FALSE;
1646 }
af3fc3bc 1647 else
19936277 1648 {
2cf0635d 1649 Elf_Internal_Sym * psym;
bb4d2ac2
L
1650 const char * version_string;
1651 enum versioned_symbol_info sym_info;
1652 unsigned short vna_other;
19936277 1653
af3fc3bc 1654 psym = symtab + symtab_index;
103f02d3 1655
bb4d2ac2 1656 version_string
dda8d76d 1657 = get_symbol_version_string (filedata, is_dynsym,
bb4d2ac2
L
1658 strtab, strtablen,
1659 symtab_index,
1660 psym,
1661 &sym_info,
1662 &vna_other);
1663
af3fc3bc 1664 printf (" ");
171191ba 1665
d8045f23
NC
1666 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
1667 {
1668 const char * name;
1669 unsigned int len;
1670 unsigned int width = is_32bit_elf ? 8 : 14;
1671
1672 /* Relocations against GNU_IFUNC symbols do not use the value
1673 of the symbol as the address to relocate against. Instead
1674 they invoke the function named by the symbol and use its
1675 result as the address for relocation.
1676
1677 To indicate this to the user, do not display the value of
1678 the symbol in the "Symbols's Value" field. Instead show
1679 its name followed by () as a hint that the symbol is
1680 invoked. */
1681
1682 if (strtab == NULL
1683 || psym->st_name == 0
1684 || psym->st_name >= strtablen)
1685 name = "??";
1686 else
1687 name = strtab + psym->st_name;
1688
1689 len = print_symbol (width, name);
bb4d2ac2
L
1690 if (version_string)
1691 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1692 version_string);
d8045f23
NC
1693 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
1694 }
1695 else
1696 {
1697 print_vma (psym->st_value, LONG_HEX);
171191ba 1698
d8045f23
NC
1699 printf (is_32bit_elf ? " " : " ");
1700 }
103f02d3 1701
af3fc3bc 1702 if (psym->st_name == 0)
f1ef08cb 1703 {
2cf0635d 1704 const char * sec_name = "<null>";
f1ef08cb
AM
1705 char name_buf[40];
1706
1707 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1708 {
dda8d76d
NC
1709 if (psym->st_shndx < filedata->file_header.e_shnum)
1710 sec_name = SECTION_NAME (filedata->section_headers + psym->st_shndx);
f1ef08cb
AM
1711 else if (psym->st_shndx == SHN_ABS)
1712 sec_name = "ABS";
1713 else if (psym->st_shndx == SHN_COMMON)
1714 sec_name = "COMMON";
dda8d76d 1715 else if ((filedata->file_header.e_machine == EM_MIPS
ac145307 1716 && psym->st_shndx == SHN_MIPS_SCOMMON)
dda8d76d 1717 || (filedata->file_header.e_machine == EM_TI_C6000
ac145307 1718 && psym->st_shndx == SHN_TIC6X_SCOMMON))
172553c7 1719 sec_name = "SCOMMON";
dda8d76d 1720 else if (filedata->file_header.e_machine == EM_MIPS
172553c7
TS
1721 && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1722 sec_name = "SUNDEF";
dda8d76d
NC
1723 else if ((filedata->file_header.e_machine == EM_X86_64
1724 || filedata->file_header.e_machine == EM_L1OM
1725 || filedata->file_header.e_machine == EM_K1OM)
3b22753a
L
1726 && psym->st_shndx == SHN_X86_64_LCOMMON)
1727 sec_name = "LARGE_COMMON";
dda8d76d
NC
1728 else if (filedata->file_header.e_machine == EM_IA_64
1729 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
9ce701e2
L
1730 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1731 sec_name = "ANSI_COM";
dda8d76d 1732 else if (is_ia64_vms (filedata)
148b93f2
NC
1733 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
1734 sec_name = "VMS_SYMVEC";
f1ef08cb
AM
1735 else
1736 {
1737 sprintf (name_buf, "<section 0x%x>",
1738 (unsigned int) psym->st_shndx);
1739 sec_name = name_buf;
1740 }
1741 }
1742 print_symbol (22, sec_name);
1743 }
af3fc3bc 1744 else if (strtab == NULL)
d79b3d50 1745 printf (_("<string table index: %3ld>"), psym->st_name);
c256ffe7 1746 else if (psym->st_name >= strtablen)
32ec8896
NC
1747 {
1748 error (_("<corrupt string table index: %3ld>"), psym->st_name);
1749 res = FALSE;
1750 }
af3fc3bc 1751 else
bb4d2ac2
L
1752 {
1753 print_symbol (22, strtab + psym->st_name);
1754 if (version_string)
1755 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1756 version_string);
1757 }
103f02d3 1758
af3fc3bc 1759 if (is_rela)
171191ba 1760 {
7360e63f 1761 bfd_vma off = rels[i].r_addend;
171191ba 1762
7360e63f 1763 if ((bfd_signed_vma) off < 0)
598aaa76 1764 printf (" - %" BFD_VMA_FMT "x", - off);
171191ba 1765 else
598aaa76 1766 printf (" + %" BFD_VMA_FMT "x", off);
171191ba 1767 }
19936277 1768 }
252b5132 1769 }
1b228002 1770 else if (is_rela)
f7a99963 1771 {
7360e63f 1772 bfd_vma off = rels[i].r_addend;
e04d7088
L
1773
1774 printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
7360e63f 1775 if ((bfd_signed_vma) off < 0)
e04d7088
L
1776 printf ("-%" BFD_VMA_FMT "x", - off);
1777 else
1778 printf ("%" BFD_VMA_FMT "x", off);
f7a99963 1779 }
252b5132 1780
dda8d76d 1781 if (filedata->file_header.e_machine == EM_SPARCV9
157c2599
NC
1782 && rtype != NULL
1783 && streq (rtype, "R_SPARC_OLO10"))
91d6fa6a 1784 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
351b4b40 1785
252b5132 1786 putchar ('\n');
2c71103e 1787
aca88567 1788#ifdef BFD64
dda8d76d 1789 if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
2c71103e 1790 {
91d6fa6a
NC
1791 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
1792 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
2cf0635d
NC
1793 const char * rtype2 = elf_mips_reloc_type (type2);
1794 const char * rtype3 = elf_mips_reloc_type (type3);
aca88567 1795
2c71103e
NC
1796 printf (" Type2: ");
1797
1798 if (rtype2 == NULL)
39dbeff8
AM
1799 printf (_("unrecognized: %-7lx"),
1800 (unsigned long) type2 & 0xffffffff);
2c71103e
NC
1801 else
1802 printf ("%-17.17s", rtype2);
1803
18bd398b 1804 printf ("\n Type3: ");
2c71103e
NC
1805
1806 if (rtype3 == NULL)
39dbeff8
AM
1807 printf (_("unrecognized: %-7lx"),
1808 (unsigned long) type3 & 0xffffffff);
2c71103e
NC
1809 else
1810 printf ("%-17.17s", rtype3);
1811
53c7db4b 1812 putchar ('\n');
2c71103e 1813 }
aca88567 1814#endif /* BFD64 */
252b5132
RH
1815 }
1816
c8286bd1 1817 free (rels);
32ec8896
NC
1818
1819 return res;
252b5132
RH
1820}
1821
37c18eed
SD
1822static const char *
1823get_aarch64_dynamic_type (unsigned long type)
1824{
1825 switch (type)
1826 {
1827 case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT";
1dbade74 1828 case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT";
2301ed1c 1829 case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS";
37c18eed
SD
1830 default:
1831 return NULL;
1832 }
1833}
1834
252b5132 1835static const char *
d3ba0551 1836get_mips_dynamic_type (unsigned long type)
252b5132
RH
1837{
1838 switch (type)
1839 {
1840 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1841 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1842 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1843 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1844 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1845 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1846 case DT_MIPS_MSYM: return "MIPS_MSYM";
1847 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1848 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1849 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1850 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1851 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1852 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1853 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1854 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1855 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1856 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
a5499fa4 1857 case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
252b5132
RH
1858 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1859 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1860 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1861 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1862 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1863 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1864 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1865 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1866 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1867 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1868 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1869 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1870 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1871 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1872 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1873 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1874 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1875 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1876 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1877 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1878 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1879 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1880 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1881 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1882 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1883 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
861fb55a
DJ
1884 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
1885 case DT_MIPS_RWPLT: return "MIPS_RWPLT";
f16a9783 1886 case DT_MIPS_XHASH: return "MIPS_XHASH";
252b5132
RH
1887 default:
1888 return NULL;
1889 }
1890}
1891
9a097730 1892static const char *
d3ba0551 1893get_sparc64_dynamic_type (unsigned long type)
9a097730
RH
1894{
1895 switch (type)
1896 {
1897 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1898 default:
1899 return NULL;
1900 }
103f02d3
UD
1901}
1902
7490d522
AM
1903static const char *
1904get_ppc_dynamic_type (unsigned long type)
1905{
1906 switch (type)
1907 {
a7f2871e 1908 case DT_PPC_GOT: return "PPC_GOT";
e8910a83 1909 case DT_PPC_OPT: return "PPC_OPT";
7490d522
AM
1910 default:
1911 return NULL;
1912 }
1913}
1914
f1cb7e17 1915static const char *
d3ba0551 1916get_ppc64_dynamic_type (unsigned long type)
f1cb7e17
AM
1917{
1918 switch (type)
1919 {
a7f2871e
AM
1920 case DT_PPC64_GLINK: return "PPC64_GLINK";
1921 case DT_PPC64_OPD: return "PPC64_OPD";
1922 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
e8910a83 1923 case DT_PPC64_OPT: return "PPC64_OPT";
f1cb7e17
AM
1924 default:
1925 return NULL;
1926 }
1927}
1928
103f02d3 1929static const char *
d3ba0551 1930get_parisc_dynamic_type (unsigned long type)
103f02d3
UD
1931{
1932 switch (type)
1933 {
1934 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1935 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1936 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1937 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1938 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1939 case DT_HP_PREINIT: return "HP_PREINIT";
1940 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1941 case DT_HP_NEEDED: return "HP_NEEDED";
1942 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1943 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1944 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1945 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1946 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
eec8f817
DA
1947 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1948 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1949 case DT_HP_FILTERED: return "HP_FILTERED";
1950 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1951 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1952 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1953 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1954 case DT_PLT: return "PLT";
1955 case DT_PLT_SIZE: return "PLT_SIZE";
1956 case DT_DLT: return "DLT";
1957 case DT_DLT_SIZE: return "DLT_SIZE";
103f02d3
UD
1958 default:
1959 return NULL;
1960 }
1961}
9a097730 1962
ecc51f48 1963static const char *
d3ba0551 1964get_ia64_dynamic_type (unsigned long type)
ecc51f48
NC
1965{
1966 switch (type)
1967 {
148b93f2
NC
1968 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1969 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
1970 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
1971 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
1972 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
1973 case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
1974 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
1975 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
1976 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
1977 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
1978 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
1979 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
1980 case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
1981 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
1982 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
1983 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
1984 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
1985 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
1986 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
1987 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
1988 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
1989 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
1990 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
1991 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
1992 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
1993 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
1994 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
1995 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
1996 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
1997 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
1998 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
ecc51f48
NC
1999 default:
2000 return NULL;
2001 }
2002}
2003
fd85a6a1
NC
2004static const char *
2005get_solaris_section_type (unsigned long type)
2006{
2007 switch (type)
2008 {
2009 case 0x6fffffee: return "SUNW_ancillary";
2010 case 0x6fffffef: return "SUNW_capchain";
2011 case 0x6ffffff0: return "SUNW_capinfo";
2012 case 0x6ffffff1: return "SUNW_symsort";
2013 case 0x6ffffff2: return "SUNW_tlssort";
2014 case 0x6ffffff3: return "SUNW_LDYNSYM";
2015 case 0x6ffffff4: return "SUNW_dof";
2016 case 0x6ffffff5: return "SUNW_cap";
2017 case 0x6ffffff6: return "SUNW_SIGNATURE";
2018 case 0x6ffffff7: return "SUNW_ANNOTATE";
2019 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2020 case 0x6ffffff9: return "SUNW_DEBUG";
2021 case 0x6ffffffa: return "SUNW_move";
2022 case 0x6ffffffb: return "SUNW_COMDAT";
2023 case 0x6ffffffc: return "SUNW_syminfo";
2024 case 0x6ffffffd: return "SUNW_verdef";
2025 case 0x6ffffffe: return "SUNW_verneed";
2026 case 0x6fffffff: return "SUNW_versym";
2027 case 0x70000000: return "SPARC_GOTDATA";
2028 default: return NULL;
2029 }
2030}
2031
fabcb361
RH
2032static const char *
2033get_alpha_dynamic_type (unsigned long type)
2034{
2035 switch (type)
2036 {
2037 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
32ec8896 2038 default: return NULL;
fabcb361
RH
2039 }
2040}
2041
1c0d3aa6
NC
2042static const char *
2043get_score_dynamic_type (unsigned long type)
2044{
2045 switch (type)
2046 {
2047 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
2048 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
2049 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
2050 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
2051 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
2052 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
32ec8896 2053 default: return NULL;
1c0d3aa6
NC
2054 }
2055}
2056
40b36596
JM
2057static const char *
2058get_tic6x_dynamic_type (unsigned long type)
2059{
2060 switch (type)
2061 {
2062 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
2063 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
2064 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
2065 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
2066 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
2067 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
32ec8896 2068 default: return NULL;
40b36596
JM
2069 }
2070}
1c0d3aa6 2071
36591ba1
SL
2072static const char *
2073get_nios2_dynamic_type (unsigned long type)
2074{
2075 switch (type)
2076 {
2077 case DT_NIOS2_GP: return "NIOS2_GP";
32ec8896 2078 default: return NULL;
36591ba1
SL
2079 }
2080}
2081
fd85a6a1
NC
2082static const char *
2083get_solaris_dynamic_type (unsigned long type)
2084{
2085 switch (type)
2086 {
2087 case 0x6000000d: return "SUNW_AUXILIARY";
2088 case 0x6000000e: return "SUNW_RTLDINF";
2089 case 0x6000000f: return "SUNW_FILTER";
2090 case 0x60000010: return "SUNW_CAP";
2091 case 0x60000011: return "SUNW_SYMTAB";
2092 case 0x60000012: return "SUNW_SYMSZ";
2093 case 0x60000013: return "SUNW_SORTENT";
2094 case 0x60000014: return "SUNW_SYMSORT";
2095 case 0x60000015: return "SUNW_SYMSORTSZ";
2096 case 0x60000016: return "SUNW_TLSSORT";
2097 case 0x60000017: return "SUNW_TLSSORTSZ";
2098 case 0x60000018: return "SUNW_CAPINFO";
2099 case 0x60000019: return "SUNW_STRPAD";
2100 case 0x6000001a: return "SUNW_CAPCHAIN";
2101 case 0x6000001b: return "SUNW_LDMACH";
2102 case 0x6000001d: return "SUNW_CAPCHAINENT";
2103 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2104 case 0x60000021: return "SUNW_PARENT";
2105 case 0x60000023: return "SUNW_ASLR";
2106 case 0x60000025: return "SUNW_RELAX";
2107 case 0x60000029: return "SUNW_NXHEAP";
2108 case 0x6000002b: return "SUNW_NXSTACK";
2109
2110 case 0x70000001: return "SPARC_REGISTER";
2111 case 0x7ffffffd: return "AUXILIARY";
2112 case 0x7ffffffe: return "USED";
2113 case 0x7fffffff: return "FILTER";
2114
15f205b1 2115 default: return NULL;
fd85a6a1
NC
2116 }
2117}
2118
252b5132 2119static const char *
dda8d76d 2120get_dynamic_type (Filedata * filedata, unsigned long type)
252b5132 2121{
e9e44622 2122 static char buff[64];
252b5132
RH
2123
2124 switch (type)
2125 {
2126 case DT_NULL: return "NULL";
2127 case DT_NEEDED: return "NEEDED";
2128 case DT_PLTRELSZ: return "PLTRELSZ";
2129 case DT_PLTGOT: return "PLTGOT";
2130 case DT_HASH: return "HASH";
2131 case DT_STRTAB: return "STRTAB";
2132 case DT_SYMTAB: return "SYMTAB";
2133 case DT_RELA: return "RELA";
2134 case DT_RELASZ: return "RELASZ";
2135 case DT_RELAENT: return "RELAENT";
2136 case DT_STRSZ: return "STRSZ";
2137 case DT_SYMENT: return "SYMENT";
2138 case DT_INIT: return "INIT";
2139 case DT_FINI: return "FINI";
2140 case DT_SONAME: return "SONAME";
2141 case DT_RPATH: return "RPATH";
2142 case DT_SYMBOLIC: return "SYMBOLIC";
2143 case DT_REL: return "REL";
2144 case DT_RELSZ: return "RELSZ";
2145 case DT_RELENT: return "RELENT";
2146 case DT_PLTREL: return "PLTREL";
2147 case DT_DEBUG: return "DEBUG";
2148 case DT_TEXTREL: return "TEXTREL";
2149 case DT_JMPREL: return "JMPREL";
2150 case DT_BIND_NOW: return "BIND_NOW";
2151 case DT_INIT_ARRAY: return "INIT_ARRAY";
2152 case DT_FINI_ARRAY: return "FINI_ARRAY";
2153 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
2154 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
d1133906
NC
2155 case DT_RUNPATH: return "RUNPATH";
2156 case DT_FLAGS: return "FLAGS";
2d0e6f43 2157
d1133906
NC
2158 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2159 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
6d913794 2160 case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX";
103f02d3 2161
05107a46 2162 case DT_CHECKSUM: return "CHECKSUM";
252b5132
RH
2163 case DT_PLTPADSZ: return "PLTPADSZ";
2164 case DT_MOVEENT: return "MOVEENT";
2165 case DT_MOVESZ: return "MOVESZ";
dcefbbbd 2166 case DT_FEATURE: return "FEATURE";
252b5132
RH
2167 case DT_POSFLAG_1: return "POSFLAG_1";
2168 case DT_SYMINSZ: return "SYMINSZ";
2169 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
103f02d3 2170
252b5132 2171 case DT_ADDRRNGLO: return "ADDRRNGLO";
dcefbbbd
L
2172 case DT_CONFIG: return "CONFIG";
2173 case DT_DEPAUDIT: return "DEPAUDIT";
2174 case DT_AUDIT: return "AUDIT";
2175 case DT_PLTPAD: return "PLTPAD";
2176 case DT_MOVETAB: return "MOVETAB";
252b5132 2177 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
103f02d3 2178
252b5132 2179 case DT_VERSYM: return "VERSYM";
103f02d3 2180
67a4f2b7
AO
2181 case DT_TLSDESC_GOT: return "TLSDESC_GOT";
2182 case DT_TLSDESC_PLT: return "TLSDESC_PLT";
252b5132
RH
2183 case DT_RELACOUNT: return "RELACOUNT";
2184 case DT_RELCOUNT: return "RELCOUNT";
2185 case DT_FLAGS_1: return "FLAGS_1";
2186 case DT_VERDEF: return "VERDEF";
2187 case DT_VERDEFNUM: return "VERDEFNUM";
2188 case DT_VERNEED: return "VERNEED";
2189 case DT_VERNEEDNUM: return "VERNEEDNUM";
103f02d3 2190
019148e4 2191 case DT_AUXILIARY: return "AUXILIARY";
252b5132
RH
2192 case DT_USED: return "USED";
2193 case DT_FILTER: return "FILTER";
103f02d3 2194
047b2264
JJ
2195 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
2196 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
2197 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
2198 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
2199 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
fdc90cb4 2200 case DT_GNU_HASH: return "GNU_HASH";
047b2264 2201
252b5132
RH
2202 default:
2203 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
2204 {
2cf0635d 2205 const char * result;
103f02d3 2206
dda8d76d 2207 switch (filedata->file_header.e_machine)
252b5132 2208 {
37c18eed
SD
2209 case EM_AARCH64:
2210 result = get_aarch64_dynamic_type (type);
2211 break;
252b5132 2212 case EM_MIPS:
4fe85591 2213 case EM_MIPS_RS3_LE:
252b5132
RH
2214 result = get_mips_dynamic_type (type);
2215 break;
9a097730
RH
2216 case EM_SPARCV9:
2217 result = get_sparc64_dynamic_type (type);
2218 break;
7490d522
AM
2219 case EM_PPC:
2220 result = get_ppc_dynamic_type (type);
2221 break;
f1cb7e17
AM
2222 case EM_PPC64:
2223 result = get_ppc64_dynamic_type (type);
2224 break;
ecc51f48
NC
2225 case EM_IA_64:
2226 result = get_ia64_dynamic_type (type);
2227 break;
fabcb361
RH
2228 case EM_ALPHA:
2229 result = get_alpha_dynamic_type (type);
2230 break;
1c0d3aa6
NC
2231 case EM_SCORE:
2232 result = get_score_dynamic_type (type);
2233 break;
40b36596
JM
2234 case EM_TI_C6000:
2235 result = get_tic6x_dynamic_type (type);
2236 break;
36591ba1
SL
2237 case EM_ALTERA_NIOS2:
2238 result = get_nios2_dynamic_type (type);
2239 break;
252b5132 2240 default:
dda8d76d 2241 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
2242 result = get_solaris_dynamic_type (type);
2243 else
2244 result = NULL;
252b5132
RH
2245 break;
2246 }
2247
2248 if (result != NULL)
2249 return result;
2250
e9e44622 2251 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
252b5132 2252 }
eec8f817 2253 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
dda8d76d 2254 || (filedata->file_header.e_machine == EM_PARISC
eec8f817 2255 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
103f02d3 2256 {
2cf0635d 2257 const char * result;
103f02d3 2258
dda8d76d 2259 switch (filedata->file_header.e_machine)
103f02d3
UD
2260 {
2261 case EM_PARISC:
2262 result = get_parisc_dynamic_type (type);
2263 break;
148b93f2
NC
2264 case EM_IA_64:
2265 result = get_ia64_dynamic_type (type);
2266 break;
103f02d3 2267 default:
dda8d76d 2268 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
2269 result = get_solaris_dynamic_type (type);
2270 else
2271 result = NULL;
103f02d3
UD
2272 break;
2273 }
2274
2275 if (result != NULL)
2276 return result;
2277
e9e44622
JJ
2278 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
2279 type);
103f02d3 2280 }
252b5132 2281 else
e9e44622 2282 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
103f02d3 2283
252b5132
RH
2284 return buff;
2285 }
2286}
2287
2288static char *
d3ba0551 2289get_file_type (unsigned e_type)
252b5132 2290{
b34976b6 2291 static char buff[32];
252b5132
RH
2292
2293 switch (e_type)
2294 {
32ec8896
NC
2295 case ET_NONE: return _("NONE (None)");
2296 case ET_REL: return _("REL (Relocatable file)");
2297 case ET_EXEC: return _("EXEC (Executable file)");
2298 case ET_DYN: return _("DYN (Shared object file)");
2299 case ET_CORE: return _("CORE (Core file)");
252b5132
RH
2300
2301 default:
2302 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
e9e44622 2303 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
252b5132 2304 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
e9e44622 2305 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
252b5132 2306 else
e9e44622 2307 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
252b5132
RH
2308 return buff;
2309 }
2310}
2311
2312static char *
d3ba0551 2313get_machine_name (unsigned e_machine)
252b5132 2314{
b34976b6 2315 static char buff[64]; /* XXX */
252b5132
RH
2316
2317 switch (e_machine)
2318 {
55e22ca8
NC
2319 /* Please keep this switch table sorted by increasing EM_ value. */
2320 /* 0 */
c45021f2
NC
2321 case EM_NONE: return _("None");
2322 case EM_M32: return "WE32100";
2323 case EM_SPARC: return "Sparc";
2324 case EM_386: return "Intel 80386";
2325 case EM_68K: return "MC68000";
2326 case EM_88K: return "MC88000";
22abe556 2327 case EM_IAMCU: return "Intel MCU";
fb70ec17 2328 case EM_860: return "Intel 80860";
c45021f2
NC
2329 case EM_MIPS: return "MIPS R3000";
2330 case EM_S370: return "IBM System/370";
55e22ca8 2331 /* 10 */
7036c0e1 2332 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
252b5132 2333 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
c45021f2 2334 case EM_PARISC: return "HPPA";
55e22ca8 2335 case EM_VPP550: return "Fujitsu VPP500";
7036c0e1 2336 case EM_SPARC32PLUS: return "Sparc v8+" ;
d7867d17 2337 case EM_960: return "Intel 80960";
c45021f2 2338 case EM_PPC: return "PowerPC";
55e22ca8 2339 /* 20 */
285d1771 2340 case EM_PPC64: return "PowerPC64";
55e22ca8
NC
2341 case EM_S390_OLD:
2342 case EM_S390: return "IBM S/390";
2343 case EM_SPU: return "SPU";
2344 /* 30 */
2345 case EM_V800: return "Renesas V850 (using RH850 ABI)";
c45021f2
NC
2346 case EM_FR20: return "Fujitsu FR20";
2347 case EM_RH32: return "TRW RH32";
b34976b6 2348 case EM_MCORE: return "MCORE";
55e22ca8 2349 /* 40 */
7036c0e1
AJ
2350 case EM_ARM: return "ARM";
2351 case EM_OLD_ALPHA: return "Digital Alpha (old)";
ef230218 2352 case EM_SH: return "Renesas / SuperH SH";
c45021f2
NC
2353 case EM_SPARCV9: return "Sparc v9";
2354 case EM_TRICORE: return "Siemens Tricore";
584da044 2355 case EM_ARC: return "ARC";
c2dcd04e
NC
2356 case EM_H8_300: return "Renesas H8/300";
2357 case EM_H8_300H: return "Renesas H8/300H";
2358 case EM_H8S: return "Renesas H8S";
2359 case EM_H8_500: return "Renesas H8/500";
55e22ca8 2360 /* 50 */
30800947 2361 case EM_IA_64: return "Intel IA-64";
252b5132
RH
2362 case EM_MIPS_X: return "Stanford MIPS-X";
2363 case EM_COLDFIRE: return "Motorola Coldfire";
55e22ca8 2364 case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
7036c0e1
AJ
2365 case EM_MMA: return "Fujitsu Multimedia Accelerator";
2366 case EM_PCP: return "Siemens PCP";
2367 case EM_NCPU: return "Sony nCPU embedded RISC processor";
2368 case EM_NDR1: return "Denso NDR1 microprocesspr";
2369 case EM_STARCORE: return "Motorola Star*Core processor";
2370 case EM_ME16: return "Toyota ME16 processor";
55e22ca8 2371 /* 60 */
7036c0e1
AJ
2372 case EM_ST100: return "STMicroelectronics ST100 processor";
2373 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
55e22ca8 2374 case EM_X86_64: return "Advanced Micro Devices X86-64";
11636f9e
JM
2375 case EM_PDSP: return "Sony DSP processor";
2376 case EM_PDP10: return "Digital Equipment Corp. PDP-10";
2377 case EM_PDP11: return "Digital Equipment Corp. PDP-11";
7036c0e1
AJ
2378 case EM_FX66: return "Siemens FX66 microcontroller";
2379 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2380 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
2381 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
55e22ca8 2382 /* 70 */
7036c0e1
AJ
2383 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
2384 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
2385 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
2386 case EM_SVX: return "Silicon Graphics SVx";
2387 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
2388 case EM_VAX: return "Digital VAX";
1b61cf92 2389 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
c45021f2
NC
2390 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
2391 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
2392 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
55e22ca8 2393 /* 80 */
b34976b6 2394 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
c45021f2 2395 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
3b36097d 2396 case EM_PRISM: return "Vitesse Prism";
55e22ca8
NC
2397 case EM_AVR_OLD:
2398 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
2399 case EM_CYGNUS_FR30:
2400 case EM_FR30: return "Fujitsu FR30";
2401 case EM_CYGNUS_D10V:
2402 case EM_D10V: return "d10v";
2403 case EM_CYGNUS_D30V:
2404 case EM_D30V: return "d30v";
2405 case EM_CYGNUS_V850:
2406 case EM_V850: return "Renesas V850";
2407 case EM_CYGNUS_M32R:
2408 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
2409 case EM_CYGNUS_MN10300:
2410 case EM_MN10300: return "mn10300";
2411 /* 90 */
2412 case EM_CYGNUS_MN10200:
2413 case EM_MN10200: return "mn10200";
2414 case EM_PJ: return "picoJava";
73589c9d 2415 case EM_OR1K: return "OpenRISC 1000";
55e22ca8 2416 case EM_ARC_COMPACT: return "ARCompact";
88da6820
NC
2417 case EM_XTENSA_OLD:
2418 case EM_XTENSA: return "Tensilica Xtensa Processor";
11636f9e
JM
2419 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
2420 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
2421 case EM_NS32K: return "National Semiconductor 32000 series";
2422 case EM_TPC: return "Tenor Network TPC processor";
55e22ca8
NC
2423 case EM_SNP1K: return "Trebia SNP 1000 processor";
2424 /* 100 */
9abca702 2425 case EM_ST200: return "STMicroelectronics ST200 microcontroller";
55e22ca8
NC
2426 case EM_IP2K_OLD:
2427 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
11636f9e
JM
2428 case EM_MAX: return "MAX Processor";
2429 case EM_CR: return "National Semiconductor CompactRISC";
2430 case EM_F2MC16: return "Fujitsu F2MC16";
2431 case EM_MSP430: return "Texas Instruments msp430 microcontroller";
7bbe5bc5 2432 case EM_BLACKFIN: return "Analog Devices Blackfin";
11636f9e
JM
2433 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
2434 case EM_SEP: return "Sharp embedded microprocessor";
2435 case EM_ARCA: return "Arca RISC microprocessor";
55e22ca8 2436 /* 110 */
11636f9e
JM
2437 case EM_UNICORE: return "Unicore";
2438 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
2439 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
64fd6348 2440 case EM_ALTERA_NIOS2: return "Altera Nios II";
55e22ca8
NC
2441 case EM_CRX: return "National Semiconductor CRX microprocessor";
2442 case EM_XGATE: return "Motorola XGATE embedded processor";
c29aca4a 2443 case EM_C166:
d70c5fc7 2444 case EM_XC16X: return "Infineon Technologies xc16x";
11636f9e
JM
2445 case EM_M16C: return "Renesas M16C series microprocessors";
2446 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
2447 case EM_CE: return "Freescale Communication Engine RISC core";
55e22ca8
NC
2448 /* 120 */
2449 case EM_M32C: return "Renesas M32c";
2450 /* 130 */
11636f9e
JM
2451 case EM_TSK3000: return "Altium TSK3000 core";
2452 case EM_RS08: return "Freescale RS08 embedded processor";
2453 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
55e22ca8 2454 case EM_SCORE: return "SUNPLUS S+Core";
11636f9e
JM
2455 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
2456 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
55e22ca8 2457 case EM_LATTICEMICO32: return "Lattice Mico32";
11636f9e 2458 case EM_SE_C17: return "Seiko Epson C17 family";
55e22ca8 2459 /* 140 */
11636f9e
JM
2460 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
2461 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
2462 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
55e22ca8
NC
2463 case EM_TI_PRU: return "TI PRU I/O processor";
2464 /* 160 */
11636f9e
JM
2465 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2466 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
2467 case EM_R32C: return "Renesas R32C series microprocessors";
2468 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
2469 case EM_QDSP6: return "QUALCOMM DSP6 Processor";
2470 case EM_8051: return "Intel 8051 and variants";
2471 case EM_STXP7X: return "STMicroelectronics STxP7x family";
2472 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
2473 case EM_ECOG1X: return "Cyan Technology eCOG1X family";
2474 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
55e22ca8 2475 /* 170 */
11636f9e
JM
2476 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
2477 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
2478 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
c7927a3c 2479 case EM_RX: return "Renesas RX";
a3c62988 2480 case EM_METAG: return "Imagination Technologies Meta processor architecture";
11636f9e
JM
2481 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
2482 case EM_ECOG16: return "Cyan Technology eCOG16 family";
55e22ca8
NC
2483 case EM_CR16:
2484 case EM_MICROBLAZE:
2485 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
11636f9e
JM
2486 case EM_ETPU: return "Freescale Extended Time Processing Unit";
2487 case EM_SLE9X: return "Infineon Technologies SLE9X core";
55e22ca8
NC
2488 /* 180 */
2489 case EM_L1OM: return "Intel L1OM";
2490 case EM_K1OM: return "Intel K1OM";
2491 case EM_INTEL182: return "Intel (reserved)";
2492 case EM_AARCH64: return "AArch64";
2493 case EM_ARM184: return "ARM (reserved)";
2494 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor";
11636f9e
JM
2495 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
2496 case EM_TILE64: return "Tilera TILE64 multicore architecture family";
2497 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
55e22ca8 2498 /* 190 */
11636f9e 2499 case EM_CUDA: return "NVIDIA CUDA architecture";
55e22ca8 2500 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
6d913794
NC
2501 case EM_CLOUDSHIELD: return "CloudShield architecture family";
2502 case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family";
2503 case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family";
55e22ca8 2504 case EM_ARC_COMPACT2: return "ARCv2";
6d913794 2505 case EM_OPEN8: return "Open8 8-bit RISC soft processor core";
55e22ca8 2506 case EM_RL78: return "Renesas RL78";
6d913794 2507 case EM_VIDEOCORE5: return "Broadcom VideoCore V processor";
55e22ca8
NC
2508 case EM_78K0R: return "Renesas 78K0R";
2509 /* 200 */
6d913794 2510 case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)";
15f205b1
NC
2511 case EM_BA1: return "Beyond BA1 CPU architecture";
2512 case EM_BA2: return "Beyond BA2 CPU architecture";
6d913794
NC
2513 case EM_XCORE: return "XMOS xCORE processor family";
2514 case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family";
55e22ca8 2515 /* 210 */
6d913794
NC
2516 case EM_KM32: return "KM211 KM32 32-bit processor";
2517 case EM_KMX32: return "KM211 KMX32 32-bit processor";
2518 case EM_KMX16: return "KM211 KMX16 16-bit processor";
2519 case EM_KMX8: return "KM211 KMX8 8-bit processor";
2520 case EM_KVARC: return "KM211 KVARC processor";
15f205b1 2521 case EM_CDP: return "Paneve CDP architecture family";
6d913794
NC
2522 case EM_COGE: return "Cognitive Smart Memory Processor";
2523 case EM_COOL: return "Bluechip Systems CoolEngine";
2524 case EM_NORC: return "Nanoradio Optimized RISC";
2525 case EM_CSR_KALIMBA: return "CSR Kalimba architecture family";
55e22ca8 2526 /* 220 */
15f205b1 2527 case EM_Z80: return "Zilog Z80";
55e22ca8
NC
2528 case EM_VISIUM: return "CDS VISIUMcore processor";
2529 case EM_FT32: return "FTDI Chip FT32";
2530 case EM_MOXIE: return "Moxie";
2531 case EM_AMDGPU: return "AMD GPU";
2532 case EM_RISCV: return "RISC-V";
2533 case EM_LANAI: return "Lanai 32-bit processor";
2534 case EM_BPF: return "Linux BPF";
fe944acf 2535 case EM_NFP: return "Netronome Flow Processor";
55e22ca8
NC
2536
2537 /* Large numbers... */
2538 case EM_MT: return "Morpho Techologies MT processor";
2539 case EM_ALPHA: return "Alpha";
2540 case EM_WEBASSEMBLY: return "Web Assembly";
9abca702 2541 case EM_DLX: return "OpenDLX";
55e22ca8
NC
2542 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
2543 case EM_IQ2000: return "Vitesse IQ2000";
2544 case EM_M32C_OLD:
2545 case EM_NIOS32: return "Altera Nios";
2546 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
2547 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
2548 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
637b1970 2549 case EM_S12Z: return "Freescale S12Z";
b8891f8d 2550 case EM_CSKY: return "C-SKY";
55e22ca8 2551
252b5132 2552 default:
35d9dd2f 2553 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
252b5132
RH
2554 return buff;
2555 }
2556}
2557
a9522a21
AB
2558static void
2559decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
2560{
2561 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2562 other compilers don't a specific architecture type in the e_flags, and
2563 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2564 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2565 architectures.
2566
2567 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2568 but also sets a specific architecture type in the e_flags field.
2569
2570 However, when decoding the flags we don't worry if we see an
2571 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2572 ARCEM architecture type. */
2573
2574 switch (e_flags & EF_ARC_MACH_MSK)
2575 {
2576 /* We only expect these to occur for EM_ARC_COMPACT2. */
2577 case EF_ARC_CPU_ARCV2EM:
2578 strcat (buf, ", ARC EM");
2579 break;
2580 case EF_ARC_CPU_ARCV2HS:
2581 strcat (buf, ", ARC HS");
2582 break;
2583
2584 /* We only expect these to occur for EM_ARC_COMPACT. */
2585 case E_ARC_MACH_ARC600:
2586 strcat (buf, ", ARC600");
2587 break;
2588 case E_ARC_MACH_ARC601:
2589 strcat (buf, ", ARC601");
2590 break;
2591 case E_ARC_MACH_ARC700:
2592 strcat (buf, ", ARC700");
2593 break;
2594
2595 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2596 new ELF with new architecture being read by an old version of
2597 readelf, or (c) An ELF built with non-GNU compiler that does not
2598 set the architecture in the e_flags. */
2599 default:
2600 if (e_machine == EM_ARC_COMPACT)
2601 strcat (buf, ", Unknown ARCompact");
2602 else
2603 strcat (buf, ", Unknown ARC");
2604 break;
2605 }
2606
2607 switch (e_flags & EF_ARC_OSABI_MSK)
2608 {
2609 case E_ARC_OSABI_ORIG:
2610 strcat (buf, ", (ABI:legacy)");
2611 break;
2612 case E_ARC_OSABI_V2:
2613 strcat (buf, ", (ABI:v2)");
2614 break;
2615 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2616 case E_ARC_OSABI_V3:
2617 strcat (buf, ", v3 no-legacy-syscalls ABI");
2618 break;
53a346d8
CZ
2619 case E_ARC_OSABI_V4:
2620 strcat (buf, ", v4 ABI");
2621 break;
a9522a21
AB
2622 default:
2623 strcat (buf, ", unrecognised ARC OSABI flag");
2624 break;
2625 }
2626}
2627
f3485b74 2628static void
d3ba0551 2629decode_ARM_machine_flags (unsigned e_flags, char buf[])
f3485b74
NC
2630{
2631 unsigned eabi;
32ec8896 2632 bfd_boolean unknown = FALSE;
f3485b74
NC
2633
2634 eabi = EF_ARM_EABI_VERSION (e_flags);
2635 e_flags &= ~ EF_ARM_EABIMASK;
2636
2637 /* Handle "generic" ARM flags. */
2638 if (e_flags & EF_ARM_RELEXEC)
2639 {
2640 strcat (buf, ", relocatable executable");
2641 e_flags &= ~ EF_ARM_RELEXEC;
2642 }
76da6bbe 2643
18a20338
CL
2644 if (e_flags & EF_ARM_PIC)
2645 {
2646 strcat (buf, ", position independent");
2647 e_flags &= ~ EF_ARM_PIC;
2648 }
2649
f3485b74
NC
2650 /* Now handle EABI specific flags. */
2651 switch (eabi)
2652 {
2653 default:
2c71103e 2654 strcat (buf, ", <unrecognized EABI>");
f3485b74 2655 if (e_flags)
32ec8896 2656 unknown = TRUE;
f3485b74
NC
2657 break;
2658
2659 case EF_ARM_EABI_VER1:
a5bcd848 2660 strcat (buf, ", Version1 EABI");
f3485b74
NC
2661 while (e_flags)
2662 {
2663 unsigned flag;
76da6bbe 2664
f3485b74
NC
2665 /* Process flags one bit at a time. */
2666 flag = e_flags & - e_flags;
2667 e_flags &= ~ flag;
76da6bbe 2668
f3485b74
NC
2669 switch (flag)
2670 {
a5bcd848 2671 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
f3485b74
NC
2672 strcat (buf, ", sorted symbol tables");
2673 break;
76da6bbe 2674
f3485b74 2675 default:
32ec8896 2676 unknown = TRUE;
f3485b74
NC
2677 break;
2678 }
2679 }
2680 break;
76da6bbe 2681
a5bcd848
PB
2682 case EF_ARM_EABI_VER2:
2683 strcat (buf, ", Version2 EABI");
2684 while (e_flags)
2685 {
2686 unsigned flag;
2687
2688 /* Process flags one bit at a time. */
2689 flag = e_flags & - e_flags;
2690 e_flags &= ~ flag;
2691
2692 switch (flag)
2693 {
2694 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2695 strcat (buf, ", sorted symbol tables");
2696 break;
2697
2698 case EF_ARM_DYNSYMSUSESEGIDX:
2699 strcat (buf, ", dynamic symbols use segment index");
2700 break;
2701
2702 case EF_ARM_MAPSYMSFIRST:
2703 strcat (buf, ", mapping symbols precede others");
2704 break;
2705
2706 default:
32ec8896 2707 unknown = TRUE;
a5bcd848
PB
2708 break;
2709 }
2710 }
2711 break;
2712
d507cf36
PB
2713 case EF_ARM_EABI_VER3:
2714 strcat (buf, ", Version3 EABI");
8cb51566
PB
2715 break;
2716
2717 case EF_ARM_EABI_VER4:
2718 strcat (buf, ", Version4 EABI");
3bfcb652
NC
2719 while (e_flags)
2720 {
2721 unsigned flag;
2722
2723 /* Process flags one bit at a time. */
2724 flag = e_flags & - e_flags;
2725 e_flags &= ~ flag;
2726
2727 switch (flag)
2728 {
2729 case EF_ARM_BE8:
2730 strcat (buf, ", BE8");
2731 break;
2732
2733 case EF_ARM_LE8:
2734 strcat (buf, ", LE8");
2735 break;
2736
2737 default:
32ec8896 2738 unknown = TRUE;
3bfcb652
NC
2739 break;
2740 }
3bfcb652
NC
2741 }
2742 break;
3a4a14e9
PB
2743
2744 case EF_ARM_EABI_VER5:
2745 strcat (buf, ", Version5 EABI");
d507cf36
PB
2746 while (e_flags)
2747 {
2748 unsigned flag;
2749
2750 /* Process flags one bit at a time. */
2751 flag = e_flags & - e_flags;
2752 e_flags &= ~ flag;
2753
2754 switch (flag)
2755 {
2756 case EF_ARM_BE8:
2757 strcat (buf, ", BE8");
2758 break;
2759
2760 case EF_ARM_LE8:
2761 strcat (buf, ", LE8");
2762 break;
2763
3bfcb652
NC
2764 case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2765 strcat (buf, ", soft-float ABI");
2766 break;
2767
2768 case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
2769 strcat (buf, ", hard-float ABI");
2770 break;
2771
d507cf36 2772 default:
32ec8896 2773 unknown = TRUE;
d507cf36
PB
2774 break;
2775 }
2776 }
2777 break;
2778
f3485b74 2779 case EF_ARM_EABI_UNKNOWN:
a5bcd848 2780 strcat (buf, ", GNU EABI");
f3485b74
NC
2781 while (e_flags)
2782 {
2783 unsigned flag;
76da6bbe 2784
f3485b74
NC
2785 /* Process flags one bit at a time. */
2786 flag = e_flags & - e_flags;
2787 e_flags &= ~ flag;
76da6bbe 2788
f3485b74
NC
2789 switch (flag)
2790 {
a5bcd848 2791 case EF_ARM_INTERWORK:
f3485b74
NC
2792 strcat (buf, ", interworking enabled");
2793 break;
76da6bbe 2794
a5bcd848 2795 case EF_ARM_APCS_26:
f3485b74
NC
2796 strcat (buf, ", uses APCS/26");
2797 break;
76da6bbe 2798
a5bcd848 2799 case EF_ARM_APCS_FLOAT:
f3485b74
NC
2800 strcat (buf, ", uses APCS/float");
2801 break;
76da6bbe 2802
a5bcd848 2803 case EF_ARM_PIC:
f3485b74
NC
2804 strcat (buf, ", position independent");
2805 break;
76da6bbe 2806
a5bcd848 2807 case EF_ARM_ALIGN8:
f3485b74
NC
2808 strcat (buf, ", 8 bit structure alignment");
2809 break;
76da6bbe 2810
a5bcd848 2811 case EF_ARM_NEW_ABI:
f3485b74
NC
2812 strcat (buf, ", uses new ABI");
2813 break;
76da6bbe 2814
a5bcd848 2815 case EF_ARM_OLD_ABI:
f3485b74
NC
2816 strcat (buf, ", uses old ABI");
2817 break;
76da6bbe 2818
a5bcd848 2819 case EF_ARM_SOFT_FLOAT:
f3485b74
NC
2820 strcat (buf, ", software FP");
2821 break;
76da6bbe 2822
90e01f86
ILT
2823 case EF_ARM_VFP_FLOAT:
2824 strcat (buf, ", VFP");
2825 break;
2826
fde78edd
NC
2827 case EF_ARM_MAVERICK_FLOAT:
2828 strcat (buf, ", Maverick FP");
2829 break;
2830
f3485b74 2831 default:
32ec8896 2832 unknown = TRUE;
f3485b74
NC
2833 break;
2834 }
2835 }
2836 }
f3485b74
NC
2837
2838 if (unknown)
2b692964 2839 strcat (buf,_(", <unknown>"));
f3485b74
NC
2840}
2841
343433df
AB
2842static void
2843decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
2844{
2845 --size; /* Leave space for null terminator. */
2846
2847 switch (e_flags & EF_AVR_MACH)
2848 {
2849 case E_AVR_MACH_AVR1:
2850 strncat (buf, ", avr:1", size);
2851 break;
2852 case E_AVR_MACH_AVR2:
2853 strncat (buf, ", avr:2", size);
2854 break;
2855 case E_AVR_MACH_AVR25:
2856 strncat (buf, ", avr:25", size);
2857 break;
2858 case E_AVR_MACH_AVR3:
2859 strncat (buf, ", avr:3", size);
2860 break;
2861 case E_AVR_MACH_AVR31:
2862 strncat (buf, ", avr:31", size);
2863 break;
2864 case E_AVR_MACH_AVR35:
2865 strncat (buf, ", avr:35", size);
2866 break;
2867 case E_AVR_MACH_AVR4:
2868 strncat (buf, ", avr:4", size);
2869 break;
2870 case E_AVR_MACH_AVR5:
2871 strncat (buf, ", avr:5", size);
2872 break;
2873 case E_AVR_MACH_AVR51:
2874 strncat (buf, ", avr:51", size);
2875 break;
2876 case E_AVR_MACH_AVR6:
2877 strncat (buf, ", avr:6", size);
2878 break;
2879 case E_AVR_MACH_AVRTINY:
2880 strncat (buf, ", avr:100", size);
2881 break;
2882 case E_AVR_MACH_XMEGA1:
2883 strncat (buf, ", avr:101", size);
2884 break;
2885 case E_AVR_MACH_XMEGA2:
2886 strncat (buf, ", avr:102", size);
2887 break;
2888 case E_AVR_MACH_XMEGA3:
2889 strncat (buf, ", avr:103", size);
2890 break;
2891 case E_AVR_MACH_XMEGA4:
2892 strncat (buf, ", avr:104", size);
2893 break;
2894 case E_AVR_MACH_XMEGA5:
2895 strncat (buf, ", avr:105", size);
2896 break;
2897 case E_AVR_MACH_XMEGA6:
2898 strncat (buf, ", avr:106", size);
2899 break;
2900 case E_AVR_MACH_XMEGA7:
2901 strncat (buf, ", avr:107", size);
2902 break;
2903 default:
2904 strncat (buf, ", avr:<unknown>", size);
2905 break;
2906 }
2907
2908 size -= strlen (buf);
2909 if (e_flags & EF_AVR_LINKRELAX_PREPARED)
2910 strncat (buf, ", link-relax", size);
2911}
2912
35c08157
KLC
2913static void
2914decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
2915{
2916 unsigned abi;
2917 unsigned arch;
2918 unsigned config;
2919 unsigned version;
32ec8896
NC
2920 bfd_boolean has_fpu = FALSE;
2921 unsigned int r = 0;
35c08157
KLC
2922
2923 static const char *ABI_STRINGS[] =
2924 {
2925 "ABI v0", /* use r5 as return register; only used in N1213HC */
2926 "ABI v1", /* use r0 as return register */
2927 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2928 "ABI v2fp", /* for FPU */
40c7a7cb
KLC
2929 "AABI",
2930 "ABI2 FP+"
35c08157
KLC
2931 };
2932 static const char *VER_STRINGS[] =
2933 {
2934 "Andes ELF V1.3 or older",
2935 "Andes ELF V1.3.1",
2936 "Andes ELF V1.4"
2937 };
2938 static const char *ARCH_STRINGS[] =
2939 {
2940 "",
2941 "Andes Star v1.0",
2942 "Andes Star v2.0",
2943 "Andes Star v3.0",
2944 "Andes Star v3.0m"
2945 };
2946
2947 abi = EF_NDS_ABI & e_flags;
2948 arch = EF_NDS_ARCH & e_flags;
2949 config = EF_NDS_INST & e_flags;
2950 version = EF_NDS32_ELF_VERSION & e_flags;
2951
2952 memset (buf, 0, size);
2953
2954 switch (abi)
2955 {
2956 case E_NDS_ABI_V0:
2957 case E_NDS_ABI_V1:
2958 case E_NDS_ABI_V2:
2959 case E_NDS_ABI_V2FP:
2960 case E_NDS_ABI_AABI:
40c7a7cb 2961 case E_NDS_ABI_V2FP_PLUS:
35c08157
KLC
2962 /* In case there are holes in the array. */
2963 r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
2964 break;
2965
2966 default:
2967 r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
2968 break;
2969 }
2970
2971 switch (version)
2972 {
2973 case E_NDS32_ELF_VER_1_2:
2974 case E_NDS32_ELF_VER_1_3:
2975 case E_NDS32_ELF_VER_1_4:
2976 r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
2977 break;
2978
2979 default:
2980 r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
2981 break;
2982 }
2983
2984 if (E_NDS_ABI_V0 == abi)
2985 {
2986 /* OLD ABI; only used in N1213HC, has performance extension 1. */
2987 r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
2988 if (arch == E_NDS_ARCH_STAR_V1_0)
2989 r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
2990 return;
2991 }
2992
2993 switch (arch)
2994 {
2995 case E_NDS_ARCH_STAR_V1_0:
2996 case E_NDS_ARCH_STAR_V2_0:
2997 case E_NDS_ARCH_STAR_V3_0:
2998 case E_NDS_ARCH_STAR_V3_M:
2999 r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
3000 break;
3001
3002 default:
3003 r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
3004 /* ARCH version determines how the e_flags are interpreted.
3005 If it is unknown, we cannot proceed. */
3006 return;
3007 }
3008
3009 /* Newer ABI; Now handle architecture specific flags. */
3010 if (arch == E_NDS_ARCH_STAR_V1_0)
3011 {
3012 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3013 r += snprintf (buf + r, size -r, ", MFUSR_PC");
3014
3015 if (!(config & E_NDS32_HAS_NO_MAC_INST))
3016 r += snprintf (buf + r, size -r, ", MAC");
3017
3018 if (config & E_NDS32_HAS_DIV_INST)
3019 r += snprintf (buf + r, size -r, ", DIV");
3020
3021 if (config & E_NDS32_HAS_16BIT_INST)
3022 r += snprintf (buf + r, size -r, ", 16b");
3023 }
3024 else
3025 {
3026 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3027 {
3028 if (version <= E_NDS32_ELF_VER_1_3)
3029 r += snprintf (buf + r, size -r, ", [B8]");
3030 else
3031 r += snprintf (buf + r, size -r, ", EX9");
3032 }
3033
3034 if (config & E_NDS32_HAS_MAC_DX_INST)
3035 r += snprintf (buf + r, size -r, ", MAC_DX");
3036
3037 if (config & E_NDS32_HAS_DIV_DX_INST)
3038 r += snprintf (buf + r, size -r, ", DIV_DX");
3039
3040 if (config & E_NDS32_HAS_16BIT_INST)
3041 {
3042 if (version <= E_NDS32_ELF_VER_1_3)
3043 r += snprintf (buf + r, size -r, ", 16b");
3044 else
3045 r += snprintf (buf + r, size -r, ", IFC");
3046 }
3047 }
3048
3049 if (config & E_NDS32_HAS_EXT_INST)
3050 r += snprintf (buf + r, size -r, ", PERF1");
3051
3052 if (config & E_NDS32_HAS_EXT2_INST)
3053 r += snprintf (buf + r, size -r, ", PERF2");
3054
3055 if (config & E_NDS32_HAS_FPU_INST)
3056 {
32ec8896 3057 has_fpu = TRUE;
35c08157
KLC
3058 r += snprintf (buf + r, size -r, ", FPU_SP");
3059 }
3060
3061 if (config & E_NDS32_HAS_FPU_DP_INST)
3062 {
32ec8896 3063 has_fpu = TRUE;
35c08157
KLC
3064 r += snprintf (buf + r, size -r, ", FPU_DP");
3065 }
3066
3067 if (config & E_NDS32_HAS_FPU_MAC_INST)
3068 {
32ec8896 3069 has_fpu = TRUE;
35c08157
KLC
3070 r += snprintf (buf + r, size -r, ", FPU_MAC");
3071 }
3072
3073 if (has_fpu)
3074 {
3075 switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
3076 {
3077 case E_NDS32_FPU_REG_8SP_4DP:
3078 r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
3079 break;
3080 case E_NDS32_FPU_REG_16SP_8DP:
3081 r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
3082 break;
3083 case E_NDS32_FPU_REG_32SP_16DP:
3084 r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
3085 break;
3086 case E_NDS32_FPU_REG_32SP_32DP:
3087 r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
3088 break;
3089 }
3090 }
3091
3092 if (config & E_NDS32_HAS_AUDIO_INST)
3093 r += snprintf (buf + r, size -r, ", AUDIO");
3094
3095 if (config & E_NDS32_HAS_STRING_INST)
3096 r += snprintf (buf + r, size -r, ", STR");
3097
3098 if (config & E_NDS32_HAS_REDUCED_REGS)
3099 r += snprintf (buf + r, size -r, ", 16REG");
3100
3101 if (config & E_NDS32_HAS_VIDEO_INST)
3102 {
3103 if (version <= E_NDS32_ELF_VER_1_3)
3104 r += snprintf (buf + r, size -r, ", VIDEO");
3105 else
3106 r += snprintf (buf + r, size -r, ", SATURATION");
3107 }
3108
3109 if (config & E_NDS32_HAS_ENCRIPT_INST)
3110 r += snprintf (buf + r, size -r, ", ENCRP");
3111
3112 if (config & E_NDS32_HAS_L2C_INST)
3113 r += snprintf (buf + r, size -r, ", L2C");
3114}
3115
252b5132 3116static char *
dda8d76d 3117get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
252b5132 3118{
b34976b6 3119 static char buf[1024];
252b5132
RH
3120
3121 buf[0] = '\0';
76da6bbe 3122
252b5132
RH
3123 if (e_flags)
3124 {
3125 switch (e_machine)
3126 {
3127 default:
3128 break;
3129
886a2506 3130 case EM_ARC_COMPACT2:
886a2506 3131 case EM_ARC_COMPACT:
a9522a21
AB
3132 decode_ARC_machine_flags (e_flags, e_machine, buf);
3133 break;
886a2506 3134
f3485b74
NC
3135 case EM_ARM:
3136 decode_ARM_machine_flags (e_flags, buf);
3137 break;
76da6bbe 3138
343433df
AB
3139 case EM_AVR:
3140 decode_AVR_machine_flags (e_flags, buf, sizeof buf);
3141 break;
3142
781303ce
MF
3143 case EM_BLACKFIN:
3144 if (e_flags & EF_BFIN_PIC)
3145 strcat (buf, ", PIC");
3146
3147 if (e_flags & EF_BFIN_FDPIC)
3148 strcat (buf, ", FDPIC");
3149
3150 if (e_flags & EF_BFIN_CODE_IN_L1)
3151 strcat (buf, ", code in L1");
3152
3153 if (e_flags & EF_BFIN_DATA_IN_L1)
3154 strcat (buf, ", data in L1");
3155
3156 break;
3157
ec2dfb42
AO
3158 case EM_CYGNUS_FRV:
3159 switch (e_flags & EF_FRV_CPU_MASK)
3160 {
3161 case EF_FRV_CPU_GENERIC:
3162 break;
3163
3164 default:
3165 strcat (buf, ", fr???");
3166 break;
57346661 3167
ec2dfb42
AO
3168 case EF_FRV_CPU_FR300:
3169 strcat (buf, ", fr300");
3170 break;
3171
3172 case EF_FRV_CPU_FR400:
3173 strcat (buf, ", fr400");
3174 break;
3175 case EF_FRV_CPU_FR405:
3176 strcat (buf, ", fr405");
3177 break;
3178
3179 case EF_FRV_CPU_FR450:
3180 strcat (buf, ", fr450");
3181 break;
3182
3183 case EF_FRV_CPU_FR500:
3184 strcat (buf, ", fr500");
3185 break;
3186 case EF_FRV_CPU_FR550:
3187 strcat (buf, ", fr550");
3188 break;
3189
3190 case EF_FRV_CPU_SIMPLE:
3191 strcat (buf, ", simple");
3192 break;
3193 case EF_FRV_CPU_TOMCAT:
3194 strcat (buf, ", tomcat");
3195 break;
3196 }
1c877e87 3197 break;
ec2dfb42 3198
53c7db4b 3199 case EM_68K:
425c6cb0 3200 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
76f57f3a 3201 strcat (buf, ", m68000");
425c6cb0 3202 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
3bdcfdf4
KH
3203 strcat (buf, ", cpu32");
3204 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
3205 strcat (buf, ", fido_a");
425c6cb0 3206 else
266abb8f 3207 {
2cf0635d
NC
3208 char const * isa = _("unknown");
3209 char const * mac = _("unknown mac");
3210 char const * additional = NULL;
0112cd26 3211
c694fd50 3212 switch (e_flags & EF_M68K_CF_ISA_MASK)
266abb8f 3213 {
c694fd50 3214 case EF_M68K_CF_ISA_A_NODIV:
0b2e31dc
NS
3215 isa = "A";
3216 additional = ", nodiv";
3217 break;
c694fd50 3218 case EF_M68K_CF_ISA_A:
266abb8f
NS
3219 isa = "A";
3220 break;
c694fd50 3221 case EF_M68K_CF_ISA_A_PLUS:
266abb8f
NS
3222 isa = "A+";
3223 break;
c694fd50 3224 case EF_M68K_CF_ISA_B_NOUSP:
0b2e31dc
NS
3225 isa = "B";
3226 additional = ", nousp";
3227 break;
c694fd50 3228 case EF_M68K_CF_ISA_B:
266abb8f
NS
3229 isa = "B";
3230 break;
f608cd77
NS
3231 case EF_M68K_CF_ISA_C:
3232 isa = "C";
3233 break;
3234 case EF_M68K_CF_ISA_C_NODIV:
3235 isa = "C";
3236 additional = ", nodiv";
3237 break;
266abb8f
NS
3238 }
3239 strcat (buf, ", cf, isa ");
3240 strcat (buf, isa);
0b2e31dc
NS
3241 if (additional)
3242 strcat (buf, additional);
c694fd50 3243 if (e_flags & EF_M68K_CF_FLOAT)
0b2e31dc 3244 strcat (buf, ", float");
c694fd50 3245 switch (e_flags & EF_M68K_CF_MAC_MASK)
266abb8f
NS
3246 {
3247 case 0:
3248 mac = NULL;
3249 break;
c694fd50 3250 case EF_M68K_CF_MAC:
266abb8f
NS
3251 mac = "mac";
3252 break;
c694fd50 3253 case EF_M68K_CF_EMAC:
266abb8f
NS
3254 mac = "emac";
3255 break;
f608cd77
NS
3256 case EF_M68K_CF_EMAC_B:
3257 mac = "emac_b";
3258 break;
266abb8f
NS
3259 }
3260 if (mac)
3261 {
3262 strcat (buf, ", ");
3263 strcat (buf, mac);
3264 }
266abb8f 3265 }
53c7db4b 3266 break;
33c63f9d 3267
abeeff98
LM
3268 case EM_AMDGPU:
3269 switch (e_flags & EF_AMDGPU_MACH)
3270 {
3271 case EF_AMDGPU_MACH_AMDGCN_GFX801 : strcat (buf, ", gfx801"); break;
3272 case EF_AMDGPU_MACH_AMDGCN_GFX802 : strcat (buf, ", gfx802"); break;
3273 case EF_AMDGPU_MACH_AMDGCN_GFX803 : strcat (buf, ", gfx803"); break;
3274 case EF_AMDGPU_MACH_AMDGCN_GFX810 : strcat (buf, ", gfx810"); break;
3275 case EF_AMDGPU_MACH_AMDGCN_GFX900 : strcat (buf, ", gfx900"); break;
3276 case EF_AMDGPU_MACH_AMDGCN_GFX902 : strcat (buf, ", gfx902"); break;
3277 case EF_AMDGPU_MACH_AMDGCN_GFX904 : strcat (buf, ", gfx904"); break;
3278 case EF_AMDGPU_MACH_AMDGCN_GFX906 : strcat (buf, ", gfx906"); break;
3279 case EF_AMDGPU_MACH_AMDGCN_GFX908 : strcat (buf, ", gfx908"); break;
3280 case EF_AMDGPU_MACH_AMDGCN_GFX909 : strcat (buf, ", gfx909"); break;
3281 default: strcat (buf, _(", <unknown AMDGPU gpu type>")); break;
3282 }
3283
3284 if (e_flags & ~ EF_AMDGPU_MACH)
3285 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
3286 e_flags & ~ EF_AMDGPU_MACH);
3287 break;
3288
153a2776
NC
3289 case EM_CYGNUS_MEP:
3290 switch (e_flags & EF_MEP_CPU_MASK)
3291 {
3292 case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
3293 case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
3294 case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
3295 case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
3296 case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
3297 case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
3298 default: strcat (buf, _(", <unknown MeP cpu type>")); break;
3299 }
3300
3301 switch (e_flags & EF_MEP_COP_MASK)
3302 {
3303 case EF_MEP_COP_NONE: break;
3304 case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
3305 case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
3306 case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
3307 case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
3308 default: strcat (buf, _("<unknown MeP copro type>")); break;
3309 }
3310
3311 if (e_flags & EF_MEP_LIBRARY)
3312 strcat (buf, ", Built for Library");
3313
3314 if (e_flags & EF_MEP_INDEX_MASK)
3315 sprintf (buf + strlen (buf), ", Configuration Index: %#x",
3316 e_flags & EF_MEP_INDEX_MASK);
3317
3318 if (e_flags & ~ EF_MEP_ALL_FLAGS)
3319 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
3320 e_flags & ~ EF_MEP_ALL_FLAGS);
3321 break;
3322
252b5132
RH
3323 case EM_PPC:
3324 if (e_flags & EF_PPC_EMB)
3325 strcat (buf, ", emb");
3326
3327 if (e_flags & EF_PPC_RELOCATABLE)
2b692964 3328 strcat (buf, _(", relocatable"));
252b5132
RH
3329
3330 if (e_flags & EF_PPC_RELOCATABLE_LIB)
2b692964 3331 strcat (buf, _(", relocatable-lib"));
252b5132
RH
3332 break;
3333
ee67d69a
AM
3334 case EM_PPC64:
3335 if (e_flags & EF_PPC64_ABI)
3336 {
3337 char abi[] = ", abiv0";
3338
3339 abi[6] += e_flags & EF_PPC64_ABI;
3340 strcat (buf, abi);
3341 }
3342 break;
3343
708e2187
NC
3344 case EM_V800:
3345 if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
3346 strcat (buf, ", RH850 ABI");
0b4362b0 3347
708e2187
NC
3348 if (e_flags & EF_V800_850E3)
3349 strcat (buf, ", V3 architecture");
3350
3351 if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
3352 strcat (buf, ", FPU not used");
3353
3354 if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
3355 strcat (buf, ", regmode: COMMON");
3356
3357 if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
3358 strcat (buf, ", r4 not used");
3359
3360 if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
3361 strcat (buf, ", r30 not used");
3362
3363 if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
3364 strcat (buf, ", r5 not used");
3365
3366 if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
3367 strcat (buf, ", r2 not used");
3368
3369 for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
3370 {
3371 switch (e_flags & - e_flags)
3372 {
3373 case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
3374 case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
708e2187
NC
3375 case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
3376 case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
708e2187
NC
3377 case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
3378 case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
3379 case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
3380 case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
3381 case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
3382 case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
3383 case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
3384 case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
3385 default: break;
3386 }
3387 }
3388 break;
3389
2b0337b0 3390 case EM_V850:
252b5132
RH
3391 case EM_CYGNUS_V850:
3392 switch (e_flags & EF_V850_ARCH)
3393 {
78c8d46c
NC
3394 case E_V850E3V5_ARCH:
3395 strcat (buf, ", v850e3v5");
3396 break;
1cd986c5
NC
3397 case E_V850E2V3_ARCH:
3398 strcat (buf, ", v850e2v3");
3399 break;
3400 case E_V850E2_ARCH:
3401 strcat (buf, ", v850e2");
3402 break;
3403 case E_V850E1_ARCH:
3404 strcat (buf, ", v850e1");
8ad30312 3405 break;
252b5132
RH
3406 case E_V850E_ARCH:
3407 strcat (buf, ", v850e");
3408 break;
252b5132
RH
3409 case E_V850_ARCH:
3410 strcat (buf, ", v850");
3411 break;
3412 default:
2b692964 3413 strcat (buf, _(", unknown v850 architecture variant"));
252b5132
RH
3414 break;
3415 }
3416 break;
3417
2b0337b0 3418 case EM_M32R:
252b5132
RH
3419 case EM_CYGNUS_M32R:
3420 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3421 strcat (buf, ", m32r");
252b5132
RH
3422 break;
3423
3424 case EM_MIPS:
4fe85591 3425 case EM_MIPS_RS3_LE:
252b5132
RH
3426 if (e_flags & EF_MIPS_NOREORDER)
3427 strcat (buf, ", noreorder");
3428
3429 if (e_flags & EF_MIPS_PIC)
3430 strcat (buf, ", pic");
3431
3432 if (e_flags & EF_MIPS_CPIC)
3433 strcat (buf, ", cpic");
3434
d1bdd336
TS
3435 if (e_flags & EF_MIPS_UCODE)
3436 strcat (buf, ", ugen_reserved");
3437
252b5132
RH
3438 if (e_flags & EF_MIPS_ABI2)
3439 strcat (buf, ", abi2");
3440
43521d43
TS
3441 if (e_flags & EF_MIPS_OPTIONS_FIRST)
3442 strcat (buf, ", odk first");
3443
a5d22d2a
TS
3444 if (e_flags & EF_MIPS_32BITMODE)
3445 strcat (buf, ", 32bitmode");
3446
ba92f887
MR
3447 if (e_flags & EF_MIPS_NAN2008)
3448 strcat (buf, ", nan2008");
3449
fef1b0b3
SE
3450 if (e_flags & EF_MIPS_FP64)
3451 strcat (buf, ", fp64");
3452
156c2f8b
NC
3453 switch ((e_flags & EF_MIPS_MACH))
3454 {
3455 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
3456 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
3457 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
156c2f8b 3458 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
810dfa6e
L
3459 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
3460 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
3461 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
3462 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
ef272caa 3463 case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break;
c6c98b38 3464 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
ebcb91b7 3465 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
350cc38d
MS
3466 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
3467 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
ac8cb70f 3468 case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break;
bd782c07 3469 case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break;
9108bc33 3470 case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break;
05c6f050 3471 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
67c2a3e8 3472 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
d32e5c54 3473 case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
52b6b6b9 3474 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
38bf472a 3475 case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break;
43521d43
TS
3476 case 0:
3477 /* We simply ignore the field in this case to avoid confusion:
3478 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3479 extension. */
3480 break;
2b692964 3481 default: strcat (buf, _(", unknown CPU")); break;
156c2f8b 3482 }
43521d43
TS
3483
3484 switch ((e_flags & EF_MIPS_ABI))
3485 {
3486 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
3487 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
3488 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
3489 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
3490 case 0:
3491 /* We simply ignore the field in this case to avoid confusion:
3492 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3493 This means it is likely to be an o32 file, but not for
3494 sure. */
3495 break;
2b692964 3496 default: strcat (buf, _(", unknown ABI")); break;
43521d43
TS
3497 }
3498
3499 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
3500 strcat (buf, ", mdmx");
3501
3502 if (e_flags & EF_MIPS_ARCH_ASE_M16)
3503 strcat (buf, ", mips16");
3504
df58fc94
RS
3505 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
3506 strcat (buf, ", micromips");
3507
43521d43
TS
3508 switch ((e_flags & EF_MIPS_ARCH))
3509 {
3510 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
3511 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
3512 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
3513 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
3514 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
3515 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
cb44e358 3516 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
7361da2c 3517 case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
43521d43 3518 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
5f74bc13 3519 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
7361da2c 3520 case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
2b692964 3521 default: strcat (buf, _(", unknown ISA")); break;
43521d43 3522 }
252b5132 3523 break;
351b4b40 3524
35c08157
KLC
3525 case EM_NDS32:
3526 decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
3527 break;
3528
fe944acf
FT
3529 case EM_NFP:
3530 switch (EF_NFP_MACH (e_flags))
3531 {
3532 case E_NFP_MACH_3200:
3533 strcat (buf, ", NFP-32xx");
3534 break;
3535 case E_NFP_MACH_6000:
3536 strcat (buf, ", NFP-6xxx");
3537 break;
3538 }
3539 break;
3540
e23eba97
NC
3541 case EM_RISCV:
3542 if (e_flags & EF_RISCV_RVC)
3543 strcat (buf, ", RVC");
2922d21d 3544
7f999549
JW
3545 if (e_flags & EF_RISCV_RVE)
3546 strcat (buf, ", RVE");
3547
2922d21d
AW
3548 switch (e_flags & EF_RISCV_FLOAT_ABI)
3549 {
3550 case EF_RISCV_FLOAT_ABI_SOFT:
3551 strcat (buf, ", soft-float ABI");
3552 break;
3553
3554 case EF_RISCV_FLOAT_ABI_SINGLE:
3555 strcat (buf, ", single-float ABI");
3556 break;
3557
3558 case EF_RISCV_FLOAT_ABI_DOUBLE:
3559 strcat (buf, ", double-float ABI");
3560 break;
3561
3562 case EF_RISCV_FLOAT_ABI_QUAD:
3563 strcat (buf, ", quad-float ABI");
3564 break;
3565 }
e23eba97
NC
3566 break;
3567
ccde1100
AO
3568 case EM_SH:
3569 switch ((e_flags & EF_SH_MACH_MASK))
3570 {
3571 case EF_SH1: strcat (buf, ", sh1"); break;
3572 case EF_SH2: strcat (buf, ", sh2"); break;
3573 case EF_SH3: strcat (buf, ", sh3"); break;
3574 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
3575 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
3576 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
3577 case EF_SH3E: strcat (buf, ", sh3e"); break;
3578 case EF_SH4: strcat (buf, ", sh4"); break;
3579 case EF_SH5: strcat (buf, ", sh5"); break;
3580 case EF_SH2E: strcat (buf, ", sh2e"); break;
3581 case EF_SH4A: strcat (buf, ", sh4a"); break;
1d70c7fb 3582 case EF_SH2A: strcat (buf, ", sh2a"); break;
ccde1100
AO
3583 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
3584 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
1d70c7fb 3585 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
0b92ab21
NH
3586 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
3587 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
3588 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3589 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
3590 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
3591 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
2b692964 3592 default: strcat (buf, _(", unknown ISA")); break;
ccde1100
AO
3593 }
3594
cec6a5b8
MR
3595 if (e_flags & EF_SH_PIC)
3596 strcat (buf, ", pic");
3597
3598 if (e_flags & EF_SH_FDPIC)
3599 strcat (buf, ", fdpic");
ccde1100 3600 break;
948f632f 3601
73589c9d
CS
3602 case EM_OR1K:
3603 if (e_flags & EF_OR1K_NODELAY)
3604 strcat (buf, ", no delay");
3605 break;
57346661 3606
351b4b40
RH
3607 case EM_SPARCV9:
3608 if (e_flags & EF_SPARC_32PLUS)
3609 strcat (buf, ", v8+");
3610
3611 if (e_flags & EF_SPARC_SUN_US1)
d07faca2
RH
3612 strcat (buf, ", ultrasparcI");
3613
3614 if (e_flags & EF_SPARC_SUN_US3)
3615 strcat (buf, ", ultrasparcIII");
351b4b40
RH
3616
3617 if (e_flags & EF_SPARC_HAL_R1)
3618 strcat (buf, ", halr1");
3619
3620 if (e_flags & EF_SPARC_LEDATA)
3621 strcat (buf, ", ledata");
3622
3623 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
3624 strcat (buf, ", tso");
3625
3626 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
3627 strcat (buf, ", pso");
3628
3629 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
3630 strcat (buf, ", rmo");
3631 break;
7d466069 3632
103f02d3
UD
3633 case EM_PARISC:
3634 switch (e_flags & EF_PARISC_ARCH)
3635 {
3636 case EFA_PARISC_1_0:
3637 strcpy (buf, ", PA-RISC 1.0");
3638 break;
3639 case EFA_PARISC_1_1:
3640 strcpy (buf, ", PA-RISC 1.1");
3641 break;
3642 case EFA_PARISC_2_0:
3643 strcpy (buf, ", PA-RISC 2.0");
3644 break;
3645 default:
3646 break;
3647 }
3648 if (e_flags & EF_PARISC_TRAPNIL)
3649 strcat (buf, ", trapnil");
3650 if (e_flags & EF_PARISC_EXT)
3651 strcat (buf, ", ext");
3652 if (e_flags & EF_PARISC_LSB)
3653 strcat (buf, ", lsb");
3654 if (e_flags & EF_PARISC_WIDE)
3655 strcat (buf, ", wide");
3656 if (e_flags & EF_PARISC_NO_KABP)
3657 strcat (buf, ", no kabp");
3658 if (e_flags & EF_PARISC_LAZYSWAP)
3659 strcat (buf, ", lazyswap");
30800947 3660 break;
76da6bbe 3661
7d466069 3662 case EM_PJ:
2b0337b0 3663 case EM_PJ_OLD:
7d466069
ILT
3664 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
3665 strcat (buf, ", new calling convention");
3666
3667 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
3668 strcat (buf, ", gnu calling convention");
3669 break;
4d6ed7c8
NC
3670
3671 case EM_IA_64:
3672 if ((e_flags & EF_IA_64_ABI64))
3673 strcat (buf, ", 64-bit");
3674 else
3675 strcat (buf, ", 32-bit");
3676 if ((e_flags & EF_IA_64_REDUCEDFP))
3677 strcat (buf, ", reduced fp model");
3678 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
3679 strcat (buf, ", no function descriptors, constant gp");
3680 else if ((e_flags & EF_IA_64_CONS_GP))
3681 strcat (buf, ", constant gp");
3682 if ((e_flags & EF_IA_64_ABSOLUTE))
3683 strcat (buf, ", absolute");
dda8d76d 3684 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
28f997cf
TG
3685 {
3686 if ((e_flags & EF_IA_64_VMS_LINKAGES))
3687 strcat (buf, ", vms_linkages");
3688 switch ((e_flags & EF_IA_64_VMS_COMCOD))
3689 {
3690 case EF_IA_64_VMS_COMCOD_SUCCESS:
3691 break;
3692 case EF_IA_64_VMS_COMCOD_WARNING:
3693 strcat (buf, ", warning");
3694 break;
3695 case EF_IA_64_VMS_COMCOD_ERROR:
3696 strcat (buf, ", error");
3697 break;
3698 case EF_IA_64_VMS_COMCOD_ABORT:
3699 strcat (buf, ", abort");
3700 break;
3701 default:
bee0ee85
NC
3702 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3703 e_flags & EF_IA_64_VMS_COMCOD);
3704 strcat (buf, ", <unknown>");
28f997cf
TG
3705 }
3706 }
4d6ed7c8 3707 break;
179d3252
JT
3708
3709 case EM_VAX:
3710 if ((e_flags & EF_VAX_NONPIC))
3711 strcat (buf, ", non-PIC");
3712 if ((e_flags & EF_VAX_DFLOAT))
3713 strcat (buf, ", D-Float");
3714 if ((e_flags & EF_VAX_GFLOAT))
3715 strcat (buf, ", G-Float");
3716 break;
c7927a3c 3717
619ed720
EB
3718 case EM_VISIUM:
3719 if (e_flags & EF_VISIUM_ARCH_MCM)
3720 strcat (buf, ", mcm");
3721 else if (e_flags & EF_VISIUM_ARCH_MCM24)
3722 strcat (buf, ", mcm24");
3723 if (e_flags & EF_VISIUM_ARCH_GR6)
3724 strcat (buf, ", gr6");
3725 break;
3726
4046d87a 3727 case EM_RL78:
1740ba0c
NC
3728 switch (e_flags & E_FLAG_RL78_CPU_MASK)
3729 {
3730 case E_FLAG_RL78_ANY_CPU: break;
3731 case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
3732 case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
3733 case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
3734 }
856ea05c
KP
3735 if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
3736 strcat (buf, ", 64-bit doubles");
4046d87a 3737 break;
0b4362b0 3738
c7927a3c
NC
3739 case EM_RX:
3740 if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
3741 strcat (buf, ", 64-bit doubles");
3742 if (e_flags & E_FLAG_RX_DSP)
dd24e3da 3743 strcat (buf, ", dsp");
d4cb0ea0 3744 if (e_flags & E_FLAG_RX_PID)
0b4362b0 3745 strcat (buf, ", pid");
708e2187
NC
3746 if (e_flags & E_FLAG_RX_ABI)
3747 strcat (buf, ", RX ABI");
3525236c
NC
3748 if (e_flags & E_FLAG_RX_SINSNS_SET)
3749 strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
3750 ? ", uses String instructions" : ", bans String instructions");
a117b0a5
YS
3751 if (e_flags & E_FLAG_RX_V2)
3752 strcat (buf, ", V2");
f87673e0
YS
3753 if (e_flags & E_FLAG_RX_V3)
3754 strcat (buf, ", V3");
d4cb0ea0 3755 break;
55786da2
AK
3756
3757 case EM_S390:
3758 if (e_flags & EF_S390_HIGH_GPRS)
3759 strcat (buf, ", highgprs");
d4cb0ea0 3760 break;
40b36596
JM
3761
3762 case EM_TI_C6000:
3763 if ((e_flags & EF_C6000_REL))
3764 strcat (buf, ", relocatable module");
d4cb0ea0 3765 break;
13761a11
NC
3766
3767 case EM_MSP430:
3768 strcat (buf, _(": architecture variant: "));
3769 switch (e_flags & EF_MSP430_MACH)
3770 {
3771 case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
3772 case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
3773 case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
3774 case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
3775 case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
3776 case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
3777 case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
3778 case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
3779 case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
3780 case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
3781 case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
3782 case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
3783 case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
3784 case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
3785 case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
3786 default:
3787 strcat (buf, _(": unknown")); break;
3788 }
3789
3790 if (e_flags & ~ EF_MSP430_MACH)
3791 strcat (buf, _(": unknown extra flag bits also present"));
252b5132
RH
3792 }
3793 }
3794
3795 return buf;
3796}
3797
252b5132 3798static const char *
dda8d76d 3799get_osabi_name (Filedata * filedata, unsigned int osabi)
d3ba0551
AM
3800{
3801 static char buff[32];
3802
3803 switch (osabi)
3804 {
3805 case ELFOSABI_NONE: return "UNIX - System V";
3806 case ELFOSABI_HPUX: return "UNIX - HP-UX";
3807 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
9c55345c 3808 case ELFOSABI_GNU: return "UNIX - GNU";
d3ba0551
AM
3809 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
3810 case ELFOSABI_AIX: return "UNIX - AIX";
3811 case ELFOSABI_IRIX: return "UNIX - IRIX";
3812 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
3813 case ELFOSABI_TRU64: return "UNIX - TRU64";
3814 case ELFOSABI_MODESTO: return "Novell - Modesto";
3815 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
3816 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
3817 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
3b26c801 3818 case ELFOSABI_AROS: return "AROS";
11636f9e 3819 case ELFOSABI_FENIXOS: return "FenixOS";
6d913794
NC
3820 case ELFOSABI_CLOUDABI: return "Nuxi CloudABI";
3821 case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS";
d3ba0551 3822 default:
40b36596 3823 if (osabi >= 64)
dda8d76d 3824 switch (filedata->file_header.e_machine)
40b36596 3825 {
abeeff98
LM
3826 case EM_AMDGPU:
3827 switch (osabi)
3828 {
3829 case ELFOSABI_AMDGPU_HSA: return "AMD HSA Runtime";
3830 default:
3831 break;
3832 }
3833 break;
3834
40b36596
JM
3835 case EM_ARM:
3836 switch (osabi)
3837 {
3838 case ELFOSABI_ARM: return "ARM";
18a20338 3839 case ELFOSABI_ARM_FDPIC: return "ARM FDPIC";
40b36596
JM
3840 default:
3841 break;
3842 }
3843 break;
3844
3845 case EM_MSP430:
3846 case EM_MSP430_OLD:
619ed720 3847 case EM_VISIUM:
40b36596
JM
3848 switch (osabi)
3849 {
3850 case ELFOSABI_STANDALONE: return _("Standalone App");
3851 default:
3852 break;
3853 }
3854 break;
3855
3856 case EM_TI_C6000:
3857 switch (osabi)
3858 {
3859 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
3860 case ELFOSABI_C6000_LINUX: return "Linux C6000";
3861 default:
3862 break;
3863 }
3864 break;
3865
3866 default:
3867 break;
3868 }
e9e44622 3869 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
d3ba0551
AM
3870 return buff;
3871 }
3872}
3873
a06ea964
NC
3874static const char *
3875get_aarch64_segment_type (unsigned long type)
3876{
3877 switch (type)
3878 {
32ec8896
NC
3879 case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT";
3880 default: return NULL;
a06ea964 3881 }
a06ea964
NC
3882}
3883
b294bdf8
MM
3884static const char *
3885get_arm_segment_type (unsigned long type)
3886{
3887 switch (type)
3888 {
32ec8896
NC
3889 case PT_ARM_EXIDX: return "EXIDX";
3890 default: return NULL;
b294bdf8 3891 }
b294bdf8
MM
3892}
3893
b4cbbe8f
AK
3894static const char *
3895get_s390_segment_type (unsigned long type)
3896{
3897 switch (type)
3898 {
3899 case PT_S390_PGSTE: return "S390_PGSTE";
3900 default: return NULL;
3901 }
3902}
3903
d3ba0551
AM
3904static const char *
3905get_mips_segment_type (unsigned long type)
252b5132
RH
3906{
3907 switch (type)
3908 {
32ec8896
NC
3909 case PT_MIPS_REGINFO: return "REGINFO";
3910 case PT_MIPS_RTPROC: return "RTPROC";
3911 case PT_MIPS_OPTIONS: return "OPTIONS";
3912 case PT_MIPS_ABIFLAGS: return "ABIFLAGS";
3913 default: return NULL;
252b5132 3914 }
252b5132
RH
3915}
3916
103f02d3 3917static const char *
d3ba0551 3918get_parisc_segment_type (unsigned long type)
103f02d3
UD
3919{
3920 switch (type)
3921 {
103f02d3
UD
3922 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
3923 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
61472819 3924 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
32ec8896 3925 default: return NULL;
103f02d3 3926 }
103f02d3
UD
3927}
3928
4d6ed7c8 3929static const char *
d3ba0551 3930get_ia64_segment_type (unsigned long type)
4d6ed7c8
NC
3931{
3932 switch (type)
3933 {
3934 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
3935 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
32ec8896 3936 default: return NULL;
4d6ed7c8 3937 }
4d6ed7c8
NC
3938}
3939
40b36596
JM
3940static const char *
3941get_tic6x_segment_type (unsigned long type)
3942{
3943 switch (type)
3944 {
32ec8896
NC
3945 case PT_C6000_PHATTR: return "C6000_PHATTR";
3946 default: return NULL;
40b36596 3947 }
40b36596
JM
3948}
3949
df3a023b
AM
3950static const char *
3951get_hpux_segment_type (unsigned long type, unsigned e_machine)
3952{
3953 if (e_machine == EM_PARISC)
3954 switch (type)
3955 {
3956 case PT_HP_TLS: return "HP_TLS";
3957 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
3958 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
3959 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
3960 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
3961 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
3962 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
3963 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
3964 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
3965 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
3966 case PT_HP_PARALLEL: return "HP_PARALLEL";
3967 case PT_HP_FASTBIND: return "HP_FASTBIND";
3968 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
3969 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
3970 case PT_HP_STACK: return "HP_STACK";
3971 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
3972 default: return NULL;
3973 }
3974
3975 if (e_machine == EM_IA_64)
3976 switch (type)
3977 {
3978 case PT_HP_TLS: return "HP_TLS";
3979 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
3980 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
3981 case PT_IA_64_HP_STACK: return "HP_STACK";
3982 default: return NULL;
3983 }
3984
3985 return NULL;
3986}
3987
5522f910
NC
3988static const char *
3989get_solaris_segment_type (unsigned long type)
3990{
3991 switch (type)
3992 {
3993 case 0x6464e550: return "PT_SUNW_UNWIND";
3994 case 0x6474e550: return "PT_SUNW_EH_FRAME";
3995 case 0x6ffffff7: return "PT_LOSUNW";
3996 case 0x6ffffffa: return "PT_SUNWBSS";
3997 case 0x6ffffffb: return "PT_SUNWSTACK";
3998 case 0x6ffffffc: return "PT_SUNWDTRACE";
3999 case 0x6ffffffd: return "PT_SUNWCAP";
4000 case 0x6fffffff: return "PT_HISUNW";
32ec8896 4001 default: return NULL;
5522f910
NC
4002 }
4003}
4004
252b5132 4005static const char *
dda8d76d 4006get_segment_type (Filedata * filedata, unsigned long p_type)
252b5132 4007{
b34976b6 4008 static char buff[32];
252b5132
RH
4009
4010 switch (p_type)
4011 {
b34976b6
AM
4012 case PT_NULL: return "NULL";
4013 case PT_LOAD: return "LOAD";
252b5132 4014 case PT_DYNAMIC: return "DYNAMIC";
b34976b6
AM
4015 case PT_INTERP: return "INTERP";
4016 case PT_NOTE: return "NOTE";
4017 case PT_SHLIB: return "SHLIB";
4018 case PT_PHDR: return "PHDR";
13ae64f3 4019 case PT_TLS: return "TLS";
32ec8896 4020 case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
2b05f1b7 4021 case PT_GNU_STACK: return "GNU_STACK";
8c37241b 4022 case PT_GNU_RELRO: return "GNU_RELRO";
0a59decb 4023 case PT_GNU_PROPERTY: return "GNU_PROPERTY";
65765700 4024
252b5132 4025 default:
df3a023b 4026 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
252b5132 4027 {
2cf0635d 4028 const char * result;
103f02d3 4029
dda8d76d 4030 switch (filedata->file_header.e_machine)
252b5132 4031 {
a06ea964
NC
4032 case EM_AARCH64:
4033 result = get_aarch64_segment_type (p_type);
4034 break;
b294bdf8
MM
4035 case EM_ARM:
4036 result = get_arm_segment_type (p_type);
4037 break;
252b5132 4038 case EM_MIPS:
4fe85591 4039 case EM_MIPS_RS3_LE:
252b5132
RH
4040 result = get_mips_segment_type (p_type);
4041 break;
103f02d3
UD
4042 case EM_PARISC:
4043 result = get_parisc_segment_type (p_type);
4044 break;
4d6ed7c8
NC
4045 case EM_IA_64:
4046 result = get_ia64_segment_type (p_type);
4047 break;
40b36596
JM
4048 case EM_TI_C6000:
4049 result = get_tic6x_segment_type (p_type);
4050 break;
b4cbbe8f
AK
4051 case EM_S390:
4052 case EM_S390_OLD:
4053 result = get_s390_segment_type (p_type);
4054 break;
252b5132
RH
4055 default:
4056 result = NULL;
4057 break;
4058 }
103f02d3 4059
252b5132
RH
4060 if (result != NULL)
4061 return result;
103f02d3 4062
1a9ccd70 4063 sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC);
252b5132
RH
4064 }
4065 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
103f02d3 4066 {
df3a023b 4067 const char * result = NULL;
103f02d3 4068
df3a023b 4069 switch (filedata->file_header.e_ident[EI_OSABI])
103f02d3 4070 {
df3a023b
AM
4071 case ELFOSABI_GNU:
4072 case ELFOSABI_FREEBSD:
4073 if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
4074 {
4075 sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO);
4076 result = buff;
4077 }
103f02d3 4078 break;
df3a023b
AM
4079 case ELFOSABI_HPUX:
4080 result = get_hpux_segment_type (p_type,
4081 filedata->file_header.e_machine);
4082 break;
4083 case ELFOSABI_SOLARIS:
4084 result = get_solaris_segment_type (p_type);
00428cca 4085 break;
103f02d3 4086 default:
103f02d3
UD
4087 break;
4088 }
103f02d3
UD
4089 if (result != NULL)
4090 return result;
4091
1a9ccd70 4092 sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS);
103f02d3 4093 }
252b5132 4094 else
e9e44622 4095 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
252b5132
RH
4096
4097 return buff;
4098 }
4099}
4100
53a346d8
CZ
4101static const char *
4102get_arc_section_type_name (unsigned int sh_type)
4103{
4104 switch (sh_type)
4105 {
4106 case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES";
4107 default:
4108 break;
4109 }
4110 return NULL;
4111}
4112
252b5132 4113static const char *
d3ba0551 4114get_mips_section_type_name (unsigned int sh_type)
252b5132
RH
4115{
4116 switch (sh_type)
4117 {
b34976b6
AM
4118 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
4119 case SHT_MIPS_MSYM: return "MIPS_MSYM";
4120 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
4121 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
4122 case SHT_MIPS_UCODE: return "MIPS_UCODE";
4123 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
4124 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
4125 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
4126 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
4127 case SHT_MIPS_RELD: return "MIPS_RELD";
4128 case SHT_MIPS_IFACE: return "MIPS_IFACE";
4129 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
4130 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
4131 case SHT_MIPS_SHDR: return "MIPS_SHDR";
4132 case SHT_MIPS_FDESC: return "MIPS_FDESC";
4133 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
4134 case SHT_MIPS_DENSE: return "MIPS_DENSE";
4135 case SHT_MIPS_PDESC: return "MIPS_PDESC";
4136 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
4137 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
4138 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
4139 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
4140 case SHT_MIPS_LINE: return "MIPS_LINE";
4141 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
4142 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
4143 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
4144 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
4145 case SHT_MIPS_DWARF: return "MIPS_DWARF";
4146 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
4147 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
4148 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
4149 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
4150 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
4151 case SHT_MIPS_XLATE: return "MIPS_XLATE";
4152 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
4153 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
4154 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
4155 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
252b5132 4156 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
351cdf24 4157 case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
f16a9783 4158 case SHT_MIPS_XHASH: return "MIPS_XHASH";
252b5132
RH
4159 default:
4160 break;
4161 }
4162 return NULL;
4163}
4164
103f02d3 4165static const char *
d3ba0551 4166get_parisc_section_type_name (unsigned int sh_type)
103f02d3
UD
4167{
4168 switch (sh_type)
4169 {
4170 case SHT_PARISC_EXT: return "PARISC_EXT";
4171 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
4172 case SHT_PARISC_DOC: return "PARISC_DOC";
eec8f817
DA
4173 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
4174 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
4175 case SHT_PARISC_STUBS: return "PARISC_STUBS";
61472819 4176 case SHT_PARISC_DLKM: return "PARISC_DLKM";
32ec8896 4177 default: return NULL;
103f02d3 4178 }
103f02d3
UD
4179}
4180
4d6ed7c8 4181static const char *
dda8d76d 4182get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type)
4d6ed7c8 4183{
18bd398b 4184 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
ecc51f48 4185 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
dda8d76d 4186 return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16);
0de14b54 4187
4d6ed7c8
NC
4188 switch (sh_type)
4189 {
148b93f2
NC
4190 case SHT_IA_64_EXT: return "IA_64_EXT";
4191 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
4192 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
4193 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
4194 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
4195 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
4196 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
4197 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
4198 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
4199 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
4d6ed7c8
NC
4200 default:
4201 break;
4202 }
4203 return NULL;
4204}
4205
d2b2c203
DJ
4206static const char *
4207get_x86_64_section_type_name (unsigned int sh_type)
4208{
4209 switch (sh_type)
4210 {
4211 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
32ec8896 4212 default: return NULL;
d2b2c203 4213 }
d2b2c203
DJ
4214}
4215
a06ea964
NC
4216static const char *
4217get_aarch64_section_type_name (unsigned int sh_type)
4218{
4219 switch (sh_type)
4220 {
32ec8896
NC
4221 case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES";
4222 default: return NULL;
a06ea964 4223 }
a06ea964
NC
4224}
4225
40a18ebd
NC
4226static const char *
4227get_arm_section_type_name (unsigned int sh_type)
4228{
4229 switch (sh_type)
4230 {
7f6fed87
NC
4231 case SHT_ARM_EXIDX: return "ARM_EXIDX";
4232 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
4233 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
4234 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
4235 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
32ec8896 4236 default: return NULL;
40a18ebd 4237 }
40a18ebd
NC
4238}
4239
40b36596
JM
4240static const char *
4241get_tic6x_section_type_name (unsigned int sh_type)
4242{
4243 switch (sh_type)
4244 {
32ec8896
NC
4245 case SHT_C6000_UNWIND: return "C6000_UNWIND";
4246 case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
4247 case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES";
4248 case SHT_TI_ICODE: return "TI_ICODE";
4249 case SHT_TI_XREF: return "TI_XREF";
4250 case SHT_TI_HANDLER: return "TI_HANDLER";
4251 case SHT_TI_INITINFO: return "TI_INITINFO";
4252 case SHT_TI_PHATTRS: return "TI_PHATTRS";
4253 default: return NULL;
40b36596 4254 }
40b36596
JM
4255}
4256
13761a11
NC
4257static const char *
4258get_msp430x_section_type_name (unsigned int sh_type)
4259{
4260 switch (sh_type)
4261 {
32ec8896
NC
4262 case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
4263 case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
4264 case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
4265 default: return NULL;
13761a11
NC
4266 }
4267}
4268
fe944acf
FT
4269static const char *
4270get_nfp_section_type_name (unsigned int sh_type)
4271{
4272 switch (sh_type)
4273 {
4274 case SHT_NFP_MECONFIG: return "NFP_MECONFIG";
4275 case SHT_NFP_INITREG: return "NFP_INITREG";
4276 case SHT_NFP_UDEBUG: return "NFP_UDEBUG";
4277 default: return NULL;
4278 }
4279}
4280
685080f2
NC
4281static const char *
4282get_v850_section_type_name (unsigned int sh_type)
4283{
4284 switch (sh_type)
4285 {
32ec8896
NC
4286 case SHT_V850_SCOMMON: return "V850 Small Common";
4287 case SHT_V850_TCOMMON: return "V850 Tiny Common";
4288 case SHT_V850_ZCOMMON: return "V850 Zero Common";
4289 case SHT_RENESAS_IOP: return "RENESAS IOP";
4290 case SHT_RENESAS_INFO: return "RENESAS INFO";
4291 default: return NULL;
685080f2
NC
4292 }
4293}
4294
2dc8dd17
JW
4295static const char *
4296get_riscv_section_type_name (unsigned int sh_type)
4297{
4298 switch (sh_type)
4299 {
4300 case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES";
4301 default: return NULL;
4302 }
4303}
4304
252b5132 4305static const char *
dda8d76d 4306get_section_type_name (Filedata * filedata, unsigned int sh_type)
252b5132 4307{
b34976b6 4308 static char buff[32];
9fb71ee4 4309 const char * result;
252b5132
RH
4310
4311 switch (sh_type)
4312 {
4313 case SHT_NULL: return "NULL";
4314 case SHT_PROGBITS: return "PROGBITS";
4315 case SHT_SYMTAB: return "SYMTAB";
4316 case SHT_STRTAB: return "STRTAB";
4317 case SHT_RELA: return "RELA";
4318 case SHT_HASH: return "HASH";
4319 case SHT_DYNAMIC: return "DYNAMIC";
4320 case SHT_NOTE: return "NOTE";
4321 case SHT_NOBITS: return "NOBITS";
4322 case SHT_REL: return "REL";
4323 case SHT_SHLIB: return "SHLIB";
4324 case SHT_DYNSYM: return "DYNSYM";
d1133906
NC
4325 case SHT_INIT_ARRAY: return "INIT_ARRAY";
4326 case SHT_FINI_ARRAY: return "FINI_ARRAY";
4327 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
fdc90cb4 4328 case SHT_GNU_HASH: return "GNU_HASH";
93ebe586 4329 case SHT_GROUP: return "GROUP";
67ce483b 4330 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES";
252b5132
RH
4331 case SHT_GNU_verdef: return "VERDEF";
4332 case SHT_GNU_verneed: return "VERNEED";
4333 case SHT_GNU_versym: return "VERSYM";
b34976b6
AM
4334 case 0x6ffffff0: return "VERSYM";
4335 case 0x6ffffffc: return "VERDEF";
252b5132
RH
4336 case 0x7ffffffd: return "AUXILIARY";
4337 case 0x7fffffff: return "FILTER";
047b2264 4338 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
252b5132
RH
4339
4340 default:
4341 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
4342 {
dda8d76d 4343 switch (filedata->file_header.e_machine)
252b5132 4344 {
53a346d8
CZ
4345 case EM_ARC:
4346 case EM_ARC_COMPACT:
4347 case EM_ARC_COMPACT2:
4348 result = get_arc_section_type_name (sh_type);
4349 break;
252b5132 4350 case EM_MIPS:
4fe85591 4351 case EM_MIPS_RS3_LE:
252b5132
RH
4352 result = get_mips_section_type_name (sh_type);
4353 break;
103f02d3
UD
4354 case EM_PARISC:
4355 result = get_parisc_section_type_name (sh_type);
4356 break;
4d6ed7c8 4357 case EM_IA_64:
dda8d76d 4358 result = get_ia64_section_type_name (filedata, sh_type);
4d6ed7c8 4359 break;
d2b2c203 4360 case EM_X86_64:
8a9036a4 4361 case EM_L1OM:
7a9068fe 4362 case EM_K1OM:
d2b2c203
DJ
4363 result = get_x86_64_section_type_name (sh_type);
4364 break;
a06ea964
NC
4365 case EM_AARCH64:
4366 result = get_aarch64_section_type_name (sh_type);
4367 break;
40a18ebd
NC
4368 case EM_ARM:
4369 result = get_arm_section_type_name (sh_type);
4370 break;
40b36596
JM
4371 case EM_TI_C6000:
4372 result = get_tic6x_section_type_name (sh_type);
4373 break;
13761a11
NC
4374 case EM_MSP430:
4375 result = get_msp430x_section_type_name (sh_type);
4376 break;
fe944acf
FT
4377 case EM_NFP:
4378 result = get_nfp_section_type_name (sh_type);
4379 break;
685080f2
NC
4380 case EM_V800:
4381 case EM_V850:
4382 case EM_CYGNUS_V850:
4383 result = get_v850_section_type_name (sh_type);
4384 break;
2dc8dd17
JW
4385 case EM_RISCV:
4386 result = get_riscv_section_type_name (sh_type);
4387 break;
252b5132
RH
4388 default:
4389 result = NULL;
4390 break;
4391 }
4392
4393 if (result != NULL)
4394 return result;
4395
9fb71ee4 4396 sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
252b5132
RH
4397 }
4398 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
148b93f2 4399 {
dda8d76d 4400 switch (filedata->file_header.e_machine)
148b93f2
NC
4401 {
4402 case EM_IA_64:
dda8d76d 4403 result = get_ia64_section_type_name (filedata, sh_type);
148b93f2
NC
4404 break;
4405 default:
dda8d76d 4406 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
4407 result = get_solaris_section_type (sh_type);
4408 else
1b4b80bf
NC
4409 {
4410 switch (sh_type)
4411 {
4412 case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break;
4413 case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break;
4414 case SHT_GNU_HASH: result = "GNU_HASH"; break;
4415 case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break;
4416 default:
4417 result = NULL;
4418 break;
4419 }
4420 }
148b93f2
NC
4421 break;
4422 }
4423
4424 if (result != NULL)
4425 return result;
4426
9fb71ee4 4427 sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
148b93f2 4428 }
252b5132 4429 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
685080f2 4430 {
dda8d76d 4431 switch (filedata->file_header.e_machine)
685080f2
NC
4432 {
4433 case EM_V800:
4434 case EM_V850:
4435 case EM_CYGNUS_V850:
9fb71ee4 4436 result = get_v850_section_type_name (sh_type);
a9fb83be 4437 break;
685080f2 4438 default:
9fb71ee4 4439 result = NULL;
685080f2
NC
4440 break;
4441 }
4442
9fb71ee4
NC
4443 if (result != NULL)
4444 return result;
4445
4446 sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
685080f2 4447 }
252b5132 4448 else
a7dbfd1c
NC
4449 /* This message is probably going to be displayed in a 15
4450 character wide field, so put the hex value first. */
4451 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
103f02d3 4452
252b5132
RH
4453 return buff;
4454 }
4455}
4456
2979dc34 4457#define OPTION_DEBUG_DUMP 512
2c610e4b 4458#define OPTION_DYN_SYMS 513
fd2f0033
TT
4459#define OPTION_DWARF_DEPTH 514
4460#define OPTION_DWARF_START 515
4723351a 4461#define OPTION_DWARF_CHECK 516
7d9813f1
NA
4462#define OPTION_CTF_DUMP 517
4463#define OPTION_CTF_PARENT 518
4464#define OPTION_CTF_SYMBOLS 519
4465#define OPTION_CTF_STRINGS 520
2979dc34 4466
85b1c36d 4467static struct option options[] =
252b5132 4468{
b34976b6 4469 {"all", no_argument, 0, 'a'},
252b5132
RH
4470 {"file-header", no_argument, 0, 'h'},
4471 {"program-headers", no_argument, 0, 'l'},
b34976b6
AM
4472 {"headers", no_argument, 0, 'e'},
4473 {"histogram", no_argument, 0, 'I'},
4474 {"segments", no_argument, 0, 'l'},
4475 {"sections", no_argument, 0, 'S'},
252b5132 4476 {"section-headers", no_argument, 0, 'S'},
f5842774 4477 {"section-groups", no_argument, 0, 'g'},
5477e8a0 4478 {"section-details", no_argument, 0, 't'},
595cf52e 4479 {"full-section-name",no_argument, 0, 'N'},
b34976b6
AM
4480 {"symbols", no_argument, 0, 's'},
4481 {"syms", no_argument, 0, 's'},
2c610e4b 4482 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
b34976b6
AM
4483 {"relocs", no_argument, 0, 'r'},
4484 {"notes", no_argument, 0, 'n'},
4485 {"dynamic", no_argument, 0, 'd'},
a952a375 4486 {"arch-specific", no_argument, 0, 'A'},
252b5132
RH
4487 {"version-info", no_argument, 0, 'V'},
4488 {"use-dynamic", no_argument, 0, 'D'},
09c11c86 4489 {"unwind", no_argument, 0, 'u'},
4145f1d5 4490 {"archive-index", no_argument, 0, 'c'},
b34976b6 4491 {"hex-dump", required_argument, 0, 'x'},
cf13d699 4492 {"relocated-dump", required_argument, 0, 'R'},
09c11c86 4493 {"string-dump", required_argument, 0, 'p'},
0e602686 4494 {"decompress", no_argument, 0, 'z'},
252b5132
RH
4495#ifdef SUPPORT_DISASSEMBLY
4496 {"instruction-dump", required_argument, 0, 'i'},
4497#endif
cf13d699 4498 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
252b5132 4499
fd2f0033
TT
4500 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
4501 {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
4723351a 4502 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
fd2f0033 4503
d344b407 4504 {"ctf", required_argument, 0, OPTION_CTF_DUMP},
7d9813f1
NA
4505
4506 {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS},
4507 {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS},
4508 {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT},
4509
b34976b6
AM
4510 {"version", no_argument, 0, 'v'},
4511 {"wide", no_argument, 0, 'W'},
4512 {"help", no_argument, 0, 'H'},
4513 {0, no_argument, 0, 0}
252b5132
RH
4514};
4515
4516static void
2cf0635d 4517usage (FILE * stream)
252b5132 4518{
92f01d61
JM
4519 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
4520 fprintf (stream, _(" Display information about the contents of ELF format files\n"));
4521 fprintf (stream, _(" Options are:\n\
8b53311e
NC
4522 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4523 -h --file-header Display the ELF file header\n\
4524 -l --program-headers Display the program headers\n\
4525 --segments An alias for --program-headers\n\
4526 -S --section-headers Display the sections' header\n\
4527 --sections An alias for --section-headers\n\
f5842774 4528 -g --section-groups Display the section groups\n\
5477e8a0 4529 -t --section-details Display the section details\n\
8b53311e
NC
4530 -e --headers Equivalent to: -h -l -S\n\
4531 -s --syms Display the symbol table\n\
3f08eb35 4532 --symbols An alias for --syms\n\
2c610e4b 4533 --dyn-syms Display the dynamic symbol table\n\
8b53311e
NC
4534 -n --notes Display the core notes (if present)\n\
4535 -r --relocs Display the relocations (if present)\n\
4536 -u --unwind Display the unwind info (if present)\n\
b2d38a17 4537 -d --dynamic Display the dynamic section (if present)\n\
8b53311e 4538 -V --version-info Display the version sections (if present)\n\
1b31d05e 4539 -A --arch-specific Display architecture specific information (if any)\n\
4145f1d5 4540 -c --archive-index Display the symbol/file index in an archive\n\
8b53311e 4541 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
09c11c86
NC
4542 -x --hex-dump=<number|name>\n\
4543 Dump the contents of section <number|name> as bytes\n\
4544 -p --string-dump=<number|name>\n\
4545 Dump the contents of section <number|name> as strings\n\
cf13d699
NC
4546 -R --relocated-dump=<number|name>\n\
4547 Dump the contents of section <number|name> as relocated bytes\n\
0e602686 4548 -z --decompress Decompress section before dumping it\n\
dda8d76d 4549 -w[lLiaprmfFsoRtUuTgAckK] or\n\
1ed06042 4550 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
6f875884 4551 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
657d0d47 4552 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
dda8d76d
NC
4553 =addr,=cu_index,=links,=follow-links]\n\
4554 Display the contents of DWARF debug sections\n"));
fd2f0033
TT
4555 fprintf (stream, _("\
4556 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4557 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4558 or deeper\n"));
7d9813f1
NA
4559 fprintf (stream, _("\
4560 --ctf=<number|name> Display CTF info from section <number|name>\n\
4561 --ctf-parent=<number|name>\n\
4562 Use section <number|name> as the CTF parent\n\n\
4563 --ctf-symbols=<number|name>\n\
4564 Use section <number|name> as the CTF external symtab\n\n\
4565 --ctf-strings=<number|name>\n\
4566 Use section <number|name> as the CTF external strtab\n\n"));
4567
252b5132 4568#ifdef SUPPORT_DISASSEMBLY
92f01d61 4569 fprintf (stream, _("\
09c11c86
NC
4570 -i --instruction-dump=<number|name>\n\
4571 Disassemble the contents of section <number|name>\n"));
252b5132 4572#endif
92f01d61 4573 fprintf (stream, _("\
8b53311e
NC
4574 -I --histogram Display histogram of bucket list lengths\n\
4575 -W --wide Allow output width to exceed 80 characters\n\
07012eee 4576 @<file> Read options from <file>\n\
8b53311e
NC
4577 -H --help Display this information\n\
4578 -v --version Display the version number of readelf\n"));
1118d252 4579
92f01d61
JM
4580 if (REPORT_BUGS_TO[0] && stream == stdout)
4581 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
252b5132 4582
92f01d61 4583 exit (stream == stdout ? 0 : 1);
252b5132
RH
4584}
4585
18bd398b
NC
4586/* Record the fact that the user wants the contents of section number
4587 SECTION to be displayed using the method(s) encoded as flags bits
4588 in TYPE. Note, TYPE can be zero if we are creating the array for
4589 the first time. */
4590
252b5132 4591static void
dda8d76d 4592request_dump_bynumber (Filedata * filedata, unsigned int section, dump_type type)
252b5132 4593{
dda8d76d 4594 if (section >= filedata->num_dump_sects)
252b5132 4595 {
2cf0635d 4596 dump_type * new_dump_sects;
252b5132 4597
3f5e193b 4598 new_dump_sects = (dump_type *) calloc (section + 1,
dda8d76d 4599 sizeof (* new_dump_sects));
252b5132
RH
4600
4601 if (new_dump_sects == NULL)
591a748a 4602 error (_("Out of memory allocating dump request table.\n"));
252b5132
RH
4603 else
4604 {
dda8d76d 4605 if (filedata->dump_sects)
21b65bac
NC
4606 {
4607 /* Copy current flag settings. */
dda8d76d
NC
4608 memcpy (new_dump_sects, filedata->dump_sects,
4609 filedata->num_dump_sects * sizeof (* new_dump_sects));
252b5132 4610
dda8d76d 4611 free (filedata->dump_sects);
21b65bac 4612 }
252b5132 4613
dda8d76d
NC
4614 filedata->dump_sects = new_dump_sects;
4615 filedata->num_dump_sects = section + 1;
252b5132
RH
4616 }
4617 }
4618
dda8d76d
NC
4619 if (filedata->dump_sects)
4620 filedata->dump_sects[section] |= type;
252b5132
RH
4621}
4622
aef1f6d0
DJ
4623/* Request a dump by section name. */
4624
4625static void
2cf0635d 4626request_dump_byname (const char * section, dump_type type)
aef1f6d0 4627{
2cf0635d 4628 struct dump_list_entry * new_request;
aef1f6d0 4629
3f5e193b
NC
4630 new_request = (struct dump_list_entry *)
4631 malloc (sizeof (struct dump_list_entry));
aef1f6d0 4632 if (!new_request)
591a748a 4633 error (_("Out of memory allocating dump request table.\n"));
aef1f6d0
DJ
4634
4635 new_request->name = strdup (section);
4636 if (!new_request->name)
591a748a 4637 error (_("Out of memory allocating dump request table.\n"));
aef1f6d0
DJ
4638
4639 new_request->type = type;
4640
4641 new_request->next = dump_sects_byname;
4642 dump_sects_byname = new_request;
4643}
4644
cf13d699 4645static inline void
dda8d76d 4646request_dump (Filedata * filedata, dump_type type)
cf13d699
NC
4647{
4648 int section;
4649 char * cp;
4650
4651 do_dump++;
4652 section = strtoul (optarg, & cp, 0);
4653
4654 if (! *cp && section >= 0)
dda8d76d 4655 request_dump_bynumber (filedata, section, type);
cf13d699
NC
4656 else
4657 request_dump_byname (optarg, type);
4658}
4659
252b5132 4660static void
dda8d76d 4661parse_args (Filedata * filedata, int argc, char ** argv)
252b5132
RH
4662{
4663 int c;
4664
4665 if (argc < 2)
92f01d61 4666 usage (stderr);
252b5132
RH
4667
4668 while ((c = getopt_long
0e602686 4669 (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
252b5132 4670 {
252b5132
RH
4671 switch (c)
4672 {
4673 case 0:
4674 /* Long options. */
4675 break;
4676 case 'H':
92f01d61 4677 usage (stdout);
252b5132
RH
4678 break;
4679
4680 case 'a':
32ec8896
NC
4681 do_syms = TRUE;
4682 do_reloc = TRUE;
4683 do_unwind = TRUE;
4684 do_dynamic = TRUE;
4685 do_header = TRUE;
4686 do_sections = TRUE;
4687 do_section_groups = TRUE;
4688 do_segments = TRUE;
4689 do_version = TRUE;
4690 do_histogram = TRUE;
4691 do_arch = TRUE;
4692 do_notes = TRUE;
252b5132 4693 break;
f5842774 4694 case 'g':
32ec8896 4695 do_section_groups = TRUE;
f5842774 4696 break;
5477e8a0 4697 case 't':
595cf52e 4698 case 'N':
32ec8896
NC
4699 do_sections = TRUE;
4700 do_section_details = TRUE;
595cf52e 4701 break;
252b5132 4702 case 'e':
32ec8896
NC
4703 do_header = TRUE;
4704 do_sections = TRUE;
4705 do_segments = TRUE;
252b5132 4706 break;
a952a375 4707 case 'A':
32ec8896 4708 do_arch = TRUE;
a952a375 4709 break;
252b5132 4710 case 'D':
32ec8896 4711 do_using_dynamic = TRUE;
252b5132
RH
4712 break;
4713 case 'r':
32ec8896 4714 do_reloc = TRUE;
252b5132 4715 break;
4d6ed7c8 4716 case 'u':
32ec8896 4717 do_unwind = TRUE;
4d6ed7c8 4718 break;
252b5132 4719 case 'h':
32ec8896 4720 do_header = TRUE;
252b5132
RH
4721 break;
4722 case 'l':
32ec8896 4723 do_segments = TRUE;
252b5132
RH
4724 break;
4725 case 's':
32ec8896 4726 do_syms = TRUE;
252b5132
RH
4727 break;
4728 case 'S':
32ec8896 4729 do_sections = TRUE;
252b5132
RH
4730 break;
4731 case 'd':
32ec8896 4732 do_dynamic = TRUE;
252b5132 4733 break;
a952a375 4734 case 'I':
32ec8896 4735 do_histogram = TRUE;
a952a375 4736 break;
779fe533 4737 case 'n':
32ec8896 4738 do_notes = TRUE;
779fe533 4739 break;
4145f1d5 4740 case 'c':
32ec8896 4741 do_archive_index = TRUE;
4145f1d5 4742 break;
252b5132 4743 case 'x':
dda8d76d 4744 request_dump (filedata, HEX_DUMP);
aef1f6d0 4745 break;
09c11c86 4746 case 'p':
dda8d76d 4747 request_dump (filedata, STRING_DUMP);
cf13d699
NC
4748 break;
4749 case 'R':
dda8d76d 4750 request_dump (filedata, RELOC_DUMP);
09c11c86 4751 break;
0e602686 4752 case 'z':
32ec8896 4753 decompress_dumps = TRUE;
0e602686 4754 break;
252b5132 4755 case 'w':
32ec8896 4756 do_dump = TRUE;
252b5132 4757 if (optarg == 0)
613ff48b 4758 {
32ec8896 4759 do_debugging = TRUE;
613ff48b
CC
4760 dwarf_select_sections_all ();
4761 }
252b5132
RH
4762 else
4763 {
32ec8896 4764 do_debugging = FALSE;
4cb93e3b 4765 dwarf_select_sections_by_letters (optarg);
252b5132
RH
4766 }
4767 break;
2979dc34 4768 case OPTION_DEBUG_DUMP:
32ec8896 4769 do_dump = TRUE;
2979dc34 4770 if (optarg == 0)
32ec8896 4771 do_debugging = TRUE;
2979dc34
JJ
4772 else
4773 {
32ec8896 4774 do_debugging = FALSE;
4cb93e3b 4775 dwarf_select_sections_by_names (optarg);
2979dc34
JJ
4776 }
4777 break;
fd2f0033
TT
4778 case OPTION_DWARF_DEPTH:
4779 {
4780 char *cp;
4781
4782 dwarf_cutoff_level = strtoul (optarg, & cp, 0);
4783 }
4784 break;
4785 case OPTION_DWARF_START:
4786 {
4787 char *cp;
4788
4789 dwarf_start_die = strtoul (optarg, & cp, 0);
4790 }
4791 break;
4723351a 4792 case OPTION_DWARF_CHECK:
32ec8896 4793 dwarf_check = TRUE;
4723351a 4794 break;
7d9813f1
NA
4795 case OPTION_CTF_DUMP:
4796 do_ctf = TRUE;
4797 request_dump (filedata, CTF_DUMP);
4798 break;
4799 case OPTION_CTF_SYMBOLS:
4800 dump_ctf_symtab_name = strdup (optarg);
4801 break;
4802 case OPTION_CTF_STRINGS:
4803 dump_ctf_strtab_name = strdup (optarg);
4804 break;
4805 case OPTION_CTF_PARENT:
4806 dump_ctf_parent_name = strdup (optarg);
4807 break;
2c610e4b 4808 case OPTION_DYN_SYMS:
32ec8896 4809 do_dyn_syms = TRUE;
2c610e4b 4810 break;
252b5132
RH
4811#ifdef SUPPORT_DISASSEMBLY
4812 case 'i':
dda8d76d 4813 request_dump (filedata, DISASS_DUMP);
cf13d699 4814 break;
252b5132
RH
4815#endif
4816 case 'v':
4817 print_version (program_name);
4818 break;
4819 case 'V':
32ec8896 4820 do_version = TRUE;
252b5132 4821 break;
d974e256 4822 case 'W':
32ec8896 4823 do_wide = TRUE;
d974e256 4824 break;
252b5132 4825 default:
252b5132
RH
4826 /* xgettext:c-format */
4827 error (_("Invalid option '-%c'\n"), c);
1a0670f3 4828 /* Fall through. */
252b5132 4829 case '?':
92f01d61 4830 usage (stderr);
252b5132
RH
4831 }
4832 }
4833
4d6ed7c8 4834 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
252b5132 4835 && !do_segments && !do_header && !do_dump && !do_version
f5842774 4836 && !do_histogram && !do_debugging && !do_arch && !do_notes
2c610e4b
L
4837 && !do_section_groups && !do_archive_index
4838 && !do_dyn_syms)
92f01d61 4839 usage (stderr);
252b5132
RH
4840}
4841
4842static const char *
d3ba0551 4843get_elf_class (unsigned int elf_class)
252b5132 4844{
b34976b6 4845 static char buff[32];
103f02d3 4846
252b5132
RH
4847 switch (elf_class)
4848 {
4849 case ELFCLASSNONE: return _("none");
e3c8793a
NC
4850 case ELFCLASS32: return "ELF32";
4851 case ELFCLASS64: return "ELF64";
ab5e7794 4852 default:
e9e44622 4853 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
ab5e7794 4854 return buff;
252b5132
RH
4855 }
4856}
4857
4858static const char *
d3ba0551 4859get_data_encoding (unsigned int encoding)
252b5132 4860{
b34976b6 4861 static char buff[32];
103f02d3 4862
252b5132
RH
4863 switch (encoding)
4864 {
4865 case ELFDATANONE: return _("none");
33c63f9d
CM
4866 case ELFDATA2LSB: return _("2's complement, little endian");
4867 case ELFDATA2MSB: return _("2's complement, big endian");
103f02d3 4868 default:
e9e44622 4869 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
ab5e7794 4870 return buff;
252b5132
RH
4871 }
4872}
4873
dda8d76d 4874/* Decode the data held in 'filedata->file_header'. */
ee42cf8c 4875
32ec8896 4876static bfd_boolean
dda8d76d 4877process_file_header (Filedata * filedata)
252b5132 4878{
dda8d76d
NC
4879 Elf_Internal_Ehdr * header = & filedata->file_header;
4880
4881 if ( header->e_ident[EI_MAG0] != ELFMAG0
4882 || header->e_ident[EI_MAG1] != ELFMAG1
4883 || header->e_ident[EI_MAG2] != ELFMAG2
4884 || header->e_ident[EI_MAG3] != ELFMAG3)
252b5132
RH
4885 {
4886 error
4887 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
32ec8896 4888 return FALSE;
252b5132
RH
4889 }
4890
955ff7fc 4891 init_dwarf_regnames_by_elf_machine_code (header->e_machine);
2dc4cec1 4892
252b5132
RH
4893 if (do_header)
4894 {
32ec8896 4895 unsigned i;
252b5132
RH
4896
4897 printf (_("ELF Header:\n"));
4898 printf (_(" Magic: "));
b34976b6 4899 for (i = 0; i < EI_NIDENT; i++)
dda8d76d 4900 printf ("%2.2x ", header->e_ident[i]);
252b5132
RH
4901 printf ("\n");
4902 printf (_(" Class: %s\n"),
dda8d76d 4903 get_elf_class (header->e_ident[EI_CLASS]));
252b5132 4904 printf (_(" Data: %s\n"),
dda8d76d 4905 get_data_encoding (header->e_ident[EI_DATA]));
e8a64888 4906 printf (_(" Version: %d%s\n"),
dda8d76d
NC
4907 header->e_ident[EI_VERSION],
4908 (header->e_ident[EI_VERSION] == EV_CURRENT
e8a64888 4909 ? _(" (current)")
dda8d76d 4910 : (header->e_ident[EI_VERSION] != EV_NONE
e8a64888 4911 ? _(" <unknown>")
789be9f7 4912 : "")));
252b5132 4913 printf (_(" OS/ABI: %s\n"),
dda8d76d 4914 get_osabi_name (filedata, header->e_ident[EI_OSABI]));
252b5132 4915 printf (_(" ABI Version: %d\n"),
dda8d76d 4916 header->e_ident[EI_ABIVERSION]);
252b5132 4917 printf (_(" Type: %s\n"),
dda8d76d 4918 get_file_type (header->e_type));
252b5132 4919 printf (_(" Machine: %s\n"),
dda8d76d 4920 get_machine_name (header->e_machine));
252b5132 4921 printf (_(" Version: 0x%lx\n"),
e8a64888 4922 header->e_version);
76da6bbe 4923
f7a99963 4924 printf (_(" Entry point address: "));
e8a64888 4925 print_vma (header->e_entry, PREFIX_HEX);
f7a99963 4926 printf (_("\n Start of program headers: "));
e8a64888 4927 print_vma (header->e_phoff, DEC);
f7a99963 4928 printf (_(" (bytes into file)\n Start of section headers: "));
e8a64888 4929 print_vma (header->e_shoff, DEC);
f7a99963 4930 printf (_(" (bytes into file)\n"));
76da6bbe 4931
252b5132 4932 printf (_(" Flags: 0x%lx%s\n"),
e8a64888 4933 header->e_flags,
dda8d76d 4934 get_machine_flags (filedata, header->e_flags, header->e_machine));
e8a64888
AM
4935 printf (_(" Size of this header: %u (bytes)\n"),
4936 header->e_ehsize);
4937 printf (_(" Size of program headers: %u (bytes)\n"),
4938 header->e_phentsize);
4939 printf (_(" Number of program headers: %u"),
4940 header->e_phnum);
dda8d76d
NC
4941 if (filedata->section_headers != NULL
4942 && header->e_phnum == PN_XNUM
4943 && filedata->section_headers[0].sh_info != 0)
e8a64888
AM
4944 {
4945 header->e_phnum = filedata->section_headers[0].sh_info;
4946 printf (" (%u)", header->e_phnum);
4947 }
2046a35d 4948 putc ('\n', stdout);
e8a64888
AM
4949 printf (_(" Size of section headers: %u (bytes)\n"),
4950 header->e_shentsize);
4951 printf (_(" Number of section headers: %u"),
4952 header->e_shnum);
dda8d76d 4953 if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF)
e8a64888
AM
4954 {
4955 header->e_shnum = filedata->section_headers[0].sh_size;
4956 printf (" (%u)", header->e_shnum);
4957 }
560f3c1c 4958 putc ('\n', stdout);
e8a64888
AM
4959 printf (_(" Section header string table index: %u"),
4960 header->e_shstrndx);
dda8d76d
NC
4961 if (filedata->section_headers != NULL
4962 && header->e_shstrndx == (SHN_XINDEX & 0xffff))
e8a64888
AM
4963 {
4964 header->e_shstrndx = filedata->section_headers[0].sh_link;
4965 printf (" (%u)", header->e_shstrndx);
4966 }
4967 if (header->e_shstrndx != SHN_UNDEF
4968 && header->e_shstrndx >= header->e_shnum)
4969 {
4970 header->e_shstrndx = SHN_UNDEF;
4971 printf (_(" <corrupt: out of range>"));
4972 }
560f3c1c
AM
4973 putc ('\n', stdout);
4974 }
4975
dda8d76d 4976 if (filedata->section_headers != NULL)
560f3c1c 4977 {
dda8d76d
NC
4978 if (header->e_phnum == PN_XNUM
4979 && filedata->section_headers[0].sh_info != 0)
4980 header->e_phnum = filedata->section_headers[0].sh_info;
4981 if (header->e_shnum == SHN_UNDEF)
4982 header->e_shnum = filedata->section_headers[0].sh_size;
4983 if (header->e_shstrndx == (SHN_XINDEX & 0xffff))
4984 header->e_shstrndx = filedata->section_headers[0].sh_link;
9c1ce108 4985 if (header->e_shstrndx >= header->e_shnum)
dda8d76d
NC
4986 header->e_shstrndx = SHN_UNDEF;
4987 free (filedata->section_headers);
4988 filedata->section_headers = NULL;
252b5132 4989 }
103f02d3 4990
32ec8896 4991 return TRUE;
9ea033b2
NC
4992}
4993
dda8d76d
NC
4994/* Read in the program headers from FILEDATA and store them in PHEADERS.
4995 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
4996
e0a31db1 4997static bfd_boolean
dda8d76d 4998get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
9ea033b2 4999{
2cf0635d
NC
5000 Elf32_External_Phdr * phdrs;
5001 Elf32_External_Phdr * external;
5002 Elf_Internal_Phdr * internal;
b34976b6 5003 unsigned int i;
dda8d76d
NC
5004 unsigned int size = filedata->file_header.e_phentsize;
5005 unsigned int num = filedata->file_header.e_phnum;
e0a31db1
NC
5006
5007 /* PR binutils/17531: Cope with unexpected section header sizes. */
5008 if (size == 0 || num == 0)
5009 return FALSE;
5010 if (size < sizeof * phdrs)
5011 {
5012 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5013 return FALSE;
5014 }
5015 if (size > sizeof * phdrs)
5016 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
103f02d3 5017
dda8d76d 5018 phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
e0a31db1
NC
5019 size, num, _("program headers"));
5020 if (phdrs == NULL)
5021 return FALSE;
9ea033b2 5022
91d6fa6a 5023 for (i = 0, internal = pheaders, external = phdrs;
dda8d76d 5024 i < filedata->file_header.e_phnum;
b34976b6 5025 i++, internal++, external++)
252b5132 5026 {
9ea033b2
NC
5027 internal->p_type = BYTE_GET (external->p_type);
5028 internal->p_offset = BYTE_GET (external->p_offset);
5029 internal->p_vaddr = BYTE_GET (external->p_vaddr);
5030 internal->p_paddr = BYTE_GET (external->p_paddr);
5031 internal->p_filesz = BYTE_GET (external->p_filesz);
5032 internal->p_memsz = BYTE_GET (external->p_memsz);
5033 internal->p_flags = BYTE_GET (external->p_flags);
5034 internal->p_align = BYTE_GET (external->p_align);
252b5132
RH
5035 }
5036
9ea033b2 5037 free (phdrs);
e0a31db1 5038 return TRUE;
252b5132
RH
5039}
5040
dda8d76d
NC
5041/* Read in the program headers from FILEDATA and store them in PHEADERS.
5042 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5043
e0a31db1 5044static bfd_boolean
dda8d76d 5045get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
9ea033b2 5046{
2cf0635d
NC
5047 Elf64_External_Phdr * phdrs;
5048 Elf64_External_Phdr * external;
5049 Elf_Internal_Phdr * internal;
b34976b6 5050 unsigned int i;
dda8d76d
NC
5051 unsigned int size = filedata->file_header.e_phentsize;
5052 unsigned int num = filedata->file_header.e_phnum;
e0a31db1
NC
5053
5054 /* PR binutils/17531: Cope with unexpected section header sizes. */
5055 if (size == 0 || num == 0)
5056 return FALSE;
5057 if (size < sizeof * phdrs)
5058 {
5059 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5060 return FALSE;
5061 }
5062 if (size > sizeof * phdrs)
5063 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
103f02d3 5064
dda8d76d 5065 phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
e0a31db1 5066 size, num, _("program headers"));
a6e9f9df 5067 if (!phdrs)
e0a31db1 5068 return FALSE;
9ea033b2 5069
91d6fa6a 5070 for (i = 0, internal = pheaders, external = phdrs;
dda8d76d 5071 i < filedata->file_header.e_phnum;
b34976b6 5072 i++, internal++, external++)
9ea033b2
NC
5073 {
5074 internal->p_type = BYTE_GET (external->p_type);
5075 internal->p_flags = BYTE_GET (external->p_flags);
66543521
AM
5076 internal->p_offset = BYTE_GET (external->p_offset);
5077 internal->p_vaddr = BYTE_GET (external->p_vaddr);
5078 internal->p_paddr = BYTE_GET (external->p_paddr);
5079 internal->p_filesz = BYTE_GET (external->p_filesz);
5080 internal->p_memsz = BYTE_GET (external->p_memsz);
5081 internal->p_align = BYTE_GET (external->p_align);
9ea033b2
NC
5082 }
5083
5084 free (phdrs);
e0a31db1 5085 return TRUE;
9ea033b2 5086}
252b5132 5087
32ec8896 5088/* Returns TRUE if the program headers were read into `program_headers'. */
d93f0186 5089
32ec8896 5090static bfd_boolean
dda8d76d 5091get_program_headers (Filedata * filedata)
d93f0186 5092{
2cf0635d 5093 Elf_Internal_Phdr * phdrs;
d93f0186
NC
5094
5095 /* Check cache of prior read. */
dda8d76d 5096 if (filedata->program_headers != NULL)
32ec8896 5097 return TRUE;
d93f0186 5098
82156ab7
NC
5099 /* Be kind to memory checkers by looking for
5100 e_phnum values which we know must be invalid. */
dda8d76d 5101 if (filedata->file_header.e_phnum
82156ab7 5102 * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr))
dda8d76d 5103 >= filedata->file_size)
82156ab7
NC
5104 {
5105 error (_("Too many program headers - %#x - the file is not that big\n"),
dda8d76d 5106 filedata->file_header.e_phnum);
82156ab7
NC
5107 return FALSE;
5108 }
d93f0186 5109
dda8d76d 5110 phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum,
82156ab7 5111 sizeof (Elf_Internal_Phdr));
d93f0186
NC
5112 if (phdrs == NULL)
5113 {
8b73c356 5114 error (_("Out of memory reading %u program headers\n"),
dda8d76d 5115 filedata->file_header.e_phnum);
32ec8896 5116 return FALSE;
d93f0186
NC
5117 }
5118
5119 if (is_32bit_elf
dda8d76d
NC
5120 ? get_32bit_program_headers (filedata, phdrs)
5121 : get_64bit_program_headers (filedata, phdrs))
d93f0186 5122 {
dda8d76d 5123 filedata->program_headers = phdrs;
32ec8896 5124 return TRUE;
d93f0186
NC
5125 }
5126
5127 free (phdrs);
32ec8896 5128 return FALSE;
d93f0186
NC
5129}
5130
32ec8896 5131/* Returns TRUE if the program headers were loaded. */
2f62977e 5132
32ec8896 5133static bfd_boolean
dda8d76d 5134process_program_headers (Filedata * filedata)
252b5132 5135{
2cf0635d 5136 Elf_Internal_Phdr * segment;
b34976b6 5137 unsigned int i;
1a9ccd70 5138 Elf_Internal_Phdr * previous_load = NULL;
252b5132 5139
663f67df
AM
5140 dynamic_addr = 0;
5141 dynamic_size = 0;
5142
dda8d76d 5143 if (filedata->file_header.e_phnum == 0)
252b5132 5144 {
82f2dbf7 5145 /* PR binutils/12467. */
dda8d76d 5146 if (filedata->file_header.e_phoff != 0)
32ec8896
NC
5147 {
5148 warn (_("possibly corrupt ELF header - it has a non-zero program"
5149 " header offset, but no program headers\n"));
5150 return FALSE;
5151 }
82f2dbf7 5152 else if (do_segments)
252b5132 5153 printf (_("\nThere are no program headers in this file.\n"));
32ec8896 5154 return TRUE;
252b5132
RH
5155 }
5156
5157 if (do_segments && !do_header)
5158 {
dda8d76d
NC
5159 printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type));
5160 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry));
d3a49aa8
AM
5161 printf (ngettext ("There is %d program header, starting at offset %s\n",
5162 "There are %d program headers, starting at offset %s\n",
dda8d76d
NC
5163 filedata->file_header.e_phnum),
5164 filedata->file_header.e_phnum,
5165 bfd_vmatoa ("u", filedata->file_header.e_phoff));
252b5132
RH
5166 }
5167
dda8d76d 5168 if (! get_program_headers (filedata))
6b4bf3bc 5169 return TRUE;
103f02d3 5170
252b5132
RH
5171 if (do_segments)
5172 {
dda8d76d 5173 if (filedata->file_header.e_phnum > 1)
3a1a2036
NC
5174 printf (_("\nProgram Headers:\n"));
5175 else
5176 printf (_("\nProgram Headers:\n"));
76da6bbe 5177
f7a99963
NC
5178 if (is_32bit_elf)
5179 printf
5180 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
d974e256
JJ
5181 else if (do_wide)
5182 printf
5183 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
f7a99963
NC
5184 else
5185 {
5186 printf
5187 (_(" Type Offset VirtAddr PhysAddr\n"));
5188 printf
5189 (_(" FileSiz MemSiz Flags Align\n"));
5190 }
252b5132
RH
5191 }
5192
dda8d76d
NC
5193 for (i = 0, segment = filedata->program_headers;
5194 i < filedata->file_header.e_phnum;
b34976b6 5195 i++, segment++)
252b5132
RH
5196 {
5197 if (do_segments)
5198 {
dda8d76d 5199 printf (" %-14.14s ", get_segment_type (filedata, segment->p_type));
f7a99963
NC
5200
5201 if (is_32bit_elf)
5202 {
5203 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5204 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
5205 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
5206 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
5207 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
5208 printf ("%c%c%c ",
5209 (segment->p_flags & PF_R ? 'R' : ' '),
5210 (segment->p_flags & PF_W ? 'W' : ' '),
5211 (segment->p_flags & PF_X ? 'E' : ' '));
5212 printf ("%#lx", (unsigned long) segment->p_align);
5213 }
d974e256
JJ
5214 else if (do_wide)
5215 {
5216 if ((unsigned long) segment->p_offset == segment->p_offset)
5217 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5218 else
5219 {
5220 print_vma (segment->p_offset, FULL_HEX);
5221 putchar (' ');
5222 }
5223
5224 print_vma (segment->p_vaddr, FULL_HEX);
5225 putchar (' ');
5226 print_vma (segment->p_paddr, FULL_HEX);
5227 putchar (' ');
5228
5229 if ((unsigned long) segment->p_filesz == segment->p_filesz)
5230 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
5231 else
5232 {
5233 print_vma (segment->p_filesz, FULL_HEX);
5234 putchar (' ');
5235 }
5236
5237 if ((unsigned long) segment->p_memsz == segment->p_memsz)
5238 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
5239 else
5240 {
f48e6c45 5241 print_vma (segment->p_memsz, FULL_HEX);
d974e256
JJ
5242 }
5243
5244 printf (" %c%c%c ",
5245 (segment->p_flags & PF_R ? 'R' : ' '),
5246 (segment->p_flags & PF_W ? 'W' : ' '),
5247 (segment->p_flags & PF_X ? 'E' : ' '));
5248
5249 if ((unsigned long) segment->p_align == segment->p_align)
5250 printf ("%#lx", (unsigned long) segment->p_align);
5251 else
5252 {
5253 print_vma (segment->p_align, PREFIX_HEX);
5254 }
5255 }
f7a99963
NC
5256 else
5257 {
5258 print_vma (segment->p_offset, FULL_HEX);
5259 putchar (' ');
5260 print_vma (segment->p_vaddr, FULL_HEX);
5261 putchar (' ');
5262 print_vma (segment->p_paddr, FULL_HEX);
5263 printf ("\n ");
5264 print_vma (segment->p_filesz, FULL_HEX);
5265 putchar (' ');
5266 print_vma (segment->p_memsz, FULL_HEX);
5267 printf (" %c%c%c ",
5268 (segment->p_flags & PF_R ? 'R' : ' '),
5269 (segment->p_flags & PF_W ? 'W' : ' '),
5270 (segment->p_flags & PF_X ? 'E' : ' '));
1d262527 5271 print_vma (segment->p_align, PREFIX_HEX);
f7a99963 5272 }
252b5132 5273
1a9ccd70
NC
5274 putc ('\n', stdout);
5275 }
f54498b4 5276
252b5132
RH
5277 switch (segment->p_type)
5278 {
1a9ccd70 5279 case PT_LOAD:
502d895c
NC
5280#if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5281 required by the ELF standard, several programs, including the Linux
5282 kernel, make use of non-ordered segments. */
1a9ccd70
NC
5283 if (previous_load
5284 && previous_load->p_vaddr > segment->p_vaddr)
5285 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
502d895c 5286#endif
1a9ccd70
NC
5287 if (segment->p_memsz < segment->p_filesz)
5288 error (_("the segment's file size is larger than its memory size\n"));
5289 previous_load = segment;
5290 break;
5291
5292 case PT_PHDR:
5293 /* PR 20815 - Verify that the program header is loaded into memory. */
5294 if (i > 0 && previous_load != NULL)
5295 error (_("the PHDR segment must occur before any LOAD segment\n"));
dda8d76d 5296 if (filedata->file_header.e_machine != EM_PARISC)
1a9ccd70
NC
5297 {
5298 unsigned int j;
5299
dda8d76d 5300 for (j = 1; j < filedata->file_header.e_phnum; j++)
c0c121b0
AM
5301 {
5302 Elf_Internal_Phdr *load = filedata->program_headers + j;
5303 if (load->p_type == PT_LOAD
5304 && load->p_offset <= segment->p_offset
5305 && (load->p_offset + load->p_filesz
5306 >= segment->p_offset + segment->p_filesz)
5307 && load->p_vaddr <= segment->p_vaddr
5308 && (load->p_vaddr + load->p_filesz
5309 >= segment->p_vaddr + segment->p_filesz))
5310 break;
5311 }
dda8d76d 5312 if (j == filedata->file_header.e_phnum)
1a9ccd70
NC
5313 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5314 }
5315 break;
5316
252b5132
RH
5317 case PT_DYNAMIC:
5318 if (dynamic_addr)
5319 error (_("more than one dynamic segment\n"));
5320
20737c13
AM
5321 /* By default, assume that the .dynamic section is the first
5322 section in the DYNAMIC segment. */
5323 dynamic_addr = segment->p_offset;
5324 dynamic_size = segment->p_filesz;
5325
b2d38a17
NC
5326 /* Try to locate the .dynamic section. If there is
5327 a section header table, we can easily locate it. */
dda8d76d 5328 if (filedata->section_headers != NULL)
b2d38a17 5329 {
2cf0635d 5330 Elf_Internal_Shdr * sec;
b2d38a17 5331
dda8d76d 5332 sec = find_section (filedata, ".dynamic");
89fac5e3 5333 if (sec == NULL || sec->sh_size == 0)
b2d38a17 5334 {
28f997cf
TG
5335 /* A corresponding .dynamic section is expected, but on
5336 IA-64/OpenVMS it is OK for it to be missing. */
dda8d76d 5337 if (!is_ia64_vms (filedata))
28f997cf 5338 error (_("no .dynamic section in the dynamic segment\n"));
b2d38a17
NC
5339 break;
5340 }
5341
42bb2e33 5342 if (sec->sh_type == SHT_NOBITS)
20737c13
AM
5343 {
5344 dynamic_size = 0;
5345 break;
5346 }
42bb2e33 5347
b2d38a17
NC
5348 dynamic_addr = sec->sh_offset;
5349 dynamic_size = sec->sh_size;
5350
5351 if (dynamic_addr < segment->p_offset
5352 || dynamic_addr > segment->p_offset + segment->p_filesz)
20737c13
AM
5353 warn (_("the .dynamic section is not contained"
5354 " within the dynamic segment\n"));
b2d38a17 5355 else if (dynamic_addr > segment->p_offset)
20737c13
AM
5356 warn (_("the .dynamic section is not the first section"
5357 " in the dynamic segment.\n"));
b2d38a17 5358 }
39e224f6
MW
5359
5360 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5361 segment. Check this after matching against the section headers
5362 so we don't warn on debuginfo file (which have NOBITS .dynamic
5363 sections). */
c22b42ce
AM
5364 if (dynamic_addr > filedata->file_size
5365 || dynamic_size > filedata->file_size - dynamic_addr)
39e224f6
MW
5366 {
5367 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5368 dynamic_addr = dynamic_size = 0;
5369 }
252b5132
RH
5370 break;
5371
5372 case PT_INTERP:
dda8d76d 5373 if (fseek (filedata->handle, archive_file_offset + (long) segment->p_offset,
fb52b2f4 5374 SEEK_SET))
252b5132
RH
5375 error (_("Unable to find program interpreter name\n"));
5376 else
5377 {
f8eae8b2 5378 char fmt [32];
9495b2e6 5379 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
f8eae8b2
L
5380
5381 if (ret >= (int) sizeof (fmt) || ret < 0)
591a748a 5382 error (_("Internal error: failed to create format string to display program interpreter\n"));
f8eae8b2 5383
252b5132 5384 program_interpreter[0] = 0;
dda8d76d 5385 if (fscanf (filedata->handle, fmt, program_interpreter) <= 0)
7bd7b3ef 5386 error (_("Unable to read program interpreter name\n"));
252b5132
RH
5387
5388 if (do_segments)
f54498b4 5389 printf (_(" [Requesting program interpreter: %s]\n"),
252b5132
RH
5390 program_interpreter);
5391 }
5392 break;
5393 }
252b5132
RH
5394 }
5395
dda8d76d
NC
5396 if (do_segments
5397 && filedata->section_headers != NULL
5398 && filedata->string_table != NULL)
252b5132
RH
5399 {
5400 printf (_("\n Section to Segment mapping:\n"));
5401 printf (_(" Segment Sections...\n"));
5402
dda8d76d 5403 for (i = 0; i < filedata->file_header.e_phnum; i++)
252b5132 5404 {
9ad5cbcf 5405 unsigned int j;
2cf0635d 5406 Elf_Internal_Shdr * section;
252b5132 5407
dda8d76d
NC
5408 segment = filedata->program_headers + i;
5409 section = filedata->section_headers + 1;
252b5132
RH
5410
5411 printf (" %2.2d ", i);
5412
dda8d76d 5413 for (j = 1; j < filedata->file_header.e_shnum; j++, section++)
252b5132 5414 {
f4638467
AM
5415 if (!ELF_TBSS_SPECIAL (section, segment)
5416 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
dda8d76d 5417 printf ("%s ", printable_section_name (filedata, section));
252b5132
RH
5418 }
5419
5420 putc ('\n',stdout);
5421 }
5422 }
5423
32ec8896 5424 return TRUE;
252b5132
RH
5425}
5426
5427
d93f0186
NC
5428/* Find the file offset corresponding to VMA by using the program headers. */
5429
5430static long
dda8d76d 5431offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size)
d93f0186 5432{
2cf0635d 5433 Elf_Internal_Phdr * seg;
d93f0186 5434
dda8d76d 5435 if (! get_program_headers (filedata))
d93f0186
NC
5436 {
5437 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5438 return (long) vma;
5439 }
5440
dda8d76d
NC
5441 for (seg = filedata->program_headers;
5442 seg < filedata->program_headers + filedata->file_header.e_phnum;
d93f0186
NC
5443 ++seg)
5444 {
5445 if (seg->p_type != PT_LOAD)
5446 continue;
5447
5448 if (vma >= (seg->p_vaddr & -seg->p_align)
5449 && vma + size <= seg->p_vaddr + seg->p_filesz)
5450 return vma - seg->p_vaddr + seg->p_offset;
5451 }
5452
5453 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
0af1713e 5454 (unsigned long) vma);
d93f0186
NC
5455 return (long) vma;
5456}
5457
5458
dda8d76d
NC
5459/* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5460 If PROBE is true, this is just a probe and we do not generate any error
5461 messages if the load fails. */
049b0c3a
NC
5462
5463static bfd_boolean
dda8d76d 5464get_32bit_section_headers (Filedata * filedata, bfd_boolean probe)
252b5132 5465{
2cf0635d
NC
5466 Elf32_External_Shdr * shdrs;
5467 Elf_Internal_Shdr * internal;
dda8d76d
NC
5468 unsigned int i;
5469 unsigned int size = filedata->file_header.e_shentsize;
5470 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
049b0c3a
NC
5471
5472 /* PR binutils/17531: Cope with unexpected section header sizes. */
5473 if (size == 0 || num == 0)
5474 return FALSE;
5475 if (size < sizeof * shdrs)
5476 {
5477 if (! probe)
5478 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5479 return FALSE;
5480 }
5481 if (!probe && size > sizeof * shdrs)
5482 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
252b5132 5483
dda8d76d 5484 shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff,
049b0c3a
NC
5485 size, num,
5486 probe ? NULL : _("section headers"));
5487 if (shdrs == NULL)
5488 return FALSE;
252b5132 5489
dda8d76d
NC
5490 free (filedata->section_headers);
5491 filedata->section_headers = (Elf_Internal_Shdr *)
5492 cmalloc (num, sizeof (Elf_Internal_Shdr));
5493 if (filedata->section_headers == NULL)
252b5132 5494 {
049b0c3a 5495 if (!probe)
8b73c356 5496 error (_("Out of memory reading %u section headers\n"), num);
e3d39609 5497 free (shdrs);
049b0c3a 5498 return FALSE;
252b5132
RH
5499 }
5500
dda8d76d 5501 for (i = 0, internal = filedata->section_headers;
560f3c1c 5502 i < num;
b34976b6 5503 i++, internal++)
252b5132
RH
5504 {
5505 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5506 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
5507 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5508 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5509 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5510 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5511 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5512 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5513 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
5514 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
315350be
NC
5515 if (!probe && internal->sh_link > num)
5516 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5517 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5518 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
252b5132
RH
5519 }
5520
5521 free (shdrs);
049b0c3a 5522 return TRUE;
252b5132
RH
5523}
5524
dda8d76d
NC
5525/* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5526
049b0c3a 5527static bfd_boolean
dda8d76d 5528get_64bit_section_headers (Filedata * filedata, bfd_boolean probe)
9ea033b2 5529{
dda8d76d
NC
5530 Elf64_External_Shdr * shdrs;
5531 Elf_Internal_Shdr * internal;
5532 unsigned int i;
5533 unsigned int size = filedata->file_header.e_shentsize;
5534 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
049b0c3a
NC
5535
5536 /* PR binutils/17531: Cope with unexpected section header sizes. */
5537 if (size == 0 || num == 0)
5538 return FALSE;
dda8d76d 5539
049b0c3a
NC
5540 if (size < sizeof * shdrs)
5541 {
5542 if (! probe)
5543 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5544 return FALSE;
5545 }
dda8d76d 5546
049b0c3a
NC
5547 if (! probe && size > sizeof * shdrs)
5548 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
9ea033b2 5549
dda8d76d
NC
5550 shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata,
5551 filedata->file_header.e_shoff,
049b0c3a
NC
5552 size, num,
5553 probe ? NULL : _("section headers"));
5554 if (shdrs == NULL)
5555 return FALSE;
9ea033b2 5556
dda8d76d
NC
5557 free (filedata->section_headers);
5558 filedata->section_headers = (Elf_Internal_Shdr *)
5559 cmalloc (num, sizeof (Elf_Internal_Shdr));
5560 if (filedata->section_headers == NULL)
9ea033b2 5561 {
049b0c3a 5562 if (! probe)
8b73c356 5563 error (_("Out of memory reading %u section headers\n"), num);
e3d39609 5564 free (shdrs);
049b0c3a 5565 return FALSE;
9ea033b2
NC
5566 }
5567
dda8d76d 5568 for (i = 0, internal = filedata->section_headers;
560f3c1c 5569 i < num;
b34976b6 5570 i++, internal++)
9ea033b2
NC
5571 {
5572 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5573 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
66543521
AM
5574 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5575 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5576 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5577 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
9ea033b2
NC
5578 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5579 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5580 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5581 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
315350be
NC
5582 if (!probe && internal->sh_link > num)
5583 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5584 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5585 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
9ea033b2
NC
5586 }
5587
5588 free (shdrs);
049b0c3a 5589 return TRUE;
9ea033b2
NC
5590}
5591
252b5132 5592static Elf_Internal_Sym *
dda8d76d
NC
5593get_32bit_elf_symbols (Filedata * filedata,
5594 Elf_Internal_Shdr * section,
5595 unsigned long * num_syms_return)
252b5132 5596{
ba5cdace 5597 unsigned long number = 0;
dd24e3da 5598 Elf32_External_Sym * esyms = NULL;
ba5cdace 5599 Elf_External_Sym_Shndx * shndx = NULL;
dd24e3da 5600 Elf_Internal_Sym * isyms = NULL;
2cf0635d 5601 Elf_Internal_Sym * psym;
b34976b6 5602 unsigned int j;
e3d39609 5603 elf_section_list * entry;
252b5132 5604
c9c1d674
EG
5605 if (section->sh_size == 0)
5606 {
5607 if (num_syms_return != NULL)
5608 * num_syms_return = 0;
5609 return NULL;
5610 }
5611
dd24e3da 5612 /* Run some sanity checks first. */
c9c1d674 5613 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
dd24e3da 5614 {
c9c1d674 5615 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
dda8d76d
NC
5616 printable_section_name (filedata, section),
5617 (unsigned long) section->sh_entsize);
ba5cdace 5618 goto exit_point;
dd24e3da
NC
5619 }
5620
dda8d76d 5621 if (section->sh_size > filedata->file_size)
f54498b4
NC
5622 {
5623 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
dda8d76d
NC
5624 printable_section_name (filedata, section),
5625 (unsigned long) section->sh_size);
f54498b4
NC
5626 goto exit_point;
5627 }
5628
dd24e3da
NC
5629 number = section->sh_size / section->sh_entsize;
5630
5631 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
5632 {
c9c1d674 5633 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
8066deb1 5634 (unsigned long) section->sh_size,
dda8d76d 5635 printable_section_name (filedata, section),
8066deb1 5636 (unsigned long) section->sh_entsize);
ba5cdace 5637 goto exit_point;
dd24e3da
NC
5638 }
5639
dda8d76d 5640 esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
3f5e193b 5641 section->sh_size, _("symbols"));
dd24e3da 5642 if (esyms == NULL)
ba5cdace 5643 goto exit_point;
252b5132 5644
e3d39609
NC
5645 shndx = NULL;
5646 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5647 {
5648 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5649 continue;
5650
5651 if (shndx != NULL)
5652 {
5653 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5654 free (shndx);
5655 }
5656
5657 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5658 entry->hdr->sh_offset,
5659 1, entry->hdr->sh_size,
5660 _("symbol table section indices"));
5661 if (shndx == NULL)
5662 goto exit_point;
5663
5664 /* PR17531: file: heap-buffer-overflow */
5665 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5666 {
5667 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5668 printable_section_name (filedata, entry->hdr),
5669 (unsigned long) entry->hdr->sh_size,
5670 (unsigned long) section->sh_size);
5671 goto exit_point;
c9c1d674 5672 }
e3d39609 5673 }
9ad5cbcf 5674
3f5e193b 5675 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
252b5132
RH
5676
5677 if (isyms == NULL)
5678 {
8b73c356
NC
5679 error (_("Out of memory reading %lu symbols\n"),
5680 (unsigned long) number);
dd24e3da 5681 goto exit_point;
252b5132
RH
5682 }
5683
dd24e3da 5684 for (j = 0, psym = isyms; j < number; j++, psym++)
252b5132
RH
5685 {
5686 psym->st_name = BYTE_GET (esyms[j].st_name);
5687 psym->st_value = BYTE_GET (esyms[j].st_value);
5688 psym->st_size = BYTE_GET (esyms[j].st_size);
5689 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
4fbb74a6 5690 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
9ad5cbcf
AM
5691 psym->st_shndx
5692 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4fbb74a6
AM
5693 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5694 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
252b5132
RH
5695 psym->st_info = BYTE_GET (esyms[j].st_info);
5696 psym->st_other = BYTE_GET (esyms[j].st_other);
5697 }
5698
dd24e3da 5699 exit_point:
e3d39609
NC
5700 free (shndx);
5701 free (esyms);
252b5132 5702
ba5cdace
NC
5703 if (num_syms_return != NULL)
5704 * num_syms_return = isyms == NULL ? 0 : number;
5705
252b5132
RH
5706 return isyms;
5707}
5708
9ea033b2 5709static Elf_Internal_Sym *
dda8d76d
NC
5710get_64bit_elf_symbols (Filedata * filedata,
5711 Elf_Internal_Shdr * section,
5712 unsigned long * num_syms_return)
9ea033b2 5713{
ba5cdace
NC
5714 unsigned long number = 0;
5715 Elf64_External_Sym * esyms = NULL;
5716 Elf_External_Sym_Shndx * shndx = NULL;
5717 Elf_Internal_Sym * isyms = NULL;
2cf0635d 5718 Elf_Internal_Sym * psym;
b34976b6 5719 unsigned int j;
e3d39609 5720 elf_section_list * entry;
9ea033b2 5721
c9c1d674
EG
5722 if (section->sh_size == 0)
5723 {
5724 if (num_syms_return != NULL)
5725 * num_syms_return = 0;
5726 return NULL;
5727 }
5728
dd24e3da 5729 /* Run some sanity checks first. */
c9c1d674 5730 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
dd24e3da 5731 {
c9c1d674 5732 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
dda8d76d 5733 printable_section_name (filedata, section),
8066deb1 5734 (unsigned long) section->sh_entsize);
ba5cdace 5735 goto exit_point;
dd24e3da
NC
5736 }
5737
dda8d76d 5738 if (section->sh_size > filedata->file_size)
f54498b4
NC
5739 {
5740 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
dda8d76d 5741 printable_section_name (filedata, section),
8066deb1 5742 (unsigned long) section->sh_size);
f54498b4
NC
5743 goto exit_point;
5744 }
5745
dd24e3da
NC
5746 number = section->sh_size / section->sh_entsize;
5747
5748 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
5749 {
c9c1d674 5750 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
8066deb1 5751 (unsigned long) section->sh_size,
dda8d76d 5752 printable_section_name (filedata, section),
8066deb1 5753 (unsigned long) section->sh_entsize);
ba5cdace 5754 goto exit_point;
dd24e3da
NC
5755 }
5756
dda8d76d 5757 esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
3f5e193b 5758 section->sh_size, _("symbols"));
a6e9f9df 5759 if (!esyms)
ba5cdace 5760 goto exit_point;
9ea033b2 5761
e3d39609
NC
5762 shndx = NULL;
5763 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5764 {
5765 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5766 continue;
5767
5768 if (shndx != NULL)
5769 {
5770 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5771 free (shndx);
c9c1d674 5772 }
e3d39609
NC
5773
5774 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5775 entry->hdr->sh_offset,
5776 1, entry->hdr->sh_size,
5777 _("symbol table section indices"));
5778 if (shndx == NULL)
5779 goto exit_point;
5780
5781 /* PR17531: file: heap-buffer-overflow */
5782 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5783 {
5784 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5785 printable_section_name (filedata, entry->hdr),
5786 (unsigned long) entry->hdr->sh_size,
5787 (unsigned long) section->sh_size);
5788 goto exit_point;
5789 }
5790 }
9ad5cbcf 5791
3f5e193b 5792 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
9ea033b2
NC
5793
5794 if (isyms == NULL)
5795 {
8b73c356
NC
5796 error (_("Out of memory reading %lu symbols\n"),
5797 (unsigned long) number);
ba5cdace 5798 goto exit_point;
9ea033b2
NC
5799 }
5800
ba5cdace 5801 for (j = 0, psym = isyms; j < number; j++, psym++)
9ea033b2
NC
5802 {
5803 psym->st_name = BYTE_GET (esyms[j].st_name);
5804 psym->st_info = BYTE_GET (esyms[j].st_info);
5805 psym->st_other = BYTE_GET (esyms[j].st_other);
5806 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
ba5cdace 5807
4fbb74a6 5808 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
9ad5cbcf
AM
5809 psym->st_shndx
5810 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4fbb74a6
AM
5811 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5812 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
ba5cdace 5813
66543521
AM
5814 psym->st_value = BYTE_GET (esyms[j].st_value);
5815 psym->st_size = BYTE_GET (esyms[j].st_size);
9ea033b2
NC
5816 }
5817
ba5cdace 5818 exit_point:
e3d39609
NC
5819 free (shndx);
5820 free (esyms);
ba5cdace
NC
5821
5822 if (num_syms_return != NULL)
5823 * num_syms_return = isyms == NULL ? 0 : number;
9ea033b2
NC
5824
5825 return isyms;
5826}
5827
d1133906 5828static const char *
dda8d76d 5829get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
d1133906 5830{
5477e8a0 5831 static char buff[1024];
2cf0635d 5832 char * p = buff;
32ec8896
NC
5833 unsigned int field_size = is_32bit_elf ? 8 : 16;
5834 signed int sindex;
5835 unsigned int size = sizeof (buff) - (field_size + 4 + 1);
8d5ff12c
L
5836 bfd_vma os_flags = 0;
5837 bfd_vma proc_flags = 0;
5838 bfd_vma unknown_flags = 0;
148b93f2 5839 static const struct
5477e8a0 5840 {
2cf0635d 5841 const char * str;
32ec8896 5842 unsigned int len;
5477e8a0
L
5843 }
5844 flags [] =
5845 {
cfcac11d
NC
5846 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
5847 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
5848 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
5849 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
5850 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
5851 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
5852 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
5853 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
5854 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
5855 /* 9 */ { STRING_COMMA_LEN ("TLS") },
5856 /* IA-64 specific. */
5857 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
5858 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
5859 /* IA-64 OpenVMS specific. */
5860 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
5861 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
5862 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
5863 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
5864 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
5865 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
18ae9cc1 5866 /* Generic. */
cfcac11d 5867 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
18ae9cc1 5868 /* SPARC specific. */
77115a4a 5869 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
ac4c9b04
MG
5870 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
5871 /* ARM specific. */
5872 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
f0728ee3 5873 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
a91e1603
L
5874 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
5875 /* GNU specific. */
5876 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
83eef883
AFB
5877 /* VLE specific. */
5878 /* 25 */ { STRING_COMMA_LEN ("VLE") },
5477e8a0
L
5879 };
5880
5881 if (do_section_details)
5882 {
8d5ff12c
L
5883 sprintf (buff, "[%*.*lx]: ",
5884 field_size, field_size, (unsigned long) sh_flags);
5885 p += field_size + 4;
5477e8a0 5886 }
76da6bbe 5887
d1133906
NC
5888 while (sh_flags)
5889 {
5890 bfd_vma flag;
5891
5892 flag = sh_flags & - sh_flags;
5893 sh_flags &= ~ flag;
76da6bbe 5894
5477e8a0 5895 if (do_section_details)
d1133906 5896 {
5477e8a0
L
5897 switch (flag)
5898 {
91d6fa6a
NC
5899 case SHF_WRITE: sindex = 0; break;
5900 case SHF_ALLOC: sindex = 1; break;
5901 case SHF_EXECINSTR: sindex = 2; break;
5902 case SHF_MERGE: sindex = 3; break;
5903 case SHF_STRINGS: sindex = 4; break;
5904 case SHF_INFO_LINK: sindex = 5; break;
5905 case SHF_LINK_ORDER: sindex = 6; break;
5906 case SHF_OS_NONCONFORMING: sindex = 7; break;
5907 case SHF_GROUP: sindex = 8; break;
5908 case SHF_TLS: sindex = 9; break;
18ae9cc1 5909 case SHF_EXCLUDE: sindex = 18; break;
77115a4a 5910 case SHF_COMPRESSED: sindex = 20; break;
a91e1603 5911 case SHF_GNU_MBIND: sindex = 24; break;
76da6bbe 5912
5477e8a0 5913 default:
91d6fa6a 5914 sindex = -1;
dda8d76d 5915 switch (filedata->file_header.e_machine)
148b93f2 5916 {
cfcac11d 5917 case EM_IA_64:
148b93f2 5918 if (flag == SHF_IA_64_SHORT)
91d6fa6a 5919 sindex = 10;
148b93f2 5920 else if (flag == SHF_IA_64_NORECOV)
91d6fa6a 5921 sindex = 11;
148b93f2 5922#ifdef BFD64
dda8d76d 5923 else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
148b93f2
NC
5924 switch (flag)
5925 {
91d6fa6a
NC
5926 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
5927 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
5928 case SHF_IA_64_VMS_SHARED: sindex = 14; break;
5929 case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
5930 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
5931 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
148b93f2
NC
5932 default: break;
5933 }
5934#endif
cfcac11d
NC
5935 break;
5936
caa83f8b 5937 case EM_386:
22abe556 5938 case EM_IAMCU:
caa83f8b 5939 case EM_X86_64:
7f502d6c 5940 case EM_L1OM:
7a9068fe 5941 case EM_K1OM:
cfcac11d
NC
5942 case EM_OLD_SPARCV9:
5943 case EM_SPARC32PLUS:
5944 case EM_SPARCV9:
5945 case EM_SPARC:
18ae9cc1 5946 if (flag == SHF_ORDERED)
91d6fa6a 5947 sindex = 19;
cfcac11d 5948 break;
ac4c9b04
MG
5949
5950 case EM_ARM:
5951 switch (flag)
5952 {
5953 case SHF_ENTRYSECT: sindex = 21; break;
f0728ee3 5954 case SHF_ARM_PURECODE: sindex = 22; break;
ac4c9b04
MG
5955 case SHF_COMDEF: sindex = 23; break;
5956 default: break;
5957 }
5958 break;
83eef883
AFB
5959 case EM_PPC:
5960 if (flag == SHF_PPC_VLE)
5961 sindex = 25;
5962 break;
ac4c9b04 5963
cfcac11d
NC
5964 default:
5965 break;
148b93f2 5966 }
5477e8a0
L
5967 }
5968
91d6fa6a 5969 if (sindex != -1)
5477e8a0 5970 {
8d5ff12c
L
5971 if (p != buff + field_size + 4)
5972 {
5973 if (size < (10 + 2))
bee0ee85
NC
5974 {
5975 warn (_("Internal error: not enough buffer room for section flag info"));
5976 return _("<unknown>");
5977 }
8d5ff12c
L
5978 size -= 2;
5979 *p++ = ',';
5980 *p++ = ' ';
5981 }
5982
91d6fa6a
NC
5983 size -= flags [sindex].len;
5984 p = stpcpy (p, flags [sindex].str);
5477e8a0 5985 }
3b22753a 5986 else if (flag & SHF_MASKOS)
8d5ff12c 5987 os_flags |= flag;
d1133906 5988 else if (flag & SHF_MASKPROC)
8d5ff12c 5989 proc_flags |= flag;
d1133906 5990 else
8d5ff12c 5991 unknown_flags |= flag;
5477e8a0
L
5992 }
5993 else
5994 {
5995 switch (flag)
5996 {
5997 case SHF_WRITE: *p = 'W'; break;
5998 case SHF_ALLOC: *p = 'A'; break;
5999 case SHF_EXECINSTR: *p = 'X'; break;
6000 case SHF_MERGE: *p = 'M'; break;
6001 case SHF_STRINGS: *p = 'S'; break;
6002 case SHF_INFO_LINK: *p = 'I'; break;
6003 case SHF_LINK_ORDER: *p = 'L'; break;
6004 case SHF_OS_NONCONFORMING: *p = 'O'; break;
6005 case SHF_GROUP: *p = 'G'; break;
6006 case SHF_TLS: *p = 'T'; break;
18ae9cc1 6007 case SHF_EXCLUDE: *p = 'E'; break;
77115a4a 6008 case SHF_COMPRESSED: *p = 'C'; break;
a91e1603 6009 case SHF_GNU_MBIND: *p = 'D'; break;
5477e8a0
L
6010
6011 default:
dda8d76d
NC
6012 if ((filedata->file_header.e_machine == EM_X86_64
6013 || filedata->file_header.e_machine == EM_L1OM
6014 || filedata->file_header.e_machine == EM_K1OM)
5477e8a0
L
6015 && flag == SHF_X86_64_LARGE)
6016 *p = 'l';
dda8d76d 6017 else if (filedata->file_header.e_machine == EM_ARM
f0728ee3 6018 && flag == SHF_ARM_PURECODE)
91f68a68 6019 *p = 'y';
dda8d76d 6020 else if (filedata->file_header.e_machine == EM_PPC
83eef883
AFB
6021 && flag == SHF_PPC_VLE)
6022 *p = 'v';
5477e8a0
L
6023 else if (flag & SHF_MASKOS)
6024 {
6025 *p = 'o';
6026 sh_flags &= ~ SHF_MASKOS;
6027 }
6028 else if (flag & SHF_MASKPROC)
6029 {
6030 *p = 'p';
6031 sh_flags &= ~ SHF_MASKPROC;
6032 }
6033 else
6034 *p = 'x';
6035 break;
6036 }
6037 p++;
d1133906
NC
6038 }
6039 }
76da6bbe 6040
8d5ff12c
L
6041 if (do_section_details)
6042 {
6043 if (os_flags)
6044 {
6045 size -= 5 + field_size;
6046 if (p != buff + field_size + 4)
6047 {
6048 if (size < (2 + 1))
bee0ee85
NC
6049 {
6050 warn (_("Internal error: not enough buffer room for section flag info"));
6051 return _("<unknown>");
6052 }
8d5ff12c
L
6053 size -= 2;
6054 *p++ = ',';
6055 *p++ = ' ';
6056 }
6057 sprintf (p, "OS (%*.*lx)", field_size, field_size,
6058 (unsigned long) os_flags);
6059 p += 5 + field_size;
6060 }
6061 if (proc_flags)
6062 {
6063 size -= 7 + field_size;
6064 if (p != buff + field_size + 4)
6065 {
6066 if (size < (2 + 1))
bee0ee85
NC
6067 {
6068 warn (_("Internal error: not enough buffer room for section flag info"));
6069 return _("<unknown>");
6070 }
8d5ff12c
L
6071 size -= 2;
6072 *p++ = ',';
6073 *p++ = ' ';
6074 }
6075 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
6076 (unsigned long) proc_flags);
6077 p += 7 + field_size;
6078 }
6079 if (unknown_flags)
6080 {
6081 size -= 10 + field_size;
6082 if (p != buff + field_size + 4)
6083 {
6084 if (size < (2 + 1))
bee0ee85
NC
6085 {
6086 warn (_("Internal error: not enough buffer room for section flag info"));
6087 return _("<unknown>");
6088 }
8d5ff12c
L
6089 size -= 2;
6090 *p++ = ',';
6091 *p++ = ' ';
6092 }
2b692964 6093 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
8d5ff12c
L
6094 (unsigned long) unknown_flags);
6095 p += 10 + field_size;
6096 }
6097 }
6098
e9e44622 6099 *p = '\0';
d1133906
NC
6100 return buff;
6101}
6102
77115a4a 6103static unsigned int
ebdf1ebf 6104get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size)
77115a4a
L
6105{
6106 if (is_32bit_elf)
6107 {
6108 Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
d8024a91 6109
ebdf1ebf
NC
6110 if (size < sizeof (* echdr))
6111 {
6112 error (_("Compressed section is too small even for a compression header\n"));
6113 return 0;
6114 }
6115
77115a4a
L
6116 chdr->ch_type = BYTE_GET (echdr->ch_type);
6117 chdr->ch_size = BYTE_GET (echdr->ch_size);
6118 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6119 return sizeof (*echdr);
6120 }
6121 else
6122 {
6123 Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
d8024a91 6124
ebdf1ebf
NC
6125 if (size < sizeof (* echdr))
6126 {
6127 error (_("Compressed section is too small even for a compression header\n"));
6128 return 0;
6129 }
6130
77115a4a
L
6131 chdr->ch_type = BYTE_GET (echdr->ch_type);
6132 chdr->ch_size = BYTE_GET (echdr->ch_size);
6133 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6134 return sizeof (*echdr);
6135 }
6136}
6137
32ec8896 6138static bfd_boolean
dda8d76d 6139process_section_headers (Filedata * filedata)
252b5132 6140{
2cf0635d 6141 Elf_Internal_Shdr * section;
b34976b6 6142 unsigned int i;
252b5132 6143
dda8d76d 6144 filedata->section_headers = NULL;
252b5132 6145
dda8d76d 6146 if (filedata->file_header.e_shnum == 0)
252b5132 6147 {
82f2dbf7 6148 /* PR binutils/12467. */
dda8d76d 6149 if (filedata->file_header.e_shoff != 0)
32ec8896
NC
6150 {
6151 warn (_("possibly corrupt ELF file header - it has a non-zero"
6152 " section header offset, but no section headers\n"));
6153 return FALSE;
6154 }
82f2dbf7 6155 else if (do_sections)
252b5132
RH
6156 printf (_("\nThere are no sections in this file.\n"));
6157
32ec8896 6158 return TRUE;
252b5132
RH
6159 }
6160
6161 if (do_sections && !do_header)
d3a49aa8
AM
6162 printf (ngettext ("There is %d section header, "
6163 "starting at offset 0x%lx:\n",
6164 "There are %d section headers, "
6165 "starting at offset 0x%lx:\n",
dda8d76d
NC
6166 filedata->file_header.e_shnum),
6167 filedata->file_header.e_shnum,
6168 (unsigned long) filedata->file_header.e_shoff);
252b5132 6169
9ea033b2
NC
6170 if (is_32bit_elf)
6171 {
dda8d76d 6172 if (! get_32bit_section_headers (filedata, FALSE))
32ec8896
NC
6173 return FALSE;
6174 }
6175 else
6176 {
dda8d76d 6177 if (! get_64bit_section_headers (filedata, FALSE))
32ec8896 6178 return FALSE;
9ea033b2 6179 }
252b5132
RH
6180
6181 /* Read in the string table, so that we have names to display. */
dda8d76d
NC
6182 if (filedata->file_header.e_shstrndx != SHN_UNDEF
6183 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
252b5132 6184 {
dda8d76d 6185 section = filedata->section_headers + filedata->file_header.e_shstrndx;
d40ac9bd 6186
c256ffe7
JJ
6187 if (section->sh_size != 0)
6188 {
dda8d76d
NC
6189 filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset,
6190 1, section->sh_size,
6191 _("string table"));
0de14b54 6192
dda8d76d 6193 filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0;
c256ffe7 6194 }
252b5132
RH
6195 }
6196
6197 /* Scan the sections for the dynamic symbol table
e3c8793a 6198 and dynamic string table and debug sections. */
252b5132
RH
6199 dynamic_symbols = NULL;
6200 dynamic_strings = NULL;
6201 dynamic_syminfo = NULL;
6a40cf0c 6202 symtab_shndx_list = NULL;
103f02d3 6203
89fac5e3 6204 eh_addr_size = is_32bit_elf ? 4 : 8;
dda8d76d 6205 switch (filedata->file_header.e_machine)
89fac5e3
RS
6206 {
6207 case EM_MIPS:
6208 case EM_MIPS_RS3_LE:
6209 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6210 FDE addresses. However, the ABI also has a semi-official ILP32
6211 variant for which the normal FDE address size rules apply.
6212
6213 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6214 section, where XX is the size of longs in bits. Unfortunately,
6215 earlier compilers provided no way of distinguishing ILP32 objects
6216 from LP64 objects, so if there's any doubt, we should assume that
6217 the official LP64 form is being used. */
dda8d76d
NC
6218 if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
6219 && find_section (filedata, ".gcc_compiled_long32") == NULL)
89fac5e3
RS
6220 eh_addr_size = 8;
6221 break;
0f56a26a
DD
6222
6223 case EM_H8_300:
6224 case EM_H8_300H:
dda8d76d 6225 switch (filedata->file_header.e_flags & EF_H8_MACH)
0f56a26a
DD
6226 {
6227 case E_H8_MACH_H8300:
6228 case E_H8_MACH_H8300HN:
6229 case E_H8_MACH_H8300SN:
6230 case E_H8_MACH_H8300SXN:
6231 eh_addr_size = 2;
6232 break;
6233 case E_H8_MACH_H8300H:
6234 case E_H8_MACH_H8300S:
6235 case E_H8_MACH_H8300SX:
6236 eh_addr_size = 4;
6237 break;
6238 }
f4236fe4
DD
6239 break;
6240
ff7eeb89 6241 case EM_M32C_OLD:
f4236fe4 6242 case EM_M32C:
dda8d76d 6243 switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK)
f4236fe4
DD
6244 {
6245 case EF_M32C_CPU_M16C:
6246 eh_addr_size = 2;
6247 break;
6248 }
6249 break;
89fac5e3
RS
6250 }
6251
76ca31c0
NC
6252#define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6253 do \
6254 { \
6255 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6256 if (section->sh_entsize != expected_entsize) \
9dd3a467 6257 { \
76ca31c0
NC
6258 char buf[40]; \
6259 sprintf_vma (buf, section->sh_entsize); \
6260 /* Note: coded this way so that there is a single string for \
6261 translation. */ \
6262 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6263 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6264 (unsigned) expected_entsize); \
9dd3a467 6265 section->sh_entsize = expected_entsize; \
76ca31c0
NC
6266 } \
6267 } \
08d8fa11 6268 while (0)
9dd3a467
NC
6269
6270#define CHECK_ENTSIZE(section, i, type) \
08d8fa11
JJ
6271 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6272 sizeof (Elf64_External_##type))
6273
dda8d76d
NC
6274 for (i = 0, section = filedata->section_headers;
6275 i < filedata->file_header.e_shnum;
b34976b6 6276 i++, section++)
252b5132 6277 {
2cf0635d 6278 char * name = SECTION_NAME (section);
252b5132
RH
6279
6280 if (section->sh_type == SHT_DYNSYM)
6281 {
6282 if (dynamic_symbols != NULL)
6283 {
6284 error (_("File contains multiple dynamic symbol tables\n"));
6285 continue;
6286 }
6287
08d8fa11 6288 CHECK_ENTSIZE (section, i, Sym);
dda8d76d 6289 dynamic_symbols = GET_ELF_SYMBOLS (filedata, section, & num_dynamic_syms);
252b5132
RH
6290 }
6291 else if (section->sh_type == SHT_STRTAB
18bd398b 6292 && streq (name, ".dynstr"))
252b5132
RH
6293 {
6294 if (dynamic_strings != NULL)
6295 {
6296 error (_("File contains multiple dynamic string tables\n"));
6297 continue;
6298 }
6299
dda8d76d 6300 dynamic_strings = (char *) get_data (NULL, filedata, section->sh_offset,
3f5e193b
NC
6301 1, section->sh_size,
6302 _("dynamic strings"));
59245841 6303 dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
252b5132 6304 }
9ad5cbcf
AM
6305 else if (section->sh_type == SHT_SYMTAB_SHNDX)
6306 {
6a40cf0c 6307 elf_section_list * entry = xmalloc (sizeof * entry);
dda8d76d 6308
6a40cf0c
NC
6309 entry->hdr = section;
6310 entry->next = symtab_shndx_list;
6311 symtab_shndx_list = entry;
9ad5cbcf 6312 }
08d8fa11
JJ
6313 else if (section->sh_type == SHT_SYMTAB)
6314 CHECK_ENTSIZE (section, i, Sym);
6315 else if (section->sh_type == SHT_GROUP)
6316 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
6317 else if (section->sh_type == SHT_REL)
6318 CHECK_ENTSIZE (section, i, Rel);
6319 else if (section->sh_type == SHT_RELA)
6320 CHECK_ENTSIZE (section, i, Rela);
252b5132 6321 else if ((do_debugging || do_debug_info || do_debug_abbrevs
f9f0e732 6322 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
cb8f3167 6323 || do_debug_aranges || do_debug_frames || do_debug_macinfo
657d0d47 6324 || do_debug_str || do_debug_loc || do_debug_ranges
d85bf2ba 6325 || do_debug_addr || do_debug_cu_index || do_debug_links)
1b315056
CS
6326 && (const_strneq (name, ".debug_")
6327 || const_strneq (name, ".zdebug_")))
252b5132 6328 {
1b315056
CS
6329 if (name[1] == 'z')
6330 name += sizeof (".zdebug_") - 1;
6331 else
6332 name += sizeof (".debug_") - 1;
252b5132
RH
6333
6334 if (do_debugging
4723351a
CC
6335 || (do_debug_info && const_strneq (name, "info"))
6336 || (do_debug_info && const_strneq (name, "types"))
6337 || (do_debug_abbrevs && const_strneq (name, "abbrev"))
b40bf0a2
NC
6338 || (do_debug_lines && strcmp (name, "line") == 0)
6339 || (do_debug_lines && const_strneq (name, "line."))
4723351a
CC
6340 || (do_debug_pubnames && const_strneq (name, "pubnames"))
6341 || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
459d52c8
DE
6342 || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
6343 || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
4723351a
CC
6344 || (do_debug_aranges && const_strneq (name, "aranges"))
6345 || (do_debug_ranges && const_strneq (name, "ranges"))
77145576 6346 || (do_debug_ranges && const_strneq (name, "rnglists"))
4723351a
CC
6347 || (do_debug_frames && const_strneq (name, "frame"))
6348 || (do_debug_macinfo && const_strneq (name, "macinfo"))
6349 || (do_debug_macinfo && const_strneq (name, "macro"))
6350 || (do_debug_str && const_strneq (name, "str"))
6351 || (do_debug_loc && const_strneq (name, "loc"))
77145576 6352 || (do_debug_loc && const_strneq (name, "loclists"))
657d0d47
CC
6353 || (do_debug_addr && const_strneq (name, "addr"))
6354 || (do_debug_cu_index && const_strneq (name, "cu_index"))
6355 || (do_debug_cu_index && const_strneq (name, "tu_index"))
252b5132 6356 )
dda8d76d 6357 request_dump_bynumber (filedata, i, DEBUG_DUMP);
252b5132 6358 }
a262ae96 6359 /* Linkonce section to be combined with .debug_info at link time. */
09fd7e38 6360 else if ((do_debugging || do_debug_info)
0112cd26 6361 && const_strneq (name, ".gnu.linkonce.wi."))
dda8d76d 6362 request_dump_bynumber (filedata, i, DEBUG_DUMP);
18bd398b 6363 else if (do_debug_frames && streq (name, ".eh_frame"))
dda8d76d 6364 request_dump_bynumber (filedata, i, DEBUG_DUMP);
61364358
JK
6365 else if (do_gdb_index && (streq (name, ".gdb_index")
6366 || streq (name, ".debug_names")))
dda8d76d 6367 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6f875884
TG
6368 /* Trace sections for Itanium VMS. */
6369 else if ((do_debugging || do_trace_info || do_trace_abbrevs
6370 || do_trace_aranges)
6371 && const_strneq (name, ".trace_"))
6372 {
6373 name += sizeof (".trace_") - 1;
6374
6375 if (do_debugging
6376 || (do_trace_info && streq (name, "info"))
6377 || (do_trace_abbrevs && streq (name, "abbrev"))
6378 || (do_trace_aranges && streq (name, "aranges"))
6379 )
dda8d76d 6380 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6f875884 6381 }
dda8d76d
NC
6382 else if ((do_debugging || do_debug_links)
6383 && (const_strneq (name, ".gnu_debuglink")
6384 || const_strneq (name, ".gnu_debugaltlink")))
6385 request_dump_bynumber (filedata, i, DEBUG_DUMP);
252b5132
RH
6386 }
6387
6388 if (! do_sections)
32ec8896 6389 return TRUE;
252b5132 6390
dda8d76d 6391 if (filedata->file_header.e_shnum > 1)
3a1a2036
NC
6392 printf (_("\nSection Headers:\n"));
6393 else
6394 printf (_("\nSection Header:\n"));
76da6bbe 6395
f7a99963 6396 if (is_32bit_elf)
595cf52e 6397 {
5477e8a0 6398 if (do_section_details)
595cf52e
L
6399 {
6400 printf (_(" [Nr] Name\n"));
5477e8a0 6401 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
595cf52e
L
6402 }
6403 else
6404 printf
6405 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6406 }
d974e256 6407 else if (do_wide)
595cf52e 6408 {
5477e8a0 6409 if (do_section_details)
595cf52e
L
6410 {
6411 printf (_(" [Nr] Name\n"));
5477e8a0 6412 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
595cf52e
L
6413 }
6414 else
6415 printf
6416 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6417 }
f7a99963
NC
6418 else
6419 {
5477e8a0 6420 if (do_section_details)
595cf52e
L
6421 {
6422 printf (_(" [Nr] Name\n"));
5477e8a0
L
6423 printf (_(" Type Address Offset Link\n"));
6424 printf (_(" Size EntSize Info Align\n"));
595cf52e
L
6425 }
6426 else
6427 {
6428 printf (_(" [Nr] Name Type Address Offset\n"));
6429 printf (_(" Size EntSize Flags Link Info Align\n"));
6430 }
f7a99963 6431 }
252b5132 6432
5477e8a0
L
6433 if (do_section_details)
6434 printf (_(" Flags\n"));
6435
dda8d76d
NC
6436 for (i = 0, section = filedata->section_headers;
6437 i < filedata->file_header.e_shnum;
b34976b6 6438 i++, section++)
252b5132 6439 {
dd905818
NC
6440 /* Run some sanity checks on the section header. */
6441
6442 /* Check the sh_link field. */
6443 switch (section->sh_type)
6444 {
285e3f99
AM
6445 case SHT_REL:
6446 case SHT_RELA:
6447 if (section->sh_link == 0
6448 && (filedata->file_header.e_type == ET_EXEC
6449 || filedata->file_header.e_type == ET_DYN))
6450 /* A dynamic relocation section where all entries use a
6451 zero symbol index need not specify a symtab section. */
6452 break;
6453 /* Fall through. */
dd905818
NC
6454 case SHT_SYMTAB_SHNDX:
6455 case SHT_GROUP:
6456 case SHT_HASH:
6457 case SHT_GNU_HASH:
6458 case SHT_GNU_versym:
285e3f99 6459 if (section->sh_link == 0
dda8d76d
NC
6460 || section->sh_link >= filedata->file_header.e_shnum
6461 || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB
6462 && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM))
dd905818
NC
6463 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6464 i, section->sh_link);
6465 break;
6466
6467 case SHT_DYNAMIC:
6468 case SHT_SYMTAB:
6469 case SHT_DYNSYM:
6470 case SHT_GNU_verneed:
6471 case SHT_GNU_verdef:
6472 case SHT_GNU_LIBLIST:
285e3f99 6473 if (section->sh_link == 0
dda8d76d
NC
6474 || section->sh_link >= filedata->file_header.e_shnum
6475 || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB)
dd905818
NC
6476 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6477 i, section->sh_link);
6478 break;
6479
6480 case SHT_INIT_ARRAY:
6481 case SHT_FINI_ARRAY:
6482 case SHT_PREINIT_ARRAY:
6483 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6484 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6485 i, section->sh_link);
6486 break;
6487
6488 default:
6489 /* FIXME: Add support for target specific section types. */
6490#if 0 /* Currently we do not check other section types as there are too
6491 many special cases. Stab sections for example have a type
6492 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6493 section. */
6494 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6495 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6496 i, section->sh_link);
6497#endif
6498 break;
6499 }
6500
6501 /* Check the sh_info field. */
6502 switch (section->sh_type)
6503 {
6504 case SHT_REL:
6505 case SHT_RELA:
285e3f99
AM
6506 if (section->sh_info == 0
6507 && (filedata->file_header.e_type == ET_EXEC
6508 || filedata->file_header.e_type == ET_DYN))
6509 /* Dynamic relocations apply to segments, so they do not
6510 need to specify the section they relocate. */
6511 break;
6512 if (section->sh_info == 0
dda8d76d
NC
6513 || section->sh_info >= filedata->file_header.e_shnum
6514 || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS
6515 && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
6516 && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
6517 && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
385e5b90
L
6518 && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY
6519 && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY
dd905818 6520 /* FIXME: Are other section types valid ? */
dda8d76d 6521 && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
285e3f99
AM
6522 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6523 i, section->sh_info);
dd905818
NC
6524 break;
6525
6526 case SHT_DYNAMIC:
6527 case SHT_HASH:
6528 case SHT_SYMTAB_SHNDX:
6529 case SHT_INIT_ARRAY:
6530 case SHT_FINI_ARRAY:
6531 case SHT_PREINIT_ARRAY:
6532 if (section->sh_info != 0)
6533 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6534 i, section->sh_info);
6535 break;
6536
6537 case SHT_GROUP:
6538 case SHT_SYMTAB:
6539 case SHT_DYNSYM:
6540 /* A symbol index - we assume that it is valid. */
6541 break;
6542
6543 default:
6544 /* FIXME: Add support for target specific section types. */
6545 if (section->sh_type == SHT_NOBITS)
6546 /* NOBITS section headers with non-zero sh_info fields can be
6547 created when a binary is stripped of everything but its debug
1a9ccd70
NC
6548 information. The stripped sections have their headers
6549 preserved but their types set to SHT_NOBITS. So do not check
6550 this type of section. */
dd905818
NC
6551 ;
6552 else if (section->sh_flags & SHF_INFO_LINK)
6553 {
dda8d76d 6554 if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum)
dd905818
NC
6555 warn (_("[%2u]: Expected link to another section in info field"), i);
6556 }
a91e1603
L
6557 else if (section->sh_type < SHT_LOOS
6558 && (section->sh_flags & SHF_GNU_MBIND) == 0
6559 && section->sh_info != 0)
dd905818
NC
6560 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6561 i, section->sh_info);
6562 break;
6563 }
6564
3e6b6445 6565 /* Check the sh_size field. */
dda8d76d 6566 if (section->sh_size > filedata->file_size
3e6b6445
NC
6567 && section->sh_type != SHT_NOBITS
6568 && section->sh_type != SHT_NULL
6569 && section->sh_type < SHT_LOOS)
6570 warn (_("Size of section %u is larger than the entire file!\n"), i);
6571
7bfd842d 6572 printf (" [%2u] ", i);
5477e8a0 6573 if (do_section_details)
dda8d76d 6574 printf ("%s\n ", printable_section_name (filedata, section));
595cf52e 6575 else
74e1a04b 6576 print_symbol (-17, SECTION_NAME (section));
0b4362b0 6577
ea52a088 6578 printf (do_wide ? " %-15s " : " %-15.15s ",
dda8d76d 6579 get_section_type_name (filedata, section->sh_type));
0b4362b0 6580
f7a99963
NC
6581 if (is_32bit_elf)
6582 {
cfcac11d
NC
6583 const char * link_too_big = NULL;
6584
f7a99963 6585 print_vma (section->sh_addr, LONG_HEX);
76da6bbe 6586
f7a99963
NC
6587 printf ( " %6.6lx %6.6lx %2.2lx",
6588 (unsigned long) section->sh_offset,
6589 (unsigned long) section->sh_size,
6590 (unsigned long) section->sh_entsize);
d1133906 6591
5477e8a0
L
6592 if (do_section_details)
6593 fputs (" ", stdout);
6594 else
dda8d76d 6595 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
76da6bbe 6596
dda8d76d 6597 if (section->sh_link >= filedata->file_header.e_shnum)
cfcac11d
NC
6598 {
6599 link_too_big = "";
6600 /* The sh_link value is out of range. Normally this indicates
caa83f8b 6601 an error but it can have special values in Solaris binaries. */
dda8d76d 6602 switch (filedata->file_header.e_machine)
cfcac11d 6603 {
caa83f8b 6604 case EM_386:
22abe556 6605 case EM_IAMCU:
caa83f8b 6606 case EM_X86_64:
7f502d6c 6607 case EM_L1OM:
7a9068fe 6608 case EM_K1OM:
cfcac11d
NC
6609 case EM_OLD_SPARCV9:
6610 case EM_SPARC32PLUS:
6611 case EM_SPARCV9:
6612 case EM_SPARC:
6613 if (section->sh_link == (SHN_BEFORE & 0xffff))
6614 link_too_big = "BEFORE";
6615 else if (section->sh_link == (SHN_AFTER & 0xffff))
6616 link_too_big = "AFTER";
6617 break;
6618 default:
6619 break;
6620 }
6621 }
6622
6623 if (do_section_details)
6624 {
6625 if (link_too_big != NULL && * link_too_big)
6626 printf ("<%s> ", link_too_big);
6627 else
6628 printf ("%2u ", section->sh_link);
6629 printf ("%3u %2lu\n", section->sh_info,
6630 (unsigned long) section->sh_addralign);
6631 }
6632 else
6633 printf ("%2u %3u %2lu\n",
6634 section->sh_link,
6635 section->sh_info,
6636 (unsigned long) section->sh_addralign);
6637
6638 if (link_too_big && ! * link_too_big)
6639 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6640 i, section->sh_link);
f7a99963 6641 }
d974e256
JJ
6642 else if (do_wide)
6643 {
6644 print_vma (section->sh_addr, LONG_HEX);
6645
6646 if ((long) section->sh_offset == section->sh_offset)
6647 printf (" %6.6lx", (unsigned long) section->sh_offset);
6648 else
6649 {
6650 putchar (' ');
6651 print_vma (section->sh_offset, LONG_HEX);
6652 }
6653
6654 if ((unsigned long) section->sh_size == section->sh_size)
6655 printf (" %6.6lx", (unsigned long) section->sh_size);
6656 else
6657 {
6658 putchar (' ');
6659 print_vma (section->sh_size, LONG_HEX);
6660 }
6661
6662 if ((unsigned long) section->sh_entsize == section->sh_entsize)
6663 printf (" %2.2lx", (unsigned long) section->sh_entsize);
6664 else
6665 {
6666 putchar (' ');
6667 print_vma (section->sh_entsize, LONG_HEX);
6668 }
6669
5477e8a0
L
6670 if (do_section_details)
6671 fputs (" ", stdout);
6672 else
dda8d76d 6673 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
d974e256 6674
72de5009 6675 printf ("%2u %3u ", section->sh_link, section->sh_info);
d974e256
JJ
6676
6677 if ((unsigned long) section->sh_addralign == section->sh_addralign)
72de5009 6678 printf ("%2lu\n", (unsigned long) section->sh_addralign);
d974e256
JJ
6679 else
6680 {
6681 print_vma (section->sh_addralign, DEC);
6682 putchar ('\n');
6683 }
6684 }
5477e8a0 6685 else if (do_section_details)
595cf52e 6686 {
55cc53e9 6687 putchar (' ');
595cf52e
L
6688 print_vma (section->sh_addr, LONG_HEX);
6689 if ((long) section->sh_offset == section->sh_offset)
5477e8a0 6690 printf (" %16.16lx", (unsigned long) section->sh_offset);
595cf52e
L
6691 else
6692 {
6693 printf (" ");
6694 print_vma (section->sh_offset, LONG_HEX);
6695 }
72de5009 6696 printf (" %u\n ", section->sh_link);
595cf52e 6697 print_vma (section->sh_size, LONG_HEX);
5477e8a0 6698 putchar (' ');
595cf52e
L
6699 print_vma (section->sh_entsize, LONG_HEX);
6700
72de5009
AM
6701 printf (" %-16u %lu\n",
6702 section->sh_info,
595cf52e
L
6703 (unsigned long) section->sh_addralign);
6704 }
f7a99963
NC
6705 else
6706 {
6707 putchar (' ');
6708 print_vma (section->sh_addr, LONG_HEX);
53c7db4b
KH
6709 if ((long) section->sh_offset == section->sh_offset)
6710 printf (" %8.8lx", (unsigned long) section->sh_offset);
6711 else
6712 {
6713 printf (" ");
6714 print_vma (section->sh_offset, LONG_HEX);
6715 }
f7a99963
NC
6716 printf ("\n ");
6717 print_vma (section->sh_size, LONG_HEX);
6718 printf (" ");
6719 print_vma (section->sh_entsize, LONG_HEX);
76da6bbe 6720
dda8d76d 6721 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
76da6bbe 6722
72de5009
AM
6723 printf (" %2u %3u %lu\n",
6724 section->sh_link,
6725 section->sh_info,
f7a99963
NC
6726 (unsigned long) section->sh_addralign);
6727 }
5477e8a0
L
6728
6729 if (do_section_details)
77115a4a 6730 {
dda8d76d 6731 printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags));
77115a4a
L
6732 if ((section->sh_flags & SHF_COMPRESSED) != 0)
6733 {
6734 /* Minimum section size is 12 bytes for 32-bit compression
6735 header + 12 bytes for compressed data header. */
6736 unsigned char buf[24];
d8024a91 6737
77115a4a 6738 assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
dda8d76d 6739 if (get_data (&buf, filedata, section->sh_offset, 1,
77115a4a
L
6740 sizeof (buf), _("compression header")))
6741 {
6742 Elf_Internal_Chdr chdr;
d8024a91 6743
ebdf1ebf 6744 (void) get_compression_header (&chdr, buf, sizeof (buf));
d8024a91 6745
77115a4a
L
6746 if (chdr.ch_type == ELFCOMPRESS_ZLIB)
6747 printf (" ZLIB, ");
6748 else
6749 printf (_(" [<unknown>: 0x%x], "),
6750 chdr.ch_type);
6751 print_vma (chdr.ch_size, LONG_HEX);
6752 printf (", %lu\n", (unsigned long) chdr.ch_addralign);
6753 }
6754 }
6755 }
252b5132
RH
6756 }
6757
5477e8a0 6758 if (!do_section_details)
3dbcc61d 6759 {
9fb71ee4
NC
6760 /* The ordering of the letters shown here matches the ordering of the
6761 corresponding SHF_xxx values, and hence the order in which these
6762 letters will be displayed to the user. */
6763 printf (_("Key to Flags:\n\
6764 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
6765 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
fd85a6a1 6766 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
dda8d76d
NC
6767 if (filedata->file_header.e_machine == EM_X86_64
6768 || filedata->file_header.e_machine == EM_L1OM
6769 || filedata->file_header.e_machine == EM_K1OM)
9fb71ee4 6770 printf (_("l (large), "));
dda8d76d 6771 else if (filedata->file_header.e_machine == EM_ARM)
f0728ee3 6772 printf (_("y (purecode), "));
dda8d76d 6773 else if (filedata->file_header.e_machine == EM_PPC)
83eef883 6774 printf (_("v (VLE), "));
9fb71ee4 6775 printf ("p (processor specific)\n");
0b4362b0 6776 }
d1133906 6777
32ec8896 6778 return TRUE;
252b5132
RH
6779}
6780
f5842774
L
6781static const char *
6782get_group_flags (unsigned int flags)
6783{
1449284b 6784 static char buff[128];
220453ec 6785
6d913794
NC
6786 if (flags == 0)
6787 return "";
6788 else if (flags == GRP_COMDAT)
6789 return "COMDAT ";
f5842774 6790
6d913794
NC
6791 snprintf (buff, 14, _("[0x%x: "), flags);
6792
6793 flags &= ~ GRP_COMDAT;
6794 if (flags & GRP_MASKOS)
6795 {
6796 strcat (buff, "<OS specific>");
6797 flags &= ~ GRP_MASKOS;
f5842774 6798 }
6d913794
NC
6799
6800 if (flags & GRP_MASKPROC)
6801 {
6802 strcat (buff, "<PROC specific>");
6803 flags &= ~ GRP_MASKPROC;
6804 }
6805
6806 if (flags)
6807 strcat (buff, "<unknown>");
6808
6809 strcat (buff, "]");
f5842774
L
6810 return buff;
6811}
6812
32ec8896 6813static bfd_boolean
dda8d76d 6814process_section_groups (Filedata * filedata)
f5842774 6815{
2cf0635d 6816 Elf_Internal_Shdr * section;
f5842774 6817 unsigned int i;
2cf0635d
NC
6818 struct group * group;
6819 Elf_Internal_Shdr * symtab_sec;
6820 Elf_Internal_Shdr * strtab_sec;
6821 Elf_Internal_Sym * symtab;
ba5cdace 6822 unsigned long num_syms;
2cf0635d 6823 char * strtab;
c256ffe7 6824 size_t strtab_size;
d1f5c6e3
L
6825
6826 /* Don't process section groups unless needed. */
6827 if (!do_unwind && !do_section_groups)
32ec8896 6828 return TRUE;
f5842774 6829
dda8d76d 6830 if (filedata->file_header.e_shnum == 0)
f5842774
L
6831 {
6832 if (do_section_groups)
82f2dbf7 6833 printf (_("\nThere are no sections to group in this file.\n"));
f5842774 6834
32ec8896 6835 return TRUE;
f5842774
L
6836 }
6837
dda8d76d 6838 if (filedata->section_headers == NULL)
f5842774
L
6839 {
6840 error (_("Section headers are not available!\n"));
fa1908fd 6841 /* PR 13622: This can happen with a corrupt ELF header. */
32ec8896 6842 return FALSE;
f5842774
L
6843 }
6844
dda8d76d 6845 section_headers_groups = (struct group **) calloc (filedata->file_header.e_shnum,
3f5e193b 6846 sizeof (struct group *));
e4b17d5c
L
6847
6848 if (section_headers_groups == NULL)
6849 {
8b73c356 6850 error (_("Out of memory reading %u section group headers\n"),
dda8d76d 6851 filedata->file_header.e_shnum);
32ec8896 6852 return FALSE;
e4b17d5c
L
6853 }
6854
f5842774 6855 /* Scan the sections for the group section. */
d1f5c6e3 6856 group_count = 0;
dda8d76d
NC
6857 for (i = 0, section = filedata->section_headers;
6858 i < filedata->file_header.e_shnum;
f5842774 6859 i++, section++)
e4b17d5c
L
6860 if (section->sh_type == SHT_GROUP)
6861 group_count++;
6862
d1f5c6e3
L
6863 if (group_count == 0)
6864 {
6865 if (do_section_groups)
6866 printf (_("\nThere are no section groups in this file.\n"));
6867
32ec8896 6868 return TRUE;
d1f5c6e3
L
6869 }
6870
3f5e193b 6871 section_groups = (struct group *) calloc (group_count, sizeof (struct group));
e4b17d5c
L
6872
6873 if (section_groups == NULL)
6874 {
8b73c356
NC
6875 error (_("Out of memory reading %lu groups\n"),
6876 (unsigned long) group_count);
32ec8896 6877 return FALSE;
e4b17d5c
L
6878 }
6879
d1f5c6e3
L
6880 symtab_sec = NULL;
6881 strtab_sec = NULL;
6882 symtab = NULL;
ba5cdace 6883 num_syms = 0;
d1f5c6e3 6884 strtab = NULL;
c256ffe7 6885 strtab_size = 0;
dda8d76d
NC
6886 for (i = 0, section = filedata->section_headers, group = section_groups;
6887 i < filedata->file_header.e_shnum;
e4b17d5c 6888 i++, section++)
f5842774
L
6889 {
6890 if (section->sh_type == SHT_GROUP)
6891 {
dda8d76d 6892 const char * name = printable_section_name (filedata, section);
74e1a04b 6893 const char * group_name;
2cf0635d
NC
6894 unsigned char * start;
6895 unsigned char * indices;
f5842774 6896 unsigned int entry, j, size;
2cf0635d
NC
6897 Elf_Internal_Shdr * sec;
6898 Elf_Internal_Sym * sym;
f5842774
L
6899
6900 /* Get the symbol table. */
dda8d76d
NC
6901 if (section->sh_link >= filedata->file_header.e_shnum
6902 || ((sec = filedata->section_headers + section->sh_link)->sh_type
c256ffe7 6903 != SHT_SYMTAB))
f5842774
L
6904 {
6905 error (_("Bad sh_link in group section `%s'\n"), name);
6906 continue;
6907 }
d1f5c6e3
L
6908
6909 if (symtab_sec != sec)
6910 {
6911 symtab_sec = sec;
6912 if (symtab)
6913 free (symtab);
dda8d76d 6914 symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms);
d1f5c6e3 6915 }
f5842774 6916
dd24e3da
NC
6917 if (symtab == NULL)
6918 {
6919 error (_("Corrupt header in group section `%s'\n"), name);
6920 continue;
6921 }
6922
ba5cdace
NC
6923 if (section->sh_info >= num_syms)
6924 {
6925 error (_("Bad sh_info in group section `%s'\n"), name);
6926 continue;
6927 }
6928
f5842774
L
6929 sym = symtab + section->sh_info;
6930
6931 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6932 {
4fbb74a6 6933 if (sym->st_shndx == 0
dda8d76d 6934 || sym->st_shndx >= filedata->file_header.e_shnum)
f5842774
L
6935 {
6936 error (_("Bad sh_info in group section `%s'\n"), name);
6937 continue;
6938 }
ba2685cc 6939
dda8d76d 6940 group_name = SECTION_NAME (filedata->section_headers + sym->st_shndx);
c256ffe7
JJ
6941 strtab_sec = NULL;
6942 if (strtab)
6943 free (strtab);
f5842774 6944 strtab = NULL;
c256ffe7 6945 strtab_size = 0;
f5842774
L
6946 }
6947 else
6948 {
6949 /* Get the string table. */
dda8d76d 6950 if (symtab_sec->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
6951 {
6952 strtab_sec = NULL;
6953 if (strtab)
6954 free (strtab);
6955 strtab = NULL;
6956 strtab_size = 0;
6957 }
6958 else if (strtab_sec
dda8d76d 6959 != (sec = filedata->section_headers + symtab_sec->sh_link))
d1f5c6e3
L
6960 {
6961 strtab_sec = sec;
6962 if (strtab)
6963 free (strtab);
071436c6 6964
dda8d76d 6965 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
071436c6
NC
6966 1, strtab_sec->sh_size,
6967 _("string table"));
c256ffe7 6968 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
d1f5c6e3 6969 }
c256ffe7 6970 group_name = sym->st_name < strtab_size
2b692964 6971 ? strtab + sym->st_name : _("<corrupt>");
f5842774
L
6972 }
6973
c9c1d674
EG
6974 /* PR 17531: file: loop. */
6975 if (section->sh_entsize > section->sh_size)
6976 {
6977 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
dda8d76d 6978 printable_section_name (filedata, section),
8066deb1
AM
6979 (unsigned long) section->sh_entsize,
6980 (unsigned long) section->sh_size);
61dd8e19 6981 continue;
c9c1d674
EG
6982 }
6983
dda8d76d 6984 start = (unsigned char *) get_data (NULL, filedata, section->sh_offset,
3f5e193b
NC
6985 1, section->sh_size,
6986 _("section data"));
59245841
NC
6987 if (start == NULL)
6988 continue;
f5842774
L
6989
6990 indices = start;
6991 size = (section->sh_size / section->sh_entsize) - 1;
6992 entry = byte_get (indices, 4);
6993 indices += 4;
e4b17d5c
L
6994
6995 if (do_section_groups)
6996 {
2b692964 6997 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
391cb864 6998 get_group_flags (entry), i, name, group_name, size);
ba2685cc 6999
e4b17d5c
L
7000 printf (_(" [Index] Name\n"));
7001 }
7002
7003 group->group_index = i;
7004
f5842774
L
7005 for (j = 0; j < size; j++)
7006 {
2cf0635d 7007 struct group_list * g;
e4b17d5c 7008
f5842774
L
7009 entry = byte_get (indices, 4);
7010 indices += 4;
7011
dda8d76d 7012 if (entry >= filedata->file_header.e_shnum)
391cb864 7013 {
57028622
NC
7014 static unsigned num_group_errors = 0;
7015
7016 if (num_group_errors ++ < 10)
7017 {
7018 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
dda8d76d 7019 entry, i, filedata->file_header.e_shnum - 1);
57028622 7020 if (num_group_errors == 10)
67ce483b 7021 warn (_("Further error messages about overlarge group section indices suppressed\n"));
57028622 7022 }
391cb864
L
7023 continue;
7024 }
391cb864 7025
4fbb74a6 7026 if (section_headers_groups [entry] != NULL)
e4b17d5c 7027 {
d1f5c6e3
L
7028 if (entry)
7029 {
57028622
NC
7030 static unsigned num_errs = 0;
7031
7032 if (num_errs ++ < 10)
7033 {
7034 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7035 entry, i,
7036 section_headers_groups [entry]->group_index);
7037 if (num_errs == 10)
7038 warn (_("Further error messages about already contained group sections suppressed\n"));
7039 }
d1f5c6e3
L
7040 continue;
7041 }
7042 else
7043 {
7044 /* Intel C/C++ compiler may put section 0 in a
32ec8896 7045 section group. We just warn it the first time
d1f5c6e3 7046 and ignore it afterwards. */
32ec8896 7047 static bfd_boolean warned = FALSE;
d1f5c6e3
L
7048 if (!warned)
7049 {
7050 error (_("section 0 in group section [%5u]\n"),
4fbb74a6 7051 section_headers_groups [entry]->group_index);
32ec8896 7052 warned = TRUE;
d1f5c6e3
L
7053 }
7054 }
e4b17d5c
L
7055 }
7056
4fbb74a6 7057 section_headers_groups [entry] = group;
e4b17d5c
L
7058
7059 if (do_section_groups)
7060 {
dda8d76d
NC
7061 sec = filedata->section_headers + entry;
7062 printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec));
ba2685cc
AM
7063 }
7064
3f5e193b 7065 g = (struct group_list *) xmalloc (sizeof (struct group_list));
e4b17d5c
L
7066 g->section_index = entry;
7067 g->next = group->root;
7068 group->root = g;
f5842774
L
7069 }
7070
f5842774
L
7071 if (start)
7072 free (start);
e4b17d5c
L
7073
7074 group++;
f5842774
L
7075 }
7076 }
7077
d1f5c6e3
L
7078 if (symtab)
7079 free (symtab);
7080 if (strtab)
7081 free (strtab);
32ec8896 7082 return TRUE;
f5842774
L
7083}
7084
28f997cf
TG
7085/* Data used to display dynamic fixups. */
7086
7087struct ia64_vms_dynfixup
7088{
7089 bfd_vma needed_ident; /* Library ident number. */
7090 bfd_vma needed; /* Index in the dstrtab of the library name. */
7091 bfd_vma fixup_needed; /* Index of the library. */
7092 bfd_vma fixup_rela_cnt; /* Number of fixups. */
7093 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
7094};
7095
7096/* Data used to display dynamic relocations. */
7097
7098struct ia64_vms_dynimgrela
7099{
7100 bfd_vma img_rela_cnt; /* Number of relocations. */
7101 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
7102};
7103
7104/* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7105 library). */
7106
32ec8896 7107static bfd_boolean
dda8d76d
NC
7108dump_ia64_vms_dynamic_fixups (Filedata * filedata,
7109 struct ia64_vms_dynfixup * fixup,
7110 const char * strtab,
7111 unsigned int strtab_sz)
28f997cf 7112{
32ec8896 7113 Elf64_External_VMS_IMAGE_FIXUP * imfs;
28f997cf 7114 long i;
32ec8896 7115 const char * lib_name;
28f997cf 7116
dda8d76d 7117 imfs = get_data (NULL, filedata, dynamic_addr + fixup->fixup_rela_off,
28f997cf
TG
7118 1, fixup->fixup_rela_cnt * sizeof (*imfs),
7119 _("dynamic section image fixups"));
7120 if (!imfs)
32ec8896 7121 return FALSE;
28f997cf
TG
7122
7123 if (fixup->needed < strtab_sz)
7124 lib_name = strtab + fixup->needed;
7125 else
7126 {
32ec8896 7127 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7f01b0c6 7128 (unsigned long) fixup->needed);
28f997cf
TG
7129 lib_name = "???";
7130 }
7131 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7132 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
7133 printf
7134 (_("Seg Offset Type SymVec DataType\n"));
7135
7136 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
7137 {
7138 unsigned int type;
7139 const char *rtype;
7140
7141 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
7142 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
7143 type = BYTE_GET (imfs [i].type);
7144 rtype = elf_ia64_reloc_type (type);
7145 if (rtype == NULL)
7146 printf (" 0x%08x ", type);
7147 else
7148 printf (" %-32s ", rtype);
7149 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
7150 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
7151 }
7152
7153 free (imfs);
32ec8896 7154 return TRUE;
28f997cf
TG
7155}
7156
7157/* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7158
32ec8896 7159static bfd_boolean
dda8d76d 7160dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela)
28f997cf
TG
7161{
7162 Elf64_External_VMS_IMAGE_RELA *imrs;
7163 long i;
7164
dda8d76d 7165 imrs = get_data (NULL, filedata, dynamic_addr + imgrela->img_rela_off,
28f997cf 7166 1, imgrela->img_rela_cnt * sizeof (*imrs),
9cf03b7e 7167 _("dynamic section image relocations"));
28f997cf 7168 if (!imrs)
32ec8896 7169 return FALSE;
28f997cf
TG
7170
7171 printf (_("\nImage relocs\n"));
7172 printf
7173 (_("Seg Offset Type Addend Seg Sym Off\n"));
7174
7175 for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
7176 {
7177 unsigned int type;
7178 const char *rtype;
7179
7180 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
7181 printf ("%08" BFD_VMA_FMT "x ",
7182 (bfd_vma) BYTE_GET (imrs [i].rela_offset));
7183 type = BYTE_GET (imrs [i].type);
7184 rtype = elf_ia64_reloc_type (type);
7185 if (rtype == NULL)
7186 printf ("0x%08x ", type);
7187 else
7188 printf ("%-31s ", rtype);
7189 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
7190 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
7191 printf ("%08" BFD_VMA_FMT "x\n",
7192 (bfd_vma) BYTE_GET (imrs [i].sym_offset));
7193 }
7194
7195 free (imrs);
32ec8896 7196 return TRUE;
28f997cf
TG
7197}
7198
7199/* Display IA-64 OpenVMS dynamic relocations and fixups. */
7200
32ec8896 7201static bfd_boolean
dda8d76d 7202process_ia64_vms_dynamic_relocs (Filedata * filedata)
28f997cf
TG
7203{
7204 struct ia64_vms_dynfixup fixup;
7205 struct ia64_vms_dynimgrela imgrela;
7206 Elf_Internal_Dyn *entry;
28f997cf
TG
7207 bfd_vma strtab_off = 0;
7208 bfd_vma strtab_sz = 0;
7209 char *strtab = NULL;
32ec8896 7210 bfd_boolean res = TRUE;
28f997cf
TG
7211
7212 memset (&fixup, 0, sizeof (fixup));
7213 memset (&imgrela, 0, sizeof (imgrela));
7214
7215 /* Note: the order of the entries is specified by the OpenVMS specs. */
7216 for (entry = dynamic_section;
7217 entry < dynamic_section + dynamic_nent;
7218 entry++)
7219 {
7220 switch (entry->d_tag)
7221 {
7222 case DT_IA_64_VMS_STRTAB_OFFSET:
7223 strtab_off = entry->d_un.d_val;
7224 break;
7225 case DT_STRSZ:
7226 strtab_sz = entry->d_un.d_val;
7227 if (strtab == NULL)
dda8d76d 7228 strtab = get_data (NULL, filedata, dynamic_addr + strtab_off,
28f997cf
TG
7229 1, strtab_sz, _("dynamic string section"));
7230 break;
7231
7232 case DT_IA_64_VMS_NEEDED_IDENT:
7233 fixup.needed_ident = entry->d_un.d_val;
7234 break;
7235 case DT_NEEDED:
7236 fixup.needed = entry->d_un.d_val;
7237 break;
7238 case DT_IA_64_VMS_FIXUP_NEEDED:
7239 fixup.fixup_needed = entry->d_un.d_val;
7240 break;
7241 case DT_IA_64_VMS_FIXUP_RELA_CNT:
7242 fixup.fixup_rela_cnt = entry->d_un.d_val;
7243 break;
7244 case DT_IA_64_VMS_FIXUP_RELA_OFF:
7245 fixup.fixup_rela_off = entry->d_un.d_val;
dda8d76d 7246 if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz))
32ec8896 7247 res = FALSE;
28f997cf 7248 break;
28f997cf
TG
7249 case DT_IA_64_VMS_IMG_RELA_CNT:
7250 imgrela.img_rela_cnt = entry->d_un.d_val;
7251 break;
7252 case DT_IA_64_VMS_IMG_RELA_OFF:
7253 imgrela.img_rela_off = entry->d_un.d_val;
dda8d76d 7254 if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela))
32ec8896 7255 res = FALSE;
28f997cf
TG
7256 break;
7257
7258 default:
7259 break;
7260 }
7261 }
7262
7263 if (strtab != NULL)
7264 free (strtab);
7265
7266 return res;
7267}
7268
85b1c36d 7269static struct
566b0d53 7270{
2cf0635d 7271 const char * name;
566b0d53
L
7272 int reloc;
7273 int size;
7274 int rela;
32ec8896
NC
7275}
7276 dynamic_relocations [] =
566b0d53 7277{
32ec8896
NC
7278 { "REL", DT_REL, DT_RELSZ, FALSE },
7279 { "RELA", DT_RELA, DT_RELASZ, TRUE },
7280 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
566b0d53
L
7281};
7282
252b5132 7283/* Process the reloc section. */
18bd398b 7284
32ec8896 7285static bfd_boolean
dda8d76d 7286process_relocs (Filedata * filedata)
252b5132 7287{
b34976b6
AM
7288 unsigned long rel_size;
7289 unsigned long rel_offset;
252b5132 7290
252b5132 7291 if (!do_reloc)
32ec8896 7292 return TRUE;
252b5132
RH
7293
7294 if (do_using_dynamic)
7295 {
32ec8896 7296 int is_rela;
2cf0635d 7297 const char * name;
32ec8896 7298 bfd_boolean has_dynamic_reloc;
566b0d53 7299 unsigned int i;
0de14b54 7300
32ec8896 7301 has_dynamic_reloc = FALSE;
252b5132 7302
566b0d53 7303 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
252b5132 7304 {
566b0d53
L
7305 is_rela = dynamic_relocations [i].rela;
7306 name = dynamic_relocations [i].name;
7307 rel_size = dynamic_info [dynamic_relocations [i].size];
7308 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
103f02d3 7309
32ec8896
NC
7310 if (rel_size)
7311 has_dynamic_reloc = TRUE;
566b0d53
L
7312
7313 if (is_rela == UNKNOWN)
aa903cfb 7314 {
566b0d53
L
7315 if (dynamic_relocations [i].reloc == DT_JMPREL)
7316 switch (dynamic_info[DT_PLTREL])
7317 {
7318 case DT_REL:
7319 is_rela = FALSE;
7320 break;
7321 case DT_RELA:
7322 is_rela = TRUE;
7323 break;
7324 }
aa903cfb 7325 }
252b5132 7326
566b0d53
L
7327 if (rel_size)
7328 {
7329 printf
7330 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7331 name, rel_offset, rel_size);
252b5132 7332
dda8d76d
NC
7333 dump_relocations (filedata,
7334 offset_from_vma (filedata, rel_offset, rel_size),
d93f0186 7335 rel_size,
566b0d53 7336 dynamic_symbols, num_dynamic_syms,
bb4d2ac2 7337 dynamic_strings, dynamic_strings_length,
32ec8896 7338 is_rela, TRUE /* is_dynamic */);
566b0d53 7339 }
252b5132 7340 }
566b0d53 7341
dda8d76d
NC
7342 if (is_ia64_vms (filedata))
7343 if (process_ia64_vms_dynamic_relocs (filedata))
32ec8896 7344 has_dynamic_reloc = TRUE;
28f997cf 7345
566b0d53 7346 if (! has_dynamic_reloc)
252b5132
RH
7347 printf (_("\nThere are no dynamic relocations in this file.\n"));
7348 }
7349 else
7350 {
2cf0635d 7351 Elf_Internal_Shdr * section;
b34976b6 7352 unsigned long i;
32ec8896 7353 bfd_boolean found = FALSE;
252b5132 7354
dda8d76d
NC
7355 for (i = 0, section = filedata->section_headers;
7356 i < filedata->file_header.e_shnum;
b34976b6 7357 i++, section++)
252b5132
RH
7358 {
7359 if ( section->sh_type != SHT_RELA
7360 && section->sh_type != SHT_REL)
7361 continue;
7362
7363 rel_offset = section->sh_offset;
7364 rel_size = section->sh_size;
7365
7366 if (rel_size)
7367 {
2cf0635d 7368 Elf_Internal_Shdr * strsec;
b34976b6 7369 int is_rela;
d3a49aa8 7370 unsigned long num_rela;
103f02d3 7371
252b5132
RH
7372 printf (_("\nRelocation section "));
7373
dda8d76d 7374 if (filedata->string_table == NULL)
19936277 7375 printf ("%d", section->sh_name);
252b5132 7376 else
dda8d76d 7377 printf ("'%s'", printable_section_name (filedata, section));
252b5132 7378
d3a49aa8
AM
7379 num_rela = rel_size / section->sh_entsize;
7380 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7381 " at offset 0x%lx contains %lu entries:\n",
7382 num_rela),
7383 rel_offset, num_rela);
252b5132 7384
d79b3d50
NC
7385 is_rela = section->sh_type == SHT_RELA;
7386
4fbb74a6 7387 if (section->sh_link != 0
dda8d76d 7388 && section->sh_link < filedata->file_header.e_shnum)
af3fc3bc 7389 {
2cf0635d
NC
7390 Elf_Internal_Shdr * symsec;
7391 Elf_Internal_Sym * symtab;
d79b3d50 7392 unsigned long nsyms;
c256ffe7 7393 unsigned long strtablen = 0;
2cf0635d 7394 char * strtab = NULL;
57346661 7395
dda8d76d 7396 symsec = filedata->section_headers + section->sh_link;
08d8fa11
JJ
7397 if (symsec->sh_type != SHT_SYMTAB
7398 && symsec->sh_type != SHT_DYNSYM)
7399 continue;
7400
dda8d76d 7401 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
252b5132 7402
af3fc3bc
AM
7403 if (symtab == NULL)
7404 continue;
252b5132 7405
4fbb74a6 7406 if (symsec->sh_link != 0
dda8d76d 7407 && symsec->sh_link < filedata->file_header.e_shnum)
c256ffe7 7408 {
dda8d76d 7409 strsec = filedata->section_headers + symsec->sh_link;
103f02d3 7410
dda8d76d 7411 strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
071436c6
NC
7412 1, strsec->sh_size,
7413 _("string table"));
c256ffe7
JJ
7414 strtablen = strtab == NULL ? 0 : strsec->sh_size;
7415 }
252b5132 7416
dda8d76d 7417 dump_relocations (filedata, rel_offset, rel_size,
bb4d2ac2
L
7418 symtab, nsyms, strtab, strtablen,
7419 is_rela,
7420 symsec->sh_type == SHT_DYNSYM);
d79b3d50
NC
7421 if (strtab)
7422 free (strtab);
7423 free (symtab);
7424 }
7425 else
dda8d76d 7426 dump_relocations (filedata, rel_offset, rel_size,
32ec8896
NC
7427 NULL, 0, NULL, 0, is_rela,
7428 FALSE /* is_dynamic */);
252b5132 7429
32ec8896 7430 found = TRUE;
252b5132
RH
7431 }
7432 }
7433
7434 if (! found)
45ac8f4f
NC
7435 {
7436 /* Users sometimes forget the -D option, so try to be helpful. */
7437 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
7438 {
7439 if (dynamic_info [dynamic_relocations [i].size])
7440 {
7441 printf (_("\nThere are no static relocations in this file."));
7442 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7443
7444 break;
7445 }
7446 }
7447 if (i == ARRAY_SIZE (dynamic_relocations))
7448 printf (_("\nThere are no relocations in this file.\n"));
7449 }
252b5132
RH
7450 }
7451
32ec8896 7452 return TRUE;
252b5132
RH
7453}
7454
4d6ed7c8
NC
7455/* An absolute address consists of a section and an offset. If the
7456 section is NULL, the offset itself is the address, otherwise, the
7457 address equals to LOAD_ADDRESS(section) + offset. */
7458
7459struct absaddr
948f632f
DA
7460{
7461 unsigned short section;
7462 bfd_vma offset;
7463};
4d6ed7c8 7464
948f632f
DA
7465/* Find the nearest symbol at or below ADDR. Returns the symbol
7466 name, if found, and the offset from the symbol to ADDR. */
4d6ed7c8 7467
4d6ed7c8 7468static void
dda8d76d
NC
7469find_symbol_for_address (Filedata * filedata,
7470 Elf_Internal_Sym * symtab,
7471 unsigned long nsyms,
7472 const char * strtab,
7473 unsigned long strtab_size,
7474 struct absaddr addr,
7475 const char ** symname,
7476 bfd_vma * offset)
4d6ed7c8 7477{
d3ba0551 7478 bfd_vma dist = 0x100000;
2cf0635d 7479 Elf_Internal_Sym * sym;
948f632f
DA
7480 Elf_Internal_Sym * beg;
7481 Elf_Internal_Sym * end;
2cf0635d 7482 Elf_Internal_Sym * best = NULL;
4d6ed7c8 7483
0b6ae522 7484 REMOVE_ARCH_BITS (addr.offset);
948f632f
DA
7485 beg = symtab;
7486 end = symtab + nsyms;
0b6ae522 7487
948f632f 7488 while (beg < end)
4d6ed7c8 7489 {
948f632f
DA
7490 bfd_vma value;
7491
7492 sym = beg + (end - beg) / 2;
0b6ae522 7493
948f632f 7494 value = sym->st_value;
0b6ae522
DJ
7495 REMOVE_ARCH_BITS (value);
7496
948f632f 7497 if (sym->st_name != 0
4d6ed7c8 7498 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
0b6ae522
DJ
7499 && addr.offset >= value
7500 && addr.offset - value < dist)
4d6ed7c8
NC
7501 {
7502 best = sym;
0b6ae522 7503 dist = addr.offset - value;
4d6ed7c8
NC
7504 if (!dist)
7505 break;
7506 }
948f632f
DA
7507
7508 if (addr.offset < value)
7509 end = sym;
7510 else
7511 beg = sym + 1;
4d6ed7c8 7512 }
1b31d05e 7513
4d6ed7c8
NC
7514 if (best)
7515 {
57346661 7516 *symname = (best->st_name >= strtab_size
2b692964 7517 ? _("<corrupt>") : strtab + best->st_name);
4d6ed7c8
NC
7518 *offset = dist;
7519 return;
7520 }
1b31d05e 7521
4d6ed7c8
NC
7522 *symname = NULL;
7523 *offset = addr.offset;
7524}
7525
32ec8896 7526static /* signed */ int
948f632f
DA
7527symcmp (const void *p, const void *q)
7528{
7529 Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
7530 Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
7531
7532 return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
7533}
7534
7535/* Process the unwind section. */
7536
7537#include "unwind-ia64.h"
7538
7539struct ia64_unw_table_entry
7540{
7541 struct absaddr start;
7542 struct absaddr end;
7543 struct absaddr info;
7544};
7545
7546struct ia64_unw_aux_info
7547{
32ec8896
NC
7548 struct ia64_unw_table_entry * table; /* Unwind table. */
7549 unsigned long table_len; /* Length of unwind table. */
7550 unsigned char * info; /* Unwind info. */
7551 unsigned long info_size; /* Size of unwind info. */
7552 bfd_vma info_addr; /* Starting address of unwind info. */
7553 bfd_vma seg_base; /* Starting address of segment. */
7554 Elf_Internal_Sym * symtab; /* The symbol table. */
7555 unsigned long nsyms; /* Number of symbols. */
7556 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
7557 unsigned long nfuns; /* Number of entries in funtab. */
7558 char * strtab; /* The string table. */
7559 unsigned long strtab_size; /* Size of string table. */
948f632f
DA
7560};
7561
32ec8896 7562static bfd_boolean
dda8d76d 7563dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux)
4d6ed7c8 7564{
2cf0635d 7565 struct ia64_unw_table_entry * tp;
948f632f 7566 unsigned long j, nfuns;
4d6ed7c8 7567 int in_body;
32ec8896 7568 bfd_boolean res = TRUE;
7036c0e1 7569
948f632f
DA
7570 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
7571 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
7572 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
7573 aux->funtab[nfuns++] = aux->symtab[j];
7574 aux->nfuns = nfuns;
7575 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
7576
4d6ed7c8
NC
7577 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
7578 {
7579 bfd_vma stamp;
7580 bfd_vma offset;
2cf0635d
NC
7581 const unsigned char * dp;
7582 const unsigned char * head;
53774b7e 7583 const unsigned char * end;
2cf0635d 7584 const char * procname;
4d6ed7c8 7585
dda8d76d 7586 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
57346661 7587 aux->strtab_size, tp->start, &procname, &offset);
4d6ed7c8
NC
7588
7589 fputs ("\n<", stdout);
7590
7591 if (procname)
7592 {
7593 fputs (procname, stdout);
7594
7595 if (offset)
7596 printf ("+%lx", (unsigned long) offset);
7597 }
7598
7599 fputs (">: [", stdout);
7600 print_vma (tp->start.offset, PREFIX_HEX);
7601 fputc ('-', stdout);
7602 print_vma (tp->end.offset, PREFIX_HEX);
86f55779 7603 printf ("], info at +0x%lx\n",
4d6ed7c8
NC
7604 (unsigned long) (tp->info.offset - aux->seg_base));
7605
53774b7e
NC
7606 /* PR 17531: file: 86232b32. */
7607 if (aux->info == NULL)
7608 continue;
7609
97c0a079
AM
7610 offset = tp->info.offset;
7611 if (tp->info.section)
7612 {
7613 if (tp->info.section >= filedata->file_header.e_shnum)
7614 {
7615 warn (_("Invalid section %u in table entry %ld\n"),
7616 tp->info.section, (long) (tp - aux->table));
7617 res = FALSE;
7618 continue;
7619 }
7620 offset += filedata->section_headers[tp->info.section].sh_addr;
7621 }
7622 offset -= aux->info_addr;
53774b7e 7623 /* PR 17531: file: 0997b4d1. */
90679903
AM
7624 if (offset >= aux->info_size
7625 || aux->info_size - offset < 8)
53774b7e
NC
7626 {
7627 warn (_("Invalid offset %lx in table entry %ld\n"),
7628 (long) tp->info.offset, (long) (tp - aux->table));
32ec8896 7629 res = FALSE;
53774b7e
NC
7630 continue;
7631 }
7632
97c0a079 7633 head = aux->info + offset;
a4a00738 7634 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
4d6ed7c8 7635
86f55779 7636 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4d6ed7c8
NC
7637 (unsigned) UNW_VER (stamp),
7638 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
7639 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
7640 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
89fac5e3 7641 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
4d6ed7c8
NC
7642
7643 if (UNW_VER (stamp) != 1)
7644 {
2b692964 7645 printf (_("\tUnknown version.\n"));
4d6ed7c8
NC
7646 continue;
7647 }
7648
7649 in_body = 0;
53774b7e
NC
7650 end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
7651 /* PR 17531: file: 16ceda89. */
7652 if (end > aux->info + aux->info_size)
7653 end = aux->info + aux->info_size;
7654 for (dp = head + 8; dp < end;)
b4477bc8 7655 dp = unw_decode (dp, in_body, & in_body, end);
4d6ed7c8 7656 }
948f632f
DA
7657
7658 free (aux->funtab);
32ec8896
NC
7659
7660 return res;
4d6ed7c8
NC
7661}
7662
53774b7e 7663static bfd_boolean
dda8d76d
NC
7664slurp_ia64_unwind_table (Filedata * filedata,
7665 struct ia64_unw_aux_info * aux,
7666 Elf_Internal_Shdr * sec)
4d6ed7c8 7667{
89fac5e3 7668 unsigned long size, nrelas, i;
2cf0635d
NC
7669 Elf_Internal_Phdr * seg;
7670 struct ia64_unw_table_entry * tep;
7671 Elf_Internal_Shdr * relsec;
7672 Elf_Internal_Rela * rela;
7673 Elf_Internal_Rela * rp;
7674 unsigned char * table;
7675 unsigned char * tp;
7676 Elf_Internal_Sym * sym;
7677 const char * relname;
4d6ed7c8 7678
53774b7e
NC
7679 aux->table_len = 0;
7680
4d6ed7c8
NC
7681 /* First, find the starting address of the segment that includes
7682 this section: */
7683
dda8d76d 7684 if (filedata->file_header.e_phnum)
4d6ed7c8 7685 {
dda8d76d 7686 if (! get_program_headers (filedata))
53774b7e 7687 return FALSE;
4d6ed7c8 7688
dda8d76d
NC
7689 for (seg = filedata->program_headers;
7690 seg < filedata->program_headers + filedata->file_header.e_phnum;
d93f0186 7691 ++seg)
4d6ed7c8
NC
7692 {
7693 if (seg->p_type != PT_LOAD)
7694 continue;
7695
7696 if (sec->sh_addr >= seg->p_vaddr
7697 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
7698 {
7699 aux->seg_base = seg->p_vaddr;
7700 break;
7701 }
7702 }
4d6ed7c8
NC
7703 }
7704
7705 /* Second, build the unwind table from the contents of the unwind section: */
7706 size = sec->sh_size;
dda8d76d 7707 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
3f5e193b 7708 _("unwind table"));
a6e9f9df 7709 if (!table)
53774b7e 7710 return FALSE;
4d6ed7c8 7711
53774b7e 7712 aux->table_len = size / (3 * eh_addr_size);
3f5e193b 7713 aux->table = (struct ia64_unw_table_entry *)
53774b7e 7714 xcmalloc (aux->table_len, sizeof (aux->table[0]));
89fac5e3 7715 tep = aux->table;
53774b7e
NC
7716
7717 for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
4d6ed7c8
NC
7718 {
7719 tep->start.section = SHN_UNDEF;
7720 tep->end.section = SHN_UNDEF;
7721 tep->info.section = SHN_UNDEF;
c6a0c689
AM
7722 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7723 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7724 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
4d6ed7c8
NC
7725 tep->start.offset += aux->seg_base;
7726 tep->end.offset += aux->seg_base;
7727 tep->info.offset += aux->seg_base;
7728 }
7729 free (table);
7730
41e92641 7731 /* Third, apply any relocations to the unwind table: */
dda8d76d
NC
7732 for (relsec = filedata->section_headers;
7733 relsec < filedata->section_headers + filedata->file_header.e_shnum;
4d6ed7c8
NC
7734 ++relsec)
7735 {
7736 if (relsec->sh_type != SHT_RELA
dda8d76d
NC
7737 || relsec->sh_info >= filedata->file_header.e_shnum
7738 || filedata->section_headers + relsec->sh_info != sec)
4d6ed7c8
NC
7739 continue;
7740
dda8d76d 7741 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
4d6ed7c8 7742 & rela, & nrelas))
53774b7e
NC
7743 {
7744 free (aux->table);
7745 aux->table = NULL;
7746 aux->table_len = 0;
7747 return FALSE;
7748 }
4d6ed7c8
NC
7749
7750 for (rp = rela; rp < rela + nrelas; ++rp)
7751 {
4770fb94 7752 unsigned int sym_ndx;
726bd37d
AM
7753 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
7754 relname = elf_ia64_reloc_type (r_type);
4d6ed7c8 7755
82b1b41b
NC
7756 /* PR 17531: file: 9fa67536. */
7757 if (relname == NULL)
7758 {
726bd37d 7759 warn (_("Skipping unknown relocation type: %u\n"), r_type);
82b1b41b
NC
7760 continue;
7761 }
948f632f 7762
0112cd26 7763 if (! const_strneq (relname, "R_IA64_SEGREL"))
4d6ed7c8 7764 {
82b1b41b 7765 warn (_("Skipping unexpected relocation type: %s\n"), relname);
4d6ed7c8
NC
7766 continue;
7767 }
7768
89fac5e3 7769 i = rp->r_offset / (3 * eh_addr_size);
4d6ed7c8 7770
53774b7e
NC
7771 /* PR 17531: file: 5bc8d9bf. */
7772 if (i >= aux->table_len)
7773 {
7774 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
7775 continue;
7776 }
7777
4770fb94
AM
7778 sym_ndx = get_reloc_symindex (rp->r_info);
7779 if (sym_ndx >= aux->nsyms)
7780 {
7781 warn (_("Skipping reloc with invalid symbol index: %u\n"),
7782 sym_ndx);
7783 continue;
7784 }
7785 sym = aux->symtab + sym_ndx;
7786
53774b7e 7787 switch (rp->r_offset / eh_addr_size % 3)
4d6ed7c8
NC
7788 {
7789 case 0:
7790 aux->table[i].start.section = sym->st_shndx;
e466bc6e 7791 aux->table[i].start.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
7792 break;
7793 case 1:
7794 aux->table[i].end.section = sym->st_shndx;
e466bc6e 7795 aux->table[i].end.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
7796 break;
7797 case 2:
7798 aux->table[i].info.section = sym->st_shndx;
e466bc6e 7799 aux->table[i].info.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
7800 break;
7801 default:
7802 break;
7803 }
7804 }
7805
7806 free (rela);
7807 }
7808
53774b7e 7809 return TRUE;
4d6ed7c8
NC
7810}
7811
32ec8896 7812static bfd_boolean
dda8d76d 7813ia64_process_unwind (Filedata * filedata)
4d6ed7c8 7814{
2cf0635d
NC
7815 Elf_Internal_Shdr * sec;
7816 Elf_Internal_Shdr * unwsec = NULL;
7817 Elf_Internal_Shdr * strsec;
89fac5e3 7818 unsigned long i, unwcount = 0, unwstart = 0;
57346661 7819 struct ia64_unw_aux_info aux;
32ec8896 7820 bfd_boolean res = TRUE;
f1467e33 7821
4d6ed7c8
NC
7822 memset (& aux, 0, sizeof (aux));
7823
dda8d76d 7824 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
4d6ed7c8 7825 {
c256ffe7 7826 if (sec->sh_type == SHT_SYMTAB
dda8d76d 7827 && sec->sh_link < filedata->file_header.e_shnum)
4d6ed7c8 7828 {
dda8d76d 7829 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
4d6ed7c8 7830
dda8d76d 7831 strsec = filedata->section_headers + sec->sh_link;
4082ef84
NC
7832 if (aux.strtab != NULL)
7833 {
7834 error (_("Multiple auxillary string tables encountered\n"));
7835 free (aux.strtab);
32ec8896 7836 res = FALSE;
4082ef84 7837 }
dda8d76d 7838 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
3f5e193b
NC
7839 1, strsec->sh_size,
7840 _("string table"));
c256ffe7 7841 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
4d6ed7c8
NC
7842 }
7843 else if (sec->sh_type == SHT_IA_64_UNWIND)
579f31ac
JJ
7844 unwcount++;
7845 }
7846
7847 if (!unwcount)
7848 printf (_("\nThere are no unwind sections in this file.\n"));
7849
7850 while (unwcount-- > 0)
7851 {
2cf0635d 7852 char * suffix;
579f31ac
JJ
7853 size_t len, len2;
7854
dda8d76d
NC
7855 for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL;
7856 i < filedata->file_header.e_shnum; ++i, ++sec)
579f31ac
JJ
7857 if (sec->sh_type == SHT_IA_64_UNWIND)
7858 {
7859 unwsec = sec;
7860 break;
7861 }
4082ef84
NC
7862 /* We have already counted the number of SHT_IA64_UNWIND
7863 sections so the loop above should never fail. */
7864 assert (unwsec != NULL);
579f31ac
JJ
7865
7866 unwstart = i + 1;
7867 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
7868
e4b17d5c
L
7869 if ((unwsec->sh_flags & SHF_GROUP) != 0)
7870 {
7871 /* We need to find which section group it is in. */
4082ef84 7872 struct group_list * g;
e4b17d5c 7873
4082ef84
NC
7874 if (section_headers_groups == NULL
7875 || section_headers_groups [i] == NULL)
dda8d76d 7876 i = filedata->file_header.e_shnum;
4082ef84 7877 else
e4b17d5c 7878 {
4082ef84 7879 g = section_headers_groups [i]->root;
18bd398b 7880
4082ef84
NC
7881 for (; g != NULL; g = g->next)
7882 {
dda8d76d 7883 sec = filedata->section_headers + g->section_index;
e4b17d5c 7884
4082ef84
NC
7885 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
7886 break;
7887 }
7888
7889 if (g == NULL)
dda8d76d 7890 i = filedata->file_header.e_shnum;
4082ef84 7891 }
e4b17d5c 7892 }
18bd398b 7893 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
579f31ac 7894 {
18bd398b 7895 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
579f31ac
JJ
7896 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
7897 suffix = SECTION_NAME (unwsec) + len;
dda8d76d 7898 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
579f31ac 7899 ++i, ++sec)
18bd398b
NC
7900 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
7901 && streq (SECTION_NAME (sec) + len2, suffix))
579f31ac
JJ
7902 break;
7903 }
7904 else
7905 {
7906 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
18bd398b 7907 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
579f31ac
JJ
7908 len = sizeof (ELF_STRING_ia64_unwind) - 1;
7909 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
7910 suffix = "";
18bd398b 7911 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
579f31ac 7912 suffix = SECTION_NAME (unwsec) + len;
dda8d76d 7913 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
579f31ac 7914 ++i, ++sec)
18bd398b
NC
7915 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
7916 && streq (SECTION_NAME (sec) + len2, suffix))
579f31ac
JJ
7917 break;
7918 }
7919
dda8d76d 7920 if (i == filedata->file_header.e_shnum)
579f31ac
JJ
7921 {
7922 printf (_("\nCould not find unwind info section for "));
7923
dda8d76d 7924 if (filedata->string_table == NULL)
579f31ac
JJ
7925 printf ("%d", unwsec->sh_name);
7926 else
dda8d76d 7927 printf ("'%s'", printable_section_name (filedata, unwsec));
579f31ac
JJ
7928 }
7929 else
4d6ed7c8 7930 {
4d6ed7c8 7931 aux.info_addr = sec->sh_addr;
dda8d76d 7932 aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1,
4082ef84
NC
7933 sec->sh_size,
7934 _("unwind info"));
59245841 7935 aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
4d6ed7c8 7936
579f31ac 7937 printf (_("\nUnwind section "));
4d6ed7c8 7938
dda8d76d 7939 if (filedata->string_table == NULL)
579f31ac
JJ
7940 printf ("%d", unwsec->sh_name);
7941 else
dda8d76d 7942 printf ("'%s'", printable_section_name (filedata, unwsec));
4d6ed7c8 7943
579f31ac 7944 printf (_(" at offset 0x%lx contains %lu entries:\n"),
e59b4dfb 7945 (unsigned long) unwsec->sh_offset,
89fac5e3 7946 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
4d6ed7c8 7947
dda8d76d 7948 if (slurp_ia64_unwind_table (filedata, & aux, unwsec)
53774b7e 7949 && aux.table_len > 0)
dda8d76d 7950 dump_ia64_unwind (filedata, & aux);
579f31ac
JJ
7951
7952 if (aux.table)
7953 free ((char *) aux.table);
7954 if (aux.info)
7955 free ((char *) aux.info);
7956 aux.table = NULL;
7957 aux.info = NULL;
7958 }
4d6ed7c8 7959 }
4d6ed7c8 7960
4d6ed7c8
NC
7961 if (aux.symtab)
7962 free (aux.symtab);
7963 if (aux.strtab)
7964 free ((char *) aux.strtab);
32ec8896
NC
7965
7966 return res;
4d6ed7c8
NC
7967}
7968
3f5e193b 7969struct hppa_unw_table_entry
32ec8896
NC
7970{
7971 struct absaddr start;
7972 struct absaddr end;
7973 unsigned int Cannot_unwind:1; /* 0 */
7974 unsigned int Millicode:1; /* 1 */
7975 unsigned int Millicode_save_sr0:1; /* 2 */
7976 unsigned int Region_description:2; /* 3..4 */
7977 unsigned int reserved1:1; /* 5 */
7978 unsigned int Entry_SR:1; /* 6 */
7979 unsigned int Entry_FR:4; /* Number saved 7..10 */
7980 unsigned int Entry_GR:5; /* Number saved 11..15 */
7981 unsigned int Args_stored:1; /* 16 */
7982 unsigned int Variable_Frame:1; /* 17 */
7983 unsigned int Separate_Package_Body:1; /* 18 */
7984 unsigned int Frame_Extension_Millicode:1; /* 19 */
7985 unsigned int Stack_Overflow_Check:1; /* 20 */
7986 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
7987 unsigned int Ada_Region:1; /* 22 */
7988 unsigned int cxx_info:1; /* 23 */
7989 unsigned int cxx_try_catch:1; /* 24 */
7990 unsigned int sched_entry_seq:1; /* 25 */
7991 unsigned int reserved2:1; /* 26 */
7992 unsigned int Save_SP:1; /* 27 */
7993 unsigned int Save_RP:1; /* 28 */
7994 unsigned int Save_MRP_in_frame:1; /* 29 */
7995 unsigned int extn_ptr_defined:1; /* 30 */
7996 unsigned int Cleanup_defined:1; /* 31 */
7997
7998 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
7999 unsigned int HP_UX_interrupt_marker:1; /* 1 */
8000 unsigned int Large_frame:1; /* 2 */
8001 unsigned int Pseudo_SP_Set:1; /* 3 */
8002 unsigned int reserved4:1; /* 4 */
8003 unsigned int Total_frame_size:27; /* 5..31 */
8004};
3f5e193b 8005
57346661 8006struct hppa_unw_aux_info
948f632f 8007{
32ec8896
NC
8008 struct hppa_unw_table_entry * table; /* Unwind table. */
8009 unsigned long table_len; /* Length of unwind table. */
8010 bfd_vma seg_base; /* Starting address of segment. */
8011 Elf_Internal_Sym * symtab; /* The symbol table. */
8012 unsigned long nsyms; /* Number of symbols. */
8013 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8014 unsigned long nfuns; /* Number of entries in funtab. */
8015 char * strtab; /* The string table. */
8016 unsigned long strtab_size; /* Size of string table. */
948f632f 8017};
57346661 8018
32ec8896 8019static bfd_boolean
dda8d76d 8020dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux)
57346661 8021{
2cf0635d 8022 struct hppa_unw_table_entry * tp;
948f632f 8023 unsigned long j, nfuns;
32ec8896 8024 bfd_boolean res = TRUE;
948f632f
DA
8025
8026 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
8027 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
8028 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
8029 aux->funtab[nfuns++] = aux->symtab[j];
8030 aux->nfuns = nfuns;
8031 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
57346661 8032
57346661
AM
8033 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
8034 {
8035 bfd_vma offset;
2cf0635d 8036 const char * procname;
57346661 8037
dda8d76d 8038 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
57346661
AM
8039 aux->strtab_size, tp->start, &procname,
8040 &offset);
8041
8042 fputs ("\n<", stdout);
8043
8044 if (procname)
8045 {
8046 fputs (procname, stdout);
8047
8048 if (offset)
8049 printf ("+%lx", (unsigned long) offset);
8050 }
8051
8052 fputs (">: [", stdout);
8053 print_vma (tp->start.offset, PREFIX_HEX);
8054 fputc ('-', stdout);
8055 print_vma (tp->end.offset, PREFIX_HEX);
8056 printf ("]\n\t");
8057
18bd398b
NC
8058#define PF(_m) if (tp->_m) printf (#_m " ");
8059#define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
57346661
AM
8060 PF(Cannot_unwind);
8061 PF(Millicode);
8062 PF(Millicode_save_sr0);
18bd398b 8063 /* PV(Region_description); */
57346661
AM
8064 PF(Entry_SR);
8065 PV(Entry_FR);
8066 PV(Entry_GR);
8067 PF(Args_stored);
8068 PF(Variable_Frame);
8069 PF(Separate_Package_Body);
8070 PF(Frame_Extension_Millicode);
8071 PF(Stack_Overflow_Check);
8072 PF(Two_Instruction_SP_Increment);
8073 PF(Ada_Region);
8074 PF(cxx_info);
8075 PF(cxx_try_catch);
8076 PF(sched_entry_seq);
8077 PF(Save_SP);
8078 PF(Save_RP);
8079 PF(Save_MRP_in_frame);
8080 PF(extn_ptr_defined);
8081 PF(Cleanup_defined);
8082 PF(MPE_XL_interrupt_marker);
8083 PF(HP_UX_interrupt_marker);
8084 PF(Large_frame);
8085 PF(Pseudo_SP_Set);
8086 PV(Total_frame_size);
8087#undef PF
8088#undef PV
8089 }
8090
18bd398b 8091 printf ("\n");
948f632f
DA
8092
8093 free (aux->funtab);
32ec8896
NC
8094
8095 return res;
57346661
AM
8096}
8097
32ec8896 8098static bfd_boolean
dda8d76d
NC
8099slurp_hppa_unwind_table (Filedata * filedata,
8100 struct hppa_unw_aux_info * aux,
8101 Elf_Internal_Shdr * sec)
57346661 8102{
1c0751b2 8103 unsigned long size, unw_ent_size, nentries, nrelas, i;
2cf0635d
NC
8104 Elf_Internal_Phdr * seg;
8105 struct hppa_unw_table_entry * tep;
8106 Elf_Internal_Shdr * relsec;
8107 Elf_Internal_Rela * rela;
8108 Elf_Internal_Rela * rp;
8109 unsigned char * table;
8110 unsigned char * tp;
8111 Elf_Internal_Sym * sym;
8112 const char * relname;
57346661 8113
57346661
AM
8114 /* First, find the starting address of the segment that includes
8115 this section. */
dda8d76d 8116 if (filedata->file_header.e_phnum)
57346661 8117 {
dda8d76d 8118 if (! get_program_headers (filedata))
32ec8896 8119 return FALSE;
57346661 8120
dda8d76d
NC
8121 for (seg = filedata->program_headers;
8122 seg < filedata->program_headers + filedata->file_header.e_phnum;
57346661
AM
8123 ++seg)
8124 {
8125 if (seg->p_type != PT_LOAD)
8126 continue;
8127
8128 if (sec->sh_addr >= seg->p_vaddr
8129 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
8130 {
8131 aux->seg_base = seg->p_vaddr;
8132 break;
8133 }
8134 }
8135 }
8136
8137 /* Second, build the unwind table from the contents of the unwind
8138 section. */
8139 size = sec->sh_size;
dda8d76d 8140 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
3f5e193b 8141 _("unwind table"));
57346661 8142 if (!table)
32ec8896 8143 return FALSE;
57346661 8144
1c0751b2
DA
8145 unw_ent_size = 16;
8146 nentries = size / unw_ent_size;
8147 size = unw_ent_size * nentries;
57346661 8148
3f5e193b
NC
8149 tep = aux->table = (struct hppa_unw_table_entry *)
8150 xcmalloc (nentries, sizeof (aux->table[0]));
57346661 8151
1c0751b2 8152 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
57346661
AM
8153 {
8154 unsigned int tmp1, tmp2;
8155
8156 tep->start.section = SHN_UNDEF;
8157 tep->end.section = SHN_UNDEF;
8158
1c0751b2
DA
8159 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
8160 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
8161 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
8162 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
8163
8164 tep->start.offset += aux->seg_base;
8165 tep->end.offset += aux->seg_base;
57346661
AM
8166
8167 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
8168 tep->Millicode = (tmp1 >> 30) & 0x1;
8169 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
8170 tep->Region_description = (tmp1 >> 27) & 0x3;
8171 tep->reserved1 = (tmp1 >> 26) & 0x1;
8172 tep->Entry_SR = (tmp1 >> 25) & 0x1;
8173 tep->Entry_FR = (tmp1 >> 21) & 0xf;
8174 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
8175 tep->Args_stored = (tmp1 >> 15) & 0x1;
8176 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
8177 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
8178 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
8179 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
8180 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
8181 tep->Ada_Region = (tmp1 >> 9) & 0x1;
8182 tep->cxx_info = (tmp1 >> 8) & 0x1;
8183 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
8184 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
8185 tep->reserved2 = (tmp1 >> 5) & 0x1;
8186 tep->Save_SP = (tmp1 >> 4) & 0x1;
8187 tep->Save_RP = (tmp1 >> 3) & 0x1;
8188 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
8189 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
8190 tep->Cleanup_defined = tmp1 & 0x1;
8191
8192 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
8193 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
8194 tep->Large_frame = (tmp2 >> 29) & 0x1;
8195 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
8196 tep->reserved4 = (tmp2 >> 27) & 0x1;
8197 tep->Total_frame_size = tmp2 & 0x7ffffff;
57346661
AM
8198 }
8199 free (table);
8200
8201 /* Third, apply any relocations to the unwind table. */
dda8d76d
NC
8202 for (relsec = filedata->section_headers;
8203 relsec < filedata->section_headers + filedata->file_header.e_shnum;
57346661
AM
8204 ++relsec)
8205 {
8206 if (relsec->sh_type != SHT_RELA
dda8d76d
NC
8207 || relsec->sh_info >= filedata->file_header.e_shnum
8208 || filedata->section_headers + relsec->sh_info != sec)
57346661
AM
8209 continue;
8210
dda8d76d 8211 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
57346661 8212 & rela, & nrelas))
32ec8896 8213 return FALSE;
57346661
AM
8214
8215 for (rp = rela; rp < rela + nrelas; ++rp)
8216 {
4770fb94 8217 unsigned int sym_ndx;
726bd37d
AM
8218 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
8219 relname = elf_hppa_reloc_type (r_type);
57346661 8220
726bd37d
AM
8221 if (relname == NULL)
8222 {
8223 warn (_("Skipping unknown relocation type: %u\n"), r_type);
8224 continue;
8225 }
8226
57346661 8227 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
0112cd26 8228 if (! const_strneq (relname, "R_PARISC_SEGREL"))
57346661 8229 {
726bd37d 8230 warn (_("Skipping unexpected relocation type: %s\n"), relname);
57346661
AM
8231 continue;
8232 }
8233
8234 i = rp->r_offset / unw_ent_size;
726bd37d
AM
8235 if (i >= aux->table_len)
8236 {
8237 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
8238 continue;
8239 }
57346661 8240
4770fb94
AM
8241 sym_ndx = get_reloc_symindex (rp->r_info);
8242 if (sym_ndx >= aux->nsyms)
8243 {
8244 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8245 sym_ndx);
8246 continue;
8247 }
8248 sym = aux->symtab + sym_ndx;
8249
43f6cd05 8250 switch ((rp->r_offset % unw_ent_size) / 4)
57346661
AM
8251 {
8252 case 0:
8253 aux->table[i].start.section = sym->st_shndx;
1e456d54 8254 aux->table[i].start.offset = sym->st_value + rp->r_addend;
57346661
AM
8255 break;
8256 case 1:
8257 aux->table[i].end.section = sym->st_shndx;
1e456d54 8258 aux->table[i].end.offset = sym->st_value + rp->r_addend;
57346661
AM
8259 break;
8260 default:
8261 break;
8262 }
8263 }
8264
8265 free (rela);
8266 }
8267
1c0751b2 8268 aux->table_len = nentries;
57346661 8269
32ec8896 8270 return TRUE;
57346661
AM
8271}
8272
32ec8896 8273static bfd_boolean
dda8d76d 8274hppa_process_unwind (Filedata * filedata)
57346661 8275{
57346661 8276 struct hppa_unw_aux_info aux;
2cf0635d
NC
8277 Elf_Internal_Shdr * unwsec = NULL;
8278 Elf_Internal_Shdr * strsec;
8279 Elf_Internal_Shdr * sec;
18bd398b 8280 unsigned long i;
32ec8896 8281 bfd_boolean res = TRUE;
57346661 8282
dda8d76d 8283 if (filedata->string_table == NULL)
32ec8896 8284 return FALSE;
1b31d05e
NC
8285
8286 memset (& aux, 0, sizeof (aux));
57346661 8287
dda8d76d 8288 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
57346661 8289 {
c256ffe7 8290 if (sec->sh_type == SHT_SYMTAB
dda8d76d 8291 && sec->sh_link < filedata->file_header.e_shnum)
57346661 8292 {
dda8d76d 8293 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
57346661 8294
dda8d76d 8295 strsec = filedata->section_headers + sec->sh_link;
4082ef84
NC
8296 if (aux.strtab != NULL)
8297 {
8298 error (_("Multiple auxillary string tables encountered\n"));
8299 free (aux.strtab);
32ec8896 8300 res = FALSE;
4082ef84 8301 }
dda8d76d 8302 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
3f5e193b
NC
8303 1, strsec->sh_size,
8304 _("string table"));
c256ffe7 8305 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
57346661 8306 }
18bd398b 8307 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
57346661
AM
8308 unwsec = sec;
8309 }
8310
8311 if (!unwsec)
8312 printf (_("\nThere are no unwind sections in this file.\n"));
8313
dda8d76d 8314 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
57346661 8315 {
18bd398b 8316 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
57346661 8317 {
43f6cd05 8318 unsigned long num_unwind = sec->sh_size / 16;
dda8d76d 8319
d3a49aa8
AM
8320 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8321 "contains %lu entry:\n",
8322 "\nUnwind section '%s' at offset 0x%lx "
8323 "contains %lu entries:\n",
8324 num_unwind),
dda8d76d 8325 printable_section_name (filedata, sec),
57346661 8326 (unsigned long) sec->sh_offset,
d3a49aa8 8327 num_unwind);
57346661 8328
dda8d76d 8329 if (! slurp_hppa_unwind_table (filedata, &aux, sec))
32ec8896 8330 res = FALSE;
66b09c7e
S
8331
8332 if (res && aux.table_len > 0)
32ec8896 8333 {
dda8d76d 8334 if (! dump_hppa_unwind (filedata, &aux))
32ec8896
NC
8335 res = FALSE;
8336 }
57346661
AM
8337
8338 if (aux.table)
8339 free ((char *) aux.table);
8340 aux.table = NULL;
8341 }
8342 }
8343
8344 if (aux.symtab)
8345 free (aux.symtab);
8346 if (aux.strtab)
8347 free ((char *) aux.strtab);
32ec8896
NC
8348
8349 return res;
57346661
AM
8350}
8351
0b6ae522
DJ
8352struct arm_section
8353{
a734115a
NC
8354 unsigned char * data; /* The unwind data. */
8355 Elf_Internal_Shdr * sec; /* The cached unwind section header. */
8356 Elf_Internal_Rela * rela; /* The cached relocations for this section. */
8357 unsigned long nrelas; /* The number of relocations. */
8358 unsigned int rel_type; /* REL or RELA ? */
8359 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
0b6ae522
DJ
8360};
8361
8362struct arm_unw_aux_info
8363{
dda8d76d 8364 Filedata * filedata; /* The file containing the unwind sections. */
a734115a
NC
8365 Elf_Internal_Sym * symtab; /* The file's symbol table. */
8366 unsigned long nsyms; /* Number of symbols. */
948f632f
DA
8367 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8368 unsigned long nfuns; /* Number of these symbols. */
a734115a
NC
8369 char * strtab; /* The file's string table. */
8370 unsigned long strtab_size; /* Size of string table. */
0b6ae522
DJ
8371};
8372
8373static const char *
dda8d76d
NC
8374arm_print_vma_and_name (Filedata * filedata,
8375 struct arm_unw_aux_info * aux,
8376 bfd_vma fn,
8377 struct absaddr addr)
0b6ae522
DJ
8378{
8379 const char *procname;
8380 bfd_vma sym_offset;
8381
8382 if (addr.section == SHN_UNDEF)
8383 addr.offset = fn;
8384
dda8d76d 8385 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
0b6ae522
DJ
8386 aux->strtab_size, addr, &procname,
8387 &sym_offset);
8388
8389 print_vma (fn, PREFIX_HEX);
8390
8391 if (procname)
8392 {
8393 fputs (" <", stdout);
8394 fputs (procname, stdout);
8395
8396 if (sym_offset)
8397 printf ("+0x%lx", (unsigned long) sym_offset);
8398 fputc ('>', stdout);
8399 }
8400
8401 return procname;
8402}
8403
8404static void
8405arm_free_section (struct arm_section *arm_sec)
8406{
8407 if (arm_sec->data != NULL)
8408 free (arm_sec->data);
8409
8410 if (arm_sec->rela != NULL)
8411 free (arm_sec->rela);
8412}
8413
a734115a
NC
8414/* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8415 cached section and install SEC instead.
8416 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8417 and return its valued in * WORDP, relocating if necessary.
1b31d05e 8418 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
a734115a 8419 relocation's offset in ADDR.
1b31d05e
NC
8420 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8421 into the string table of the symbol associated with the reloc. If no
8422 reloc was applied store -1 there.
8423 5) Return TRUE upon success, FALSE otherwise. */
a734115a
NC
8424
8425static bfd_boolean
dda8d76d
NC
8426get_unwind_section_word (Filedata * filedata,
8427 struct arm_unw_aux_info * aux,
1b31d05e
NC
8428 struct arm_section * arm_sec,
8429 Elf_Internal_Shdr * sec,
8430 bfd_vma word_offset,
8431 unsigned int * wordp,
8432 struct absaddr * addr,
8433 bfd_vma * sym_name)
0b6ae522
DJ
8434{
8435 Elf_Internal_Rela *rp;
8436 Elf_Internal_Sym *sym;
8437 const char * relname;
8438 unsigned int word;
8439 bfd_boolean wrapped;
8440
e0a31db1
NC
8441 if (sec == NULL || arm_sec == NULL)
8442 return FALSE;
8443
0b6ae522
DJ
8444 addr->section = SHN_UNDEF;
8445 addr->offset = 0;
8446
1b31d05e
NC
8447 if (sym_name != NULL)
8448 *sym_name = (bfd_vma) -1;
8449
a734115a 8450 /* If necessary, update the section cache. */
0b6ae522
DJ
8451 if (sec != arm_sec->sec)
8452 {
8453 Elf_Internal_Shdr *relsec;
8454
8455 arm_free_section (arm_sec);
8456
8457 arm_sec->sec = sec;
dda8d76d 8458 arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1,
0b6ae522 8459 sec->sh_size, _("unwind data"));
0b6ae522
DJ
8460 arm_sec->rela = NULL;
8461 arm_sec->nrelas = 0;
8462
dda8d76d
NC
8463 for (relsec = filedata->section_headers;
8464 relsec < filedata->section_headers + filedata->file_header.e_shnum;
0b6ae522
DJ
8465 ++relsec)
8466 {
dda8d76d
NC
8467 if (relsec->sh_info >= filedata->file_header.e_shnum
8468 || filedata->section_headers + relsec->sh_info != sec
1ae40aa4
NC
8469 /* PR 15745: Check the section type as well. */
8470 || (relsec->sh_type != SHT_REL
8471 && relsec->sh_type != SHT_RELA))
0b6ae522
DJ
8472 continue;
8473
a734115a 8474 arm_sec->rel_type = relsec->sh_type;
0b6ae522
DJ
8475 if (relsec->sh_type == SHT_REL)
8476 {
dda8d76d 8477 if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset,
0b6ae522
DJ
8478 relsec->sh_size,
8479 & arm_sec->rela, & arm_sec->nrelas))
a734115a 8480 return FALSE;
0b6ae522 8481 }
1ae40aa4 8482 else /* relsec->sh_type == SHT_RELA */
0b6ae522 8483 {
dda8d76d 8484 if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset,
0b6ae522
DJ
8485 relsec->sh_size,
8486 & arm_sec->rela, & arm_sec->nrelas))
a734115a 8487 return FALSE;
0b6ae522 8488 }
1ae40aa4 8489 break;
0b6ae522
DJ
8490 }
8491
8492 arm_sec->next_rela = arm_sec->rela;
8493 }
8494
a734115a 8495 /* If there is no unwind data we can do nothing. */
0b6ae522 8496 if (arm_sec->data == NULL)
a734115a 8497 return FALSE;
0b6ae522 8498
e0a31db1 8499 /* If the offset is invalid then fail. */
f32ba729
NC
8500 if (/* PR 21343 *//* PR 18879 */
8501 sec->sh_size < 4
8502 || word_offset > (sec->sh_size - 4)
1a915552 8503 || ((bfd_signed_vma) word_offset) < 0)
e0a31db1
NC
8504 return FALSE;
8505
a734115a 8506 /* Get the word at the required offset. */
0b6ae522
DJ
8507 word = byte_get (arm_sec->data + word_offset, 4);
8508
0eff7165
NC
8509 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8510 if (arm_sec->rela == NULL)
8511 {
8512 * wordp = word;
8513 return TRUE;
8514 }
8515
a734115a 8516 /* Look through the relocs to find the one that applies to the provided offset. */
0b6ae522
DJ
8517 wrapped = FALSE;
8518 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
8519 {
8520 bfd_vma prelval, offset;
8521
8522 if (rp->r_offset > word_offset && !wrapped)
8523 {
8524 rp = arm_sec->rela;
8525 wrapped = TRUE;
8526 }
8527 if (rp->r_offset > word_offset)
8528 break;
8529
8530 if (rp->r_offset & 3)
8531 {
8532 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8533 (unsigned long) rp->r_offset);
8534 continue;
8535 }
8536
8537 if (rp->r_offset < word_offset)
8538 continue;
8539
74e1a04b
NC
8540 /* PR 17531: file: 027-161405-0.004 */
8541 if (aux->symtab == NULL)
8542 continue;
8543
0b6ae522
DJ
8544 if (arm_sec->rel_type == SHT_REL)
8545 {
8546 offset = word & 0x7fffffff;
8547 if (offset & 0x40000000)
8548 offset |= ~ (bfd_vma) 0x7fffffff;
8549 }
a734115a 8550 else if (arm_sec->rel_type == SHT_RELA)
0b6ae522 8551 offset = rp->r_addend;
a734115a 8552 else
74e1a04b
NC
8553 {
8554 error (_("Unknown section relocation type %d encountered\n"),
8555 arm_sec->rel_type);
8556 break;
8557 }
0b6ae522 8558
071436c6
NC
8559 /* PR 17531 file: 027-1241568-0.004. */
8560 if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
8561 {
8562 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8563 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
8564 break;
8565 }
8566
8567 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
0b6ae522
DJ
8568 offset += sym->st_value;
8569 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
8570
a734115a 8571 /* Check that we are processing the expected reloc type. */
dda8d76d 8572 if (filedata->file_header.e_machine == EM_ARM)
a734115a
NC
8573 {
8574 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
071436c6
NC
8575 if (relname == NULL)
8576 {
8577 warn (_("Skipping unknown ARM relocation type: %d\n"),
8578 (int) ELF32_R_TYPE (rp->r_info));
8579 continue;
8580 }
a734115a
NC
8581
8582 if (streq (relname, "R_ARM_NONE"))
8583 continue;
0b4362b0 8584
a734115a
NC
8585 if (! streq (relname, "R_ARM_PREL31"))
8586 {
071436c6 8587 warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
a734115a
NC
8588 continue;
8589 }
8590 }
dda8d76d 8591 else if (filedata->file_header.e_machine == EM_TI_C6000)
a734115a
NC
8592 {
8593 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
071436c6
NC
8594 if (relname == NULL)
8595 {
8596 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8597 (int) ELF32_R_TYPE (rp->r_info));
8598 continue;
8599 }
0b4362b0 8600
a734115a
NC
8601 if (streq (relname, "R_C6000_NONE"))
8602 continue;
8603
8604 if (! streq (relname, "R_C6000_PREL31"))
8605 {
071436c6 8606 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
a734115a
NC
8607 continue;
8608 }
8609
8610 prelval >>= 1;
8611 }
8612 else
74e1a04b
NC
8613 {
8614 /* This function currently only supports ARM and TI unwinders. */
8615 warn (_("Only TI and ARM unwinders are currently supported\n"));
8616 break;
8617 }
fa197c1c 8618
0b6ae522
DJ
8619 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
8620 addr->section = sym->st_shndx;
8621 addr->offset = offset;
74e1a04b 8622
1b31d05e
NC
8623 if (sym_name)
8624 * sym_name = sym->st_name;
0b6ae522
DJ
8625 break;
8626 }
8627
8628 *wordp = word;
8629 arm_sec->next_rela = rp;
8630
a734115a 8631 return TRUE;
0b6ae522
DJ
8632}
8633
a734115a
NC
8634static const char *tic6x_unwind_regnames[16] =
8635{
0b4362b0
RM
8636 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8637 "A14", "A13", "A12", "A11", "A10",
a734115a
NC
8638 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8639};
fa197c1c 8640
0b6ae522 8641static void
fa197c1c 8642decode_tic6x_unwind_regmask (unsigned int mask)
0b6ae522 8643{
fa197c1c
PB
8644 int i;
8645
8646 for (i = 12; mask; mask >>= 1, i--)
8647 {
8648 if (mask & 1)
8649 {
8650 fputs (tic6x_unwind_regnames[i], stdout);
8651 if (mask > 1)
8652 fputs (", ", stdout);
8653 }
8654 }
8655}
0b6ae522
DJ
8656
8657#define ADVANCE \
8658 if (remaining == 0 && more_words) \
8659 { \
8660 data_offset += 4; \
dda8d76d 8661 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
1b31d05e 8662 data_offset, & word, & addr, NULL)) \
32ec8896 8663 return FALSE; \
0b6ae522
DJ
8664 remaining = 4; \
8665 more_words--; \
8666 } \
8667
8668#define GET_OP(OP) \
8669 ADVANCE; \
8670 if (remaining) \
8671 { \
8672 remaining--; \
8673 (OP) = word >> 24; \
8674 word <<= 8; \
8675 } \
8676 else \
8677 { \
2b692964 8678 printf (_("[Truncated opcode]\n")); \
32ec8896 8679 return FALSE; \
0b6ae522 8680 } \
cc5914eb 8681 printf ("0x%02x ", OP)
0b6ae522 8682
32ec8896 8683static bfd_boolean
dda8d76d
NC
8684decode_arm_unwind_bytecode (Filedata * filedata,
8685 struct arm_unw_aux_info * aux,
948f632f
DA
8686 unsigned int word,
8687 unsigned int remaining,
8688 unsigned int more_words,
8689 bfd_vma data_offset,
8690 Elf_Internal_Shdr * data_sec,
8691 struct arm_section * data_arm_sec)
fa197c1c
PB
8692{
8693 struct absaddr addr;
32ec8896 8694 bfd_boolean res = TRUE;
0b6ae522
DJ
8695
8696 /* Decode the unwinding instructions. */
8697 while (1)
8698 {
8699 unsigned int op, op2;
8700
8701 ADVANCE;
8702 if (remaining == 0)
8703 break;
8704 remaining--;
8705 op = word >> 24;
8706 word <<= 8;
8707
cc5914eb 8708 printf (" 0x%02x ", op);
0b6ae522
DJ
8709
8710 if ((op & 0xc0) == 0x00)
8711 {
8712 int offset = ((op & 0x3f) << 2) + 4;
61865e30 8713
cc5914eb 8714 printf (" vsp = vsp + %d", offset);
0b6ae522
DJ
8715 }
8716 else if ((op & 0xc0) == 0x40)
8717 {
8718 int offset = ((op & 0x3f) << 2) + 4;
61865e30 8719
cc5914eb 8720 printf (" vsp = vsp - %d", offset);
0b6ae522
DJ
8721 }
8722 else if ((op & 0xf0) == 0x80)
8723 {
8724 GET_OP (op2);
8725 if (op == 0x80 && op2 == 0)
8726 printf (_("Refuse to unwind"));
8727 else
8728 {
8729 unsigned int mask = ((op & 0x0f) << 8) | op2;
32ec8896 8730 bfd_boolean first = TRUE;
0b6ae522 8731 int i;
2b692964 8732
0b6ae522
DJ
8733 printf ("pop {");
8734 for (i = 0; i < 12; i++)
8735 if (mask & (1 << i))
8736 {
8737 if (first)
32ec8896 8738 first = FALSE;
0b6ae522
DJ
8739 else
8740 printf (", ");
8741 printf ("r%d", 4 + i);
8742 }
8743 printf ("}");
8744 }
8745 }
8746 else if ((op & 0xf0) == 0x90)
8747 {
8748 if (op == 0x9d || op == 0x9f)
8749 printf (_(" [Reserved]"));
8750 else
cc5914eb 8751 printf (" vsp = r%d", op & 0x0f);
0b6ae522
DJ
8752 }
8753 else if ((op & 0xf0) == 0xa0)
8754 {
8755 int end = 4 + (op & 0x07);
32ec8896 8756 bfd_boolean first = TRUE;
0b6ae522 8757 int i;
61865e30 8758
0b6ae522
DJ
8759 printf (" pop {");
8760 for (i = 4; i <= end; i++)
8761 {
8762 if (first)
32ec8896 8763 first = FALSE;
0b6ae522
DJ
8764 else
8765 printf (", ");
8766 printf ("r%d", i);
8767 }
8768 if (op & 0x08)
8769 {
1b31d05e 8770 if (!first)
0b6ae522
DJ
8771 printf (", ");
8772 printf ("r14");
8773 }
8774 printf ("}");
8775 }
8776 else if (op == 0xb0)
8777 printf (_(" finish"));
8778 else if (op == 0xb1)
8779 {
8780 GET_OP (op2);
8781 if (op2 == 0 || (op2 & 0xf0) != 0)
8782 printf (_("[Spare]"));
8783 else
8784 {
8785 unsigned int mask = op2 & 0x0f;
32ec8896 8786 bfd_boolean first = TRUE;
0b6ae522 8787 int i;
61865e30 8788
0b6ae522
DJ
8789 printf ("pop {");
8790 for (i = 0; i < 12; i++)
8791 if (mask & (1 << i))
8792 {
8793 if (first)
32ec8896 8794 first = FALSE;
0b6ae522
DJ
8795 else
8796 printf (", ");
8797 printf ("r%d", i);
8798 }
8799 printf ("}");
8800 }
8801 }
8802 else if (op == 0xb2)
8803 {
b115cf96 8804 unsigned char buf[9];
0b6ae522
DJ
8805 unsigned int i, len;
8806 unsigned long offset;
61865e30 8807
b115cf96 8808 for (i = 0; i < sizeof (buf); i++)
0b6ae522
DJ
8809 {
8810 GET_OP (buf[i]);
8811 if ((buf[i] & 0x80) == 0)
8812 break;
8813 }
4082ef84 8814 if (i == sizeof (buf))
32ec8896
NC
8815 {
8816 error (_("corrupt change to vsp"));
8817 res = FALSE;
8818 }
4082ef84
NC
8819 else
8820 {
8821 offset = read_uleb128 (buf, &len, buf + i + 1);
8822 assert (len == i + 1);
8823 offset = offset * 4 + 0x204;
8824 printf ("vsp = vsp + %ld", offset);
8825 }
0b6ae522 8826 }
61865e30 8827 else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
0b6ae522 8828 {
61865e30
NC
8829 unsigned int first, last;
8830
8831 GET_OP (op2);
8832 first = op2 >> 4;
8833 last = op2 & 0x0f;
8834 if (op == 0xc8)
8835 first = first + 16;
8836 printf ("pop {D%d", first);
8837 if (last)
8838 printf ("-D%d", first + last);
8839 printf ("}");
8840 }
8841 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
8842 {
8843 unsigned int count = op & 0x07;
8844
8845 printf ("pop {D8");
8846 if (count)
8847 printf ("-D%d", 8 + count);
8848 printf ("}");
8849 }
8850 else if (op >= 0xc0 && op <= 0xc5)
8851 {
8852 unsigned int count = op & 0x07;
8853
8854 printf (" pop {wR10");
8855 if (count)
8856 printf ("-wR%d", 10 + count);
8857 printf ("}");
8858 }
8859 else if (op == 0xc6)
8860 {
8861 unsigned int first, last;
8862
8863 GET_OP (op2);
8864 first = op2 >> 4;
8865 last = op2 & 0x0f;
8866 printf ("pop {wR%d", first);
8867 if (last)
8868 printf ("-wR%d", first + last);
8869 printf ("}");
8870 }
8871 else if (op == 0xc7)
8872 {
8873 GET_OP (op2);
8874 if (op2 == 0 || (op2 & 0xf0) != 0)
8875 printf (_("[Spare]"));
0b6ae522
DJ
8876 else
8877 {
61865e30 8878 unsigned int mask = op2 & 0x0f;
32ec8896 8879 bfd_boolean first = TRUE;
61865e30
NC
8880 int i;
8881
8882 printf ("pop {");
8883 for (i = 0; i < 4; i++)
8884 if (mask & (1 << i))
8885 {
8886 if (first)
32ec8896 8887 first = FALSE;
61865e30
NC
8888 else
8889 printf (", ");
8890 printf ("wCGR%d", i);
8891 }
8892 printf ("}");
0b6ae522
DJ
8893 }
8894 }
61865e30 8895 else
32ec8896
NC
8896 {
8897 printf (_(" [unsupported opcode]"));
8898 res = FALSE;
8899 }
8900
0b6ae522
DJ
8901 printf ("\n");
8902 }
32ec8896
NC
8903
8904 return res;
fa197c1c
PB
8905}
8906
32ec8896 8907static bfd_boolean
dda8d76d
NC
8908decode_tic6x_unwind_bytecode (Filedata * filedata,
8909 struct arm_unw_aux_info * aux,
948f632f
DA
8910 unsigned int word,
8911 unsigned int remaining,
8912 unsigned int more_words,
8913 bfd_vma data_offset,
8914 Elf_Internal_Shdr * data_sec,
8915 struct arm_section * data_arm_sec)
fa197c1c
PB
8916{
8917 struct absaddr addr;
8918
8919 /* Decode the unwinding instructions. */
8920 while (1)
8921 {
8922 unsigned int op, op2;
8923
8924 ADVANCE;
8925 if (remaining == 0)
8926 break;
8927 remaining--;
8928 op = word >> 24;
8929 word <<= 8;
8930
9cf03b7e 8931 printf (" 0x%02x ", op);
fa197c1c
PB
8932
8933 if ((op & 0xc0) == 0x00)
8934 {
8935 int offset = ((op & 0x3f) << 3) + 8;
9cf03b7e 8936 printf (" sp = sp + %d", offset);
fa197c1c
PB
8937 }
8938 else if ((op & 0xc0) == 0x80)
8939 {
8940 GET_OP (op2);
8941 if (op == 0x80 && op2 == 0)
8942 printf (_("Refuse to unwind"));
8943 else
8944 {
8945 unsigned int mask = ((op & 0x1f) << 8) | op2;
8946 if (op & 0x20)
8947 printf ("pop compact {");
8948 else
8949 printf ("pop {");
8950
8951 decode_tic6x_unwind_regmask (mask);
8952 printf("}");
8953 }
8954 }
8955 else if ((op & 0xf0) == 0xc0)
8956 {
8957 unsigned int reg;
8958 unsigned int nregs;
8959 unsigned int i;
8960 const char *name;
a734115a
NC
8961 struct
8962 {
32ec8896
NC
8963 unsigned int offset;
8964 unsigned int reg;
fa197c1c
PB
8965 } regpos[16];
8966
8967 /* Scan entire instruction first so that GET_OP output is not
8968 interleaved with disassembly. */
8969 nregs = 0;
8970 for (i = 0; nregs < (op & 0xf); i++)
8971 {
8972 GET_OP (op2);
8973 reg = op2 >> 4;
8974 if (reg != 0xf)
8975 {
8976 regpos[nregs].offset = i * 2;
8977 regpos[nregs].reg = reg;
8978 nregs++;
8979 }
8980
8981 reg = op2 & 0xf;
8982 if (reg != 0xf)
8983 {
8984 regpos[nregs].offset = i * 2 + 1;
8985 regpos[nregs].reg = reg;
8986 nregs++;
8987 }
8988 }
8989
8990 printf (_("pop frame {"));
18344509 8991 if (nregs == 0)
fa197c1c 8992 {
18344509
NC
8993 printf (_("*corrupt* - no registers specified"));
8994 }
8995 else
8996 {
8997 reg = nregs - 1;
8998 for (i = i * 2; i > 0; i--)
fa197c1c 8999 {
18344509
NC
9000 if (regpos[reg].offset == i - 1)
9001 {
9002 name = tic6x_unwind_regnames[regpos[reg].reg];
9003 if (reg > 0)
9004 reg--;
9005 }
9006 else
9007 name = _("[pad]");
fa197c1c 9008
18344509
NC
9009 fputs (name, stdout);
9010 if (i > 1)
9011 printf (", ");
9012 }
fa197c1c
PB
9013 }
9014
9015 printf ("}");
9016 }
9017 else if (op == 0xd0)
9018 printf (" MOV FP, SP");
9019 else if (op == 0xd1)
9020 printf (" __c6xabi_pop_rts");
9021 else if (op == 0xd2)
9022 {
9023 unsigned char buf[9];
9024 unsigned int i, len;
9025 unsigned long offset;
a734115a 9026
fa197c1c
PB
9027 for (i = 0; i < sizeof (buf); i++)
9028 {
9029 GET_OP (buf[i]);
9030 if ((buf[i] & 0x80) == 0)
9031 break;
9032 }
0eff7165
NC
9033 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9034 if (i == sizeof (buf))
9035 {
0eff7165 9036 warn (_("Corrupt stack pointer adjustment detected\n"));
32ec8896 9037 return FALSE;
0eff7165 9038 }
948f632f 9039
f6f0e17b 9040 offset = read_uleb128 (buf, &len, buf + i + 1);
fa197c1c
PB
9041 assert (len == i + 1);
9042 offset = offset * 8 + 0x408;
9043 printf (_("sp = sp + %ld"), offset);
9044 }
9045 else if ((op & 0xf0) == 0xe0)
9046 {
9047 if ((op & 0x0f) == 7)
9048 printf (" RETURN");
9049 else
9050 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
9051 }
9052 else
9053 {
9054 printf (_(" [unsupported opcode]"));
9055 }
9056 putchar ('\n');
9057 }
32ec8896
NC
9058
9059 return TRUE;
fa197c1c
PB
9060}
9061
9062static bfd_vma
dda8d76d 9063arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where)
fa197c1c
PB
9064{
9065 bfd_vma offset;
9066
9067 offset = word & 0x7fffffff;
9068 if (offset & 0x40000000)
9069 offset |= ~ (bfd_vma) 0x7fffffff;
9070
dda8d76d 9071 if (filedata->file_header.e_machine == EM_TI_C6000)
fa197c1c
PB
9072 offset <<= 1;
9073
9074 return offset + where;
9075}
9076
32ec8896 9077static bfd_boolean
dda8d76d
NC
9078decode_arm_unwind (Filedata * filedata,
9079 struct arm_unw_aux_info * aux,
1b31d05e
NC
9080 unsigned int word,
9081 unsigned int remaining,
9082 bfd_vma data_offset,
9083 Elf_Internal_Shdr * data_sec,
9084 struct arm_section * data_arm_sec)
fa197c1c
PB
9085{
9086 int per_index;
9087 unsigned int more_words = 0;
37e14bc3 9088 struct absaddr addr;
1b31d05e 9089 bfd_vma sym_name = (bfd_vma) -1;
97953bab 9090 bfd_boolean res = TRUE;
fa197c1c
PB
9091
9092 if (remaining == 0)
9093 {
1b31d05e
NC
9094 /* Fetch the first word.
9095 Note - when decoding an object file the address extracted
9096 here will always be 0. So we also pass in the sym_name
9097 parameter so that we can find the symbol associated with
9098 the personality routine. */
dda8d76d 9099 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset,
1b31d05e 9100 & word, & addr, & sym_name))
32ec8896 9101 return FALSE;
1b31d05e 9102
fa197c1c
PB
9103 remaining = 4;
9104 }
c93dbb25
CZ
9105 else
9106 {
9107 addr.section = SHN_UNDEF;
9108 addr.offset = 0;
9109 }
fa197c1c
PB
9110
9111 if ((word & 0x80000000) == 0)
9112 {
9113 /* Expand prel31 for personality routine. */
9114 bfd_vma fn;
9115 const char *procname;
9116
dda8d76d 9117 fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset);
fa197c1c 9118 printf (_(" Personality routine: "));
1b31d05e
NC
9119 if (fn == 0
9120 && addr.section == SHN_UNDEF && addr.offset == 0
9121 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
9122 {
9123 procname = aux->strtab + sym_name;
9124 print_vma (fn, PREFIX_HEX);
9125 if (procname)
9126 {
9127 fputs (" <", stdout);
9128 fputs (procname, stdout);
9129 fputc ('>', stdout);
9130 }
9131 }
9132 else
dda8d76d 9133 procname = arm_print_vma_and_name (filedata, aux, fn, addr);
fa197c1c
PB
9134 fputc ('\n', stdout);
9135
9136 /* The GCC personality routines use the standard compact
9137 encoding, starting with one byte giving the number of
9138 words. */
9139 if (procname != NULL
9140 && (const_strneq (procname, "__gcc_personality_v0")
9141 || const_strneq (procname, "__gxx_personality_v0")
9142 || const_strneq (procname, "__gcj_personality_v0")
9143 || const_strneq (procname, "__gnu_objc_personality_v0")))
9144 {
9145 remaining = 0;
9146 more_words = 1;
9147 ADVANCE;
9148 if (!remaining)
9149 {
9150 printf (_(" [Truncated data]\n"));
32ec8896 9151 return FALSE;
fa197c1c
PB
9152 }
9153 more_words = word >> 24;
9154 word <<= 8;
9155 remaining--;
9156 per_index = -1;
9157 }
9158 else
32ec8896 9159 return TRUE;
fa197c1c
PB
9160 }
9161 else
9162 {
1b31d05e 9163 /* ARM EHABI Section 6.3:
0b4362b0 9164
1b31d05e 9165 An exception-handling table entry for the compact model looks like:
0b4362b0 9166
1b31d05e
NC
9167 31 30-28 27-24 23-0
9168 -- ----- ----- ----
9169 1 0 index Data for personalityRoutine[index] */
9170
dda8d76d 9171 if (filedata->file_header.e_machine == EM_ARM
1b31d05e 9172 && (word & 0x70000000))
32ec8896
NC
9173 {
9174 warn (_("Corrupt ARM compact model table entry: %x \n"), word);
9175 res = FALSE;
9176 }
1b31d05e 9177
fa197c1c 9178 per_index = (word >> 24) & 0x7f;
1b31d05e 9179 printf (_(" Compact model index: %d\n"), per_index);
fa197c1c
PB
9180 if (per_index == 0)
9181 {
9182 more_words = 0;
9183 word <<= 8;
9184 remaining--;
9185 }
9186 else if (per_index < 3)
9187 {
9188 more_words = (word >> 16) & 0xff;
9189 word <<= 16;
9190 remaining -= 2;
9191 }
9192 }
9193
dda8d76d 9194 switch (filedata->file_header.e_machine)
fa197c1c
PB
9195 {
9196 case EM_ARM:
9197 if (per_index < 3)
9198 {
dda8d76d 9199 if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words,
32ec8896
NC
9200 data_offset, data_sec, data_arm_sec))
9201 res = FALSE;
fa197c1c
PB
9202 }
9203 else
1b31d05e
NC
9204 {
9205 warn (_("Unknown ARM compact model index encountered\n"));
9206 printf (_(" [reserved]\n"));
32ec8896 9207 res = FALSE;
1b31d05e 9208 }
fa197c1c
PB
9209 break;
9210
9211 case EM_TI_C6000:
9212 if (per_index < 3)
9213 {
dda8d76d 9214 if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words,
32ec8896
NC
9215 data_offset, data_sec, data_arm_sec))
9216 res = FALSE;
fa197c1c
PB
9217 }
9218 else if (per_index < 5)
9219 {
9220 if (((word >> 17) & 0x7f) == 0x7f)
9221 printf (_(" Restore stack from frame pointer\n"));
9222 else
9223 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
9224 printf (_(" Registers restored: "));
9225 if (per_index == 4)
9226 printf (" (compact) ");
9227 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
9228 putchar ('\n');
9229 printf (_(" Return register: %s\n"),
9230 tic6x_unwind_regnames[word & 0xf]);
9231 }
9232 else
1b31d05e 9233 printf (_(" [reserved (%d)]\n"), per_index);
fa197c1c
PB
9234 break;
9235
9236 default:
74e1a04b 9237 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
dda8d76d 9238 filedata->file_header.e_machine);
32ec8896 9239 res = FALSE;
fa197c1c 9240 }
0b6ae522
DJ
9241
9242 /* Decode the descriptors. Not implemented. */
32ec8896
NC
9243
9244 return res;
0b6ae522
DJ
9245}
9246
32ec8896 9247static bfd_boolean
dda8d76d
NC
9248dump_arm_unwind (Filedata * filedata,
9249 struct arm_unw_aux_info * aux,
9250 Elf_Internal_Shdr * exidx_sec)
0b6ae522
DJ
9251{
9252 struct arm_section exidx_arm_sec, extab_arm_sec;
9253 unsigned int i, exidx_len;
948f632f 9254 unsigned long j, nfuns;
32ec8896 9255 bfd_boolean res = TRUE;
0b6ae522
DJ
9256
9257 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
9258 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
9259 exidx_len = exidx_sec->sh_size / 8;
9260
948f632f
DA
9261 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
9262 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
9263 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
9264 aux->funtab[nfuns++] = aux->symtab[j];
9265 aux->nfuns = nfuns;
9266 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
9267
0b6ae522
DJ
9268 for (i = 0; i < exidx_len; i++)
9269 {
9270 unsigned int exidx_fn, exidx_entry;
9271 struct absaddr fn_addr, entry_addr;
9272 bfd_vma fn;
9273
9274 fputc ('\n', stdout);
9275
dda8d76d 9276 if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
1b31d05e 9277 8 * i, & exidx_fn, & fn_addr, NULL)
dda8d76d 9278 || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
1b31d05e 9279 8 * i + 4, & exidx_entry, & entry_addr, NULL))
0b6ae522 9280 {
948f632f 9281 free (aux->funtab);
1b31d05e
NC
9282 arm_free_section (& exidx_arm_sec);
9283 arm_free_section (& extab_arm_sec);
32ec8896 9284 return FALSE;
0b6ae522
DJ
9285 }
9286
83c257ca
NC
9287 /* ARM EHABI, Section 5:
9288 An index table entry consists of 2 words.
9289 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9290 if (exidx_fn & 0x80000000)
32ec8896
NC
9291 {
9292 warn (_("corrupt index table entry: %x\n"), exidx_fn);
9293 res = FALSE;
9294 }
83c257ca 9295
dda8d76d 9296 fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i);
0b6ae522 9297
dda8d76d 9298 arm_print_vma_and_name (filedata, aux, fn, fn_addr);
0b6ae522
DJ
9299 fputs (": ", stdout);
9300
9301 if (exidx_entry == 1)
9302 {
9303 print_vma (exidx_entry, PREFIX_HEX);
9304 fputs (" [cantunwind]\n", stdout);
9305 }
9306 else if (exidx_entry & 0x80000000)
9307 {
9308 print_vma (exidx_entry, PREFIX_HEX);
9309 fputc ('\n', stdout);
dda8d76d 9310 decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL);
0b6ae522
DJ
9311 }
9312 else
9313 {
8f73510c 9314 bfd_vma table, table_offset = 0;
0b6ae522
DJ
9315 Elf_Internal_Shdr *table_sec;
9316
9317 fputs ("@", stdout);
dda8d76d 9318 table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
0b6ae522
DJ
9319 print_vma (table, PREFIX_HEX);
9320 printf ("\n");
9321
9322 /* Locate the matching .ARM.extab. */
9323 if (entry_addr.section != SHN_UNDEF
dda8d76d 9324 && entry_addr.section < filedata->file_header.e_shnum)
0b6ae522 9325 {
dda8d76d 9326 table_sec = filedata->section_headers + entry_addr.section;
0b6ae522 9327 table_offset = entry_addr.offset;
1a915552
NC
9328 /* PR 18879 */
9329 if (table_offset > table_sec->sh_size
9330 || ((bfd_signed_vma) table_offset) < 0)
9331 {
9332 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9333 (unsigned long) table_offset,
dda8d76d 9334 printable_section_name (filedata, table_sec));
32ec8896 9335 res = FALSE;
1a915552
NC
9336 continue;
9337 }
0b6ae522
DJ
9338 }
9339 else
9340 {
dda8d76d 9341 table_sec = find_section_by_address (filedata, table);
0b6ae522
DJ
9342 if (table_sec != NULL)
9343 table_offset = table - table_sec->sh_addr;
9344 }
32ec8896 9345
0b6ae522
DJ
9346 if (table_sec == NULL)
9347 {
9348 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9349 (unsigned long) table);
32ec8896 9350 res = FALSE;
0b6ae522
DJ
9351 continue;
9352 }
32ec8896 9353
dda8d76d 9354 if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec,
32ec8896
NC
9355 &extab_arm_sec))
9356 res = FALSE;
0b6ae522
DJ
9357 }
9358 }
9359
9360 printf ("\n");
9361
948f632f 9362 free (aux->funtab);
0b6ae522
DJ
9363 arm_free_section (&exidx_arm_sec);
9364 arm_free_section (&extab_arm_sec);
32ec8896
NC
9365
9366 return res;
0b6ae522
DJ
9367}
9368
fa197c1c 9369/* Used for both ARM and C6X unwinding tables. */
1b31d05e 9370
32ec8896 9371static bfd_boolean
dda8d76d 9372arm_process_unwind (Filedata * filedata)
0b6ae522
DJ
9373{
9374 struct arm_unw_aux_info aux;
9375 Elf_Internal_Shdr *unwsec = NULL;
9376 Elf_Internal_Shdr *strsec;
9377 Elf_Internal_Shdr *sec;
9378 unsigned long i;
fa197c1c 9379 unsigned int sec_type;
32ec8896 9380 bfd_boolean res = TRUE;
0b6ae522 9381
dda8d76d 9382 switch (filedata->file_header.e_machine)
fa197c1c
PB
9383 {
9384 case EM_ARM:
9385 sec_type = SHT_ARM_EXIDX;
9386 break;
9387
9388 case EM_TI_C6000:
9389 sec_type = SHT_C6000_UNWIND;
9390 break;
9391
0b4362b0 9392 default:
74e1a04b 9393 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
dda8d76d 9394 filedata->file_header.e_machine);
32ec8896 9395 return FALSE;
fa197c1c
PB
9396 }
9397
dda8d76d 9398 if (filedata->string_table == NULL)
32ec8896 9399 return FALSE;
1b31d05e
NC
9400
9401 memset (& aux, 0, sizeof (aux));
dda8d76d 9402 aux.filedata = filedata;
0b6ae522 9403
dda8d76d 9404 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
0b6ae522 9405 {
dda8d76d 9406 if (sec->sh_type == SHT_SYMTAB && sec->sh_link < filedata->file_header.e_shnum)
0b6ae522 9407 {
dda8d76d 9408 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
0b6ae522 9409
dda8d76d 9410 strsec = filedata->section_headers + sec->sh_link;
74e1a04b
NC
9411
9412 /* PR binutils/17531 file: 011-12666-0.004. */
9413 if (aux.strtab != NULL)
9414 {
4082ef84 9415 error (_("Multiple string tables found in file.\n"));
74e1a04b 9416 free (aux.strtab);
32ec8896 9417 res = FALSE;
74e1a04b 9418 }
dda8d76d 9419 aux.strtab = get_data (NULL, filedata, strsec->sh_offset,
0b6ae522
DJ
9420 1, strsec->sh_size, _("string table"));
9421 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
9422 }
fa197c1c 9423 else if (sec->sh_type == sec_type)
0b6ae522
DJ
9424 unwsec = sec;
9425 }
9426
1b31d05e 9427 if (unwsec == NULL)
0b6ae522 9428 printf (_("\nThere are no unwind sections in this file.\n"));
1b31d05e 9429 else
dda8d76d 9430 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
1b31d05e
NC
9431 {
9432 if (sec->sh_type == sec_type)
9433 {
d3a49aa8
AM
9434 unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size);
9435 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9436 "contains %lu entry:\n",
9437 "\nUnwind section '%s' at offset 0x%lx "
9438 "contains %lu entries:\n",
9439 num_unwind),
dda8d76d 9440 printable_section_name (filedata, sec),
1b31d05e 9441 (unsigned long) sec->sh_offset,
d3a49aa8 9442 num_unwind);
0b6ae522 9443
dda8d76d 9444 if (! dump_arm_unwind (filedata, &aux, sec))
32ec8896 9445 res = FALSE;
1b31d05e
NC
9446 }
9447 }
0b6ae522
DJ
9448
9449 if (aux.symtab)
9450 free (aux.symtab);
9451 if (aux.strtab)
9452 free ((char *) aux.strtab);
32ec8896
NC
9453
9454 return res;
0b6ae522
DJ
9455}
9456
32ec8896 9457static bfd_boolean
dda8d76d 9458process_unwind (Filedata * filedata)
57346661 9459{
2cf0635d
NC
9460 struct unwind_handler
9461 {
32ec8896 9462 unsigned int machtype;
dda8d76d 9463 bfd_boolean (* handler)(Filedata *);
2cf0635d
NC
9464 } handlers[] =
9465 {
0b6ae522 9466 { EM_ARM, arm_process_unwind },
57346661
AM
9467 { EM_IA_64, ia64_process_unwind },
9468 { EM_PARISC, hppa_process_unwind },
fa197c1c 9469 { EM_TI_C6000, arm_process_unwind },
32ec8896 9470 { 0, NULL }
57346661
AM
9471 };
9472 int i;
9473
9474 if (!do_unwind)
32ec8896 9475 return TRUE;
57346661
AM
9476
9477 for (i = 0; handlers[i].handler != NULL; i++)
dda8d76d
NC
9478 if (filedata->file_header.e_machine == handlers[i].machtype)
9479 return handlers[i].handler (filedata);
57346661 9480
1b31d05e 9481 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
dda8d76d 9482 get_machine_name (filedata->file_header.e_machine));
32ec8896 9483 return TRUE;
57346661
AM
9484}
9485
37c18eed
SD
9486static void
9487dynamic_section_aarch64_val (Elf_Internal_Dyn * entry)
9488{
9489 switch (entry->d_tag)
9490 {
9491 case DT_AARCH64_BTI_PLT:
1dbade74 9492 case DT_AARCH64_PAC_PLT:
37c18eed
SD
9493 break;
9494 default:
9495 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9496 break;
9497 }
9498 putchar ('\n');
9499}
9500
252b5132 9501static void
2cf0635d 9502dynamic_section_mips_val (Elf_Internal_Dyn * entry)
252b5132
RH
9503{
9504 switch (entry->d_tag)
9505 {
9506 case DT_MIPS_FLAGS:
9507 if (entry->d_un.d_val == 0)
4b68bca3 9508 printf (_("NONE"));
252b5132
RH
9509 else
9510 {
9511 static const char * opts[] =
9512 {
9513 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9514 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9515 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9516 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9517 "RLD_ORDER_SAFE"
9518 };
9519 unsigned int cnt;
32ec8896 9520 bfd_boolean first = TRUE;
2b692964 9521
60bca95a 9522 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
252b5132
RH
9523 if (entry->d_un.d_val & (1 << cnt))
9524 {
9525 printf ("%s%s", first ? "" : " ", opts[cnt]);
32ec8896 9526 first = FALSE;
252b5132 9527 }
252b5132
RH
9528 }
9529 break;
103f02d3 9530
252b5132 9531 case DT_MIPS_IVERSION:
d79b3d50 9532 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
4b68bca3 9533 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
252b5132 9534 else
76ca31c0
NC
9535 {
9536 char buf[40];
9537 sprintf_vma (buf, entry->d_un.d_ptr);
9538 /* Note: coded this way so that there is a single string for translation. */
9539 printf (_("<corrupt: %s>"), buf);
9540 }
252b5132 9541 break;
103f02d3 9542
252b5132
RH
9543 case DT_MIPS_TIME_STAMP:
9544 {
d5b07ef4 9545 char timebuf[128];
2cf0635d 9546 struct tm * tmp;
91d6fa6a 9547 time_t atime = entry->d_un.d_val;
82b1b41b 9548
91d6fa6a 9549 tmp = gmtime (&atime);
82b1b41b
NC
9550 /* PR 17531: file: 6accc532. */
9551 if (tmp == NULL)
9552 snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
9553 else
9554 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
9555 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9556 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
4b68bca3 9557 printf (_("Time Stamp: %s"), timebuf);
252b5132
RH
9558 }
9559 break;
103f02d3 9560
252b5132
RH
9561 case DT_MIPS_RLD_VERSION:
9562 case DT_MIPS_LOCAL_GOTNO:
9563 case DT_MIPS_CONFLICTNO:
9564 case DT_MIPS_LIBLISTNO:
9565 case DT_MIPS_SYMTABNO:
9566 case DT_MIPS_UNREFEXTNO:
9567 case DT_MIPS_HIPAGENO:
9568 case DT_MIPS_DELTA_CLASS_NO:
9569 case DT_MIPS_DELTA_INSTANCE_NO:
9570 case DT_MIPS_DELTA_RELOC_NO:
9571 case DT_MIPS_DELTA_SYM_NO:
9572 case DT_MIPS_DELTA_CLASSSYM_NO:
9573 case DT_MIPS_COMPACT_SIZE:
c69075ac 9574 print_vma (entry->d_un.d_val, DEC);
252b5132 9575 break;
103f02d3 9576
f16a9783
MS
9577 case DT_MIPS_XHASH:
9578 dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val;
9579 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
9580 /* Falls through. */
9581
103f02d3 9582 default:
4b68bca3 9583 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
103f02d3 9584 }
4b68bca3 9585 putchar ('\n');
103f02d3
UD
9586}
9587
103f02d3 9588static void
2cf0635d 9589dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
103f02d3
UD
9590{
9591 switch (entry->d_tag)
9592 {
9593 case DT_HP_DLD_FLAGS:
9594 {
9595 static struct
9596 {
9597 long int bit;
2cf0635d 9598 const char * str;
5e220199
NC
9599 }
9600 flags[] =
9601 {
9602 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
9603 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
9604 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
9605 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
9606 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
9607 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
9608 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
9609 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
9610 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
9611 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
eec8f817
DA
9612 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
9613 { DT_HP_GST, "HP_GST" },
9614 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
9615 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
9616 { DT_HP_NODELETE, "HP_NODELETE" },
9617 { DT_HP_GROUP, "HP_GROUP" },
9618 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
5e220199 9619 };
32ec8896 9620 bfd_boolean first = TRUE;
5e220199 9621 size_t cnt;
f7a99963 9622 bfd_vma val = entry->d_un.d_val;
103f02d3 9623
60bca95a 9624 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
103f02d3 9625 if (val & flags[cnt].bit)
30800947
NC
9626 {
9627 if (! first)
9628 putchar (' ');
9629 fputs (flags[cnt].str, stdout);
32ec8896 9630 first = FALSE;
30800947
NC
9631 val ^= flags[cnt].bit;
9632 }
76da6bbe 9633
103f02d3 9634 if (val != 0 || first)
f7a99963
NC
9635 {
9636 if (! first)
9637 putchar (' ');
9638 print_vma (val, HEX);
9639 }
103f02d3
UD
9640 }
9641 break;
76da6bbe 9642
252b5132 9643 default:
f7a99963
NC
9644 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9645 break;
252b5132 9646 }
35b1837e 9647 putchar ('\n');
252b5132
RH
9648}
9649
28f997cf
TG
9650#ifdef BFD64
9651
9652/* VMS vs Unix time offset and factor. */
9653
9654#define VMS_EPOCH_OFFSET 35067168000000000LL
9655#define VMS_GRANULARITY_FACTOR 10000000
9656
9657/* Display a VMS time in a human readable format. */
9658
9659static void
9660print_vms_time (bfd_int64_t vmstime)
9661{
9662 struct tm *tm;
9663 time_t unxtime;
9664
9665 unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
9666 tm = gmtime (&unxtime);
9667 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
9668 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
9669 tm->tm_hour, tm->tm_min, tm->tm_sec);
9670}
9671#endif /* BFD64 */
9672
ecc51f48 9673static void
2cf0635d 9674dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
ecc51f48
NC
9675{
9676 switch (entry->d_tag)
9677 {
0de14b54 9678 case DT_IA_64_PLT_RESERVE:
bdf4d63a 9679 /* First 3 slots reserved. */
ecc51f48
NC
9680 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9681 printf (" -- ");
9682 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
bdf4d63a
JJ
9683 break;
9684
28f997cf
TG
9685 case DT_IA_64_VMS_LINKTIME:
9686#ifdef BFD64
9687 print_vms_time (entry->d_un.d_val);
9688#endif
9689 break;
9690
9691 case DT_IA_64_VMS_LNKFLAGS:
9692 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9693 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
9694 printf (" CALL_DEBUG");
9695 if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
9696 printf (" NOP0BUFS");
9697 if (entry->d_un.d_val & VMS_LF_P0IMAGE)
9698 printf (" P0IMAGE");
9699 if (entry->d_un.d_val & VMS_LF_MKTHREADS)
9700 printf (" MKTHREADS");
9701 if (entry->d_un.d_val & VMS_LF_UPCALLS)
9702 printf (" UPCALLS");
9703 if (entry->d_un.d_val & VMS_LF_IMGSTA)
9704 printf (" IMGSTA");
9705 if (entry->d_un.d_val & VMS_LF_INITIALIZE)
9706 printf (" INITIALIZE");
9707 if (entry->d_un.d_val & VMS_LF_MAIN)
9708 printf (" MAIN");
9709 if (entry->d_un.d_val & VMS_LF_EXE_INIT)
9710 printf (" EXE_INIT");
9711 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
9712 printf (" TBK_IN_IMG");
9713 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
9714 printf (" DBG_IN_IMG");
9715 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
9716 printf (" TBK_IN_DSF");
9717 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
9718 printf (" DBG_IN_DSF");
9719 if (entry->d_un.d_val & VMS_LF_SIGNATURES)
9720 printf (" SIGNATURES");
9721 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
9722 printf (" REL_SEG_OFF");
9723 break;
9724
bdf4d63a
JJ
9725 default:
9726 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9727 break;
ecc51f48 9728 }
bdf4d63a 9729 putchar ('\n');
ecc51f48
NC
9730}
9731
32ec8896 9732static bfd_boolean
dda8d76d 9733get_32bit_dynamic_section (Filedata * filedata)
252b5132 9734{
2cf0635d
NC
9735 Elf32_External_Dyn * edyn;
9736 Elf32_External_Dyn * ext;
9737 Elf_Internal_Dyn * entry;
103f02d3 9738
dda8d76d 9739 edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
3f5e193b 9740 dynamic_size, _("dynamic section"));
a6e9f9df 9741 if (!edyn)
32ec8896 9742 return FALSE;
103f02d3 9743
071436c6
NC
9744 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9745 might not have the luxury of section headers. Look for the DT_NULL
9746 terminator to determine the number of entries. */
ba2685cc 9747 for (ext = edyn, dynamic_nent = 0;
53c3012c 9748 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
ba2685cc
AM
9749 ext++)
9750 {
9751 dynamic_nent++;
9752 if (BYTE_GET (ext->d_tag) == DT_NULL)
9753 break;
9754 }
252b5132 9755
3f5e193b
NC
9756 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9757 sizeof (* entry));
b2d38a17 9758 if (dynamic_section == NULL)
252b5132 9759 {
8b73c356
NC
9760 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9761 (unsigned long) dynamic_nent);
9ea033b2 9762 free (edyn);
32ec8896 9763 return FALSE;
9ea033b2 9764 }
252b5132 9765
fb514b26 9766 for (ext = edyn, entry = dynamic_section;
ba2685cc 9767 entry < dynamic_section + dynamic_nent;
fb514b26 9768 ext++, entry++)
9ea033b2 9769 {
fb514b26
AM
9770 entry->d_tag = BYTE_GET (ext->d_tag);
9771 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
252b5132
RH
9772 }
9773
9ea033b2
NC
9774 free (edyn);
9775
32ec8896 9776 return TRUE;
9ea033b2
NC
9777}
9778
32ec8896 9779static bfd_boolean
dda8d76d 9780get_64bit_dynamic_section (Filedata * filedata)
9ea033b2 9781{
2cf0635d
NC
9782 Elf64_External_Dyn * edyn;
9783 Elf64_External_Dyn * ext;
9784 Elf_Internal_Dyn * entry;
103f02d3 9785
071436c6 9786 /* Read in the data. */
dda8d76d 9787 edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
3f5e193b 9788 dynamic_size, _("dynamic section"));
a6e9f9df 9789 if (!edyn)
32ec8896 9790 return FALSE;
103f02d3 9791
071436c6
NC
9792 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9793 might not have the luxury of section headers. Look for the DT_NULL
9794 terminator to determine the number of entries. */
ba2685cc 9795 for (ext = edyn, dynamic_nent = 0;
53c3012c
AM
9796 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
9797 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
ba2685cc
AM
9798 ext++)
9799 {
9800 dynamic_nent++;
66543521 9801 if (BYTE_GET (ext->d_tag) == DT_NULL)
ba2685cc
AM
9802 break;
9803 }
252b5132 9804
3f5e193b
NC
9805 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9806 sizeof (* entry));
b2d38a17 9807 if (dynamic_section == NULL)
252b5132 9808 {
8b73c356
NC
9809 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9810 (unsigned long) dynamic_nent);
252b5132 9811 free (edyn);
32ec8896 9812 return FALSE;
252b5132
RH
9813 }
9814
071436c6 9815 /* Convert from external to internal formats. */
fb514b26 9816 for (ext = edyn, entry = dynamic_section;
ba2685cc 9817 entry < dynamic_section + dynamic_nent;
fb514b26 9818 ext++, entry++)
252b5132 9819 {
66543521
AM
9820 entry->d_tag = BYTE_GET (ext->d_tag);
9821 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
252b5132
RH
9822 }
9823
9824 free (edyn);
9825
32ec8896 9826 return TRUE;
9ea033b2
NC
9827}
9828
e9e44622
JJ
9829static void
9830print_dynamic_flags (bfd_vma flags)
d1133906 9831{
32ec8896 9832 bfd_boolean first = TRUE;
13ae64f3 9833
d1133906
NC
9834 while (flags)
9835 {
9836 bfd_vma flag;
9837
9838 flag = flags & - flags;
9839 flags &= ~ flag;
9840
e9e44622 9841 if (first)
32ec8896 9842 first = FALSE;
e9e44622
JJ
9843 else
9844 putc (' ', stdout);
13ae64f3 9845
d1133906
NC
9846 switch (flag)
9847 {
e9e44622
JJ
9848 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
9849 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
9850 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
9851 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
9852 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
2b692964 9853 default: fputs (_("unknown"), stdout); break;
d1133906
NC
9854 }
9855 }
e9e44622 9856 puts ("");
d1133906
NC
9857}
9858
b2d38a17
NC
9859/* Parse and display the contents of the dynamic section. */
9860
32ec8896 9861static bfd_boolean
dda8d76d 9862process_dynamic_section (Filedata * filedata)
9ea033b2 9863{
2cf0635d 9864 Elf_Internal_Dyn * entry;
9ea033b2
NC
9865
9866 if (dynamic_size == 0)
9867 {
9868 if (do_dynamic)
b2d38a17 9869 printf (_("\nThere is no dynamic section in this file.\n"));
9ea033b2 9870
32ec8896 9871 return TRUE;
9ea033b2
NC
9872 }
9873
9874 if (is_32bit_elf)
9875 {
dda8d76d 9876 if (! get_32bit_dynamic_section (filedata))
32ec8896
NC
9877 return FALSE;
9878 }
9879 else
9880 {
dda8d76d 9881 if (! get_64bit_dynamic_section (filedata))
32ec8896 9882 return FALSE;
9ea033b2 9883 }
9ea033b2 9884
252b5132
RH
9885 /* Find the appropriate symbol table. */
9886 if (dynamic_symbols == NULL)
9887 {
86dba8ee
AM
9888 for (entry = dynamic_section;
9889 entry < dynamic_section + dynamic_nent;
9890 ++entry)
252b5132 9891 {
c8286bd1 9892 Elf_Internal_Shdr section;
252b5132
RH
9893
9894 if (entry->d_tag != DT_SYMTAB)
9895 continue;
9896
9897 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
9898
9899 /* Since we do not know how big the symbol table is,
9900 we default to reading in the entire file (!) and
9901 processing that. This is overkill, I know, but it
e3c8793a 9902 should work. */
dda8d76d
NC
9903 section.sh_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
9904 if ((bfd_size_type) section.sh_offset > filedata->file_size)
7296a62a
NC
9905 {
9906 /* See PR 21379 for a reproducer. */
9907 error (_("Invalid DT_SYMTAB entry: %lx"), (long) section.sh_offset);
9908 return FALSE;
9909 }
252b5132 9910
fb52b2f4
NC
9911 if (archive_file_offset != 0)
9912 section.sh_size = archive_file_size - section.sh_offset;
9913 else
dda8d76d 9914 section.sh_size = filedata->file_size - section.sh_offset;
252b5132 9915
9ea033b2 9916 if (is_32bit_elf)
9ad5cbcf 9917 section.sh_entsize = sizeof (Elf32_External_Sym);
9ea033b2 9918 else
9ad5cbcf 9919 section.sh_entsize = sizeof (Elf64_External_Sym);
dda8d76d 9920 section.sh_name = filedata->string_table_length;
252b5132 9921
e3d39609
NC
9922 if (dynamic_symbols != NULL)
9923 {
9924 error (_("Multiple dynamic symbol table sections found\n"));
9925 free (dynamic_symbols);
9926 }
dda8d76d 9927 dynamic_symbols = GET_ELF_SYMBOLS (filedata, &section, & num_dynamic_syms);
19936277 9928 if (num_dynamic_syms < 1)
252b5132
RH
9929 {
9930 error (_("Unable to determine the number of symbols to load\n"));
9931 continue;
9932 }
252b5132
RH
9933 }
9934 }
9935
9936 /* Similarly find a string table. */
9937 if (dynamic_strings == NULL)
9938 {
86dba8ee
AM
9939 for (entry = dynamic_section;
9940 entry < dynamic_section + dynamic_nent;
9941 ++entry)
252b5132
RH
9942 {
9943 unsigned long offset;
b34976b6 9944 long str_tab_len;
252b5132
RH
9945
9946 if (entry->d_tag != DT_STRTAB)
9947 continue;
9948
9949 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
9950
9951 /* Since we do not know how big the string table is,
9952 we default to reading in the entire file (!) and
9953 processing that. This is overkill, I know, but it
e3c8793a 9954 should work. */
252b5132 9955
dda8d76d 9956 offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
fb52b2f4
NC
9957
9958 if (archive_file_offset != 0)
9959 str_tab_len = archive_file_size - offset;
9960 else
86c6c6df 9961 str_tab_len = filedata->file_size - offset;
252b5132
RH
9962
9963 if (str_tab_len < 1)
9964 {
9965 error
9966 (_("Unable to determine the length of the dynamic string table\n"));
9967 continue;
9968 }
9969
e3d39609
NC
9970 if (dynamic_strings != NULL)
9971 {
9972 error (_("Multiple dynamic string tables found\n"));
9973 free (dynamic_strings);
9974 }
9975
dda8d76d 9976 dynamic_strings = (char *) get_data (NULL, filedata, offset, 1,
3f5e193b
NC
9977 str_tab_len,
9978 _("dynamic string table"));
59245841 9979 dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
252b5132
RH
9980 }
9981 }
9982
9983 /* And find the syminfo section if available. */
9984 if (dynamic_syminfo == NULL)
9985 {
3e8bba36 9986 unsigned long syminsz = 0;
252b5132 9987
86dba8ee
AM
9988 for (entry = dynamic_section;
9989 entry < dynamic_section + dynamic_nent;
9990 ++entry)
252b5132
RH
9991 {
9992 if (entry->d_tag == DT_SYMINENT)
9993 {
9994 /* Note: these braces are necessary to avoid a syntax
9995 error from the SunOS4 C compiler. */
049b0c3a
NC
9996 /* PR binutils/17531: A corrupt file can trigger this test.
9997 So do not use an assert, instead generate an error message. */
9998 if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
071436c6 9999 error (_("Bad value (%d) for SYMINENT entry\n"),
049b0c3a 10000 (int) entry->d_un.d_val);
252b5132
RH
10001 }
10002 else if (entry->d_tag == DT_SYMINSZ)
10003 syminsz = entry->d_un.d_val;
10004 else if (entry->d_tag == DT_SYMINFO)
dda8d76d 10005 dynamic_syminfo_offset = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 10006 syminsz);
252b5132
RH
10007 }
10008
10009 if (dynamic_syminfo_offset != 0 && syminsz != 0)
10010 {
2cf0635d
NC
10011 Elf_External_Syminfo * extsyminfo;
10012 Elf_External_Syminfo * extsym;
10013 Elf_Internal_Syminfo * syminfo;
252b5132
RH
10014
10015 /* There is a syminfo section. Read the data. */
3f5e193b 10016 extsyminfo = (Elf_External_Syminfo *)
dda8d76d 10017 get_data (NULL, filedata, dynamic_syminfo_offset, 1, syminsz,
3f5e193b 10018 _("symbol information"));
a6e9f9df 10019 if (!extsyminfo)
32ec8896 10020 return FALSE;
252b5132 10021
e3d39609
NC
10022 if (dynamic_syminfo != NULL)
10023 {
10024 error (_("Multiple dynamic symbol information sections found\n"));
10025 free (dynamic_syminfo);
10026 }
3f5e193b 10027 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
252b5132
RH
10028 if (dynamic_syminfo == NULL)
10029 {
8b73c356
NC
10030 error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
10031 (unsigned long) syminsz);
32ec8896 10032 return FALSE;
252b5132
RH
10033 }
10034
10035 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
86dba8ee
AM
10036 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
10037 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
10038 ++syminfo, ++extsym)
252b5132 10039 {
86dba8ee
AM
10040 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
10041 syminfo->si_flags = BYTE_GET (extsym->si_flags);
252b5132
RH
10042 }
10043
10044 free (extsyminfo);
10045 }
10046 }
10047
10048 if (do_dynamic && dynamic_addr)
d3a49aa8
AM
10049 printf (ngettext ("\nDynamic section at offset 0x%lx "
10050 "contains %lu entry:\n",
10051 "\nDynamic section at offset 0x%lx "
10052 "contains %lu entries:\n",
10053 dynamic_nent),
8b73c356 10054 dynamic_addr, (unsigned long) dynamic_nent);
252b5132
RH
10055 if (do_dynamic)
10056 printf (_(" Tag Type Name/Value\n"));
10057
86dba8ee
AM
10058 for (entry = dynamic_section;
10059 entry < dynamic_section + dynamic_nent;
10060 entry++)
252b5132
RH
10061 {
10062 if (do_dynamic)
f7a99963 10063 {
2cf0635d 10064 const char * dtype;
e699b9ff 10065
f7a99963
NC
10066 putchar (' ');
10067 print_vma (entry->d_tag, FULL_HEX);
dda8d76d 10068 dtype = get_dynamic_type (filedata, entry->d_tag);
e699b9ff 10069 printf (" (%s)%*s", dtype,
32ec8896 10070 ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " ");
f7a99963 10071 }
252b5132
RH
10072
10073 switch (entry->d_tag)
10074 {
d1133906
NC
10075 case DT_FLAGS:
10076 if (do_dynamic)
e9e44622 10077 print_dynamic_flags (entry->d_un.d_val);
d1133906 10078 break;
76da6bbe 10079
252b5132
RH
10080 case DT_AUXILIARY:
10081 case DT_FILTER:
019148e4
L
10082 case DT_CONFIG:
10083 case DT_DEPAUDIT:
10084 case DT_AUDIT:
252b5132
RH
10085 if (do_dynamic)
10086 {
019148e4 10087 switch (entry->d_tag)
b34976b6 10088 {
019148e4
L
10089 case DT_AUXILIARY:
10090 printf (_("Auxiliary library"));
10091 break;
10092
10093 case DT_FILTER:
10094 printf (_("Filter library"));
10095 break;
10096
b34976b6 10097 case DT_CONFIG:
019148e4
L
10098 printf (_("Configuration file"));
10099 break;
10100
10101 case DT_DEPAUDIT:
10102 printf (_("Dependency audit library"));
10103 break;
10104
10105 case DT_AUDIT:
10106 printf (_("Audit library"));
10107 break;
10108 }
252b5132 10109
d79b3d50
NC
10110 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
10111 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
252b5132 10112 else
f7a99963
NC
10113 {
10114 printf (": ");
10115 print_vma (entry->d_un.d_val, PREFIX_HEX);
10116 putchar ('\n');
10117 }
252b5132
RH
10118 }
10119 break;
10120
dcefbbbd 10121 case DT_FEATURE:
252b5132
RH
10122 if (do_dynamic)
10123 {
10124 printf (_("Flags:"));
86f55779 10125
252b5132
RH
10126 if (entry->d_un.d_val == 0)
10127 printf (_(" None\n"));
10128 else
10129 {
10130 unsigned long int val = entry->d_un.d_val;
86f55779 10131
252b5132
RH
10132 if (val & DTF_1_PARINIT)
10133 {
10134 printf (" PARINIT");
10135 val ^= DTF_1_PARINIT;
10136 }
dcefbbbd
L
10137 if (val & DTF_1_CONFEXP)
10138 {
10139 printf (" CONFEXP");
10140 val ^= DTF_1_CONFEXP;
10141 }
252b5132
RH
10142 if (val != 0)
10143 printf (" %lx", val);
10144 puts ("");
10145 }
10146 }
10147 break;
10148
10149 case DT_POSFLAG_1:
10150 if (do_dynamic)
10151 {
10152 printf (_("Flags:"));
86f55779 10153
252b5132
RH
10154 if (entry->d_un.d_val == 0)
10155 printf (_(" None\n"));
10156 else
10157 {
10158 unsigned long int val = entry->d_un.d_val;
86f55779 10159
252b5132
RH
10160 if (val & DF_P1_LAZYLOAD)
10161 {
10162 printf (" LAZYLOAD");
10163 val ^= DF_P1_LAZYLOAD;
10164 }
10165 if (val & DF_P1_GROUPPERM)
10166 {
10167 printf (" GROUPPERM");
10168 val ^= DF_P1_GROUPPERM;
10169 }
10170 if (val != 0)
10171 printf (" %lx", val);
10172 puts ("");
10173 }
10174 }
10175 break;
10176
10177 case DT_FLAGS_1:
10178 if (do_dynamic)
10179 {
10180 printf (_("Flags:"));
10181 if (entry->d_un.d_val == 0)
10182 printf (_(" None\n"));
10183 else
10184 {
10185 unsigned long int val = entry->d_un.d_val;
86f55779 10186
252b5132
RH
10187 if (val & DF_1_NOW)
10188 {
10189 printf (" NOW");
10190 val ^= DF_1_NOW;
10191 }
10192 if (val & DF_1_GLOBAL)
10193 {
10194 printf (" GLOBAL");
10195 val ^= DF_1_GLOBAL;
10196 }
10197 if (val & DF_1_GROUP)
10198 {
10199 printf (" GROUP");
10200 val ^= DF_1_GROUP;
10201 }
10202 if (val & DF_1_NODELETE)
10203 {
10204 printf (" NODELETE");
10205 val ^= DF_1_NODELETE;
10206 }
10207 if (val & DF_1_LOADFLTR)
10208 {
10209 printf (" LOADFLTR");
10210 val ^= DF_1_LOADFLTR;
10211 }
10212 if (val & DF_1_INITFIRST)
10213 {
10214 printf (" INITFIRST");
10215 val ^= DF_1_INITFIRST;
10216 }
10217 if (val & DF_1_NOOPEN)
10218 {
10219 printf (" NOOPEN");
10220 val ^= DF_1_NOOPEN;
10221 }
10222 if (val & DF_1_ORIGIN)
10223 {
10224 printf (" ORIGIN");
10225 val ^= DF_1_ORIGIN;
10226 }
10227 if (val & DF_1_DIRECT)
10228 {
10229 printf (" DIRECT");
10230 val ^= DF_1_DIRECT;
10231 }
10232 if (val & DF_1_TRANS)
10233 {
10234 printf (" TRANS");
10235 val ^= DF_1_TRANS;
10236 }
10237 if (val & DF_1_INTERPOSE)
10238 {
10239 printf (" INTERPOSE");
10240 val ^= DF_1_INTERPOSE;
10241 }
f7db6139 10242 if (val & DF_1_NODEFLIB)
dcefbbbd 10243 {
f7db6139
L
10244 printf (" NODEFLIB");
10245 val ^= DF_1_NODEFLIB;
dcefbbbd
L
10246 }
10247 if (val & DF_1_NODUMP)
10248 {
10249 printf (" NODUMP");
10250 val ^= DF_1_NODUMP;
10251 }
34b60028 10252 if (val & DF_1_CONFALT)
dcefbbbd 10253 {
34b60028
L
10254 printf (" CONFALT");
10255 val ^= DF_1_CONFALT;
10256 }
10257 if (val & DF_1_ENDFILTEE)
10258 {
10259 printf (" ENDFILTEE");
10260 val ^= DF_1_ENDFILTEE;
10261 }
10262 if (val & DF_1_DISPRELDNE)
10263 {
10264 printf (" DISPRELDNE");
10265 val ^= DF_1_DISPRELDNE;
10266 }
10267 if (val & DF_1_DISPRELPND)
10268 {
10269 printf (" DISPRELPND");
10270 val ^= DF_1_DISPRELPND;
10271 }
10272 if (val & DF_1_NODIRECT)
10273 {
10274 printf (" NODIRECT");
10275 val ^= DF_1_NODIRECT;
10276 }
10277 if (val & DF_1_IGNMULDEF)
10278 {
10279 printf (" IGNMULDEF");
10280 val ^= DF_1_IGNMULDEF;
10281 }
10282 if (val & DF_1_NOKSYMS)
10283 {
10284 printf (" NOKSYMS");
10285 val ^= DF_1_NOKSYMS;
10286 }
10287 if (val & DF_1_NOHDR)
10288 {
10289 printf (" NOHDR");
10290 val ^= DF_1_NOHDR;
10291 }
10292 if (val & DF_1_EDITED)
10293 {
10294 printf (" EDITED");
10295 val ^= DF_1_EDITED;
10296 }
10297 if (val & DF_1_NORELOC)
10298 {
10299 printf (" NORELOC");
10300 val ^= DF_1_NORELOC;
10301 }
10302 if (val & DF_1_SYMINTPOSE)
10303 {
10304 printf (" SYMINTPOSE");
10305 val ^= DF_1_SYMINTPOSE;
10306 }
10307 if (val & DF_1_GLOBAUDIT)
10308 {
10309 printf (" GLOBAUDIT");
10310 val ^= DF_1_GLOBAUDIT;
10311 }
10312 if (val & DF_1_SINGLETON)
10313 {
10314 printf (" SINGLETON");
10315 val ^= DF_1_SINGLETON;
dcefbbbd 10316 }
5c383f02
RO
10317 if (val & DF_1_STUB)
10318 {
10319 printf (" STUB");
10320 val ^= DF_1_STUB;
10321 }
10322 if (val & DF_1_PIE)
10323 {
10324 printf (" PIE");
10325 val ^= DF_1_PIE;
10326 }
b1202ffa
L
10327 if (val & DF_1_KMOD)
10328 {
10329 printf (" KMOD");
10330 val ^= DF_1_KMOD;
10331 }
10332 if (val & DF_1_WEAKFILTER)
10333 {
10334 printf (" WEAKFILTER");
10335 val ^= DF_1_WEAKFILTER;
10336 }
10337 if (val & DF_1_NOCOMMON)
10338 {
10339 printf (" NOCOMMON");
10340 val ^= DF_1_NOCOMMON;
10341 }
252b5132
RH
10342 if (val != 0)
10343 printf (" %lx", val);
10344 puts ("");
10345 }
10346 }
10347 break;
10348
10349 case DT_PLTREL:
566b0d53 10350 dynamic_info[entry->d_tag] = entry->d_un.d_val;
252b5132 10351 if (do_dynamic)
dda8d76d 10352 puts (get_dynamic_type (filedata, entry->d_un.d_val));
252b5132
RH
10353 break;
10354
10355 case DT_NULL :
10356 case DT_NEEDED :
10357 case DT_PLTGOT :
10358 case DT_HASH :
10359 case DT_STRTAB :
10360 case DT_SYMTAB :
10361 case DT_RELA :
10362 case DT_INIT :
10363 case DT_FINI :
10364 case DT_SONAME :
10365 case DT_RPATH :
10366 case DT_SYMBOLIC:
10367 case DT_REL :
10368 case DT_DEBUG :
10369 case DT_TEXTREL :
10370 case DT_JMPREL :
019148e4 10371 case DT_RUNPATH :
252b5132
RH
10372 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10373
10374 if (do_dynamic)
10375 {
2cf0635d 10376 char * name;
252b5132 10377
d79b3d50
NC
10378 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
10379 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
252b5132 10380 else
d79b3d50 10381 name = NULL;
252b5132
RH
10382
10383 if (name)
10384 {
10385 switch (entry->d_tag)
10386 {
10387 case DT_NEEDED:
10388 printf (_("Shared library: [%s]"), name);
10389
18bd398b 10390 if (streq (name, program_interpreter))
f7a99963 10391 printf (_(" program interpreter"));
252b5132
RH
10392 break;
10393
10394 case DT_SONAME:
f7a99963 10395 printf (_("Library soname: [%s]"), name);
252b5132
RH
10396 break;
10397
10398 case DT_RPATH:
f7a99963 10399 printf (_("Library rpath: [%s]"), name);
252b5132
RH
10400 break;
10401
019148e4
L
10402 case DT_RUNPATH:
10403 printf (_("Library runpath: [%s]"), name);
10404 break;
10405
252b5132 10406 default:
f7a99963
NC
10407 print_vma (entry->d_un.d_val, PREFIX_HEX);
10408 break;
252b5132
RH
10409 }
10410 }
10411 else
f7a99963
NC
10412 print_vma (entry->d_un.d_val, PREFIX_HEX);
10413
10414 putchar ('\n');
252b5132
RH
10415 }
10416 break;
10417
10418 case DT_PLTRELSZ:
10419 case DT_RELASZ :
10420 case DT_STRSZ :
10421 case DT_RELSZ :
10422 case DT_RELAENT :
10423 case DT_SYMENT :
10424 case DT_RELENT :
566b0d53 10425 dynamic_info[entry->d_tag] = entry->d_un.d_val;
1a0670f3 10426 /* Fall through. */
252b5132
RH
10427 case DT_PLTPADSZ:
10428 case DT_MOVEENT :
10429 case DT_MOVESZ :
10430 case DT_INIT_ARRAYSZ:
10431 case DT_FINI_ARRAYSZ:
047b2264
JJ
10432 case DT_GNU_CONFLICTSZ:
10433 case DT_GNU_LIBLISTSZ:
252b5132 10434 if (do_dynamic)
f7a99963
NC
10435 {
10436 print_vma (entry->d_un.d_val, UNSIGNED);
2b692964 10437 printf (_(" (bytes)\n"));
f7a99963 10438 }
252b5132
RH
10439 break;
10440
10441 case DT_VERDEFNUM:
10442 case DT_VERNEEDNUM:
10443 case DT_RELACOUNT:
10444 case DT_RELCOUNT:
10445 if (do_dynamic)
f7a99963
NC
10446 {
10447 print_vma (entry->d_un.d_val, UNSIGNED);
10448 putchar ('\n');
10449 }
252b5132
RH
10450 break;
10451
10452 case DT_SYMINSZ:
10453 case DT_SYMINENT:
10454 case DT_SYMINFO:
10455 case DT_USED:
10456 case DT_INIT_ARRAY:
10457 case DT_FINI_ARRAY:
10458 if (do_dynamic)
10459 {
d79b3d50
NC
10460 if (entry->d_tag == DT_USED
10461 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
252b5132 10462 {
2cf0635d 10463 char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
252b5132 10464
b34976b6 10465 if (*name)
252b5132
RH
10466 {
10467 printf (_("Not needed object: [%s]\n"), name);
10468 break;
10469 }
10470 }
103f02d3 10471
f7a99963
NC
10472 print_vma (entry->d_un.d_val, PREFIX_HEX);
10473 putchar ('\n');
252b5132
RH
10474 }
10475 break;
10476
10477 case DT_BIND_NOW:
10478 /* The value of this entry is ignored. */
35b1837e
AM
10479 if (do_dynamic)
10480 putchar ('\n');
252b5132 10481 break;
103f02d3 10482
047b2264
JJ
10483 case DT_GNU_PRELINKED:
10484 if (do_dynamic)
10485 {
2cf0635d 10486 struct tm * tmp;
91d6fa6a 10487 time_t atime = entry->d_un.d_val;
047b2264 10488
91d6fa6a 10489 tmp = gmtime (&atime);
071436c6
NC
10490 /* PR 17533 file: 041-1244816-0.004. */
10491 if (tmp == NULL)
5a2cbcf4
L
10492 printf (_("<corrupt time val: %lx"),
10493 (unsigned long) atime);
071436c6
NC
10494 else
10495 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
10496 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
10497 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
047b2264
JJ
10498
10499 }
10500 break;
10501
fdc90cb4
JJ
10502 case DT_GNU_HASH:
10503 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
10504 if (do_dynamic)
10505 {
10506 print_vma (entry->d_un.d_val, PREFIX_HEX);
10507 putchar ('\n');
10508 }
10509 break;
10510
252b5132
RH
10511 default:
10512 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
b34976b6 10513 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
252b5132
RH
10514 entry->d_un.d_val;
10515
10516 if (do_dynamic)
10517 {
dda8d76d 10518 switch (filedata->file_header.e_machine)
252b5132 10519 {
37c18eed
SD
10520 case EM_AARCH64:
10521 dynamic_section_aarch64_val (entry);
10522 break;
252b5132 10523 case EM_MIPS:
4fe85591 10524 case EM_MIPS_RS3_LE:
b2d38a17 10525 dynamic_section_mips_val (entry);
252b5132 10526 break;
103f02d3 10527 case EM_PARISC:
b2d38a17 10528 dynamic_section_parisc_val (entry);
103f02d3 10529 break;
ecc51f48 10530 case EM_IA_64:
b2d38a17 10531 dynamic_section_ia64_val (entry);
ecc51f48 10532 break;
252b5132 10533 default:
f7a99963
NC
10534 print_vma (entry->d_un.d_val, PREFIX_HEX);
10535 putchar ('\n');
252b5132
RH
10536 }
10537 }
10538 break;
10539 }
10540 }
10541
32ec8896 10542 return TRUE;
252b5132
RH
10543}
10544
10545static char *
d3ba0551 10546get_ver_flags (unsigned int flags)
252b5132 10547{
6d4f21f6 10548 static char buff[128];
252b5132
RH
10549
10550 buff[0] = 0;
10551
10552 if (flags == 0)
10553 return _("none");
10554
10555 if (flags & VER_FLG_BASE)
7bb1ad17 10556 strcat (buff, "BASE");
252b5132
RH
10557
10558 if (flags & VER_FLG_WEAK)
10559 {
10560 if (flags & VER_FLG_BASE)
7bb1ad17 10561 strcat (buff, " | ");
252b5132 10562
7bb1ad17 10563 strcat (buff, "WEAK");
252b5132
RH
10564 }
10565
44ec90b9
RO
10566 if (flags & VER_FLG_INFO)
10567 {
10568 if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
7bb1ad17 10569 strcat (buff, " | ");
44ec90b9 10570
7bb1ad17 10571 strcat (buff, "INFO");
44ec90b9
RO
10572 }
10573
10574 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
7bb1ad17
MR
10575 {
10576 if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
10577 strcat (buff, " | ");
10578
10579 strcat (buff, _("<unknown>"));
10580 }
252b5132
RH
10581
10582 return buff;
10583}
10584
10585/* Display the contents of the version sections. */
98fb390a 10586
32ec8896 10587static bfd_boolean
dda8d76d 10588process_version_sections (Filedata * filedata)
252b5132 10589{
2cf0635d 10590 Elf_Internal_Shdr * section;
b34976b6 10591 unsigned i;
32ec8896 10592 bfd_boolean found = FALSE;
252b5132
RH
10593
10594 if (! do_version)
32ec8896 10595 return TRUE;
252b5132 10596
dda8d76d
NC
10597 for (i = 0, section = filedata->section_headers;
10598 i < filedata->file_header.e_shnum;
b34976b6 10599 i++, section++)
252b5132
RH
10600 {
10601 switch (section->sh_type)
10602 {
10603 case SHT_GNU_verdef:
10604 {
2cf0635d 10605 Elf_External_Verdef * edefs;
452bf675
AM
10606 unsigned long idx;
10607 unsigned long cnt;
2cf0635d 10608 char * endbuf;
252b5132 10609
32ec8896 10610 found = TRUE;
252b5132 10611
d3a49aa8
AM
10612 printf (ngettext ("\nVersion definition section '%s' "
10613 "contains %u entry:\n",
10614 "\nVersion definition section '%s' "
10615 "contains %u entries:\n",
10616 section->sh_info),
dda8d76d 10617 printable_section_name (filedata, section),
74e1a04b 10618 section->sh_info);
252b5132 10619
ae9ac79e 10620 printf (_(" Addr: 0x"));
252b5132 10621 printf_vma (section->sh_addr);
233f82cf 10622 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 10623 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 10624 printable_section_name_from_index (filedata, section->sh_link));
252b5132 10625
3f5e193b 10626 edefs = (Elf_External_Verdef *)
dda8d76d 10627 get_data (NULL, filedata, section->sh_offset, 1,section->sh_size,
3f5e193b 10628 _("version definition section"));
a6e9f9df
AM
10629 if (!edefs)
10630 break;
59245841 10631 endbuf = (char *) edefs + section->sh_size;
252b5132 10632
1445030f 10633 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
252b5132 10634 {
2cf0635d
NC
10635 char * vstart;
10636 Elf_External_Verdef * edef;
b34976b6 10637 Elf_Internal_Verdef ent;
2cf0635d 10638 Elf_External_Verdaux * eaux;
b34976b6 10639 Elf_Internal_Verdaux aux;
452bf675 10640 unsigned long isum;
b34976b6 10641 int j;
103f02d3 10642
252b5132 10643 vstart = ((char *) edefs) + idx;
54806181
AM
10644 if (vstart + sizeof (*edef) > endbuf)
10645 break;
252b5132
RH
10646
10647 edef = (Elf_External_Verdef *) vstart;
10648
10649 ent.vd_version = BYTE_GET (edef->vd_version);
10650 ent.vd_flags = BYTE_GET (edef->vd_flags);
10651 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
10652 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
10653 ent.vd_hash = BYTE_GET (edef->vd_hash);
10654 ent.vd_aux = BYTE_GET (edef->vd_aux);
10655 ent.vd_next = BYTE_GET (edef->vd_next);
10656
452bf675 10657 printf (_(" %#06lx: Rev: %d Flags: %s"),
252b5132
RH
10658 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
10659
10660 printf (_(" Index: %d Cnt: %d "),
10661 ent.vd_ndx, ent.vd_cnt);
10662
452bf675 10663 /* Check for overflow. */
1445030f 10664 if (ent.vd_aux > (size_t) (endbuf - vstart))
dd24e3da
NC
10665 break;
10666
252b5132
RH
10667 vstart += ent.vd_aux;
10668
1445030f
AM
10669 if (vstart + sizeof (*eaux) > endbuf)
10670 break;
252b5132
RH
10671 eaux = (Elf_External_Verdaux *) vstart;
10672
10673 aux.vda_name = BYTE_GET (eaux->vda_name);
10674 aux.vda_next = BYTE_GET (eaux->vda_next);
10675
d79b3d50
NC
10676 if (VALID_DYNAMIC_NAME (aux.vda_name))
10677 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
252b5132
RH
10678 else
10679 printf (_("Name index: %ld\n"), aux.vda_name);
10680
10681 isum = idx + ent.vd_aux;
10682
b34976b6 10683 for (j = 1; j < ent.vd_cnt; j++)
252b5132 10684 {
1445030f
AM
10685 if (aux.vda_next < sizeof (*eaux)
10686 && !(j == ent.vd_cnt - 1 && aux.vda_next == 0))
10687 {
10688 warn (_("Invalid vda_next field of %lx\n"),
10689 aux.vda_next);
10690 j = ent.vd_cnt;
10691 break;
10692 }
dd24e3da 10693 /* Check for overflow. */
7e26601c 10694 if (aux.vda_next > (size_t) (endbuf - vstart))
dd24e3da
NC
10695 break;
10696
252b5132
RH
10697 isum += aux.vda_next;
10698 vstart += aux.vda_next;
10699
54806181
AM
10700 if (vstart + sizeof (*eaux) > endbuf)
10701 break;
1445030f 10702 eaux = (Elf_External_Verdaux *) vstart;
252b5132
RH
10703
10704 aux.vda_name = BYTE_GET (eaux->vda_name);
10705 aux.vda_next = BYTE_GET (eaux->vda_next);
10706
d79b3d50 10707 if (VALID_DYNAMIC_NAME (aux.vda_name))
452bf675 10708 printf (_(" %#06lx: Parent %d: %s\n"),
d79b3d50 10709 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
252b5132 10710 else
452bf675 10711 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
252b5132
RH
10712 isum, j, aux.vda_name);
10713 }
dd24e3da 10714
54806181
AM
10715 if (j < ent.vd_cnt)
10716 printf (_(" Version def aux past end of section\n"));
252b5132 10717
c9f02c3e
MR
10718 /* PR 17531:
10719 file: id:000001,src:000172+005151,op:splice,rep:2. */
1445030f
AM
10720 if (ent.vd_next < sizeof (*edef)
10721 && !(cnt == section->sh_info - 1 && ent.vd_next == 0))
10722 {
10723 warn (_("Invalid vd_next field of %lx\n"), ent.vd_next);
10724 cnt = section->sh_info;
10725 break;
10726 }
452bf675 10727 if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx)))
5d921cbd
NC
10728 break;
10729
252b5132
RH
10730 idx += ent.vd_next;
10731 }
dd24e3da 10732
54806181
AM
10733 if (cnt < section->sh_info)
10734 printf (_(" Version definition past end of section\n"));
252b5132
RH
10735
10736 free (edefs);
10737 }
10738 break;
103f02d3 10739
252b5132
RH
10740 case SHT_GNU_verneed:
10741 {
2cf0635d 10742 Elf_External_Verneed * eneed;
452bf675
AM
10743 unsigned long idx;
10744 unsigned long cnt;
2cf0635d 10745 char * endbuf;
252b5132 10746
32ec8896 10747 found = TRUE;
252b5132 10748
d3a49aa8
AM
10749 printf (ngettext ("\nVersion needs section '%s' "
10750 "contains %u entry:\n",
10751 "\nVersion needs section '%s' "
10752 "contains %u entries:\n",
10753 section->sh_info),
dda8d76d 10754 printable_section_name (filedata, section), section->sh_info);
252b5132
RH
10755
10756 printf (_(" Addr: 0x"));
10757 printf_vma (section->sh_addr);
72de5009 10758 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 10759 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 10760 printable_section_name_from_index (filedata, section->sh_link));
252b5132 10761
dda8d76d 10762 eneed = (Elf_External_Verneed *) get_data (NULL, filedata,
3f5e193b
NC
10763 section->sh_offset, 1,
10764 section->sh_size,
9cf03b7e 10765 _("Version Needs section"));
a6e9f9df
AM
10766 if (!eneed)
10767 break;
59245841 10768 endbuf = (char *) eneed + section->sh_size;
252b5132
RH
10769
10770 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
10771 {
2cf0635d 10772 Elf_External_Verneed * entry;
b34976b6 10773 Elf_Internal_Verneed ent;
452bf675 10774 unsigned long isum;
b34976b6 10775 int j;
2cf0635d 10776 char * vstart;
252b5132
RH
10777
10778 vstart = ((char *) eneed) + idx;
54806181
AM
10779 if (vstart + sizeof (*entry) > endbuf)
10780 break;
252b5132
RH
10781
10782 entry = (Elf_External_Verneed *) vstart;
10783
10784 ent.vn_version = BYTE_GET (entry->vn_version);
10785 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
10786 ent.vn_file = BYTE_GET (entry->vn_file);
10787 ent.vn_aux = BYTE_GET (entry->vn_aux);
10788 ent.vn_next = BYTE_GET (entry->vn_next);
10789
452bf675 10790 printf (_(" %#06lx: Version: %d"), idx, ent.vn_version);
252b5132 10791
d79b3d50
NC
10792 if (VALID_DYNAMIC_NAME (ent.vn_file))
10793 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
252b5132
RH
10794 else
10795 printf (_(" File: %lx"), ent.vn_file);
10796
10797 printf (_(" Cnt: %d\n"), ent.vn_cnt);
10798
dd24e3da 10799 /* Check for overflow. */
7e26601c 10800 if (ent.vn_aux > (size_t) (endbuf - vstart))
dd24e3da 10801 break;
252b5132
RH
10802 vstart += ent.vn_aux;
10803
10804 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
10805 {
2cf0635d 10806 Elf_External_Vernaux * eaux;
b34976b6 10807 Elf_Internal_Vernaux aux;
252b5132 10808
54806181
AM
10809 if (vstart + sizeof (*eaux) > endbuf)
10810 break;
252b5132
RH
10811 eaux = (Elf_External_Vernaux *) vstart;
10812
10813 aux.vna_hash = BYTE_GET (eaux->vna_hash);
10814 aux.vna_flags = BYTE_GET (eaux->vna_flags);
10815 aux.vna_other = BYTE_GET (eaux->vna_other);
10816 aux.vna_name = BYTE_GET (eaux->vna_name);
10817 aux.vna_next = BYTE_GET (eaux->vna_next);
10818
d79b3d50 10819 if (VALID_DYNAMIC_NAME (aux.vna_name))
452bf675 10820 printf (_(" %#06lx: Name: %s"),
d79b3d50 10821 isum, GET_DYNAMIC_NAME (aux.vna_name));
252b5132 10822 else
452bf675 10823 printf (_(" %#06lx: Name index: %lx"),
252b5132
RH
10824 isum, aux.vna_name);
10825
10826 printf (_(" Flags: %s Version: %d\n"),
10827 get_ver_flags (aux.vna_flags), aux.vna_other);
10828
1445030f
AM
10829 if (aux.vna_next < sizeof (*eaux)
10830 && !(j == ent.vn_cnt - 1 && aux.vna_next == 0))
53774b7e
NC
10831 {
10832 warn (_("Invalid vna_next field of %lx\n"),
10833 aux.vna_next);
10834 j = ent.vn_cnt;
10835 break;
10836 }
1445030f
AM
10837 /* Check for overflow. */
10838 if (aux.vna_next > (size_t) (endbuf - vstart))
10839 break;
252b5132
RH
10840 isum += aux.vna_next;
10841 vstart += aux.vna_next;
10842 }
9cf03b7e 10843
54806181 10844 if (j < ent.vn_cnt)
9cf03b7e 10845 warn (_("Missing Version Needs auxillary information\n"));
252b5132 10846
1445030f
AM
10847 if (ent.vn_next < sizeof (*entry)
10848 && !(cnt == section->sh_info - 1 && ent.vn_next == 0))
c24cf8b6 10849 {
452bf675 10850 warn (_("Invalid vn_next field of %lx\n"), ent.vn_next);
c24cf8b6
NC
10851 cnt = section->sh_info;
10852 break;
10853 }
1445030f
AM
10854 if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx)))
10855 break;
252b5132
RH
10856 idx += ent.vn_next;
10857 }
9cf03b7e 10858
54806181 10859 if (cnt < section->sh_info)
9cf03b7e 10860 warn (_("Missing Version Needs information\n"));
103f02d3 10861
252b5132
RH
10862 free (eneed);
10863 }
10864 break;
10865
10866 case SHT_GNU_versym:
10867 {
2cf0635d 10868 Elf_Internal_Shdr * link_section;
8b73c356
NC
10869 size_t total;
10870 unsigned int cnt;
2cf0635d
NC
10871 unsigned char * edata;
10872 unsigned short * data;
10873 char * strtab;
10874 Elf_Internal_Sym * symbols;
10875 Elf_Internal_Shdr * string_sec;
ba5cdace 10876 unsigned long num_syms;
d3ba0551 10877 long off;
252b5132 10878
dda8d76d 10879 if (section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
10880 break;
10881
dda8d76d 10882 link_section = filedata->section_headers + section->sh_link;
08d8fa11 10883 total = section->sh_size / sizeof (Elf_External_Versym);
252b5132 10884
dda8d76d 10885 if (link_section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
10886 break;
10887
32ec8896 10888 found = TRUE;
252b5132 10889
dda8d76d 10890 symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms);
dd24e3da
NC
10891 if (symbols == NULL)
10892 break;
252b5132 10893
dda8d76d 10894 string_sec = filedata->section_headers + link_section->sh_link;
252b5132 10895
dda8d76d 10896 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
3f5e193b
NC
10897 string_sec->sh_size,
10898 _("version string table"));
a6e9f9df 10899 if (!strtab)
0429c154
MS
10900 {
10901 free (symbols);
10902 break;
10903 }
252b5132 10904
d3a49aa8
AM
10905 printf (ngettext ("\nVersion symbols section '%s' "
10906 "contains %lu entry:\n",
10907 "\nVersion symbols section '%s' "
10908 "contains %lu entries:\n",
10909 total),
dda8d76d 10910 printable_section_name (filedata, section), (unsigned long) total);
252b5132 10911
ae9ac79e 10912 printf (_(" Addr: 0x"));
252b5132 10913 printf_vma (section->sh_addr);
72de5009 10914 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 10915 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 10916 printable_section_name (filedata, link_section));
252b5132 10917
dda8d76d 10918 off = offset_from_vma (filedata,
d3ba0551
AM
10919 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
10920 total * sizeof (short));
dda8d76d 10921 edata = (unsigned char *) get_data (NULL, filedata, off, total,
3f5e193b
NC
10922 sizeof (short),
10923 _("version symbol data"));
a6e9f9df
AM
10924 if (!edata)
10925 {
10926 free (strtab);
0429c154 10927 free (symbols);
a6e9f9df
AM
10928 break;
10929 }
252b5132 10930
3f5e193b 10931 data = (short unsigned int *) cmalloc (total, sizeof (short));
252b5132
RH
10932
10933 for (cnt = total; cnt --;)
b34976b6
AM
10934 data[cnt] = byte_get (edata + cnt * sizeof (short),
10935 sizeof (short));
252b5132
RH
10936
10937 free (edata);
10938
10939 for (cnt = 0; cnt < total; cnt += 4)
10940 {
10941 int j, nn;
ab273396
AM
10942 char *name;
10943 char *invalid = _("*invalid*");
252b5132
RH
10944
10945 printf (" %03x:", cnt);
10946
10947 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
b34976b6 10948 switch (data[cnt + j])
252b5132
RH
10949 {
10950 case 0:
10951 fputs (_(" 0 (*local*) "), stdout);
10952 break;
10953
10954 case 1:
10955 fputs (_(" 1 (*global*) "), stdout);
10956 break;
10957
10958 default:
c244d050
NC
10959 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
10960 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
252b5132 10961
dd24e3da 10962 /* If this index value is greater than the size of the symbols
ba5cdace
NC
10963 array, break to avoid an out-of-bounds read. */
10964 if ((unsigned long)(cnt + j) >= num_syms)
dd24e3da
NC
10965 {
10966 warn (_("invalid index into symbol array\n"));
10967 break;
10968 }
10969
ab273396
AM
10970 name = NULL;
10971 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
252b5132 10972 {
b34976b6
AM
10973 Elf_Internal_Verneed ivn;
10974 unsigned long offset;
252b5132 10975
d93f0186 10976 offset = offset_from_vma
dda8d76d 10977 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
d93f0186 10978 sizeof (Elf_External_Verneed));
252b5132 10979
b34976b6 10980 do
252b5132 10981 {
b34976b6
AM
10982 Elf_Internal_Vernaux ivna;
10983 Elf_External_Verneed evn;
10984 Elf_External_Vernaux evna;
10985 unsigned long a_off;
252b5132 10986
dda8d76d 10987 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
59245841
NC
10988 _("version need")) == NULL)
10989 break;
0b4362b0 10990
252b5132
RH
10991 ivn.vn_aux = BYTE_GET (evn.vn_aux);
10992 ivn.vn_next = BYTE_GET (evn.vn_next);
10993
10994 a_off = offset + ivn.vn_aux;
10995
10996 do
10997 {
dda8d76d 10998 if (get_data (&evna, filedata, a_off, sizeof (evna),
59245841
NC
10999 1, _("version need aux (2)")) == NULL)
11000 {
11001 ivna.vna_next = 0;
11002 ivna.vna_other = 0;
11003 }
11004 else
11005 {
11006 ivna.vna_next = BYTE_GET (evna.vna_next);
11007 ivna.vna_other = BYTE_GET (evna.vna_other);
11008 }
252b5132
RH
11009
11010 a_off += ivna.vna_next;
11011 }
b34976b6 11012 while (ivna.vna_other != data[cnt + j]
252b5132
RH
11013 && ivna.vna_next != 0);
11014
b34976b6 11015 if (ivna.vna_other == data[cnt + j])
252b5132
RH
11016 {
11017 ivna.vna_name = BYTE_GET (evna.vna_name);
11018
54806181 11019 if (ivna.vna_name >= string_sec->sh_size)
ab273396 11020 name = invalid;
54806181
AM
11021 else
11022 name = strtab + ivna.vna_name;
252b5132
RH
11023 break;
11024 }
11025
11026 offset += ivn.vn_next;
11027 }
11028 while (ivn.vn_next);
11029 }
00d93f34 11030
ab273396 11031 if (data[cnt + j] != 0x8001
b34976b6 11032 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
252b5132 11033 {
b34976b6
AM
11034 Elf_Internal_Verdef ivd;
11035 Elf_External_Verdef evd;
11036 unsigned long offset;
252b5132 11037
d93f0186 11038 offset = offset_from_vma
dda8d76d 11039 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
d93f0186 11040 sizeof evd);
252b5132
RH
11041
11042 do
11043 {
dda8d76d 11044 if (get_data (&evd, filedata, offset, sizeof (evd), 1,
59245841
NC
11045 _("version def")) == NULL)
11046 {
11047 ivd.vd_next = 0;
948f632f 11048 /* PR 17531: file: 046-1082287-0.004. */
3102e897
NC
11049 ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
11050 break;
59245841
NC
11051 }
11052 else
11053 {
11054 ivd.vd_next = BYTE_GET (evd.vd_next);
11055 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
11056 }
252b5132
RH
11057
11058 offset += ivd.vd_next;
11059 }
c244d050 11060 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
252b5132
RH
11061 && ivd.vd_next != 0);
11062
c244d050 11063 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
252b5132 11064 {
b34976b6
AM
11065 Elf_External_Verdaux evda;
11066 Elf_Internal_Verdaux ivda;
252b5132
RH
11067
11068 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11069
dda8d76d 11070 if (get_data (&evda, filedata,
59245841
NC
11071 offset - ivd.vd_next + ivd.vd_aux,
11072 sizeof (evda), 1,
11073 _("version def aux")) == NULL)
11074 break;
252b5132
RH
11075
11076 ivda.vda_name = BYTE_GET (evda.vda_name);
11077
54806181 11078 if (ivda.vda_name >= string_sec->sh_size)
ab273396
AM
11079 name = invalid;
11080 else if (name != NULL && name != invalid)
11081 name = _("*both*");
54806181
AM
11082 else
11083 name = strtab + ivda.vda_name;
252b5132
RH
11084 }
11085 }
ab273396
AM
11086 if (name != NULL)
11087 nn += printf ("(%s%-*s",
11088 name,
11089 12 - (int) strlen (name),
11090 ")");
252b5132
RH
11091
11092 if (nn < 18)
11093 printf ("%*c", 18 - nn, ' ');
11094 }
11095
11096 putchar ('\n');
11097 }
11098
11099 free (data);
11100 free (strtab);
11101 free (symbols);
11102 }
11103 break;
103f02d3 11104
252b5132
RH
11105 default:
11106 break;
11107 }
11108 }
11109
11110 if (! found)
11111 printf (_("\nNo version information found in this file.\n"));
11112
32ec8896 11113 return TRUE;
252b5132
RH
11114}
11115
d1133906 11116static const char *
dda8d76d 11117get_symbol_binding (Filedata * filedata, unsigned int binding)
252b5132 11118{
b34976b6 11119 static char buff[32];
252b5132
RH
11120
11121 switch (binding)
11122 {
b34976b6
AM
11123 case STB_LOCAL: return "LOCAL";
11124 case STB_GLOBAL: return "GLOBAL";
11125 case STB_WEAK: return "WEAK";
252b5132
RH
11126 default:
11127 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
e9e44622
JJ
11128 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
11129 binding);
252b5132 11130 else if (binding >= STB_LOOS && binding <= STB_HIOS)
3e7a7d11
NC
11131 {
11132 if (binding == STB_GNU_UNIQUE
df3a023b 11133 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU)
3e7a7d11
NC
11134 return "UNIQUE";
11135 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
11136 }
252b5132 11137 else
e9e44622 11138 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
252b5132
RH
11139 return buff;
11140 }
11141}
11142
d1133906 11143static const char *
dda8d76d 11144get_symbol_type (Filedata * filedata, unsigned int type)
252b5132 11145{
b34976b6 11146 static char buff[32];
252b5132
RH
11147
11148 switch (type)
11149 {
b34976b6
AM
11150 case STT_NOTYPE: return "NOTYPE";
11151 case STT_OBJECT: return "OBJECT";
11152 case STT_FUNC: return "FUNC";
11153 case STT_SECTION: return "SECTION";
11154 case STT_FILE: return "FILE";
11155 case STT_COMMON: return "COMMON";
11156 case STT_TLS: return "TLS";
15ab5209
DB
11157 case STT_RELC: return "RELC";
11158 case STT_SRELC: return "SRELC";
252b5132
RH
11159 default:
11160 if (type >= STT_LOPROC && type <= STT_HIPROC)
df75f1af 11161 {
dda8d76d 11162 if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
3510a7b8 11163 return "THUMB_FUNC";
103f02d3 11164
dda8d76d 11165 if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
103f02d3
UD
11166 return "REGISTER";
11167
dda8d76d 11168 if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
103f02d3
UD
11169 return "PARISC_MILLI";
11170
e9e44622 11171 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
df75f1af 11172 }
252b5132 11173 else if (type >= STT_LOOS && type <= STT_HIOS)
103f02d3 11174 {
dda8d76d 11175 if (filedata->file_header.e_machine == EM_PARISC)
103f02d3
UD
11176 {
11177 if (type == STT_HP_OPAQUE)
11178 return "HP_OPAQUE";
11179 if (type == STT_HP_STUB)
11180 return "HP_STUB";
11181 }
11182
d8045f23 11183 if (type == STT_GNU_IFUNC
dda8d76d 11184 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
df3a023b 11185 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD))
d8045f23
NC
11186 return "IFUNC";
11187
e9e44622 11188 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
103f02d3 11189 }
252b5132 11190 else
e9e44622 11191 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
252b5132
RH
11192 return buff;
11193 }
11194}
11195
d1133906 11196static const char *
d3ba0551 11197get_symbol_visibility (unsigned int visibility)
d1133906
NC
11198{
11199 switch (visibility)
11200 {
b34976b6
AM
11201 case STV_DEFAULT: return "DEFAULT";
11202 case STV_INTERNAL: return "INTERNAL";
11203 case STV_HIDDEN: return "HIDDEN";
d1133906 11204 case STV_PROTECTED: return "PROTECTED";
bee0ee85
NC
11205 default:
11206 error (_("Unrecognized visibility value: %u"), visibility);
11207 return _("<unknown>");
d1133906
NC
11208 }
11209}
11210
2057d69d
CZ
11211static const char *
11212get_alpha_symbol_other (unsigned int other)
9abca702 11213{
2057d69d
CZ
11214 switch (other)
11215 {
11216 case STO_ALPHA_NOPV: return "NOPV";
11217 case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD";
11218 default:
11219 error (_("Unrecognized alpah specific other value: %u"), other);
11220 return _("<unknown>");
9abca702 11221 }
2057d69d
CZ
11222}
11223
fd85a6a1
NC
11224static const char *
11225get_solaris_symbol_visibility (unsigned int visibility)
11226{
11227 switch (visibility)
11228 {
11229 case 4: return "EXPORTED";
11230 case 5: return "SINGLETON";
11231 case 6: return "ELIMINATE";
11232 default: return get_symbol_visibility (visibility);
11233 }
11234}
11235
2301ed1c
SN
11236static const char *
11237get_aarch64_symbol_other (unsigned int other)
11238{
11239 static char buf[32];
11240
11241 if (other & STO_AARCH64_VARIANT_PCS)
11242 {
11243 other &= ~STO_AARCH64_VARIANT_PCS;
11244 if (other == 0)
11245 return "VARIANT_PCS";
11246 snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other);
11247 return buf;
11248 }
11249 return NULL;
11250}
11251
5e2b0d47
NC
11252static const char *
11253get_mips_symbol_other (unsigned int other)
11254{
11255 switch (other)
11256 {
32ec8896
NC
11257 case STO_OPTIONAL: return "OPTIONAL";
11258 case STO_MIPS_PLT: return "MIPS PLT";
11259 case STO_MIPS_PIC: return "MIPS PIC";
11260 case STO_MICROMIPS: return "MICROMIPS";
11261 case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC";
11262 case STO_MIPS16: return "MIPS16";
11263 default: return NULL;
5e2b0d47
NC
11264 }
11265}
11266
28f997cf 11267static const char *
dda8d76d 11268get_ia64_symbol_other (Filedata * filedata, unsigned int other)
28f997cf 11269{
dda8d76d 11270 if (is_ia64_vms (filedata))
28f997cf
TG
11271 {
11272 static char res[32];
11273
11274 res[0] = 0;
11275
11276 /* Function types is for images and .STB files only. */
dda8d76d 11277 switch (filedata->file_header.e_type)
28f997cf
TG
11278 {
11279 case ET_DYN:
11280 case ET_EXEC:
11281 switch (VMS_ST_FUNC_TYPE (other))
11282 {
11283 case VMS_SFT_CODE_ADDR:
11284 strcat (res, " CA");
11285 break;
11286 case VMS_SFT_SYMV_IDX:
11287 strcat (res, " VEC");
11288 break;
11289 case VMS_SFT_FD:
11290 strcat (res, " FD");
11291 break;
11292 case VMS_SFT_RESERVE:
11293 strcat (res, " RSV");
11294 break;
11295 default:
bee0ee85
NC
11296 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
11297 VMS_ST_FUNC_TYPE (other));
11298 strcat (res, " <unknown>");
11299 break;
28f997cf
TG
11300 }
11301 break;
11302 default:
11303 break;
11304 }
11305 switch (VMS_ST_LINKAGE (other))
11306 {
11307 case VMS_STL_IGNORE:
11308 strcat (res, " IGN");
11309 break;
11310 case VMS_STL_RESERVE:
11311 strcat (res, " RSV");
11312 break;
11313 case VMS_STL_STD:
11314 strcat (res, " STD");
11315 break;
11316 case VMS_STL_LNK:
11317 strcat (res, " LNK");
11318 break;
11319 default:
bee0ee85
NC
11320 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
11321 VMS_ST_LINKAGE (other));
11322 strcat (res, " <unknown>");
11323 break;
28f997cf
TG
11324 }
11325
11326 if (res[0] != 0)
11327 return res + 1;
11328 else
11329 return res;
11330 }
11331 return NULL;
11332}
11333
6911b7dc
AM
11334static const char *
11335get_ppc64_symbol_other (unsigned int other)
11336{
14732552
AM
11337 if ((other & ~STO_PPC64_LOCAL_MASK) != 0)
11338 return NULL;
11339
11340 other >>= STO_PPC64_LOCAL_BIT;
11341 if (other <= 6)
6911b7dc
AM
11342 {
11343 static char buf[32];
14732552
AM
11344 if (other >= 2)
11345 other = ppc64_decode_local_entry (other);
11346 snprintf (buf, sizeof buf, _("<localentry>: %d"), other);
6911b7dc
AM
11347 return buf;
11348 }
11349 return NULL;
11350}
11351
5e2b0d47 11352static const char *
dda8d76d 11353get_symbol_other (Filedata * filedata, unsigned int other)
5e2b0d47
NC
11354{
11355 const char * result = NULL;
11356 static char buff [32];
11357
11358 if (other == 0)
11359 return "";
11360
dda8d76d 11361 switch (filedata->file_header.e_machine)
5e2b0d47 11362 {
2057d69d
CZ
11363 case EM_ALPHA:
11364 result = get_alpha_symbol_other (other);
11365 break;
2301ed1c
SN
11366 case EM_AARCH64:
11367 result = get_aarch64_symbol_other (other);
11368 break;
5e2b0d47
NC
11369 case EM_MIPS:
11370 result = get_mips_symbol_other (other);
28f997cf
TG
11371 break;
11372 case EM_IA_64:
dda8d76d 11373 result = get_ia64_symbol_other (filedata, other);
28f997cf 11374 break;
6911b7dc
AM
11375 case EM_PPC64:
11376 result = get_ppc64_symbol_other (other);
11377 break;
5e2b0d47 11378 default:
fd85a6a1 11379 result = NULL;
5e2b0d47
NC
11380 break;
11381 }
11382
11383 if (result)
11384 return result;
11385
11386 snprintf (buff, sizeof buff, _("<other>: %x"), other);
11387 return buff;
11388}
11389
d1133906 11390static const char *
dda8d76d 11391get_symbol_index_type (Filedata * filedata, unsigned int type)
252b5132 11392{
b34976b6 11393 static char buff[32];
5cf1065c 11394
252b5132
RH
11395 switch (type)
11396 {
b34976b6
AM
11397 case SHN_UNDEF: return "UND";
11398 case SHN_ABS: return "ABS";
11399 case SHN_COMMON: return "COM";
252b5132 11400 default:
9ce701e2 11401 if (type == SHN_IA_64_ANSI_COMMON
dda8d76d
NC
11402 && filedata->file_header.e_machine == EM_IA_64
11403 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
9ce701e2 11404 return "ANSI_COM";
dda8d76d
NC
11405 else if ((filedata->file_header.e_machine == EM_X86_64
11406 || filedata->file_header.e_machine == EM_L1OM
11407 || filedata->file_header.e_machine == EM_K1OM)
3b22753a
L
11408 && type == SHN_X86_64_LCOMMON)
11409 return "LARGE_COM";
ac145307 11410 else if ((type == SHN_MIPS_SCOMMON
dda8d76d 11411 && filedata->file_header.e_machine == EM_MIPS)
ac145307 11412 || (type == SHN_TIC6X_SCOMMON
dda8d76d 11413 && filedata->file_header.e_machine == EM_TI_C6000))
172553c7
TS
11414 return "SCOM";
11415 else if (type == SHN_MIPS_SUNDEFINED
dda8d76d 11416 && filedata->file_header.e_machine == EM_MIPS)
172553c7 11417 return "SUND";
9ce701e2 11418 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4fbb74a6 11419 sprintf (buff, "PRC[0x%04x]", type & 0xffff);
252b5132 11420 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4fbb74a6
AM
11421 sprintf (buff, "OS [0x%04x]", type & 0xffff);
11422 else if (type >= SHN_LORESERVE)
11423 sprintf (buff, "RSV[0x%04x]", type & 0xffff);
dda8d76d 11424 else if (type >= filedata->file_header.e_shnum)
e0a31db1 11425 sprintf (buff, _("bad section index[%3d]"), type);
252b5132 11426 else
232e7cb8 11427 sprintf (buff, "%3d", type);
5cf1065c 11428 break;
252b5132 11429 }
5cf1065c
NC
11430
11431 return buff;
252b5132
RH
11432}
11433
66543521 11434static bfd_vma *
dda8d76d 11435get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size)
252b5132 11436{
2cf0635d
NC
11437 unsigned char * e_data;
11438 bfd_vma * i_data;
252b5132 11439
57028622
NC
11440 /* If the size_t type is smaller than the bfd_size_type, eg because
11441 you are building a 32-bit tool on a 64-bit host, then make sure
11442 that when (number) is cast to (size_t) no information is lost. */
11443 if (sizeof (size_t) < sizeof (bfd_size_type)
11444 && (bfd_size_type) ((size_t) number) != number)
11445 {
66cfc0fd
AM
11446 error (_("Size truncation prevents reading %s elements of size %u\n"),
11447 bfd_vmatoa ("u", number), ent_size);
57028622
NC
11448 return NULL;
11449 }
948f632f 11450
3102e897
NC
11451 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
11452 attempting to allocate memory when the read is bound to fail. */
dda8d76d 11453 if (ent_size * number > filedata->file_size)
3102e897 11454 {
66cfc0fd
AM
11455 error (_("Invalid number of dynamic entries: %s\n"),
11456 bfd_vmatoa ("u", number));
3102e897
NC
11457 return NULL;
11458 }
11459
57028622 11460 e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
252b5132
RH
11461 if (e_data == NULL)
11462 {
66cfc0fd
AM
11463 error (_("Out of memory reading %s dynamic entries\n"),
11464 bfd_vmatoa ("u", number));
252b5132
RH
11465 return NULL;
11466 }
11467
dda8d76d 11468 if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number)
252b5132 11469 {
66cfc0fd
AM
11470 error (_("Unable to read in %s bytes of dynamic data\n"),
11471 bfd_vmatoa ("u", number * ent_size));
3102e897 11472 free (e_data);
252b5132
RH
11473 return NULL;
11474 }
11475
57028622 11476 i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
252b5132
RH
11477 if (i_data == NULL)
11478 {
66cfc0fd
AM
11479 error (_("Out of memory allocating space for %s dynamic entries\n"),
11480 bfd_vmatoa ("u", number));
252b5132
RH
11481 free (e_data);
11482 return NULL;
11483 }
11484
11485 while (number--)
66543521 11486 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
252b5132
RH
11487
11488 free (e_data);
11489
11490 return i_data;
11491}
11492
6bd1a22c 11493static void
dda8d76d 11494print_dynamic_symbol (Filedata * filedata, bfd_vma si, unsigned long hn)
6bd1a22c 11495{
2cf0635d 11496 Elf_Internal_Sym * psym;
6bd1a22c
L
11497 int n;
11498
6bd1a22c
L
11499 n = print_vma (si, DEC_5);
11500 if (n < 5)
0b4362b0 11501 fputs (&" "[n], stdout);
6bd1a22c 11502 printf (" %3lu: ", hn);
e0a31db1
NC
11503
11504 if (dynamic_symbols == NULL || si >= num_dynamic_syms)
11505 {
3102e897
NC
11506 printf (_("<No info available for dynamic symbol number %lu>\n"),
11507 (unsigned long) si);
e0a31db1
NC
11508 return;
11509 }
11510
11511 psym = dynamic_symbols + si;
6bd1a22c
L
11512 print_vma (psym->st_value, LONG_HEX);
11513 putchar (' ');
11514 print_vma (psym->st_size, DEC_5);
11515
dda8d76d
NC
11516 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
11517 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
fd85a6a1 11518
dda8d76d 11519 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
11520 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
11521 else
11522 {
11523 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
11524
11525 printf (" %-7s", get_symbol_visibility (vis));
11526 /* Check to see if any other bits in the st_other field are set.
11527 Note - displaying this information disrupts the layout of the
11528 table being generated, but for the moment this case is very
11529 rare. */
11530 if (psym->st_other ^ vis)
dda8d76d 11531 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
fd85a6a1
NC
11532 }
11533
dda8d76d 11534 printf (" %3.3s ", get_symbol_index_type (filedata, psym->st_shndx));
6bd1a22c
L
11535 if (VALID_DYNAMIC_NAME (psym->st_name))
11536 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
11537 else
2b692964 11538 printf (_(" <corrupt: %14ld>"), psym->st_name);
6bd1a22c
L
11539 putchar ('\n');
11540}
11541
bb4d2ac2 11542static const char *
dda8d76d 11543get_symbol_version_string (Filedata * filedata,
1449284b
NC
11544 bfd_boolean is_dynsym,
11545 const char * strtab,
11546 unsigned long int strtab_size,
11547 unsigned int si,
11548 Elf_Internal_Sym * psym,
11549 enum versioned_symbol_info * sym_info,
11550 unsigned short * vna_other)
bb4d2ac2 11551{
ab273396
AM
11552 unsigned char data[2];
11553 unsigned short vers_data;
11554 unsigned long offset;
7a815dd5 11555 unsigned short max_vd_ndx;
bb4d2ac2 11556
ab273396
AM
11557 if (!is_dynsym
11558 || version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
11559 return NULL;
bb4d2ac2 11560
dda8d76d 11561 offset = offset_from_vma (filedata, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
ab273396 11562 sizeof data + si * sizeof (vers_data));
bb4d2ac2 11563
dda8d76d 11564 if (get_data (&data, filedata, offset + si * sizeof (vers_data),
ab273396
AM
11565 sizeof (data), 1, _("version data")) == NULL)
11566 return NULL;
11567
11568 vers_data = byte_get (data, 2);
bb4d2ac2 11569
1f6f5dba 11570 if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0)
ab273396 11571 return NULL;
bb4d2ac2 11572
0b8b7609 11573 *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public;
7a815dd5
L
11574 max_vd_ndx = 0;
11575
ab273396
AM
11576 /* Usually we'd only see verdef for defined symbols, and verneed for
11577 undefined symbols. However, symbols defined by the linker in
11578 .dynbss for variables copied from a shared library in order to
11579 avoid text relocations are defined yet have verneed. We could
11580 use a heuristic to detect the special case, for example, check
11581 for verneed first on symbols defined in SHT_NOBITS sections, but
11582 it is simpler and more reliable to just look for both verdef and
11583 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
bb4d2ac2 11584
ab273396
AM
11585 if (psym->st_shndx != SHN_UNDEF
11586 && vers_data != 0x8001
11587 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
11588 {
11589 Elf_Internal_Verdef ivd;
11590 Elf_Internal_Verdaux ivda;
11591 Elf_External_Verdaux evda;
11592 unsigned long off;
bb4d2ac2 11593
dda8d76d 11594 off = offset_from_vma (filedata,
ab273396
AM
11595 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
11596 sizeof (Elf_External_Verdef));
11597
11598 do
bb4d2ac2 11599 {
ab273396
AM
11600 Elf_External_Verdef evd;
11601
dda8d76d 11602 if (get_data (&evd, filedata, off, sizeof (evd), 1,
ab273396
AM
11603 _("version def")) == NULL)
11604 {
11605 ivd.vd_ndx = 0;
11606 ivd.vd_aux = 0;
11607 ivd.vd_next = 0;
1f6f5dba 11608 ivd.vd_flags = 0;
ab273396
AM
11609 }
11610 else
bb4d2ac2 11611 {
ab273396
AM
11612 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
11613 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11614 ivd.vd_next = BYTE_GET (evd.vd_next);
1f6f5dba 11615 ivd.vd_flags = BYTE_GET (evd.vd_flags);
ab273396 11616 }
bb4d2ac2 11617
7a815dd5
L
11618 if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx)
11619 max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION;
11620
ab273396
AM
11621 off += ivd.vd_next;
11622 }
11623 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
bb4d2ac2 11624
ab273396
AM
11625 if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
11626 {
9abca702 11627 if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE)
1f6f5dba
L
11628 return NULL;
11629
ab273396
AM
11630 off -= ivd.vd_next;
11631 off += ivd.vd_aux;
bb4d2ac2 11632
dda8d76d 11633 if (get_data (&evda, filedata, off, sizeof (evda), 1,
ab273396
AM
11634 _("version def aux")) != NULL)
11635 {
11636 ivda.vda_name = BYTE_GET (evda.vda_name);
bb4d2ac2 11637
ab273396 11638 if (psym->st_name != ivda.vda_name)
0b8b7609
AM
11639 return (ivda.vda_name < strtab_size
11640 ? strtab + ivda.vda_name : _("<corrupt>"));
ab273396
AM
11641 }
11642 }
11643 }
bb4d2ac2 11644
ab273396
AM
11645 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
11646 {
11647 Elf_External_Verneed evn;
11648 Elf_Internal_Verneed ivn;
11649 Elf_Internal_Vernaux ivna;
bb4d2ac2 11650
dda8d76d 11651 offset = offset_from_vma (filedata,
ab273396
AM
11652 version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
11653 sizeof evn);
11654 do
11655 {
11656 unsigned long vna_off;
bb4d2ac2 11657
dda8d76d 11658 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
ab273396
AM
11659 _("version need")) == NULL)
11660 {
11661 ivna.vna_next = 0;
11662 ivna.vna_other = 0;
11663 ivna.vna_name = 0;
11664 break;
11665 }
bb4d2ac2 11666
ab273396
AM
11667 ivn.vn_aux = BYTE_GET (evn.vn_aux);
11668 ivn.vn_next = BYTE_GET (evn.vn_next);
bb4d2ac2 11669
ab273396 11670 vna_off = offset + ivn.vn_aux;
bb4d2ac2 11671
ab273396
AM
11672 do
11673 {
11674 Elf_External_Vernaux evna;
bb4d2ac2 11675
dda8d76d 11676 if (get_data (&evna, filedata, vna_off, sizeof (evna), 1,
ab273396 11677 _("version need aux (3)")) == NULL)
bb4d2ac2 11678 {
ab273396
AM
11679 ivna.vna_next = 0;
11680 ivna.vna_other = 0;
11681 ivna.vna_name = 0;
bb4d2ac2 11682 }
bb4d2ac2 11683 else
bb4d2ac2 11684 {
ab273396
AM
11685 ivna.vna_other = BYTE_GET (evna.vna_other);
11686 ivna.vna_next = BYTE_GET (evna.vna_next);
11687 ivna.vna_name = BYTE_GET (evna.vna_name);
11688 }
bb4d2ac2 11689
ab273396
AM
11690 vna_off += ivna.vna_next;
11691 }
11692 while (ivna.vna_other != vers_data && ivna.vna_next != 0);
bb4d2ac2 11693
ab273396
AM
11694 if (ivna.vna_other == vers_data)
11695 break;
bb4d2ac2 11696
ab273396
AM
11697 offset += ivn.vn_next;
11698 }
11699 while (ivn.vn_next != 0);
bb4d2ac2 11700
ab273396
AM
11701 if (ivna.vna_other == vers_data)
11702 {
11703 *sym_info = symbol_undefined;
11704 *vna_other = ivna.vna_other;
11705 return (ivna.vna_name < strtab_size
11706 ? strtab + ivna.vna_name : _("<corrupt>"));
bb4d2ac2 11707 }
7a815dd5
L
11708 else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1)
11709 && (vers_data & VERSYM_VERSION) > max_vd_ndx)
11710 return _("<corrupt>");
bb4d2ac2 11711 }
ab273396 11712 return NULL;
bb4d2ac2
L
11713}
11714
e3c8793a 11715/* Dump the symbol table. */
32ec8896 11716static bfd_boolean
dda8d76d 11717process_symbol_table (Filedata * filedata)
252b5132 11718{
2cf0635d 11719 Elf_Internal_Shdr * section;
8b73c356
NC
11720 bfd_size_type nbuckets = 0;
11721 bfd_size_type nchains = 0;
2cf0635d
NC
11722 bfd_vma * buckets = NULL;
11723 bfd_vma * chains = NULL;
fdc90cb4 11724 bfd_vma ngnubuckets = 0;
2cf0635d
NC
11725 bfd_vma * gnubuckets = NULL;
11726 bfd_vma * gnuchains = NULL;
f16a9783 11727 bfd_vma * mipsxlat = NULL;
6bd1a22c 11728 bfd_vma gnusymidx = 0;
071436c6 11729 bfd_size_type ngnuchains = 0;
252b5132 11730
2c610e4b 11731 if (!do_syms && !do_dyn_syms && !do_histogram)
32ec8896 11732 return TRUE;
252b5132 11733
6bd1a22c
L
11734 if (dynamic_info[DT_HASH]
11735 && (do_histogram
2c610e4b
L
11736 || (do_using_dynamic
11737 && !do_dyn_syms
11738 && dynamic_strings != NULL)))
252b5132 11739 {
66543521
AM
11740 unsigned char nb[8];
11741 unsigned char nc[8];
8b73c356 11742 unsigned int hash_ent_size = 4;
66543521 11743
dda8d76d
NC
11744 if ((filedata->file_header.e_machine == EM_ALPHA
11745 || filedata->file_header.e_machine == EM_S390
11746 || filedata->file_header.e_machine == EM_S390_OLD)
11747 && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64)
66543521
AM
11748 hash_ent_size = 8;
11749
dda8d76d 11750 if (fseek (filedata->handle,
fb52b2f4 11751 (archive_file_offset
dda8d76d 11752 + offset_from_vma (filedata, dynamic_info[DT_HASH],
fb52b2f4 11753 sizeof nb + sizeof nc)),
d93f0186 11754 SEEK_SET))
252b5132 11755 {
591a748a 11756 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11757 goto no_hash;
252b5132
RH
11758 }
11759
dda8d76d 11760 if (fread (nb, hash_ent_size, 1, filedata->handle) != 1)
252b5132
RH
11761 {
11762 error (_("Failed to read in number of buckets\n"));
d3a44ec6 11763 goto no_hash;
252b5132
RH
11764 }
11765
dda8d76d 11766 if (fread (nc, hash_ent_size, 1, filedata->handle) != 1)
252b5132
RH
11767 {
11768 error (_("Failed to read in number of chains\n"));
d3a44ec6 11769 goto no_hash;
252b5132
RH
11770 }
11771
66543521
AM
11772 nbuckets = byte_get (nb, hash_ent_size);
11773 nchains = byte_get (nc, hash_ent_size);
252b5132 11774
dda8d76d
NC
11775 buckets = get_dynamic_data (filedata, nbuckets, hash_ent_size);
11776 chains = get_dynamic_data (filedata, nchains, hash_ent_size);
252b5132 11777
d3a44ec6 11778 no_hash:
252b5132 11779 if (buckets == NULL || chains == NULL)
d3a44ec6
JJ
11780 {
11781 if (do_using_dynamic)
32ec8896 11782 return FALSE;
d3a44ec6
JJ
11783 free (buckets);
11784 free (chains);
11785 buckets = NULL;
11786 chains = NULL;
11787 nbuckets = 0;
11788 nchains = 0;
11789 }
252b5132
RH
11790 }
11791
6bd1a22c
L
11792 if (dynamic_info_DT_GNU_HASH
11793 && (do_histogram
2c610e4b
L
11794 || (do_using_dynamic
11795 && !do_dyn_syms
11796 && dynamic_strings != NULL)))
252b5132 11797 {
6bd1a22c
L
11798 unsigned char nb[16];
11799 bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
11800 bfd_vma buckets_vma;
11801
dda8d76d 11802 if (fseek (filedata->handle,
6bd1a22c 11803 (archive_file_offset
dda8d76d 11804 + offset_from_vma (filedata, dynamic_info_DT_GNU_HASH,
6bd1a22c
L
11805 sizeof nb)),
11806 SEEK_SET))
11807 {
11808 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11809 goto no_gnu_hash;
6bd1a22c 11810 }
252b5132 11811
dda8d76d 11812 if (fread (nb, 16, 1, filedata->handle) != 1)
6bd1a22c
L
11813 {
11814 error (_("Failed to read in number of buckets\n"));
d3a44ec6 11815 goto no_gnu_hash;
6bd1a22c
L
11816 }
11817
11818 ngnubuckets = byte_get (nb, 4);
11819 gnusymidx = byte_get (nb + 4, 4);
11820 bitmaskwords = byte_get (nb + 8, 4);
11821 buckets_vma = dynamic_info_DT_GNU_HASH + 16;
f7a99963 11822 if (is_32bit_elf)
6bd1a22c 11823 buckets_vma += bitmaskwords * 4;
f7a99963 11824 else
6bd1a22c 11825 buckets_vma += bitmaskwords * 8;
252b5132 11826
dda8d76d 11827 if (fseek (filedata->handle,
6bd1a22c 11828 (archive_file_offset
dda8d76d 11829 + offset_from_vma (filedata, buckets_vma, 4)),
6bd1a22c 11830 SEEK_SET))
252b5132 11831 {
6bd1a22c 11832 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11833 goto no_gnu_hash;
6bd1a22c
L
11834 }
11835
dda8d76d 11836 gnubuckets = get_dynamic_data (filedata, ngnubuckets, 4);
252b5132 11837
6bd1a22c 11838 if (gnubuckets == NULL)
d3a44ec6 11839 goto no_gnu_hash;
6bd1a22c
L
11840
11841 for (i = 0; i < ngnubuckets; i++)
11842 if (gnubuckets[i] != 0)
11843 {
11844 if (gnubuckets[i] < gnusymidx)
32ec8896 11845 return FALSE;
6bd1a22c
L
11846
11847 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
11848 maxchain = gnubuckets[i];
11849 }
11850
11851 if (maxchain == 0xffffffff)
d3a44ec6 11852 goto no_gnu_hash;
6bd1a22c
L
11853
11854 maxchain -= gnusymidx;
11855
dda8d76d 11856 if (fseek (filedata->handle,
6bd1a22c 11857 (archive_file_offset
dda8d76d 11858 + offset_from_vma (filedata, buckets_vma
6bd1a22c
L
11859 + 4 * (ngnubuckets + maxchain), 4)),
11860 SEEK_SET))
11861 {
11862 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11863 goto no_gnu_hash;
6bd1a22c
L
11864 }
11865
11866 do
11867 {
dda8d76d 11868 if (fread (nb, 4, 1, filedata->handle) != 1)
252b5132 11869 {
6bd1a22c 11870 error (_("Failed to determine last chain length\n"));
d3a44ec6 11871 goto no_gnu_hash;
6bd1a22c 11872 }
252b5132 11873
6bd1a22c 11874 if (maxchain + 1 == 0)
d3a44ec6 11875 goto no_gnu_hash;
252b5132 11876
6bd1a22c
L
11877 ++maxchain;
11878 }
11879 while ((byte_get (nb, 4) & 1) == 0);
76da6bbe 11880
dda8d76d 11881 if (fseek (filedata->handle,
6bd1a22c 11882 (archive_file_offset
dda8d76d 11883 + offset_from_vma (filedata, buckets_vma + 4 * ngnubuckets, 4)),
6bd1a22c
L
11884 SEEK_SET))
11885 {
11886 error (_("Unable to seek to start of dynamic information\n"));
d3a44ec6 11887 goto no_gnu_hash;
6bd1a22c
L
11888 }
11889
dda8d76d 11890 gnuchains = get_dynamic_data (filedata, maxchain, 4);
071436c6 11891 ngnuchains = maxchain;
6bd1a22c 11892
f16a9783
MS
11893 if (gnuchains == NULL)
11894 goto no_gnu_hash;
11895
11896 if (dynamic_info_DT_MIPS_XHASH)
11897 {
11898 if (fseek (filedata->handle,
11899 (archive_file_offset
11900 + offset_from_vma (filedata, (buckets_vma
11901 + 4 * (ngnubuckets
11902 + maxchain)), 4)),
11903 SEEK_SET))
11904 {
11905 error (_("Unable to seek to start of dynamic information\n"));
11906 goto no_gnu_hash;
11907 }
11908
11909 mipsxlat = get_dynamic_data (filedata, maxchain, 4);
11910 }
11911
d3a44ec6 11912 no_gnu_hash:
f16a9783
MS
11913 if (dynamic_info_DT_MIPS_XHASH && mipsxlat == NULL)
11914 {
11915 free (gnuchains);
11916 gnuchains = NULL;
11917 }
6bd1a22c 11918 if (gnuchains == NULL)
d3a44ec6
JJ
11919 {
11920 free (gnubuckets);
d3a44ec6
JJ
11921 gnubuckets = NULL;
11922 ngnubuckets = 0;
f64fddf1 11923 if (do_using_dynamic)
32ec8896 11924 return FALSE;
d3a44ec6 11925 }
6bd1a22c
L
11926 }
11927
11928 if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
11929 && do_syms
11930 && do_using_dynamic
3102e897
NC
11931 && dynamic_strings != NULL
11932 && dynamic_symbols != NULL)
6bd1a22c
L
11933 {
11934 unsigned long hn;
11935
11936 if (dynamic_info[DT_HASH])
11937 {
11938 bfd_vma si;
6bd6a03d 11939 char *visited;
6bd1a22c
L
11940
11941 printf (_("\nSymbol table for image:\n"));
11942 if (is_32bit_elf)
11943 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11944 else
11945 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11946
6bd6a03d
AM
11947 visited = xcmalloc (nchains, 1);
11948 memset (visited, 0, nchains);
6bd1a22c
L
11949 for (hn = 0; hn < nbuckets; hn++)
11950 {
6bd6a03d
AM
11951 for (si = buckets[hn]; si > 0; si = chains[si])
11952 {
dda8d76d 11953 print_dynamic_symbol (filedata, si, hn);
6bd6a03d
AM
11954 if (si >= nchains || visited[si])
11955 {
11956 error (_("histogram chain is corrupt\n"));
11957 break;
11958 }
11959 visited[si] = 1;
11960 }
252b5132 11961 }
6bd6a03d 11962 free (visited);
252b5132 11963 }
6bd1a22c
L
11964
11965 if (dynamic_info_DT_GNU_HASH)
11966 {
f16a9783
MS
11967 printf (_("\nSymbol table of `%s' for image:\n"),
11968 GNU_HASH_SECTION_NAME);
6bd1a22c
L
11969 if (is_32bit_elf)
11970 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11971 else
11972 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11973
11974 for (hn = 0; hn < ngnubuckets; ++hn)
11975 if (gnubuckets[hn] != 0)
11976 {
11977 bfd_vma si = gnubuckets[hn];
11978 bfd_vma off = si - gnusymidx;
11979
11980 do
11981 {
f16a9783
MS
11982 if (dynamic_info_DT_MIPS_XHASH)
11983 print_dynamic_symbol (filedata, mipsxlat[off], hn);
11984 else
11985 print_dynamic_symbol (filedata, si, hn);
6bd1a22c
L
11986 si++;
11987 }
071436c6 11988 while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
6bd1a22c
L
11989 }
11990 }
252b5132 11991 }
8b73c356 11992 else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
dda8d76d 11993 && filedata->section_headers != NULL)
252b5132 11994 {
b34976b6 11995 unsigned int i;
252b5132 11996
dda8d76d
NC
11997 for (i = 0, section = filedata->section_headers;
11998 i < filedata->file_header.e_shnum;
252b5132
RH
11999 i++, section++)
12000 {
b34976b6 12001 unsigned int si;
2cf0635d 12002 char * strtab = NULL;
c256ffe7 12003 unsigned long int strtab_size = 0;
2cf0635d
NC
12004 Elf_Internal_Sym * symtab;
12005 Elf_Internal_Sym * psym;
ba5cdace 12006 unsigned long num_syms;
252b5132 12007
2c610e4b
L
12008 if ((section->sh_type != SHT_SYMTAB
12009 && section->sh_type != SHT_DYNSYM)
12010 || (!do_syms
12011 && section->sh_type == SHT_SYMTAB))
252b5132
RH
12012 continue;
12013
dd24e3da
NC
12014 if (section->sh_entsize == 0)
12015 {
12016 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
dda8d76d 12017 printable_section_name (filedata, section));
dd24e3da
NC
12018 continue;
12019 }
12020
d3a49aa8
AM
12021 num_syms = section->sh_size / section->sh_entsize;
12022 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
12023 "\nSymbol table '%s' contains %lu entries:\n",
12024 num_syms),
dda8d76d 12025 printable_section_name (filedata, section),
d3a49aa8 12026 num_syms);
dd24e3da 12027
f7a99963 12028 if (is_32bit_elf)
ca47b30c 12029 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
f7a99963 12030 else
ca47b30c 12031 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
252b5132 12032
dda8d76d 12033 symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms);
252b5132
RH
12034 if (symtab == NULL)
12035 continue;
12036
dda8d76d 12037 if (section->sh_link == filedata->file_header.e_shstrndx)
c256ffe7 12038 {
dda8d76d
NC
12039 strtab = filedata->string_table;
12040 strtab_size = filedata->string_table_length;
c256ffe7 12041 }
dda8d76d 12042 else if (section->sh_link < filedata->file_header.e_shnum)
252b5132 12043 {
2cf0635d 12044 Elf_Internal_Shdr * string_sec;
252b5132 12045
dda8d76d 12046 string_sec = filedata->section_headers + section->sh_link;
252b5132 12047
dda8d76d 12048 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset,
3f5e193b
NC
12049 1, string_sec->sh_size,
12050 _("string table"));
c256ffe7 12051 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
252b5132
RH
12052 }
12053
ba5cdace 12054 for (si = 0, psym = symtab; si < num_syms; si++, psym++)
252b5132 12055 {
bb4d2ac2
L
12056 const char *version_string;
12057 enum versioned_symbol_info sym_info;
12058 unsigned short vna_other;
12059
5e220199 12060 printf ("%6d: ", si);
f7a99963
NC
12061 print_vma (psym->st_value, LONG_HEX);
12062 putchar (' ');
12063 print_vma (psym->st_size, DEC_5);
dda8d76d
NC
12064 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
12065 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
12066 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
12067 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
12068 else
12069 {
12070 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
12071
12072 printf (" %-7s", get_symbol_visibility (vis));
12073 /* Check to see if any other bits in the st_other field are set.
12074 Note - displaying this information disrupts the layout of the
12075 table being generated, but for the moment this case is very rare. */
12076 if (psym->st_other ^ vis)
dda8d76d 12077 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
fd85a6a1 12078 }
dda8d76d 12079 printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
c256ffe7 12080 print_symbol (25, psym->st_name < strtab_size
2b692964 12081 ? strtab + psym->st_name : _("<corrupt>"));
252b5132 12082
bb4d2ac2 12083 version_string
dda8d76d 12084 = get_symbol_version_string (filedata,
bb4d2ac2
L
12085 section->sh_type == SHT_DYNSYM,
12086 strtab, strtab_size, si,
12087 psym, &sym_info, &vna_other);
12088 if (version_string)
252b5132 12089 {
bb4d2ac2
L
12090 if (sym_info == symbol_undefined)
12091 printf ("@%s (%d)", version_string, vna_other);
12092 else
12093 printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
12094 version_string);
252b5132
RH
12095 }
12096
12097 putchar ('\n');
52c3c391
NC
12098
12099 if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
dd905818
NC
12100 && si >= section->sh_info
12101 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
dda8d76d 12102 && filedata->file_header.e_machine != EM_MIPS
dd905818
NC
12103 /* Solaris binaries have been found to violate this requirement as
12104 well. Not sure if this is a bug or an ABI requirement. */
dda8d76d 12105 && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS)
52c3c391 12106 warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"),
dda8d76d 12107 si, printable_section_name (filedata, section), section->sh_info);
252b5132
RH
12108 }
12109
12110 free (symtab);
dda8d76d 12111 if (strtab != filedata->string_table)
252b5132
RH
12112 free (strtab);
12113 }
12114 }
12115 else if (do_syms)
12116 printf
12117 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
12118
12119 if (do_histogram && buckets != NULL)
12120 {
2cf0635d
NC
12121 unsigned long * lengths;
12122 unsigned long * counts;
66543521
AM
12123 unsigned long hn;
12124 bfd_vma si;
12125 unsigned long maxlength = 0;
12126 unsigned long nzero_counts = 0;
12127 unsigned long nsyms = 0;
6bd6a03d 12128 char *visited;
252b5132 12129
d3a49aa8
AM
12130 printf (ngettext ("\nHistogram for bucket list length "
12131 "(total of %lu bucket):\n",
12132 "\nHistogram for bucket list length "
12133 "(total of %lu buckets):\n",
12134 (unsigned long) nbuckets),
66543521 12135 (unsigned long) nbuckets);
252b5132 12136
3f5e193b 12137 lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
252b5132
RH
12138 if (lengths == NULL)
12139 {
8b73c356 12140 error (_("Out of memory allocating space for histogram buckets\n"));
32ec8896 12141 return FALSE;
252b5132 12142 }
6bd6a03d
AM
12143 visited = xcmalloc (nchains, 1);
12144 memset (visited, 0, nchains);
8b73c356
NC
12145
12146 printf (_(" Length Number %% of total Coverage\n"));
252b5132
RH
12147 for (hn = 0; hn < nbuckets; ++hn)
12148 {
6bd6a03d 12149 for (si = buckets[hn]; si > 0; si = chains[si])
252b5132 12150 {
b34976b6 12151 ++nsyms;
252b5132 12152 if (maxlength < ++lengths[hn])
b34976b6 12153 ++maxlength;
6bd6a03d
AM
12154 if (si >= nchains || visited[si])
12155 {
12156 error (_("histogram chain is corrupt\n"));
12157 break;
12158 }
12159 visited[si] = 1;
252b5132
RH
12160 }
12161 }
6bd6a03d 12162 free (visited);
252b5132 12163
3f5e193b 12164 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
252b5132
RH
12165 if (counts == NULL)
12166 {
b2e951ec 12167 free (lengths);
8b73c356 12168 error (_("Out of memory allocating space for histogram counts\n"));
32ec8896 12169 return FALSE;
252b5132
RH
12170 }
12171
12172 for (hn = 0; hn < nbuckets; ++hn)
b34976b6 12173 ++counts[lengths[hn]];
252b5132 12174
103f02d3 12175 if (nbuckets > 0)
252b5132 12176 {
66543521
AM
12177 unsigned long i;
12178 printf (" 0 %-10lu (%5.1f%%)\n",
103f02d3 12179 counts[0], (counts[0] * 100.0) / nbuckets);
66543521 12180 for (i = 1; i <= maxlength; ++i)
103f02d3 12181 {
66543521
AM
12182 nzero_counts += counts[i] * i;
12183 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12184 i, counts[i], (counts[i] * 100.0) / nbuckets,
103f02d3
UD
12185 (nzero_counts * 100.0) / nsyms);
12186 }
252b5132
RH
12187 }
12188
12189 free (counts);
12190 free (lengths);
12191 }
12192
12193 if (buckets != NULL)
12194 {
12195 free (buckets);
12196 free (chains);
12197 }
12198
d3a44ec6 12199 if (do_histogram && gnubuckets != NULL)
fdc90cb4 12200 {
2cf0635d
NC
12201 unsigned long * lengths;
12202 unsigned long * counts;
fdc90cb4
JJ
12203 unsigned long hn;
12204 unsigned long maxlength = 0;
12205 unsigned long nzero_counts = 0;
12206 unsigned long nsyms = 0;
fdc90cb4 12207
f16a9783 12208 printf (ngettext ("\nHistogram for `%s' bucket list length "
d3a49aa8 12209 "(total of %lu bucket):\n",
f16a9783 12210 "\nHistogram for `%s' bucket list length "
d3a49aa8
AM
12211 "(total of %lu buckets):\n",
12212 (unsigned long) ngnubuckets),
f16a9783 12213 GNU_HASH_SECTION_NAME,
8b73c356
NC
12214 (unsigned long) ngnubuckets);
12215
3f5e193b 12216 lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
fdc90cb4
JJ
12217 if (lengths == NULL)
12218 {
8b73c356 12219 error (_("Out of memory allocating space for gnu histogram buckets\n"));
32ec8896 12220 return FALSE;
fdc90cb4
JJ
12221 }
12222
fdc90cb4
JJ
12223 printf (_(" Length Number %% of total Coverage\n"));
12224
12225 for (hn = 0; hn < ngnubuckets; ++hn)
12226 if (gnubuckets[hn] != 0)
12227 {
12228 bfd_vma off, length = 1;
12229
6bd1a22c 12230 for (off = gnubuckets[hn] - gnusymidx;
071436c6
NC
12231 /* PR 17531 file: 010-77222-0.004. */
12232 off < ngnuchains && (gnuchains[off] & 1) == 0;
12233 ++off)
fdc90cb4
JJ
12234 ++length;
12235 lengths[hn] = length;
12236 if (length > maxlength)
12237 maxlength = length;
12238 nsyms += length;
12239 }
12240
3f5e193b 12241 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
fdc90cb4
JJ
12242 if (counts == NULL)
12243 {
b2e951ec 12244 free (lengths);
8b73c356 12245 error (_("Out of memory allocating space for gnu histogram counts\n"));
32ec8896 12246 return FALSE;
fdc90cb4
JJ
12247 }
12248
12249 for (hn = 0; hn < ngnubuckets; ++hn)
12250 ++counts[lengths[hn]];
12251
12252 if (ngnubuckets > 0)
12253 {
12254 unsigned long j;
12255 printf (" 0 %-10lu (%5.1f%%)\n",
12256 counts[0], (counts[0] * 100.0) / ngnubuckets);
12257 for (j = 1; j <= maxlength; ++j)
12258 {
12259 nzero_counts += counts[j] * j;
12260 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12261 j, counts[j], (counts[j] * 100.0) / ngnubuckets,
12262 (nzero_counts * 100.0) / nsyms);
12263 }
12264 }
12265
12266 free (counts);
12267 free (lengths);
12268 free (gnubuckets);
12269 free (gnuchains);
f16a9783 12270 free (mipsxlat);
fdc90cb4
JJ
12271 }
12272
32ec8896 12273 return TRUE;
252b5132
RH
12274}
12275
32ec8896 12276static bfd_boolean
dda8d76d 12277process_syminfo (Filedata * filedata ATTRIBUTE_UNUSED)
252b5132 12278{
b4c96d0d 12279 unsigned int i;
252b5132
RH
12280
12281 if (dynamic_syminfo == NULL
12282 || !do_dynamic)
12283 /* No syminfo, this is ok. */
32ec8896 12284 return TRUE;
252b5132
RH
12285
12286 /* There better should be a dynamic symbol section. */
12287 if (dynamic_symbols == NULL || dynamic_strings == NULL)
32ec8896 12288 return FALSE;
252b5132
RH
12289
12290 if (dynamic_addr)
d3a49aa8
AM
12291 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
12292 "contains %d entry:\n",
12293 "\nDynamic info segment at offset 0x%lx "
12294 "contains %d entries:\n",
12295 dynamic_syminfo_nent),
252b5132
RH
12296 dynamic_syminfo_offset, dynamic_syminfo_nent);
12297
12298 printf (_(" Num: Name BoundTo Flags\n"));
12299 for (i = 0; i < dynamic_syminfo_nent; ++i)
12300 {
12301 unsigned short int flags = dynamic_syminfo[i].si_flags;
12302
31104126 12303 printf ("%4d: ", i);
4082ef84
NC
12304 if (i >= num_dynamic_syms)
12305 printf (_("<corrupt index>"));
12306 else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
d79b3d50
NC
12307 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
12308 else
2b692964 12309 printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
31104126 12310 putchar (' ');
252b5132
RH
12311
12312 switch (dynamic_syminfo[i].si_boundto)
12313 {
12314 case SYMINFO_BT_SELF:
12315 fputs ("SELF ", stdout);
12316 break;
12317 case SYMINFO_BT_PARENT:
12318 fputs ("PARENT ", stdout);
12319 break;
12320 default:
12321 if (dynamic_syminfo[i].si_boundto > 0
d79b3d50
NC
12322 && dynamic_syminfo[i].si_boundto < dynamic_nent
12323 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
31104126 12324 {
d79b3d50 12325 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
31104126
NC
12326 putchar (' ' );
12327 }
252b5132
RH
12328 else
12329 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
12330 break;
12331 }
12332
12333 if (flags & SYMINFO_FLG_DIRECT)
12334 printf (" DIRECT");
12335 if (flags & SYMINFO_FLG_PASSTHRU)
12336 printf (" PASSTHRU");
12337 if (flags & SYMINFO_FLG_COPY)
12338 printf (" COPY");
12339 if (flags & SYMINFO_FLG_LAZYLOAD)
12340 printf (" LAZYLOAD");
12341
12342 puts ("");
12343 }
12344
32ec8896 12345 return TRUE;
252b5132
RH
12346}
12347
75802ccb
CE
12348/* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
12349 is contained by the region START .. END. The types of ADDR, START
12350 and END should all be the same. Note both ADDR + NELEM and END
12351 point to just beyond the end of the regions that are being tested. */
12352#define IN_RANGE(START,END,ADDR,NELEM) \
12353 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
b32e566b 12354
cf13d699
NC
12355/* Check to see if the given reloc needs to be handled in a target specific
12356 manner. If so then process the reloc and return TRUE otherwise return
f84ce13b
NC
12357 FALSE.
12358
12359 If called with reloc == NULL, then this is a signal that reloc processing
12360 for the current section has finished, and any saved state should be
12361 discarded. */
09c11c86 12362
cf13d699 12363static bfd_boolean
dda8d76d
NC
12364target_specific_reloc_handling (Filedata * filedata,
12365 Elf_Internal_Rela * reloc,
12366 unsigned char * start,
12367 unsigned char * end,
12368 Elf_Internal_Sym * symtab,
12369 unsigned long num_syms)
252b5132 12370{
f84ce13b
NC
12371 unsigned int reloc_type = 0;
12372 unsigned long sym_index = 0;
12373
12374 if (reloc)
12375 {
dda8d76d 12376 reloc_type = get_reloc_type (filedata, reloc->r_info);
f84ce13b
NC
12377 sym_index = get_reloc_symindex (reloc->r_info);
12378 }
252b5132 12379
dda8d76d 12380 switch (filedata->file_header.e_machine)
252b5132 12381 {
13761a11
NC
12382 case EM_MSP430:
12383 case EM_MSP430_OLD:
12384 {
12385 static Elf_Internal_Sym * saved_sym = NULL;
12386
f84ce13b
NC
12387 if (reloc == NULL)
12388 {
12389 saved_sym = NULL;
12390 return TRUE;
12391 }
12392
13761a11
NC
12393 switch (reloc_type)
12394 {
12395 case 10: /* R_MSP430_SYM_DIFF */
dda8d76d 12396 if (uses_msp430x_relocs (filedata))
13761a11 12397 break;
1a0670f3 12398 /* Fall through. */
13761a11 12399 case 21: /* R_MSP430X_SYM_DIFF */
f84ce13b
NC
12400 /* PR 21139. */
12401 if (sym_index >= num_syms)
12402 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
12403 sym_index);
12404 else
12405 saved_sym = symtab + sym_index;
13761a11
NC
12406 return TRUE;
12407
12408 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
12409 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
12410 goto handle_sym_diff;
0b4362b0 12411
13761a11
NC
12412 case 5: /* R_MSP430_16_BYTE */
12413 case 9: /* R_MSP430_8 */
dda8d76d 12414 if (uses_msp430x_relocs (filedata))
13761a11
NC
12415 break;
12416 goto handle_sym_diff;
12417
12418 case 2: /* R_MSP430_ABS16 */
12419 case 15: /* R_MSP430X_ABS16 */
dda8d76d 12420 if (! uses_msp430x_relocs (filedata))
13761a11
NC
12421 break;
12422 goto handle_sym_diff;
0b4362b0 12423
13761a11
NC
12424 handle_sym_diff:
12425 if (saved_sym != NULL)
12426 {
03f7786e 12427 int reloc_size = reloc_type == 1 ? 4 : 2;
13761a11
NC
12428 bfd_vma value;
12429
f84ce13b
NC
12430 if (sym_index >= num_syms)
12431 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
12432 sym_index);
03f7786e 12433 else
f84ce13b
NC
12434 {
12435 value = reloc->r_addend + (symtab[sym_index].st_value
12436 - saved_sym->st_value);
12437
b32e566b 12438 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
f84ce13b 12439 byte_put (start + reloc->r_offset, value, reloc_size);
b32e566b
NC
12440 else
12441 /* PR 21137 */
12442 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
12443 (long) reloc->r_offset);
f84ce13b 12444 }
13761a11
NC
12445
12446 saved_sym = NULL;
12447 return TRUE;
12448 }
12449 break;
12450
12451 default:
12452 if (saved_sym != NULL)
071436c6 12453 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
13761a11
NC
12454 break;
12455 }
12456 break;
12457 }
12458
cf13d699
NC
12459 case EM_MN10300:
12460 case EM_CYGNUS_MN10300:
12461 {
12462 static Elf_Internal_Sym * saved_sym = NULL;
252b5132 12463
f84ce13b
NC
12464 if (reloc == NULL)
12465 {
12466 saved_sym = NULL;
12467 return TRUE;
12468 }
12469
cf13d699
NC
12470 switch (reloc_type)
12471 {
12472 case 34: /* R_MN10300_ALIGN */
12473 return TRUE;
12474 case 33: /* R_MN10300_SYM_DIFF */
f84ce13b
NC
12475 if (sym_index >= num_syms)
12476 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
12477 sym_index);
12478 else
12479 saved_sym = symtab + sym_index;
cf13d699 12480 return TRUE;
f84ce13b 12481
cf13d699
NC
12482 case 1: /* R_MN10300_32 */
12483 case 2: /* R_MN10300_16 */
12484 if (saved_sym != NULL)
12485 {
03f7786e 12486 int reloc_size = reloc_type == 1 ? 4 : 2;
cf13d699 12487 bfd_vma value;
252b5132 12488
f84ce13b
NC
12489 if (sym_index >= num_syms)
12490 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
12491 sym_index);
03f7786e 12492 else
f84ce13b
NC
12493 {
12494 value = reloc->r_addend + (symtab[sym_index].st_value
12495 - saved_sym->st_value);
12496
b32e566b 12497 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
f84ce13b 12498 byte_put (start + reloc->r_offset, value, reloc_size);
b32e566b
NC
12499 else
12500 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
12501 (long) reloc->r_offset);
f84ce13b 12502 }
252b5132 12503
cf13d699
NC
12504 saved_sym = NULL;
12505 return TRUE;
12506 }
12507 break;
12508 default:
12509 if (saved_sym != NULL)
071436c6 12510 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
cf13d699
NC
12511 break;
12512 }
12513 break;
12514 }
6ff71e76
NC
12515
12516 case EM_RL78:
12517 {
12518 static bfd_vma saved_sym1 = 0;
12519 static bfd_vma saved_sym2 = 0;
12520 static bfd_vma value;
12521
f84ce13b
NC
12522 if (reloc == NULL)
12523 {
12524 saved_sym1 = saved_sym2 = 0;
12525 return TRUE;
12526 }
12527
6ff71e76
NC
12528 switch (reloc_type)
12529 {
12530 case 0x80: /* R_RL78_SYM. */
12531 saved_sym1 = saved_sym2;
f84ce13b
NC
12532 if (sym_index >= num_syms)
12533 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
12534 sym_index);
12535 else
12536 {
12537 saved_sym2 = symtab[sym_index].st_value;
12538 saved_sym2 += reloc->r_addend;
12539 }
6ff71e76
NC
12540 return TRUE;
12541
12542 case 0x83: /* R_RL78_OPsub. */
12543 value = saved_sym1 - saved_sym2;
12544 saved_sym2 = saved_sym1 = 0;
12545 return TRUE;
12546 break;
12547
12548 case 0x41: /* R_RL78_ABS32. */
b32e566b 12549 if (IN_RANGE (start, end, start + reloc->r_offset, 4))
03f7786e 12550 byte_put (start + reloc->r_offset, value, 4);
b32e566b
NC
12551 else
12552 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12553 (long) reloc->r_offset);
6ff71e76
NC
12554 value = 0;
12555 return TRUE;
12556
12557 case 0x43: /* R_RL78_ABS16. */
b32e566b 12558 if (IN_RANGE (start, end, start + reloc->r_offset, 2))
03f7786e 12559 byte_put (start + reloc->r_offset, value, 2);
b32e566b
NC
12560 else
12561 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12562 (long) reloc->r_offset);
6ff71e76
NC
12563 value = 0;
12564 return TRUE;
12565
12566 default:
12567 break;
12568 }
12569 break;
12570 }
252b5132
RH
12571 }
12572
cf13d699 12573 return FALSE;
252b5132
RH
12574}
12575
aca88567
NC
12576/* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
12577 DWARF debug sections. This is a target specific test. Note - we do not
12578 go through the whole including-target-headers-multiple-times route, (as
12579 we have already done with <elf/h8.h>) because this would become very
12580 messy and even then this function would have to contain target specific
12581 information (the names of the relocs instead of their numeric values).
12582 FIXME: This is not the correct way to solve this problem. The proper way
12583 is to have target specific reloc sizing and typing functions created by
12584 the reloc-macros.h header, in the same way that it already creates the
12585 reloc naming functions. */
12586
12587static bfd_boolean
dda8d76d 12588is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 12589{
d347c9df 12590 /* Please keep this table alpha-sorted for ease of visual lookup. */
dda8d76d 12591 switch (filedata->file_header.e_machine)
aca88567 12592 {
41e92641 12593 case EM_386:
22abe556 12594 case EM_IAMCU:
41e92641 12595 return reloc_type == 1; /* R_386_32. */
aca88567
NC
12596 case EM_68K:
12597 return reloc_type == 1; /* R_68K_32. */
f954747f
AM
12598 case EM_860:
12599 return reloc_type == 1; /* R_860_32. */
12600 case EM_960:
12601 return reloc_type == 2; /* R_960_32. */
a06ea964 12602 case EM_AARCH64:
9282b95a
JW
12603 return (reloc_type == 258
12604 || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
aca4efc7
JM
12605 case EM_BPF:
12606 return reloc_type == 11; /* R_BPF_DATA_32 */
d347c9df
PS
12607 case EM_ADAPTEVA_EPIPHANY:
12608 return reloc_type == 3;
aca88567 12609 case EM_ALPHA:
137b6b5f 12610 return reloc_type == 1; /* R_ALPHA_REFLONG. */
41e92641
NC
12611 case EM_ARC:
12612 return reloc_type == 1; /* R_ARC_32. */
886a2506
NC
12613 case EM_ARC_COMPACT:
12614 case EM_ARC_COMPACT2:
12615 return reloc_type == 4; /* R_ARC_32. */
41e92641
NC
12616 case EM_ARM:
12617 return reloc_type == 2; /* R_ARM_ABS32 */
cb8f3167 12618 case EM_AVR_OLD:
aca88567
NC
12619 case EM_AVR:
12620 return reloc_type == 1;
12621 case EM_BLACKFIN:
12622 return reloc_type == 0x12; /* R_byte4_data. */
12623 case EM_CRIS:
12624 return reloc_type == 3; /* R_CRIS_32. */
12625 case EM_CR16:
12626 return reloc_type == 3; /* R_CR16_NUM32. */
12627 case EM_CRX:
12628 return reloc_type == 15; /* R_CRX_NUM32. */
b8891f8d
AJ
12629 case EM_CSKY:
12630 return reloc_type == 1; /* R_CKCORE_ADDR32. */
aca88567
NC
12631 case EM_CYGNUS_FRV:
12632 return reloc_type == 1;
41e92641
NC
12633 case EM_CYGNUS_D10V:
12634 case EM_D10V:
12635 return reloc_type == 6; /* R_D10V_32. */
aca88567
NC
12636 case EM_CYGNUS_D30V:
12637 case EM_D30V:
12638 return reloc_type == 12; /* R_D30V_32_NORMAL. */
41e92641
NC
12639 case EM_DLX:
12640 return reloc_type == 3; /* R_DLX_RELOC_32. */
aca88567
NC
12641 case EM_CYGNUS_FR30:
12642 case EM_FR30:
12643 return reloc_type == 3; /* R_FR30_32. */
3f8107ab
AM
12644 case EM_FT32:
12645 return reloc_type == 1; /* R_FT32_32. */
aca88567
NC
12646 case EM_H8S:
12647 case EM_H8_300:
12648 case EM_H8_300H:
12649 return reloc_type == 1; /* R_H8_DIR32. */
3730236a 12650 case EM_IA_64:
262cdac7
AM
12651 return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */
12652 || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */
12653 || reloc_type == 0x24 /* R_IA64_DIR32MSB. */
12654 || reloc_type == 0x25 /* R_IA64_DIR32LSB. */);
aca88567
NC
12655 case EM_IP2K_OLD:
12656 case EM_IP2K:
12657 return reloc_type == 2; /* R_IP2K_32. */
12658 case EM_IQ2000:
12659 return reloc_type == 2; /* R_IQ2000_32. */
84e94c90
NC
12660 case EM_LATTICEMICO32:
12661 return reloc_type == 3; /* R_LM32_32. */
ff7eeb89 12662 case EM_M32C_OLD:
aca88567
NC
12663 case EM_M32C:
12664 return reloc_type == 3; /* R_M32C_32. */
12665 case EM_M32R:
12666 return reloc_type == 34; /* R_M32R_32_RELA. */
adec12c1
AM
12667 case EM_68HC11:
12668 case EM_68HC12:
12669 return reloc_type == 6; /* R_M68HC11_32. */
7b4ae824 12670 case EM_S12Z:
2849d19f
JD
12671 return reloc_type == 7 || /* R_S12Z_EXT32 */
12672 reloc_type == 6; /* R_S12Z_CW32. */
aca88567
NC
12673 case EM_MCORE:
12674 return reloc_type == 1; /* R_MCORE_ADDR32. */
12675 case EM_CYGNUS_MEP:
12676 return reloc_type == 4; /* R_MEP_32. */
a3c62988
NC
12677 case EM_METAG:
12678 return reloc_type == 2; /* R_METAG_ADDR32. */
137b6b5f
AM
12679 case EM_MICROBLAZE:
12680 return reloc_type == 1; /* R_MICROBLAZE_32. */
aca88567
NC
12681 case EM_MIPS:
12682 return reloc_type == 2; /* R_MIPS_32. */
12683 case EM_MMIX:
12684 return reloc_type == 4; /* R_MMIX_32. */
12685 case EM_CYGNUS_MN10200:
12686 case EM_MN10200:
12687 return reloc_type == 1; /* R_MN10200_32. */
12688 case EM_CYGNUS_MN10300:
12689 case EM_MN10300:
12690 return reloc_type == 1; /* R_MN10300_32. */
5506d11a
AM
12691 case EM_MOXIE:
12692 return reloc_type == 1; /* R_MOXIE_32. */
aca88567
NC
12693 case EM_MSP430_OLD:
12694 case EM_MSP430:
13761a11 12695 return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
aca88567
NC
12696 case EM_MT:
12697 return reloc_type == 2; /* R_MT_32. */
35c08157
KLC
12698 case EM_NDS32:
12699 return reloc_type == 20; /* R_NDS32_RELA. */
3e0873ac 12700 case EM_ALTERA_NIOS2:
36591ba1 12701 return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
3e0873ac
NC
12702 case EM_NIOS32:
12703 return reloc_type == 1; /* R_NIOS_32. */
73589c9d
CS
12704 case EM_OR1K:
12705 return reloc_type == 1; /* R_OR1K_32. */
aca88567 12706 case EM_PARISC:
9abca702 12707 return (reloc_type == 1 /* R_PARISC_DIR32. */
0df8ad28 12708 || reloc_type == 2 /* R_PARISC_DIR21L. */
5fda8eca 12709 || reloc_type == 41); /* R_PARISC_SECREL32. */
aca88567
NC
12710 case EM_PJ:
12711 case EM_PJ_OLD:
12712 return reloc_type == 1; /* R_PJ_DATA_DIR32. */
12713 case EM_PPC64:
12714 return reloc_type == 1; /* R_PPC64_ADDR32. */
12715 case EM_PPC:
12716 return reloc_type == 1; /* R_PPC_ADDR32. */
2b100bb5
DD
12717 case EM_TI_PRU:
12718 return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
e23eba97
NC
12719 case EM_RISCV:
12720 return reloc_type == 1; /* R_RISCV_32. */
99c513f6
DD
12721 case EM_RL78:
12722 return reloc_type == 1; /* R_RL78_DIR32. */
c7927a3c
NC
12723 case EM_RX:
12724 return reloc_type == 1; /* R_RX_DIR32. */
f954747f
AM
12725 case EM_S370:
12726 return reloc_type == 1; /* R_I370_ADDR31. */
aca88567
NC
12727 case EM_S390_OLD:
12728 case EM_S390:
12729 return reloc_type == 4; /* R_S390_32. */
41e92641
NC
12730 case EM_SCORE:
12731 return reloc_type == 8; /* R_SCORE_ABS32. */
aca88567
NC
12732 case EM_SH:
12733 return reloc_type == 1; /* R_SH_DIR32. */
12734 case EM_SPARC32PLUS:
12735 case EM_SPARCV9:
12736 case EM_SPARC:
12737 return reloc_type == 3 /* R_SPARC_32. */
12738 || reloc_type == 23; /* R_SPARC_UA32. */
a7dd7d05
AM
12739 case EM_SPU:
12740 return reloc_type == 6; /* R_SPU_ADDR32 */
40b36596
JM
12741 case EM_TI_C6000:
12742 return reloc_type == 1; /* R_C6000_ABS32. */
aa137e4d
NC
12743 case EM_TILEGX:
12744 return reloc_type == 2; /* R_TILEGX_32. */
12745 case EM_TILEPRO:
12746 return reloc_type == 1; /* R_TILEPRO_32. */
aca88567
NC
12747 case EM_CYGNUS_V850:
12748 case EM_V850:
12749 return reloc_type == 6; /* R_V850_ABS32. */
708e2187
NC
12750 case EM_V800:
12751 return reloc_type == 0x33; /* R_V810_WORD. */
aca88567
NC
12752 case EM_VAX:
12753 return reloc_type == 1; /* R_VAX_32. */
619ed720
EB
12754 case EM_VISIUM:
12755 return reloc_type == 3; /* R_VISIUM_32. */
f96bd6c2
PC
12756 case EM_WEBASSEMBLY:
12757 return reloc_type == 1; /* R_WASM32_32. */
aca88567 12758 case EM_X86_64:
8a9036a4 12759 case EM_L1OM:
7a9068fe 12760 case EM_K1OM:
aca88567 12761 return reloc_type == 10; /* R_X86_64_32. */
c29aca4a
NC
12762 case EM_XC16X:
12763 case EM_C166:
12764 return reloc_type == 3; /* R_XC16C_ABS_32. */
f6c1a2d5
NC
12765 case EM_XGATE:
12766 return reloc_type == 4; /* R_XGATE_32. */
aca88567
NC
12767 case EM_XSTORMY16:
12768 return reloc_type == 1; /* R_XSTROMY16_32. */
12769 case EM_XTENSA_OLD:
12770 case EM_XTENSA:
12771 return reloc_type == 1; /* R_XTENSA_32. */
aca88567 12772 default:
bee0ee85
NC
12773 {
12774 static unsigned int prev_warn = 0;
12775
12776 /* Avoid repeating the same warning multiple times. */
dda8d76d 12777 if (prev_warn != filedata->file_header.e_machine)
bee0ee85 12778 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
dda8d76d
NC
12779 filedata->file_header.e_machine);
12780 prev_warn = filedata->file_header.e_machine;
bee0ee85
NC
12781 return FALSE;
12782 }
aca88567
NC
12783 }
12784}
12785
12786/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12787 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
12788
12789static bfd_boolean
dda8d76d 12790is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 12791{
dda8d76d 12792 switch (filedata->file_header.e_machine)
d347c9df 12793 /* Please keep this table alpha-sorted for ease of visual lookup. */
aca88567 12794 {
41e92641 12795 case EM_386:
22abe556 12796 case EM_IAMCU:
3e0873ac 12797 return reloc_type == 2; /* R_386_PC32. */
aca88567 12798 case EM_68K:
3e0873ac 12799 return reloc_type == 4; /* R_68K_PC32. */
a06ea964
NC
12800 case EM_AARCH64:
12801 return reloc_type == 261; /* R_AARCH64_PREL32 */
cfb8c092
NC
12802 case EM_ADAPTEVA_EPIPHANY:
12803 return reloc_type == 6;
aca88567
NC
12804 case EM_ALPHA:
12805 return reloc_type == 10; /* R_ALPHA_SREL32. */
726c18e1
CZ
12806 case EM_ARC_COMPACT:
12807 case EM_ARC_COMPACT2:
12808 return reloc_type == 49; /* R_ARC_32_PCREL. */
41e92641 12809 case EM_ARM:
3e0873ac 12810 return reloc_type == 3; /* R_ARM_REL32 */
d347c9df
PS
12811 case EM_AVR_OLD:
12812 case EM_AVR:
12813 return reloc_type == 36; /* R_AVR_32_PCREL. */
137b6b5f
AM
12814 case EM_MICROBLAZE:
12815 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
73589c9d
CS
12816 case EM_OR1K:
12817 return reloc_type == 9; /* R_OR1K_32_PCREL. */
aca88567 12818 case EM_PARISC:
85acf597 12819 return reloc_type == 9; /* R_PARISC_PCREL32. */
aca88567
NC
12820 case EM_PPC:
12821 return reloc_type == 26; /* R_PPC_REL32. */
12822 case EM_PPC64:
3e0873ac 12823 return reloc_type == 26; /* R_PPC64_REL32. */
25cbdcbb
AS
12824 case EM_RISCV:
12825 return reloc_type == 57; /* R_RISCV_32_PCREL. */
aca88567
NC
12826 case EM_S390_OLD:
12827 case EM_S390:
3e0873ac 12828 return reloc_type == 5; /* R_390_PC32. */
aca88567 12829 case EM_SH:
3e0873ac 12830 return reloc_type == 2; /* R_SH_REL32. */
aca88567
NC
12831 case EM_SPARC32PLUS:
12832 case EM_SPARCV9:
12833 case EM_SPARC:
3e0873ac 12834 return reloc_type == 6; /* R_SPARC_DISP32. */
a7dd7d05
AM
12835 case EM_SPU:
12836 return reloc_type == 13; /* R_SPU_REL32. */
aa137e4d
NC
12837 case EM_TILEGX:
12838 return reloc_type == 6; /* R_TILEGX_32_PCREL. */
12839 case EM_TILEPRO:
12840 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
619ed720
EB
12841 case EM_VISIUM:
12842 return reloc_type == 6; /* R_VISIUM_32_PCREL */
aca88567 12843 case EM_X86_64:
8a9036a4 12844 case EM_L1OM:
7a9068fe 12845 case EM_K1OM:
3e0873ac 12846 return reloc_type == 2; /* R_X86_64_PC32. */
2057d69d
CZ
12847 case EM_VAX:
12848 return reloc_type == 4; /* R_VAX_PCREL32. */
2fcb9706
BW
12849 case EM_XTENSA_OLD:
12850 case EM_XTENSA:
12851 return reloc_type == 14; /* R_XTENSA_32_PCREL. */
aca88567
NC
12852 default:
12853 /* Do not abort or issue an error message here. Not all targets use
12854 pc-relative 32-bit relocs in their DWARF debug information and we
12855 have already tested for target coverage in is_32bit_abs_reloc. A
cf13d699
NC
12856 more helpful warning message will be generated by apply_relocations
12857 anyway, so just return. */
aca88567
NC
12858 return FALSE;
12859 }
12860}
12861
12862/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12863 a 64-bit absolute RELA relocation used in DWARF debug sections. */
12864
12865static bfd_boolean
dda8d76d 12866is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 12867{
dda8d76d 12868 switch (filedata->file_header.e_machine)
aca88567 12869 {
a06ea964
NC
12870 case EM_AARCH64:
12871 return reloc_type == 257; /* R_AARCH64_ABS64. */
aca88567
NC
12872 case EM_ALPHA:
12873 return reloc_type == 2; /* R_ALPHA_REFQUAD. */
3730236a 12874 case EM_IA_64:
262cdac7
AM
12875 return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */
12876 || reloc_type == 0x27 /* R_IA64_DIR64LSB. */);
3e0873ac
NC
12877 case EM_PARISC:
12878 return reloc_type == 80; /* R_PARISC_DIR64. */
aca88567
NC
12879 case EM_PPC64:
12880 return reloc_type == 38; /* R_PPC64_ADDR64. */
e23eba97
NC
12881 case EM_RISCV:
12882 return reloc_type == 2; /* R_RISCV_64. */
aca88567
NC
12883 case EM_SPARC32PLUS:
12884 case EM_SPARCV9:
12885 case EM_SPARC:
714da62f
NC
12886 return reloc_type == 32 /* R_SPARC_64. */
12887 || reloc_type == 54; /* R_SPARC_UA64. */
aca88567 12888 case EM_X86_64:
8a9036a4 12889 case EM_L1OM:
7a9068fe 12890 case EM_K1OM:
aca88567 12891 return reloc_type == 1; /* R_X86_64_64. */
e819ade1
AS
12892 case EM_S390_OLD:
12893 case EM_S390:
aa137e4d
NC
12894 return reloc_type == 22; /* R_S390_64. */
12895 case EM_TILEGX:
12896 return reloc_type == 1; /* R_TILEGX_64. */
85a82265 12897 case EM_MIPS:
aa137e4d 12898 return reloc_type == 18; /* R_MIPS_64. */
aca88567
NC
12899 default:
12900 return FALSE;
12901 }
12902}
12903
85acf597
RH
12904/* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
12905 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
12906
12907static bfd_boolean
dda8d76d 12908is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
85acf597 12909{
dda8d76d 12910 switch (filedata->file_header.e_machine)
85acf597 12911 {
a06ea964
NC
12912 case EM_AARCH64:
12913 return reloc_type == 260; /* R_AARCH64_PREL64. */
85acf597 12914 case EM_ALPHA:
aa137e4d 12915 return reloc_type == 11; /* R_ALPHA_SREL64. */
85acf597 12916 case EM_IA_64:
262cdac7
AM
12917 return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */
12918 || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */);
85acf597 12919 case EM_PARISC:
aa137e4d 12920 return reloc_type == 72; /* R_PARISC_PCREL64. */
85acf597 12921 case EM_PPC64:
aa137e4d 12922 return reloc_type == 44; /* R_PPC64_REL64. */
85acf597
RH
12923 case EM_SPARC32PLUS:
12924 case EM_SPARCV9:
12925 case EM_SPARC:
aa137e4d 12926 return reloc_type == 46; /* R_SPARC_DISP64. */
85acf597 12927 case EM_X86_64:
8a9036a4 12928 case EM_L1OM:
7a9068fe 12929 case EM_K1OM:
aa137e4d 12930 return reloc_type == 24; /* R_X86_64_PC64. */
85acf597
RH
12931 case EM_S390_OLD:
12932 case EM_S390:
aa137e4d
NC
12933 return reloc_type == 23; /* R_S390_PC64. */
12934 case EM_TILEGX:
12935 return reloc_type == 5; /* R_TILEGX_64_PCREL. */
85acf597
RH
12936 default:
12937 return FALSE;
12938 }
12939}
12940
4dc3c23d
AM
12941/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12942 a 24-bit absolute RELA relocation used in DWARF debug sections. */
12943
12944static bfd_boolean
dda8d76d 12945is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
4dc3c23d 12946{
dda8d76d 12947 switch (filedata->file_header.e_machine)
4dc3c23d
AM
12948 {
12949 case EM_CYGNUS_MN10200:
12950 case EM_MN10200:
12951 return reloc_type == 4; /* R_MN10200_24. */
3ee6e4fb
NC
12952 case EM_FT32:
12953 return reloc_type == 5; /* R_FT32_20. */
4dc3c23d
AM
12954 default:
12955 return FALSE;
12956 }
12957}
12958
aca88567
NC
12959/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12960 a 16-bit absolute RELA relocation used in DWARF debug sections. */
12961
12962static bfd_boolean
dda8d76d 12963is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
4b78141a 12964{
d347c9df 12965 /* Please keep this table alpha-sorted for ease of visual lookup. */
dda8d76d 12966 switch (filedata->file_header.e_machine)
4b78141a 12967 {
886a2506
NC
12968 case EM_ARC:
12969 case EM_ARC_COMPACT:
12970 case EM_ARC_COMPACT2:
12971 return reloc_type == 2; /* R_ARC_16. */
d347c9df
PS
12972 case EM_ADAPTEVA_EPIPHANY:
12973 return reloc_type == 5;
aca88567
NC
12974 case EM_AVR_OLD:
12975 case EM_AVR:
12976 return reloc_type == 4; /* R_AVR_16. */
41e92641
NC
12977 case EM_CYGNUS_D10V:
12978 case EM_D10V:
12979 return reloc_type == 3; /* R_D10V_16. */
81b42bca
JB
12980 case EM_FT32:
12981 return reloc_type == 2; /* R_FT32_16. */
4b78141a
NC
12982 case EM_H8S:
12983 case EM_H8_300:
12984 case EM_H8_300H:
aca88567
NC
12985 return reloc_type == R_H8_DIR16;
12986 case EM_IP2K_OLD:
12987 case EM_IP2K:
12988 return reloc_type == 1; /* R_IP2K_16. */
ff7eeb89 12989 case EM_M32C_OLD:
f4236fe4
DD
12990 case EM_M32C:
12991 return reloc_type == 1; /* R_M32C_16 */
d347c9df
PS
12992 case EM_CYGNUS_MN10200:
12993 case EM_MN10200:
12994 return reloc_type == 2; /* R_MN10200_16. */
12995 case EM_CYGNUS_MN10300:
12996 case EM_MN10300:
12997 return reloc_type == 2; /* R_MN10300_16. */
aca88567 12998 case EM_MSP430:
dda8d76d 12999 if (uses_msp430x_relocs (filedata))
13761a11 13000 return reloc_type == 2; /* R_MSP430_ABS16. */
1a0670f3 13001 /* Fall through. */
78c8d46c 13002 case EM_MSP430_OLD:
aca88567 13003 return reloc_type == 5; /* R_MSP430_16_BYTE. */
35c08157
KLC
13004 case EM_NDS32:
13005 return reloc_type == 19; /* R_NDS32_RELA. */
3e0873ac 13006 case EM_ALTERA_NIOS2:
36591ba1 13007 return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
3e0873ac
NC
13008 case EM_NIOS32:
13009 return reloc_type == 9; /* R_NIOS_16. */
73589c9d
CS
13010 case EM_OR1K:
13011 return reloc_type == 2; /* R_OR1K_16. */
39e07931
AS
13012 case EM_RISCV:
13013 return reloc_type == 55; /* R_RISCV_SET16. */
2b100bb5
DD
13014 case EM_TI_PRU:
13015 return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */
40b36596
JM
13016 case EM_TI_C6000:
13017 return reloc_type == 2; /* R_C6000_ABS16. */
d347c9df
PS
13018 case EM_VISIUM:
13019 return reloc_type == 2; /* R_VISIUM_16. */
c29aca4a
NC
13020 case EM_XC16X:
13021 case EM_C166:
13022 return reloc_type == 2; /* R_XC16C_ABS_16. */
f6c1a2d5
NC
13023 case EM_XGATE:
13024 return reloc_type == 3; /* R_XGATE_16. */
4b78141a 13025 default:
aca88567 13026 return FALSE;
4b78141a
NC
13027 }
13028}
13029
39e07931
AS
13030/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13031 a 8-bit absolute RELA relocation used in DWARF debug sections. */
13032
13033static bfd_boolean
13034is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
13035{
13036 switch (filedata->file_header.e_machine)
13037 {
13038 case EM_RISCV:
13039 return reloc_type == 54; /* R_RISCV_SET8. */
13040 default:
13041 return FALSE;
13042 }
13043}
13044
13045/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13046 a 6-bit absolute RELA relocation used in DWARF debug sections. */
13047
13048static bfd_boolean
13049is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
13050{
13051 switch (filedata->file_header.e_machine)
13052 {
13053 case EM_RISCV:
13054 return reloc_type == 53; /* R_RISCV_SET6. */
13055 default:
13056 return FALSE;
13057 }
13058}
13059
03336641
JW
13060/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13061 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
13062
13063static bfd_boolean
13064is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13065{
13066 /* Please keep this table alpha-sorted for ease of visual lookup. */
13067 switch (filedata->file_header.e_machine)
13068 {
13069 case EM_RISCV:
13070 return reloc_type == 35; /* R_RISCV_ADD32. */
13071 default:
13072 return FALSE;
13073 }
13074}
13075
13076/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13077 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
13078
13079static bfd_boolean
13080is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13081{
13082 /* Please keep this table alpha-sorted for ease of visual lookup. */
13083 switch (filedata->file_header.e_machine)
13084 {
13085 case EM_RISCV:
13086 return reloc_type == 39; /* R_RISCV_SUB32. */
13087 default:
13088 return FALSE;
13089 }
13090}
13091
13092/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13093 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
13094
13095static bfd_boolean
13096is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13097{
13098 /* Please keep this table alpha-sorted for ease of visual lookup. */
13099 switch (filedata->file_header.e_machine)
13100 {
13101 case EM_RISCV:
13102 return reloc_type == 36; /* R_RISCV_ADD64. */
13103 default:
13104 return FALSE;
13105 }
13106}
13107
13108/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13109 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
13110
13111static bfd_boolean
13112is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13113{
13114 /* Please keep this table alpha-sorted for ease of visual lookup. */
13115 switch (filedata->file_header.e_machine)
13116 {
13117 case EM_RISCV:
13118 return reloc_type == 40; /* R_RISCV_SUB64. */
13119 default:
13120 return FALSE;
13121 }
13122}
13123
13124/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13125 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
13126
13127static bfd_boolean
13128is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13129{
13130 /* Please keep this table alpha-sorted for ease of visual lookup. */
13131 switch (filedata->file_header.e_machine)
13132 {
13133 case EM_RISCV:
13134 return reloc_type == 34; /* R_RISCV_ADD16. */
13135 default:
13136 return FALSE;
13137 }
13138}
13139
13140/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13141 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
13142
13143static bfd_boolean
13144is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13145{
13146 /* Please keep this table alpha-sorted for ease of visual lookup. */
13147 switch (filedata->file_header.e_machine)
13148 {
13149 case EM_RISCV:
13150 return reloc_type == 38; /* R_RISCV_SUB16. */
13151 default:
13152 return FALSE;
13153 }
13154}
13155
13156/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13157 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
13158
13159static bfd_boolean
13160is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13161{
13162 /* Please keep this table alpha-sorted for ease of visual lookup. */
13163 switch (filedata->file_header.e_machine)
13164 {
13165 case EM_RISCV:
13166 return reloc_type == 33; /* R_RISCV_ADD8. */
13167 default:
13168 return FALSE;
13169 }
13170}
13171
13172/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13173 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
13174
13175static bfd_boolean
13176is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13177{
13178 /* Please keep this table alpha-sorted for ease of visual lookup. */
13179 switch (filedata->file_header.e_machine)
13180 {
13181 case EM_RISCV:
13182 return reloc_type == 37; /* R_RISCV_SUB8. */
13183 default:
13184 return FALSE;
13185 }
13186}
13187
39e07931
AS
13188/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13189 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
13190
13191static bfd_boolean
13192is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13193{
13194 switch (filedata->file_header.e_machine)
13195 {
13196 case EM_RISCV:
13197 return reloc_type == 52; /* R_RISCV_SUB6. */
13198 default:
13199 return FALSE;
13200 }
13201}
13202
2a7b2e88
JK
13203/* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
13204 relocation entries (possibly formerly used for SHT_GROUP sections). */
13205
13206static bfd_boolean
dda8d76d 13207is_none_reloc (Filedata * filedata, unsigned int reloc_type)
2a7b2e88 13208{
dda8d76d 13209 switch (filedata->file_header.e_machine)
2a7b2e88 13210 {
cb8f3167 13211 case EM_386: /* R_386_NONE. */
d347c9df 13212 case EM_68K: /* R_68K_NONE. */
cfb8c092 13213 case EM_ADAPTEVA_EPIPHANY:
d347c9df
PS
13214 case EM_ALPHA: /* R_ALPHA_NONE. */
13215 case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
886a2506 13216 case EM_ARC: /* R_ARC_NONE. */
886a2506 13217 case EM_ARC_COMPACT2: /* R_ARC_NONE. */
d347c9df 13218 case EM_ARC_COMPACT: /* R_ARC_NONE. */
cb8f3167 13219 case EM_ARM: /* R_ARM_NONE. */
d347c9df 13220 case EM_C166: /* R_XC16X_NONE. */
cb8f3167 13221 case EM_CRIS: /* R_CRIS_NONE. */
d347c9df
PS
13222 case EM_FT32: /* R_FT32_NONE. */
13223 case EM_IA_64: /* R_IA64_NONE. */
7a9068fe 13224 case EM_K1OM: /* R_X86_64_NONE. */
d347c9df
PS
13225 case EM_L1OM: /* R_X86_64_NONE. */
13226 case EM_M32R: /* R_M32R_NONE. */
13227 case EM_MIPS: /* R_MIPS_NONE. */
cb8f3167 13228 case EM_MN10300: /* R_MN10300_NONE. */
5506d11a 13229 case EM_MOXIE: /* R_MOXIE_NONE. */
d347c9df
PS
13230 case EM_NIOS32: /* R_NIOS_NONE. */
13231 case EM_OR1K: /* R_OR1K_NONE. */
13232 case EM_PARISC: /* R_PARISC_NONE. */
13233 case EM_PPC64: /* R_PPC64_NONE. */
13234 case EM_PPC: /* R_PPC_NONE. */
e23eba97 13235 case EM_RISCV: /* R_RISCV_NONE. */
d347c9df
PS
13236 case EM_S390: /* R_390_NONE. */
13237 case EM_S390_OLD:
13238 case EM_SH: /* R_SH_NONE. */
13239 case EM_SPARC32PLUS:
13240 case EM_SPARC: /* R_SPARC_NONE. */
13241 case EM_SPARCV9:
aa137e4d
NC
13242 case EM_TILEGX: /* R_TILEGX_NONE. */
13243 case EM_TILEPRO: /* R_TILEPRO_NONE. */
d347c9df
PS
13244 case EM_TI_C6000:/* R_C6000_NONE. */
13245 case EM_X86_64: /* R_X86_64_NONE. */
c29aca4a 13246 case EM_XC16X:
f96bd6c2 13247 case EM_WEBASSEMBLY: /* R_WASM32_NONE. */
cb8f3167 13248 return reloc_type == 0;
d347c9df 13249
a06ea964
NC
13250 case EM_AARCH64:
13251 return reloc_type == 0 || reloc_type == 256;
d347c9df
PS
13252 case EM_AVR_OLD:
13253 case EM_AVR:
13254 return (reloc_type == 0 /* R_AVR_NONE. */
13255 || reloc_type == 30 /* R_AVR_DIFF8. */
13256 || reloc_type == 31 /* R_AVR_DIFF16. */
13257 || reloc_type == 32 /* R_AVR_DIFF32. */);
13258 case EM_METAG:
13259 return reloc_type == 3; /* R_METAG_NONE. */
35c08157
KLC
13260 case EM_NDS32:
13261 return (reloc_type == 0 /* R_XTENSA_NONE. */
13262 || reloc_type == 204 /* R_NDS32_DIFF8. */
13263 || reloc_type == 205 /* R_NDS32_DIFF16. */
13264 || reloc_type == 206 /* R_NDS32_DIFF32. */
13265 || reloc_type == 207 /* R_NDS32_ULEB128. */);
2b100bb5
DD
13266 case EM_TI_PRU:
13267 return (reloc_type == 0 /* R_PRU_NONE. */
13268 || reloc_type == 65 /* R_PRU_DIFF8. */
13269 || reloc_type == 66 /* R_PRU_DIFF16. */
13270 || reloc_type == 67 /* R_PRU_DIFF32. */);
58332dda
JK
13271 case EM_XTENSA_OLD:
13272 case EM_XTENSA:
4dc3c23d
AM
13273 return (reloc_type == 0 /* R_XTENSA_NONE. */
13274 || reloc_type == 17 /* R_XTENSA_DIFF8. */
13275 || reloc_type == 18 /* R_XTENSA_DIFF16. */
13276 || reloc_type == 19 /* R_XTENSA_DIFF32. */);
2a7b2e88
JK
13277 }
13278 return FALSE;
13279}
13280
d1c4b12b
NC
13281/* Returns TRUE if there is a relocation against
13282 section NAME at OFFSET bytes. */
13283
13284bfd_boolean
13285reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
13286{
13287 Elf_Internal_Rela * relocs;
13288 Elf_Internal_Rela * rp;
13289
13290 if (dsec == NULL || dsec->reloc_info == NULL)
13291 return FALSE;
13292
13293 relocs = (Elf_Internal_Rela *) dsec->reloc_info;
13294
13295 for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
13296 if (rp->r_offset == offset)
13297 return TRUE;
13298
13299 return FALSE;
13300}
13301
cf13d699 13302/* Apply relocations to a section.
32ec8896
NC
13303 Returns TRUE upon success, FALSE otherwise.
13304 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
13305 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
13306 will be set to the number of relocs loaded.
13307
cf13d699 13308 Note: So far support has been added only for those relocations
32ec8896
NC
13309 which can be found in debug sections. FIXME: Add support for
13310 more relocations ? */
1b315056 13311
32ec8896 13312static bfd_boolean
dda8d76d 13313apply_relocations (Filedata * filedata,
d1c4b12b
NC
13314 const Elf_Internal_Shdr * section,
13315 unsigned char * start,
13316 bfd_size_type size,
1449284b 13317 void ** relocs_return,
d1c4b12b 13318 unsigned long * num_relocs_return)
1b315056 13319{
cf13d699 13320 Elf_Internal_Shdr * relsec;
0d2a7a93 13321 unsigned char * end = start + size;
cb8f3167 13322
d1c4b12b
NC
13323 if (relocs_return != NULL)
13324 {
13325 * (Elf_Internal_Rela **) relocs_return = NULL;
13326 * num_relocs_return = 0;
13327 }
13328
dda8d76d 13329 if (filedata->file_header.e_type != ET_REL)
32ec8896
NC
13330 /* No relocs to apply. */
13331 return TRUE;
1b315056 13332
cf13d699 13333 /* Find the reloc section associated with the section. */
dda8d76d
NC
13334 for (relsec = filedata->section_headers;
13335 relsec < filedata->section_headers + filedata->file_header.e_shnum;
5b18a4bc 13336 ++relsec)
252b5132 13337 {
41e92641
NC
13338 bfd_boolean is_rela;
13339 unsigned long num_relocs;
2cf0635d
NC
13340 Elf_Internal_Rela * relocs;
13341 Elf_Internal_Rela * rp;
13342 Elf_Internal_Shdr * symsec;
13343 Elf_Internal_Sym * symtab;
ba5cdace 13344 unsigned long num_syms;
2cf0635d 13345 Elf_Internal_Sym * sym;
252b5132 13346
41e92641 13347 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
13348 || relsec->sh_info >= filedata->file_header.e_shnum
13349 || filedata->section_headers + relsec->sh_info != section
c256ffe7 13350 || relsec->sh_size == 0
dda8d76d 13351 || relsec->sh_link >= filedata->file_header.e_shnum)
5b18a4bc 13352 continue;
428409d5 13353
41e92641
NC
13354 is_rela = relsec->sh_type == SHT_RELA;
13355
13356 if (is_rela)
13357 {
dda8d76d 13358 if (!slurp_rela_relocs (filedata, relsec->sh_offset,
3f5e193b 13359 relsec->sh_size, & relocs, & num_relocs))
32ec8896 13360 return FALSE;
41e92641
NC
13361 }
13362 else
13363 {
dda8d76d 13364 if (!slurp_rel_relocs (filedata, relsec->sh_offset,
3f5e193b 13365 relsec->sh_size, & relocs, & num_relocs))
32ec8896 13366 return FALSE;
41e92641
NC
13367 }
13368
13369 /* SH uses RELA but uses in place value instead of the addend field. */
dda8d76d 13370 if (filedata->file_header.e_machine == EM_SH)
41e92641 13371 is_rela = FALSE;
428409d5 13372
dda8d76d 13373 symsec = filedata->section_headers + relsec->sh_link;
1449284b
NC
13374 if (symsec->sh_type != SHT_SYMTAB
13375 && symsec->sh_type != SHT_DYNSYM)
32ec8896 13376 return FALSE;
dda8d76d 13377 symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms);
103f02d3 13378
41e92641 13379 for (rp = relocs; rp < relocs + num_relocs; ++rp)
252b5132 13380 {
41e92641
NC
13381 bfd_vma addend;
13382 unsigned int reloc_type;
13383 unsigned int reloc_size;
03336641
JW
13384 bfd_boolean reloc_inplace = FALSE;
13385 bfd_boolean reloc_subtract = FALSE;
91d6fa6a 13386 unsigned char * rloc;
ba5cdace 13387 unsigned long sym_index;
4b78141a 13388
dda8d76d 13389 reloc_type = get_reloc_type (filedata, rp->r_info);
41e92641 13390
dda8d76d 13391 if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms))
2a7b2e88 13392 continue;
dda8d76d 13393 else if (is_none_reloc (filedata, reloc_type))
98fb390a 13394 continue;
dda8d76d
NC
13395 else if (is_32bit_abs_reloc (filedata, reloc_type)
13396 || is_32bit_pcrel_reloc (filedata, reloc_type))
aca88567 13397 reloc_size = 4;
dda8d76d
NC
13398 else if (is_64bit_abs_reloc (filedata, reloc_type)
13399 || is_64bit_pcrel_reloc (filedata, reloc_type))
aca88567 13400 reloc_size = 8;
dda8d76d 13401 else if (is_24bit_abs_reloc (filedata, reloc_type))
4dc3c23d 13402 reloc_size = 3;
dda8d76d 13403 else if (is_16bit_abs_reloc (filedata, reloc_type))
aca88567 13404 reloc_size = 2;
39e07931
AS
13405 else if (is_8bit_abs_reloc (filedata, reloc_type)
13406 || is_6bit_abs_reloc (filedata, reloc_type))
13407 reloc_size = 1;
03336641
JW
13408 else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
13409 reloc_type))
13410 || is_32bit_inplace_add_reloc (filedata, reloc_type))
13411 {
13412 reloc_size = 4;
13413 reloc_inplace = TRUE;
13414 }
13415 else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata,
13416 reloc_type))
13417 || is_64bit_inplace_add_reloc (filedata, reloc_type))
13418 {
13419 reloc_size = 8;
13420 reloc_inplace = TRUE;
13421 }
13422 else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata,
13423 reloc_type))
13424 || is_16bit_inplace_add_reloc (filedata, reloc_type))
13425 {
13426 reloc_size = 2;
13427 reloc_inplace = TRUE;
13428 }
13429 else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata,
13430 reloc_type))
13431 || is_8bit_inplace_add_reloc (filedata, reloc_type))
13432 {
13433 reloc_size = 1;
13434 reloc_inplace = TRUE;
13435 }
39e07931
AS
13436 else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata,
13437 reloc_type)))
13438 {
13439 reloc_size = 1;
13440 reloc_inplace = TRUE;
13441 }
aca88567 13442 else
4b78141a 13443 {
bee0ee85 13444 static unsigned int prev_reloc = 0;
dda8d76d 13445
bee0ee85
NC
13446 if (reloc_type != prev_reloc)
13447 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
dda8d76d 13448 reloc_type, printable_section_name (filedata, section));
bee0ee85 13449 prev_reloc = reloc_type;
4b78141a
NC
13450 continue;
13451 }
103f02d3 13452
91d6fa6a 13453 rloc = start + rp->r_offset;
75802ccb 13454 if (!IN_RANGE (start, end, rloc, reloc_size))
700dd8b7
L
13455 {
13456 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
13457 (unsigned long) rp->r_offset,
dda8d76d 13458 printable_section_name (filedata, section));
700dd8b7
L
13459 continue;
13460 }
103f02d3 13461
ba5cdace
NC
13462 sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
13463 if (sym_index >= num_syms)
13464 {
13465 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
dda8d76d 13466 sym_index, printable_section_name (filedata, section));
ba5cdace
NC
13467 continue;
13468 }
13469 sym = symtab + sym_index;
41e92641
NC
13470
13471 /* If the reloc has a symbol associated with it,
55f25fc3
L
13472 make sure that it is of an appropriate type.
13473
13474 Relocations against symbols without type can happen.
13475 Gcc -feliminate-dwarf2-dups may generate symbols
13476 without type for debug info.
13477
13478 Icc generates relocations against function symbols
13479 instead of local labels.
13480
13481 Relocations against object symbols can happen, eg when
13482 referencing a global array. For an example of this see
13483 the _clz.o binary in libgcc.a. */
aca88567 13484 if (sym != symtab
b8871f35 13485 && ELF_ST_TYPE (sym->st_info) != STT_COMMON
55f25fc3 13486 && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
5b18a4bc 13487 {
d3a49aa8 13488 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
dda8d76d
NC
13489 get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)),
13490 printable_section_name (filedata, relsec),
d3a49aa8 13491 (long int)(rp - relocs));
aca88567 13492 continue;
5b18a4bc 13493 }
252b5132 13494
4dc3c23d
AM
13495 addend = 0;
13496 if (is_rela)
13497 addend += rp->r_addend;
c47320c3
AM
13498 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
13499 partial_inplace. */
4dc3c23d 13500 if (!is_rela
dda8d76d 13501 || (filedata->file_header.e_machine == EM_XTENSA
4dc3c23d 13502 && reloc_type == 1)
dda8d76d
NC
13503 || ((filedata->file_header.e_machine == EM_PJ
13504 || filedata->file_header.e_machine == EM_PJ_OLD)
c47320c3 13505 && reloc_type == 1)
dda8d76d
NC
13506 || ((filedata->file_header.e_machine == EM_D30V
13507 || filedata->file_header.e_machine == EM_CYGNUS_D30V)
03336641
JW
13508 && reloc_type == 12)
13509 || reloc_inplace)
39e07931
AS
13510 {
13511 if (is_6bit_inplace_sub_reloc (filedata, reloc_type))
13512 addend += byte_get (rloc, reloc_size) & 0x3f;
13513 else
13514 addend += byte_get (rloc, reloc_size);
13515 }
cb8f3167 13516
dda8d76d
NC
13517 if (is_32bit_pcrel_reloc (filedata, reloc_type)
13518 || is_64bit_pcrel_reloc (filedata, reloc_type))
85acf597
RH
13519 {
13520 /* On HPPA, all pc-relative relocations are biased by 8. */
dda8d76d 13521 if (filedata->file_header.e_machine == EM_PARISC)
85acf597 13522 addend -= 8;
91d6fa6a 13523 byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
85acf597
RH
13524 reloc_size);
13525 }
39e07931
AS
13526 else if (is_6bit_abs_reloc (filedata, reloc_type)
13527 || is_6bit_inplace_sub_reloc (filedata, reloc_type))
13528 {
13529 if (reloc_subtract)
13530 addend -= sym->st_value;
13531 else
13532 addend += sym->st_value;
13533 addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0);
13534 byte_put (rloc, addend, reloc_size);
13535 }
03336641
JW
13536 else if (reloc_subtract)
13537 byte_put (rloc, addend - sym->st_value, reloc_size);
41e92641 13538 else
91d6fa6a 13539 byte_put (rloc, addend + sym->st_value, reloc_size);
5b18a4bc 13540 }
252b5132 13541
5b18a4bc 13542 free (symtab);
f84ce13b
NC
13543 /* Let the target specific reloc processing code know that
13544 we have finished with these relocs. */
dda8d76d 13545 target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0);
d1c4b12b
NC
13546
13547 if (relocs_return)
13548 {
13549 * (Elf_Internal_Rela **) relocs_return = relocs;
13550 * num_relocs_return = num_relocs;
13551 }
13552 else
13553 free (relocs);
13554
5b18a4bc
NC
13555 break;
13556 }
32ec8896 13557
dfc616fa 13558 return TRUE;
5b18a4bc 13559}
103f02d3 13560
cf13d699 13561#ifdef SUPPORT_DISASSEMBLY
32ec8896 13562static bfd_boolean
dda8d76d 13563disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 13564{
dda8d76d 13565 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section));
cf13d699 13566
74e1a04b 13567 /* FIXME: XXX -- to be done --- XXX */
cf13d699 13568
32ec8896 13569 return TRUE;
cf13d699
NC
13570}
13571#endif
13572
13573/* Reads in the contents of SECTION from FILE, returning a pointer
13574 to a malloc'ed buffer or NULL if something went wrong. */
13575
13576static char *
dda8d76d 13577get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 13578{
dda8d76d 13579 bfd_size_type num_bytes = section->sh_size;
cf13d699
NC
13580
13581 if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
13582 {
c6b78c96 13583 printf (_("Section '%s' has no data to dump.\n"),
dda8d76d 13584 printable_section_name (filedata, section));
cf13d699
NC
13585 return NULL;
13586 }
13587
dda8d76d 13588 return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes,
3f5e193b 13589 _("section contents"));
cf13d699
NC
13590}
13591
0e602686
NC
13592/* Uncompresses a section that was compressed using zlib, in place. */
13593
13594static bfd_boolean
dda8d76d
NC
13595uncompress_section_contents (unsigned char ** buffer,
13596 dwarf_size_type uncompressed_size,
13597 dwarf_size_type * size)
0e602686
NC
13598{
13599 dwarf_size_type compressed_size = *size;
13600 unsigned char * compressed_buffer = *buffer;
13601 unsigned char * uncompressed_buffer;
13602 z_stream strm;
13603 int rc;
13604
13605 /* It is possible the section consists of several compressed
13606 buffers concatenated together, so we uncompress in a loop. */
13607 /* PR 18313: The state field in the z_stream structure is supposed
13608 to be invisible to the user (ie us), but some compilers will
13609 still complain about it being used without initialisation. So
13610 we first zero the entire z_stream structure and then set the fields
13611 that we need. */
13612 memset (& strm, 0, sizeof strm);
13613 strm.avail_in = compressed_size;
13614 strm.next_in = (Bytef *) compressed_buffer;
13615 strm.avail_out = uncompressed_size;
13616 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
13617
13618 rc = inflateInit (& strm);
13619 while (strm.avail_in > 0)
13620 {
13621 if (rc != Z_OK)
13622 goto fail;
13623 strm.next_out = ((Bytef *) uncompressed_buffer
13624 + (uncompressed_size - strm.avail_out));
13625 rc = inflate (&strm, Z_FINISH);
13626 if (rc != Z_STREAM_END)
13627 goto fail;
13628 rc = inflateReset (& strm);
13629 }
13630 rc = inflateEnd (& strm);
13631 if (rc != Z_OK
13632 || strm.avail_out != 0)
13633 goto fail;
13634
13635 *buffer = uncompressed_buffer;
13636 *size = uncompressed_size;
13637 return TRUE;
13638
13639 fail:
13640 free (uncompressed_buffer);
13641 /* Indicate decompression failure. */
13642 *buffer = NULL;
13643 return FALSE;
13644}
dd24e3da 13645
32ec8896 13646static bfd_boolean
dda8d76d 13647dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 13648{
0e602686
NC
13649 Elf_Internal_Shdr * relsec;
13650 bfd_size_type num_bytes;
fd8008d8
L
13651 unsigned char * data;
13652 unsigned char * end;
13653 unsigned char * real_start;
13654 unsigned char * start;
0e602686 13655 bfd_boolean some_strings_shown;
cf13d699 13656
dda8d76d 13657 real_start = start = (unsigned char *) get_section_contents (section, filedata);
cf13d699 13658 if (start == NULL)
c6b78c96
NC
13659 /* PR 21820: Do not fail if the section was empty. */
13660 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
13661
0e602686 13662 num_bytes = section->sh_size;
cf13d699 13663
dda8d76d 13664 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata, section));
cf13d699 13665
0e602686
NC
13666 if (decompress_dumps)
13667 {
13668 dwarf_size_type new_size = num_bytes;
13669 dwarf_size_type uncompressed_size = 0;
13670
13671 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13672 {
13673 Elf_Internal_Chdr chdr;
13674 unsigned int compression_header_size
ebdf1ebf
NC
13675 = get_compression_header (& chdr, (unsigned char *) start,
13676 num_bytes);
0e602686 13677
813dabb9 13678 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
0e602686 13679 {
813dabb9 13680 warn (_("section '%s' has unsupported compress type: %d\n"),
dda8d76d 13681 printable_section_name (filedata, section), chdr.ch_type);
32ec8896 13682 return FALSE;
813dabb9 13683 }
813dabb9
L
13684 uncompressed_size = chdr.ch_size;
13685 start += compression_header_size;
13686 new_size -= compression_header_size;
0e602686
NC
13687 }
13688 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13689 {
13690 /* Read the zlib header. In this case, it should be "ZLIB"
13691 followed by the uncompressed section size, 8 bytes in
13692 big-endian order. */
13693 uncompressed_size = start[4]; uncompressed_size <<= 8;
13694 uncompressed_size += start[5]; uncompressed_size <<= 8;
13695 uncompressed_size += start[6]; uncompressed_size <<= 8;
13696 uncompressed_size += start[7]; uncompressed_size <<= 8;
13697 uncompressed_size += start[8]; uncompressed_size <<= 8;
13698 uncompressed_size += start[9]; uncompressed_size <<= 8;
13699 uncompressed_size += start[10]; uncompressed_size <<= 8;
13700 uncompressed_size += start[11];
13701 start += 12;
13702 new_size -= 12;
13703 }
13704
1835f746
NC
13705 if (uncompressed_size)
13706 {
13707 if (uncompress_section_contents (& start,
13708 uncompressed_size, & new_size))
13709 num_bytes = new_size;
13710 else
13711 {
13712 error (_("Unable to decompress section %s\n"),
dda8d76d 13713 printable_section_name (filedata, section));
32ec8896 13714 return FALSE;
1835f746
NC
13715 }
13716 }
bc303e5d
NC
13717 else
13718 start = real_start;
0e602686 13719 }
fd8008d8 13720
cf13d699
NC
13721 /* If the section being dumped has relocations against it the user might
13722 be expecting these relocations to have been applied. Check for this
13723 case and issue a warning message in order to avoid confusion.
13724 FIXME: Maybe we ought to have an option that dumps a section with
13725 relocs applied ? */
dda8d76d
NC
13726 for (relsec = filedata->section_headers;
13727 relsec < filedata->section_headers + filedata->file_header.e_shnum;
cf13d699
NC
13728 ++relsec)
13729 {
13730 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
13731 || relsec->sh_info >= filedata->file_header.e_shnum
13732 || filedata->section_headers + relsec->sh_info != section
cf13d699 13733 || relsec->sh_size == 0
dda8d76d 13734 || relsec->sh_link >= filedata->file_header.e_shnum)
cf13d699
NC
13735 continue;
13736
13737 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13738 break;
13739 }
13740
cf13d699
NC
13741 data = start;
13742 end = start + num_bytes;
13743 some_strings_shown = FALSE;
13744
13745 while (data < end)
13746 {
13747 while (!ISPRINT (* data))
13748 if (++ data >= end)
13749 break;
13750
13751 if (data < end)
13752 {
071436c6
NC
13753 size_t maxlen = end - data;
13754
cf13d699 13755#ifndef __MSVCRT__
c975cc98
NC
13756 /* PR 11128: Use two separate invocations in order to work
13757 around bugs in the Solaris 8 implementation of printf. */
13758 printf (" [%6tx] ", data - start);
cf13d699 13759#else
071436c6 13760 printf (" [%6Ix] ", (size_t) (data - start));
cf13d699 13761#endif
4082ef84
NC
13762 if (maxlen > 0)
13763 {
fd8008d8 13764 print_symbol ((int) maxlen, (const char *) data);
4082ef84 13765 putchar ('\n');
fd8008d8 13766 data += strnlen ((const char *) data, maxlen);
4082ef84
NC
13767 }
13768 else
13769 {
13770 printf (_("<corrupt>\n"));
13771 data = end;
13772 }
cf13d699
NC
13773 some_strings_shown = TRUE;
13774 }
13775 }
13776
13777 if (! some_strings_shown)
13778 printf (_(" No strings found in this section."));
13779
0e602686 13780 free (real_start);
cf13d699
NC
13781
13782 putchar ('\n');
32ec8896 13783 return TRUE;
cf13d699
NC
13784}
13785
32ec8896 13786static bfd_boolean
dda8d76d
NC
13787dump_section_as_bytes (Elf_Internal_Shdr * section,
13788 Filedata * filedata,
13789 bfd_boolean relocate)
cf13d699
NC
13790{
13791 Elf_Internal_Shdr * relsec;
0e602686
NC
13792 bfd_size_type bytes;
13793 bfd_size_type section_size;
13794 bfd_vma addr;
13795 unsigned char * data;
13796 unsigned char * real_start;
13797 unsigned char * start;
13798
dda8d76d 13799 real_start = start = (unsigned char *) get_section_contents (section, filedata);
cf13d699 13800 if (start == NULL)
c6b78c96
NC
13801 /* PR 21820: Do not fail if the section was empty. */
13802 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
32ec8896 13803
0e602686 13804 section_size = section->sh_size;
cf13d699 13805
dda8d76d 13806 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata, section));
cf13d699 13807
0e602686
NC
13808 if (decompress_dumps)
13809 {
13810 dwarf_size_type new_size = section_size;
13811 dwarf_size_type uncompressed_size = 0;
13812
13813 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13814 {
13815 Elf_Internal_Chdr chdr;
13816 unsigned int compression_header_size
ebdf1ebf 13817 = get_compression_header (& chdr, start, section_size);
0e602686 13818
813dabb9 13819 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
0e602686 13820 {
813dabb9 13821 warn (_("section '%s' has unsupported compress type: %d\n"),
dda8d76d 13822 printable_section_name (filedata, section), chdr.ch_type);
32ec8896 13823 return FALSE;
0e602686 13824 }
813dabb9
L
13825 uncompressed_size = chdr.ch_size;
13826 start += compression_header_size;
13827 new_size -= compression_header_size;
0e602686
NC
13828 }
13829 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13830 {
13831 /* Read the zlib header. In this case, it should be "ZLIB"
13832 followed by the uncompressed section size, 8 bytes in
13833 big-endian order. */
13834 uncompressed_size = start[4]; uncompressed_size <<= 8;
13835 uncompressed_size += start[5]; uncompressed_size <<= 8;
13836 uncompressed_size += start[6]; uncompressed_size <<= 8;
13837 uncompressed_size += start[7]; uncompressed_size <<= 8;
13838 uncompressed_size += start[8]; uncompressed_size <<= 8;
13839 uncompressed_size += start[9]; uncompressed_size <<= 8;
13840 uncompressed_size += start[10]; uncompressed_size <<= 8;
13841 uncompressed_size += start[11];
13842 start += 12;
13843 new_size -= 12;
13844 }
13845
f055032e
NC
13846 if (uncompressed_size)
13847 {
13848 if (uncompress_section_contents (& start, uncompressed_size,
13849 & new_size))
bc303e5d
NC
13850 {
13851 section_size = new_size;
13852 }
f055032e
NC
13853 else
13854 {
13855 error (_("Unable to decompress section %s\n"),
dda8d76d 13856 printable_section_name (filedata, section));
bc303e5d 13857 /* FIXME: Print the section anyway ? */
32ec8896 13858 return FALSE;
f055032e
NC
13859 }
13860 }
bc303e5d
NC
13861 else
13862 start = real_start;
0e602686 13863 }
14ae95f2 13864
cf13d699
NC
13865 if (relocate)
13866 {
dda8d76d 13867 if (! apply_relocations (filedata, section, start, section_size, NULL, NULL))
32ec8896 13868 return FALSE;
cf13d699
NC
13869 }
13870 else
13871 {
13872 /* If the section being dumped has relocations against it the user might
13873 be expecting these relocations to have been applied. Check for this
13874 case and issue a warning message in order to avoid confusion.
13875 FIXME: Maybe we ought to have an option that dumps a section with
13876 relocs applied ? */
dda8d76d
NC
13877 for (relsec = filedata->section_headers;
13878 relsec < filedata->section_headers + filedata->file_header.e_shnum;
cf13d699
NC
13879 ++relsec)
13880 {
13881 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
13882 || relsec->sh_info >= filedata->file_header.e_shnum
13883 || filedata->section_headers + relsec->sh_info != section
cf13d699 13884 || relsec->sh_size == 0
dda8d76d 13885 || relsec->sh_link >= filedata->file_header.e_shnum)
cf13d699
NC
13886 continue;
13887
13888 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13889 break;
13890 }
13891 }
13892
13893 addr = section->sh_addr;
0e602686 13894 bytes = section_size;
cf13d699
NC
13895 data = start;
13896
13897 while (bytes)
13898 {
13899 int j;
13900 int k;
13901 int lbytes;
13902
13903 lbytes = (bytes > 16 ? 16 : bytes);
13904
13905 printf (" 0x%8.8lx ", (unsigned long) addr);
13906
13907 for (j = 0; j < 16; j++)
13908 {
13909 if (j < lbytes)
13910 printf ("%2.2x", data[j]);
13911 else
13912 printf (" ");
13913
13914 if ((j & 3) == 3)
13915 printf (" ");
13916 }
13917
13918 for (j = 0; j < lbytes; j++)
13919 {
13920 k = data[j];
13921 if (k >= ' ' && k < 0x7f)
13922 printf ("%c", k);
13923 else
13924 printf (".");
13925 }
13926
13927 putchar ('\n');
13928
13929 data += lbytes;
13930 addr += lbytes;
13931 bytes -= lbytes;
13932 }
13933
0e602686 13934 free (real_start);
cf13d699
NC
13935
13936 putchar ('\n');
32ec8896 13937 return TRUE;
cf13d699
NC
13938}
13939
7d9813f1
NA
13940static ctf_sect_t *
13941shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata)
13942{
90bd5423 13943 buf->cts_name = SECTION_NAME (shdr);
7d9813f1
NA
13944 buf->cts_size = shdr->sh_size;
13945 buf->cts_entsize = shdr->sh_entsize;
7d9813f1
NA
13946
13947 return buf;
13948}
13949
13950/* Formatting callback function passed to ctf_dump. Returns either the pointer
13951 it is passed, or a pointer to newly-allocated storage, in which case
13952 dump_ctf() will free it when it no longer needs it. */
13953
13954static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
13955 char *s, void *arg)
13956{
3e50a591 13957 const char *blanks = arg;
7d9813f1
NA
13958 char *new_s;
13959
3e50a591 13960 if (asprintf (&new_s, "%s%s", blanks, s) < 0)
7d9813f1
NA
13961 return s;
13962 return new_s;
13963}
13964
13965static bfd_boolean
13966dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
13967{
13968 Elf_Internal_Shdr * parent_sec = NULL;
13969 Elf_Internal_Shdr * symtab_sec = NULL;
13970 Elf_Internal_Shdr * strtab_sec = NULL;
d344b407
NA
13971 void * data = NULL;
13972 void * symdata = NULL;
13973 void * strdata = NULL;
13974 void * parentdata = NULL;
13975 ctf_sect_t ctfsect, symsect, strsect, parentsect;
13976 ctf_sect_t * symsectp = NULL;
13977 ctf_sect_t * strsectp = NULL;
13978 ctf_file_t * ctf = NULL;
13979 ctf_file_t * parent = NULL;
7d9813f1 13980
9b32cba4
NA
13981 const char *things[] = {"Header", "Labels", "Data objects",
13982 "Function objects", "Variables", "Types", "Strings",
13983 ""};
7d9813f1
NA
13984 const char **thing;
13985 int err;
13986 bfd_boolean ret = FALSE;
13987 size_t i;
13988
13989 shdr_to_ctf_sect (&ctfsect, section, filedata);
13990 data = get_section_contents (section, filedata);
13991 ctfsect.cts_data = data;
13992
616febde
NA
13993 if (!dump_ctf_symtab_name)
13994 dump_ctf_symtab_name = strdup (".symtab");
13995
13996 if (!dump_ctf_strtab_name)
13997 dump_ctf_strtab_name = strdup (".strtab");
13998
13999 if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0)
7d9813f1
NA
14000 {
14001 if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL)
14002 {
14003 error (_("No symbol section named %s\n"), dump_ctf_symtab_name);
14004 goto fail;
14005 }
14006 if ((symdata = (void *) get_data (NULL, filedata,
14007 symtab_sec->sh_offset, 1,
14008 symtab_sec->sh_size,
14009 _("symbols"))) == NULL)
14010 goto fail;
14011 symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata);
14012 symsect.cts_data = symdata;
14013 }
616febde 14014 if (dump_ctf_strtab_name && dump_ctf_symtab_name[0] != 0)
7d9813f1
NA
14015 {
14016 if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL)
14017 {
14018 error (_("No string table section named %s\n"),
14019 dump_ctf_strtab_name);
14020 goto fail;
14021 }
14022 if ((strdata = (void *) get_data (NULL, filedata,
14023 strtab_sec->sh_offset, 1,
14024 strtab_sec->sh_size,
14025 _("strings"))) == NULL)
14026 goto fail;
14027 strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata);
14028 strsect.cts_data = strdata;
14029 }
14030 if (dump_ctf_parent_name)
14031 {
14032 if ((parent_sec = find_section (filedata, dump_ctf_parent_name)) == NULL)
14033 {
14034 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name);
14035 goto fail;
14036 }
14037 if ((parentdata = (void *) get_data (NULL, filedata,
14038 parent_sec->sh_offset, 1,
14039 parent_sec->sh_size,
14040 _("CTF parent"))) == NULL)
14041 goto fail;
14042 shdr_to_ctf_sect (&parentsect, parent_sec, filedata);
14043 parentsect.cts_data = parentdata;
14044 }
14045
14046 /* Load the CTF file and dump it. */
14047
14048 if ((ctf = ctf_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
14049 {
14050 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
14051 goto fail;
14052 }
14053
14054 if (parentdata)
14055 {
14056 if ((parent = ctf_bufopen (&parentsect, symsectp, strsectp, &err)) == NULL)
14057 {
14058 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
14059 goto fail;
14060 }
14061
14062 ctf_import (ctf, parent);
14063 }
14064
14065 ret = TRUE;
14066
14067 printf (_("\nDump of CTF section '%s':\n"),
14068 printable_section_name (filedata, section));
14069
9b32cba4 14070 for (i = 0, thing = things; *thing[0]; thing++, i++)
7d9813f1
NA
14071 {
14072 ctf_dump_state_t *s = NULL;
14073 char *item;
14074
14075 printf ("\n %s:\n", *thing);
14076 while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
14077 (void *) " ")) != NULL)
14078 {
14079 printf ("%s\n", item);
14080 free (item);
14081 }
14082
14083 if (ctf_errno (ctf))
14084 {
14085 error (_("Iteration failed: %s, %s\n"), *thing,
14086 ctf_errmsg (ctf_errno (ctf)));
14087 ret = FALSE;
14088 }
14089 }
14090
14091 fail:
14092 ctf_file_close (ctf);
14093 ctf_file_close (parent);
14094 free (parentdata);
14095 free (data);
14096 free (symdata);
14097 free (strdata);
14098 return ret;
14099}
14100
32ec8896 14101static bfd_boolean
dda8d76d
NC
14102load_specific_debug_section (enum dwarf_section_display_enum debug,
14103 const Elf_Internal_Shdr * sec,
14104 void * data)
1007acb3 14105{
2cf0635d 14106 struct dwarf_section * section = &debug_displays [debug].section;
19e6b90e 14107 char buf [64];
dda8d76d 14108 Filedata * filedata = (Filedata *) data;
9abca702 14109
19e6b90e 14110 if (section->start != NULL)
dda8d76d
NC
14111 {
14112 /* If it is already loaded, do nothing. */
14113 if (streq (section->filename, filedata->file_name))
14114 return TRUE;
14115 free (section->start);
14116 }
1007acb3 14117
19e6b90e
L
14118 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
14119 section->address = sec->sh_addr;
06614111 14120 section->user_data = NULL;
dda8d76d
NC
14121 section->filename = filedata->file_name;
14122 section->start = (unsigned char *) get_data (NULL, filedata,
3f5e193b
NC
14123 sec->sh_offset, 1,
14124 sec->sh_size, buf);
59245841
NC
14125 if (section->start == NULL)
14126 section->size = 0;
14127 else
14128 {
77115a4a
L
14129 unsigned char *start = section->start;
14130 dwarf_size_type size = sec->sh_size;
dab394de 14131 dwarf_size_type uncompressed_size = 0;
77115a4a
L
14132
14133 if ((sec->sh_flags & SHF_COMPRESSED) != 0)
14134 {
14135 Elf_Internal_Chdr chdr;
d8024a91
NC
14136 unsigned int compression_header_size;
14137
f53be977
L
14138 if (size < (is_32bit_elf
14139 ? sizeof (Elf32_External_Chdr)
14140 : sizeof (Elf64_External_Chdr)))
d8024a91
NC
14141 {
14142 warn (_("compressed section %s is too small to contain a compression header"),
14143 section->name);
32ec8896 14144 return FALSE;
d8024a91
NC
14145 }
14146
ebdf1ebf 14147 compression_header_size = get_compression_header (&chdr, start, size);
d8024a91 14148
813dabb9
L
14149 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
14150 {
14151 warn (_("section '%s' has unsupported compress type: %d\n"),
14152 section->name, chdr.ch_type);
32ec8896 14153 return FALSE;
813dabb9 14154 }
dab394de 14155 uncompressed_size = chdr.ch_size;
77115a4a
L
14156 start += compression_header_size;
14157 size -= compression_header_size;
14158 }
dab394de
L
14159 else if (size > 12 && streq ((char *) start, "ZLIB"))
14160 {
14161 /* Read the zlib header. In this case, it should be "ZLIB"
14162 followed by the uncompressed section size, 8 bytes in
14163 big-endian order. */
14164 uncompressed_size = start[4]; uncompressed_size <<= 8;
14165 uncompressed_size += start[5]; uncompressed_size <<= 8;
14166 uncompressed_size += start[6]; uncompressed_size <<= 8;
14167 uncompressed_size += start[7]; uncompressed_size <<= 8;
14168 uncompressed_size += start[8]; uncompressed_size <<= 8;
14169 uncompressed_size += start[9]; uncompressed_size <<= 8;
14170 uncompressed_size += start[10]; uncompressed_size <<= 8;
14171 uncompressed_size += start[11];
14172 start += 12;
14173 size -= 12;
14174 }
14175
1835f746 14176 if (uncompressed_size)
77115a4a 14177 {
1835f746
NC
14178 if (uncompress_section_contents (&start, uncompressed_size,
14179 &size))
14180 {
14181 /* Free the compressed buffer, update the section buffer
14182 and the section size if uncompress is successful. */
14183 free (section->start);
14184 section->start = start;
14185 }
14186 else
14187 {
14188 error (_("Unable to decompress section %s\n"),
dda8d76d 14189 printable_section_name (filedata, sec));
32ec8896 14190 return FALSE;
1835f746 14191 }
77115a4a 14192 }
bc303e5d 14193
77115a4a 14194 section->size = size;
59245841 14195 }
4a114e3e 14196
1b315056 14197 if (section->start == NULL)
32ec8896 14198 return FALSE;
1b315056 14199
19e6b90e 14200 if (debug_displays [debug].relocate)
32ec8896 14201 {
dda8d76d 14202 if (! apply_relocations (filedata, sec, section->start, section->size,
32ec8896
NC
14203 & section->reloc_info, & section->num_relocs))
14204 return FALSE;
14205 }
d1c4b12b
NC
14206 else
14207 {
14208 section->reloc_info = NULL;
14209 section->num_relocs = 0;
14210 }
1007acb3 14211
32ec8896 14212 return TRUE;
1007acb3
L
14213}
14214
657d0d47
CC
14215/* If this is not NULL, load_debug_section will only look for sections
14216 within the list of sections given here. */
32ec8896 14217static unsigned int * section_subset = NULL;
657d0d47 14218
32ec8896 14219bfd_boolean
dda8d76d 14220load_debug_section (enum dwarf_section_display_enum debug, void * data)
d966045b 14221{
2cf0635d
NC
14222 struct dwarf_section * section = &debug_displays [debug].section;
14223 Elf_Internal_Shdr * sec;
dda8d76d
NC
14224 Filedata * filedata = (Filedata *) data;
14225
f425ec66
NC
14226 /* Without section headers we cannot find any sections. */
14227 if (filedata->section_headers == NULL)
14228 return FALSE;
14229
9c1ce108
AM
14230 if (filedata->string_table == NULL
14231 && filedata->file_header.e_shstrndx != SHN_UNDEF
14232 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
dda8d76d
NC
14233 {
14234 Elf_Internal_Shdr * strs;
14235
14236 /* Read in the string table, so that we have section names to scan. */
14237 strs = filedata->section_headers + filedata->file_header.e_shstrndx;
14238
4dff97b2 14239 if (strs != NULL && strs->sh_size != 0)
dda8d76d 14240 {
9c1ce108
AM
14241 filedata->string_table
14242 = (char *) get_data (NULL, filedata, strs->sh_offset,
14243 1, strs->sh_size, _("string table"));
dda8d76d 14244
9c1ce108
AM
14245 filedata->string_table_length
14246 = filedata->string_table != NULL ? strs->sh_size : 0;
dda8d76d
NC
14247 }
14248 }
d966045b
DJ
14249
14250 /* Locate the debug section. */
dda8d76d 14251 sec = find_section_in_set (filedata, section->uncompressed_name, section_subset);
d966045b
DJ
14252 if (sec != NULL)
14253 section->name = section->uncompressed_name;
14254 else
14255 {
dda8d76d 14256 sec = find_section_in_set (filedata, section->compressed_name, section_subset);
d966045b
DJ
14257 if (sec != NULL)
14258 section->name = section->compressed_name;
14259 }
14260 if (sec == NULL)
32ec8896 14261 return FALSE;
d966045b 14262
657d0d47
CC
14263 /* If we're loading from a subset of sections, and we've loaded
14264 a section matching this name before, it's likely that it's a
14265 different one. */
14266 if (section_subset != NULL)
14267 free_debug_section (debug);
14268
dda8d76d 14269 return load_specific_debug_section (debug, sec, data);
d966045b
DJ
14270}
14271
19e6b90e
L
14272void
14273free_debug_section (enum dwarf_section_display_enum debug)
1007acb3 14274{
2cf0635d 14275 struct dwarf_section * section = &debug_displays [debug].section;
1007acb3 14276
19e6b90e
L
14277 if (section->start == NULL)
14278 return;
1007acb3 14279
19e6b90e
L
14280 free ((char *) section->start);
14281 section->start = NULL;
14282 section->address = 0;
14283 section->size = 0;
1007acb3
L
14284}
14285
32ec8896 14286static bfd_boolean
dda8d76d 14287display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata)
1007acb3 14288{
2cf0635d 14289 char * name = SECTION_NAME (section);
dda8d76d 14290 const char * print_name = printable_section_name (filedata, section);
19e6b90e 14291 bfd_size_type length;
32ec8896 14292 bfd_boolean result = TRUE;
3f5e193b 14293 int i;
1007acb3 14294
19e6b90e
L
14295 length = section->sh_size;
14296 if (length == 0)
1007acb3 14297 {
74e1a04b 14298 printf (_("\nSection '%s' has no debugging data.\n"), print_name);
32ec8896 14299 return TRUE;
1007acb3 14300 }
5dff79d8
NC
14301 if (section->sh_type == SHT_NOBITS)
14302 {
14303 /* There is no point in dumping the contents of a debugging section
14304 which has the NOBITS type - the bits in the file will be random.
14305 This can happen when a file containing a .eh_frame section is
14306 stripped with the --only-keep-debug command line option. */
74e1a04b
NC
14307 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
14308 print_name);
32ec8896 14309 return FALSE;
5dff79d8 14310 }
1007acb3 14311
0112cd26 14312 if (const_strneq (name, ".gnu.linkonce.wi."))
19e6b90e 14313 name = ".debug_info";
1007acb3 14314
19e6b90e
L
14315 /* See if we know how to display the contents of this section. */
14316 for (i = 0; i < max; i++)
d85bf2ba
NC
14317 {
14318 enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i;
14319 struct dwarf_section_display * display = debug_displays + i;
14320 struct dwarf_section * sec = & display->section;
d966045b 14321
d85bf2ba
NC
14322 if (streq (sec->uncompressed_name, name)
14323 || (id == line && const_strneq (name, ".debug_line."))
14324 || streq (sec->compressed_name, name))
14325 {
14326 bfd_boolean secondary = (section != find_section (filedata, name));
1007acb3 14327
d85bf2ba
NC
14328 if (secondary)
14329 free_debug_section (id);
dda8d76d 14330
d85bf2ba
NC
14331 if (i == line && const_strneq (name, ".debug_line."))
14332 sec->name = name;
14333 else if (streq (sec->uncompressed_name, name))
14334 sec->name = sec->uncompressed_name;
14335 else
14336 sec->name = sec->compressed_name;
657d0d47 14337
d85bf2ba
NC
14338 if (load_specific_debug_section (id, section, filedata))
14339 {
14340 /* If this debug section is part of a CU/TU set in a .dwp file,
14341 restrict load_debug_section to the sections in that set. */
14342 section_subset = find_cu_tu_set (filedata, shndx);
1007acb3 14343
d85bf2ba 14344 result &= display->display (sec, filedata);
657d0d47 14345
d85bf2ba 14346 section_subset = NULL;
1007acb3 14347
d85bf2ba
NC
14348 if (secondary || (id != info && id != abbrev))
14349 free_debug_section (id);
14350 }
14351 break;
14352 }
14353 }
1007acb3 14354
19e6b90e 14355 if (i == max)
1007acb3 14356 {
74e1a04b 14357 printf (_("Unrecognized debug section: %s\n"), print_name);
32ec8896 14358 result = FALSE;
1007acb3
L
14359 }
14360
19e6b90e 14361 return result;
5b18a4bc 14362}
103f02d3 14363
aef1f6d0
DJ
14364/* Set DUMP_SECTS for all sections where dumps were requested
14365 based on section name. */
14366
14367static void
dda8d76d 14368initialise_dumps_byname (Filedata * filedata)
aef1f6d0 14369{
2cf0635d 14370 struct dump_list_entry * cur;
aef1f6d0
DJ
14371
14372 for (cur = dump_sects_byname; cur; cur = cur->next)
14373 {
14374 unsigned int i;
32ec8896 14375 bfd_boolean any = FALSE;
aef1f6d0 14376
dda8d76d
NC
14377 for (i = 0; i < filedata->file_header.e_shnum; i++)
14378 if (streq (SECTION_NAME (filedata->section_headers + i), cur->name))
aef1f6d0 14379 {
dda8d76d 14380 request_dump_bynumber (filedata, i, cur->type);
32ec8896 14381 any = TRUE;
aef1f6d0
DJ
14382 }
14383
14384 if (!any)
14385 warn (_("Section '%s' was not dumped because it does not exist!\n"),
14386 cur->name);
14387 }
14388}
14389
32ec8896 14390static bfd_boolean
dda8d76d 14391process_section_contents (Filedata * filedata)
5b18a4bc 14392{
2cf0635d 14393 Elf_Internal_Shdr * section;
19e6b90e 14394 unsigned int i;
32ec8896 14395 bfd_boolean res = TRUE;
103f02d3 14396
19e6b90e 14397 if (! do_dump)
32ec8896 14398 return TRUE;
103f02d3 14399
dda8d76d 14400 initialise_dumps_byname (filedata);
aef1f6d0 14401
dda8d76d
NC
14402 for (i = 0, section = filedata->section_headers;
14403 i < filedata->file_header.e_shnum && i < filedata->num_dump_sects;
19e6b90e
L
14404 i++, section++)
14405 {
dda8d76d
NC
14406 dump_type dump = filedata->dump_sects[i];
14407
19e6b90e 14408#ifdef SUPPORT_DISASSEMBLY
dda8d76d
NC
14409 if (dump & DISASS_DUMP)
14410 {
14411 if (! disassemble_section (section, filedata))
14412 res = FALSE;
14413 }
19e6b90e 14414#endif
dda8d76d 14415 if (dump & HEX_DUMP)
32ec8896 14416 {
dda8d76d 14417 if (! dump_section_as_bytes (section, filedata, FALSE))
32ec8896
NC
14418 res = FALSE;
14419 }
103f02d3 14420
dda8d76d 14421 if (dump & RELOC_DUMP)
32ec8896 14422 {
dda8d76d 14423 if (! dump_section_as_bytes (section, filedata, TRUE))
32ec8896
NC
14424 res = FALSE;
14425 }
09c11c86 14426
dda8d76d 14427 if (dump & STRING_DUMP)
32ec8896 14428 {
dda8d76d 14429 if (! dump_section_as_strings (section, filedata))
32ec8896
NC
14430 res = FALSE;
14431 }
cf13d699 14432
dda8d76d 14433 if (dump & DEBUG_DUMP)
32ec8896 14434 {
dda8d76d 14435 if (! display_debug_section (i, section, filedata))
32ec8896
NC
14436 res = FALSE;
14437 }
7d9813f1
NA
14438
14439 if (dump & CTF_DUMP)
14440 {
14441 if (! dump_section_as_ctf (section, filedata))
14442 res = FALSE;
14443 }
5b18a4bc 14444 }
103f02d3 14445
19e6b90e
L
14446 /* Check to see if the user requested a
14447 dump of a section that does not exist. */
dda8d76d 14448 while (i < filedata->num_dump_sects)
0ee3043f 14449 {
dda8d76d 14450 if (filedata->dump_sects[i])
32ec8896
NC
14451 {
14452 warn (_("Section %d was not dumped because it does not exist!\n"), i);
14453 res = FALSE;
14454 }
0ee3043f
NC
14455 i++;
14456 }
32ec8896
NC
14457
14458 return res;
5b18a4bc 14459}
103f02d3 14460
5b18a4bc 14461static void
19e6b90e 14462process_mips_fpe_exception (int mask)
5b18a4bc 14463{
19e6b90e
L
14464 if (mask)
14465 {
32ec8896
NC
14466 bfd_boolean first = TRUE;
14467
19e6b90e 14468 if (mask & OEX_FPU_INEX)
32ec8896 14469 fputs ("INEX", stdout), first = FALSE;
19e6b90e 14470 if (mask & OEX_FPU_UFLO)
32ec8896 14471 printf ("%sUFLO", first ? "" : "|"), first = FALSE;
19e6b90e 14472 if (mask & OEX_FPU_OFLO)
32ec8896 14473 printf ("%sOFLO", first ? "" : "|"), first = FALSE;
19e6b90e 14474 if (mask & OEX_FPU_DIV0)
32ec8896 14475 printf ("%sDIV0", first ? "" : "|"), first = FALSE;
19e6b90e
L
14476 if (mask & OEX_FPU_INVAL)
14477 printf ("%sINVAL", first ? "" : "|");
14478 }
5b18a4bc 14479 else
19e6b90e 14480 fputs ("0", stdout);
5b18a4bc 14481}
103f02d3 14482
f6f0e17b
NC
14483/* Display's the value of TAG at location P. If TAG is
14484 greater than 0 it is assumed to be an unknown tag, and
14485 a message is printed to this effect. Otherwise it is
14486 assumed that a message has already been printed.
14487
14488 If the bottom bit of TAG is set it assumed to have a
14489 string value, otherwise it is assumed to have an integer
14490 value.
14491
14492 Returns an updated P pointing to the first unread byte
14493 beyond the end of TAG's value.
14494
14495 Reads at or beyond END will not be made. */
14496
14497static unsigned char *
60abdbed 14498display_tag_value (signed int tag,
f6f0e17b
NC
14499 unsigned char * p,
14500 const unsigned char * const end)
14501{
14502 unsigned long val;
14503
14504 if (tag > 0)
14505 printf (" Tag_unknown_%d: ", tag);
14506
14507 if (p >= end)
14508 {
4082ef84 14509 warn (_("<corrupt tag>\n"));
f6f0e17b
NC
14510 }
14511 else if (tag & 1)
14512 {
071436c6
NC
14513 /* PR 17531 file: 027-19978-0.004. */
14514 size_t maxlen = (end - p) - 1;
14515
14516 putchar ('"');
4082ef84
NC
14517 if (maxlen > 0)
14518 {
14519 print_symbol ((int) maxlen, (const char *) p);
14520 p += strnlen ((char *) p, maxlen) + 1;
14521 }
14522 else
14523 {
14524 printf (_("<corrupt string tag>"));
14525 p = (unsigned char *) end;
14526 }
071436c6 14527 printf ("\"\n");
f6f0e17b
NC
14528 }
14529 else
14530 {
14531 unsigned int len;
14532
14533 val = read_uleb128 (p, &len, end);
14534 p += len;
14535 printf ("%ld (0x%lx)\n", val, val);
14536 }
14537
4082ef84 14538 assert (p <= end);
f6f0e17b
NC
14539 return p;
14540}
14541
53a346d8
CZ
14542/* ARC ABI attributes section. */
14543
14544static unsigned char *
14545display_arc_attribute (unsigned char * p,
14546 const unsigned char * const end)
14547{
14548 unsigned int tag;
14549 unsigned int len;
14550 unsigned int val;
14551
14552 tag = read_uleb128 (p, &len, end);
14553 p += len;
14554
14555 switch (tag)
14556 {
14557 case Tag_ARC_PCS_config:
14558 val = read_uleb128 (p, &len, end);
14559 p += len;
14560 printf (" Tag_ARC_PCS_config: ");
14561 switch (val)
14562 {
14563 case 0:
14564 printf (_("Absent/Non standard\n"));
14565 break;
14566 case 1:
14567 printf (_("Bare metal/mwdt\n"));
14568 break;
14569 case 2:
14570 printf (_("Bare metal/newlib\n"));
14571 break;
14572 case 3:
14573 printf (_("Linux/uclibc\n"));
14574 break;
14575 case 4:
14576 printf (_("Linux/glibc\n"));
14577 break;
14578 default:
14579 printf (_("Unknown\n"));
14580 break;
14581 }
14582 break;
14583
14584 case Tag_ARC_CPU_base:
14585 val = read_uleb128 (p, &len, end);
14586 p += len;
14587 printf (" Tag_ARC_CPU_base: ");
14588 switch (val)
14589 {
14590 default:
14591 case TAG_CPU_NONE:
14592 printf (_("Absent\n"));
14593 break;
14594 case TAG_CPU_ARC6xx:
14595 printf ("ARC6xx\n");
14596 break;
14597 case TAG_CPU_ARC7xx:
14598 printf ("ARC7xx\n");
14599 break;
14600 case TAG_CPU_ARCEM:
14601 printf ("ARCEM\n");
14602 break;
14603 case TAG_CPU_ARCHS:
14604 printf ("ARCHS\n");
14605 break;
14606 }
14607 break;
14608
14609 case Tag_ARC_CPU_variation:
14610 val = read_uleb128 (p, &len, end);
14611 p += len;
14612 printf (" Tag_ARC_CPU_variation: ");
14613 switch (val)
14614 {
14615 default:
14616 if (val > 0 && val < 16)
53a346d8 14617 printf ("Core%d\n", val);
d8cbc93b
JL
14618 else
14619 printf ("Unknown\n");
14620 break;
14621
53a346d8
CZ
14622 case 0:
14623 printf (_("Absent\n"));
14624 break;
14625 }
14626 break;
14627
14628 case Tag_ARC_CPU_name:
14629 printf (" Tag_ARC_CPU_name: ");
14630 p = display_tag_value (-1, p, end);
14631 break;
14632
14633 case Tag_ARC_ABI_rf16:
14634 val = read_uleb128 (p, &len, end);
14635 p += len;
14636 printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
14637 break;
14638
14639 case Tag_ARC_ABI_osver:
14640 val = read_uleb128 (p, &len, end);
14641 p += len;
14642 printf (" Tag_ARC_ABI_osver: v%d\n", val);
14643 break;
14644
14645 case Tag_ARC_ABI_pic:
14646 case Tag_ARC_ABI_sda:
14647 val = read_uleb128 (p, &len, end);
14648 p += len;
14649 printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
14650 : " Tag_ARC_ABI_pic: ");
14651 switch (val)
14652 {
14653 case 0:
14654 printf (_("Absent\n"));
14655 break;
14656 case 1:
14657 printf ("MWDT\n");
14658 break;
14659 case 2:
14660 printf ("GNU\n");
14661 break;
14662 default:
14663 printf (_("Unknown\n"));
14664 break;
14665 }
14666 break;
14667
14668 case Tag_ARC_ABI_tls:
14669 val = read_uleb128 (p, &len, end);
14670 p += len;
14671 printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
14672 break;
14673
14674 case Tag_ARC_ABI_enumsize:
14675 val = read_uleb128 (p, &len, end);
14676 p += len;
14677 printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
14678 _("smallest"));
14679 break;
14680
14681 case Tag_ARC_ABI_exceptions:
14682 val = read_uleb128 (p, &len, end);
14683 p += len;
14684 printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
14685 : _("default"));
14686 break;
14687
14688 case Tag_ARC_ABI_double_size:
14689 val = read_uleb128 (p, &len, end);
14690 p += len;
14691 printf (" Tag_ARC_ABI_double_size: %d\n", val);
14692 break;
14693
14694 case Tag_ARC_ISA_config:
14695 printf (" Tag_ARC_ISA_config: ");
14696 p = display_tag_value (-1, p, end);
14697 break;
14698
14699 case Tag_ARC_ISA_apex:
14700 printf (" Tag_ARC_ISA_apex: ");
14701 p = display_tag_value (-1, p, end);
14702 break;
14703
14704 case Tag_ARC_ISA_mpy_option:
14705 val = read_uleb128 (p, &len, end);
14706 p += len;
14707 printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
14708 break;
14709
db1e1b45 14710 case Tag_ARC_ATR_version:
14711 val = read_uleb128 (p, &len, end);
14712 p += len;
14713 printf (" Tag_ARC_ATR_version: %d\n", val);
14714 break;
14715
53a346d8
CZ
14716 default:
14717 return display_tag_value (tag & 1, p, end);
14718 }
14719
14720 return p;
14721}
14722
11c1ff18
PB
14723/* ARM EABI attributes section. */
14724typedef struct
14725{
70e99720 14726 unsigned int tag;
2cf0635d 14727 const char * name;
11c1ff18 14728 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
70e99720 14729 unsigned int type;
2cf0635d 14730 const char ** table;
11c1ff18
PB
14731} arm_attr_public_tag;
14732
2cf0635d 14733static const char * arm_attr_tag_CPU_arch[] =
11c1ff18 14734 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
ced40572 14735 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
031254f2 14736 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
2cf0635d
NC
14737static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
14738static const char * arm_attr_tag_THUMB_ISA_use[] =
4ed7ed8d 14739 {"No", "Thumb-1", "Thumb-2", "Yes"};
75375b3e 14740static const char * arm_attr_tag_FP_arch[] =
bca38921 14741 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
a715796b 14742 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
2cf0635d 14743static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
dd24e3da 14744static const char * arm_attr_tag_Advanced_SIMD_arch[] =
9411fd44
MW
14745 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
14746 "NEON for ARMv8.1"};
2cf0635d 14747static const char * arm_attr_tag_PCS_config[] =
11c1ff18
PB
14748 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
14749 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
2cf0635d 14750static const char * arm_attr_tag_ABI_PCS_R9_use[] =
11c1ff18 14751 {"V6", "SB", "TLS", "Unused"};
2cf0635d 14752static const char * arm_attr_tag_ABI_PCS_RW_data[] =
11c1ff18 14753 {"Absolute", "PC-relative", "SB-relative", "None"};
2cf0635d 14754static const char * arm_attr_tag_ABI_PCS_RO_data[] =
11c1ff18 14755 {"Absolute", "PC-relative", "None"};
2cf0635d 14756static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
11c1ff18 14757 {"None", "direct", "GOT-indirect"};
2cf0635d 14758static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
11c1ff18 14759 {"None", "??? 1", "2", "??? 3", "4"};
2cf0635d
NC
14760static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
14761static const char * arm_attr_tag_ABI_FP_denormal[] =
f5f53991 14762 {"Unused", "Needed", "Sign only"};
2cf0635d
NC
14763static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
14764static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
14765static const char * arm_attr_tag_ABI_FP_number_model[] =
11c1ff18 14766 {"Unused", "Finite", "RTABI", "IEEE 754"};
2cf0635d 14767static const char * arm_attr_tag_ABI_enum_size[] =
11c1ff18 14768 {"Unused", "small", "int", "forced to int"};
2cf0635d 14769static const char * arm_attr_tag_ABI_HardFP_use[] =
99654aaf 14770 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
2cf0635d 14771static const char * arm_attr_tag_ABI_VFP_args[] =
5c294fee 14772 {"AAPCS", "VFP registers", "custom", "compatible"};
2cf0635d 14773static const char * arm_attr_tag_ABI_WMMX_args[] =
11c1ff18 14774 {"AAPCS", "WMMX registers", "custom"};
2cf0635d 14775static const char * arm_attr_tag_ABI_optimization_goals[] =
11c1ff18
PB
14776 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14777 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
2cf0635d 14778static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
11c1ff18
PB
14779 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14780 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
2cf0635d 14781static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
75375b3e 14782static const char * arm_attr_tag_FP_HP_extension[] =
8e79c3df 14783 {"Not Allowed", "Allowed"};
2cf0635d 14784static const char * arm_attr_tag_ABI_FP_16bit_format[] =
8e79c3df 14785 {"None", "IEEE 754", "Alternative Format"};
15afaa63
TP
14786static const char * arm_attr_tag_DSP_extension[] =
14787 {"Follow architecture", "Allowed"};
dd24e3da 14788static const char * arm_attr_tag_MPextension_use[] =
cd21e546
MGD
14789 {"Not Allowed", "Allowed"};
14790static const char * arm_attr_tag_DIV_use[] =
dd24e3da 14791 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
cd21e546 14792 "Allowed in v7-A with integer division extension"};
2cf0635d
NC
14793static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
14794static const char * arm_attr_tag_Virtualization_use[] =
dd24e3da 14795 {"Not Allowed", "TrustZone", "Virtualization Extensions",
cd21e546 14796 "TrustZone and Virtualization Extensions"};
dd24e3da 14797static const char * arm_attr_tag_MPextension_use_legacy[] =
f5f53991 14798 {"Not Allowed", "Allowed"};
11c1ff18 14799
a7ad558c
AV
14800static const char * arm_attr_tag_MVE_arch[] =
14801 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
14802
11c1ff18
PB
14803#define LOOKUP(id, name) \
14804 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
d70c5fc7 14805static arm_attr_public_tag arm_attr_public_tags[] =
11c1ff18
PB
14806{
14807 {4, "CPU_raw_name", 1, NULL},
14808 {5, "CPU_name", 1, NULL},
14809 LOOKUP(6, CPU_arch),
14810 {7, "CPU_arch_profile", 0, NULL},
14811 LOOKUP(8, ARM_ISA_use),
14812 LOOKUP(9, THUMB_ISA_use),
75375b3e 14813 LOOKUP(10, FP_arch),
11c1ff18 14814 LOOKUP(11, WMMX_arch),
f5f53991
AS
14815 LOOKUP(12, Advanced_SIMD_arch),
14816 LOOKUP(13, PCS_config),
11c1ff18
PB
14817 LOOKUP(14, ABI_PCS_R9_use),
14818 LOOKUP(15, ABI_PCS_RW_data),
f5f53991 14819 LOOKUP(16, ABI_PCS_RO_data),
11c1ff18
PB
14820 LOOKUP(17, ABI_PCS_GOT_use),
14821 LOOKUP(18, ABI_PCS_wchar_t),
14822 LOOKUP(19, ABI_FP_rounding),
14823 LOOKUP(20, ABI_FP_denormal),
14824 LOOKUP(21, ABI_FP_exceptions),
14825 LOOKUP(22, ABI_FP_user_exceptions),
14826 LOOKUP(23, ABI_FP_number_model),
75375b3e
MGD
14827 {24, "ABI_align_needed", 0, NULL},
14828 {25, "ABI_align_preserved", 0, NULL},
11c1ff18
PB
14829 LOOKUP(26, ABI_enum_size),
14830 LOOKUP(27, ABI_HardFP_use),
14831 LOOKUP(28, ABI_VFP_args),
14832 LOOKUP(29, ABI_WMMX_args),
14833 LOOKUP(30, ABI_optimization_goals),
14834 LOOKUP(31, ABI_FP_optimization_goals),
8e79c3df 14835 {32, "compatibility", 0, NULL},
f5f53991 14836 LOOKUP(34, CPU_unaligned_access),
75375b3e 14837 LOOKUP(36, FP_HP_extension),
8e79c3df 14838 LOOKUP(38, ABI_FP_16bit_format),
cd21e546
MGD
14839 LOOKUP(42, MPextension_use),
14840 LOOKUP(44, DIV_use),
15afaa63 14841 LOOKUP(46, DSP_extension),
a7ad558c 14842 LOOKUP(48, MVE_arch),
f5f53991
AS
14843 {64, "nodefaults", 0, NULL},
14844 {65, "also_compatible_with", 0, NULL},
14845 LOOKUP(66, T2EE_use),
14846 {67, "conformance", 1, NULL},
14847 LOOKUP(68, Virtualization_use),
cd21e546 14848 LOOKUP(70, MPextension_use_legacy)
11c1ff18
PB
14849};
14850#undef LOOKUP
14851
11c1ff18 14852static unsigned char *
f6f0e17b
NC
14853display_arm_attribute (unsigned char * p,
14854 const unsigned char * const end)
11c1ff18 14855{
70e99720 14856 unsigned int tag;
11c1ff18 14857 unsigned int len;
70e99720 14858 unsigned int val;
2cf0635d 14859 arm_attr_public_tag * attr;
11c1ff18 14860 unsigned i;
70e99720 14861 unsigned int type;
11c1ff18 14862
f6f0e17b 14863 tag = read_uleb128 (p, &len, end);
11c1ff18
PB
14864 p += len;
14865 attr = NULL;
2cf0635d 14866 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
11c1ff18
PB
14867 {
14868 if (arm_attr_public_tags[i].tag == tag)
14869 {
14870 attr = &arm_attr_public_tags[i];
14871 break;
14872 }
14873 }
14874
14875 if (attr)
14876 {
14877 printf (" Tag_%s: ", attr->name);
14878 switch (attr->type)
14879 {
14880 case 0:
14881 switch (tag)
14882 {
14883 case 7: /* Tag_CPU_arch_profile. */
f6f0e17b 14884 val = read_uleb128 (p, &len, end);
11c1ff18
PB
14885 p += len;
14886 switch (val)
14887 {
2b692964
NC
14888 case 0: printf (_("None\n")); break;
14889 case 'A': printf (_("Application\n")); break;
14890 case 'R': printf (_("Realtime\n")); break;
14891 case 'M': printf (_("Microcontroller\n")); break;
14892 case 'S': printf (_("Application or Realtime\n")); break;
11c1ff18
PB
14893 default: printf ("??? (%d)\n", val); break;
14894 }
14895 break;
14896
75375b3e 14897 case 24: /* Tag_align_needed. */
f6f0e17b 14898 val = read_uleb128 (p, &len, end);
75375b3e
MGD
14899 p += len;
14900 switch (val)
14901 {
2b692964
NC
14902 case 0: printf (_("None\n")); break;
14903 case 1: printf (_("8-byte\n")); break;
14904 case 2: printf (_("4-byte\n")); break;
75375b3e
MGD
14905 case 3: printf ("??? 3\n"); break;
14906 default:
14907 if (val <= 12)
dd24e3da 14908 printf (_("8-byte and up to %d-byte extended\n"),
75375b3e
MGD
14909 1 << val);
14910 else
14911 printf ("??? (%d)\n", val);
14912 break;
14913 }
14914 break;
14915
14916 case 25: /* Tag_align_preserved. */
f6f0e17b 14917 val = read_uleb128 (p, &len, end);
75375b3e
MGD
14918 p += len;
14919 switch (val)
14920 {
2b692964
NC
14921 case 0: printf (_("None\n")); break;
14922 case 1: printf (_("8-byte, except leaf SP\n")); break;
14923 case 2: printf (_("8-byte\n")); break;
75375b3e
MGD
14924 case 3: printf ("??? 3\n"); break;
14925 default:
14926 if (val <= 12)
dd24e3da 14927 printf (_("8-byte and up to %d-byte extended\n"),
75375b3e
MGD
14928 1 << val);
14929 else
14930 printf ("??? (%d)\n", val);
14931 break;
14932 }
14933 break;
14934
11c1ff18 14935 case 32: /* Tag_compatibility. */
071436c6 14936 {
071436c6
NC
14937 val = read_uleb128 (p, &len, end);
14938 p += len;
071436c6 14939 printf (_("flag = %d, vendor = "), val);
4082ef84
NC
14940 if (p < end - 1)
14941 {
14942 size_t maxlen = (end - p) - 1;
14943
14944 print_symbol ((int) maxlen, (const char *) p);
14945 p += strnlen ((char *) p, maxlen) + 1;
14946 }
14947 else
14948 {
14949 printf (_("<corrupt>"));
14950 p = (unsigned char *) end;
14951 }
071436c6 14952 putchar ('\n');
071436c6 14953 }
11c1ff18
PB
14954 break;
14955
f5f53991 14956 case 64: /* Tag_nodefaults. */
541a3cbd
NC
14957 /* PR 17531: file: 001-505008-0.01. */
14958 if (p < end)
14959 p++;
2b692964 14960 printf (_("True\n"));
f5f53991
AS
14961 break;
14962
14963 case 65: /* Tag_also_compatible_with. */
f6f0e17b 14964 val = read_uleb128 (p, &len, end);
f5f53991
AS
14965 p += len;
14966 if (val == 6 /* Tag_CPU_arch. */)
14967 {
f6f0e17b 14968 val = read_uleb128 (p, &len, end);
f5f53991 14969 p += len;
071436c6 14970 if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
f5f53991
AS
14971 printf ("??? (%d)\n", val);
14972 else
14973 printf ("%s\n", arm_attr_tag_CPU_arch[val]);
14974 }
14975 else
14976 printf ("???\n");
071436c6
NC
14977 while (p < end && *(p++) != '\0' /* NUL terminator. */)
14978 ;
f5f53991
AS
14979 break;
14980
11c1ff18 14981 default:
bee0ee85
NC
14982 printf (_("<unknown: %d>\n"), tag);
14983 break;
11c1ff18
PB
14984 }
14985 return p;
14986
14987 case 1:
f6f0e17b 14988 return display_tag_value (-1, p, end);
11c1ff18 14989 case 2:
f6f0e17b 14990 return display_tag_value (0, p, end);
11c1ff18
PB
14991
14992 default:
14993 assert (attr->type & 0x80);
f6f0e17b 14994 val = read_uleb128 (p, &len, end);
11c1ff18
PB
14995 p += len;
14996 type = attr->type & 0x7f;
14997 if (val >= type)
14998 printf ("??? (%d)\n", val);
14999 else
15000 printf ("%s\n", attr->table[val]);
15001 return p;
15002 }
15003 }
11c1ff18 15004
f6f0e17b 15005 return display_tag_value (tag, p, end);
11c1ff18
PB
15006}
15007
104d59d1 15008static unsigned char *
60bca95a 15009display_gnu_attribute (unsigned char * p,
60abdbed 15010 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
f6f0e17b 15011 const unsigned char * const end)
104d59d1
JM
15012{
15013 int tag;
15014 unsigned int len;
60abdbed 15015 unsigned int val;
104d59d1 15016
f6f0e17b 15017 tag = read_uleb128 (p, &len, end);
104d59d1
JM
15018 p += len;
15019
15020 /* Tag_compatibility is the only generic GNU attribute defined at
15021 present. */
15022 if (tag == 32)
15023 {
f6f0e17b 15024 val = read_uleb128 (p, &len, end);
104d59d1 15025 p += len;
071436c6
NC
15026
15027 printf (_("flag = %d, vendor = "), val);
f6f0e17b
NC
15028 if (p == end)
15029 {
071436c6 15030 printf (_("<corrupt>\n"));
f6f0e17b
NC
15031 warn (_("corrupt vendor attribute\n"));
15032 }
15033 else
15034 {
4082ef84
NC
15035 if (p < end - 1)
15036 {
15037 size_t maxlen = (end - p) - 1;
071436c6 15038
4082ef84
NC
15039 print_symbol ((int) maxlen, (const char *) p);
15040 p += strnlen ((char *) p, maxlen) + 1;
15041 }
15042 else
15043 {
15044 printf (_("<corrupt>"));
15045 p = (unsigned char *) end;
15046 }
071436c6 15047 putchar ('\n');
f6f0e17b 15048 }
104d59d1
JM
15049 return p;
15050 }
15051
15052 if ((tag & 2) == 0 && display_proc_gnu_attribute)
f6f0e17b 15053 return display_proc_gnu_attribute (p, tag, end);
104d59d1 15054
f6f0e17b 15055 return display_tag_value (tag, p, end);
104d59d1
JM
15056}
15057
34c8bcba 15058static unsigned char *
f6f0e17b 15059display_power_gnu_attribute (unsigned char * p,
60abdbed 15060 unsigned int tag,
f6f0e17b 15061 const unsigned char * const end)
34c8bcba 15062{
34c8bcba 15063 unsigned int len;
005d79fd 15064 unsigned int val;
34c8bcba
JM
15065
15066 if (tag == Tag_GNU_Power_ABI_FP)
15067 {
f6f0e17b 15068 val = read_uleb128 (p, &len, end);
34c8bcba
JM
15069 p += len;
15070 printf (" Tag_GNU_Power_ABI_FP: ");
005d79fd
AM
15071 if (len == 0)
15072 {
15073 printf (_("<corrupt>\n"));
15074 return p;
15075 }
60bca95a 15076
005d79fd
AM
15077 if (val > 15)
15078 printf ("(%#x), ", val);
15079
15080 switch (val & 3)
34c8bcba
JM
15081 {
15082 case 0:
005d79fd 15083 printf (_("unspecified hard/soft float, "));
34c8bcba
JM
15084 break;
15085 case 1:
005d79fd 15086 printf (_("hard float, "));
34c8bcba
JM
15087 break;
15088 case 2:
005d79fd 15089 printf (_("soft float, "));
34c8bcba 15090 break;
3c7b9897 15091 case 3:
005d79fd 15092 printf (_("single-precision hard float, "));
3c7b9897 15093 break;
005d79fd
AM
15094 }
15095
15096 switch (val & 0xC)
15097 {
15098 case 0:
15099 printf (_("unspecified long double\n"));
15100 break;
15101 case 4:
15102 printf (_("128-bit IBM long double\n"));
15103 break;
15104 case 8:
15105 printf (_("64-bit long double\n"));
15106 break;
15107 case 12:
15108 printf (_("128-bit IEEE long double\n"));
34c8bcba
JM
15109 break;
15110 }
15111 return p;
005d79fd 15112 }
34c8bcba 15113
c6e65352
DJ
15114 if (tag == Tag_GNU_Power_ABI_Vector)
15115 {
f6f0e17b 15116 val = read_uleb128 (p, &len, end);
c6e65352
DJ
15117 p += len;
15118 printf (" Tag_GNU_Power_ABI_Vector: ");
005d79fd
AM
15119 if (len == 0)
15120 {
15121 printf (_("<corrupt>\n"));
15122 return p;
15123 }
15124
15125 if (val > 3)
15126 printf ("(%#x), ", val);
15127
15128 switch (val & 3)
c6e65352
DJ
15129 {
15130 case 0:
005d79fd 15131 printf (_("unspecified\n"));
c6e65352
DJ
15132 break;
15133 case 1:
005d79fd 15134 printf (_("generic\n"));
c6e65352
DJ
15135 break;
15136 case 2:
15137 printf ("AltiVec\n");
15138 break;
15139 case 3:
15140 printf ("SPE\n");
15141 break;
c6e65352
DJ
15142 }
15143 return p;
005d79fd 15144 }
c6e65352 15145
f82e0623
NF
15146 if (tag == Tag_GNU_Power_ABI_Struct_Return)
15147 {
005d79fd
AM
15148 val = read_uleb128 (p, &len, end);
15149 p += len;
15150 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
15151 if (len == 0)
f6f0e17b 15152 {
005d79fd 15153 printf (_("<corrupt>\n"));
f6f0e17b
NC
15154 return p;
15155 }
0b4362b0 15156
005d79fd
AM
15157 if (val > 2)
15158 printf ("(%#x), ", val);
15159
15160 switch (val & 3)
15161 {
15162 case 0:
15163 printf (_("unspecified\n"));
15164 break;
15165 case 1:
15166 printf ("r3/r4\n");
15167 break;
15168 case 2:
15169 printf (_("memory\n"));
15170 break;
15171 case 3:
15172 printf ("???\n");
15173 break;
15174 }
f82e0623
NF
15175 return p;
15176 }
15177
f6f0e17b 15178 return display_tag_value (tag & 1, p, end);
34c8bcba
JM
15179}
15180
643f7afb
AK
15181static unsigned char *
15182display_s390_gnu_attribute (unsigned char * p,
60abdbed 15183 unsigned int tag,
643f7afb
AK
15184 const unsigned char * const end)
15185{
15186 unsigned int len;
15187 int val;
15188
15189 if (tag == Tag_GNU_S390_ABI_Vector)
15190 {
15191 val = read_uleb128 (p, &len, end);
15192 p += len;
15193 printf (" Tag_GNU_S390_ABI_Vector: ");
15194
15195 switch (val)
15196 {
15197 case 0:
15198 printf (_("any\n"));
15199 break;
15200 case 1:
15201 printf (_("software\n"));
15202 break;
15203 case 2:
15204 printf (_("hardware\n"));
15205 break;
15206 default:
15207 printf ("??? (%d)\n", val);
15208 break;
15209 }
15210 return p;
15211 }
15212
15213 return display_tag_value (tag & 1, p, end);
15214}
15215
9e8c70f9 15216static void
60abdbed 15217display_sparc_hwcaps (unsigned int mask)
9e8c70f9
DM
15218{
15219 if (mask)
15220 {
32ec8896 15221 bfd_boolean first = TRUE;
071436c6 15222
9e8c70f9 15223 if (mask & ELF_SPARC_HWCAP_MUL32)
32ec8896 15224 fputs ("mul32", stdout), first = FALSE;
9e8c70f9 15225 if (mask & ELF_SPARC_HWCAP_DIV32)
32ec8896 15226 printf ("%sdiv32", first ? "" : "|"), first = FALSE;
9e8c70f9 15227 if (mask & ELF_SPARC_HWCAP_FSMULD)
32ec8896 15228 printf ("%sfsmuld", first ? "" : "|"), first = FALSE;
9e8c70f9 15229 if (mask & ELF_SPARC_HWCAP_V8PLUS)
32ec8896 15230 printf ("%sv8plus", first ? "" : "|"), first = FALSE;
9e8c70f9 15231 if (mask & ELF_SPARC_HWCAP_POPC)
32ec8896 15232 printf ("%spopc", first ? "" : "|"), first = FALSE;
9e8c70f9 15233 if (mask & ELF_SPARC_HWCAP_VIS)
32ec8896 15234 printf ("%svis", first ? "" : "|"), first = FALSE;
9e8c70f9 15235 if (mask & ELF_SPARC_HWCAP_VIS2)
32ec8896 15236 printf ("%svis2", first ? "" : "|"), first = FALSE;
9e8c70f9 15237 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
32ec8896 15238 printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE;
9e8c70f9 15239 if (mask & ELF_SPARC_HWCAP_FMAF)
32ec8896 15240 printf ("%sfmaf", first ? "" : "|"), first = FALSE;
9e8c70f9 15241 if (mask & ELF_SPARC_HWCAP_VIS3)
32ec8896 15242 printf ("%svis3", first ? "" : "|"), first = FALSE;
9e8c70f9 15243 if (mask & ELF_SPARC_HWCAP_HPC)
32ec8896 15244 printf ("%shpc", first ? "" : "|"), first = FALSE;
9e8c70f9 15245 if (mask & ELF_SPARC_HWCAP_RANDOM)
32ec8896 15246 printf ("%srandom", first ? "" : "|"), first = FALSE;
9e8c70f9 15247 if (mask & ELF_SPARC_HWCAP_TRANS)
32ec8896 15248 printf ("%strans", first ? "" : "|"), first = FALSE;
9e8c70f9 15249 if (mask & ELF_SPARC_HWCAP_FJFMAU)
32ec8896 15250 printf ("%sfjfmau", first ? "" : "|"), first = FALSE;
9e8c70f9 15251 if (mask & ELF_SPARC_HWCAP_IMA)
32ec8896 15252 printf ("%sima", first ? "" : "|"), first = FALSE;
9e8c70f9 15253 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
32ec8896 15254 printf ("%scspare", first ? "" : "|"), first = FALSE;
9e8c70f9
DM
15255 }
15256 else
071436c6
NC
15257 fputc ('0', stdout);
15258 fputc ('\n', stdout);
9e8c70f9
DM
15259}
15260
3d68f91c 15261static void
60abdbed 15262display_sparc_hwcaps2 (unsigned int mask)
3d68f91c
JM
15263{
15264 if (mask)
15265 {
32ec8896 15266 bfd_boolean first = TRUE;
071436c6 15267
3d68f91c 15268 if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
32ec8896 15269 fputs ("fjathplus", stdout), first = FALSE;
3d68f91c 15270 if (mask & ELF_SPARC_HWCAP2_VIS3B)
32ec8896 15271 printf ("%svis3b", first ? "" : "|"), first = FALSE;
3d68f91c 15272 if (mask & ELF_SPARC_HWCAP2_ADP)
32ec8896 15273 printf ("%sadp", first ? "" : "|"), first = FALSE;
3d68f91c 15274 if (mask & ELF_SPARC_HWCAP2_SPARC5)
32ec8896 15275 printf ("%ssparc5", first ? "" : "|"), first = FALSE;
3d68f91c 15276 if (mask & ELF_SPARC_HWCAP2_MWAIT)
32ec8896 15277 printf ("%smwait", first ? "" : "|"), first = FALSE;
3d68f91c 15278 if (mask & ELF_SPARC_HWCAP2_XMPMUL)
32ec8896 15279 printf ("%sxmpmul", first ? "" : "|"), first = FALSE;
3d68f91c 15280 if (mask & ELF_SPARC_HWCAP2_XMONT)
32ec8896 15281 printf ("%sxmont2", first ? "" : "|"), first = FALSE;
3d68f91c 15282 if (mask & ELF_SPARC_HWCAP2_NSEC)
32ec8896 15283 printf ("%snsec", first ? "" : "|"), first = FALSE;
3d68f91c 15284 if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
32ec8896 15285 printf ("%sfjathhpc", first ? "" : "|"), first = FALSE;
3d68f91c 15286 if (mask & ELF_SPARC_HWCAP2_FJDES)
32ec8896 15287 printf ("%sfjdes", first ? "" : "|"), first = FALSE;
3d68f91c 15288 if (mask & ELF_SPARC_HWCAP2_FJAES)
32ec8896 15289 printf ("%sfjaes", first ? "" : "|"), first = FALSE;
3d68f91c
JM
15290 }
15291 else
071436c6
NC
15292 fputc ('0', stdout);
15293 fputc ('\n', stdout);
3d68f91c
JM
15294}
15295
9e8c70f9 15296static unsigned char *
f6f0e17b 15297display_sparc_gnu_attribute (unsigned char * p,
60abdbed 15298 unsigned int tag,
f6f0e17b 15299 const unsigned char * const end)
9e8c70f9 15300{
3d68f91c
JM
15301 unsigned int len;
15302 int val;
15303
9e8c70f9
DM
15304 if (tag == Tag_GNU_Sparc_HWCAPS)
15305 {
f6f0e17b 15306 val = read_uleb128 (p, &len, end);
9e8c70f9
DM
15307 p += len;
15308 printf (" Tag_GNU_Sparc_HWCAPS: ");
9e8c70f9
DM
15309 display_sparc_hwcaps (val);
15310 return p;
3d68f91c
JM
15311 }
15312 if (tag == Tag_GNU_Sparc_HWCAPS2)
15313 {
15314 val = read_uleb128 (p, &len, end);
15315 p += len;
15316 printf (" Tag_GNU_Sparc_HWCAPS2: ");
15317 display_sparc_hwcaps2 (val);
15318 return p;
15319 }
9e8c70f9 15320
f6f0e17b 15321 return display_tag_value (tag, p, end);
9e8c70f9
DM
15322}
15323
351cdf24 15324static void
32ec8896 15325print_mips_fp_abi_value (unsigned int val)
351cdf24
MF
15326{
15327 switch (val)
15328 {
15329 case Val_GNU_MIPS_ABI_FP_ANY:
15330 printf (_("Hard or soft float\n"));
15331 break;
15332 case Val_GNU_MIPS_ABI_FP_DOUBLE:
15333 printf (_("Hard float (double precision)\n"));
15334 break;
15335 case Val_GNU_MIPS_ABI_FP_SINGLE:
15336 printf (_("Hard float (single precision)\n"));
15337 break;
15338 case Val_GNU_MIPS_ABI_FP_SOFT:
15339 printf (_("Soft float\n"));
15340 break;
15341 case Val_GNU_MIPS_ABI_FP_OLD_64:
15342 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
15343 break;
15344 case Val_GNU_MIPS_ABI_FP_XX:
15345 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
15346 break;
15347 case Val_GNU_MIPS_ABI_FP_64:
15348 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
15349 break;
15350 case Val_GNU_MIPS_ABI_FP_64A:
15351 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
15352 break;
3350cc01
CM
15353 case Val_GNU_MIPS_ABI_FP_NAN2008:
15354 printf (_("NaN 2008 compatibility\n"));
15355 break;
351cdf24
MF
15356 default:
15357 printf ("??? (%d)\n", val);
15358 break;
15359 }
15360}
15361
2cf19d5c 15362static unsigned char *
f6f0e17b 15363display_mips_gnu_attribute (unsigned char * p,
60abdbed 15364 unsigned int tag,
f6f0e17b 15365 const unsigned char * const end)
2cf19d5c 15366{
2cf19d5c
JM
15367 if (tag == Tag_GNU_MIPS_ABI_FP)
15368 {
f6f0e17b 15369 unsigned int len;
32ec8896 15370 unsigned int val;
f6f0e17b
NC
15371
15372 val = read_uleb128 (p, &len, end);
2cf19d5c
JM
15373 p += len;
15374 printf (" Tag_GNU_MIPS_ABI_FP: ");
60bca95a 15375
351cdf24
MF
15376 print_mips_fp_abi_value (val);
15377
2cf19d5c
JM
15378 return p;
15379 }
15380
a9f58168
CF
15381 if (tag == Tag_GNU_MIPS_ABI_MSA)
15382 {
15383 unsigned int len;
32ec8896 15384 unsigned int val;
a9f58168
CF
15385
15386 val = read_uleb128 (p, &len, end);
15387 p += len;
15388 printf (" Tag_GNU_MIPS_ABI_MSA: ");
15389
15390 switch (val)
15391 {
15392 case Val_GNU_MIPS_ABI_MSA_ANY:
15393 printf (_("Any MSA or not\n"));
15394 break;
15395 case Val_GNU_MIPS_ABI_MSA_128:
15396 printf (_("128-bit MSA\n"));
15397 break;
15398 default:
15399 printf ("??? (%d)\n", val);
15400 break;
15401 }
15402 return p;
15403 }
15404
f6f0e17b 15405 return display_tag_value (tag & 1, p, end);
2cf19d5c
JM
15406}
15407
59e6276b 15408static unsigned char *
f6f0e17b
NC
15409display_tic6x_attribute (unsigned char * p,
15410 const unsigned char * const end)
59e6276b 15411{
60abdbed 15412 unsigned int tag;
59e6276b
JM
15413 unsigned int len;
15414 int val;
15415
f6f0e17b 15416 tag = read_uleb128 (p, &len, end);
59e6276b
JM
15417 p += len;
15418
15419 switch (tag)
15420 {
75fa6dc1 15421 case Tag_ISA:
f6f0e17b 15422 val = read_uleb128 (p, &len, end);
59e6276b 15423 p += len;
75fa6dc1 15424 printf (" Tag_ISA: ");
59e6276b
JM
15425
15426 switch (val)
15427 {
75fa6dc1 15428 case C6XABI_Tag_ISA_none:
59e6276b
JM
15429 printf (_("None\n"));
15430 break;
75fa6dc1 15431 case C6XABI_Tag_ISA_C62X:
59e6276b
JM
15432 printf ("C62x\n");
15433 break;
75fa6dc1 15434 case C6XABI_Tag_ISA_C67X:
59e6276b
JM
15435 printf ("C67x\n");
15436 break;
75fa6dc1 15437 case C6XABI_Tag_ISA_C67XP:
59e6276b
JM
15438 printf ("C67x+\n");
15439 break;
75fa6dc1 15440 case C6XABI_Tag_ISA_C64X:
59e6276b
JM
15441 printf ("C64x\n");
15442 break;
75fa6dc1 15443 case C6XABI_Tag_ISA_C64XP:
59e6276b
JM
15444 printf ("C64x+\n");
15445 break;
75fa6dc1 15446 case C6XABI_Tag_ISA_C674X:
59e6276b
JM
15447 printf ("C674x\n");
15448 break;
15449 default:
15450 printf ("??? (%d)\n", val);
15451 break;
15452 }
15453 return p;
15454
87779176 15455 case Tag_ABI_wchar_t:
f6f0e17b 15456 val = read_uleb128 (p, &len, end);
87779176
JM
15457 p += len;
15458 printf (" Tag_ABI_wchar_t: ");
15459 switch (val)
15460 {
15461 case 0:
15462 printf (_("Not used\n"));
15463 break;
15464 case 1:
15465 printf (_("2 bytes\n"));
15466 break;
15467 case 2:
15468 printf (_("4 bytes\n"));
15469 break;
15470 default:
15471 printf ("??? (%d)\n", val);
15472 break;
15473 }
15474 return p;
15475
15476 case Tag_ABI_stack_align_needed:
f6f0e17b 15477 val = read_uleb128 (p, &len, end);
87779176
JM
15478 p += len;
15479 printf (" Tag_ABI_stack_align_needed: ");
15480 switch (val)
15481 {
15482 case 0:
15483 printf (_("8-byte\n"));
15484 break;
15485 case 1:
15486 printf (_("16-byte\n"));
15487 break;
15488 default:
15489 printf ("??? (%d)\n", val);
15490 break;
15491 }
15492 return p;
15493
15494 case Tag_ABI_stack_align_preserved:
f6f0e17b 15495 val = read_uleb128 (p, &len, end);
87779176
JM
15496 p += len;
15497 printf (" Tag_ABI_stack_align_preserved: ");
15498 switch (val)
15499 {
15500 case 0:
15501 printf (_("8-byte\n"));
15502 break;
15503 case 1:
15504 printf (_("16-byte\n"));
15505 break;
15506 default:
15507 printf ("??? (%d)\n", val);
15508 break;
15509 }
15510 return p;
15511
b5593623 15512 case Tag_ABI_DSBT:
f6f0e17b 15513 val = read_uleb128 (p, &len, end);
b5593623
JM
15514 p += len;
15515 printf (" Tag_ABI_DSBT: ");
15516 switch (val)
15517 {
15518 case 0:
15519 printf (_("DSBT addressing not used\n"));
15520 break;
15521 case 1:
15522 printf (_("DSBT addressing used\n"));
15523 break;
15524 default:
15525 printf ("??? (%d)\n", val);
15526 break;
15527 }
15528 return p;
15529
87779176 15530 case Tag_ABI_PID:
f6f0e17b 15531 val = read_uleb128 (p, &len, end);
87779176
JM
15532 p += len;
15533 printf (" Tag_ABI_PID: ");
15534 switch (val)
15535 {
15536 case 0:
15537 printf (_("Data addressing position-dependent\n"));
15538 break;
15539 case 1:
15540 printf (_("Data addressing position-independent, GOT near DP\n"));
15541 break;
15542 case 2:
15543 printf (_("Data addressing position-independent, GOT far from DP\n"));
15544 break;
15545 default:
15546 printf ("??? (%d)\n", val);
15547 break;
15548 }
15549 return p;
15550
15551 case Tag_ABI_PIC:
f6f0e17b 15552 val = read_uleb128 (p, &len, end);
87779176
JM
15553 p += len;
15554 printf (" Tag_ABI_PIC: ");
15555 switch (val)
15556 {
15557 case 0:
15558 printf (_("Code addressing position-dependent\n"));
15559 break;
15560 case 1:
15561 printf (_("Code addressing position-independent\n"));
15562 break;
15563 default:
15564 printf ("??? (%d)\n", val);
15565 break;
15566 }
15567 return p;
15568
15569 case Tag_ABI_array_object_alignment:
f6f0e17b 15570 val = read_uleb128 (p, &len, end);
87779176
JM
15571 p += len;
15572 printf (" Tag_ABI_array_object_alignment: ");
15573 switch (val)
15574 {
15575 case 0:
15576 printf (_("8-byte\n"));
15577 break;
15578 case 1:
15579 printf (_("4-byte\n"));
15580 break;
15581 case 2:
15582 printf (_("16-byte\n"));
15583 break;
15584 default:
15585 printf ("??? (%d)\n", val);
15586 break;
15587 }
15588 return p;
15589
15590 case Tag_ABI_array_object_align_expected:
f6f0e17b 15591 val = read_uleb128 (p, &len, end);
87779176
JM
15592 p += len;
15593 printf (" Tag_ABI_array_object_align_expected: ");
15594 switch (val)
15595 {
15596 case 0:
15597 printf (_("8-byte\n"));
15598 break;
15599 case 1:
15600 printf (_("4-byte\n"));
15601 break;
15602 case 2:
15603 printf (_("16-byte\n"));
15604 break;
15605 default:
15606 printf ("??? (%d)\n", val);
15607 break;
15608 }
15609 return p;
15610
3cbd1c06 15611 case Tag_ABI_compatibility:
071436c6 15612 {
071436c6
NC
15613 val = read_uleb128 (p, &len, end);
15614 p += len;
15615 printf (" Tag_ABI_compatibility: ");
071436c6 15616 printf (_("flag = %d, vendor = "), val);
4082ef84
NC
15617 if (p < end - 1)
15618 {
15619 size_t maxlen = (end - p) - 1;
15620
15621 print_symbol ((int) maxlen, (const char *) p);
15622 p += strnlen ((char *) p, maxlen) + 1;
15623 }
15624 else
15625 {
15626 printf (_("<corrupt>"));
15627 p = (unsigned char *) end;
15628 }
071436c6 15629 putchar ('\n');
071436c6
NC
15630 return p;
15631 }
87779176
JM
15632
15633 case Tag_ABI_conformance:
071436c6 15634 {
4082ef84
NC
15635 printf (" Tag_ABI_conformance: \"");
15636 if (p < end - 1)
15637 {
15638 size_t maxlen = (end - p) - 1;
071436c6 15639
4082ef84
NC
15640 print_symbol ((int) maxlen, (const char *) p);
15641 p += strnlen ((char *) p, maxlen) + 1;
15642 }
15643 else
15644 {
15645 printf (_("<corrupt>"));
15646 p = (unsigned char *) end;
15647 }
071436c6 15648 printf ("\"\n");
071436c6
NC
15649 return p;
15650 }
59e6276b
JM
15651 }
15652
f6f0e17b
NC
15653 return display_tag_value (tag, p, end);
15654}
59e6276b 15655
f6f0e17b 15656static void
60abdbed 15657display_raw_attribute (unsigned char * p, unsigned char const * const end)
f6f0e17b
NC
15658{
15659 unsigned long addr = 0;
15660 size_t bytes = end - p;
15661
feceaa59 15662 assert (end >= p);
f6f0e17b 15663 while (bytes)
87779176 15664 {
f6f0e17b
NC
15665 int j;
15666 int k;
15667 int lbytes = (bytes > 16 ? 16 : bytes);
15668
15669 printf (" 0x%8.8lx ", addr);
15670
15671 for (j = 0; j < 16; j++)
15672 {
15673 if (j < lbytes)
15674 printf ("%2.2x", p[j]);
15675 else
15676 printf (" ");
15677
15678 if ((j & 3) == 3)
15679 printf (" ");
15680 }
15681
15682 for (j = 0; j < lbytes; j++)
15683 {
15684 k = p[j];
15685 if (k >= ' ' && k < 0x7f)
15686 printf ("%c", k);
15687 else
15688 printf (".");
15689 }
15690
15691 putchar ('\n');
15692
15693 p += lbytes;
15694 bytes -= lbytes;
15695 addr += lbytes;
87779176 15696 }
59e6276b 15697
f6f0e17b 15698 putchar ('\n');
59e6276b
JM
15699}
15700
13761a11
NC
15701static unsigned char *
15702display_msp430x_attribute (unsigned char * p,
15703 const unsigned char * const end)
15704{
15705 unsigned int len;
60abdbed
NC
15706 unsigned int val;
15707 unsigned int tag;
13761a11
NC
15708
15709 tag = read_uleb128 (p, & len, end);
15710 p += len;
0b4362b0 15711
13761a11
NC
15712 switch (tag)
15713 {
15714 case OFBA_MSPABI_Tag_ISA:
15715 val = read_uleb128 (p, &len, end);
15716 p += len;
15717 printf (" Tag_ISA: ");
15718 switch (val)
15719 {
15720 case 0: printf (_("None\n")); break;
15721 case 1: printf (_("MSP430\n")); break;
15722 case 2: printf (_("MSP430X\n")); break;
15723 default: printf ("??? (%d)\n", val); break;
15724 }
15725 break;
15726
15727 case OFBA_MSPABI_Tag_Code_Model:
15728 val = read_uleb128 (p, &len, end);
15729 p += len;
15730 printf (" Tag_Code_Model: ");
15731 switch (val)
15732 {
15733 case 0: printf (_("None\n")); break;
15734 case 1: printf (_("Small\n")); break;
15735 case 2: printf (_("Large\n")); break;
15736 default: printf ("??? (%d)\n", val); break;
15737 }
15738 break;
15739
15740 case OFBA_MSPABI_Tag_Data_Model:
15741 val = read_uleb128 (p, &len, end);
15742 p += len;
15743 printf (" Tag_Data_Model: ");
15744 switch (val)
15745 {
15746 case 0: printf (_("None\n")); break;
15747 case 1: printf (_("Small\n")); break;
15748 case 2: printf (_("Large\n")); break;
15749 case 3: printf (_("Restricted Large\n")); break;
15750 default: printf ("??? (%d)\n", val); break;
15751 }
15752 break;
15753
15754 default:
15755 printf (_(" <unknown tag %d>: "), tag);
15756
15757 if (tag & 1)
15758 {
071436c6 15759 putchar ('"');
4082ef84
NC
15760 if (p < end - 1)
15761 {
15762 size_t maxlen = (end - p) - 1;
15763
15764 print_symbol ((int) maxlen, (const char *) p);
15765 p += strnlen ((char *) p, maxlen) + 1;
15766 }
15767 else
15768 {
15769 printf (_("<corrupt>"));
15770 p = (unsigned char *) end;
15771 }
071436c6 15772 printf ("\"\n");
13761a11
NC
15773 }
15774 else
15775 {
15776 val = read_uleb128 (p, &len, end);
15777 p += len;
15778 printf ("%d (0x%x)\n", val, val);
15779 }
15780 break;
15781 }
15782
4082ef84 15783 assert (p <= end);
13761a11
NC
15784 return p;
15785}
15786
c0ea7c52
JL
15787static unsigned char *
15788display_msp430_gnu_attribute (unsigned char * p,
15789 unsigned int tag,
15790 const unsigned char * const end)
15791{
15792 if (tag == Tag_GNU_MSP430_Data_Region)
15793 {
15794 unsigned int len;
15795 int val;
15796
15797 val = read_uleb128 (p, &len, end);
15798 p += len;
15799 printf (" Tag_GNU_MSP430_Data_Region: ");
15800
15801 switch (val)
15802 {
15803 case Val_GNU_MSP430_Data_Region_Any:
15804 printf (_("Any Region\n"));
15805 break;
15806 case Val_GNU_MSP430_Data_Region_Lower:
15807 printf (_("Lower Region Only\n"));
15808 break;
15809 default:
15810 printf ("??? (%d)\n", val);
15811 }
15812 return p;
15813 }
15814 return display_tag_value (tag & 1, p, end);
15815}
15816
2dc8dd17
JW
15817struct riscv_attr_tag_t {
15818 const char *name;
15819 int tag;
15820};
15821
15822static struct riscv_attr_tag_t riscv_attr_tag[] =
15823{
15824#define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
15825 T(arch),
15826 T(priv_spec),
15827 T(priv_spec_minor),
15828 T(priv_spec_revision),
15829 T(unaligned_access),
15830 T(stack_align),
15831#undef T
15832};
15833
15834static unsigned char *
15835display_riscv_attribute (unsigned char *p,
15836 const unsigned char * const end)
15837{
15838 unsigned int len;
15839 int val;
15840 int tag;
15841 struct riscv_attr_tag_t *attr = NULL;
15842 unsigned i;
15843
15844 tag = read_uleb128 (p, &len, end);
15845 p += len;
15846
15847 /* Find the name of attribute. */
15848 for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++)
15849 {
15850 if (riscv_attr_tag[i].tag == tag)
15851 {
15852 attr = &riscv_attr_tag[i];
15853 break;
15854 }
15855 }
15856
15857 if (attr)
15858 printf (" %s: ", attr->name);
15859 else
15860 return display_tag_value (tag, p, end);
15861
15862 switch (tag)
15863 {
15864 case Tag_RISCV_priv_spec:
15865 case Tag_RISCV_priv_spec_minor:
15866 case Tag_RISCV_priv_spec_revision:
15867 val = read_uleb128 (p, &len, end);
15868 p += len;
15869 printf (_("%d\n"), val);
15870 break;
15871 case Tag_RISCV_unaligned_access:
15872 val = read_uleb128 (p, &len, end);
15873 p += len;
15874 switch (val)
15875 {
15876 case 0:
15877 printf (_("No unaligned access\n"));
15878 break;
15879 case 1:
15880 printf (_("Unaligned access\n"));
15881 break;
15882 }
15883 break;
15884 case Tag_RISCV_stack_align:
15885 val = read_uleb128 (p, &len, end);
15886 p += len;
15887 printf (_("%d-bytes\n"), val);
15888 break;
15889 case Tag_RISCV_arch:
15890 p = display_tag_value (-1, p, end);
15891 break;
15892 default:
15893 return display_tag_value (tag, p, end);
15894 }
15895
15896 return p;
15897}
15898
32ec8896 15899static bfd_boolean
dda8d76d 15900process_attributes (Filedata * filedata,
60bca95a 15901 const char * public_name,
104d59d1 15902 unsigned int proc_type,
f6f0e17b 15903 unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
60abdbed 15904 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
11c1ff18 15905{
2cf0635d 15906 Elf_Internal_Shdr * sect;
11c1ff18 15907 unsigned i;
32ec8896 15908 bfd_boolean res = TRUE;
11c1ff18
PB
15909
15910 /* Find the section header so that we get the size. */
dda8d76d
NC
15911 for (i = 0, sect = filedata->section_headers;
15912 i < filedata->file_header.e_shnum;
11c1ff18
PB
15913 i++, sect++)
15914 {
071436c6
NC
15915 unsigned char * contents;
15916 unsigned char * p;
15917
104d59d1 15918 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
11c1ff18
PB
15919 continue;
15920
dda8d76d 15921 contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1,
3f5e193b 15922 sect->sh_size, _("attributes"));
60bca95a 15923 if (contents == NULL)
32ec8896
NC
15924 {
15925 res = FALSE;
15926 continue;
15927 }
60bca95a 15928
11c1ff18 15929 p = contents;
60abdbed
NC
15930 /* The first character is the version of the attributes.
15931 Currently only version 1, (aka 'A') is recognised here. */
15932 if (*p != 'A')
32ec8896
NC
15933 {
15934 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
15935 res = FALSE;
15936 }
60abdbed 15937 else
11c1ff18 15938 {
071436c6
NC
15939 bfd_vma section_len;
15940
15941 section_len = sect->sh_size - 1;
11c1ff18 15942 p++;
60bca95a 15943
071436c6 15944 while (section_len > 0)
11c1ff18 15945 {
071436c6 15946 bfd_vma attr_len;
e9847026 15947 unsigned int namelen;
11c1ff18 15948 bfd_boolean public_section;
104d59d1 15949 bfd_boolean gnu_section;
11c1ff18 15950
071436c6 15951 if (section_len <= 4)
e0a31db1
NC
15952 {
15953 error (_("Tag section ends prematurely\n"));
32ec8896 15954 res = FALSE;
e0a31db1
NC
15955 break;
15956 }
071436c6 15957 attr_len = byte_get (p, 4);
11c1ff18 15958 p += 4;
60bca95a 15959
071436c6 15960 if (attr_len > section_len)
11c1ff18 15961 {
071436c6
NC
15962 error (_("Bad attribute length (%u > %u)\n"),
15963 (unsigned) attr_len, (unsigned) section_len);
15964 attr_len = section_len;
32ec8896 15965 res = FALSE;
11c1ff18 15966 }
74e1a04b 15967 /* PR 17531: file: 001-101425-0.004 */
071436c6 15968 else if (attr_len < 5)
74e1a04b 15969 {
071436c6 15970 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
32ec8896 15971 res = FALSE;
74e1a04b
NC
15972 break;
15973 }
e9847026 15974
071436c6
NC
15975 section_len -= attr_len;
15976 attr_len -= 4;
15977
15978 namelen = strnlen ((char *) p, attr_len) + 1;
15979 if (namelen == 0 || namelen >= attr_len)
e9847026
NC
15980 {
15981 error (_("Corrupt attribute section name\n"));
32ec8896 15982 res = FALSE;
e9847026
NC
15983 break;
15984 }
15985
071436c6
NC
15986 printf (_("Attribute Section: "));
15987 print_symbol (INT_MAX, (const char *) p);
15988 putchar ('\n');
60bca95a
NC
15989
15990 if (public_name && streq ((char *) p, public_name))
11c1ff18
PB
15991 public_section = TRUE;
15992 else
15993 public_section = FALSE;
60bca95a
NC
15994
15995 if (streq ((char *) p, "gnu"))
104d59d1
JM
15996 gnu_section = TRUE;
15997 else
15998 gnu_section = FALSE;
60bca95a 15999
11c1ff18 16000 p += namelen;
071436c6 16001 attr_len -= namelen;
e0a31db1 16002
071436c6 16003 while (attr_len > 0 && p < contents + sect->sh_size)
11c1ff18 16004 {
e0a31db1 16005 int tag;
11c1ff18
PB
16006 int val;
16007 bfd_vma size;
071436c6 16008 unsigned char * end;
60bca95a 16009
e0a31db1 16010 /* PR binutils/17531: Safe handling of corrupt files. */
071436c6 16011 if (attr_len < 6)
e0a31db1
NC
16012 {
16013 error (_("Unused bytes at end of section\n"));
32ec8896 16014 res = FALSE;
e0a31db1
NC
16015 section_len = 0;
16016 break;
16017 }
16018
16019 tag = *(p++);
11c1ff18 16020 size = byte_get (p, 4);
071436c6 16021 if (size > attr_len)
11c1ff18 16022 {
e9847026 16023 error (_("Bad subsection length (%u > %u)\n"),
071436c6 16024 (unsigned) size, (unsigned) attr_len);
32ec8896 16025 res = FALSE;
071436c6 16026 size = attr_len;
11c1ff18 16027 }
e0a31db1
NC
16028 /* PR binutils/17531: Safe handling of corrupt files. */
16029 if (size < 6)
16030 {
16031 error (_("Bad subsection length (%u < 6)\n"),
16032 (unsigned) size);
32ec8896 16033 res = FALSE;
e0a31db1
NC
16034 section_len = 0;
16035 break;
16036 }
60bca95a 16037
071436c6 16038 attr_len -= size;
11c1ff18 16039 end = p + size - 1;
071436c6 16040 assert (end <= contents + sect->sh_size);
11c1ff18 16041 p += 4;
60bca95a 16042
11c1ff18
PB
16043 switch (tag)
16044 {
16045 case 1:
2b692964 16046 printf (_("File Attributes\n"));
11c1ff18
PB
16047 break;
16048 case 2:
2b692964 16049 printf (_("Section Attributes:"));
11c1ff18
PB
16050 goto do_numlist;
16051 case 3:
2b692964 16052 printf (_("Symbol Attributes:"));
1a0670f3 16053 /* Fall through. */
11c1ff18
PB
16054 do_numlist:
16055 for (;;)
16056 {
91d6fa6a 16057 unsigned int j;
60bca95a 16058
f6f0e17b 16059 val = read_uleb128 (p, &j, end);
91d6fa6a 16060 p += j;
11c1ff18
PB
16061 if (val == 0)
16062 break;
16063 printf (" %d", val);
16064 }
16065 printf ("\n");
16066 break;
16067 default:
2b692964 16068 printf (_("Unknown tag: %d\n"), tag);
11c1ff18
PB
16069 public_section = FALSE;
16070 break;
16071 }
60bca95a 16072
071436c6 16073 if (public_section && display_pub_attribute != NULL)
11c1ff18
PB
16074 {
16075 while (p < end)
f6f0e17b 16076 p = display_pub_attribute (p, end);
60abdbed 16077 assert (p == end);
104d59d1 16078 }
071436c6 16079 else if (gnu_section && display_proc_gnu_attribute != NULL)
104d59d1
JM
16080 {
16081 while (p < end)
16082 p = display_gnu_attribute (p,
f6f0e17b
NC
16083 display_proc_gnu_attribute,
16084 end);
60abdbed 16085 assert (p == end);
11c1ff18 16086 }
071436c6 16087 else if (p < end)
11c1ff18 16088 {
071436c6 16089 printf (_(" Unknown attribute:\n"));
f6f0e17b 16090 display_raw_attribute (p, end);
11c1ff18
PB
16091 p = end;
16092 }
071436c6
NC
16093 else
16094 attr_len = 0;
11c1ff18
PB
16095 }
16096 }
16097 }
d70c5fc7 16098
60bca95a 16099 free (contents);
11c1ff18 16100 }
32ec8896
NC
16101
16102 return res;
11c1ff18
PB
16103}
16104
ccb4c951
RS
16105/* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
16106 Print the Address, Access and Initial fields of an entry at VMA ADDR
82b1b41b
NC
16107 and return the VMA of the next entry, or -1 if there was a problem.
16108 Does not read from DATA_END or beyond. */
ccb4c951
RS
16109
16110static bfd_vma
82b1b41b
NC
16111print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
16112 unsigned char * data_end)
ccb4c951
RS
16113{
16114 printf (" ");
16115 print_vma (addr, LONG_HEX);
16116 printf (" ");
16117 if (addr < pltgot + 0xfff0)
16118 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
16119 else
16120 printf ("%10s", "");
16121 printf (" ");
16122 if (data == NULL)
2b692964 16123 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
ccb4c951
RS
16124 else
16125 {
16126 bfd_vma entry;
82b1b41b 16127 unsigned char * from = data + addr - pltgot;
ccb4c951 16128
82b1b41b
NC
16129 if (from + (is_32bit_elf ? 4 : 8) > data_end)
16130 {
16131 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
16132 printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
16133 return (bfd_vma) -1;
16134 }
16135 else
16136 {
16137 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
16138 print_vma (entry, LONG_HEX);
16139 }
ccb4c951
RS
16140 }
16141 return addr + (is_32bit_elf ? 4 : 8);
16142}
16143
861fb55a
DJ
16144/* DATA points to the contents of a MIPS PLT GOT that starts at VMA
16145 PLTGOT. Print the Address and Initial fields of an entry at VMA
16146 ADDR and return the VMA of the next entry. */
16147
16148static bfd_vma
2cf0635d 16149print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
861fb55a
DJ
16150{
16151 printf (" ");
16152 print_vma (addr, LONG_HEX);
16153 printf (" ");
16154 if (data == NULL)
2b692964 16155 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
861fb55a
DJ
16156 else
16157 {
16158 bfd_vma entry;
16159
16160 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
16161 print_vma (entry, LONG_HEX);
16162 }
16163 return addr + (is_32bit_elf ? 4 : 8);
16164}
16165
351cdf24
MF
16166static void
16167print_mips_ases (unsigned int mask)
16168{
16169 if (mask & AFL_ASE_DSP)
16170 fputs ("\n\tDSP ASE", stdout);
16171 if (mask & AFL_ASE_DSPR2)
16172 fputs ("\n\tDSP R2 ASE", stdout);
8f4f9071
MF
16173 if (mask & AFL_ASE_DSPR3)
16174 fputs ("\n\tDSP R3 ASE", stdout);
351cdf24
MF
16175 if (mask & AFL_ASE_EVA)
16176 fputs ("\n\tEnhanced VA Scheme", stdout);
16177 if (mask & AFL_ASE_MCU)
16178 fputs ("\n\tMCU (MicroController) ASE", stdout);
16179 if (mask & AFL_ASE_MDMX)
16180 fputs ("\n\tMDMX ASE", stdout);
16181 if (mask & AFL_ASE_MIPS3D)
16182 fputs ("\n\tMIPS-3D ASE", stdout);
16183 if (mask & AFL_ASE_MT)
16184 fputs ("\n\tMT ASE", stdout);
16185 if (mask & AFL_ASE_SMARTMIPS)
16186 fputs ("\n\tSmartMIPS ASE", stdout);
16187 if (mask & AFL_ASE_VIRT)
16188 fputs ("\n\tVZ ASE", stdout);
16189 if (mask & AFL_ASE_MSA)
16190 fputs ("\n\tMSA ASE", stdout);
16191 if (mask & AFL_ASE_MIPS16)
16192 fputs ("\n\tMIPS16 ASE", stdout);
16193 if (mask & AFL_ASE_MICROMIPS)
16194 fputs ("\n\tMICROMIPS ASE", stdout);
16195 if (mask & AFL_ASE_XPA)
16196 fputs ("\n\tXPA ASE", stdout);
25499ac7
MR
16197 if (mask & AFL_ASE_MIPS16E2)
16198 fputs ("\n\tMIPS16e2 ASE", stdout);
730c3174
SE
16199 if (mask & AFL_ASE_CRC)
16200 fputs ("\n\tCRC ASE", stdout);
6f20c942
FS
16201 if (mask & AFL_ASE_GINV)
16202 fputs ("\n\tGINV ASE", stdout);
8095d2f7
CX
16203 if (mask & AFL_ASE_LOONGSON_MMI)
16204 fputs ("\n\tLoongson MMI ASE", stdout);
716c08de
CX
16205 if (mask & AFL_ASE_LOONGSON_CAM)
16206 fputs ("\n\tLoongson CAM ASE", stdout);
bdc6c06e
CX
16207 if (mask & AFL_ASE_LOONGSON_EXT)
16208 fputs ("\n\tLoongson EXT ASE", stdout);
a693765e
CX
16209 if (mask & AFL_ASE_LOONGSON_EXT2)
16210 fputs ("\n\tLoongson EXT2 ASE", stdout);
351cdf24
MF
16211 if (mask == 0)
16212 fprintf (stdout, "\n\t%s", _("None"));
00ac7aa0
MF
16213 else if ((mask & ~AFL_ASE_MASK) != 0)
16214 fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
351cdf24
MF
16215}
16216
16217static void
16218print_mips_isa_ext (unsigned int isa_ext)
16219{
16220 switch (isa_ext)
16221 {
16222 case 0:
16223 fputs (_("None"), stdout);
16224 break;
16225 case AFL_EXT_XLR:
16226 fputs ("RMI XLR", stdout);
16227 break;
2c629856
N
16228 case AFL_EXT_OCTEON3:
16229 fputs ("Cavium Networks Octeon3", stdout);
16230 break;
351cdf24
MF
16231 case AFL_EXT_OCTEON2:
16232 fputs ("Cavium Networks Octeon2", stdout);
16233 break;
16234 case AFL_EXT_OCTEONP:
16235 fputs ("Cavium Networks OcteonP", stdout);
16236 break;
351cdf24
MF
16237 case AFL_EXT_OCTEON:
16238 fputs ("Cavium Networks Octeon", stdout);
16239 break;
16240 case AFL_EXT_5900:
16241 fputs ("Toshiba R5900", stdout);
16242 break;
16243 case AFL_EXT_4650:
16244 fputs ("MIPS R4650", stdout);
16245 break;
16246 case AFL_EXT_4010:
16247 fputs ("LSI R4010", stdout);
16248 break;
16249 case AFL_EXT_4100:
16250 fputs ("NEC VR4100", stdout);
16251 break;
16252 case AFL_EXT_3900:
16253 fputs ("Toshiba R3900", stdout);
16254 break;
16255 case AFL_EXT_10000:
16256 fputs ("MIPS R10000", stdout);
16257 break;
16258 case AFL_EXT_SB1:
16259 fputs ("Broadcom SB-1", stdout);
16260 break;
16261 case AFL_EXT_4111:
16262 fputs ("NEC VR4111/VR4181", stdout);
16263 break;
16264 case AFL_EXT_4120:
16265 fputs ("NEC VR4120", stdout);
16266 break;
16267 case AFL_EXT_5400:
16268 fputs ("NEC VR5400", stdout);
16269 break;
16270 case AFL_EXT_5500:
16271 fputs ("NEC VR5500", stdout);
16272 break;
16273 case AFL_EXT_LOONGSON_2E:
16274 fputs ("ST Microelectronics Loongson 2E", stdout);
16275 break;
16276 case AFL_EXT_LOONGSON_2F:
16277 fputs ("ST Microelectronics Loongson 2F", stdout);
16278 break;
38bf472a
MR
16279 case AFL_EXT_INTERAPTIV_MR2:
16280 fputs ("Imagination interAptiv MR2", stdout);
16281 break;
351cdf24 16282 default:
00ac7aa0 16283 fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
351cdf24
MF
16284 }
16285}
16286
32ec8896 16287static signed int
351cdf24
MF
16288get_mips_reg_size (int reg_size)
16289{
16290 return (reg_size == AFL_REG_NONE) ? 0
16291 : (reg_size == AFL_REG_32) ? 32
16292 : (reg_size == AFL_REG_64) ? 64
16293 : (reg_size == AFL_REG_128) ? 128
16294 : -1;
16295}
16296
32ec8896 16297static bfd_boolean
dda8d76d 16298process_mips_specific (Filedata * filedata)
5b18a4bc 16299{
2cf0635d 16300 Elf_Internal_Dyn * entry;
351cdf24 16301 Elf_Internal_Shdr *sect = NULL;
19e6b90e
L
16302 size_t liblist_offset = 0;
16303 size_t liblistno = 0;
16304 size_t conflictsno = 0;
16305 size_t options_offset = 0;
16306 size_t conflicts_offset = 0;
861fb55a
DJ
16307 size_t pltrelsz = 0;
16308 size_t pltrel = 0;
ccb4c951 16309 bfd_vma pltgot = 0;
861fb55a
DJ
16310 bfd_vma mips_pltgot = 0;
16311 bfd_vma jmprel = 0;
ccb4c951
RS
16312 bfd_vma local_gotno = 0;
16313 bfd_vma gotsym = 0;
16314 bfd_vma symtabno = 0;
32ec8896 16315 bfd_boolean res = TRUE;
103f02d3 16316
dda8d76d 16317 if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
32ec8896
NC
16318 display_mips_gnu_attribute))
16319 res = FALSE;
2cf19d5c 16320
dda8d76d 16321 sect = find_section (filedata, ".MIPS.abiflags");
351cdf24
MF
16322
16323 if (sect != NULL)
16324 {
16325 Elf_External_ABIFlags_v0 *abiflags_ext;
16326 Elf_Internal_ABIFlags_v0 abiflags_in;
16327
16328 if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
32ec8896
NC
16329 {
16330 error (_("Corrupt MIPS ABI Flags section.\n"));
16331 res = FALSE;
16332 }
351cdf24
MF
16333 else
16334 {
dda8d76d 16335 abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
351cdf24
MF
16336 sect->sh_size, _("MIPS ABI Flags section"));
16337 if (abiflags_ext)
16338 {
16339 abiflags_in.version = BYTE_GET (abiflags_ext->version);
16340 abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
16341 abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
16342 abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
16343 abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
16344 abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
16345 abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
16346 abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
16347 abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
16348 abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
16349 abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
16350
16351 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
16352 printf ("\nISA: MIPS%d", abiflags_in.isa_level);
16353 if (abiflags_in.isa_rev > 1)
16354 printf ("r%d", abiflags_in.isa_rev);
16355 printf ("\nGPR size: %d",
16356 get_mips_reg_size (abiflags_in.gpr_size));
16357 printf ("\nCPR1 size: %d",
16358 get_mips_reg_size (abiflags_in.cpr1_size));
16359 printf ("\nCPR2 size: %d",
16360 get_mips_reg_size (abiflags_in.cpr2_size));
16361 fputs ("\nFP ABI: ", stdout);
16362 print_mips_fp_abi_value (abiflags_in.fp_abi);
16363 fputs ("ISA Extension: ", stdout);
16364 print_mips_isa_ext (abiflags_in.isa_ext);
16365 fputs ("\nASEs:", stdout);
16366 print_mips_ases (abiflags_in.ases);
16367 printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
16368 printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
16369 fputc ('\n', stdout);
16370 free (abiflags_ext);
16371 }
16372 }
16373 }
16374
19e6b90e
L
16375 /* We have a lot of special sections. Thanks SGI! */
16376 if (dynamic_section == NULL)
bbdd9a68
MR
16377 {
16378 /* No dynamic information available. See if there is static GOT. */
dda8d76d 16379 sect = find_section (filedata, ".got");
bbdd9a68
MR
16380 if (sect != NULL)
16381 {
16382 unsigned char *data_end;
16383 unsigned char *data;
16384 bfd_vma ent, end;
16385 int addr_size;
16386
16387 pltgot = sect->sh_addr;
16388
16389 ent = pltgot;
16390 addr_size = (is_32bit_elf ? 4 : 8);
16391 end = pltgot + sect->sh_size;
16392
dda8d76d 16393 data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset,
bbdd9a68
MR
16394 end - pltgot, 1,
16395 _("Global Offset Table data"));
16396 /* PR 12855: Null data is handled gracefully throughout. */
16397 data_end = data + (end - pltgot);
16398
16399 printf (_("\nStatic GOT:\n"));
16400 printf (_(" Canonical gp value: "));
16401 print_vma (ent + 0x7ff0, LONG_HEX);
16402 printf ("\n\n");
16403
16404 /* In a dynamic binary GOT[0] is reserved for the dynamic
16405 loader to store the lazy resolver pointer, however in
16406 a static binary it may well have been omitted and GOT
16407 reduced to a table of addresses.
16408 PR 21344: Check for the entry being fully available
16409 before fetching it. */
16410 if (data
16411 && data + ent - pltgot + addr_size <= data_end
16412 && byte_get (data + ent - pltgot, addr_size) == 0)
16413 {
16414 printf (_(" Reserved entries:\n"));
16415 printf (_(" %*s %10s %*s\n"),
16416 addr_size * 2, _("Address"), _("Access"),
16417 addr_size * 2, _("Value"));
16418 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16419 printf ("\n");
16420 if (ent == (bfd_vma) -1)
16421 goto sgot_print_fail;
16422
16423 /* Check for the MSB of GOT[1] being set, identifying a
16424 GNU object. This entry will be used by some runtime
16425 loaders, to store the module pointer. Otherwise this
16426 is an ordinary local entry.
16427 PR 21344: Check for the entry being fully available
16428 before fetching it. */
16429 if (data
16430 && data + ent - pltgot + addr_size <= data_end
16431 && (byte_get (data + ent - pltgot, addr_size)
16432 >> (addr_size * 8 - 1)) != 0)
16433 {
16434 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16435 printf ("\n");
16436 if (ent == (bfd_vma) -1)
16437 goto sgot_print_fail;
16438 }
16439 printf ("\n");
16440 }
16441
f17e9d8a 16442 if (data != NULL && ent < end)
bbdd9a68
MR
16443 {
16444 printf (_(" Local entries:\n"));
16445 printf (" %*s %10s %*s\n",
16446 addr_size * 2, _("Address"), _("Access"),
16447 addr_size * 2, _("Value"));
16448 while (ent < end)
16449 {
16450 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16451 printf ("\n");
16452 if (ent == (bfd_vma) -1)
16453 goto sgot_print_fail;
16454 }
16455 printf ("\n");
16456 }
16457
16458 sgot_print_fail:
16459 if (data)
16460 free (data);
16461 }
16462 return res;
16463 }
252b5132 16464
071436c6
NC
16465 for (entry = dynamic_section;
16466 /* PR 17531 file: 012-50589-0.004. */
16467 entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
16468 ++entry)
252b5132
RH
16469 switch (entry->d_tag)
16470 {
16471 case DT_MIPS_LIBLIST:
d93f0186 16472 liblist_offset
dda8d76d 16473 = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 16474 liblistno * sizeof (Elf32_External_Lib));
252b5132
RH
16475 break;
16476 case DT_MIPS_LIBLISTNO:
16477 liblistno = entry->d_un.d_val;
16478 break;
16479 case DT_MIPS_OPTIONS:
dda8d76d 16480 options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
252b5132
RH
16481 break;
16482 case DT_MIPS_CONFLICT:
d93f0186 16483 conflicts_offset
dda8d76d 16484 = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 16485 conflictsno * sizeof (Elf32_External_Conflict));
252b5132
RH
16486 break;
16487 case DT_MIPS_CONFLICTNO:
16488 conflictsno = entry->d_un.d_val;
16489 break;
ccb4c951 16490 case DT_PLTGOT:
861fb55a
DJ
16491 pltgot = entry->d_un.d_ptr;
16492 break;
ccb4c951
RS
16493 case DT_MIPS_LOCAL_GOTNO:
16494 local_gotno = entry->d_un.d_val;
16495 break;
16496 case DT_MIPS_GOTSYM:
16497 gotsym = entry->d_un.d_val;
16498 break;
16499 case DT_MIPS_SYMTABNO:
16500 symtabno = entry->d_un.d_val;
16501 break;
861fb55a
DJ
16502 case DT_MIPS_PLTGOT:
16503 mips_pltgot = entry->d_un.d_ptr;
16504 break;
16505 case DT_PLTREL:
16506 pltrel = entry->d_un.d_val;
16507 break;
16508 case DT_PLTRELSZ:
16509 pltrelsz = entry->d_un.d_val;
16510 break;
16511 case DT_JMPREL:
16512 jmprel = entry->d_un.d_ptr;
16513 break;
252b5132
RH
16514 default:
16515 break;
16516 }
16517
16518 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
16519 {
2cf0635d 16520 Elf32_External_Lib * elib;
252b5132
RH
16521 size_t cnt;
16522
dda8d76d 16523 elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset,
3f5e193b
NC
16524 liblistno,
16525 sizeof (Elf32_External_Lib),
9cf03b7e 16526 _("liblist section data"));
a6e9f9df 16527 if (elib)
252b5132 16528 {
d3a49aa8
AM
16529 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
16530 "\nSection '.liblist' contains %lu entries:\n",
16531 (unsigned long) liblistno),
a6e9f9df 16532 (unsigned long) liblistno);
2b692964 16533 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
a6e9f9df
AM
16534 stdout);
16535
16536 for (cnt = 0; cnt < liblistno; ++cnt)
252b5132 16537 {
a6e9f9df 16538 Elf32_Lib liblist;
91d6fa6a 16539 time_t atime;
d5b07ef4 16540 char timebuf[128];
2cf0635d 16541 struct tm * tmp;
a6e9f9df
AM
16542
16543 liblist.l_name = BYTE_GET (elib[cnt].l_name);
91d6fa6a 16544 atime = BYTE_GET (elib[cnt].l_time_stamp);
a6e9f9df
AM
16545 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
16546 liblist.l_version = BYTE_GET (elib[cnt].l_version);
16547 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
16548
91d6fa6a 16549 tmp = gmtime (&atime);
e9e44622
JJ
16550 snprintf (timebuf, sizeof (timebuf),
16551 "%04u-%02u-%02uT%02u:%02u:%02u",
16552 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
16553 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
a6e9f9df 16554
31104126 16555 printf ("%3lu: ", (unsigned long) cnt);
d79b3d50
NC
16556 if (VALID_DYNAMIC_NAME (liblist.l_name))
16557 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
16558 else
2b692964 16559 printf (_("<corrupt: %9ld>"), liblist.l_name);
31104126
NC
16560 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
16561 liblist.l_version);
a6e9f9df
AM
16562
16563 if (liblist.l_flags == 0)
2b692964 16564 puts (_(" NONE"));
a6e9f9df
AM
16565 else
16566 {
16567 static const struct
252b5132 16568 {
2cf0635d 16569 const char * name;
a6e9f9df 16570 int bit;
252b5132 16571 }
a6e9f9df
AM
16572 l_flags_vals[] =
16573 {
16574 { " EXACT_MATCH", LL_EXACT_MATCH },
16575 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
16576 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
16577 { " EXPORTS", LL_EXPORTS },
16578 { " DELAY_LOAD", LL_DELAY_LOAD },
16579 { " DELTA", LL_DELTA }
16580 };
16581 int flags = liblist.l_flags;
16582 size_t fcnt;
16583
60bca95a 16584 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
a6e9f9df
AM
16585 if ((flags & l_flags_vals[fcnt].bit) != 0)
16586 {
16587 fputs (l_flags_vals[fcnt].name, stdout);
16588 flags ^= l_flags_vals[fcnt].bit;
16589 }
16590 if (flags != 0)
16591 printf (" %#x", (unsigned int) flags);
252b5132 16592
a6e9f9df
AM
16593 puts ("");
16594 }
252b5132 16595 }
252b5132 16596
a6e9f9df
AM
16597 free (elib);
16598 }
32ec8896
NC
16599 else
16600 res = FALSE;
252b5132
RH
16601 }
16602
16603 if (options_offset != 0)
16604 {
2cf0635d 16605 Elf_External_Options * eopt;
252b5132
RH
16606 size_t offset;
16607 int cnt;
dda8d76d 16608 sect = filedata->section_headers;
252b5132
RH
16609
16610 /* Find the section header so that we get the size. */
dda8d76d 16611 sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS);
948f632f 16612 /* PR 17533 file: 012-277276-0.004. */
071436c6
NC
16613 if (sect == NULL)
16614 {
16615 error (_("No MIPS_OPTIONS header found\n"));
32ec8896 16616 return FALSE;
071436c6 16617 }
7fc0c668
NC
16618 /* PR 24243 */
16619 if (sect->sh_size < sizeof (* eopt))
16620 {
16621 error (_("The MIPS options section is too small.\n"));
16622 return FALSE;
16623 }
252b5132 16624
dda8d76d 16625 eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1,
3f5e193b 16626 sect->sh_size, _("options"));
a6e9f9df 16627 if (eopt)
252b5132 16628 {
2e6be59c
NC
16629 Elf_Internal_Options * iopt;
16630 Elf_Internal_Options * option;
16631 Elf_Internal_Options * iopt_end;
16632
3f5e193b
NC
16633 iopt = (Elf_Internal_Options *)
16634 cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
a6e9f9df
AM
16635 if (iopt == NULL)
16636 {
fb324ee9 16637 error (_("Out of memory allocating space for MIPS options\n"));
32ec8896 16638 return FALSE;
a6e9f9df 16639 }
76da6bbe 16640
a6e9f9df
AM
16641 offset = cnt = 0;
16642 option = iopt;
2e6be59c
NC
16643 iopt_end = iopt + (sect->sh_size / sizeof (eopt));
16644
82b1b41b 16645 while (offset <= sect->sh_size - sizeof (* eopt))
a6e9f9df 16646 {
2cf0635d 16647 Elf_External_Options * eoption;
252b5132 16648
a6e9f9df 16649 eoption = (Elf_External_Options *) ((char *) eopt + offset);
252b5132 16650
a6e9f9df
AM
16651 option->kind = BYTE_GET (eoption->kind);
16652 option->size = BYTE_GET (eoption->size);
16653 option->section = BYTE_GET (eoption->section);
16654 option->info = BYTE_GET (eoption->info);
76da6bbe 16655
82b1b41b
NC
16656 /* PR 17531: file: ffa0fa3b. */
16657 if (option->size < sizeof (* eopt)
16658 || offset + option->size > sect->sh_size)
16659 {
55325047 16660 error (_("Invalid size (%u) for MIPS option\n"), option->size);
32ec8896 16661 return FALSE;
82b1b41b 16662 }
a6e9f9df 16663 offset += option->size;
14ae95f2 16664
a6e9f9df
AM
16665 ++option;
16666 ++cnt;
16667 }
252b5132 16668
d3a49aa8
AM
16669 printf (ngettext ("\nSection '%s' contains %d entry:\n",
16670 "\nSection '%s' contains %d entries:\n",
16671 cnt),
dda8d76d 16672 printable_section_name (filedata, sect), cnt);
76da6bbe 16673
a6e9f9df 16674 option = iopt;
82b1b41b 16675 offset = 0;
252b5132 16676
a6e9f9df 16677 while (cnt-- > 0)
252b5132 16678 {
a6e9f9df
AM
16679 size_t len;
16680
16681 switch (option->kind)
252b5132 16682 {
a6e9f9df
AM
16683 case ODK_NULL:
16684 /* This shouldn't happen. */
16685 printf (" NULL %d %lx", option->section, option->info);
16686 break;
2e6be59c 16687
a6e9f9df
AM
16688 case ODK_REGINFO:
16689 printf (" REGINFO ");
dda8d76d 16690 if (filedata->file_header.e_machine == EM_MIPS)
a6e9f9df 16691 {
2cf0635d 16692 Elf32_External_RegInfo * ereg;
b34976b6 16693 Elf32_RegInfo reginfo;
a6e9f9df 16694
2e6be59c
NC
16695 /* 32bit form. */
16696 if (option + 2 > iopt_end)
16697 {
16698 printf (_("<corrupt>\n"));
16699 error (_("Truncated MIPS REGINFO option\n"));
16700 cnt = 0;
16701 break;
16702 }
16703
a6e9f9df 16704 ereg = (Elf32_External_RegInfo *) (option + 1);
2e6be59c 16705
a6e9f9df
AM
16706 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
16707 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
16708 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
16709 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
16710 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
16711 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
16712
16713 printf ("GPR %08lx GP 0x%lx\n",
16714 reginfo.ri_gprmask,
16715 (unsigned long) reginfo.ri_gp_value);
16716 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16717 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
16718 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
16719 }
16720 else
16721 {
16722 /* 64 bit form. */
2cf0635d 16723 Elf64_External_RegInfo * ereg;
a6e9f9df
AM
16724 Elf64_Internal_RegInfo reginfo;
16725
2e6be59c
NC
16726 if (option + 2 > iopt_end)
16727 {
16728 printf (_("<corrupt>\n"));
16729 error (_("Truncated MIPS REGINFO option\n"));
16730 cnt = 0;
16731 break;
16732 }
16733
a6e9f9df
AM
16734 ereg = (Elf64_External_RegInfo *) (option + 1);
16735 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
16736 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
16737 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
16738 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
16739 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
66543521 16740 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
a6e9f9df
AM
16741
16742 printf ("GPR %08lx GP 0x",
16743 reginfo.ri_gprmask);
16744 printf_vma (reginfo.ri_gp_value);
16745 printf ("\n");
16746
16747 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16748 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
16749 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
16750 }
16751 ++option;
16752 continue;
2e6be59c 16753
a6e9f9df
AM
16754 case ODK_EXCEPTIONS:
16755 fputs (" EXCEPTIONS fpe_min(", stdout);
16756 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
16757 fputs (") fpe_max(", stdout);
16758 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
16759 fputs (")", stdout);
16760
16761 if (option->info & OEX_PAGE0)
16762 fputs (" PAGE0", stdout);
16763 if (option->info & OEX_SMM)
16764 fputs (" SMM", stdout);
16765 if (option->info & OEX_FPDBUG)
16766 fputs (" FPDBUG", stdout);
16767 if (option->info & OEX_DISMISS)
16768 fputs (" DISMISS", stdout);
16769 break;
2e6be59c 16770
a6e9f9df
AM
16771 case ODK_PAD:
16772 fputs (" PAD ", stdout);
16773 if (option->info & OPAD_PREFIX)
16774 fputs (" PREFIX", stdout);
16775 if (option->info & OPAD_POSTFIX)
16776 fputs (" POSTFIX", stdout);
16777 if (option->info & OPAD_SYMBOL)
16778 fputs (" SYMBOL", stdout);
16779 break;
2e6be59c 16780
a6e9f9df
AM
16781 case ODK_HWPATCH:
16782 fputs (" HWPATCH ", stdout);
16783 if (option->info & OHW_R4KEOP)
16784 fputs (" R4KEOP", stdout);
16785 if (option->info & OHW_R8KPFETCH)
16786 fputs (" R8KPFETCH", stdout);
16787 if (option->info & OHW_R5KEOP)
16788 fputs (" R5KEOP", stdout);
16789 if (option->info & OHW_R5KCVTL)
16790 fputs (" R5KCVTL", stdout);
16791 break;
2e6be59c 16792
a6e9f9df
AM
16793 case ODK_FILL:
16794 fputs (" FILL ", stdout);
16795 /* XXX Print content of info word? */
16796 break;
2e6be59c 16797
a6e9f9df
AM
16798 case ODK_TAGS:
16799 fputs (" TAGS ", stdout);
16800 /* XXX Print content of info word? */
16801 break;
2e6be59c 16802
a6e9f9df
AM
16803 case ODK_HWAND:
16804 fputs (" HWAND ", stdout);
16805 if (option->info & OHWA0_R4KEOP_CHECKED)
16806 fputs (" R4KEOP_CHECKED", stdout);
16807 if (option->info & OHWA0_R4KEOP_CLEAN)
16808 fputs (" R4KEOP_CLEAN", stdout);
16809 break;
2e6be59c 16810
a6e9f9df
AM
16811 case ODK_HWOR:
16812 fputs (" HWOR ", stdout);
16813 if (option->info & OHWA0_R4KEOP_CHECKED)
16814 fputs (" R4KEOP_CHECKED", stdout);
16815 if (option->info & OHWA0_R4KEOP_CLEAN)
16816 fputs (" R4KEOP_CLEAN", stdout);
16817 break;
2e6be59c 16818
a6e9f9df
AM
16819 case ODK_GP_GROUP:
16820 printf (" GP_GROUP %#06lx self-contained %#06lx",
16821 option->info & OGP_GROUP,
16822 (option->info & OGP_SELF) >> 16);
16823 break;
2e6be59c 16824
a6e9f9df
AM
16825 case ODK_IDENT:
16826 printf (" IDENT %#06lx self-contained %#06lx",
16827 option->info & OGP_GROUP,
16828 (option->info & OGP_SELF) >> 16);
16829 break;
2e6be59c 16830
a6e9f9df
AM
16831 default:
16832 /* This shouldn't happen. */
16833 printf (" %3d ??? %d %lx",
16834 option->kind, option->section, option->info);
16835 break;
252b5132 16836 }
a6e9f9df 16837
2cf0635d 16838 len = sizeof (* eopt);
a6e9f9df 16839 while (len < option->size)
82b1b41b 16840 {
7e27a9d5 16841 unsigned char datum = * ((unsigned char *) eopt + offset + len);
a6e9f9df 16842
82b1b41b
NC
16843 if (ISPRINT (datum))
16844 printf ("%c", datum);
16845 else
16846 printf ("\\%03o", datum);
16847 len ++;
16848 }
a6e9f9df 16849 fputs ("\n", stdout);
82b1b41b
NC
16850
16851 offset += option->size;
252b5132 16852 ++option;
252b5132
RH
16853 }
16854
a6e9f9df 16855 free (eopt);
252b5132 16856 }
32ec8896
NC
16857 else
16858 res = FALSE;
252b5132
RH
16859 }
16860
16861 if (conflicts_offset != 0 && conflictsno != 0)
16862 {
2cf0635d 16863 Elf32_Conflict * iconf;
252b5132
RH
16864 size_t cnt;
16865
16866 if (dynamic_symbols == NULL)
16867 {
591a748a 16868 error (_("conflict list found without a dynamic symbol table\n"));
32ec8896 16869 return FALSE;
252b5132
RH
16870 }
16871
7296a62a
NC
16872 /* PR 21345 - print a slightly more helpful error message
16873 if we are sure that the cmalloc will fail. */
dda8d76d 16874 if (conflictsno * sizeof (* iconf) > filedata->file_size)
7296a62a
NC
16875 {
16876 error (_("Overlarge number of conflicts detected: %lx\n"),
16877 (long) conflictsno);
16878 return FALSE;
16879 }
16880
3f5e193b 16881 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
252b5132
RH
16882 if (iconf == NULL)
16883 {
8b73c356 16884 error (_("Out of memory allocating space for dynamic conflicts\n"));
32ec8896 16885 return FALSE;
252b5132
RH
16886 }
16887
9ea033b2 16888 if (is_32bit_elf)
252b5132 16889 {
2cf0635d 16890 Elf32_External_Conflict * econf32;
a6e9f9df 16891
3f5e193b 16892 econf32 = (Elf32_External_Conflict *)
dda8d76d 16893 get_data (NULL, filedata, conflicts_offset, conflictsno,
3f5e193b 16894 sizeof (* econf32), _("conflict"));
a6e9f9df 16895 if (!econf32)
32ec8896 16896 return FALSE;
252b5132
RH
16897
16898 for (cnt = 0; cnt < conflictsno; ++cnt)
16899 iconf[cnt] = BYTE_GET (econf32[cnt]);
a6e9f9df
AM
16900
16901 free (econf32);
252b5132
RH
16902 }
16903 else
16904 {
2cf0635d 16905 Elf64_External_Conflict * econf64;
a6e9f9df 16906
3f5e193b 16907 econf64 = (Elf64_External_Conflict *)
dda8d76d 16908 get_data (NULL, filedata, conflicts_offset, conflictsno,
3f5e193b 16909 sizeof (* econf64), _("conflict"));
a6e9f9df 16910 if (!econf64)
32ec8896 16911 return FALSE;
252b5132
RH
16912
16913 for (cnt = 0; cnt < conflictsno; ++cnt)
16914 iconf[cnt] = BYTE_GET (econf64[cnt]);
a6e9f9df
AM
16915
16916 free (econf64);
252b5132
RH
16917 }
16918
d3a49aa8
AM
16919 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
16920 "\nSection '.conflict' contains %lu entries:\n",
16921 (unsigned long) conflictsno),
c7e7ca54 16922 (unsigned long) conflictsno);
252b5132
RH
16923 puts (_(" Num: Index Value Name"));
16924
16925 for (cnt = 0; cnt < conflictsno; ++cnt)
16926 {
b34976b6 16927 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
e0a31db1
NC
16928
16929 if (iconf[cnt] >= num_dynamic_syms)
16930 printf (_("<corrupt symbol index>"));
d79b3d50 16931 else
e0a31db1
NC
16932 {
16933 Elf_Internal_Sym * psym;
16934
16935 psym = & dynamic_symbols[iconf[cnt]];
16936 print_vma (psym->st_value, FULL_HEX);
16937 putchar (' ');
16938 if (VALID_DYNAMIC_NAME (psym->st_name))
16939 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
16940 else
16941 printf (_("<corrupt: %14ld>"), psym->st_name);
16942 }
31104126 16943 putchar ('\n');
252b5132
RH
16944 }
16945
252b5132
RH
16946 free (iconf);
16947 }
16948
ccb4c951
RS
16949 if (pltgot != 0 && local_gotno != 0)
16950 {
91d6fa6a 16951 bfd_vma ent, local_end, global_end;
bbeee7ea 16952 size_t i, offset;
2cf0635d 16953 unsigned char * data;
82b1b41b 16954 unsigned char * data_end;
bbeee7ea 16955 int addr_size;
ccb4c951 16956
91d6fa6a 16957 ent = pltgot;
ccb4c951
RS
16958 addr_size = (is_32bit_elf ? 4 : 8);
16959 local_end = pltgot + local_gotno * addr_size;
ccb4c951 16960
74e1a04b
NC
16961 /* PR binutils/17533 file: 012-111227-0.004 */
16962 if (symtabno < gotsym)
16963 {
16964 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
82b1b41b 16965 (unsigned long) gotsym, (unsigned long) symtabno);
32ec8896 16966 return FALSE;
74e1a04b 16967 }
82b1b41b 16968
74e1a04b 16969 global_end = local_end + (symtabno - gotsym) * addr_size;
82b1b41b
NC
16970 /* PR 17531: file: 54c91a34. */
16971 if (global_end < local_end)
16972 {
16973 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
32ec8896 16974 return FALSE;
82b1b41b 16975 }
948f632f 16976
dda8d76d
NC
16977 offset = offset_from_vma (filedata, pltgot, global_end - pltgot);
16978 data = (unsigned char *) get_data (NULL, filedata, offset,
9cf03b7e
NC
16979 global_end - pltgot, 1,
16980 _("Global Offset Table data"));
919383ac 16981 /* PR 12855: Null data is handled gracefully throughout. */
82b1b41b 16982 data_end = data + (global_end - pltgot);
59245841 16983
ccb4c951
RS
16984 printf (_("\nPrimary GOT:\n"));
16985 printf (_(" Canonical gp value: "));
16986 print_vma (pltgot + 0x7ff0, LONG_HEX);
16987 printf ("\n\n");
16988
16989 printf (_(" Reserved entries:\n"));
16990 printf (_(" %*s %10s %*s Purpose\n"),
2b692964
NC
16991 addr_size * 2, _("Address"), _("Access"),
16992 addr_size * 2, _("Initial"));
82b1b41b 16993 ent = print_mips_got_entry (data, pltgot, ent, data_end);
2b692964 16994 printf (_(" Lazy resolver\n"));
82b1b41b
NC
16995 if (ent == (bfd_vma) -1)
16996 goto got_print_fail;
75ec1fdb 16997
c4ab9505
MR
16998 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
16999 This entry will be used by some runtime loaders, to store the
17000 module pointer. Otherwise this is an ordinary local entry.
17001 PR 21344: Check for the entry being fully available before
17002 fetching it. */
17003 if (data
17004 && data + ent - pltgot + addr_size <= data_end
17005 && (byte_get (data + ent - pltgot, addr_size)
17006 >> (addr_size * 8 - 1)) != 0)
17007 {
17008 ent = print_mips_got_entry (data, pltgot, ent, data_end);
17009 printf (_(" Module pointer (GNU extension)\n"));
17010 if (ent == (bfd_vma) -1)
17011 goto got_print_fail;
ccb4c951
RS
17012 }
17013 printf ("\n");
17014
f17e9d8a 17015 if (data != NULL && ent < local_end)
ccb4c951
RS
17016 {
17017 printf (_(" Local entries:\n"));
cc5914eb 17018 printf (" %*s %10s %*s\n",
2b692964
NC
17019 addr_size * 2, _("Address"), _("Access"),
17020 addr_size * 2, _("Initial"));
91d6fa6a 17021 while (ent < local_end)
ccb4c951 17022 {
82b1b41b 17023 ent = print_mips_got_entry (data, pltgot, ent, data_end);
ccb4c951 17024 printf ("\n");
82b1b41b
NC
17025 if (ent == (bfd_vma) -1)
17026 goto got_print_fail;
ccb4c951
RS
17027 }
17028 printf ("\n");
17029 }
17030
f17e9d8a 17031 if (data != NULL && gotsym < symtabno)
ccb4c951
RS
17032 {
17033 int sym_width;
17034
17035 printf (_(" Global entries:\n"));
cc5914eb 17036 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
9cf03b7e
NC
17037 addr_size * 2, _("Address"),
17038 _("Access"),
2b692964 17039 addr_size * 2, _("Initial"),
9cf03b7e
NC
17040 addr_size * 2, _("Sym.Val."),
17041 _("Type"),
17042 /* Note for translators: "Ndx" = abbreviated form of "Index". */
17043 _("Ndx"), _("Name"));
0b4362b0 17044
ccb4c951 17045 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
e0a31db1 17046
ccb4c951
RS
17047 for (i = gotsym; i < symtabno; i++)
17048 {
82b1b41b 17049 ent = print_mips_got_entry (data, pltgot, ent, data_end);
ccb4c951 17050 printf (" ");
e0a31db1
NC
17051
17052 if (dynamic_symbols == NULL)
17053 printf (_("<no dynamic symbols>"));
17054 else if (i < num_dynamic_syms)
17055 {
17056 Elf_Internal_Sym * psym = dynamic_symbols + i;
17057
17058 print_vma (psym->st_value, LONG_HEX);
17059 printf (" %-7s %3s ",
dda8d76d
NC
17060 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
17061 get_symbol_index_type (filedata, psym->st_shndx));
e0a31db1
NC
17062
17063 if (VALID_DYNAMIC_NAME (psym->st_name))
17064 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
17065 else
17066 printf (_("<corrupt: %14ld>"), psym->st_name);
17067 }
ccb4c951 17068 else
7fc5ac57
JBG
17069 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
17070 (unsigned long) i);
e0a31db1 17071
ccb4c951 17072 printf ("\n");
82b1b41b
NC
17073 if (ent == (bfd_vma) -1)
17074 break;
ccb4c951
RS
17075 }
17076 printf ("\n");
17077 }
17078
82b1b41b 17079 got_print_fail:
ccb4c951
RS
17080 if (data)
17081 free (data);
17082 }
17083
861fb55a
DJ
17084 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
17085 {
91d6fa6a 17086 bfd_vma ent, end;
861fb55a
DJ
17087 size_t offset, rel_offset;
17088 unsigned long count, i;
2cf0635d 17089 unsigned char * data;
861fb55a 17090 int addr_size, sym_width;
2cf0635d 17091 Elf_Internal_Rela * rels;
861fb55a 17092
dda8d76d 17093 rel_offset = offset_from_vma (filedata, jmprel, pltrelsz);
861fb55a
DJ
17094 if (pltrel == DT_RELA)
17095 {
dda8d76d 17096 if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
32ec8896 17097 return FALSE;
861fb55a
DJ
17098 }
17099 else
17100 {
dda8d76d 17101 if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
32ec8896 17102 return FALSE;
861fb55a
DJ
17103 }
17104
91d6fa6a 17105 ent = mips_pltgot;
861fb55a
DJ
17106 addr_size = (is_32bit_elf ? 4 : 8);
17107 end = mips_pltgot + (2 + count) * addr_size;
17108
dda8d76d
NC
17109 offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot);
17110 data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot,
9cf03b7e 17111 1, _("Procedure Linkage Table data"));
59245841 17112 if (data == NULL)
32ec8896 17113 return FALSE;
59245841 17114
9cf03b7e 17115 printf ("\nPLT GOT:\n\n");
861fb55a
DJ
17116 printf (_(" Reserved entries:\n"));
17117 printf (_(" %*s %*s Purpose\n"),
2b692964 17118 addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
91d6fa6a 17119 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
2b692964 17120 printf (_(" PLT lazy resolver\n"));
91d6fa6a 17121 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
2b692964 17122 printf (_(" Module pointer\n"));
861fb55a
DJ
17123 printf ("\n");
17124
17125 printf (_(" Entries:\n"));
cc5914eb 17126 printf (" %*s %*s %*s %-7s %3s %s\n",
2b692964
NC
17127 addr_size * 2, _("Address"),
17128 addr_size * 2, _("Initial"),
17129 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
861fb55a
DJ
17130 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
17131 for (i = 0; i < count; i++)
17132 {
df97ab2a 17133 unsigned long idx = get_reloc_symindex (rels[i].r_info);
861fb55a 17134
91d6fa6a 17135 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
861fb55a 17136 printf (" ");
e0a31db1 17137
df97ab2a
MF
17138 if (idx >= num_dynamic_syms)
17139 printf (_("<corrupt symbol index: %lu>"), idx);
861fb55a 17140 else
e0a31db1 17141 {
df97ab2a 17142 Elf_Internal_Sym * psym = dynamic_symbols + idx;
e0a31db1
NC
17143
17144 print_vma (psym->st_value, LONG_HEX);
17145 printf (" %-7s %3s ",
dda8d76d
NC
17146 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
17147 get_symbol_index_type (filedata, psym->st_shndx));
e0a31db1
NC
17148 if (VALID_DYNAMIC_NAME (psym->st_name))
17149 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
17150 else
17151 printf (_("<corrupt: %14ld>"), psym->st_name);
17152 }
861fb55a
DJ
17153 printf ("\n");
17154 }
17155 printf ("\n");
17156
17157 if (data)
17158 free (data);
17159 free (rels);
17160 }
17161
32ec8896 17162 return res;
252b5132
RH
17163}
17164
32ec8896 17165static bfd_boolean
dda8d76d 17166process_nds32_specific (Filedata * filedata)
35c08157
KLC
17167{
17168 Elf_Internal_Shdr *sect = NULL;
17169
dda8d76d 17170 sect = find_section (filedata, ".nds32_e_flags");
35c08157
KLC
17171 if (sect != NULL)
17172 {
17173 unsigned int *flag;
17174
17175 printf ("\nNDS32 elf flags section:\n");
dda8d76d 17176 flag = get_data (NULL, filedata, sect->sh_offset, 1,
35c08157
KLC
17177 sect->sh_size, _("NDS32 elf flags section"));
17178
32ec8896
NC
17179 if (! flag)
17180 return FALSE;
17181
35c08157
KLC
17182 switch ((*flag) & 0x3)
17183 {
17184 case 0:
17185 printf ("(VEC_SIZE):\tNo entry.\n");
17186 break;
17187 case 1:
17188 printf ("(VEC_SIZE):\t4 bytes\n");
17189 break;
17190 case 2:
17191 printf ("(VEC_SIZE):\t16 bytes\n");
17192 break;
17193 case 3:
17194 printf ("(VEC_SIZE):\treserved\n");
17195 break;
17196 }
17197 }
17198
17199 return TRUE;
17200}
17201
32ec8896 17202static bfd_boolean
dda8d76d 17203process_gnu_liblist (Filedata * filedata)
047b2264 17204{
2cf0635d
NC
17205 Elf_Internal_Shdr * section;
17206 Elf_Internal_Shdr * string_sec;
17207 Elf32_External_Lib * elib;
17208 char * strtab;
c256ffe7 17209 size_t strtab_size;
047b2264 17210 size_t cnt;
d3a49aa8 17211 unsigned long num_liblist;
047b2264 17212 unsigned i;
32ec8896 17213 bfd_boolean res = TRUE;
047b2264
JJ
17214
17215 if (! do_arch)
32ec8896 17216 return TRUE;
047b2264 17217
dda8d76d
NC
17218 for (i = 0, section = filedata->section_headers;
17219 i < filedata->file_header.e_shnum;
b34976b6 17220 i++, section++)
047b2264
JJ
17221 {
17222 switch (section->sh_type)
17223 {
17224 case SHT_GNU_LIBLIST:
dda8d76d 17225 if (section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
17226 break;
17227
3f5e193b 17228 elib = (Elf32_External_Lib *)
dda8d76d 17229 get_data (NULL, filedata, section->sh_offset, 1, section->sh_size,
9cf03b7e 17230 _("liblist section data"));
047b2264
JJ
17231
17232 if (elib == NULL)
32ec8896
NC
17233 {
17234 res = FALSE;
17235 break;
17236 }
047b2264 17237
dda8d76d
NC
17238 string_sec = filedata->section_headers + section->sh_link;
17239 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
3f5e193b
NC
17240 string_sec->sh_size,
17241 _("liblist string table"));
047b2264
JJ
17242 if (strtab == NULL
17243 || section->sh_entsize != sizeof (Elf32_External_Lib))
17244 {
17245 free (elib);
2842702f 17246 free (strtab);
32ec8896 17247 res = FALSE;
047b2264
JJ
17248 break;
17249 }
59245841 17250 strtab_size = string_sec->sh_size;
047b2264 17251
d3a49aa8
AM
17252 num_liblist = section->sh_size / sizeof (Elf32_External_Lib);
17253 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
17254 "\nLibrary list section '%s' contains %lu entries:\n",
17255 num_liblist),
dda8d76d 17256 printable_section_name (filedata, section),
d3a49aa8 17257 num_liblist);
047b2264 17258
2b692964 17259 puts (_(" Library Time Stamp Checksum Version Flags"));
047b2264
JJ
17260
17261 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
17262 ++cnt)
17263 {
17264 Elf32_Lib liblist;
91d6fa6a 17265 time_t atime;
d5b07ef4 17266 char timebuf[128];
2cf0635d 17267 struct tm * tmp;
047b2264
JJ
17268
17269 liblist.l_name = BYTE_GET (elib[cnt].l_name);
91d6fa6a 17270 atime = BYTE_GET (elib[cnt].l_time_stamp);
047b2264
JJ
17271 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
17272 liblist.l_version = BYTE_GET (elib[cnt].l_version);
17273 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
17274
91d6fa6a 17275 tmp = gmtime (&atime);
e9e44622
JJ
17276 snprintf (timebuf, sizeof (timebuf),
17277 "%04u-%02u-%02uT%02u:%02u:%02u",
17278 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
17279 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
047b2264
JJ
17280
17281 printf ("%3lu: ", (unsigned long) cnt);
17282 if (do_wide)
c256ffe7 17283 printf ("%-20s", liblist.l_name < strtab_size
2b692964 17284 ? strtab + liblist.l_name : _("<corrupt>"));
047b2264 17285 else
c256ffe7 17286 printf ("%-20.20s", liblist.l_name < strtab_size
2b692964 17287 ? strtab + liblist.l_name : _("<corrupt>"));
047b2264
JJ
17288 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
17289 liblist.l_version, liblist.l_flags);
17290 }
17291
17292 free (elib);
2842702f 17293 free (strtab);
047b2264
JJ
17294 }
17295 }
17296
32ec8896 17297 return res;
047b2264
JJ
17298}
17299
9437c45b 17300static const char *
dda8d76d 17301get_note_type (Filedata * filedata, unsigned e_type)
779fe533
NC
17302{
17303 static char buff[64];
103f02d3 17304
dda8d76d 17305 if (filedata->file_header.e_type == ET_CORE)
1ec5cd37
NC
17306 switch (e_type)
17307 {
57346661 17308 case NT_AUXV:
1ec5cd37 17309 return _("NT_AUXV (auxiliary vector)");
57346661 17310 case NT_PRSTATUS:
1ec5cd37 17311 return _("NT_PRSTATUS (prstatus structure)");
57346661 17312 case NT_FPREGSET:
1ec5cd37 17313 return _("NT_FPREGSET (floating point registers)");
57346661 17314 case NT_PRPSINFO:
1ec5cd37 17315 return _("NT_PRPSINFO (prpsinfo structure)");
57346661 17316 case NT_TASKSTRUCT:
1ec5cd37 17317 return _("NT_TASKSTRUCT (task structure)");
57346661 17318 case NT_PRXFPREG:
1ec5cd37 17319 return _("NT_PRXFPREG (user_xfpregs structure)");
e1e95dec
AM
17320 case NT_PPC_VMX:
17321 return _("NT_PPC_VMX (ppc Altivec registers)");
89eeb0bc
LM
17322 case NT_PPC_VSX:
17323 return _("NT_PPC_VSX (ppc VSX registers)");
66c3b5f8
GR
17324 case NT_PPC_TAR:
17325 return _("NT_PPC_TAR (ppc TAR register)");
17326 case NT_PPC_PPR:
17327 return _("NT_PPC_PPR (ppc PPR register)");
17328 case NT_PPC_DSCR:
17329 return _("NT_PPC_DSCR (ppc DSCR register)");
17330 case NT_PPC_EBB:
17331 return _("NT_PPC_EBB (ppc EBB registers)");
17332 case NT_PPC_PMU:
17333 return _("NT_PPC_PMU (ppc PMU registers)");
17334 case NT_PPC_TM_CGPR:
17335 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
17336 case NT_PPC_TM_CFPR:
17337 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
17338 case NT_PPC_TM_CVMX:
17339 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
17340 case NT_PPC_TM_CVSX:
3fd21718 17341 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
66c3b5f8
GR
17342 case NT_PPC_TM_SPR:
17343 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
17344 case NT_PPC_TM_CTAR:
17345 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
17346 case NT_PPC_TM_CPPR:
17347 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
17348 case NT_PPC_TM_CDSCR:
17349 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
ff826ef3
TT
17350 case NT_386_TLS:
17351 return _("NT_386_TLS (x86 TLS information)");
17352 case NT_386_IOPERM:
17353 return _("NT_386_IOPERM (x86 I/O permissions)");
4339cae0
L
17354 case NT_X86_XSTATE:
17355 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
0675e188
UW
17356 case NT_S390_HIGH_GPRS:
17357 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
d7eeb400
MS
17358 case NT_S390_TIMER:
17359 return _("NT_S390_TIMER (s390 timer register)");
17360 case NT_S390_TODCMP:
17361 return _("NT_S390_TODCMP (s390 TOD comparator register)");
17362 case NT_S390_TODPREG:
17363 return _("NT_S390_TODPREG (s390 TOD programmable register)");
17364 case NT_S390_CTRS:
17365 return _("NT_S390_CTRS (s390 control registers)");
17366 case NT_S390_PREFIX:
17367 return _("NT_S390_PREFIX (s390 prefix register)");
a367d729
AK
17368 case NT_S390_LAST_BREAK:
17369 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
17370 case NT_S390_SYSTEM_CALL:
17371 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
abb3f6cc
NC
17372 case NT_S390_TDB:
17373 return _("NT_S390_TDB (s390 transaction diagnostic block)");
4ef9f41a
AA
17374 case NT_S390_VXRS_LOW:
17375 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
17376 case NT_S390_VXRS_HIGH:
17377 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
88ab90e8
AA
17378 case NT_S390_GS_CB:
17379 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
17380 case NT_S390_GS_BC:
17381 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
faa9a424
UW
17382 case NT_ARM_VFP:
17383 return _("NT_ARM_VFP (arm VFP registers)");
652451f8
YZ
17384 case NT_ARM_TLS:
17385 return _("NT_ARM_TLS (AArch TLS registers)");
17386 case NT_ARM_HW_BREAK:
17387 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
17388 case NT_ARM_HW_WATCH:
17389 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
57346661 17390 case NT_PSTATUS:
1ec5cd37 17391 return _("NT_PSTATUS (pstatus structure)");
57346661 17392 case NT_FPREGS:
1ec5cd37 17393 return _("NT_FPREGS (floating point registers)");
57346661 17394 case NT_PSINFO:
1ec5cd37 17395 return _("NT_PSINFO (psinfo structure)");
57346661 17396 case NT_LWPSTATUS:
1ec5cd37 17397 return _("NT_LWPSTATUS (lwpstatus_t structure)");
57346661 17398 case NT_LWPSINFO:
1ec5cd37 17399 return _("NT_LWPSINFO (lwpsinfo_t structure)");
57346661 17400 case NT_WIN32PSTATUS:
1ec5cd37 17401 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9ece1fa9
TT
17402 case NT_SIGINFO:
17403 return _("NT_SIGINFO (siginfo_t data)");
17404 case NT_FILE:
17405 return _("NT_FILE (mapped files)");
1ec5cd37
NC
17406 default:
17407 break;
17408 }
17409 else
17410 switch (e_type)
17411 {
17412 case NT_VERSION:
17413 return _("NT_VERSION (version)");
17414 case NT_ARCH:
17415 return _("NT_ARCH (architecture)");
9ef920e9 17416 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
6f156d7a 17417 return _("OPEN");
9ef920e9 17418 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
6f156d7a 17419 return _("func");
1ec5cd37
NC
17420 default:
17421 break;
17422 }
17423
e9e44622 17424 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
1ec5cd37 17425 return buff;
779fe533
NC
17426}
17427
32ec8896 17428static bfd_boolean
9ece1fa9
TT
17429print_core_note (Elf_Internal_Note *pnote)
17430{
17431 unsigned int addr_size = is_32bit_elf ? 4 : 8;
17432 bfd_vma count, page_size;
17433 unsigned char *descdata, *filenames, *descend;
17434
17435 if (pnote->type != NT_FILE)
04ac15ab
AS
17436 {
17437 if (do_wide)
17438 printf ("\n");
17439 return TRUE;
17440 }
9ece1fa9
TT
17441
17442#ifndef BFD64
17443 if (!is_32bit_elf)
17444 {
17445 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
17446 /* Still "successful". */
32ec8896 17447 return TRUE;
9ece1fa9
TT
17448 }
17449#endif
17450
17451 if (pnote->descsz < 2 * addr_size)
17452 {
32ec8896
NC
17453 error (_(" Malformed note - too short for header\n"));
17454 return FALSE;
9ece1fa9
TT
17455 }
17456
17457 descdata = (unsigned char *) pnote->descdata;
17458 descend = descdata + pnote->descsz;
17459
17460 if (descdata[pnote->descsz - 1] != '\0')
17461 {
32ec8896
NC
17462 error (_(" Malformed note - does not end with \\0\n"));
17463 return FALSE;
9ece1fa9
TT
17464 }
17465
17466 count = byte_get (descdata, addr_size);
17467 descdata += addr_size;
17468
17469 page_size = byte_get (descdata, addr_size);
17470 descdata += addr_size;
17471
5396a86e
AM
17472 if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size)
17473 || pnote->descsz < 2 * addr_size + count * 3 * addr_size)
9ece1fa9 17474 {
32ec8896
NC
17475 error (_(" Malformed note - too short for supplied file count\n"));
17476 return FALSE;
9ece1fa9
TT
17477 }
17478
17479 printf (_(" Page size: "));
17480 print_vma (page_size, DEC);
17481 printf ("\n");
17482
17483 printf (_(" %*s%*s%*s\n"),
17484 (int) (2 + 2 * addr_size), _("Start"),
17485 (int) (4 + 2 * addr_size), _("End"),
17486 (int) (4 + 2 * addr_size), _("Page Offset"));
17487 filenames = descdata + count * 3 * addr_size;
595712bb 17488 while (count-- > 0)
9ece1fa9
TT
17489 {
17490 bfd_vma start, end, file_ofs;
17491
17492 if (filenames == descend)
17493 {
32ec8896
NC
17494 error (_(" Malformed note - filenames end too early\n"));
17495 return FALSE;
9ece1fa9
TT
17496 }
17497
17498 start = byte_get (descdata, addr_size);
17499 descdata += addr_size;
17500 end = byte_get (descdata, addr_size);
17501 descdata += addr_size;
17502 file_ofs = byte_get (descdata, addr_size);
17503 descdata += addr_size;
17504
17505 printf (" ");
17506 print_vma (start, FULL_HEX);
17507 printf (" ");
17508 print_vma (end, FULL_HEX);
17509 printf (" ");
17510 print_vma (file_ofs, FULL_HEX);
17511 printf ("\n %s\n", filenames);
17512
17513 filenames += 1 + strlen ((char *) filenames);
17514 }
17515
32ec8896 17516 return TRUE;
9ece1fa9
TT
17517}
17518
1118d252
RM
17519static const char *
17520get_gnu_elf_note_type (unsigned e_type)
17521{
1449284b 17522 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
1118d252
RM
17523 switch (e_type)
17524 {
17525 case NT_GNU_ABI_TAG:
17526 return _("NT_GNU_ABI_TAG (ABI version tag)");
17527 case NT_GNU_HWCAP:
17528 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
17529 case NT_GNU_BUILD_ID:
17530 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
0297aed6
DM
17531 case NT_GNU_GOLD_VERSION:
17532 return _("NT_GNU_GOLD_VERSION (gold version)");
9ef920e9
NC
17533 case NT_GNU_PROPERTY_TYPE_0:
17534 return _("NT_GNU_PROPERTY_TYPE_0");
17535 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
17536 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
17537 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
17538 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
1118d252 17539 default:
1449284b
NC
17540 {
17541 static char buff[64];
1118d252 17542
1449284b
NC
17543 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17544 return buff;
17545 }
17546 }
1118d252
RM
17547}
17548
a9eafb08
L
17549static void
17550decode_x86_compat_isa (unsigned int bitmask)
17551{
17552 while (bitmask)
17553 {
17554 unsigned int bit = bitmask & (- bitmask);
17555
17556 bitmask &= ~ bit;
17557 switch (bit)
17558 {
17559 case GNU_PROPERTY_X86_COMPAT_ISA_1_486:
17560 printf ("i486");
17561 break;
17562 case GNU_PROPERTY_X86_COMPAT_ISA_1_586:
17563 printf ("586");
17564 break;
17565 case GNU_PROPERTY_X86_COMPAT_ISA_1_686:
17566 printf ("686");
17567 break;
17568 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE:
17569 printf ("SSE");
17570 break;
17571 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2:
17572 printf ("SSE2");
17573 break;
17574 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3:
17575 printf ("SSE3");
17576 break;
17577 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3:
17578 printf ("SSSE3");
17579 break;
17580 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1:
17581 printf ("SSE4_1");
17582 break;
17583 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2:
17584 printf ("SSE4_2");
17585 break;
17586 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX:
17587 printf ("AVX");
17588 break;
17589 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2:
17590 printf ("AVX2");
17591 break;
17592 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F:
17593 printf ("AVX512F");
17594 break;
17595 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD:
17596 printf ("AVX512CD");
17597 break;
17598 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER:
17599 printf ("AVX512ER");
17600 break;
17601 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF:
17602 printf ("AVX512PF");
17603 break;
17604 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL:
17605 printf ("AVX512VL");
17606 break;
17607 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ:
17608 printf ("AVX512DQ");
17609 break;
17610 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW:
17611 printf ("AVX512BW");
17612 break;
65b3d26e
L
17613 default:
17614 printf (_("<unknown: %x>"), bit);
17615 break;
a9eafb08
L
17616 }
17617 if (bitmask)
17618 printf (", ");
17619 }
17620}
17621
9ef920e9 17622static void
1fc87489 17623decode_x86_isa (unsigned int bitmask)
9ef920e9 17624{
0a59decb 17625 if (!bitmask)
90c745dc
L
17626 {
17627 printf (_("<None>"));
17628 return;
17629 }
90c745dc 17630
9ef920e9
NC
17631 while (bitmask)
17632 {
1fc87489 17633 unsigned int bit = bitmask & (- bitmask);
9ef920e9
NC
17634
17635 bitmask &= ~ bit;
17636 switch (bit)
17637 {
a9eafb08
L
17638 case GNU_PROPERTY_X86_ISA_1_CMOV:
17639 printf ("CMOV");
17640 break;
17641 case GNU_PROPERTY_X86_ISA_1_SSE:
17642 printf ("SSE");
17643 break;
17644 case GNU_PROPERTY_X86_ISA_1_SSE2:
17645 printf ("SSE2");
17646 break;
17647 case GNU_PROPERTY_X86_ISA_1_SSE3:
17648 printf ("SSE3");
17649 break;
17650 case GNU_PROPERTY_X86_ISA_1_SSSE3:
17651 printf ("SSSE3");
17652 break;
17653 case GNU_PROPERTY_X86_ISA_1_SSE4_1:
17654 printf ("SSE4_1");
17655 break;
17656 case GNU_PROPERTY_X86_ISA_1_SSE4_2:
17657 printf ("SSE4_2");
17658 break;
17659 case GNU_PROPERTY_X86_ISA_1_AVX:
17660 printf ("AVX");
17661 break;
17662 case GNU_PROPERTY_X86_ISA_1_AVX2:
17663 printf ("AVX2");
17664 break;
17665 case GNU_PROPERTY_X86_ISA_1_FMA:
17666 printf ("FMA");
17667 break;
17668 case GNU_PROPERTY_X86_ISA_1_AVX512F:
17669 printf ("AVX512F");
17670 break;
17671 case GNU_PROPERTY_X86_ISA_1_AVX512CD:
17672 printf ("AVX512CD");
17673 break;
17674 case GNU_PROPERTY_X86_ISA_1_AVX512ER:
17675 printf ("AVX512ER");
17676 break;
17677 case GNU_PROPERTY_X86_ISA_1_AVX512PF:
17678 printf ("AVX512PF");
17679 break;
17680 case GNU_PROPERTY_X86_ISA_1_AVX512VL:
17681 printf ("AVX512VL");
17682 break;
17683 case GNU_PROPERTY_X86_ISA_1_AVX512DQ:
17684 printf ("AVX512DQ");
17685 break;
17686 case GNU_PROPERTY_X86_ISA_1_AVX512BW:
17687 printf ("AVX512BW");
17688 break;
17689 case GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS:
17690 printf ("AVX512_4FMAPS");
17691 break;
17692 case GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW:
17693 printf ("AVX512_4VNNIW");
17694 break;
17695 case GNU_PROPERTY_X86_ISA_1_AVX512_BITALG:
17696 printf ("AVX512_BITALG");
17697 break;
17698 case GNU_PROPERTY_X86_ISA_1_AVX512_IFMA:
17699 printf ("AVX512_IFMA");
17700 break;
17701 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI:
17702 printf ("AVX512_VBMI");
17703 break;
17704 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2:
17705 printf ("AVX512_VBMI2");
17706 break;
17707 case GNU_PROPERTY_X86_ISA_1_AVX512_VNNI:
17708 printf ("AVX512_VNNI");
17709 break;
462cac58
L
17710 case GNU_PROPERTY_X86_ISA_1_AVX512_BF16:
17711 printf ("AVX512_BF16");
17712 break;
65b3d26e
L
17713 default:
17714 printf (_("<unknown: %x>"), bit);
17715 break;
9ef920e9
NC
17716 }
17717 if (bitmask)
17718 printf (", ");
17719 }
17720}
17721
abeeff98
LM
17722static const char *
17723get_amd_elf_note_type (unsigned e_type)
17724{
17725 static char buff[64];
17726
17727 switch (e_type)
17728 {
17729 case NT_AMDGPU_HSA_CODE_OBJECT_VERSION:
17730 return _("NT_AMDGPU_HSA_CODE_OBJECT_VERSION (code object version)");
17731 case NT_AMDGPU_HSA_HSAIL:
17732 return _("NT_AMDGPU_HSA_HSAIL (hsail)");
17733 case NT_AMDGPU_HSA_ISA:
17734 return _("NT_AMDGPU_HSA_ISA (ISA name)");
17735 case NT_AMDGPU_HSA_PRODUCER:
17736 return _("NT_AMDGPU_HSA_PRODUCER (producer name)");
17737 case NT_AMDGPU_HSA_PRODUCER_OPTIONS:
17738 return _("NT_AMDGPU_HSA_PRODUCER_OPTIONS (producer options");
17739 case NT_AMDGPU_HSA_EXTENSION:
17740 return _("NT_AMDGPU_HSA_EXTENSION (extension)");
17741 case NT_AMDGPU_HSA_METADATA:
17742 return _("NT_AMDGPU_HSA_METADATA (code object metadata)");
17743 case NT_AMDGPU_ISA:
17744 return _("NT_AMDGPU_ISA");
17745 case NT_AMDGPU_PAL_METADATA:
17746 return _("NT_AMDGPU_PAL_METADATA (code object metadata)");
17747 case NT_AMDGPU_METADATA:
17748 return _("NT_AMDGPU_METADATA (code object metadata)");
17749 default:
17750 break;
17751 }
17752
17753 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17754 return buff;
17755}
17756
17757static int
17758print_amd_note (Elf_Internal_Note *pnote)
17759{
17760 switch (pnote->type)
17761 {
17762 case NT_AMDGPU_HSA_CODE_OBJECT_VERSION:
17763 {
17764 unsigned int major, minor;
17765
17766 major = byte_get ((unsigned char*) pnote->descdata, 4);
17767 minor = byte_get ((unsigned char*) pnote->descdata + 4, 4);
17768
17769 printf (_(" Version: %d.%d\n"), major, minor);
17770 }
17771 break;
17772
17773 case NT_AMDGPU_HSA_ISA:
17774 {
17775 unsigned long i, vendorsz;
17776 unsigned int major, minor, stepping;
17777
17778 vendorsz = byte_get ((unsigned char*) pnote->descdata, 2);
17779 major = byte_get ((unsigned char*) pnote->descdata + 4, 4);
17780 minor = byte_get ((unsigned char*) pnote->descdata + 8, 4);
17781 stepping = byte_get ((unsigned char*) pnote->descdata + 12, 4);
17782
17783 printf (_(" Vendor: "));
17784 for (i = 16; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
17785 printf ("%c", pnote->descdata[i]);
17786 printf (_(", Architecture: "));
17787 for (i = 16 + vendorsz; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
17788 printf ("%c", pnote->descdata[i]);
17789
17790 printf (_(", Version: %d.%d.%d"), major, minor, stepping);
17791 printf ("\n");
17792 }
17793 break;
17794 }
17795 return 1;
17796}
17797
ee2fdd6f 17798static void
a9eafb08 17799decode_x86_feature_1 (unsigned int bitmask)
ee2fdd6f 17800{
0a59decb 17801 if (!bitmask)
90c745dc
L
17802 {
17803 printf (_("<None>"));
17804 return;
17805 }
90c745dc 17806
ee2fdd6f
L
17807 while (bitmask)
17808 {
17809 unsigned int bit = bitmask & (- bitmask);
17810
17811 bitmask &= ~ bit;
17812 switch (bit)
17813 {
17814 case GNU_PROPERTY_X86_FEATURE_1_IBT:
a9eafb08 17815 printf ("IBT");
ee2fdd6f 17816 break;
48580982 17817 case GNU_PROPERTY_X86_FEATURE_1_SHSTK:
a9eafb08 17818 printf ("SHSTK");
48580982 17819 break;
ee2fdd6f
L
17820 default:
17821 printf (_("<unknown: %x>"), bit);
17822 break;
17823 }
17824 if (bitmask)
17825 printf (", ");
17826 }
17827}
17828
a9eafb08
L
17829static void
17830decode_x86_feature_2 (unsigned int bitmask)
17831{
0a59decb 17832 if (!bitmask)
90c745dc
L
17833 {
17834 printf (_("<None>"));
17835 return;
17836 }
90c745dc 17837
a9eafb08
L
17838 while (bitmask)
17839 {
17840 unsigned int bit = bitmask & (- bitmask);
17841
17842 bitmask &= ~ bit;
17843 switch (bit)
17844 {
17845 case GNU_PROPERTY_X86_FEATURE_2_X86:
17846 printf ("x86");
17847 break;
17848 case GNU_PROPERTY_X86_FEATURE_2_X87:
17849 printf ("x87");
17850 break;
17851 case GNU_PROPERTY_X86_FEATURE_2_MMX:
17852 printf ("MMX");
17853 break;
17854 case GNU_PROPERTY_X86_FEATURE_2_XMM:
17855 printf ("XMM");
17856 break;
17857 case GNU_PROPERTY_X86_FEATURE_2_YMM:
17858 printf ("YMM");
17859 break;
17860 case GNU_PROPERTY_X86_FEATURE_2_ZMM:
17861 printf ("ZMM");
17862 break;
17863 case GNU_PROPERTY_X86_FEATURE_2_FXSR:
17864 printf ("FXSR");
17865 break;
17866 case GNU_PROPERTY_X86_FEATURE_2_XSAVE:
17867 printf ("XSAVE");
17868 break;
17869 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT:
17870 printf ("XSAVEOPT");
17871 break;
17872 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC:
17873 printf ("XSAVEC");
17874 break;
65b3d26e
L
17875 default:
17876 printf (_("<unknown: %x>"), bit);
17877 break;
a9eafb08
L
17878 }
17879 if (bitmask)
17880 printf (", ");
17881 }
17882}
17883
cd702818
SD
17884static void
17885decode_aarch64_feature_1_and (unsigned int bitmask)
17886{
17887 while (bitmask)
17888 {
17889 unsigned int bit = bitmask & (- bitmask);
17890
17891 bitmask &= ~ bit;
17892 switch (bit)
17893 {
17894 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI:
17895 printf ("BTI");
17896 break;
17897
17898 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC:
17899 printf ("PAC");
17900 break;
17901
17902 default:
17903 printf (_("<unknown: %x>"), bit);
17904 break;
17905 }
17906 if (bitmask)
17907 printf (", ");
17908 }
17909}
17910
9ef920e9 17911static void
dda8d76d 17912print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
9ef920e9
NC
17913{
17914 unsigned char * ptr = (unsigned char *) pnote->descdata;
17915 unsigned char * ptr_end = ptr + pnote->descsz;
17916 unsigned int size = is_32bit_elf ? 4 : 8;
17917
17918 printf (_(" Properties: "));
17919
1fc87489 17920 if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
9ef920e9
NC
17921 {
17922 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
17923 return;
17924 }
17925
6ab2c4ed 17926 while (ptr < ptr_end)
9ef920e9 17927 {
1fc87489 17928 unsigned int j;
6ab2c4ed
MC
17929 unsigned int type;
17930 unsigned int datasz;
17931
17932 if ((size_t) (ptr_end - ptr) < 8)
17933 {
17934 printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
17935 break;
17936 }
17937
17938 type = byte_get (ptr, 4);
17939 datasz = byte_get (ptr + 4, 4);
9ef920e9 17940
1fc87489 17941 ptr += 8;
9ef920e9 17942
6ab2c4ed 17943 if (datasz > (size_t) (ptr_end - ptr))
9ef920e9 17944 {
1fc87489
L
17945 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
17946 type, datasz);
9ef920e9 17947 break;
1fc87489 17948 }
9ef920e9 17949
1fc87489
L
17950 if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
17951 {
dda8d76d
NC
17952 if (filedata->file_header.e_machine == EM_X86_64
17953 || filedata->file_header.e_machine == EM_IAMCU
17954 || filedata->file_header.e_machine == EM_386)
1fc87489 17955 {
aa7bca9b
L
17956 unsigned int bitmask;
17957
17958 if (datasz == 4)
0a59decb 17959 bitmask = byte_get (ptr, 4);
aa7bca9b
L
17960 else
17961 bitmask = 0;
17962
1fc87489
L
17963 switch (type)
17964 {
17965 case GNU_PROPERTY_X86_ISA_1_USED:
1fc87489 17966 if (datasz != 4)
aa7bca9b
L
17967 printf (_("x86 ISA used: <corrupt length: %#x> "),
17968 datasz);
1fc87489 17969 else
aa7bca9b
L
17970 {
17971 printf ("x86 ISA used: ");
17972 decode_x86_isa (bitmask);
17973 }
1fc87489 17974 goto next;
9ef920e9 17975
1fc87489 17976 case GNU_PROPERTY_X86_ISA_1_NEEDED:
1fc87489 17977 if (datasz != 4)
aa7bca9b
L
17978 printf (_("x86 ISA needed: <corrupt length: %#x> "),
17979 datasz);
1fc87489 17980 else
aa7bca9b
L
17981 {
17982 printf ("x86 ISA needed: ");
17983 decode_x86_isa (bitmask);
17984 }
1fc87489 17985 goto next;
9ef920e9 17986
ee2fdd6f 17987 case GNU_PROPERTY_X86_FEATURE_1_AND:
ee2fdd6f 17988 if (datasz != 4)
aa7bca9b
L
17989 printf (_("x86 feature: <corrupt length: %#x> "),
17990 datasz);
ee2fdd6f 17991 else
aa7bca9b
L
17992 {
17993 printf ("x86 feature: ");
a9eafb08
L
17994 decode_x86_feature_1 (bitmask);
17995 }
17996 goto next;
17997
17998 case GNU_PROPERTY_X86_FEATURE_2_USED:
17999 if (datasz != 4)
18000 printf (_("x86 feature used: <corrupt length: %#x> "),
18001 datasz);
18002 else
18003 {
18004 printf ("x86 feature used: ");
18005 decode_x86_feature_2 (bitmask);
18006 }
18007 goto next;
18008
18009 case GNU_PROPERTY_X86_FEATURE_2_NEEDED:
18010 if (datasz != 4)
18011 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz);
18012 else
18013 {
18014 printf ("x86 feature needed: ");
18015 decode_x86_feature_2 (bitmask);
18016 }
18017 goto next;
18018
18019 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
18020 if (datasz != 4)
18021 printf (_("x86 ISA used: <corrupt length: %#x> "),
18022 datasz);
18023 else
18024 {
18025 printf ("x86 ISA used: ");
18026 decode_x86_compat_isa (bitmask);
18027 }
18028 goto next;
18029
18030 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
18031 if (datasz != 4)
18032 printf (_("x86 ISA needed: <corrupt length: %#x> "),
18033 datasz);
18034 else
18035 {
18036 printf ("x86 ISA needed: ");
18037 decode_x86_compat_isa (bitmask);
aa7bca9b 18038 }
ee2fdd6f
L
18039 goto next;
18040
1fc87489
L
18041 default:
18042 break;
18043 }
18044 }
cd702818
SD
18045 else if (filedata->file_header.e_machine == EM_AARCH64)
18046 {
18047 if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
18048 {
18049 printf ("AArch64 feature: ");
18050 if (datasz != 4)
18051 printf (_("<corrupt length: %#x> "), datasz);
18052 else
18053 decode_aarch64_feature_1_and (byte_get (ptr, 4));
18054 goto next;
18055 }
18056 }
1fc87489
L
18057 }
18058 else
18059 {
18060 switch (type)
9ef920e9 18061 {
1fc87489
L
18062 case GNU_PROPERTY_STACK_SIZE:
18063 printf (_("stack size: "));
18064 if (datasz != size)
18065 printf (_("<corrupt length: %#x> "), datasz);
18066 else
18067 printf ("%#lx", (unsigned long) byte_get (ptr, size));
18068 goto next;
18069
18070 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
18071 printf ("no copy on protected ");
18072 if (datasz)
18073 printf (_("<corrupt length: %#x> "), datasz);
18074 goto next;
18075
18076 default:
9ef920e9
NC
18077 break;
18078 }
9ef920e9
NC
18079 }
18080
1fc87489
L
18081 if (type < GNU_PROPERTY_LOPROC)
18082 printf (_("<unknown type %#x data: "), type);
18083 else if (type < GNU_PROPERTY_LOUSER)
18084 printf (_("<procesor-specific type %#x data: "), type);
18085 else
18086 printf (_("<application-specific type %#x data: "), type);
18087 for (j = 0; j < datasz; ++j)
18088 printf ("%02x ", ptr[j] & 0xff);
18089 printf (">");
18090
18091next:
9ef920e9 18092 ptr += ((datasz + (size - 1)) & ~ (size - 1));
1fc87489
L
18093 if (ptr == ptr_end)
18094 break;
1fc87489 18095
6ab2c4ed
MC
18096 if (do_wide)
18097 printf (", ");
18098 else
18099 printf ("\n\t");
9ef920e9
NC
18100 }
18101
18102 printf ("\n");
18103}
18104
32ec8896 18105static bfd_boolean
dda8d76d 18106print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote)
664f90a3 18107{
1449284b 18108 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
664f90a3
TT
18109 switch (pnote->type)
18110 {
18111 case NT_GNU_BUILD_ID:
18112 {
18113 unsigned long i;
18114
18115 printf (_(" Build ID: "));
18116 for (i = 0; i < pnote->descsz; ++i)
18117 printf ("%02x", pnote->descdata[i] & 0xff);
9cf03b7e 18118 printf ("\n");
664f90a3
TT
18119 }
18120 break;
18121
18122 case NT_GNU_ABI_TAG:
18123 {
18124 unsigned long os, major, minor, subminor;
18125 const char *osname;
18126
3102e897
NC
18127 /* PR 17531: file: 030-599401-0.004. */
18128 if (pnote->descsz < 16)
18129 {
18130 printf (_(" <corrupt GNU_ABI_TAG>\n"));
18131 break;
18132 }
18133
664f90a3
TT
18134 os = byte_get ((unsigned char *) pnote->descdata, 4);
18135 major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
18136 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
18137 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
18138
18139 switch (os)
18140 {
18141 case GNU_ABI_TAG_LINUX:
18142 osname = "Linux";
18143 break;
18144 case GNU_ABI_TAG_HURD:
18145 osname = "Hurd";
18146 break;
18147 case GNU_ABI_TAG_SOLARIS:
18148 osname = "Solaris";
18149 break;
18150 case GNU_ABI_TAG_FREEBSD:
18151 osname = "FreeBSD";
18152 break;
18153 case GNU_ABI_TAG_NETBSD:
18154 osname = "NetBSD";
18155 break;
14ae95f2
RM
18156 case GNU_ABI_TAG_SYLLABLE:
18157 osname = "Syllable";
18158 break;
18159 case GNU_ABI_TAG_NACL:
18160 osname = "NaCl";
18161 break;
664f90a3
TT
18162 default:
18163 osname = "Unknown";
18164 break;
18165 }
18166
18167 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
18168 major, minor, subminor);
18169 }
18170 break;
926c5385
CC
18171
18172 case NT_GNU_GOLD_VERSION:
18173 {
18174 unsigned long i;
18175
18176 printf (_(" Version: "));
18177 for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
18178 printf ("%c", pnote->descdata[i]);
18179 printf ("\n");
18180 }
18181 break;
1449284b
NC
18182
18183 case NT_GNU_HWCAP:
18184 {
18185 unsigned long num_entries, mask;
18186
18187 /* Hardware capabilities information. Word 0 is the number of entries.
18188 Word 1 is a bitmask of enabled entries. The rest of the descriptor
18189 is a series of entries, where each entry is a single byte followed
18190 by a nul terminated string. The byte gives the bit number to test
18191 if enabled in the bitmask. */
18192 printf (_(" Hardware Capabilities: "));
18193 if (pnote->descsz < 8)
18194 {
32ec8896
NC
18195 error (_("<corrupt GNU_HWCAP>\n"));
18196 return FALSE;
1449284b
NC
18197 }
18198 num_entries = byte_get ((unsigned char *) pnote->descdata, 4);
18199 mask = byte_get ((unsigned char *) pnote->descdata + 4, 4);
18200 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask);
18201 /* FIXME: Add code to display the entries... */
18202 }
18203 break;
18204
9ef920e9 18205 case NT_GNU_PROPERTY_TYPE_0:
dda8d76d 18206 print_gnu_property_note (filedata, pnote);
9ef920e9 18207 break;
9abca702 18208
1449284b
NC
18209 default:
18210 /* Handle unrecognised types. An error message should have already been
18211 created by get_gnu_elf_note_type(), so all that we need to do is to
18212 display the data. */
18213 {
18214 unsigned long i;
18215
18216 printf (_(" Description data: "));
18217 for (i = 0; i < pnote->descsz; ++i)
18218 printf ("%02x ", pnote->descdata[i] & 0xff);
18219 printf ("\n");
18220 }
18221 break;
664f90a3
TT
18222 }
18223
32ec8896 18224 return TRUE;
664f90a3
TT
18225}
18226
685080f2
NC
18227static const char *
18228get_v850_elf_note_type (enum v850_notes n_type)
18229{
18230 static char buff[64];
18231
18232 switch (n_type)
18233 {
18234 case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects");
18235 case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double");
18236 case V850_NOTE_FPU_INFO: return _("Type of FPU support needed");
18237 case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions");
18238 case V850_NOTE_CACHE_INFO: return _("Use of cache");
18239 case V850_NOTE_MMU_INFO: return _("Use of MMU");
18240 default:
18241 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
18242 return buff;
18243 }
18244}
18245
32ec8896 18246static bfd_boolean
685080f2
NC
18247print_v850_note (Elf_Internal_Note * pnote)
18248{
18249 unsigned int val;
18250
18251 if (pnote->descsz != 4)
32ec8896
NC
18252 return FALSE;
18253
685080f2
NC
18254 val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
18255
18256 if (val == 0)
18257 {
18258 printf (_("not set\n"));
32ec8896 18259 return TRUE;
685080f2
NC
18260 }
18261
18262 switch (pnote->type)
18263 {
18264 case V850_NOTE_ALIGNMENT:
18265 switch (val)
18266 {
32ec8896
NC
18267 case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE;
18268 case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE;
685080f2
NC
18269 }
18270 break;
14ae95f2 18271
685080f2
NC
18272 case V850_NOTE_DATA_SIZE:
18273 switch (val)
18274 {
32ec8896
NC
18275 case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE;
18276 case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE;
685080f2
NC
18277 }
18278 break;
14ae95f2 18279
685080f2
NC
18280 case V850_NOTE_FPU_INFO:
18281 switch (val)
18282 {
32ec8896
NC
18283 case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE;
18284 case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE;
685080f2
NC
18285 }
18286 break;
14ae95f2 18287
685080f2
NC
18288 case V850_NOTE_MMU_INFO:
18289 case V850_NOTE_CACHE_INFO:
18290 case V850_NOTE_SIMD_INFO:
18291 if (val == EF_RH850_SIMD)
18292 {
18293 printf (_("yes\n"));
32ec8896 18294 return TRUE;
685080f2
NC
18295 }
18296 break;
18297
18298 default:
18299 /* An 'unknown note type' message will already have been displayed. */
18300 break;
18301 }
18302
18303 printf (_("unknown value: %x\n"), val);
32ec8896 18304 return FALSE;
685080f2
NC
18305}
18306
32ec8896 18307static bfd_boolean
c6056a74
SF
18308process_netbsd_elf_note (Elf_Internal_Note * pnote)
18309{
18310 unsigned int version;
18311
18312 switch (pnote->type)
18313 {
18314 case NT_NETBSD_IDENT:
18315 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
18316 if ((version / 10000) % 100)
18317 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
18318 version, version / 100000000, (version / 1000000) % 100,
18319 (version / 10000) % 100 > 26 ? "Z" : "",
15f205b1 18320 'A' + (version / 10000) % 26);
c6056a74
SF
18321 else
18322 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
18323 version, version / 100000000, (version / 1000000) % 100,
15f205b1 18324 (version / 100) % 100);
32ec8896 18325 return TRUE;
c6056a74
SF
18326
18327 case NT_NETBSD_MARCH:
9abca702 18328 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
c6056a74 18329 pnote->descdata);
32ec8896 18330 return TRUE;
c6056a74 18331
9abca702
CZ
18332#ifdef NT_NETBSD_PAX
18333 case NT_NETBSD_PAX:
18334 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
18335 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz,
18336 ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""),
18337 ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""),
18338 ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""),
18339 ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""),
18340 ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""),
18341 ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : ""));
18342 return TRUE;
18343#endif
18344
c6056a74 18345 default:
32ec8896
NC
18346 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
18347 pnote->type);
18348 return FALSE;
c6056a74 18349 }
c6056a74
SF
18350}
18351
f4ddf30f 18352static const char *
dda8d76d 18353get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
f4ddf30f 18354{
f4ddf30f
JB
18355 switch (e_type)
18356 {
18357 case NT_FREEBSD_THRMISC:
18358 return _("NT_THRMISC (thrmisc structure)");
18359 case NT_FREEBSD_PROCSTAT_PROC:
18360 return _("NT_PROCSTAT_PROC (proc data)");
18361 case NT_FREEBSD_PROCSTAT_FILES:
18362 return _("NT_PROCSTAT_FILES (files data)");
18363 case NT_FREEBSD_PROCSTAT_VMMAP:
18364 return _("NT_PROCSTAT_VMMAP (vmmap data)");
18365 case NT_FREEBSD_PROCSTAT_GROUPS:
18366 return _("NT_PROCSTAT_GROUPS (groups data)");
18367 case NT_FREEBSD_PROCSTAT_UMASK:
18368 return _("NT_PROCSTAT_UMASK (umask data)");
18369 case NT_FREEBSD_PROCSTAT_RLIMIT:
18370 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
18371 case NT_FREEBSD_PROCSTAT_OSREL:
18372 return _("NT_PROCSTAT_OSREL (osreldate data)");
18373 case NT_FREEBSD_PROCSTAT_PSSTRINGS:
18374 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
18375 case NT_FREEBSD_PROCSTAT_AUXV:
18376 return _("NT_PROCSTAT_AUXV (auxv data)");
0b9305ed
JB
18377 case NT_FREEBSD_PTLWPINFO:
18378 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
f4ddf30f 18379 }
dda8d76d 18380 return get_note_type (filedata, e_type);
f4ddf30f
JB
18381}
18382
9437c45b 18383static const char *
dda8d76d 18384get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
9437c45b
JT
18385{
18386 static char buff[64];
18387
540e6170
CZ
18388 switch (e_type)
18389 {
18390 case NT_NETBSDCORE_PROCINFO:
18391 /* NetBSD core "procinfo" structure. */
18392 return _("NetBSD procinfo structure");
9437c45b 18393
540e6170
CZ
18394#ifdef NT_NETBSDCORE_AUXV
18395 case NT_NETBSDCORE_AUXV:
18396 return _("NetBSD ELF auxiliary vector data");
18397#endif
9437c45b 18398
540e6170
CZ
18399 default:
18400 /* As of Jan 2002 there are no other machine-independent notes
18401 defined for NetBSD core files. If the note type is less
18402 than the start of the machine-dependent note types, we don't
18403 understand it. */
18404
18405 if (e_type < NT_NETBSDCORE_FIRSTMACH)
18406 {
18407 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18408 return buff;
18409 }
18410 break;
9437c45b
JT
18411 }
18412
dda8d76d 18413 switch (filedata->file_header.e_machine)
9437c45b
JT
18414 {
18415 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
18416 and PT_GETFPREGS == mach+2. */
18417
18418 case EM_OLD_ALPHA:
18419 case EM_ALPHA:
18420 case EM_SPARC:
18421 case EM_SPARC32PLUS:
18422 case EM_SPARCV9:
18423 switch (e_type)
18424 {
2b692964 18425 case NT_NETBSDCORE_FIRSTMACH + 0:
b4db1224 18426 return _("PT_GETREGS (reg structure)");
2b692964 18427 case NT_NETBSDCORE_FIRSTMACH + 2:
b4db1224 18428 return _("PT_GETFPREGS (fpreg structure)");
9437c45b
JT
18429 default:
18430 break;
18431 }
18432 break;
18433
c0d38b0e
CZ
18434 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
18435 There's also old PT___GETREGS40 == mach + 1 for old reg
18436 structure which lacks GBR. */
18437 case EM_SH:
18438 switch (e_type)
18439 {
18440 case NT_NETBSDCORE_FIRSTMACH + 1:
18441 return _("PT___GETREGS40 (old reg structure)");
18442 case NT_NETBSDCORE_FIRSTMACH + 3:
18443 return _("PT_GETREGS (reg structure)");
18444 case NT_NETBSDCORE_FIRSTMACH + 5:
18445 return _("PT_GETFPREGS (fpreg structure)");
18446 default:
18447 break;
18448 }
18449 break;
18450
9437c45b
JT
18451 /* On all other arch's, PT_GETREGS == mach+1 and
18452 PT_GETFPREGS == mach+3. */
18453 default:
18454 switch (e_type)
18455 {
2b692964 18456 case NT_NETBSDCORE_FIRSTMACH + 1:
b4db1224 18457 return _("PT_GETREGS (reg structure)");
2b692964 18458 case NT_NETBSDCORE_FIRSTMACH + 3:
b4db1224 18459 return _("PT_GETFPREGS (fpreg structure)");
9437c45b
JT
18460 default:
18461 break;
18462 }
18463 }
18464
9cf03b7e 18465 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
e9e44622 18466 e_type - NT_NETBSDCORE_FIRSTMACH);
9437c45b
JT
18467 return buff;
18468}
18469
70616151
TT
18470static const char *
18471get_stapsdt_note_type (unsigned e_type)
18472{
18473 static char buff[64];
18474
18475 switch (e_type)
18476 {
18477 case NT_STAPSDT:
18478 return _("NT_STAPSDT (SystemTap probe descriptors)");
18479
18480 default:
18481 break;
18482 }
18483
18484 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18485 return buff;
18486}
18487
32ec8896 18488static bfd_boolean
c6a9fc58
TT
18489print_stapsdt_note (Elf_Internal_Note *pnote)
18490{
3ca60c57
NC
18491 size_t len, maxlen;
18492 unsigned long addr_size = is_32bit_elf ? 4 : 8;
c6a9fc58
TT
18493 char *data = pnote->descdata;
18494 char *data_end = pnote->descdata + pnote->descsz;
18495 bfd_vma pc, base_addr, semaphore;
18496 char *provider, *probe, *arg_fmt;
18497
3ca60c57
NC
18498 if (pnote->descsz < (addr_size * 3))
18499 goto stapdt_note_too_small;
18500
c6a9fc58
TT
18501 pc = byte_get ((unsigned char *) data, addr_size);
18502 data += addr_size;
3ca60c57 18503
c6a9fc58
TT
18504 base_addr = byte_get ((unsigned char *) data, addr_size);
18505 data += addr_size;
3ca60c57 18506
c6a9fc58
TT
18507 semaphore = byte_get ((unsigned char *) data, addr_size);
18508 data += addr_size;
18509
3ca60c57
NC
18510 if (data >= data_end)
18511 goto stapdt_note_too_small;
18512 maxlen = data_end - data;
18513 len = strnlen (data, maxlen);
18514 if (len < maxlen)
18515 {
18516 provider = data;
18517 data += len + 1;
18518 }
18519 else
18520 goto stapdt_note_too_small;
18521
18522 if (data >= data_end)
18523 goto stapdt_note_too_small;
18524 maxlen = data_end - data;
18525 len = strnlen (data, maxlen);
18526 if (len < maxlen)
18527 {
18528 probe = data;
18529 data += len + 1;
18530 }
18531 else
18532 goto stapdt_note_too_small;
9abca702 18533
3ca60c57
NC
18534 if (data >= data_end)
18535 goto stapdt_note_too_small;
18536 maxlen = data_end - data;
18537 len = strnlen (data, maxlen);
18538 if (len < maxlen)
18539 {
18540 arg_fmt = data;
18541 data += len + 1;
18542 }
18543 else
18544 goto stapdt_note_too_small;
c6a9fc58
TT
18545
18546 printf (_(" Provider: %s\n"), provider);
18547 printf (_(" Name: %s\n"), probe);
18548 printf (_(" Location: "));
18549 print_vma (pc, FULL_HEX);
18550 printf (_(", Base: "));
18551 print_vma (base_addr, FULL_HEX);
18552 printf (_(", Semaphore: "));
18553 print_vma (semaphore, FULL_HEX);
9cf03b7e 18554 printf ("\n");
c6a9fc58
TT
18555 printf (_(" Arguments: %s\n"), arg_fmt);
18556
18557 return data == data_end;
3ca60c57
NC
18558
18559 stapdt_note_too_small:
18560 printf (_(" <corrupt - note is too small>\n"));
18561 error (_("corrupt stapdt note - the data size is too small\n"));
18562 return FALSE;
c6a9fc58
TT
18563}
18564
00e98fc7
TG
18565static const char *
18566get_ia64_vms_note_type (unsigned e_type)
18567{
18568 static char buff[64];
18569
18570 switch (e_type)
18571 {
18572 case NT_VMS_MHD:
18573 return _("NT_VMS_MHD (module header)");
18574 case NT_VMS_LNM:
18575 return _("NT_VMS_LNM (language name)");
18576 case NT_VMS_SRC:
18577 return _("NT_VMS_SRC (source files)");
18578 case NT_VMS_TITLE:
9cf03b7e 18579 return "NT_VMS_TITLE";
00e98fc7
TG
18580 case NT_VMS_EIDC:
18581 return _("NT_VMS_EIDC (consistency check)");
18582 case NT_VMS_FPMODE:
18583 return _("NT_VMS_FPMODE (FP mode)");
18584 case NT_VMS_LINKTIME:
9cf03b7e 18585 return "NT_VMS_LINKTIME";
00e98fc7
TG
18586 case NT_VMS_IMGNAM:
18587 return _("NT_VMS_IMGNAM (image name)");
18588 case NT_VMS_IMGID:
18589 return _("NT_VMS_IMGID (image id)");
18590 case NT_VMS_LINKID:
18591 return _("NT_VMS_LINKID (link id)");
18592 case NT_VMS_IMGBID:
18593 return _("NT_VMS_IMGBID (build id)");
18594 case NT_VMS_GSTNAM:
18595 return _("NT_VMS_GSTNAM (sym table name)");
18596 case NT_VMS_ORIG_DYN:
9cf03b7e 18597 return "NT_VMS_ORIG_DYN";
00e98fc7 18598 case NT_VMS_PATCHTIME:
9cf03b7e 18599 return "NT_VMS_PATCHTIME";
00e98fc7
TG
18600 default:
18601 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18602 return buff;
18603 }
18604}
18605
32ec8896 18606static bfd_boolean
00e98fc7
TG
18607print_ia64_vms_note (Elf_Internal_Note * pnote)
18608{
8d18bf79
NC
18609 int maxlen = pnote->descsz;
18610
18611 if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz)
18612 goto desc_size_fail;
18613
00e98fc7
TG
18614 switch (pnote->type)
18615 {
18616 case NT_VMS_MHD:
8d18bf79
NC
18617 if (maxlen <= 36)
18618 goto desc_size_fail;
18619
18620 int l = (int) strnlen (pnote->descdata + 34, maxlen - 34);
18621
18622 printf (_(" Creation date : %.17s\n"), pnote->descdata);
18623 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
18624 if (l + 34 < maxlen)
18625 {
18626 printf (_(" Module name : %s\n"), pnote->descdata + 34);
18627 if (l + 35 < maxlen)
18628 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
18629 else
18630 printf (_(" Module version : <missing>\n"));
18631 }
00e98fc7 18632 else
8d18bf79
NC
18633 {
18634 printf (_(" Module name : <missing>\n"));
18635 printf (_(" Module version : <missing>\n"));
18636 }
00e98fc7 18637 break;
8d18bf79 18638
00e98fc7 18639 case NT_VMS_LNM:
8d18bf79 18640 printf (_(" Language: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18641 break;
8d18bf79 18642
00e98fc7
TG
18643#ifdef BFD64
18644 case NT_VMS_FPMODE:
9cf03b7e 18645 printf (_(" Floating Point mode: "));
8d18bf79
NC
18646 if (maxlen < 8)
18647 goto desc_size_fail;
18648 /* FIXME: Generate an error if descsz > 8 ? */
18649
4a5cb34f 18650 printf ("0x%016" BFD_VMA_FMT "x\n",
8d18bf79 18651 (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7 18652 break;
8d18bf79 18653
00e98fc7
TG
18654 case NT_VMS_LINKTIME:
18655 printf (_(" Link time: "));
8d18bf79
NC
18656 if (maxlen < 8)
18657 goto desc_size_fail;
18658 /* FIXME: Generate an error if descsz > 8 ? */
18659
00e98fc7 18660 print_vms_time
8d18bf79 18661 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7
TG
18662 printf ("\n");
18663 break;
8d18bf79 18664
00e98fc7
TG
18665 case NT_VMS_PATCHTIME:
18666 printf (_(" Patch time: "));
8d18bf79
NC
18667 if (maxlen < 8)
18668 goto desc_size_fail;
18669 /* FIXME: Generate an error if descsz > 8 ? */
18670
00e98fc7 18671 print_vms_time
8d18bf79 18672 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7
TG
18673 printf ("\n");
18674 break;
8d18bf79 18675
00e98fc7 18676 case NT_VMS_ORIG_DYN:
8d18bf79
NC
18677 if (maxlen < 34)
18678 goto desc_size_fail;
18679
00e98fc7
TG
18680 printf (_(" Major id: %u, minor id: %u\n"),
18681 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
18682 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
9cf03b7e 18683 printf (_(" Last modified : "));
00e98fc7
TG
18684 print_vms_time
18685 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
9cf03b7e 18686 printf (_("\n Link flags : "));
4a5cb34f 18687 printf ("0x%016" BFD_VMA_FMT "x\n",
948f632f 18688 (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
00e98fc7 18689 printf (_(" Header flags: 0x%08x\n"),
948f632f 18690 (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
8d18bf79 18691 printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32);
00e98fc7
TG
18692 break;
18693#endif
8d18bf79 18694
00e98fc7 18695 case NT_VMS_IMGNAM:
8d18bf79 18696 printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18697 break;
8d18bf79 18698
00e98fc7 18699 case NT_VMS_GSTNAM:
8d18bf79 18700 printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18701 break;
8d18bf79 18702
00e98fc7 18703 case NT_VMS_IMGID:
8d18bf79 18704 printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18705 break;
8d18bf79 18706
00e98fc7 18707 case NT_VMS_LINKID:
8d18bf79 18708 printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 18709 break;
8d18bf79 18710
00e98fc7 18711 default:
32ec8896 18712 return FALSE;
00e98fc7 18713 }
8d18bf79 18714
32ec8896 18715 return TRUE;
8d18bf79
NC
18716
18717 desc_size_fail:
18718 printf (_(" <corrupt - data size is too small>\n"));
18719 error (_("corrupt IA64 note: data size is too small\n"));
18720 return FALSE;
00e98fc7
TG
18721}
18722
6f156d7a
NC
18723/* Find the symbol associated with a build attribute that is attached
18724 to address OFFSET. If PNAME is non-NULL then store the name of
18725 the symbol (if found) in the provided pointer, Returns NULL if a
18726 symbol could not be found. */
c799a79d 18727
6f156d7a
NC
18728static Elf_Internal_Sym *
18729get_symbol_for_build_attribute (Filedata * filedata,
18730 unsigned long offset,
18731 bfd_boolean is_open_attr,
18732 const char ** pname)
9ef920e9 18733{
dda8d76d 18734 static Filedata * saved_filedata = NULL;
c799a79d
NC
18735 static char * strtab;
18736 static unsigned long strtablen;
18737 static Elf_Internal_Sym * symtab;
18738 static unsigned long nsyms;
7296a62a
NC
18739 Elf_Internal_Sym * saved_sym = NULL;
18740 Elf_Internal_Sym * sym;
9ef920e9 18741
dda8d76d
NC
18742 if (filedata->section_headers != NULL
18743 && (saved_filedata == NULL || filedata != saved_filedata))
9ef920e9 18744 {
c799a79d 18745 Elf_Internal_Shdr * symsec;
9ef920e9 18746
c799a79d 18747 /* Load the symbol and string sections. */
dda8d76d
NC
18748 for (symsec = filedata->section_headers;
18749 symsec < filedata->section_headers + filedata->file_header.e_shnum;
c799a79d 18750 symsec ++)
9ef920e9 18751 {
c799a79d 18752 if (symsec->sh_type == SHT_SYMTAB)
9ef920e9 18753 {
dda8d76d 18754 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
9ef920e9 18755
dda8d76d 18756 if (symsec->sh_link < filedata->file_header.e_shnum)
c799a79d 18757 {
dda8d76d 18758 Elf_Internal_Shdr * strtab_sec = filedata->section_headers + symsec->sh_link;
c799a79d 18759
dda8d76d 18760 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
c799a79d
NC
18761 1, strtab_sec->sh_size,
18762 _("string table"));
18763 strtablen = strtab != NULL ? strtab_sec->sh_size : 0;
18764 }
9ef920e9
NC
18765 }
18766 }
dda8d76d 18767 saved_filedata = filedata;
9ef920e9
NC
18768 }
18769
c799a79d 18770 if (symtab == NULL || strtab == NULL)
6f156d7a 18771 return NULL;
9ef920e9 18772
c799a79d
NC
18773 /* Find a symbol whose value matches offset. */
18774 for (sym = symtab; sym < symtab + nsyms; sym ++)
18775 if (sym->st_value == offset)
18776 {
18777 if (sym->st_name >= strtablen)
18778 /* Huh ? This should not happen. */
18779 continue;
9ef920e9 18780
c799a79d
NC
18781 if (strtab[sym->st_name] == 0)
18782 continue;
9ef920e9 18783
8fd75781
NC
18784 /* The AArch64 and ARM architectures define mapping symbols
18785 (eg $d, $x, $t) which we want to ignore. */
18786 if (strtab[sym->st_name] == '$'
18787 && strtab[sym->st_name + 1] != 0
18788 && strtab[sym->st_name + 2] == 0)
18789 continue;
18790
c799a79d
NC
18791 if (is_open_attr)
18792 {
18793 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
18794 and FILE or OBJECT symbols over NOTYPE symbols. We skip
18795 FUNC symbols entirely. */
18796 switch (ELF_ST_TYPE (sym->st_info))
18797 {
c799a79d 18798 case STT_OBJECT:
6f156d7a 18799 case STT_FILE:
c799a79d 18800 saved_sym = sym;
6f156d7a
NC
18801 if (sym->st_size)
18802 {
18803 /* If the symbol has a size associated
18804 with it then we can stop searching. */
18805 sym = symtab + nsyms;
18806 }
c799a79d 18807 continue;
9ef920e9 18808
c799a79d
NC
18809 case STT_FUNC:
18810 /* Ignore function symbols. */
18811 continue;
18812
18813 default:
18814 break;
18815 }
18816
18817 switch (ELF_ST_BIND (sym->st_info))
9ef920e9 18818 {
c799a79d
NC
18819 case STB_GLOBAL:
18820 if (saved_sym == NULL
18821 || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT)
18822 saved_sym = sym;
18823 break;
c871dade 18824
c799a79d
NC
18825 case STB_LOCAL:
18826 if (saved_sym == NULL)
18827 saved_sym = sym;
18828 break;
18829
18830 default:
9ef920e9
NC
18831 break;
18832 }
18833 }
c799a79d
NC
18834 else
18835 {
18836 if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
18837 continue;
18838
18839 saved_sym = sym;
18840 break;
18841 }
18842 }
18843
6f156d7a
NC
18844 if (saved_sym && pname)
18845 * pname = strtab + saved_sym->st_name;
18846
18847 return saved_sym;
c799a79d
NC
18848}
18849
d20e98ab
NC
18850/* Returns true iff addr1 and addr2 are in the same section. */
18851
18852static bfd_boolean
18853same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2)
18854{
18855 Elf_Internal_Shdr * a1;
18856 Elf_Internal_Shdr * a2;
18857
18858 a1 = find_section_by_address (filedata, addr1);
18859 a2 = find_section_by_address (filedata, addr2);
9abca702 18860
d20e98ab
NC
18861 return a1 == a2 && a1 != NULL;
18862}
18863
c799a79d 18864static bfd_boolean
dda8d76d
NC
18865print_gnu_build_attribute_description (Elf_Internal_Note * pnote,
18866 Filedata * filedata)
c799a79d 18867{
6f156d7a
NC
18868 static unsigned long global_offset = 0;
18869 static unsigned long global_end = 0;
18870 static unsigned long func_offset = 0;
18871 static unsigned long func_end = 0;
c871dade 18872
6f156d7a
NC
18873 Elf_Internal_Sym * sym;
18874 const char * name;
18875 unsigned long start;
18876 unsigned long end;
18877 bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
18878
18879 switch (pnote->descsz)
c799a79d 18880 {
6f156d7a
NC
18881 case 0:
18882 /* A zero-length description means that the range of
18883 the previous note of the same type should be used. */
c799a79d 18884 if (is_open_attr)
c871dade 18885 {
6f156d7a
NC
18886 if (global_end > global_offset)
18887 printf (_(" Applies to region from %#lx to %#lx\n"),
18888 global_offset, global_end);
18889 else
18890 printf (_(" Applies to region from %#lx\n"), global_offset);
c799a79d
NC
18891 }
18892 else
18893 {
6f156d7a
NC
18894 if (func_end > func_offset)
18895 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end);
18896 else
18897 printf (_(" Applies to region from %#lx\n"), func_offset);
c871dade 18898 }
6f156d7a 18899 return TRUE;
9ef920e9 18900
6f156d7a
NC
18901 case 4:
18902 start = byte_get ((unsigned char *) pnote->descdata, 4);
18903 end = 0;
18904 break;
18905
18906 case 8:
18907 if (is_32bit_elf)
18908 {
18909 /* FIXME: We should check that version 3+ notes are being used here... */
18910 start = byte_get ((unsigned char *) pnote->descdata, 4);
18911 end = byte_get ((unsigned char *) pnote->descdata + 4, 4);
18912 }
18913 else
18914 {
18915 start = byte_get ((unsigned char *) pnote->descdata, 8);
18916 end = 0;
18917 }
18918 break;
18919
18920 case 16:
18921 start = byte_get ((unsigned char *) pnote->descdata, 8);
18922 end = byte_get ((unsigned char *) pnote->descdata + 8, 8);
18923 break;
9abca702 18924
6f156d7a 18925 default:
c799a79d
NC
18926 error (_(" <invalid description size: %lx>\n"), pnote->descsz);
18927 printf (_(" <invalid descsz>"));
18928 return FALSE;
18929 }
18930
6f156d7a
NC
18931 name = NULL;
18932 sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name);
8fd75781
NC
18933 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
18934 in order to avoid them being confused with the start address of the
18935 first function in the file... */
18936 if (sym == NULL && is_open_attr)
18937 sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr,
18938 & name);
6f156d7a
NC
18939
18940 if (end == 0 && sym != NULL && sym->st_size > 0)
18941 end = start + sym->st_size;
c799a79d
NC
18942
18943 if (is_open_attr)
18944 {
d20e98ab
NC
18945 /* FIXME: Need to properly allow for section alignment.
18946 16 is just the alignment used on x86_64. */
18947 if (global_end > 0
18948 && start > BFD_ALIGN (global_end, 16)
18949 /* Build notes are not guaranteed to be organised in order of
18950 increasing address, but we should find the all of the notes
18951 for one section in the same place. */
18952 && same_section (filedata, start, global_end))
6f156d7a
NC
18953 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
18954 global_end + 1, start - 1);
18955
18956 printf (_(" Applies to region from %#lx"), start);
18957 global_offset = start;
18958
18959 if (end)
18960 {
18961 printf (_(" to %#lx"), end);
18962 global_end = end;
18963 }
c799a79d
NC
18964 }
18965 else
18966 {
6f156d7a
NC
18967 printf (_(" Applies to region from %#lx"), start);
18968 func_offset = start;
18969
18970 if (end)
18971 {
18972 printf (_(" to %#lx"), end);
18973 func_end = end;
18974 }
c799a79d
NC
18975 }
18976
6f156d7a
NC
18977 if (sym && name)
18978 printf (_(" (%s)"), name);
18979
18980 printf ("\n");
18981 return TRUE;
9ef920e9
NC
18982}
18983
18984static bfd_boolean
18985print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
18986{
1d15e434
NC
18987 static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 };
18988 static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 };
18989 static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 };
9ef920e9
NC
18990 char name_type;
18991 char name_attribute;
1d15e434 18992 const char * expected_types;
9ef920e9
NC
18993 const char * name = pnote->namedata;
18994 const char * text;
88305e1b 18995 signed int left;
9ef920e9
NC
18996
18997 if (name == NULL || pnote->namesz < 2)
18998 {
18999 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
7296a62a 19000 print_symbol (-20, _(" <corrupt name>"));
9ef920e9
NC
19001 return FALSE;
19002 }
19003
6f156d7a
NC
19004 if (do_wide)
19005 left = 28;
19006 else
19007 left = 20;
88305e1b
NC
19008
19009 /* Version 2 of the spec adds a "GA" prefix to the name field. */
19010 if (name[0] == 'G' && name[1] == 'A')
19011 {
6f156d7a
NC
19012 if (pnote->namesz < 4)
19013 {
19014 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
19015 print_symbol (-20, _(" <corrupt name>"));
19016 return FALSE;
19017 }
19018
88305e1b
NC
19019 printf ("GA");
19020 name += 2;
19021 left -= 2;
19022 }
19023
9ef920e9
NC
19024 switch ((name_type = * name))
19025 {
19026 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
19027 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
19028 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
19029 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
19030 printf ("%c", * name);
88305e1b 19031 left --;
9ef920e9
NC
19032 break;
19033 default:
19034 error (_("unrecognised attribute type in name field: %d\n"), name_type);
19035 print_symbol (-20, _("<unknown name type>"));
19036 return FALSE;
19037 }
19038
9ef920e9
NC
19039 ++ name;
19040 text = NULL;
19041
19042 switch ((name_attribute = * name))
19043 {
19044 case GNU_BUILD_ATTRIBUTE_VERSION:
19045 text = _("<version>");
1d15e434 19046 expected_types = string_expected;
9ef920e9
NC
19047 ++ name;
19048 break;
19049 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
19050 text = _("<stack prot>");
75d7d298 19051 expected_types = "!+*";
9ef920e9
NC
19052 ++ name;
19053 break;
19054 case GNU_BUILD_ATTRIBUTE_RELRO:
19055 text = _("<relro>");
1d15e434 19056 expected_types = bool_expected;
9ef920e9
NC
19057 ++ name;
19058 break;
19059 case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
19060 text = _("<stack size>");
1d15e434 19061 expected_types = number_expected;
9ef920e9
NC
19062 ++ name;
19063 break;
19064 case GNU_BUILD_ATTRIBUTE_TOOL:
19065 text = _("<tool>");
1d15e434 19066 expected_types = string_expected;
9ef920e9
NC
19067 ++ name;
19068 break;
19069 case GNU_BUILD_ATTRIBUTE_ABI:
19070 text = _("<ABI>");
19071 expected_types = "$*";
19072 ++ name;
19073 break;
19074 case GNU_BUILD_ATTRIBUTE_PIC:
19075 text = _("<PIC>");
1d15e434 19076 expected_types = number_expected;
9ef920e9
NC
19077 ++ name;
19078 break;
a8be5506
NC
19079 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
19080 text = _("<short enum>");
1d15e434 19081 expected_types = bool_expected;
a8be5506
NC
19082 ++ name;
19083 break;
9ef920e9
NC
19084 default:
19085 if (ISPRINT (* name))
19086 {
19087 int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1;
19088
19089 if (len > left && ! do_wide)
19090 len = left;
75d7d298 19091 printf ("%.*s:", len, name);
9ef920e9 19092 left -= len;
0dd6ae21 19093 name += len;
9ef920e9
NC
19094 }
19095 else
19096 {
3e6b6445 19097 static char tmpbuf [128];
88305e1b 19098
3e6b6445
NC
19099 error (_("unrecognised byte in name field: %d\n"), * name);
19100 sprintf (tmpbuf, _("<unknown:_%d>"), * name);
19101 text = tmpbuf;
19102 name ++;
9ef920e9
NC
19103 }
19104 expected_types = "*$!+";
19105 break;
19106 }
19107
19108 if (text)
88305e1b 19109 left -= printf ("%s", text);
9ef920e9
NC
19110
19111 if (strchr (expected_types, name_type) == NULL)
75d7d298 19112 warn (_("attribute does not have an expected type (%c)\n"), name_type);
9ef920e9
NC
19113
19114 if ((unsigned long)(name - pnote->namedata) > pnote->namesz)
19115 {
19116 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
19117 (unsigned long) pnote->namesz,
19118 (long) (name - pnote->namedata));
19119 return FALSE;
19120 }
19121
19122 if (left < 1 && ! do_wide)
19123 return TRUE;
19124
19125 switch (name_type)
19126 {
19127 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
19128 {
b06b2c92 19129 unsigned int bytes;
ddef72cd
NC
19130 unsigned long long val = 0;
19131 unsigned int shift = 0;
19132 char * decoded = NULL;
19133
b06b2c92
NC
19134 bytes = pnote->namesz - (name - pnote->namedata);
19135 if (bytes > 0)
19136 /* The -1 is because the name field is always 0 terminated, and we
19137 want to be able to ensure that the shift in the while loop below
19138 will not overflow. */
19139 -- bytes;
19140
ddef72cd
NC
19141 if (bytes > sizeof (val))
19142 {
3e6b6445
NC
19143 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
19144 bytes);
19145 bytes = sizeof (val);
ddef72cd 19146 }
3e6b6445
NC
19147 /* We do not bother to warn if bytes == 0 as this can
19148 happen with some early versions of the gcc plugin. */
9ef920e9
NC
19149
19150 while (bytes --)
19151 {
79a964dc
NC
19152 unsigned long byte = (* name ++) & 0xff;
19153
19154 val |= byte << shift;
9ef920e9
NC
19155 shift += 8;
19156 }
19157
75d7d298 19158 switch (name_attribute)
9ef920e9 19159 {
75d7d298 19160 case GNU_BUILD_ATTRIBUTE_PIC:
9ef920e9
NC
19161 switch (val)
19162 {
75d7d298
NC
19163 case 0: decoded = "static"; break;
19164 case 1: decoded = "pic"; break;
19165 case 2: decoded = "PIC"; break;
19166 case 3: decoded = "pie"; break;
19167 case 4: decoded = "PIE"; break;
19168 default: break;
9ef920e9 19169 }
75d7d298
NC
19170 break;
19171 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
19172 switch (val)
9ef920e9 19173 {
75d7d298
NC
19174 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
19175 case 0: decoded = "off"; break;
19176 case 1: decoded = "on"; break;
19177 case 2: decoded = "all"; break;
19178 case 3: decoded = "strong"; break;
19179 case 4: decoded = "explicit"; break;
19180 default: break;
9ef920e9 19181 }
75d7d298
NC
19182 break;
19183 default:
19184 break;
9ef920e9
NC
19185 }
19186
75d7d298 19187 if (decoded != NULL)
3e6b6445
NC
19188 {
19189 print_symbol (-left, decoded);
19190 left = 0;
19191 }
19192 else if (val == 0)
19193 {
19194 printf ("0x0");
19195 left -= 3;
19196 }
9ef920e9 19197 else
75d7d298
NC
19198 {
19199 if (do_wide)
ddef72cd 19200 left -= printf ("0x%llx", val);
75d7d298 19201 else
ddef72cd 19202 left -= printf ("0x%-.*llx", left, val);
75d7d298 19203 }
9ef920e9
NC
19204 }
19205 break;
19206 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
19207 left -= print_symbol (- left, name);
19208 break;
19209 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
19210 left -= print_symbol (- left, "true");
19211 break;
19212 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
19213 left -= print_symbol (- left, "false");
19214 break;
19215 }
19216
19217 if (do_wide && left > 0)
19218 printf ("%-*s", left, " ");
9abca702 19219
9ef920e9
NC
19220 return TRUE;
19221}
19222
6d118b09
NC
19223/* Note that by the ELF standard, the name field is already null byte
19224 terminated, and namesz includes the terminating null byte.
19225 I.E. the value of namesz for the name "FSF" is 4.
19226
e3c8793a 19227 If the value of namesz is zero, there is no name present. */
9ef920e9 19228
32ec8896 19229static bfd_boolean
9ef920e9 19230process_note (Elf_Internal_Note * pnote,
dda8d76d 19231 Filedata * filedata)
779fe533 19232{
2cf0635d
NC
19233 const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
19234 const char * nt;
9437c45b
JT
19235
19236 if (pnote->namesz == 0)
1ec5cd37
NC
19237 /* If there is no note name, then use the default set of
19238 note type strings. */
dda8d76d 19239 nt = get_note_type (filedata, pnote->type);
1ec5cd37 19240
1118d252
RM
19241 else if (const_strneq (pnote->namedata, "GNU"))
19242 /* GNU-specific object file notes. */
19243 nt = get_gnu_elf_note_type (pnote->type);
f4ddf30f 19244
abeeff98
LM
19245 else if (const_strneq (pnote->namedata, "AMD")
19246 || const_strneq (pnote->namedata, "AMDGPU"))
19247 /* AMD-specific object file notes. */
19248 nt = get_amd_elf_note_type (pnote->type);
19249
f4ddf30f
JB
19250 else if (const_strneq (pnote->namedata, "FreeBSD"))
19251 /* FreeBSD-specific core file notes. */
dda8d76d 19252 nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
1118d252 19253
0112cd26 19254 else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
1ec5cd37 19255 /* NetBSD-specific core file notes. */
dda8d76d 19256 nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
1ec5cd37 19257
c6056a74
SF
19258 else if (const_strneq (pnote->namedata, "NetBSD"))
19259 /* NetBSD-specific core file notes. */
19260 return process_netbsd_elf_note (pnote);
19261
9abca702
CZ
19262 else if (const_strneq (pnote->namedata, "PaX"))
19263 /* NetBSD-specific core file notes. */
19264 return process_netbsd_elf_note (pnote);
19265
b15fa79e
AM
19266 else if (strneq (pnote->namedata, "SPU/", 4))
19267 {
19268 /* SPU-specific core file notes. */
19269 nt = pnote->namedata + 4;
19270 name = "SPU";
19271 }
19272
00e98fc7
TG
19273 else if (const_strneq (pnote->namedata, "IPF/VMS"))
19274 /* VMS/ia64-specific file notes. */
19275 nt = get_ia64_vms_note_type (pnote->type);
19276
70616151
TT
19277 else if (const_strneq (pnote->namedata, "stapsdt"))
19278 nt = get_stapsdt_note_type (pnote->type);
19279
9437c45b 19280 else
1ec5cd37
NC
19281 /* Don't recognize this note name; just use the default set of
19282 note type strings. */
dda8d76d 19283 nt = get_note_type (filedata, pnote->type);
9437c45b 19284
1449284b 19285 printf (" ");
9ef920e9 19286
483767a3
AM
19287 if (((const_strneq (pnote->namedata, "GA")
19288 && strchr ("*$!+", pnote->namedata[2]) != NULL)
19289 || strchr ("*$!+", pnote->namedata[0]) != NULL)
19290 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
19291 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
9ef920e9
NC
19292 print_gnu_build_attribute_name (pnote);
19293 else
19294 print_symbol (-20, name);
19295
19296 if (do_wide)
19297 printf (" 0x%08lx\t%s\t", pnote->descsz, nt);
19298 else
19299 printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
00e98fc7
TG
19300
19301 if (const_strneq (pnote->namedata, "IPF/VMS"))
19302 return print_ia64_vms_note (pnote);
664f90a3 19303 else if (const_strneq (pnote->namedata, "GNU"))
dda8d76d 19304 return print_gnu_note (filedata, pnote);
abeeff98
LM
19305 else if (const_strneq (pnote->namedata, "AMD")
19306 || const_strneq (pnote->namedata, "AMDGPU"))
19307 return print_amd_note (pnote);
c6a9fc58
TT
19308 else if (const_strneq (pnote->namedata, "stapsdt"))
19309 return print_stapsdt_note (pnote);
9ece1fa9
TT
19310 else if (const_strneq (pnote->namedata, "CORE"))
19311 return print_core_note (pnote);
483767a3
AM
19312 else if (((const_strneq (pnote->namedata, "GA")
19313 && strchr ("*$!+", pnote->namedata[2]) != NULL)
19314 || strchr ("*$!+", pnote->namedata[0]) != NULL)
19315 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
19316 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
dda8d76d 19317 return print_gnu_build_attribute_description (pnote, filedata);
779fe533 19318
9ef920e9 19319 if (pnote->descsz)
1449284b
NC
19320 {
19321 unsigned long i;
19322
19323 printf (_(" description data: "));
19324 for (i = 0; i < pnote->descsz; i++)
178d8719 19325 printf ("%02x ", pnote->descdata[i] & 0xff);
04ac15ab
AS
19326 if (!do_wide)
19327 printf ("\n");
1449284b
NC
19328 }
19329
9ef920e9
NC
19330 if (do_wide)
19331 printf ("\n");
19332
32ec8896 19333 return TRUE;
1449284b 19334}
6d118b09 19335
32ec8896 19336static bfd_boolean
dda8d76d
NC
19337process_notes_at (Filedata * filedata,
19338 Elf_Internal_Shdr * section,
19339 bfd_vma offset,
82ed9683
L
19340 bfd_vma length,
19341 bfd_vma align)
779fe533 19342{
2cf0635d
NC
19343 Elf_External_Note * pnotes;
19344 Elf_External_Note * external;
4dff97b2
NC
19345 char * end;
19346 bfd_boolean res = TRUE;
103f02d3 19347
779fe533 19348 if (length <= 0)
32ec8896 19349 return FALSE;
103f02d3 19350
1449284b
NC
19351 if (section)
19352 {
dda8d76d 19353 pnotes = (Elf_External_Note *) get_section_contents (section, filedata);
1449284b 19354 if (pnotes)
32ec8896 19355 {
dda8d76d 19356 if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL))
32ec8896
NC
19357 return FALSE;
19358 }
1449284b
NC
19359 }
19360 else
82ed9683 19361 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
1449284b 19362 _("notes"));
4dff97b2 19363
dd24e3da 19364 if (pnotes == NULL)
32ec8896 19365 return FALSE;
779fe533 19366
103f02d3 19367 external = pnotes;
103f02d3 19368
1449284b 19369 if (section)
dda8d76d 19370 printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (filedata, section));
1449284b
NC
19371 else
19372 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
19373 (unsigned long) offset, (unsigned long) length);
19374
82ed9683
L
19375 /* NB: Some note sections may have alignment value of 0 or 1. gABI
19376 specifies that notes should be aligned to 4 bytes in 32-bit
19377 objects and to 8 bytes in 64-bit objects. As a Linux extension,
19378 we also support 4 byte alignment in 64-bit objects. If section
19379 alignment is less than 4, we treate alignment as 4 bytes. */
19380 if (align < 4)
19381 align = 4;
19382 else if (align != 4 && align != 8)
19383 {
19384 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
19385 (long) align);
19386 return FALSE;
19387 }
19388
dbe15e4e 19389 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
103f02d3 19390
c8071705
NC
19391 end = (char *) pnotes + length;
19392 while ((char *) external < end)
779fe533 19393 {
b34976b6 19394 Elf_Internal_Note inote;
15b42fb0 19395 size_t min_notesz;
4dff97b2 19396 char * next;
2cf0635d 19397 char * temp = NULL;
c8071705 19398 size_t data_remaining = end - (char *) external;
6d118b09 19399
dda8d76d 19400 if (!is_ia64_vms (filedata))
15b42fb0 19401 {
9dd3a467
NC
19402 /* PR binutils/15191
19403 Make sure that there is enough data to read. */
15b42fb0
AM
19404 min_notesz = offsetof (Elf_External_Note, name);
19405 if (data_remaining < min_notesz)
9dd3a467 19406 {
d3a49aa8
AM
19407 warn (ngettext ("Corrupt note: only %ld byte remains, "
19408 "not enough for a full note\n",
19409 "Corrupt note: only %ld bytes remain, "
19410 "not enough for a full note\n",
19411 data_remaining),
19412 (long) data_remaining);
9dd3a467
NC
19413 break;
19414 }
5396a86e
AM
19415 data_remaining -= min_notesz;
19416
15b42fb0
AM
19417 inote.type = BYTE_GET (external->type);
19418 inote.namesz = BYTE_GET (external->namesz);
19419 inote.namedata = external->name;
19420 inote.descsz = BYTE_GET (external->descsz);
276da9b3 19421 inote.descdata = ((char *) external
4dff97b2 19422 + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
15b42fb0 19423 inote.descpos = offset + (inote.descdata - (char *) pnotes);
276da9b3 19424 next = ((char *) external
4dff97b2 19425 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
15b42fb0 19426 }
00e98fc7 19427 else
15b42fb0
AM
19428 {
19429 Elf64_External_VMS_Note *vms_external;
00e98fc7 19430
9dd3a467
NC
19431 /* PR binutils/15191
19432 Make sure that there is enough data to read. */
15b42fb0
AM
19433 min_notesz = offsetof (Elf64_External_VMS_Note, name);
19434 if (data_remaining < min_notesz)
9dd3a467 19435 {
d3a49aa8
AM
19436 warn (ngettext ("Corrupt note: only %ld byte remains, "
19437 "not enough for a full note\n",
19438 "Corrupt note: only %ld bytes remain, "
19439 "not enough for a full note\n",
19440 data_remaining),
19441 (long) data_remaining);
9dd3a467
NC
19442 break;
19443 }
5396a86e 19444 data_remaining -= min_notesz;
3e55a963 19445
15b42fb0
AM
19446 vms_external = (Elf64_External_VMS_Note *) external;
19447 inote.type = BYTE_GET (vms_external->type);
19448 inote.namesz = BYTE_GET (vms_external->namesz);
19449 inote.namedata = vms_external->name;
19450 inote.descsz = BYTE_GET (vms_external->descsz);
19451 inote.descdata = inote.namedata + align_power (inote.namesz, 3);
19452 inote.descpos = offset + (inote.descdata - (char *) pnotes);
19453 next = inote.descdata + align_power (inote.descsz, 3);
19454 }
19455
5396a86e
AM
19456 /* PR 17531: file: 3443835e. */
19457 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
19458 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
19459 || (size_t) (inote.descdata - inote.namedata) > data_remaining
19460 || (size_t) (next - inote.descdata) < inote.descsz
19461 || ((size_t) (next - inote.descdata)
19462 > data_remaining - (size_t) (inote.descdata - inote.namedata)))
3e55a963 19463 {
15b42fb0 19464 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
0af1713e 19465 (unsigned long) ((char *) external - (char *) pnotes));
4dff97b2
NC
19466 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
19467 inote.type, inote.namesz, inote.descsz, (int) align);
3e55a963
NC
19468 break;
19469 }
19470
15b42fb0 19471 external = (Elf_External_Note *) next;
dd24e3da 19472
6d118b09
NC
19473 /* Verify that name is null terminated. It appears that at least
19474 one version of Linux (RedHat 6.0) generates corefiles that don't
19475 comply with the ELF spec by failing to include the null byte in
19476 namesz. */
18344509 19477 if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0')
6d118b09 19478 {
5396a86e 19479 if ((size_t) (inote.descdata - inote.namedata) == inote.namesz)
6d118b09 19480 {
5396a86e
AM
19481 temp = (char *) malloc (inote.namesz + 1);
19482 if (temp == NULL)
19483 {
19484 error (_("Out of memory allocating space for inote name\n"));
19485 res = FALSE;
19486 break;
19487 }
76da6bbe 19488
5396a86e
AM
19489 memcpy (temp, inote.namedata, inote.namesz);
19490 inote.namedata = temp;
19491 }
19492 inote.namedata[inote.namesz] = 0;
6d118b09
NC
19493 }
19494
dda8d76d 19495 if (! process_note (& inote, filedata))
6b4bf3bc 19496 res = FALSE;
103f02d3 19497
6d118b09
NC
19498 if (temp != NULL)
19499 {
19500 free (temp);
19501 temp = NULL;
19502 }
779fe533
NC
19503 }
19504
19505 free (pnotes);
103f02d3 19506
779fe533
NC
19507 return res;
19508}
19509
32ec8896 19510static bfd_boolean
dda8d76d 19511process_corefile_note_segments (Filedata * filedata)
779fe533 19512{
2cf0635d 19513 Elf_Internal_Phdr * segment;
b34976b6 19514 unsigned int i;
32ec8896 19515 bfd_boolean res = TRUE;
103f02d3 19516
dda8d76d 19517 if (! get_program_headers (filedata))
6b4bf3bc 19518 return TRUE;
103f02d3 19519
dda8d76d
NC
19520 for (i = 0, segment = filedata->program_headers;
19521 i < filedata->file_header.e_phnum;
b34976b6 19522 i++, segment++)
779fe533
NC
19523 {
19524 if (segment->p_type == PT_NOTE)
dda8d76d 19525 if (! process_notes_at (filedata, NULL,
32ec8896 19526 (bfd_vma) segment->p_offset,
82ed9683
L
19527 (bfd_vma) segment->p_filesz,
19528 (bfd_vma) segment->p_align))
32ec8896 19529 res = FALSE;
779fe533 19530 }
103f02d3 19531
779fe533
NC
19532 return res;
19533}
19534
32ec8896 19535static bfd_boolean
dda8d76d 19536process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length)
685080f2
NC
19537{
19538 Elf_External_Note * pnotes;
19539 Elf_External_Note * external;
c8071705 19540 char * end;
32ec8896 19541 bfd_boolean res = TRUE;
685080f2
NC
19542
19543 if (length <= 0)
32ec8896 19544 return FALSE;
685080f2 19545
dda8d76d 19546 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
685080f2
NC
19547 _("v850 notes"));
19548 if (pnotes == NULL)
32ec8896 19549 return FALSE;
685080f2
NC
19550
19551 external = pnotes;
c8071705 19552 end = (char*) pnotes + length;
685080f2
NC
19553
19554 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
19555 (unsigned long) offset, (unsigned long) length);
19556
c8071705 19557 while ((char *) external + sizeof (Elf_External_Note) < end)
685080f2
NC
19558 {
19559 Elf_External_Note * next;
19560 Elf_Internal_Note inote;
19561
19562 inote.type = BYTE_GET (external->type);
19563 inote.namesz = BYTE_GET (external->namesz);
19564 inote.namedata = external->name;
19565 inote.descsz = BYTE_GET (external->descsz);
19566 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
19567 inote.descpos = offset + (inote.descdata - (char *) pnotes);
19568
c8071705
NC
19569 if (inote.descdata < (char *) pnotes || inote.descdata >= end)
19570 {
19571 warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
19572 inote.descdata = inote.namedata;
19573 inote.namesz = 0;
19574 }
19575
685080f2
NC
19576 next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
19577
c8071705 19578 if ( ((char *) next > end)
685080f2
NC
19579 || ((char *) next < (char *) pnotes))
19580 {
19581 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
19582 (unsigned long) ((char *) external - (char *) pnotes));
19583 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19584 inote.type, inote.namesz, inote.descsz);
19585 break;
19586 }
19587
19588 external = next;
19589
19590 /* Prevent out-of-bounds indexing. */
c8071705 19591 if ( inote.namedata + inote.namesz > end
685080f2
NC
19592 || inote.namedata + inote.namesz < inote.namedata)
19593 {
19594 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
19595 (unsigned long) ((char *) external - (char *) pnotes));
19596 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19597 inote.type, inote.namesz, inote.descsz);
19598 break;
19599 }
19600
19601 printf (" %s: ", get_v850_elf_note_type (inote.type));
19602
19603 if (! print_v850_note (& inote))
19604 {
32ec8896 19605 res = FALSE;
685080f2
NC
19606 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
19607 inote.namesz, inote.descsz);
19608 }
19609 }
19610
19611 free (pnotes);
19612
19613 return res;
19614}
19615
32ec8896 19616static bfd_boolean
dda8d76d 19617process_note_sections (Filedata * filedata)
1ec5cd37 19618{
2cf0635d 19619 Elf_Internal_Shdr * section;
1ec5cd37 19620 unsigned long i;
32ec8896
NC
19621 unsigned int n = 0;
19622 bfd_boolean res = TRUE;
1ec5cd37 19623
dda8d76d
NC
19624 for (i = 0, section = filedata->section_headers;
19625 i < filedata->file_header.e_shnum && section != NULL;
1ec5cd37 19626 i++, section++)
685080f2
NC
19627 {
19628 if (section->sh_type == SHT_NOTE)
19629 {
dda8d76d 19630 if (! process_notes_at (filedata, section,
32ec8896 19631 (bfd_vma) section->sh_offset,
82ed9683
L
19632 (bfd_vma) section->sh_size,
19633 (bfd_vma) section->sh_addralign))
32ec8896 19634 res = FALSE;
685080f2
NC
19635 n++;
19636 }
19637
dda8d76d
NC
19638 if (( filedata->file_header.e_machine == EM_V800
19639 || filedata->file_header.e_machine == EM_V850
19640 || filedata->file_header.e_machine == EM_CYGNUS_V850)
685080f2
NC
19641 && section->sh_type == SHT_RENESAS_INFO)
19642 {
dda8d76d 19643 if (! process_v850_notes (filedata,
32ec8896
NC
19644 (bfd_vma) section->sh_offset,
19645 (bfd_vma) section->sh_size))
19646 res = FALSE;
685080f2
NC
19647 n++;
19648 }
19649 }
df565f32
NC
19650
19651 if (n == 0)
19652 /* Try processing NOTE segments instead. */
dda8d76d 19653 return process_corefile_note_segments (filedata);
1ec5cd37
NC
19654
19655 return res;
19656}
19657
32ec8896 19658static bfd_boolean
dda8d76d 19659process_notes (Filedata * filedata)
779fe533
NC
19660{
19661 /* If we have not been asked to display the notes then do nothing. */
19662 if (! do_notes)
32ec8896 19663 return TRUE;
103f02d3 19664
dda8d76d
NC
19665 if (filedata->file_header.e_type != ET_CORE)
19666 return process_note_sections (filedata);
103f02d3 19667
779fe533 19668 /* No program headers means no NOTE segment. */
dda8d76d
NC
19669 if (filedata->file_header.e_phnum > 0)
19670 return process_corefile_note_segments (filedata);
779fe533 19671
1ec5cd37 19672 printf (_("No note segments present in the core file.\n"));
32ec8896 19673 return TRUE;
779fe533
NC
19674}
19675
60abdbed
NC
19676static unsigned char *
19677display_public_gnu_attributes (unsigned char * start,
19678 const unsigned char * const end)
19679{
19680 printf (_(" Unknown GNU attribute: %s\n"), start);
19681
19682 start += strnlen ((char *) start, end - start);
19683 display_raw_attribute (start, end);
19684
19685 return (unsigned char *) end;
19686}
19687
19688static unsigned char *
19689display_generic_attribute (unsigned char * start,
19690 unsigned int tag,
19691 const unsigned char * const end)
19692{
19693 if (tag == 0)
19694 return (unsigned char *) end;
19695
19696 return display_tag_value (tag, start, end);
19697}
19698
32ec8896 19699static bfd_boolean
dda8d76d 19700process_arch_specific (Filedata * filedata)
252b5132 19701{
a952a375 19702 if (! do_arch)
32ec8896 19703 return TRUE;
a952a375 19704
dda8d76d 19705 switch (filedata->file_header.e_machine)
252b5132 19706 {
53a346d8
CZ
19707 case EM_ARC:
19708 case EM_ARC_COMPACT:
19709 case EM_ARC_COMPACT2:
dda8d76d 19710 return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES,
53a346d8
CZ
19711 display_arc_attribute,
19712 display_generic_attribute);
11c1ff18 19713 case EM_ARM:
dda8d76d 19714 return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES,
60abdbed
NC
19715 display_arm_attribute,
19716 display_generic_attribute);
19717
252b5132 19718 case EM_MIPS:
4fe85591 19719 case EM_MIPS_RS3_LE:
dda8d76d 19720 return process_mips_specific (filedata);
60abdbed
NC
19721
19722 case EM_MSP430:
dda8d76d
NC
19723 return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
19724 display_msp430x_attribute,
c0ea7c52 19725 display_msp430_gnu_attribute);
60abdbed 19726
2dc8dd17
JW
19727 case EM_RISCV:
19728 return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES,
19729 display_riscv_attribute,
19730 display_generic_attribute);
19731
35c08157 19732 case EM_NDS32:
dda8d76d 19733 return process_nds32_specific (filedata);
60abdbed 19734
34c8bcba 19735 case EM_PPC:
b82317dd 19736 case EM_PPC64:
dda8d76d 19737 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
19738 display_power_gnu_attribute);
19739
643f7afb
AK
19740 case EM_S390:
19741 case EM_S390_OLD:
dda8d76d 19742 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
19743 display_s390_gnu_attribute);
19744
9e8c70f9
DM
19745 case EM_SPARC:
19746 case EM_SPARC32PLUS:
19747 case EM_SPARCV9:
dda8d76d 19748 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
19749 display_sparc_gnu_attribute);
19750
59e6276b 19751 case EM_TI_C6000:
dda8d76d 19752 return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES,
60abdbed
NC
19753 display_tic6x_attribute,
19754 display_generic_attribute);
19755
252b5132 19756 default:
dda8d76d 19757 return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES,
60abdbed
NC
19758 display_public_gnu_attributes,
19759 display_generic_attribute);
252b5132 19760 }
252b5132
RH
19761}
19762
32ec8896 19763static bfd_boolean
dda8d76d 19764get_file_header (Filedata * filedata)
252b5132 19765{
9ea033b2 19766 /* Read in the identity array. */
dda8d76d 19767 if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 19768 return FALSE;
252b5132 19769
9ea033b2 19770 /* Determine how to read the rest of the header. */
dda8d76d 19771 switch (filedata->file_header.e_ident[EI_DATA])
9ea033b2 19772 {
1a0670f3
AM
19773 default:
19774 case ELFDATANONE:
adab8cdc
AO
19775 case ELFDATA2LSB:
19776 byte_get = byte_get_little_endian;
19777 byte_put = byte_put_little_endian;
19778 break;
19779 case ELFDATA2MSB:
19780 byte_get = byte_get_big_endian;
19781 byte_put = byte_put_big_endian;
19782 break;
9ea033b2
NC
19783 }
19784
19785 /* For now we only support 32 bit and 64 bit ELF files. */
dda8d76d 19786 is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64);
9ea033b2
NC
19787
19788 /* Read in the rest of the header. */
19789 if (is_32bit_elf)
19790 {
19791 Elf32_External_Ehdr ehdr32;
252b5132 19792
dda8d76d 19793 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 19794 return FALSE;
103f02d3 19795
dda8d76d
NC
19796 filedata->file_header.e_type = BYTE_GET (ehdr32.e_type);
19797 filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine);
19798 filedata->file_header.e_version = BYTE_GET (ehdr32.e_version);
19799 filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry);
19800 filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
19801 filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
19802 filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags);
19803 filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
19804 filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
19805 filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
19806 filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
19807 filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
19808 filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9ea033b2 19809 }
252b5132 19810 else
9ea033b2
NC
19811 {
19812 Elf64_External_Ehdr ehdr64;
a952a375
NC
19813
19814 /* If we have been compiled with sizeof (bfd_vma) == 4, then
19815 we will not be able to cope with the 64bit data found in
19816 64 ELF files. Detect this now and abort before we start
50c2245b 19817 overwriting things. */
a952a375
NC
19818 if (sizeof (bfd_vma) < 8)
19819 {
e3c8793a
NC
19820 error (_("This instance of readelf has been built without support for a\n\
1982164 bit data type and so it cannot read 64 bit ELF files.\n"));
32ec8896 19822 return FALSE;
a952a375 19823 }
103f02d3 19824
dda8d76d 19825 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 19826 return FALSE;
103f02d3 19827
dda8d76d
NC
19828 filedata->file_header.e_type = BYTE_GET (ehdr64.e_type);
19829 filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine);
19830 filedata->file_header.e_version = BYTE_GET (ehdr64.e_version);
19831 filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry);
19832 filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
19833 filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
19834 filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags);
19835 filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
19836 filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
19837 filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
19838 filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
19839 filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
19840 filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9ea033b2 19841 }
252b5132 19842
dda8d76d 19843 if (filedata->file_header.e_shoff)
7ece0d85
JJ
19844 {
19845 /* There may be some extensions in the first section header. Don't
19846 bomb if we can't read it. */
19847 if (is_32bit_elf)
dda8d76d 19848 get_32bit_section_headers (filedata, TRUE);
7ece0d85 19849 else
dda8d76d 19850 get_64bit_section_headers (filedata, TRUE);
7ece0d85 19851 }
560f3c1c 19852
32ec8896 19853 return TRUE;
252b5132
RH
19854}
19855
dda8d76d
NC
19856static void
19857close_file (Filedata * filedata)
19858{
19859 if (filedata)
19860 {
19861 if (filedata->handle)
19862 fclose (filedata->handle);
19863 free (filedata);
19864 }
19865}
19866
19867void
19868close_debug_file (void * data)
19869{
19870 close_file ((Filedata *) data);
19871}
19872
19873static Filedata *
19874open_file (const char * pathname)
19875{
19876 struct stat statbuf;
19877 Filedata * filedata = NULL;
19878
19879 if (stat (pathname, & statbuf) < 0
19880 || ! S_ISREG (statbuf.st_mode))
19881 goto fail;
19882
19883 filedata = calloc (1, sizeof * filedata);
19884 if (filedata == NULL)
19885 goto fail;
19886
19887 filedata->handle = fopen (pathname, "rb");
19888 if (filedata->handle == NULL)
19889 goto fail;
19890
19891 filedata->file_size = (bfd_size_type) statbuf.st_size;
19892 filedata->file_name = pathname;
19893
19894 if (! get_file_header (filedata))
19895 goto fail;
19896
19897 if (filedata->file_header.e_shoff)
19898 {
19899 bfd_boolean res;
19900
19901 /* Read the section headers again, this time for real. */
19902 if (is_32bit_elf)
19903 res = get_32bit_section_headers (filedata, FALSE);
19904 else
19905 res = get_64bit_section_headers (filedata, FALSE);
19906
19907 if (!res)
19908 goto fail;
19909 }
19910
19911 return filedata;
19912
19913 fail:
19914 if (filedata)
19915 {
19916 if (filedata->handle)
19917 fclose (filedata->handle);
19918 free (filedata);
19919 }
19920 return NULL;
19921}
19922
19923void *
19924open_debug_file (const char * pathname)
19925{
19926 return open_file (pathname);
19927}
19928
fb52b2f4
NC
19929/* Process one ELF object file according to the command line options.
19930 This file may actually be stored in an archive. The file is
32ec8896
NC
19931 positioned at the start of the ELF object. Returns TRUE if no
19932 problems were encountered, FALSE otherwise. */
fb52b2f4 19933
32ec8896 19934static bfd_boolean
dda8d76d 19935process_object (Filedata * filedata)
252b5132 19936{
24841daa 19937 bfd_boolean have_separate_files;
252b5132 19938 unsigned int i;
32ec8896 19939 bfd_boolean res = TRUE;
252b5132 19940
dda8d76d 19941 if (! get_file_header (filedata))
252b5132 19942 {
dda8d76d 19943 error (_("%s: Failed to read file header\n"), filedata->file_name);
32ec8896 19944 return FALSE;
252b5132
RH
19945 }
19946
19947 /* Initialise per file variables. */
60bca95a 19948 for (i = ARRAY_SIZE (version_info); i--;)
252b5132
RH
19949 version_info[i] = 0;
19950
60bca95a 19951 for (i = ARRAY_SIZE (dynamic_info); i--;)
252b5132 19952 dynamic_info[i] = 0;
5115b233 19953 dynamic_info_DT_GNU_HASH = 0;
f16a9783 19954 dynamic_info_DT_MIPS_XHASH = 0;
252b5132
RH
19955
19956 /* Process the file. */
19957 if (show_name)
dda8d76d 19958 printf (_("\nFile: %s\n"), filedata->file_name);
252b5132 19959
18bd398b
NC
19960 /* Initialise the dump_sects array from the cmdline_dump_sects array.
19961 Note we do this even if cmdline_dump_sects is empty because we
19962 must make sure that the dump_sets array is zeroed out before each
19963 object file is processed. */
dda8d76d
NC
19964 if (filedata->num_dump_sects > cmdline.num_dump_sects)
19965 memset (filedata->dump_sects, 0, filedata->num_dump_sects * sizeof (* filedata->dump_sects));
18bd398b 19966
dda8d76d 19967 if (cmdline.num_dump_sects > 0)
18bd398b 19968 {
dda8d76d 19969 if (filedata->num_dump_sects == 0)
18bd398b 19970 /* A sneaky way of allocating the dump_sects array. */
dda8d76d 19971 request_dump_bynumber (filedata, cmdline.num_dump_sects, 0);
18bd398b 19972
dda8d76d
NC
19973 assert (filedata->num_dump_sects >= cmdline.num_dump_sects);
19974 memcpy (filedata->dump_sects, cmdline.dump_sects,
19975 cmdline.num_dump_sects * sizeof (* filedata->dump_sects));
18bd398b 19976 }
d70c5fc7 19977
dda8d76d 19978 if (! process_file_header (filedata))
32ec8896 19979 return FALSE;
252b5132 19980
dda8d76d 19981 if (! process_section_headers (filedata))
2f62977e 19982 {
32ec8896
NC
19983 /* Without loaded section headers we cannot process lots of things. */
19984 do_unwind = do_version = do_dump = do_arch = FALSE;
252b5132 19985
2f62977e 19986 if (! do_using_dynamic)
32ec8896 19987 do_syms = do_dyn_syms = do_reloc = FALSE;
2f62977e 19988 }
252b5132 19989
dda8d76d 19990 if (! process_section_groups (filedata))
32ec8896
NC
19991 /* Without loaded section groups we cannot process unwind. */
19992 do_unwind = FALSE;
d1f5c6e3 19993
dda8d76d
NC
19994 if (process_program_headers (filedata))
19995 process_dynamic_section (filedata);
32ec8896
NC
19996 else
19997 res = FALSE;
252b5132 19998
dda8d76d 19999 if (! process_relocs (filedata))
32ec8896 20000 res = FALSE;
252b5132 20001
dda8d76d 20002 if (! process_unwind (filedata))
32ec8896 20003 res = FALSE;
4d6ed7c8 20004
dda8d76d 20005 if (! process_symbol_table (filedata))
32ec8896 20006 res = FALSE;
252b5132 20007
dda8d76d 20008 if (! process_syminfo (filedata))
32ec8896 20009 res = FALSE;
252b5132 20010
dda8d76d 20011 if (! process_version_sections (filedata))
32ec8896 20012 res = FALSE;
252b5132 20013
82ed9683 20014 if (filedata->file_header.e_shstrndx != SHN_UNDEF)
24841daa 20015 have_separate_files = load_separate_debug_files (filedata, filedata->file_name);
82ed9683 20016 else
24841daa 20017 have_separate_files = FALSE;
dda8d76d
NC
20018
20019 if (! process_section_contents (filedata))
32ec8896 20020 res = FALSE;
f5842774 20021
24841daa 20022 if (have_separate_files)
dda8d76d 20023 {
24841daa
NC
20024 separate_info * d;
20025
20026 for (d = first_separate_info; d != NULL; d = d->next)
20027 {
20028 if (! process_section_headers (d->handle))
20029 res = FALSE;
20030 else if (! process_section_contents (d->handle))
20031 res = FALSE;
20032 }
20033
20034 /* The file handles are closed by the call to free_debug_memory() below. */
dda8d76d
NC
20035 }
20036
20037 if (! process_notes (filedata))
32ec8896 20038 res = FALSE;
103f02d3 20039
dda8d76d 20040 if (! process_gnu_liblist (filedata))
32ec8896 20041 res = FALSE;
047b2264 20042
dda8d76d 20043 if (! process_arch_specific (filedata))
32ec8896 20044 res = FALSE;
252b5132 20045
dda8d76d
NC
20046 free (filedata->program_headers);
20047 filedata->program_headers = NULL;
d93f0186 20048
dda8d76d
NC
20049 free (filedata->section_headers);
20050 filedata->section_headers = NULL;
252b5132 20051
dda8d76d
NC
20052 free (filedata->string_table);
20053 filedata->string_table = NULL;
20054 filedata->string_table_length = 0;
252b5132
RH
20055
20056 if (dynamic_strings)
20057 {
20058 free (dynamic_strings);
20059 dynamic_strings = NULL;
d79b3d50 20060 dynamic_strings_length = 0;
252b5132
RH
20061 }
20062
20063 if (dynamic_symbols)
20064 {
20065 free (dynamic_symbols);
20066 dynamic_symbols = NULL;
19936277 20067 num_dynamic_syms = 0;
252b5132
RH
20068 }
20069
20070 if (dynamic_syminfo)
20071 {
20072 free (dynamic_syminfo);
20073 dynamic_syminfo = NULL;
20074 }
ff78d6d6 20075
293c573e
MR
20076 if (dynamic_section)
20077 {
20078 free (dynamic_section);
20079 dynamic_section = NULL;
20080 }
20081
e4b17d5c
L
20082 if (section_headers_groups)
20083 {
20084 free (section_headers_groups);
20085 section_headers_groups = NULL;
20086 }
20087
20088 if (section_groups)
20089 {
2cf0635d
NC
20090 struct group_list * g;
20091 struct group_list * next;
e4b17d5c
L
20092
20093 for (i = 0; i < group_count; i++)
20094 {
20095 for (g = section_groups [i].root; g != NULL; g = next)
20096 {
20097 next = g->next;
20098 free (g);
20099 }
20100 }
20101
20102 free (section_groups);
20103 section_groups = NULL;
20104 }
20105
19e6b90e 20106 free_debug_memory ();
18bd398b 20107
32ec8896 20108 return res;
252b5132
RH
20109}
20110
2cf0635d 20111/* Process an ELF archive.
32ec8896
NC
20112 On entry the file is positioned just after the ARMAG string.
20113 Returns TRUE upon success, FALSE otherwise. */
2cf0635d 20114
32ec8896 20115static bfd_boolean
dda8d76d 20116process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
2cf0635d
NC
20117{
20118 struct archive_info arch;
20119 struct archive_info nested_arch;
20120 size_t got;
32ec8896 20121 bfd_boolean ret = TRUE;
2cf0635d 20122
32ec8896 20123 show_name = TRUE;
2cf0635d
NC
20124
20125 /* The ARCH structure is used to hold information about this archive. */
20126 arch.file_name = NULL;
20127 arch.file = NULL;
20128 arch.index_array = NULL;
20129 arch.sym_table = NULL;
20130 arch.longnames = NULL;
20131
20132 /* The NESTED_ARCH structure is used as a single-item cache of information
20133 about a nested archive (when members of a thin archive reside within
20134 another regular archive file). */
20135 nested_arch.file_name = NULL;
20136 nested_arch.file = NULL;
20137 nested_arch.index_array = NULL;
20138 nested_arch.sym_table = NULL;
20139 nested_arch.longnames = NULL;
20140
dda8d76d
NC
20141 if (setup_archive (&arch, filedata->file_name, filedata->handle,
20142 is_thin_archive, do_archive_index) != 0)
2cf0635d 20143 {
32ec8896 20144 ret = FALSE;
2cf0635d 20145 goto out;
4145f1d5 20146 }
fb52b2f4 20147
4145f1d5
NC
20148 if (do_archive_index)
20149 {
2cf0635d 20150 if (arch.sym_table == NULL)
dda8d76d 20151 error (_("%s: unable to dump the index as none was found\n"), filedata->file_name);
4145f1d5
NC
20152 else
20153 {
591f7597 20154 unsigned long i, l;
4145f1d5
NC
20155 unsigned long current_pos;
20156
591f7597 20157 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
dda8d76d
NC
20158 filedata->file_name, (unsigned long) arch.index_num, arch.sym_size);
20159
20160 current_pos = ftell (filedata->handle);
4145f1d5 20161
2cf0635d 20162 for (i = l = 0; i < arch.index_num; i++)
4145f1d5 20163 {
2cf0635d
NC
20164 if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
20165 {
20166 char * member_name;
4145f1d5 20167
2cf0635d
NC
20168 member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
20169
20170 if (member_name != NULL)
20171 {
20172 char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
20173
20174 if (qualified_name != NULL)
20175 {
c2a7d3f5
NC
20176 printf (_("Contents of binary %s at offset "), qualified_name);
20177 (void) print_vma (arch.index_array[i], PREFIX_HEX);
20178 putchar ('\n');
2cf0635d
NC
20179 free (qualified_name);
20180 }
4145f1d5
NC
20181 }
20182 }
2cf0635d
NC
20183
20184 if (l >= arch.sym_size)
4145f1d5
NC
20185 {
20186 error (_("%s: end of the symbol table reached before the end of the index\n"),
dda8d76d 20187 filedata->file_name);
32ec8896 20188 ret = FALSE;
cb8f3167 20189 break;
4145f1d5 20190 }
591f7597
NC
20191 /* PR 17531: file: 0b6630b2. */
20192 printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l);
20193 l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
4145f1d5
NC
20194 }
20195
67ce483b 20196 if (arch.uses_64bit_indices)
c2a7d3f5
NC
20197 l = (l + 7) & ~ 7;
20198 else
20199 l += l & 1;
20200
2cf0635d 20201 if (l < arch.sym_size)
32ec8896 20202 {
d3a49aa8
AM
20203 error (ngettext ("%s: %ld byte remains in the symbol table, "
20204 "but without corresponding entries in "
20205 "the index table\n",
20206 "%s: %ld bytes remain in the symbol table, "
20207 "but without corresponding entries in "
20208 "the index table\n",
20209 arch.sym_size - l),
dda8d76d 20210 filedata->file_name, arch.sym_size - l);
32ec8896
NC
20211 ret = FALSE;
20212 }
4145f1d5 20213
dda8d76d 20214 if (fseek (filedata->handle, current_pos, SEEK_SET) != 0)
4145f1d5 20215 {
dda8d76d
NC
20216 error (_("%s: failed to seek back to start of object files in the archive\n"),
20217 filedata->file_name);
32ec8896 20218 ret = FALSE;
2cf0635d 20219 goto out;
4145f1d5 20220 }
fb52b2f4 20221 }
4145f1d5
NC
20222
20223 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
20224 && !do_segments && !do_header && !do_dump && !do_version
20225 && !do_histogram && !do_debugging && !do_arch && !do_notes
2c610e4b 20226 && !do_section_groups && !do_dyn_syms)
2cf0635d 20227 {
32ec8896 20228 ret = TRUE; /* Archive index only. */
2cf0635d
NC
20229 goto out;
20230 }
fb52b2f4
NC
20231 }
20232
fb52b2f4
NC
20233 while (1)
20234 {
2cf0635d
NC
20235 char * name;
20236 size_t namelen;
20237 char * qualified_name;
20238
20239 /* Read the next archive header. */
dda8d76d 20240 if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0)
2cf0635d 20241 {
28e817cc 20242 error (_("%s: failed to seek to next archive header\n"), arch.file_name);
32ec8896 20243 return FALSE;
2cf0635d 20244 }
dda8d76d 20245 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle);
2cf0635d
NC
20246 if (got != sizeof arch.arhdr)
20247 {
20248 if (got == 0)
20249 break;
28e817cc
NC
20250 /* PR 24049 - we cannot use filedata->file_name as this will
20251 have already been freed. */
20252 error (_("%s: failed to read archive header\n"), arch.file_name);
9abca702 20253
32ec8896 20254 ret = FALSE;
2cf0635d
NC
20255 break;
20256 }
20257 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
20258 {
20259 error (_("%s: did not find a valid archive header\n"), arch.file_name);
32ec8896 20260 ret = FALSE;
2cf0635d
NC
20261 break;
20262 }
20263
20264 arch.next_arhdr_offset += sizeof arch.arhdr;
20265
20266 archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
20267 if (archive_file_size & 01)
20268 ++archive_file_size;
20269
20270 name = get_archive_member_name (&arch, &nested_arch);
20271 if (name == NULL)
fb52b2f4 20272 {
28e817cc 20273 error (_("%s: bad archive file name\n"), arch.file_name);
32ec8896 20274 ret = FALSE;
d989285c 20275 break;
fb52b2f4 20276 }
2cf0635d 20277 namelen = strlen (name);
fb52b2f4 20278
2cf0635d
NC
20279 qualified_name = make_qualified_name (&arch, &nested_arch, name);
20280 if (qualified_name == NULL)
fb52b2f4 20281 {
28e817cc 20282 error (_("%s: bad archive file name\n"), arch.file_name);
32ec8896 20283 ret = FALSE;
d989285c 20284 break;
fb52b2f4
NC
20285 }
20286
2cf0635d
NC
20287 if (is_thin_archive && arch.nested_member_origin == 0)
20288 {
20289 /* This is a proxy for an external member of a thin archive. */
dda8d76d
NC
20290 Filedata * member_filedata;
20291 char * member_file_name = adjust_relative_path
20292 (filedata->file_name, name, namelen);
32ec8896 20293
2cf0635d
NC
20294 if (member_file_name == NULL)
20295 {
32ec8896 20296 ret = FALSE;
2cf0635d
NC
20297 break;
20298 }
20299
dda8d76d
NC
20300 member_filedata = open_file (member_file_name);
20301 if (member_filedata == NULL)
2cf0635d
NC
20302 {
20303 error (_("Input file '%s' is not readable.\n"), member_file_name);
20304 free (member_file_name);
32ec8896 20305 ret = FALSE;
2cf0635d
NC
20306 break;
20307 }
20308
20309 archive_file_offset = arch.nested_member_origin;
dda8d76d 20310 member_filedata->file_name = qualified_name;
2cf0635d 20311
dda8d76d 20312 if (! process_object (member_filedata))
32ec8896 20313 ret = FALSE;
2cf0635d 20314
dda8d76d 20315 close_file (member_filedata);
2cf0635d
NC
20316 free (member_file_name);
20317 }
20318 else if (is_thin_archive)
20319 {
eb02c04d
PK
20320 Filedata thin_filedata;
20321
20322 memset (&thin_filedata, 0, sizeof (thin_filedata));
dda8d76d 20323
a043396b
NC
20324 /* PR 15140: Allow for corrupt thin archives. */
20325 if (nested_arch.file == NULL)
20326 {
20327 error (_("%s: contains corrupt thin archive: %s\n"),
28e817cc 20328 qualified_name, name);
32ec8896 20329 ret = FALSE;
a043396b
NC
20330 break;
20331 }
20332
2cf0635d
NC
20333 /* This is a proxy for a member of a nested archive. */
20334 archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
20335
20336 /* The nested archive file will have been opened and setup by
20337 get_archive_member_name. */
20338 if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
20339 {
20340 error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
32ec8896 20341 ret = FALSE;
2cf0635d
NC
20342 break;
20343 }
20344
dda8d76d
NC
20345 thin_filedata.handle = nested_arch.file;
20346 thin_filedata.file_name = qualified_name;
9abca702 20347
dda8d76d 20348 if (! process_object (& thin_filedata))
32ec8896 20349 ret = FALSE;
2cf0635d
NC
20350 }
20351 else
20352 {
20353 archive_file_offset = arch.next_arhdr_offset;
20354 arch.next_arhdr_offset += archive_file_size;
fb52b2f4 20355
6a6196fc 20356 filedata->file_name = qualified_name;
dda8d76d 20357 if (! process_object (filedata))
32ec8896 20358 ret = FALSE;
2cf0635d 20359 }
fb52b2f4 20360
dda8d76d 20361 if (filedata->dump_sects != NULL)
2b52916e 20362 {
dda8d76d
NC
20363 free (filedata->dump_sects);
20364 filedata->dump_sects = NULL;
20365 filedata->num_dump_sects = 0;
2b52916e
L
20366 }
20367
2cf0635d 20368 free (qualified_name);
fb52b2f4
NC
20369 }
20370
4145f1d5 20371 out:
2cf0635d
NC
20372 if (nested_arch.file != NULL)
20373 fclose (nested_arch.file);
20374 release_archive (&nested_arch);
20375 release_archive (&arch);
fb52b2f4 20376
d989285c 20377 return ret;
fb52b2f4
NC
20378}
20379
32ec8896 20380static bfd_boolean
2cf0635d 20381process_file (char * file_name)
fb52b2f4 20382{
dda8d76d 20383 Filedata * filedata = NULL;
fb52b2f4
NC
20384 struct stat statbuf;
20385 char armag[SARMAG];
32ec8896 20386 bfd_boolean ret = TRUE;
fb52b2f4
NC
20387
20388 if (stat (file_name, &statbuf) < 0)
20389 {
f24ddbdd
NC
20390 if (errno == ENOENT)
20391 error (_("'%s': No such file\n"), file_name);
20392 else
20393 error (_("Could not locate '%s'. System error message: %s\n"),
20394 file_name, strerror (errno));
32ec8896 20395 return FALSE;
f24ddbdd
NC
20396 }
20397
20398 if (! S_ISREG (statbuf.st_mode))
20399 {
20400 error (_("'%s' is not an ordinary file\n"), file_name);
32ec8896 20401 return FALSE;
fb52b2f4
NC
20402 }
20403
dda8d76d
NC
20404 filedata = calloc (1, sizeof * filedata);
20405 if (filedata == NULL)
20406 {
20407 error (_("Out of memory allocating file data structure\n"));
20408 return FALSE;
20409 }
20410
20411 filedata->file_name = file_name;
20412 filedata->handle = fopen (file_name, "rb");
20413 if (filedata->handle == NULL)
fb52b2f4 20414 {
f24ddbdd 20415 error (_("Input file '%s' is not readable.\n"), file_name);
dda8d76d 20416 free (filedata);
32ec8896 20417 return FALSE;
fb52b2f4
NC
20418 }
20419
dda8d76d 20420 if (fread (armag, SARMAG, 1, filedata->handle) != 1)
fb52b2f4 20421 {
4145f1d5 20422 error (_("%s: Failed to read file's magic number\n"), file_name);
dda8d76d
NC
20423 fclose (filedata->handle);
20424 free (filedata);
32ec8896 20425 return FALSE;
fb52b2f4
NC
20426 }
20427
dda8d76d 20428 filedata->file_size = (bfd_size_type) statbuf.st_size;
f54498b4 20429
fb52b2f4 20430 if (memcmp (armag, ARMAG, SARMAG) == 0)
32ec8896 20431 {
dda8d76d 20432 if (! process_archive (filedata, FALSE))
32ec8896
NC
20433 ret = FALSE;
20434 }
2cf0635d 20435 else if (memcmp (armag, ARMAGT, SARMAG) == 0)
32ec8896 20436 {
dda8d76d 20437 if ( ! process_archive (filedata, TRUE))
32ec8896
NC
20438 ret = FALSE;
20439 }
fb52b2f4
NC
20440 else
20441 {
4145f1d5
NC
20442 if (do_archive_index)
20443 error (_("File %s is not an archive so its index cannot be displayed.\n"),
20444 file_name);
20445
dda8d76d 20446 rewind (filedata->handle);
fb52b2f4 20447 archive_file_size = archive_file_offset = 0;
32ec8896 20448
dda8d76d 20449 if (! process_object (filedata))
32ec8896 20450 ret = FALSE;
fb52b2f4
NC
20451 }
20452
dda8d76d
NC
20453 fclose (filedata->handle);
20454 free (filedata);
32ec8896 20455
fb52b2f4
NC
20456 return ret;
20457}
20458
252b5132
RH
20459#ifdef SUPPORT_DISASSEMBLY
20460/* Needed by the i386 disassembler. For extra credit, someone could
9ea033b2 20461 fix this so that we insert symbolic addresses here, esp for GOT/PLT
e3c8793a 20462 symbols. */
252b5132
RH
20463
20464void
2cf0635d 20465print_address (unsigned int addr, FILE * outfile)
252b5132
RH
20466{
20467 fprintf (outfile,"0x%8.8x", addr);
20468}
20469
e3c8793a 20470/* Needed by the i386 disassembler. */
dda8d76d 20471
252b5132
RH
20472void
20473db_task_printsym (unsigned int addr)
20474{
20475 print_address (addr, stderr);
20476}
20477#endif
20478
20479int
2cf0635d 20480main (int argc, char ** argv)
252b5132 20481{
ff78d6d6
L
20482 int err;
20483
252b5132
RH
20484#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
20485 setlocale (LC_MESSAGES, "");
3882b010
L
20486#endif
20487#if defined (HAVE_SETLOCALE)
20488 setlocale (LC_CTYPE, "");
252b5132
RH
20489#endif
20490 bindtextdomain (PACKAGE, LOCALEDIR);
20491 textdomain (PACKAGE);
20492
869b9d07
MM
20493 expandargv (&argc, &argv);
20494
dda8d76d
NC
20495 cmdline.file_name = "<cmdline>";
20496 parse_args (& cmdline, argc, argv);
59f14fc0 20497
18bd398b 20498 if (optind < (argc - 1))
32ec8896 20499 show_name = TRUE;
5656ba2c
L
20500 else if (optind >= argc)
20501 {
20502 warn (_("Nothing to do.\n"));
20503 usage (stderr);
20504 }
18bd398b 20505
32ec8896 20506 err = FALSE;
252b5132 20507 while (optind < argc)
32ec8896
NC
20508 if (! process_file (argv[optind++]))
20509 err = TRUE;
252b5132 20510
dda8d76d
NC
20511 if (cmdline.dump_sects != NULL)
20512 free (cmdline.dump_sects);
252b5132 20513
7d9813f1
NA
20514 free (dump_ctf_symtab_name);
20515 free (dump_ctf_strtab_name);
20516 free (dump_ctf_parent_name);
20517
32ec8896 20518 return err ? EXIT_FAILURE : EXIT_SUCCESS;
252b5132 20519}
This page took 3.115694 seconds and 4 git commands to generate.