d16a8f195acfb79b3a284984fc9896145d61e333
[deliverable/binutils-gdb.git] / binutils / readelf.c
1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
3 Copyright (C) 2019 Advanced Micro Devices, Inc. All rights reserved.
4
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
7
8 This file is part of GNU Binutils.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 02110-1301, USA. */
24 \f
25 /* The difference between readelf and objdump:
26
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
29
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
36
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
39
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
43 \f
44 #include "sysdep.h"
45 #include <assert.h>
46 #include <time.h>
47 #include <zlib.h>
48 #ifdef HAVE_WCHAR_H
49 #include <wchar.h>
50 #endif
51
52 #if __GNUC__ >= 2
53 /* Define BFD64 here, even if our default architecture is 32 bit ELF
54 as this will allow us to read in and parse 64bit and 32bit ELF files.
55 Only do this if we believe that the compiler can support a 64 bit
56 data type. For now we only rely on GCC being able to do this. */
57 #define BFD64
58 #endif
59
60 #include "bfd.h"
61 #include "bucomm.h"
62 #include "elfcomm.h"
63 #include "dwarf.h"
64 #include "ctf-api.h"
65
66 #include "elf/common.h"
67 #include "elf/external.h"
68 #include "elf/internal.h"
69
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
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
94 #include "elf/aarch64.h"
95 #include "elf/alpha.h"
96 #include "elf/amdgcn.h"
97 #include "elf/arc.h"
98 #include "elf/arm.h"
99 #include "elf/avr.h"
100 #include "elf/bfin.h"
101 #include "elf/cr16.h"
102 #include "elf/cris.h"
103 #include "elf/crx.h"
104 #include "elf/csky.h"
105 #include "elf/d10v.h"
106 #include "elf/d30v.h"
107 #include "elf/dlx.h"
108 #include "elf/bpf.h"
109 #include "elf/epiphany.h"
110 #include "elf/fr30.h"
111 #include "elf/frv.h"
112 #include "elf/ft32.h"
113 #include "elf/h8.h"
114 #include "elf/hppa.h"
115 #include "elf/i386.h"
116 #include "elf/i370.h"
117 #include "elf/i860.h"
118 #include "elf/i960.h"
119 #include "elf/ia64.h"
120 #include "elf/ip2k.h"
121 #include "elf/lm32.h"
122 #include "elf/iq2000.h"
123 #include "elf/m32c.h"
124 #include "elf/m32r.h"
125 #include "elf/m68k.h"
126 #include "elf/m68hc11.h"
127 #include "elf/s12z.h"
128 #include "elf/mcore.h"
129 #include "elf/mep.h"
130 #include "elf/metag.h"
131 #include "elf/microblaze.h"
132 #include "elf/mips.h"
133 #include "elf/mmix.h"
134 #include "elf/mn10200.h"
135 #include "elf/mn10300.h"
136 #include "elf/moxie.h"
137 #include "elf/mt.h"
138 #include "elf/msp430.h"
139 #include "elf/nds32.h"
140 #include "elf/nfp.h"
141 #include "elf/nios2.h"
142 #include "elf/or1k.h"
143 #include "elf/pj.h"
144 #include "elf/ppc.h"
145 #include "elf/ppc64.h"
146 #include "elf/pru.h"
147 #include "elf/riscv.h"
148 #include "elf/rl78.h"
149 #include "elf/rx.h"
150 #include "elf/s390.h"
151 #include "elf/score.h"
152 #include "elf/sh.h"
153 #include "elf/sparc.h"
154 #include "elf/spu.h"
155 #include "elf/tic6x.h"
156 #include "elf/tilegx.h"
157 #include "elf/tilepro.h"
158 #include "elf/v850.h"
159 #include "elf/vax.h"
160 #include "elf/visium.h"
161 #include "elf/wasm32.h"
162 #include "elf/x86-64.h"
163 #include "elf/xc16x.h"
164 #include "elf/xgate.h"
165 #include "elf/xstormy16.h"
166 #include "elf/xtensa.h"
167
168 #include "getopt.h"
169 #include "libiberty.h"
170 #include "safe-ctype.h"
171 #include "filenames.h"
172
173 #ifndef offsetof
174 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
175 #endif
176
177 typedef struct elf_section_list
178 {
179 Elf_Internal_Shdr * hdr;
180 struct elf_section_list * next;
181 } elf_section_list;
182
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. */
189 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
190
191 typedef unsigned char dump_type;
192
193 /* A linked list of the section names for which dumps were requested. */
194 struct dump_list_entry
195 {
196 char * name;
197 dump_type type;
198 struct dump_list_entry * next;
199 };
200
201 typedef struct filedata
202 {
203 const char * file_name;
204 FILE * handle;
205 bfd_size_type file_size;
206 Elf_Internal_Ehdr file_header;
207 Elf_Internal_Shdr * section_headers;
208 Elf_Internal_Phdr * program_headers;
209 char * string_table;
210 unsigned long string_table_length;
211 /* A dynamic array of flags indicating for which sections a dump of
212 some kind has been requested. It is reset on a per-object file
213 basis and then initialised from the cmdline_dump_sects array,
214 the results of interpreting the -w switch, and the
215 dump_sects_byname list. */
216 dump_type * dump_sects;
217 unsigned int num_dump_sects;
218 } Filedata;
219
220 char * program_name = "readelf";
221
222 static unsigned long archive_file_offset;
223 static unsigned long archive_file_size;
224 static unsigned long dynamic_addr;
225 static bfd_size_type dynamic_size;
226 static size_t dynamic_nent;
227 static char * dynamic_strings;
228 static unsigned long dynamic_strings_length;
229 static unsigned long num_dynamic_syms;
230 static Elf_Internal_Sym * dynamic_symbols;
231 static Elf_Internal_Syminfo * dynamic_syminfo;
232 static unsigned long dynamic_syminfo_offset;
233 static unsigned int dynamic_syminfo_nent;
234 static char program_interpreter[PATH_MAX];
235 static bfd_vma dynamic_info[DT_ENCODING];
236 static bfd_vma dynamic_info_DT_GNU_HASH;
237 static bfd_vma dynamic_info_DT_MIPS_XHASH;
238 static bfd_vma version_info[16];
239 static Elf_Internal_Dyn * dynamic_section;
240 static elf_section_list * symtab_shndx_list;
241 static bfd_boolean show_name = FALSE;
242 static bfd_boolean do_dynamic = FALSE;
243 static bfd_boolean do_syms = FALSE;
244 static bfd_boolean do_dyn_syms = FALSE;
245 static bfd_boolean do_reloc = FALSE;
246 static bfd_boolean do_sections = FALSE;
247 static bfd_boolean do_section_groups = FALSE;
248 static bfd_boolean do_section_details = FALSE;
249 static bfd_boolean do_segments = FALSE;
250 static bfd_boolean do_unwind = FALSE;
251 static bfd_boolean do_using_dynamic = FALSE;
252 static bfd_boolean do_header = FALSE;
253 static bfd_boolean do_dump = FALSE;
254 static bfd_boolean do_version = FALSE;
255 static bfd_boolean do_histogram = FALSE;
256 static bfd_boolean do_debugging = FALSE;
257 static bfd_boolean do_ctf = FALSE;
258 static bfd_boolean do_arch = FALSE;
259 static bfd_boolean do_notes = FALSE;
260 static bfd_boolean do_archive_index = FALSE;
261 static bfd_boolean is_32bit_elf = FALSE;
262 static bfd_boolean decompress_dumps = FALSE;
263
264 static char *dump_ctf_parent_name;
265 static char *dump_ctf_symtab_name;
266 static char *dump_ctf_strtab_name;
267
268 struct group_list
269 {
270 struct group_list * next;
271 unsigned int section_index;
272 };
273
274 struct group
275 {
276 struct group_list * root;
277 unsigned int group_index;
278 };
279
280 static size_t group_count;
281 static struct group * section_groups;
282 static struct group ** section_headers_groups;
283
284 /* A dynamic array of flags indicating for which sections a dump
285 has been requested via command line switches. */
286 static Filedata cmdline;
287
288 static struct dump_list_entry * dump_sects_byname;
289
290 /* How to print a vma value. */
291 typedef enum print_mode
292 {
293 HEX,
294 DEC,
295 DEC_5,
296 UNSIGNED,
297 PREFIX_HEX,
298 FULL_HEX,
299 LONG_HEX
300 }
301 print_mode;
302
303 /* Versioned symbol info. */
304 enum versioned_symbol_info
305 {
306 symbol_undefined,
307 symbol_hidden,
308 symbol_public
309 };
310
311 static const char * get_symbol_version_string
312 (Filedata *, bfd_boolean, const char *, unsigned long, unsigned,
313 Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *);
314
315 #define UNKNOWN -1
316
317 #define SECTION_NAME(X) \
318 ((X) == NULL ? _("<none>") \
319 : filedata->string_table == NULL ? _("<no-strings>") \
320 : ((X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
321 : filedata->string_table + (X)->sh_name))
322
323 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
324
325 #define GET_ELF_SYMBOLS(file, section, sym_count) \
326 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
327 : get_64bit_elf_symbols (file, section, sym_count))
328
329 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
330 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
331 already been called and verified that the string exists. */
332 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
333
334 #define REMOVE_ARCH_BITS(ADDR) \
335 do \
336 { \
337 if (filedata->file_header.e_machine == EM_ARM) \
338 (ADDR) &= ~1; \
339 } \
340 while (0)
341
342 /* Get the correct GNU hash section name. */
343 #define GNU_HASH_SECTION_NAME \
344 dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
345 \f
346 /* Print a BFD_VMA to an internal buffer, for use in error messages.
347 BFD_FMA_FMT can't be used in translated strings. */
348
349 static const char *
350 bfd_vmatoa (char *fmtch, bfd_vma value)
351 {
352 /* bfd_vmatoa is used more then once in a printf call for output.
353 Cycle through an array of buffers. */
354 static int buf_pos = 0;
355 static struct bfd_vmatoa_buf
356 {
357 char place[64];
358 } buf[4];
359 char *ret;
360 char fmt[32];
361
362 ret = buf[buf_pos++].place;
363 buf_pos %= ARRAY_SIZE (buf);
364
365 sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
366 snprintf (ret, sizeof (buf[0].place), fmt, value);
367 return ret;
368 }
369
370 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
371 OFFSET + the offset of the current archive member, if we are examining an
372 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
373 allocate a buffer using malloc and fill that. In either case return the
374 pointer to the start of the retrieved data or NULL if something went wrong.
375 If something does go wrong and REASON is not NULL then emit an error
376 message using REASON as part of the context. */
377
378 static void *
379 get_data (void * var,
380 Filedata * filedata,
381 unsigned long offset,
382 bfd_size_type size,
383 bfd_size_type nmemb,
384 const char * reason)
385 {
386 void * mvar;
387 bfd_size_type amt = size * nmemb;
388
389 if (size == 0 || nmemb == 0)
390 return NULL;
391
392 /* If the size_t type is smaller than the bfd_size_type, eg because
393 you are building a 32-bit tool on a 64-bit host, then make sure
394 that when the sizes are cast to (size_t) no information is lost. */
395 if ((size_t) size != size
396 || (size_t) nmemb != nmemb
397 || (size_t) amt != amt)
398 {
399 if (reason)
400 error (_("Size truncation prevents reading %s"
401 " elements of size %s for %s\n"),
402 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
403 return NULL;
404 }
405
406 /* Check for size overflow. */
407 if (amt / size != nmemb || (size_t) amt + 1 == 0)
408 {
409 if (reason)
410 error (_("Size overflow prevents reading %s"
411 " elements of size %s for %s\n"),
412 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
413 return NULL;
414 }
415
416 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
417 attempting to allocate memory when the read is bound to fail. */
418 if (archive_file_offset > filedata->file_size
419 || offset > filedata->file_size - archive_file_offset
420 || amt > filedata->file_size - archive_file_offset - offset)
421 {
422 if (reason)
423 error (_("Reading %s bytes extends past end of file for %s\n"),
424 bfd_vmatoa ("u", amt), reason);
425 return NULL;
426 }
427
428 if (fseek (filedata->handle, archive_file_offset + offset, SEEK_SET))
429 {
430 if (reason)
431 error (_("Unable to seek to 0x%lx for %s\n"),
432 archive_file_offset + offset, reason);
433 return NULL;
434 }
435
436 mvar = var;
437 if (mvar == NULL)
438 {
439 /* + 1 so that we can '\0' terminate invalid string table sections. */
440 mvar = malloc ((size_t) amt + 1);
441
442 if (mvar == NULL)
443 {
444 if (reason)
445 error (_("Out of memory allocating %s bytes for %s\n"),
446 bfd_vmatoa ("u", amt), reason);
447 return NULL;
448 }
449
450 ((char *) mvar)[amt] = '\0';
451 }
452
453 if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb)
454 {
455 if (reason)
456 error (_("Unable to read in %s bytes of %s\n"),
457 bfd_vmatoa ("u", amt), reason);
458 if (mvar != var)
459 free (mvar);
460 return NULL;
461 }
462
463 return mvar;
464 }
465
466 /* Print a VMA value in the MODE specified.
467 Returns the number of characters displayed. */
468
469 static unsigned int
470 print_vma (bfd_vma vma, print_mode mode)
471 {
472 unsigned int nc = 0;
473
474 switch (mode)
475 {
476 case FULL_HEX:
477 nc = printf ("0x");
478 /* Fall through. */
479 case LONG_HEX:
480 #ifdef BFD64
481 if (is_32bit_elf)
482 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
483 #endif
484 printf_vma (vma);
485 return nc + 16;
486
487 case DEC_5:
488 if (vma <= 99999)
489 return printf ("%5" BFD_VMA_FMT "d", vma);
490 /* Fall through. */
491 case PREFIX_HEX:
492 nc = printf ("0x");
493 /* Fall through. */
494 case HEX:
495 return nc + printf ("%" BFD_VMA_FMT "x", vma);
496
497 case DEC:
498 return printf ("%" BFD_VMA_FMT "d", vma);
499
500 case UNSIGNED:
501 return printf ("%" BFD_VMA_FMT "u", vma);
502
503 default:
504 /* FIXME: Report unrecognised mode ? */
505 return 0;
506 }
507 }
508
509 /* Display a symbol on stdout. Handles the display of control characters and
510 multibye characters (assuming the host environment supports them).
511
512 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
513
514 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
515 padding as necessary.
516
517 Returns the number of emitted characters. */
518
519 static unsigned int
520 print_symbol (signed int width, const char *symbol)
521 {
522 bfd_boolean extra_padding = FALSE;
523 signed int num_printed = 0;
524 #ifdef HAVE_MBSTATE_T
525 mbstate_t state;
526 #endif
527 unsigned int width_remaining;
528
529 if (width < 0)
530 {
531 /* Keep the width positive. This helps the code below. */
532 width = - width;
533 extra_padding = TRUE;
534 }
535 else if (width == 0)
536 return 0;
537
538 if (do_wide)
539 /* Set the remaining width to a very large value.
540 This simplifies the code below. */
541 width_remaining = INT_MAX;
542 else
543 width_remaining = width;
544
545 #ifdef HAVE_MBSTATE_T
546 /* Initialise the multibyte conversion state. */
547 memset (& state, 0, sizeof (state));
548 #endif
549
550 while (width_remaining)
551 {
552 size_t n;
553 const char c = *symbol++;
554
555 if (c == 0)
556 break;
557
558 /* Do not print control characters directly as they can affect terminal
559 settings. Such characters usually appear in the names generated
560 by the assembler for local labels. */
561 if (ISCNTRL (c))
562 {
563 if (width_remaining < 2)
564 break;
565
566 printf ("^%c", c + 0x40);
567 width_remaining -= 2;
568 num_printed += 2;
569 }
570 else if (ISPRINT (c))
571 {
572 putchar (c);
573 width_remaining --;
574 num_printed ++;
575 }
576 else
577 {
578 #ifdef HAVE_MBSTATE_T
579 wchar_t w;
580 #endif
581 /* Let printf do the hard work of displaying multibyte characters. */
582 printf ("%.1s", symbol - 1);
583 width_remaining --;
584 num_printed ++;
585
586 #ifdef HAVE_MBSTATE_T
587 /* Try to find out how many bytes made up the character that was
588 just printed. Advance the symbol pointer past the bytes that
589 were displayed. */
590 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
591 #else
592 n = 1;
593 #endif
594 if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
595 symbol += (n - 1);
596 }
597 }
598
599 if (extra_padding && num_printed < width)
600 {
601 /* Fill in the remaining spaces. */
602 printf ("%-*s", width - num_printed, " ");
603 num_printed = width;
604 }
605
606 return num_printed;
607 }
608
609 /* Returns a pointer to a static buffer containing a printable version of
610 the given section's name. Like print_symbol, except that it does not try
611 to print multibyte characters, it just interprets them as hex values. */
612
613 static const char *
614 printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec)
615 {
616 #define MAX_PRINT_SEC_NAME_LEN 128
617 static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
618 const char * name = SECTION_NAME (sec);
619 char * buf = sec_name_buf;
620 char c;
621 unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
622
623 while ((c = * name ++) != 0)
624 {
625 if (ISCNTRL (c))
626 {
627 if (remaining < 2)
628 break;
629
630 * buf ++ = '^';
631 * buf ++ = c + 0x40;
632 remaining -= 2;
633 }
634 else if (ISPRINT (c))
635 {
636 * buf ++ = c;
637 remaining -= 1;
638 }
639 else
640 {
641 static char hex[17] = "0123456789ABCDEF";
642
643 if (remaining < 4)
644 break;
645 * buf ++ = '<';
646 * buf ++ = hex[(c & 0xf0) >> 4];
647 * buf ++ = hex[c & 0x0f];
648 * buf ++ = '>';
649 remaining -= 4;
650 }
651
652 if (remaining == 0)
653 break;
654 }
655
656 * buf = 0;
657 return sec_name_buf;
658 }
659
660 static const char *
661 printable_section_name_from_index (Filedata * filedata, unsigned long ndx)
662 {
663 if (ndx >= filedata->file_header.e_shnum)
664 return _("<corrupt>");
665
666 return printable_section_name (filedata, filedata->section_headers + ndx);
667 }
668
669 /* Return a pointer to section NAME, or NULL if no such section exists. */
670
671 static Elf_Internal_Shdr *
672 find_section (Filedata * filedata, const char * name)
673 {
674 unsigned int i;
675
676 if (filedata->section_headers == NULL)
677 return NULL;
678
679 for (i = 0; i < filedata->file_header.e_shnum; i++)
680 if (streq (SECTION_NAME (filedata->section_headers + i), name))
681 return filedata->section_headers + i;
682
683 return NULL;
684 }
685
686 /* Return a pointer to a section containing ADDR, or NULL if no such
687 section exists. */
688
689 static Elf_Internal_Shdr *
690 find_section_by_address (Filedata * filedata, bfd_vma addr)
691 {
692 unsigned int i;
693
694 if (filedata->section_headers == NULL)
695 return NULL;
696
697 for (i = 0; i < filedata->file_header.e_shnum; i++)
698 {
699 Elf_Internal_Shdr *sec = filedata->section_headers + i;
700
701 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
702 return sec;
703 }
704
705 return NULL;
706 }
707
708 static Elf_Internal_Shdr *
709 find_section_by_type (Filedata * filedata, unsigned int type)
710 {
711 unsigned int i;
712
713 if (filedata->section_headers == NULL)
714 return NULL;
715
716 for (i = 0; i < filedata->file_header.e_shnum; i++)
717 {
718 Elf_Internal_Shdr *sec = filedata->section_headers + i;
719
720 if (sec->sh_type == type)
721 return sec;
722 }
723
724 return NULL;
725 }
726
727 /* Return a pointer to section NAME, or NULL if no such section exists,
728 restricted to the list of sections given in SET. */
729
730 static Elf_Internal_Shdr *
731 find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
732 {
733 unsigned int i;
734
735 if (filedata->section_headers == NULL)
736 return NULL;
737
738 if (set != NULL)
739 {
740 while ((i = *set++) > 0)
741 {
742 /* See PR 21156 for a reproducer. */
743 if (i >= filedata->file_header.e_shnum)
744 continue; /* FIXME: Should we issue an error message ? */
745
746 if (streq (SECTION_NAME (filedata->section_headers + i), name))
747 return filedata->section_headers + i;
748 }
749 }
750
751 return find_section (filedata, name);
752 }
753
754 /* Read an unsigned LEB128 encoded value from DATA.
755 Set *LENGTH_RETURN to the number of bytes read. */
756
757 static inline unsigned long
758 read_uleb128 (unsigned char * data,
759 unsigned int * length_return,
760 const unsigned char * const end)
761 {
762 return read_leb128 (data, length_return, FALSE, end);
763 }
764
765 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
766 This OS has so many departures from the ELF standard that we test it at
767 many places. */
768
769 static inline bfd_boolean
770 is_ia64_vms (Filedata * filedata)
771 {
772 return filedata->file_header.e_machine == EM_IA_64
773 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
774 }
775
776 /* Guess the relocation size commonly used by the specific machines. */
777
778 static bfd_boolean
779 guess_is_rela (unsigned int e_machine)
780 {
781 switch (e_machine)
782 {
783 /* Targets that use REL relocations. */
784 case EM_386:
785 case EM_IAMCU:
786 case EM_960:
787 case EM_ARM:
788 case EM_D10V:
789 case EM_CYGNUS_D10V:
790 case EM_DLX:
791 case EM_MIPS:
792 case EM_MIPS_RS3_LE:
793 case EM_CYGNUS_M32R:
794 case EM_SCORE:
795 case EM_XGATE:
796 case EM_NFP:
797 case EM_BPF:
798 return FALSE;
799
800 /* Targets that use RELA relocations. */
801 case EM_68K:
802 case EM_860:
803 case EM_AARCH64:
804 case EM_ADAPTEVA_EPIPHANY:
805 case EM_ALPHA:
806 case EM_ALTERA_NIOS2:
807 case EM_ARC:
808 case EM_ARC_COMPACT:
809 case EM_ARC_COMPACT2:
810 case EM_AVR:
811 case EM_AVR_OLD:
812 case EM_BLACKFIN:
813 case EM_CR16:
814 case EM_CRIS:
815 case EM_CRX:
816 case EM_CSKY:
817 case EM_D30V:
818 case EM_CYGNUS_D30V:
819 case EM_FR30:
820 case EM_FT32:
821 case EM_CYGNUS_FR30:
822 case EM_CYGNUS_FRV:
823 case EM_H8S:
824 case EM_H8_300:
825 case EM_H8_300H:
826 case EM_IA_64:
827 case EM_IP2K:
828 case EM_IP2K_OLD:
829 case EM_IQ2000:
830 case EM_LATTICEMICO32:
831 case EM_M32C_OLD:
832 case EM_M32C:
833 case EM_M32R:
834 case EM_MCORE:
835 case EM_CYGNUS_MEP:
836 case EM_METAG:
837 case EM_MMIX:
838 case EM_MN10200:
839 case EM_CYGNUS_MN10200:
840 case EM_MN10300:
841 case EM_CYGNUS_MN10300:
842 case EM_MOXIE:
843 case EM_MSP430:
844 case EM_MSP430_OLD:
845 case EM_MT:
846 case EM_NDS32:
847 case EM_NIOS32:
848 case EM_OR1K:
849 case EM_PPC64:
850 case EM_PPC:
851 case EM_TI_PRU:
852 case EM_RISCV:
853 case EM_RL78:
854 case EM_RX:
855 case EM_S390:
856 case EM_S390_OLD:
857 case EM_SH:
858 case EM_SPARC:
859 case EM_SPARC32PLUS:
860 case EM_SPARCV9:
861 case EM_SPU:
862 case EM_TI_C6000:
863 case EM_TILEGX:
864 case EM_TILEPRO:
865 case EM_V800:
866 case EM_V850:
867 case EM_CYGNUS_V850:
868 case EM_VAX:
869 case EM_VISIUM:
870 case EM_X86_64:
871 case EM_L1OM:
872 case EM_K1OM:
873 case EM_XSTORMY16:
874 case EM_XTENSA:
875 case EM_XTENSA_OLD:
876 case EM_MICROBLAZE:
877 case EM_MICROBLAZE_OLD:
878 case EM_WEBASSEMBLY:
879 return TRUE;
880
881 case EM_68HC05:
882 case EM_68HC08:
883 case EM_68HC11:
884 case EM_68HC16:
885 case EM_FX66:
886 case EM_ME16:
887 case EM_MMA:
888 case EM_NCPU:
889 case EM_NDR1:
890 case EM_PCP:
891 case EM_ST100:
892 case EM_ST19:
893 case EM_ST7:
894 case EM_ST9PLUS:
895 case EM_STARCORE:
896 case EM_SVX:
897 case EM_TINYJ:
898 default:
899 warn (_("Don't know about relocations on this machine architecture\n"));
900 return FALSE;
901 }
902 }
903
904 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
905 Returns TRUE upon success, FALSE otherwise. If successful then a
906 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
907 and the number of relocs loaded is placed in *NRELASP. It is the caller's
908 responsibility to free the allocated buffer. */
909
910 static bfd_boolean
911 slurp_rela_relocs (Filedata * filedata,
912 unsigned long rel_offset,
913 unsigned long rel_size,
914 Elf_Internal_Rela ** relasp,
915 unsigned long * nrelasp)
916 {
917 Elf_Internal_Rela * relas;
918 size_t nrelas;
919 unsigned int i;
920
921 if (is_32bit_elf)
922 {
923 Elf32_External_Rela * erelas;
924
925 erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
926 rel_size, _("32-bit relocation data"));
927 if (!erelas)
928 return FALSE;
929
930 nrelas = rel_size / sizeof (Elf32_External_Rela);
931
932 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
933 sizeof (Elf_Internal_Rela));
934
935 if (relas == NULL)
936 {
937 free (erelas);
938 error (_("out of memory parsing relocs\n"));
939 return FALSE;
940 }
941
942 for (i = 0; i < nrelas; i++)
943 {
944 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
945 relas[i].r_info = BYTE_GET (erelas[i].r_info);
946 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
947 }
948
949 free (erelas);
950 }
951 else
952 {
953 Elf64_External_Rela * erelas;
954
955 erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
956 rel_size, _("64-bit relocation data"));
957 if (!erelas)
958 return FALSE;
959
960 nrelas = rel_size / sizeof (Elf64_External_Rela);
961
962 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
963 sizeof (Elf_Internal_Rela));
964
965 if (relas == NULL)
966 {
967 free (erelas);
968 error (_("out of memory parsing relocs\n"));
969 return FALSE;
970 }
971
972 for (i = 0; i < nrelas; i++)
973 {
974 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
975 relas[i].r_info = BYTE_GET (erelas[i].r_info);
976 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
977
978 /* The #ifdef BFD64 below is to prevent a compile time
979 warning. We know that if we do not have a 64 bit data
980 type that we will never execute this code anyway. */
981 #ifdef BFD64
982 if (filedata->file_header.e_machine == EM_MIPS
983 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
984 {
985 /* In little-endian objects, r_info isn't really a
986 64-bit little-endian value: it has a 32-bit
987 little-endian symbol index followed by four
988 individual byte fields. Reorder INFO
989 accordingly. */
990 bfd_vma inf = relas[i].r_info;
991 inf = (((inf & 0xffffffff) << 32)
992 | ((inf >> 56) & 0xff)
993 | ((inf >> 40) & 0xff00)
994 | ((inf >> 24) & 0xff0000)
995 | ((inf >> 8) & 0xff000000));
996 relas[i].r_info = inf;
997 }
998 #endif /* BFD64 */
999 }
1000
1001 free (erelas);
1002 }
1003
1004 *relasp = relas;
1005 *nrelasp = nrelas;
1006 return TRUE;
1007 }
1008
1009 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1010 Returns TRUE upon success, FALSE otherwise. If successful then a
1011 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1012 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1013 responsibility to free the allocated buffer. */
1014
1015 static bfd_boolean
1016 slurp_rel_relocs (Filedata * filedata,
1017 unsigned long rel_offset,
1018 unsigned long rel_size,
1019 Elf_Internal_Rela ** relsp,
1020 unsigned long * nrelsp)
1021 {
1022 Elf_Internal_Rela * rels;
1023 size_t nrels;
1024 unsigned int i;
1025
1026 if (is_32bit_elf)
1027 {
1028 Elf32_External_Rel * erels;
1029
1030 erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
1031 rel_size, _("32-bit relocation data"));
1032 if (!erels)
1033 return FALSE;
1034
1035 nrels = rel_size / sizeof (Elf32_External_Rel);
1036
1037 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
1038
1039 if (rels == NULL)
1040 {
1041 free (erels);
1042 error (_("out of memory parsing relocs\n"));
1043 return FALSE;
1044 }
1045
1046 for (i = 0; i < nrels; i++)
1047 {
1048 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1049 rels[i].r_info = BYTE_GET (erels[i].r_info);
1050 rels[i].r_addend = 0;
1051 }
1052
1053 free (erels);
1054 }
1055 else
1056 {
1057 Elf64_External_Rel * erels;
1058
1059 erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
1060 rel_size, _("64-bit relocation data"));
1061 if (!erels)
1062 return FALSE;
1063
1064 nrels = rel_size / sizeof (Elf64_External_Rel);
1065
1066 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
1067
1068 if (rels == NULL)
1069 {
1070 free (erels);
1071 error (_("out of memory parsing relocs\n"));
1072 return FALSE;
1073 }
1074
1075 for (i = 0; i < nrels; i++)
1076 {
1077 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1078 rels[i].r_info = BYTE_GET (erels[i].r_info);
1079 rels[i].r_addend = 0;
1080
1081 /* The #ifdef BFD64 below is to prevent a compile time
1082 warning. We know that if we do not have a 64 bit data
1083 type that we will never execute this code anyway. */
1084 #ifdef BFD64
1085 if (filedata->file_header.e_machine == EM_MIPS
1086 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
1087 {
1088 /* In little-endian objects, r_info isn't really a
1089 64-bit little-endian value: it has a 32-bit
1090 little-endian symbol index followed by four
1091 individual byte fields. Reorder INFO
1092 accordingly. */
1093 bfd_vma inf = rels[i].r_info;
1094 inf = (((inf & 0xffffffff) << 32)
1095 | ((inf >> 56) & 0xff)
1096 | ((inf >> 40) & 0xff00)
1097 | ((inf >> 24) & 0xff0000)
1098 | ((inf >> 8) & 0xff000000));
1099 rels[i].r_info = inf;
1100 }
1101 #endif /* BFD64 */
1102 }
1103
1104 free (erels);
1105 }
1106
1107 *relsp = rels;
1108 *nrelsp = nrels;
1109 return TRUE;
1110 }
1111
1112 /* Returns the reloc type extracted from the reloc info field. */
1113
1114 static unsigned int
1115 get_reloc_type (Filedata * filedata, bfd_vma reloc_info)
1116 {
1117 if (is_32bit_elf)
1118 return ELF32_R_TYPE (reloc_info);
1119
1120 switch (filedata->file_header.e_machine)
1121 {
1122 case EM_MIPS:
1123 /* Note: We assume that reloc_info has already been adjusted for us. */
1124 return ELF64_MIPS_R_TYPE (reloc_info);
1125
1126 case EM_SPARCV9:
1127 return ELF64_R_TYPE_ID (reloc_info);
1128
1129 default:
1130 return ELF64_R_TYPE (reloc_info);
1131 }
1132 }
1133
1134 /* Return the symbol index extracted from the reloc info field. */
1135
1136 static bfd_vma
1137 get_reloc_symindex (bfd_vma reloc_info)
1138 {
1139 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
1140 }
1141
1142 static inline bfd_boolean
1143 uses_msp430x_relocs (Filedata * filedata)
1144 {
1145 return
1146 filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */
1147 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1148 && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
1149 /* TI compiler uses ELFOSABI_NONE. */
1150 || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
1151 }
1152
1153 /* Display the contents of the relocation data found at the specified
1154 offset. */
1155
1156 static bfd_boolean
1157 dump_relocations (Filedata * filedata,
1158 unsigned long rel_offset,
1159 unsigned long rel_size,
1160 Elf_Internal_Sym * symtab,
1161 unsigned long nsyms,
1162 char * strtab,
1163 unsigned long strtablen,
1164 int is_rela,
1165 bfd_boolean is_dynsym)
1166 {
1167 unsigned long i;
1168 Elf_Internal_Rela * rels;
1169 bfd_boolean res = TRUE;
1170
1171 if (is_rela == UNKNOWN)
1172 is_rela = guess_is_rela (filedata->file_header.e_machine);
1173
1174 if (is_rela)
1175 {
1176 if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
1177 return FALSE;
1178 }
1179 else
1180 {
1181 if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
1182 return FALSE;
1183 }
1184
1185 if (is_32bit_elf)
1186 {
1187 if (is_rela)
1188 {
1189 if (do_wide)
1190 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1191 else
1192 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1193 }
1194 else
1195 {
1196 if (do_wide)
1197 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1198 else
1199 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1200 }
1201 }
1202 else
1203 {
1204 if (is_rela)
1205 {
1206 if (do_wide)
1207 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1208 else
1209 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1210 }
1211 else
1212 {
1213 if (do_wide)
1214 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1215 else
1216 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1217 }
1218 }
1219
1220 for (i = 0; i < rel_size; i++)
1221 {
1222 const char * rtype;
1223 bfd_vma offset;
1224 bfd_vma inf;
1225 bfd_vma symtab_index;
1226 bfd_vma type;
1227
1228 offset = rels[i].r_offset;
1229 inf = rels[i].r_info;
1230
1231 type = get_reloc_type (filedata, inf);
1232 symtab_index = get_reloc_symindex (inf);
1233
1234 if (is_32bit_elf)
1235 {
1236 printf ("%8.8lx %8.8lx ",
1237 (unsigned long) offset & 0xffffffff,
1238 (unsigned long) inf & 0xffffffff);
1239 }
1240 else
1241 {
1242 #if BFD_HOST_64BIT_LONG
1243 printf (do_wide
1244 ? "%16.16lx %16.16lx "
1245 : "%12.12lx %12.12lx ",
1246 offset, inf);
1247 #elif BFD_HOST_64BIT_LONG_LONG
1248 #ifndef __MSVCRT__
1249 printf (do_wide
1250 ? "%16.16llx %16.16llx "
1251 : "%12.12llx %12.12llx ",
1252 offset, inf);
1253 #else
1254 printf (do_wide
1255 ? "%16.16I64x %16.16I64x "
1256 : "%12.12I64x %12.12I64x ",
1257 offset, inf);
1258 #endif
1259 #else
1260 printf (do_wide
1261 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1262 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1263 _bfd_int64_high (offset),
1264 _bfd_int64_low (offset),
1265 _bfd_int64_high (inf),
1266 _bfd_int64_low (inf));
1267 #endif
1268 }
1269
1270 switch (filedata->file_header.e_machine)
1271 {
1272 default:
1273 rtype = NULL;
1274 break;
1275
1276 case EM_AARCH64:
1277 rtype = elf_aarch64_reloc_type (type);
1278 break;
1279
1280 case EM_M32R:
1281 case EM_CYGNUS_M32R:
1282 rtype = elf_m32r_reloc_type (type);
1283 break;
1284
1285 case EM_386:
1286 case EM_IAMCU:
1287 rtype = elf_i386_reloc_type (type);
1288 break;
1289
1290 case EM_68HC11:
1291 case EM_68HC12:
1292 rtype = elf_m68hc11_reloc_type (type);
1293 break;
1294
1295 case EM_S12Z:
1296 rtype = elf_s12z_reloc_type (type);
1297 break;
1298
1299 case EM_68K:
1300 rtype = elf_m68k_reloc_type (type);
1301 break;
1302
1303 case EM_960:
1304 rtype = elf_i960_reloc_type (type);
1305 break;
1306
1307 case EM_AVR:
1308 case EM_AVR_OLD:
1309 rtype = elf_avr_reloc_type (type);
1310 break;
1311
1312 case EM_OLD_SPARCV9:
1313 case EM_SPARC32PLUS:
1314 case EM_SPARCV9:
1315 case EM_SPARC:
1316 rtype = elf_sparc_reloc_type (type);
1317 break;
1318
1319 case EM_SPU:
1320 rtype = elf_spu_reloc_type (type);
1321 break;
1322
1323 case EM_V800:
1324 rtype = v800_reloc_type (type);
1325 break;
1326 case EM_V850:
1327 case EM_CYGNUS_V850:
1328 rtype = v850_reloc_type (type);
1329 break;
1330
1331 case EM_D10V:
1332 case EM_CYGNUS_D10V:
1333 rtype = elf_d10v_reloc_type (type);
1334 break;
1335
1336 case EM_D30V:
1337 case EM_CYGNUS_D30V:
1338 rtype = elf_d30v_reloc_type (type);
1339 break;
1340
1341 case EM_DLX:
1342 rtype = elf_dlx_reloc_type (type);
1343 break;
1344
1345 case EM_SH:
1346 rtype = elf_sh_reloc_type (type);
1347 break;
1348
1349 case EM_MN10300:
1350 case EM_CYGNUS_MN10300:
1351 rtype = elf_mn10300_reloc_type (type);
1352 break;
1353
1354 case EM_MN10200:
1355 case EM_CYGNUS_MN10200:
1356 rtype = elf_mn10200_reloc_type (type);
1357 break;
1358
1359 case EM_FR30:
1360 case EM_CYGNUS_FR30:
1361 rtype = elf_fr30_reloc_type (type);
1362 break;
1363
1364 case EM_CYGNUS_FRV:
1365 rtype = elf_frv_reloc_type (type);
1366 break;
1367
1368 case EM_CSKY:
1369 rtype = elf_csky_reloc_type (type);
1370 break;
1371
1372 case EM_FT32:
1373 rtype = elf_ft32_reloc_type (type);
1374 break;
1375
1376 case EM_MCORE:
1377 rtype = elf_mcore_reloc_type (type);
1378 break;
1379
1380 case EM_MMIX:
1381 rtype = elf_mmix_reloc_type (type);
1382 break;
1383
1384 case EM_MOXIE:
1385 rtype = elf_moxie_reloc_type (type);
1386 break;
1387
1388 case EM_MSP430:
1389 if (uses_msp430x_relocs (filedata))
1390 {
1391 rtype = elf_msp430x_reloc_type (type);
1392 break;
1393 }
1394 /* Fall through. */
1395 case EM_MSP430_OLD:
1396 rtype = elf_msp430_reloc_type (type);
1397 break;
1398
1399 case EM_NDS32:
1400 rtype = elf_nds32_reloc_type (type);
1401 break;
1402
1403 case EM_PPC:
1404 rtype = elf_ppc_reloc_type (type);
1405 break;
1406
1407 case EM_PPC64:
1408 rtype = elf_ppc64_reloc_type (type);
1409 break;
1410
1411 case EM_MIPS:
1412 case EM_MIPS_RS3_LE:
1413 rtype = elf_mips_reloc_type (type);
1414 break;
1415
1416 case EM_RISCV:
1417 rtype = elf_riscv_reloc_type (type);
1418 break;
1419
1420 case EM_ALPHA:
1421 rtype = elf_alpha_reloc_type (type);
1422 break;
1423
1424 case EM_ARM:
1425 rtype = elf_arm_reloc_type (type);
1426 break;
1427
1428 case EM_ARC:
1429 case EM_ARC_COMPACT:
1430 case EM_ARC_COMPACT2:
1431 rtype = elf_arc_reloc_type (type);
1432 break;
1433
1434 case EM_PARISC:
1435 rtype = elf_hppa_reloc_type (type);
1436 break;
1437
1438 case EM_H8_300:
1439 case EM_H8_300H:
1440 case EM_H8S:
1441 rtype = elf_h8_reloc_type (type);
1442 break;
1443
1444 case EM_OR1K:
1445 rtype = elf_or1k_reloc_type (type);
1446 break;
1447
1448 case EM_PJ:
1449 case EM_PJ_OLD:
1450 rtype = elf_pj_reloc_type (type);
1451 break;
1452 case EM_IA_64:
1453 rtype = elf_ia64_reloc_type (type);
1454 break;
1455
1456 case EM_CRIS:
1457 rtype = elf_cris_reloc_type (type);
1458 break;
1459
1460 case EM_860:
1461 rtype = elf_i860_reloc_type (type);
1462 break;
1463
1464 case EM_X86_64:
1465 case EM_L1OM:
1466 case EM_K1OM:
1467 rtype = elf_x86_64_reloc_type (type);
1468 break;
1469
1470 case EM_S370:
1471 rtype = i370_reloc_type (type);
1472 break;
1473
1474 case EM_S390_OLD:
1475 case EM_S390:
1476 rtype = elf_s390_reloc_type (type);
1477 break;
1478
1479 case EM_SCORE:
1480 rtype = elf_score_reloc_type (type);
1481 break;
1482
1483 case EM_XSTORMY16:
1484 rtype = elf_xstormy16_reloc_type (type);
1485 break;
1486
1487 case EM_CRX:
1488 rtype = elf_crx_reloc_type (type);
1489 break;
1490
1491 case EM_VAX:
1492 rtype = elf_vax_reloc_type (type);
1493 break;
1494
1495 case EM_VISIUM:
1496 rtype = elf_visium_reloc_type (type);
1497 break;
1498
1499 case EM_BPF:
1500 rtype = elf_bpf_reloc_type (type);
1501 break;
1502
1503 case EM_ADAPTEVA_EPIPHANY:
1504 rtype = elf_epiphany_reloc_type (type);
1505 break;
1506
1507 case EM_IP2K:
1508 case EM_IP2K_OLD:
1509 rtype = elf_ip2k_reloc_type (type);
1510 break;
1511
1512 case EM_IQ2000:
1513 rtype = elf_iq2000_reloc_type (type);
1514 break;
1515
1516 case EM_XTENSA_OLD:
1517 case EM_XTENSA:
1518 rtype = elf_xtensa_reloc_type (type);
1519 break;
1520
1521 case EM_LATTICEMICO32:
1522 rtype = elf_lm32_reloc_type (type);
1523 break;
1524
1525 case EM_M32C_OLD:
1526 case EM_M32C:
1527 rtype = elf_m32c_reloc_type (type);
1528 break;
1529
1530 case EM_MT:
1531 rtype = elf_mt_reloc_type (type);
1532 break;
1533
1534 case EM_BLACKFIN:
1535 rtype = elf_bfin_reloc_type (type);
1536 break;
1537
1538 case EM_CYGNUS_MEP:
1539 rtype = elf_mep_reloc_type (type);
1540 break;
1541
1542 case EM_CR16:
1543 rtype = elf_cr16_reloc_type (type);
1544 break;
1545
1546 case EM_MICROBLAZE:
1547 case EM_MICROBLAZE_OLD:
1548 rtype = elf_microblaze_reloc_type (type);
1549 break;
1550
1551 case EM_RL78:
1552 rtype = elf_rl78_reloc_type (type);
1553 break;
1554
1555 case EM_RX:
1556 rtype = elf_rx_reloc_type (type);
1557 break;
1558
1559 case EM_METAG:
1560 rtype = elf_metag_reloc_type (type);
1561 break;
1562
1563 case EM_XC16X:
1564 case EM_C166:
1565 rtype = elf_xc16x_reloc_type (type);
1566 break;
1567
1568 case EM_TI_C6000:
1569 rtype = elf_tic6x_reloc_type (type);
1570 break;
1571
1572 case EM_TILEGX:
1573 rtype = elf_tilegx_reloc_type (type);
1574 break;
1575
1576 case EM_TILEPRO:
1577 rtype = elf_tilepro_reloc_type (type);
1578 break;
1579
1580 case EM_WEBASSEMBLY:
1581 rtype = elf_wasm32_reloc_type (type);
1582 break;
1583
1584 case EM_XGATE:
1585 rtype = elf_xgate_reloc_type (type);
1586 break;
1587
1588 case EM_ALTERA_NIOS2:
1589 rtype = elf_nios2_reloc_type (type);
1590 break;
1591
1592 case EM_TI_PRU:
1593 rtype = elf_pru_reloc_type (type);
1594 break;
1595
1596 case EM_NFP:
1597 if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200)
1598 rtype = elf_nfp3200_reloc_type (type);
1599 else
1600 rtype = elf_nfp_reloc_type (type);
1601 break;
1602
1603 case EM_AMDGPU:
1604 rtype = elf_amdgcn_reloc_type (type);
1605 break;
1606 }
1607
1608 if (rtype == NULL)
1609 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
1610 else
1611 printf (do_wide ? "%-22s" : "%-17.17s", rtype);
1612
1613 if (filedata->file_header.e_machine == EM_ALPHA
1614 && rtype != NULL
1615 && streq (rtype, "R_ALPHA_LITUSE")
1616 && is_rela)
1617 {
1618 switch (rels[i].r_addend)
1619 {
1620 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1621 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1622 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1623 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1624 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1625 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1626 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1627 default: rtype = NULL;
1628 }
1629
1630 if (rtype)
1631 printf (" (%s)", rtype);
1632 else
1633 {
1634 putchar (' ');
1635 printf (_("<unknown addend: %lx>"),
1636 (unsigned long) rels[i].r_addend);
1637 res = FALSE;
1638 }
1639 }
1640 else if (symtab_index)
1641 {
1642 if (symtab == NULL || symtab_index >= nsyms)
1643 {
1644 error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index);
1645 res = FALSE;
1646 }
1647 else
1648 {
1649 Elf_Internal_Sym * psym;
1650 const char * version_string;
1651 enum versioned_symbol_info sym_info;
1652 unsigned short vna_other;
1653
1654 psym = symtab + symtab_index;
1655
1656 version_string
1657 = get_symbol_version_string (filedata, is_dynsym,
1658 strtab, strtablen,
1659 symtab_index,
1660 psym,
1661 &sym_info,
1662 &vna_other);
1663
1664 printf (" ");
1665
1666 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
1667 {
1668 const char * name;
1669 unsigned int len;
1670 unsigned int width = is_32bit_elf ? 8 : 14;
1671
1672 /* Relocations against GNU_IFUNC symbols do not use the value
1673 of the symbol as the address to relocate against. Instead
1674 they invoke the function named by the symbol and use its
1675 result as the address for relocation.
1676
1677 To indicate this to the user, do not display the value of
1678 the symbol in the "Symbols's Value" field. Instead show
1679 its name followed by () as a hint that the symbol is
1680 invoked. */
1681
1682 if (strtab == NULL
1683 || psym->st_name == 0
1684 || psym->st_name >= strtablen)
1685 name = "??";
1686 else
1687 name = strtab + psym->st_name;
1688
1689 len = print_symbol (width, name);
1690 if (version_string)
1691 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1692 version_string);
1693 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
1694 }
1695 else
1696 {
1697 print_vma (psym->st_value, LONG_HEX);
1698
1699 printf (is_32bit_elf ? " " : " ");
1700 }
1701
1702 if (psym->st_name == 0)
1703 {
1704 const char * sec_name = "<null>";
1705 char name_buf[40];
1706
1707 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1708 {
1709 if (psym->st_shndx < filedata->file_header.e_shnum)
1710 sec_name = SECTION_NAME (filedata->section_headers + psym->st_shndx);
1711 else if (psym->st_shndx == SHN_ABS)
1712 sec_name = "ABS";
1713 else if (psym->st_shndx == SHN_COMMON)
1714 sec_name = "COMMON";
1715 else if ((filedata->file_header.e_machine == EM_MIPS
1716 && psym->st_shndx == SHN_MIPS_SCOMMON)
1717 || (filedata->file_header.e_machine == EM_TI_C6000
1718 && psym->st_shndx == SHN_TIC6X_SCOMMON))
1719 sec_name = "SCOMMON";
1720 else if (filedata->file_header.e_machine == EM_MIPS
1721 && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1722 sec_name = "SUNDEF";
1723 else if ((filedata->file_header.e_machine == EM_X86_64
1724 || filedata->file_header.e_machine == EM_L1OM
1725 || filedata->file_header.e_machine == EM_K1OM)
1726 && psym->st_shndx == SHN_X86_64_LCOMMON)
1727 sec_name = "LARGE_COMMON";
1728 else if (filedata->file_header.e_machine == EM_IA_64
1729 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1730 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1731 sec_name = "ANSI_COM";
1732 else if (is_ia64_vms (filedata)
1733 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
1734 sec_name = "VMS_SYMVEC";
1735 else
1736 {
1737 sprintf (name_buf, "<section 0x%x>",
1738 (unsigned int) psym->st_shndx);
1739 sec_name = name_buf;
1740 }
1741 }
1742 print_symbol (22, sec_name);
1743 }
1744 else if (strtab == NULL)
1745 printf (_("<string table index: %3ld>"), psym->st_name);
1746 else if (psym->st_name >= strtablen)
1747 {
1748 error (_("<corrupt string table index: %3ld>"), psym->st_name);
1749 res = FALSE;
1750 }
1751 else
1752 {
1753 print_symbol (22, strtab + psym->st_name);
1754 if (version_string)
1755 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1756 version_string);
1757 }
1758
1759 if (is_rela)
1760 {
1761 bfd_vma off = rels[i].r_addend;
1762
1763 if ((bfd_signed_vma) off < 0)
1764 printf (" - %" BFD_VMA_FMT "x", - off);
1765 else
1766 printf (" + %" BFD_VMA_FMT "x", off);
1767 }
1768 }
1769 }
1770 else if (is_rela)
1771 {
1772 bfd_vma off = rels[i].r_addend;
1773
1774 printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
1775 if ((bfd_signed_vma) off < 0)
1776 printf ("-%" BFD_VMA_FMT "x", - off);
1777 else
1778 printf ("%" BFD_VMA_FMT "x", off);
1779 }
1780
1781 if (filedata->file_header.e_machine == EM_SPARCV9
1782 && rtype != NULL
1783 && streq (rtype, "R_SPARC_OLO10"))
1784 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
1785
1786 putchar ('\n');
1787
1788 #ifdef BFD64
1789 if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
1790 {
1791 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
1792 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
1793 const char * rtype2 = elf_mips_reloc_type (type2);
1794 const char * rtype3 = elf_mips_reloc_type (type3);
1795
1796 printf (" Type2: ");
1797
1798 if (rtype2 == NULL)
1799 printf (_("unrecognized: %-7lx"),
1800 (unsigned long) type2 & 0xffffffff);
1801 else
1802 printf ("%-17.17s", rtype2);
1803
1804 printf ("\n Type3: ");
1805
1806 if (rtype3 == NULL)
1807 printf (_("unrecognized: %-7lx"),
1808 (unsigned long) type3 & 0xffffffff);
1809 else
1810 printf ("%-17.17s", rtype3);
1811
1812 putchar ('\n');
1813 }
1814 #endif /* BFD64 */
1815 }
1816
1817 free (rels);
1818
1819 return res;
1820 }
1821
1822 static const char *
1823 get_aarch64_dynamic_type (unsigned long type)
1824 {
1825 switch (type)
1826 {
1827 case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT";
1828 case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT";
1829 case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS";
1830 default:
1831 return NULL;
1832 }
1833 }
1834
1835 static const char *
1836 get_mips_dynamic_type (unsigned long type)
1837 {
1838 switch (type)
1839 {
1840 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1841 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1842 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1843 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1844 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1845 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1846 case DT_MIPS_MSYM: return "MIPS_MSYM";
1847 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1848 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1849 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1850 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1851 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1852 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1853 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1854 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1855 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1856 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1857 case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
1858 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1859 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1860 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1861 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1862 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1863 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1864 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1865 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1866 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1867 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1868 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1869 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1870 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1871 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1872 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1873 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1874 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1875 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1876 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1877 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1878 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1879 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1880 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1881 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1882 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1883 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1884 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
1885 case DT_MIPS_RWPLT: return "MIPS_RWPLT";
1886 case DT_MIPS_XHASH: return "MIPS_XHASH";
1887 default:
1888 return NULL;
1889 }
1890 }
1891
1892 static const char *
1893 get_sparc64_dynamic_type (unsigned long type)
1894 {
1895 switch (type)
1896 {
1897 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1898 default:
1899 return NULL;
1900 }
1901 }
1902
1903 static const char *
1904 get_ppc_dynamic_type (unsigned long type)
1905 {
1906 switch (type)
1907 {
1908 case DT_PPC_GOT: return "PPC_GOT";
1909 case DT_PPC_OPT: return "PPC_OPT";
1910 default:
1911 return NULL;
1912 }
1913 }
1914
1915 static const char *
1916 get_ppc64_dynamic_type (unsigned long type)
1917 {
1918 switch (type)
1919 {
1920 case DT_PPC64_GLINK: return "PPC64_GLINK";
1921 case DT_PPC64_OPD: return "PPC64_OPD";
1922 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1923 case DT_PPC64_OPT: return "PPC64_OPT";
1924 default:
1925 return NULL;
1926 }
1927 }
1928
1929 static const char *
1930 get_parisc_dynamic_type (unsigned long type)
1931 {
1932 switch (type)
1933 {
1934 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1935 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1936 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1937 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1938 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1939 case DT_HP_PREINIT: return "HP_PREINIT";
1940 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1941 case DT_HP_NEEDED: return "HP_NEEDED";
1942 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1943 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1944 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1945 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1946 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1947 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1948 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1949 case DT_HP_FILTERED: return "HP_FILTERED";
1950 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1951 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1952 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1953 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1954 case DT_PLT: return "PLT";
1955 case DT_PLT_SIZE: return "PLT_SIZE";
1956 case DT_DLT: return "DLT";
1957 case DT_DLT_SIZE: return "DLT_SIZE";
1958 default:
1959 return NULL;
1960 }
1961 }
1962
1963 static const char *
1964 get_ia64_dynamic_type (unsigned long type)
1965 {
1966 switch (type)
1967 {
1968 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1969 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
1970 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
1971 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
1972 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
1973 case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
1974 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
1975 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
1976 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
1977 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
1978 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
1979 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
1980 case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
1981 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
1982 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
1983 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
1984 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
1985 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
1986 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
1987 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
1988 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
1989 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
1990 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
1991 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
1992 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
1993 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
1994 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
1995 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
1996 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
1997 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
1998 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
1999 default:
2000 return NULL;
2001 }
2002 }
2003
2004 static const char *
2005 get_solaris_section_type (unsigned long type)
2006 {
2007 switch (type)
2008 {
2009 case 0x6fffffee: return "SUNW_ancillary";
2010 case 0x6fffffef: return "SUNW_capchain";
2011 case 0x6ffffff0: return "SUNW_capinfo";
2012 case 0x6ffffff1: return "SUNW_symsort";
2013 case 0x6ffffff2: return "SUNW_tlssort";
2014 case 0x6ffffff3: return "SUNW_LDYNSYM";
2015 case 0x6ffffff4: return "SUNW_dof";
2016 case 0x6ffffff5: return "SUNW_cap";
2017 case 0x6ffffff6: return "SUNW_SIGNATURE";
2018 case 0x6ffffff7: return "SUNW_ANNOTATE";
2019 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2020 case 0x6ffffff9: return "SUNW_DEBUG";
2021 case 0x6ffffffa: return "SUNW_move";
2022 case 0x6ffffffb: return "SUNW_COMDAT";
2023 case 0x6ffffffc: return "SUNW_syminfo";
2024 case 0x6ffffffd: return "SUNW_verdef";
2025 case 0x6ffffffe: return "SUNW_verneed";
2026 case 0x6fffffff: return "SUNW_versym";
2027 case 0x70000000: return "SPARC_GOTDATA";
2028 default: return NULL;
2029 }
2030 }
2031
2032 static const char *
2033 get_alpha_dynamic_type (unsigned long type)
2034 {
2035 switch (type)
2036 {
2037 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
2038 default: return NULL;
2039 }
2040 }
2041
2042 static const char *
2043 get_score_dynamic_type (unsigned long type)
2044 {
2045 switch (type)
2046 {
2047 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
2048 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
2049 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
2050 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
2051 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
2052 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
2053 default: return NULL;
2054 }
2055 }
2056
2057 static const char *
2058 get_tic6x_dynamic_type (unsigned long type)
2059 {
2060 switch (type)
2061 {
2062 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
2063 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
2064 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
2065 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
2066 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
2067 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
2068 default: return NULL;
2069 }
2070 }
2071
2072 static const char *
2073 get_nios2_dynamic_type (unsigned long type)
2074 {
2075 switch (type)
2076 {
2077 case DT_NIOS2_GP: return "NIOS2_GP";
2078 default: return NULL;
2079 }
2080 }
2081
2082 static const char *
2083 get_solaris_dynamic_type (unsigned long type)
2084 {
2085 switch (type)
2086 {
2087 case 0x6000000d: return "SUNW_AUXILIARY";
2088 case 0x6000000e: return "SUNW_RTLDINF";
2089 case 0x6000000f: return "SUNW_FILTER";
2090 case 0x60000010: return "SUNW_CAP";
2091 case 0x60000011: return "SUNW_SYMTAB";
2092 case 0x60000012: return "SUNW_SYMSZ";
2093 case 0x60000013: return "SUNW_SORTENT";
2094 case 0x60000014: return "SUNW_SYMSORT";
2095 case 0x60000015: return "SUNW_SYMSORTSZ";
2096 case 0x60000016: return "SUNW_TLSSORT";
2097 case 0x60000017: return "SUNW_TLSSORTSZ";
2098 case 0x60000018: return "SUNW_CAPINFO";
2099 case 0x60000019: return "SUNW_STRPAD";
2100 case 0x6000001a: return "SUNW_CAPCHAIN";
2101 case 0x6000001b: return "SUNW_LDMACH";
2102 case 0x6000001d: return "SUNW_CAPCHAINENT";
2103 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2104 case 0x60000021: return "SUNW_PARENT";
2105 case 0x60000023: return "SUNW_ASLR";
2106 case 0x60000025: return "SUNW_RELAX";
2107 case 0x60000029: return "SUNW_NXHEAP";
2108 case 0x6000002b: return "SUNW_NXSTACK";
2109
2110 case 0x70000001: return "SPARC_REGISTER";
2111 case 0x7ffffffd: return "AUXILIARY";
2112 case 0x7ffffffe: return "USED";
2113 case 0x7fffffff: return "FILTER";
2114
2115 default: return NULL;
2116 }
2117 }
2118
2119 static const char *
2120 get_dynamic_type (Filedata * filedata, unsigned long type)
2121 {
2122 static char buff[64];
2123
2124 switch (type)
2125 {
2126 case DT_NULL: return "NULL";
2127 case DT_NEEDED: return "NEEDED";
2128 case DT_PLTRELSZ: return "PLTRELSZ";
2129 case DT_PLTGOT: return "PLTGOT";
2130 case DT_HASH: return "HASH";
2131 case DT_STRTAB: return "STRTAB";
2132 case DT_SYMTAB: return "SYMTAB";
2133 case DT_RELA: return "RELA";
2134 case DT_RELASZ: return "RELASZ";
2135 case DT_RELAENT: return "RELAENT";
2136 case DT_STRSZ: return "STRSZ";
2137 case DT_SYMENT: return "SYMENT";
2138 case DT_INIT: return "INIT";
2139 case DT_FINI: return "FINI";
2140 case DT_SONAME: return "SONAME";
2141 case DT_RPATH: return "RPATH";
2142 case DT_SYMBOLIC: return "SYMBOLIC";
2143 case DT_REL: return "REL";
2144 case DT_RELSZ: return "RELSZ";
2145 case DT_RELENT: return "RELENT";
2146 case DT_PLTREL: return "PLTREL";
2147 case DT_DEBUG: return "DEBUG";
2148 case DT_TEXTREL: return "TEXTREL";
2149 case DT_JMPREL: return "JMPREL";
2150 case DT_BIND_NOW: return "BIND_NOW";
2151 case DT_INIT_ARRAY: return "INIT_ARRAY";
2152 case DT_FINI_ARRAY: return "FINI_ARRAY";
2153 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
2154 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
2155 case DT_RUNPATH: return "RUNPATH";
2156 case DT_FLAGS: return "FLAGS";
2157
2158 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2159 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
2160 case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX";
2161
2162 case DT_CHECKSUM: return "CHECKSUM";
2163 case DT_PLTPADSZ: return "PLTPADSZ";
2164 case DT_MOVEENT: return "MOVEENT";
2165 case DT_MOVESZ: return "MOVESZ";
2166 case DT_FEATURE: return "FEATURE";
2167 case DT_POSFLAG_1: return "POSFLAG_1";
2168 case DT_SYMINSZ: return "SYMINSZ";
2169 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
2170
2171 case DT_ADDRRNGLO: return "ADDRRNGLO";
2172 case DT_CONFIG: return "CONFIG";
2173 case DT_DEPAUDIT: return "DEPAUDIT";
2174 case DT_AUDIT: return "AUDIT";
2175 case DT_PLTPAD: return "PLTPAD";
2176 case DT_MOVETAB: return "MOVETAB";
2177 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
2178
2179 case DT_VERSYM: return "VERSYM";
2180
2181 case DT_TLSDESC_GOT: return "TLSDESC_GOT";
2182 case DT_TLSDESC_PLT: return "TLSDESC_PLT";
2183 case DT_RELACOUNT: return "RELACOUNT";
2184 case DT_RELCOUNT: return "RELCOUNT";
2185 case DT_FLAGS_1: return "FLAGS_1";
2186 case DT_VERDEF: return "VERDEF";
2187 case DT_VERDEFNUM: return "VERDEFNUM";
2188 case DT_VERNEED: return "VERNEED";
2189 case DT_VERNEEDNUM: return "VERNEEDNUM";
2190
2191 case DT_AUXILIARY: return "AUXILIARY";
2192 case DT_USED: return "USED";
2193 case DT_FILTER: return "FILTER";
2194
2195 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
2196 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
2197 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
2198 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
2199 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
2200 case DT_GNU_HASH: return "GNU_HASH";
2201
2202 default:
2203 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
2204 {
2205 const char * result;
2206
2207 switch (filedata->file_header.e_machine)
2208 {
2209 case EM_AARCH64:
2210 result = get_aarch64_dynamic_type (type);
2211 break;
2212 case EM_MIPS:
2213 case EM_MIPS_RS3_LE:
2214 result = get_mips_dynamic_type (type);
2215 break;
2216 case EM_SPARCV9:
2217 result = get_sparc64_dynamic_type (type);
2218 break;
2219 case EM_PPC:
2220 result = get_ppc_dynamic_type (type);
2221 break;
2222 case EM_PPC64:
2223 result = get_ppc64_dynamic_type (type);
2224 break;
2225 case EM_IA_64:
2226 result = get_ia64_dynamic_type (type);
2227 break;
2228 case EM_ALPHA:
2229 result = get_alpha_dynamic_type (type);
2230 break;
2231 case EM_SCORE:
2232 result = get_score_dynamic_type (type);
2233 break;
2234 case EM_TI_C6000:
2235 result = get_tic6x_dynamic_type (type);
2236 break;
2237 case EM_ALTERA_NIOS2:
2238 result = get_nios2_dynamic_type (type);
2239 break;
2240 default:
2241 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
2242 result = get_solaris_dynamic_type (type);
2243 else
2244 result = NULL;
2245 break;
2246 }
2247
2248 if (result != NULL)
2249 return result;
2250
2251 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
2252 }
2253 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
2254 || (filedata->file_header.e_machine == EM_PARISC
2255 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
2256 {
2257 const char * result;
2258
2259 switch (filedata->file_header.e_machine)
2260 {
2261 case EM_PARISC:
2262 result = get_parisc_dynamic_type (type);
2263 break;
2264 case EM_IA_64:
2265 result = get_ia64_dynamic_type (type);
2266 break;
2267 default:
2268 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
2269 result = get_solaris_dynamic_type (type);
2270 else
2271 result = NULL;
2272 break;
2273 }
2274
2275 if (result != NULL)
2276 return result;
2277
2278 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
2279 type);
2280 }
2281 else
2282 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
2283
2284 return buff;
2285 }
2286 }
2287
2288 static char *
2289 get_file_type (unsigned e_type)
2290 {
2291 static char buff[32];
2292
2293 switch (e_type)
2294 {
2295 case ET_NONE: return _("NONE (None)");
2296 case ET_REL: return _("REL (Relocatable file)");
2297 case ET_EXEC: return _("EXEC (Executable file)");
2298 case ET_DYN: return _("DYN (Shared object file)");
2299 case ET_CORE: return _("CORE (Core file)");
2300
2301 default:
2302 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
2303 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
2304 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
2305 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
2306 else
2307 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
2308 return buff;
2309 }
2310 }
2311
2312 static char *
2313 get_machine_name (unsigned e_machine)
2314 {
2315 static char buff[64]; /* XXX */
2316
2317 switch (e_machine)
2318 {
2319 /* Please keep this switch table sorted by increasing EM_ value. */
2320 /* 0 */
2321 case EM_NONE: return _("None");
2322 case EM_M32: return "WE32100";
2323 case EM_SPARC: return "Sparc";
2324 case EM_386: return "Intel 80386";
2325 case EM_68K: return "MC68000";
2326 case EM_88K: return "MC88000";
2327 case EM_IAMCU: return "Intel MCU";
2328 case EM_860: return "Intel 80860";
2329 case EM_MIPS: return "MIPS R3000";
2330 case EM_S370: return "IBM System/370";
2331 /* 10 */
2332 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
2333 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
2334 case EM_PARISC: return "HPPA";
2335 case EM_VPP550: return "Fujitsu VPP500";
2336 case EM_SPARC32PLUS: return "Sparc v8+" ;
2337 case EM_960: return "Intel 80960";
2338 case EM_PPC: return "PowerPC";
2339 /* 20 */
2340 case EM_PPC64: return "PowerPC64";
2341 case EM_S390_OLD:
2342 case EM_S390: return "IBM S/390";
2343 case EM_SPU: return "SPU";
2344 /* 30 */
2345 case EM_V800: return "Renesas V850 (using RH850 ABI)";
2346 case EM_FR20: return "Fujitsu FR20";
2347 case EM_RH32: return "TRW RH32";
2348 case EM_MCORE: return "MCORE";
2349 /* 40 */
2350 case EM_ARM: return "ARM";
2351 case EM_OLD_ALPHA: return "Digital Alpha (old)";
2352 case EM_SH: return "Renesas / SuperH SH";
2353 case EM_SPARCV9: return "Sparc v9";
2354 case EM_TRICORE: return "Siemens Tricore";
2355 case EM_ARC: return "ARC";
2356 case EM_H8_300: return "Renesas H8/300";
2357 case EM_H8_300H: return "Renesas H8/300H";
2358 case EM_H8S: return "Renesas H8S";
2359 case EM_H8_500: return "Renesas H8/500";
2360 /* 50 */
2361 case EM_IA_64: return "Intel IA-64";
2362 case EM_MIPS_X: return "Stanford MIPS-X";
2363 case EM_COLDFIRE: return "Motorola Coldfire";
2364 case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
2365 case EM_MMA: return "Fujitsu Multimedia Accelerator";
2366 case EM_PCP: return "Siemens PCP";
2367 case EM_NCPU: return "Sony nCPU embedded RISC processor";
2368 case EM_NDR1: return "Denso NDR1 microprocesspr";
2369 case EM_STARCORE: return "Motorola Star*Core processor";
2370 case EM_ME16: return "Toyota ME16 processor";
2371 /* 60 */
2372 case EM_ST100: return "STMicroelectronics ST100 processor";
2373 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
2374 case EM_X86_64: return "Advanced Micro Devices X86-64";
2375 case EM_PDSP: return "Sony DSP processor";
2376 case EM_PDP10: return "Digital Equipment Corp. PDP-10";
2377 case EM_PDP11: return "Digital Equipment Corp. PDP-11";
2378 case EM_FX66: return "Siemens FX66 microcontroller";
2379 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2380 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
2381 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
2382 /* 70 */
2383 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
2384 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
2385 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
2386 case EM_SVX: return "Silicon Graphics SVx";
2387 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
2388 case EM_VAX: return "Digital VAX";
2389 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
2390 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
2391 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
2392 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
2393 /* 80 */
2394 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
2395 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
2396 case EM_PRISM: return "Vitesse Prism";
2397 case EM_AVR_OLD:
2398 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
2399 case EM_CYGNUS_FR30:
2400 case EM_FR30: return "Fujitsu FR30";
2401 case EM_CYGNUS_D10V:
2402 case EM_D10V: return "d10v";
2403 case EM_CYGNUS_D30V:
2404 case EM_D30V: return "d30v";
2405 case EM_CYGNUS_V850:
2406 case EM_V850: return "Renesas V850";
2407 case EM_CYGNUS_M32R:
2408 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
2409 case EM_CYGNUS_MN10300:
2410 case EM_MN10300: return "mn10300";
2411 /* 90 */
2412 case EM_CYGNUS_MN10200:
2413 case EM_MN10200: return "mn10200";
2414 case EM_PJ: return "picoJava";
2415 case EM_OR1K: return "OpenRISC 1000";
2416 case EM_ARC_COMPACT: return "ARCompact";
2417 case EM_XTENSA_OLD:
2418 case EM_XTENSA: return "Tensilica Xtensa Processor";
2419 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
2420 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
2421 case EM_NS32K: return "National Semiconductor 32000 series";
2422 case EM_TPC: return "Tenor Network TPC processor";
2423 case EM_SNP1K: return "Trebia SNP 1000 processor";
2424 /* 100 */
2425 case EM_ST200: return "STMicroelectronics ST200 microcontroller";
2426 case EM_IP2K_OLD:
2427 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
2428 case EM_MAX: return "MAX Processor";
2429 case EM_CR: return "National Semiconductor CompactRISC";
2430 case EM_F2MC16: return "Fujitsu F2MC16";
2431 case EM_MSP430: return "Texas Instruments msp430 microcontroller";
2432 case EM_BLACKFIN: return "Analog Devices Blackfin";
2433 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
2434 case EM_SEP: return "Sharp embedded microprocessor";
2435 case EM_ARCA: return "Arca RISC microprocessor";
2436 /* 110 */
2437 case EM_UNICORE: return "Unicore";
2438 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
2439 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
2440 case EM_ALTERA_NIOS2: return "Altera Nios II";
2441 case EM_CRX: return "National Semiconductor CRX microprocessor";
2442 case EM_XGATE: return "Motorola XGATE embedded processor";
2443 case EM_C166:
2444 case EM_XC16X: return "Infineon Technologies xc16x";
2445 case EM_M16C: return "Renesas M16C series microprocessors";
2446 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
2447 case EM_CE: return "Freescale Communication Engine RISC core";
2448 /* 120 */
2449 case EM_M32C: return "Renesas M32c";
2450 /* 130 */
2451 case EM_TSK3000: return "Altium TSK3000 core";
2452 case EM_RS08: return "Freescale RS08 embedded processor";
2453 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
2454 case EM_SCORE: return "SUNPLUS S+Core";
2455 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
2456 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
2457 case EM_LATTICEMICO32: return "Lattice Mico32";
2458 case EM_SE_C17: return "Seiko Epson C17 family";
2459 /* 140 */
2460 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
2461 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
2462 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
2463 case EM_TI_PRU: return "TI PRU I/O processor";
2464 /* 160 */
2465 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2466 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
2467 case EM_R32C: return "Renesas R32C series microprocessors";
2468 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
2469 case EM_QDSP6: return "QUALCOMM DSP6 Processor";
2470 case EM_8051: return "Intel 8051 and variants";
2471 case EM_STXP7X: return "STMicroelectronics STxP7x family";
2472 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
2473 case EM_ECOG1X: return "Cyan Technology eCOG1X family";
2474 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2475 /* 170 */
2476 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
2477 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
2478 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
2479 case EM_RX: return "Renesas RX";
2480 case EM_METAG: return "Imagination Technologies Meta processor architecture";
2481 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
2482 case EM_ECOG16: return "Cyan Technology eCOG16 family";
2483 case EM_CR16:
2484 case EM_MICROBLAZE:
2485 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
2486 case EM_ETPU: return "Freescale Extended Time Processing Unit";
2487 case EM_SLE9X: return "Infineon Technologies SLE9X core";
2488 /* 180 */
2489 case EM_L1OM: return "Intel L1OM";
2490 case EM_K1OM: return "Intel K1OM";
2491 case EM_INTEL182: return "Intel (reserved)";
2492 case EM_AARCH64: return "AArch64";
2493 case EM_ARM184: return "ARM (reserved)";
2494 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor";
2495 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
2496 case EM_TILE64: return "Tilera TILE64 multicore architecture family";
2497 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
2498 /* 190 */
2499 case EM_CUDA: return "NVIDIA CUDA architecture";
2500 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
2501 case EM_CLOUDSHIELD: return "CloudShield architecture family";
2502 case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family";
2503 case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family";
2504 case EM_ARC_COMPACT2: return "ARCv2";
2505 case EM_OPEN8: return "Open8 8-bit RISC soft processor core";
2506 case EM_RL78: return "Renesas RL78";
2507 case EM_VIDEOCORE5: return "Broadcom VideoCore V processor";
2508 case EM_78K0R: return "Renesas 78K0R";
2509 /* 200 */
2510 case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)";
2511 case EM_BA1: return "Beyond BA1 CPU architecture";
2512 case EM_BA2: return "Beyond BA2 CPU architecture";
2513 case EM_XCORE: return "XMOS xCORE processor family";
2514 case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family";
2515 /* 210 */
2516 case EM_KM32: return "KM211 KM32 32-bit processor";
2517 case EM_KMX32: return "KM211 KMX32 32-bit processor";
2518 case EM_KMX16: return "KM211 KMX16 16-bit processor";
2519 case EM_KMX8: return "KM211 KMX8 8-bit processor";
2520 case EM_KVARC: return "KM211 KVARC processor";
2521 case EM_CDP: return "Paneve CDP architecture family";
2522 case EM_COGE: return "Cognitive Smart Memory Processor";
2523 case EM_COOL: return "Bluechip Systems CoolEngine";
2524 case EM_NORC: return "Nanoradio Optimized RISC";
2525 case EM_CSR_KALIMBA: return "CSR Kalimba architecture family";
2526 /* 220 */
2527 case EM_Z80: return "Zilog Z80";
2528 case EM_VISIUM: return "CDS VISIUMcore processor";
2529 case EM_FT32: return "FTDI Chip FT32";
2530 case EM_MOXIE: return "Moxie";
2531 case EM_AMDGPU: return "AMD GPU";
2532 case EM_RISCV: return "RISC-V";
2533 case EM_LANAI: return "Lanai 32-bit processor";
2534 case EM_BPF: return "Linux BPF";
2535 case EM_NFP: return "Netronome Flow Processor";
2536
2537 /* Large numbers... */
2538 case EM_MT: return "Morpho Techologies MT processor";
2539 case EM_ALPHA: return "Alpha";
2540 case EM_WEBASSEMBLY: return "Web Assembly";
2541 case EM_DLX: return "OpenDLX";
2542 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
2543 case EM_IQ2000: return "Vitesse IQ2000";
2544 case EM_M32C_OLD:
2545 case EM_NIOS32: return "Altera Nios";
2546 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
2547 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
2548 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
2549 case EM_S12Z: return "Freescale S12Z";
2550 case EM_CSKY: return "C-SKY";
2551
2552 default:
2553 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
2554 return buff;
2555 }
2556 }
2557
2558 static void
2559 decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
2560 {
2561 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2562 other compilers don't a specific architecture type in the e_flags, and
2563 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2564 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2565 architectures.
2566
2567 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2568 but also sets a specific architecture type in the e_flags field.
2569
2570 However, when decoding the flags we don't worry if we see an
2571 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2572 ARCEM architecture type. */
2573
2574 switch (e_flags & EF_ARC_MACH_MSK)
2575 {
2576 /* We only expect these to occur for EM_ARC_COMPACT2. */
2577 case EF_ARC_CPU_ARCV2EM:
2578 strcat (buf, ", ARC EM");
2579 break;
2580 case EF_ARC_CPU_ARCV2HS:
2581 strcat (buf, ", ARC HS");
2582 break;
2583
2584 /* We only expect these to occur for EM_ARC_COMPACT. */
2585 case E_ARC_MACH_ARC600:
2586 strcat (buf, ", ARC600");
2587 break;
2588 case E_ARC_MACH_ARC601:
2589 strcat (buf, ", ARC601");
2590 break;
2591 case E_ARC_MACH_ARC700:
2592 strcat (buf, ", ARC700");
2593 break;
2594
2595 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2596 new ELF with new architecture being read by an old version of
2597 readelf, or (c) An ELF built with non-GNU compiler that does not
2598 set the architecture in the e_flags. */
2599 default:
2600 if (e_machine == EM_ARC_COMPACT)
2601 strcat (buf, ", Unknown ARCompact");
2602 else
2603 strcat (buf, ", Unknown ARC");
2604 break;
2605 }
2606
2607 switch (e_flags & EF_ARC_OSABI_MSK)
2608 {
2609 case E_ARC_OSABI_ORIG:
2610 strcat (buf, ", (ABI:legacy)");
2611 break;
2612 case E_ARC_OSABI_V2:
2613 strcat (buf, ", (ABI:v2)");
2614 break;
2615 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2616 case E_ARC_OSABI_V3:
2617 strcat (buf, ", v3 no-legacy-syscalls ABI");
2618 break;
2619 case E_ARC_OSABI_V4:
2620 strcat (buf, ", v4 ABI");
2621 break;
2622 default:
2623 strcat (buf, ", unrecognised ARC OSABI flag");
2624 break;
2625 }
2626 }
2627
2628 static void
2629 decode_ARM_machine_flags (unsigned e_flags, char buf[])
2630 {
2631 unsigned eabi;
2632 bfd_boolean unknown = FALSE;
2633
2634 eabi = EF_ARM_EABI_VERSION (e_flags);
2635 e_flags &= ~ EF_ARM_EABIMASK;
2636
2637 /* Handle "generic" ARM flags. */
2638 if (e_flags & EF_ARM_RELEXEC)
2639 {
2640 strcat (buf, ", relocatable executable");
2641 e_flags &= ~ EF_ARM_RELEXEC;
2642 }
2643
2644 if (e_flags & EF_ARM_PIC)
2645 {
2646 strcat (buf, ", position independent");
2647 e_flags &= ~ EF_ARM_PIC;
2648 }
2649
2650 /* Now handle EABI specific flags. */
2651 switch (eabi)
2652 {
2653 default:
2654 strcat (buf, ", <unrecognized EABI>");
2655 if (e_flags)
2656 unknown = TRUE;
2657 break;
2658
2659 case EF_ARM_EABI_VER1:
2660 strcat (buf, ", Version1 EABI");
2661 while (e_flags)
2662 {
2663 unsigned flag;
2664
2665 /* Process flags one bit at a time. */
2666 flag = e_flags & - e_flags;
2667 e_flags &= ~ flag;
2668
2669 switch (flag)
2670 {
2671 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2672 strcat (buf, ", sorted symbol tables");
2673 break;
2674
2675 default:
2676 unknown = TRUE;
2677 break;
2678 }
2679 }
2680 break;
2681
2682 case EF_ARM_EABI_VER2:
2683 strcat (buf, ", Version2 EABI");
2684 while (e_flags)
2685 {
2686 unsigned flag;
2687
2688 /* Process flags one bit at a time. */
2689 flag = e_flags & - e_flags;
2690 e_flags &= ~ flag;
2691
2692 switch (flag)
2693 {
2694 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2695 strcat (buf, ", sorted symbol tables");
2696 break;
2697
2698 case EF_ARM_DYNSYMSUSESEGIDX:
2699 strcat (buf, ", dynamic symbols use segment index");
2700 break;
2701
2702 case EF_ARM_MAPSYMSFIRST:
2703 strcat (buf, ", mapping symbols precede others");
2704 break;
2705
2706 default:
2707 unknown = TRUE;
2708 break;
2709 }
2710 }
2711 break;
2712
2713 case EF_ARM_EABI_VER3:
2714 strcat (buf, ", Version3 EABI");
2715 break;
2716
2717 case EF_ARM_EABI_VER4:
2718 strcat (buf, ", Version4 EABI");
2719 while (e_flags)
2720 {
2721 unsigned flag;
2722
2723 /* Process flags one bit at a time. */
2724 flag = e_flags & - e_flags;
2725 e_flags &= ~ flag;
2726
2727 switch (flag)
2728 {
2729 case EF_ARM_BE8:
2730 strcat (buf, ", BE8");
2731 break;
2732
2733 case EF_ARM_LE8:
2734 strcat (buf, ", LE8");
2735 break;
2736
2737 default:
2738 unknown = TRUE;
2739 break;
2740 }
2741 }
2742 break;
2743
2744 case EF_ARM_EABI_VER5:
2745 strcat (buf, ", Version5 EABI");
2746 while (e_flags)
2747 {
2748 unsigned flag;
2749
2750 /* Process flags one bit at a time. */
2751 flag = e_flags & - e_flags;
2752 e_flags &= ~ flag;
2753
2754 switch (flag)
2755 {
2756 case EF_ARM_BE8:
2757 strcat (buf, ", BE8");
2758 break;
2759
2760 case EF_ARM_LE8:
2761 strcat (buf, ", LE8");
2762 break;
2763
2764 case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2765 strcat (buf, ", soft-float ABI");
2766 break;
2767
2768 case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
2769 strcat (buf, ", hard-float ABI");
2770 break;
2771
2772 default:
2773 unknown = TRUE;
2774 break;
2775 }
2776 }
2777 break;
2778
2779 case EF_ARM_EABI_UNKNOWN:
2780 strcat (buf, ", GNU EABI");
2781 while (e_flags)
2782 {
2783 unsigned flag;
2784
2785 /* Process flags one bit at a time. */
2786 flag = e_flags & - e_flags;
2787 e_flags &= ~ flag;
2788
2789 switch (flag)
2790 {
2791 case EF_ARM_INTERWORK:
2792 strcat (buf, ", interworking enabled");
2793 break;
2794
2795 case EF_ARM_APCS_26:
2796 strcat (buf, ", uses APCS/26");
2797 break;
2798
2799 case EF_ARM_APCS_FLOAT:
2800 strcat (buf, ", uses APCS/float");
2801 break;
2802
2803 case EF_ARM_PIC:
2804 strcat (buf, ", position independent");
2805 break;
2806
2807 case EF_ARM_ALIGN8:
2808 strcat (buf, ", 8 bit structure alignment");
2809 break;
2810
2811 case EF_ARM_NEW_ABI:
2812 strcat (buf, ", uses new ABI");
2813 break;
2814
2815 case EF_ARM_OLD_ABI:
2816 strcat (buf, ", uses old ABI");
2817 break;
2818
2819 case EF_ARM_SOFT_FLOAT:
2820 strcat (buf, ", software FP");
2821 break;
2822
2823 case EF_ARM_VFP_FLOAT:
2824 strcat (buf, ", VFP");
2825 break;
2826
2827 case EF_ARM_MAVERICK_FLOAT:
2828 strcat (buf, ", Maverick FP");
2829 break;
2830
2831 default:
2832 unknown = TRUE;
2833 break;
2834 }
2835 }
2836 }
2837
2838 if (unknown)
2839 strcat (buf,_(", <unknown>"));
2840 }
2841
2842 static void
2843 decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
2844 {
2845 --size; /* Leave space for null terminator. */
2846
2847 switch (e_flags & EF_AVR_MACH)
2848 {
2849 case E_AVR_MACH_AVR1:
2850 strncat (buf, ", avr:1", size);
2851 break;
2852 case E_AVR_MACH_AVR2:
2853 strncat (buf, ", avr:2", size);
2854 break;
2855 case E_AVR_MACH_AVR25:
2856 strncat (buf, ", avr:25", size);
2857 break;
2858 case E_AVR_MACH_AVR3:
2859 strncat (buf, ", avr:3", size);
2860 break;
2861 case E_AVR_MACH_AVR31:
2862 strncat (buf, ", avr:31", size);
2863 break;
2864 case E_AVR_MACH_AVR35:
2865 strncat (buf, ", avr:35", size);
2866 break;
2867 case E_AVR_MACH_AVR4:
2868 strncat (buf, ", avr:4", size);
2869 break;
2870 case E_AVR_MACH_AVR5:
2871 strncat (buf, ", avr:5", size);
2872 break;
2873 case E_AVR_MACH_AVR51:
2874 strncat (buf, ", avr:51", size);
2875 break;
2876 case E_AVR_MACH_AVR6:
2877 strncat (buf, ", avr:6", size);
2878 break;
2879 case E_AVR_MACH_AVRTINY:
2880 strncat (buf, ", avr:100", size);
2881 break;
2882 case E_AVR_MACH_XMEGA1:
2883 strncat (buf, ", avr:101", size);
2884 break;
2885 case E_AVR_MACH_XMEGA2:
2886 strncat (buf, ", avr:102", size);
2887 break;
2888 case E_AVR_MACH_XMEGA3:
2889 strncat (buf, ", avr:103", size);
2890 break;
2891 case E_AVR_MACH_XMEGA4:
2892 strncat (buf, ", avr:104", size);
2893 break;
2894 case E_AVR_MACH_XMEGA5:
2895 strncat (buf, ", avr:105", size);
2896 break;
2897 case E_AVR_MACH_XMEGA6:
2898 strncat (buf, ", avr:106", size);
2899 break;
2900 case E_AVR_MACH_XMEGA7:
2901 strncat (buf, ", avr:107", size);
2902 break;
2903 default:
2904 strncat (buf, ", avr:<unknown>", size);
2905 break;
2906 }
2907
2908 size -= strlen (buf);
2909 if (e_flags & EF_AVR_LINKRELAX_PREPARED)
2910 strncat (buf, ", link-relax", size);
2911 }
2912
2913 static void
2914 decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
2915 {
2916 unsigned abi;
2917 unsigned arch;
2918 unsigned config;
2919 unsigned version;
2920 bfd_boolean has_fpu = FALSE;
2921 unsigned int r = 0;
2922
2923 static const char *ABI_STRINGS[] =
2924 {
2925 "ABI v0", /* use r5 as return register; only used in N1213HC */
2926 "ABI v1", /* use r0 as return register */
2927 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2928 "ABI v2fp", /* for FPU */
2929 "AABI",
2930 "ABI2 FP+"
2931 };
2932 static const char *VER_STRINGS[] =
2933 {
2934 "Andes ELF V1.3 or older",
2935 "Andes ELF V1.3.1",
2936 "Andes ELF V1.4"
2937 };
2938 static const char *ARCH_STRINGS[] =
2939 {
2940 "",
2941 "Andes Star v1.0",
2942 "Andes Star v2.0",
2943 "Andes Star v3.0",
2944 "Andes Star v3.0m"
2945 };
2946
2947 abi = EF_NDS_ABI & e_flags;
2948 arch = EF_NDS_ARCH & e_flags;
2949 config = EF_NDS_INST & e_flags;
2950 version = EF_NDS32_ELF_VERSION & e_flags;
2951
2952 memset (buf, 0, size);
2953
2954 switch (abi)
2955 {
2956 case E_NDS_ABI_V0:
2957 case E_NDS_ABI_V1:
2958 case E_NDS_ABI_V2:
2959 case E_NDS_ABI_V2FP:
2960 case E_NDS_ABI_AABI:
2961 case E_NDS_ABI_V2FP_PLUS:
2962 /* In case there are holes in the array. */
2963 r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
2964 break;
2965
2966 default:
2967 r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
2968 break;
2969 }
2970
2971 switch (version)
2972 {
2973 case E_NDS32_ELF_VER_1_2:
2974 case E_NDS32_ELF_VER_1_3:
2975 case E_NDS32_ELF_VER_1_4:
2976 r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
2977 break;
2978
2979 default:
2980 r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
2981 break;
2982 }
2983
2984 if (E_NDS_ABI_V0 == abi)
2985 {
2986 /* OLD ABI; only used in N1213HC, has performance extension 1. */
2987 r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
2988 if (arch == E_NDS_ARCH_STAR_V1_0)
2989 r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
2990 return;
2991 }
2992
2993 switch (arch)
2994 {
2995 case E_NDS_ARCH_STAR_V1_0:
2996 case E_NDS_ARCH_STAR_V2_0:
2997 case E_NDS_ARCH_STAR_V3_0:
2998 case E_NDS_ARCH_STAR_V3_M:
2999 r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
3000 break;
3001
3002 default:
3003 r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
3004 /* ARCH version determines how the e_flags are interpreted.
3005 If it is unknown, we cannot proceed. */
3006 return;
3007 }
3008
3009 /* Newer ABI; Now handle architecture specific flags. */
3010 if (arch == E_NDS_ARCH_STAR_V1_0)
3011 {
3012 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3013 r += snprintf (buf + r, size -r, ", MFUSR_PC");
3014
3015 if (!(config & E_NDS32_HAS_NO_MAC_INST))
3016 r += snprintf (buf + r, size -r, ", MAC");
3017
3018 if (config & E_NDS32_HAS_DIV_INST)
3019 r += snprintf (buf + r, size -r, ", DIV");
3020
3021 if (config & E_NDS32_HAS_16BIT_INST)
3022 r += snprintf (buf + r, size -r, ", 16b");
3023 }
3024 else
3025 {
3026 if (config & E_NDS32_HAS_MFUSR_PC_INST)
3027 {
3028 if (version <= E_NDS32_ELF_VER_1_3)
3029 r += snprintf (buf + r, size -r, ", [B8]");
3030 else
3031 r += snprintf (buf + r, size -r, ", EX9");
3032 }
3033
3034 if (config & E_NDS32_HAS_MAC_DX_INST)
3035 r += snprintf (buf + r, size -r, ", MAC_DX");
3036
3037 if (config & E_NDS32_HAS_DIV_DX_INST)
3038 r += snprintf (buf + r, size -r, ", DIV_DX");
3039
3040 if (config & E_NDS32_HAS_16BIT_INST)
3041 {
3042 if (version <= E_NDS32_ELF_VER_1_3)
3043 r += snprintf (buf + r, size -r, ", 16b");
3044 else
3045 r += snprintf (buf + r, size -r, ", IFC");
3046 }
3047 }
3048
3049 if (config & E_NDS32_HAS_EXT_INST)
3050 r += snprintf (buf + r, size -r, ", PERF1");
3051
3052 if (config & E_NDS32_HAS_EXT2_INST)
3053 r += snprintf (buf + r, size -r, ", PERF2");
3054
3055 if (config & E_NDS32_HAS_FPU_INST)
3056 {
3057 has_fpu = TRUE;
3058 r += snprintf (buf + r, size -r, ", FPU_SP");
3059 }
3060
3061 if (config & E_NDS32_HAS_FPU_DP_INST)
3062 {
3063 has_fpu = TRUE;
3064 r += snprintf (buf + r, size -r, ", FPU_DP");
3065 }
3066
3067 if (config & E_NDS32_HAS_FPU_MAC_INST)
3068 {
3069 has_fpu = TRUE;
3070 r += snprintf (buf + r, size -r, ", FPU_MAC");
3071 }
3072
3073 if (has_fpu)
3074 {
3075 switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
3076 {
3077 case E_NDS32_FPU_REG_8SP_4DP:
3078 r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
3079 break;
3080 case E_NDS32_FPU_REG_16SP_8DP:
3081 r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
3082 break;
3083 case E_NDS32_FPU_REG_32SP_16DP:
3084 r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
3085 break;
3086 case E_NDS32_FPU_REG_32SP_32DP:
3087 r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
3088 break;
3089 }
3090 }
3091
3092 if (config & E_NDS32_HAS_AUDIO_INST)
3093 r += snprintf (buf + r, size -r, ", AUDIO");
3094
3095 if (config & E_NDS32_HAS_STRING_INST)
3096 r += snprintf (buf + r, size -r, ", STR");
3097
3098 if (config & E_NDS32_HAS_REDUCED_REGS)
3099 r += snprintf (buf + r, size -r, ", 16REG");
3100
3101 if (config & E_NDS32_HAS_VIDEO_INST)
3102 {
3103 if (version <= E_NDS32_ELF_VER_1_3)
3104 r += snprintf (buf + r, size -r, ", VIDEO");
3105 else
3106 r += snprintf (buf + r, size -r, ", SATURATION");
3107 }
3108
3109 if (config & E_NDS32_HAS_ENCRIPT_INST)
3110 r += snprintf (buf + r, size -r, ", ENCRP");
3111
3112 if (config & E_NDS32_HAS_L2C_INST)
3113 r += snprintf (buf + r, size -r, ", L2C");
3114 }
3115
3116 static char *
3117 get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
3118 {
3119 static char buf[1024];
3120
3121 buf[0] = '\0';
3122
3123 if (e_flags)
3124 {
3125 switch (e_machine)
3126 {
3127 default:
3128 break;
3129
3130 case EM_ARC_COMPACT2:
3131 case EM_ARC_COMPACT:
3132 decode_ARC_machine_flags (e_flags, e_machine, buf);
3133 break;
3134
3135 case EM_ARM:
3136 decode_ARM_machine_flags (e_flags, buf);
3137 break;
3138
3139 case EM_AVR:
3140 decode_AVR_machine_flags (e_flags, buf, sizeof buf);
3141 break;
3142
3143 case EM_BLACKFIN:
3144 if (e_flags & EF_BFIN_PIC)
3145 strcat (buf, ", PIC");
3146
3147 if (e_flags & EF_BFIN_FDPIC)
3148 strcat (buf, ", FDPIC");
3149
3150 if (e_flags & EF_BFIN_CODE_IN_L1)
3151 strcat (buf, ", code in L1");
3152
3153 if (e_flags & EF_BFIN_DATA_IN_L1)
3154 strcat (buf, ", data in L1");
3155
3156 break;
3157
3158 case EM_CYGNUS_FRV:
3159 switch (e_flags & EF_FRV_CPU_MASK)
3160 {
3161 case EF_FRV_CPU_GENERIC:
3162 break;
3163
3164 default:
3165 strcat (buf, ", fr???");
3166 break;
3167
3168 case EF_FRV_CPU_FR300:
3169 strcat (buf, ", fr300");
3170 break;
3171
3172 case EF_FRV_CPU_FR400:
3173 strcat (buf, ", fr400");
3174 break;
3175 case EF_FRV_CPU_FR405:
3176 strcat (buf, ", fr405");
3177 break;
3178
3179 case EF_FRV_CPU_FR450:
3180 strcat (buf, ", fr450");
3181 break;
3182
3183 case EF_FRV_CPU_FR500:
3184 strcat (buf, ", fr500");
3185 break;
3186 case EF_FRV_CPU_FR550:
3187 strcat (buf, ", fr550");
3188 break;
3189
3190 case EF_FRV_CPU_SIMPLE:
3191 strcat (buf, ", simple");
3192 break;
3193 case EF_FRV_CPU_TOMCAT:
3194 strcat (buf, ", tomcat");
3195 break;
3196 }
3197 break;
3198
3199 case EM_68K:
3200 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
3201 strcat (buf, ", m68000");
3202 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
3203 strcat (buf, ", cpu32");
3204 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
3205 strcat (buf, ", fido_a");
3206 else
3207 {
3208 char const * isa = _("unknown");
3209 char const * mac = _("unknown mac");
3210 char const * additional = NULL;
3211
3212 switch (e_flags & EF_M68K_CF_ISA_MASK)
3213 {
3214 case EF_M68K_CF_ISA_A_NODIV:
3215 isa = "A";
3216 additional = ", nodiv";
3217 break;
3218 case EF_M68K_CF_ISA_A:
3219 isa = "A";
3220 break;
3221 case EF_M68K_CF_ISA_A_PLUS:
3222 isa = "A+";
3223 break;
3224 case EF_M68K_CF_ISA_B_NOUSP:
3225 isa = "B";
3226 additional = ", nousp";
3227 break;
3228 case EF_M68K_CF_ISA_B:
3229 isa = "B";
3230 break;
3231 case EF_M68K_CF_ISA_C:
3232 isa = "C";
3233 break;
3234 case EF_M68K_CF_ISA_C_NODIV:
3235 isa = "C";
3236 additional = ", nodiv";
3237 break;
3238 }
3239 strcat (buf, ", cf, isa ");
3240 strcat (buf, isa);
3241 if (additional)
3242 strcat (buf, additional);
3243 if (e_flags & EF_M68K_CF_FLOAT)
3244 strcat (buf, ", float");
3245 switch (e_flags & EF_M68K_CF_MAC_MASK)
3246 {
3247 case 0:
3248 mac = NULL;
3249 break;
3250 case EF_M68K_CF_MAC:
3251 mac = "mac";
3252 break;
3253 case EF_M68K_CF_EMAC:
3254 mac = "emac";
3255 break;
3256 case EF_M68K_CF_EMAC_B:
3257 mac = "emac_b";
3258 break;
3259 }
3260 if (mac)
3261 {
3262 strcat (buf, ", ");
3263 strcat (buf, mac);
3264 }
3265 }
3266 break;
3267
3268 case EM_AMDGPU:
3269 switch (e_flags & EF_AMDGPU_MACH)
3270 {
3271 case EF_AMDGPU_MACH_AMDGCN_GFX801 : strcat (buf, ", gfx801"); break;
3272 case EF_AMDGPU_MACH_AMDGCN_GFX802 : strcat (buf, ", gfx802"); break;
3273 case EF_AMDGPU_MACH_AMDGCN_GFX803 : strcat (buf, ", gfx803"); break;
3274 case EF_AMDGPU_MACH_AMDGCN_GFX810 : strcat (buf, ", gfx810"); break;
3275 case EF_AMDGPU_MACH_AMDGCN_GFX900 : strcat (buf, ", gfx900"); break;
3276 case EF_AMDGPU_MACH_AMDGCN_GFX902 : strcat (buf, ", gfx902"); break;
3277 case EF_AMDGPU_MACH_AMDGCN_GFX904 : strcat (buf, ", gfx904"); break;
3278 case EF_AMDGPU_MACH_AMDGCN_GFX906 : strcat (buf, ", gfx906"); break;
3279 case EF_AMDGPU_MACH_AMDGCN_GFX908 : strcat (buf, ", gfx908"); break;
3280 case EF_AMDGPU_MACH_AMDGCN_GFX909 : strcat (buf, ", gfx909"); break;
3281 default: strcat (buf, _(", <unknown AMDGPU gpu type>")); break;
3282 }
3283
3284 if (e_flags & ~ EF_AMDGPU_MACH)
3285 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
3286 e_flags & ~ EF_AMDGPU_MACH);
3287 break;
3288
3289 case EM_CYGNUS_MEP:
3290 switch (e_flags & EF_MEP_CPU_MASK)
3291 {
3292 case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
3293 case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
3294 case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
3295 case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
3296 case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
3297 case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
3298 default: strcat (buf, _(", <unknown MeP cpu type>")); break;
3299 }
3300
3301 switch (e_flags & EF_MEP_COP_MASK)
3302 {
3303 case EF_MEP_COP_NONE: break;
3304 case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
3305 case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
3306 case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
3307 case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
3308 default: strcat (buf, _("<unknown MeP copro type>")); break;
3309 }
3310
3311 if (e_flags & EF_MEP_LIBRARY)
3312 strcat (buf, ", Built for Library");
3313
3314 if (e_flags & EF_MEP_INDEX_MASK)
3315 sprintf (buf + strlen (buf), ", Configuration Index: %#x",
3316 e_flags & EF_MEP_INDEX_MASK);
3317
3318 if (e_flags & ~ EF_MEP_ALL_FLAGS)
3319 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
3320 e_flags & ~ EF_MEP_ALL_FLAGS);
3321 break;
3322
3323 case EM_PPC:
3324 if (e_flags & EF_PPC_EMB)
3325 strcat (buf, ", emb");
3326
3327 if (e_flags & EF_PPC_RELOCATABLE)
3328 strcat (buf, _(", relocatable"));
3329
3330 if (e_flags & EF_PPC_RELOCATABLE_LIB)
3331 strcat (buf, _(", relocatable-lib"));
3332 break;
3333
3334 case EM_PPC64:
3335 if (e_flags & EF_PPC64_ABI)
3336 {
3337 char abi[] = ", abiv0";
3338
3339 abi[6] += e_flags & EF_PPC64_ABI;
3340 strcat (buf, abi);
3341 }
3342 break;
3343
3344 case EM_V800:
3345 if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
3346 strcat (buf, ", RH850 ABI");
3347
3348 if (e_flags & EF_V800_850E3)
3349 strcat (buf, ", V3 architecture");
3350
3351 if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
3352 strcat (buf, ", FPU not used");
3353
3354 if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
3355 strcat (buf, ", regmode: COMMON");
3356
3357 if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
3358 strcat (buf, ", r4 not used");
3359
3360 if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
3361 strcat (buf, ", r30 not used");
3362
3363 if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
3364 strcat (buf, ", r5 not used");
3365
3366 if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
3367 strcat (buf, ", r2 not used");
3368
3369 for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
3370 {
3371 switch (e_flags & - e_flags)
3372 {
3373 case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
3374 case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
3375 case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
3376 case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
3377 case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
3378 case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
3379 case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
3380 case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
3381 case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
3382 case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
3383 case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
3384 case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
3385 default: break;
3386 }
3387 }
3388 break;
3389
3390 case EM_V850:
3391 case EM_CYGNUS_V850:
3392 switch (e_flags & EF_V850_ARCH)
3393 {
3394 case E_V850E3V5_ARCH:
3395 strcat (buf, ", v850e3v5");
3396 break;
3397 case E_V850E2V3_ARCH:
3398 strcat (buf, ", v850e2v3");
3399 break;
3400 case E_V850E2_ARCH:
3401 strcat (buf, ", v850e2");
3402 break;
3403 case E_V850E1_ARCH:
3404 strcat (buf, ", v850e1");
3405 break;
3406 case E_V850E_ARCH:
3407 strcat (buf, ", v850e");
3408 break;
3409 case E_V850_ARCH:
3410 strcat (buf, ", v850");
3411 break;
3412 default:
3413 strcat (buf, _(", unknown v850 architecture variant"));
3414 break;
3415 }
3416 break;
3417
3418 case EM_M32R:
3419 case EM_CYGNUS_M32R:
3420 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3421 strcat (buf, ", m32r");
3422 break;
3423
3424 case EM_MIPS:
3425 case EM_MIPS_RS3_LE:
3426 if (e_flags & EF_MIPS_NOREORDER)
3427 strcat (buf, ", noreorder");
3428
3429 if (e_flags & EF_MIPS_PIC)
3430 strcat (buf, ", pic");
3431
3432 if (e_flags & EF_MIPS_CPIC)
3433 strcat (buf, ", cpic");
3434
3435 if (e_flags & EF_MIPS_UCODE)
3436 strcat (buf, ", ugen_reserved");
3437
3438 if (e_flags & EF_MIPS_ABI2)
3439 strcat (buf, ", abi2");
3440
3441 if (e_flags & EF_MIPS_OPTIONS_FIRST)
3442 strcat (buf, ", odk first");
3443
3444 if (e_flags & EF_MIPS_32BITMODE)
3445 strcat (buf, ", 32bitmode");
3446
3447 if (e_flags & EF_MIPS_NAN2008)
3448 strcat (buf, ", nan2008");
3449
3450 if (e_flags & EF_MIPS_FP64)
3451 strcat (buf, ", fp64");
3452
3453 switch ((e_flags & EF_MIPS_MACH))
3454 {
3455 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
3456 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
3457 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
3458 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
3459 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
3460 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
3461 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
3462 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
3463 case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break;
3464 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
3465 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
3466 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
3467 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
3468 case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break;
3469 case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break;
3470 case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break;
3471 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
3472 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
3473 case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
3474 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
3475 case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break;
3476 case 0:
3477 /* We simply ignore the field in this case to avoid confusion:
3478 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3479 extension. */
3480 break;
3481 default: strcat (buf, _(", unknown CPU")); break;
3482 }
3483
3484 switch ((e_flags & EF_MIPS_ABI))
3485 {
3486 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
3487 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
3488 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
3489 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
3490 case 0:
3491 /* We simply ignore the field in this case to avoid confusion:
3492 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3493 This means it is likely to be an o32 file, but not for
3494 sure. */
3495 break;
3496 default: strcat (buf, _(", unknown ABI")); break;
3497 }
3498
3499 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
3500 strcat (buf, ", mdmx");
3501
3502 if (e_flags & EF_MIPS_ARCH_ASE_M16)
3503 strcat (buf, ", mips16");
3504
3505 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
3506 strcat (buf, ", micromips");
3507
3508 switch ((e_flags & EF_MIPS_ARCH))
3509 {
3510 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
3511 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
3512 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
3513 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
3514 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
3515 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
3516 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
3517 case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
3518 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
3519 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
3520 case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
3521 default: strcat (buf, _(", unknown ISA")); break;
3522 }
3523 break;
3524
3525 case EM_NDS32:
3526 decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
3527 break;
3528
3529 case EM_NFP:
3530 switch (EF_NFP_MACH (e_flags))
3531 {
3532 case E_NFP_MACH_3200:
3533 strcat (buf, ", NFP-32xx");
3534 break;
3535 case E_NFP_MACH_6000:
3536 strcat (buf, ", NFP-6xxx");
3537 break;
3538 }
3539 break;
3540
3541 case EM_RISCV:
3542 if (e_flags & EF_RISCV_RVC)
3543 strcat (buf, ", RVC");
3544
3545 if (e_flags & EF_RISCV_RVE)
3546 strcat (buf, ", RVE");
3547
3548 switch (e_flags & EF_RISCV_FLOAT_ABI)
3549 {
3550 case EF_RISCV_FLOAT_ABI_SOFT:
3551 strcat (buf, ", soft-float ABI");
3552 break;
3553
3554 case EF_RISCV_FLOAT_ABI_SINGLE:
3555 strcat (buf, ", single-float ABI");
3556 break;
3557
3558 case EF_RISCV_FLOAT_ABI_DOUBLE:
3559 strcat (buf, ", double-float ABI");
3560 break;
3561
3562 case EF_RISCV_FLOAT_ABI_QUAD:
3563 strcat (buf, ", quad-float ABI");
3564 break;
3565 }
3566 break;
3567
3568 case EM_SH:
3569 switch ((e_flags & EF_SH_MACH_MASK))
3570 {
3571 case EF_SH1: strcat (buf, ", sh1"); break;
3572 case EF_SH2: strcat (buf, ", sh2"); break;
3573 case EF_SH3: strcat (buf, ", sh3"); break;
3574 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
3575 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
3576 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
3577 case EF_SH3E: strcat (buf, ", sh3e"); break;
3578 case EF_SH4: strcat (buf, ", sh4"); break;
3579 case EF_SH5: strcat (buf, ", sh5"); break;
3580 case EF_SH2E: strcat (buf, ", sh2e"); break;
3581 case EF_SH4A: strcat (buf, ", sh4a"); break;
3582 case EF_SH2A: strcat (buf, ", sh2a"); break;
3583 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
3584 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
3585 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
3586 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
3587 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
3588 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3589 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
3590 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
3591 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
3592 default: strcat (buf, _(", unknown ISA")); break;
3593 }
3594
3595 if (e_flags & EF_SH_PIC)
3596 strcat (buf, ", pic");
3597
3598 if (e_flags & EF_SH_FDPIC)
3599 strcat (buf, ", fdpic");
3600 break;
3601
3602 case EM_OR1K:
3603 if (e_flags & EF_OR1K_NODELAY)
3604 strcat (buf, ", no delay");
3605 break;
3606
3607 case EM_SPARCV9:
3608 if (e_flags & EF_SPARC_32PLUS)
3609 strcat (buf, ", v8+");
3610
3611 if (e_flags & EF_SPARC_SUN_US1)
3612 strcat (buf, ", ultrasparcI");
3613
3614 if (e_flags & EF_SPARC_SUN_US3)
3615 strcat (buf, ", ultrasparcIII");
3616
3617 if (e_flags & EF_SPARC_HAL_R1)
3618 strcat (buf, ", halr1");
3619
3620 if (e_flags & EF_SPARC_LEDATA)
3621 strcat (buf, ", ledata");
3622
3623 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
3624 strcat (buf, ", tso");
3625
3626 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
3627 strcat (buf, ", pso");
3628
3629 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
3630 strcat (buf, ", rmo");
3631 break;
3632
3633 case EM_PARISC:
3634 switch (e_flags & EF_PARISC_ARCH)
3635 {
3636 case EFA_PARISC_1_0:
3637 strcpy (buf, ", PA-RISC 1.0");
3638 break;
3639 case EFA_PARISC_1_1:
3640 strcpy (buf, ", PA-RISC 1.1");
3641 break;
3642 case EFA_PARISC_2_0:
3643 strcpy (buf, ", PA-RISC 2.0");
3644 break;
3645 default:
3646 break;
3647 }
3648 if (e_flags & EF_PARISC_TRAPNIL)
3649 strcat (buf, ", trapnil");
3650 if (e_flags & EF_PARISC_EXT)
3651 strcat (buf, ", ext");
3652 if (e_flags & EF_PARISC_LSB)
3653 strcat (buf, ", lsb");
3654 if (e_flags & EF_PARISC_WIDE)
3655 strcat (buf, ", wide");
3656 if (e_flags & EF_PARISC_NO_KABP)
3657 strcat (buf, ", no kabp");
3658 if (e_flags & EF_PARISC_LAZYSWAP)
3659 strcat (buf, ", lazyswap");
3660 break;
3661
3662 case EM_PJ:
3663 case EM_PJ_OLD:
3664 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
3665 strcat (buf, ", new calling convention");
3666
3667 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
3668 strcat (buf, ", gnu calling convention");
3669 break;
3670
3671 case EM_IA_64:
3672 if ((e_flags & EF_IA_64_ABI64))
3673 strcat (buf, ", 64-bit");
3674 else
3675 strcat (buf, ", 32-bit");
3676 if ((e_flags & EF_IA_64_REDUCEDFP))
3677 strcat (buf, ", reduced fp model");
3678 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
3679 strcat (buf, ", no function descriptors, constant gp");
3680 else if ((e_flags & EF_IA_64_CONS_GP))
3681 strcat (buf, ", constant gp");
3682 if ((e_flags & EF_IA_64_ABSOLUTE))
3683 strcat (buf, ", absolute");
3684 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
3685 {
3686 if ((e_flags & EF_IA_64_VMS_LINKAGES))
3687 strcat (buf, ", vms_linkages");
3688 switch ((e_flags & EF_IA_64_VMS_COMCOD))
3689 {
3690 case EF_IA_64_VMS_COMCOD_SUCCESS:
3691 break;
3692 case EF_IA_64_VMS_COMCOD_WARNING:
3693 strcat (buf, ", warning");
3694 break;
3695 case EF_IA_64_VMS_COMCOD_ERROR:
3696 strcat (buf, ", error");
3697 break;
3698 case EF_IA_64_VMS_COMCOD_ABORT:
3699 strcat (buf, ", abort");
3700 break;
3701 default:
3702 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3703 e_flags & EF_IA_64_VMS_COMCOD);
3704 strcat (buf, ", <unknown>");
3705 }
3706 }
3707 break;
3708
3709 case EM_VAX:
3710 if ((e_flags & EF_VAX_NONPIC))
3711 strcat (buf, ", non-PIC");
3712 if ((e_flags & EF_VAX_DFLOAT))
3713 strcat (buf, ", D-Float");
3714 if ((e_flags & EF_VAX_GFLOAT))
3715 strcat (buf, ", G-Float");
3716 break;
3717
3718 case EM_VISIUM:
3719 if (e_flags & EF_VISIUM_ARCH_MCM)
3720 strcat (buf, ", mcm");
3721 else if (e_flags & EF_VISIUM_ARCH_MCM24)
3722 strcat (buf, ", mcm24");
3723 if (e_flags & EF_VISIUM_ARCH_GR6)
3724 strcat (buf, ", gr6");
3725 break;
3726
3727 case EM_RL78:
3728 switch (e_flags & E_FLAG_RL78_CPU_MASK)
3729 {
3730 case E_FLAG_RL78_ANY_CPU: break;
3731 case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
3732 case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
3733 case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
3734 }
3735 if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
3736 strcat (buf, ", 64-bit doubles");
3737 break;
3738
3739 case EM_RX:
3740 if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
3741 strcat (buf, ", 64-bit doubles");
3742 if (e_flags & E_FLAG_RX_DSP)
3743 strcat (buf, ", dsp");
3744 if (e_flags & E_FLAG_RX_PID)
3745 strcat (buf, ", pid");
3746 if (e_flags & E_FLAG_RX_ABI)
3747 strcat (buf, ", RX ABI");
3748 if (e_flags & E_FLAG_RX_SINSNS_SET)
3749 strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
3750 ? ", uses String instructions" : ", bans String instructions");
3751 if (e_flags & E_FLAG_RX_V2)
3752 strcat (buf, ", V2");
3753 if (e_flags & E_FLAG_RX_V3)
3754 strcat (buf, ", V3");
3755 break;
3756
3757 case EM_S390:
3758 if (e_flags & EF_S390_HIGH_GPRS)
3759 strcat (buf, ", highgprs");
3760 break;
3761
3762 case EM_TI_C6000:
3763 if ((e_flags & EF_C6000_REL))
3764 strcat (buf, ", relocatable module");
3765 break;
3766
3767 case EM_MSP430:
3768 strcat (buf, _(": architecture variant: "));
3769 switch (e_flags & EF_MSP430_MACH)
3770 {
3771 case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
3772 case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
3773 case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
3774 case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
3775 case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
3776 case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
3777 case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
3778 case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
3779 case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
3780 case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
3781 case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
3782 case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
3783 case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
3784 case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
3785 case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
3786 default:
3787 strcat (buf, _(": unknown")); break;
3788 }
3789
3790 if (e_flags & ~ EF_MSP430_MACH)
3791 strcat (buf, _(": unknown extra flag bits also present"));
3792 }
3793 }
3794
3795 return buf;
3796 }
3797
3798 static const char *
3799 get_osabi_name (Filedata * filedata, unsigned int osabi)
3800 {
3801 static char buff[32];
3802
3803 switch (osabi)
3804 {
3805 case ELFOSABI_NONE: return "UNIX - System V";
3806 case ELFOSABI_HPUX: return "UNIX - HP-UX";
3807 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
3808 case ELFOSABI_GNU: return "UNIX - GNU";
3809 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
3810 case ELFOSABI_AIX: return "UNIX - AIX";
3811 case ELFOSABI_IRIX: return "UNIX - IRIX";
3812 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
3813 case ELFOSABI_TRU64: return "UNIX - TRU64";
3814 case ELFOSABI_MODESTO: return "Novell - Modesto";
3815 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
3816 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
3817 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
3818 case ELFOSABI_AROS: return "AROS";
3819 case ELFOSABI_FENIXOS: return "FenixOS";
3820 case ELFOSABI_CLOUDABI: return "Nuxi CloudABI";
3821 case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS";
3822 default:
3823 if (osabi >= 64)
3824 switch (filedata->file_header.e_machine)
3825 {
3826 case EM_AMDGPU:
3827 switch (osabi)
3828 {
3829 case ELFOSABI_AMDGPU_HSA: return "AMD HSA Runtime";
3830 default:
3831 break;
3832 }
3833 break;
3834
3835 case EM_ARM:
3836 switch (osabi)
3837 {
3838 case ELFOSABI_ARM: return "ARM";
3839 case ELFOSABI_ARM_FDPIC: return "ARM FDPIC";
3840 default:
3841 break;
3842 }
3843 break;
3844
3845 case EM_MSP430:
3846 case EM_MSP430_OLD:
3847 case EM_VISIUM:
3848 switch (osabi)
3849 {
3850 case ELFOSABI_STANDALONE: return _("Standalone App");
3851 default:
3852 break;
3853 }
3854 break;
3855
3856 case EM_TI_C6000:
3857 switch (osabi)
3858 {
3859 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
3860 case ELFOSABI_C6000_LINUX: return "Linux C6000";
3861 default:
3862 break;
3863 }
3864 break;
3865
3866 default:
3867 break;
3868 }
3869 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
3870 return buff;
3871 }
3872 }
3873
3874 static const char *
3875 get_aarch64_segment_type (unsigned long type)
3876 {
3877 switch (type)
3878 {
3879 case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT";
3880 default: return NULL;
3881 }
3882 }
3883
3884 static const char *
3885 get_arm_segment_type (unsigned long type)
3886 {
3887 switch (type)
3888 {
3889 case PT_ARM_EXIDX: return "EXIDX";
3890 default: return NULL;
3891 }
3892 }
3893
3894 static const char *
3895 get_s390_segment_type (unsigned long type)
3896 {
3897 switch (type)
3898 {
3899 case PT_S390_PGSTE: return "S390_PGSTE";
3900 default: return NULL;
3901 }
3902 }
3903
3904 static const char *
3905 get_mips_segment_type (unsigned long type)
3906 {
3907 switch (type)
3908 {
3909 case PT_MIPS_REGINFO: return "REGINFO";
3910 case PT_MIPS_RTPROC: return "RTPROC";
3911 case PT_MIPS_OPTIONS: return "OPTIONS";
3912 case PT_MIPS_ABIFLAGS: return "ABIFLAGS";
3913 default: return NULL;
3914 }
3915 }
3916
3917 static const char *
3918 get_parisc_segment_type (unsigned long type)
3919 {
3920 switch (type)
3921 {
3922 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
3923 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
3924 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
3925 default: return NULL;
3926 }
3927 }
3928
3929 static const char *
3930 get_ia64_segment_type (unsigned long type)
3931 {
3932 switch (type)
3933 {
3934 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
3935 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
3936 default: return NULL;
3937 }
3938 }
3939
3940 static const char *
3941 get_tic6x_segment_type (unsigned long type)
3942 {
3943 switch (type)
3944 {
3945 case PT_C6000_PHATTR: return "C6000_PHATTR";
3946 default: return NULL;
3947 }
3948 }
3949
3950 static const char *
3951 get_hpux_segment_type (unsigned long type, unsigned e_machine)
3952 {
3953 if (e_machine == EM_PARISC)
3954 switch (type)
3955 {
3956 case PT_HP_TLS: return "HP_TLS";
3957 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
3958 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
3959 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
3960 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
3961 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
3962 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
3963 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
3964 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
3965 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
3966 case PT_HP_PARALLEL: return "HP_PARALLEL";
3967 case PT_HP_FASTBIND: return "HP_FASTBIND";
3968 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
3969 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
3970 case PT_HP_STACK: return "HP_STACK";
3971 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
3972 default: return NULL;
3973 }
3974
3975 if (e_machine == EM_IA_64)
3976 switch (type)
3977 {
3978 case PT_HP_TLS: return "HP_TLS";
3979 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
3980 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
3981 case PT_IA_64_HP_STACK: return "HP_STACK";
3982 default: return NULL;
3983 }
3984
3985 return NULL;
3986 }
3987
3988 static const char *
3989 get_solaris_segment_type (unsigned long type)
3990 {
3991 switch (type)
3992 {
3993 case 0x6464e550: return "PT_SUNW_UNWIND";
3994 case 0x6474e550: return "PT_SUNW_EH_FRAME";
3995 case 0x6ffffff7: return "PT_LOSUNW";
3996 case 0x6ffffffa: return "PT_SUNWBSS";
3997 case 0x6ffffffb: return "PT_SUNWSTACK";
3998 case 0x6ffffffc: return "PT_SUNWDTRACE";
3999 case 0x6ffffffd: return "PT_SUNWCAP";
4000 case 0x6fffffff: return "PT_HISUNW";
4001 default: return NULL;
4002 }
4003 }
4004
4005 static const char *
4006 get_segment_type (Filedata * filedata, unsigned long p_type)
4007 {
4008 static char buff[32];
4009
4010 switch (p_type)
4011 {
4012 case PT_NULL: return "NULL";
4013 case PT_LOAD: return "LOAD";
4014 case PT_DYNAMIC: return "DYNAMIC";
4015 case PT_INTERP: return "INTERP";
4016 case PT_NOTE: return "NOTE";
4017 case PT_SHLIB: return "SHLIB";
4018 case PT_PHDR: return "PHDR";
4019 case PT_TLS: return "TLS";
4020 case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
4021 case PT_GNU_STACK: return "GNU_STACK";
4022 case PT_GNU_RELRO: return "GNU_RELRO";
4023 case PT_GNU_PROPERTY: return "GNU_PROPERTY";
4024
4025 default:
4026 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
4027 {
4028 const char * result;
4029
4030 switch (filedata->file_header.e_machine)
4031 {
4032 case EM_AARCH64:
4033 result = get_aarch64_segment_type (p_type);
4034 break;
4035 case EM_ARM:
4036 result = get_arm_segment_type (p_type);
4037 break;
4038 case EM_MIPS:
4039 case EM_MIPS_RS3_LE:
4040 result = get_mips_segment_type (p_type);
4041 break;
4042 case EM_PARISC:
4043 result = get_parisc_segment_type (p_type);
4044 break;
4045 case EM_IA_64:
4046 result = get_ia64_segment_type (p_type);
4047 break;
4048 case EM_TI_C6000:
4049 result = get_tic6x_segment_type (p_type);
4050 break;
4051 case EM_S390:
4052 case EM_S390_OLD:
4053 result = get_s390_segment_type (p_type);
4054 break;
4055 default:
4056 result = NULL;
4057 break;
4058 }
4059
4060 if (result != NULL)
4061 return result;
4062
4063 sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC);
4064 }
4065 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
4066 {
4067 const char * result = NULL;
4068
4069 switch (filedata->file_header.e_ident[EI_OSABI])
4070 {
4071 case ELFOSABI_GNU:
4072 case ELFOSABI_FREEBSD:
4073 if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
4074 {
4075 sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO);
4076 result = buff;
4077 }
4078 break;
4079 case ELFOSABI_HPUX:
4080 result = get_hpux_segment_type (p_type,
4081 filedata->file_header.e_machine);
4082 break;
4083 case ELFOSABI_SOLARIS:
4084 result = get_solaris_segment_type (p_type);
4085 break;
4086 default:
4087 break;
4088 }
4089 if (result != NULL)
4090 return result;
4091
4092 sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS);
4093 }
4094 else
4095 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
4096
4097 return buff;
4098 }
4099 }
4100
4101 static const char *
4102 get_arc_section_type_name (unsigned int sh_type)
4103 {
4104 switch (sh_type)
4105 {
4106 case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES";
4107 default:
4108 break;
4109 }
4110 return NULL;
4111 }
4112
4113 static const char *
4114 get_mips_section_type_name (unsigned int sh_type)
4115 {
4116 switch (sh_type)
4117 {
4118 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
4119 case SHT_MIPS_MSYM: return "MIPS_MSYM";
4120 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
4121 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
4122 case SHT_MIPS_UCODE: return "MIPS_UCODE";
4123 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
4124 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
4125 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
4126 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
4127 case SHT_MIPS_RELD: return "MIPS_RELD";
4128 case SHT_MIPS_IFACE: return "MIPS_IFACE";
4129 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
4130 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
4131 case SHT_MIPS_SHDR: return "MIPS_SHDR";
4132 case SHT_MIPS_FDESC: return "MIPS_FDESC";
4133 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
4134 case SHT_MIPS_DENSE: return "MIPS_DENSE";
4135 case SHT_MIPS_PDESC: return "MIPS_PDESC";
4136 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
4137 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
4138 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
4139 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
4140 case SHT_MIPS_LINE: return "MIPS_LINE";
4141 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
4142 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
4143 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
4144 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
4145 case SHT_MIPS_DWARF: return "MIPS_DWARF";
4146 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
4147 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
4148 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
4149 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
4150 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
4151 case SHT_MIPS_XLATE: return "MIPS_XLATE";
4152 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
4153 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
4154 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
4155 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
4156 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
4157 case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
4158 case SHT_MIPS_XHASH: return "MIPS_XHASH";
4159 default:
4160 break;
4161 }
4162 return NULL;
4163 }
4164
4165 static const char *
4166 get_parisc_section_type_name (unsigned int sh_type)
4167 {
4168 switch (sh_type)
4169 {
4170 case SHT_PARISC_EXT: return "PARISC_EXT";
4171 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
4172 case SHT_PARISC_DOC: return "PARISC_DOC";
4173 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
4174 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
4175 case SHT_PARISC_STUBS: return "PARISC_STUBS";
4176 case SHT_PARISC_DLKM: return "PARISC_DLKM";
4177 default: return NULL;
4178 }
4179 }
4180
4181 static const char *
4182 get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type)
4183 {
4184 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4185 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
4186 return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16);
4187
4188 switch (sh_type)
4189 {
4190 case SHT_IA_64_EXT: return "IA_64_EXT";
4191 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
4192 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
4193 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
4194 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
4195 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
4196 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
4197 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
4198 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
4199 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
4200 default:
4201 break;
4202 }
4203 return NULL;
4204 }
4205
4206 static const char *
4207 get_x86_64_section_type_name (unsigned int sh_type)
4208 {
4209 switch (sh_type)
4210 {
4211 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
4212 default: return NULL;
4213 }
4214 }
4215
4216 static const char *
4217 get_aarch64_section_type_name (unsigned int sh_type)
4218 {
4219 switch (sh_type)
4220 {
4221 case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES";
4222 default: return NULL;
4223 }
4224 }
4225
4226 static const char *
4227 get_arm_section_type_name (unsigned int sh_type)
4228 {
4229 switch (sh_type)
4230 {
4231 case SHT_ARM_EXIDX: return "ARM_EXIDX";
4232 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
4233 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
4234 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
4235 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
4236 default: return NULL;
4237 }
4238 }
4239
4240 static const char *
4241 get_tic6x_section_type_name (unsigned int sh_type)
4242 {
4243 switch (sh_type)
4244 {
4245 case SHT_C6000_UNWIND: return "C6000_UNWIND";
4246 case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
4247 case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES";
4248 case SHT_TI_ICODE: return "TI_ICODE";
4249 case SHT_TI_XREF: return "TI_XREF";
4250 case SHT_TI_HANDLER: return "TI_HANDLER";
4251 case SHT_TI_INITINFO: return "TI_INITINFO";
4252 case SHT_TI_PHATTRS: return "TI_PHATTRS";
4253 default: return NULL;
4254 }
4255 }
4256
4257 static const char *
4258 get_msp430x_section_type_name (unsigned int sh_type)
4259 {
4260 switch (sh_type)
4261 {
4262 case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
4263 case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
4264 case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
4265 default: return NULL;
4266 }
4267 }
4268
4269 static const char *
4270 get_nfp_section_type_name (unsigned int sh_type)
4271 {
4272 switch (sh_type)
4273 {
4274 case SHT_NFP_MECONFIG: return "NFP_MECONFIG";
4275 case SHT_NFP_INITREG: return "NFP_INITREG";
4276 case SHT_NFP_UDEBUG: return "NFP_UDEBUG";
4277 default: return NULL;
4278 }
4279 }
4280
4281 static const char *
4282 get_v850_section_type_name (unsigned int sh_type)
4283 {
4284 switch (sh_type)
4285 {
4286 case SHT_V850_SCOMMON: return "V850 Small Common";
4287 case SHT_V850_TCOMMON: return "V850 Tiny Common";
4288 case SHT_V850_ZCOMMON: return "V850 Zero Common";
4289 case SHT_RENESAS_IOP: return "RENESAS IOP";
4290 case SHT_RENESAS_INFO: return "RENESAS INFO";
4291 default: return NULL;
4292 }
4293 }
4294
4295 static const char *
4296 get_riscv_section_type_name (unsigned int sh_type)
4297 {
4298 switch (sh_type)
4299 {
4300 case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES";
4301 default: return NULL;
4302 }
4303 }
4304
4305 static const char *
4306 get_section_type_name (Filedata * filedata, unsigned int sh_type)
4307 {
4308 static char buff[32];
4309 const char * result;
4310
4311 switch (sh_type)
4312 {
4313 case SHT_NULL: return "NULL";
4314 case SHT_PROGBITS: return "PROGBITS";
4315 case SHT_SYMTAB: return "SYMTAB";
4316 case SHT_STRTAB: return "STRTAB";
4317 case SHT_RELA: return "RELA";
4318 case SHT_HASH: return "HASH";
4319 case SHT_DYNAMIC: return "DYNAMIC";
4320 case SHT_NOTE: return "NOTE";
4321 case SHT_NOBITS: return "NOBITS";
4322 case SHT_REL: return "REL";
4323 case SHT_SHLIB: return "SHLIB";
4324 case SHT_DYNSYM: return "DYNSYM";
4325 case SHT_INIT_ARRAY: return "INIT_ARRAY";
4326 case SHT_FINI_ARRAY: return "FINI_ARRAY";
4327 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
4328 case SHT_GNU_HASH: return "GNU_HASH";
4329 case SHT_GROUP: return "GROUP";
4330 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES";
4331 case SHT_GNU_verdef: return "VERDEF";
4332 case SHT_GNU_verneed: return "VERNEED";
4333 case SHT_GNU_versym: return "VERSYM";
4334 case 0x6ffffff0: return "VERSYM";
4335 case 0x6ffffffc: return "VERDEF";
4336 case 0x7ffffffd: return "AUXILIARY";
4337 case 0x7fffffff: return "FILTER";
4338 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
4339
4340 default:
4341 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
4342 {
4343 switch (filedata->file_header.e_machine)
4344 {
4345 case EM_ARC:
4346 case EM_ARC_COMPACT:
4347 case EM_ARC_COMPACT2:
4348 result = get_arc_section_type_name (sh_type);
4349 break;
4350 case EM_MIPS:
4351 case EM_MIPS_RS3_LE:
4352 result = get_mips_section_type_name (sh_type);
4353 break;
4354 case EM_PARISC:
4355 result = get_parisc_section_type_name (sh_type);
4356 break;
4357 case EM_IA_64:
4358 result = get_ia64_section_type_name (filedata, sh_type);
4359 break;
4360 case EM_X86_64:
4361 case EM_L1OM:
4362 case EM_K1OM:
4363 result = get_x86_64_section_type_name (sh_type);
4364 break;
4365 case EM_AARCH64:
4366 result = get_aarch64_section_type_name (sh_type);
4367 break;
4368 case EM_ARM:
4369 result = get_arm_section_type_name (sh_type);
4370 break;
4371 case EM_TI_C6000:
4372 result = get_tic6x_section_type_name (sh_type);
4373 break;
4374 case EM_MSP430:
4375 result = get_msp430x_section_type_name (sh_type);
4376 break;
4377 case EM_NFP:
4378 result = get_nfp_section_type_name (sh_type);
4379 break;
4380 case EM_V800:
4381 case EM_V850:
4382 case EM_CYGNUS_V850:
4383 result = get_v850_section_type_name (sh_type);
4384 break;
4385 case EM_RISCV:
4386 result = get_riscv_section_type_name (sh_type);
4387 break;
4388 default:
4389 result = NULL;
4390 break;
4391 }
4392
4393 if (result != NULL)
4394 return result;
4395
4396 sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
4397 }
4398 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
4399 {
4400 switch (filedata->file_header.e_machine)
4401 {
4402 case EM_IA_64:
4403 result = get_ia64_section_type_name (filedata, sh_type);
4404 break;
4405 default:
4406 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
4407 result = get_solaris_section_type (sh_type);
4408 else
4409 {
4410 switch (sh_type)
4411 {
4412 case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break;
4413 case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break;
4414 case SHT_GNU_HASH: result = "GNU_HASH"; break;
4415 case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break;
4416 default:
4417 result = NULL;
4418 break;
4419 }
4420 }
4421 break;
4422 }
4423
4424 if (result != NULL)
4425 return result;
4426
4427 sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
4428 }
4429 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
4430 {
4431 switch (filedata->file_header.e_machine)
4432 {
4433 case EM_V800:
4434 case EM_V850:
4435 case EM_CYGNUS_V850:
4436 result = get_v850_section_type_name (sh_type);
4437 break;
4438 default:
4439 result = NULL;
4440 break;
4441 }
4442
4443 if (result != NULL)
4444 return result;
4445
4446 sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
4447 }
4448 else
4449 /* This message is probably going to be displayed in a 15
4450 character wide field, so put the hex value first. */
4451 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
4452
4453 return buff;
4454 }
4455 }
4456
4457 #define OPTION_DEBUG_DUMP 512
4458 #define OPTION_DYN_SYMS 513
4459 #define OPTION_DWARF_DEPTH 514
4460 #define OPTION_DWARF_START 515
4461 #define OPTION_DWARF_CHECK 516
4462 #define OPTION_CTF_DUMP 517
4463 #define OPTION_CTF_PARENT 518
4464 #define OPTION_CTF_SYMBOLS 519
4465 #define OPTION_CTF_STRINGS 520
4466
4467 static struct option options[] =
4468 {
4469 {"all", no_argument, 0, 'a'},
4470 {"file-header", no_argument, 0, 'h'},
4471 {"program-headers", no_argument, 0, 'l'},
4472 {"headers", no_argument, 0, 'e'},
4473 {"histogram", no_argument, 0, 'I'},
4474 {"segments", no_argument, 0, 'l'},
4475 {"sections", no_argument, 0, 'S'},
4476 {"section-headers", no_argument, 0, 'S'},
4477 {"section-groups", no_argument, 0, 'g'},
4478 {"section-details", no_argument, 0, 't'},
4479 {"full-section-name",no_argument, 0, 'N'},
4480 {"symbols", no_argument, 0, 's'},
4481 {"syms", no_argument, 0, 's'},
4482 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
4483 {"relocs", no_argument, 0, 'r'},
4484 {"notes", no_argument, 0, 'n'},
4485 {"dynamic", no_argument, 0, 'd'},
4486 {"arch-specific", no_argument, 0, 'A'},
4487 {"version-info", no_argument, 0, 'V'},
4488 {"use-dynamic", no_argument, 0, 'D'},
4489 {"unwind", no_argument, 0, 'u'},
4490 {"archive-index", no_argument, 0, 'c'},
4491 {"hex-dump", required_argument, 0, 'x'},
4492 {"relocated-dump", required_argument, 0, 'R'},
4493 {"string-dump", required_argument, 0, 'p'},
4494 {"decompress", no_argument, 0, 'z'},
4495 #ifdef SUPPORT_DISASSEMBLY
4496 {"instruction-dump", required_argument, 0, 'i'},
4497 #endif
4498 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
4499
4500 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
4501 {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
4502 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
4503
4504 {"ctf", required_argument, 0, OPTION_CTF_DUMP},
4505
4506 {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS},
4507 {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS},
4508 {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT},
4509
4510 {"version", no_argument, 0, 'v'},
4511 {"wide", no_argument, 0, 'W'},
4512 {"help", no_argument, 0, 'H'},
4513 {0, no_argument, 0, 0}
4514 };
4515
4516 static void
4517 usage (FILE * stream)
4518 {
4519 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
4520 fprintf (stream, _(" Display information about the contents of ELF format files\n"));
4521 fprintf (stream, _(" Options are:\n\
4522 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4523 -h --file-header Display the ELF file header\n\
4524 -l --program-headers Display the program headers\n\
4525 --segments An alias for --program-headers\n\
4526 -S --section-headers Display the sections' header\n\
4527 --sections An alias for --section-headers\n\
4528 -g --section-groups Display the section groups\n\
4529 -t --section-details Display the section details\n\
4530 -e --headers Equivalent to: -h -l -S\n\
4531 -s --syms Display the symbol table\n\
4532 --symbols An alias for --syms\n\
4533 --dyn-syms Display the dynamic symbol table\n\
4534 -n --notes Display the core notes (if present)\n\
4535 -r --relocs Display the relocations (if present)\n\
4536 -u --unwind Display the unwind info (if present)\n\
4537 -d --dynamic Display the dynamic section (if present)\n\
4538 -V --version-info Display the version sections (if present)\n\
4539 -A --arch-specific Display architecture specific information (if any)\n\
4540 -c --archive-index Display the symbol/file index in an archive\n\
4541 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
4542 -x --hex-dump=<number|name>\n\
4543 Dump the contents of section <number|name> as bytes\n\
4544 -p --string-dump=<number|name>\n\
4545 Dump the contents of section <number|name> as strings\n\
4546 -R --relocated-dump=<number|name>\n\
4547 Dump the contents of section <number|name> as relocated bytes\n\
4548 -z --decompress Decompress section before dumping it\n\
4549 -w[lLiaprmfFsoRtUuTgAckK] or\n\
4550 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
4551 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
4552 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
4553 =addr,=cu_index,=links,=follow-links]\n\
4554 Display the contents of DWARF debug sections\n"));
4555 fprintf (stream, _("\
4556 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4557 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4558 or deeper\n"));
4559 fprintf (stream, _("\
4560 --ctf=<number|name> Display CTF info from section <number|name>\n\
4561 --ctf-parent=<number|name>\n\
4562 Use section <number|name> as the CTF parent\n\n\
4563 --ctf-symbols=<number|name>\n\
4564 Use section <number|name> as the CTF external symtab\n\n\
4565 --ctf-strings=<number|name>\n\
4566 Use section <number|name> as the CTF external strtab\n\n"));
4567
4568 #ifdef SUPPORT_DISASSEMBLY
4569 fprintf (stream, _("\
4570 -i --instruction-dump=<number|name>\n\
4571 Disassemble the contents of section <number|name>\n"));
4572 #endif
4573 fprintf (stream, _("\
4574 -I --histogram Display histogram of bucket list lengths\n\
4575 -W --wide Allow output width to exceed 80 characters\n\
4576 @<file> Read options from <file>\n\
4577 -H --help Display this information\n\
4578 -v --version Display the version number of readelf\n"));
4579
4580 if (REPORT_BUGS_TO[0] && stream == stdout)
4581 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
4582
4583 exit (stream == stdout ? 0 : 1);
4584 }
4585
4586 /* Record the fact that the user wants the contents of section number
4587 SECTION to be displayed using the method(s) encoded as flags bits
4588 in TYPE. Note, TYPE can be zero if we are creating the array for
4589 the first time. */
4590
4591 static void
4592 request_dump_bynumber (Filedata * filedata, unsigned int section, dump_type type)
4593 {
4594 if (section >= filedata->num_dump_sects)
4595 {
4596 dump_type * new_dump_sects;
4597
4598 new_dump_sects = (dump_type *) calloc (section + 1,
4599 sizeof (* new_dump_sects));
4600
4601 if (new_dump_sects == NULL)
4602 error (_("Out of memory allocating dump request table.\n"));
4603 else
4604 {
4605 if (filedata->dump_sects)
4606 {
4607 /* Copy current flag settings. */
4608 memcpy (new_dump_sects, filedata->dump_sects,
4609 filedata->num_dump_sects * sizeof (* new_dump_sects));
4610
4611 free (filedata->dump_sects);
4612 }
4613
4614 filedata->dump_sects = new_dump_sects;
4615 filedata->num_dump_sects = section + 1;
4616 }
4617 }
4618
4619 if (filedata->dump_sects)
4620 filedata->dump_sects[section] |= type;
4621 }
4622
4623 /* Request a dump by section name. */
4624
4625 static void
4626 request_dump_byname (const char * section, dump_type type)
4627 {
4628 struct dump_list_entry * new_request;
4629
4630 new_request = (struct dump_list_entry *)
4631 malloc (sizeof (struct dump_list_entry));
4632 if (!new_request)
4633 error (_("Out of memory allocating dump request table.\n"));
4634
4635 new_request->name = strdup (section);
4636 if (!new_request->name)
4637 error (_("Out of memory allocating dump request table.\n"));
4638
4639 new_request->type = type;
4640
4641 new_request->next = dump_sects_byname;
4642 dump_sects_byname = new_request;
4643 }
4644
4645 static inline void
4646 request_dump (Filedata * filedata, dump_type type)
4647 {
4648 int section;
4649 char * cp;
4650
4651 do_dump++;
4652 section = strtoul (optarg, & cp, 0);
4653
4654 if (! *cp && section >= 0)
4655 request_dump_bynumber (filedata, section, type);
4656 else
4657 request_dump_byname (optarg, type);
4658 }
4659
4660 static void
4661 parse_args (Filedata * filedata, int argc, char ** argv)
4662 {
4663 int c;
4664
4665 if (argc < 2)
4666 usage (stderr);
4667
4668 while ((c = getopt_long
4669 (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
4670 {
4671 switch (c)
4672 {
4673 case 0:
4674 /* Long options. */
4675 break;
4676 case 'H':
4677 usage (stdout);
4678 break;
4679
4680 case 'a':
4681 do_syms = TRUE;
4682 do_reloc = TRUE;
4683 do_unwind = TRUE;
4684 do_dynamic = TRUE;
4685 do_header = TRUE;
4686 do_sections = TRUE;
4687 do_section_groups = TRUE;
4688 do_segments = TRUE;
4689 do_version = TRUE;
4690 do_histogram = TRUE;
4691 do_arch = TRUE;
4692 do_notes = TRUE;
4693 break;
4694 case 'g':
4695 do_section_groups = TRUE;
4696 break;
4697 case 't':
4698 case 'N':
4699 do_sections = TRUE;
4700 do_section_details = TRUE;
4701 break;
4702 case 'e':
4703 do_header = TRUE;
4704 do_sections = TRUE;
4705 do_segments = TRUE;
4706 break;
4707 case 'A':
4708 do_arch = TRUE;
4709 break;
4710 case 'D':
4711 do_using_dynamic = TRUE;
4712 break;
4713 case 'r':
4714 do_reloc = TRUE;
4715 break;
4716 case 'u':
4717 do_unwind = TRUE;
4718 break;
4719 case 'h':
4720 do_header = TRUE;
4721 break;
4722 case 'l':
4723 do_segments = TRUE;
4724 break;
4725 case 's':
4726 do_syms = TRUE;
4727 break;
4728 case 'S':
4729 do_sections = TRUE;
4730 break;
4731 case 'd':
4732 do_dynamic = TRUE;
4733 break;
4734 case 'I':
4735 do_histogram = TRUE;
4736 break;
4737 case 'n':
4738 do_notes = TRUE;
4739 break;
4740 case 'c':
4741 do_archive_index = TRUE;
4742 break;
4743 case 'x':
4744 request_dump (filedata, HEX_DUMP);
4745 break;
4746 case 'p':
4747 request_dump (filedata, STRING_DUMP);
4748 break;
4749 case 'R':
4750 request_dump (filedata, RELOC_DUMP);
4751 break;
4752 case 'z':
4753 decompress_dumps = TRUE;
4754 break;
4755 case 'w':
4756 do_dump = TRUE;
4757 if (optarg == 0)
4758 {
4759 do_debugging = TRUE;
4760 dwarf_select_sections_all ();
4761 }
4762 else
4763 {
4764 do_debugging = FALSE;
4765 dwarf_select_sections_by_letters (optarg);
4766 }
4767 break;
4768 case OPTION_DEBUG_DUMP:
4769 do_dump = TRUE;
4770 if (optarg == 0)
4771 do_debugging = TRUE;
4772 else
4773 {
4774 do_debugging = FALSE;
4775 dwarf_select_sections_by_names (optarg);
4776 }
4777 break;
4778 case OPTION_DWARF_DEPTH:
4779 {
4780 char *cp;
4781
4782 dwarf_cutoff_level = strtoul (optarg, & cp, 0);
4783 }
4784 break;
4785 case OPTION_DWARF_START:
4786 {
4787 char *cp;
4788
4789 dwarf_start_die = strtoul (optarg, & cp, 0);
4790 }
4791 break;
4792 case OPTION_DWARF_CHECK:
4793 dwarf_check = TRUE;
4794 break;
4795 case OPTION_CTF_DUMP:
4796 do_ctf = TRUE;
4797 request_dump (filedata, CTF_DUMP);
4798 break;
4799 case OPTION_CTF_SYMBOLS:
4800 dump_ctf_symtab_name = strdup (optarg);
4801 break;
4802 case OPTION_CTF_STRINGS:
4803 dump_ctf_strtab_name = strdup (optarg);
4804 break;
4805 case OPTION_CTF_PARENT:
4806 dump_ctf_parent_name = strdup (optarg);
4807 break;
4808 case OPTION_DYN_SYMS:
4809 do_dyn_syms = TRUE;
4810 break;
4811 #ifdef SUPPORT_DISASSEMBLY
4812 case 'i':
4813 request_dump (filedata, DISASS_DUMP);
4814 break;
4815 #endif
4816 case 'v':
4817 print_version (program_name);
4818 break;
4819 case 'V':
4820 do_version = TRUE;
4821 break;
4822 case 'W':
4823 do_wide = TRUE;
4824 break;
4825 default:
4826 /* xgettext:c-format */
4827 error (_("Invalid option '-%c'\n"), c);
4828 /* Fall through. */
4829 case '?':
4830 usage (stderr);
4831 }
4832 }
4833
4834 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
4835 && !do_segments && !do_header && !do_dump && !do_version
4836 && !do_histogram && !do_debugging && !do_arch && !do_notes
4837 && !do_section_groups && !do_archive_index
4838 && !do_dyn_syms)
4839 usage (stderr);
4840 }
4841
4842 static const char *
4843 get_elf_class (unsigned int elf_class)
4844 {
4845 static char buff[32];
4846
4847 switch (elf_class)
4848 {
4849 case ELFCLASSNONE: return _("none");
4850 case ELFCLASS32: return "ELF32";
4851 case ELFCLASS64: return "ELF64";
4852 default:
4853 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
4854 return buff;
4855 }
4856 }
4857
4858 static const char *
4859 get_data_encoding (unsigned int encoding)
4860 {
4861 static char buff[32];
4862
4863 switch (encoding)
4864 {
4865 case ELFDATANONE: return _("none");
4866 case ELFDATA2LSB: return _("2's complement, little endian");
4867 case ELFDATA2MSB: return _("2's complement, big endian");
4868 default:
4869 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
4870 return buff;
4871 }
4872 }
4873
4874 /* Decode the data held in 'filedata->file_header'. */
4875
4876 static bfd_boolean
4877 process_file_header (Filedata * filedata)
4878 {
4879 Elf_Internal_Ehdr * header = & filedata->file_header;
4880
4881 if ( header->e_ident[EI_MAG0] != ELFMAG0
4882 || header->e_ident[EI_MAG1] != ELFMAG1
4883 || header->e_ident[EI_MAG2] != ELFMAG2
4884 || header->e_ident[EI_MAG3] != ELFMAG3)
4885 {
4886 error
4887 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
4888 return FALSE;
4889 }
4890
4891 init_dwarf_regnames_by_elf_machine_code (header->e_machine);
4892
4893 if (do_header)
4894 {
4895 unsigned i;
4896
4897 printf (_("ELF Header:\n"));
4898 printf (_(" Magic: "));
4899 for (i = 0; i < EI_NIDENT; i++)
4900 printf ("%2.2x ", header->e_ident[i]);
4901 printf ("\n");
4902 printf (_(" Class: %s\n"),
4903 get_elf_class (header->e_ident[EI_CLASS]));
4904 printf (_(" Data: %s\n"),
4905 get_data_encoding (header->e_ident[EI_DATA]));
4906 printf (_(" Version: %d%s\n"),
4907 header->e_ident[EI_VERSION],
4908 (header->e_ident[EI_VERSION] == EV_CURRENT
4909 ? _(" (current)")
4910 : (header->e_ident[EI_VERSION] != EV_NONE
4911 ? _(" <unknown>")
4912 : "")));
4913 printf (_(" OS/ABI: %s\n"),
4914 get_osabi_name (filedata, header->e_ident[EI_OSABI]));
4915 printf (_(" ABI Version: %d\n"),
4916 header->e_ident[EI_ABIVERSION]);
4917 printf (_(" Type: %s\n"),
4918 get_file_type (header->e_type));
4919 printf (_(" Machine: %s\n"),
4920 get_machine_name (header->e_machine));
4921 printf (_(" Version: 0x%lx\n"),
4922 header->e_version);
4923
4924 printf (_(" Entry point address: "));
4925 print_vma (header->e_entry, PREFIX_HEX);
4926 printf (_("\n Start of program headers: "));
4927 print_vma (header->e_phoff, DEC);
4928 printf (_(" (bytes into file)\n Start of section headers: "));
4929 print_vma (header->e_shoff, DEC);
4930 printf (_(" (bytes into file)\n"));
4931
4932 printf (_(" Flags: 0x%lx%s\n"),
4933 header->e_flags,
4934 get_machine_flags (filedata, header->e_flags, header->e_machine));
4935 printf (_(" Size of this header: %u (bytes)\n"),
4936 header->e_ehsize);
4937 printf (_(" Size of program headers: %u (bytes)\n"),
4938 header->e_phentsize);
4939 printf (_(" Number of program headers: %u"),
4940 header->e_phnum);
4941 if (filedata->section_headers != NULL
4942 && header->e_phnum == PN_XNUM
4943 && filedata->section_headers[0].sh_info != 0)
4944 {
4945 header->e_phnum = filedata->section_headers[0].sh_info;
4946 printf (" (%u)", header->e_phnum);
4947 }
4948 putc ('\n', stdout);
4949 printf (_(" Size of section headers: %u (bytes)\n"),
4950 header->e_shentsize);
4951 printf (_(" Number of section headers: %u"),
4952 header->e_shnum);
4953 if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF)
4954 {
4955 header->e_shnum = filedata->section_headers[0].sh_size;
4956 printf (" (%u)", header->e_shnum);
4957 }
4958 putc ('\n', stdout);
4959 printf (_(" Section header string table index: %u"),
4960 header->e_shstrndx);
4961 if (filedata->section_headers != NULL
4962 && header->e_shstrndx == (SHN_XINDEX & 0xffff))
4963 {
4964 header->e_shstrndx = filedata->section_headers[0].sh_link;
4965 printf (" (%u)", header->e_shstrndx);
4966 }
4967 if (header->e_shstrndx != SHN_UNDEF
4968 && header->e_shstrndx >= header->e_shnum)
4969 {
4970 header->e_shstrndx = SHN_UNDEF;
4971 printf (_(" <corrupt: out of range>"));
4972 }
4973 putc ('\n', stdout);
4974 }
4975
4976 if (filedata->section_headers != NULL)
4977 {
4978 if (header->e_phnum == PN_XNUM
4979 && filedata->section_headers[0].sh_info != 0)
4980 header->e_phnum = filedata->section_headers[0].sh_info;
4981 if (header->e_shnum == SHN_UNDEF)
4982 header->e_shnum = filedata->section_headers[0].sh_size;
4983 if (header->e_shstrndx == (SHN_XINDEX & 0xffff))
4984 header->e_shstrndx = filedata->section_headers[0].sh_link;
4985 if (header->e_shstrndx >= header->e_shnum)
4986 header->e_shstrndx = SHN_UNDEF;
4987 free (filedata->section_headers);
4988 filedata->section_headers = NULL;
4989 }
4990
4991 return TRUE;
4992 }
4993
4994 /* Read in the program headers from FILEDATA and store them in PHEADERS.
4995 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
4996
4997 static bfd_boolean
4998 get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
4999 {
5000 Elf32_External_Phdr * phdrs;
5001 Elf32_External_Phdr * external;
5002 Elf_Internal_Phdr * internal;
5003 unsigned int i;
5004 unsigned int size = filedata->file_header.e_phentsize;
5005 unsigned int num = filedata->file_header.e_phnum;
5006
5007 /* PR binutils/17531: Cope with unexpected section header sizes. */
5008 if (size == 0 || num == 0)
5009 return FALSE;
5010 if (size < sizeof * phdrs)
5011 {
5012 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5013 return FALSE;
5014 }
5015 if (size > sizeof * phdrs)
5016 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5017
5018 phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
5019 size, num, _("program headers"));
5020 if (phdrs == NULL)
5021 return FALSE;
5022
5023 for (i = 0, internal = pheaders, external = phdrs;
5024 i < filedata->file_header.e_phnum;
5025 i++, internal++, external++)
5026 {
5027 internal->p_type = BYTE_GET (external->p_type);
5028 internal->p_offset = BYTE_GET (external->p_offset);
5029 internal->p_vaddr = BYTE_GET (external->p_vaddr);
5030 internal->p_paddr = BYTE_GET (external->p_paddr);
5031 internal->p_filesz = BYTE_GET (external->p_filesz);
5032 internal->p_memsz = BYTE_GET (external->p_memsz);
5033 internal->p_flags = BYTE_GET (external->p_flags);
5034 internal->p_align = BYTE_GET (external->p_align);
5035 }
5036
5037 free (phdrs);
5038 return TRUE;
5039 }
5040
5041 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5042 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5043
5044 static bfd_boolean
5045 get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
5046 {
5047 Elf64_External_Phdr * phdrs;
5048 Elf64_External_Phdr * external;
5049 Elf_Internal_Phdr * internal;
5050 unsigned int i;
5051 unsigned int size = filedata->file_header.e_phentsize;
5052 unsigned int num = filedata->file_header.e_phnum;
5053
5054 /* PR binutils/17531: Cope with unexpected section header sizes. */
5055 if (size == 0 || num == 0)
5056 return FALSE;
5057 if (size < sizeof * phdrs)
5058 {
5059 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5060 return FALSE;
5061 }
5062 if (size > sizeof * phdrs)
5063 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5064
5065 phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
5066 size, num, _("program headers"));
5067 if (!phdrs)
5068 return FALSE;
5069
5070 for (i = 0, internal = pheaders, external = phdrs;
5071 i < filedata->file_header.e_phnum;
5072 i++, internal++, external++)
5073 {
5074 internal->p_type = BYTE_GET (external->p_type);
5075 internal->p_flags = BYTE_GET (external->p_flags);
5076 internal->p_offset = BYTE_GET (external->p_offset);
5077 internal->p_vaddr = BYTE_GET (external->p_vaddr);
5078 internal->p_paddr = BYTE_GET (external->p_paddr);
5079 internal->p_filesz = BYTE_GET (external->p_filesz);
5080 internal->p_memsz = BYTE_GET (external->p_memsz);
5081 internal->p_align = BYTE_GET (external->p_align);
5082 }
5083
5084 free (phdrs);
5085 return TRUE;
5086 }
5087
5088 /* Returns TRUE if the program headers were read into `program_headers'. */
5089
5090 static bfd_boolean
5091 get_program_headers (Filedata * filedata)
5092 {
5093 Elf_Internal_Phdr * phdrs;
5094
5095 /* Check cache of prior read. */
5096 if (filedata->program_headers != NULL)
5097 return TRUE;
5098
5099 /* Be kind to memory checkers by looking for
5100 e_phnum values which we know must be invalid. */
5101 if (filedata->file_header.e_phnum
5102 * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr))
5103 >= filedata->file_size)
5104 {
5105 error (_("Too many program headers - %#x - the file is not that big\n"),
5106 filedata->file_header.e_phnum);
5107 return FALSE;
5108 }
5109
5110 phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum,
5111 sizeof (Elf_Internal_Phdr));
5112 if (phdrs == NULL)
5113 {
5114 error (_("Out of memory reading %u program headers\n"),
5115 filedata->file_header.e_phnum);
5116 return FALSE;
5117 }
5118
5119 if (is_32bit_elf
5120 ? get_32bit_program_headers (filedata, phdrs)
5121 : get_64bit_program_headers (filedata, phdrs))
5122 {
5123 filedata->program_headers = phdrs;
5124 return TRUE;
5125 }
5126
5127 free (phdrs);
5128 return FALSE;
5129 }
5130
5131 /* Returns TRUE if the program headers were loaded. */
5132
5133 static bfd_boolean
5134 process_program_headers (Filedata * filedata)
5135 {
5136 Elf_Internal_Phdr * segment;
5137 unsigned int i;
5138 Elf_Internal_Phdr * previous_load = NULL;
5139
5140 dynamic_addr = 0;
5141 dynamic_size = 0;
5142
5143 if (filedata->file_header.e_phnum == 0)
5144 {
5145 /* PR binutils/12467. */
5146 if (filedata->file_header.e_phoff != 0)
5147 {
5148 warn (_("possibly corrupt ELF header - it has a non-zero program"
5149 " header offset, but no program headers\n"));
5150 return FALSE;
5151 }
5152 else if (do_segments)
5153 printf (_("\nThere are no program headers in this file.\n"));
5154 return TRUE;
5155 }
5156
5157 if (do_segments && !do_header)
5158 {
5159 printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type));
5160 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry));
5161 printf (ngettext ("There is %d program header, starting at offset %s\n",
5162 "There are %d program headers, starting at offset %s\n",
5163 filedata->file_header.e_phnum),
5164 filedata->file_header.e_phnum,
5165 bfd_vmatoa ("u", filedata->file_header.e_phoff));
5166 }
5167
5168 if (! get_program_headers (filedata))
5169 return TRUE;
5170
5171 if (do_segments)
5172 {
5173 if (filedata->file_header.e_phnum > 1)
5174 printf (_("\nProgram Headers:\n"));
5175 else
5176 printf (_("\nProgram Headers:\n"));
5177
5178 if (is_32bit_elf)
5179 printf
5180 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5181 else if (do_wide)
5182 printf
5183 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5184 else
5185 {
5186 printf
5187 (_(" Type Offset VirtAddr PhysAddr\n"));
5188 printf
5189 (_(" FileSiz MemSiz Flags Align\n"));
5190 }
5191 }
5192
5193 for (i = 0, segment = filedata->program_headers;
5194 i < filedata->file_header.e_phnum;
5195 i++, segment++)
5196 {
5197 if (do_segments)
5198 {
5199 printf (" %-14.14s ", get_segment_type (filedata, segment->p_type));
5200
5201 if (is_32bit_elf)
5202 {
5203 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5204 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
5205 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
5206 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
5207 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
5208 printf ("%c%c%c ",
5209 (segment->p_flags & PF_R ? 'R' : ' '),
5210 (segment->p_flags & PF_W ? 'W' : ' '),
5211 (segment->p_flags & PF_X ? 'E' : ' '));
5212 printf ("%#lx", (unsigned long) segment->p_align);
5213 }
5214 else if (do_wide)
5215 {
5216 if ((unsigned long) segment->p_offset == segment->p_offset)
5217 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
5218 else
5219 {
5220 print_vma (segment->p_offset, FULL_HEX);
5221 putchar (' ');
5222 }
5223
5224 print_vma (segment->p_vaddr, FULL_HEX);
5225 putchar (' ');
5226 print_vma (segment->p_paddr, FULL_HEX);
5227 putchar (' ');
5228
5229 if ((unsigned long) segment->p_filesz == segment->p_filesz)
5230 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
5231 else
5232 {
5233 print_vma (segment->p_filesz, FULL_HEX);
5234 putchar (' ');
5235 }
5236
5237 if ((unsigned long) segment->p_memsz == segment->p_memsz)
5238 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
5239 else
5240 {
5241 print_vma (segment->p_memsz, FULL_HEX);
5242 }
5243
5244 printf (" %c%c%c ",
5245 (segment->p_flags & PF_R ? 'R' : ' '),
5246 (segment->p_flags & PF_W ? 'W' : ' '),
5247 (segment->p_flags & PF_X ? 'E' : ' '));
5248
5249 if ((unsigned long) segment->p_align == segment->p_align)
5250 printf ("%#lx", (unsigned long) segment->p_align);
5251 else
5252 {
5253 print_vma (segment->p_align, PREFIX_HEX);
5254 }
5255 }
5256 else
5257 {
5258 print_vma (segment->p_offset, FULL_HEX);
5259 putchar (' ');
5260 print_vma (segment->p_vaddr, FULL_HEX);
5261 putchar (' ');
5262 print_vma (segment->p_paddr, FULL_HEX);
5263 printf ("\n ");
5264 print_vma (segment->p_filesz, FULL_HEX);
5265 putchar (' ');
5266 print_vma (segment->p_memsz, FULL_HEX);
5267 printf (" %c%c%c ",
5268 (segment->p_flags & PF_R ? 'R' : ' '),
5269 (segment->p_flags & PF_W ? 'W' : ' '),
5270 (segment->p_flags & PF_X ? 'E' : ' '));
5271 print_vma (segment->p_align, PREFIX_HEX);
5272 }
5273
5274 putc ('\n', stdout);
5275 }
5276
5277 switch (segment->p_type)
5278 {
5279 case PT_LOAD:
5280 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5281 required by the ELF standard, several programs, including the Linux
5282 kernel, make use of non-ordered segments. */
5283 if (previous_load
5284 && previous_load->p_vaddr > segment->p_vaddr)
5285 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
5286 #endif
5287 if (segment->p_memsz < segment->p_filesz)
5288 error (_("the segment's file size is larger than its memory size\n"));
5289 previous_load = segment;
5290 break;
5291
5292 case PT_PHDR:
5293 /* PR 20815 - Verify that the program header is loaded into memory. */
5294 if (i > 0 && previous_load != NULL)
5295 error (_("the PHDR segment must occur before any LOAD segment\n"));
5296 if (filedata->file_header.e_machine != EM_PARISC)
5297 {
5298 unsigned int j;
5299
5300 for (j = 1; j < filedata->file_header.e_phnum; j++)
5301 {
5302 Elf_Internal_Phdr *load = filedata->program_headers + j;
5303 if (load->p_type == PT_LOAD
5304 && load->p_offset <= segment->p_offset
5305 && (load->p_offset + load->p_filesz
5306 >= segment->p_offset + segment->p_filesz)
5307 && load->p_vaddr <= segment->p_vaddr
5308 && (load->p_vaddr + load->p_filesz
5309 >= segment->p_vaddr + segment->p_filesz))
5310 break;
5311 }
5312 if (j == filedata->file_header.e_phnum)
5313 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5314 }
5315 break;
5316
5317 case PT_DYNAMIC:
5318 if (dynamic_addr)
5319 error (_("more than one dynamic segment\n"));
5320
5321 /* By default, assume that the .dynamic section is the first
5322 section in the DYNAMIC segment. */
5323 dynamic_addr = segment->p_offset;
5324 dynamic_size = segment->p_filesz;
5325
5326 /* Try to locate the .dynamic section. If there is
5327 a section header table, we can easily locate it. */
5328 if (filedata->section_headers != NULL)
5329 {
5330 Elf_Internal_Shdr * sec;
5331
5332 sec = find_section (filedata, ".dynamic");
5333 if (sec == NULL || sec->sh_size == 0)
5334 {
5335 /* A corresponding .dynamic section is expected, but on
5336 IA-64/OpenVMS it is OK for it to be missing. */
5337 if (!is_ia64_vms (filedata))
5338 error (_("no .dynamic section in the dynamic segment\n"));
5339 break;
5340 }
5341
5342 if (sec->sh_type == SHT_NOBITS)
5343 {
5344 dynamic_size = 0;
5345 break;
5346 }
5347
5348 dynamic_addr = sec->sh_offset;
5349 dynamic_size = sec->sh_size;
5350
5351 if (dynamic_addr < segment->p_offset
5352 || dynamic_addr > segment->p_offset + segment->p_filesz)
5353 warn (_("the .dynamic section is not contained"
5354 " within the dynamic segment\n"));
5355 else if (dynamic_addr > segment->p_offset)
5356 warn (_("the .dynamic section is not the first section"
5357 " in the dynamic segment.\n"));
5358 }
5359
5360 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5361 segment. Check this after matching against the section headers
5362 so we don't warn on debuginfo file (which have NOBITS .dynamic
5363 sections). */
5364 if (dynamic_addr > filedata->file_size
5365 || dynamic_size > filedata->file_size - dynamic_addr)
5366 {
5367 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5368 dynamic_addr = dynamic_size = 0;
5369 }
5370 break;
5371
5372 case PT_INTERP:
5373 if (fseek (filedata->handle, archive_file_offset + (long) segment->p_offset,
5374 SEEK_SET))
5375 error (_("Unable to find program interpreter name\n"));
5376 else
5377 {
5378 char fmt [32];
5379 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
5380
5381 if (ret >= (int) sizeof (fmt) || ret < 0)
5382 error (_("Internal error: failed to create format string to display program interpreter\n"));
5383
5384 program_interpreter[0] = 0;
5385 if (fscanf (filedata->handle, fmt, program_interpreter) <= 0)
5386 error (_("Unable to read program interpreter name\n"));
5387
5388 if (do_segments)
5389 printf (_(" [Requesting program interpreter: %s]\n"),
5390 program_interpreter);
5391 }
5392 break;
5393 }
5394 }
5395
5396 if (do_segments
5397 && filedata->section_headers != NULL
5398 && filedata->string_table != NULL)
5399 {
5400 printf (_("\n Section to Segment mapping:\n"));
5401 printf (_(" Segment Sections...\n"));
5402
5403 for (i = 0; i < filedata->file_header.e_phnum; i++)
5404 {
5405 unsigned int j;
5406 Elf_Internal_Shdr * section;
5407
5408 segment = filedata->program_headers + i;
5409 section = filedata->section_headers + 1;
5410
5411 printf (" %2.2d ", i);
5412
5413 for (j = 1; j < filedata->file_header.e_shnum; j++, section++)
5414 {
5415 if (!ELF_TBSS_SPECIAL (section, segment)
5416 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
5417 printf ("%s ", printable_section_name (filedata, section));
5418 }
5419
5420 putc ('\n',stdout);
5421 }
5422 }
5423
5424 return TRUE;
5425 }
5426
5427
5428 /* Find the file offset corresponding to VMA by using the program headers. */
5429
5430 static long
5431 offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size)
5432 {
5433 Elf_Internal_Phdr * seg;
5434
5435 if (! get_program_headers (filedata))
5436 {
5437 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5438 return (long) vma;
5439 }
5440
5441 for (seg = filedata->program_headers;
5442 seg < filedata->program_headers + filedata->file_header.e_phnum;
5443 ++seg)
5444 {
5445 if (seg->p_type != PT_LOAD)
5446 continue;
5447
5448 if (vma >= (seg->p_vaddr & -seg->p_align)
5449 && vma + size <= seg->p_vaddr + seg->p_filesz)
5450 return vma - seg->p_vaddr + seg->p_offset;
5451 }
5452
5453 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
5454 (unsigned long) vma);
5455 return (long) vma;
5456 }
5457
5458
5459 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5460 If PROBE is true, this is just a probe and we do not generate any error
5461 messages if the load fails. */
5462
5463 static bfd_boolean
5464 get_32bit_section_headers (Filedata * filedata, bfd_boolean probe)
5465 {
5466 Elf32_External_Shdr * shdrs;
5467 Elf_Internal_Shdr * internal;
5468 unsigned int i;
5469 unsigned int size = filedata->file_header.e_shentsize;
5470 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
5471
5472 /* PR binutils/17531: Cope with unexpected section header sizes. */
5473 if (size == 0 || num == 0)
5474 return FALSE;
5475 if (size < sizeof * shdrs)
5476 {
5477 if (! probe)
5478 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5479 return FALSE;
5480 }
5481 if (!probe && size > sizeof * shdrs)
5482 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5483
5484 shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff,
5485 size, num,
5486 probe ? NULL : _("section headers"));
5487 if (shdrs == NULL)
5488 return FALSE;
5489
5490 free (filedata->section_headers);
5491 filedata->section_headers = (Elf_Internal_Shdr *)
5492 cmalloc (num, sizeof (Elf_Internal_Shdr));
5493 if (filedata->section_headers == NULL)
5494 {
5495 if (!probe)
5496 error (_("Out of memory reading %u section headers\n"), num);
5497 free (shdrs);
5498 return FALSE;
5499 }
5500
5501 for (i = 0, internal = filedata->section_headers;
5502 i < num;
5503 i++, internal++)
5504 {
5505 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5506 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
5507 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5508 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5509 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5510 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5511 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5512 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5513 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
5514 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
5515 if (!probe && internal->sh_link > num)
5516 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5517 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5518 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
5519 }
5520
5521 free (shdrs);
5522 return TRUE;
5523 }
5524
5525 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5526
5527 static bfd_boolean
5528 get_64bit_section_headers (Filedata * filedata, bfd_boolean probe)
5529 {
5530 Elf64_External_Shdr * shdrs;
5531 Elf_Internal_Shdr * internal;
5532 unsigned int i;
5533 unsigned int size = filedata->file_header.e_shentsize;
5534 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
5535
5536 /* PR binutils/17531: Cope with unexpected section header sizes. */
5537 if (size == 0 || num == 0)
5538 return FALSE;
5539
5540 if (size < sizeof * shdrs)
5541 {
5542 if (! probe)
5543 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5544 return FALSE;
5545 }
5546
5547 if (! probe && size > sizeof * shdrs)
5548 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5549
5550 shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata,
5551 filedata->file_header.e_shoff,
5552 size, num,
5553 probe ? NULL : _("section headers"));
5554 if (shdrs == NULL)
5555 return FALSE;
5556
5557 free (filedata->section_headers);
5558 filedata->section_headers = (Elf_Internal_Shdr *)
5559 cmalloc (num, sizeof (Elf_Internal_Shdr));
5560 if (filedata->section_headers == NULL)
5561 {
5562 if (! probe)
5563 error (_("Out of memory reading %u section headers\n"), num);
5564 free (shdrs);
5565 return FALSE;
5566 }
5567
5568 for (i = 0, internal = filedata->section_headers;
5569 i < num;
5570 i++, internal++)
5571 {
5572 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5573 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
5574 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5575 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5576 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5577 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
5578 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5579 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5580 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5581 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
5582 if (!probe && internal->sh_link > num)
5583 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5584 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5585 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
5586 }
5587
5588 free (shdrs);
5589 return TRUE;
5590 }
5591
5592 static Elf_Internal_Sym *
5593 get_32bit_elf_symbols (Filedata * filedata,
5594 Elf_Internal_Shdr * section,
5595 unsigned long * num_syms_return)
5596 {
5597 unsigned long number = 0;
5598 Elf32_External_Sym * esyms = NULL;
5599 Elf_External_Sym_Shndx * shndx = NULL;
5600 Elf_Internal_Sym * isyms = NULL;
5601 Elf_Internal_Sym * psym;
5602 unsigned int j;
5603 elf_section_list * entry;
5604
5605 if (section->sh_size == 0)
5606 {
5607 if (num_syms_return != NULL)
5608 * num_syms_return = 0;
5609 return NULL;
5610 }
5611
5612 /* Run some sanity checks first. */
5613 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
5614 {
5615 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5616 printable_section_name (filedata, section),
5617 (unsigned long) section->sh_entsize);
5618 goto exit_point;
5619 }
5620
5621 if (section->sh_size > filedata->file_size)
5622 {
5623 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5624 printable_section_name (filedata, section),
5625 (unsigned long) section->sh_size);
5626 goto exit_point;
5627 }
5628
5629 number = section->sh_size / section->sh_entsize;
5630
5631 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
5632 {
5633 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5634 (unsigned long) section->sh_size,
5635 printable_section_name (filedata, section),
5636 (unsigned long) section->sh_entsize);
5637 goto exit_point;
5638 }
5639
5640 esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
5641 section->sh_size, _("symbols"));
5642 if (esyms == NULL)
5643 goto exit_point;
5644
5645 shndx = NULL;
5646 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5647 {
5648 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5649 continue;
5650
5651 if (shndx != NULL)
5652 {
5653 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5654 free (shndx);
5655 }
5656
5657 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5658 entry->hdr->sh_offset,
5659 1, entry->hdr->sh_size,
5660 _("symbol table section indices"));
5661 if (shndx == NULL)
5662 goto exit_point;
5663
5664 /* PR17531: file: heap-buffer-overflow */
5665 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5666 {
5667 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5668 printable_section_name (filedata, entry->hdr),
5669 (unsigned long) entry->hdr->sh_size,
5670 (unsigned long) section->sh_size);
5671 goto exit_point;
5672 }
5673 }
5674
5675 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
5676
5677 if (isyms == NULL)
5678 {
5679 error (_("Out of memory reading %lu symbols\n"),
5680 (unsigned long) number);
5681 goto exit_point;
5682 }
5683
5684 for (j = 0, psym = isyms; j < number; j++, psym++)
5685 {
5686 psym->st_name = BYTE_GET (esyms[j].st_name);
5687 psym->st_value = BYTE_GET (esyms[j].st_value);
5688 psym->st_size = BYTE_GET (esyms[j].st_size);
5689 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
5690 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
5691 psym->st_shndx
5692 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
5693 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5694 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
5695 psym->st_info = BYTE_GET (esyms[j].st_info);
5696 psym->st_other = BYTE_GET (esyms[j].st_other);
5697 }
5698
5699 exit_point:
5700 free (shndx);
5701 free (esyms);
5702
5703 if (num_syms_return != NULL)
5704 * num_syms_return = isyms == NULL ? 0 : number;
5705
5706 return isyms;
5707 }
5708
5709 static Elf_Internal_Sym *
5710 get_64bit_elf_symbols (Filedata * filedata,
5711 Elf_Internal_Shdr * section,
5712 unsigned long * num_syms_return)
5713 {
5714 unsigned long number = 0;
5715 Elf64_External_Sym * esyms = NULL;
5716 Elf_External_Sym_Shndx * shndx = NULL;
5717 Elf_Internal_Sym * isyms = NULL;
5718 Elf_Internal_Sym * psym;
5719 unsigned int j;
5720 elf_section_list * entry;
5721
5722 if (section->sh_size == 0)
5723 {
5724 if (num_syms_return != NULL)
5725 * num_syms_return = 0;
5726 return NULL;
5727 }
5728
5729 /* Run some sanity checks first. */
5730 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
5731 {
5732 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5733 printable_section_name (filedata, section),
5734 (unsigned long) section->sh_entsize);
5735 goto exit_point;
5736 }
5737
5738 if (section->sh_size > filedata->file_size)
5739 {
5740 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5741 printable_section_name (filedata, section),
5742 (unsigned long) section->sh_size);
5743 goto exit_point;
5744 }
5745
5746 number = section->sh_size / section->sh_entsize;
5747
5748 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
5749 {
5750 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5751 (unsigned long) section->sh_size,
5752 printable_section_name (filedata, section),
5753 (unsigned long) section->sh_entsize);
5754 goto exit_point;
5755 }
5756
5757 esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
5758 section->sh_size, _("symbols"));
5759 if (!esyms)
5760 goto exit_point;
5761
5762 shndx = NULL;
5763 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5764 {
5765 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
5766 continue;
5767
5768 if (shndx != NULL)
5769 {
5770 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5771 free (shndx);
5772 }
5773
5774 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5775 entry->hdr->sh_offset,
5776 1, entry->hdr->sh_size,
5777 _("symbol table section indices"));
5778 if (shndx == NULL)
5779 goto exit_point;
5780
5781 /* PR17531: file: heap-buffer-overflow */
5782 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5783 {
5784 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5785 printable_section_name (filedata, entry->hdr),
5786 (unsigned long) entry->hdr->sh_size,
5787 (unsigned long) section->sh_size);
5788 goto exit_point;
5789 }
5790 }
5791
5792 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
5793
5794 if (isyms == NULL)
5795 {
5796 error (_("Out of memory reading %lu symbols\n"),
5797 (unsigned long) number);
5798 goto exit_point;
5799 }
5800
5801 for (j = 0, psym = isyms; j < number; j++, psym++)
5802 {
5803 psym->st_name = BYTE_GET (esyms[j].st_name);
5804 psym->st_info = BYTE_GET (esyms[j].st_info);
5805 psym->st_other = BYTE_GET (esyms[j].st_other);
5806 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
5807
5808 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
5809 psym->st_shndx
5810 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
5811 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5812 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
5813
5814 psym->st_value = BYTE_GET (esyms[j].st_value);
5815 psym->st_size = BYTE_GET (esyms[j].st_size);
5816 }
5817
5818 exit_point:
5819 free (shndx);
5820 free (esyms);
5821
5822 if (num_syms_return != NULL)
5823 * num_syms_return = isyms == NULL ? 0 : number;
5824
5825 return isyms;
5826 }
5827
5828 static const char *
5829 get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
5830 {
5831 static char buff[1024];
5832 char * p = buff;
5833 unsigned int field_size = is_32bit_elf ? 8 : 16;
5834 signed int sindex;
5835 unsigned int size = sizeof (buff) - (field_size + 4 + 1);
5836 bfd_vma os_flags = 0;
5837 bfd_vma proc_flags = 0;
5838 bfd_vma unknown_flags = 0;
5839 static const struct
5840 {
5841 const char * str;
5842 unsigned int len;
5843 }
5844 flags [] =
5845 {
5846 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
5847 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
5848 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
5849 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
5850 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
5851 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
5852 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
5853 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
5854 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
5855 /* 9 */ { STRING_COMMA_LEN ("TLS") },
5856 /* IA-64 specific. */
5857 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
5858 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
5859 /* IA-64 OpenVMS specific. */
5860 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
5861 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
5862 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
5863 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
5864 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
5865 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
5866 /* Generic. */
5867 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
5868 /* SPARC specific. */
5869 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
5870 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
5871 /* ARM specific. */
5872 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
5873 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
5874 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
5875 /* GNU specific. */
5876 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
5877 /* VLE specific. */
5878 /* 25 */ { STRING_COMMA_LEN ("VLE") },
5879 };
5880
5881 if (do_section_details)
5882 {
5883 sprintf (buff, "[%*.*lx]: ",
5884 field_size, field_size, (unsigned long) sh_flags);
5885 p += field_size + 4;
5886 }
5887
5888 while (sh_flags)
5889 {
5890 bfd_vma flag;
5891
5892 flag = sh_flags & - sh_flags;
5893 sh_flags &= ~ flag;
5894
5895 if (do_section_details)
5896 {
5897 switch (flag)
5898 {
5899 case SHF_WRITE: sindex = 0; break;
5900 case SHF_ALLOC: sindex = 1; break;
5901 case SHF_EXECINSTR: sindex = 2; break;
5902 case SHF_MERGE: sindex = 3; break;
5903 case SHF_STRINGS: sindex = 4; break;
5904 case SHF_INFO_LINK: sindex = 5; break;
5905 case SHF_LINK_ORDER: sindex = 6; break;
5906 case SHF_OS_NONCONFORMING: sindex = 7; break;
5907 case SHF_GROUP: sindex = 8; break;
5908 case SHF_TLS: sindex = 9; break;
5909 case SHF_EXCLUDE: sindex = 18; break;
5910 case SHF_COMPRESSED: sindex = 20; break;
5911 case SHF_GNU_MBIND: sindex = 24; break;
5912
5913 default:
5914 sindex = -1;
5915 switch (filedata->file_header.e_machine)
5916 {
5917 case EM_IA_64:
5918 if (flag == SHF_IA_64_SHORT)
5919 sindex = 10;
5920 else if (flag == SHF_IA_64_NORECOV)
5921 sindex = 11;
5922 #ifdef BFD64
5923 else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
5924 switch (flag)
5925 {
5926 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
5927 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
5928 case SHF_IA_64_VMS_SHARED: sindex = 14; break;
5929 case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
5930 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
5931 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
5932 default: break;
5933 }
5934 #endif
5935 break;
5936
5937 case EM_386:
5938 case EM_IAMCU:
5939 case EM_X86_64:
5940 case EM_L1OM:
5941 case EM_K1OM:
5942 case EM_OLD_SPARCV9:
5943 case EM_SPARC32PLUS:
5944 case EM_SPARCV9:
5945 case EM_SPARC:
5946 if (flag == SHF_ORDERED)
5947 sindex = 19;
5948 break;
5949
5950 case EM_ARM:
5951 switch (flag)
5952 {
5953 case SHF_ENTRYSECT: sindex = 21; break;
5954 case SHF_ARM_PURECODE: sindex = 22; break;
5955 case SHF_COMDEF: sindex = 23; break;
5956 default: break;
5957 }
5958 break;
5959 case EM_PPC:
5960 if (flag == SHF_PPC_VLE)
5961 sindex = 25;
5962 break;
5963
5964 default:
5965 break;
5966 }
5967 }
5968
5969 if (sindex != -1)
5970 {
5971 if (p != buff + field_size + 4)
5972 {
5973 if (size < (10 + 2))
5974 {
5975 warn (_("Internal error: not enough buffer room for section flag info"));
5976 return _("<unknown>");
5977 }
5978 size -= 2;
5979 *p++ = ',';
5980 *p++ = ' ';
5981 }
5982
5983 size -= flags [sindex].len;
5984 p = stpcpy (p, flags [sindex].str);
5985 }
5986 else if (flag & SHF_MASKOS)
5987 os_flags |= flag;
5988 else if (flag & SHF_MASKPROC)
5989 proc_flags |= flag;
5990 else
5991 unknown_flags |= flag;
5992 }
5993 else
5994 {
5995 switch (flag)
5996 {
5997 case SHF_WRITE: *p = 'W'; break;
5998 case SHF_ALLOC: *p = 'A'; break;
5999 case SHF_EXECINSTR: *p = 'X'; break;
6000 case SHF_MERGE: *p = 'M'; break;
6001 case SHF_STRINGS: *p = 'S'; break;
6002 case SHF_INFO_LINK: *p = 'I'; break;
6003 case SHF_LINK_ORDER: *p = 'L'; break;
6004 case SHF_OS_NONCONFORMING: *p = 'O'; break;
6005 case SHF_GROUP: *p = 'G'; break;
6006 case SHF_TLS: *p = 'T'; break;
6007 case SHF_EXCLUDE: *p = 'E'; break;
6008 case SHF_COMPRESSED: *p = 'C'; break;
6009 case SHF_GNU_MBIND: *p = 'D'; break;
6010
6011 default:
6012 if ((filedata->file_header.e_machine == EM_X86_64
6013 || filedata->file_header.e_machine == EM_L1OM
6014 || filedata->file_header.e_machine == EM_K1OM)
6015 && flag == SHF_X86_64_LARGE)
6016 *p = 'l';
6017 else if (filedata->file_header.e_machine == EM_ARM
6018 && flag == SHF_ARM_PURECODE)
6019 *p = 'y';
6020 else if (filedata->file_header.e_machine == EM_PPC
6021 && flag == SHF_PPC_VLE)
6022 *p = 'v';
6023 else if (flag & SHF_MASKOS)
6024 {
6025 *p = 'o';
6026 sh_flags &= ~ SHF_MASKOS;
6027 }
6028 else if (flag & SHF_MASKPROC)
6029 {
6030 *p = 'p';
6031 sh_flags &= ~ SHF_MASKPROC;
6032 }
6033 else
6034 *p = 'x';
6035 break;
6036 }
6037 p++;
6038 }
6039 }
6040
6041 if (do_section_details)
6042 {
6043 if (os_flags)
6044 {
6045 size -= 5 + field_size;
6046 if (p != buff + field_size + 4)
6047 {
6048 if (size < (2 + 1))
6049 {
6050 warn (_("Internal error: not enough buffer room for section flag info"));
6051 return _("<unknown>");
6052 }
6053 size -= 2;
6054 *p++ = ',';
6055 *p++ = ' ';
6056 }
6057 sprintf (p, "OS (%*.*lx)", field_size, field_size,
6058 (unsigned long) os_flags);
6059 p += 5 + field_size;
6060 }
6061 if (proc_flags)
6062 {
6063 size -= 7 + field_size;
6064 if (p != buff + field_size + 4)
6065 {
6066 if (size < (2 + 1))
6067 {
6068 warn (_("Internal error: not enough buffer room for section flag info"));
6069 return _("<unknown>");
6070 }
6071 size -= 2;
6072 *p++ = ',';
6073 *p++ = ' ';
6074 }
6075 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
6076 (unsigned long) proc_flags);
6077 p += 7 + field_size;
6078 }
6079 if (unknown_flags)
6080 {
6081 size -= 10 + field_size;
6082 if (p != buff + field_size + 4)
6083 {
6084 if (size < (2 + 1))
6085 {
6086 warn (_("Internal error: not enough buffer room for section flag info"));
6087 return _("<unknown>");
6088 }
6089 size -= 2;
6090 *p++ = ',';
6091 *p++ = ' ';
6092 }
6093 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
6094 (unsigned long) unknown_flags);
6095 p += 10 + field_size;
6096 }
6097 }
6098
6099 *p = '\0';
6100 return buff;
6101 }
6102
6103 static unsigned int
6104 get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size)
6105 {
6106 if (is_32bit_elf)
6107 {
6108 Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
6109
6110 if (size < sizeof (* echdr))
6111 {
6112 error (_("Compressed section is too small even for a compression header\n"));
6113 return 0;
6114 }
6115
6116 chdr->ch_type = BYTE_GET (echdr->ch_type);
6117 chdr->ch_size = BYTE_GET (echdr->ch_size);
6118 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6119 return sizeof (*echdr);
6120 }
6121 else
6122 {
6123 Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
6124
6125 if (size < sizeof (* echdr))
6126 {
6127 error (_("Compressed section is too small even for a compression header\n"));
6128 return 0;
6129 }
6130
6131 chdr->ch_type = BYTE_GET (echdr->ch_type);
6132 chdr->ch_size = BYTE_GET (echdr->ch_size);
6133 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
6134 return sizeof (*echdr);
6135 }
6136 }
6137
6138 static bfd_boolean
6139 process_section_headers (Filedata * filedata)
6140 {
6141 Elf_Internal_Shdr * section;
6142 unsigned int i;
6143
6144 filedata->section_headers = NULL;
6145
6146 if (filedata->file_header.e_shnum == 0)
6147 {
6148 /* PR binutils/12467. */
6149 if (filedata->file_header.e_shoff != 0)
6150 {
6151 warn (_("possibly corrupt ELF file header - it has a non-zero"
6152 " section header offset, but no section headers\n"));
6153 return FALSE;
6154 }
6155 else if (do_sections)
6156 printf (_("\nThere are no sections in this file.\n"));
6157
6158 return TRUE;
6159 }
6160
6161 if (do_sections && !do_header)
6162 printf (ngettext ("There is %d section header, "
6163 "starting at offset 0x%lx:\n",
6164 "There are %d section headers, "
6165 "starting at offset 0x%lx:\n",
6166 filedata->file_header.e_shnum),
6167 filedata->file_header.e_shnum,
6168 (unsigned long) filedata->file_header.e_shoff);
6169
6170 if (is_32bit_elf)
6171 {
6172 if (! get_32bit_section_headers (filedata, FALSE))
6173 return FALSE;
6174 }
6175 else
6176 {
6177 if (! get_64bit_section_headers (filedata, FALSE))
6178 return FALSE;
6179 }
6180
6181 /* Read in the string table, so that we have names to display. */
6182 if (filedata->file_header.e_shstrndx != SHN_UNDEF
6183 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
6184 {
6185 section = filedata->section_headers + filedata->file_header.e_shstrndx;
6186
6187 if (section->sh_size != 0)
6188 {
6189 filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset,
6190 1, section->sh_size,
6191 _("string table"));
6192
6193 filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0;
6194 }
6195 }
6196
6197 /* Scan the sections for the dynamic symbol table
6198 and dynamic string table and debug sections. */
6199 dynamic_symbols = NULL;
6200 dynamic_strings = NULL;
6201 dynamic_syminfo = NULL;
6202 symtab_shndx_list = NULL;
6203
6204 eh_addr_size = is_32bit_elf ? 4 : 8;
6205 switch (filedata->file_header.e_machine)
6206 {
6207 case EM_MIPS:
6208 case EM_MIPS_RS3_LE:
6209 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6210 FDE addresses. However, the ABI also has a semi-official ILP32
6211 variant for which the normal FDE address size rules apply.
6212
6213 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6214 section, where XX is the size of longs in bits. Unfortunately,
6215 earlier compilers provided no way of distinguishing ILP32 objects
6216 from LP64 objects, so if there's any doubt, we should assume that
6217 the official LP64 form is being used. */
6218 if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
6219 && find_section (filedata, ".gcc_compiled_long32") == NULL)
6220 eh_addr_size = 8;
6221 break;
6222
6223 case EM_H8_300:
6224 case EM_H8_300H:
6225 switch (filedata->file_header.e_flags & EF_H8_MACH)
6226 {
6227 case E_H8_MACH_H8300:
6228 case E_H8_MACH_H8300HN:
6229 case E_H8_MACH_H8300SN:
6230 case E_H8_MACH_H8300SXN:
6231 eh_addr_size = 2;
6232 break;
6233 case E_H8_MACH_H8300H:
6234 case E_H8_MACH_H8300S:
6235 case E_H8_MACH_H8300SX:
6236 eh_addr_size = 4;
6237 break;
6238 }
6239 break;
6240
6241 case EM_M32C_OLD:
6242 case EM_M32C:
6243 switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK)
6244 {
6245 case EF_M32C_CPU_M16C:
6246 eh_addr_size = 2;
6247 break;
6248 }
6249 break;
6250 }
6251
6252 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6253 do \
6254 { \
6255 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6256 if (section->sh_entsize != expected_entsize) \
6257 { \
6258 char buf[40]; \
6259 sprintf_vma (buf, section->sh_entsize); \
6260 /* Note: coded this way so that there is a single string for \
6261 translation. */ \
6262 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6263 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6264 (unsigned) expected_entsize); \
6265 section->sh_entsize = expected_entsize; \
6266 } \
6267 } \
6268 while (0)
6269
6270 #define CHECK_ENTSIZE(section, i, type) \
6271 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6272 sizeof (Elf64_External_##type))
6273
6274 for (i = 0, section = filedata->section_headers;
6275 i < filedata->file_header.e_shnum;
6276 i++, section++)
6277 {
6278 char * name = SECTION_NAME (section);
6279
6280 if (section->sh_type == SHT_DYNSYM)
6281 {
6282 if (dynamic_symbols != NULL)
6283 {
6284 error (_("File contains multiple dynamic symbol tables\n"));
6285 continue;
6286 }
6287
6288 CHECK_ENTSIZE (section, i, Sym);
6289 dynamic_symbols = GET_ELF_SYMBOLS (filedata, section, & num_dynamic_syms);
6290 }
6291 else if (section->sh_type == SHT_STRTAB
6292 && streq (name, ".dynstr"))
6293 {
6294 if (dynamic_strings != NULL)
6295 {
6296 error (_("File contains multiple dynamic string tables\n"));
6297 continue;
6298 }
6299
6300 dynamic_strings = (char *) get_data (NULL, filedata, section->sh_offset,
6301 1, section->sh_size,
6302 _("dynamic strings"));
6303 dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
6304 }
6305 else if (section->sh_type == SHT_SYMTAB_SHNDX)
6306 {
6307 elf_section_list * entry = xmalloc (sizeof * entry);
6308
6309 entry->hdr = section;
6310 entry->next = symtab_shndx_list;
6311 symtab_shndx_list = entry;
6312 }
6313 else if (section->sh_type == SHT_SYMTAB)
6314 CHECK_ENTSIZE (section, i, Sym);
6315 else if (section->sh_type == SHT_GROUP)
6316 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
6317 else if (section->sh_type == SHT_REL)
6318 CHECK_ENTSIZE (section, i, Rel);
6319 else if (section->sh_type == SHT_RELA)
6320 CHECK_ENTSIZE (section, i, Rela);
6321 else if ((do_debugging || do_debug_info || do_debug_abbrevs
6322 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
6323 || do_debug_aranges || do_debug_frames || do_debug_macinfo
6324 || do_debug_str || do_debug_loc || do_debug_ranges
6325 || do_debug_addr || do_debug_cu_index || do_debug_links)
6326 && (const_strneq (name, ".debug_")
6327 || const_strneq (name, ".zdebug_")))
6328 {
6329 if (name[1] == 'z')
6330 name += sizeof (".zdebug_") - 1;
6331 else
6332 name += sizeof (".debug_") - 1;
6333
6334 if (do_debugging
6335 || (do_debug_info && const_strneq (name, "info"))
6336 || (do_debug_info && const_strneq (name, "types"))
6337 || (do_debug_abbrevs && const_strneq (name, "abbrev"))
6338 || (do_debug_lines && strcmp (name, "line") == 0)
6339 || (do_debug_lines && const_strneq (name, "line."))
6340 || (do_debug_pubnames && const_strneq (name, "pubnames"))
6341 || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
6342 || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
6343 || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
6344 || (do_debug_aranges && const_strneq (name, "aranges"))
6345 || (do_debug_ranges && const_strneq (name, "ranges"))
6346 || (do_debug_ranges && const_strneq (name, "rnglists"))
6347 || (do_debug_frames && const_strneq (name, "frame"))
6348 || (do_debug_macinfo && const_strneq (name, "macinfo"))
6349 || (do_debug_macinfo && const_strneq (name, "macro"))
6350 || (do_debug_str && const_strneq (name, "str"))
6351 || (do_debug_loc && const_strneq (name, "loc"))
6352 || (do_debug_loc && const_strneq (name, "loclists"))
6353 || (do_debug_addr && const_strneq (name, "addr"))
6354 || (do_debug_cu_index && const_strneq (name, "cu_index"))
6355 || (do_debug_cu_index && const_strneq (name, "tu_index"))
6356 )
6357 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6358 }
6359 /* Linkonce section to be combined with .debug_info at link time. */
6360 else if ((do_debugging || do_debug_info)
6361 && const_strneq (name, ".gnu.linkonce.wi."))
6362 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6363 else if (do_debug_frames && streq (name, ".eh_frame"))
6364 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6365 else if (do_gdb_index && (streq (name, ".gdb_index")
6366 || streq (name, ".debug_names")))
6367 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6368 /* Trace sections for Itanium VMS. */
6369 else if ((do_debugging || do_trace_info || do_trace_abbrevs
6370 || do_trace_aranges)
6371 && const_strneq (name, ".trace_"))
6372 {
6373 name += sizeof (".trace_") - 1;
6374
6375 if (do_debugging
6376 || (do_trace_info && streq (name, "info"))
6377 || (do_trace_abbrevs && streq (name, "abbrev"))
6378 || (do_trace_aranges && streq (name, "aranges"))
6379 )
6380 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6381 }
6382 else if ((do_debugging || do_debug_links)
6383 && (const_strneq (name, ".gnu_debuglink")
6384 || const_strneq (name, ".gnu_debugaltlink")))
6385 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6386 }
6387
6388 if (! do_sections)
6389 return TRUE;
6390
6391 if (filedata->file_header.e_shnum > 1)
6392 printf (_("\nSection Headers:\n"));
6393 else
6394 printf (_("\nSection Header:\n"));
6395
6396 if (is_32bit_elf)
6397 {
6398 if (do_section_details)
6399 {
6400 printf (_(" [Nr] Name\n"));
6401 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
6402 }
6403 else
6404 printf
6405 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6406 }
6407 else if (do_wide)
6408 {
6409 if (do_section_details)
6410 {
6411 printf (_(" [Nr] Name\n"));
6412 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
6413 }
6414 else
6415 printf
6416 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6417 }
6418 else
6419 {
6420 if (do_section_details)
6421 {
6422 printf (_(" [Nr] Name\n"));
6423 printf (_(" Type Address Offset Link\n"));
6424 printf (_(" Size EntSize Info Align\n"));
6425 }
6426 else
6427 {
6428 printf (_(" [Nr] Name Type Address Offset\n"));
6429 printf (_(" Size EntSize Flags Link Info Align\n"));
6430 }
6431 }
6432
6433 if (do_section_details)
6434 printf (_(" Flags\n"));
6435
6436 for (i = 0, section = filedata->section_headers;
6437 i < filedata->file_header.e_shnum;
6438 i++, section++)
6439 {
6440 /* Run some sanity checks on the section header. */
6441
6442 /* Check the sh_link field. */
6443 switch (section->sh_type)
6444 {
6445 case SHT_REL:
6446 case SHT_RELA:
6447 if (section->sh_link == 0
6448 && (filedata->file_header.e_type == ET_EXEC
6449 || filedata->file_header.e_type == ET_DYN))
6450 /* A dynamic relocation section where all entries use a
6451 zero symbol index need not specify a symtab section. */
6452 break;
6453 /* Fall through. */
6454 case SHT_SYMTAB_SHNDX:
6455 case SHT_GROUP:
6456 case SHT_HASH:
6457 case SHT_GNU_HASH:
6458 case SHT_GNU_versym:
6459 if (section->sh_link == 0
6460 || section->sh_link >= filedata->file_header.e_shnum
6461 || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB
6462 && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM))
6463 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6464 i, section->sh_link);
6465 break;
6466
6467 case SHT_DYNAMIC:
6468 case SHT_SYMTAB:
6469 case SHT_DYNSYM:
6470 case SHT_GNU_verneed:
6471 case SHT_GNU_verdef:
6472 case SHT_GNU_LIBLIST:
6473 if (section->sh_link == 0
6474 || section->sh_link >= filedata->file_header.e_shnum
6475 || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB)
6476 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6477 i, section->sh_link);
6478 break;
6479
6480 case SHT_INIT_ARRAY:
6481 case SHT_FINI_ARRAY:
6482 case SHT_PREINIT_ARRAY:
6483 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6484 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6485 i, section->sh_link);
6486 break;
6487
6488 default:
6489 /* FIXME: Add support for target specific section types. */
6490 #if 0 /* Currently we do not check other section types as there are too
6491 many special cases. Stab sections for example have a type
6492 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6493 section. */
6494 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6495 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6496 i, section->sh_link);
6497 #endif
6498 break;
6499 }
6500
6501 /* Check the sh_info field. */
6502 switch (section->sh_type)
6503 {
6504 case SHT_REL:
6505 case SHT_RELA:
6506 if (section->sh_info == 0
6507 && (filedata->file_header.e_type == ET_EXEC
6508 || filedata->file_header.e_type == ET_DYN))
6509 /* Dynamic relocations apply to segments, so they do not
6510 need to specify the section they relocate. */
6511 break;
6512 if (section->sh_info == 0
6513 || section->sh_info >= filedata->file_header.e_shnum
6514 || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS
6515 && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
6516 && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
6517 && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
6518 && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY
6519 && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY
6520 /* FIXME: Are other section types valid ? */
6521 && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
6522 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6523 i, section->sh_info);
6524 break;
6525
6526 case SHT_DYNAMIC:
6527 case SHT_HASH:
6528 case SHT_SYMTAB_SHNDX:
6529 case SHT_INIT_ARRAY:
6530 case SHT_FINI_ARRAY:
6531 case SHT_PREINIT_ARRAY:
6532 if (section->sh_info != 0)
6533 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6534 i, section->sh_info);
6535 break;
6536
6537 case SHT_GROUP:
6538 case SHT_SYMTAB:
6539 case SHT_DYNSYM:
6540 /* A symbol index - we assume that it is valid. */
6541 break;
6542
6543 default:
6544 /* FIXME: Add support for target specific section types. */
6545 if (section->sh_type == SHT_NOBITS)
6546 /* NOBITS section headers with non-zero sh_info fields can be
6547 created when a binary is stripped of everything but its debug
6548 information. The stripped sections have their headers
6549 preserved but their types set to SHT_NOBITS. So do not check
6550 this type of section. */
6551 ;
6552 else if (section->sh_flags & SHF_INFO_LINK)
6553 {
6554 if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum)
6555 warn (_("[%2u]: Expected link to another section in info field"), i);
6556 }
6557 else if (section->sh_type < SHT_LOOS
6558 && (section->sh_flags & SHF_GNU_MBIND) == 0
6559 && section->sh_info != 0)
6560 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6561 i, section->sh_info);
6562 break;
6563 }
6564
6565 /* Check the sh_size field. */
6566 if (section->sh_size > filedata->file_size
6567 && section->sh_type != SHT_NOBITS
6568 && section->sh_type != SHT_NULL
6569 && section->sh_type < SHT_LOOS)
6570 warn (_("Size of section %u is larger than the entire file!\n"), i);
6571
6572 printf (" [%2u] ", i);
6573 if (do_section_details)
6574 printf ("%s\n ", printable_section_name (filedata, section));
6575 else
6576 print_symbol (-17, SECTION_NAME (section));
6577
6578 printf (do_wide ? " %-15s " : " %-15.15s ",
6579 get_section_type_name (filedata, section->sh_type));
6580
6581 if (is_32bit_elf)
6582 {
6583 const char * link_too_big = NULL;
6584
6585 print_vma (section->sh_addr, LONG_HEX);
6586
6587 printf ( " %6.6lx %6.6lx %2.2lx",
6588 (unsigned long) section->sh_offset,
6589 (unsigned long) section->sh_size,
6590 (unsigned long) section->sh_entsize);
6591
6592 if (do_section_details)
6593 fputs (" ", stdout);
6594 else
6595 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
6596
6597 if (section->sh_link >= filedata->file_header.e_shnum)
6598 {
6599 link_too_big = "";
6600 /* The sh_link value is out of range. Normally this indicates
6601 an error but it can have special values in Solaris binaries. */
6602 switch (filedata->file_header.e_machine)
6603 {
6604 case EM_386:
6605 case EM_IAMCU:
6606 case EM_X86_64:
6607 case EM_L1OM:
6608 case EM_K1OM:
6609 case EM_OLD_SPARCV9:
6610 case EM_SPARC32PLUS:
6611 case EM_SPARCV9:
6612 case EM_SPARC:
6613 if (section->sh_link == (SHN_BEFORE & 0xffff))
6614 link_too_big = "BEFORE";
6615 else if (section->sh_link == (SHN_AFTER & 0xffff))
6616 link_too_big = "AFTER";
6617 break;
6618 default:
6619 break;
6620 }
6621 }
6622
6623 if (do_section_details)
6624 {
6625 if (link_too_big != NULL && * link_too_big)
6626 printf ("<%s> ", link_too_big);
6627 else
6628 printf ("%2u ", section->sh_link);
6629 printf ("%3u %2lu\n", section->sh_info,
6630 (unsigned long) section->sh_addralign);
6631 }
6632 else
6633 printf ("%2u %3u %2lu\n",
6634 section->sh_link,
6635 section->sh_info,
6636 (unsigned long) section->sh_addralign);
6637
6638 if (link_too_big && ! * link_too_big)
6639 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6640 i, section->sh_link);
6641 }
6642 else if (do_wide)
6643 {
6644 print_vma (section->sh_addr, LONG_HEX);
6645
6646 if ((long) section->sh_offset == section->sh_offset)
6647 printf (" %6.6lx", (unsigned long) section->sh_offset);
6648 else
6649 {
6650 putchar (' ');
6651 print_vma (section->sh_offset, LONG_HEX);
6652 }
6653
6654 if ((unsigned long) section->sh_size == section->sh_size)
6655 printf (" %6.6lx", (unsigned long) section->sh_size);
6656 else
6657 {
6658 putchar (' ');
6659 print_vma (section->sh_size, LONG_HEX);
6660 }
6661
6662 if ((unsigned long) section->sh_entsize == section->sh_entsize)
6663 printf (" %2.2lx", (unsigned long) section->sh_entsize);
6664 else
6665 {
6666 putchar (' ');
6667 print_vma (section->sh_entsize, LONG_HEX);
6668 }
6669
6670 if (do_section_details)
6671 fputs (" ", stdout);
6672 else
6673 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
6674
6675 printf ("%2u %3u ", section->sh_link, section->sh_info);
6676
6677 if ((unsigned long) section->sh_addralign == section->sh_addralign)
6678 printf ("%2lu\n", (unsigned long) section->sh_addralign);
6679 else
6680 {
6681 print_vma (section->sh_addralign, DEC);
6682 putchar ('\n');
6683 }
6684 }
6685 else if (do_section_details)
6686 {
6687 putchar (' ');
6688 print_vma (section->sh_addr, LONG_HEX);
6689 if ((long) section->sh_offset == section->sh_offset)
6690 printf (" %16.16lx", (unsigned long) section->sh_offset);
6691 else
6692 {
6693 printf (" ");
6694 print_vma (section->sh_offset, LONG_HEX);
6695 }
6696 printf (" %u\n ", section->sh_link);
6697 print_vma (section->sh_size, LONG_HEX);
6698 putchar (' ');
6699 print_vma (section->sh_entsize, LONG_HEX);
6700
6701 printf (" %-16u %lu\n",
6702 section->sh_info,
6703 (unsigned long) section->sh_addralign);
6704 }
6705 else
6706 {
6707 putchar (' ');
6708 print_vma (section->sh_addr, LONG_HEX);
6709 if ((long) section->sh_offset == section->sh_offset)
6710 printf (" %8.8lx", (unsigned long) section->sh_offset);
6711 else
6712 {
6713 printf (" ");
6714 print_vma (section->sh_offset, LONG_HEX);
6715 }
6716 printf ("\n ");
6717 print_vma (section->sh_size, LONG_HEX);
6718 printf (" ");
6719 print_vma (section->sh_entsize, LONG_HEX);
6720
6721 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
6722
6723 printf (" %2u %3u %lu\n",
6724 section->sh_link,
6725 section->sh_info,
6726 (unsigned long) section->sh_addralign);
6727 }
6728
6729 if (do_section_details)
6730 {
6731 printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags));
6732 if ((section->sh_flags & SHF_COMPRESSED) != 0)
6733 {
6734 /* Minimum section size is 12 bytes for 32-bit compression
6735 header + 12 bytes for compressed data header. */
6736 unsigned char buf[24];
6737
6738 assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
6739 if (get_data (&buf, filedata, section->sh_offset, 1,
6740 sizeof (buf), _("compression header")))
6741 {
6742 Elf_Internal_Chdr chdr;
6743
6744 (void) get_compression_header (&chdr, buf, sizeof (buf));
6745
6746 if (chdr.ch_type == ELFCOMPRESS_ZLIB)
6747 printf (" ZLIB, ");
6748 else
6749 printf (_(" [<unknown>: 0x%x], "),
6750 chdr.ch_type);
6751 print_vma (chdr.ch_size, LONG_HEX);
6752 printf (", %lu\n", (unsigned long) chdr.ch_addralign);
6753 }
6754 }
6755 }
6756 }
6757
6758 if (!do_section_details)
6759 {
6760 /* The ordering of the letters shown here matches the ordering of the
6761 corresponding SHF_xxx values, and hence the order in which these
6762 letters will be displayed to the user. */
6763 printf (_("Key to Flags:\n\
6764 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
6765 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
6766 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
6767 if (filedata->file_header.e_machine == EM_X86_64
6768 || filedata->file_header.e_machine == EM_L1OM
6769 || filedata->file_header.e_machine == EM_K1OM)
6770 printf (_("l (large), "));
6771 else if (filedata->file_header.e_machine == EM_ARM)
6772 printf (_("y (purecode), "));
6773 else if (filedata->file_header.e_machine == EM_PPC)
6774 printf (_("v (VLE), "));
6775 printf ("p (processor specific)\n");
6776 }
6777
6778 return TRUE;
6779 }
6780
6781 static const char *
6782 get_group_flags (unsigned int flags)
6783 {
6784 static char buff[128];
6785
6786 if (flags == 0)
6787 return "";
6788 else if (flags == GRP_COMDAT)
6789 return "COMDAT ";
6790
6791 snprintf (buff, 14, _("[0x%x: "), flags);
6792
6793 flags &= ~ GRP_COMDAT;
6794 if (flags & GRP_MASKOS)
6795 {
6796 strcat (buff, "<OS specific>");
6797 flags &= ~ GRP_MASKOS;
6798 }
6799
6800 if (flags & GRP_MASKPROC)
6801 {
6802 strcat (buff, "<PROC specific>");
6803 flags &= ~ GRP_MASKPROC;
6804 }
6805
6806 if (flags)
6807 strcat (buff, "<unknown>");
6808
6809 strcat (buff, "]");
6810 return buff;
6811 }
6812
6813 static bfd_boolean
6814 process_section_groups (Filedata * filedata)
6815 {
6816 Elf_Internal_Shdr * section;
6817 unsigned int i;
6818 struct group * group;
6819 Elf_Internal_Shdr * symtab_sec;
6820 Elf_Internal_Shdr * strtab_sec;
6821 Elf_Internal_Sym * symtab;
6822 unsigned long num_syms;
6823 char * strtab;
6824 size_t strtab_size;
6825
6826 /* Don't process section groups unless needed. */
6827 if (!do_unwind && !do_section_groups)
6828 return TRUE;
6829
6830 if (filedata->file_header.e_shnum == 0)
6831 {
6832 if (do_section_groups)
6833 printf (_("\nThere are no sections to group in this file.\n"));
6834
6835 return TRUE;
6836 }
6837
6838 if (filedata->section_headers == NULL)
6839 {
6840 error (_("Section headers are not available!\n"));
6841 /* PR 13622: This can happen with a corrupt ELF header. */
6842 return FALSE;
6843 }
6844
6845 section_headers_groups = (struct group **) calloc (filedata->file_header.e_shnum,
6846 sizeof (struct group *));
6847
6848 if (section_headers_groups == NULL)
6849 {
6850 error (_("Out of memory reading %u section group headers\n"),
6851 filedata->file_header.e_shnum);
6852 return FALSE;
6853 }
6854
6855 /* Scan the sections for the group section. */
6856 group_count = 0;
6857 for (i = 0, section = filedata->section_headers;
6858 i < filedata->file_header.e_shnum;
6859 i++, section++)
6860 if (section->sh_type == SHT_GROUP)
6861 group_count++;
6862
6863 if (group_count == 0)
6864 {
6865 if (do_section_groups)
6866 printf (_("\nThere are no section groups in this file.\n"));
6867
6868 return TRUE;
6869 }
6870
6871 section_groups = (struct group *) calloc (group_count, sizeof (struct group));
6872
6873 if (section_groups == NULL)
6874 {
6875 error (_("Out of memory reading %lu groups\n"),
6876 (unsigned long) group_count);
6877 return FALSE;
6878 }
6879
6880 symtab_sec = NULL;
6881 strtab_sec = NULL;
6882 symtab = NULL;
6883 num_syms = 0;
6884 strtab = NULL;
6885 strtab_size = 0;
6886 for (i = 0, section = filedata->section_headers, group = section_groups;
6887 i < filedata->file_header.e_shnum;
6888 i++, section++)
6889 {
6890 if (section->sh_type == SHT_GROUP)
6891 {
6892 const char * name = printable_section_name (filedata, section);
6893 const char * group_name;
6894 unsigned char * start;
6895 unsigned char * indices;
6896 unsigned int entry, j, size;
6897 Elf_Internal_Shdr * sec;
6898 Elf_Internal_Sym * sym;
6899
6900 /* Get the symbol table. */
6901 if (section->sh_link >= filedata->file_header.e_shnum
6902 || ((sec = filedata->section_headers + section->sh_link)->sh_type
6903 != SHT_SYMTAB))
6904 {
6905 error (_("Bad sh_link in group section `%s'\n"), name);
6906 continue;
6907 }
6908
6909 if (symtab_sec != sec)
6910 {
6911 symtab_sec = sec;
6912 if (symtab)
6913 free (symtab);
6914 symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms);
6915 }
6916
6917 if (symtab == NULL)
6918 {
6919 error (_("Corrupt header in group section `%s'\n"), name);
6920 continue;
6921 }
6922
6923 if (section->sh_info >= num_syms)
6924 {
6925 error (_("Bad sh_info in group section `%s'\n"), name);
6926 continue;
6927 }
6928
6929 sym = symtab + section->sh_info;
6930
6931 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6932 {
6933 if (sym->st_shndx == 0
6934 || sym->st_shndx >= filedata->file_header.e_shnum)
6935 {
6936 error (_("Bad sh_info in group section `%s'\n"), name);
6937 continue;
6938 }
6939
6940 group_name = SECTION_NAME (filedata->section_headers + sym->st_shndx);
6941 strtab_sec = NULL;
6942 if (strtab)
6943 free (strtab);
6944 strtab = NULL;
6945 strtab_size = 0;
6946 }
6947 else
6948 {
6949 /* Get the string table. */
6950 if (symtab_sec->sh_link >= filedata->file_header.e_shnum)
6951 {
6952 strtab_sec = NULL;
6953 if (strtab)
6954 free (strtab);
6955 strtab = NULL;
6956 strtab_size = 0;
6957 }
6958 else if (strtab_sec
6959 != (sec = filedata->section_headers + symtab_sec->sh_link))
6960 {
6961 strtab_sec = sec;
6962 if (strtab)
6963 free (strtab);
6964
6965 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
6966 1, strtab_sec->sh_size,
6967 _("string table"));
6968 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
6969 }
6970 group_name = sym->st_name < strtab_size
6971 ? strtab + sym->st_name : _("<corrupt>");
6972 }
6973
6974 /* PR 17531: file: loop. */
6975 if (section->sh_entsize > section->sh_size)
6976 {
6977 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
6978 printable_section_name (filedata, section),
6979 (unsigned long) section->sh_entsize,
6980 (unsigned long) section->sh_size);
6981 continue;
6982 }
6983
6984 start = (unsigned char *) get_data (NULL, filedata, section->sh_offset,
6985 1, section->sh_size,
6986 _("section data"));
6987 if (start == NULL)
6988 continue;
6989
6990 indices = start;
6991 size = (section->sh_size / section->sh_entsize) - 1;
6992 entry = byte_get (indices, 4);
6993 indices += 4;
6994
6995 if (do_section_groups)
6996 {
6997 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
6998 get_group_flags (entry), i, name, group_name, size);
6999
7000 printf (_(" [Index] Name\n"));
7001 }
7002
7003 group->group_index = i;
7004
7005 for (j = 0; j < size; j++)
7006 {
7007 struct group_list * g;
7008
7009 entry = byte_get (indices, 4);
7010 indices += 4;
7011
7012 if (entry >= filedata->file_header.e_shnum)
7013 {
7014 static unsigned num_group_errors = 0;
7015
7016 if (num_group_errors ++ < 10)
7017 {
7018 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
7019 entry, i, filedata->file_header.e_shnum - 1);
7020 if (num_group_errors == 10)
7021 warn (_("Further error messages about overlarge group section indices suppressed\n"));
7022 }
7023 continue;
7024 }
7025
7026 if (section_headers_groups [entry] != NULL)
7027 {
7028 if (entry)
7029 {
7030 static unsigned num_errs = 0;
7031
7032 if (num_errs ++ < 10)
7033 {
7034 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7035 entry, i,
7036 section_headers_groups [entry]->group_index);
7037 if (num_errs == 10)
7038 warn (_("Further error messages about already contained group sections suppressed\n"));
7039 }
7040 continue;
7041 }
7042 else
7043 {
7044 /* Intel C/C++ compiler may put section 0 in a
7045 section group. We just warn it the first time
7046 and ignore it afterwards. */
7047 static bfd_boolean warned = FALSE;
7048 if (!warned)
7049 {
7050 error (_("section 0 in group section [%5u]\n"),
7051 section_headers_groups [entry]->group_index);
7052 warned = TRUE;
7053 }
7054 }
7055 }
7056
7057 section_headers_groups [entry] = group;
7058
7059 if (do_section_groups)
7060 {
7061 sec = filedata->section_headers + entry;
7062 printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec));
7063 }
7064
7065 g = (struct group_list *) xmalloc (sizeof (struct group_list));
7066 g->section_index = entry;
7067 g->next = group->root;
7068 group->root = g;
7069 }
7070
7071 if (start)
7072 free (start);
7073
7074 group++;
7075 }
7076 }
7077
7078 if (symtab)
7079 free (symtab);
7080 if (strtab)
7081 free (strtab);
7082 return TRUE;
7083 }
7084
7085 /* Data used to display dynamic fixups. */
7086
7087 struct ia64_vms_dynfixup
7088 {
7089 bfd_vma needed_ident; /* Library ident number. */
7090 bfd_vma needed; /* Index in the dstrtab of the library name. */
7091 bfd_vma fixup_needed; /* Index of the library. */
7092 bfd_vma fixup_rela_cnt; /* Number of fixups. */
7093 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
7094 };
7095
7096 /* Data used to display dynamic relocations. */
7097
7098 struct ia64_vms_dynimgrela
7099 {
7100 bfd_vma img_rela_cnt; /* Number of relocations. */
7101 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
7102 };
7103
7104 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7105 library). */
7106
7107 static bfd_boolean
7108 dump_ia64_vms_dynamic_fixups (Filedata * filedata,
7109 struct ia64_vms_dynfixup * fixup,
7110 const char * strtab,
7111 unsigned int strtab_sz)
7112 {
7113 Elf64_External_VMS_IMAGE_FIXUP * imfs;
7114 long i;
7115 const char * lib_name;
7116
7117 imfs = get_data (NULL, filedata, dynamic_addr + fixup->fixup_rela_off,
7118 1, fixup->fixup_rela_cnt * sizeof (*imfs),
7119 _("dynamic section image fixups"));
7120 if (!imfs)
7121 return FALSE;
7122
7123 if (fixup->needed < strtab_sz)
7124 lib_name = strtab + fixup->needed;
7125 else
7126 {
7127 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7128 (unsigned long) fixup->needed);
7129 lib_name = "???";
7130 }
7131 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7132 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
7133 printf
7134 (_("Seg Offset Type SymVec DataType\n"));
7135
7136 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
7137 {
7138 unsigned int type;
7139 const char *rtype;
7140
7141 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
7142 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
7143 type = BYTE_GET (imfs [i].type);
7144 rtype = elf_ia64_reloc_type (type);
7145 if (rtype == NULL)
7146 printf (" 0x%08x ", type);
7147 else
7148 printf (" %-32s ", rtype);
7149 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
7150 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
7151 }
7152
7153 free (imfs);
7154 return TRUE;
7155 }
7156
7157 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7158
7159 static bfd_boolean
7160 dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela)
7161 {
7162 Elf64_External_VMS_IMAGE_RELA *imrs;
7163 long i;
7164
7165 imrs = get_data (NULL, filedata, dynamic_addr + imgrela->img_rela_off,
7166 1, imgrela->img_rela_cnt * sizeof (*imrs),
7167 _("dynamic section image relocations"));
7168 if (!imrs)
7169 return FALSE;
7170
7171 printf (_("\nImage relocs\n"));
7172 printf
7173 (_("Seg Offset Type Addend Seg Sym Off\n"));
7174
7175 for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
7176 {
7177 unsigned int type;
7178 const char *rtype;
7179
7180 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
7181 printf ("%08" BFD_VMA_FMT "x ",
7182 (bfd_vma) BYTE_GET (imrs [i].rela_offset));
7183 type = BYTE_GET (imrs [i].type);
7184 rtype = elf_ia64_reloc_type (type);
7185 if (rtype == NULL)
7186 printf ("0x%08x ", type);
7187 else
7188 printf ("%-31s ", rtype);
7189 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
7190 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
7191 printf ("%08" BFD_VMA_FMT "x\n",
7192 (bfd_vma) BYTE_GET (imrs [i].sym_offset));
7193 }
7194
7195 free (imrs);
7196 return TRUE;
7197 }
7198
7199 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
7200
7201 static bfd_boolean
7202 process_ia64_vms_dynamic_relocs (Filedata * filedata)
7203 {
7204 struct ia64_vms_dynfixup fixup;
7205 struct ia64_vms_dynimgrela imgrela;
7206 Elf_Internal_Dyn *entry;
7207 bfd_vma strtab_off = 0;
7208 bfd_vma strtab_sz = 0;
7209 char *strtab = NULL;
7210 bfd_boolean res = TRUE;
7211
7212 memset (&fixup, 0, sizeof (fixup));
7213 memset (&imgrela, 0, sizeof (imgrela));
7214
7215 /* Note: the order of the entries is specified by the OpenVMS specs. */
7216 for (entry = dynamic_section;
7217 entry < dynamic_section + dynamic_nent;
7218 entry++)
7219 {
7220 switch (entry->d_tag)
7221 {
7222 case DT_IA_64_VMS_STRTAB_OFFSET:
7223 strtab_off = entry->d_un.d_val;
7224 break;
7225 case DT_STRSZ:
7226 strtab_sz = entry->d_un.d_val;
7227 if (strtab == NULL)
7228 strtab = get_data (NULL, filedata, dynamic_addr + strtab_off,
7229 1, strtab_sz, _("dynamic string section"));
7230 break;
7231
7232 case DT_IA_64_VMS_NEEDED_IDENT:
7233 fixup.needed_ident = entry->d_un.d_val;
7234 break;
7235 case DT_NEEDED:
7236 fixup.needed = entry->d_un.d_val;
7237 break;
7238 case DT_IA_64_VMS_FIXUP_NEEDED:
7239 fixup.fixup_needed = entry->d_un.d_val;
7240 break;
7241 case DT_IA_64_VMS_FIXUP_RELA_CNT:
7242 fixup.fixup_rela_cnt = entry->d_un.d_val;
7243 break;
7244 case DT_IA_64_VMS_FIXUP_RELA_OFF:
7245 fixup.fixup_rela_off = entry->d_un.d_val;
7246 if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz))
7247 res = FALSE;
7248 break;
7249 case DT_IA_64_VMS_IMG_RELA_CNT:
7250 imgrela.img_rela_cnt = entry->d_un.d_val;
7251 break;
7252 case DT_IA_64_VMS_IMG_RELA_OFF:
7253 imgrela.img_rela_off = entry->d_un.d_val;
7254 if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela))
7255 res = FALSE;
7256 break;
7257
7258 default:
7259 break;
7260 }
7261 }
7262
7263 if (strtab != NULL)
7264 free (strtab);
7265
7266 return res;
7267 }
7268
7269 static struct
7270 {
7271 const char * name;
7272 int reloc;
7273 int size;
7274 int rela;
7275 }
7276 dynamic_relocations [] =
7277 {
7278 { "REL", DT_REL, DT_RELSZ, FALSE },
7279 { "RELA", DT_RELA, DT_RELASZ, TRUE },
7280 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
7281 };
7282
7283 /* Process the reloc section. */
7284
7285 static bfd_boolean
7286 process_relocs (Filedata * filedata)
7287 {
7288 unsigned long rel_size;
7289 unsigned long rel_offset;
7290
7291 if (!do_reloc)
7292 return TRUE;
7293
7294 if (do_using_dynamic)
7295 {
7296 int is_rela;
7297 const char * name;
7298 bfd_boolean has_dynamic_reloc;
7299 unsigned int i;
7300
7301 has_dynamic_reloc = FALSE;
7302
7303 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
7304 {
7305 is_rela = dynamic_relocations [i].rela;
7306 name = dynamic_relocations [i].name;
7307 rel_size = dynamic_info [dynamic_relocations [i].size];
7308 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
7309
7310 if (rel_size)
7311 has_dynamic_reloc = TRUE;
7312
7313 if (is_rela == UNKNOWN)
7314 {
7315 if (dynamic_relocations [i].reloc == DT_JMPREL)
7316 switch (dynamic_info[DT_PLTREL])
7317 {
7318 case DT_REL:
7319 is_rela = FALSE;
7320 break;
7321 case DT_RELA:
7322 is_rela = TRUE;
7323 break;
7324 }
7325 }
7326
7327 if (rel_size)
7328 {
7329 printf
7330 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7331 name, rel_offset, rel_size);
7332
7333 dump_relocations (filedata,
7334 offset_from_vma (filedata, rel_offset, rel_size),
7335 rel_size,
7336 dynamic_symbols, num_dynamic_syms,
7337 dynamic_strings, dynamic_strings_length,
7338 is_rela, TRUE /* is_dynamic */);
7339 }
7340 }
7341
7342 if (is_ia64_vms (filedata))
7343 if (process_ia64_vms_dynamic_relocs (filedata))
7344 has_dynamic_reloc = TRUE;
7345
7346 if (! has_dynamic_reloc)
7347 printf (_("\nThere are no dynamic relocations in this file.\n"));
7348 }
7349 else
7350 {
7351 Elf_Internal_Shdr * section;
7352 unsigned long i;
7353 bfd_boolean found = FALSE;
7354
7355 for (i = 0, section = filedata->section_headers;
7356 i < filedata->file_header.e_shnum;
7357 i++, section++)
7358 {
7359 if ( section->sh_type != SHT_RELA
7360 && section->sh_type != SHT_REL)
7361 continue;
7362
7363 rel_offset = section->sh_offset;
7364 rel_size = section->sh_size;
7365
7366 if (rel_size)
7367 {
7368 Elf_Internal_Shdr * strsec;
7369 int is_rela;
7370 unsigned long num_rela;
7371
7372 printf (_("\nRelocation section "));
7373
7374 if (filedata->string_table == NULL)
7375 printf ("%d", section->sh_name);
7376 else
7377 printf ("'%s'", printable_section_name (filedata, section));
7378
7379 num_rela = rel_size / section->sh_entsize;
7380 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7381 " at offset 0x%lx contains %lu entries:\n",
7382 num_rela),
7383 rel_offset, num_rela);
7384
7385 is_rela = section->sh_type == SHT_RELA;
7386
7387 if (section->sh_link != 0
7388 && section->sh_link < filedata->file_header.e_shnum)
7389 {
7390 Elf_Internal_Shdr * symsec;
7391 Elf_Internal_Sym * symtab;
7392 unsigned long nsyms;
7393 unsigned long strtablen = 0;
7394 char * strtab = NULL;
7395
7396 symsec = filedata->section_headers + section->sh_link;
7397 if (symsec->sh_type != SHT_SYMTAB
7398 && symsec->sh_type != SHT_DYNSYM)
7399 continue;
7400
7401 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
7402
7403 if (symtab == NULL)
7404 continue;
7405
7406 if (symsec->sh_link != 0
7407 && symsec->sh_link < filedata->file_header.e_shnum)
7408 {
7409 strsec = filedata->section_headers + symsec->sh_link;
7410
7411 strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
7412 1, strsec->sh_size,
7413 _("string table"));
7414 strtablen = strtab == NULL ? 0 : strsec->sh_size;
7415 }
7416
7417 dump_relocations (filedata, rel_offset, rel_size,
7418 symtab, nsyms, strtab, strtablen,
7419 is_rela,
7420 symsec->sh_type == SHT_DYNSYM);
7421 if (strtab)
7422 free (strtab);
7423 free (symtab);
7424 }
7425 else
7426 dump_relocations (filedata, rel_offset, rel_size,
7427 NULL, 0, NULL, 0, is_rela,
7428 FALSE /* is_dynamic */);
7429
7430 found = TRUE;
7431 }
7432 }
7433
7434 if (! found)
7435 {
7436 /* Users sometimes forget the -D option, so try to be helpful. */
7437 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
7438 {
7439 if (dynamic_info [dynamic_relocations [i].size])
7440 {
7441 printf (_("\nThere are no static relocations in this file."));
7442 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7443
7444 break;
7445 }
7446 }
7447 if (i == ARRAY_SIZE (dynamic_relocations))
7448 printf (_("\nThere are no relocations in this file.\n"));
7449 }
7450 }
7451
7452 return TRUE;
7453 }
7454
7455 /* An absolute address consists of a section and an offset. If the
7456 section is NULL, the offset itself is the address, otherwise, the
7457 address equals to LOAD_ADDRESS(section) + offset. */
7458
7459 struct absaddr
7460 {
7461 unsigned short section;
7462 bfd_vma offset;
7463 };
7464
7465 /* Find the nearest symbol at or below ADDR. Returns the symbol
7466 name, if found, and the offset from the symbol to ADDR. */
7467
7468 static void
7469 find_symbol_for_address (Filedata * filedata,
7470 Elf_Internal_Sym * symtab,
7471 unsigned long nsyms,
7472 const char * strtab,
7473 unsigned long strtab_size,
7474 struct absaddr addr,
7475 const char ** symname,
7476 bfd_vma * offset)
7477 {
7478 bfd_vma dist = 0x100000;
7479 Elf_Internal_Sym * sym;
7480 Elf_Internal_Sym * beg;
7481 Elf_Internal_Sym * end;
7482 Elf_Internal_Sym * best = NULL;
7483
7484 REMOVE_ARCH_BITS (addr.offset);
7485 beg = symtab;
7486 end = symtab + nsyms;
7487
7488 while (beg < end)
7489 {
7490 bfd_vma value;
7491
7492 sym = beg + (end - beg) / 2;
7493
7494 value = sym->st_value;
7495 REMOVE_ARCH_BITS (value);
7496
7497 if (sym->st_name != 0
7498 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
7499 && addr.offset >= value
7500 && addr.offset - value < dist)
7501 {
7502 best = sym;
7503 dist = addr.offset - value;
7504 if (!dist)
7505 break;
7506 }
7507
7508 if (addr.offset < value)
7509 end = sym;
7510 else
7511 beg = sym + 1;
7512 }
7513
7514 if (best)
7515 {
7516 *symname = (best->st_name >= strtab_size
7517 ? _("<corrupt>") : strtab + best->st_name);
7518 *offset = dist;
7519 return;
7520 }
7521
7522 *symname = NULL;
7523 *offset = addr.offset;
7524 }
7525
7526 static /* signed */ int
7527 symcmp (const void *p, const void *q)
7528 {
7529 Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
7530 Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
7531
7532 return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
7533 }
7534
7535 /* Process the unwind section. */
7536
7537 #include "unwind-ia64.h"
7538
7539 struct ia64_unw_table_entry
7540 {
7541 struct absaddr start;
7542 struct absaddr end;
7543 struct absaddr info;
7544 };
7545
7546 struct ia64_unw_aux_info
7547 {
7548 struct ia64_unw_table_entry * table; /* Unwind table. */
7549 unsigned long table_len; /* Length of unwind table. */
7550 unsigned char * info; /* Unwind info. */
7551 unsigned long info_size; /* Size of unwind info. */
7552 bfd_vma info_addr; /* Starting address of unwind info. */
7553 bfd_vma seg_base; /* Starting address of segment. */
7554 Elf_Internal_Sym * symtab; /* The symbol table. */
7555 unsigned long nsyms; /* Number of symbols. */
7556 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
7557 unsigned long nfuns; /* Number of entries in funtab. */
7558 char * strtab; /* The string table. */
7559 unsigned long strtab_size; /* Size of string table. */
7560 };
7561
7562 static bfd_boolean
7563 dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux)
7564 {
7565 struct ia64_unw_table_entry * tp;
7566 unsigned long j, nfuns;
7567 int in_body;
7568 bfd_boolean res = TRUE;
7569
7570 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
7571 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
7572 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
7573 aux->funtab[nfuns++] = aux->symtab[j];
7574 aux->nfuns = nfuns;
7575 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
7576
7577 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
7578 {
7579 bfd_vma stamp;
7580 bfd_vma offset;
7581 const unsigned char * dp;
7582 const unsigned char * head;
7583 const unsigned char * end;
7584 const char * procname;
7585
7586 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
7587 aux->strtab_size, tp->start, &procname, &offset);
7588
7589 fputs ("\n<", stdout);
7590
7591 if (procname)
7592 {
7593 fputs (procname, stdout);
7594
7595 if (offset)
7596 printf ("+%lx", (unsigned long) offset);
7597 }
7598
7599 fputs (">: [", stdout);
7600 print_vma (tp->start.offset, PREFIX_HEX);
7601 fputc ('-', stdout);
7602 print_vma (tp->end.offset, PREFIX_HEX);
7603 printf ("], info at +0x%lx\n",
7604 (unsigned long) (tp->info.offset - aux->seg_base));
7605
7606 /* PR 17531: file: 86232b32. */
7607 if (aux->info == NULL)
7608 continue;
7609
7610 offset = tp->info.offset;
7611 if (tp->info.section)
7612 {
7613 if (tp->info.section >= filedata->file_header.e_shnum)
7614 {
7615 warn (_("Invalid section %u in table entry %ld\n"),
7616 tp->info.section, (long) (tp - aux->table));
7617 res = FALSE;
7618 continue;
7619 }
7620 offset += filedata->section_headers[tp->info.section].sh_addr;
7621 }
7622 offset -= aux->info_addr;
7623 /* PR 17531: file: 0997b4d1. */
7624 if (offset >= aux->info_size
7625 || aux->info_size - offset < 8)
7626 {
7627 warn (_("Invalid offset %lx in table entry %ld\n"),
7628 (long) tp->info.offset, (long) (tp - aux->table));
7629 res = FALSE;
7630 continue;
7631 }
7632
7633 head = aux->info + offset;
7634 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
7635
7636 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
7637 (unsigned) UNW_VER (stamp),
7638 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
7639 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
7640 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
7641 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
7642
7643 if (UNW_VER (stamp) != 1)
7644 {
7645 printf (_("\tUnknown version.\n"));
7646 continue;
7647 }
7648
7649 in_body = 0;
7650 end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
7651 /* PR 17531: file: 16ceda89. */
7652 if (end > aux->info + aux->info_size)
7653 end = aux->info + aux->info_size;
7654 for (dp = head + 8; dp < end;)
7655 dp = unw_decode (dp, in_body, & in_body, end);
7656 }
7657
7658 free (aux->funtab);
7659
7660 return res;
7661 }
7662
7663 static bfd_boolean
7664 slurp_ia64_unwind_table (Filedata * filedata,
7665 struct ia64_unw_aux_info * aux,
7666 Elf_Internal_Shdr * sec)
7667 {
7668 unsigned long size, nrelas, i;
7669 Elf_Internal_Phdr * seg;
7670 struct ia64_unw_table_entry * tep;
7671 Elf_Internal_Shdr * relsec;
7672 Elf_Internal_Rela * rela;
7673 Elf_Internal_Rela * rp;
7674 unsigned char * table;
7675 unsigned char * tp;
7676 Elf_Internal_Sym * sym;
7677 const char * relname;
7678
7679 aux->table_len = 0;
7680
7681 /* First, find the starting address of the segment that includes
7682 this section: */
7683
7684 if (filedata->file_header.e_phnum)
7685 {
7686 if (! get_program_headers (filedata))
7687 return FALSE;
7688
7689 for (seg = filedata->program_headers;
7690 seg < filedata->program_headers + filedata->file_header.e_phnum;
7691 ++seg)
7692 {
7693 if (seg->p_type != PT_LOAD)
7694 continue;
7695
7696 if (sec->sh_addr >= seg->p_vaddr
7697 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
7698 {
7699 aux->seg_base = seg->p_vaddr;
7700 break;
7701 }
7702 }
7703 }
7704
7705 /* Second, build the unwind table from the contents of the unwind section: */
7706 size = sec->sh_size;
7707 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
7708 _("unwind table"));
7709 if (!table)
7710 return FALSE;
7711
7712 aux->table_len = size / (3 * eh_addr_size);
7713 aux->table = (struct ia64_unw_table_entry *)
7714 xcmalloc (aux->table_len, sizeof (aux->table[0]));
7715 tep = aux->table;
7716
7717 for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
7718 {
7719 tep->start.section = SHN_UNDEF;
7720 tep->end.section = SHN_UNDEF;
7721 tep->info.section = SHN_UNDEF;
7722 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7723 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7724 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7725 tep->start.offset += aux->seg_base;
7726 tep->end.offset += aux->seg_base;
7727 tep->info.offset += aux->seg_base;
7728 }
7729 free (table);
7730
7731 /* Third, apply any relocations to the unwind table: */
7732 for (relsec = filedata->section_headers;
7733 relsec < filedata->section_headers + filedata->file_header.e_shnum;
7734 ++relsec)
7735 {
7736 if (relsec->sh_type != SHT_RELA
7737 || relsec->sh_info >= filedata->file_header.e_shnum
7738 || filedata->section_headers + relsec->sh_info != sec)
7739 continue;
7740
7741 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
7742 & rela, & nrelas))
7743 {
7744 free (aux->table);
7745 aux->table = NULL;
7746 aux->table_len = 0;
7747 return FALSE;
7748 }
7749
7750 for (rp = rela; rp < rela + nrelas; ++rp)
7751 {
7752 unsigned int sym_ndx;
7753 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
7754 relname = elf_ia64_reloc_type (r_type);
7755
7756 /* PR 17531: file: 9fa67536. */
7757 if (relname == NULL)
7758 {
7759 warn (_("Skipping unknown relocation type: %u\n"), r_type);
7760 continue;
7761 }
7762
7763 if (! const_strneq (relname, "R_IA64_SEGREL"))
7764 {
7765 warn (_("Skipping unexpected relocation type: %s\n"), relname);
7766 continue;
7767 }
7768
7769 i = rp->r_offset / (3 * eh_addr_size);
7770
7771 /* PR 17531: file: 5bc8d9bf. */
7772 if (i >= aux->table_len)
7773 {
7774 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
7775 continue;
7776 }
7777
7778 sym_ndx = get_reloc_symindex (rp->r_info);
7779 if (sym_ndx >= aux->nsyms)
7780 {
7781 warn (_("Skipping reloc with invalid symbol index: %u\n"),
7782 sym_ndx);
7783 continue;
7784 }
7785 sym = aux->symtab + sym_ndx;
7786
7787 switch (rp->r_offset / eh_addr_size % 3)
7788 {
7789 case 0:
7790 aux->table[i].start.section = sym->st_shndx;
7791 aux->table[i].start.offset = rp->r_addend + sym->st_value;
7792 break;
7793 case 1:
7794 aux->table[i].end.section = sym->st_shndx;
7795 aux->table[i].end.offset = rp->r_addend + sym->st_value;
7796 break;
7797 case 2:
7798 aux->table[i].info.section = sym->st_shndx;
7799 aux->table[i].info.offset = rp->r_addend + sym->st_value;
7800 break;
7801 default:
7802 break;
7803 }
7804 }
7805
7806 free (rela);
7807 }
7808
7809 return TRUE;
7810 }
7811
7812 static bfd_boolean
7813 ia64_process_unwind (Filedata * filedata)
7814 {
7815 Elf_Internal_Shdr * sec;
7816 Elf_Internal_Shdr * unwsec = NULL;
7817 Elf_Internal_Shdr * strsec;
7818 unsigned long i, unwcount = 0, unwstart = 0;
7819 struct ia64_unw_aux_info aux;
7820 bfd_boolean res = TRUE;
7821
7822 memset (& aux, 0, sizeof (aux));
7823
7824 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
7825 {
7826 if (sec->sh_type == SHT_SYMTAB
7827 && sec->sh_link < filedata->file_header.e_shnum)
7828 {
7829 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
7830
7831 strsec = filedata->section_headers + sec->sh_link;
7832 if (aux.strtab != NULL)
7833 {
7834 error (_("Multiple auxillary string tables encountered\n"));
7835 free (aux.strtab);
7836 res = FALSE;
7837 }
7838 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
7839 1, strsec->sh_size,
7840 _("string table"));
7841 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
7842 }
7843 else if (sec->sh_type == SHT_IA_64_UNWIND)
7844 unwcount++;
7845 }
7846
7847 if (!unwcount)
7848 printf (_("\nThere are no unwind sections in this file.\n"));
7849
7850 while (unwcount-- > 0)
7851 {
7852 char * suffix;
7853 size_t len, len2;
7854
7855 for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL;
7856 i < filedata->file_header.e_shnum; ++i, ++sec)
7857 if (sec->sh_type == SHT_IA_64_UNWIND)
7858 {
7859 unwsec = sec;
7860 break;
7861 }
7862 /* We have already counted the number of SHT_IA64_UNWIND
7863 sections so the loop above should never fail. */
7864 assert (unwsec != NULL);
7865
7866 unwstart = i + 1;
7867 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
7868
7869 if ((unwsec->sh_flags & SHF_GROUP) != 0)
7870 {
7871 /* We need to find which section group it is in. */
7872 struct group_list * g;
7873
7874 if (section_headers_groups == NULL
7875 || section_headers_groups [i] == NULL)
7876 i = filedata->file_header.e_shnum;
7877 else
7878 {
7879 g = section_headers_groups [i]->root;
7880
7881 for (; g != NULL; g = g->next)
7882 {
7883 sec = filedata->section_headers + g->section_index;
7884
7885 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
7886 break;
7887 }
7888
7889 if (g == NULL)
7890 i = filedata->file_header.e_shnum;
7891 }
7892 }
7893 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
7894 {
7895 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
7896 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
7897 suffix = SECTION_NAME (unwsec) + len;
7898 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
7899 ++i, ++sec)
7900 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
7901 && streq (SECTION_NAME (sec) + len2, suffix))
7902 break;
7903 }
7904 else
7905 {
7906 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
7907 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
7908 len = sizeof (ELF_STRING_ia64_unwind) - 1;
7909 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
7910 suffix = "";
7911 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
7912 suffix = SECTION_NAME (unwsec) + len;
7913 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
7914 ++i, ++sec)
7915 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
7916 && streq (SECTION_NAME (sec) + len2, suffix))
7917 break;
7918 }
7919
7920 if (i == filedata->file_header.e_shnum)
7921 {
7922 printf (_("\nCould not find unwind info section for "));
7923
7924 if (filedata->string_table == NULL)
7925 printf ("%d", unwsec->sh_name);
7926 else
7927 printf ("'%s'", printable_section_name (filedata, unwsec));
7928 }
7929 else
7930 {
7931 aux.info_addr = sec->sh_addr;
7932 aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1,
7933 sec->sh_size,
7934 _("unwind info"));
7935 aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
7936
7937 printf (_("\nUnwind section "));
7938
7939 if (filedata->string_table == NULL)
7940 printf ("%d", unwsec->sh_name);
7941 else
7942 printf ("'%s'", printable_section_name (filedata, unwsec));
7943
7944 printf (_(" at offset 0x%lx contains %lu entries:\n"),
7945 (unsigned long) unwsec->sh_offset,
7946 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
7947
7948 if (slurp_ia64_unwind_table (filedata, & aux, unwsec)
7949 && aux.table_len > 0)
7950 dump_ia64_unwind (filedata, & aux);
7951
7952 if (aux.table)
7953 free ((char *) aux.table);
7954 if (aux.info)
7955 free ((char *) aux.info);
7956 aux.table = NULL;
7957 aux.info = NULL;
7958 }
7959 }
7960
7961 if (aux.symtab)
7962 free (aux.symtab);
7963 if (aux.strtab)
7964 free ((char *) aux.strtab);
7965
7966 return res;
7967 }
7968
7969 struct hppa_unw_table_entry
7970 {
7971 struct absaddr start;
7972 struct absaddr end;
7973 unsigned int Cannot_unwind:1; /* 0 */
7974 unsigned int Millicode:1; /* 1 */
7975 unsigned int Millicode_save_sr0:1; /* 2 */
7976 unsigned int Region_description:2; /* 3..4 */
7977 unsigned int reserved1:1; /* 5 */
7978 unsigned int Entry_SR:1; /* 6 */
7979 unsigned int Entry_FR:4; /* Number saved 7..10 */
7980 unsigned int Entry_GR:5; /* Number saved 11..15 */
7981 unsigned int Args_stored:1; /* 16 */
7982 unsigned int Variable_Frame:1; /* 17 */
7983 unsigned int Separate_Package_Body:1; /* 18 */
7984 unsigned int Frame_Extension_Millicode:1; /* 19 */
7985 unsigned int Stack_Overflow_Check:1; /* 20 */
7986 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
7987 unsigned int Ada_Region:1; /* 22 */
7988 unsigned int cxx_info:1; /* 23 */
7989 unsigned int cxx_try_catch:1; /* 24 */
7990 unsigned int sched_entry_seq:1; /* 25 */
7991 unsigned int reserved2:1; /* 26 */
7992 unsigned int Save_SP:1; /* 27 */
7993 unsigned int Save_RP:1; /* 28 */
7994 unsigned int Save_MRP_in_frame:1; /* 29 */
7995 unsigned int extn_ptr_defined:1; /* 30 */
7996 unsigned int Cleanup_defined:1; /* 31 */
7997
7998 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
7999 unsigned int HP_UX_interrupt_marker:1; /* 1 */
8000 unsigned int Large_frame:1; /* 2 */
8001 unsigned int Pseudo_SP_Set:1; /* 3 */
8002 unsigned int reserved4:1; /* 4 */
8003 unsigned int Total_frame_size:27; /* 5..31 */
8004 };
8005
8006 struct hppa_unw_aux_info
8007 {
8008 struct hppa_unw_table_entry * table; /* Unwind table. */
8009 unsigned long table_len; /* Length of unwind table. */
8010 bfd_vma seg_base; /* Starting address of segment. */
8011 Elf_Internal_Sym * symtab; /* The symbol table. */
8012 unsigned long nsyms; /* Number of symbols. */
8013 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8014 unsigned long nfuns; /* Number of entries in funtab. */
8015 char * strtab; /* The string table. */
8016 unsigned long strtab_size; /* Size of string table. */
8017 };
8018
8019 static bfd_boolean
8020 dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux)
8021 {
8022 struct hppa_unw_table_entry * tp;
8023 unsigned long j, nfuns;
8024 bfd_boolean res = TRUE;
8025
8026 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
8027 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
8028 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
8029 aux->funtab[nfuns++] = aux->symtab[j];
8030 aux->nfuns = nfuns;
8031 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
8032
8033 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
8034 {
8035 bfd_vma offset;
8036 const char * procname;
8037
8038 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
8039 aux->strtab_size, tp->start, &procname,
8040 &offset);
8041
8042 fputs ("\n<", stdout);
8043
8044 if (procname)
8045 {
8046 fputs (procname, stdout);
8047
8048 if (offset)
8049 printf ("+%lx", (unsigned long) offset);
8050 }
8051
8052 fputs (">: [", stdout);
8053 print_vma (tp->start.offset, PREFIX_HEX);
8054 fputc ('-', stdout);
8055 print_vma (tp->end.offset, PREFIX_HEX);
8056 printf ("]\n\t");
8057
8058 #define PF(_m) if (tp->_m) printf (#_m " ");
8059 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
8060 PF(Cannot_unwind);
8061 PF(Millicode);
8062 PF(Millicode_save_sr0);
8063 /* PV(Region_description); */
8064 PF(Entry_SR);
8065 PV(Entry_FR);
8066 PV(Entry_GR);
8067 PF(Args_stored);
8068 PF(Variable_Frame);
8069 PF(Separate_Package_Body);
8070 PF(Frame_Extension_Millicode);
8071 PF(Stack_Overflow_Check);
8072 PF(Two_Instruction_SP_Increment);
8073 PF(Ada_Region);
8074 PF(cxx_info);
8075 PF(cxx_try_catch);
8076 PF(sched_entry_seq);
8077 PF(Save_SP);
8078 PF(Save_RP);
8079 PF(Save_MRP_in_frame);
8080 PF(extn_ptr_defined);
8081 PF(Cleanup_defined);
8082 PF(MPE_XL_interrupt_marker);
8083 PF(HP_UX_interrupt_marker);
8084 PF(Large_frame);
8085 PF(Pseudo_SP_Set);
8086 PV(Total_frame_size);
8087 #undef PF
8088 #undef PV
8089 }
8090
8091 printf ("\n");
8092
8093 free (aux->funtab);
8094
8095 return res;
8096 }
8097
8098 static bfd_boolean
8099 slurp_hppa_unwind_table (Filedata * filedata,
8100 struct hppa_unw_aux_info * aux,
8101 Elf_Internal_Shdr * sec)
8102 {
8103 unsigned long size, unw_ent_size, nentries, nrelas, i;
8104 Elf_Internal_Phdr * seg;
8105 struct hppa_unw_table_entry * tep;
8106 Elf_Internal_Shdr * relsec;
8107 Elf_Internal_Rela * rela;
8108 Elf_Internal_Rela * rp;
8109 unsigned char * table;
8110 unsigned char * tp;
8111 Elf_Internal_Sym * sym;
8112 const char * relname;
8113
8114 /* First, find the starting address of the segment that includes
8115 this section. */
8116 if (filedata->file_header.e_phnum)
8117 {
8118 if (! get_program_headers (filedata))
8119 return FALSE;
8120
8121 for (seg = filedata->program_headers;
8122 seg < filedata->program_headers + filedata->file_header.e_phnum;
8123 ++seg)
8124 {
8125 if (seg->p_type != PT_LOAD)
8126 continue;
8127
8128 if (sec->sh_addr >= seg->p_vaddr
8129 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
8130 {
8131 aux->seg_base = seg->p_vaddr;
8132 break;
8133 }
8134 }
8135 }
8136
8137 /* Second, build the unwind table from the contents of the unwind
8138 section. */
8139 size = sec->sh_size;
8140 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
8141 _("unwind table"));
8142 if (!table)
8143 return FALSE;
8144
8145 unw_ent_size = 16;
8146 nentries = size / unw_ent_size;
8147 size = unw_ent_size * nentries;
8148
8149 tep = aux->table = (struct hppa_unw_table_entry *)
8150 xcmalloc (nentries, sizeof (aux->table[0]));
8151
8152 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
8153 {
8154 unsigned int tmp1, tmp2;
8155
8156 tep->start.section = SHN_UNDEF;
8157 tep->end.section = SHN_UNDEF;
8158
8159 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
8160 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
8161 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
8162 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
8163
8164 tep->start.offset += aux->seg_base;
8165 tep->end.offset += aux->seg_base;
8166
8167 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
8168 tep->Millicode = (tmp1 >> 30) & 0x1;
8169 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
8170 tep->Region_description = (tmp1 >> 27) & 0x3;
8171 tep->reserved1 = (tmp1 >> 26) & 0x1;
8172 tep->Entry_SR = (tmp1 >> 25) & 0x1;
8173 tep->Entry_FR = (tmp1 >> 21) & 0xf;
8174 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
8175 tep->Args_stored = (tmp1 >> 15) & 0x1;
8176 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
8177 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
8178 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
8179 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
8180 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
8181 tep->Ada_Region = (tmp1 >> 9) & 0x1;
8182 tep->cxx_info = (tmp1 >> 8) & 0x1;
8183 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
8184 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
8185 tep->reserved2 = (tmp1 >> 5) & 0x1;
8186 tep->Save_SP = (tmp1 >> 4) & 0x1;
8187 tep->Save_RP = (tmp1 >> 3) & 0x1;
8188 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
8189 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
8190 tep->Cleanup_defined = tmp1 & 0x1;
8191
8192 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
8193 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
8194 tep->Large_frame = (tmp2 >> 29) & 0x1;
8195 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
8196 tep->reserved4 = (tmp2 >> 27) & 0x1;
8197 tep->Total_frame_size = tmp2 & 0x7ffffff;
8198 }
8199 free (table);
8200
8201 /* Third, apply any relocations to the unwind table. */
8202 for (relsec = filedata->section_headers;
8203 relsec < filedata->section_headers + filedata->file_header.e_shnum;
8204 ++relsec)
8205 {
8206 if (relsec->sh_type != SHT_RELA
8207 || relsec->sh_info >= filedata->file_header.e_shnum
8208 || filedata->section_headers + relsec->sh_info != sec)
8209 continue;
8210
8211 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
8212 & rela, & nrelas))
8213 return FALSE;
8214
8215 for (rp = rela; rp < rela + nrelas; ++rp)
8216 {
8217 unsigned int sym_ndx;
8218 unsigned int r_type = get_reloc_type (filedata, rp->r_info);
8219 relname = elf_hppa_reloc_type (r_type);
8220
8221 if (relname == NULL)
8222 {
8223 warn (_("Skipping unknown relocation type: %u\n"), r_type);
8224 continue;
8225 }
8226
8227 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
8228 if (! const_strneq (relname, "R_PARISC_SEGREL"))
8229 {
8230 warn (_("Skipping unexpected relocation type: %s\n"), relname);
8231 continue;
8232 }
8233
8234 i = rp->r_offset / unw_ent_size;
8235 if (i >= aux->table_len)
8236 {
8237 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
8238 continue;
8239 }
8240
8241 sym_ndx = get_reloc_symindex (rp->r_info);
8242 if (sym_ndx >= aux->nsyms)
8243 {
8244 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8245 sym_ndx);
8246 continue;
8247 }
8248 sym = aux->symtab + sym_ndx;
8249
8250 switch ((rp->r_offset % unw_ent_size) / 4)
8251 {
8252 case 0:
8253 aux->table[i].start.section = sym->st_shndx;
8254 aux->table[i].start.offset = sym->st_value + rp->r_addend;
8255 break;
8256 case 1:
8257 aux->table[i].end.section = sym->st_shndx;
8258 aux->table[i].end.offset = sym->st_value + rp->r_addend;
8259 break;
8260 default:
8261 break;
8262 }
8263 }
8264
8265 free (rela);
8266 }
8267
8268 aux->table_len = nentries;
8269
8270 return TRUE;
8271 }
8272
8273 static bfd_boolean
8274 hppa_process_unwind (Filedata * filedata)
8275 {
8276 struct hppa_unw_aux_info aux;
8277 Elf_Internal_Shdr * unwsec = NULL;
8278 Elf_Internal_Shdr * strsec;
8279 Elf_Internal_Shdr * sec;
8280 unsigned long i;
8281 bfd_boolean res = TRUE;
8282
8283 if (filedata->string_table == NULL)
8284 return FALSE;
8285
8286 memset (& aux, 0, sizeof (aux));
8287
8288 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
8289 {
8290 if (sec->sh_type == SHT_SYMTAB
8291 && sec->sh_link < filedata->file_header.e_shnum)
8292 {
8293 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
8294
8295 strsec = filedata->section_headers + sec->sh_link;
8296 if (aux.strtab != NULL)
8297 {
8298 error (_("Multiple auxillary string tables encountered\n"));
8299 free (aux.strtab);
8300 res = FALSE;
8301 }
8302 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
8303 1, strsec->sh_size,
8304 _("string table"));
8305 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
8306 }
8307 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
8308 unwsec = sec;
8309 }
8310
8311 if (!unwsec)
8312 printf (_("\nThere are no unwind sections in this file.\n"));
8313
8314 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
8315 {
8316 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
8317 {
8318 unsigned long num_unwind = sec->sh_size / 16;
8319
8320 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8321 "contains %lu entry:\n",
8322 "\nUnwind section '%s' at offset 0x%lx "
8323 "contains %lu entries:\n",
8324 num_unwind),
8325 printable_section_name (filedata, sec),
8326 (unsigned long) sec->sh_offset,
8327 num_unwind);
8328
8329 if (! slurp_hppa_unwind_table (filedata, &aux, sec))
8330 res = FALSE;
8331
8332 if (res && aux.table_len > 0)
8333 {
8334 if (! dump_hppa_unwind (filedata, &aux))
8335 res = FALSE;
8336 }
8337
8338 if (aux.table)
8339 free ((char *) aux.table);
8340 aux.table = NULL;
8341 }
8342 }
8343
8344 if (aux.symtab)
8345 free (aux.symtab);
8346 if (aux.strtab)
8347 free ((char *) aux.strtab);
8348
8349 return res;
8350 }
8351
8352 struct arm_section
8353 {
8354 unsigned char * data; /* The unwind data. */
8355 Elf_Internal_Shdr * sec; /* The cached unwind section header. */
8356 Elf_Internal_Rela * rela; /* The cached relocations for this section. */
8357 unsigned long nrelas; /* The number of relocations. */
8358 unsigned int rel_type; /* REL or RELA ? */
8359 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
8360 };
8361
8362 struct arm_unw_aux_info
8363 {
8364 Filedata * filedata; /* The file containing the unwind sections. */
8365 Elf_Internal_Sym * symtab; /* The file's symbol table. */
8366 unsigned long nsyms; /* Number of symbols. */
8367 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8368 unsigned long nfuns; /* Number of these symbols. */
8369 char * strtab; /* The file's string table. */
8370 unsigned long strtab_size; /* Size of string table. */
8371 };
8372
8373 static const char *
8374 arm_print_vma_and_name (Filedata * filedata,
8375 struct arm_unw_aux_info * aux,
8376 bfd_vma fn,
8377 struct absaddr addr)
8378 {
8379 const char *procname;
8380 bfd_vma sym_offset;
8381
8382 if (addr.section == SHN_UNDEF)
8383 addr.offset = fn;
8384
8385 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
8386 aux->strtab_size, addr, &procname,
8387 &sym_offset);
8388
8389 print_vma (fn, PREFIX_HEX);
8390
8391 if (procname)
8392 {
8393 fputs (" <", stdout);
8394 fputs (procname, stdout);
8395
8396 if (sym_offset)
8397 printf ("+0x%lx", (unsigned long) sym_offset);
8398 fputc ('>', stdout);
8399 }
8400
8401 return procname;
8402 }
8403
8404 static void
8405 arm_free_section (struct arm_section *arm_sec)
8406 {
8407 if (arm_sec->data != NULL)
8408 free (arm_sec->data);
8409
8410 if (arm_sec->rela != NULL)
8411 free (arm_sec->rela);
8412 }
8413
8414 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8415 cached section and install SEC instead.
8416 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8417 and return its valued in * WORDP, relocating if necessary.
8418 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
8419 relocation's offset in ADDR.
8420 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8421 into the string table of the symbol associated with the reloc. If no
8422 reloc was applied store -1 there.
8423 5) Return TRUE upon success, FALSE otherwise. */
8424
8425 static bfd_boolean
8426 get_unwind_section_word (Filedata * filedata,
8427 struct arm_unw_aux_info * aux,
8428 struct arm_section * arm_sec,
8429 Elf_Internal_Shdr * sec,
8430 bfd_vma word_offset,
8431 unsigned int * wordp,
8432 struct absaddr * addr,
8433 bfd_vma * sym_name)
8434 {
8435 Elf_Internal_Rela *rp;
8436 Elf_Internal_Sym *sym;
8437 const char * relname;
8438 unsigned int word;
8439 bfd_boolean wrapped;
8440
8441 if (sec == NULL || arm_sec == NULL)
8442 return FALSE;
8443
8444 addr->section = SHN_UNDEF;
8445 addr->offset = 0;
8446
8447 if (sym_name != NULL)
8448 *sym_name = (bfd_vma) -1;
8449
8450 /* If necessary, update the section cache. */
8451 if (sec != arm_sec->sec)
8452 {
8453 Elf_Internal_Shdr *relsec;
8454
8455 arm_free_section (arm_sec);
8456
8457 arm_sec->sec = sec;
8458 arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1,
8459 sec->sh_size, _("unwind data"));
8460 arm_sec->rela = NULL;
8461 arm_sec->nrelas = 0;
8462
8463 for (relsec = filedata->section_headers;
8464 relsec < filedata->section_headers + filedata->file_header.e_shnum;
8465 ++relsec)
8466 {
8467 if (relsec->sh_info >= filedata->file_header.e_shnum
8468 || filedata->section_headers + relsec->sh_info != sec
8469 /* PR 15745: Check the section type as well. */
8470 || (relsec->sh_type != SHT_REL
8471 && relsec->sh_type != SHT_RELA))
8472 continue;
8473
8474 arm_sec->rel_type = relsec->sh_type;
8475 if (relsec->sh_type == SHT_REL)
8476 {
8477 if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset,
8478 relsec->sh_size,
8479 & arm_sec->rela, & arm_sec->nrelas))
8480 return FALSE;
8481 }
8482 else /* relsec->sh_type == SHT_RELA */
8483 {
8484 if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset,
8485 relsec->sh_size,
8486 & arm_sec->rela, & arm_sec->nrelas))
8487 return FALSE;
8488 }
8489 break;
8490 }
8491
8492 arm_sec->next_rela = arm_sec->rela;
8493 }
8494
8495 /* If there is no unwind data we can do nothing. */
8496 if (arm_sec->data == NULL)
8497 return FALSE;
8498
8499 /* If the offset is invalid then fail. */
8500 if (/* PR 21343 *//* PR 18879 */
8501 sec->sh_size < 4
8502 || word_offset > (sec->sh_size - 4)
8503 || ((bfd_signed_vma) word_offset) < 0)
8504 return FALSE;
8505
8506 /* Get the word at the required offset. */
8507 word = byte_get (arm_sec->data + word_offset, 4);
8508
8509 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8510 if (arm_sec->rela == NULL)
8511 {
8512 * wordp = word;
8513 return TRUE;
8514 }
8515
8516 /* Look through the relocs to find the one that applies to the provided offset. */
8517 wrapped = FALSE;
8518 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
8519 {
8520 bfd_vma prelval, offset;
8521
8522 if (rp->r_offset > word_offset && !wrapped)
8523 {
8524 rp = arm_sec->rela;
8525 wrapped = TRUE;
8526 }
8527 if (rp->r_offset > word_offset)
8528 break;
8529
8530 if (rp->r_offset & 3)
8531 {
8532 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8533 (unsigned long) rp->r_offset);
8534 continue;
8535 }
8536
8537 if (rp->r_offset < word_offset)
8538 continue;
8539
8540 /* PR 17531: file: 027-161405-0.004 */
8541 if (aux->symtab == NULL)
8542 continue;
8543
8544 if (arm_sec->rel_type == SHT_REL)
8545 {
8546 offset = word & 0x7fffffff;
8547 if (offset & 0x40000000)
8548 offset |= ~ (bfd_vma) 0x7fffffff;
8549 }
8550 else if (arm_sec->rel_type == SHT_RELA)
8551 offset = rp->r_addend;
8552 else
8553 {
8554 error (_("Unknown section relocation type %d encountered\n"),
8555 arm_sec->rel_type);
8556 break;
8557 }
8558
8559 /* PR 17531 file: 027-1241568-0.004. */
8560 if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
8561 {
8562 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8563 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
8564 break;
8565 }
8566
8567 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
8568 offset += sym->st_value;
8569 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
8570
8571 /* Check that we are processing the expected reloc type. */
8572 if (filedata->file_header.e_machine == EM_ARM)
8573 {
8574 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
8575 if (relname == NULL)
8576 {
8577 warn (_("Skipping unknown ARM relocation type: %d\n"),
8578 (int) ELF32_R_TYPE (rp->r_info));
8579 continue;
8580 }
8581
8582 if (streq (relname, "R_ARM_NONE"))
8583 continue;
8584
8585 if (! streq (relname, "R_ARM_PREL31"))
8586 {
8587 warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
8588 continue;
8589 }
8590 }
8591 else if (filedata->file_header.e_machine == EM_TI_C6000)
8592 {
8593 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
8594 if (relname == NULL)
8595 {
8596 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8597 (int) ELF32_R_TYPE (rp->r_info));
8598 continue;
8599 }
8600
8601 if (streq (relname, "R_C6000_NONE"))
8602 continue;
8603
8604 if (! streq (relname, "R_C6000_PREL31"))
8605 {
8606 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
8607 continue;
8608 }
8609
8610 prelval >>= 1;
8611 }
8612 else
8613 {
8614 /* This function currently only supports ARM and TI unwinders. */
8615 warn (_("Only TI and ARM unwinders are currently supported\n"));
8616 break;
8617 }
8618
8619 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
8620 addr->section = sym->st_shndx;
8621 addr->offset = offset;
8622
8623 if (sym_name)
8624 * sym_name = sym->st_name;
8625 break;
8626 }
8627
8628 *wordp = word;
8629 arm_sec->next_rela = rp;
8630
8631 return TRUE;
8632 }
8633
8634 static const char *tic6x_unwind_regnames[16] =
8635 {
8636 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8637 "A14", "A13", "A12", "A11", "A10",
8638 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8639 };
8640
8641 static void
8642 decode_tic6x_unwind_regmask (unsigned int mask)
8643 {
8644 int i;
8645
8646 for (i = 12; mask; mask >>= 1, i--)
8647 {
8648 if (mask & 1)
8649 {
8650 fputs (tic6x_unwind_regnames[i], stdout);
8651 if (mask > 1)
8652 fputs (", ", stdout);
8653 }
8654 }
8655 }
8656
8657 #define ADVANCE \
8658 if (remaining == 0 && more_words) \
8659 { \
8660 data_offset += 4; \
8661 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
8662 data_offset, & word, & addr, NULL)) \
8663 return FALSE; \
8664 remaining = 4; \
8665 more_words--; \
8666 } \
8667
8668 #define GET_OP(OP) \
8669 ADVANCE; \
8670 if (remaining) \
8671 { \
8672 remaining--; \
8673 (OP) = word >> 24; \
8674 word <<= 8; \
8675 } \
8676 else \
8677 { \
8678 printf (_("[Truncated opcode]\n")); \
8679 return FALSE; \
8680 } \
8681 printf ("0x%02x ", OP)
8682
8683 static bfd_boolean
8684 decode_arm_unwind_bytecode (Filedata * filedata,
8685 struct arm_unw_aux_info * aux,
8686 unsigned int word,
8687 unsigned int remaining,
8688 unsigned int more_words,
8689 bfd_vma data_offset,
8690 Elf_Internal_Shdr * data_sec,
8691 struct arm_section * data_arm_sec)
8692 {
8693 struct absaddr addr;
8694 bfd_boolean res = TRUE;
8695
8696 /* Decode the unwinding instructions. */
8697 while (1)
8698 {
8699 unsigned int op, op2;
8700
8701 ADVANCE;
8702 if (remaining == 0)
8703 break;
8704 remaining--;
8705 op = word >> 24;
8706 word <<= 8;
8707
8708 printf (" 0x%02x ", op);
8709
8710 if ((op & 0xc0) == 0x00)
8711 {
8712 int offset = ((op & 0x3f) << 2) + 4;
8713
8714 printf (" vsp = vsp + %d", offset);
8715 }
8716 else if ((op & 0xc0) == 0x40)
8717 {
8718 int offset = ((op & 0x3f) << 2) + 4;
8719
8720 printf (" vsp = vsp - %d", offset);
8721 }
8722 else if ((op & 0xf0) == 0x80)
8723 {
8724 GET_OP (op2);
8725 if (op == 0x80 && op2 == 0)
8726 printf (_("Refuse to unwind"));
8727 else
8728 {
8729 unsigned int mask = ((op & 0x0f) << 8) | op2;
8730 bfd_boolean first = TRUE;
8731 int i;
8732
8733 printf ("pop {");
8734 for (i = 0; i < 12; i++)
8735 if (mask & (1 << i))
8736 {
8737 if (first)
8738 first = FALSE;
8739 else
8740 printf (", ");
8741 printf ("r%d", 4 + i);
8742 }
8743 printf ("}");
8744 }
8745 }
8746 else if ((op & 0xf0) == 0x90)
8747 {
8748 if (op == 0x9d || op == 0x9f)
8749 printf (_(" [Reserved]"));
8750 else
8751 printf (" vsp = r%d", op & 0x0f);
8752 }
8753 else if ((op & 0xf0) == 0xa0)
8754 {
8755 int end = 4 + (op & 0x07);
8756 bfd_boolean first = TRUE;
8757 int i;
8758
8759 printf (" pop {");
8760 for (i = 4; i <= end; i++)
8761 {
8762 if (first)
8763 first = FALSE;
8764 else
8765 printf (", ");
8766 printf ("r%d", i);
8767 }
8768 if (op & 0x08)
8769 {
8770 if (!first)
8771 printf (", ");
8772 printf ("r14");
8773 }
8774 printf ("}");
8775 }
8776 else if (op == 0xb0)
8777 printf (_(" finish"));
8778 else if (op == 0xb1)
8779 {
8780 GET_OP (op2);
8781 if (op2 == 0 || (op2 & 0xf0) != 0)
8782 printf (_("[Spare]"));
8783 else
8784 {
8785 unsigned int mask = op2 & 0x0f;
8786 bfd_boolean first = TRUE;
8787 int i;
8788
8789 printf ("pop {");
8790 for (i = 0; i < 12; i++)
8791 if (mask & (1 << i))
8792 {
8793 if (first)
8794 first = FALSE;
8795 else
8796 printf (", ");
8797 printf ("r%d", i);
8798 }
8799 printf ("}");
8800 }
8801 }
8802 else if (op == 0xb2)
8803 {
8804 unsigned char buf[9];
8805 unsigned int i, len;
8806 unsigned long offset;
8807
8808 for (i = 0; i < sizeof (buf); i++)
8809 {
8810 GET_OP (buf[i]);
8811 if ((buf[i] & 0x80) == 0)
8812 break;
8813 }
8814 if (i == sizeof (buf))
8815 {
8816 error (_("corrupt change to vsp"));
8817 res = FALSE;
8818 }
8819 else
8820 {
8821 offset = read_uleb128 (buf, &len, buf + i + 1);
8822 assert (len == i + 1);
8823 offset = offset * 4 + 0x204;
8824 printf ("vsp = vsp + %ld", offset);
8825 }
8826 }
8827 else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
8828 {
8829 unsigned int first, last;
8830
8831 GET_OP (op2);
8832 first = op2 >> 4;
8833 last = op2 & 0x0f;
8834 if (op == 0xc8)
8835 first = first + 16;
8836 printf ("pop {D%d", first);
8837 if (last)
8838 printf ("-D%d", first + last);
8839 printf ("}");
8840 }
8841 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
8842 {
8843 unsigned int count = op & 0x07;
8844
8845 printf ("pop {D8");
8846 if (count)
8847 printf ("-D%d", 8 + count);
8848 printf ("}");
8849 }
8850 else if (op >= 0xc0 && op <= 0xc5)
8851 {
8852 unsigned int count = op & 0x07;
8853
8854 printf (" pop {wR10");
8855 if (count)
8856 printf ("-wR%d", 10 + count);
8857 printf ("}");
8858 }
8859 else if (op == 0xc6)
8860 {
8861 unsigned int first, last;
8862
8863 GET_OP (op2);
8864 first = op2 >> 4;
8865 last = op2 & 0x0f;
8866 printf ("pop {wR%d", first);
8867 if (last)
8868 printf ("-wR%d", first + last);
8869 printf ("}");
8870 }
8871 else if (op == 0xc7)
8872 {
8873 GET_OP (op2);
8874 if (op2 == 0 || (op2 & 0xf0) != 0)
8875 printf (_("[Spare]"));
8876 else
8877 {
8878 unsigned int mask = op2 & 0x0f;
8879 bfd_boolean first = TRUE;
8880 int i;
8881
8882 printf ("pop {");
8883 for (i = 0; i < 4; i++)
8884 if (mask & (1 << i))
8885 {
8886 if (first)
8887 first = FALSE;
8888 else
8889 printf (", ");
8890 printf ("wCGR%d", i);
8891 }
8892 printf ("}");
8893 }
8894 }
8895 else
8896 {
8897 printf (_(" [unsupported opcode]"));
8898 res = FALSE;
8899 }
8900
8901 printf ("\n");
8902 }
8903
8904 return res;
8905 }
8906
8907 static bfd_boolean
8908 decode_tic6x_unwind_bytecode (Filedata * filedata,
8909 struct arm_unw_aux_info * aux,
8910 unsigned int word,
8911 unsigned int remaining,
8912 unsigned int more_words,
8913 bfd_vma data_offset,
8914 Elf_Internal_Shdr * data_sec,
8915 struct arm_section * data_arm_sec)
8916 {
8917 struct absaddr addr;
8918
8919 /* Decode the unwinding instructions. */
8920 while (1)
8921 {
8922 unsigned int op, op2;
8923
8924 ADVANCE;
8925 if (remaining == 0)
8926 break;
8927 remaining--;
8928 op = word >> 24;
8929 word <<= 8;
8930
8931 printf (" 0x%02x ", op);
8932
8933 if ((op & 0xc0) == 0x00)
8934 {
8935 int offset = ((op & 0x3f) << 3) + 8;
8936 printf (" sp = sp + %d", offset);
8937 }
8938 else if ((op & 0xc0) == 0x80)
8939 {
8940 GET_OP (op2);
8941 if (op == 0x80 && op2 == 0)
8942 printf (_("Refuse to unwind"));
8943 else
8944 {
8945 unsigned int mask = ((op & 0x1f) << 8) | op2;
8946 if (op & 0x20)
8947 printf ("pop compact {");
8948 else
8949 printf ("pop {");
8950
8951 decode_tic6x_unwind_regmask (mask);
8952 printf("}");
8953 }
8954 }
8955 else if ((op & 0xf0) == 0xc0)
8956 {
8957 unsigned int reg;
8958 unsigned int nregs;
8959 unsigned int i;
8960 const char *name;
8961 struct
8962 {
8963 unsigned int offset;
8964 unsigned int reg;
8965 } regpos[16];
8966
8967 /* Scan entire instruction first so that GET_OP output is not
8968 interleaved with disassembly. */
8969 nregs = 0;
8970 for (i = 0; nregs < (op & 0xf); i++)
8971 {
8972 GET_OP (op2);
8973 reg = op2 >> 4;
8974 if (reg != 0xf)
8975 {
8976 regpos[nregs].offset = i * 2;
8977 regpos[nregs].reg = reg;
8978 nregs++;
8979 }
8980
8981 reg = op2 & 0xf;
8982 if (reg != 0xf)
8983 {
8984 regpos[nregs].offset = i * 2 + 1;
8985 regpos[nregs].reg = reg;
8986 nregs++;
8987 }
8988 }
8989
8990 printf (_("pop frame {"));
8991 if (nregs == 0)
8992 {
8993 printf (_("*corrupt* - no registers specified"));
8994 }
8995 else
8996 {
8997 reg = nregs - 1;
8998 for (i = i * 2; i > 0; i--)
8999 {
9000 if (regpos[reg].offset == i - 1)
9001 {
9002 name = tic6x_unwind_regnames[regpos[reg].reg];
9003 if (reg > 0)
9004 reg--;
9005 }
9006 else
9007 name = _("[pad]");
9008
9009 fputs (name, stdout);
9010 if (i > 1)
9011 printf (", ");
9012 }
9013 }
9014
9015 printf ("}");
9016 }
9017 else if (op == 0xd0)
9018 printf (" MOV FP, SP");
9019 else if (op == 0xd1)
9020 printf (" __c6xabi_pop_rts");
9021 else if (op == 0xd2)
9022 {
9023 unsigned char buf[9];
9024 unsigned int i, len;
9025 unsigned long offset;
9026
9027 for (i = 0; i < sizeof (buf); i++)
9028 {
9029 GET_OP (buf[i]);
9030 if ((buf[i] & 0x80) == 0)
9031 break;
9032 }
9033 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9034 if (i == sizeof (buf))
9035 {
9036 warn (_("Corrupt stack pointer adjustment detected\n"));
9037 return FALSE;
9038 }
9039
9040 offset = read_uleb128 (buf, &len, buf + i + 1);
9041 assert (len == i + 1);
9042 offset = offset * 8 + 0x408;
9043 printf (_("sp = sp + %ld"), offset);
9044 }
9045 else if ((op & 0xf0) == 0xe0)
9046 {
9047 if ((op & 0x0f) == 7)
9048 printf (" RETURN");
9049 else
9050 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
9051 }
9052 else
9053 {
9054 printf (_(" [unsupported opcode]"));
9055 }
9056 putchar ('\n');
9057 }
9058
9059 return TRUE;
9060 }
9061
9062 static bfd_vma
9063 arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where)
9064 {
9065 bfd_vma offset;
9066
9067 offset = word & 0x7fffffff;
9068 if (offset & 0x40000000)
9069 offset |= ~ (bfd_vma) 0x7fffffff;
9070
9071 if (filedata->file_header.e_machine == EM_TI_C6000)
9072 offset <<= 1;
9073
9074 return offset + where;
9075 }
9076
9077 static bfd_boolean
9078 decode_arm_unwind (Filedata * filedata,
9079 struct arm_unw_aux_info * aux,
9080 unsigned int word,
9081 unsigned int remaining,
9082 bfd_vma data_offset,
9083 Elf_Internal_Shdr * data_sec,
9084 struct arm_section * data_arm_sec)
9085 {
9086 int per_index;
9087 unsigned int more_words = 0;
9088 struct absaddr addr;
9089 bfd_vma sym_name = (bfd_vma) -1;
9090 bfd_boolean res = TRUE;
9091
9092 if (remaining == 0)
9093 {
9094 /* Fetch the first word.
9095 Note - when decoding an object file the address extracted
9096 here will always be 0. So we also pass in the sym_name
9097 parameter so that we can find the symbol associated with
9098 the personality routine. */
9099 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset,
9100 & word, & addr, & sym_name))
9101 return FALSE;
9102
9103 remaining = 4;
9104 }
9105 else
9106 {
9107 addr.section = SHN_UNDEF;
9108 addr.offset = 0;
9109 }
9110
9111 if ((word & 0x80000000) == 0)
9112 {
9113 /* Expand prel31 for personality routine. */
9114 bfd_vma fn;
9115 const char *procname;
9116
9117 fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset);
9118 printf (_(" Personality routine: "));
9119 if (fn == 0
9120 && addr.section == SHN_UNDEF && addr.offset == 0
9121 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
9122 {
9123 procname = aux->strtab + sym_name;
9124 print_vma (fn, PREFIX_HEX);
9125 if (procname)
9126 {
9127 fputs (" <", stdout);
9128 fputs (procname, stdout);
9129 fputc ('>', stdout);
9130 }
9131 }
9132 else
9133 procname = arm_print_vma_and_name (filedata, aux, fn, addr);
9134 fputc ('\n', stdout);
9135
9136 /* The GCC personality routines use the standard compact
9137 encoding, starting with one byte giving the number of
9138 words. */
9139 if (procname != NULL
9140 && (const_strneq (procname, "__gcc_personality_v0")
9141 || const_strneq (procname, "__gxx_personality_v0")
9142 || const_strneq (procname, "__gcj_personality_v0")
9143 || const_strneq (procname, "__gnu_objc_personality_v0")))
9144 {
9145 remaining = 0;
9146 more_words = 1;
9147 ADVANCE;
9148 if (!remaining)
9149 {
9150 printf (_(" [Truncated data]\n"));
9151 return FALSE;
9152 }
9153 more_words = word >> 24;
9154 word <<= 8;
9155 remaining--;
9156 per_index = -1;
9157 }
9158 else
9159 return TRUE;
9160 }
9161 else
9162 {
9163 /* ARM EHABI Section 6.3:
9164
9165 An exception-handling table entry for the compact model looks like:
9166
9167 31 30-28 27-24 23-0
9168 -- ----- ----- ----
9169 1 0 index Data for personalityRoutine[index] */
9170
9171 if (filedata->file_header.e_machine == EM_ARM
9172 && (word & 0x70000000))
9173 {
9174 warn (_("Corrupt ARM compact model table entry: %x \n"), word);
9175 res = FALSE;
9176 }
9177
9178 per_index = (word >> 24) & 0x7f;
9179 printf (_(" Compact model index: %d\n"), per_index);
9180 if (per_index == 0)
9181 {
9182 more_words = 0;
9183 word <<= 8;
9184 remaining--;
9185 }
9186 else if (per_index < 3)
9187 {
9188 more_words = (word >> 16) & 0xff;
9189 word <<= 16;
9190 remaining -= 2;
9191 }
9192 }
9193
9194 switch (filedata->file_header.e_machine)
9195 {
9196 case EM_ARM:
9197 if (per_index < 3)
9198 {
9199 if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words,
9200 data_offset, data_sec, data_arm_sec))
9201 res = FALSE;
9202 }
9203 else
9204 {
9205 warn (_("Unknown ARM compact model index encountered\n"));
9206 printf (_(" [reserved]\n"));
9207 res = FALSE;
9208 }
9209 break;
9210
9211 case EM_TI_C6000:
9212 if (per_index < 3)
9213 {
9214 if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words,
9215 data_offset, data_sec, data_arm_sec))
9216 res = FALSE;
9217 }
9218 else if (per_index < 5)
9219 {
9220 if (((word >> 17) & 0x7f) == 0x7f)
9221 printf (_(" Restore stack from frame pointer\n"));
9222 else
9223 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
9224 printf (_(" Registers restored: "));
9225 if (per_index == 4)
9226 printf (" (compact) ");
9227 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
9228 putchar ('\n');
9229 printf (_(" Return register: %s\n"),
9230 tic6x_unwind_regnames[word & 0xf]);
9231 }
9232 else
9233 printf (_(" [reserved (%d)]\n"), per_index);
9234 break;
9235
9236 default:
9237 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
9238 filedata->file_header.e_machine);
9239 res = FALSE;
9240 }
9241
9242 /* Decode the descriptors. Not implemented. */
9243
9244 return res;
9245 }
9246
9247 static bfd_boolean
9248 dump_arm_unwind (Filedata * filedata,
9249 struct arm_unw_aux_info * aux,
9250 Elf_Internal_Shdr * exidx_sec)
9251 {
9252 struct arm_section exidx_arm_sec, extab_arm_sec;
9253 unsigned int i, exidx_len;
9254 unsigned long j, nfuns;
9255 bfd_boolean res = TRUE;
9256
9257 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
9258 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
9259 exidx_len = exidx_sec->sh_size / 8;
9260
9261 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
9262 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
9263 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
9264 aux->funtab[nfuns++] = aux->symtab[j];
9265 aux->nfuns = nfuns;
9266 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
9267
9268 for (i = 0; i < exidx_len; i++)
9269 {
9270 unsigned int exidx_fn, exidx_entry;
9271 struct absaddr fn_addr, entry_addr;
9272 bfd_vma fn;
9273
9274 fputc ('\n', stdout);
9275
9276 if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
9277 8 * i, & exidx_fn, & fn_addr, NULL)
9278 || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
9279 8 * i + 4, & exidx_entry, & entry_addr, NULL))
9280 {
9281 free (aux->funtab);
9282 arm_free_section (& exidx_arm_sec);
9283 arm_free_section (& extab_arm_sec);
9284 return FALSE;
9285 }
9286
9287 /* ARM EHABI, Section 5:
9288 An index table entry consists of 2 words.
9289 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9290 if (exidx_fn & 0x80000000)
9291 {
9292 warn (_("corrupt index table entry: %x\n"), exidx_fn);
9293 res = FALSE;
9294 }
9295
9296 fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i);
9297
9298 arm_print_vma_and_name (filedata, aux, fn, fn_addr);
9299 fputs (": ", stdout);
9300
9301 if (exidx_entry == 1)
9302 {
9303 print_vma (exidx_entry, PREFIX_HEX);
9304 fputs (" [cantunwind]\n", stdout);
9305 }
9306 else if (exidx_entry & 0x80000000)
9307 {
9308 print_vma (exidx_entry, PREFIX_HEX);
9309 fputc ('\n', stdout);
9310 decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL);
9311 }
9312 else
9313 {
9314 bfd_vma table, table_offset = 0;
9315 Elf_Internal_Shdr *table_sec;
9316
9317 fputs ("@", stdout);
9318 table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
9319 print_vma (table, PREFIX_HEX);
9320 printf ("\n");
9321
9322 /* Locate the matching .ARM.extab. */
9323 if (entry_addr.section != SHN_UNDEF
9324 && entry_addr.section < filedata->file_header.e_shnum)
9325 {
9326 table_sec = filedata->section_headers + entry_addr.section;
9327 table_offset = entry_addr.offset;
9328 /* PR 18879 */
9329 if (table_offset > table_sec->sh_size
9330 || ((bfd_signed_vma) table_offset) < 0)
9331 {
9332 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9333 (unsigned long) table_offset,
9334 printable_section_name (filedata, table_sec));
9335 res = FALSE;
9336 continue;
9337 }
9338 }
9339 else
9340 {
9341 table_sec = find_section_by_address (filedata, table);
9342 if (table_sec != NULL)
9343 table_offset = table - table_sec->sh_addr;
9344 }
9345
9346 if (table_sec == NULL)
9347 {
9348 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9349 (unsigned long) table);
9350 res = FALSE;
9351 continue;
9352 }
9353
9354 if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec,
9355 &extab_arm_sec))
9356 res = FALSE;
9357 }
9358 }
9359
9360 printf ("\n");
9361
9362 free (aux->funtab);
9363 arm_free_section (&exidx_arm_sec);
9364 arm_free_section (&extab_arm_sec);
9365
9366 return res;
9367 }
9368
9369 /* Used for both ARM and C6X unwinding tables. */
9370
9371 static bfd_boolean
9372 arm_process_unwind (Filedata * filedata)
9373 {
9374 struct arm_unw_aux_info aux;
9375 Elf_Internal_Shdr *unwsec = NULL;
9376 Elf_Internal_Shdr *strsec;
9377 Elf_Internal_Shdr *sec;
9378 unsigned long i;
9379 unsigned int sec_type;
9380 bfd_boolean res = TRUE;
9381
9382 switch (filedata->file_header.e_machine)
9383 {
9384 case EM_ARM:
9385 sec_type = SHT_ARM_EXIDX;
9386 break;
9387
9388 case EM_TI_C6000:
9389 sec_type = SHT_C6000_UNWIND;
9390 break;
9391
9392 default:
9393 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
9394 filedata->file_header.e_machine);
9395 return FALSE;
9396 }
9397
9398 if (filedata->string_table == NULL)
9399 return FALSE;
9400
9401 memset (& aux, 0, sizeof (aux));
9402 aux.filedata = filedata;
9403
9404 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
9405 {
9406 if (sec->sh_type == SHT_SYMTAB && sec->sh_link < filedata->file_header.e_shnum)
9407 {
9408 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
9409
9410 strsec = filedata->section_headers + sec->sh_link;
9411
9412 /* PR binutils/17531 file: 011-12666-0.004. */
9413 if (aux.strtab != NULL)
9414 {
9415 error (_("Multiple string tables found in file.\n"));
9416 free (aux.strtab);
9417 res = FALSE;
9418 }
9419 aux.strtab = get_data (NULL, filedata, strsec->sh_offset,
9420 1, strsec->sh_size, _("string table"));
9421 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
9422 }
9423 else if (sec->sh_type == sec_type)
9424 unwsec = sec;
9425 }
9426
9427 if (unwsec == NULL)
9428 printf (_("\nThere are no unwind sections in this file.\n"));
9429 else
9430 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
9431 {
9432 if (sec->sh_type == sec_type)
9433 {
9434 unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size);
9435 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9436 "contains %lu entry:\n",
9437 "\nUnwind section '%s' at offset 0x%lx "
9438 "contains %lu entries:\n",
9439 num_unwind),
9440 printable_section_name (filedata, sec),
9441 (unsigned long) sec->sh_offset,
9442 num_unwind);
9443
9444 if (! dump_arm_unwind (filedata, &aux, sec))
9445 res = FALSE;
9446 }
9447 }
9448
9449 if (aux.symtab)
9450 free (aux.symtab);
9451 if (aux.strtab)
9452 free ((char *) aux.strtab);
9453
9454 return res;
9455 }
9456
9457 static bfd_boolean
9458 process_unwind (Filedata * filedata)
9459 {
9460 struct unwind_handler
9461 {
9462 unsigned int machtype;
9463 bfd_boolean (* handler)(Filedata *);
9464 } handlers[] =
9465 {
9466 { EM_ARM, arm_process_unwind },
9467 { EM_IA_64, ia64_process_unwind },
9468 { EM_PARISC, hppa_process_unwind },
9469 { EM_TI_C6000, arm_process_unwind },
9470 { 0, NULL }
9471 };
9472 int i;
9473
9474 if (!do_unwind)
9475 return TRUE;
9476
9477 for (i = 0; handlers[i].handler != NULL; i++)
9478 if (filedata->file_header.e_machine == handlers[i].machtype)
9479 return handlers[i].handler (filedata);
9480
9481 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
9482 get_machine_name (filedata->file_header.e_machine));
9483 return TRUE;
9484 }
9485
9486 static void
9487 dynamic_section_aarch64_val (Elf_Internal_Dyn * entry)
9488 {
9489 switch (entry->d_tag)
9490 {
9491 case DT_AARCH64_BTI_PLT:
9492 case DT_AARCH64_PAC_PLT:
9493 break;
9494 default:
9495 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9496 break;
9497 }
9498 putchar ('\n');
9499 }
9500
9501 static void
9502 dynamic_section_mips_val (Elf_Internal_Dyn * entry)
9503 {
9504 switch (entry->d_tag)
9505 {
9506 case DT_MIPS_FLAGS:
9507 if (entry->d_un.d_val == 0)
9508 printf (_("NONE"));
9509 else
9510 {
9511 static const char * opts[] =
9512 {
9513 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9514 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9515 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9516 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9517 "RLD_ORDER_SAFE"
9518 };
9519 unsigned int cnt;
9520 bfd_boolean first = TRUE;
9521
9522 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
9523 if (entry->d_un.d_val & (1 << cnt))
9524 {
9525 printf ("%s%s", first ? "" : " ", opts[cnt]);
9526 first = FALSE;
9527 }
9528 }
9529 break;
9530
9531 case DT_MIPS_IVERSION:
9532 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
9533 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
9534 else
9535 {
9536 char buf[40];
9537 sprintf_vma (buf, entry->d_un.d_ptr);
9538 /* Note: coded this way so that there is a single string for translation. */
9539 printf (_("<corrupt: %s>"), buf);
9540 }
9541 break;
9542
9543 case DT_MIPS_TIME_STAMP:
9544 {
9545 char timebuf[128];
9546 struct tm * tmp;
9547 time_t atime = entry->d_un.d_val;
9548
9549 tmp = gmtime (&atime);
9550 /* PR 17531: file: 6accc532. */
9551 if (tmp == NULL)
9552 snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
9553 else
9554 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
9555 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9556 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
9557 printf (_("Time Stamp: %s"), timebuf);
9558 }
9559 break;
9560
9561 case DT_MIPS_RLD_VERSION:
9562 case DT_MIPS_LOCAL_GOTNO:
9563 case DT_MIPS_CONFLICTNO:
9564 case DT_MIPS_LIBLISTNO:
9565 case DT_MIPS_SYMTABNO:
9566 case DT_MIPS_UNREFEXTNO:
9567 case DT_MIPS_HIPAGENO:
9568 case DT_MIPS_DELTA_CLASS_NO:
9569 case DT_MIPS_DELTA_INSTANCE_NO:
9570 case DT_MIPS_DELTA_RELOC_NO:
9571 case DT_MIPS_DELTA_SYM_NO:
9572 case DT_MIPS_DELTA_CLASSSYM_NO:
9573 case DT_MIPS_COMPACT_SIZE:
9574 print_vma (entry->d_un.d_val, DEC);
9575 break;
9576
9577 case DT_MIPS_XHASH:
9578 dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val;
9579 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
9580 /* Falls through. */
9581
9582 default:
9583 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9584 }
9585 putchar ('\n');
9586 }
9587
9588 static void
9589 dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
9590 {
9591 switch (entry->d_tag)
9592 {
9593 case DT_HP_DLD_FLAGS:
9594 {
9595 static struct
9596 {
9597 long int bit;
9598 const char * str;
9599 }
9600 flags[] =
9601 {
9602 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
9603 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
9604 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
9605 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
9606 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
9607 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
9608 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
9609 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
9610 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
9611 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
9612 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
9613 { DT_HP_GST, "HP_GST" },
9614 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
9615 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
9616 { DT_HP_NODELETE, "HP_NODELETE" },
9617 { DT_HP_GROUP, "HP_GROUP" },
9618 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
9619 };
9620 bfd_boolean first = TRUE;
9621 size_t cnt;
9622 bfd_vma val = entry->d_un.d_val;
9623
9624 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
9625 if (val & flags[cnt].bit)
9626 {
9627 if (! first)
9628 putchar (' ');
9629 fputs (flags[cnt].str, stdout);
9630 first = FALSE;
9631 val ^= flags[cnt].bit;
9632 }
9633
9634 if (val != 0 || first)
9635 {
9636 if (! first)
9637 putchar (' ');
9638 print_vma (val, HEX);
9639 }
9640 }
9641 break;
9642
9643 default:
9644 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9645 break;
9646 }
9647 putchar ('\n');
9648 }
9649
9650 #ifdef BFD64
9651
9652 /* VMS vs Unix time offset and factor. */
9653
9654 #define VMS_EPOCH_OFFSET 35067168000000000LL
9655 #define VMS_GRANULARITY_FACTOR 10000000
9656
9657 /* Display a VMS time in a human readable format. */
9658
9659 static void
9660 print_vms_time (bfd_int64_t vmstime)
9661 {
9662 struct tm *tm;
9663 time_t unxtime;
9664
9665 unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
9666 tm = gmtime (&unxtime);
9667 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
9668 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
9669 tm->tm_hour, tm->tm_min, tm->tm_sec);
9670 }
9671 #endif /* BFD64 */
9672
9673 static void
9674 dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
9675 {
9676 switch (entry->d_tag)
9677 {
9678 case DT_IA_64_PLT_RESERVE:
9679 /* First 3 slots reserved. */
9680 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9681 printf (" -- ");
9682 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
9683 break;
9684
9685 case DT_IA_64_VMS_LINKTIME:
9686 #ifdef BFD64
9687 print_vms_time (entry->d_un.d_val);
9688 #endif
9689 break;
9690
9691 case DT_IA_64_VMS_LNKFLAGS:
9692 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9693 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
9694 printf (" CALL_DEBUG");
9695 if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
9696 printf (" NOP0BUFS");
9697 if (entry->d_un.d_val & VMS_LF_P0IMAGE)
9698 printf (" P0IMAGE");
9699 if (entry->d_un.d_val & VMS_LF_MKTHREADS)
9700 printf (" MKTHREADS");
9701 if (entry->d_un.d_val & VMS_LF_UPCALLS)
9702 printf (" UPCALLS");
9703 if (entry->d_un.d_val & VMS_LF_IMGSTA)
9704 printf (" IMGSTA");
9705 if (entry->d_un.d_val & VMS_LF_INITIALIZE)
9706 printf (" INITIALIZE");
9707 if (entry->d_un.d_val & VMS_LF_MAIN)
9708 printf (" MAIN");
9709 if (entry->d_un.d_val & VMS_LF_EXE_INIT)
9710 printf (" EXE_INIT");
9711 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
9712 printf (" TBK_IN_IMG");
9713 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
9714 printf (" DBG_IN_IMG");
9715 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
9716 printf (" TBK_IN_DSF");
9717 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
9718 printf (" DBG_IN_DSF");
9719 if (entry->d_un.d_val & VMS_LF_SIGNATURES)
9720 printf (" SIGNATURES");
9721 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
9722 printf (" REL_SEG_OFF");
9723 break;
9724
9725 default:
9726 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9727 break;
9728 }
9729 putchar ('\n');
9730 }
9731
9732 static bfd_boolean
9733 get_32bit_dynamic_section (Filedata * filedata)
9734 {
9735 Elf32_External_Dyn * edyn;
9736 Elf32_External_Dyn * ext;
9737 Elf_Internal_Dyn * entry;
9738
9739 edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
9740 dynamic_size, _("dynamic section"));
9741 if (!edyn)
9742 return FALSE;
9743
9744 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9745 might not have the luxury of section headers. Look for the DT_NULL
9746 terminator to determine the number of entries. */
9747 for (ext = edyn, dynamic_nent = 0;
9748 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
9749 ext++)
9750 {
9751 dynamic_nent++;
9752 if (BYTE_GET (ext->d_tag) == DT_NULL)
9753 break;
9754 }
9755
9756 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9757 sizeof (* entry));
9758 if (dynamic_section == NULL)
9759 {
9760 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9761 (unsigned long) dynamic_nent);
9762 free (edyn);
9763 return FALSE;
9764 }
9765
9766 for (ext = edyn, entry = dynamic_section;
9767 entry < dynamic_section + dynamic_nent;
9768 ext++, entry++)
9769 {
9770 entry->d_tag = BYTE_GET (ext->d_tag);
9771 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
9772 }
9773
9774 free (edyn);
9775
9776 return TRUE;
9777 }
9778
9779 static bfd_boolean
9780 get_64bit_dynamic_section (Filedata * filedata)
9781 {
9782 Elf64_External_Dyn * edyn;
9783 Elf64_External_Dyn * ext;
9784 Elf_Internal_Dyn * entry;
9785
9786 /* Read in the data. */
9787 edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
9788 dynamic_size, _("dynamic section"));
9789 if (!edyn)
9790 return FALSE;
9791
9792 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9793 might not have the luxury of section headers. Look for the DT_NULL
9794 terminator to determine the number of entries. */
9795 for (ext = edyn, dynamic_nent = 0;
9796 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
9797 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
9798 ext++)
9799 {
9800 dynamic_nent++;
9801 if (BYTE_GET (ext->d_tag) == DT_NULL)
9802 break;
9803 }
9804
9805 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9806 sizeof (* entry));
9807 if (dynamic_section == NULL)
9808 {
9809 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9810 (unsigned long) dynamic_nent);
9811 free (edyn);
9812 return FALSE;
9813 }
9814
9815 /* Convert from external to internal formats. */
9816 for (ext = edyn, entry = dynamic_section;
9817 entry < dynamic_section + dynamic_nent;
9818 ext++, entry++)
9819 {
9820 entry->d_tag = BYTE_GET (ext->d_tag);
9821 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
9822 }
9823
9824 free (edyn);
9825
9826 return TRUE;
9827 }
9828
9829 static void
9830 print_dynamic_flags (bfd_vma flags)
9831 {
9832 bfd_boolean first = TRUE;
9833
9834 while (flags)
9835 {
9836 bfd_vma flag;
9837
9838 flag = flags & - flags;
9839 flags &= ~ flag;
9840
9841 if (first)
9842 first = FALSE;
9843 else
9844 putc (' ', stdout);
9845
9846 switch (flag)
9847 {
9848 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
9849 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
9850 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
9851 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
9852 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
9853 default: fputs (_("unknown"), stdout); break;
9854 }
9855 }
9856 puts ("");
9857 }
9858
9859 /* Parse and display the contents of the dynamic section. */
9860
9861 static bfd_boolean
9862 process_dynamic_section (Filedata * filedata)
9863 {
9864 Elf_Internal_Dyn * entry;
9865
9866 if (dynamic_size == 0)
9867 {
9868 if (do_dynamic)
9869 printf (_("\nThere is no dynamic section in this file.\n"));
9870
9871 return TRUE;
9872 }
9873
9874 if (is_32bit_elf)
9875 {
9876 if (! get_32bit_dynamic_section (filedata))
9877 return FALSE;
9878 }
9879 else
9880 {
9881 if (! get_64bit_dynamic_section (filedata))
9882 return FALSE;
9883 }
9884
9885 /* Find the appropriate symbol table. */
9886 if (dynamic_symbols == NULL)
9887 {
9888 for (entry = dynamic_section;
9889 entry < dynamic_section + dynamic_nent;
9890 ++entry)
9891 {
9892 Elf_Internal_Shdr section;
9893
9894 if (entry->d_tag != DT_SYMTAB)
9895 continue;
9896
9897 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
9898
9899 /* Since we do not know how big the symbol table is,
9900 we default to reading in the entire file (!) and
9901 processing that. This is overkill, I know, but it
9902 should work. */
9903 section.sh_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
9904 if ((bfd_size_type) section.sh_offset > filedata->file_size)
9905 {
9906 /* See PR 21379 for a reproducer. */
9907 error (_("Invalid DT_SYMTAB entry: %lx"), (long) section.sh_offset);
9908 return FALSE;
9909 }
9910
9911 if (archive_file_offset != 0)
9912 section.sh_size = archive_file_size - section.sh_offset;
9913 else
9914 section.sh_size = filedata->file_size - section.sh_offset;
9915
9916 if (is_32bit_elf)
9917 section.sh_entsize = sizeof (Elf32_External_Sym);
9918 else
9919 section.sh_entsize = sizeof (Elf64_External_Sym);
9920 section.sh_name = filedata->string_table_length;
9921
9922 if (dynamic_symbols != NULL)
9923 {
9924 error (_("Multiple dynamic symbol table sections found\n"));
9925 free (dynamic_symbols);
9926 }
9927 dynamic_symbols = GET_ELF_SYMBOLS (filedata, &section, & num_dynamic_syms);
9928 if (num_dynamic_syms < 1)
9929 {
9930 error (_("Unable to determine the number of symbols to load\n"));
9931 continue;
9932 }
9933 }
9934 }
9935
9936 /* Similarly find a string table. */
9937 if (dynamic_strings == NULL)
9938 {
9939 for (entry = dynamic_section;
9940 entry < dynamic_section + dynamic_nent;
9941 ++entry)
9942 {
9943 unsigned long offset;
9944 long str_tab_len;
9945
9946 if (entry->d_tag != DT_STRTAB)
9947 continue;
9948
9949 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
9950
9951 /* Since we do not know how big the string table is,
9952 we default to reading in the entire file (!) and
9953 processing that. This is overkill, I know, but it
9954 should work. */
9955
9956 offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
9957
9958 if (archive_file_offset != 0)
9959 str_tab_len = archive_file_size - offset;
9960 else
9961 str_tab_len = filedata->file_size - offset;
9962
9963 if (str_tab_len < 1)
9964 {
9965 error
9966 (_("Unable to determine the length of the dynamic string table\n"));
9967 continue;
9968 }
9969
9970 if (dynamic_strings != NULL)
9971 {
9972 error (_("Multiple dynamic string tables found\n"));
9973 free (dynamic_strings);
9974 }
9975
9976 dynamic_strings = (char *) get_data (NULL, filedata, offset, 1,
9977 str_tab_len,
9978 _("dynamic string table"));
9979 dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
9980 }
9981 }
9982
9983 /* And find the syminfo section if available. */
9984 if (dynamic_syminfo == NULL)
9985 {
9986 unsigned long syminsz = 0;
9987
9988 for (entry = dynamic_section;
9989 entry < dynamic_section + dynamic_nent;
9990 ++entry)
9991 {
9992 if (entry->d_tag == DT_SYMINENT)
9993 {
9994 /* Note: these braces are necessary to avoid a syntax
9995 error from the SunOS4 C compiler. */
9996 /* PR binutils/17531: A corrupt file can trigger this test.
9997 So do not use an assert, instead generate an error message. */
9998 if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
9999 error (_("Bad value (%d) for SYMINENT entry\n"),
10000 (int) entry->d_un.d_val);
10001 }
10002 else if (entry->d_tag == DT_SYMINSZ)
10003 syminsz = entry->d_un.d_val;
10004 else if (entry->d_tag == DT_SYMINFO)
10005 dynamic_syminfo_offset = offset_from_vma (filedata, entry->d_un.d_val,
10006 syminsz);
10007 }
10008
10009 if (dynamic_syminfo_offset != 0 && syminsz != 0)
10010 {
10011 Elf_External_Syminfo * extsyminfo;
10012 Elf_External_Syminfo * extsym;
10013 Elf_Internal_Syminfo * syminfo;
10014
10015 /* There is a syminfo section. Read the data. */
10016 extsyminfo = (Elf_External_Syminfo *)
10017 get_data (NULL, filedata, dynamic_syminfo_offset, 1, syminsz,
10018 _("symbol information"));
10019 if (!extsyminfo)
10020 return FALSE;
10021
10022 if (dynamic_syminfo != NULL)
10023 {
10024 error (_("Multiple dynamic symbol information sections found\n"));
10025 free (dynamic_syminfo);
10026 }
10027 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
10028 if (dynamic_syminfo == NULL)
10029 {
10030 error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
10031 (unsigned long) syminsz);
10032 return FALSE;
10033 }
10034
10035 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
10036 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
10037 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
10038 ++syminfo, ++extsym)
10039 {
10040 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
10041 syminfo->si_flags = BYTE_GET (extsym->si_flags);
10042 }
10043
10044 free (extsyminfo);
10045 }
10046 }
10047
10048 if (do_dynamic && dynamic_addr)
10049 printf (ngettext ("\nDynamic section at offset 0x%lx "
10050 "contains %lu entry:\n",
10051 "\nDynamic section at offset 0x%lx "
10052 "contains %lu entries:\n",
10053 dynamic_nent),
10054 dynamic_addr, (unsigned long) dynamic_nent);
10055 if (do_dynamic)
10056 printf (_(" Tag Type Name/Value\n"));
10057
10058 for (entry = dynamic_section;
10059 entry < dynamic_section + dynamic_nent;
10060 entry++)
10061 {
10062 if (do_dynamic)
10063 {
10064 const char * dtype;
10065
10066 putchar (' ');
10067 print_vma (entry->d_tag, FULL_HEX);
10068 dtype = get_dynamic_type (filedata, entry->d_tag);
10069 printf (" (%s)%*s", dtype,
10070 ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " ");
10071 }
10072
10073 switch (entry->d_tag)
10074 {
10075 case DT_FLAGS:
10076 if (do_dynamic)
10077 print_dynamic_flags (entry->d_un.d_val);
10078 break;
10079
10080 case DT_AUXILIARY:
10081 case DT_FILTER:
10082 case DT_CONFIG:
10083 case DT_DEPAUDIT:
10084 case DT_AUDIT:
10085 if (do_dynamic)
10086 {
10087 switch (entry->d_tag)
10088 {
10089 case DT_AUXILIARY:
10090 printf (_("Auxiliary library"));
10091 break;
10092
10093 case DT_FILTER:
10094 printf (_("Filter library"));
10095 break;
10096
10097 case DT_CONFIG:
10098 printf (_("Configuration file"));
10099 break;
10100
10101 case DT_DEPAUDIT:
10102 printf (_("Dependency audit library"));
10103 break;
10104
10105 case DT_AUDIT:
10106 printf (_("Audit library"));
10107 break;
10108 }
10109
10110 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
10111 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
10112 else
10113 {
10114 printf (": ");
10115 print_vma (entry->d_un.d_val, PREFIX_HEX);
10116 putchar ('\n');
10117 }
10118 }
10119 break;
10120
10121 case DT_FEATURE:
10122 if (do_dynamic)
10123 {
10124 printf (_("Flags:"));
10125
10126 if (entry->d_un.d_val == 0)
10127 printf (_(" None\n"));
10128 else
10129 {
10130 unsigned long int val = entry->d_un.d_val;
10131
10132 if (val & DTF_1_PARINIT)
10133 {
10134 printf (" PARINIT");
10135 val ^= DTF_1_PARINIT;
10136 }
10137 if (val & DTF_1_CONFEXP)
10138 {
10139 printf (" CONFEXP");
10140 val ^= DTF_1_CONFEXP;
10141 }
10142 if (val != 0)
10143 printf (" %lx", val);
10144 puts ("");
10145 }
10146 }
10147 break;
10148
10149 case DT_POSFLAG_1:
10150 if (do_dynamic)
10151 {
10152 printf (_("Flags:"));
10153
10154 if (entry->d_un.d_val == 0)
10155 printf (_(" None\n"));
10156 else
10157 {
10158 unsigned long int val = entry->d_un.d_val;
10159
10160 if (val & DF_P1_LAZYLOAD)
10161 {
10162 printf (" LAZYLOAD");
10163 val ^= DF_P1_LAZYLOAD;
10164 }
10165 if (val & DF_P1_GROUPPERM)
10166 {
10167 printf (" GROUPPERM");
10168 val ^= DF_P1_GROUPPERM;
10169 }
10170 if (val != 0)
10171 printf (" %lx", val);
10172 puts ("");
10173 }
10174 }
10175 break;
10176
10177 case DT_FLAGS_1:
10178 if (do_dynamic)
10179 {
10180 printf (_("Flags:"));
10181 if (entry->d_un.d_val == 0)
10182 printf (_(" None\n"));
10183 else
10184 {
10185 unsigned long int val = entry->d_un.d_val;
10186
10187 if (val & DF_1_NOW)
10188 {
10189 printf (" NOW");
10190 val ^= DF_1_NOW;
10191 }
10192 if (val & DF_1_GLOBAL)
10193 {
10194 printf (" GLOBAL");
10195 val ^= DF_1_GLOBAL;
10196 }
10197 if (val & DF_1_GROUP)
10198 {
10199 printf (" GROUP");
10200 val ^= DF_1_GROUP;
10201 }
10202 if (val & DF_1_NODELETE)
10203 {
10204 printf (" NODELETE");
10205 val ^= DF_1_NODELETE;
10206 }
10207 if (val & DF_1_LOADFLTR)
10208 {
10209 printf (" LOADFLTR");
10210 val ^= DF_1_LOADFLTR;
10211 }
10212 if (val & DF_1_INITFIRST)
10213 {
10214 printf (" INITFIRST");
10215 val ^= DF_1_INITFIRST;
10216 }
10217 if (val & DF_1_NOOPEN)
10218 {
10219 printf (" NOOPEN");
10220 val ^= DF_1_NOOPEN;
10221 }
10222 if (val & DF_1_ORIGIN)
10223 {
10224 printf (" ORIGIN");
10225 val ^= DF_1_ORIGIN;
10226 }
10227 if (val & DF_1_DIRECT)
10228 {
10229 printf (" DIRECT");
10230 val ^= DF_1_DIRECT;
10231 }
10232 if (val & DF_1_TRANS)
10233 {
10234 printf (" TRANS");
10235 val ^= DF_1_TRANS;
10236 }
10237 if (val & DF_1_INTERPOSE)
10238 {
10239 printf (" INTERPOSE");
10240 val ^= DF_1_INTERPOSE;
10241 }
10242 if (val & DF_1_NODEFLIB)
10243 {
10244 printf (" NODEFLIB");
10245 val ^= DF_1_NODEFLIB;
10246 }
10247 if (val & DF_1_NODUMP)
10248 {
10249 printf (" NODUMP");
10250 val ^= DF_1_NODUMP;
10251 }
10252 if (val & DF_1_CONFALT)
10253 {
10254 printf (" CONFALT");
10255 val ^= DF_1_CONFALT;
10256 }
10257 if (val & DF_1_ENDFILTEE)
10258 {
10259 printf (" ENDFILTEE");
10260 val ^= DF_1_ENDFILTEE;
10261 }
10262 if (val & DF_1_DISPRELDNE)
10263 {
10264 printf (" DISPRELDNE");
10265 val ^= DF_1_DISPRELDNE;
10266 }
10267 if (val & DF_1_DISPRELPND)
10268 {
10269 printf (" DISPRELPND");
10270 val ^= DF_1_DISPRELPND;
10271 }
10272 if (val & DF_1_NODIRECT)
10273 {
10274 printf (" NODIRECT");
10275 val ^= DF_1_NODIRECT;
10276 }
10277 if (val & DF_1_IGNMULDEF)
10278 {
10279 printf (" IGNMULDEF");
10280 val ^= DF_1_IGNMULDEF;
10281 }
10282 if (val & DF_1_NOKSYMS)
10283 {
10284 printf (" NOKSYMS");
10285 val ^= DF_1_NOKSYMS;
10286 }
10287 if (val & DF_1_NOHDR)
10288 {
10289 printf (" NOHDR");
10290 val ^= DF_1_NOHDR;
10291 }
10292 if (val & DF_1_EDITED)
10293 {
10294 printf (" EDITED");
10295 val ^= DF_1_EDITED;
10296 }
10297 if (val & DF_1_NORELOC)
10298 {
10299 printf (" NORELOC");
10300 val ^= DF_1_NORELOC;
10301 }
10302 if (val & DF_1_SYMINTPOSE)
10303 {
10304 printf (" SYMINTPOSE");
10305 val ^= DF_1_SYMINTPOSE;
10306 }
10307 if (val & DF_1_GLOBAUDIT)
10308 {
10309 printf (" GLOBAUDIT");
10310 val ^= DF_1_GLOBAUDIT;
10311 }
10312 if (val & DF_1_SINGLETON)
10313 {
10314 printf (" SINGLETON");
10315 val ^= DF_1_SINGLETON;
10316 }
10317 if (val & DF_1_STUB)
10318 {
10319 printf (" STUB");
10320 val ^= DF_1_STUB;
10321 }
10322 if (val & DF_1_PIE)
10323 {
10324 printf (" PIE");
10325 val ^= DF_1_PIE;
10326 }
10327 if (val & DF_1_KMOD)
10328 {
10329 printf (" KMOD");
10330 val ^= DF_1_KMOD;
10331 }
10332 if (val & DF_1_WEAKFILTER)
10333 {
10334 printf (" WEAKFILTER");
10335 val ^= DF_1_WEAKFILTER;
10336 }
10337 if (val & DF_1_NOCOMMON)
10338 {
10339 printf (" NOCOMMON");
10340 val ^= DF_1_NOCOMMON;
10341 }
10342 if (val != 0)
10343 printf (" %lx", val);
10344 puts ("");
10345 }
10346 }
10347 break;
10348
10349 case DT_PLTREL:
10350 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10351 if (do_dynamic)
10352 puts (get_dynamic_type (filedata, entry->d_un.d_val));
10353 break;
10354
10355 case DT_NULL :
10356 case DT_NEEDED :
10357 case DT_PLTGOT :
10358 case DT_HASH :
10359 case DT_STRTAB :
10360 case DT_SYMTAB :
10361 case DT_RELA :
10362 case DT_INIT :
10363 case DT_FINI :
10364 case DT_SONAME :
10365 case DT_RPATH :
10366 case DT_SYMBOLIC:
10367 case DT_REL :
10368 case DT_DEBUG :
10369 case DT_TEXTREL :
10370 case DT_JMPREL :
10371 case DT_RUNPATH :
10372 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10373
10374 if (do_dynamic)
10375 {
10376 char * name;
10377
10378 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
10379 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
10380 else
10381 name = NULL;
10382
10383 if (name)
10384 {
10385 switch (entry->d_tag)
10386 {
10387 case DT_NEEDED:
10388 printf (_("Shared library: [%s]"), name);
10389
10390 if (streq (name, program_interpreter))
10391 printf (_(" program interpreter"));
10392 break;
10393
10394 case DT_SONAME:
10395 printf (_("Library soname: [%s]"), name);
10396 break;
10397
10398 case DT_RPATH:
10399 printf (_("Library rpath: [%s]"), name);
10400 break;
10401
10402 case DT_RUNPATH:
10403 printf (_("Library runpath: [%s]"), name);
10404 break;
10405
10406 default:
10407 print_vma (entry->d_un.d_val, PREFIX_HEX);
10408 break;
10409 }
10410 }
10411 else
10412 print_vma (entry->d_un.d_val, PREFIX_HEX);
10413
10414 putchar ('\n');
10415 }
10416 break;
10417
10418 case DT_PLTRELSZ:
10419 case DT_RELASZ :
10420 case DT_STRSZ :
10421 case DT_RELSZ :
10422 case DT_RELAENT :
10423 case DT_SYMENT :
10424 case DT_RELENT :
10425 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10426 /* Fall through. */
10427 case DT_PLTPADSZ:
10428 case DT_MOVEENT :
10429 case DT_MOVESZ :
10430 case DT_INIT_ARRAYSZ:
10431 case DT_FINI_ARRAYSZ:
10432 case DT_GNU_CONFLICTSZ:
10433 case DT_GNU_LIBLISTSZ:
10434 if (do_dynamic)
10435 {
10436 print_vma (entry->d_un.d_val, UNSIGNED);
10437 printf (_(" (bytes)\n"));
10438 }
10439 break;
10440
10441 case DT_VERDEFNUM:
10442 case DT_VERNEEDNUM:
10443 case DT_RELACOUNT:
10444 case DT_RELCOUNT:
10445 if (do_dynamic)
10446 {
10447 print_vma (entry->d_un.d_val, UNSIGNED);
10448 putchar ('\n');
10449 }
10450 break;
10451
10452 case DT_SYMINSZ:
10453 case DT_SYMINENT:
10454 case DT_SYMINFO:
10455 case DT_USED:
10456 case DT_INIT_ARRAY:
10457 case DT_FINI_ARRAY:
10458 if (do_dynamic)
10459 {
10460 if (entry->d_tag == DT_USED
10461 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
10462 {
10463 char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
10464
10465 if (*name)
10466 {
10467 printf (_("Not needed object: [%s]\n"), name);
10468 break;
10469 }
10470 }
10471
10472 print_vma (entry->d_un.d_val, PREFIX_HEX);
10473 putchar ('\n');
10474 }
10475 break;
10476
10477 case DT_BIND_NOW:
10478 /* The value of this entry is ignored. */
10479 if (do_dynamic)
10480 putchar ('\n');
10481 break;
10482
10483 case DT_GNU_PRELINKED:
10484 if (do_dynamic)
10485 {
10486 struct tm * tmp;
10487 time_t atime = entry->d_un.d_val;
10488
10489 tmp = gmtime (&atime);
10490 /* PR 17533 file: 041-1244816-0.004. */
10491 if (tmp == NULL)
10492 printf (_("<corrupt time val: %lx"),
10493 (unsigned long) atime);
10494 else
10495 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
10496 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
10497 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
10498
10499 }
10500 break;
10501
10502 case DT_GNU_HASH:
10503 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
10504 if (do_dynamic)
10505 {
10506 print_vma (entry->d_un.d_val, PREFIX_HEX);
10507 putchar ('\n');
10508 }
10509 break;
10510
10511 default:
10512 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
10513 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
10514 entry->d_un.d_val;
10515
10516 if (do_dynamic)
10517 {
10518 switch (filedata->file_header.e_machine)
10519 {
10520 case EM_AARCH64:
10521 dynamic_section_aarch64_val (entry);
10522 break;
10523 case EM_MIPS:
10524 case EM_MIPS_RS3_LE:
10525 dynamic_section_mips_val (entry);
10526 break;
10527 case EM_PARISC:
10528 dynamic_section_parisc_val (entry);
10529 break;
10530 case EM_IA_64:
10531 dynamic_section_ia64_val (entry);
10532 break;
10533 default:
10534 print_vma (entry->d_un.d_val, PREFIX_HEX);
10535 putchar ('\n');
10536 }
10537 }
10538 break;
10539 }
10540 }
10541
10542 return TRUE;
10543 }
10544
10545 static char *
10546 get_ver_flags (unsigned int flags)
10547 {
10548 static char buff[128];
10549
10550 buff[0] = 0;
10551
10552 if (flags == 0)
10553 return _("none");
10554
10555 if (flags & VER_FLG_BASE)
10556 strcat (buff, "BASE");
10557
10558 if (flags & VER_FLG_WEAK)
10559 {
10560 if (flags & VER_FLG_BASE)
10561 strcat (buff, " | ");
10562
10563 strcat (buff, "WEAK");
10564 }
10565
10566 if (flags & VER_FLG_INFO)
10567 {
10568 if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
10569 strcat (buff, " | ");
10570
10571 strcat (buff, "INFO");
10572 }
10573
10574 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
10575 {
10576 if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
10577 strcat (buff, " | ");
10578
10579 strcat (buff, _("<unknown>"));
10580 }
10581
10582 return buff;
10583 }
10584
10585 /* Display the contents of the version sections. */
10586
10587 static bfd_boolean
10588 process_version_sections (Filedata * filedata)
10589 {
10590 Elf_Internal_Shdr * section;
10591 unsigned i;
10592 bfd_boolean found = FALSE;
10593
10594 if (! do_version)
10595 return TRUE;
10596
10597 for (i = 0, section = filedata->section_headers;
10598 i < filedata->file_header.e_shnum;
10599 i++, section++)
10600 {
10601 switch (section->sh_type)
10602 {
10603 case SHT_GNU_verdef:
10604 {
10605 Elf_External_Verdef * edefs;
10606 unsigned long idx;
10607 unsigned long cnt;
10608 char * endbuf;
10609
10610 found = TRUE;
10611
10612 printf (ngettext ("\nVersion definition section '%s' "
10613 "contains %u entry:\n",
10614 "\nVersion definition section '%s' "
10615 "contains %u entries:\n",
10616 section->sh_info),
10617 printable_section_name (filedata, section),
10618 section->sh_info);
10619
10620 printf (_(" Addr: 0x"));
10621 printf_vma (section->sh_addr);
10622 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10623 (unsigned long) section->sh_offset, section->sh_link,
10624 printable_section_name_from_index (filedata, section->sh_link));
10625
10626 edefs = (Elf_External_Verdef *)
10627 get_data (NULL, filedata, section->sh_offset, 1,section->sh_size,
10628 _("version definition section"));
10629 if (!edefs)
10630 break;
10631 endbuf = (char *) edefs + section->sh_size;
10632
10633 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
10634 {
10635 char * vstart;
10636 Elf_External_Verdef * edef;
10637 Elf_Internal_Verdef ent;
10638 Elf_External_Verdaux * eaux;
10639 Elf_Internal_Verdaux aux;
10640 unsigned long isum;
10641 int j;
10642
10643 vstart = ((char *) edefs) + idx;
10644 if (vstart + sizeof (*edef) > endbuf)
10645 break;
10646
10647 edef = (Elf_External_Verdef *) vstart;
10648
10649 ent.vd_version = BYTE_GET (edef->vd_version);
10650 ent.vd_flags = BYTE_GET (edef->vd_flags);
10651 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
10652 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
10653 ent.vd_hash = BYTE_GET (edef->vd_hash);
10654 ent.vd_aux = BYTE_GET (edef->vd_aux);
10655 ent.vd_next = BYTE_GET (edef->vd_next);
10656
10657 printf (_(" %#06lx: Rev: %d Flags: %s"),
10658 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
10659
10660 printf (_(" Index: %d Cnt: %d "),
10661 ent.vd_ndx, ent.vd_cnt);
10662
10663 /* Check for overflow. */
10664 if (ent.vd_aux > (size_t) (endbuf - vstart))
10665 break;
10666
10667 vstart += ent.vd_aux;
10668
10669 if (vstart + sizeof (*eaux) > endbuf)
10670 break;
10671 eaux = (Elf_External_Verdaux *) vstart;
10672
10673 aux.vda_name = BYTE_GET (eaux->vda_name);
10674 aux.vda_next = BYTE_GET (eaux->vda_next);
10675
10676 if (VALID_DYNAMIC_NAME (aux.vda_name))
10677 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
10678 else
10679 printf (_("Name index: %ld\n"), aux.vda_name);
10680
10681 isum = idx + ent.vd_aux;
10682
10683 for (j = 1; j < ent.vd_cnt; j++)
10684 {
10685 if (aux.vda_next < sizeof (*eaux)
10686 && !(j == ent.vd_cnt - 1 && aux.vda_next == 0))
10687 {
10688 warn (_("Invalid vda_next field of %lx\n"),
10689 aux.vda_next);
10690 j = ent.vd_cnt;
10691 break;
10692 }
10693 /* Check for overflow. */
10694 if (aux.vda_next > (size_t) (endbuf - vstart))
10695 break;
10696
10697 isum += aux.vda_next;
10698 vstart += aux.vda_next;
10699
10700 if (vstart + sizeof (*eaux) > endbuf)
10701 break;
10702 eaux = (Elf_External_Verdaux *) vstart;
10703
10704 aux.vda_name = BYTE_GET (eaux->vda_name);
10705 aux.vda_next = BYTE_GET (eaux->vda_next);
10706
10707 if (VALID_DYNAMIC_NAME (aux.vda_name))
10708 printf (_(" %#06lx: Parent %d: %s\n"),
10709 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
10710 else
10711 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
10712 isum, j, aux.vda_name);
10713 }
10714
10715 if (j < ent.vd_cnt)
10716 printf (_(" Version def aux past end of section\n"));
10717
10718 /* PR 17531:
10719 file: id:000001,src:000172+005151,op:splice,rep:2. */
10720 if (ent.vd_next < sizeof (*edef)
10721 && !(cnt == section->sh_info - 1 && ent.vd_next == 0))
10722 {
10723 warn (_("Invalid vd_next field of %lx\n"), ent.vd_next);
10724 cnt = section->sh_info;
10725 break;
10726 }
10727 if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx)))
10728 break;
10729
10730 idx += ent.vd_next;
10731 }
10732
10733 if (cnt < section->sh_info)
10734 printf (_(" Version definition past end of section\n"));
10735
10736 free (edefs);
10737 }
10738 break;
10739
10740 case SHT_GNU_verneed:
10741 {
10742 Elf_External_Verneed * eneed;
10743 unsigned long idx;
10744 unsigned long cnt;
10745 char * endbuf;
10746
10747 found = TRUE;
10748
10749 printf (ngettext ("\nVersion needs section '%s' "
10750 "contains %u entry:\n",
10751 "\nVersion needs section '%s' "
10752 "contains %u entries:\n",
10753 section->sh_info),
10754 printable_section_name (filedata, section), section->sh_info);
10755
10756 printf (_(" Addr: 0x"));
10757 printf_vma (section->sh_addr);
10758 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10759 (unsigned long) section->sh_offset, section->sh_link,
10760 printable_section_name_from_index (filedata, section->sh_link));
10761
10762 eneed = (Elf_External_Verneed *) get_data (NULL, filedata,
10763 section->sh_offset, 1,
10764 section->sh_size,
10765 _("Version Needs section"));
10766 if (!eneed)
10767 break;
10768 endbuf = (char *) eneed + section->sh_size;
10769
10770 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
10771 {
10772 Elf_External_Verneed * entry;
10773 Elf_Internal_Verneed ent;
10774 unsigned long isum;
10775 int j;
10776 char * vstart;
10777
10778 vstart = ((char *) eneed) + idx;
10779 if (vstart + sizeof (*entry) > endbuf)
10780 break;
10781
10782 entry = (Elf_External_Verneed *) vstart;
10783
10784 ent.vn_version = BYTE_GET (entry->vn_version);
10785 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
10786 ent.vn_file = BYTE_GET (entry->vn_file);
10787 ent.vn_aux = BYTE_GET (entry->vn_aux);
10788 ent.vn_next = BYTE_GET (entry->vn_next);
10789
10790 printf (_(" %#06lx: Version: %d"), idx, ent.vn_version);
10791
10792 if (VALID_DYNAMIC_NAME (ent.vn_file))
10793 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
10794 else
10795 printf (_(" File: %lx"), ent.vn_file);
10796
10797 printf (_(" Cnt: %d\n"), ent.vn_cnt);
10798
10799 /* Check for overflow. */
10800 if (ent.vn_aux > (size_t) (endbuf - vstart))
10801 break;
10802 vstart += ent.vn_aux;
10803
10804 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
10805 {
10806 Elf_External_Vernaux * eaux;
10807 Elf_Internal_Vernaux aux;
10808
10809 if (vstart + sizeof (*eaux) > endbuf)
10810 break;
10811 eaux = (Elf_External_Vernaux *) vstart;
10812
10813 aux.vna_hash = BYTE_GET (eaux->vna_hash);
10814 aux.vna_flags = BYTE_GET (eaux->vna_flags);
10815 aux.vna_other = BYTE_GET (eaux->vna_other);
10816 aux.vna_name = BYTE_GET (eaux->vna_name);
10817 aux.vna_next = BYTE_GET (eaux->vna_next);
10818
10819 if (VALID_DYNAMIC_NAME (aux.vna_name))
10820 printf (_(" %#06lx: Name: %s"),
10821 isum, GET_DYNAMIC_NAME (aux.vna_name));
10822 else
10823 printf (_(" %#06lx: Name index: %lx"),
10824 isum, aux.vna_name);
10825
10826 printf (_(" Flags: %s Version: %d\n"),
10827 get_ver_flags (aux.vna_flags), aux.vna_other);
10828
10829 if (aux.vna_next < sizeof (*eaux)
10830 && !(j == ent.vn_cnt - 1 && aux.vna_next == 0))
10831 {
10832 warn (_("Invalid vna_next field of %lx\n"),
10833 aux.vna_next);
10834 j = ent.vn_cnt;
10835 break;
10836 }
10837 /* Check for overflow. */
10838 if (aux.vna_next > (size_t) (endbuf - vstart))
10839 break;
10840 isum += aux.vna_next;
10841 vstart += aux.vna_next;
10842 }
10843
10844 if (j < ent.vn_cnt)
10845 warn (_("Missing Version Needs auxillary information\n"));
10846
10847 if (ent.vn_next < sizeof (*entry)
10848 && !(cnt == section->sh_info - 1 && ent.vn_next == 0))
10849 {
10850 warn (_("Invalid vn_next field of %lx\n"), ent.vn_next);
10851 cnt = section->sh_info;
10852 break;
10853 }
10854 if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx)))
10855 break;
10856 idx += ent.vn_next;
10857 }
10858
10859 if (cnt < section->sh_info)
10860 warn (_("Missing Version Needs information\n"));
10861
10862 free (eneed);
10863 }
10864 break;
10865
10866 case SHT_GNU_versym:
10867 {
10868 Elf_Internal_Shdr * link_section;
10869 size_t total;
10870 unsigned int cnt;
10871 unsigned char * edata;
10872 unsigned short * data;
10873 char * strtab;
10874 Elf_Internal_Sym * symbols;
10875 Elf_Internal_Shdr * string_sec;
10876 unsigned long num_syms;
10877 long off;
10878
10879 if (section->sh_link >= filedata->file_header.e_shnum)
10880 break;
10881
10882 link_section = filedata->section_headers + section->sh_link;
10883 total = section->sh_size / sizeof (Elf_External_Versym);
10884
10885 if (link_section->sh_link >= filedata->file_header.e_shnum)
10886 break;
10887
10888 found = TRUE;
10889
10890 symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms);
10891 if (symbols == NULL)
10892 break;
10893
10894 string_sec = filedata->section_headers + link_section->sh_link;
10895
10896 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
10897 string_sec->sh_size,
10898 _("version string table"));
10899 if (!strtab)
10900 {
10901 free (symbols);
10902 break;
10903 }
10904
10905 printf (ngettext ("\nVersion symbols section '%s' "
10906 "contains %lu entry:\n",
10907 "\nVersion symbols section '%s' "
10908 "contains %lu entries:\n",
10909 total),
10910 printable_section_name (filedata, section), (unsigned long) total);
10911
10912 printf (_(" Addr: 0x"));
10913 printf_vma (section->sh_addr);
10914 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10915 (unsigned long) section->sh_offset, section->sh_link,
10916 printable_section_name (filedata, link_section));
10917
10918 off = offset_from_vma (filedata,
10919 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
10920 total * sizeof (short));
10921 edata = (unsigned char *) get_data (NULL, filedata, off, total,
10922 sizeof (short),
10923 _("version symbol data"));
10924 if (!edata)
10925 {
10926 free (strtab);
10927 free (symbols);
10928 break;
10929 }
10930
10931 data = (short unsigned int *) cmalloc (total, sizeof (short));
10932
10933 for (cnt = total; cnt --;)
10934 data[cnt] = byte_get (edata + cnt * sizeof (short),
10935 sizeof (short));
10936
10937 free (edata);
10938
10939 for (cnt = 0; cnt < total; cnt += 4)
10940 {
10941 int j, nn;
10942 char *name;
10943 char *invalid = _("*invalid*");
10944
10945 printf (" %03x:", cnt);
10946
10947 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
10948 switch (data[cnt + j])
10949 {
10950 case 0:
10951 fputs (_(" 0 (*local*) "), stdout);
10952 break;
10953
10954 case 1:
10955 fputs (_(" 1 (*global*) "), stdout);
10956 break;
10957
10958 default:
10959 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
10960 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
10961
10962 /* If this index value is greater than the size of the symbols
10963 array, break to avoid an out-of-bounds read. */
10964 if ((unsigned long)(cnt + j) >= num_syms)
10965 {
10966 warn (_("invalid index into symbol array\n"));
10967 break;
10968 }
10969
10970 name = NULL;
10971 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
10972 {
10973 Elf_Internal_Verneed ivn;
10974 unsigned long offset;
10975
10976 offset = offset_from_vma
10977 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
10978 sizeof (Elf_External_Verneed));
10979
10980 do
10981 {
10982 Elf_Internal_Vernaux ivna;
10983 Elf_External_Verneed evn;
10984 Elf_External_Vernaux evna;
10985 unsigned long a_off;
10986
10987 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
10988 _("version need")) == NULL)
10989 break;
10990
10991 ivn.vn_aux = BYTE_GET (evn.vn_aux);
10992 ivn.vn_next = BYTE_GET (evn.vn_next);
10993
10994 a_off = offset + ivn.vn_aux;
10995
10996 do
10997 {
10998 if (get_data (&evna, filedata, a_off, sizeof (evna),
10999 1, _("version need aux (2)")) == NULL)
11000 {
11001 ivna.vna_next = 0;
11002 ivna.vna_other = 0;
11003 }
11004 else
11005 {
11006 ivna.vna_next = BYTE_GET (evna.vna_next);
11007 ivna.vna_other = BYTE_GET (evna.vna_other);
11008 }
11009
11010 a_off += ivna.vna_next;
11011 }
11012 while (ivna.vna_other != data[cnt + j]
11013 && ivna.vna_next != 0);
11014
11015 if (ivna.vna_other == data[cnt + j])
11016 {
11017 ivna.vna_name = BYTE_GET (evna.vna_name);
11018
11019 if (ivna.vna_name >= string_sec->sh_size)
11020 name = invalid;
11021 else
11022 name = strtab + ivna.vna_name;
11023 break;
11024 }
11025
11026 offset += ivn.vn_next;
11027 }
11028 while (ivn.vn_next);
11029 }
11030
11031 if (data[cnt + j] != 0x8001
11032 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
11033 {
11034 Elf_Internal_Verdef ivd;
11035 Elf_External_Verdef evd;
11036 unsigned long offset;
11037
11038 offset = offset_from_vma
11039 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
11040 sizeof evd);
11041
11042 do
11043 {
11044 if (get_data (&evd, filedata, offset, sizeof (evd), 1,
11045 _("version def")) == NULL)
11046 {
11047 ivd.vd_next = 0;
11048 /* PR 17531: file: 046-1082287-0.004. */
11049 ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
11050 break;
11051 }
11052 else
11053 {
11054 ivd.vd_next = BYTE_GET (evd.vd_next);
11055 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
11056 }
11057
11058 offset += ivd.vd_next;
11059 }
11060 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
11061 && ivd.vd_next != 0);
11062
11063 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
11064 {
11065 Elf_External_Verdaux evda;
11066 Elf_Internal_Verdaux ivda;
11067
11068 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11069
11070 if (get_data (&evda, filedata,
11071 offset - ivd.vd_next + ivd.vd_aux,
11072 sizeof (evda), 1,
11073 _("version def aux")) == NULL)
11074 break;
11075
11076 ivda.vda_name = BYTE_GET (evda.vda_name);
11077
11078 if (ivda.vda_name >= string_sec->sh_size)
11079 name = invalid;
11080 else if (name != NULL && name != invalid)
11081 name = _("*both*");
11082 else
11083 name = strtab + ivda.vda_name;
11084 }
11085 }
11086 if (name != NULL)
11087 nn += printf ("(%s%-*s",
11088 name,
11089 12 - (int) strlen (name),
11090 ")");
11091
11092 if (nn < 18)
11093 printf ("%*c", 18 - nn, ' ');
11094 }
11095
11096 putchar ('\n');
11097 }
11098
11099 free (data);
11100 free (strtab);
11101 free (symbols);
11102 }
11103 break;
11104
11105 default:
11106 break;
11107 }
11108 }
11109
11110 if (! found)
11111 printf (_("\nNo version information found in this file.\n"));
11112
11113 return TRUE;
11114 }
11115
11116 static const char *
11117 get_symbol_binding (Filedata * filedata, unsigned int binding)
11118 {
11119 static char buff[32];
11120
11121 switch (binding)
11122 {
11123 case STB_LOCAL: return "LOCAL";
11124 case STB_GLOBAL: return "GLOBAL";
11125 case STB_WEAK: return "WEAK";
11126 default:
11127 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
11128 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
11129 binding);
11130 else if (binding >= STB_LOOS && binding <= STB_HIOS)
11131 {
11132 if (binding == STB_GNU_UNIQUE
11133 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU)
11134 return "UNIQUE";
11135 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
11136 }
11137 else
11138 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
11139 return buff;
11140 }
11141 }
11142
11143 static const char *
11144 get_symbol_type (Filedata * filedata, unsigned int type)
11145 {
11146 static char buff[32];
11147
11148 switch (type)
11149 {
11150 case STT_NOTYPE: return "NOTYPE";
11151 case STT_OBJECT: return "OBJECT";
11152 case STT_FUNC: return "FUNC";
11153 case STT_SECTION: return "SECTION";
11154 case STT_FILE: return "FILE";
11155 case STT_COMMON: return "COMMON";
11156 case STT_TLS: return "TLS";
11157 case STT_RELC: return "RELC";
11158 case STT_SRELC: return "SRELC";
11159 default:
11160 if (type >= STT_LOPROC && type <= STT_HIPROC)
11161 {
11162 if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
11163 return "THUMB_FUNC";
11164
11165 if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
11166 return "REGISTER";
11167
11168 if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
11169 return "PARISC_MILLI";
11170
11171 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
11172 }
11173 else if (type >= STT_LOOS && type <= STT_HIOS)
11174 {
11175 if (filedata->file_header.e_machine == EM_PARISC)
11176 {
11177 if (type == STT_HP_OPAQUE)
11178 return "HP_OPAQUE";
11179 if (type == STT_HP_STUB)
11180 return "HP_STUB";
11181 }
11182
11183 if (type == STT_GNU_IFUNC
11184 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
11185 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD))
11186 return "IFUNC";
11187
11188 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
11189 }
11190 else
11191 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
11192 return buff;
11193 }
11194 }
11195
11196 static const char *
11197 get_symbol_visibility (unsigned int visibility)
11198 {
11199 switch (visibility)
11200 {
11201 case STV_DEFAULT: return "DEFAULT";
11202 case STV_INTERNAL: return "INTERNAL";
11203 case STV_HIDDEN: return "HIDDEN";
11204 case STV_PROTECTED: return "PROTECTED";
11205 default:
11206 error (_("Unrecognized visibility value: %u"), visibility);
11207 return _("<unknown>");
11208 }
11209 }
11210
11211 static const char *
11212 get_alpha_symbol_other (unsigned int other)
11213 {
11214 switch (other)
11215 {
11216 case STO_ALPHA_NOPV: return "NOPV";
11217 case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD";
11218 default:
11219 error (_("Unrecognized alpah specific other value: %u"), other);
11220 return _("<unknown>");
11221 }
11222 }
11223
11224 static const char *
11225 get_solaris_symbol_visibility (unsigned int visibility)
11226 {
11227 switch (visibility)
11228 {
11229 case 4: return "EXPORTED";
11230 case 5: return "SINGLETON";
11231 case 6: return "ELIMINATE";
11232 default: return get_symbol_visibility (visibility);
11233 }
11234 }
11235
11236 static const char *
11237 get_aarch64_symbol_other (unsigned int other)
11238 {
11239 static char buf[32];
11240
11241 if (other & STO_AARCH64_VARIANT_PCS)
11242 {
11243 other &= ~STO_AARCH64_VARIANT_PCS;
11244 if (other == 0)
11245 return "VARIANT_PCS";
11246 snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other);
11247 return buf;
11248 }
11249 return NULL;
11250 }
11251
11252 static const char *
11253 get_mips_symbol_other (unsigned int other)
11254 {
11255 switch (other)
11256 {
11257 case STO_OPTIONAL: return "OPTIONAL";
11258 case STO_MIPS_PLT: return "MIPS PLT";
11259 case STO_MIPS_PIC: return "MIPS PIC";
11260 case STO_MICROMIPS: return "MICROMIPS";
11261 case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC";
11262 case STO_MIPS16: return "MIPS16";
11263 default: return NULL;
11264 }
11265 }
11266
11267 static const char *
11268 get_ia64_symbol_other (Filedata * filedata, unsigned int other)
11269 {
11270 if (is_ia64_vms (filedata))
11271 {
11272 static char res[32];
11273
11274 res[0] = 0;
11275
11276 /* Function types is for images and .STB files only. */
11277 switch (filedata->file_header.e_type)
11278 {
11279 case ET_DYN:
11280 case ET_EXEC:
11281 switch (VMS_ST_FUNC_TYPE (other))
11282 {
11283 case VMS_SFT_CODE_ADDR:
11284 strcat (res, " CA");
11285 break;
11286 case VMS_SFT_SYMV_IDX:
11287 strcat (res, " VEC");
11288 break;
11289 case VMS_SFT_FD:
11290 strcat (res, " FD");
11291 break;
11292 case VMS_SFT_RESERVE:
11293 strcat (res, " RSV");
11294 break;
11295 default:
11296 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
11297 VMS_ST_FUNC_TYPE (other));
11298 strcat (res, " <unknown>");
11299 break;
11300 }
11301 break;
11302 default:
11303 break;
11304 }
11305 switch (VMS_ST_LINKAGE (other))
11306 {
11307 case VMS_STL_IGNORE:
11308 strcat (res, " IGN");
11309 break;
11310 case VMS_STL_RESERVE:
11311 strcat (res, " RSV");
11312 break;
11313 case VMS_STL_STD:
11314 strcat (res, " STD");
11315 break;
11316 case VMS_STL_LNK:
11317 strcat (res, " LNK");
11318 break;
11319 default:
11320 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
11321 VMS_ST_LINKAGE (other));
11322 strcat (res, " <unknown>");
11323 break;
11324 }
11325
11326 if (res[0] != 0)
11327 return res + 1;
11328 else
11329 return res;
11330 }
11331 return NULL;
11332 }
11333
11334 static const char *
11335 get_ppc64_symbol_other (unsigned int other)
11336 {
11337 if ((other & ~STO_PPC64_LOCAL_MASK) != 0)
11338 return NULL;
11339
11340 other >>= STO_PPC64_LOCAL_BIT;
11341 if (other <= 6)
11342 {
11343 static char buf[32];
11344 if (other >= 2)
11345 other = ppc64_decode_local_entry (other);
11346 snprintf (buf, sizeof buf, _("<localentry>: %d"), other);
11347 return buf;
11348 }
11349 return NULL;
11350 }
11351
11352 static const char *
11353 get_symbol_other (Filedata * filedata, unsigned int other)
11354 {
11355 const char * result = NULL;
11356 static char buff [32];
11357
11358 if (other == 0)
11359 return "";
11360
11361 switch (filedata->file_header.e_machine)
11362 {
11363 case EM_ALPHA:
11364 result = get_alpha_symbol_other (other);
11365 break;
11366 case EM_AARCH64:
11367 result = get_aarch64_symbol_other (other);
11368 break;
11369 case EM_MIPS:
11370 result = get_mips_symbol_other (other);
11371 break;
11372 case EM_IA_64:
11373 result = get_ia64_symbol_other (filedata, other);
11374 break;
11375 case EM_PPC64:
11376 result = get_ppc64_symbol_other (other);
11377 break;
11378 default:
11379 result = NULL;
11380 break;
11381 }
11382
11383 if (result)
11384 return result;
11385
11386 snprintf (buff, sizeof buff, _("<other>: %x"), other);
11387 return buff;
11388 }
11389
11390 static const char *
11391 get_symbol_index_type (Filedata * filedata, unsigned int type)
11392 {
11393 static char buff[32];
11394
11395 switch (type)
11396 {
11397 case SHN_UNDEF: return "UND";
11398 case SHN_ABS: return "ABS";
11399 case SHN_COMMON: return "COM";
11400 default:
11401 if (type == SHN_IA_64_ANSI_COMMON
11402 && filedata->file_header.e_machine == EM_IA_64
11403 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
11404 return "ANSI_COM";
11405 else if ((filedata->file_header.e_machine == EM_X86_64
11406 || filedata->file_header.e_machine == EM_L1OM
11407 || filedata->file_header.e_machine == EM_K1OM)
11408 && type == SHN_X86_64_LCOMMON)
11409 return "LARGE_COM";
11410 else if ((type == SHN_MIPS_SCOMMON
11411 && filedata->file_header.e_machine == EM_MIPS)
11412 || (type == SHN_TIC6X_SCOMMON
11413 && filedata->file_header.e_machine == EM_TI_C6000))
11414 return "SCOM";
11415 else if (type == SHN_MIPS_SUNDEFINED
11416 && filedata->file_header.e_machine == EM_MIPS)
11417 return "SUND";
11418 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
11419 sprintf (buff, "PRC[0x%04x]", type & 0xffff);
11420 else if (type >= SHN_LOOS && type <= SHN_HIOS)
11421 sprintf (buff, "OS [0x%04x]", type & 0xffff);
11422 else if (type >= SHN_LORESERVE)
11423 sprintf (buff, "RSV[0x%04x]", type & 0xffff);
11424 else if (type >= filedata->file_header.e_shnum)
11425 sprintf (buff, _("bad section index[%3d]"), type);
11426 else
11427 sprintf (buff, "%3d", type);
11428 break;
11429 }
11430
11431 return buff;
11432 }
11433
11434 static bfd_vma *
11435 get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size)
11436 {
11437 unsigned char * e_data;
11438 bfd_vma * i_data;
11439
11440 /* If the size_t type is smaller than the bfd_size_type, eg because
11441 you are building a 32-bit tool on a 64-bit host, then make sure
11442 that when (number) is cast to (size_t) no information is lost. */
11443 if (sizeof (size_t) < sizeof (bfd_size_type)
11444 && (bfd_size_type) ((size_t) number) != number)
11445 {
11446 error (_("Size truncation prevents reading %s elements of size %u\n"),
11447 bfd_vmatoa ("u", number), ent_size);
11448 return NULL;
11449 }
11450
11451 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
11452 attempting to allocate memory when the read is bound to fail. */
11453 if (ent_size * number > filedata->file_size)
11454 {
11455 error (_("Invalid number of dynamic entries: %s\n"),
11456 bfd_vmatoa ("u", number));
11457 return NULL;
11458 }
11459
11460 e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
11461 if (e_data == NULL)
11462 {
11463 error (_("Out of memory reading %s dynamic entries\n"),
11464 bfd_vmatoa ("u", number));
11465 return NULL;
11466 }
11467
11468 if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number)
11469 {
11470 error (_("Unable to read in %s bytes of dynamic data\n"),
11471 bfd_vmatoa ("u", number * ent_size));
11472 free (e_data);
11473 return NULL;
11474 }
11475
11476 i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
11477 if (i_data == NULL)
11478 {
11479 error (_("Out of memory allocating space for %s dynamic entries\n"),
11480 bfd_vmatoa ("u", number));
11481 free (e_data);
11482 return NULL;
11483 }
11484
11485 while (number--)
11486 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
11487
11488 free (e_data);
11489
11490 return i_data;
11491 }
11492
11493 static void
11494 print_dynamic_symbol (Filedata * filedata, bfd_vma si, unsigned long hn)
11495 {
11496 Elf_Internal_Sym * psym;
11497 int n;
11498
11499 n = print_vma (si, DEC_5);
11500 if (n < 5)
11501 fputs (&" "[n], stdout);
11502 printf (" %3lu: ", hn);
11503
11504 if (dynamic_symbols == NULL || si >= num_dynamic_syms)
11505 {
11506 printf (_("<No info available for dynamic symbol number %lu>\n"),
11507 (unsigned long) si);
11508 return;
11509 }
11510
11511 psym = dynamic_symbols + si;
11512 print_vma (psym->st_value, LONG_HEX);
11513 putchar (' ');
11514 print_vma (psym->st_size, DEC_5);
11515
11516 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
11517 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
11518
11519 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
11520 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
11521 else
11522 {
11523 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
11524
11525 printf (" %-7s", get_symbol_visibility (vis));
11526 /* Check to see if any other bits in the st_other field are set.
11527 Note - displaying this information disrupts the layout of the
11528 table being generated, but for the moment this case is very
11529 rare. */
11530 if (psym->st_other ^ vis)
11531 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
11532 }
11533
11534 printf (" %3.3s ", get_symbol_index_type (filedata, psym->st_shndx));
11535 if (VALID_DYNAMIC_NAME (psym->st_name))
11536 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
11537 else
11538 printf (_(" <corrupt: %14ld>"), psym->st_name);
11539 putchar ('\n');
11540 }
11541
11542 static const char *
11543 get_symbol_version_string (Filedata * filedata,
11544 bfd_boolean is_dynsym,
11545 const char * strtab,
11546 unsigned long int strtab_size,
11547 unsigned int si,
11548 Elf_Internal_Sym * psym,
11549 enum versioned_symbol_info * sym_info,
11550 unsigned short * vna_other)
11551 {
11552 unsigned char data[2];
11553 unsigned short vers_data;
11554 unsigned long offset;
11555 unsigned short max_vd_ndx;
11556
11557 if (!is_dynsym
11558 || version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
11559 return NULL;
11560
11561 offset = offset_from_vma (filedata, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
11562 sizeof data + si * sizeof (vers_data));
11563
11564 if (get_data (&data, filedata, offset + si * sizeof (vers_data),
11565 sizeof (data), 1, _("version data")) == NULL)
11566 return NULL;
11567
11568 vers_data = byte_get (data, 2);
11569
11570 if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0)
11571 return NULL;
11572
11573 *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public;
11574 max_vd_ndx = 0;
11575
11576 /* Usually we'd only see verdef for defined symbols, and verneed for
11577 undefined symbols. However, symbols defined by the linker in
11578 .dynbss for variables copied from a shared library in order to
11579 avoid text relocations are defined yet have verneed. We could
11580 use a heuristic to detect the special case, for example, check
11581 for verneed first on symbols defined in SHT_NOBITS sections, but
11582 it is simpler and more reliable to just look for both verdef and
11583 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
11584
11585 if (psym->st_shndx != SHN_UNDEF
11586 && vers_data != 0x8001
11587 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
11588 {
11589 Elf_Internal_Verdef ivd;
11590 Elf_Internal_Verdaux ivda;
11591 Elf_External_Verdaux evda;
11592 unsigned long off;
11593
11594 off = offset_from_vma (filedata,
11595 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
11596 sizeof (Elf_External_Verdef));
11597
11598 do
11599 {
11600 Elf_External_Verdef evd;
11601
11602 if (get_data (&evd, filedata, off, sizeof (evd), 1,
11603 _("version def")) == NULL)
11604 {
11605 ivd.vd_ndx = 0;
11606 ivd.vd_aux = 0;
11607 ivd.vd_next = 0;
11608 ivd.vd_flags = 0;
11609 }
11610 else
11611 {
11612 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
11613 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11614 ivd.vd_next = BYTE_GET (evd.vd_next);
11615 ivd.vd_flags = BYTE_GET (evd.vd_flags);
11616 }
11617
11618 if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx)
11619 max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION;
11620
11621 off += ivd.vd_next;
11622 }
11623 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
11624
11625 if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
11626 {
11627 if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE)
11628 return NULL;
11629
11630 off -= ivd.vd_next;
11631 off += ivd.vd_aux;
11632
11633 if (get_data (&evda, filedata, off, sizeof (evda), 1,
11634 _("version def aux")) != NULL)
11635 {
11636 ivda.vda_name = BYTE_GET (evda.vda_name);
11637
11638 if (psym->st_name != ivda.vda_name)
11639 return (ivda.vda_name < strtab_size
11640 ? strtab + ivda.vda_name : _("<corrupt>"));
11641 }
11642 }
11643 }
11644
11645 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
11646 {
11647 Elf_External_Verneed evn;
11648 Elf_Internal_Verneed ivn;
11649 Elf_Internal_Vernaux ivna;
11650
11651 offset = offset_from_vma (filedata,
11652 version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
11653 sizeof evn);
11654 do
11655 {
11656 unsigned long vna_off;
11657
11658 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
11659 _("version need")) == NULL)
11660 {
11661 ivna.vna_next = 0;
11662 ivna.vna_other = 0;
11663 ivna.vna_name = 0;
11664 break;
11665 }
11666
11667 ivn.vn_aux = BYTE_GET (evn.vn_aux);
11668 ivn.vn_next = BYTE_GET (evn.vn_next);
11669
11670 vna_off = offset + ivn.vn_aux;
11671
11672 do
11673 {
11674 Elf_External_Vernaux evna;
11675
11676 if (get_data (&evna, filedata, vna_off, sizeof (evna), 1,
11677 _("version need aux (3)")) == NULL)
11678 {
11679 ivna.vna_next = 0;
11680 ivna.vna_other = 0;
11681 ivna.vna_name = 0;
11682 }
11683 else
11684 {
11685 ivna.vna_other = BYTE_GET (evna.vna_other);
11686 ivna.vna_next = BYTE_GET (evna.vna_next);
11687 ivna.vna_name = BYTE_GET (evna.vna_name);
11688 }
11689
11690 vna_off += ivna.vna_next;
11691 }
11692 while (ivna.vna_other != vers_data && ivna.vna_next != 0);
11693
11694 if (ivna.vna_other == vers_data)
11695 break;
11696
11697 offset += ivn.vn_next;
11698 }
11699 while (ivn.vn_next != 0);
11700
11701 if (ivna.vna_other == vers_data)
11702 {
11703 *sym_info = symbol_undefined;
11704 *vna_other = ivna.vna_other;
11705 return (ivna.vna_name < strtab_size
11706 ? strtab + ivna.vna_name : _("<corrupt>"));
11707 }
11708 else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1)
11709 && (vers_data & VERSYM_VERSION) > max_vd_ndx)
11710 return _("<corrupt>");
11711 }
11712 return NULL;
11713 }
11714
11715 /* Dump the symbol table. */
11716 static bfd_boolean
11717 process_symbol_table (Filedata * filedata)
11718 {
11719 Elf_Internal_Shdr * section;
11720 bfd_size_type nbuckets = 0;
11721 bfd_size_type nchains = 0;
11722 bfd_vma * buckets = NULL;
11723 bfd_vma * chains = NULL;
11724 bfd_vma ngnubuckets = 0;
11725 bfd_vma * gnubuckets = NULL;
11726 bfd_vma * gnuchains = NULL;
11727 bfd_vma * mipsxlat = NULL;
11728 bfd_vma gnusymidx = 0;
11729 bfd_size_type ngnuchains = 0;
11730
11731 if (!do_syms && !do_dyn_syms && !do_histogram)
11732 return TRUE;
11733
11734 if (dynamic_info[DT_HASH]
11735 && (do_histogram
11736 || (do_using_dynamic
11737 && !do_dyn_syms
11738 && dynamic_strings != NULL)))
11739 {
11740 unsigned char nb[8];
11741 unsigned char nc[8];
11742 unsigned int hash_ent_size = 4;
11743
11744 if ((filedata->file_header.e_machine == EM_ALPHA
11745 || filedata->file_header.e_machine == EM_S390
11746 || filedata->file_header.e_machine == EM_S390_OLD)
11747 && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64)
11748 hash_ent_size = 8;
11749
11750 if (fseek (filedata->handle,
11751 (archive_file_offset
11752 + offset_from_vma (filedata, dynamic_info[DT_HASH],
11753 sizeof nb + sizeof nc)),
11754 SEEK_SET))
11755 {
11756 error (_("Unable to seek to start of dynamic information\n"));
11757 goto no_hash;
11758 }
11759
11760 if (fread (nb, hash_ent_size, 1, filedata->handle) != 1)
11761 {
11762 error (_("Failed to read in number of buckets\n"));
11763 goto no_hash;
11764 }
11765
11766 if (fread (nc, hash_ent_size, 1, filedata->handle) != 1)
11767 {
11768 error (_("Failed to read in number of chains\n"));
11769 goto no_hash;
11770 }
11771
11772 nbuckets = byte_get (nb, hash_ent_size);
11773 nchains = byte_get (nc, hash_ent_size);
11774
11775 buckets = get_dynamic_data (filedata, nbuckets, hash_ent_size);
11776 chains = get_dynamic_data (filedata, nchains, hash_ent_size);
11777
11778 no_hash:
11779 if (buckets == NULL || chains == NULL)
11780 {
11781 if (do_using_dynamic)
11782 return FALSE;
11783 free (buckets);
11784 free (chains);
11785 buckets = NULL;
11786 chains = NULL;
11787 nbuckets = 0;
11788 nchains = 0;
11789 }
11790 }
11791
11792 if (dynamic_info_DT_GNU_HASH
11793 && (do_histogram
11794 || (do_using_dynamic
11795 && !do_dyn_syms
11796 && dynamic_strings != NULL)))
11797 {
11798 unsigned char nb[16];
11799 bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
11800 bfd_vma buckets_vma;
11801
11802 if (fseek (filedata->handle,
11803 (archive_file_offset
11804 + offset_from_vma (filedata, dynamic_info_DT_GNU_HASH,
11805 sizeof nb)),
11806 SEEK_SET))
11807 {
11808 error (_("Unable to seek to start of dynamic information\n"));
11809 goto no_gnu_hash;
11810 }
11811
11812 if (fread (nb, 16, 1, filedata->handle) != 1)
11813 {
11814 error (_("Failed to read in number of buckets\n"));
11815 goto no_gnu_hash;
11816 }
11817
11818 ngnubuckets = byte_get (nb, 4);
11819 gnusymidx = byte_get (nb + 4, 4);
11820 bitmaskwords = byte_get (nb + 8, 4);
11821 buckets_vma = dynamic_info_DT_GNU_HASH + 16;
11822 if (is_32bit_elf)
11823 buckets_vma += bitmaskwords * 4;
11824 else
11825 buckets_vma += bitmaskwords * 8;
11826
11827 if (fseek (filedata->handle,
11828 (archive_file_offset
11829 + offset_from_vma (filedata, buckets_vma, 4)),
11830 SEEK_SET))
11831 {
11832 error (_("Unable to seek to start of dynamic information\n"));
11833 goto no_gnu_hash;
11834 }
11835
11836 gnubuckets = get_dynamic_data (filedata, ngnubuckets, 4);
11837
11838 if (gnubuckets == NULL)
11839 goto no_gnu_hash;
11840
11841 for (i = 0; i < ngnubuckets; i++)
11842 if (gnubuckets[i] != 0)
11843 {
11844 if (gnubuckets[i] < gnusymidx)
11845 return FALSE;
11846
11847 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
11848 maxchain = gnubuckets[i];
11849 }
11850
11851 if (maxchain == 0xffffffff)
11852 goto no_gnu_hash;
11853
11854 maxchain -= gnusymidx;
11855
11856 if (fseek (filedata->handle,
11857 (archive_file_offset
11858 + offset_from_vma (filedata, buckets_vma
11859 + 4 * (ngnubuckets + maxchain), 4)),
11860 SEEK_SET))
11861 {
11862 error (_("Unable to seek to start of dynamic information\n"));
11863 goto no_gnu_hash;
11864 }
11865
11866 do
11867 {
11868 if (fread (nb, 4, 1, filedata->handle) != 1)
11869 {
11870 error (_("Failed to determine last chain length\n"));
11871 goto no_gnu_hash;
11872 }
11873
11874 if (maxchain + 1 == 0)
11875 goto no_gnu_hash;
11876
11877 ++maxchain;
11878 }
11879 while ((byte_get (nb, 4) & 1) == 0);
11880
11881 if (fseek (filedata->handle,
11882 (archive_file_offset
11883 + offset_from_vma (filedata, buckets_vma + 4 * ngnubuckets, 4)),
11884 SEEK_SET))
11885 {
11886 error (_("Unable to seek to start of dynamic information\n"));
11887 goto no_gnu_hash;
11888 }
11889
11890 gnuchains = get_dynamic_data (filedata, maxchain, 4);
11891 ngnuchains = maxchain;
11892
11893 if (gnuchains == NULL)
11894 goto no_gnu_hash;
11895
11896 if (dynamic_info_DT_MIPS_XHASH)
11897 {
11898 if (fseek (filedata->handle,
11899 (archive_file_offset
11900 + offset_from_vma (filedata, (buckets_vma
11901 + 4 * (ngnubuckets
11902 + maxchain)), 4)),
11903 SEEK_SET))
11904 {
11905 error (_("Unable to seek to start of dynamic information\n"));
11906 goto no_gnu_hash;
11907 }
11908
11909 mipsxlat = get_dynamic_data (filedata, maxchain, 4);
11910 }
11911
11912 no_gnu_hash:
11913 if (dynamic_info_DT_MIPS_XHASH && mipsxlat == NULL)
11914 {
11915 free (gnuchains);
11916 gnuchains = NULL;
11917 }
11918 if (gnuchains == NULL)
11919 {
11920 free (gnubuckets);
11921 gnubuckets = NULL;
11922 ngnubuckets = 0;
11923 if (do_using_dynamic)
11924 return FALSE;
11925 }
11926 }
11927
11928 if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
11929 && do_syms
11930 && do_using_dynamic
11931 && dynamic_strings != NULL
11932 && dynamic_symbols != NULL)
11933 {
11934 unsigned long hn;
11935
11936 if (dynamic_info[DT_HASH])
11937 {
11938 bfd_vma si;
11939 char *visited;
11940
11941 printf (_("\nSymbol table for image:\n"));
11942 if (is_32bit_elf)
11943 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11944 else
11945 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11946
11947 visited = xcmalloc (nchains, 1);
11948 memset (visited, 0, nchains);
11949 for (hn = 0; hn < nbuckets; hn++)
11950 {
11951 for (si = buckets[hn]; si > 0; si = chains[si])
11952 {
11953 print_dynamic_symbol (filedata, si, hn);
11954 if (si >= nchains || visited[si])
11955 {
11956 error (_("histogram chain is corrupt\n"));
11957 break;
11958 }
11959 visited[si] = 1;
11960 }
11961 }
11962 free (visited);
11963 }
11964
11965 if (dynamic_info_DT_GNU_HASH)
11966 {
11967 printf (_("\nSymbol table of `%s' for image:\n"),
11968 GNU_HASH_SECTION_NAME);
11969 if (is_32bit_elf)
11970 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11971 else
11972 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11973
11974 for (hn = 0; hn < ngnubuckets; ++hn)
11975 if (gnubuckets[hn] != 0)
11976 {
11977 bfd_vma si = gnubuckets[hn];
11978 bfd_vma off = si - gnusymidx;
11979
11980 do
11981 {
11982 if (dynamic_info_DT_MIPS_XHASH)
11983 print_dynamic_symbol (filedata, mipsxlat[off], hn);
11984 else
11985 print_dynamic_symbol (filedata, si, hn);
11986 si++;
11987 }
11988 while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
11989 }
11990 }
11991 }
11992 else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
11993 && filedata->section_headers != NULL)
11994 {
11995 unsigned int i;
11996
11997 for (i = 0, section = filedata->section_headers;
11998 i < filedata->file_header.e_shnum;
11999 i++, section++)
12000 {
12001 unsigned int si;
12002 char * strtab = NULL;
12003 unsigned long int strtab_size = 0;
12004 Elf_Internal_Sym * symtab;
12005 Elf_Internal_Sym * psym;
12006 unsigned long num_syms;
12007
12008 if ((section->sh_type != SHT_SYMTAB
12009 && section->sh_type != SHT_DYNSYM)
12010 || (!do_syms
12011 && section->sh_type == SHT_SYMTAB))
12012 continue;
12013
12014 if (section->sh_entsize == 0)
12015 {
12016 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
12017 printable_section_name (filedata, section));
12018 continue;
12019 }
12020
12021 num_syms = section->sh_size / section->sh_entsize;
12022 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
12023 "\nSymbol table '%s' contains %lu entries:\n",
12024 num_syms),
12025 printable_section_name (filedata, section),
12026 num_syms);
12027
12028 if (is_32bit_elf)
12029 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12030 else
12031 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12032
12033 symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms);
12034 if (symtab == NULL)
12035 continue;
12036
12037 if (section->sh_link == filedata->file_header.e_shstrndx)
12038 {
12039 strtab = filedata->string_table;
12040 strtab_size = filedata->string_table_length;
12041 }
12042 else if (section->sh_link < filedata->file_header.e_shnum)
12043 {
12044 Elf_Internal_Shdr * string_sec;
12045
12046 string_sec = filedata->section_headers + section->sh_link;
12047
12048 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset,
12049 1, string_sec->sh_size,
12050 _("string table"));
12051 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
12052 }
12053
12054 for (si = 0, psym = symtab; si < num_syms; si++, psym++)
12055 {
12056 const char *version_string;
12057 enum versioned_symbol_info sym_info;
12058 unsigned short vna_other;
12059
12060 printf ("%6d: ", si);
12061 print_vma (psym->st_value, LONG_HEX);
12062 putchar (' ');
12063 print_vma (psym->st_size, DEC_5);
12064 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
12065 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
12066 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
12067 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
12068 else
12069 {
12070 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
12071
12072 printf (" %-7s", get_symbol_visibility (vis));
12073 /* Check to see if any other bits in the st_other field are set.
12074 Note - displaying this information disrupts the layout of the
12075 table being generated, but for the moment this case is very rare. */
12076 if (psym->st_other ^ vis)
12077 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
12078 }
12079 printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
12080 print_symbol (25, psym->st_name < strtab_size
12081 ? strtab + psym->st_name : _("<corrupt>"));
12082
12083 version_string
12084 = get_symbol_version_string (filedata,
12085 section->sh_type == SHT_DYNSYM,
12086 strtab, strtab_size, si,
12087 psym, &sym_info, &vna_other);
12088 if (version_string)
12089 {
12090 if (sym_info == symbol_undefined)
12091 printf ("@%s (%d)", version_string, vna_other);
12092 else
12093 printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
12094 version_string);
12095 }
12096
12097 putchar ('\n');
12098
12099 if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
12100 && si >= section->sh_info
12101 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
12102 && filedata->file_header.e_machine != EM_MIPS
12103 /* Solaris binaries have been found to violate this requirement as
12104 well. Not sure if this is a bug or an ABI requirement. */
12105 && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS)
12106 warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"),
12107 si, printable_section_name (filedata, section), section->sh_info);
12108 }
12109
12110 free (symtab);
12111 if (strtab != filedata->string_table)
12112 free (strtab);
12113 }
12114 }
12115 else if (do_syms)
12116 printf
12117 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
12118
12119 if (do_histogram && buckets != NULL)
12120 {
12121 unsigned long * lengths;
12122 unsigned long * counts;
12123 unsigned long hn;
12124 bfd_vma si;
12125 unsigned long maxlength = 0;
12126 unsigned long nzero_counts = 0;
12127 unsigned long nsyms = 0;
12128 char *visited;
12129
12130 printf (ngettext ("\nHistogram for bucket list length "
12131 "(total of %lu bucket):\n",
12132 "\nHistogram for bucket list length "
12133 "(total of %lu buckets):\n",
12134 (unsigned long) nbuckets),
12135 (unsigned long) nbuckets);
12136
12137 lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
12138 if (lengths == NULL)
12139 {
12140 error (_("Out of memory allocating space for histogram buckets\n"));
12141 return FALSE;
12142 }
12143 visited = xcmalloc (nchains, 1);
12144 memset (visited, 0, nchains);
12145
12146 printf (_(" Length Number %% of total Coverage\n"));
12147 for (hn = 0; hn < nbuckets; ++hn)
12148 {
12149 for (si = buckets[hn]; si > 0; si = chains[si])
12150 {
12151 ++nsyms;
12152 if (maxlength < ++lengths[hn])
12153 ++maxlength;
12154 if (si >= nchains || visited[si])
12155 {
12156 error (_("histogram chain is corrupt\n"));
12157 break;
12158 }
12159 visited[si] = 1;
12160 }
12161 }
12162 free (visited);
12163
12164 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
12165 if (counts == NULL)
12166 {
12167 free (lengths);
12168 error (_("Out of memory allocating space for histogram counts\n"));
12169 return FALSE;
12170 }
12171
12172 for (hn = 0; hn < nbuckets; ++hn)
12173 ++counts[lengths[hn]];
12174
12175 if (nbuckets > 0)
12176 {
12177 unsigned long i;
12178 printf (" 0 %-10lu (%5.1f%%)\n",
12179 counts[0], (counts[0] * 100.0) / nbuckets);
12180 for (i = 1; i <= maxlength; ++i)
12181 {
12182 nzero_counts += counts[i] * i;
12183 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12184 i, counts[i], (counts[i] * 100.0) / nbuckets,
12185 (nzero_counts * 100.0) / nsyms);
12186 }
12187 }
12188
12189 free (counts);
12190 free (lengths);
12191 }
12192
12193 if (buckets != NULL)
12194 {
12195 free (buckets);
12196 free (chains);
12197 }
12198
12199 if (do_histogram && gnubuckets != NULL)
12200 {
12201 unsigned long * lengths;
12202 unsigned long * counts;
12203 unsigned long hn;
12204 unsigned long maxlength = 0;
12205 unsigned long nzero_counts = 0;
12206 unsigned long nsyms = 0;
12207
12208 printf (ngettext ("\nHistogram for `%s' bucket list length "
12209 "(total of %lu bucket):\n",
12210 "\nHistogram for `%s' bucket list length "
12211 "(total of %lu buckets):\n",
12212 (unsigned long) ngnubuckets),
12213 GNU_HASH_SECTION_NAME,
12214 (unsigned long) ngnubuckets);
12215
12216 lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
12217 if (lengths == NULL)
12218 {
12219 error (_("Out of memory allocating space for gnu histogram buckets\n"));
12220 return FALSE;
12221 }
12222
12223 printf (_(" Length Number %% of total Coverage\n"));
12224
12225 for (hn = 0; hn < ngnubuckets; ++hn)
12226 if (gnubuckets[hn] != 0)
12227 {
12228 bfd_vma off, length = 1;
12229
12230 for (off = gnubuckets[hn] - gnusymidx;
12231 /* PR 17531 file: 010-77222-0.004. */
12232 off < ngnuchains && (gnuchains[off] & 1) == 0;
12233 ++off)
12234 ++length;
12235 lengths[hn] = length;
12236 if (length > maxlength)
12237 maxlength = length;
12238 nsyms += length;
12239 }
12240
12241 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
12242 if (counts == NULL)
12243 {
12244 free (lengths);
12245 error (_("Out of memory allocating space for gnu histogram counts\n"));
12246 return FALSE;
12247 }
12248
12249 for (hn = 0; hn < ngnubuckets; ++hn)
12250 ++counts[lengths[hn]];
12251
12252 if (ngnubuckets > 0)
12253 {
12254 unsigned long j;
12255 printf (" 0 %-10lu (%5.1f%%)\n",
12256 counts[0], (counts[0] * 100.0) / ngnubuckets);
12257 for (j = 1; j <= maxlength; ++j)
12258 {
12259 nzero_counts += counts[j] * j;
12260 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12261 j, counts[j], (counts[j] * 100.0) / ngnubuckets,
12262 (nzero_counts * 100.0) / nsyms);
12263 }
12264 }
12265
12266 free (counts);
12267 free (lengths);
12268 free (gnubuckets);
12269 free (gnuchains);
12270 free (mipsxlat);
12271 }
12272
12273 return TRUE;
12274 }
12275
12276 static bfd_boolean
12277 process_syminfo (Filedata * filedata ATTRIBUTE_UNUSED)
12278 {
12279 unsigned int i;
12280
12281 if (dynamic_syminfo == NULL
12282 || !do_dynamic)
12283 /* No syminfo, this is ok. */
12284 return TRUE;
12285
12286 /* There better should be a dynamic symbol section. */
12287 if (dynamic_symbols == NULL || dynamic_strings == NULL)
12288 return FALSE;
12289
12290 if (dynamic_addr)
12291 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
12292 "contains %d entry:\n",
12293 "\nDynamic info segment at offset 0x%lx "
12294 "contains %d entries:\n",
12295 dynamic_syminfo_nent),
12296 dynamic_syminfo_offset, dynamic_syminfo_nent);
12297
12298 printf (_(" Num: Name BoundTo Flags\n"));
12299 for (i = 0; i < dynamic_syminfo_nent; ++i)
12300 {
12301 unsigned short int flags = dynamic_syminfo[i].si_flags;
12302
12303 printf ("%4d: ", i);
12304 if (i >= num_dynamic_syms)
12305 printf (_("<corrupt index>"));
12306 else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
12307 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
12308 else
12309 printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
12310 putchar (' ');
12311
12312 switch (dynamic_syminfo[i].si_boundto)
12313 {
12314 case SYMINFO_BT_SELF:
12315 fputs ("SELF ", stdout);
12316 break;
12317 case SYMINFO_BT_PARENT:
12318 fputs ("PARENT ", stdout);
12319 break;
12320 default:
12321 if (dynamic_syminfo[i].si_boundto > 0
12322 && dynamic_syminfo[i].si_boundto < dynamic_nent
12323 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
12324 {
12325 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
12326 putchar (' ' );
12327 }
12328 else
12329 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
12330 break;
12331 }
12332
12333 if (flags & SYMINFO_FLG_DIRECT)
12334 printf (" DIRECT");
12335 if (flags & SYMINFO_FLG_PASSTHRU)
12336 printf (" PASSTHRU");
12337 if (flags & SYMINFO_FLG_COPY)
12338 printf (" COPY");
12339 if (flags & SYMINFO_FLG_LAZYLOAD)
12340 printf (" LAZYLOAD");
12341
12342 puts ("");
12343 }
12344
12345 return TRUE;
12346 }
12347
12348 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
12349 is contained by the region START .. END. The types of ADDR, START
12350 and END should all be the same. Note both ADDR + NELEM and END
12351 point to just beyond the end of the regions that are being tested. */
12352 #define IN_RANGE(START,END,ADDR,NELEM) \
12353 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
12354
12355 /* Check to see if the given reloc needs to be handled in a target specific
12356 manner. If so then process the reloc and return TRUE otherwise return
12357 FALSE.
12358
12359 If called with reloc == NULL, then this is a signal that reloc processing
12360 for the current section has finished, and any saved state should be
12361 discarded. */
12362
12363 static bfd_boolean
12364 target_specific_reloc_handling (Filedata * filedata,
12365 Elf_Internal_Rela * reloc,
12366 unsigned char * start,
12367 unsigned char * end,
12368 Elf_Internal_Sym * symtab,
12369 unsigned long num_syms)
12370 {
12371 unsigned int reloc_type = 0;
12372 unsigned long sym_index = 0;
12373
12374 if (reloc)
12375 {
12376 reloc_type = get_reloc_type (filedata, reloc->r_info);
12377 sym_index = get_reloc_symindex (reloc->r_info);
12378 }
12379
12380 switch (filedata->file_header.e_machine)
12381 {
12382 case EM_MSP430:
12383 case EM_MSP430_OLD:
12384 {
12385 static Elf_Internal_Sym * saved_sym = NULL;
12386
12387 if (reloc == NULL)
12388 {
12389 saved_sym = NULL;
12390 return TRUE;
12391 }
12392
12393 switch (reloc_type)
12394 {
12395 case 10: /* R_MSP430_SYM_DIFF */
12396 if (uses_msp430x_relocs (filedata))
12397 break;
12398 /* Fall through. */
12399 case 21: /* R_MSP430X_SYM_DIFF */
12400 /* PR 21139. */
12401 if (sym_index >= num_syms)
12402 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
12403 sym_index);
12404 else
12405 saved_sym = symtab + sym_index;
12406 return TRUE;
12407
12408 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
12409 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
12410 goto handle_sym_diff;
12411
12412 case 5: /* R_MSP430_16_BYTE */
12413 case 9: /* R_MSP430_8 */
12414 if (uses_msp430x_relocs (filedata))
12415 break;
12416 goto handle_sym_diff;
12417
12418 case 2: /* R_MSP430_ABS16 */
12419 case 15: /* R_MSP430X_ABS16 */
12420 if (! uses_msp430x_relocs (filedata))
12421 break;
12422 goto handle_sym_diff;
12423
12424 handle_sym_diff:
12425 if (saved_sym != NULL)
12426 {
12427 int reloc_size = reloc_type == 1 ? 4 : 2;
12428 bfd_vma value;
12429
12430 if (sym_index >= num_syms)
12431 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
12432 sym_index);
12433 else
12434 {
12435 value = reloc->r_addend + (symtab[sym_index].st_value
12436 - saved_sym->st_value);
12437
12438 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
12439 byte_put (start + reloc->r_offset, value, reloc_size);
12440 else
12441 /* PR 21137 */
12442 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
12443 (long) reloc->r_offset);
12444 }
12445
12446 saved_sym = NULL;
12447 return TRUE;
12448 }
12449 break;
12450
12451 default:
12452 if (saved_sym != NULL)
12453 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
12454 break;
12455 }
12456 break;
12457 }
12458
12459 case EM_MN10300:
12460 case EM_CYGNUS_MN10300:
12461 {
12462 static Elf_Internal_Sym * saved_sym = NULL;
12463
12464 if (reloc == NULL)
12465 {
12466 saved_sym = NULL;
12467 return TRUE;
12468 }
12469
12470 switch (reloc_type)
12471 {
12472 case 34: /* R_MN10300_ALIGN */
12473 return TRUE;
12474 case 33: /* R_MN10300_SYM_DIFF */
12475 if (sym_index >= num_syms)
12476 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
12477 sym_index);
12478 else
12479 saved_sym = symtab + sym_index;
12480 return TRUE;
12481
12482 case 1: /* R_MN10300_32 */
12483 case 2: /* R_MN10300_16 */
12484 if (saved_sym != NULL)
12485 {
12486 int reloc_size = reloc_type == 1 ? 4 : 2;
12487 bfd_vma value;
12488
12489 if (sym_index >= num_syms)
12490 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
12491 sym_index);
12492 else
12493 {
12494 value = reloc->r_addend + (symtab[sym_index].st_value
12495 - saved_sym->st_value);
12496
12497 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
12498 byte_put (start + reloc->r_offset, value, reloc_size);
12499 else
12500 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
12501 (long) reloc->r_offset);
12502 }
12503
12504 saved_sym = NULL;
12505 return TRUE;
12506 }
12507 break;
12508 default:
12509 if (saved_sym != NULL)
12510 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
12511 break;
12512 }
12513 break;
12514 }
12515
12516 case EM_RL78:
12517 {
12518 static bfd_vma saved_sym1 = 0;
12519 static bfd_vma saved_sym2 = 0;
12520 static bfd_vma value;
12521
12522 if (reloc == NULL)
12523 {
12524 saved_sym1 = saved_sym2 = 0;
12525 return TRUE;
12526 }
12527
12528 switch (reloc_type)
12529 {
12530 case 0x80: /* R_RL78_SYM. */
12531 saved_sym1 = saved_sym2;
12532 if (sym_index >= num_syms)
12533 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
12534 sym_index);
12535 else
12536 {
12537 saved_sym2 = symtab[sym_index].st_value;
12538 saved_sym2 += reloc->r_addend;
12539 }
12540 return TRUE;
12541
12542 case 0x83: /* R_RL78_OPsub. */
12543 value = saved_sym1 - saved_sym2;
12544 saved_sym2 = saved_sym1 = 0;
12545 return TRUE;
12546 break;
12547
12548 case 0x41: /* R_RL78_ABS32. */
12549 if (IN_RANGE (start, end, start + reloc->r_offset, 4))
12550 byte_put (start + reloc->r_offset, value, 4);
12551 else
12552 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12553 (long) reloc->r_offset);
12554 value = 0;
12555 return TRUE;
12556
12557 case 0x43: /* R_RL78_ABS16. */
12558 if (IN_RANGE (start, end, start + reloc->r_offset, 2))
12559 byte_put (start + reloc->r_offset, value, 2);
12560 else
12561 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12562 (long) reloc->r_offset);
12563 value = 0;
12564 return TRUE;
12565
12566 default:
12567 break;
12568 }
12569 break;
12570 }
12571 }
12572
12573 return FALSE;
12574 }
12575
12576 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
12577 DWARF debug sections. This is a target specific test. Note - we do not
12578 go through the whole including-target-headers-multiple-times route, (as
12579 we have already done with <elf/h8.h>) because this would become very
12580 messy and even then this function would have to contain target specific
12581 information (the names of the relocs instead of their numeric values).
12582 FIXME: This is not the correct way to solve this problem. The proper way
12583 is to have target specific reloc sizing and typing functions created by
12584 the reloc-macros.h header, in the same way that it already creates the
12585 reloc naming functions. */
12586
12587 static bfd_boolean
12588 is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12589 {
12590 /* Please keep this table alpha-sorted for ease of visual lookup. */
12591 switch (filedata->file_header.e_machine)
12592 {
12593 case EM_386:
12594 case EM_IAMCU:
12595 return reloc_type == 1; /* R_386_32. */
12596 case EM_68K:
12597 return reloc_type == 1; /* R_68K_32. */
12598 case EM_860:
12599 return reloc_type == 1; /* R_860_32. */
12600 case EM_960:
12601 return reloc_type == 2; /* R_960_32. */
12602 case EM_AARCH64:
12603 return (reloc_type == 258
12604 || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
12605 case EM_BPF:
12606 return reloc_type == 11; /* R_BPF_DATA_32 */
12607 case EM_ADAPTEVA_EPIPHANY:
12608 return reloc_type == 3;
12609 case EM_ALPHA:
12610 return reloc_type == 1; /* R_ALPHA_REFLONG. */
12611 case EM_ARC:
12612 return reloc_type == 1; /* R_ARC_32. */
12613 case EM_ARC_COMPACT:
12614 case EM_ARC_COMPACT2:
12615 return reloc_type == 4; /* R_ARC_32. */
12616 case EM_ARM:
12617 return reloc_type == 2; /* R_ARM_ABS32 */
12618 case EM_AVR_OLD:
12619 case EM_AVR:
12620 return reloc_type == 1;
12621 case EM_BLACKFIN:
12622 return reloc_type == 0x12; /* R_byte4_data. */
12623 case EM_CRIS:
12624 return reloc_type == 3; /* R_CRIS_32. */
12625 case EM_CR16:
12626 return reloc_type == 3; /* R_CR16_NUM32. */
12627 case EM_CRX:
12628 return reloc_type == 15; /* R_CRX_NUM32. */
12629 case EM_CSKY:
12630 return reloc_type == 1; /* R_CKCORE_ADDR32. */
12631 case EM_CYGNUS_FRV:
12632 return reloc_type == 1;
12633 case EM_CYGNUS_D10V:
12634 case EM_D10V:
12635 return reloc_type == 6; /* R_D10V_32. */
12636 case EM_CYGNUS_D30V:
12637 case EM_D30V:
12638 return reloc_type == 12; /* R_D30V_32_NORMAL. */
12639 case EM_DLX:
12640 return reloc_type == 3; /* R_DLX_RELOC_32. */
12641 case EM_CYGNUS_FR30:
12642 case EM_FR30:
12643 return reloc_type == 3; /* R_FR30_32. */
12644 case EM_FT32:
12645 return reloc_type == 1; /* R_FT32_32. */
12646 case EM_H8S:
12647 case EM_H8_300:
12648 case EM_H8_300H:
12649 return reloc_type == 1; /* R_H8_DIR32. */
12650 case EM_IA_64:
12651 return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */
12652 || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */
12653 || reloc_type == 0x24 /* R_IA64_DIR32MSB. */
12654 || reloc_type == 0x25 /* R_IA64_DIR32LSB. */);
12655 case EM_IP2K_OLD:
12656 case EM_IP2K:
12657 return reloc_type == 2; /* R_IP2K_32. */
12658 case EM_IQ2000:
12659 return reloc_type == 2; /* R_IQ2000_32. */
12660 case EM_LATTICEMICO32:
12661 return reloc_type == 3; /* R_LM32_32. */
12662 case EM_M32C_OLD:
12663 case EM_M32C:
12664 return reloc_type == 3; /* R_M32C_32. */
12665 case EM_M32R:
12666 return reloc_type == 34; /* R_M32R_32_RELA. */
12667 case EM_68HC11:
12668 case EM_68HC12:
12669 return reloc_type == 6; /* R_M68HC11_32. */
12670 case EM_S12Z:
12671 return reloc_type == 7 || /* R_S12Z_EXT32 */
12672 reloc_type == 6; /* R_S12Z_CW32. */
12673 case EM_MCORE:
12674 return reloc_type == 1; /* R_MCORE_ADDR32. */
12675 case EM_CYGNUS_MEP:
12676 return reloc_type == 4; /* R_MEP_32. */
12677 case EM_METAG:
12678 return reloc_type == 2; /* R_METAG_ADDR32. */
12679 case EM_MICROBLAZE:
12680 return reloc_type == 1; /* R_MICROBLAZE_32. */
12681 case EM_MIPS:
12682 return reloc_type == 2; /* R_MIPS_32. */
12683 case EM_MMIX:
12684 return reloc_type == 4; /* R_MMIX_32. */
12685 case EM_CYGNUS_MN10200:
12686 case EM_MN10200:
12687 return reloc_type == 1; /* R_MN10200_32. */
12688 case EM_CYGNUS_MN10300:
12689 case EM_MN10300:
12690 return reloc_type == 1; /* R_MN10300_32. */
12691 case EM_MOXIE:
12692 return reloc_type == 1; /* R_MOXIE_32. */
12693 case EM_MSP430_OLD:
12694 case EM_MSP430:
12695 return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
12696 case EM_MT:
12697 return reloc_type == 2; /* R_MT_32. */
12698 case EM_NDS32:
12699 return reloc_type == 20; /* R_NDS32_RELA. */
12700 case EM_ALTERA_NIOS2:
12701 return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
12702 case EM_NIOS32:
12703 return reloc_type == 1; /* R_NIOS_32. */
12704 case EM_OR1K:
12705 return reloc_type == 1; /* R_OR1K_32. */
12706 case EM_PARISC:
12707 return (reloc_type == 1 /* R_PARISC_DIR32. */
12708 || reloc_type == 2 /* R_PARISC_DIR21L. */
12709 || reloc_type == 41); /* R_PARISC_SECREL32. */
12710 case EM_PJ:
12711 case EM_PJ_OLD:
12712 return reloc_type == 1; /* R_PJ_DATA_DIR32. */
12713 case EM_PPC64:
12714 return reloc_type == 1; /* R_PPC64_ADDR32. */
12715 case EM_PPC:
12716 return reloc_type == 1; /* R_PPC_ADDR32. */
12717 case EM_TI_PRU:
12718 return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
12719 case EM_RISCV:
12720 return reloc_type == 1; /* R_RISCV_32. */
12721 case EM_RL78:
12722 return reloc_type == 1; /* R_RL78_DIR32. */
12723 case EM_RX:
12724 return reloc_type == 1; /* R_RX_DIR32. */
12725 case EM_S370:
12726 return reloc_type == 1; /* R_I370_ADDR31. */
12727 case EM_S390_OLD:
12728 case EM_S390:
12729 return reloc_type == 4; /* R_S390_32. */
12730 case EM_SCORE:
12731 return reloc_type == 8; /* R_SCORE_ABS32. */
12732 case EM_SH:
12733 return reloc_type == 1; /* R_SH_DIR32. */
12734 case EM_SPARC32PLUS:
12735 case EM_SPARCV9:
12736 case EM_SPARC:
12737 return reloc_type == 3 /* R_SPARC_32. */
12738 || reloc_type == 23; /* R_SPARC_UA32. */
12739 case EM_SPU:
12740 return reloc_type == 6; /* R_SPU_ADDR32 */
12741 case EM_TI_C6000:
12742 return reloc_type == 1; /* R_C6000_ABS32. */
12743 case EM_TILEGX:
12744 return reloc_type == 2; /* R_TILEGX_32. */
12745 case EM_TILEPRO:
12746 return reloc_type == 1; /* R_TILEPRO_32. */
12747 case EM_CYGNUS_V850:
12748 case EM_V850:
12749 return reloc_type == 6; /* R_V850_ABS32. */
12750 case EM_V800:
12751 return reloc_type == 0x33; /* R_V810_WORD. */
12752 case EM_VAX:
12753 return reloc_type == 1; /* R_VAX_32. */
12754 case EM_VISIUM:
12755 return reloc_type == 3; /* R_VISIUM_32. */
12756 case EM_WEBASSEMBLY:
12757 return reloc_type == 1; /* R_WASM32_32. */
12758 case EM_X86_64:
12759 case EM_L1OM:
12760 case EM_K1OM:
12761 return reloc_type == 10; /* R_X86_64_32. */
12762 case EM_XC16X:
12763 case EM_C166:
12764 return reloc_type == 3; /* R_XC16C_ABS_32. */
12765 case EM_XGATE:
12766 return reloc_type == 4; /* R_XGATE_32. */
12767 case EM_XSTORMY16:
12768 return reloc_type == 1; /* R_XSTROMY16_32. */
12769 case EM_XTENSA_OLD:
12770 case EM_XTENSA:
12771 return reloc_type == 1; /* R_XTENSA_32. */
12772 default:
12773 {
12774 static unsigned int prev_warn = 0;
12775
12776 /* Avoid repeating the same warning multiple times. */
12777 if (prev_warn != filedata->file_header.e_machine)
12778 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
12779 filedata->file_header.e_machine);
12780 prev_warn = filedata->file_header.e_machine;
12781 return FALSE;
12782 }
12783 }
12784 }
12785
12786 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12787 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
12788
12789 static bfd_boolean
12790 is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
12791 {
12792 switch (filedata->file_header.e_machine)
12793 /* Please keep this table alpha-sorted for ease of visual lookup. */
12794 {
12795 case EM_386:
12796 case EM_IAMCU:
12797 return reloc_type == 2; /* R_386_PC32. */
12798 case EM_68K:
12799 return reloc_type == 4; /* R_68K_PC32. */
12800 case EM_AARCH64:
12801 return reloc_type == 261; /* R_AARCH64_PREL32 */
12802 case EM_ADAPTEVA_EPIPHANY:
12803 return reloc_type == 6;
12804 case EM_ALPHA:
12805 return reloc_type == 10; /* R_ALPHA_SREL32. */
12806 case EM_ARC_COMPACT:
12807 case EM_ARC_COMPACT2:
12808 return reloc_type == 49; /* R_ARC_32_PCREL. */
12809 case EM_ARM:
12810 return reloc_type == 3; /* R_ARM_REL32 */
12811 case EM_AVR_OLD:
12812 case EM_AVR:
12813 return reloc_type == 36; /* R_AVR_32_PCREL. */
12814 case EM_MICROBLAZE:
12815 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
12816 case EM_OR1K:
12817 return reloc_type == 9; /* R_OR1K_32_PCREL. */
12818 case EM_PARISC:
12819 return reloc_type == 9; /* R_PARISC_PCREL32. */
12820 case EM_PPC:
12821 return reloc_type == 26; /* R_PPC_REL32. */
12822 case EM_PPC64:
12823 return reloc_type == 26; /* R_PPC64_REL32. */
12824 case EM_RISCV:
12825 return reloc_type == 57; /* R_RISCV_32_PCREL. */
12826 case EM_S390_OLD:
12827 case EM_S390:
12828 return reloc_type == 5; /* R_390_PC32. */
12829 case EM_SH:
12830 return reloc_type == 2; /* R_SH_REL32. */
12831 case EM_SPARC32PLUS:
12832 case EM_SPARCV9:
12833 case EM_SPARC:
12834 return reloc_type == 6; /* R_SPARC_DISP32. */
12835 case EM_SPU:
12836 return reloc_type == 13; /* R_SPU_REL32. */
12837 case EM_TILEGX:
12838 return reloc_type == 6; /* R_TILEGX_32_PCREL. */
12839 case EM_TILEPRO:
12840 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
12841 case EM_VISIUM:
12842 return reloc_type == 6; /* R_VISIUM_32_PCREL */
12843 case EM_X86_64:
12844 case EM_L1OM:
12845 case EM_K1OM:
12846 return reloc_type == 2; /* R_X86_64_PC32. */
12847 case EM_VAX:
12848 return reloc_type == 4; /* R_VAX_PCREL32. */
12849 case EM_XTENSA_OLD:
12850 case EM_XTENSA:
12851 return reloc_type == 14; /* R_XTENSA_32_PCREL. */
12852 default:
12853 /* Do not abort or issue an error message here. Not all targets use
12854 pc-relative 32-bit relocs in their DWARF debug information and we
12855 have already tested for target coverage in is_32bit_abs_reloc. A
12856 more helpful warning message will be generated by apply_relocations
12857 anyway, so just return. */
12858 return FALSE;
12859 }
12860 }
12861
12862 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12863 a 64-bit absolute RELA relocation used in DWARF debug sections. */
12864
12865 static bfd_boolean
12866 is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12867 {
12868 switch (filedata->file_header.e_machine)
12869 {
12870 case EM_AARCH64:
12871 return reloc_type == 257; /* R_AARCH64_ABS64. */
12872 case EM_ALPHA:
12873 return reloc_type == 2; /* R_ALPHA_REFQUAD. */
12874 case EM_IA_64:
12875 return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */
12876 || reloc_type == 0x27 /* R_IA64_DIR64LSB. */);
12877 case EM_PARISC:
12878 return reloc_type == 80; /* R_PARISC_DIR64. */
12879 case EM_PPC64:
12880 return reloc_type == 38; /* R_PPC64_ADDR64. */
12881 case EM_RISCV:
12882 return reloc_type == 2; /* R_RISCV_64. */
12883 case EM_SPARC32PLUS:
12884 case EM_SPARCV9:
12885 case EM_SPARC:
12886 return reloc_type == 32 /* R_SPARC_64. */
12887 || reloc_type == 54; /* R_SPARC_UA64. */
12888 case EM_X86_64:
12889 case EM_L1OM:
12890 case EM_K1OM:
12891 return reloc_type == 1; /* R_X86_64_64. */
12892 case EM_S390_OLD:
12893 case EM_S390:
12894 return reloc_type == 22; /* R_S390_64. */
12895 case EM_TILEGX:
12896 return reloc_type == 1; /* R_TILEGX_64. */
12897 case EM_MIPS:
12898 return reloc_type == 18; /* R_MIPS_64. */
12899 default:
12900 return FALSE;
12901 }
12902 }
12903
12904 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
12905 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
12906
12907 static bfd_boolean
12908 is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
12909 {
12910 switch (filedata->file_header.e_machine)
12911 {
12912 case EM_AARCH64:
12913 return reloc_type == 260; /* R_AARCH64_PREL64. */
12914 case EM_ALPHA:
12915 return reloc_type == 11; /* R_ALPHA_SREL64. */
12916 case EM_IA_64:
12917 return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */
12918 || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */);
12919 case EM_PARISC:
12920 return reloc_type == 72; /* R_PARISC_PCREL64. */
12921 case EM_PPC64:
12922 return reloc_type == 44; /* R_PPC64_REL64. */
12923 case EM_SPARC32PLUS:
12924 case EM_SPARCV9:
12925 case EM_SPARC:
12926 return reloc_type == 46; /* R_SPARC_DISP64. */
12927 case EM_X86_64:
12928 case EM_L1OM:
12929 case EM_K1OM:
12930 return reloc_type == 24; /* R_X86_64_PC64. */
12931 case EM_S390_OLD:
12932 case EM_S390:
12933 return reloc_type == 23; /* R_S390_PC64. */
12934 case EM_TILEGX:
12935 return reloc_type == 5; /* R_TILEGX_64_PCREL. */
12936 default:
12937 return FALSE;
12938 }
12939 }
12940
12941 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12942 a 24-bit absolute RELA relocation used in DWARF debug sections. */
12943
12944 static bfd_boolean
12945 is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12946 {
12947 switch (filedata->file_header.e_machine)
12948 {
12949 case EM_CYGNUS_MN10200:
12950 case EM_MN10200:
12951 return reloc_type == 4; /* R_MN10200_24. */
12952 case EM_FT32:
12953 return reloc_type == 5; /* R_FT32_20. */
12954 default:
12955 return FALSE;
12956 }
12957 }
12958
12959 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12960 a 16-bit absolute RELA relocation used in DWARF debug sections. */
12961
12962 static bfd_boolean
12963 is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12964 {
12965 /* Please keep this table alpha-sorted for ease of visual lookup. */
12966 switch (filedata->file_header.e_machine)
12967 {
12968 case EM_ARC:
12969 case EM_ARC_COMPACT:
12970 case EM_ARC_COMPACT2:
12971 return reloc_type == 2; /* R_ARC_16. */
12972 case EM_ADAPTEVA_EPIPHANY:
12973 return reloc_type == 5;
12974 case EM_AVR_OLD:
12975 case EM_AVR:
12976 return reloc_type == 4; /* R_AVR_16. */
12977 case EM_CYGNUS_D10V:
12978 case EM_D10V:
12979 return reloc_type == 3; /* R_D10V_16. */
12980 case EM_FT32:
12981 return reloc_type == 2; /* R_FT32_16. */
12982 case EM_H8S:
12983 case EM_H8_300:
12984 case EM_H8_300H:
12985 return reloc_type == R_H8_DIR16;
12986 case EM_IP2K_OLD:
12987 case EM_IP2K:
12988 return reloc_type == 1; /* R_IP2K_16. */
12989 case EM_M32C_OLD:
12990 case EM_M32C:
12991 return reloc_type == 1; /* R_M32C_16 */
12992 case EM_CYGNUS_MN10200:
12993 case EM_MN10200:
12994 return reloc_type == 2; /* R_MN10200_16. */
12995 case EM_CYGNUS_MN10300:
12996 case EM_MN10300:
12997 return reloc_type == 2; /* R_MN10300_16. */
12998 case EM_MSP430:
12999 if (uses_msp430x_relocs (filedata))
13000 return reloc_type == 2; /* R_MSP430_ABS16. */
13001 /* Fall through. */
13002 case EM_MSP430_OLD:
13003 return reloc_type == 5; /* R_MSP430_16_BYTE. */
13004 case EM_NDS32:
13005 return reloc_type == 19; /* R_NDS32_RELA. */
13006 case EM_ALTERA_NIOS2:
13007 return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
13008 case EM_NIOS32:
13009 return reloc_type == 9; /* R_NIOS_16. */
13010 case EM_OR1K:
13011 return reloc_type == 2; /* R_OR1K_16. */
13012 case EM_RISCV:
13013 return reloc_type == 55; /* R_RISCV_SET16. */
13014 case EM_TI_PRU:
13015 return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */
13016 case EM_TI_C6000:
13017 return reloc_type == 2; /* R_C6000_ABS16. */
13018 case EM_VISIUM:
13019 return reloc_type == 2; /* R_VISIUM_16. */
13020 case EM_XC16X:
13021 case EM_C166:
13022 return reloc_type == 2; /* R_XC16C_ABS_16. */
13023 case EM_XGATE:
13024 return reloc_type == 3; /* R_XGATE_16. */
13025 default:
13026 return FALSE;
13027 }
13028 }
13029
13030 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13031 a 8-bit absolute RELA relocation used in DWARF debug sections. */
13032
13033 static bfd_boolean
13034 is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
13035 {
13036 switch (filedata->file_header.e_machine)
13037 {
13038 case EM_RISCV:
13039 return reloc_type == 54; /* R_RISCV_SET8. */
13040 default:
13041 return FALSE;
13042 }
13043 }
13044
13045 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13046 a 6-bit absolute RELA relocation used in DWARF debug sections. */
13047
13048 static bfd_boolean
13049 is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
13050 {
13051 switch (filedata->file_header.e_machine)
13052 {
13053 case EM_RISCV:
13054 return reloc_type == 53; /* R_RISCV_SET6. */
13055 default:
13056 return FALSE;
13057 }
13058 }
13059
13060 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13061 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
13062
13063 static bfd_boolean
13064 is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13065 {
13066 /* Please keep this table alpha-sorted for ease of visual lookup. */
13067 switch (filedata->file_header.e_machine)
13068 {
13069 case EM_RISCV:
13070 return reloc_type == 35; /* R_RISCV_ADD32. */
13071 default:
13072 return FALSE;
13073 }
13074 }
13075
13076 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13077 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
13078
13079 static bfd_boolean
13080 is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13081 {
13082 /* Please keep this table alpha-sorted for ease of visual lookup. */
13083 switch (filedata->file_header.e_machine)
13084 {
13085 case EM_RISCV:
13086 return reloc_type == 39; /* R_RISCV_SUB32. */
13087 default:
13088 return FALSE;
13089 }
13090 }
13091
13092 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13093 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
13094
13095 static bfd_boolean
13096 is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13097 {
13098 /* Please keep this table alpha-sorted for ease of visual lookup. */
13099 switch (filedata->file_header.e_machine)
13100 {
13101 case EM_RISCV:
13102 return reloc_type == 36; /* R_RISCV_ADD64. */
13103 default:
13104 return FALSE;
13105 }
13106 }
13107
13108 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13109 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
13110
13111 static bfd_boolean
13112 is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13113 {
13114 /* Please keep this table alpha-sorted for ease of visual lookup. */
13115 switch (filedata->file_header.e_machine)
13116 {
13117 case EM_RISCV:
13118 return reloc_type == 40; /* R_RISCV_SUB64. */
13119 default:
13120 return FALSE;
13121 }
13122 }
13123
13124 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13125 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
13126
13127 static bfd_boolean
13128 is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13129 {
13130 /* Please keep this table alpha-sorted for ease of visual lookup. */
13131 switch (filedata->file_header.e_machine)
13132 {
13133 case EM_RISCV:
13134 return reloc_type == 34; /* R_RISCV_ADD16. */
13135 default:
13136 return FALSE;
13137 }
13138 }
13139
13140 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13141 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
13142
13143 static bfd_boolean
13144 is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13145 {
13146 /* Please keep this table alpha-sorted for ease of visual lookup. */
13147 switch (filedata->file_header.e_machine)
13148 {
13149 case EM_RISCV:
13150 return reloc_type == 38; /* R_RISCV_SUB16. */
13151 default:
13152 return FALSE;
13153 }
13154 }
13155
13156 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13157 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
13158
13159 static bfd_boolean
13160 is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
13161 {
13162 /* Please keep this table alpha-sorted for ease of visual lookup. */
13163 switch (filedata->file_header.e_machine)
13164 {
13165 case EM_RISCV:
13166 return reloc_type == 33; /* R_RISCV_ADD8. */
13167 default:
13168 return FALSE;
13169 }
13170 }
13171
13172 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13173 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
13174
13175 static bfd_boolean
13176 is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13177 {
13178 /* Please keep this table alpha-sorted for ease of visual lookup. */
13179 switch (filedata->file_header.e_machine)
13180 {
13181 case EM_RISCV:
13182 return reloc_type == 37; /* R_RISCV_SUB8. */
13183 default:
13184 return FALSE;
13185 }
13186 }
13187
13188 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13189 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
13190
13191 static bfd_boolean
13192 is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
13193 {
13194 switch (filedata->file_header.e_machine)
13195 {
13196 case EM_RISCV:
13197 return reloc_type == 52; /* R_RISCV_SUB6. */
13198 default:
13199 return FALSE;
13200 }
13201 }
13202
13203 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
13204 relocation entries (possibly formerly used for SHT_GROUP sections). */
13205
13206 static bfd_boolean
13207 is_none_reloc (Filedata * filedata, unsigned int reloc_type)
13208 {
13209 switch (filedata->file_header.e_machine)
13210 {
13211 case EM_386: /* R_386_NONE. */
13212 case EM_68K: /* R_68K_NONE. */
13213 case EM_ADAPTEVA_EPIPHANY:
13214 case EM_ALPHA: /* R_ALPHA_NONE. */
13215 case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
13216 case EM_ARC: /* R_ARC_NONE. */
13217 case EM_ARC_COMPACT2: /* R_ARC_NONE. */
13218 case EM_ARC_COMPACT: /* R_ARC_NONE. */
13219 case EM_ARM: /* R_ARM_NONE. */
13220 case EM_C166: /* R_XC16X_NONE. */
13221 case EM_CRIS: /* R_CRIS_NONE. */
13222 case EM_FT32: /* R_FT32_NONE. */
13223 case EM_IA_64: /* R_IA64_NONE. */
13224 case EM_K1OM: /* R_X86_64_NONE. */
13225 case EM_L1OM: /* R_X86_64_NONE. */
13226 case EM_M32R: /* R_M32R_NONE. */
13227 case EM_MIPS: /* R_MIPS_NONE. */
13228 case EM_MN10300: /* R_MN10300_NONE. */
13229 case EM_MOXIE: /* R_MOXIE_NONE. */
13230 case EM_NIOS32: /* R_NIOS_NONE. */
13231 case EM_OR1K: /* R_OR1K_NONE. */
13232 case EM_PARISC: /* R_PARISC_NONE. */
13233 case EM_PPC64: /* R_PPC64_NONE. */
13234 case EM_PPC: /* R_PPC_NONE. */
13235 case EM_RISCV: /* R_RISCV_NONE. */
13236 case EM_S390: /* R_390_NONE. */
13237 case EM_S390_OLD:
13238 case EM_SH: /* R_SH_NONE. */
13239 case EM_SPARC32PLUS:
13240 case EM_SPARC: /* R_SPARC_NONE. */
13241 case EM_SPARCV9:
13242 case EM_TILEGX: /* R_TILEGX_NONE. */
13243 case EM_TILEPRO: /* R_TILEPRO_NONE. */
13244 case EM_TI_C6000:/* R_C6000_NONE. */
13245 case EM_X86_64: /* R_X86_64_NONE. */
13246 case EM_XC16X:
13247 case EM_WEBASSEMBLY: /* R_WASM32_NONE. */
13248 return reloc_type == 0;
13249
13250 case EM_AARCH64:
13251 return reloc_type == 0 || reloc_type == 256;
13252 case EM_AVR_OLD:
13253 case EM_AVR:
13254 return (reloc_type == 0 /* R_AVR_NONE. */
13255 || reloc_type == 30 /* R_AVR_DIFF8. */
13256 || reloc_type == 31 /* R_AVR_DIFF16. */
13257 || reloc_type == 32 /* R_AVR_DIFF32. */);
13258 case EM_METAG:
13259 return reloc_type == 3; /* R_METAG_NONE. */
13260 case EM_NDS32:
13261 return (reloc_type == 0 /* R_XTENSA_NONE. */
13262 || reloc_type == 204 /* R_NDS32_DIFF8. */
13263 || reloc_type == 205 /* R_NDS32_DIFF16. */
13264 || reloc_type == 206 /* R_NDS32_DIFF32. */
13265 || reloc_type == 207 /* R_NDS32_ULEB128. */);
13266 case EM_TI_PRU:
13267 return (reloc_type == 0 /* R_PRU_NONE. */
13268 || reloc_type == 65 /* R_PRU_DIFF8. */
13269 || reloc_type == 66 /* R_PRU_DIFF16. */
13270 || reloc_type == 67 /* R_PRU_DIFF32. */);
13271 case EM_XTENSA_OLD:
13272 case EM_XTENSA:
13273 return (reloc_type == 0 /* R_XTENSA_NONE. */
13274 || reloc_type == 17 /* R_XTENSA_DIFF8. */
13275 || reloc_type == 18 /* R_XTENSA_DIFF16. */
13276 || reloc_type == 19 /* R_XTENSA_DIFF32. */);
13277 }
13278 return FALSE;
13279 }
13280
13281 /* Returns TRUE if there is a relocation against
13282 section NAME at OFFSET bytes. */
13283
13284 bfd_boolean
13285 reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
13286 {
13287 Elf_Internal_Rela * relocs;
13288 Elf_Internal_Rela * rp;
13289
13290 if (dsec == NULL || dsec->reloc_info == NULL)
13291 return FALSE;
13292
13293 relocs = (Elf_Internal_Rela *) dsec->reloc_info;
13294
13295 for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
13296 if (rp->r_offset == offset)
13297 return TRUE;
13298
13299 return FALSE;
13300 }
13301
13302 /* Apply relocations to a section.
13303 Returns TRUE upon success, FALSE otherwise.
13304 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
13305 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
13306 will be set to the number of relocs loaded.
13307
13308 Note: So far support has been added only for those relocations
13309 which can be found in debug sections. FIXME: Add support for
13310 more relocations ? */
13311
13312 static bfd_boolean
13313 apply_relocations (Filedata * filedata,
13314 const Elf_Internal_Shdr * section,
13315 unsigned char * start,
13316 bfd_size_type size,
13317 void ** relocs_return,
13318 unsigned long * num_relocs_return)
13319 {
13320 Elf_Internal_Shdr * relsec;
13321 unsigned char * end = start + size;
13322
13323 if (relocs_return != NULL)
13324 {
13325 * (Elf_Internal_Rela **) relocs_return = NULL;
13326 * num_relocs_return = 0;
13327 }
13328
13329 if (filedata->file_header.e_type != ET_REL)
13330 /* No relocs to apply. */
13331 return TRUE;
13332
13333 /* Find the reloc section associated with the section. */
13334 for (relsec = filedata->section_headers;
13335 relsec < filedata->section_headers + filedata->file_header.e_shnum;
13336 ++relsec)
13337 {
13338 bfd_boolean is_rela;
13339 unsigned long num_relocs;
13340 Elf_Internal_Rela * relocs;
13341 Elf_Internal_Rela * rp;
13342 Elf_Internal_Shdr * symsec;
13343 Elf_Internal_Sym * symtab;
13344 unsigned long num_syms;
13345 Elf_Internal_Sym * sym;
13346
13347 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
13348 || relsec->sh_info >= filedata->file_header.e_shnum
13349 || filedata->section_headers + relsec->sh_info != section
13350 || relsec->sh_size == 0
13351 || relsec->sh_link >= filedata->file_header.e_shnum)
13352 continue;
13353
13354 is_rela = relsec->sh_type == SHT_RELA;
13355
13356 if (is_rela)
13357 {
13358 if (!slurp_rela_relocs (filedata, relsec->sh_offset,
13359 relsec->sh_size, & relocs, & num_relocs))
13360 return FALSE;
13361 }
13362 else
13363 {
13364 if (!slurp_rel_relocs (filedata, relsec->sh_offset,
13365 relsec->sh_size, & relocs, & num_relocs))
13366 return FALSE;
13367 }
13368
13369 /* SH uses RELA but uses in place value instead of the addend field. */
13370 if (filedata->file_header.e_machine == EM_SH)
13371 is_rela = FALSE;
13372
13373 symsec = filedata->section_headers + relsec->sh_link;
13374 if (symsec->sh_type != SHT_SYMTAB
13375 && symsec->sh_type != SHT_DYNSYM)
13376 return FALSE;
13377 symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms);
13378
13379 for (rp = relocs; rp < relocs + num_relocs; ++rp)
13380 {
13381 bfd_vma addend;
13382 unsigned int reloc_type;
13383 unsigned int reloc_size;
13384 bfd_boolean reloc_inplace = FALSE;
13385 bfd_boolean reloc_subtract = FALSE;
13386 unsigned char * rloc;
13387 unsigned long sym_index;
13388
13389 reloc_type = get_reloc_type (filedata, rp->r_info);
13390
13391 if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms))
13392 continue;
13393 else if (is_none_reloc (filedata, reloc_type))
13394 continue;
13395 else if (is_32bit_abs_reloc (filedata, reloc_type)
13396 || is_32bit_pcrel_reloc (filedata, reloc_type))
13397 reloc_size = 4;
13398 else if (is_64bit_abs_reloc (filedata, reloc_type)
13399 || is_64bit_pcrel_reloc (filedata, reloc_type))
13400 reloc_size = 8;
13401 else if (is_24bit_abs_reloc (filedata, reloc_type))
13402 reloc_size = 3;
13403 else if (is_16bit_abs_reloc (filedata, reloc_type))
13404 reloc_size = 2;
13405 else if (is_8bit_abs_reloc (filedata, reloc_type)
13406 || is_6bit_abs_reloc (filedata, reloc_type))
13407 reloc_size = 1;
13408 else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
13409 reloc_type))
13410 || is_32bit_inplace_add_reloc (filedata, reloc_type))
13411 {
13412 reloc_size = 4;
13413 reloc_inplace = TRUE;
13414 }
13415 else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata,
13416 reloc_type))
13417 || is_64bit_inplace_add_reloc (filedata, reloc_type))
13418 {
13419 reloc_size = 8;
13420 reloc_inplace = TRUE;
13421 }
13422 else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata,
13423 reloc_type))
13424 || is_16bit_inplace_add_reloc (filedata, reloc_type))
13425 {
13426 reloc_size = 2;
13427 reloc_inplace = TRUE;
13428 }
13429 else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata,
13430 reloc_type))
13431 || is_8bit_inplace_add_reloc (filedata, reloc_type))
13432 {
13433 reloc_size = 1;
13434 reloc_inplace = TRUE;
13435 }
13436 else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata,
13437 reloc_type)))
13438 {
13439 reloc_size = 1;
13440 reloc_inplace = TRUE;
13441 }
13442 else
13443 {
13444 static unsigned int prev_reloc = 0;
13445
13446 if (reloc_type != prev_reloc)
13447 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
13448 reloc_type, printable_section_name (filedata, section));
13449 prev_reloc = reloc_type;
13450 continue;
13451 }
13452
13453 rloc = start + rp->r_offset;
13454 if (!IN_RANGE (start, end, rloc, reloc_size))
13455 {
13456 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
13457 (unsigned long) rp->r_offset,
13458 printable_section_name (filedata, section));
13459 continue;
13460 }
13461
13462 sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
13463 if (sym_index >= num_syms)
13464 {
13465 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
13466 sym_index, printable_section_name (filedata, section));
13467 continue;
13468 }
13469 sym = symtab + sym_index;
13470
13471 /* If the reloc has a symbol associated with it,
13472 make sure that it is of an appropriate type.
13473
13474 Relocations against symbols without type can happen.
13475 Gcc -feliminate-dwarf2-dups may generate symbols
13476 without type for debug info.
13477
13478 Icc generates relocations against function symbols
13479 instead of local labels.
13480
13481 Relocations against object symbols can happen, eg when
13482 referencing a global array. For an example of this see
13483 the _clz.o binary in libgcc.a. */
13484 if (sym != symtab
13485 && ELF_ST_TYPE (sym->st_info) != STT_COMMON
13486 && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
13487 {
13488 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
13489 get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)),
13490 printable_section_name (filedata, relsec),
13491 (long int)(rp - relocs));
13492 continue;
13493 }
13494
13495 addend = 0;
13496 if (is_rela)
13497 addend += rp->r_addend;
13498 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
13499 partial_inplace. */
13500 if (!is_rela
13501 || (filedata->file_header.e_machine == EM_XTENSA
13502 && reloc_type == 1)
13503 || ((filedata->file_header.e_machine == EM_PJ
13504 || filedata->file_header.e_machine == EM_PJ_OLD)
13505 && reloc_type == 1)
13506 || ((filedata->file_header.e_machine == EM_D30V
13507 || filedata->file_header.e_machine == EM_CYGNUS_D30V)
13508 && reloc_type == 12)
13509 || reloc_inplace)
13510 {
13511 if (is_6bit_inplace_sub_reloc (filedata, reloc_type))
13512 addend += byte_get (rloc, reloc_size) & 0x3f;
13513 else
13514 addend += byte_get (rloc, reloc_size);
13515 }
13516
13517 if (is_32bit_pcrel_reloc (filedata, reloc_type)
13518 || is_64bit_pcrel_reloc (filedata, reloc_type))
13519 {
13520 /* On HPPA, all pc-relative relocations are biased by 8. */
13521 if (filedata->file_header.e_machine == EM_PARISC)
13522 addend -= 8;
13523 byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
13524 reloc_size);
13525 }
13526 else if (is_6bit_abs_reloc (filedata, reloc_type)
13527 || is_6bit_inplace_sub_reloc (filedata, reloc_type))
13528 {
13529 if (reloc_subtract)
13530 addend -= sym->st_value;
13531 else
13532 addend += sym->st_value;
13533 addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0);
13534 byte_put (rloc, addend, reloc_size);
13535 }
13536 else if (reloc_subtract)
13537 byte_put (rloc, addend - sym->st_value, reloc_size);
13538 else
13539 byte_put (rloc, addend + sym->st_value, reloc_size);
13540 }
13541
13542 free (symtab);
13543 /* Let the target specific reloc processing code know that
13544 we have finished with these relocs. */
13545 target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0);
13546
13547 if (relocs_return)
13548 {
13549 * (Elf_Internal_Rela **) relocs_return = relocs;
13550 * num_relocs_return = num_relocs;
13551 }
13552 else
13553 free (relocs);
13554
13555 break;
13556 }
13557
13558 return TRUE;
13559 }
13560
13561 #ifdef SUPPORT_DISASSEMBLY
13562 static bfd_boolean
13563 disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata)
13564 {
13565 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section));
13566
13567 /* FIXME: XXX -- to be done --- XXX */
13568
13569 return TRUE;
13570 }
13571 #endif
13572
13573 /* Reads in the contents of SECTION from FILE, returning a pointer
13574 to a malloc'ed buffer or NULL if something went wrong. */
13575
13576 static char *
13577 get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata)
13578 {
13579 bfd_size_type num_bytes = section->sh_size;
13580
13581 if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
13582 {
13583 printf (_("Section '%s' has no data to dump.\n"),
13584 printable_section_name (filedata, section));
13585 return NULL;
13586 }
13587
13588 return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes,
13589 _("section contents"));
13590 }
13591
13592 /* Uncompresses a section that was compressed using zlib, in place. */
13593
13594 static bfd_boolean
13595 uncompress_section_contents (unsigned char ** buffer,
13596 dwarf_size_type uncompressed_size,
13597 dwarf_size_type * size)
13598 {
13599 dwarf_size_type compressed_size = *size;
13600 unsigned char * compressed_buffer = *buffer;
13601 unsigned char * uncompressed_buffer;
13602 z_stream strm;
13603 int rc;
13604
13605 /* It is possible the section consists of several compressed
13606 buffers concatenated together, so we uncompress in a loop. */
13607 /* PR 18313: The state field in the z_stream structure is supposed
13608 to be invisible to the user (ie us), but some compilers will
13609 still complain about it being used without initialisation. So
13610 we first zero the entire z_stream structure and then set the fields
13611 that we need. */
13612 memset (& strm, 0, sizeof strm);
13613 strm.avail_in = compressed_size;
13614 strm.next_in = (Bytef *) compressed_buffer;
13615 strm.avail_out = uncompressed_size;
13616 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
13617
13618 rc = inflateInit (& strm);
13619 while (strm.avail_in > 0)
13620 {
13621 if (rc != Z_OK)
13622 goto fail;
13623 strm.next_out = ((Bytef *) uncompressed_buffer
13624 + (uncompressed_size - strm.avail_out));
13625 rc = inflate (&strm, Z_FINISH);
13626 if (rc != Z_STREAM_END)
13627 goto fail;
13628 rc = inflateReset (& strm);
13629 }
13630 rc = inflateEnd (& strm);
13631 if (rc != Z_OK
13632 || strm.avail_out != 0)
13633 goto fail;
13634
13635 *buffer = uncompressed_buffer;
13636 *size = uncompressed_size;
13637 return TRUE;
13638
13639 fail:
13640 free (uncompressed_buffer);
13641 /* Indicate decompression failure. */
13642 *buffer = NULL;
13643 return FALSE;
13644 }
13645
13646 static bfd_boolean
13647 dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
13648 {
13649 Elf_Internal_Shdr * relsec;
13650 bfd_size_type num_bytes;
13651 unsigned char * data;
13652 unsigned char * end;
13653 unsigned char * real_start;
13654 unsigned char * start;
13655 bfd_boolean some_strings_shown;
13656
13657 real_start = start = (unsigned char *) get_section_contents (section, filedata);
13658 if (start == NULL)
13659 /* PR 21820: Do not fail if the section was empty. */
13660 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
13661
13662 num_bytes = section->sh_size;
13663
13664 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata, section));
13665
13666 if (decompress_dumps)
13667 {
13668 dwarf_size_type new_size = num_bytes;
13669 dwarf_size_type uncompressed_size = 0;
13670
13671 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13672 {
13673 Elf_Internal_Chdr chdr;
13674 unsigned int compression_header_size
13675 = get_compression_header (& chdr, (unsigned char *) start,
13676 num_bytes);
13677
13678 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
13679 {
13680 warn (_("section '%s' has unsupported compress type: %d\n"),
13681 printable_section_name (filedata, section), chdr.ch_type);
13682 return FALSE;
13683 }
13684 uncompressed_size = chdr.ch_size;
13685 start += compression_header_size;
13686 new_size -= compression_header_size;
13687 }
13688 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13689 {
13690 /* Read the zlib header. In this case, it should be "ZLIB"
13691 followed by the uncompressed section size, 8 bytes in
13692 big-endian order. */
13693 uncompressed_size = start[4]; uncompressed_size <<= 8;
13694 uncompressed_size += start[5]; uncompressed_size <<= 8;
13695 uncompressed_size += start[6]; uncompressed_size <<= 8;
13696 uncompressed_size += start[7]; uncompressed_size <<= 8;
13697 uncompressed_size += start[8]; uncompressed_size <<= 8;
13698 uncompressed_size += start[9]; uncompressed_size <<= 8;
13699 uncompressed_size += start[10]; uncompressed_size <<= 8;
13700 uncompressed_size += start[11];
13701 start += 12;
13702 new_size -= 12;
13703 }
13704
13705 if (uncompressed_size)
13706 {
13707 if (uncompress_section_contents (& start,
13708 uncompressed_size, & new_size))
13709 num_bytes = new_size;
13710 else
13711 {
13712 error (_("Unable to decompress section %s\n"),
13713 printable_section_name (filedata, section));
13714 return FALSE;
13715 }
13716 }
13717 else
13718 start = real_start;
13719 }
13720
13721 /* If the section being dumped has relocations against it the user might
13722 be expecting these relocations to have been applied. Check for this
13723 case and issue a warning message in order to avoid confusion.
13724 FIXME: Maybe we ought to have an option that dumps a section with
13725 relocs applied ? */
13726 for (relsec = filedata->section_headers;
13727 relsec < filedata->section_headers + filedata->file_header.e_shnum;
13728 ++relsec)
13729 {
13730 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
13731 || relsec->sh_info >= filedata->file_header.e_shnum
13732 || filedata->section_headers + relsec->sh_info != section
13733 || relsec->sh_size == 0
13734 || relsec->sh_link >= filedata->file_header.e_shnum)
13735 continue;
13736
13737 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13738 break;
13739 }
13740
13741 data = start;
13742 end = start + num_bytes;
13743 some_strings_shown = FALSE;
13744
13745 while (data < end)
13746 {
13747 while (!ISPRINT (* data))
13748 if (++ data >= end)
13749 break;
13750
13751 if (data < end)
13752 {
13753 size_t maxlen = end - data;
13754
13755 #ifndef __MSVCRT__
13756 /* PR 11128: Use two separate invocations in order to work
13757 around bugs in the Solaris 8 implementation of printf. */
13758 printf (" [%6tx] ", data - start);
13759 #else
13760 printf (" [%6Ix] ", (size_t) (data - start));
13761 #endif
13762 if (maxlen > 0)
13763 {
13764 print_symbol ((int) maxlen, (const char *) data);
13765 putchar ('\n');
13766 data += strnlen ((const char *) data, maxlen);
13767 }
13768 else
13769 {
13770 printf (_("<corrupt>\n"));
13771 data = end;
13772 }
13773 some_strings_shown = TRUE;
13774 }
13775 }
13776
13777 if (! some_strings_shown)
13778 printf (_(" No strings found in this section."));
13779
13780 free (real_start);
13781
13782 putchar ('\n');
13783 return TRUE;
13784 }
13785
13786 static bfd_boolean
13787 dump_section_as_bytes (Elf_Internal_Shdr * section,
13788 Filedata * filedata,
13789 bfd_boolean relocate)
13790 {
13791 Elf_Internal_Shdr * relsec;
13792 bfd_size_type bytes;
13793 bfd_size_type section_size;
13794 bfd_vma addr;
13795 unsigned char * data;
13796 unsigned char * real_start;
13797 unsigned char * start;
13798
13799 real_start = start = (unsigned char *) get_section_contents (section, filedata);
13800 if (start == NULL)
13801 /* PR 21820: Do not fail if the section was empty. */
13802 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
13803
13804 section_size = section->sh_size;
13805
13806 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata, section));
13807
13808 if (decompress_dumps)
13809 {
13810 dwarf_size_type new_size = section_size;
13811 dwarf_size_type uncompressed_size = 0;
13812
13813 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13814 {
13815 Elf_Internal_Chdr chdr;
13816 unsigned int compression_header_size
13817 = get_compression_header (& chdr, start, section_size);
13818
13819 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
13820 {
13821 warn (_("section '%s' has unsupported compress type: %d\n"),
13822 printable_section_name (filedata, section), chdr.ch_type);
13823 return FALSE;
13824 }
13825 uncompressed_size = chdr.ch_size;
13826 start += compression_header_size;
13827 new_size -= compression_header_size;
13828 }
13829 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13830 {
13831 /* Read the zlib header. In this case, it should be "ZLIB"
13832 followed by the uncompressed section size, 8 bytes in
13833 big-endian order. */
13834 uncompressed_size = start[4]; uncompressed_size <<= 8;
13835 uncompressed_size += start[5]; uncompressed_size <<= 8;
13836 uncompressed_size += start[6]; uncompressed_size <<= 8;
13837 uncompressed_size += start[7]; uncompressed_size <<= 8;
13838 uncompressed_size += start[8]; uncompressed_size <<= 8;
13839 uncompressed_size += start[9]; uncompressed_size <<= 8;
13840 uncompressed_size += start[10]; uncompressed_size <<= 8;
13841 uncompressed_size += start[11];
13842 start += 12;
13843 new_size -= 12;
13844 }
13845
13846 if (uncompressed_size)
13847 {
13848 if (uncompress_section_contents (& start, uncompressed_size,
13849 & new_size))
13850 {
13851 section_size = new_size;
13852 }
13853 else
13854 {
13855 error (_("Unable to decompress section %s\n"),
13856 printable_section_name (filedata, section));
13857 /* FIXME: Print the section anyway ? */
13858 return FALSE;
13859 }
13860 }
13861 else
13862 start = real_start;
13863 }
13864
13865 if (relocate)
13866 {
13867 if (! apply_relocations (filedata, section, start, section_size, NULL, NULL))
13868 return FALSE;
13869 }
13870 else
13871 {
13872 /* If the section being dumped has relocations against it the user might
13873 be expecting these relocations to have been applied. Check for this
13874 case and issue a warning message in order to avoid confusion.
13875 FIXME: Maybe we ought to have an option that dumps a section with
13876 relocs applied ? */
13877 for (relsec = filedata->section_headers;
13878 relsec < filedata->section_headers + filedata->file_header.e_shnum;
13879 ++relsec)
13880 {
13881 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
13882 || relsec->sh_info >= filedata->file_header.e_shnum
13883 || filedata->section_headers + relsec->sh_info != section
13884 || relsec->sh_size == 0
13885 || relsec->sh_link >= filedata->file_header.e_shnum)
13886 continue;
13887
13888 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13889 break;
13890 }
13891 }
13892
13893 addr = section->sh_addr;
13894 bytes = section_size;
13895 data = start;
13896
13897 while (bytes)
13898 {
13899 int j;
13900 int k;
13901 int lbytes;
13902
13903 lbytes = (bytes > 16 ? 16 : bytes);
13904
13905 printf (" 0x%8.8lx ", (unsigned long) addr);
13906
13907 for (j = 0; j < 16; j++)
13908 {
13909 if (j < lbytes)
13910 printf ("%2.2x", data[j]);
13911 else
13912 printf (" ");
13913
13914 if ((j & 3) == 3)
13915 printf (" ");
13916 }
13917
13918 for (j = 0; j < lbytes; j++)
13919 {
13920 k = data[j];
13921 if (k >= ' ' && k < 0x7f)
13922 printf ("%c", k);
13923 else
13924 printf (".");
13925 }
13926
13927 putchar ('\n');
13928
13929 data += lbytes;
13930 addr += lbytes;
13931 bytes -= lbytes;
13932 }
13933
13934 free (real_start);
13935
13936 putchar ('\n');
13937 return TRUE;
13938 }
13939
13940 static ctf_sect_t *
13941 shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata)
13942 {
13943 buf->cts_name = SECTION_NAME (shdr);
13944 buf->cts_size = shdr->sh_size;
13945 buf->cts_entsize = shdr->sh_entsize;
13946
13947 return buf;
13948 }
13949
13950 /* Formatting callback function passed to ctf_dump. Returns either the pointer
13951 it is passed, or a pointer to newly-allocated storage, in which case
13952 dump_ctf() will free it when it no longer needs it. */
13953
13954 static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
13955 char *s, void *arg)
13956 {
13957 const char *blanks = arg;
13958 char *new_s;
13959
13960 if (asprintf (&new_s, "%s%s", blanks, s) < 0)
13961 return s;
13962 return new_s;
13963 }
13964
13965 static bfd_boolean
13966 dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
13967 {
13968 Elf_Internal_Shdr * parent_sec = NULL;
13969 Elf_Internal_Shdr * symtab_sec = NULL;
13970 Elf_Internal_Shdr * strtab_sec = NULL;
13971 void * data = NULL;
13972 void * symdata = NULL;
13973 void * strdata = NULL;
13974 void * parentdata = NULL;
13975 ctf_sect_t ctfsect, symsect, strsect, parentsect;
13976 ctf_sect_t * symsectp = NULL;
13977 ctf_sect_t * strsectp = NULL;
13978 ctf_file_t * ctf = NULL;
13979 ctf_file_t * parent = NULL;
13980
13981 const char *things[] = {"Header", "Labels", "Data objects",
13982 "Function objects", "Variables", "Types", "Strings",
13983 ""};
13984 const char **thing;
13985 int err;
13986 bfd_boolean ret = FALSE;
13987 size_t i;
13988
13989 shdr_to_ctf_sect (&ctfsect, section, filedata);
13990 data = get_section_contents (section, filedata);
13991 ctfsect.cts_data = data;
13992
13993 if (!dump_ctf_symtab_name)
13994 dump_ctf_symtab_name = strdup (".symtab");
13995
13996 if (!dump_ctf_strtab_name)
13997 dump_ctf_strtab_name = strdup (".strtab");
13998
13999 if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0)
14000 {
14001 if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL)
14002 {
14003 error (_("No symbol section named %s\n"), dump_ctf_symtab_name);
14004 goto fail;
14005 }
14006 if ((symdata = (void *) get_data (NULL, filedata,
14007 symtab_sec->sh_offset, 1,
14008 symtab_sec->sh_size,
14009 _("symbols"))) == NULL)
14010 goto fail;
14011 symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata);
14012 symsect.cts_data = symdata;
14013 }
14014 if (dump_ctf_strtab_name && dump_ctf_symtab_name[0] != 0)
14015 {
14016 if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL)
14017 {
14018 error (_("No string table section named %s\n"),
14019 dump_ctf_strtab_name);
14020 goto fail;
14021 }
14022 if ((strdata = (void *) get_data (NULL, filedata,
14023 strtab_sec->sh_offset, 1,
14024 strtab_sec->sh_size,
14025 _("strings"))) == NULL)
14026 goto fail;
14027 strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata);
14028 strsect.cts_data = strdata;
14029 }
14030 if (dump_ctf_parent_name)
14031 {
14032 if ((parent_sec = find_section (filedata, dump_ctf_parent_name)) == NULL)
14033 {
14034 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name);
14035 goto fail;
14036 }
14037 if ((parentdata = (void *) get_data (NULL, filedata,
14038 parent_sec->sh_offset, 1,
14039 parent_sec->sh_size,
14040 _("CTF parent"))) == NULL)
14041 goto fail;
14042 shdr_to_ctf_sect (&parentsect, parent_sec, filedata);
14043 parentsect.cts_data = parentdata;
14044 }
14045
14046 /* Load the CTF file and dump it. */
14047
14048 if ((ctf = ctf_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
14049 {
14050 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
14051 goto fail;
14052 }
14053
14054 if (parentdata)
14055 {
14056 if ((parent = ctf_bufopen (&parentsect, symsectp, strsectp, &err)) == NULL)
14057 {
14058 error (_("CTF open failure: %s\n"), ctf_errmsg (err));
14059 goto fail;
14060 }
14061
14062 ctf_import (ctf, parent);
14063 }
14064
14065 ret = TRUE;
14066
14067 printf (_("\nDump of CTF section '%s':\n"),
14068 printable_section_name (filedata, section));
14069
14070 for (i = 0, thing = things; *thing[0]; thing++, i++)
14071 {
14072 ctf_dump_state_t *s = NULL;
14073 char *item;
14074
14075 printf ("\n %s:\n", *thing);
14076 while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
14077 (void *) " ")) != NULL)
14078 {
14079 printf ("%s\n", item);
14080 free (item);
14081 }
14082
14083 if (ctf_errno (ctf))
14084 {
14085 error (_("Iteration failed: %s, %s\n"), *thing,
14086 ctf_errmsg (ctf_errno (ctf)));
14087 ret = FALSE;
14088 }
14089 }
14090
14091 fail:
14092 ctf_file_close (ctf);
14093 ctf_file_close (parent);
14094 free (parentdata);
14095 free (data);
14096 free (symdata);
14097 free (strdata);
14098 return ret;
14099 }
14100
14101 static bfd_boolean
14102 load_specific_debug_section (enum dwarf_section_display_enum debug,
14103 const Elf_Internal_Shdr * sec,
14104 void * data)
14105 {
14106 struct dwarf_section * section = &debug_displays [debug].section;
14107 char buf [64];
14108 Filedata * filedata = (Filedata *) data;
14109
14110 if (section->start != NULL)
14111 {
14112 /* If it is already loaded, do nothing. */
14113 if (streq (section->filename, filedata->file_name))
14114 return TRUE;
14115 free (section->start);
14116 }
14117
14118 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
14119 section->address = sec->sh_addr;
14120 section->user_data = NULL;
14121 section->filename = filedata->file_name;
14122 section->start = (unsigned char *) get_data (NULL, filedata,
14123 sec->sh_offset, 1,
14124 sec->sh_size, buf);
14125 if (section->start == NULL)
14126 section->size = 0;
14127 else
14128 {
14129 unsigned char *start = section->start;
14130 dwarf_size_type size = sec->sh_size;
14131 dwarf_size_type uncompressed_size = 0;
14132
14133 if ((sec->sh_flags & SHF_COMPRESSED) != 0)
14134 {
14135 Elf_Internal_Chdr chdr;
14136 unsigned int compression_header_size;
14137
14138 if (size < (is_32bit_elf
14139 ? sizeof (Elf32_External_Chdr)
14140 : sizeof (Elf64_External_Chdr)))
14141 {
14142 warn (_("compressed section %s is too small to contain a compression header"),
14143 section->name);
14144 return FALSE;
14145 }
14146
14147 compression_header_size = get_compression_header (&chdr, start, size);
14148
14149 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
14150 {
14151 warn (_("section '%s' has unsupported compress type: %d\n"),
14152 section->name, chdr.ch_type);
14153 return FALSE;
14154 }
14155 uncompressed_size = chdr.ch_size;
14156 start += compression_header_size;
14157 size -= compression_header_size;
14158 }
14159 else if (size > 12 && streq ((char *) start, "ZLIB"))
14160 {
14161 /* Read the zlib header. In this case, it should be "ZLIB"
14162 followed by the uncompressed section size, 8 bytes in
14163 big-endian order. */
14164 uncompressed_size = start[4]; uncompressed_size <<= 8;
14165 uncompressed_size += start[5]; uncompressed_size <<= 8;
14166 uncompressed_size += start[6]; uncompressed_size <<= 8;
14167 uncompressed_size += start[7]; uncompressed_size <<= 8;
14168 uncompressed_size += start[8]; uncompressed_size <<= 8;
14169 uncompressed_size += start[9]; uncompressed_size <<= 8;
14170 uncompressed_size += start[10]; uncompressed_size <<= 8;
14171 uncompressed_size += start[11];
14172 start += 12;
14173 size -= 12;
14174 }
14175
14176 if (uncompressed_size)
14177 {
14178 if (uncompress_section_contents (&start, uncompressed_size,
14179 &size))
14180 {
14181 /* Free the compressed buffer, update the section buffer
14182 and the section size if uncompress is successful. */
14183 free (section->start);
14184 section->start = start;
14185 }
14186 else
14187 {
14188 error (_("Unable to decompress section %s\n"),
14189 printable_section_name (filedata, sec));
14190 return FALSE;
14191 }
14192 }
14193
14194 section->size = size;
14195 }
14196
14197 if (section->start == NULL)
14198 return FALSE;
14199
14200 if (debug_displays [debug].relocate)
14201 {
14202 if (! apply_relocations (filedata, sec, section->start, section->size,
14203 & section->reloc_info, & section->num_relocs))
14204 return FALSE;
14205 }
14206 else
14207 {
14208 section->reloc_info = NULL;
14209 section->num_relocs = 0;
14210 }
14211
14212 return TRUE;
14213 }
14214
14215 /* If this is not NULL, load_debug_section will only look for sections
14216 within the list of sections given here. */
14217 static unsigned int * section_subset = NULL;
14218
14219 bfd_boolean
14220 load_debug_section (enum dwarf_section_display_enum debug, void * data)
14221 {
14222 struct dwarf_section * section = &debug_displays [debug].section;
14223 Elf_Internal_Shdr * sec;
14224 Filedata * filedata = (Filedata *) data;
14225
14226 /* Without section headers we cannot find any sections. */
14227 if (filedata->section_headers == NULL)
14228 return FALSE;
14229
14230 if (filedata->string_table == NULL
14231 && filedata->file_header.e_shstrndx != SHN_UNDEF
14232 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
14233 {
14234 Elf_Internal_Shdr * strs;
14235
14236 /* Read in the string table, so that we have section names to scan. */
14237 strs = filedata->section_headers + filedata->file_header.e_shstrndx;
14238
14239 if (strs != NULL && strs->sh_size != 0)
14240 {
14241 filedata->string_table
14242 = (char *) get_data (NULL, filedata, strs->sh_offset,
14243 1, strs->sh_size, _("string table"));
14244
14245 filedata->string_table_length
14246 = filedata->string_table != NULL ? strs->sh_size : 0;
14247 }
14248 }
14249
14250 /* Locate the debug section. */
14251 sec = find_section_in_set (filedata, section->uncompressed_name, section_subset);
14252 if (sec != NULL)
14253 section->name = section->uncompressed_name;
14254 else
14255 {
14256 sec = find_section_in_set (filedata, section->compressed_name, section_subset);
14257 if (sec != NULL)
14258 section->name = section->compressed_name;
14259 }
14260 if (sec == NULL)
14261 return FALSE;
14262
14263 /* If we're loading from a subset of sections, and we've loaded
14264 a section matching this name before, it's likely that it's a
14265 different one. */
14266 if (section_subset != NULL)
14267 free_debug_section (debug);
14268
14269 return load_specific_debug_section (debug, sec, data);
14270 }
14271
14272 void
14273 free_debug_section (enum dwarf_section_display_enum debug)
14274 {
14275 struct dwarf_section * section = &debug_displays [debug].section;
14276
14277 if (section->start == NULL)
14278 return;
14279
14280 free ((char *) section->start);
14281 section->start = NULL;
14282 section->address = 0;
14283 section->size = 0;
14284 }
14285
14286 static bfd_boolean
14287 display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata)
14288 {
14289 char * name = SECTION_NAME (section);
14290 const char * print_name = printable_section_name (filedata, section);
14291 bfd_size_type length;
14292 bfd_boolean result = TRUE;
14293 int i;
14294
14295 length = section->sh_size;
14296 if (length == 0)
14297 {
14298 printf (_("\nSection '%s' has no debugging data.\n"), print_name);
14299 return TRUE;
14300 }
14301 if (section->sh_type == SHT_NOBITS)
14302 {
14303 /* There is no point in dumping the contents of a debugging section
14304 which has the NOBITS type - the bits in the file will be random.
14305 This can happen when a file containing a .eh_frame section is
14306 stripped with the --only-keep-debug command line option. */
14307 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
14308 print_name);
14309 return FALSE;
14310 }
14311
14312 if (const_strneq (name, ".gnu.linkonce.wi."))
14313 name = ".debug_info";
14314
14315 /* See if we know how to display the contents of this section. */
14316 for (i = 0; i < max; i++)
14317 {
14318 enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i;
14319 struct dwarf_section_display * display = debug_displays + i;
14320 struct dwarf_section * sec = & display->section;
14321
14322 if (streq (sec->uncompressed_name, name)
14323 || (id == line && const_strneq (name, ".debug_line."))
14324 || streq (sec->compressed_name, name))
14325 {
14326 bfd_boolean secondary = (section != find_section (filedata, name));
14327
14328 if (secondary)
14329 free_debug_section (id);
14330
14331 if (i == line && const_strneq (name, ".debug_line."))
14332 sec->name = name;
14333 else if (streq (sec->uncompressed_name, name))
14334 sec->name = sec->uncompressed_name;
14335 else
14336 sec->name = sec->compressed_name;
14337
14338 if (load_specific_debug_section (id, section, filedata))
14339 {
14340 /* If this debug section is part of a CU/TU set in a .dwp file,
14341 restrict load_debug_section to the sections in that set. */
14342 section_subset = find_cu_tu_set (filedata, shndx);
14343
14344 result &= display->display (sec, filedata);
14345
14346 section_subset = NULL;
14347
14348 if (secondary || (id != info && id != abbrev))
14349 free_debug_section (id);
14350 }
14351 break;
14352 }
14353 }
14354
14355 if (i == max)
14356 {
14357 printf (_("Unrecognized debug section: %s\n"), print_name);
14358 result = FALSE;
14359 }
14360
14361 return result;
14362 }
14363
14364 /* Set DUMP_SECTS for all sections where dumps were requested
14365 based on section name. */
14366
14367 static void
14368 initialise_dumps_byname (Filedata * filedata)
14369 {
14370 struct dump_list_entry * cur;
14371
14372 for (cur = dump_sects_byname; cur; cur = cur->next)
14373 {
14374 unsigned int i;
14375 bfd_boolean any = FALSE;
14376
14377 for (i = 0; i < filedata->file_header.e_shnum; i++)
14378 if (streq (SECTION_NAME (filedata->section_headers + i), cur->name))
14379 {
14380 request_dump_bynumber (filedata, i, cur->type);
14381 any = TRUE;
14382 }
14383
14384 if (!any)
14385 warn (_("Section '%s' was not dumped because it does not exist!\n"),
14386 cur->name);
14387 }
14388 }
14389
14390 static bfd_boolean
14391 process_section_contents (Filedata * filedata)
14392 {
14393 Elf_Internal_Shdr * section;
14394 unsigned int i;
14395 bfd_boolean res = TRUE;
14396
14397 if (! do_dump)
14398 return TRUE;
14399
14400 initialise_dumps_byname (filedata);
14401
14402 for (i = 0, section = filedata->section_headers;
14403 i < filedata->file_header.e_shnum && i < filedata->num_dump_sects;
14404 i++, section++)
14405 {
14406 dump_type dump = filedata->dump_sects[i];
14407
14408 #ifdef SUPPORT_DISASSEMBLY
14409 if (dump & DISASS_DUMP)
14410 {
14411 if (! disassemble_section (section, filedata))
14412 res = FALSE;
14413 }
14414 #endif
14415 if (dump & HEX_DUMP)
14416 {
14417 if (! dump_section_as_bytes (section, filedata, FALSE))
14418 res = FALSE;
14419 }
14420
14421 if (dump & RELOC_DUMP)
14422 {
14423 if (! dump_section_as_bytes (section, filedata, TRUE))
14424 res = FALSE;
14425 }
14426
14427 if (dump & STRING_DUMP)
14428 {
14429 if (! dump_section_as_strings (section, filedata))
14430 res = FALSE;
14431 }
14432
14433 if (dump & DEBUG_DUMP)
14434 {
14435 if (! display_debug_section (i, section, filedata))
14436 res = FALSE;
14437 }
14438
14439 if (dump & CTF_DUMP)
14440 {
14441 if (! dump_section_as_ctf (section, filedata))
14442 res = FALSE;
14443 }
14444 }
14445
14446 /* Check to see if the user requested a
14447 dump of a section that does not exist. */
14448 while (i < filedata->num_dump_sects)
14449 {
14450 if (filedata->dump_sects[i])
14451 {
14452 warn (_("Section %d was not dumped because it does not exist!\n"), i);
14453 res = FALSE;
14454 }
14455 i++;
14456 }
14457
14458 return res;
14459 }
14460
14461 static void
14462 process_mips_fpe_exception (int mask)
14463 {
14464 if (mask)
14465 {
14466 bfd_boolean first = TRUE;
14467
14468 if (mask & OEX_FPU_INEX)
14469 fputs ("INEX", stdout), first = FALSE;
14470 if (mask & OEX_FPU_UFLO)
14471 printf ("%sUFLO", first ? "" : "|"), first = FALSE;
14472 if (mask & OEX_FPU_OFLO)
14473 printf ("%sOFLO", first ? "" : "|"), first = FALSE;
14474 if (mask & OEX_FPU_DIV0)
14475 printf ("%sDIV0", first ? "" : "|"), first = FALSE;
14476 if (mask & OEX_FPU_INVAL)
14477 printf ("%sINVAL", first ? "" : "|");
14478 }
14479 else
14480 fputs ("0", stdout);
14481 }
14482
14483 /* Display's the value of TAG at location P. If TAG is
14484 greater than 0 it is assumed to be an unknown tag, and
14485 a message is printed to this effect. Otherwise it is
14486 assumed that a message has already been printed.
14487
14488 If the bottom bit of TAG is set it assumed to have a
14489 string value, otherwise it is assumed to have an integer
14490 value.
14491
14492 Returns an updated P pointing to the first unread byte
14493 beyond the end of TAG's value.
14494
14495 Reads at or beyond END will not be made. */
14496
14497 static unsigned char *
14498 display_tag_value (signed int tag,
14499 unsigned char * p,
14500 const unsigned char * const end)
14501 {
14502 unsigned long val;
14503
14504 if (tag > 0)
14505 printf (" Tag_unknown_%d: ", tag);
14506
14507 if (p >= end)
14508 {
14509 warn (_("<corrupt tag>\n"));
14510 }
14511 else if (tag & 1)
14512 {
14513 /* PR 17531 file: 027-19978-0.004. */
14514 size_t maxlen = (end - p) - 1;
14515
14516 putchar ('"');
14517 if (maxlen > 0)
14518 {
14519 print_symbol ((int) maxlen, (const char *) p);
14520 p += strnlen ((char *) p, maxlen) + 1;
14521 }
14522 else
14523 {
14524 printf (_("<corrupt string tag>"));
14525 p = (unsigned char *) end;
14526 }
14527 printf ("\"\n");
14528 }
14529 else
14530 {
14531 unsigned int len;
14532
14533 val = read_uleb128 (p, &len, end);
14534 p += len;
14535 printf ("%ld (0x%lx)\n", val, val);
14536 }
14537
14538 assert (p <= end);
14539 return p;
14540 }
14541
14542 /* ARC ABI attributes section. */
14543
14544 static unsigned char *
14545 display_arc_attribute (unsigned char * p,
14546 const unsigned char * const end)
14547 {
14548 unsigned int tag;
14549 unsigned int len;
14550 unsigned int val;
14551
14552 tag = read_uleb128 (p, &len, end);
14553 p += len;
14554
14555 switch (tag)
14556 {
14557 case Tag_ARC_PCS_config:
14558 val = read_uleb128 (p, &len, end);
14559 p += len;
14560 printf (" Tag_ARC_PCS_config: ");
14561 switch (val)
14562 {
14563 case 0:
14564 printf (_("Absent/Non standard\n"));
14565 break;
14566 case 1:
14567 printf (_("Bare metal/mwdt\n"));
14568 break;
14569 case 2:
14570 printf (_("Bare metal/newlib\n"));
14571 break;
14572 case 3:
14573 printf (_("Linux/uclibc\n"));
14574 break;
14575 case 4:
14576 printf (_("Linux/glibc\n"));
14577 break;
14578 default:
14579 printf (_("Unknown\n"));
14580 break;
14581 }
14582 break;
14583
14584 case Tag_ARC_CPU_base:
14585 val = read_uleb128 (p, &len, end);
14586 p += len;
14587 printf (" Tag_ARC_CPU_base: ");
14588 switch (val)
14589 {
14590 default:
14591 case TAG_CPU_NONE:
14592 printf (_("Absent\n"));
14593 break;
14594 case TAG_CPU_ARC6xx:
14595 printf ("ARC6xx\n");
14596 break;
14597 case TAG_CPU_ARC7xx:
14598 printf ("ARC7xx\n");
14599 break;
14600 case TAG_CPU_ARCEM:
14601 printf ("ARCEM\n");
14602 break;
14603 case TAG_CPU_ARCHS:
14604 printf ("ARCHS\n");
14605 break;
14606 }
14607 break;
14608
14609 case Tag_ARC_CPU_variation:
14610 val = read_uleb128 (p, &len, end);
14611 p += len;
14612 printf (" Tag_ARC_CPU_variation: ");
14613 switch (val)
14614 {
14615 default:
14616 if (val > 0 && val < 16)
14617 printf ("Core%d\n", val);
14618 else
14619 printf ("Unknown\n");
14620 break;
14621
14622 case 0:
14623 printf (_("Absent\n"));
14624 break;
14625 }
14626 break;
14627
14628 case Tag_ARC_CPU_name:
14629 printf (" Tag_ARC_CPU_name: ");
14630 p = display_tag_value (-1, p, end);
14631 break;
14632
14633 case Tag_ARC_ABI_rf16:
14634 val = read_uleb128 (p, &len, end);
14635 p += len;
14636 printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
14637 break;
14638
14639 case Tag_ARC_ABI_osver:
14640 val = read_uleb128 (p, &len, end);
14641 p += len;
14642 printf (" Tag_ARC_ABI_osver: v%d\n", val);
14643 break;
14644
14645 case Tag_ARC_ABI_pic:
14646 case Tag_ARC_ABI_sda:
14647 val = read_uleb128 (p, &len, end);
14648 p += len;
14649 printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
14650 : " Tag_ARC_ABI_pic: ");
14651 switch (val)
14652 {
14653 case 0:
14654 printf (_("Absent\n"));
14655 break;
14656 case 1:
14657 printf ("MWDT\n");
14658 break;
14659 case 2:
14660 printf ("GNU\n");
14661 break;
14662 default:
14663 printf (_("Unknown\n"));
14664 break;
14665 }
14666 break;
14667
14668 case Tag_ARC_ABI_tls:
14669 val = read_uleb128 (p, &len, end);
14670 p += len;
14671 printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
14672 break;
14673
14674 case Tag_ARC_ABI_enumsize:
14675 val = read_uleb128 (p, &len, end);
14676 p += len;
14677 printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
14678 _("smallest"));
14679 break;
14680
14681 case Tag_ARC_ABI_exceptions:
14682 val = read_uleb128 (p, &len, end);
14683 p += len;
14684 printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
14685 : _("default"));
14686 break;
14687
14688 case Tag_ARC_ABI_double_size:
14689 val = read_uleb128 (p, &len, end);
14690 p += len;
14691 printf (" Tag_ARC_ABI_double_size: %d\n", val);
14692 break;
14693
14694 case Tag_ARC_ISA_config:
14695 printf (" Tag_ARC_ISA_config: ");
14696 p = display_tag_value (-1, p, end);
14697 break;
14698
14699 case Tag_ARC_ISA_apex:
14700 printf (" Tag_ARC_ISA_apex: ");
14701 p = display_tag_value (-1, p, end);
14702 break;
14703
14704 case Tag_ARC_ISA_mpy_option:
14705 val = read_uleb128 (p, &len, end);
14706 p += len;
14707 printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
14708 break;
14709
14710 case Tag_ARC_ATR_version:
14711 val = read_uleb128 (p, &len, end);
14712 p += len;
14713 printf (" Tag_ARC_ATR_version: %d\n", val);
14714 break;
14715
14716 default:
14717 return display_tag_value (tag & 1, p, end);
14718 }
14719
14720 return p;
14721 }
14722
14723 /* ARM EABI attributes section. */
14724 typedef struct
14725 {
14726 unsigned int tag;
14727 const char * name;
14728 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
14729 unsigned int type;
14730 const char ** table;
14731 } arm_attr_public_tag;
14732
14733 static const char * arm_attr_tag_CPU_arch[] =
14734 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
14735 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
14736 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
14737 static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
14738 static const char * arm_attr_tag_THUMB_ISA_use[] =
14739 {"No", "Thumb-1", "Thumb-2", "Yes"};
14740 static const char * arm_attr_tag_FP_arch[] =
14741 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
14742 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
14743 static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
14744 static const char * arm_attr_tag_Advanced_SIMD_arch[] =
14745 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
14746 "NEON for ARMv8.1"};
14747 static const char * arm_attr_tag_PCS_config[] =
14748 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
14749 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
14750 static const char * arm_attr_tag_ABI_PCS_R9_use[] =
14751 {"V6", "SB", "TLS", "Unused"};
14752 static const char * arm_attr_tag_ABI_PCS_RW_data[] =
14753 {"Absolute", "PC-relative", "SB-relative", "None"};
14754 static const char * arm_attr_tag_ABI_PCS_RO_data[] =
14755 {"Absolute", "PC-relative", "None"};
14756 static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
14757 {"None", "direct", "GOT-indirect"};
14758 static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
14759 {"None", "??? 1", "2", "??? 3", "4"};
14760 static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
14761 static const char * arm_attr_tag_ABI_FP_denormal[] =
14762 {"Unused", "Needed", "Sign only"};
14763 static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
14764 static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
14765 static const char * arm_attr_tag_ABI_FP_number_model[] =
14766 {"Unused", "Finite", "RTABI", "IEEE 754"};
14767 static const char * arm_attr_tag_ABI_enum_size[] =
14768 {"Unused", "small", "int", "forced to int"};
14769 static const char * arm_attr_tag_ABI_HardFP_use[] =
14770 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
14771 static const char * arm_attr_tag_ABI_VFP_args[] =
14772 {"AAPCS", "VFP registers", "custom", "compatible"};
14773 static const char * arm_attr_tag_ABI_WMMX_args[] =
14774 {"AAPCS", "WMMX registers", "custom"};
14775 static const char * arm_attr_tag_ABI_optimization_goals[] =
14776 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14777 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
14778 static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
14779 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14780 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
14781 static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
14782 static const char * arm_attr_tag_FP_HP_extension[] =
14783 {"Not Allowed", "Allowed"};
14784 static const char * arm_attr_tag_ABI_FP_16bit_format[] =
14785 {"None", "IEEE 754", "Alternative Format"};
14786 static const char * arm_attr_tag_DSP_extension[] =
14787 {"Follow architecture", "Allowed"};
14788 static const char * arm_attr_tag_MPextension_use[] =
14789 {"Not Allowed", "Allowed"};
14790 static const char * arm_attr_tag_DIV_use[] =
14791 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
14792 "Allowed in v7-A with integer division extension"};
14793 static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
14794 static const char * arm_attr_tag_Virtualization_use[] =
14795 {"Not Allowed", "TrustZone", "Virtualization Extensions",
14796 "TrustZone and Virtualization Extensions"};
14797 static const char * arm_attr_tag_MPextension_use_legacy[] =
14798 {"Not Allowed", "Allowed"};
14799
14800 static const char * arm_attr_tag_MVE_arch[] =
14801 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
14802
14803 #define LOOKUP(id, name) \
14804 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
14805 static arm_attr_public_tag arm_attr_public_tags[] =
14806 {
14807 {4, "CPU_raw_name", 1, NULL},
14808 {5, "CPU_name", 1, NULL},
14809 LOOKUP(6, CPU_arch),
14810 {7, "CPU_arch_profile", 0, NULL},
14811 LOOKUP(8, ARM_ISA_use),
14812 LOOKUP(9, THUMB_ISA_use),
14813 LOOKUP(10, FP_arch),
14814 LOOKUP(11, WMMX_arch),
14815 LOOKUP(12, Advanced_SIMD_arch),
14816 LOOKUP(13, PCS_config),
14817 LOOKUP(14, ABI_PCS_R9_use),
14818 LOOKUP(15, ABI_PCS_RW_data),
14819 LOOKUP(16, ABI_PCS_RO_data),
14820 LOOKUP(17, ABI_PCS_GOT_use),
14821 LOOKUP(18, ABI_PCS_wchar_t),
14822 LOOKUP(19, ABI_FP_rounding),
14823 LOOKUP(20, ABI_FP_denormal),
14824 LOOKUP(21, ABI_FP_exceptions),
14825 LOOKUP(22, ABI_FP_user_exceptions),
14826 LOOKUP(23, ABI_FP_number_model),
14827 {24, "ABI_align_needed", 0, NULL},
14828 {25, "ABI_align_preserved", 0, NULL},
14829 LOOKUP(26, ABI_enum_size),
14830 LOOKUP(27, ABI_HardFP_use),
14831 LOOKUP(28, ABI_VFP_args),
14832 LOOKUP(29, ABI_WMMX_args),
14833 LOOKUP(30, ABI_optimization_goals),
14834 LOOKUP(31, ABI_FP_optimization_goals),
14835 {32, "compatibility", 0, NULL},
14836 LOOKUP(34, CPU_unaligned_access),
14837 LOOKUP(36, FP_HP_extension),
14838 LOOKUP(38, ABI_FP_16bit_format),
14839 LOOKUP(42, MPextension_use),
14840 LOOKUP(44, DIV_use),
14841 LOOKUP(46, DSP_extension),
14842 LOOKUP(48, MVE_arch),
14843 {64, "nodefaults", 0, NULL},
14844 {65, "also_compatible_with", 0, NULL},
14845 LOOKUP(66, T2EE_use),
14846 {67, "conformance", 1, NULL},
14847 LOOKUP(68, Virtualization_use),
14848 LOOKUP(70, MPextension_use_legacy)
14849 };
14850 #undef LOOKUP
14851
14852 static unsigned char *
14853 display_arm_attribute (unsigned char * p,
14854 const unsigned char * const end)
14855 {
14856 unsigned int tag;
14857 unsigned int len;
14858 unsigned int val;
14859 arm_attr_public_tag * attr;
14860 unsigned i;
14861 unsigned int type;
14862
14863 tag = read_uleb128 (p, &len, end);
14864 p += len;
14865 attr = NULL;
14866 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
14867 {
14868 if (arm_attr_public_tags[i].tag == tag)
14869 {
14870 attr = &arm_attr_public_tags[i];
14871 break;
14872 }
14873 }
14874
14875 if (attr)
14876 {
14877 printf (" Tag_%s: ", attr->name);
14878 switch (attr->type)
14879 {
14880 case 0:
14881 switch (tag)
14882 {
14883 case 7: /* Tag_CPU_arch_profile. */
14884 val = read_uleb128 (p, &len, end);
14885 p += len;
14886 switch (val)
14887 {
14888 case 0: printf (_("None\n")); break;
14889 case 'A': printf (_("Application\n")); break;
14890 case 'R': printf (_("Realtime\n")); break;
14891 case 'M': printf (_("Microcontroller\n")); break;
14892 case 'S': printf (_("Application or Realtime\n")); break;
14893 default: printf ("??? (%d)\n", val); break;
14894 }
14895 break;
14896
14897 case 24: /* Tag_align_needed. */
14898 val = read_uleb128 (p, &len, end);
14899 p += len;
14900 switch (val)
14901 {
14902 case 0: printf (_("None\n")); break;
14903 case 1: printf (_("8-byte\n")); break;
14904 case 2: printf (_("4-byte\n")); break;
14905 case 3: printf ("??? 3\n"); break;
14906 default:
14907 if (val <= 12)
14908 printf (_("8-byte and up to %d-byte extended\n"),
14909 1 << val);
14910 else
14911 printf ("??? (%d)\n", val);
14912 break;
14913 }
14914 break;
14915
14916 case 25: /* Tag_align_preserved. */
14917 val = read_uleb128 (p, &len, end);
14918 p += len;
14919 switch (val)
14920 {
14921 case 0: printf (_("None\n")); break;
14922 case 1: printf (_("8-byte, except leaf SP\n")); break;
14923 case 2: printf (_("8-byte\n")); break;
14924 case 3: printf ("??? 3\n"); break;
14925 default:
14926 if (val <= 12)
14927 printf (_("8-byte and up to %d-byte extended\n"),
14928 1 << val);
14929 else
14930 printf ("??? (%d)\n", val);
14931 break;
14932 }
14933 break;
14934
14935 case 32: /* Tag_compatibility. */
14936 {
14937 val = read_uleb128 (p, &len, end);
14938 p += len;
14939 printf (_("flag = %d, vendor = "), val);
14940 if (p < end - 1)
14941 {
14942 size_t maxlen = (end - p) - 1;
14943
14944 print_symbol ((int) maxlen, (const char *) p);
14945 p += strnlen ((char *) p, maxlen) + 1;
14946 }
14947 else
14948 {
14949 printf (_("<corrupt>"));
14950 p = (unsigned char *) end;
14951 }
14952 putchar ('\n');
14953 }
14954 break;
14955
14956 case 64: /* Tag_nodefaults. */
14957 /* PR 17531: file: 001-505008-0.01. */
14958 if (p < end)
14959 p++;
14960 printf (_("True\n"));
14961 break;
14962
14963 case 65: /* Tag_also_compatible_with. */
14964 val = read_uleb128 (p, &len, end);
14965 p += len;
14966 if (val == 6 /* Tag_CPU_arch. */)
14967 {
14968 val = read_uleb128 (p, &len, end);
14969 p += len;
14970 if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
14971 printf ("??? (%d)\n", val);
14972 else
14973 printf ("%s\n", arm_attr_tag_CPU_arch[val]);
14974 }
14975 else
14976 printf ("???\n");
14977 while (p < end && *(p++) != '\0' /* NUL terminator. */)
14978 ;
14979 break;
14980
14981 default:
14982 printf (_("<unknown: %d>\n"), tag);
14983 break;
14984 }
14985 return p;
14986
14987 case 1:
14988 return display_tag_value (-1, p, end);
14989 case 2:
14990 return display_tag_value (0, p, end);
14991
14992 default:
14993 assert (attr->type & 0x80);
14994 val = read_uleb128 (p, &len, end);
14995 p += len;
14996 type = attr->type & 0x7f;
14997 if (val >= type)
14998 printf ("??? (%d)\n", val);
14999 else
15000 printf ("%s\n", attr->table[val]);
15001 return p;
15002 }
15003 }
15004
15005 return display_tag_value (tag, p, end);
15006 }
15007
15008 static unsigned char *
15009 display_gnu_attribute (unsigned char * p,
15010 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
15011 const unsigned char * const end)
15012 {
15013 int tag;
15014 unsigned int len;
15015 unsigned int val;
15016
15017 tag = read_uleb128 (p, &len, end);
15018 p += len;
15019
15020 /* Tag_compatibility is the only generic GNU attribute defined at
15021 present. */
15022 if (tag == 32)
15023 {
15024 val = read_uleb128 (p, &len, end);
15025 p += len;
15026
15027 printf (_("flag = %d, vendor = "), val);
15028 if (p == end)
15029 {
15030 printf (_("<corrupt>\n"));
15031 warn (_("corrupt vendor attribute\n"));
15032 }
15033 else
15034 {
15035 if (p < end - 1)
15036 {
15037 size_t maxlen = (end - p) - 1;
15038
15039 print_symbol ((int) maxlen, (const char *) p);
15040 p += strnlen ((char *) p, maxlen) + 1;
15041 }
15042 else
15043 {
15044 printf (_("<corrupt>"));
15045 p = (unsigned char *) end;
15046 }
15047 putchar ('\n');
15048 }
15049 return p;
15050 }
15051
15052 if ((tag & 2) == 0 && display_proc_gnu_attribute)
15053 return display_proc_gnu_attribute (p, tag, end);
15054
15055 return display_tag_value (tag, p, end);
15056 }
15057
15058 static unsigned char *
15059 display_power_gnu_attribute (unsigned char * p,
15060 unsigned int tag,
15061 const unsigned char * const end)
15062 {
15063 unsigned int len;
15064 unsigned int val;
15065
15066 if (tag == Tag_GNU_Power_ABI_FP)
15067 {
15068 val = read_uleb128 (p, &len, end);
15069 p += len;
15070 printf (" Tag_GNU_Power_ABI_FP: ");
15071 if (len == 0)
15072 {
15073 printf (_("<corrupt>\n"));
15074 return p;
15075 }
15076
15077 if (val > 15)
15078 printf ("(%#x), ", val);
15079
15080 switch (val & 3)
15081 {
15082 case 0:
15083 printf (_("unspecified hard/soft float, "));
15084 break;
15085 case 1:
15086 printf (_("hard float, "));
15087 break;
15088 case 2:
15089 printf (_("soft float, "));
15090 break;
15091 case 3:
15092 printf (_("single-precision hard float, "));
15093 break;
15094 }
15095
15096 switch (val & 0xC)
15097 {
15098 case 0:
15099 printf (_("unspecified long double\n"));
15100 break;
15101 case 4:
15102 printf (_("128-bit IBM long double\n"));
15103 break;
15104 case 8:
15105 printf (_("64-bit long double\n"));
15106 break;
15107 case 12:
15108 printf (_("128-bit IEEE long double\n"));
15109 break;
15110 }
15111 return p;
15112 }
15113
15114 if (tag == Tag_GNU_Power_ABI_Vector)
15115 {
15116 val = read_uleb128 (p, &len, end);
15117 p += len;
15118 printf (" Tag_GNU_Power_ABI_Vector: ");
15119 if (len == 0)
15120 {
15121 printf (_("<corrupt>\n"));
15122 return p;
15123 }
15124
15125 if (val > 3)
15126 printf ("(%#x), ", val);
15127
15128 switch (val & 3)
15129 {
15130 case 0:
15131 printf (_("unspecified\n"));
15132 break;
15133 case 1:
15134 printf (_("generic\n"));
15135 break;
15136 case 2:
15137 printf ("AltiVec\n");
15138 break;
15139 case 3:
15140 printf ("SPE\n");
15141 break;
15142 }
15143 return p;
15144 }
15145
15146 if (tag == Tag_GNU_Power_ABI_Struct_Return)
15147 {
15148 val = read_uleb128 (p, &len, end);
15149 p += len;
15150 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
15151 if (len == 0)
15152 {
15153 printf (_("<corrupt>\n"));
15154 return p;
15155 }
15156
15157 if (val > 2)
15158 printf ("(%#x), ", val);
15159
15160 switch (val & 3)
15161 {
15162 case 0:
15163 printf (_("unspecified\n"));
15164 break;
15165 case 1:
15166 printf ("r3/r4\n");
15167 break;
15168 case 2:
15169 printf (_("memory\n"));
15170 break;
15171 case 3:
15172 printf ("???\n");
15173 break;
15174 }
15175 return p;
15176 }
15177
15178 return display_tag_value (tag & 1, p, end);
15179 }
15180
15181 static unsigned char *
15182 display_s390_gnu_attribute (unsigned char * p,
15183 unsigned int tag,
15184 const unsigned char * const end)
15185 {
15186 unsigned int len;
15187 int val;
15188
15189 if (tag == Tag_GNU_S390_ABI_Vector)
15190 {
15191 val = read_uleb128 (p, &len, end);
15192 p += len;
15193 printf (" Tag_GNU_S390_ABI_Vector: ");
15194
15195 switch (val)
15196 {
15197 case 0:
15198 printf (_("any\n"));
15199 break;
15200 case 1:
15201 printf (_("software\n"));
15202 break;
15203 case 2:
15204 printf (_("hardware\n"));
15205 break;
15206 default:
15207 printf ("??? (%d)\n", val);
15208 break;
15209 }
15210 return p;
15211 }
15212
15213 return display_tag_value (tag & 1, p, end);
15214 }
15215
15216 static void
15217 display_sparc_hwcaps (unsigned int mask)
15218 {
15219 if (mask)
15220 {
15221 bfd_boolean first = TRUE;
15222
15223 if (mask & ELF_SPARC_HWCAP_MUL32)
15224 fputs ("mul32", stdout), first = FALSE;
15225 if (mask & ELF_SPARC_HWCAP_DIV32)
15226 printf ("%sdiv32", first ? "" : "|"), first = FALSE;
15227 if (mask & ELF_SPARC_HWCAP_FSMULD)
15228 printf ("%sfsmuld", first ? "" : "|"), first = FALSE;
15229 if (mask & ELF_SPARC_HWCAP_V8PLUS)
15230 printf ("%sv8plus", first ? "" : "|"), first = FALSE;
15231 if (mask & ELF_SPARC_HWCAP_POPC)
15232 printf ("%spopc", first ? "" : "|"), first = FALSE;
15233 if (mask & ELF_SPARC_HWCAP_VIS)
15234 printf ("%svis", first ? "" : "|"), first = FALSE;
15235 if (mask & ELF_SPARC_HWCAP_VIS2)
15236 printf ("%svis2", first ? "" : "|"), first = FALSE;
15237 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
15238 printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE;
15239 if (mask & ELF_SPARC_HWCAP_FMAF)
15240 printf ("%sfmaf", first ? "" : "|"), first = FALSE;
15241 if (mask & ELF_SPARC_HWCAP_VIS3)
15242 printf ("%svis3", first ? "" : "|"), first = FALSE;
15243 if (mask & ELF_SPARC_HWCAP_HPC)
15244 printf ("%shpc", first ? "" : "|"), first = FALSE;
15245 if (mask & ELF_SPARC_HWCAP_RANDOM)
15246 printf ("%srandom", first ? "" : "|"), first = FALSE;
15247 if (mask & ELF_SPARC_HWCAP_TRANS)
15248 printf ("%strans", first ? "" : "|"), first = FALSE;
15249 if (mask & ELF_SPARC_HWCAP_FJFMAU)
15250 printf ("%sfjfmau", first ? "" : "|"), first = FALSE;
15251 if (mask & ELF_SPARC_HWCAP_IMA)
15252 printf ("%sima", first ? "" : "|"), first = FALSE;
15253 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
15254 printf ("%scspare", first ? "" : "|"), first = FALSE;
15255 }
15256 else
15257 fputc ('0', stdout);
15258 fputc ('\n', stdout);
15259 }
15260
15261 static void
15262 display_sparc_hwcaps2 (unsigned int mask)
15263 {
15264 if (mask)
15265 {
15266 bfd_boolean first = TRUE;
15267
15268 if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
15269 fputs ("fjathplus", stdout), first = FALSE;
15270 if (mask & ELF_SPARC_HWCAP2_VIS3B)
15271 printf ("%svis3b", first ? "" : "|"), first = FALSE;
15272 if (mask & ELF_SPARC_HWCAP2_ADP)
15273 printf ("%sadp", first ? "" : "|"), first = FALSE;
15274 if (mask & ELF_SPARC_HWCAP2_SPARC5)
15275 printf ("%ssparc5", first ? "" : "|"), first = FALSE;
15276 if (mask & ELF_SPARC_HWCAP2_MWAIT)
15277 printf ("%smwait", first ? "" : "|"), first = FALSE;
15278 if (mask & ELF_SPARC_HWCAP2_XMPMUL)
15279 printf ("%sxmpmul", first ? "" : "|"), first = FALSE;
15280 if (mask & ELF_SPARC_HWCAP2_XMONT)
15281 printf ("%sxmont2", first ? "" : "|"), first = FALSE;
15282 if (mask & ELF_SPARC_HWCAP2_NSEC)
15283 printf ("%snsec", first ? "" : "|"), first = FALSE;
15284 if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
15285 printf ("%sfjathhpc", first ? "" : "|"), first = FALSE;
15286 if (mask & ELF_SPARC_HWCAP2_FJDES)
15287 printf ("%sfjdes", first ? "" : "|"), first = FALSE;
15288 if (mask & ELF_SPARC_HWCAP2_FJAES)
15289 printf ("%sfjaes", first ? "" : "|"), first = FALSE;
15290 }
15291 else
15292 fputc ('0', stdout);
15293 fputc ('\n', stdout);
15294 }
15295
15296 static unsigned char *
15297 display_sparc_gnu_attribute (unsigned char * p,
15298 unsigned int tag,
15299 const unsigned char * const end)
15300 {
15301 unsigned int len;
15302 int val;
15303
15304 if (tag == Tag_GNU_Sparc_HWCAPS)
15305 {
15306 val = read_uleb128 (p, &len, end);
15307 p += len;
15308 printf (" Tag_GNU_Sparc_HWCAPS: ");
15309 display_sparc_hwcaps (val);
15310 return p;
15311 }
15312 if (tag == Tag_GNU_Sparc_HWCAPS2)
15313 {
15314 val = read_uleb128 (p, &len, end);
15315 p += len;
15316 printf (" Tag_GNU_Sparc_HWCAPS2: ");
15317 display_sparc_hwcaps2 (val);
15318 return p;
15319 }
15320
15321 return display_tag_value (tag, p, end);
15322 }
15323
15324 static void
15325 print_mips_fp_abi_value (unsigned int val)
15326 {
15327 switch (val)
15328 {
15329 case Val_GNU_MIPS_ABI_FP_ANY:
15330 printf (_("Hard or soft float\n"));
15331 break;
15332 case Val_GNU_MIPS_ABI_FP_DOUBLE:
15333 printf (_("Hard float (double precision)\n"));
15334 break;
15335 case Val_GNU_MIPS_ABI_FP_SINGLE:
15336 printf (_("Hard float (single precision)\n"));
15337 break;
15338 case Val_GNU_MIPS_ABI_FP_SOFT:
15339 printf (_("Soft float\n"));
15340 break;
15341 case Val_GNU_MIPS_ABI_FP_OLD_64:
15342 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
15343 break;
15344 case Val_GNU_MIPS_ABI_FP_XX:
15345 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
15346 break;
15347 case Val_GNU_MIPS_ABI_FP_64:
15348 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
15349 break;
15350 case Val_GNU_MIPS_ABI_FP_64A:
15351 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
15352 break;
15353 case Val_GNU_MIPS_ABI_FP_NAN2008:
15354 printf (_("NaN 2008 compatibility\n"));
15355 break;
15356 default:
15357 printf ("??? (%d)\n", val);
15358 break;
15359 }
15360 }
15361
15362 static unsigned char *
15363 display_mips_gnu_attribute (unsigned char * p,
15364 unsigned int tag,
15365 const unsigned char * const end)
15366 {
15367 if (tag == Tag_GNU_MIPS_ABI_FP)
15368 {
15369 unsigned int len;
15370 unsigned int val;
15371
15372 val = read_uleb128 (p, &len, end);
15373 p += len;
15374 printf (" Tag_GNU_MIPS_ABI_FP: ");
15375
15376 print_mips_fp_abi_value (val);
15377
15378 return p;
15379 }
15380
15381 if (tag == Tag_GNU_MIPS_ABI_MSA)
15382 {
15383 unsigned int len;
15384 unsigned int val;
15385
15386 val = read_uleb128 (p, &len, end);
15387 p += len;
15388 printf (" Tag_GNU_MIPS_ABI_MSA: ");
15389
15390 switch (val)
15391 {
15392 case Val_GNU_MIPS_ABI_MSA_ANY:
15393 printf (_("Any MSA or not\n"));
15394 break;
15395 case Val_GNU_MIPS_ABI_MSA_128:
15396 printf (_("128-bit MSA\n"));
15397 break;
15398 default:
15399 printf ("??? (%d)\n", val);
15400 break;
15401 }
15402 return p;
15403 }
15404
15405 return display_tag_value (tag & 1, p, end);
15406 }
15407
15408 static unsigned char *
15409 display_tic6x_attribute (unsigned char * p,
15410 const unsigned char * const end)
15411 {
15412 unsigned int tag;
15413 unsigned int len;
15414 int val;
15415
15416 tag = read_uleb128 (p, &len, end);
15417 p += len;
15418
15419 switch (tag)
15420 {
15421 case Tag_ISA:
15422 val = read_uleb128 (p, &len, end);
15423 p += len;
15424 printf (" Tag_ISA: ");
15425
15426 switch (val)
15427 {
15428 case C6XABI_Tag_ISA_none:
15429 printf (_("None\n"));
15430 break;
15431 case C6XABI_Tag_ISA_C62X:
15432 printf ("C62x\n");
15433 break;
15434 case C6XABI_Tag_ISA_C67X:
15435 printf ("C67x\n");
15436 break;
15437 case C6XABI_Tag_ISA_C67XP:
15438 printf ("C67x+\n");
15439 break;
15440 case C6XABI_Tag_ISA_C64X:
15441 printf ("C64x\n");
15442 break;
15443 case C6XABI_Tag_ISA_C64XP:
15444 printf ("C64x+\n");
15445 break;
15446 case C6XABI_Tag_ISA_C674X:
15447 printf ("C674x\n");
15448 break;
15449 default:
15450 printf ("??? (%d)\n", val);
15451 break;
15452 }
15453 return p;
15454
15455 case Tag_ABI_wchar_t:
15456 val = read_uleb128 (p, &len, end);
15457 p += len;
15458 printf (" Tag_ABI_wchar_t: ");
15459 switch (val)
15460 {
15461 case 0:
15462 printf (_("Not used\n"));
15463 break;
15464 case 1:
15465 printf (_("2 bytes\n"));
15466 break;
15467 case 2:
15468 printf (_("4 bytes\n"));
15469 break;
15470 default:
15471 printf ("??? (%d)\n", val);
15472 break;
15473 }
15474 return p;
15475
15476 case Tag_ABI_stack_align_needed:
15477 val = read_uleb128 (p, &len, end);
15478 p += len;
15479 printf (" Tag_ABI_stack_align_needed: ");
15480 switch (val)
15481 {
15482 case 0:
15483 printf (_("8-byte\n"));
15484 break;
15485 case 1:
15486 printf (_("16-byte\n"));
15487 break;
15488 default:
15489 printf ("??? (%d)\n", val);
15490 break;
15491 }
15492 return p;
15493
15494 case Tag_ABI_stack_align_preserved:
15495 val = read_uleb128 (p, &len, end);
15496 p += len;
15497 printf (" Tag_ABI_stack_align_preserved: ");
15498 switch (val)
15499 {
15500 case 0:
15501 printf (_("8-byte\n"));
15502 break;
15503 case 1:
15504 printf (_("16-byte\n"));
15505 break;
15506 default:
15507 printf ("??? (%d)\n", val);
15508 break;
15509 }
15510 return p;
15511
15512 case Tag_ABI_DSBT:
15513 val = read_uleb128 (p, &len, end);
15514 p += len;
15515 printf (" Tag_ABI_DSBT: ");
15516 switch (val)
15517 {
15518 case 0:
15519 printf (_("DSBT addressing not used\n"));
15520 break;
15521 case 1:
15522 printf (_("DSBT addressing used\n"));
15523 break;
15524 default:
15525 printf ("??? (%d)\n", val);
15526 break;
15527 }
15528 return p;
15529
15530 case Tag_ABI_PID:
15531 val = read_uleb128 (p, &len, end);
15532 p += len;
15533 printf (" Tag_ABI_PID: ");
15534 switch (val)
15535 {
15536 case 0:
15537 printf (_("Data addressing position-dependent\n"));
15538 break;
15539 case 1:
15540 printf (_("Data addressing position-independent, GOT near DP\n"));
15541 break;
15542 case 2:
15543 printf (_("Data addressing position-independent, GOT far from DP\n"));
15544 break;
15545 default:
15546 printf ("??? (%d)\n", val);
15547 break;
15548 }
15549 return p;
15550
15551 case Tag_ABI_PIC:
15552 val = read_uleb128 (p, &len, end);
15553 p += len;
15554 printf (" Tag_ABI_PIC: ");
15555 switch (val)
15556 {
15557 case 0:
15558 printf (_("Code addressing position-dependent\n"));
15559 break;
15560 case 1:
15561 printf (_("Code addressing position-independent\n"));
15562 break;
15563 default:
15564 printf ("??? (%d)\n", val);
15565 break;
15566 }
15567 return p;
15568
15569 case Tag_ABI_array_object_alignment:
15570 val = read_uleb128 (p, &len, end);
15571 p += len;
15572 printf (" Tag_ABI_array_object_alignment: ");
15573 switch (val)
15574 {
15575 case 0:
15576 printf (_("8-byte\n"));
15577 break;
15578 case 1:
15579 printf (_("4-byte\n"));
15580 break;
15581 case 2:
15582 printf (_("16-byte\n"));
15583 break;
15584 default:
15585 printf ("??? (%d)\n", val);
15586 break;
15587 }
15588 return p;
15589
15590 case Tag_ABI_array_object_align_expected:
15591 val = read_uleb128 (p, &len, end);
15592 p += len;
15593 printf (" Tag_ABI_array_object_align_expected: ");
15594 switch (val)
15595 {
15596 case 0:
15597 printf (_("8-byte\n"));
15598 break;
15599 case 1:
15600 printf (_("4-byte\n"));
15601 break;
15602 case 2:
15603 printf (_("16-byte\n"));
15604 break;
15605 default:
15606 printf ("??? (%d)\n", val);
15607 break;
15608 }
15609 return p;
15610
15611 case Tag_ABI_compatibility:
15612 {
15613 val = read_uleb128 (p, &len, end);
15614 p += len;
15615 printf (" Tag_ABI_compatibility: ");
15616 printf (_("flag = %d, vendor = "), val);
15617 if (p < end - 1)
15618 {
15619 size_t maxlen = (end - p) - 1;
15620
15621 print_symbol ((int) maxlen, (const char *) p);
15622 p += strnlen ((char *) p, maxlen) + 1;
15623 }
15624 else
15625 {
15626 printf (_("<corrupt>"));
15627 p = (unsigned char *) end;
15628 }
15629 putchar ('\n');
15630 return p;
15631 }
15632
15633 case Tag_ABI_conformance:
15634 {
15635 printf (" Tag_ABI_conformance: \"");
15636 if (p < end - 1)
15637 {
15638 size_t maxlen = (end - p) - 1;
15639
15640 print_symbol ((int) maxlen, (const char *) p);
15641 p += strnlen ((char *) p, maxlen) + 1;
15642 }
15643 else
15644 {
15645 printf (_("<corrupt>"));
15646 p = (unsigned char *) end;
15647 }
15648 printf ("\"\n");
15649 return p;
15650 }
15651 }
15652
15653 return display_tag_value (tag, p, end);
15654 }
15655
15656 static void
15657 display_raw_attribute (unsigned char * p, unsigned char const * const end)
15658 {
15659 unsigned long addr = 0;
15660 size_t bytes = end - p;
15661
15662 assert (end >= p);
15663 while (bytes)
15664 {
15665 int j;
15666 int k;
15667 int lbytes = (bytes > 16 ? 16 : bytes);
15668
15669 printf (" 0x%8.8lx ", addr);
15670
15671 for (j = 0; j < 16; j++)
15672 {
15673 if (j < lbytes)
15674 printf ("%2.2x", p[j]);
15675 else
15676 printf (" ");
15677
15678 if ((j & 3) == 3)
15679 printf (" ");
15680 }
15681
15682 for (j = 0; j < lbytes; j++)
15683 {
15684 k = p[j];
15685 if (k >= ' ' && k < 0x7f)
15686 printf ("%c", k);
15687 else
15688 printf (".");
15689 }
15690
15691 putchar ('\n');
15692
15693 p += lbytes;
15694 bytes -= lbytes;
15695 addr += lbytes;
15696 }
15697
15698 putchar ('\n');
15699 }
15700
15701 static unsigned char *
15702 display_msp430x_attribute (unsigned char * p,
15703 const unsigned char * const end)
15704 {
15705 unsigned int len;
15706 unsigned int val;
15707 unsigned int tag;
15708
15709 tag = read_uleb128 (p, & len, end);
15710 p += len;
15711
15712 switch (tag)
15713 {
15714 case OFBA_MSPABI_Tag_ISA:
15715 val = read_uleb128 (p, &len, end);
15716 p += len;
15717 printf (" Tag_ISA: ");
15718 switch (val)
15719 {
15720 case 0: printf (_("None\n")); break;
15721 case 1: printf (_("MSP430\n")); break;
15722 case 2: printf (_("MSP430X\n")); break;
15723 default: printf ("??? (%d)\n", val); break;
15724 }
15725 break;
15726
15727 case OFBA_MSPABI_Tag_Code_Model:
15728 val = read_uleb128 (p, &len, end);
15729 p += len;
15730 printf (" Tag_Code_Model: ");
15731 switch (val)
15732 {
15733 case 0: printf (_("None\n")); break;
15734 case 1: printf (_("Small\n")); break;
15735 case 2: printf (_("Large\n")); break;
15736 default: printf ("??? (%d)\n", val); break;
15737 }
15738 break;
15739
15740 case OFBA_MSPABI_Tag_Data_Model:
15741 val = read_uleb128 (p, &len, end);
15742 p += len;
15743 printf (" Tag_Data_Model: ");
15744 switch (val)
15745 {
15746 case 0: printf (_("None\n")); break;
15747 case 1: printf (_("Small\n")); break;
15748 case 2: printf (_("Large\n")); break;
15749 case 3: printf (_("Restricted Large\n")); break;
15750 default: printf ("??? (%d)\n", val); break;
15751 }
15752 break;
15753
15754 default:
15755 printf (_(" <unknown tag %d>: "), tag);
15756
15757 if (tag & 1)
15758 {
15759 putchar ('"');
15760 if (p < end - 1)
15761 {
15762 size_t maxlen = (end - p) - 1;
15763
15764 print_symbol ((int) maxlen, (const char *) p);
15765 p += strnlen ((char *) p, maxlen) + 1;
15766 }
15767 else
15768 {
15769 printf (_("<corrupt>"));
15770 p = (unsigned char *) end;
15771 }
15772 printf ("\"\n");
15773 }
15774 else
15775 {
15776 val = read_uleb128 (p, &len, end);
15777 p += len;
15778 printf ("%d (0x%x)\n", val, val);
15779 }
15780 break;
15781 }
15782
15783 assert (p <= end);
15784 return p;
15785 }
15786
15787 static unsigned char *
15788 display_msp430_gnu_attribute (unsigned char * p,
15789 unsigned int tag,
15790 const unsigned char * const end)
15791 {
15792 if (tag == Tag_GNU_MSP430_Data_Region)
15793 {
15794 unsigned int len;
15795 int val;
15796
15797 val = read_uleb128 (p, &len, end);
15798 p += len;
15799 printf (" Tag_GNU_MSP430_Data_Region: ");
15800
15801 switch (val)
15802 {
15803 case Val_GNU_MSP430_Data_Region_Any:
15804 printf (_("Any Region\n"));
15805 break;
15806 case Val_GNU_MSP430_Data_Region_Lower:
15807 printf (_("Lower Region Only\n"));
15808 break;
15809 default:
15810 printf ("??? (%d)\n", val);
15811 }
15812 return p;
15813 }
15814 return display_tag_value (tag & 1, p, end);
15815 }
15816
15817 struct riscv_attr_tag_t {
15818 const char *name;
15819 int tag;
15820 };
15821
15822 static struct riscv_attr_tag_t riscv_attr_tag[] =
15823 {
15824 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
15825 T(arch),
15826 T(priv_spec),
15827 T(priv_spec_minor),
15828 T(priv_spec_revision),
15829 T(unaligned_access),
15830 T(stack_align),
15831 #undef T
15832 };
15833
15834 static unsigned char *
15835 display_riscv_attribute (unsigned char *p,
15836 const unsigned char * const end)
15837 {
15838 unsigned int len;
15839 int val;
15840 int tag;
15841 struct riscv_attr_tag_t *attr = NULL;
15842 unsigned i;
15843
15844 tag = read_uleb128 (p, &len, end);
15845 p += len;
15846
15847 /* Find the name of attribute. */
15848 for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++)
15849 {
15850 if (riscv_attr_tag[i].tag == tag)
15851 {
15852 attr = &riscv_attr_tag[i];
15853 break;
15854 }
15855 }
15856
15857 if (attr)
15858 printf (" %s: ", attr->name);
15859 else
15860 return display_tag_value (tag, p, end);
15861
15862 switch (tag)
15863 {
15864 case Tag_RISCV_priv_spec:
15865 case Tag_RISCV_priv_spec_minor:
15866 case Tag_RISCV_priv_spec_revision:
15867 val = read_uleb128 (p, &len, end);
15868 p += len;
15869 printf (_("%d\n"), val);
15870 break;
15871 case Tag_RISCV_unaligned_access:
15872 val = read_uleb128 (p, &len, end);
15873 p += len;
15874 switch (val)
15875 {
15876 case 0:
15877 printf (_("No unaligned access\n"));
15878 break;
15879 case 1:
15880 printf (_("Unaligned access\n"));
15881 break;
15882 }
15883 break;
15884 case Tag_RISCV_stack_align:
15885 val = read_uleb128 (p, &len, end);
15886 p += len;
15887 printf (_("%d-bytes\n"), val);
15888 break;
15889 case Tag_RISCV_arch:
15890 p = display_tag_value (-1, p, end);
15891 break;
15892 default:
15893 return display_tag_value (tag, p, end);
15894 }
15895
15896 return p;
15897 }
15898
15899 static bfd_boolean
15900 process_attributes (Filedata * filedata,
15901 const char * public_name,
15902 unsigned int proc_type,
15903 unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
15904 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
15905 {
15906 Elf_Internal_Shdr * sect;
15907 unsigned i;
15908 bfd_boolean res = TRUE;
15909
15910 /* Find the section header so that we get the size. */
15911 for (i = 0, sect = filedata->section_headers;
15912 i < filedata->file_header.e_shnum;
15913 i++, sect++)
15914 {
15915 unsigned char * contents;
15916 unsigned char * p;
15917
15918 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
15919 continue;
15920
15921 contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1,
15922 sect->sh_size, _("attributes"));
15923 if (contents == NULL)
15924 {
15925 res = FALSE;
15926 continue;
15927 }
15928
15929 p = contents;
15930 /* The first character is the version of the attributes.
15931 Currently only version 1, (aka 'A') is recognised here. */
15932 if (*p != 'A')
15933 {
15934 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
15935 res = FALSE;
15936 }
15937 else
15938 {
15939 bfd_vma section_len;
15940
15941 section_len = sect->sh_size - 1;
15942 p++;
15943
15944 while (section_len > 0)
15945 {
15946 bfd_vma attr_len;
15947 unsigned int namelen;
15948 bfd_boolean public_section;
15949 bfd_boolean gnu_section;
15950
15951 if (section_len <= 4)
15952 {
15953 error (_("Tag section ends prematurely\n"));
15954 res = FALSE;
15955 break;
15956 }
15957 attr_len = byte_get (p, 4);
15958 p += 4;
15959
15960 if (attr_len > section_len)
15961 {
15962 error (_("Bad attribute length (%u > %u)\n"),
15963 (unsigned) attr_len, (unsigned) section_len);
15964 attr_len = section_len;
15965 res = FALSE;
15966 }
15967 /* PR 17531: file: 001-101425-0.004 */
15968 else if (attr_len < 5)
15969 {
15970 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
15971 res = FALSE;
15972 break;
15973 }
15974
15975 section_len -= attr_len;
15976 attr_len -= 4;
15977
15978 namelen = strnlen ((char *) p, attr_len) + 1;
15979 if (namelen == 0 || namelen >= attr_len)
15980 {
15981 error (_("Corrupt attribute section name\n"));
15982 res = FALSE;
15983 break;
15984 }
15985
15986 printf (_("Attribute Section: "));
15987 print_symbol (INT_MAX, (const char *) p);
15988 putchar ('\n');
15989
15990 if (public_name && streq ((char *) p, public_name))
15991 public_section = TRUE;
15992 else
15993 public_section = FALSE;
15994
15995 if (streq ((char *) p, "gnu"))
15996 gnu_section = TRUE;
15997 else
15998 gnu_section = FALSE;
15999
16000 p += namelen;
16001 attr_len -= namelen;
16002
16003 while (attr_len > 0 && p < contents + sect->sh_size)
16004 {
16005 int tag;
16006 int val;
16007 bfd_vma size;
16008 unsigned char * end;
16009
16010 /* PR binutils/17531: Safe handling of corrupt files. */
16011 if (attr_len < 6)
16012 {
16013 error (_("Unused bytes at end of section\n"));
16014 res = FALSE;
16015 section_len = 0;
16016 break;
16017 }
16018
16019 tag = *(p++);
16020 size = byte_get (p, 4);
16021 if (size > attr_len)
16022 {
16023 error (_("Bad subsection length (%u > %u)\n"),
16024 (unsigned) size, (unsigned) attr_len);
16025 res = FALSE;
16026 size = attr_len;
16027 }
16028 /* PR binutils/17531: Safe handling of corrupt files. */
16029 if (size < 6)
16030 {
16031 error (_("Bad subsection length (%u < 6)\n"),
16032 (unsigned) size);
16033 res = FALSE;
16034 section_len = 0;
16035 break;
16036 }
16037
16038 attr_len -= size;
16039 end = p + size - 1;
16040 assert (end <= contents + sect->sh_size);
16041 p += 4;
16042
16043 switch (tag)
16044 {
16045 case 1:
16046 printf (_("File Attributes\n"));
16047 break;
16048 case 2:
16049 printf (_("Section Attributes:"));
16050 goto do_numlist;
16051 case 3:
16052 printf (_("Symbol Attributes:"));
16053 /* Fall through. */
16054 do_numlist:
16055 for (;;)
16056 {
16057 unsigned int j;
16058
16059 val = read_uleb128 (p, &j, end);
16060 p += j;
16061 if (val == 0)
16062 break;
16063 printf (" %d", val);
16064 }
16065 printf ("\n");
16066 break;
16067 default:
16068 printf (_("Unknown tag: %d\n"), tag);
16069 public_section = FALSE;
16070 break;
16071 }
16072
16073 if (public_section && display_pub_attribute != NULL)
16074 {
16075 while (p < end)
16076 p = display_pub_attribute (p, end);
16077 assert (p == end);
16078 }
16079 else if (gnu_section && display_proc_gnu_attribute != NULL)
16080 {
16081 while (p < end)
16082 p = display_gnu_attribute (p,
16083 display_proc_gnu_attribute,
16084 end);
16085 assert (p == end);
16086 }
16087 else if (p < end)
16088 {
16089 printf (_(" Unknown attribute:\n"));
16090 display_raw_attribute (p, end);
16091 p = end;
16092 }
16093 else
16094 attr_len = 0;
16095 }
16096 }
16097 }
16098
16099 free (contents);
16100 }
16101
16102 return res;
16103 }
16104
16105 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
16106 Print the Address, Access and Initial fields of an entry at VMA ADDR
16107 and return the VMA of the next entry, or -1 if there was a problem.
16108 Does not read from DATA_END or beyond. */
16109
16110 static bfd_vma
16111 print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
16112 unsigned char * data_end)
16113 {
16114 printf (" ");
16115 print_vma (addr, LONG_HEX);
16116 printf (" ");
16117 if (addr < pltgot + 0xfff0)
16118 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
16119 else
16120 printf ("%10s", "");
16121 printf (" ");
16122 if (data == NULL)
16123 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
16124 else
16125 {
16126 bfd_vma entry;
16127 unsigned char * from = data + addr - pltgot;
16128
16129 if (from + (is_32bit_elf ? 4 : 8) > data_end)
16130 {
16131 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
16132 printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
16133 return (bfd_vma) -1;
16134 }
16135 else
16136 {
16137 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
16138 print_vma (entry, LONG_HEX);
16139 }
16140 }
16141 return addr + (is_32bit_elf ? 4 : 8);
16142 }
16143
16144 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
16145 PLTGOT. Print the Address and Initial fields of an entry at VMA
16146 ADDR and return the VMA of the next entry. */
16147
16148 static bfd_vma
16149 print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
16150 {
16151 printf (" ");
16152 print_vma (addr, LONG_HEX);
16153 printf (" ");
16154 if (data == NULL)
16155 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
16156 else
16157 {
16158 bfd_vma entry;
16159
16160 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
16161 print_vma (entry, LONG_HEX);
16162 }
16163 return addr + (is_32bit_elf ? 4 : 8);
16164 }
16165
16166 static void
16167 print_mips_ases (unsigned int mask)
16168 {
16169 if (mask & AFL_ASE_DSP)
16170 fputs ("\n\tDSP ASE", stdout);
16171 if (mask & AFL_ASE_DSPR2)
16172 fputs ("\n\tDSP R2 ASE", stdout);
16173 if (mask & AFL_ASE_DSPR3)
16174 fputs ("\n\tDSP R3 ASE", stdout);
16175 if (mask & AFL_ASE_EVA)
16176 fputs ("\n\tEnhanced VA Scheme", stdout);
16177 if (mask & AFL_ASE_MCU)
16178 fputs ("\n\tMCU (MicroController) ASE", stdout);
16179 if (mask & AFL_ASE_MDMX)
16180 fputs ("\n\tMDMX ASE", stdout);
16181 if (mask & AFL_ASE_MIPS3D)
16182 fputs ("\n\tMIPS-3D ASE", stdout);
16183 if (mask & AFL_ASE_MT)
16184 fputs ("\n\tMT ASE", stdout);
16185 if (mask & AFL_ASE_SMARTMIPS)
16186 fputs ("\n\tSmartMIPS ASE", stdout);
16187 if (mask & AFL_ASE_VIRT)
16188 fputs ("\n\tVZ ASE", stdout);
16189 if (mask & AFL_ASE_MSA)
16190 fputs ("\n\tMSA ASE", stdout);
16191 if (mask & AFL_ASE_MIPS16)
16192 fputs ("\n\tMIPS16 ASE", stdout);
16193 if (mask & AFL_ASE_MICROMIPS)
16194 fputs ("\n\tMICROMIPS ASE", stdout);
16195 if (mask & AFL_ASE_XPA)
16196 fputs ("\n\tXPA ASE", stdout);
16197 if (mask & AFL_ASE_MIPS16E2)
16198 fputs ("\n\tMIPS16e2 ASE", stdout);
16199 if (mask & AFL_ASE_CRC)
16200 fputs ("\n\tCRC ASE", stdout);
16201 if (mask & AFL_ASE_GINV)
16202 fputs ("\n\tGINV ASE", stdout);
16203 if (mask & AFL_ASE_LOONGSON_MMI)
16204 fputs ("\n\tLoongson MMI ASE", stdout);
16205 if (mask & AFL_ASE_LOONGSON_CAM)
16206 fputs ("\n\tLoongson CAM ASE", stdout);
16207 if (mask & AFL_ASE_LOONGSON_EXT)
16208 fputs ("\n\tLoongson EXT ASE", stdout);
16209 if (mask & AFL_ASE_LOONGSON_EXT2)
16210 fputs ("\n\tLoongson EXT2 ASE", stdout);
16211 if (mask == 0)
16212 fprintf (stdout, "\n\t%s", _("None"));
16213 else if ((mask & ~AFL_ASE_MASK) != 0)
16214 fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
16215 }
16216
16217 static void
16218 print_mips_isa_ext (unsigned int isa_ext)
16219 {
16220 switch (isa_ext)
16221 {
16222 case 0:
16223 fputs (_("None"), stdout);
16224 break;
16225 case AFL_EXT_XLR:
16226 fputs ("RMI XLR", stdout);
16227 break;
16228 case AFL_EXT_OCTEON3:
16229 fputs ("Cavium Networks Octeon3", stdout);
16230 break;
16231 case AFL_EXT_OCTEON2:
16232 fputs ("Cavium Networks Octeon2", stdout);
16233 break;
16234 case AFL_EXT_OCTEONP:
16235 fputs ("Cavium Networks OcteonP", stdout);
16236 break;
16237 case AFL_EXT_OCTEON:
16238 fputs ("Cavium Networks Octeon", stdout);
16239 break;
16240 case AFL_EXT_5900:
16241 fputs ("Toshiba R5900", stdout);
16242 break;
16243 case AFL_EXT_4650:
16244 fputs ("MIPS R4650", stdout);
16245 break;
16246 case AFL_EXT_4010:
16247 fputs ("LSI R4010", stdout);
16248 break;
16249 case AFL_EXT_4100:
16250 fputs ("NEC VR4100", stdout);
16251 break;
16252 case AFL_EXT_3900:
16253 fputs ("Toshiba R3900", stdout);
16254 break;
16255 case AFL_EXT_10000:
16256 fputs ("MIPS R10000", stdout);
16257 break;
16258 case AFL_EXT_SB1:
16259 fputs ("Broadcom SB-1", stdout);
16260 break;
16261 case AFL_EXT_4111:
16262 fputs ("NEC VR4111/VR4181", stdout);
16263 break;
16264 case AFL_EXT_4120:
16265 fputs ("NEC VR4120", stdout);
16266 break;
16267 case AFL_EXT_5400:
16268 fputs ("NEC VR5400", stdout);
16269 break;
16270 case AFL_EXT_5500:
16271 fputs ("NEC VR5500", stdout);
16272 break;
16273 case AFL_EXT_LOONGSON_2E:
16274 fputs ("ST Microelectronics Loongson 2E", stdout);
16275 break;
16276 case AFL_EXT_LOONGSON_2F:
16277 fputs ("ST Microelectronics Loongson 2F", stdout);
16278 break;
16279 case AFL_EXT_INTERAPTIV_MR2:
16280 fputs ("Imagination interAptiv MR2", stdout);
16281 break;
16282 default:
16283 fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
16284 }
16285 }
16286
16287 static signed int
16288 get_mips_reg_size (int reg_size)
16289 {
16290 return (reg_size == AFL_REG_NONE) ? 0
16291 : (reg_size == AFL_REG_32) ? 32
16292 : (reg_size == AFL_REG_64) ? 64
16293 : (reg_size == AFL_REG_128) ? 128
16294 : -1;
16295 }
16296
16297 static bfd_boolean
16298 process_mips_specific (Filedata * filedata)
16299 {
16300 Elf_Internal_Dyn * entry;
16301 Elf_Internal_Shdr *sect = NULL;
16302 size_t liblist_offset = 0;
16303 size_t liblistno = 0;
16304 size_t conflictsno = 0;
16305 size_t options_offset = 0;
16306 size_t conflicts_offset = 0;
16307 size_t pltrelsz = 0;
16308 size_t pltrel = 0;
16309 bfd_vma pltgot = 0;
16310 bfd_vma mips_pltgot = 0;
16311 bfd_vma jmprel = 0;
16312 bfd_vma local_gotno = 0;
16313 bfd_vma gotsym = 0;
16314 bfd_vma symtabno = 0;
16315 bfd_boolean res = TRUE;
16316
16317 if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
16318 display_mips_gnu_attribute))
16319 res = FALSE;
16320
16321 sect = find_section (filedata, ".MIPS.abiflags");
16322
16323 if (sect != NULL)
16324 {
16325 Elf_External_ABIFlags_v0 *abiflags_ext;
16326 Elf_Internal_ABIFlags_v0 abiflags_in;
16327
16328 if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
16329 {
16330 error (_("Corrupt MIPS ABI Flags section.\n"));
16331 res = FALSE;
16332 }
16333 else
16334 {
16335 abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
16336 sect->sh_size, _("MIPS ABI Flags section"));
16337 if (abiflags_ext)
16338 {
16339 abiflags_in.version = BYTE_GET (abiflags_ext->version);
16340 abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
16341 abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
16342 abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
16343 abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
16344 abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
16345 abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
16346 abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
16347 abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
16348 abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
16349 abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
16350
16351 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
16352 printf ("\nISA: MIPS%d", abiflags_in.isa_level);
16353 if (abiflags_in.isa_rev > 1)
16354 printf ("r%d", abiflags_in.isa_rev);
16355 printf ("\nGPR size: %d",
16356 get_mips_reg_size (abiflags_in.gpr_size));
16357 printf ("\nCPR1 size: %d",
16358 get_mips_reg_size (abiflags_in.cpr1_size));
16359 printf ("\nCPR2 size: %d",
16360 get_mips_reg_size (abiflags_in.cpr2_size));
16361 fputs ("\nFP ABI: ", stdout);
16362 print_mips_fp_abi_value (abiflags_in.fp_abi);
16363 fputs ("ISA Extension: ", stdout);
16364 print_mips_isa_ext (abiflags_in.isa_ext);
16365 fputs ("\nASEs:", stdout);
16366 print_mips_ases (abiflags_in.ases);
16367 printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
16368 printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
16369 fputc ('\n', stdout);
16370 free (abiflags_ext);
16371 }
16372 }
16373 }
16374
16375 /* We have a lot of special sections. Thanks SGI! */
16376 if (dynamic_section == NULL)
16377 {
16378 /* No dynamic information available. See if there is static GOT. */
16379 sect = find_section (filedata, ".got");
16380 if (sect != NULL)
16381 {
16382 unsigned char *data_end;
16383 unsigned char *data;
16384 bfd_vma ent, end;
16385 int addr_size;
16386
16387 pltgot = sect->sh_addr;
16388
16389 ent = pltgot;
16390 addr_size = (is_32bit_elf ? 4 : 8);
16391 end = pltgot + sect->sh_size;
16392
16393 data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset,
16394 end - pltgot, 1,
16395 _("Global Offset Table data"));
16396 /* PR 12855: Null data is handled gracefully throughout. */
16397 data_end = data + (end - pltgot);
16398
16399 printf (_("\nStatic GOT:\n"));
16400 printf (_(" Canonical gp value: "));
16401 print_vma (ent + 0x7ff0, LONG_HEX);
16402 printf ("\n\n");
16403
16404 /* In a dynamic binary GOT[0] is reserved for the dynamic
16405 loader to store the lazy resolver pointer, however in
16406 a static binary it may well have been omitted and GOT
16407 reduced to a table of addresses.
16408 PR 21344: Check for the entry being fully available
16409 before fetching it. */
16410 if (data
16411 && data + ent - pltgot + addr_size <= data_end
16412 && byte_get (data + ent - pltgot, addr_size) == 0)
16413 {
16414 printf (_(" Reserved entries:\n"));
16415 printf (_(" %*s %10s %*s\n"),
16416 addr_size * 2, _("Address"), _("Access"),
16417 addr_size * 2, _("Value"));
16418 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16419 printf ("\n");
16420 if (ent == (bfd_vma) -1)
16421 goto sgot_print_fail;
16422
16423 /* Check for the MSB of GOT[1] being set, identifying a
16424 GNU object. This entry will be used by some runtime
16425 loaders, to store the module pointer. Otherwise this
16426 is an ordinary local entry.
16427 PR 21344: Check for the entry being fully available
16428 before fetching it. */
16429 if (data
16430 && data + ent - pltgot + addr_size <= data_end
16431 && (byte_get (data + ent - pltgot, addr_size)
16432 >> (addr_size * 8 - 1)) != 0)
16433 {
16434 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16435 printf ("\n");
16436 if (ent == (bfd_vma) -1)
16437 goto sgot_print_fail;
16438 }
16439 printf ("\n");
16440 }
16441
16442 if (data != NULL && ent < end)
16443 {
16444 printf (_(" Local entries:\n"));
16445 printf (" %*s %10s %*s\n",
16446 addr_size * 2, _("Address"), _("Access"),
16447 addr_size * 2, _("Value"));
16448 while (ent < end)
16449 {
16450 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16451 printf ("\n");
16452 if (ent == (bfd_vma) -1)
16453 goto sgot_print_fail;
16454 }
16455 printf ("\n");
16456 }
16457
16458 sgot_print_fail:
16459 if (data)
16460 free (data);
16461 }
16462 return res;
16463 }
16464
16465 for (entry = dynamic_section;
16466 /* PR 17531 file: 012-50589-0.004. */
16467 entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
16468 ++entry)
16469 switch (entry->d_tag)
16470 {
16471 case DT_MIPS_LIBLIST:
16472 liblist_offset
16473 = offset_from_vma (filedata, entry->d_un.d_val,
16474 liblistno * sizeof (Elf32_External_Lib));
16475 break;
16476 case DT_MIPS_LIBLISTNO:
16477 liblistno = entry->d_un.d_val;
16478 break;
16479 case DT_MIPS_OPTIONS:
16480 options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
16481 break;
16482 case DT_MIPS_CONFLICT:
16483 conflicts_offset
16484 = offset_from_vma (filedata, entry->d_un.d_val,
16485 conflictsno * sizeof (Elf32_External_Conflict));
16486 break;
16487 case DT_MIPS_CONFLICTNO:
16488 conflictsno = entry->d_un.d_val;
16489 break;
16490 case DT_PLTGOT:
16491 pltgot = entry->d_un.d_ptr;
16492 break;
16493 case DT_MIPS_LOCAL_GOTNO:
16494 local_gotno = entry->d_un.d_val;
16495 break;
16496 case DT_MIPS_GOTSYM:
16497 gotsym = entry->d_un.d_val;
16498 break;
16499 case DT_MIPS_SYMTABNO:
16500 symtabno = entry->d_un.d_val;
16501 break;
16502 case DT_MIPS_PLTGOT:
16503 mips_pltgot = entry->d_un.d_ptr;
16504 break;
16505 case DT_PLTREL:
16506 pltrel = entry->d_un.d_val;
16507 break;
16508 case DT_PLTRELSZ:
16509 pltrelsz = entry->d_un.d_val;
16510 break;
16511 case DT_JMPREL:
16512 jmprel = entry->d_un.d_ptr;
16513 break;
16514 default:
16515 break;
16516 }
16517
16518 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
16519 {
16520 Elf32_External_Lib * elib;
16521 size_t cnt;
16522
16523 elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset,
16524 liblistno,
16525 sizeof (Elf32_External_Lib),
16526 _("liblist section data"));
16527 if (elib)
16528 {
16529 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
16530 "\nSection '.liblist' contains %lu entries:\n",
16531 (unsigned long) liblistno),
16532 (unsigned long) liblistno);
16533 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
16534 stdout);
16535
16536 for (cnt = 0; cnt < liblistno; ++cnt)
16537 {
16538 Elf32_Lib liblist;
16539 time_t atime;
16540 char timebuf[128];
16541 struct tm * tmp;
16542
16543 liblist.l_name = BYTE_GET (elib[cnt].l_name);
16544 atime = BYTE_GET (elib[cnt].l_time_stamp);
16545 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
16546 liblist.l_version = BYTE_GET (elib[cnt].l_version);
16547 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
16548
16549 tmp = gmtime (&atime);
16550 snprintf (timebuf, sizeof (timebuf),
16551 "%04u-%02u-%02uT%02u:%02u:%02u",
16552 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
16553 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
16554
16555 printf ("%3lu: ", (unsigned long) cnt);
16556 if (VALID_DYNAMIC_NAME (liblist.l_name))
16557 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
16558 else
16559 printf (_("<corrupt: %9ld>"), liblist.l_name);
16560 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
16561 liblist.l_version);
16562
16563 if (liblist.l_flags == 0)
16564 puts (_(" NONE"));
16565 else
16566 {
16567 static const struct
16568 {
16569 const char * name;
16570 int bit;
16571 }
16572 l_flags_vals[] =
16573 {
16574 { " EXACT_MATCH", LL_EXACT_MATCH },
16575 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
16576 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
16577 { " EXPORTS", LL_EXPORTS },
16578 { " DELAY_LOAD", LL_DELAY_LOAD },
16579 { " DELTA", LL_DELTA }
16580 };
16581 int flags = liblist.l_flags;
16582 size_t fcnt;
16583
16584 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
16585 if ((flags & l_flags_vals[fcnt].bit) != 0)
16586 {
16587 fputs (l_flags_vals[fcnt].name, stdout);
16588 flags ^= l_flags_vals[fcnt].bit;
16589 }
16590 if (flags != 0)
16591 printf (" %#x", (unsigned int) flags);
16592
16593 puts ("");
16594 }
16595 }
16596
16597 free (elib);
16598 }
16599 else
16600 res = FALSE;
16601 }
16602
16603 if (options_offset != 0)
16604 {
16605 Elf_External_Options * eopt;
16606 size_t offset;
16607 int cnt;
16608 sect = filedata->section_headers;
16609
16610 /* Find the section header so that we get the size. */
16611 sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS);
16612 /* PR 17533 file: 012-277276-0.004. */
16613 if (sect == NULL)
16614 {
16615 error (_("No MIPS_OPTIONS header found\n"));
16616 return FALSE;
16617 }
16618 /* PR 24243 */
16619 if (sect->sh_size < sizeof (* eopt))
16620 {
16621 error (_("The MIPS options section is too small.\n"));
16622 return FALSE;
16623 }
16624
16625 eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1,
16626 sect->sh_size, _("options"));
16627 if (eopt)
16628 {
16629 Elf_Internal_Options * iopt;
16630 Elf_Internal_Options * option;
16631 Elf_Internal_Options * iopt_end;
16632
16633 iopt = (Elf_Internal_Options *)
16634 cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
16635 if (iopt == NULL)
16636 {
16637 error (_("Out of memory allocating space for MIPS options\n"));
16638 return FALSE;
16639 }
16640
16641 offset = cnt = 0;
16642 option = iopt;
16643 iopt_end = iopt + (sect->sh_size / sizeof (eopt));
16644
16645 while (offset <= sect->sh_size - sizeof (* eopt))
16646 {
16647 Elf_External_Options * eoption;
16648
16649 eoption = (Elf_External_Options *) ((char *) eopt + offset);
16650
16651 option->kind = BYTE_GET (eoption->kind);
16652 option->size = BYTE_GET (eoption->size);
16653 option->section = BYTE_GET (eoption->section);
16654 option->info = BYTE_GET (eoption->info);
16655
16656 /* PR 17531: file: ffa0fa3b. */
16657 if (option->size < sizeof (* eopt)
16658 || offset + option->size > sect->sh_size)
16659 {
16660 error (_("Invalid size (%u) for MIPS option\n"), option->size);
16661 return FALSE;
16662 }
16663 offset += option->size;
16664
16665 ++option;
16666 ++cnt;
16667 }
16668
16669 printf (ngettext ("\nSection '%s' contains %d entry:\n",
16670 "\nSection '%s' contains %d entries:\n",
16671 cnt),
16672 printable_section_name (filedata, sect), cnt);
16673
16674 option = iopt;
16675 offset = 0;
16676
16677 while (cnt-- > 0)
16678 {
16679 size_t len;
16680
16681 switch (option->kind)
16682 {
16683 case ODK_NULL:
16684 /* This shouldn't happen. */
16685 printf (" NULL %d %lx", option->section, option->info);
16686 break;
16687
16688 case ODK_REGINFO:
16689 printf (" REGINFO ");
16690 if (filedata->file_header.e_machine == EM_MIPS)
16691 {
16692 Elf32_External_RegInfo * ereg;
16693 Elf32_RegInfo reginfo;
16694
16695 /* 32bit form. */
16696 if (option + 2 > iopt_end)
16697 {
16698 printf (_("<corrupt>\n"));
16699 error (_("Truncated MIPS REGINFO option\n"));
16700 cnt = 0;
16701 break;
16702 }
16703
16704 ereg = (Elf32_External_RegInfo *) (option + 1);
16705
16706 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
16707 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
16708 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
16709 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
16710 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
16711 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
16712
16713 printf ("GPR %08lx GP 0x%lx\n",
16714 reginfo.ri_gprmask,
16715 (unsigned long) reginfo.ri_gp_value);
16716 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16717 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
16718 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
16719 }
16720 else
16721 {
16722 /* 64 bit form. */
16723 Elf64_External_RegInfo * ereg;
16724 Elf64_Internal_RegInfo reginfo;
16725
16726 if (option + 2 > iopt_end)
16727 {
16728 printf (_("<corrupt>\n"));
16729 error (_("Truncated MIPS REGINFO option\n"));
16730 cnt = 0;
16731 break;
16732 }
16733
16734 ereg = (Elf64_External_RegInfo *) (option + 1);
16735 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
16736 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
16737 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
16738 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
16739 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
16740 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
16741
16742 printf ("GPR %08lx GP 0x",
16743 reginfo.ri_gprmask);
16744 printf_vma (reginfo.ri_gp_value);
16745 printf ("\n");
16746
16747 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16748 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
16749 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
16750 }
16751 ++option;
16752 continue;
16753
16754 case ODK_EXCEPTIONS:
16755 fputs (" EXCEPTIONS fpe_min(", stdout);
16756 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
16757 fputs (") fpe_max(", stdout);
16758 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
16759 fputs (")", stdout);
16760
16761 if (option->info & OEX_PAGE0)
16762 fputs (" PAGE0", stdout);
16763 if (option->info & OEX_SMM)
16764 fputs (" SMM", stdout);
16765 if (option->info & OEX_FPDBUG)
16766 fputs (" FPDBUG", stdout);
16767 if (option->info & OEX_DISMISS)
16768 fputs (" DISMISS", stdout);
16769 break;
16770
16771 case ODK_PAD:
16772 fputs (" PAD ", stdout);
16773 if (option->info & OPAD_PREFIX)
16774 fputs (" PREFIX", stdout);
16775 if (option->info & OPAD_POSTFIX)
16776 fputs (" POSTFIX", stdout);
16777 if (option->info & OPAD_SYMBOL)
16778 fputs (" SYMBOL", stdout);
16779 break;
16780
16781 case ODK_HWPATCH:
16782 fputs (" HWPATCH ", stdout);
16783 if (option->info & OHW_R4KEOP)
16784 fputs (" R4KEOP", stdout);
16785 if (option->info & OHW_R8KPFETCH)
16786 fputs (" R8KPFETCH", stdout);
16787 if (option->info & OHW_R5KEOP)
16788 fputs (" R5KEOP", stdout);
16789 if (option->info & OHW_R5KCVTL)
16790 fputs (" R5KCVTL", stdout);
16791 break;
16792
16793 case ODK_FILL:
16794 fputs (" FILL ", stdout);
16795 /* XXX Print content of info word? */
16796 break;
16797
16798 case ODK_TAGS:
16799 fputs (" TAGS ", stdout);
16800 /* XXX Print content of info word? */
16801 break;
16802
16803 case ODK_HWAND:
16804 fputs (" HWAND ", stdout);
16805 if (option->info & OHWA0_R4KEOP_CHECKED)
16806 fputs (" R4KEOP_CHECKED", stdout);
16807 if (option->info & OHWA0_R4KEOP_CLEAN)
16808 fputs (" R4KEOP_CLEAN", stdout);
16809 break;
16810
16811 case ODK_HWOR:
16812 fputs (" HWOR ", stdout);
16813 if (option->info & OHWA0_R4KEOP_CHECKED)
16814 fputs (" R4KEOP_CHECKED", stdout);
16815 if (option->info & OHWA0_R4KEOP_CLEAN)
16816 fputs (" R4KEOP_CLEAN", stdout);
16817 break;
16818
16819 case ODK_GP_GROUP:
16820 printf (" GP_GROUP %#06lx self-contained %#06lx",
16821 option->info & OGP_GROUP,
16822 (option->info & OGP_SELF) >> 16);
16823 break;
16824
16825 case ODK_IDENT:
16826 printf (" IDENT %#06lx self-contained %#06lx",
16827 option->info & OGP_GROUP,
16828 (option->info & OGP_SELF) >> 16);
16829 break;
16830
16831 default:
16832 /* This shouldn't happen. */
16833 printf (" %3d ??? %d %lx",
16834 option->kind, option->section, option->info);
16835 break;
16836 }
16837
16838 len = sizeof (* eopt);
16839 while (len < option->size)
16840 {
16841 unsigned char datum = * ((unsigned char *) eopt + offset + len);
16842
16843 if (ISPRINT (datum))
16844 printf ("%c", datum);
16845 else
16846 printf ("\\%03o", datum);
16847 len ++;
16848 }
16849 fputs ("\n", stdout);
16850
16851 offset += option->size;
16852 ++option;
16853 }
16854
16855 free (eopt);
16856 }
16857 else
16858 res = FALSE;
16859 }
16860
16861 if (conflicts_offset != 0 && conflictsno != 0)
16862 {
16863 Elf32_Conflict * iconf;
16864 size_t cnt;
16865
16866 if (dynamic_symbols == NULL)
16867 {
16868 error (_("conflict list found without a dynamic symbol table\n"));
16869 return FALSE;
16870 }
16871
16872 /* PR 21345 - print a slightly more helpful error message
16873 if we are sure that the cmalloc will fail. */
16874 if (conflictsno * sizeof (* iconf) > filedata->file_size)
16875 {
16876 error (_("Overlarge number of conflicts detected: %lx\n"),
16877 (long) conflictsno);
16878 return FALSE;
16879 }
16880
16881 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
16882 if (iconf == NULL)
16883 {
16884 error (_("Out of memory allocating space for dynamic conflicts\n"));
16885 return FALSE;
16886 }
16887
16888 if (is_32bit_elf)
16889 {
16890 Elf32_External_Conflict * econf32;
16891
16892 econf32 = (Elf32_External_Conflict *)
16893 get_data (NULL, filedata, conflicts_offset, conflictsno,
16894 sizeof (* econf32), _("conflict"));
16895 if (!econf32)
16896 return FALSE;
16897
16898 for (cnt = 0; cnt < conflictsno; ++cnt)
16899 iconf[cnt] = BYTE_GET (econf32[cnt]);
16900
16901 free (econf32);
16902 }
16903 else
16904 {
16905 Elf64_External_Conflict * econf64;
16906
16907 econf64 = (Elf64_External_Conflict *)
16908 get_data (NULL, filedata, conflicts_offset, conflictsno,
16909 sizeof (* econf64), _("conflict"));
16910 if (!econf64)
16911 return FALSE;
16912
16913 for (cnt = 0; cnt < conflictsno; ++cnt)
16914 iconf[cnt] = BYTE_GET (econf64[cnt]);
16915
16916 free (econf64);
16917 }
16918
16919 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
16920 "\nSection '.conflict' contains %lu entries:\n",
16921 (unsigned long) conflictsno),
16922 (unsigned long) conflictsno);
16923 puts (_(" Num: Index Value Name"));
16924
16925 for (cnt = 0; cnt < conflictsno; ++cnt)
16926 {
16927 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
16928
16929 if (iconf[cnt] >= num_dynamic_syms)
16930 printf (_("<corrupt symbol index>"));
16931 else
16932 {
16933 Elf_Internal_Sym * psym;
16934
16935 psym = & dynamic_symbols[iconf[cnt]];
16936 print_vma (psym->st_value, FULL_HEX);
16937 putchar (' ');
16938 if (VALID_DYNAMIC_NAME (psym->st_name))
16939 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
16940 else
16941 printf (_("<corrupt: %14ld>"), psym->st_name);
16942 }
16943 putchar ('\n');
16944 }
16945
16946 free (iconf);
16947 }
16948
16949 if (pltgot != 0 && local_gotno != 0)
16950 {
16951 bfd_vma ent, local_end, global_end;
16952 size_t i, offset;
16953 unsigned char * data;
16954 unsigned char * data_end;
16955 int addr_size;
16956
16957 ent = pltgot;
16958 addr_size = (is_32bit_elf ? 4 : 8);
16959 local_end = pltgot + local_gotno * addr_size;
16960
16961 /* PR binutils/17533 file: 012-111227-0.004 */
16962 if (symtabno < gotsym)
16963 {
16964 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
16965 (unsigned long) gotsym, (unsigned long) symtabno);
16966 return FALSE;
16967 }
16968
16969 global_end = local_end + (symtabno - gotsym) * addr_size;
16970 /* PR 17531: file: 54c91a34. */
16971 if (global_end < local_end)
16972 {
16973 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
16974 return FALSE;
16975 }
16976
16977 offset = offset_from_vma (filedata, pltgot, global_end - pltgot);
16978 data = (unsigned char *) get_data (NULL, filedata, offset,
16979 global_end - pltgot, 1,
16980 _("Global Offset Table data"));
16981 /* PR 12855: Null data is handled gracefully throughout. */
16982 data_end = data + (global_end - pltgot);
16983
16984 printf (_("\nPrimary GOT:\n"));
16985 printf (_(" Canonical gp value: "));
16986 print_vma (pltgot + 0x7ff0, LONG_HEX);
16987 printf ("\n\n");
16988
16989 printf (_(" Reserved entries:\n"));
16990 printf (_(" %*s %10s %*s Purpose\n"),
16991 addr_size * 2, _("Address"), _("Access"),
16992 addr_size * 2, _("Initial"));
16993 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16994 printf (_(" Lazy resolver\n"));
16995 if (ent == (bfd_vma) -1)
16996 goto got_print_fail;
16997
16998 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
16999 This entry will be used by some runtime loaders, to store the
17000 module pointer. Otherwise this is an ordinary local entry.
17001 PR 21344: Check for the entry being fully available before
17002 fetching it. */
17003 if (data
17004 && data + ent - pltgot + addr_size <= data_end
17005 && (byte_get (data + ent - pltgot, addr_size)
17006 >> (addr_size * 8 - 1)) != 0)
17007 {
17008 ent = print_mips_got_entry (data, pltgot, ent, data_end);
17009 printf (_(" Module pointer (GNU extension)\n"));
17010 if (ent == (bfd_vma) -1)
17011 goto got_print_fail;
17012 }
17013 printf ("\n");
17014
17015 if (data != NULL && ent < local_end)
17016 {
17017 printf (_(" Local entries:\n"));
17018 printf (" %*s %10s %*s\n",
17019 addr_size * 2, _("Address"), _("Access"),
17020 addr_size * 2, _("Initial"));
17021 while (ent < local_end)
17022 {
17023 ent = print_mips_got_entry (data, pltgot, ent, data_end);
17024 printf ("\n");
17025 if (ent == (bfd_vma) -1)
17026 goto got_print_fail;
17027 }
17028 printf ("\n");
17029 }
17030
17031 if (data != NULL && gotsym < symtabno)
17032 {
17033 int sym_width;
17034
17035 printf (_(" Global entries:\n"));
17036 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
17037 addr_size * 2, _("Address"),
17038 _("Access"),
17039 addr_size * 2, _("Initial"),
17040 addr_size * 2, _("Sym.Val."),
17041 _("Type"),
17042 /* Note for translators: "Ndx" = abbreviated form of "Index". */
17043 _("Ndx"), _("Name"));
17044
17045 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
17046
17047 for (i = gotsym; i < symtabno; i++)
17048 {
17049 ent = print_mips_got_entry (data, pltgot, ent, data_end);
17050 printf (" ");
17051
17052 if (dynamic_symbols == NULL)
17053 printf (_("<no dynamic symbols>"));
17054 else if (i < num_dynamic_syms)
17055 {
17056 Elf_Internal_Sym * psym = dynamic_symbols + i;
17057
17058 print_vma (psym->st_value, LONG_HEX);
17059 printf (" %-7s %3s ",
17060 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
17061 get_symbol_index_type (filedata, psym->st_shndx));
17062
17063 if (VALID_DYNAMIC_NAME (psym->st_name))
17064 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
17065 else
17066 printf (_("<corrupt: %14ld>"), psym->st_name);
17067 }
17068 else
17069 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
17070 (unsigned long) i);
17071
17072 printf ("\n");
17073 if (ent == (bfd_vma) -1)
17074 break;
17075 }
17076 printf ("\n");
17077 }
17078
17079 got_print_fail:
17080 if (data)
17081 free (data);
17082 }
17083
17084 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
17085 {
17086 bfd_vma ent, end;
17087 size_t offset, rel_offset;
17088 unsigned long count, i;
17089 unsigned char * data;
17090 int addr_size, sym_width;
17091 Elf_Internal_Rela * rels;
17092
17093 rel_offset = offset_from_vma (filedata, jmprel, pltrelsz);
17094 if (pltrel == DT_RELA)
17095 {
17096 if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
17097 return FALSE;
17098 }
17099 else
17100 {
17101 if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
17102 return FALSE;
17103 }
17104
17105 ent = mips_pltgot;
17106 addr_size = (is_32bit_elf ? 4 : 8);
17107 end = mips_pltgot + (2 + count) * addr_size;
17108
17109 offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot);
17110 data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot,
17111 1, _("Procedure Linkage Table data"));
17112 if (data == NULL)
17113 return FALSE;
17114
17115 printf ("\nPLT GOT:\n\n");
17116 printf (_(" Reserved entries:\n"));
17117 printf (_(" %*s %*s Purpose\n"),
17118 addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
17119 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
17120 printf (_(" PLT lazy resolver\n"));
17121 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
17122 printf (_(" Module pointer\n"));
17123 printf ("\n");
17124
17125 printf (_(" Entries:\n"));
17126 printf (" %*s %*s %*s %-7s %3s %s\n",
17127 addr_size * 2, _("Address"),
17128 addr_size * 2, _("Initial"),
17129 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
17130 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
17131 for (i = 0; i < count; i++)
17132 {
17133 unsigned long idx = get_reloc_symindex (rels[i].r_info);
17134
17135 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
17136 printf (" ");
17137
17138 if (idx >= num_dynamic_syms)
17139 printf (_("<corrupt symbol index: %lu>"), idx);
17140 else
17141 {
17142 Elf_Internal_Sym * psym = dynamic_symbols + idx;
17143
17144 print_vma (psym->st_value, LONG_HEX);
17145 printf (" %-7s %3s ",
17146 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
17147 get_symbol_index_type (filedata, psym->st_shndx));
17148 if (VALID_DYNAMIC_NAME (psym->st_name))
17149 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
17150 else
17151 printf (_("<corrupt: %14ld>"), psym->st_name);
17152 }
17153 printf ("\n");
17154 }
17155 printf ("\n");
17156
17157 if (data)
17158 free (data);
17159 free (rels);
17160 }
17161
17162 return res;
17163 }
17164
17165 static bfd_boolean
17166 process_nds32_specific (Filedata * filedata)
17167 {
17168 Elf_Internal_Shdr *sect = NULL;
17169
17170 sect = find_section (filedata, ".nds32_e_flags");
17171 if (sect != NULL)
17172 {
17173 unsigned int *flag;
17174
17175 printf ("\nNDS32 elf flags section:\n");
17176 flag = get_data (NULL, filedata, sect->sh_offset, 1,
17177 sect->sh_size, _("NDS32 elf flags section"));
17178
17179 if (! flag)
17180 return FALSE;
17181
17182 switch ((*flag) & 0x3)
17183 {
17184 case 0:
17185 printf ("(VEC_SIZE):\tNo entry.\n");
17186 break;
17187 case 1:
17188 printf ("(VEC_SIZE):\t4 bytes\n");
17189 break;
17190 case 2:
17191 printf ("(VEC_SIZE):\t16 bytes\n");
17192 break;
17193 case 3:
17194 printf ("(VEC_SIZE):\treserved\n");
17195 break;
17196 }
17197 }
17198
17199 return TRUE;
17200 }
17201
17202 static bfd_boolean
17203 process_gnu_liblist (Filedata * filedata)
17204 {
17205 Elf_Internal_Shdr * section;
17206 Elf_Internal_Shdr * string_sec;
17207 Elf32_External_Lib * elib;
17208 char * strtab;
17209 size_t strtab_size;
17210 size_t cnt;
17211 unsigned long num_liblist;
17212 unsigned i;
17213 bfd_boolean res = TRUE;
17214
17215 if (! do_arch)
17216 return TRUE;
17217
17218 for (i = 0, section = filedata->section_headers;
17219 i < filedata->file_header.e_shnum;
17220 i++, section++)
17221 {
17222 switch (section->sh_type)
17223 {
17224 case SHT_GNU_LIBLIST:
17225 if (section->sh_link >= filedata->file_header.e_shnum)
17226 break;
17227
17228 elib = (Elf32_External_Lib *)
17229 get_data (NULL, filedata, section->sh_offset, 1, section->sh_size,
17230 _("liblist section data"));
17231
17232 if (elib == NULL)
17233 {
17234 res = FALSE;
17235 break;
17236 }
17237
17238 string_sec = filedata->section_headers + section->sh_link;
17239 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
17240 string_sec->sh_size,
17241 _("liblist string table"));
17242 if (strtab == NULL
17243 || section->sh_entsize != sizeof (Elf32_External_Lib))
17244 {
17245 free (elib);
17246 free (strtab);
17247 res = FALSE;
17248 break;
17249 }
17250 strtab_size = string_sec->sh_size;
17251
17252 num_liblist = section->sh_size / sizeof (Elf32_External_Lib);
17253 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
17254 "\nLibrary list section '%s' contains %lu entries:\n",
17255 num_liblist),
17256 printable_section_name (filedata, section),
17257 num_liblist);
17258
17259 puts (_(" Library Time Stamp Checksum Version Flags"));
17260
17261 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
17262 ++cnt)
17263 {
17264 Elf32_Lib liblist;
17265 time_t atime;
17266 char timebuf[128];
17267 struct tm * tmp;
17268
17269 liblist.l_name = BYTE_GET (elib[cnt].l_name);
17270 atime = BYTE_GET (elib[cnt].l_time_stamp);
17271 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
17272 liblist.l_version = BYTE_GET (elib[cnt].l_version);
17273 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
17274
17275 tmp = gmtime (&atime);
17276 snprintf (timebuf, sizeof (timebuf),
17277 "%04u-%02u-%02uT%02u:%02u:%02u",
17278 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
17279 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
17280
17281 printf ("%3lu: ", (unsigned long) cnt);
17282 if (do_wide)
17283 printf ("%-20s", liblist.l_name < strtab_size
17284 ? strtab + liblist.l_name : _("<corrupt>"));
17285 else
17286 printf ("%-20.20s", liblist.l_name < strtab_size
17287 ? strtab + liblist.l_name : _("<corrupt>"));
17288 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
17289 liblist.l_version, liblist.l_flags);
17290 }
17291
17292 free (elib);
17293 free (strtab);
17294 }
17295 }
17296
17297 return res;
17298 }
17299
17300 static const char *
17301 get_note_type (Filedata * filedata, unsigned e_type)
17302 {
17303 static char buff[64];
17304
17305 if (filedata->file_header.e_type == ET_CORE)
17306 switch (e_type)
17307 {
17308 case NT_AUXV:
17309 return _("NT_AUXV (auxiliary vector)");
17310 case NT_PRSTATUS:
17311 return _("NT_PRSTATUS (prstatus structure)");
17312 case NT_FPREGSET:
17313 return _("NT_FPREGSET (floating point registers)");
17314 case NT_PRPSINFO:
17315 return _("NT_PRPSINFO (prpsinfo structure)");
17316 case NT_TASKSTRUCT:
17317 return _("NT_TASKSTRUCT (task structure)");
17318 case NT_PRXFPREG:
17319 return _("NT_PRXFPREG (user_xfpregs structure)");
17320 case NT_PPC_VMX:
17321 return _("NT_PPC_VMX (ppc Altivec registers)");
17322 case NT_PPC_VSX:
17323 return _("NT_PPC_VSX (ppc VSX registers)");
17324 case NT_PPC_TAR:
17325 return _("NT_PPC_TAR (ppc TAR register)");
17326 case NT_PPC_PPR:
17327 return _("NT_PPC_PPR (ppc PPR register)");
17328 case NT_PPC_DSCR:
17329 return _("NT_PPC_DSCR (ppc DSCR register)");
17330 case NT_PPC_EBB:
17331 return _("NT_PPC_EBB (ppc EBB registers)");
17332 case NT_PPC_PMU:
17333 return _("NT_PPC_PMU (ppc PMU registers)");
17334 case NT_PPC_TM_CGPR:
17335 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
17336 case NT_PPC_TM_CFPR:
17337 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
17338 case NT_PPC_TM_CVMX:
17339 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
17340 case NT_PPC_TM_CVSX:
17341 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
17342 case NT_PPC_TM_SPR:
17343 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
17344 case NT_PPC_TM_CTAR:
17345 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
17346 case NT_PPC_TM_CPPR:
17347 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
17348 case NT_PPC_TM_CDSCR:
17349 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
17350 case NT_386_TLS:
17351 return _("NT_386_TLS (x86 TLS information)");
17352 case NT_386_IOPERM:
17353 return _("NT_386_IOPERM (x86 I/O permissions)");
17354 case NT_X86_XSTATE:
17355 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
17356 case NT_S390_HIGH_GPRS:
17357 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
17358 case NT_S390_TIMER:
17359 return _("NT_S390_TIMER (s390 timer register)");
17360 case NT_S390_TODCMP:
17361 return _("NT_S390_TODCMP (s390 TOD comparator register)");
17362 case NT_S390_TODPREG:
17363 return _("NT_S390_TODPREG (s390 TOD programmable register)");
17364 case NT_S390_CTRS:
17365 return _("NT_S390_CTRS (s390 control registers)");
17366 case NT_S390_PREFIX:
17367 return _("NT_S390_PREFIX (s390 prefix register)");
17368 case NT_S390_LAST_BREAK:
17369 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
17370 case NT_S390_SYSTEM_CALL:
17371 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
17372 case NT_S390_TDB:
17373 return _("NT_S390_TDB (s390 transaction diagnostic block)");
17374 case NT_S390_VXRS_LOW:
17375 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
17376 case NT_S390_VXRS_HIGH:
17377 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
17378 case NT_S390_GS_CB:
17379 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
17380 case NT_S390_GS_BC:
17381 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
17382 case NT_ARM_VFP:
17383 return _("NT_ARM_VFP (arm VFP registers)");
17384 case NT_ARM_TLS:
17385 return _("NT_ARM_TLS (AArch TLS registers)");
17386 case NT_ARM_HW_BREAK:
17387 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
17388 case NT_ARM_HW_WATCH:
17389 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
17390 case NT_PSTATUS:
17391 return _("NT_PSTATUS (pstatus structure)");
17392 case NT_FPREGS:
17393 return _("NT_FPREGS (floating point registers)");
17394 case NT_PSINFO:
17395 return _("NT_PSINFO (psinfo structure)");
17396 case NT_LWPSTATUS:
17397 return _("NT_LWPSTATUS (lwpstatus_t structure)");
17398 case NT_LWPSINFO:
17399 return _("NT_LWPSINFO (lwpsinfo_t structure)");
17400 case NT_WIN32PSTATUS:
17401 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
17402 case NT_SIGINFO:
17403 return _("NT_SIGINFO (siginfo_t data)");
17404 case NT_FILE:
17405 return _("NT_FILE (mapped files)");
17406 default:
17407 break;
17408 }
17409 else
17410 switch (e_type)
17411 {
17412 case NT_VERSION:
17413 return _("NT_VERSION (version)");
17414 case NT_ARCH:
17415 return _("NT_ARCH (architecture)");
17416 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
17417 return _("OPEN");
17418 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
17419 return _("func");
17420 default:
17421 break;
17422 }
17423
17424 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17425 return buff;
17426 }
17427
17428 static bfd_boolean
17429 print_core_note (Elf_Internal_Note *pnote)
17430 {
17431 unsigned int addr_size = is_32bit_elf ? 4 : 8;
17432 bfd_vma count, page_size;
17433 unsigned char *descdata, *filenames, *descend;
17434
17435 if (pnote->type != NT_FILE)
17436 {
17437 if (do_wide)
17438 printf ("\n");
17439 return TRUE;
17440 }
17441
17442 #ifndef BFD64
17443 if (!is_32bit_elf)
17444 {
17445 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
17446 /* Still "successful". */
17447 return TRUE;
17448 }
17449 #endif
17450
17451 if (pnote->descsz < 2 * addr_size)
17452 {
17453 error (_(" Malformed note - too short for header\n"));
17454 return FALSE;
17455 }
17456
17457 descdata = (unsigned char *) pnote->descdata;
17458 descend = descdata + pnote->descsz;
17459
17460 if (descdata[pnote->descsz - 1] != '\0')
17461 {
17462 error (_(" Malformed note - does not end with \\0\n"));
17463 return FALSE;
17464 }
17465
17466 count = byte_get (descdata, addr_size);
17467 descdata += addr_size;
17468
17469 page_size = byte_get (descdata, addr_size);
17470 descdata += addr_size;
17471
17472 if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size)
17473 || pnote->descsz < 2 * addr_size + count * 3 * addr_size)
17474 {
17475 error (_(" Malformed note - too short for supplied file count\n"));
17476 return FALSE;
17477 }
17478
17479 printf (_(" Page size: "));
17480 print_vma (page_size, DEC);
17481 printf ("\n");
17482
17483 printf (_(" %*s%*s%*s\n"),
17484 (int) (2 + 2 * addr_size), _("Start"),
17485 (int) (4 + 2 * addr_size), _("End"),
17486 (int) (4 + 2 * addr_size), _("Page Offset"));
17487 filenames = descdata + count * 3 * addr_size;
17488 while (count-- > 0)
17489 {
17490 bfd_vma start, end, file_ofs;
17491
17492 if (filenames == descend)
17493 {
17494 error (_(" Malformed note - filenames end too early\n"));
17495 return FALSE;
17496 }
17497
17498 start = byte_get (descdata, addr_size);
17499 descdata += addr_size;
17500 end = byte_get (descdata, addr_size);
17501 descdata += addr_size;
17502 file_ofs = byte_get (descdata, addr_size);
17503 descdata += addr_size;
17504
17505 printf (" ");
17506 print_vma (start, FULL_HEX);
17507 printf (" ");
17508 print_vma (end, FULL_HEX);
17509 printf (" ");
17510 print_vma (file_ofs, FULL_HEX);
17511 printf ("\n %s\n", filenames);
17512
17513 filenames += 1 + strlen ((char *) filenames);
17514 }
17515
17516 return TRUE;
17517 }
17518
17519 static const char *
17520 get_gnu_elf_note_type (unsigned e_type)
17521 {
17522 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
17523 switch (e_type)
17524 {
17525 case NT_GNU_ABI_TAG:
17526 return _("NT_GNU_ABI_TAG (ABI version tag)");
17527 case NT_GNU_HWCAP:
17528 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
17529 case NT_GNU_BUILD_ID:
17530 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
17531 case NT_GNU_GOLD_VERSION:
17532 return _("NT_GNU_GOLD_VERSION (gold version)");
17533 case NT_GNU_PROPERTY_TYPE_0:
17534 return _("NT_GNU_PROPERTY_TYPE_0");
17535 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
17536 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
17537 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
17538 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
17539 default:
17540 {
17541 static char buff[64];
17542
17543 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17544 return buff;
17545 }
17546 }
17547 }
17548
17549 static void
17550 decode_x86_compat_isa (unsigned int bitmask)
17551 {
17552 while (bitmask)
17553 {
17554 unsigned int bit = bitmask & (- bitmask);
17555
17556 bitmask &= ~ bit;
17557 switch (bit)
17558 {
17559 case GNU_PROPERTY_X86_COMPAT_ISA_1_486:
17560 printf ("i486");
17561 break;
17562 case GNU_PROPERTY_X86_COMPAT_ISA_1_586:
17563 printf ("586");
17564 break;
17565 case GNU_PROPERTY_X86_COMPAT_ISA_1_686:
17566 printf ("686");
17567 break;
17568 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE:
17569 printf ("SSE");
17570 break;
17571 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2:
17572 printf ("SSE2");
17573 break;
17574 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3:
17575 printf ("SSE3");
17576 break;
17577 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3:
17578 printf ("SSSE3");
17579 break;
17580 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1:
17581 printf ("SSE4_1");
17582 break;
17583 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2:
17584 printf ("SSE4_2");
17585 break;
17586 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX:
17587 printf ("AVX");
17588 break;
17589 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2:
17590 printf ("AVX2");
17591 break;
17592 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F:
17593 printf ("AVX512F");
17594 break;
17595 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD:
17596 printf ("AVX512CD");
17597 break;
17598 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER:
17599 printf ("AVX512ER");
17600 break;
17601 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF:
17602 printf ("AVX512PF");
17603 break;
17604 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL:
17605 printf ("AVX512VL");
17606 break;
17607 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ:
17608 printf ("AVX512DQ");
17609 break;
17610 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW:
17611 printf ("AVX512BW");
17612 break;
17613 default:
17614 printf (_("<unknown: %x>"), bit);
17615 break;
17616 }
17617 if (bitmask)
17618 printf (", ");
17619 }
17620 }
17621
17622 static void
17623 decode_x86_isa (unsigned int bitmask)
17624 {
17625 if (!bitmask)
17626 {
17627 printf (_("<None>"));
17628 return;
17629 }
17630
17631 while (bitmask)
17632 {
17633 unsigned int bit = bitmask & (- bitmask);
17634
17635 bitmask &= ~ bit;
17636 switch (bit)
17637 {
17638 case GNU_PROPERTY_X86_ISA_1_CMOV:
17639 printf ("CMOV");
17640 break;
17641 case GNU_PROPERTY_X86_ISA_1_SSE:
17642 printf ("SSE");
17643 break;
17644 case GNU_PROPERTY_X86_ISA_1_SSE2:
17645 printf ("SSE2");
17646 break;
17647 case GNU_PROPERTY_X86_ISA_1_SSE3:
17648 printf ("SSE3");
17649 break;
17650 case GNU_PROPERTY_X86_ISA_1_SSSE3:
17651 printf ("SSSE3");
17652 break;
17653 case GNU_PROPERTY_X86_ISA_1_SSE4_1:
17654 printf ("SSE4_1");
17655 break;
17656 case GNU_PROPERTY_X86_ISA_1_SSE4_2:
17657 printf ("SSE4_2");
17658 break;
17659 case GNU_PROPERTY_X86_ISA_1_AVX:
17660 printf ("AVX");
17661 break;
17662 case GNU_PROPERTY_X86_ISA_1_AVX2:
17663 printf ("AVX2");
17664 break;
17665 case GNU_PROPERTY_X86_ISA_1_FMA:
17666 printf ("FMA");
17667 break;
17668 case GNU_PROPERTY_X86_ISA_1_AVX512F:
17669 printf ("AVX512F");
17670 break;
17671 case GNU_PROPERTY_X86_ISA_1_AVX512CD:
17672 printf ("AVX512CD");
17673 break;
17674 case GNU_PROPERTY_X86_ISA_1_AVX512ER:
17675 printf ("AVX512ER");
17676 break;
17677 case GNU_PROPERTY_X86_ISA_1_AVX512PF:
17678 printf ("AVX512PF");
17679 break;
17680 case GNU_PROPERTY_X86_ISA_1_AVX512VL:
17681 printf ("AVX512VL");
17682 break;
17683 case GNU_PROPERTY_X86_ISA_1_AVX512DQ:
17684 printf ("AVX512DQ");
17685 break;
17686 case GNU_PROPERTY_X86_ISA_1_AVX512BW:
17687 printf ("AVX512BW");
17688 break;
17689 case GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS:
17690 printf ("AVX512_4FMAPS");
17691 break;
17692 case GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW:
17693 printf ("AVX512_4VNNIW");
17694 break;
17695 case GNU_PROPERTY_X86_ISA_1_AVX512_BITALG:
17696 printf ("AVX512_BITALG");
17697 break;
17698 case GNU_PROPERTY_X86_ISA_1_AVX512_IFMA:
17699 printf ("AVX512_IFMA");
17700 break;
17701 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI:
17702 printf ("AVX512_VBMI");
17703 break;
17704 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2:
17705 printf ("AVX512_VBMI2");
17706 break;
17707 case GNU_PROPERTY_X86_ISA_1_AVX512_VNNI:
17708 printf ("AVX512_VNNI");
17709 break;
17710 case GNU_PROPERTY_X86_ISA_1_AVX512_BF16:
17711 printf ("AVX512_BF16");
17712 break;
17713 default:
17714 printf (_("<unknown: %x>"), bit);
17715 break;
17716 }
17717 if (bitmask)
17718 printf (", ");
17719 }
17720 }
17721
17722 static const char *
17723 get_amd_elf_note_type (unsigned e_type)
17724 {
17725 static char buff[64];
17726
17727 switch (e_type)
17728 {
17729 case NT_AMDGPU_HSA_CODE_OBJECT_VERSION:
17730 return _("NT_AMDGPU_HSA_CODE_OBJECT_VERSION (code object version)");
17731 case NT_AMDGPU_HSA_HSAIL:
17732 return _("NT_AMDGPU_HSA_HSAIL (hsail)");
17733 case NT_AMDGPU_HSA_ISA:
17734 return _("NT_AMDGPU_HSA_ISA (ISA name)");
17735 case NT_AMDGPU_HSA_PRODUCER:
17736 return _("NT_AMDGPU_HSA_PRODUCER (producer name)");
17737 case NT_AMDGPU_HSA_PRODUCER_OPTIONS:
17738 return _("NT_AMDGPU_HSA_PRODUCER_OPTIONS (producer options");
17739 case NT_AMDGPU_HSA_EXTENSION:
17740 return _("NT_AMDGPU_HSA_EXTENSION (extension)");
17741 case NT_AMDGPU_HSA_METADATA:
17742 return _("NT_AMDGPU_HSA_METADATA (code object metadata)");
17743 case NT_AMDGPU_ISA:
17744 return _("NT_AMDGPU_ISA");
17745 case NT_AMDGPU_PAL_METADATA:
17746 return _("NT_AMDGPU_PAL_METADATA (code object metadata)");
17747 case NT_AMDGPU_METADATA:
17748 return _("NT_AMDGPU_METADATA (code object metadata)");
17749 default:
17750 break;
17751 }
17752
17753 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17754 return buff;
17755 }
17756
17757 static int
17758 print_amd_note (Elf_Internal_Note *pnote)
17759 {
17760 switch (pnote->type)
17761 {
17762 case NT_AMDGPU_HSA_CODE_OBJECT_VERSION:
17763 {
17764 unsigned int major, minor;
17765
17766 major = byte_get ((unsigned char*) pnote->descdata, 4);
17767 minor = byte_get ((unsigned char*) pnote->descdata + 4, 4);
17768
17769 printf (_(" Version: %d.%d\n"), major, minor);
17770 }
17771 break;
17772
17773 case NT_AMDGPU_HSA_ISA:
17774 {
17775 unsigned long i, vendorsz;
17776 unsigned int major, minor, stepping;
17777
17778 vendorsz = byte_get ((unsigned char*) pnote->descdata, 2);
17779 major = byte_get ((unsigned char*) pnote->descdata + 4, 4);
17780 minor = byte_get ((unsigned char*) pnote->descdata + 8, 4);
17781 stepping = byte_get ((unsigned char*) pnote->descdata + 12, 4);
17782
17783 printf (_(" Vendor: "));
17784 for (i = 16; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
17785 printf ("%c", pnote->descdata[i]);
17786 printf (_(", Architecture: "));
17787 for (i = 16 + vendorsz; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
17788 printf ("%c", pnote->descdata[i]);
17789
17790 printf (_(", Version: %d.%d.%d"), major, minor, stepping);
17791 printf ("\n");
17792 }
17793 break;
17794 }
17795 return 1;
17796 }
17797
17798 static void
17799 decode_x86_feature_1 (unsigned int bitmask)
17800 {
17801 if (!bitmask)
17802 {
17803 printf (_("<None>"));
17804 return;
17805 }
17806
17807 while (bitmask)
17808 {
17809 unsigned int bit = bitmask & (- bitmask);
17810
17811 bitmask &= ~ bit;
17812 switch (bit)
17813 {
17814 case GNU_PROPERTY_X86_FEATURE_1_IBT:
17815 printf ("IBT");
17816 break;
17817 case GNU_PROPERTY_X86_FEATURE_1_SHSTK:
17818 printf ("SHSTK");
17819 break;
17820 default:
17821 printf (_("<unknown: %x>"), bit);
17822 break;
17823 }
17824 if (bitmask)
17825 printf (", ");
17826 }
17827 }
17828
17829 static void
17830 decode_x86_feature_2 (unsigned int bitmask)
17831 {
17832 if (!bitmask)
17833 {
17834 printf (_("<None>"));
17835 return;
17836 }
17837
17838 while (bitmask)
17839 {
17840 unsigned int bit = bitmask & (- bitmask);
17841
17842 bitmask &= ~ bit;
17843 switch (bit)
17844 {
17845 case GNU_PROPERTY_X86_FEATURE_2_X86:
17846 printf ("x86");
17847 break;
17848 case GNU_PROPERTY_X86_FEATURE_2_X87:
17849 printf ("x87");
17850 break;
17851 case GNU_PROPERTY_X86_FEATURE_2_MMX:
17852 printf ("MMX");
17853 break;
17854 case GNU_PROPERTY_X86_FEATURE_2_XMM:
17855 printf ("XMM");
17856 break;
17857 case GNU_PROPERTY_X86_FEATURE_2_YMM:
17858 printf ("YMM");
17859 break;
17860 case GNU_PROPERTY_X86_FEATURE_2_ZMM:
17861 printf ("ZMM");
17862 break;
17863 case GNU_PROPERTY_X86_FEATURE_2_FXSR:
17864 printf ("FXSR");
17865 break;
17866 case GNU_PROPERTY_X86_FEATURE_2_XSAVE:
17867 printf ("XSAVE");
17868 break;
17869 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT:
17870 printf ("XSAVEOPT");
17871 break;
17872 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC:
17873 printf ("XSAVEC");
17874 break;
17875 default:
17876 printf (_("<unknown: %x>"), bit);
17877 break;
17878 }
17879 if (bitmask)
17880 printf (", ");
17881 }
17882 }
17883
17884 static void
17885 decode_aarch64_feature_1_and (unsigned int bitmask)
17886 {
17887 while (bitmask)
17888 {
17889 unsigned int bit = bitmask & (- bitmask);
17890
17891 bitmask &= ~ bit;
17892 switch (bit)
17893 {
17894 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI:
17895 printf ("BTI");
17896 break;
17897
17898 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC:
17899 printf ("PAC");
17900 break;
17901
17902 default:
17903 printf (_("<unknown: %x>"), bit);
17904 break;
17905 }
17906 if (bitmask)
17907 printf (", ");
17908 }
17909 }
17910
17911 static void
17912 print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
17913 {
17914 unsigned char * ptr = (unsigned char *) pnote->descdata;
17915 unsigned char * ptr_end = ptr + pnote->descsz;
17916 unsigned int size = is_32bit_elf ? 4 : 8;
17917
17918 printf (_(" Properties: "));
17919
17920 if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
17921 {
17922 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
17923 return;
17924 }
17925
17926 while (ptr < ptr_end)
17927 {
17928 unsigned int j;
17929 unsigned int type;
17930 unsigned int datasz;
17931
17932 if ((size_t) (ptr_end - ptr) < 8)
17933 {
17934 printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
17935 break;
17936 }
17937
17938 type = byte_get (ptr, 4);
17939 datasz = byte_get (ptr + 4, 4);
17940
17941 ptr += 8;
17942
17943 if (datasz > (size_t) (ptr_end - ptr))
17944 {
17945 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
17946 type, datasz);
17947 break;
17948 }
17949
17950 if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
17951 {
17952 if (filedata->file_header.e_machine == EM_X86_64
17953 || filedata->file_header.e_machine == EM_IAMCU
17954 || filedata->file_header.e_machine == EM_386)
17955 {
17956 unsigned int bitmask;
17957
17958 if (datasz == 4)
17959 bitmask = byte_get (ptr, 4);
17960 else
17961 bitmask = 0;
17962
17963 switch (type)
17964 {
17965 case GNU_PROPERTY_X86_ISA_1_USED:
17966 if (datasz != 4)
17967 printf (_("x86 ISA used: <corrupt length: %#x> "),
17968 datasz);
17969 else
17970 {
17971 printf ("x86 ISA used: ");
17972 decode_x86_isa (bitmask);
17973 }
17974 goto next;
17975
17976 case GNU_PROPERTY_X86_ISA_1_NEEDED:
17977 if (datasz != 4)
17978 printf (_("x86 ISA needed: <corrupt length: %#x> "),
17979 datasz);
17980 else
17981 {
17982 printf ("x86 ISA needed: ");
17983 decode_x86_isa (bitmask);
17984 }
17985 goto next;
17986
17987 case GNU_PROPERTY_X86_FEATURE_1_AND:
17988 if (datasz != 4)
17989 printf (_("x86 feature: <corrupt length: %#x> "),
17990 datasz);
17991 else
17992 {
17993 printf ("x86 feature: ");
17994 decode_x86_feature_1 (bitmask);
17995 }
17996 goto next;
17997
17998 case GNU_PROPERTY_X86_FEATURE_2_USED:
17999 if (datasz != 4)
18000 printf (_("x86 feature used: <corrupt length: %#x> "),
18001 datasz);
18002 else
18003 {
18004 printf ("x86 feature used: ");
18005 decode_x86_feature_2 (bitmask);
18006 }
18007 goto next;
18008
18009 case GNU_PROPERTY_X86_FEATURE_2_NEEDED:
18010 if (datasz != 4)
18011 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz);
18012 else
18013 {
18014 printf ("x86 feature needed: ");
18015 decode_x86_feature_2 (bitmask);
18016 }
18017 goto next;
18018
18019 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
18020 if (datasz != 4)
18021 printf (_("x86 ISA used: <corrupt length: %#x> "),
18022 datasz);
18023 else
18024 {
18025 printf ("x86 ISA used: ");
18026 decode_x86_compat_isa (bitmask);
18027 }
18028 goto next;
18029
18030 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
18031 if (datasz != 4)
18032 printf (_("x86 ISA needed: <corrupt length: %#x> "),
18033 datasz);
18034 else
18035 {
18036 printf ("x86 ISA needed: ");
18037 decode_x86_compat_isa (bitmask);
18038 }
18039 goto next;
18040
18041 default:
18042 break;
18043 }
18044 }
18045 else if (filedata->file_header.e_machine == EM_AARCH64)
18046 {
18047 if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
18048 {
18049 printf ("AArch64 feature: ");
18050 if (datasz != 4)
18051 printf (_("<corrupt length: %#x> "), datasz);
18052 else
18053 decode_aarch64_feature_1_and (byte_get (ptr, 4));
18054 goto next;
18055 }
18056 }
18057 }
18058 else
18059 {
18060 switch (type)
18061 {
18062 case GNU_PROPERTY_STACK_SIZE:
18063 printf (_("stack size: "));
18064 if (datasz != size)
18065 printf (_("<corrupt length: %#x> "), datasz);
18066 else
18067 printf ("%#lx", (unsigned long) byte_get (ptr, size));
18068 goto next;
18069
18070 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
18071 printf ("no copy on protected ");
18072 if (datasz)
18073 printf (_("<corrupt length: %#x> "), datasz);
18074 goto next;
18075
18076 default:
18077 break;
18078 }
18079 }
18080
18081 if (type < GNU_PROPERTY_LOPROC)
18082 printf (_("<unknown type %#x data: "), type);
18083 else if (type < GNU_PROPERTY_LOUSER)
18084 printf (_("<procesor-specific type %#x data: "), type);
18085 else
18086 printf (_("<application-specific type %#x data: "), type);
18087 for (j = 0; j < datasz; ++j)
18088 printf ("%02x ", ptr[j] & 0xff);
18089 printf (">");
18090
18091 next:
18092 ptr += ((datasz + (size - 1)) & ~ (size - 1));
18093 if (ptr == ptr_end)
18094 break;
18095
18096 if (do_wide)
18097 printf (", ");
18098 else
18099 printf ("\n\t");
18100 }
18101
18102 printf ("\n");
18103 }
18104
18105 static bfd_boolean
18106 print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote)
18107 {
18108 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
18109 switch (pnote->type)
18110 {
18111 case NT_GNU_BUILD_ID:
18112 {
18113 unsigned long i;
18114
18115 printf (_(" Build ID: "));
18116 for (i = 0; i < pnote->descsz; ++i)
18117 printf ("%02x", pnote->descdata[i] & 0xff);
18118 printf ("\n");
18119 }
18120 break;
18121
18122 case NT_GNU_ABI_TAG:
18123 {
18124 unsigned long os, major, minor, subminor;
18125 const char *osname;
18126
18127 /* PR 17531: file: 030-599401-0.004. */
18128 if (pnote->descsz < 16)
18129 {
18130 printf (_(" <corrupt GNU_ABI_TAG>\n"));
18131 break;
18132 }
18133
18134 os = byte_get ((unsigned char *) pnote->descdata, 4);
18135 major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
18136 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
18137 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
18138
18139 switch (os)
18140 {
18141 case GNU_ABI_TAG_LINUX:
18142 osname = "Linux";
18143 break;
18144 case GNU_ABI_TAG_HURD:
18145 osname = "Hurd";
18146 break;
18147 case GNU_ABI_TAG_SOLARIS:
18148 osname = "Solaris";
18149 break;
18150 case GNU_ABI_TAG_FREEBSD:
18151 osname = "FreeBSD";
18152 break;
18153 case GNU_ABI_TAG_NETBSD:
18154 osname = "NetBSD";
18155 break;
18156 case GNU_ABI_TAG_SYLLABLE:
18157 osname = "Syllable";
18158 break;
18159 case GNU_ABI_TAG_NACL:
18160 osname = "NaCl";
18161 break;
18162 default:
18163 osname = "Unknown";
18164 break;
18165 }
18166
18167 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
18168 major, minor, subminor);
18169 }
18170 break;
18171
18172 case NT_GNU_GOLD_VERSION:
18173 {
18174 unsigned long i;
18175
18176 printf (_(" Version: "));
18177 for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
18178 printf ("%c", pnote->descdata[i]);
18179 printf ("\n");
18180 }
18181 break;
18182
18183 case NT_GNU_HWCAP:
18184 {
18185 unsigned long num_entries, mask;
18186
18187 /* Hardware capabilities information. Word 0 is the number of entries.
18188 Word 1 is a bitmask of enabled entries. The rest of the descriptor
18189 is a series of entries, where each entry is a single byte followed
18190 by a nul terminated string. The byte gives the bit number to test
18191 if enabled in the bitmask. */
18192 printf (_(" Hardware Capabilities: "));
18193 if (pnote->descsz < 8)
18194 {
18195 error (_("<corrupt GNU_HWCAP>\n"));
18196 return FALSE;
18197 }
18198 num_entries = byte_get ((unsigned char *) pnote->descdata, 4);
18199 mask = byte_get ((unsigned char *) pnote->descdata + 4, 4);
18200 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask);
18201 /* FIXME: Add code to display the entries... */
18202 }
18203 break;
18204
18205 case NT_GNU_PROPERTY_TYPE_0:
18206 print_gnu_property_note (filedata, pnote);
18207 break;
18208
18209 default:
18210 /* Handle unrecognised types. An error message should have already been
18211 created by get_gnu_elf_note_type(), so all that we need to do is to
18212 display the data. */
18213 {
18214 unsigned long i;
18215
18216 printf (_(" Description data: "));
18217 for (i = 0; i < pnote->descsz; ++i)
18218 printf ("%02x ", pnote->descdata[i] & 0xff);
18219 printf ("\n");
18220 }
18221 break;
18222 }
18223
18224 return TRUE;
18225 }
18226
18227 static const char *
18228 get_v850_elf_note_type (enum v850_notes n_type)
18229 {
18230 static char buff[64];
18231
18232 switch (n_type)
18233 {
18234 case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects");
18235 case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double");
18236 case V850_NOTE_FPU_INFO: return _("Type of FPU support needed");
18237 case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions");
18238 case V850_NOTE_CACHE_INFO: return _("Use of cache");
18239 case V850_NOTE_MMU_INFO: return _("Use of MMU");
18240 default:
18241 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
18242 return buff;
18243 }
18244 }
18245
18246 static bfd_boolean
18247 print_v850_note (Elf_Internal_Note * pnote)
18248 {
18249 unsigned int val;
18250
18251 if (pnote->descsz != 4)
18252 return FALSE;
18253
18254 val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
18255
18256 if (val == 0)
18257 {
18258 printf (_("not set\n"));
18259 return TRUE;
18260 }
18261
18262 switch (pnote->type)
18263 {
18264 case V850_NOTE_ALIGNMENT:
18265 switch (val)
18266 {
18267 case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE;
18268 case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE;
18269 }
18270 break;
18271
18272 case V850_NOTE_DATA_SIZE:
18273 switch (val)
18274 {
18275 case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE;
18276 case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE;
18277 }
18278 break;
18279
18280 case V850_NOTE_FPU_INFO:
18281 switch (val)
18282 {
18283 case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE;
18284 case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE;
18285 }
18286 break;
18287
18288 case V850_NOTE_MMU_INFO:
18289 case V850_NOTE_CACHE_INFO:
18290 case V850_NOTE_SIMD_INFO:
18291 if (val == EF_RH850_SIMD)
18292 {
18293 printf (_("yes\n"));
18294 return TRUE;
18295 }
18296 break;
18297
18298 default:
18299 /* An 'unknown note type' message will already have been displayed. */
18300 break;
18301 }
18302
18303 printf (_("unknown value: %x\n"), val);
18304 return FALSE;
18305 }
18306
18307 static bfd_boolean
18308 process_netbsd_elf_note (Elf_Internal_Note * pnote)
18309 {
18310 unsigned int version;
18311
18312 switch (pnote->type)
18313 {
18314 case NT_NETBSD_IDENT:
18315 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
18316 if ((version / 10000) % 100)
18317 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
18318 version, version / 100000000, (version / 1000000) % 100,
18319 (version / 10000) % 100 > 26 ? "Z" : "",
18320 'A' + (version / 10000) % 26);
18321 else
18322 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
18323 version, version / 100000000, (version / 1000000) % 100,
18324 (version / 100) % 100);
18325 return TRUE;
18326
18327 case NT_NETBSD_MARCH:
18328 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
18329 pnote->descdata);
18330 return TRUE;
18331
18332 #ifdef NT_NETBSD_PAX
18333 case NT_NETBSD_PAX:
18334 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
18335 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz,
18336 ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""),
18337 ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""),
18338 ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""),
18339 ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""),
18340 ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""),
18341 ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : ""));
18342 return TRUE;
18343 #endif
18344
18345 default:
18346 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
18347 pnote->type);
18348 return FALSE;
18349 }
18350 }
18351
18352 static const char *
18353 get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
18354 {
18355 switch (e_type)
18356 {
18357 case NT_FREEBSD_THRMISC:
18358 return _("NT_THRMISC (thrmisc structure)");
18359 case NT_FREEBSD_PROCSTAT_PROC:
18360 return _("NT_PROCSTAT_PROC (proc data)");
18361 case NT_FREEBSD_PROCSTAT_FILES:
18362 return _("NT_PROCSTAT_FILES (files data)");
18363 case NT_FREEBSD_PROCSTAT_VMMAP:
18364 return _("NT_PROCSTAT_VMMAP (vmmap data)");
18365 case NT_FREEBSD_PROCSTAT_GROUPS:
18366 return _("NT_PROCSTAT_GROUPS (groups data)");
18367 case NT_FREEBSD_PROCSTAT_UMASK:
18368 return _("NT_PROCSTAT_UMASK (umask data)");
18369 case NT_FREEBSD_PROCSTAT_RLIMIT:
18370 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
18371 case NT_FREEBSD_PROCSTAT_OSREL:
18372 return _("NT_PROCSTAT_OSREL (osreldate data)");
18373 case NT_FREEBSD_PROCSTAT_PSSTRINGS:
18374 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
18375 case NT_FREEBSD_PROCSTAT_AUXV:
18376 return _("NT_PROCSTAT_AUXV (auxv data)");
18377 case NT_FREEBSD_PTLWPINFO:
18378 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
18379 }
18380 return get_note_type (filedata, e_type);
18381 }
18382
18383 static const char *
18384 get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
18385 {
18386 static char buff[64];
18387
18388 switch (e_type)
18389 {
18390 case NT_NETBSDCORE_PROCINFO:
18391 /* NetBSD core "procinfo" structure. */
18392 return _("NetBSD procinfo structure");
18393
18394 #ifdef NT_NETBSDCORE_AUXV
18395 case NT_NETBSDCORE_AUXV:
18396 return _("NetBSD ELF auxiliary vector data");
18397 #endif
18398
18399 default:
18400 /* As of Jan 2002 there are no other machine-independent notes
18401 defined for NetBSD core files. If the note type is less
18402 than the start of the machine-dependent note types, we don't
18403 understand it. */
18404
18405 if (e_type < NT_NETBSDCORE_FIRSTMACH)
18406 {
18407 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18408 return buff;
18409 }
18410 break;
18411 }
18412
18413 switch (filedata->file_header.e_machine)
18414 {
18415 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
18416 and PT_GETFPREGS == mach+2. */
18417
18418 case EM_OLD_ALPHA:
18419 case EM_ALPHA:
18420 case EM_SPARC:
18421 case EM_SPARC32PLUS:
18422 case EM_SPARCV9:
18423 switch (e_type)
18424 {
18425 case NT_NETBSDCORE_FIRSTMACH + 0:
18426 return _("PT_GETREGS (reg structure)");
18427 case NT_NETBSDCORE_FIRSTMACH + 2:
18428 return _("PT_GETFPREGS (fpreg structure)");
18429 default:
18430 break;
18431 }
18432 break;
18433
18434 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
18435 There's also old PT___GETREGS40 == mach + 1 for old reg
18436 structure which lacks GBR. */
18437 case EM_SH:
18438 switch (e_type)
18439 {
18440 case NT_NETBSDCORE_FIRSTMACH + 1:
18441 return _("PT___GETREGS40 (old reg structure)");
18442 case NT_NETBSDCORE_FIRSTMACH + 3:
18443 return _("PT_GETREGS (reg structure)");
18444 case NT_NETBSDCORE_FIRSTMACH + 5:
18445 return _("PT_GETFPREGS (fpreg structure)");
18446 default:
18447 break;
18448 }
18449 break;
18450
18451 /* On all other arch's, PT_GETREGS == mach+1 and
18452 PT_GETFPREGS == mach+3. */
18453 default:
18454 switch (e_type)
18455 {
18456 case NT_NETBSDCORE_FIRSTMACH + 1:
18457 return _("PT_GETREGS (reg structure)");
18458 case NT_NETBSDCORE_FIRSTMACH + 3:
18459 return _("PT_GETFPREGS (fpreg structure)");
18460 default:
18461 break;
18462 }
18463 }
18464
18465 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
18466 e_type - NT_NETBSDCORE_FIRSTMACH);
18467 return buff;
18468 }
18469
18470 static const char *
18471 get_stapsdt_note_type (unsigned e_type)
18472 {
18473 static char buff[64];
18474
18475 switch (e_type)
18476 {
18477 case NT_STAPSDT:
18478 return _("NT_STAPSDT (SystemTap probe descriptors)");
18479
18480 default:
18481 break;
18482 }
18483
18484 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18485 return buff;
18486 }
18487
18488 static bfd_boolean
18489 print_stapsdt_note (Elf_Internal_Note *pnote)
18490 {
18491 size_t len, maxlen;
18492 unsigned long addr_size = is_32bit_elf ? 4 : 8;
18493 char *data = pnote->descdata;
18494 char *data_end = pnote->descdata + pnote->descsz;
18495 bfd_vma pc, base_addr, semaphore;
18496 char *provider, *probe, *arg_fmt;
18497
18498 if (pnote->descsz < (addr_size * 3))
18499 goto stapdt_note_too_small;
18500
18501 pc = byte_get ((unsigned char *) data, addr_size);
18502 data += addr_size;
18503
18504 base_addr = byte_get ((unsigned char *) data, addr_size);
18505 data += addr_size;
18506
18507 semaphore = byte_get ((unsigned char *) data, addr_size);
18508 data += addr_size;
18509
18510 if (data >= data_end)
18511 goto stapdt_note_too_small;
18512 maxlen = data_end - data;
18513 len = strnlen (data, maxlen);
18514 if (len < maxlen)
18515 {
18516 provider = data;
18517 data += len + 1;
18518 }
18519 else
18520 goto stapdt_note_too_small;
18521
18522 if (data >= data_end)
18523 goto stapdt_note_too_small;
18524 maxlen = data_end - data;
18525 len = strnlen (data, maxlen);
18526 if (len < maxlen)
18527 {
18528 probe = data;
18529 data += len + 1;
18530 }
18531 else
18532 goto stapdt_note_too_small;
18533
18534 if (data >= data_end)
18535 goto stapdt_note_too_small;
18536 maxlen = data_end - data;
18537 len = strnlen (data, maxlen);
18538 if (len < maxlen)
18539 {
18540 arg_fmt = data;
18541 data += len + 1;
18542 }
18543 else
18544 goto stapdt_note_too_small;
18545
18546 printf (_(" Provider: %s\n"), provider);
18547 printf (_(" Name: %s\n"), probe);
18548 printf (_(" Location: "));
18549 print_vma (pc, FULL_HEX);
18550 printf (_(", Base: "));
18551 print_vma (base_addr, FULL_HEX);
18552 printf (_(", Semaphore: "));
18553 print_vma (semaphore, FULL_HEX);
18554 printf ("\n");
18555 printf (_(" Arguments: %s\n"), arg_fmt);
18556
18557 return data == data_end;
18558
18559 stapdt_note_too_small:
18560 printf (_(" <corrupt - note is too small>\n"));
18561 error (_("corrupt stapdt note - the data size is too small\n"));
18562 return FALSE;
18563 }
18564
18565 static const char *
18566 get_ia64_vms_note_type (unsigned e_type)
18567 {
18568 static char buff[64];
18569
18570 switch (e_type)
18571 {
18572 case NT_VMS_MHD:
18573 return _("NT_VMS_MHD (module header)");
18574 case NT_VMS_LNM:
18575 return _("NT_VMS_LNM (language name)");
18576 case NT_VMS_SRC:
18577 return _("NT_VMS_SRC (source files)");
18578 case NT_VMS_TITLE:
18579 return "NT_VMS_TITLE";
18580 case NT_VMS_EIDC:
18581 return _("NT_VMS_EIDC (consistency check)");
18582 case NT_VMS_FPMODE:
18583 return _("NT_VMS_FPMODE (FP mode)");
18584 case NT_VMS_LINKTIME:
18585 return "NT_VMS_LINKTIME";
18586 case NT_VMS_IMGNAM:
18587 return _("NT_VMS_IMGNAM (image name)");
18588 case NT_VMS_IMGID:
18589 return _("NT_VMS_IMGID (image id)");
18590 case NT_VMS_LINKID:
18591 return _("NT_VMS_LINKID (link id)");
18592 case NT_VMS_IMGBID:
18593 return _("NT_VMS_IMGBID (build id)");
18594 case NT_VMS_GSTNAM:
18595 return _("NT_VMS_GSTNAM (sym table name)");
18596 case NT_VMS_ORIG_DYN:
18597 return "NT_VMS_ORIG_DYN";
18598 case NT_VMS_PATCHTIME:
18599 return "NT_VMS_PATCHTIME";
18600 default:
18601 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
18602 return buff;
18603 }
18604 }
18605
18606 static bfd_boolean
18607 print_ia64_vms_note (Elf_Internal_Note * pnote)
18608 {
18609 int maxlen = pnote->descsz;
18610
18611 if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz)
18612 goto desc_size_fail;
18613
18614 switch (pnote->type)
18615 {
18616 case NT_VMS_MHD:
18617 if (maxlen <= 36)
18618 goto desc_size_fail;
18619
18620 int l = (int) strnlen (pnote->descdata + 34, maxlen - 34);
18621
18622 printf (_(" Creation date : %.17s\n"), pnote->descdata);
18623 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
18624 if (l + 34 < maxlen)
18625 {
18626 printf (_(" Module name : %s\n"), pnote->descdata + 34);
18627 if (l + 35 < maxlen)
18628 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
18629 else
18630 printf (_(" Module version : <missing>\n"));
18631 }
18632 else
18633 {
18634 printf (_(" Module name : <missing>\n"));
18635 printf (_(" Module version : <missing>\n"));
18636 }
18637 break;
18638
18639 case NT_VMS_LNM:
18640 printf (_(" Language: %.*s\n"), maxlen, pnote->descdata);
18641 break;
18642
18643 #ifdef BFD64
18644 case NT_VMS_FPMODE:
18645 printf (_(" Floating Point mode: "));
18646 if (maxlen < 8)
18647 goto desc_size_fail;
18648 /* FIXME: Generate an error if descsz > 8 ? */
18649
18650 printf ("0x%016" BFD_VMA_FMT "x\n",
18651 (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
18652 break;
18653
18654 case NT_VMS_LINKTIME:
18655 printf (_(" Link time: "));
18656 if (maxlen < 8)
18657 goto desc_size_fail;
18658 /* FIXME: Generate an error if descsz > 8 ? */
18659
18660 print_vms_time
18661 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
18662 printf ("\n");
18663 break;
18664
18665 case NT_VMS_PATCHTIME:
18666 printf (_(" Patch time: "));
18667 if (maxlen < 8)
18668 goto desc_size_fail;
18669 /* FIXME: Generate an error if descsz > 8 ? */
18670
18671 print_vms_time
18672 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
18673 printf ("\n");
18674 break;
18675
18676 case NT_VMS_ORIG_DYN:
18677 if (maxlen < 34)
18678 goto desc_size_fail;
18679
18680 printf (_(" Major id: %u, minor id: %u\n"),
18681 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
18682 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
18683 printf (_(" Last modified : "));
18684 print_vms_time
18685 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
18686 printf (_("\n Link flags : "));
18687 printf ("0x%016" BFD_VMA_FMT "x\n",
18688 (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
18689 printf (_(" Header flags: 0x%08x\n"),
18690 (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
18691 printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32);
18692 break;
18693 #endif
18694
18695 case NT_VMS_IMGNAM:
18696 printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata);
18697 break;
18698
18699 case NT_VMS_GSTNAM:
18700 printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata);
18701 break;
18702
18703 case NT_VMS_IMGID:
18704 printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata);
18705 break;
18706
18707 case NT_VMS_LINKID:
18708 printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata);
18709 break;
18710
18711 default:
18712 return FALSE;
18713 }
18714
18715 return TRUE;
18716
18717 desc_size_fail:
18718 printf (_(" <corrupt - data size is too small>\n"));
18719 error (_("corrupt IA64 note: data size is too small\n"));
18720 return FALSE;
18721 }
18722
18723 /* Find the symbol associated with a build attribute that is attached
18724 to address OFFSET. If PNAME is non-NULL then store the name of
18725 the symbol (if found) in the provided pointer, Returns NULL if a
18726 symbol could not be found. */
18727
18728 static Elf_Internal_Sym *
18729 get_symbol_for_build_attribute (Filedata * filedata,
18730 unsigned long offset,
18731 bfd_boolean is_open_attr,
18732 const char ** pname)
18733 {
18734 static Filedata * saved_filedata = NULL;
18735 static char * strtab;
18736 static unsigned long strtablen;
18737 static Elf_Internal_Sym * symtab;
18738 static unsigned long nsyms;
18739 Elf_Internal_Sym * saved_sym = NULL;
18740 Elf_Internal_Sym * sym;
18741
18742 if (filedata->section_headers != NULL
18743 && (saved_filedata == NULL || filedata != saved_filedata))
18744 {
18745 Elf_Internal_Shdr * symsec;
18746
18747 /* Load the symbol and string sections. */
18748 for (symsec = filedata->section_headers;
18749 symsec < filedata->section_headers + filedata->file_header.e_shnum;
18750 symsec ++)
18751 {
18752 if (symsec->sh_type == SHT_SYMTAB)
18753 {
18754 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
18755
18756 if (symsec->sh_link < filedata->file_header.e_shnum)
18757 {
18758 Elf_Internal_Shdr * strtab_sec = filedata->section_headers + symsec->sh_link;
18759
18760 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
18761 1, strtab_sec->sh_size,
18762 _("string table"));
18763 strtablen = strtab != NULL ? strtab_sec->sh_size : 0;
18764 }
18765 }
18766 }
18767 saved_filedata = filedata;
18768 }
18769
18770 if (symtab == NULL || strtab == NULL)
18771 return NULL;
18772
18773 /* Find a symbol whose value matches offset. */
18774 for (sym = symtab; sym < symtab + nsyms; sym ++)
18775 if (sym->st_value == offset)
18776 {
18777 if (sym->st_name >= strtablen)
18778 /* Huh ? This should not happen. */
18779 continue;
18780
18781 if (strtab[sym->st_name] == 0)
18782 continue;
18783
18784 /* The AArch64 and ARM architectures define mapping symbols
18785 (eg $d, $x, $t) which we want to ignore. */
18786 if (strtab[sym->st_name] == '$'
18787 && strtab[sym->st_name + 1] != 0
18788 && strtab[sym->st_name + 2] == 0)
18789 continue;
18790
18791 if (is_open_attr)
18792 {
18793 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
18794 and FILE or OBJECT symbols over NOTYPE symbols. We skip
18795 FUNC symbols entirely. */
18796 switch (ELF_ST_TYPE (sym->st_info))
18797 {
18798 case STT_OBJECT:
18799 case STT_FILE:
18800 saved_sym = sym;
18801 if (sym->st_size)
18802 {
18803 /* If the symbol has a size associated
18804 with it then we can stop searching. */
18805 sym = symtab + nsyms;
18806 }
18807 continue;
18808
18809 case STT_FUNC:
18810 /* Ignore function symbols. */
18811 continue;
18812
18813 default:
18814 break;
18815 }
18816
18817 switch (ELF_ST_BIND (sym->st_info))
18818 {
18819 case STB_GLOBAL:
18820 if (saved_sym == NULL
18821 || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT)
18822 saved_sym = sym;
18823 break;
18824
18825 case STB_LOCAL:
18826 if (saved_sym == NULL)
18827 saved_sym = sym;
18828 break;
18829
18830 default:
18831 break;
18832 }
18833 }
18834 else
18835 {
18836 if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
18837 continue;
18838
18839 saved_sym = sym;
18840 break;
18841 }
18842 }
18843
18844 if (saved_sym && pname)
18845 * pname = strtab + saved_sym->st_name;
18846
18847 return saved_sym;
18848 }
18849
18850 /* Returns true iff addr1 and addr2 are in the same section. */
18851
18852 static bfd_boolean
18853 same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2)
18854 {
18855 Elf_Internal_Shdr * a1;
18856 Elf_Internal_Shdr * a2;
18857
18858 a1 = find_section_by_address (filedata, addr1);
18859 a2 = find_section_by_address (filedata, addr2);
18860
18861 return a1 == a2 && a1 != NULL;
18862 }
18863
18864 static bfd_boolean
18865 print_gnu_build_attribute_description (Elf_Internal_Note * pnote,
18866 Filedata * filedata)
18867 {
18868 static unsigned long global_offset = 0;
18869 static unsigned long global_end = 0;
18870 static unsigned long func_offset = 0;
18871 static unsigned long func_end = 0;
18872
18873 Elf_Internal_Sym * sym;
18874 const char * name;
18875 unsigned long start;
18876 unsigned long end;
18877 bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
18878
18879 switch (pnote->descsz)
18880 {
18881 case 0:
18882 /* A zero-length description means that the range of
18883 the previous note of the same type should be used. */
18884 if (is_open_attr)
18885 {
18886 if (global_end > global_offset)
18887 printf (_(" Applies to region from %#lx to %#lx\n"),
18888 global_offset, global_end);
18889 else
18890 printf (_(" Applies to region from %#lx\n"), global_offset);
18891 }
18892 else
18893 {
18894 if (func_end > func_offset)
18895 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end);
18896 else
18897 printf (_(" Applies to region from %#lx\n"), func_offset);
18898 }
18899 return TRUE;
18900
18901 case 4:
18902 start = byte_get ((unsigned char *) pnote->descdata, 4);
18903 end = 0;
18904 break;
18905
18906 case 8:
18907 if (is_32bit_elf)
18908 {
18909 /* FIXME: We should check that version 3+ notes are being used here... */
18910 start = byte_get ((unsigned char *) pnote->descdata, 4);
18911 end = byte_get ((unsigned char *) pnote->descdata + 4, 4);
18912 }
18913 else
18914 {
18915 start = byte_get ((unsigned char *) pnote->descdata, 8);
18916 end = 0;
18917 }
18918 break;
18919
18920 case 16:
18921 start = byte_get ((unsigned char *) pnote->descdata, 8);
18922 end = byte_get ((unsigned char *) pnote->descdata + 8, 8);
18923 break;
18924
18925 default:
18926 error (_(" <invalid description size: %lx>\n"), pnote->descsz);
18927 printf (_(" <invalid descsz>"));
18928 return FALSE;
18929 }
18930
18931 name = NULL;
18932 sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name);
18933 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
18934 in order to avoid them being confused with the start address of the
18935 first function in the file... */
18936 if (sym == NULL && is_open_attr)
18937 sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr,
18938 & name);
18939
18940 if (end == 0 && sym != NULL && sym->st_size > 0)
18941 end = start + sym->st_size;
18942
18943 if (is_open_attr)
18944 {
18945 /* FIXME: Need to properly allow for section alignment.
18946 16 is just the alignment used on x86_64. */
18947 if (global_end > 0
18948 && start > BFD_ALIGN (global_end, 16)
18949 /* Build notes are not guaranteed to be organised in order of
18950 increasing address, but we should find the all of the notes
18951 for one section in the same place. */
18952 && same_section (filedata, start, global_end))
18953 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
18954 global_end + 1, start - 1);
18955
18956 printf (_(" Applies to region from %#lx"), start);
18957 global_offset = start;
18958
18959 if (end)
18960 {
18961 printf (_(" to %#lx"), end);
18962 global_end = end;
18963 }
18964 }
18965 else
18966 {
18967 printf (_(" Applies to region from %#lx"), start);
18968 func_offset = start;
18969
18970 if (end)
18971 {
18972 printf (_(" to %#lx"), end);
18973 func_end = end;
18974 }
18975 }
18976
18977 if (sym && name)
18978 printf (_(" (%s)"), name);
18979
18980 printf ("\n");
18981 return TRUE;
18982 }
18983
18984 static bfd_boolean
18985 print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
18986 {
18987 static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 };
18988 static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 };
18989 static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 };
18990 char name_type;
18991 char name_attribute;
18992 const char * expected_types;
18993 const char * name = pnote->namedata;
18994 const char * text;
18995 signed int left;
18996
18997 if (name == NULL || pnote->namesz < 2)
18998 {
18999 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
19000 print_symbol (-20, _(" <corrupt name>"));
19001 return FALSE;
19002 }
19003
19004 if (do_wide)
19005 left = 28;
19006 else
19007 left = 20;
19008
19009 /* Version 2 of the spec adds a "GA" prefix to the name field. */
19010 if (name[0] == 'G' && name[1] == 'A')
19011 {
19012 if (pnote->namesz < 4)
19013 {
19014 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
19015 print_symbol (-20, _(" <corrupt name>"));
19016 return FALSE;
19017 }
19018
19019 printf ("GA");
19020 name += 2;
19021 left -= 2;
19022 }
19023
19024 switch ((name_type = * name))
19025 {
19026 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
19027 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
19028 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
19029 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
19030 printf ("%c", * name);
19031 left --;
19032 break;
19033 default:
19034 error (_("unrecognised attribute type in name field: %d\n"), name_type);
19035 print_symbol (-20, _("<unknown name type>"));
19036 return FALSE;
19037 }
19038
19039 ++ name;
19040 text = NULL;
19041
19042 switch ((name_attribute = * name))
19043 {
19044 case GNU_BUILD_ATTRIBUTE_VERSION:
19045 text = _("<version>");
19046 expected_types = string_expected;
19047 ++ name;
19048 break;
19049 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
19050 text = _("<stack prot>");
19051 expected_types = "!+*";
19052 ++ name;
19053 break;
19054 case GNU_BUILD_ATTRIBUTE_RELRO:
19055 text = _("<relro>");
19056 expected_types = bool_expected;
19057 ++ name;
19058 break;
19059 case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
19060 text = _("<stack size>");
19061 expected_types = number_expected;
19062 ++ name;
19063 break;
19064 case GNU_BUILD_ATTRIBUTE_TOOL:
19065 text = _("<tool>");
19066 expected_types = string_expected;
19067 ++ name;
19068 break;
19069 case GNU_BUILD_ATTRIBUTE_ABI:
19070 text = _("<ABI>");
19071 expected_types = "$*";
19072 ++ name;
19073 break;
19074 case GNU_BUILD_ATTRIBUTE_PIC:
19075 text = _("<PIC>");
19076 expected_types = number_expected;
19077 ++ name;
19078 break;
19079 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
19080 text = _("<short enum>");
19081 expected_types = bool_expected;
19082 ++ name;
19083 break;
19084 default:
19085 if (ISPRINT (* name))
19086 {
19087 int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1;
19088
19089 if (len > left && ! do_wide)
19090 len = left;
19091 printf ("%.*s:", len, name);
19092 left -= len;
19093 name += len;
19094 }
19095 else
19096 {
19097 static char tmpbuf [128];
19098
19099 error (_("unrecognised byte in name field: %d\n"), * name);
19100 sprintf (tmpbuf, _("<unknown:_%d>"), * name);
19101 text = tmpbuf;
19102 name ++;
19103 }
19104 expected_types = "*$!+";
19105 break;
19106 }
19107
19108 if (text)
19109 left -= printf ("%s", text);
19110
19111 if (strchr (expected_types, name_type) == NULL)
19112 warn (_("attribute does not have an expected type (%c)\n"), name_type);
19113
19114 if ((unsigned long)(name - pnote->namedata) > pnote->namesz)
19115 {
19116 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
19117 (unsigned long) pnote->namesz,
19118 (long) (name - pnote->namedata));
19119 return FALSE;
19120 }
19121
19122 if (left < 1 && ! do_wide)
19123 return TRUE;
19124
19125 switch (name_type)
19126 {
19127 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
19128 {
19129 unsigned int bytes;
19130 unsigned long long val = 0;
19131 unsigned int shift = 0;
19132 char * decoded = NULL;
19133
19134 bytes = pnote->namesz - (name - pnote->namedata);
19135 if (bytes > 0)
19136 /* The -1 is because the name field is always 0 terminated, and we
19137 want to be able to ensure that the shift in the while loop below
19138 will not overflow. */
19139 -- bytes;
19140
19141 if (bytes > sizeof (val))
19142 {
19143 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
19144 bytes);
19145 bytes = sizeof (val);
19146 }
19147 /* We do not bother to warn if bytes == 0 as this can
19148 happen with some early versions of the gcc plugin. */
19149
19150 while (bytes --)
19151 {
19152 unsigned long byte = (* name ++) & 0xff;
19153
19154 val |= byte << shift;
19155 shift += 8;
19156 }
19157
19158 switch (name_attribute)
19159 {
19160 case GNU_BUILD_ATTRIBUTE_PIC:
19161 switch (val)
19162 {
19163 case 0: decoded = "static"; break;
19164 case 1: decoded = "pic"; break;
19165 case 2: decoded = "PIC"; break;
19166 case 3: decoded = "pie"; break;
19167 case 4: decoded = "PIE"; break;
19168 default: break;
19169 }
19170 break;
19171 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
19172 switch (val)
19173 {
19174 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
19175 case 0: decoded = "off"; break;
19176 case 1: decoded = "on"; break;
19177 case 2: decoded = "all"; break;
19178 case 3: decoded = "strong"; break;
19179 case 4: decoded = "explicit"; break;
19180 default: break;
19181 }
19182 break;
19183 default:
19184 break;
19185 }
19186
19187 if (decoded != NULL)
19188 {
19189 print_symbol (-left, decoded);
19190 left = 0;
19191 }
19192 else if (val == 0)
19193 {
19194 printf ("0x0");
19195 left -= 3;
19196 }
19197 else
19198 {
19199 if (do_wide)
19200 left -= printf ("0x%llx", val);
19201 else
19202 left -= printf ("0x%-.*llx", left, val);
19203 }
19204 }
19205 break;
19206 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
19207 left -= print_symbol (- left, name);
19208 break;
19209 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
19210 left -= print_symbol (- left, "true");
19211 break;
19212 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
19213 left -= print_symbol (- left, "false");
19214 break;
19215 }
19216
19217 if (do_wide && left > 0)
19218 printf ("%-*s", left, " ");
19219
19220 return TRUE;
19221 }
19222
19223 /* Note that by the ELF standard, the name field is already null byte
19224 terminated, and namesz includes the terminating null byte.
19225 I.E. the value of namesz for the name "FSF" is 4.
19226
19227 If the value of namesz is zero, there is no name present. */
19228
19229 static bfd_boolean
19230 process_note (Elf_Internal_Note * pnote,
19231 Filedata * filedata)
19232 {
19233 const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
19234 const char * nt;
19235
19236 if (pnote->namesz == 0)
19237 /* If there is no note name, then use the default set of
19238 note type strings. */
19239 nt = get_note_type (filedata, pnote->type);
19240
19241 else if (const_strneq (pnote->namedata, "GNU"))
19242 /* GNU-specific object file notes. */
19243 nt = get_gnu_elf_note_type (pnote->type);
19244
19245 else if (const_strneq (pnote->namedata, "AMD")
19246 || const_strneq (pnote->namedata, "AMDGPU"))
19247 /* AMD-specific object file notes. */
19248 nt = get_amd_elf_note_type (pnote->type);
19249
19250 else if (const_strneq (pnote->namedata, "FreeBSD"))
19251 /* FreeBSD-specific core file notes. */
19252 nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
19253
19254 else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
19255 /* NetBSD-specific core file notes. */
19256 nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
19257
19258 else if (const_strneq (pnote->namedata, "NetBSD"))
19259 /* NetBSD-specific core file notes. */
19260 return process_netbsd_elf_note (pnote);
19261
19262 else if (const_strneq (pnote->namedata, "PaX"))
19263 /* NetBSD-specific core file notes. */
19264 return process_netbsd_elf_note (pnote);
19265
19266 else if (strneq (pnote->namedata, "SPU/", 4))
19267 {
19268 /* SPU-specific core file notes. */
19269 nt = pnote->namedata + 4;
19270 name = "SPU";
19271 }
19272
19273 else if (const_strneq (pnote->namedata, "IPF/VMS"))
19274 /* VMS/ia64-specific file notes. */
19275 nt = get_ia64_vms_note_type (pnote->type);
19276
19277 else if (const_strneq (pnote->namedata, "stapsdt"))
19278 nt = get_stapsdt_note_type (pnote->type);
19279
19280 else
19281 /* Don't recognize this note name; just use the default set of
19282 note type strings. */
19283 nt = get_note_type (filedata, pnote->type);
19284
19285 printf (" ");
19286
19287 if (((const_strneq (pnote->namedata, "GA")
19288 && strchr ("*$!+", pnote->namedata[2]) != NULL)
19289 || strchr ("*$!+", pnote->namedata[0]) != NULL)
19290 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
19291 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
19292 print_gnu_build_attribute_name (pnote);
19293 else
19294 print_symbol (-20, name);
19295
19296 if (do_wide)
19297 printf (" 0x%08lx\t%s\t", pnote->descsz, nt);
19298 else
19299 printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
19300
19301 if (const_strneq (pnote->namedata, "IPF/VMS"))
19302 return print_ia64_vms_note (pnote);
19303 else if (const_strneq (pnote->namedata, "GNU"))
19304 return print_gnu_note (filedata, pnote);
19305 else if (const_strneq (pnote->namedata, "AMD")
19306 || const_strneq (pnote->namedata, "AMDGPU"))
19307 return print_amd_note (pnote);
19308 else if (const_strneq (pnote->namedata, "stapsdt"))
19309 return print_stapsdt_note (pnote);
19310 else if (const_strneq (pnote->namedata, "CORE"))
19311 return print_core_note (pnote);
19312 else if (((const_strneq (pnote->namedata, "GA")
19313 && strchr ("*$!+", pnote->namedata[2]) != NULL)
19314 || strchr ("*$!+", pnote->namedata[0]) != NULL)
19315 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
19316 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
19317 return print_gnu_build_attribute_description (pnote, filedata);
19318
19319 if (pnote->descsz)
19320 {
19321 unsigned long i;
19322
19323 printf (_(" description data: "));
19324 for (i = 0; i < pnote->descsz; i++)
19325 printf ("%02x ", pnote->descdata[i] & 0xff);
19326 if (!do_wide)
19327 printf ("\n");
19328 }
19329
19330 if (do_wide)
19331 printf ("\n");
19332
19333 return TRUE;
19334 }
19335
19336 static bfd_boolean
19337 process_notes_at (Filedata * filedata,
19338 Elf_Internal_Shdr * section,
19339 bfd_vma offset,
19340 bfd_vma length,
19341 bfd_vma align)
19342 {
19343 Elf_External_Note * pnotes;
19344 Elf_External_Note * external;
19345 char * end;
19346 bfd_boolean res = TRUE;
19347
19348 if (length <= 0)
19349 return FALSE;
19350
19351 if (section)
19352 {
19353 pnotes = (Elf_External_Note *) get_section_contents (section, filedata);
19354 if (pnotes)
19355 {
19356 if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL))
19357 return FALSE;
19358 }
19359 }
19360 else
19361 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
19362 _("notes"));
19363
19364 if (pnotes == NULL)
19365 return FALSE;
19366
19367 external = pnotes;
19368
19369 if (section)
19370 printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (filedata, section));
19371 else
19372 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
19373 (unsigned long) offset, (unsigned long) length);
19374
19375 /* NB: Some note sections may have alignment value of 0 or 1. gABI
19376 specifies that notes should be aligned to 4 bytes in 32-bit
19377 objects and to 8 bytes in 64-bit objects. As a Linux extension,
19378 we also support 4 byte alignment in 64-bit objects. If section
19379 alignment is less than 4, we treate alignment as 4 bytes. */
19380 if (align < 4)
19381 align = 4;
19382 else if (align != 4 && align != 8)
19383 {
19384 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
19385 (long) align);
19386 return FALSE;
19387 }
19388
19389 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
19390
19391 end = (char *) pnotes + length;
19392 while ((char *) external < end)
19393 {
19394 Elf_Internal_Note inote;
19395 size_t min_notesz;
19396 char * next;
19397 char * temp = NULL;
19398 size_t data_remaining = end - (char *) external;
19399
19400 if (!is_ia64_vms (filedata))
19401 {
19402 /* PR binutils/15191
19403 Make sure that there is enough data to read. */
19404 min_notesz = offsetof (Elf_External_Note, name);
19405 if (data_remaining < min_notesz)
19406 {
19407 warn (ngettext ("Corrupt note: only %ld byte remains, "
19408 "not enough for a full note\n",
19409 "Corrupt note: only %ld bytes remain, "
19410 "not enough for a full note\n",
19411 data_remaining),
19412 (long) data_remaining);
19413 break;
19414 }
19415 data_remaining -= min_notesz;
19416
19417 inote.type = BYTE_GET (external->type);
19418 inote.namesz = BYTE_GET (external->namesz);
19419 inote.namedata = external->name;
19420 inote.descsz = BYTE_GET (external->descsz);
19421 inote.descdata = ((char *) external
19422 + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
19423 inote.descpos = offset + (inote.descdata - (char *) pnotes);
19424 next = ((char *) external
19425 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
19426 }
19427 else
19428 {
19429 Elf64_External_VMS_Note *vms_external;
19430
19431 /* PR binutils/15191
19432 Make sure that there is enough data to read. */
19433 min_notesz = offsetof (Elf64_External_VMS_Note, name);
19434 if (data_remaining < min_notesz)
19435 {
19436 warn (ngettext ("Corrupt note: only %ld byte remains, "
19437 "not enough for a full note\n",
19438 "Corrupt note: only %ld bytes remain, "
19439 "not enough for a full note\n",
19440 data_remaining),
19441 (long) data_remaining);
19442 break;
19443 }
19444 data_remaining -= min_notesz;
19445
19446 vms_external = (Elf64_External_VMS_Note *) external;
19447 inote.type = BYTE_GET (vms_external->type);
19448 inote.namesz = BYTE_GET (vms_external->namesz);
19449 inote.namedata = vms_external->name;
19450 inote.descsz = BYTE_GET (vms_external->descsz);
19451 inote.descdata = inote.namedata + align_power (inote.namesz, 3);
19452 inote.descpos = offset + (inote.descdata - (char *) pnotes);
19453 next = inote.descdata + align_power (inote.descsz, 3);
19454 }
19455
19456 /* PR 17531: file: 3443835e. */
19457 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
19458 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
19459 || (size_t) (inote.descdata - inote.namedata) > data_remaining
19460 || (size_t) (next - inote.descdata) < inote.descsz
19461 || ((size_t) (next - inote.descdata)
19462 > data_remaining - (size_t) (inote.descdata - inote.namedata)))
19463 {
19464 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
19465 (unsigned long) ((char *) external - (char *) pnotes));
19466 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
19467 inote.type, inote.namesz, inote.descsz, (int) align);
19468 break;
19469 }
19470
19471 external = (Elf_External_Note *) next;
19472
19473 /* Verify that name is null terminated. It appears that at least
19474 one version of Linux (RedHat 6.0) generates corefiles that don't
19475 comply with the ELF spec by failing to include the null byte in
19476 namesz. */
19477 if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0')
19478 {
19479 if ((size_t) (inote.descdata - inote.namedata) == inote.namesz)
19480 {
19481 temp = (char *) malloc (inote.namesz + 1);
19482 if (temp == NULL)
19483 {
19484 error (_("Out of memory allocating space for inote name\n"));
19485 res = FALSE;
19486 break;
19487 }
19488
19489 memcpy (temp, inote.namedata, inote.namesz);
19490 inote.namedata = temp;
19491 }
19492 inote.namedata[inote.namesz] = 0;
19493 }
19494
19495 if (! process_note (& inote, filedata))
19496 res = FALSE;
19497
19498 if (temp != NULL)
19499 {
19500 free (temp);
19501 temp = NULL;
19502 }
19503 }
19504
19505 free (pnotes);
19506
19507 return res;
19508 }
19509
19510 static bfd_boolean
19511 process_corefile_note_segments (Filedata * filedata)
19512 {
19513 Elf_Internal_Phdr * segment;
19514 unsigned int i;
19515 bfd_boolean res = TRUE;
19516
19517 if (! get_program_headers (filedata))
19518 return TRUE;
19519
19520 for (i = 0, segment = filedata->program_headers;
19521 i < filedata->file_header.e_phnum;
19522 i++, segment++)
19523 {
19524 if (segment->p_type == PT_NOTE)
19525 if (! process_notes_at (filedata, NULL,
19526 (bfd_vma) segment->p_offset,
19527 (bfd_vma) segment->p_filesz,
19528 (bfd_vma) segment->p_align))
19529 res = FALSE;
19530 }
19531
19532 return res;
19533 }
19534
19535 static bfd_boolean
19536 process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length)
19537 {
19538 Elf_External_Note * pnotes;
19539 Elf_External_Note * external;
19540 char * end;
19541 bfd_boolean res = TRUE;
19542
19543 if (length <= 0)
19544 return FALSE;
19545
19546 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
19547 _("v850 notes"));
19548 if (pnotes == NULL)
19549 return FALSE;
19550
19551 external = pnotes;
19552 end = (char*) pnotes + length;
19553
19554 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
19555 (unsigned long) offset, (unsigned long) length);
19556
19557 while ((char *) external + sizeof (Elf_External_Note) < end)
19558 {
19559 Elf_External_Note * next;
19560 Elf_Internal_Note inote;
19561
19562 inote.type = BYTE_GET (external->type);
19563 inote.namesz = BYTE_GET (external->namesz);
19564 inote.namedata = external->name;
19565 inote.descsz = BYTE_GET (external->descsz);
19566 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
19567 inote.descpos = offset + (inote.descdata - (char *) pnotes);
19568
19569 if (inote.descdata < (char *) pnotes || inote.descdata >= end)
19570 {
19571 warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
19572 inote.descdata = inote.namedata;
19573 inote.namesz = 0;
19574 }
19575
19576 next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
19577
19578 if ( ((char *) next > end)
19579 || ((char *) next < (char *) pnotes))
19580 {
19581 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
19582 (unsigned long) ((char *) external - (char *) pnotes));
19583 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19584 inote.type, inote.namesz, inote.descsz);
19585 break;
19586 }
19587
19588 external = next;
19589
19590 /* Prevent out-of-bounds indexing. */
19591 if ( inote.namedata + inote.namesz > end
19592 || inote.namedata + inote.namesz < inote.namedata)
19593 {
19594 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
19595 (unsigned long) ((char *) external - (char *) pnotes));
19596 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19597 inote.type, inote.namesz, inote.descsz);
19598 break;
19599 }
19600
19601 printf (" %s: ", get_v850_elf_note_type (inote.type));
19602
19603 if (! print_v850_note (& inote))
19604 {
19605 res = FALSE;
19606 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
19607 inote.namesz, inote.descsz);
19608 }
19609 }
19610
19611 free (pnotes);
19612
19613 return res;
19614 }
19615
19616 static bfd_boolean
19617 process_note_sections (Filedata * filedata)
19618 {
19619 Elf_Internal_Shdr * section;
19620 unsigned long i;
19621 unsigned int n = 0;
19622 bfd_boolean res = TRUE;
19623
19624 for (i = 0, section = filedata->section_headers;
19625 i < filedata->file_header.e_shnum && section != NULL;
19626 i++, section++)
19627 {
19628 if (section->sh_type == SHT_NOTE)
19629 {
19630 if (! process_notes_at (filedata, section,
19631 (bfd_vma) section->sh_offset,
19632 (bfd_vma) section->sh_size,
19633 (bfd_vma) section->sh_addralign))
19634 res = FALSE;
19635 n++;
19636 }
19637
19638 if (( filedata->file_header.e_machine == EM_V800
19639 || filedata->file_header.e_machine == EM_V850
19640 || filedata->file_header.e_machine == EM_CYGNUS_V850)
19641 && section->sh_type == SHT_RENESAS_INFO)
19642 {
19643 if (! process_v850_notes (filedata,
19644 (bfd_vma) section->sh_offset,
19645 (bfd_vma) section->sh_size))
19646 res = FALSE;
19647 n++;
19648 }
19649 }
19650
19651 if (n == 0)
19652 /* Try processing NOTE segments instead. */
19653 return process_corefile_note_segments (filedata);
19654
19655 return res;
19656 }
19657
19658 static bfd_boolean
19659 process_notes (Filedata * filedata)
19660 {
19661 /* If we have not been asked to display the notes then do nothing. */
19662 if (! do_notes)
19663 return TRUE;
19664
19665 if (filedata->file_header.e_type != ET_CORE)
19666 return process_note_sections (filedata);
19667
19668 /* No program headers means no NOTE segment. */
19669 if (filedata->file_header.e_phnum > 0)
19670 return process_corefile_note_segments (filedata);
19671
19672 printf (_("No note segments present in the core file.\n"));
19673 return TRUE;
19674 }
19675
19676 static unsigned char *
19677 display_public_gnu_attributes (unsigned char * start,
19678 const unsigned char * const end)
19679 {
19680 printf (_(" Unknown GNU attribute: %s\n"), start);
19681
19682 start += strnlen ((char *) start, end - start);
19683 display_raw_attribute (start, end);
19684
19685 return (unsigned char *) end;
19686 }
19687
19688 static unsigned char *
19689 display_generic_attribute (unsigned char * start,
19690 unsigned int tag,
19691 const unsigned char * const end)
19692 {
19693 if (tag == 0)
19694 return (unsigned char *) end;
19695
19696 return display_tag_value (tag, start, end);
19697 }
19698
19699 static bfd_boolean
19700 process_arch_specific (Filedata * filedata)
19701 {
19702 if (! do_arch)
19703 return TRUE;
19704
19705 switch (filedata->file_header.e_machine)
19706 {
19707 case EM_ARC:
19708 case EM_ARC_COMPACT:
19709 case EM_ARC_COMPACT2:
19710 return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES,
19711 display_arc_attribute,
19712 display_generic_attribute);
19713 case EM_ARM:
19714 return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES,
19715 display_arm_attribute,
19716 display_generic_attribute);
19717
19718 case EM_MIPS:
19719 case EM_MIPS_RS3_LE:
19720 return process_mips_specific (filedata);
19721
19722 case EM_MSP430:
19723 return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
19724 display_msp430x_attribute,
19725 display_msp430_gnu_attribute);
19726
19727 case EM_RISCV:
19728 return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES,
19729 display_riscv_attribute,
19730 display_generic_attribute);
19731
19732 case EM_NDS32:
19733 return process_nds32_specific (filedata);
19734
19735 case EM_PPC:
19736 case EM_PPC64:
19737 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
19738 display_power_gnu_attribute);
19739
19740 case EM_S390:
19741 case EM_S390_OLD:
19742 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
19743 display_s390_gnu_attribute);
19744
19745 case EM_SPARC:
19746 case EM_SPARC32PLUS:
19747 case EM_SPARCV9:
19748 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
19749 display_sparc_gnu_attribute);
19750
19751 case EM_TI_C6000:
19752 return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES,
19753 display_tic6x_attribute,
19754 display_generic_attribute);
19755
19756 default:
19757 return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES,
19758 display_public_gnu_attributes,
19759 display_generic_attribute);
19760 }
19761 }
19762
19763 static bfd_boolean
19764 get_file_header (Filedata * filedata)
19765 {
19766 /* Read in the identity array. */
19767 if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1)
19768 return FALSE;
19769
19770 /* Determine how to read the rest of the header. */
19771 switch (filedata->file_header.e_ident[EI_DATA])
19772 {
19773 default:
19774 case ELFDATANONE:
19775 case ELFDATA2LSB:
19776 byte_get = byte_get_little_endian;
19777 byte_put = byte_put_little_endian;
19778 break;
19779 case ELFDATA2MSB:
19780 byte_get = byte_get_big_endian;
19781 byte_put = byte_put_big_endian;
19782 break;
19783 }
19784
19785 /* For now we only support 32 bit and 64 bit ELF files. */
19786 is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64);
19787
19788 /* Read in the rest of the header. */
19789 if (is_32bit_elf)
19790 {
19791 Elf32_External_Ehdr ehdr32;
19792
19793 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1)
19794 return FALSE;
19795
19796 filedata->file_header.e_type = BYTE_GET (ehdr32.e_type);
19797 filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine);
19798 filedata->file_header.e_version = BYTE_GET (ehdr32.e_version);
19799 filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry);
19800 filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
19801 filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
19802 filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags);
19803 filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
19804 filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
19805 filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
19806 filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
19807 filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
19808 filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
19809 }
19810 else
19811 {
19812 Elf64_External_Ehdr ehdr64;
19813
19814 /* If we have been compiled with sizeof (bfd_vma) == 4, then
19815 we will not be able to cope with the 64bit data found in
19816 64 ELF files. Detect this now and abort before we start
19817 overwriting things. */
19818 if (sizeof (bfd_vma) < 8)
19819 {
19820 error (_("This instance of readelf has been built without support for a\n\
19821 64 bit data type and so it cannot read 64 bit ELF files.\n"));
19822 return FALSE;
19823 }
19824
19825 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1)
19826 return FALSE;
19827
19828 filedata->file_header.e_type = BYTE_GET (ehdr64.e_type);
19829 filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine);
19830 filedata->file_header.e_version = BYTE_GET (ehdr64.e_version);
19831 filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry);
19832 filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
19833 filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
19834 filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags);
19835 filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
19836 filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
19837 filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
19838 filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
19839 filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
19840 filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
19841 }
19842
19843 if (filedata->file_header.e_shoff)
19844 {
19845 /* There may be some extensions in the first section header. Don't
19846 bomb if we can't read it. */
19847 if (is_32bit_elf)
19848 get_32bit_section_headers (filedata, TRUE);
19849 else
19850 get_64bit_section_headers (filedata, TRUE);
19851 }
19852
19853 return TRUE;
19854 }
19855
19856 static void
19857 close_file (Filedata * filedata)
19858 {
19859 if (filedata)
19860 {
19861 if (filedata->handle)
19862 fclose (filedata->handle);
19863 free (filedata);
19864 }
19865 }
19866
19867 void
19868 close_debug_file (void * data)
19869 {
19870 close_file ((Filedata *) data);
19871 }
19872
19873 static Filedata *
19874 open_file (const char * pathname)
19875 {
19876 struct stat statbuf;
19877 Filedata * filedata = NULL;
19878
19879 if (stat (pathname, & statbuf) < 0
19880 || ! S_ISREG (statbuf.st_mode))
19881 goto fail;
19882
19883 filedata = calloc (1, sizeof * filedata);
19884 if (filedata == NULL)
19885 goto fail;
19886
19887 filedata->handle = fopen (pathname, "rb");
19888 if (filedata->handle == NULL)
19889 goto fail;
19890
19891 filedata->file_size = (bfd_size_type) statbuf.st_size;
19892 filedata->file_name = pathname;
19893
19894 if (! get_file_header (filedata))
19895 goto fail;
19896
19897 if (filedata->file_header.e_shoff)
19898 {
19899 bfd_boolean res;
19900
19901 /* Read the section headers again, this time for real. */
19902 if (is_32bit_elf)
19903 res = get_32bit_section_headers (filedata, FALSE);
19904 else
19905 res = get_64bit_section_headers (filedata, FALSE);
19906
19907 if (!res)
19908 goto fail;
19909 }
19910
19911 return filedata;
19912
19913 fail:
19914 if (filedata)
19915 {
19916 if (filedata->handle)
19917 fclose (filedata->handle);
19918 free (filedata);
19919 }
19920 return NULL;
19921 }
19922
19923 void *
19924 open_debug_file (const char * pathname)
19925 {
19926 return open_file (pathname);
19927 }
19928
19929 /* Process one ELF object file according to the command line options.
19930 This file may actually be stored in an archive. The file is
19931 positioned at the start of the ELF object. Returns TRUE if no
19932 problems were encountered, FALSE otherwise. */
19933
19934 static bfd_boolean
19935 process_object (Filedata * filedata)
19936 {
19937 bfd_boolean have_separate_files;
19938 unsigned int i;
19939 bfd_boolean res = TRUE;
19940
19941 if (! get_file_header (filedata))
19942 {
19943 error (_("%s: Failed to read file header\n"), filedata->file_name);
19944 return FALSE;
19945 }
19946
19947 /* Initialise per file variables. */
19948 for (i = ARRAY_SIZE (version_info); i--;)
19949 version_info[i] = 0;
19950
19951 for (i = ARRAY_SIZE (dynamic_info); i--;)
19952 dynamic_info[i] = 0;
19953 dynamic_info_DT_GNU_HASH = 0;
19954 dynamic_info_DT_MIPS_XHASH = 0;
19955
19956 /* Process the file. */
19957 if (show_name)
19958 printf (_("\nFile: %s\n"), filedata->file_name);
19959
19960 /* Initialise the dump_sects array from the cmdline_dump_sects array.
19961 Note we do this even if cmdline_dump_sects is empty because we
19962 must make sure that the dump_sets array is zeroed out before each
19963 object file is processed. */
19964 if (filedata->num_dump_sects > cmdline.num_dump_sects)
19965 memset (filedata->dump_sects, 0, filedata->num_dump_sects * sizeof (* filedata->dump_sects));
19966
19967 if (cmdline.num_dump_sects > 0)
19968 {
19969 if (filedata->num_dump_sects == 0)
19970 /* A sneaky way of allocating the dump_sects array. */
19971 request_dump_bynumber (filedata, cmdline.num_dump_sects, 0);
19972
19973 assert (filedata->num_dump_sects >= cmdline.num_dump_sects);
19974 memcpy (filedata->dump_sects, cmdline.dump_sects,
19975 cmdline.num_dump_sects * sizeof (* filedata->dump_sects));
19976 }
19977
19978 if (! process_file_header (filedata))
19979 return FALSE;
19980
19981 if (! process_section_headers (filedata))
19982 {
19983 /* Without loaded section headers we cannot process lots of things. */
19984 do_unwind = do_version = do_dump = do_arch = FALSE;
19985
19986 if (! do_using_dynamic)
19987 do_syms = do_dyn_syms = do_reloc = FALSE;
19988 }
19989
19990 if (! process_section_groups (filedata))
19991 /* Without loaded section groups we cannot process unwind. */
19992 do_unwind = FALSE;
19993
19994 if (process_program_headers (filedata))
19995 process_dynamic_section (filedata);
19996 else
19997 res = FALSE;
19998
19999 if (! process_relocs (filedata))
20000 res = FALSE;
20001
20002 if (! process_unwind (filedata))
20003 res = FALSE;
20004
20005 if (! process_symbol_table (filedata))
20006 res = FALSE;
20007
20008 if (! process_syminfo (filedata))
20009 res = FALSE;
20010
20011 if (! process_version_sections (filedata))
20012 res = FALSE;
20013
20014 if (filedata->file_header.e_shstrndx != SHN_UNDEF)
20015 have_separate_files = load_separate_debug_files (filedata, filedata->file_name);
20016 else
20017 have_separate_files = FALSE;
20018
20019 if (! process_section_contents (filedata))
20020 res = FALSE;
20021
20022 if (have_separate_files)
20023 {
20024 separate_info * d;
20025
20026 for (d = first_separate_info; d != NULL; d = d->next)
20027 {
20028 if (! process_section_headers (d->handle))
20029 res = FALSE;
20030 else if (! process_section_contents (d->handle))
20031 res = FALSE;
20032 }
20033
20034 /* The file handles are closed by the call to free_debug_memory() below. */
20035 }
20036
20037 if (! process_notes (filedata))
20038 res = FALSE;
20039
20040 if (! process_gnu_liblist (filedata))
20041 res = FALSE;
20042
20043 if (! process_arch_specific (filedata))
20044 res = FALSE;
20045
20046 free (filedata->program_headers);
20047 filedata->program_headers = NULL;
20048
20049 free (filedata->section_headers);
20050 filedata->section_headers = NULL;
20051
20052 free (filedata->string_table);
20053 filedata->string_table = NULL;
20054 filedata->string_table_length = 0;
20055
20056 if (dynamic_strings)
20057 {
20058 free (dynamic_strings);
20059 dynamic_strings = NULL;
20060 dynamic_strings_length = 0;
20061 }
20062
20063 if (dynamic_symbols)
20064 {
20065 free (dynamic_symbols);
20066 dynamic_symbols = NULL;
20067 num_dynamic_syms = 0;
20068 }
20069
20070 if (dynamic_syminfo)
20071 {
20072 free (dynamic_syminfo);
20073 dynamic_syminfo = NULL;
20074 }
20075
20076 if (dynamic_section)
20077 {
20078 free (dynamic_section);
20079 dynamic_section = NULL;
20080 }
20081
20082 if (section_headers_groups)
20083 {
20084 free (section_headers_groups);
20085 section_headers_groups = NULL;
20086 }
20087
20088 if (section_groups)
20089 {
20090 struct group_list * g;
20091 struct group_list * next;
20092
20093 for (i = 0; i < group_count; i++)
20094 {
20095 for (g = section_groups [i].root; g != NULL; g = next)
20096 {
20097 next = g->next;
20098 free (g);
20099 }
20100 }
20101
20102 free (section_groups);
20103 section_groups = NULL;
20104 }
20105
20106 free_debug_memory ();
20107
20108 return res;
20109 }
20110
20111 /* Process an ELF archive.
20112 On entry the file is positioned just after the ARMAG string.
20113 Returns TRUE upon success, FALSE otherwise. */
20114
20115 static bfd_boolean
20116 process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
20117 {
20118 struct archive_info arch;
20119 struct archive_info nested_arch;
20120 size_t got;
20121 bfd_boolean ret = TRUE;
20122
20123 show_name = TRUE;
20124
20125 /* The ARCH structure is used to hold information about this archive. */
20126 arch.file_name = NULL;
20127 arch.file = NULL;
20128 arch.index_array = NULL;
20129 arch.sym_table = NULL;
20130 arch.longnames = NULL;
20131
20132 /* The NESTED_ARCH structure is used as a single-item cache of information
20133 about a nested archive (when members of a thin archive reside within
20134 another regular archive file). */
20135 nested_arch.file_name = NULL;
20136 nested_arch.file = NULL;
20137 nested_arch.index_array = NULL;
20138 nested_arch.sym_table = NULL;
20139 nested_arch.longnames = NULL;
20140
20141 if (setup_archive (&arch, filedata->file_name, filedata->handle,
20142 is_thin_archive, do_archive_index) != 0)
20143 {
20144 ret = FALSE;
20145 goto out;
20146 }
20147
20148 if (do_archive_index)
20149 {
20150 if (arch.sym_table == NULL)
20151 error (_("%s: unable to dump the index as none was found\n"), filedata->file_name);
20152 else
20153 {
20154 unsigned long i, l;
20155 unsigned long current_pos;
20156
20157 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
20158 filedata->file_name, (unsigned long) arch.index_num, arch.sym_size);
20159
20160 current_pos = ftell (filedata->handle);
20161
20162 for (i = l = 0; i < arch.index_num; i++)
20163 {
20164 if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
20165 {
20166 char * member_name;
20167
20168 member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
20169
20170 if (member_name != NULL)
20171 {
20172 char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
20173
20174 if (qualified_name != NULL)
20175 {
20176 printf (_("Contents of binary %s at offset "), qualified_name);
20177 (void) print_vma (arch.index_array[i], PREFIX_HEX);
20178 putchar ('\n');
20179 free (qualified_name);
20180 }
20181 }
20182 }
20183
20184 if (l >= arch.sym_size)
20185 {
20186 error (_("%s: end of the symbol table reached before the end of the index\n"),
20187 filedata->file_name);
20188 ret = FALSE;
20189 break;
20190 }
20191 /* PR 17531: file: 0b6630b2. */
20192 printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l);
20193 l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
20194 }
20195
20196 if (arch.uses_64bit_indices)
20197 l = (l + 7) & ~ 7;
20198 else
20199 l += l & 1;
20200
20201 if (l < arch.sym_size)
20202 {
20203 error (ngettext ("%s: %ld byte remains in the symbol table, "
20204 "but without corresponding entries in "
20205 "the index table\n",
20206 "%s: %ld bytes remain in the symbol table, "
20207 "but without corresponding entries in "
20208 "the index table\n",
20209 arch.sym_size - l),
20210 filedata->file_name, arch.sym_size - l);
20211 ret = FALSE;
20212 }
20213
20214 if (fseek (filedata->handle, current_pos, SEEK_SET) != 0)
20215 {
20216 error (_("%s: failed to seek back to start of object files in the archive\n"),
20217 filedata->file_name);
20218 ret = FALSE;
20219 goto out;
20220 }
20221 }
20222
20223 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
20224 && !do_segments && !do_header && !do_dump && !do_version
20225 && !do_histogram && !do_debugging && !do_arch && !do_notes
20226 && !do_section_groups && !do_dyn_syms)
20227 {
20228 ret = TRUE; /* Archive index only. */
20229 goto out;
20230 }
20231 }
20232
20233 while (1)
20234 {
20235 char * name;
20236 size_t namelen;
20237 char * qualified_name;
20238
20239 /* Read the next archive header. */
20240 if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0)
20241 {
20242 error (_("%s: failed to seek to next archive header\n"), arch.file_name);
20243 return FALSE;
20244 }
20245 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle);
20246 if (got != sizeof arch.arhdr)
20247 {
20248 if (got == 0)
20249 break;
20250 /* PR 24049 - we cannot use filedata->file_name as this will
20251 have already been freed. */
20252 error (_("%s: failed to read archive header\n"), arch.file_name);
20253
20254 ret = FALSE;
20255 break;
20256 }
20257 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
20258 {
20259 error (_("%s: did not find a valid archive header\n"), arch.file_name);
20260 ret = FALSE;
20261 break;
20262 }
20263
20264 arch.next_arhdr_offset += sizeof arch.arhdr;
20265
20266 archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
20267 if (archive_file_size & 01)
20268 ++archive_file_size;
20269
20270 name = get_archive_member_name (&arch, &nested_arch);
20271 if (name == NULL)
20272 {
20273 error (_("%s: bad archive file name\n"), arch.file_name);
20274 ret = FALSE;
20275 break;
20276 }
20277 namelen = strlen (name);
20278
20279 qualified_name = make_qualified_name (&arch, &nested_arch, name);
20280 if (qualified_name == NULL)
20281 {
20282 error (_("%s: bad archive file name\n"), arch.file_name);
20283 ret = FALSE;
20284 break;
20285 }
20286
20287 if (is_thin_archive && arch.nested_member_origin == 0)
20288 {
20289 /* This is a proxy for an external member of a thin archive. */
20290 Filedata * member_filedata;
20291 char * member_file_name = adjust_relative_path
20292 (filedata->file_name, name, namelen);
20293
20294 if (member_file_name == NULL)
20295 {
20296 ret = FALSE;
20297 break;
20298 }
20299
20300 member_filedata = open_file (member_file_name);
20301 if (member_filedata == NULL)
20302 {
20303 error (_("Input file '%s' is not readable.\n"), member_file_name);
20304 free (member_file_name);
20305 ret = FALSE;
20306 break;
20307 }
20308
20309 archive_file_offset = arch.nested_member_origin;
20310 member_filedata->file_name = qualified_name;
20311
20312 if (! process_object (member_filedata))
20313 ret = FALSE;
20314
20315 close_file (member_filedata);
20316 free (member_file_name);
20317 }
20318 else if (is_thin_archive)
20319 {
20320 Filedata thin_filedata;
20321
20322 memset (&thin_filedata, 0, sizeof (thin_filedata));
20323
20324 /* PR 15140: Allow for corrupt thin archives. */
20325 if (nested_arch.file == NULL)
20326 {
20327 error (_("%s: contains corrupt thin archive: %s\n"),
20328 qualified_name, name);
20329 ret = FALSE;
20330 break;
20331 }
20332
20333 /* This is a proxy for a member of a nested archive. */
20334 archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
20335
20336 /* The nested archive file will have been opened and setup by
20337 get_archive_member_name. */
20338 if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
20339 {
20340 error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
20341 ret = FALSE;
20342 break;
20343 }
20344
20345 thin_filedata.handle = nested_arch.file;
20346 thin_filedata.file_name = qualified_name;
20347
20348 if (! process_object (& thin_filedata))
20349 ret = FALSE;
20350 }
20351 else
20352 {
20353 archive_file_offset = arch.next_arhdr_offset;
20354 arch.next_arhdr_offset += archive_file_size;
20355
20356 filedata->file_name = qualified_name;
20357 if (! process_object (filedata))
20358 ret = FALSE;
20359 }
20360
20361 if (filedata->dump_sects != NULL)
20362 {
20363 free (filedata->dump_sects);
20364 filedata->dump_sects = NULL;
20365 filedata->num_dump_sects = 0;
20366 }
20367
20368 free (qualified_name);
20369 }
20370
20371 out:
20372 if (nested_arch.file != NULL)
20373 fclose (nested_arch.file);
20374 release_archive (&nested_arch);
20375 release_archive (&arch);
20376
20377 return ret;
20378 }
20379
20380 static bfd_boolean
20381 process_file (char * file_name)
20382 {
20383 Filedata * filedata = NULL;
20384 struct stat statbuf;
20385 char armag[SARMAG];
20386 bfd_boolean ret = TRUE;
20387
20388 if (stat (file_name, &statbuf) < 0)
20389 {
20390 if (errno == ENOENT)
20391 error (_("'%s': No such file\n"), file_name);
20392 else
20393 error (_("Could not locate '%s'. System error message: %s\n"),
20394 file_name, strerror (errno));
20395 return FALSE;
20396 }
20397
20398 if (! S_ISREG (statbuf.st_mode))
20399 {
20400 error (_("'%s' is not an ordinary file\n"), file_name);
20401 return FALSE;
20402 }
20403
20404 filedata = calloc (1, sizeof * filedata);
20405 if (filedata == NULL)
20406 {
20407 error (_("Out of memory allocating file data structure\n"));
20408 return FALSE;
20409 }
20410
20411 filedata->file_name = file_name;
20412 filedata->handle = fopen (file_name, "rb");
20413 if (filedata->handle == NULL)
20414 {
20415 error (_("Input file '%s' is not readable.\n"), file_name);
20416 free (filedata);
20417 return FALSE;
20418 }
20419
20420 if (fread (armag, SARMAG, 1, filedata->handle) != 1)
20421 {
20422 error (_("%s: Failed to read file's magic number\n"), file_name);
20423 fclose (filedata->handle);
20424 free (filedata);
20425 return FALSE;
20426 }
20427
20428 filedata->file_size = (bfd_size_type) statbuf.st_size;
20429
20430 if (memcmp (armag, ARMAG, SARMAG) == 0)
20431 {
20432 if (! process_archive (filedata, FALSE))
20433 ret = FALSE;
20434 }
20435 else if (memcmp (armag, ARMAGT, SARMAG) == 0)
20436 {
20437 if ( ! process_archive (filedata, TRUE))
20438 ret = FALSE;
20439 }
20440 else
20441 {
20442 if (do_archive_index)
20443 error (_("File %s is not an archive so its index cannot be displayed.\n"),
20444 file_name);
20445
20446 rewind (filedata->handle);
20447 archive_file_size = archive_file_offset = 0;
20448
20449 if (! process_object (filedata))
20450 ret = FALSE;
20451 }
20452
20453 fclose (filedata->handle);
20454 free (filedata);
20455
20456 return ret;
20457 }
20458
20459 #ifdef SUPPORT_DISASSEMBLY
20460 /* Needed by the i386 disassembler. For extra credit, someone could
20461 fix this so that we insert symbolic addresses here, esp for GOT/PLT
20462 symbols. */
20463
20464 void
20465 print_address (unsigned int addr, FILE * outfile)
20466 {
20467 fprintf (outfile,"0x%8.8x", addr);
20468 }
20469
20470 /* Needed by the i386 disassembler. */
20471
20472 void
20473 db_task_printsym (unsigned int addr)
20474 {
20475 print_address (addr, stderr);
20476 }
20477 #endif
20478
20479 int
20480 main (int argc, char ** argv)
20481 {
20482 int err;
20483
20484 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
20485 setlocale (LC_MESSAGES, "");
20486 #endif
20487 #if defined (HAVE_SETLOCALE)
20488 setlocale (LC_CTYPE, "");
20489 #endif
20490 bindtextdomain (PACKAGE, LOCALEDIR);
20491 textdomain (PACKAGE);
20492
20493 expandargv (&argc, &argv);
20494
20495 cmdline.file_name = "<cmdline>";
20496 parse_args (& cmdline, argc, argv);
20497
20498 if (optind < (argc - 1))
20499 show_name = TRUE;
20500 else if (optind >= argc)
20501 {
20502 warn (_("Nothing to do.\n"));
20503 usage (stderr);
20504 }
20505
20506 err = FALSE;
20507 while (optind < argc)
20508 if (! process_file (argv[optind++]))
20509 err = TRUE;
20510
20511 if (cmdline.dump_sects != NULL)
20512 free (cmdline.dump_sects);
20513
20514 free (dump_ctf_symtab_name);
20515 free (dump_ctf_strtab_name);
20516 free (dump_ctf_parent_name);
20517
20518 return err ? EXIT_FAILURE : EXIT_SUCCESS;
20519 }
This page took 0.762526 seconds and 4 git commands to generate.