]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - binutils/readelf.c
gas int vs bfd_boolean fixes
[thirdparty/binutils-gdb.git] / binutils / readelf.c
CommitLineData
252b5132 1/* readelf.c -- display contents of an ELF format file
250d07de 2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
252b5132
RH
3
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
12ab83a9 5 Modifications by Nick Clifton <nickc@redhat.com>
252b5132
RH
6
7 This file is part of GNU Binutils.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
32866df7 11 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
b43b5d5f
NC
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 02110-1301, USA. */
252b5132 23\f
9eb20dd8 24/* The difference between readelf and objdump:
252b5132 25
74013231 26 Both programs are capable of displaying the contents of ELF format files,
9eb20dd8 27 so why does the binutils project have two file dumpers ?
0de14b54 28
9eb20dd8
NC
29 The reason is that objdump sees an ELF file through a BFD filter of the
30 world; if BFD has a bug where, say, it disagrees about a machine constant
31 in e_flags, then the odds are good that it will remain internally
32 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
33 GAS sees it the BFD way. There was need for a tool to go find out what
34 the file actually says.
35
36 This is why the readelf program does not link against the BFD library - it
37 exists as an independent program to help verify the correct working of BFD.
38
39 There is also the case that readelf can provide more information about an
40 ELF file than is provided by objdump. In particular it can display DWARF
41 debugging information which (at the moment) objdump cannot. */
42\f
3db64b00 43#include "sysdep.h"
252b5132 44#include <assert.h>
252b5132 45#include <time.h>
1b315056 46#include <zlib.h>
3bfcb652 47#ifdef HAVE_WCHAR_H
7bfd842d 48#include <wchar.h>
3bfcb652 49#endif
252b5132 50
a952a375 51#if __GNUC__ >= 2
19936277 52/* Define BFD64 here, even if our default architecture is 32 bit ELF
a952a375 53 as this will allow us to read in and parse 64bit and 32bit ELF files.
b34976b6 54 Only do this if we believe that the compiler can support a 64 bit
a952a375 55 data type. For now we only rely on GCC being able to do this. */
19936277 56#define BFD64
a952a375
NC
57#endif
58
3db64b00
AM
59#include "bfd.h"
60#include "bucomm.h"
3284fe0c 61#include "elfcomm.h"
19e6b90e 62#include "dwarf.h"
7d9813f1 63#include "ctf-api.h"
79bc120c 64#include "demangle.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"
3b16e843 96#include "elf/arc.h"
252b5132 97#include "elf/arm.h"
3b16e843 98#include "elf/avr.h"
1d65ded4 99#include "elf/bfin.h"
60bca95a 100#include "elf/cr16.h"
3b16e843 101#include "elf/cris.h"
1c0d3aa6 102#include "elf/crx.h"
b8891f8d 103#include "elf/csky.h"
252b5132
RH
104#include "elf/d10v.h"
105#include "elf/d30v.h"
d172d4ba 106#include "elf/dlx.h"
aca4efc7 107#include "elf/bpf.h"
cfb8c092 108#include "elf/epiphany.h"
252b5132 109#include "elf/fr30.h"
5c70f934 110#include "elf/frv.h"
3f8107ab 111#include "elf/ft32.h"
3b16e843
NC
112#include "elf/h8.h"
113#include "elf/hppa.h"
114#include "elf/i386.h"
f954747f
AM
115#include "elf/i370.h"
116#include "elf/i860.h"
117#include "elf/i960.h"
3b16e843 118#include "elf/ia64.h"
1e4cf259 119#include "elf/ip2k.h"
84e94c90 120#include "elf/lm32.h"
1c0d3aa6 121#include "elf/iq2000.h"
49f58d10 122#include "elf/m32c.h"
3b16e843
NC
123#include "elf/m32r.h"
124#include "elf/m68k.h"
75751cd9 125#include "elf/m68hc11.h"
7b4ae824 126#include "elf/s12z.h"
252b5132 127#include "elf/mcore.h"
15ab5209 128#include "elf/mep.h"
a3c62988 129#include "elf/metag.h"
7ba29e2a 130#include "elf/microblaze.h"
3b16e843 131#include "elf/mips.h"
3c3bdf30 132#include "elf/mmix.h"
3b16e843
NC
133#include "elf/mn10200.h"
134#include "elf/mn10300.h"
5506d11a 135#include "elf/moxie.h"
4970f871 136#include "elf/mt.h"
2469cfa2 137#include "elf/msp430.h"
35c08157 138#include "elf/nds32.h"
fe944acf 139#include "elf/nfp.h"
13761a11 140#include "elf/nios2.h"
73589c9d 141#include "elf/or1k.h"
7d466069 142#include "elf/pj.h"
3b16e843 143#include "elf/ppc.h"
c833c019 144#include "elf/ppc64.h"
2b100bb5 145#include "elf/pru.h"
03336641 146#include "elf/riscv.h"
99c513f6 147#include "elf/rl78.h"
c7927a3c 148#include "elf/rx.h"
a85d7ed0 149#include "elf/s390.h"
1c0d3aa6 150#include "elf/score.h"
3b16e843
NC
151#include "elf/sh.h"
152#include "elf/sparc.h"
e9f53129 153#include "elf/spu.h"
40b36596 154#include "elf/tic6x.h"
aa137e4d
NC
155#include "elf/tilegx.h"
156#include "elf/tilepro.h"
3b16e843 157#include "elf/v850.h"
179d3252 158#include "elf/vax.h"
619ed720 159#include "elf/visium.h"
f96bd6c2 160#include "elf/wasm32.h"
3b16e843 161#include "elf/x86-64.h"
c29aca4a 162#include "elf/xc16x.h"
f6c1a2d5 163#include "elf/xgate.h"
93fbbb04 164#include "elf/xstormy16.h"
88da6820 165#include "elf/xtensa.h"
6655dba2 166#include "elf/z80.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
6431e409
AM
201/* A dynamic array of flags indicating for which sections a dump
202 has been requested via command line switches. */
1b513401
NC
203struct dump_data
204{
6431e409
AM
205 dump_type * dump_sects;
206 unsigned int num_dump_sects;
207};
208
209static struct dump_data cmdline;
210
211static struct dump_list_entry * dump_sects_byname;
212
2cf0635d 213char * program_name = "readelf";
dda8d76d 214
32ec8896
NC
215static bfd_boolean show_name = FALSE;
216static bfd_boolean do_dynamic = FALSE;
217static bfd_boolean do_syms = FALSE;
218static bfd_boolean do_dyn_syms = FALSE;
0f03783c 219static bfd_boolean do_lto_syms = FALSE;
32ec8896
NC
220static bfd_boolean do_reloc = FALSE;
221static bfd_boolean do_sections = FALSE;
222static bfd_boolean do_section_groups = FALSE;
223static bfd_boolean do_section_details = FALSE;
224static bfd_boolean do_segments = FALSE;
225static bfd_boolean do_unwind = FALSE;
226static bfd_boolean do_using_dynamic = FALSE;
227static bfd_boolean do_header = FALSE;
228static bfd_boolean do_dump = FALSE;
229static bfd_boolean do_version = FALSE;
230static bfd_boolean do_histogram = FALSE;
231static bfd_boolean do_debugging = FALSE;
7d9813f1 232static bfd_boolean do_ctf = FALSE;
32ec8896
NC
233static bfd_boolean do_arch = FALSE;
234static bfd_boolean do_notes = FALSE;
235static bfd_boolean do_archive_index = FALSE;
1b513401 236static bfd_boolean check_all = FALSE;
32ec8896
NC
237static bfd_boolean is_32bit_elf = FALSE;
238static bfd_boolean decompress_dumps = FALSE;
0942c7ab 239static bfd_boolean do_not_show_symbol_truncation = FALSE;
79bc120c 240static bfd_boolean do_demangle = FALSE; /* Pretty print C++ symbol names. */
ca0e11aa 241static bfd_boolean process_links = FALSE;
79bc120c 242static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
252b5132 243
7d9813f1
NA
244static char *dump_ctf_parent_name;
245static char *dump_ctf_symtab_name;
246static char *dump_ctf_strtab_name;
247
e4b17d5c
L
248struct group_list
249{
dda8d76d
NC
250 struct group_list * next;
251 unsigned int section_index;
e4b17d5c
L
252};
253
254struct group
255{
dda8d76d
NC
256 struct group_list * root;
257 unsigned int group_index;
e4b17d5c
L
258};
259
978c4450
AM
260typedef struct filedata
261{
262 const char * file_name;
ca0e11aa 263 bfd_boolean is_separate;
978c4450
AM
264 FILE * handle;
265 bfd_size_type file_size;
266 Elf_Internal_Ehdr file_header;
267 Elf_Internal_Shdr * section_headers;
268 Elf_Internal_Phdr * program_headers;
269 char * string_table;
270 unsigned long string_table_length;
271 unsigned long archive_file_offset;
272 unsigned long archive_file_size;
273 unsigned long dynamic_addr;
274 bfd_size_type dynamic_size;
275 size_t dynamic_nent;
276 Elf_Internal_Dyn * dynamic_section;
8ac10c5b 277 Elf_Internal_Shdr * dynamic_strtab_section;
978c4450
AM
278 char * dynamic_strings;
279 unsigned long dynamic_strings_length;
8ac10c5b 280 Elf_Internal_Shdr * dynamic_symtab_section;
978c4450
AM
281 unsigned long num_dynamic_syms;
282 Elf_Internal_Sym * dynamic_symbols;
283 bfd_vma version_info[16];
284 unsigned int dynamic_syminfo_nent;
285 Elf_Internal_Syminfo * dynamic_syminfo;
286 unsigned long dynamic_syminfo_offset;
287 bfd_size_type nbuckets;
288 bfd_size_type nchains;
289 bfd_vma * buckets;
290 bfd_vma * chains;
291 bfd_size_type ngnubuckets;
292 bfd_size_type ngnuchains;
293 bfd_vma * gnubuckets;
294 bfd_vma * gnuchains;
295 bfd_vma * mipsxlat;
296 bfd_vma gnusymidx;
297 char program_interpreter[PATH_MAX];
298 bfd_vma dynamic_info[DT_ENCODING];
299 bfd_vma dynamic_info_DT_GNU_HASH;
300 bfd_vma dynamic_info_DT_MIPS_XHASH;
301 elf_section_list * symtab_shndx_list;
302 size_t group_count;
303 struct group * section_groups;
304 struct group ** section_headers_groups;
305 /* A dynamic array of flags indicating for which sections a dump of
306 some kind has been requested. It is reset on a per-object file
307 basis and then initialised from the cmdline_dump_sects array,
308 the results of interpreting the -w switch, and the
309 dump_sects_byname list. */
310 struct dump_data dump;
311} Filedata;
aef1f6d0 312
c256ffe7 313/* How to print a vma value. */
843dd992
NC
314typedef enum print_mode
315{
316 HEX,
317 DEC,
318 DEC_5,
319 UNSIGNED,
320 PREFIX_HEX,
321 FULL_HEX,
322 LONG_HEX
323}
324print_mode;
325
bb4d2ac2
L
326/* Versioned symbol info. */
327enum versioned_symbol_info
328{
329 symbol_undefined,
330 symbol_hidden,
331 symbol_public
332};
333
32ec8896 334static const char * get_symbol_version_string
dda8d76d 335 (Filedata *, bfd_boolean, const char *, unsigned long, unsigned,
32ec8896 336 Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *);
bb4d2ac2 337
9c19a809
NC
338#define UNKNOWN -1
339
b9e920ec
AM
340#define SECTION_NAME(X) \
341 (filedata->string_table + (X)->sh_name)
342
343#define SECTION_NAME_VALID(X) \
344 ((X) != NULL \
345 && filedata->string_table != NULL \
346 && (X)->sh_name < filedata->string_table_length)
347
348#define SECTION_NAME_PRINT(X) \
349 ((X) == NULL ? _("<none>") \
350 : filedata->string_table == NULL ? _("<no-strings>") \
351 : (X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
352 : filedata->string_table + (X)->sh_name)
252b5132 353
ee42cf8c 354#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
252b5132 355
ba5cdace
NC
356#define GET_ELF_SYMBOLS(file, section, sym_count) \
357 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
358 : get_64bit_elf_symbols (file, section, sym_count))
9ea033b2 359
10ca4b04
L
360#define VALID_SYMBOL_NAME(strtab, strtab_size, offset) \
361 (strtab != NULL && offset < strtab_size)
978c4450
AM
362#define VALID_DYNAMIC_NAME(filedata, offset) \
363 VALID_SYMBOL_NAME (filedata->dynamic_strings, \
364 filedata->dynamic_strings_length, offset)
d79b3d50
NC
365/* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
366 already been called and verified that the string exists. */
978c4450
AM
367#define GET_DYNAMIC_NAME(filedata, offset) \
368 (filedata->dynamic_strings + offset)
18bd398b 369
61865e30
NC
370#define REMOVE_ARCH_BITS(ADDR) \
371 do \
372 { \
dda8d76d 373 if (filedata->file_header.e_machine == EM_ARM) \
61865e30
NC
374 (ADDR) &= ~1; \
375 } \
376 while (0)
f16a9783
MS
377
378/* Get the correct GNU hash section name. */
978c4450
AM
379#define GNU_HASH_SECTION_NAME(filedata) \
380 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
d79b3d50 381\f
66cfc0fd
AM
382/* Print a BFD_VMA to an internal buffer, for use in error messages.
383 BFD_FMA_FMT can't be used in translated strings. */
384
385static const char *
386bfd_vmatoa (char *fmtch, bfd_vma value)
387{
388 /* bfd_vmatoa is used more then once in a printf call for output.
389 Cycle through an array of buffers. */
390 static int buf_pos = 0;
391 static struct bfd_vmatoa_buf
392 {
393 char place[64];
394 } buf[4];
395 char *ret;
396 char fmt[32];
397
398 ret = buf[buf_pos++].place;
399 buf_pos %= ARRAY_SIZE (buf);
400
401 sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
402 snprintf (ret, sizeof (buf[0].place), fmt, value);
403 return ret;
404}
405
dda8d76d
NC
406/* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
407 OFFSET + the offset of the current archive member, if we are examining an
408 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
409 allocate a buffer using malloc and fill that. In either case return the
410 pointer to the start of the retrieved data or NULL if something went wrong.
411 If something does go wrong and REASON is not NULL then emit an error
412 message using REASON as part of the context. */
59245841 413
c256ffe7 414static void *
dda8d76d
NC
415get_data (void * var,
416 Filedata * filedata,
417 unsigned long offset,
418 bfd_size_type size,
419 bfd_size_type nmemb,
420 const char * reason)
a6e9f9df 421{
2cf0635d 422 void * mvar;
57028622 423 bfd_size_type amt = size * nmemb;
a6e9f9df 424
c256ffe7 425 if (size == 0 || nmemb == 0)
a6e9f9df
AM
426 return NULL;
427
57028622
NC
428 /* If the size_t type is smaller than the bfd_size_type, eg because
429 you are building a 32-bit tool on a 64-bit host, then make sure
430 that when the sizes are cast to (size_t) no information is lost. */
7c1c1904
AM
431 if ((size_t) size != size
432 || (size_t) nmemb != nmemb
433 || (size_t) amt != amt)
57028622
NC
434 {
435 if (reason)
66cfc0fd
AM
436 error (_("Size truncation prevents reading %s"
437 " elements of size %s for %s\n"),
438 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
57028622
NC
439 return NULL;
440 }
441
442 /* Check for size overflow. */
7c1c1904 443 if (amt / size != nmemb || (size_t) amt + 1 == 0)
57028622
NC
444 {
445 if (reason)
66cfc0fd
AM
446 error (_("Size overflow prevents reading %s"
447 " elements of size %s for %s\n"),
448 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
57028622
NC
449 return NULL;
450 }
451
c22b42ce 452 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
c9c1d674 453 attempting to allocate memory when the read is bound to fail. */
978c4450
AM
454 if (filedata->archive_file_offset > filedata->file_size
455 || offset > filedata->file_size - filedata->archive_file_offset
456 || amt > filedata->file_size - filedata->archive_file_offset - offset)
a6e9f9df 457 {
049b0c3a 458 if (reason)
66cfc0fd
AM
459 error (_("Reading %s bytes extends past end of file for %s\n"),
460 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
461 return NULL;
462 }
463
978c4450
AM
464 if (fseek (filedata->handle, filedata->archive_file_offset + offset,
465 SEEK_SET))
071436c6
NC
466 {
467 if (reason)
c9c1d674 468 error (_("Unable to seek to 0x%lx for %s\n"),
978c4450 469 filedata->archive_file_offset + offset, reason);
071436c6
NC
470 return NULL;
471 }
472
a6e9f9df
AM
473 mvar = var;
474 if (mvar == NULL)
475 {
7c1c1904
AM
476 /* + 1 so that we can '\0' terminate invalid string table sections. */
477 mvar = malloc ((size_t) amt + 1);
a6e9f9df
AM
478
479 if (mvar == NULL)
480 {
049b0c3a 481 if (reason)
66cfc0fd
AM
482 error (_("Out of memory allocating %s bytes for %s\n"),
483 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
484 return NULL;
485 }
c256ffe7 486
c9c1d674 487 ((char *) mvar)[amt] = '\0';
a6e9f9df
AM
488 }
489
dda8d76d 490 if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb)
a6e9f9df 491 {
049b0c3a 492 if (reason)
66cfc0fd
AM
493 error (_("Unable to read in %s bytes of %s\n"),
494 bfd_vmatoa ("u", amt), reason);
a6e9f9df
AM
495 if (mvar != var)
496 free (mvar);
497 return NULL;
498 }
499
500 return mvar;
501}
502
32ec8896
NC
503/* Print a VMA value in the MODE specified.
504 Returns the number of characters displayed. */
cb8f3167 505
32ec8896 506static unsigned int
14a91970 507print_vma (bfd_vma vma, print_mode mode)
66543521 508{
32ec8896 509 unsigned int nc = 0;
66543521 510
14a91970 511 switch (mode)
66543521 512 {
14a91970
AM
513 case FULL_HEX:
514 nc = printf ("0x");
1a0670f3 515 /* Fall through. */
14a91970 516 case LONG_HEX:
f7a99963 517#ifdef BFD64
14a91970 518 if (is_32bit_elf)
437c2fb7 519 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
f7a99963 520#endif
14a91970
AM
521 printf_vma (vma);
522 return nc + 16;
b19aac67 523
14a91970
AM
524 case DEC_5:
525 if (vma <= 99999)
526 return printf ("%5" BFD_VMA_FMT "d", vma);
1a0670f3 527 /* Fall through. */
14a91970
AM
528 case PREFIX_HEX:
529 nc = printf ("0x");
1a0670f3 530 /* Fall through. */
14a91970
AM
531 case HEX:
532 return nc + printf ("%" BFD_VMA_FMT "x", vma);
b19aac67 533
14a91970
AM
534 case DEC:
535 return printf ("%" BFD_VMA_FMT "d", vma);
b19aac67 536
14a91970
AM
537 case UNSIGNED:
538 return printf ("%" BFD_VMA_FMT "u", vma);
32ec8896
NC
539
540 default:
541 /* FIXME: Report unrecognised mode ? */
542 return 0;
f7a99963 543 }
f7a99963
NC
544}
545
7bfd842d 546/* Display a symbol on stdout. Handles the display of control characters and
3bfcb652 547 multibye characters (assuming the host environment supports them).
31104126 548
7bfd842d
NC
549 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
550
0942c7ab
NC
551 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
552 abs(WIDTH) - 5 characters followed by "[...]".
553
7bfd842d
NC
554 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
555 padding as necessary.
171191ba
NC
556
557 Returns the number of emitted characters. */
558
559static unsigned int
0942c7ab 560print_symbol (signed int width, const char * symbol)
31104126 561{
171191ba 562 bfd_boolean extra_padding = FALSE;
0942c7ab 563 bfd_boolean do_dots = FALSE;
32ec8896 564 signed int num_printed = 0;
3bfcb652 565#ifdef HAVE_MBSTATE_T
7bfd842d 566 mbstate_t state;
3bfcb652 567#endif
32ec8896 568 unsigned int width_remaining;
79bc120c 569 const void * alloced_symbol = NULL;
961c521f 570
7bfd842d 571 if (width < 0)
961c521f 572 {
88305e1b 573 /* Keep the width positive. This helps the code below. */
961c521f 574 width = - width;
171191ba 575 extra_padding = TRUE;
0b4362b0 576 }
56d8f8a9
NC
577 else if (width == 0)
578 return 0;
961c521f 579
7bfd842d
NC
580 if (do_wide)
581 /* Set the remaining width to a very large value.
582 This simplifies the code below. */
583 width_remaining = INT_MAX;
584 else
0942c7ab
NC
585 {
586 width_remaining = width;
587 if (! do_not_show_symbol_truncation
588 && (int) strlen (symbol) > width)
589 {
590 width_remaining -= 5;
591 if ((int) width_remaining < 0)
592 width_remaining = 0;
593 do_dots = TRUE;
594 }
595 }
cb8f3167 596
3bfcb652 597#ifdef HAVE_MBSTATE_T
7bfd842d
NC
598 /* Initialise the multibyte conversion state. */
599 memset (& state, 0, sizeof (state));
3bfcb652 600#endif
961c521f 601
79bc120c
NC
602 if (do_demangle && *symbol)
603 {
604 const char * res = cplus_demangle (symbol, demangle_flags);
605
606 if (res != NULL)
607 alloced_symbol = symbol = res;
608 }
609
7bfd842d
NC
610 while (width_remaining)
611 {
612 size_t n;
7bfd842d 613 const char c = *symbol++;
961c521f 614
7bfd842d 615 if (c == 0)
961c521f
NC
616 break;
617
7bfd842d
NC
618 /* Do not print control characters directly as they can affect terminal
619 settings. Such characters usually appear in the names generated
620 by the assembler for local labels. */
621 if (ISCNTRL (c))
961c521f 622 {
7bfd842d 623 if (width_remaining < 2)
961c521f
NC
624 break;
625
7bfd842d
NC
626 printf ("^%c", c + 0x40);
627 width_remaining -= 2;
171191ba 628 num_printed += 2;
961c521f 629 }
7bfd842d
NC
630 else if (ISPRINT (c))
631 {
632 putchar (c);
633 width_remaining --;
634 num_printed ++;
635 }
961c521f
NC
636 else
637 {
3bfcb652
NC
638#ifdef HAVE_MBSTATE_T
639 wchar_t w;
640#endif
7bfd842d
NC
641 /* Let printf do the hard work of displaying multibyte characters. */
642 printf ("%.1s", symbol - 1);
643 width_remaining --;
644 num_printed ++;
645
3bfcb652 646#ifdef HAVE_MBSTATE_T
7bfd842d
NC
647 /* Try to find out how many bytes made up the character that was
648 just printed. Advance the symbol pointer past the bytes that
649 were displayed. */
650 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
3bfcb652
NC
651#else
652 n = 1;
653#endif
7bfd842d
NC
654 if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
655 symbol += (n - 1);
961c521f 656 }
961c521f 657 }
171191ba 658
0942c7ab
NC
659 if (do_dots)
660 num_printed += printf ("[...]");
661
7bfd842d 662 if (extra_padding && num_printed < width)
171191ba
NC
663 {
664 /* Fill in the remaining spaces. */
7bfd842d
NC
665 printf ("%-*s", width - num_printed, " ");
666 num_printed = width;
171191ba
NC
667 }
668
79bc120c 669 free ((void *) alloced_symbol);
171191ba 670 return num_printed;
31104126
NC
671}
672
1449284b 673/* Returns a pointer to a static buffer containing a printable version of
74e1a04b
NC
674 the given section's name. Like print_symbol, except that it does not try
675 to print multibyte characters, it just interprets them as hex values. */
676
677static const char *
dda8d76d 678printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec)
74e1a04b 679{
ca0e11aa 680#define MAX_PRINT_SEC_NAME_LEN 256
74e1a04b 681 static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
b9e920ec 682 const char * name = SECTION_NAME_PRINT (sec);
74e1a04b
NC
683 char * buf = sec_name_buf;
684 char c;
685 unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
686
687 while ((c = * name ++) != 0)
688 {
689 if (ISCNTRL (c))
690 {
691 if (remaining < 2)
692 break;
948f632f 693
74e1a04b
NC
694 * buf ++ = '^';
695 * buf ++ = c + 0x40;
696 remaining -= 2;
697 }
698 else if (ISPRINT (c))
699 {
700 * buf ++ = c;
701 remaining -= 1;
702 }
703 else
704 {
705 static char hex[17] = "0123456789ABCDEF";
706
707 if (remaining < 4)
708 break;
709 * buf ++ = '<';
710 * buf ++ = hex[(c & 0xf0) >> 4];
711 * buf ++ = hex[c & 0x0f];
712 * buf ++ = '>';
713 remaining -= 4;
714 }
715
716 if (remaining == 0)
717 break;
718 }
719
720 * buf = 0;
721 return sec_name_buf;
722}
723
724static const char *
dda8d76d 725printable_section_name_from_index (Filedata * filedata, unsigned long ndx)
74e1a04b 726{
dda8d76d 727 if (ndx >= filedata->file_header.e_shnum)
74e1a04b
NC
728 return _("<corrupt>");
729
dda8d76d 730 return printable_section_name (filedata, filedata->section_headers + ndx);
74e1a04b
NC
731}
732
89fac5e3
RS
733/* Return a pointer to section NAME, or NULL if no such section exists. */
734
735static Elf_Internal_Shdr *
dda8d76d 736find_section (Filedata * filedata, const char * name)
89fac5e3
RS
737{
738 unsigned int i;
739
68807c3c
NC
740 if (filedata->section_headers == NULL)
741 return NULL;
dda8d76d
NC
742
743 for (i = 0; i < filedata->file_header.e_shnum; i++)
b9e920ec
AM
744 if (SECTION_NAME_VALID (filedata->section_headers + i)
745 && streq (SECTION_NAME (filedata->section_headers + i), name))
dda8d76d 746 return filedata->section_headers + i;
89fac5e3
RS
747
748 return NULL;
749}
750
0b6ae522
DJ
751/* Return a pointer to a section containing ADDR, or NULL if no such
752 section exists. */
753
754static Elf_Internal_Shdr *
dda8d76d 755find_section_by_address (Filedata * filedata, bfd_vma addr)
0b6ae522
DJ
756{
757 unsigned int i;
758
68807c3c
NC
759 if (filedata->section_headers == NULL)
760 return NULL;
761
dda8d76d 762 for (i = 0; i < filedata->file_header.e_shnum; i++)
0b6ae522 763 {
dda8d76d
NC
764 Elf_Internal_Shdr *sec = filedata->section_headers + i;
765
0b6ae522
DJ
766 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
767 return sec;
768 }
769
770 return NULL;
771}
772
071436c6 773static Elf_Internal_Shdr *
dda8d76d 774find_section_by_type (Filedata * filedata, unsigned int type)
071436c6
NC
775{
776 unsigned int i;
777
68807c3c
NC
778 if (filedata->section_headers == NULL)
779 return NULL;
780
dda8d76d 781 for (i = 0; i < filedata->file_header.e_shnum; i++)
071436c6 782 {
dda8d76d
NC
783 Elf_Internal_Shdr *sec = filedata->section_headers + i;
784
071436c6
NC
785 if (sec->sh_type == type)
786 return sec;
787 }
788
789 return NULL;
790}
791
657d0d47
CC
792/* Return a pointer to section NAME, or NULL if no such section exists,
793 restricted to the list of sections given in SET. */
794
795static Elf_Internal_Shdr *
dda8d76d 796find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
657d0d47
CC
797{
798 unsigned int i;
799
68807c3c
NC
800 if (filedata->section_headers == NULL)
801 return NULL;
802
657d0d47
CC
803 if (set != NULL)
804 {
805 while ((i = *set++) > 0)
b814a36d
NC
806 {
807 /* See PR 21156 for a reproducer. */
dda8d76d 808 if (i >= filedata->file_header.e_shnum)
b814a36d
NC
809 continue; /* FIXME: Should we issue an error message ? */
810
b9e920ec
AM
811 if (SECTION_NAME_VALID (filedata->section_headers + i)
812 && streq (SECTION_NAME (filedata->section_headers + i), name))
dda8d76d 813 return filedata->section_headers + i;
b814a36d 814 }
657d0d47
CC
815 }
816
dda8d76d 817 return find_section (filedata, name);
657d0d47
CC
818}
819
32ec8896 820/* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
28f997cf
TG
821 This OS has so many departures from the ELF standard that we test it at
822 many places. */
823
32ec8896 824static inline bfd_boolean
dda8d76d 825is_ia64_vms (Filedata * filedata)
28f997cf 826{
dda8d76d
NC
827 return filedata->file_header.e_machine == EM_IA_64
828 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
28f997cf
TG
829}
830
bcedfee6 831/* Guess the relocation size commonly used by the specific machines. */
252b5132 832
32ec8896 833static bfd_boolean
2dc4cec1 834guess_is_rela (unsigned int e_machine)
252b5132 835{
9c19a809 836 switch (e_machine)
252b5132
RH
837 {
838 /* Targets that use REL relocations. */
252b5132 839 case EM_386:
22abe556 840 case EM_IAMCU:
f954747f 841 case EM_960:
e9f53129 842 case EM_ARM:
2b0337b0 843 case EM_D10V:
252b5132 844 case EM_CYGNUS_D10V:
e9f53129 845 case EM_DLX:
252b5132 846 case EM_MIPS:
4fe85591 847 case EM_MIPS_RS3_LE:
e9f53129 848 case EM_CYGNUS_M32R:
1c0d3aa6 849 case EM_SCORE:
f6c1a2d5 850 case EM_XGATE:
fe944acf 851 case EM_NFP:
aca4efc7 852 case EM_BPF:
9c19a809 853 return FALSE;
103f02d3 854
252b5132
RH
855 /* Targets that use RELA relocations. */
856 case EM_68K:
f954747f 857 case EM_860:
a06ea964 858 case EM_AARCH64:
cfb8c092 859 case EM_ADAPTEVA_EPIPHANY:
e9f53129
AM
860 case EM_ALPHA:
861 case EM_ALTERA_NIOS2:
886a2506
NC
862 case EM_ARC:
863 case EM_ARC_COMPACT:
864 case EM_ARC_COMPACT2:
e9f53129
AM
865 case EM_AVR:
866 case EM_AVR_OLD:
867 case EM_BLACKFIN:
60bca95a 868 case EM_CR16:
e9f53129
AM
869 case EM_CRIS:
870 case EM_CRX:
b8891f8d 871 case EM_CSKY:
2b0337b0 872 case EM_D30V:
252b5132 873 case EM_CYGNUS_D30V:
2b0337b0 874 case EM_FR30:
3f8107ab 875 case EM_FT32:
252b5132 876 case EM_CYGNUS_FR30:
5c70f934 877 case EM_CYGNUS_FRV:
e9f53129
AM
878 case EM_H8S:
879 case EM_H8_300:
880 case EM_H8_300H:
800eeca4 881 case EM_IA_64:
1e4cf259
NC
882 case EM_IP2K:
883 case EM_IP2K_OLD:
3b36097d 884 case EM_IQ2000:
84e94c90 885 case EM_LATTICEMICO32:
ff7eeb89 886 case EM_M32C_OLD:
49f58d10 887 case EM_M32C:
e9f53129
AM
888 case EM_M32R:
889 case EM_MCORE:
15ab5209 890 case EM_CYGNUS_MEP:
a3c62988 891 case EM_METAG:
e9f53129
AM
892 case EM_MMIX:
893 case EM_MN10200:
894 case EM_CYGNUS_MN10200:
895 case EM_MN10300:
896 case EM_CYGNUS_MN10300:
5506d11a 897 case EM_MOXIE:
e9f53129
AM
898 case EM_MSP430:
899 case EM_MSP430_OLD:
d031aafb 900 case EM_MT:
35c08157 901 case EM_NDS32:
64fd6348 902 case EM_NIOS32:
73589c9d 903 case EM_OR1K:
e9f53129
AM
904 case EM_PPC64:
905 case EM_PPC:
2b100bb5 906 case EM_TI_PRU:
e23eba97 907 case EM_RISCV:
99c513f6 908 case EM_RL78:
c7927a3c 909 case EM_RX:
e9f53129
AM
910 case EM_S390:
911 case EM_S390_OLD:
912 case EM_SH:
913 case EM_SPARC:
914 case EM_SPARC32PLUS:
915 case EM_SPARCV9:
916 case EM_SPU:
40b36596 917 case EM_TI_C6000:
aa137e4d
NC
918 case EM_TILEGX:
919 case EM_TILEPRO:
708e2187 920 case EM_V800:
e9f53129
AM
921 case EM_V850:
922 case EM_CYGNUS_V850:
923 case EM_VAX:
619ed720 924 case EM_VISIUM:
e9f53129 925 case EM_X86_64:
8a9036a4 926 case EM_L1OM:
7a9068fe 927 case EM_K1OM:
e9f53129
AM
928 case EM_XSTORMY16:
929 case EM_XTENSA:
930 case EM_XTENSA_OLD:
7ba29e2a
NC
931 case EM_MICROBLAZE:
932 case EM_MICROBLAZE_OLD:
f96bd6c2 933 case EM_WEBASSEMBLY:
9c19a809 934 return TRUE;
103f02d3 935
e9f53129
AM
936 case EM_68HC05:
937 case EM_68HC08:
938 case EM_68HC11:
939 case EM_68HC16:
940 case EM_FX66:
941 case EM_ME16:
d1133906 942 case EM_MMA:
d1133906
NC
943 case EM_NCPU:
944 case EM_NDR1:
e9f53129 945 case EM_PCP:
d1133906 946 case EM_ST100:
e9f53129 947 case EM_ST19:
d1133906 948 case EM_ST7:
e9f53129
AM
949 case EM_ST9PLUS:
950 case EM_STARCORE:
d1133906 951 case EM_SVX:
e9f53129 952 case EM_TINYJ:
9c19a809
NC
953 default:
954 warn (_("Don't know about relocations on this machine architecture\n"));
955 return FALSE;
956 }
957}
252b5132 958
dda8d76d 959/* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
32ec8896
NC
960 Returns TRUE upon success, FALSE otherwise. If successful then a
961 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
962 and the number of relocs loaded is placed in *NRELASP. It is the caller's
963 responsibility to free the allocated buffer. */
964
965static bfd_boolean
dda8d76d
NC
966slurp_rela_relocs (Filedata * filedata,
967 unsigned long rel_offset,
968 unsigned long rel_size,
969 Elf_Internal_Rela ** relasp,
970 unsigned long * nrelasp)
9c19a809 971{
2cf0635d 972 Elf_Internal_Rela * relas;
8b73c356 973 size_t nrelas;
4d6ed7c8 974 unsigned int i;
252b5132 975
4d6ed7c8
NC
976 if (is_32bit_elf)
977 {
2cf0635d 978 Elf32_External_Rela * erelas;
103f02d3 979
dda8d76d 980 erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 981 rel_size, _("32-bit relocation data"));
a6e9f9df 982 if (!erelas)
32ec8896 983 return FALSE;
252b5132 984
4d6ed7c8 985 nrelas = rel_size / sizeof (Elf32_External_Rela);
103f02d3 986
3f5e193b
NC
987 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
988 sizeof (Elf_Internal_Rela));
103f02d3 989
4d6ed7c8
NC
990 if (relas == NULL)
991 {
c256ffe7 992 free (erelas);
591a748a 993 error (_("out of memory parsing relocs\n"));
32ec8896 994 return FALSE;
4d6ed7c8 995 }
103f02d3 996
4d6ed7c8
NC
997 for (i = 0; i < nrelas; i++)
998 {
999 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
1000 relas[i].r_info = BYTE_GET (erelas[i].r_info);
598aaa76 1001 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
4d6ed7c8 1002 }
103f02d3 1003
4d6ed7c8
NC
1004 free (erelas);
1005 }
1006 else
1007 {
2cf0635d 1008 Elf64_External_Rela * erelas;
103f02d3 1009
dda8d76d 1010 erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 1011 rel_size, _("64-bit relocation data"));
a6e9f9df 1012 if (!erelas)
32ec8896 1013 return FALSE;
4d6ed7c8
NC
1014
1015 nrelas = rel_size / sizeof (Elf64_External_Rela);
103f02d3 1016
3f5e193b
NC
1017 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
1018 sizeof (Elf_Internal_Rela));
103f02d3 1019
4d6ed7c8
NC
1020 if (relas == NULL)
1021 {
c256ffe7 1022 free (erelas);
591a748a 1023 error (_("out of memory parsing relocs\n"));
32ec8896 1024 return FALSE;
9c19a809 1025 }
4d6ed7c8
NC
1026
1027 for (i = 0; i < nrelas; i++)
9c19a809 1028 {
66543521
AM
1029 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
1030 relas[i].r_info = BYTE_GET (erelas[i].r_info);
598aaa76 1031 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
861fb55a
DJ
1032
1033 /* The #ifdef BFD64 below is to prevent a compile time
1034 warning. We know that if we do not have a 64 bit data
1035 type that we will never execute this code anyway. */
1036#ifdef BFD64
dda8d76d
NC
1037 if (filedata->file_header.e_machine == EM_MIPS
1038 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
861fb55a
DJ
1039 {
1040 /* In little-endian objects, r_info isn't really a
1041 64-bit little-endian value: it has a 32-bit
1042 little-endian symbol index followed by four
1043 individual byte fields. Reorder INFO
1044 accordingly. */
91d6fa6a
NC
1045 bfd_vma inf = relas[i].r_info;
1046 inf = (((inf & 0xffffffff) << 32)
1047 | ((inf >> 56) & 0xff)
1048 | ((inf >> 40) & 0xff00)
1049 | ((inf >> 24) & 0xff0000)
1050 | ((inf >> 8) & 0xff000000));
1051 relas[i].r_info = inf;
861fb55a
DJ
1052 }
1053#endif /* BFD64 */
4d6ed7c8 1054 }
103f02d3 1055
4d6ed7c8
NC
1056 free (erelas);
1057 }
32ec8896 1058
4d6ed7c8
NC
1059 *relasp = relas;
1060 *nrelasp = nrelas;
32ec8896 1061 return TRUE;
4d6ed7c8 1062}
103f02d3 1063
dda8d76d 1064/* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
32ec8896
NC
1065 Returns TRUE upon success, FALSE otherwise. If successful then a
1066 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1067 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1068 responsibility to free the allocated buffer. */
1069
1070static bfd_boolean
dda8d76d
NC
1071slurp_rel_relocs (Filedata * filedata,
1072 unsigned long rel_offset,
1073 unsigned long rel_size,
1074 Elf_Internal_Rela ** relsp,
1075 unsigned long * nrelsp)
4d6ed7c8 1076{
2cf0635d 1077 Elf_Internal_Rela * rels;
8b73c356 1078 size_t nrels;
4d6ed7c8 1079 unsigned int i;
103f02d3 1080
4d6ed7c8
NC
1081 if (is_32bit_elf)
1082 {
2cf0635d 1083 Elf32_External_Rel * erels;
103f02d3 1084
dda8d76d 1085 erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 1086 rel_size, _("32-bit relocation data"));
a6e9f9df 1087 if (!erels)
32ec8896 1088 return FALSE;
103f02d3 1089
4d6ed7c8 1090 nrels = rel_size / sizeof (Elf32_External_Rel);
103f02d3 1091
3f5e193b 1092 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
103f02d3 1093
4d6ed7c8
NC
1094 if (rels == NULL)
1095 {
c256ffe7 1096 free (erels);
591a748a 1097 error (_("out of memory parsing relocs\n"));
32ec8896 1098 return FALSE;
4d6ed7c8
NC
1099 }
1100
1101 for (i = 0; i < nrels; i++)
1102 {
1103 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1104 rels[i].r_info = BYTE_GET (erels[i].r_info);
c8286bd1 1105 rels[i].r_addend = 0;
9ea033b2 1106 }
4d6ed7c8
NC
1107
1108 free (erels);
9c19a809
NC
1109 }
1110 else
1111 {
2cf0635d 1112 Elf64_External_Rel * erels;
9ea033b2 1113
dda8d76d 1114 erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
9cf03b7e 1115 rel_size, _("64-bit relocation data"));
a6e9f9df 1116 if (!erels)
32ec8896 1117 return FALSE;
103f02d3 1118
4d6ed7c8 1119 nrels = rel_size / sizeof (Elf64_External_Rel);
103f02d3 1120
3f5e193b 1121 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
103f02d3 1122
4d6ed7c8 1123 if (rels == NULL)
9c19a809 1124 {
c256ffe7 1125 free (erels);
591a748a 1126 error (_("out of memory parsing relocs\n"));
32ec8896 1127 return FALSE;
4d6ed7c8 1128 }
103f02d3 1129
4d6ed7c8
NC
1130 for (i = 0; i < nrels; i++)
1131 {
66543521
AM
1132 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1133 rels[i].r_info = BYTE_GET (erels[i].r_info);
c8286bd1 1134 rels[i].r_addend = 0;
861fb55a
DJ
1135
1136 /* The #ifdef BFD64 below is to prevent a compile time
1137 warning. We know that if we do not have a 64 bit data
1138 type that we will never execute this code anyway. */
1139#ifdef BFD64
dda8d76d
NC
1140 if (filedata->file_header.e_machine == EM_MIPS
1141 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
861fb55a
DJ
1142 {
1143 /* In little-endian objects, r_info isn't really a
1144 64-bit little-endian value: it has a 32-bit
1145 little-endian symbol index followed by four
1146 individual byte fields. Reorder INFO
1147 accordingly. */
91d6fa6a
NC
1148 bfd_vma inf = rels[i].r_info;
1149 inf = (((inf & 0xffffffff) << 32)
1150 | ((inf >> 56) & 0xff)
1151 | ((inf >> 40) & 0xff00)
1152 | ((inf >> 24) & 0xff0000)
1153 | ((inf >> 8) & 0xff000000));
1154 rels[i].r_info = inf;
861fb55a
DJ
1155 }
1156#endif /* BFD64 */
4d6ed7c8 1157 }
103f02d3 1158
4d6ed7c8
NC
1159 free (erels);
1160 }
32ec8896 1161
4d6ed7c8
NC
1162 *relsp = rels;
1163 *nrelsp = nrels;
32ec8896 1164 return TRUE;
4d6ed7c8 1165}
103f02d3 1166
aca88567
NC
1167/* Returns the reloc type extracted from the reloc info field. */
1168
1169static unsigned int
dda8d76d 1170get_reloc_type (Filedata * filedata, bfd_vma reloc_info)
aca88567
NC
1171{
1172 if (is_32bit_elf)
1173 return ELF32_R_TYPE (reloc_info);
1174
dda8d76d 1175 switch (filedata->file_header.e_machine)
aca88567
NC
1176 {
1177 case EM_MIPS:
1178 /* Note: We assume that reloc_info has already been adjusted for us. */
1179 return ELF64_MIPS_R_TYPE (reloc_info);
1180
1181 case EM_SPARCV9:
1182 return ELF64_R_TYPE_ID (reloc_info);
1183
1184 default:
1185 return ELF64_R_TYPE (reloc_info);
1186 }
1187}
1188
1189/* Return the symbol index extracted from the reloc info field. */
1190
1191static bfd_vma
1192get_reloc_symindex (bfd_vma reloc_info)
1193{
1194 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
1195}
1196
13761a11 1197static inline bfd_boolean
dda8d76d 1198uses_msp430x_relocs (Filedata * filedata)
13761a11
NC
1199{
1200 return
dda8d76d 1201 filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */
13761a11 1202 /* GCC uses osabi == ELFOSBI_STANDALONE. */
dda8d76d 1203 && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
13761a11 1204 /* TI compiler uses ELFOSABI_NONE. */
dda8d76d 1205 || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
13761a11
NC
1206}
1207
d3ba0551
AM
1208/* Display the contents of the relocation data found at the specified
1209 offset. */
ee42cf8c 1210
32ec8896 1211static bfd_boolean
dda8d76d
NC
1212dump_relocations (Filedata * filedata,
1213 unsigned long rel_offset,
1214 unsigned long rel_size,
1215 Elf_Internal_Sym * symtab,
1216 unsigned long nsyms,
1217 char * strtab,
1218 unsigned long strtablen,
1219 int is_rela,
1220 bfd_boolean is_dynsym)
4d6ed7c8 1221{
32ec8896 1222 unsigned long i;
2cf0635d 1223 Elf_Internal_Rela * rels;
32ec8896 1224 bfd_boolean res = TRUE;
103f02d3 1225
4d6ed7c8 1226 if (is_rela == UNKNOWN)
dda8d76d 1227 is_rela = guess_is_rela (filedata->file_header.e_machine);
103f02d3 1228
4d6ed7c8
NC
1229 if (is_rela)
1230 {
dda8d76d 1231 if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
32ec8896 1232 return FALSE;
4d6ed7c8
NC
1233 }
1234 else
1235 {
dda8d76d 1236 if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
32ec8896 1237 return FALSE;
252b5132
RH
1238 }
1239
410f7a12
L
1240 if (is_32bit_elf)
1241 {
1242 if (is_rela)
2c71103e
NC
1243 {
1244 if (do_wide)
1245 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1246 else
1247 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1248 }
410f7a12 1249 else
2c71103e
NC
1250 {
1251 if (do_wide)
1252 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1253 else
1254 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1255 }
410f7a12 1256 }
252b5132 1257 else
410f7a12
L
1258 {
1259 if (is_rela)
2c71103e
NC
1260 {
1261 if (do_wide)
8beeaeb7 1262 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
2c71103e
NC
1263 else
1264 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1265 }
410f7a12 1266 else
2c71103e
NC
1267 {
1268 if (do_wide)
8beeaeb7 1269 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
2c71103e
NC
1270 else
1271 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1272 }
410f7a12 1273 }
252b5132
RH
1274
1275 for (i = 0; i < rel_size; i++)
1276 {
2cf0635d 1277 const char * rtype;
b34976b6 1278 bfd_vma offset;
91d6fa6a 1279 bfd_vma inf;
b34976b6
AM
1280 bfd_vma symtab_index;
1281 bfd_vma type;
103f02d3 1282
b34976b6 1283 offset = rels[i].r_offset;
91d6fa6a 1284 inf = rels[i].r_info;
103f02d3 1285
dda8d76d 1286 type = get_reloc_type (filedata, inf);
91d6fa6a 1287 symtab_index = get_reloc_symindex (inf);
252b5132 1288
410f7a12
L
1289 if (is_32bit_elf)
1290 {
39dbeff8
AM
1291 printf ("%8.8lx %8.8lx ",
1292 (unsigned long) offset & 0xffffffff,
91d6fa6a 1293 (unsigned long) inf & 0xffffffff);
410f7a12
L
1294 }
1295 else
1296 {
39dbeff8 1297 printf (do_wide
d1ce973e
AM
1298 ? "%16.16" BFD_VMA_FMT "x %16.16" BFD_VMA_FMT "x "
1299 : "%12.12" BFD_VMA_FMT "x %12.12" BFD_VMA_FMT "x ",
91d6fa6a 1300 offset, inf);
410f7a12 1301 }
103f02d3 1302
dda8d76d 1303 switch (filedata->file_header.e_machine)
252b5132
RH
1304 {
1305 default:
1306 rtype = NULL;
1307 break;
1308
a06ea964
NC
1309 case EM_AARCH64:
1310 rtype = elf_aarch64_reloc_type (type);
1311 break;
1312
2b0337b0 1313 case EM_M32R:
252b5132 1314 case EM_CYGNUS_M32R:
9ea033b2 1315 rtype = elf_m32r_reloc_type (type);
252b5132
RH
1316 break;
1317
1318 case EM_386:
22abe556 1319 case EM_IAMCU:
9ea033b2 1320 rtype = elf_i386_reloc_type (type);
252b5132
RH
1321 break;
1322
ba2685cc
AM
1323 case EM_68HC11:
1324 case EM_68HC12:
1325 rtype = elf_m68hc11_reloc_type (type);
1326 break;
75751cd9 1327
7b4ae824
JD
1328 case EM_S12Z:
1329 rtype = elf_s12z_reloc_type (type);
1330 break;
1331
252b5132 1332 case EM_68K:
9ea033b2 1333 rtype = elf_m68k_reloc_type (type);
252b5132
RH
1334 break;
1335
f954747f
AM
1336 case EM_960:
1337 rtype = elf_i960_reloc_type (type);
1338 break;
1339
adde6300 1340 case EM_AVR:
2b0337b0 1341 case EM_AVR_OLD:
adde6300
AM
1342 rtype = elf_avr_reloc_type (type);
1343 break;
1344
9ea033b2
NC
1345 case EM_OLD_SPARCV9:
1346 case EM_SPARC32PLUS:
1347 case EM_SPARCV9:
252b5132 1348 case EM_SPARC:
9ea033b2 1349 rtype = elf_sparc_reloc_type (type);
252b5132
RH
1350 break;
1351
e9f53129
AM
1352 case EM_SPU:
1353 rtype = elf_spu_reloc_type (type);
1354 break;
1355
708e2187
NC
1356 case EM_V800:
1357 rtype = v800_reloc_type (type);
1358 break;
2b0337b0 1359 case EM_V850:
252b5132 1360 case EM_CYGNUS_V850:
9ea033b2 1361 rtype = v850_reloc_type (type);
252b5132
RH
1362 break;
1363
2b0337b0 1364 case EM_D10V:
252b5132 1365 case EM_CYGNUS_D10V:
9ea033b2 1366 rtype = elf_d10v_reloc_type (type);
252b5132
RH
1367 break;
1368
2b0337b0 1369 case EM_D30V:
252b5132 1370 case EM_CYGNUS_D30V:
9ea033b2 1371 rtype = elf_d30v_reloc_type (type);
252b5132
RH
1372 break;
1373
d172d4ba
NC
1374 case EM_DLX:
1375 rtype = elf_dlx_reloc_type (type);
1376 break;
1377
252b5132 1378 case EM_SH:
9ea033b2 1379 rtype = elf_sh_reloc_type (type);
252b5132
RH
1380 break;
1381
2b0337b0 1382 case EM_MN10300:
252b5132 1383 case EM_CYGNUS_MN10300:
9ea033b2 1384 rtype = elf_mn10300_reloc_type (type);
252b5132
RH
1385 break;
1386
2b0337b0 1387 case EM_MN10200:
252b5132 1388 case EM_CYGNUS_MN10200:
9ea033b2 1389 rtype = elf_mn10200_reloc_type (type);
252b5132
RH
1390 break;
1391
2b0337b0 1392 case EM_FR30:
252b5132 1393 case EM_CYGNUS_FR30:
9ea033b2 1394 rtype = elf_fr30_reloc_type (type);
252b5132
RH
1395 break;
1396
ba2685cc
AM
1397 case EM_CYGNUS_FRV:
1398 rtype = elf_frv_reloc_type (type);
1399 break;
5c70f934 1400
b8891f8d
AJ
1401 case EM_CSKY:
1402 rtype = elf_csky_reloc_type (type);
1403 break;
1404
3f8107ab
AM
1405 case EM_FT32:
1406 rtype = elf_ft32_reloc_type (type);
1407 break;
1408
252b5132 1409 case EM_MCORE:
9ea033b2 1410 rtype = elf_mcore_reloc_type (type);
252b5132
RH
1411 break;
1412
3c3bdf30
NC
1413 case EM_MMIX:
1414 rtype = elf_mmix_reloc_type (type);
1415 break;
1416
5506d11a
AM
1417 case EM_MOXIE:
1418 rtype = elf_moxie_reloc_type (type);
1419 break;
1420
2469cfa2 1421 case EM_MSP430:
dda8d76d 1422 if (uses_msp430x_relocs (filedata))
13761a11
NC
1423 {
1424 rtype = elf_msp430x_reloc_type (type);
1425 break;
1426 }
1a0670f3 1427 /* Fall through. */
2469cfa2
NC
1428 case EM_MSP430_OLD:
1429 rtype = elf_msp430_reloc_type (type);
1430 break;
1431
35c08157
KLC
1432 case EM_NDS32:
1433 rtype = elf_nds32_reloc_type (type);
1434 break;
1435
252b5132 1436 case EM_PPC:
9ea033b2 1437 rtype = elf_ppc_reloc_type (type);
252b5132
RH
1438 break;
1439
c833c019
AM
1440 case EM_PPC64:
1441 rtype = elf_ppc64_reloc_type (type);
1442 break;
1443
252b5132 1444 case EM_MIPS:
4fe85591 1445 case EM_MIPS_RS3_LE:
9ea033b2 1446 rtype = elf_mips_reloc_type (type);
252b5132
RH
1447 break;
1448
e23eba97
NC
1449 case EM_RISCV:
1450 rtype = elf_riscv_reloc_type (type);
1451 break;
1452
252b5132 1453 case EM_ALPHA:
9ea033b2 1454 rtype = elf_alpha_reloc_type (type);
252b5132
RH
1455 break;
1456
1457 case EM_ARM:
9ea033b2 1458 rtype = elf_arm_reloc_type (type);
252b5132
RH
1459 break;
1460
584da044 1461 case EM_ARC:
886a2506
NC
1462 case EM_ARC_COMPACT:
1463 case EM_ARC_COMPACT2:
9ea033b2 1464 rtype = elf_arc_reloc_type (type);
252b5132
RH
1465 break;
1466
1467 case EM_PARISC:
69e617ca 1468 rtype = elf_hppa_reloc_type (type);
252b5132 1469 break;
7d466069 1470
b8720f9d
JL
1471 case EM_H8_300:
1472 case EM_H8_300H:
1473 case EM_H8S:
1474 rtype = elf_h8_reloc_type (type);
1475 break;
1476
73589c9d
CS
1477 case EM_OR1K:
1478 rtype = elf_or1k_reloc_type (type);
3b16e843
NC
1479 break;
1480
7d466069 1481 case EM_PJ:
2b0337b0 1482 case EM_PJ_OLD:
7d466069
ILT
1483 rtype = elf_pj_reloc_type (type);
1484 break;
800eeca4
JW
1485 case EM_IA_64:
1486 rtype = elf_ia64_reloc_type (type);
1487 break;
1b61cf92
HPN
1488
1489 case EM_CRIS:
1490 rtype = elf_cris_reloc_type (type);
1491 break;
535c37ff 1492
f954747f
AM
1493 case EM_860:
1494 rtype = elf_i860_reloc_type (type);
1495 break;
1496
bcedfee6 1497 case EM_X86_64:
8a9036a4 1498 case EM_L1OM:
7a9068fe 1499 case EM_K1OM:
bcedfee6
NC
1500 rtype = elf_x86_64_reloc_type (type);
1501 break;
a85d7ed0 1502
f954747f
AM
1503 case EM_S370:
1504 rtype = i370_reloc_type (type);
1505 break;
1506
53c7db4b
KH
1507 case EM_S390_OLD:
1508 case EM_S390:
1509 rtype = elf_s390_reloc_type (type);
1510 break;
93fbbb04 1511
1c0d3aa6
NC
1512 case EM_SCORE:
1513 rtype = elf_score_reloc_type (type);
1514 break;
1515
93fbbb04
GK
1516 case EM_XSTORMY16:
1517 rtype = elf_xstormy16_reloc_type (type);
1518 break;
179d3252 1519
1fe1f39c
NC
1520 case EM_CRX:
1521 rtype = elf_crx_reloc_type (type);
1522 break;
1523
179d3252
JT
1524 case EM_VAX:
1525 rtype = elf_vax_reloc_type (type);
1526 break;
1e4cf259 1527
619ed720
EB
1528 case EM_VISIUM:
1529 rtype = elf_visium_reloc_type (type);
1530 break;
1531
aca4efc7
JM
1532 case EM_BPF:
1533 rtype = elf_bpf_reloc_type (type);
1534 break;
1535
cfb8c092
NC
1536 case EM_ADAPTEVA_EPIPHANY:
1537 rtype = elf_epiphany_reloc_type (type);
1538 break;
1539
1e4cf259
NC
1540 case EM_IP2K:
1541 case EM_IP2K_OLD:
1542 rtype = elf_ip2k_reloc_type (type);
1543 break;
3b36097d
SC
1544
1545 case EM_IQ2000:
1546 rtype = elf_iq2000_reloc_type (type);
1547 break;
88da6820
NC
1548
1549 case EM_XTENSA_OLD:
1550 case EM_XTENSA:
1551 rtype = elf_xtensa_reloc_type (type);
1552 break;
a34e3ecb 1553
84e94c90
NC
1554 case EM_LATTICEMICO32:
1555 rtype = elf_lm32_reloc_type (type);
1556 break;
1557
ff7eeb89 1558 case EM_M32C_OLD:
49f58d10
JB
1559 case EM_M32C:
1560 rtype = elf_m32c_reloc_type (type);
1561 break;
1562
d031aafb
NS
1563 case EM_MT:
1564 rtype = elf_mt_reloc_type (type);
a34e3ecb 1565 break;
1d65ded4
CM
1566
1567 case EM_BLACKFIN:
1568 rtype = elf_bfin_reloc_type (type);
1569 break;
15ab5209
DB
1570
1571 case EM_CYGNUS_MEP:
1572 rtype = elf_mep_reloc_type (type);
1573 break;
60bca95a
NC
1574
1575 case EM_CR16:
1576 rtype = elf_cr16_reloc_type (type);
1577 break;
dd24e3da 1578
7ba29e2a
NC
1579 case EM_MICROBLAZE:
1580 case EM_MICROBLAZE_OLD:
1581 rtype = elf_microblaze_reloc_type (type);
1582 break;
c7927a3c 1583
99c513f6
DD
1584 case EM_RL78:
1585 rtype = elf_rl78_reloc_type (type);
1586 break;
1587
c7927a3c
NC
1588 case EM_RX:
1589 rtype = elf_rx_reloc_type (type);
1590 break;
c29aca4a 1591
a3c62988
NC
1592 case EM_METAG:
1593 rtype = elf_metag_reloc_type (type);
1594 break;
1595
c29aca4a
NC
1596 case EM_XC16X:
1597 case EM_C166:
1598 rtype = elf_xc16x_reloc_type (type);
1599 break;
40b36596
JM
1600
1601 case EM_TI_C6000:
1602 rtype = elf_tic6x_reloc_type (type);
1603 break;
aa137e4d
NC
1604
1605 case EM_TILEGX:
1606 rtype = elf_tilegx_reloc_type (type);
1607 break;
1608
1609 case EM_TILEPRO:
1610 rtype = elf_tilepro_reloc_type (type);
1611 break;
f6c1a2d5 1612
f96bd6c2
PC
1613 case EM_WEBASSEMBLY:
1614 rtype = elf_wasm32_reloc_type (type);
1615 break;
1616
f6c1a2d5
NC
1617 case EM_XGATE:
1618 rtype = elf_xgate_reloc_type (type);
1619 break;
36591ba1
SL
1620
1621 case EM_ALTERA_NIOS2:
1622 rtype = elf_nios2_reloc_type (type);
1623 break;
2b100bb5
DD
1624
1625 case EM_TI_PRU:
1626 rtype = elf_pru_reloc_type (type);
1627 break;
fe944acf
FT
1628
1629 case EM_NFP:
1630 if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200)
1631 rtype = elf_nfp3200_reloc_type (type);
1632 else
1633 rtype = elf_nfp_reloc_type (type);
1634 break;
6655dba2
SB
1635
1636 case EM_Z80:
1637 rtype = elf_z80_reloc_type (type);
1638 break;
252b5132
RH
1639 }
1640
1641 if (rtype == NULL)
39dbeff8 1642 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
252b5132 1643 else
5c144731 1644 printf (do_wide ? "%-22s" : "%-17.17s", rtype);
252b5132 1645
dda8d76d 1646 if (filedata->file_header.e_machine == EM_ALPHA
157c2599 1647 && rtype != NULL
7ace3541
RH
1648 && streq (rtype, "R_ALPHA_LITUSE")
1649 && is_rela)
1650 {
1651 switch (rels[i].r_addend)
1652 {
1653 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1654 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1655 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1656 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1657 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1658 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1659 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1660 default: rtype = NULL;
1661 }
32ec8896 1662
7ace3541
RH
1663 if (rtype)
1664 printf (" (%s)", rtype);
1665 else
1666 {
1667 putchar (' ');
1668 printf (_("<unknown addend: %lx>"),
1669 (unsigned long) rels[i].r_addend);
32ec8896 1670 res = FALSE;
7ace3541
RH
1671 }
1672 }
1673 else if (symtab_index)
252b5132 1674 {
af3fc3bc 1675 if (symtab == NULL || symtab_index >= nsyms)
32ec8896 1676 {
27a45f42
AS
1677 error (_(" bad symbol index: %08lx in reloc\n"),
1678 (unsigned long) symtab_index);
32ec8896
NC
1679 res = FALSE;
1680 }
af3fc3bc 1681 else
19936277 1682 {
2cf0635d 1683 Elf_Internal_Sym * psym;
bb4d2ac2
L
1684 const char * version_string;
1685 enum versioned_symbol_info sym_info;
1686 unsigned short vna_other;
19936277 1687
af3fc3bc 1688 psym = symtab + symtab_index;
103f02d3 1689
bb4d2ac2 1690 version_string
dda8d76d 1691 = get_symbol_version_string (filedata, is_dynsym,
bb4d2ac2
L
1692 strtab, strtablen,
1693 symtab_index,
1694 psym,
1695 &sym_info,
1696 &vna_other);
1697
af3fc3bc 1698 printf (" ");
171191ba 1699
d8045f23
NC
1700 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
1701 {
1702 const char * name;
1703 unsigned int len;
1704 unsigned int width = is_32bit_elf ? 8 : 14;
1705
1706 /* Relocations against GNU_IFUNC symbols do not use the value
1707 of the symbol as the address to relocate against. Instead
1708 they invoke the function named by the symbol and use its
1709 result as the address for relocation.
1710
1711 To indicate this to the user, do not display the value of
1712 the symbol in the "Symbols's Value" field. Instead show
1713 its name followed by () as a hint that the symbol is
1714 invoked. */
1715
1716 if (strtab == NULL
1717 || psym->st_name == 0
1718 || psym->st_name >= strtablen)
1719 name = "??";
1720 else
1721 name = strtab + psym->st_name;
1722
1723 len = print_symbol (width, name);
bb4d2ac2
L
1724 if (version_string)
1725 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1726 version_string);
d8045f23
NC
1727 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
1728 }
1729 else
1730 {
1731 print_vma (psym->st_value, LONG_HEX);
171191ba 1732
d8045f23
NC
1733 printf (is_32bit_elf ? " " : " ");
1734 }
103f02d3 1735
af3fc3bc 1736 if (psym->st_name == 0)
f1ef08cb 1737 {
2cf0635d 1738 const char * sec_name = "<null>";
f1ef08cb
AM
1739 char name_buf[40];
1740
1741 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1742 {
dda8d76d 1743 if (psym->st_shndx < filedata->file_header.e_shnum)
b9e920ec
AM
1744 sec_name = SECTION_NAME_PRINT (filedata->section_headers
1745 + psym->st_shndx);
f1ef08cb
AM
1746 else if (psym->st_shndx == SHN_ABS)
1747 sec_name = "ABS";
1748 else if (psym->st_shndx == SHN_COMMON)
1749 sec_name = "COMMON";
dda8d76d 1750 else if ((filedata->file_header.e_machine == EM_MIPS
ac145307 1751 && psym->st_shndx == SHN_MIPS_SCOMMON)
dda8d76d 1752 || (filedata->file_header.e_machine == EM_TI_C6000
ac145307 1753 && psym->st_shndx == SHN_TIC6X_SCOMMON))
172553c7 1754 sec_name = "SCOMMON";
dda8d76d 1755 else if (filedata->file_header.e_machine == EM_MIPS
172553c7
TS
1756 && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1757 sec_name = "SUNDEF";
dda8d76d
NC
1758 else if ((filedata->file_header.e_machine == EM_X86_64
1759 || filedata->file_header.e_machine == EM_L1OM
1760 || filedata->file_header.e_machine == EM_K1OM)
3b22753a
L
1761 && psym->st_shndx == SHN_X86_64_LCOMMON)
1762 sec_name = "LARGE_COMMON";
dda8d76d
NC
1763 else if (filedata->file_header.e_machine == EM_IA_64
1764 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
9ce701e2
L
1765 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1766 sec_name = "ANSI_COM";
dda8d76d 1767 else if (is_ia64_vms (filedata)
148b93f2
NC
1768 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
1769 sec_name = "VMS_SYMVEC";
f1ef08cb
AM
1770 else
1771 {
1772 sprintf (name_buf, "<section 0x%x>",
1773 (unsigned int) psym->st_shndx);
1774 sec_name = name_buf;
1775 }
1776 }
1777 print_symbol (22, sec_name);
1778 }
af3fc3bc 1779 else if (strtab == NULL)
d79b3d50 1780 printf (_("<string table index: %3ld>"), psym->st_name);
c256ffe7 1781 else if (psym->st_name >= strtablen)
32ec8896 1782 {
27a45f42
AS
1783 error (_("<corrupt string table index: %3ld>\n"),
1784 psym->st_name);
32ec8896
NC
1785 res = FALSE;
1786 }
af3fc3bc 1787 else
bb4d2ac2
L
1788 {
1789 print_symbol (22, strtab + psym->st_name);
1790 if (version_string)
1791 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1792 version_string);
1793 }
103f02d3 1794
af3fc3bc 1795 if (is_rela)
171191ba 1796 {
7360e63f 1797 bfd_vma off = rels[i].r_addend;
171191ba 1798
7360e63f 1799 if ((bfd_signed_vma) off < 0)
598aaa76 1800 printf (" - %" BFD_VMA_FMT "x", - off);
171191ba 1801 else
598aaa76 1802 printf (" + %" BFD_VMA_FMT "x", off);
171191ba 1803 }
19936277 1804 }
252b5132 1805 }
1b228002 1806 else if (is_rela)
f7a99963 1807 {
7360e63f 1808 bfd_vma off = rels[i].r_addend;
e04d7088
L
1809
1810 printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
7360e63f 1811 if ((bfd_signed_vma) off < 0)
e04d7088
L
1812 printf ("-%" BFD_VMA_FMT "x", - off);
1813 else
1814 printf ("%" BFD_VMA_FMT "x", off);
f7a99963 1815 }
252b5132 1816
dda8d76d 1817 if (filedata->file_header.e_machine == EM_SPARCV9
157c2599
NC
1818 && rtype != NULL
1819 && streq (rtype, "R_SPARC_OLO10"))
91d6fa6a 1820 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
351b4b40 1821
252b5132 1822 putchar ('\n');
2c71103e 1823
aca88567 1824#ifdef BFD64
dda8d76d 1825 if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
2c71103e 1826 {
91d6fa6a
NC
1827 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
1828 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
2cf0635d
NC
1829 const char * rtype2 = elf_mips_reloc_type (type2);
1830 const char * rtype3 = elf_mips_reloc_type (type3);
aca88567 1831
2c71103e
NC
1832 printf (" Type2: ");
1833
1834 if (rtype2 == NULL)
39dbeff8
AM
1835 printf (_("unrecognized: %-7lx"),
1836 (unsigned long) type2 & 0xffffffff);
2c71103e
NC
1837 else
1838 printf ("%-17.17s", rtype2);
1839
18bd398b 1840 printf ("\n Type3: ");
2c71103e
NC
1841
1842 if (rtype3 == NULL)
39dbeff8
AM
1843 printf (_("unrecognized: %-7lx"),
1844 (unsigned long) type3 & 0xffffffff);
2c71103e
NC
1845 else
1846 printf ("%-17.17s", rtype3);
1847
53c7db4b 1848 putchar ('\n');
2c71103e 1849 }
aca88567 1850#endif /* BFD64 */
252b5132
RH
1851 }
1852
c8286bd1 1853 free (rels);
32ec8896
NC
1854
1855 return res;
252b5132
RH
1856}
1857
37c18eed
SD
1858static const char *
1859get_aarch64_dynamic_type (unsigned long type)
1860{
1861 switch (type)
1862 {
1863 case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT";
1dbade74 1864 case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT";
2301ed1c 1865 case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS";
37c18eed
SD
1866 default:
1867 return NULL;
1868 }
1869}
1870
252b5132 1871static const char *
d3ba0551 1872get_mips_dynamic_type (unsigned long type)
252b5132
RH
1873{
1874 switch (type)
1875 {
1876 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1877 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1878 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1879 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1880 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1881 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1882 case DT_MIPS_MSYM: return "MIPS_MSYM";
1883 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1884 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1885 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1886 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1887 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1888 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1889 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1890 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1891 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1892 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
a5499fa4 1893 case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
252b5132
RH
1894 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1895 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1896 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1897 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1898 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1899 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1900 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1901 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1902 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1903 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1904 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1905 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1906 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1907 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1908 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1909 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1910 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1911 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1912 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1913 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1914 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1915 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1916 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1917 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1918 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1919 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
861fb55a
DJ
1920 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
1921 case DT_MIPS_RWPLT: return "MIPS_RWPLT";
f16a9783 1922 case DT_MIPS_XHASH: return "MIPS_XHASH";
252b5132
RH
1923 default:
1924 return NULL;
1925 }
1926}
1927
9a097730 1928static const char *
d3ba0551 1929get_sparc64_dynamic_type (unsigned long type)
9a097730
RH
1930{
1931 switch (type)
1932 {
1933 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1934 default:
1935 return NULL;
1936 }
103f02d3
UD
1937}
1938
7490d522
AM
1939static const char *
1940get_ppc_dynamic_type (unsigned long type)
1941{
1942 switch (type)
1943 {
a7f2871e 1944 case DT_PPC_GOT: return "PPC_GOT";
e8910a83 1945 case DT_PPC_OPT: return "PPC_OPT";
7490d522
AM
1946 default:
1947 return NULL;
1948 }
1949}
1950
f1cb7e17 1951static const char *
d3ba0551 1952get_ppc64_dynamic_type (unsigned long type)
f1cb7e17
AM
1953{
1954 switch (type)
1955 {
a7f2871e
AM
1956 case DT_PPC64_GLINK: return "PPC64_GLINK";
1957 case DT_PPC64_OPD: return "PPC64_OPD";
1958 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
e8910a83 1959 case DT_PPC64_OPT: return "PPC64_OPT";
f1cb7e17
AM
1960 default:
1961 return NULL;
1962 }
1963}
1964
103f02d3 1965static const char *
d3ba0551 1966get_parisc_dynamic_type (unsigned long type)
103f02d3
UD
1967{
1968 switch (type)
1969 {
1970 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1971 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1972 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1973 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1974 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1975 case DT_HP_PREINIT: return "HP_PREINIT";
1976 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1977 case DT_HP_NEEDED: return "HP_NEEDED";
1978 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1979 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1980 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1981 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1982 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
eec8f817
DA
1983 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1984 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1985 case DT_HP_FILTERED: return "HP_FILTERED";
1986 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1987 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1988 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1989 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1990 case DT_PLT: return "PLT";
1991 case DT_PLT_SIZE: return "PLT_SIZE";
1992 case DT_DLT: return "DLT";
1993 case DT_DLT_SIZE: return "DLT_SIZE";
103f02d3
UD
1994 default:
1995 return NULL;
1996 }
1997}
9a097730 1998
ecc51f48 1999static const char *
d3ba0551 2000get_ia64_dynamic_type (unsigned long type)
ecc51f48
NC
2001{
2002 switch (type)
2003 {
148b93f2
NC
2004 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
2005 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
2006 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
2007 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
2008 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
2009 case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
2010 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
2011 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
2012 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
2013 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
2014 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
2015 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
2016 case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
2017 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
2018 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
2019 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
2020 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
2021 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
2022 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
2023 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
2024 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
2025 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
2026 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
2027 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
2028 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
2029 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
2030 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
2031 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
2032 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
2033 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
2034 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
ecc51f48
NC
2035 default:
2036 return NULL;
2037 }
2038}
2039
fd85a6a1
NC
2040static const char *
2041get_solaris_section_type (unsigned long type)
2042{
2043 switch (type)
2044 {
2045 case 0x6fffffee: return "SUNW_ancillary";
2046 case 0x6fffffef: return "SUNW_capchain";
2047 case 0x6ffffff0: return "SUNW_capinfo";
2048 case 0x6ffffff1: return "SUNW_symsort";
2049 case 0x6ffffff2: return "SUNW_tlssort";
2050 case 0x6ffffff3: return "SUNW_LDYNSYM";
2051 case 0x6ffffff4: return "SUNW_dof";
2052 case 0x6ffffff5: return "SUNW_cap";
2053 case 0x6ffffff6: return "SUNW_SIGNATURE";
2054 case 0x6ffffff7: return "SUNW_ANNOTATE";
2055 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2056 case 0x6ffffff9: return "SUNW_DEBUG";
2057 case 0x6ffffffa: return "SUNW_move";
2058 case 0x6ffffffb: return "SUNW_COMDAT";
2059 case 0x6ffffffc: return "SUNW_syminfo";
2060 case 0x6ffffffd: return "SUNW_verdef";
2061 case 0x6ffffffe: return "SUNW_verneed";
2062 case 0x6fffffff: return "SUNW_versym";
2063 case 0x70000000: return "SPARC_GOTDATA";
2064 default: return NULL;
2065 }
2066}
2067
fabcb361
RH
2068static const char *
2069get_alpha_dynamic_type (unsigned long type)
2070{
2071 switch (type)
2072 {
2073 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
32ec8896 2074 default: return NULL;
fabcb361
RH
2075 }
2076}
2077
1c0d3aa6
NC
2078static const char *
2079get_score_dynamic_type (unsigned long type)
2080{
2081 switch (type)
2082 {
2083 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
2084 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
2085 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
2086 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
2087 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
2088 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
32ec8896 2089 default: return NULL;
1c0d3aa6
NC
2090 }
2091}
2092
40b36596
JM
2093static const char *
2094get_tic6x_dynamic_type (unsigned long type)
2095{
2096 switch (type)
2097 {
2098 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
2099 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
2100 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
2101 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
2102 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
2103 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
32ec8896 2104 default: return NULL;
40b36596
JM
2105 }
2106}
1c0d3aa6 2107
36591ba1
SL
2108static const char *
2109get_nios2_dynamic_type (unsigned long type)
2110{
2111 switch (type)
2112 {
2113 case DT_NIOS2_GP: return "NIOS2_GP";
32ec8896 2114 default: return NULL;
36591ba1
SL
2115 }
2116}
2117
fd85a6a1
NC
2118static const char *
2119get_solaris_dynamic_type (unsigned long type)
2120{
2121 switch (type)
2122 {
2123 case 0x6000000d: return "SUNW_AUXILIARY";
2124 case 0x6000000e: return "SUNW_RTLDINF";
2125 case 0x6000000f: return "SUNW_FILTER";
2126 case 0x60000010: return "SUNW_CAP";
2127 case 0x60000011: return "SUNW_SYMTAB";
2128 case 0x60000012: return "SUNW_SYMSZ";
2129 case 0x60000013: return "SUNW_SORTENT";
2130 case 0x60000014: return "SUNW_SYMSORT";
2131 case 0x60000015: return "SUNW_SYMSORTSZ";
2132 case 0x60000016: return "SUNW_TLSSORT";
2133 case 0x60000017: return "SUNW_TLSSORTSZ";
2134 case 0x60000018: return "SUNW_CAPINFO";
2135 case 0x60000019: return "SUNW_STRPAD";
2136 case 0x6000001a: return "SUNW_CAPCHAIN";
2137 case 0x6000001b: return "SUNW_LDMACH";
2138 case 0x6000001d: return "SUNW_CAPCHAINENT";
2139 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2140 case 0x60000021: return "SUNW_PARENT";
2141 case 0x60000023: return "SUNW_ASLR";
2142 case 0x60000025: return "SUNW_RELAX";
2143 case 0x60000029: return "SUNW_NXHEAP";
2144 case 0x6000002b: return "SUNW_NXSTACK";
2145
2146 case 0x70000001: return "SPARC_REGISTER";
2147 case 0x7ffffffd: return "AUXILIARY";
2148 case 0x7ffffffe: return "USED";
2149 case 0x7fffffff: return "FILTER";
2150
15f205b1 2151 default: return NULL;
fd85a6a1
NC
2152 }
2153}
2154
252b5132 2155static const char *
dda8d76d 2156get_dynamic_type (Filedata * filedata, unsigned long type)
252b5132 2157{
e9e44622 2158 static char buff[64];
252b5132
RH
2159
2160 switch (type)
2161 {
2162 case DT_NULL: return "NULL";
2163 case DT_NEEDED: return "NEEDED";
2164 case DT_PLTRELSZ: return "PLTRELSZ";
2165 case DT_PLTGOT: return "PLTGOT";
2166 case DT_HASH: return "HASH";
2167 case DT_STRTAB: return "STRTAB";
2168 case DT_SYMTAB: return "SYMTAB";
2169 case DT_RELA: return "RELA";
2170 case DT_RELASZ: return "RELASZ";
2171 case DT_RELAENT: return "RELAENT";
2172 case DT_STRSZ: return "STRSZ";
2173 case DT_SYMENT: return "SYMENT";
2174 case DT_INIT: return "INIT";
2175 case DT_FINI: return "FINI";
2176 case DT_SONAME: return "SONAME";
2177 case DT_RPATH: return "RPATH";
2178 case DT_SYMBOLIC: return "SYMBOLIC";
2179 case DT_REL: return "REL";
2180 case DT_RELSZ: return "RELSZ";
2181 case DT_RELENT: return "RELENT";
2182 case DT_PLTREL: return "PLTREL";
2183 case DT_DEBUG: return "DEBUG";
2184 case DT_TEXTREL: return "TEXTREL";
2185 case DT_JMPREL: return "JMPREL";
2186 case DT_BIND_NOW: return "BIND_NOW";
2187 case DT_INIT_ARRAY: return "INIT_ARRAY";
2188 case DT_FINI_ARRAY: return "FINI_ARRAY";
2189 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
2190 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
d1133906
NC
2191 case DT_RUNPATH: return "RUNPATH";
2192 case DT_FLAGS: return "FLAGS";
2d0e6f43 2193
d1133906
NC
2194 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2195 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
6d913794 2196 case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX";
103f02d3 2197
05107a46 2198 case DT_CHECKSUM: return "CHECKSUM";
252b5132
RH
2199 case DT_PLTPADSZ: return "PLTPADSZ";
2200 case DT_MOVEENT: return "MOVEENT";
2201 case DT_MOVESZ: return "MOVESZ";
dcefbbbd 2202 case DT_FEATURE: return "FEATURE";
252b5132
RH
2203 case DT_POSFLAG_1: return "POSFLAG_1";
2204 case DT_SYMINSZ: return "SYMINSZ";
2205 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
103f02d3 2206
252b5132 2207 case DT_ADDRRNGLO: return "ADDRRNGLO";
dcefbbbd
L
2208 case DT_CONFIG: return "CONFIG";
2209 case DT_DEPAUDIT: return "DEPAUDIT";
2210 case DT_AUDIT: return "AUDIT";
2211 case DT_PLTPAD: return "PLTPAD";
2212 case DT_MOVETAB: return "MOVETAB";
252b5132 2213 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
103f02d3 2214
252b5132 2215 case DT_VERSYM: return "VERSYM";
103f02d3 2216
67a4f2b7
AO
2217 case DT_TLSDESC_GOT: return "TLSDESC_GOT";
2218 case DT_TLSDESC_PLT: return "TLSDESC_PLT";
252b5132
RH
2219 case DT_RELACOUNT: return "RELACOUNT";
2220 case DT_RELCOUNT: return "RELCOUNT";
2221 case DT_FLAGS_1: return "FLAGS_1";
2222 case DT_VERDEF: return "VERDEF";
2223 case DT_VERDEFNUM: return "VERDEFNUM";
2224 case DT_VERNEED: return "VERNEED";
2225 case DT_VERNEEDNUM: return "VERNEEDNUM";
103f02d3 2226
019148e4 2227 case DT_AUXILIARY: return "AUXILIARY";
252b5132
RH
2228 case DT_USED: return "USED";
2229 case DT_FILTER: return "FILTER";
103f02d3 2230
047b2264
JJ
2231 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
2232 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
2233 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
2234 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
2235 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
fdc90cb4 2236 case DT_GNU_HASH: return "GNU_HASH";
a5da3dee 2237 case DT_GNU_FLAGS_1: return "GNU_FLAGS_1";
047b2264 2238
252b5132
RH
2239 default:
2240 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
2241 {
2cf0635d 2242 const char * result;
103f02d3 2243
dda8d76d 2244 switch (filedata->file_header.e_machine)
252b5132 2245 {
37c18eed
SD
2246 case EM_AARCH64:
2247 result = get_aarch64_dynamic_type (type);
2248 break;
252b5132 2249 case EM_MIPS:
4fe85591 2250 case EM_MIPS_RS3_LE:
252b5132
RH
2251 result = get_mips_dynamic_type (type);
2252 break;
9a097730
RH
2253 case EM_SPARCV9:
2254 result = get_sparc64_dynamic_type (type);
2255 break;
7490d522
AM
2256 case EM_PPC:
2257 result = get_ppc_dynamic_type (type);
2258 break;
f1cb7e17
AM
2259 case EM_PPC64:
2260 result = get_ppc64_dynamic_type (type);
2261 break;
ecc51f48
NC
2262 case EM_IA_64:
2263 result = get_ia64_dynamic_type (type);
2264 break;
fabcb361
RH
2265 case EM_ALPHA:
2266 result = get_alpha_dynamic_type (type);
2267 break;
1c0d3aa6
NC
2268 case EM_SCORE:
2269 result = get_score_dynamic_type (type);
2270 break;
40b36596
JM
2271 case EM_TI_C6000:
2272 result = get_tic6x_dynamic_type (type);
2273 break;
36591ba1
SL
2274 case EM_ALTERA_NIOS2:
2275 result = get_nios2_dynamic_type (type);
2276 break;
252b5132 2277 default:
dda8d76d 2278 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
2279 result = get_solaris_dynamic_type (type);
2280 else
2281 result = NULL;
252b5132
RH
2282 break;
2283 }
2284
2285 if (result != NULL)
2286 return result;
2287
e9e44622 2288 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
252b5132 2289 }
eec8f817 2290 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
dda8d76d 2291 || (filedata->file_header.e_machine == EM_PARISC
eec8f817 2292 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
103f02d3 2293 {
2cf0635d 2294 const char * result;
103f02d3 2295
dda8d76d 2296 switch (filedata->file_header.e_machine)
103f02d3
UD
2297 {
2298 case EM_PARISC:
2299 result = get_parisc_dynamic_type (type);
2300 break;
148b93f2
NC
2301 case EM_IA_64:
2302 result = get_ia64_dynamic_type (type);
2303 break;
103f02d3 2304 default:
dda8d76d 2305 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
2306 result = get_solaris_dynamic_type (type);
2307 else
2308 result = NULL;
103f02d3
UD
2309 break;
2310 }
2311
2312 if (result != NULL)
2313 return result;
2314
e9e44622
JJ
2315 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
2316 type);
103f02d3 2317 }
252b5132 2318 else
e9e44622 2319 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
103f02d3 2320
252b5132
RH
2321 return buff;
2322 }
2323}
2324
2325static char *
d3ba0551 2326get_file_type (unsigned e_type)
252b5132 2327{
89246a0e 2328 static char buff[64];
252b5132
RH
2329
2330 switch (e_type)
2331 {
32ec8896
NC
2332 case ET_NONE: return _("NONE (None)");
2333 case ET_REL: return _("REL (Relocatable file)");
2334 case ET_EXEC: return _("EXEC (Executable file)");
2335 case ET_DYN: return _("DYN (Shared object file)");
2336 case ET_CORE: return _("CORE (Core file)");
252b5132
RH
2337
2338 default:
2339 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
e9e44622 2340 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
252b5132 2341 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
e9e44622 2342 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
252b5132 2343 else
e9e44622 2344 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
252b5132
RH
2345 return buff;
2346 }
2347}
2348
2349static char *
d3ba0551 2350get_machine_name (unsigned e_machine)
252b5132 2351{
b34976b6 2352 static char buff[64]; /* XXX */
252b5132
RH
2353
2354 switch (e_machine)
2355 {
55e22ca8
NC
2356 /* Please keep this switch table sorted by increasing EM_ value. */
2357 /* 0 */
c45021f2
NC
2358 case EM_NONE: return _("None");
2359 case EM_M32: return "WE32100";
2360 case EM_SPARC: return "Sparc";
2361 case EM_386: return "Intel 80386";
2362 case EM_68K: return "MC68000";
2363 case EM_88K: return "MC88000";
22abe556 2364 case EM_IAMCU: return "Intel MCU";
fb70ec17 2365 case EM_860: return "Intel 80860";
c45021f2
NC
2366 case EM_MIPS: return "MIPS R3000";
2367 case EM_S370: return "IBM System/370";
55e22ca8 2368 /* 10 */
7036c0e1 2369 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
252b5132 2370 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
c45021f2 2371 case EM_PARISC: return "HPPA";
55e22ca8 2372 case EM_VPP550: return "Fujitsu VPP500";
7036c0e1 2373 case EM_SPARC32PLUS: return "Sparc v8+" ;
d7867d17 2374 case EM_960: return "Intel 80960";
c45021f2 2375 case EM_PPC: return "PowerPC";
55e22ca8 2376 /* 20 */
285d1771 2377 case EM_PPC64: return "PowerPC64";
55e22ca8
NC
2378 case EM_S390_OLD:
2379 case EM_S390: return "IBM S/390";
2380 case EM_SPU: return "SPU";
2381 /* 30 */
2382 case EM_V800: return "Renesas V850 (using RH850 ABI)";
c45021f2
NC
2383 case EM_FR20: return "Fujitsu FR20";
2384 case EM_RH32: return "TRW RH32";
b34976b6 2385 case EM_MCORE: return "MCORE";
55e22ca8 2386 /* 40 */
7036c0e1
AJ
2387 case EM_ARM: return "ARM";
2388 case EM_OLD_ALPHA: return "Digital Alpha (old)";
ef230218 2389 case EM_SH: return "Renesas / SuperH SH";
c45021f2
NC
2390 case EM_SPARCV9: return "Sparc v9";
2391 case EM_TRICORE: return "Siemens Tricore";
584da044 2392 case EM_ARC: return "ARC";
c2dcd04e
NC
2393 case EM_H8_300: return "Renesas H8/300";
2394 case EM_H8_300H: return "Renesas H8/300H";
2395 case EM_H8S: return "Renesas H8S";
2396 case EM_H8_500: return "Renesas H8/500";
55e22ca8 2397 /* 50 */
30800947 2398 case EM_IA_64: return "Intel IA-64";
252b5132
RH
2399 case EM_MIPS_X: return "Stanford MIPS-X";
2400 case EM_COLDFIRE: return "Motorola Coldfire";
55e22ca8 2401 case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
7036c0e1
AJ
2402 case EM_MMA: return "Fujitsu Multimedia Accelerator";
2403 case EM_PCP: return "Siemens PCP";
2404 case EM_NCPU: return "Sony nCPU embedded RISC processor";
2405 case EM_NDR1: return "Denso NDR1 microprocesspr";
2406 case EM_STARCORE: return "Motorola Star*Core processor";
2407 case EM_ME16: return "Toyota ME16 processor";
55e22ca8 2408 /* 60 */
7036c0e1
AJ
2409 case EM_ST100: return "STMicroelectronics ST100 processor";
2410 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
55e22ca8 2411 case EM_X86_64: return "Advanced Micro Devices X86-64";
11636f9e
JM
2412 case EM_PDSP: return "Sony DSP processor";
2413 case EM_PDP10: return "Digital Equipment Corp. PDP-10";
2414 case EM_PDP11: return "Digital Equipment Corp. PDP-11";
7036c0e1
AJ
2415 case EM_FX66: return "Siemens FX66 microcontroller";
2416 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2417 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
2418 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
55e22ca8 2419 /* 70 */
7036c0e1
AJ
2420 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
2421 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
2422 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
2423 case EM_SVX: return "Silicon Graphics SVx";
2424 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
2425 case EM_VAX: return "Digital VAX";
1b61cf92 2426 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
c45021f2
NC
2427 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
2428 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
2429 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
55e22ca8 2430 /* 80 */
b34976b6 2431 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
c45021f2 2432 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
3b36097d 2433 case EM_PRISM: return "Vitesse Prism";
55e22ca8
NC
2434 case EM_AVR_OLD:
2435 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
2436 case EM_CYGNUS_FR30:
2437 case EM_FR30: return "Fujitsu FR30";
2438 case EM_CYGNUS_D10V:
2439 case EM_D10V: return "d10v";
2440 case EM_CYGNUS_D30V:
2441 case EM_D30V: return "d30v";
2442 case EM_CYGNUS_V850:
2443 case EM_V850: return "Renesas V850";
2444 case EM_CYGNUS_M32R:
2445 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
2446 case EM_CYGNUS_MN10300:
2447 case EM_MN10300: return "mn10300";
2448 /* 90 */
2449 case EM_CYGNUS_MN10200:
2450 case EM_MN10200: return "mn10200";
2451 case EM_PJ: return "picoJava";
73589c9d 2452 case EM_OR1K: return "OpenRISC 1000";
55e22ca8 2453 case EM_ARC_COMPACT: return "ARCompact";
88da6820
NC
2454 case EM_XTENSA_OLD:
2455 case EM_XTENSA: return "Tensilica Xtensa Processor";
11636f9e
JM
2456 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
2457 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
2458 case EM_NS32K: return "National Semiconductor 32000 series";
2459 case EM_TPC: return "Tenor Network TPC processor";
55e22ca8
NC
2460 case EM_SNP1K: return "Trebia SNP 1000 processor";
2461 /* 100 */
9abca702 2462 case EM_ST200: return "STMicroelectronics ST200 microcontroller";
55e22ca8
NC
2463 case EM_IP2K_OLD:
2464 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
11636f9e
JM
2465 case EM_MAX: return "MAX Processor";
2466 case EM_CR: return "National Semiconductor CompactRISC";
2467 case EM_F2MC16: return "Fujitsu F2MC16";
2468 case EM_MSP430: return "Texas Instruments msp430 microcontroller";
7bbe5bc5 2469 case EM_BLACKFIN: return "Analog Devices Blackfin";
11636f9e
JM
2470 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
2471 case EM_SEP: return "Sharp embedded microprocessor";
2472 case EM_ARCA: return "Arca RISC microprocessor";
55e22ca8 2473 /* 110 */
11636f9e
JM
2474 case EM_UNICORE: return "Unicore";
2475 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
2476 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
64fd6348 2477 case EM_ALTERA_NIOS2: return "Altera Nios II";
55e22ca8
NC
2478 case EM_CRX: return "National Semiconductor CRX microprocessor";
2479 case EM_XGATE: return "Motorola XGATE embedded processor";
c29aca4a 2480 case EM_C166:
d70c5fc7 2481 case EM_XC16X: return "Infineon Technologies xc16x";
11636f9e
JM
2482 case EM_M16C: return "Renesas M16C series microprocessors";
2483 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
2484 case EM_CE: return "Freescale Communication Engine RISC core";
55e22ca8
NC
2485 /* 120 */
2486 case EM_M32C: return "Renesas M32c";
2487 /* 130 */
11636f9e
JM
2488 case EM_TSK3000: return "Altium TSK3000 core";
2489 case EM_RS08: return "Freescale RS08 embedded processor";
2490 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
55e22ca8 2491 case EM_SCORE: return "SUNPLUS S+Core";
11636f9e
JM
2492 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
2493 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
55e22ca8 2494 case EM_LATTICEMICO32: return "Lattice Mico32";
11636f9e 2495 case EM_SE_C17: return "Seiko Epson C17 family";
55e22ca8 2496 /* 140 */
11636f9e
JM
2497 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
2498 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
2499 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
55e22ca8
NC
2500 case EM_TI_PRU: return "TI PRU I/O processor";
2501 /* 160 */
11636f9e
JM
2502 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2503 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
2504 case EM_R32C: return "Renesas R32C series microprocessors";
2505 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
2506 case EM_QDSP6: return "QUALCOMM DSP6 Processor";
2507 case EM_8051: return "Intel 8051 and variants";
2508 case EM_STXP7X: return "STMicroelectronics STxP7x family";
2509 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
2510 case EM_ECOG1X: return "Cyan Technology eCOG1X family";
2511 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
55e22ca8 2512 /* 170 */
11636f9e
JM
2513 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
2514 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
2515 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
c7927a3c 2516 case EM_RX: return "Renesas RX";
a3c62988 2517 case EM_METAG: return "Imagination Technologies Meta processor architecture";
11636f9e
JM
2518 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
2519 case EM_ECOG16: return "Cyan Technology eCOG16 family";
55e22ca8
NC
2520 case EM_CR16:
2521 case EM_MICROBLAZE:
2522 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
11636f9e
JM
2523 case EM_ETPU: return "Freescale Extended Time Processing Unit";
2524 case EM_SLE9X: return "Infineon Technologies SLE9X core";
55e22ca8
NC
2525 /* 180 */
2526 case EM_L1OM: return "Intel L1OM";
2527 case EM_K1OM: return "Intel K1OM";
2528 case EM_INTEL182: return "Intel (reserved)";
2529 case EM_AARCH64: return "AArch64";
2530 case EM_ARM184: return "ARM (reserved)";
2531 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor";
11636f9e
JM
2532 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
2533 case EM_TILE64: return "Tilera TILE64 multicore architecture family";
2534 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
55e22ca8 2535 /* 190 */
11636f9e 2536 case EM_CUDA: return "NVIDIA CUDA architecture";
55e22ca8 2537 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
6d913794
NC
2538 case EM_CLOUDSHIELD: return "CloudShield architecture family";
2539 case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family";
2540 case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family";
55e22ca8 2541 case EM_ARC_COMPACT2: return "ARCv2";
6d913794 2542 case EM_OPEN8: return "Open8 8-bit RISC soft processor core";
55e22ca8 2543 case EM_RL78: return "Renesas RL78";
6d913794 2544 case EM_VIDEOCORE5: return "Broadcom VideoCore V processor";
55e22ca8
NC
2545 case EM_78K0R: return "Renesas 78K0R";
2546 /* 200 */
6d913794 2547 case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)";
15f205b1
NC
2548 case EM_BA1: return "Beyond BA1 CPU architecture";
2549 case EM_BA2: return "Beyond BA2 CPU architecture";
6d913794
NC
2550 case EM_XCORE: return "XMOS xCORE processor family";
2551 case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family";
7b9f9859 2552 case EM_INTELGT: return "Intel Graphics Technology";
55e22ca8 2553 /* 210 */
6d913794
NC
2554 case EM_KM32: return "KM211 KM32 32-bit processor";
2555 case EM_KMX32: return "KM211 KMX32 32-bit processor";
2556 case EM_KMX16: return "KM211 KMX16 16-bit processor";
2557 case EM_KMX8: return "KM211 KMX8 8-bit processor";
2558 case EM_KVARC: return "KM211 KVARC processor";
15f205b1 2559 case EM_CDP: return "Paneve CDP architecture family";
6d913794
NC
2560 case EM_COGE: return "Cognitive Smart Memory Processor";
2561 case EM_COOL: return "Bluechip Systems CoolEngine";
2562 case EM_NORC: return "Nanoradio Optimized RISC";
2563 case EM_CSR_KALIMBA: return "CSR Kalimba architecture family";
55e22ca8 2564 /* 220 */
15f205b1 2565 case EM_Z80: return "Zilog Z80";
55e22ca8
NC
2566 case EM_VISIUM: return "CDS VISIUMcore processor";
2567 case EM_FT32: return "FTDI Chip FT32";
2568 case EM_MOXIE: return "Moxie";
2569 case EM_AMDGPU: return "AMD GPU";
4cf2ad72
CC
2570 /* 230 (all reserved) */
2571 /* 240 */
55e22ca8
NC
2572 case EM_RISCV: return "RISC-V";
2573 case EM_LANAI: return "Lanai 32-bit processor";
4cf2ad72
CC
2574 case EM_CEVA: return "CEVA Processor Architecture Family";
2575 case EM_CEVA_X2: return "CEVA X2 Processor Family";
55e22ca8 2576 case EM_BPF: return "Linux BPF";
4cf2ad72
CC
2577 case EM_GRAPHCORE_IPU: return "Graphcore Intelligent Processing Unit";
2578 case EM_IMG1: return "Imagination Technologies";
2579 /* 250 */
fe944acf 2580 case EM_NFP: return "Netronome Flow Processor";
4cf2ad72
CC
2581 case EM_VE: return "NEC Vector Engine";
2582 case EM_CSKY: return "C-SKY";
2583 case EM_ARC_COMPACT3_64: return "Synopsys ARCv2.3 64-bit";
2584 case EM_MCS6502: return "MOS Technology MCS 6502 processor";
2585 case EM_ARC_COMPACT3: return "Synopsys ARCv2.3 32-bit";
2586 case EM_KVX: return "Kalray VLIW core of the MPPA processor family";
2587 case EM_65816: return "WDC 65816/65C816";
2588 case EM_LOONGARCH: return "Loongson Loongarch";
2589 case EM_KF32: return "ChipON KungFu32";
55e22ca8
NC
2590
2591 /* Large numbers... */
2592 case EM_MT: return "Morpho Techologies MT processor";
2593 case EM_ALPHA: return "Alpha";
2594 case EM_WEBASSEMBLY: return "Web Assembly";
9abca702 2595 case EM_DLX: return "OpenDLX";
55e22ca8
NC
2596 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
2597 case EM_IQ2000: return "Vitesse IQ2000";
2598 case EM_M32C_OLD:
2599 case EM_NIOS32: return "Altera Nios";
2600 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
2601 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
2602 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
637b1970 2603 case EM_S12Z: return "Freescale S12Z";
55e22ca8 2604
252b5132 2605 default:
35d9dd2f 2606 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
252b5132
RH
2607 return buff;
2608 }
2609}
2610
a9522a21
AB
2611static void
2612decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
2613{
2614 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
6987d5a1 2615 other compilers don't specify an architecture type in the e_flags, and
a9522a21
AB
2616 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2617 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2618 architectures.
2619
2620 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2621 but also sets a specific architecture type in the e_flags field.
2622
2623 However, when decoding the flags we don't worry if we see an
2624 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2625 ARCEM architecture type. */
2626
2627 switch (e_flags & EF_ARC_MACH_MSK)
2628 {
2629 /* We only expect these to occur for EM_ARC_COMPACT2. */
2630 case EF_ARC_CPU_ARCV2EM:
2631 strcat (buf, ", ARC EM");
2632 break;
2633 case EF_ARC_CPU_ARCV2HS:
2634 strcat (buf, ", ARC HS");
2635 break;
2636
2637 /* We only expect these to occur for EM_ARC_COMPACT. */
2638 case E_ARC_MACH_ARC600:
2639 strcat (buf, ", ARC600");
2640 break;
2641 case E_ARC_MACH_ARC601:
2642 strcat (buf, ", ARC601");
2643 break;
2644 case E_ARC_MACH_ARC700:
2645 strcat (buf, ", ARC700");
2646 break;
2647
2648 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2649 new ELF with new architecture being read by an old version of
2650 readelf, or (c) An ELF built with non-GNU compiler that does not
2651 set the architecture in the e_flags. */
2652 default:
2653 if (e_machine == EM_ARC_COMPACT)
2654 strcat (buf, ", Unknown ARCompact");
2655 else
2656 strcat (buf, ", Unknown ARC");
2657 break;
2658 }
2659
2660 switch (e_flags & EF_ARC_OSABI_MSK)
2661 {
2662 case E_ARC_OSABI_ORIG:
2663 strcat (buf, ", (ABI:legacy)");
2664 break;
2665 case E_ARC_OSABI_V2:
2666 strcat (buf, ", (ABI:v2)");
2667 break;
2668 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2669 case E_ARC_OSABI_V3:
2670 strcat (buf, ", v3 no-legacy-syscalls ABI");
2671 break;
53a346d8
CZ
2672 case E_ARC_OSABI_V4:
2673 strcat (buf, ", v4 ABI");
2674 break;
a9522a21
AB
2675 default:
2676 strcat (buf, ", unrecognised ARC OSABI flag");
2677 break;
2678 }
2679}
2680
f3485b74 2681static void
d3ba0551 2682decode_ARM_machine_flags (unsigned e_flags, char buf[])
f3485b74
NC
2683{
2684 unsigned eabi;
32ec8896 2685 bfd_boolean unknown = FALSE;
f3485b74
NC
2686
2687 eabi = EF_ARM_EABI_VERSION (e_flags);
2688 e_flags &= ~ EF_ARM_EABIMASK;
2689
2690 /* Handle "generic" ARM flags. */
2691 if (e_flags & EF_ARM_RELEXEC)
2692 {
2693 strcat (buf, ", relocatable executable");
2694 e_flags &= ~ EF_ARM_RELEXEC;
2695 }
76da6bbe 2696
18a20338
CL
2697 if (e_flags & EF_ARM_PIC)
2698 {
2699 strcat (buf, ", position independent");
2700 e_flags &= ~ EF_ARM_PIC;
2701 }
2702
f3485b74
NC
2703 /* Now handle EABI specific flags. */
2704 switch (eabi)
2705 {
2706 default:
2c71103e 2707 strcat (buf, ", <unrecognized EABI>");
f3485b74 2708 if (e_flags)
32ec8896 2709 unknown = TRUE;
f3485b74
NC
2710 break;
2711
2712 case EF_ARM_EABI_VER1:
a5bcd848 2713 strcat (buf, ", Version1 EABI");
f3485b74
NC
2714 while (e_flags)
2715 {
2716 unsigned flag;
76da6bbe 2717
f3485b74
NC
2718 /* Process flags one bit at a time. */
2719 flag = e_flags & - e_flags;
2720 e_flags &= ~ flag;
76da6bbe 2721
f3485b74
NC
2722 switch (flag)
2723 {
a5bcd848 2724 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
f3485b74
NC
2725 strcat (buf, ", sorted symbol tables");
2726 break;
76da6bbe 2727
f3485b74 2728 default:
32ec8896 2729 unknown = TRUE;
f3485b74
NC
2730 break;
2731 }
2732 }
2733 break;
76da6bbe 2734
a5bcd848
PB
2735 case EF_ARM_EABI_VER2:
2736 strcat (buf, ", Version2 EABI");
2737 while (e_flags)
2738 {
2739 unsigned flag;
2740
2741 /* Process flags one bit at a time. */
2742 flag = e_flags & - e_flags;
2743 e_flags &= ~ flag;
2744
2745 switch (flag)
2746 {
2747 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2748 strcat (buf, ", sorted symbol tables");
2749 break;
2750
2751 case EF_ARM_DYNSYMSUSESEGIDX:
2752 strcat (buf, ", dynamic symbols use segment index");
2753 break;
2754
2755 case EF_ARM_MAPSYMSFIRST:
2756 strcat (buf, ", mapping symbols precede others");
2757 break;
2758
2759 default:
32ec8896 2760 unknown = TRUE;
a5bcd848
PB
2761 break;
2762 }
2763 }
2764 break;
2765
d507cf36
PB
2766 case EF_ARM_EABI_VER3:
2767 strcat (buf, ", Version3 EABI");
8cb51566
PB
2768 break;
2769
2770 case EF_ARM_EABI_VER4:
2771 strcat (buf, ", Version4 EABI");
3bfcb652
NC
2772 while (e_flags)
2773 {
2774 unsigned flag;
2775
2776 /* Process flags one bit at a time. */
2777 flag = e_flags & - e_flags;
2778 e_flags &= ~ flag;
2779
2780 switch (flag)
2781 {
2782 case EF_ARM_BE8:
2783 strcat (buf, ", BE8");
2784 break;
2785
2786 case EF_ARM_LE8:
2787 strcat (buf, ", LE8");
2788 break;
2789
2790 default:
32ec8896 2791 unknown = TRUE;
3bfcb652
NC
2792 break;
2793 }
3bfcb652
NC
2794 }
2795 break;
3a4a14e9
PB
2796
2797 case EF_ARM_EABI_VER5:
2798 strcat (buf, ", Version5 EABI");
d507cf36
PB
2799 while (e_flags)
2800 {
2801 unsigned flag;
2802
2803 /* Process flags one bit at a time. */
2804 flag = e_flags & - e_flags;
2805 e_flags &= ~ flag;
2806
2807 switch (flag)
2808 {
2809 case EF_ARM_BE8:
2810 strcat (buf, ", BE8");
2811 break;
2812
2813 case EF_ARM_LE8:
2814 strcat (buf, ", LE8");
2815 break;
2816
3bfcb652
NC
2817 case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2818 strcat (buf, ", soft-float ABI");
2819 break;
2820
2821 case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
2822 strcat (buf, ", hard-float ABI");
2823 break;
2824
d507cf36 2825 default:
32ec8896 2826 unknown = TRUE;
d507cf36
PB
2827 break;
2828 }
2829 }
2830 break;
2831
f3485b74 2832 case EF_ARM_EABI_UNKNOWN:
a5bcd848 2833 strcat (buf, ", GNU EABI");
f3485b74
NC
2834 while (e_flags)
2835 {
2836 unsigned flag;
76da6bbe 2837
f3485b74
NC
2838 /* Process flags one bit at a time. */
2839 flag = e_flags & - e_flags;
2840 e_flags &= ~ flag;
76da6bbe 2841
f3485b74
NC
2842 switch (flag)
2843 {
a5bcd848 2844 case EF_ARM_INTERWORK:
f3485b74
NC
2845 strcat (buf, ", interworking enabled");
2846 break;
76da6bbe 2847
a5bcd848 2848 case EF_ARM_APCS_26:
f3485b74
NC
2849 strcat (buf, ", uses APCS/26");
2850 break;
76da6bbe 2851
a5bcd848 2852 case EF_ARM_APCS_FLOAT:
f3485b74
NC
2853 strcat (buf, ", uses APCS/float");
2854 break;
76da6bbe 2855
a5bcd848 2856 case EF_ARM_PIC:
f3485b74
NC
2857 strcat (buf, ", position independent");
2858 break;
76da6bbe 2859
a5bcd848 2860 case EF_ARM_ALIGN8:
f3485b74
NC
2861 strcat (buf, ", 8 bit structure alignment");
2862 break;
76da6bbe 2863
a5bcd848 2864 case EF_ARM_NEW_ABI:
f3485b74
NC
2865 strcat (buf, ", uses new ABI");
2866 break;
76da6bbe 2867
a5bcd848 2868 case EF_ARM_OLD_ABI:
f3485b74
NC
2869 strcat (buf, ", uses old ABI");
2870 break;
76da6bbe 2871
a5bcd848 2872 case EF_ARM_SOFT_FLOAT:
f3485b74
NC
2873 strcat (buf, ", software FP");
2874 break;
76da6bbe 2875
90e01f86
ILT
2876 case EF_ARM_VFP_FLOAT:
2877 strcat (buf, ", VFP");
2878 break;
2879
fde78edd
NC
2880 case EF_ARM_MAVERICK_FLOAT:
2881 strcat (buf, ", Maverick FP");
2882 break;
2883
f3485b74 2884 default:
32ec8896 2885 unknown = TRUE;
f3485b74
NC
2886 break;
2887 }
2888 }
2889 }
f3485b74
NC
2890
2891 if (unknown)
2b692964 2892 strcat (buf,_(", <unknown>"));
f3485b74
NC
2893}
2894
343433df
AB
2895static void
2896decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
2897{
2898 --size; /* Leave space for null terminator. */
2899
2900 switch (e_flags & EF_AVR_MACH)
2901 {
2902 case E_AVR_MACH_AVR1:
2903 strncat (buf, ", avr:1", size);
2904 break;
2905 case E_AVR_MACH_AVR2:
2906 strncat (buf, ", avr:2", size);
2907 break;
2908 case E_AVR_MACH_AVR25:
2909 strncat (buf, ", avr:25", size);
2910 break;
2911 case E_AVR_MACH_AVR3:
2912 strncat (buf, ", avr:3", size);
2913 break;
2914 case E_AVR_MACH_AVR31:
2915 strncat (buf, ", avr:31", size);
2916 break;
2917 case E_AVR_MACH_AVR35:
2918 strncat (buf, ", avr:35", size);
2919 break;
2920 case E_AVR_MACH_AVR4:
2921 strncat (buf, ", avr:4", size);
2922 break;
2923 case E_AVR_MACH_AVR5:
2924 strncat (buf, ", avr:5", size);
2925 break;
2926 case E_AVR_MACH_AVR51:
2927 strncat (buf, ", avr:51", size);
2928 break;
2929 case E_AVR_MACH_AVR6:
2930 strncat (buf, ", avr:6", size);
2931 break;
2932 case E_AVR_MACH_AVRTINY:
2933 strncat (buf, ", avr:100", size);
2934 break;
2935 case E_AVR_MACH_XMEGA1:
2936 strncat (buf, ", avr:101", size);
2937 break;
2938 case E_AVR_MACH_XMEGA2:
2939 strncat (buf, ", avr:102", size);
2940 break;
2941 case E_AVR_MACH_XMEGA3:
2942 strncat (buf, ", avr:103", size);
2943 break;
2944 case E_AVR_MACH_XMEGA4:
2945 strncat (buf, ", avr:104", size);
2946 break;
2947 case E_AVR_MACH_XMEGA5:
2948 strncat (buf, ", avr:105", size);
2949 break;
2950 case E_AVR_MACH_XMEGA6:
2951 strncat (buf, ", avr:106", size);
2952 break;
2953 case E_AVR_MACH_XMEGA7:
2954 strncat (buf, ", avr:107", size);
2955 break;
2956 default:
2957 strncat (buf, ", avr:<unknown>", size);
2958 break;
2959 }
2960
2961 size -= strlen (buf);
2962 if (e_flags & EF_AVR_LINKRELAX_PREPARED)
2963 strncat (buf, ", link-relax", size);
2964}
2965
35c08157
KLC
2966static void
2967decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
2968{
2969 unsigned abi;
2970 unsigned arch;
2971 unsigned config;
2972 unsigned version;
32ec8896
NC
2973 bfd_boolean has_fpu = FALSE;
2974 unsigned int r = 0;
35c08157
KLC
2975
2976 static const char *ABI_STRINGS[] =
2977 {
2978 "ABI v0", /* use r5 as return register; only used in N1213HC */
2979 "ABI v1", /* use r0 as return register */
2980 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2981 "ABI v2fp", /* for FPU */
40c7a7cb
KLC
2982 "AABI",
2983 "ABI2 FP+"
35c08157
KLC
2984 };
2985 static const char *VER_STRINGS[] =
2986 {
2987 "Andes ELF V1.3 or older",
2988 "Andes ELF V1.3.1",
2989 "Andes ELF V1.4"
2990 };
2991 static const char *ARCH_STRINGS[] =
2992 {
2993 "",
2994 "Andes Star v1.0",
2995 "Andes Star v2.0",
2996 "Andes Star v3.0",
2997 "Andes Star v3.0m"
2998 };
2999
3000 abi = EF_NDS_ABI & e_flags;
3001 arch = EF_NDS_ARCH & e_flags;
3002 config = EF_NDS_INST & e_flags;
3003 version = EF_NDS32_ELF_VERSION & e_flags;
3004
3005 memset (buf, 0, size);
3006
3007 switch (abi)
3008 {
3009 case E_NDS_ABI_V0:
3010 case E_NDS_ABI_V1:
3011 case E_NDS_ABI_V2:
3012 case E_NDS_ABI_V2FP:
3013 case E_NDS_ABI_AABI:
40c7a7cb 3014 case E_NDS_ABI_V2FP_PLUS:
35c08157
KLC
3015 /* In case there are holes in the array. */
3016 r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
3017 break;
3018
3019 default:
3020 r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
3021 break;
3022 }
3023
3024 switch (version)
3025 {
3026 case E_NDS32_ELF_VER_1_2:
3027 case E_NDS32_ELF_VER_1_3:
3028 case E_NDS32_ELF_VER_1_4:
3029 r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
3030 break;
3031
3032 default:
3033 r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
3034 break;
3035 }
3036
3037 if (E_NDS_ABI_V0 == abi)
3038 {
3039 /* OLD ABI; only used in N1213HC, has performance extension 1. */
3040 r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
3041 if (arch == E_NDS_ARCH_STAR_V1_0)
3042 r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
3043 return;
3044 }
3045
3046 switch (arch)
3047 {
3048 case E_NDS_ARCH_STAR_V1_0:
3049 case E_NDS_ARCH_STAR_V2_0:
3050 case E_NDS_ARCH_STAR_V3_0:
3051 case E_NDS_ARCH_STAR_V3_M:
3052 r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
3053 break;
3054
3055 default:
3056 r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
3057 /* ARCH version determines how the e_flags are interpreted.
3058 If it is unknown, we cannot proceed. */
3059 return;
3060 }
3061
3062 /* Newer ABI; Now handle architecture specific flags. */
3063 if (arch == E_NDS_ARCH_STAR_V1_0)
3064 {
3065 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3066 r += snprintf (buf + r, size -r, ", MFUSR_PC");
3067
3068 if (!(config & E_NDS32_HAS_NO_MAC_INST))
3069 r += snprintf (buf + r, size -r, ", MAC");
3070
3071 if (config & E_NDS32_HAS_DIV_INST)
3072 r += snprintf (buf + r, size -r, ", DIV");
3073
3074 if (config & E_NDS32_HAS_16BIT_INST)
3075 r += snprintf (buf + r, size -r, ", 16b");
3076 }
3077 else
3078 {
3079 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3080 {
3081 if (version <= E_NDS32_ELF_VER_1_3)
3082 r += snprintf (buf + r, size -r, ", [B8]");
3083 else
3084 r += snprintf (buf + r, size -r, ", EX9");
3085 }
3086
3087 if (config & E_NDS32_HAS_MAC_DX_INST)
3088 r += snprintf (buf + r, size -r, ", MAC_DX");
3089
3090 if (config & E_NDS32_HAS_DIV_DX_INST)
3091 r += snprintf (buf + r, size -r, ", DIV_DX");
3092
3093 if (config & E_NDS32_HAS_16BIT_INST)
3094 {
3095 if (version <= E_NDS32_ELF_VER_1_3)
3096 r += snprintf (buf + r, size -r, ", 16b");
3097 else
3098 r += snprintf (buf + r, size -r, ", IFC");
3099 }
3100 }
3101
3102 if (config & E_NDS32_HAS_EXT_INST)
3103 r += snprintf (buf + r, size -r, ", PERF1");
3104
3105 if (config & E_NDS32_HAS_EXT2_INST)
3106 r += snprintf (buf + r, size -r, ", PERF2");
3107
3108 if (config & E_NDS32_HAS_FPU_INST)
3109 {
32ec8896 3110 has_fpu = TRUE;
35c08157
KLC
3111 r += snprintf (buf + r, size -r, ", FPU_SP");
3112 }
3113
3114 if (config & E_NDS32_HAS_FPU_DP_INST)
3115 {
32ec8896 3116 has_fpu = TRUE;
35c08157
KLC
3117 r += snprintf (buf + r, size -r, ", FPU_DP");
3118 }
3119
3120 if (config & E_NDS32_HAS_FPU_MAC_INST)
3121 {
32ec8896 3122 has_fpu = TRUE;
35c08157
KLC
3123 r += snprintf (buf + r, size -r, ", FPU_MAC");
3124 }
3125
3126 if (has_fpu)
3127 {
3128 switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
3129 {
3130 case E_NDS32_FPU_REG_8SP_4DP:
3131 r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
3132 break;
3133 case E_NDS32_FPU_REG_16SP_8DP:
3134 r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
3135 break;
3136 case E_NDS32_FPU_REG_32SP_16DP:
3137 r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
3138 break;
3139 case E_NDS32_FPU_REG_32SP_32DP:
3140 r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
3141 break;
3142 }
3143 }
3144
3145 if (config & E_NDS32_HAS_AUDIO_INST)
3146 r += snprintf (buf + r, size -r, ", AUDIO");
3147
3148 if (config & E_NDS32_HAS_STRING_INST)
3149 r += snprintf (buf + r, size -r, ", STR");
3150
3151 if (config & E_NDS32_HAS_REDUCED_REGS)
3152 r += snprintf (buf + r, size -r, ", 16REG");
3153
3154 if (config & E_NDS32_HAS_VIDEO_INST)
3155 {
3156 if (version <= E_NDS32_ELF_VER_1_3)
3157 r += snprintf (buf + r, size -r, ", VIDEO");
3158 else
3159 r += snprintf (buf + r, size -r, ", SATURATION");
3160 }
3161
3162 if (config & E_NDS32_HAS_ENCRIPT_INST)
3163 r += snprintf (buf + r, size -r, ", ENCRP");
3164
3165 if (config & E_NDS32_HAS_L2C_INST)
3166 r += snprintf (buf + r, size -r, ", L2C");
3167}
3168
252b5132 3169static char *
dda8d76d 3170get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
252b5132 3171{
b34976b6 3172 static char buf[1024];
252b5132
RH
3173
3174 buf[0] = '\0';
76da6bbe 3175
252b5132
RH
3176 if (e_flags)
3177 {
3178 switch (e_machine)
3179 {
3180 default:
3181 break;
3182
886a2506 3183 case EM_ARC_COMPACT2:
886a2506 3184 case EM_ARC_COMPACT:
a9522a21
AB
3185 decode_ARC_machine_flags (e_flags, e_machine, buf);
3186 break;
886a2506 3187
f3485b74
NC
3188 case EM_ARM:
3189 decode_ARM_machine_flags (e_flags, buf);
3190 break;
76da6bbe 3191
343433df
AB
3192 case EM_AVR:
3193 decode_AVR_machine_flags (e_flags, buf, sizeof buf);
3194 break;
3195
781303ce
MF
3196 case EM_BLACKFIN:
3197 if (e_flags & EF_BFIN_PIC)
3198 strcat (buf, ", PIC");
3199
3200 if (e_flags & EF_BFIN_FDPIC)
3201 strcat (buf, ", FDPIC");
3202
3203 if (e_flags & EF_BFIN_CODE_IN_L1)
3204 strcat (buf, ", code in L1");
3205
3206 if (e_flags & EF_BFIN_DATA_IN_L1)
3207 strcat (buf, ", data in L1");
3208
3209 break;
3210
ec2dfb42
AO
3211 case EM_CYGNUS_FRV:
3212 switch (e_flags & EF_FRV_CPU_MASK)
3213 {
3214 case EF_FRV_CPU_GENERIC:
3215 break;
3216
3217 default:
3218 strcat (buf, ", fr???");
3219 break;
57346661 3220
ec2dfb42
AO
3221 case EF_FRV_CPU_FR300:
3222 strcat (buf, ", fr300");
3223 break;
3224
3225 case EF_FRV_CPU_FR400:
3226 strcat (buf, ", fr400");
3227 break;
3228 case EF_FRV_CPU_FR405:
3229 strcat (buf, ", fr405");
3230 break;
3231
3232 case EF_FRV_CPU_FR450:
3233 strcat (buf, ", fr450");
3234 break;
3235
3236 case EF_FRV_CPU_FR500:
3237 strcat (buf, ", fr500");
3238 break;
3239 case EF_FRV_CPU_FR550:
3240 strcat (buf, ", fr550");
3241 break;
3242
3243 case EF_FRV_CPU_SIMPLE:
3244 strcat (buf, ", simple");
3245 break;
3246 case EF_FRV_CPU_TOMCAT:
3247 strcat (buf, ", tomcat");
3248 break;
3249 }
1c877e87 3250 break;
ec2dfb42 3251
53c7db4b 3252 case EM_68K:
425c6cb0 3253 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
76f57f3a 3254 strcat (buf, ", m68000");
425c6cb0 3255 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
3bdcfdf4
KH
3256 strcat (buf, ", cpu32");
3257 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
3258 strcat (buf, ", fido_a");
425c6cb0 3259 else
266abb8f 3260 {
2cf0635d
NC
3261 char const * isa = _("unknown");
3262 char const * mac = _("unknown mac");
3263 char const * additional = NULL;
0112cd26 3264
c694fd50 3265 switch (e_flags & EF_M68K_CF_ISA_MASK)
266abb8f 3266 {
c694fd50 3267 case EF_M68K_CF_ISA_A_NODIV:
0b2e31dc
NS
3268 isa = "A";
3269 additional = ", nodiv";
3270 break;
c694fd50 3271 case EF_M68K_CF_ISA_A:
266abb8f
NS
3272 isa = "A";
3273 break;
c694fd50 3274 case EF_M68K_CF_ISA_A_PLUS:
266abb8f
NS
3275 isa = "A+";
3276 break;
c694fd50 3277 case EF_M68K_CF_ISA_B_NOUSP:
0b2e31dc
NS
3278 isa = "B";
3279 additional = ", nousp";
3280 break;
c694fd50 3281 case EF_M68K_CF_ISA_B:
266abb8f
NS
3282 isa = "B";
3283 break;
f608cd77
NS
3284 case EF_M68K_CF_ISA_C:
3285 isa = "C";
3286 break;
3287 case EF_M68K_CF_ISA_C_NODIV:
3288 isa = "C";
3289 additional = ", nodiv";
3290 break;
266abb8f
NS
3291 }
3292 strcat (buf, ", cf, isa ");
3293 strcat (buf, isa);
0b2e31dc
NS
3294 if (additional)
3295 strcat (buf, additional);
c694fd50 3296 if (e_flags & EF_M68K_CF_FLOAT)
0b2e31dc 3297 strcat (buf, ", float");
c694fd50 3298 switch (e_flags & EF_M68K_CF_MAC_MASK)
266abb8f
NS
3299 {
3300 case 0:
3301 mac = NULL;
3302 break;
c694fd50 3303 case EF_M68K_CF_MAC:
266abb8f
NS
3304 mac = "mac";
3305 break;
c694fd50 3306 case EF_M68K_CF_EMAC:
266abb8f
NS
3307 mac = "emac";
3308 break;
f608cd77
NS
3309 case EF_M68K_CF_EMAC_B:
3310 mac = "emac_b";
3311 break;
266abb8f
NS
3312 }
3313 if (mac)
3314 {
3315 strcat (buf, ", ");
3316 strcat (buf, mac);
3317 }
266abb8f 3318 }
53c7db4b 3319 break;
33c63f9d 3320
153a2776
NC
3321 case EM_CYGNUS_MEP:
3322 switch (e_flags & EF_MEP_CPU_MASK)
3323 {
3324 case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
3325 case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
3326 case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
3327 case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
3328 case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
3329 case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
3330 default: strcat (buf, _(", <unknown MeP cpu type>")); break;
3331 }
3332
3333 switch (e_flags & EF_MEP_COP_MASK)
3334 {
3335 case EF_MEP_COP_NONE: break;
3336 case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
3337 case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
3338 case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
3339 case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
3340 default: strcat (buf, _("<unknown MeP copro type>")); break;
3341 }
3342
3343 if (e_flags & EF_MEP_LIBRARY)
3344 strcat (buf, ", Built for Library");
3345
3346 if (e_flags & EF_MEP_INDEX_MASK)
3347 sprintf (buf + strlen (buf), ", Configuration Index: %#x",
3348 e_flags & EF_MEP_INDEX_MASK);
3349
3350 if (e_flags & ~ EF_MEP_ALL_FLAGS)
3351 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
3352 e_flags & ~ EF_MEP_ALL_FLAGS);
3353 break;
3354
252b5132
RH
3355 case EM_PPC:
3356 if (e_flags & EF_PPC_EMB)
3357 strcat (buf, ", emb");
3358
3359 if (e_flags & EF_PPC_RELOCATABLE)
2b692964 3360 strcat (buf, _(", relocatable"));
252b5132
RH
3361
3362 if (e_flags & EF_PPC_RELOCATABLE_LIB)
2b692964 3363 strcat (buf, _(", relocatable-lib"));
252b5132
RH
3364 break;
3365
ee67d69a
AM
3366 case EM_PPC64:
3367 if (e_flags & EF_PPC64_ABI)
3368 {
3369 char abi[] = ", abiv0";
3370
3371 abi[6] += e_flags & EF_PPC64_ABI;
3372 strcat (buf, abi);
3373 }
3374 break;
3375
708e2187
NC
3376 case EM_V800:
3377 if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
3378 strcat (buf, ", RH850 ABI");
0b4362b0 3379
708e2187
NC
3380 if (e_flags & EF_V800_850E3)
3381 strcat (buf, ", V3 architecture");
3382
3383 if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
3384 strcat (buf, ", FPU not used");
3385
3386 if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
3387 strcat (buf, ", regmode: COMMON");
3388
3389 if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
3390 strcat (buf, ", r4 not used");
3391
3392 if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
3393 strcat (buf, ", r30 not used");
3394
3395 if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
3396 strcat (buf, ", r5 not used");
3397
3398 if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
3399 strcat (buf, ", r2 not used");
3400
3401 for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
3402 {
3403 switch (e_flags & - e_flags)
3404 {
3405 case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
3406 case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
708e2187
NC
3407 case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
3408 case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
708e2187
NC
3409 case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
3410 case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
3411 case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
3412 case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
3413 case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
3414 case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
3415 case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
3416 case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
3417 default: break;
3418 }
3419 }
3420 break;
3421
2b0337b0 3422 case EM_V850:
252b5132
RH
3423 case EM_CYGNUS_V850:
3424 switch (e_flags & EF_V850_ARCH)
3425 {
78c8d46c
NC
3426 case E_V850E3V5_ARCH:
3427 strcat (buf, ", v850e3v5");
3428 break;
1cd986c5
NC
3429 case E_V850E2V3_ARCH:
3430 strcat (buf, ", v850e2v3");
3431 break;
3432 case E_V850E2_ARCH:
3433 strcat (buf, ", v850e2");
3434 break;
3435 case E_V850E1_ARCH:
3436 strcat (buf, ", v850e1");
8ad30312 3437 break;
252b5132
RH
3438 case E_V850E_ARCH:
3439 strcat (buf, ", v850e");
3440 break;
252b5132
RH
3441 case E_V850_ARCH:
3442 strcat (buf, ", v850");
3443 break;
3444 default:
2b692964 3445 strcat (buf, _(", unknown v850 architecture variant"));
252b5132
RH
3446 break;
3447 }
3448 break;
3449
2b0337b0 3450 case EM_M32R:
252b5132
RH
3451 case EM_CYGNUS_M32R:
3452 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3453 strcat (buf, ", m32r");
252b5132
RH
3454 break;
3455
3456 case EM_MIPS:
4fe85591 3457 case EM_MIPS_RS3_LE:
252b5132
RH
3458 if (e_flags & EF_MIPS_NOREORDER)
3459 strcat (buf, ", noreorder");
3460
3461 if (e_flags & EF_MIPS_PIC)
3462 strcat (buf, ", pic");
3463
3464 if (e_flags & EF_MIPS_CPIC)
3465 strcat (buf, ", cpic");
3466
d1bdd336
TS
3467 if (e_flags & EF_MIPS_UCODE)
3468 strcat (buf, ", ugen_reserved");
3469
252b5132
RH
3470 if (e_flags & EF_MIPS_ABI2)
3471 strcat (buf, ", abi2");
3472
43521d43
TS
3473 if (e_flags & EF_MIPS_OPTIONS_FIRST)
3474 strcat (buf, ", odk first");
3475
a5d22d2a
TS
3476 if (e_flags & EF_MIPS_32BITMODE)
3477 strcat (buf, ", 32bitmode");
3478
ba92f887
MR
3479 if (e_flags & EF_MIPS_NAN2008)
3480 strcat (buf, ", nan2008");
3481
fef1b0b3
SE
3482 if (e_flags & EF_MIPS_FP64)
3483 strcat (buf, ", fp64");
3484
156c2f8b
NC
3485 switch ((e_flags & EF_MIPS_MACH))
3486 {
3487 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
3488 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
3489 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
156c2f8b 3490 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
810dfa6e
L
3491 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
3492 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
3493 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
3494 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
ef272caa 3495 case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break;
c6c98b38 3496 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
ebcb91b7 3497 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
350cc38d
MS
3498 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
3499 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
ac8cb70f 3500 case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break;
bd782c07 3501 case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break;
9108bc33 3502 case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break;
05c6f050 3503 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
67c2a3e8 3504 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
d32e5c54 3505 case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
52b6b6b9 3506 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
38bf472a 3507 case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break;
43521d43
TS
3508 case 0:
3509 /* We simply ignore the field in this case to avoid confusion:
3510 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3511 extension. */
3512 break;
2b692964 3513 default: strcat (buf, _(", unknown CPU")); break;
156c2f8b 3514 }
43521d43
TS
3515
3516 switch ((e_flags & EF_MIPS_ABI))
3517 {
3518 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
3519 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
3520 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
3521 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
3522 case 0:
3523 /* We simply ignore the field in this case to avoid confusion:
3524 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3525 This means it is likely to be an o32 file, but not for
3526 sure. */
3527 break;
2b692964 3528 default: strcat (buf, _(", unknown ABI")); break;
43521d43
TS
3529 }
3530
3531 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
3532 strcat (buf, ", mdmx");
3533
3534 if (e_flags & EF_MIPS_ARCH_ASE_M16)
3535 strcat (buf, ", mips16");
3536
df58fc94
RS
3537 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
3538 strcat (buf, ", micromips");
3539
43521d43
TS
3540 switch ((e_flags & EF_MIPS_ARCH))
3541 {
3542 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
3543 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
3544 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
3545 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
3546 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
3547 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
cb44e358 3548 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
7361da2c 3549 case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
43521d43 3550 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
5f74bc13 3551 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
7361da2c 3552 case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
2b692964 3553 default: strcat (buf, _(", unknown ISA")); break;
43521d43 3554 }
252b5132 3555 break;
351b4b40 3556
35c08157
KLC
3557 case EM_NDS32:
3558 decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
3559 break;
3560
fe944acf
FT
3561 case EM_NFP:
3562 switch (EF_NFP_MACH (e_flags))
3563 {
3564 case E_NFP_MACH_3200:
3565 strcat (buf, ", NFP-32xx");
3566 break;
3567 case E_NFP_MACH_6000:
3568 strcat (buf, ", NFP-6xxx");
3569 break;
3570 }
3571 break;
3572
e23eba97
NC
3573 case EM_RISCV:
3574 if (e_flags & EF_RISCV_RVC)
3575 strcat (buf, ", RVC");
2922d21d 3576
7f999549
JW
3577 if (e_flags & EF_RISCV_RVE)
3578 strcat (buf, ", RVE");
3579
2922d21d
AW
3580 switch (e_flags & EF_RISCV_FLOAT_ABI)
3581 {
3582 case EF_RISCV_FLOAT_ABI_SOFT:
3583 strcat (buf, ", soft-float ABI");
3584 break;
3585
3586 case EF_RISCV_FLOAT_ABI_SINGLE:
3587 strcat (buf, ", single-float ABI");
3588 break;
3589
3590 case EF_RISCV_FLOAT_ABI_DOUBLE:
3591 strcat (buf, ", double-float ABI");
3592 break;
3593
3594 case EF_RISCV_FLOAT_ABI_QUAD:
3595 strcat (buf, ", quad-float ABI");
3596 break;
3597 }
e23eba97
NC
3598 break;
3599
ccde1100
AO
3600 case EM_SH:
3601 switch ((e_flags & EF_SH_MACH_MASK))
3602 {
3603 case EF_SH1: strcat (buf, ", sh1"); break;
3604 case EF_SH2: strcat (buf, ", sh2"); break;
3605 case EF_SH3: strcat (buf, ", sh3"); break;
3606 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
3607 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
3608 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
3609 case EF_SH3E: strcat (buf, ", sh3e"); break;
3610 case EF_SH4: strcat (buf, ", sh4"); break;
3611 case EF_SH5: strcat (buf, ", sh5"); break;
3612 case EF_SH2E: strcat (buf, ", sh2e"); break;
3613 case EF_SH4A: strcat (buf, ", sh4a"); break;
1d70c7fb 3614 case EF_SH2A: strcat (buf, ", sh2a"); break;
ccde1100
AO
3615 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
3616 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
1d70c7fb 3617 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
0b92ab21
NH
3618 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
3619 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
3620 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3621 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
3622 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
3623 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
2b692964 3624 default: strcat (buf, _(", unknown ISA")); break;
ccde1100
AO
3625 }
3626
cec6a5b8
MR
3627 if (e_flags & EF_SH_PIC)
3628 strcat (buf, ", pic");
3629
3630 if (e_flags & EF_SH_FDPIC)
3631 strcat (buf, ", fdpic");
ccde1100 3632 break;
948f632f 3633
73589c9d
CS
3634 case EM_OR1K:
3635 if (e_flags & EF_OR1K_NODELAY)
3636 strcat (buf, ", no delay");
3637 break;
57346661 3638
351b4b40
RH
3639 case EM_SPARCV9:
3640 if (e_flags & EF_SPARC_32PLUS)
3641 strcat (buf, ", v8+");
3642
3643 if (e_flags & EF_SPARC_SUN_US1)
d07faca2
RH
3644 strcat (buf, ", ultrasparcI");
3645
3646 if (e_flags & EF_SPARC_SUN_US3)
3647 strcat (buf, ", ultrasparcIII");
351b4b40
RH
3648
3649 if (e_flags & EF_SPARC_HAL_R1)
3650 strcat (buf, ", halr1");
3651
3652 if (e_flags & EF_SPARC_LEDATA)
3653 strcat (buf, ", ledata");
3654
3655 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
3656 strcat (buf, ", tso");
3657
3658 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
3659 strcat (buf, ", pso");
3660
3661 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
3662 strcat (buf, ", rmo");
3663 break;
7d466069 3664
103f02d3
UD
3665 case EM_PARISC:
3666 switch (e_flags & EF_PARISC_ARCH)
3667 {
3668 case EFA_PARISC_1_0:
3669 strcpy (buf, ", PA-RISC 1.0");
3670 break;
3671 case EFA_PARISC_1_1:
3672 strcpy (buf, ", PA-RISC 1.1");
3673 break;
3674 case EFA_PARISC_2_0:
3675 strcpy (buf, ", PA-RISC 2.0");
3676 break;
3677 default:
3678 break;
3679 }
3680 if (e_flags & EF_PARISC_TRAPNIL)
3681 strcat (buf, ", trapnil");
3682 if (e_flags & EF_PARISC_EXT)
3683 strcat (buf, ", ext");
3684 if (e_flags & EF_PARISC_LSB)
3685 strcat (buf, ", lsb");
3686 if (e_flags & EF_PARISC_WIDE)
3687 strcat (buf, ", wide");
3688 if (e_flags & EF_PARISC_NO_KABP)
3689 strcat (buf, ", no kabp");
3690 if (e_flags & EF_PARISC_LAZYSWAP)
3691 strcat (buf, ", lazyswap");
30800947 3692 break;
76da6bbe 3693
7d466069 3694 case EM_PJ:
2b0337b0 3695 case EM_PJ_OLD:
7d466069
ILT
3696 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
3697 strcat (buf, ", new calling convention");
3698
3699 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
3700 strcat (buf, ", gnu calling convention");
3701 break;
4d6ed7c8
NC
3702
3703 case EM_IA_64:
3704 if ((e_flags & EF_IA_64_ABI64))
3705 strcat (buf, ", 64-bit");
3706 else
3707 strcat (buf, ", 32-bit");
3708 if ((e_flags & EF_IA_64_REDUCEDFP))
3709 strcat (buf, ", reduced fp model");
3710 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
3711 strcat (buf, ", no function descriptors, constant gp");
3712 else if ((e_flags & EF_IA_64_CONS_GP))
3713 strcat (buf, ", constant gp");
3714 if ((e_flags & EF_IA_64_ABSOLUTE))
3715 strcat (buf, ", absolute");
dda8d76d 3716 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
28f997cf
TG
3717 {
3718 if ((e_flags & EF_IA_64_VMS_LINKAGES))
3719 strcat (buf, ", vms_linkages");
3720 switch ((e_flags & EF_IA_64_VMS_COMCOD))
3721 {
3722 case EF_IA_64_VMS_COMCOD_SUCCESS:
3723 break;
3724 case EF_IA_64_VMS_COMCOD_WARNING:
3725 strcat (buf, ", warning");
3726 break;
3727 case EF_IA_64_VMS_COMCOD_ERROR:
3728 strcat (buf, ", error");
3729 break;
3730 case EF_IA_64_VMS_COMCOD_ABORT:
3731 strcat (buf, ", abort");
3732 break;
3733 default:
bee0ee85
NC
3734 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3735 e_flags & EF_IA_64_VMS_COMCOD);
3736 strcat (buf, ", <unknown>");
28f997cf
TG
3737 }
3738 }
4d6ed7c8 3739 break;
179d3252
JT
3740
3741 case EM_VAX:
3742 if ((e_flags & EF_VAX_NONPIC))
3743 strcat (buf, ", non-PIC");
3744 if ((e_flags & EF_VAX_DFLOAT))
3745 strcat (buf, ", D-Float");
3746 if ((e_flags & EF_VAX_GFLOAT))
3747 strcat (buf, ", G-Float");
3748 break;
c7927a3c 3749
619ed720
EB
3750 case EM_VISIUM:
3751 if (e_flags & EF_VISIUM_ARCH_MCM)
3752 strcat (buf, ", mcm");
3753 else if (e_flags & EF_VISIUM_ARCH_MCM24)
3754 strcat (buf, ", mcm24");
3755 if (e_flags & EF_VISIUM_ARCH_GR6)
3756 strcat (buf, ", gr6");
3757 break;
3758
4046d87a 3759 case EM_RL78:
1740ba0c
NC
3760 switch (e_flags & E_FLAG_RL78_CPU_MASK)
3761 {
3762 case E_FLAG_RL78_ANY_CPU: break;
3763 case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
3764 case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
3765 case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
3766 }
856ea05c
KP
3767 if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
3768 strcat (buf, ", 64-bit doubles");
4046d87a 3769 break;
0b4362b0 3770
c7927a3c
NC
3771 case EM_RX:
3772 if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
3773 strcat (buf, ", 64-bit doubles");
3774 if (e_flags & E_FLAG_RX_DSP)
dd24e3da 3775 strcat (buf, ", dsp");
d4cb0ea0 3776 if (e_flags & E_FLAG_RX_PID)
0b4362b0 3777 strcat (buf, ", pid");
708e2187
NC
3778 if (e_flags & E_FLAG_RX_ABI)
3779 strcat (buf, ", RX ABI");
3525236c
NC
3780 if (e_flags & E_FLAG_RX_SINSNS_SET)
3781 strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
3782 ? ", uses String instructions" : ", bans String instructions");
a117b0a5
YS
3783 if (e_flags & E_FLAG_RX_V2)
3784 strcat (buf, ", V2");
f87673e0
YS
3785 if (e_flags & E_FLAG_RX_V3)
3786 strcat (buf, ", V3");
d4cb0ea0 3787 break;
55786da2
AK
3788
3789 case EM_S390:
3790 if (e_flags & EF_S390_HIGH_GPRS)
3791 strcat (buf, ", highgprs");
d4cb0ea0 3792 break;
40b36596
JM
3793
3794 case EM_TI_C6000:
3795 if ((e_flags & EF_C6000_REL))
3796 strcat (buf, ", relocatable module");
d4cb0ea0 3797 break;
13761a11
NC
3798
3799 case EM_MSP430:
3800 strcat (buf, _(": architecture variant: "));
3801 switch (e_flags & EF_MSP430_MACH)
3802 {
3803 case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
3804 case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
3805 case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
3806 case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
3807 case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
3808 case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
3809 case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
3810 case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
3811 case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
3812 case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
3813 case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
3814 case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
3815 case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
3816 case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
3817 case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
3818 default:
3819 strcat (buf, _(": unknown")); break;
3820 }
3821
3822 if (e_flags & ~ EF_MSP430_MACH)
3823 strcat (buf, _(": unknown extra flag bits also present"));
6655dba2
SB
3824 break;
3825
3826 case EM_Z80:
3827 switch (e_flags & EF_Z80_MACH_MSK)
3828 {
3829 case EF_Z80_MACH_Z80: strcat (buf, ", Z80"); break;
3830 case EF_Z80_MACH_Z180: strcat (buf, ", Z180"); break;
3831 case EF_Z80_MACH_R800: strcat (buf, ", R800"); break;
3832 case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break;
3833 case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break;
3834 case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break;
9fc0b501 3835 case EF_Z80_MACH_Z80N: strcat (buf, ", Z80N"); break;
6655dba2
SB
3836 default:
3837 strcat (buf, _(", unknown")); break;
3838 }
3839 break;
252b5132
RH
3840 }
3841 }
3842
3843 return buf;
3844}
3845
252b5132 3846static const char *
dda8d76d 3847get_osabi_name (Filedata * filedata, unsigned int osabi)
d3ba0551
AM
3848{
3849 static char buff[32];
3850
3851 switch (osabi)
3852 {
3853 case ELFOSABI_NONE: return "UNIX - System V";
3854 case ELFOSABI_HPUX: return "UNIX - HP-UX";
3855 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
9c55345c 3856 case ELFOSABI_GNU: return "UNIX - GNU";
d3ba0551
AM
3857 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
3858 case ELFOSABI_AIX: return "UNIX - AIX";
3859 case ELFOSABI_IRIX: return "UNIX - IRIX";
3860 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
3861 case ELFOSABI_TRU64: return "UNIX - TRU64";
3862 case ELFOSABI_MODESTO: return "Novell - Modesto";
3863 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
3864 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
3865 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
3b26c801 3866 case ELFOSABI_AROS: return "AROS";
11636f9e 3867 case ELFOSABI_FENIXOS: return "FenixOS";
6d913794
NC
3868 case ELFOSABI_CLOUDABI: return "Nuxi CloudABI";
3869 case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS";
d3ba0551 3870 default:
40b36596 3871 if (osabi >= 64)
dda8d76d 3872 switch (filedata->file_header.e_machine)
40b36596
JM
3873 {
3874 case EM_ARM:
3875 switch (osabi)
3876 {
3877 case ELFOSABI_ARM: return "ARM";
18a20338 3878 case ELFOSABI_ARM_FDPIC: return "ARM FDPIC";
40b36596
JM
3879 default:
3880 break;
3881 }
3882 break;
3883
3884 case EM_MSP430:
3885 case EM_MSP430_OLD:
619ed720 3886 case EM_VISIUM:
40b36596
JM
3887 switch (osabi)
3888 {
3889 case ELFOSABI_STANDALONE: return _("Standalone App");
3890 default:
3891 break;
3892 }
3893 break;
3894
3895 case EM_TI_C6000:
3896 switch (osabi)
3897 {
3898 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
3899 case ELFOSABI_C6000_LINUX: return "Linux C6000";
3900 default:
3901 break;
3902 }
3903 break;
3904
3905 default:
3906 break;
3907 }
e9e44622 3908 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
d3ba0551
AM
3909 return buff;
3910 }
3911}
3912
a06ea964
NC
3913static const char *
3914get_aarch64_segment_type (unsigned long type)
3915{
3916 switch (type)
3917 {
32ec8896
NC
3918 case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT";
3919 default: return NULL;
a06ea964 3920 }
a06ea964
NC
3921}
3922
b294bdf8
MM
3923static const char *
3924get_arm_segment_type (unsigned long type)
3925{
3926 switch (type)
3927 {
32ec8896
NC
3928 case PT_ARM_EXIDX: return "EXIDX";
3929 default: return NULL;
b294bdf8 3930 }
b294bdf8
MM
3931}
3932
b4cbbe8f
AK
3933static const char *
3934get_s390_segment_type (unsigned long type)
3935{
3936 switch (type)
3937 {
3938 case PT_S390_PGSTE: return "S390_PGSTE";
3939 default: return NULL;
3940 }
3941}
3942
d3ba0551
AM
3943static const char *
3944get_mips_segment_type (unsigned long type)
252b5132
RH
3945{
3946 switch (type)
3947 {
32ec8896
NC
3948 case PT_MIPS_REGINFO: return "REGINFO";
3949 case PT_MIPS_RTPROC: return "RTPROC";
3950 case PT_MIPS_OPTIONS: return "OPTIONS";
3951 case PT_MIPS_ABIFLAGS: return "ABIFLAGS";
3952 default: return NULL;
252b5132 3953 }
252b5132
RH
3954}
3955
103f02d3 3956static const char *
d3ba0551 3957get_parisc_segment_type (unsigned long type)
103f02d3
UD
3958{
3959 switch (type)
3960 {
103f02d3
UD
3961 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
3962 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
61472819 3963 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
32ec8896 3964 default: return NULL;
103f02d3 3965 }
103f02d3
UD
3966}
3967
4d6ed7c8 3968static const char *
d3ba0551 3969get_ia64_segment_type (unsigned long type)
4d6ed7c8
NC
3970{
3971 switch (type)
3972 {
3973 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
3974 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
32ec8896 3975 default: return NULL;
4d6ed7c8 3976 }
4d6ed7c8
NC
3977}
3978
40b36596
JM
3979static const char *
3980get_tic6x_segment_type (unsigned long type)
3981{
3982 switch (type)
3983 {
32ec8896
NC
3984 case PT_C6000_PHATTR: return "C6000_PHATTR";
3985 default: return NULL;
40b36596 3986 }
40b36596
JM
3987}
3988
df3a023b
AM
3989static const char *
3990get_hpux_segment_type (unsigned long type, unsigned e_machine)
3991{
3992 if (e_machine == EM_PARISC)
3993 switch (type)
3994 {
3995 case PT_HP_TLS: return "HP_TLS";
3996 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
3997 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
3998 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
3999 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
4000 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
4001 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
4002 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
4003 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
4004 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
4005 case PT_HP_PARALLEL: return "HP_PARALLEL";
4006 case PT_HP_FASTBIND: return "HP_FASTBIND";
4007 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
4008 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
4009 case PT_HP_STACK: return "HP_STACK";
4010 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
4011 default: return NULL;
4012 }
4013
4014 if (e_machine == EM_IA_64)
4015 switch (type)
4016 {
4017 case PT_HP_TLS: return "HP_TLS";
4018 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
4019 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
4020 case PT_IA_64_HP_STACK: return "HP_STACK";
4021 default: return NULL;
4022 }
4023
4024 return NULL;
4025}
4026
5522f910
NC
4027static const char *
4028get_solaris_segment_type (unsigned long type)
4029{
4030 switch (type)
4031 {
4032 case 0x6464e550: return "PT_SUNW_UNWIND";
4033 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4034 case 0x6ffffff7: return "PT_LOSUNW";
4035 case 0x6ffffffa: return "PT_SUNWBSS";
4036 case 0x6ffffffb: return "PT_SUNWSTACK";
4037 case 0x6ffffffc: return "PT_SUNWDTRACE";
4038 case 0x6ffffffd: return "PT_SUNWCAP";
4039 case 0x6fffffff: return "PT_HISUNW";
32ec8896 4040 default: return NULL;
5522f910
NC
4041 }
4042}
4043
252b5132 4044static const char *
dda8d76d 4045get_segment_type (Filedata * filedata, unsigned long p_type)
252b5132 4046{
b34976b6 4047 static char buff[32];
252b5132
RH
4048
4049 switch (p_type)
4050 {
b34976b6
AM
4051 case PT_NULL: return "NULL";
4052 case PT_LOAD: return "LOAD";
252b5132 4053 case PT_DYNAMIC: return "DYNAMIC";
b34976b6
AM
4054 case PT_INTERP: return "INTERP";
4055 case PT_NOTE: return "NOTE";
4056 case PT_SHLIB: return "SHLIB";
4057 case PT_PHDR: return "PHDR";
13ae64f3 4058 case PT_TLS: return "TLS";
32ec8896 4059 case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
2b05f1b7 4060 case PT_GNU_STACK: return "GNU_STACK";
8c37241b 4061 case PT_GNU_RELRO: return "GNU_RELRO";
0a59decb 4062 case PT_GNU_PROPERTY: return "GNU_PROPERTY";
65765700 4063
3eba3ef3
NC
4064 case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE";
4065 case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED";
4066 case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA";
b9e920ec 4067
252b5132 4068 default:
df3a023b 4069 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
252b5132 4070 {
2cf0635d 4071 const char * result;
103f02d3 4072
dda8d76d 4073 switch (filedata->file_header.e_machine)
252b5132 4074 {
a06ea964
NC
4075 case EM_AARCH64:
4076 result = get_aarch64_segment_type (p_type);
4077 break;
b294bdf8
MM
4078 case EM_ARM:
4079 result = get_arm_segment_type (p_type);
4080 break;
252b5132 4081 case EM_MIPS:
4fe85591 4082 case EM_MIPS_RS3_LE:
252b5132
RH
4083 result = get_mips_segment_type (p_type);
4084 break;
103f02d3
UD
4085 case EM_PARISC:
4086 result = get_parisc_segment_type (p_type);
4087 break;
4d6ed7c8
NC
4088 case EM_IA_64:
4089 result = get_ia64_segment_type (p_type);
4090 break;
40b36596
JM
4091 case EM_TI_C6000:
4092 result = get_tic6x_segment_type (p_type);
4093 break;
b4cbbe8f
AK
4094 case EM_S390:
4095 case EM_S390_OLD:
4096 result = get_s390_segment_type (p_type);
4097 break;
252b5132
RH
4098 default:
4099 result = NULL;
4100 break;
4101 }
103f02d3 4102
252b5132
RH
4103 if (result != NULL)
4104 return result;
103f02d3 4105
1a9ccd70 4106 sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC);
252b5132
RH
4107 }
4108 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
103f02d3 4109 {
df3a023b 4110 const char * result = NULL;
103f02d3 4111
df3a023b 4112 switch (filedata->file_header.e_ident[EI_OSABI])
103f02d3 4113 {
df3a023b
AM
4114 case ELFOSABI_GNU:
4115 case ELFOSABI_FREEBSD:
4116 if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
4117 {
4118 sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO);
4119 result = buff;
4120 }
103f02d3 4121 break;
df3a023b
AM
4122 case ELFOSABI_HPUX:
4123 result = get_hpux_segment_type (p_type,
4124 filedata->file_header.e_machine);
4125 break;
4126 case ELFOSABI_SOLARIS:
4127 result = get_solaris_segment_type (p_type);
00428cca 4128 break;
103f02d3 4129 default:
103f02d3
UD
4130 break;
4131 }
103f02d3
UD
4132 if (result != NULL)
4133 return result;
4134
1a9ccd70 4135 sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS);
103f02d3 4136 }
252b5132 4137 else
e9e44622 4138 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
252b5132
RH
4139
4140 return buff;
4141 }
4142}
4143
53a346d8
CZ
4144static const char *
4145get_arc_section_type_name (unsigned int sh_type)
4146{
4147 switch (sh_type)
4148 {
4149 case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES";
4150 default:
4151 break;
4152 }
4153 return NULL;
4154}
4155
252b5132 4156static const char *
d3ba0551 4157get_mips_section_type_name (unsigned int sh_type)
252b5132
RH
4158{
4159 switch (sh_type)
4160 {
b34976b6
AM
4161 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
4162 case SHT_MIPS_MSYM: return "MIPS_MSYM";
4163 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
4164 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
4165 case SHT_MIPS_UCODE: return "MIPS_UCODE";
4166 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
4167 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
4168 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
4169 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
4170 case SHT_MIPS_RELD: return "MIPS_RELD";
4171 case SHT_MIPS_IFACE: return "MIPS_IFACE";
4172 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
4173 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
4174 case SHT_MIPS_SHDR: return "MIPS_SHDR";
4175 case SHT_MIPS_FDESC: return "MIPS_FDESC";
4176 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
4177 case SHT_MIPS_DENSE: return "MIPS_DENSE";
4178 case SHT_MIPS_PDESC: return "MIPS_PDESC";
4179 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
4180 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
4181 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
4182 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
4183 case SHT_MIPS_LINE: return "MIPS_LINE";
4184 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
4185 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
4186 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
4187 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
4188 case SHT_MIPS_DWARF: return "MIPS_DWARF";
4189 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
4190 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
4191 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
4192 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
4193 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
4194 case SHT_MIPS_XLATE: return "MIPS_XLATE";
4195 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
4196 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
4197 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
4198 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
252b5132 4199 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
351cdf24 4200 case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
f16a9783 4201 case SHT_MIPS_XHASH: return "MIPS_XHASH";
252b5132
RH
4202 default:
4203 break;
4204 }
4205 return NULL;
4206}
4207
103f02d3 4208static const char *
d3ba0551 4209get_parisc_section_type_name (unsigned int sh_type)
103f02d3
UD
4210{
4211 switch (sh_type)
4212 {
4213 case SHT_PARISC_EXT: return "PARISC_EXT";
4214 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
4215 case SHT_PARISC_DOC: return "PARISC_DOC";
eec8f817
DA
4216 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
4217 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
4218 case SHT_PARISC_STUBS: return "PARISC_STUBS";
61472819 4219 case SHT_PARISC_DLKM: return "PARISC_DLKM";
32ec8896 4220 default: return NULL;
103f02d3 4221 }
103f02d3
UD
4222}
4223
4d6ed7c8 4224static const char *
dda8d76d 4225get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type)
4d6ed7c8 4226{
18bd398b 4227 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
ecc51f48 4228 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
dda8d76d 4229 return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16);
0de14b54 4230
4d6ed7c8
NC
4231 switch (sh_type)
4232 {
148b93f2
NC
4233 case SHT_IA_64_EXT: return "IA_64_EXT";
4234 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
4235 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
4236 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
4237 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
4238 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
4239 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
4240 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
4241 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
4242 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
4d6ed7c8
NC
4243 default:
4244 break;
4245 }
4246 return NULL;
4247}
4248
d2b2c203
DJ
4249static const char *
4250get_x86_64_section_type_name (unsigned int sh_type)
4251{
4252 switch (sh_type)
4253 {
4254 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
32ec8896 4255 default: return NULL;
d2b2c203 4256 }
d2b2c203
DJ
4257}
4258
a06ea964
NC
4259static const char *
4260get_aarch64_section_type_name (unsigned int sh_type)
4261{
4262 switch (sh_type)
4263 {
32ec8896
NC
4264 case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES";
4265 default: return NULL;
a06ea964 4266 }
a06ea964
NC
4267}
4268
40a18ebd
NC
4269static const char *
4270get_arm_section_type_name (unsigned int sh_type)
4271{
4272 switch (sh_type)
4273 {
7f6fed87
NC
4274 case SHT_ARM_EXIDX: return "ARM_EXIDX";
4275 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
4276 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
4277 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
4278 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
32ec8896 4279 default: return NULL;
40a18ebd 4280 }
40a18ebd
NC
4281}
4282
40b36596
JM
4283static const char *
4284get_tic6x_section_type_name (unsigned int sh_type)
4285{
4286 switch (sh_type)
4287 {
32ec8896
NC
4288 case SHT_C6000_UNWIND: return "C6000_UNWIND";
4289 case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
4290 case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES";
4291 case SHT_TI_ICODE: return "TI_ICODE";
4292 case SHT_TI_XREF: return "TI_XREF";
4293 case SHT_TI_HANDLER: return "TI_HANDLER";
4294 case SHT_TI_INITINFO: return "TI_INITINFO";
4295 case SHT_TI_PHATTRS: return "TI_PHATTRS";
4296 default: return NULL;
40b36596 4297 }
40b36596
JM
4298}
4299
13761a11 4300static const char *
b0191216 4301get_msp430_section_type_name (unsigned int sh_type)
13761a11
NC
4302{
4303 switch (sh_type)
4304 {
32ec8896
NC
4305 case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
4306 case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
4307 case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
4308 default: return NULL;
13761a11
NC
4309 }
4310}
4311
fe944acf
FT
4312static const char *
4313get_nfp_section_type_name (unsigned int sh_type)
4314{
4315 switch (sh_type)
4316 {
4317 case SHT_NFP_MECONFIG: return "NFP_MECONFIG";
4318 case SHT_NFP_INITREG: return "NFP_INITREG";
4319 case SHT_NFP_UDEBUG: return "NFP_UDEBUG";
4320 default: return NULL;
4321 }
4322}
4323
685080f2
NC
4324static const char *
4325get_v850_section_type_name (unsigned int sh_type)
4326{
4327 switch (sh_type)
4328 {
32ec8896
NC
4329 case SHT_V850_SCOMMON: return "V850 Small Common";
4330 case SHT_V850_TCOMMON: return "V850 Tiny Common";
4331 case SHT_V850_ZCOMMON: return "V850 Zero Common";
4332 case SHT_RENESAS_IOP: return "RENESAS IOP";
4333 case SHT_RENESAS_INFO: return "RENESAS INFO";
4334 default: return NULL;
685080f2
NC
4335 }
4336}
4337
2dc8dd17
JW
4338static const char *
4339get_riscv_section_type_name (unsigned int sh_type)
4340{
4341 switch (sh_type)
4342 {
4343 case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES";
4344 default: return NULL;
4345 }
4346}
4347
0861f561
CQ
4348static const char *
4349get_csky_section_type_name (unsigned int sh_type)
4350{
4351 switch (sh_type)
4352 {
4353 case SHT_CSKY_ATTRIBUTES: return "CSKY_ATTRIBUTES";
4354 default: return NULL;
4355 }
4356}
4357
252b5132 4358static const char *
dda8d76d 4359get_section_type_name (Filedata * filedata, unsigned int sh_type)
252b5132 4360{
b34976b6 4361 static char buff[32];
9fb71ee4 4362 const char * result;
252b5132
RH
4363
4364 switch (sh_type)
4365 {
4366 case SHT_NULL: return "NULL";
4367 case SHT_PROGBITS: return "PROGBITS";
4368 case SHT_SYMTAB: return "SYMTAB";
4369 case SHT_STRTAB: return "STRTAB";
4370 case SHT_RELA: return "RELA";
4371 case SHT_HASH: return "HASH";
4372 case SHT_DYNAMIC: return "DYNAMIC";
4373 case SHT_NOTE: return "NOTE";
4374 case SHT_NOBITS: return "NOBITS";
4375 case SHT_REL: return "REL";
4376 case SHT_SHLIB: return "SHLIB";
4377 case SHT_DYNSYM: return "DYNSYM";
d1133906
NC
4378 case SHT_INIT_ARRAY: return "INIT_ARRAY";
4379 case SHT_FINI_ARRAY: return "FINI_ARRAY";
4380 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
fdc90cb4 4381 case SHT_GNU_HASH: return "GNU_HASH";
93ebe586 4382 case SHT_GROUP: return "GROUP";
67ce483b 4383 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES";
252b5132
RH
4384 case SHT_GNU_verdef: return "VERDEF";
4385 case SHT_GNU_verneed: return "VERNEED";
4386 case SHT_GNU_versym: return "VERSYM";
b34976b6
AM
4387 case 0x6ffffff0: return "VERSYM";
4388 case 0x6ffffffc: return "VERDEF";
252b5132
RH
4389 case 0x7ffffffd: return "AUXILIARY";
4390 case 0x7fffffff: return "FILTER";
047b2264 4391 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
252b5132
RH
4392
4393 default:
4394 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
4395 {
dda8d76d 4396 switch (filedata->file_header.e_machine)
252b5132 4397 {
53a346d8
CZ
4398 case EM_ARC:
4399 case EM_ARC_COMPACT:
4400 case EM_ARC_COMPACT2:
4401 result = get_arc_section_type_name (sh_type);
4402 break;
252b5132 4403 case EM_MIPS:
4fe85591 4404 case EM_MIPS_RS3_LE:
252b5132
RH
4405 result = get_mips_section_type_name (sh_type);
4406 break;
103f02d3
UD
4407 case EM_PARISC:
4408 result = get_parisc_section_type_name (sh_type);
4409 break;
4d6ed7c8 4410 case EM_IA_64:
dda8d76d 4411 result = get_ia64_section_type_name (filedata, sh_type);
4d6ed7c8 4412 break;
d2b2c203 4413 case EM_X86_64:
8a9036a4 4414 case EM_L1OM:
7a9068fe 4415 case EM_K1OM:
d2b2c203
DJ
4416 result = get_x86_64_section_type_name (sh_type);
4417 break;
a06ea964
NC
4418 case EM_AARCH64:
4419 result = get_aarch64_section_type_name (sh_type);
4420 break;
40a18ebd
NC
4421 case EM_ARM:
4422 result = get_arm_section_type_name (sh_type);
4423 break;
40b36596
JM
4424 case EM_TI_C6000:
4425 result = get_tic6x_section_type_name (sh_type);
4426 break;
13761a11 4427 case EM_MSP430:
b0191216 4428 result = get_msp430_section_type_name (sh_type);
13761a11 4429 break;
fe944acf
FT
4430 case EM_NFP:
4431 result = get_nfp_section_type_name (sh_type);
4432 break;
685080f2
NC
4433 case EM_V800:
4434 case EM_V850:
4435 case EM_CYGNUS_V850:
4436 result = get_v850_section_type_name (sh_type);
4437 break;
2dc8dd17
JW
4438 case EM_RISCV:
4439 result = get_riscv_section_type_name (sh_type);
4440 break;
0861f561
CQ
4441 case EM_CSKY:
4442 result = get_csky_section_type_name (sh_type);
4443 break;
252b5132
RH
4444 default:
4445 result = NULL;
4446 break;
4447 }
4448
4449 if (result != NULL)
4450 return result;
4451
9fb71ee4 4452 sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
252b5132
RH
4453 }
4454 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
148b93f2 4455 {
dda8d76d 4456 switch (filedata->file_header.e_machine)
148b93f2
NC
4457 {
4458 case EM_IA_64:
dda8d76d 4459 result = get_ia64_section_type_name (filedata, sh_type);
148b93f2
NC
4460 break;
4461 default:
dda8d76d 4462 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
fd85a6a1
NC
4463 result = get_solaris_section_type (sh_type);
4464 else
1b4b80bf
NC
4465 {
4466 switch (sh_type)
4467 {
4468 case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break;
4469 case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break;
4470 case SHT_GNU_HASH: result = "GNU_HASH"; break;
4471 case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break;
4472 default:
4473 result = NULL;
4474 break;
4475 }
4476 }
148b93f2
NC
4477 break;
4478 }
4479
4480 if (result != NULL)
4481 return result;
4482
9fb71ee4 4483 sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
148b93f2 4484 }
252b5132 4485 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
685080f2 4486 {
dda8d76d 4487 switch (filedata->file_header.e_machine)
685080f2
NC
4488 {
4489 case EM_V800:
4490 case EM_V850:
4491 case EM_CYGNUS_V850:
9fb71ee4 4492 result = get_v850_section_type_name (sh_type);
a9fb83be 4493 break;
685080f2 4494 default:
9fb71ee4 4495 result = NULL;
685080f2
NC
4496 break;
4497 }
4498
9fb71ee4
NC
4499 if (result != NULL)
4500 return result;
4501
4502 sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
685080f2 4503 }
252b5132 4504 else
a7dbfd1c
NC
4505 /* This message is probably going to be displayed in a 15
4506 character wide field, so put the hex value first. */
4507 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
103f02d3 4508
252b5132
RH
4509 return buff;
4510 }
4511}
4512
79bc120c
NC
4513enum long_option_values
4514{
4515 OPTION_DEBUG_DUMP = 512,
4516 OPTION_DYN_SYMS,
0f03783c 4517 OPTION_LTO_SYMS,
79bc120c
NC
4518 OPTION_DWARF_DEPTH,
4519 OPTION_DWARF_START,
4520 OPTION_DWARF_CHECK,
4521 OPTION_CTF_DUMP,
4522 OPTION_CTF_PARENT,
4523 OPTION_CTF_SYMBOLS,
4524 OPTION_CTF_STRINGS,
4525 OPTION_WITH_SYMBOL_VERSIONS,
4526 OPTION_RECURSE_LIMIT,
4527 OPTION_NO_RECURSE_LIMIT,
4528 OPTION_NO_DEMANGLING
4529};
2979dc34 4530
85b1c36d 4531static struct option options[] =
252b5132 4532{
79bc120c
NC
4533 /* Note - This table is alpha-sorted on the 'val'
4534 field in order to make adding new options easier. */
4535 {"arch-specific", no_argument, 0, 'A'},
b34976b6 4536 {"all", no_argument, 0, 'a'},
79bc120c
NC
4537 {"demangle", optional_argument, 0, 'C'},
4538 {"archive-index", no_argument, 0, 'c'},
4539 {"use-dynamic", no_argument, 0, 'D'},
4540 {"dynamic", no_argument, 0, 'd'},
b34976b6 4541 {"headers", no_argument, 0, 'e'},
79bc120c
NC
4542 {"section-groups", no_argument, 0, 'g'},
4543 {"help", no_argument, 0, 'H'},
4544 {"file-header", no_argument, 0, 'h'},
b34976b6 4545 {"histogram", no_argument, 0, 'I'},
79bc120c
NC
4546 {"lint", no_argument, 0, 'L'},
4547 {"enable-checks", no_argument, 0, 'L'},
4548 {"program-headers", no_argument, 0, 'l'},
b34976b6 4549 {"segments", no_argument, 0, 'l'},
595cf52e 4550 {"full-section-name",no_argument, 0, 'N'},
79bc120c 4551 {"notes", no_argument, 0, 'n'},
ca0e11aa 4552 {"process-links", no_argument, 0, 'P'},
79bc120c
NC
4553 {"string-dump", required_argument, 0, 'p'},
4554 {"relocated-dump", required_argument, 0, 'R'},
4555 {"relocs", no_argument, 0, 'r'},
4556 {"section-headers", no_argument, 0, 'S'},
4557 {"sections", no_argument, 0, 'S'},
b34976b6
AM
4558 {"symbols", no_argument, 0, 's'},
4559 {"syms", no_argument, 0, 's'},
79bc120c
NC
4560 {"silent-truncation",no_argument, 0, 'T'},
4561 {"section-details", no_argument, 0, 't'},
09c11c86 4562 {"unwind", no_argument, 0, 'u'},
79bc120c
NC
4563 {"version-info", no_argument, 0, 'V'},
4564 {"version", no_argument, 0, 'v'},
4565 {"wide", no_argument, 0, 'W'},
b34976b6 4566 {"hex-dump", required_argument, 0, 'x'},
0e602686 4567 {"decompress", no_argument, 0, 'z'},
252b5132 4568
79bc120c
NC
4569 {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLING},
4570 {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
4571 {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
4572 {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
4573 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
0f03783c 4574 {"lto-syms", no_argument, 0, OPTION_LTO_SYMS},
79bc120c 4575 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
fd2f0033
TT
4576 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
4577 {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
4723351a 4578 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
094e34f2 4579#ifdef ENABLE_LIBCTF
d344b407 4580 {"ctf", required_argument, 0, OPTION_CTF_DUMP},
7d9813f1
NA
4581 {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS},
4582 {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS},
4583 {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT},
094e34f2 4584#endif
7d9813f1 4585
b34976b6 4586 {0, no_argument, 0, 0}
252b5132
RH
4587};
4588
4589static void
2cf0635d 4590usage (FILE * stream)
252b5132 4591{
92f01d61
JM
4592 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
4593 fprintf (stream, _(" Display information about the contents of ELF format files\n"));
4594 fprintf (stream, _(" Options are:\n\
8b53311e
NC
4595 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4596 -h --file-header Display the ELF file header\n\
4597 -l --program-headers Display the program headers\n\
4598 --segments An alias for --program-headers\n\
4599 -S --section-headers Display the sections' header\n\
4600 --sections An alias for --section-headers\n\
f5842774 4601 -g --section-groups Display the section groups\n\
5477e8a0 4602 -t --section-details Display the section details\n\
8b53311e
NC
4603 -e --headers Equivalent to: -h -l -S\n\
4604 -s --syms Display the symbol table\n\
3f08eb35 4605 --symbols An alias for --syms\n\
1b513401 4606 --dyn-syms Display the dynamic symbol table\n\
0f03783c 4607 --lto-syms Display LTO symbol tables\n\
79bc120c
NC
4608 -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
4609 The STYLE, if specified, can be `auto' (the default),\n\
4610 `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
4611 or `gnat'\n\
4612 --no-demangle Do not demangle low-level symbol names. (This is the default)\n\
4613 --recurse-limit Enable a demangling recursion limit. (This is the default)\n\
4614 --no-recurse-limit Disable a demangling recursion limit\n\
8b53311e
NC
4615 -n --notes Display the core notes (if present)\n\
4616 -r --relocs Display the relocations (if present)\n\
4617 -u --unwind Display the unwind info (if present)\n\
b2d38a17 4618 -d --dynamic Display the dynamic section (if present)\n\
8b53311e 4619 -V --version-info Display the version sections (if present)\n\
1b31d05e 4620 -A --arch-specific Display architecture specific information (if any)\n\
4145f1d5 4621 -c --archive-index Display the symbol/file index in an archive\n\
8b53311e 4622 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
1b513401 4623 -L --lint|--enable-checks Display warning messages for possible problems\n\
09c11c86
NC
4624 -x --hex-dump=<number|name>\n\
4625 Dump the contents of section <number|name> as bytes\n\
4626 -p --string-dump=<number|name>\n\
4627 Dump the contents of section <number|name> as strings\n\
cf13d699
NC
4628 -R --relocated-dump=<number|name>\n\
4629 Dump the contents of section <number|name> as relocated bytes\n\
0e602686 4630 -z --decompress Decompress section before dumping it\n\
ca0e11aa 4631 -w[lLiaprmfFsoORtUuTgAc] or\n\
1ed06042 4632 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
e4b7104b 4633 =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\
657d0d47 4634 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
ca0e11aa
NC
4635 =addr,=cu_index]\n\
4636 Display the contents of DWARF debug sections\n\
4637 -wk,--debug-dump=links Display the contents of sections that link to separate debuginfo files\n\
4638 -P,--process-links Display the contents of non-debug sections in separate debuginfo files. (Implies -wK)\n"));
c46b7066
NC
4639#if DEFAULT_FOR_FOLLOW_LINKS
4640 fprintf (stream, _("\
4641 -wK,--debug-dump=follow-links Follow links to separate debug info files (default)\n\
4642 -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files\n\
4643"));
4644#else
4645 fprintf (stream, _("\
4646 -wK,--debug-dump=follow-links Follow links to separate debug info files\n\
4647 -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files (default)\n\
4648"));
4649#endif
fd2f0033
TT
4650 fprintf (stream, _("\
4651 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4652 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4653 or deeper\n"));
094e34f2 4654#ifdef ENABLE_LIBCTF
7d9813f1
NA
4655 fprintf (stream, _("\
4656 --ctf=<number|name> Display CTF info from section <number|name>\n\
4657 --ctf-parent=<number|name>\n\
4658 Use section <number|name> as the CTF parent\n\n\
4659 --ctf-symbols=<number|name>\n\
4660 Use section <number|name> as the CTF external symtab\n\n\
4661 --ctf-strings=<number|name>\n\
4662 Use section <number|name> as the CTF external strtab\n\n"));
094e34f2 4663#endif
7d9813f1 4664
252b5132 4665#ifdef SUPPORT_DISASSEMBLY
92f01d61 4666 fprintf (stream, _("\
09c11c86
NC
4667 -i --instruction-dump=<number|name>\n\
4668 Disassemble the contents of section <number|name>\n"));
252b5132 4669#endif
92f01d61 4670 fprintf (stream, _("\
8b53311e
NC
4671 -I --histogram Display histogram of bucket list lengths\n\
4672 -W --wide Allow output width to exceed 80 characters\n\
0942c7ab 4673 -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\
07012eee 4674 @<file> Read options from <file>\n\
8b53311e
NC
4675 -H --help Display this information\n\
4676 -v --version Display the version number of readelf\n"));
1118d252 4677
92f01d61
JM
4678 if (REPORT_BUGS_TO[0] && stream == stdout)
4679 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
252b5132 4680
92f01d61 4681 exit (stream == stdout ? 0 : 1);
252b5132
RH
4682}
4683
18bd398b
NC
4684/* Record the fact that the user wants the contents of section number
4685 SECTION to be displayed using the method(s) encoded as flags bits
4686 in TYPE. Note, TYPE can be zero if we are creating the array for
4687 the first time. */
4688
252b5132 4689static void
6431e409
AM
4690request_dump_bynumber (struct dump_data *dumpdata,
4691 unsigned int section, dump_type type)
252b5132 4692{
6431e409 4693 if (section >= dumpdata->num_dump_sects)
252b5132 4694 {
2cf0635d 4695 dump_type * new_dump_sects;
252b5132 4696
3f5e193b 4697 new_dump_sects = (dump_type *) calloc (section + 1,
dda8d76d 4698 sizeof (* new_dump_sects));
252b5132
RH
4699
4700 if (new_dump_sects == NULL)
591a748a 4701 error (_("Out of memory allocating dump request table.\n"));
252b5132
RH
4702 else
4703 {
6431e409 4704 if (dumpdata->dump_sects)
21b65bac
NC
4705 {
4706 /* Copy current flag settings. */
6431e409
AM
4707 memcpy (new_dump_sects, dumpdata->dump_sects,
4708 dumpdata->num_dump_sects * sizeof (* new_dump_sects));
252b5132 4709
6431e409 4710 free (dumpdata->dump_sects);
21b65bac 4711 }
252b5132 4712
6431e409
AM
4713 dumpdata->dump_sects = new_dump_sects;
4714 dumpdata->num_dump_sects = section + 1;
252b5132
RH
4715 }
4716 }
4717
6431e409
AM
4718 if (dumpdata->dump_sects)
4719 dumpdata->dump_sects[section] |= type;
252b5132
RH
4720}
4721
aef1f6d0
DJ
4722/* Request a dump by section name. */
4723
4724static void
2cf0635d 4725request_dump_byname (const char * section, dump_type type)
aef1f6d0 4726{
2cf0635d 4727 struct dump_list_entry * new_request;
aef1f6d0 4728
3f5e193b
NC
4729 new_request = (struct dump_list_entry *)
4730 malloc (sizeof (struct dump_list_entry));
aef1f6d0 4731 if (!new_request)
591a748a 4732 error (_("Out of memory allocating dump request table.\n"));
aef1f6d0
DJ
4733
4734 new_request->name = strdup (section);
4735 if (!new_request->name)
591a748a 4736 error (_("Out of memory allocating dump request table.\n"));
aef1f6d0
DJ
4737
4738 new_request->type = type;
4739
4740 new_request->next = dump_sects_byname;
4741 dump_sects_byname = new_request;
4742}
4743
cf13d699 4744static inline void
6431e409 4745request_dump (struct dump_data *dumpdata, dump_type type)
cf13d699
NC
4746{
4747 int section;
4748 char * cp;
4749
1be305ff 4750 do_dump = TRUE;
cf13d699
NC
4751 section = strtoul (optarg, & cp, 0);
4752
4753 if (! *cp && section >= 0)
6431e409 4754 request_dump_bynumber (dumpdata, section, type);
cf13d699
NC
4755 else
4756 request_dump_byname (optarg, type);
4757}
4758
252b5132 4759static void
6431e409 4760parse_args (struct dump_data *dumpdata, int argc, char ** argv)
252b5132
RH
4761{
4762 int c;
4763
4764 if (argc < 2)
92f01d61 4765 usage (stderr);
252b5132
RH
4766
4767 while ((c = getopt_long
ca0e11aa 4768 (argc, argv, "ACDHILNPR:STVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
252b5132 4769 {
252b5132
RH
4770 switch (c)
4771 {
4772 case 0:
4773 /* Long options. */
4774 break;
4775 case 'H':
92f01d61 4776 usage (stdout);
252b5132
RH
4777 break;
4778
4779 case 'a':
32ec8896
NC
4780 do_syms = TRUE;
4781 do_reloc = TRUE;
4782 do_unwind = TRUE;
4783 do_dynamic = TRUE;
4784 do_header = TRUE;
4785 do_sections = TRUE;
4786 do_section_groups = TRUE;
4787 do_segments = TRUE;
4788 do_version = TRUE;
4789 do_histogram = TRUE;
4790 do_arch = TRUE;
4791 do_notes = TRUE;
252b5132 4792 break;
79bc120c 4793
f5842774 4794 case 'g':
32ec8896 4795 do_section_groups = TRUE;
f5842774 4796 break;
5477e8a0 4797 case 't':
595cf52e 4798 case 'N':
32ec8896
NC
4799 do_sections = TRUE;
4800 do_section_details = TRUE;
595cf52e 4801 break;
252b5132 4802 case 'e':
32ec8896
NC
4803 do_header = TRUE;
4804 do_sections = TRUE;
4805 do_segments = TRUE;
252b5132 4806 break;
a952a375 4807 case 'A':
32ec8896 4808 do_arch = TRUE;
a952a375 4809 break;
252b5132 4810 case 'D':
32ec8896 4811 do_using_dynamic = TRUE;
252b5132
RH
4812 break;
4813 case 'r':
32ec8896 4814 do_reloc = TRUE;
252b5132 4815 break;
4d6ed7c8 4816 case 'u':
32ec8896 4817 do_unwind = TRUE;
4d6ed7c8 4818 break;
252b5132 4819 case 'h':
32ec8896 4820 do_header = TRUE;
252b5132
RH
4821 break;
4822 case 'l':
32ec8896 4823 do_segments = TRUE;
252b5132
RH
4824 break;
4825 case 's':
32ec8896 4826 do_syms = TRUE;
252b5132
RH
4827 break;
4828 case 'S':
32ec8896 4829 do_sections = TRUE;
252b5132
RH
4830 break;
4831 case 'd':
32ec8896 4832 do_dynamic = TRUE;
252b5132 4833 break;
a952a375 4834 case 'I':
32ec8896 4835 do_histogram = TRUE;
a952a375 4836 break;
779fe533 4837 case 'n':
32ec8896 4838 do_notes = TRUE;
779fe533 4839 break;
4145f1d5 4840 case 'c':
32ec8896 4841 do_archive_index = TRUE;
4145f1d5 4842 break;
1b513401
NC
4843 case 'L':
4844 do_checks = TRUE;
4845 break;
ca0e11aa
NC
4846 case 'P':
4847 process_links = TRUE;
4848 do_follow_links = TRUE;
4849 break;
252b5132 4850 case 'x':
6431e409 4851 request_dump (dumpdata, HEX_DUMP);
aef1f6d0 4852 break;
09c11c86 4853 case 'p':
6431e409 4854 request_dump (dumpdata, STRING_DUMP);
cf13d699
NC
4855 break;
4856 case 'R':
6431e409 4857 request_dump (dumpdata, RELOC_DUMP);
09c11c86 4858 break;
0e602686 4859 case 'z':
32ec8896 4860 decompress_dumps = TRUE;
0e602686 4861 break;
252b5132 4862 case 'w':
32ec8896 4863 do_dump = TRUE;
0f03783c 4864 if (optarg == NULL)
613ff48b 4865 {
32ec8896 4866 do_debugging = TRUE;
613ff48b
CC
4867 dwarf_select_sections_all ();
4868 }
252b5132
RH
4869 else
4870 {
32ec8896 4871 do_debugging = FALSE;
4cb93e3b 4872 dwarf_select_sections_by_letters (optarg);
252b5132
RH
4873 }
4874 break;
2979dc34 4875 case OPTION_DEBUG_DUMP:
32ec8896 4876 do_dump = TRUE;
0f03783c 4877 if (optarg == NULL)
32ec8896 4878 do_debugging = TRUE;
2979dc34
JJ
4879 else
4880 {
32ec8896 4881 do_debugging = FALSE;
4cb93e3b 4882 dwarf_select_sections_by_names (optarg);
2979dc34
JJ
4883 }
4884 break;
fd2f0033
TT
4885 case OPTION_DWARF_DEPTH:
4886 {
4887 char *cp;
4888
4889 dwarf_cutoff_level = strtoul (optarg, & cp, 0);
4890 }
4891 break;
4892 case OPTION_DWARF_START:
4893 {
4894 char *cp;
4895
4896 dwarf_start_die = strtoul (optarg, & cp, 0);
4897 }
4898 break;
4723351a 4899 case OPTION_DWARF_CHECK:
32ec8896 4900 dwarf_check = TRUE;
4723351a 4901 break;
7d9813f1
NA
4902 case OPTION_CTF_DUMP:
4903 do_ctf = TRUE;
6431e409 4904 request_dump (dumpdata, CTF_DUMP);
7d9813f1
NA
4905 break;
4906 case OPTION_CTF_SYMBOLS:
df16e041 4907 free (dump_ctf_symtab_name);
7d9813f1
NA
4908 dump_ctf_symtab_name = strdup (optarg);
4909 break;
4910 case OPTION_CTF_STRINGS:
df16e041 4911 free (dump_ctf_strtab_name);
7d9813f1
NA
4912 dump_ctf_strtab_name = strdup (optarg);
4913 break;
4914 case OPTION_CTF_PARENT:
df16e041 4915 free (dump_ctf_parent_name);
7d9813f1
NA
4916 dump_ctf_parent_name = strdup (optarg);
4917 break;
2c610e4b 4918 case OPTION_DYN_SYMS:
32ec8896 4919 do_dyn_syms = TRUE;
2c610e4b 4920 break;
0f03783c
NC
4921 case OPTION_LTO_SYMS:
4922 do_lto_syms = TRUE;
4923 break;
252b5132
RH
4924#ifdef SUPPORT_DISASSEMBLY
4925 case 'i':
6431e409 4926 request_dump (dumpdata, DISASS_DUMP);
cf13d699 4927 break;
252b5132
RH
4928#endif
4929 case 'v':
4930 print_version (program_name);
4931 break;
4932 case 'V':
32ec8896 4933 do_version = TRUE;
252b5132 4934 break;
d974e256 4935 case 'W':
32ec8896 4936 do_wide = TRUE;
d974e256 4937 break;
0942c7ab
NC
4938 case 'T':
4939 do_not_show_symbol_truncation = TRUE;
4940 break;
79bc120c
NC
4941 case 'C':
4942 do_demangle = TRUE;
4943 if (optarg != NULL)
4944 {
4945 enum demangling_styles style;
4946
4947 style = cplus_demangle_name_to_style (optarg);
4948 if (style == unknown_demangling)
4949 error (_("unknown demangling style `%s'"), optarg);
4950
4951 cplus_demangle_set_style (style);
4952 }
4953 break;
4954 case OPTION_NO_DEMANGLING:
4955 do_demangle = FALSE;
4956 break;
4957 case OPTION_RECURSE_LIMIT:
4958 demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT;
4959 break;
4960 case OPTION_NO_RECURSE_LIMIT:
4961 demangle_flags |= DMGL_NO_RECURSE_LIMIT;
4962 break;
4963 case OPTION_WITH_SYMBOL_VERSIONS:
4964 /* Ignored for backward compatibility. */
4965 break;
b9e920ec 4966
252b5132 4967 default:
252b5132
RH
4968 /* xgettext:c-format */
4969 error (_("Invalid option '-%c'\n"), c);
1a0670f3 4970 /* Fall through. */
252b5132 4971 case '?':
92f01d61 4972 usage (stderr);
252b5132
RH
4973 }
4974 }
4975
4d6ed7c8 4976 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
252b5132 4977 && !do_segments && !do_header && !do_dump && !do_version
f5842774 4978 && !do_histogram && !do_debugging && !do_arch && !do_notes
2c610e4b 4979 && !do_section_groups && !do_archive_index
0f03783c 4980 && !do_dyn_syms && !do_lto_syms)
1b513401
NC
4981 {
4982 if (do_checks)
4983 {
4984 check_all = TRUE;
4985 do_dynamic = do_syms = do_reloc = do_unwind = do_sections = TRUE;
4986 do_segments = do_header = do_dump = do_version = TRUE;
4987 do_histogram = do_debugging = do_arch = do_notes = TRUE;
4988 do_section_groups = do_archive_index = do_dyn_syms = TRUE;
0f03783c 4989 do_lto_syms = TRUE;
1b513401
NC
4990 }
4991 else
4992 usage (stderr);
4993 }
252b5132
RH
4994}
4995
4996static const char *
d3ba0551 4997get_elf_class (unsigned int elf_class)
252b5132 4998{
b34976b6 4999 static char buff[32];
103f02d3 5000
252b5132
RH
5001 switch (elf_class)
5002 {
5003 case ELFCLASSNONE: return _("none");
e3c8793a
NC
5004 case ELFCLASS32: return "ELF32";
5005 case ELFCLASS64: return "ELF64";
ab5e7794 5006 default:
e9e44622 5007 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
ab5e7794 5008 return buff;
252b5132
RH
5009 }
5010}
5011
5012static const char *
d3ba0551 5013get_data_encoding (unsigned int encoding)
252b5132 5014{
b34976b6 5015 static char buff[32];
103f02d3 5016
252b5132
RH
5017 switch (encoding)
5018 {
5019 case ELFDATANONE: return _("none");
33c63f9d
CM
5020 case ELFDATA2LSB: return _("2's complement, little endian");
5021 case ELFDATA2MSB: return _("2's complement, big endian");
103f02d3 5022 default:
e9e44622 5023 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
ab5e7794 5024 return buff;
252b5132
RH
5025 }
5026}
5027
dda8d76d 5028/* Decode the data held in 'filedata->file_header'. */
ee42cf8c 5029
32ec8896 5030static bfd_boolean
dda8d76d 5031process_file_header (Filedata * filedata)
252b5132 5032{
dda8d76d
NC
5033 Elf_Internal_Ehdr * header = & filedata->file_header;
5034
5035 if ( header->e_ident[EI_MAG0] != ELFMAG0
5036 || header->e_ident[EI_MAG1] != ELFMAG1
5037 || header->e_ident[EI_MAG2] != ELFMAG2
5038 || header->e_ident[EI_MAG3] != ELFMAG3)
252b5132
RH
5039 {
5040 error
5041 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
32ec8896 5042 return FALSE;
252b5132
RH
5043 }
5044
ca0e11aa
NC
5045 if (! filedata->is_separate)
5046 init_dwarf_regnames_by_elf_machine_code (header->e_machine);
2dc4cec1 5047
252b5132
RH
5048 if (do_header)
5049 {
32ec8896 5050 unsigned i;
252b5132 5051
ca0e11aa
NC
5052 if (filedata->is_separate)
5053 printf (_("ELF Header in linked file '%s':\n"), filedata->file_name);
5054 else
5055 printf (_("ELF Header:\n"));
252b5132 5056 printf (_(" Magic: "));
b34976b6 5057 for (i = 0; i < EI_NIDENT; i++)
dda8d76d 5058 printf ("%2.2x ", header->e_ident[i]);
252b5132
RH
5059 printf ("\n");
5060 printf (_(" Class: %s\n"),
dda8d76d 5061 get_elf_class (header->e_ident[EI_CLASS]));
252b5132 5062 printf (_(" Data: %s\n"),
dda8d76d 5063 get_data_encoding (header->e_ident[EI_DATA]));
e8a64888 5064 printf (_(" Version: %d%s\n"),
dda8d76d
NC
5065 header->e_ident[EI_VERSION],
5066 (header->e_ident[EI_VERSION] == EV_CURRENT
e8a64888 5067 ? _(" (current)")
dda8d76d 5068 : (header->e_ident[EI_VERSION] != EV_NONE
e8a64888 5069 ? _(" <unknown>")
789be9f7 5070 : "")));
252b5132 5071 printf (_(" OS/ABI: %s\n"),
dda8d76d 5072 get_osabi_name (filedata, header->e_ident[EI_OSABI]));
252b5132 5073 printf (_(" ABI Version: %d\n"),
dda8d76d 5074 header->e_ident[EI_ABIVERSION]);
252b5132 5075 printf (_(" Type: %s\n"),
dda8d76d 5076 get_file_type (header->e_type));
252b5132 5077 printf (_(" Machine: %s\n"),
dda8d76d 5078 get_machine_name (header->e_machine));
252b5132 5079 printf (_(" Version: 0x%lx\n"),
e8a64888 5080 header->e_version);
76da6bbe 5081
f7a99963 5082 printf (_(" Entry point address: "));
e8a64888 5083 print_vma (header->e_entry, PREFIX_HEX);
f7a99963 5084 printf (_("\n Start of program headers: "));
e8a64888 5085 print_vma (header->e_phoff, DEC);
f7a99963 5086 printf (_(" (bytes into file)\n Start of section headers: "));
e8a64888 5087 print_vma (header->e_shoff, DEC);
f7a99963 5088 printf (_(" (bytes into file)\n"));
76da6bbe 5089
252b5132 5090 printf (_(" Flags: 0x%lx%s\n"),
e8a64888 5091 header->e_flags,
dda8d76d 5092 get_machine_flags (filedata, header->e_flags, header->e_machine));
e8a64888
AM
5093 printf (_(" Size of this header: %u (bytes)\n"),
5094 header->e_ehsize);
5095 printf (_(" Size of program headers: %u (bytes)\n"),
5096 header->e_phentsize);
5097 printf (_(" Number of program headers: %u"),
5098 header->e_phnum);
dda8d76d
NC
5099 if (filedata->section_headers != NULL
5100 && header->e_phnum == PN_XNUM
5101 && filedata->section_headers[0].sh_info != 0)
e8a64888
AM
5102 {
5103 header->e_phnum = filedata->section_headers[0].sh_info;
5104 printf (" (%u)", header->e_phnum);
5105 }
2046a35d 5106 putc ('\n', stdout);
e8a64888
AM
5107 printf (_(" Size of section headers: %u (bytes)\n"),
5108 header->e_shentsize);
5109 printf (_(" Number of section headers: %u"),
5110 header->e_shnum);
dda8d76d 5111 if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF)
e8a64888
AM
5112 {
5113 header->e_shnum = filedata->section_headers[0].sh_size;
5114 printf (" (%u)", header->e_shnum);
5115 }
560f3c1c 5116 putc ('\n', stdout);
e8a64888
AM
5117 printf (_(" Section header string table index: %u"),
5118 header->e_shstrndx);
dda8d76d
NC
5119 if (filedata->section_headers != NULL
5120 && header->e_shstrndx == (SHN_XINDEX & 0xffff))
e8a64888
AM
5121 {
5122 header->e_shstrndx = filedata->section_headers[0].sh_link;
5123 printf (" (%u)", header->e_shstrndx);
5124 }
5125 if (header->e_shstrndx != SHN_UNDEF
5126 && header->e_shstrndx >= header->e_shnum)
5127 {
5128 header->e_shstrndx = SHN_UNDEF;
5129 printf (_(" <corrupt: out of range>"));
5130 }
560f3c1c
AM
5131 putc ('\n', stdout);
5132 }
5133
dda8d76d 5134 if (filedata->section_headers != NULL)
560f3c1c 5135 {
dda8d76d
NC
5136 if (header->e_phnum == PN_XNUM
5137 && filedata->section_headers[0].sh_info != 0)
5138 header->e_phnum = filedata->section_headers[0].sh_info;
5139 if (header->e_shnum == SHN_UNDEF)
5140 header->e_shnum = filedata->section_headers[0].sh_size;
5141 if (header->e_shstrndx == (SHN_XINDEX & 0xffff))
5142 header->e_shstrndx = filedata->section_headers[0].sh_link;
9c1ce108 5143 if (header->e_shstrndx >= header->e_shnum)
dda8d76d
NC
5144 header->e_shstrndx = SHN_UNDEF;
5145 free (filedata->section_headers);
5146 filedata->section_headers = NULL;
252b5132 5147 }
103f02d3 5148
32ec8896 5149 return TRUE;
9ea033b2
NC
5150}
5151
dda8d76d
NC
5152/* Read in the program headers from FILEDATA and store them in PHEADERS.
5153 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5154
e0a31db1 5155static bfd_boolean
dda8d76d 5156get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
9ea033b2 5157{
2cf0635d
NC
5158 Elf32_External_Phdr * phdrs;
5159 Elf32_External_Phdr * external;
5160 Elf_Internal_Phdr * internal;
b34976b6 5161 unsigned int i;
dda8d76d
NC
5162 unsigned int size = filedata->file_header.e_phentsize;
5163 unsigned int num = filedata->file_header.e_phnum;
e0a31db1
NC
5164
5165 /* PR binutils/17531: Cope with unexpected section header sizes. */
5166 if (size == 0 || num == 0)
5167 return FALSE;
5168 if (size < sizeof * phdrs)
5169 {
5170 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5171 return FALSE;
5172 }
5173 if (size > sizeof * phdrs)
5174 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
103f02d3 5175
dda8d76d 5176 phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
e0a31db1
NC
5177 size, num, _("program headers"));
5178 if (phdrs == NULL)
5179 return FALSE;
9ea033b2 5180
91d6fa6a 5181 for (i = 0, internal = pheaders, external = phdrs;
dda8d76d 5182 i < filedata->file_header.e_phnum;
b34976b6 5183 i++, internal++, external++)
252b5132 5184 {
9ea033b2
NC
5185 internal->p_type = BYTE_GET (external->p_type);
5186 internal->p_offset = BYTE_GET (external->p_offset);
5187 internal->p_vaddr = BYTE_GET (external->p_vaddr);
5188 internal->p_paddr = BYTE_GET (external->p_paddr);
5189 internal->p_filesz = BYTE_GET (external->p_filesz);
5190 internal->p_memsz = BYTE_GET (external->p_memsz);
5191 internal->p_flags = BYTE_GET (external->p_flags);
5192 internal->p_align = BYTE_GET (external->p_align);
252b5132
RH
5193 }
5194
9ea033b2 5195 free (phdrs);
e0a31db1 5196 return TRUE;
252b5132
RH
5197}
5198
dda8d76d
NC
5199/* Read in the program headers from FILEDATA and store them in PHEADERS.
5200 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5201
e0a31db1 5202static bfd_boolean
dda8d76d 5203get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
9ea033b2 5204{
2cf0635d
NC
5205 Elf64_External_Phdr * phdrs;
5206 Elf64_External_Phdr * external;
5207 Elf_Internal_Phdr * internal;
b34976b6 5208 unsigned int i;
dda8d76d
NC
5209 unsigned int size = filedata->file_header.e_phentsize;
5210 unsigned int num = filedata->file_header.e_phnum;
e0a31db1
NC
5211
5212 /* PR binutils/17531: Cope with unexpected section header sizes. */
5213 if (size == 0 || num == 0)
5214 return FALSE;
5215 if (size < sizeof * phdrs)
5216 {
5217 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5218 return FALSE;
5219 }
5220 if (size > sizeof * phdrs)
5221 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
103f02d3 5222
dda8d76d 5223 phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
e0a31db1 5224 size, num, _("program headers"));
a6e9f9df 5225 if (!phdrs)
e0a31db1 5226 return FALSE;
9ea033b2 5227
91d6fa6a 5228 for (i = 0, internal = pheaders, external = phdrs;
dda8d76d 5229 i < filedata->file_header.e_phnum;
b34976b6 5230 i++, internal++, external++)
9ea033b2
NC
5231 {
5232 internal->p_type = BYTE_GET (external->p_type);
5233 internal->p_flags = BYTE_GET (external->p_flags);
66543521
AM
5234 internal->p_offset = BYTE_GET (external->p_offset);
5235 internal->p_vaddr = BYTE_GET (external->p_vaddr);
5236 internal->p_paddr = BYTE_GET (external->p_paddr);
5237 internal->p_filesz = BYTE_GET (external->p_filesz);
5238 internal->p_memsz = BYTE_GET (external->p_memsz);
5239 internal->p_align = BYTE_GET (external->p_align);
9ea033b2
NC
5240 }
5241
5242 free (phdrs);
e0a31db1 5243 return TRUE;
9ea033b2 5244}
252b5132 5245
32ec8896 5246/* Returns TRUE if the program headers were read into `program_headers'. */
d93f0186 5247
32ec8896 5248static bfd_boolean
dda8d76d 5249get_program_headers (Filedata * filedata)
d93f0186 5250{
2cf0635d 5251 Elf_Internal_Phdr * phdrs;
d93f0186
NC
5252
5253 /* Check cache of prior read. */
dda8d76d 5254 if (filedata->program_headers != NULL)
32ec8896 5255 return TRUE;
d93f0186 5256
82156ab7
NC
5257 /* Be kind to memory checkers by looking for
5258 e_phnum values which we know must be invalid. */
dda8d76d 5259 if (filedata->file_header.e_phnum
82156ab7 5260 * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr))
dda8d76d 5261 >= filedata->file_size)
82156ab7
NC
5262 {
5263 error (_("Too many program headers - %#x - the file is not that big\n"),
dda8d76d 5264 filedata->file_header.e_phnum);
82156ab7
NC
5265 return FALSE;
5266 }
d93f0186 5267
dda8d76d 5268 phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum,
82156ab7 5269 sizeof (Elf_Internal_Phdr));
d93f0186
NC
5270 if (phdrs == NULL)
5271 {
8b73c356 5272 error (_("Out of memory reading %u program headers\n"),
dda8d76d 5273 filedata->file_header.e_phnum);
32ec8896 5274 return FALSE;
d93f0186
NC
5275 }
5276
5277 if (is_32bit_elf
dda8d76d
NC
5278 ? get_32bit_program_headers (filedata, phdrs)
5279 : get_64bit_program_headers (filedata, phdrs))
d93f0186 5280 {
dda8d76d 5281 filedata->program_headers = phdrs;
32ec8896 5282 return TRUE;
d93f0186
NC
5283 }
5284
5285 free (phdrs);
32ec8896 5286 return FALSE;
d93f0186
NC
5287}
5288
32ec8896 5289/* Returns TRUE if the program headers were loaded. */
2f62977e 5290
32ec8896 5291static bfd_boolean
dda8d76d 5292process_program_headers (Filedata * filedata)
252b5132 5293{
2cf0635d 5294 Elf_Internal_Phdr * segment;
b34976b6 5295 unsigned int i;
1a9ccd70 5296 Elf_Internal_Phdr * previous_load = NULL;
252b5132 5297
978c4450
AM
5298 filedata->dynamic_addr = 0;
5299 filedata->dynamic_size = 0;
663f67df 5300
dda8d76d 5301 if (filedata->file_header.e_phnum == 0)
252b5132 5302 {
82f2dbf7 5303 /* PR binutils/12467. */
dda8d76d 5304 if (filedata->file_header.e_phoff != 0)
32ec8896
NC
5305 {
5306 warn (_("possibly corrupt ELF header - it has a non-zero program"
5307 " header offset, but no program headers\n"));
5308 return FALSE;
5309 }
82f2dbf7 5310 else if (do_segments)
ca0e11aa
NC
5311 {
5312 if (filedata->is_separate)
5313 printf (_("\nThere are no program headers in linked file '%s'.\n"),
5314 filedata->file_name);
5315 else
5316 printf (_("\nThere are no program headers in this file.\n"));
5317 }
32ec8896 5318 return TRUE;
252b5132
RH
5319 }
5320
5321 if (do_segments && !do_header)
5322 {
ca0e11aa
NC
5323 if (filedata->is_separate)
5324 printf ("\nIn linked file '%s' the ELF file type is %s\n",
5325 filedata->file_name,
5326 get_file_type (filedata->file_header.e_type));
5327 else
5328 printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type));
dda8d76d 5329 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry));
d3a49aa8
AM
5330 printf (ngettext ("There is %d program header, starting at offset %s\n",
5331 "There are %d program headers, starting at offset %s\n",
dda8d76d
NC
5332 filedata->file_header.e_phnum),
5333 filedata->file_header.e_phnum,
5334 bfd_vmatoa ("u", filedata->file_header.e_phoff));
252b5132
RH
5335 }
5336
dda8d76d 5337 if (! get_program_headers (filedata))
6b4bf3bc 5338 return TRUE;
103f02d3 5339
252b5132
RH
5340 if (do_segments)
5341 {
dda8d76d 5342 if (filedata->file_header.e_phnum > 1)
3a1a2036
NC
5343 printf (_("\nProgram Headers:\n"));
5344 else
5345 printf (_("\nProgram Headers:\n"));
76da6bbe 5346
f7a99963
NC
5347 if (is_32bit_elf)
5348 printf
5349 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
d974e256
JJ
5350 else if (do_wide)
5351 printf
5352 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
f7a99963
NC
5353 else
5354 {
5355 printf
5356 (_(" Type Offset VirtAddr PhysAddr\n"));
5357 printf
5358 (_(" FileSiz MemSiz Flags Align\n"));
5359 }
252b5132
RH
5360 }
5361
dda8d76d
NC
5362 for (i = 0, segment = filedata->program_headers;
5363 i < filedata->file_header.e_phnum;
b34976b6 5364 i++, segment++)
252b5132
RH
5365 {
5366 if (do_segments)
5367 {
dda8d76d 5368 printf (" %-14.14s ", get_segment_type (filedata, segment->p_type));
f7a99963
NC
5369
5370 if (is_32bit_elf)
5371 {
5372 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5373 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
5374 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
5375 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
5376 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
5377 printf ("%c%c%c ",
5378 (segment->p_flags & PF_R ? 'R' : ' '),
5379 (segment->p_flags & PF_W ? 'W' : ' '),
5380 (segment->p_flags & PF_X ? 'E' : ' '));
5381 printf ("%#lx", (unsigned long) segment->p_align);
5382 }
d974e256
JJ
5383 else if (do_wide)
5384 {
5385 if ((unsigned long) segment->p_offset == segment->p_offset)
5386 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5387 else
5388 {
5389 print_vma (segment->p_offset, FULL_HEX);
5390 putchar (' ');
5391 }
5392
5393 print_vma (segment->p_vaddr, FULL_HEX);
5394 putchar (' ');
5395 print_vma (segment->p_paddr, FULL_HEX);
5396 putchar (' ');
5397
5398 if ((unsigned long) segment->p_filesz == segment->p_filesz)
5399 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
5400 else
5401 {
5402 print_vma (segment->p_filesz, FULL_HEX);
5403 putchar (' ');
5404 }
5405
5406 if ((unsigned long) segment->p_memsz == segment->p_memsz)
5407 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
5408 else
5409 {
f48e6c45 5410 print_vma (segment->p_memsz, FULL_HEX);
d974e256
JJ
5411 }
5412
5413 printf (" %c%c%c ",
5414 (segment->p_flags & PF_R ? 'R' : ' '),
5415 (segment->p_flags & PF_W ? 'W' : ' '),
5416 (segment->p_flags & PF_X ? 'E' : ' '));
5417
5418 if ((unsigned long) segment->p_align == segment->p_align)
5419 printf ("%#lx", (unsigned long) segment->p_align);
5420 else
5421 {
5422 print_vma (segment->p_align, PREFIX_HEX);
5423 }
5424 }
f7a99963
NC
5425 else
5426 {
5427 print_vma (segment->p_offset, FULL_HEX);
5428 putchar (' ');
5429 print_vma (segment->p_vaddr, FULL_HEX);
5430 putchar (' ');
5431 print_vma (segment->p_paddr, FULL_HEX);
5432 printf ("\n ");
5433 print_vma (segment->p_filesz, FULL_HEX);
5434 putchar (' ');
5435 print_vma (segment->p_memsz, FULL_HEX);
5436 printf (" %c%c%c ",
5437 (segment->p_flags & PF_R ? 'R' : ' '),
5438 (segment->p_flags & PF_W ? 'W' : ' '),
5439 (segment->p_flags & PF_X ? 'E' : ' '));
1d262527 5440 print_vma (segment->p_align, PREFIX_HEX);
f7a99963 5441 }
252b5132 5442
1a9ccd70
NC
5443 putc ('\n', stdout);
5444 }
f54498b4 5445
252b5132
RH
5446 switch (segment->p_type)
5447 {
1a9ccd70 5448 case PT_LOAD:
502d895c
NC
5449#if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5450 required by the ELF standard, several programs, including the Linux
5451 kernel, make use of non-ordered segments. */
1a9ccd70
NC
5452 if (previous_load
5453 && previous_load->p_vaddr > segment->p_vaddr)
5454 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
502d895c 5455#endif
1a9ccd70
NC
5456 if (segment->p_memsz < segment->p_filesz)
5457 error (_("the segment's file size is larger than its memory size\n"));
5458 previous_load = segment;
5459 break;
5460
5461 case PT_PHDR:
5462 /* PR 20815 - Verify that the program header is loaded into memory. */
5463 if (i > 0 && previous_load != NULL)
5464 error (_("the PHDR segment must occur before any LOAD segment\n"));
dda8d76d 5465 if (filedata->file_header.e_machine != EM_PARISC)
1a9ccd70
NC
5466 {
5467 unsigned int j;
5468
dda8d76d 5469 for (j = 1; j < filedata->file_header.e_phnum; j++)
c0c121b0
AM
5470 {
5471 Elf_Internal_Phdr *load = filedata->program_headers + j;
5472 if (load->p_type == PT_LOAD
5473 && load->p_offset <= segment->p_offset
5474 && (load->p_offset + load->p_filesz
5475 >= segment->p_offset + segment->p_filesz)
5476 && load->p_vaddr <= segment->p_vaddr
5477 && (load->p_vaddr + load->p_filesz
5478 >= segment->p_vaddr + segment->p_filesz))
5479 break;
5480 }
dda8d76d 5481 if (j == filedata->file_header.e_phnum)
1a9ccd70
NC
5482 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5483 }
5484 break;
5485
252b5132 5486 case PT_DYNAMIC:
978c4450 5487 if (filedata->dynamic_addr)
252b5132
RH
5488 error (_("more than one dynamic segment\n"));
5489
20737c13
AM
5490 /* By default, assume that the .dynamic section is the first
5491 section in the DYNAMIC segment. */
978c4450
AM
5492 filedata->dynamic_addr = segment->p_offset;
5493 filedata->dynamic_size = segment->p_filesz;
20737c13 5494
b2d38a17
NC
5495 /* Try to locate the .dynamic section. If there is
5496 a section header table, we can easily locate it. */
dda8d76d 5497 if (filedata->section_headers != NULL)
b2d38a17 5498 {
2cf0635d 5499 Elf_Internal_Shdr * sec;
b2d38a17 5500
dda8d76d 5501 sec = find_section (filedata, ".dynamic");
89fac5e3 5502 if (sec == NULL || sec->sh_size == 0)
b2d38a17 5503 {
28f997cf
TG
5504 /* A corresponding .dynamic section is expected, but on
5505 IA-64/OpenVMS it is OK for it to be missing. */
dda8d76d 5506 if (!is_ia64_vms (filedata))
28f997cf 5507 error (_("no .dynamic section in the dynamic segment\n"));
b2d38a17
NC
5508 break;
5509 }
5510
42bb2e33 5511 if (sec->sh_type == SHT_NOBITS)
20737c13 5512 {
978c4450 5513 filedata->dynamic_size = 0;
20737c13
AM
5514 break;
5515 }
42bb2e33 5516
978c4450
AM
5517 filedata->dynamic_addr = sec->sh_offset;
5518 filedata->dynamic_size = sec->sh_size;
b2d38a17 5519
8ac10c5b
L
5520 /* The PT_DYNAMIC segment, which is used by the run-time
5521 loader, should exactly match the .dynamic section. */
5522 if (do_checks
5523 && (filedata->dynamic_addr != segment->p_offset
5524 || filedata->dynamic_size != segment->p_filesz))
5525 warn (_("\
5526the .dynamic section is not the same as the dynamic segment\n"));
b2d38a17 5527 }
39e224f6
MW
5528
5529 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5530 segment. Check this after matching against the section headers
5531 so we don't warn on debuginfo file (which have NOBITS .dynamic
5532 sections). */
978c4450
AM
5533 if (filedata->dynamic_addr > filedata->file_size
5534 || (filedata->dynamic_size
5535 > filedata->file_size - filedata->dynamic_addr))
39e224f6
MW
5536 {
5537 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
978c4450 5538 filedata->dynamic_addr = filedata->dynamic_size = 0;
39e224f6 5539 }
252b5132
RH
5540 break;
5541
5542 case PT_INTERP:
978c4450
AM
5543 if (fseek (filedata->handle,
5544 filedata->archive_file_offset + (long) segment->p_offset,
fb52b2f4 5545 SEEK_SET))
252b5132
RH
5546 error (_("Unable to find program interpreter name\n"));
5547 else
5548 {
f8eae8b2 5549 char fmt [32];
9495b2e6 5550 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
f8eae8b2
L
5551
5552 if (ret >= (int) sizeof (fmt) || ret < 0)
591a748a 5553 error (_("Internal error: failed to create format string to display program interpreter\n"));
f8eae8b2 5554
978c4450
AM
5555 filedata->program_interpreter[0] = 0;
5556 if (fscanf (filedata->handle, fmt,
5557 filedata->program_interpreter) <= 0)
7bd7b3ef 5558 error (_("Unable to read program interpreter name\n"));
252b5132
RH
5559
5560 if (do_segments)
f54498b4 5561 printf (_(" [Requesting program interpreter: %s]\n"),
978c4450 5562 filedata->program_interpreter);
252b5132
RH
5563 }
5564 break;
5565 }
252b5132
RH
5566 }
5567
dda8d76d
NC
5568 if (do_segments
5569 && filedata->section_headers != NULL
5570 && filedata->string_table != NULL)
252b5132
RH
5571 {
5572 printf (_("\n Section to Segment mapping:\n"));
5573 printf (_(" Segment Sections...\n"));
5574
dda8d76d 5575 for (i = 0; i < filedata->file_header.e_phnum; i++)
252b5132 5576 {
9ad5cbcf 5577 unsigned int j;
2cf0635d 5578 Elf_Internal_Shdr * section;
252b5132 5579
dda8d76d
NC
5580 segment = filedata->program_headers + i;
5581 section = filedata->section_headers + 1;
252b5132
RH
5582
5583 printf (" %2.2d ", i);
5584
dda8d76d 5585 for (j = 1; j < filedata->file_header.e_shnum; j++, section++)
252b5132 5586 {
f4638467
AM
5587 if (!ELF_TBSS_SPECIAL (section, segment)
5588 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
dda8d76d 5589 printf ("%s ", printable_section_name (filedata, section));
252b5132
RH
5590 }
5591
5592 putc ('\n',stdout);
5593 }
5594 }
5595
32ec8896 5596 return TRUE;
252b5132
RH
5597}
5598
5599
d93f0186
NC
5600/* Find the file offset corresponding to VMA by using the program headers. */
5601
5602static long
dda8d76d 5603offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size)
d93f0186 5604{
2cf0635d 5605 Elf_Internal_Phdr * seg;
d93f0186 5606
dda8d76d 5607 if (! get_program_headers (filedata))
d93f0186
NC
5608 {
5609 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5610 return (long) vma;
5611 }
5612
dda8d76d
NC
5613 for (seg = filedata->program_headers;
5614 seg < filedata->program_headers + filedata->file_header.e_phnum;
d93f0186
NC
5615 ++seg)
5616 {
5617 if (seg->p_type != PT_LOAD)
5618 continue;
5619
5620 if (vma >= (seg->p_vaddr & -seg->p_align)
5621 && vma + size <= seg->p_vaddr + seg->p_filesz)
5622 return vma - seg->p_vaddr + seg->p_offset;
5623 }
5624
5625 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
0af1713e 5626 (unsigned long) vma);
d93f0186
NC
5627 return (long) vma;
5628}
5629
5630
dda8d76d
NC
5631/* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5632 If PROBE is true, this is just a probe and we do not generate any error
5633 messages if the load fails. */
049b0c3a
NC
5634
5635static bfd_boolean
dda8d76d 5636get_32bit_section_headers (Filedata * filedata, bfd_boolean probe)
252b5132 5637{
2cf0635d
NC
5638 Elf32_External_Shdr * shdrs;
5639 Elf_Internal_Shdr * internal;
dda8d76d
NC
5640 unsigned int i;
5641 unsigned int size = filedata->file_header.e_shentsize;
5642 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
049b0c3a
NC
5643
5644 /* PR binutils/17531: Cope with unexpected section header sizes. */
5645 if (size == 0 || num == 0)
5646 return FALSE;
5647 if (size < sizeof * shdrs)
5648 {
5649 if (! probe)
5650 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5651 return FALSE;
5652 }
5653 if (!probe && size > sizeof * shdrs)
5654 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
252b5132 5655
dda8d76d 5656 shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff,
049b0c3a
NC
5657 size, num,
5658 probe ? NULL : _("section headers"));
5659 if (shdrs == NULL)
5660 return FALSE;
252b5132 5661
dda8d76d
NC
5662 free (filedata->section_headers);
5663 filedata->section_headers = (Elf_Internal_Shdr *)
5664 cmalloc (num, sizeof (Elf_Internal_Shdr));
5665 if (filedata->section_headers == NULL)
252b5132 5666 {
049b0c3a 5667 if (!probe)
8b73c356 5668 error (_("Out of memory reading %u section headers\n"), num);
e3d39609 5669 free (shdrs);
049b0c3a 5670 return FALSE;
252b5132
RH
5671 }
5672
dda8d76d 5673 for (i = 0, internal = filedata->section_headers;
560f3c1c 5674 i < num;
b34976b6 5675 i++, internal++)
252b5132
RH
5676 {
5677 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5678 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
5679 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5680 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5681 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5682 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5683 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5684 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5685 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
5686 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
315350be
NC
5687 if (!probe && internal->sh_link > num)
5688 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5689 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5690 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
252b5132
RH
5691 }
5692
5693 free (shdrs);
049b0c3a 5694 return TRUE;
252b5132
RH
5695}
5696
dda8d76d
NC
5697/* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5698
049b0c3a 5699static bfd_boolean
dda8d76d 5700get_64bit_section_headers (Filedata * filedata, bfd_boolean probe)
9ea033b2 5701{
dda8d76d
NC
5702 Elf64_External_Shdr * shdrs;
5703 Elf_Internal_Shdr * internal;
5704 unsigned int i;
5705 unsigned int size = filedata->file_header.e_shentsize;
5706 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
049b0c3a
NC
5707
5708 /* PR binutils/17531: Cope with unexpected section header sizes. */
5709 if (size == 0 || num == 0)
5710 return FALSE;
dda8d76d 5711
049b0c3a
NC
5712 if (size < sizeof * shdrs)
5713 {
5714 if (! probe)
5715 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5716 return FALSE;
5717 }
dda8d76d 5718
049b0c3a
NC
5719 if (! probe && size > sizeof * shdrs)
5720 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
9ea033b2 5721
dda8d76d
NC
5722 shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata,
5723 filedata->file_header.e_shoff,
049b0c3a
NC
5724 size, num,
5725 probe ? NULL : _("section headers"));
5726 if (shdrs == NULL)
5727 return FALSE;
9ea033b2 5728
dda8d76d
NC
5729 free (filedata->section_headers);
5730 filedata->section_headers = (Elf_Internal_Shdr *)
5731 cmalloc (num, sizeof (Elf_Internal_Shdr));
5732 if (filedata->section_headers == NULL)
9ea033b2 5733 {
049b0c3a 5734 if (! probe)
8b73c356 5735 error (_("Out of memory reading %u section headers\n"), num);
e3d39609 5736 free (shdrs);
049b0c3a 5737 return FALSE;
9ea033b2
NC
5738 }
5739
dda8d76d 5740 for (i = 0, internal = filedata->section_headers;
560f3c1c 5741 i < num;
b34976b6 5742 i++, internal++)
9ea033b2
NC
5743 {
5744 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5745 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
66543521
AM
5746 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5747 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5748 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5749 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
9ea033b2
NC
5750 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5751 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5752 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5753 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
315350be
NC
5754 if (!probe && internal->sh_link > num)
5755 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5756 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5757 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
9ea033b2
NC
5758 }
5759
5760 free (shdrs);
049b0c3a 5761 return TRUE;
9ea033b2
NC
5762}
5763
252b5132 5764static Elf_Internal_Sym *
dda8d76d
NC
5765get_32bit_elf_symbols (Filedata * filedata,
5766 Elf_Internal_Shdr * section,
5767 unsigned long * num_syms_return)
252b5132 5768{
ba5cdace 5769 unsigned long number = 0;
dd24e3da 5770 Elf32_External_Sym * esyms = NULL;
ba5cdace 5771 Elf_External_Sym_Shndx * shndx = NULL;
dd24e3da 5772 Elf_Internal_Sym * isyms = NULL;
2cf0635d 5773 Elf_Internal_Sym * psym;
b34976b6 5774 unsigned int j;
e3d39609 5775 elf_section_list * entry;
252b5132 5776
c9c1d674
EG
5777 if (section->sh_size == 0)
5778 {
5779 if (num_syms_return != NULL)
5780 * num_syms_return = 0;
5781 return NULL;
5782 }
5783
dd24e3da 5784 /* Run some sanity checks first. */
c9c1d674 5785 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
dd24e3da 5786 {
c9c1d674 5787 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
dda8d76d
NC
5788 printable_section_name (filedata, section),
5789 (unsigned long) section->sh_entsize);
ba5cdace 5790 goto exit_point;
dd24e3da
NC
5791 }
5792
dda8d76d 5793 if (section->sh_size > filedata->file_size)
f54498b4
NC
5794 {
5795 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
dda8d76d
NC
5796 printable_section_name (filedata, section),
5797 (unsigned long) section->sh_size);
f54498b4
NC
5798 goto exit_point;
5799 }
5800
dd24e3da
NC
5801 number = section->sh_size / section->sh_entsize;
5802
5803 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
5804 {
c9c1d674 5805 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
8066deb1 5806 (unsigned long) section->sh_size,
dda8d76d 5807 printable_section_name (filedata, section),
8066deb1 5808 (unsigned long) section->sh_entsize);
ba5cdace 5809 goto exit_point;
dd24e3da
NC
5810 }
5811
dda8d76d 5812 esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
3f5e193b 5813 section->sh_size, _("symbols"));
dd24e3da 5814 if (esyms == NULL)
ba5cdace 5815 goto exit_point;
252b5132 5816
e3d39609 5817 shndx = NULL;
978c4450 5818 for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next)
e3d39609
NC
5819 {
5820 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5821 continue;
5822
5823 if (shndx != NULL)
5824 {
5825 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5826 free (shndx);
5827 }
5828
5829 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5830 entry->hdr->sh_offset,
5831 1, entry->hdr->sh_size,
5832 _("symbol table section indices"));
5833 if (shndx == NULL)
5834 goto exit_point;
5835
5836 /* PR17531: file: heap-buffer-overflow */
5837 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5838 {
5839 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5840 printable_section_name (filedata, entry->hdr),
5841 (unsigned long) entry->hdr->sh_size,
5842 (unsigned long) section->sh_size);
5843 goto exit_point;
c9c1d674 5844 }
e3d39609 5845 }
9ad5cbcf 5846
3f5e193b 5847 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
252b5132
RH
5848
5849 if (isyms == NULL)
5850 {
8b73c356
NC
5851 error (_("Out of memory reading %lu symbols\n"),
5852 (unsigned long) number);
dd24e3da 5853 goto exit_point;
252b5132
RH
5854 }
5855
dd24e3da 5856 for (j = 0, psym = isyms; j < number; j++, psym++)
252b5132
RH
5857 {
5858 psym->st_name = BYTE_GET (esyms[j].st_name);
5859 psym->st_value = BYTE_GET (esyms[j].st_value);
5860 psym->st_size = BYTE_GET (esyms[j].st_size);
5861 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
4fbb74a6 5862 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
9ad5cbcf
AM
5863 psym->st_shndx
5864 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4fbb74a6
AM
5865 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5866 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
252b5132
RH
5867 psym->st_info = BYTE_GET (esyms[j].st_info);
5868 psym->st_other = BYTE_GET (esyms[j].st_other);
5869 }
5870
dd24e3da 5871 exit_point:
e3d39609
NC
5872 free (shndx);
5873 free (esyms);
252b5132 5874
ba5cdace
NC
5875 if (num_syms_return != NULL)
5876 * num_syms_return = isyms == NULL ? 0 : number;
5877
252b5132
RH
5878 return isyms;
5879}
5880
9ea033b2 5881static Elf_Internal_Sym *
dda8d76d
NC
5882get_64bit_elf_symbols (Filedata * filedata,
5883 Elf_Internal_Shdr * section,
5884 unsigned long * num_syms_return)
9ea033b2 5885{
ba5cdace
NC
5886 unsigned long number = 0;
5887 Elf64_External_Sym * esyms = NULL;
5888 Elf_External_Sym_Shndx * shndx = NULL;
5889 Elf_Internal_Sym * isyms = NULL;
2cf0635d 5890 Elf_Internal_Sym * psym;
b34976b6 5891 unsigned int j;
e3d39609 5892 elf_section_list * entry;
9ea033b2 5893
c9c1d674
EG
5894 if (section->sh_size == 0)
5895 {
5896 if (num_syms_return != NULL)
5897 * num_syms_return = 0;
5898 return NULL;
5899 }
5900
dd24e3da 5901 /* Run some sanity checks first. */
c9c1d674 5902 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
dd24e3da 5903 {
c9c1d674 5904 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
dda8d76d 5905 printable_section_name (filedata, section),
8066deb1 5906 (unsigned long) section->sh_entsize);
ba5cdace 5907 goto exit_point;
dd24e3da
NC
5908 }
5909
dda8d76d 5910 if (section->sh_size > filedata->file_size)
f54498b4
NC
5911 {
5912 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
dda8d76d 5913 printable_section_name (filedata, section),
8066deb1 5914 (unsigned long) section->sh_size);
f54498b4
NC
5915 goto exit_point;
5916 }
5917
dd24e3da
NC
5918 number = section->sh_size / section->sh_entsize;
5919
5920 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
5921 {
c9c1d674 5922 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
8066deb1 5923 (unsigned long) section->sh_size,
dda8d76d 5924 printable_section_name (filedata, section),
8066deb1 5925 (unsigned long) section->sh_entsize);
ba5cdace 5926 goto exit_point;
dd24e3da
NC
5927 }
5928
dda8d76d 5929 esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
3f5e193b 5930 section->sh_size, _("symbols"));
a6e9f9df 5931 if (!esyms)
ba5cdace 5932 goto exit_point;
9ea033b2 5933
e3d39609 5934 shndx = NULL;
978c4450 5935 for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next)
e3d39609
NC
5936 {
5937 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5938 continue;
5939
5940 if (shndx != NULL)
5941 {
5942 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5943 free (shndx);
c9c1d674 5944 }
e3d39609
NC
5945
5946 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5947 entry->hdr->sh_offset,
5948 1, entry->hdr->sh_size,
5949 _("symbol table section indices"));
5950 if (shndx == NULL)
5951 goto exit_point;
5952
5953 /* PR17531: file: heap-buffer-overflow */
5954 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5955 {
5956 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5957 printable_section_name (filedata, entry->hdr),
5958 (unsigned long) entry->hdr->sh_size,
5959 (unsigned long) section->sh_size);
5960 goto exit_point;
5961 }
5962 }
9ad5cbcf 5963
3f5e193b 5964 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
9ea033b2
NC
5965
5966 if (isyms == NULL)
5967 {
8b73c356
NC
5968 error (_("Out of memory reading %lu symbols\n"),
5969 (unsigned long) number);
ba5cdace 5970 goto exit_point;
9ea033b2
NC
5971 }
5972
ba5cdace 5973 for (j = 0, psym = isyms; j < number; j++, psym++)
9ea033b2
NC
5974 {
5975 psym->st_name = BYTE_GET (esyms[j].st_name);
5976 psym->st_info = BYTE_GET (esyms[j].st_info);
5977 psym->st_other = BYTE_GET (esyms[j].st_other);
5978 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
ba5cdace 5979
4fbb74a6 5980 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
9ad5cbcf
AM
5981 psym->st_shndx
5982 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4fbb74a6
AM
5983 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5984 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
ba5cdace 5985
66543521
AM
5986 psym->st_value = BYTE_GET (esyms[j].st_value);
5987 psym->st_size = BYTE_GET (esyms[j].st_size);
9ea033b2
NC
5988 }
5989
ba5cdace 5990 exit_point:
e3d39609
NC
5991 free (shndx);
5992 free (esyms);
ba5cdace
NC
5993
5994 if (num_syms_return != NULL)
5995 * num_syms_return = isyms == NULL ? 0 : number;
9ea033b2
NC
5996
5997 return isyms;
5998}
5999
d1133906 6000static const char *
dda8d76d 6001get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
d1133906 6002{
5477e8a0 6003 static char buff[1024];
2cf0635d 6004 char * p = buff;
32ec8896
NC
6005 unsigned int field_size = is_32bit_elf ? 8 : 16;
6006 signed int sindex;
6007 unsigned int size = sizeof (buff) - (field_size + 4 + 1);
8d5ff12c
L
6008 bfd_vma os_flags = 0;
6009 bfd_vma proc_flags = 0;
6010 bfd_vma unknown_flags = 0;
148b93f2 6011 static const struct
5477e8a0 6012 {
2cf0635d 6013 const char * str;
32ec8896 6014 unsigned int len;
5477e8a0
L
6015 }
6016 flags [] =
6017 {
cfcac11d
NC
6018 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
6019 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
6020 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
6021 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
6022 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
6023 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
6024 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
6025 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
6026 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
6027 /* 9 */ { STRING_COMMA_LEN ("TLS") },
6028 /* IA-64 specific. */
6029 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
6030 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
6031 /* IA-64 OpenVMS specific. */
6032 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
6033 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
6034 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
6035 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
6036 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
6037 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
18ae9cc1 6038 /* Generic. */
cfcac11d 6039 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
18ae9cc1 6040 /* SPARC specific. */
77115a4a 6041 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
ac4c9b04
MG
6042 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
6043 /* ARM specific. */
6044 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
f0728ee3 6045 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
a91e1603
L
6046 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
6047 /* GNU specific. */
6048 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
83eef883
AFB
6049 /* VLE specific. */
6050 /* 25 */ { STRING_COMMA_LEN ("VLE") },
99fabbc9
JL
6051 /* GNU specific. */
6052 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
5477e8a0
L
6053 };
6054
6055 if (do_section_details)
6056 {
8d5ff12c
L
6057 sprintf (buff, "[%*.*lx]: ",
6058 field_size, field_size, (unsigned long) sh_flags);
6059 p += field_size + 4;
5477e8a0 6060 }
76da6bbe 6061
d1133906
NC
6062 while (sh_flags)
6063 {
6064 bfd_vma flag;
6065
6066 flag = sh_flags & - sh_flags;
6067 sh_flags &= ~ flag;
76da6bbe 6068
5477e8a0 6069 if (do_section_details)
d1133906 6070 {
5477e8a0
L
6071 switch (flag)
6072 {
91d6fa6a
NC
6073 case SHF_WRITE: sindex = 0; break;
6074 case SHF_ALLOC: sindex = 1; break;
6075 case SHF_EXECINSTR: sindex = 2; break;
6076 case SHF_MERGE: sindex = 3; break;
6077 case SHF_STRINGS: sindex = 4; break;
6078 case SHF_INFO_LINK: sindex = 5; break;
6079 case SHF_LINK_ORDER: sindex = 6; break;
6080 case SHF_OS_NONCONFORMING: sindex = 7; break;
6081 case SHF_GROUP: sindex = 8; break;
6082 case SHF_TLS: sindex = 9; break;
18ae9cc1 6083 case SHF_EXCLUDE: sindex = 18; break;
77115a4a 6084 case SHF_COMPRESSED: sindex = 20; break;
76da6bbe 6085
5477e8a0 6086 default:
91d6fa6a 6087 sindex = -1;
dda8d76d 6088 switch (filedata->file_header.e_machine)
148b93f2 6089 {
cfcac11d 6090 case EM_IA_64:
148b93f2 6091 if (flag == SHF_IA_64_SHORT)
91d6fa6a 6092 sindex = 10;
148b93f2 6093 else if (flag == SHF_IA_64_NORECOV)
91d6fa6a 6094 sindex = 11;
148b93f2 6095#ifdef BFD64
dda8d76d 6096 else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
148b93f2
NC
6097 switch (flag)
6098 {
91d6fa6a
NC
6099 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
6100 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
6101 case SHF_IA_64_VMS_SHARED: sindex = 14; break;
6102 case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
6103 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
6104 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
148b93f2
NC
6105 default: break;
6106 }
6107#endif
cfcac11d
NC
6108 break;
6109
caa83f8b 6110 case EM_386:
22abe556 6111 case EM_IAMCU:
caa83f8b 6112 case EM_X86_64:
7f502d6c 6113 case EM_L1OM:
7a9068fe 6114 case EM_K1OM:
cfcac11d
NC
6115 case EM_OLD_SPARCV9:
6116 case EM_SPARC32PLUS:
6117 case EM_SPARCV9:
6118 case EM_SPARC:
18ae9cc1 6119 if (flag == SHF_ORDERED)
91d6fa6a 6120 sindex = 19;
cfcac11d 6121 break;
ac4c9b04
MG
6122
6123 case EM_ARM:
6124 switch (flag)
6125 {
6126 case SHF_ENTRYSECT: sindex = 21; break;
f0728ee3 6127 case SHF_ARM_PURECODE: sindex = 22; break;
ac4c9b04
MG
6128 case SHF_COMDEF: sindex = 23; break;
6129 default: break;
6130 }
6131 break;
83eef883
AFB
6132 case EM_PPC:
6133 if (flag == SHF_PPC_VLE)
6134 sindex = 25;
6135 break;
99fabbc9
JL
6136 default:
6137 break;
6138 }
ac4c9b04 6139
99fabbc9
JL
6140 switch (filedata->file_header.e_ident[EI_OSABI])
6141 {
6142 case ELFOSABI_GNU:
6143 case ELFOSABI_FREEBSD:
6144 if (flag == SHF_GNU_RETAIN)
6145 sindex = 26;
6146 /* Fall through */
6147 case ELFOSABI_NONE:
6148 if (flag == SHF_GNU_MBIND)
6149 /* We should not recognize SHF_GNU_MBIND for
6150 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6151 not set the EI_OSABI header byte. */
6152 sindex = 24;
6153 break;
cfcac11d
NC
6154 default:
6155 break;
148b93f2 6156 }
99fabbc9 6157 break;
5477e8a0
L
6158 }
6159
91d6fa6a 6160 if (sindex != -1)
5477e8a0 6161 {
8d5ff12c
L
6162 if (p != buff + field_size + 4)
6163 {
6164 if (size < (10 + 2))
bee0ee85
NC
6165 {
6166 warn (_("Internal error: not enough buffer room for section flag info"));
6167 return _("<unknown>");
6168 }
8d5ff12c
L
6169 size -= 2;
6170 *p++ = ',';
6171 *p++ = ' ';
6172 }
6173
91d6fa6a
NC
6174 size -= flags [sindex].len;
6175 p = stpcpy (p, flags [sindex].str);
5477e8a0 6176 }
3b22753a 6177 else if (flag & SHF_MASKOS)
8d5ff12c 6178 os_flags |= flag;
d1133906 6179 else if (flag & SHF_MASKPROC)
8d5ff12c 6180 proc_flags |= flag;
d1133906 6181 else
8d5ff12c 6182 unknown_flags |= flag;
5477e8a0
L
6183 }
6184 else
6185 {
6186 switch (flag)
6187 {
6188 case SHF_WRITE: *p = 'W'; break;
6189 case SHF_ALLOC: *p = 'A'; break;
6190 case SHF_EXECINSTR: *p = 'X'; break;
6191 case SHF_MERGE: *p = 'M'; break;
6192 case SHF_STRINGS: *p = 'S'; break;
6193 case SHF_INFO_LINK: *p = 'I'; break;
6194 case SHF_LINK_ORDER: *p = 'L'; break;
6195 case SHF_OS_NONCONFORMING: *p = 'O'; break;
6196 case SHF_GROUP: *p = 'G'; break;
6197 case SHF_TLS: *p = 'T'; break;
18ae9cc1 6198 case SHF_EXCLUDE: *p = 'E'; break;
77115a4a 6199 case SHF_COMPRESSED: *p = 'C'; break;
5477e8a0
L
6200
6201 default:
dda8d76d
NC
6202 if ((filedata->file_header.e_machine == EM_X86_64
6203 || filedata->file_header.e_machine == EM_L1OM
6204 || filedata->file_header.e_machine == EM_K1OM)
5477e8a0
L
6205 && flag == SHF_X86_64_LARGE)
6206 *p = 'l';
dda8d76d 6207 else if (filedata->file_header.e_machine == EM_ARM
f0728ee3 6208 && flag == SHF_ARM_PURECODE)
99fabbc9 6209 *p = 'y';
dda8d76d 6210 else if (filedata->file_header.e_machine == EM_PPC
83eef883 6211 && flag == SHF_PPC_VLE)
99fabbc9 6212 *p = 'v';
5477e8a0
L
6213 else if (flag & SHF_MASKOS)
6214 {
99fabbc9
JL
6215 switch (filedata->file_header.e_ident[EI_OSABI])
6216 {
6217 case ELFOSABI_GNU:
6218 case ELFOSABI_FREEBSD:
6219 if (flag == SHF_GNU_RETAIN)
6220 {
6221 *p = 'R';
6222 break;
6223 }
6224 /* Fall through */
6225 case ELFOSABI_NONE:
6226 if (flag == SHF_GNU_MBIND)
6227 {
6228 /* We should not recognize SHF_GNU_MBIND for
6229 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6230 not set the EI_OSABI header byte. */
6231 *p = 'D';
6232 break;
6233 }
6234 /* Fall through */
6235 default:
6236 *p = 'o';
6237 sh_flags &= ~SHF_MASKOS;
6238 break;
6239 }
5477e8a0
L
6240 }
6241 else if (flag & SHF_MASKPROC)
6242 {
6243 *p = 'p';
6244 sh_flags &= ~ SHF_MASKPROC;
6245 }
6246 else
6247 *p = 'x';
6248 break;
6249 }
6250 p++;
d1133906
NC
6251 }
6252 }
76da6bbe 6253
8d5ff12c
L
6254 if (do_section_details)
6255 {
6256 if (os_flags)
6257 {
6258 size -= 5 + field_size;
6259 if (p != buff + field_size + 4)
6260 {
6261 if (size < (2 + 1))
bee0ee85
NC
6262 {
6263 warn (_("Internal error: not enough buffer room for section flag info"));
6264 return _("<unknown>");
6265 }
8d5ff12c
L
6266 size -= 2;
6267 *p++ = ',';
6268 *p++ = ' ';
6269 }
6270 sprintf (p, "OS (%*.*lx)", field_size, field_size,
6271 (unsigned long) os_flags);
6272 p += 5 + field_size;
6273 }
6274 if (proc_flags)
6275 {
6276 size -= 7 + field_size;
6277 if (p != buff + field_size + 4)
6278 {
6279 if (size < (2 + 1))
bee0ee85
NC
6280 {
6281 warn (_("Internal error: not enough buffer room for section flag info"));
6282 return _("<unknown>");
6283 }
8d5ff12c
L
6284 size -= 2;
6285 *p++ = ',';
6286 *p++ = ' ';
6287 }
6288 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
6289 (unsigned long) proc_flags);
6290 p += 7 + field_size;
6291 }
6292 if (unknown_flags)
6293 {
6294 size -= 10 + field_size;
6295 if (p != buff + field_size + 4)
6296 {
6297 if (size < (2 + 1))
bee0ee85
NC
6298 {
6299 warn (_("Internal error: not enough buffer room for section flag info"));
6300 return _("<unknown>");
6301 }
8d5ff12c
L
6302 size -= 2;
6303 *p++ = ',';
6304 *p++ = ' ';
6305 }
2b692964 6306 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
8d5ff12c
L
6307 (unsigned long) unknown_flags);
6308 p += 10 + field_size;
6309 }
6310 }
6311
e9e44622 6312 *p = '\0';
d1133906
NC
6313 return buff;
6314}
6315
5844b465 6316static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
ebdf1ebf 6317get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size)
77115a4a
L
6318{
6319 if (is_32bit_elf)
6320 {
6321 Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
d8024a91 6322
ebdf1ebf
NC
6323 if (size < sizeof (* echdr))
6324 {
6325 error (_("Compressed section is too small even for a compression header\n"));
6326 return 0;
6327 }
6328
77115a4a
L
6329 chdr->ch_type = BYTE_GET (echdr->ch_type);
6330 chdr->ch_size = BYTE_GET (echdr->ch_size);
6331 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6332 return sizeof (*echdr);
6333 }
6334 else
6335 {
6336 Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
d8024a91 6337
ebdf1ebf
NC
6338 if (size < sizeof (* echdr))
6339 {
6340 error (_("Compressed section is too small even for a compression header\n"));
6341 return 0;
6342 }
6343
77115a4a
L
6344 chdr->ch_type = BYTE_GET (echdr->ch_type);
6345 chdr->ch_size = BYTE_GET (echdr->ch_size);
6346 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6347 return sizeof (*echdr);
6348 }
6349}
6350
32ec8896 6351static bfd_boolean
dda8d76d 6352process_section_headers (Filedata * filedata)
252b5132 6353{
2cf0635d 6354 Elf_Internal_Shdr * section;
b34976b6 6355 unsigned int i;
252b5132 6356
8fb879cd 6357 free (filedata->section_headers);
dda8d76d 6358 filedata->section_headers = NULL;
978c4450
AM
6359 free (filedata->dynamic_symbols);
6360 filedata->dynamic_symbols = NULL;
6361 filedata->num_dynamic_syms = 0;
6362 free (filedata->dynamic_strings);
6363 filedata->dynamic_strings = NULL;
6364 filedata->dynamic_strings_length = 0;
6365 free (filedata->dynamic_syminfo);
6366 filedata->dynamic_syminfo = NULL;
6367 while (filedata->symtab_shndx_list != NULL)
8ff66993 6368 {
978c4450
AM
6369 elf_section_list *next = filedata->symtab_shndx_list->next;
6370 free (filedata->symtab_shndx_list);
6371 filedata->symtab_shndx_list = next;
8ff66993 6372 }
252b5132 6373
dda8d76d 6374 if (filedata->file_header.e_shnum == 0)
252b5132 6375 {
82f2dbf7 6376 /* PR binutils/12467. */
dda8d76d 6377 if (filedata->file_header.e_shoff != 0)
32ec8896
NC
6378 {
6379 warn (_("possibly corrupt ELF file header - it has a non-zero"
6380 " section header offset, but no section headers\n"));
6381 return FALSE;
6382 }
82f2dbf7 6383 else if (do_sections)
252b5132
RH
6384 printf (_("\nThere are no sections in this file.\n"));
6385
32ec8896 6386 return TRUE;
252b5132
RH
6387 }
6388
6389 if (do_sections && !do_header)
ca0e11aa
NC
6390 {
6391 if (filedata->is_separate && process_links)
6392 printf (_("In linked file '%s': "), filedata->file_name);
6393 if (! filedata->is_separate || process_links)
6394 printf (ngettext ("There is %d section header, "
6395 "starting at offset 0x%lx:\n",
6396 "There are %d section headers, "
6397 "starting at offset 0x%lx:\n",
6398 filedata->file_header.e_shnum),
6399 filedata->file_header.e_shnum,
6400 (unsigned long) filedata->file_header.e_shoff);
6401 }
252b5132 6402
9ea033b2
NC
6403 if (is_32bit_elf)
6404 {
dda8d76d 6405 if (! get_32bit_section_headers (filedata, FALSE))
32ec8896
NC
6406 return FALSE;
6407 }
6408 else
6409 {
dda8d76d 6410 if (! get_64bit_section_headers (filedata, FALSE))
32ec8896 6411 return FALSE;
9ea033b2 6412 }
252b5132
RH
6413
6414 /* Read in the string table, so that we have names to display. */
dda8d76d
NC
6415 if (filedata->file_header.e_shstrndx != SHN_UNDEF
6416 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
252b5132 6417 {
dda8d76d 6418 section = filedata->section_headers + filedata->file_header.e_shstrndx;
d40ac9bd 6419
c256ffe7
JJ
6420 if (section->sh_size != 0)
6421 {
dda8d76d
NC
6422 filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset,
6423 1, section->sh_size,
6424 _("string table"));
0de14b54 6425
dda8d76d 6426 filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0;
c256ffe7 6427 }
252b5132
RH
6428 }
6429
6430 /* Scan the sections for the dynamic symbol table
e3c8793a 6431 and dynamic string table and debug sections. */
89fac5e3 6432 eh_addr_size = is_32bit_elf ? 4 : 8;
dda8d76d 6433 switch (filedata->file_header.e_machine)
89fac5e3
RS
6434 {
6435 case EM_MIPS:
6436 case EM_MIPS_RS3_LE:
6437 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6438 FDE addresses. However, the ABI also has a semi-official ILP32
6439 variant for which the normal FDE address size rules apply.
6440
6441 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6442 section, where XX is the size of longs in bits. Unfortunately,
6443 earlier compilers provided no way of distinguishing ILP32 objects
6444 from LP64 objects, so if there's any doubt, we should assume that
6445 the official LP64 form is being used. */
dda8d76d
NC
6446 if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
6447 && find_section (filedata, ".gcc_compiled_long32") == NULL)
89fac5e3
RS
6448 eh_addr_size = 8;
6449 break;
0f56a26a
DD
6450
6451 case EM_H8_300:
6452 case EM_H8_300H:
dda8d76d 6453 switch (filedata->file_header.e_flags & EF_H8_MACH)
0f56a26a
DD
6454 {
6455 case E_H8_MACH_H8300:
6456 case E_H8_MACH_H8300HN:
6457 case E_H8_MACH_H8300SN:
6458 case E_H8_MACH_H8300SXN:
6459 eh_addr_size = 2;
6460 break;
6461 case E_H8_MACH_H8300H:
6462 case E_H8_MACH_H8300S:
6463 case E_H8_MACH_H8300SX:
6464 eh_addr_size = 4;
6465 break;
6466 }
f4236fe4
DD
6467 break;
6468
ff7eeb89 6469 case EM_M32C_OLD:
f4236fe4 6470 case EM_M32C:
dda8d76d 6471 switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK)
f4236fe4
DD
6472 {
6473 case EF_M32C_CPU_M16C:
6474 eh_addr_size = 2;
6475 break;
6476 }
6477 break;
89fac5e3
RS
6478 }
6479
76ca31c0
NC
6480#define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6481 do \
6482 { \
6483 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6484 if (section->sh_entsize != expected_entsize) \
9dd3a467 6485 { \
76ca31c0
NC
6486 char buf[40]; \
6487 sprintf_vma (buf, section->sh_entsize); \
6488 /* Note: coded this way so that there is a single string for \
6489 translation. */ \
6490 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6491 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6492 (unsigned) expected_entsize); \
9dd3a467 6493 section->sh_entsize = expected_entsize; \
76ca31c0
NC
6494 } \
6495 } \
08d8fa11 6496 while (0)
9dd3a467
NC
6497
6498#define CHECK_ENTSIZE(section, i, type) \
1b513401 6499 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
08d8fa11
JJ
6500 sizeof (Elf64_External_##type))
6501
dda8d76d
NC
6502 for (i = 0, section = filedata->section_headers;
6503 i < filedata->file_header.e_shnum;
b34976b6 6504 i++, section++)
252b5132 6505 {
b9e920ec 6506 char * name = SECTION_NAME_PRINT (section);
252b5132 6507
1b513401
NC
6508 /* Run some sanity checks on the headers and
6509 possibly fill in some file data as well. */
6510 switch (section->sh_type)
252b5132 6511 {
1b513401 6512 case SHT_DYNSYM:
978c4450 6513 if (filedata->dynamic_symbols != NULL)
252b5132
RH
6514 {
6515 error (_("File contains multiple dynamic symbol tables\n"));
6516 continue;
6517 }
6518
08d8fa11 6519 CHECK_ENTSIZE (section, i, Sym);
978c4450
AM
6520 filedata->dynamic_symbols
6521 = GET_ELF_SYMBOLS (filedata, section, &filedata->num_dynamic_syms);
8ac10c5b 6522 filedata->dynamic_symtab_section = section;
1b513401
NC
6523 break;
6524
6525 case SHT_STRTAB:
6526 if (streq (name, ".dynstr"))
252b5132 6527 {
1b513401
NC
6528 if (filedata->dynamic_strings != NULL)
6529 {
6530 error (_("File contains multiple dynamic string tables\n"));
6531 continue;
6532 }
6533
6534 filedata->dynamic_strings
6535 = (char *) get_data (NULL, filedata, section->sh_offset,
6536 1, section->sh_size, _("dynamic strings"));
6537 filedata->dynamic_strings_length
6538 = filedata->dynamic_strings == NULL ? 0 : section->sh_size;
8ac10c5b 6539 filedata->dynamic_strtab_section = section;
252b5132 6540 }
1b513401
NC
6541 break;
6542
6543 case SHT_SYMTAB_SHNDX:
6544 {
6545 elf_section_list * entry = xmalloc (sizeof * entry);
6546
6547 entry->hdr = section;
6548 entry->next = filedata->symtab_shndx_list;
6549 filedata->symtab_shndx_list = entry;
6550 }
6551 break;
6552
6553 case SHT_SYMTAB:
6554 CHECK_ENTSIZE (section, i, Sym);
6555 break;
6556
6557 case SHT_GROUP:
6558 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
6559 break;
252b5132 6560
1b513401
NC
6561 case SHT_REL:
6562 CHECK_ENTSIZE (section, i, Rel);
546cb2d8 6563 if (do_checks && section->sh_size == 0)
1b513401
NC
6564 warn (_("Section '%s': zero-sized relocation section\n"), name);
6565 break;
6566
6567 case SHT_RELA:
6568 CHECK_ENTSIZE (section, i, Rela);
546cb2d8 6569 if (do_checks && section->sh_size == 0)
1b513401
NC
6570 warn (_("Section '%s': zero-sized relocation section\n"), name);
6571 break;
6572
6573 case SHT_NOTE:
6574 case SHT_PROGBITS:
546cb2d8
NC
6575 /* Having a zero sized section is not illegal according to the
6576 ELF standard, but it might be an indication that something
6577 is wrong. So issue a warning if we are running in lint mode. */
6578 if (do_checks && section->sh_size == 0)
1b513401
NC
6579 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name);
6580 break;
6581
6582 default:
6583 break;
6584 }
6585
6586 if ((do_debugging || do_debug_info || do_debug_abbrevs
6587 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
6588 || do_debug_aranges || do_debug_frames || do_debug_macinfo
e38332c2
NC
6589 || do_debug_str || do_debug_str_offsets || do_debug_loc
6590 || do_debug_ranges
1b513401
NC
6591 || do_debug_addr || do_debug_cu_index || do_debug_links)
6592 && (const_strneq (name, ".debug_")
6593 || const_strneq (name, ".zdebug_")))
252b5132 6594 {
1b315056
CS
6595 if (name[1] == 'z')
6596 name += sizeof (".zdebug_") - 1;
6597 else
6598 name += sizeof (".debug_") - 1;
252b5132
RH
6599
6600 if (do_debugging
4723351a
CC
6601 || (do_debug_info && const_strneq (name, "info"))
6602 || (do_debug_info && const_strneq (name, "types"))
6603 || (do_debug_abbrevs && const_strneq (name, "abbrev"))
b40bf0a2
NC
6604 || (do_debug_lines && strcmp (name, "line") == 0)
6605 || (do_debug_lines && const_strneq (name, "line."))
4723351a
CC
6606 || (do_debug_pubnames && const_strneq (name, "pubnames"))
6607 || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
459d52c8
DE
6608 || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
6609 || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
4723351a
CC
6610 || (do_debug_aranges && const_strneq (name, "aranges"))
6611 || (do_debug_ranges && const_strneq (name, "ranges"))
77145576 6612 || (do_debug_ranges && const_strneq (name, "rnglists"))
4723351a
CC
6613 || (do_debug_frames && const_strneq (name, "frame"))
6614 || (do_debug_macinfo && const_strneq (name, "macinfo"))
6615 || (do_debug_macinfo && const_strneq (name, "macro"))
6616 || (do_debug_str && const_strneq (name, "str"))
e38332c2 6617 || (do_debug_links && const_strneq (name, "sup"))
e4b7104b 6618 || (do_debug_str_offsets && const_strneq (name, "str_offsets"))
4723351a 6619 || (do_debug_loc && const_strneq (name, "loc"))
77145576 6620 || (do_debug_loc && const_strneq (name, "loclists"))
657d0d47
CC
6621 || (do_debug_addr && const_strneq (name, "addr"))
6622 || (do_debug_cu_index && const_strneq (name, "cu_index"))
6623 || (do_debug_cu_index && const_strneq (name, "tu_index"))
252b5132 6624 )
6431e409 6625 request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
252b5132 6626 }
a262ae96 6627 /* Linkonce section to be combined with .debug_info at link time. */
09fd7e38 6628 else if ((do_debugging || do_debug_info)
0112cd26 6629 && const_strneq (name, ".gnu.linkonce.wi."))
6431e409 6630 request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
18bd398b 6631 else if (do_debug_frames && streq (name, ".eh_frame"))
6431e409 6632 request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
61364358
JK
6633 else if (do_gdb_index && (streq (name, ".gdb_index")
6634 || streq (name, ".debug_names")))
6431e409 6635 request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
6f875884
TG
6636 /* Trace sections for Itanium VMS. */
6637 else if ((do_debugging || do_trace_info || do_trace_abbrevs
6638 || do_trace_aranges)
6639 && const_strneq (name, ".trace_"))
6640 {
6641 name += sizeof (".trace_") - 1;
6642
6643 if (do_debugging
6644 || (do_trace_info && streq (name, "info"))
6645 || (do_trace_abbrevs && streq (name, "abbrev"))
6646 || (do_trace_aranges && streq (name, "aranges"))
6647 )
6431e409 6648 request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
6f875884 6649 }
dda8d76d
NC
6650 else if ((do_debugging || do_debug_links)
6651 && (const_strneq (name, ".gnu_debuglink")
6652 || const_strneq (name, ".gnu_debugaltlink")))
6431e409 6653 request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
252b5132
RH
6654 }
6655
6656 if (! do_sections)
32ec8896 6657 return TRUE;
252b5132 6658
ca0e11aa
NC
6659 if (filedata->is_separate && ! process_links)
6660 return TRUE;
6661
6662 if (filedata->is_separate)
6663 printf (_("\nSection Headers in linked file '%s':\n"), filedata->file_name);
6664 else if (filedata->file_header.e_shnum > 1)
3a1a2036
NC
6665 printf (_("\nSection Headers:\n"));
6666 else
6667 printf (_("\nSection Header:\n"));
76da6bbe 6668
f7a99963 6669 if (is_32bit_elf)
595cf52e 6670 {
5477e8a0 6671 if (do_section_details)
595cf52e
L
6672 {
6673 printf (_(" [Nr] Name\n"));
5477e8a0 6674 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
595cf52e
L
6675 }
6676 else
6677 printf
6678 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6679 }
d974e256 6680 else if (do_wide)
595cf52e 6681 {
5477e8a0 6682 if (do_section_details)
595cf52e
L
6683 {
6684 printf (_(" [Nr] Name\n"));
5477e8a0 6685 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
595cf52e
L
6686 }
6687 else
6688 printf
6689 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6690 }
f7a99963
NC
6691 else
6692 {
5477e8a0 6693 if (do_section_details)
595cf52e
L
6694 {
6695 printf (_(" [Nr] Name\n"));
5477e8a0
L
6696 printf (_(" Type Address Offset Link\n"));
6697 printf (_(" Size EntSize Info Align\n"));
595cf52e
L
6698 }
6699 else
6700 {
6701 printf (_(" [Nr] Name Type Address Offset\n"));
6702 printf (_(" Size EntSize Flags Link Info Align\n"));
6703 }
f7a99963 6704 }
252b5132 6705
5477e8a0
L
6706 if (do_section_details)
6707 printf (_(" Flags\n"));
6708
dda8d76d
NC
6709 for (i = 0, section = filedata->section_headers;
6710 i < filedata->file_header.e_shnum;
b34976b6 6711 i++, section++)
252b5132 6712 {
dd905818
NC
6713 /* Run some sanity checks on the section header. */
6714
6715 /* Check the sh_link field. */
6716 switch (section->sh_type)
6717 {
285e3f99
AM
6718 case SHT_REL:
6719 case SHT_RELA:
6720 if (section->sh_link == 0
6721 && (filedata->file_header.e_type == ET_EXEC
6722 || filedata->file_header.e_type == ET_DYN))
6723 /* A dynamic relocation section where all entries use a
6724 zero symbol index need not specify a symtab section. */
6725 break;
6726 /* Fall through. */
dd905818
NC
6727 case SHT_SYMTAB_SHNDX:
6728 case SHT_GROUP:
6729 case SHT_HASH:
6730 case SHT_GNU_HASH:
6731 case SHT_GNU_versym:
285e3f99 6732 if (section->sh_link == 0
dda8d76d
NC
6733 || section->sh_link >= filedata->file_header.e_shnum
6734 || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB
6735 && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM))
dd905818
NC
6736 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6737 i, section->sh_link);
6738 break;
6739
6740 case SHT_DYNAMIC:
6741 case SHT_SYMTAB:
6742 case SHT_DYNSYM:
6743 case SHT_GNU_verneed:
6744 case SHT_GNU_verdef:
6745 case SHT_GNU_LIBLIST:
285e3f99 6746 if (section->sh_link == 0
dda8d76d
NC
6747 || section->sh_link >= filedata->file_header.e_shnum
6748 || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB)
dd905818
NC
6749 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6750 i, section->sh_link);
6751 break;
6752
6753 case SHT_INIT_ARRAY:
6754 case SHT_FINI_ARRAY:
6755 case SHT_PREINIT_ARRAY:
6756 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6757 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6758 i, section->sh_link);
6759 break;
6760
6761 default:
6762 /* FIXME: Add support for target specific section types. */
6763#if 0 /* Currently we do not check other section types as there are too
6764 many special cases. Stab sections for example have a type
6765 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6766 section. */
6767 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6768 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6769 i, section->sh_link);
6770#endif
6771 break;
6772 }
6773
6774 /* Check the sh_info field. */
6775 switch (section->sh_type)
6776 {
6777 case SHT_REL:
6778 case SHT_RELA:
285e3f99
AM
6779 if (section->sh_info == 0
6780 && (filedata->file_header.e_type == ET_EXEC
6781 || filedata->file_header.e_type == ET_DYN))
6782 /* Dynamic relocations apply to segments, so they do not
6783 need to specify the section they relocate. */
6784 break;
6785 if (section->sh_info == 0
dda8d76d
NC
6786 || section->sh_info >= filedata->file_header.e_shnum
6787 || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS
6788 && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
6789 && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
6790 && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
385e5b90
L
6791 && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY
6792 && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY
dd905818 6793 /* FIXME: Are other section types valid ? */
dda8d76d 6794 && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
285e3f99
AM
6795 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6796 i, section->sh_info);
dd905818
NC
6797 break;
6798
6799 case SHT_DYNAMIC:
6800 case SHT_HASH:
6801 case SHT_SYMTAB_SHNDX:
6802 case SHT_INIT_ARRAY:
6803 case SHT_FINI_ARRAY:
6804 case SHT_PREINIT_ARRAY:
6805 if (section->sh_info != 0)
6806 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6807 i, section->sh_info);
6808 break;
6809
6810 case SHT_GROUP:
6811 case SHT_SYMTAB:
6812 case SHT_DYNSYM:
6813 /* A symbol index - we assume that it is valid. */
6814 break;
6815
6816 default:
6817 /* FIXME: Add support for target specific section types. */
6818 if (section->sh_type == SHT_NOBITS)
6819 /* NOBITS section headers with non-zero sh_info fields can be
6820 created when a binary is stripped of everything but its debug
1a9ccd70
NC
6821 information. The stripped sections have their headers
6822 preserved but their types set to SHT_NOBITS. So do not check
6823 this type of section. */
dd905818
NC
6824 ;
6825 else if (section->sh_flags & SHF_INFO_LINK)
6826 {
dda8d76d 6827 if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum)
dd905818
NC
6828 warn (_("[%2u]: Expected link to another section in info field"), i);
6829 }
a91e1603
L
6830 else if (section->sh_type < SHT_LOOS
6831 && (section->sh_flags & SHF_GNU_MBIND) == 0
6832 && section->sh_info != 0)
dd905818
NC
6833 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6834 i, section->sh_info);
6835 break;
6836 }
6837
3e6b6445 6838 /* Check the sh_size field. */
dda8d76d 6839 if (section->sh_size > filedata->file_size
3e6b6445
NC
6840 && section->sh_type != SHT_NOBITS
6841 && section->sh_type != SHT_NULL
6842 && section->sh_type < SHT_LOOS)
6843 warn (_("Size of section %u is larger than the entire file!\n"), i);
6844
7bfd842d 6845 printf (" [%2u] ", i);
5477e8a0 6846 if (do_section_details)
dda8d76d 6847 printf ("%s\n ", printable_section_name (filedata, section));
595cf52e 6848 else
b9e920ec 6849 print_symbol (-17, SECTION_NAME_PRINT (section));
0b4362b0 6850
ea52a088 6851 printf (do_wide ? " %-15s " : " %-15.15s ",
dda8d76d 6852 get_section_type_name (filedata, section->sh_type));
0b4362b0 6853
f7a99963
NC
6854 if (is_32bit_elf)
6855 {
cfcac11d
NC
6856 const char * link_too_big = NULL;
6857
f7a99963 6858 print_vma (section->sh_addr, LONG_HEX);
76da6bbe 6859
f7a99963
NC
6860 printf ( " %6.6lx %6.6lx %2.2lx",
6861 (unsigned long) section->sh_offset,
6862 (unsigned long) section->sh_size,
6863 (unsigned long) section->sh_entsize);
d1133906 6864
5477e8a0
L
6865 if (do_section_details)
6866 fputs (" ", stdout);
6867 else
dda8d76d 6868 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
76da6bbe 6869
dda8d76d 6870 if (section->sh_link >= filedata->file_header.e_shnum)
cfcac11d
NC
6871 {
6872 link_too_big = "";
6873 /* The sh_link value is out of range. Normally this indicates
caa83f8b 6874 an error but it can have special values in Solaris binaries. */
dda8d76d 6875 switch (filedata->file_header.e_machine)
cfcac11d 6876 {
caa83f8b 6877 case EM_386:
22abe556 6878 case EM_IAMCU:
caa83f8b 6879 case EM_X86_64:
7f502d6c 6880 case EM_L1OM:
7a9068fe 6881 case EM_K1OM:
cfcac11d
NC
6882 case EM_OLD_SPARCV9:
6883 case EM_SPARC32PLUS:
6884 case EM_SPARCV9:
6885 case EM_SPARC:
6886 if (section->sh_link == (SHN_BEFORE & 0xffff))
6887 link_too_big = "BEFORE";
6888 else if (section->sh_link == (SHN_AFTER & 0xffff))
6889 link_too_big = "AFTER";
6890 break;
6891 default:
6892 break;
6893 }
6894 }
6895
6896 if (do_section_details)
6897 {
6898 if (link_too_big != NULL && * link_too_big)
6899 printf ("<%s> ", link_too_big);
6900 else
6901 printf ("%2u ", section->sh_link);
6902 printf ("%3u %2lu\n", section->sh_info,
6903 (unsigned long) section->sh_addralign);
6904 }
6905 else
6906 printf ("%2u %3u %2lu\n",
6907 section->sh_link,
6908 section->sh_info,
6909 (unsigned long) section->sh_addralign);
6910
6911 if (link_too_big && ! * link_too_big)
6912 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6913 i, section->sh_link);
f7a99963 6914 }
d974e256
JJ
6915 else if (do_wide)
6916 {
6917 print_vma (section->sh_addr, LONG_HEX);
6918
6919 if ((long) section->sh_offset == section->sh_offset)
6920 printf (" %6.6lx", (unsigned long) section->sh_offset);
6921 else
6922 {
6923 putchar (' ');
6924 print_vma (section->sh_offset, LONG_HEX);
6925 }
6926
6927 if ((unsigned long) section->sh_size == section->sh_size)
6928 printf (" %6.6lx", (unsigned long) section->sh_size);
6929 else
6930 {
6931 putchar (' ');
6932 print_vma (section->sh_size, LONG_HEX);
6933 }
6934
6935 if ((unsigned long) section->sh_entsize == section->sh_entsize)
6936 printf (" %2.2lx", (unsigned long) section->sh_entsize);
6937 else
6938 {
6939 putchar (' ');
6940 print_vma (section->sh_entsize, LONG_HEX);
6941 }
6942
5477e8a0
L
6943 if (do_section_details)
6944 fputs (" ", stdout);
6945 else
dda8d76d 6946 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
d974e256 6947
72de5009 6948 printf ("%2u %3u ", section->sh_link, section->sh_info);
d974e256
JJ
6949
6950 if ((unsigned long) section->sh_addralign == section->sh_addralign)
72de5009 6951 printf ("%2lu\n", (unsigned long) section->sh_addralign);
d974e256
JJ
6952 else
6953 {
6954 print_vma (section->sh_addralign, DEC);
6955 putchar ('\n');
6956 }
6957 }
5477e8a0 6958 else if (do_section_details)
595cf52e 6959 {
55cc53e9 6960 putchar (' ');
595cf52e
L
6961 print_vma (section->sh_addr, LONG_HEX);
6962 if ((long) section->sh_offset == section->sh_offset)
5477e8a0 6963 printf (" %16.16lx", (unsigned long) section->sh_offset);
595cf52e
L
6964 else
6965 {
6966 printf (" ");
6967 print_vma (section->sh_offset, LONG_HEX);
6968 }
72de5009 6969 printf (" %u\n ", section->sh_link);
595cf52e 6970 print_vma (section->sh_size, LONG_HEX);
5477e8a0 6971 putchar (' ');
595cf52e
L
6972 print_vma (section->sh_entsize, LONG_HEX);
6973
72de5009
AM
6974 printf (" %-16u %lu\n",
6975 section->sh_info,
595cf52e
L
6976 (unsigned long) section->sh_addralign);
6977 }
f7a99963
NC
6978 else
6979 {
6980 putchar (' ');
6981 print_vma (section->sh_addr, LONG_HEX);
53c7db4b
KH
6982 if ((long) section->sh_offset == section->sh_offset)
6983 printf (" %8.8lx", (unsigned long) section->sh_offset);
6984 else
6985 {
6986 printf (" ");
6987 print_vma (section->sh_offset, LONG_HEX);
6988 }
f7a99963
NC
6989 printf ("\n ");
6990 print_vma (section->sh_size, LONG_HEX);
6991 printf (" ");
6992 print_vma (section->sh_entsize, LONG_HEX);
76da6bbe 6993
dda8d76d 6994 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
76da6bbe 6995
72de5009
AM
6996 printf (" %2u %3u %lu\n",
6997 section->sh_link,
6998 section->sh_info,
f7a99963
NC
6999 (unsigned long) section->sh_addralign);
7000 }
5477e8a0
L
7001
7002 if (do_section_details)
77115a4a 7003 {
dda8d76d 7004 printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags));
77115a4a
L
7005 if ((section->sh_flags & SHF_COMPRESSED) != 0)
7006 {
7007 /* Minimum section size is 12 bytes for 32-bit compression
7008 header + 12 bytes for compressed data header. */
7009 unsigned char buf[24];
d8024a91 7010
77115a4a 7011 assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
dda8d76d 7012 if (get_data (&buf, filedata, section->sh_offset, 1,
77115a4a
L
7013 sizeof (buf), _("compression header")))
7014 {
7015 Elf_Internal_Chdr chdr;
d8024a91 7016
5844b465
NC
7017 if (get_compression_header (&chdr, buf, sizeof (buf)) == 0)
7018 printf (_(" [<corrupt>]\n"));
77115a4a 7019 else
5844b465
NC
7020 {
7021 if (chdr.ch_type == ELFCOMPRESS_ZLIB)
7022 printf (" ZLIB, ");
7023 else
7024 printf (_(" [<unknown>: 0x%x], "),
7025 chdr.ch_type);
7026 print_vma (chdr.ch_size, LONG_HEX);
7027 printf (", %lu\n", (unsigned long) chdr.ch_addralign);
7028 }
77115a4a
L
7029 }
7030 }
7031 }
252b5132
RH
7032 }
7033
5477e8a0 7034 if (!do_section_details)
3dbcc61d 7035 {
9fb71ee4
NC
7036 /* The ordering of the letters shown here matches the ordering of the
7037 corresponding SHF_xxx values, and hence the order in which these
7038 letters will be displayed to the user. */
7039 printf (_("Key to Flags:\n\
7040 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
7041 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
fd85a6a1 7042 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
5424d7ed
L
7043 switch (filedata->file_header.e_ident[EI_OSABI])
7044 {
7045 case ELFOSABI_GNU:
7046 case ELFOSABI_FREEBSD:
7047 printf (_("R (retain), "));
7048 /* Fall through */
7049 case ELFOSABI_NONE:
7050 printf (_("D (mbind), "));
7051 break;
7052 default:
7053 break;
7054 }
dda8d76d
NC
7055 if (filedata->file_header.e_machine == EM_X86_64
7056 || filedata->file_header.e_machine == EM_L1OM
7057 || filedata->file_header.e_machine == EM_K1OM)
9fb71ee4 7058 printf (_("l (large), "));
dda8d76d 7059 else if (filedata->file_header.e_machine == EM_ARM)
f0728ee3 7060 printf (_("y (purecode), "));
dda8d76d 7061 else if (filedata->file_header.e_machine == EM_PPC)
83eef883 7062 printf (_("v (VLE), "));
9fb71ee4 7063 printf ("p (processor specific)\n");
0b4362b0 7064 }
d1133906 7065
32ec8896 7066 return TRUE;
252b5132
RH
7067}
7068
28d13567
AM
7069static bfd_boolean
7070get_symtab (Filedata *filedata, Elf_Internal_Shdr *symsec,
7071 Elf_Internal_Sym **symtab, unsigned long *nsyms,
7072 char **strtab, unsigned long *strtablen)
7073{
7074 *strtab = NULL;
7075 *strtablen = 0;
7076 *symtab = GET_ELF_SYMBOLS (filedata, symsec, nsyms);
7077
7078 if (*symtab == NULL)
7079 return FALSE;
7080
7081 if (symsec->sh_link != 0)
7082 {
7083 Elf_Internal_Shdr *strsec;
7084
7085 if (symsec->sh_link >= filedata->file_header.e_shnum)
7086 {
7087 error (_("Bad sh_link in symbol table section\n"));
7088 free (*symtab);
7089 *symtab = NULL;
7090 *nsyms = 0;
7091 return FALSE;
7092 }
7093
7094 strsec = filedata->section_headers + symsec->sh_link;
7095
7096 *strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
7097 1, strsec->sh_size, _("string table"));
7098 if (*strtab == NULL)
7099 {
7100 free (*symtab);
7101 *symtab = NULL;
7102 *nsyms = 0;
7103 return FALSE;
7104 }
7105 *strtablen = strsec->sh_size;
7106 }
7107 return TRUE;
7108}
7109
f5842774
L
7110static const char *
7111get_group_flags (unsigned int flags)
7112{
1449284b 7113 static char buff[128];
220453ec 7114
6d913794
NC
7115 if (flags == 0)
7116 return "";
7117 else if (flags == GRP_COMDAT)
7118 return "COMDAT ";
f5842774 7119
89246a0e
AM
7120 snprintf (buff, sizeof buff, "[0x%x: %s%s%s]",
7121 flags,
7122 flags & GRP_MASKOS ? _("<OS specific>") : "",
7123 flags & GRP_MASKPROC ? _("<PROC specific>") : "",
7124 (flags & ~(GRP_COMDAT | GRP_MASKOS | GRP_MASKPROC)
7125 ? _("<unknown>") : ""));
6d913794 7126
f5842774
L
7127 return buff;
7128}
7129
32ec8896 7130static bfd_boolean
dda8d76d 7131process_section_groups (Filedata * filedata)
f5842774 7132{
2cf0635d 7133 Elf_Internal_Shdr * section;
f5842774 7134 unsigned int i;
2cf0635d
NC
7135 struct group * group;
7136 Elf_Internal_Shdr * symtab_sec;
7137 Elf_Internal_Shdr * strtab_sec;
7138 Elf_Internal_Sym * symtab;
ba5cdace 7139 unsigned long num_syms;
2cf0635d 7140 char * strtab;
c256ffe7 7141 size_t strtab_size;
d1f5c6e3
L
7142
7143 /* Don't process section groups unless needed. */
7144 if (!do_unwind && !do_section_groups)
32ec8896 7145 return TRUE;
f5842774 7146
dda8d76d 7147 if (filedata->file_header.e_shnum == 0)
f5842774
L
7148 {
7149 if (do_section_groups)
ca0e11aa
NC
7150 {
7151 if (filedata->is_separate)
7152 printf (_("\nThere are no sections group in linked file '%s'.\n"),
7153 filedata->file_name);
7154 else
7155 printf (_("\nThere are no section groups in this file.\n"));
7156 }
32ec8896 7157 return TRUE;
f5842774
L
7158 }
7159
dda8d76d 7160 if (filedata->section_headers == NULL)
f5842774
L
7161 {
7162 error (_("Section headers are not available!\n"));
fa1908fd 7163 /* PR 13622: This can happen with a corrupt ELF header. */
32ec8896 7164 return FALSE;
f5842774
L
7165 }
7166
978c4450
AM
7167 filedata->section_headers_groups
7168 = (struct group **) calloc (filedata->file_header.e_shnum,
7169 sizeof (struct group *));
e4b17d5c 7170
978c4450 7171 if (filedata->section_headers_groups == NULL)
e4b17d5c 7172 {
8b73c356 7173 error (_("Out of memory reading %u section group headers\n"),
dda8d76d 7174 filedata->file_header.e_shnum);
32ec8896 7175 return FALSE;
e4b17d5c
L
7176 }
7177
f5842774 7178 /* Scan the sections for the group section. */
978c4450 7179 filedata->group_count = 0;
dda8d76d
NC
7180 for (i = 0, section = filedata->section_headers;
7181 i < filedata->file_header.e_shnum;
f5842774 7182 i++, section++)
e4b17d5c 7183 if (section->sh_type == SHT_GROUP)
978c4450 7184 filedata->group_count++;
e4b17d5c 7185
978c4450 7186 if (filedata->group_count == 0)
d1f5c6e3
L
7187 {
7188 if (do_section_groups)
ca0e11aa
NC
7189 {
7190 if (filedata->is_separate)
7191 printf (_("\nThere are no section groups in linked file '%s'.\n"),
7192 filedata->file_name);
7193 else
7194 printf (_("\nThere are no section groups in this file.\n"));
7195 }
d1f5c6e3 7196
32ec8896 7197 return TRUE;
d1f5c6e3
L
7198 }
7199
978c4450
AM
7200 filedata->section_groups = (struct group *) calloc (filedata->group_count,
7201 sizeof (struct group));
e4b17d5c 7202
978c4450 7203 if (filedata->section_groups == NULL)
e4b17d5c 7204 {
8b73c356 7205 error (_("Out of memory reading %lu groups\n"),
978c4450 7206 (unsigned long) filedata->group_count);
32ec8896 7207 return FALSE;
e4b17d5c
L
7208 }
7209
d1f5c6e3
L
7210 symtab_sec = NULL;
7211 strtab_sec = NULL;
7212 symtab = NULL;
ba5cdace 7213 num_syms = 0;
d1f5c6e3 7214 strtab = NULL;
c256ffe7 7215 strtab_size = 0;
ca0e11aa
NC
7216
7217 if (filedata->is_separate)
7218 printf (_("Section groups in linked file '%s'\n"), filedata->file_name);
7219
978c4450 7220 for (i = 0, section = filedata->section_headers, group = filedata->section_groups;
dda8d76d 7221 i < filedata->file_header.e_shnum;
e4b17d5c 7222 i++, section++)
f5842774
L
7223 {
7224 if (section->sh_type == SHT_GROUP)
7225 {
dda8d76d 7226 const char * name = printable_section_name (filedata, section);
74e1a04b 7227 const char * group_name;
2cf0635d
NC
7228 unsigned char * start;
7229 unsigned char * indices;
f5842774 7230 unsigned int entry, j, size;
2cf0635d
NC
7231 Elf_Internal_Shdr * sec;
7232 Elf_Internal_Sym * sym;
f5842774
L
7233
7234 /* Get the symbol table. */
dda8d76d
NC
7235 if (section->sh_link >= filedata->file_header.e_shnum
7236 || ((sec = filedata->section_headers + section->sh_link)->sh_type
c256ffe7 7237 != SHT_SYMTAB))
f5842774
L
7238 {
7239 error (_("Bad sh_link in group section `%s'\n"), name);
7240 continue;
7241 }
d1f5c6e3
L
7242
7243 if (symtab_sec != sec)
7244 {
7245 symtab_sec = sec;
9db70fc3 7246 free (symtab);
dda8d76d 7247 symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms);
d1f5c6e3 7248 }
f5842774 7249
dd24e3da
NC
7250 if (symtab == NULL)
7251 {
7252 error (_("Corrupt header in group section `%s'\n"), name);
7253 continue;
7254 }
7255
ba5cdace
NC
7256 if (section->sh_info >= num_syms)
7257 {
7258 error (_("Bad sh_info in group section `%s'\n"), name);
7259 continue;
7260 }
7261
f5842774
L
7262 sym = symtab + section->sh_info;
7263
7264 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7265 {
4fbb74a6 7266 if (sym->st_shndx == 0
dda8d76d 7267 || sym->st_shndx >= filedata->file_header.e_shnum)
f5842774
L
7268 {
7269 error (_("Bad sh_info in group section `%s'\n"), name);
7270 continue;
7271 }
ba2685cc 7272
b9e920ec
AM
7273 group_name = SECTION_NAME_PRINT (filedata->section_headers
7274 + sym->st_shndx);
c256ffe7 7275 strtab_sec = NULL;
9db70fc3 7276 free (strtab);
f5842774 7277 strtab = NULL;
c256ffe7 7278 strtab_size = 0;
f5842774
L
7279 }
7280 else
7281 {
7282 /* Get the string table. */
dda8d76d 7283 if (symtab_sec->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
7284 {
7285 strtab_sec = NULL;
9db70fc3 7286 free (strtab);
c256ffe7
JJ
7287 strtab = NULL;
7288 strtab_size = 0;
7289 }
7290 else if (strtab_sec
dda8d76d 7291 != (sec = filedata->section_headers + symtab_sec->sh_link))
d1f5c6e3
L
7292 {
7293 strtab_sec = sec;
9db70fc3 7294 free (strtab);
071436c6 7295
dda8d76d 7296 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
071436c6
NC
7297 1, strtab_sec->sh_size,
7298 _("string table"));
c256ffe7 7299 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
d1f5c6e3 7300 }
c256ffe7 7301 group_name = sym->st_name < strtab_size
2b692964 7302 ? strtab + sym->st_name : _("<corrupt>");
f5842774
L
7303 }
7304
c9c1d674
EG
7305 /* PR 17531: file: loop. */
7306 if (section->sh_entsize > section->sh_size)
7307 {
7308 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
dda8d76d 7309 printable_section_name (filedata, section),
8066deb1
AM
7310 (unsigned long) section->sh_entsize,
7311 (unsigned long) section->sh_size);
61dd8e19 7312 continue;
c9c1d674
EG
7313 }
7314
dda8d76d 7315 start = (unsigned char *) get_data (NULL, filedata, section->sh_offset,
3f5e193b
NC
7316 1, section->sh_size,
7317 _("section data"));
59245841
NC
7318 if (start == NULL)
7319 continue;
f5842774
L
7320
7321 indices = start;
7322 size = (section->sh_size / section->sh_entsize) - 1;
7323 entry = byte_get (indices, 4);
7324 indices += 4;
e4b17d5c
L
7325
7326 if (do_section_groups)
7327 {
2b692964 7328 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
391cb864 7329 get_group_flags (entry), i, name, group_name, size);
ba2685cc 7330
e4b17d5c
L
7331 printf (_(" [Index] Name\n"));
7332 }
7333
7334 group->group_index = i;
7335
f5842774
L
7336 for (j = 0; j < size; j++)
7337 {
2cf0635d 7338 struct group_list * g;
e4b17d5c 7339
f5842774
L
7340 entry = byte_get (indices, 4);
7341 indices += 4;
7342
dda8d76d 7343 if (entry >= filedata->file_header.e_shnum)
391cb864 7344 {
57028622
NC
7345 static unsigned num_group_errors = 0;
7346
7347 if (num_group_errors ++ < 10)
7348 {
7349 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
dda8d76d 7350 entry, i, filedata->file_header.e_shnum - 1);
57028622 7351 if (num_group_errors == 10)
67ce483b 7352 warn (_("Further error messages about overlarge group section indices suppressed\n"));
57028622 7353 }
391cb864
L
7354 continue;
7355 }
391cb864 7356
978c4450 7357 if (filedata->section_headers_groups [entry] != NULL)
e4b17d5c 7358 {
d1f5c6e3
L
7359 if (entry)
7360 {
57028622
NC
7361 static unsigned num_errs = 0;
7362
7363 if (num_errs ++ < 10)
7364 {
7365 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7366 entry, i,
978c4450 7367 filedata->section_headers_groups [entry]->group_index);
57028622
NC
7368 if (num_errs == 10)
7369 warn (_("Further error messages about already contained group sections suppressed\n"));
7370 }
d1f5c6e3
L
7371 continue;
7372 }
7373 else
7374 {
7375 /* Intel C/C++ compiler may put section 0 in a
32ec8896 7376 section group. We just warn it the first time
d1f5c6e3 7377 and ignore it afterwards. */
32ec8896 7378 static bfd_boolean warned = FALSE;
d1f5c6e3
L
7379 if (!warned)
7380 {
7381 error (_("section 0 in group section [%5u]\n"),
978c4450 7382 filedata->section_headers_groups [entry]->group_index);
32ec8896 7383 warned = TRUE;
d1f5c6e3
L
7384 }
7385 }
e4b17d5c
L
7386 }
7387
978c4450 7388 filedata->section_headers_groups [entry] = group;
e4b17d5c
L
7389
7390 if (do_section_groups)
7391 {
dda8d76d
NC
7392 sec = filedata->section_headers + entry;
7393 printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec));
ba2685cc
AM
7394 }
7395
3f5e193b 7396 g = (struct group_list *) xmalloc (sizeof (struct group_list));
e4b17d5c
L
7397 g->section_index = entry;
7398 g->next = group->root;
7399 group->root = g;
f5842774
L
7400 }
7401
9db70fc3 7402 free (start);
e4b17d5c
L
7403
7404 group++;
f5842774
L
7405 }
7406 }
7407
9db70fc3
AM
7408 free (symtab);
7409 free (strtab);
32ec8896 7410 return TRUE;
f5842774
L
7411}
7412
28f997cf
TG
7413/* Data used to display dynamic fixups. */
7414
7415struct ia64_vms_dynfixup
7416{
7417 bfd_vma needed_ident; /* Library ident number. */
7418 bfd_vma needed; /* Index in the dstrtab of the library name. */
7419 bfd_vma fixup_needed; /* Index of the library. */
7420 bfd_vma fixup_rela_cnt; /* Number of fixups. */
7421 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
7422};
7423
7424/* Data used to display dynamic relocations. */
7425
7426struct ia64_vms_dynimgrela
7427{
7428 bfd_vma img_rela_cnt; /* Number of relocations. */
7429 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
7430};
7431
7432/* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7433 library). */
7434
32ec8896 7435static bfd_boolean
dda8d76d
NC
7436dump_ia64_vms_dynamic_fixups (Filedata * filedata,
7437 struct ia64_vms_dynfixup * fixup,
7438 const char * strtab,
7439 unsigned int strtab_sz)
28f997cf 7440{
32ec8896 7441 Elf64_External_VMS_IMAGE_FIXUP * imfs;
28f997cf 7442 long i;
32ec8896 7443 const char * lib_name;
28f997cf 7444
978c4450
AM
7445 imfs = get_data (NULL, filedata,
7446 filedata->dynamic_addr + fixup->fixup_rela_off,
95099889 7447 sizeof (*imfs), fixup->fixup_rela_cnt,
28f997cf
TG
7448 _("dynamic section image fixups"));
7449 if (!imfs)
32ec8896 7450 return FALSE;
28f997cf
TG
7451
7452 if (fixup->needed < strtab_sz)
7453 lib_name = strtab + fixup->needed;
7454 else
7455 {
32ec8896 7456 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7f01b0c6 7457 (unsigned long) fixup->needed);
28f997cf
TG
7458 lib_name = "???";
7459 }
736990c4 7460
28f997cf
TG
7461 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7462 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
7463 printf
7464 (_("Seg Offset Type SymVec DataType\n"));
7465
7466 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
7467 {
7468 unsigned int type;
7469 const char *rtype;
7470
7471 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
7472 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
7473 type = BYTE_GET (imfs [i].type);
7474 rtype = elf_ia64_reloc_type (type);
7475 if (rtype == NULL)
7476 printf (" 0x%08x ", type);
7477 else
7478 printf (" %-32s ", rtype);
7479 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
7480 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
7481 }
7482
7483 free (imfs);
32ec8896 7484 return TRUE;
28f997cf
TG
7485}
7486
7487/* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7488
32ec8896 7489static bfd_boolean
dda8d76d 7490dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela)
28f997cf
TG
7491{
7492 Elf64_External_VMS_IMAGE_RELA *imrs;
7493 long i;
7494
978c4450
AM
7495 imrs = get_data (NULL, filedata,
7496 filedata->dynamic_addr + imgrela->img_rela_off,
95099889 7497 sizeof (*imrs), imgrela->img_rela_cnt,
9cf03b7e 7498 _("dynamic section image relocations"));
28f997cf 7499 if (!imrs)
32ec8896 7500 return FALSE;
28f997cf
TG
7501
7502 printf (_("\nImage relocs\n"));
7503 printf
7504 (_("Seg Offset Type Addend Seg Sym Off\n"));
7505
7506 for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
7507 {
7508 unsigned int type;
7509 const char *rtype;
7510
7511 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
7512 printf ("%08" BFD_VMA_FMT "x ",
7513 (bfd_vma) BYTE_GET (imrs [i].rela_offset));
7514 type = BYTE_GET (imrs [i].type);
7515 rtype = elf_ia64_reloc_type (type);
7516 if (rtype == NULL)
7517 printf ("0x%08x ", type);
7518 else
7519 printf ("%-31s ", rtype);
7520 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
7521 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
7522 printf ("%08" BFD_VMA_FMT "x\n",
7523 (bfd_vma) BYTE_GET (imrs [i].sym_offset));
7524 }
7525
7526 free (imrs);
32ec8896 7527 return TRUE;
28f997cf
TG
7528}
7529
7530/* Display IA-64 OpenVMS dynamic relocations and fixups. */
7531
32ec8896 7532static bfd_boolean
dda8d76d 7533process_ia64_vms_dynamic_relocs (Filedata * filedata)
28f997cf
TG
7534{
7535 struct ia64_vms_dynfixup fixup;
7536 struct ia64_vms_dynimgrela imgrela;
7537 Elf_Internal_Dyn *entry;
28f997cf
TG
7538 bfd_vma strtab_off = 0;
7539 bfd_vma strtab_sz = 0;
7540 char *strtab = NULL;
32ec8896 7541 bfd_boolean res = TRUE;
28f997cf
TG
7542
7543 memset (&fixup, 0, sizeof (fixup));
7544 memset (&imgrela, 0, sizeof (imgrela));
7545
7546 /* Note: the order of the entries is specified by the OpenVMS specs. */
978c4450
AM
7547 for (entry = filedata->dynamic_section;
7548 entry < filedata->dynamic_section + filedata->dynamic_nent;
28f997cf
TG
7549 entry++)
7550 {
7551 switch (entry->d_tag)
7552 {
7553 case DT_IA_64_VMS_STRTAB_OFFSET:
7554 strtab_off = entry->d_un.d_val;
7555 break;
7556 case DT_STRSZ:
7557 strtab_sz = entry->d_un.d_val;
7558 if (strtab == NULL)
978c4450
AM
7559 strtab = get_data (NULL, filedata,
7560 filedata->dynamic_addr + strtab_off,
28f997cf 7561 1, strtab_sz, _("dynamic string section"));
736990c4
NC
7562 if (strtab == NULL)
7563 strtab_sz = 0;
28f997cf
TG
7564 break;
7565
7566 case DT_IA_64_VMS_NEEDED_IDENT:
7567 fixup.needed_ident = entry->d_un.d_val;
7568 break;
7569 case DT_NEEDED:
7570 fixup.needed = entry->d_un.d_val;
7571 break;
7572 case DT_IA_64_VMS_FIXUP_NEEDED:
7573 fixup.fixup_needed = entry->d_un.d_val;
7574 break;
7575 case DT_IA_64_VMS_FIXUP_RELA_CNT:
7576 fixup.fixup_rela_cnt = entry->d_un.d_val;
7577 break;
7578 case DT_IA_64_VMS_FIXUP_RELA_OFF:
7579 fixup.fixup_rela_off = entry->d_un.d_val;
dda8d76d 7580 if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz))
32ec8896 7581 res = FALSE;
28f997cf 7582 break;
28f997cf
TG
7583 case DT_IA_64_VMS_IMG_RELA_CNT:
7584 imgrela.img_rela_cnt = entry->d_un.d_val;
7585 break;
7586 case DT_IA_64_VMS_IMG_RELA_OFF:
7587 imgrela.img_rela_off = entry->d_un.d_val;
dda8d76d 7588 if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela))
32ec8896 7589 res = FALSE;
28f997cf
TG
7590 break;
7591
7592 default:
7593 break;
7594 }
7595 }
7596
9db70fc3 7597 free (strtab);
28f997cf
TG
7598
7599 return res;
7600}
7601
85b1c36d 7602static struct
566b0d53 7603{
2cf0635d 7604 const char * name;
566b0d53
L
7605 int reloc;
7606 int size;
7607 int rela;
32ec8896
NC
7608}
7609 dynamic_relocations [] =
566b0d53 7610{
32ec8896
NC
7611 { "REL", DT_REL, DT_RELSZ, FALSE },
7612 { "RELA", DT_RELA, DT_RELASZ, TRUE },
7613 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
566b0d53
L
7614};
7615
252b5132 7616/* Process the reloc section. */
18bd398b 7617
32ec8896 7618static bfd_boolean
dda8d76d 7619process_relocs (Filedata * filedata)
252b5132 7620{
b34976b6
AM
7621 unsigned long rel_size;
7622 unsigned long rel_offset;
252b5132 7623
252b5132 7624 if (!do_reloc)
32ec8896 7625 return TRUE;
252b5132
RH
7626
7627 if (do_using_dynamic)
7628 {
32ec8896 7629 int is_rela;
2cf0635d 7630 const char * name;
32ec8896 7631 bfd_boolean has_dynamic_reloc;
566b0d53 7632 unsigned int i;
0de14b54 7633
32ec8896 7634 has_dynamic_reloc = FALSE;
252b5132 7635
566b0d53 7636 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
252b5132 7637 {
566b0d53
L
7638 is_rela = dynamic_relocations [i].rela;
7639 name = dynamic_relocations [i].name;
978c4450
AM
7640 rel_size = filedata->dynamic_info[dynamic_relocations [i].size];
7641 rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc];
103f02d3 7642
32ec8896
NC
7643 if (rel_size)
7644 has_dynamic_reloc = TRUE;
566b0d53
L
7645
7646 if (is_rela == UNKNOWN)
aa903cfb 7647 {
566b0d53 7648 if (dynamic_relocations [i].reloc == DT_JMPREL)
978c4450 7649 switch (filedata->dynamic_info[DT_PLTREL])
566b0d53
L
7650 {
7651 case DT_REL:
7652 is_rela = FALSE;
7653 break;
7654 case DT_RELA:
7655 is_rela = TRUE;
7656 break;
7657 }
aa903cfb 7658 }
252b5132 7659
566b0d53
L
7660 if (rel_size)
7661 {
ca0e11aa
NC
7662 if (filedata->is_separate)
7663 printf
7664 (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"),
7665 filedata->file_name, name, rel_offset, rel_size);
7666 else
7667 printf
7668 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7669 name, rel_offset, rel_size);
7670
252b5132 7671
dda8d76d
NC
7672 dump_relocations (filedata,
7673 offset_from_vma (filedata, rel_offset, rel_size),
d93f0186 7674 rel_size,
978c4450
AM
7675 filedata->dynamic_symbols,
7676 filedata->num_dynamic_syms,
7677 filedata->dynamic_strings,
7678 filedata->dynamic_strings_length,
32ec8896 7679 is_rela, TRUE /* is_dynamic */);
566b0d53 7680 }
252b5132 7681 }
566b0d53 7682
dda8d76d
NC
7683 if (is_ia64_vms (filedata))
7684 if (process_ia64_vms_dynamic_relocs (filedata))
32ec8896 7685 has_dynamic_reloc = TRUE;
28f997cf 7686
566b0d53 7687 if (! has_dynamic_reloc)
ca0e11aa
NC
7688 {
7689 if (filedata->is_separate)
7690 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
7691 filedata->file_name);
7692 else
7693 printf (_("\nThere are no dynamic relocations in this file.\n"));
7694 }
252b5132
RH
7695 }
7696 else
7697 {
2cf0635d 7698 Elf_Internal_Shdr * section;
b34976b6 7699 unsigned long i;
32ec8896 7700 bfd_boolean found = FALSE;
252b5132 7701
dda8d76d
NC
7702 for (i = 0, section = filedata->section_headers;
7703 i < filedata->file_header.e_shnum;
b34976b6 7704 i++, section++)
252b5132
RH
7705 {
7706 if ( section->sh_type != SHT_RELA
7707 && section->sh_type != SHT_REL)
7708 continue;
7709
7710 rel_offset = section->sh_offset;
7711 rel_size = section->sh_size;
7712
7713 if (rel_size)
7714 {
b34976b6 7715 int is_rela;
d3a49aa8 7716 unsigned long num_rela;
103f02d3 7717
ca0e11aa
NC
7718 if (filedata->is_separate)
7719 printf (_("\nIn linked file '%s' relocation section "),
7720 filedata->file_name);
7721 else
7722 printf (_("\nRelocation section "));
252b5132 7723
dda8d76d 7724 if (filedata->string_table == NULL)
19936277 7725 printf ("%d", section->sh_name);
252b5132 7726 else
dda8d76d 7727 printf ("'%s'", printable_section_name (filedata, section));
252b5132 7728
d3a49aa8
AM
7729 num_rela = rel_size / section->sh_entsize;
7730 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7731 " at offset 0x%lx contains %lu entries:\n",
7732 num_rela),
7733 rel_offset, num_rela);
252b5132 7734
d79b3d50
NC
7735 is_rela = section->sh_type == SHT_RELA;
7736
4fbb74a6 7737 if (section->sh_link != 0
dda8d76d 7738 && section->sh_link < filedata->file_header.e_shnum)
af3fc3bc 7739 {
2cf0635d
NC
7740 Elf_Internal_Shdr * symsec;
7741 Elf_Internal_Sym * symtab;
d79b3d50 7742 unsigned long nsyms;
c256ffe7 7743 unsigned long strtablen = 0;
2cf0635d 7744 char * strtab = NULL;
57346661 7745
dda8d76d 7746 symsec = filedata->section_headers + section->sh_link;
08d8fa11
JJ
7747 if (symsec->sh_type != SHT_SYMTAB
7748 && symsec->sh_type != SHT_DYNSYM)
7749 continue;
7750
28d13567
AM
7751 if (!get_symtab (filedata, symsec,
7752 &symtab, &nsyms, &strtab, &strtablen))
af3fc3bc 7753 continue;
252b5132 7754
dda8d76d 7755 dump_relocations (filedata, rel_offset, rel_size,
bb4d2ac2
L
7756 symtab, nsyms, strtab, strtablen,
7757 is_rela,
7758 symsec->sh_type == SHT_DYNSYM);
9db70fc3 7759 free (strtab);
d79b3d50
NC
7760 free (symtab);
7761 }
7762 else
dda8d76d 7763 dump_relocations (filedata, rel_offset, rel_size,
32ec8896
NC
7764 NULL, 0, NULL, 0, is_rela,
7765 FALSE /* is_dynamic */);
252b5132 7766
32ec8896 7767 found = TRUE;
252b5132
RH
7768 }
7769 }
7770
7771 if (! found)
45ac8f4f
NC
7772 {
7773 /* Users sometimes forget the -D option, so try to be helpful. */
7774 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
7775 {
978c4450 7776 if (filedata->dynamic_info[dynamic_relocations [i].size])
45ac8f4f 7777 {
ca0e11aa
NC
7778 if (filedata->is_separate)
7779 printf (_("\nThere are no static relocations in linked file '%s'."),
7780 filedata->file_name);
7781 else
7782 printf (_("\nThere are no static relocations in this file."));
45ac8f4f
NC
7783 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7784
7785 break;
7786 }
7787 }
7788 if (i == ARRAY_SIZE (dynamic_relocations))
ca0e11aa
NC
7789 {
7790 if (filedata->is_separate)
7791 printf (_("\nThere are no relocations in linked file '%s'.\n"),
7792 filedata->file_name);
7793 else
7794 printf (_("\nThere are no relocations in this file.\n"));
7795 }
45ac8f4f 7796 }
252b5132
RH
7797 }
7798
32ec8896 7799 return TRUE;
252b5132
RH
7800}
7801
4d6ed7c8
NC
7802/* An absolute address consists of a section and an offset. If the
7803 section is NULL, the offset itself is the address, otherwise, the
7804 address equals to LOAD_ADDRESS(section) + offset. */
7805
7806struct absaddr
948f632f
DA
7807{
7808 unsigned short section;
7809 bfd_vma offset;
7810};
4d6ed7c8 7811
948f632f
DA
7812/* Find the nearest symbol at or below ADDR. Returns the symbol
7813 name, if found, and the offset from the symbol to ADDR. */
4d6ed7c8 7814
4d6ed7c8 7815static void
dda8d76d
NC
7816find_symbol_for_address (Filedata * filedata,
7817 Elf_Internal_Sym * symtab,
7818 unsigned long nsyms,
7819 const char * strtab,
7820 unsigned long strtab_size,
7821 struct absaddr addr,
7822 const char ** symname,
7823 bfd_vma * offset)
4d6ed7c8 7824{
d3ba0551 7825 bfd_vma dist = 0x100000;
2cf0635d 7826 Elf_Internal_Sym * sym;
948f632f
DA
7827 Elf_Internal_Sym * beg;
7828 Elf_Internal_Sym * end;
2cf0635d 7829 Elf_Internal_Sym * best = NULL;
4d6ed7c8 7830
0b6ae522 7831 REMOVE_ARCH_BITS (addr.offset);
948f632f
DA
7832 beg = symtab;
7833 end = symtab + nsyms;
0b6ae522 7834
948f632f 7835 while (beg < end)
4d6ed7c8 7836 {
948f632f
DA
7837 bfd_vma value;
7838
7839 sym = beg + (end - beg) / 2;
0b6ae522 7840
948f632f 7841 value = sym->st_value;
0b6ae522
DJ
7842 REMOVE_ARCH_BITS (value);
7843
948f632f 7844 if (sym->st_name != 0
4d6ed7c8 7845 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
0b6ae522
DJ
7846 && addr.offset >= value
7847 && addr.offset - value < dist)
4d6ed7c8
NC
7848 {
7849 best = sym;
0b6ae522 7850 dist = addr.offset - value;
4d6ed7c8
NC
7851 if (!dist)
7852 break;
7853 }
948f632f
DA
7854
7855 if (addr.offset < value)
7856 end = sym;
7857 else
7858 beg = sym + 1;
4d6ed7c8 7859 }
1b31d05e 7860
4d6ed7c8
NC
7861 if (best)
7862 {
57346661 7863 *symname = (best->st_name >= strtab_size
2b692964 7864 ? _("<corrupt>") : strtab + best->st_name);
4d6ed7c8
NC
7865 *offset = dist;
7866 return;
7867 }
1b31d05e 7868
4d6ed7c8
NC
7869 *symname = NULL;
7870 *offset = addr.offset;
7871}
7872
32ec8896 7873static /* signed */ int
948f632f
DA
7874symcmp (const void *p, const void *q)
7875{
7876 Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
7877 Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
7878
7879 return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
7880}
7881
7882/* Process the unwind section. */
7883
7884#include "unwind-ia64.h"
7885
7886struct ia64_unw_table_entry
7887{
7888 struct absaddr start;
7889 struct absaddr end;
7890 struct absaddr info;
7891};
7892
7893struct ia64_unw_aux_info
7894{
32ec8896
NC
7895 struct ia64_unw_table_entry * table; /* Unwind table. */
7896 unsigned long table_len; /* Length of unwind table. */
7897 unsigned char * info; /* Unwind info. */
7898 unsigned long info_size; /* Size of unwind info. */
7899 bfd_vma info_addr; /* Starting address of unwind info. */
7900 bfd_vma seg_base; /* Starting address of segment. */
7901 Elf_Internal_Sym * symtab; /* The symbol table. */
7902 unsigned long nsyms; /* Number of symbols. */
7903 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
7904 unsigned long nfuns; /* Number of entries in funtab. */
7905 char * strtab; /* The string table. */
7906 unsigned long strtab_size; /* Size of string table. */
948f632f
DA
7907};
7908
32ec8896 7909static bfd_boolean
dda8d76d 7910dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux)
4d6ed7c8 7911{
2cf0635d 7912 struct ia64_unw_table_entry * tp;
948f632f 7913 unsigned long j, nfuns;
4d6ed7c8 7914 int in_body;
32ec8896 7915 bfd_boolean res = TRUE;
7036c0e1 7916
948f632f
DA
7917 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
7918 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
7919 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
7920 aux->funtab[nfuns++] = aux->symtab[j];
7921 aux->nfuns = nfuns;
7922 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
7923
4d6ed7c8
NC
7924 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
7925 {
7926 bfd_vma stamp;
7927 bfd_vma offset;
2cf0635d
NC
7928 const unsigned char * dp;
7929 const unsigned char * head;
53774b7e 7930 const unsigned char * end;
2cf0635d 7931 const char * procname;
4d6ed7c8 7932
dda8d76d 7933 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
57346661 7934 aux->strtab_size, tp->start, &procname, &offset);
4d6ed7c8
NC
7935
7936 fputs ("\n<", stdout);
7937
7938 if (procname)
7939 {
7940 fputs (procname, stdout);
7941
7942 if (offset)
7943 printf ("+%lx", (unsigned long) offset);
7944 }
7945
7946 fputs (">: [", stdout);
7947 print_vma (tp->start.offset, PREFIX_HEX);
7948 fputc ('-', stdout);
7949 print_vma (tp->end.offset, PREFIX_HEX);
86f55779 7950 printf ("], info at +0x%lx\n",
4d6ed7c8
NC
7951 (unsigned long) (tp->info.offset - aux->seg_base));
7952
53774b7e
NC
7953 /* PR 17531: file: 86232b32. */
7954 if (aux->info == NULL)
7955 continue;
7956
97c0a079
AM
7957 offset = tp->info.offset;
7958 if (tp->info.section)
7959 {
7960 if (tp->info.section >= filedata->file_header.e_shnum)
7961 {
7962 warn (_("Invalid section %u in table entry %ld\n"),
7963 tp->info.section, (long) (tp - aux->table));
7964 res = FALSE;
7965 continue;
7966 }
7967 offset += filedata->section_headers[tp->info.section].sh_addr;
7968 }
7969 offset -= aux->info_addr;
53774b7e 7970 /* PR 17531: file: 0997b4d1. */
90679903
AM
7971 if (offset >= aux->info_size
7972 || aux->info_size - offset < 8)
53774b7e
NC
7973 {
7974 warn (_("Invalid offset %lx in table entry %ld\n"),
7975 (long) tp->info.offset, (long) (tp - aux->table));
32ec8896 7976 res = FALSE;
53774b7e
NC
7977 continue;
7978 }
7979
97c0a079 7980 head = aux->info + offset;
a4a00738 7981 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
4d6ed7c8 7982
86f55779 7983 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4d6ed7c8
NC
7984 (unsigned) UNW_VER (stamp),
7985 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
7986 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
7987 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
89fac5e3 7988 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
4d6ed7c8
NC
7989
7990 if (UNW_VER (stamp) != 1)
7991 {
2b692964 7992 printf (_("\tUnknown version.\n"));
4d6ed7c8
NC
7993 continue;
7994 }
7995
7996 in_body = 0;
53774b7e
NC
7997 end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
7998 /* PR 17531: file: 16ceda89. */
7999 if (end > aux->info + aux->info_size)
8000 end = aux->info + aux->info_size;
8001 for (dp = head + 8; dp < end;)
b4477bc8 8002 dp = unw_decode (dp, in_body, & in_body, end);
4d6ed7c8 8003 }
948f632f
DA
8004
8005 free (aux->funtab);
32ec8896
NC
8006
8007 return res;
4d6ed7c8
NC
8008}
8009
53774b7e 8010static bfd_boolean
dda8d76d
NC
8011slurp_ia64_unwind_table (Filedata * filedata,
8012 struct ia64_unw_aux_info * aux,
8013 Elf_Internal_Shdr * sec)
4d6ed7c8 8014{
89fac5e3 8015 unsigned long size, nrelas, i;
2cf0635d
NC
8016 Elf_Internal_Phdr * seg;
8017 struct ia64_unw_table_entry * tep;
8018 Elf_Internal_Shdr * relsec;
8019 Elf_Internal_Rela * rela;
8020 Elf_Internal_Rela * rp;
8021 unsigned char * table;
8022 unsigned char * tp;
8023 Elf_Internal_Sym * sym;
8024 const char * relname;
4d6ed7c8 8025
53774b7e
NC
8026 aux->table_len = 0;
8027
4d6ed7c8
NC
8028 /* First, find the starting address of the segment that includes
8029 this section: */
8030
dda8d76d 8031 if (filedata->file_header.e_phnum)
4d6ed7c8 8032 {
dda8d76d 8033 if (! get_program_headers (filedata))
53774b7e 8034 return FALSE;
4d6ed7c8 8035
dda8d76d
NC
8036 for (seg = filedata->program_headers;
8037 seg < filedata->program_headers + filedata->file_header.e_phnum;
d93f0186 8038 ++seg)
4d6ed7c8
NC
8039 {
8040 if (seg->p_type != PT_LOAD)
8041 continue;
8042
8043 if (sec->sh_addr >= seg->p_vaddr
8044 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
8045 {
8046 aux->seg_base = seg->p_vaddr;
8047 break;
8048 }
8049 }
4d6ed7c8
NC
8050 }
8051
8052 /* Second, build the unwind table from the contents of the unwind section: */
8053 size = sec->sh_size;
dda8d76d 8054 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
3f5e193b 8055 _("unwind table"));
a6e9f9df 8056 if (!table)
53774b7e 8057 return FALSE;
4d6ed7c8 8058
53774b7e 8059 aux->table_len = size / (3 * eh_addr_size);
3f5e193b 8060 aux->table = (struct ia64_unw_table_entry *)
53774b7e 8061 xcmalloc (aux->table_len, sizeof (aux->table[0]));
89fac5e3 8062 tep = aux->table;
53774b7e
NC
8063
8064 for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
4d6ed7c8
NC
8065 {
8066 tep->start.section = SHN_UNDEF;
8067 tep->end.section = SHN_UNDEF;
8068 tep->info.section = SHN_UNDEF;
c6a0c689
AM
8069 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
8070 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
8071 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
4d6ed7c8
NC
8072 tep->start.offset += aux->seg_base;
8073 tep->end.offset += aux->seg_base;
8074 tep->info.offset += aux->seg_base;
8075 }
8076 free (table);
8077
41e92641 8078 /* Third, apply any relocations to the unwind table: */
dda8d76d
NC
8079 for (relsec = filedata->section_headers;
8080 relsec < filedata->section_headers + filedata->file_header.e_shnum;
4d6ed7c8
NC
8081 ++relsec)
8082 {
8083 if (relsec->sh_type != SHT_RELA
dda8d76d
NC
8084 || relsec->sh_info >= filedata->file_header.e_shnum
8085 || filedata->section_headers + relsec->sh_info != sec)
4d6ed7c8
NC
8086 continue;
8087
dda8d76d 8088 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
4d6ed7c8 8089 & rela, & nrelas))
53774b7e
NC
8090 {
8091 free (aux->table);
8092 aux->table = NULL;
8093 aux->table_len = 0;
8094 return FALSE;
8095 }
4d6ed7c8
NC
8096
8097 for (rp = rela; rp < rela + nrelas; ++rp)
8098 {
4770fb94 8099 unsigned int sym_ndx;
726bd37d
AM
8100 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
8101 relname = elf_ia64_reloc_type (r_type);
4d6ed7c8 8102
82b1b41b
NC
8103 /* PR 17531: file: 9fa67536. */
8104 if (relname == NULL)
8105 {
726bd37d 8106 warn (_("Skipping unknown relocation type: %u\n"), r_type);
82b1b41b
NC
8107 continue;
8108 }
948f632f 8109
0112cd26 8110 if (! const_strneq (relname, "R_IA64_SEGREL"))
4d6ed7c8 8111 {
82b1b41b 8112 warn (_("Skipping unexpected relocation type: %s\n"), relname);
4d6ed7c8
NC
8113 continue;
8114 }
8115
89fac5e3 8116 i = rp->r_offset / (3 * eh_addr_size);
4d6ed7c8 8117
53774b7e
NC
8118 /* PR 17531: file: 5bc8d9bf. */
8119 if (i >= aux->table_len)
8120 {
8121 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
8122 continue;
8123 }
8124
4770fb94
AM
8125 sym_ndx = get_reloc_symindex (rp->r_info);
8126 if (sym_ndx >= aux->nsyms)
8127 {
8128 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8129 sym_ndx);
8130 continue;
8131 }
8132 sym = aux->symtab + sym_ndx;
8133
53774b7e 8134 switch (rp->r_offset / eh_addr_size % 3)
4d6ed7c8
NC
8135 {
8136 case 0:
8137 aux->table[i].start.section = sym->st_shndx;
e466bc6e 8138 aux->table[i].start.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
8139 break;
8140 case 1:
8141 aux->table[i].end.section = sym->st_shndx;
e466bc6e 8142 aux->table[i].end.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
8143 break;
8144 case 2:
8145 aux->table[i].info.section = sym->st_shndx;
e466bc6e 8146 aux->table[i].info.offset = rp->r_addend + sym->st_value;
4d6ed7c8
NC
8147 break;
8148 default:
8149 break;
8150 }
8151 }
8152
8153 free (rela);
8154 }
8155
53774b7e 8156 return TRUE;
4d6ed7c8
NC
8157}
8158
32ec8896 8159static bfd_boolean
dda8d76d 8160ia64_process_unwind (Filedata * filedata)
4d6ed7c8 8161{
2cf0635d
NC
8162 Elf_Internal_Shdr * sec;
8163 Elf_Internal_Shdr * unwsec = NULL;
89fac5e3 8164 unsigned long i, unwcount = 0, unwstart = 0;
57346661 8165 struct ia64_unw_aux_info aux;
32ec8896 8166 bfd_boolean res = TRUE;
f1467e33 8167
4d6ed7c8
NC
8168 memset (& aux, 0, sizeof (aux));
8169
dda8d76d 8170 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
4d6ed7c8 8171 {
28d13567 8172 if (sec->sh_type == SHT_SYMTAB)
4d6ed7c8 8173 {
28d13567 8174 if (aux.symtab)
4082ef84 8175 {
28d13567
AM
8176 error (_("Multiple symbol tables encountered\n"));
8177 free (aux.symtab);
8178 aux.symtab = NULL;
4082ef84 8179 free (aux.strtab);
28d13567 8180 aux.strtab = NULL;
4082ef84 8181 }
28d13567
AM
8182 if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms,
8183 &aux.strtab, &aux.strtab_size))
8184 return FALSE;
4d6ed7c8
NC
8185 }
8186 else if (sec->sh_type == SHT_IA_64_UNWIND)
579f31ac
JJ
8187 unwcount++;
8188 }
8189
8190 if (!unwcount)
8191 printf (_("\nThere are no unwind sections in this file.\n"));
8192
8193 while (unwcount-- > 0)
8194 {
2cf0635d 8195 char * suffix;
579f31ac
JJ
8196 size_t len, len2;
8197
dda8d76d
NC
8198 for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL;
8199 i < filedata->file_header.e_shnum; ++i, ++sec)
579f31ac
JJ
8200 if (sec->sh_type == SHT_IA_64_UNWIND)
8201 {
8202 unwsec = sec;
8203 break;
8204 }
4082ef84
NC
8205 /* We have already counted the number of SHT_IA64_UNWIND
8206 sections so the loop above should never fail. */
8207 assert (unwsec != NULL);
579f31ac
JJ
8208
8209 unwstart = i + 1;
8210 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
8211
e4b17d5c
L
8212 if ((unwsec->sh_flags & SHF_GROUP) != 0)
8213 {
8214 /* We need to find which section group it is in. */
4082ef84 8215 struct group_list * g;
e4b17d5c 8216
978c4450
AM
8217 if (filedata->section_headers_groups == NULL
8218 || filedata->section_headers_groups[i] == NULL)
dda8d76d 8219 i = filedata->file_header.e_shnum;
4082ef84 8220 else
e4b17d5c 8221 {
978c4450 8222 g = filedata->section_headers_groups[i]->root;
18bd398b 8223
4082ef84
NC
8224 for (; g != NULL; g = g->next)
8225 {
dda8d76d 8226 sec = filedata->section_headers + g->section_index;
e4b17d5c 8227
b9e920ec
AM
8228 if (SECTION_NAME_VALID (sec)
8229 && streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
4082ef84
NC
8230 break;
8231 }
8232
8233 if (g == NULL)
dda8d76d 8234 i = filedata->file_header.e_shnum;
4082ef84 8235 }
e4b17d5c 8236 }
b9e920ec
AM
8237 else if (SECTION_NAME_VALID (unwsec)
8238 && strneq (SECTION_NAME (unwsec),
8239 ELF_STRING_ia64_unwind_once, len))
579f31ac 8240 {
18bd398b 8241 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
579f31ac
JJ
8242 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
8243 suffix = SECTION_NAME (unwsec) + len;
b9e920ec
AM
8244 for (i = 0, sec = filedata->section_headers;
8245 i < filedata->file_header.e_shnum;
579f31ac 8246 ++i, ++sec)
b9e920ec
AM
8247 if (SECTION_NAME_VALID (sec)
8248 && strneq (SECTION_NAME (sec),
8249 ELF_STRING_ia64_unwind_info_once, len2)
18bd398b 8250 && streq (SECTION_NAME (sec) + len2, suffix))
579f31ac
JJ
8251 break;
8252 }
8253 else
8254 {
8255 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
18bd398b 8256 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
579f31ac
JJ
8257 len = sizeof (ELF_STRING_ia64_unwind) - 1;
8258 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
8259 suffix = "";
b9e920ec
AM
8260 if (SECTION_NAME_VALID (unwsec)
8261 && strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
579f31ac 8262 suffix = SECTION_NAME (unwsec) + len;
b9e920ec
AM
8263 for (i = 0, sec = filedata->section_headers;
8264 i < filedata->file_header.e_shnum;
579f31ac 8265 ++i, ++sec)
b9e920ec
AM
8266 if (SECTION_NAME_VALID (sec)
8267 && strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
18bd398b 8268 && streq (SECTION_NAME (sec) + len2, suffix))
579f31ac
JJ
8269 break;
8270 }
8271
dda8d76d 8272 if (i == filedata->file_header.e_shnum)
579f31ac
JJ
8273 {
8274 printf (_("\nCould not find unwind info section for "));
8275
dda8d76d 8276 if (filedata->string_table == NULL)
579f31ac
JJ
8277 printf ("%d", unwsec->sh_name);
8278 else
dda8d76d 8279 printf ("'%s'", printable_section_name (filedata, unwsec));
579f31ac
JJ
8280 }
8281 else
4d6ed7c8 8282 {
4d6ed7c8 8283 aux.info_addr = sec->sh_addr;
dda8d76d 8284 aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1,
4082ef84
NC
8285 sec->sh_size,
8286 _("unwind info"));
59245841 8287 aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
4d6ed7c8 8288
579f31ac 8289 printf (_("\nUnwind section "));
4d6ed7c8 8290
dda8d76d 8291 if (filedata->string_table == NULL)
579f31ac
JJ
8292 printf ("%d", unwsec->sh_name);
8293 else
dda8d76d 8294 printf ("'%s'", printable_section_name (filedata, unwsec));
4d6ed7c8 8295
579f31ac 8296 printf (_(" at offset 0x%lx contains %lu entries:\n"),
e59b4dfb 8297 (unsigned long) unwsec->sh_offset,
89fac5e3 8298 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
4d6ed7c8 8299
dda8d76d 8300 if (slurp_ia64_unwind_table (filedata, & aux, unwsec)
53774b7e 8301 && aux.table_len > 0)
dda8d76d 8302 dump_ia64_unwind (filedata, & aux);
579f31ac 8303
9db70fc3
AM
8304 free ((char *) aux.table);
8305 free ((char *) aux.info);
579f31ac
JJ
8306 aux.table = NULL;
8307 aux.info = NULL;
8308 }
4d6ed7c8 8309 }
4d6ed7c8 8310
9db70fc3
AM
8311 free (aux.symtab);
8312 free ((char *) aux.strtab);
32ec8896
NC
8313
8314 return res;
4d6ed7c8
NC
8315}
8316
3f5e193b 8317struct hppa_unw_table_entry
32ec8896
NC
8318{
8319 struct absaddr start;
8320 struct absaddr end;
8321 unsigned int Cannot_unwind:1; /* 0 */
8322 unsigned int Millicode:1; /* 1 */
8323 unsigned int Millicode_save_sr0:1; /* 2 */
8324 unsigned int Region_description:2; /* 3..4 */
8325 unsigned int reserved1:1; /* 5 */
8326 unsigned int Entry_SR:1; /* 6 */
8327 unsigned int Entry_FR:4; /* Number saved 7..10 */
8328 unsigned int Entry_GR:5; /* Number saved 11..15 */
8329 unsigned int Args_stored:1; /* 16 */
8330 unsigned int Variable_Frame:1; /* 17 */
8331 unsigned int Separate_Package_Body:1; /* 18 */
8332 unsigned int Frame_Extension_Millicode:1; /* 19 */
8333 unsigned int Stack_Overflow_Check:1; /* 20 */
8334 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
8335 unsigned int Ada_Region:1; /* 22 */
8336 unsigned int cxx_info:1; /* 23 */
8337 unsigned int cxx_try_catch:1; /* 24 */
8338 unsigned int sched_entry_seq:1; /* 25 */
8339 unsigned int reserved2:1; /* 26 */
8340 unsigned int Save_SP:1; /* 27 */
8341 unsigned int Save_RP:1; /* 28 */
8342 unsigned int Save_MRP_in_frame:1; /* 29 */
8343 unsigned int extn_ptr_defined:1; /* 30 */
8344 unsigned int Cleanup_defined:1; /* 31 */
8345
8346 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
8347 unsigned int HP_UX_interrupt_marker:1; /* 1 */
8348 unsigned int Large_frame:1; /* 2 */
8349 unsigned int Pseudo_SP_Set:1; /* 3 */
8350 unsigned int reserved4:1; /* 4 */
8351 unsigned int Total_frame_size:27; /* 5..31 */
8352};
3f5e193b 8353
57346661 8354struct hppa_unw_aux_info
948f632f 8355{
32ec8896
NC
8356 struct hppa_unw_table_entry * table; /* Unwind table. */
8357 unsigned long table_len; /* Length of unwind table. */
8358 bfd_vma seg_base; /* Starting address of segment. */
8359 Elf_Internal_Sym * symtab; /* The symbol table. */
8360 unsigned long nsyms; /* Number of symbols. */
8361 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8362 unsigned long nfuns; /* Number of entries in funtab. */
8363 char * strtab; /* The string table. */
8364 unsigned long strtab_size; /* Size of string table. */
948f632f 8365};
57346661 8366
32ec8896 8367static bfd_boolean
dda8d76d 8368dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux)
57346661 8369{
2cf0635d 8370 struct hppa_unw_table_entry * tp;
948f632f 8371 unsigned long j, nfuns;
32ec8896 8372 bfd_boolean res = TRUE;
948f632f
DA
8373
8374 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
8375 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
8376 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
8377 aux->funtab[nfuns++] = aux->symtab[j];
8378 aux->nfuns = nfuns;
8379 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
57346661 8380
57346661
AM
8381 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
8382 {
8383 bfd_vma offset;
2cf0635d 8384 const char * procname;
57346661 8385
dda8d76d 8386 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
57346661
AM
8387 aux->strtab_size, tp->start, &procname,
8388 &offset);
8389
8390 fputs ("\n<", stdout);
8391
8392 if (procname)
8393 {
8394 fputs (procname, stdout);
8395
8396 if (offset)
8397 printf ("+%lx", (unsigned long) offset);
8398 }
8399
8400 fputs (">: [", stdout);
8401 print_vma (tp->start.offset, PREFIX_HEX);
8402 fputc ('-', stdout);
8403 print_vma (tp->end.offset, PREFIX_HEX);
8404 printf ("]\n\t");
8405
18bd398b
NC
8406#define PF(_m) if (tp->_m) printf (#_m " ");
8407#define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
57346661
AM
8408 PF(Cannot_unwind);
8409 PF(Millicode);
8410 PF(Millicode_save_sr0);
18bd398b 8411 /* PV(Region_description); */
57346661
AM
8412 PF(Entry_SR);
8413 PV(Entry_FR);
8414 PV(Entry_GR);
8415 PF(Args_stored);
8416 PF(Variable_Frame);
8417 PF(Separate_Package_Body);
8418 PF(Frame_Extension_Millicode);
8419 PF(Stack_Overflow_Check);
8420 PF(Two_Instruction_SP_Increment);
8421 PF(Ada_Region);
8422 PF(cxx_info);
8423 PF(cxx_try_catch);
8424 PF(sched_entry_seq);
8425 PF(Save_SP);
8426 PF(Save_RP);
8427 PF(Save_MRP_in_frame);
8428 PF(extn_ptr_defined);
8429 PF(Cleanup_defined);
8430 PF(MPE_XL_interrupt_marker);
8431 PF(HP_UX_interrupt_marker);
8432 PF(Large_frame);
8433 PF(Pseudo_SP_Set);
8434 PV(Total_frame_size);
8435#undef PF
8436#undef PV
8437 }
8438
18bd398b 8439 printf ("\n");
948f632f
DA
8440
8441 free (aux->funtab);
32ec8896
NC
8442
8443 return res;
57346661
AM
8444}
8445
32ec8896 8446static bfd_boolean
dda8d76d
NC
8447slurp_hppa_unwind_table (Filedata * filedata,
8448 struct hppa_unw_aux_info * aux,
8449 Elf_Internal_Shdr * sec)
57346661 8450{
1c0751b2 8451 unsigned long size, unw_ent_size, nentries, nrelas, i;
2cf0635d
NC
8452 Elf_Internal_Phdr * seg;
8453 struct hppa_unw_table_entry * tep;
8454 Elf_Internal_Shdr * relsec;
8455 Elf_Internal_Rela * rela;
8456 Elf_Internal_Rela * rp;
8457 unsigned char * table;
8458 unsigned char * tp;
8459 Elf_Internal_Sym * sym;
8460 const char * relname;
57346661 8461
57346661
AM
8462 /* First, find the starting address of the segment that includes
8463 this section. */
dda8d76d 8464 if (filedata->file_header.e_phnum)
57346661 8465 {
dda8d76d 8466 if (! get_program_headers (filedata))
32ec8896 8467 return FALSE;
57346661 8468
dda8d76d
NC
8469 for (seg = filedata->program_headers;
8470 seg < filedata->program_headers + filedata->file_header.e_phnum;
57346661
AM
8471 ++seg)
8472 {
8473 if (seg->p_type != PT_LOAD)
8474 continue;
8475
8476 if (sec->sh_addr >= seg->p_vaddr
8477 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
8478 {
8479 aux->seg_base = seg->p_vaddr;
8480 break;
8481 }
8482 }
8483 }
8484
8485 /* Second, build the unwind table from the contents of the unwind
8486 section. */
8487 size = sec->sh_size;
dda8d76d 8488 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
3f5e193b 8489 _("unwind table"));
57346661 8490 if (!table)
32ec8896 8491 return FALSE;
57346661 8492
1c0751b2
DA
8493 unw_ent_size = 16;
8494 nentries = size / unw_ent_size;
8495 size = unw_ent_size * nentries;
57346661 8496
e3fdc001 8497 aux->table_len = nentries;
3f5e193b
NC
8498 tep = aux->table = (struct hppa_unw_table_entry *)
8499 xcmalloc (nentries, sizeof (aux->table[0]));
57346661 8500
1c0751b2 8501 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
57346661
AM
8502 {
8503 unsigned int tmp1, tmp2;
8504
8505 tep->start.section = SHN_UNDEF;
8506 tep->end.section = SHN_UNDEF;
8507
1c0751b2
DA
8508 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
8509 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
8510 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
8511 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
8512
8513 tep->start.offset += aux->seg_base;
8514 tep->end.offset += aux->seg_base;
57346661
AM
8515
8516 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
8517 tep->Millicode = (tmp1 >> 30) & 0x1;
8518 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
8519 tep->Region_description = (tmp1 >> 27) & 0x3;
8520 tep->reserved1 = (tmp1 >> 26) & 0x1;
8521 tep->Entry_SR = (tmp1 >> 25) & 0x1;
8522 tep->Entry_FR = (tmp1 >> 21) & 0xf;
8523 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
8524 tep->Args_stored = (tmp1 >> 15) & 0x1;
8525 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
8526 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
8527 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
8528 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
8529 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
8530 tep->Ada_Region = (tmp1 >> 9) & 0x1;
8531 tep->cxx_info = (tmp1 >> 8) & 0x1;
8532 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
8533 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
8534 tep->reserved2 = (tmp1 >> 5) & 0x1;
8535 tep->Save_SP = (tmp1 >> 4) & 0x1;
8536 tep->Save_RP = (tmp1 >> 3) & 0x1;
8537 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
8538 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
8539 tep->Cleanup_defined = tmp1 & 0x1;
8540
8541 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
8542 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
8543 tep->Large_frame = (tmp2 >> 29) & 0x1;
8544 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
8545 tep->reserved4 = (tmp2 >> 27) & 0x1;
8546 tep->Total_frame_size = tmp2 & 0x7ffffff;
57346661
AM
8547 }
8548 free (table);
8549
8550 /* Third, apply any relocations to the unwind table. */
dda8d76d
NC
8551 for (relsec = filedata->section_headers;
8552 relsec < filedata->section_headers + filedata->file_header.e_shnum;
57346661
AM
8553 ++relsec)
8554 {
8555 if (relsec->sh_type != SHT_RELA
dda8d76d
NC
8556 || relsec->sh_info >= filedata->file_header.e_shnum
8557 || filedata->section_headers + relsec->sh_info != sec)
57346661
AM
8558 continue;
8559
dda8d76d 8560 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
57346661 8561 & rela, & nrelas))
32ec8896 8562 return FALSE;
57346661
AM
8563
8564 for (rp = rela; rp < rela + nrelas; ++rp)
8565 {
4770fb94 8566 unsigned int sym_ndx;
726bd37d
AM
8567 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
8568 relname = elf_hppa_reloc_type (r_type);
57346661 8569
726bd37d
AM
8570 if (relname == NULL)
8571 {
8572 warn (_("Skipping unknown relocation type: %u\n"), r_type);
8573 continue;
8574 }
8575
57346661 8576 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
0112cd26 8577 if (! const_strneq (relname, "R_PARISC_SEGREL"))
57346661 8578 {
726bd37d 8579 warn (_("Skipping unexpected relocation type: %s\n"), relname);
57346661
AM
8580 continue;
8581 }
8582
8583 i = rp->r_offset / unw_ent_size;
726bd37d
AM
8584 if (i >= aux->table_len)
8585 {
8586 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
8587 continue;
8588 }
57346661 8589
4770fb94
AM
8590 sym_ndx = get_reloc_symindex (rp->r_info);
8591 if (sym_ndx >= aux->nsyms)
8592 {
8593 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8594 sym_ndx);
8595 continue;
8596 }
8597 sym = aux->symtab + sym_ndx;
8598
43f6cd05 8599 switch ((rp->r_offset % unw_ent_size) / 4)
57346661
AM
8600 {
8601 case 0:
8602 aux->table[i].start.section = sym->st_shndx;
1e456d54 8603 aux->table[i].start.offset = sym->st_value + rp->r_addend;
57346661
AM
8604 break;
8605 case 1:
8606 aux->table[i].end.section = sym->st_shndx;
1e456d54 8607 aux->table[i].end.offset = sym->st_value + rp->r_addend;
57346661
AM
8608 break;
8609 default:
8610 break;
8611 }
8612 }
8613
8614 free (rela);
8615 }
8616
32ec8896 8617 return TRUE;
57346661
AM
8618}
8619
32ec8896 8620static bfd_boolean
dda8d76d 8621hppa_process_unwind (Filedata * filedata)
57346661 8622{
57346661 8623 struct hppa_unw_aux_info aux;
2cf0635d 8624 Elf_Internal_Shdr * unwsec = NULL;
2cf0635d 8625 Elf_Internal_Shdr * sec;
18bd398b 8626 unsigned long i;
32ec8896 8627 bfd_boolean res = TRUE;
57346661 8628
dda8d76d 8629 if (filedata->string_table == NULL)
32ec8896 8630 return FALSE;
1b31d05e
NC
8631
8632 memset (& aux, 0, sizeof (aux));
57346661 8633
dda8d76d 8634 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
57346661 8635 {
28d13567 8636 if (sec->sh_type == SHT_SYMTAB)
57346661 8637 {
28d13567 8638 if (aux.symtab)
4082ef84 8639 {
28d13567
AM
8640 error (_("Multiple symbol tables encountered\n"));
8641 free (aux.symtab);
8642 aux.symtab = NULL;
4082ef84 8643 free (aux.strtab);
28d13567 8644 aux.strtab = NULL;
4082ef84 8645 }
28d13567
AM
8646 if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms,
8647 &aux.strtab, &aux.strtab_size))
8648 return FALSE;
57346661 8649 }
b9e920ec
AM
8650 else if (SECTION_NAME_VALID (sec)
8651 && streq (SECTION_NAME (sec), ".PARISC.unwind"))
57346661
AM
8652 unwsec = sec;
8653 }
8654
8655 if (!unwsec)
8656 printf (_("\nThere are no unwind sections in this file.\n"));
8657
dda8d76d 8658 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
57346661 8659 {
b9e920ec
AM
8660 if (SECTION_NAME_VALID (sec)
8661 && streq (SECTION_NAME (sec), ".PARISC.unwind"))
57346661 8662 {
43f6cd05 8663 unsigned long num_unwind = sec->sh_size / 16;
dda8d76d 8664
d3a49aa8
AM
8665 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8666 "contains %lu entry:\n",
8667 "\nUnwind section '%s' at offset 0x%lx "
8668 "contains %lu entries:\n",
8669 num_unwind),
dda8d76d 8670 printable_section_name (filedata, sec),
57346661 8671 (unsigned long) sec->sh_offset,
d3a49aa8 8672 num_unwind);
57346661 8673
dda8d76d 8674 if (! slurp_hppa_unwind_table (filedata, &aux, sec))
32ec8896 8675 res = FALSE;
66b09c7e
S
8676
8677 if (res && aux.table_len > 0)
32ec8896 8678 {
dda8d76d 8679 if (! dump_hppa_unwind (filedata, &aux))
32ec8896
NC
8680 res = FALSE;
8681 }
57346661 8682
9db70fc3 8683 free ((char *) aux.table);
57346661
AM
8684 aux.table = NULL;
8685 }
8686 }
8687
9db70fc3
AM
8688 free (aux.symtab);
8689 free ((char *) aux.strtab);
32ec8896
NC
8690
8691 return res;
57346661
AM
8692}
8693
0b6ae522
DJ
8694struct arm_section
8695{
a734115a
NC
8696 unsigned char * data; /* The unwind data. */
8697 Elf_Internal_Shdr * sec; /* The cached unwind section header. */
8698 Elf_Internal_Rela * rela; /* The cached relocations for this section. */
8699 unsigned long nrelas; /* The number of relocations. */
8700 unsigned int rel_type; /* REL or RELA ? */
8701 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
0b6ae522
DJ
8702};
8703
8704struct arm_unw_aux_info
8705{
dda8d76d 8706 Filedata * filedata; /* The file containing the unwind sections. */
a734115a
NC
8707 Elf_Internal_Sym * symtab; /* The file's symbol table. */
8708 unsigned long nsyms; /* Number of symbols. */
948f632f
DA
8709 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8710 unsigned long nfuns; /* Number of these symbols. */
a734115a
NC
8711 char * strtab; /* The file's string table. */
8712 unsigned long strtab_size; /* Size of string table. */
0b6ae522
DJ
8713};
8714
8715static const char *
dda8d76d
NC
8716arm_print_vma_and_name (Filedata * filedata,
8717 struct arm_unw_aux_info * aux,
8718 bfd_vma fn,
8719 struct absaddr addr)
0b6ae522
DJ
8720{
8721 const char *procname;
8722 bfd_vma sym_offset;
8723
8724 if (addr.section == SHN_UNDEF)
8725 addr.offset = fn;
8726
dda8d76d 8727 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
0b6ae522
DJ
8728 aux->strtab_size, addr, &procname,
8729 &sym_offset);
8730
8731 print_vma (fn, PREFIX_HEX);
8732
8733 if (procname)
8734 {
8735 fputs (" <", stdout);
8736 fputs (procname, stdout);
8737
8738 if (sym_offset)
8739 printf ("+0x%lx", (unsigned long) sym_offset);
8740 fputc ('>', stdout);
8741 }
8742
8743 return procname;
8744}
8745
8746static void
8747arm_free_section (struct arm_section *arm_sec)
8748{
9db70fc3
AM
8749 free (arm_sec->data);
8750 free (arm_sec->rela);
0b6ae522
DJ
8751}
8752
a734115a
NC
8753/* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8754 cached section and install SEC instead.
8755 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8756 and return its valued in * WORDP, relocating if necessary.
1b31d05e 8757 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
a734115a 8758 relocation's offset in ADDR.
1b31d05e
NC
8759 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8760 into the string table of the symbol associated with the reloc. If no
8761 reloc was applied store -1 there.
8762 5) Return TRUE upon success, FALSE otherwise. */
a734115a
NC
8763
8764static bfd_boolean
dda8d76d
NC
8765get_unwind_section_word (Filedata * filedata,
8766 struct arm_unw_aux_info * aux,
1b31d05e
NC
8767 struct arm_section * arm_sec,
8768 Elf_Internal_Shdr * sec,
8769 bfd_vma word_offset,
8770 unsigned int * wordp,
8771 struct absaddr * addr,
8772 bfd_vma * sym_name)
0b6ae522
DJ
8773{
8774 Elf_Internal_Rela *rp;
8775 Elf_Internal_Sym *sym;
8776 const char * relname;
8777 unsigned int word;
8778 bfd_boolean wrapped;
8779
e0a31db1
NC
8780 if (sec == NULL || arm_sec == NULL)
8781 return FALSE;
8782
0b6ae522
DJ
8783 addr->section = SHN_UNDEF;
8784 addr->offset = 0;
8785
1b31d05e
NC
8786 if (sym_name != NULL)
8787 *sym_name = (bfd_vma) -1;
8788
a734115a 8789 /* If necessary, update the section cache. */
0b6ae522
DJ
8790 if (sec != arm_sec->sec)
8791 {
8792 Elf_Internal_Shdr *relsec;
8793
8794 arm_free_section (arm_sec);
8795
8796 arm_sec->sec = sec;
dda8d76d 8797 arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1,
0b6ae522 8798 sec->sh_size, _("unwind data"));
0b6ae522
DJ
8799 arm_sec->rela = NULL;
8800 arm_sec->nrelas = 0;
8801
dda8d76d
NC
8802 for (relsec = filedata->section_headers;
8803 relsec < filedata->section_headers + filedata->file_header.e_shnum;
0b6ae522
DJ
8804 ++relsec)
8805 {
dda8d76d
NC
8806 if (relsec->sh_info >= filedata->file_header.e_shnum
8807 || filedata->section_headers + relsec->sh_info != sec
1ae40aa4
NC
8808 /* PR 15745: Check the section type as well. */
8809 || (relsec->sh_type != SHT_REL
8810 && relsec->sh_type != SHT_RELA))
0b6ae522
DJ
8811 continue;
8812
a734115a 8813 arm_sec->rel_type = relsec->sh_type;
0b6ae522
DJ
8814 if (relsec->sh_type == SHT_REL)
8815 {
dda8d76d 8816 if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset,
0b6ae522
DJ
8817 relsec->sh_size,
8818 & arm_sec->rela, & arm_sec->nrelas))
a734115a 8819 return FALSE;
0b6ae522 8820 }
1ae40aa4 8821 else /* relsec->sh_type == SHT_RELA */
0b6ae522 8822 {
dda8d76d 8823 if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset,
0b6ae522
DJ
8824 relsec->sh_size,
8825 & arm_sec->rela, & arm_sec->nrelas))
a734115a 8826 return FALSE;
0b6ae522 8827 }
1ae40aa4 8828 break;
0b6ae522
DJ
8829 }
8830
8831 arm_sec->next_rela = arm_sec->rela;
8832 }
8833
a734115a 8834 /* If there is no unwind data we can do nothing. */
0b6ae522 8835 if (arm_sec->data == NULL)
a734115a 8836 return FALSE;
0b6ae522 8837
e0a31db1 8838 /* If the offset is invalid then fail. */
f32ba729
NC
8839 if (/* PR 21343 *//* PR 18879 */
8840 sec->sh_size < 4
8841 || word_offset > (sec->sh_size - 4)
1a915552 8842 || ((bfd_signed_vma) word_offset) < 0)
e0a31db1
NC
8843 return FALSE;
8844
a734115a 8845 /* Get the word at the required offset. */
0b6ae522
DJ
8846 word = byte_get (arm_sec->data + word_offset, 4);
8847
0eff7165
NC
8848 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8849 if (arm_sec->rela == NULL)
8850 {
8851 * wordp = word;
8852 return TRUE;
8853 }
8854
a734115a 8855 /* Look through the relocs to find the one that applies to the provided offset. */
0b6ae522
DJ
8856 wrapped = FALSE;
8857 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
8858 {
8859 bfd_vma prelval, offset;
8860
8861 if (rp->r_offset > word_offset && !wrapped)
8862 {
8863 rp = arm_sec->rela;
8864 wrapped = TRUE;
8865 }
8866 if (rp->r_offset > word_offset)
8867 break;
8868
8869 if (rp->r_offset & 3)
8870 {
8871 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8872 (unsigned long) rp->r_offset);
8873 continue;
8874 }
8875
8876 if (rp->r_offset < word_offset)
8877 continue;
8878
74e1a04b
NC
8879 /* PR 17531: file: 027-161405-0.004 */
8880 if (aux->symtab == NULL)
8881 continue;
8882
0b6ae522
DJ
8883 if (arm_sec->rel_type == SHT_REL)
8884 {
8885 offset = word & 0x7fffffff;
8886 if (offset & 0x40000000)
8887 offset |= ~ (bfd_vma) 0x7fffffff;
8888 }
a734115a 8889 else if (arm_sec->rel_type == SHT_RELA)
0b6ae522 8890 offset = rp->r_addend;
a734115a 8891 else
74e1a04b
NC
8892 {
8893 error (_("Unknown section relocation type %d encountered\n"),
8894 arm_sec->rel_type);
8895 break;
8896 }
0b6ae522 8897
071436c6
NC
8898 /* PR 17531 file: 027-1241568-0.004. */
8899 if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
8900 {
8901 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8902 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
8903 break;
8904 }
8905
8906 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
0b6ae522
DJ
8907 offset += sym->st_value;
8908 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
8909
a734115a 8910 /* Check that we are processing the expected reloc type. */
dda8d76d 8911 if (filedata->file_header.e_machine == EM_ARM)
a734115a
NC
8912 {
8913 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
071436c6
NC
8914 if (relname == NULL)
8915 {
8916 warn (_("Skipping unknown ARM relocation type: %d\n"),
8917 (int) ELF32_R_TYPE (rp->r_info));
8918 continue;
8919 }
a734115a
NC
8920
8921 if (streq (relname, "R_ARM_NONE"))
8922 continue;
0b4362b0 8923
a734115a
NC
8924 if (! streq (relname, "R_ARM_PREL31"))
8925 {
071436c6 8926 warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
a734115a
NC
8927 continue;
8928 }
8929 }
dda8d76d 8930 else if (filedata->file_header.e_machine == EM_TI_C6000)
a734115a
NC
8931 {
8932 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
071436c6
NC
8933 if (relname == NULL)
8934 {
8935 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8936 (int) ELF32_R_TYPE (rp->r_info));
8937 continue;
8938 }
0b4362b0 8939
a734115a
NC
8940 if (streq (relname, "R_C6000_NONE"))
8941 continue;
8942
8943 if (! streq (relname, "R_C6000_PREL31"))
8944 {
071436c6 8945 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
a734115a
NC
8946 continue;
8947 }
8948
8949 prelval >>= 1;
8950 }
8951 else
74e1a04b
NC
8952 {
8953 /* This function currently only supports ARM and TI unwinders. */
8954 warn (_("Only TI and ARM unwinders are currently supported\n"));
8955 break;
8956 }
fa197c1c 8957
0b6ae522
DJ
8958 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
8959 addr->section = sym->st_shndx;
8960 addr->offset = offset;
74e1a04b 8961
1b31d05e
NC
8962 if (sym_name)
8963 * sym_name = sym->st_name;
0b6ae522
DJ
8964 break;
8965 }
8966
8967 *wordp = word;
8968 arm_sec->next_rela = rp;
8969
a734115a 8970 return TRUE;
0b6ae522
DJ
8971}
8972
a734115a
NC
8973static const char *tic6x_unwind_regnames[16] =
8974{
0b4362b0
RM
8975 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8976 "A14", "A13", "A12", "A11", "A10",
a734115a
NC
8977 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8978};
fa197c1c 8979
0b6ae522 8980static void
fa197c1c 8981decode_tic6x_unwind_regmask (unsigned int mask)
0b6ae522 8982{
fa197c1c
PB
8983 int i;
8984
8985 for (i = 12; mask; mask >>= 1, i--)
8986 {
8987 if (mask & 1)
8988 {
8989 fputs (tic6x_unwind_regnames[i], stdout);
8990 if (mask > 1)
8991 fputs (", ", stdout);
8992 }
8993 }
8994}
0b6ae522
DJ
8995
8996#define ADVANCE \
8997 if (remaining == 0 && more_words) \
8998 { \
8999 data_offset += 4; \
dda8d76d 9000 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
1b31d05e 9001 data_offset, & word, & addr, NULL)) \
32ec8896 9002 return FALSE; \
0b6ae522
DJ
9003 remaining = 4; \
9004 more_words--; \
9005 } \
9006
9007#define GET_OP(OP) \
9008 ADVANCE; \
9009 if (remaining) \
9010 { \
9011 remaining--; \
9012 (OP) = word >> 24; \
9013 word <<= 8; \
9014 } \
9015 else \
9016 { \
2b692964 9017 printf (_("[Truncated opcode]\n")); \
32ec8896 9018 return FALSE; \
0b6ae522 9019 } \
cc5914eb 9020 printf ("0x%02x ", OP)
0b6ae522 9021
32ec8896 9022static bfd_boolean
dda8d76d
NC
9023decode_arm_unwind_bytecode (Filedata * filedata,
9024 struct arm_unw_aux_info * aux,
948f632f
DA
9025 unsigned int word,
9026 unsigned int remaining,
9027 unsigned int more_words,
9028 bfd_vma data_offset,
9029 Elf_Internal_Shdr * data_sec,
9030 struct arm_section * data_arm_sec)
fa197c1c
PB
9031{
9032 struct absaddr addr;
32ec8896 9033 bfd_boolean res = TRUE;
0b6ae522
DJ
9034
9035 /* Decode the unwinding instructions. */
9036 while (1)
9037 {
9038 unsigned int op, op2;
9039
9040 ADVANCE;
9041 if (remaining == 0)
9042 break;
9043 remaining--;
9044 op = word >> 24;
9045 word <<= 8;
9046
cc5914eb 9047 printf (" 0x%02x ", op);
0b6ae522
DJ
9048
9049 if ((op & 0xc0) == 0x00)
9050 {
9051 int offset = ((op & 0x3f) << 2) + 4;
61865e30 9052
cc5914eb 9053 printf (" vsp = vsp + %d", offset);
0b6ae522
DJ
9054 }
9055 else if ((op & 0xc0) == 0x40)
9056 {
9057 int offset = ((op & 0x3f) << 2) + 4;
61865e30 9058
cc5914eb 9059 printf (" vsp = vsp - %d", offset);
0b6ae522
DJ
9060 }
9061 else if ((op & 0xf0) == 0x80)
9062 {
9063 GET_OP (op2);
9064 if (op == 0x80 && op2 == 0)
9065 printf (_("Refuse to unwind"));
9066 else
9067 {
9068 unsigned int mask = ((op & 0x0f) << 8) | op2;
32ec8896 9069 bfd_boolean first = TRUE;
0b6ae522 9070 int i;
2b692964 9071
0b6ae522
DJ
9072 printf ("pop {");
9073 for (i = 0; i < 12; i++)
9074 if (mask & (1 << i))
9075 {
9076 if (first)
32ec8896 9077 first = FALSE;
0b6ae522
DJ
9078 else
9079 printf (", ");
9080 printf ("r%d", 4 + i);
9081 }
9082 printf ("}");
9083 }
9084 }
9085 else if ((op & 0xf0) == 0x90)
9086 {
9087 if (op == 0x9d || op == 0x9f)
9088 printf (_(" [Reserved]"));
9089 else
cc5914eb 9090 printf (" vsp = r%d", op & 0x0f);
0b6ae522
DJ
9091 }
9092 else if ((op & 0xf0) == 0xa0)
9093 {
9094 int end = 4 + (op & 0x07);
32ec8896 9095 bfd_boolean first = TRUE;
0b6ae522 9096 int i;
61865e30 9097
0b6ae522
DJ
9098 printf (" pop {");
9099 for (i = 4; i <= end; i++)
9100 {
9101 if (first)
32ec8896 9102 first = FALSE;
0b6ae522
DJ
9103 else
9104 printf (", ");
9105 printf ("r%d", i);
9106 }
9107 if (op & 0x08)
9108 {
1b31d05e 9109 if (!first)
0b6ae522
DJ
9110 printf (", ");
9111 printf ("r14");
9112 }
9113 printf ("}");
9114 }
9115 else if (op == 0xb0)
9116 printf (_(" finish"));
9117 else if (op == 0xb1)
9118 {
9119 GET_OP (op2);
9120 if (op2 == 0 || (op2 & 0xf0) != 0)
9121 printf (_("[Spare]"));
9122 else
9123 {
9124 unsigned int mask = op2 & 0x0f;
32ec8896 9125 bfd_boolean first = TRUE;
0b6ae522 9126 int i;
61865e30 9127
0b6ae522
DJ
9128 printf ("pop {");
9129 for (i = 0; i < 12; i++)
9130 if (mask & (1 << i))
9131 {
9132 if (first)
32ec8896 9133 first = FALSE;
0b6ae522
DJ
9134 else
9135 printf (", ");
9136 printf ("r%d", i);
9137 }
9138 printf ("}");
9139 }
9140 }
9141 else if (op == 0xb2)
9142 {
b115cf96 9143 unsigned char buf[9];
0b6ae522
DJ
9144 unsigned int i, len;
9145 unsigned long offset;
61865e30 9146
b115cf96 9147 for (i = 0; i < sizeof (buf); i++)
0b6ae522
DJ
9148 {
9149 GET_OP (buf[i]);
9150 if ((buf[i] & 0x80) == 0)
9151 break;
9152 }
4082ef84 9153 if (i == sizeof (buf))
32ec8896 9154 {
27a45f42 9155 error (_("corrupt change to vsp\n"));
32ec8896
NC
9156 res = FALSE;
9157 }
4082ef84
NC
9158 else
9159 {
cd30bcef 9160 offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL);
4082ef84
NC
9161 assert (len == i + 1);
9162 offset = offset * 4 + 0x204;
9163 printf ("vsp = vsp + %ld", offset);
9164 }
0b6ae522 9165 }
61865e30 9166 else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
0b6ae522 9167 {
61865e30
NC
9168 unsigned int first, last;
9169
9170 GET_OP (op2);
9171 first = op2 >> 4;
9172 last = op2 & 0x0f;
9173 if (op == 0xc8)
9174 first = first + 16;
9175 printf ("pop {D%d", first);
9176 if (last)
9177 printf ("-D%d", first + last);
9178 printf ("}");
9179 }
9180 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
9181 {
9182 unsigned int count = op & 0x07;
9183
9184 printf ("pop {D8");
9185 if (count)
9186 printf ("-D%d", 8 + count);
9187 printf ("}");
9188 }
9189 else if (op >= 0xc0 && op <= 0xc5)
9190 {
9191 unsigned int count = op & 0x07;
9192
9193 printf (" pop {wR10");
9194 if (count)
9195 printf ("-wR%d", 10 + count);
9196 printf ("}");
9197 }
9198 else if (op == 0xc6)
9199 {
9200 unsigned int first, last;
9201
9202 GET_OP (op2);
9203 first = op2 >> 4;
9204 last = op2 & 0x0f;
9205 printf ("pop {wR%d", first);
9206 if (last)
9207 printf ("-wR%d", first + last);
9208 printf ("}");
9209 }
9210 else if (op == 0xc7)
9211 {
9212 GET_OP (op2);
9213 if (op2 == 0 || (op2 & 0xf0) != 0)
9214 printf (_("[Spare]"));
0b6ae522
DJ
9215 else
9216 {
61865e30 9217 unsigned int mask = op2 & 0x0f;
32ec8896 9218 bfd_boolean first = TRUE;
61865e30
NC
9219 int i;
9220
9221 printf ("pop {");
9222 for (i = 0; i < 4; i++)
9223 if (mask & (1 << i))
9224 {
9225 if (first)
32ec8896 9226 first = FALSE;
61865e30
NC
9227 else
9228 printf (", ");
9229 printf ("wCGR%d", i);
9230 }
9231 printf ("}");
0b6ae522
DJ
9232 }
9233 }
61865e30 9234 else
32ec8896
NC
9235 {
9236 printf (_(" [unsupported opcode]"));
9237 res = FALSE;
9238 }
9239
0b6ae522
DJ
9240 printf ("\n");
9241 }
32ec8896
NC
9242
9243 return res;
fa197c1c
PB
9244}
9245
32ec8896 9246static bfd_boolean
dda8d76d
NC
9247decode_tic6x_unwind_bytecode (Filedata * filedata,
9248 struct arm_unw_aux_info * aux,
948f632f
DA
9249 unsigned int word,
9250 unsigned int remaining,
9251 unsigned int more_words,
9252 bfd_vma data_offset,
9253 Elf_Internal_Shdr * data_sec,
9254 struct arm_section * data_arm_sec)
fa197c1c
PB
9255{
9256 struct absaddr addr;
9257
9258 /* Decode the unwinding instructions. */
9259 while (1)
9260 {
9261 unsigned int op, op2;
9262
9263 ADVANCE;
9264 if (remaining == 0)
9265 break;
9266 remaining--;
9267 op = word >> 24;
9268 word <<= 8;
9269
9cf03b7e 9270 printf (" 0x%02x ", op);
fa197c1c
PB
9271
9272 if ((op & 0xc0) == 0x00)
9273 {
9274 int offset = ((op & 0x3f) << 3) + 8;
9cf03b7e 9275 printf (" sp = sp + %d", offset);
fa197c1c
PB
9276 }
9277 else if ((op & 0xc0) == 0x80)
9278 {
9279 GET_OP (op2);
9280 if (op == 0x80 && op2 == 0)
9281 printf (_("Refuse to unwind"));
9282 else
9283 {
9284 unsigned int mask = ((op & 0x1f) << 8) | op2;
9285 if (op & 0x20)
9286 printf ("pop compact {");
9287 else
9288 printf ("pop {");
9289
9290 decode_tic6x_unwind_regmask (mask);
9291 printf("}");
9292 }
9293 }
9294 else if ((op & 0xf0) == 0xc0)
9295 {
9296 unsigned int reg;
9297 unsigned int nregs;
9298 unsigned int i;
9299 const char *name;
a734115a
NC
9300 struct
9301 {
32ec8896
NC
9302 unsigned int offset;
9303 unsigned int reg;
fa197c1c
PB
9304 } regpos[16];
9305
9306 /* Scan entire instruction first so that GET_OP output is not
9307 interleaved with disassembly. */
9308 nregs = 0;
9309 for (i = 0; nregs < (op & 0xf); i++)
9310 {
9311 GET_OP (op2);
9312 reg = op2 >> 4;
9313 if (reg != 0xf)
9314 {
9315 regpos[nregs].offset = i * 2;
9316 regpos[nregs].reg = reg;
9317 nregs++;
9318 }
9319
9320 reg = op2 & 0xf;
9321 if (reg != 0xf)
9322 {
9323 regpos[nregs].offset = i * 2 + 1;
9324 regpos[nregs].reg = reg;
9325 nregs++;
9326 }
9327 }
9328
9329 printf (_("pop frame {"));
18344509 9330 if (nregs == 0)
fa197c1c 9331 {
18344509
NC
9332 printf (_("*corrupt* - no registers specified"));
9333 }
9334 else
9335 {
9336 reg = nregs - 1;
9337 for (i = i * 2; i > 0; i--)
fa197c1c 9338 {
18344509
NC
9339 if (regpos[reg].offset == i - 1)
9340 {
9341 name = tic6x_unwind_regnames[regpos[reg].reg];
9342 if (reg > 0)
9343 reg--;
9344 }
9345 else
9346 name = _("[pad]");
fa197c1c 9347
18344509
NC
9348 fputs (name, stdout);
9349 if (i > 1)
9350 printf (", ");
9351 }
fa197c1c
PB
9352 }
9353
9354 printf ("}");
9355 }
9356 else if (op == 0xd0)
9357 printf (" MOV FP, SP");
9358 else if (op == 0xd1)
9359 printf (" __c6xabi_pop_rts");
9360 else if (op == 0xd2)
9361 {
9362 unsigned char buf[9];
9363 unsigned int i, len;
9364 unsigned long offset;
a734115a 9365
fa197c1c
PB
9366 for (i = 0; i < sizeof (buf); i++)
9367 {
9368 GET_OP (buf[i]);
9369 if ((buf[i] & 0x80) == 0)
9370 break;
9371 }
0eff7165
NC
9372 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9373 if (i == sizeof (buf))
9374 {
0eff7165 9375 warn (_("Corrupt stack pointer adjustment detected\n"));
32ec8896 9376 return FALSE;
0eff7165 9377 }
948f632f 9378
cd30bcef 9379 offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL);
fa197c1c
PB
9380 assert (len == i + 1);
9381 offset = offset * 8 + 0x408;
9382 printf (_("sp = sp + %ld"), offset);
9383 }
9384 else if ((op & 0xf0) == 0xe0)
9385 {
9386 if ((op & 0x0f) == 7)
9387 printf (" RETURN");
9388 else
9389 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
9390 }
9391 else
9392 {
9393 printf (_(" [unsupported opcode]"));
9394 }
9395 putchar ('\n');
9396 }
32ec8896
NC
9397
9398 return TRUE;
fa197c1c
PB
9399}
9400
9401static bfd_vma
dda8d76d 9402arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where)
fa197c1c
PB
9403{
9404 bfd_vma offset;
9405
9406 offset = word & 0x7fffffff;
9407 if (offset & 0x40000000)
9408 offset |= ~ (bfd_vma) 0x7fffffff;
9409
dda8d76d 9410 if (filedata->file_header.e_machine == EM_TI_C6000)
fa197c1c
PB
9411 offset <<= 1;
9412
9413 return offset + where;
9414}
9415
32ec8896 9416static bfd_boolean
dda8d76d
NC
9417decode_arm_unwind (Filedata * filedata,
9418 struct arm_unw_aux_info * aux,
1b31d05e
NC
9419 unsigned int word,
9420 unsigned int remaining,
9421 bfd_vma data_offset,
9422 Elf_Internal_Shdr * data_sec,
9423 struct arm_section * data_arm_sec)
fa197c1c
PB
9424{
9425 int per_index;
9426 unsigned int more_words = 0;
37e14bc3 9427 struct absaddr addr;
1b31d05e 9428 bfd_vma sym_name = (bfd_vma) -1;
97953bab 9429 bfd_boolean res = TRUE;
fa197c1c
PB
9430
9431 if (remaining == 0)
9432 {
1b31d05e
NC
9433 /* Fetch the first word.
9434 Note - when decoding an object file the address extracted
9435 here will always be 0. So we also pass in the sym_name
9436 parameter so that we can find the symbol associated with
9437 the personality routine. */
dda8d76d 9438 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset,
1b31d05e 9439 & word, & addr, & sym_name))
32ec8896 9440 return FALSE;
1b31d05e 9441
fa197c1c
PB
9442 remaining = 4;
9443 }
c93dbb25
CZ
9444 else
9445 {
9446 addr.section = SHN_UNDEF;
9447 addr.offset = 0;
9448 }
fa197c1c
PB
9449
9450 if ((word & 0x80000000) == 0)
9451 {
9452 /* Expand prel31 for personality routine. */
9453 bfd_vma fn;
9454 const char *procname;
9455
dda8d76d 9456 fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset);
fa197c1c 9457 printf (_(" Personality routine: "));
1b31d05e
NC
9458 if (fn == 0
9459 && addr.section == SHN_UNDEF && addr.offset == 0
9460 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
9461 {
9462 procname = aux->strtab + sym_name;
9463 print_vma (fn, PREFIX_HEX);
9464 if (procname)
9465 {
9466 fputs (" <", stdout);
9467 fputs (procname, stdout);
9468 fputc ('>', stdout);
9469 }
9470 }
9471 else
dda8d76d 9472 procname = arm_print_vma_and_name (filedata, aux, fn, addr);
fa197c1c
PB
9473 fputc ('\n', stdout);
9474
9475 /* The GCC personality routines use the standard compact
9476 encoding, starting with one byte giving the number of
9477 words. */
9478 if (procname != NULL
9479 && (const_strneq (procname, "__gcc_personality_v0")
9480 || const_strneq (procname, "__gxx_personality_v0")
9481 || const_strneq (procname, "__gcj_personality_v0")
9482 || const_strneq (procname, "__gnu_objc_personality_v0")))
9483 {
9484 remaining = 0;
9485 more_words = 1;
9486 ADVANCE;
9487 if (!remaining)
9488 {
9489 printf (_(" [Truncated data]\n"));
32ec8896 9490 return FALSE;
fa197c1c
PB
9491 }
9492 more_words = word >> 24;
9493 word <<= 8;
9494 remaining--;
9495 per_index = -1;
9496 }
9497 else
32ec8896 9498 return TRUE;
fa197c1c
PB
9499 }
9500 else
9501 {
1b31d05e 9502 /* ARM EHABI Section 6.3:
0b4362b0 9503
1b31d05e 9504 An exception-handling table entry for the compact model looks like:
0b4362b0 9505
1b31d05e
NC
9506 31 30-28 27-24 23-0
9507 -- ----- ----- ----
9508 1 0 index Data for personalityRoutine[index] */
9509
dda8d76d 9510 if (filedata->file_header.e_machine == EM_ARM
1b31d05e 9511 && (word & 0x70000000))
32ec8896
NC
9512 {
9513 warn (_("Corrupt ARM compact model table entry: %x \n"), word);
9514 res = FALSE;
9515 }
1b31d05e 9516
fa197c1c 9517 per_index = (word >> 24) & 0x7f;
1b31d05e 9518 printf (_(" Compact model index: %d\n"), per_index);
fa197c1c
PB
9519 if (per_index == 0)
9520 {
9521 more_words = 0;
9522 word <<= 8;
9523 remaining--;
9524 }
9525 else if (per_index < 3)
9526 {
9527 more_words = (word >> 16) & 0xff;
9528 word <<= 16;
9529 remaining -= 2;
9530 }
9531 }
9532
dda8d76d 9533 switch (filedata->file_header.e_machine)
fa197c1c
PB
9534 {
9535 case EM_ARM:
9536 if (per_index < 3)
9537 {
dda8d76d 9538 if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words,
32ec8896
NC
9539 data_offset, data_sec, data_arm_sec))
9540 res = FALSE;
fa197c1c
PB
9541 }
9542 else
1b31d05e
NC
9543 {
9544 warn (_("Unknown ARM compact model index encountered\n"));
9545 printf (_(" [reserved]\n"));
32ec8896 9546 res = FALSE;
1b31d05e 9547 }
fa197c1c
PB
9548 break;
9549
9550 case EM_TI_C6000:
9551 if (per_index < 3)
9552 {
dda8d76d 9553 if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words,
32ec8896
NC
9554 data_offset, data_sec, data_arm_sec))
9555 res = FALSE;
fa197c1c
PB
9556 }
9557 else if (per_index < 5)
9558 {
9559 if (((word >> 17) & 0x7f) == 0x7f)
9560 printf (_(" Restore stack from frame pointer\n"));
9561 else
9562 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
9563 printf (_(" Registers restored: "));
9564 if (per_index == 4)
9565 printf (" (compact) ");
9566 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
9567 putchar ('\n');
9568 printf (_(" Return register: %s\n"),
9569 tic6x_unwind_regnames[word & 0xf]);
9570 }
9571 else
1b31d05e 9572 printf (_(" [reserved (%d)]\n"), per_index);
fa197c1c
PB
9573 break;
9574
9575 default:
74e1a04b 9576 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
dda8d76d 9577 filedata->file_header.e_machine);
32ec8896 9578 res = FALSE;
fa197c1c 9579 }
0b6ae522
DJ
9580
9581 /* Decode the descriptors. Not implemented. */
32ec8896
NC
9582
9583 return res;
0b6ae522
DJ
9584}
9585
32ec8896 9586static bfd_boolean
dda8d76d
NC
9587dump_arm_unwind (Filedata * filedata,
9588 struct arm_unw_aux_info * aux,
9589 Elf_Internal_Shdr * exidx_sec)
0b6ae522
DJ
9590{
9591 struct arm_section exidx_arm_sec, extab_arm_sec;
9592 unsigned int i, exidx_len;
948f632f 9593 unsigned long j, nfuns;
32ec8896 9594 bfd_boolean res = TRUE;
0b6ae522
DJ
9595
9596 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
9597 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
9598 exidx_len = exidx_sec->sh_size / 8;
9599
948f632f
DA
9600 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
9601 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
9602 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
9603 aux->funtab[nfuns++] = aux->symtab[j];
9604 aux->nfuns = nfuns;
9605 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
9606
0b6ae522
DJ
9607 for (i = 0; i < exidx_len; i++)
9608 {
9609 unsigned int exidx_fn, exidx_entry;
9610 struct absaddr fn_addr, entry_addr;
9611 bfd_vma fn;
9612
9613 fputc ('\n', stdout);
9614
dda8d76d 9615 if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
1b31d05e 9616 8 * i, & exidx_fn, & fn_addr, NULL)
dda8d76d 9617 || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
1b31d05e 9618 8 * i + 4, & exidx_entry, & entry_addr, NULL))
0b6ae522 9619 {
948f632f 9620 free (aux->funtab);
1b31d05e
NC
9621 arm_free_section (& exidx_arm_sec);
9622 arm_free_section (& extab_arm_sec);
32ec8896 9623 return FALSE;
0b6ae522
DJ
9624 }
9625
83c257ca
NC
9626 /* ARM EHABI, Section 5:
9627 An index table entry consists of 2 words.
9628 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9629 if (exidx_fn & 0x80000000)
32ec8896
NC
9630 {
9631 warn (_("corrupt index table entry: %x\n"), exidx_fn);
9632 res = FALSE;
9633 }
83c257ca 9634
dda8d76d 9635 fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i);
0b6ae522 9636
dda8d76d 9637 arm_print_vma_and_name (filedata, aux, fn, fn_addr);
0b6ae522
DJ
9638 fputs (": ", stdout);
9639
9640 if (exidx_entry == 1)
9641 {
9642 print_vma (exidx_entry, PREFIX_HEX);
9643 fputs (" [cantunwind]\n", stdout);
9644 }
9645 else if (exidx_entry & 0x80000000)
9646 {
9647 print_vma (exidx_entry, PREFIX_HEX);
9648 fputc ('\n', stdout);
dda8d76d 9649 decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL);
0b6ae522
DJ
9650 }
9651 else
9652 {
8f73510c 9653 bfd_vma table, table_offset = 0;
0b6ae522
DJ
9654 Elf_Internal_Shdr *table_sec;
9655
9656 fputs ("@", stdout);
dda8d76d 9657 table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
0b6ae522
DJ
9658 print_vma (table, PREFIX_HEX);
9659 printf ("\n");
9660
9661 /* Locate the matching .ARM.extab. */
9662 if (entry_addr.section != SHN_UNDEF
dda8d76d 9663 && entry_addr.section < filedata->file_header.e_shnum)
0b6ae522 9664 {
dda8d76d 9665 table_sec = filedata->section_headers + entry_addr.section;
0b6ae522 9666 table_offset = entry_addr.offset;
1a915552
NC
9667 /* PR 18879 */
9668 if (table_offset > table_sec->sh_size
9669 || ((bfd_signed_vma) table_offset) < 0)
9670 {
9671 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9672 (unsigned long) table_offset,
dda8d76d 9673 printable_section_name (filedata, table_sec));
32ec8896 9674 res = FALSE;
1a915552
NC
9675 continue;
9676 }
0b6ae522
DJ
9677 }
9678 else
9679 {
dda8d76d 9680 table_sec = find_section_by_address (filedata, table);
0b6ae522
DJ
9681 if (table_sec != NULL)
9682 table_offset = table - table_sec->sh_addr;
9683 }
32ec8896 9684
0b6ae522
DJ
9685 if (table_sec == NULL)
9686 {
9687 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9688 (unsigned long) table);
32ec8896 9689 res = FALSE;
0b6ae522
DJ
9690 continue;
9691 }
32ec8896 9692
dda8d76d 9693 if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec,
32ec8896
NC
9694 &extab_arm_sec))
9695 res = FALSE;
0b6ae522
DJ
9696 }
9697 }
9698
9699 printf ("\n");
9700
948f632f 9701 free (aux->funtab);
0b6ae522
DJ
9702 arm_free_section (&exidx_arm_sec);
9703 arm_free_section (&extab_arm_sec);
32ec8896
NC
9704
9705 return res;
0b6ae522
DJ
9706}
9707
fa197c1c 9708/* Used for both ARM and C6X unwinding tables. */
1b31d05e 9709
32ec8896 9710static bfd_boolean
dda8d76d 9711arm_process_unwind (Filedata * filedata)
0b6ae522
DJ
9712{
9713 struct arm_unw_aux_info aux;
9714 Elf_Internal_Shdr *unwsec = NULL;
0b6ae522
DJ
9715 Elf_Internal_Shdr *sec;
9716 unsigned long i;
fa197c1c 9717 unsigned int sec_type;
32ec8896 9718 bfd_boolean res = TRUE;
0b6ae522 9719
dda8d76d 9720 switch (filedata->file_header.e_machine)
fa197c1c
PB
9721 {
9722 case EM_ARM:
9723 sec_type = SHT_ARM_EXIDX;
9724 break;
9725
9726 case EM_TI_C6000:
9727 sec_type = SHT_C6000_UNWIND;
9728 break;
9729
0b4362b0 9730 default:
74e1a04b 9731 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
dda8d76d 9732 filedata->file_header.e_machine);
32ec8896 9733 return FALSE;
fa197c1c
PB
9734 }
9735
dda8d76d 9736 if (filedata->string_table == NULL)
32ec8896 9737 return FALSE;
1b31d05e
NC
9738
9739 memset (& aux, 0, sizeof (aux));
dda8d76d 9740 aux.filedata = filedata;
0b6ae522 9741
dda8d76d 9742 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
0b6ae522 9743 {
28d13567 9744 if (sec->sh_type == SHT_SYMTAB)
0b6ae522 9745 {
28d13567 9746 if (aux.symtab)
74e1a04b 9747 {
28d13567
AM
9748 error (_("Multiple symbol tables encountered\n"));
9749 free (aux.symtab);
9750 aux.symtab = NULL;
74e1a04b 9751 free (aux.strtab);
28d13567 9752 aux.strtab = NULL;
74e1a04b 9753 }
28d13567
AM
9754 if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms,
9755 &aux.strtab, &aux.strtab_size))
9756 return FALSE;
0b6ae522 9757 }
fa197c1c 9758 else if (sec->sh_type == sec_type)
0b6ae522
DJ
9759 unwsec = sec;
9760 }
9761
1b31d05e 9762 if (unwsec == NULL)
0b6ae522 9763 printf (_("\nThere are no unwind sections in this file.\n"));
1b31d05e 9764 else
dda8d76d 9765 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
1b31d05e
NC
9766 {
9767 if (sec->sh_type == sec_type)
9768 {
d3a49aa8
AM
9769 unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size);
9770 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9771 "contains %lu entry:\n",
9772 "\nUnwind section '%s' at offset 0x%lx "
9773 "contains %lu entries:\n",
9774 num_unwind),
dda8d76d 9775 printable_section_name (filedata, sec),
1b31d05e 9776 (unsigned long) sec->sh_offset,
d3a49aa8 9777 num_unwind);
0b6ae522 9778
dda8d76d 9779 if (! dump_arm_unwind (filedata, &aux, sec))
32ec8896 9780 res = FALSE;
1b31d05e
NC
9781 }
9782 }
0b6ae522 9783
9db70fc3
AM
9784 free (aux.symtab);
9785 free ((char *) aux.strtab);
32ec8896
NC
9786
9787 return res;
0b6ae522
DJ
9788}
9789
32ec8896 9790static bfd_boolean
dda8d76d 9791process_unwind (Filedata * filedata)
57346661 9792{
2cf0635d
NC
9793 struct unwind_handler
9794 {
32ec8896 9795 unsigned int machtype;
dda8d76d 9796 bfd_boolean (* handler)(Filedata *);
2cf0635d
NC
9797 } handlers[] =
9798 {
0b6ae522 9799 { EM_ARM, arm_process_unwind },
57346661
AM
9800 { EM_IA_64, ia64_process_unwind },
9801 { EM_PARISC, hppa_process_unwind },
fa197c1c 9802 { EM_TI_C6000, arm_process_unwind },
32ec8896 9803 { 0, NULL }
57346661
AM
9804 };
9805 int i;
9806
9807 if (!do_unwind)
32ec8896 9808 return TRUE;
57346661
AM
9809
9810 for (i = 0; handlers[i].handler != NULL; i++)
dda8d76d
NC
9811 if (filedata->file_header.e_machine == handlers[i].machtype)
9812 return handlers[i].handler (filedata);
57346661 9813
1b31d05e 9814 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
dda8d76d 9815 get_machine_name (filedata->file_header.e_machine));
32ec8896 9816 return TRUE;
57346661
AM
9817}
9818
37c18eed
SD
9819static void
9820dynamic_section_aarch64_val (Elf_Internal_Dyn * entry)
9821{
9822 switch (entry->d_tag)
9823 {
9824 case DT_AARCH64_BTI_PLT:
1dbade74 9825 case DT_AARCH64_PAC_PLT:
37c18eed
SD
9826 break;
9827 default:
9828 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9829 break;
9830 }
9831 putchar ('\n');
9832}
9833
252b5132 9834static void
978c4450 9835dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry)
252b5132
RH
9836{
9837 switch (entry->d_tag)
9838 {
9839 case DT_MIPS_FLAGS:
9840 if (entry->d_un.d_val == 0)
4b68bca3 9841 printf (_("NONE"));
252b5132
RH
9842 else
9843 {
9844 static const char * opts[] =
9845 {
9846 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9847 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9848 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9849 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9850 "RLD_ORDER_SAFE"
9851 };
9852 unsigned int cnt;
32ec8896 9853 bfd_boolean first = TRUE;
2b692964 9854
60bca95a 9855 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
252b5132
RH
9856 if (entry->d_un.d_val & (1 << cnt))
9857 {
9858 printf ("%s%s", first ? "" : " ", opts[cnt]);
32ec8896 9859 first = FALSE;
252b5132 9860 }
252b5132
RH
9861 }
9862 break;
103f02d3 9863
252b5132 9864 case DT_MIPS_IVERSION:
978c4450
AM
9865 if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val))
9866 printf (_("Interface Version: %s"),
9867 GET_DYNAMIC_NAME (filedata, entry->d_un.d_val));
252b5132 9868 else
76ca31c0
NC
9869 {
9870 char buf[40];
9871 sprintf_vma (buf, entry->d_un.d_ptr);
9872 /* Note: coded this way so that there is a single string for translation. */
9873 printf (_("<corrupt: %s>"), buf);
9874 }
252b5132 9875 break;
103f02d3 9876
252b5132
RH
9877 case DT_MIPS_TIME_STAMP:
9878 {
d5b07ef4 9879 char timebuf[128];
2cf0635d 9880 struct tm * tmp;
91d6fa6a 9881 time_t atime = entry->d_un.d_val;
82b1b41b 9882
91d6fa6a 9883 tmp = gmtime (&atime);
82b1b41b
NC
9884 /* PR 17531: file: 6accc532. */
9885 if (tmp == NULL)
9886 snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
9887 else
9888 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
9889 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9890 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
4b68bca3 9891 printf (_("Time Stamp: %s"), timebuf);
252b5132
RH
9892 }
9893 break;
103f02d3 9894
252b5132
RH
9895 case DT_MIPS_RLD_VERSION:
9896 case DT_MIPS_LOCAL_GOTNO:
9897 case DT_MIPS_CONFLICTNO:
9898 case DT_MIPS_LIBLISTNO:
9899 case DT_MIPS_SYMTABNO:
9900 case DT_MIPS_UNREFEXTNO:
9901 case DT_MIPS_HIPAGENO:
9902 case DT_MIPS_DELTA_CLASS_NO:
9903 case DT_MIPS_DELTA_INSTANCE_NO:
9904 case DT_MIPS_DELTA_RELOC_NO:
9905 case DT_MIPS_DELTA_SYM_NO:
9906 case DT_MIPS_DELTA_CLASSSYM_NO:
9907 case DT_MIPS_COMPACT_SIZE:
c69075ac 9908 print_vma (entry->d_un.d_val, DEC);
252b5132 9909 break;
103f02d3 9910
f16a9783 9911 case DT_MIPS_XHASH:
978c4450
AM
9912 filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val;
9913 filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
f16a9783
MS
9914 /* Falls through. */
9915
103f02d3 9916 default:
4b68bca3 9917 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
103f02d3 9918 }
4b68bca3 9919 putchar ('\n');
103f02d3
UD
9920}
9921
103f02d3 9922static void
2cf0635d 9923dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
103f02d3
UD
9924{
9925 switch (entry->d_tag)
9926 {
9927 case DT_HP_DLD_FLAGS:
9928 {
9929 static struct
9930 {
9931 long int bit;
2cf0635d 9932 const char * str;
5e220199
NC
9933 }
9934 flags[] =
9935 {
9936 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
9937 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
9938 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
9939 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
9940 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
9941 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
9942 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
9943 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
9944 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
9945 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
eec8f817
DA
9946 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
9947 { DT_HP_GST, "HP_GST" },
9948 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
9949 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
9950 { DT_HP_NODELETE, "HP_NODELETE" },
9951 { DT_HP_GROUP, "HP_GROUP" },
9952 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
5e220199 9953 };
32ec8896 9954 bfd_boolean first = TRUE;
5e220199 9955 size_t cnt;
f7a99963 9956 bfd_vma val = entry->d_un.d_val;
103f02d3 9957
60bca95a 9958 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
103f02d3 9959 if (val & flags[cnt].bit)
30800947
NC
9960 {
9961 if (! first)
9962 putchar (' ');
9963 fputs (flags[cnt].str, stdout);
32ec8896 9964 first = FALSE;
30800947
NC
9965 val ^= flags[cnt].bit;
9966 }
76da6bbe 9967
103f02d3 9968 if (val != 0 || first)
f7a99963
NC
9969 {
9970 if (! first)
9971 putchar (' ');
9972 print_vma (val, HEX);
9973 }
103f02d3
UD
9974 }
9975 break;
76da6bbe 9976
252b5132 9977 default:
f7a99963
NC
9978 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9979 break;
252b5132 9980 }
35b1837e 9981 putchar ('\n');
252b5132
RH
9982}
9983
28f997cf
TG
9984#ifdef BFD64
9985
9986/* VMS vs Unix time offset and factor. */
9987
9988#define VMS_EPOCH_OFFSET 35067168000000000LL
9989#define VMS_GRANULARITY_FACTOR 10000000
dccc31de
AM
9990#ifndef INT64_MIN
9991#define INT64_MIN (-9223372036854775807LL - 1)
9992#endif
28f997cf
TG
9993
9994/* Display a VMS time in a human readable format. */
9995
9996static void
9997print_vms_time (bfd_int64_t vmstime)
9998{
dccc31de 9999 struct tm *tm = NULL;
28f997cf
TG
10000 time_t unxtime;
10001
dccc31de
AM
10002 if (vmstime >= INT64_MIN + VMS_EPOCH_OFFSET)
10003 {
10004 vmstime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
10005 unxtime = vmstime;
10006 if (unxtime == vmstime)
10007 tm = gmtime (&unxtime);
10008 }
10009 if (tm != NULL)
10010 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
10011 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
10012 tm->tm_hour, tm->tm_min, tm->tm_sec);
28f997cf
TG
10013}
10014#endif /* BFD64 */
10015
ecc51f48 10016static void
2cf0635d 10017dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
ecc51f48
NC
10018{
10019 switch (entry->d_tag)
10020 {
0de14b54 10021 case DT_IA_64_PLT_RESERVE:
bdf4d63a 10022 /* First 3 slots reserved. */
ecc51f48
NC
10023 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
10024 printf (" -- ");
10025 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
bdf4d63a
JJ
10026 break;
10027
28f997cf
TG
10028 case DT_IA_64_VMS_LINKTIME:
10029#ifdef BFD64
10030 print_vms_time (entry->d_un.d_val);
10031#endif
10032 break;
10033
10034 case DT_IA_64_VMS_LNKFLAGS:
10035 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
10036 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
10037 printf (" CALL_DEBUG");
10038 if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
10039 printf (" NOP0BUFS");
10040 if (entry->d_un.d_val & VMS_LF_P0IMAGE)
10041 printf (" P0IMAGE");
10042 if (entry->d_un.d_val & VMS_LF_MKTHREADS)
10043 printf (" MKTHREADS");
10044 if (entry->d_un.d_val & VMS_LF_UPCALLS)
10045 printf (" UPCALLS");
10046 if (entry->d_un.d_val & VMS_LF_IMGSTA)
10047 printf (" IMGSTA");
10048 if (entry->d_un.d_val & VMS_LF_INITIALIZE)
10049 printf (" INITIALIZE");
10050 if (entry->d_un.d_val & VMS_LF_MAIN)
10051 printf (" MAIN");
10052 if (entry->d_un.d_val & VMS_LF_EXE_INIT)
10053 printf (" EXE_INIT");
10054 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
10055 printf (" TBK_IN_IMG");
10056 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
10057 printf (" DBG_IN_IMG");
10058 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
10059 printf (" TBK_IN_DSF");
10060 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
10061 printf (" DBG_IN_DSF");
10062 if (entry->d_un.d_val & VMS_LF_SIGNATURES)
10063 printf (" SIGNATURES");
10064 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
10065 printf (" REL_SEG_OFF");
10066 break;
10067
bdf4d63a
JJ
10068 default:
10069 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
10070 break;
ecc51f48 10071 }
bdf4d63a 10072 putchar ('\n');
ecc51f48
NC
10073}
10074
32ec8896 10075static bfd_boolean
dda8d76d 10076get_32bit_dynamic_section (Filedata * filedata)
252b5132 10077{
2cf0635d
NC
10078 Elf32_External_Dyn * edyn;
10079 Elf32_External_Dyn * ext;
10080 Elf_Internal_Dyn * entry;
103f02d3 10081
978c4450
AM
10082 edyn = (Elf32_External_Dyn *) get_data (NULL, filedata,
10083 filedata->dynamic_addr, 1,
10084 filedata->dynamic_size,
10085 _("dynamic section"));
a6e9f9df 10086 if (!edyn)
32ec8896 10087 return FALSE;
103f02d3 10088
071436c6
NC
10089 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10090 might not have the luxury of section headers. Look for the DT_NULL
10091 terminator to determine the number of entries. */
978c4450
AM
10092 for (ext = edyn, filedata->dynamic_nent = 0;
10093 (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size;
ba2685cc
AM
10094 ext++)
10095 {
978c4450 10096 filedata->dynamic_nent++;
ba2685cc
AM
10097 if (BYTE_GET (ext->d_tag) == DT_NULL)
10098 break;
10099 }
252b5132 10100
978c4450
AM
10101 filedata->dynamic_section
10102 = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry));
10103 if (filedata->dynamic_section == NULL)
252b5132 10104 {
8b73c356 10105 error (_("Out of memory allocating space for %lu dynamic entries\n"),
978c4450 10106 (unsigned long) filedata->dynamic_nent);
9ea033b2 10107 free (edyn);
32ec8896 10108 return FALSE;
9ea033b2 10109 }
252b5132 10110
978c4450
AM
10111 for (ext = edyn, entry = filedata->dynamic_section;
10112 entry < filedata->dynamic_section + filedata->dynamic_nent;
fb514b26 10113 ext++, entry++)
9ea033b2 10114 {
fb514b26
AM
10115 entry->d_tag = BYTE_GET (ext->d_tag);
10116 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
252b5132
RH
10117 }
10118
9ea033b2
NC
10119 free (edyn);
10120
32ec8896 10121 return TRUE;
9ea033b2
NC
10122}
10123
32ec8896 10124static bfd_boolean
dda8d76d 10125get_64bit_dynamic_section (Filedata * filedata)
9ea033b2 10126{
2cf0635d
NC
10127 Elf64_External_Dyn * edyn;
10128 Elf64_External_Dyn * ext;
10129 Elf_Internal_Dyn * entry;
103f02d3 10130
071436c6 10131 /* Read in the data. */
978c4450
AM
10132 edyn = (Elf64_External_Dyn *) get_data (NULL, filedata,
10133 filedata->dynamic_addr, 1,
10134 filedata->dynamic_size,
10135 _("dynamic section"));
a6e9f9df 10136 if (!edyn)
32ec8896 10137 return FALSE;
103f02d3 10138
071436c6
NC
10139 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10140 might not have the luxury of section headers. Look for the DT_NULL
10141 terminator to determine the number of entries. */
978c4450 10142 for (ext = edyn, filedata->dynamic_nent = 0;
53c3012c 10143 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
978c4450 10144 (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size;
ba2685cc
AM
10145 ext++)
10146 {
978c4450 10147 filedata->dynamic_nent++;
66543521 10148 if (BYTE_GET (ext->d_tag) == DT_NULL)
ba2685cc
AM
10149 break;
10150 }
252b5132 10151
978c4450
AM
10152 filedata->dynamic_section
10153 = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry));
10154 if (filedata->dynamic_section == NULL)
252b5132 10155 {
8b73c356 10156 error (_("Out of memory allocating space for %lu dynamic entries\n"),
978c4450 10157 (unsigned long) filedata->dynamic_nent);
252b5132 10158 free (edyn);
32ec8896 10159 return FALSE;
252b5132
RH
10160 }
10161
071436c6 10162 /* Convert from external to internal formats. */
978c4450
AM
10163 for (ext = edyn, entry = filedata->dynamic_section;
10164 entry < filedata->dynamic_section + filedata->dynamic_nent;
fb514b26 10165 ext++, entry++)
252b5132 10166 {
66543521
AM
10167 entry->d_tag = BYTE_GET (ext->d_tag);
10168 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
252b5132
RH
10169 }
10170
10171 free (edyn);
10172
32ec8896 10173 return TRUE;
9ea033b2
NC
10174}
10175
e9e44622
JJ
10176static void
10177print_dynamic_flags (bfd_vma flags)
d1133906 10178{
32ec8896 10179 bfd_boolean first = TRUE;
13ae64f3 10180
d1133906
NC
10181 while (flags)
10182 {
10183 bfd_vma flag;
10184
10185 flag = flags & - flags;
10186 flags &= ~ flag;
10187
e9e44622 10188 if (first)
32ec8896 10189 first = FALSE;
e9e44622
JJ
10190 else
10191 putc (' ', stdout);
13ae64f3 10192
d1133906
NC
10193 switch (flag)
10194 {
e9e44622
JJ
10195 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
10196 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
10197 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
10198 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
10199 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
2b692964 10200 default: fputs (_("unknown"), stdout); break;
d1133906
NC
10201 }
10202 }
e9e44622 10203 puts ("");
d1133906
NC
10204}
10205
10ca4b04
L
10206static bfd_vma *
10207get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size)
10208{
10209 unsigned char * e_data;
10210 bfd_vma * i_data;
10211
10212 /* If the size_t type is smaller than the bfd_size_type, eg because
10213 you are building a 32-bit tool on a 64-bit host, then make sure
10214 that when (number) is cast to (size_t) no information is lost. */
10215 if (sizeof (size_t) < sizeof (bfd_size_type)
10216 && (bfd_size_type) ((size_t) number) != number)
10217 {
10218 error (_("Size truncation prevents reading %s elements of size %u\n"),
10219 bfd_vmatoa ("u", number), ent_size);
10220 return NULL;
10221 }
10222
10223 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
10224 attempting to allocate memory when the read is bound to fail. */
10225 if (ent_size * number > filedata->file_size)
10226 {
10227 error (_("Invalid number of dynamic entries: %s\n"),
10228 bfd_vmatoa ("u", number));
10229 return NULL;
10230 }
10231
10232 e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
10233 if (e_data == NULL)
10234 {
10235 error (_("Out of memory reading %s dynamic entries\n"),
10236 bfd_vmatoa ("u", number));
10237 return NULL;
10238 }
10239
10240 if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number)
10241 {
10242 error (_("Unable to read in %s bytes of dynamic data\n"),
10243 bfd_vmatoa ("u", number * ent_size));
10244 free (e_data);
10245 return NULL;
10246 }
10247
10248 i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
10249 if (i_data == NULL)
10250 {
10251 error (_("Out of memory allocating space for %s dynamic entries\n"),
10252 bfd_vmatoa ("u", number));
10253 free (e_data);
10254 return NULL;
10255 }
10256
10257 while (number--)
10258 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
10259
10260 free (e_data);
10261
10262 return i_data;
10263}
10264
10265static unsigned long
10266get_num_dynamic_syms (Filedata * filedata)
10267{
10268 unsigned long num_of_syms = 0;
10269
10270 if (!do_histogram && (!do_using_dynamic || do_dyn_syms))
10271 return num_of_syms;
10272
978c4450 10273 if (filedata->dynamic_info[DT_HASH])
10ca4b04
L
10274 {
10275 unsigned char nb[8];
10276 unsigned char nc[8];
10277 unsigned int hash_ent_size = 4;
10278
10279 if ((filedata->file_header.e_machine == EM_ALPHA
10280 || filedata->file_header.e_machine == EM_S390
10281 || filedata->file_header.e_machine == EM_S390_OLD)
10282 && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64)
10283 hash_ent_size = 8;
10284
10285 if (fseek (filedata->handle,
978c4450
AM
10286 (filedata->archive_file_offset
10287 + offset_from_vma (filedata, filedata->dynamic_info[DT_HASH],
10ca4b04
L
10288 sizeof nb + sizeof nc)),
10289 SEEK_SET))
10290 {
10291 error (_("Unable to seek to start of dynamic information\n"));
10292 goto no_hash;
10293 }
10294
10295 if (fread (nb, hash_ent_size, 1, filedata->handle) != 1)
10296 {
10297 error (_("Failed to read in number of buckets\n"));
10298 goto no_hash;
10299 }
10300
10301 if (fread (nc, hash_ent_size, 1, filedata->handle) != 1)
10302 {
10303 error (_("Failed to read in number of chains\n"));
10304 goto no_hash;
10305 }
10306
978c4450
AM
10307 filedata->nbuckets = byte_get (nb, hash_ent_size);
10308 filedata->nchains = byte_get (nc, hash_ent_size);
10ca4b04 10309
2482f306
AM
10310 if (filedata->nbuckets != 0 && filedata->nchains != 0)
10311 {
10312 filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets,
10313 hash_ent_size);
10314 filedata->chains = get_dynamic_data (filedata, filedata->nchains,
10315 hash_ent_size);
001890e1 10316
2482f306
AM
10317 if (filedata->buckets != NULL && filedata->chains != NULL)
10318 num_of_syms = filedata->nchains;
10319 }
ceb9bf11 10320 no_hash:
10ca4b04
L
10321 if (num_of_syms == 0)
10322 {
9db70fc3
AM
10323 free (filedata->buckets);
10324 filedata->buckets = NULL;
10325 free (filedata->chains);
10326 filedata->chains = NULL;
978c4450 10327 filedata->nbuckets = 0;
10ca4b04
L
10328 }
10329 }
10330
978c4450 10331 if (filedata->dynamic_info_DT_GNU_HASH)
10ca4b04
L
10332 {
10333 unsigned char nb[16];
10334 bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
10335 bfd_vma buckets_vma;
10336 unsigned long hn;
10ca4b04
L
10337
10338 if (fseek (filedata->handle,
978c4450
AM
10339 (filedata->archive_file_offset
10340 + offset_from_vma (filedata,
10341 filedata->dynamic_info_DT_GNU_HASH,
10ca4b04
L
10342 sizeof nb)),
10343 SEEK_SET))
10344 {
10345 error (_("Unable to seek to start of dynamic information\n"));
10ca4b04
L
10346 goto no_gnu_hash;
10347 }
10348
10349 if (fread (nb, 16, 1, filedata->handle) != 1)
10350 {
10351 error (_("Failed to read in number of buckets\n"));
10ca4b04
L
10352 goto no_gnu_hash;
10353 }
10354
978c4450
AM
10355 filedata->ngnubuckets = byte_get (nb, 4);
10356 filedata->gnusymidx = byte_get (nb + 4, 4);
10ca4b04 10357 bitmaskwords = byte_get (nb + 8, 4);
978c4450 10358 buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16;
10ca4b04
L
10359 if (is_32bit_elf)
10360 buckets_vma += bitmaskwords * 4;
10361 else
10362 buckets_vma += bitmaskwords * 8;
10363
10364 if (fseek (filedata->handle,
978c4450 10365 (filedata->archive_file_offset
10ca4b04
L
10366 + offset_from_vma (filedata, buckets_vma, 4)),
10367 SEEK_SET))
10368 {
10369 error (_("Unable to seek to start of dynamic information\n"));
10ca4b04
L
10370 goto no_gnu_hash;
10371 }
10372
978c4450
AM
10373 filedata->gnubuckets
10374 = get_dynamic_data (filedata, filedata->ngnubuckets, 4);
10ca4b04 10375
978c4450 10376 if (filedata->gnubuckets == NULL)
90837ea7 10377 goto no_gnu_hash;
10ca4b04 10378
978c4450
AM
10379 for (i = 0; i < filedata->ngnubuckets; i++)
10380 if (filedata->gnubuckets[i] != 0)
10ca4b04 10381 {
978c4450 10382 if (filedata->gnubuckets[i] < filedata->gnusymidx)
90837ea7 10383 goto no_gnu_hash;
10ca4b04 10384
978c4450
AM
10385 if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain)
10386 maxchain = filedata->gnubuckets[i];
10ca4b04
L
10387 }
10388
10389 if (maxchain == 0xffffffff)
90837ea7 10390 goto no_gnu_hash;
10ca4b04 10391
978c4450 10392 maxchain -= filedata->gnusymidx;
10ca4b04
L
10393
10394 if (fseek (filedata->handle,
978c4450
AM
10395 (filedata->archive_file_offset
10396 + offset_from_vma (filedata,
10397 buckets_vma + 4 * (filedata->ngnubuckets
10398 + maxchain),
10399 4)),
10ca4b04
L
10400 SEEK_SET))
10401 {
10402 error (_("Unable to seek to start of dynamic information\n"));
10ca4b04
L
10403 goto no_gnu_hash;
10404 }
10405
10406 do
10407 {
10408 if (fread (nb, 4, 1, filedata->handle) != 1)
10409 {
10410 error (_("Failed to determine last chain length\n"));
10ca4b04
L
10411 goto no_gnu_hash;
10412 }
10413
10414 if (maxchain + 1 == 0)
90837ea7 10415 goto no_gnu_hash;
10ca4b04
L
10416
10417 ++maxchain;
10418 }
10419 while ((byte_get (nb, 4) & 1) == 0);
10420
10421 if (fseek (filedata->handle,
978c4450
AM
10422 (filedata->archive_file_offset
10423 + offset_from_vma (filedata, (buckets_vma
10424 + 4 * filedata->ngnubuckets),
10425 4)),
10ca4b04
L
10426 SEEK_SET))
10427 {
10428 error (_("Unable to seek to start of dynamic information\n"));
10ca4b04
L
10429 goto no_gnu_hash;
10430 }
10431
978c4450
AM
10432 filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4);
10433 filedata->ngnuchains = maxchain;
10ca4b04 10434
978c4450 10435 if (filedata->gnuchains == NULL)
90837ea7 10436 goto no_gnu_hash;
10ca4b04 10437
978c4450 10438 if (filedata->dynamic_info_DT_MIPS_XHASH)
10ca4b04
L
10439 {
10440 if (fseek (filedata->handle,
978c4450 10441 (filedata->archive_file_offset
10ca4b04 10442 + offset_from_vma (filedata, (buckets_vma
978c4450 10443 + 4 * (filedata->ngnubuckets
10ca4b04
L
10444 + maxchain)), 4)),
10445 SEEK_SET))
10446 {
10447 error (_("Unable to seek to start of dynamic information\n"));
10ca4b04
L
10448 goto no_gnu_hash;
10449 }
10450
978c4450 10451 filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4);
90837ea7
AM
10452 if (filedata->mipsxlat == NULL)
10453 goto no_gnu_hash;
10ca4b04
L
10454 }
10455
978c4450
AM
10456 for (hn = 0; hn < filedata->ngnubuckets; ++hn)
10457 if (filedata->gnubuckets[hn] != 0)
10ca4b04 10458 {
978c4450
AM
10459 bfd_vma si = filedata->gnubuckets[hn];
10460 bfd_vma off = si - filedata->gnusymidx;
10ca4b04
L
10461
10462 do
10463 {
978c4450 10464 if (filedata->dynamic_info_DT_MIPS_XHASH)
10ca4b04 10465 {
c31ab5a0
AM
10466 if (off < filedata->ngnuchains
10467 && filedata->mipsxlat[off] >= num_of_syms)
978c4450 10468 num_of_syms = filedata->mipsxlat[off] + 1;
10ca4b04
L
10469 }
10470 else
10471 {
10472 if (si >= num_of_syms)
10473 num_of_syms = si + 1;
10474 }
10475 si++;
10476 }
978c4450
AM
10477 while (off < filedata->ngnuchains
10478 && (filedata->gnuchains[off++] & 1) == 0);
10ca4b04
L
10479 }
10480
90837ea7 10481 if (num_of_syms == 0)
10ca4b04 10482 {
90837ea7 10483 no_gnu_hash:
9db70fc3
AM
10484 free (filedata->mipsxlat);
10485 filedata->mipsxlat = NULL;
10486 free (filedata->gnuchains);
10487 filedata->gnuchains = NULL;
10488 free (filedata->gnubuckets);
10489 filedata->gnubuckets = NULL;
978c4450
AM
10490 filedata->ngnubuckets = 0;
10491 filedata->ngnuchains = 0;
10ca4b04
L
10492 }
10493 }
10494
10495 return num_of_syms;
10496}
10497
b2d38a17
NC
10498/* Parse and display the contents of the dynamic section. */
10499
32ec8896 10500static bfd_boolean
dda8d76d 10501process_dynamic_section (Filedata * filedata)
9ea033b2 10502{
2cf0635d 10503 Elf_Internal_Dyn * entry;
9ea033b2 10504
978c4450 10505 if (filedata->dynamic_size == 0)
9ea033b2
NC
10506 {
10507 if (do_dynamic)
ca0e11aa
NC
10508 {
10509 if (filedata->is_separate)
10510 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
10511 filedata->file_name);
10512 else
10513 printf (_("\nThere is no dynamic section in this file.\n"));
10514 }
9ea033b2 10515
32ec8896 10516 return TRUE;
9ea033b2
NC
10517 }
10518
10519 if (is_32bit_elf)
10520 {
dda8d76d 10521 if (! get_32bit_dynamic_section (filedata))
32ec8896
NC
10522 return FALSE;
10523 }
10524 else
10525 {
dda8d76d 10526 if (! get_64bit_dynamic_section (filedata))
32ec8896 10527 return FALSE;
9ea033b2 10528 }
9ea033b2 10529
252b5132 10530 /* Find the appropriate symbol table. */
978c4450 10531 if (filedata->dynamic_symbols == NULL || do_histogram)
252b5132 10532 {
2482f306
AM
10533 unsigned long num_of_syms;
10534
978c4450
AM
10535 for (entry = filedata->dynamic_section;
10536 entry < filedata->dynamic_section + filedata->dynamic_nent;
86dba8ee 10537 ++entry)
10ca4b04 10538 if (entry->d_tag == DT_SYMTAB)
978c4450 10539 filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
10ca4b04 10540 else if (entry->d_tag == DT_SYMENT)
978c4450 10541 filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val;
10ca4b04 10542 else if (entry->d_tag == DT_HASH)
978c4450 10543 filedata->dynamic_info[DT_HASH] = entry->d_un.d_val;
10ca4b04 10544 else if (entry->d_tag == DT_GNU_HASH)
978c4450 10545 filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
10ca4b04
L
10546 else if ((filedata->file_header.e_machine == EM_MIPS
10547 || filedata->file_header.e_machine == EM_MIPS_RS3_LE)
10548 && entry->d_tag == DT_MIPS_XHASH)
10549 {
978c4450
AM
10550 filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val;
10551 filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
10ca4b04 10552 }
252b5132 10553
2482f306
AM
10554 num_of_syms = get_num_dynamic_syms (filedata);
10555
10556 if (num_of_syms != 0
10557 && filedata->dynamic_symbols == NULL
10558 && filedata->dynamic_info[DT_SYMTAB]
978c4450 10559 && filedata->dynamic_info[DT_SYMENT])
10ca4b04
L
10560 {
10561 Elf_Internal_Phdr *seg;
2482f306 10562 bfd_vma vma = filedata->dynamic_info[DT_SYMTAB];
252b5132 10563
2482f306
AM
10564 if (! get_program_headers (filedata))
10565 {
10566 error (_("Cannot interpret virtual addresses "
10567 "without program headers.\n"));
10568 return FALSE;
10569 }
252b5132 10570
2482f306
AM
10571 for (seg = filedata->program_headers;
10572 seg < filedata->program_headers + filedata->file_header.e_phnum;
10573 ++seg)
10574 {
10575 if (seg->p_type != PT_LOAD)
10576 continue;
252b5132 10577
2482f306
AM
10578 if (seg->p_offset + seg->p_filesz > filedata->file_size)
10579 {
10580 /* See PR 21379 for a reproducer. */
10581 error (_("Invalid PT_LOAD entry\n"));
10582 return FALSE;
10583 }
252b5132 10584
2482f306
AM
10585 if (vma >= (seg->p_vaddr & -seg->p_align)
10586 && vma < seg->p_vaddr + seg->p_filesz)
10587 {
10588 /* Since we do not know how big the symbol table is,
10589 we default to reading in up to the end of PT_LOAD
10590 segment and processing that. This is overkill, I
10591 know, but it should work. */
10592 Elf_Internal_Shdr section;
10593 section.sh_offset = (vma - seg->p_vaddr
10594 + seg->p_offset);
10595 section.sh_size = (num_of_syms
10596 * filedata->dynamic_info[DT_SYMENT]);
10597 section.sh_entsize = filedata->dynamic_info[DT_SYMENT];
8ac10c5b
L
10598
10599 if (do_checks
10600 && filedata->dynamic_symtab_section != NULL
10601 && ((filedata->dynamic_symtab_section->sh_offset
10602 != section.sh_offset)
10603 || (filedata->dynamic_symtab_section->sh_size
10604 != section.sh_size)
10605 || (filedata->dynamic_symtab_section->sh_entsize
10606 != section.sh_entsize)))
10607 warn (_("\
10608the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
10609
2482f306
AM
10610 section.sh_name = filedata->string_table_length;
10611 filedata->dynamic_symbols
10612 = GET_ELF_SYMBOLS (filedata, &section,
10613 &filedata->num_dynamic_syms);
10614 if (filedata->dynamic_symbols == NULL
10615 || filedata->num_dynamic_syms != num_of_syms)
10616 {
10617 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
10618 return FALSE;
10619 }
10620 break;
10621 }
10622 }
10623 }
10624 }
252b5132
RH
10625
10626 /* Similarly find a string table. */
978c4450
AM
10627 if (filedata->dynamic_strings == NULL)
10628 for (entry = filedata->dynamic_section;
10629 entry < filedata->dynamic_section + filedata->dynamic_nent;
10ca4b04
L
10630 ++entry)
10631 {
10632 if (entry->d_tag == DT_STRTAB)
978c4450 10633 filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val;
252b5132 10634
10ca4b04 10635 if (entry->d_tag == DT_STRSZ)
978c4450 10636 filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val;
252b5132 10637
978c4450
AM
10638 if (filedata->dynamic_info[DT_STRTAB]
10639 && filedata->dynamic_info[DT_STRSZ])
10ca4b04
L
10640 {
10641 unsigned long offset;
978c4450 10642 bfd_size_type str_tab_len = filedata->dynamic_info[DT_STRSZ];
10ca4b04
L
10643
10644 offset = offset_from_vma (filedata,
978c4450 10645 filedata->dynamic_info[DT_STRTAB],
10ca4b04 10646 str_tab_len);
8ac10c5b
L
10647 if (do_checks
10648 && filedata->dynamic_strtab_section
10649 && ((filedata->dynamic_strtab_section->sh_offset
10650 != (file_ptr) offset)
10651 || (filedata->dynamic_strtab_section->sh_size
10652 != str_tab_len)))
10653 warn (_("\
10654the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
10655
978c4450
AM
10656 filedata->dynamic_strings
10657 = (char *) get_data (NULL, filedata, offset, 1, str_tab_len,
10658 _("dynamic string table"));
10659 if (filedata->dynamic_strings == NULL)
10ca4b04
L
10660 {
10661 error (_("Corrupt DT_STRTAB dynamic entry\n"));
10662 break;
10663 }
e3d39609 10664
978c4450 10665 filedata->dynamic_strings_length = str_tab_len;
10ca4b04
L
10666 break;
10667 }
10668 }
252b5132
RH
10669
10670 /* And find the syminfo section if available. */
978c4450 10671 if (filedata->dynamic_syminfo == NULL)
252b5132 10672 {
3e8bba36 10673 unsigned long syminsz = 0;
252b5132 10674
978c4450
AM
10675 for (entry = filedata->dynamic_section;
10676 entry < filedata->dynamic_section + filedata->dynamic_nent;
86dba8ee 10677 ++entry)
252b5132
RH
10678 {
10679 if (entry->d_tag == DT_SYMINENT)
10680 {
10681 /* Note: these braces are necessary to avoid a syntax
10682 error from the SunOS4 C compiler. */
049b0c3a
NC
10683 /* PR binutils/17531: A corrupt file can trigger this test.
10684 So do not use an assert, instead generate an error message. */
10685 if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
071436c6 10686 error (_("Bad value (%d) for SYMINENT entry\n"),
049b0c3a 10687 (int) entry->d_un.d_val);
252b5132
RH
10688 }
10689 else if (entry->d_tag == DT_SYMINSZ)
10690 syminsz = entry->d_un.d_val;
10691 else if (entry->d_tag == DT_SYMINFO)
978c4450
AM
10692 filedata->dynamic_syminfo_offset
10693 = offset_from_vma (filedata, entry->d_un.d_val, syminsz);
252b5132
RH
10694 }
10695
978c4450 10696 if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0)
252b5132 10697 {
2cf0635d
NC
10698 Elf_External_Syminfo * extsyminfo;
10699 Elf_External_Syminfo * extsym;
10700 Elf_Internal_Syminfo * syminfo;
252b5132
RH
10701
10702 /* There is a syminfo section. Read the data. */
3f5e193b 10703 extsyminfo = (Elf_External_Syminfo *)
978c4450
AM
10704 get_data (NULL, filedata, filedata->dynamic_syminfo_offset,
10705 1, syminsz, _("symbol information"));
a6e9f9df 10706 if (!extsyminfo)
32ec8896 10707 return FALSE;
252b5132 10708
978c4450 10709 if (filedata->dynamic_syminfo != NULL)
e3d39609
NC
10710 {
10711 error (_("Multiple dynamic symbol information sections found\n"));
978c4450 10712 free (filedata->dynamic_syminfo);
e3d39609 10713 }
978c4450
AM
10714 filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
10715 if (filedata->dynamic_syminfo == NULL)
252b5132 10716 {
2482f306
AM
10717 error (_("Out of memory allocating %lu bytes "
10718 "for dynamic symbol info\n"),
8b73c356 10719 (unsigned long) syminsz);
32ec8896 10720 return FALSE;
252b5132
RH
10721 }
10722
2482f306
AM
10723 filedata->dynamic_syminfo_nent
10724 = syminsz / sizeof (Elf_External_Syminfo);
978c4450 10725 for (syminfo = filedata->dynamic_syminfo, extsym = extsyminfo;
2482f306
AM
10726 syminfo < (filedata->dynamic_syminfo
10727 + filedata->dynamic_syminfo_nent);
86dba8ee 10728 ++syminfo, ++extsym)
252b5132 10729 {
86dba8ee
AM
10730 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
10731 syminfo->si_flags = BYTE_GET (extsym->si_flags);
252b5132
RH
10732 }
10733
10734 free (extsyminfo);
10735 }
10736 }
10737
978c4450 10738 if (do_dynamic && filedata->dynamic_addr)
ca0e11aa
NC
10739 {
10740 if (filedata->dynamic_nent == 1)
10741 {
10742 if (filedata->is_separate)
10743 printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains 1 entry:\n"),
10744 filedata->file_name,
10745 filedata->dynamic_addr);
10746 else
10747 printf (_("\nDynamic section at offset 0x%lx contains 1 entry:\n"),
10748 filedata->dynamic_addr);
10749 }
10750 else
10751 {
10752 if (filedata->is_separate)
10753 printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n"),
10754 filedata->file_name,
10755 filedata->dynamic_addr,
10756 (unsigned long) filedata->dynamic_nent);
10757 else
10758 printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"),
10759 filedata->dynamic_addr,
10760 (unsigned long) filedata->dynamic_nent);
10761 }
10762 }
252b5132
RH
10763 if (do_dynamic)
10764 printf (_(" Tag Type Name/Value\n"));
10765
978c4450
AM
10766 for (entry = filedata->dynamic_section;
10767 entry < filedata->dynamic_section + filedata->dynamic_nent;
86dba8ee 10768 entry++)
252b5132
RH
10769 {
10770 if (do_dynamic)
f7a99963 10771 {
2cf0635d 10772 const char * dtype;
e699b9ff 10773
f7a99963
NC
10774 putchar (' ');
10775 print_vma (entry->d_tag, FULL_HEX);
dda8d76d 10776 dtype = get_dynamic_type (filedata, entry->d_tag);
e699b9ff 10777 printf (" (%s)%*s", dtype,
32ec8896 10778 ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " ");
f7a99963 10779 }
252b5132
RH
10780
10781 switch (entry->d_tag)
10782 {
d1133906
NC
10783 case DT_FLAGS:
10784 if (do_dynamic)
e9e44622 10785 print_dynamic_flags (entry->d_un.d_val);
d1133906 10786 break;
76da6bbe 10787
252b5132
RH
10788 case DT_AUXILIARY:
10789 case DT_FILTER:
019148e4
L
10790 case DT_CONFIG:
10791 case DT_DEPAUDIT:
10792 case DT_AUDIT:
252b5132
RH
10793 if (do_dynamic)
10794 {
019148e4 10795 switch (entry->d_tag)
b34976b6 10796 {
019148e4
L
10797 case DT_AUXILIARY:
10798 printf (_("Auxiliary library"));
10799 break;
10800
10801 case DT_FILTER:
10802 printf (_("Filter library"));
10803 break;
10804
b34976b6 10805 case DT_CONFIG:
019148e4
L
10806 printf (_("Configuration file"));
10807 break;
10808
10809 case DT_DEPAUDIT:
10810 printf (_("Dependency audit library"));
10811 break;
10812
10813 case DT_AUDIT:
10814 printf (_("Audit library"));
10815 break;
10816 }
252b5132 10817
978c4450
AM
10818 if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val))
10819 printf (": [%s]\n",
10820 GET_DYNAMIC_NAME (filedata, entry->d_un.d_val));
252b5132 10821 else
f7a99963
NC
10822 {
10823 printf (": ");
10824 print_vma (entry->d_un.d_val, PREFIX_HEX);
10825 putchar ('\n');
10826 }
252b5132
RH
10827 }
10828 break;
10829
dcefbbbd 10830 case DT_FEATURE:
252b5132
RH
10831 if (do_dynamic)
10832 {
10833 printf (_("Flags:"));
86f55779 10834
252b5132
RH
10835 if (entry->d_un.d_val == 0)
10836 printf (_(" None\n"));
10837 else
10838 {
10839 unsigned long int val = entry->d_un.d_val;
86f55779 10840
252b5132
RH
10841 if (val & DTF_1_PARINIT)
10842 {
10843 printf (" PARINIT");
10844 val ^= DTF_1_PARINIT;
10845 }
dcefbbbd
L
10846 if (val & DTF_1_CONFEXP)
10847 {
10848 printf (" CONFEXP");
10849 val ^= DTF_1_CONFEXP;
10850 }
252b5132
RH
10851 if (val != 0)
10852 printf (" %lx", val);
10853 puts ("");
10854 }
10855 }
10856 break;
10857
10858 case DT_POSFLAG_1:
10859 if (do_dynamic)
10860 {
10861 printf (_("Flags:"));
86f55779 10862
252b5132
RH
10863 if (entry->d_un.d_val == 0)
10864 printf (_(" None\n"));
10865 else
10866 {
10867 unsigned long int val = entry->d_un.d_val;
86f55779 10868
252b5132
RH
10869 if (val & DF_P1_LAZYLOAD)
10870 {
10871 printf (" LAZYLOAD");
10872 val ^= DF_P1_LAZYLOAD;
10873 }
10874 if (val & DF_P1_GROUPPERM)
10875 {
10876 printf (" GROUPPERM");
10877 val ^= DF_P1_GROUPPERM;
10878 }
10879 if (val != 0)
10880 printf (" %lx", val);
10881 puts ("");
10882 }
10883 }
10884 break;
10885
10886 case DT_FLAGS_1:
10887 if (do_dynamic)
10888 {
10889 printf (_("Flags:"));
10890 if (entry->d_un.d_val == 0)
10891 printf (_(" None\n"));
10892 else
10893 {
10894 unsigned long int val = entry->d_un.d_val;
86f55779 10895
252b5132
RH
10896 if (val & DF_1_NOW)
10897 {
10898 printf (" NOW");
10899 val ^= DF_1_NOW;
10900 }
10901 if (val & DF_1_GLOBAL)
10902 {
10903 printf (" GLOBAL");
10904 val ^= DF_1_GLOBAL;
10905 }
10906 if (val & DF_1_GROUP)
10907 {
10908 printf (" GROUP");
10909 val ^= DF_1_GROUP;
10910 }
10911 if (val & DF_1_NODELETE)
10912 {
10913 printf (" NODELETE");
10914 val ^= DF_1_NODELETE;
10915 }
10916 if (val & DF_1_LOADFLTR)
10917 {
10918 printf (" LOADFLTR");
10919 val ^= DF_1_LOADFLTR;
10920 }
10921 if (val & DF_1_INITFIRST)
10922 {
10923 printf (" INITFIRST");
10924 val ^= DF_1_INITFIRST;
10925 }
10926 if (val & DF_1_NOOPEN)
10927 {
10928 printf (" NOOPEN");
10929 val ^= DF_1_NOOPEN;
10930 }
10931 if (val & DF_1_ORIGIN)
10932 {
10933 printf (" ORIGIN");
10934 val ^= DF_1_ORIGIN;
10935 }
10936 if (val & DF_1_DIRECT)
10937 {
10938 printf (" DIRECT");
10939 val ^= DF_1_DIRECT;
10940 }
10941 if (val & DF_1_TRANS)
10942 {
10943 printf (" TRANS");
10944 val ^= DF_1_TRANS;
10945 }
10946 if (val & DF_1_INTERPOSE)
10947 {
10948 printf (" INTERPOSE");
10949 val ^= DF_1_INTERPOSE;
10950 }
f7db6139 10951 if (val & DF_1_NODEFLIB)
dcefbbbd 10952 {
f7db6139
L
10953 printf (" NODEFLIB");
10954 val ^= DF_1_NODEFLIB;
dcefbbbd
L
10955 }
10956 if (val & DF_1_NODUMP)
10957 {
10958 printf (" NODUMP");
10959 val ^= DF_1_NODUMP;
10960 }
34b60028 10961 if (val & DF_1_CONFALT)
dcefbbbd 10962 {
34b60028
L
10963 printf (" CONFALT");
10964 val ^= DF_1_CONFALT;
10965 }
10966 if (val & DF_1_ENDFILTEE)
10967 {
10968 printf (" ENDFILTEE");
10969 val ^= DF_1_ENDFILTEE;
10970 }
10971 if (val & DF_1_DISPRELDNE)
10972 {
10973 printf (" DISPRELDNE");
10974 val ^= DF_1_DISPRELDNE;
10975 }
10976 if (val & DF_1_DISPRELPND)
10977 {
10978 printf (" DISPRELPND");
10979 val ^= DF_1_DISPRELPND;
10980 }
10981 if (val & DF_1_NODIRECT)
10982 {
10983 printf (" NODIRECT");
10984 val ^= DF_1_NODIRECT;
10985 }
10986 if (val & DF_1_IGNMULDEF)
10987 {
10988 printf (" IGNMULDEF");
10989 val ^= DF_1_IGNMULDEF;
10990 }
10991 if (val & DF_1_NOKSYMS)
10992 {
10993 printf (" NOKSYMS");
10994 val ^= DF_1_NOKSYMS;
10995 }
10996 if (val & DF_1_NOHDR)
10997 {
10998 printf (" NOHDR");
10999 val ^= DF_1_NOHDR;
11000 }
11001 if (val & DF_1_EDITED)
11002 {
11003 printf (" EDITED");
11004 val ^= DF_1_EDITED;
11005 }
11006 if (val & DF_1_NORELOC)
11007 {
11008 printf (" NORELOC");
11009 val ^= DF_1_NORELOC;
11010 }
11011 if (val & DF_1_SYMINTPOSE)
11012 {
11013 printf (" SYMINTPOSE");
11014 val ^= DF_1_SYMINTPOSE;
11015 }
11016 if (val & DF_1_GLOBAUDIT)
11017 {
11018 printf (" GLOBAUDIT");
11019 val ^= DF_1_GLOBAUDIT;
11020 }
11021 if (val & DF_1_SINGLETON)
11022 {
11023 printf (" SINGLETON");
11024 val ^= DF_1_SINGLETON;
dcefbbbd 11025 }
5c383f02
RO
11026 if (val & DF_1_STUB)
11027 {
11028 printf (" STUB");
11029 val ^= DF_1_STUB;
11030 }
11031 if (val & DF_1_PIE)
11032 {
11033 printf (" PIE");
11034 val ^= DF_1_PIE;
11035 }
b1202ffa
L
11036 if (val & DF_1_KMOD)
11037 {
11038 printf (" KMOD");
11039 val ^= DF_1_KMOD;
11040 }
11041 if (val & DF_1_WEAKFILTER)
11042 {
11043 printf (" WEAKFILTER");
11044 val ^= DF_1_WEAKFILTER;
11045 }
11046 if (val & DF_1_NOCOMMON)
11047 {
11048 printf (" NOCOMMON");
11049 val ^= DF_1_NOCOMMON;
11050 }
252b5132
RH
11051 if (val != 0)
11052 printf (" %lx", val);
11053 puts ("");
11054 }
11055 }
11056 break;
11057
11058 case DT_PLTREL:
978c4450 11059 filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val;
252b5132 11060 if (do_dynamic)
dda8d76d 11061 puts (get_dynamic_type (filedata, entry->d_un.d_val));
252b5132
RH
11062 break;
11063
11064 case DT_NULL :
11065 case DT_NEEDED :
11066 case DT_PLTGOT :
11067 case DT_HASH :
11068 case DT_STRTAB :
11069 case DT_SYMTAB :
11070 case DT_RELA :
11071 case DT_INIT :
11072 case DT_FINI :
11073 case DT_SONAME :
11074 case DT_RPATH :
11075 case DT_SYMBOLIC:
11076 case DT_REL :
11077 case DT_DEBUG :
11078 case DT_TEXTREL :
11079 case DT_JMPREL :
019148e4 11080 case DT_RUNPATH :
978c4450 11081 filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val;
252b5132
RH
11082
11083 if (do_dynamic)
11084 {
2cf0635d 11085 char * name;
252b5132 11086
978c4450
AM
11087 if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val))
11088 name = GET_DYNAMIC_NAME (filedata, entry->d_un.d_val);
252b5132 11089 else
d79b3d50 11090 name = NULL;
252b5132
RH
11091
11092 if (name)
11093 {
11094 switch (entry->d_tag)
11095 {
11096 case DT_NEEDED:
11097 printf (_("Shared library: [%s]"), name);
11098
978c4450 11099 if (streq (name, filedata->program_interpreter))
f7a99963 11100 printf (_(" program interpreter"));
252b5132
RH
11101 break;
11102
11103 case DT_SONAME:
f7a99963 11104 printf (_("Library soname: [%s]"), name);
252b5132
RH
11105 break;
11106
11107 case DT_RPATH:
f7a99963 11108 printf (_("Library rpath: [%s]"), name);
252b5132
RH
11109 break;
11110
019148e4
L
11111 case DT_RUNPATH:
11112 printf (_("Library runpath: [%s]"), name);
11113 break;
11114
252b5132 11115 default:
f7a99963
NC
11116 print_vma (entry->d_un.d_val, PREFIX_HEX);
11117 break;
252b5132
RH
11118 }
11119 }
11120 else
f7a99963
NC
11121 print_vma (entry->d_un.d_val, PREFIX_HEX);
11122
11123 putchar ('\n');
252b5132
RH
11124 }
11125 break;
11126
11127 case DT_PLTRELSZ:
11128 case DT_RELASZ :
11129 case DT_STRSZ :
11130 case DT_RELSZ :
11131 case DT_RELAENT :
11132 case DT_SYMENT :
11133 case DT_RELENT :
978c4450 11134 filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val;
1a0670f3 11135 /* Fall through. */
252b5132
RH
11136 case DT_PLTPADSZ:
11137 case DT_MOVEENT :
11138 case DT_MOVESZ :
11139 case DT_INIT_ARRAYSZ:
11140 case DT_FINI_ARRAYSZ:
047b2264
JJ
11141 case DT_GNU_CONFLICTSZ:
11142 case DT_GNU_LIBLISTSZ:
252b5132 11143 if (do_dynamic)
f7a99963
NC
11144 {
11145 print_vma (entry->d_un.d_val, UNSIGNED);
2b692964 11146 printf (_(" (bytes)\n"));
f7a99963 11147 }
252b5132
RH
11148 break;
11149
11150 case DT_VERDEFNUM:
11151 case DT_VERNEEDNUM:
11152 case DT_RELACOUNT:
11153 case DT_RELCOUNT:
11154 if (do_dynamic)
f7a99963
NC
11155 {
11156 print_vma (entry->d_un.d_val, UNSIGNED);
11157 putchar ('\n');
11158 }
252b5132
RH
11159 break;
11160
11161 case DT_SYMINSZ:
11162 case DT_SYMINENT:
11163 case DT_SYMINFO:
11164 case DT_USED:
11165 case DT_INIT_ARRAY:
11166 case DT_FINI_ARRAY:
11167 if (do_dynamic)
11168 {
d79b3d50 11169 if (entry->d_tag == DT_USED
978c4450 11170 && VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val))
252b5132 11171 {
978c4450 11172 char * name = GET_DYNAMIC_NAME (filedata, entry->d_un.d_val);
252b5132 11173
b34976b6 11174 if (*name)
252b5132
RH
11175 {
11176 printf (_("Not needed object: [%s]\n"), name);
11177 break;
11178 }
11179 }
103f02d3 11180
f7a99963
NC
11181 print_vma (entry->d_un.d_val, PREFIX_HEX);
11182 putchar ('\n');
252b5132
RH
11183 }
11184 break;
11185
11186 case DT_BIND_NOW:
11187 /* The value of this entry is ignored. */
35b1837e
AM
11188 if (do_dynamic)
11189 putchar ('\n');
252b5132 11190 break;
103f02d3 11191
047b2264
JJ
11192 case DT_GNU_PRELINKED:
11193 if (do_dynamic)
11194 {
2cf0635d 11195 struct tm * tmp;
91d6fa6a 11196 time_t atime = entry->d_un.d_val;
047b2264 11197
91d6fa6a 11198 tmp = gmtime (&atime);
071436c6
NC
11199 /* PR 17533 file: 041-1244816-0.004. */
11200 if (tmp == NULL)
5a2cbcf4
L
11201 printf (_("<corrupt time val: %lx"),
11202 (unsigned long) atime);
071436c6
NC
11203 else
11204 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
11205 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
11206 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
047b2264
JJ
11207
11208 }
11209 break;
11210
fdc90cb4 11211 case DT_GNU_HASH:
978c4450 11212 filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
fdc90cb4
JJ
11213 if (do_dynamic)
11214 {
11215 print_vma (entry->d_un.d_val, PREFIX_HEX);
11216 putchar ('\n');
11217 }
11218 break;
11219
a5da3dee
VDM
11220 case DT_GNU_FLAGS_1:
11221 if (do_dynamic)
11222 {
11223 printf (_("Flags:"));
11224 if (entry->d_un.d_val == 0)
11225 printf (_(" None\n"));
11226 else
11227 {
11228 unsigned long int val = entry->d_un.d_val;
11229
11230 if (val & DF_GNU_1_UNIQUE)
11231 {
11232 printf (" UNIQUE");
11233 val ^= DF_GNU_1_UNIQUE;
11234 }
11235 if (val != 0)
11236 printf (" %lx", val);
11237 puts ("");
11238 }
11239 }
11240 break;
11241
252b5132
RH
11242 default:
11243 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
978c4450
AM
11244 filedata->version_info[DT_VERSIONTAGIDX (entry->d_tag)]
11245 = entry->d_un.d_val;
252b5132
RH
11246
11247 if (do_dynamic)
11248 {
dda8d76d 11249 switch (filedata->file_header.e_machine)
252b5132 11250 {
37c18eed
SD
11251 case EM_AARCH64:
11252 dynamic_section_aarch64_val (entry);
11253 break;
252b5132 11254 case EM_MIPS:
4fe85591 11255 case EM_MIPS_RS3_LE:
978c4450 11256 dynamic_section_mips_val (filedata, entry);
252b5132 11257 break;
103f02d3 11258 case EM_PARISC:
b2d38a17 11259 dynamic_section_parisc_val (entry);
103f02d3 11260 break;
ecc51f48 11261 case EM_IA_64:
b2d38a17 11262 dynamic_section_ia64_val (entry);
ecc51f48 11263 break;
252b5132 11264 default:
f7a99963
NC
11265 print_vma (entry->d_un.d_val, PREFIX_HEX);
11266 putchar ('\n');
252b5132
RH
11267 }
11268 }
11269 break;
11270 }
11271 }
11272
32ec8896 11273 return TRUE;
252b5132
RH
11274}
11275
11276static char *
d3ba0551 11277get_ver_flags (unsigned int flags)
252b5132 11278{
6d4f21f6 11279 static char buff[128];
252b5132
RH
11280
11281 buff[0] = 0;
11282
11283 if (flags == 0)
11284 return _("none");
11285
11286 if (flags & VER_FLG_BASE)
7bb1ad17 11287 strcat (buff, "BASE");
252b5132
RH
11288
11289 if (flags & VER_FLG_WEAK)
11290 {
11291 if (flags & VER_FLG_BASE)
7bb1ad17 11292 strcat (buff, " | ");
252b5132 11293
7bb1ad17 11294 strcat (buff, "WEAK");
252b5132
RH
11295 }
11296
44ec90b9
RO
11297 if (flags & VER_FLG_INFO)
11298 {
11299 if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
7bb1ad17 11300 strcat (buff, " | ");
44ec90b9 11301
7bb1ad17 11302 strcat (buff, "INFO");
44ec90b9
RO
11303 }
11304
11305 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
7bb1ad17
MR
11306 {
11307 if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
11308 strcat (buff, " | ");
11309
11310 strcat (buff, _("<unknown>"));
11311 }
252b5132
RH
11312
11313 return buff;
11314}
11315
11316/* Display the contents of the version sections. */
98fb390a 11317
32ec8896 11318static bfd_boolean
dda8d76d 11319process_version_sections (Filedata * filedata)
252b5132 11320{
2cf0635d 11321 Elf_Internal_Shdr * section;
b34976b6 11322 unsigned i;
32ec8896 11323 bfd_boolean found = FALSE;
252b5132
RH
11324
11325 if (! do_version)
32ec8896 11326 return TRUE;
252b5132 11327
dda8d76d
NC
11328 for (i = 0, section = filedata->section_headers;
11329 i < filedata->file_header.e_shnum;
b34976b6 11330 i++, section++)
252b5132
RH
11331 {
11332 switch (section->sh_type)
11333 {
11334 case SHT_GNU_verdef:
11335 {
2cf0635d 11336 Elf_External_Verdef * edefs;
452bf675
AM
11337 unsigned long idx;
11338 unsigned long cnt;
2cf0635d 11339 char * endbuf;
252b5132 11340
32ec8896 11341 found = TRUE;
252b5132 11342
ca0e11aa
NC
11343 if (filedata->is_separate)
11344 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
11345 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
11346 section->sh_info),
11347 filedata->file_name,
11348 printable_section_name (filedata, section),
11349 section->sh_info);
11350 else
11351 printf (ngettext ("\nVersion definition section '%s' "
11352 "contains %u entry:\n",
11353 "\nVersion definition section '%s' "
11354 "contains %u entries:\n",
11355 section->sh_info),
11356 printable_section_name (filedata, section),
11357 section->sh_info);
11358
ae9ac79e 11359 printf (_(" Addr: 0x"));
252b5132 11360 printf_vma (section->sh_addr);
233f82cf 11361 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 11362 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 11363 printable_section_name_from_index (filedata, section->sh_link));
252b5132 11364
3f5e193b 11365 edefs = (Elf_External_Verdef *)
dda8d76d 11366 get_data (NULL, filedata, section->sh_offset, 1,section->sh_size,
3f5e193b 11367 _("version definition section"));
a6e9f9df
AM
11368 if (!edefs)
11369 break;
59245841 11370 endbuf = (char *) edefs + section->sh_size;
252b5132 11371
1445030f 11372 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
252b5132 11373 {
2cf0635d
NC
11374 char * vstart;
11375 Elf_External_Verdef * edef;
b34976b6 11376 Elf_Internal_Verdef ent;
2cf0635d 11377 Elf_External_Verdaux * eaux;
b34976b6 11378 Elf_Internal_Verdaux aux;
452bf675 11379 unsigned long isum;
b34976b6 11380 int j;
103f02d3 11381
252b5132 11382 vstart = ((char *) edefs) + idx;
54806181
AM
11383 if (vstart + sizeof (*edef) > endbuf)
11384 break;
252b5132
RH
11385
11386 edef = (Elf_External_Verdef *) vstart;
11387
11388 ent.vd_version = BYTE_GET (edef->vd_version);
11389 ent.vd_flags = BYTE_GET (edef->vd_flags);
11390 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
11391 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
11392 ent.vd_hash = BYTE_GET (edef->vd_hash);
11393 ent.vd_aux = BYTE_GET (edef->vd_aux);
11394 ent.vd_next = BYTE_GET (edef->vd_next);
11395
452bf675 11396 printf (_(" %#06lx: Rev: %d Flags: %s"),
252b5132
RH
11397 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
11398
11399 printf (_(" Index: %d Cnt: %d "),
11400 ent.vd_ndx, ent.vd_cnt);
11401
452bf675 11402 /* Check for overflow. */
1445030f 11403 if (ent.vd_aux > (size_t) (endbuf - vstart))
dd24e3da
NC
11404 break;
11405
252b5132
RH
11406 vstart += ent.vd_aux;
11407
1445030f
AM
11408 if (vstart + sizeof (*eaux) > endbuf)
11409 break;
252b5132
RH
11410 eaux = (Elf_External_Verdaux *) vstart;
11411
11412 aux.vda_name = BYTE_GET (eaux->vda_name);
11413 aux.vda_next = BYTE_GET (eaux->vda_next);
11414
978c4450
AM
11415 if (VALID_DYNAMIC_NAME (filedata, aux.vda_name))
11416 printf (_("Name: %s\n"),
11417 GET_DYNAMIC_NAME (filedata, aux.vda_name));
252b5132
RH
11418 else
11419 printf (_("Name index: %ld\n"), aux.vda_name);
11420
11421 isum = idx + ent.vd_aux;
11422
b34976b6 11423 for (j = 1; j < ent.vd_cnt; j++)
252b5132 11424 {
1445030f
AM
11425 if (aux.vda_next < sizeof (*eaux)
11426 && !(j == ent.vd_cnt - 1 && aux.vda_next == 0))
11427 {
11428 warn (_("Invalid vda_next field of %lx\n"),
11429 aux.vda_next);
11430 j = ent.vd_cnt;
11431 break;
11432 }
dd24e3da 11433 /* Check for overflow. */
7e26601c 11434 if (aux.vda_next > (size_t) (endbuf - vstart))
dd24e3da
NC
11435 break;
11436
252b5132
RH
11437 isum += aux.vda_next;
11438 vstart += aux.vda_next;
11439
54806181
AM
11440 if (vstart + sizeof (*eaux) > endbuf)
11441 break;
1445030f 11442 eaux = (Elf_External_Verdaux *) vstart;
252b5132
RH
11443
11444 aux.vda_name = BYTE_GET (eaux->vda_name);
11445 aux.vda_next = BYTE_GET (eaux->vda_next);
11446
978c4450 11447 if (VALID_DYNAMIC_NAME (filedata, aux.vda_name))
452bf675 11448 printf (_(" %#06lx: Parent %d: %s\n"),
978c4450
AM
11449 isum, j,
11450 GET_DYNAMIC_NAME (filedata, aux.vda_name));
252b5132 11451 else
452bf675 11452 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
252b5132
RH
11453 isum, j, aux.vda_name);
11454 }
dd24e3da 11455
54806181
AM
11456 if (j < ent.vd_cnt)
11457 printf (_(" Version def aux past end of section\n"));
252b5132 11458
c9f02c3e
MR
11459 /* PR 17531:
11460 file: id:000001,src:000172+005151,op:splice,rep:2. */
1445030f
AM
11461 if (ent.vd_next < sizeof (*edef)
11462 && !(cnt == section->sh_info - 1 && ent.vd_next == 0))
11463 {
11464 warn (_("Invalid vd_next field of %lx\n"), ent.vd_next);
11465 cnt = section->sh_info;
11466 break;
11467 }
452bf675 11468 if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx)))
5d921cbd
NC
11469 break;
11470
252b5132
RH
11471 idx += ent.vd_next;
11472 }
dd24e3da 11473
54806181
AM
11474 if (cnt < section->sh_info)
11475 printf (_(" Version definition past end of section\n"));
252b5132
RH
11476
11477 free (edefs);
11478 }
11479 break;
103f02d3 11480
252b5132
RH
11481 case SHT_GNU_verneed:
11482 {
2cf0635d 11483 Elf_External_Verneed * eneed;
452bf675
AM
11484 unsigned long idx;
11485 unsigned long cnt;
2cf0635d 11486 char * endbuf;
252b5132 11487
32ec8896 11488 found = TRUE;
252b5132 11489
ca0e11aa
NC
11490 if (filedata->is_separate)
11491 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
11492 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
11493 section->sh_info),
11494 filedata->file_name,
11495 printable_section_name (filedata, section),
11496 section->sh_info);
11497 else
11498 printf (ngettext ("\nVersion needs section '%s' "
11499 "contains %u entry:\n",
11500 "\nVersion needs section '%s' "
11501 "contains %u entries:\n",
11502 section->sh_info),
11503 printable_section_name (filedata, section),
11504 section->sh_info);
11505
252b5132
RH
11506 printf (_(" Addr: 0x"));
11507 printf_vma (section->sh_addr);
72de5009 11508 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 11509 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 11510 printable_section_name_from_index (filedata, section->sh_link));
252b5132 11511
dda8d76d 11512 eneed = (Elf_External_Verneed *) get_data (NULL, filedata,
3f5e193b
NC
11513 section->sh_offset, 1,
11514 section->sh_size,
9cf03b7e 11515 _("Version Needs section"));
a6e9f9df
AM
11516 if (!eneed)
11517 break;
59245841 11518 endbuf = (char *) eneed + section->sh_size;
252b5132
RH
11519
11520 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
11521 {
2cf0635d 11522 Elf_External_Verneed * entry;
b34976b6 11523 Elf_Internal_Verneed ent;
452bf675 11524 unsigned long isum;
b34976b6 11525 int j;
2cf0635d 11526 char * vstart;
252b5132
RH
11527
11528 vstart = ((char *) eneed) + idx;
54806181
AM
11529 if (vstart + sizeof (*entry) > endbuf)
11530 break;
252b5132
RH
11531
11532 entry = (Elf_External_Verneed *) vstart;
11533
11534 ent.vn_version = BYTE_GET (entry->vn_version);
11535 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
11536 ent.vn_file = BYTE_GET (entry->vn_file);
11537 ent.vn_aux = BYTE_GET (entry->vn_aux);
11538 ent.vn_next = BYTE_GET (entry->vn_next);
11539
452bf675 11540 printf (_(" %#06lx: Version: %d"), idx, ent.vn_version);
252b5132 11541
978c4450
AM
11542 if (VALID_DYNAMIC_NAME (filedata, ent.vn_file))
11543 printf (_(" File: %s"),
11544 GET_DYNAMIC_NAME (filedata, ent.vn_file));
252b5132
RH
11545 else
11546 printf (_(" File: %lx"), ent.vn_file);
11547
11548 printf (_(" Cnt: %d\n"), ent.vn_cnt);
11549
dd24e3da 11550 /* Check for overflow. */
7e26601c 11551 if (ent.vn_aux > (size_t) (endbuf - vstart))
dd24e3da 11552 break;
252b5132
RH
11553 vstart += ent.vn_aux;
11554
11555 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
11556 {
2cf0635d 11557 Elf_External_Vernaux * eaux;
b34976b6 11558 Elf_Internal_Vernaux aux;
252b5132 11559
54806181
AM
11560 if (vstart + sizeof (*eaux) > endbuf)
11561 break;
252b5132
RH
11562 eaux = (Elf_External_Vernaux *) vstart;
11563
11564 aux.vna_hash = BYTE_GET (eaux->vna_hash);
11565 aux.vna_flags = BYTE_GET (eaux->vna_flags);
11566 aux.vna_other = BYTE_GET (eaux->vna_other);
11567 aux.vna_name = BYTE_GET (eaux->vna_name);
11568 aux.vna_next = BYTE_GET (eaux->vna_next);
11569
978c4450 11570 if (VALID_DYNAMIC_NAME (filedata, aux.vna_name))
452bf675 11571 printf (_(" %#06lx: Name: %s"),
978c4450 11572 isum, GET_DYNAMIC_NAME (filedata, aux.vna_name));
252b5132 11573 else
452bf675 11574 printf (_(" %#06lx: Name index: %lx"),
252b5132
RH
11575 isum, aux.vna_name);
11576
11577 printf (_(" Flags: %s Version: %d\n"),
11578 get_ver_flags (aux.vna_flags), aux.vna_other);
11579
1445030f
AM
11580 if (aux.vna_next < sizeof (*eaux)
11581 && !(j == ent.vn_cnt - 1 && aux.vna_next == 0))
53774b7e
NC
11582 {
11583 warn (_("Invalid vna_next field of %lx\n"),
11584 aux.vna_next);
11585 j = ent.vn_cnt;
11586 break;
11587 }
1445030f
AM
11588 /* Check for overflow. */
11589 if (aux.vna_next > (size_t) (endbuf - vstart))
11590 break;
252b5132
RH
11591 isum += aux.vna_next;
11592 vstart += aux.vna_next;
11593 }
9cf03b7e 11594
54806181 11595 if (j < ent.vn_cnt)
f9a6a8f0 11596 warn (_("Missing Version Needs auxiliary information\n"));
252b5132 11597
1445030f
AM
11598 if (ent.vn_next < sizeof (*entry)
11599 && !(cnt == section->sh_info - 1 && ent.vn_next == 0))
c24cf8b6 11600 {
452bf675 11601 warn (_("Invalid vn_next field of %lx\n"), ent.vn_next);
c24cf8b6
NC
11602 cnt = section->sh_info;
11603 break;
11604 }
1445030f
AM
11605 if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx)))
11606 break;
252b5132
RH
11607 idx += ent.vn_next;
11608 }
9cf03b7e 11609
54806181 11610 if (cnt < section->sh_info)
9cf03b7e 11611 warn (_("Missing Version Needs information\n"));
103f02d3 11612
252b5132
RH
11613 free (eneed);
11614 }
11615 break;
11616
11617 case SHT_GNU_versym:
11618 {
2cf0635d 11619 Elf_Internal_Shdr * link_section;
8b73c356
NC
11620 size_t total;
11621 unsigned int cnt;
2cf0635d
NC
11622 unsigned char * edata;
11623 unsigned short * data;
11624 char * strtab;
11625 Elf_Internal_Sym * symbols;
11626 Elf_Internal_Shdr * string_sec;
ba5cdace 11627 unsigned long num_syms;
d3ba0551 11628 long off;
252b5132 11629
dda8d76d 11630 if (section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
11631 break;
11632
dda8d76d 11633 link_section = filedata->section_headers + section->sh_link;
08d8fa11 11634 total = section->sh_size / sizeof (Elf_External_Versym);
252b5132 11635
dda8d76d 11636 if (link_section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
11637 break;
11638
32ec8896 11639 found = TRUE;
252b5132 11640
dda8d76d 11641 symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms);
dd24e3da
NC
11642 if (symbols == NULL)
11643 break;
252b5132 11644
dda8d76d 11645 string_sec = filedata->section_headers + link_section->sh_link;
252b5132 11646
dda8d76d 11647 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
3f5e193b
NC
11648 string_sec->sh_size,
11649 _("version string table"));
a6e9f9df 11650 if (!strtab)
0429c154
MS
11651 {
11652 free (symbols);
11653 break;
11654 }
252b5132 11655
ca0e11aa
NC
11656 if (filedata->is_separate)
11657 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n",
11658 "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n",
11659 total),
11660 filedata->file_name,
11661 printable_section_name (filedata, section),
11662 (unsigned long) total);
11663 else
11664 printf (ngettext ("\nVersion symbols section '%s' "
11665 "contains %lu entry:\n",
11666 "\nVersion symbols section '%s' "
11667 "contains %lu entries:\n",
11668 total),
11669 printable_section_name (filedata, section),
11670 (unsigned long) total);
252b5132 11671
ae9ac79e 11672 printf (_(" Addr: 0x"));
252b5132 11673 printf_vma (section->sh_addr);
72de5009 11674 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
1b228002 11675 (unsigned long) section->sh_offset, section->sh_link,
dda8d76d 11676 printable_section_name (filedata, link_section));
252b5132 11677
dda8d76d 11678 off = offset_from_vma (filedata,
978c4450 11679 filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
d3ba0551 11680 total * sizeof (short));
95099889
AM
11681 edata = (unsigned char *) get_data (NULL, filedata, off,
11682 sizeof (short), total,
11683 _("version symbol data"));
a6e9f9df
AM
11684 if (!edata)
11685 {
11686 free (strtab);
0429c154 11687 free (symbols);
a6e9f9df
AM
11688 break;
11689 }
252b5132 11690
3f5e193b 11691 data = (short unsigned int *) cmalloc (total, sizeof (short));
252b5132
RH
11692
11693 for (cnt = total; cnt --;)
b34976b6
AM
11694 data[cnt] = byte_get (edata + cnt * sizeof (short),
11695 sizeof (short));
252b5132
RH
11696
11697 free (edata);
11698
11699 for (cnt = 0; cnt < total; cnt += 4)
11700 {
11701 int j, nn;
ab273396
AM
11702 char *name;
11703 char *invalid = _("*invalid*");
252b5132
RH
11704
11705 printf (" %03x:", cnt);
11706
11707 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
b34976b6 11708 switch (data[cnt + j])
252b5132
RH
11709 {
11710 case 0:
11711 fputs (_(" 0 (*local*) "), stdout);
11712 break;
11713
11714 case 1:
11715 fputs (_(" 1 (*global*) "), stdout);
11716 break;
11717
11718 default:
c244d050
NC
11719 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
11720 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
252b5132 11721
dd24e3da 11722 /* If this index value is greater than the size of the symbols
ba5cdace
NC
11723 array, break to avoid an out-of-bounds read. */
11724 if ((unsigned long)(cnt + j) >= num_syms)
dd24e3da
NC
11725 {
11726 warn (_("invalid index into symbol array\n"));
11727 break;
11728 }
11729
ab273396 11730 name = NULL;
978c4450 11731 if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
252b5132 11732 {
b34976b6
AM
11733 Elf_Internal_Verneed ivn;
11734 unsigned long offset;
252b5132 11735
d93f0186 11736 offset = offset_from_vma
978c4450
AM
11737 (filedata,
11738 filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
d93f0186 11739 sizeof (Elf_External_Verneed));
252b5132 11740
b34976b6 11741 do
252b5132 11742 {
b34976b6
AM
11743 Elf_Internal_Vernaux ivna;
11744 Elf_External_Verneed evn;
11745 Elf_External_Vernaux evna;
11746 unsigned long a_off;
252b5132 11747
dda8d76d 11748 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
59245841
NC
11749 _("version need")) == NULL)
11750 break;
0b4362b0 11751
252b5132
RH
11752 ivn.vn_aux = BYTE_GET (evn.vn_aux);
11753 ivn.vn_next = BYTE_GET (evn.vn_next);
11754
11755 a_off = offset + ivn.vn_aux;
11756
11757 do
11758 {
dda8d76d 11759 if (get_data (&evna, filedata, a_off, sizeof (evna),
59245841
NC
11760 1, _("version need aux (2)")) == NULL)
11761 {
11762 ivna.vna_next = 0;
11763 ivna.vna_other = 0;
11764 }
11765 else
11766 {
11767 ivna.vna_next = BYTE_GET (evna.vna_next);
11768 ivna.vna_other = BYTE_GET (evna.vna_other);
11769 }
252b5132
RH
11770
11771 a_off += ivna.vna_next;
11772 }
b34976b6 11773 while (ivna.vna_other != data[cnt + j]
252b5132
RH
11774 && ivna.vna_next != 0);
11775
b34976b6 11776 if (ivna.vna_other == data[cnt + j])
252b5132
RH
11777 {
11778 ivna.vna_name = BYTE_GET (evna.vna_name);
11779
54806181 11780 if (ivna.vna_name >= string_sec->sh_size)
ab273396 11781 name = invalid;
54806181
AM
11782 else
11783 name = strtab + ivna.vna_name;
252b5132
RH
11784 break;
11785 }
11786
11787 offset += ivn.vn_next;
11788 }
11789 while (ivn.vn_next);
11790 }
00d93f34 11791
ab273396 11792 if (data[cnt + j] != 0x8001
978c4450 11793 && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
252b5132 11794 {
b34976b6
AM
11795 Elf_Internal_Verdef ivd;
11796 Elf_External_Verdef evd;
11797 unsigned long offset;
252b5132 11798
d93f0186 11799 offset = offset_from_vma
978c4450
AM
11800 (filedata,
11801 filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
d93f0186 11802 sizeof evd);
252b5132
RH
11803
11804 do
11805 {
dda8d76d 11806 if (get_data (&evd, filedata, offset, sizeof (evd), 1,
59245841
NC
11807 _("version def")) == NULL)
11808 {
11809 ivd.vd_next = 0;
948f632f 11810 /* PR 17531: file: 046-1082287-0.004. */
3102e897
NC
11811 ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
11812 break;
59245841
NC
11813 }
11814 else
11815 {
11816 ivd.vd_next = BYTE_GET (evd.vd_next);
11817 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
11818 }
252b5132
RH
11819
11820 offset += ivd.vd_next;
11821 }
c244d050 11822 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
252b5132
RH
11823 && ivd.vd_next != 0);
11824
c244d050 11825 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
252b5132 11826 {
b34976b6
AM
11827 Elf_External_Verdaux evda;
11828 Elf_Internal_Verdaux ivda;
252b5132
RH
11829
11830 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11831
dda8d76d 11832 if (get_data (&evda, filedata,
59245841
NC
11833 offset - ivd.vd_next + ivd.vd_aux,
11834 sizeof (evda), 1,
11835 _("version def aux")) == NULL)
11836 break;
252b5132
RH
11837
11838 ivda.vda_name = BYTE_GET (evda.vda_name);
11839
54806181 11840 if (ivda.vda_name >= string_sec->sh_size)
ab273396
AM
11841 name = invalid;
11842 else if (name != NULL && name != invalid)
11843 name = _("*both*");
54806181
AM
11844 else
11845 name = strtab + ivda.vda_name;
252b5132
RH
11846 }
11847 }
ab273396
AM
11848 if (name != NULL)
11849 nn += printf ("(%s%-*s",
11850 name,
11851 12 - (int) strlen (name),
11852 ")");
252b5132
RH
11853
11854 if (nn < 18)
11855 printf ("%*c", 18 - nn, ' ');
11856 }
11857
11858 putchar ('\n');
11859 }
11860
11861 free (data);
11862 free (strtab);
11863 free (symbols);
11864 }
11865 break;
103f02d3 11866
252b5132
RH
11867 default:
11868 break;
11869 }
11870 }
11871
11872 if (! found)
ca0e11aa
NC
11873 {
11874 if (filedata->is_separate)
11875 printf (_("\nNo version information found in linked file '%s'.\n"),
11876 filedata->file_name);
11877 else
11878 printf (_("\nNo version information found in this file.\n"));
11879 }
252b5132 11880
32ec8896 11881 return TRUE;
252b5132
RH
11882}
11883
d1133906 11884static const char *
dda8d76d 11885get_symbol_binding (Filedata * filedata, unsigned int binding)
252b5132 11886{
89246a0e 11887 static char buff[64];
252b5132
RH
11888
11889 switch (binding)
11890 {
b34976b6
AM
11891 case STB_LOCAL: return "LOCAL";
11892 case STB_GLOBAL: return "GLOBAL";
11893 case STB_WEAK: return "WEAK";
252b5132
RH
11894 default:
11895 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
e9e44622
JJ
11896 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
11897 binding);
252b5132 11898 else if (binding >= STB_LOOS && binding <= STB_HIOS)
3e7a7d11
NC
11899 {
11900 if (binding == STB_GNU_UNIQUE
df3a023b 11901 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU)
3e7a7d11
NC
11902 return "UNIQUE";
11903 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
11904 }
252b5132 11905 else
e9e44622 11906 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
252b5132
RH
11907 return buff;
11908 }
11909}
11910
d1133906 11911static const char *
dda8d76d 11912get_symbol_type (Filedata * filedata, unsigned int type)
252b5132 11913{
89246a0e 11914 static char buff[64];
252b5132
RH
11915
11916 switch (type)
11917 {
b34976b6
AM
11918 case STT_NOTYPE: return "NOTYPE";
11919 case STT_OBJECT: return "OBJECT";
11920 case STT_FUNC: return "FUNC";
11921 case STT_SECTION: return "SECTION";
11922 case STT_FILE: return "FILE";
11923 case STT_COMMON: return "COMMON";
11924 case STT_TLS: return "TLS";
15ab5209
DB
11925 case STT_RELC: return "RELC";
11926 case STT_SRELC: return "SRELC";
252b5132
RH
11927 default:
11928 if (type >= STT_LOPROC && type <= STT_HIPROC)
df75f1af 11929 {
dda8d76d 11930 if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
3510a7b8 11931 return "THUMB_FUNC";
103f02d3 11932
dda8d76d 11933 if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
103f02d3
UD
11934 return "REGISTER";
11935
dda8d76d 11936 if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
103f02d3
UD
11937 return "PARISC_MILLI";
11938
e9e44622 11939 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
df75f1af 11940 }
252b5132 11941 else if (type >= STT_LOOS && type <= STT_HIOS)
103f02d3 11942 {
dda8d76d 11943 if (filedata->file_header.e_machine == EM_PARISC)
103f02d3
UD
11944 {
11945 if (type == STT_HP_OPAQUE)
11946 return "HP_OPAQUE";
11947 if (type == STT_HP_STUB)
11948 return "HP_STUB";
11949 }
11950
d8045f23 11951 if (type == STT_GNU_IFUNC
dda8d76d 11952 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
df3a023b 11953 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD))
d8045f23
NC
11954 return "IFUNC";
11955
e9e44622 11956 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
103f02d3 11957 }
252b5132 11958 else
e9e44622 11959 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
252b5132
RH
11960 return buff;
11961 }
11962}
11963
d1133906 11964static const char *
d3ba0551 11965get_symbol_visibility (unsigned int visibility)
d1133906
NC
11966{
11967 switch (visibility)
11968 {
b34976b6
AM
11969 case STV_DEFAULT: return "DEFAULT";
11970 case STV_INTERNAL: return "INTERNAL";
11971 case STV_HIDDEN: return "HIDDEN";
d1133906 11972 case STV_PROTECTED: return "PROTECTED";
bee0ee85 11973 default:
27a45f42 11974 error (_("Unrecognized visibility value: %u\n"), visibility);
bee0ee85 11975 return _("<unknown>");
d1133906
NC
11976 }
11977}
11978
2057d69d
CZ
11979static const char *
11980get_alpha_symbol_other (unsigned int other)
9abca702 11981{
2057d69d
CZ
11982 switch (other)
11983 {
11984 case STO_ALPHA_NOPV: return "NOPV";
11985 case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD";
11986 default:
27a45f42 11987 error (_("Unrecognized alpha specific other value: %u\n"), other);
2057d69d 11988 return _("<unknown>");
9abca702 11989 }
2057d69d
CZ
11990}
11991
fd85a6a1
NC
11992static const char *
11993get_solaris_symbol_visibility (unsigned int visibility)
11994{
11995 switch (visibility)
11996 {
11997 case 4: return "EXPORTED";
11998 case 5: return "SINGLETON";
11999 case 6: return "ELIMINATE";
12000 default: return get_symbol_visibility (visibility);
12001 }
12002}
12003
2301ed1c
SN
12004static const char *
12005get_aarch64_symbol_other (unsigned int other)
12006{
12007 static char buf[32];
12008
12009 if (other & STO_AARCH64_VARIANT_PCS)
12010 {
12011 other &= ~STO_AARCH64_VARIANT_PCS;
12012 if (other == 0)
12013 return "VARIANT_PCS";
12014 snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other);
12015 return buf;
12016 }
12017 return NULL;
12018}
12019
5e2b0d47
NC
12020static const char *
12021get_mips_symbol_other (unsigned int other)
12022{
12023 switch (other)
12024 {
32ec8896
NC
12025 case STO_OPTIONAL: return "OPTIONAL";
12026 case STO_MIPS_PLT: return "MIPS PLT";
12027 case STO_MIPS_PIC: return "MIPS PIC";
12028 case STO_MICROMIPS: return "MICROMIPS";
12029 case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC";
12030 case STO_MIPS16: return "MIPS16";
12031 default: return NULL;
5e2b0d47
NC
12032 }
12033}
12034
28f997cf 12035static const char *
dda8d76d 12036get_ia64_symbol_other (Filedata * filedata, unsigned int other)
28f997cf 12037{
dda8d76d 12038 if (is_ia64_vms (filedata))
28f997cf
TG
12039 {
12040 static char res[32];
12041
12042 res[0] = 0;
12043
12044 /* Function types is for images and .STB files only. */
dda8d76d 12045 switch (filedata->file_header.e_type)
28f997cf
TG
12046 {
12047 case ET_DYN:
12048 case ET_EXEC:
12049 switch (VMS_ST_FUNC_TYPE (other))
12050 {
12051 case VMS_SFT_CODE_ADDR:
12052 strcat (res, " CA");
12053 break;
12054 case VMS_SFT_SYMV_IDX:
12055 strcat (res, " VEC");
12056 break;
12057 case VMS_SFT_FD:
12058 strcat (res, " FD");
12059 break;
12060 case VMS_SFT_RESERVE:
12061 strcat (res, " RSV");
12062 break;
12063 default:
bee0ee85
NC
12064 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
12065 VMS_ST_FUNC_TYPE (other));
12066 strcat (res, " <unknown>");
12067 break;
28f997cf
TG
12068 }
12069 break;
12070 default:
12071 break;
12072 }
12073 switch (VMS_ST_LINKAGE (other))
12074 {
12075 case VMS_STL_IGNORE:
12076 strcat (res, " IGN");
12077 break;
12078 case VMS_STL_RESERVE:
12079 strcat (res, " RSV");
12080 break;
12081 case VMS_STL_STD:
12082 strcat (res, " STD");
12083 break;
12084 case VMS_STL_LNK:
12085 strcat (res, " LNK");
12086 break;
12087 default:
bee0ee85
NC
12088 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
12089 VMS_ST_LINKAGE (other));
12090 strcat (res, " <unknown>");
12091 break;
28f997cf
TG
12092 }
12093
12094 if (res[0] != 0)
12095 return res + 1;
12096 else
12097 return res;
12098 }
12099 return NULL;
12100}
12101
6911b7dc
AM
12102static const char *
12103get_ppc64_symbol_other (unsigned int other)
12104{
14732552
AM
12105 if ((other & ~STO_PPC64_LOCAL_MASK) != 0)
12106 return NULL;
12107
12108 other >>= STO_PPC64_LOCAL_BIT;
12109 if (other <= 6)
6911b7dc 12110 {
89246a0e 12111 static char buf[64];
14732552
AM
12112 if (other >= 2)
12113 other = ppc64_decode_local_entry (other);
12114 snprintf (buf, sizeof buf, _("<localentry>: %d"), other);
6911b7dc
AM
12115 return buf;
12116 }
12117 return NULL;
12118}
12119
5e2b0d47 12120static const char *
dda8d76d 12121get_symbol_other (Filedata * filedata, unsigned int other)
5e2b0d47
NC
12122{
12123 const char * result = NULL;
89246a0e 12124 static char buff [64];
5e2b0d47
NC
12125
12126 if (other == 0)
12127 return "";
12128
dda8d76d 12129 switch (filedata->file_header.e_machine)
5e2b0d47 12130 {
2057d69d
CZ
12131 case EM_ALPHA:
12132 result = get_alpha_symbol_other (other);
12133 break;
2301ed1c
SN
12134 case EM_AARCH64:
12135 result = get_aarch64_symbol_other (other);
12136 break;
5e2b0d47
NC
12137 case EM_MIPS:
12138 result = get_mips_symbol_other (other);
28f997cf
TG
12139 break;
12140 case EM_IA_64:
dda8d76d 12141 result = get_ia64_symbol_other (filedata, other);
28f997cf 12142 break;
6911b7dc
AM
12143 case EM_PPC64:
12144 result = get_ppc64_symbol_other (other);
12145 break;
5e2b0d47 12146 default:
fd85a6a1 12147 result = NULL;
5e2b0d47
NC
12148 break;
12149 }
12150
12151 if (result)
12152 return result;
12153
12154 snprintf (buff, sizeof buff, _("<other>: %x"), other);
12155 return buff;
12156}
12157
d1133906 12158static const char *
dda8d76d 12159get_symbol_index_type (Filedata * filedata, unsigned int type)
252b5132 12160{
b34976b6 12161 static char buff[32];
5cf1065c 12162
252b5132
RH
12163 switch (type)
12164 {
b34976b6
AM
12165 case SHN_UNDEF: return "UND";
12166 case SHN_ABS: return "ABS";
12167 case SHN_COMMON: return "COM";
252b5132 12168 default:
9ce701e2 12169 if (type == SHN_IA_64_ANSI_COMMON
10ca4b04
L
12170 && filedata->file_header.e_machine == EM_IA_64
12171 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
12172 return "ANSI_COM";
12173 else if ((filedata->file_header.e_machine == EM_X86_64
12174 || filedata->file_header.e_machine == EM_L1OM
12175 || filedata->file_header.e_machine == EM_K1OM)
12176 && type == SHN_X86_64_LCOMMON)
12177 return "LARGE_COM";
12178 else if ((type == SHN_MIPS_SCOMMON
12179 && filedata->file_header.e_machine == EM_MIPS)
12180 || (type == SHN_TIC6X_SCOMMON
12181 && filedata->file_header.e_machine == EM_TI_C6000))
12182 return "SCOM";
12183 else if (type == SHN_MIPS_SUNDEFINED
12184 && filedata->file_header.e_machine == EM_MIPS)
12185 return "SUND";
12186 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
12187 sprintf (buff, "PRC[0x%04x]", type & 0xffff);
12188 else if (type >= SHN_LOOS && type <= SHN_HIOS)
12189 sprintf (buff, "OS [0x%04x]", type & 0xffff);
12190 else if (type >= SHN_LORESERVE)
12191 sprintf (buff, "RSV[0x%04x]", type & 0xffff);
12192 else if (filedata->file_header.e_shnum != 0
12193 && type >= filedata->file_header.e_shnum)
12194 sprintf (buff, _("bad section index[%3d]"), type);
12195 else
12196 sprintf (buff, "%3d", type);
12197 break;
fd85a6a1
NC
12198 }
12199
10ca4b04 12200 return buff;
6bd1a22c
L
12201}
12202
bb4d2ac2 12203static const char *
dda8d76d 12204get_symbol_version_string (Filedata * filedata,
1449284b
NC
12205 bfd_boolean is_dynsym,
12206 const char * strtab,
12207 unsigned long int strtab_size,
12208 unsigned int si,
12209 Elf_Internal_Sym * psym,
12210 enum versioned_symbol_info * sym_info,
12211 unsigned short * vna_other)
bb4d2ac2 12212{
ab273396
AM
12213 unsigned char data[2];
12214 unsigned short vers_data;
12215 unsigned long offset;
7a815dd5 12216 unsigned short max_vd_ndx;
bb4d2ac2 12217
ab273396 12218 if (!is_dynsym
978c4450 12219 || filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
ab273396 12220 return NULL;
bb4d2ac2 12221
978c4450
AM
12222 offset = offset_from_vma (filedata,
12223 filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
ab273396 12224 sizeof data + si * sizeof (vers_data));
bb4d2ac2 12225
dda8d76d 12226 if (get_data (&data, filedata, offset + si * sizeof (vers_data),
ab273396
AM
12227 sizeof (data), 1, _("version data")) == NULL)
12228 return NULL;
12229
12230 vers_data = byte_get (data, 2);
bb4d2ac2 12231
1f6f5dba 12232 if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0)
ab273396 12233 return NULL;
bb4d2ac2 12234
0b8b7609 12235 *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public;
7a815dd5
L
12236 max_vd_ndx = 0;
12237
ab273396
AM
12238 /* Usually we'd only see verdef for defined symbols, and verneed for
12239 undefined symbols. However, symbols defined by the linker in
12240 .dynbss for variables copied from a shared library in order to
12241 avoid text relocations are defined yet have verneed. We could
12242 use a heuristic to detect the special case, for example, check
12243 for verneed first on symbols defined in SHT_NOBITS sections, but
12244 it is simpler and more reliable to just look for both verdef and
12245 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
bb4d2ac2 12246
ab273396
AM
12247 if (psym->st_shndx != SHN_UNDEF
12248 && vers_data != 0x8001
978c4450 12249 && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
ab273396
AM
12250 {
12251 Elf_Internal_Verdef ivd;
12252 Elf_Internal_Verdaux ivda;
12253 Elf_External_Verdaux evda;
12254 unsigned long off;
bb4d2ac2 12255
dda8d76d 12256 off = offset_from_vma (filedata,
978c4450 12257 filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
ab273396
AM
12258 sizeof (Elf_External_Verdef));
12259
12260 do
bb4d2ac2 12261 {
ab273396
AM
12262 Elf_External_Verdef evd;
12263
dda8d76d 12264 if (get_data (&evd, filedata, off, sizeof (evd), 1,
ab273396
AM
12265 _("version def")) == NULL)
12266 {
12267 ivd.vd_ndx = 0;
12268 ivd.vd_aux = 0;
12269 ivd.vd_next = 0;
1f6f5dba 12270 ivd.vd_flags = 0;
ab273396
AM
12271 }
12272 else
bb4d2ac2 12273 {
ab273396
AM
12274 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
12275 ivd.vd_aux = BYTE_GET (evd.vd_aux);
12276 ivd.vd_next = BYTE_GET (evd.vd_next);
1f6f5dba 12277 ivd.vd_flags = BYTE_GET (evd.vd_flags);
ab273396 12278 }
bb4d2ac2 12279
7a815dd5
L
12280 if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx)
12281 max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION;
12282
ab273396
AM
12283 off += ivd.vd_next;
12284 }
12285 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
bb4d2ac2 12286
ab273396
AM
12287 if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
12288 {
9abca702 12289 if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE)
1f6f5dba
L
12290 return NULL;
12291
ab273396
AM
12292 off -= ivd.vd_next;
12293 off += ivd.vd_aux;
bb4d2ac2 12294
dda8d76d 12295 if (get_data (&evda, filedata, off, sizeof (evda), 1,
ab273396
AM
12296 _("version def aux")) != NULL)
12297 {
12298 ivda.vda_name = BYTE_GET (evda.vda_name);
bb4d2ac2 12299
ab273396 12300 if (psym->st_name != ivda.vda_name)
0b8b7609
AM
12301 return (ivda.vda_name < strtab_size
12302 ? strtab + ivda.vda_name : _("<corrupt>"));
ab273396
AM
12303 }
12304 }
12305 }
bb4d2ac2 12306
978c4450 12307 if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
ab273396
AM
12308 {
12309 Elf_External_Verneed evn;
12310 Elf_Internal_Verneed ivn;
12311 Elf_Internal_Vernaux ivna;
bb4d2ac2 12312
dda8d76d 12313 offset = offset_from_vma (filedata,
978c4450 12314 filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
ab273396
AM
12315 sizeof evn);
12316 do
12317 {
12318 unsigned long vna_off;
bb4d2ac2 12319
dda8d76d 12320 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
ab273396
AM
12321 _("version need")) == NULL)
12322 {
12323 ivna.vna_next = 0;
12324 ivna.vna_other = 0;
12325 ivna.vna_name = 0;
12326 break;
12327 }
bb4d2ac2 12328
ab273396
AM
12329 ivn.vn_aux = BYTE_GET (evn.vn_aux);
12330 ivn.vn_next = BYTE_GET (evn.vn_next);
bb4d2ac2 12331
ab273396 12332 vna_off = offset + ivn.vn_aux;
bb4d2ac2 12333
ab273396
AM
12334 do
12335 {
12336 Elf_External_Vernaux evna;
bb4d2ac2 12337
dda8d76d 12338 if (get_data (&evna, filedata, vna_off, sizeof (evna), 1,
ab273396 12339 _("version need aux (3)")) == NULL)
bb4d2ac2 12340 {
ab273396
AM
12341 ivna.vna_next = 0;
12342 ivna.vna_other = 0;
12343 ivna.vna_name = 0;
bb4d2ac2 12344 }
bb4d2ac2 12345 else
bb4d2ac2 12346 {
ab273396
AM
12347 ivna.vna_other = BYTE_GET (evna.vna_other);
12348 ivna.vna_next = BYTE_GET (evna.vna_next);
12349 ivna.vna_name = BYTE_GET (evna.vna_name);
12350 }
bb4d2ac2 12351
ab273396
AM
12352 vna_off += ivna.vna_next;
12353 }
12354 while (ivna.vna_other != vers_data && ivna.vna_next != 0);
bb4d2ac2 12355
ab273396
AM
12356 if (ivna.vna_other == vers_data)
12357 break;
bb4d2ac2 12358
ab273396
AM
12359 offset += ivn.vn_next;
12360 }
12361 while (ivn.vn_next != 0);
bb4d2ac2 12362
ab273396
AM
12363 if (ivna.vna_other == vers_data)
12364 {
12365 *sym_info = symbol_undefined;
12366 *vna_other = ivna.vna_other;
12367 return (ivna.vna_name < strtab_size
12368 ? strtab + ivna.vna_name : _("<corrupt>"));
bb4d2ac2 12369 }
7a815dd5
L
12370 else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1)
12371 && (vers_data & VERSYM_VERSION) > max_vd_ndx)
12372 return _("<corrupt>");
bb4d2ac2 12373 }
ab273396 12374 return NULL;
bb4d2ac2
L
12375}
12376
10ca4b04
L
12377static void
12378print_dynamic_symbol (Filedata *filedata, unsigned long si,
12379 Elf_Internal_Sym *symtab,
12380 Elf_Internal_Shdr *section,
12381 char *strtab, size_t strtab_size)
252b5132 12382{
10ca4b04
L
12383 const char *version_string;
12384 enum versioned_symbol_info sym_info;
12385 unsigned short vna_other;
12386 Elf_Internal_Sym *psym = symtab + si;
b9e920ec 12387
10ca4b04
L
12388 printf ("%6ld: ", si);
12389 print_vma (psym->st_value, LONG_HEX);
12390 putchar (' ');
12391 print_vma (psym->st_size, DEC_5);
12392 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
12393 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
12394 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
12395 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
12396 else
252b5132 12397 {
10ca4b04 12398 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
252b5132 12399
10ca4b04
L
12400 printf (" %-7s", get_symbol_visibility (vis));
12401 /* Check to see if any other bits in the st_other field are set.
12402 Note - displaying this information disrupts the layout of the
12403 table being generated, but for the moment this case is very rare. */
12404 if (psym->st_other ^ vis)
12405 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
252b5132 12406 }
10ca4b04 12407 printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
0942c7ab
NC
12408
12409 bfd_boolean is_valid = VALID_SYMBOL_NAME (strtab, strtab_size,
12410 psym->st_name);
12411 const char * sstr = is_valid ? strtab + psym->st_name : _("<corrupt>");
10ca4b04
L
12412
12413 version_string
12414 = get_symbol_version_string (filedata,
12415 (section == NULL
12416 || section->sh_type == SHT_DYNSYM),
12417 strtab, strtab_size, si,
12418 psym, &sym_info, &vna_other);
b9e920ec 12419
0942c7ab
NC
12420 int len_avail = 21;
12421 if (! do_wide && version_string != NULL)
12422 {
ddb43bab 12423 char buffer[16];
0942c7ab 12424
ddb43bab 12425 len_avail -= 1 + strlen (version_string);
0942c7ab
NC
12426
12427 if (sym_info == symbol_undefined)
12428 len_avail -= sprintf (buffer," (%d)", vna_other);
12429 else if (sym_info != symbol_hidden)
12430 len_avail -= 1;
12431 }
12432
12433 print_symbol (len_avail, sstr);
b9e920ec 12434
10ca4b04
L
12435 if (version_string)
12436 {
12437 if (sym_info == symbol_undefined)
12438 printf ("@%s (%d)", version_string, vna_other);
f7a99963 12439 else
10ca4b04
L
12440 printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
12441 version_string);
12442 }
6bd1a22c 12443
10ca4b04 12444 putchar ('\n');
6bd1a22c 12445
10ca4b04
L
12446 if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
12447 && section != NULL
12448 && si >= section->sh_info
12449 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
12450 && filedata->file_header.e_machine != EM_MIPS
12451 /* Solaris binaries have been found to violate this requirement as
12452 well. Not sure if this is a bug or an ABI requirement. */
12453 && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS)
12454 warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"),
12455 si, printable_section_name (filedata, section), section->sh_info);
12456}
f16a9783 12457
0f03783c
NC
12458static const char *
12459get_lto_kind (unsigned int kind)
12460{
12461 switch (kind)
12462 {
12463 case 0: return "DEF";
12464 case 1: return "WEAKDEF";
12465 case 2: return "UNDEF";
12466 case 3: return "WEAKUNDEF";
12467 case 4: return "COMMON";
12468 default:
12469 break;
12470 }
12471
12472 static char buffer[30];
12473 error (_("Unknown LTO symbol definition encountered: %u\n"), kind);
12474 sprintf (buffer, "<unknown: %u>", kind);
12475 return buffer;
12476}
12477
12478static const char *
12479get_lto_visibility (unsigned int visibility)
12480{
12481 switch (visibility)
12482 {
12483 case 0: return "DEFAULT";
12484 case 1: return "PROTECTED";
12485 case 2: return "INTERNAL";
12486 case 3: return "HIDDEN";
12487 default:
12488 break;
12489 }
12490
12491 static char buffer[30];
12492 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility);
12493 sprintf (buffer, "<unknown: %u>", visibility);
12494 return buffer;
12495}
12496
12497static const char *
12498get_lto_sym_type (unsigned int sym_type)
12499{
12500 switch (sym_type)
12501 {
12502 case 0: return "UNKNOWN";
12503 case 1: return "FUNCTION";
12504 case 2: return "VARIABLE";
12505 default:
12506 break;
12507 }
12508
12509 static char buffer[30];
12510 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type);
12511 sprintf (buffer, "<unknown: %u>", sym_type);
12512 return buffer;
12513}
12514
12515/* Display an LTO format symbol table.
12516 FIXME: The format of LTO symbol tables is not formalized.
12517 So this code could need changing in the future. */
12518
12519static bfd_boolean
12520display_lto_symtab (Filedata * filedata,
12521 Elf_Internal_Shdr * section)
12522{
12523 if (section->sh_size == 0)
12524 {
ca0e11aa
NC
12525 if (filedata->is_separate)
12526 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
12527 printable_section_name (filedata, section),
12528 filedata->file_name);
12529 else
12530 printf (_("\nLTO Symbol table '%s' is empty!\n"),
12531 printable_section_name (filedata, section));
12532
0f03783c
NC
12533 return TRUE;
12534 }
12535
12536 if (section->sh_size > filedata->file_size)
12537 {
12538 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
12539 printable_section_name (filedata, section),
12540 (unsigned long) section->sh_size);
12541 return FALSE;
12542 }
12543
12544 void * alloced_data = get_data (NULL, filedata, section->sh_offset,
12545 section->sh_size, 1, _("LTO symbols"));
12546 if (alloced_data == NULL)
12547 return FALSE;
12548
12549 /* Look for extended data for the symbol table. */
12550 Elf_Internal_Shdr * ext;
12551 void * ext_data_orig = NULL;
12552 char * ext_data = NULL;
12553 char * ext_data_end = NULL;
12554 char * ext_name = NULL;
12555
12556 if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s",
b9e920ec 12557 SECTION_NAME (section) + sizeof (".gnu.lto_.symtab.") - 1) > 0
0f03783c
NC
12558 && ext_name != NULL /* Paranoia. */
12559 && (ext = find_section (filedata, ext_name)) != NULL)
12560 {
12561 if (ext->sh_size < 3)
12562 error (_("LTO Symbol extension table '%s' is empty!\n"),
12563 printable_section_name (filedata, ext));
12564 else
12565 {
12566 ext_data_orig = ext_data = get_data (NULL, filedata, ext->sh_offset,
12567 ext->sh_size, 1,
12568 _("LTO ext symbol data"));
12569 if (ext_data != NULL)
12570 {
12571 ext_data_end = ext_data + ext->sh_size;
12572 if (* ext_data++ != 1)
12573 error (_("Unexpected version number in symbol extension table\n"));
12574 }
12575 }
12576 }
b9e920ec 12577
0f03783c
NC
12578 const unsigned char * data = (const unsigned char *) alloced_data;
12579 const unsigned char * end = data + section->sh_size;
12580
ca0e11aa
NC
12581 if (filedata->is_separate)
12582 printf (_("\nIn linked file '%s': "), filedata->file_name);
12583 else
12584 printf ("\n");
12585
0f03783c
NC
12586 if (ext_data_orig != NULL)
12587 {
12588 if (do_wide)
ca0e11aa 12589 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
0f03783c
NC
12590 printable_section_name (filedata, section),
12591 printable_section_name (filedata, ext));
12592 else
12593 {
ca0e11aa 12594 printf (_("LTO Symbol table '%s'\n"),
0f03783c
NC
12595 printable_section_name (filedata, section));
12596 printf (_(" and extension table '%s' contain:\n"),
12597 printable_section_name (filedata, ext));
12598 }
12599 }
12600 else
ca0e11aa 12601 printf (_("LTO Symbol table '%s' contains:\n"),
0f03783c 12602 printable_section_name (filedata, section));
b9e920ec 12603
0f03783c 12604 /* FIXME: Add a wide version. */
b9e920ec 12605 if (ext_data_orig != NULL)
0f03783c
NC
12606 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
12607 else
12608 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
12609
12610 /* FIXME: We do not handle style prefixes. */
12611
12612 while (data < end)
12613 {
12614 const unsigned char * sym_name = data;
12615 data += strnlen ((const char *) sym_name, end - data) + 1;
12616 if (data >= end)
12617 goto fail;
12618
12619 const unsigned char * comdat_key = data;
12620 data += strnlen ((const char *) comdat_key, end - data) + 1;
12621 if (data >= end)
12622 goto fail;
12623
12624 if (data + 2 + 8 + 4 > end)
12625 goto fail;
12626
12627 unsigned int kind = *data++;
12628 unsigned int visibility = *data++;
12629
12630 elf_vma size = byte_get (data, 8);
12631 data += 8;
12632
12633 elf_vma slot = byte_get (data, 4);
12634 data += 4;
12635
12636 if (ext_data != NULL)
12637 {
12638 if (ext_data < (ext_data_end - 1))
12639 {
12640 unsigned int sym_type = * ext_data ++;
12641 unsigned int sec_kind = * ext_data ++;
12642
12643 printf (" %10s %10s %11s %08lx %08lx %9s %08lx _",
12644 * comdat_key == 0 ? "-" : (char *) comdat_key,
12645 get_lto_kind (kind),
12646 get_lto_visibility (visibility),
12647 (long) size,
12648 (long) slot,
12649 get_lto_sym_type (sym_type),
12650 (long) sec_kind);
12651 print_symbol (6, (const char *) sym_name);
12652 }
12653 else
12654 {
12655 error (_("Ran out of LTO symbol extension data\n"));
12656 ext_data = NULL;
12657 /* FIXME: return FAIL result ? */
12658 }
12659 }
12660 else
12661 {
12662 printf (" %10s %10s %11s %08lx %08lx _",
12663 * comdat_key == 0 ? "-" : (char *) comdat_key,
12664 get_lto_kind (kind),
12665 get_lto_visibility (visibility),
12666 (long) size,
12667 (long) slot);
12668 print_symbol (21, (const char *) sym_name);
12669 }
12670 putchar ('\n');
12671 }
12672
12673 if (ext_data != NULL && ext_data < ext_data_end)
12674 {
12675 error (_("Data remains in the LTO symbol extension table\n"));
12676 goto fail;
12677 }
12678
12679 free (alloced_data);
12680 free (ext_data_orig);
12681 free (ext_name);
12682 return TRUE;
b9e920ec 12683
0f03783c
NC
12684 fail:
12685 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
12686 free (alloced_data);
12687 free (ext_data_orig);
12688 free (ext_name);
12689 return FALSE;
12690}
12691
12692/* Display LTO symbol tables. */
12693
12694static bfd_boolean
12695process_lto_symbol_tables (Filedata * filedata)
12696{
12697 Elf_Internal_Shdr * section;
12698 unsigned int i;
12699 bfd_boolean res = TRUE;
12700
12701 if (!do_lto_syms)
12702 return TRUE;
12703
12704 if (filedata->section_headers == NULL)
12705 return TRUE;
12706
12707 for (i = 0, section = filedata->section_headers;
12708 i < filedata->file_header.e_shnum;
12709 i++, section++)
b9e920ec 12710 if (SECTION_NAME_VALID (section)
08dedd66 12711 && startswith (SECTION_NAME (section), ".gnu.lto_.symtab."))
0f03783c
NC
12712 res &= display_lto_symtab (filedata, section);
12713
b9e920ec 12714 return res;
0f03783c
NC
12715}
12716
10ca4b04 12717/* Dump the symbol table. */
0f03783c 12718
10ca4b04
L
12719static bfd_boolean
12720process_symbol_table (Filedata * filedata)
12721{
12722 Elf_Internal_Shdr * section;
f16a9783 12723
10ca4b04
L
12724 if (!do_syms && !do_dyn_syms && !do_histogram)
12725 return TRUE;
6bd1a22c 12726
978c4450 12727 if ((filedata->dynamic_info[DT_HASH] || filedata->dynamic_info_DT_GNU_HASH)
6bd1a22c
L
12728 && do_syms
12729 && do_using_dynamic
978c4450
AM
12730 && filedata->dynamic_strings != NULL
12731 && filedata->dynamic_symbols != NULL)
6bd1a22c 12732 {
10ca4b04 12733 unsigned long si;
6bd1a22c 12734
ca0e11aa
NC
12735 if (filedata->is_separate)
12736 {
12737 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n",
12738 "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n",
12739 filedata->num_dynamic_syms),
12740 filedata->file_name,
12741 filedata->num_dynamic_syms);
12742 }
12743 else
12744 {
12745 printf (ngettext ("\nSymbol table for image contains %lu entry:\n",
12746 "\nSymbol table for image contains %lu entries:\n",
12747 filedata->num_dynamic_syms),
12748 filedata->num_dynamic_syms);
12749 }
10ca4b04
L
12750 if (is_32bit_elf)
12751 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12752 else
12753 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6bd1a22c 12754
978c4450
AM
12755 for (si = 0; si < filedata->num_dynamic_syms; si++)
12756 print_dynamic_symbol (filedata, si, filedata->dynamic_symbols, NULL,
12757 filedata->dynamic_strings,
12758 filedata->dynamic_strings_length);
252b5132 12759 }
8b73c356 12760 else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
dda8d76d 12761 && filedata->section_headers != NULL)
252b5132 12762 {
b34976b6 12763 unsigned int i;
252b5132 12764
dda8d76d
NC
12765 for (i = 0, section = filedata->section_headers;
12766 i < filedata->file_header.e_shnum;
252b5132
RH
12767 i++, section++)
12768 {
2cf0635d 12769 char * strtab = NULL;
c256ffe7 12770 unsigned long int strtab_size = 0;
2cf0635d 12771 Elf_Internal_Sym * symtab;
ef3df110 12772 unsigned long si, num_syms;
252b5132 12773
2c610e4b
L
12774 if ((section->sh_type != SHT_SYMTAB
12775 && section->sh_type != SHT_DYNSYM)
12776 || (!do_syms
12777 && section->sh_type == SHT_SYMTAB))
252b5132
RH
12778 continue;
12779
dd24e3da
NC
12780 if (section->sh_entsize == 0)
12781 {
12782 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
dda8d76d 12783 printable_section_name (filedata, section));
dd24e3da
NC
12784 continue;
12785 }
12786
d3a49aa8 12787 num_syms = section->sh_size / section->sh_entsize;
ca0e11aa
NC
12788
12789 if (filedata->is_separate)
12790 printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n",
12791 "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n",
12792 num_syms),
12793 filedata->file_name,
12794 printable_section_name (filedata, section),
12795 num_syms);
12796 else
12797 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
12798 "\nSymbol table '%s' contains %lu entries:\n",
12799 num_syms),
12800 printable_section_name (filedata, section),
12801 num_syms);
dd24e3da 12802
f7a99963 12803 if (is_32bit_elf)
ca47b30c 12804 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
f7a99963 12805 else
ca47b30c 12806 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
252b5132 12807
dda8d76d 12808 symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms);
252b5132
RH
12809 if (symtab == NULL)
12810 continue;
12811
dda8d76d 12812 if (section->sh_link == filedata->file_header.e_shstrndx)
c256ffe7 12813 {
dda8d76d
NC
12814 strtab = filedata->string_table;
12815 strtab_size = filedata->string_table_length;
c256ffe7 12816 }
dda8d76d 12817 else if (section->sh_link < filedata->file_header.e_shnum)
252b5132 12818 {
2cf0635d 12819 Elf_Internal_Shdr * string_sec;
252b5132 12820
dda8d76d 12821 string_sec = filedata->section_headers + section->sh_link;
252b5132 12822
dda8d76d 12823 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset,
3f5e193b
NC
12824 1, string_sec->sh_size,
12825 _("string table"));
c256ffe7 12826 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
252b5132
RH
12827 }
12828
10ca4b04
L
12829 for (si = 0; si < num_syms; si++)
12830 print_dynamic_symbol (filedata, si, symtab, section,
12831 strtab, strtab_size);
252b5132
RH
12832
12833 free (symtab);
dda8d76d 12834 if (strtab != filedata->string_table)
252b5132
RH
12835 free (strtab);
12836 }
12837 }
12838 else if (do_syms)
12839 printf
12840 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
12841
978c4450 12842 if (do_histogram && filedata->buckets != NULL)
252b5132 12843 {
2cf0635d
NC
12844 unsigned long * lengths;
12845 unsigned long * counts;
66543521
AM
12846 unsigned long hn;
12847 bfd_vma si;
12848 unsigned long maxlength = 0;
12849 unsigned long nzero_counts = 0;
12850 unsigned long nsyms = 0;
6bd6a03d 12851 char *visited;
252b5132 12852
d3a49aa8
AM
12853 printf (ngettext ("\nHistogram for bucket list length "
12854 "(total of %lu bucket):\n",
12855 "\nHistogram for bucket list length "
12856 "(total of %lu buckets):\n",
978c4450
AM
12857 (unsigned long) filedata->nbuckets),
12858 (unsigned long) filedata->nbuckets);
252b5132 12859
978c4450
AM
12860 lengths = (unsigned long *) calloc (filedata->nbuckets,
12861 sizeof (*lengths));
252b5132
RH
12862 if (lengths == NULL)
12863 {
8b73c356 12864 error (_("Out of memory allocating space for histogram buckets\n"));
fd486f32 12865 goto err_out;
252b5132 12866 }
978c4450
AM
12867 visited = xcmalloc (filedata->nchains, 1);
12868 memset (visited, 0, filedata->nchains);
8b73c356
NC
12869
12870 printf (_(" Length Number %% of total Coverage\n"));
978c4450 12871 for (hn = 0; hn < filedata->nbuckets; ++hn)
252b5132 12872 {
978c4450 12873 for (si = filedata->buckets[hn]; si > 0; si = filedata->chains[si])
252b5132 12874 {
b34976b6 12875 ++nsyms;
252b5132 12876 if (maxlength < ++lengths[hn])
b34976b6 12877 ++maxlength;
978c4450 12878 if (si >= filedata->nchains || visited[si])
6bd6a03d
AM
12879 {
12880 error (_("histogram chain is corrupt\n"));
12881 break;
12882 }
12883 visited[si] = 1;
252b5132
RH
12884 }
12885 }
6bd6a03d 12886 free (visited);
252b5132 12887
3f5e193b 12888 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
252b5132
RH
12889 if (counts == NULL)
12890 {
b2e951ec 12891 free (lengths);
8b73c356 12892 error (_("Out of memory allocating space for histogram counts\n"));
fd486f32 12893 goto err_out;
252b5132
RH
12894 }
12895
978c4450 12896 for (hn = 0; hn < filedata->nbuckets; ++hn)
b34976b6 12897 ++counts[lengths[hn]];
252b5132 12898
978c4450 12899 if (filedata->nbuckets > 0)
252b5132 12900 {
66543521
AM
12901 unsigned long i;
12902 printf (" 0 %-10lu (%5.1f%%)\n",
978c4450 12903 counts[0], (counts[0] * 100.0) / filedata->nbuckets);
66543521 12904 for (i = 1; i <= maxlength; ++i)
103f02d3 12905 {
66543521
AM
12906 nzero_counts += counts[i] * i;
12907 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
978c4450 12908 i, counts[i], (counts[i] * 100.0) / filedata->nbuckets,
103f02d3
UD
12909 (nzero_counts * 100.0) / nsyms);
12910 }
252b5132
RH
12911 }
12912
12913 free (counts);
12914 free (lengths);
12915 }
12916
978c4450
AM
12917 free (filedata->buckets);
12918 filedata->buckets = NULL;
12919 filedata->nbuckets = 0;
12920 free (filedata->chains);
12921 filedata->chains = NULL;
252b5132 12922
978c4450 12923 if (do_histogram && filedata->gnubuckets != NULL)
fdc90cb4 12924 {
2cf0635d
NC
12925 unsigned long * lengths;
12926 unsigned long * counts;
fdc90cb4
JJ
12927 unsigned long hn;
12928 unsigned long maxlength = 0;
12929 unsigned long nzero_counts = 0;
12930 unsigned long nsyms = 0;
fdc90cb4 12931
f16a9783 12932 printf (ngettext ("\nHistogram for `%s' bucket list length "
d3a49aa8 12933 "(total of %lu bucket):\n",
f16a9783 12934 "\nHistogram for `%s' bucket list length "
d3a49aa8 12935 "(total of %lu buckets):\n",
978c4450
AM
12936 (unsigned long) filedata->ngnubuckets),
12937 GNU_HASH_SECTION_NAME (filedata),
12938 (unsigned long) filedata->ngnubuckets);
8b73c356 12939
978c4450
AM
12940 lengths = (unsigned long *) calloc (filedata->ngnubuckets,
12941 sizeof (*lengths));
fdc90cb4
JJ
12942 if (lengths == NULL)
12943 {
8b73c356 12944 error (_("Out of memory allocating space for gnu histogram buckets\n"));
fd486f32 12945 goto err_out;
fdc90cb4
JJ
12946 }
12947
fdc90cb4
JJ
12948 printf (_(" Length Number %% of total Coverage\n"));
12949
978c4450
AM
12950 for (hn = 0; hn < filedata->ngnubuckets; ++hn)
12951 if (filedata->gnubuckets[hn] != 0)
fdc90cb4
JJ
12952 {
12953 bfd_vma off, length = 1;
12954
978c4450 12955 for (off = filedata->gnubuckets[hn] - filedata->gnusymidx;
071436c6 12956 /* PR 17531 file: 010-77222-0.004. */
978c4450
AM
12957 off < filedata->ngnuchains
12958 && (filedata->gnuchains[off] & 1) == 0;
071436c6 12959 ++off)
fdc90cb4
JJ
12960 ++length;
12961 lengths[hn] = length;
12962 if (length > maxlength)
12963 maxlength = length;
12964 nsyms += length;
12965 }
12966
3f5e193b 12967 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
fdc90cb4
JJ
12968 if (counts == NULL)
12969 {
b2e951ec 12970 free (lengths);
8b73c356 12971 error (_("Out of memory allocating space for gnu histogram counts\n"));
fd486f32 12972 goto err_out;
fdc90cb4
JJ
12973 }
12974
978c4450 12975 for (hn = 0; hn < filedata->ngnubuckets; ++hn)
fdc90cb4
JJ
12976 ++counts[lengths[hn]];
12977
978c4450 12978 if (filedata->ngnubuckets > 0)
fdc90cb4
JJ
12979 {
12980 unsigned long j;
12981 printf (" 0 %-10lu (%5.1f%%)\n",
978c4450 12982 counts[0], (counts[0] * 100.0) / filedata->ngnubuckets);
fdc90cb4
JJ
12983 for (j = 1; j <= maxlength; ++j)
12984 {
12985 nzero_counts += counts[j] * j;
12986 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
978c4450 12987 j, counts[j], (counts[j] * 100.0) / filedata->ngnubuckets,
fdc90cb4
JJ
12988 (nzero_counts * 100.0) / nsyms);
12989 }
12990 }
12991
12992 free (counts);
12993 free (lengths);
fdc90cb4 12994 }
978c4450
AM
12995 free (filedata->gnubuckets);
12996 filedata->gnubuckets = NULL;
12997 filedata->ngnubuckets = 0;
12998 free (filedata->gnuchains);
12999 filedata->gnuchains = NULL;
13000 filedata->ngnuchains = 0;
13001 free (filedata->mipsxlat);
13002 filedata->mipsxlat = NULL;
32ec8896 13003 return TRUE;
fd486f32
AM
13004
13005 err_out:
978c4450
AM
13006 free (filedata->gnubuckets);
13007 filedata->gnubuckets = NULL;
13008 filedata->ngnubuckets = 0;
13009 free (filedata->gnuchains);
13010 filedata->gnuchains = NULL;
13011 filedata->ngnuchains = 0;
13012 free (filedata->mipsxlat);
13013 filedata->mipsxlat = NULL;
13014 free (filedata->buckets);
13015 filedata->buckets = NULL;
13016 filedata->nbuckets = 0;
13017 free (filedata->chains);
13018 filedata->chains = NULL;
fd486f32 13019 return FALSE;
252b5132
RH
13020}
13021
32ec8896 13022static bfd_boolean
ca0e11aa 13023process_syminfo (Filedata * filedata)
252b5132 13024{
b4c96d0d 13025 unsigned int i;
252b5132 13026
978c4450 13027 if (filedata->dynamic_syminfo == NULL
252b5132
RH
13028 || !do_dynamic)
13029 /* No syminfo, this is ok. */
32ec8896 13030 return TRUE;
252b5132
RH
13031
13032 /* There better should be a dynamic symbol section. */
978c4450 13033 if (filedata->dynamic_symbols == NULL || filedata->dynamic_strings == NULL)
32ec8896 13034 return FALSE;
252b5132 13035
ca0e11aa
NC
13036 if (filedata->is_separate)
13037 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n",
13038 "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n",
13039 filedata->dynamic_syminfo_nent),
13040 filedata->file_name,
13041 filedata->dynamic_syminfo_offset,
13042 filedata->dynamic_syminfo_nent);
13043 else
d3a49aa8
AM
13044 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
13045 "contains %d entry:\n",
13046 "\nDynamic info segment at offset 0x%lx "
13047 "contains %d entries:\n",
978c4450 13048 filedata->dynamic_syminfo_nent),
ca0e11aa
NC
13049 filedata->dynamic_syminfo_offset,
13050 filedata->dynamic_syminfo_nent);
252b5132
RH
13051
13052 printf (_(" Num: Name BoundTo Flags\n"));
978c4450 13053 for (i = 0; i < filedata->dynamic_syminfo_nent; ++i)
252b5132 13054 {
978c4450 13055 unsigned short int flags = filedata->dynamic_syminfo[i].si_flags;
252b5132 13056
31104126 13057 printf ("%4d: ", i);
978c4450 13058 if (i >= filedata->num_dynamic_syms)
4082ef84 13059 printf (_("<corrupt index>"));
978c4450
AM
13060 else if (VALID_DYNAMIC_NAME (filedata, filedata->dynamic_symbols[i].st_name))
13061 print_symbol (30, GET_DYNAMIC_NAME (filedata,
13062 filedata->dynamic_symbols[i].st_name));
d79b3d50 13063 else
978c4450 13064 printf (_("<corrupt: %19ld>"), filedata->dynamic_symbols[i].st_name);
31104126 13065 putchar (' ');
252b5132 13066
978c4450 13067 switch (filedata->dynamic_syminfo[i].si_boundto)
252b5132
RH
13068 {
13069 case SYMINFO_BT_SELF:
13070 fputs ("SELF ", stdout);
13071 break;
13072 case SYMINFO_BT_PARENT:
13073 fputs ("PARENT ", stdout);
13074 break;
13075 default:
978c4450
AM
13076 if (filedata->dynamic_syminfo[i].si_boundto > 0
13077 && filedata->dynamic_syminfo[i].si_boundto < filedata->dynamic_nent
13078 && VALID_DYNAMIC_NAME (filedata,
13079 filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val))
31104126 13080 {
978c4450
AM
13081 print_symbol (10, GET_DYNAMIC_NAME (filedata,
13082 filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val));
31104126
NC
13083 putchar (' ' );
13084 }
252b5132 13085 else
978c4450 13086 printf ("%-10d ", filedata->dynamic_syminfo[i].si_boundto);
252b5132
RH
13087 break;
13088 }
13089
13090 if (flags & SYMINFO_FLG_DIRECT)
13091 printf (" DIRECT");
13092 if (flags & SYMINFO_FLG_PASSTHRU)
13093 printf (" PASSTHRU");
13094 if (flags & SYMINFO_FLG_COPY)
13095 printf (" COPY");
13096 if (flags & SYMINFO_FLG_LAZYLOAD)
13097 printf (" LAZYLOAD");
13098
13099 puts ("");
13100 }
13101
32ec8896 13102 return TRUE;
252b5132
RH
13103}
13104
75802ccb
CE
13105/* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
13106 is contained by the region START .. END. The types of ADDR, START
13107 and END should all be the same. Note both ADDR + NELEM and END
13108 point to just beyond the end of the regions that are being tested. */
13109#define IN_RANGE(START,END,ADDR,NELEM) \
13110 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
b32e566b 13111
cf13d699
NC
13112/* Check to see if the given reloc needs to be handled in a target specific
13113 manner. If so then process the reloc and return TRUE otherwise return
f84ce13b
NC
13114 FALSE.
13115
13116 If called with reloc == NULL, then this is a signal that reloc processing
13117 for the current section has finished, and any saved state should be
13118 discarded. */
09c11c86 13119
cf13d699 13120static bfd_boolean
dda8d76d
NC
13121target_specific_reloc_handling (Filedata * filedata,
13122 Elf_Internal_Rela * reloc,
13123 unsigned char * start,
13124 unsigned char * end,
13125 Elf_Internal_Sym * symtab,
13126 unsigned long num_syms)
252b5132 13127{
f84ce13b
NC
13128 unsigned int reloc_type = 0;
13129 unsigned long sym_index = 0;
13130
13131 if (reloc)
13132 {
dda8d76d 13133 reloc_type = get_reloc_type (filedata, reloc->r_info);
f84ce13b
NC
13134 sym_index = get_reloc_symindex (reloc->r_info);
13135 }
252b5132 13136
dda8d76d 13137 switch (filedata->file_header.e_machine)
252b5132 13138 {
13761a11
NC
13139 case EM_MSP430:
13140 case EM_MSP430_OLD:
13141 {
13142 static Elf_Internal_Sym * saved_sym = NULL;
13143
f84ce13b
NC
13144 if (reloc == NULL)
13145 {
13146 saved_sym = NULL;
13147 return TRUE;
13148 }
13149
13761a11
NC
13150 switch (reloc_type)
13151 {
13152 case 10: /* R_MSP430_SYM_DIFF */
7d81bc93 13153 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
dda8d76d 13154 if (uses_msp430x_relocs (filedata))
13761a11 13155 break;
1a0670f3 13156 /* Fall through. */
13761a11 13157 case 21: /* R_MSP430X_SYM_DIFF */
7d81bc93 13158 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
f84ce13b
NC
13159 /* PR 21139. */
13160 if (sym_index >= num_syms)
13161 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
13162 sym_index);
13163 else
13164 saved_sym = symtab + sym_index;
13761a11
NC
13165 return TRUE;
13166
13167 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13168 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
13169 goto handle_sym_diff;
0b4362b0 13170
13761a11
NC
13171 case 5: /* R_MSP430_16_BYTE */
13172 case 9: /* R_MSP430_8 */
7d81bc93 13173 case 11: /* R_MSP430_GNU_SET_ULEB128 */
dda8d76d 13174 if (uses_msp430x_relocs (filedata))
13761a11
NC
13175 break;
13176 goto handle_sym_diff;
13177
13178 case 2: /* R_MSP430_ABS16 */
13179 case 15: /* R_MSP430X_ABS16 */
7d81bc93 13180 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
dda8d76d 13181 if (! uses_msp430x_relocs (filedata))
13761a11
NC
13182 break;
13183 goto handle_sym_diff;
0b4362b0 13184
13761a11
NC
13185 handle_sym_diff:
13186 if (saved_sym != NULL)
13187 {
13188 bfd_vma value;
5a805384 13189 unsigned int reloc_size = 0;
7d81bc93
JL
13190 int leb_ret = 0;
13191 switch (reloc_type)
13192 {
13193 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13194 reloc_size = 4;
13195 break;
13196 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13197 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
5a805384
AM
13198 if (reloc->r_offset < (size_t) (end - start))
13199 read_leb128 (start + reloc->r_offset, end, FALSE,
13200 &reloc_size, &leb_ret);
7d81bc93
JL
13201 break;
13202 default:
13203 reloc_size = 2;
13204 break;
13205 }
13761a11 13206
5a805384 13207 if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8)
7d81bc93
JL
13208 error (_("MSP430 ULEB128 field at 0x%lx contains invalid "
13209 "ULEB128 value\n"),
13210 (long) reloc->r_offset);
13211 else if (sym_index >= num_syms)
f84ce13b
NC
13212 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
13213 sym_index);
03f7786e 13214 else
f84ce13b
NC
13215 {
13216 value = reloc->r_addend + (symtab[sym_index].st_value
13217 - saved_sym->st_value);
13218
b32e566b 13219 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
f84ce13b 13220 byte_put (start + reloc->r_offset, value, reloc_size);
b32e566b
NC
13221 else
13222 /* PR 21137 */
13223 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
13224 (long) reloc->r_offset);
f84ce13b 13225 }
13761a11
NC
13226
13227 saved_sym = NULL;
13228 return TRUE;
13229 }
13230 break;
13231
13232 default:
13233 if (saved_sym != NULL)
071436c6 13234 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
13761a11
NC
13235 break;
13236 }
13237 break;
13238 }
13239
cf13d699
NC
13240 case EM_MN10300:
13241 case EM_CYGNUS_MN10300:
13242 {
13243 static Elf_Internal_Sym * saved_sym = NULL;
252b5132 13244
f84ce13b
NC
13245 if (reloc == NULL)
13246 {
13247 saved_sym = NULL;
13248 return TRUE;
13249 }
13250
cf13d699
NC
13251 switch (reloc_type)
13252 {
13253 case 34: /* R_MN10300_ALIGN */
13254 return TRUE;
13255 case 33: /* R_MN10300_SYM_DIFF */
f84ce13b
NC
13256 if (sym_index >= num_syms)
13257 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
13258 sym_index);
13259 else
13260 saved_sym = symtab + sym_index;
cf13d699 13261 return TRUE;
f84ce13b 13262
cf13d699
NC
13263 case 1: /* R_MN10300_32 */
13264 case 2: /* R_MN10300_16 */
13265 if (saved_sym != NULL)
13266 {
03f7786e 13267 int reloc_size = reloc_type == 1 ? 4 : 2;
cf13d699 13268 bfd_vma value;
252b5132 13269
f84ce13b
NC
13270 if (sym_index >= num_syms)
13271 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
13272 sym_index);
03f7786e 13273 else
f84ce13b
NC
13274 {
13275 value = reloc->r_addend + (symtab[sym_index].st_value
13276 - saved_sym->st_value);
13277
b32e566b 13278 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
f84ce13b 13279 byte_put (start + reloc->r_offset, value, reloc_size);
b32e566b
NC
13280 else
13281 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
13282 (long) reloc->r_offset);
f84ce13b 13283 }
252b5132 13284
cf13d699
NC
13285 saved_sym = NULL;
13286 return TRUE;
13287 }
13288 break;
13289 default:
13290 if (saved_sym != NULL)
071436c6 13291 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
cf13d699
NC
13292 break;
13293 }
13294 break;
13295 }
6ff71e76
NC
13296
13297 case EM_RL78:
13298 {
13299 static bfd_vma saved_sym1 = 0;
13300 static bfd_vma saved_sym2 = 0;
13301 static bfd_vma value;
13302
f84ce13b
NC
13303 if (reloc == NULL)
13304 {
13305 saved_sym1 = saved_sym2 = 0;
13306 return TRUE;
13307 }
13308
6ff71e76
NC
13309 switch (reloc_type)
13310 {
13311 case 0x80: /* R_RL78_SYM. */
13312 saved_sym1 = saved_sym2;
f84ce13b
NC
13313 if (sym_index >= num_syms)
13314 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
13315 sym_index);
13316 else
13317 {
13318 saved_sym2 = symtab[sym_index].st_value;
13319 saved_sym2 += reloc->r_addend;
13320 }
6ff71e76
NC
13321 return TRUE;
13322
13323 case 0x83: /* R_RL78_OPsub. */
13324 value = saved_sym1 - saved_sym2;
13325 saved_sym2 = saved_sym1 = 0;
13326 return TRUE;
13327 break;
13328
13329 case 0x41: /* R_RL78_ABS32. */
b32e566b 13330 if (IN_RANGE (start, end, start + reloc->r_offset, 4))
03f7786e 13331 byte_put (start + reloc->r_offset, value, 4);
b32e566b
NC
13332 else
13333 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13334 (long) reloc->r_offset);
6ff71e76
NC
13335 value = 0;
13336 return TRUE;
13337
13338 case 0x43: /* R_RL78_ABS16. */
b32e566b 13339 if (IN_RANGE (start, end, start + reloc->r_offset, 2))
03f7786e 13340 byte_put (start + reloc->r_offset, value, 2);
b32e566b
NC
13341 else
13342 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13343 (long) reloc->r_offset);
6ff71e76
NC
13344 value = 0;
13345 return TRUE;
13346
13347 default:
13348 break;
13349 }
13350 break;
13351 }
252b5132
RH
13352 }
13353
cf13d699 13354 return FALSE;
252b5132
RH
13355}
13356
aca88567
NC
13357/* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
13358 DWARF debug sections. This is a target specific test. Note - we do not
13359 go through the whole including-target-headers-multiple-times route, (as
13360 we have already done with <elf/h8.h>) because this would become very
13361 messy and even then this function would have to contain target specific
13362 information (the names of the relocs instead of their numeric values).
13363 FIXME: This is not the correct way to solve this problem. The proper way
13364 is to have target specific reloc sizing and typing functions created by
13365 the reloc-macros.h header, in the same way that it already creates the
13366 reloc naming functions. */
13367
13368static bfd_boolean
dda8d76d 13369is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 13370{
d347c9df 13371 /* Please keep this table alpha-sorted for ease of visual lookup. */
dda8d76d 13372 switch (filedata->file_header.e_machine)
aca88567 13373 {
41e92641 13374 case EM_386:
22abe556 13375 case EM_IAMCU:
41e92641 13376 return reloc_type == 1; /* R_386_32. */
aca88567
NC
13377 case EM_68K:
13378 return reloc_type == 1; /* R_68K_32. */
f954747f
AM
13379 case EM_860:
13380 return reloc_type == 1; /* R_860_32. */
13381 case EM_960:
13382 return reloc_type == 2; /* R_960_32. */
a06ea964 13383 case EM_AARCH64:
9282b95a
JW
13384 return (reloc_type == 258
13385 || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
aca4efc7
JM
13386 case EM_BPF:
13387 return reloc_type == 11; /* R_BPF_DATA_32 */
d347c9df
PS
13388 case EM_ADAPTEVA_EPIPHANY:
13389 return reloc_type == 3;
aca88567 13390 case EM_ALPHA:
137b6b5f 13391 return reloc_type == 1; /* R_ALPHA_REFLONG. */
41e92641
NC
13392 case EM_ARC:
13393 return reloc_type == 1; /* R_ARC_32. */
886a2506
NC
13394 case EM_ARC_COMPACT:
13395 case EM_ARC_COMPACT2:
13396 return reloc_type == 4; /* R_ARC_32. */
41e92641
NC
13397 case EM_ARM:
13398 return reloc_type == 2; /* R_ARM_ABS32 */
cb8f3167 13399 case EM_AVR_OLD:
aca88567
NC
13400 case EM_AVR:
13401 return reloc_type == 1;
13402 case EM_BLACKFIN:
13403 return reloc_type == 0x12; /* R_byte4_data. */
13404 case EM_CRIS:
13405 return reloc_type == 3; /* R_CRIS_32. */
13406 case EM_CR16:
13407 return reloc_type == 3; /* R_CR16_NUM32. */
13408 case EM_CRX:
13409 return reloc_type == 15; /* R_CRX_NUM32. */
b8891f8d
AJ
13410 case EM_CSKY:
13411 return reloc_type == 1; /* R_CKCORE_ADDR32. */
aca88567
NC
13412 case EM_CYGNUS_FRV:
13413 return reloc_type == 1;
41e92641
NC
13414 case EM_CYGNUS_D10V:
13415 case EM_D10V:
13416 return reloc_type == 6; /* R_D10V_32. */
aca88567
NC
13417 case EM_CYGNUS_D30V:
13418 case EM_D30V:
13419 return reloc_type == 12; /* R_D30V_32_NORMAL. */
41e92641
NC
13420 case EM_DLX:
13421 return reloc_type == 3; /* R_DLX_RELOC_32. */
aca88567
NC
13422 case EM_CYGNUS_FR30:
13423 case EM_FR30:
13424 return reloc_type == 3; /* R_FR30_32. */
3f8107ab
AM
13425 case EM_FT32:
13426 return reloc_type == 1; /* R_FT32_32. */
aca88567
NC
13427 case EM_H8S:
13428 case EM_H8_300:
13429 case EM_H8_300H:
13430 return reloc_type == 1; /* R_H8_DIR32. */
3730236a 13431 case EM_IA_64:
262cdac7
AM
13432 return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */
13433 || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */
13434 || reloc_type == 0x24 /* R_IA64_DIR32MSB. */
13435 || reloc_type == 0x25 /* R_IA64_DIR32LSB. */);
aca88567
NC
13436 case EM_IP2K_OLD:
13437 case EM_IP2K:
13438 return reloc_type == 2; /* R_IP2K_32. */
13439 case EM_IQ2000:
13440 return reloc_type == 2; /* R_IQ2000_32. */
84e94c90
NC
13441 case EM_LATTICEMICO32:
13442 return reloc_type == 3; /* R_LM32_32. */
ff7eeb89 13443 case EM_M32C_OLD:
aca88567
NC
13444 case EM_M32C:
13445 return reloc_type == 3; /* R_M32C_32. */
13446 case EM_M32R:
13447 return reloc_type == 34; /* R_M32R_32_RELA. */
adec12c1
AM
13448 case EM_68HC11:
13449 case EM_68HC12:
13450 return reloc_type == 6; /* R_M68HC11_32. */
7b4ae824 13451 case EM_S12Z:
2849d19f
JD
13452 return reloc_type == 7 || /* R_S12Z_EXT32 */
13453 reloc_type == 6; /* R_S12Z_CW32. */
aca88567
NC
13454 case EM_MCORE:
13455 return reloc_type == 1; /* R_MCORE_ADDR32. */
13456 case EM_CYGNUS_MEP:
13457 return reloc_type == 4; /* R_MEP_32. */
a3c62988
NC
13458 case EM_METAG:
13459 return reloc_type == 2; /* R_METAG_ADDR32. */
137b6b5f
AM
13460 case EM_MICROBLAZE:
13461 return reloc_type == 1; /* R_MICROBLAZE_32. */
aca88567
NC
13462 case EM_MIPS:
13463 return reloc_type == 2; /* R_MIPS_32. */
13464 case EM_MMIX:
13465 return reloc_type == 4; /* R_MMIX_32. */
13466 case EM_CYGNUS_MN10200:
13467 case EM_MN10200:
13468 return reloc_type == 1; /* R_MN10200_32. */
13469 case EM_CYGNUS_MN10300:
13470 case EM_MN10300:
13471 return reloc_type == 1; /* R_MN10300_32. */
5506d11a
AM
13472 case EM_MOXIE:
13473 return reloc_type == 1; /* R_MOXIE_32. */
aca88567
NC
13474 case EM_MSP430_OLD:
13475 case EM_MSP430:
13761a11 13476 return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
aca88567
NC
13477 case EM_MT:
13478 return reloc_type == 2; /* R_MT_32. */
35c08157
KLC
13479 case EM_NDS32:
13480 return reloc_type == 20; /* R_NDS32_RELA. */
3e0873ac 13481 case EM_ALTERA_NIOS2:
36591ba1 13482 return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
3e0873ac
NC
13483 case EM_NIOS32:
13484 return reloc_type == 1; /* R_NIOS_32. */
73589c9d
CS
13485 case EM_OR1K:
13486 return reloc_type == 1; /* R_OR1K_32. */
aca88567 13487 case EM_PARISC:
9abca702 13488 return (reloc_type == 1 /* R_PARISC_DIR32. */
0df8ad28 13489 || reloc_type == 2 /* R_PARISC_DIR21L. */
5fda8eca 13490 || reloc_type == 41); /* R_PARISC_SECREL32. */
aca88567
NC
13491 case EM_PJ:
13492 case EM_PJ_OLD:
13493 return reloc_type == 1; /* R_PJ_DATA_DIR32. */
13494 case EM_PPC64:
13495 return reloc_type == 1; /* R_PPC64_ADDR32. */
13496 case EM_PPC:
13497 return reloc_type == 1; /* R_PPC_ADDR32. */
2b100bb5
DD
13498 case EM_TI_PRU:
13499 return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
e23eba97
NC
13500 case EM_RISCV:
13501 return reloc_type == 1; /* R_RISCV_32. */
99c513f6
DD
13502 case EM_RL78:
13503 return reloc_type == 1; /* R_RL78_DIR32. */
c7927a3c
NC
13504 case EM_RX:
13505 return reloc_type == 1; /* R_RX_DIR32. */
f954747f
AM
13506 case EM_S370:
13507 return reloc_type == 1; /* R_I370_ADDR31. */
aca88567
NC
13508 case EM_S390_OLD:
13509 case EM_S390:
13510 return reloc_type == 4; /* R_S390_32. */
41e92641
NC
13511 case EM_SCORE:
13512 return reloc_type == 8; /* R_SCORE_ABS32. */
aca88567
NC
13513 case EM_SH:
13514 return reloc_type == 1; /* R_SH_DIR32. */
13515 case EM_SPARC32PLUS:
13516 case EM_SPARCV9:
13517 case EM_SPARC:
13518 return reloc_type == 3 /* R_SPARC_32. */
13519 || reloc_type == 23; /* R_SPARC_UA32. */
a7dd7d05
AM
13520 case EM_SPU:
13521 return reloc_type == 6; /* R_SPU_ADDR32 */
40b36596
JM
13522 case EM_TI_C6000:
13523 return reloc_type == 1; /* R_C6000_ABS32. */
aa137e4d
NC
13524 case EM_TILEGX:
13525 return reloc_type == 2; /* R_TILEGX_32. */
13526 case EM_TILEPRO:
13527 return reloc_type == 1; /* R_TILEPRO_32. */
aca88567
NC
13528 case EM_CYGNUS_V850:
13529 case EM_V850:
13530 return reloc_type == 6; /* R_V850_ABS32. */
708e2187
NC
13531 case EM_V800:
13532 return reloc_type == 0x33; /* R_V810_WORD. */
aca88567
NC
13533 case EM_VAX:
13534 return reloc_type == 1; /* R_VAX_32. */
619ed720
EB
13535 case EM_VISIUM:
13536 return reloc_type == 3; /* R_VISIUM_32. */
f96bd6c2
PC
13537 case EM_WEBASSEMBLY:
13538 return reloc_type == 1; /* R_WASM32_32. */
aca88567 13539 case EM_X86_64:
8a9036a4 13540 case EM_L1OM:
7a9068fe 13541 case EM_K1OM:
aca88567 13542 return reloc_type == 10; /* R_X86_64_32. */
c29aca4a
NC
13543 case EM_XC16X:
13544 case EM_C166:
13545 return reloc_type == 3; /* R_XC16C_ABS_32. */
f6c1a2d5
NC
13546 case EM_XGATE:
13547 return reloc_type == 4; /* R_XGATE_32. */
aca88567
NC
13548 case EM_XSTORMY16:
13549 return reloc_type == 1; /* R_XSTROMY16_32. */
13550 case EM_XTENSA_OLD:
13551 case EM_XTENSA:
13552 return reloc_type == 1; /* R_XTENSA_32. */
6655dba2
SB
13553 case EM_Z80:
13554 return reloc_type == 6; /* R_Z80_32. */
aca88567 13555 default:
bee0ee85
NC
13556 {
13557 static unsigned int prev_warn = 0;
13558
13559 /* Avoid repeating the same warning multiple times. */
dda8d76d 13560 if (prev_warn != filedata->file_header.e_machine)
bee0ee85 13561 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
dda8d76d
NC
13562 filedata->file_header.e_machine);
13563 prev_warn = filedata->file_header.e_machine;
bee0ee85
NC
13564 return FALSE;
13565 }
aca88567
NC
13566 }
13567}
13568
13569/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13570 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
13571
13572static bfd_boolean
dda8d76d 13573is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 13574{
dda8d76d 13575 switch (filedata->file_header.e_machine)
d347c9df 13576 /* Please keep this table alpha-sorted for ease of visual lookup. */
aca88567 13577 {
41e92641 13578 case EM_386:
22abe556 13579 case EM_IAMCU:
3e0873ac 13580 return reloc_type == 2; /* R_386_PC32. */
aca88567 13581 case EM_68K:
3e0873ac 13582 return reloc_type == 4; /* R_68K_PC32. */
a06ea964
NC
13583 case EM_AARCH64:
13584 return reloc_type == 261; /* R_AARCH64_PREL32 */
cfb8c092
NC
13585 case EM_ADAPTEVA_EPIPHANY:
13586 return reloc_type == 6;
aca88567
NC
13587 case EM_ALPHA:
13588 return reloc_type == 10; /* R_ALPHA_SREL32. */
726c18e1
CZ
13589 case EM_ARC_COMPACT:
13590 case EM_ARC_COMPACT2:
13591 return reloc_type == 49; /* R_ARC_32_PCREL. */
41e92641 13592 case EM_ARM:
3e0873ac 13593 return reloc_type == 3; /* R_ARM_REL32 */
d347c9df
PS
13594 case EM_AVR_OLD:
13595 case EM_AVR:
13596 return reloc_type == 36; /* R_AVR_32_PCREL. */
137b6b5f
AM
13597 case EM_MICROBLAZE:
13598 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
73589c9d
CS
13599 case EM_OR1K:
13600 return reloc_type == 9; /* R_OR1K_32_PCREL. */
aca88567 13601 case EM_PARISC:
85acf597 13602 return reloc_type == 9; /* R_PARISC_PCREL32. */
aca88567
NC
13603 case EM_PPC:
13604 return reloc_type == 26; /* R_PPC_REL32. */
13605 case EM_PPC64:
3e0873ac 13606 return reloc_type == 26; /* R_PPC64_REL32. */
25cbdcbb
AS
13607 case EM_RISCV:
13608 return reloc_type == 57; /* R_RISCV_32_PCREL. */
aca88567
NC
13609 case EM_S390_OLD:
13610 case EM_S390:
3e0873ac 13611 return reloc_type == 5; /* R_390_PC32. */
aca88567 13612 case EM_SH:
3e0873ac 13613 return reloc_type == 2; /* R_SH_REL32. */
aca88567
NC
13614 case EM_SPARC32PLUS:
13615 case EM_SPARCV9:
13616 case EM_SPARC:
3e0873ac 13617 return reloc_type == 6; /* R_SPARC_DISP32. */
a7dd7d05
AM
13618 case EM_SPU:
13619 return reloc_type == 13; /* R_SPU_REL32. */
aa137e4d
NC
13620 case EM_TILEGX:
13621 return reloc_type == 6; /* R_TILEGX_32_PCREL. */
13622 case EM_TILEPRO:
13623 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
619ed720
EB
13624 case EM_VISIUM:
13625 return reloc_type == 6; /* R_VISIUM_32_PCREL */
aca88567 13626 case EM_X86_64:
8a9036a4 13627 case EM_L1OM:
7a9068fe 13628 case EM_K1OM:
3e0873ac 13629 return reloc_type == 2; /* R_X86_64_PC32. */
2057d69d
CZ
13630 case EM_VAX:
13631 return reloc_type == 4; /* R_VAX_PCREL32. */
2fcb9706
BW
13632 case EM_XTENSA_OLD:
13633 case EM_XTENSA:
13634 return reloc_type == 14; /* R_XTENSA_32_PCREL. */
aca88567
NC
13635 default:
13636 /* Do not abort or issue an error message here. Not all targets use
13637 pc-relative 32-bit relocs in their DWARF debug information and we
13638 have already tested for target coverage in is_32bit_abs_reloc. A
cf13d699
NC
13639 more helpful warning message will be generated by apply_relocations
13640 anyway, so just return. */
aca88567
NC
13641 return FALSE;
13642 }
13643}
13644
13645/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13646 a 64-bit absolute RELA relocation used in DWARF debug sections. */
13647
13648static bfd_boolean
dda8d76d 13649is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
aca88567 13650{
dda8d76d 13651 switch (filedata->file_header.e_machine)
aca88567 13652 {
a06ea964
NC
13653 case EM_AARCH64:
13654 return reloc_type == 257; /* R_AARCH64_ABS64. */
aca88567
NC
13655 case EM_ALPHA:
13656 return reloc_type == 2; /* R_ALPHA_REFQUAD. */
3730236a 13657 case EM_IA_64:
262cdac7
AM
13658 return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */
13659 || reloc_type == 0x27 /* R_IA64_DIR64LSB. */);
3e0873ac
NC
13660 case EM_PARISC:
13661 return reloc_type == 80; /* R_PARISC_DIR64. */
aca88567
NC
13662 case EM_PPC64:
13663 return reloc_type == 38; /* R_PPC64_ADDR64. */
e23eba97
NC
13664 case EM_RISCV:
13665 return reloc_type == 2; /* R_RISCV_64. */
aca88567
NC
13666 case EM_SPARC32PLUS:
13667 case EM_SPARCV9:
13668 case EM_SPARC:
714da62f
NC
13669 return reloc_type == 32 /* R_SPARC_64. */
13670 || reloc_type == 54; /* R_SPARC_UA64. */
aca88567 13671 case EM_X86_64:
8a9036a4 13672 case EM_L1OM:
7a9068fe 13673 case EM_K1OM:
aca88567 13674 return reloc_type == 1; /* R_X86_64_64. */
e819ade1
AS
13675 case EM_S390_OLD:
13676 case EM_S390:
aa137e4d
NC
13677 return reloc_type == 22; /* R_S390_64. */
13678 case EM_TILEGX:
13679 return reloc_type == 1; /* R_TILEGX_64. */
85a82265 13680 case EM_MIPS:
aa137e4d 13681 return reloc_type == 18; /* R_MIPS_64. */
aca88567
NC
13682 default:
13683 return FALSE;
13684 }
13685}
13686
85acf597
RH
13687/* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
13688 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
13689
13690static bfd_boolean
dda8d76d 13691is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
85acf597 13692{
dda8d76d 13693 switch (filedata->file_header.e_machine)
85acf597 13694 {
a06ea964
NC
13695 case EM_AARCH64:
13696 return reloc_type == 260; /* R_AARCH64_PREL64. */
85acf597 13697 case EM_ALPHA:
aa137e4d 13698 return reloc_type == 11; /* R_ALPHA_SREL64. */
85acf597 13699 case EM_IA_64:
262cdac7
AM
13700 return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */
13701 || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */);
85acf597 13702 case EM_PARISC:
aa137e4d 13703 return reloc_type == 72; /* R_PARISC_PCREL64. */
85acf597 13704 case EM_PPC64:
aa137e4d 13705 return reloc_type == 44; /* R_PPC64_REL64. */
85acf597
RH
13706 case EM_SPARC32PLUS:
13707 case EM_SPARCV9:
13708 case EM_SPARC:
aa137e4d 13709 return reloc_type == 46; /* R_SPARC_DISP64. */
85acf597 13710 case EM_X86_64:
8a9036a4 13711 case EM_L1OM:
7a9068fe 13712 case EM_K1OM:
aa137e4d 13713 return reloc_type == 24; /* R_X86_64_PC64. */
85acf597
RH
13714 case EM_S390_OLD:
13715 case EM_S390:
aa137e4d
NC
13716 return reloc_type == 23; /* R_S390_PC64. */
13717 case EM_TILEGX:
13718 return reloc_type == 5; /* R_TILEGX_64_PCREL. */
85acf597
RH
13719 default:
13720 return FALSE;
13721 }
13722}
13723
4dc3c23d
AM
13724/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13725 a 24-bit absolute RELA relocation used in DWARF debug sections. */
13726
13727static bfd_boolean
dda8d76d 13728is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
4dc3c23d 13729{
dda8d76d 13730 switch (filedata->file_header.e_machine)
4dc3c23d
AM
13731 {
13732 case EM_CYGNUS_MN10200:
13733 case EM_MN10200:
13734 return reloc_type == 4; /* R_MN10200_24. */
3ee6e4fb
NC
13735 case EM_FT32:
13736 return reloc_type == 5; /* R_FT32_20. */
6655dba2
SB
13737 case EM_Z80:
13738 return reloc_type == 5; /* R_Z80_24. */
4dc3c23d
AM
13739 default:
13740 return FALSE;
13741 }
13742}
13743
aca88567
NC
13744/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13745 a 16-bit absolute RELA relocation used in DWARF debug sections. */
13746
13747static bfd_boolean
dda8d76d 13748is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
4b78141a 13749{
d347c9df 13750 /* Please keep this table alpha-sorted for ease of visual lookup. */
dda8d76d 13751 switch (filedata->file_header.e_machine)
4b78141a 13752 {
886a2506
NC
13753 case EM_ARC:
13754 case EM_ARC_COMPACT:
13755 case EM_ARC_COMPACT2:
13756 return reloc_type == 2; /* R_ARC_16. */
d347c9df
PS
13757 case EM_ADAPTEVA_EPIPHANY:
13758 return reloc_type == 5;
aca88567
NC
13759 case EM_AVR_OLD:
13760 case EM_AVR:
13761 return reloc_type == 4; /* R_AVR_16. */
41e92641
NC
13762 case EM_CYGNUS_D10V:
13763 case EM_D10V:
13764 return reloc_type == 3; /* R_D10V_16. */
81b42bca
JB
13765 case EM_FT32:
13766 return reloc_type == 2; /* R_FT32_16. */
4b78141a
NC
13767 case EM_H8S:
13768 case EM_H8_300:
13769 case EM_H8_300H:
aca88567
NC
13770 return reloc_type == R_H8_DIR16;
13771 case EM_IP2K_OLD:
13772 case EM_IP2K:
13773 return reloc_type == 1; /* R_IP2K_16. */
ff7eeb89 13774 case EM_M32C_OLD:
f4236fe4
DD
13775 case EM_M32C:
13776 return reloc_type == 1; /* R_M32C_16 */
d347c9df
PS
13777 case EM_CYGNUS_MN10200:
13778 case EM_MN10200:
13779 return reloc_type == 2; /* R_MN10200_16. */
13780 case EM_CYGNUS_MN10300:
13781 case EM_MN10300:
13782 return reloc_type == 2; /* R_MN10300_16. */
aca88567 13783 case EM_MSP430:
dda8d76d 13784 if (uses_msp430x_relocs (filedata))
13761a11 13785 return reloc_type == 2; /* R_MSP430_ABS16. */
1a0670f3 13786 /* Fall through. */
78c8d46c 13787 case EM_MSP430_OLD:
aca88567 13788 return reloc_type == 5; /* R_MSP430_16_BYTE. */
35c08157
KLC
13789 case EM_NDS32:
13790 return reloc_type == 19; /* R_NDS32_RELA. */
3e0873ac 13791 case EM_ALTERA_NIOS2:
36591ba1 13792 return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
3e0873ac
NC
13793 case EM_NIOS32:
13794 return reloc_type == 9; /* R_NIOS_16. */
73589c9d
CS
13795 case EM_OR1K:
13796 return reloc_type == 2; /* R_OR1K_16. */
39e07931
AS
13797 case EM_RISCV:
13798 return reloc_type == 55; /* R_RISCV_SET16. */
2b100bb5
DD
13799 case EM_TI_PRU:
13800 return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */
40b36596
JM
13801 case EM_TI_C6000:
13802 return reloc_type == 2; /* R_C6000_ABS16. */
d347c9df
PS
13803 case EM_VISIUM:
13804 return reloc_type == 2; /* R_VISIUM_16. */
c29aca4a
NC
13805 case EM_XC16X:
13806 case EM_C166:
13807 return reloc_type == 2; /* R_XC16C_ABS_16. */
f6c1a2d5
NC
13808 case EM_XGATE:
13809 return reloc_type == 3; /* R_XGATE_16. */
6655dba2
SB
13810 case EM_Z80:
13811 return reloc_type == 4; /* R_Z80_16. */
4b78141a 13812 default:
aca88567 13813 return FALSE;
4b78141a
NC
13814 }
13815}
13816
39e07931
AS
13817/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13818 a 8-bit absolute RELA relocation used in DWARF debug sections. */
13819
13820static bfd_boolean
13821is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
13822{
13823 switch (filedata->file_header.e_machine)
13824 {
13825 case EM_RISCV:
13826 return reloc_type == 54; /* R_RISCV_SET8. */
6655dba2
SB
13827 case EM_Z80:
13828 return reloc_type == 1; /* R_Z80_8. */
39e07931
AS
13829 default:
13830 return FALSE;
13831 }
13832}
13833
13834/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13835 a 6-bit absolute RELA relocation used in DWARF debug sections. */
13836
13837static bfd_boolean
13838is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
13839{
13840 switch (filedata->file_header.e_machine)
13841 {
13842 case EM_RISCV:
13843 return reloc_type == 53; /* R_RISCV_SET6. */
13844 default:
13845 return FALSE;
13846 }
13847}
13848
03336641
JW
13849/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13850 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
13851
13852static bfd_boolean
13853is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13854{
13855 /* Please keep this table alpha-sorted for ease of visual lookup. */
13856 switch (filedata->file_header.e_machine)
13857 {
13858 case EM_RISCV:
13859 return reloc_type == 35; /* R_RISCV_ADD32. */
13860 default:
13861 return FALSE;
13862 }
13863}
13864
13865/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13866 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
13867
13868static bfd_boolean
13869is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13870{
13871 /* Please keep this table alpha-sorted for ease of visual lookup. */
13872 switch (filedata->file_header.e_machine)
13873 {
13874 case EM_RISCV:
13875 return reloc_type == 39; /* R_RISCV_SUB32. */
13876 default:
13877 return FALSE;
13878 }
13879}
13880
13881/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13882 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
13883
13884static bfd_boolean
13885is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13886{
13887 /* Please keep this table alpha-sorted for ease of visual lookup. */
13888 switch (filedata->file_header.e_machine)
13889 {
13890 case EM_RISCV:
13891 return reloc_type == 36; /* R_RISCV_ADD64. */
13892 default:
13893 return FALSE;
13894 }
13895}
13896
13897/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13898 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
13899
13900static bfd_boolean
13901is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13902{
13903 /* Please keep this table alpha-sorted for ease of visual lookup. */
13904 switch (filedata->file_header.e_machine)
13905 {
13906 case EM_RISCV:
13907 return reloc_type == 40; /* R_RISCV_SUB64. */
13908 default:
13909 return FALSE;
13910 }
13911}
13912
13913/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13914 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
13915
13916static bfd_boolean
13917is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13918{
13919 /* Please keep this table alpha-sorted for ease of visual lookup. */
13920 switch (filedata->file_header.e_machine)
13921 {
13922 case EM_RISCV:
13923 return reloc_type == 34; /* R_RISCV_ADD16. */
13924 default:
13925 return FALSE;
13926 }
13927}
13928
13929/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13930 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
13931
13932static bfd_boolean
13933is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13934{
13935 /* Please keep this table alpha-sorted for ease of visual lookup. */
13936 switch (filedata->file_header.e_machine)
13937 {
13938 case EM_RISCV:
13939 return reloc_type == 38; /* R_RISCV_SUB16. */
13940 default:
13941 return FALSE;
13942 }
13943}
13944
13945/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13946 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
13947
13948static bfd_boolean
13949is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13950{
13951 /* Please keep this table alpha-sorted for ease of visual lookup. */
13952 switch (filedata->file_header.e_machine)
13953 {
13954 case EM_RISCV:
13955 return reloc_type == 33; /* R_RISCV_ADD8. */
13956 default:
13957 return FALSE;
13958 }
13959}
13960
13961/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13962 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
13963
13964static bfd_boolean
13965is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13966{
13967 /* Please keep this table alpha-sorted for ease of visual lookup. */
13968 switch (filedata->file_header.e_machine)
13969 {
13970 case EM_RISCV:
13971 return reloc_type == 37; /* R_RISCV_SUB8. */
13972 default:
13973 return FALSE;
13974 }
13975}
13976
39e07931
AS
13977/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13978 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
13979
13980static bfd_boolean
13981is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13982{
13983 switch (filedata->file_header.e_machine)
13984 {
13985 case EM_RISCV:
13986 return reloc_type == 52; /* R_RISCV_SUB6. */
13987 default:
13988 return FALSE;
13989 }
13990}
13991
2a7b2e88
JK
13992/* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
13993 relocation entries (possibly formerly used for SHT_GROUP sections). */
13994
13995static bfd_boolean
dda8d76d 13996is_none_reloc (Filedata * filedata, unsigned int reloc_type)
2a7b2e88 13997{
dda8d76d 13998 switch (filedata->file_header.e_machine)
2a7b2e88 13999 {
cb8f3167 14000 case EM_386: /* R_386_NONE. */
d347c9df 14001 case EM_68K: /* R_68K_NONE. */
cfb8c092 14002 case EM_ADAPTEVA_EPIPHANY:
d347c9df
PS
14003 case EM_ALPHA: /* R_ALPHA_NONE. */
14004 case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
886a2506 14005 case EM_ARC: /* R_ARC_NONE. */
886a2506 14006 case EM_ARC_COMPACT2: /* R_ARC_NONE. */
d347c9df 14007 case EM_ARC_COMPACT: /* R_ARC_NONE. */
cb8f3167 14008 case EM_ARM: /* R_ARM_NONE. */
d347c9df 14009 case EM_C166: /* R_XC16X_NONE. */
cb8f3167 14010 case EM_CRIS: /* R_CRIS_NONE. */
d347c9df
PS
14011 case EM_FT32: /* R_FT32_NONE. */
14012 case EM_IA_64: /* R_IA64_NONE. */
7a9068fe 14013 case EM_K1OM: /* R_X86_64_NONE. */
d347c9df
PS
14014 case EM_L1OM: /* R_X86_64_NONE. */
14015 case EM_M32R: /* R_M32R_NONE. */
14016 case EM_MIPS: /* R_MIPS_NONE. */
cb8f3167 14017 case EM_MN10300: /* R_MN10300_NONE. */
5506d11a 14018 case EM_MOXIE: /* R_MOXIE_NONE. */
d347c9df
PS
14019 case EM_NIOS32: /* R_NIOS_NONE. */
14020 case EM_OR1K: /* R_OR1K_NONE. */
14021 case EM_PARISC: /* R_PARISC_NONE. */
14022 case EM_PPC64: /* R_PPC64_NONE. */
14023 case EM_PPC: /* R_PPC_NONE. */
e23eba97 14024 case EM_RISCV: /* R_RISCV_NONE. */
d347c9df
PS
14025 case EM_S390: /* R_390_NONE. */
14026 case EM_S390_OLD:
14027 case EM_SH: /* R_SH_NONE. */
14028 case EM_SPARC32PLUS:
14029 case EM_SPARC: /* R_SPARC_NONE. */
14030 case EM_SPARCV9:
aa137e4d
NC
14031 case EM_TILEGX: /* R_TILEGX_NONE. */
14032 case EM_TILEPRO: /* R_TILEPRO_NONE. */
d347c9df
PS
14033 case EM_TI_C6000:/* R_C6000_NONE. */
14034 case EM_X86_64: /* R_X86_64_NONE. */
c29aca4a 14035 case EM_XC16X:
6655dba2 14036 case EM_Z80: /* R_Z80_NONE. */
f96bd6c2 14037 case EM_WEBASSEMBLY: /* R_WASM32_NONE. */
cb8f3167 14038 return reloc_type == 0;
d347c9df 14039
a06ea964
NC
14040 case EM_AARCH64:
14041 return reloc_type == 0 || reloc_type == 256;
d347c9df
PS
14042 case EM_AVR_OLD:
14043 case EM_AVR:
14044 return (reloc_type == 0 /* R_AVR_NONE. */
14045 || reloc_type == 30 /* R_AVR_DIFF8. */
14046 || reloc_type == 31 /* R_AVR_DIFF16. */
14047 || reloc_type == 32 /* R_AVR_DIFF32. */);
14048 case EM_METAG:
14049 return reloc_type == 3; /* R_METAG_NONE. */
35c08157
KLC
14050 case EM_NDS32:
14051 return (reloc_type == 0 /* R_XTENSA_NONE. */
14052 || reloc_type == 204 /* R_NDS32_DIFF8. */
14053 || reloc_type == 205 /* R_NDS32_DIFF16. */
14054 || reloc_type == 206 /* R_NDS32_DIFF32. */
14055 || reloc_type == 207 /* R_NDS32_ULEB128. */);
2b100bb5
DD
14056 case EM_TI_PRU:
14057 return (reloc_type == 0 /* R_PRU_NONE. */
14058 || reloc_type == 65 /* R_PRU_DIFF8. */
14059 || reloc_type == 66 /* R_PRU_DIFF16. */
14060 || reloc_type == 67 /* R_PRU_DIFF32. */);
58332dda
JK
14061 case EM_XTENSA_OLD:
14062 case EM_XTENSA:
4dc3c23d
AM
14063 return (reloc_type == 0 /* R_XTENSA_NONE. */
14064 || reloc_type == 17 /* R_XTENSA_DIFF8. */
14065 || reloc_type == 18 /* R_XTENSA_DIFF16. */
30ce8e47
MF
14066 || reloc_type == 19 /* R_XTENSA_DIFF32. */
14067 || reloc_type == 57 /* R_XTENSA_PDIFF8. */
14068 || reloc_type == 58 /* R_XTENSA_PDIFF16. */
14069 || reloc_type == 59 /* R_XTENSA_PDIFF32. */
14070 || reloc_type == 60 /* R_XTENSA_NDIFF8. */
14071 || reloc_type == 61 /* R_XTENSA_NDIFF16. */
14072 || reloc_type == 62 /* R_XTENSA_NDIFF32. */);
2a7b2e88
JK
14073 }
14074 return FALSE;
14075}
14076
d1c4b12b
NC
14077/* Returns TRUE if there is a relocation against
14078 section NAME at OFFSET bytes. */
14079
14080bfd_boolean
14081reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
14082{
14083 Elf_Internal_Rela * relocs;
14084 Elf_Internal_Rela * rp;
14085
14086 if (dsec == NULL || dsec->reloc_info == NULL)
14087 return FALSE;
14088
14089 relocs = (Elf_Internal_Rela *) dsec->reloc_info;
14090
14091 for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
14092 if (rp->r_offset == offset)
14093 return TRUE;
14094
14095 return FALSE;
14096}
14097
cf13d699 14098/* Apply relocations to a section.
32ec8896
NC
14099 Returns TRUE upon success, FALSE otherwise.
14100 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
14101 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
14102 will be set to the number of relocs loaded.
14103
cf13d699 14104 Note: So far support has been added only for those relocations
32ec8896
NC
14105 which can be found in debug sections. FIXME: Add support for
14106 more relocations ? */
1b315056 14107
32ec8896 14108static bfd_boolean
dda8d76d 14109apply_relocations (Filedata * filedata,
d1c4b12b
NC
14110 const Elf_Internal_Shdr * section,
14111 unsigned char * start,
14112 bfd_size_type size,
1449284b 14113 void ** relocs_return,
d1c4b12b 14114 unsigned long * num_relocs_return)
1b315056 14115{
cf13d699 14116 Elf_Internal_Shdr * relsec;
0d2a7a93 14117 unsigned char * end = start + size;
cb8f3167 14118
d1c4b12b
NC
14119 if (relocs_return != NULL)
14120 {
14121 * (Elf_Internal_Rela **) relocs_return = NULL;
14122 * num_relocs_return = 0;
14123 }
14124
dda8d76d 14125 if (filedata->file_header.e_type != ET_REL)
32ec8896
NC
14126 /* No relocs to apply. */
14127 return TRUE;
1b315056 14128
cf13d699 14129 /* Find the reloc section associated with the section. */
dda8d76d
NC
14130 for (relsec = filedata->section_headers;
14131 relsec < filedata->section_headers + filedata->file_header.e_shnum;
5b18a4bc 14132 ++relsec)
252b5132 14133 {
41e92641
NC
14134 bfd_boolean is_rela;
14135 unsigned long num_relocs;
2cf0635d
NC
14136 Elf_Internal_Rela * relocs;
14137 Elf_Internal_Rela * rp;
14138 Elf_Internal_Shdr * symsec;
14139 Elf_Internal_Sym * symtab;
ba5cdace 14140 unsigned long num_syms;
2cf0635d 14141 Elf_Internal_Sym * sym;
252b5132 14142
41e92641 14143 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
14144 || relsec->sh_info >= filedata->file_header.e_shnum
14145 || filedata->section_headers + relsec->sh_info != section
c256ffe7 14146 || relsec->sh_size == 0
dda8d76d 14147 || relsec->sh_link >= filedata->file_header.e_shnum)
5b18a4bc 14148 continue;
428409d5 14149
a788aedd
AM
14150 symsec = filedata->section_headers + relsec->sh_link;
14151 if (symsec->sh_type != SHT_SYMTAB
14152 && symsec->sh_type != SHT_DYNSYM)
14153 return FALSE;
14154
41e92641
NC
14155 is_rela = relsec->sh_type == SHT_RELA;
14156
14157 if (is_rela)
14158 {
dda8d76d 14159 if (!slurp_rela_relocs (filedata, relsec->sh_offset,
3f5e193b 14160 relsec->sh_size, & relocs, & num_relocs))
32ec8896 14161 return FALSE;
41e92641
NC
14162 }
14163 else
14164 {
dda8d76d 14165 if (!slurp_rel_relocs (filedata, relsec->sh_offset,
3f5e193b 14166 relsec->sh_size, & relocs, & num_relocs))
32ec8896 14167 return FALSE;
41e92641
NC
14168 }
14169
14170 /* SH uses RELA but uses in place value instead of the addend field. */
dda8d76d 14171 if (filedata->file_header.e_machine == EM_SH)
41e92641 14172 is_rela = FALSE;
428409d5 14173
dda8d76d 14174 symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms);
103f02d3 14175
41e92641 14176 for (rp = relocs; rp < relocs + num_relocs; ++rp)
252b5132 14177 {
41e92641
NC
14178 bfd_vma addend;
14179 unsigned int reloc_type;
14180 unsigned int reloc_size;
03336641
JW
14181 bfd_boolean reloc_inplace = FALSE;
14182 bfd_boolean reloc_subtract = FALSE;
91d6fa6a 14183 unsigned char * rloc;
ba5cdace 14184 unsigned long sym_index;
4b78141a 14185
dda8d76d 14186 reloc_type = get_reloc_type (filedata, rp->r_info);
41e92641 14187
dda8d76d 14188 if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms))
2a7b2e88 14189 continue;
dda8d76d 14190 else if (is_none_reloc (filedata, reloc_type))
98fb390a 14191 continue;
dda8d76d
NC
14192 else if (is_32bit_abs_reloc (filedata, reloc_type)
14193 || is_32bit_pcrel_reloc (filedata, reloc_type))
aca88567 14194 reloc_size = 4;
dda8d76d
NC
14195 else if (is_64bit_abs_reloc (filedata, reloc_type)
14196 || is_64bit_pcrel_reloc (filedata, reloc_type))
aca88567 14197 reloc_size = 8;
dda8d76d 14198 else if (is_24bit_abs_reloc (filedata, reloc_type))
4dc3c23d 14199 reloc_size = 3;
dda8d76d 14200 else if (is_16bit_abs_reloc (filedata, reloc_type))
aca88567 14201 reloc_size = 2;
39e07931
AS
14202 else if (is_8bit_abs_reloc (filedata, reloc_type)
14203 || is_6bit_abs_reloc (filedata, reloc_type))
14204 reloc_size = 1;
03336641
JW
14205 else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
14206 reloc_type))
14207 || is_32bit_inplace_add_reloc (filedata, reloc_type))
14208 {
14209 reloc_size = 4;
14210 reloc_inplace = TRUE;
14211 }
14212 else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata,
14213 reloc_type))
14214 || is_64bit_inplace_add_reloc (filedata, reloc_type))
14215 {
14216 reloc_size = 8;
14217 reloc_inplace = TRUE;
14218 }
14219 else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata,
14220 reloc_type))
14221 || is_16bit_inplace_add_reloc (filedata, reloc_type))
14222 {
14223 reloc_size = 2;
14224 reloc_inplace = TRUE;
14225 }
14226 else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata,
14227 reloc_type))
14228 || is_8bit_inplace_add_reloc (filedata, reloc_type))
14229 {
14230 reloc_size = 1;
14231 reloc_inplace = TRUE;
14232 }
39e07931
AS
14233 else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata,
14234 reloc_type)))
14235 {
14236 reloc_size = 1;
14237 reloc_inplace = TRUE;
14238 }
aca88567 14239 else
4b78141a 14240 {
bee0ee85 14241 static unsigned int prev_reloc = 0;
dda8d76d 14242
bee0ee85
NC
14243 if (reloc_type != prev_reloc)
14244 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
dda8d76d 14245 reloc_type, printable_section_name (filedata, section));
bee0ee85 14246 prev_reloc = reloc_type;
4b78141a
NC
14247 continue;
14248 }
103f02d3 14249
91d6fa6a 14250 rloc = start + rp->r_offset;
75802ccb 14251 if (!IN_RANGE (start, end, rloc, reloc_size))
700dd8b7
L
14252 {
14253 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
14254 (unsigned long) rp->r_offset,
dda8d76d 14255 printable_section_name (filedata, section));
700dd8b7
L
14256 continue;
14257 }
103f02d3 14258
ba5cdace
NC
14259 sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
14260 if (sym_index >= num_syms)
14261 {
14262 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
dda8d76d 14263 sym_index, printable_section_name (filedata, section));
ba5cdace
NC
14264 continue;
14265 }
14266 sym = symtab + sym_index;
41e92641
NC
14267
14268 /* If the reloc has a symbol associated with it,
55f25fc3
L
14269 make sure that it is of an appropriate type.
14270
14271 Relocations against symbols without type can happen.
14272 Gcc -feliminate-dwarf2-dups may generate symbols
14273 without type for debug info.
14274
14275 Icc generates relocations against function symbols
14276 instead of local labels.
14277
14278 Relocations against object symbols can happen, eg when
14279 referencing a global array. For an example of this see
14280 the _clz.o binary in libgcc.a. */
aca88567 14281 if (sym != symtab
b8871f35 14282 && ELF_ST_TYPE (sym->st_info) != STT_COMMON
55f25fc3 14283 && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
5b18a4bc 14284 {
d3a49aa8 14285 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
dda8d76d
NC
14286 get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)),
14287 printable_section_name (filedata, relsec),
d3a49aa8 14288 (long int)(rp - relocs));
aca88567 14289 continue;
5b18a4bc 14290 }
252b5132 14291
4dc3c23d
AM
14292 addend = 0;
14293 if (is_rela)
14294 addend += rp->r_addend;
c47320c3
AM
14295 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
14296 partial_inplace. */
4dc3c23d 14297 if (!is_rela
dda8d76d 14298 || (filedata->file_header.e_machine == EM_XTENSA
4dc3c23d 14299 && reloc_type == 1)
dda8d76d
NC
14300 || ((filedata->file_header.e_machine == EM_PJ
14301 || filedata->file_header.e_machine == EM_PJ_OLD)
c47320c3 14302 && reloc_type == 1)
dda8d76d
NC
14303 || ((filedata->file_header.e_machine == EM_D30V
14304 || filedata->file_header.e_machine == EM_CYGNUS_D30V)
03336641
JW
14305 && reloc_type == 12)
14306 || reloc_inplace)
39e07931
AS
14307 {
14308 if (is_6bit_inplace_sub_reloc (filedata, reloc_type))
14309 addend += byte_get (rloc, reloc_size) & 0x3f;
14310 else
14311 addend += byte_get (rloc, reloc_size);
14312 }
cb8f3167 14313
dda8d76d
NC
14314 if (is_32bit_pcrel_reloc (filedata, reloc_type)
14315 || is_64bit_pcrel_reloc (filedata, reloc_type))
85acf597
RH
14316 {
14317 /* On HPPA, all pc-relative relocations are biased by 8. */
dda8d76d 14318 if (filedata->file_header.e_machine == EM_PARISC)
85acf597 14319 addend -= 8;
91d6fa6a 14320 byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
85acf597
RH
14321 reloc_size);
14322 }
39e07931
AS
14323 else if (is_6bit_abs_reloc (filedata, reloc_type)
14324 || is_6bit_inplace_sub_reloc (filedata, reloc_type))
14325 {
14326 if (reloc_subtract)
14327 addend -= sym->st_value;
14328 else
14329 addend += sym->st_value;
14330 addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0);
14331 byte_put (rloc, addend, reloc_size);
14332 }
03336641
JW
14333 else if (reloc_subtract)
14334 byte_put (rloc, addend - sym->st_value, reloc_size);
41e92641 14335 else
91d6fa6a 14336 byte_put (rloc, addend + sym->st_value, reloc_size);
5b18a4bc 14337 }
252b5132 14338
5b18a4bc 14339 free (symtab);
f84ce13b
NC
14340 /* Let the target specific reloc processing code know that
14341 we have finished with these relocs. */
dda8d76d 14342 target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0);
d1c4b12b
NC
14343
14344 if (relocs_return)
14345 {
14346 * (Elf_Internal_Rela **) relocs_return = relocs;
14347 * num_relocs_return = num_relocs;
14348 }
14349 else
14350 free (relocs);
14351
5b18a4bc
NC
14352 break;
14353 }
32ec8896 14354
dfc616fa 14355 return TRUE;
5b18a4bc 14356}
103f02d3 14357
cf13d699 14358#ifdef SUPPORT_DISASSEMBLY
32ec8896 14359static bfd_boolean
dda8d76d 14360disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 14361{
dda8d76d 14362 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section));
cf13d699 14363
74e1a04b 14364 /* FIXME: XXX -- to be done --- XXX */
cf13d699 14365
32ec8896 14366 return TRUE;
cf13d699
NC
14367}
14368#endif
14369
14370/* Reads in the contents of SECTION from FILE, returning a pointer
14371 to a malloc'ed buffer or NULL if something went wrong. */
14372
14373static char *
dda8d76d 14374get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 14375{
dda8d76d 14376 bfd_size_type num_bytes = section->sh_size;
cf13d699
NC
14377
14378 if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
14379 {
c6b78c96 14380 printf (_("Section '%s' has no data to dump.\n"),
dda8d76d 14381 printable_section_name (filedata, section));
cf13d699
NC
14382 return NULL;
14383 }
14384
dda8d76d 14385 return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes,
3f5e193b 14386 _("section contents"));
cf13d699
NC
14387}
14388
0e602686
NC
14389/* Uncompresses a section that was compressed using zlib, in place. */
14390
14391static bfd_boolean
dda8d76d
NC
14392uncompress_section_contents (unsigned char ** buffer,
14393 dwarf_size_type uncompressed_size,
14394 dwarf_size_type * size)
0e602686
NC
14395{
14396 dwarf_size_type compressed_size = *size;
14397 unsigned char * compressed_buffer = *buffer;
14398 unsigned char * uncompressed_buffer;
14399 z_stream strm;
14400 int rc;
14401
14402 /* It is possible the section consists of several compressed
14403 buffers concatenated together, so we uncompress in a loop. */
14404 /* PR 18313: The state field in the z_stream structure is supposed
14405 to be invisible to the user (ie us), but some compilers will
14406 still complain about it being used without initialisation. So
14407 we first zero the entire z_stream structure and then set the fields
14408 that we need. */
14409 memset (& strm, 0, sizeof strm);
14410 strm.avail_in = compressed_size;
14411 strm.next_in = (Bytef *) compressed_buffer;
14412 strm.avail_out = uncompressed_size;
14413 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
14414
14415 rc = inflateInit (& strm);
14416 while (strm.avail_in > 0)
14417 {
14418 if (rc != Z_OK)
3624a6c1 14419 break;
0e602686
NC
14420 strm.next_out = ((Bytef *) uncompressed_buffer
14421 + (uncompressed_size - strm.avail_out));
14422 rc = inflate (&strm, Z_FINISH);
14423 if (rc != Z_STREAM_END)
3624a6c1 14424 break;
0e602686
NC
14425 rc = inflateReset (& strm);
14426 }
ad92f33d
AM
14427 if (inflateEnd (& strm) != Z_OK
14428 || rc != Z_OK
0e602686
NC
14429 || strm.avail_out != 0)
14430 goto fail;
14431
14432 *buffer = uncompressed_buffer;
14433 *size = uncompressed_size;
14434 return TRUE;
14435
14436 fail:
14437 free (uncompressed_buffer);
14438 /* Indicate decompression failure. */
14439 *buffer = NULL;
14440 return FALSE;
14441}
dd24e3da 14442
32ec8896 14443static bfd_boolean
dda8d76d 14444dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
cf13d699 14445{
0e602686
NC
14446 Elf_Internal_Shdr * relsec;
14447 bfd_size_type num_bytes;
fd8008d8
L
14448 unsigned char * data;
14449 unsigned char * end;
14450 unsigned char * real_start;
14451 unsigned char * start;
0e602686 14452 bfd_boolean some_strings_shown;
cf13d699 14453
dda8d76d 14454 real_start = start = (unsigned char *) get_section_contents (section, filedata);
cf13d699 14455 if (start == NULL)
c6b78c96
NC
14456 /* PR 21820: Do not fail if the section was empty. */
14457 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
14458
0e602686 14459 num_bytes = section->sh_size;
cf13d699 14460
835f2fae
NC
14461 if (filedata->is_separate)
14462 printf (_("\nString dump of section '%s' in linked file %s:\n"),
14463 printable_section_name (filedata, section),
14464 filedata->file_name);
14465 else
14466 printf (_("\nString dump of section '%s':\n"),
14467 printable_section_name (filedata, section));
cf13d699 14468
0e602686
NC
14469 if (decompress_dumps)
14470 {
14471 dwarf_size_type new_size = num_bytes;
14472 dwarf_size_type uncompressed_size = 0;
14473
14474 if ((section->sh_flags & SHF_COMPRESSED) != 0)
14475 {
14476 Elf_Internal_Chdr chdr;
14477 unsigned int compression_header_size
ebdf1ebf
NC
14478 = get_compression_header (& chdr, (unsigned char *) start,
14479 num_bytes);
5844b465
NC
14480 if (compression_header_size == 0)
14481 /* An error message will have already been generated
14482 by get_compression_header. */
14483 goto error_out;
0e602686 14484
813dabb9 14485 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
0e602686 14486 {
813dabb9 14487 warn (_("section '%s' has unsupported compress type: %d\n"),
dda8d76d 14488 printable_section_name (filedata, section), chdr.ch_type);
f761cb13 14489 goto error_out;
813dabb9 14490 }
813dabb9
L
14491 uncompressed_size = chdr.ch_size;
14492 start += compression_header_size;
14493 new_size -= compression_header_size;
0e602686
NC
14494 }
14495 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
14496 {
14497 /* Read the zlib header. In this case, it should be "ZLIB"
14498 followed by the uncompressed section size, 8 bytes in
14499 big-endian order. */
14500 uncompressed_size = start[4]; uncompressed_size <<= 8;
14501 uncompressed_size += start[5]; uncompressed_size <<= 8;
14502 uncompressed_size += start[6]; uncompressed_size <<= 8;
14503 uncompressed_size += start[7]; uncompressed_size <<= 8;
14504 uncompressed_size += start[8]; uncompressed_size <<= 8;
14505 uncompressed_size += start[9]; uncompressed_size <<= 8;
14506 uncompressed_size += start[10]; uncompressed_size <<= 8;
14507 uncompressed_size += start[11];
14508 start += 12;
14509 new_size -= 12;
14510 }
14511
1835f746
NC
14512 if (uncompressed_size)
14513 {
14514 if (uncompress_section_contents (& start,
14515 uncompressed_size, & new_size))
14516 num_bytes = new_size;
14517 else
14518 {
14519 error (_("Unable to decompress section %s\n"),
dda8d76d 14520 printable_section_name (filedata, section));
f761cb13 14521 goto error_out;
1835f746
NC
14522 }
14523 }
bc303e5d
NC
14524 else
14525 start = real_start;
0e602686 14526 }
fd8008d8 14527
cf13d699
NC
14528 /* If the section being dumped has relocations against it the user might
14529 be expecting these relocations to have been applied. Check for this
14530 case and issue a warning message in order to avoid confusion.
14531 FIXME: Maybe we ought to have an option that dumps a section with
14532 relocs applied ? */
dda8d76d
NC
14533 for (relsec = filedata->section_headers;
14534 relsec < filedata->section_headers + filedata->file_header.e_shnum;
cf13d699
NC
14535 ++relsec)
14536 {
14537 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
14538 || relsec->sh_info >= filedata->file_header.e_shnum
14539 || filedata->section_headers + relsec->sh_info != section
cf13d699 14540 || relsec->sh_size == 0
dda8d76d 14541 || relsec->sh_link >= filedata->file_header.e_shnum)
cf13d699
NC
14542 continue;
14543
14544 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14545 break;
14546 }
14547
cf13d699
NC
14548 data = start;
14549 end = start + num_bytes;
14550 some_strings_shown = FALSE;
14551
ba3265d0
NC
14552#ifdef HAVE_MBSTATE_T
14553 mbstate_t state;
14554 /* Initialise the multibyte conversion state. */
14555 memset (& state, 0, sizeof (state));
14556#endif
14557
14558 bfd_boolean continuing = FALSE;
14559
cf13d699
NC
14560 while (data < end)
14561 {
14562 while (!ISPRINT (* data))
14563 if (++ data >= end)
14564 break;
14565
14566 if (data < end)
14567 {
071436c6
NC
14568 size_t maxlen = end - data;
14569
ba3265d0
NC
14570 if (continuing)
14571 {
14572 printf (" ");
14573 continuing = FALSE;
14574 }
14575 else
14576 {
d1ce973e 14577 printf (" [%6lx] ", (unsigned long) (data - start));
ba3265d0
NC
14578 }
14579
4082ef84
NC
14580 if (maxlen > 0)
14581 {
f3da8a96 14582 char c = 0;
ba3265d0
NC
14583
14584 while (maxlen)
14585 {
14586 c = *data++;
14587
14588 if (c == 0)
14589 break;
14590
14591 /* PR 25543: Treat new-lines as string-ending characters. */
14592 if (c == '\n')
14593 {
14594 printf ("\\n\n");
14595 if (*data != 0)
14596 continuing = TRUE;
14597 break;
14598 }
14599
14600 /* Do not print control characters directly as they can affect terminal
14601 settings. Such characters usually appear in the names generated
14602 by the assembler for local labels. */
14603 if (ISCNTRL (c))
14604 {
14605 printf ("^%c", c + 0x40);
14606 }
14607 else if (ISPRINT (c))
14608 {
14609 putchar (c);
14610 }
14611 else
14612 {
14613 size_t n;
14614#ifdef HAVE_MBSTATE_T
14615 wchar_t w;
14616#endif
14617 /* Let printf do the hard work of displaying multibyte characters. */
14618 printf ("%.1s", data - 1);
14619#ifdef HAVE_MBSTATE_T
14620 /* Try to find out how many bytes made up the character that was
14621 just printed. Advance the symbol pointer past the bytes that
14622 were displayed. */
14623 n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state);
14624#else
14625 n = 1;
14626#endif
14627 if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
14628 data += (n - 1);
14629 }
14630 }
14631
14632 if (c != '\n')
14633 putchar ('\n');
4082ef84
NC
14634 }
14635 else
14636 {
14637 printf (_("<corrupt>\n"));
14638 data = end;
14639 }
cf13d699
NC
14640 some_strings_shown = TRUE;
14641 }
14642 }
14643
14644 if (! some_strings_shown)
14645 printf (_(" No strings found in this section."));
14646
0e602686 14647 free (real_start);
cf13d699
NC
14648
14649 putchar ('\n');
32ec8896 14650 return TRUE;
f761cb13
AM
14651
14652error_out:
14653 free (real_start);
14654 return FALSE;
cf13d699
NC
14655}
14656
32ec8896 14657static bfd_boolean
dda8d76d
NC
14658dump_section_as_bytes (Elf_Internal_Shdr * section,
14659 Filedata * filedata,
14660 bfd_boolean relocate)
cf13d699
NC
14661{
14662 Elf_Internal_Shdr * relsec;
0e602686
NC
14663 bfd_size_type bytes;
14664 bfd_size_type section_size;
14665 bfd_vma addr;
14666 unsigned char * data;
14667 unsigned char * real_start;
14668 unsigned char * start;
14669
dda8d76d 14670 real_start = start = (unsigned char *) get_section_contents (section, filedata);
cf13d699 14671 if (start == NULL)
c6b78c96
NC
14672 /* PR 21820: Do not fail if the section was empty. */
14673 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
32ec8896 14674
0e602686 14675 section_size = section->sh_size;
cf13d699 14676
835f2fae
NC
14677 if (filedata->is_separate)
14678 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
14679 printable_section_name (filedata, section),
14680 filedata->file_name);
14681 else
14682 printf (_("\nHex dump of section '%s':\n"),
14683 printable_section_name (filedata, section));
cf13d699 14684
0e602686
NC
14685 if (decompress_dumps)
14686 {
14687 dwarf_size_type new_size = section_size;
14688 dwarf_size_type uncompressed_size = 0;
14689
14690 if ((section->sh_flags & SHF_COMPRESSED) != 0)
14691 {
14692 Elf_Internal_Chdr chdr;
14693 unsigned int compression_header_size
ebdf1ebf 14694 = get_compression_header (& chdr, start, section_size);
0e602686 14695
5844b465
NC
14696 if (compression_header_size == 0)
14697 /* An error message will have already been generated
14698 by get_compression_header. */
14699 goto error_out;
14700
813dabb9 14701 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
0e602686 14702 {
813dabb9 14703 warn (_("section '%s' has unsupported compress type: %d\n"),
dda8d76d 14704 printable_section_name (filedata, section), chdr.ch_type);
f761cb13 14705 goto error_out;
0e602686 14706 }
813dabb9
L
14707 uncompressed_size = chdr.ch_size;
14708 start += compression_header_size;
14709 new_size -= compression_header_size;
0e602686
NC
14710 }
14711 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
14712 {
14713 /* Read the zlib header. In this case, it should be "ZLIB"
14714 followed by the uncompressed section size, 8 bytes in
14715 big-endian order. */
14716 uncompressed_size = start[4]; uncompressed_size <<= 8;
14717 uncompressed_size += start[5]; uncompressed_size <<= 8;
14718 uncompressed_size += start[6]; uncompressed_size <<= 8;
14719 uncompressed_size += start[7]; uncompressed_size <<= 8;
14720 uncompressed_size += start[8]; uncompressed_size <<= 8;
14721 uncompressed_size += start[9]; uncompressed_size <<= 8;
14722 uncompressed_size += start[10]; uncompressed_size <<= 8;
14723 uncompressed_size += start[11];
14724 start += 12;
14725 new_size -= 12;
14726 }
14727
f055032e
NC
14728 if (uncompressed_size)
14729 {
14730 if (uncompress_section_contents (& start, uncompressed_size,
14731 & new_size))
bc303e5d
NC
14732 {
14733 section_size = new_size;
14734 }
f055032e
NC
14735 else
14736 {
14737 error (_("Unable to decompress section %s\n"),
dda8d76d 14738 printable_section_name (filedata, section));
bc303e5d 14739 /* FIXME: Print the section anyway ? */
f761cb13 14740 goto error_out;
f055032e
NC
14741 }
14742 }
bc303e5d
NC
14743 else
14744 start = real_start;
0e602686 14745 }
14ae95f2 14746
cf13d699
NC
14747 if (relocate)
14748 {
dda8d76d 14749 if (! apply_relocations (filedata, section, start, section_size, NULL, NULL))
f761cb13 14750 goto error_out;
cf13d699
NC
14751 }
14752 else
14753 {
14754 /* If the section being dumped has relocations against it the user might
14755 be expecting these relocations to have been applied. Check for this
14756 case and issue a warning message in order to avoid confusion.
14757 FIXME: Maybe we ought to have an option that dumps a section with
14758 relocs applied ? */
dda8d76d
NC
14759 for (relsec = filedata->section_headers;
14760 relsec < filedata->section_headers + filedata->file_header.e_shnum;
cf13d699
NC
14761 ++relsec)
14762 {
14763 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
dda8d76d
NC
14764 || relsec->sh_info >= filedata->file_header.e_shnum
14765 || filedata->section_headers + relsec->sh_info != section
cf13d699 14766 || relsec->sh_size == 0
dda8d76d 14767 || relsec->sh_link >= filedata->file_header.e_shnum)
cf13d699
NC
14768 continue;
14769
14770 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14771 break;
14772 }
14773 }
14774
14775 addr = section->sh_addr;
0e602686 14776 bytes = section_size;
cf13d699
NC
14777 data = start;
14778
14779 while (bytes)
14780 {
14781 int j;
14782 int k;
14783 int lbytes;
14784
14785 lbytes = (bytes > 16 ? 16 : bytes);
14786
14787 printf (" 0x%8.8lx ", (unsigned long) addr);
14788
14789 for (j = 0; j < 16; j++)
14790 {
14791 if (j < lbytes)
14792 printf ("%2.2x", data[j]);
14793 else
14794 printf (" ");
14795
14796 if ((j & 3) == 3)
14797 printf (" ");
14798 }
14799
14800 for (j = 0; j < lbytes; j++)
14801 {
14802 k = data[j];
14803 if (k >= ' ' && k < 0x7f)
14804 printf ("%c", k);
14805 else
14806 printf (".");
14807 }
14808
14809 putchar ('\n');
14810
14811 data += lbytes;
14812 addr += lbytes;
14813 bytes -= lbytes;
14814 }
14815
0e602686 14816 free (real_start);
cf13d699
NC
14817
14818 putchar ('\n');
32ec8896 14819 return TRUE;
f761cb13
AM
14820
14821 error_out:
14822 free (real_start);
14823 return FALSE;
cf13d699
NC
14824}
14825
094e34f2 14826#ifdef ENABLE_LIBCTF
7d9813f1
NA
14827static ctf_sect_t *
14828shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata)
14829{
b9e920ec 14830 buf->cts_name = SECTION_NAME_PRINT (shdr);
7d9813f1
NA
14831 buf->cts_size = shdr->sh_size;
14832 buf->cts_entsize = shdr->sh_entsize;
7d9813f1
NA
14833
14834 return buf;
14835}
14836
14837/* Formatting callback function passed to ctf_dump. Returns either the pointer
14838 it is passed, or a pointer to newly-allocated storage, in which case
14839 dump_ctf() will free it when it no longer needs it. */
14840
2f6ecaed
NA
14841static char *
14842dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
14843 char *s, void *arg)
7d9813f1 14844{
3e50a591 14845 const char *blanks = arg;
7d9813f1
NA
14846 char *new_s;
14847
3e50a591 14848 if (asprintf (&new_s, "%s%s", blanks, s) < 0)
7d9813f1
NA
14849 return s;
14850 return new_s;
14851}
14852
926c9e76
NA
14853/* Dump CTF errors/warnings. */
14854static void
139633c3 14855dump_ctf_errs (ctf_dict_t *fp)
926c9e76
NA
14856{
14857 ctf_next_t *it = NULL;
14858 char *errtext;
14859 int is_warning;
14860 int err;
14861
14862 /* Dump accumulated errors and warnings. */
14863 while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL)
14864 {
5e9b84f7 14865 error (_("%s: %s"), is_warning ? _("warning"): _("error"),
926c9e76
NA
14866 errtext);
14867 free (errtext);
14868 }
14869 if (err != ECTF_NEXT_END)
14870 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err));
14871}
14872
2f6ecaed
NA
14873/* Dump one CTF archive member. */
14874
14875static int
139633c3 14876dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, void *arg)
2f6ecaed 14877{
139633c3 14878 ctf_dict_t *parent = (ctf_dict_t *) arg;
2f6ecaed
NA
14879 const char *things[] = {"Header", "Labels", "Data objects",
14880 "Function objects", "Variables", "Types", "Strings",
14881 ""};
14882 const char **thing;
14883 size_t i;
8b37e7b6 14884 int err = 0;
2f6ecaed
NA
14885
14886 /* Only print out the name of non-default-named archive members.
14887 The name .ctf appears everywhere, even for things that aren't
14888 really archives, so printing it out is liable to be confusing.
14889
14890 The parent, if there is one, is the default-owned archive member:
14891 avoid importing it into itself. (This does no harm, but looks
14892 confusing.) */
14893
14894 if (strcmp (name, ".ctf") != 0)
14895 {
14896 printf (_("\nCTF archive member: %s:\n"), name);
14897 ctf_import (ctf, parent);
14898 }
14899
14900 for (i = 0, thing = things; *thing[0]; thing++, i++)
14901 {
14902 ctf_dump_state_t *s = NULL;
14903 char *item;
14904
14905 printf ("\n %s:\n", *thing);
14906 while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
14907 (void *) " ")) != NULL)
14908 {
14909 printf ("%s\n", item);
14910 free (item);
14911 }
14912
14913 if (ctf_errno (ctf))
14914 {
14915 error (_("Iteration failed: %s, %s\n"), *thing,
14916 ctf_errmsg (ctf_errno (ctf)));
8b37e7b6
NA
14917 err = 1;
14918 goto out;
2f6ecaed
NA
14919 }
14920 }
8b37e7b6
NA
14921
14922 out:
926c9e76 14923 dump_ctf_errs (ctf);
8b37e7b6 14924 return err;
2f6ecaed
NA
14925}
14926
7d9813f1
NA
14927static bfd_boolean
14928dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
14929{
14930 Elf_Internal_Shdr * parent_sec = NULL;
14931 Elf_Internal_Shdr * symtab_sec = NULL;
14932 Elf_Internal_Shdr * strtab_sec = NULL;
d344b407
NA
14933 void * data = NULL;
14934 void * symdata = NULL;
14935 void * strdata = NULL;
14936 void * parentdata = NULL;
14937 ctf_sect_t ctfsect, symsect, strsect, parentsect;
14938 ctf_sect_t * symsectp = NULL;
14939 ctf_sect_t * strsectp = NULL;
2f6ecaed
NA
14940 ctf_archive_t * ctfa = NULL;
14941 ctf_archive_t * parenta = NULL, *lookparent;
139633c3 14942 ctf_dict_t * parent = NULL;
7d9813f1 14943
7d9813f1
NA
14944 int err;
14945 bfd_boolean ret = FALSE;
7d9813f1
NA
14946
14947 shdr_to_ctf_sect (&ctfsect, section, filedata);
14948 data = get_section_contents (section, filedata);
14949 ctfsect.cts_data = data;
14950
616febde 14951 if (!dump_ctf_symtab_name)
3d16b64e 14952 dump_ctf_symtab_name = strdup (".dynsym");
616febde
NA
14953
14954 if (!dump_ctf_strtab_name)
3d16b64e 14955 dump_ctf_strtab_name = strdup (".dynstr");
616febde
NA
14956
14957 if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0)
7d9813f1
NA
14958 {
14959 if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL)
14960 {
14961 error (_("No symbol section named %s\n"), dump_ctf_symtab_name);
14962 goto fail;
14963 }
14964 if ((symdata = (void *) get_data (NULL, filedata,
14965 symtab_sec->sh_offset, 1,
14966 symtab_sec->sh_size,
14967 _("symbols"))) == NULL)
14968 goto fail;
14969 symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata);
14970 symsect.cts_data = symdata;
14971 }
835f2fae 14972
df16e041 14973 if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0)
7d9813f1
NA
14974 {
14975 if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL)
14976 {
14977 error (_("No string table section named %s\n"),
14978 dump_ctf_strtab_name);
14979 goto fail;
14980 }
14981 if ((strdata = (void *) get_data (NULL, filedata,
14982 strtab_sec->sh_offset, 1,
14983 strtab_sec->sh_size,
14984 _("strings"))) == NULL)
14985 goto fail;
14986 strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata);
14987 strsect.cts_data = strdata;
14988 }
835f2fae 14989
7d9813f1
NA
14990 if (dump_ctf_parent_name)
14991 {
14992 if ((parent_sec = find_section (filedata, dump_ctf_parent_name)) == NULL)
14993 {
14994 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name);
14995 goto fail;
14996 }
14997 if ((parentdata = (void *) get_data (NULL, filedata,
14998 parent_sec->sh_offset, 1,
14999 parent_sec->sh_size,
15000 _("CTF parent"))) == NULL)
15001 goto fail;
15002 shdr_to_ctf_sect (&parentsect, parent_sec, filedata);
15003 parentsect.cts_data = parentdata;
15004 }
15005
2f6ecaed
NA
15006 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
15007 libctf papers over the difference, so we can pretend it is always an
15008 archive. Possibly open the parent as well, if one was specified. */
7d9813f1 15009
2f6ecaed 15010 if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
7d9813f1 15011 {
926c9e76 15012 dump_ctf_errs (NULL);
7d9813f1
NA
15013 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
15014 goto fail;
15015 }
15016
96c61be5
NA
15017 ctf_arc_symsect_endianness (ctfa, filedata->file_header.e_ident[EI_DATA]
15018 != ELFDATA2MSB);
15019
7d9813f1
NA
15020 if (parentdata)
15021 {
2f6ecaed
NA
15022 if ((parenta = ctf_arc_bufopen (&parentsect, symsectp, strsectp,
15023 &err)) == NULL)
7d9813f1 15024 {
926c9e76 15025 dump_ctf_errs (NULL);
7d9813f1
NA
15026 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
15027 goto fail;
15028 }
2f6ecaed
NA
15029 lookparent = parenta;
15030 }
15031 else
15032 lookparent = ctfa;
7d9813f1 15033
2f6ecaed
NA
15034 /* Assume that the applicable parent archive member is the default one.
15035 (This is what all known implementations are expected to do, if they
15036 put CTFs and their parents in archives together.) */
ae41200b 15037 if ((parent = ctf_dict_open (lookparent, NULL, &err)) == NULL)
2f6ecaed 15038 {
926c9e76 15039 dump_ctf_errs (NULL);
2f6ecaed
NA
15040 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
15041 goto fail;
7d9813f1
NA
15042 }
15043
15044 ret = TRUE;
15045
835f2fae
NC
15046 if (filedata->is_separate)
15047 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
15048 printable_section_name (filedata, section),
15049 filedata->file_name);
15050 else
15051 printf (_("\nDump of CTF section '%s':\n"),
15052 printable_section_name (filedata, section));
7d9813f1 15053
83d59285
NA
15054 if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0)
15055 {
15056 dump_ctf_errs (NULL);
15057 error (_("CTF member open failure: %s\n"), ctf_errmsg (err));
15058 ret = FALSE;
15059 }
7d9813f1
NA
15060
15061 fail:
139633c3 15062 ctf_dict_close (parent);
2f6ecaed
NA
15063 ctf_close (ctfa);
15064 ctf_close (parenta);
7d9813f1
NA
15065 free (parentdata);
15066 free (data);
15067 free (symdata);
15068 free (strdata);
15069 return ret;
15070}
094e34f2 15071#endif
7d9813f1 15072
32ec8896 15073static bfd_boolean
dda8d76d
NC
15074load_specific_debug_section (enum dwarf_section_display_enum debug,
15075 const Elf_Internal_Shdr * sec,
15076 void * data)
1007acb3 15077{
2cf0635d 15078 struct dwarf_section * section = &debug_displays [debug].section;
19e6b90e 15079 char buf [64];
dda8d76d 15080 Filedata * filedata = (Filedata *) data;
9abca702 15081
19e6b90e 15082 if (section->start != NULL)
dda8d76d
NC
15083 {
15084 /* If it is already loaded, do nothing. */
15085 if (streq (section->filename, filedata->file_name))
15086 return TRUE;
15087 free (section->start);
15088 }
1007acb3 15089
19e6b90e
L
15090 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
15091 section->address = sec->sh_addr;
dda8d76d
NC
15092 section->filename = filedata->file_name;
15093 section->start = (unsigned char *) get_data (NULL, filedata,
3f5e193b
NC
15094 sec->sh_offset, 1,
15095 sec->sh_size, buf);
59245841
NC
15096 if (section->start == NULL)
15097 section->size = 0;
15098 else
15099 {
77115a4a
L
15100 unsigned char *start = section->start;
15101 dwarf_size_type size = sec->sh_size;
dab394de 15102 dwarf_size_type uncompressed_size = 0;
77115a4a
L
15103
15104 if ((sec->sh_flags & SHF_COMPRESSED) != 0)
15105 {
15106 Elf_Internal_Chdr chdr;
d8024a91
NC
15107 unsigned int compression_header_size;
15108
f53be977
L
15109 if (size < (is_32bit_elf
15110 ? sizeof (Elf32_External_Chdr)
15111 : sizeof (Elf64_External_Chdr)))
d8024a91 15112 {
55be8fd0 15113 warn (_("compressed section %s is too small to contain a compression header\n"),
d8024a91 15114 section->name);
32ec8896 15115 return FALSE;
d8024a91
NC
15116 }
15117
ebdf1ebf 15118 compression_header_size = get_compression_header (&chdr, start, size);
5844b465
NC
15119 if (compression_header_size == 0)
15120 /* An error message will have already been generated
15121 by get_compression_header. */
15122 return FALSE;
d8024a91 15123
813dabb9
L
15124 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
15125 {
15126 warn (_("section '%s' has unsupported compress type: %d\n"),
15127 section->name, chdr.ch_type);
32ec8896 15128 return FALSE;
813dabb9 15129 }
dab394de 15130 uncompressed_size = chdr.ch_size;
77115a4a
L
15131 start += compression_header_size;
15132 size -= compression_header_size;
15133 }
dab394de
L
15134 else if (size > 12 && streq ((char *) start, "ZLIB"))
15135 {
15136 /* Read the zlib header. In this case, it should be "ZLIB"
15137 followed by the uncompressed section size, 8 bytes in
15138 big-endian order. */
15139 uncompressed_size = start[4]; uncompressed_size <<= 8;
15140 uncompressed_size += start[5]; uncompressed_size <<= 8;
15141 uncompressed_size += start[6]; uncompressed_size <<= 8;
15142 uncompressed_size += start[7]; uncompressed_size <<= 8;
15143 uncompressed_size += start[8]; uncompressed_size <<= 8;
15144 uncompressed_size += start[9]; uncompressed_size <<= 8;
15145 uncompressed_size += start[10]; uncompressed_size <<= 8;
15146 uncompressed_size += start[11];
15147 start += 12;
15148 size -= 12;
15149 }
15150
1835f746 15151 if (uncompressed_size)
77115a4a 15152 {
1835f746
NC
15153 if (uncompress_section_contents (&start, uncompressed_size,
15154 &size))
15155 {
15156 /* Free the compressed buffer, update the section buffer
15157 and the section size if uncompress is successful. */
15158 free (section->start);
15159 section->start = start;
15160 }
15161 else
15162 {
15163 error (_("Unable to decompress section %s\n"),
dda8d76d 15164 printable_section_name (filedata, sec));
32ec8896 15165 return FALSE;
1835f746 15166 }
77115a4a 15167 }
bc303e5d 15168
77115a4a 15169 section->size = size;
59245841 15170 }
4a114e3e 15171
1b315056 15172 if (section->start == NULL)
32ec8896 15173 return FALSE;
1b315056 15174
19e6b90e 15175 if (debug_displays [debug].relocate)
32ec8896 15176 {
dda8d76d 15177 if (! apply_relocations (filedata, sec, section->start, section->size,
32ec8896
NC
15178 & section->reloc_info, & section->num_relocs))
15179 return FALSE;
15180 }
d1c4b12b
NC
15181 else
15182 {
15183 section->reloc_info = NULL;
15184 section->num_relocs = 0;
15185 }
1007acb3 15186
32ec8896 15187 return TRUE;
1007acb3
L
15188}
15189
301a9420
AM
15190#if HAVE_LIBDEBUGINFOD
15191/* Return a hex string representation of the build-id. */
15192unsigned char *
15193get_build_id (void * data)
15194{
ca0e11aa 15195 Filedata * filedata = (Filedata *) data;
301a9420
AM
15196 Elf_Internal_Shdr * shdr;
15197 unsigned long i;
15198
55be8fd0
NC
15199 /* Iterate through notes to find note.gnu.build-id.
15200 FIXME: Only the first note in any note section is examined. */
301a9420
AM
15201 for (i = 0, shdr = filedata->section_headers;
15202 i < filedata->file_header.e_shnum && shdr != NULL;
15203 i++, shdr++)
15204 {
15205 if (shdr->sh_type != SHT_NOTE)
15206 continue;
15207
15208 char * next;
15209 char * end;
15210 size_t data_remaining;
15211 size_t min_notesz;
15212 Elf_External_Note * enote;
15213 Elf_Internal_Note inote;
15214
15215 bfd_vma offset = shdr->sh_offset;
15216 bfd_vma align = shdr->sh_addralign;
15217 bfd_vma length = shdr->sh_size;
15218
15219 enote = (Elf_External_Note *) get_section_contents (shdr, filedata);
15220 if (enote == NULL)
15221 continue;
15222
15223 if (align < 4)
15224 align = 4;
15225 else if (align != 4 && align != 8)
f761cb13
AM
15226 {
15227 free (enote);
15228 continue;
15229 }
301a9420
AM
15230
15231 end = (char *) enote + length;
15232 data_remaining = end - (char *) enote;
15233
15234 if (!is_ia64_vms (filedata))
15235 {
15236 min_notesz = offsetof (Elf_External_Note, name);
15237 if (data_remaining < min_notesz)
15238 {
55be8fd0
NC
15239 warn (_("\
15240malformed note encountered in section %s whilst scanning for build-id note\n"),
15241 printable_section_name (filedata, shdr));
f761cb13 15242 free (enote);
55be8fd0 15243 continue;
301a9420
AM
15244 }
15245 data_remaining -= min_notesz;
15246
15247 inote.type = BYTE_GET (enote->type);
15248 inote.namesz = BYTE_GET (enote->namesz);
15249 inote.namedata = enote->name;
15250 inote.descsz = BYTE_GET (enote->descsz);
15251 inote.descdata = ((char *) enote
15252 + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
15253 inote.descpos = offset + (inote.descdata - (char *) enote);
15254 next = ((char *) enote
15255 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
15256 }
15257 else
15258 {
15259 Elf64_External_VMS_Note *vms_enote;
15260
15261 /* PR binutils/15191
15262 Make sure that there is enough data to read. */
15263 min_notesz = offsetof (Elf64_External_VMS_Note, name);
15264 if (data_remaining < min_notesz)
15265 {
55be8fd0
NC
15266 warn (_("\
15267malformed note encountered in section %s whilst scanning for build-id note\n"),
15268 printable_section_name (filedata, shdr));
f761cb13 15269 free (enote);
55be8fd0 15270 continue;
301a9420
AM
15271 }
15272 data_remaining -= min_notesz;
15273
15274 vms_enote = (Elf64_External_VMS_Note *) enote;
15275 inote.type = BYTE_GET (vms_enote->type);
15276 inote.namesz = BYTE_GET (vms_enote->namesz);
15277 inote.namedata = vms_enote->name;
15278 inote.descsz = BYTE_GET (vms_enote->descsz);
15279 inote.descdata = inote.namedata + align_power (inote.namesz, 3);
15280 inote.descpos = offset + (inote.descdata - (char *) enote);
15281 next = inote.descdata + align_power (inote.descsz, 3);
15282 }
15283
15284 /* Skip malformed notes. */
15285 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
15286 || (size_t) (inote.descdata - inote.namedata) > data_remaining
15287 || (size_t) (next - inote.descdata) < inote.descsz
15288 || ((size_t) (next - inote.descdata)
15289 > data_remaining - (size_t) (inote.descdata - inote.namedata)))
15290 {
55be8fd0
NC
15291 warn (_("\
15292malformed note encountered in section %s whilst scanning for build-id note\n"),
15293 printable_section_name (filedata, shdr));
f761cb13 15294 free (enote);
301a9420
AM
15295 continue;
15296 }
15297
15298 /* Check if this is the build-id note. If so then convert the build-id
15299 bytes to a hex string. */
15300 if (inote.namesz > 0
15301 && const_strneq (inote.namedata, "GNU")
15302 && inote.type == NT_GNU_BUILD_ID)
15303 {
15304 unsigned long j;
15305 char * build_id;
15306
15307 build_id = malloc (inote.descsz * 2 + 1);
15308 if (build_id == NULL)
f761cb13
AM
15309 {
15310 free (enote);
15311 return NULL;
15312 }
301a9420
AM
15313
15314 for (j = 0; j < inote.descsz; ++j)
15315 sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff);
15316 build_id[inote.descsz * 2] = '\0';
f761cb13 15317 free (enote);
301a9420 15318
55be8fd0 15319 return (unsigned char *) build_id;
301a9420 15320 }
f761cb13 15321 free (enote);
301a9420
AM
15322 }
15323
15324 return NULL;
15325}
15326#endif /* HAVE_LIBDEBUGINFOD */
15327
657d0d47
CC
15328/* If this is not NULL, load_debug_section will only look for sections
15329 within the list of sections given here. */
32ec8896 15330static unsigned int * section_subset = NULL;
657d0d47 15331
32ec8896 15332bfd_boolean
dda8d76d 15333load_debug_section (enum dwarf_section_display_enum debug, void * data)
d966045b 15334{
2cf0635d
NC
15335 struct dwarf_section * section = &debug_displays [debug].section;
15336 Elf_Internal_Shdr * sec;
dda8d76d
NC
15337 Filedata * filedata = (Filedata *) data;
15338
f425ec66
NC
15339 /* Without section headers we cannot find any sections. */
15340 if (filedata->section_headers == NULL)
15341 return FALSE;
15342
9c1ce108
AM
15343 if (filedata->string_table == NULL
15344 && filedata->file_header.e_shstrndx != SHN_UNDEF
15345 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
dda8d76d
NC
15346 {
15347 Elf_Internal_Shdr * strs;
15348
15349 /* Read in the string table, so that we have section names to scan. */
15350 strs = filedata->section_headers + filedata->file_header.e_shstrndx;
15351
4dff97b2 15352 if (strs != NULL && strs->sh_size != 0)
dda8d76d 15353 {
9c1ce108
AM
15354 filedata->string_table
15355 = (char *) get_data (NULL, filedata, strs->sh_offset,
15356 1, strs->sh_size, _("string table"));
dda8d76d 15357
9c1ce108
AM
15358 filedata->string_table_length
15359 = filedata->string_table != NULL ? strs->sh_size : 0;
dda8d76d
NC
15360 }
15361 }
d966045b
DJ
15362
15363 /* Locate the debug section. */
dda8d76d 15364 sec = find_section_in_set (filedata, section->uncompressed_name, section_subset);
d966045b
DJ
15365 if (sec != NULL)
15366 section->name = section->uncompressed_name;
15367 else
15368 {
dda8d76d 15369 sec = find_section_in_set (filedata, section->compressed_name, section_subset);
d966045b
DJ
15370 if (sec != NULL)
15371 section->name = section->compressed_name;
15372 }
15373 if (sec == NULL)
32ec8896 15374 return FALSE;
d966045b 15375
657d0d47
CC
15376 /* If we're loading from a subset of sections, and we've loaded
15377 a section matching this name before, it's likely that it's a
15378 different one. */
15379 if (section_subset != NULL)
15380 free_debug_section (debug);
15381
dda8d76d 15382 return load_specific_debug_section (debug, sec, data);
d966045b
DJ
15383}
15384
19e6b90e
L
15385void
15386free_debug_section (enum dwarf_section_display_enum debug)
1007acb3 15387{
2cf0635d 15388 struct dwarf_section * section = &debug_displays [debug].section;
1007acb3 15389
19e6b90e
L
15390 if (section->start == NULL)
15391 return;
1007acb3 15392
19e6b90e
L
15393 free ((char *) section->start);
15394 section->start = NULL;
15395 section->address = 0;
15396 section->size = 0;
a788aedd 15397
9db70fc3
AM
15398 free (section->reloc_info);
15399 section->reloc_info = NULL;
15400 section->num_relocs = 0;
1007acb3
L
15401}
15402
32ec8896 15403static bfd_boolean
dda8d76d 15404display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata)
1007acb3 15405{
b9e920ec 15406 char * name = SECTION_NAME_VALID (section) ? SECTION_NAME (section) : "";
dda8d76d 15407 const char * print_name = printable_section_name (filedata, section);
19e6b90e 15408 bfd_size_type length;
32ec8896 15409 bfd_boolean result = TRUE;
3f5e193b 15410 int i;
1007acb3 15411
19e6b90e
L
15412 length = section->sh_size;
15413 if (length == 0)
1007acb3 15414 {
74e1a04b 15415 printf (_("\nSection '%s' has no debugging data.\n"), print_name);
32ec8896 15416 return TRUE;
1007acb3 15417 }
5dff79d8
NC
15418 if (section->sh_type == SHT_NOBITS)
15419 {
15420 /* There is no point in dumping the contents of a debugging section
15421 which has the NOBITS type - the bits in the file will be random.
15422 This can happen when a file containing a .eh_frame section is
15423 stripped with the --only-keep-debug command line option. */
74e1a04b
NC
15424 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
15425 print_name);
32ec8896 15426 return FALSE;
5dff79d8 15427 }
1007acb3 15428
0112cd26 15429 if (const_strneq (name, ".gnu.linkonce.wi."))
19e6b90e 15430 name = ".debug_info";
1007acb3 15431
19e6b90e
L
15432 /* See if we know how to display the contents of this section. */
15433 for (i = 0; i < max; i++)
d85bf2ba
NC
15434 {
15435 enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i;
15436 struct dwarf_section_display * display = debug_displays + i;
15437 struct dwarf_section * sec = & display->section;
d966045b 15438
d85bf2ba
NC
15439 if (streq (sec->uncompressed_name, name)
15440 || (id == line && const_strneq (name, ".debug_line."))
15441 || streq (sec->compressed_name, name))
15442 {
15443 bfd_boolean secondary = (section != find_section (filedata, name));
1007acb3 15444
d85bf2ba
NC
15445 if (secondary)
15446 free_debug_section (id);
dda8d76d 15447
d85bf2ba
NC
15448 if (i == line && const_strneq (name, ".debug_line."))
15449 sec->name = name;
15450 else if (streq (sec->uncompressed_name, name))
15451 sec->name = sec->uncompressed_name;
15452 else
15453 sec->name = sec->compressed_name;
657d0d47 15454
d85bf2ba
NC
15455 if (load_specific_debug_section (id, section, filedata))
15456 {
15457 /* If this debug section is part of a CU/TU set in a .dwp file,
15458 restrict load_debug_section to the sections in that set. */
15459 section_subset = find_cu_tu_set (filedata, shndx);
1007acb3 15460
d85bf2ba 15461 result &= display->display (sec, filedata);
657d0d47 15462
d85bf2ba 15463 section_subset = NULL;
1007acb3 15464
44266f36 15465 if (secondary || (id != info && id != abbrev && id != debug_addr))
d85bf2ba
NC
15466 free_debug_section (id);
15467 }
15468 break;
15469 }
15470 }
1007acb3 15471
19e6b90e 15472 if (i == max)
1007acb3 15473 {
74e1a04b 15474 printf (_("Unrecognized debug section: %s\n"), print_name);
32ec8896 15475 result = FALSE;
1007acb3
L
15476 }
15477
19e6b90e 15478 return result;
5b18a4bc 15479}
103f02d3 15480
aef1f6d0
DJ
15481/* Set DUMP_SECTS for all sections where dumps were requested
15482 based on section name. */
15483
15484static void
dda8d76d 15485initialise_dumps_byname (Filedata * filedata)
aef1f6d0 15486{
2cf0635d 15487 struct dump_list_entry * cur;
aef1f6d0
DJ
15488
15489 for (cur = dump_sects_byname; cur; cur = cur->next)
15490 {
15491 unsigned int i;
32ec8896 15492 bfd_boolean any = FALSE;
aef1f6d0 15493
dda8d76d 15494 for (i = 0; i < filedata->file_header.e_shnum; i++)
b9e920ec
AM
15495 if (SECTION_NAME_VALID (filedata->section_headers + i)
15496 && streq (SECTION_NAME (filedata->section_headers + i), cur->name))
aef1f6d0 15497 {
6431e409 15498 request_dump_bynumber (&filedata->dump, i, cur->type);
32ec8896 15499 any = TRUE;
aef1f6d0
DJ
15500 }
15501
835f2fae
NC
15502 if (!any && !filedata->is_separate)
15503 warn (_("Section '%s' was not dumped because it does not exist\n"),
15504 cur->name);
aef1f6d0
DJ
15505 }
15506}
15507
32ec8896 15508static bfd_boolean
dda8d76d 15509process_section_contents (Filedata * filedata)
5b18a4bc 15510{
2cf0635d 15511 Elf_Internal_Shdr * section;
19e6b90e 15512 unsigned int i;
32ec8896 15513 bfd_boolean res = TRUE;
103f02d3 15514
19e6b90e 15515 if (! do_dump)
32ec8896 15516 return TRUE;
103f02d3 15517
dda8d76d 15518 initialise_dumps_byname (filedata);
aef1f6d0 15519
dda8d76d 15520 for (i = 0, section = filedata->section_headers;
6431e409 15521 i < filedata->file_header.e_shnum && i < filedata->dump.num_dump_sects;
19e6b90e
L
15522 i++, section++)
15523 {
6431e409 15524 dump_type dump = filedata->dump.dump_sects[i];
dda8d76d 15525
d6bfbc39
NC
15526 if (filedata->is_separate && ! process_links)
15527 dump &= DEBUG_DUMP;
15528
19e6b90e 15529#ifdef SUPPORT_DISASSEMBLY
dda8d76d
NC
15530 if (dump & DISASS_DUMP)
15531 {
15532 if (! disassemble_section (section, filedata))
15533 res = FALSE;
15534 }
19e6b90e 15535#endif
dda8d76d 15536 if (dump & HEX_DUMP)
32ec8896 15537 {
dda8d76d 15538 if (! dump_section_as_bytes (section, filedata, FALSE))
32ec8896
NC
15539 res = FALSE;
15540 }
103f02d3 15541
dda8d76d 15542 if (dump & RELOC_DUMP)
32ec8896 15543 {
dda8d76d 15544 if (! dump_section_as_bytes (section, filedata, TRUE))
32ec8896
NC
15545 res = FALSE;
15546 }
09c11c86 15547
dda8d76d 15548 if (dump & STRING_DUMP)
32ec8896 15549 {
dda8d76d 15550 if (! dump_section_as_strings (section, filedata))
32ec8896
NC
15551 res = FALSE;
15552 }
cf13d699 15553
dda8d76d 15554 if (dump & DEBUG_DUMP)
32ec8896 15555 {
dda8d76d 15556 if (! display_debug_section (i, section, filedata))
32ec8896
NC
15557 res = FALSE;
15558 }
7d9813f1 15559
094e34f2 15560#ifdef ENABLE_LIBCTF
7d9813f1
NA
15561 if (dump & CTF_DUMP)
15562 {
15563 if (! dump_section_as_ctf (section, filedata))
15564 res = FALSE;
15565 }
094e34f2 15566#endif
5b18a4bc 15567 }
103f02d3 15568
835f2fae 15569 if (! filedata->is_separate)
0ee3043f 15570 {
835f2fae
NC
15571 /* Check to see if the user requested a
15572 dump of a section that does not exist. */
15573 for (; i < filedata->dump.num_dump_sects; i++)
15574 if (filedata->dump.dump_sects[i])
15575 {
ca0e11aa 15576 warn (_("Section %d was not dumped because it does not exist!\n"), i);
835f2fae
NC
15577 res = FALSE;
15578 }
0ee3043f 15579 }
32ec8896
NC
15580
15581 return res;
5b18a4bc 15582}
103f02d3 15583
5b18a4bc 15584static void
19e6b90e 15585process_mips_fpe_exception (int mask)
5b18a4bc 15586{
19e6b90e
L
15587 if (mask)
15588 {
32ec8896
NC
15589 bfd_boolean first = TRUE;
15590
19e6b90e 15591 if (mask & OEX_FPU_INEX)
32ec8896 15592 fputs ("INEX", stdout), first = FALSE;
19e6b90e 15593 if (mask & OEX_FPU_UFLO)
32ec8896 15594 printf ("%sUFLO", first ? "" : "|"), first = FALSE;
19e6b90e 15595 if (mask & OEX_FPU_OFLO)
32ec8896 15596 printf ("%sOFLO", first ? "" : "|"), first = FALSE;
19e6b90e 15597 if (mask & OEX_FPU_DIV0)
32ec8896 15598 printf ("%sDIV0", first ? "" : "|"), first = FALSE;
19e6b90e
L
15599 if (mask & OEX_FPU_INVAL)
15600 printf ("%sINVAL", first ? "" : "|");
15601 }
5b18a4bc 15602 else
19e6b90e 15603 fputs ("0", stdout);
5b18a4bc 15604}
103f02d3 15605
f6f0e17b
NC
15606/* Display's the value of TAG at location P. If TAG is
15607 greater than 0 it is assumed to be an unknown tag, and
15608 a message is printed to this effect. Otherwise it is
15609 assumed that a message has already been printed.
15610
15611 If the bottom bit of TAG is set it assumed to have a
15612 string value, otherwise it is assumed to have an integer
15613 value.
15614
15615 Returns an updated P pointing to the first unread byte
15616 beyond the end of TAG's value.
15617
15618 Reads at or beyond END will not be made. */
15619
15620static unsigned char *
60abdbed 15621display_tag_value (signed int tag,
f6f0e17b
NC
15622 unsigned char * p,
15623 const unsigned char * const end)
15624{
15625 unsigned long val;
15626
15627 if (tag > 0)
15628 printf (" Tag_unknown_%d: ", tag);
15629
15630 if (p >= end)
15631 {
4082ef84 15632 warn (_("<corrupt tag>\n"));
f6f0e17b
NC
15633 }
15634 else if (tag & 1)
15635 {
071436c6
NC
15636 /* PR 17531 file: 027-19978-0.004. */
15637 size_t maxlen = (end - p) - 1;
15638
15639 putchar ('"');
4082ef84
NC
15640 if (maxlen > 0)
15641 {
15642 print_symbol ((int) maxlen, (const char *) p);
15643 p += strnlen ((char *) p, maxlen) + 1;
15644 }
15645 else
15646 {
15647 printf (_("<corrupt string tag>"));
15648 p = (unsigned char *) end;
15649 }
071436c6 15650 printf ("\"\n");
f6f0e17b
NC
15651 }
15652 else
15653 {
cd30bcef 15654 READ_ULEB (val, p, end);
f6f0e17b
NC
15655 printf ("%ld (0x%lx)\n", val, val);
15656 }
15657
4082ef84 15658 assert (p <= end);
f6f0e17b
NC
15659 return p;
15660}
15661
53a346d8
CZ
15662/* ARC ABI attributes section. */
15663
15664static unsigned char *
15665display_arc_attribute (unsigned char * p,
15666 const unsigned char * const end)
15667{
15668 unsigned int tag;
53a346d8
CZ
15669 unsigned int val;
15670
cd30bcef 15671 READ_ULEB (tag, p, end);
53a346d8
CZ
15672
15673 switch (tag)
15674 {
15675 case Tag_ARC_PCS_config:
cd30bcef 15676 READ_ULEB (val, p, end);
53a346d8
CZ
15677 printf (" Tag_ARC_PCS_config: ");
15678 switch (val)
15679 {
15680 case 0:
15681 printf (_("Absent/Non standard\n"));
15682 break;
15683 case 1:
15684 printf (_("Bare metal/mwdt\n"));
15685 break;
15686 case 2:
15687 printf (_("Bare metal/newlib\n"));
15688 break;
15689 case 3:
15690 printf (_("Linux/uclibc\n"));
15691 break;
15692 case 4:
15693 printf (_("Linux/glibc\n"));
15694 break;
15695 default:
15696 printf (_("Unknown\n"));
15697 break;
15698 }
15699 break;
15700
15701 case Tag_ARC_CPU_base:
cd30bcef 15702 READ_ULEB (val, p, end);
53a346d8
CZ
15703 printf (" Tag_ARC_CPU_base: ");
15704 switch (val)
15705 {
15706 default:
15707 case TAG_CPU_NONE:
15708 printf (_("Absent\n"));
15709 break;
15710 case TAG_CPU_ARC6xx:
15711 printf ("ARC6xx\n");
15712 break;
15713 case TAG_CPU_ARC7xx:
15714 printf ("ARC7xx\n");
15715 break;
15716 case TAG_CPU_ARCEM:
15717 printf ("ARCEM\n");
15718 break;
15719 case TAG_CPU_ARCHS:
15720 printf ("ARCHS\n");
15721 break;
15722 }
15723 break;
15724
15725 case Tag_ARC_CPU_variation:
cd30bcef 15726 READ_ULEB (val, p, end);
53a346d8
CZ
15727 printf (" Tag_ARC_CPU_variation: ");
15728 switch (val)
15729 {
15730 default:
15731 if (val > 0 && val < 16)
53a346d8 15732 printf ("Core%d\n", val);
d8cbc93b
JL
15733 else
15734 printf ("Unknown\n");
15735 break;
15736
53a346d8
CZ
15737 case 0:
15738 printf (_("Absent\n"));
15739 break;
15740 }
15741 break;
15742
15743 case Tag_ARC_CPU_name:
15744 printf (" Tag_ARC_CPU_name: ");
15745 p = display_tag_value (-1, p, end);
15746 break;
15747
15748 case Tag_ARC_ABI_rf16:
cd30bcef 15749 READ_ULEB (val, p, end);
53a346d8
CZ
15750 printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
15751 break;
15752
15753 case Tag_ARC_ABI_osver:
cd30bcef 15754 READ_ULEB (val, p, end);
53a346d8
CZ
15755 printf (" Tag_ARC_ABI_osver: v%d\n", val);
15756 break;
15757
15758 case Tag_ARC_ABI_pic:
15759 case Tag_ARC_ABI_sda:
cd30bcef 15760 READ_ULEB (val, p, end);
53a346d8
CZ
15761 printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
15762 : " Tag_ARC_ABI_pic: ");
15763 switch (val)
15764 {
15765 case 0:
15766 printf (_("Absent\n"));
15767 break;
15768 case 1:
15769 printf ("MWDT\n");
15770 break;
15771 case 2:
15772 printf ("GNU\n");
15773 break;
15774 default:
15775 printf (_("Unknown\n"));
15776 break;
15777 }
15778 break;
15779
15780 case Tag_ARC_ABI_tls:
cd30bcef 15781 READ_ULEB (val, p, end);
53a346d8
CZ
15782 printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
15783 break;
15784
15785 case Tag_ARC_ABI_enumsize:
cd30bcef 15786 READ_ULEB (val, p, end);
53a346d8
CZ
15787 printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
15788 _("smallest"));
15789 break;
15790
15791 case Tag_ARC_ABI_exceptions:
cd30bcef 15792 READ_ULEB (val, p, end);
53a346d8
CZ
15793 printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
15794 : _("default"));
15795 break;
15796
15797 case Tag_ARC_ABI_double_size:
cd30bcef 15798 READ_ULEB (val, p, end);
53a346d8
CZ
15799 printf (" Tag_ARC_ABI_double_size: %d\n", val);
15800 break;
15801
15802 case Tag_ARC_ISA_config:
15803 printf (" Tag_ARC_ISA_config: ");
15804 p = display_tag_value (-1, p, end);
15805 break;
15806
15807 case Tag_ARC_ISA_apex:
15808 printf (" Tag_ARC_ISA_apex: ");
15809 p = display_tag_value (-1, p, end);
15810 break;
15811
15812 case Tag_ARC_ISA_mpy_option:
cd30bcef 15813 READ_ULEB (val, p, end);
53a346d8
CZ
15814 printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
15815 break;
15816
db1e1b45 15817 case Tag_ARC_ATR_version:
cd30bcef 15818 READ_ULEB (val, p, end);
db1e1b45 15819 printf (" Tag_ARC_ATR_version: %d\n", val);
15820 break;
15821
53a346d8
CZ
15822 default:
15823 return display_tag_value (tag & 1, p, end);
15824 }
15825
15826 return p;
15827}
15828
11c1ff18
PB
15829/* ARM EABI attributes section. */
15830typedef struct
15831{
70e99720 15832 unsigned int tag;
2cf0635d 15833 const char * name;
11c1ff18 15834 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
70e99720 15835 unsigned int type;
288f0ba2 15836 const char *const *table;
11c1ff18
PB
15837} arm_attr_public_tag;
15838
288f0ba2 15839static const char *const arm_attr_tag_CPU_arch[] =
11c1ff18 15840 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
ced40572 15841 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
031254f2 15842 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
288f0ba2
AM
15843static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
15844static const char *const arm_attr_tag_THUMB_ISA_use[] =
4ed7ed8d 15845 {"No", "Thumb-1", "Thumb-2", "Yes"};
288f0ba2 15846static const char *const arm_attr_tag_FP_arch[] =
bca38921 15847 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
a715796b 15848 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
288f0ba2
AM
15849static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
15850static const char *const arm_attr_tag_Advanced_SIMD_arch[] =
9411fd44
MW
15851 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
15852 "NEON for ARMv8.1"};
288f0ba2 15853static const char *const arm_attr_tag_PCS_config[] =
11c1ff18
PB
15854 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
15855 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
288f0ba2 15856static const char *const arm_attr_tag_ABI_PCS_R9_use[] =
11c1ff18 15857 {"V6", "SB", "TLS", "Unused"};
288f0ba2 15858static const char *const arm_attr_tag_ABI_PCS_RW_data[] =
11c1ff18 15859 {"Absolute", "PC-relative", "SB-relative", "None"};
288f0ba2 15860static const char *const arm_attr_tag_ABI_PCS_RO_data[] =
11c1ff18 15861 {"Absolute", "PC-relative", "None"};
288f0ba2 15862static const char *const arm_attr_tag_ABI_PCS_GOT_use[] =
11c1ff18 15863 {"None", "direct", "GOT-indirect"};
288f0ba2 15864static const char *const arm_attr_tag_ABI_PCS_wchar_t[] =
11c1ff18 15865 {"None", "??? 1", "2", "??? 3", "4"};
288f0ba2
AM
15866static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
15867static const char *const arm_attr_tag_ABI_FP_denormal[] =
f5f53991 15868 {"Unused", "Needed", "Sign only"};
288f0ba2
AM
15869static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
15870static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
15871static const char *const arm_attr_tag_ABI_FP_number_model[] =
11c1ff18 15872 {"Unused", "Finite", "RTABI", "IEEE 754"};
288f0ba2 15873static const char *const arm_attr_tag_ABI_enum_size[] =
11c1ff18 15874 {"Unused", "small", "int", "forced to int"};
288f0ba2 15875static const char *const arm_attr_tag_ABI_HardFP_use[] =
99654aaf 15876 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
288f0ba2 15877static const char *const arm_attr_tag_ABI_VFP_args[] =
5c294fee 15878 {"AAPCS", "VFP registers", "custom", "compatible"};
288f0ba2 15879static const char *const arm_attr_tag_ABI_WMMX_args[] =
11c1ff18 15880 {"AAPCS", "WMMX registers", "custom"};
288f0ba2 15881static const char *const arm_attr_tag_ABI_optimization_goals[] =
11c1ff18
PB
15882 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15883 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
288f0ba2 15884static const char *const arm_attr_tag_ABI_FP_optimization_goals[] =
11c1ff18
PB
15885 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15886 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
288f0ba2
AM
15887static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
15888static const char *const arm_attr_tag_FP_HP_extension[] =
8e79c3df 15889 {"Not Allowed", "Allowed"};
288f0ba2 15890static const char *const arm_attr_tag_ABI_FP_16bit_format[] =
8e79c3df 15891 {"None", "IEEE 754", "Alternative Format"};
288f0ba2 15892static const char *const arm_attr_tag_DSP_extension[] =
15afaa63 15893 {"Follow architecture", "Allowed"};
288f0ba2 15894static const char *const arm_attr_tag_MPextension_use[] =
cd21e546 15895 {"Not Allowed", "Allowed"};
288f0ba2 15896static const char *const arm_attr_tag_DIV_use[] =
dd24e3da 15897 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
cd21e546 15898 "Allowed in v7-A with integer division extension"};
288f0ba2
AM
15899static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
15900static const char *const arm_attr_tag_Virtualization_use[] =
dd24e3da 15901 {"Not Allowed", "TrustZone", "Virtualization Extensions",
cd21e546 15902 "TrustZone and Virtualization Extensions"};
288f0ba2 15903static const char *const arm_attr_tag_MPextension_use_legacy[] =
f5f53991 15904 {"Not Allowed", "Allowed"};
11c1ff18 15905
288f0ba2 15906static const char *const arm_attr_tag_MVE_arch[] =
a7ad558c
AV
15907 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
15908
11c1ff18
PB
15909#define LOOKUP(id, name) \
15910 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
d70c5fc7 15911static arm_attr_public_tag arm_attr_public_tags[] =
11c1ff18
PB
15912{
15913 {4, "CPU_raw_name", 1, NULL},
15914 {5, "CPU_name", 1, NULL},
15915 LOOKUP(6, CPU_arch),
15916 {7, "CPU_arch_profile", 0, NULL},
15917 LOOKUP(8, ARM_ISA_use),
15918 LOOKUP(9, THUMB_ISA_use),
75375b3e 15919 LOOKUP(10, FP_arch),
11c1ff18 15920 LOOKUP(11, WMMX_arch),
f5f53991
AS
15921 LOOKUP(12, Advanced_SIMD_arch),
15922 LOOKUP(13, PCS_config),
11c1ff18
PB
15923 LOOKUP(14, ABI_PCS_R9_use),
15924 LOOKUP(15, ABI_PCS_RW_data),
f5f53991 15925 LOOKUP(16, ABI_PCS_RO_data),
11c1ff18
PB
15926 LOOKUP(17, ABI_PCS_GOT_use),
15927 LOOKUP(18, ABI_PCS_wchar_t),
15928 LOOKUP(19, ABI_FP_rounding),
15929 LOOKUP(20, ABI_FP_denormal),
15930 LOOKUP(21, ABI_FP_exceptions),
15931 LOOKUP(22, ABI_FP_user_exceptions),
15932 LOOKUP(23, ABI_FP_number_model),
75375b3e
MGD
15933 {24, "ABI_align_needed", 0, NULL},
15934 {25, "ABI_align_preserved", 0, NULL},
11c1ff18
PB
15935 LOOKUP(26, ABI_enum_size),
15936 LOOKUP(27, ABI_HardFP_use),
15937 LOOKUP(28, ABI_VFP_args),
15938 LOOKUP(29, ABI_WMMX_args),
15939 LOOKUP(30, ABI_optimization_goals),
15940 LOOKUP(31, ABI_FP_optimization_goals),
8e79c3df 15941 {32, "compatibility", 0, NULL},
f5f53991 15942 LOOKUP(34, CPU_unaligned_access),
75375b3e 15943 LOOKUP(36, FP_HP_extension),
8e79c3df 15944 LOOKUP(38, ABI_FP_16bit_format),
cd21e546
MGD
15945 LOOKUP(42, MPextension_use),
15946 LOOKUP(44, DIV_use),
15afaa63 15947 LOOKUP(46, DSP_extension),
a7ad558c 15948 LOOKUP(48, MVE_arch),
f5f53991
AS
15949 {64, "nodefaults", 0, NULL},
15950 {65, "also_compatible_with", 0, NULL},
15951 LOOKUP(66, T2EE_use),
15952 {67, "conformance", 1, NULL},
15953 LOOKUP(68, Virtualization_use),
cd21e546 15954 LOOKUP(70, MPextension_use_legacy)
11c1ff18
PB
15955};
15956#undef LOOKUP
15957
11c1ff18 15958static unsigned char *
f6f0e17b
NC
15959display_arm_attribute (unsigned char * p,
15960 const unsigned char * const end)
11c1ff18 15961{
70e99720 15962 unsigned int tag;
70e99720 15963 unsigned int val;
2cf0635d 15964 arm_attr_public_tag * attr;
11c1ff18 15965 unsigned i;
70e99720 15966 unsigned int type;
11c1ff18 15967
cd30bcef 15968 READ_ULEB (tag, p, end);
11c1ff18 15969 attr = NULL;
2cf0635d 15970 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
11c1ff18
PB
15971 {
15972 if (arm_attr_public_tags[i].tag == tag)
15973 {
15974 attr = &arm_attr_public_tags[i];
15975 break;
15976 }
15977 }
15978
15979 if (attr)
15980 {
15981 printf (" Tag_%s: ", attr->name);
15982 switch (attr->type)
15983 {
15984 case 0:
15985 switch (tag)
15986 {
15987 case 7: /* Tag_CPU_arch_profile. */
cd30bcef 15988 READ_ULEB (val, p, end);
11c1ff18
PB
15989 switch (val)
15990 {
2b692964
NC
15991 case 0: printf (_("None\n")); break;
15992 case 'A': printf (_("Application\n")); break;
15993 case 'R': printf (_("Realtime\n")); break;
15994 case 'M': printf (_("Microcontroller\n")); break;
15995 case 'S': printf (_("Application or Realtime\n")); break;
11c1ff18
PB
15996 default: printf ("??? (%d)\n", val); break;
15997 }
15998 break;
15999
75375b3e 16000 case 24: /* Tag_align_needed. */
cd30bcef 16001 READ_ULEB (val, p, end);
75375b3e
MGD
16002 switch (val)
16003 {
2b692964
NC
16004 case 0: printf (_("None\n")); break;
16005 case 1: printf (_("8-byte\n")); break;
16006 case 2: printf (_("4-byte\n")); break;
75375b3e
MGD
16007 case 3: printf ("??? 3\n"); break;
16008 default:
16009 if (val <= 12)
dd24e3da 16010 printf (_("8-byte and up to %d-byte extended\n"),
75375b3e
MGD
16011 1 << val);
16012 else
16013 printf ("??? (%d)\n", val);
16014 break;
16015 }
16016 break;
16017
16018 case 25: /* Tag_align_preserved. */
cd30bcef 16019 READ_ULEB (val, p, end);
75375b3e
MGD
16020 switch (val)
16021 {
2b692964
NC
16022 case 0: printf (_("None\n")); break;
16023 case 1: printf (_("8-byte, except leaf SP\n")); break;
16024 case 2: printf (_("8-byte\n")); break;
75375b3e
MGD
16025 case 3: printf ("??? 3\n"); break;
16026 default:
16027 if (val <= 12)
dd24e3da 16028 printf (_("8-byte and up to %d-byte extended\n"),
75375b3e
MGD
16029 1 << val);
16030 else
16031 printf ("??? (%d)\n", val);
16032 break;
16033 }
16034 break;
16035
11c1ff18 16036 case 32: /* Tag_compatibility. */
071436c6 16037 {
cd30bcef 16038 READ_ULEB (val, p, end);
071436c6 16039 printf (_("flag = %d, vendor = "), val);
4082ef84
NC
16040 if (p < end - 1)
16041 {
16042 size_t maxlen = (end - p) - 1;
16043
16044 print_symbol ((int) maxlen, (const char *) p);
16045 p += strnlen ((char *) p, maxlen) + 1;
16046 }
16047 else
16048 {
16049 printf (_("<corrupt>"));
16050 p = (unsigned char *) end;
16051 }
071436c6 16052 putchar ('\n');
071436c6 16053 }
11c1ff18
PB
16054 break;
16055
f5f53991 16056 case 64: /* Tag_nodefaults. */
541a3cbd
NC
16057 /* PR 17531: file: 001-505008-0.01. */
16058 if (p < end)
16059 p++;
2b692964 16060 printf (_("True\n"));
f5f53991
AS
16061 break;
16062
16063 case 65: /* Tag_also_compatible_with. */
cd30bcef 16064 READ_ULEB (val, p, end);
f5f53991
AS
16065 if (val == 6 /* Tag_CPU_arch. */)
16066 {
cd30bcef 16067 READ_ULEB (val, p, end);
071436c6 16068 if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
f5f53991
AS
16069 printf ("??? (%d)\n", val);
16070 else
16071 printf ("%s\n", arm_attr_tag_CPU_arch[val]);
16072 }
16073 else
16074 printf ("???\n");
071436c6
NC
16075 while (p < end && *(p++) != '\0' /* NUL terminator. */)
16076 ;
f5f53991
AS
16077 break;
16078
11c1ff18 16079 default:
bee0ee85
NC
16080 printf (_("<unknown: %d>\n"), tag);
16081 break;
11c1ff18
PB
16082 }
16083 return p;
16084
16085 case 1:
f6f0e17b 16086 return display_tag_value (-1, p, end);
11c1ff18 16087 case 2:
f6f0e17b 16088 return display_tag_value (0, p, end);
11c1ff18
PB
16089
16090 default:
16091 assert (attr->type & 0x80);
cd30bcef 16092 READ_ULEB (val, p, end);
11c1ff18
PB
16093 type = attr->type & 0x7f;
16094 if (val >= type)
16095 printf ("??? (%d)\n", val);
16096 else
16097 printf ("%s\n", attr->table[val]);
16098 return p;
16099 }
16100 }
11c1ff18 16101
f6f0e17b 16102 return display_tag_value (tag, p, end);
11c1ff18
PB
16103}
16104
104d59d1 16105static unsigned char *
60bca95a 16106display_gnu_attribute (unsigned char * p,
60abdbed 16107 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
f6f0e17b 16108 const unsigned char * const end)
104d59d1 16109{
cd30bcef 16110 unsigned int tag;
60abdbed 16111 unsigned int val;
104d59d1 16112
cd30bcef 16113 READ_ULEB (tag, p, end);
104d59d1
JM
16114
16115 /* Tag_compatibility is the only generic GNU attribute defined at
16116 present. */
16117 if (tag == 32)
16118 {
cd30bcef 16119 READ_ULEB (val, p, end);
071436c6
NC
16120
16121 printf (_("flag = %d, vendor = "), val);
f6f0e17b
NC
16122 if (p == end)
16123 {
071436c6 16124 printf (_("<corrupt>\n"));
f6f0e17b
NC
16125 warn (_("corrupt vendor attribute\n"));
16126 }
16127 else
16128 {
4082ef84
NC
16129 if (p < end - 1)
16130 {
16131 size_t maxlen = (end - p) - 1;
071436c6 16132
4082ef84
NC
16133 print_symbol ((int) maxlen, (const char *) p);
16134 p += strnlen ((char *) p, maxlen) + 1;
16135 }
16136 else
16137 {
16138 printf (_("<corrupt>"));
16139 p = (unsigned char *) end;
16140 }
071436c6 16141 putchar ('\n');
f6f0e17b 16142 }
104d59d1
JM
16143 return p;
16144 }
16145
16146 if ((tag & 2) == 0 && display_proc_gnu_attribute)
f6f0e17b 16147 return display_proc_gnu_attribute (p, tag, end);
104d59d1 16148
f6f0e17b 16149 return display_tag_value (tag, p, end);
104d59d1
JM
16150}
16151
85f7484a
PB
16152static unsigned char *
16153display_m68k_gnu_attribute (unsigned char * p,
16154 unsigned int tag,
16155 const unsigned char * const end)
16156{
16157 unsigned int val;
16158
16159 if (tag == Tag_GNU_M68K_ABI_FP)
16160 {
16161 printf (" Tag_GNU_M68K_ABI_FP: ");
16162 if (p == end)
16163 {
16164 printf (_("<corrupt>\n"));
16165 return p;
16166 }
16167 READ_ULEB (val, p, end);
16168
16169 if (val > 3)
16170 printf ("(%#x), ", val);
16171
16172 switch (val & 3)
16173 {
16174 case 0:
16175 printf (_("unspecified hard/soft float\n"));
16176 break;
16177 case 1:
16178 printf (_("hard float\n"));
16179 break;
16180 case 2:
16181 printf (_("soft float\n"));
16182 break;
16183 }
16184 return p;
16185 }
16186
16187 return display_tag_value (tag & 1, p, end);
16188}
16189
34c8bcba 16190static unsigned char *
f6f0e17b 16191display_power_gnu_attribute (unsigned char * p,
60abdbed 16192 unsigned int tag,
f6f0e17b 16193 const unsigned char * const end)
34c8bcba 16194{
005d79fd 16195 unsigned int val;
34c8bcba
JM
16196
16197 if (tag == Tag_GNU_Power_ABI_FP)
16198 {
34c8bcba 16199 printf (" Tag_GNU_Power_ABI_FP: ");
cd30bcef 16200 if (p == end)
005d79fd
AM
16201 {
16202 printf (_("<corrupt>\n"));
16203 return p;
16204 }
cd30bcef 16205 READ_ULEB (val, p, end);
60bca95a 16206
005d79fd
AM
16207 if (val > 15)
16208 printf ("(%#x), ", val);
16209
16210 switch (val & 3)
34c8bcba
JM
16211 {
16212 case 0:
005d79fd 16213 printf (_("unspecified hard/soft float, "));
34c8bcba
JM
16214 break;
16215 case 1:
005d79fd 16216 printf (_("hard float, "));
34c8bcba
JM
16217 break;
16218 case 2:
005d79fd 16219 printf (_("soft float, "));
34c8bcba 16220 break;
3c7b9897 16221 case 3:
005d79fd 16222 printf (_("single-precision hard float, "));
3c7b9897 16223 break;
005d79fd
AM
16224 }
16225
16226 switch (val & 0xC)
16227 {
16228 case 0:
16229 printf (_("unspecified long double\n"));
16230 break;
16231 case 4:
16232 printf (_("128-bit IBM long double\n"));
16233 break;
16234 case 8:
16235 printf (_("64-bit long double\n"));
16236 break;
16237 case 12:
16238 printf (_("128-bit IEEE long double\n"));
34c8bcba
JM
16239 break;
16240 }
16241 return p;
005d79fd 16242 }
34c8bcba 16243
c6e65352
DJ
16244 if (tag == Tag_GNU_Power_ABI_Vector)
16245 {
c6e65352 16246 printf (" Tag_GNU_Power_ABI_Vector: ");
cd30bcef 16247 if (p == end)
005d79fd
AM
16248 {
16249 printf (_("<corrupt>\n"));
16250 return p;
16251 }
cd30bcef 16252 READ_ULEB (val, p, end);
005d79fd
AM
16253
16254 if (val > 3)
16255 printf ("(%#x), ", val);
16256
16257 switch (val & 3)
c6e65352
DJ
16258 {
16259 case 0:
005d79fd 16260 printf (_("unspecified\n"));
c6e65352
DJ
16261 break;
16262 case 1:
005d79fd 16263 printf (_("generic\n"));
c6e65352
DJ
16264 break;
16265 case 2:
16266 printf ("AltiVec\n");
16267 break;
16268 case 3:
16269 printf ("SPE\n");
16270 break;
c6e65352
DJ
16271 }
16272 return p;
005d79fd 16273 }
c6e65352 16274
f82e0623
NF
16275 if (tag == Tag_GNU_Power_ABI_Struct_Return)
16276 {
005d79fd 16277 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
cd30bcef 16278 if (p == end)
f6f0e17b 16279 {
005d79fd 16280 printf (_("<corrupt>\n"));
f6f0e17b
NC
16281 return p;
16282 }
cd30bcef 16283 READ_ULEB (val, p, end);
0b4362b0 16284
005d79fd
AM
16285 if (val > 2)
16286 printf ("(%#x), ", val);
16287
16288 switch (val & 3)
16289 {
16290 case 0:
16291 printf (_("unspecified\n"));
16292 break;
16293 case 1:
16294 printf ("r3/r4\n");
16295 break;
16296 case 2:
16297 printf (_("memory\n"));
16298 break;
16299 case 3:
16300 printf ("???\n");
16301 break;
16302 }
f82e0623
NF
16303 return p;
16304 }
16305
f6f0e17b 16306 return display_tag_value (tag & 1, p, end);
34c8bcba
JM
16307}
16308
643f7afb
AK
16309static unsigned char *
16310display_s390_gnu_attribute (unsigned char * p,
60abdbed 16311 unsigned int tag,
643f7afb
AK
16312 const unsigned char * const end)
16313{
cd30bcef 16314 unsigned int val;
643f7afb
AK
16315
16316 if (tag == Tag_GNU_S390_ABI_Vector)
16317 {
643f7afb 16318 printf (" Tag_GNU_S390_ABI_Vector: ");
cd30bcef 16319 READ_ULEB (val, p, end);
643f7afb
AK
16320
16321 switch (val)
16322 {
16323 case 0:
16324 printf (_("any\n"));
16325 break;
16326 case 1:
16327 printf (_("software\n"));
16328 break;
16329 case 2:
16330 printf (_("hardware\n"));
16331 break;
16332 default:
16333 printf ("??? (%d)\n", val);
16334 break;
16335 }
16336 return p;
16337 }
16338
16339 return display_tag_value (tag & 1, p, end);
16340}
16341
9e8c70f9 16342static void
60abdbed 16343display_sparc_hwcaps (unsigned int mask)
9e8c70f9
DM
16344{
16345 if (mask)
16346 {
32ec8896 16347 bfd_boolean first = TRUE;
071436c6 16348
9e8c70f9 16349 if (mask & ELF_SPARC_HWCAP_MUL32)
32ec8896 16350 fputs ("mul32", stdout), first = FALSE;
9e8c70f9 16351 if (mask & ELF_SPARC_HWCAP_DIV32)
32ec8896 16352 printf ("%sdiv32", first ? "" : "|"), first = FALSE;
9e8c70f9 16353 if (mask & ELF_SPARC_HWCAP_FSMULD)
32ec8896 16354 printf ("%sfsmuld", first ? "" : "|"), first = FALSE;
9e8c70f9 16355 if (mask & ELF_SPARC_HWCAP_V8PLUS)
32ec8896 16356 printf ("%sv8plus", first ? "" : "|"), first = FALSE;
9e8c70f9 16357 if (mask & ELF_SPARC_HWCAP_POPC)
32ec8896 16358 printf ("%spopc", first ? "" : "|"), first = FALSE;
9e8c70f9 16359 if (mask & ELF_SPARC_HWCAP_VIS)
32ec8896 16360 printf ("%svis", first ? "" : "|"), first = FALSE;
9e8c70f9 16361 if (mask & ELF_SPARC_HWCAP_VIS2)
32ec8896 16362 printf ("%svis2", first ? "" : "|"), first = FALSE;
9e8c70f9 16363 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
32ec8896 16364 printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE;
9e8c70f9 16365 if (mask & ELF_SPARC_HWCAP_FMAF)
32ec8896 16366 printf ("%sfmaf", first ? "" : "|"), first = FALSE;
9e8c70f9 16367 if (mask & ELF_SPARC_HWCAP_VIS3)
32ec8896 16368 printf ("%svis3", first ? "" : "|"), first = FALSE;
9e8c70f9 16369 if (mask & ELF_SPARC_HWCAP_HPC)
32ec8896 16370 printf ("%shpc", first ? "" : "|"), first = FALSE;
9e8c70f9 16371 if (mask & ELF_SPARC_HWCAP_RANDOM)
32ec8896 16372 printf ("%srandom", first ? "" : "|"), first = FALSE;
9e8c70f9 16373 if (mask & ELF_SPARC_HWCAP_TRANS)
32ec8896 16374 printf ("%strans", first ? "" : "|"), first = FALSE;
9e8c70f9 16375 if (mask & ELF_SPARC_HWCAP_FJFMAU)
32ec8896 16376 printf ("%sfjfmau", first ? "" : "|"), first = FALSE;
9e8c70f9 16377 if (mask & ELF_SPARC_HWCAP_IMA)
32ec8896 16378 printf ("%sima", first ? "" : "|"), first = FALSE;
9e8c70f9 16379 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
32ec8896 16380 printf ("%scspare", first ? "" : "|"), first = FALSE;
9e8c70f9
DM
16381 }
16382 else
071436c6
NC
16383 fputc ('0', stdout);
16384 fputc ('\n', stdout);
9e8c70f9
DM
16385}
16386
3d68f91c 16387static void
60abdbed 16388display_sparc_hwcaps2 (unsigned int mask)
3d68f91c
JM
16389{
16390 if (mask)
16391 {
32ec8896 16392 bfd_boolean first = TRUE;
071436c6 16393
3d68f91c 16394 if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
32ec8896 16395 fputs ("fjathplus", stdout), first = FALSE;
3d68f91c 16396 if (mask & ELF_SPARC_HWCAP2_VIS3B)
32ec8896 16397 printf ("%svis3b", first ? "" : "|"), first = FALSE;
3d68f91c 16398 if (mask & ELF_SPARC_HWCAP2_ADP)
32ec8896 16399 printf ("%sadp", first ? "" : "|"), first = FALSE;
3d68f91c 16400 if (mask & ELF_SPARC_HWCAP2_SPARC5)
32ec8896 16401 printf ("%ssparc5", first ? "" : "|"), first = FALSE;
3d68f91c 16402 if (mask & ELF_SPARC_HWCAP2_MWAIT)
32ec8896 16403 printf ("%smwait", first ? "" : "|"), first = FALSE;
3d68f91c 16404 if (mask & ELF_SPARC_HWCAP2_XMPMUL)
32ec8896 16405 printf ("%sxmpmul", first ? "" : "|"), first = FALSE;
3d68f91c 16406 if (mask & ELF_SPARC_HWCAP2_XMONT)
32ec8896 16407 printf ("%sxmont2", first ? "" : "|"), first = FALSE;
3d68f91c 16408 if (mask & ELF_SPARC_HWCAP2_NSEC)
32ec8896 16409 printf ("%snsec", first ? "" : "|"), first = FALSE;
3d68f91c 16410 if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
32ec8896 16411 printf ("%sfjathhpc", first ? "" : "|"), first = FALSE;
3d68f91c 16412 if (mask & ELF_SPARC_HWCAP2_FJDES)
32ec8896 16413 printf ("%sfjdes", first ? "" : "|"), first = FALSE;
3d68f91c 16414 if (mask & ELF_SPARC_HWCAP2_FJAES)
32ec8896 16415 printf ("%sfjaes", first ? "" : "|"), first = FALSE;
3d68f91c
JM
16416 }
16417 else
071436c6
NC
16418 fputc ('0', stdout);
16419 fputc ('\n', stdout);
3d68f91c
JM
16420}
16421
9e8c70f9 16422static unsigned char *
f6f0e17b 16423display_sparc_gnu_attribute (unsigned char * p,
60abdbed 16424 unsigned int tag,
f6f0e17b 16425 const unsigned char * const end)
9e8c70f9 16426{
cd30bcef 16427 unsigned int val;
3d68f91c 16428
9e8c70f9
DM
16429 if (tag == Tag_GNU_Sparc_HWCAPS)
16430 {
cd30bcef 16431 READ_ULEB (val, p, end);
9e8c70f9 16432 printf (" Tag_GNU_Sparc_HWCAPS: ");
9e8c70f9
DM
16433 display_sparc_hwcaps (val);
16434 return p;
3d68f91c
JM
16435 }
16436 if (tag == Tag_GNU_Sparc_HWCAPS2)
16437 {
cd30bcef 16438 READ_ULEB (val, p, end);
3d68f91c
JM
16439 printf (" Tag_GNU_Sparc_HWCAPS2: ");
16440 display_sparc_hwcaps2 (val);
16441 return p;
16442 }
9e8c70f9 16443
f6f0e17b 16444 return display_tag_value (tag, p, end);
9e8c70f9
DM
16445}
16446
351cdf24 16447static void
32ec8896 16448print_mips_fp_abi_value (unsigned int val)
351cdf24
MF
16449{
16450 switch (val)
16451 {
16452 case Val_GNU_MIPS_ABI_FP_ANY:
16453 printf (_("Hard or soft float\n"));
16454 break;
16455 case Val_GNU_MIPS_ABI_FP_DOUBLE:
16456 printf (_("Hard float (double precision)\n"));
16457 break;
16458 case Val_GNU_MIPS_ABI_FP_SINGLE:
16459 printf (_("Hard float (single precision)\n"));
16460 break;
16461 case Val_GNU_MIPS_ABI_FP_SOFT:
16462 printf (_("Soft float\n"));
16463 break;
16464 case Val_GNU_MIPS_ABI_FP_OLD_64:
16465 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
16466 break;
16467 case Val_GNU_MIPS_ABI_FP_XX:
16468 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
16469 break;
16470 case Val_GNU_MIPS_ABI_FP_64:
16471 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
16472 break;
16473 case Val_GNU_MIPS_ABI_FP_64A:
16474 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
16475 break;
3350cc01
CM
16476 case Val_GNU_MIPS_ABI_FP_NAN2008:
16477 printf (_("NaN 2008 compatibility\n"));
16478 break;
351cdf24
MF
16479 default:
16480 printf ("??? (%d)\n", val);
16481 break;
16482 }
16483}
16484
2cf19d5c 16485static unsigned char *
f6f0e17b 16486display_mips_gnu_attribute (unsigned char * p,
60abdbed 16487 unsigned int tag,
f6f0e17b 16488 const unsigned char * const end)
2cf19d5c 16489{
2cf19d5c
JM
16490 if (tag == Tag_GNU_MIPS_ABI_FP)
16491 {
32ec8896 16492 unsigned int val;
f6f0e17b 16493
2cf19d5c 16494 printf (" Tag_GNU_MIPS_ABI_FP: ");
cd30bcef 16495 READ_ULEB (val, p, end);
351cdf24 16496 print_mips_fp_abi_value (val);
2cf19d5c
JM
16497 return p;
16498 }
16499
a9f58168
CF
16500 if (tag == Tag_GNU_MIPS_ABI_MSA)
16501 {
32ec8896 16502 unsigned int val;
a9f58168 16503
a9f58168 16504 printf (" Tag_GNU_MIPS_ABI_MSA: ");
cd30bcef 16505 READ_ULEB (val, p, end);
a9f58168
CF
16506
16507 switch (val)
16508 {
16509 case Val_GNU_MIPS_ABI_MSA_ANY:
16510 printf (_("Any MSA or not\n"));
16511 break;
16512 case Val_GNU_MIPS_ABI_MSA_128:
16513 printf (_("128-bit MSA\n"));
16514 break;
16515 default:
16516 printf ("??? (%d)\n", val);
16517 break;
16518 }
16519 return p;
16520 }
16521
f6f0e17b 16522 return display_tag_value (tag & 1, p, end);
2cf19d5c
JM
16523}
16524
59e6276b 16525static unsigned char *
f6f0e17b
NC
16526display_tic6x_attribute (unsigned char * p,
16527 const unsigned char * const end)
59e6276b 16528{
60abdbed 16529 unsigned int tag;
cd30bcef 16530 unsigned int val;
59e6276b 16531
cd30bcef 16532 READ_ULEB (tag, p, end);
59e6276b
JM
16533
16534 switch (tag)
16535 {
75fa6dc1 16536 case Tag_ISA:
75fa6dc1 16537 printf (" Tag_ISA: ");
cd30bcef 16538 READ_ULEB (val, p, end);
59e6276b
JM
16539
16540 switch (val)
16541 {
75fa6dc1 16542 case C6XABI_Tag_ISA_none:
59e6276b
JM
16543 printf (_("None\n"));
16544 break;
75fa6dc1 16545 case C6XABI_Tag_ISA_C62X:
59e6276b
JM
16546 printf ("C62x\n");
16547 break;
75fa6dc1 16548 case C6XABI_Tag_ISA_C67X:
59e6276b
JM
16549 printf ("C67x\n");
16550 break;
75fa6dc1 16551 case C6XABI_Tag_ISA_C67XP:
59e6276b
JM
16552 printf ("C67x+\n");
16553 break;
75fa6dc1 16554 case C6XABI_Tag_ISA_C64X:
59e6276b
JM
16555 printf ("C64x\n");
16556 break;
75fa6dc1 16557 case C6XABI_Tag_ISA_C64XP:
59e6276b
JM
16558 printf ("C64x+\n");
16559 break;
75fa6dc1 16560 case C6XABI_Tag_ISA_C674X:
59e6276b
JM
16561 printf ("C674x\n");
16562 break;
16563 default:
16564 printf ("??? (%d)\n", val);
16565 break;
16566 }
16567 return p;
16568
87779176 16569 case Tag_ABI_wchar_t:
87779176 16570 printf (" Tag_ABI_wchar_t: ");
cd30bcef 16571 READ_ULEB (val, p, end);
87779176
JM
16572 switch (val)
16573 {
16574 case 0:
16575 printf (_("Not used\n"));
16576 break;
16577 case 1:
16578 printf (_("2 bytes\n"));
16579 break;
16580 case 2:
16581 printf (_("4 bytes\n"));
16582 break;
16583 default:
16584 printf ("??? (%d)\n", val);
16585 break;
16586 }
16587 return p;
16588
16589 case Tag_ABI_stack_align_needed:
87779176 16590 printf (" Tag_ABI_stack_align_needed: ");
cd30bcef 16591 READ_ULEB (val, p, end);
87779176
JM
16592 switch (val)
16593 {
16594 case 0:
16595 printf (_("8-byte\n"));
16596 break;
16597 case 1:
16598 printf (_("16-byte\n"));
16599 break;
16600 default:
16601 printf ("??? (%d)\n", val);
16602 break;
16603 }
16604 return p;
16605
16606 case Tag_ABI_stack_align_preserved:
cd30bcef 16607 READ_ULEB (val, p, end);
87779176
JM
16608 printf (" Tag_ABI_stack_align_preserved: ");
16609 switch (val)
16610 {
16611 case 0:
16612 printf (_("8-byte\n"));
16613 break;
16614 case 1:
16615 printf (_("16-byte\n"));
16616 break;
16617 default:
16618 printf ("??? (%d)\n", val);
16619 break;
16620 }
16621 return p;
16622
b5593623 16623 case Tag_ABI_DSBT:
cd30bcef 16624 READ_ULEB (val, p, end);
b5593623
JM
16625 printf (" Tag_ABI_DSBT: ");
16626 switch (val)
16627 {
16628 case 0:
16629 printf (_("DSBT addressing not used\n"));
16630 break;
16631 case 1:
16632 printf (_("DSBT addressing used\n"));
16633 break;
16634 default:
16635 printf ("??? (%d)\n", val);
16636 break;
16637 }
16638 return p;
16639
87779176 16640 case Tag_ABI_PID:
cd30bcef 16641 READ_ULEB (val, p, end);
87779176
JM
16642 printf (" Tag_ABI_PID: ");
16643 switch (val)
16644 {
16645 case 0:
16646 printf (_("Data addressing position-dependent\n"));
16647 break;
16648 case 1:
16649 printf (_("Data addressing position-independent, GOT near DP\n"));
16650 break;
16651 case 2:
16652 printf (_("Data addressing position-independent, GOT far from DP\n"));
16653 break;
16654 default:
16655 printf ("??? (%d)\n", val);
16656 break;
16657 }
16658 return p;
16659
16660 case Tag_ABI_PIC:
cd30bcef 16661 READ_ULEB (val, p, end);
87779176
JM
16662 printf (" Tag_ABI_PIC: ");
16663 switch (val)
16664 {
16665 case 0:
16666 printf (_("Code addressing position-dependent\n"));
16667 break;
16668 case 1:
16669 printf (_("Code addressing position-independent\n"));
16670 break;
16671 default:
16672 printf ("??? (%d)\n", val);
16673 break;
16674 }
16675 return p;
16676
16677 case Tag_ABI_array_object_alignment:
cd30bcef 16678 READ_ULEB (val, p, end);
87779176
JM
16679 printf (" Tag_ABI_array_object_alignment: ");
16680 switch (val)
16681 {
16682 case 0:
16683 printf (_("8-byte\n"));
16684 break;
16685 case 1:
16686 printf (_("4-byte\n"));
16687 break;
16688 case 2:
16689 printf (_("16-byte\n"));
16690 break;
16691 default:
16692 printf ("??? (%d)\n", val);
16693 break;
16694 }
16695 return p;
16696
16697 case Tag_ABI_array_object_align_expected:
cd30bcef 16698 READ_ULEB (val, p, end);
87779176
JM
16699 printf (" Tag_ABI_array_object_align_expected: ");
16700 switch (val)
16701 {
16702 case 0:
16703 printf (_("8-byte\n"));
16704 break;
16705 case 1:
16706 printf (_("4-byte\n"));
16707 break;
16708 case 2:
16709 printf (_("16-byte\n"));
16710 break;
16711 default:
16712 printf ("??? (%d)\n", val);
16713 break;
16714 }
16715 return p;
16716
3cbd1c06 16717 case Tag_ABI_compatibility:
071436c6 16718 {
cd30bcef 16719 READ_ULEB (val, p, end);
071436c6 16720 printf (" Tag_ABI_compatibility: ");
071436c6 16721 printf (_("flag = %d, vendor = "), val);
4082ef84
NC
16722 if (p < end - 1)
16723 {
16724 size_t maxlen = (end - p) - 1;
16725
16726 print_symbol ((int) maxlen, (const char *) p);
16727 p += strnlen ((char *) p, maxlen) + 1;
16728 }
16729 else
16730 {
16731 printf (_("<corrupt>"));
16732 p = (unsigned char *) end;
16733 }
071436c6 16734 putchar ('\n');
071436c6
NC
16735 return p;
16736 }
87779176
JM
16737
16738 case Tag_ABI_conformance:
071436c6 16739 {
4082ef84
NC
16740 printf (" Tag_ABI_conformance: \"");
16741 if (p < end - 1)
16742 {
16743 size_t maxlen = (end - p) - 1;
071436c6 16744
4082ef84
NC
16745 print_symbol ((int) maxlen, (const char *) p);
16746 p += strnlen ((char *) p, maxlen) + 1;
16747 }
16748 else
16749 {
16750 printf (_("<corrupt>"));
16751 p = (unsigned char *) end;
16752 }
071436c6 16753 printf ("\"\n");
071436c6
NC
16754 return p;
16755 }
59e6276b
JM
16756 }
16757
f6f0e17b
NC
16758 return display_tag_value (tag, p, end);
16759}
59e6276b 16760
f6f0e17b 16761static void
60abdbed 16762display_raw_attribute (unsigned char * p, unsigned char const * const end)
f6f0e17b
NC
16763{
16764 unsigned long addr = 0;
16765 size_t bytes = end - p;
16766
feceaa59 16767 assert (end >= p);
f6f0e17b 16768 while (bytes)
87779176 16769 {
f6f0e17b
NC
16770 int j;
16771 int k;
16772 int lbytes = (bytes > 16 ? 16 : bytes);
16773
16774 printf (" 0x%8.8lx ", addr);
16775
16776 for (j = 0; j < 16; j++)
16777 {
16778 if (j < lbytes)
16779 printf ("%2.2x", p[j]);
16780 else
16781 printf (" ");
16782
16783 if ((j & 3) == 3)
16784 printf (" ");
16785 }
16786
16787 for (j = 0; j < lbytes; j++)
16788 {
16789 k = p[j];
16790 if (k >= ' ' && k < 0x7f)
16791 printf ("%c", k);
16792 else
16793 printf (".");
16794 }
16795
16796 putchar ('\n');
16797
16798 p += lbytes;
16799 bytes -= lbytes;
16800 addr += lbytes;
87779176 16801 }
59e6276b 16802
f6f0e17b 16803 putchar ('\n');
59e6276b
JM
16804}
16805
13761a11 16806static unsigned char *
b0191216 16807display_msp430_attribute (unsigned char * p,
13761a11
NC
16808 const unsigned char * const end)
16809{
60abdbed
NC
16810 unsigned int val;
16811 unsigned int tag;
13761a11 16812
cd30bcef 16813 READ_ULEB (tag, p, end);
0b4362b0 16814
13761a11
NC
16815 switch (tag)
16816 {
16817 case OFBA_MSPABI_Tag_ISA:
13761a11 16818 printf (" Tag_ISA: ");
cd30bcef 16819 READ_ULEB (val, p, end);
13761a11
NC
16820 switch (val)
16821 {
16822 case 0: printf (_("None\n")); break;
16823 case 1: printf (_("MSP430\n")); break;
16824 case 2: printf (_("MSP430X\n")); break;
16825 default: printf ("??? (%d)\n", val); break;
16826 }
16827 break;
16828
16829 case OFBA_MSPABI_Tag_Code_Model:
13761a11 16830 printf (" Tag_Code_Model: ");
cd30bcef 16831 READ_ULEB (val, p, end);
13761a11
NC
16832 switch (val)
16833 {
16834 case 0: printf (_("None\n")); break;
16835 case 1: printf (_("Small\n")); break;
16836 case 2: printf (_("Large\n")); break;
16837 default: printf ("??? (%d)\n", val); break;
16838 }
16839 break;
16840
16841 case OFBA_MSPABI_Tag_Data_Model:
13761a11 16842 printf (" Tag_Data_Model: ");
cd30bcef 16843 READ_ULEB (val, p, end);
13761a11
NC
16844 switch (val)
16845 {
16846 case 0: printf (_("None\n")); break;
16847 case 1: printf (_("Small\n")); break;
16848 case 2: printf (_("Large\n")); break;
16849 case 3: printf (_("Restricted Large\n")); break;
16850 default: printf ("??? (%d)\n", val); break;
16851 }
16852 break;
16853
16854 default:
16855 printf (_(" <unknown tag %d>: "), tag);
16856
16857 if (tag & 1)
16858 {
071436c6 16859 putchar ('"');
4082ef84
NC
16860 if (p < end - 1)
16861 {
16862 size_t maxlen = (end - p) - 1;
16863
16864 print_symbol ((int) maxlen, (const char *) p);
16865 p += strnlen ((char *) p, maxlen) + 1;
16866 }
16867 else
16868 {
16869 printf (_("<corrupt>"));
16870 p = (unsigned char *) end;
16871 }
071436c6 16872 printf ("\"\n");
13761a11
NC
16873 }
16874 else
16875 {
cd30bcef 16876 READ_ULEB (val, p, end);
13761a11
NC
16877 printf ("%d (0x%x)\n", val, val);
16878 }
16879 break;
16880 }
16881
4082ef84 16882 assert (p <= end);
13761a11
NC
16883 return p;
16884}
16885
c0ea7c52
JL
16886static unsigned char *
16887display_msp430_gnu_attribute (unsigned char * p,
16888 unsigned int tag,
16889 const unsigned char * const end)
16890{
16891 if (tag == Tag_GNU_MSP430_Data_Region)
16892 {
cd30bcef 16893 unsigned int val;
c0ea7c52 16894
c0ea7c52 16895 printf (" Tag_GNU_MSP430_Data_Region: ");
cd30bcef 16896 READ_ULEB (val, p, end);
c0ea7c52
JL
16897
16898 switch (val)
16899 {
16900 case Val_GNU_MSP430_Data_Region_Any:
16901 printf (_("Any Region\n"));
16902 break;
16903 case Val_GNU_MSP430_Data_Region_Lower:
16904 printf (_("Lower Region Only\n"));
16905 break;
16906 default:
cd30bcef 16907 printf ("??? (%u)\n", val);
c0ea7c52
JL
16908 }
16909 return p;
16910 }
16911 return display_tag_value (tag & 1, p, end);
16912}
16913
2dc8dd17
JW
16914struct riscv_attr_tag_t {
16915 const char *name;
cd30bcef 16916 unsigned int tag;
2dc8dd17
JW
16917};
16918
16919static struct riscv_attr_tag_t riscv_attr_tag[] =
16920{
16921#define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
16922 T(arch),
16923 T(priv_spec),
16924 T(priv_spec_minor),
16925 T(priv_spec_revision),
16926 T(unaligned_access),
16927 T(stack_align),
16928#undef T
16929};
16930
16931static unsigned char *
16932display_riscv_attribute (unsigned char *p,
16933 const unsigned char * const end)
16934{
cd30bcef
AM
16935 unsigned int val;
16936 unsigned int tag;
2dc8dd17
JW
16937 struct riscv_attr_tag_t *attr = NULL;
16938 unsigned i;
16939
cd30bcef 16940 READ_ULEB (tag, p, end);
2dc8dd17
JW
16941
16942 /* Find the name of attribute. */
16943 for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++)
16944 {
16945 if (riscv_attr_tag[i].tag == tag)
16946 {
16947 attr = &riscv_attr_tag[i];
16948 break;
16949 }
16950 }
16951
16952 if (attr)
16953 printf (" %s: ", attr->name);
16954 else
16955 return display_tag_value (tag, p, end);
16956
16957 switch (tag)
16958 {
16959 case Tag_RISCV_priv_spec:
16960 case Tag_RISCV_priv_spec_minor:
16961 case Tag_RISCV_priv_spec_revision:
cd30bcef
AM
16962 READ_ULEB (val, p, end);
16963 printf (_("%u\n"), val);
2dc8dd17
JW
16964 break;
16965 case Tag_RISCV_unaligned_access:
cd30bcef 16966 READ_ULEB (val, p, end);
2dc8dd17
JW
16967 switch (val)
16968 {
16969 case 0:
16970 printf (_("No unaligned access\n"));
16971 break;
16972 case 1:
16973 printf (_("Unaligned access\n"));
16974 break;
16975 }
16976 break;
16977 case Tag_RISCV_stack_align:
cd30bcef
AM
16978 READ_ULEB (val, p, end);
16979 printf (_("%u-bytes\n"), val);
2dc8dd17
JW
16980 break;
16981 case Tag_RISCV_arch:
16982 p = display_tag_value (-1, p, end);
16983 break;
16984 default:
16985 return display_tag_value (tag, p, end);
16986 }
16987
16988 return p;
16989}
16990
0861f561
CQ
16991static unsigned char *
16992display_csky_attribute (unsigned char * p,
16993 const unsigned char * const end)
16994{
16995 unsigned int tag;
16996 unsigned int val;
16997 READ_ULEB (tag, p, end);
16998
16999 if (tag >= Tag_CSKY_MAX)
17000 {
17001 return display_tag_value (-1, p, end);
17002 }
17003
17004 switch (tag)
17005 {
17006 case Tag_CSKY_ARCH_NAME:
17007 printf (" Tag_CSKY_ARCH_NAME:\t\t");
17008 return display_tag_value (-1, p, end);
17009 case Tag_CSKY_CPU_NAME:
17010 printf (" Tag_CSKY_CPU_NAME:\t\t");
17011 return display_tag_value (-1, p, end);
17012
17013 case Tag_CSKY_ISA_FLAGS:
17014 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
17015 return display_tag_value (0, p, end);
17016 case Tag_CSKY_ISA_EXT_FLAGS:
17017 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
17018 return display_tag_value (0, p, end);
17019
17020 case Tag_CSKY_DSP_VERSION:
17021 printf (" Tag_CSKY_DSP_VERSION:\t\t");
17022 READ_ULEB (val, p, end);
17023 if (val == VAL_CSKY_DSP_VERSION_EXTENSION)
17024 printf ("DSP Extension\n");
17025 else if (val == VAL_CSKY_DSP_VERSION_2)
17026 printf ("DSP 2.0\n");
17027 break;
17028
17029 case Tag_CSKY_VDSP_VERSION:
17030 printf (" Tag_CSKY_VDSP_VERSION:\t");
17031 READ_ULEB (val, p, end);
17032 printf ("VDSP Version %d\n", val);
17033 break;
17034
17035 case Tag_CSKY_FPU_VERSION:
17036 printf (" Tag_CSKY_FPU_VERSION:\t\t");
17037 READ_ULEB (val, p, end);
17038 if (val == VAL_CSKY_FPU_VERSION_1)
17039 printf ("ABIV1 FPU Version 1\n");
17040 else if (val == VAL_CSKY_FPU_VERSION_2)
17041 printf ("FPU Version 2\n");
17042 break;
17043
17044 case Tag_CSKY_FPU_ABI:
17045 printf (" Tag_CSKY_FPU_ABI:\t\t");
17046 READ_ULEB (val, p, end);
17047 if (val == VAL_CSKY_FPU_ABI_HARD)
17048 printf ("Hard\n");
17049 else if (val == VAL_CSKY_FPU_ABI_SOFTFP)
17050 printf ("SoftFP\n");
17051 else if (val == VAL_CSKY_FPU_ABI_SOFT)
17052 printf ("Soft\n");
17053 break;
17054 case Tag_CSKY_FPU_ROUNDING:
17055 READ_ULEB (val, p, end);
17056 if (val == 1) {
17057 printf (" Tag_CSKY_FPU_ROUNDING:\t");
17058 printf ("Needed\n");
17059 }
17060 break;
17061 case Tag_CSKY_FPU_DENORMAL:
17062 READ_ULEB (val, p, end);
17063 if (val == 1) {
17064 printf (" Tag_CSKY_FPU_DENORMAL:\t");
17065 printf ("Needed\n");
17066 }
17067 break;
17068 case Tag_CSKY_FPU_Exception:
17069 READ_ULEB (val, p, end);
17070 if (val == 1) {
17071 printf (" Tag_CSKY_FPU_Exception:\t");
17072 printf ("Needed\n");
17073 }
17074 break;
17075 case Tag_CSKY_FPU_NUMBER_MODULE:
17076 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
17077 return display_tag_value (-1, p, end);
17078 case Tag_CSKY_FPU_HARDFP:
17079 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
17080 READ_ULEB (val, p, end);
17081 if (val & VAL_CSKY_FPU_HARDFP_HALF)
17082 printf (" Half");
17083 if (val & VAL_CSKY_FPU_HARDFP_SINGLE)
17084 printf (" Single");
17085 if (val & VAL_CSKY_FPU_HARDFP_DOUBLE)
17086 printf (" Double");
17087 printf ("\n");
17088 break;
17089 default:
17090 return display_tag_value (tag, p, end);
17091 }
17092 return p;
17093}
17094
32ec8896 17095static bfd_boolean
dda8d76d 17096process_attributes (Filedata * filedata,
60bca95a 17097 const char * public_name,
104d59d1 17098 unsigned int proc_type,
f6f0e17b 17099 unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
60abdbed 17100 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
11c1ff18 17101{
2cf0635d 17102 Elf_Internal_Shdr * sect;
11c1ff18 17103 unsigned i;
32ec8896 17104 bfd_boolean res = TRUE;
11c1ff18
PB
17105
17106 /* Find the section header so that we get the size. */
dda8d76d
NC
17107 for (i = 0, sect = filedata->section_headers;
17108 i < filedata->file_header.e_shnum;
11c1ff18
PB
17109 i++, sect++)
17110 {
071436c6
NC
17111 unsigned char * contents;
17112 unsigned char * p;
17113
104d59d1 17114 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
11c1ff18
PB
17115 continue;
17116
dda8d76d 17117 contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1,
3f5e193b 17118 sect->sh_size, _("attributes"));
60bca95a 17119 if (contents == NULL)
32ec8896
NC
17120 {
17121 res = FALSE;
17122 continue;
17123 }
60bca95a 17124
11c1ff18 17125 p = contents;
60abdbed
NC
17126 /* The first character is the version of the attributes.
17127 Currently only version 1, (aka 'A') is recognised here. */
17128 if (*p != 'A')
32ec8896
NC
17129 {
17130 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
17131 res = FALSE;
17132 }
60abdbed 17133 else
11c1ff18 17134 {
071436c6
NC
17135 bfd_vma section_len;
17136
17137 section_len = sect->sh_size - 1;
11c1ff18 17138 p++;
60bca95a 17139
071436c6 17140 while (section_len > 0)
11c1ff18 17141 {
071436c6 17142 bfd_vma attr_len;
e9847026 17143 unsigned int namelen;
11c1ff18 17144 bfd_boolean public_section;
104d59d1 17145 bfd_boolean gnu_section;
11c1ff18 17146
071436c6 17147 if (section_len <= 4)
e0a31db1
NC
17148 {
17149 error (_("Tag section ends prematurely\n"));
32ec8896 17150 res = FALSE;
e0a31db1
NC
17151 break;
17152 }
071436c6 17153 attr_len = byte_get (p, 4);
11c1ff18 17154 p += 4;
60bca95a 17155
071436c6 17156 if (attr_len > section_len)
11c1ff18 17157 {
071436c6
NC
17158 error (_("Bad attribute length (%u > %u)\n"),
17159 (unsigned) attr_len, (unsigned) section_len);
17160 attr_len = section_len;
32ec8896 17161 res = FALSE;
11c1ff18 17162 }
74e1a04b 17163 /* PR 17531: file: 001-101425-0.004 */
071436c6 17164 else if (attr_len < 5)
74e1a04b 17165 {
071436c6 17166 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
32ec8896 17167 res = FALSE;
74e1a04b
NC
17168 break;
17169 }
e9847026 17170
071436c6
NC
17171 section_len -= attr_len;
17172 attr_len -= 4;
17173
17174 namelen = strnlen ((char *) p, attr_len) + 1;
17175 if (namelen == 0 || namelen >= attr_len)
e9847026
NC
17176 {
17177 error (_("Corrupt attribute section name\n"));
32ec8896 17178 res = FALSE;
e9847026
NC
17179 break;
17180 }
17181
071436c6
NC
17182 printf (_("Attribute Section: "));
17183 print_symbol (INT_MAX, (const char *) p);
17184 putchar ('\n');
60bca95a
NC
17185
17186 if (public_name && streq ((char *) p, public_name))
11c1ff18
PB
17187 public_section = TRUE;
17188 else
17189 public_section = FALSE;
60bca95a
NC
17190
17191 if (streq ((char *) p, "gnu"))
104d59d1
JM
17192 gnu_section = TRUE;
17193 else
17194 gnu_section = FALSE;
60bca95a 17195
11c1ff18 17196 p += namelen;
071436c6 17197 attr_len -= namelen;
e0a31db1 17198
071436c6 17199 while (attr_len > 0 && p < contents + sect->sh_size)
11c1ff18 17200 {
e0a31db1 17201 int tag;
cd30bcef 17202 unsigned int val;
11c1ff18 17203 bfd_vma size;
071436c6 17204 unsigned char * end;
60bca95a 17205
e0a31db1 17206 /* PR binutils/17531: Safe handling of corrupt files. */
071436c6 17207 if (attr_len < 6)
e0a31db1
NC
17208 {
17209 error (_("Unused bytes at end of section\n"));
32ec8896 17210 res = FALSE;
e0a31db1
NC
17211 section_len = 0;
17212 break;
17213 }
17214
17215 tag = *(p++);
11c1ff18 17216 size = byte_get (p, 4);
071436c6 17217 if (size > attr_len)
11c1ff18 17218 {
e9847026 17219 error (_("Bad subsection length (%u > %u)\n"),
071436c6 17220 (unsigned) size, (unsigned) attr_len);
32ec8896 17221 res = FALSE;
071436c6 17222 size = attr_len;
11c1ff18 17223 }
e0a31db1
NC
17224 /* PR binutils/17531: Safe handling of corrupt files. */
17225 if (size < 6)
17226 {
17227 error (_("Bad subsection length (%u < 6)\n"),
17228 (unsigned) size);
32ec8896 17229 res = FALSE;
e0a31db1
NC
17230 section_len = 0;
17231 break;
17232 }
60bca95a 17233
071436c6 17234 attr_len -= size;
11c1ff18 17235 end = p + size - 1;
071436c6 17236 assert (end <= contents + sect->sh_size);
11c1ff18 17237 p += 4;
60bca95a 17238
11c1ff18
PB
17239 switch (tag)
17240 {
17241 case 1:
2b692964 17242 printf (_("File Attributes\n"));
11c1ff18
PB
17243 break;
17244 case 2:
2b692964 17245 printf (_("Section Attributes:"));
11c1ff18
PB
17246 goto do_numlist;
17247 case 3:
2b692964 17248 printf (_("Symbol Attributes:"));
1a0670f3 17249 /* Fall through. */
11c1ff18
PB
17250 do_numlist:
17251 for (;;)
17252 {
cd30bcef 17253 READ_ULEB (val, p, end);
11c1ff18
PB
17254 if (val == 0)
17255 break;
17256 printf (" %d", val);
17257 }
17258 printf ("\n");
17259 break;
17260 default:
2b692964 17261 printf (_("Unknown tag: %d\n"), tag);
11c1ff18
PB
17262 public_section = FALSE;
17263 break;
17264 }
60bca95a 17265
071436c6 17266 if (public_section && display_pub_attribute != NULL)
11c1ff18
PB
17267 {
17268 while (p < end)
f6f0e17b 17269 p = display_pub_attribute (p, end);
60abdbed 17270 assert (p == end);
104d59d1 17271 }
071436c6 17272 else if (gnu_section && display_proc_gnu_attribute != NULL)
104d59d1
JM
17273 {
17274 while (p < end)
17275 p = display_gnu_attribute (p,
f6f0e17b
NC
17276 display_proc_gnu_attribute,
17277 end);
60abdbed 17278 assert (p == end);
11c1ff18 17279 }
071436c6 17280 else if (p < end)
11c1ff18 17281 {
071436c6 17282 printf (_(" Unknown attribute:\n"));
f6f0e17b 17283 display_raw_attribute (p, end);
11c1ff18
PB
17284 p = end;
17285 }
071436c6
NC
17286 else
17287 attr_len = 0;
11c1ff18
PB
17288 }
17289 }
17290 }
d70c5fc7 17291
60bca95a 17292 free (contents);
11c1ff18 17293 }
32ec8896
NC
17294
17295 return res;
11c1ff18
PB
17296}
17297
ccb4c951
RS
17298/* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
17299 Print the Address, Access and Initial fields of an entry at VMA ADDR
82b1b41b
NC
17300 and return the VMA of the next entry, or -1 if there was a problem.
17301 Does not read from DATA_END or beyond. */
ccb4c951
RS
17302
17303static bfd_vma
82b1b41b
NC
17304print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
17305 unsigned char * data_end)
ccb4c951
RS
17306{
17307 printf (" ");
17308 print_vma (addr, LONG_HEX);
17309 printf (" ");
17310 if (addr < pltgot + 0xfff0)
17311 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
17312 else
17313 printf ("%10s", "");
17314 printf (" ");
17315 if (data == NULL)
2b692964 17316 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
ccb4c951
RS
17317 else
17318 {
17319 bfd_vma entry;
82b1b41b 17320 unsigned char * from = data + addr - pltgot;
ccb4c951 17321
82b1b41b
NC
17322 if (from + (is_32bit_elf ? 4 : 8) > data_end)
17323 {
17324 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
17325 printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
17326 return (bfd_vma) -1;
17327 }
17328 else
17329 {
17330 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
17331 print_vma (entry, LONG_HEX);
17332 }
ccb4c951
RS
17333 }
17334 return addr + (is_32bit_elf ? 4 : 8);
17335}
17336
861fb55a
DJ
17337/* DATA points to the contents of a MIPS PLT GOT that starts at VMA
17338 PLTGOT. Print the Address and Initial fields of an entry at VMA
17339 ADDR and return the VMA of the next entry. */
17340
17341static bfd_vma
2cf0635d 17342print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
861fb55a
DJ
17343{
17344 printf (" ");
17345 print_vma (addr, LONG_HEX);
17346 printf (" ");
17347 if (data == NULL)
2b692964 17348 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
861fb55a
DJ
17349 else
17350 {
17351 bfd_vma entry;
17352
17353 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
17354 print_vma (entry, LONG_HEX);
17355 }
17356 return addr + (is_32bit_elf ? 4 : 8);
17357}
17358
351cdf24
MF
17359static void
17360print_mips_ases (unsigned int mask)
17361{
17362 if (mask & AFL_ASE_DSP)
17363 fputs ("\n\tDSP ASE", stdout);
17364 if (mask & AFL_ASE_DSPR2)
17365 fputs ("\n\tDSP R2 ASE", stdout);
8f4f9071
MF
17366 if (mask & AFL_ASE_DSPR3)
17367 fputs ("\n\tDSP R3 ASE", stdout);
351cdf24
MF
17368 if (mask & AFL_ASE_EVA)
17369 fputs ("\n\tEnhanced VA Scheme", stdout);
17370 if (mask & AFL_ASE_MCU)
17371 fputs ("\n\tMCU (MicroController) ASE", stdout);
17372 if (mask & AFL_ASE_MDMX)
17373 fputs ("\n\tMDMX ASE", stdout);
17374 if (mask & AFL_ASE_MIPS3D)
17375 fputs ("\n\tMIPS-3D ASE", stdout);
17376 if (mask & AFL_ASE_MT)
17377 fputs ("\n\tMT ASE", stdout);
17378 if (mask & AFL_ASE_SMARTMIPS)
17379 fputs ("\n\tSmartMIPS ASE", stdout);
17380 if (mask & AFL_ASE_VIRT)
17381 fputs ("\n\tVZ ASE", stdout);
17382 if (mask & AFL_ASE_MSA)
17383 fputs ("\n\tMSA ASE", stdout);
17384 if (mask & AFL_ASE_MIPS16)
17385 fputs ("\n\tMIPS16 ASE", stdout);
17386 if (mask & AFL_ASE_MICROMIPS)
17387 fputs ("\n\tMICROMIPS ASE", stdout);
17388 if (mask & AFL_ASE_XPA)
17389 fputs ("\n\tXPA ASE", stdout);
25499ac7
MR
17390 if (mask & AFL_ASE_MIPS16E2)
17391 fputs ("\n\tMIPS16e2 ASE", stdout);
730c3174
SE
17392 if (mask & AFL_ASE_CRC)
17393 fputs ("\n\tCRC ASE", stdout);
6f20c942
FS
17394 if (mask & AFL_ASE_GINV)
17395 fputs ("\n\tGINV ASE", stdout);
8095d2f7
CX
17396 if (mask & AFL_ASE_LOONGSON_MMI)
17397 fputs ("\n\tLoongson MMI ASE", stdout);
716c08de
CX
17398 if (mask & AFL_ASE_LOONGSON_CAM)
17399 fputs ("\n\tLoongson CAM ASE", stdout);
bdc6c06e
CX
17400 if (mask & AFL_ASE_LOONGSON_EXT)
17401 fputs ("\n\tLoongson EXT ASE", stdout);
a693765e
CX
17402 if (mask & AFL_ASE_LOONGSON_EXT2)
17403 fputs ("\n\tLoongson EXT2 ASE", stdout);
351cdf24
MF
17404 if (mask == 0)
17405 fprintf (stdout, "\n\t%s", _("None"));
00ac7aa0
MF
17406 else if ((mask & ~AFL_ASE_MASK) != 0)
17407 fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
351cdf24
MF
17408}
17409
17410static void
17411print_mips_isa_ext (unsigned int isa_ext)
17412{
17413 switch (isa_ext)
17414 {
17415 case 0:
17416 fputs (_("None"), stdout);
17417 break;
17418 case AFL_EXT_XLR:
17419 fputs ("RMI XLR", stdout);
17420 break;
2c629856
N
17421 case AFL_EXT_OCTEON3:
17422 fputs ("Cavium Networks Octeon3", stdout);
17423 break;
351cdf24
MF
17424 case AFL_EXT_OCTEON2:
17425 fputs ("Cavium Networks Octeon2", stdout);
17426 break;
17427 case AFL_EXT_OCTEONP:
17428 fputs ("Cavium Networks OcteonP", stdout);
17429 break;
351cdf24
MF
17430 case AFL_EXT_OCTEON:
17431 fputs ("Cavium Networks Octeon", stdout);
17432 break;
17433 case AFL_EXT_5900:
17434 fputs ("Toshiba R5900", stdout);
17435 break;
17436 case AFL_EXT_4650:
17437 fputs ("MIPS R4650", stdout);
17438 break;
17439 case AFL_EXT_4010:
17440 fputs ("LSI R4010", stdout);
17441 break;
17442 case AFL_EXT_4100:
17443 fputs ("NEC VR4100", stdout);
17444 break;
17445 case AFL_EXT_3900:
17446 fputs ("Toshiba R3900", stdout);
17447 break;
17448 case AFL_EXT_10000:
17449 fputs ("MIPS R10000", stdout);
17450 break;
17451 case AFL_EXT_SB1:
17452 fputs ("Broadcom SB-1", stdout);
17453 break;
17454 case AFL_EXT_4111:
17455 fputs ("NEC VR4111/VR4181", stdout);
17456 break;
17457 case AFL_EXT_4120:
17458 fputs ("NEC VR4120", stdout);
17459 break;
17460 case AFL_EXT_5400:
17461 fputs ("NEC VR5400", stdout);
17462 break;
17463 case AFL_EXT_5500:
17464 fputs ("NEC VR5500", stdout);
17465 break;
17466 case AFL_EXT_LOONGSON_2E:
17467 fputs ("ST Microelectronics Loongson 2E", stdout);
17468 break;
17469 case AFL_EXT_LOONGSON_2F:
17470 fputs ("ST Microelectronics Loongson 2F", stdout);
17471 break;
38bf472a
MR
17472 case AFL_EXT_INTERAPTIV_MR2:
17473 fputs ("Imagination interAptiv MR2", stdout);
17474 break;
351cdf24 17475 default:
00ac7aa0 17476 fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
351cdf24
MF
17477 }
17478}
17479
32ec8896 17480static signed int
351cdf24
MF
17481get_mips_reg_size (int reg_size)
17482{
17483 return (reg_size == AFL_REG_NONE) ? 0
17484 : (reg_size == AFL_REG_32) ? 32
17485 : (reg_size == AFL_REG_64) ? 64
17486 : (reg_size == AFL_REG_128) ? 128
17487 : -1;
17488}
17489
32ec8896 17490static bfd_boolean
dda8d76d 17491process_mips_specific (Filedata * filedata)
5b18a4bc 17492{
2cf0635d 17493 Elf_Internal_Dyn * entry;
351cdf24 17494 Elf_Internal_Shdr *sect = NULL;
19e6b90e
L
17495 size_t liblist_offset = 0;
17496 size_t liblistno = 0;
17497 size_t conflictsno = 0;
17498 size_t options_offset = 0;
17499 size_t conflicts_offset = 0;
861fb55a
DJ
17500 size_t pltrelsz = 0;
17501 size_t pltrel = 0;
ccb4c951 17502 bfd_vma pltgot = 0;
861fb55a
DJ
17503 bfd_vma mips_pltgot = 0;
17504 bfd_vma jmprel = 0;
ccb4c951
RS
17505 bfd_vma local_gotno = 0;
17506 bfd_vma gotsym = 0;
17507 bfd_vma symtabno = 0;
32ec8896 17508 bfd_boolean res = TRUE;
103f02d3 17509
dda8d76d 17510 if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
32ec8896
NC
17511 display_mips_gnu_attribute))
17512 res = FALSE;
2cf19d5c 17513
dda8d76d 17514 sect = find_section (filedata, ".MIPS.abiflags");
351cdf24
MF
17515
17516 if (sect != NULL)
17517 {
17518 Elf_External_ABIFlags_v0 *abiflags_ext;
17519 Elf_Internal_ABIFlags_v0 abiflags_in;
17520
17521 if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
32ec8896
NC
17522 {
17523 error (_("Corrupt MIPS ABI Flags section.\n"));
17524 res = FALSE;
17525 }
351cdf24
MF
17526 else
17527 {
dda8d76d 17528 abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
351cdf24
MF
17529 sect->sh_size, _("MIPS ABI Flags section"));
17530 if (abiflags_ext)
17531 {
17532 abiflags_in.version = BYTE_GET (abiflags_ext->version);
17533 abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
17534 abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
17535 abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
17536 abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
17537 abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
17538 abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
17539 abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
17540 abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
17541 abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
17542 abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
17543
17544 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
17545 printf ("\nISA: MIPS%d", abiflags_in.isa_level);
17546 if (abiflags_in.isa_rev > 1)
17547 printf ("r%d", abiflags_in.isa_rev);
17548 printf ("\nGPR size: %d",
17549 get_mips_reg_size (abiflags_in.gpr_size));
17550 printf ("\nCPR1 size: %d",
17551 get_mips_reg_size (abiflags_in.cpr1_size));
17552 printf ("\nCPR2 size: %d",
17553 get_mips_reg_size (abiflags_in.cpr2_size));
17554 fputs ("\nFP ABI: ", stdout);
17555 print_mips_fp_abi_value (abiflags_in.fp_abi);
17556 fputs ("ISA Extension: ", stdout);
17557 print_mips_isa_ext (abiflags_in.isa_ext);
17558 fputs ("\nASEs:", stdout);
17559 print_mips_ases (abiflags_in.ases);
17560 printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
17561 printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
17562 fputc ('\n', stdout);
17563 free (abiflags_ext);
17564 }
17565 }
17566 }
17567
19e6b90e 17568 /* We have a lot of special sections. Thanks SGI! */
978c4450 17569 if (filedata->dynamic_section == NULL)
bbdd9a68
MR
17570 {
17571 /* No dynamic information available. See if there is static GOT. */
dda8d76d 17572 sect = find_section (filedata, ".got");
bbdd9a68
MR
17573 if (sect != NULL)
17574 {
17575 unsigned char *data_end;
17576 unsigned char *data;
17577 bfd_vma ent, end;
17578 int addr_size;
17579
17580 pltgot = sect->sh_addr;
17581
17582 ent = pltgot;
17583 addr_size = (is_32bit_elf ? 4 : 8);
17584 end = pltgot + sect->sh_size;
17585
dda8d76d 17586 data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset,
bbdd9a68
MR
17587 end - pltgot, 1,
17588 _("Global Offset Table data"));
17589 /* PR 12855: Null data is handled gracefully throughout. */
17590 data_end = data + (end - pltgot);
17591
17592 printf (_("\nStatic GOT:\n"));
17593 printf (_(" Canonical gp value: "));
17594 print_vma (ent + 0x7ff0, LONG_HEX);
17595 printf ("\n\n");
17596
17597 /* In a dynamic binary GOT[0] is reserved for the dynamic
17598 loader to store the lazy resolver pointer, however in
17599 a static binary it may well have been omitted and GOT
17600 reduced to a table of addresses.
17601 PR 21344: Check for the entry being fully available
17602 before fetching it. */
17603 if (data
17604 && data + ent - pltgot + addr_size <= data_end
17605 && byte_get (data + ent - pltgot, addr_size) == 0)
17606 {
17607 printf (_(" Reserved entries:\n"));
17608 printf (_(" %*s %10s %*s\n"),
17609 addr_size * 2, _("Address"), _("Access"),
17610 addr_size * 2, _("Value"));
17611 ent = print_mips_got_entry (data, pltgot, ent, data_end);
17612 printf ("\n");
17613 if (ent == (bfd_vma) -1)
17614 goto sgot_print_fail;
17615
17616 /* Check for the MSB of GOT[1] being set, identifying a
17617 GNU object. This entry will be used by some runtime
17618 loaders, to store the module pointer. Otherwise this
17619 is an ordinary local entry.
17620 PR 21344: Check for the entry being fully available
17621 before fetching it. */
17622 if (data
17623 && data + ent - pltgot + addr_size <= data_end
17624 && (byte_get (data + ent - pltgot, addr_size)
17625 >> (addr_size * 8 - 1)) != 0)
17626 {
17627 ent = print_mips_got_entry (data, pltgot, ent, data_end);
17628 printf ("\n");
17629 if (ent == (bfd_vma) -1)
17630 goto sgot_print_fail;
17631 }
17632 printf ("\n");
17633 }
17634
f17e9d8a 17635 if (data != NULL && ent < end)
bbdd9a68
MR
17636 {
17637 printf (_(" Local entries:\n"));
17638 printf (" %*s %10s %*s\n",
17639 addr_size * 2, _("Address"), _("Access"),
17640 addr_size * 2, _("Value"));
17641 while (ent < end)
17642 {
17643 ent = print_mips_got_entry (data, pltgot, ent, data_end);
17644 printf ("\n");
17645 if (ent == (bfd_vma) -1)
17646 goto sgot_print_fail;
17647 }
17648 printf ("\n");
17649 }
17650
17651 sgot_print_fail:
9db70fc3 17652 free (data);
bbdd9a68
MR
17653 }
17654 return res;
17655 }
252b5132 17656
978c4450 17657 for (entry = filedata->dynamic_section;
071436c6 17658 /* PR 17531 file: 012-50589-0.004. */
978c4450
AM
17659 (entry < filedata->dynamic_section + filedata->dynamic_nent
17660 && entry->d_tag != DT_NULL);
071436c6 17661 ++entry)
252b5132
RH
17662 switch (entry->d_tag)
17663 {
17664 case DT_MIPS_LIBLIST:
d93f0186 17665 liblist_offset
dda8d76d 17666 = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 17667 liblistno * sizeof (Elf32_External_Lib));
252b5132
RH
17668 break;
17669 case DT_MIPS_LIBLISTNO:
17670 liblistno = entry->d_un.d_val;
17671 break;
17672 case DT_MIPS_OPTIONS:
dda8d76d 17673 options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
252b5132
RH
17674 break;
17675 case DT_MIPS_CONFLICT:
d93f0186 17676 conflicts_offset
dda8d76d 17677 = offset_from_vma (filedata, entry->d_un.d_val,
d93f0186 17678 conflictsno * sizeof (Elf32_External_Conflict));
252b5132
RH
17679 break;
17680 case DT_MIPS_CONFLICTNO:
17681 conflictsno = entry->d_un.d_val;
17682 break;
ccb4c951 17683 case DT_PLTGOT:
861fb55a
DJ
17684 pltgot = entry->d_un.d_ptr;
17685 break;
ccb4c951
RS
17686 case DT_MIPS_LOCAL_GOTNO:
17687 local_gotno = entry->d_un.d_val;
17688 break;
17689 case DT_MIPS_GOTSYM:
17690 gotsym = entry->d_un.d_val;
17691 break;
17692 case DT_MIPS_SYMTABNO:
17693 symtabno = entry->d_un.d_val;
17694 break;
861fb55a
DJ
17695 case DT_MIPS_PLTGOT:
17696 mips_pltgot = entry->d_un.d_ptr;
17697 break;
17698 case DT_PLTREL:
17699 pltrel = entry->d_un.d_val;
17700 break;
17701 case DT_PLTRELSZ:
17702 pltrelsz = entry->d_un.d_val;
17703 break;
17704 case DT_JMPREL:
17705 jmprel = entry->d_un.d_ptr;
17706 break;
252b5132
RH
17707 default:
17708 break;
17709 }
17710
17711 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
17712 {
2cf0635d 17713 Elf32_External_Lib * elib;
252b5132
RH
17714 size_t cnt;
17715
dda8d76d 17716 elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset,
95099889
AM
17717 sizeof (Elf32_External_Lib),
17718 liblistno,
17719 _("liblist section data"));
a6e9f9df 17720 if (elib)
252b5132 17721 {
d3a49aa8
AM
17722 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
17723 "\nSection '.liblist' contains %lu entries:\n",
17724 (unsigned long) liblistno),
a6e9f9df 17725 (unsigned long) liblistno);
2b692964 17726 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
a6e9f9df
AM
17727 stdout);
17728
17729 for (cnt = 0; cnt < liblistno; ++cnt)
252b5132 17730 {
a6e9f9df 17731 Elf32_Lib liblist;
91d6fa6a 17732 time_t atime;
d5b07ef4 17733 char timebuf[128];
2cf0635d 17734 struct tm * tmp;
a6e9f9df
AM
17735
17736 liblist.l_name = BYTE_GET (elib[cnt].l_name);
91d6fa6a 17737 atime = BYTE_GET (elib[cnt].l_time_stamp);
a6e9f9df
AM
17738 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
17739 liblist.l_version = BYTE_GET (elib[cnt].l_version);
17740 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
17741
91d6fa6a 17742 tmp = gmtime (&atime);
e9e44622
JJ
17743 snprintf (timebuf, sizeof (timebuf),
17744 "%04u-%02u-%02uT%02u:%02u:%02u",
17745 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
17746 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
a6e9f9df 17747
31104126 17748 printf ("%3lu: ", (unsigned long) cnt);
978c4450
AM
17749 if (VALID_DYNAMIC_NAME (filedata, liblist.l_name))
17750 print_symbol (20, GET_DYNAMIC_NAME (filedata, liblist.l_name));
d79b3d50 17751 else
2b692964 17752 printf (_("<corrupt: %9ld>"), liblist.l_name);
31104126
NC
17753 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
17754 liblist.l_version);
a6e9f9df
AM
17755
17756 if (liblist.l_flags == 0)
2b692964 17757 puts (_(" NONE"));
a6e9f9df
AM
17758 else
17759 {
17760 static const struct
252b5132 17761 {
2cf0635d 17762 const char * name;
a6e9f9df 17763 int bit;
252b5132 17764 }
a6e9f9df
AM
17765 l_flags_vals[] =
17766 {
17767 { " EXACT_MATCH", LL_EXACT_MATCH },
17768 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
17769 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
17770 { " EXPORTS", LL_EXPORTS },
17771 { " DELAY_LOAD", LL_DELAY_LOAD },
17772 { " DELTA", LL_DELTA }
17773 };
17774 int flags = liblist.l_flags;
17775 size_t fcnt;
17776
60bca95a 17777 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
a6e9f9df
AM
17778 if ((flags & l_flags_vals[fcnt].bit) != 0)
17779 {
17780 fputs (l_flags_vals[fcnt].name, stdout);
17781 flags ^= l_flags_vals[fcnt].bit;
17782 }
17783 if (flags != 0)
17784 printf (" %#x", (unsigned int) flags);
252b5132 17785
a6e9f9df
AM
17786 puts ("");
17787 }
252b5132 17788 }
252b5132 17789
a6e9f9df
AM
17790 free (elib);
17791 }
32ec8896
NC
17792 else
17793 res = FALSE;
252b5132
RH
17794 }
17795
17796 if (options_offset != 0)
17797 {
2cf0635d 17798 Elf_External_Options * eopt;
252b5132
RH
17799 size_t offset;
17800 int cnt;
dda8d76d 17801 sect = filedata->section_headers;
252b5132
RH
17802
17803 /* Find the section header so that we get the size. */
dda8d76d 17804 sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS);
948f632f 17805 /* PR 17533 file: 012-277276-0.004. */
071436c6
NC
17806 if (sect == NULL)
17807 {
17808 error (_("No MIPS_OPTIONS header found\n"));
32ec8896 17809 return FALSE;
071436c6 17810 }
7fc0c668
NC
17811 /* PR 24243 */
17812 if (sect->sh_size < sizeof (* eopt))
17813 {
17814 error (_("The MIPS options section is too small.\n"));
17815 return FALSE;
17816 }
252b5132 17817
dda8d76d 17818 eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1,
3f5e193b 17819 sect->sh_size, _("options"));
a6e9f9df 17820 if (eopt)
252b5132 17821 {
fd17d1e6 17822 Elf_Internal_Options option;
76da6bbe 17823
a6e9f9df 17824 offset = cnt = 0;
82b1b41b 17825 while (offset <= sect->sh_size - sizeof (* eopt))
a6e9f9df 17826 {
2cf0635d 17827 Elf_External_Options * eoption;
fd17d1e6 17828 unsigned int optsize;
252b5132 17829
a6e9f9df 17830 eoption = (Elf_External_Options *) ((char *) eopt + offset);
252b5132 17831
fd17d1e6 17832 optsize = BYTE_GET (eoption->size);
76da6bbe 17833
82b1b41b 17834 /* PR 17531: file: ffa0fa3b. */
fd17d1e6
AM
17835 if (optsize < sizeof (* eopt)
17836 || optsize > sect->sh_size - offset)
82b1b41b 17837 {
645f43a8 17838 error (_("Invalid size (%u) for MIPS option\n"),
fd17d1e6 17839 optsize);
645f43a8 17840 free (eopt);
32ec8896 17841 return FALSE;
82b1b41b 17842 }
fd17d1e6 17843 offset += optsize;
a6e9f9df
AM
17844 ++cnt;
17845 }
252b5132 17846
d3a49aa8
AM
17847 printf (ngettext ("\nSection '%s' contains %d entry:\n",
17848 "\nSection '%s' contains %d entries:\n",
17849 cnt),
dda8d76d 17850 printable_section_name (filedata, sect), cnt);
76da6bbe 17851
82b1b41b 17852 offset = 0;
a6e9f9df 17853 while (cnt-- > 0)
252b5132 17854 {
a6e9f9df 17855 size_t len;
fd17d1e6
AM
17856 Elf_External_Options * eoption;
17857
17858 eoption = (Elf_External_Options *) ((char *) eopt + offset);
17859
17860 option.kind = BYTE_GET (eoption->kind);
17861 option.size = BYTE_GET (eoption->size);
17862 option.section = BYTE_GET (eoption->section);
17863 option.info = BYTE_GET (eoption->info);
a6e9f9df 17864
fd17d1e6 17865 switch (option.kind)
252b5132 17866 {
a6e9f9df
AM
17867 case ODK_NULL:
17868 /* This shouldn't happen. */
d0c4e780 17869 printf (" NULL %" PRId16 " %" PRIx32,
fd17d1e6 17870 option.section, option.info);
a6e9f9df 17871 break;
2e6be59c 17872
a6e9f9df
AM
17873 case ODK_REGINFO:
17874 printf (" REGINFO ");
dda8d76d 17875 if (filedata->file_header.e_machine == EM_MIPS)
a6e9f9df 17876 {
2cf0635d 17877 Elf32_External_RegInfo * ereg;
b34976b6 17878 Elf32_RegInfo reginfo;
a6e9f9df 17879
2e6be59c 17880 /* 32bit form. */
fd17d1e6
AM
17881 if (option.size < (sizeof (Elf_External_Options)
17882 + sizeof (Elf32_External_RegInfo)))
2e6be59c
NC
17883 {
17884 printf (_("<corrupt>\n"));
17885 error (_("Truncated MIPS REGINFO option\n"));
17886 cnt = 0;
17887 break;
17888 }
17889
fd17d1e6 17890 ereg = (Elf32_External_RegInfo *) (eoption + 1);
2e6be59c 17891
a6e9f9df
AM
17892 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
17893 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
17894 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
17895 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
17896 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
17897 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
17898
d0c4e780
AM
17899 printf ("GPR %08" PRIx32 " GP 0x%" PRIx32 "\n",
17900 reginfo.ri_gprmask, reginfo.ri_gp_value);
17901 printf (" "
17902 " CPR0 %08" PRIx32 " CPR1 %08" PRIx32
17903 " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n",
a6e9f9df
AM
17904 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
17905 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
17906 }
17907 else
17908 {
17909 /* 64 bit form. */
2cf0635d 17910 Elf64_External_RegInfo * ereg;
a6e9f9df
AM
17911 Elf64_Internal_RegInfo reginfo;
17912
fd17d1e6
AM
17913 if (option.size < (sizeof (Elf_External_Options)
17914 + sizeof (Elf64_External_RegInfo)))
2e6be59c
NC
17915 {
17916 printf (_("<corrupt>\n"));
17917 error (_("Truncated MIPS REGINFO option\n"));
17918 cnt = 0;
17919 break;
17920 }
17921
fd17d1e6 17922 ereg = (Elf64_External_RegInfo *) (eoption + 1);
a6e9f9df
AM
17923 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
17924 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
17925 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
17926 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
17927 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
66543521 17928 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
a6e9f9df 17929
d0c4e780
AM
17930 printf ("GPR %08" PRIx32 " GP 0x%" PRIx64 "\n",
17931 reginfo.ri_gprmask, reginfo.ri_gp_value);
17932 printf (" "
17933 " CPR0 %08" PRIx32 " CPR1 %08" PRIx32
17934 " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n",
a6e9f9df
AM
17935 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
17936 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
17937 }
fd17d1e6 17938 offset += option.size;
a6e9f9df 17939 continue;
2e6be59c 17940
a6e9f9df
AM
17941 case ODK_EXCEPTIONS:
17942 fputs (" EXCEPTIONS fpe_min(", stdout);
fd17d1e6 17943 process_mips_fpe_exception (option.info & OEX_FPU_MIN);
a6e9f9df 17944 fputs (") fpe_max(", stdout);
fd17d1e6 17945 process_mips_fpe_exception ((option.info & OEX_FPU_MAX) >> 8);
a6e9f9df
AM
17946 fputs (")", stdout);
17947
fd17d1e6 17948 if (option.info & OEX_PAGE0)
a6e9f9df 17949 fputs (" PAGE0", stdout);
fd17d1e6 17950 if (option.info & OEX_SMM)
a6e9f9df 17951 fputs (" SMM", stdout);
fd17d1e6 17952 if (option.info & OEX_FPDBUG)
a6e9f9df 17953 fputs (" FPDBUG", stdout);
fd17d1e6 17954 if (option.info & OEX_DISMISS)
a6e9f9df
AM
17955 fputs (" DISMISS", stdout);
17956 break;
2e6be59c 17957
a6e9f9df
AM
17958 case ODK_PAD:
17959 fputs (" PAD ", stdout);
fd17d1e6 17960 if (option.info & OPAD_PREFIX)
a6e9f9df 17961 fputs (" PREFIX", stdout);
fd17d1e6 17962 if (option.info & OPAD_POSTFIX)
a6e9f9df 17963 fputs (" POSTFIX", stdout);
fd17d1e6 17964 if (option.info & OPAD_SYMBOL)
a6e9f9df
AM
17965 fputs (" SYMBOL", stdout);
17966 break;
2e6be59c 17967
a6e9f9df
AM
17968 case ODK_HWPATCH:
17969 fputs (" HWPATCH ", stdout);
fd17d1e6 17970 if (option.info & OHW_R4KEOP)
a6e9f9df 17971 fputs (" R4KEOP", stdout);
fd17d1e6 17972 if (option.info & OHW_R8KPFETCH)
a6e9f9df 17973 fputs (" R8KPFETCH", stdout);
fd17d1e6 17974 if (option.info & OHW_R5KEOP)
a6e9f9df 17975 fputs (" R5KEOP", stdout);
fd17d1e6 17976 if (option.info & OHW_R5KCVTL)
a6e9f9df
AM
17977 fputs (" R5KCVTL", stdout);
17978 break;
2e6be59c 17979
a6e9f9df
AM
17980 case ODK_FILL:
17981 fputs (" FILL ", stdout);
17982 /* XXX Print content of info word? */
17983 break;
2e6be59c 17984
a6e9f9df
AM
17985 case ODK_TAGS:
17986 fputs (" TAGS ", stdout);
17987 /* XXX Print content of info word? */
17988 break;
2e6be59c 17989
a6e9f9df
AM
17990 case ODK_HWAND:
17991 fputs (" HWAND ", stdout);
fd17d1e6 17992 if (option.info & OHWA0_R4KEOP_CHECKED)
a6e9f9df 17993 fputs (" R4KEOP_CHECKED", stdout);
fd17d1e6 17994 if (option.info & OHWA0_R4KEOP_CLEAN)
a6e9f9df
AM
17995 fputs (" R4KEOP_CLEAN", stdout);
17996 break;
2e6be59c 17997
a6e9f9df
AM
17998 case ODK_HWOR:
17999 fputs (" HWOR ", stdout);
fd17d1e6 18000 if (option.info & OHWA0_R4KEOP_CHECKED)
a6e9f9df 18001 fputs (" R4KEOP_CHECKED", stdout);
fd17d1e6 18002 if (option.info & OHWA0_R4KEOP_CLEAN)
a6e9f9df
AM
18003 fputs (" R4KEOP_CLEAN", stdout);
18004 break;
2e6be59c 18005
a6e9f9df 18006 case ODK_GP_GROUP:
d0c4e780 18007 printf (" GP_GROUP %#06x self-contained %#06x",
fd17d1e6
AM
18008 option.info & OGP_GROUP,
18009 (option.info & OGP_SELF) >> 16);
a6e9f9df 18010 break;
2e6be59c 18011
a6e9f9df 18012 case ODK_IDENT:
d0c4e780 18013 printf (" IDENT %#06x self-contained %#06x",
fd17d1e6
AM
18014 option.info & OGP_GROUP,
18015 (option.info & OGP_SELF) >> 16);
a6e9f9df 18016 break;
2e6be59c 18017
a6e9f9df
AM
18018 default:
18019 /* This shouldn't happen. */
d0c4e780 18020 printf (" %3d ??? %" PRId16 " %" PRIx32,
fd17d1e6 18021 option.kind, option.section, option.info);
a6e9f9df 18022 break;
252b5132 18023 }
a6e9f9df 18024
2cf0635d 18025 len = sizeof (* eopt);
fd17d1e6 18026 while (len < option.size)
82b1b41b 18027 {
fd17d1e6 18028 unsigned char datum = *((unsigned char *) eoption + len);
a6e9f9df 18029
82b1b41b
NC
18030 if (ISPRINT (datum))
18031 printf ("%c", datum);
18032 else
18033 printf ("\\%03o", datum);
18034 len ++;
18035 }
a6e9f9df 18036 fputs ("\n", stdout);
82b1b41b 18037
fd17d1e6 18038 offset += option.size;
252b5132 18039 }
a6e9f9df 18040 free (eopt);
252b5132 18041 }
32ec8896
NC
18042 else
18043 res = FALSE;
252b5132
RH
18044 }
18045
18046 if (conflicts_offset != 0 && conflictsno != 0)
18047 {
2cf0635d 18048 Elf32_Conflict * iconf;
252b5132
RH
18049 size_t cnt;
18050
978c4450 18051 if (filedata->dynamic_symbols == NULL)
252b5132 18052 {
591a748a 18053 error (_("conflict list found without a dynamic symbol table\n"));
32ec8896 18054 return FALSE;
252b5132
RH
18055 }
18056
7296a62a
NC
18057 /* PR 21345 - print a slightly more helpful error message
18058 if we are sure that the cmalloc will fail. */
645f43a8 18059 if (conflictsno > filedata->file_size / sizeof (* iconf))
7296a62a
NC
18060 {
18061 error (_("Overlarge number of conflicts detected: %lx\n"),
18062 (long) conflictsno);
18063 return FALSE;
18064 }
18065
3f5e193b 18066 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
252b5132
RH
18067 if (iconf == NULL)
18068 {
8b73c356 18069 error (_("Out of memory allocating space for dynamic conflicts\n"));
32ec8896 18070 return FALSE;
252b5132
RH
18071 }
18072
9ea033b2 18073 if (is_32bit_elf)
252b5132 18074 {
2cf0635d 18075 Elf32_External_Conflict * econf32;
a6e9f9df 18076
3f5e193b 18077 econf32 = (Elf32_External_Conflict *)
95099889
AM
18078 get_data (NULL, filedata, conflicts_offset,
18079 sizeof (*econf32), conflictsno, _("conflict"));
a6e9f9df 18080 if (!econf32)
5a814d6d
AM
18081 {
18082 free (iconf);
18083 return FALSE;
18084 }
252b5132
RH
18085
18086 for (cnt = 0; cnt < conflictsno; ++cnt)
18087 iconf[cnt] = BYTE_GET (econf32[cnt]);
a6e9f9df
AM
18088
18089 free (econf32);
252b5132
RH
18090 }
18091 else
18092 {
2cf0635d 18093 Elf64_External_Conflict * econf64;
a6e9f9df 18094
3f5e193b 18095 econf64 = (Elf64_External_Conflict *)
95099889
AM
18096 get_data (NULL, filedata, conflicts_offset,
18097 sizeof (*econf64), conflictsno, _("conflict"));
a6e9f9df 18098 if (!econf64)
5a814d6d
AM
18099 {
18100 free (iconf);
18101 return FALSE;
18102 }
252b5132
RH
18103
18104 for (cnt = 0; cnt < conflictsno; ++cnt)
18105 iconf[cnt] = BYTE_GET (econf64[cnt]);
a6e9f9df
AM
18106
18107 free (econf64);
252b5132
RH
18108 }
18109
d3a49aa8
AM
18110 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
18111 "\nSection '.conflict' contains %lu entries:\n",
18112 (unsigned long) conflictsno),
c7e7ca54 18113 (unsigned long) conflictsno);
252b5132
RH
18114 puts (_(" Num: Index Value Name"));
18115
18116 for (cnt = 0; cnt < conflictsno; ++cnt)
18117 {
b34976b6 18118 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
e0a31db1 18119
978c4450 18120 if (iconf[cnt] >= filedata->num_dynamic_syms)
e0a31db1 18121 printf (_("<corrupt symbol index>"));
d79b3d50 18122 else
e0a31db1
NC
18123 {
18124 Elf_Internal_Sym * psym;
18125
978c4450 18126 psym = & filedata->dynamic_symbols[iconf[cnt]];
e0a31db1
NC
18127 print_vma (psym->st_value, FULL_HEX);
18128 putchar (' ');
978c4450
AM
18129 if (VALID_DYNAMIC_NAME (filedata, psym->st_name))
18130 print_symbol (25, GET_DYNAMIC_NAME (filedata, psym->st_name));
e0a31db1
NC
18131 else
18132 printf (_("<corrupt: %14ld>"), psym->st_name);
18133 }
31104126 18134 putchar ('\n');
252b5132
RH
18135 }
18136
252b5132
RH
18137 free (iconf);
18138 }
18139
ccb4c951
RS
18140 if (pltgot != 0 && local_gotno != 0)
18141 {
91d6fa6a 18142 bfd_vma ent, local_end, global_end;
bbeee7ea 18143 size_t i, offset;
2cf0635d 18144 unsigned char * data;
82b1b41b 18145 unsigned char * data_end;
bbeee7ea 18146 int addr_size;
ccb4c951 18147
91d6fa6a 18148 ent = pltgot;
ccb4c951
RS
18149 addr_size = (is_32bit_elf ? 4 : 8);
18150 local_end = pltgot + local_gotno * addr_size;
ccb4c951 18151
74e1a04b
NC
18152 /* PR binutils/17533 file: 012-111227-0.004 */
18153 if (symtabno < gotsym)
18154 {
18155 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
82b1b41b 18156 (unsigned long) gotsym, (unsigned long) symtabno);
32ec8896 18157 return FALSE;
74e1a04b 18158 }
82b1b41b 18159
74e1a04b 18160 global_end = local_end + (symtabno - gotsym) * addr_size;
82b1b41b
NC
18161 /* PR 17531: file: 54c91a34. */
18162 if (global_end < local_end)
18163 {
18164 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
32ec8896 18165 return FALSE;
82b1b41b 18166 }
948f632f 18167
dda8d76d
NC
18168 offset = offset_from_vma (filedata, pltgot, global_end - pltgot);
18169 data = (unsigned char *) get_data (NULL, filedata, offset,
9cf03b7e
NC
18170 global_end - pltgot, 1,
18171 _("Global Offset Table data"));
919383ac 18172 /* PR 12855: Null data is handled gracefully throughout. */
82b1b41b 18173 data_end = data + (global_end - pltgot);
59245841 18174
ccb4c951
RS
18175 printf (_("\nPrimary GOT:\n"));
18176 printf (_(" Canonical gp value: "));
18177 print_vma (pltgot + 0x7ff0, LONG_HEX);
18178 printf ("\n\n");
18179
18180 printf (_(" Reserved entries:\n"));
18181 printf (_(" %*s %10s %*s Purpose\n"),
2b692964
NC
18182 addr_size * 2, _("Address"), _("Access"),
18183 addr_size * 2, _("Initial"));
82b1b41b 18184 ent = print_mips_got_entry (data, pltgot, ent, data_end);
2b692964 18185 printf (_(" Lazy resolver\n"));
82b1b41b
NC
18186 if (ent == (bfd_vma) -1)
18187 goto got_print_fail;
75ec1fdb 18188
c4ab9505
MR
18189 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
18190 This entry will be used by some runtime loaders, to store the
18191 module pointer. Otherwise this is an ordinary local entry.
18192 PR 21344: Check for the entry being fully available before
18193 fetching it. */
18194 if (data
18195 && data + ent - pltgot + addr_size <= data_end
18196 && (byte_get (data + ent - pltgot, addr_size)
18197 >> (addr_size * 8 - 1)) != 0)
18198 {
18199 ent = print_mips_got_entry (data, pltgot, ent, data_end);
18200 printf (_(" Module pointer (GNU extension)\n"));
18201 if (ent == (bfd_vma) -1)
18202 goto got_print_fail;
ccb4c951
RS
18203 }
18204 printf ("\n");
18205
f17e9d8a 18206 if (data != NULL && ent < local_end)
ccb4c951
RS
18207 {
18208 printf (_(" Local entries:\n"));
cc5914eb 18209 printf (" %*s %10s %*s\n",
2b692964
NC
18210 addr_size * 2, _("Address"), _("Access"),
18211 addr_size * 2, _("Initial"));
91d6fa6a 18212 while (ent < local_end)
ccb4c951 18213 {
82b1b41b 18214 ent = print_mips_got_entry (data, pltgot, ent, data_end);
ccb4c951 18215 printf ("\n");
82b1b41b
NC
18216 if (ent == (bfd_vma) -1)
18217 goto got_print_fail;
ccb4c951
RS
18218 }
18219 printf ("\n");
18220 }
18221
f17e9d8a 18222 if (data != NULL && gotsym < symtabno)
ccb4c951
RS
18223 {
18224 int sym_width;
18225
18226 printf (_(" Global entries:\n"));
cc5914eb 18227 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
9cf03b7e
NC
18228 addr_size * 2, _("Address"),
18229 _("Access"),
2b692964 18230 addr_size * 2, _("Initial"),
9cf03b7e
NC
18231 addr_size * 2, _("Sym.Val."),
18232 _("Type"),
18233 /* Note for translators: "Ndx" = abbreviated form of "Index". */
18234 _("Ndx"), _("Name"));
0b4362b0 18235
ccb4c951 18236 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
e0a31db1 18237
ccb4c951
RS
18238 for (i = gotsym; i < symtabno; i++)
18239 {
82b1b41b 18240 ent = print_mips_got_entry (data, pltgot, ent, data_end);
ccb4c951 18241 printf (" ");
e0a31db1 18242
978c4450 18243 if (filedata->dynamic_symbols == NULL)
e0a31db1 18244 printf (_("<no dynamic symbols>"));
978c4450 18245 else if (i < filedata->num_dynamic_syms)
e0a31db1 18246 {
978c4450 18247 Elf_Internal_Sym * psym = filedata->dynamic_symbols + i;
e0a31db1
NC
18248
18249 print_vma (psym->st_value, LONG_HEX);
18250 printf (" %-7s %3s ",
dda8d76d
NC
18251 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
18252 get_symbol_index_type (filedata, psym->st_shndx));
e0a31db1 18253
978c4450
AM
18254 if (VALID_DYNAMIC_NAME (filedata, psym->st_name))
18255 print_symbol (sym_width,
18256 GET_DYNAMIC_NAME (filedata, psym->st_name));
e0a31db1
NC
18257 else
18258 printf (_("<corrupt: %14ld>"), psym->st_name);
18259 }
ccb4c951 18260 else
7fc5ac57
JBG
18261 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
18262 (unsigned long) i);
e0a31db1 18263
ccb4c951 18264 printf ("\n");
82b1b41b
NC
18265 if (ent == (bfd_vma) -1)
18266 break;
ccb4c951
RS
18267 }
18268 printf ("\n");
18269 }
18270
82b1b41b 18271 got_print_fail:
9db70fc3 18272 free (data);
ccb4c951
RS
18273 }
18274
861fb55a
DJ
18275 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
18276 {
91d6fa6a 18277 bfd_vma ent, end;
861fb55a
DJ
18278 size_t offset, rel_offset;
18279 unsigned long count, i;
2cf0635d 18280 unsigned char * data;
861fb55a 18281 int addr_size, sym_width;
2cf0635d 18282 Elf_Internal_Rela * rels;
861fb55a 18283
dda8d76d 18284 rel_offset = offset_from_vma (filedata, jmprel, pltrelsz);
861fb55a
DJ
18285 if (pltrel == DT_RELA)
18286 {
dda8d76d 18287 if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
32ec8896 18288 return FALSE;
861fb55a
DJ
18289 }
18290 else
18291 {
dda8d76d 18292 if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
32ec8896 18293 return FALSE;
861fb55a
DJ
18294 }
18295
91d6fa6a 18296 ent = mips_pltgot;
861fb55a
DJ
18297 addr_size = (is_32bit_elf ? 4 : 8);
18298 end = mips_pltgot + (2 + count) * addr_size;
18299
dda8d76d
NC
18300 offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot);
18301 data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot,
9cf03b7e 18302 1, _("Procedure Linkage Table data"));
59245841 18303 if (data == NULL)
288f0ba2
AM
18304 {
18305 free (rels);
18306 return FALSE;
18307 }
59245841 18308
9cf03b7e 18309 printf ("\nPLT GOT:\n\n");
861fb55a
DJ
18310 printf (_(" Reserved entries:\n"));
18311 printf (_(" %*s %*s Purpose\n"),
2b692964 18312 addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
91d6fa6a 18313 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
2b692964 18314 printf (_(" PLT lazy resolver\n"));
91d6fa6a 18315 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
2b692964 18316 printf (_(" Module pointer\n"));
861fb55a
DJ
18317 printf ("\n");
18318
18319 printf (_(" Entries:\n"));
cc5914eb 18320 printf (" %*s %*s %*s %-7s %3s %s\n",
2b692964
NC
18321 addr_size * 2, _("Address"),
18322 addr_size * 2, _("Initial"),
18323 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
861fb55a
DJ
18324 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
18325 for (i = 0; i < count; i++)
18326 {
df97ab2a 18327 unsigned long idx = get_reloc_symindex (rels[i].r_info);
861fb55a 18328
91d6fa6a 18329 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
861fb55a 18330 printf (" ");
e0a31db1 18331
978c4450 18332 if (idx >= filedata->num_dynamic_syms)
df97ab2a 18333 printf (_("<corrupt symbol index: %lu>"), idx);
861fb55a 18334 else
e0a31db1 18335 {
978c4450 18336 Elf_Internal_Sym * psym = filedata->dynamic_symbols + idx;
e0a31db1
NC
18337
18338 print_vma (psym->st_value, LONG_HEX);
18339 printf (" %-7s %3s ",
dda8d76d
NC
18340 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
18341 get_symbol_index_type (filedata, psym->st_shndx));
978c4450
AM
18342 if (VALID_DYNAMIC_NAME (filedata, psym->st_name))
18343 print_symbol (sym_width,
18344 GET_DYNAMIC_NAME (filedata, psym->st_name));
e0a31db1
NC
18345 else
18346 printf (_("<corrupt: %14ld>"), psym->st_name);
18347 }
861fb55a
DJ
18348 printf ("\n");
18349 }
18350 printf ("\n");
18351
9db70fc3 18352 free (data);
861fb55a
DJ
18353 free (rels);
18354 }
18355
32ec8896 18356 return res;
252b5132
RH
18357}
18358
32ec8896 18359static bfd_boolean
dda8d76d 18360process_nds32_specific (Filedata * filedata)
35c08157
KLC
18361{
18362 Elf_Internal_Shdr *sect = NULL;
18363
dda8d76d 18364 sect = find_section (filedata, ".nds32_e_flags");
9c7b8e9b 18365 if (sect != NULL && sect->sh_size >= 4)
35c08157 18366 {
9c7b8e9b
AM
18367 unsigned char *buf;
18368 unsigned int flag;
35c08157
KLC
18369
18370 printf ("\nNDS32 elf flags section:\n");
9c7b8e9b
AM
18371 buf = get_data (NULL, filedata, sect->sh_offset, 1, 4,
18372 _("NDS32 elf flags section"));
35c08157 18373
9c7b8e9b 18374 if (buf == NULL)
32ec8896
NC
18375 return FALSE;
18376
9c7b8e9b
AM
18377 flag = byte_get (buf, 4);
18378 free (buf);
18379 switch (flag & 0x3)
35c08157
KLC
18380 {
18381 case 0:
18382 printf ("(VEC_SIZE):\tNo entry.\n");
18383 break;
18384 case 1:
18385 printf ("(VEC_SIZE):\t4 bytes\n");
18386 break;
18387 case 2:
18388 printf ("(VEC_SIZE):\t16 bytes\n");
18389 break;
18390 case 3:
18391 printf ("(VEC_SIZE):\treserved\n");
18392 break;
18393 }
18394 }
18395
18396 return TRUE;
18397}
18398
32ec8896 18399static bfd_boolean
dda8d76d 18400process_gnu_liblist (Filedata * filedata)
047b2264 18401{
2cf0635d
NC
18402 Elf_Internal_Shdr * section;
18403 Elf_Internal_Shdr * string_sec;
18404 Elf32_External_Lib * elib;
18405 char * strtab;
c256ffe7 18406 size_t strtab_size;
047b2264 18407 size_t cnt;
d3a49aa8 18408 unsigned long num_liblist;
047b2264 18409 unsigned i;
32ec8896 18410 bfd_boolean res = TRUE;
047b2264
JJ
18411
18412 if (! do_arch)
32ec8896 18413 return TRUE;
047b2264 18414
dda8d76d
NC
18415 for (i = 0, section = filedata->section_headers;
18416 i < filedata->file_header.e_shnum;
b34976b6 18417 i++, section++)
047b2264
JJ
18418 {
18419 switch (section->sh_type)
18420 {
18421 case SHT_GNU_LIBLIST:
dda8d76d 18422 if (section->sh_link >= filedata->file_header.e_shnum)
c256ffe7
JJ
18423 break;
18424
3f5e193b 18425 elib = (Elf32_External_Lib *)
dda8d76d 18426 get_data (NULL, filedata, section->sh_offset, 1, section->sh_size,
9cf03b7e 18427 _("liblist section data"));
047b2264
JJ
18428
18429 if (elib == NULL)
32ec8896
NC
18430 {
18431 res = FALSE;
18432 break;
18433 }
047b2264 18434
dda8d76d
NC
18435 string_sec = filedata->section_headers + section->sh_link;
18436 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
3f5e193b
NC
18437 string_sec->sh_size,
18438 _("liblist string table"));
047b2264
JJ
18439 if (strtab == NULL
18440 || section->sh_entsize != sizeof (Elf32_External_Lib))
18441 {
18442 free (elib);
2842702f 18443 free (strtab);
32ec8896 18444 res = FALSE;
047b2264
JJ
18445 break;
18446 }
59245841 18447 strtab_size = string_sec->sh_size;
047b2264 18448
d3a49aa8
AM
18449 num_liblist = section->sh_size / sizeof (Elf32_External_Lib);
18450 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
18451 "\nLibrary list section '%s' contains %lu entries:\n",
18452 num_liblist),
dda8d76d 18453 printable_section_name (filedata, section),
d3a49aa8 18454 num_liblist);
047b2264 18455
2b692964 18456 puts (_(" Library Time Stamp Checksum Version Flags"));
047b2264
JJ
18457
18458 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
18459 ++cnt)
18460 {
18461 Elf32_Lib liblist;
91d6fa6a 18462 time_t atime;
d5b07ef4 18463 char timebuf[128];
2cf0635d 18464 struct tm * tmp;
047b2264
JJ
18465
18466 liblist.l_name = BYTE_GET (elib[cnt].l_name);
91d6fa6a 18467 atime = BYTE_GET (elib[cnt].l_time_stamp);
047b2264
JJ
18468 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
18469 liblist.l_version = BYTE_GET (elib[cnt].l_version);
18470 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
18471
91d6fa6a 18472 tmp = gmtime (&atime);
e9e44622
JJ
18473 snprintf (timebuf, sizeof (timebuf),
18474 "%04u-%02u-%02uT%02u:%02u:%02u",
18475 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
18476 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
047b2264
JJ
18477
18478 printf ("%3lu: ", (unsigned long) cnt);
18479 if (do_wide)
c256ffe7 18480 printf ("%-20s", liblist.l_name < strtab_size
2b692964 18481 ? strtab + liblist.l_name : _("<corrupt>"));
047b2264 18482 else
c256ffe7 18483 printf ("%-20.20s", liblist.l_name < strtab_size
2b692964 18484 ? strtab + liblist.l_name : _("<corrupt>"));
047b2264
JJ
18485 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
18486 liblist.l_version, liblist.l_flags);
18487 }
18488
18489 free (elib);
2842702f 18490 free (strtab);
047b2264
JJ
18491 }
18492 }
18493
32ec8896 18494 return res;
047b2264
JJ
18495}
18496
9437c45b 18497static const char *
dda8d76d 18498get_note_type (Filedata * filedata, unsigned e_type)
779fe533
NC
18499{
18500 static char buff[64];
103f02d3 18501
dda8d76d 18502 if (filedata->file_header.e_type == ET_CORE)
1ec5cd37
NC
18503 switch (e_type)
18504 {
57346661 18505 case NT_AUXV:
1ec5cd37 18506 return _("NT_AUXV (auxiliary vector)");
57346661 18507 case NT_PRSTATUS:
1ec5cd37 18508 return _("NT_PRSTATUS (prstatus structure)");
57346661 18509 case NT_FPREGSET:
1ec5cd37 18510 return _("NT_FPREGSET (floating point registers)");
57346661 18511 case NT_PRPSINFO:
1ec5cd37 18512 return _("NT_PRPSINFO (prpsinfo structure)");
57346661 18513 case NT_TASKSTRUCT:
1ec5cd37 18514 return _("NT_TASKSTRUCT (task structure)");
b63a5e38
AB
18515 case NT_GDB_TDESC:
18516 return _("NT_GDB_TDESC (GDB XML target description)");
57346661 18517 case NT_PRXFPREG:
1ec5cd37 18518 return _("NT_PRXFPREG (user_xfpregs structure)");
e1e95dec
AM
18519 case NT_PPC_VMX:
18520 return _("NT_PPC_VMX (ppc Altivec registers)");
89eeb0bc
LM
18521 case NT_PPC_VSX:
18522 return _("NT_PPC_VSX (ppc VSX registers)");
66c3b5f8
GR
18523 case NT_PPC_TAR:
18524 return _("NT_PPC_TAR (ppc TAR register)");
18525 case NT_PPC_PPR:
18526 return _("NT_PPC_PPR (ppc PPR register)");
18527 case NT_PPC_DSCR:
18528 return _("NT_PPC_DSCR (ppc DSCR register)");
18529 case NT_PPC_EBB:
18530 return _("NT_PPC_EBB (ppc EBB registers)");
18531 case NT_PPC_PMU:
18532 return _("NT_PPC_PMU (ppc PMU registers)");
18533 case NT_PPC_TM_CGPR:
18534 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
18535 case NT_PPC_TM_CFPR:
18536 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
18537 case NT_PPC_TM_CVMX:
18538 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
18539 case NT_PPC_TM_CVSX:
3fd21718 18540 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
66c3b5f8
GR
18541 case NT_PPC_TM_SPR:
18542 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
18543 case NT_PPC_TM_CTAR:
18544 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
18545 case NT_PPC_TM_CPPR:
18546 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
18547 case NT_PPC_TM_CDSCR:
18548 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
ff826ef3
TT
18549 case NT_386_TLS:
18550 return _("NT_386_TLS (x86 TLS information)");
18551 case NT_386_IOPERM:
18552 return _("NT_386_IOPERM (x86 I/O permissions)");
4339cae0
L
18553 case NT_X86_XSTATE:
18554 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
8d58ed37
L
18555 case NT_X86_CET:
18556 return _("NT_X86_CET (x86 CET state)");
0675e188
UW
18557 case NT_S390_HIGH_GPRS:
18558 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
d7eeb400
MS
18559 case NT_S390_TIMER:
18560 return _("NT_S390_TIMER (s390 timer register)");
18561 case NT_S390_TODCMP:
18562 return _("NT_S390_TODCMP (s390 TOD comparator register)");
18563 case NT_S390_TODPREG:
18564 return _("NT_S390_TODPREG (s390 TOD programmable register)");
18565 case NT_S390_CTRS:
18566 return _("NT_S390_CTRS (s390 control registers)");
18567 case NT_S390_PREFIX:
18568 return _("NT_S390_PREFIX (s390 prefix register)");
a367d729
AK
18569 case NT_S390_LAST_BREAK:
18570 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
18571 case NT_S390_SYSTEM_CALL:
18572 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
abb3f6cc
NC
18573 case NT_S390_TDB:
18574 return _("NT_S390_TDB (s390 transaction diagnostic block)");
4ef9f41a
AA
18575 case NT_S390_VXRS_LOW:
18576 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
18577 case NT_S390_VXRS_HIGH:
18578 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
88ab90e8
AA
18579 case NT_S390_GS_CB:
18580 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
18581 case NT_S390_GS_BC:
18582 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
faa9a424
UW
18583 case NT_ARM_VFP:
18584 return _("NT_ARM_VFP (arm VFP registers)");
652451f8
YZ
18585 case NT_ARM_TLS:
18586 return _("NT_ARM_TLS (AArch TLS registers)");
18587 case NT_ARM_HW_BREAK:
18588 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
18589 case NT_ARM_HW_WATCH:
18590 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
27456742
AK
18591 case NT_ARC_V2:
18592 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
db6092f3
AB
18593 case NT_RISCV_CSR:
18594 return _("NT_RISCV_CSR (RISC-V control and status registers)");
57346661 18595 case NT_PSTATUS:
1ec5cd37 18596 return _("NT_PSTATUS (pstatus structure)");
57346661 18597 case NT_FPREGS:
1ec5cd37 18598 return _("NT_FPREGS (floating point registers)");
57346661 18599 case NT_PSINFO:
1ec5cd37 18600 return _("NT_PSINFO (psinfo structure)");
57346661 18601 case NT_LWPSTATUS:
1ec5cd37 18602 return _("NT_LWPSTATUS (lwpstatus_t structure)");
57346661 18603 case NT_LWPSINFO:
1ec5cd37 18604 return _("NT_LWPSINFO (lwpsinfo_t structure)");
57346661 18605 case NT_WIN32PSTATUS:
1ec5cd37 18606 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9ece1fa9
TT
18607 case NT_SIGINFO:
18608 return _("NT_SIGINFO (siginfo_t data)");
18609 case NT_FILE:
18610 return _("NT_FILE (mapped files)");
1ec5cd37
NC
18611 default:
18612 break;
18613 }
18614 else
18615 switch (e_type)
18616 {
18617 case NT_VERSION:
18618 return _("NT_VERSION (version)");
18619 case NT_ARCH:
18620 return _("NT_ARCH (architecture)");
9ef920e9 18621 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
6f156d7a 18622 return _("OPEN");
9ef920e9 18623 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
6f156d7a 18624 return _("func");
1ec5cd37
NC
18625 default:
18626 break;
18627 }
18628
e9e44622 18629 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
1ec5cd37 18630 return buff;
779fe533
NC
18631}
18632
32ec8896 18633static bfd_boolean
9ece1fa9
TT
18634print_core_note (Elf_Internal_Note *pnote)
18635{
18636 unsigned int addr_size = is_32bit_elf ? 4 : 8;
18637 bfd_vma count, page_size;
18638 unsigned char *descdata, *filenames, *descend;
18639
18640 if (pnote->type != NT_FILE)
04ac15ab
AS
18641 {
18642 if (do_wide)
18643 printf ("\n");
18644 return TRUE;
18645 }
9ece1fa9
TT
18646
18647#ifndef BFD64
18648 if (!is_32bit_elf)
18649 {
18650 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
18651 /* Still "successful". */
32ec8896 18652 return TRUE;
9ece1fa9
TT
18653 }
18654#endif
18655
18656 if (pnote->descsz < 2 * addr_size)
18657 {
32ec8896
NC
18658 error (_(" Malformed note - too short for header\n"));
18659 return FALSE;
9ece1fa9
TT
18660 }
18661
18662 descdata = (unsigned char *) pnote->descdata;
18663 descend = descdata + pnote->descsz;
18664
18665 if (descdata[pnote->descsz - 1] != '\0')
18666 {
32ec8896
NC
18667 error (_(" Malformed note - does not end with \\0\n"));
18668 return FALSE;
9ece1fa9
TT
18669 }
18670
18671 count = byte_get (descdata, addr_size);
18672 descdata += addr_size;
18673
18674 page_size = byte_get (descdata, addr_size);
18675 descdata += addr_size;
18676
5396a86e
AM
18677 if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size)
18678 || pnote->descsz < 2 * addr_size + count * 3 * addr_size)
9ece1fa9 18679 {
32ec8896
NC
18680 error (_(" Malformed note - too short for supplied file count\n"));
18681 return FALSE;
9ece1fa9
TT
18682 }
18683
18684 printf (_(" Page size: "));
18685 print_vma (page_size, DEC);
18686 printf ("\n");
18687
18688 printf (_(" %*s%*s%*s\n"),
18689 (int) (2 + 2 * addr_size), _("Start"),
18690 (int) (4 + 2 * addr_size), _("End"),
18691 (int) (4 + 2 * addr_size), _("Page Offset"));
18692 filenames = descdata + count * 3 * addr_size;
595712bb 18693 while (count-- > 0)
9ece1fa9
TT
18694 {
18695 bfd_vma start, end, file_ofs;
18696
18697 if (filenames == descend)
18698 {
32ec8896
NC
18699 error (_(" Malformed note - filenames end too early\n"));
18700 return FALSE;
9ece1fa9
TT
18701 }
18702
18703 start = byte_get (descdata, addr_size);
18704 descdata += addr_size;
18705 end = byte_get (descdata, addr_size);
18706 descdata += addr_size;
18707 file_ofs = byte_get (descdata, addr_size);
18708 descdata += addr_size;
18709
18710 printf (" ");
18711 print_vma (start, FULL_HEX);
18712 printf (" ");
18713 print_vma (end, FULL_HEX);
18714 printf (" ");
18715 print_vma (file_ofs, FULL_HEX);
18716 printf ("\n %s\n", filenames);
18717
18718 filenames += 1 + strlen ((char *) filenames);
18719 }
18720
32ec8896 18721 return TRUE;
9ece1fa9
TT
18722}
18723
1118d252
RM
18724static const char *
18725get_gnu_elf_note_type (unsigned e_type)
18726{
1449284b 18727 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
1118d252
RM
18728 switch (e_type)
18729 {
18730 case NT_GNU_ABI_TAG:
18731 return _("NT_GNU_ABI_TAG (ABI version tag)");
18732 case NT_GNU_HWCAP:
18733 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
18734 case NT_GNU_BUILD_ID:
18735 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
0297aed6
DM
18736 case NT_GNU_GOLD_VERSION:
18737 return _("NT_GNU_GOLD_VERSION (gold version)");
9ef920e9
NC
18738 case NT_GNU_PROPERTY_TYPE_0:
18739 return _("NT_GNU_PROPERTY_TYPE_0");
18740 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
18741 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
18742 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
18743 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
1118d252 18744 default:
1449284b
NC
18745 {
18746 static char buff[64];
1118d252 18747
1449284b
NC
18748 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18749 return buff;
18750 }
18751 }
1118d252
RM
18752}
18753
a9eafb08
L
18754static void
18755decode_x86_compat_isa (unsigned int bitmask)
18756{
18757 while (bitmask)
18758 {
18759 unsigned int bit = bitmask & (- bitmask);
18760
18761 bitmask &= ~ bit;
18762 switch (bit)
18763 {
18764 case GNU_PROPERTY_X86_COMPAT_ISA_1_486:
18765 printf ("i486");
18766 break;
18767 case GNU_PROPERTY_X86_COMPAT_ISA_1_586:
18768 printf ("586");
18769 break;
18770 case GNU_PROPERTY_X86_COMPAT_ISA_1_686:
18771 printf ("686");
18772 break;
18773 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE:
18774 printf ("SSE");
18775 break;
18776 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2:
18777 printf ("SSE2");
18778 break;
18779 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3:
18780 printf ("SSE3");
18781 break;
18782 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3:
18783 printf ("SSSE3");
18784 break;
18785 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1:
18786 printf ("SSE4_1");
18787 break;
18788 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2:
18789 printf ("SSE4_2");
18790 break;
18791 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX:
18792 printf ("AVX");
18793 break;
18794 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2:
18795 printf ("AVX2");
18796 break;
18797 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F:
18798 printf ("AVX512F");
18799 break;
18800 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD:
18801 printf ("AVX512CD");
18802 break;
18803 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER:
18804 printf ("AVX512ER");
18805 break;
18806 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF:
18807 printf ("AVX512PF");
18808 break;
18809 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL:
18810 printf ("AVX512VL");
18811 break;
18812 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ:
18813 printf ("AVX512DQ");
18814 break;
18815 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW:
18816 printf ("AVX512BW");
18817 break;
65b3d26e
L
18818 default:
18819 printf (_("<unknown: %x>"), bit);
18820 break;
a9eafb08
L
18821 }
18822 if (bitmask)
18823 printf (", ");
18824 }
18825}
18826
9ef920e9 18827static void
32930e4e 18828decode_x86_compat_2_isa (unsigned int bitmask)
9ef920e9 18829{
0a59decb 18830 if (!bitmask)
90c745dc
L
18831 {
18832 printf (_("<None>"));
18833 return;
18834 }
90c745dc 18835
9ef920e9
NC
18836 while (bitmask)
18837 {
1fc87489 18838 unsigned int bit = bitmask & (- bitmask);
9ef920e9
NC
18839
18840 bitmask &= ~ bit;
18841 switch (bit)
18842 {
32930e4e 18843 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV:
a9eafb08
L
18844 printf ("CMOV");
18845 break;
32930e4e 18846 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE:
a9eafb08
L
18847 printf ("SSE");
18848 break;
32930e4e 18849 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2:
a9eafb08
L
18850 printf ("SSE2");
18851 break;
32930e4e 18852 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3:
a9eafb08
L
18853 printf ("SSE3");
18854 break;
32930e4e 18855 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3:
a9eafb08
L
18856 printf ("SSSE3");
18857 break;
32930e4e 18858 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1:
a9eafb08
L
18859 printf ("SSE4_1");
18860 break;
32930e4e 18861 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2:
a9eafb08
L
18862 printf ("SSE4_2");
18863 break;
32930e4e 18864 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX:
a9eafb08
L
18865 printf ("AVX");
18866 break;
32930e4e 18867 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2:
a9eafb08
L
18868 printf ("AVX2");
18869 break;
32930e4e 18870 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA:
a9eafb08
L
18871 printf ("FMA");
18872 break;
32930e4e 18873 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F:
a9eafb08
L
18874 printf ("AVX512F");
18875 break;
32930e4e 18876 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD:
a9eafb08
L
18877 printf ("AVX512CD");
18878 break;
32930e4e 18879 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER:
a9eafb08
L
18880 printf ("AVX512ER");
18881 break;
32930e4e 18882 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF:
a9eafb08
L
18883 printf ("AVX512PF");
18884 break;
32930e4e 18885 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL:
a9eafb08
L
18886 printf ("AVX512VL");
18887 break;
32930e4e 18888 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ:
a9eafb08
L
18889 printf ("AVX512DQ");
18890 break;
32930e4e 18891 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW:
a9eafb08
L
18892 printf ("AVX512BW");
18893 break;
32930e4e 18894 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS:
a9eafb08
L
18895 printf ("AVX512_4FMAPS");
18896 break;
32930e4e 18897 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW:
a9eafb08
L
18898 printf ("AVX512_4VNNIW");
18899 break;
32930e4e 18900 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG:
a9eafb08
L
18901 printf ("AVX512_BITALG");
18902 break;
32930e4e 18903 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA:
a9eafb08
L
18904 printf ("AVX512_IFMA");
18905 break;
32930e4e 18906 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI:
a9eafb08
L
18907 printf ("AVX512_VBMI");
18908 break;
32930e4e 18909 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2:
a9eafb08
L
18910 printf ("AVX512_VBMI2");
18911 break;
32930e4e 18912 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI:
a9eafb08
L
18913 printf ("AVX512_VNNI");
18914 break;
32930e4e 18915 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16:
462cac58
L
18916 printf ("AVX512_BF16");
18917 break;
65b3d26e
L
18918 default:
18919 printf (_("<unknown: %x>"), bit);
18920 break;
9ef920e9
NC
18921 }
18922 if (bitmask)
18923 printf (", ");
18924 }
18925}
18926
32930e4e
L
18927static void
18928decode_x86_isa (unsigned int bitmask)
18929{
32930e4e
L
18930 while (bitmask)
18931 {
18932 unsigned int bit = bitmask & (- bitmask);
18933
18934 bitmask &= ~ bit;
18935 switch (bit)
18936 {
b0ab0693
L
18937 case GNU_PROPERTY_X86_ISA_1_BASELINE:
18938 printf ("x86-64-baseline");
18939 break;
32930e4e
L
18940 case GNU_PROPERTY_X86_ISA_1_V2:
18941 printf ("x86-64-v2");
18942 break;
18943 case GNU_PROPERTY_X86_ISA_1_V3:
18944 printf ("x86-64-v3");
18945 break;
18946 case GNU_PROPERTY_X86_ISA_1_V4:
18947 printf ("x86-64-v4");
18948 break;
18949 default:
18950 printf (_("<unknown: %x>"), bit);
18951 break;
18952 }
18953 if (bitmask)
18954 printf (", ");
18955 }
18956}
18957
ee2fdd6f 18958static void
a9eafb08 18959decode_x86_feature_1 (unsigned int bitmask)
ee2fdd6f 18960{
0a59decb 18961 if (!bitmask)
90c745dc
L
18962 {
18963 printf (_("<None>"));
18964 return;
18965 }
90c745dc 18966
ee2fdd6f
L
18967 while (bitmask)
18968 {
18969 unsigned int bit = bitmask & (- bitmask);
18970
18971 bitmask &= ~ bit;
18972 switch (bit)
18973 {
18974 case GNU_PROPERTY_X86_FEATURE_1_IBT:
a9eafb08 18975 printf ("IBT");
ee2fdd6f 18976 break;
48580982 18977 case GNU_PROPERTY_X86_FEATURE_1_SHSTK:
a9eafb08 18978 printf ("SHSTK");
48580982 18979 break;
279d901e
L
18980 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48:
18981 printf ("LAM_U48");
18982 break;
18983 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57:
18984 printf ("LAM_U57");
18985 break;
ee2fdd6f
L
18986 default:
18987 printf (_("<unknown: %x>"), bit);
18988 break;
18989 }
18990 if (bitmask)
18991 printf (", ");
18992 }
18993}
18994
a9eafb08
L
18995static void
18996decode_x86_feature_2 (unsigned int bitmask)
18997{
0a59decb 18998 if (!bitmask)
90c745dc
L
18999 {
19000 printf (_("<None>"));
19001 return;
19002 }
90c745dc 19003
a9eafb08
L
19004 while (bitmask)
19005 {
19006 unsigned int bit = bitmask & (- bitmask);
19007
19008 bitmask &= ~ bit;
19009 switch (bit)
19010 {
19011 case GNU_PROPERTY_X86_FEATURE_2_X86:
19012 printf ("x86");
19013 break;
19014 case GNU_PROPERTY_X86_FEATURE_2_X87:
19015 printf ("x87");
19016 break;
19017 case GNU_PROPERTY_X86_FEATURE_2_MMX:
19018 printf ("MMX");
19019 break;
19020 case GNU_PROPERTY_X86_FEATURE_2_XMM:
19021 printf ("XMM");
19022 break;
19023 case GNU_PROPERTY_X86_FEATURE_2_YMM:
19024 printf ("YMM");
19025 break;
19026 case GNU_PROPERTY_X86_FEATURE_2_ZMM:
19027 printf ("ZMM");
19028 break;
a308b89d
L
19029 case GNU_PROPERTY_X86_FEATURE_2_TMM:
19030 printf ("TMM");
19031 break;
32930e4e
L
19032 case GNU_PROPERTY_X86_FEATURE_2_MASK:
19033 printf ("MASK");
19034 break;
a9eafb08
L
19035 case GNU_PROPERTY_X86_FEATURE_2_FXSR:
19036 printf ("FXSR");
19037 break;
19038 case GNU_PROPERTY_X86_FEATURE_2_XSAVE:
19039 printf ("XSAVE");
19040 break;
19041 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT:
19042 printf ("XSAVEOPT");
19043 break;
19044 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC:
19045 printf ("XSAVEC");
19046 break;
65b3d26e
L
19047 default:
19048 printf (_("<unknown: %x>"), bit);
19049 break;
a9eafb08
L
19050 }
19051 if (bitmask)
19052 printf (", ");
19053 }
19054}
19055
cd702818
SD
19056static void
19057decode_aarch64_feature_1_and (unsigned int bitmask)
19058{
19059 while (bitmask)
19060 {
19061 unsigned int bit = bitmask & (- bitmask);
19062
19063 bitmask &= ~ bit;
19064 switch (bit)
19065 {
19066 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI:
19067 printf ("BTI");
19068 break;
19069
19070 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC:
19071 printf ("PAC");
19072 break;
19073
19074 default:
19075 printf (_("<unknown: %x>"), bit);
19076 break;
19077 }
19078 if (bitmask)
19079 printf (", ");
19080 }
19081}
19082
9ef920e9 19083static void
dda8d76d 19084print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
9ef920e9
NC
19085{
19086 unsigned char * ptr = (unsigned char *) pnote->descdata;
19087 unsigned char * ptr_end = ptr + pnote->descsz;
19088 unsigned int size = is_32bit_elf ? 4 : 8;
19089
19090 printf (_(" Properties: "));
19091
1fc87489 19092 if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
9ef920e9
NC
19093 {
19094 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
19095 return;
19096 }
19097
6ab2c4ed 19098 while (ptr < ptr_end)
9ef920e9 19099 {
1fc87489 19100 unsigned int j;
6ab2c4ed
MC
19101 unsigned int type;
19102 unsigned int datasz;
19103
19104 if ((size_t) (ptr_end - ptr) < 8)
19105 {
19106 printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
19107 break;
19108 }
19109
19110 type = byte_get (ptr, 4);
19111 datasz = byte_get (ptr + 4, 4);
9ef920e9 19112
1fc87489 19113 ptr += 8;
9ef920e9 19114
6ab2c4ed 19115 if (datasz > (size_t) (ptr_end - ptr))
9ef920e9 19116 {
1fc87489
L
19117 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
19118 type, datasz);
9ef920e9 19119 break;
1fc87489 19120 }
9ef920e9 19121
1fc87489
L
19122 if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
19123 {
dda8d76d
NC
19124 if (filedata->file_header.e_machine == EM_X86_64
19125 || filedata->file_header.e_machine == EM_IAMCU
19126 || filedata->file_header.e_machine == EM_386)
1fc87489 19127 {
aa7bca9b
L
19128 unsigned int bitmask;
19129
19130 if (datasz == 4)
0a59decb 19131 bitmask = byte_get (ptr, 4);
aa7bca9b
L
19132 else
19133 bitmask = 0;
19134
1fc87489
L
19135 switch (type)
19136 {
19137 case GNU_PROPERTY_X86_ISA_1_USED:
1fc87489 19138 if (datasz != 4)
aa7bca9b
L
19139 printf (_("x86 ISA used: <corrupt length: %#x> "),
19140 datasz);
1fc87489 19141 else
aa7bca9b
L
19142 {
19143 printf ("x86 ISA used: ");
19144 decode_x86_isa (bitmask);
19145 }
1fc87489 19146 goto next;
9ef920e9 19147
1fc87489 19148 case GNU_PROPERTY_X86_ISA_1_NEEDED:
1fc87489 19149 if (datasz != 4)
aa7bca9b
L
19150 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19151 datasz);
1fc87489 19152 else
aa7bca9b
L
19153 {
19154 printf ("x86 ISA needed: ");
19155 decode_x86_isa (bitmask);
19156 }
1fc87489 19157 goto next;
9ef920e9 19158
ee2fdd6f 19159 case GNU_PROPERTY_X86_FEATURE_1_AND:
ee2fdd6f 19160 if (datasz != 4)
aa7bca9b
L
19161 printf (_("x86 feature: <corrupt length: %#x> "),
19162 datasz);
ee2fdd6f 19163 else
aa7bca9b
L
19164 {
19165 printf ("x86 feature: ");
a9eafb08
L
19166 decode_x86_feature_1 (bitmask);
19167 }
19168 goto next;
19169
19170 case GNU_PROPERTY_X86_FEATURE_2_USED:
19171 if (datasz != 4)
19172 printf (_("x86 feature used: <corrupt length: %#x> "),
19173 datasz);
19174 else
19175 {
19176 printf ("x86 feature used: ");
19177 decode_x86_feature_2 (bitmask);
19178 }
19179 goto next;
19180
19181 case GNU_PROPERTY_X86_FEATURE_2_NEEDED:
19182 if (datasz != 4)
19183 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz);
19184 else
19185 {
19186 printf ("x86 feature needed: ");
19187 decode_x86_feature_2 (bitmask);
19188 }
19189 goto next;
19190
19191 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
19192 if (datasz != 4)
19193 printf (_("x86 ISA used: <corrupt length: %#x> "),
19194 datasz);
19195 else
19196 {
19197 printf ("x86 ISA used: ");
19198 decode_x86_compat_isa (bitmask);
19199 }
19200 goto next;
19201
19202 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
19203 if (datasz != 4)
19204 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19205 datasz);
19206 else
19207 {
19208 printf ("x86 ISA needed: ");
19209 decode_x86_compat_isa (bitmask);
aa7bca9b 19210 }
ee2fdd6f
L
19211 goto next;
19212
32930e4e
L
19213 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED:
19214 if (datasz != 4)
19215 printf (_("x86 ISA used: <corrupt length: %#x> "),
19216 datasz);
19217 else
19218 {
19219 printf ("x86 ISA used: ");
19220 decode_x86_compat_2_isa (bitmask);
19221 }
19222 goto next;
19223
19224 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED:
19225 if (datasz != 4)
19226 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19227 datasz);
19228 else
19229 {
19230 printf ("x86 ISA needed: ");
19231 decode_x86_compat_2_isa (bitmask);
19232 }
19233 goto next;
19234
1fc87489
L
19235 default:
19236 break;
19237 }
19238 }
cd702818
SD
19239 else if (filedata->file_header.e_machine == EM_AARCH64)
19240 {
19241 if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
19242 {
19243 printf ("AArch64 feature: ");
19244 if (datasz != 4)
19245 printf (_("<corrupt length: %#x> "), datasz);
19246 else
19247 decode_aarch64_feature_1_and (byte_get (ptr, 4));
19248 goto next;
19249 }
19250 }
1fc87489
L
19251 }
19252 else
19253 {
19254 switch (type)
9ef920e9 19255 {
1fc87489
L
19256 case GNU_PROPERTY_STACK_SIZE:
19257 printf (_("stack size: "));
19258 if (datasz != size)
19259 printf (_("<corrupt length: %#x> "), datasz);
19260 else
19261 printf ("%#lx", (unsigned long) byte_get (ptr, size));
19262 goto next;
19263
19264 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
19265 printf ("no copy on protected ");
19266 if (datasz)
19267 printf (_("<corrupt length: %#x> "), datasz);
19268 goto next;
19269
19270 default:
9ef920e9
NC
19271 break;
19272 }
9ef920e9
NC
19273 }
19274
1fc87489
L
19275 if (type < GNU_PROPERTY_LOPROC)
19276 printf (_("<unknown type %#x data: "), type);
19277 else if (type < GNU_PROPERTY_LOUSER)
8c3853d9 19278 printf (_("<processor-specific type %#x data: "), type);
1fc87489
L
19279 else
19280 printf (_("<application-specific type %#x data: "), type);
19281 for (j = 0; j < datasz; ++j)
19282 printf ("%02x ", ptr[j] & 0xff);
19283 printf (">");
19284
dc1e8a47 19285 next:
9ef920e9 19286 ptr += ((datasz + (size - 1)) & ~ (size - 1));
1fc87489
L
19287 if (ptr == ptr_end)
19288 break;
1fc87489 19289
6ab2c4ed
MC
19290 if (do_wide)
19291 printf (", ");
19292 else
19293 printf ("\n\t");
9ef920e9
NC
19294 }
19295
19296 printf ("\n");
19297}
19298
32ec8896 19299static bfd_boolean
dda8d76d 19300print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote)
664f90a3 19301{
1449284b 19302 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
664f90a3
TT
19303 switch (pnote->type)
19304 {
19305 case NT_GNU_BUILD_ID:
19306 {
19307 unsigned long i;
19308
19309 printf (_(" Build ID: "));
19310 for (i = 0; i < pnote->descsz; ++i)
19311 printf ("%02x", pnote->descdata[i] & 0xff);
9cf03b7e 19312 printf ("\n");
664f90a3
TT
19313 }
19314 break;
19315
19316 case NT_GNU_ABI_TAG:
19317 {
19318 unsigned long os, major, minor, subminor;
19319 const char *osname;
19320
3102e897
NC
19321 /* PR 17531: file: 030-599401-0.004. */
19322 if (pnote->descsz < 16)
19323 {
19324 printf (_(" <corrupt GNU_ABI_TAG>\n"));
19325 break;
19326 }
19327
664f90a3
TT
19328 os = byte_get ((unsigned char *) pnote->descdata, 4);
19329 major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
19330 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
19331 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
19332
19333 switch (os)
19334 {
19335 case GNU_ABI_TAG_LINUX:
19336 osname = "Linux";
19337 break;
19338 case GNU_ABI_TAG_HURD:
19339 osname = "Hurd";
19340 break;
19341 case GNU_ABI_TAG_SOLARIS:
19342 osname = "Solaris";
19343 break;
19344 case GNU_ABI_TAG_FREEBSD:
19345 osname = "FreeBSD";
19346 break;
19347 case GNU_ABI_TAG_NETBSD:
19348 osname = "NetBSD";
19349 break;
14ae95f2
RM
19350 case GNU_ABI_TAG_SYLLABLE:
19351 osname = "Syllable";
19352 break;
19353 case GNU_ABI_TAG_NACL:
19354 osname = "NaCl";
19355 break;
664f90a3
TT
19356 default:
19357 osname = "Unknown";
19358 break;
19359 }
19360
19361 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
19362 major, minor, subminor);
19363 }
19364 break;
926c5385
CC
19365
19366 case NT_GNU_GOLD_VERSION:
19367 {
19368 unsigned long i;
19369
19370 printf (_(" Version: "));
19371 for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
19372 printf ("%c", pnote->descdata[i]);
19373 printf ("\n");
19374 }
19375 break;
1449284b
NC
19376
19377 case NT_GNU_HWCAP:
19378 {
19379 unsigned long num_entries, mask;
19380
19381 /* Hardware capabilities information. Word 0 is the number of entries.
19382 Word 1 is a bitmask of enabled entries. The rest of the descriptor
19383 is a series of entries, where each entry is a single byte followed
19384 by a nul terminated string. The byte gives the bit number to test
19385 if enabled in the bitmask. */
19386 printf (_(" Hardware Capabilities: "));
19387 if (pnote->descsz < 8)
19388 {
32ec8896
NC
19389 error (_("<corrupt GNU_HWCAP>\n"));
19390 return FALSE;
1449284b
NC
19391 }
19392 num_entries = byte_get ((unsigned char *) pnote->descdata, 4);
19393 mask = byte_get ((unsigned char *) pnote->descdata + 4, 4);
19394 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask);
19395 /* FIXME: Add code to display the entries... */
19396 }
19397 break;
19398
9ef920e9 19399 case NT_GNU_PROPERTY_TYPE_0:
dda8d76d 19400 print_gnu_property_note (filedata, pnote);
9ef920e9 19401 break;
9abca702 19402
1449284b
NC
19403 default:
19404 /* Handle unrecognised types. An error message should have already been
19405 created by get_gnu_elf_note_type(), so all that we need to do is to
19406 display the data. */
19407 {
19408 unsigned long i;
19409
19410 printf (_(" Description data: "));
19411 for (i = 0; i < pnote->descsz; ++i)
19412 printf ("%02x ", pnote->descdata[i] & 0xff);
19413 printf ("\n");
19414 }
19415 break;
664f90a3
TT
19416 }
19417
32ec8896 19418 return TRUE;
664f90a3
TT
19419}
19420
685080f2
NC
19421static const char *
19422get_v850_elf_note_type (enum v850_notes n_type)
19423{
19424 static char buff[64];
19425
19426 switch (n_type)
19427 {
19428 case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects");
19429 case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double");
19430 case V850_NOTE_FPU_INFO: return _("Type of FPU support needed");
19431 case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions");
19432 case V850_NOTE_CACHE_INFO: return _("Use of cache");
19433 case V850_NOTE_MMU_INFO: return _("Use of MMU");
19434 default:
19435 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
19436 return buff;
19437 }
19438}
19439
32ec8896 19440static bfd_boolean
685080f2
NC
19441print_v850_note (Elf_Internal_Note * pnote)
19442{
19443 unsigned int val;
19444
19445 if (pnote->descsz != 4)
32ec8896
NC
19446 return FALSE;
19447
685080f2
NC
19448 val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
19449
19450 if (val == 0)
19451 {
19452 printf (_("not set\n"));
32ec8896 19453 return TRUE;
685080f2
NC
19454 }
19455
19456 switch (pnote->type)
19457 {
19458 case V850_NOTE_ALIGNMENT:
19459 switch (val)
19460 {
32ec8896
NC
19461 case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE;
19462 case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE;
685080f2
NC
19463 }
19464 break;
14ae95f2 19465
685080f2
NC
19466 case V850_NOTE_DATA_SIZE:
19467 switch (val)
19468 {
32ec8896
NC
19469 case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE;
19470 case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE;
685080f2
NC
19471 }
19472 break;
14ae95f2 19473
685080f2
NC
19474 case V850_NOTE_FPU_INFO:
19475 switch (val)
19476 {
32ec8896
NC
19477 case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE;
19478 case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE;
685080f2
NC
19479 }
19480 break;
14ae95f2 19481
685080f2
NC
19482 case V850_NOTE_MMU_INFO:
19483 case V850_NOTE_CACHE_INFO:
19484 case V850_NOTE_SIMD_INFO:
19485 if (val == EF_RH850_SIMD)
19486 {
19487 printf (_("yes\n"));
32ec8896 19488 return TRUE;
685080f2
NC
19489 }
19490 break;
19491
19492 default:
19493 /* An 'unknown note type' message will already have been displayed. */
19494 break;
19495 }
19496
19497 printf (_("unknown value: %x\n"), val);
32ec8896 19498 return FALSE;
685080f2
NC
19499}
19500
32ec8896 19501static bfd_boolean
c6056a74
SF
19502process_netbsd_elf_note (Elf_Internal_Note * pnote)
19503{
19504 unsigned int version;
19505
19506 switch (pnote->type)
19507 {
19508 case NT_NETBSD_IDENT:
b966f55f
AM
19509 if (pnote->descsz < 1)
19510 break;
c6056a74
SF
19511 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
19512 if ((version / 10000) % 100)
b966f55f 19513 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
c6056a74
SF
19514 version, version / 100000000, (version / 1000000) % 100,
19515 (version / 10000) % 100 > 26 ? "Z" : "",
15f205b1 19516 'A' + (version / 10000) % 26);
c6056a74
SF
19517 else
19518 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
b966f55f 19519 version, version / 100000000, (version / 1000000) % 100,
15f205b1 19520 (version / 100) % 100);
32ec8896 19521 return TRUE;
c6056a74
SF
19522
19523 case NT_NETBSD_MARCH:
9abca702 19524 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
c6056a74 19525 pnote->descdata);
32ec8896 19526 return TRUE;
c6056a74 19527
9abca702
CZ
19528#ifdef NT_NETBSD_PAX
19529 case NT_NETBSD_PAX:
b966f55f
AM
19530 if (pnote->descsz < 1)
19531 break;
9abca702
CZ
19532 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
19533 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz,
19534 ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""),
19535 ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""),
19536 ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""),
19537 ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""),
19538 ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""),
19539 ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : ""));
19540 return TRUE;
19541#endif
c6056a74 19542 }
b966f55f
AM
19543
19544 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
19545 pnote->descsz, pnote->type);
19546 return FALSE;
c6056a74
SF
19547}
19548
f4ddf30f 19549static const char *
dda8d76d 19550get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
f4ddf30f 19551{
f4ddf30f
JB
19552 switch (e_type)
19553 {
19554 case NT_FREEBSD_THRMISC:
19555 return _("NT_THRMISC (thrmisc structure)");
19556 case NT_FREEBSD_PROCSTAT_PROC:
19557 return _("NT_PROCSTAT_PROC (proc data)");
19558 case NT_FREEBSD_PROCSTAT_FILES:
19559 return _("NT_PROCSTAT_FILES (files data)");
19560 case NT_FREEBSD_PROCSTAT_VMMAP:
19561 return _("NT_PROCSTAT_VMMAP (vmmap data)");
19562 case NT_FREEBSD_PROCSTAT_GROUPS:
19563 return _("NT_PROCSTAT_GROUPS (groups data)");
19564 case NT_FREEBSD_PROCSTAT_UMASK:
19565 return _("NT_PROCSTAT_UMASK (umask data)");
19566 case NT_FREEBSD_PROCSTAT_RLIMIT:
19567 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
19568 case NT_FREEBSD_PROCSTAT_OSREL:
19569 return _("NT_PROCSTAT_OSREL (osreldate data)");
19570 case NT_FREEBSD_PROCSTAT_PSSTRINGS:
19571 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
19572 case NT_FREEBSD_PROCSTAT_AUXV:
19573 return _("NT_PROCSTAT_AUXV (auxv data)");
0b9305ed
JB
19574 case NT_FREEBSD_PTLWPINFO:
19575 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
f4ddf30f 19576 }
dda8d76d 19577 return get_note_type (filedata, e_type);
f4ddf30f
JB
19578}
19579
9437c45b 19580static const char *
dda8d76d 19581get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
9437c45b
JT
19582{
19583 static char buff[64];
19584
540e6170
CZ
19585 switch (e_type)
19586 {
19587 case NT_NETBSDCORE_PROCINFO:
19588 /* NetBSD core "procinfo" structure. */
19589 return _("NetBSD procinfo structure");
9437c45b 19590
540e6170
CZ
19591#ifdef NT_NETBSDCORE_AUXV
19592 case NT_NETBSDCORE_AUXV:
19593 return _("NetBSD ELF auxiliary vector data");
19594#endif
9437c45b 19595
06d949ec
KR
19596#ifdef NT_NETBSDCORE_LWPSTATUS
19597 case NT_NETBSDCORE_LWPSTATUS:
19598 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
19599#endif
19600
540e6170 19601 default:
06d949ec 19602 /* As of Jan 2020 there are no other machine-independent notes
540e6170
CZ
19603 defined for NetBSD core files. If the note type is less
19604 than the start of the machine-dependent note types, we don't
19605 understand it. */
19606
19607 if (e_type < NT_NETBSDCORE_FIRSTMACH)
19608 {
19609 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
19610 return buff;
19611 }
19612 break;
9437c45b
JT
19613 }
19614
dda8d76d 19615 switch (filedata->file_header.e_machine)
9437c45b
JT
19616 {
19617 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
19618 and PT_GETFPREGS == mach+2. */
19619
19620 case EM_OLD_ALPHA:
19621 case EM_ALPHA:
19622 case EM_SPARC:
19623 case EM_SPARC32PLUS:
19624 case EM_SPARCV9:
19625 switch (e_type)
19626 {
2b692964 19627 case NT_NETBSDCORE_FIRSTMACH + 0:
b4db1224 19628 return _("PT_GETREGS (reg structure)");
2b692964 19629 case NT_NETBSDCORE_FIRSTMACH + 2:
b4db1224 19630 return _("PT_GETFPREGS (fpreg structure)");
9437c45b
JT
19631 default:
19632 break;
19633 }
19634 break;
19635
c0d38b0e
CZ
19636 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
19637 There's also old PT___GETREGS40 == mach + 1 for old reg
19638 structure which lacks GBR. */
19639 case EM_SH:
19640 switch (e_type)
19641 {
19642 case NT_NETBSDCORE_FIRSTMACH + 1:
19643 return _("PT___GETREGS40 (old reg structure)");
19644 case NT_NETBSDCORE_FIRSTMACH + 3:
19645 return _("PT_GETREGS (reg structure)");
19646 case NT_NETBSDCORE_FIRSTMACH + 5:
19647 return _("PT_GETFPREGS (fpreg structure)");
19648 default:
19649 break;
19650 }
19651 break;
19652
9437c45b
JT
19653 /* On all other arch's, PT_GETREGS == mach+1 and
19654 PT_GETFPREGS == mach+3. */
19655 default:
19656 switch (e_type)
19657 {
2b692964 19658 case NT_NETBSDCORE_FIRSTMACH + 1:
b4db1224 19659 return _("PT_GETREGS (reg structure)");
2b692964 19660 case NT_NETBSDCORE_FIRSTMACH + 3:
b4db1224 19661 return _("PT_GETFPREGS (fpreg structure)");
9437c45b
JT
19662 default:
19663 break;
19664 }
19665 }
19666
9cf03b7e 19667 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
e9e44622 19668 e_type - NT_NETBSDCORE_FIRSTMACH);
9437c45b
JT
19669 return buff;
19670}
19671
70616151
TT
19672static const char *
19673get_stapsdt_note_type (unsigned e_type)
19674{
19675 static char buff[64];
19676
19677 switch (e_type)
19678 {
19679 case NT_STAPSDT:
19680 return _("NT_STAPSDT (SystemTap probe descriptors)");
19681
19682 default:
19683 break;
19684 }
19685
19686 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
19687 return buff;
19688}
19689
32ec8896 19690static bfd_boolean
c6a9fc58
TT
19691print_stapsdt_note (Elf_Internal_Note *pnote)
19692{
3ca60c57
NC
19693 size_t len, maxlen;
19694 unsigned long addr_size = is_32bit_elf ? 4 : 8;
c6a9fc58
TT
19695 char *data = pnote->descdata;
19696 char *data_end = pnote->descdata + pnote->descsz;
19697 bfd_vma pc, base_addr, semaphore;
19698 char *provider, *probe, *arg_fmt;
19699
3ca60c57
NC
19700 if (pnote->descsz < (addr_size * 3))
19701 goto stapdt_note_too_small;
19702
c6a9fc58
TT
19703 pc = byte_get ((unsigned char *) data, addr_size);
19704 data += addr_size;
3ca60c57 19705
c6a9fc58
TT
19706 base_addr = byte_get ((unsigned char *) data, addr_size);
19707 data += addr_size;
3ca60c57 19708
c6a9fc58
TT
19709 semaphore = byte_get ((unsigned char *) data, addr_size);
19710 data += addr_size;
19711
3ca60c57
NC
19712 if (data >= data_end)
19713 goto stapdt_note_too_small;
19714 maxlen = data_end - data;
19715 len = strnlen (data, maxlen);
19716 if (len < maxlen)
19717 {
19718 provider = data;
19719 data += len + 1;
19720 }
19721 else
19722 goto stapdt_note_too_small;
19723
19724 if (data >= data_end)
19725 goto stapdt_note_too_small;
19726 maxlen = data_end - data;
19727 len = strnlen (data, maxlen);
19728 if (len < maxlen)
19729 {
19730 probe = data;
19731 data += len + 1;
19732 }
19733 else
19734 goto stapdt_note_too_small;
9abca702 19735
3ca60c57
NC
19736 if (data >= data_end)
19737 goto stapdt_note_too_small;
19738 maxlen = data_end - data;
19739 len = strnlen (data, maxlen);
19740 if (len < maxlen)
19741 {
19742 arg_fmt = data;
19743 data += len + 1;
19744 }
19745 else
19746 goto stapdt_note_too_small;
c6a9fc58
TT
19747
19748 printf (_(" Provider: %s\n"), provider);
19749 printf (_(" Name: %s\n"), probe);
19750 printf (_(" Location: "));
19751 print_vma (pc, FULL_HEX);
19752 printf (_(", Base: "));
19753 print_vma (base_addr, FULL_HEX);
19754 printf (_(", Semaphore: "));
19755 print_vma (semaphore, FULL_HEX);
9cf03b7e 19756 printf ("\n");
c6a9fc58
TT
19757 printf (_(" Arguments: %s\n"), arg_fmt);
19758
19759 return data == data_end;
3ca60c57
NC
19760
19761 stapdt_note_too_small:
19762 printf (_(" <corrupt - note is too small>\n"));
19763 error (_("corrupt stapdt note - the data size is too small\n"));
19764 return FALSE;
c6a9fc58
TT
19765}
19766
00e98fc7
TG
19767static const char *
19768get_ia64_vms_note_type (unsigned e_type)
19769{
19770 static char buff[64];
19771
19772 switch (e_type)
19773 {
19774 case NT_VMS_MHD:
19775 return _("NT_VMS_MHD (module header)");
19776 case NT_VMS_LNM:
19777 return _("NT_VMS_LNM (language name)");
19778 case NT_VMS_SRC:
19779 return _("NT_VMS_SRC (source files)");
19780 case NT_VMS_TITLE:
9cf03b7e 19781 return "NT_VMS_TITLE";
00e98fc7
TG
19782 case NT_VMS_EIDC:
19783 return _("NT_VMS_EIDC (consistency check)");
19784 case NT_VMS_FPMODE:
19785 return _("NT_VMS_FPMODE (FP mode)");
19786 case NT_VMS_LINKTIME:
9cf03b7e 19787 return "NT_VMS_LINKTIME";
00e98fc7
TG
19788 case NT_VMS_IMGNAM:
19789 return _("NT_VMS_IMGNAM (image name)");
19790 case NT_VMS_IMGID:
19791 return _("NT_VMS_IMGID (image id)");
19792 case NT_VMS_LINKID:
19793 return _("NT_VMS_LINKID (link id)");
19794 case NT_VMS_IMGBID:
19795 return _("NT_VMS_IMGBID (build id)");
19796 case NT_VMS_GSTNAM:
19797 return _("NT_VMS_GSTNAM (sym table name)");
19798 case NT_VMS_ORIG_DYN:
9cf03b7e 19799 return "NT_VMS_ORIG_DYN";
00e98fc7 19800 case NT_VMS_PATCHTIME:
9cf03b7e 19801 return "NT_VMS_PATCHTIME";
00e98fc7
TG
19802 default:
19803 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
19804 return buff;
19805 }
19806}
19807
32ec8896 19808static bfd_boolean
00e98fc7
TG
19809print_ia64_vms_note (Elf_Internal_Note * pnote)
19810{
8d18bf79
NC
19811 int maxlen = pnote->descsz;
19812
19813 if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz)
19814 goto desc_size_fail;
19815
00e98fc7
TG
19816 switch (pnote->type)
19817 {
19818 case NT_VMS_MHD:
8d18bf79
NC
19819 if (maxlen <= 36)
19820 goto desc_size_fail;
19821
19822 int l = (int) strnlen (pnote->descdata + 34, maxlen - 34);
19823
19824 printf (_(" Creation date : %.17s\n"), pnote->descdata);
19825 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
19826 if (l + 34 < maxlen)
19827 {
19828 printf (_(" Module name : %s\n"), pnote->descdata + 34);
19829 if (l + 35 < maxlen)
19830 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
19831 else
19832 printf (_(" Module version : <missing>\n"));
19833 }
00e98fc7 19834 else
8d18bf79
NC
19835 {
19836 printf (_(" Module name : <missing>\n"));
19837 printf (_(" Module version : <missing>\n"));
19838 }
00e98fc7 19839 break;
8d18bf79 19840
00e98fc7 19841 case NT_VMS_LNM:
8d18bf79 19842 printf (_(" Language: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 19843 break;
8d18bf79 19844
00e98fc7
TG
19845#ifdef BFD64
19846 case NT_VMS_FPMODE:
9cf03b7e 19847 printf (_(" Floating Point mode: "));
8d18bf79
NC
19848 if (maxlen < 8)
19849 goto desc_size_fail;
19850 /* FIXME: Generate an error if descsz > 8 ? */
19851
4a5cb34f 19852 printf ("0x%016" BFD_VMA_FMT "x\n",
8d18bf79 19853 (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7 19854 break;
8d18bf79 19855
00e98fc7
TG
19856 case NT_VMS_LINKTIME:
19857 printf (_(" Link time: "));
8d18bf79
NC
19858 if (maxlen < 8)
19859 goto desc_size_fail;
19860 /* FIXME: Generate an error if descsz > 8 ? */
19861
00e98fc7 19862 print_vms_time
8d18bf79 19863 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7
TG
19864 printf ("\n");
19865 break;
8d18bf79 19866
00e98fc7
TG
19867 case NT_VMS_PATCHTIME:
19868 printf (_(" Patch time: "));
8d18bf79
NC
19869 if (maxlen < 8)
19870 goto desc_size_fail;
19871 /* FIXME: Generate an error if descsz > 8 ? */
19872
00e98fc7 19873 print_vms_time
8d18bf79 19874 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
00e98fc7
TG
19875 printf ("\n");
19876 break;
8d18bf79 19877
00e98fc7 19878 case NT_VMS_ORIG_DYN:
8d18bf79
NC
19879 if (maxlen < 34)
19880 goto desc_size_fail;
19881
00e98fc7
TG
19882 printf (_(" Major id: %u, minor id: %u\n"),
19883 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
19884 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
9cf03b7e 19885 printf (_(" Last modified : "));
00e98fc7
TG
19886 print_vms_time
19887 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
9cf03b7e 19888 printf (_("\n Link flags : "));
4a5cb34f 19889 printf ("0x%016" BFD_VMA_FMT "x\n",
948f632f 19890 (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
00e98fc7 19891 printf (_(" Header flags: 0x%08x\n"),
948f632f 19892 (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
8d18bf79 19893 printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32);
00e98fc7
TG
19894 break;
19895#endif
8d18bf79 19896
00e98fc7 19897 case NT_VMS_IMGNAM:
8d18bf79 19898 printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 19899 break;
8d18bf79 19900
00e98fc7 19901 case NT_VMS_GSTNAM:
8d18bf79 19902 printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 19903 break;
8d18bf79 19904
00e98fc7 19905 case NT_VMS_IMGID:
8d18bf79 19906 printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 19907 break;
8d18bf79 19908
00e98fc7 19909 case NT_VMS_LINKID:
8d18bf79 19910 printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata);
00e98fc7 19911 break;
8d18bf79 19912
00e98fc7 19913 default:
32ec8896 19914 return FALSE;
00e98fc7 19915 }
8d18bf79 19916
32ec8896 19917 return TRUE;
8d18bf79
NC
19918
19919 desc_size_fail:
19920 printf (_(" <corrupt - data size is too small>\n"));
19921 error (_("corrupt IA64 note: data size is too small\n"));
19922 return FALSE;
00e98fc7
TG
19923}
19924
fd486f32
AM
19925struct build_attr_cache {
19926 Filedata *filedata;
19927 char *strtab;
19928 unsigned long strtablen;
19929 Elf_Internal_Sym *symtab;
19930 unsigned long nsyms;
19931} ba_cache;
19932
6f156d7a
NC
19933/* Find the symbol associated with a build attribute that is attached
19934 to address OFFSET. If PNAME is non-NULL then store the name of
19935 the symbol (if found) in the provided pointer, Returns NULL if a
19936 symbol could not be found. */
c799a79d 19937
6f156d7a
NC
19938static Elf_Internal_Sym *
19939get_symbol_for_build_attribute (Filedata * filedata,
19940 unsigned long offset,
19941 bfd_boolean is_open_attr,
19942 const char ** pname)
9ef920e9 19943{
fd486f32
AM
19944 Elf_Internal_Sym *saved_sym = NULL;
19945 Elf_Internal_Sym *sym;
9ef920e9 19946
dda8d76d 19947 if (filedata->section_headers != NULL
fd486f32 19948 && (ba_cache.filedata == NULL || filedata != ba_cache.filedata))
9ef920e9 19949 {
c799a79d 19950 Elf_Internal_Shdr * symsec;
9ef920e9 19951
fd486f32
AM
19952 free (ba_cache.strtab);
19953 ba_cache.strtab = NULL;
19954 free (ba_cache.symtab);
19955 ba_cache.symtab = NULL;
19956
c799a79d 19957 /* Load the symbol and string sections. */
dda8d76d
NC
19958 for (symsec = filedata->section_headers;
19959 symsec < filedata->section_headers + filedata->file_header.e_shnum;
c799a79d 19960 symsec ++)
9ef920e9 19961 {
28d13567
AM
19962 if (symsec->sh_type == SHT_SYMTAB
19963 && get_symtab (filedata, symsec,
19964 &ba_cache.symtab, &ba_cache.nsyms,
19965 &ba_cache.strtab, &ba_cache.strtablen))
19966 break;
9ef920e9 19967 }
fd486f32 19968 ba_cache.filedata = filedata;
9ef920e9
NC
19969 }
19970
fd486f32 19971 if (ba_cache.symtab == NULL)
6f156d7a 19972 return NULL;
9ef920e9 19973
c799a79d 19974 /* Find a symbol whose value matches offset. */
fd486f32 19975 for (sym = ba_cache.symtab; sym < ba_cache.symtab + ba_cache.nsyms; sym ++)
c799a79d
NC
19976 if (sym->st_value == offset)
19977 {
fd486f32 19978 if (sym->st_name >= ba_cache.strtablen)
c799a79d
NC
19979 /* Huh ? This should not happen. */
19980 continue;
9ef920e9 19981
fd486f32 19982 if (ba_cache.strtab[sym->st_name] == 0)
c799a79d 19983 continue;
9ef920e9 19984
8fd75781
NC
19985 /* The AArch64 and ARM architectures define mapping symbols
19986 (eg $d, $x, $t) which we want to ignore. */
fd486f32
AM
19987 if (ba_cache.strtab[sym->st_name] == '$'
19988 && ba_cache.strtab[sym->st_name + 1] != 0
19989 && ba_cache.strtab[sym->st_name + 2] == 0)
8fd75781
NC
19990 continue;
19991
c799a79d
NC
19992 if (is_open_attr)
19993 {
19994 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
19995 and FILE or OBJECT symbols over NOTYPE symbols. We skip
19996 FUNC symbols entirely. */
19997 switch (ELF_ST_TYPE (sym->st_info))
19998 {
c799a79d 19999 case STT_OBJECT:
6f156d7a 20000 case STT_FILE:
c799a79d 20001 saved_sym = sym;
6f156d7a
NC
20002 if (sym->st_size)
20003 {
20004 /* If the symbol has a size associated
20005 with it then we can stop searching. */
fd486f32 20006 sym = ba_cache.symtab + ba_cache.nsyms;
6f156d7a 20007 }
c799a79d 20008 continue;
9ef920e9 20009
c799a79d
NC
20010 case STT_FUNC:
20011 /* Ignore function symbols. */
20012 continue;
20013
20014 default:
20015 break;
20016 }
20017
20018 switch (ELF_ST_BIND (sym->st_info))
9ef920e9 20019 {
c799a79d
NC
20020 case STB_GLOBAL:
20021 if (saved_sym == NULL
20022 || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT)
20023 saved_sym = sym;
20024 break;
c871dade 20025
c799a79d
NC
20026 case STB_LOCAL:
20027 if (saved_sym == NULL)
20028 saved_sym = sym;
20029 break;
20030
20031 default:
9ef920e9
NC
20032 break;
20033 }
20034 }
c799a79d
NC
20035 else
20036 {
20037 if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
20038 continue;
20039
20040 saved_sym = sym;
20041 break;
20042 }
20043 }
20044
6f156d7a 20045 if (saved_sym && pname)
fd486f32 20046 * pname = ba_cache.strtab + saved_sym->st_name;
6f156d7a
NC
20047
20048 return saved_sym;
c799a79d
NC
20049}
20050
d20e98ab
NC
20051/* Returns true iff addr1 and addr2 are in the same section. */
20052
20053static bfd_boolean
20054same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2)
20055{
20056 Elf_Internal_Shdr * a1;
20057 Elf_Internal_Shdr * a2;
20058
20059 a1 = find_section_by_address (filedata, addr1);
20060 a2 = find_section_by_address (filedata, addr2);
9abca702 20061
d20e98ab
NC
20062 return a1 == a2 && a1 != NULL;
20063}
20064
c799a79d 20065static bfd_boolean
dda8d76d
NC
20066print_gnu_build_attribute_description (Elf_Internal_Note * pnote,
20067 Filedata * filedata)
c799a79d 20068{
6f156d7a
NC
20069 static unsigned long global_offset = 0;
20070 static unsigned long global_end = 0;
20071 static unsigned long func_offset = 0;
20072 static unsigned long func_end = 0;
c871dade 20073
6f156d7a
NC
20074 Elf_Internal_Sym * sym;
20075 const char * name;
20076 unsigned long start;
20077 unsigned long end;
20078 bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
20079
20080 switch (pnote->descsz)
c799a79d 20081 {
6f156d7a
NC
20082 case 0:
20083 /* A zero-length description means that the range of
20084 the previous note of the same type should be used. */
c799a79d 20085 if (is_open_attr)
c871dade 20086 {
6f156d7a
NC
20087 if (global_end > global_offset)
20088 printf (_(" Applies to region from %#lx to %#lx\n"),
20089 global_offset, global_end);
20090 else
20091 printf (_(" Applies to region from %#lx\n"), global_offset);
c799a79d
NC
20092 }
20093 else
20094 {
6f156d7a
NC
20095 if (func_end > func_offset)
20096 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end);
20097 else
20098 printf (_(" Applies to region from %#lx\n"), func_offset);
c871dade 20099 }
6f156d7a 20100 return TRUE;
9ef920e9 20101
6f156d7a
NC
20102 case 4:
20103 start = byte_get ((unsigned char *) pnote->descdata, 4);
20104 end = 0;
20105 break;
20106
20107 case 8:
c74147bb
NC
20108 start = byte_get ((unsigned char *) pnote->descdata, 4);
20109 end = byte_get ((unsigned char *) pnote->descdata + 4, 4);
6f156d7a
NC
20110 break;
20111
20112 case 16:
20113 start = byte_get ((unsigned char *) pnote->descdata, 8);
20114 end = byte_get ((unsigned char *) pnote->descdata + 8, 8);
20115 break;
9abca702 20116
6f156d7a 20117 default:
c799a79d
NC
20118 error (_(" <invalid description size: %lx>\n"), pnote->descsz);
20119 printf (_(" <invalid descsz>"));
20120 return FALSE;
20121 }
20122
6f156d7a
NC
20123 name = NULL;
20124 sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name);
8fd75781
NC
20125 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
20126 in order to avoid them being confused with the start address of the
20127 first function in the file... */
20128 if (sym == NULL && is_open_attr)
20129 sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr,
20130 & name);
6f156d7a
NC
20131
20132 if (end == 0 && sym != NULL && sym->st_size > 0)
20133 end = start + sym->st_size;
c799a79d
NC
20134
20135 if (is_open_attr)
20136 {
d20e98ab
NC
20137 /* FIXME: Need to properly allow for section alignment.
20138 16 is just the alignment used on x86_64. */
20139 if (global_end > 0
20140 && start > BFD_ALIGN (global_end, 16)
20141 /* Build notes are not guaranteed to be organised in order of
20142 increasing address, but we should find the all of the notes
20143 for one section in the same place. */
20144 && same_section (filedata, start, global_end))
6f156d7a
NC
20145 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
20146 global_end + 1, start - 1);
20147
20148 printf (_(" Applies to region from %#lx"), start);
20149 global_offset = start;
20150
20151 if (end)
20152 {
20153 printf (_(" to %#lx"), end);
20154 global_end = end;
20155 }
c799a79d
NC
20156 }
20157 else
20158 {
6f156d7a
NC
20159 printf (_(" Applies to region from %#lx"), start);
20160 func_offset = start;
20161
20162 if (end)
20163 {
20164 printf (_(" to %#lx"), end);
20165 func_end = end;
20166 }
c799a79d
NC
20167 }
20168
6f156d7a
NC
20169 if (sym && name)
20170 printf (_(" (%s)"), name);
20171
20172 printf ("\n");
20173 return TRUE;
9ef920e9
NC
20174}
20175
20176static bfd_boolean
20177print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
20178{
1d15e434
NC
20179 static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 };
20180 static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 };
20181 static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 };
9ef920e9
NC
20182 char name_type;
20183 char name_attribute;
1d15e434 20184 const char * expected_types;
9ef920e9
NC
20185 const char * name = pnote->namedata;
20186 const char * text;
88305e1b 20187 signed int left;
9ef920e9
NC
20188
20189 if (name == NULL || pnote->namesz < 2)
20190 {
20191 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
7296a62a 20192 print_symbol (-20, _(" <corrupt name>"));
9ef920e9
NC
20193 return FALSE;
20194 }
20195
6f156d7a
NC
20196 if (do_wide)
20197 left = 28;
20198 else
20199 left = 20;
88305e1b
NC
20200
20201 /* Version 2 of the spec adds a "GA" prefix to the name field. */
20202 if (name[0] == 'G' && name[1] == 'A')
20203 {
6f156d7a
NC
20204 if (pnote->namesz < 4)
20205 {
20206 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
20207 print_symbol (-20, _(" <corrupt name>"));
20208 return FALSE;
20209 }
20210
88305e1b
NC
20211 printf ("GA");
20212 name += 2;
20213 left -= 2;
20214 }
20215
9ef920e9
NC
20216 switch ((name_type = * name))
20217 {
20218 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
20219 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
20220 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
20221 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
20222 printf ("%c", * name);
88305e1b 20223 left --;
9ef920e9
NC
20224 break;
20225 default:
20226 error (_("unrecognised attribute type in name field: %d\n"), name_type);
20227 print_symbol (-20, _("<unknown name type>"));
20228 return FALSE;
20229 }
20230
9ef920e9
NC
20231 ++ name;
20232 text = NULL;
20233
20234 switch ((name_attribute = * name))
20235 {
20236 case GNU_BUILD_ATTRIBUTE_VERSION:
20237 text = _("<version>");
1d15e434 20238 expected_types = string_expected;
9ef920e9
NC
20239 ++ name;
20240 break;
20241 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
20242 text = _("<stack prot>");
75d7d298 20243 expected_types = "!+*";
9ef920e9
NC
20244 ++ name;
20245 break;
20246 case GNU_BUILD_ATTRIBUTE_RELRO:
20247 text = _("<relro>");
1d15e434 20248 expected_types = bool_expected;
9ef920e9
NC
20249 ++ name;
20250 break;
20251 case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
20252 text = _("<stack size>");
1d15e434 20253 expected_types = number_expected;
9ef920e9
NC
20254 ++ name;
20255 break;
20256 case GNU_BUILD_ATTRIBUTE_TOOL:
20257 text = _("<tool>");
1d15e434 20258 expected_types = string_expected;
9ef920e9
NC
20259 ++ name;
20260 break;
20261 case GNU_BUILD_ATTRIBUTE_ABI:
20262 text = _("<ABI>");
20263 expected_types = "$*";
20264 ++ name;
20265 break;
20266 case GNU_BUILD_ATTRIBUTE_PIC:
20267 text = _("<PIC>");
1d15e434 20268 expected_types = number_expected;
9ef920e9
NC
20269 ++ name;
20270 break;
a8be5506
NC
20271 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
20272 text = _("<short enum>");
1d15e434 20273 expected_types = bool_expected;
a8be5506
NC
20274 ++ name;
20275 break;
9ef920e9
NC
20276 default:
20277 if (ISPRINT (* name))
20278 {
20279 int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1;
20280
20281 if (len > left && ! do_wide)
20282 len = left;
75d7d298 20283 printf ("%.*s:", len, name);
9ef920e9 20284 left -= len;
0dd6ae21 20285 name += len;
9ef920e9
NC
20286 }
20287 else
20288 {
3e6b6445 20289 static char tmpbuf [128];
88305e1b 20290
3e6b6445
NC
20291 error (_("unrecognised byte in name field: %d\n"), * name);
20292 sprintf (tmpbuf, _("<unknown:_%d>"), * name);
20293 text = tmpbuf;
20294 name ++;
9ef920e9
NC
20295 }
20296 expected_types = "*$!+";
20297 break;
20298 }
20299
20300 if (text)
88305e1b 20301 left -= printf ("%s", text);
9ef920e9
NC
20302
20303 if (strchr (expected_types, name_type) == NULL)
75d7d298 20304 warn (_("attribute does not have an expected type (%c)\n"), name_type);
9ef920e9
NC
20305
20306 if ((unsigned long)(name - pnote->namedata) > pnote->namesz)
20307 {
20308 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
20309 (unsigned long) pnote->namesz,
20310 (long) (name - pnote->namedata));
20311 return FALSE;
20312 }
20313
20314 if (left < 1 && ! do_wide)
20315 return TRUE;
20316
20317 switch (name_type)
20318 {
20319 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
20320 {
b06b2c92 20321 unsigned int bytes;
ddef72cd
NC
20322 unsigned long long val = 0;
20323 unsigned int shift = 0;
20324 char * decoded = NULL;
20325
b06b2c92
NC
20326 bytes = pnote->namesz - (name - pnote->namedata);
20327 if (bytes > 0)
20328 /* The -1 is because the name field is always 0 terminated, and we
20329 want to be able to ensure that the shift in the while loop below
20330 will not overflow. */
20331 -- bytes;
20332
ddef72cd
NC
20333 if (bytes > sizeof (val))
20334 {
3e6b6445
NC
20335 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
20336 bytes);
20337 bytes = sizeof (val);
ddef72cd 20338 }
3e6b6445
NC
20339 /* We do not bother to warn if bytes == 0 as this can
20340 happen with some early versions of the gcc plugin. */
9ef920e9
NC
20341
20342 while (bytes --)
20343 {
54b8331d 20344 unsigned long long byte = *name++ & 0xff;
79a964dc
NC
20345
20346 val |= byte << shift;
9ef920e9
NC
20347 shift += 8;
20348 }
20349
75d7d298 20350 switch (name_attribute)
9ef920e9 20351 {
75d7d298 20352 case GNU_BUILD_ATTRIBUTE_PIC:
9ef920e9
NC
20353 switch (val)
20354 {
75d7d298
NC
20355 case 0: decoded = "static"; break;
20356 case 1: decoded = "pic"; break;
20357 case 2: decoded = "PIC"; break;
20358 case 3: decoded = "pie"; break;
20359 case 4: decoded = "PIE"; break;
20360 default: break;
9ef920e9 20361 }
75d7d298
NC
20362 break;
20363 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
20364 switch (val)
9ef920e9 20365 {
75d7d298
NC
20366 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
20367 case 0: decoded = "off"; break;
20368 case 1: decoded = "on"; break;
20369 case 2: decoded = "all"; break;
20370 case 3: decoded = "strong"; break;
20371 case 4: decoded = "explicit"; break;
20372 default: break;
9ef920e9 20373 }
75d7d298
NC
20374 break;
20375 default:
20376 break;
9ef920e9
NC
20377 }
20378
75d7d298 20379 if (decoded != NULL)
3e6b6445
NC
20380 {
20381 print_symbol (-left, decoded);
20382 left = 0;
20383 }
20384 else if (val == 0)
20385 {
20386 printf ("0x0");
20387 left -= 3;
20388 }
9ef920e9 20389 else
75d7d298
NC
20390 {
20391 if (do_wide)
ddef72cd 20392 left -= printf ("0x%llx", val);
75d7d298 20393 else
ddef72cd 20394 left -= printf ("0x%-.*llx", left, val);
75d7d298 20395 }
9ef920e9
NC
20396 }
20397 break;
20398 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
20399 left -= print_symbol (- left, name);
20400 break;
20401 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
20402 left -= print_symbol (- left, "true");
20403 break;
20404 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
20405 left -= print_symbol (- left, "false");
20406 break;
20407 }
20408
20409 if (do_wide && left > 0)
20410 printf ("%-*s", left, " ");
9abca702 20411
9ef920e9
NC
20412 return TRUE;
20413}
20414
6d118b09
NC
20415/* Note that by the ELF standard, the name field is already null byte
20416 terminated, and namesz includes the terminating null byte.
20417 I.E. the value of namesz for the name "FSF" is 4.
20418
e3c8793a 20419 If the value of namesz is zero, there is no name present. */
9ef920e9 20420
32ec8896 20421static bfd_boolean
9ef920e9 20422process_note (Elf_Internal_Note * pnote,
dda8d76d 20423 Filedata * filedata)
779fe533 20424{
2cf0635d
NC
20425 const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
20426 const char * nt;
9437c45b
JT
20427
20428 if (pnote->namesz == 0)
1ec5cd37
NC
20429 /* If there is no note name, then use the default set of
20430 note type strings. */
dda8d76d 20431 nt = get_note_type (filedata, pnote->type);
1ec5cd37 20432
1118d252
RM
20433 else if (const_strneq (pnote->namedata, "GNU"))
20434 /* GNU-specific object file notes. */
20435 nt = get_gnu_elf_note_type (pnote->type);
f4ddf30f
JB
20436
20437 else if (const_strneq (pnote->namedata, "FreeBSD"))
20438 /* FreeBSD-specific core file notes. */
dda8d76d 20439 nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
1118d252 20440
0112cd26 20441 else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
1ec5cd37 20442 /* NetBSD-specific core file notes. */
dda8d76d 20443 nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
1ec5cd37 20444
c6056a74
SF
20445 else if (const_strneq (pnote->namedata, "NetBSD"))
20446 /* NetBSD-specific core file notes. */
20447 return process_netbsd_elf_note (pnote);
20448
9abca702
CZ
20449 else if (const_strneq (pnote->namedata, "PaX"))
20450 /* NetBSD-specific core file notes. */
20451 return process_netbsd_elf_note (pnote);
20452
b15fa79e
AM
20453 else if (strneq (pnote->namedata, "SPU/", 4))
20454 {
20455 /* SPU-specific core file notes. */
20456 nt = pnote->namedata + 4;
20457 name = "SPU";
20458 }
20459
00e98fc7
TG
20460 else if (const_strneq (pnote->namedata, "IPF/VMS"))
20461 /* VMS/ia64-specific file notes. */
20462 nt = get_ia64_vms_note_type (pnote->type);
20463
70616151
TT
20464 else if (const_strneq (pnote->namedata, "stapsdt"))
20465 nt = get_stapsdt_note_type (pnote->type);
20466
9437c45b 20467 else
1ec5cd37
NC
20468 /* Don't recognize this note name; just use the default set of
20469 note type strings. */
dda8d76d 20470 nt = get_note_type (filedata, pnote->type);
9437c45b 20471
1449284b 20472 printf (" ");
9ef920e9 20473
483767a3
AM
20474 if (((const_strneq (pnote->namedata, "GA")
20475 && strchr ("*$!+", pnote->namedata[2]) != NULL)
20476 || strchr ("*$!+", pnote->namedata[0]) != NULL)
20477 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
20478 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
9ef920e9
NC
20479 print_gnu_build_attribute_name (pnote);
20480 else
20481 print_symbol (-20, name);
20482
20483 if (do_wide)
20484 printf (" 0x%08lx\t%s\t", pnote->descsz, nt);
20485 else
20486 printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
00e98fc7
TG
20487
20488 if (const_strneq (pnote->namedata, "IPF/VMS"))
20489 return print_ia64_vms_note (pnote);
664f90a3 20490 else if (const_strneq (pnote->namedata, "GNU"))
dda8d76d 20491 return print_gnu_note (filedata, pnote);
c6a9fc58
TT
20492 else if (const_strneq (pnote->namedata, "stapsdt"))
20493 return print_stapsdt_note (pnote);
9ece1fa9
TT
20494 else if (const_strneq (pnote->namedata, "CORE"))
20495 return print_core_note (pnote);
483767a3
AM
20496 else if (((const_strneq (pnote->namedata, "GA")
20497 && strchr ("*$!+", pnote->namedata[2]) != NULL)
20498 || strchr ("*$!+", pnote->namedata[0]) != NULL)
20499 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
20500 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
dda8d76d 20501 return print_gnu_build_attribute_description (pnote, filedata);
779fe533 20502
9ef920e9 20503 if (pnote->descsz)
1449284b
NC
20504 {
20505 unsigned long i;
20506
20507 printf (_(" description data: "));
20508 for (i = 0; i < pnote->descsz; i++)
178d8719 20509 printf ("%02x ", pnote->descdata[i] & 0xff);
04ac15ab
AS
20510 if (!do_wide)
20511 printf ("\n");
1449284b
NC
20512 }
20513
9ef920e9
NC
20514 if (do_wide)
20515 printf ("\n");
20516
32ec8896 20517 return TRUE;
1449284b 20518}
6d118b09 20519
32ec8896 20520static bfd_boolean
dda8d76d
NC
20521process_notes_at (Filedata * filedata,
20522 Elf_Internal_Shdr * section,
20523 bfd_vma offset,
82ed9683
L
20524 bfd_vma length,
20525 bfd_vma align)
779fe533 20526{
2cf0635d
NC
20527 Elf_External_Note * pnotes;
20528 Elf_External_Note * external;
4dff97b2
NC
20529 char * end;
20530 bfd_boolean res = TRUE;
103f02d3 20531
779fe533 20532 if (length <= 0)
32ec8896 20533 return FALSE;
103f02d3 20534
1449284b
NC
20535 if (section)
20536 {
dda8d76d 20537 pnotes = (Elf_External_Note *) get_section_contents (section, filedata);
1449284b 20538 if (pnotes)
32ec8896 20539 {
dda8d76d 20540 if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL))
f761cb13
AM
20541 {
20542 free (pnotes);
20543 return FALSE;
20544 }
32ec8896 20545 }
1449284b
NC
20546 }
20547 else
82ed9683 20548 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
1449284b 20549 _("notes"));
4dff97b2 20550
dd24e3da 20551 if (pnotes == NULL)
32ec8896 20552 return FALSE;
779fe533 20553
103f02d3 20554 external = pnotes;
103f02d3 20555
ca0e11aa
NC
20556 if (filedata->is_separate)
20557 printf (_("In linked file '%s': "), filedata->file_name);
20558 else
20559 printf ("\n");
1449284b 20560 if (section)
ca0e11aa 20561 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata, section));
1449284b 20562 else
ca0e11aa 20563 printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
1449284b
NC
20564 (unsigned long) offset, (unsigned long) length);
20565
82ed9683
L
20566 /* NB: Some note sections may have alignment value of 0 or 1. gABI
20567 specifies that notes should be aligned to 4 bytes in 32-bit
20568 objects and to 8 bytes in 64-bit objects. As a Linux extension,
20569 we also support 4 byte alignment in 64-bit objects. If section
20570 alignment is less than 4, we treate alignment as 4 bytes. */
20571 if (align < 4)
20572 align = 4;
20573 else if (align != 4 && align != 8)
20574 {
20575 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
20576 (long) align);
a788aedd 20577 free (pnotes);
82ed9683
L
20578 return FALSE;
20579 }
20580
dbe15e4e 20581 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
103f02d3 20582
c8071705
NC
20583 end = (char *) pnotes + length;
20584 while ((char *) external < end)
779fe533 20585 {
b34976b6 20586 Elf_Internal_Note inote;
15b42fb0 20587 size_t min_notesz;
4dff97b2 20588 char * next;
2cf0635d 20589 char * temp = NULL;
c8071705 20590 size_t data_remaining = end - (char *) external;
6d118b09 20591
dda8d76d 20592 if (!is_ia64_vms (filedata))
15b42fb0 20593 {
9dd3a467
NC
20594 /* PR binutils/15191
20595 Make sure that there is enough data to read. */
15b42fb0
AM
20596 min_notesz = offsetof (Elf_External_Note, name);
20597 if (data_remaining < min_notesz)
9dd3a467 20598 {
d3a49aa8
AM
20599 warn (ngettext ("Corrupt note: only %ld byte remains, "
20600 "not enough for a full note\n",
20601 "Corrupt note: only %ld bytes remain, "
20602 "not enough for a full note\n",
20603 data_remaining),
20604 (long) data_remaining);
9dd3a467
NC
20605 break;
20606 }
5396a86e
AM
20607 data_remaining -= min_notesz;
20608
15b42fb0
AM
20609 inote.type = BYTE_GET (external->type);
20610 inote.namesz = BYTE_GET (external->namesz);
20611 inote.namedata = external->name;
20612 inote.descsz = BYTE_GET (external->descsz);
276da9b3 20613 inote.descdata = ((char *) external
4dff97b2 20614 + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
15b42fb0 20615 inote.descpos = offset + (inote.descdata - (char *) pnotes);
276da9b3 20616 next = ((char *) external
4dff97b2 20617 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
15b42fb0 20618 }
00e98fc7 20619 else
15b42fb0
AM
20620 {
20621 Elf64_External_VMS_Note *vms_external;
00e98fc7 20622
9dd3a467
NC
20623 /* PR binutils/15191
20624 Make sure that there is enough data to read. */
15b42fb0
AM
20625 min_notesz = offsetof (Elf64_External_VMS_Note, name);
20626 if (data_remaining < min_notesz)
9dd3a467 20627 {
d3a49aa8
AM
20628 warn (ngettext ("Corrupt note: only %ld byte remains, "
20629 "not enough for a full note\n",
20630 "Corrupt note: only %ld bytes remain, "
20631 "not enough for a full note\n",
20632 data_remaining),
20633 (long) data_remaining);
9dd3a467
NC
20634 break;
20635 }
5396a86e 20636 data_remaining -= min_notesz;
3e55a963 20637
15b42fb0
AM
20638 vms_external = (Elf64_External_VMS_Note *) external;
20639 inote.type = BYTE_GET (vms_external->type);
20640 inote.namesz = BYTE_GET (vms_external->namesz);
20641 inote.namedata = vms_external->name;
20642 inote.descsz = BYTE_GET (vms_external->descsz);
20643 inote.descdata = inote.namedata + align_power (inote.namesz, 3);
20644 inote.descpos = offset + (inote.descdata - (char *) pnotes);
20645 next = inote.descdata + align_power (inote.descsz, 3);
20646 }
20647
5396a86e
AM
20648 /* PR 17531: file: 3443835e. */
20649 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
20650 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
20651 || (size_t) (inote.descdata - inote.namedata) > data_remaining
20652 || (size_t) (next - inote.descdata) < inote.descsz
20653 || ((size_t) (next - inote.descdata)
20654 > data_remaining - (size_t) (inote.descdata - inote.namedata)))
3e55a963 20655 {
15b42fb0 20656 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
0af1713e 20657 (unsigned long) ((char *) external - (char *) pnotes));
4dff97b2
NC
20658 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
20659 inote.type, inote.namesz, inote.descsz, (int) align);
3e55a963
NC
20660 break;
20661 }
20662
15b42fb0 20663 external = (Elf_External_Note *) next;
dd24e3da 20664
6d118b09
NC
20665 /* Verify that name is null terminated. It appears that at least
20666 one version of Linux (RedHat 6.0) generates corefiles that don't
20667 comply with the ELF spec by failing to include the null byte in
20668 namesz. */
18344509 20669 if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0')
6d118b09 20670 {
5396a86e 20671 if ((size_t) (inote.descdata - inote.namedata) == inote.namesz)
6d118b09 20672 {
5396a86e
AM
20673 temp = (char *) malloc (inote.namesz + 1);
20674 if (temp == NULL)
20675 {
20676 error (_("Out of memory allocating space for inote name\n"));
20677 res = FALSE;
20678 break;
20679 }
76da6bbe 20680
5396a86e
AM
20681 memcpy (temp, inote.namedata, inote.namesz);
20682 inote.namedata = temp;
20683 }
20684 inote.namedata[inote.namesz] = 0;
6d118b09
NC
20685 }
20686
dda8d76d 20687 if (! process_note (& inote, filedata))
6b4bf3bc 20688 res = FALSE;
103f02d3 20689
9db70fc3
AM
20690 free (temp);
20691 temp = NULL;
779fe533
NC
20692 }
20693
20694 free (pnotes);
103f02d3 20695
779fe533
NC
20696 return res;
20697}
20698
32ec8896 20699static bfd_boolean
dda8d76d 20700process_corefile_note_segments (Filedata * filedata)
779fe533 20701{
2cf0635d 20702 Elf_Internal_Phdr * segment;
b34976b6 20703 unsigned int i;
32ec8896 20704 bfd_boolean res = TRUE;
103f02d3 20705
dda8d76d 20706 if (! get_program_headers (filedata))
6b4bf3bc 20707 return TRUE;
103f02d3 20708
dda8d76d
NC
20709 for (i = 0, segment = filedata->program_headers;
20710 i < filedata->file_header.e_phnum;
b34976b6 20711 i++, segment++)
779fe533
NC
20712 {
20713 if (segment->p_type == PT_NOTE)
dda8d76d 20714 if (! process_notes_at (filedata, NULL,
32ec8896 20715 (bfd_vma) segment->p_offset,
82ed9683
L
20716 (bfd_vma) segment->p_filesz,
20717 (bfd_vma) segment->p_align))
32ec8896 20718 res = FALSE;
779fe533 20719 }
103f02d3 20720
779fe533
NC
20721 return res;
20722}
20723
32ec8896 20724static bfd_boolean
dda8d76d 20725process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length)
685080f2
NC
20726{
20727 Elf_External_Note * pnotes;
20728 Elf_External_Note * external;
c8071705 20729 char * end;
32ec8896 20730 bfd_boolean res = TRUE;
685080f2
NC
20731
20732 if (length <= 0)
32ec8896 20733 return FALSE;
685080f2 20734
dda8d76d 20735 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
685080f2
NC
20736 _("v850 notes"));
20737 if (pnotes == NULL)
32ec8896 20738 return FALSE;
685080f2
NC
20739
20740 external = pnotes;
c8071705 20741 end = (char*) pnotes + length;
685080f2
NC
20742
20743 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
20744 (unsigned long) offset, (unsigned long) length);
20745
c8071705 20746 while ((char *) external + sizeof (Elf_External_Note) < end)
685080f2
NC
20747 {
20748 Elf_External_Note * next;
20749 Elf_Internal_Note inote;
20750
20751 inote.type = BYTE_GET (external->type);
20752 inote.namesz = BYTE_GET (external->namesz);
20753 inote.namedata = external->name;
20754 inote.descsz = BYTE_GET (external->descsz);
20755 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
20756 inote.descpos = offset + (inote.descdata - (char *) pnotes);
20757
c8071705
NC
20758 if (inote.descdata < (char *) pnotes || inote.descdata >= end)
20759 {
20760 warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
20761 inote.descdata = inote.namedata;
20762 inote.namesz = 0;
20763 }
20764
685080f2
NC
20765 next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
20766
c8071705 20767 if ( ((char *) next > end)
685080f2
NC
20768 || ((char *) next < (char *) pnotes))
20769 {
20770 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
20771 (unsigned long) ((char *) external - (char *) pnotes));
20772 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20773 inote.type, inote.namesz, inote.descsz);
20774 break;
20775 }
20776
20777 external = next;
20778
20779 /* Prevent out-of-bounds indexing. */
c8071705 20780 if ( inote.namedata + inote.namesz > end
685080f2
NC
20781 || inote.namedata + inote.namesz < inote.namedata)
20782 {
20783 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
20784 (unsigned long) ((char *) external - (char *) pnotes));
20785 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20786 inote.type, inote.namesz, inote.descsz);
20787 break;
20788 }
20789
20790 printf (" %s: ", get_v850_elf_note_type (inote.type));
20791
20792 if (! print_v850_note (& inote))
20793 {
32ec8896 20794 res = FALSE;
685080f2
NC
20795 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
20796 inote.namesz, inote.descsz);
20797 }
20798 }
20799
20800 free (pnotes);
20801
20802 return res;
20803}
20804
32ec8896 20805static bfd_boolean
dda8d76d 20806process_note_sections (Filedata * filedata)
1ec5cd37 20807{
2cf0635d 20808 Elf_Internal_Shdr * section;
1ec5cd37 20809 unsigned long i;
32ec8896
NC
20810 unsigned int n = 0;
20811 bfd_boolean res = TRUE;
1ec5cd37 20812
dda8d76d
NC
20813 for (i = 0, section = filedata->section_headers;
20814 i < filedata->file_header.e_shnum && section != NULL;
1ec5cd37 20815 i++, section++)
685080f2
NC
20816 {
20817 if (section->sh_type == SHT_NOTE)
20818 {
dda8d76d 20819 if (! process_notes_at (filedata, section,
32ec8896 20820 (bfd_vma) section->sh_offset,
82ed9683
L
20821 (bfd_vma) section->sh_size,
20822 (bfd_vma) section->sh_addralign))
32ec8896 20823 res = FALSE;
685080f2
NC
20824 n++;
20825 }
20826
dda8d76d
NC
20827 if (( filedata->file_header.e_machine == EM_V800
20828 || filedata->file_header.e_machine == EM_V850
20829 || filedata->file_header.e_machine == EM_CYGNUS_V850)
685080f2
NC
20830 && section->sh_type == SHT_RENESAS_INFO)
20831 {
dda8d76d 20832 if (! process_v850_notes (filedata,
32ec8896
NC
20833 (bfd_vma) section->sh_offset,
20834 (bfd_vma) section->sh_size))
20835 res = FALSE;
685080f2
NC
20836 n++;
20837 }
20838 }
df565f32
NC
20839
20840 if (n == 0)
20841 /* Try processing NOTE segments instead. */
dda8d76d 20842 return process_corefile_note_segments (filedata);
1ec5cd37
NC
20843
20844 return res;
20845}
20846
32ec8896 20847static bfd_boolean
dda8d76d 20848process_notes (Filedata * filedata)
779fe533
NC
20849{
20850 /* If we have not been asked to display the notes then do nothing. */
20851 if (! do_notes)
32ec8896 20852 return TRUE;
103f02d3 20853
dda8d76d
NC
20854 if (filedata->file_header.e_type != ET_CORE)
20855 return process_note_sections (filedata);
103f02d3 20856
779fe533 20857 /* No program headers means no NOTE segment. */
dda8d76d
NC
20858 if (filedata->file_header.e_phnum > 0)
20859 return process_corefile_note_segments (filedata);
779fe533 20860
ca0e11aa
NC
20861 if (filedata->is_separate)
20862 printf (_("No notes found in linked file '%s'.\n"),
20863 filedata->file_name);
20864 else
20865 printf (_("No notes found file.\n"));
20866
32ec8896 20867 return TRUE;
779fe533
NC
20868}
20869
60abdbed
NC
20870static unsigned char *
20871display_public_gnu_attributes (unsigned char * start,
20872 const unsigned char * const end)
20873{
20874 printf (_(" Unknown GNU attribute: %s\n"), start);
20875
20876 start += strnlen ((char *) start, end - start);
20877 display_raw_attribute (start, end);
20878
20879 return (unsigned char *) end;
20880}
20881
20882static unsigned char *
20883display_generic_attribute (unsigned char * start,
20884 unsigned int tag,
20885 const unsigned char * const end)
20886{
20887 if (tag == 0)
20888 return (unsigned char *) end;
20889
20890 return display_tag_value (tag, start, end);
20891}
20892
32ec8896 20893static bfd_boolean
dda8d76d 20894process_arch_specific (Filedata * filedata)
252b5132 20895{
a952a375 20896 if (! do_arch)
32ec8896 20897 return TRUE;
a952a375 20898
dda8d76d 20899 switch (filedata->file_header.e_machine)
252b5132 20900 {
53a346d8
CZ
20901 case EM_ARC:
20902 case EM_ARC_COMPACT:
20903 case EM_ARC_COMPACT2:
dda8d76d 20904 return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES,
53a346d8
CZ
20905 display_arc_attribute,
20906 display_generic_attribute);
11c1ff18 20907 case EM_ARM:
dda8d76d 20908 return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES,
60abdbed
NC
20909 display_arm_attribute,
20910 display_generic_attribute);
20911
252b5132 20912 case EM_MIPS:
4fe85591 20913 case EM_MIPS_RS3_LE:
dda8d76d 20914 return process_mips_specific (filedata);
60abdbed
NC
20915
20916 case EM_MSP430:
dda8d76d 20917 return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
b0191216 20918 display_msp430_attribute,
c0ea7c52 20919 display_msp430_gnu_attribute);
60abdbed 20920
2dc8dd17
JW
20921 case EM_RISCV:
20922 return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES,
20923 display_riscv_attribute,
20924 display_generic_attribute);
20925
35c08157 20926 case EM_NDS32:
dda8d76d 20927 return process_nds32_specific (filedata);
60abdbed 20928
85f7484a
PB
20929 case EM_68K:
20930 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
20931 display_m68k_gnu_attribute);
20932
34c8bcba 20933 case EM_PPC:
b82317dd 20934 case EM_PPC64:
dda8d76d 20935 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
20936 display_power_gnu_attribute);
20937
643f7afb
AK
20938 case EM_S390:
20939 case EM_S390_OLD:
dda8d76d 20940 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
20941 display_s390_gnu_attribute);
20942
9e8c70f9
DM
20943 case EM_SPARC:
20944 case EM_SPARC32PLUS:
20945 case EM_SPARCV9:
dda8d76d 20946 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
60abdbed
NC
20947 display_sparc_gnu_attribute);
20948
59e6276b 20949 case EM_TI_C6000:
dda8d76d 20950 return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES,
60abdbed
NC
20951 display_tic6x_attribute,
20952 display_generic_attribute);
20953
0861f561
CQ
20954 case EM_CSKY:
20955 return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES,
20956 display_csky_attribute, NULL);
20957
252b5132 20958 default:
dda8d76d 20959 return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES,
60abdbed
NC
20960 display_public_gnu_attributes,
20961 display_generic_attribute);
252b5132 20962 }
252b5132
RH
20963}
20964
32ec8896 20965static bfd_boolean
dda8d76d 20966get_file_header (Filedata * filedata)
252b5132 20967{
9ea033b2 20968 /* Read in the identity array. */
dda8d76d 20969 if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 20970 return FALSE;
252b5132 20971
9ea033b2 20972 /* Determine how to read the rest of the header. */
dda8d76d 20973 switch (filedata->file_header.e_ident[EI_DATA])
9ea033b2 20974 {
1a0670f3
AM
20975 default:
20976 case ELFDATANONE:
adab8cdc
AO
20977 case ELFDATA2LSB:
20978 byte_get = byte_get_little_endian;
20979 byte_put = byte_put_little_endian;
20980 break;
20981 case ELFDATA2MSB:
20982 byte_get = byte_get_big_endian;
20983 byte_put = byte_put_big_endian;
20984 break;
9ea033b2
NC
20985 }
20986
20987 /* For now we only support 32 bit and 64 bit ELF files. */
dda8d76d 20988 is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64);
9ea033b2
NC
20989
20990 /* Read in the rest of the header. */
20991 if (is_32bit_elf)
20992 {
20993 Elf32_External_Ehdr ehdr32;
252b5132 20994
dda8d76d 20995 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 20996 return FALSE;
103f02d3 20997
dda8d76d
NC
20998 filedata->file_header.e_type = BYTE_GET (ehdr32.e_type);
20999 filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine);
21000 filedata->file_header.e_version = BYTE_GET (ehdr32.e_version);
21001 filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry);
21002 filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
21003 filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
21004 filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags);
21005 filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
21006 filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
21007 filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
21008 filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
21009 filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
21010 filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9ea033b2 21011 }
252b5132 21012 else
9ea033b2
NC
21013 {
21014 Elf64_External_Ehdr ehdr64;
a952a375
NC
21015
21016 /* If we have been compiled with sizeof (bfd_vma) == 4, then
21017 we will not be able to cope with the 64bit data found in
21018 64 ELF files. Detect this now and abort before we start
50c2245b 21019 overwriting things. */
a952a375
NC
21020 if (sizeof (bfd_vma) < 8)
21021 {
e3c8793a
NC
21022 error (_("This instance of readelf has been built without support for a\n\
2102364 bit data type and so it cannot read 64 bit ELF files.\n"));
32ec8896 21024 return FALSE;
a952a375 21025 }
103f02d3 21026
dda8d76d 21027 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1)
32ec8896 21028 return FALSE;
103f02d3 21029
dda8d76d
NC
21030 filedata->file_header.e_type = BYTE_GET (ehdr64.e_type);
21031 filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine);
21032 filedata->file_header.e_version = BYTE_GET (ehdr64.e_version);
21033 filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry);
21034 filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
21035 filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
21036 filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags);
21037 filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
21038 filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
21039 filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
21040 filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
21041 filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
21042 filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9ea033b2 21043 }
252b5132 21044
dda8d76d 21045 if (filedata->file_header.e_shoff)
7ece0d85
JJ
21046 {
21047 /* There may be some extensions in the first section header. Don't
21048 bomb if we can't read it. */
21049 if (is_32bit_elf)
dda8d76d 21050 get_32bit_section_headers (filedata, TRUE);
7ece0d85 21051 else
dda8d76d 21052 get_64bit_section_headers (filedata, TRUE);
7ece0d85 21053 }
560f3c1c 21054
32ec8896 21055 return TRUE;
252b5132
RH
21056}
21057
dda8d76d
NC
21058static void
21059close_file (Filedata * filedata)
21060{
21061 if (filedata)
21062 {
21063 if (filedata->handle)
21064 fclose (filedata->handle);
21065 free (filedata);
21066 }
21067}
21068
21069void
21070close_debug_file (void * data)
21071{
21072 close_file ((Filedata *) data);
21073}
21074
21075static Filedata *
ca0e11aa 21076open_file (const char * pathname, bfd_boolean is_separate)
dda8d76d
NC
21077{
21078 struct stat statbuf;
21079 Filedata * filedata = NULL;
21080
21081 if (stat (pathname, & statbuf) < 0
21082 || ! S_ISREG (statbuf.st_mode))
21083 goto fail;
21084
21085 filedata = calloc (1, sizeof * filedata);
21086 if (filedata == NULL)
21087 goto fail;
21088
21089 filedata->handle = fopen (pathname, "rb");
21090 if (filedata->handle == NULL)
21091 goto fail;
21092
21093 filedata->file_size = (bfd_size_type) statbuf.st_size;
21094 filedata->file_name = pathname;
ca0e11aa 21095 filedata->is_separate = is_separate;
dda8d76d
NC
21096
21097 if (! get_file_header (filedata))
21098 goto fail;
21099
21100 if (filedata->file_header.e_shoff)
21101 {
21102 bfd_boolean res;
21103
21104 /* Read the section headers again, this time for real. */
21105 if (is_32bit_elf)
21106 res = get_32bit_section_headers (filedata, FALSE);
21107 else
21108 res = get_64bit_section_headers (filedata, FALSE);
21109
21110 if (!res)
21111 goto fail;
21112 }
21113
21114 return filedata;
21115
21116 fail:
21117 if (filedata)
21118 {
21119 if (filedata->handle)
21120 fclose (filedata->handle);
21121 free (filedata);
21122 }
21123 return NULL;
21124}
21125
21126void *
21127open_debug_file (const char * pathname)
21128{
ca0e11aa 21129 return open_file (pathname, TRUE);
dda8d76d
NC
21130}
21131
835f2fae
NC
21132static void
21133initialise_dump_sects (Filedata * filedata)
21134{
21135 /* Initialise the dump_sects array from the cmdline_dump_sects array.
21136 Note we do this even if cmdline_dump_sects is empty because we
21137 must make sure that the dump_sets array is zeroed out before each
21138 object file is processed. */
21139 if (filedata->dump.num_dump_sects > cmdline.num_dump_sects)
21140 memset (filedata->dump.dump_sects, 0,
21141 filedata->dump.num_dump_sects * sizeof (*filedata->dump.dump_sects));
21142
21143 if (cmdline.num_dump_sects > 0)
21144 {
21145 if (filedata->dump.num_dump_sects == 0)
21146 /* A sneaky way of allocating the dump_sects array. */
21147 request_dump_bynumber (&filedata->dump, cmdline.num_dump_sects, 0);
21148
21149 assert (filedata->dump.num_dump_sects >= cmdline.num_dump_sects);
21150 memcpy (filedata->dump.dump_sects, cmdline.dump_sects,
21151 cmdline.num_dump_sects * sizeof (*filedata->dump.dump_sects));
21152 }
21153}
21154
fb52b2f4
NC
21155/* Process one ELF object file according to the command line options.
21156 This file may actually be stored in an archive. The file is
32ec8896
NC
21157 positioned at the start of the ELF object. Returns TRUE if no
21158 problems were encountered, FALSE otherwise. */
fb52b2f4 21159
32ec8896 21160static bfd_boolean
dda8d76d 21161process_object (Filedata * filedata)
252b5132 21162{
24841daa 21163 bfd_boolean have_separate_files;
252b5132 21164 unsigned int i;
2482f306 21165 bfd_boolean res;
252b5132 21166
dda8d76d 21167 if (! get_file_header (filedata))
252b5132 21168 {
dda8d76d 21169 error (_("%s: Failed to read file header\n"), filedata->file_name);
32ec8896 21170 return FALSE;
252b5132
RH
21171 }
21172
21173 /* Initialise per file variables. */
978c4450
AM
21174 for (i = ARRAY_SIZE (filedata->version_info); i--;)
21175 filedata->version_info[i] = 0;
252b5132 21176
978c4450
AM
21177 for (i = ARRAY_SIZE (filedata->dynamic_info); i--;)
21178 filedata->dynamic_info[i] = 0;
21179 filedata->dynamic_info_DT_GNU_HASH = 0;
21180 filedata->dynamic_info_DT_MIPS_XHASH = 0;
252b5132
RH
21181
21182 /* Process the file. */
21183 if (show_name)
dda8d76d 21184 printf (_("\nFile: %s\n"), filedata->file_name);
252b5132 21185
835f2fae 21186 initialise_dump_sects (filedata);
d70c5fc7 21187
dda8d76d 21188 if (! process_file_header (filedata))
32ec8896 21189 return FALSE;
252b5132 21190
dda8d76d 21191 if (! process_section_headers (filedata))
2f62977e 21192 {
32ec8896
NC
21193 /* Without loaded section headers we cannot process lots of things. */
21194 do_unwind = do_version = do_dump = do_arch = FALSE;
252b5132 21195
2f62977e 21196 if (! do_using_dynamic)
32ec8896 21197 do_syms = do_dyn_syms = do_reloc = FALSE;
2f62977e 21198 }
252b5132 21199
dda8d76d 21200 if (! process_section_groups (filedata))
32ec8896
NC
21201 /* Without loaded section groups we cannot process unwind. */
21202 do_unwind = FALSE;
d1f5c6e3 21203
2482f306
AM
21204 res = process_program_headers (filedata);
21205 if (res)
21206 res = process_dynamic_section (filedata);
252b5132 21207
dda8d76d 21208 if (! process_relocs (filedata))
32ec8896 21209 res = FALSE;
252b5132 21210
dda8d76d 21211 if (! process_unwind (filedata))
32ec8896 21212 res = FALSE;
4d6ed7c8 21213
dda8d76d 21214 if (! process_symbol_table (filedata))
32ec8896 21215 res = FALSE;
252b5132 21216
0f03783c
NC
21217 if (! process_lto_symbol_tables (filedata))
21218 res = FALSE;
b9e920ec 21219
dda8d76d 21220 if (! process_syminfo (filedata))
32ec8896 21221 res = FALSE;
252b5132 21222
dda8d76d 21223 if (! process_version_sections (filedata))
32ec8896 21224 res = FALSE;
252b5132 21225
82ed9683 21226 if (filedata->file_header.e_shstrndx != SHN_UNDEF)
24841daa 21227 have_separate_files = load_separate_debug_files (filedata, filedata->file_name);
82ed9683 21228 else
24841daa 21229 have_separate_files = FALSE;
dda8d76d
NC
21230
21231 if (! process_section_contents (filedata))
32ec8896 21232 res = FALSE;
f5842774 21233
24841daa 21234 if (have_separate_files)
dda8d76d 21235 {
24841daa
NC
21236 separate_info * d;
21237
21238 for (d = first_separate_info; d != NULL; d = d->next)
21239 {
835f2fae
NC
21240 initialise_dump_sects (d->handle);
21241
ca0e11aa 21242 if (process_links && ! process_file_header (d->handle))
24841daa 21243 res = FALSE;
ca0e11aa 21244 else if (! process_section_headers (d->handle))
24841daa 21245 res = FALSE;
d6bfbc39
NC
21246 else if (! process_section_contents (d->handle))
21247 res = FALSE;
ca0e11aa
NC
21248 else if (process_links)
21249 {
ca0e11aa
NC
21250 if (! process_section_groups (d->handle))
21251 res = FALSE;
21252 if (! process_program_headers (d->handle))
21253 res = FALSE;
21254 if (! process_dynamic_section (d->handle))
21255 res = FALSE;
21256 if (! process_relocs (d->handle))
21257 res = FALSE;
21258 if (! process_unwind (d->handle))
21259 res = FALSE;
21260 if (! process_symbol_table (d->handle))
21261 res = FALSE;
21262 if (! process_lto_symbol_tables (d->handle))
21263 res = FALSE;
21264 if (! process_syminfo (d->handle))
21265 res = FALSE;
21266 if (! process_version_sections (d->handle))
21267 res = FALSE;
21268 if (! process_notes (d->handle))
21269 res = FALSE;
21270 }
24841daa
NC
21271 }
21272
21273 /* The file handles are closed by the call to free_debug_memory() below. */
dda8d76d
NC
21274 }
21275
21276 if (! process_notes (filedata))
32ec8896 21277 res = FALSE;
103f02d3 21278
dda8d76d 21279 if (! process_gnu_liblist (filedata))
32ec8896 21280 res = FALSE;
047b2264 21281
dda8d76d 21282 if (! process_arch_specific (filedata))
32ec8896 21283 res = FALSE;
252b5132 21284
dda8d76d
NC
21285 free (filedata->program_headers);
21286 filedata->program_headers = NULL;
d93f0186 21287
dda8d76d
NC
21288 free (filedata->section_headers);
21289 filedata->section_headers = NULL;
252b5132 21290
dda8d76d
NC
21291 free (filedata->string_table);
21292 filedata->string_table = NULL;
21293 filedata->string_table_length = 0;
252b5132 21294
9db70fc3
AM
21295 free (filedata->dump.dump_sects);
21296 filedata->dump.dump_sects = NULL;
21297 filedata->dump.num_dump_sects = 0;
a788aedd 21298
9db70fc3
AM
21299 free (filedata->dynamic_strings);
21300 filedata->dynamic_strings = NULL;
21301 filedata->dynamic_strings_length = 0;
252b5132 21302
9db70fc3
AM
21303 free (filedata->dynamic_symbols);
21304 filedata->dynamic_symbols = NULL;
21305 filedata->num_dynamic_syms = 0;
252b5132 21306
9db70fc3
AM
21307 free (filedata->dynamic_syminfo);
21308 filedata->dynamic_syminfo = NULL;
ff78d6d6 21309
9db70fc3
AM
21310 free (filedata->dynamic_section);
21311 filedata->dynamic_section = NULL;
293c573e 21312
978c4450 21313 while (filedata->symtab_shndx_list != NULL)
8fb879cd 21314 {
978c4450
AM
21315 elf_section_list *next = filedata->symtab_shndx_list->next;
21316 free (filedata->symtab_shndx_list);
21317 filedata->symtab_shndx_list = next;
8fb879cd
AM
21318 }
21319
9db70fc3
AM
21320 free (filedata->section_headers_groups);
21321 filedata->section_headers_groups = NULL;
e4b17d5c 21322
978c4450 21323 if (filedata->section_groups)
e4b17d5c 21324 {
2cf0635d
NC
21325 struct group_list * g;
21326 struct group_list * next;
e4b17d5c 21327
978c4450 21328 for (i = 0; i < filedata->group_count; i++)
e4b17d5c 21329 {
978c4450 21330 for (g = filedata->section_groups [i].root; g != NULL; g = next)
e4b17d5c
L
21331 {
21332 next = g->next;
21333 free (g);
21334 }
21335 }
21336
978c4450
AM
21337 free (filedata->section_groups);
21338 filedata->section_groups = NULL;
e4b17d5c
L
21339 }
21340
19e6b90e 21341 free_debug_memory ();
18bd398b 21342
32ec8896 21343 return res;
252b5132
RH
21344}
21345
2cf0635d 21346/* Process an ELF archive.
32ec8896
NC
21347 On entry the file is positioned just after the ARMAG string.
21348 Returns TRUE upon success, FALSE otherwise. */
2cf0635d 21349
32ec8896 21350static bfd_boolean
dda8d76d 21351process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
2cf0635d
NC
21352{
21353 struct archive_info arch;
21354 struct archive_info nested_arch;
21355 size_t got;
32ec8896 21356 bfd_boolean ret = TRUE;
2cf0635d 21357
32ec8896 21358 show_name = TRUE;
2cf0635d
NC
21359
21360 /* The ARCH structure is used to hold information about this archive. */
21361 arch.file_name = NULL;
21362 arch.file = NULL;
21363 arch.index_array = NULL;
21364 arch.sym_table = NULL;
21365 arch.longnames = NULL;
21366
21367 /* The NESTED_ARCH structure is used as a single-item cache of information
21368 about a nested archive (when members of a thin archive reside within
21369 another regular archive file). */
21370 nested_arch.file_name = NULL;
21371 nested_arch.file = NULL;
21372 nested_arch.index_array = NULL;
21373 nested_arch.sym_table = NULL;
21374 nested_arch.longnames = NULL;
21375
dda8d76d 21376 if (setup_archive (&arch, filedata->file_name, filedata->handle,
780f96ae
AM
21377 filedata->file_size, is_thin_archive,
21378 do_archive_index) != 0)
2cf0635d 21379 {
32ec8896 21380 ret = FALSE;
2cf0635d 21381 goto out;
4145f1d5 21382 }
fb52b2f4 21383
4145f1d5
NC
21384 if (do_archive_index)
21385 {
2cf0635d 21386 if (arch.sym_table == NULL)
1cb7d8b1
AM
21387 error (_("%s: unable to dump the index as none was found\n"),
21388 filedata->file_name);
4145f1d5
NC
21389 else
21390 {
591f7597 21391 unsigned long i, l;
4145f1d5
NC
21392 unsigned long current_pos;
21393
1cb7d8b1
AM
21394 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
21395 "in the symbol table)\n"),
21396 filedata->file_name, (unsigned long) arch.index_num,
21397 arch.sym_size);
dda8d76d
NC
21398
21399 current_pos = ftell (filedata->handle);
4145f1d5 21400
2cf0635d 21401 for (i = l = 0; i < arch.index_num; i++)
4145f1d5 21402 {
1cb7d8b1
AM
21403 if (i == 0
21404 || (i > 0 && arch.index_array[i] != arch.index_array[i - 1]))
21405 {
21406 char * member_name
21407 = get_archive_member_name_at (&arch, arch.index_array[i],
21408 &nested_arch);
2cf0635d 21409
1cb7d8b1
AM
21410 if (member_name != NULL)
21411 {
21412 char * qualified_name
21413 = make_qualified_name (&arch, &nested_arch,
21414 member_name);
2cf0635d 21415
1cb7d8b1
AM
21416 if (qualified_name != NULL)
21417 {
21418 printf (_("Contents of binary %s at offset "),
21419 qualified_name);
c2a7d3f5
NC
21420 (void) print_vma (arch.index_array[i], PREFIX_HEX);
21421 putchar ('\n');
1cb7d8b1
AM
21422 free (qualified_name);
21423 }
fd486f32 21424 free (member_name);
4145f1d5
NC
21425 }
21426 }
2cf0635d
NC
21427
21428 if (l >= arch.sym_size)
4145f1d5 21429 {
1cb7d8b1
AM
21430 error (_("%s: end of the symbol table reached "
21431 "before the end of the index\n"),
dda8d76d 21432 filedata->file_name);
32ec8896 21433 ret = FALSE;
cb8f3167 21434 break;
4145f1d5 21435 }
591f7597 21436 /* PR 17531: file: 0b6630b2. */
1cb7d8b1
AM
21437 printf ("\t%.*s\n",
21438 (int) (arch.sym_size - l), arch.sym_table + l);
591f7597 21439 l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
4145f1d5
NC
21440 }
21441
67ce483b 21442 if (arch.uses_64bit_indices)
c2a7d3f5
NC
21443 l = (l + 7) & ~ 7;
21444 else
21445 l += l & 1;
21446
2cf0635d 21447 if (l < arch.sym_size)
32ec8896 21448 {
d3a49aa8
AM
21449 error (ngettext ("%s: %ld byte remains in the symbol table, "
21450 "but without corresponding entries in "
21451 "the index table\n",
21452 "%s: %ld bytes remain in the symbol table, "
21453 "but without corresponding entries in "
21454 "the index table\n",
21455 arch.sym_size - l),
dda8d76d 21456 filedata->file_name, arch.sym_size - l);
32ec8896
NC
21457 ret = FALSE;
21458 }
4145f1d5 21459
dda8d76d 21460 if (fseek (filedata->handle, current_pos, SEEK_SET) != 0)
4145f1d5 21461 {
1cb7d8b1
AM
21462 error (_("%s: failed to seek back to start of object files "
21463 "in the archive\n"),
dda8d76d 21464 filedata->file_name);
32ec8896 21465 ret = FALSE;
2cf0635d 21466 goto out;
4145f1d5 21467 }
fb52b2f4 21468 }
4145f1d5
NC
21469
21470 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
21471 && !do_segments && !do_header && !do_dump && !do_version
21472 && !do_histogram && !do_debugging && !do_arch && !do_notes
2c610e4b 21473 && !do_section_groups && !do_dyn_syms)
2cf0635d 21474 {
32ec8896 21475 ret = TRUE; /* Archive index only. */
2cf0635d
NC
21476 goto out;
21477 }
fb52b2f4
NC
21478 }
21479
fb52b2f4
NC
21480 while (1)
21481 {
2cf0635d
NC
21482 char * name;
21483 size_t namelen;
21484 char * qualified_name;
21485
21486 /* Read the next archive header. */
dda8d76d 21487 if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0)
1cb7d8b1
AM
21488 {
21489 error (_("%s: failed to seek to next archive header\n"),
21490 arch.file_name);
21491 ret = FALSE;
21492 break;
21493 }
dda8d76d 21494 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle);
2cf0635d 21495 if (got != sizeof arch.arhdr)
1cb7d8b1
AM
21496 {
21497 if (got == 0)
2cf0635d 21498 break;
28e817cc
NC
21499 /* PR 24049 - we cannot use filedata->file_name as this will
21500 have already been freed. */
21501 error (_("%s: failed to read archive header\n"), arch.file_name);
9abca702 21502
1cb7d8b1
AM
21503 ret = FALSE;
21504 break;
21505 }
2cf0635d 21506 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
1cb7d8b1
AM
21507 {
21508 error (_("%s: did not find a valid archive header\n"),
21509 arch.file_name);
21510 ret = FALSE;
21511 break;
21512 }
2cf0635d
NC
21513
21514 arch.next_arhdr_offset += sizeof arch.arhdr;
21515
978c4450
AM
21516 filedata->archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
21517 if (filedata->archive_file_size & 01)
21518 ++filedata->archive_file_size;
2cf0635d
NC
21519
21520 name = get_archive_member_name (&arch, &nested_arch);
21521 if (name == NULL)
fb52b2f4 21522 {
28e817cc 21523 error (_("%s: bad archive file name\n"), arch.file_name);
32ec8896 21524 ret = FALSE;
d989285c 21525 break;
fb52b2f4 21526 }
2cf0635d 21527 namelen = strlen (name);
fb52b2f4 21528
2cf0635d
NC
21529 qualified_name = make_qualified_name (&arch, &nested_arch, name);
21530 if (qualified_name == NULL)
fb52b2f4 21531 {
28e817cc 21532 error (_("%s: bad archive file name\n"), arch.file_name);
fd486f32 21533 free (name);
32ec8896 21534 ret = FALSE;
d989285c 21535 break;
fb52b2f4
NC
21536 }
21537
2cf0635d 21538 if (is_thin_archive && arch.nested_member_origin == 0)
1cb7d8b1
AM
21539 {
21540 /* This is a proxy for an external member of a thin archive. */
21541 Filedata * member_filedata;
21542 char * member_file_name = adjust_relative_path
dda8d76d 21543 (filedata->file_name, name, namelen);
32ec8896 21544
fd486f32 21545 free (name);
1cb7d8b1
AM
21546 if (member_file_name == NULL)
21547 {
fd486f32 21548 free (qualified_name);
1cb7d8b1
AM
21549 ret = FALSE;
21550 break;
21551 }
2cf0635d 21552
ca0e11aa 21553 member_filedata = open_file (member_file_name, FALSE);
1cb7d8b1
AM
21554 if (member_filedata == NULL)
21555 {
21556 error (_("Input file '%s' is not readable.\n"), member_file_name);
21557 free (member_file_name);
fd486f32 21558 free (qualified_name);
1cb7d8b1
AM
21559 ret = FALSE;
21560 break;
21561 }
2cf0635d 21562
978c4450 21563 filedata->archive_file_offset = arch.nested_member_origin;
dda8d76d 21564 member_filedata->file_name = qualified_name;
2cf0635d 21565
1cb7d8b1 21566 if (! process_object (member_filedata))
32ec8896 21567 ret = FALSE;
2cf0635d 21568
1cb7d8b1
AM
21569 close_file (member_filedata);
21570 free (member_file_name);
1cb7d8b1 21571 }
2cf0635d 21572 else if (is_thin_archive)
1cb7d8b1
AM
21573 {
21574 Filedata thin_filedata;
eb02c04d 21575
1cb7d8b1 21576 memset (&thin_filedata, 0, sizeof (thin_filedata));
dda8d76d 21577
a043396b
NC
21578 /* PR 15140: Allow for corrupt thin archives. */
21579 if (nested_arch.file == NULL)
21580 {
21581 error (_("%s: contains corrupt thin archive: %s\n"),
28e817cc 21582 qualified_name, name);
fd486f32
AM
21583 free (qualified_name);
21584 free (name);
32ec8896 21585 ret = FALSE;
a043396b
NC
21586 break;
21587 }
fd486f32 21588 free (name);
a043396b 21589
1cb7d8b1 21590 /* This is a proxy for a member of a nested archive. */
978c4450
AM
21591 filedata->archive_file_offset
21592 = arch.nested_member_origin + sizeof arch.arhdr;
2cf0635d 21593
1cb7d8b1
AM
21594 /* The nested archive file will have been opened and setup by
21595 get_archive_member_name. */
978c4450
AM
21596 if (fseek (nested_arch.file, filedata->archive_file_offset,
21597 SEEK_SET) != 0)
1cb7d8b1
AM
21598 {
21599 error (_("%s: failed to seek to archive member.\n"),
21600 nested_arch.file_name);
fd486f32 21601 free (qualified_name);
1cb7d8b1
AM
21602 ret = FALSE;
21603 break;
21604 }
2cf0635d 21605
dda8d76d
NC
21606 thin_filedata.handle = nested_arch.file;
21607 thin_filedata.file_name = qualified_name;
9abca702 21608
1cb7d8b1 21609 if (! process_object (& thin_filedata))
32ec8896 21610 ret = FALSE;
1cb7d8b1 21611 }
2cf0635d 21612 else
1cb7d8b1 21613 {
fd486f32 21614 free (name);
978c4450 21615 filedata->archive_file_offset = arch.next_arhdr_offset;
6a6196fc 21616 filedata->file_name = qualified_name;
1cb7d8b1 21617 if (! process_object (filedata))
32ec8896 21618 ret = FALSE;
978c4450 21619 arch.next_arhdr_offset += filedata->archive_file_size;
4c836627 21620 /* Stop looping with "negative" archive_file_size. */
978c4450 21621 if (arch.next_arhdr_offset < filedata->archive_file_size)
80e2a3b6 21622 arch.next_arhdr_offset = -1ul;
1cb7d8b1 21623 }
fb52b2f4 21624
2cf0635d 21625 free (qualified_name);
fb52b2f4
NC
21626 }
21627
4145f1d5 21628 out:
2cf0635d
NC
21629 if (nested_arch.file != NULL)
21630 fclose (nested_arch.file);
21631 release_archive (&nested_arch);
21632 release_archive (&arch);
fb52b2f4 21633
d989285c 21634 return ret;
fb52b2f4
NC
21635}
21636
32ec8896 21637static bfd_boolean
2cf0635d 21638process_file (char * file_name)
fb52b2f4 21639{
dda8d76d 21640 Filedata * filedata = NULL;
fb52b2f4
NC
21641 struct stat statbuf;
21642 char armag[SARMAG];
32ec8896 21643 bfd_boolean ret = TRUE;
fb52b2f4
NC
21644
21645 if (stat (file_name, &statbuf) < 0)
21646 {
f24ddbdd
NC
21647 if (errno == ENOENT)
21648 error (_("'%s': No such file\n"), file_name);
21649 else
21650 error (_("Could not locate '%s'. System error message: %s\n"),
21651 file_name, strerror (errno));
32ec8896 21652 return FALSE;
f24ddbdd
NC
21653 }
21654
21655 if (! S_ISREG (statbuf.st_mode))
21656 {
21657 error (_("'%s' is not an ordinary file\n"), file_name);
32ec8896 21658 return FALSE;
fb52b2f4
NC
21659 }
21660
dda8d76d
NC
21661 filedata = calloc (1, sizeof * filedata);
21662 if (filedata == NULL)
21663 {
21664 error (_("Out of memory allocating file data structure\n"));
21665 return FALSE;
21666 }
21667
21668 filedata->file_name = file_name;
21669 filedata->handle = fopen (file_name, "rb");
21670 if (filedata->handle == NULL)
fb52b2f4 21671 {
f24ddbdd 21672 error (_("Input file '%s' is not readable.\n"), file_name);
dda8d76d 21673 free (filedata);
32ec8896 21674 return FALSE;
fb52b2f4
NC
21675 }
21676
dda8d76d 21677 if (fread (armag, SARMAG, 1, filedata->handle) != 1)
fb52b2f4 21678 {
4145f1d5 21679 error (_("%s: Failed to read file's magic number\n"), file_name);
dda8d76d
NC
21680 fclose (filedata->handle);
21681 free (filedata);
32ec8896 21682 return FALSE;
fb52b2f4
NC
21683 }
21684
dda8d76d 21685 filedata->file_size = (bfd_size_type) statbuf.st_size;
ca0e11aa 21686 filedata->is_separate = FALSE;
f54498b4 21687
fb52b2f4 21688 if (memcmp (armag, ARMAG, SARMAG) == 0)
32ec8896 21689 {
dda8d76d 21690 if (! process_archive (filedata, FALSE))
32ec8896
NC
21691 ret = FALSE;
21692 }
2cf0635d 21693 else if (memcmp (armag, ARMAGT, SARMAG) == 0)
32ec8896 21694 {
dda8d76d 21695 if ( ! process_archive (filedata, TRUE))
32ec8896
NC
21696 ret = FALSE;
21697 }
fb52b2f4
NC
21698 else
21699 {
1b513401 21700 if (do_archive_index && !check_all)
4145f1d5
NC
21701 error (_("File %s is not an archive so its index cannot be displayed.\n"),
21702 file_name);
21703
dda8d76d 21704 rewind (filedata->handle);
978c4450 21705 filedata->archive_file_size = filedata->archive_file_offset = 0;
32ec8896 21706
dda8d76d 21707 if (! process_object (filedata))
32ec8896 21708 ret = FALSE;
fb52b2f4
NC
21709 }
21710
dda8d76d 21711 fclose (filedata->handle);
8fb879cd
AM
21712 free (filedata->section_headers);
21713 free (filedata->program_headers);
21714 free (filedata->string_table);
6431e409 21715 free (filedata->dump.dump_sects);
dda8d76d 21716 free (filedata);
32ec8896 21717
fd486f32 21718 free (ba_cache.strtab);
1bd6175a 21719 ba_cache.strtab = NULL;
fd486f32 21720 free (ba_cache.symtab);
1bd6175a 21721 ba_cache.symtab = NULL;
fd486f32
AM
21722 ba_cache.filedata = NULL;
21723
fb52b2f4
NC
21724 return ret;
21725}
21726
252b5132
RH
21727#ifdef SUPPORT_DISASSEMBLY
21728/* Needed by the i386 disassembler. For extra credit, someone could
9ea033b2 21729 fix this so that we insert symbolic addresses here, esp for GOT/PLT
e3c8793a 21730 symbols. */
252b5132
RH
21731
21732void
2cf0635d 21733print_address (unsigned int addr, FILE * outfile)
252b5132
RH
21734{
21735 fprintf (outfile,"0x%8.8x", addr);
21736}
21737
e3c8793a 21738/* Needed by the i386 disassembler. */
dda8d76d 21739
252b5132
RH
21740void
21741db_task_printsym (unsigned int addr)
21742{
21743 print_address (addr, stderr);
21744}
21745#endif
21746
21747int
2cf0635d 21748main (int argc, char ** argv)
252b5132 21749{
ff78d6d6
L
21750 int err;
21751
252b5132
RH
21752#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
21753 setlocale (LC_MESSAGES, "");
3882b010
L
21754#endif
21755#if defined (HAVE_SETLOCALE)
21756 setlocale (LC_CTYPE, "");
252b5132
RH
21757#endif
21758 bindtextdomain (PACKAGE, LOCALEDIR);
21759 textdomain (PACKAGE);
21760
869b9d07
MM
21761 expandargv (&argc, &argv);
21762
dda8d76d 21763 parse_args (& cmdline, argc, argv);
59f14fc0 21764
18bd398b 21765 if (optind < (argc - 1))
1b513401
NC
21766 /* When displaying information for more than one file,
21767 prefix the information with the file name. */
32ec8896 21768 show_name = TRUE;
5656ba2c
L
21769 else if (optind >= argc)
21770 {
1b513401
NC
21771 /* Ensure that the warning is always displayed. */
21772 do_checks = TRUE;
21773
5656ba2c
L
21774 warn (_("Nothing to do.\n"));
21775 usage (stderr);
21776 }
18bd398b 21777
32ec8896 21778 err = FALSE;
252b5132 21779 while (optind < argc)
32ec8896
NC
21780 if (! process_file (argv[optind++]))
21781 err = TRUE;
252b5132 21782
9db70fc3 21783 free (cmdline.dump_sects);
252b5132 21784
7d9813f1
NA
21785 free (dump_ctf_symtab_name);
21786 free (dump_ctf_strtab_name);
21787 free (dump_ctf_parent_name);
21788
32ec8896 21789 return err ? EXIT_FAILURE : EXIT_SUCCESS;
252b5132 21790}