1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* The difference between readelf and objdump:
26 Both programs are capable of displaying the contents of ELF format files,
27 so why does the binutils project have two file dumpers ?
29 The reason is that objdump sees an ELF file through a BFD filter of the
30 world; if BFD has a bug where, say, it disagrees about a machine constant
31 in e_flags, then the odds are good that it will remain internally
32 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
33 GAS sees it the BFD way. There was need for a tool to go find out what
34 the file actually says.
36 This is why the readelf program does not link against the BFD library - it
37 exists as an independent program to help verify the correct working of BFD.
39 There is also the case that readelf can provide more information about an
40 ELF file than is provided by objdump. In particular it can display DWARF
41 debugging information which (at the moment) objdump cannot. */
50 /* Define BFD64 here, even if our default architecture is 32 bit ELF
51 as this will allow us to read in and parse 64bit and 32bit ELF files.
52 Only do this if we believe that the compiler can support a 64 bit
53 data type. For now we only rely on GCC being able to do this. */
64 #include "elf/common.h"
65 #include "elf/external.h"
66 #include "elf/internal.h"
69 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
70 we can obtain the H8 reloc numbers. We need these for the
71 get_reloc_size() function. We include h8.h again after defining
72 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
77 /* Undo the effects of #including reloc-macros.h. */
79 #undef START_RELOC_NUMBERS
83 #undef END_RELOC_NUMBERS
84 #undef _RELOC_MACROS_H
86 /* The following headers use the elf/reloc-macros.h file to
87 automatically generate relocation recognition functions
88 such as elf_mips_reloc_type() */
90 #define RELOC_MACROS_GEN_FUNC
92 #include "elf/aarch64.h"
93 #include "elf/alpha.h"
101 #include "elf/csky.h"
102 #include "elf/d10v.h"
103 #include "elf/d30v.h"
106 #include "elf/epiphany.h"
107 #include "elf/fr30.h"
109 #include "elf/ft32.h"
111 #include "elf/hppa.h"
112 #include "elf/i386.h"
113 #include "elf/i370.h"
114 #include "elf/i860.h"
115 #include "elf/i960.h"
116 #include "elf/ia64.h"
117 #include "elf/ip2k.h"
118 #include "elf/lm32.h"
119 #include "elf/iq2000.h"
120 #include "elf/m32c.h"
121 #include "elf/m32r.h"
122 #include "elf/m68k.h"
123 #include "elf/m68hc11.h"
124 #include "elf/s12z.h"
125 #include "elf/mcore.h"
127 #include "elf/metag.h"
128 #include "elf/microblaze.h"
129 #include "elf/mips.h"
130 #include "elf/mmix.h"
131 #include "elf/mn10200.h"
132 #include "elf/mn10300.h"
133 #include "elf/moxie.h"
135 #include "elf/msp430.h"
136 #include "elf/nds32.h"
138 #include "elf/nios2.h"
139 #include "elf/or1k.h"
142 #include "elf/ppc64.h"
144 #include "elf/riscv.h"
145 #include "elf/rl78.h"
147 #include "elf/s390.h"
148 #include "elf/score.h"
150 #include "elf/sparc.h"
152 #include "elf/tic6x.h"
153 #include "elf/tilegx.h"
154 #include "elf/tilepro.h"
155 #include "elf/v850.h"
157 #include "elf/visium.h"
158 #include "elf/wasm32.h"
159 #include "elf/x86-64.h"
160 #include "elf/xc16x.h"
161 #include "elf/xgate.h"
162 #include "elf/xstormy16.h"
163 #include "elf/xtensa.h"
165 #include "elf/loongarch.h"
168 #include "libiberty.h"
169 #include "safe-ctype.h"
170 #include "filenames.h"
173 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
176 typedef struct elf_section_list
178 Elf_Internal_Shdr
* hdr
;
179 struct elf_section_list
* next
;
182 /* Flag bits indicating particular types of dump. */
183 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
184 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
185 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
186 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
187 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
188 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
190 typedef unsigned char dump_type
;
192 /* A linked list of the section names for which dumps were requested. */
193 struct dump_list_entry
197 struct dump_list_entry
* next
;
200 /* A dynamic array of flags indicating for which sections a dump
201 has been requested via command line switches. */
204 dump_type
* dump_sects
;
205 unsigned int num_dump_sects
;
208 static struct dump_data cmdline
;
210 static struct dump_list_entry
* dump_sects_byname
;
212 char * program_name
= "readelf";
214 static bool show_name
= false;
215 static bool do_dynamic
= false;
216 static bool do_syms
= false;
217 static bool do_dyn_syms
= false;
218 static bool do_lto_syms
= false;
219 static bool do_reloc
= false;
220 static bool do_sections
= false;
221 static bool do_section_groups
= false;
222 static bool do_section_details
= false;
223 static bool do_segments
= false;
224 static bool do_unwind
= false;
225 static bool do_using_dynamic
= false;
226 static bool do_header
= false;
227 static bool do_dump
= false;
228 static bool do_version
= false;
229 static bool do_histogram
= false;
230 static bool do_debugging
= false;
231 static bool do_ctf
= false;
232 static bool do_arch
= false;
233 static bool do_notes
= false;
234 static bool do_archive_index
= false;
235 static bool check_all
= false;
236 static bool is_32bit_elf
= false;
237 static bool decompress_dumps
= false;
238 static bool do_not_show_symbol_truncation
= false;
239 static bool do_demangle
= false; /* Pretty print C++ symbol names. */
240 static bool process_links
= false;
241 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
242 static int sym_base
= 0;
244 static char *dump_ctf_parent_name
;
245 static char *dump_ctf_symtab_name
;
246 static char *dump_ctf_strtab_name
;
250 struct group_list
* next
;
251 unsigned int section_index
;
256 struct group_list
* root
;
257 unsigned int group_index
;
260 typedef struct filedata
262 const char * file_name
;
265 bfd_size_type file_size
;
266 Elf_Internal_Ehdr file_header
;
267 unsigned long archive_file_offset
;
268 unsigned long archive_file_size
;
269 /* Everything below this point is cleared out by free_filedata. */
270 Elf_Internal_Shdr
* section_headers
;
271 Elf_Internal_Phdr
* program_headers
;
273 unsigned long string_table_length
;
274 unsigned long dynamic_addr
;
275 bfd_size_type dynamic_size
;
277 Elf_Internal_Dyn
* dynamic_section
;
278 Elf_Internal_Shdr
* dynamic_strtab_section
;
279 char * dynamic_strings
;
280 unsigned long dynamic_strings_length
;
281 Elf_Internal_Shdr
* dynamic_symtab_section
;
282 unsigned long num_dynamic_syms
;
283 Elf_Internal_Sym
* dynamic_symbols
;
284 bfd_vma version_info
[16];
285 unsigned int dynamic_syminfo_nent
;
286 Elf_Internal_Syminfo
* dynamic_syminfo
;
287 unsigned long dynamic_syminfo_offset
;
288 bfd_size_type nbuckets
;
289 bfd_size_type nchains
;
292 bfd_size_type ngnubuckets
;
293 bfd_size_type ngnuchains
;
294 bfd_vma
* gnubuckets
;
298 char * program_interpreter
;
299 bfd_vma dynamic_info
[DT_ENCODING
];
300 bfd_vma dynamic_info_DT_GNU_HASH
;
301 bfd_vma dynamic_info_DT_MIPS_XHASH
;
302 elf_section_list
* symtab_shndx_list
;
304 struct group
* section_groups
;
305 struct group
** section_headers_groups
;
306 /* A dynamic array of flags indicating for which sections a dump of
307 some kind has been requested. It is reset on a per-object file
308 basis and then initialised from the cmdline_dump_sects array,
309 the results of interpreting the -w switch, and the
310 dump_sects_byname list. */
311 struct dump_data dump
;
314 /* How to print a vma value. */
315 typedef enum print_mode
332 /* Versioned symbol info. */
333 enum versioned_symbol_info
340 static const char * get_symbol_version_string
341 (Filedata
*, bool, const char *, unsigned long, unsigned,
342 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
346 static inline const char *
347 section_name (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
349 return filedata
->string_table
+ hdr
->sh_name
;
353 section_name_valid (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
356 && filedata
->string_table
!= NULL
357 && hdr
->sh_name
< filedata
->string_table_length
);
360 static inline const char *
361 section_name_print (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
365 if (filedata
->string_table
== NULL
)
366 return _("<no-strings>");
367 if (hdr
->sh_name
>= filedata
->string_table_length
)
368 return _("<corrupt>");
369 return section_name (filedata
, hdr
);
372 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
375 valid_symbol_name (const char *strtab
, size_t strtab_size
, uint64_t offset
)
377 return strtab
!= NULL
&& offset
< strtab_size
;
381 valid_dynamic_name (const Filedata
*filedata
, uint64_t offset
)
383 return valid_symbol_name (filedata
->dynamic_strings
,
384 filedata
->dynamic_strings_length
, offset
);
387 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
388 already been called and verified that the string exists. */
389 static inline const char *
390 get_dynamic_name (const Filedata
*filedata
, size_t offset
)
392 return filedata
->dynamic_strings
+ offset
;
395 #define REMOVE_ARCH_BITS(ADDR) \
398 if (filedata->file_header.e_machine == EM_ARM) \
403 /* Get the correct GNU hash section name. */
404 #define GNU_HASH_SECTION_NAME(filedata) \
405 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
407 /* Print a BFD_VMA to an internal buffer, for use in error messages.
408 BFD_FMA_FMT can't be used in translated strings. */
411 bfd_vmatoa (char *fmtch
, bfd_vma value
)
413 /* bfd_vmatoa is used more then once in a printf call for output.
414 Cycle through an array of buffers. */
415 static int buf_pos
= 0;
416 static struct bfd_vmatoa_buf
423 ret
= buf
[buf_pos
++].place
;
424 buf_pos
%= ARRAY_SIZE (buf
);
426 sprintf (fmt
, "%%%s%s", BFD_VMA_FMT
, fmtch
);
427 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
431 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
432 OFFSET + the offset of the current archive member, if we are examining an
433 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
434 allocate a buffer using malloc and fill that. In either case return the
435 pointer to the start of the retrieved data or NULL if something went wrong.
436 If something does go wrong and REASON is not NULL then emit an error
437 message using REASON as part of the context. */
440 get_data (void * var
,
442 unsigned long offset
,
448 bfd_size_type amt
= size
* nmemb
;
450 if (size
== 0 || nmemb
== 0)
453 /* If the size_t type is smaller than the bfd_size_type, eg because
454 you are building a 32-bit tool on a 64-bit host, then make sure
455 that when the sizes are cast to (size_t) no information is lost. */
456 if ((size_t) size
!= size
457 || (size_t) nmemb
!= nmemb
458 || (size_t) amt
!= amt
)
461 error (_("Size truncation prevents reading %s"
462 " elements of size %s for %s\n"),
463 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
467 /* Check for size overflow. */
468 if (amt
/ size
!= nmemb
|| (size_t) amt
+ 1 == 0)
471 error (_("Size overflow prevents reading %s"
472 " elements of size %s for %s\n"),
473 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
477 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
478 attempting to allocate memory when the read is bound to fail. */
479 if (filedata
->archive_file_offset
> filedata
->file_size
480 || offset
> filedata
->file_size
- filedata
->archive_file_offset
481 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
484 error (_("Reading %s bytes extends past end of file for %s\n"),
485 bfd_vmatoa ("u", amt
), reason
);
489 if (fseek (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
493 error (_("Unable to seek to 0x%lx for %s\n"),
494 filedata
->archive_file_offset
+ offset
, reason
);
501 /* + 1 so that we can '\0' terminate invalid string table sections. */
502 mvar
= malloc ((size_t) amt
+ 1);
507 error (_("Out of memory allocating %s bytes for %s\n"),
508 bfd_vmatoa ("u", amt
), reason
);
512 ((char *) mvar
)[amt
] = '\0';
515 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
518 error (_("Unable to read in %s bytes of %s\n"),
519 bfd_vmatoa ("u", amt
), reason
);
528 /* Print a VMA value in the MODE specified.
529 Returns the number of characters displayed. */
532 print_vma (bfd_vma vma
, print_mode mode
)
544 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
551 return printf ("%5" BFD_VMA_FMT
"d", vma
);
557 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
563 return nc
+ printf ("%05" BFD_VMA_FMT
"x", vma
);
566 return printf ("%" BFD_VMA_FMT
"d", vma
);
569 return printf ("%" BFD_VMA_FMT
"u", vma
);
572 return printf ("%5" BFD_VMA_FMT
"u", vma
);
575 return printf ("%" BFD_VMA_FMT
"o", vma
);
578 return printf ("%5" BFD_VMA_FMT
"o", vma
);
581 /* FIXME: Report unrecognised mode ? */
587 /* Display a symbol on stdout. Handles the display of control characters and
588 multibye characters (assuming the host environment supports them).
590 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
592 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
593 abs(WIDTH) - 5 characters followed by "[...]".
595 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
596 padding as necessary.
598 Returns the number of emitted characters. */
601 print_symbol (signed int width
, const char * symbol
)
603 bool extra_padding
= false;
604 bool do_dots
= false;
605 signed int num_printed
= 0;
606 #ifdef HAVE_MBSTATE_T
609 unsigned int width_remaining
;
610 const void * alloced_symbol
= NULL
;
614 /* Keep the width positive. This helps the code below. */
616 extra_padding
= true;
622 /* Set the remaining width to a very large value.
623 This simplifies the code below. */
624 width_remaining
= INT_MAX
;
627 width_remaining
= width
;
628 if (! do_not_show_symbol_truncation
629 && (int) strlen (symbol
) > width
)
631 width_remaining
-= 5;
632 if ((int) width_remaining
< 0)
638 #ifdef HAVE_MBSTATE_T
639 /* Initialise the multibyte conversion state. */
640 memset (& state
, 0, sizeof (state
));
643 if (do_demangle
&& *symbol
)
645 const char * res
= cplus_demangle (symbol
, demangle_flags
);
648 alloced_symbol
= symbol
= res
;
651 while (width_remaining
)
654 const char c
= *symbol
++;
659 /* Do not print control characters directly as they can affect terminal
660 settings. Such characters usually appear in the names generated
661 by the assembler for local labels. */
664 if (width_remaining
< 2)
667 printf ("^%c", c
+ 0x40);
668 width_remaining
-= 2;
671 else if (ISPRINT (c
))
679 #ifdef HAVE_MBSTATE_T
682 /* Let printf do the hard work of displaying multibyte characters. */
683 printf ("%.1s", symbol
- 1);
687 #ifdef HAVE_MBSTATE_T
688 /* Try to find out how many bytes made up the character that was
689 just printed. Advance the symbol pointer past the bytes that
691 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
695 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
701 num_printed
+= printf ("[...]");
703 if (extra_padding
&& num_printed
< width
)
705 /* Fill in the remaining spaces. */
706 printf ("%-*s", width
- num_printed
, " ");
710 free ((void *) alloced_symbol
);
714 /* Returns a pointer to a static buffer containing a printable version of
715 the given section's name. Like print_symbol, except that it does not try
716 to print multibyte characters, it just interprets them as hex values. */
719 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
721 #define MAX_PRINT_SEC_NAME_LEN 256
722 static char sec_name_buf
[MAX_PRINT_SEC_NAME_LEN
+ 1];
723 const char * name
= section_name_print (filedata
, sec
);
724 char * buf
= sec_name_buf
;
726 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
728 while ((c
= * name
++) != 0)
739 else if (ISPRINT (c
))
746 static char hex
[17] = "0123456789ABCDEF";
751 * buf
++ = hex
[(c
& 0xf0) >> 4];
752 * buf
++ = hex
[c
& 0x0f];
766 printable_section_name_from_index (Filedata
* filedata
, unsigned long ndx
)
768 if (ndx
>= filedata
->file_header
.e_shnum
)
769 return _("<corrupt>");
771 return printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
774 /* Return a pointer to section NAME, or NULL if no such section exists. */
776 static Elf_Internal_Shdr
*
777 find_section (Filedata
* filedata
, const char * name
)
781 if (filedata
->section_headers
== NULL
)
784 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
785 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
786 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
788 return filedata
->section_headers
+ i
;
793 /* Return a pointer to a section containing ADDR, or NULL if no such
796 static Elf_Internal_Shdr
*
797 find_section_by_address (Filedata
* filedata
, bfd_vma addr
)
801 if (filedata
->section_headers
== NULL
)
804 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
806 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
808 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
815 static Elf_Internal_Shdr
*
816 find_section_by_type (Filedata
* filedata
, unsigned int type
)
820 if (filedata
->section_headers
== NULL
)
823 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
825 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
827 if (sec
->sh_type
== type
)
834 /* Return a pointer to section NAME, or NULL if no such section exists,
835 restricted to the list of sections given in SET. */
837 static Elf_Internal_Shdr
*
838 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
842 if (filedata
->section_headers
== NULL
)
847 while ((i
= *set
++) > 0)
849 /* See PR 21156 for a reproducer. */
850 if (i
>= filedata
->file_header
.e_shnum
)
851 continue; /* FIXME: Should we issue an error message ? */
853 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
854 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
856 return filedata
->section_headers
+ i
;
860 return find_section (filedata
, name
);
863 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
864 This OS has so many departures from the ELF standard that we test it at
868 is_ia64_vms (Filedata
* filedata
)
870 return filedata
->file_header
.e_machine
== EM_IA_64
871 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
874 /* Guess the relocation size commonly used by the specific machines. */
877 guess_is_rela (unsigned int e_machine
)
881 /* Targets that use REL relocations. */
898 /* Targets that use RELA relocations. */
902 case EM_ADAPTEVA_EPIPHANY
:
904 case EM_ALTERA_NIOS2
:
907 case EM_ARC_COMPACT2
:
928 case EM_LATTICEMICO32
:
937 case EM_CYGNUS_MN10200
:
939 case EM_CYGNUS_MN10300
:
975 case EM_MICROBLAZE_OLD
:
997 warn (_("Don't know about relocations on this machine architecture\n"));
1002 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1003 Returns TRUE upon success, FALSE otherwise. If successful then a
1004 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
1005 and the number of relocs loaded is placed in *NRELASP. It is the caller's
1006 responsibility to free the allocated buffer. */
1009 slurp_rela_relocs (Filedata
* filedata
,
1010 unsigned long rel_offset
,
1011 unsigned long rel_size
,
1012 Elf_Internal_Rela
** relasp
,
1013 unsigned long * nrelasp
)
1015 Elf_Internal_Rela
* relas
;
1021 Elf32_External_Rela
* erelas
;
1023 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1024 rel_size
, _("32-bit relocation data"));
1028 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
1030 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1031 sizeof (Elf_Internal_Rela
));
1036 error (_("out of memory parsing relocs\n"));
1040 for (i
= 0; i
< nrelas
; i
++)
1042 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1043 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1044 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1051 Elf64_External_Rela
* erelas
;
1053 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1054 rel_size
, _("64-bit relocation data"));
1058 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1060 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1061 sizeof (Elf_Internal_Rela
));
1066 error (_("out of memory parsing relocs\n"));
1070 for (i
= 0; i
< nrelas
; i
++)
1072 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1073 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1074 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1076 /* The #ifdef BFD64 below is to prevent a compile time
1077 warning. We know that if we do not have a 64 bit data
1078 type that we will never execute this code anyway. */
1080 if (filedata
->file_header
.e_machine
== EM_MIPS
1081 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1083 /* In little-endian objects, r_info isn't really a
1084 64-bit little-endian value: it has a 32-bit
1085 little-endian symbol index followed by four
1086 individual byte fields. Reorder INFO
1088 bfd_vma inf
= relas
[i
].r_info
;
1089 inf
= (((inf
& 0xffffffff) << 32)
1090 | ((inf
>> 56) & 0xff)
1091 | ((inf
>> 40) & 0xff00)
1092 | ((inf
>> 24) & 0xff0000)
1093 | ((inf
>> 8) & 0xff000000));
1094 relas
[i
].r_info
= inf
;
1107 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1108 Returns TRUE upon success, FALSE otherwise. If successful then a
1109 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1110 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1111 responsibility to free the allocated buffer. */
1114 slurp_rel_relocs (Filedata
* filedata
,
1115 unsigned long rel_offset
,
1116 unsigned long rel_size
,
1117 Elf_Internal_Rela
** relsp
,
1118 unsigned long * nrelsp
)
1120 Elf_Internal_Rela
* rels
;
1126 Elf32_External_Rel
* erels
;
1128 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1129 rel_size
, _("32-bit relocation data"));
1133 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1135 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1140 error (_("out of memory parsing relocs\n"));
1144 for (i
= 0; i
< nrels
; i
++)
1146 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1147 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1148 rels
[i
].r_addend
= 0;
1155 Elf64_External_Rel
* erels
;
1157 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1158 rel_size
, _("64-bit relocation data"));
1162 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1164 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1169 error (_("out of memory parsing relocs\n"));
1173 for (i
= 0; i
< nrels
; i
++)
1175 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1176 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1177 rels
[i
].r_addend
= 0;
1179 /* The #ifdef BFD64 below is to prevent a compile time
1180 warning. We know that if we do not have a 64 bit data
1181 type that we will never execute this code anyway. */
1183 if (filedata
->file_header
.e_machine
== EM_MIPS
1184 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1186 /* In little-endian objects, r_info isn't really a
1187 64-bit little-endian value: it has a 32-bit
1188 little-endian symbol index followed by four
1189 individual byte fields. Reorder INFO
1191 bfd_vma inf
= rels
[i
].r_info
;
1192 inf
= (((inf
& 0xffffffff) << 32)
1193 | ((inf
>> 56) & 0xff)
1194 | ((inf
>> 40) & 0xff00)
1195 | ((inf
>> 24) & 0xff0000)
1196 | ((inf
>> 8) & 0xff000000));
1197 rels
[i
].r_info
= inf
;
1210 /* Returns the reloc type extracted from the reloc info field. */
1213 get_reloc_type (Filedata
* filedata
, bfd_vma reloc_info
)
1216 return ELF32_R_TYPE (reloc_info
);
1218 switch (filedata
->file_header
.e_machine
)
1221 /* Note: We assume that reloc_info has already been adjusted for us. */
1222 return ELF64_MIPS_R_TYPE (reloc_info
);
1225 return ELF64_R_TYPE_ID (reloc_info
);
1228 return ELF64_R_TYPE (reloc_info
);
1232 /* Return the symbol index extracted from the reloc info field. */
1235 get_reloc_symindex (bfd_vma reloc_info
)
1237 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1241 uses_msp430x_relocs (Filedata
* filedata
)
1244 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1245 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1246 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1247 /* TI compiler uses ELFOSABI_NONE. */
1248 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1251 /* Display the contents of the relocation data found at the specified
1255 dump_relocations (Filedata
* filedata
,
1256 unsigned long rel_offset
,
1257 unsigned long rel_size
,
1258 Elf_Internal_Sym
* symtab
,
1259 unsigned long nsyms
,
1261 unsigned long strtablen
,
1266 Elf_Internal_Rela
* rels
;
1269 if (is_rela
== UNKNOWN
)
1270 is_rela
= guess_is_rela (filedata
->file_header
.e_machine
);
1274 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1279 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1288 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1290 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1295 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1297 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1305 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1307 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1312 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1314 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1318 for (i
= 0; i
< rel_size
; i
++)
1323 bfd_vma symtab_index
;
1326 offset
= rels
[i
].r_offset
;
1327 inf
= rels
[i
].r_info
;
1329 type
= get_reloc_type (filedata
, inf
);
1330 symtab_index
= get_reloc_symindex (inf
);
1334 printf ("%8.8lx %8.8lx ",
1335 (unsigned long) offset
& 0xffffffff,
1336 (unsigned long) inf
& 0xffffffff);
1341 ? "%16.16" BFD_VMA_FMT
"x %16.16" BFD_VMA_FMT
"x "
1342 : "%12.12" BFD_VMA_FMT
"x %12.12" BFD_VMA_FMT
"x ",
1346 switch (filedata
->file_header
.e_machine
)
1353 rtype
= elf_aarch64_reloc_type (type
);
1357 case EM_CYGNUS_M32R
:
1358 rtype
= elf_m32r_reloc_type (type
);
1363 rtype
= elf_i386_reloc_type (type
);
1368 rtype
= elf_m68hc11_reloc_type (type
);
1372 rtype
= elf_s12z_reloc_type (type
);
1376 rtype
= elf_m68k_reloc_type (type
);
1380 rtype
= elf_i960_reloc_type (type
);
1385 rtype
= elf_avr_reloc_type (type
);
1388 case EM_OLD_SPARCV9
:
1389 case EM_SPARC32PLUS
:
1392 rtype
= elf_sparc_reloc_type (type
);
1396 rtype
= elf_spu_reloc_type (type
);
1400 rtype
= v800_reloc_type (type
);
1403 case EM_CYGNUS_V850
:
1404 rtype
= v850_reloc_type (type
);
1408 case EM_CYGNUS_D10V
:
1409 rtype
= elf_d10v_reloc_type (type
);
1413 case EM_CYGNUS_D30V
:
1414 rtype
= elf_d30v_reloc_type (type
);
1418 rtype
= elf_dlx_reloc_type (type
);
1422 rtype
= elf_sh_reloc_type (type
);
1426 case EM_CYGNUS_MN10300
:
1427 rtype
= elf_mn10300_reloc_type (type
);
1431 case EM_CYGNUS_MN10200
:
1432 rtype
= elf_mn10200_reloc_type (type
);
1436 case EM_CYGNUS_FR30
:
1437 rtype
= elf_fr30_reloc_type (type
);
1441 rtype
= elf_frv_reloc_type (type
);
1445 rtype
= elf_csky_reloc_type (type
);
1449 rtype
= elf_ft32_reloc_type (type
);
1453 rtype
= elf_mcore_reloc_type (type
);
1457 rtype
= elf_mmix_reloc_type (type
);
1461 rtype
= elf_moxie_reloc_type (type
);
1465 if (uses_msp430x_relocs (filedata
))
1467 rtype
= elf_msp430x_reloc_type (type
);
1472 rtype
= elf_msp430_reloc_type (type
);
1476 rtype
= elf_nds32_reloc_type (type
);
1480 rtype
= elf_ppc_reloc_type (type
);
1484 rtype
= elf_ppc64_reloc_type (type
);
1488 case EM_MIPS_RS3_LE
:
1489 rtype
= elf_mips_reloc_type (type
);
1493 rtype
= elf_riscv_reloc_type (type
);
1497 rtype
= elf_alpha_reloc_type (type
);
1501 rtype
= elf_arm_reloc_type (type
);
1505 case EM_ARC_COMPACT
:
1506 case EM_ARC_COMPACT2
:
1507 rtype
= elf_arc_reloc_type (type
);
1511 rtype
= elf_hppa_reloc_type (type
);
1517 rtype
= elf_h8_reloc_type (type
);
1521 rtype
= elf_or1k_reloc_type (type
);
1526 rtype
= elf_pj_reloc_type (type
);
1529 rtype
= elf_ia64_reloc_type (type
);
1533 rtype
= elf_cris_reloc_type (type
);
1537 rtype
= elf_i860_reloc_type (type
);
1543 rtype
= elf_x86_64_reloc_type (type
);
1547 rtype
= i370_reloc_type (type
);
1552 rtype
= elf_s390_reloc_type (type
);
1556 rtype
= elf_score_reloc_type (type
);
1560 rtype
= elf_xstormy16_reloc_type (type
);
1564 rtype
= elf_crx_reloc_type (type
);
1568 rtype
= elf_vax_reloc_type (type
);
1572 rtype
= elf_visium_reloc_type (type
);
1576 rtype
= elf_bpf_reloc_type (type
);
1579 case EM_ADAPTEVA_EPIPHANY
:
1580 rtype
= elf_epiphany_reloc_type (type
);
1585 rtype
= elf_ip2k_reloc_type (type
);
1589 rtype
= elf_iq2000_reloc_type (type
);
1594 rtype
= elf_xtensa_reloc_type (type
);
1597 case EM_LATTICEMICO32
:
1598 rtype
= elf_lm32_reloc_type (type
);
1603 rtype
= elf_m32c_reloc_type (type
);
1607 rtype
= elf_mt_reloc_type (type
);
1611 rtype
= elf_bfin_reloc_type (type
);
1615 rtype
= elf_mep_reloc_type (type
);
1619 rtype
= elf_cr16_reloc_type (type
);
1623 case EM_MICROBLAZE_OLD
:
1624 rtype
= elf_microblaze_reloc_type (type
);
1628 rtype
= elf_rl78_reloc_type (type
);
1632 rtype
= elf_rx_reloc_type (type
);
1636 rtype
= elf_metag_reloc_type (type
);
1641 rtype
= elf_xc16x_reloc_type (type
);
1645 rtype
= elf_tic6x_reloc_type (type
);
1649 rtype
= elf_tilegx_reloc_type (type
);
1653 rtype
= elf_tilepro_reloc_type (type
);
1656 case EM_WEBASSEMBLY
:
1657 rtype
= elf_wasm32_reloc_type (type
);
1661 rtype
= elf_xgate_reloc_type (type
);
1664 case EM_ALTERA_NIOS2
:
1665 rtype
= elf_nios2_reloc_type (type
);
1669 rtype
= elf_pru_reloc_type (type
);
1673 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
1674 rtype
= elf_nfp3200_reloc_type (type
);
1676 rtype
= elf_nfp_reloc_type (type
);
1680 rtype
= elf_z80_reloc_type (type
);
1684 rtype
= elf_loongarch_reloc_type (type
);
1690 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1692 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
1694 if (filedata
->file_header
.e_machine
== EM_ALPHA
1696 && streq (rtype
, "R_ALPHA_LITUSE")
1699 switch (rels
[i
].r_addend
)
1701 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1702 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1703 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1704 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1705 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1706 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1707 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1708 default: rtype
= NULL
;
1712 printf (" (%s)", rtype
);
1716 printf (_("<unknown addend: %lx>"),
1717 (unsigned long) rels
[i
].r_addend
);
1721 else if (symtab_index
)
1723 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1725 error (_(" bad symbol index: %08lx in reloc\n"),
1726 (unsigned long) symtab_index
);
1731 Elf_Internal_Sym
* psym
;
1732 const char * version_string
;
1733 enum versioned_symbol_info sym_info
;
1734 unsigned short vna_other
;
1736 psym
= symtab
+ symtab_index
;
1739 = get_symbol_version_string (filedata
, is_dynsym
,
1748 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1752 unsigned int width
= is_32bit_elf
? 8 : 14;
1754 /* Relocations against GNU_IFUNC symbols do not use the value
1755 of the symbol as the address to relocate against. Instead
1756 they invoke the function named by the symbol and use its
1757 result as the address for relocation.
1759 To indicate this to the user, do not display the value of
1760 the symbol in the "Symbols's Value" field. Instead show
1761 its name followed by () as a hint that the symbol is
1765 || psym
->st_name
== 0
1766 || psym
->st_name
>= strtablen
)
1769 name
= strtab
+ psym
->st_name
;
1771 len
= print_symbol (width
, name
);
1773 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1775 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
1779 print_vma (psym
->st_value
, LONG_HEX
);
1781 printf (is_32bit_elf
? " " : " ");
1784 if (psym
->st_name
== 0)
1786 const char * sec_name
= "<null>";
1789 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1791 if (psym
->st_shndx
< filedata
->file_header
.e_shnum
)
1792 sec_name
= section_name_print (filedata
,
1793 filedata
->section_headers
1795 else if (psym
->st_shndx
== SHN_ABS
)
1797 else if (psym
->st_shndx
== SHN_COMMON
)
1798 sec_name
= "COMMON";
1799 else if ((filedata
->file_header
.e_machine
== EM_MIPS
1800 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1801 || (filedata
->file_header
.e_machine
== EM_TI_C6000
1802 && psym
->st_shndx
== SHN_TIC6X_SCOMMON
))
1803 sec_name
= "SCOMMON";
1804 else if (filedata
->file_header
.e_machine
== EM_MIPS
1805 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1806 sec_name
= "SUNDEF";
1807 else if ((filedata
->file_header
.e_machine
== EM_X86_64
1808 || filedata
->file_header
.e_machine
== EM_L1OM
1809 || filedata
->file_header
.e_machine
== EM_K1OM
)
1810 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1811 sec_name
= "LARGE_COMMON";
1812 else if (filedata
->file_header
.e_machine
== EM_IA_64
1813 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1814 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1815 sec_name
= "ANSI_COM";
1816 else if (is_ia64_vms (filedata
)
1817 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1818 sec_name
= "VMS_SYMVEC";
1821 sprintf (name_buf
, "<section 0x%x>",
1822 (unsigned int) psym
->st_shndx
);
1823 sec_name
= name_buf
;
1826 print_symbol (22, sec_name
);
1828 else if (strtab
== NULL
)
1829 printf (_("<string table index: %3ld>"), psym
->st_name
);
1830 else if (psym
->st_name
>= strtablen
)
1832 error (_("<corrupt string table index: %3ld>\n"),
1838 print_symbol (22, strtab
+ psym
->st_name
);
1840 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1846 bfd_vma off
= rels
[i
].r_addend
;
1848 if ((bfd_signed_vma
) off
< 0)
1849 printf (" - %" BFD_VMA_FMT
"x", - off
);
1851 printf (" + %" BFD_VMA_FMT
"x", off
);
1857 bfd_vma off
= rels
[i
].r_addend
;
1859 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
1860 if ((bfd_signed_vma
) off
< 0)
1861 printf ("-%" BFD_VMA_FMT
"x", - off
);
1863 printf ("%" BFD_VMA_FMT
"x", off
);
1866 if (filedata
->file_header
.e_machine
== EM_SPARCV9
1868 && streq (rtype
, "R_SPARC_OLO10"))
1869 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf
));
1874 if (! is_32bit_elf
&& filedata
->file_header
.e_machine
== EM_MIPS
)
1876 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (inf
);
1877 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (inf
);
1878 const char * rtype2
= elf_mips_reloc_type (type2
);
1879 const char * rtype3
= elf_mips_reloc_type (type3
);
1881 printf (" Type2: ");
1884 printf (_("unrecognized: %-7lx"),
1885 (unsigned long) type2
& 0xffffffff);
1887 printf ("%-17.17s", rtype2
);
1889 printf ("\n Type3: ");
1892 printf (_("unrecognized: %-7lx"),
1893 (unsigned long) type3
& 0xffffffff);
1895 printf ("%-17.17s", rtype3
);
1908 get_aarch64_dynamic_type (unsigned long type
)
1912 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
1913 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
1914 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
1921 get_mips_dynamic_type (unsigned long type
)
1925 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1926 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1927 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1928 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1929 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1930 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1931 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1932 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1933 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1934 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1935 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1936 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1937 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1938 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1939 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1940 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1941 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1942 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
1943 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1944 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1945 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1946 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1947 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1948 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1949 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1950 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1951 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1952 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1953 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1954 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1955 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1956 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1957 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1958 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1959 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1960 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1961 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1962 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1963 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1964 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1965 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1966 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1967 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1968 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1969 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
1970 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
1971 case DT_MIPS_XHASH
: return "MIPS_XHASH";
1978 get_sparc64_dynamic_type (unsigned long type
)
1982 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1989 get_ppc_dynamic_type (unsigned long type
)
1993 case DT_PPC_GOT
: return "PPC_GOT";
1994 case DT_PPC_OPT
: return "PPC_OPT";
2001 get_ppc64_dynamic_type (unsigned long type
)
2005 case DT_PPC64_GLINK
: return "PPC64_GLINK";
2006 case DT_PPC64_OPD
: return "PPC64_OPD";
2007 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
2008 case DT_PPC64_OPT
: return "PPC64_OPT";
2015 get_parisc_dynamic_type (unsigned long type
)
2019 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
2020 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
2021 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
2022 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
2023 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
2024 case DT_HP_PREINIT
: return "HP_PREINIT";
2025 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
2026 case DT_HP_NEEDED
: return "HP_NEEDED";
2027 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
2028 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
2029 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
2030 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
2031 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
2032 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
2033 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
2034 case DT_HP_FILTERED
: return "HP_FILTERED";
2035 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
2036 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
2037 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
2038 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
2039 case DT_PLT
: return "PLT";
2040 case DT_PLT_SIZE
: return "PLT_SIZE";
2041 case DT_DLT
: return "DLT";
2042 case DT_DLT_SIZE
: return "DLT_SIZE";
2049 get_ia64_dynamic_type (unsigned long type
)
2053 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
2054 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
2055 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
2056 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
2057 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
2058 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
2059 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
2060 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
2061 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
2062 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
2063 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
2064 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
2065 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
2066 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
2067 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
2068 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
2069 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
2070 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
2071 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
2072 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
2073 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
2074 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
2075 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
2076 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
2077 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
2078 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
2079 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
2080 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
2081 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
2082 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
2083 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
2090 get_solaris_section_type (unsigned long type
)
2094 case 0x6fffffee: return "SUNW_ancillary";
2095 case 0x6fffffef: return "SUNW_capchain";
2096 case 0x6ffffff0: return "SUNW_capinfo";
2097 case 0x6ffffff1: return "SUNW_symsort";
2098 case 0x6ffffff2: return "SUNW_tlssort";
2099 case 0x6ffffff3: return "SUNW_LDYNSYM";
2100 case 0x6ffffff4: return "SUNW_dof";
2101 case 0x6ffffff5: return "SUNW_cap";
2102 case 0x6ffffff6: return "SUNW_SIGNATURE";
2103 case 0x6ffffff7: return "SUNW_ANNOTATE";
2104 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2105 case 0x6ffffff9: return "SUNW_DEBUG";
2106 case 0x6ffffffa: return "SUNW_move";
2107 case 0x6ffffffb: return "SUNW_COMDAT";
2108 case 0x6ffffffc: return "SUNW_syminfo";
2109 case 0x6ffffffd: return "SUNW_verdef";
2110 case 0x6ffffffe: return "SUNW_verneed";
2111 case 0x6fffffff: return "SUNW_versym";
2112 case 0x70000000: return "SPARC_GOTDATA";
2113 default: return NULL
;
2118 get_alpha_dynamic_type (unsigned long type
)
2122 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
2123 default: return NULL
;
2128 get_score_dynamic_type (unsigned long type
)
2132 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
2133 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
2134 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
2135 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
2136 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
2137 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
2138 default: return NULL
;
2143 get_tic6x_dynamic_type (unsigned long type
)
2147 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
2148 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
2149 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
2150 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
2151 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
2152 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
2153 default: return NULL
;
2158 get_nios2_dynamic_type (unsigned long type
)
2162 case DT_NIOS2_GP
: return "NIOS2_GP";
2163 default: return NULL
;
2168 get_solaris_dynamic_type (unsigned long type
)
2172 case 0x6000000d: return "SUNW_AUXILIARY";
2173 case 0x6000000e: return "SUNW_RTLDINF";
2174 case 0x6000000f: return "SUNW_FILTER";
2175 case 0x60000010: return "SUNW_CAP";
2176 case 0x60000011: return "SUNW_SYMTAB";
2177 case 0x60000012: return "SUNW_SYMSZ";
2178 case 0x60000013: return "SUNW_SORTENT";
2179 case 0x60000014: return "SUNW_SYMSORT";
2180 case 0x60000015: return "SUNW_SYMSORTSZ";
2181 case 0x60000016: return "SUNW_TLSSORT";
2182 case 0x60000017: return "SUNW_TLSSORTSZ";
2183 case 0x60000018: return "SUNW_CAPINFO";
2184 case 0x60000019: return "SUNW_STRPAD";
2185 case 0x6000001a: return "SUNW_CAPCHAIN";
2186 case 0x6000001b: return "SUNW_LDMACH";
2187 case 0x6000001d: return "SUNW_CAPCHAINENT";
2188 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2189 case 0x60000021: return "SUNW_PARENT";
2190 case 0x60000023: return "SUNW_ASLR";
2191 case 0x60000025: return "SUNW_RELAX";
2192 case 0x60000029: return "SUNW_NXHEAP";
2193 case 0x6000002b: return "SUNW_NXSTACK";
2195 case 0x70000001: return "SPARC_REGISTER";
2196 case 0x7ffffffd: return "AUXILIARY";
2197 case 0x7ffffffe: return "USED";
2198 case 0x7fffffff: return "FILTER";
2200 default: return NULL
;
2205 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
2207 static char buff
[64];
2211 case DT_NULL
: return "NULL";
2212 case DT_NEEDED
: return "NEEDED";
2213 case DT_PLTRELSZ
: return "PLTRELSZ";
2214 case DT_PLTGOT
: return "PLTGOT";
2215 case DT_HASH
: return "HASH";
2216 case DT_STRTAB
: return "STRTAB";
2217 case DT_SYMTAB
: return "SYMTAB";
2218 case DT_RELA
: return "RELA";
2219 case DT_RELASZ
: return "RELASZ";
2220 case DT_RELAENT
: return "RELAENT";
2221 case DT_STRSZ
: return "STRSZ";
2222 case DT_SYMENT
: return "SYMENT";
2223 case DT_INIT
: return "INIT";
2224 case DT_FINI
: return "FINI";
2225 case DT_SONAME
: return "SONAME";
2226 case DT_RPATH
: return "RPATH";
2227 case DT_SYMBOLIC
: return "SYMBOLIC";
2228 case DT_REL
: return "REL";
2229 case DT_RELSZ
: return "RELSZ";
2230 case DT_RELENT
: return "RELENT";
2231 case DT_PLTREL
: return "PLTREL";
2232 case DT_DEBUG
: return "DEBUG";
2233 case DT_TEXTREL
: return "TEXTREL";
2234 case DT_JMPREL
: return "JMPREL";
2235 case DT_BIND_NOW
: return "BIND_NOW";
2236 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2237 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2238 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2239 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2240 case DT_RUNPATH
: return "RUNPATH";
2241 case DT_FLAGS
: return "FLAGS";
2243 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2244 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2245 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2247 case DT_CHECKSUM
: return "CHECKSUM";
2248 case DT_PLTPADSZ
: return "PLTPADSZ";
2249 case DT_MOVEENT
: return "MOVEENT";
2250 case DT_MOVESZ
: return "MOVESZ";
2251 case DT_FEATURE
: return "FEATURE";
2252 case DT_POSFLAG_1
: return "POSFLAG_1";
2253 case DT_SYMINSZ
: return "SYMINSZ";
2254 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2256 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2257 case DT_CONFIG
: return "CONFIG";
2258 case DT_DEPAUDIT
: return "DEPAUDIT";
2259 case DT_AUDIT
: return "AUDIT";
2260 case DT_PLTPAD
: return "PLTPAD";
2261 case DT_MOVETAB
: return "MOVETAB";
2262 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2264 case DT_VERSYM
: return "VERSYM";
2266 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2267 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2268 case DT_RELACOUNT
: return "RELACOUNT";
2269 case DT_RELCOUNT
: return "RELCOUNT";
2270 case DT_FLAGS_1
: return "FLAGS_1";
2271 case DT_VERDEF
: return "VERDEF";
2272 case DT_VERDEFNUM
: return "VERDEFNUM";
2273 case DT_VERNEED
: return "VERNEED";
2274 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2276 case DT_AUXILIARY
: return "AUXILIARY";
2277 case DT_USED
: return "USED";
2278 case DT_FILTER
: return "FILTER";
2280 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2281 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2282 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2283 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2284 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2285 case DT_GNU_HASH
: return "GNU_HASH";
2286 case DT_GNU_FLAGS_1
: return "GNU_FLAGS_1";
2289 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2291 const char * result
;
2293 switch (filedata
->file_header
.e_machine
)
2296 result
= get_aarch64_dynamic_type (type
);
2299 case EM_MIPS_RS3_LE
:
2300 result
= get_mips_dynamic_type (type
);
2303 result
= get_sparc64_dynamic_type (type
);
2306 result
= get_ppc_dynamic_type (type
);
2309 result
= get_ppc64_dynamic_type (type
);
2312 result
= get_ia64_dynamic_type (type
);
2315 result
= get_alpha_dynamic_type (type
);
2318 result
= get_score_dynamic_type (type
);
2321 result
= get_tic6x_dynamic_type (type
);
2323 case EM_ALTERA_NIOS2
:
2324 result
= get_nios2_dynamic_type (type
);
2327 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2328 result
= get_solaris_dynamic_type (type
);
2337 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2339 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2340 || (filedata
->file_header
.e_machine
== EM_PARISC
2341 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2343 const char * result
;
2345 switch (filedata
->file_header
.e_machine
)
2348 result
= get_parisc_dynamic_type (type
);
2351 result
= get_ia64_dynamic_type (type
);
2354 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2355 result
= get_solaris_dynamic_type (type
);
2364 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2368 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2374 static bool get_program_headers (Filedata
*);
2375 static bool get_dynamic_section (Filedata
*);
2378 locate_dynamic_section (Filedata
*filedata
)
2380 unsigned long dynamic_addr
= 0;
2381 bfd_size_type dynamic_size
= 0;
2383 if (filedata
->file_header
.e_phnum
!= 0
2384 && get_program_headers (filedata
))
2386 Elf_Internal_Phdr
*segment
;
2389 for (i
= 0, segment
= filedata
->program_headers
;
2390 i
< filedata
->file_header
.e_phnum
;
2393 if (segment
->p_type
== PT_DYNAMIC
)
2395 dynamic_addr
= segment
->p_offset
;
2396 dynamic_size
= segment
->p_filesz
;
2398 if (filedata
->section_headers
!= NULL
)
2400 Elf_Internal_Shdr
*sec
;
2402 sec
= find_section (filedata
, ".dynamic");
2405 if (sec
->sh_size
== 0
2406 || sec
->sh_type
== SHT_NOBITS
)
2413 dynamic_addr
= sec
->sh_offset
;
2414 dynamic_size
= sec
->sh_size
;
2419 if (dynamic_addr
> filedata
->file_size
2420 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
2429 filedata
->dynamic_addr
= dynamic_addr
;
2430 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
2434 is_pie (Filedata
*filedata
)
2436 Elf_Internal_Dyn
*entry
;
2438 if (filedata
->dynamic_size
== 0)
2439 locate_dynamic_section (filedata
);
2440 if (filedata
->dynamic_size
<= 1)
2443 if (!get_dynamic_section (filedata
))
2446 for (entry
= filedata
->dynamic_section
;
2447 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
2450 if (entry
->d_tag
== DT_FLAGS_1
)
2452 if ((entry
->d_un
.d_val
& DF_1_PIE
) != 0)
2461 get_file_type (Filedata
*filedata
)
2463 unsigned e_type
= filedata
->file_header
.e_type
;
2464 static char buff
[64];
2468 case ET_NONE
: return _("NONE (None)");
2469 case ET_REL
: return _("REL (Relocatable file)");
2470 case ET_EXEC
: return _("EXEC (Executable file)");
2472 if (is_pie (filedata
))
2473 return _("DYN (Position-Independent Executable file)");
2475 return _("DYN (Shared object file)");
2476 case ET_CORE
: return _("CORE (Core file)");
2479 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2480 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2481 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2482 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2484 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2490 get_machine_name (unsigned e_machine
)
2492 static char buff
[64]; /* XXX */
2496 /* Please keep this switch table sorted by increasing EM_ value. */
2498 case EM_NONE
: return _("None");
2499 case EM_M32
: return "WE32100";
2500 case EM_SPARC
: return "Sparc";
2501 case EM_386
: return "Intel 80386";
2502 case EM_68K
: return "MC68000";
2503 case EM_88K
: return "MC88000";
2504 case EM_IAMCU
: return "Intel MCU";
2505 case EM_860
: return "Intel 80860";
2506 case EM_MIPS
: return "MIPS R3000";
2507 case EM_S370
: return "IBM System/370";
2509 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2510 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2511 case EM_PARISC
: return "HPPA";
2512 case EM_VPP550
: return "Fujitsu VPP500";
2513 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2514 case EM_960
: return "Intel 80960";
2515 case EM_PPC
: return "PowerPC";
2517 case EM_PPC64
: return "PowerPC64";
2519 case EM_S390
: return "IBM S/390";
2520 case EM_SPU
: return "SPU";
2522 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2523 case EM_FR20
: return "Fujitsu FR20";
2524 case EM_RH32
: return "TRW RH32";
2525 case EM_MCORE
: return "MCORE";
2527 case EM_ARM
: return "ARM";
2528 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2529 case EM_SH
: return "Renesas / SuperH SH";
2530 case EM_SPARCV9
: return "Sparc v9";
2531 case EM_TRICORE
: return "Siemens Tricore";
2532 case EM_ARC
: return "ARC";
2533 case EM_H8_300
: return "Renesas H8/300";
2534 case EM_H8_300H
: return "Renesas H8/300H";
2535 case EM_H8S
: return "Renesas H8S";
2536 case EM_H8_500
: return "Renesas H8/500";
2538 case EM_IA_64
: return "Intel IA-64";
2539 case EM_MIPS_X
: return "Stanford MIPS-X";
2540 case EM_COLDFIRE
: return "Motorola Coldfire";
2541 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2542 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2543 case EM_PCP
: return "Siemens PCP";
2544 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2545 case EM_NDR1
: return "Denso NDR1 microprocesspr";
2546 case EM_STARCORE
: return "Motorola Star*Core processor";
2547 case EM_ME16
: return "Toyota ME16 processor";
2549 case EM_ST100
: return "STMicroelectronics ST100 processor";
2550 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2551 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2552 case EM_PDSP
: return "Sony DSP processor";
2553 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2554 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2555 case EM_FX66
: return "Siemens FX66 microcontroller";
2556 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2557 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2558 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2560 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2561 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2562 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2563 case EM_SVX
: return "Silicon Graphics SVx";
2564 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2565 case EM_VAX
: return "Digital VAX";
2566 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2567 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2568 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2569 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2571 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2572 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2573 case EM_PRISM
: return "Vitesse Prism";
2575 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2576 case EM_CYGNUS_FR30
:
2577 case EM_FR30
: return "Fujitsu FR30";
2578 case EM_CYGNUS_D10V
:
2579 case EM_D10V
: return "d10v";
2580 case EM_CYGNUS_D30V
:
2581 case EM_D30V
: return "d30v";
2582 case EM_CYGNUS_V850
:
2583 case EM_V850
: return "Renesas V850";
2584 case EM_CYGNUS_M32R
:
2585 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2586 case EM_CYGNUS_MN10300
:
2587 case EM_MN10300
: return "mn10300";
2589 case EM_CYGNUS_MN10200
:
2590 case EM_MN10200
: return "mn10200";
2591 case EM_PJ
: return "picoJava";
2592 case EM_OR1K
: return "OpenRISC 1000";
2593 case EM_ARC_COMPACT
: return "ARCompact";
2595 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2596 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2597 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2598 case EM_NS32K
: return "National Semiconductor 32000 series";
2599 case EM_TPC
: return "Tenor Network TPC processor";
2600 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2602 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2604 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2605 case EM_MAX
: return "MAX Processor";
2606 case EM_CR
: return "National Semiconductor CompactRISC";
2607 case EM_F2MC16
: return "Fujitsu F2MC16";
2608 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2609 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2610 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2611 case EM_SEP
: return "Sharp embedded microprocessor";
2612 case EM_ARCA
: return "Arca RISC microprocessor";
2614 case EM_UNICORE
: return "Unicore";
2615 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2616 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2617 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2618 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2619 case EM_XGATE
: return "Motorola XGATE embedded processor";
2621 case EM_XC16X
: return "Infineon Technologies xc16x";
2622 case EM_M16C
: return "Renesas M16C series microprocessors";
2623 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2624 case EM_CE
: return "Freescale Communication Engine RISC core";
2626 case EM_M32C
: return "Renesas M32c";
2628 case EM_TSK3000
: return "Altium TSK3000 core";
2629 case EM_RS08
: return "Freescale RS08 embedded processor";
2630 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2631 case EM_SCORE
: return "SUNPLUS S+Core";
2632 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2633 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2634 case EM_LATTICEMICO32
: return "Lattice Mico32";
2635 case EM_SE_C17
: return "Seiko Epson C17 family";
2637 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2638 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2639 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2640 case EM_TI_PRU
: return "TI PRU I/O processor";
2642 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2643 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2644 case EM_R32C
: return "Renesas R32C series microprocessors";
2645 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2646 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2647 case EM_8051
: return "Intel 8051 and variants";
2648 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2649 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2650 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2651 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2653 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
2654 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
2655 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
2656 case EM_RX
: return "Renesas RX";
2657 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
2658 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
2659 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
2662 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
2663 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
2664 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
2666 case EM_L1OM
: return "Intel L1OM";
2667 case EM_K1OM
: return "Intel K1OM";
2668 case EM_INTEL182
: return "Intel (reserved)";
2669 case EM_AARCH64
: return "AArch64";
2670 case EM_ARM184
: return "ARM (reserved)";
2671 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
2672 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
2673 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
2674 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
2676 case EM_CUDA
: return "NVIDIA CUDA architecture";
2677 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
2678 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
2679 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
2680 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
2681 case EM_ARC_COMPACT2
: return "ARCv2";
2682 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
2683 case EM_RL78
: return "Renesas RL78";
2684 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
2685 case EM_78K0R
: return "Renesas 78K0R";
2687 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
2688 case EM_BA1
: return "Beyond BA1 CPU architecture";
2689 case EM_BA2
: return "Beyond BA2 CPU architecture";
2690 case EM_XCORE
: return "XMOS xCORE processor family";
2691 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
2692 case EM_INTELGT
: return "Intel Graphics Technology";
2694 case EM_KM32
: return "KM211 KM32 32-bit processor";
2695 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
2696 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
2697 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
2698 case EM_KVARC
: return "KM211 KVARC processor";
2699 case EM_CDP
: return "Paneve CDP architecture family";
2700 case EM_COGE
: return "Cognitive Smart Memory Processor";
2701 case EM_COOL
: return "Bluechip Systems CoolEngine";
2702 case EM_NORC
: return "Nanoradio Optimized RISC";
2703 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
2705 case EM_Z80
: return "Zilog Z80";
2706 case EM_VISIUM
: return "CDS VISIUMcore processor";
2707 case EM_FT32
: return "FTDI Chip FT32";
2708 case EM_MOXIE
: return "Moxie";
2709 case EM_AMDGPU
: return "AMD GPU";
2710 /* 230 (all reserved) */
2712 case EM_RISCV
: return "RISC-V";
2713 case EM_LANAI
: return "Lanai 32-bit processor";
2714 case EM_CEVA
: return "CEVA Processor Architecture Family";
2715 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
2716 case EM_BPF
: return "Linux BPF";
2717 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
2718 case EM_IMG1
: return "Imagination Technologies";
2720 case EM_NFP
: return "Netronome Flow Processor";
2721 case EM_VE
: return "NEC Vector Engine";
2722 case EM_CSKY
: return "C-SKY";
2723 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv2.3 64-bit";
2724 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
2725 case EM_ARC_COMPACT3
: return "Synopsys ARCv2.3 32-bit";
2726 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
2727 case EM_65816
: return "WDC 65816/65C816";
2728 case EM_LOONGARCH
: return "LoongArch";
2729 case EM_KF32
: return "ChipON KungFu32";
2731 /* Large numbers... */
2732 case EM_MT
: return "Morpho Techologies MT processor";
2733 case EM_ALPHA
: return "Alpha";
2734 case EM_WEBASSEMBLY
: return "Web Assembly";
2735 case EM_DLX
: return "OpenDLX";
2736 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
2737 case EM_IQ2000
: return "Vitesse IQ2000";
2739 case EM_NIOS32
: return "Altera Nios";
2740 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
2741 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
2742 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
2743 case EM_S12Z
: return "Freescale S12Z";
2746 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
2752 decode_ARC_machine_flags (unsigned e_flags
, unsigned e_machine
, char buf
[])
2754 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2755 other compilers don't specify an architecture type in the e_flags, and
2756 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2757 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2760 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2761 but also sets a specific architecture type in the e_flags field.
2763 However, when decoding the flags we don't worry if we see an
2764 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2765 ARCEM architecture type. */
2767 switch (e_flags
& EF_ARC_MACH_MSK
)
2769 /* We only expect these to occur for EM_ARC_COMPACT2. */
2770 case EF_ARC_CPU_ARCV2EM
:
2771 strcat (buf
, ", ARC EM");
2773 case EF_ARC_CPU_ARCV2HS
:
2774 strcat (buf
, ", ARC HS");
2777 /* We only expect these to occur for EM_ARC_COMPACT. */
2778 case E_ARC_MACH_ARC600
:
2779 strcat (buf
, ", ARC600");
2781 case E_ARC_MACH_ARC601
:
2782 strcat (buf
, ", ARC601");
2784 case E_ARC_MACH_ARC700
:
2785 strcat (buf
, ", ARC700");
2788 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2789 new ELF with new architecture being read by an old version of
2790 readelf, or (c) An ELF built with non-GNU compiler that does not
2791 set the architecture in the e_flags. */
2793 if (e_machine
== EM_ARC_COMPACT
)
2794 strcat (buf
, ", Unknown ARCompact");
2796 strcat (buf
, ", Unknown ARC");
2800 switch (e_flags
& EF_ARC_OSABI_MSK
)
2802 case E_ARC_OSABI_ORIG
:
2803 strcat (buf
, ", (ABI:legacy)");
2805 case E_ARC_OSABI_V2
:
2806 strcat (buf
, ", (ABI:v2)");
2808 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2809 case E_ARC_OSABI_V3
:
2810 strcat (buf
, ", v3 no-legacy-syscalls ABI");
2812 case E_ARC_OSABI_V4
:
2813 strcat (buf
, ", v4 ABI");
2816 strcat (buf
, ", unrecognised ARC OSABI flag");
2822 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
2825 bool unknown
= false;
2827 eabi
= EF_ARM_EABI_VERSION (e_flags
);
2828 e_flags
&= ~ EF_ARM_EABIMASK
;
2830 /* Handle "generic" ARM flags. */
2831 if (e_flags
& EF_ARM_RELEXEC
)
2833 strcat (buf
, ", relocatable executable");
2834 e_flags
&= ~ EF_ARM_RELEXEC
;
2837 if (e_flags
& EF_ARM_PIC
)
2839 strcat (buf
, ", position independent");
2840 e_flags
&= ~ EF_ARM_PIC
;
2843 /* Now handle EABI specific flags. */
2847 strcat (buf
, ", <unrecognized EABI>");
2852 case EF_ARM_EABI_VER1
:
2853 strcat (buf
, ", Version1 EABI");
2858 /* Process flags one bit at a time. */
2859 flag
= e_flags
& - e_flags
;
2864 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2865 strcat (buf
, ", sorted symbol tables");
2875 case EF_ARM_EABI_VER2
:
2876 strcat (buf
, ", Version2 EABI");
2881 /* Process flags one bit at a time. */
2882 flag
= e_flags
& - e_flags
;
2887 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2888 strcat (buf
, ", sorted symbol tables");
2891 case EF_ARM_DYNSYMSUSESEGIDX
:
2892 strcat (buf
, ", dynamic symbols use segment index");
2895 case EF_ARM_MAPSYMSFIRST
:
2896 strcat (buf
, ", mapping symbols precede others");
2906 case EF_ARM_EABI_VER3
:
2907 strcat (buf
, ", Version3 EABI");
2910 case EF_ARM_EABI_VER4
:
2911 strcat (buf
, ", Version4 EABI");
2916 /* Process flags one bit at a time. */
2917 flag
= e_flags
& - e_flags
;
2923 strcat (buf
, ", BE8");
2927 strcat (buf
, ", LE8");
2937 case EF_ARM_EABI_VER5
:
2938 strcat (buf
, ", Version5 EABI");
2943 /* Process flags one bit at a time. */
2944 flag
= e_flags
& - e_flags
;
2950 strcat (buf
, ", BE8");
2954 strcat (buf
, ", LE8");
2957 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2958 strcat (buf
, ", soft-float ABI");
2961 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
2962 strcat (buf
, ", hard-float ABI");
2972 case EF_ARM_EABI_UNKNOWN
:
2973 strcat (buf
, ", GNU EABI");
2978 /* Process flags one bit at a time. */
2979 flag
= e_flags
& - e_flags
;
2984 case EF_ARM_INTERWORK
:
2985 strcat (buf
, ", interworking enabled");
2988 case EF_ARM_APCS_26
:
2989 strcat (buf
, ", uses APCS/26");
2992 case EF_ARM_APCS_FLOAT
:
2993 strcat (buf
, ", uses APCS/float");
2997 strcat (buf
, ", position independent");
3001 strcat (buf
, ", 8 bit structure alignment");
3004 case EF_ARM_NEW_ABI
:
3005 strcat (buf
, ", uses new ABI");
3008 case EF_ARM_OLD_ABI
:
3009 strcat (buf
, ", uses old ABI");
3012 case EF_ARM_SOFT_FLOAT
:
3013 strcat (buf
, ", software FP");
3016 case EF_ARM_VFP_FLOAT
:
3017 strcat (buf
, ", VFP");
3020 case EF_ARM_MAVERICK_FLOAT
:
3021 strcat (buf
, ", Maverick FP");
3032 strcat (buf
,_(", <unknown>"));
3036 decode_AVR_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
3038 --size
; /* Leave space for null terminator. */
3040 switch (e_flags
& EF_AVR_MACH
)
3042 case E_AVR_MACH_AVR1
:
3043 strncat (buf
, ", avr:1", size
);
3045 case E_AVR_MACH_AVR2
:
3046 strncat (buf
, ", avr:2", size
);
3048 case E_AVR_MACH_AVR25
:
3049 strncat (buf
, ", avr:25", size
);
3051 case E_AVR_MACH_AVR3
:
3052 strncat (buf
, ", avr:3", size
);
3054 case E_AVR_MACH_AVR31
:
3055 strncat (buf
, ", avr:31", size
);
3057 case E_AVR_MACH_AVR35
:
3058 strncat (buf
, ", avr:35", size
);
3060 case E_AVR_MACH_AVR4
:
3061 strncat (buf
, ", avr:4", size
);
3063 case E_AVR_MACH_AVR5
:
3064 strncat (buf
, ", avr:5", size
);
3066 case E_AVR_MACH_AVR51
:
3067 strncat (buf
, ", avr:51", size
);
3069 case E_AVR_MACH_AVR6
:
3070 strncat (buf
, ", avr:6", size
);
3072 case E_AVR_MACH_AVRTINY
:
3073 strncat (buf
, ", avr:100", size
);
3075 case E_AVR_MACH_XMEGA1
:
3076 strncat (buf
, ", avr:101", size
);
3078 case E_AVR_MACH_XMEGA2
:
3079 strncat (buf
, ", avr:102", size
);
3081 case E_AVR_MACH_XMEGA3
:
3082 strncat (buf
, ", avr:103", size
);
3084 case E_AVR_MACH_XMEGA4
:
3085 strncat (buf
, ", avr:104", size
);
3087 case E_AVR_MACH_XMEGA5
:
3088 strncat (buf
, ", avr:105", size
);
3090 case E_AVR_MACH_XMEGA6
:
3091 strncat (buf
, ", avr:106", size
);
3093 case E_AVR_MACH_XMEGA7
:
3094 strncat (buf
, ", avr:107", size
);
3097 strncat (buf
, ", avr:<unknown>", size
);
3101 size
-= strlen (buf
);
3102 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
3103 strncat (buf
, ", link-relax", size
);
3107 decode_NDS32_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
3113 bool has_fpu
= false;
3116 static const char *ABI_STRINGS
[] =
3118 "ABI v0", /* use r5 as return register; only used in N1213HC */
3119 "ABI v1", /* use r0 as return register */
3120 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
3121 "ABI v2fp", /* for FPU */
3125 static const char *VER_STRINGS
[] =
3127 "Andes ELF V1.3 or older",
3131 static const char *ARCH_STRINGS
[] =
3140 abi
= EF_NDS_ABI
& e_flags
;
3141 arch
= EF_NDS_ARCH
& e_flags
;
3142 config
= EF_NDS_INST
& e_flags
;
3143 version
= EF_NDS32_ELF_VERSION
& e_flags
;
3145 memset (buf
, 0, size
);
3152 case E_NDS_ABI_V2FP
:
3153 case E_NDS_ABI_AABI
:
3154 case E_NDS_ABI_V2FP_PLUS
:
3155 /* In case there are holes in the array. */
3156 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
3160 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ABI>");
3166 case E_NDS32_ELF_VER_1_2
:
3167 case E_NDS32_ELF_VER_1_3
:
3168 case E_NDS32_ELF_VER_1_4
:
3169 r
+= snprintf (buf
+ r
, size
- r
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
3173 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ELF version number>");
3177 if (E_NDS_ABI_V0
== abi
)
3179 /* OLD ABI; only used in N1213HC, has performance extension 1. */
3180 r
+= snprintf (buf
+ r
, size
- r
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
3181 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3182 r
+= snprintf (buf
+ r
, size
-r
, ", 16b"); /* has 16-bit instructions */
3188 case E_NDS_ARCH_STAR_V1_0
:
3189 case E_NDS_ARCH_STAR_V2_0
:
3190 case E_NDS_ARCH_STAR_V3_0
:
3191 case E_NDS_ARCH_STAR_V3_M
:
3192 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
3196 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized architecture>");
3197 /* ARCH version determines how the e_flags are interpreted.
3198 If it is unknown, we cannot proceed. */
3202 /* Newer ABI; Now handle architecture specific flags. */
3203 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3205 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3206 r
+= snprintf (buf
+ r
, size
-r
, ", MFUSR_PC");
3208 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
3209 r
+= snprintf (buf
+ r
, size
-r
, ", MAC");
3211 if (config
& E_NDS32_HAS_DIV_INST
)
3212 r
+= snprintf (buf
+ r
, size
-r
, ", DIV");
3214 if (config
& E_NDS32_HAS_16BIT_INST
)
3215 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3219 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3221 if (version
<= E_NDS32_ELF_VER_1_3
)
3222 r
+= snprintf (buf
+ r
, size
-r
, ", [B8]");
3224 r
+= snprintf (buf
+ r
, size
-r
, ", EX9");
3227 if (config
& E_NDS32_HAS_MAC_DX_INST
)
3228 r
+= snprintf (buf
+ r
, size
-r
, ", MAC_DX");
3230 if (config
& E_NDS32_HAS_DIV_DX_INST
)
3231 r
+= snprintf (buf
+ r
, size
-r
, ", DIV_DX");
3233 if (config
& E_NDS32_HAS_16BIT_INST
)
3235 if (version
<= E_NDS32_ELF_VER_1_3
)
3236 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3238 r
+= snprintf (buf
+ r
, size
-r
, ", IFC");
3242 if (config
& E_NDS32_HAS_EXT_INST
)
3243 r
+= snprintf (buf
+ r
, size
-r
, ", PERF1");
3245 if (config
& E_NDS32_HAS_EXT2_INST
)
3246 r
+= snprintf (buf
+ r
, size
-r
, ", PERF2");
3248 if (config
& E_NDS32_HAS_FPU_INST
)
3251 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_SP");
3254 if (config
& E_NDS32_HAS_FPU_DP_INST
)
3257 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_DP");
3260 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
3263 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_MAC");
3268 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
3270 case E_NDS32_FPU_REG_8SP_4DP
:
3271 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:8/4");
3273 case E_NDS32_FPU_REG_16SP_8DP
:
3274 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:16/8");
3276 case E_NDS32_FPU_REG_32SP_16DP
:
3277 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/16");
3279 case E_NDS32_FPU_REG_32SP_32DP
:
3280 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/32");
3285 if (config
& E_NDS32_HAS_AUDIO_INST
)
3286 r
+= snprintf (buf
+ r
, size
-r
, ", AUDIO");
3288 if (config
& E_NDS32_HAS_STRING_INST
)
3289 r
+= snprintf (buf
+ r
, size
-r
, ", STR");
3291 if (config
& E_NDS32_HAS_REDUCED_REGS
)
3292 r
+= snprintf (buf
+ r
, size
-r
, ", 16REG");
3294 if (config
& E_NDS32_HAS_VIDEO_INST
)
3296 if (version
<= E_NDS32_ELF_VER_1_3
)
3297 r
+= snprintf (buf
+ r
, size
-r
, ", VIDEO");
3299 r
+= snprintf (buf
+ r
, size
-r
, ", SATURATION");
3302 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
3303 r
+= snprintf (buf
+ r
, size
-r
, ", ENCRP");
3305 if (config
& E_NDS32_HAS_L2C_INST
)
3306 r
+= snprintf (buf
+ r
, size
-r
, ", L2C");
3310 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
3312 static char buf
[1024];
3323 case EM_ARC_COMPACT2
:
3324 case EM_ARC_COMPACT
:
3325 decode_ARC_machine_flags (e_flags
, e_machine
, buf
);
3329 decode_ARM_machine_flags (e_flags
, buf
);
3333 decode_AVR_machine_flags (e_flags
, buf
, sizeof buf
);
3337 if (e_flags
& EF_BFIN_PIC
)
3338 strcat (buf
, ", PIC");
3340 if (e_flags
& EF_BFIN_FDPIC
)
3341 strcat (buf
, ", FDPIC");
3343 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3344 strcat (buf
, ", code in L1");
3346 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3347 strcat (buf
, ", data in L1");
3352 switch (e_flags
& EF_FRV_CPU_MASK
)
3354 case EF_FRV_CPU_GENERIC
:
3358 strcat (buf
, ", fr???");
3361 case EF_FRV_CPU_FR300
:
3362 strcat (buf
, ", fr300");
3365 case EF_FRV_CPU_FR400
:
3366 strcat (buf
, ", fr400");
3368 case EF_FRV_CPU_FR405
:
3369 strcat (buf
, ", fr405");
3372 case EF_FRV_CPU_FR450
:
3373 strcat (buf
, ", fr450");
3376 case EF_FRV_CPU_FR500
:
3377 strcat (buf
, ", fr500");
3379 case EF_FRV_CPU_FR550
:
3380 strcat (buf
, ", fr550");
3383 case EF_FRV_CPU_SIMPLE
:
3384 strcat (buf
, ", simple");
3386 case EF_FRV_CPU_TOMCAT
:
3387 strcat (buf
, ", tomcat");
3393 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3394 strcat (buf
, ", m68000");
3395 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3396 strcat (buf
, ", cpu32");
3397 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3398 strcat (buf
, ", fido_a");
3401 char const * isa
= _("unknown");
3402 char const * mac
= _("unknown mac");
3403 char const * additional
= NULL
;
3405 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3407 case EF_M68K_CF_ISA_A_NODIV
:
3409 additional
= ", nodiv";
3411 case EF_M68K_CF_ISA_A
:
3414 case EF_M68K_CF_ISA_A_PLUS
:
3417 case EF_M68K_CF_ISA_B_NOUSP
:
3419 additional
= ", nousp";
3421 case EF_M68K_CF_ISA_B
:
3424 case EF_M68K_CF_ISA_C
:
3427 case EF_M68K_CF_ISA_C_NODIV
:
3429 additional
= ", nodiv";
3432 strcat (buf
, ", cf, isa ");
3435 strcat (buf
, additional
);
3436 if (e_flags
& EF_M68K_CF_FLOAT
)
3437 strcat (buf
, ", float");
3438 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3443 case EF_M68K_CF_MAC
:
3446 case EF_M68K_CF_EMAC
:
3449 case EF_M68K_CF_EMAC_B
:
3462 switch (e_flags
& EF_MEP_CPU_MASK
)
3464 case EF_MEP_CPU_MEP
: strcat (buf
, ", generic MeP"); break;
3465 case EF_MEP_CPU_C2
: strcat (buf
, ", MeP C2"); break;
3466 case EF_MEP_CPU_C3
: strcat (buf
, ", MeP C3"); break;
3467 case EF_MEP_CPU_C4
: strcat (buf
, ", MeP C4"); break;
3468 case EF_MEP_CPU_C5
: strcat (buf
, ", MeP C5"); break;
3469 case EF_MEP_CPU_H1
: strcat (buf
, ", MeP H1"); break;
3470 default: strcat (buf
, _(", <unknown MeP cpu type>")); break;
3473 switch (e_flags
& EF_MEP_COP_MASK
)
3475 case EF_MEP_COP_NONE
: break;
3476 case EF_MEP_COP_AVC
: strcat (buf
, ", AVC coprocessor"); break;
3477 case EF_MEP_COP_AVC2
: strcat (buf
, ", AVC2 coprocessor"); break;
3478 case EF_MEP_COP_FMAX
: strcat (buf
, ", FMAX coprocessor"); break;
3479 case EF_MEP_COP_IVC2
: strcat (buf
, ", IVC2 coprocessor"); break;
3480 default: strcat (buf
, _("<unknown MeP copro type>")); break;
3483 if (e_flags
& EF_MEP_LIBRARY
)
3484 strcat (buf
, ", Built for Library");
3486 if (e_flags
& EF_MEP_INDEX_MASK
)
3487 sprintf (buf
+ strlen (buf
), ", Configuration Index: %#x",
3488 e_flags
& EF_MEP_INDEX_MASK
);
3490 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3491 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3492 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3496 if (e_flags
& EF_PPC_EMB
)
3497 strcat (buf
, ", emb");
3499 if (e_flags
& EF_PPC_RELOCATABLE
)
3500 strcat (buf
, _(", relocatable"));
3502 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
3503 strcat (buf
, _(", relocatable-lib"));
3507 if (e_flags
& EF_PPC64_ABI
)
3509 char abi
[] = ", abiv0";
3511 abi
[6] += e_flags
& EF_PPC64_ABI
;
3517 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
3518 strcat (buf
, ", RH850 ABI");
3520 if (e_flags
& EF_V800_850E3
)
3521 strcat (buf
, ", V3 architecture");
3523 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
3524 strcat (buf
, ", FPU not used");
3526 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
3527 strcat (buf
, ", regmode: COMMON");
3529 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
3530 strcat (buf
, ", r4 not used");
3532 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
3533 strcat (buf
, ", r30 not used");
3535 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
3536 strcat (buf
, ", r5 not used");
3538 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
3539 strcat (buf
, ", r2 not used");
3541 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
3543 switch (e_flags
& - e_flags
)
3545 case EF_RH850_FPU_DOUBLE
: strcat (buf
, ", double precision FPU"); break;
3546 case EF_RH850_FPU_SINGLE
: strcat (buf
, ", single precision FPU"); break;
3547 case EF_RH850_REGMODE22
: strcat (buf
, ", regmode:22"); break;
3548 case EF_RH850_REGMODE32
: strcat (buf
, ", regmode:23"); break;
3549 case EF_RH850_GP_FIX
: strcat (buf
, ", r4 fixed"); break;
3550 case EF_RH850_GP_NOFIX
: strcat (buf
, ", r4 free"); break;
3551 case EF_RH850_EP_FIX
: strcat (buf
, ", r30 fixed"); break;
3552 case EF_RH850_EP_NOFIX
: strcat (buf
, ", r30 free"); break;
3553 case EF_RH850_TP_FIX
: strcat (buf
, ", r5 fixed"); break;
3554 case EF_RH850_TP_NOFIX
: strcat (buf
, ", r5 free"); break;
3555 case EF_RH850_REG2_RESERVE
: strcat (buf
, ", r2 fixed"); break;
3556 case EF_RH850_REG2_NORESERVE
: strcat (buf
, ", r2 free"); break;
3563 case EM_CYGNUS_V850
:
3564 switch (e_flags
& EF_V850_ARCH
)
3566 case E_V850E3V5_ARCH
:
3567 strcat (buf
, ", v850e3v5");
3569 case E_V850E2V3_ARCH
:
3570 strcat (buf
, ", v850e2v3");
3573 strcat (buf
, ", v850e2");
3576 strcat (buf
, ", v850e1");
3579 strcat (buf
, ", v850e");
3582 strcat (buf
, ", v850");
3585 strcat (buf
, _(", unknown v850 architecture variant"));
3591 case EM_CYGNUS_M32R
:
3592 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
3593 strcat (buf
, ", m32r");
3597 case EM_MIPS_RS3_LE
:
3598 if (e_flags
& EF_MIPS_NOREORDER
)
3599 strcat (buf
, ", noreorder");
3601 if (e_flags
& EF_MIPS_PIC
)
3602 strcat (buf
, ", pic");
3604 if (e_flags
& EF_MIPS_CPIC
)
3605 strcat (buf
, ", cpic");
3607 if (e_flags
& EF_MIPS_UCODE
)
3608 strcat (buf
, ", ugen_reserved");
3610 if (e_flags
& EF_MIPS_ABI2
)
3611 strcat (buf
, ", abi2");
3613 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
3614 strcat (buf
, ", odk first");
3616 if (e_flags
& EF_MIPS_32BITMODE
)
3617 strcat (buf
, ", 32bitmode");
3619 if (e_flags
& EF_MIPS_NAN2008
)
3620 strcat (buf
, ", nan2008");
3622 if (e_flags
& EF_MIPS_FP64
)
3623 strcat (buf
, ", fp64");
3625 switch ((e_flags
& EF_MIPS_MACH
))
3627 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
3628 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
3629 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
3630 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
3631 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
3632 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
3633 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
3634 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
3635 case E_MIPS_MACH_5900
: strcat (buf
, ", 5900"); break;
3636 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
3637 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
3638 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
3639 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
3640 case E_MIPS_MACH_GS464
: strcat (buf
, ", gs464"); break;
3641 case E_MIPS_MACH_GS464E
: strcat (buf
, ", gs464e"); break;
3642 case E_MIPS_MACH_GS264E
: strcat (buf
, ", gs264e"); break;
3643 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
3644 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
3645 case E_MIPS_MACH_OCTEON3
: strcat (buf
, ", octeon3"); break;
3646 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
3647 case E_MIPS_MACH_IAMR2
: strcat (buf
, ", interaptiv-mr2"); break;
3649 /* We simply ignore the field in this case to avoid confusion:
3650 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3653 default: strcat (buf
, _(", unknown CPU")); break;
3656 switch ((e_flags
& EF_MIPS_ABI
))
3658 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
3659 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
3660 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
3661 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
3663 /* We simply ignore the field in this case to avoid confusion:
3664 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3665 This means it is likely to be an o32 file, but not for
3668 default: strcat (buf
, _(", unknown ABI")); break;
3671 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
3672 strcat (buf
, ", mdmx");
3674 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
3675 strcat (buf
, ", mips16");
3677 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
3678 strcat (buf
, ", micromips");
3680 switch ((e_flags
& EF_MIPS_ARCH
))
3682 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
3683 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
3684 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
3685 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
3686 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
3687 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
3688 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
3689 case E_MIPS_ARCH_32R6
: strcat (buf
, ", mips32r6"); break;
3690 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
3691 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
3692 case E_MIPS_ARCH_64R6
: strcat (buf
, ", mips64r6"); break;
3693 default: strcat (buf
, _(", unknown ISA")); break;
3698 decode_NDS32_machine_flags (e_flags
, buf
, sizeof buf
);
3702 switch (EF_NFP_MACH (e_flags
))
3704 case E_NFP_MACH_3200
:
3705 strcat (buf
, ", NFP-32xx");
3707 case E_NFP_MACH_6000
:
3708 strcat (buf
, ", NFP-6xxx");
3714 if (e_flags
& EF_RISCV_RVC
)
3715 strcat (buf
, ", RVC");
3717 if (e_flags
& EF_RISCV_RVE
)
3718 strcat (buf
, ", RVE");
3720 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
3722 case EF_RISCV_FLOAT_ABI_SOFT
:
3723 strcat (buf
, ", soft-float ABI");
3726 case EF_RISCV_FLOAT_ABI_SINGLE
:
3727 strcat (buf
, ", single-float ABI");
3730 case EF_RISCV_FLOAT_ABI_DOUBLE
:
3731 strcat (buf
, ", double-float ABI");
3734 case EF_RISCV_FLOAT_ABI_QUAD
:
3735 strcat (buf
, ", quad-float ABI");
3741 switch ((e_flags
& EF_SH_MACH_MASK
))
3743 case EF_SH1
: strcat (buf
, ", sh1"); break;
3744 case EF_SH2
: strcat (buf
, ", sh2"); break;
3745 case EF_SH3
: strcat (buf
, ", sh3"); break;
3746 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
3747 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
3748 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
3749 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
3750 case EF_SH4
: strcat (buf
, ", sh4"); break;
3751 case EF_SH5
: strcat (buf
, ", sh5"); break;
3752 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
3753 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
3754 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
3755 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
3756 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
3757 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
3758 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
3759 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
3760 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3761 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
3762 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
3763 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
3764 default: strcat (buf
, _(", unknown ISA")); break;
3767 if (e_flags
& EF_SH_PIC
)
3768 strcat (buf
, ", pic");
3770 if (e_flags
& EF_SH_FDPIC
)
3771 strcat (buf
, ", fdpic");
3775 if (e_flags
& EF_OR1K_NODELAY
)
3776 strcat (buf
, ", no delay");
3780 if (e_flags
& EF_SPARC_32PLUS
)
3781 strcat (buf
, ", v8+");
3783 if (e_flags
& EF_SPARC_SUN_US1
)
3784 strcat (buf
, ", ultrasparcI");
3786 if (e_flags
& EF_SPARC_SUN_US3
)
3787 strcat (buf
, ", ultrasparcIII");
3789 if (e_flags
& EF_SPARC_HAL_R1
)
3790 strcat (buf
, ", halr1");
3792 if (e_flags
& EF_SPARC_LEDATA
)
3793 strcat (buf
, ", ledata");
3795 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
3796 strcat (buf
, ", tso");
3798 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
3799 strcat (buf
, ", pso");
3801 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
3802 strcat (buf
, ", rmo");
3806 switch (e_flags
& EF_PARISC_ARCH
)
3808 case EFA_PARISC_1_0
:
3809 strcpy (buf
, ", PA-RISC 1.0");
3811 case EFA_PARISC_1_1
:
3812 strcpy (buf
, ", PA-RISC 1.1");
3814 case EFA_PARISC_2_0
:
3815 strcpy (buf
, ", PA-RISC 2.0");
3820 if (e_flags
& EF_PARISC_TRAPNIL
)
3821 strcat (buf
, ", trapnil");
3822 if (e_flags
& EF_PARISC_EXT
)
3823 strcat (buf
, ", ext");
3824 if (e_flags
& EF_PARISC_LSB
)
3825 strcat (buf
, ", lsb");
3826 if (e_flags
& EF_PARISC_WIDE
)
3827 strcat (buf
, ", wide");
3828 if (e_flags
& EF_PARISC_NO_KABP
)
3829 strcat (buf
, ", no kabp");
3830 if (e_flags
& EF_PARISC_LAZYSWAP
)
3831 strcat (buf
, ", lazyswap");
3836 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
3837 strcat (buf
, ", new calling convention");
3839 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
3840 strcat (buf
, ", gnu calling convention");
3844 if ((e_flags
& EF_IA_64_ABI64
))
3845 strcat (buf
, ", 64-bit");
3847 strcat (buf
, ", 32-bit");
3848 if ((e_flags
& EF_IA_64_REDUCEDFP
))
3849 strcat (buf
, ", reduced fp model");
3850 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
3851 strcat (buf
, ", no function descriptors, constant gp");
3852 else if ((e_flags
& EF_IA_64_CONS_GP
))
3853 strcat (buf
, ", constant gp");
3854 if ((e_flags
& EF_IA_64_ABSOLUTE
))
3855 strcat (buf
, ", absolute");
3856 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3858 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
3859 strcat (buf
, ", vms_linkages");
3860 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
3862 case EF_IA_64_VMS_COMCOD_SUCCESS
:
3864 case EF_IA_64_VMS_COMCOD_WARNING
:
3865 strcat (buf
, ", warning");
3867 case EF_IA_64_VMS_COMCOD_ERROR
:
3868 strcat (buf
, ", error");
3870 case EF_IA_64_VMS_COMCOD_ABORT
:
3871 strcat (buf
, ", abort");
3874 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3875 e_flags
& EF_IA_64_VMS_COMCOD
);
3876 strcat (buf
, ", <unknown>");
3882 if ((e_flags
& EF_VAX_NONPIC
))
3883 strcat (buf
, ", non-PIC");
3884 if ((e_flags
& EF_VAX_DFLOAT
))
3885 strcat (buf
, ", D-Float");
3886 if ((e_flags
& EF_VAX_GFLOAT
))
3887 strcat (buf
, ", G-Float");
3891 if (e_flags
& EF_VISIUM_ARCH_MCM
)
3892 strcat (buf
, ", mcm");
3893 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
3894 strcat (buf
, ", mcm24");
3895 if (e_flags
& EF_VISIUM_ARCH_GR6
)
3896 strcat (buf
, ", gr6");
3900 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
3902 case E_FLAG_RL78_ANY_CPU
: break;
3903 case E_FLAG_RL78_G10
: strcat (buf
, ", G10"); break;
3904 case E_FLAG_RL78_G13
: strcat (buf
, ", G13"); break;
3905 case E_FLAG_RL78_G14
: strcat (buf
, ", G14"); break;
3907 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
3908 strcat (buf
, ", 64-bit doubles");
3912 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
3913 strcat (buf
, ", 64-bit doubles");
3914 if (e_flags
& E_FLAG_RX_DSP
)
3915 strcat (buf
, ", dsp");
3916 if (e_flags
& E_FLAG_RX_PID
)
3917 strcat (buf
, ", pid");
3918 if (e_flags
& E_FLAG_RX_ABI
)
3919 strcat (buf
, ", RX ABI");
3920 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
3921 strcat (buf
, e_flags
& E_FLAG_RX_SINSNS_YES
3922 ? ", uses String instructions" : ", bans String instructions");
3923 if (e_flags
& E_FLAG_RX_V2
)
3924 strcat (buf
, ", V2");
3925 if (e_flags
& E_FLAG_RX_V3
)
3926 strcat (buf
, ", V3");
3930 if (e_flags
& EF_S390_HIGH_GPRS
)
3931 strcat (buf
, ", highgprs");
3935 if ((e_flags
& EF_C6000_REL
))
3936 strcat (buf
, ", relocatable module");
3940 strcat (buf
, _(": architecture variant: "));
3941 switch (e_flags
& EF_MSP430_MACH
)
3943 case E_MSP430_MACH_MSP430x11
: strcat (buf
, "MSP430x11"); break;
3944 case E_MSP430_MACH_MSP430x11x1
: strcat (buf
, "MSP430x11x1 "); break;
3945 case E_MSP430_MACH_MSP430x12
: strcat (buf
, "MSP430x12"); break;
3946 case E_MSP430_MACH_MSP430x13
: strcat (buf
, "MSP430x13"); break;
3947 case E_MSP430_MACH_MSP430x14
: strcat (buf
, "MSP430x14"); break;
3948 case E_MSP430_MACH_MSP430x15
: strcat (buf
, "MSP430x15"); break;
3949 case E_MSP430_MACH_MSP430x16
: strcat (buf
, "MSP430x16"); break;
3950 case E_MSP430_MACH_MSP430x31
: strcat (buf
, "MSP430x31"); break;
3951 case E_MSP430_MACH_MSP430x32
: strcat (buf
, "MSP430x32"); break;
3952 case E_MSP430_MACH_MSP430x33
: strcat (buf
, "MSP430x33"); break;
3953 case E_MSP430_MACH_MSP430x41
: strcat (buf
, "MSP430x41"); break;
3954 case E_MSP430_MACH_MSP430x42
: strcat (buf
, "MSP430x42"); break;
3955 case E_MSP430_MACH_MSP430x43
: strcat (buf
, "MSP430x43"); break;
3956 case E_MSP430_MACH_MSP430x44
: strcat (buf
, "MSP430x44"); break;
3957 case E_MSP430_MACH_MSP430X
: strcat (buf
, "MSP430X"); break;
3959 strcat (buf
, _(": unknown")); break;
3962 if (e_flags
& ~ EF_MSP430_MACH
)
3963 strcat (buf
, _(": unknown extra flag bits also present"));
3967 switch (e_flags
& EF_Z80_MACH_MSK
)
3969 case EF_Z80_MACH_Z80
: strcat (buf
, ", Z80"); break;
3970 case EF_Z80_MACH_Z180
: strcat (buf
, ", Z180"); break;
3971 case EF_Z80_MACH_R800
: strcat (buf
, ", R800"); break;
3972 case EF_Z80_MACH_EZ80_Z80
: strcat (buf
, ", EZ80"); break;
3973 case EF_Z80_MACH_EZ80_ADL
: strcat (buf
, ", EZ80, ADL"); break;
3974 case EF_Z80_MACH_GBZ80
: strcat (buf
, ", GBZ80"); break;
3975 case EF_Z80_MACH_Z80N
: strcat (buf
, ", Z80N"); break;
3977 strcat (buf
, _(", unknown")); break;
3981 if (EF_LOONGARCH_IS_LP64 (e_flags
))
3982 strcat (buf
, ", LP64");
3983 else if (EF_LOONGARCH_IS_ILP32 (e_flags
))
3984 strcat (buf
, ", ILP32");
3986 if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags
))
3987 strcat (buf
, ", SOFT-FLOAT");
3988 else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags
))
3989 strcat (buf
, ", SINGLE-FLOAT");
3990 else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags
))
3991 strcat (buf
, ", DOUBLE-FLOAT");
4001 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
4003 static char buff
[32];
4007 case ELFOSABI_NONE
: return "UNIX - System V";
4008 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
4009 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
4010 case ELFOSABI_GNU
: return "UNIX - GNU";
4011 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
4012 case ELFOSABI_AIX
: return "UNIX - AIX";
4013 case ELFOSABI_IRIX
: return "UNIX - IRIX";
4014 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
4015 case ELFOSABI_TRU64
: return "UNIX - TRU64";
4016 case ELFOSABI_MODESTO
: return "Novell - Modesto";
4017 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
4018 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
4019 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
4020 case ELFOSABI_AROS
: return "AROS";
4021 case ELFOSABI_FENIXOS
: return "FenixOS";
4022 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
4023 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
4026 switch (filedata
->file_header
.e_machine
)
4031 case ELFOSABI_ARM
: return "ARM";
4032 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
4043 case ELFOSABI_STANDALONE
: return _("Standalone App");
4052 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
4053 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
4062 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
4068 get_aarch64_segment_type (unsigned long type
)
4072 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
4073 default: return NULL
;
4078 get_arm_segment_type (unsigned long type
)
4082 case PT_ARM_EXIDX
: return "EXIDX";
4083 default: return NULL
;
4088 get_s390_segment_type (unsigned long type
)
4092 case PT_S390_PGSTE
: return "S390_PGSTE";
4093 default: return NULL
;
4098 get_mips_segment_type (unsigned long type
)
4102 case PT_MIPS_REGINFO
: return "REGINFO";
4103 case PT_MIPS_RTPROC
: return "RTPROC";
4104 case PT_MIPS_OPTIONS
: return "OPTIONS";
4105 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
4106 default: return NULL
;
4111 get_parisc_segment_type (unsigned long type
)
4115 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
4116 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
4117 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
4118 default: return NULL
;
4123 get_ia64_segment_type (unsigned long type
)
4127 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
4128 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
4129 default: return NULL
;
4134 get_tic6x_segment_type (unsigned long type
)
4138 case PT_C6000_PHATTR
: return "C6000_PHATTR";
4139 default: return NULL
;
4144 get_riscv_segment_type (unsigned long type
)
4148 case PT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4149 default: return NULL
;
4154 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
4156 if (e_machine
== EM_PARISC
)
4159 case PT_HP_TLS
: return "HP_TLS";
4160 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
4161 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
4162 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
4163 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
4164 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
4165 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
4166 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
4167 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
4168 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
4169 case PT_HP_PARALLEL
: return "HP_PARALLEL";
4170 case PT_HP_FASTBIND
: return "HP_FASTBIND";
4171 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
4172 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
4173 case PT_HP_STACK
: return "HP_STACK";
4174 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
4175 default: return NULL
;
4178 if (e_machine
== EM_IA_64
)
4181 case PT_HP_TLS
: return "HP_TLS";
4182 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
4183 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
4184 case PT_IA_64_HP_STACK
: return "HP_STACK";
4185 default: return NULL
;
4192 get_solaris_segment_type (unsigned long type
)
4196 case 0x6464e550: return "PT_SUNW_UNWIND";
4197 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4198 case 0x6ffffff7: return "PT_LOSUNW";
4199 case 0x6ffffffa: return "PT_SUNWBSS";
4200 case 0x6ffffffb: return "PT_SUNWSTACK";
4201 case 0x6ffffffc: return "PT_SUNWDTRACE";
4202 case 0x6ffffffd: return "PT_SUNWCAP";
4203 case 0x6fffffff: return "PT_HISUNW";
4204 default: return NULL
;
4209 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4211 static char buff
[32];
4215 case PT_NULL
: return "NULL";
4216 case PT_LOAD
: return "LOAD";
4217 case PT_DYNAMIC
: return "DYNAMIC";
4218 case PT_INTERP
: return "INTERP";
4219 case PT_NOTE
: return "NOTE";
4220 case PT_SHLIB
: return "SHLIB";
4221 case PT_PHDR
: return "PHDR";
4222 case PT_TLS
: return "TLS";
4223 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4224 case PT_GNU_STACK
: return "GNU_STACK";
4225 case PT_GNU_RELRO
: return "GNU_RELRO";
4226 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4228 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
4229 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
4230 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
4233 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4235 const char * result
;
4237 switch (filedata
->file_header
.e_machine
)
4240 result
= get_aarch64_segment_type (p_type
);
4243 result
= get_arm_segment_type (p_type
);
4246 case EM_MIPS_RS3_LE
:
4247 result
= get_mips_segment_type (p_type
);
4250 result
= get_parisc_segment_type (p_type
);
4253 result
= get_ia64_segment_type (p_type
);
4256 result
= get_tic6x_segment_type (p_type
);
4260 result
= get_s390_segment_type (p_type
);
4263 result
= get_riscv_segment_type (p_type
);
4273 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4275 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4277 const char * result
= NULL
;
4279 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4282 case ELFOSABI_FREEBSD
:
4283 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4285 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4290 result
= get_hpux_segment_type (p_type
,
4291 filedata
->file_header
.e_machine
);
4293 case ELFOSABI_SOLARIS
:
4294 result
= get_solaris_segment_type (p_type
);
4302 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4305 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4312 get_arc_section_type_name (unsigned int sh_type
)
4316 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4324 get_mips_section_type_name (unsigned int sh_type
)
4328 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4329 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4330 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4331 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4332 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4333 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4334 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4335 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4336 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4337 case SHT_MIPS_RELD
: return "MIPS_RELD";
4338 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4339 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4340 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4341 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4342 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4343 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4344 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4345 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4346 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4347 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4348 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4349 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4350 case SHT_MIPS_LINE
: return "MIPS_LINE";
4351 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4352 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4353 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4354 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4355 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4356 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4357 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4358 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4359 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4360 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4361 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4362 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4363 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4364 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4365 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4366 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4367 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4368 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4376 get_parisc_section_type_name (unsigned int sh_type
)
4380 case SHT_PARISC_EXT
: return "PARISC_EXT";
4381 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4382 case SHT_PARISC_DOC
: return "PARISC_DOC";
4383 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4384 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4385 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4386 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4387 default: return NULL
;
4392 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4394 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4395 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4396 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4400 case SHT_IA_64_EXT
: return "IA_64_EXT";
4401 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4402 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4403 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4404 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4405 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4406 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4407 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4408 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4409 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4417 get_x86_64_section_type_name (unsigned int sh_type
)
4421 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4422 default: return NULL
;
4427 get_aarch64_section_type_name (unsigned int sh_type
)
4431 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4432 default: return NULL
;
4437 get_arm_section_type_name (unsigned int sh_type
)
4441 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4442 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4443 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4444 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4445 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4446 default: return NULL
;
4451 get_tic6x_section_type_name (unsigned int sh_type
)
4455 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4456 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4457 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4458 case SHT_TI_ICODE
: return "TI_ICODE";
4459 case SHT_TI_XREF
: return "TI_XREF";
4460 case SHT_TI_HANDLER
: return "TI_HANDLER";
4461 case SHT_TI_INITINFO
: return "TI_INITINFO";
4462 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4463 default: return NULL
;
4468 get_msp430_section_type_name (unsigned int sh_type
)
4472 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4473 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4474 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4475 default: return NULL
;
4480 get_nfp_section_type_name (unsigned int sh_type
)
4484 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4485 case SHT_NFP_INITREG
: return "NFP_INITREG";
4486 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4487 default: return NULL
;
4492 get_v850_section_type_name (unsigned int sh_type
)
4496 case SHT_V850_SCOMMON
: return "V850 Small Common";
4497 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4498 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4499 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4500 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4501 default: return NULL
;
4506 get_riscv_section_type_name (unsigned int sh_type
)
4510 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4511 default: return NULL
;
4516 get_csky_section_type_name (unsigned int sh_type
)
4520 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
4521 default: return NULL
;
4526 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4528 static char buff
[32];
4529 const char * result
;
4533 case SHT_NULL
: return "NULL";
4534 case SHT_PROGBITS
: return "PROGBITS";
4535 case SHT_SYMTAB
: return "SYMTAB";
4536 case SHT_STRTAB
: return "STRTAB";
4537 case SHT_RELA
: return "RELA";
4538 case SHT_HASH
: return "HASH";
4539 case SHT_DYNAMIC
: return "DYNAMIC";
4540 case SHT_NOTE
: return "NOTE";
4541 case SHT_NOBITS
: return "NOBITS";
4542 case SHT_REL
: return "REL";
4543 case SHT_SHLIB
: return "SHLIB";
4544 case SHT_DYNSYM
: return "DYNSYM";
4545 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4546 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4547 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4548 case SHT_GNU_HASH
: return "GNU_HASH";
4549 case SHT_GROUP
: return "GROUP";
4550 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4551 case SHT_GNU_verdef
: return "VERDEF";
4552 case SHT_GNU_verneed
: return "VERNEED";
4553 case SHT_GNU_versym
: return "VERSYM";
4554 case 0x6ffffff0: return "VERSYM";
4555 case 0x6ffffffc: return "VERDEF";
4556 case 0x7ffffffd: return "AUXILIARY";
4557 case 0x7fffffff: return "FILTER";
4558 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4561 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4563 switch (filedata
->file_header
.e_machine
)
4566 case EM_ARC_COMPACT
:
4567 case EM_ARC_COMPACT2
:
4568 result
= get_arc_section_type_name (sh_type
);
4571 case EM_MIPS_RS3_LE
:
4572 result
= get_mips_section_type_name (sh_type
);
4575 result
= get_parisc_section_type_name (sh_type
);
4578 result
= get_ia64_section_type_name (filedata
, sh_type
);
4583 result
= get_x86_64_section_type_name (sh_type
);
4586 result
= get_aarch64_section_type_name (sh_type
);
4589 result
= get_arm_section_type_name (sh_type
);
4592 result
= get_tic6x_section_type_name (sh_type
);
4595 result
= get_msp430_section_type_name (sh_type
);
4598 result
= get_nfp_section_type_name (sh_type
);
4602 case EM_CYGNUS_V850
:
4603 result
= get_v850_section_type_name (sh_type
);
4606 result
= get_riscv_section_type_name (sh_type
);
4609 result
= get_csky_section_type_name (sh_type
);
4619 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
4621 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
4623 switch (filedata
->file_header
.e_machine
)
4626 result
= get_ia64_section_type_name (filedata
, sh_type
);
4629 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
4630 result
= get_solaris_section_type (sh_type
);
4635 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
4636 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
4637 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
4638 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
4650 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
4652 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
4654 switch (filedata
->file_header
.e_machine
)
4658 case EM_CYGNUS_V850
:
4659 result
= get_v850_section_type_name (sh_type
);
4669 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
4672 /* This message is probably going to be displayed in a 15
4673 character wide field, so put the hex value first. */
4674 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
4680 enum long_option_values
4682 OPTION_DEBUG_DUMP
= 512,
4692 OPTION_WITH_SYMBOL_VERSIONS
,
4693 OPTION_RECURSE_LIMIT
,
4694 OPTION_NO_RECURSE_LIMIT
,
4695 OPTION_NO_DEMANGLING
,
4699 static struct option options
[] =
4701 /* Note - This table is alpha-sorted on the 'val'
4702 field in order to make adding new options easier. */
4703 {"arch-specific", no_argument
, 0, 'A'},
4704 {"all", no_argument
, 0, 'a'},
4705 {"demangle", optional_argument
, 0, 'C'},
4706 {"archive-index", no_argument
, 0, 'c'},
4707 {"use-dynamic", no_argument
, 0, 'D'},
4708 {"dynamic", no_argument
, 0, 'd'},
4709 {"headers", no_argument
, 0, 'e'},
4710 {"section-groups", no_argument
, 0, 'g'},
4711 {"help", no_argument
, 0, 'H'},
4712 {"file-header", no_argument
, 0, 'h'},
4713 {"histogram", no_argument
, 0, 'I'},
4714 {"lint", no_argument
, 0, 'L'},
4715 {"enable-checks", no_argument
, 0, 'L'},
4716 {"program-headers", no_argument
, 0, 'l'},
4717 {"segments", no_argument
, 0, 'l'},
4718 {"full-section-name",no_argument
, 0, 'N'},
4719 {"notes", no_argument
, 0, 'n'},
4720 {"process-links", no_argument
, 0, 'P'},
4721 {"string-dump", required_argument
, 0, 'p'},
4722 {"relocated-dump", required_argument
, 0, 'R'},
4723 {"relocs", no_argument
, 0, 'r'},
4724 {"section-headers", no_argument
, 0, 'S'},
4725 {"sections", no_argument
, 0, 'S'},
4726 {"symbols", no_argument
, 0, 's'},
4727 {"syms", no_argument
, 0, 's'},
4728 {"silent-truncation",no_argument
, 0, 'T'},
4729 {"section-details", no_argument
, 0, 't'},
4730 {"unwind", no_argument
, 0, 'u'},
4731 {"version-info", no_argument
, 0, 'V'},
4732 {"version", no_argument
, 0, 'v'},
4733 {"wide", no_argument
, 0, 'W'},
4734 {"hex-dump", required_argument
, 0, 'x'},
4735 {"decompress", no_argument
, 0, 'z'},
4737 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
4738 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
4739 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4740 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4741 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
4742 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
4743 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
4744 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
4745 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
4746 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
4747 #ifdef ENABLE_LIBCTF
4748 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
4749 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
4750 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
4751 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
4753 {"sym-base", optional_argument
, 0, OPTION_SYM_BASE
},
4755 {0, no_argument
, 0, 0}
4759 usage (FILE * stream
)
4761 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
4762 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
4763 fprintf (stream
, _(" Options are:\n"));
4764 fprintf (stream
, _("\
4765 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
4766 fprintf (stream
, _("\
4767 -h --file-header Display the ELF file header\n"));
4768 fprintf (stream
, _("\
4769 -l --program-headers Display the program headers\n"));
4770 fprintf (stream
, _("\
4771 --segments An alias for --program-headers\n"));
4772 fprintf (stream
, _("\
4773 -S --section-headers Display the sections' header\n"));
4774 fprintf (stream
, _("\
4775 --sections An alias for --section-headers\n"));
4776 fprintf (stream
, _("\
4777 -g --section-groups Display the section groups\n"));
4778 fprintf (stream
, _("\
4779 -t --section-details Display the section details\n"));
4780 fprintf (stream
, _("\
4781 -e --headers Equivalent to: -h -l -S\n"));
4782 fprintf (stream
, _("\
4783 -s --syms Display the symbol table\n"));
4784 fprintf (stream
, _("\
4785 --symbols An alias for --syms\n"));
4786 fprintf (stream
, _("\
4787 --dyn-syms Display the dynamic symbol table\n"));
4788 fprintf (stream
, _("\
4789 --lto-syms Display LTO symbol tables\n"));
4790 fprintf (stream
, _("\
4791 --sym-base=[0|8|10|16] \n\
4792 Force base for symbol sizes. The options are \n\
4793 mixed (the default), octal, decimal, hexadecimal.\n"));
4794 fprintf (stream
, _("\
4795 -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
4796 The STYLE, if specified, can be `auto' (the default),\n\
4797 `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
4799 fprintf (stream
, _("\
4800 --no-demangle Do not demangle low-level symbol names. (default)\n"));
4801 fprintf (stream
, _("\
4802 --recurse-limit Enable a demangling recursion limit. (default)\n"));
4803 fprintf (stream
, _("\
4804 --no-recurse-limit Disable a demangling recursion limit\n"));
4805 fprintf (stream
, _("\
4806 -n --notes Display the core notes (if present)\n"));
4807 fprintf (stream
, _("\
4808 -r --relocs Display the relocations (if present)\n"));
4809 fprintf (stream
, _("\
4810 -u --unwind Display the unwind info (if present)\n"));
4811 fprintf (stream
, _("\
4812 -d --dynamic Display the dynamic section (if present)\n"));
4813 fprintf (stream
, _("\
4814 -V --version-info Display the version sections (if present)\n"));
4815 fprintf (stream
, _("\
4816 -A --arch-specific Display architecture specific information (if any)\n"));
4817 fprintf (stream
, _("\
4818 -c --archive-index Display the symbol/file index in an archive\n"));
4819 fprintf (stream
, _("\
4820 -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
4821 fprintf (stream
, _("\
4822 -L --lint|--enable-checks\n\
4823 Display warning messages for possible problems\n"));
4824 fprintf (stream
, _("\
4825 -x --hex-dump=<number|name>\n\
4826 Dump the contents of section <number|name> as bytes\n"));
4827 fprintf (stream
, _("\
4828 -p --string-dump=<number|name>\n\
4829 Dump the contents of section <number|name> as strings\n"));
4830 fprintf (stream
, _("\
4831 -R --relocated-dump=<number|name>\n\
4832 Dump the relocated contents of section <number|name>\n"));
4833 fprintf (stream
, _("\
4834 -z --decompress Decompress section before dumping it\n"));
4835 fprintf (stream
, _("\
4836 -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
4837 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
4838 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
4839 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
4841 Display the contents of DWARF debug sections\n"));
4842 fprintf (stream
, _("\
4843 -wk --debug-dump=links Display the contents of sections that link to separate\n\
4844 debuginfo files\n"));
4845 fprintf (stream
, _("\
4846 -P --process-links Display the contents of non-debug sections in separate\n\
4847 debuginfo files. (Implies -wK)\n"));
4848 #if DEFAULT_FOR_FOLLOW_LINKS
4849 fprintf (stream
, _("\
4850 -wK --debug-dump=follow-links\n\
4851 Follow links to separate debug info files (default)\n"));
4852 fprintf (stream
, _("\
4853 -wN --debug-dump=no-follow-links\n\
4854 Do not follow links to separate debug info files\n"));
4856 fprintf (stream
, _("\
4857 -wK --debug-dump=follow-links\n\
4858 Follow links to separate debug info files\n"));
4859 fprintf (stream
, _("\
4860 -wN --debug-dump=no-follow-links\n\
4861 Do not follow links to separate debug info files\n\
4864 fprintf (stream
, _("\
4865 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
4866 fprintf (stream
, _("\
4867 --dwarf-start=N Display DIEs starting at offset N\n"));
4868 #ifdef ENABLE_LIBCTF
4869 fprintf (stream
, _("\
4870 --ctf=<number|name> Display CTF info from section <number|name>\n"));
4871 fprintf (stream
, _("\
4872 --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
4873 fprintf (stream
, _("\
4874 --ctf-symbols=<number|name>\n\
4875 Use section <number|name> as the CTF external symtab\n"));
4876 fprintf (stream
, _("\
4877 --ctf-strings=<number|name>\n\
4878 Use section <number|name> as the CTF external strtab\n"));
4881 #ifdef SUPPORT_DISASSEMBLY
4882 fprintf (stream
, _("\
4883 -i --instruction-dump=<number|name>\n\
4884 Disassemble the contents of section <number|name>\n"));
4886 fprintf (stream
, _("\
4887 -I --histogram Display histogram of bucket list lengths\n"));
4888 fprintf (stream
, _("\
4889 -W --wide Allow output width to exceed 80 characters\n"));
4890 fprintf (stream
, _("\
4891 -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
4892 fprintf (stream
, _("\
4893 @<file> Read options from <file>\n"));
4894 fprintf (stream
, _("\
4895 -H --help Display this information\n"));
4896 fprintf (stream
, _("\
4897 -v --version Display the version number of readelf\n"));
4899 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
4900 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
4902 exit (stream
== stdout
? 0 : 1);
4905 /* Record the fact that the user wants the contents of section number
4906 SECTION to be displayed using the method(s) encoded as flags bits
4907 in TYPE. Note, TYPE can be zero if we are creating the array for
4911 request_dump_bynumber (struct dump_data
*dumpdata
,
4912 unsigned int section
, dump_type type
)
4914 if (section
>= dumpdata
->num_dump_sects
)
4916 dump_type
* new_dump_sects
;
4918 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
4919 sizeof (* new_dump_sects
));
4921 if (new_dump_sects
== NULL
)
4922 error (_("Out of memory allocating dump request table.\n"));
4925 if (dumpdata
->dump_sects
)
4927 /* Copy current flag settings. */
4928 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
4929 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
4931 free (dumpdata
->dump_sects
);
4934 dumpdata
->dump_sects
= new_dump_sects
;
4935 dumpdata
->num_dump_sects
= section
+ 1;
4939 if (dumpdata
->dump_sects
)
4940 dumpdata
->dump_sects
[section
] |= type
;
4943 /* Request a dump by section name. */
4946 request_dump_byname (const char * section
, dump_type type
)
4948 struct dump_list_entry
* new_request
;
4950 new_request
= (struct dump_list_entry
*)
4951 malloc (sizeof (struct dump_list_entry
));
4953 error (_("Out of memory allocating dump request table.\n"));
4955 new_request
->name
= strdup (section
);
4956 if (!new_request
->name
)
4957 error (_("Out of memory allocating dump request table.\n"));
4959 new_request
->type
= type
;
4961 new_request
->next
= dump_sects_byname
;
4962 dump_sects_byname
= new_request
;
4966 request_dump (struct dump_data
*dumpdata
, dump_type type
)
4972 section
= strtoul (optarg
, & cp
, 0);
4974 if (! *cp
&& section
>= 0)
4975 request_dump_bynumber (dumpdata
, section
, type
);
4977 request_dump_byname (optarg
, type
);
4981 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
4988 while ((c
= getopt_long
4989 (argc
, argv
, "ACDHILNPR:STVWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
5007 do_section_groups
= true;
5010 do_histogram
= true;
5016 do_section_groups
= true;
5021 do_section_details
= true;
5032 do_using_dynamic
= true;
5056 do_histogram
= true;
5062 do_archive_index
= true;
5068 process_links
= true;
5069 do_follow_links
= true;
5072 request_dump (dumpdata
, HEX_DUMP
);
5075 request_dump (dumpdata
, STRING_DUMP
);
5078 request_dump (dumpdata
, RELOC_DUMP
);
5081 decompress_dumps
= true;
5087 do_debugging
= true;
5088 dwarf_select_sections_all ();
5092 do_debugging
= false;
5093 dwarf_select_sections_by_letters (optarg
);
5096 case OPTION_DEBUG_DUMP
:
5100 do_debugging
= true;
5101 dwarf_select_sections_all ();
5105 do_debugging
= false;
5106 dwarf_select_sections_by_names (optarg
);
5109 case OPTION_DWARF_DEPTH
:
5113 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5116 case OPTION_DWARF_START
:
5120 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5123 case OPTION_DWARF_CHECK
:
5126 case OPTION_CTF_DUMP
:
5128 request_dump (dumpdata
, CTF_DUMP
);
5130 case OPTION_CTF_SYMBOLS
:
5131 free (dump_ctf_symtab_name
);
5132 dump_ctf_symtab_name
= strdup (optarg
);
5134 case OPTION_CTF_STRINGS
:
5135 free (dump_ctf_strtab_name
);
5136 dump_ctf_strtab_name
= strdup (optarg
);
5138 case OPTION_CTF_PARENT
:
5139 free (dump_ctf_parent_name
);
5140 dump_ctf_parent_name
= strdup (optarg
);
5142 case OPTION_DYN_SYMS
:
5145 case OPTION_LTO_SYMS
:
5148 #ifdef SUPPORT_DISASSEMBLY
5150 request_dump (dumpdata
, DISASS_DUMP
);
5154 print_version (program_name
);
5163 do_not_show_symbol_truncation
= true;
5169 enum demangling_styles style
;
5171 style
= cplus_demangle_name_to_style (optarg
);
5172 if (style
== unknown_demangling
)
5173 error (_("unknown demangling style `%s'"), optarg
);
5175 cplus_demangle_set_style (style
);
5178 case OPTION_NO_DEMANGLING
:
5179 do_demangle
= false;
5181 case OPTION_RECURSE_LIMIT
:
5182 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5184 case OPTION_NO_RECURSE_LIMIT
:
5185 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5187 case OPTION_WITH_SYMBOL_VERSIONS
:
5188 /* Ignored for backward compatibility. */
5191 case OPTION_SYM_BASE
:
5195 sym_base
= strtoul (optarg
, NULL
, 0);
5212 /* xgettext:c-format */
5213 error (_("Invalid option '-%c'\n"), c
);
5220 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
5221 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
5222 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
5223 && !do_section_groups
&& !do_archive_index
5224 && !do_dyn_syms
&& !do_lto_syms
)
5229 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
5230 do_segments
= do_header
= do_dump
= do_version
= true;
5231 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
5232 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
5241 get_elf_class (unsigned int elf_class
)
5243 static char buff
[32];
5247 case ELFCLASSNONE
: return _("none");
5248 case ELFCLASS32
: return "ELF32";
5249 case ELFCLASS64
: return "ELF64";
5251 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
5257 get_data_encoding (unsigned int encoding
)
5259 static char buff
[32];
5263 case ELFDATANONE
: return _("none");
5264 case ELFDATA2LSB
: return _("2's complement, little endian");
5265 case ELFDATA2MSB
: return _("2's complement, big endian");
5267 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
5272 /* Decode the data held in 'filedata->file_header'. */
5275 process_file_header (Filedata
* filedata
)
5277 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
5279 if ( header
->e_ident
[EI_MAG0
] != ELFMAG0
5280 || header
->e_ident
[EI_MAG1
] != ELFMAG1
5281 || header
->e_ident
[EI_MAG2
] != ELFMAG2
5282 || header
->e_ident
[EI_MAG3
] != ELFMAG3
)
5285 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
5289 if (! filedata
->is_separate
)
5290 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
5296 if (filedata
->is_separate
)
5297 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
5299 printf (_("ELF Header:\n"));
5300 printf (_(" Magic: "));
5301 for (i
= 0; i
< EI_NIDENT
; i
++)
5302 printf ("%2.2x ", header
->e_ident
[i
]);
5304 printf (_(" Class: %s\n"),
5305 get_elf_class (header
->e_ident
[EI_CLASS
]));
5306 printf (_(" Data: %s\n"),
5307 get_data_encoding (header
->e_ident
[EI_DATA
]));
5308 printf (_(" Version: %d%s\n"),
5309 header
->e_ident
[EI_VERSION
],
5310 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
5312 : (header
->e_ident
[EI_VERSION
] != EV_NONE
5315 printf (_(" OS/ABI: %s\n"),
5316 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
5317 printf (_(" ABI Version: %d\n"),
5318 header
->e_ident
[EI_ABIVERSION
]);
5319 printf (_(" Type: %s\n"),
5320 get_file_type (filedata
));
5321 printf (_(" Machine: %s\n"),
5322 get_machine_name (header
->e_machine
));
5323 printf (_(" Version: 0x%lx\n"),
5326 printf (_(" Entry point address: "));
5327 print_vma (header
->e_entry
, PREFIX_HEX
);
5328 printf (_("\n Start of program headers: "));
5329 print_vma (header
->e_phoff
, DEC
);
5330 printf (_(" (bytes into file)\n Start of section headers: "));
5331 print_vma (header
->e_shoff
, DEC
);
5332 printf (_(" (bytes into file)\n"));
5334 printf (_(" Flags: 0x%lx%s\n"),
5336 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
5337 printf (_(" Size of this header: %u (bytes)\n"),
5339 printf (_(" Size of program headers: %u (bytes)\n"),
5340 header
->e_phentsize
);
5341 printf (_(" Number of program headers: %u"),
5343 if (filedata
->section_headers
!= NULL
5344 && header
->e_phnum
== PN_XNUM
5345 && filedata
->section_headers
[0].sh_info
!= 0)
5347 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5348 printf (" (%u)", header
->e_phnum
);
5350 putc ('\n', stdout
);
5351 printf (_(" Size of section headers: %u (bytes)\n"),
5352 header
->e_shentsize
);
5353 printf (_(" Number of section headers: %u"),
5355 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
5357 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5358 printf (" (%u)", header
->e_shnum
);
5360 putc ('\n', stdout
);
5361 printf (_(" Section header string table index: %u"),
5362 header
->e_shstrndx
);
5363 if (filedata
->section_headers
!= NULL
5364 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5366 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5367 printf (" (%u)", header
->e_shstrndx
);
5369 if (header
->e_shstrndx
!= SHN_UNDEF
5370 && header
->e_shstrndx
>= header
->e_shnum
)
5372 header
->e_shstrndx
= SHN_UNDEF
;
5373 printf (_(" <corrupt: out of range>"));
5375 putc ('\n', stdout
);
5378 if (filedata
->section_headers
!= NULL
)
5380 if (header
->e_phnum
== PN_XNUM
5381 && filedata
->section_headers
[0].sh_info
!= 0)
5382 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5383 if (header
->e_shnum
== SHN_UNDEF
)
5384 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5385 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5386 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5387 if (header
->e_shstrndx
>= header
->e_shnum
)
5388 header
->e_shstrndx
= SHN_UNDEF
;
5394 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5395 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5398 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5400 Elf32_External_Phdr
* phdrs
;
5401 Elf32_External_Phdr
* external
;
5402 Elf_Internal_Phdr
* internal
;
5404 unsigned int size
= filedata
->file_header
.e_phentsize
;
5405 unsigned int num
= filedata
->file_header
.e_phnum
;
5407 /* PR binutils/17531: Cope with unexpected section header sizes. */
5408 if (size
== 0 || num
== 0)
5410 if (size
< sizeof * phdrs
)
5412 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5415 if (size
> sizeof * phdrs
)
5416 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5418 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5419 size
, num
, _("program headers"));
5423 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5424 i
< filedata
->file_header
.e_phnum
;
5425 i
++, internal
++, external
++)
5427 internal
->p_type
= BYTE_GET (external
->p_type
);
5428 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5429 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5430 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5431 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5432 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5433 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5434 internal
->p_align
= BYTE_GET (external
->p_align
);
5441 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5442 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5445 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5447 Elf64_External_Phdr
* phdrs
;
5448 Elf64_External_Phdr
* external
;
5449 Elf_Internal_Phdr
* internal
;
5451 unsigned int size
= filedata
->file_header
.e_phentsize
;
5452 unsigned int num
= filedata
->file_header
.e_phnum
;
5454 /* PR binutils/17531: Cope with unexpected section header sizes. */
5455 if (size
== 0 || num
== 0)
5457 if (size
< sizeof * phdrs
)
5459 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5462 if (size
> sizeof * phdrs
)
5463 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5465 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5466 size
, num
, _("program headers"));
5470 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5471 i
< filedata
->file_header
.e_phnum
;
5472 i
++, internal
++, external
++)
5474 internal
->p_type
= BYTE_GET (external
->p_type
);
5475 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5476 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5477 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5478 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5479 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5480 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5481 internal
->p_align
= BYTE_GET (external
->p_align
);
5488 /* Returns TRUE if the program headers were read into `program_headers'. */
5491 get_program_headers (Filedata
* filedata
)
5493 Elf_Internal_Phdr
* phdrs
;
5495 /* Check cache of prior read. */
5496 if (filedata
->program_headers
!= NULL
)
5499 /* Be kind to memory checkers by looking for
5500 e_phnum values which we know must be invalid. */
5501 if (filedata
->file_header
.e_phnum
5502 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
5503 >= filedata
->file_size
)
5505 error (_("Too many program headers - %#x - the file is not that big\n"),
5506 filedata
->file_header
.e_phnum
);
5510 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
5511 sizeof (Elf_Internal_Phdr
));
5514 error (_("Out of memory reading %u program headers\n"),
5515 filedata
->file_header
.e_phnum
);
5520 ? get_32bit_program_headers (filedata
, phdrs
)
5521 : get_64bit_program_headers (filedata
, phdrs
))
5523 filedata
->program_headers
= phdrs
;
5531 /* Print program header info and locate dynamic section. */
5534 process_program_headers (Filedata
* filedata
)
5536 Elf_Internal_Phdr
* segment
;
5538 Elf_Internal_Phdr
* previous_load
= NULL
;
5540 if (filedata
->file_header
.e_phnum
== 0)
5542 /* PR binutils/12467. */
5543 if (filedata
->file_header
.e_phoff
!= 0)
5544 warn (_("possibly corrupt ELF header - it has a non-zero program"
5545 " header offset, but no program headers\n"));
5546 else if (do_segments
)
5548 if (filedata
->is_separate
)
5549 printf (_("\nThere are no program headers in linked file '%s'.\n"),
5550 filedata
->file_name
);
5552 printf (_("\nThere are no program headers in this file.\n"));
5557 if (do_segments
&& !do_header
)
5559 if (filedata
->is_separate
)
5560 printf ("\nIn linked file '%s' the ELF file type is %s\n",
5561 filedata
->file_name
, get_file_type (filedata
));
5563 printf (_("\nElf file type is %s\n"), get_file_type (filedata
));
5564 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata
->file_header
.e_entry
));
5565 printf (ngettext ("There is %d program header, starting at offset %s\n",
5566 "There are %d program headers, starting at offset %s\n",
5567 filedata
->file_header
.e_phnum
),
5568 filedata
->file_header
.e_phnum
,
5569 bfd_vmatoa ("u", filedata
->file_header
.e_phoff
));
5572 if (! get_program_headers (filedata
))
5577 if (filedata
->file_header
.e_phnum
> 1)
5578 printf (_("\nProgram Headers:\n"));
5580 printf (_("\nProgram Headers:\n"));
5584 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5587 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5591 (_(" Type Offset VirtAddr PhysAddr\n"));
5593 (_(" FileSiz MemSiz Flags Align\n"));
5597 unsigned long dynamic_addr
= 0;
5598 bfd_size_type dynamic_size
= 0;
5599 for (i
= 0, segment
= filedata
->program_headers
;
5600 i
< filedata
->file_header
.e_phnum
;
5605 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
5609 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5610 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
5611 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
5612 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
5613 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
5615 (segment
->p_flags
& PF_R
? 'R' : ' '),
5616 (segment
->p_flags
& PF_W
? 'W' : ' '),
5617 (segment
->p_flags
& PF_X
? 'E' : ' '));
5618 printf ("%#lx", (unsigned long) segment
->p_align
);
5622 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
5623 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5626 print_vma (segment
->p_offset
, FULL_HEX
);
5630 print_vma (segment
->p_vaddr
, FULL_HEX
);
5632 print_vma (segment
->p_paddr
, FULL_HEX
);
5635 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
5636 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
5639 print_vma (segment
->p_filesz
, FULL_HEX
);
5643 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
5644 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
5647 print_vma (segment
->p_memsz
, FULL_HEX
);
5651 (segment
->p_flags
& PF_R
? 'R' : ' '),
5652 (segment
->p_flags
& PF_W
? 'W' : ' '),
5653 (segment
->p_flags
& PF_X
? 'E' : ' '));
5655 if ((unsigned long) segment
->p_align
== segment
->p_align
)
5656 printf ("%#lx", (unsigned long) segment
->p_align
);
5659 print_vma (segment
->p_align
, PREFIX_HEX
);
5664 print_vma (segment
->p_offset
, FULL_HEX
);
5666 print_vma (segment
->p_vaddr
, FULL_HEX
);
5668 print_vma (segment
->p_paddr
, FULL_HEX
);
5670 print_vma (segment
->p_filesz
, FULL_HEX
);
5672 print_vma (segment
->p_memsz
, FULL_HEX
);
5674 (segment
->p_flags
& PF_R
? 'R' : ' '),
5675 (segment
->p_flags
& PF_W
? 'W' : ' '),
5676 (segment
->p_flags
& PF_X
? 'E' : ' '));
5677 print_vma (segment
->p_align
, PREFIX_HEX
);
5680 putc ('\n', stdout
);
5683 switch (segment
->p_type
)
5686 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5687 required by the ELF standard, several programs, including the Linux
5688 kernel, make use of non-ordered segments. */
5690 && previous_load
->p_vaddr
> segment
->p_vaddr
)
5691 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
5693 if (segment
->p_memsz
< segment
->p_filesz
)
5694 error (_("the segment's file size is larger than its memory size\n"));
5695 previous_load
= segment
;
5699 /* PR 20815 - Verify that the program header is loaded into memory. */
5700 if (i
> 0 && previous_load
!= NULL
)
5701 error (_("the PHDR segment must occur before any LOAD segment\n"));
5702 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
5706 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
5708 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
5709 if (load
->p_type
== PT_LOAD
5710 && load
->p_offset
<= segment
->p_offset
5711 && (load
->p_offset
+ load
->p_filesz
5712 >= segment
->p_offset
+ segment
->p_filesz
)
5713 && load
->p_vaddr
<= segment
->p_vaddr
5714 && (load
->p_vaddr
+ load
->p_filesz
5715 >= segment
->p_vaddr
+ segment
->p_filesz
))
5718 if (j
== filedata
->file_header
.e_phnum
)
5719 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5725 error (_("more than one dynamic segment\n"));
5727 /* By default, assume that the .dynamic section is the first
5728 section in the DYNAMIC segment. */
5729 dynamic_addr
= segment
->p_offset
;
5730 dynamic_size
= segment
->p_filesz
;
5732 /* Try to locate the .dynamic section. If there is
5733 a section header table, we can easily locate it. */
5734 if (filedata
->section_headers
!= NULL
)
5736 Elf_Internal_Shdr
* sec
;
5738 sec
= find_section (filedata
, ".dynamic");
5739 if (sec
== NULL
|| sec
->sh_size
== 0)
5741 /* A corresponding .dynamic section is expected, but on
5742 IA-64/OpenVMS it is OK for it to be missing. */
5743 if (!is_ia64_vms (filedata
))
5744 error (_("no .dynamic section in the dynamic segment\n"));
5748 if (sec
->sh_type
== SHT_NOBITS
)
5755 dynamic_addr
= sec
->sh_offset
;
5756 dynamic_size
= sec
->sh_size
;
5758 /* The PT_DYNAMIC segment, which is used by the run-time
5759 loader, should exactly match the .dynamic section. */
5761 && (dynamic_addr
!= segment
->p_offset
5762 || dynamic_size
!= segment
->p_filesz
))
5764 the .dynamic section is not the same as the dynamic segment\n"));
5767 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5768 segment. Check this after matching against the section headers
5769 so we don't warn on debuginfo file (which have NOBITS .dynamic
5771 if (dynamic_addr
> filedata
->file_size
5772 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
5774 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5781 if (segment
->p_offset
>= filedata
->file_size
5782 || segment
->p_filesz
> filedata
->file_size
- segment
->p_offset
5783 || segment
->p_filesz
- 1 >= (size_t) -2
5784 || fseek (filedata
->handle
,
5785 filedata
->archive_file_offset
+ (long) segment
->p_offset
,
5787 error (_("Unable to find program interpreter name\n"));
5790 size_t len
= segment
->p_filesz
;
5791 free (filedata
->program_interpreter
);
5792 filedata
->program_interpreter
= xmalloc (len
+ 1);
5793 len
= fread (filedata
->program_interpreter
, 1, len
,
5795 filedata
->program_interpreter
[len
] = 0;
5798 printf (_(" [Requesting program interpreter: %s]\n"),
5799 filedata
->program_interpreter
);
5806 && filedata
->section_headers
!= NULL
5807 && filedata
->string_table
!= NULL
)
5809 printf (_("\n Section to Segment mapping:\n"));
5810 printf (_(" Segment Sections...\n"));
5812 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
5815 Elf_Internal_Shdr
* section
;
5817 segment
= filedata
->program_headers
+ i
;
5818 section
= filedata
->section_headers
+ 1;
5820 printf (" %2.2d ", i
);
5822 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
5824 if (!ELF_TBSS_SPECIAL (section
, segment
)
5825 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
5826 printf ("%s ", printable_section_name (filedata
, section
));
5833 filedata
->dynamic_addr
= dynamic_addr
;
5834 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
5838 filedata
->dynamic_addr
= 0;
5839 filedata
->dynamic_size
= 1;
5843 /* Find the file offset corresponding to VMA by using the program headers. */
5846 offset_from_vma (Filedata
* filedata
, bfd_vma vma
, bfd_size_type size
)
5848 Elf_Internal_Phdr
* seg
;
5850 if (! get_program_headers (filedata
))
5852 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5856 for (seg
= filedata
->program_headers
;
5857 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
5860 if (seg
->p_type
!= PT_LOAD
)
5863 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
5864 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
5865 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
5868 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
5869 (unsigned long) vma
);
5874 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5875 If PROBE is true, this is just a probe and we do not generate any error
5876 messages if the load fails. */
5879 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
5881 Elf32_External_Shdr
* shdrs
;
5882 Elf_Internal_Shdr
* internal
;
5884 unsigned int size
= filedata
->file_header
.e_shentsize
;
5885 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5887 /* PR binutils/17531: Cope with unexpected section header sizes. */
5888 if (size
== 0 || num
== 0)
5890 if (size
< sizeof * shdrs
)
5893 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5896 if (!probe
&& size
> sizeof * shdrs
)
5897 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5899 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
5901 probe
? NULL
: _("section headers"));
5905 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5906 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5907 if (filedata
->section_headers
== NULL
)
5910 error (_("Out of memory reading %u section headers\n"), num
);
5915 for (i
= 0, internal
= filedata
->section_headers
;
5919 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5920 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5921 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5922 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5923 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5924 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5925 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5926 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5927 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5928 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5929 if (!probe
&& internal
->sh_link
> num
)
5930 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5931 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5932 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5939 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5942 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
5944 Elf64_External_Shdr
* shdrs
;
5945 Elf_Internal_Shdr
* internal
;
5947 unsigned int size
= filedata
->file_header
.e_shentsize
;
5948 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5950 /* PR binutils/17531: Cope with unexpected section header sizes. */
5951 if (size
== 0 || num
== 0)
5954 if (size
< sizeof * shdrs
)
5957 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5961 if (! probe
&& size
> sizeof * shdrs
)
5962 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5964 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
5965 filedata
->file_header
.e_shoff
,
5967 probe
? NULL
: _("section headers"));
5971 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5972 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5973 if (filedata
->section_headers
== NULL
)
5976 error (_("Out of memory reading %u section headers\n"), num
);
5981 for (i
= 0, internal
= filedata
->section_headers
;
5985 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5986 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5987 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5988 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5989 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5990 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5991 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5992 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5993 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5994 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5995 if (!probe
&& internal
->sh_link
> num
)
5996 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5997 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5998 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6006 get_section_headers (Filedata
*filedata
, bool probe
)
6008 if (filedata
->section_headers
!= NULL
)
6012 return get_32bit_section_headers (filedata
, probe
);
6014 return get_64bit_section_headers (filedata
, probe
);
6017 static Elf_Internal_Sym
*
6018 get_32bit_elf_symbols (Filedata
* filedata
,
6019 Elf_Internal_Shdr
* section
,
6020 unsigned long * num_syms_return
)
6022 unsigned long number
= 0;
6023 Elf32_External_Sym
* esyms
= NULL
;
6024 Elf_External_Sym_Shndx
* shndx
= NULL
;
6025 Elf_Internal_Sym
* isyms
= NULL
;
6026 Elf_Internal_Sym
* psym
;
6028 elf_section_list
* entry
;
6030 if (section
->sh_size
== 0)
6032 if (num_syms_return
!= NULL
)
6033 * num_syms_return
= 0;
6037 /* Run some sanity checks first. */
6038 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6040 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
6041 printable_section_name (filedata
, section
),
6042 (unsigned long) section
->sh_entsize
);
6046 if (section
->sh_size
> filedata
->file_size
)
6048 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
6049 printable_section_name (filedata
, section
),
6050 (unsigned long) section
->sh_size
);
6054 number
= section
->sh_size
/ section
->sh_entsize
;
6056 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
6058 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
6059 (unsigned long) section
->sh_size
,
6060 printable_section_name (filedata
, section
),
6061 (unsigned long) section
->sh_entsize
);
6065 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6066 section
->sh_size
, _("symbols"));
6071 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6073 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
6078 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6082 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6083 entry
->hdr
->sh_offset
,
6084 1, entry
->hdr
->sh_size
,
6085 _("symbol table section indices"));
6089 /* PR17531: file: heap-buffer-overflow */
6090 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6092 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
6093 printable_section_name (filedata
, entry
->hdr
),
6094 (unsigned long) entry
->hdr
->sh_size
,
6095 (unsigned long) section
->sh_size
);
6100 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6104 error (_("Out of memory reading %lu symbols\n"),
6105 (unsigned long) number
);
6109 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6111 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6112 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6113 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6114 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6115 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6117 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6118 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6119 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6120 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6121 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6128 if (num_syms_return
!= NULL
)
6129 * num_syms_return
= isyms
== NULL
? 0 : number
;
6134 static Elf_Internal_Sym
*
6135 get_64bit_elf_symbols (Filedata
* filedata
,
6136 Elf_Internal_Shdr
* section
,
6137 unsigned long * num_syms_return
)
6139 unsigned long number
= 0;
6140 Elf64_External_Sym
* esyms
= NULL
;
6141 Elf_External_Sym_Shndx
* shndx
= NULL
;
6142 Elf_Internal_Sym
* isyms
= NULL
;
6143 Elf_Internal_Sym
* psym
;
6145 elf_section_list
* entry
;
6147 if (section
->sh_size
== 0)
6149 if (num_syms_return
!= NULL
)
6150 * num_syms_return
= 0;
6154 /* Run some sanity checks first. */
6155 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6157 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
6158 printable_section_name (filedata
, section
),
6159 (unsigned long) section
->sh_entsize
);
6163 if (section
->sh_size
> filedata
->file_size
)
6165 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
6166 printable_section_name (filedata
, section
),
6167 (unsigned long) section
->sh_size
);
6171 number
= section
->sh_size
/ section
->sh_entsize
;
6173 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
6175 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
6176 (unsigned long) section
->sh_size
,
6177 printable_section_name (filedata
, section
),
6178 (unsigned long) section
->sh_entsize
);
6182 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6183 section
->sh_size
, _("symbols"));
6188 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6190 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
6195 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6199 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6200 entry
->hdr
->sh_offset
,
6201 1, entry
->hdr
->sh_size
,
6202 _("symbol table section indices"));
6206 /* PR17531: file: heap-buffer-overflow */
6207 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6209 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
6210 printable_section_name (filedata
, entry
->hdr
),
6211 (unsigned long) entry
->hdr
->sh_size
,
6212 (unsigned long) section
->sh_size
);
6217 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6221 error (_("Out of memory reading %lu symbols\n"),
6222 (unsigned long) number
);
6226 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6228 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6229 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6230 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6231 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6233 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6235 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6236 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6237 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6239 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6240 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6247 if (num_syms_return
!= NULL
)
6248 * num_syms_return
= isyms
== NULL
? 0 : number
;
6253 static Elf_Internal_Sym
*
6254 get_elf_symbols (Filedata
*filedata
,
6255 Elf_Internal_Shdr
*section
,
6256 unsigned long *num_syms_return
)
6259 return get_32bit_elf_symbols (filedata
, section
, num_syms_return
);
6261 return get_64bit_elf_symbols (filedata
, section
, num_syms_return
);
6265 get_elf_section_flags (Filedata
* filedata
, bfd_vma sh_flags
)
6267 static char buff
[1024];
6269 unsigned int field_size
= is_32bit_elf
? 8 : 16;
6271 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
6272 bfd_vma os_flags
= 0;
6273 bfd_vma proc_flags
= 0;
6274 bfd_vma unknown_flags
= 0;
6282 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
6283 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
6284 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
6285 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
6286 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
6287 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
6288 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
6289 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
6290 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
6291 /* 9 */ { STRING_COMMA_LEN ("TLS") },
6292 /* IA-64 specific. */
6293 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
6294 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
6295 /* IA-64 OpenVMS specific. */
6296 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
6297 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
6298 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
6299 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
6300 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
6301 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
6303 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
6304 /* SPARC specific. */
6305 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
6306 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
6308 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
6309 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
6310 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
6312 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
6314 /* 25 */ { STRING_COMMA_LEN ("VLE") },
6316 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
6319 if (do_section_details
)
6321 sprintf (buff
, "[%*.*lx]: ",
6322 field_size
, field_size
, (unsigned long) sh_flags
);
6323 p
+= field_size
+ 4;
6330 flag
= sh_flags
& - sh_flags
;
6333 if (do_section_details
)
6337 case SHF_WRITE
: sindex
= 0; break;
6338 case SHF_ALLOC
: sindex
= 1; break;
6339 case SHF_EXECINSTR
: sindex
= 2; break;
6340 case SHF_MERGE
: sindex
= 3; break;
6341 case SHF_STRINGS
: sindex
= 4; break;
6342 case SHF_INFO_LINK
: sindex
= 5; break;
6343 case SHF_LINK_ORDER
: sindex
= 6; break;
6344 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
6345 case SHF_GROUP
: sindex
= 8; break;
6346 case SHF_TLS
: sindex
= 9; break;
6347 case SHF_EXCLUDE
: sindex
= 18; break;
6348 case SHF_COMPRESSED
: sindex
= 20; break;
6352 switch (filedata
->file_header
.e_machine
)
6355 if (flag
== SHF_IA_64_SHORT
)
6357 else if (flag
== SHF_IA_64_NORECOV
)
6360 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
6363 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
6364 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
6365 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
6366 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
6367 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
6368 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
6379 case EM_OLD_SPARCV9
:
6380 case EM_SPARC32PLUS
:
6383 if (flag
== SHF_ORDERED
)
6390 case SHF_ENTRYSECT
: sindex
= 21; break;
6391 case SHF_ARM_PURECODE
: sindex
= 22; break;
6392 case SHF_COMDEF
: sindex
= 23; break;
6397 if (flag
== SHF_PPC_VLE
)
6404 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6407 case ELFOSABI_FREEBSD
:
6408 if (flag
== SHF_GNU_RETAIN
)
6412 if (flag
== SHF_GNU_MBIND
)
6413 /* We should not recognize SHF_GNU_MBIND for
6414 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6415 not set the EI_OSABI header byte. */
6426 if (p
!= buff
+ field_size
+ 4)
6428 if (size
< (10 + 2))
6430 warn (_("Internal error: not enough buffer room for section flag info"));
6431 return _("<unknown>");
6438 size
-= flags
[sindex
].len
;
6439 p
= stpcpy (p
, flags
[sindex
].str
);
6441 else if (flag
& SHF_MASKOS
)
6443 else if (flag
& SHF_MASKPROC
)
6446 unknown_flags
|= flag
;
6452 case SHF_WRITE
: *p
= 'W'; break;
6453 case SHF_ALLOC
: *p
= 'A'; break;
6454 case SHF_EXECINSTR
: *p
= 'X'; break;
6455 case SHF_MERGE
: *p
= 'M'; break;
6456 case SHF_STRINGS
: *p
= 'S'; break;
6457 case SHF_INFO_LINK
: *p
= 'I'; break;
6458 case SHF_LINK_ORDER
: *p
= 'L'; break;
6459 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
6460 case SHF_GROUP
: *p
= 'G'; break;
6461 case SHF_TLS
: *p
= 'T'; break;
6462 case SHF_EXCLUDE
: *p
= 'E'; break;
6463 case SHF_COMPRESSED
: *p
= 'C'; break;
6466 if ((filedata
->file_header
.e_machine
== EM_X86_64
6467 || filedata
->file_header
.e_machine
== EM_L1OM
6468 || filedata
->file_header
.e_machine
== EM_K1OM
)
6469 && flag
== SHF_X86_64_LARGE
)
6471 else if (filedata
->file_header
.e_machine
== EM_ARM
6472 && flag
== SHF_ARM_PURECODE
)
6474 else if (filedata
->file_header
.e_machine
== EM_PPC
6475 && flag
== SHF_PPC_VLE
)
6477 else if (flag
& SHF_MASKOS
)
6479 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6482 case ELFOSABI_FREEBSD
:
6483 if (flag
== SHF_GNU_RETAIN
)
6490 if (flag
== SHF_GNU_MBIND
)
6492 /* We should not recognize SHF_GNU_MBIND for
6493 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6494 not set the EI_OSABI header byte. */
6501 sh_flags
&= ~SHF_MASKOS
;
6505 else if (flag
& SHF_MASKPROC
)
6508 sh_flags
&= ~ SHF_MASKPROC
;
6518 if (do_section_details
)
6522 size
-= 5 + field_size
;
6523 if (p
!= buff
+ field_size
+ 4)
6527 warn (_("Internal error: not enough buffer room for section flag info"));
6528 return _("<unknown>");
6534 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
6535 (unsigned long) os_flags
);
6536 p
+= 5 + field_size
;
6540 size
-= 7 + field_size
;
6541 if (p
!= buff
+ field_size
+ 4)
6545 warn (_("Internal error: not enough buffer room for section flag info"));
6546 return _("<unknown>");
6552 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
6553 (unsigned long) proc_flags
);
6554 p
+= 7 + field_size
;
6558 size
-= 10 + field_size
;
6559 if (p
!= buff
+ field_size
+ 4)
6563 warn (_("Internal error: not enough buffer room for section flag info"));
6564 return _("<unknown>");
6570 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
6571 (unsigned long) unknown_flags
);
6572 p
+= 10 + field_size
;
6580 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
6581 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
, bfd_size_type size
)
6585 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
6587 if (size
< sizeof (* echdr
))
6589 error (_("Compressed section is too small even for a compression header\n"));
6593 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6594 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6595 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6596 return sizeof (*echdr
);
6600 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
6602 if (size
< sizeof (* echdr
))
6604 error (_("Compressed section is too small even for a compression header\n"));
6608 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6609 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6610 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6611 return sizeof (*echdr
);
6616 process_section_headers (Filedata
* filedata
)
6618 Elf_Internal_Shdr
* section
;
6621 if (filedata
->file_header
.e_shnum
== 0)
6623 /* PR binutils/12467. */
6624 if (filedata
->file_header
.e_shoff
!= 0)
6626 warn (_("possibly corrupt ELF file header - it has a non-zero"
6627 " section header offset, but no section headers\n"));
6630 else if (do_sections
)
6631 printf (_("\nThere are no sections in this file.\n"));
6636 if (do_sections
&& !do_header
)
6638 if (filedata
->is_separate
&& process_links
)
6639 printf (_("In linked file '%s': "), filedata
->file_name
);
6640 if (! filedata
->is_separate
|| process_links
)
6641 printf (ngettext ("There is %d section header, "
6642 "starting at offset 0x%lx:\n",
6643 "There are %d section headers, "
6644 "starting at offset 0x%lx:\n",
6645 filedata
->file_header
.e_shnum
),
6646 filedata
->file_header
.e_shnum
,
6647 (unsigned long) filedata
->file_header
.e_shoff
);
6650 if (!get_section_headers (filedata
, false))
6653 /* Read in the string table, so that we have names to display. */
6654 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
6655 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
6657 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
6659 if (section
->sh_size
!= 0)
6661 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6662 1, section
->sh_size
,
6665 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
6669 /* Scan the sections for the dynamic symbol table
6670 and dynamic string table and debug sections. */
6671 eh_addr_size
= is_32bit_elf
? 4 : 8;
6672 switch (filedata
->file_header
.e_machine
)
6675 case EM_MIPS_RS3_LE
:
6676 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6677 FDE addresses. However, the ABI also has a semi-official ILP32
6678 variant for which the normal FDE address size rules apply.
6680 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6681 section, where XX is the size of longs in bits. Unfortunately,
6682 earlier compilers provided no way of distinguishing ILP32 objects
6683 from LP64 objects, so if there's any doubt, we should assume that
6684 the official LP64 form is being used. */
6685 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
6686 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
6692 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
6694 case E_H8_MACH_H8300
:
6695 case E_H8_MACH_H8300HN
:
6696 case E_H8_MACH_H8300SN
:
6697 case E_H8_MACH_H8300SXN
:
6700 case E_H8_MACH_H8300H
:
6701 case E_H8_MACH_H8300S
:
6702 case E_H8_MACH_H8300SX
:
6710 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
6712 case EF_M32C_CPU_M16C
:
6719 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6722 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6723 if (section->sh_entsize != expected_entsize) \
6726 sprintf_vma (buf, section->sh_entsize); \
6727 /* Note: coded this way so that there is a single string for \
6729 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6730 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6731 (unsigned) expected_entsize); \
6732 section->sh_entsize = expected_entsize; \
6737 #define CHECK_ENTSIZE(section, i, type) \
6738 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6739 sizeof (Elf64_External_##type))
6741 for (i
= 0, section
= filedata
->section_headers
;
6742 i
< filedata
->file_header
.e_shnum
;
6745 const char *name
= section_name_print (filedata
, section
);
6747 /* Run some sanity checks on the headers and
6748 possibly fill in some file data as well. */
6749 switch (section
->sh_type
)
6752 if (filedata
->dynamic_symbols
!= NULL
)
6754 error (_("File contains multiple dynamic symbol tables\n"));
6758 CHECK_ENTSIZE (section
, i
, Sym
);
6759 filedata
->dynamic_symbols
6760 = get_elf_symbols (filedata
, section
, &filedata
->num_dynamic_syms
);
6761 filedata
->dynamic_symtab_section
= section
;
6765 if (streq (name
, ".dynstr"))
6767 if (filedata
->dynamic_strings
!= NULL
)
6769 error (_("File contains multiple dynamic string tables\n"));
6773 filedata
->dynamic_strings
6774 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6775 1, section
->sh_size
, _("dynamic strings"));
6776 filedata
->dynamic_strings_length
6777 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
6778 filedata
->dynamic_strtab_section
= section
;
6782 case SHT_SYMTAB_SHNDX
:
6784 elf_section_list
* entry
= xmalloc (sizeof * entry
);
6786 entry
->hdr
= section
;
6787 entry
->next
= filedata
->symtab_shndx_list
;
6788 filedata
->symtab_shndx_list
= entry
;
6793 CHECK_ENTSIZE (section
, i
, Sym
);
6797 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
6801 CHECK_ENTSIZE (section
, i
, Rel
);
6802 if (do_checks
&& section
->sh_size
== 0)
6803 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6807 CHECK_ENTSIZE (section
, i
, Rela
);
6808 if (do_checks
&& section
->sh_size
== 0)
6809 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6814 /* Having a zero sized section is not illegal according to the
6815 ELF standard, but it might be an indication that something
6816 is wrong. So issue a warning if we are running in lint mode. */
6817 if (do_checks
&& section
->sh_size
== 0)
6818 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
6825 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
6826 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
6827 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
6828 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
6830 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
6831 && (startswith (name
, ".debug_")
6832 || startswith (name
, ".zdebug_")))
6835 name
+= sizeof (".zdebug_") - 1;
6837 name
+= sizeof (".debug_") - 1;
6840 || (do_debug_info
&& startswith (name
, "info"))
6841 || (do_debug_info
&& startswith (name
, "types"))
6842 || (do_debug_abbrevs
&& startswith (name
, "abbrev"))
6843 || (do_debug_lines
&& strcmp (name
, "line") == 0)
6844 || (do_debug_lines
&& startswith (name
, "line."))
6845 || (do_debug_pubnames
&& startswith (name
, "pubnames"))
6846 || (do_debug_pubtypes
&& startswith (name
, "pubtypes"))
6847 || (do_debug_pubnames
&& startswith (name
, "gnu_pubnames"))
6848 || (do_debug_pubtypes
&& startswith (name
, "gnu_pubtypes"))
6849 || (do_debug_aranges
&& startswith (name
, "aranges"))
6850 || (do_debug_ranges
&& startswith (name
, "ranges"))
6851 || (do_debug_ranges
&& startswith (name
, "rnglists"))
6852 || (do_debug_frames
&& startswith (name
, "frame"))
6853 || (do_debug_macinfo
&& startswith (name
, "macinfo"))
6854 || (do_debug_macinfo
&& startswith (name
, "macro"))
6855 || (do_debug_str
&& startswith (name
, "str"))
6856 || (do_debug_links
&& startswith (name
, "sup"))
6857 || (do_debug_str_offsets
&& startswith (name
, "str_offsets"))
6858 || (do_debug_loc
&& startswith (name
, "loc"))
6859 || (do_debug_loc
&& startswith (name
, "loclists"))
6860 || (do_debug_addr
&& startswith (name
, "addr"))
6861 || (do_debug_cu_index
&& startswith (name
, "cu_index"))
6862 || (do_debug_cu_index
&& startswith (name
, "tu_index"))
6864 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6866 /* Linkonce section to be combined with .debug_info at link time. */
6867 else if ((do_debugging
|| do_debug_info
)
6868 && startswith (name
, ".gnu.linkonce.wi."))
6869 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6870 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
6871 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6872 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
6873 || streq (name
, ".debug_names")))
6874 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6875 /* Trace sections for Itanium VMS. */
6876 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
6877 || do_trace_aranges
)
6878 && startswith (name
, ".trace_"))
6880 name
+= sizeof (".trace_") - 1;
6883 || (do_trace_info
&& streq (name
, "info"))
6884 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
6885 || (do_trace_aranges
&& streq (name
, "aranges"))
6887 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6889 else if ((do_debugging
|| do_debug_links
)
6890 && (startswith (name
, ".gnu_debuglink")
6891 || startswith (name
, ".gnu_debugaltlink")))
6892 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6898 if (filedata
->is_separate
&& ! process_links
)
6901 if (filedata
->is_separate
)
6902 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
6903 else if (filedata
->file_header
.e_shnum
> 1)
6904 printf (_("\nSection Headers:\n"));
6906 printf (_("\nSection Header:\n"));
6910 if (do_section_details
)
6912 printf (_(" [Nr] Name\n"));
6913 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
6917 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6921 if (do_section_details
)
6923 printf (_(" [Nr] Name\n"));
6924 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
6928 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6932 if (do_section_details
)
6934 printf (_(" [Nr] Name\n"));
6935 printf (_(" Type Address Offset Link\n"));
6936 printf (_(" Size EntSize Info Align\n"));
6940 printf (_(" [Nr] Name Type Address Offset\n"));
6941 printf (_(" Size EntSize Flags Link Info Align\n"));
6945 if (do_section_details
)
6946 printf (_(" Flags\n"));
6948 for (i
= 0, section
= filedata
->section_headers
;
6949 i
< filedata
->file_header
.e_shnum
;
6952 /* Run some sanity checks on the section header. */
6954 /* Check the sh_link field. */
6955 switch (section
->sh_type
)
6959 if (section
->sh_link
== 0
6960 && (filedata
->file_header
.e_type
== ET_EXEC
6961 || filedata
->file_header
.e_type
== ET_DYN
))
6962 /* A dynamic relocation section where all entries use a
6963 zero symbol index need not specify a symtab section. */
6966 case SHT_SYMTAB_SHNDX
:
6970 case SHT_GNU_versym
:
6971 if (section
->sh_link
== 0
6972 || section
->sh_link
>= filedata
->file_header
.e_shnum
6973 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
6974 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
6975 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6976 i
, section
->sh_link
);
6982 case SHT_GNU_verneed
:
6983 case SHT_GNU_verdef
:
6984 case SHT_GNU_LIBLIST
:
6985 if (section
->sh_link
== 0
6986 || section
->sh_link
>= filedata
->file_header
.e_shnum
6987 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
6988 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6989 i
, section
->sh_link
);
6992 case SHT_INIT_ARRAY
:
6993 case SHT_FINI_ARRAY
:
6994 case SHT_PREINIT_ARRAY
:
6995 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6996 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6997 i
, section
->sh_link
);
7001 /* FIXME: Add support for target specific section types. */
7002 #if 0 /* Currently we do not check other section types as there are too
7003 many special cases. Stab sections for example have a type
7004 of SHT_PROGBITS but an sh_link field that links to the .stabstr
7006 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7007 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7008 i
, section
->sh_link
);
7013 /* Check the sh_info field. */
7014 switch (section
->sh_type
)
7018 if (section
->sh_info
== 0
7019 && (filedata
->file_header
.e_type
== ET_EXEC
7020 || filedata
->file_header
.e_type
== ET_DYN
))
7021 /* Dynamic relocations apply to segments, so they do not
7022 need to specify the section they relocate. */
7024 if (section
->sh_info
== 0
7025 || section
->sh_info
>= filedata
->file_header
.e_shnum
7026 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
7027 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
7028 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
7029 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
7030 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
7031 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
7032 /* FIXME: Are other section types valid ? */
7033 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
7034 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
7035 i
, section
->sh_info
);
7040 case SHT_SYMTAB_SHNDX
:
7041 case SHT_INIT_ARRAY
:
7042 case SHT_FINI_ARRAY
:
7043 case SHT_PREINIT_ARRAY
:
7044 if (section
->sh_info
!= 0)
7045 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7046 i
, section
->sh_info
);
7052 /* A symbol index - we assume that it is valid. */
7056 /* FIXME: Add support for target specific section types. */
7057 if (section
->sh_type
== SHT_NOBITS
)
7058 /* NOBITS section headers with non-zero sh_info fields can be
7059 created when a binary is stripped of everything but its debug
7060 information. The stripped sections have their headers
7061 preserved but their types set to SHT_NOBITS. So do not check
7062 this type of section. */
7064 else if (section
->sh_flags
& SHF_INFO_LINK
)
7066 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
7067 warn (_("[%2u]: Expected link to another section in info field"), i
);
7069 else if (section
->sh_type
< SHT_LOOS
7070 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
7071 && section
->sh_info
!= 0)
7072 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7073 i
, section
->sh_info
);
7077 /* Check the sh_size field. */
7078 if (section
->sh_size
> filedata
->file_size
7079 && section
->sh_type
!= SHT_NOBITS
7080 && section
->sh_type
!= SHT_NULL
7081 && section
->sh_type
< SHT_LOOS
)
7082 warn (_("Size of section %u is larger than the entire file!\n"), i
);
7084 printf (" [%2u] ", i
);
7085 if (do_section_details
)
7086 printf ("%s\n ", printable_section_name (filedata
, section
));
7088 print_symbol (-17, section_name_print (filedata
, section
));
7090 printf (do_wide
? " %-15s " : " %-15.15s ",
7091 get_section_type_name (filedata
, section
->sh_type
));
7095 const char * link_too_big
= NULL
;
7097 print_vma (section
->sh_addr
, LONG_HEX
);
7099 printf ( " %6.6lx %6.6lx %2.2lx",
7100 (unsigned long) section
->sh_offset
,
7101 (unsigned long) section
->sh_size
,
7102 (unsigned long) section
->sh_entsize
);
7104 if (do_section_details
)
7105 fputs (" ", stdout
);
7107 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7109 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
7112 /* The sh_link value is out of range. Normally this indicates
7113 an error but it can have special values in Solaris binaries. */
7114 switch (filedata
->file_header
.e_machine
)
7121 case EM_OLD_SPARCV9
:
7122 case EM_SPARC32PLUS
:
7125 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
7126 link_too_big
= "BEFORE";
7127 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
7128 link_too_big
= "AFTER";
7135 if (do_section_details
)
7137 if (link_too_big
!= NULL
&& * link_too_big
)
7138 printf ("<%s> ", link_too_big
);
7140 printf ("%2u ", section
->sh_link
);
7141 printf ("%3u %2lu\n", section
->sh_info
,
7142 (unsigned long) section
->sh_addralign
);
7145 printf ("%2u %3u %2lu\n",
7148 (unsigned long) section
->sh_addralign
);
7150 if (link_too_big
&& ! * link_too_big
)
7151 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
7152 i
, section
->sh_link
);
7156 print_vma (section
->sh_addr
, LONG_HEX
);
7158 if ((long) section
->sh_offset
== section
->sh_offset
)
7159 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
7163 print_vma (section
->sh_offset
, LONG_HEX
);
7166 if ((unsigned long) section
->sh_size
== section
->sh_size
)
7167 printf (" %6.6lx", (unsigned long) section
->sh_size
);
7171 print_vma (section
->sh_size
, LONG_HEX
);
7174 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
7175 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
7179 print_vma (section
->sh_entsize
, LONG_HEX
);
7182 if (do_section_details
)
7183 fputs (" ", stdout
);
7185 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7187 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
7189 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
7190 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
7193 print_vma (section
->sh_addralign
, DEC
);
7197 else if (do_section_details
)
7200 print_vma (section
->sh_addr
, LONG_HEX
);
7201 if ((long) section
->sh_offset
== section
->sh_offset
)
7202 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
7206 print_vma (section
->sh_offset
, LONG_HEX
);
7208 printf (" %u\n ", section
->sh_link
);
7209 print_vma (section
->sh_size
, LONG_HEX
);
7211 print_vma (section
->sh_entsize
, LONG_HEX
);
7213 printf (" %-16u %lu\n",
7215 (unsigned long) section
->sh_addralign
);
7220 print_vma (section
->sh_addr
, LONG_HEX
);
7221 if ((long) section
->sh_offset
== section
->sh_offset
)
7222 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
7226 print_vma (section
->sh_offset
, LONG_HEX
);
7229 print_vma (section
->sh_size
, LONG_HEX
);
7231 print_vma (section
->sh_entsize
, LONG_HEX
);
7233 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7235 printf (" %2u %3u %lu\n",
7238 (unsigned long) section
->sh_addralign
);
7241 if (do_section_details
)
7243 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
7244 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
7246 /* Minimum section size is 12 bytes for 32-bit compression
7247 header + 12 bytes for compressed data header. */
7248 unsigned char buf
[24];
7250 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
7251 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
7252 sizeof (buf
), _("compression header")))
7254 Elf_Internal_Chdr chdr
;
7256 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
7257 printf (_(" [<corrupt>]\n"));
7260 if (chdr
.ch_type
== ELFCOMPRESS_ZLIB
)
7263 printf (_(" [<unknown>: 0x%x], "),
7265 print_vma (chdr
.ch_size
, LONG_HEX
);
7266 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
7273 if (!do_section_details
)
7275 /* The ordering of the letters shown here matches the ordering of the
7276 corresponding SHF_xxx values, and hence the order in which these
7277 letters will be displayed to the user. */
7278 printf (_("Key to Flags:\n\
7279 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
7280 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
7281 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
7282 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7285 case ELFOSABI_FREEBSD
:
7286 printf (_("R (retain), "));
7289 printf (_("D (mbind), "));
7294 if (filedata
->file_header
.e_machine
== EM_X86_64
7295 || filedata
->file_header
.e_machine
== EM_L1OM
7296 || filedata
->file_header
.e_machine
== EM_K1OM
)
7297 printf (_("l (large), "));
7298 else if (filedata
->file_header
.e_machine
== EM_ARM
)
7299 printf (_("y (purecode), "));
7300 else if (filedata
->file_header
.e_machine
== EM_PPC
)
7301 printf (_("v (VLE), "));
7302 printf ("p (processor specific)\n");
7309 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
7310 Elf_Internal_Sym
**symtab
, unsigned long *nsyms
,
7311 char **strtab
, unsigned long *strtablen
)
7315 *symtab
= get_elf_symbols (filedata
, symsec
, nsyms
);
7317 if (*symtab
== NULL
)
7320 if (symsec
->sh_link
!= 0)
7322 Elf_Internal_Shdr
*strsec
;
7324 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
7326 error (_("Bad sh_link in symbol table section\n"));
7333 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
7335 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7336 1, strsec
->sh_size
, _("string table"));
7337 if (*strtab
== NULL
)
7344 *strtablen
= strsec
->sh_size
;
7350 get_group_flags (unsigned int flags
)
7352 static char buff
[128];
7356 else if (flags
== GRP_COMDAT
)
7359 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
7361 flags
& GRP_MASKOS
? _("<OS specific>") : "",
7362 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
7363 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
7364 ? _("<unknown>") : ""));
7370 process_section_groups (Filedata
* filedata
)
7372 Elf_Internal_Shdr
* section
;
7374 struct group
* group
;
7375 Elf_Internal_Shdr
* symtab_sec
;
7376 Elf_Internal_Shdr
* strtab_sec
;
7377 Elf_Internal_Sym
* symtab
;
7378 unsigned long num_syms
;
7382 /* Don't process section groups unless needed. */
7383 if (!do_unwind
&& !do_section_groups
)
7386 if (filedata
->file_header
.e_shnum
== 0)
7388 if (do_section_groups
)
7390 if (filedata
->is_separate
)
7391 printf (_("\nThere are no sections group in linked file '%s'.\n"),
7392 filedata
->file_name
);
7394 printf (_("\nThere are no section groups in this file.\n"));
7399 if (filedata
->section_headers
== NULL
)
7401 error (_("Section headers are not available!\n"));
7402 /* PR 13622: This can happen with a corrupt ELF header. */
7406 filedata
->section_headers_groups
7407 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
7408 sizeof (struct group
*));
7410 if (filedata
->section_headers_groups
== NULL
)
7412 error (_("Out of memory reading %u section group headers\n"),
7413 filedata
->file_header
.e_shnum
);
7417 /* Scan the sections for the group section. */
7418 filedata
->group_count
= 0;
7419 for (i
= 0, section
= filedata
->section_headers
;
7420 i
< filedata
->file_header
.e_shnum
;
7422 if (section
->sh_type
== SHT_GROUP
)
7423 filedata
->group_count
++;
7425 if (filedata
->group_count
== 0)
7427 if (do_section_groups
)
7429 if (filedata
->is_separate
)
7430 printf (_("\nThere are no section groups in linked file '%s'.\n"),
7431 filedata
->file_name
);
7433 printf (_("\nThere are no section groups in this file.\n"));
7439 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
7440 sizeof (struct group
));
7442 if (filedata
->section_groups
== NULL
)
7444 error (_("Out of memory reading %lu groups\n"),
7445 (unsigned long) filedata
->group_count
);
7456 if (filedata
->is_separate
)
7457 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
7459 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
7460 i
< filedata
->file_header
.e_shnum
;
7463 if (section
->sh_type
== SHT_GROUP
)
7465 const char * name
= printable_section_name (filedata
, section
);
7466 const char * group_name
;
7467 unsigned char * start
;
7468 unsigned char * indices
;
7469 unsigned int entry
, j
, size
;
7470 Elf_Internal_Shdr
* sec
;
7471 Elf_Internal_Sym
* sym
;
7473 /* Get the symbol table. */
7474 if (section
->sh_link
>= filedata
->file_header
.e_shnum
7475 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
7478 error (_("Bad sh_link in group section `%s'\n"), name
);
7482 if (symtab_sec
!= sec
)
7486 symtab
= get_elf_symbols (filedata
, symtab_sec
, & num_syms
);
7491 error (_("Corrupt header in group section `%s'\n"), name
);
7495 if (section
->sh_info
>= num_syms
)
7497 error (_("Bad sh_info in group section `%s'\n"), name
);
7501 sym
= symtab
+ section
->sh_info
;
7503 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7505 if (sym
->st_shndx
== 0
7506 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
7508 error (_("Bad sh_info in group section `%s'\n"), name
);
7512 group_name
= section_name_print (filedata
,
7513 filedata
->section_headers
7522 /* Get the string table. */
7523 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
7531 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
7536 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
7537 1, strtab_sec
->sh_size
,
7539 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
7541 group_name
= sym
->st_name
< strtab_size
7542 ? strtab
+ sym
->st_name
: _("<corrupt>");
7545 /* PR 17531: file: loop. */
7546 if (section
->sh_entsize
> section
->sh_size
)
7548 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
7549 printable_section_name (filedata
, section
),
7550 (unsigned long) section
->sh_entsize
,
7551 (unsigned long) section
->sh_size
);
7555 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
7556 1, section
->sh_size
,
7562 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
7563 entry
= byte_get (indices
, 4);
7566 if (do_section_groups
)
7568 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
7569 get_group_flags (entry
), i
, name
, group_name
, size
);
7571 printf (_(" [Index] Name\n"));
7574 group
->group_index
= i
;
7576 for (j
= 0; j
< size
; j
++)
7578 struct group_list
* g
;
7580 entry
= byte_get (indices
, 4);
7583 if (entry
>= filedata
->file_header
.e_shnum
)
7585 static unsigned num_group_errors
= 0;
7587 if (num_group_errors
++ < 10)
7589 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
7590 entry
, i
, filedata
->file_header
.e_shnum
- 1);
7591 if (num_group_errors
== 10)
7592 warn (_("Further error messages about overlarge group section indices suppressed\n"));
7597 if (filedata
->section_headers_groups
[entry
] != NULL
)
7601 static unsigned num_errs
= 0;
7603 if (num_errs
++ < 10)
7605 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7607 filedata
->section_headers_groups
[entry
]->group_index
);
7609 warn (_("Further error messages about already contained group sections suppressed\n"));
7615 /* Intel C/C++ compiler may put section 0 in a
7616 section group. We just warn it the first time
7617 and ignore it afterwards. */
7618 static bool warned
= false;
7621 error (_("section 0 in group section [%5u]\n"),
7622 filedata
->section_headers_groups
[entry
]->group_index
);
7628 filedata
->section_headers_groups
[entry
] = group
;
7630 if (do_section_groups
)
7632 sec
= filedata
->section_headers
+ entry
;
7633 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
7636 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
7637 g
->section_index
= entry
;
7638 g
->next
= group
->root
;
7653 /* Data used to display dynamic fixups. */
7655 struct ia64_vms_dynfixup
7657 bfd_vma needed_ident
; /* Library ident number. */
7658 bfd_vma needed
; /* Index in the dstrtab of the library name. */
7659 bfd_vma fixup_needed
; /* Index of the library. */
7660 bfd_vma fixup_rela_cnt
; /* Number of fixups. */
7661 bfd_vma fixup_rela_off
; /* Fixups offset in the dynamic segment. */
7664 /* Data used to display dynamic relocations. */
7666 struct ia64_vms_dynimgrela
7668 bfd_vma img_rela_cnt
; /* Number of relocations. */
7669 bfd_vma img_rela_off
; /* Reloc offset in the dynamic segment. */
7672 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7676 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
7677 struct ia64_vms_dynfixup
* fixup
,
7678 const char * strtab
,
7679 unsigned int strtab_sz
)
7681 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
7683 const char * lib_name
;
7685 imfs
= get_data (NULL
, filedata
,
7686 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
7687 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
7688 _("dynamic section image fixups"));
7692 if (fixup
->needed
< strtab_sz
)
7693 lib_name
= strtab
+ fixup
->needed
;
7696 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7697 (unsigned long) fixup
->needed
);
7701 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7702 (int) fixup
->fixup_needed
, lib_name
, (long) fixup
->needed_ident
);
7704 (_("Seg Offset Type SymVec DataType\n"));
7706 for (i
= 0; i
< (long) fixup
->fixup_rela_cnt
; i
++)
7711 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
7712 printf_vma ((bfd_vma
) BYTE_GET (imfs
[i
].fixup_offset
));
7713 type
= BYTE_GET (imfs
[i
].type
);
7714 rtype
= elf_ia64_reloc_type (type
);
7716 printf (" 0x%08x ", type
);
7718 printf (" %-32s ", rtype
);
7719 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
7720 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
7727 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7730 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
7732 Elf64_External_VMS_IMAGE_RELA
*imrs
;
7735 imrs
= get_data (NULL
, filedata
,
7736 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
7737 sizeof (*imrs
), imgrela
->img_rela_cnt
,
7738 _("dynamic section image relocations"));
7742 printf (_("\nImage relocs\n"));
7744 (_("Seg Offset Type Addend Seg Sym Off\n"));
7746 for (i
= 0; i
< (long) imgrela
->img_rela_cnt
; i
++)
7751 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
7752 printf ("%08" BFD_VMA_FMT
"x ",
7753 (bfd_vma
) BYTE_GET (imrs
[i
].rela_offset
));
7754 type
= BYTE_GET (imrs
[i
].type
);
7755 rtype
= elf_ia64_reloc_type (type
);
7757 printf ("0x%08x ", type
);
7759 printf ("%-31s ", rtype
);
7760 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
7761 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
7762 printf ("%08" BFD_VMA_FMT
"x\n",
7763 (bfd_vma
) BYTE_GET (imrs
[i
].sym_offset
));
7770 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
7773 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
7775 struct ia64_vms_dynfixup fixup
;
7776 struct ia64_vms_dynimgrela imgrela
;
7777 Elf_Internal_Dyn
*entry
;
7778 bfd_vma strtab_off
= 0;
7779 bfd_vma strtab_sz
= 0;
7780 char *strtab
= NULL
;
7783 memset (&fixup
, 0, sizeof (fixup
));
7784 memset (&imgrela
, 0, sizeof (imgrela
));
7786 /* Note: the order of the entries is specified by the OpenVMS specs. */
7787 for (entry
= filedata
->dynamic_section
;
7788 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
7791 switch (entry
->d_tag
)
7793 case DT_IA_64_VMS_STRTAB_OFFSET
:
7794 strtab_off
= entry
->d_un
.d_val
;
7797 strtab_sz
= entry
->d_un
.d_val
;
7799 strtab
= get_data (NULL
, filedata
,
7800 filedata
->dynamic_addr
+ strtab_off
,
7801 1, strtab_sz
, _("dynamic string section"));
7806 case DT_IA_64_VMS_NEEDED_IDENT
:
7807 fixup
.needed_ident
= entry
->d_un
.d_val
;
7810 fixup
.needed
= entry
->d_un
.d_val
;
7812 case DT_IA_64_VMS_FIXUP_NEEDED
:
7813 fixup
.fixup_needed
= entry
->d_un
.d_val
;
7815 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
7816 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
7818 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
7819 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
7820 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
7823 case DT_IA_64_VMS_IMG_RELA_CNT
:
7824 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
7826 case DT_IA_64_VMS_IMG_RELA_OFF
:
7827 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
7828 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
7849 dynamic_relocations
[] =
7851 { "REL", DT_REL
, DT_RELSZ
, false },
7852 { "RELA", DT_RELA
, DT_RELASZ
, true },
7853 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
7856 /* Process the reloc section. */
7859 process_relocs (Filedata
* filedata
)
7861 unsigned long rel_size
;
7862 unsigned long rel_offset
;
7867 if (do_using_dynamic
)
7871 bool has_dynamic_reloc
;
7874 has_dynamic_reloc
= false;
7876 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7878 is_rela
= dynamic_relocations
[i
].rela
;
7879 name
= dynamic_relocations
[i
].name
;
7880 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
7881 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
7884 has_dynamic_reloc
= true;
7886 if (is_rela
== UNKNOWN
)
7888 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
7889 switch (filedata
->dynamic_info
[DT_PLTREL
])
7902 if (filedata
->is_separate
)
7904 (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"),
7905 filedata
->file_name
, name
, rel_offset
, rel_size
);
7908 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7909 name
, rel_offset
, rel_size
);
7911 dump_relocations (filedata
,
7912 offset_from_vma (filedata
, rel_offset
, rel_size
),
7914 filedata
->dynamic_symbols
,
7915 filedata
->num_dynamic_syms
,
7916 filedata
->dynamic_strings
,
7917 filedata
->dynamic_strings_length
,
7918 is_rela
, true /* is_dynamic */);
7922 if (is_ia64_vms (filedata
))
7923 if (process_ia64_vms_dynamic_relocs (filedata
))
7924 has_dynamic_reloc
= true;
7926 if (! has_dynamic_reloc
)
7928 if (filedata
->is_separate
)
7929 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
7930 filedata
->file_name
);
7932 printf (_("\nThere are no dynamic relocations in this file.\n"));
7937 Elf_Internal_Shdr
* section
;
7941 for (i
= 0, section
= filedata
->section_headers
;
7942 i
< filedata
->file_header
.e_shnum
;
7945 if ( section
->sh_type
!= SHT_RELA
7946 && section
->sh_type
!= SHT_REL
)
7949 rel_offset
= section
->sh_offset
;
7950 rel_size
= section
->sh_size
;
7955 unsigned long num_rela
;
7957 if (filedata
->is_separate
)
7958 printf (_("\nIn linked file '%s' relocation section "),
7959 filedata
->file_name
);
7961 printf (_("\nRelocation section "));
7963 if (filedata
->string_table
== NULL
)
7964 printf ("%d", section
->sh_name
);
7966 printf ("'%s'", printable_section_name (filedata
, section
));
7968 num_rela
= rel_size
/ section
->sh_entsize
;
7969 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7970 " at offset 0x%lx contains %lu entries:\n",
7972 rel_offset
, num_rela
);
7974 is_rela
= section
->sh_type
== SHT_RELA
;
7976 if (section
->sh_link
!= 0
7977 && section
->sh_link
< filedata
->file_header
.e_shnum
)
7979 Elf_Internal_Shdr
* symsec
;
7980 Elf_Internal_Sym
* symtab
;
7981 unsigned long nsyms
;
7982 unsigned long strtablen
= 0;
7983 char * strtab
= NULL
;
7985 symsec
= filedata
->section_headers
+ section
->sh_link
;
7986 if (symsec
->sh_type
!= SHT_SYMTAB
7987 && symsec
->sh_type
!= SHT_DYNSYM
)
7990 if (!get_symtab (filedata
, symsec
,
7991 &symtab
, &nsyms
, &strtab
, &strtablen
))
7994 dump_relocations (filedata
, rel_offset
, rel_size
,
7995 symtab
, nsyms
, strtab
, strtablen
,
7997 symsec
->sh_type
== SHT_DYNSYM
);
8002 dump_relocations (filedata
, rel_offset
, rel_size
,
8003 NULL
, 0, NULL
, 0, is_rela
,
8004 false /* is_dynamic */);
8012 /* Users sometimes forget the -D option, so try to be helpful. */
8013 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8015 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
8017 if (filedata
->is_separate
)
8018 printf (_("\nThere are no static relocations in linked file '%s'."),
8019 filedata
->file_name
);
8021 printf (_("\nThere are no static relocations in this file."));
8022 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
8027 if (i
== ARRAY_SIZE (dynamic_relocations
))
8029 if (filedata
->is_separate
)
8030 printf (_("\nThere are no relocations in linked file '%s'.\n"),
8031 filedata
->file_name
);
8033 printf (_("\nThere are no relocations in this file.\n"));
8041 /* An absolute address consists of a section and an offset. If the
8042 section is NULL, the offset itself is the address, otherwise, the
8043 address equals to LOAD_ADDRESS(section) + offset. */
8047 unsigned short section
;
8051 /* Find the nearest symbol at or below ADDR. Returns the symbol
8052 name, if found, and the offset from the symbol to ADDR. */
8055 find_symbol_for_address (Filedata
* filedata
,
8056 Elf_Internal_Sym
* symtab
,
8057 unsigned long nsyms
,
8058 const char * strtab
,
8059 unsigned long strtab_size
,
8060 struct absaddr addr
,
8061 const char ** symname
,
8064 bfd_vma dist
= 0x100000;
8065 Elf_Internal_Sym
* sym
;
8066 Elf_Internal_Sym
* beg
;
8067 Elf_Internal_Sym
* end
;
8068 Elf_Internal_Sym
* best
= NULL
;
8070 REMOVE_ARCH_BITS (addr
.offset
);
8072 end
= symtab
+ nsyms
;
8078 sym
= beg
+ (end
- beg
) / 2;
8080 value
= sym
->st_value
;
8081 REMOVE_ARCH_BITS (value
);
8083 if (sym
->st_name
!= 0
8084 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
8085 && addr
.offset
>= value
8086 && addr
.offset
- value
< dist
)
8089 dist
= addr
.offset
- value
;
8094 if (addr
.offset
< value
)
8102 *symname
= (best
->st_name
>= strtab_size
8103 ? _("<corrupt>") : strtab
+ best
->st_name
);
8109 *offset
= addr
.offset
;
8112 static /* signed */ int
8113 symcmp (const void *p
, const void *q
)
8115 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
8116 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
8118 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
8121 /* Process the unwind section. */
8123 #include "unwind-ia64.h"
8125 struct ia64_unw_table_entry
8127 struct absaddr start
;
8129 struct absaddr info
;
8132 struct ia64_unw_aux_info
8134 struct ia64_unw_table_entry
* table
; /* Unwind table. */
8135 unsigned long table_len
; /* Length of unwind table. */
8136 unsigned char * info
; /* Unwind info. */
8137 unsigned long info_size
; /* Size of unwind info. */
8138 bfd_vma info_addr
; /* Starting address of unwind info. */
8139 bfd_vma seg_base
; /* Starting address of segment. */
8140 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8141 unsigned long nsyms
; /* Number of symbols. */
8142 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8143 unsigned long nfuns
; /* Number of entries in funtab. */
8144 char * strtab
; /* The string table. */
8145 unsigned long strtab_size
; /* Size of string table. */
8149 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
8151 struct ia64_unw_table_entry
* tp
;
8152 unsigned long j
, nfuns
;
8156 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8157 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8158 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8159 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8161 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8163 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8167 const unsigned char * dp
;
8168 const unsigned char * head
;
8169 const unsigned char * end
;
8170 const char * procname
;
8172 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8173 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
8175 fputs ("\n<", stdout
);
8179 fputs (procname
, stdout
);
8182 printf ("+%lx", (unsigned long) offset
);
8185 fputs (">: [", stdout
);
8186 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8187 fputc ('-', stdout
);
8188 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8189 printf ("], info at +0x%lx\n",
8190 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
8192 /* PR 17531: file: 86232b32. */
8193 if (aux
->info
== NULL
)
8196 offset
= tp
->info
.offset
;
8197 if (tp
->info
.section
)
8199 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
8201 warn (_("Invalid section %u in table entry %ld\n"),
8202 tp
->info
.section
, (long) (tp
- aux
->table
));
8206 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
8208 offset
-= aux
->info_addr
;
8209 /* PR 17531: file: 0997b4d1. */
8210 if (offset
>= aux
->info_size
8211 || aux
->info_size
- offset
< 8)
8213 warn (_("Invalid offset %lx in table entry %ld\n"),
8214 (long) tp
->info
.offset
, (long) (tp
- aux
->table
));
8219 head
= aux
->info
+ offset
;
8220 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
8222 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
8223 (unsigned) UNW_VER (stamp
),
8224 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
8225 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
8226 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
8227 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
8229 if (UNW_VER (stamp
) != 1)
8231 printf (_("\tUnknown version.\n"));
8236 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
8237 /* PR 17531: file: 16ceda89. */
8238 if (end
> aux
->info
+ aux
->info_size
)
8239 end
= aux
->info
+ aux
->info_size
;
8240 for (dp
= head
+ 8; dp
< end
;)
8241 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
8250 slurp_ia64_unwind_table (Filedata
* filedata
,
8251 struct ia64_unw_aux_info
* aux
,
8252 Elf_Internal_Shdr
* sec
)
8254 unsigned long size
, nrelas
, i
;
8255 Elf_Internal_Phdr
* seg
;
8256 struct ia64_unw_table_entry
* tep
;
8257 Elf_Internal_Shdr
* relsec
;
8258 Elf_Internal_Rela
* rela
;
8259 Elf_Internal_Rela
* rp
;
8260 unsigned char * table
;
8262 Elf_Internal_Sym
* sym
;
8263 const char * relname
;
8267 /* First, find the starting address of the segment that includes
8270 if (filedata
->file_header
.e_phnum
)
8272 if (! get_program_headers (filedata
))
8275 for (seg
= filedata
->program_headers
;
8276 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8279 if (seg
->p_type
!= PT_LOAD
)
8282 if (sec
->sh_addr
>= seg
->p_vaddr
8283 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8285 aux
->seg_base
= seg
->p_vaddr
;
8291 /* Second, build the unwind table from the contents of the unwind section: */
8292 size
= sec
->sh_size
;
8293 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8298 aux
->table_len
= size
/ (3 * eh_addr_size
);
8299 aux
->table
= (struct ia64_unw_table_entry
*)
8300 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
8303 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
8305 tep
->start
.section
= SHN_UNDEF
;
8306 tep
->end
.section
= SHN_UNDEF
;
8307 tep
->info
.section
= SHN_UNDEF
;
8308 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8309 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8310 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8311 tep
->start
.offset
+= aux
->seg_base
;
8312 tep
->end
.offset
+= aux
->seg_base
;
8313 tep
->info
.offset
+= aux
->seg_base
;
8317 /* Third, apply any relocations to the unwind table: */
8318 for (relsec
= filedata
->section_headers
;
8319 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8322 if (relsec
->sh_type
!= SHT_RELA
8323 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8324 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8327 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8336 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8338 unsigned int sym_ndx
;
8339 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8340 relname
= elf_ia64_reloc_type (r_type
);
8342 /* PR 17531: file: 9fa67536. */
8343 if (relname
== NULL
)
8345 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8349 if (! startswith (relname
, "R_IA64_SEGREL"))
8351 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8355 i
= rp
->r_offset
/ (3 * eh_addr_size
);
8357 /* PR 17531: file: 5bc8d9bf. */
8358 if (i
>= aux
->table_len
)
8360 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8364 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8365 if (sym_ndx
>= aux
->nsyms
)
8367 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8371 sym
= aux
->symtab
+ sym_ndx
;
8373 switch (rp
->r_offset
/ eh_addr_size
% 3)
8376 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8377 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
8380 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8381 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
8384 aux
->table
[i
].info
.section
= sym
->st_shndx
;
8385 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
8399 ia64_process_unwind (Filedata
* filedata
)
8401 Elf_Internal_Shdr
* sec
;
8402 Elf_Internal_Shdr
* unwsec
= NULL
;
8403 unsigned long i
, unwcount
= 0, unwstart
= 0;
8404 struct ia64_unw_aux_info aux
;
8407 memset (& aux
, 0, sizeof (aux
));
8409 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8411 if (sec
->sh_type
== SHT_SYMTAB
)
8415 error (_("Multiple symbol tables encountered\n"));
8421 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8422 &aux
.strtab
, &aux
.strtab_size
))
8425 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8430 printf (_("\nThere are no unwind sections in this file.\n"));
8432 while (unwcount
-- > 0)
8437 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
8438 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8439 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8444 /* We have already counted the number of SHT_IA64_UNWIND
8445 sections so the loop above should never fail. */
8446 assert (unwsec
!= NULL
);
8449 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
8451 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
8453 /* We need to find which section group it is in. */
8454 struct group_list
* g
;
8456 if (filedata
->section_headers_groups
== NULL
8457 || filedata
->section_headers_groups
[i
] == NULL
)
8458 i
= filedata
->file_header
.e_shnum
;
8461 g
= filedata
->section_headers_groups
[i
]->root
;
8463 for (; g
!= NULL
; g
= g
->next
)
8465 sec
= filedata
->section_headers
+ g
->section_index
;
8467 if (section_name_valid (filedata
, sec
)
8468 && streq (section_name (filedata
, sec
),
8469 ELF_STRING_ia64_unwind_info
))
8474 i
= filedata
->file_header
.e_shnum
;
8477 else if (section_name_valid (filedata
, unwsec
)
8478 && startswith (section_name (filedata
, unwsec
),
8479 ELF_STRING_ia64_unwind_once
))
8481 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
8482 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
8483 suffix
= section_name (filedata
, unwsec
) + len
;
8484 for (i
= 0, sec
= filedata
->section_headers
;
8485 i
< filedata
->file_header
.e_shnum
;
8487 if (section_name_valid (filedata
, sec
)
8488 && startswith (section_name (filedata
, sec
),
8489 ELF_STRING_ia64_unwind_info_once
)
8490 && streq (section_name (filedata
, sec
) + len2
, suffix
))
8495 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
8496 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
8497 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
8498 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
8500 if (section_name_valid (filedata
, unwsec
)
8501 && startswith (section_name (filedata
, unwsec
),
8502 ELF_STRING_ia64_unwind
))
8503 suffix
= section_name (filedata
, unwsec
) + len
;
8504 for (i
= 0, sec
= filedata
->section_headers
;
8505 i
< filedata
->file_header
.e_shnum
;
8507 if (section_name_valid (filedata
, sec
)
8508 && startswith (section_name (filedata
, sec
),
8509 ELF_STRING_ia64_unwind_info
)
8510 && streq (section_name (filedata
, sec
) + len2
, suffix
))
8514 if (i
== filedata
->file_header
.e_shnum
)
8516 printf (_("\nCould not find unwind info section for "));
8518 if (filedata
->string_table
== NULL
)
8519 printf ("%d", unwsec
->sh_name
);
8521 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8525 aux
.info_addr
= sec
->sh_addr
;
8526 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
8529 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
8531 printf (_("\nUnwind section "));
8533 if (filedata
->string_table
== NULL
)
8534 printf ("%d", unwsec
->sh_name
);
8536 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8538 printf (_(" at offset 0x%lx contains %lu entries:\n"),
8539 (unsigned long) unwsec
->sh_offset
,
8540 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
8542 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
8543 && aux
.table_len
> 0)
8544 dump_ia64_unwind (filedata
, & aux
);
8546 free ((char *) aux
.table
);
8547 free ((char *) aux
.info
);
8554 free ((char *) aux
.strtab
);
8559 struct hppa_unw_table_entry
8561 struct absaddr start
;
8563 unsigned int Cannot_unwind
:1; /* 0 */
8564 unsigned int Millicode
:1; /* 1 */
8565 unsigned int Millicode_save_sr0
:1; /* 2 */
8566 unsigned int Region_description
:2; /* 3..4 */
8567 unsigned int reserved1
:1; /* 5 */
8568 unsigned int Entry_SR
:1; /* 6 */
8569 unsigned int Entry_FR
:4; /* Number saved 7..10 */
8570 unsigned int Entry_GR
:5; /* Number saved 11..15 */
8571 unsigned int Args_stored
:1; /* 16 */
8572 unsigned int Variable_Frame
:1; /* 17 */
8573 unsigned int Separate_Package_Body
:1; /* 18 */
8574 unsigned int Frame_Extension_Millicode
:1; /* 19 */
8575 unsigned int Stack_Overflow_Check
:1; /* 20 */
8576 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
8577 unsigned int Ada_Region
:1; /* 22 */
8578 unsigned int cxx_info
:1; /* 23 */
8579 unsigned int cxx_try_catch
:1; /* 24 */
8580 unsigned int sched_entry_seq
:1; /* 25 */
8581 unsigned int reserved2
:1; /* 26 */
8582 unsigned int Save_SP
:1; /* 27 */
8583 unsigned int Save_RP
:1; /* 28 */
8584 unsigned int Save_MRP_in_frame
:1; /* 29 */
8585 unsigned int extn_ptr_defined
:1; /* 30 */
8586 unsigned int Cleanup_defined
:1; /* 31 */
8588 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
8589 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
8590 unsigned int Large_frame
:1; /* 2 */
8591 unsigned int Pseudo_SP_Set
:1; /* 3 */
8592 unsigned int reserved4
:1; /* 4 */
8593 unsigned int Total_frame_size
:27; /* 5..31 */
8596 struct hppa_unw_aux_info
8598 struct hppa_unw_table_entry
* table
; /* Unwind table. */
8599 unsigned long table_len
; /* Length of unwind table. */
8600 bfd_vma seg_base
; /* Starting address of segment. */
8601 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8602 unsigned long nsyms
; /* Number of symbols. */
8603 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8604 unsigned long nfuns
; /* Number of entries in funtab. */
8605 char * strtab
; /* The string table. */
8606 unsigned long strtab_size
; /* Size of string table. */
8610 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
8612 struct hppa_unw_table_entry
* tp
;
8613 unsigned long j
, nfuns
;
8616 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8617 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8618 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8619 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8621 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8623 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8626 const char * procname
;
8628 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8629 aux
->strtab_size
, tp
->start
, &procname
,
8632 fputs ("\n<", stdout
);
8636 fputs (procname
, stdout
);
8639 printf ("+%lx", (unsigned long) offset
);
8642 fputs (">: [", stdout
);
8643 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8644 fputc ('-', stdout
);
8645 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8648 #define PF(_m) if (tp->_m) printf (#_m " ");
8649 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
8652 PF(Millicode_save_sr0
);
8653 /* PV(Region_description); */
8659 PF(Separate_Package_Body
);
8660 PF(Frame_Extension_Millicode
);
8661 PF(Stack_Overflow_Check
);
8662 PF(Two_Instruction_SP_Increment
);
8666 PF(sched_entry_seq
);
8669 PF(Save_MRP_in_frame
);
8670 PF(extn_ptr_defined
);
8671 PF(Cleanup_defined
);
8672 PF(MPE_XL_interrupt_marker
);
8673 PF(HP_UX_interrupt_marker
);
8676 PV(Total_frame_size
);
8689 slurp_hppa_unwind_table (Filedata
* filedata
,
8690 struct hppa_unw_aux_info
* aux
,
8691 Elf_Internal_Shdr
* sec
)
8693 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
8694 Elf_Internal_Phdr
* seg
;
8695 struct hppa_unw_table_entry
* tep
;
8696 Elf_Internal_Shdr
* relsec
;
8697 Elf_Internal_Rela
* rela
;
8698 Elf_Internal_Rela
* rp
;
8699 unsigned char * table
;
8701 Elf_Internal_Sym
* sym
;
8702 const char * relname
;
8704 /* First, find the starting address of the segment that includes
8706 if (filedata
->file_header
.e_phnum
)
8708 if (! get_program_headers (filedata
))
8711 for (seg
= filedata
->program_headers
;
8712 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8715 if (seg
->p_type
!= PT_LOAD
)
8718 if (sec
->sh_addr
>= seg
->p_vaddr
8719 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8721 aux
->seg_base
= seg
->p_vaddr
;
8727 /* Second, build the unwind table from the contents of the unwind
8729 size
= sec
->sh_size
;
8730 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8736 nentries
= size
/ unw_ent_size
;
8737 size
= unw_ent_size
* nentries
;
8739 aux
->table_len
= nentries
;
8740 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
8741 xcmalloc (nentries
, sizeof (aux
->table
[0]));
8743 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
8745 unsigned int tmp1
, tmp2
;
8747 tep
->start
.section
= SHN_UNDEF
;
8748 tep
->end
.section
= SHN_UNDEF
;
8750 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
8751 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
8752 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
8753 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
8755 tep
->start
.offset
+= aux
->seg_base
;
8756 tep
->end
.offset
+= aux
->seg_base
;
8758 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
8759 tep
->Millicode
= (tmp1
>> 30) & 0x1;
8760 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
8761 tep
->Region_description
= (tmp1
>> 27) & 0x3;
8762 tep
->reserved1
= (tmp1
>> 26) & 0x1;
8763 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
8764 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
8765 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
8766 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
8767 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
8768 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
8769 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
8770 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
8771 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
8772 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
8773 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
8774 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
8775 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
8776 tep
->reserved2
= (tmp1
>> 5) & 0x1;
8777 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
8778 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
8779 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
8780 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
8781 tep
->Cleanup_defined
= tmp1
& 0x1;
8783 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
8784 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
8785 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
8786 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
8787 tep
->reserved4
= (tmp2
>> 27) & 0x1;
8788 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
8792 /* Third, apply any relocations to the unwind table. */
8793 for (relsec
= filedata
->section_headers
;
8794 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8797 if (relsec
->sh_type
!= SHT_RELA
8798 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8799 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8802 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8806 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8808 unsigned int sym_ndx
;
8809 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8810 relname
= elf_hppa_reloc_type (r_type
);
8812 if (relname
== NULL
)
8814 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8818 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
8819 if (! startswith (relname
, "R_PARISC_SEGREL"))
8821 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8825 i
= rp
->r_offset
/ unw_ent_size
;
8826 if (i
>= aux
->table_len
)
8828 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8832 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8833 if (sym_ndx
>= aux
->nsyms
)
8835 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8839 sym
= aux
->symtab
+ sym_ndx
;
8841 switch ((rp
->r_offset
% unw_ent_size
) / 4)
8844 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8845 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
8848 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8849 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
8863 hppa_process_unwind (Filedata
* filedata
)
8865 struct hppa_unw_aux_info aux
;
8866 Elf_Internal_Shdr
* unwsec
= NULL
;
8867 Elf_Internal_Shdr
* sec
;
8871 if (filedata
->string_table
== NULL
)
8874 memset (& aux
, 0, sizeof (aux
));
8876 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8878 if (sec
->sh_type
== SHT_SYMTAB
)
8882 error (_("Multiple symbol tables encountered\n"));
8888 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8889 &aux
.strtab
, &aux
.strtab_size
))
8892 else if (section_name_valid (filedata
, sec
)
8893 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
8898 printf (_("\nThere are no unwind sections in this file.\n"));
8900 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8902 if (section_name_valid (filedata
, sec
)
8903 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
8905 unsigned long num_unwind
= sec
->sh_size
/ 16;
8907 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8908 "contains %lu entry:\n",
8909 "\nUnwind section '%s' at offset 0x%lx "
8910 "contains %lu entries:\n",
8912 printable_section_name (filedata
, sec
),
8913 (unsigned long) sec
->sh_offset
,
8916 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
8919 if (res
&& aux
.table_len
> 0)
8921 if (! dump_hppa_unwind (filedata
, &aux
))
8925 free ((char *) aux
.table
);
8931 free ((char *) aux
.strtab
);
8938 unsigned char * data
; /* The unwind data. */
8939 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
8940 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
8941 unsigned long nrelas
; /* The number of relocations. */
8942 unsigned int rel_type
; /* REL or RELA ? */
8943 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
8946 struct arm_unw_aux_info
8948 Filedata
* filedata
; /* The file containing the unwind sections. */
8949 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
8950 unsigned long nsyms
; /* Number of symbols. */
8951 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8952 unsigned long nfuns
; /* Number of these symbols. */
8953 char * strtab
; /* The file's string table. */
8954 unsigned long strtab_size
; /* Size of string table. */
8958 arm_print_vma_and_name (Filedata
* filedata
,
8959 struct arm_unw_aux_info
* aux
,
8961 struct absaddr addr
)
8963 const char *procname
;
8966 if (addr
.section
== SHN_UNDEF
)
8969 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8970 aux
->strtab_size
, addr
, &procname
,
8973 print_vma (fn
, PREFIX_HEX
);
8977 fputs (" <", stdout
);
8978 fputs (procname
, stdout
);
8981 printf ("+0x%lx", (unsigned long) sym_offset
);
8982 fputc ('>', stdout
);
8989 arm_free_section (struct arm_section
*arm_sec
)
8991 free (arm_sec
->data
);
8992 free (arm_sec
->rela
);
8995 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8996 cached section and install SEC instead.
8997 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8998 and return its valued in * WORDP, relocating if necessary.
8999 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
9000 relocation's offset in ADDR.
9001 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
9002 into the string table of the symbol associated with the reloc. If no
9003 reloc was applied store -1 there.
9004 5) Return TRUE upon success, FALSE otherwise. */
9007 get_unwind_section_word (Filedata
* filedata
,
9008 struct arm_unw_aux_info
* aux
,
9009 struct arm_section
* arm_sec
,
9010 Elf_Internal_Shdr
* sec
,
9011 bfd_vma word_offset
,
9012 unsigned int * wordp
,
9013 struct absaddr
* addr
,
9016 Elf_Internal_Rela
*rp
;
9017 Elf_Internal_Sym
*sym
;
9018 const char * relname
;
9022 if (sec
== NULL
|| arm_sec
== NULL
)
9025 addr
->section
= SHN_UNDEF
;
9028 if (sym_name
!= NULL
)
9029 *sym_name
= (bfd_vma
) -1;
9031 /* If necessary, update the section cache. */
9032 if (sec
!= arm_sec
->sec
)
9034 Elf_Internal_Shdr
*relsec
;
9036 arm_free_section (arm_sec
);
9039 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
9040 sec
->sh_size
, _("unwind data"));
9041 arm_sec
->rela
= NULL
;
9042 arm_sec
->nrelas
= 0;
9044 for (relsec
= filedata
->section_headers
;
9045 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9048 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
9049 || filedata
->section_headers
+ relsec
->sh_info
!= sec
9050 /* PR 15745: Check the section type as well. */
9051 || (relsec
->sh_type
!= SHT_REL
9052 && relsec
->sh_type
!= SHT_RELA
))
9055 arm_sec
->rel_type
= relsec
->sh_type
;
9056 if (relsec
->sh_type
== SHT_REL
)
9058 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
9060 & arm_sec
->rela
, & arm_sec
->nrelas
))
9063 else /* relsec->sh_type == SHT_RELA */
9065 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
9067 & arm_sec
->rela
, & arm_sec
->nrelas
))
9073 arm_sec
->next_rela
= arm_sec
->rela
;
9076 /* If there is no unwind data we can do nothing. */
9077 if (arm_sec
->data
== NULL
)
9080 /* If the offset is invalid then fail. */
9081 if (/* PR 21343 *//* PR 18879 */
9083 || word_offset
> (sec
->sh_size
- 4)
9084 || ((bfd_signed_vma
) word_offset
) < 0)
9087 /* Get the word at the required offset. */
9088 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
9090 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
9091 if (arm_sec
->rela
== NULL
)
9097 /* Look through the relocs to find the one that applies to the provided offset. */
9099 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
9101 bfd_vma prelval
, offset
;
9103 if (rp
->r_offset
> word_offset
&& !wrapped
)
9108 if (rp
->r_offset
> word_offset
)
9111 if (rp
->r_offset
& 3)
9113 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
9114 (unsigned long) rp
->r_offset
);
9118 if (rp
->r_offset
< word_offset
)
9121 /* PR 17531: file: 027-161405-0.004 */
9122 if (aux
->symtab
== NULL
)
9125 if (arm_sec
->rel_type
== SHT_REL
)
9127 offset
= word
& 0x7fffffff;
9128 if (offset
& 0x40000000)
9129 offset
|= ~ (bfd_vma
) 0x7fffffff;
9131 else if (arm_sec
->rel_type
== SHT_RELA
)
9132 offset
= rp
->r_addend
;
9135 error (_("Unknown section relocation type %d encountered\n"),
9140 /* PR 17531 file: 027-1241568-0.004. */
9141 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
9143 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
9144 (unsigned long) ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
9148 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
9149 offset
+= sym
->st_value
;
9150 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
9152 /* Check that we are processing the expected reloc type. */
9153 if (filedata
->file_header
.e_machine
== EM_ARM
)
9155 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9156 if (relname
== NULL
)
9158 warn (_("Skipping unknown ARM relocation type: %d\n"),
9159 (int) ELF32_R_TYPE (rp
->r_info
));
9163 if (streq (relname
, "R_ARM_NONE"))
9166 if (! streq (relname
, "R_ARM_PREL31"))
9168 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
9172 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9174 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9175 if (relname
== NULL
)
9177 warn (_("Skipping unknown C6000 relocation type: %d\n"),
9178 (int) ELF32_R_TYPE (rp
->r_info
));
9182 if (streq (relname
, "R_C6000_NONE"))
9185 if (! streq (relname
, "R_C6000_PREL31"))
9187 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
9195 /* This function currently only supports ARM and TI unwinders. */
9196 warn (_("Only TI and ARM unwinders are currently supported\n"));
9200 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
9201 addr
->section
= sym
->st_shndx
;
9202 addr
->offset
= offset
;
9205 * sym_name
= sym
->st_name
;
9210 arm_sec
->next_rela
= rp
;
9215 static const char *tic6x_unwind_regnames
[16] =
9217 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
9218 "A14", "A13", "A12", "A11", "A10",
9219 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
9223 decode_tic6x_unwind_regmask (unsigned int mask
)
9227 for (i
= 12; mask
; mask
>>= 1, i
--)
9231 fputs (tic6x_unwind_regnames
[i
], stdout
);
9233 fputs (", ", stdout
);
9239 if (remaining == 0 && more_words) \
9242 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
9243 data_offset, & word, & addr, NULL)) \
9249 #define GET_OP(OP) \
9254 (OP) = word >> 24; \
9259 printf (_("[Truncated opcode]\n")); \
9262 printf ("0x%02x ", OP)
9265 decode_arm_unwind_bytecode (Filedata
* filedata
,
9266 struct arm_unw_aux_info
* aux
,
9268 unsigned int remaining
,
9269 unsigned int more_words
,
9270 bfd_vma data_offset
,
9271 Elf_Internal_Shdr
* data_sec
,
9272 struct arm_section
* data_arm_sec
)
9274 struct absaddr addr
;
9277 /* Decode the unwinding instructions. */
9280 unsigned int op
, op2
;
9289 printf (" 0x%02x ", op
);
9291 if ((op
& 0xc0) == 0x00)
9293 int offset
= ((op
& 0x3f) << 2) + 4;
9295 printf (" vsp = vsp + %d", offset
);
9297 else if ((op
& 0xc0) == 0x40)
9299 int offset
= ((op
& 0x3f) << 2) + 4;
9301 printf (" vsp = vsp - %d", offset
);
9303 else if ((op
& 0xf0) == 0x80)
9306 if (op
== 0x80 && op2
== 0)
9307 printf (_("Refuse to unwind"));
9310 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
9315 for (i
= 0; i
< 12; i
++)
9316 if (mask
& (1 << i
))
9322 printf ("r%d", 4 + i
);
9327 else if ((op
& 0xf0) == 0x90)
9329 if (op
== 0x9d || op
== 0x9f)
9330 printf (_(" [Reserved]"));
9332 printf (" vsp = r%d", op
& 0x0f);
9334 else if ((op
& 0xf0) == 0xa0)
9336 int end
= 4 + (op
& 0x07);
9341 for (i
= 4; i
<= end
; i
++)
9357 else if (op
== 0xb0)
9358 printf (_(" finish"));
9359 else if (op
== 0xb1)
9362 if (op2
== 0 || (op2
& 0xf0) != 0)
9363 printf (_("[Spare]"));
9366 unsigned int mask
= op2
& 0x0f;
9371 for (i
= 0; i
< 12; i
++)
9372 if (mask
& (1 << i
))
9383 else if (op
== 0xb2)
9385 unsigned char buf
[9];
9386 unsigned int i
, len
;
9387 unsigned long offset
;
9389 for (i
= 0; i
< sizeof (buf
); i
++)
9392 if ((buf
[i
] & 0x80) == 0)
9395 if (i
== sizeof (buf
))
9397 error (_("corrupt change to vsp\n"));
9402 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
9403 assert (len
== i
+ 1);
9404 offset
= offset
* 4 + 0x204;
9405 printf ("vsp = vsp + %ld", offset
);
9408 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
9410 unsigned int first
, last
;
9417 printf ("pop {D%d", first
);
9419 printf ("-D%d", first
+ last
);
9422 else if (op
== 0xb4)
9423 printf (_(" pop {ra_auth_code}"));
9424 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
9426 unsigned int count
= op
& 0x07;
9430 printf ("-D%d", 8 + count
);
9433 else if (op
>= 0xc0 && op
<= 0xc5)
9435 unsigned int count
= op
& 0x07;
9437 printf (" pop {wR10");
9439 printf ("-wR%d", 10 + count
);
9442 else if (op
== 0xc6)
9444 unsigned int first
, last
;
9449 printf ("pop {wR%d", first
);
9451 printf ("-wR%d", first
+ last
);
9454 else if (op
== 0xc7)
9457 if (op2
== 0 || (op2
& 0xf0) != 0)
9458 printf (_("[Spare]"));
9461 unsigned int mask
= op2
& 0x0f;
9466 for (i
= 0; i
< 4; i
++)
9467 if (mask
& (1 << i
))
9473 printf ("wCGR%d", i
);
9480 printf (_(" [unsupported opcode]"));
9491 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
9492 struct arm_unw_aux_info
* aux
,
9494 unsigned int remaining
,
9495 unsigned int more_words
,
9496 bfd_vma data_offset
,
9497 Elf_Internal_Shdr
* data_sec
,
9498 struct arm_section
* data_arm_sec
)
9500 struct absaddr addr
;
9502 /* Decode the unwinding instructions. */
9505 unsigned int op
, op2
;
9514 printf (" 0x%02x ", op
);
9516 if ((op
& 0xc0) == 0x00)
9518 int offset
= ((op
& 0x3f) << 3) + 8;
9519 printf (" sp = sp + %d", offset
);
9521 else if ((op
& 0xc0) == 0x80)
9524 if (op
== 0x80 && op2
== 0)
9525 printf (_("Refuse to unwind"));
9528 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
9530 printf ("pop compact {");
9534 decode_tic6x_unwind_regmask (mask
);
9538 else if ((op
& 0xf0) == 0xc0)
9546 unsigned int offset
;
9550 /* Scan entire instruction first so that GET_OP output is not
9551 interleaved with disassembly. */
9553 for (i
= 0; nregs
< (op
& 0xf); i
++)
9559 regpos
[nregs
].offset
= i
* 2;
9560 regpos
[nregs
].reg
= reg
;
9567 regpos
[nregs
].offset
= i
* 2 + 1;
9568 regpos
[nregs
].reg
= reg
;
9573 printf (_("pop frame {"));
9576 printf (_("*corrupt* - no registers specified"));
9581 for (i
= i
* 2; i
> 0; i
--)
9583 if (regpos
[reg
].offset
== i
- 1)
9585 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
9592 fputs (name
, stdout
);
9600 else if (op
== 0xd0)
9601 printf (" MOV FP, SP");
9602 else if (op
== 0xd1)
9603 printf (" __c6xabi_pop_rts");
9604 else if (op
== 0xd2)
9606 unsigned char buf
[9];
9607 unsigned int i
, len
;
9608 unsigned long offset
;
9610 for (i
= 0; i
< sizeof (buf
); i
++)
9613 if ((buf
[i
] & 0x80) == 0)
9616 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9617 if (i
== sizeof (buf
))
9619 warn (_("Corrupt stack pointer adjustment detected\n"));
9623 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
9624 assert (len
== i
+ 1);
9625 offset
= offset
* 8 + 0x408;
9626 printf (_("sp = sp + %ld"), offset
);
9628 else if ((op
& 0xf0) == 0xe0)
9630 if ((op
& 0x0f) == 7)
9633 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
9637 printf (_(" [unsupported opcode]"));
9646 arm_expand_prel31 (Filedata
* filedata
, bfd_vma word
, bfd_vma where
)
9650 offset
= word
& 0x7fffffff;
9651 if (offset
& 0x40000000)
9652 offset
|= ~ (bfd_vma
) 0x7fffffff;
9654 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9657 return offset
+ where
;
9661 decode_arm_unwind (Filedata
* filedata
,
9662 struct arm_unw_aux_info
* aux
,
9664 unsigned int remaining
,
9665 bfd_vma data_offset
,
9666 Elf_Internal_Shdr
* data_sec
,
9667 struct arm_section
* data_arm_sec
)
9670 unsigned int more_words
= 0;
9671 struct absaddr addr
;
9672 bfd_vma sym_name
= (bfd_vma
) -1;
9677 /* Fetch the first word.
9678 Note - when decoding an object file the address extracted
9679 here will always be 0. So we also pass in the sym_name
9680 parameter so that we can find the symbol associated with
9681 the personality routine. */
9682 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
9683 & word
, & addr
, & sym_name
))
9690 addr
.section
= SHN_UNDEF
;
9694 if ((word
& 0x80000000) == 0)
9696 /* Expand prel31 for personality routine. */
9698 const char *procname
;
9700 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
9701 printf (_(" Personality routine: "));
9703 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
9704 && sym_name
!= (bfd_vma
) -1 && sym_name
< aux
->strtab_size
)
9706 procname
= aux
->strtab
+ sym_name
;
9707 print_vma (fn
, PREFIX_HEX
);
9710 fputs (" <", stdout
);
9711 fputs (procname
, stdout
);
9712 fputc ('>', stdout
);
9716 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
9717 fputc ('\n', stdout
);
9719 /* The GCC personality routines use the standard compact
9720 encoding, starting with one byte giving the number of
9722 if (procname
!= NULL
9723 && (startswith (procname
, "__gcc_personality_v0")
9724 || startswith (procname
, "__gxx_personality_v0")
9725 || startswith (procname
, "__gcj_personality_v0")
9726 || startswith (procname
, "__gnu_objc_personality_v0")))
9733 printf (_(" [Truncated data]\n"));
9736 more_words
= word
>> 24;
9746 /* ARM EHABI Section 6.3:
9748 An exception-handling table entry for the compact model looks like:
9752 1 0 index Data for personalityRoutine[index] */
9754 if (filedata
->file_header
.e_machine
== EM_ARM
9755 && (word
& 0x70000000))
9757 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
9761 per_index
= (word
>> 24) & 0x7f;
9762 printf (_(" Compact model index: %d\n"), per_index
);
9769 else if (per_index
< 3)
9771 more_words
= (word
>> 16) & 0xff;
9777 switch (filedata
->file_header
.e_machine
)
9782 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9783 data_offset
, data_sec
, data_arm_sec
))
9788 warn (_("Unknown ARM compact model index encountered\n"));
9789 printf (_(" [reserved]\n"));
9797 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9798 data_offset
, data_sec
, data_arm_sec
))
9801 else if (per_index
< 5)
9803 if (((word
>> 17) & 0x7f) == 0x7f)
9804 printf (_(" Restore stack from frame pointer\n"));
9806 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
9807 printf (_(" Registers restored: "));
9809 printf (" (compact) ");
9810 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
9812 printf (_(" Return register: %s\n"),
9813 tic6x_unwind_regnames
[word
& 0xf]);
9816 printf (_(" [reserved (%d)]\n"), per_index
);
9820 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
9821 filedata
->file_header
.e_machine
);
9825 /* Decode the descriptors. Not implemented. */
9831 dump_arm_unwind (Filedata
* filedata
,
9832 struct arm_unw_aux_info
* aux
,
9833 Elf_Internal_Shdr
* exidx_sec
)
9835 struct arm_section exidx_arm_sec
, extab_arm_sec
;
9836 unsigned int i
, exidx_len
;
9837 unsigned long j
, nfuns
;
9840 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
9841 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
9842 exidx_len
= exidx_sec
->sh_size
/ 8;
9844 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9845 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9846 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9847 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9849 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9851 for (i
= 0; i
< exidx_len
; i
++)
9853 unsigned int exidx_fn
, exidx_entry
;
9854 struct absaddr fn_addr
, entry_addr
;
9857 fputc ('\n', stdout
);
9859 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9860 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
9861 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9862 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
9865 arm_free_section (& exidx_arm_sec
);
9866 arm_free_section (& extab_arm_sec
);
9870 /* ARM EHABI, Section 5:
9871 An index table entry consists of 2 words.
9872 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9873 if (exidx_fn
& 0x80000000)
9875 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
9879 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
9881 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
9882 fputs (": ", stdout
);
9884 if (exidx_entry
== 1)
9886 print_vma (exidx_entry
, PREFIX_HEX
);
9887 fputs (" [cantunwind]\n", stdout
);
9889 else if (exidx_entry
& 0x80000000)
9891 print_vma (exidx_entry
, PREFIX_HEX
);
9892 fputc ('\n', stdout
);
9893 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
9897 bfd_vma table
, table_offset
= 0;
9898 Elf_Internal_Shdr
*table_sec
;
9900 fputs ("@", stdout
);
9901 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
9902 print_vma (table
, PREFIX_HEX
);
9905 /* Locate the matching .ARM.extab. */
9906 if (entry_addr
.section
!= SHN_UNDEF
9907 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
9909 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
9910 table_offset
= entry_addr
.offset
;
9912 if (table_offset
> table_sec
->sh_size
9913 || ((bfd_signed_vma
) table_offset
) < 0)
9915 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9916 (unsigned long) table_offset
,
9917 printable_section_name (filedata
, table_sec
));
9924 table_sec
= find_section_by_address (filedata
, table
);
9925 if (table_sec
!= NULL
)
9926 table_offset
= table
- table_sec
->sh_addr
;
9929 if (table_sec
== NULL
)
9931 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9932 (unsigned long) table
);
9937 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
9946 arm_free_section (&exidx_arm_sec
);
9947 arm_free_section (&extab_arm_sec
);
9952 /* Used for both ARM and C6X unwinding tables. */
9955 arm_process_unwind (Filedata
* filedata
)
9957 struct arm_unw_aux_info aux
;
9958 Elf_Internal_Shdr
*unwsec
= NULL
;
9959 Elf_Internal_Shdr
*sec
;
9961 unsigned int sec_type
;
9964 switch (filedata
->file_header
.e_machine
)
9967 sec_type
= SHT_ARM_EXIDX
;
9971 sec_type
= SHT_C6000_UNWIND
;
9975 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
9976 filedata
->file_header
.e_machine
);
9980 if (filedata
->string_table
== NULL
)
9983 memset (& aux
, 0, sizeof (aux
));
9984 aux
.filedata
= filedata
;
9986 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9988 if (sec
->sh_type
== SHT_SYMTAB
)
9992 error (_("Multiple symbol tables encountered\n"));
9998 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9999 &aux
.strtab
, &aux
.strtab_size
))
10002 else if (sec
->sh_type
== sec_type
)
10006 if (unwsec
== NULL
)
10007 printf (_("\nThere are no unwind sections in this file.\n"));
10009 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10011 if (sec
->sh_type
== sec_type
)
10013 unsigned long num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
10014 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
10015 "contains %lu entry:\n",
10016 "\nUnwind section '%s' at offset 0x%lx "
10017 "contains %lu entries:\n",
10019 printable_section_name (filedata
, sec
),
10020 (unsigned long) sec
->sh_offset
,
10023 if (! dump_arm_unwind (filedata
, &aux
, sec
))
10029 free ((char *) aux
.strtab
);
10035 no_processor_specific_unwind (Filedata
* filedata ATTRIBUTE_UNUSED
)
10037 printf (_("No processor specific unwind information to decode\n"));
10042 process_unwind (Filedata
* filedata
)
10044 struct unwind_handler
10046 unsigned int machtype
;
10047 bool (* handler
)(Filedata
*);
10050 { EM_ARM
, arm_process_unwind
},
10051 { EM_IA_64
, ia64_process_unwind
},
10052 { EM_PARISC
, hppa_process_unwind
},
10053 { EM_TI_C6000
, arm_process_unwind
},
10054 { EM_386
, no_processor_specific_unwind
},
10055 { EM_X86_64
, no_processor_specific_unwind
},
10063 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
10064 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
10065 return handlers
[i
].handler (filedata
);
10067 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
10068 get_machine_name (filedata
->file_header
.e_machine
));
10073 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
10075 switch (entry
->d_tag
)
10077 case DT_AARCH64_BTI_PLT
:
10078 case DT_AARCH64_PAC_PLT
:
10081 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10088 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
10090 switch (entry
->d_tag
)
10092 case DT_MIPS_FLAGS
:
10093 if (entry
->d_un
.d_val
== 0)
10094 printf (_("NONE"));
10097 static const char * opts
[] =
10099 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
10100 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
10101 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
10102 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
10108 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
10109 if (entry
->d_un
.d_val
& (1 << cnt
))
10111 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
10117 case DT_MIPS_IVERSION
:
10118 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
10119 printf (_("Interface Version: %s"),
10120 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
10124 sprintf_vma (buf
, entry
->d_un
.d_ptr
);
10125 /* Note: coded this way so that there is a single string for translation. */
10126 printf (_("<corrupt: %s>"), buf
);
10130 case DT_MIPS_TIME_STAMP
:
10134 time_t atime
= entry
->d_un
.d_val
;
10136 tmp
= gmtime (&atime
);
10137 /* PR 17531: file: 6accc532. */
10139 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
10141 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
10142 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10143 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10144 printf (_("Time Stamp: %s"), timebuf
);
10148 case DT_MIPS_RLD_VERSION
:
10149 case DT_MIPS_LOCAL_GOTNO
:
10150 case DT_MIPS_CONFLICTNO
:
10151 case DT_MIPS_LIBLISTNO
:
10152 case DT_MIPS_SYMTABNO
:
10153 case DT_MIPS_UNREFEXTNO
:
10154 case DT_MIPS_HIPAGENO
:
10155 case DT_MIPS_DELTA_CLASS_NO
:
10156 case DT_MIPS_DELTA_INSTANCE_NO
:
10157 case DT_MIPS_DELTA_RELOC_NO
:
10158 case DT_MIPS_DELTA_SYM_NO
:
10159 case DT_MIPS_DELTA_CLASSSYM_NO
:
10160 case DT_MIPS_COMPACT_SIZE
:
10161 print_vma (entry
->d_un
.d_val
, DEC
);
10164 case DT_MIPS_XHASH
:
10165 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10166 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10167 /* Falls through. */
10170 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10176 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
10178 switch (entry
->d_tag
)
10180 case DT_HP_DLD_FLAGS
:
10189 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
10190 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
10191 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
10192 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
10193 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
10194 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
10195 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
10196 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
10197 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
10198 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
10199 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
10200 { DT_HP_GST
, "HP_GST" },
10201 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
10202 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
10203 { DT_HP_NODELETE
, "HP_NODELETE" },
10204 { DT_HP_GROUP
, "HP_GROUP" },
10205 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
10209 bfd_vma val
= entry
->d_un
.d_val
;
10211 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
10212 if (val
& flags
[cnt
].bit
)
10216 fputs (flags
[cnt
].str
, stdout
);
10218 val
^= flags
[cnt
].bit
;
10221 if (val
!= 0 || first
)
10225 print_vma (val
, HEX
);
10231 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10239 /* VMS vs Unix time offset and factor. */
10241 #define VMS_EPOCH_OFFSET 35067168000000000LL
10242 #define VMS_GRANULARITY_FACTOR 10000000
10244 #define INT64_MIN (-9223372036854775807LL - 1)
10247 /* Display a VMS time in a human readable format. */
10250 print_vms_time (bfd_int64_t vmstime
)
10252 struct tm
*tm
= NULL
;
10255 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
10257 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
10259 if (unxtime
== vmstime
)
10260 tm
= gmtime (&unxtime
);
10263 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
10264 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
10265 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
10270 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
10272 switch (entry
->d_tag
)
10274 case DT_IA_64_PLT_RESERVE
:
10275 /* First 3 slots reserved. */
10276 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10278 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
10281 case DT_IA_64_VMS_LINKTIME
:
10283 print_vms_time (entry
->d_un
.d_val
);
10287 case DT_IA_64_VMS_LNKFLAGS
:
10288 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10289 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
10290 printf (" CALL_DEBUG");
10291 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
10292 printf (" NOP0BUFS");
10293 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
10294 printf (" P0IMAGE");
10295 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
10296 printf (" MKTHREADS");
10297 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
10298 printf (" UPCALLS");
10299 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
10300 printf (" IMGSTA");
10301 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
10302 printf (" INITIALIZE");
10303 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
10305 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
10306 printf (" EXE_INIT");
10307 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
10308 printf (" TBK_IN_IMG");
10309 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
10310 printf (" DBG_IN_IMG");
10311 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
10312 printf (" TBK_IN_DSF");
10313 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
10314 printf (" DBG_IN_DSF");
10315 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
10316 printf (" SIGNATURES");
10317 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
10318 printf (" REL_SEG_OFF");
10322 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10329 get_32bit_dynamic_section (Filedata
* filedata
)
10331 Elf32_External_Dyn
* edyn
;
10332 Elf32_External_Dyn
* ext
;
10333 Elf_Internal_Dyn
* entry
;
10335 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
10336 filedata
->dynamic_addr
, 1,
10337 filedata
->dynamic_size
,
10338 _("dynamic section"));
10342 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10343 might not have the luxury of section headers. Look for the DT_NULL
10344 terminator to determine the number of entries. */
10345 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10346 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10349 filedata
->dynamic_nent
++;
10350 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10354 filedata
->dynamic_section
10355 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10356 if (filedata
->dynamic_section
== NULL
)
10358 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10359 (unsigned long) filedata
->dynamic_nent
);
10364 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10365 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10368 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10369 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10378 get_64bit_dynamic_section (Filedata
* filedata
)
10380 Elf64_External_Dyn
* edyn
;
10381 Elf64_External_Dyn
* ext
;
10382 Elf_Internal_Dyn
* entry
;
10384 /* Read in the data. */
10385 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
10386 filedata
->dynamic_addr
, 1,
10387 filedata
->dynamic_size
,
10388 _("dynamic section"));
10392 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10393 might not have the luxury of section headers. Look for the DT_NULL
10394 terminator to determine the number of entries. */
10395 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10396 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
10397 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10400 filedata
->dynamic_nent
++;
10401 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10405 filedata
->dynamic_section
10406 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10407 if (filedata
->dynamic_section
== NULL
)
10409 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10410 (unsigned long) filedata
->dynamic_nent
);
10415 /* Convert from external to internal formats. */
10416 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10417 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10420 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10421 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10430 get_dynamic_section (Filedata
*filedata
)
10432 if (filedata
->dynamic_section
)
10436 return get_32bit_dynamic_section (filedata
);
10438 return get_64bit_dynamic_section (filedata
);
10442 print_dynamic_flags (bfd_vma flags
)
10450 flag
= flags
& - flags
;
10456 putc (' ', stdout
);
10460 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
10461 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
10462 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
10463 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
10464 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
10465 default: fputs (_("unknown"), stdout
); break;
10472 get_dynamic_data (Filedata
* filedata
, bfd_size_type number
, unsigned int ent_size
)
10474 unsigned char * e_data
;
10477 /* If the size_t type is smaller than the bfd_size_type, eg because
10478 you are building a 32-bit tool on a 64-bit host, then make sure
10479 that when (number) is cast to (size_t) no information is lost. */
10480 if (sizeof (size_t) < sizeof (bfd_size_type
)
10481 && (bfd_size_type
) ((size_t) number
) != number
)
10483 error (_("Size truncation prevents reading %s elements of size %u\n"),
10484 bfd_vmatoa ("u", number
), ent_size
);
10488 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
10489 attempting to allocate memory when the read is bound to fail. */
10490 if (ent_size
* number
> filedata
->file_size
)
10492 error (_("Invalid number of dynamic entries: %s\n"),
10493 bfd_vmatoa ("u", number
));
10497 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
10498 if (e_data
== NULL
)
10500 error (_("Out of memory reading %s dynamic entries\n"),
10501 bfd_vmatoa ("u", number
));
10505 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
10507 error (_("Unable to read in %s bytes of dynamic data\n"),
10508 bfd_vmatoa ("u", number
* ent_size
));
10513 i_data
= (bfd_vma
*) cmalloc ((size_t) number
, sizeof (*i_data
));
10514 if (i_data
== NULL
)
10516 error (_("Out of memory allocating space for %s dynamic entries\n"),
10517 bfd_vmatoa ("u", number
));
10523 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
10530 static unsigned long
10531 get_num_dynamic_syms (Filedata
* filedata
)
10533 unsigned long num_of_syms
= 0;
10535 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
10536 return num_of_syms
;
10538 if (filedata
->dynamic_info
[DT_HASH
])
10540 unsigned char nb
[8];
10541 unsigned char nc
[8];
10542 unsigned int hash_ent_size
= 4;
10544 if ((filedata
->file_header
.e_machine
== EM_ALPHA
10545 || filedata
->file_header
.e_machine
== EM_S390
10546 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
10547 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
10550 if (fseek (filedata
->handle
,
10551 (filedata
->archive_file_offset
10552 + offset_from_vma (filedata
, filedata
->dynamic_info
[DT_HASH
],
10553 sizeof nb
+ sizeof nc
)),
10556 error (_("Unable to seek to start of dynamic information\n"));
10560 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
10562 error (_("Failed to read in number of buckets\n"));
10566 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
10568 error (_("Failed to read in number of chains\n"));
10572 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
10573 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
10575 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
10577 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
10579 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
10582 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
10583 num_of_syms
= filedata
->nchains
;
10586 if (num_of_syms
== 0)
10588 free (filedata
->buckets
);
10589 filedata
->buckets
= NULL
;
10590 free (filedata
->chains
);
10591 filedata
->chains
= NULL
;
10592 filedata
->nbuckets
= 0;
10596 if (filedata
->dynamic_info_DT_GNU_HASH
)
10598 unsigned char nb
[16];
10599 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
10600 bfd_vma buckets_vma
;
10603 if (fseek (filedata
->handle
,
10604 (filedata
->archive_file_offset
10605 + offset_from_vma (filedata
,
10606 filedata
->dynamic_info_DT_GNU_HASH
,
10610 error (_("Unable to seek to start of dynamic information\n"));
10614 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
10616 error (_("Failed to read in number of buckets\n"));
10620 filedata
->ngnubuckets
= byte_get (nb
, 4);
10621 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
10622 bitmaskwords
= byte_get (nb
+ 8, 4);
10623 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
10625 buckets_vma
+= bitmaskwords
* 4;
10627 buckets_vma
+= bitmaskwords
* 8;
10629 if (fseek (filedata
->handle
,
10630 (filedata
->archive_file_offset
10631 + offset_from_vma (filedata
, buckets_vma
, 4)),
10634 error (_("Unable to seek to start of dynamic information\n"));
10638 filedata
->gnubuckets
10639 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
10641 if (filedata
->gnubuckets
== NULL
)
10644 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
10645 if (filedata
->gnubuckets
[i
] != 0)
10647 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
10650 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
10651 maxchain
= filedata
->gnubuckets
[i
];
10654 if (maxchain
== 0xffffffff)
10657 maxchain
-= filedata
->gnusymidx
;
10659 if (fseek (filedata
->handle
,
10660 (filedata
->archive_file_offset
10661 + offset_from_vma (filedata
,
10662 buckets_vma
+ 4 * (filedata
->ngnubuckets
10667 error (_("Unable to seek to start of dynamic information\n"));
10673 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
10675 error (_("Failed to determine last chain length\n"));
10679 if (maxchain
+ 1 == 0)
10684 while ((byte_get (nb
, 4) & 1) == 0);
10686 if (fseek (filedata
->handle
,
10687 (filedata
->archive_file_offset
10688 + offset_from_vma (filedata
, (buckets_vma
10689 + 4 * filedata
->ngnubuckets
),
10693 error (_("Unable to seek to start of dynamic information\n"));
10697 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
10698 filedata
->ngnuchains
= maxchain
;
10700 if (filedata
->gnuchains
== NULL
)
10703 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10705 if (fseek (filedata
->handle
,
10706 (filedata
->archive_file_offset
10707 + offset_from_vma (filedata
, (buckets_vma
10708 + 4 * (filedata
->ngnubuckets
10712 error (_("Unable to seek to start of dynamic information\n"));
10716 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
10717 if (filedata
->mipsxlat
== NULL
)
10721 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
10722 if (filedata
->gnubuckets
[hn
] != 0)
10724 bfd_vma si
= filedata
->gnubuckets
[hn
];
10725 bfd_vma off
= si
- filedata
->gnusymidx
;
10729 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10731 if (off
< filedata
->ngnuchains
10732 && filedata
->mipsxlat
[off
] >= num_of_syms
)
10733 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
10737 if (si
>= num_of_syms
)
10738 num_of_syms
= si
+ 1;
10742 while (off
< filedata
->ngnuchains
10743 && (filedata
->gnuchains
[off
++] & 1) == 0);
10746 if (num_of_syms
== 0)
10749 free (filedata
->mipsxlat
);
10750 filedata
->mipsxlat
= NULL
;
10751 free (filedata
->gnuchains
);
10752 filedata
->gnuchains
= NULL
;
10753 free (filedata
->gnubuckets
);
10754 filedata
->gnubuckets
= NULL
;
10755 filedata
->ngnubuckets
= 0;
10756 filedata
->ngnuchains
= 0;
10760 return num_of_syms
;
10763 /* Parse and display the contents of the dynamic section. */
10766 process_dynamic_section (Filedata
* filedata
)
10768 Elf_Internal_Dyn
* entry
;
10770 if (filedata
->dynamic_size
<= 1)
10774 if (filedata
->is_separate
)
10775 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
10776 filedata
->file_name
);
10778 printf (_("\nThere is no dynamic section in this file.\n"));
10784 if (!get_dynamic_section (filedata
))
10787 /* Find the appropriate symbol table. */
10788 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
10790 unsigned long num_of_syms
;
10792 for (entry
= filedata
->dynamic_section
;
10793 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10795 if (entry
->d_tag
== DT_SYMTAB
)
10796 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
10797 else if (entry
->d_tag
== DT_SYMENT
)
10798 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
10799 else if (entry
->d_tag
== DT_HASH
)
10800 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
10801 else if (entry
->d_tag
== DT_GNU_HASH
)
10802 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10803 else if ((filedata
->file_header
.e_machine
== EM_MIPS
10804 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
10805 && entry
->d_tag
== DT_MIPS_XHASH
)
10807 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10808 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10811 num_of_syms
= get_num_dynamic_syms (filedata
);
10813 if (num_of_syms
!= 0
10814 && filedata
->dynamic_symbols
== NULL
10815 && filedata
->dynamic_info
[DT_SYMTAB
]
10816 && filedata
->dynamic_info
[DT_SYMENT
])
10818 Elf_Internal_Phdr
*seg
;
10819 bfd_vma vma
= filedata
->dynamic_info
[DT_SYMTAB
];
10821 if (! get_program_headers (filedata
))
10823 error (_("Cannot interpret virtual addresses "
10824 "without program headers.\n"));
10828 for (seg
= filedata
->program_headers
;
10829 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
10832 if (seg
->p_type
!= PT_LOAD
)
10835 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
10837 /* See PR 21379 for a reproducer. */
10838 error (_("Invalid PT_LOAD entry\n"));
10842 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
10843 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
10845 /* Since we do not know how big the symbol table is,
10846 we default to reading in up to the end of PT_LOAD
10847 segment and processing that. This is overkill, I
10848 know, but it should work. */
10849 Elf_Internal_Shdr section
;
10850 section
.sh_offset
= (vma
- seg
->p_vaddr
10852 section
.sh_size
= (num_of_syms
10853 * filedata
->dynamic_info
[DT_SYMENT
]);
10854 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
10857 && filedata
->dynamic_symtab_section
!= NULL
10858 && ((filedata
->dynamic_symtab_section
->sh_offset
10859 != section
.sh_offset
)
10860 || (filedata
->dynamic_symtab_section
->sh_size
10861 != section
.sh_size
)
10862 || (filedata
->dynamic_symtab_section
->sh_entsize
10863 != section
.sh_entsize
)))
10865 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
10867 section
.sh_name
= filedata
->string_table_length
;
10868 filedata
->dynamic_symbols
10869 = get_elf_symbols (filedata
, §ion
,
10870 &filedata
->num_dynamic_syms
);
10871 if (filedata
->dynamic_symbols
== NULL
10872 || filedata
->num_dynamic_syms
!= num_of_syms
)
10874 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
10883 /* Similarly find a string table. */
10884 if (filedata
->dynamic_strings
== NULL
)
10885 for (entry
= filedata
->dynamic_section
;
10886 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10889 if (entry
->d_tag
== DT_STRTAB
)
10890 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
10892 if (entry
->d_tag
== DT_STRSZ
)
10893 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
10895 if (filedata
->dynamic_info
[DT_STRTAB
]
10896 && filedata
->dynamic_info
[DT_STRSZ
])
10898 unsigned long offset
;
10899 bfd_size_type str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
10901 offset
= offset_from_vma (filedata
,
10902 filedata
->dynamic_info
[DT_STRTAB
],
10905 && filedata
->dynamic_strtab_section
10906 && ((filedata
->dynamic_strtab_section
->sh_offset
10907 != (file_ptr
) offset
)
10908 || (filedata
->dynamic_strtab_section
->sh_size
10911 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
10913 filedata
->dynamic_strings
10914 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
10915 _("dynamic string table"));
10916 if (filedata
->dynamic_strings
== NULL
)
10918 error (_("Corrupt DT_STRTAB dynamic entry\n"));
10922 filedata
->dynamic_strings_length
= str_tab_len
;
10927 /* And find the syminfo section if available. */
10928 if (filedata
->dynamic_syminfo
== NULL
)
10930 unsigned long syminsz
= 0;
10932 for (entry
= filedata
->dynamic_section
;
10933 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10936 if (entry
->d_tag
== DT_SYMINENT
)
10938 /* Note: these braces are necessary to avoid a syntax
10939 error from the SunOS4 C compiler. */
10940 /* PR binutils/17531: A corrupt file can trigger this test.
10941 So do not use an assert, instead generate an error message. */
10942 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
10943 error (_("Bad value (%d) for SYMINENT entry\n"),
10944 (int) entry
->d_un
.d_val
);
10946 else if (entry
->d_tag
== DT_SYMINSZ
)
10947 syminsz
= entry
->d_un
.d_val
;
10948 else if (entry
->d_tag
== DT_SYMINFO
)
10949 filedata
->dynamic_syminfo_offset
10950 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
10953 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
10955 Elf_External_Syminfo
* extsyminfo
;
10956 Elf_External_Syminfo
* extsym
;
10957 Elf_Internal_Syminfo
* syminfo
;
10959 /* There is a syminfo section. Read the data. */
10960 extsyminfo
= (Elf_External_Syminfo
*)
10961 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
10962 1, syminsz
, _("symbol information"));
10966 if (filedata
->dynamic_syminfo
!= NULL
)
10968 error (_("Multiple dynamic symbol information sections found\n"));
10969 free (filedata
->dynamic_syminfo
);
10971 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
10972 if (filedata
->dynamic_syminfo
== NULL
)
10974 error (_("Out of memory allocating %lu bytes "
10975 "for dynamic symbol info\n"),
10976 (unsigned long) syminsz
);
10980 filedata
->dynamic_syminfo_nent
10981 = syminsz
/ sizeof (Elf_External_Syminfo
);
10982 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
10983 syminfo
< (filedata
->dynamic_syminfo
10984 + filedata
->dynamic_syminfo_nent
);
10985 ++syminfo
, ++extsym
)
10987 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
10988 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
10995 if (do_dynamic
&& filedata
->dynamic_addr
)
10997 if (filedata
->is_separate
)
10998 printf (ngettext ("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entry:\n",
10999 "\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n",
11000 (unsigned long) filedata
->dynamic_nent
),
11001 filedata
->file_name
,
11002 filedata
->dynamic_addr
,
11003 (unsigned long) filedata
->dynamic_nent
);
11005 printf (ngettext ("\nDynamic section at offset 0x%lx contains %lu entry:\n",
11006 "\nDynamic section at offset 0x%lx contains %lu entries:\n",
11007 (unsigned long) filedata
->dynamic_nent
),
11008 filedata
->dynamic_addr
,
11009 (unsigned long) filedata
->dynamic_nent
);
11012 printf (_(" Tag Type Name/Value\n"));
11014 for (entry
= filedata
->dynamic_section
;
11015 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11020 const char * dtype
;
11023 print_vma (entry
->d_tag
, FULL_HEX
);
11024 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
11025 printf (" (%s)%*s", dtype
,
11026 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
11029 switch (entry
->d_tag
)
11033 print_dynamic_flags (entry
->d_un
.d_val
);
11043 switch (entry
->d_tag
)
11046 printf (_("Auxiliary library"));
11050 printf (_("Filter library"));
11054 printf (_("Configuration file"));
11058 printf (_("Dependency audit library"));
11062 printf (_("Audit library"));
11066 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11067 printf (": [%s]\n",
11068 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
11072 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11081 printf (_("Flags:"));
11083 if (entry
->d_un
.d_val
== 0)
11084 printf (_(" None\n"));
11087 unsigned long int val
= entry
->d_un
.d_val
;
11089 if (val
& DTF_1_PARINIT
)
11091 printf (" PARINIT");
11092 val
^= DTF_1_PARINIT
;
11094 if (val
& DTF_1_CONFEXP
)
11096 printf (" CONFEXP");
11097 val
^= DTF_1_CONFEXP
;
11100 printf (" %lx", val
);
11109 printf (_("Flags:"));
11111 if (entry
->d_un
.d_val
== 0)
11112 printf (_(" None\n"));
11115 unsigned long int val
= entry
->d_un
.d_val
;
11117 if (val
& DF_P1_LAZYLOAD
)
11119 printf (" LAZYLOAD");
11120 val
^= DF_P1_LAZYLOAD
;
11122 if (val
& DF_P1_GROUPPERM
)
11124 printf (" GROUPPERM");
11125 val
^= DF_P1_GROUPPERM
;
11128 printf (" %lx", val
);
11137 printf (_("Flags:"));
11138 if (entry
->d_un
.d_val
== 0)
11139 printf (_(" None\n"));
11142 unsigned long int val
= entry
->d_un
.d_val
;
11144 if (val
& DF_1_NOW
)
11149 if (val
& DF_1_GLOBAL
)
11151 printf (" GLOBAL");
11152 val
^= DF_1_GLOBAL
;
11154 if (val
& DF_1_GROUP
)
11159 if (val
& DF_1_NODELETE
)
11161 printf (" NODELETE");
11162 val
^= DF_1_NODELETE
;
11164 if (val
& DF_1_LOADFLTR
)
11166 printf (" LOADFLTR");
11167 val
^= DF_1_LOADFLTR
;
11169 if (val
& DF_1_INITFIRST
)
11171 printf (" INITFIRST");
11172 val
^= DF_1_INITFIRST
;
11174 if (val
& DF_1_NOOPEN
)
11176 printf (" NOOPEN");
11177 val
^= DF_1_NOOPEN
;
11179 if (val
& DF_1_ORIGIN
)
11181 printf (" ORIGIN");
11182 val
^= DF_1_ORIGIN
;
11184 if (val
& DF_1_DIRECT
)
11186 printf (" DIRECT");
11187 val
^= DF_1_DIRECT
;
11189 if (val
& DF_1_TRANS
)
11194 if (val
& DF_1_INTERPOSE
)
11196 printf (" INTERPOSE");
11197 val
^= DF_1_INTERPOSE
;
11199 if (val
& DF_1_NODEFLIB
)
11201 printf (" NODEFLIB");
11202 val
^= DF_1_NODEFLIB
;
11204 if (val
& DF_1_NODUMP
)
11206 printf (" NODUMP");
11207 val
^= DF_1_NODUMP
;
11209 if (val
& DF_1_CONFALT
)
11211 printf (" CONFALT");
11212 val
^= DF_1_CONFALT
;
11214 if (val
& DF_1_ENDFILTEE
)
11216 printf (" ENDFILTEE");
11217 val
^= DF_1_ENDFILTEE
;
11219 if (val
& DF_1_DISPRELDNE
)
11221 printf (" DISPRELDNE");
11222 val
^= DF_1_DISPRELDNE
;
11224 if (val
& DF_1_DISPRELPND
)
11226 printf (" DISPRELPND");
11227 val
^= DF_1_DISPRELPND
;
11229 if (val
& DF_1_NODIRECT
)
11231 printf (" NODIRECT");
11232 val
^= DF_1_NODIRECT
;
11234 if (val
& DF_1_IGNMULDEF
)
11236 printf (" IGNMULDEF");
11237 val
^= DF_1_IGNMULDEF
;
11239 if (val
& DF_1_NOKSYMS
)
11241 printf (" NOKSYMS");
11242 val
^= DF_1_NOKSYMS
;
11244 if (val
& DF_1_NOHDR
)
11249 if (val
& DF_1_EDITED
)
11251 printf (" EDITED");
11252 val
^= DF_1_EDITED
;
11254 if (val
& DF_1_NORELOC
)
11256 printf (" NORELOC");
11257 val
^= DF_1_NORELOC
;
11259 if (val
& DF_1_SYMINTPOSE
)
11261 printf (" SYMINTPOSE");
11262 val
^= DF_1_SYMINTPOSE
;
11264 if (val
& DF_1_GLOBAUDIT
)
11266 printf (" GLOBAUDIT");
11267 val
^= DF_1_GLOBAUDIT
;
11269 if (val
& DF_1_SINGLETON
)
11271 printf (" SINGLETON");
11272 val
^= DF_1_SINGLETON
;
11274 if (val
& DF_1_STUB
)
11279 if (val
& DF_1_PIE
)
11284 if (val
& DF_1_KMOD
)
11289 if (val
& DF_1_WEAKFILTER
)
11291 printf (" WEAKFILTER");
11292 val
^= DF_1_WEAKFILTER
;
11294 if (val
& DF_1_NOCOMMON
)
11296 printf (" NOCOMMON");
11297 val
^= DF_1_NOCOMMON
;
11300 printf (" %lx", val
);
11307 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11309 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
11329 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11335 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11336 name
= get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11342 switch (entry
->d_tag
)
11345 printf (_("Shared library: [%s]"), name
);
11347 if (filedata
->program_interpreter
11348 && streq (name
, filedata
->program_interpreter
))
11349 printf (_(" program interpreter"));
11353 printf (_("Library soname: [%s]"), name
);
11357 printf (_("Library rpath: [%s]"), name
);
11361 printf (_("Library runpath: [%s]"), name
);
11365 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11370 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11383 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11384 /* Fall through. */
11388 case DT_INIT_ARRAYSZ
:
11389 case DT_FINI_ARRAYSZ
:
11390 case DT_GNU_CONFLICTSZ
:
11391 case DT_GNU_LIBLISTSZ
:
11394 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11395 printf (_(" (bytes)\n"));
11400 case DT_VERNEEDNUM
:
11405 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11414 case DT_INIT_ARRAY
:
11415 case DT_FINI_ARRAY
:
11418 if (entry
->d_tag
== DT_USED
11419 && valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11422 = get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11426 printf (_("Not needed object: [%s]\n"), name
);
11431 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11437 /* The value of this entry is ignored. */
11442 case DT_GNU_PRELINKED
:
11446 time_t atime
= entry
->d_un
.d_val
;
11448 tmp
= gmtime (&atime
);
11449 /* PR 17533 file: 041-1244816-0.004. */
11451 printf (_("<corrupt time val: %lx"),
11452 (unsigned long) atime
);
11454 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
11455 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11456 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11462 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11465 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11470 case DT_GNU_FLAGS_1
:
11473 printf (_("Flags:"));
11474 if (entry
->d_un
.d_val
== 0)
11475 printf (_(" None\n"));
11478 unsigned long int val
= entry
->d_un
.d_val
;
11480 if (val
& DF_GNU_1_UNIQUE
)
11482 printf (" UNIQUE");
11483 val
^= DF_GNU_1_UNIQUE
;
11486 printf (" %lx", val
);
11493 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
11494 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
11495 = entry
->d_un
.d_val
;
11499 switch (filedata
->file_header
.e_machine
)
11502 dynamic_section_aarch64_val (entry
);
11505 case EM_MIPS_RS3_LE
:
11506 dynamic_section_mips_val (filedata
, entry
);
11509 dynamic_section_parisc_val (entry
);
11512 dynamic_section_ia64_val (entry
);
11515 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11527 get_ver_flags (unsigned int flags
)
11529 static char buff
[128];
11536 if (flags
& VER_FLG_BASE
)
11537 strcat (buff
, "BASE");
11539 if (flags
& VER_FLG_WEAK
)
11541 if (flags
& VER_FLG_BASE
)
11542 strcat (buff
, " | ");
11544 strcat (buff
, "WEAK");
11547 if (flags
& VER_FLG_INFO
)
11549 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
11550 strcat (buff
, " | ");
11552 strcat (buff
, "INFO");
11555 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11557 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11558 strcat (buff
, " | ");
11560 strcat (buff
, _("<unknown>"));
11566 /* Display the contents of the version sections. */
11569 process_version_sections (Filedata
* filedata
)
11571 Elf_Internal_Shdr
* section
;
11573 bool found
= false;
11578 for (i
= 0, section
= filedata
->section_headers
;
11579 i
< filedata
->file_header
.e_shnum
;
11582 switch (section
->sh_type
)
11584 case SHT_GNU_verdef
:
11586 Elf_External_Verdef
* edefs
;
11593 if (filedata
->is_separate
)
11594 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
11595 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
11597 filedata
->file_name
,
11598 printable_section_name (filedata
, section
),
11601 printf (ngettext ("\nVersion definition section '%s' "
11602 "contains %u entry:\n",
11603 "\nVersion definition section '%s' "
11604 "contains %u entries:\n",
11606 printable_section_name (filedata
, section
),
11609 printf (_(" Addr: 0x"));
11610 printf_vma (section
->sh_addr
);
11611 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11612 (unsigned long) section
->sh_offset
, section
->sh_link
,
11613 printable_section_name_from_index (filedata
, section
->sh_link
));
11615 edefs
= (Elf_External_Verdef
*)
11616 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
11617 _("version definition section"));
11620 endbuf
= (char *) edefs
+ section
->sh_size
;
11622 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11625 Elf_External_Verdef
* edef
;
11626 Elf_Internal_Verdef ent
;
11627 Elf_External_Verdaux
* eaux
;
11628 Elf_Internal_Verdaux aux
;
11629 unsigned long isum
;
11632 vstart
= ((char *) edefs
) + idx
;
11633 if (vstart
+ sizeof (*edef
) > endbuf
)
11636 edef
= (Elf_External_Verdef
*) vstart
;
11638 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
11639 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
11640 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
11641 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
11642 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
11643 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
11644 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
11646 printf (_(" %#06lx: Rev: %d Flags: %s"),
11647 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
11649 printf (_(" Index: %d Cnt: %d "),
11650 ent
.vd_ndx
, ent
.vd_cnt
);
11652 /* Check for overflow. */
11653 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
11656 vstart
+= ent
.vd_aux
;
11658 if (vstart
+ sizeof (*eaux
) > endbuf
)
11660 eaux
= (Elf_External_Verdaux
*) vstart
;
11662 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11663 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11665 if (valid_dynamic_name (filedata
, aux
.vda_name
))
11666 printf (_("Name: %s\n"),
11667 get_dynamic_name (filedata
, aux
.vda_name
));
11669 printf (_("Name index: %ld\n"), aux
.vda_name
);
11671 isum
= idx
+ ent
.vd_aux
;
11673 for (j
= 1; j
< ent
.vd_cnt
; j
++)
11675 if (aux
.vda_next
< sizeof (*eaux
)
11676 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
11678 warn (_("Invalid vda_next field of %lx\n"),
11683 /* Check for overflow. */
11684 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
11687 isum
+= aux
.vda_next
;
11688 vstart
+= aux
.vda_next
;
11690 if (vstart
+ sizeof (*eaux
) > endbuf
)
11692 eaux
= (Elf_External_Verdaux
*) vstart
;
11694 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11695 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11697 if (valid_dynamic_name (filedata
, aux
.vda_name
))
11698 printf (_(" %#06lx: Parent %d: %s\n"),
11700 get_dynamic_name (filedata
, aux
.vda_name
));
11702 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
11703 isum
, j
, aux
.vda_name
);
11706 if (j
< ent
.vd_cnt
)
11707 printf (_(" Version def aux past end of section\n"));
11710 file: id:000001,src:000172+005151,op:splice,rep:2. */
11711 if (ent
.vd_next
< sizeof (*edef
)
11712 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
11714 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
11715 cnt
= section
->sh_info
;
11718 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
11721 idx
+= ent
.vd_next
;
11724 if (cnt
< section
->sh_info
)
11725 printf (_(" Version definition past end of section\n"));
11731 case SHT_GNU_verneed
:
11733 Elf_External_Verneed
* eneed
;
11740 if (filedata
->is_separate
)
11741 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
11742 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
11744 filedata
->file_name
,
11745 printable_section_name (filedata
, section
),
11748 printf (ngettext ("\nVersion needs section '%s' "
11749 "contains %u entry:\n",
11750 "\nVersion needs section '%s' "
11751 "contains %u entries:\n",
11753 printable_section_name (filedata
, section
),
11756 printf (_(" Addr: 0x"));
11757 printf_vma (section
->sh_addr
);
11758 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11759 (unsigned long) section
->sh_offset
, section
->sh_link
,
11760 printable_section_name_from_index (filedata
, section
->sh_link
));
11762 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
11763 section
->sh_offset
, 1,
11765 _("Version Needs section"));
11768 endbuf
= (char *) eneed
+ section
->sh_size
;
11770 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11772 Elf_External_Verneed
* entry
;
11773 Elf_Internal_Verneed ent
;
11774 unsigned long isum
;
11778 vstart
= ((char *) eneed
) + idx
;
11779 if (vstart
+ sizeof (*entry
) > endbuf
)
11782 entry
= (Elf_External_Verneed
*) vstart
;
11784 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
11785 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
11786 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
11787 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
11788 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
11790 printf (_(" %#06lx: Version: %d"), idx
, ent
.vn_version
);
11792 if (valid_dynamic_name (filedata
, ent
.vn_file
))
11793 printf (_(" File: %s"),
11794 get_dynamic_name (filedata
, ent
.vn_file
));
11796 printf (_(" File: %lx"), ent
.vn_file
);
11798 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
11800 /* Check for overflow. */
11801 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
11803 vstart
+= ent
.vn_aux
;
11805 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
11807 Elf_External_Vernaux
* eaux
;
11808 Elf_Internal_Vernaux aux
;
11810 if (vstart
+ sizeof (*eaux
) > endbuf
)
11812 eaux
= (Elf_External_Vernaux
*) vstart
;
11814 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
11815 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
11816 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
11817 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
11818 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
11820 if (valid_dynamic_name (filedata
, aux
.vna_name
))
11821 printf (_(" %#06lx: Name: %s"),
11822 isum
, get_dynamic_name (filedata
, aux
.vna_name
));
11824 printf (_(" %#06lx: Name index: %lx"),
11825 isum
, aux
.vna_name
);
11827 printf (_(" Flags: %s Version: %d\n"),
11828 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
11830 if (aux
.vna_next
< sizeof (*eaux
)
11831 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
11833 warn (_("Invalid vna_next field of %lx\n"),
11838 /* Check for overflow. */
11839 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
11841 isum
+= aux
.vna_next
;
11842 vstart
+= aux
.vna_next
;
11845 if (j
< ent
.vn_cnt
)
11846 warn (_("Missing Version Needs auxiliary information\n"));
11848 if (ent
.vn_next
< sizeof (*entry
)
11849 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
11851 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
11852 cnt
= section
->sh_info
;
11855 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
11857 idx
+= ent
.vn_next
;
11860 if (cnt
< section
->sh_info
)
11861 warn (_("Missing Version Needs information\n"));
11867 case SHT_GNU_versym
:
11869 Elf_Internal_Shdr
* link_section
;
11872 unsigned char * edata
;
11873 unsigned short * data
;
11875 Elf_Internal_Sym
* symbols
;
11876 Elf_Internal_Shdr
* string_sec
;
11877 unsigned long num_syms
;
11880 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
11883 link_section
= filedata
->section_headers
+ section
->sh_link
;
11884 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
11886 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
11891 symbols
= get_elf_symbols (filedata
, link_section
, & num_syms
);
11892 if (symbols
== NULL
)
11895 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
11897 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
11898 string_sec
->sh_size
,
11899 _("version string table"));
11906 if (filedata
->is_separate
)
11907 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n",
11908 "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n",
11910 filedata
->file_name
,
11911 printable_section_name (filedata
, section
),
11912 (unsigned long) total
);
11914 printf (ngettext ("\nVersion symbols section '%s' "
11915 "contains %lu entry:\n",
11916 "\nVersion symbols section '%s' "
11917 "contains %lu entries:\n",
11919 printable_section_name (filedata
, section
),
11920 (unsigned long) total
);
11922 printf (_(" Addr: 0x"));
11923 printf_vma (section
->sh_addr
);
11924 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11925 (unsigned long) section
->sh_offset
, section
->sh_link
,
11926 printable_section_name (filedata
, link_section
));
11928 off
= offset_from_vma (filedata
,
11929 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
11930 total
* sizeof (short));
11931 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
11932 sizeof (short), total
,
11933 _("version symbol data"));
11941 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
11943 for (cnt
= total
; cnt
--;)
11944 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
11949 for (cnt
= 0; cnt
< total
; cnt
+= 4)
11953 char *invalid
= _("*invalid*");
11955 printf (" %03x:", cnt
);
11957 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
11958 switch (data
[cnt
+ j
])
11961 fputs (_(" 0 (*local*) "), stdout
);
11965 fputs (_(" 1 (*global*) "), stdout
);
11969 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
11970 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
11972 /* If this index value is greater than the size of the symbols
11973 array, break to avoid an out-of-bounds read. */
11974 if ((unsigned long)(cnt
+ j
) >= num_syms
)
11976 warn (_("invalid index into symbol array\n"));
11981 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
11983 Elf_Internal_Verneed ivn
;
11984 unsigned long offset
;
11986 offset
= offset_from_vma
11988 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
11989 sizeof (Elf_External_Verneed
));
11993 Elf_Internal_Vernaux ivna
;
11994 Elf_External_Verneed evn
;
11995 Elf_External_Vernaux evna
;
11996 unsigned long a_off
;
11998 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
11999 _("version need")) == NULL
)
12002 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12003 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12005 a_off
= offset
+ ivn
.vn_aux
;
12009 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
12010 1, _("version need aux (2)")) == NULL
)
12013 ivna
.vna_other
= 0;
12017 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12018 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12021 a_off
+= ivna
.vna_next
;
12023 while (ivna
.vna_other
!= data
[cnt
+ j
]
12024 && ivna
.vna_next
!= 0);
12026 if (ivna
.vna_other
== data
[cnt
+ j
])
12028 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12030 if (ivna
.vna_name
>= string_sec
->sh_size
)
12033 name
= strtab
+ ivna
.vna_name
;
12037 offset
+= ivn
.vn_next
;
12039 while (ivn
.vn_next
);
12042 if (data
[cnt
+ j
] != 0x8001
12043 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12045 Elf_Internal_Verdef ivd
;
12046 Elf_External_Verdef evd
;
12047 unsigned long offset
;
12049 offset
= offset_from_vma
12051 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
12056 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
12057 _("version def")) == NULL
)
12060 /* PR 17531: file: 046-1082287-0.004. */
12061 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
12066 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12067 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12070 offset
+= ivd
.vd_next
;
12072 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
12073 && ivd
.vd_next
!= 0);
12075 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
12077 Elf_External_Verdaux evda
;
12078 Elf_Internal_Verdaux ivda
;
12080 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12082 if (get_data (&evda
, filedata
,
12083 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
12085 _("version def aux")) == NULL
)
12088 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12090 if (ivda
.vda_name
>= string_sec
->sh_size
)
12092 else if (name
!= NULL
&& name
!= invalid
)
12093 name
= _("*both*");
12095 name
= strtab
+ ivda
.vda_name
;
12099 nn
+= printf ("(%s%-*s",
12101 12 - (int) strlen (name
),
12105 printf ("%*c", 18 - nn
, ' ');
12124 if (filedata
->is_separate
)
12125 printf (_("\nNo version information found in linked file '%s'.\n"),
12126 filedata
->file_name
);
12128 printf (_("\nNo version information found in this file.\n"));
12134 static const char *
12135 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
12137 static char buff
[64];
12141 case STB_LOCAL
: return "LOCAL";
12142 case STB_GLOBAL
: return "GLOBAL";
12143 case STB_WEAK
: return "WEAK";
12145 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
12146 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
12148 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
12150 if (binding
== STB_GNU_UNIQUE
12151 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
12153 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
12156 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
12161 static const char *
12162 get_symbol_type (Filedata
* filedata
, unsigned int type
)
12164 static char buff
[64];
12168 case STT_NOTYPE
: return "NOTYPE";
12169 case STT_OBJECT
: return "OBJECT";
12170 case STT_FUNC
: return "FUNC";
12171 case STT_SECTION
: return "SECTION";
12172 case STT_FILE
: return "FILE";
12173 case STT_COMMON
: return "COMMON";
12174 case STT_TLS
: return "TLS";
12175 case STT_RELC
: return "RELC";
12176 case STT_SRELC
: return "SRELC";
12178 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
12180 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
12181 return "THUMB_FUNC";
12183 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
12186 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
12187 return "PARISC_MILLI";
12189 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
12191 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
12193 if (filedata
->file_header
.e_machine
== EM_PARISC
)
12195 if (type
== STT_HP_OPAQUE
)
12196 return "HP_OPAQUE";
12197 if (type
== STT_HP_STUB
)
12201 if (type
== STT_GNU_IFUNC
12202 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
12203 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
12206 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
12209 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
12214 static const char *
12215 get_symbol_visibility (unsigned int visibility
)
12217 switch (visibility
)
12219 case STV_DEFAULT
: return "DEFAULT";
12220 case STV_INTERNAL
: return "INTERNAL";
12221 case STV_HIDDEN
: return "HIDDEN";
12222 case STV_PROTECTED
: return "PROTECTED";
12224 error (_("Unrecognized visibility value: %u\n"), visibility
);
12225 return _("<unknown>");
12229 static const char *
12230 get_alpha_symbol_other (unsigned int other
)
12234 case STO_ALPHA_NOPV
: return "NOPV";
12235 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
12237 error (_("Unrecognized alpha specific other value: %u\n"), other
);
12238 return _("<unknown>");
12242 static const char *
12243 get_solaris_symbol_visibility (unsigned int visibility
)
12245 switch (visibility
)
12247 case 4: return "EXPORTED";
12248 case 5: return "SINGLETON";
12249 case 6: return "ELIMINATE";
12250 default: return get_symbol_visibility (visibility
);
12254 static const char *
12255 get_aarch64_symbol_other (unsigned int other
)
12257 static char buf
[32];
12259 if (other
& STO_AARCH64_VARIANT_PCS
)
12261 other
&= ~STO_AARCH64_VARIANT_PCS
;
12263 return "VARIANT_PCS";
12264 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
12270 static const char *
12271 get_mips_symbol_other (unsigned int other
)
12275 case STO_OPTIONAL
: return "OPTIONAL";
12276 case STO_MIPS_PLT
: return "MIPS PLT";
12277 case STO_MIPS_PIC
: return "MIPS PIC";
12278 case STO_MICROMIPS
: return "MICROMIPS";
12279 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
12280 case STO_MIPS16
: return "MIPS16";
12281 default: return NULL
;
12285 static const char *
12286 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
12288 if (is_ia64_vms (filedata
))
12290 static char res
[32];
12294 /* Function types is for images and .STB files only. */
12295 switch (filedata
->file_header
.e_type
)
12299 switch (VMS_ST_FUNC_TYPE (other
))
12301 case VMS_SFT_CODE_ADDR
:
12302 strcat (res
, " CA");
12304 case VMS_SFT_SYMV_IDX
:
12305 strcat (res
, " VEC");
12308 strcat (res
, " FD");
12310 case VMS_SFT_RESERVE
:
12311 strcat (res
, " RSV");
12314 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
12315 VMS_ST_FUNC_TYPE (other
));
12316 strcat (res
, " <unknown>");
12323 switch (VMS_ST_LINKAGE (other
))
12325 case VMS_STL_IGNORE
:
12326 strcat (res
, " IGN");
12328 case VMS_STL_RESERVE
:
12329 strcat (res
, " RSV");
12332 strcat (res
, " STD");
12335 strcat (res
, " LNK");
12338 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
12339 VMS_ST_LINKAGE (other
));
12340 strcat (res
, " <unknown>");
12352 static const char *
12353 get_ppc64_symbol_other (unsigned int other
)
12355 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
12358 other
>>= STO_PPC64_LOCAL_BIT
;
12361 static char buf
[64];
12363 other
= ppc64_decode_local_entry (other
);
12364 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
12370 static const char *
12371 get_symbol_other (Filedata
* filedata
, unsigned int other
)
12373 const char * result
= NULL
;
12374 static char buff
[64];
12379 switch (filedata
->file_header
.e_machine
)
12382 result
= get_alpha_symbol_other (other
);
12385 result
= get_aarch64_symbol_other (other
);
12388 result
= get_mips_symbol_other (other
);
12391 result
= get_ia64_symbol_other (filedata
, other
);
12394 result
= get_ppc64_symbol_other (other
);
12404 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
12408 static const char *
12409 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
12411 static char buff
[32];
12415 case SHN_UNDEF
: return "UND";
12416 case SHN_ABS
: return "ABS";
12417 case SHN_COMMON
: return "COM";
12419 if (type
== SHN_IA_64_ANSI_COMMON
12420 && filedata
->file_header
.e_machine
== EM_IA_64
12421 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
12423 else if ((filedata
->file_header
.e_machine
== EM_X86_64
12424 || filedata
->file_header
.e_machine
== EM_L1OM
12425 || filedata
->file_header
.e_machine
== EM_K1OM
)
12426 && type
== SHN_X86_64_LCOMMON
)
12427 return "LARGE_COM";
12428 else if ((type
== SHN_MIPS_SCOMMON
12429 && filedata
->file_header
.e_machine
== EM_MIPS
)
12430 || (type
== SHN_TIC6X_SCOMMON
12431 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
12433 else if (type
== SHN_MIPS_SUNDEFINED
12434 && filedata
->file_header
.e_machine
== EM_MIPS
)
12436 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
12437 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
12438 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
12439 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
12440 else if (type
>= SHN_LORESERVE
)
12441 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
12442 else if (filedata
->file_header
.e_shnum
!= 0
12443 && type
>= filedata
->file_header
.e_shnum
)
12444 sprintf (buff
, _("bad section index[%3d]"), type
);
12446 sprintf (buff
, "%3d", type
);
12453 static const char *
12454 get_symbol_version_string (Filedata
* filedata
,
12456 const char * strtab
,
12457 unsigned long int strtab_size
,
12459 Elf_Internal_Sym
* psym
,
12460 enum versioned_symbol_info
* sym_info
,
12461 unsigned short * vna_other
)
12463 unsigned char data
[2];
12464 unsigned short vers_data
;
12465 unsigned long offset
;
12466 unsigned short max_vd_ndx
;
12469 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
12472 offset
= offset_from_vma (filedata
,
12473 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12474 sizeof data
+ si
* sizeof (vers_data
));
12476 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
12477 sizeof (data
), 1, _("version data")) == NULL
)
12480 vers_data
= byte_get (data
, 2);
12482 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
12485 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
12488 /* Usually we'd only see verdef for defined symbols, and verneed for
12489 undefined symbols. However, symbols defined by the linker in
12490 .dynbss for variables copied from a shared library in order to
12491 avoid text relocations are defined yet have verneed. We could
12492 use a heuristic to detect the special case, for example, check
12493 for verneed first on symbols defined in SHT_NOBITS sections, but
12494 it is simpler and more reliable to just look for both verdef and
12495 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
12497 if (psym
->st_shndx
!= SHN_UNDEF
12498 && vers_data
!= 0x8001
12499 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12501 Elf_Internal_Verdef ivd
;
12502 Elf_Internal_Verdaux ivda
;
12503 Elf_External_Verdaux evda
;
12506 off
= offset_from_vma (filedata
,
12507 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
12508 sizeof (Elf_External_Verdef
));
12512 Elf_External_Verdef evd
;
12514 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
12515 _("version def")) == NULL
)
12524 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12525 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12526 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12527 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
12530 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
12531 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
12533 off
+= ivd
.vd_next
;
12535 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
12537 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
12539 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
12542 off
-= ivd
.vd_next
;
12545 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
12546 _("version def aux")) != NULL
)
12548 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12550 if (psym
->st_name
!= ivda
.vda_name
)
12551 return (ivda
.vda_name
< strtab_size
12552 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
12557 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12559 Elf_External_Verneed evn
;
12560 Elf_Internal_Verneed ivn
;
12561 Elf_Internal_Vernaux ivna
;
12563 offset
= offset_from_vma (filedata
,
12564 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12568 unsigned long vna_off
;
12570 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12571 _("version need")) == NULL
)
12574 ivna
.vna_other
= 0;
12579 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12580 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12582 vna_off
= offset
+ ivn
.vn_aux
;
12586 Elf_External_Vernaux evna
;
12588 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
12589 _("version need aux (3)")) == NULL
)
12592 ivna
.vna_other
= 0;
12597 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12598 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12599 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12602 vna_off
+= ivna
.vna_next
;
12604 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
12606 if (ivna
.vna_other
== vers_data
)
12609 offset
+= ivn
.vn_next
;
12611 while (ivn
.vn_next
!= 0);
12613 if (ivna
.vna_other
== vers_data
)
12615 *sym_info
= symbol_undefined
;
12616 *vna_other
= ivna
.vna_other
;
12617 return (ivna
.vna_name
< strtab_size
12618 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
12620 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
12621 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
12622 return _("<corrupt>");
12627 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
12629 static unsigned int
12630 print_dynamic_symbol_size (bfd_vma vma
, int base
)
12635 return print_vma (vma
, OCTAL_5
);
12638 return print_vma (vma
, UNSIGNED_5
);
12641 return print_vma (vma
, PREFIX_HEX_5
);
12645 return print_vma (vma
, DEC_5
);
12650 print_dynamic_symbol (Filedata
*filedata
, unsigned long si
,
12651 Elf_Internal_Sym
*symtab
,
12652 Elf_Internal_Shdr
*section
,
12653 char *strtab
, size_t strtab_size
)
12655 const char *version_string
;
12656 enum versioned_symbol_info sym_info
;
12657 unsigned short vna_other
;
12660 Elf_Internal_Sym
*psym
= symtab
+ si
;
12662 printf ("%6ld: ", si
);
12663 print_vma (psym
->st_value
, LONG_HEX
);
12665 print_dynamic_symbol_size (psym
->st_size
, sym_base
);
12666 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
12667 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
12668 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
12669 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
12672 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
12674 printf (" %-7s", get_symbol_visibility (vis
));
12675 /* Check to see if any other bits in the st_other field are set.
12676 Note - displaying this information disrupts the layout of the
12677 table being generated, but for the moment this case is very rare. */
12678 if (psym
->st_other
^ vis
)
12679 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
12681 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
12683 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
12684 && psym
->st_shndx
< filedata
->file_header
.e_shnum
12685 && psym
->st_name
== 0)
12688 = section_name_valid (filedata
,
12689 filedata
->section_headers
+ psym
->st_shndx
);
12691 section_name_print (filedata
,
12692 filedata
->section_headers
+ psym
->st_shndx
)
12697 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
12698 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
12702 = get_symbol_version_string (filedata
,
12704 || section
->sh_type
== SHT_DYNSYM
),
12705 strtab
, strtab_size
, si
,
12706 psym
, &sym_info
, &vna_other
);
12708 int len_avail
= 21;
12709 if (! do_wide
&& version_string
!= NULL
)
12713 len_avail
-= 1 + strlen (version_string
);
12715 if (sym_info
== symbol_undefined
)
12716 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
12717 else if (sym_info
!= symbol_hidden
)
12721 print_symbol (len_avail
, sstr
);
12723 if (version_string
)
12725 if (sym_info
== symbol_undefined
)
12726 printf ("@%s (%d)", version_string
, vna_other
);
12728 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
12734 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
12736 && si
>= section
->sh_info
12737 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
12738 && filedata
->file_header
.e_machine
!= EM_MIPS
12739 /* Solaris binaries have been found to violate this requirement as
12740 well. Not sure if this is a bug or an ABI requirement. */
12741 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
12742 warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"),
12743 si
, printable_section_name (filedata
, section
), section
->sh_info
);
12746 static const char *
12747 get_lto_kind (unsigned int kind
)
12751 case 0: return "DEF";
12752 case 1: return "WEAKDEF";
12753 case 2: return "UNDEF";
12754 case 3: return "WEAKUNDEF";
12755 case 4: return "COMMON";
12760 static char buffer
[30];
12761 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
12762 sprintf (buffer
, "<unknown: %u>", kind
);
12766 static const char *
12767 get_lto_visibility (unsigned int visibility
)
12769 switch (visibility
)
12771 case 0: return "DEFAULT";
12772 case 1: return "PROTECTED";
12773 case 2: return "INTERNAL";
12774 case 3: return "HIDDEN";
12779 static char buffer
[30];
12780 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
12781 sprintf (buffer
, "<unknown: %u>", visibility
);
12785 static const char *
12786 get_lto_sym_type (unsigned int sym_type
)
12790 case 0: return "UNKNOWN";
12791 case 1: return "FUNCTION";
12792 case 2: return "VARIABLE";
12797 static char buffer
[30];
12798 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
12799 sprintf (buffer
, "<unknown: %u>", sym_type
);
12803 /* Display an LTO format symbol table.
12804 FIXME: The format of LTO symbol tables is not formalized.
12805 So this code could need changing in the future. */
12808 display_lto_symtab (Filedata
* filedata
,
12809 Elf_Internal_Shdr
* section
)
12811 if (section
->sh_size
== 0)
12813 if (filedata
->is_separate
)
12814 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
12815 printable_section_name (filedata
, section
),
12816 filedata
->file_name
);
12818 printf (_("\nLTO Symbol table '%s' is empty!\n"),
12819 printable_section_name (filedata
, section
));
12824 if (section
->sh_size
> filedata
->file_size
)
12826 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
12827 printable_section_name (filedata
, section
),
12828 (unsigned long) section
->sh_size
);
12832 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
12833 section
->sh_size
, 1, _("LTO symbols"));
12834 if (alloced_data
== NULL
)
12837 /* Look for extended data for the symbol table. */
12838 Elf_Internal_Shdr
* ext
;
12839 void * ext_data_orig
= NULL
;
12840 char * ext_data
= NULL
;
12841 char * ext_data_end
= NULL
;
12842 char * ext_name
= NULL
;
12844 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
12845 (section_name (filedata
, section
)
12846 + sizeof (".gnu.lto_.symtab.") - 1)) > 0
12847 && ext_name
!= NULL
/* Paranoia. */
12848 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
12850 if (ext
->sh_size
< 3)
12851 error (_("LTO Symbol extension table '%s' is empty!\n"),
12852 printable_section_name (filedata
, ext
));
12855 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
12857 _("LTO ext symbol data"));
12858 if (ext_data
!= NULL
)
12860 ext_data_end
= ext_data
+ ext
->sh_size
;
12861 if (* ext_data
++ != 1)
12862 error (_("Unexpected version number in symbol extension table\n"));
12867 const unsigned char * data
= (const unsigned char *) alloced_data
;
12868 const unsigned char * end
= data
+ section
->sh_size
;
12870 if (filedata
->is_separate
)
12871 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
12875 if (ext_data_orig
!= NULL
)
12878 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
12879 printable_section_name (filedata
, section
),
12880 printable_section_name (filedata
, ext
));
12883 printf (_("LTO Symbol table '%s'\n"),
12884 printable_section_name (filedata
, section
));
12885 printf (_(" and extension table '%s' contain:\n"),
12886 printable_section_name (filedata
, ext
));
12890 printf (_("LTO Symbol table '%s' contains:\n"),
12891 printable_section_name (filedata
, section
));
12893 /* FIXME: Add a wide version. */
12894 if (ext_data_orig
!= NULL
)
12895 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
12897 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
12899 /* FIXME: We do not handle style prefixes. */
12903 const unsigned char * sym_name
= data
;
12904 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
12908 const unsigned char * comdat_key
= data
;
12909 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
12913 if (data
+ 2 + 8 + 4 > end
)
12916 unsigned int kind
= *data
++;
12917 unsigned int visibility
= *data
++;
12919 elf_vma size
= byte_get (data
, 8);
12922 elf_vma slot
= byte_get (data
, 4);
12925 if (ext_data
!= NULL
)
12927 if (ext_data
< (ext_data_end
- 1))
12929 unsigned int sym_type
= * ext_data
++;
12930 unsigned int sec_kind
= * ext_data
++;
12932 printf (" %10s %10s %11s %08lx %08lx %9s %08lx _",
12933 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
12934 get_lto_kind (kind
),
12935 get_lto_visibility (visibility
),
12938 get_lto_sym_type (sym_type
),
12940 print_symbol (6, (const char *) sym_name
);
12944 error (_("Ran out of LTO symbol extension data\n"));
12946 /* FIXME: return FAIL result ? */
12951 printf (" %10s %10s %11s %08lx %08lx _",
12952 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
12953 get_lto_kind (kind
),
12954 get_lto_visibility (visibility
),
12957 print_symbol (21, (const char *) sym_name
);
12962 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
12964 error (_("Data remains in the LTO symbol extension table\n"));
12968 free (alloced_data
);
12969 free (ext_data_orig
);
12974 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
12975 free (alloced_data
);
12976 free (ext_data_orig
);
12981 /* Display LTO symbol tables. */
12984 process_lto_symbol_tables (Filedata
* filedata
)
12986 Elf_Internal_Shdr
* section
;
12993 if (filedata
->section_headers
== NULL
)
12996 for (i
= 0, section
= filedata
->section_headers
;
12997 i
< filedata
->file_header
.e_shnum
;
12999 if (section_name_valid (filedata
, section
)
13000 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
13001 res
&= display_lto_symtab (filedata
, section
);
13006 /* Dump the symbol table. */
13009 process_symbol_table (Filedata
* filedata
)
13011 Elf_Internal_Shdr
* section
;
13013 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
13016 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
13018 && do_using_dynamic
13019 && filedata
->dynamic_strings
!= NULL
13020 && filedata
->dynamic_symbols
!= NULL
)
13024 if (filedata
->is_separate
)
13026 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n",
13027 "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n",
13028 filedata
->num_dynamic_syms
),
13029 filedata
->file_name
,
13030 filedata
->num_dynamic_syms
);
13034 printf (ngettext ("\nSymbol table for image contains %lu entry:\n",
13035 "\nSymbol table for image contains %lu entries:\n",
13036 filedata
->num_dynamic_syms
),
13037 filedata
->num_dynamic_syms
);
13040 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13042 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13044 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
13045 print_dynamic_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
13046 filedata
->dynamic_strings
,
13047 filedata
->dynamic_strings_length
);
13049 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
13050 && filedata
->section_headers
!= NULL
)
13054 for (i
= 0, section
= filedata
->section_headers
;
13055 i
< filedata
->file_header
.e_shnum
;
13058 char * strtab
= NULL
;
13059 unsigned long int strtab_size
= 0;
13060 Elf_Internal_Sym
* symtab
;
13061 unsigned long si
, num_syms
;
13063 if ((section
->sh_type
!= SHT_SYMTAB
13064 && section
->sh_type
!= SHT_DYNSYM
)
13066 && section
->sh_type
== SHT_SYMTAB
))
13069 if (section
->sh_entsize
== 0)
13071 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
13072 printable_section_name (filedata
, section
));
13076 num_syms
= section
->sh_size
/ section
->sh_entsize
;
13078 if (filedata
->is_separate
)
13079 printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n",
13080 "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n",
13082 filedata
->file_name
,
13083 printable_section_name (filedata
, section
),
13086 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
13087 "\nSymbol table '%s' contains %lu entries:\n",
13089 printable_section_name (filedata
, section
),
13093 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13095 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13097 symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
13098 if (symtab
== NULL
)
13101 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
13103 strtab
= filedata
->string_table
;
13104 strtab_size
= filedata
->string_table_length
;
13106 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
13108 Elf_Internal_Shdr
* string_sec
;
13110 string_sec
= filedata
->section_headers
+ section
->sh_link
;
13112 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
13113 1, string_sec
->sh_size
,
13114 _("string table"));
13115 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
13118 for (si
= 0; si
< num_syms
; si
++)
13119 print_dynamic_symbol (filedata
, si
, symtab
, section
,
13120 strtab
, strtab_size
);
13123 if (strtab
!= filedata
->string_table
)
13129 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
13131 if (do_histogram
&& filedata
->buckets
!= NULL
)
13133 unsigned long * lengths
;
13134 unsigned long * counts
;
13137 unsigned long maxlength
= 0;
13138 unsigned long nzero_counts
= 0;
13139 unsigned long nsyms
= 0;
13142 printf (ngettext ("\nHistogram for bucket list length "
13143 "(total of %lu bucket):\n",
13144 "\nHistogram for bucket list length "
13145 "(total of %lu buckets):\n",
13146 (unsigned long) filedata
->nbuckets
),
13147 (unsigned long) filedata
->nbuckets
);
13149 lengths
= (unsigned long *) calloc (filedata
->nbuckets
,
13150 sizeof (*lengths
));
13151 if (lengths
== NULL
)
13153 error (_("Out of memory allocating space for histogram buckets\n"));
13156 visited
= xcmalloc (filedata
->nchains
, 1);
13157 memset (visited
, 0, filedata
->nchains
);
13159 printf (_(" Length Number %% of total Coverage\n"));
13160 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13162 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
13165 if (maxlength
< ++lengths
[hn
])
13167 if (si
>= filedata
->nchains
|| visited
[si
])
13169 error (_("histogram chain is corrupt\n"));
13177 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
13178 if (counts
== NULL
)
13181 error (_("Out of memory allocating space for histogram counts\n"));
13185 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13186 ++counts
[lengths
[hn
]];
13188 if (filedata
->nbuckets
> 0)
13191 printf (" 0 %-10lu (%5.1f%%)\n",
13192 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
13193 for (i
= 1; i
<= maxlength
; ++i
)
13195 nzero_counts
+= counts
[i
] * i
;
13196 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
13197 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
13198 (nzero_counts
* 100.0) / nsyms
);
13206 free (filedata
->buckets
);
13207 filedata
->buckets
= NULL
;
13208 filedata
->nbuckets
= 0;
13209 free (filedata
->chains
);
13210 filedata
->chains
= NULL
;
13212 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
13214 unsigned long * lengths
;
13215 unsigned long * counts
;
13217 unsigned long maxlength
= 0;
13218 unsigned long nzero_counts
= 0;
13219 unsigned long nsyms
= 0;
13221 printf (ngettext ("\nHistogram for `%s' bucket list length "
13222 "(total of %lu bucket):\n",
13223 "\nHistogram for `%s' bucket list length "
13224 "(total of %lu buckets):\n",
13225 (unsigned long) filedata
->ngnubuckets
),
13226 GNU_HASH_SECTION_NAME (filedata
),
13227 (unsigned long) filedata
->ngnubuckets
);
13229 lengths
= (unsigned long *) calloc (filedata
->ngnubuckets
,
13230 sizeof (*lengths
));
13231 if (lengths
== NULL
)
13233 error (_("Out of memory allocating space for gnu histogram buckets\n"));
13237 printf (_(" Length Number %% of total Coverage\n"));
13239 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13240 if (filedata
->gnubuckets
[hn
] != 0)
13242 bfd_vma off
, length
= 1;
13244 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
13245 /* PR 17531 file: 010-77222-0.004. */
13246 off
< filedata
->ngnuchains
13247 && (filedata
->gnuchains
[off
] & 1) == 0;
13250 lengths
[hn
] = length
;
13251 if (length
> maxlength
)
13252 maxlength
= length
;
13256 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
13257 if (counts
== NULL
)
13260 error (_("Out of memory allocating space for gnu histogram counts\n"));
13264 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13265 ++counts
[lengths
[hn
]];
13267 if (filedata
->ngnubuckets
> 0)
13270 printf (" 0 %-10lu (%5.1f%%)\n",
13271 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
13272 for (j
= 1; j
<= maxlength
; ++j
)
13274 nzero_counts
+= counts
[j
] * j
;
13275 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
13276 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
13277 (nzero_counts
* 100.0) / nsyms
);
13284 free (filedata
->gnubuckets
);
13285 filedata
->gnubuckets
= NULL
;
13286 filedata
->ngnubuckets
= 0;
13287 free (filedata
->gnuchains
);
13288 filedata
->gnuchains
= NULL
;
13289 filedata
->ngnuchains
= 0;
13290 free (filedata
->mipsxlat
);
13291 filedata
->mipsxlat
= NULL
;
13295 free (filedata
->gnubuckets
);
13296 filedata
->gnubuckets
= NULL
;
13297 filedata
->ngnubuckets
= 0;
13298 free (filedata
->gnuchains
);
13299 filedata
->gnuchains
= NULL
;
13300 filedata
->ngnuchains
= 0;
13301 free (filedata
->mipsxlat
);
13302 filedata
->mipsxlat
= NULL
;
13303 free (filedata
->buckets
);
13304 filedata
->buckets
= NULL
;
13305 filedata
->nbuckets
= 0;
13306 free (filedata
->chains
);
13307 filedata
->chains
= NULL
;
13312 process_syminfo (Filedata
* filedata
)
13316 if (filedata
->dynamic_syminfo
== NULL
13318 /* No syminfo, this is ok. */
13321 /* There better should be a dynamic symbol section. */
13322 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
13325 if (filedata
->is_separate
)
13326 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n",
13327 "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n",
13328 filedata
->dynamic_syminfo_nent
),
13329 filedata
->file_name
,
13330 filedata
->dynamic_syminfo_offset
,
13331 filedata
->dynamic_syminfo_nent
);
13333 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
13334 "contains %d entry:\n",
13335 "\nDynamic info segment at offset 0x%lx "
13336 "contains %d entries:\n",
13337 filedata
->dynamic_syminfo_nent
),
13338 filedata
->dynamic_syminfo_offset
,
13339 filedata
->dynamic_syminfo_nent
);
13341 printf (_(" Num: Name BoundTo Flags\n"));
13342 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
13344 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
13346 printf ("%4d: ", i
);
13347 if (i
>= filedata
->num_dynamic_syms
)
13348 printf (_("<corrupt index>"));
13349 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
13350 print_symbol (30, get_dynamic_name (filedata
,
13351 filedata
->dynamic_symbols
[i
].st_name
));
13353 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
13356 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
13358 case SYMINFO_BT_SELF
:
13359 fputs ("SELF ", stdout
);
13361 case SYMINFO_BT_PARENT
:
13362 fputs ("PARENT ", stdout
);
13365 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
13366 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
13367 && valid_dynamic_name (filedata
,
13368 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
13370 print_symbol (10, get_dynamic_name (filedata
,
13371 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
13375 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
13379 if (flags
& SYMINFO_FLG_DIRECT
)
13380 printf (" DIRECT");
13381 if (flags
& SYMINFO_FLG_PASSTHRU
)
13382 printf (" PASSTHRU");
13383 if (flags
& SYMINFO_FLG_COPY
)
13385 if (flags
& SYMINFO_FLG_LAZYLOAD
)
13386 printf (" LAZYLOAD");
13394 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
13395 is contained by the region START .. END. The types of ADDR, START
13396 and END should all be the same. Note both ADDR + NELEM and END
13397 point to just beyond the end of the regions that are being tested. */
13398 #define IN_RANGE(START,END,ADDR,NELEM) \
13399 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
13401 /* Check to see if the given reloc needs to be handled in a target specific
13402 manner. If so then process the reloc and return TRUE otherwise return
13405 If called with reloc == NULL, then this is a signal that reloc processing
13406 for the current section has finished, and any saved state should be
13410 target_specific_reloc_handling (Filedata
* filedata
,
13411 Elf_Internal_Rela
* reloc
,
13412 unsigned char * start
,
13413 unsigned char * end
,
13414 Elf_Internal_Sym
* symtab
,
13415 unsigned long num_syms
)
13417 unsigned int reloc_type
= 0;
13418 unsigned long sym_index
= 0;
13422 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
13423 sym_index
= get_reloc_symindex (reloc
->r_info
);
13426 switch (filedata
->file_header
.e_machine
)
13429 case EM_MSP430_OLD
:
13431 static Elf_Internal_Sym
* saved_sym
= NULL
;
13439 switch (reloc_type
)
13441 case 10: /* R_MSP430_SYM_DIFF */
13442 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
13443 if (uses_msp430x_relocs (filedata
))
13445 /* Fall through. */
13446 case 21: /* R_MSP430X_SYM_DIFF */
13447 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
13449 if (sym_index
>= num_syms
)
13450 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
13453 saved_sym
= symtab
+ sym_index
;
13456 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13457 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
13458 goto handle_sym_diff
;
13460 case 5: /* R_MSP430_16_BYTE */
13461 case 9: /* R_MSP430_8 */
13462 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13463 if (uses_msp430x_relocs (filedata
))
13465 goto handle_sym_diff
;
13467 case 2: /* R_MSP430_ABS16 */
13468 case 15: /* R_MSP430X_ABS16 */
13469 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13470 if (! uses_msp430x_relocs (filedata
))
13472 goto handle_sym_diff
;
13475 if (saved_sym
!= NULL
)
13478 unsigned int reloc_size
= 0;
13480 switch (reloc_type
)
13482 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13485 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13486 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13487 if (reloc
->r_offset
< (size_t) (end
- start
))
13488 read_leb128 (start
+ reloc
->r_offset
, end
, false,
13489 &reloc_size
, &leb_ret
);
13496 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
13497 error (_("MSP430 ULEB128 field at 0x%lx contains invalid "
13498 "ULEB128 value\n"),
13499 (long) reloc
->r_offset
);
13500 else if (sym_index
>= num_syms
)
13501 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
13505 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
13506 - saved_sym
->st_value
);
13508 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
13509 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
13512 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
13513 (long) reloc
->r_offset
);
13522 if (saved_sym
!= NULL
)
13523 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
13530 case EM_CYGNUS_MN10300
:
13532 static Elf_Internal_Sym
* saved_sym
= NULL
;
13540 switch (reloc_type
)
13542 case 34: /* R_MN10300_ALIGN */
13544 case 33: /* R_MN10300_SYM_DIFF */
13545 if (sym_index
>= num_syms
)
13546 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
13549 saved_sym
= symtab
+ sym_index
;
13552 case 1: /* R_MN10300_32 */
13553 case 2: /* R_MN10300_16 */
13554 if (saved_sym
!= NULL
)
13556 int reloc_size
= reloc_type
== 1 ? 4 : 2;
13559 if (sym_index
>= num_syms
)
13560 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
13564 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
13565 - saved_sym
->st_value
);
13567 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
13568 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
13570 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
13571 (long) reloc
->r_offset
);
13579 if (saved_sym
!= NULL
)
13580 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
13588 static bfd_vma saved_sym1
= 0;
13589 static bfd_vma saved_sym2
= 0;
13590 static bfd_vma value
;
13594 saved_sym1
= saved_sym2
= 0;
13598 switch (reloc_type
)
13600 case 0x80: /* R_RL78_SYM. */
13601 saved_sym1
= saved_sym2
;
13602 if (sym_index
>= num_syms
)
13603 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
13607 saved_sym2
= symtab
[sym_index
].st_value
;
13608 saved_sym2
+= reloc
->r_addend
;
13612 case 0x83: /* R_RL78_OPsub. */
13613 value
= saved_sym1
- saved_sym2
;
13614 saved_sym2
= saved_sym1
= 0;
13618 case 0x41: /* R_RL78_ABS32. */
13619 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
13620 byte_put (start
+ reloc
->r_offset
, value
, 4);
13622 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13623 (long) reloc
->r_offset
);
13627 case 0x43: /* R_RL78_ABS16. */
13628 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
13629 byte_put (start
+ reloc
->r_offset
, value
, 2);
13631 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13632 (long) reloc
->r_offset
);
13646 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
13647 DWARF debug sections. This is a target specific test. Note - we do not
13648 go through the whole including-target-headers-multiple-times route, (as
13649 we have already done with <elf/h8.h>) because this would become very
13650 messy and even then this function would have to contain target specific
13651 information (the names of the relocs instead of their numeric values).
13652 FIXME: This is not the correct way to solve this problem. The proper way
13653 is to have target specific reloc sizing and typing functions created by
13654 the reloc-macros.h header, in the same way that it already creates the
13655 reloc naming functions. */
13658 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13660 /* Please keep this table alpha-sorted for ease of visual lookup. */
13661 switch (filedata
->file_header
.e_machine
)
13665 return reloc_type
== 1; /* R_386_32. */
13667 return reloc_type
== 1; /* R_68K_32. */
13669 return reloc_type
== 1; /* R_860_32. */
13671 return reloc_type
== 2; /* R_960_32. */
13673 return (reloc_type
== 258
13674 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
13676 return reloc_type
== 11; /* R_BPF_DATA_32 */
13677 case EM_ADAPTEVA_EPIPHANY
:
13678 return reloc_type
== 3;
13680 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
13682 return reloc_type
== 1; /* R_ARC_32. */
13683 case EM_ARC_COMPACT
:
13684 case EM_ARC_COMPACT2
:
13685 return reloc_type
== 4; /* R_ARC_32. */
13687 return reloc_type
== 2; /* R_ARM_ABS32 */
13690 return reloc_type
== 1;
13692 return reloc_type
== 0x12; /* R_byte4_data. */
13694 return reloc_type
== 3; /* R_CRIS_32. */
13696 return reloc_type
== 3; /* R_CR16_NUM32. */
13698 return reloc_type
== 15; /* R_CRX_NUM32. */
13700 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
13701 case EM_CYGNUS_FRV
:
13702 return reloc_type
== 1;
13703 case EM_CYGNUS_D10V
:
13705 return reloc_type
== 6; /* R_D10V_32. */
13706 case EM_CYGNUS_D30V
:
13708 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
13710 return reloc_type
== 3; /* R_DLX_RELOC_32. */
13711 case EM_CYGNUS_FR30
:
13713 return reloc_type
== 3; /* R_FR30_32. */
13715 return reloc_type
== 1; /* R_FT32_32. */
13719 return reloc_type
== 1; /* R_H8_DIR32. */
13721 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
13722 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
13723 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
13724 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
13727 return reloc_type
== 2; /* R_IP2K_32. */
13729 return reloc_type
== 2; /* R_IQ2000_32. */
13730 case EM_LATTICEMICO32
:
13731 return reloc_type
== 3; /* R_LM32_32. */
13733 return reloc_type
== 1; /* R_LARCH_32. */
13736 return reloc_type
== 3; /* R_M32C_32. */
13738 return reloc_type
== 34; /* R_M32R_32_RELA. */
13741 return reloc_type
== 6; /* R_M68HC11_32. */
13743 return reloc_type
== 7 || /* R_S12Z_EXT32 */
13744 reloc_type
== 6; /* R_S12Z_CW32. */
13746 return reloc_type
== 1; /* R_MCORE_ADDR32. */
13747 case EM_CYGNUS_MEP
:
13748 return reloc_type
== 4; /* R_MEP_32. */
13750 return reloc_type
== 2; /* R_METAG_ADDR32. */
13751 case EM_MICROBLAZE
:
13752 return reloc_type
== 1; /* R_MICROBLAZE_32. */
13754 return reloc_type
== 2; /* R_MIPS_32. */
13756 return reloc_type
== 4; /* R_MMIX_32. */
13757 case EM_CYGNUS_MN10200
:
13759 return reloc_type
== 1; /* R_MN10200_32. */
13760 case EM_CYGNUS_MN10300
:
13762 return reloc_type
== 1; /* R_MN10300_32. */
13764 return reloc_type
== 1; /* R_MOXIE_32. */
13765 case EM_MSP430_OLD
:
13767 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
13769 return reloc_type
== 2; /* R_MT_32. */
13771 return reloc_type
== 20; /* R_NDS32_RELA. */
13772 case EM_ALTERA_NIOS2
:
13773 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
13775 return reloc_type
== 1; /* R_NIOS_32. */
13777 return reloc_type
== 1; /* R_OR1K_32. */
13779 return (reloc_type
== 1 /* R_PARISC_DIR32. */
13780 || reloc_type
== 2 /* R_PARISC_DIR21L. */
13781 || reloc_type
== 41); /* R_PARISC_SECREL32. */
13784 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
13786 return reloc_type
== 1; /* R_PPC64_ADDR32. */
13788 return reloc_type
== 1; /* R_PPC_ADDR32. */
13790 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
13792 return reloc_type
== 1; /* R_RISCV_32. */
13794 return reloc_type
== 1; /* R_RL78_DIR32. */
13796 return reloc_type
== 1; /* R_RX_DIR32. */
13798 return reloc_type
== 1; /* R_I370_ADDR31. */
13801 return reloc_type
== 4; /* R_S390_32. */
13803 return reloc_type
== 8; /* R_SCORE_ABS32. */
13805 return reloc_type
== 1; /* R_SH_DIR32. */
13806 case EM_SPARC32PLUS
:
13809 return reloc_type
== 3 /* R_SPARC_32. */
13810 || reloc_type
== 23; /* R_SPARC_UA32. */
13812 return reloc_type
== 6; /* R_SPU_ADDR32 */
13814 return reloc_type
== 1; /* R_C6000_ABS32. */
13816 return reloc_type
== 2; /* R_TILEGX_32. */
13818 return reloc_type
== 1; /* R_TILEPRO_32. */
13819 case EM_CYGNUS_V850
:
13821 return reloc_type
== 6; /* R_V850_ABS32. */
13823 return reloc_type
== 0x33; /* R_V810_WORD. */
13825 return reloc_type
== 1; /* R_VAX_32. */
13827 return reloc_type
== 3; /* R_VISIUM_32. */
13828 case EM_WEBASSEMBLY
:
13829 return reloc_type
== 1; /* R_WASM32_32. */
13833 return reloc_type
== 10; /* R_X86_64_32. */
13836 return reloc_type
== 3; /* R_XC16C_ABS_32. */
13838 return reloc_type
== 4; /* R_XGATE_32. */
13840 return reloc_type
== 1; /* R_XSTROMY16_32. */
13841 case EM_XTENSA_OLD
:
13843 return reloc_type
== 1; /* R_XTENSA_32. */
13845 return reloc_type
== 6; /* R_Z80_32. */
13848 static unsigned int prev_warn
= 0;
13850 /* Avoid repeating the same warning multiple times. */
13851 if (prev_warn
!= filedata
->file_header
.e_machine
)
13852 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
13853 filedata
->file_header
.e_machine
);
13854 prev_warn
= filedata
->file_header
.e_machine
;
13860 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13861 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
13864 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13866 switch (filedata
->file_header
.e_machine
)
13867 /* Please keep this table alpha-sorted for ease of visual lookup. */
13871 return reloc_type
== 2; /* R_386_PC32. */
13873 return reloc_type
== 4; /* R_68K_PC32. */
13875 return reloc_type
== 261; /* R_AARCH64_PREL32 */
13876 case EM_ADAPTEVA_EPIPHANY
:
13877 return reloc_type
== 6;
13879 return reloc_type
== 10; /* R_ALPHA_SREL32. */
13880 case EM_ARC_COMPACT
:
13881 case EM_ARC_COMPACT2
:
13882 return reloc_type
== 49; /* R_ARC_32_PCREL. */
13884 return reloc_type
== 3; /* R_ARM_REL32 */
13887 return reloc_type
== 36; /* R_AVR_32_PCREL. */
13888 case EM_MICROBLAZE
:
13889 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
13891 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
13893 return reloc_type
== 9; /* R_PARISC_PCREL32. */
13895 return reloc_type
== 26; /* R_PPC_REL32. */
13897 return reloc_type
== 26; /* R_PPC64_REL32. */
13899 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
13902 return reloc_type
== 5; /* R_390_PC32. */
13904 return reloc_type
== 2; /* R_SH_REL32. */
13905 case EM_SPARC32PLUS
:
13908 return reloc_type
== 6; /* R_SPARC_DISP32. */
13910 return reloc_type
== 13; /* R_SPU_REL32. */
13912 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
13914 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
13916 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
13920 return reloc_type
== 2; /* R_X86_64_PC32. */
13922 return reloc_type
== 4; /* R_VAX_PCREL32. */
13923 case EM_XTENSA_OLD
:
13925 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
13927 /* Do not abort or issue an error message here. Not all targets use
13928 pc-relative 32-bit relocs in their DWARF debug information and we
13929 have already tested for target coverage in is_32bit_abs_reloc. A
13930 more helpful warning message will be generated by apply_relocations
13931 anyway, so just return. */
13936 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13937 a 64-bit absolute RELA relocation used in DWARF debug sections. */
13940 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13942 switch (filedata
->file_header
.e_machine
)
13945 return reloc_type
== 257; /* R_AARCH64_ABS64. */
13947 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
13949 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
13950 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
13952 return reloc_type
== 2; /* R_LARCH_64 */
13954 return reloc_type
== 80; /* R_PARISC_DIR64. */
13956 return reloc_type
== 38; /* R_PPC64_ADDR64. */
13958 return reloc_type
== 2; /* R_RISCV_64. */
13959 case EM_SPARC32PLUS
:
13962 return reloc_type
== 32 /* R_SPARC_64. */
13963 || reloc_type
== 54; /* R_SPARC_UA64. */
13967 return reloc_type
== 1; /* R_X86_64_64. */
13970 return reloc_type
== 22; /* R_S390_64. */
13972 return reloc_type
== 1; /* R_TILEGX_64. */
13974 return reloc_type
== 18; /* R_MIPS_64. */
13980 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
13981 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
13984 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13986 switch (filedata
->file_header
.e_machine
)
13989 return reloc_type
== 260; /* R_AARCH64_PREL64. */
13991 return reloc_type
== 11; /* R_ALPHA_SREL64. */
13993 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
13994 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
13996 return reloc_type
== 72; /* R_PARISC_PCREL64. */
13998 return reloc_type
== 44; /* R_PPC64_REL64. */
13999 case EM_SPARC32PLUS
:
14002 return reloc_type
== 46; /* R_SPARC_DISP64. */
14006 return reloc_type
== 24; /* R_X86_64_PC64. */
14009 return reloc_type
== 23; /* R_S390_PC64. */
14011 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
14017 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14018 a 24-bit absolute RELA relocation used in DWARF debug sections. */
14021 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14023 switch (filedata
->file_header
.e_machine
)
14025 case EM_CYGNUS_MN10200
:
14027 return reloc_type
== 4; /* R_MN10200_24. */
14029 return reloc_type
== 5; /* R_FT32_20. */
14031 return reloc_type
== 5; /* R_Z80_24. */
14037 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14038 a 16-bit absolute RELA relocation used in DWARF debug sections. */
14041 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14043 /* Please keep this table alpha-sorted for ease of visual lookup. */
14044 switch (filedata
->file_header
.e_machine
)
14047 case EM_ARC_COMPACT
:
14048 case EM_ARC_COMPACT2
:
14049 return reloc_type
== 2; /* R_ARC_16. */
14050 case EM_ADAPTEVA_EPIPHANY
:
14051 return reloc_type
== 5;
14054 return reloc_type
== 4; /* R_AVR_16. */
14055 case EM_CYGNUS_D10V
:
14057 return reloc_type
== 3; /* R_D10V_16. */
14059 return reloc_type
== 2; /* R_FT32_16. */
14063 return reloc_type
== R_H8_DIR16
;
14066 return reloc_type
== 1; /* R_IP2K_16. */
14069 return reloc_type
== 1; /* R_M32C_16 */
14070 case EM_CYGNUS_MN10200
:
14072 return reloc_type
== 2; /* R_MN10200_16. */
14073 case EM_CYGNUS_MN10300
:
14075 return reloc_type
== 2; /* R_MN10300_16. */
14077 if (uses_msp430x_relocs (filedata
))
14078 return reloc_type
== 2; /* R_MSP430_ABS16. */
14079 /* Fall through. */
14080 case EM_MSP430_OLD
:
14081 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
14083 return reloc_type
== 19; /* R_NDS32_RELA. */
14084 case EM_ALTERA_NIOS2
:
14085 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
14087 return reloc_type
== 9; /* R_NIOS_16. */
14089 return reloc_type
== 2; /* R_OR1K_16. */
14091 return reloc_type
== 55; /* R_RISCV_SET16. */
14093 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
14095 return reloc_type
== 2; /* R_C6000_ABS16. */
14097 return reloc_type
== 2; /* R_VISIUM_16. */
14100 return reloc_type
== 2; /* R_XC16C_ABS_16. */
14102 return reloc_type
== 3; /* R_XGATE_16. */
14104 return reloc_type
== 4; /* R_Z80_16. */
14110 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14111 a 8-bit absolute RELA relocation used in DWARF debug sections. */
14114 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14116 switch (filedata
->file_header
.e_machine
)
14119 return reloc_type
== 54; /* R_RISCV_SET8. */
14121 return reloc_type
== 1; /* R_Z80_8. */
14127 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14128 a 6-bit absolute RELA relocation used in DWARF debug sections. */
14131 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14133 switch (filedata
->file_header
.e_machine
)
14136 return reloc_type
== 53; /* R_RISCV_SET6. */
14142 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14143 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
14146 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14148 /* Please keep this table alpha-sorted for ease of visual lookup. */
14149 switch (filedata
->file_header
.e_machine
)
14152 return reloc_type
== 35; /* R_RISCV_ADD32. */
14158 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14159 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
14162 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14164 /* Please keep this table alpha-sorted for ease of visual lookup. */
14165 switch (filedata
->file_header
.e_machine
)
14168 return reloc_type
== 39; /* R_RISCV_SUB32. */
14174 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14175 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
14178 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14180 /* Please keep this table alpha-sorted for ease of visual lookup. */
14181 switch (filedata
->file_header
.e_machine
)
14184 return reloc_type
== 36; /* R_RISCV_ADD64. */
14190 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14191 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
14194 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14196 /* Please keep this table alpha-sorted for ease of visual lookup. */
14197 switch (filedata
->file_header
.e_machine
)
14200 return reloc_type
== 40; /* R_RISCV_SUB64. */
14206 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14207 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
14210 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14212 /* Please keep this table alpha-sorted for ease of visual lookup. */
14213 switch (filedata
->file_header
.e_machine
)
14216 return reloc_type
== 34; /* R_RISCV_ADD16. */
14222 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14223 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
14226 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14228 /* Please keep this table alpha-sorted for ease of visual lookup. */
14229 switch (filedata
->file_header
.e_machine
)
14232 return reloc_type
== 38; /* R_RISCV_SUB16. */
14238 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14239 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
14242 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14244 /* Please keep this table alpha-sorted for ease of visual lookup. */
14245 switch (filedata
->file_header
.e_machine
)
14248 return reloc_type
== 33; /* R_RISCV_ADD8. */
14254 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14255 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
14258 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14260 /* Please keep this table alpha-sorted for ease of visual lookup. */
14261 switch (filedata
->file_header
.e_machine
)
14264 return reloc_type
== 37; /* R_RISCV_SUB8. */
14270 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14271 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
14274 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14276 switch (filedata
->file_header
.e_machine
)
14279 return reloc_type
== 52; /* R_RISCV_SUB6. */
14285 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
14286 relocation entries (possibly formerly used for SHT_GROUP sections). */
14289 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14291 switch (filedata
->file_header
.e_machine
)
14293 case EM_386
: /* R_386_NONE. */
14294 case EM_68K
: /* R_68K_NONE. */
14295 case EM_ADAPTEVA_EPIPHANY
:
14296 case EM_ALPHA
: /* R_ALPHA_NONE. */
14297 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
14298 case EM_ARC
: /* R_ARC_NONE. */
14299 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
14300 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
14301 case EM_ARM
: /* R_ARM_NONE. */
14302 case EM_C166
: /* R_XC16X_NONE. */
14303 case EM_CRIS
: /* R_CRIS_NONE. */
14304 case EM_FT32
: /* R_FT32_NONE. */
14305 case EM_IA_64
: /* R_IA64_NONE. */
14306 case EM_K1OM
: /* R_X86_64_NONE. */
14307 case EM_L1OM
: /* R_X86_64_NONE. */
14308 case EM_M32R
: /* R_M32R_NONE. */
14309 case EM_MIPS
: /* R_MIPS_NONE. */
14310 case EM_MN10300
: /* R_MN10300_NONE. */
14311 case EM_MOXIE
: /* R_MOXIE_NONE. */
14312 case EM_NIOS32
: /* R_NIOS_NONE. */
14313 case EM_OR1K
: /* R_OR1K_NONE. */
14314 case EM_PARISC
: /* R_PARISC_NONE. */
14315 case EM_PPC64
: /* R_PPC64_NONE. */
14316 case EM_PPC
: /* R_PPC_NONE. */
14317 case EM_RISCV
: /* R_RISCV_NONE. */
14318 case EM_S390
: /* R_390_NONE. */
14320 case EM_SH
: /* R_SH_NONE. */
14321 case EM_SPARC32PLUS
:
14322 case EM_SPARC
: /* R_SPARC_NONE. */
14324 case EM_TILEGX
: /* R_TILEGX_NONE. */
14325 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
14326 case EM_TI_C6000
:/* R_C6000_NONE. */
14327 case EM_X86_64
: /* R_X86_64_NONE. */
14329 case EM_Z80
: /* R_Z80_NONE. */
14330 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
14331 return reloc_type
== 0;
14334 return reloc_type
== 0 || reloc_type
== 256;
14337 return (reloc_type
== 0 /* R_AVR_NONE. */
14338 || reloc_type
== 30 /* R_AVR_DIFF8. */
14339 || reloc_type
== 31 /* R_AVR_DIFF16. */
14340 || reloc_type
== 32 /* R_AVR_DIFF32. */);
14342 return reloc_type
== 3; /* R_METAG_NONE. */
14344 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14345 || reloc_type
== 204 /* R_NDS32_DIFF8. */
14346 || reloc_type
== 205 /* R_NDS32_DIFF16. */
14347 || reloc_type
== 206 /* R_NDS32_DIFF32. */
14348 || reloc_type
== 207 /* R_NDS32_ULEB128. */);
14350 return (reloc_type
== 0 /* R_PRU_NONE. */
14351 || reloc_type
== 65 /* R_PRU_DIFF8. */
14352 || reloc_type
== 66 /* R_PRU_DIFF16. */
14353 || reloc_type
== 67 /* R_PRU_DIFF32. */);
14354 case EM_XTENSA_OLD
:
14356 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14357 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
14358 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
14359 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
14360 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
14361 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
14362 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
14363 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
14364 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
14365 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
14370 /* Returns TRUE if there is a relocation against
14371 section NAME at OFFSET bytes. */
14374 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
14376 Elf_Internal_Rela
* relocs
;
14377 Elf_Internal_Rela
* rp
;
14379 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
14382 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
14384 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
14385 if (rp
->r_offset
== offset
)
14391 /* Apply relocations to a section.
14392 Returns TRUE upon success, FALSE otherwise.
14393 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
14394 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
14395 will be set to the number of relocs loaded.
14397 Note: So far support has been added only for those relocations
14398 which can be found in debug sections. FIXME: Add support for
14399 more relocations ? */
14402 apply_relocations (Filedata
* filedata
,
14403 const Elf_Internal_Shdr
* section
,
14404 unsigned char * start
,
14405 bfd_size_type size
,
14406 void ** relocs_return
,
14407 unsigned long * num_relocs_return
)
14409 Elf_Internal_Shdr
* relsec
;
14410 unsigned char * end
= start
+ size
;
14412 if (relocs_return
!= NULL
)
14414 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
14415 * num_relocs_return
= 0;
14418 if (filedata
->file_header
.e_type
!= ET_REL
)
14419 /* No relocs to apply. */
14422 /* Find the reloc section associated with the section. */
14423 for (relsec
= filedata
->section_headers
;
14424 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14428 unsigned long num_relocs
;
14429 Elf_Internal_Rela
* relocs
;
14430 Elf_Internal_Rela
* rp
;
14431 Elf_Internal_Shdr
* symsec
;
14432 Elf_Internal_Sym
* symtab
;
14433 unsigned long num_syms
;
14434 Elf_Internal_Sym
* sym
;
14436 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14437 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14438 || filedata
->section_headers
+ relsec
->sh_info
!= section
14439 || relsec
->sh_size
== 0
14440 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14443 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
14444 if (symsec
->sh_type
!= SHT_SYMTAB
14445 && symsec
->sh_type
!= SHT_DYNSYM
)
14448 is_rela
= relsec
->sh_type
== SHT_RELA
;
14452 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
14453 relsec
->sh_size
, & relocs
, & num_relocs
))
14458 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
14459 relsec
->sh_size
, & relocs
, & num_relocs
))
14463 /* SH uses RELA but uses in place value instead of the addend field. */
14464 if (filedata
->file_header
.e_machine
== EM_SH
)
14467 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
14469 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
14472 unsigned int reloc_type
;
14473 unsigned int reloc_size
;
14474 bool reloc_inplace
= false;
14475 bool reloc_subtract
= false;
14476 unsigned char *rloc
;
14477 unsigned long sym_index
;
14479 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
14481 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
14483 else if (is_none_reloc (filedata
, reloc_type
))
14485 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
14486 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
14488 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
14489 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
14491 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
14493 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
14495 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
14496 || is_6bit_abs_reloc (filedata
, reloc_type
))
14498 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
14500 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
14503 reloc_inplace
= true;
14505 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
14507 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
14510 reloc_inplace
= true;
14512 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
14514 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
14517 reloc_inplace
= true;
14519 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
14521 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
14524 reloc_inplace
= true;
14526 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
14530 reloc_inplace
= true;
14534 static unsigned int prev_reloc
= 0;
14536 if (reloc_type
!= prev_reloc
)
14537 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
14538 reloc_type
, printable_section_name (filedata
, section
));
14539 prev_reloc
= reloc_type
;
14543 rloc
= start
+ rp
->r_offset
;
14544 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
14546 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
14547 (unsigned long) rp
->r_offset
,
14548 printable_section_name (filedata
, section
));
14552 sym_index
= (unsigned long) get_reloc_symindex (rp
->r_info
);
14553 if (sym_index
>= num_syms
)
14555 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
14556 sym_index
, printable_section_name (filedata
, section
));
14559 sym
= symtab
+ sym_index
;
14561 /* If the reloc has a symbol associated with it,
14562 make sure that it is of an appropriate type.
14564 Relocations against symbols without type can happen.
14565 Gcc -feliminate-dwarf2-dups may generate symbols
14566 without type for debug info.
14568 Icc generates relocations against function symbols
14569 instead of local labels.
14571 Relocations against object symbols can happen, eg when
14572 referencing a global array. For an example of this see
14573 the _clz.o binary in libgcc.a. */
14575 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
14576 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
14578 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
14579 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
14580 printable_section_name (filedata
, relsec
),
14581 (long int)(rp
- relocs
));
14587 addend
+= rp
->r_addend
;
14588 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
14589 partial_inplace. */
14591 || (filedata
->file_header
.e_machine
== EM_XTENSA
14592 && reloc_type
== 1)
14593 || ((filedata
->file_header
.e_machine
== EM_PJ
14594 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
14595 && reloc_type
== 1)
14596 || ((filedata
->file_header
.e_machine
== EM_D30V
14597 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
14598 && reloc_type
== 12)
14601 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
14602 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
14604 addend
+= byte_get (rloc
, reloc_size
);
14607 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
14608 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
14610 /* On HPPA, all pc-relative relocations are biased by 8. */
14611 if (filedata
->file_header
.e_machine
== EM_PARISC
)
14613 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
14616 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
14617 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
14619 if (reloc_subtract
)
14620 addend
-= sym
->st_value
;
14622 addend
+= sym
->st_value
;
14623 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
14624 byte_put (rloc
, addend
, reloc_size
);
14626 else if (reloc_subtract
)
14627 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
14629 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
14633 /* Let the target specific reloc processing code know that
14634 we have finished with these relocs. */
14635 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
14639 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
14640 * num_relocs_return
= num_relocs
;
14651 #ifdef SUPPORT_DISASSEMBLY
14653 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14655 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
14657 /* FIXME: XXX -- to be done --- XXX */
14663 /* Reads in the contents of SECTION from FILE, returning a pointer
14664 to a malloc'ed buffer or NULL if something went wrong. */
14667 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14669 bfd_size_type num_bytes
= section
->sh_size
;
14671 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
14673 printf (_("Section '%s' has no data to dump.\n"),
14674 printable_section_name (filedata
, section
));
14678 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
14679 _("section contents"));
14682 /* Uncompresses a section that was compressed using zlib, in place. */
14685 uncompress_section_contents (unsigned char ** buffer
,
14686 dwarf_size_type uncompressed_size
,
14687 dwarf_size_type
* size
)
14689 dwarf_size_type compressed_size
= *size
;
14690 unsigned char * compressed_buffer
= *buffer
;
14691 unsigned char * uncompressed_buffer
;
14695 /* It is possible the section consists of several compressed
14696 buffers concatenated together, so we uncompress in a loop. */
14697 /* PR 18313: The state field in the z_stream structure is supposed
14698 to be invisible to the user (ie us), but some compilers will
14699 still complain about it being used without initialisation. So
14700 we first zero the entire z_stream structure and then set the fields
14702 memset (& strm
, 0, sizeof strm
);
14703 strm
.avail_in
= compressed_size
;
14704 strm
.next_in
= (Bytef
*) compressed_buffer
;
14705 strm
.avail_out
= uncompressed_size
;
14706 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
14708 rc
= inflateInit (& strm
);
14709 while (strm
.avail_in
> 0)
14713 strm
.next_out
= ((Bytef
*) uncompressed_buffer
14714 + (uncompressed_size
- strm
.avail_out
));
14715 rc
= inflate (&strm
, Z_FINISH
);
14716 if (rc
!= Z_STREAM_END
)
14718 rc
= inflateReset (& strm
);
14720 if (inflateEnd (& strm
) != Z_OK
14722 || strm
.avail_out
!= 0)
14725 *buffer
= uncompressed_buffer
;
14726 *size
= uncompressed_size
;
14730 free (uncompressed_buffer
);
14731 /* Indicate decompression failure. */
14737 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14739 Elf_Internal_Shdr
*relsec
;
14740 bfd_size_type num_bytes
;
14741 unsigned char *data
;
14742 unsigned char *end
;
14743 unsigned char *real_start
;
14744 unsigned char *start
;
14745 bool some_strings_shown
;
14747 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
14749 /* PR 21820: Do not fail if the section was empty. */
14750 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
14752 num_bytes
= section
->sh_size
;
14754 if (filedata
->is_separate
)
14755 printf (_("\nString dump of section '%s' in linked file %s:\n"),
14756 printable_section_name (filedata
, section
),
14757 filedata
->file_name
);
14759 printf (_("\nString dump of section '%s':\n"),
14760 printable_section_name (filedata
, section
));
14762 if (decompress_dumps
)
14764 dwarf_size_type new_size
= num_bytes
;
14765 dwarf_size_type uncompressed_size
= 0;
14767 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14769 Elf_Internal_Chdr chdr
;
14770 unsigned int compression_header_size
14771 = get_compression_header (& chdr
, (unsigned char *) start
,
14773 if (compression_header_size
== 0)
14774 /* An error message will have already been generated
14775 by get_compression_header. */
14778 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14780 warn (_("section '%s' has unsupported compress type: %d\n"),
14781 printable_section_name (filedata
, section
), chdr
.ch_type
);
14784 uncompressed_size
= chdr
.ch_size
;
14785 start
+= compression_header_size
;
14786 new_size
-= compression_header_size
;
14788 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
14790 /* Read the zlib header. In this case, it should be "ZLIB"
14791 followed by the uncompressed section size, 8 bytes in
14792 big-endian order. */
14793 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14794 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14795 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14796 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14797 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14798 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14799 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14800 uncompressed_size
+= start
[11];
14805 if (uncompressed_size
)
14807 if (uncompress_section_contents (& start
,
14808 uncompressed_size
, & new_size
))
14809 num_bytes
= new_size
;
14812 error (_("Unable to decompress section %s\n"),
14813 printable_section_name (filedata
, section
));
14818 start
= real_start
;
14821 /* If the section being dumped has relocations against it the user might
14822 be expecting these relocations to have been applied. Check for this
14823 case and issue a warning message in order to avoid confusion.
14824 FIXME: Maybe we ought to have an option that dumps a section with
14825 relocs applied ? */
14826 for (relsec
= filedata
->section_headers
;
14827 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14830 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14831 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14832 || filedata
->section_headers
+ relsec
->sh_info
!= section
14833 || relsec
->sh_size
== 0
14834 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14837 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14842 end
= start
+ num_bytes
;
14843 some_strings_shown
= false;
14845 #ifdef HAVE_MBSTATE_T
14847 /* Initialise the multibyte conversion state. */
14848 memset (& state
, 0, sizeof (state
));
14851 bool continuing
= false;
14855 while (!ISPRINT (* data
))
14856 if (++ data
>= end
)
14861 size_t maxlen
= end
- data
;
14866 continuing
= false;
14870 printf (" [%6lx] ", (unsigned long) (data
- start
));
14884 /* PR 25543: Treat new-lines as string-ending characters. */
14893 /* Do not print control characters directly as they can affect terminal
14894 settings. Such characters usually appear in the names generated
14895 by the assembler for local labels. */
14898 printf ("^%c", c
+ 0x40);
14900 else if (ISPRINT (c
))
14907 #ifdef HAVE_MBSTATE_T
14910 /* Let printf do the hard work of displaying multibyte characters. */
14911 printf ("%.1s", data
- 1);
14912 #ifdef HAVE_MBSTATE_T
14913 /* Try to find out how many bytes made up the character that was
14914 just printed. Advance the symbol pointer past the bytes that
14916 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
14920 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
14930 printf (_("<corrupt>\n"));
14933 some_strings_shown
= true;
14937 if (! some_strings_shown
)
14938 printf (_(" No strings found in this section."));
14951 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
14952 Filedata
*filedata
,
14955 Elf_Internal_Shdr
* relsec
;
14956 bfd_size_type bytes
;
14957 bfd_size_type section_size
;
14959 unsigned char * data
;
14960 unsigned char * real_start
;
14961 unsigned char * start
;
14963 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
14965 /* PR 21820: Do not fail if the section was empty. */
14966 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
14968 section_size
= section
->sh_size
;
14970 if (filedata
->is_separate
)
14971 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
14972 printable_section_name (filedata
, section
),
14973 filedata
->file_name
);
14975 printf (_("\nHex dump of section '%s':\n"),
14976 printable_section_name (filedata
, section
));
14978 if (decompress_dumps
)
14980 dwarf_size_type new_size
= section_size
;
14981 dwarf_size_type uncompressed_size
= 0;
14983 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14985 Elf_Internal_Chdr chdr
;
14986 unsigned int compression_header_size
14987 = get_compression_header (& chdr
, start
, section_size
);
14989 if (compression_header_size
== 0)
14990 /* An error message will have already been generated
14991 by get_compression_header. */
14994 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14996 warn (_("section '%s' has unsupported compress type: %d\n"),
14997 printable_section_name (filedata
, section
), chdr
.ch_type
);
15000 uncompressed_size
= chdr
.ch_size
;
15001 start
+= compression_header_size
;
15002 new_size
-= compression_header_size
;
15004 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15006 /* Read the zlib header. In this case, it should be "ZLIB"
15007 followed by the uncompressed section size, 8 bytes in
15008 big-endian order. */
15009 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15010 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15011 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15012 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15013 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15014 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15015 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15016 uncompressed_size
+= start
[11];
15021 if (uncompressed_size
)
15023 if (uncompress_section_contents (& start
, uncompressed_size
,
15026 section_size
= new_size
;
15030 error (_("Unable to decompress section %s\n"),
15031 printable_section_name (filedata
, section
));
15032 /* FIXME: Print the section anyway ? */
15037 start
= real_start
;
15042 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
15047 /* If the section being dumped has relocations against it the user might
15048 be expecting these relocations to have been applied. Check for this
15049 case and issue a warning message in order to avoid confusion.
15050 FIXME: Maybe we ought to have an option that dumps a section with
15051 relocs applied ? */
15052 for (relsec
= filedata
->section_headers
;
15053 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15056 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15057 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15058 || filedata
->section_headers
+ relsec
->sh_info
!= section
15059 || relsec
->sh_size
== 0
15060 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15063 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
15068 addr
= section
->sh_addr
;
15069 bytes
= section_size
;
15078 lbytes
= (bytes
> 16 ? 16 : bytes
);
15080 printf (" 0x%8.8lx ", (unsigned long) addr
);
15082 for (j
= 0; j
< 16; j
++)
15085 printf ("%2.2x", data
[j
]);
15093 for (j
= 0; j
< lbytes
; j
++)
15096 if (k
>= ' ' && k
< 0x7f)
15119 #ifdef ENABLE_LIBCTF
15120 static ctf_sect_t
*
15121 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
15123 buf
->cts_name
= section_name_print (filedata
, shdr
);
15124 buf
->cts_size
= shdr
->sh_size
;
15125 buf
->cts_entsize
= shdr
->sh_entsize
;
15130 /* Formatting callback function passed to ctf_dump. Returns either the pointer
15131 it is passed, or a pointer to newly-allocated storage, in which case
15132 dump_ctf() will free it when it no longer needs it. */
15135 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
15136 char *s
, void *arg
)
15138 const char *blanks
= arg
;
15141 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
15146 /* Dump CTF errors/warnings. */
15148 dump_ctf_errs (ctf_dict_t
*fp
)
15150 ctf_next_t
*it
= NULL
;
15155 /* Dump accumulated errors and warnings. */
15156 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
15158 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
15162 if (err
!= ECTF_NEXT_END
)
15163 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
15166 /* Dump one CTF archive member. */
15169 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
15172 const char *things
[] = {"Header", "Labels", "Data objects",
15173 "Function objects", "Variables", "Types", "Strings",
15175 const char **thing
;
15178 /* Don't print out the name of the default-named archive member if it appears
15179 first in the list. The name .ctf appears everywhere, even for things that
15180 aren't really archives, so printing it out is liable to be confusing; also,
15181 the common case by far is for only one archive member to exist, and hiding
15182 it in that case seems worthwhile. */
15184 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
15185 printf (_("\nCTF archive member: %s:\n"), name
);
15187 if (ctf_parent_name (ctf
) != NULL
)
15188 ctf_import (ctf
, parent
);
15190 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
15192 ctf_dump_state_t
*s
= NULL
;
15195 printf ("\n %s:\n", *thing
);
15196 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
15197 (void *) " ")) != NULL
)
15199 printf ("%s\n", item
);
15203 if (ctf_errno (ctf
))
15205 error (_("Iteration failed: %s, %s\n"), *thing
,
15206 ctf_errmsg (ctf_errno (ctf
)));
15211 dump_ctf_errs (ctf
);
15215 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15217 Elf_Internal_Shdr
* symtab_sec
= NULL
;
15218 Elf_Internal_Shdr
* strtab_sec
= NULL
;
15219 void * data
= NULL
;
15220 void * symdata
= NULL
;
15221 void * strdata
= NULL
;
15222 ctf_sect_t ctfsect
, symsect
, strsect
;
15223 ctf_sect_t
* symsectp
= NULL
;
15224 ctf_sect_t
* strsectp
= NULL
;
15225 ctf_archive_t
* ctfa
= NULL
;
15226 ctf_dict_t
* parent
= NULL
;
15229 ctf_next_t
*i
= NULL
;
15235 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
15236 data
= get_section_contents (section
, filedata
);
15237 ctfsect
.cts_data
= data
;
15239 if (!dump_ctf_symtab_name
)
15240 dump_ctf_symtab_name
= strdup (".dynsym");
15242 if (!dump_ctf_strtab_name
)
15243 dump_ctf_strtab_name
= strdup (".dynstr");
15245 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
15247 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
15249 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
15252 if ((symdata
= (void *) get_data (NULL
, filedata
,
15253 symtab_sec
->sh_offset
, 1,
15254 symtab_sec
->sh_size
,
15255 _("symbols"))) == NULL
)
15257 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
15258 symsect
.cts_data
= symdata
;
15261 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
15263 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
15265 error (_("No string table section named %s\n"),
15266 dump_ctf_strtab_name
);
15269 if ((strdata
= (void *) get_data (NULL
, filedata
,
15270 strtab_sec
->sh_offset
, 1,
15271 strtab_sec
->sh_size
,
15272 _("strings"))) == NULL
)
15274 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
15275 strsect
.cts_data
= strdata
;
15278 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
15279 libctf papers over the difference, so we can pretend it is always an
15282 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
15284 dump_ctf_errs (NULL
);
15285 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15289 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
15292 /* Preload the parent dict, since it will need to be imported into every
15294 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
15296 dump_ctf_errs (NULL
);
15297 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15303 if (filedata
->is_separate
)
15304 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
15305 printable_section_name (filedata
, section
),
15306 filedata
->file_name
);
15308 printf (_("\nDump of CTF section '%s':\n"),
15309 printable_section_name (filedata
, section
));
15311 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
15312 dump_ctf_archive_member (fp
, name
, parent
, member
++);
15313 if (err
!= ECTF_NEXT_END
)
15315 dump_ctf_errs (NULL
);
15316 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
15321 ctf_dict_close (parent
);
15331 load_specific_debug_section (enum dwarf_section_display_enum debug
,
15332 const Elf_Internal_Shdr
* sec
,
15335 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15337 Filedata
* filedata
= (Filedata
*) data
;
15339 if (section
->start
!= NULL
)
15341 /* If it is already loaded, do nothing. */
15342 if (streq (section
->filename
, filedata
->file_name
))
15344 free (section
->start
);
15347 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
15348 section
->address
= sec
->sh_addr
;
15349 section
->filename
= filedata
->file_name
;
15350 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
15352 sec
->sh_size
, buf
);
15353 if (section
->start
== NULL
)
15357 unsigned char *start
= section
->start
;
15358 dwarf_size_type size
= sec
->sh_size
;
15359 dwarf_size_type uncompressed_size
= 0;
15361 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
15363 Elf_Internal_Chdr chdr
;
15364 unsigned int compression_header_size
;
15366 if (size
< (is_32bit_elf
15367 ? sizeof (Elf32_External_Chdr
)
15368 : sizeof (Elf64_External_Chdr
)))
15370 warn (_("compressed section %s is too small to contain a compression header\n"),
15375 compression_header_size
= get_compression_header (&chdr
, start
, size
);
15376 if (compression_header_size
== 0)
15377 /* An error message will have already been generated
15378 by get_compression_header. */
15381 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15383 warn (_("section '%s' has unsupported compress type: %d\n"),
15384 section
->name
, chdr
.ch_type
);
15387 uncompressed_size
= chdr
.ch_size
;
15388 start
+= compression_header_size
;
15389 size
-= compression_header_size
;
15391 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
15393 /* Read the zlib header. In this case, it should be "ZLIB"
15394 followed by the uncompressed section size, 8 bytes in
15395 big-endian order. */
15396 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15397 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15398 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15399 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15400 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15401 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15402 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15403 uncompressed_size
+= start
[11];
15408 if (uncompressed_size
)
15410 if (uncompress_section_contents (&start
, uncompressed_size
,
15413 /* Free the compressed buffer, update the section buffer
15414 and the section size if uncompress is successful. */
15415 free (section
->start
);
15416 section
->start
= start
;
15420 error (_("Unable to decompress section %s\n"),
15421 printable_section_name (filedata
, sec
));
15426 section
->size
= size
;
15429 if (section
->start
== NULL
)
15432 if (debug_displays
[debug
].relocate
)
15434 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
15435 & section
->reloc_info
, & section
->num_relocs
))
15440 section
->reloc_info
= NULL
;
15441 section
->num_relocs
= 0;
15447 #if HAVE_LIBDEBUGINFOD
15448 /* Return a hex string representation of the build-id. */
15450 get_build_id (void * data
)
15452 Filedata
* filedata
= (Filedata
*) data
;
15453 Elf_Internal_Shdr
* shdr
;
15456 /* Iterate through notes to find note.gnu.build-id.
15457 FIXME: Only the first note in any note section is examined. */
15458 for (i
= 0, shdr
= filedata
->section_headers
;
15459 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
15462 if (shdr
->sh_type
!= SHT_NOTE
)
15467 size_t data_remaining
;
15469 Elf_External_Note
* enote
;
15470 Elf_Internal_Note inote
;
15472 bfd_vma offset
= shdr
->sh_offset
;
15473 bfd_vma align
= shdr
->sh_addralign
;
15474 bfd_vma length
= shdr
->sh_size
;
15476 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
15482 else if (align
!= 4 && align
!= 8)
15488 end
= (char *) enote
+ length
;
15489 data_remaining
= end
- (char *) enote
;
15491 if (!is_ia64_vms (filedata
))
15493 min_notesz
= offsetof (Elf_External_Note
, name
);
15494 if (data_remaining
< min_notesz
)
15497 malformed note encountered in section %s whilst scanning for build-id note\n"),
15498 printable_section_name (filedata
, shdr
));
15502 data_remaining
-= min_notesz
;
15504 inote
.type
= BYTE_GET (enote
->type
);
15505 inote
.namesz
= BYTE_GET (enote
->namesz
);
15506 inote
.namedata
= enote
->name
;
15507 inote
.descsz
= BYTE_GET (enote
->descsz
);
15508 inote
.descdata
= ((char *) enote
15509 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
15510 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
15511 next
= ((char *) enote
15512 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
15516 Elf64_External_VMS_Note
*vms_enote
;
15518 /* PR binutils/15191
15519 Make sure that there is enough data to read. */
15520 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
15521 if (data_remaining
< min_notesz
)
15524 malformed note encountered in section %s whilst scanning for build-id note\n"),
15525 printable_section_name (filedata
, shdr
));
15529 data_remaining
-= min_notesz
;
15531 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
15532 inote
.type
= BYTE_GET (vms_enote
->type
);
15533 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
15534 inote
.namedata
= vms_enote
->name
;
15535 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
15536 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
15537 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
15538 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
15541 /* Skip malformed notes. */
15542 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
15543 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
15544 || (size_t) (next
- inote
.descdata
) < inote
.descsz
15545 || ((size_t) (next
- inote
.descdata
)
15546 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
15549 malformed note encountered in section %s whilst scanning for build-id note\n"),
15550 printable_section_name (filedata
, shdr
));
15555 /* Check if this is the build-id note. If so then convert the build-id
15556 bytes to a hex string. */
15557 if (inote
.namesz
> 0
15558 && startswith (inote
.namedata
, "GNU")
15559 && inote
.type
== NT_GNU_BUILD_ID
)
15564 build_id
= malloc (inote
.descsz
* 2 + 1);
15565 if (build_id
== NULL
)
15571 for (j
= 0; j
< inote
.descsz
; ++j
)
15572 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
15573 build_id
[inote
.descsz
* 2] = '\0';
15576 return (unsigned char *) build_id
;
15583 #endif /* HAVE_LIBDEBUGINFOD */
15585 /* If this is not NULL, load_debug_section will only look for sections
15586 within the list of sections given here. */
15587 static unsigned int * section_subset
= NULL
;
15590 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
15592 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15593 Elf_Internal_Shdr
* sec
;
15594 Filedata
* filedata
= (Filedata
*) data
;
15596 /* Without section headers we cannot find any sections. */
15597 if (filedata
->section_headers
== NULL
)
15600 if (filedata
->string_table
== NULL
15601 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
15602 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
15604 Elf_Internal_Shdr
* strs
;
15606 /* Read in the string table, so that we have section names to scan. */
15607 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
15609 if (strs
!= NULL
&& strs
->sh_size
!= 0)
15611 filedata
->string_table
15612 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
15613 1, strs
->sh_size
, _("string table"));
15615 filedata
->string_table_length
15616 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
15620 /* Locate the debug section. */
15621 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
15623 section
->name
= section
->uncompressed_name
;
15626 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
15628 section
->name
= section
->compressed_name
;
15633 /* If we're loading from a subset of sections, and we've loaded
15634 a section matching this name before, it's likely that it's a
15636 if (section_subset
!= NULL
)
15637 free_debug_section (debug
);
15639 return load_specific_debug_section (debug
, sec
, data
);
15643 free_debug_section (enum dwarf_section_display_enum debug
)
15645 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15647 if (section
->start
== NULL
)
15650 free ((char *) section
->start
);
15651 section
->start
= NULL
;
15652 section
->address
= 0;
15655 free (section
->reloc_info
);
15656 section
->reloc_info
= NULL
;
15657 section
->num_relocs
= 0;
15661 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15663 const char *name
= (section_name_valid (filedata
, section
)
15664 ? section_name (filedata
, section
) : "");
15665 const char *print_name
= printable_section_name (filedata
, section
);
15666 bfd_size_type length
;
15667 bool result
= true;
15670 length
= section
->sh_size
;
15673 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
15676 if (section
->sh_type
== SHT_NOBITS
)
15678 /* There is no point in dumping the contents of a debugging section
15679 which has the NOBITS type - the bits in the file will be random.
15680 This can happen when a file containing a .eh_frame section is
15681 stripped with the --only-keep-debug command line option. */
15682 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
15687 if (startswith (name
, ".gnu.linkonce.wi."))
15688 name
= ".debug_info";
15690 /* See if we know how to display the contents of this section. */
15691 for (i
= 0; i
< max
; i
++)
15693 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
15694 struct dwarf_section_display
* display
= debug_displays
+ i
;
15695 struct dwarf_section
* sec
= & display
->section
;
15697 if (streq (sec
->uncompressed_name
, name
)
15698 || (id
== line
&& startswith (name
, ".debug_line."))
15699 || streq (sec
->compressed_name
, name
))
15701 bool secondary
= (section
!= find_section (filedata
, name
));
15704 free_debug_section (id
);
15706 if (i
== line
&& startswith (name
, ".debug_line."))
15708 else if (streq (sec
->uncompressed_name
, name
))
15709 sec
->name
= sec
->uncompressed_name
;
15711 sec
->name
= sec
->compressed_name
;
15713 if (load_specific_debug_section (id
, section
, filedata
))
15715 /* If this debug section is part of a CU/TU set in a .dwp file,
15716 restrict load_debug_section to the sections in that set. */
15717 section_subset
= find_cu_tu_set (filedata
, shndx
);
15719 result
&= display
->display (sec
, filedata
);
15721 section_subset
= NULL
;
15723 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
15724 free_debug_section (id
);
15732 printf (_("Unrecognized debug section: %s\n"), print_name
);
15739 /* Set DUMP_SECTS for all sections where dumps were requested
15740 based on section name. */
15743 initialise_dumps_byname (Filedata
* filedata
)
15745 struct dump_list_entry
* cur
;
15747 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
15752 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
15753 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
15754 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
15757 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
15761 if (!any
&& !filedata
->is_separate
)
15762 warn (_("Section '%s' was not dumped because it does not exist\n"),
15768 process_section_contents (Filedata
* filedata
)
15770 Elf_Internal_Shdr
* section
;
15777 initialise_dumps_byname (filedata
);
15779 for (i
= 0, section
= filedata
->section_headers
;
15780 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
15783 dump_type dump
= filedata
->dump
.dump_sects
[i
];
15785 if (filedata
->is_separate
&& ! process_links
)
15786 dump
&= DEBUG_DUMP
;
15788 #ifdef SUPPORT_DISASSEMBLY
15789 if (dump
& DISASS_DUMP
)
15791 if (! disassemble_section (section
, filedata
))
15795 if (dump
& HEX_DUMP
)
15797 if (! dump_section_as_bytes (section
, filedata
, false))
15801 if (dump
& RELOC_DUMP
)
15803 if (! dump_section_as_bytes (section
, filedata
, true))
15807 if (dump
& STRING_DUMP
)
15809 if (! dump_section_as_strings (section
, filedata
))
15813 if (dump
& DEBUG_DUMP
)
15815 if (! display_debug_section (i
, section
, filedata
))
15819 #ifdef ENABLE_LIBCTF
15820 if (dump
& CTF_DUMP
)
15822 if (! dump_section_as_ctf (section
, filedata
))
15828 if (! filedata
->is_separate
)
15830 /* Check to see if the user requested a
15831 dump of a section that does not exist. */
15832 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
15833 if (filedata
->dump
.dump_sects
[i
])
15835 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
15844 process_mips_fpe_exception (int mask
)
15850 if (mask
& OEX_FPU_INEX
)
15851 fputs ("INEX", stdout
), first
= false;
15852 if (mask
& OEX_FPU_UFLO
)
15853 printf ("%sUFLO", first
? "" : "|"), first
= false;
15854 if (mask
& OEX_FPU_OFLO
)
15855 printf ("%sOFLO", first
? "" : "|"), first
= false;
15856 if (mask
& OEX_FPU_DIV0
)
15857 printf ("%sDIV0", first
? "" : "|"), first
= false;
15858 if (mask
& OEX_FPU_INVAL
)
15859 printf ("%sINVAL", first
? "" : "|");
15862 fputs ("0", stdout
);
15865 /* Display's the value of TAG at location P. If TAG is
15866 greater than 0 it is assumed to be an unknown tag, and
15867 a message is printed to this effect. Otherwise it is
15868 assumed that a message has already been printed.
15870 If the bottom bit of TAG is set it assumed to have a
15871 string value, otherwise it is assumed to have an integer
15874 Returns an updated P pointing to the first unread byte
15875 beyond the end of TAG's value.
15877 Reads at or beyond END will not be made. */
15879 static unsigned char *
15880 display_tag_value (signed int tag
,
15882 const unsigned char * const end
)
15887 printf (" Tag_unknown_%d: ", tag
);
15891 warn (_("<corrupt tag>\n"));
15895 /* PR 17531 file: 027-19978-0.004. */
15896 size_t maxlen
= (end
- p
) - 1;
15901 print_symbol ((int) maxlen
, (const char *) p
);
15902 p
+= strnlen ((char *) p
, maxlen
) + 1;
15906 printf (_("<corrupt string tag>"));
15907 p
= (unsigned char *) end
;
15913 READ_ULEB (val
, p
, end
);
15914 printf ("%ld (0x%lx)\n", val
, val
);
15921 /* ARC ABI attributes section. */
15923 static unsigned char *
15924 display_arc_attribute (unsigned char * p
,
15925 const unsigned char * const end
)
15930 READ_ULEB (tag
, p
, end
);
15934 case Tag_ARC_PCS_config
:
15935 READ_ULEB (val
, p
, end
);
15936 printf (" Tag_ARC_PCS_config: ");
15940 printf (_("Absent/Non standard\n"));
15943 printf (_("Bare metal/mwdt\n"));
15946 printf (_("Bare metal/newlib\n"));
15949 printf (_("Linux/uclibc\n"));
15952 printf (_("Linux/glibc\n"));
15955 printf (_("Unknown\n"));
15960 case Tag_ARC_CPU_base
:
15961 READ_ULEB (val
, p
, end
);
15962 printf (" Tag_ARC_CPU_base: ");
15967 printf (_("Absent\n"));
15969 case TAG_CPU_ARC6xx
:
15970 printf ("ARC6xx\n");
15972 case TAG_CPU_ARC7xx
:
15973 printf ("ARC7xx\n");
15975 case TAG_CPU_ARCEM
:
15976 printf ("ARCEM\n");
15978 case TAG_CPU_ARCHS
:
15979 printf ("ARCHS\n");
15984 case Tag_ARC_CPU_variation
:
15985 READ_ULEB (val
, p
, end
);
15986 printf (" Tag_ARC_CPU_variation: ");
15990 if (val
> 0 && val
< 16)
15991 printf ("Core%d\n", val
);
15993 printf ("Unknown\n");
15997 printf (_("Absent\n"));
16002 case Tag_ARC_CPU_name
:
16003 printf (" Tag_ARC_CPU_name: ");
16004 p
= display_tag_value (-1, p
, end
);
16007 case Tag_ARC_ABI_rf16
:
16008 READ_ULEB (val
, p
, end
);
16009 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
16012 case Tag_ARC_ABI_osver
:
16013 READ_ULEB (val
, p
, end
);
16014 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
16017 case Tag_ARC_ABI_pic
:
16018 case Tag_ARC_ABI_sda
:
16019 READ_ULEB (val
, p
, end
);
16020 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
16021 : " Tag_ARC_ABI_pic: ");
16025 printf (_("Absent\n"));
16034 printf (_("Unknown\n"));
16039 case Tag_ARC_ABI_tls
:
16040 READ_ULEB (val
, p
, end
);
16041 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
16044 case Tag_ARC_ABI_enumsize
:
16045 READ_ULEB (val
, p
, end
);
16046 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
16050 case Tag_ARC_ABI_exceptions
:
16051 READ_ULEB (val
, p
, end
);
16052 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
16056 case Tag_ARC_ABI_double_size
:
16057 READ_ULEB (val
, p
, end
);
16058 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
16061 case Tag_ARC_ISA_config
:
16062 printf (" Tag_ARC_ISA_config: ");
16063 p
= display_tag_value (-1, p
, end
);
16066 case Tag_ARC_ISA_apex
:
16067 printf (" Tag_ARC_ISA_apex: ");
16068 p
= display_tag_value (-1, p
, end
);
16071 case Tag_ARC_ISA_mpy_option
:
16072 READ_ULEB (val
, p
, end
);
16073 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
16076 case Tag_ARC_ATR_version
:
16077 READ_ULEB (val
, p
, end
);
16078 printf (" Tag_ARC_ATR_version: %d\n", val
);
16082 return display_tag_value (tag
& 1, p
, end
);
16088 /* ARM EABI attributes section. */
16093 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
16095 const char *const *table
;
16096 } arm_attr_public_tag
;
16098 static const char *const arm_attr_tag_CPU_arch
[] =
16099 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
16100 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
16101 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
16102 "v8.1-M.mainline", "v9"};
16103 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
16104 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
16105 {"No", "Thumb-1", "Thumb-2", "Yes"};
16106 static const char *const arm_attr_tag_FP_arch
[] =
16107 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
16108 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
16109 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
16110 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
16111 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
16112 "NEON for ARMv8.1"};
16113 static const char *const arm_attr_tag_PCS_config
[] =
16114 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
16115 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
16116 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
16117 {"V6", "SB", "TLS", "Unused"};
16118 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
16119 {"Absolute", "PC-relative", "SB-relative", "None"};
16120 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
16121 {"Absolute", "PC-relative", "None"};
16122 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
16123 {"None", "direct", "GOT-indirect"};
16124 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
16125 {"None", "??? 1", "2", "??? 3", "4"};
16126 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
16127 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
16128 {"Unused", "Needed", "Sign only"};
16129 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
16130 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
16131 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
16132 {"Unused", "Finite", "RTABI", "IEEE 754"};
16133 static const char *const arm_attr_tag_ABI_enum_size
[] =
16134 {"Unused", "small", "int", "forced to int"};
16135 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
16136 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
16137 static const char *const arm_attr_tag_ABI_VFP_args
[] =
16138 {"AAPCS", "VFP registers", "custom", "compatible"};
16139 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
16140 {"AAPCS", "WMMX registers", "custom"};
16141 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
16142 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16143 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
16144 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
16145 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16146 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
16147 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
16148 static const char *const arm_attr_tag_FP_HP_extension
[] =
16149 {"Not Allowed", "Allowed"};
16150 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
16151 {"None", "IEEE 754", "Alternative Format"};
16152 static const char *const arm_attr_tag_DSP_extension
[] =
16153 {"Follow architecture", "Allowed"};
16154 static const char *const arm_attr_tag_MPextension_use
[] =
16155 {"Not Allowed", "Allowed"};
16156 static const char *const arm_attr_tag_DIV_use
[] =
16157 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
16158 "Allowed in v7-A with integer division extension"};
16159 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
16160 static const char *const arm_attr_tag_Virtualization_use
[] =
16161 {"Not Allowed", "TrustZone", "Virtualization Extensions",
16162 "TrustZone and Virtualization Extensions"};
16163 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
16164 {"Not Allowed", "Allowed"};
16166 static const char *const arm_attr_tag_MVE_arch
[] =
16167 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
16169 static const char * arm_attr_tag_PAC_extension
[] =
16170 {"No PAC/AUT instructions",
16171 "PAC/AUT instructions permitted in the NOP space",
16172 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
16174 static const char * arm_attr_tag_BTI_extension
[] =
16175 {"BTI instructions not permitted",
16176 "BTI instructions permitted in the NOP space",
16177 "BTI instructions permitted in the NOP and in the non-NOP space"};
16179 static const char * arm_attr_tag_BTI_use
[] =
16180 {"Compiled without branch target enforcement",
16181 "Compiled with branch target enforcement"};
16183 static const char * arm_attr_tag_PACRET_use
[] =
16184 {"Compiled without return address signing and authentication",
16185 "Compiled with return address signing and authentication"};
16187 #define LOOKUP(id, name) \
16188 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
16189 static arm_attr_public_tag arm_attr_public_tags
[] =
16191 {4, "CPU_raw_name", 1, NULL
},
16192 {5, "CPU_name", 1, NULL
},
16193 LOOKUP(6, CPU_arch
),
16194 {7, "CPU_arch_profile", 0, NULL
},
16195 LOOKUP(8, ARM_ISA_use
),
16196 LOOKUP(9, THUMB_ISA_use
),
16197 LOOKUP(10, FP_arch
),
16198 LOOKUP(11, WMMX_arch
),
16199 LOOKUP(12, Advanced_SIMD_arch
),
16200 LOOKUP(13, PCS_config
),
16201 LOOKUP(14, ABI_PCS_R9_use
),
16202 LOOKUP(15, ABI_PCS_RW_data
),
16203 LOOKUP(16, ABI_PCS_RO_data
),
16204 LOOKUP(17, ABI_PCS_GOT_use
),
16205 LOOKUP(18, ABI_PCS_wchar_t
),
16206 LOOKUP(19, ABI_FP_rounding
),
16207 LOOKUP(20, ABI_FP_denormal
),
16208 LOOKUP(21, ABI_FP_exceptions
),
16209 LOOKUP(22, ABI_FP_user_exceptions
),
16210 LOOKUP(23, ABI_FP_number_model
),
16211 {24, "ABI_align_needed", 0, NULL
},
16212 {25, "ABI_align_preserved", 0, NULL
},
16213 LOOKUP(26, ABI_enum_size
),
16214 LOOKUP(27, ABI_HardFP_use
),
16215 LOOKUP(28, ABI_VFP_args
),
16216 LOOKUP(29, ABI_WMMX_args
),
16217 LOOKUP(30, ABI_optimization_goals
),
16218 LOOKUP(31, ABI_FP_optimization_goals
),
16219 {32, "compatibility", 0, NULL
},
16220 LOOKUP(34, CPU_unaligned_access
),
16221 LOOKUP(36, FP_HP_extension
),
16222 LOOKUP(38, ABI_FP_16bit_format
),
16223 LOOKUP(42, MPextension_use
),
16224 LOOKUP(44, DIV_use
),
16225 LOOKUP(46, DSP_extension
),
16226 LOOKUP(48, MVE_arch
),
16227 LOOKUP(50, PAC_extension
),
16228 LOOKUP(52, BTI_extension
),
16229 LOOKUP(74, BTI_use
),
16230 LOOKUP(76, PACRET_use
),
16231 {64, "nodefaults", 0, NULL
},
16232 {65, "also_compatible_with", 0, NULL
},
16233 LOOKUP(66, T2EE_use
),
16234 {67, "conformance", 1, NULL
},
16235 LOOKUP(68, Virtualization_use
),
16236 LOOKUP(70, MPextension_use_legacy
)
16240 static unsigned char *
16241 display_arm_attribute (unsigned char * p
,
16242 const unsigned char * const end
)
16246 arm_attr_public_tag
* attr
;
16250 READ_ULEB (tag
, p
, end
);
16252 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
16254 if (arm_attr_public_tags
[i
].tag
== tag
)
16256 attr
= &arm_attr_public_tags
[i
];
16263 printf (" Tag_%s: ", attr
->name
);
16264 switch (attr
->type
)
16269 case 7: /* Tag_CPU_arch_profile. */
16270 READ_ULEB (val
, p
, end
);
16273 case 0: printf (_("None\n")); break;
16274 case 'A': printf (_("Application\n")); break;
16275 case 'R': printf (_("Realtime\n")); break;
16276 case 'M': printf (_("Microcontroller\n")); break;
16277 case 'S': printf (_("Application or Realtime\n")); break;
16278 default: printf ("??? (%d)\n", val
); break;
16282 case 24: /* Tag_align_needed. */
16283 READ_ULEB (val
, p
, end
);
16286 case 0: printf (_("None\n")); break;
16287 case 1: printf (_("8-byte\n")); break;
16288 case 2: printf (_("4-byte\n")); break;
16289 case 3: printf ("??? 3\n"); break;
16292 printf (_("8-byte and up to %d-byte extended\n"),
16295 printf ("??? (%d)\n", val
);
16300 case 25: /* Tag_align_preserved. */
16301 READ_ULEB (val
, p
, end
);
16304 case 0: printf (_("None\n")); break;
16305 case 1: printf (_("8-byte, except leaf SP\n")); break;
16306 case 2: printf (_("8-byte\n")); break;
16307 case 3: printf ("??? 3\n"); break;
16310 printf (_("8-byte and up to %d-byte extended\n"),
16313 printf ("??? (%d)\n", val
);
16318 case 32: /* Tag_compatibility. */
16320 READ_ULEB (val
, p
, end
);
16321 printf (_("flag = %d, vendor = "), val
);
16324 size_t maxlen
= (end
- p
) - 1;
16326 print_symbol ((int) maxlen
, (const char *) p
);
16327 p
+= strnlen ((char *) p
, maxlen
) + 1;
16331 printf (_("<corrupt>"));
16332 p
= (unsigned char *) end
;
16338 case 64: /* Tag_nodefaults. */
16339 /* PR 17531: file: 001-505008-0.01. */
16342 printf (_("True\n"));
16345 case 65: /* Tag_also_compatible_with. */
16346 READ_ULEB (val
, p
, end
);
16347 if (val
== 6 /* Tag_CPU_arch. */)
16349 READ_ULEB (val
, p
, end
);
16350 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
16351 printf ("??? (%d)\n", val
);
16353 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
16357 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
16362 printf (_("<unknown: %d>\n"), tag
);
16368 return display_tag_value (-1, p
, end
);
16370 return display_tag_value (0, p
, end
);
16373 assert (attr
->type
& 0x80);
16374 READ_ULEB (val
, p
, end
);
16375 type
= attr
->type
& 0x7f;
16377 printf ("??? (%d)\n", val
);
16379 printf ("%s\n", attr
->table
[val
]);
16384 return display_tag_value (tag
, p
, end
);
16387 static unsigned char *
16388 display_gnu_attribute (unsigned char * p
,
16389 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
16390 const unsigned char * const end
)
16395 READ_ULEB (tag
, p
, end
);
16397 /* Tag_compatibility is the only generic GNU attribute defined at
16401 READ_ULEB (val
, p
, end
);
16403 printf (_("flag = %d, vendor = "), val
);
16406 printf (_("<corrupt>\n"));
16407 warn (_("corrupt vendor attribute\n"));
16413 size_t maxlen
= (end
- p
) - 1;
16415 print_symbol ((int) maxlen
, (const char *) p
);
16416 p
+= strnlen ((char *) p
, maxlen
) + 1;
16420 printf (_("<corrupt>"));
16421 p
= (unsigned char *) end
;
16428 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
16429 return display_proc_gnu_attribute (p
, tag
, end
);
16431 return display_tag_value (tag
, p
, end
);
16434 static unsigned char *
16435 display_m68k_gnu_attribute (unsigned char * p
,
16437 const unsigned char * const end
)
16441 if (tag
== Tag_GNU_M68K_ABI_FP
)
16443 printf (" Tag_GNU_M68K_ABI_FP: ");
16446 printf (_("<corrupt>\n"));
16449 READ_ULEB (val
, p
, end
);
16452 printf ("(%#x), ", val
);
16457 printf (_("unspecified hard/soft float\n"));
16460 printf (_("hard float\n"));
16463 printf (_("soft float\n"));
16469 return display_tag_value (tag
& 1, p
, end
);
16472 static unsigned char *
16473 display_power_gnu_attribute (unsigned char * p
,
16475 const unsigned char * const end
)
16479 if (tag
== Tag_GNU_Power_ABI_FP
)
16481 printf (" Tag_GNU_Power_ABI_FP: ");
16484 printf (_("<corrupt>\n"));
16487 READ_ULEB (val
, p
, end
);
16490 printf ("(%#x), ", val
);
16495 printf (_("unspecified hard/soft float, "));
16498 printf (_("hard float, "));
16501 printf (_("soft float, "));
16504 printf (_("single-precision hard float, "));
16511 printf (_("unspecified long double\n"));
16514 printf (_("128-bit IBM long double\n"));
16517 printf (_("64-bit long double\n"));
16520 printf (_("128-bit IEEE long double\n"));
16526 if (tag
== Tag_GNU_Power_ABI_Vector
)
16528 printf (" Tag_GNU_Power_ABI_Vector: ");
16531 printf (_("<corrupt>\n"));
16534 READ_ULEB (val
, p
, end
);
16537 printf ("(%#x), ", val
);
16542 printf (_("unspecified\n"));
16545 printf (_("generic\n"));
16548 printf ("AltiVec\n");
16557 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
16559 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
16562 printf (_("<corrupt>\n"));
16565 READ_ULEB (val
, p
, end
);
16568 printf ("(%#x), ", val
);
16573 printf (_("unspecified\n"));
16576 printf ("r3/r4\n");
16579 printf (_("memory\n"));
16588 return display_tag_value (tag
& 1, p
, end
);
16591 static unsigned char *
16592 display_s390_gnu_attribute (unsigned char * p
,
16594 const unsigned char * const end
)
16598 if (tag
== Tag_GNU_S390_ABI_Vector
)
16600 printf (" Tag_GNU_S390_ABI_Vector: ");
16601 READ_ULEB (val
, p
, end
);
16606 printf (_("any\n"));
16609 printf (_("software\n"));
16612 printf (_("hardware\n"));
16615 printf ("??? (%d)\n", val
);
16621 return display_tag_value (tag
& 1, p
, end
);
16625 display_sparc_hwcaps (unsigned int mask
)
16631 if (mask
& ELF_SPARC_HWCAP_MUL32
)
16632 fputs ("mul32", stdout
), first
= false;
16633 if (mask
& ELF_SPARC_HWCAP_DIV32
)
16634 printf ("%sdiv32", first
? "" : "|"), first
= false;
16635 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
16636 printf ("%sfsmuld", first
? "" : "|"), first
= false;
16637 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
16638 printf ("%sv8plus", first
? "" : "|"), first
= false;
16639 if (mask
& ELF_SPARC_HWCAP_POPC
)
16640 printf ("%spopc", first
? "" : "|"), first
= false;
16641 if (mask
& ELF_SPARC_HWCAP_VIS
)
16642 printf ("%svis", first
? "" : "|"), first
= false;
16643 if (mask
& ELF_SPARC_HWCAP_VIS2
)
16644 printf ("%svis2", first
? "" : "|"), first
= false;
16645 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
16646 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
16647 if (mask
& ELF_SPARC_HWCAP_FMAF
)
16648 printf ("%sfmaf", first
? "" : "|"), first
= false;
16649 if (mask
& ELF_SPARC_HWCAP_VIS3
)
16650 printf ("%svis3", first
? "" : "|"), first
= false;
16651 if (mask
& ELF_SPARC_HWCAP_HPC
)
16652 printf ("%shpc", first
? "" : "|"), first
= false;
16653 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
16654 printf ("%srandom", first
? "" : "|"), first
= false;
16655 if (mask
& ELF_SPARC_HWCAP_TRANS
)
16656 printf ("%strans", first
? "" : "|"), first
= false;
16657 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
16658 printf ("%sfjfmau", first
? "" : "|"), first
= false;
16659 if (mask
& ELF_SPARC_HWCAP_IMA
)
16660 printf ("%sima", first
? "" : "|"), first
= false;
16661 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
16662 printf ("%scspare", first
? "" : "|"), first
= false;
16665 fputc ('0', stdout
);
16666 fputc ('\n', stdout
);
16670 display_sparc_hwcaps2 (unsigned int mask
)
16676 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
16677 fputs ("fjathplus", stdout
), first
= false;
16678 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
16679 printf ("%svis3b", first
? "" : "|"), first
= false;
16680 if (mask
& ELF_SPARC_HWCAP2_ADP
)
16681 printf ("%sadp", first
? "" : "|"), first
= false;
16682 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
16683 printf ("%ssparc5", first
? "" : "|"), first
= false;
16684 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
16685 printf ("%smwait", first
? "" : "|"), first
= false;
16686 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
16687 printf ("%sxmpmul", first
? "" : "|"), first
= false;
16688 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
16689 printf ("%sxmont2", first
? "" : "|"), first
= false;
16690 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
16691 printf ("%snsec", first
? "" : "|"), first
= false;
16692 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
16693 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
16694 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
16695 printf ("%sfjdes", first
? "" : "|"), first
= false;
16696 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
16697 printf ("%sfjaes", first
? "" : "|"), first
= false;
16700 fputc ('0', stdout
);
16701 fputc ('\n', stdout
);
16704 static unsigned char *
16705 display_sparc_gnu_attribute (unsigned char * p
,
16707 const unsigned char * const end
)
16711 if (tag
== Tag_GNU_Sparc_HWCAPS
)
16713 READ_ULEB (val
, p
, end
);
16714 printf (" Tag_GNU_Sparc_HWCAPS: ");
16715 display_sparc_hwcaps (val
);
16718 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
16720 READ_ULEB (val
, p
, end
);
16721 printf (" Tag_GNU_Sparc_HWCAPS2: ");
16722 display_sparc_hwcaps2 (val
);
16726 return display_tag_value (tag
, p
, end
);
16730 print_mips_fp_abi_value (unsigned int val
)
16734 case Val_GNU_MIPS_ABI_FP_ANY
:
16735 printf (_("Hard or soft float\n"));
16737 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
16738 printf (_("Hard float (double precision)\n"));
16740 case Val_GNU_MIPS_ABI_FP_SINGLE
:
16741 printf (_("Hard float (single precision)\n"));
16743 case Val_GNU_MIPS_ABI_FP_SOFT
:
16744 printf (_("Soft float\n"));
16746 case Val_GNU_MIPS_ABI_FP_OLD_64
:
16747 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
16749 case Val_GNU_MIPS_ABI_FP_XX
:
16750 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
16752 case Val_GNU_MIPS_ABI_FP_64
:
16753 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
16755 case Val_GNU_MIPS_ABI_FP_64A
:
16756 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
16758 case Val_GNU_MIPS_ABI_FP_NAN2008
:
16759 printf (_("NaN 2008 compatibility\n"));
16762 printf ("??? (%d)\n", val
);
16767 static unsigned char *
16768 display_mips_gnu_attribute (unsigned char * p
,
16770 const unsigned char * const end
)
16772 if (tag
== Tag_GNU_MIPS_ABI_FP
)
16776 printf (" Tag_GNU_MIPS_ABI_FP: ");
16777 READ_ULEB (val
, p
, end
);
16778 print_mips_fp_abi_value (val
);
16782 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
16786 printf (" Tag_GNU_MIPS_ABI_MSA: ");
16787 READ_ULEB (val
, p
, end
);
16791 case Val_GNU_MIPS_ABI_MSA_ANY
:
16792 printf (_("Any MSA or not\n"));
16794 case Val_GNU_MIPS_ABI_MSA_128
:
16795 printf (_("128-bit MSA\n"));
16798 printf ("??? (%d)\n", val
);
16804 return display_tag_value (tag
& 1, p
, end
);
16807 static unsigned char *
16808 display_tic6x_attribute (unsigned char * p
,
16809 const unsigned char * const end
)
16814 READ_ULEB (tag
, p
, end
);
16819 printf (" Tag_ISA: ");
16820 READ_ULEB (val
, p
, end
);
16824 case C6XABI_Tag_ISA_none
:
16825 printf (_("None\n"));
16827 case C6XABI_Tag_ISA_C62X
:
16830 case C6XABI_Tag_ISA_C67X
:
16833 case C6XABI_Tag_ISA_C67XP
:
16834 printf ("C67x+\n");
16836 case C6XABI_Tag_ISA_C64X
:
16839 case C6XABI_Tag_ISA_C64XP
:
16840 printf ("C64x+\n");
16842 case C6XABI_Tag_ISA_C674X
:
16843 printf ("C674x\n");
16846 printf ("??? (%d)\n", val
);
16851 case Tag_ABI_wchar_t
:
16852 printf (" Tag_ABI_wchar_t: ");
16853 READ_ULEB (val
, p
, end
);
16857 printf (_("Not used\n"));
16860 printf (_("2 bytes\n"));
16863 printf (_("4 bytes\n"));
16866 printf ("??? (%d)\n", val
);
16871 case Tag_ABI_stack_align_needed
:
16872 printf (" Tag_ABI_stack_align_needed: ");
16873 READ_ULEB (val
, p
, end
);
16877 printf (_("8-byte\n"));
16880 printf (_("16-byte\n"));
16883 printf ("??? (%d)\n", val
);
16888 case Tag_ABI_stack_align_preserved
:
16889 READ_ULEB (val
, p
, end
);
16890 printf (" Tag_ABI_stack_align_preserved: ");
16894 printf (_("8-byte\n"));
16897 printf (_("16-byte\n"));
16900 printf ("??? (%d)\n", val
);
16906 READ_ULEB (val
, p
, end
);
16907 printf (" Tag_ABI_DSBT: ");
16911 printf (_("DSBT addressing not used\n"));
16914 printf (_("DSBT addressing used\n"));
16917 printf ("??? (%d)\n", val
);
16923 READ_ULEB (val
, p
, end
);
16924 printf (" Tag_ABI_PID: ");
16928 printf (_("Data addressing position-dependent\n"));
16931 printf (_("Data addressing position-independent, GOT near DP\n"));
16934 printf (_("Data addressing position-independent, GOT far from DP\n"));
16937 printf ("??? (%d)\n", val
);
16943 READ_ULEB (val
, p
, end
);
16944 printf (" Tag_ABI_PIC: ");
16948 printf (_("Code addressing position-dependent\n"));
16951 printf (_("Code addressing position-independent\n"));
16954 printf ("??? (%d)\n", val
);
16959 case Tag_ABI_array_object_alignment
:
16960 READ_ULEB (val
, p
, end
);
16961 printf (" Tag_ABI_array_object_alignment: ");
16965 printf (_("8-byte\n"));
16968 printf (_("4-byte\n"));
16971 printf (_("16-byte\n"));
16974 printf ("??? (%d)\n", val
);
16979 case Tag_ABI_array_object_align_expected
:
16980 READ_ULEB (val
, p
, end
);
16981 printf (" Tag_ABI_array_object_align_expected: ");
16985 printf (_("8-byte\n"));
16988 printf (_("4-byte\n"));
16991 printf (_("16-byte\n"));
16994 printf ("??? (%d)\n", val
);
16999 case Tag_ABI_compatibility
:
17001 READ_ULEB (val
, p
, end
);
17002 printf (" Tag_ABI_compatibility: ");
17003 printf (_("flag = %d, vendor = "), val
);
17006 size_t maxlen
= (end
- p
) - 1;
17008 print_symbol ((int) maxlen
, (const char *) p
);
17009 p
+= strnlen ((char *) p
, maxlen
) + 1;
17013 printf (_("<corrupt>"));
17014 p
= (unsigned char *) end
;
17020 case Tag_ABI_conformance
:
17022 printf (" Tag_ABI_conformance: \"");
17025 size_t maxlen
= (end
- p
) - 1;
17027 print_symbol ((int) maxlen
, (const char *) p
);
17028 p
+= strnlen ((char *) p
, maxlen
) + 1;
17032 printf (_("<corrupt>"));
17033 p
= (unsigned char *) end
;
17040 return display_tag_value (tag
, p
, end
);
17044 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
17046 unsigned long addr
= 0;
17047 size_t bytes
= end
- p
;
17054 int lbytes
= (bytes
> 16 ? 16 : bytes
);
17056 printf (" 0x%8.8lx ", addr
);
17058 for (j
= 0; j
< 16; j
++)
17061 printf ("%2.2x", p
[j
]);
17069 for (j
= 0; j
< lbytes
; j
++)
17072 if (k
>= ' ' && k
< 0x7f)
17088 static unsigned char *
17089 display_msp430_attribute (unsigned char * p
,
17090 const unsigned char * const end
)
17095 READ_ULEB (tag
, p
, end
);
17099 case OFBA_MSPABI_Tag_ISA
:
17100 printf (" Tag_ISA: ");
17101 READ_ULEB (val
, p
, end
);
17104 case 0: printf (_("None\n")); break;
17105 case 1: printf (_("MSP430\n")); break;
17106 case 2: printf (_("MSP430X\n")); break;
17107 default: printf ("??? (%d)\n", val
); break;
17111 case OFBA_MSPABI_Tag_Code_Model
:
17112 printf (" Tag_Code_Model: ");
17113 READ_ULEB (val
, p
, end
);
17116 case 0: printf (_("None\n")); break;
17117 case 1: printf (_("Small\n")); break;
17118 case 2: printf (_("Large\n")); break;
17119 default: printf ("??? (%d)\n", val
); break;
17123 case OFBA_MSPABI_Tag_Data_Model
:
17124 printf (" Tag_Data_Model: ");
17125 READ_ULEB (val
, p
, end
);
17128 case 0: printf (_("None\n")); break;
17129 case 1: printf (_("Small\n")); break;
17130 case 2: printf (_("Large\n")); break;
17131 case 3: printf (_("Restricted Large\n")); break;
17132 default: printf ("??? (%d)\n", val
); break;
17137 printf (_(" <unknown tag %d>: "), tag
);
17144 size_t maxlen
= (end
- p
) - 1;
17146 print_symbol ((int) maxlen
, (const char *) p
);
17147 p
+= strnlen ((char *) p
, maxlen
) + 1;
17151 printf (_("<corrupt>"));
17152 p
= (unsigned char *) end
;
17158 READ_ULEB (val
, p
, end
);
17159 printf ("%d (0x%x)\n", val
, val
);
17168 static unsigned char *
17169 display_msp430_gnu_attribute (unsigned char * p
,
17171 const unsigned char * const end
)
17173 if (tag
== Tag_GNU_MSP430_Data_Region
)
17177 printf (" Tag_GNU_MSP430_Data_Region: ");
17178 READ_ULEB (val
, p
, end
);
17182 case Val_GNU_MSP430_Data_Region_Any
:
17183 printf (_("Any Region\n"));
17185 case Val_GNU_MSP430_Data_Region_Lower
:
17186 printf (_("Lower Region Only\n"));
17189 printf ("??? (%u)\n", val
);
17193 return display_tag_value (tag
& 1, p
, end
);
17196 struct riscv_attr_tag_t
{
17201 static struct riscv_attr_tag_t riscv_attr_tag
[] =
17203 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
17206 T(priv_spec_minor
),
17207 T(priv_spec_revision
),
17208 T(unaligned_access
),
17213 static unsigned char *
17214 display_riscv_attribute (unsigned char *p
,
17215 const unsigned char * const end
)
17219 struct riscv_attr_tag_t
*attr
= NULL
;
17222 READ_ULEB (tag
, p
, end
);
17224 /* Find the name of attribute. */
17225 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
17227 if (riscv_attr_tag
[i
].tag
== tag
)
17229 attr
= &riscv_attr_tag
[i
];
17235 printf (" %s: ", attr
->name
);
17237 return display_tag_value (tag
, p
, end
);
17241 case Tag_RISCV_priv_spec
:
17242 case Tag_RISCV_priv_spec_minor
:
17243 case Tag_RISCV_priv_spec_revision
:
17244 READ_ULEB (val
, p
, end
);
17245 printf (_("%u\n"), val
);
17247 case Tag_RISCV_unaligned_access
:
17248 READ_ULEB (val
, p
, end
);
17252 printf (_("No unaligned access\n"));
17255 printf (_("Unaligned access\n"));
17259 case Tag_RISCV_stack_align
:
17260 READ_ULEB (val
, p
, end
);
17261 printf (_("%u-bytes\n"), val
);
17263 case Tag_RISCV_arch
:
17264 p
= display_tag_value (-1, p
, end
);
17267 return display_tag_value (tag
, p
, end
);
17273 static unsigned char *
17274 display_csky_attribute (unsigned char * p
,
17275 const unsigned char * const end
)
17279 READ_ULEB (tag
, p
, end
);
17281 if (tag
>= Tag_CSKY_MAX
)
17283 return display_tag_value (-1, p
, end
);
17288 case Tag_CSKY_ARCH_NAME
:
17289 printf (" Tag_CSKY_ARCH_NAME:\t\t");
17290 return display_tag_value (-1, p
, end
);
17291 case Tag_CSKY_CPU_NAME
:
17292 printf (" Tag_CSKY_CPU_NAME:\t\t");
17293 return display_tag_value (-1, p
, end
);
17295 case Tag_CSKY_ISA_FLAGS
:
17296 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
17297 return display_tag_value (0, p
, end
);
17298 case Tag_CSKY_ISA_EXT_FLAGS
:
17299 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
17300 return display_tag_value (0, p
, end
);
17302 case Tag_CSKY_DSP_VERSION
:
17303 printf (" Tag_CSKY_DSP_VERSION:\t\t");
17304 READ_ULEB (val
, p
, end
);
17305 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
17306 printf ("DSP Extension\n");
17307 else if (val
== VAL_CSKY_DSP_VERSION_2
)
17308 printf ("DSP 2.0\n");
17311 case Tag_CSKY_VDSP_VERSION
:
17312 printf (" Tag_CSKY_VDSP_VERSION:\t");
17313 READ_ULEB (val
, p
, end
);
17314 printf ("VDSP Version %d\n", val
);
17317 case Tag_CSKY_FPU_VERSION
:
17318 printf (" Tag_CSKY_FPU_VERSION:\t\t");
17319 READ_ULEB (val
, p
, end
);
17320 if (val
== VAL_CSKY_FPU_VERSION_1
)
17321 printf ("ABIV1 FPU Version 1\n");
17322 else if (val
== VAL_CSKY_FPU_VERSION_2
)
17323 printf ("FPU Version 2\n");
17326 case Tag_CSKY_FPU_ABI
:
17327 printf (" Tag_CSKY_FPU_ABI:\t\t");
17328 READ_ULEB (val
, p
, end
);
17329 if (val
== VAL_CSKY_FPU_ABI_HARD
)
17331 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
17332 printf ("SoftFP\n");
17333 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
17336 case Tag_CSKY_FPU_ROUNDING
:
17337 READ_ULEB (val
, p
, end
);
17340 printf (" Tag_CSKY_FPU_ROUNDING:\t");
17341 printf ("Needed\n");
17344 case Tag_CSKY_FPU_DENORMAL
:
17345 READ_ULEB (val
, p
, end
);
17348 printf (" Tag_CSKY_FPU_DENORMAL:\t");
17349 printf ("Needed\n");
17352 case Tag_CSKY_FPU_Exception
:
17353 READ_ULEB (val
, p
, end
);
17356 printf (" Tag_CSKY_FPU_Exception:\t");
17357 printf ("Needed\n");
17360 case Tag_CSKY_FPU_NUMBER_MODULE
:
17361 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
17362 return display_tag_value (-1, p
, end
);
17363 case Tag_CSKY_FPU_HARDFP
:
17364 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
17365 READ_ULEB (val
, p
, end
);
17366 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
17368 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
17369 printf (" Single");
17370 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
17371 printf (" Double");
17375 return display_tag_value (tag
, p
, end
);
17381 process_attributes (Filedata
* filedata
,
17382 const char * public_name
,
17383 unsigned int proc_type
,
17384 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
17385 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
17387 Elf_Internal_Shdr
* sect
;
17391 /* Find the section header so that we get the size. */
17392 for (i
= 0, sect
= filedata
->section_headers
;
17393 i
< filedata
->file_header
.e_shnum
;
17396 unsigned char * contents
;
17399 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
17402 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17403 sect
->sh_size
, _("attributes"));
17404 if (contents
== NULL
)
17411 /* The first character is the version of the attributes.
17412 Currently only version 1, (aka 'A') is recognised here. */
17415 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
17420 bfd_vma section_len
;
17422 section_len
= sect
->sh_size
- 1;
17425 while (section_len
> 0)
17428 unsigned int namelen
;
17429 bool public_section
;
17432 if (section_len
<= 4)
17434 error (_("Tag section ends prematurely\n"));
17438 attr_len
= byte_get (p
, 4);
17441 if (attr_len
> section_len
)
17443 error (_("Bad attribute length (%u > %u)\n"),
17444 (unsigned) attr_len
, (unsigned) section_len
);
17445 attr_len
= section_len
;
17448 /* PR 17531: file: 001-101425-0.004 */
17449 else if (attr_len
< 5)
17451 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
17456 section_len
-= attr_len
;
17459 namelen
= strnlen ((char *) p
, attr_len
) + 1;
17460 if (namelen
== 0 || namelen
>= attr_len
)
17462 error (_("Corrupt attribute section name\n"));
17467 printf (_("Attribute Section: "));
17468 print_symbol (INT_MAX
, (const char *) p
);
17471 if (public_name
&& streq ((char *) p
, public_name
))
17472 public_section
= true;
17474 public_section
= false;
17476 if (streq ((char *) p
, "gnu"))
17477 gnu_section
= true;
17479 gnu_section
= false;
17482 attr_len
-= namelen
;
17484 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
17489 unsigned char * end
;
17491 /* PR binutils/17531: Safe handling of corrupt files. */
17494 error (_("Unused bytes at end of section\n"));
17501 size
= byte_get (p
, 4);
17502 if (size
> attr_len
)
17504 error (_("Bad subsection length (%u > %u)\n"),
17505 (unsigned) size
, (unsigned) attr_len
);
17509 /* PR binutils/17531: Safe handling of corrupt files. */
17512 error (_("Bad subsection length (%u < 6)\n"),
17520 end
= p
+ size
- 1;
17521 assert (end
<= contents
+ sect
->sh_size
);
17527 printf (_("File Attributes\n"));
17530 printf (_("Section Attributes:"));
17533 printf (_("Symbol Attributes:"));
17534 /* Fall through. */
17538 READ_ULEB (val
, p
, end
);
17541 printf (" %d", val
);
17546 printf (_("Unknown tag: %d\n"), tag
);
17547 public_section
= false;
17551 if (public_section
&& display_pub_attribute
!= NULL
)
17554 p
= display_pub_attribute (p
, end
);
17557 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
17560 p
= display_gnu_attribute (p
,
17561 display_proc_gnu_attribute
,
17567 printf (_(" Unknown attribute:\n"));
17568 display_raw_attribute (p
, end
);
17583 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
17584 Print the Address, Access and Initial fields of an entry at VMA ADDR
17585 and return the VMA of the next entry, or -1 if there was a problem.
17586 Does not read from DATA_END or beyond. */
17589 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
,
17590 unsigned char * data_end
)
17593 print_vma (addr
, LONG_HEX
);
17595 if (addr
< pltgot
+ 0xfff0)
17596 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
17598 printf ("%10s", "");
17601 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
17605 unsigned char * from
= data
+ addr
- pltgot
;
17607 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
17609 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
17610 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
17611 return (bfd_vma
) -1;
17615 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
17616 print_vma (entry
, LONG_HEX
);
17619 return addr
+ (is_32bit_elf
? 4 : 8);
17622 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
17623 PLTGOT. Print the Address and Initial fields of an entry at VMA
17624 ADDR and return the VMA of the next entry. */
17627 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
17630 print_vma (addr
, LONG_HEX
);
17633 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
17638 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
17639 print_vma (entry
, LONG_HEX
);
17641 return addr
+ (is_32bit_elf
? 4 : 8);
17645 print_mips_ases (unsigned int mask
)
17647 if (mask
& AFL_ASE_DSP
)
17648 fputs ("\n\tDSP ASE", stdout
);
17649 if (mask
& AFL_ASE_DSPR2
)
17650 fputs ("\n\tDSP R2 ASE", stdout
);
17651 if (mask
& AFL_ASE_DSPR3
)
17652 fputs ("\n\tDSP R3 ASE", stdout
);
17653 if (mask
& AFL_ASE_EVA
)
17654 fputs ("\n\tEnhanced VA Scheme", stdout
);
17655 if (mask
& AFL_ASE_MCU
)
17656 fputs ("\n\tMCU (MicroController) ASE", stdout
);
17657 if (mask
& AFL_ASE_MDMX
)
17658 fputs ("\n\tMDMX ASE", stdout
);
17659 if (mask
& AFL_ASE_MIPS3D
)
17660 fputs ("\n\tMIPS-3D ASE", stdout
);
17661 if (mask
& AFL_ASE_MT
)
17662 fputs ("\n\tMT ASE", stdout
);
17663 if (mask
& AFL_ASE_SMARTMIPS
)
17664 fputs ("\n\tSmartMIPS ASE", stdout
);
17665 if (mask
& AFL_ASE_VIRT
)
17666 fputs ("\n\tVZ ASE", stdout
);
17667 if (mask
& AFL_ASE_MSA
)
17668 fputs ("\n\tMSA ASE", stdout
);
17669 if (mask
& AFL_ASE_MIPS16
)
17670 fputs ("\n\tMIPS16 ASE", stdout
);
17671 if (mask
& AFL_ASE_MICROMIPS
)
17672 fputs ("\n\tMICROMIPS ASE", stdout
);
17673 if (mask
& AFL_ASE_XPA
)
17674 fputs ("\n\tXPA ASE", stdout
);
17675 if (mask
& AFL_ASE_MIPS16E2
)
17676 fputs ("\n\tMIPS16e2 ASE", stdout
);
17677 if (mask
& AFL_ASE_CRC
)
17678 fputs ("\n\tCRC ASE", stdout
);
17679 if (mask
& AFL_ASE_GINV
)
17680 fputs ("\n\tGINV ASE", stdout
);
17681 if (mask
& AFL_ASE_LOONGSON_MMI
)
17682 fputs ("\n\tLoongson MMI ASE", stdout
);
17683 if (mask
& AFL_ASE_LOONGSON_CAM
)
17684 fputs ("\n\tLoongson CAM ASE", stdout
);
17685 if (mask
& AFL_ASE_LOONGSON_EXT
)
17686 fputs ("\n\tLoongson EXT ASE", stdout
);
17687 if (mask
& AFL_ASE_LOONGSON_EXT2
)
17688 fputs ("\n\tLoongson EXT2 ASE", stdout
);
17690 fprintf (stdout
, "\n\t%s", _("None"));
17691 else if ((mask
& ~AFL_ASE_MASK
) != 0)
17692 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
17696 print_mips_isa_ext (unsigned int isa_ext
)
17701 fputs (_("None"), stdout
);
17704 fputs ("RMI XLR", stdout
);
17706 case AFL_EXT_OCTEON3
:
17707 fputs ("Cavium Networks Octeon3", stdout
);
17709 case AFL_EXT_OCTEON2
:
17710 fputs ("Cavium Networks Octeon2", stdout
);
17712 case AFL_EXT_OCTEONP
:
17713 fputs ("Cavium Networks OcteonP", stdout
);
17715 case AFL_EXT_OCTEON
:
17716 fputs ("Cavium Networks Octeon", stdout
);
17719 fputs ("Toshiba R5900", stdout
);
17722 fputs ("MIPS R4650", stdout
);
17725 fputs ("LSI R4010", stdout
);
17728 fputs ("NEC VR4100", stdout
);
17731 fputs ("Toshiba R3900", stdout
);
17733 case AFL_EXT_10000
:
17734 fputs ("MIPS R10000", stdout
);
17737 fputs ("Broadcom SB-1", stdout
);
17740 fputs ("NEC VR4111/VR4181", stdout
);
17743 fputs ("NEC VR4120", stdout
);
17746 fputs ("NEC VR5400", stdout
);
17749 fputs ("NEC VR5500", stdout
);
17751 case AFL_EXT_LOONGSON_2E
:
17752 fputs ("ST Microelectronics Loongson 2E", stdout
);
17754 case AFL_EXT_LOONGSON_2F
:
17755 fputs ("ST Microelectronics Loongson 2F", stdout
);
17757 case AFL_EXT_INTERAPTIV_MR2
:
17758 fputs ("Imagination interAptiv MR2", stdout
);
17761 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
17766 get_mips_reg_size (int reg_size
)
17768 return (reg_size
== AFL_REG_NONE
) ? 0
17769 : (reg_size
== AFL_REG_32
) ? 32
17770 : (reg_size
== AFL_REG_64
) ? 64
17771 : (reg_size
== AFL_REG_128
) ? 128
17776 process_mips_specific (Filedata
* filedata
)
17778 Elf_Internal_Dyn
* entry
;
17779 Elf_Internal_Shdr
*sect
= NULL
;
17780 size_t liblist_offset
= 0;
17781 size_t liblistno
= 0;
17782 size_t conflictsno
= 0;
17783 size_t options_offset
= 0;
17784 size_t conflicts_offset
= 0;
17785 size_t pltrelsz
= 0;
17787 bfd_vma pltgot
= 0;
17788 bfd_vma mips_pltgot
= 0;
17789 bfd_vma jmprel
= 0;
17790 bfd_vma local_gotno
= 0;
17791 bfd_vma gotsym
= 0;
17792 bfd_vma symtabno
= 0;
17795 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
17796 display_mips_gnu_attribute
))
17799 sect
= find_section (filedata
, ".MIPS.abiflags");
17803 Elf_External_ABIFlags_v0
*abiflags_ext
;
17804 Elf_Internal_ABIFlags_v0 abiflags_in
;
17806 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
17808 error (_("Corrupt MIPS ABI Flags section.\n"));
17813 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17814 sect
->sh_size
, _("MIPS ABI Flags section"));
17817 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
17818 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
17819 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
17820 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
17821 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
17822 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
17823 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
17824 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
17825 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
17826 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
17827 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
17829 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
17830 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
17831 if (abiflags_in
.isa_rev
> 1)
17832 printf ("r%d", abiflags_in
.isa_rev
);
17833 printf ("\nGPR size: %d",
17834 get_mips_reg_size (abiflags_in
.gpr_size
));
17835 printf ("\nCPR1 size: %d",
17836 get_mips_reg_size (abiflags_in
.cpr1_size
));
17837 printf ("\nCPR2 size: %d",
17838 get_mips_reg_size (abiflags_in
.cpr2_size
));
17839 fputs ("\nFP ABI: ", stdout
);
17840 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
17841 fputs ("ISA Extension: ", stdout
);
17842 print_mips_isa_ext (abiflags_in
.isa_ext
);
17843 fputs ("\nASEs:", stdout
);
17844 print_mips_ases (abiflags_in
.ases
);
17845 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
17846 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
17847 fputc ('\n', stdout
);
17848 free (abiflags_ext
);
17853 /* We have a lot of special sections. Thanks SGI! */
17854 if (filedata
->dynamic_section
== NULL
)
17856 /* No dynamic information available. See if there is static GOT. */
17857 sect
= find_section (filedata
, ".got");
17860 unsigned char *data_end
;
17861 unsigned char *data
;
17865 pltgot
= sect
->sh_addr
;
17868 addr_size
= (is_32bit_elf
? 4 : 8);
17869 end
= pltgot
+ sect
->sh_size
;
17871 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
17873 _("Global Offset Table data"));
17874 /* PR 12855: Null data is handled gracefully throughout. */
17875 data_end
= data
+ (end
- pltgot
);
17877 printf (_("\nStatic GOT:\n"));
17878 printf (_(" Canonical gp value: "));
17879 print_vma (ent
+ 0x7ff0, LONG_HEX
);
17882 /* In a dynamic binary GOT[0] is reserved for the dynamic
17883 loader to store the lazy resolver pointer, however in
17884 a static binary it may well have been omitted and GOT
17885 reduced to a table of addresses.
17886 PR 21344: Check for the entry being fully available
17887 before fetching it. */
17889 && data
+ ent
- pltgot
+ addr_size
<= data_end
17890 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
17892 printf (_(" Reserved entries:\n"));
17893 printf (_(" %*s %10s %*s\n"),
17894 addr_size
* 2, _("Address"), _("Access"),
17895 addr_size
* 2, _("Value"));
17896 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17898 if (ent
== (bfd_vma
) -1)
17899 goto sgot_print_fail
;
17901 /* Check for the MSB of GOT[1] being set, identifying a
17902 GNU object. This entry will be used by some runtime
17903 loaders, to store the module pointer. Otherwise this
17904 is an ordinary local entry.
17905 PR 21344: Check for the entry being fully available
17906 before fetching it. */
17908 && data
+ ent
- pltgot
+ addr_size
<= data_end
17909 && (byte_get (data
+ ent
- pltgot
, addr_size
)
17910 >> (addr_size
* 8 - 1)) != 0)
17912 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17914 if (ent
== (bfd_vma
) -1)
17915 goto sgot_print_fail
;
17920 if (data
!= NULL
&& ent
< end
)
17922 printf (_(" Local entries:\n"));
17923 printf (" %*s %10s %*s\n",
17924 addr_size
* 2, _("Address"), _("Access"),
17925 addr_size
* 2, _("Value"));
17928 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17930 if (ent
== (bfd_vma
) -1)
17931 goto sgot_print_fail
;
17942 for (entry
= filedata
->dynamic_section
;
17943 /* PR 17531 file: 012-50589-0.004. */
17944 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
17945 && entry
->d_tag
!= DT_NULL
);
17947 switch (entry
->d_tag
)
17949 case DT_MIPS_LIBLIST
:
17951 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17952 liblistno
* sizeof (Elf32_External_Lib
));
17954 case DT_MIPS_LIBLISTNO
:
17955 liblistno
= entry
->d_un
.d_val
;
17957 case DT_MIPS_OPTIONS
:
17958 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
17960 case DT_MIPS_CONFLICT
:
17962 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17963 conflictsno
* sizeof (Elf32_External_Conflict
));
17965 case DT_MIPS_CONFLICTNO
:
17966 conflictsno
= entry
->d_un
.d_val
;
17969 pltgot
= entry
->d_un
.d_ptr
;
17971 case DT_MIPS_LOCAL_GOTNO
:
17972 local_gotno
= entry
->d_un
.d_val
;
17974 case DT_MIPS_GOTSYM
:
17975 gotsym
= entry
->d_un
.d_val
;
17977 case DT_MIPS_SYMTABNO
:
17978 symtabno
= entry
->d_un
.d_val
;
17980 case DT_MIPS_PLTGOT
:
17981 mips_pltgot
= entry
->d_un
.d_ptr
;
17984 pltrel
= entry
->d_un
.d_val
;
17987 pltrelsz
= entry
->d_un
.d_val
;
17990 jmprel
= entry
->d_un
.d_ptr
;
17996 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
17998 Elf32_External_Lib
* elib
;
18001 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
18002 sizeof (Elf32_External_Lib
),
18004 _("liblist section data"));
18007 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
18008 "\nSection '.liblist' contains %lu entries:\n",
18009 (unsigned long) liblistno
),
18010 (unsigned long) liblistno
);
18011 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
18014 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
18021 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18022 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18023 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18024 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18025 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18027 tmp
= gmtime (&atime
);
18028 snprintf (timebuf
, sizeof (timebuf
),
18029 "%04u-%02u-%02uT%02u:%02u:%02u",
18030 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18031 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18033 printf ("%3lu: ", (unsigned long) cnt
);
18034 if (valid_dynamic_name (filedata
, liblist
.l_name
))
18035 print_symbol (20, get_dynamic_name (filedata
, liblist
.l_name
));
18037 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
18038 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
18039 liblist
.l_version
);
18041 if (liblist
.l_flags
== 0)
18045 static const struct
18052 { " EXACT_MATCH", LL_EXACT_MATCH
},
18053 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
18054 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
18055 { " EXPORTS", LL_EXPORTS
},
18056 { " DELAY_LOAD", LL_DELAY_LOAD
},
18057 { " DELTA", LL_DELTA
}
18059 int flags
= liblist
.l_flags
;
18062 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
18063 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
18065 fputs (l_flags_vals
[fcnt
].name
, stdout
);
18066 flags
^= l_flags_vals
[fcnt
].bit
;
18069 printf (" %#x", (unsigned int) flags
);
18081 if (options_offset
!= 0)
18083 Elf_External_Options
* eopt
;
18086 sect
= filedata
->section_headers
;
18088 /* Find the section header so that we get the size. */
18089 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
18090 /* PR 17533 file: 012-277276-0.004. */
18093 error (_("No MIPS_OPTIONS header found\n"));
18097 if (sect
->sh_size
< sizeof (* eopt
))
18099 error (_("The MIPS options section is too small.\n"));
18103 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
18104 sect
->sh_size
, _("options"));
18107 Elf_Internal_Options option
;
18110 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
18112 Elf_External_Options
* eoption
;
18113 unsigned int optsize
;
18115 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18117 optsize
= BYTE_GET (eoption
->size
);
18119 /* PR 17531: file: ffa0fa3b. */
18120 if (optsize
< sizeof (* eopt
)
18121 || optsize
> sect
->sh_size
- offset
)
18123 error (_("Invalid size (%u) for MIPS option\n"),
18132 printf (ngettext ("\nSection '%s' contains %d entry:\n",
18133 "\nSection '%s' contains %d entries:\n",
18135 printable_section_name (filedata
, sect
), cnt
);
18141 Elf_External_Options
* eoption
;
18143 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18145 option
.kind
= BYTE_GET (eoption
->kind
);
18146 option
.size
= BYTE_GET (eoption
->size
);
18147 option
.section
= BYTE_GET (eoption
->section
);
18148 option
.info
= BYTE_GET (eoption
->info
);
18150 switch (option
.kind
)
18153 /* This shouldn't happen. */
18154 printf (" NULL %" PRId16
" %" PRIx32
,
18155 option
.section
, option
.info
);
18159 printf (" REGINFO ");
18160 if (filedata
->file_header
.e_machine
== EM_MIPS
)
18162 Elf32_External_RegInfo
* ereg
;
18163 Elf32_RegInfo reginfo
;
18166 if (option
.size
< (sizeof (Elf_External_Options
)
18167 + sizeof (Elf32_External_RegInfo
)))
18169 printf (_("<corrupt>\n"));
18170 error (_("Truncated MIPS REGINFO option\n"));
18175 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
18177 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18178 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18179 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18180 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18181 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18182 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18184 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
18185 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18187 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18188 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18189 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18190 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18195 Elf64_External_RegInfo
* ereg
;
18196 Elf64_Internal_RegInfo reginfo
;
18198 if (option
.size
< (sizeof (Elf_External_Options
)
18199 + sizeof (Elf64_External_RegInfo
)))
18201 printf (_("<corrupt>\n"));
18202 error (_("Truncated MIPS REGINFO option\n"));
18207 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
18208 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18209 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18210 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18211 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18212 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18213 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18215 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
18216 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18218 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18219 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18220 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18221 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18223 offset
+= option
.size
;
18226 case ODK_EXCEPTIONS
:
18227 fputs (" EXCEPTIONS fpe_min(", stdout
);
18228 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
18229 fputs (") fpe_max(", stdout
);
18230 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
18231 fputs (")", stdout
);
18233 if (option
.info
& OEX_PAGE0
)
18234 fputs (" PAGE0", stdout
);
18235 if (option
.info
& OEX_SMM
)
18236 fputs (" SMM", stdout
);
18237 if (option
.info
& OEX_FPDBUG
)
18238 fputs (" FPDBUG", stdout
);
18239 if (option
.info
& OEX_DISMISS
)
18240 fputs (" DISMISS", stdout
);
18244 fputs (" PAD ", stdout
);
18245 if (option
.info
& OPAD_PREFIX
)
18246 fputs (" PREFIX", stdout
);
18247 if (option
.info
& OPAD_POSTFIX
)
18248 fputs (" POSTFIX", stdout
);
18249 if (option
.info
& OPAD_SYMBOL
)
18250 fputs (" SYMBOL", stdout
);
18254 fputs (" HWPATCH ", stdout
);
18255 if (option
.info
& OHW_R4KEOP
)
18256 fputs (" R4KEOP", stdout
);
18257 if (option
.info
& OHW_R8KPFETCH
)
18258 fputs (" R8KPFETCH", stdout
);
18259 if (option
.info
& OHW_R5KEOP
)
18260 fputs (" R5KEOP", stdout
);
18261 if (option
.info
& OHW_R5KCVTL
)
18262 fputs (" R5KCVTL", stdout
);
18266 fputs (" FILL ", stdout
);
18267 /* XXX Print content of info word? */
18271 fputs (" TAGS ", stdout
);
18272 /* XXX Print content of info word? */
18276 fputs (" HWAND ", stdout
);
18277 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18278 fputs (" R4KEOP_CHECKED", stdout
);
18279 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18280 fputs (" R4KEOP_CLEAN", stdout
);
18284 fputs (" HWOR ", stdout
);
18285 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18286 fputs (" R4KEOP_CHECKED", stdout
);
18287 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18288 fputs (" R4KEOP_CLEAN", stdout
);
18292 printf (" GP_GROUP %#06x self-contained %#06x",
18293 option
.info
& OGP_GROUP
,
18294 (option
.info
& OGP_SELF
) >> 16);
18298 printf (" IDENT %#06x self-contained %#06x",
18299 option
.info
& OGP_GROUP
,
18300 (option
.info
& OGP_SELF
) >> 16);
18304 /* This shouldn't happen. */
18305 printf (" %3d ??? %" PRId16
" %" PRIx32
,
18306 option
.kind
, option
.section
, option
.info
);
18310 len
= sizeof (* eopt
);
18311 while (len
< option
.size
)
18313 unsigned char datum
= *((unsigned char *) eoption
+ len
);
18315 if (ISPRINT (datum
))
18316 printf ("%c", datum
);
18318 printf ("\\%03o", datum
);
18321 fputs ("\n", stdout
);
18323 offset
+= option
.size
;
18331 if (conflicts_offset
!= 0 && conflictsno
!= 0)
18333 Elf32_Conflict
* iconf
;
18336 if (filedata
->dynamic_symbols
== NULL
)
18338 error (_("conflict list found without a dynamic symbol table\n"));
18342 /* PR 21345 - print a slightly more helpful error message
18343 if we are sure that the cmalloc will fail. */
18344 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
18346 error (_("Overlarge number of conflicts detected: %lx\n"),
18347 (long) conflictsno
);
18351 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
18354 error (_("Out of memory allocating space for dynamic conflicts\n"));
18360 Elf32_External_Conflict
* econf32
;
18362 econf32
= (Elf32_External_Conflict
*)
18363 get_data (NULL
, filedata
, conflicts_offset
,
18364 sizeof (*econf32
), conflictsno
, _("conflict"));
18371 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18372 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
18378 Elf64_External_Conflict
* econf64
;
18380 econf64
= (Elf64_External_Conflict
*)
18381 get_data (NULL
, filedata
, conflicts_offset
,
18382 sizeof (*econf64
), conflictsno
, _("conflict"));
18389 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18390 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
18395 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
18396 "\nSection '.conflict' contains %lu entries:\n",
18397 (unsigned long) conflictsno
),
18398 (unsigned long) conflictsno
);
18399 puts (_(" Num: Index Value Name"));
18401 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18403 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
18405 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
18406 printf (_("<corrupt symbol index>"));
18409 Elf_Internal_Sym
* psym
;
18411 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
18412 print_vma (psym
->st_value
, FULL_HEX
);
18414 if (valid_dynamic_name (filedata
, psym
->st_name
))
18415 print_symbol (25, get_dynamic_name (filedata
, psym
->st_name
));
18417 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18425 if (pltgot
!= 0 && local_gotno
!= 0)
18427 bfd_vma ent
, local_end
, global_end
;
18429 unsigned char * data
;
18430 unsigned char * data_end
;
18434 addr_size
= (is_32bit_elf
? 4 : 8);
18435 local_end
= pltgot
+ local_gotno
* addr_size
;
18437 /* PR binutils/17533 file: 012-111227-0.004 */
18438 if (symtabno
< gotsym
)
18440 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
18441 (unsigned long) gotsym
, (unsigned long) symtabno
);
18445 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
18446 /* PR 17531: file: 54c91a34. */
18447 if (global_end
< local_end
)
18449 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno
);
18453 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
18454 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
18455 global_end
- pltgot
, 1,
18456 _("Global Offset Table data"));
18457 /* PR 12855: Null data is handled gracefully throughout. */
18458 data_end
= data
+ (global_end
- pltgot
);
18460 printf (_("\nPrimary GOT:\n"));
18461 printf (_(" Canonical gp value: "));
18462 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
18465 printf (_(" Reserved entries:\n"));
18466 printf (_(" %*s %10s %*s Purpose\n"),
18467 addr_size
* 2, _("Address"), _("Access"),
18468 addr_size
* 2, _("Initial"));
18469 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18470 printf (_(" Lazy resolver\n"));
18471 if (ent
== (bfd_vma
) -1)
18472 goto got_print_fail
;
18474 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
18475 This entry will be used by some runtime loaders, to store the
18476 module pointer. Otherwise this is an ordinary local entry.
18477 PR 21344: Check for the entry being fully available before
18480 && data
+ ent
- pltgot
+ addr_size
<= data_end
18481 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18482 >> (addr_size
* 8 - 1)) != 0)
18484 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18485 printf (_(" Module pointer (GNU extension)\n"));
18486 if (ent
== (bfd_vma
) -1)
18487 goto got_print_fail
;
18491 if (data
!= NULL
&& ent
< local_end
)
18493 printf (_(" Local entries:\n"));
18494 printf (" %*s %10s %*s\n",
18495 addr_size
* 2, _("Address"), _("Access"),
18496 addr_size
* 2, _("Initial"));
18497 while (ent
< local_end
)
18499 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18501 if (ent
== (bfd_vma
) -1)
18502 goto got_print_fail
;
18507 if (data
!= NULL
&& gotsym
< symtabno
)
18511 printf (_(" Global entries:\n"));
18512 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
18513 addr_size
* 2, _("Address"),
18515 addr_size
* 2, _("Initial"),
18516 addr_size
* 2, _("Sym.Val."),
18518 /* Note for translators: "Ndx" = abbreviated form of "Index". */
18519 _("Ndx"), _("Name"));
18521 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
18523 for (i
= gotsym
; i
< symtabno
; i
++)
18525 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18528 if (filedata
->dynamic_symbols
== NULL
)
18529 printf (_("<no dynamic symbols>"));
18530 else if (i
< filedata
->num_dynamic_syms
)
18532 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
18534 print_vma (psym
->st_value
, LONG_HEX
);
18535 printf (" %-7s %3s ",
18536 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
18537 get_symbol_index_type (filedata
, psym
->st_shndx
));
18539 if (valid_dynamic_name (filedata
, psym
->st_name
))
18540 print_symbol (sym_width
,
18541 get_dynamic_name (filedata
, psym
->st_name
));
18543 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18546 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
18547 (unsigned long) i
);
18550 if (ent
== (bfd_vma
) -1)
18560 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
18563 size_t offset
, rel_offset
;
18564 unsigned long count
, i
;
18565 unsigned char * data
;
18566 int addr_size
, sym_width
;
18567 Elf_Internal_Rela
* rels
;
18569 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
18570 if (pltrel
== DT_RELA
)
18572 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
18577 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
18582 addr_size
= (is_32bit_elf
? 4 : 8);
18583 end
= mips_pltgot
+ (2 + count
) * addr_size
;
18585 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
18586 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
18587 1, _("Procedure Linkage Table data"));
18594 printf ("\nPLT GOT:\n\n");
18595 printf (_(" Reserved entries:\n"));
18596 printf (_(" %*s %*s Purpose\n"),
18597 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
18598 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18599 printf (_(" PLT lazy resolver\n"));
18600 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18601 printf (_(" Module pointer\n"));
18604 printf (_(" Entries:\n"));
18605 printf (" %*s %*s %*s %-7s %3s %s\n",
18606 addr_size
* 2, _("Address"),
18607 addr_size
* 2, _("Initial"),
18608 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
18609 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
18610 for (i
= 0; i
< count
; i
++)
18612 unsigned long idx
= get_reloc_symindex (rels
[i
].r_info
);
18614 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18617 if (idx
>= filedata
->num_dynamic_syms
)
18618 printf (_("<corrupt symbol index: %lu>"), idx
);
18621 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
18623 print_vma (psym
->st_value
, LONG_HEX
);
18624 printf (" %-7s %3s ",
18625 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
18626 get_symbol_index_type (filedata
, psym
->st_shndx
));
18627 if (valid_dynamic_name (filedata
, psym
->st_name
))
18628 print_symbol (sym_width
,
18629 get_dynamic_name (filedata
, psym
->st_name
));
18631 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18645 process_nds32_specific (Filedata
* filedata
)
18647 Elf_Internal_Shdr
*sect
= NULL
;
18649 sect
= find_section (filedata
, ".nds32_e_flags");
18650 if (sect
!= NULL
&& sect
->sh_size
>= 4)
18652 unsigned char *buf
;
18655 printf ("\nNDS32 elf flags section:\n");
18656 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
18657 _("NDS32 elf flags section"));
18662 flag
= byte_get (buf
, 4);
18664 switch (flag
& 0x3)
18667 printf ("(VEC_SIZE):\tNo entry.\n");
18670 printf ("(VEC_SIZE):\t4 bytes\n");
18673 printf ("(VEC_SIZE):\t16 bytes\n");
18676 printf ("(VEC_SIZE):\treserved\n");
18685 process_gnu_liblist (Filedata
* filedata
)
18687 Elf_Internal_Shdr
* section
;
18688 Elf_Internal_Shdr
* string_sec
;
18689 Elf32_External_Lib
* elib
;
18691 size_t strtab_size
;
18693 unsigned long num_liblist
;
18700 for (i
= 0, section
= filedata
->section_headers
;
18701 i
< filedata
->file_header
.e_shnum
;
18704 switch (section
->sh_type
)
18706 case SHT_GNU_LIBLIST
:
18707 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
18710 elib
= (Elf32_External_Lib
*)
18711 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
18712 _("liblist section data"));
18720 string_sec
= filedata
->section_headers
+ section
->sh_link
;
18721 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
18722 string_sec
->sh_size
,
18723 _("liblist string table"));
18725 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
18732 strtab_size
= string_sec
->sh_size
;
18734 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
18735 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
18736 "\nLibrary list section '%s' contains %lu entries:\n",
18738 printable_section_name (filedata
, section
),
18741 puts (_(" Library Time Stamp Checksum Version Flags"));
18743 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
18751 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18752 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18753 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18754 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18755 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18757 tmp
= gmtime (&atime
);
18758 snprintf (timebuf
, sizeof (timebuf
),
18759 "%04u-%02u-%02uT%02u:%02u:%02u",
18760 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18761 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18763 printf ("%3lu: ", (unsigned long) cnt
);
18765 printf ("%-20s", liblist
.l_name
< strtab_size
18766 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18768 printf ("%-20.20s", liblist
.l_name
< strtab_size
18769 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18770 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
18771 liblist
.l_version
, liblist
.l_flags
);
18782 static const char *
18783 get_note_type (Filedata
* filedata
, unsigned e_type
)
18785 static char buff
[64];
18787 if (filedata
->file_header
.e_type
== ET_CORE
)
18791 return _("NT_AUXV (auxiliary vector)");
18793 return _("NT_PRSTATUS (prstatus structure)");
18795 return _("NT_FPREGSET (floating point registers)");
18797 return _("NT_PRPSINFO (prpsinfo structure)");
18798 case NT_TASKSTRUCT
:
18799 return _("NT_TASKSTRUCT (task structure)");
18801 return _("NT_GDB_TDESC (GDB XML target description)");
18803 return _("NT_PRXFPREG (user_xfpregs structure)");
18805 return _("NT_PPC_VMX (ppc Altivec registers)");
18807 return _("NT_PPC_VSX (ppc VSX registers)");
18809 return _("NT_PPC_TAR (ppc TAR register)");
18811 return _("NT_PPC_PPR (ppc PPR register)");
18813 return _("NT_PPC_DSCR (ppc DSCR register)");
18815 return _("NT_PPC_EBB (ppc EBB registers)");
18817 return _("NT_PPC_PMU (ppc PMU registers)");
18818 case NT_PPC_TM_CGPR
:
18819 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
18820 case NT_PPC_TM_CFPR
:
18821 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
18822 case NT_PPC_TM_CVMX
:
18823 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
18824 case NT_PPC_TM_CVSX
:
18825 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
18826 case NT_PPC_TM_SPR
:
18827 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
18828 case NT_PPC_TM_CTAR
:
18829 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
18830 case NT_PPC_TM_CPPR
:
18831 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
18832 case NT_PPC_TM_CDSCR
:
18833 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
18835 return _("NT_386_TLS (x86 TLS information)");
18836 case NT_386_IOPERM
:
18837 return _("NT_386_IOPERM (x86 I/O permissions)");
18838 case NT_X86_XSTATE
:
18839 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
18841 return _("NT_X86_CET (x86 CET state)");
18842 case NT_S390_HIGH_GPRS
:
18843 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
18844 case NT_S390_TIMER
:
18845 return _("NT_S390_TIMER (s390 timer register)");
18846 case NT_S390_TODCMP
:
18847 return _("NT_S390_TODCMP (s390 TOD comparator register)");
18848 case NT_S390_TODPREG
:
18849 return _("NT_S390_TODPREG (s390 TOD programmable register)");
18851 return _("NT_S390_CTRS (s390 control registers)");
18852 case NT_S390_PREFIX
:
18853 return _("NT_S390_PREFIX (s390 prefix register)");
18854 case NT_S390_LAST_BREAK
:
18855 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
18856 case NT_S390_SYSTEM_CALL
:
18857 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
18859 return _("NT_S390_TDB (s390 transaction diagnostic block)");
18860 case NT_S390_VXRS_LOW
:
18861 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
18862 case NT_S390_VXRS_HIGH
:
18863 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
18864 case NT_S390_GS_CB
:
18865 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
18866 case NT_S390_GS_BC
:
18867 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
18869 return _("NT_ARM_VFP (arm VFP registers)");
18871 return _("NT_ARM_TLS (AArch TLS registers)");
18872 case NT_ARM_HW_BREAK
:
18873 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
18874 case NT_ARM_HW_WATCH
:
18875 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
18877 return _("NT_ARM_SVE (AArch SVE registers)");
18878 case NT_ARM_PAC_MASK
:
18879 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
18880 case NT_ARM_PACA_KEYS
:
18881 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
18882 case NT_ARM_PACG_KEYS
:
18883 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
18884 case NT_ARM_TAGGED_ADDR_CTRL
:
18885 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
18886 case NT_ARM_PAC_ENABLED_KEYS
:
18887 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
18889 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
18891 return _("NT_RISCV_CSR (RISC-V control and status registers)");
18893 return _("NT_PSTATUS (pstatus structure)");
18895 return _("NT_FPREGS (floating point registers)");
18897 return _("NT_PSINFO (psinfo structure)");
18899 return _("NT_LWPSTATUS (lwpstatus_t structure)");
18901 return _("NT_LWPSINFO (lwpsinfo_t structure)");
18902 case NT_WIN32PSTATUS
:
18903 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
18905 return _("NT_SIGINFO (siginfo_t data)");
18907 return _("NT_FILE (mapped files)");
18915 return _("NT_VERSION (version)");
18917 return _("NT_ARCH (architecture)");
18918 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
18920 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
18922 case NT_GO_BUILDID
:
18923 return _("GO BUILDID");
18928 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18933 print_core_note (Elf_Internal_Note
*pnote
)
18935 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
18936 bfd_vma count
, page_size
;
18937 unsigned char *descdata
, *filenames
, *descend
;
18939 if (pnote
->type
!= NT_FILE
)
18949 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
18950 /* Still "successful". */
18955 if (pnote
->descsz
< 2 * addr_size
)
18957 error (_(" Malformed note - too short for header\n"));
18961 descdata
= (unsigned char *) pnote
->descdata
;
18962 descend
= descdata
+ pnote
->descsz
;
18964 if (descdata
[pnote
->descsz
- 1] != '\0')
18966 error (_(" Malformed note - does not end with \\0\n"));
18970 count
= byte_get (descdata
, addr_size
);
18971 descdata
+= addr_size
;
18973 page_size
= byte_get (descdata
, addr_size
);
18974 descdata
+= addr_size
;
18976 if (count
> ((bfd_vma
) -1 - 2 * addr_size
) / (3 * addr_size
)
18977 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
18979 error (_(" Malformed note - too short for supplied file count\n"));
18983 printf (_(" Page size: "));
18984 print_vma (page_size
, DEC
);
18987 printf (_(" %*s%*s%*s\n"),
18988 (int) (2 + 2 * addr_size
), _("Start"),
18989 (int) (4 + 2 * addr_size
), _("End"),
18990 (int) (4 + 2 * addr_size
), _("Page Offset"));
18991 filenames
= descdata
+ count
* 3 * addr_size
;
18992 while (count
-- > 0)
18994 bfd_vma start
, end
, file_ofs
;
18996 if (filenames
== descend
)
18998 error (_(" Malformed note - filenames end too early\n"));
19002 start
= byte_get (descdata
, addr_size
);
19003 descdata
+= addr_size
;
19004 end
= byte_get (descdata
, addr_size
);
19005 descdata
+= addr_size
;
19006 file_ofs
= byte_get (descdata
, addr_size
);
19007 descdata
+= addr_size
;
19010 print_vma (start
, FULL_HEX
);
19012 print_vma (end
, FULL_HEX
);
19014 print_vma (file_ofs
, FULL_HEX
);
19015 printf ("\n %s\n", filenames
);
19017 filenames
+= 1 + strlen ((char *) filenames
);
19023 static const char *
19024 get_gnu_elf_note_type (unsigned e_type
)
19026 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
19029 case NT_GNU_ABI_TAG
:
19030 return _("NT_GNU_ABI_TAG (ABI version tag)");
19032 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
19033 case NT_GNU_BUILD_ID
:
19034 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
19035 case NT_GNU_GOLD_VERSION
:
19036 return _("NT_GNU_GOLD_VERSION (gold version)");
19037 case NT_GNU_PROPERTY_TYPE_0
:
19038 return _("NT_GNU_PROPERTY_TYPE_0");
19039 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
19040 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
19041 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
19042 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
19045 static char buff
[64];
19047 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19054 decode_x86_compat_isa (unsigned int bitmask
)
19058 unsigned int bit
= bitmask
& (- bitmask
);
19063 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
19066 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
19069 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
19072 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
19075 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
19078 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
19081 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
19084 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
19087 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
19090 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
19093 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
19096 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
19097 printf ("AVX512F");
19099 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
19100 printf ("AVX512CD");
19102 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
19103 printf ("AVX512ER");
19105 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
19106 printf ("AVX512PF");
19108 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
19109 printf ("AVX512VL");
19111 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
19112 printf ("AVX512DQ");
19114 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
19115 printf ("AVX512BW");
19118 printf (_("<unknown: %x>"), bit
);
19127 decode_x86_compat_2_isa (unsigned int bitmask
)
19131 printf (_("<None>"));
19137 unsigned int bit
= bitmask
& (- bitmask
);
19142 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
19145 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
19148 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
19151 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
19154 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
19157 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
19160 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
19163 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
19166 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
19169 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
19172 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
19173 printf ("AVX512F");
19175 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
19176 printf ("AVX512CD");
19178 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
19179 printf ("AVX512ER");
19181 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
19182 printf ("AVX512PF");
19184 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
19185 printf ("AVX512VL");
19187 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
19188 printf ("AVX512DQ");
19190 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
19191 printf ("AVX512BW");
19193 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
19194 printf ("AVX512_4FMAPS");
19196 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
19197 printf ("AVX512_4VNNIW");
19199 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
19200 printf ("AVX512_BITALG");
19202 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
19203 printf ("AVX512_IFMA");
19205 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
19206 printf ("AVX512_VBMI");
19208 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
19209 printf ("AVX512_VBMI2");
19211 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
19212 printf ("AVX512_VNNI");
19214 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
19215 printf ("AVX512_BF16");
19218 printf (_("<unknown: %x>"), bit
);
19227 decode_x86_isa (unsigned int bitmask
)
19231 unsigned int bit
= bitmask
& (- bitmask
);
19236 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
19237 printf ("x86-64-baseline");
19239 case GNU_PROPERTY_X86_ISA_1_V2
:
19240 printf ("x86-64-v2");
19242 case GNU_PROPERTY_X86_ISA_1_V3
:
19243 printf ("x86-64-v3");
19245 case GNU_PROPERTY_X86_ISA_1_V4
:
19246 printf ("x86-64-v4");
19249 printf (_("<unknown: %x>"), bit
);
19258 decode_x86_feature_1 (unsigned int bitmask
)
19262 printf (_("<None>"));
19268 unsigned int bit
= bitmask
& (- bitmask
);
19273 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
19276 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
19279 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
19280 printf ("LAM_U48");
19282 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
19283 printf ("LAM_U57");
19286 printf (_("<unknown: %x>"), bit
);
19295 decode_x86_feature_2 (unsigned int bitmask
)
19299 printf (_("<None>"));
19305 unsigned int bit
= bitmask
& (- bitmask
);
19310 case GNU_PROPERTY_X86_FEATURE_2_X86
:
19313 case GNU_PROPERTY_X86_FEATURE_2_X87
:
19316 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
19319 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
19322 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
19325 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
19328 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
19331 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
19334 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
19337 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
19340 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
19341 printf ("XSAVEOPT");
19343 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
19347 printf (_("<unknown: %x>"), bit
);
19356 decode_aarch64_feature_1_and (unsigned int bitmask
)
19360 unsigned int bit
= bitmask
& (- bitmask
);
19365 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
19369 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
19374 printf (_("<unknown: %x>"), bit
);
19383 decode_1_needed (unsigned int bitmask
)
19387 unsigned int bit
= bitmask
& (- bitmask
);
19392 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
19393 printf ("indirect external access");
19396 printf (_("<unknown: %x>"), bit
);
19405 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
19407 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
19408 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
19409 unsigned int size
= is_32bit_elf
? 4 : 8;
19411 printf (_(" Properties: "));
19413 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
19415 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
19419 while (ptr
< ptr_end
)
19423 unsigned int datasz
;
19425 if ((size_t) (ptr_end
- ptr
) < 8)
19427 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
19431 type
= byte_get (ptr
, 4);
19432 datasz
= byte_get (ptr
+ 4, 4);
19436 if (datasz
> (size_t) (ptr_end
- ptr
))
19438 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
19443 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
19445 if (filedata
->file_header
.e_machine
== EM_X86_64
19446 || filedata
->file_header
.e_machine
== EM_IAMCU
19447 || filedata
->file_header
.e_machine
== EM_386
)
19449 unsigned int bitmask
;
19452 bitmask
= byte_get (ptr
, 4);
19458 case GNU_PROPERTY_X86_ISA_1_USED
:
19460 printf (_("x86 ISA used: <corrupt length: %#x> "),
19464 printf ("x86 ISA used: ");
19465 decode_x86_isa (bitmask
);
19469 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
19471 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19475 printf ("x86 ISA needed: ");
19476 decode_x86_isa (bitmask
);
19480 case GNU_PROPERTY_X86_FEATURE_1_AND
:
19482 printf (_("x86 feature: <corrupt length: %#x> "),
19486 printf ("x86 feature: ");
19487 decode_x86_feature_1 (bitmask
);
19491 case GNU_PROPERTY_X86_FEATURE_2_USED
:
19493 printf (_("x86 feature used: <corrupt length: %#x> "),
19497 printf ("x86 feature used: ");
19498 decode_x86_feature_2 (bitmask
);
19502 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
19504 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
19507 printf ("x86 feature needed: ");
19508 decode_x86_feature_2 (bitmask
);
19512 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
19514 printf (_("x86 ISA used: <corrupt length: %#x> "),
19518 printf ("x86 ISA used: ");
19519 decode_x86_compat_isa (bitmask
);
19523 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
19525 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19529 printf ("x86 ISA needed: ");
19530 decode_x86_compat_isa (bitmask
);
19534 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
19536 printf (_("x86 ISA used: <corrupt length: %#x> "),
19540 printf ("x86 ISA used: ");
19541 decode_x86_compat_2_isa (bitmask
);
19545 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
19547 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19551 printf ("x86 ISA needed: ");
19552 decode_x86_compat_2_isa (bitmask
);
19560 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
19562 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
19564 printf ("AArch64 feature: ");
19566 printf (_("<corrupt length: %#x> "), datasz
);
19568 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
19577 case GNU_PROPERTY_STACK_SIZE
:
19578 printf (_("stack size: "));
19579 if (datasz
!= size
)
19580 printf (_("<corrupt length: %#x> "), datasz
);
19582 printf ("%#lx", (unsigned long) byte_get (ptr
, size
));
19585 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
19586 printf ("no copy on protected ");
19588 printf (_("<corrupt length: %#x> "), datasz
);
19592 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
19593 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
19594 || (type
>= GNU_PROPERTY_UINT32_OR_LO
19595 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
19599 case GNU_PROPERTY_1_NEEDED
:
19601 printf (_("1_needed: <corrupt length: %#x> "),
19605 unsigned int bitmask
= byte_get (ptr
, 4);
19606 printf ("1_needed: ");
19607 decode_1_needed (bitmask
);
19614 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
19615 printf (_("UINT32_AND (%#x): "), type
);
19617 printf (_("UINT32_OR (%#x): "), type
);
19619 printf (_("<corrupt length: %#x> "), datasz
);
19621 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
19628 if (type
< GNU_PROPERTY_LOPROC
)
19629 printf (_("<unknown type %#x data: "), type
);
19630 else if (type
< GNU_PROPERTY_LOUSER
)
19631 printf (_("<processor-specific type %#x data: "), type
);
19633 printf (_("<application-specific type %#x data: "), type
);
19634 for (j
= 0; j
< datasz
; ++j
)
19635 printf ("%02x ", ptr
[j
] & 0xff);
19639 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
19640 if (ptr
== ptr_end
)
19653 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
19655 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
19656 switch (pnote
->type
)
19658 case NT_GNU_BUILD_ID
:
19662 printf (_(" Build ID: "));
19663 for (i
= 0; i
< pnote
->descsz
; ++i
)
19664 printf ("%02x", pnote
->descdata
[i
] & 0xff);
19669 case NT_GNU_ABI_TAG
:
19671 unsigned long os
, major
, minor
, subminor
;
19672 const char *osname
;
19674 /* PR 17531: file: 030-599401-0.004. */
19675 if (pnote
->descsz
< 16)
19677 printf (_(" <corrupt GNU_ABI_TAG>\n"));
19681 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19682 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19683 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
19684 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
19688 case GNU_ABI_TAG_LINUX
:
19691 case GNU_ABI_TAG_HURD
:
19694 case GNU_ABI_TAG_SOLARIS
:
19695 osname
= "Solaris";
19697 case GNU_ABI_TAG_FREEBSD
:
19698 osname
= "FreeBSD";
19700 case GNU_ABI_TAG_NETBSD
:
19703 case GNU_ABI_TAG_SYLLABLE
:
19704 osname
= "Syllable";
19706 case GNU_ABI_TAG_NACL
:
19710 osname
= "Unknown";
19714 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname
,
19715 major
, minor
, subminor
);
19719 case NT_GNU_GOLD_VERSION
:
19723 printf (_(" Version: "));
19724 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
19725 printf ("%c", pnote
->descdata
[i
]);
19732 unsigned long num_entries
, mask
;
19734 /* Hardware capabilities information. Word 0 is the number of entries.
19735 Word 1 is a bitmask of enabled entries. The rest of the descriptor
19736 is a series of entries, where each entry is a single byte followed
19737 by a nul terminated string. The byte gives the bit number to test
19738 if enabled in the bitmask. */
19739 printf (_(" Hardware Capabilities: "));
19740 if (pnote
->descsz
< 8)
19742 error (_("<corrupt GNU_HWCAP>\n"));
19745 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19746 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19747 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries
, mask
);
19748 /* FIXME: Add code to display the entries... */
19752 case NT_GNU_PROPERTY_TYPE_0
:
19753 print_gnu_property_note (filedata
, pnote
);
19757 /* Handle unrecognised types. An error message should have already been
19758 created by get_gnu_elf_note_type(), so all that we need to do is to
19759 display the data. */
19763 printf (_(" Description data: "));
19764 for (i
= 0; i
< pnote
->descsz
; ++i
)
19765 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
19774 static const char *
19775 get_v850_elf_note_type (enum v850_notes n_type
)
19777 static char buff
[64];
19781 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
19782 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
19783 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
19784 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
19785 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
19786 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
19788 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
19794 print_v850_note (Elf_Internal_Note
* pnote
)
19798 if (pnote
->descsz
!= 4)
19801 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
19805 printf (_("not set\n"));
19809 switch (pnote
->type
)
19811 case V850_NOTE_ALIGNMENT
:
19814 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
19815 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
19819 case V850_NOTE_DATA_SIZE
:
19822 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
19823 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
19827 case V850_NOTE_FPU_INFO
:
19830 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
19831 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
19835 case V850_NOTE_MMU_INFO
:
19836 case V850_NOTE_CACHE_INFO
:
19837 case V850_NOTE_SIMD_INFO
:
19838 if (val
== EF_RH850_SIMD
)
19840 printf (_("yes\n"));
19846 /* An 'unknown note type' message will already have been displayed. */
19850 printf (_("unknown value: %x\n"), val
);
19855 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
19857 unsigned int version
;
19859 switch (pnote
->type
)
19861 case NT_NETBSD_IDENT
:
19862 if (pnote
->descsz
< 1)
19864 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19865 if ((version
/ 10000) % 100)
19866 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
19867 version
, version
/ 100000000, (version
/ 1000000) % 100,
19868 (version
/ 10000) % 100 > 26 ? "Z" : "",
19869 'A' + (version
/ 10000) % 26);
19871 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
19872 version
, version
/ 100000000, (version
/ 1000000) % 100,
19873 (version
/ 100) % 100);
19876 case NT_NETBSD_MARCH
:
19877 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
19881 case NT_NETBSD_PAX
:
19882 if (pnote
->descsz
< 1)
19884 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19885 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
19886 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
19887 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
19888 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
19889 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
19890 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
19891 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
19895 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
19896 pnote
->descsz
, pnote
->type
);
19900 static const char *
19901 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19905 case NT_FREEBSD_THRMISC
:
19906 return _("NT_THRMISC (thrmisc structure)");
19907 case NT_FREEBSD_PROCSTAT_PROC
:
19908 return _("NT_PROCSTAT_PROC (proc data)");
19909 case NT_FREEBSD_PROCSTAT_FILES
:
19910 return _("NT_PROCSTAT_FILES (files data)");
19911 case NT_FREEBSD_PROCSTAT_VMMAP
:
19912 return _("NT_PROCSTAT_VMMAP (vmmap data)");
19913 case NT_FREEBSD_PROCSTAT_GROUPS
:
19914 return _("NT_PROCSTAT_GROUPS (groups data)");
19915 case NT_FREEBSD_PROCSTAT_UMASK
:
19916 return _("NT_PROCSTAT_UMASK (umask data)");
19917 case NT_FREEBSD_PROCSTAT_RLIMIT
:
19918 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
19919 case NT_FREEBSD_PROCSTAT_OSREL
:
19920 return _("NT_PROCSTAT_OSREL (osreldate data)");
19921 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
19922 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
19923 case NT_FREEBSD_PROCSTAT_AUXV
:
19924 return _("NT_PROCSTAT_AUXV (auxv data)");
19925 case NT_FREEBSD_PTLWPINFO
:
19926 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
19928 return get_note_type (filedata
, e_type
);
19931 static const char *
19932 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19934 static char buff
[64];
19938 case NT_NETBSDCORE_PROCINFO
:
19939 /* NetBSD core "procinfo" structure. */
19940 return _("NetBSD procinfo structure");
19942 case NT_NETBSDCORE_AUXV
:
19943 return _("NetBSD ELF auxiliary vector data");
19945 case NT_NETBSDCORE_LWPSTATUS
:
19946 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
19949 /* As of Jan 2020 there are no other machine-independent notes
19950 defined for NetBSD core files. If the note type is less
19951 than the start of the machine-dependent note types, we don't
19954 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
19956 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19962 switch (filedata
->file_header
.e_machine
)
19964 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
19965 and PT_GETFPREGS == mach+2. */
19970 case EM_SPARC32PLUS
:
19974 case NT_NETBSDCORE_FIRSTMACH
+ 0:
19975 return _("PT_GETREGS (reg structure)");
19976 case NT_NETBSDCORE_FIRSTMACH
+ 2:
19977 return _("PT_GETFPREGS (fpreg structure)");
19983 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
19984 There's also old PT___GETREGS40 == mach + 1 for old reg
19985 structure which lacks GBR. */
19989 case NT_NETBSDCORE_FIRSTMACH
+ 1:
19990 return _("PT___GETREGS40 (old reg structure)");
19991 case NT_NETBSDCORE_FIRSTMACH
+ 3:
19992 return _("PT_GETREGS (reg structure)");
19993 case NT_NETBSDCORE_FIRSTMACH
+ 5:
19994 return _("PT_GETFPREGS (fpreg structure)");
20000 /* On all other arch's, PT_GETREGS == mach+1 and
20001 PT_GETFPREGS == mach+3. */
20005 case NT_NETBSDCORE_FIRSTMACH
+ 1:
20006 return _("PT_GETREGS (reg structure)");
20007 case NT_NETBSDCORE_FIRSTMACH
+ 3:
20008 return _("PT_GETFPREGS (fpreg structure)");
20014 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
20015 e_type
- NT_NETBSDCORE_FIRSTMACH
);
20019 static const char *
20020 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20024 case NT_OPENBSD_PROCINFO
:
20025 return _("OpenBSD procinfo structure");
20026 case NT_OPENBSD_AUXV
:
20027 return _("OpenBSD ELF auxiliary vector data");
20028 case NT_OPENBSD_REGS
:
20029 return _("OpenBSD regular registers");
20030 case NT_OPENBSD_FPREGS
:
20031 return _("OpenBSD floating point registers");
20032 case NT_OPENBSD_WCOOKIE
:
20033 return _("OpenBSD window cookie");
20036 return get_note_type (filedata
, e_type
);
20039 static const char *
20040 get_stapsdt_note_type (unsigned e_type
)
20042 static char buff
[64];
20047 return _("NT_STAPSDT (SystemTap probe descriptors)");
20053 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20058 print_stapsdt_note (Elf_Internal_Note
*pnote
)
20060 size_t len
, maxlen
;
20061 unsigned long addr_size
= is_32bit_elf
? 4 : 8;
20062 char *data
= pnote
->descdata
;
20063 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
20064 bfd_vma pc
, base_addr
, semaphore
;
20065 char *provider
, *probe
, *arg_fmt
;
20067 if (pnote
->descsz
< (addr_size
* 3))
20068 goto stapdt_note_too_small
;
20070 pc
= byte_get ((unsigned char *) data
, addr_size
);
20073 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
20076 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
20079 if (data
>= data_end
)
20080 goto stapdt_note_too_small
;
20081 maxlen
= data_end
- data
;
20082 len
= strnlen (data
, maxlen
);
20089 goto stapdt_note_too_small
;
20091 if (data
>= data_end
)
20092 goto stapdt_note_too_small
;
20093 maxlen
= data_end
- data
;
20094 len
= strnlen (data
, maxlen
);
20101 goto stapdt_note_too_small
;
20103 if (data
>= data_end
)
20104 goto stapdt_note_too_small
;
20105 maxlen
= data_end
- data
;
20106 len
= strnlen (data
, maxlen
);
20113 goto stapdt_note_too_small
;
20115 printf (_(" Provider: %s\n"), provider
);
20116 printf (_(" Name: %s\n"), probe
);
20117 printf (_(" Location: "));
20118 print_vma (pc
, FULL_HEX
);
20119 printf (_(", Base: "));
20120 print_vma (base_addr
, FULL_HEX
);
20121 printf (_(", Semaphore: "));
20122 print_vma (semaphore
, FULL_HEX
);
20124 printf (_(" Arguments: %s\n"), arg_fmt
);
20126 return data
== data_end
;
20128 stapdt_note_too_small
:
20129 printf (_(" <corrupt - note is too small>\n"));
20130 error (_("corrupt stapdt note - the data size is too small\n"));
20134 static const char *
20135 get_ia64_vms_note_type (unsigned e_type
)
20137 static char buff
[64];
20142 return _("NT_VMS_MHD (module header)");
20144 return _("NT_VMS_LNM (language name)");
20146 return _("NT_VMS_SRC (source files)");
20148 return "NT_VMS_TITLE";
20150 return _("NT_VMS_EIDC (consistency check)");
20151 case NT_VMS_FPMODE
:
20152 return _("NT_VMS_FPMODE (FP mode)");
20153 case NT_VMS_LINKTIME
:
20154 return "NT_VMS_LINKTIME";
20155 case NT_VMS_IMGNAM
:
20156 return _("NT_VMS_IMGNAM (image name)");
20158 return _("NT_VMS_IMGID (image id)");
20159 case NT_VMS_LINKID
:
20160 return _("NT_VMS_LINKID (link id)");
20161 case NT_VMS_IMGBID
:
20162 return _("NT_VMS_IMGBID (build id)");
20163 case NT_VMS_GSTNAM
:
20164 return _("NT_VMS_GSTNAM (sym table name)");
20165 case NT_VMS_ORIG_DYN
:
20166 return "NT_VMS_ORIG_DYN";
20167 case NT_VMS_PATCHTIME
:
20168 return "NT_VMS_PATCHTIME";
20170 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20176 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
20178 int maxlen
= pnote
->descsz
;
20180 if (maxlen
< 2 || (unsigned long) maxlen
!= pnote
->descsz
)
20181 goto desc_size_fail
;
20183 switch (pnote
->type
)
20187 goto desc_size_fail
;
20189 int l
= (int) strnlen (pnote
->descdata
+ 34, maxlen
- 34);
20191 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
20192 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
20193 if (l
+ 34 < maxlen
)
20195 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
20196 if (l
+ 35 < maxlen
)
20197 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
20199 printf (_(" Module version : <missing>\n"));
20203 printf (_(" Module name : <missing>\n"));
20204 printf (_(" Module version : <missing>\n"));
20209 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
20213 case NT_VMS_FPMODE
:
20214 printf (_(" Floating Point mode: "));
20216 goto desc_size_fail
;
20217 /* FIXME: Generate an error if descsz > 8 ? */
20219 printf ("0x%016" BFD_VMA_FMT
"x\n",
20220 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
, 8));
20223 case NT_VMS_LINKTIME
:
20224 printf (_(" Link time: "));
20226 goto desc_size_fail
;
20227 /* FIXME: Generate an error if descsz > 8 ? */
20230 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
20234 case NT_VMS_PATCHTIME
:
20235 printf (_(" Patch time: "));
20237 goto desc_size_fail
;
20238 /* FIXME: Generate an error if descsz > 8 ? */
20241 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
20245 case NT_VMS_ORIG_DYN
:
20247 goto desc_size_fail
;
20249 printf (_(" Major id: %u, minor id: %u\n"),
20250 (unsigned) byte_get ((unsigned char *)pnote
->descdata
, 4),
20251 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 4, 4));
20252 printf (_(" Last modified : "));
20254 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
+ 8, 8));
20255 printf (_("\n Link flags : "));
20256 printf ("0x%016" BFD_VMA_FMT
"x\n",
20257 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
+ 16, 8));
20258 printf (_(" Header flags: 0x%08x\n"),
20259 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 24, 4));
20260 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
20264 case NT_VMS_IMGNAM
:
20265 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
20268 case NT_VMS_GSTNAM
:
20269 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
20273 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
20276 case NT_VMS_LINKID
:
20277 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
20287 printf (_(" <corrupt - data size is too small>\n"));
20288 error (_("corrupt IA64 note: data size is too small\n"));
20292 struct build_attr_cache
{
20293 Filedata
*filedata
;
20295 unsigned long strtablen
;
20296 Elf_Internal_Sym
*symtab
;
20297 unsigned long nsyms
;
20300 /* Find the symbol associated with a build attribute that is attached
20301 to address OFFSET. If PNAME is non-NULL then store the name of
20302 the symbol (if found) in the provided pointer, Returns NULL if a
20303 symbol could not be found. */
20305 static Elf_Internal_Sym
*
20306 get_symbol_for_build_attribute (Filedata
*filedata
,
20307 unsigned long offset
,
20309 const char **pname
)
20311 Elf_Internal_Sym
*saved_sym
= NULL
;
20312 Elf_Internal_Sym
*sym
;
20314 if (filedata
->section_headers
!= NULL
20315 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
20317 Elf_Internal_Shdr
* symsec
;
20319 free (ba_cache
.strtab
);
20320 ba_cache
.strtab
= NULL
;
20321 free (ba_cache
.symtab
);
20322 ba_cache
.symtab
= NULL
;
20324 /* Load the symbol and string sections. */
20325 for (symsec
= filedata
->section_headers
;
20326 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
20329 if (symsec
->sh_type
== SHT_SYMTAB
20330 && get_symtab (filedata
, symsec
,
20331 &ba_cache
.symtab
, &ba_cache
.nsyms
,
20332 &ba_cache
.strtab
, &ba_cache
.strtablen
))
20335 ba_cache
.filedata
= filedata
;
20338 if (ba_cache
.symtab
== NULL
)
20341 /* Find a symbol whose value matches offset. */
20342 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
20343 if (sym
->st_value
== offset
)
20345 if (sym
->st_name
>= ba_cache
.strtablen
)
20346 /* Huh ? This should not happen. */
20349 if (ba_cache
.strtab
[sym
->st_name
] == 0)
20352 /* The AArch64, ARM and RISC-V architectures define mapping symbols
20353 (eg $d, $x, $t) which we want to ignore. */
20354 if (ba_cache
.strtab
[sym
->st_name
] == '$'
20355 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
20356 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
20361 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
20362 and FILE or OBJECT symbols over NOTYPE symbols. We skip
20363 FUNC symbols entirely. */
20364 switch (ELF_ST_TYPE (sym
->st_info
))
20371 /* If the symbol has a size associated
20372 with it then we can stop searching. */
20373 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
20378 /* Ignore function symbols. */
20385 switch (ELF_ST_BIND (sym
->st_info
))
20388 if (saved_sym
== NULL
20389 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
20394 if (saved_sym
== NULL
)
20404 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
20412 if (saved_sym
&& pname
)
20413 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
20418 /* Returns true iff addr1 and addr2 are in the same section. */
20421 same_section (Filedata
* filedata
, unsigned long addr1
, unsigned long addr2
)
20423 Elf_Internal_Shdr
* a1
;
20424 Elf_Internal_Shdr
* a2
;
20426 a1
= find_section_by_address (filedata
, addr1
);
20427 a2
= find_section_by_address (filedata
, addr2
);
20429 return a1
== a2
&& a1
!= NULL
;
20433 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
20434 Filedata
* filedata
)
20436 static unsigned long global_offset
= 0;
20437 static unsigned long global_end
= 0;
20438 static unsigned long func_offset
= 0;
20439 static unsigned long func_end
= 0;
20441 Elf_Internal_Sym
*sym
;
20443 unsigned long start
;
20445 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
20447 switch (pnote
->descsz
)
20450 /* A zero-length description means that the range of
20451 the previous note of the same type should be used. */
20454 if (global_end
> global_offset
)
20455 printf (_(" Applies to region from %#lx to %#lx\n"),
20456 global_offset
, global_end
);
20458 printf (_(" Applies to region from %#lx\n"), global_offset
);
20462 if (func_end
> func_offset
)
20463 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset
, func_end
);
20465 printf (_(" Applies to region from %#lx\n"), func_offset
);
20470 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20475 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20476 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20480 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
20481 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
20485 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
20486 printf (_(" <invalid descsz>"));
20491 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
20492 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
20493 in order to avoid them being confused with the start address of the
20494 first function in the file... */
20495 if (sym
== NULL
&& is_open_attr
)
20496 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
20499 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
20500 end
= start
+ sym
->st_size
;
20504 /* FIXME: Need to properly allow for section alignment.
20505 16 is just the alignment used on x86_64. */
20507 && start
> BFD_ALIGN (global_end
, 16)
20508 /* Build notes are not guaranteed to be organised in order of
20509 increasing address, but we should find the all of the notes
20510 for one section in the same place. */
20511 && same_section (filedata
, start
, global_end
))
20512 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
20513 global_end
+ 1, start
- 1);
20515 printf (_(" Applies to region from %#lx"), start
);
20516 global_offset
= start
;
20520 printf (_(" to %#lx"), end
);
20526 printf (_(" Applies to region from %#lx"), start
);
20527 func_offset
= start
;
20531 printf (_(" to %#lx"), end
);
20537 printf (_(" (%s)"), name
);
20544 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
20546 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
20547 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
20548 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
20550 char name_attribute
;
20551 const char * expected_types
;
20552 const char * name
= pnote
->namedata
;
20556 if (name
== NULL
|| pnote
->namesz
< 2)
20558 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
20559 print_symbol (-20, _(" <corrupt name>"));
20568 /* Version 2 of the spec adds a "GA" prefix to the name field. */
20569 if (name
[0] == 'G' && name
[1] == 'A')
20571 if (pnote
->namesz
< 4)
20573 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
20574 print_symbol (-20, _(" <corrupt name>"));
20583 switch ((name_type
= * name
))
20585 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
20586 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
20587 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
20588 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
20589 printf ("%c", * name
);
20593 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
20594 print_symbol (-20, _("<unknown name type>"));
20601 switch ((name_attribute
= * name
))
20603 case GNU_BUILD_ATTRIBUTE_VERSION
:
20604 text
= _("<version>");
20605 expected_types
= string_expected
;
20608 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
20609 text
= _("<stack prot>");
20610 expected_types
= "!+*";
20613 case GNU_BUILD_ATTRIBUTE_RELRO
:
20614 text
= _("<relro>");
20615 expected_types
= bool_expected
;
20618 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
20619 text
= _("<stack size>");
20620 expected_types
= number_expected
;
20623 case GNU_BUILD_ATTRIBUTE_TOOL
:
20624 text
= _("<tool>");
20625 expected_types
= string_expected
;
20628 case GNU_BUILD_ATTRIBUTE_ABI
:
20630 expected_types
= "$*";
20633 case GNU_BUILD_ATTRIBUTE_PIC
:
20635 expected_types
= number_expected
;
20638 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
20639 text
= _("<short enum>");
20640 expected_types
= bool_expected
;
20644 if (ISPRINT (* name
))
20646 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
20648 if (len
> left
&& ! do_wide
)
20650 printf ("%.*s:", len
, name
);
20656 static char tmpbuf
[128];
20658 error (_("unrecognised byte in name field: %d\n"), * name
);
20659 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
20663 expected_types
= "*$!+";
20668 left
-= printf ("%s", text
);
20670 if (strchr (expected_types
, name_type
) == NULL
)
20671 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
20673 if ((unsigned long)(name
- pnote
->namedata
) > pnote
->namesz
)
20675 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
20676 (unsigned long) pnote
->namesz
,
20677 (long) (name
- pnote
->namedata
));
20681 if (left
< 1 && ! do_wide
)
20686 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
20688 unsigned int bytes
;
20689 unsigned long long val
= 0;
20690 unsigned int shift
= 0;
20691 char * decoded
= NULL
;
20693 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
20695 /* The -1 is because the name field is always 0 terminated, and we
20696 want to be able to ensure that the shift in the while loop below
20697 will not overflow. */
20700 if (bytes
> sizeof (val
))
20702 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
20704 bytes
= sizeof (val
);
20706 /* We do not bother to warn if bytes == 0 as this can
20707 happen with some early versions of the gcc plugin. */
20711 unsigned long long byte
= *name
++ & 0xff;
20713 val
|= byte
<< shift
;
20717 switch (name_attribute
)
20719 case GNU_BUILD_ATTRIBUTE_PIC
:
20722 case 0: decoded
= "static"; break;
20723 case 1: decoded
= "pic"; break;
20724 case 2: decoded
= "PIC"; break;
20725 case 3: decoded
= "pie"; break;
20726 case 4: decoded
= "PIE"; break;
20730 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
20733 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
20734 case 0: decoded
= "off"; break;
20735 case 1: decoded
= "on"; break;
20736 case 2: decoded
= "all"; break;
20737 case 3: decoded
= "strong"; break;
20738 case 4: decoded
= "explicit"; break;
20746 if (decoded
!= NULL
)
20748 print_symbol (-left
, decoded
);
20759 left
-= printf ("0x%llx", val
);
20761 left
-= printf ("0x%-.*llx", left
, val
);
20765 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
20766 left
-= print_symbol (- left
, name
);
20768 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
20769 left
-= print_symbol (- left
, "true");
20771 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
20772 left
-= print_symbol (- left
, "false");
20776 if (do_wide
&& left
> 0)
20777 printf ("%-*s", left
, " ");
20782 /* Note that by the ELF standard, the name field is already null byte
20783 terminated, and namesz includes the terminating null byte.
20784 I.E. the value of namesz for the name "FSF" is 4.
20786 If the value of namesz is zero, there is no name present. */
20789 process_note (Elf_Internal_Note
* pnote
,
20790 Filedata
* filedata
)
20792 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
20795 if (pnote
->namesz
== 0)
20796 /* If there is no note name, then use the default set of
20797 note type strings. */
20798 nt
= get_note_type (filedata
, pnote
->type
);
20800 else if (startswith (pnote
->namedata
, "GNU"))
20801 /* GNU-specific object file notes. */
20802 nt
= get_gnu_elf_note_type (pnote
->type
);
20804 else if (startswith (pnote
->namedata
, "FreeBSD"))
20805 /* FreeBSD-specific core file notes. */
20806 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
20808 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
20809 /* NetBSD-specific core file notes. */
20810 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
20812 else if (startswith (pnote
->namedata
, "NetBSD"))
20813 /* NetBSD-specific core file notes. */
20814 return process_netbsd_elf_note (pnote
);
20816 else if (startswith (pnote
->namedata
, "PaX"))
20817 /* NetBSD-specific core file notes. */
20818 return process_netbsd_elf_note (pnote
);
20820 else if (startswith (pnote
->namedata
, "OpenBSD"))
20821 /* OpenBSD-specific core file notes. */
20822 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
20824 else if (startswith (pnote
->namedata
, "SPU/"))
20826 /* SPU-specific core file notes. */
20827 nt
= pnote
->namedata
+ 4;
20831 else if (startswith (pnote
->namedata
, "IPF/VMS"))
20832 /* VMS/ia64-specific file notes. */
20833 nt
= get_ia64_vms_note_type (pnote
->type
);
20835 else if (startswith (pnote
->namedata
, "stapsdt"))
20836 nt
= get_stapsdt_note_type (pnote
->type
);
20839 /* Don't recognize this note name; just use the default set of
20840 note type strings. */
20841 nt
= get_note_type (filedata
, pnote
->type
);
20845 if (((startswith (pnote
->namedata
, "GA")
20846 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20847 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20848 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20849 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20850 print_gnu_build_attribute_name (pnote
);
20852 print_symbol (-20, name
);
20855 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
20857 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
20859 if (startswith (pnote
->namedata
, "IPF/VMS"))
20860 return print_ia64_vms_note (pnote
);
20861 else if (startswith (pnote
->namedata
, "GNU"))
20862 return print_gnu_note (filedata
, pnote
);
20863 else if (startswith (pnote
->namedata
, "stapsdt"))
20864 return print_stapsdt_note (pnote
);
20865 else if (startswith (pnote
->namedata
, "CORE"))
20866 return print_core_note (pnote
);
20867 else if (((startswith (pnote
->namedata
, "GA")
20868 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20869 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20870 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20871 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20872 return print_gnu_build_attribute_description (pnote
, filedata
);
20878 printf (_(" description data: "));
20879 for (i
= 0; i
< pnote
->descsz
; i
++)
20880 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
20892 process_notes_at (Filedata
* filedata
,
20893 Elf_Internal_Shdr
* section
,
20898 Elf_External_Note
*pnotes
;
20899 Elf_External_Note
*external
;
20908 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
20911 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
20919 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
20922 if (pnotes
== NULL
)
20927 if (filedata
->is_separate
)
20928 printf (_("In linked file '%s': "), filedata
->file_name
);
20932 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
20934 printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
20935 (unsigned long) offset
, (unsigned long) length
);
20937 /* NB: Some note sections may have alignment value of 0 or 1. gABI
20938 specifies that notes should be aligned to 4 bytes in 32-bit
20939 objects and to 8 bytes in 64-bit objects. As a Linux extension,
20940 we also support 4 byte alignment in 64-bit objects. If section
20941 alignment is less than 4, we treate alignment as 4 bytes. */
20944 else if (align
!= 4 && align
!= 8)
20946 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
20952 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
20954 end
= (char *) pnotes
+ length
;
20955 while ((char *) external
< end
)
20957 Elf_Internal_Note inote
;
20960 char * temp
= NULL
;
20961 size_t data_remaining
= end
- (char *) external
;
20963 if (!is_ia64_vms (filedata
))
20965 /* PR binutils/15191
20966 Make sure that there is enough data to read. */
20967 min_notesz
= offsetof (Elf_External_Note
, name
);
20968 if (data_remaining
< min_notesz
)
20970 warn (ngettext ("Corrupt note: only %ld byte remains, "
20971 "not enough for a full note\n",
20972 "Corrupt note: only %ld bytes remain, "
20973 "not enough for a full note\n",
20975 (long) data_remaining
);
20978 data_remaining
-= min_notesz
;
20980 inote
.type
= BYTE_GET (external
->type
);
20981 inote
.namesz
= BYTE_GET (external
->namesz
);
20982 inote
.namedata
= external
->name
;
20983 inote
.descsz
= BYTE_GET (external
->descsz
);
20984 inote
.descdata
= ((char *) external
20985 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
20986 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20987 next
= ((char *) external
20988 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
20992 Elf64_External_VMS_Note
*vms_external
;
20994 /* PR binutils/15191
20995 Make sure that there is enough data to read. */
20996 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
20997 if (data_remaining
< min_notesz
)
20999 warn (ngettext ("Corrupt note: only %ld byte remains, "
21000 "not enough for a full note\n",
21001 "Corrupt note: only %ld bytes remain, "
21002 "not enough for a full note\n",
21004 (long) data_remaining
);
21007 data_remaining
-= min_notesz
;
21009 vms_external
= (Elf64_External_VMS_Note
*) external
;
21010 inote
.type
= BYTE_GET (vms_external
->type
);
21011 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
21012 inote
.namedata
= vms_external
->name
;
21013 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
21014 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
21015 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21016 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
21019 /* PR 17531: file: 3443835e. */
21020 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
21021 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
21022 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
21023 || (size_t) (next
- inote
.descdata
) < inote
.descsz
21024 || ((size_t) (next
- inote
.descdata
)
21025 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
21027 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
21028 (unsigned long) ((char *) external
- (char *) pnotes
));
21029 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
21030 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
21034 external
= (Elf_External_Note
*) next
;
21036 /* Verify that name is null terminated. It appears that at least
21037 one version of Linux (RedHat 6.0) generates corefiles that don't
21038 comply with the ELF spec by failing to include the null byte in
21040 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
21042 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
21044 temp
= (char *) malloc (inote
.namesz
+ 1);
21047 error (_("Out of memory allocating space for inote name\n"));
21052 memcpy (temp
, inote
.namedata
, inote
.namesz
);
21053 inote
.namedata
= temp
;
21055 inote
.namedata
[inote
.namesz
] = 0;
21058 if (! process_note (& inote
, filedata
))
21071 process_corefile_note_segments (Filedata
* filedata
)
21073 Elf_Internal_Phdr
*segment
;
21077 if (! get_program_headers (filedata
))
21080 for (i
= 0, segment
= filedata
->program_headers
;
21081 i
< filedata
->file_header
.e_phnum
;
21084 if (segment
->p_type
== PT_NOTE
)
21085 if (! process_notes_at (filedata
, NULL
,
21086 (bfd_vma
) segment
->p_offset
,
21087 (bfd_vma
) segment
->p_filesz
,
21088 (bfd_vma
) segment
->p_align
))
21096 process_v850_notes (Filedata
* filedata
, bfd_vma offset
, bfd_vma length
)
21098 Elf_External_Note
* pnotes
;
21099 Elf_External_Note
* external
;
21106 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
21108 if (pnotes
== NULL
)
21112 end
= (char*) pnotes
+ length
;
21114 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
21115 (unsigned long) offset
, (unsigned long) length
);
21117 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
21119 Elf_External_Note
* next
;
21120 Elf_Internal_Note inote
;
21122 inote
.type
= BYTE_GET (external
->type
);
21123 inote
.namesz
= BYTE_GET (external
->namesz
);
21124 inote
.namedata
= external
->name
;
21125 inote
.descsz
= BYTE_GET (external
->descsz
);
21126 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
21127 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21129 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
21131 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
21132 inote
.descdata
= inote
.namedata
;
21136 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
21138 if ( ((char *) next
> end
)
21139 || ((char *) next
< (char *) pnotes
))
21141 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
21142 (unsigned long) ((char *) external
- (char *) pnotes
));
21143 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
21144 inote
.type
, inote
.namesz
, inote
.descsz
);
21150 /* Prevent out-of-bounds indexing. */
21151 if ( inote
.namedata
+ inote
.namesz
> end
21152 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
21154 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
21155 (unsigned long) ((char *) external
- (char *) pnotes
));
21156 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
21157 inote
.type
, inote
.namesz
, inote
.descsz
);
21161 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
21163 if (! print_v850_note (& inote
))
21166 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
21167 inote
.namesz
, inote
.descsz
);
21177 process_note_sections (Filedata
* filedata
)
21179 Elf_Internal_Shdr
*section
;
21181 unsigned int n
= 0;
21184 for (i
= 0, section
= filedata
->section_headers
;
21185 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
21188 if (section
->sh_type
== SHT_NOTE
)
21190 if (! process_notes_at (filedata
, section
,
21191 (bfd_vma
) section
->sh_offset
,
21192 (bfd_vma
) section
->sh_size
,
21193 (bfd_vma
) section
->sh_addralign
))
21198 if (( filedata
->file_header
.e_machine
== EM_V800
21199 || filedata
->file_header
.e_machine
== EM_V850
21200 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
21201 && section
->sh_type
== SHT_RENESAS_INFO
)
21203 if (! process_v850_notes (filedata
,
21204 (bfd_vma
) section
->sh_offset
,
21205 (bfd_vma
) section
->sh_size
))
21212 /* Try processing NOTE segments instead. */
21213 return process_corefile_note_segments (filedata
);
21219 process_notes (Filedata
* filedata
)
21221 /* If we have not been asked to display the notes then do nothing. */
21225 if (filedata
->file_header
.e_type
!= ET_CORE
)
21226 return process_note_sections (filedata
);
21228 /* No program headers means no NOTE segment. */
21229 if (filedata
->file_header
.e_phnum
> 0)
21230 return process_corefile_note_segments (filedata
);
21232 if (filedata
->is_separate
)
21233 printf (_("No notes found in linked file '%s'.\n"),
21234 filedata
->file_name
);
21236 printf (_("No notes found file.\n"));
21241 static unsigned char *
21242 display_public_gnu_attributes (unsigned char * start
,
21243 const unsigned char * const end
)
21245 printf (_(" Unknown GNU attribute: %s\n"), start
);
21247 start
+= strnlen ((char *) start
, end
- start
);
21248 display_raw_attribute (start
, end
);
21250 return (unsigned char *) end
;
21253 static unsigned char *
21254 display_generic_attribute (unsigned char * start
,
21256 const unsigned char * const end
)
21259 return (unsigned char *) end
;
21261 return display_tag_value (tag
, start
, end
);
21265 process_arch_specific (Filedata
* filedata
)
21270 switch (filedata
->file_header
.e_machine
)
21273 case EM_ARC_COMPACT
:
21274 case EM_ARC_COMPACT2
:
21275 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
21276 display_arc_attribute
,
21277 display_generic_attribute
);
21279 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
21280 display_arm_attribute
,
21281 display_generic_attribute
);
21284 case EM_MIPS_RS3_LE
:
21285 return process_mips_specific (filedata
);
21288 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
21289 display_msp430_attribute
,
21290 display_msp430_gnu_attribute
);
21293 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
21294 display_riscv_attribute
,
21295 display_generic_attribute
);
21298 return process_nds32_specific (filedata
);
21301 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21302 display_m68k_gnu_attribute
);
21306 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21307 display_power_gnu_attribute
);
21311 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21312 display_s390_gnu_attribute
);
21315 case EM_SPARC32PLUS
:
21317 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21318 display_sparc_gnu_attribute
);
21321 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
21322 display_tic6x_attribute
,
21323 display_generic_attribute
);
21326 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
21327 display_csky_attribute
, NULL
);
21330 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
21331 display_public_gnu_attributes
,
21332 display_generic_attribute
);
21337 get_file_header (Filedata
* filedata
)
21339 /* Read in the identity array. */
21340 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
21343 /* Determine how to read the rest of the header. */
21344 switch (filedata
->file_header
.e_ident
[EI_DATA
])
21349 byte_get
= byte_get_little_endian
;
21350 byte_put
= byte_put_little_endian
;
21353 byte_get
= byte_get_big_endian
;
21354 byte_put
= byte_put_big_endian
;
21358 /* For now we only support 32 bit and 64 bit ELF files. */
21359 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
21361 /* Read in the rest of the header. */
21364 Elf32_External_Ehdr ehdr32
;
21366 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
21369 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
21370 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
21371 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
21372 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
21373 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
21374 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
21375 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
21376 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
21377 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
21378 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
21379 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
21380 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
21381 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
21385 Elf64_External_Ehdr ehdr64
;
21387 /* If we have been compiled with sizeof (bfd_vma) == 4, then
21388 we will not be able to cope with the 64bit data found in
21389 64 ELF files. Detect this now and abort before we start
21390 overwriting things. */
21391 if (sizeof (bfd_vma
) < 8)
21393 error (_("This instance of readelf has been built without support for a\n\
21394 64 bit data type and so it cannot read 64 bit ELF files.\n"));
21398 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
21401 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
21402 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
21403 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
21404 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
21405 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
21406 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
21407 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
21408 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
21409 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
21410 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
21411 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
21412 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
21413 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
21420 free_filedata (Filedata
*filedata
)
21422 free (filedata
->program_interpreter
);
21423 free (filedata
->program_headers
);
21424 free (filedata
->section_headers
);
21425 free (filedata
->string_table
);
21426 free (filedata
->dump
.dump_sects
);
21427 free (filedata
->dynamic_strings
);
21428 free (filedata
->dynamic_symbols
);
21429 free (filedata
->dynamic_syminfo
);
21430 free (filedata
->dynamic_section
);
21432 while (filedata
->symtab_shndx_list
!= NULL
)
21434 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
21435 free (filedata
->symtab_shndx_list
);
21436 filedata
->symtab_shndx_list
= next
;
21439 free (filedata
->section_headers_groups
);
21441 if (filedata
->section_groups
)
21444 struct group_list
* g
;
21445 struct group_list
* next
;
21447 for (i
= 0; i
< filedata
->group_count
; i
++)
21449 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
21456 free (filedata
->section_groups
);
21458 memset (&filedata
->section_headers
, 0,
21459 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
21463 close_file (Filedata
* filedata
)
21467 if (filedata
->handle
)
21468 fclose (filedata
->handle
);
21474 close_debug_file (void * data
)
21476 free_filedata ((Filedata
*) data
);
21477 close_file ((Filedata
*) data
);
21481 open_file (const char * pathname
, bool is_separate
)
21483 struct stat statbuf
;
21484 Filedata
* filedata
= NULL
;
21486 if (stat (pathname
, & statbuf
) < 0
21487 || ! S_ISREG (statbuf
.st_mode
))
21490 filedata
= calloc (1, sizeof * filedata
);
21491 if (filedata
== NULL
)
21494 filedata
->handle
= fopen (pathname
, "rb");
21495 if (filedata
->handle
== NULL
)
21498 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
21499 filedata
->file_name
= pathname
;
21500 filedata
->is_separate
= is_separate
;
21502 if (! get_file_header (filedata
))
21505 if (!get_section_headers (filedata
, false))
21513 if (filedata
->handle
)
21514 fclose (filedata
->handle
);
21521 open_debug_file (const char * pathname
)
21523 return open_file (pathname
, true);
21527 initialise_dump_sects (Filedata
* filedata
)
21529 /* Initialise the dump_sects array from the cmdline_dump_sects array.
21530 Note we do this even if cmdline_dump_sects is empty because we
21531 must make sure that the dump_sets array is zeroed out before each
21532 object file is processed. */
21533 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
21534 memset (filedata
->dump
.dump_sects
, 0,
21535 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
21537 if (cmdline
.num_dump_sects
> 0)
21539 if (filedata
->dump
.num_dump_sects
== 0)
21540 /* A sneaky way of allocating the dump_sects array. */
21541 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
21543 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
21544 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
21545 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
21549 /* Process one ELF object file according to the command line options.
21550 This file may actually be stored in an archive. The file is
21551 positioned at the start of the ELF object. Returns TRUE if no
21552 problems were encountered, FALSE otherwise. */
21555 process_object (Filedata
* filedata
)
21557 bool have_separate_files
;
21561 if (! get_file_header (filedata
))
21563 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
21567 /* Initialise per file variables. */
21568 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
21569 filedata
->version_info
[i
] = 0;
21571 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
21572 filedata
->dynamic_info
[i
] = 0;
21573 filedata
->dynamic_info_DT_GNU_HASH
= 0;
21574 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
21576 /* Process the file. */
21578 printf (_("\nFile: %s\n"), filedata
->file_name
);
21580 initialise_dump_sects (filedata
);
21582 /* There may be some extensions in the first section header. Don't
21583 bomb if we can't read it. */
21584 get_section_headers (filedata
, true);
21586 if (! process_file_header (filedata
))
21592 /* Throw away the single section header read above, so that we
21593 re-read the entire set. */
21594 free (filedata
->section_headers
);
21595 filedata
->section_headers
= NULL
;
21597 if (! process_section_headers (filedata
))
21599 /* Without loaded section headers we cannot process lots of things. */
21600 do_unwind
= do_version
= do_dump
= do_arch
= false;
21602 if (! do_using_dynamic
)
21603 do_syms
= do_dyn_syms
= do_reloc
= false;
21606 if (! process_section_groups (filedata
))
21607 /* Without loaded section groups we cannot process unwind. */
21610 process_program_headers (filedata
);
21612 res
= process_dynamic_section (filedata
);
21614 if (! process_relocs (filedata
))
21617 if (! process_unwind (filedata
))
21620 if (! process_symbol_table (filedata
))
21623 if (! process_lto_symbol_tables (filedata
))
21626 if (! process_syminfo (filedata
))
21629 if (! process_version_sections (filedata
))
21632 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
)
21633 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
21635 have_separate_files
= false;
21637 if (! process_section_contents (filedata
))
21640 if (have_separate_files
)
21644 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
21646 initialise_dump_sects (d
->handle
);
21648 if (process_links
&& ! process_file_header (d
->handle
))
21650 else if (! process_section_headers (d
->handle
))
21652 else if (! process_section_contents (d
->handle
))
21654 else if (process_links
)
21656 if (! process_section_groups (d
->handle
))
21658 process_program_headers (d
->handle
);
21659 if (! process_dynamic_section (d
->handle
))
21661 if (! process_relocs (d
->handle
))
21663 if (! process_unwind (d
->handle
))
21665 if (! process_symbol_table (d
->handle
))
21667 if (! process_lto_symbol_tables (d
->handle
))
21669 if (! process_syminfo (d
->handle
))
21671 if (! process_version_sections (d
->handle
))
21673 if (! process_notes (d
->handle
))
21678 /* The file handles are closed by the call to free_debug_memory() below. */
21681 if (! process_notes (filedata
))
21684 if (! process_gnu_liblist (filedata
))
21687 if (! process_arch_specific (filedata
))
21691 free_filedata (filedata
);
21693 free_debug_memory ();
21698 /* Process an ELF archive.
21699 On entry the file is positioned just after the ARMAG string.
21700 Returns TRUE upon success, FALSE otherwise. */
21703 process_archive (Filedata
* filedata
, bool is_thin_archive
)
21705 struct archive_info arch
;
21706 struct archive_info nested_arch
;
21712 /* The ARCH structure is used to hold information about this archive. */
21713 arch
.file_name
= NULL
;
21715 arch
.index_array
= NULL
;
21716 arch
.sym_table
= NULL
;
21717 arch
.longnames
= NULL
;
21719 /* The NESTED_ARCH structure is used as a single-item cache of information
21720 about a nested archive (when members of a thin archive reside within
21721 another regular archive file). */
21722 nested_arch
.file_name
= NULL
;
21723 nested_arch
.file
= NULL
;
21724 nested_arch
.index_array
= NULL
;
21725 nested_arch
.sym_table
= NULL
;
21726 nested_arch
.longnames
= NULL
;
21728 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
21729 filedata
->file_size
, is_thin_archive
,
21730 do_archive_index
) != 0)
21736 if (do_archive_index
)
21738 if (arch
.sym_table
== NULL
)
21739 error (_("%s: unable to dump the index as none was found\n"),
21740 filedata
->file_name
);
21743 unsigned long i
, l
;
21744 unsigned long current_pos
;
21746 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
21747 "in the symbol table)\n"),
21748 filedata
->file_name
, (unsigned long) arch
.index_num
,
21751 current_pos
= ftell (filedata
->handle
);
21753 for (i
= l
= 0; i
< arch
.index_num
; i
++)
21756 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
21759 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
21762 if (member_name
!= NULL
)
21764 char * qualified_name
21765 = make_qualified_name (&arch
, &nested_arch
,
21768 if (qualified_name
!= NULL
)
21770 printf (_("Contents of binary %s at offset "),
21772 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
21774 free (qualified_name
);
21776 free (member_name
);
21780 if (l
>= arch
.sym_size
)
21782 error (_("%s: end of the symbol table reached "
21783 "before the end of the index\n"),
21784 filedata
->file_name
);
21788 /* PR 17531: file: 0b6630b2. */
21789 printf ("\t%.*s\n",
21790 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
21791 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
21794 if (arch
.uses_64bit_indices
)
21799 if (l
< arch
.sym_size
)
21801 error (ngettext ("%s: %ld byte remains in the symbol table, "
21802 "but without corresponding entries in "
21803 "the index table\n",
21804 "%s: %ld bytes remain in the symbol table, "
21805 "but without corresponding entries in "
21806 "the index table\n",
21807 arch
.sym_size
- l
),
21808 filedata
->file_name
, arch
.sym_size
- l
);
21812 if (fseek (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
21814 error (_("%s: failed to seek back to start of object files "
21815 "in the archive\n"),
21816 filedata
->file_name
);
21822 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
21823 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
21824 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
21825 && !do_section_groups
&& !do_dyn_syms
)
21827 ret
= true; /* Archive index only. */
21836 char * qualified_name
;
21838 /* Read the next archive header. */
21839 if (fseek (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
21841 error (_("%s: failed to seek to next archive header\n"),
21846 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
21847 if (got
!= sizeof arch
.arhdr
)
21851 /* PR 24049 - we cannot use filedata->file_name as this will
21852 have already been freed. */
21853 error (_("%s: failed to read archive header\n"), arch
.file_name
);
21858 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
21860 error (_("%s: did not find a valid archive header\n"),
21866 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
21868 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
21870 name
= get_archive_member_name (&arch
, &nested_arch
);
21873 error (_("%s: bad archive file name\n"), arch
.file_name
);
21877 namelen
= strlen (name
);
21879 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
21880 if (qualified_name
== NULL
)
21882 error (_("%s: bad archive file name\n"), arch
.file_name
);
21888 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
21890 /* This is a proxy for an external member of a thin archive. */
21891 Filedata
* member_filedata
;
21892 char * member_file_name
= adjust_relative_path
21893 (filedata
->file_name
, name
, namelen
);
21896 if (member_file_name
== NULL
)
21898 free (qualified_name
);
21903 member_filedata
= open_file (member_file_name
, false);
21904 if (member_filedata
== NULL
)
21906 error (_("Input file '%s' is not readable.\n"), member_file_name
);
21907 free (member_file_name
);
21908 free (qualified_name
);
21913 filedata
->archive_file_offset
= arch
.nested_member_origin
;
21914 member_filedata
->file_name
= qualified_name
;
21916 /* The call to process_object() expects the file to be at the beginning. */
21917 rewind (member_filedata
->handle
);
21919 if (! process_object (member_filedata
))
21922 close_file (member_filedata
);
21923 free (member_file_name
);
21925 else if (is_thin_archive
)
21927 Filedata thin_filedata
;
21929 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
21931 /* PR 15140: Allow for corrupt thin archives. */
21932 if (nested_arch
.file
== NULL
)
21934 error (_("%s: contains corrupt thin archive: %s\n"),
21935 qualified_name
, name
);
21936 free (qualified_name
);
21943 /* This is a proxy for a member of a nested archive. */
21944 filedata
->archive_file_offset
21945 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
21947 /* The nested archive file will have been opened and setup by
21948 get_archive_member_name. */
21949 if (fseek (nested_arch
.file
, filedata
->archive_file_offset
,
21952 error (_("%s: failed to seek to archive member.\n"),
21953 nested_arch
.file_name
);
21954 free (qualified_name
);
21959 thin_filedata
.handle
= nested_arch
.file
;
21960 thin_filedata
.file_name
= qualified_name
;
21962 if (! process_object (& thin_filedata
))
21968 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
21969 filedata
->file_name
= qualified_name
;
21970 if (! process_object (filedata
))
21972 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
21973 /* Stop looping with "negative" archive_file_size. */
21974 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
21975 arch
.next_arhdr_offset
= -1ul;
21978 free (qualified_name
);
21982 if (nested_arch
.file
!= NULL
)
21983 fclose (nested_arch
.file
);
21984 release_archive (&nested_arch
);
21985 release_archive (&arch
);
21991 process_file (char * file_name
)
21993 Filedata
* filedata
= NULL
;
21994 struct stat statbuf
;
21995 char armag
[SARMAG
];
21998 if (stat (file_name
, &statbuf
) < 0)
22000 if (errno
== ENOENT
)
22001 error (_("'%s': No such file\n"), file_name
);
22003 error (_("Could not locate '%s'. System error message: %s\n"),
22004 file_name
, strerror (errno
));
22008 if (! S_ISREG (statbuf
.st_mode
))
22010 error (_("'%s' is not an ordinary file\n"), file_name
);
22014 filedata
= calloc (1, sizeof * filedata
);
22015 if (filedata
== NULL
)
22017 error (_("Out of memory allocating file data structure\n"));
22021 filedata
->file_name
= file_name
;
22022 filedata
->handle
= fopen (file_name
, "rb");
22023 if (filedata
->handle
== NULL
)
22025 error (_("Input file '%s' is not readable.\n"), file_name
);
22030 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
22032 error (_("%s: Failed to read file's magic number\n"), file_name
);
22033 fclose (filedata
->handle
);
22038 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
22039 filedata
->is_separate
= false;
22041 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
22043 if (! process_archive (filedata
, false))
22046 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
22048 if ( ! process_archive (filedata
, true))
22053 if (do_archive_index
&& !check_all
)
22054 error (_("File %s is not an archive so its index cannot be displayed.\n"),
22057 rewind (filedata
->handle
);
22058 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
22060 if (! process_object (filedata
))
22064 fclose (filedata
->handle
);
22065 free (filedata
->section_headers
);
22066 free (filedata
->program_headers
);
22067 free (filedata
->string_table
);
22068 free (filedata
->dump
.dump_sects
);
22071 free (ba_cache
.strtab
);
22072 ba_cache
.strtab
= NULL
;
22073 free (ba_cache
.symtab
);
22074 ba_cache
.symtab
= NULL
;
22075 ba_cache
.filedata
= NULL
;
22080 #ifdef SUPPORT_DISASSEMBLY
22081 /* Needed by the i386 disassembler. For extra credit, someone could
22082 fix this so that we insert symbolic addresses here, esp for GOT/PLT
22086 print_address (unsigned int addr
, FILE * outfile
)
22088 fprintf (outfile
,"0x%8.8x", addr
);
22091 /* Needed by the i386 disassembler. */
22094 db_task_printsym (unsigned int addr
)
22096 print_address (addr
, stderr
);
22101 main (int argc
, char ** argv
)
22105 #ifdef HAVE_LC_MESSAGES
22106 setlocale (LC_MESSAGES
, "");
22108 setlocale (LC_CTYPE
, "");
22109 bindtextdomain (PACKAGE
, LOCALEDIR
);
22110 textdomain (PACKAGE
);
22112 expandargv (&argc
, &argv
);
22114 parse_args (& cmdline
, argc
, argv
);
22116 if (optind
< (argc
- 1))
22117 /* When displaying information for more than one file,
22118 prefix the information with the file name. */
22120 else if (optind
>= argc
)
22122 /* Ensure that the warning is always displayed. */
22125 warn (_("Nothing to do.\n"));
22130 while (optind
< argc
)
22131 if (! process_file (argv
[optind
++]))
22134 free (cmdline
.dump_sects
);
22136 free (dump_ctf_symtab_name
);
22137 free (dump_ctf_strtab_name
);
22138 free (dump_ctf_parent_name
);
22140 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;