1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2023 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. */
52 #if defined HAVE_MSGPACK
56 /* Define BFD64 here, even if our default architecture is 32 bit ELF
57 as this will allow us to read in and parse 64bit and 32bit ELF files. */
63 #include "demanguse.h"
66 #include "sframe-api.h"
69 #include "elf/common.h"
70 #include "elf/external.h"
71 #include "elf/internal.h"
74 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
75 we can obtain the H8 reloc numbers. We need these for the
76 get_reloc_size() function. We include h8.h again after defining
77 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
82 /* Undo the effects of #including reloc-macros.h. */
84 #undef START_RELOC_NUMBERS
88 #undef END_RELOC_NUMBERS
89 #undef _RELOC_MACROS_H
91 /* The following headers use the elf/reloc-macros.h file to
92 automatically generate relocation recognition functions
93 such as elf_mips_reloc_type() */
95 #define RELOC_MACROS_GEN_FUNC
97 #include "elf/aarch64.h"
98 #include "elf/alpha.h"
99 #include "elf/amdgpu.h"
103 #include "elf/bfin.h"
104 #include "elf/cr16.h"
105 #include "elf/cris.h"
107 #include "elf/csky.h"
108 #include "elf/d10v.h"
109 #include "elf/d30v.h"
112 #include "elf/epiphany.h"
113 #include "elf/fr30.h"
115 #include "elf/ft32.h"
117 #include "elf/hppa.h"
118 #include "elf/i386.h"
119 #include "elf/i370.h"
120 #include "elf/i860.h"
121 #include "elf/i960.h"
122 #include "elf/ia64.h"
123 #include "elf/ip2k.h"
124 #include "elf/lm32.h"
125 #include "elf/iq2000.h"
126 #include "elf/m32c.h"
127 #include "elf/m32r.h"
128 #include "elf/m68k.h"
129 #include "elf/m68hc11.h"
130 #include "elf/s12z.h"
131 #include "elf/mcore.h"
133 #include "elf/metag.h"
134 #include "elf/microblaze.h"
135 #include "elf/mips.h"
136 #include "elf/mmix.h"
137 #include "elf/mn10200.h"
138 #include "elf/mn10300.h"
139 #include "elf/moxie.h"
141 #include "elf/msp430.h"
142 #include "elf/nds32.h"
144 #include "elf/nios2.h"
145 #include "elf/or1k.h"
148 #include "elf/ppc64.h"
150 #include "elf/riscv.h"
151 #include "elf/rl78.h"
153 #include "elf/s390.h"
154 #include "elf/score.h"
156 #include "elf/sparc.h"
158 #include "elf/tic6x.h"
159 #include "elf/tilegx.h"
160 #include "elf/tilepro.h"
161 #include "elf/v850.h"
163 #include "elf/visium.h"
164 #include "elf/wasm32.h"
165 #include "elf/x86-64.h"
166 #include "elf/xgate.h"
167 #include "elf/xstormy16.h"
168 #include "elf/xtensa.h"
170 #include "elf/loongarch.h"
173 #include "libiberty.h"
174 #include "safe-ctype.h"
175 #include "filenames.h"
178 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
181 typedef struct elf_section_list
183 Elf_Internal_Shdr
* hdr
;
184 struct elf_section_list
* next
;
187 /* Flag bits indicating particular types of dump. */
188 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
189 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
190 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
191 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
192 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
193 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
194 #define SFRAME_DUMP (1 << 6) /* The --sframe command line switch. */
196 typedef unsigned char dump_type
;
198 /* A linked list of the section names for which dumps were requested. */
199 struct dump_list_entry
203 struct dump_list_entry
* next
;
206 /* A dynamic array of flags indicating for which sections a dump
207 has been requested via command line switches. */
210 dump_type
* dump_sects
;
211 unsigned int num_dump_sects
;
214 static struct dump_data cmdline
;
216 static struct dump_list_entry
* dump_sects_byname
;
218 char * program_name
= "readelf";
220 static bool show_name
= false;
221 static bool do_dynamic
= false;
222 static bool do_syms
= false;
223 static bool do_dyn_syms
= false;
224 static bool do_lto_syms
= false;
225 static bool do_reloc
= false;
226 static bool do_sections
= false;
227 static bool do_section_groups
= false;
228 static bool do_section_details
= false;
229 static bool do_segments
= false;
230 static bool do_unwind
= false;
231 static bool do_using_dynamic
= false;
232 static bool do_header
= false;
233 static bool do_dump
= false;
234 static bool do_version
= false;
235 static bool do_histogram
= false;
236 static bool do_debugging
= false;
237 static bool do_ctf
= false;
238 static bool do_sframe
= false;
239 static bool do_arch
= false;
240 static bool do_notes
= false;
241 static bool do_archive_index
= false;
242 static bool check_all
= false;
243 static bool is_32bit_elf
= false;
244 static bool decompress_dumps
= false;
245 static bool do_not_show_symbol_truncation
= false;
246 static bool do_demangle
= false; /* Pretty print C++ symbol names. */
247 static bool process_links
= false;
248 static bool dump_any_debugging
= false;
249 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
250 static int sym_base
= 0;
252 static char *dump_ctf_parent_name
;
253 static char *dump_ctf_symtab_name
;
254 static char *dump_ctf_strtab_name
;
258 struct group_list
* next
;
259 unsigned int section_index
;
264 struct group_list
* root
;
265 unsigned int group_index
;
268 typedef struct filedata
270 const char * file_name
;
274 Elf_Internal_Ehdr file_header
;
275 uint64_t archive_file_offset
;
276 uint64_t archive_file_size
;
277 /* Everything below this point is cleared out by free_filedata. */
278 Elf_Internal_Shdr
* section_headers
;
279 Elf_Internal_Phdr
* program_headers
;
281 uint64_t string_table_length
;
282 uint64_t dynamic_addr
;
283 uint64_t dynamic_size
;
284 uint64_t dynamic_nent
;
285 Elf_Internal_Dyn
* dynamic_section
;
286 Elf_Internal_Shdr
* dynamic_strtab_section
;
287 char * dynamic_strings
;
288 uint64_t dynamic_strings_length
;
289 Elf_Internal_Shdr
* dynamic_symtab_section
;
290 uint64_t num_dynamic_syms
;
291 Elf_Internal_Sym
* dynamic_symbols
;
292 uint64_t version_info
[16];
293 unsigned int dynamic_syminfo_nent
;
294 Elf_Internal_Syminfo
* dynamic_syminfo
;
295 uint64_t dynamic_syminfo_offset
;
300 uint64_t ngnubuckets
;
302 uint64_t * gnubuckets
;
303 uint64_t * gnuchains
;
306 char * program_interpreter
;
307 uint64_t dynamic_info
[DT_ENCODING
];
308 uint64_t dynamic_info_DT_GNU_HASH
;
309 uint64_t dynamic_info_DT_MIPS_XHASH
;
310 elf_section_list
* symtab_shndx_list
;
312 struct group
* section_groups
;
313 struct group
** section_headers_groups
;
314 /* A dynamic array of flags indicating for which sections a dump of
315 some kind has been requested. It is reset on a per-object file
316 basis and then initialised from the cmdline_dump_sects array,
317 the results of interpreting the -w switch, and the
318 dump_sects_byname list. */
319 struct dump_data dump
;
322 /* How to print a vma value. */
323 typedef enum print_mode
340 typedef enum unicode_display_type
348 } unicode_display_type
;
350 static unicode_display_type unicode_display
= unicode_default
;
360 /* Versioned symbol info. */
361 enum versioned_symbol_info
369 fseek64 (FILE *stream
, int64_t offset
, int whence
)
371 #if defined (HAVE_FSEEKO64)
378 return fseeko64 (stream
, o
, whence
);
379 #elif defined (HAVE_FSEEKO)
386 return fseeko (stream
, o
, whence
);
394 return fseek (stream
, o
, whence
);
398 static const char * get_symbol_version_string
399 (Filedata
*, bool, const char *, size_t, unsigned,
400 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
404 static inline const char *
405 section_name (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
407 return filedata
->string_table
+ hdr
->sh_name
;
411 section_name_valid (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
414 && filedata
->string_table
!= NULL
415 && hdr
->sh_name
< filedata
->string_table_length
);
418 static inline const char *
419 section_name_print (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
423 if (filedata
->string_table
== NULL
)
424 return _("<no-strings>");
425 if (hdr
->sh_name
>= filedata
->string_table_length
)
426 return _("<corrupt>");
427 return section_name (filedata
, hdr
);
430 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
433 valid_symbol_name (const char *strtab
, size_t strtab_size
, uint64_t offset
)
435 return strtab
!= NULL
&& offset
< strtab_size
;
439 valid_dynamic_name (const Filedata
*filedata
, uint64_t offset
)
441 return valid_symbol_name (filedata
->dynamic_strings
,
442 filedata
->dynamic_strings_length
, offset
);
445 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
446 already been called and verified that the string exists. */
447 static inline const char *
448 get_dynamic_name (const Filedata
*filedata
, size_t offset
)
450 return filedata
->dynamic_strings
+ offset
;
453 #define REMOVE_ARCH_BITS(ADDR) \
456 if (filedata->file_header.e_machine == EM_ARM) \
461 /* Get the correct GNU hash section name. */
462 #define GNU_HASH_SECTION_NAME(filedata) \
463 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
465 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
466 OFFSET + the offset of the current archive member, if we are examining an
467 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
468 allocate a buffer using malloc and fill that. In either case return the
469 pointer to the start of the retrieved data or NULL if something went wrong.
470 If something does go wrong and REASON is not NULL then emit an error
471 message using REASON as part of the context. */
482 uint64_t amt
= size
* nmemb
;
484 if (size
== 0 || nmemb
== 0)
487 /* If size_t is smaller than uint64_t, eg because you are building
488 on a 32-bit host, then make sure that when the sizes are cast to
489 size_t no information is lost. */
490 if ((size_t) size
!= size
491 || (size_t) nmemb
!= nmemb
492 || (size_t) amt
!= amt
493 || amt
/ size
!= nmemb
494 || (size_t) amt
+ 1 == 0)
497 error (_("Size overflow prevents reading %" PRIu64
498 " elements of size %" PRIu64
" for %s\n"),
499 nmemb
, size
, reason
);
503 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
504 attempting to allocate memory when the read is bound to fail. */
505 if (filedata
->archive_file_offset
> filedata
->file_size
506 || offset
> filedata
->file_size
- filedata
->archive_file_offset
507 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
510 error (_("Reading %" PRIu64
" bytes extends past end of file for %s\n"),
515 if (fseek64 (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
519 error (_("Unable to seek to %#" PRIx64
" for %s\n"),
520 filedata
->archive_file_offset
+ offset
, reason
);
527 /* + 1 so that we can '\0' terminate invalid string table sections. */
528 mvar
= malloc ((size_t) amt
+ 1);
533 error (_("Out of memory allocating %" PRIu64
" bytes for %s\n"),
538 ((char *) mvar
)[amt
] = '\0';
541 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
544 error (_("Unable to read in %" PRIu64
" bytes of %s\n"),
554 /* Print a VMA value in the MODE specified.
555 Returns the number of characters displayed. */
558 print_vma (uint64_t vma
, print_mode mode
)
569 return nc
+ printf ("%16.16" PRIx64
, vma
);
570 return nc
+ printf ("%8.8" PRIx64
, vma
);
574 return printf ("%5" PRId64
, vma
);
580 return nc
+ printf ("%" PRIx64
, vma
);
586 return nc
+ printf ("%05" PRIx64
, vma
);
589 return printf ("%" PRId64
, vma
);
592 return printf ("%" PRIu64
, vma
);
595 return printf ("%5" PRIu64
, vma
);
598 return printf ("%" PRIo64
, vma
);
601 return printf ("%5" PRIo64
, vma
);
604 /* FIXME: Report unrecognised mode ? */
610 /* Display a symbol on stdout. Handles the display of control characters and
611 multibye characters (assuming the host environment supports them).
613 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
615 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
616 abs(WIDTH) - 5 characters followed by "[...]".
618 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
619 padding as necessary.
621 Returns the number of emitted characters. */
624 print_symbol (signed int width
, const char * symbol
)
626 bool extra_padding
= false;
627 bool do_dots
= false;
628 signed int num_printed
= 0;
629 #ifdef HAVE_MBSTATE_T
632 unsigned int width_remaining
;
633 const void * alloced_symbol
= NULL
;
637 /* Keep the width positive. This helps the code below. */
639 extra_padding
= true;
645 /* Set the remaining width to a very large value.
646 This simplifies the code below. */
647 width_remaining
= INT_MAX
;
650 width_remaining
= width
;
651 if (! do_not_show_symbol_truncation
652 && (int) strlen (symbol
) > width
)
654 width_remaining
-= 5;
655 if ((int) width_remaining
< 0)
661 #ifdef HAVE_MBSTATE_T
662 /* Initialise the multibyte conversion state. */
663 memset (& state
, 0, sizeof (state
));
666 if (do_demangle
&& *symbol
)
668 const char * res
= cplus_demangle (symbol
, demangle_flags
);
671 alloced_symbol
= symbol
= res
;
674 while (width_remaining
)
677 const char c
= *symbol
++;
688 else if (ISCNTRL (c
))
690 /* Do not print control characters directly as they can affect terminal
691 settings. Such characters usually appear in the names generated
692 by the assembler for local labels. */
694 if (width_remaining
< 2)
697 printf ("^%c", c
+ 0x40);
698 width_remaining
-= 2;
703 if (width_remaining
< 5)
706 width_remaining
-= 5;
709 else if (unicode_display
!= unicode_locale
710 && unicode_display
!= unicode_default
)
712 /* Display unicode characters as something else. */
713 unsigned char bytes
[4];
726 bytes
[1] = *symbol
++;
728 if ((bytes
[1] & 0xc0) != 0x80)
731 /* Do not consume this character. It may only
732 be the first byte in the sequence that was
737 else if ((bytes
[0] & 0x20) == 0)
744 bytes
[2] = *symbol
++;
746 if ((bytes
[2] & 0xc0) != 0x80)
752 else if ((bytes
[0] & 0x10) == 0)
759 bytes
[3] = *symbol
++;
763 if ((bytes
[3] & 0xc0) != 0x80)
775 if (unicode_display
== unicode_invalid
)
778 if (unicode_display
== unicode_hex
|| ! is_utf8
)
782 if (width_remaining
< (nbytes
* 2) + 2)
785 putchar (is_utf8
? '<' : '{');
787 for (i
= 0; i
< nbytes
; i
++)
788 printf ("%02x", bytes
[i
]);
789 putchar (is_utf8
? '>' : '}');
793 if (unicode_display
== unicode_highlight
&& isatty (1))
794 printf ("\x1B[31;47m"); /* Red. */
799 if (width_remaining
< 6)
801 printf ("\\u%02x%02x",
802 (bytes
[0] & 0x1c) >> 2,
803 ((bytes
[0] & 0x03) << 6) | (bytes
[1] & 0x3f));
806 if (width_remaining
< 6)
808 printf ("\\u%02x%02x",
809 ((bytes
[0] & 0x0f) << 4) | ((bytes
[1] & 0x3c) >> 2),
810 ((bytes
[1] & 0x03) << 6) | (bytes
[2] & 0x3f));
813 if (width_remaining
< 8)
815 printf ("\\u%02x%02x%02x",
816 ((bytes
[0] & 0x07) << 6) | ((bytes
[1] & 0x3c) >> 2),
817 ((bytes
[1] & 0x03) << 6) | ((bytes
[2] & 0x3c) >> 2),
818 ((bytes
[2] & 0x03) << 6) | (bytes
[3] & 0x3f));
826 if (unicode_display
== unicode_highlight
&& isatty (1))
827 printf ("\033[0m"); /* Default colour. */
830 if (bytes
[nbytes
- 1] == 0)
835 #ifdef HAVE_MBSTATE_T
838 /* Let printf do the hard work of displaying multibyte characters. */
839 printf ("%.1s", symbol
- 1);
843 #ifdef HAVE_MBSTATE_T
844 /* Try to find out how many bytes made up the character that was
845 just printed. Advance the symbol pointer past the bytes that
847 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
851 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
857 num_printed
+= printf ("[...]");
859 if (extra_padding
&& num_printed
< width
)
861 /* Fill in the remaining spaces. */
862 printf ("%-*s", width
- num_printed
, " ");
866 free ((void *) alloced_symbol
);
870 /* Returns a pointer to a static buffer containing a printable version of
871 the given section's name. Like print_symbol, except that it does not try
872 to print multibyte characters, it just interprets them as hex values. */
875 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
877 #define MAX_PRINT_SEC_NAME_LEN 256
878 static char sec_name_buf
[MAX_PRINT_SEC_NAME_LEN
+ 1];
879 const char * name
= section_name_print (filedata
, sec
);
880 char * buf
= sec_name_buf
;
882 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
884 while ((c
= * name
++) != 0)
895 else if (ISPRINT (c
))
902 static char hex
[17] = "0123456789ABCDEF";
907 * buf
++ = hex
[(c
& 0xf0) >> 4];
908 * buf
++ = hex
[c
& 0x0f];
922 printable_section_name_from_index (Filedata
*filedata
, size_t ndx
)
924 if (ndx
>= filedata
->file_header
.e_shnum
)
925 return _("<corrupt>");
927 return printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
930 /* Return a pointer to section NAME, or NULL if no such section exists. */
932 static Elf_Internal_Shdr
*
933 find_section (Filedata
* filedata
, const char * name
)
937 if (filedata
->section_headers
== NULL
)
940 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
941 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
942 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
944 return filedata
->section_headers
+ i
;
949 /* Return a pointer to a section containing ADDR, or NULL if no such
952 static Elf_Internal_Shdr
*
953 find_section_by_address (Filedata
* filedata
, uint64_t addr
)
957 if (filedata
->section_headers
== NULL
)
960 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
962 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
964 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
971 static Elf_Internal_Shdr
*
972 find_section_by_type (Filedata
* filedata
, unsigned int type
)
976 if (filedata
->section_headers
== NULL
)
979 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
981 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
983 if (sec
->sh_type
== type
)
990 /* Return a pointer to section NAME, or NULL if no such section exists,
991 restricted to the list of sections given in SET. */
993 static Elf_Internal_Shdr
*
994 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
998 if (filedata
->section_headers
== NULL
)
1003 while ((i
= *set
++) > 0)
1005 /* See PR 21156 for a reproducer. */
1006 if (i
>= filedata
->file_header
.e_shnum
)
1007 continue; /* FIXME: Should we issue an error message ? */
1009 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
1010 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
1012 return filedata
->section_headers
+ i
;
1016 return find_section (filedata
, name
);
1019 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
1020 This OS has so many departures from the ELF standard that we test it at
1024 is_ia64_vms (Filedata
* filedata
)
1026 return filedata
->file_header
.e_machine
== EM_IA_64
1027 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
1030 /* Guess the relocation size commonly used by the specific machines. */
1033 guess_is_rela (unsigned int e_machine
)
1037 /* Targets that use REL relocations. */
1043 case EM_CYGNUS_D10V
:
1046 case EM_MIPS_RS3_LE
:
1047 case EM_CYGNUS_M32R
:
1054 /* Targets that use RELA relocations. */
1058 case EM_ADAPTEVA_EPIPHANY
:
1060 case EM_ALTERA_NIOS2
:
1062 case EM_ARC_COMPACT
:
1063 case EM_ARC_COMPACT2
:
1072 case EM_CYGNUS_D30V
:
1075 case EM_CYGNUS_FR30
:
1084 case EM_LATTICEMICO32
:
1093 case EM_CYGNUS_MN10200
:
1095 case EM_CYGNUS_MN10300
:
1113 case EM_SPARC32PLUS
:
1121 case EM_CYGNUS_V850
:
1131 case EM_MICROBLAZE_OLD
:
1132 case EM_WEBASSEMBLY
:
1153 warn (_("Don't know about relocations on this machine architecture\n"));
1158 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1159 Returns TRUE upon success, FALSE otherwise. If successful then a
1160 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
1161 and the number of relocs loaded is placed in *NRELASP. It is the caller's
1162 responsibility to free the allocated buffer. */
1165 slurp_rela_relocs (Filedata
*filedata
,
1166 uint64_t rel_offset
,
1168 Elf_Internal_Rela
**relasp
,
1171 Elf_Internal_Rela
* relas
;
1177 Elf32_External_Rela
* erelas
;
1179 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1180 rel_size
, _("32-bit relocation data"));
1184 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
1186 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1187 sizeof (Elf_Internal_Rela
));
1192 error (_("out of memory parsing relocs\n"));
1196 for (i
= 0; i
< nrelas
; i
++)
1198 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1199 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1200 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1207 Elf64_External_Rela
* erelas
;
1209 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1210 rel_size
, _("64-bit relocation data"));
1214 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1216 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1217 sizeof (Elf_Internal_Rela
));
1222 error (_("out of memory parsing relocs\n"));
1226 for (i
= 0; i
< nrelas
; i
++)
1228 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1229 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1230 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1232 if (filedata
->file_header
.e_machine
== EM_MIPS
1233 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1235 /* In little-endian objects, r_info isn't really a
1236 64-bit little-endian value: it has a 32-bit
1237 little-endian symbol index followed by four
1238 individual byte fields. Reorder INFO
1240 uint64_t inf
= relas
[i
].r_info
;
1241 inf
= (((inf
& 0xffffffff) << 32)
1242 | ((inf
>> 56) & 0xff)
1243 | ((inf
>> 40) & 0xff00)
1244 | ((inf
>> 24) & 0xff0000)
1245 | ((inf
>> 8) & 0xff000000));
1246 relas
[i
].r_info
= inf
;
1258 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1259 Returns TRUE upon success, FALSE otherwise. If successful then a
1260 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1261 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1262 responsibility to free the allocated buffer. */
1265 slurp_rel_relocs (Filedata
*filedata
,
1266 uint64_t rel_offset
,
1268 Elf_Internal_Rela
**relsp
,
1271 Elf_Internal_Rela
* rels
;
1277 Elf32_External_Rel
* erels
;
1279 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1280 rel_size
, _("32-bit relocation data"));
1284 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1286 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1291 error (_("out of memory parsing relocs\n"));
1295 for (i
= 0; i
< nrels
; i
++)
1297 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1298 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1299 rels
[i
].r_addend
= 0;
1306 Elf64_External_Rel
* erels
;
1308 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1309 rel_size
, _("64-bit relocation data"));
1313 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1315 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1320 error (_("out of memory parsing relocs\n"));
1324 for (i
= 0; i
< nrels
; i
++)
1326 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1327 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1328 rels
[i
].r_addend
= 0;
1330 if (filedata
->file_header
.e_machine
== EM_MIPS
1331 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1333 /* In little-endian objects, r_info isn't really a
1334 64-bit little-endian value: it has a 32-bit
1335 little-endian symbol index followed by four
1336 individual byte fields. Reorder INFO
1338 uint64_t inf
= rels
[i
].r_info
;
1339 inf
= (((inf
& 0xffffffff) << 32)
1340 | ((inf
>> 56) & 0xff)
1341 | ((inf
>> 40) & 0xff00)
1342 | ((inf
>> 24) & 0xff0000)
1343 | ((inf
>> 8) & 0xff000000));
1344 rels
[i
].r_info
= inf
;
1357 slurp_relr_relocs (Filedata
*filedata
,
1358 uint64_t relr_offset
,
1364 size_t size
= 0, nentries
, i
;
1365 uint64_t base
= 0, addr
, entry
;
1367 relrs
= get_data (NULL
, filedata
, relr_offset
, 1, relr_size
,
1368 _("RELR relocation data"));
1373 nentries
= relr_size
/ sizeof (Elf32_External_Relr
);
1375 nentries
= relr_size
/ sizeof (Elf64_External_Relr
);
1376 for (i
= 0; i
< nentries
; i
++)
1379 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1381 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1382 if ((entry
& 1) == 0)
1385 while ((entry
>>= 1) != 0)
1386 if ((entry
& 1) == 1)
1390 *relrsp
= malloc (size
* sizeof (**relrsp
));
1391 if (*relrsp
== NULL
)
1394 error (_("out of memory parsing relocs\n"));
1399 for (i
= 0; i
< nentries
; i
++)
1401 const uint64_t entry_bytes
= is_32bit_elf
? 4 : 8;
1404 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1406 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1407 if ((entry
& 1) == 0)
1409 (*relrsp
)[size
++] = entry
;
1410 base
= entry
+ entry_bytes
;
1414 for (addr
= base
; (entry
>>= 1) != 0; addr
+= entry_bytes
)
1415 if ((entry
& 1) != 0)
1416 (*relrsp
)[size
++] = addr
;
1417 base
+= entry_bytes
* (entry_bytes
* CHAR_BIT
- 1);
1426 /* Returns the reloc type extracted from the reloc info field. */
1429 get_reloc_type (Filedata
* filedata
, uint64_t reloc_info
)
1432 return ELF32_R_TYPE (reloc_info
);
1434 switch (filedata
->file_header
.e_machine
)
1437 /* Note: We assume that reloc_info has already been adjusted for us. */
1438 return ELF64_MIPS_R_TYPE (reloc_info
);
1441 return ELF64_R_TYPE_ID (reloc_info
);
1444 return ELF64_R_TYPE (reloc_info
);
1448 /* Return the symbol index extracted from the reloc info field. */
1451 get_reloc_symindex (uint64_t reloc_info
)
1453 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1457 uses_msp430x_relocs (Filedata
* filedata
)
1460 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1461 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1462 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1463 /* TI compiler uses ELFOSABI_NONE. */
1464 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1467 /* Display the contents of the relocation data found at the specified
1471 dump_relocations (Filedata
*filedata
,
1472 uint64_t rel_offset
,
1474 Elf_Internal_Sym
*symtab
,
1478 relocation_type rel_type
,
1482 Elf_Internal_Rela
* rels
;
1485 if (rel_type
== reltype_unknown
)
1486 rel_type
= guess_is_rela (filedata
->file_header
.e_machine
) ? reltype_rela
: reltype_rel
;
1488 if (rel_type
== reltype_rela
)
1490 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1493 else if (rel_type
== reltype_rel
)
1495 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1498 else if (rel_type
== reltype_relr
)
1502 = is_32bit_elf
? "%08" PRIx64
"\n" : "%016" PRIx64
"\n";
1504 if (!slurp_relr_relocs (filedata
, rel_offset
, rel_size
, &relrs
,
1508 printf (ngettext (" %" PRIu64
" offset\n",
1509 " %" PRIu64
" offsets\n", rel_size
),
1511 for (i
= 0; i
< rel_size
; i
++)
1512 printf (format
, relrs
[i
]);
1519 if (rel_type
== reltype_rela
)
1522 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1524 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1529 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1531 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1536 if (rel_type
== reltype_rela
)
1539 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1541 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1546 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1548 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1552 for (i
= 0; i
< rel_size
; i
++)
1557 uint64_t symtab_index
;
1560 offset
= rels
[i
].r_offset
;
1561 inf
= rels
[i
].r_info
;
1563 type
= get_reloc_type (filedata
, inf
);
1564 symtab_index
= get_reloc_symindex (inf
);
1568 printf ("%8.8lx %8.8lx ",
1569 (unsigned long) offset
& 0xffffffff,
1570 (unsigned long) inf
& 0xffffffff);
1575 ? "%16.16" PRIx64
" %16.16" PRIx64
" "
1576 : "%12.12" PRIx64
" %12.12" PRIx64
" ",
1580 switch (filedata
->file_header
.e_machine
)
1587 rtype
= elf_aarch64_reloc_type (type
);
1591 case EM_CYGNUS_M32R
:
1592 rtype
= elf_m32r_reloc_type (type
);
1597 rtype
= elf_i386_reloc_type (type
);
1602 rtype
= elf_m68hc11_reloc_type (type
);
1606 rtype
= elf_s12z_reloc_type (type
);
1610 rtype
= elf_m68k_reloc_type (type
);
1614 rtype
= elf_i960_reloc_type (type
);
1619 rtype
= elf_avr_reloc_type (type
);
1622 case EM_OLD_SPARCV9
:
1623 case EM_SPARC32PLUS
:
1626 rtype
= elf_sparc_reloc_type (type
);
1630 rtype
= elf_spu_reloc_type (type
);
1634 rtype
= v800_reloc_type (type
);
1637 case EM_CYGNUS_V850
:
1638 rtype
= v850_reloc_type (type
);
1642 case EM_CYGNUS_D10V
:
1643 rtype
= elf_d10v_reloc_type (type
);
1647 case EM_CYGNUS_D30V
:
1648 rtype
= elf_d30v_reloc_type (type
);
1652 rtype
= elf_dlx_reloc_type (type
);
1656 rtype
= elf_sh_reloc_type (type
);
1660 case EM_CYGNUS_MN10300
:
1661 rtype
= elf_mn10300_reloc_type (type
);
1665 case EM_CYGNUS_MN10200
:
1666 rtype
= elf_mn10200_reloc_type (type
);
1670 case EM_CYGNUS_FR30
:
1671 rtype
= elf_fr30_reloc_type (type
);
1675 rtype
= elf_frv_reloc_type (type
);
1679 rtype
= elf_csky_reloc_type (type
);
1683 rtype
= elf_ft32_reloc_type (type
);
1687 rtype
= elf_mcore_reloc_type (type
);
1691 rtype
= elf_mmix_reloc_type (type
);
1695 rtype
= elf_moxie_reloc_type (type
);
1699 if (uses_msp430x_relocs (filedata
))
1701 rtype
= elf_msp430x_reloc_type (type
);
1706 rtype
= elf_msp430_reloc_type (type
);
1710 rtype
= elf_nds32_reloc_type (type
);
1714 rtype
= elf_ppc_reloc_type (type
);
1718 rtype
= elf_ppc64_reloc_type (type
);
1722 case EM_MIPS_RS3_LE
:
1723 rtype
= elf_mips_reloc_type (type
);
1727 rtype
= elf_riscv_reloc_type (type
);
1731 rtype
= elf_alpha_reloc_type (type
);
1735 rtype
= elf_arm_reloc_type (type
);
1739 case EM_ARC_COMPACT
:
1740 case EM_ARC_COMPACT2
:
1741 rtype
= elf_arc_reloc_type (type
);
1745 rtype
= elf_hppa_reloc_type (type
);
1751 rtype
= elf_h8_reloc_type (type
);
1755 rtype
= elf_or1k_reloc_type (type
);
1760 rtype
= elf_pj_reloc_type (type
);
1763 rtype
= elf_ia64_reloc_type (type
);
1767 rtype
= elf_cris_reloc_type (type
);
1771 rtype
= elf_i860_reloc_type (type
);
1777 rtype
= elf_x86_64_reloc_type (type
);
1781 rtype
= i370_reloc_type (type
);
1786 rtype
= elf_s390_reloc_type (type
);
1790 rtype
= elf_score_reloc_type (type
);
1794 rtype
= elf_xstormy16_reloc_type (type
);
1798 rtype
= elf_crx_reloc_type (type
);
1802 rtype
= elf_vax_reloc_type (type
);
1806 rtype
= elf_visium_reloc_type (type
);
1810 rtype
= elf_bpf_reloc_type (type
);
1813 case EM_ADAPTEVA_EPIPHANY
:
1814 rtype
= elf_epiphany_reloc_type (type
);
1819 rtype
= elf_ip2k_reloc_type (type
);
1823 rtype
= elf_iq2000_reloc_type (type
);
1828 rtype
= elf_xtensa_reloc_type (type
);
1831 case EM_LATTICEMICO32
:
1832 rtype
= elf_lm32_reloc_type (type
);
1837 rtype
= elf_m32c_reloc_type (type
);
1841 rtype
= elf_mt_reloc_type (type
);
1845 rtype
= elf_bfin_reloc_type (type
);
1849 rtype
= elf_mep_reloc_type (type
);
1853 rtype
= elf_cr16_reloc_type (type
);
1857 case EM_MICROBLAZE_OLD
:
1858 rtype
= elf_microblaze_reloc_type (type
);
1862 rtype
= elf_rl78_reloc_type (type
);
1866 rtype
= elf_rx_reloc_type (type
);
1870 rtype
= elf_metag_reloc_type (type
);
1874 rtype
= elf_tic6x_reloc_type (type
);
1878 rtype
= elf_tilegx_reloc_type (type
);
1882 rtype
= elf_tilepro_reloc_type (type
);
1885 case EM_WEBASSEMBLY
:
1886 rtype
= elf_wasm32_reloc_type (type
);
1890 rtype
= elf_xgate_reloc_type (type
);
1893 case EM_ALTERA_NIOS2
:
1894 rtype
= elf_nios2_reloc_type (type
);
1898 rtype
= elf_pru_reloc_type (type
);
1902 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
1903 rtype
= elf_nfp3200_reloc_type (type
);
1905 rtype
= elf_nfp_reloc_type (type
);
1909 rtype
= elf_z80_reloc_type (type
);
1913 rtype
= elf_loongarch_reloc_type (type
);
1917 rtype
= elf_amdgpu_reloc_type (type
);
1922 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1924 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
1926 if (filedata
->file_header
.e_machine
== EM_ALPHA
1928 && streq (rtype
, "R_ALPHA_LITUSE")
1929 && rel_type
== reltype_rela
)
1931 switch (rels
[i
].r_addend
)
1933 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1934 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1935 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1936 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1937 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1938 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1939 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1940 default: rtype
= NULL
;
1944 printf (" (%s)", rtype
);
1948 printf (_("<unknown addend: %" PRIx64
">"),
1953 else if (symtab_index
)
1955 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1957 error (_(" bad symbol index: %08lx in reloc\n"),
1958 (unsigned long) symtab_index
);
1963 Elf_Internal_Sym
* psym
;
1964 const char * version_string
;
1965 enum versioned_symbol_info sym_info
;
1966 unsigned short vna_other
;
1968 psym
= symtab
+ symtab_index
;
1971 = get_symbol_version_string (filedata
, is_dynsym
,
1980 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1984 unsigned int width
= is_32bit_elf
? 8 : 14;
1986 /* Relocations against GNU_IFUNC symbols do not use the value
1987 of the symbol as the address to relocate against. Instead
1988 they invoke the function named by the symbol and use its
1989 result as the address for relocation.
1991 To indicate this to the user, do not display the value of
1992 the symbol in the "Symbols's Value" field. Instead show
1993 its name followed by () as a hint that the symbol is
1997 || psym
->st_name
== 0
1998 || psym
->st_name
>= strtablen
)
2001 name
= strtab
+ psym
->st_name
;
2003 len
= print_symbol (width
, name
);
2005 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
2007 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
2011 print_vma (psym
->st_value
, LONG_HEX
);
2013 printf (is_32bit_elf
? " " : " ");
2016 if (psym
->st_name
== 0)
2018 const char * sec_name
= "<null>";
2021 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
2023 if (psym
->st_shndx
< filedata
->file_header
.e_shnum
2024 && filedata
->section_headers
!= NULL
)
2025 sec_name
= section_name_print (filedata
,
2026 filedata
->section_headers
2028 else if (psym
->st_shndx
== SHN_ABS
)
2030 else if (psym
->st_shndx
== SHN_COMMON
)
2031 sec_name
= "COMMON";
2032 else if ((filedata
->file_header
.e_machine
== EM_MIPS
2033 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
2034 || (filedata
->file_header
.e_machine
== EM_TI_C6000
2035 && psym
->st_shndx
== SHN_TIC6X_SCOMMON
))
2036 sec_name
= "SCOMMON";
2037 else if (filedata
->file_header
.e_machine
== EM_MIPS
2038 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
2039 sec_name
= "SUNDEF";
2040 else if ((filedata
->file_header
.e_machine
== EM_X86_64
2041 || filedata
->file_header
.e_machine
== EM_L1OM
2042 || filedata
->file_header
.e_machine
== EM_K1OM
)
2043 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
2044 sec_name
= "LARGE_COMMON";
2045 else if (filedata
->file_header
.e_machine
== EM_IA_64
2046 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
2047 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
2048 sec_name
= "ANSI_COM";
2049 else if (is_ia64_vms (filedata
)
2050 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
2051 sec_name
= "VMS_SYMVEC";
2054 sprintf (name_buf
, "<section 0x%x>",
2055 (unsigned int) psym
->st_shndx
);
2056 sec_name
= name_buf
;
2059 print_symbol (22, sec_name
);
2061 else if (strtab
== NULL
)
2062 printf (_("<string table index: %3ld>"), psym
->st_name
);
2063 else if (psym
->st_name
>= strtablen
)
2065 error (_("<corrupt string table index: %3ld>\n"),
2071 print_symbol (22, strtab
+ psym
->st_name
);
2073 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
2077 if (rel_type
== reltype_rela
)
2079 uint64_t off
= rels
[i
].r_addend
;
2081 if ((int64_t) off
< 0)
2082 printf (" - %" PRIx64
, -off
);
2084 printf (" + %" PRIx64
, off
);
2088 else if (rel_type
== reltype_rela
)
2090 uint64_t off
= rels
[i
].r_addend
;
2092 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
2093 if ((int64_t) off
< 0)
2094 printf ("-%" PRIx64
, -off
);
2096 printf ("%" PRIx64
, off
);
2099 if (filedata
->file_header
.e_machine
== EM_SPARCV9
2101 && streq (rtype
, "R_SPARC_OLO10"))
2102 printf (" + %" PRIx64
, ELF64_R_TYPE_DATA (inf
));
2106 if (! is_32bit_elf
&& filedata
->file_header
.e_machine
== EM_MIPS
)
2108 uint64_t type2
= ELF64_MIPS_R_TYPE2 (inf
);
2109 uint64_t type3
= ELF64_MIPS_R_TYPE3 (inf
);
2110 const char * rtype2
= elf_mips_reloc_type (type2
);
2111 const char * rtype3
= elf_mips_reloc_type (type3
);
2113 printf (" Type2: ");
2116 printf (_("unrecognized: %-7lx"),
2117 (unsigned long) type2
& 0xffffffff);
2119 printf ("%-17.17s", rtype2
);
2121 printf ("\n Type3: ");
2124 printf (_("unrecognized: %-7lx"),
2125 (unsigned long) type3
& 0xffffffff);
2127 printf ("%-17.17s", rtype3
);
2139 get_aarch64_dynamic_type (unsigned long type
)
2143 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
2144 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
2145 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
2152 get_mips_dynamic_type (unsigned long type
)
2156 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
2157 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
2158 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
2159 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
2160 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
2161 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
2162 case DT_MIPS_MSYM
: return "MIPS_MSYM";
2163 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2164 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2165 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
2166 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
2167 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
2168 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
2169 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
2170 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
2171 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
2172 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
2173 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
2174 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
2175 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
2176 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
2177 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
2178 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
2179 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
2180 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
2181 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
2182 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
2183 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
2184 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
2185 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
2186 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2187 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
2188 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
2189 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
2190 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
2191 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2192 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
2193 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
2194 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
2195 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
2196 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
2197 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
2198 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
2199 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
2200 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
2201 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
2202 case DT_MIPS_XHASH
: return "MIPS_XHASH";
2209 get_sparc64_dynamic_type (unsigned long type
)
2213 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
2220 get_ppc_dynamic_type (unsigned long type
)
2224 case DT_PPC_GOT
: return "PPC_GOT";
2225 case DT_PPC_OPT
: return "PPC_OPT";
2232 get_ppc64_dynamic_type (unsigned long type
)
2236 case DT_PPC64_GLINK
: return "PPC64_GLINK";
2237 case DT_PPC64_OPD
: return "PPC64_OPD";
2238 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
2239 case DT_PPC64_OPT
: return "PPC64_OPT";
2246 get_parisc_dynamic_type (unsigned long type
)
2250 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
2251 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
2252 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
2253 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
2254 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
2255 case DT_HP_PREINIT
: return "HP_PREINIT";
2256 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
2257 case DT_HP_NEEDED
: return "HP_NEEDED";
2258 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
2259 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
2260 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
2261 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
2262 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
2263 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
2264 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
2265 case DT_HP_FILTERED
: return "HP_FILTERED";
2266 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
2267 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
2268 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
2269 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
2270 case DT_PLT
: return "PLT";
2271 case DT_PLT_SIZE
: return "PLT_SIZE";
2272 case DT_DLT
: return "DLT";
2273 case DT_DLT_SIZE
: return "DLT_SIZE";
2280 get_ia64_dynamic_type (unsigned long type
)
2284 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
2285 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
2286 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
2287 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
2288 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
2289 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
2290 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
2291 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
2292 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
2293 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
2294 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
2295 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
2296 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
2297 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
2298 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
2299 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
2300 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
2301 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
2302 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
2303 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
2304 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
2305 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
2306 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
2307 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
2308 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
2309 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
2310 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
2311 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
2312 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
2313 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
2314 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
2321 get_solaris_section_type (unsigned long type
)
2325 case 0x6fffffee: return "SUNW_ancillary";
2326 case 0x6fffffef: return "SUNW_capchain";
2327 case 0x6ffffff0: return "SUNW_capinfo";
2328 case 0x6ffffff1: return "SUNW_symsort";
2329 case 0x6ffffff2: return "SUNW_tlssort";
2330 case 0x6ffffff3: return "SUNW_LDYNSYM";
2331 case 0x6ffffff4: return "SUNW_dof";
2332 case 0x6ffffff5: return "SUNW_cap";
2333 case 0x6ffffff6: return "SUNW_SIGNATURE";
2334 case 0x6ffffff7: return "SUNW_ANNOTATE";
2335 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2336 case 0x6ffffff9: return "SUNW_DEBUG";
2337 case 0x6ffffffa: return "SUNW_move";
2338 case 0x6ffffffb: return "SUNW_COMDAT";
2339 case 0x6ffffffc: return "SUNW_syminfo";
2340 case 0x6ffffffd: return "SUNW_verdef";
2341 case 0x6ffffffe: return "SUNW_verneed";
2342 case 0x6fffffff: return "SUNW_versym";
2343 case 0x70000000: return "SPARC_GOTDATA";
2344 default: return NULL
;
2349 get_alpha_dynamic_type (unsigned long type
)
2353 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
2354 default: return NULL
;
2359 get_score_dynamic_type (unsigned long type
)
2363 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
2364 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
2365 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
2366 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
2367 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
2368 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
2369 default: return NULL
;
2374 get_tic6x_dynamic_type (unsigned long type
)
2378 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
2379 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
2380 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
2381 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
2382 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
2383 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
2384 default: return NULL
;
2389 get_nios2_dynamic_type (unsigned long type
)
2393 case DT_NIOS2_GP
: return "NIOS2_GP";
2394 default: return NULL
;
2399 get_solaris_dynamic_type (unsigned long type
)
2403 case 0x6000000d: return "SUNW_AUXILIARY";
2404 case 0x6000000e: return "SUNW_RTLDINF";
2405 case 0x6000000f: return "SUNW_FILTER";
2406 case 0x60000010: return "SUNW_CAP";
2407 case 0x60000011: return "SUNW_SYMTAB";
2408 case 0x60000012: return "SUNW_SYMSZ";
2409 case 0x60000013: return "SUNW_SORTENT";
2410 case 0x60000014: return "SUNW_SYMSORT";
2411 case 0x60000015: return "SUNW_SYMSORTSZ";
2412 case 0x60000016: return "SUNW_TLSSORT";
2413 case 0x60000017: return "SUNW_TLSSORTSZ";
2414 case 0x60000018: return "SUNW_CAPINFO";
2415 case 0x60000019: return "SUNW_STRPAD";
2416 case 0x6000001a: return "SUNW_CAPCHAIN";
2417 case 0x6000001b: return "SUNW_LDMACH";
2418 case 0x6000001d: return "SUNW_CAPCHAINENT";
2419 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2420 case 0x60000021: return "SUNW_PARENT";
2421 case 0x60000023: return "SUNW_ASLR";
2422 case 0x60000025: return "SUNW_RELAX";
2423 case 0x60000029: return "SUNW_NXHEAP";
2424 case 0x6000002b: return "SUNW_NXSTACK";
2426 case 0x70000001: return "SPARC_REGISTER";
2427 case 0x7ffffffd: return "AUXILIARY";
2428 case 0x7ffffffe: return "USED";
2429 case 0x7fffffff: return "FILTER";
2431 default: return NULL
;
2436 get_riscv_dynamic_type (unsigned long type
)
2440 case DT_RISCV_VARIANT_CC
: return "RISCV_VARIANT_CC";
2447 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
2449 static char buff
[64];
2453 case DT_NULL
: return "NULL";
2454 case DT_NEEDED
: return "NEEDED";
2455 case DT_PLTRELSZ
: return "PLTRELSZ";
2456 case DT_PLTGOT
: return "PLTGOT";
2457 case DT_HASH
: return "HASH";
2458 case DT_STRTAB
: return "STRTAB";
2459 case DT_SYMTAB
: return "SYMTAB";
2460 case DT_RELA
: return "RELA";
2461 case DT_RELASZ
: return "RELASZ";
2462 case DT_RELAENT
: return "RELAENT";
2463 case DT_STRSZ
: return "STRSZ";
2464 case DT_SYMENT
: return "SYMENT";
2465 case DT_INIT
: return "INIT";
2466 case DT_FINI
: return "FINI";
2467 case DT_SONAME
: return "SONAME";
2468 case DT_RPATH
: return "RPATH";
2469 case DT_SYMBOLIC
: return "SYMBOLIC";
2470 case DT_REL
: return "REL";
2471 case DT_RELSZ
: return "RELSZ";
2472 case DT_RELENT
: return "RELENT";
2473 case DT_RELR
: return "RELR";
2474 case DT_RELRSZ
: return "RELRSZ";
2475 case DT_RELRENT
: return "RELRENT";
2476 case DT_PLTREL
: return "PLTREL";
2477 case DT_DEBUG
: return "DEBUG";
2478 case DT_TEXTREL
: return "TEXTREL";
2479 case DT_JMPREL
: return "JMPREL";
2480 case DT_BIND_NOW
: return "BIND_NOW";
2481 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2482 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2483 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2484 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2485 case DT_RUNPATH
: return "RUNPATH";
2486 case DT_FLAGS
: return "FLAGS";
2488 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2489 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2490 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2492 case DT_CHECKSUM
: return "CHECKSUM";
2493 case DT_PLTPADSZ
: return "PLTPADSZ";
2494 case DT_MOVEENT
: return "MOVEENT";
2495 case DT_MOVESZ
: return "MOVESZ";
2496 case DT_FEATURE
: return "FEATURE";
2497 case DT_POSFLAG_1
: return "POSFLAG_1";
2498 case DT_SYMINSZ
: return "SYMINSZ";
2499 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2501 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2502 case DT_CONFIG
: return "CONFIG";
2503 case DT_DEPAUDIT
: return "DEPAUDIT";
2504 case DT_AUDIT
: return "AUDIT";
2505 case DT_PLTPAD
: return "PLTPAD";
2506 case DT_MOVETAB
: return "MOVETAB";
2507 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2509 case DT_VERSYM
: return "VERSYM";
2511 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2512 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2513 case DT_RELACOUNT
: return "RELACOUNT";
2514 case DT_RELCOUNT
: return "RELCOUNT";
2515 case DT_FLAGS_1
: return "FLAGS_1";
2516 case DT_VERDEF
: return "VERDEF";
2517 case DT_VERDEFNUM
: return "VERDEFNUM";
2518 case DT_VERNEED
: return "VERNEED";
2519 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2521 case DT_AUXILIARY
: return "AUXILIARY";
2522 case DT_USED
: return "USED";
2523 case DT_FILTER
: return "FILTER";
2525 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2526 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2527 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2528 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2529 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2530 case DT_GNU_HASH
: return "GNU_HASH";
2531 case DT_GNU_FLAGS_1
: return "GNU_FLAGS_1";
2534 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2536 const char * result
;
2538 switch (filedata
->file_header
.e_machine
)
2541 result
= get_aarch64_dynamic_type (type
);
2544 case EM_MIPS_RS3_LE
:
2545 result
= get_mips_dynamic_type (type
);
2548 result
= get_sparc64_dynamic_type (type
);
2551 result
= get_ppc_dynamic_type (type
);
2554 result
= get_ppc64_dynamic_type (type
);
2557 result
= get_ia64_dynamic_type (type
);
2560 result
= get_alpha_dynamic_type (type
);
2563 result
= get_score_dynamic_type (type
);
2566 result
= get_tic6x_dynamic_type (type
);
2568 case EM_ALTERA_NIOS2
:
2569 result
= get_nios2_dynamic_type (type
);
2572 result
= get_riscv_dynamic_type (type
);
2575 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2576 result
= get_solaris_dynamic_type (type
);
2585 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2587 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2588 || (filedata
->file_header
.e_machine
== EM_PARISC
2589 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2591 const char * result
;
2593 switch (filedata
->file_header
.e_machine
)
2596 result
= get_parisc_dynamic_type (type
);
2599 result
= get_ia64_dynamic_type (type
);
2602 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2603 result
= get_solaris_dynamic_type (type
);
2612 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2616 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2622 static bool get_program_headers (Filedata
*);
2623 static bool get_dynamic_section (Filedata
*);
2626 locate_dynamic_section (Filedata
*filedata
)
2628 uint64_t dynamic_addr
= 0;
2629 uint64_t dynamic_size
= 0;
2631 if (filedata
->file_header
.e_phnum
!= 0
2632 && get_program_headers (filedata
))
2634 Elf_Internal_Phdr
*segment
;
2637 for (i
= 0, segment
= filedata
->program_headers
;
2638 i
< filedata
->file_header
.e_phnum
;
2641 if (segment
->p_type
== PT_DYNAMIC
)
2643 dynamic_addr
= segment
->p_offset
;
2644 dynamic_size
= segment
->p_filesz
;
2646 if (filedata
->section_headers
!= NULL
)
2648 Elf_Internal_Shdr
*sec
;
2650 sec
= find_section (filedata
, ".dynamic");
2653 if (sec
->sh_size
== 0
2654 || sec
->sh_type
== SHT_NOBITS
)
2661 dynamic_addr
= sec
->sh_offset
;
2662 dynamic_size
= sec
->sh_size
;
2667 if (dynamic_addr
> filedata
->file_size
2668 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
2677 filedata
->dynamic_addr
= dynamic_addr
;
2678 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
2682 is_pie (Filedata
*filedata
)
2684 Elf_Internal_Dyn
*entry
;
2686 if (filedata
->dynamic_size
== 0)
2687 locate_dynamic_section (filedata
);
2688 if (filedata
->dynamic_size
<= 1)
2691 if (!get_dynamic_section (filedata
))
2694 for (entry
= filedata
->dynamic_section
;
2695 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
2698 if (entry
->d_tag
== DT_FLAGS_1
)
2700 if ((entry
->d_un
.d_val
& DF_1_PIE
) != 0)
2709 get_file_type (Filedata
*filedata
)
2711 unsigned e_type
= filedata
->file_header
.e_type
;
2712 static char buff
[64];
2716 case ET_NONE
: return _("NONE (None)");
2717 case ET_REL
: return _("REL (Relocatable file)");
2718 case ET_EXEC
: return _("EXEC (Executable file)");
2720 if (is_pie (filedata
))
2721 return _("DYN (Position-Independent Executable file)");
2723 return _("DYN (Shared object file)");
2724 case ET_CORE
: return _("CORE (Core file)");
2727 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2728 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2729 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2730 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2732 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2738 get_machine_name (unsigned e_machine
)
2740 static char buff
[64]; /* XXX */
2744 /* Please keep this switch table sorted by increasing EM_ value. */
2746 case EM_NONE
: return _("None");
2747 case EM_M32
: return "WE32100";
2748 case EM_SPARC
: return "Sparc";
2749 case EM_386
: return "Intel 80386";
2750 case EM_68K
: return "MC68000";
2751 case EM_88K
: return "MC88000";
2752 case EM_IAMCU
: return "Intel MCU";
2753 case EM_860
: return "Intel 80860";
2754 case EM_MIPS
: return "MIPS R3000";
2755 case EM_S370
: return "IBM System/370";
2757 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2758 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2759 case EM_PARISC
: return "HPPA";
2760 case EM_VPP550
: return "Fujitsu VPP500";
2761 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2762 case EM_960
: return "Intel 80960";
2763 case EM_PPC
: return "PowerPC";
2765 case EM_PPC64
: return "PowerPC64";
2767 case EM_S390
: return "IBM S/390";
2768 case EM_SPU
: return "SPU";
2770 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2771 case EM_FR20
: return "Fujitsu FR20";
2772 case EM_RH32
: return "TRW RH32";
2773 case EM_MCORE
: return "MCORE";
2775 case EM_ARM
: return "ARM";
2776 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2777 case EM_SH
: return "Renesas / SuperH SH";
2778 case EM_SPARCV9
: return "Sparc v9";
2779 case EM_TRICORE
: return "Siemens Tricore";
2780 case EM_ARC
: return "ARC";
2781 case EM_H8_300
: return "Renesas H8/300";
2782 case EM_H8_300H
: return "Renesas H8/300H";
2783 case EM_H8S
: return "Renesas H8S";
2784 case EM_H8_500
: return "Renesas H8/500";
2786 case EM_IA_64
: return "Intel IA-64";
2787 case EM_MIPS_X
: return "Stanford MIPS-X";
2788 case EM_COLDFIRE
: return "Motorola Coldfire";
2789 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2790 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2791 case EM_PCP
: return "Siemens PCP";
2792 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2793 case EM_NDR1
: return "Denso NDR1 microprocesspr";
2794 case EM_STARCORE
: return "Motorola Star*Core processor";
2795 case EM_ME16
: return "Toyota ME16 processor";
2797 case EM_ST100
: return "STMicroelectronics ST100 processor";
2798 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2799 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2800 case EM_PDSP
: return "Sony DSP processor";
2801 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2802 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2803 case EM_FX66
: return "Siemens FX66 microcontroller";
2804 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2805 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2806 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2808 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2809 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2810 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2811 case EM_SVX
: return "Silicon Graphics SVx";
2812 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2813 case EM_VAX
: return "Digital VAX";
2814 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2815 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2816 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2817 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2819 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2820 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2821 case EM_PRISM
: return "Vitesse Prism";
2823 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2824 case EM_CYGNUS_FR30
:
2825 case EM_FR30
: return "Fujitsu FR30";
2826 case EM_CYGNUS_D10V
:
2827 case EM_D10V
: return "d10v";
2828 case EM_CYGNUS_D30V
:
2829 case EM_D30V
: return "d30v";
2830 case EM_CYGNUS_V850
:
2831 case EM_V850
: return "Renesas V850";
2832 case EM_CYGNUS_M32R
:
2833 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2834 case EM_CYGNUS_MN10300
:
2835 case EM_MN10300
: return "mn10300";
2837 case EM_CYGNUS_MN10200
:
2838 case EM_MN10200
: return "mn10200";
2839 case EM_PJ
: return "picoJava";
2840 case EM_OR1K
: return "OpenRISC 1000";
2841 case EM_ARC_COMPACT
: return "ARCompact";
2843 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2844 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2845 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2846 case EM_NS32K
: return "National Semiconductor 32000 series";
2847 case EM_TPC
: return "Tenor Network TPC processor";
2848 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2850 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2852 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2853 case EM_MAX
: return "MAX Processor";
2854 case EM_CR
: return "National Semiconductor CompactRISC";
2855 case EM_F2MC16
: return "Fujitsu F2MC16";
2856 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2857 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2858 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2859 case EM_SEP
: return "Sharp embedded microprocessor";
2860 case EM_ARCA
: return "Arca RISC microprocessor";
2862 case EM_UNICORE
: return "Unicore";
2863 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2864 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2865 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2866 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2867 case EM_XGATE
: return "Motorola XGATE embedded processor";
2869 case EM_XC16X
: return "Infineon Technologies xc16x";
2870 case EM_M16C
: return "Renesas M16C series microprocessors";
2871 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2872 case EM_CE
: return "Freescale Communication Engine RISC core";
2874 case EM_M32C
: return "Renesas M32c";
2876 case EM_TSK3000
: return "Altium TSK3000 core";
2877 case EM_RS08
: return "Freescale RS08 embedded processor";
2878 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2879 case EM_SCORE
: return "SUNPLUS S+Core";
2880 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2881 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2882 case EM_LATTICEMICO32
: return "Lattice Mico32";
2883 case EM_SE_C17
: return "Seiko Epson C17 family";
2885 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2886 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2887 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2888 case EM_TI_PRU
: return "TI PRU I/O processor";
2890 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2891 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2892 case EM_R32C
: return "Renesas R32C series microprocessors";
2893 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2894 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2895 case EM_8051
: return "Intel 8051 and variants";
2896 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2897 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2898 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2899 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2901 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
2902 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
2903 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
2904 case EM_RX
: return "Renesas RX";
2905 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
2906 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
2907 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
2910 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
2911 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
2912 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
2914 case EM_L1OM
: return "Intel L1OM";
2915 case EM_K1OM
: return "Intel K1OM";
2916 case EM_INTEL182
: return "Intel (reserved)";
2917 case EM_AARCH64
: return "AArch64";
2918 case EM_ARM184
: return "ARM (reserved)";
2919 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
2920 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
2921 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
2922 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
2924 case EM_CUDA
: return "NVIDIA CUDA architecture";
2925 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
2926 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
2927 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
2928 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
2929 case EM_ARC_COMPACT2
: return "ARCv2";
2930 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
2931 case EM_RL78
: return "Renesas RL78";
2932 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
2933 case EM_78K0R
: return "Renesas 78K0R";
2935 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
2936 case EM_BA1
: return "Beyond BA1 CPU architecture";
2937 case EM_BA2
: return "Beyond BA2 CPU architecture";
2938 case EM_XCORE
: return "XMOS xCORE processor family";
2939 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
2940 case EM_INTELGT
: return "Intel Graphics Technology";
2942 case EM_KM32
: return "KM211 KM32 32-bit processor";
2943 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
2944 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
2945 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
2946 case EM_KVARC
: return "KM211 KVARC processor";
2947 case EM_CDP
: return "Paneve CDP architecture family";
2948 case EM_COGE
: return "Cognitive Smart Memory Processor";
2949 case EM_COOL
: return "Bluechip Systems CoolEngine";
2950 case EM_NORC
: return "Nanoradio Optimized RISC";
2951 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
2953 case EM_Z80
: return "Zilog Z80";
2954 case EM_VISIUM
: return "CDS VISIUMcore processor";
2955 case EM_FT32
: return "FTDI Chip FT32";
2956 case EM_MOXIE
: return "Moxie";
2957 case EM_AMDGPU
: return "AMD GPU";
2958 /* 230 (all reserved) */
2960 case EM_RISCV
: return "RISC-V";
2961 case EM_LANAI
: return "Lanai 32-bit processor";
2962 case EM_CEVA
: return "CEVA Processor Architecture Family";
2963 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
2964 case EM_BPF
: return "Linux BPF";
2965 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
2966 case EM_IMG1
: return "Imagination Technologies";
2968 case EM_NFP
: return "Netronome Flow Processor";
2969 case EM_VE
: return "NEC Vector Engine";
2970 case EM_CSKY
: return "C-SKY";
2971 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv2.3 64-bit";
2972 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
2973 case EM_ARC_COMPACT3
: return "Synopsys ARCv2.3 32-bit";
2974 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
2975 case EM_65816
: return "WDC 65816/65C816";
2976 case EM_LOONGARCH
: return "LoongArch";
2977 case EM_KF32
: return "ChipON KungFu32";
2979 /* Large numbers... */
2980 case EM_MT
: return "Morpho Techologies MT processor";
2981 case EM_ALPHA
: return "Alpha";
2982 case EM_WEBASSEMBLY
: return "Web Assembly";
2983 case EM_DLX
: return "OpenDLX";
2984 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
2985 case EM_IQ2000
: return "Vitesse IQ2000";
2987 case EM_NIOS32
: return "Altera Nios";
2988 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
2989 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
2990 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
2991 case EM_S12Z
: return "Freescale S12Z";
2994 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
3000 decode_ARC_machine_flags (unsigned e_flags
, unsigned e_machine
, char buf
[])
3002 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
3003 other compilers don't specify an architecture type in the e_flags, and
3004 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
3005 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
3008 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
3009 but also sets a specific architecture type in the e_flags field.
3011 However, when decoding the flags we don't worry if we see an
3012 unexpected pairing, for example EM_ARC_COMPACT machine type, with
3013 ARCEM architecture type. */
3015 switch (e_flags
& EF_ARC_MACH_MSK
)
3017 /* We only expect these to occur for EM_ARC_COMPACT2. */
3018 case EF_ARC_CPU_ARCV2EM
:
3019 strcat (buf
, ", ARC EM");
3021 case EF_ARC_CPU_ARCV2HS
:
3022 strcat (buf
, ", ARC HS");
3025 /* We only expect these to occur for EM_ARC_COMPACT. */
3026 case E_ARC_MACH_ARC600
:
3027 strcat (buf
, ", ARC600");
3029 case E_ARC_MACH_ARC601
:
3030 strcat (buf
, ", ARC601");
3032 case E_ARC_MACH_ARC700
:
3033 strcat (buf
, ", ARC700");
3036 /* The only times we should end up here are (a) A corrupt ELF, (b) A
3037 new ELF with new architecture being read by an old version of
3038 readelf, or (c) An ELF built with non-GNU compiler that does not
3039 set the architecture in the e_flags. */
3041 if (e_machine
== EM_ARC_COMPACT
)
3042 strcat (buf
, ", Unknown ARCompact");
3044 strcat (buf
, ", Unknown ARC");
3048 switch (e_flags
& EF_ARC_OSABI_MSK
)
3050 case E_ARC_OSABI_ORIG
:
3051 strcat (buf
, ", (ABI:legacy)");
3053 case E_ARC_OSABI_V2
:
3054 strcat (buf
, ", (ABI:v2)");
3056 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
3057 case E_ARC_OSABI_V3
:
3058 strcat (buf
, ", v3 no-legacy-syscalls ABI");
3060 case E_ARC_OSABI_V4
:
3061 strcat (buf
, ", v4 ABI");
3064 strcat (buf
, ", unrecognised ARC OSABI flag");
3070 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
3073 bool unknown
= false;
3075 eabi
= EF_ARM_EABI_VERSION (e_flags
);
3076 e_flags
&= ~ EF_ARM_EABIMASK
;
3078 /* Handle "generic" ARM flags. */
3079 if (e_flags
& EF_ARM_RELEXEC
)
3081 strcat (buf
, ", relocatable executable");
3082 e_flags
&= ~ EF_ARM_RELEXEC
;
3085 if (e_flags
& EF_ARM_PIC
)
3087 strcat (buf
, ", position independent");
3088 e_flags
&= ~ EF_ARM_PIC
;
3091 /* Now handle EABI specific flags. */
3095 strcat (buf
, ", <unrecognized EABI>");
3100 case EF_ARM_EABI_VER1
:
3101 strcat (buf
, ", Version1 EABI");
3106 /* Process flags one bit at a time. */
3107 flag
= e_flags
& - e_flags
;
3112 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3113 strcat (buf
, ", sorted symbol tables");
3123 case EF_ARM_EABI_VER2
:
3124 strcat (buf
, ", Version2 EABI");
3129 /* Process flags one bit at a time. */
3130 flag
= e_flags
& - e_flags
;
3135 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3136 strcat (buf
, ", sorted symbol tables");
3139 case EF_ARM_DYNSYMSUSESEGIDX
:
3140 strcat (buf
, ", dynamic symbols use segment index");
3143 case EF_ARM_MAPSYMSFIRST
:
3144 strcat (buf
, ", mapping symbols precede others");
3154 case EF_ARM_EABI_VER3
:
3155 strcat (buf
, ", Version3 EABI");
3158 case EF_ARM_EABI_VER4
:
3159 strcat (buf
, ", Version4 EABI");
3164 /* Process flags one bit at a time. */
3165 flag
= e_flags
& - e_flags
;
3171 strcat (buf
, ", BE8");
3175 strcat (buf
, ", LE8");
3185 case EF_ARM_EABI_VER5
:
3186 strcat (buf
, ", Version5 EABI");
3191 /* Process flags one bit at a time. */
3192 flag
= e_flags
& - e_flags
;
3198 strcat (buf
, ", BE8");
3202 strcat (buf
, ", LE8");
3205 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
3206 strcat (buf
, ", soft-float ABI");
3209 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
3210 strcat (buf
, ", hard-float ABI");
3220 case EF_ARM_EABI_UNKNOWN
:
3221 strcat (buf
, ", GNU EABI");
3226 /* Process flags one bit at a time. */
3227 flag
= e_flags
& - e_flags
;
3232 case EF_ARM_INTERWORK
:
3233 strcat (buf
, ", interworking enabled");
3236 case EF_ARM_APCS_26
:
3237 strcat (buf
, ", uses APCS/26");
3240 case EF_ARM_APCS_FLOAT
:
3241 strcat (buf
, ", uses APCS/float");
3245 strcat (buf
, ", position independent");
3249 strcat (buf
, ", 8 bit structure alignment");
3252 case EF_ARM_NEW_ABI
:
3253 strcat (buf
, ", uses new ABI");
3256 case EF_ARM_OLD_ABI
:
3257 strcat (buf
, ", uses old ABI");
3260 case EF_ARM_SOFT_FLOAT
:
3261 strcat (buf
, ", software FP");
3264 case EF_ARM_VFP_FLOAT
:
3265 strcat (buf
, ", VFP");
3268 case EF_ARM_MAVERICK_FLOAT
:
3269 strcat (buf
, ", Maverick FP");
3280 strcat (buf
,_(", <unknown>"));
3284 decode_AVR_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
3286 --size
; /* Leave space for null terminator. */
3288 switch (e_flags
& EF_AVR_MACH
)
3290 case E_AVR_MACH_AVR1
:
3291 strncat (buf
, ", avr:1", size
);
3293 case E_AVR_MACH_AVR2
:
3294 strncat (buf
, ", avr:2", size
);
3296 case E_AVR_MACH_AVR25
:
3297 strncat (buf
, ", avr:25", size
);
3299 case E_AVR_MACH_AVR3
:
3300 strncat (buf
, ", avr:3", size
);
3302 case E_AVR_MACH_AVR31
:
3303 strncat (buf
, ", avr:31", size
);
3305 case E_AVR_MACH_AVR35
:
3306 strncat (buf
, ", avr:35", size
);
3308 case E_AVR_MACH_AVR4
:
3309 strncat (buf
, ", avr:4", size
);
3311 case E_AVR_MACH_AVR5
:
3312 strncat (buf
, ", avr:5", size
);
3314 case E_AVR_MACH_AVR51
:
3315 strncat (buf
, ", avr:51", size
);
3317 case E_AVR_MACH_AVR6
:
3318 strncat (buf
, ", avr:6", size
);
3320 case E_AVR_MACH_AVRTINY
:
3321 strncat (buf
, ", avr:100", size
);
3323 case E_AVR_MACH_XMEGA1
:
3324 strncat (buf
, ", avr:101", size
);
3326 case E_AVR_MACH_XMEGA2
:
3327 strncat (buf
, ", avr:102", size
);
3329 case E_AVR_MACH_XMEGA3
:
3330 strncat (buf
, ", avr:103", size
);
3332 case E_AVR_MACH_XMEGA4
:
3333 strncat (buf
, ", avr:104", size
);
3335 case E_AVR_MACH_XMEGA5
:
3336 strncat (buf
, ", avr:105", size
);
3338 case E_AVR_MACH_XMEGA6
:
3339 strncat (buf
, ", avr:106", size
);
3341 case E_AVR_MACH_XMEGA7
:
3342 strncat (buf
, ", avr:107", size
);
3345 strncat (buf
, ", avr:<unknown>", size
);
3349 size
-= strlen (buf
);
3350 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
3351 strncat (buf
, ", link-relax", size
);
3355 decode_NDS32_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
3361 bool has_fpu
= false;
3364 static const char *ABI_STRINGS
[] =
3366 "ABI v0", /* use r5 as return register; only used in N1213HC */
3367 "ABI v1", /* use r0 as return register */
3368 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
3369 "ABI v2fp", /* for FPU */
3373 static const char *VER_STRINGS
[] =
3375 "Andes ELF V1.3 or older",
3379 static const char *ARCH_STRINGS
[] =
3388 abi
= EF_NDS_ABI
& e_flags
;
3389 arch
= EF_NDS_ARCH
& e_flags
;
3390 config
= EF_NDS_INST
& e_flags
;
3391 version
= EF_NDS32_ELF_VERSION
& e_flags
;
3393 memset (buf
, 0, size
);
3400 case E_NDS_ABI_V2FP
:
3401 case E_NDS_ABI_AABI
:
3402 case E_NDS_ABI_V2FP_PLUS
:
3403 /* In case there are holes in the array. */
3404 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
3408 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ABI>");
3414 case E_NDS32_ELF_VER_1_2
:
3415 case E_NDS32_ELF_VER_1_3
:
3416 case E_NDS32_ELF_VER_1_4
:
3417 r
+= snprintf (buf
+ r
, size
- r
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
3421 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ELF version number>");
3425 if (E_NDS_ABI_V0
== abi
)
3427 /* OLD ABI; only used in N1213HC, has performance extension 1. */
3428 r
+= snprintf (buf
+ r
, size
- r
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
3429 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3430 r
+= snprintf (buf
+ r
, size
-r
, ", 16b"); /* has 16-bit instructions */
3436 case E_NDS_ARCH_STAR_V1_0
:
3437 case E_NDS_ARCH_STAR_V2_0
:
3438 case E_NDS_ARCH_STAR_V3_0
:
3439 case E_NDS_ARCH_STAR_V3_M
:
3440 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
3444 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized architecture>");
3445 /* ARCH version determines how the e_flags are interpreted.
3446 If it is unknown, we cannot proceed. */
3450 /* Newer ABI; Now handle architecture specific flags. */
3451 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3453 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3454 r
+= snprintf (buf
+ r
, size
-r
, ", MFUSR_PC");
3456 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
3457 r
+= snprintf (buf
+ r
, size
-r
, ", MAC");
3459 if (config
& E_NDS32_HAS_DIV_INST
)
3460 r
+= snprintf (buf
+ r
, size
-r
, ", DIV");
3462 if (config
& E_NDS32_HAS_16BIT_INST
)
3463 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3467 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3469 if (version
<= E_NDS32_ELF_VER_1_3
)
3470 r
+= snprintf (buf
+ r
, size
-r
, ", [B8]");
3472 r
+= snprintf (buf
+ r
, size
-r
, ", EX9");
3475 if (config
& E_NDS32_HAS_MAC_DX_INST
)
3476 r
+= snprintf (buf
+ r
, size
-r
, ", MAC_DX");
3478 if (config
& E_NDS32_HAS_DIV_DX_INST
)
3479 r
+= snprintf (buf
+ r
, size
-r
, ", DIV_DX");
3481 if (config
& E_NDS32_HAS_16BIT_INST
)
3483 if (version
<= E_NDS32_ELF_VER_1_3
)
3484 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3486 r
+= snprintf (buf
+ r
, size
-r
, ", IFC");
3490 if (config
& E_NDS32_HAS_EXT_INST
)
3491 r
+= snprintf (buf
+ r
, size
-r
, ", PERF1");
3493 if (config
& E_NDS32_HAS_EXT2_INST
)
3494 r
+= snprintf (buf
+ r
, size
-r
, ", PERF2");
3496 if (config
& E_NDS32_HAS_FPU_INST
)
3499 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_SP");
3502 if (config
& E_NDS32_HAS_FPU_DP_INST
)
3505 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_DP");
3508 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
3511 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_MAC");
3516 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
3518 case E_NDS32_FPU_REG_8SP_4DP
:
3519 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:8/4");
3521 case E_NDS32_FPU_REG_16SP_8DP
:
3522 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:16/8");
3524 case E_NDS32_FPU_REG_32SP_16DP
:
3525 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/16");
3527 case E_NDS32_FPU_REG_32SP_32DP
:
3528 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/32");
3533 if (config
& E_NDS32_HAS_AUDIO_INST
)
3534 r
+= snprintf (buf
+ r
, size
-r
, ", AUDIO");
3536 if (config
& E_NDS32_HAS_STRING_INST
)
3537 r
+= snprintf (buf
+ r
, size
-r
, ", STR");
3539 if (config
& E_NDS32_HAS_REDUCED_REGS
)
3540 r
+= snprintf (buf
+ r
, size
-r
, ", 16REG");
3542 if (config
& E_NDS32_HAS_VIDEO_INST
)
3544 if (version
<= E_NDS32_ELF_VER_1_3
)
3545 r
+= snprintf (buf
+ r
, size
-r
, ", VIDEO");
3547 r
+= snprintf (buf
+ r
, size
-r
, ", SATURATION");
3550 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
3551 r
+= snprintf (buf
+ r
, size
-r
, ", ENCRP");
3553 if (config
& E_NDS32_HAS_L2C_INST
)
3554 r
+= snprintf (buf
+ r
, size
-r
, ", L2C");
3558 decode_AMDGPU_machine_flags (Filedata
*filedata
, unsigned int e_flags
,
3561 unsigned char *e_ident
= filedata
->file_header
.e_ident
;
3562 unsigned char osabi
= e_ident
[EI_OSABI
];
3563 unsigned char abiversion
= e_ident
[EI_ABIVERSION
];
3566 /* HSA OS ABI v2 used a different encoding, but we don't need to support it,
3567 it has been deprecated for a while.
3569 The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time
3570 of writing, they use the same flags as HSA v3, so the code below uses that
3572 if (osabi
== ELFOSABI_AMDGPU_HSA
&& abiversion
< ELFABIVERSION_AMDGPU_HSA_V3
)
3575 mach
= e_flags
& EF_AMDGPU_MACH
;
3578 #define AMDGPU_CASE(code, string) \
3579 case code: strcat (buf, ", " string); break;
3580 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600
, "gfx600")
3581 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601
, "gfx601")
3582 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700
, "gfx700")
3583 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701
, "gfx701")
3584 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702
, "gfx702")
3585 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703
, "gfx703")
3586 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704
, "gfx704")
3587 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801
, "gfx801")
3588 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802
, "gfx802")
3589 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803
, "gfx803")
3590 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810
, "gfx810")
3591 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900
, "gfx900")
3592 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902
, "gfx902")
3593 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904
, "gfx904")
3594 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906
, "gfx906")
3595 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908
, "gfx908")
3596 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909
, "gfx909")
3597 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C
, "gfx90c")
3598 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010
, "gfx1010")
3599 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011
, "gfx1011")
3600 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012
, "gfx1012")
3601 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030
, "gfx1030")
3602 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031
, "gfx1031")
3603 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032
, "gfx1032")
3604 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033
, "gfx1033")
3605 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602
, "gfx602")
3606 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705
, "gfx705")
3607 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805
, "gfx805")
3608 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035
, "gfx1035")
3609 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034
, "gfx1034")
3610 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A
, "gfx90a")
3611 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940
, "gfx940")
3612 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013
, "gfx1013")
3613 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036
, "gfx1036")
3615 sprintf (buf
, _(", <unknown AMDGPU GPU type: %#x>"), mach
);
3620 buf
+= strlen (buf
);
3621 e_flags
&= ~EF_AMDGPU_MACH
;
3623 if ((osabi
== ELFOSABI_AMDGPU_HSA
3624 && abiversion
== ELFABIVERSION_AMDGPU_HSA_V3
)
3625 || osabi
!= ELFOSABI_AMDGPU_HSA
)
3627 /* For HSA v3 and other OS ABIs. */
3628 if (e_flags
& EF_AMDGPU_FEATURE_XNACK_V3
)
3630 strcat (buf
, ", xnack on");
3631 buf
+= strlen (buf
);
3632 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V3
;
3635 if (e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V3
)
3637 strcat (buf
, ", sramecc on");
3638 buf
+= strlen (buf
);
3639 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V3
;
3647 xnack
= e_flags
& EF_AMDGPU_FEATURE_XNACK_V4
;
3650 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
:
3653 case EF_AMDGPU_FEATURE_XNACK_ANY_V4
:
3654 strcat (buf
, ", xnack any");
3657 case EF_AMDGPU_FEATURE_XNACK_OFF_V4
:
3658 strcat (buf
, ", xnack off");
3661 case EF_AMDGPU_FEATURE_XNACK_ON_V4
:
3662 strcat (buf
, ", xnack on");
3666 sprintf (buf
, _(", <unknown xnack value: %#x>"), xnack
);
3670 buf
+= strlen (buf
);
3671 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V4
;
3673 sramecc
= e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V4
;
3676 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
:
3679 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
:
3680 strcat (buf
, ", sramecc any");
3683 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
:
3684 strcat (buf
, ", sramecc off");
3687 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4
:
3688 strcat (buf
, ", sramecc on");
3692 sprintf (buf
, _(", <unknown sramecc value: %#x>"), sramecc
);
3696 buf
+= strlen (buf
);
3697 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V4
;
3701 sprintf (buf
, _(", unknown flags bits: %#x"), e_flags
);
3705 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
3707 static char buf
[1024];
3718 case EM_ARC_COMPACT2
:
3719 case EM_ARC_COMPACT
:
3720 decode_ARC_machine_flags (e_flags
, e_machine
, buf
);
3724 decode_ARM_machine_flags (e_flags
, buf
);
3728 decode_AVR_machine_flags (e_flags
, buf
, sizeof buf
);
3732 if (e_flags
& EF_BFIN_PIC
)
3733 strcat (buf
, ", PIC");
3735 if (e_flags
& EF_BFIN_FDPIC
)
3736 strcat (buf
, ", FDPIC");
3738 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3739 strcat (buf
, ", code in L1");
3741 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3742 strcat (buf
, ", data in L1");
3747 switch (e_flags
& EF_FRV_CPU_MASK
)
3749 case EF_FRV_CPU_GENERIC
:
3753 strcat (buf
, ", fr???");
3756 case EF_FRV_CPU_FR300
:
3757 strcat (buf
, ", fr300");
3760 case EF_FRV_CPU_FR400
:
3761 strcat (buf
, ", fr400");
3763 case EF_FRV_CPU_FR405
:
3764 strcat (buf
, ", fr405");
3767 case EF_FRV_CPU_FR450
:
3768 strcat (buf
, ", fr450");
3771 case EF_FRV_CPU_FR500
:
3772 strcat (buf
, ", fr500");
3774 case EF_FRV_CPU_FR550
:
3775 strcat (buf
, ", fr550");
3778 case EF_FRV_CPU_SIMPLE
:
3779 strcat (buf
, ", simple");
3781 case EF_FRV_CPU_TOMCAT
:
3782 strcat (buf
, ", tomcat");
3788 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3789 strcat (buf
, ", m68000");
3790 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3791 strcat (buf
, ", cpu32");
3792 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3793 strcat (buf
, ", fido_a");
3796 char const * isa
= _("unknown");
3797 char const * mac
= _("unknown mac");
3798 char const * additional
= NULL
;
3800 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3802 case EF_M68K_CF_ISA_A_NODIV
:
3804 additional
= ", nodiv";
3806 case EF_M68K_CF_ISA_A
:
3809 case EF_M68K_CF_ISA_A_PLUS
:
3812 case EF_M68K_CF_ISA_B_NOUSP
:
3814 additional
= ", nousp";
3816 case EF_M68K_CF_ISA_B
:
3819 case EF_M68K_CF_ISA_C
:
3822 case EF_M68K_CF_ISA_C_NODIV
:
3824 additional
= ", nodiv";
3827 strcat (buf
, ", cf, isa ");
3830 strcat (buf
, additional
);
3831 if (e_flags
& EF_M68K_CF_FLOAT
)
3832 strcat (buf
, ", float");
3833 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3838 case EF_M68K_CF_MAC
:
3841 case EF_M68K_CF_EMAC
:
3844 case EF_M68K_CF_EMAC_B
:
3857 decode_AMDGPU_machine_flags (filedata
, e_flags
, buf
);
3861 switch (e_flags
& EF_MEP_CPU_MASK
)
3863 case EF_MEP_CPU_MEP
: strcat (buf
, ", generic MeP"); break;
3864 case EF_MEP_CPU_C2
: strcat (buf
, ", MeP C2"); break;
3865 case EF_MEP_CPU_C3
: strcat (buf
, ", MeP C3"); break;
3866 case EF_MEP_CPU_C4
: strcat (buf
, ", MeP C4"); break;
3867 case EF_MEP_CPU_C5
: strcat (buf
, ", MeP C5"); break;
3868 case EF_MEP_CPU_H1
: strcat (buf
, ", MeP H1"); break;
3869 default: strcat (buf
, _(", <unknown MeP cpu type>")); break;
3872 switch (e_flags
& EF_MEP_COP_MASK
)
3874 case EF_MEP_COP_NONE
: break;
3875 case EF_MEP_COP_AVC
: strcat (buf
, ", AVC coprocessor"); break;
3876 case EF_MEP_COP_AVC2
: strcat (buf
, ", AVC2 coprocessor"); break;
3877 case EF_MEP_COP_FMAX
: strcat (buf
, ", FMAX coprocessor"); break;
3878 case EF_MEP_COP_IVC2
: strcat (buf
, ", IVC2 coprocessor"); break;
3879 default: strcat (buf
, _("<unknown MeP copro type>")); break;
3882 if (e_flags
& EF_MEP_LIBRARY
)
3883 strcat (buf
, ", Built for Library");
3885 if (e_flags
& EF_MEP_INDEX_MASK
)
3886 sprintf (buf
+ strlen (buf
), ", Configuration Index: %#x",
3887 e_flags
& EF_MEP_INDEX_MASK
);
3889 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3890 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3891 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3895 if (e_flags
& EF_PPC_EMB
)
3896 strcat (buf
, ", emb");
3898 if (e_flags
& EF_PPC_RELOCATABLE
)
3899 strcat (buf
, _(", relocatable"));
3901 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
3902 strcat (buf
, _(", relocatable-lib"));
3906 if (e_flags
& EF_PPC64_ABI
)
3908 char abi
[] = ", abiv0";
3910 abi
[6] += e_flags
& EF_PPC64_ABI
;
3916 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
3917 strcat (buf
, ", RH850 ABI");
3919 if (e_flags
& EF_V800_850E3
)
3920 strcat (buf
, ", V3 architecture");
3922 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
3923 strcat (buf
, ", FPU not used");
3925 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
3926 strcat (buf
, ", regmode: COMMON");
3928 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
3929 strcat (buf
, ", r4 not used");
3931 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
3932 strcat (buf
, ", r30 not used");
3934 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
3935 strcat (buf
, ", r5 not used");
3937 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
3938 strcat (buf
, ", r2 not used");
3940 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
3942 switch (e_flags
& - e_flags
)
3944 case EF_RH850_FPU_DOUBLE
: strcat (buf
, ", double precision FPU"); break;
3945 case EF_RH850_FPU_SINGLE
: strcat (buf
, ", single precision FPU"); break;
3946 case EF_RH850_REGMODE22
: strcat (buf
, ", regmode:22"); break;
3947 case EF_RH850_REGMODE32
: strcat (buf
, ", regmode:23"); break;
3948 case EF_RH850_GP_FIX
: strcat (buf
, ", r4 fixed"); break;
3949 case EF_RH850_GP_NOFIX
: strcat (buf
, ", r4 free"); break;
3950 case EF_RH850_EP_FIX
: strcat (buf
, ", r30 fixed"); break;
3951 case EF_RH850_EP_NOFIX
: strcat (buf
, ", r30 free"); break;
3952 case EF_RH850_TP_FIX
: strcat (buf
, ", r5 fixed"); break;
3953 case EF_RH850_TP_NOFIX
: strcat (buf
, ", r5 free"); break;
3954 case EF_RH850_REG2_RESERVE
: strcat (buf
, ", r2 fixed"); break;
3955 case EF_RH850_REG2_NORESERVE
: strcat (buf
, ", r2 free"); break;
3962 case EM_CYGNUS_V850
:
3963 switch (e_flags
& EF_V850_ARCH
)
3965 case E_V850E3V5_ARCH
:
3966 strcat (buf
, ", v850e3v5");
3968 case E_V850E2V3_ARCH
:
3969 strcat (buf
, ", v850e2v3");
3972 strcat (buf
, ", v850e2");
3975 strcat (buf
, ", v850e1");
3978 strcat (buf
, ", v850e");
3981 strcat (buf
, ", v850");
3984 strcat (buf
, _(", unknown v850 architecture variant"));
3990 case EM_CYGNUS_M32R
:
3991 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
3992 strcat (buf
, ", m32r");
3996 case EM_MIPS_RS3_LE
:
3997 if (e_flags
& EF_MIPS_NOREORDER
)
3998 strcat (buf
, ", noreorder");
4000 if (e_flags
& EF_MIPS_PIC
)
4001 strcat (buf
, ", pic");
4003 if (e_flags
& EF_MIPS_CPIC
)
4004 strcat (buf
, ", cpic");
4006 if (e_flags
& EF_MIPS_UCODE
)
4007 strcat (buf
, ", ugen_reserved");
4009 if (e_flags
& EF_MIPS_ABI2
)
4010 strcat (buf
, ", abi2");
4012 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
4013 strcat (buf
, ", odk first");
4015 if (e_flags
& EF_MIPS_32BITMODE
)
4016 strcat (buf
, ", 32bitmode");
4018 if (e_flags
& EF_MIPS_NAN2008
)
4019 strcat (buf
, ", nan2008");
4021 if (e_flags
& EF_MIPS_FP64
)
4022 strcat (buf
, ", fp64");
4024 switch ((e_flags
& EF_MIPS_MACH
))
4026 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
4027 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
4028 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
4029 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
4030 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
4031 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
4032 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
4033 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
4034 case E_MIPS_MACH_5900
: strcat (buf
, ", 5900"); break;
4035 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
4036 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
4037 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
4038 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
4039 case E_MIPS_MACH_GS464
: strcat (buf
, ", gs464"); break;
4040 case E_MIPS_MACH_GS464E
: strcat (buf
, ", gs464e"); break;
4041 case E_MIPS_MACH_GS264E
: strcat (buf
, ", gs264e"); break;
4042 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
4043 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
4044 case E_MIPS_MACH_OCTEON3
: strcat (buf
, ", octeon3"); break;
4045 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
4046 case E_MIPS_MACH_IAMR2
: strcat (buf
, ", interaptiv-mr2"); break;
4048 /* We simply ignore the field in this case to avoid confusion:
4049 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
4052 default: strcat (buf
, _(", unknown CPU")); break;
4055 switch ((e_flags
& EF_MIPS_ABI
))
4057 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
4058 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
4059 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
4060 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
4062 /* We simply ignore the field in this case to avoid confusion:
4063 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
4064 This means it is likely to be an o32 file, but not for
4067 default: strcat (buf
, _(", unknown ABI")); break;
4070 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
4071 strcat (buf
, ", mdmx");
4073 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
4074 strcat (buf
, ", mips16");
4076 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
4077 strcat (buf
, ", micromips");
4079 switch ((e_flags
& EF_MIPS_ARCH
))
4081 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
4082 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
4083 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
4084 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
4085 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
4086 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
4087 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
4088 case E_MIPS_ARCH_32R6
: strcat (buf
, ", mips32r6"); break;
4089 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
4090 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
4091 case E_MIPS_ARCH_64R6
: strcat (buf
, ", mips64r6"); break;
4092 default: strcat (buf
, _(", unknown ISA")); break;
4097 decode_NDS32_machine_flags (e_flags
, buf
, sizeof buf
);
4101 switch (EF_NFP_MACH (e_flags
))
4103 case E_NFP_MACH_3200
:
4104 strcat (buf
, ", NFP-32xx");
4106 case E_NFP_MACH_6000
:
4107 strcat (buf
, ", NFP-6xxx");
4113 if (e_flags
& EF_RISCV_RVC
)
4114 strcat (buf
, ", RVC");
4116 if (e_flags
& EF_RISCV_RVE
)
4117 strcat (buf
, ", RVE");
4119 if (e_flags
& EF_RISCV_TSO
)
4120 strcat (buf
, ", TSO");
4122 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
4124 case EF_RISCV_FLOAT_ABI_SOFT
:
4125 strcat (buf
, ", soft-float ABI");
4128 case EF_RISCV_FLOAT_ABI_SINGLE
:
4129 strcat (buf
, ", single-float ABI");
4132 case EF_RISCV_FLOAT_ABI_DOUBLE
:
4133 strcat (buf
, ", double-float ABI");
4136 case EF_RISCV_FLOAT_ABI_QUAD
:
4137 strcat (buf
, ", quad-float ABI");
4143 switch ((e_flags
& EF_SH_MACH_MASK
))
4145 case EF_SH1
: strcat (buf
, ", sh1"); break;
4146 case EF_SH2
: strcat (buf
, ", sh2"); break;
4147 case EF_SH3
: strcat (buf
, ", sh3"); break;
4148 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
4149 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
4150 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
4151 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
4152 case EF_SH4
: strcat (buf
, ", sh4"); break;
4153 case EF_SH5
: strcat (buf
, ", sh5"); break;
4154 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
4155 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
4156 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
4157 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
4158 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
4159 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
4160 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
4161 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
4162 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
4163 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
4164 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
4165 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
4166 default: strcat (buf
, _(", unknown ISA")); break;
4169 if (e_flags
& EF_SH_PIC
)
4170 strcat (buf
, ", pic");
4172 if (e_flags
& EF_SH_FDPIC
)
4173 strcat (buf
, ", fdpic");
4177 if (e_flags
& EF_OR1K_NODELAY
)
4178 strcat (buf
, ", no delay");
4182 if (e_flags
& EF_SPARC_32PLUS
)
4183 strcat (buf
, ", v8+");
4185 if (e_flags
& EF_SPARC_SUN_US1
)
4186 strcat (buf
, ", ultrasparcI");
4188 if (e_flags
& EF_SPARC_SUN_US3
)
4189 strcat (buf
, ", ultrasparcIII");
4191 if (e_flags
& EF_SPARC_HAL_R1
)
4192 strcat (buf
, ", halr1");
4194 if (e_flags
& EF_SPARC_LEDATA
)
4195 strcat (buf
, ", ledata");
4197 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
4198 strcat (buf
, ", tso");
4200 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
4201 strcat (buf
, ", pso");
4203 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
4204 strcat (buf
, ", rmo");
4208 switch (e_flags
& EF_PARISC_ARCH
)
4210 case EFA_PARISC_1_0
:
4211 strcpy (buf
, ", PA-RISC 1.0");
4213 case EFA_PARISC_1_1
:
4214 strcpy (buf
, ", PA-RISC 1.1");
4216 case EFA_PARISC_2_0
:
4217 strcpy (buf
, ", PA-RISC 2.0");
4222 if (e_flags
& EF_PARISC_TRAPNIL
)
4223 strcat (buf
, ", trapnil");
4224 if (e_flags
& EF_PARISC_EXT
)
4225 strcat (buf
, ", ext");
4226 if (e_flags
& EF_PARISC_LSB
)
4227 strcat (buf
, ", lsb");
4228 if (e_flags
& EF_PARISC_WIDE
)
4229 strcat (buf
, ", wide");
4230 if (e_flags
& EF_PARISC_NO_KABP
)
4231 strcat (buf
, ", no kabp");
4232 if (e_flags
& EF_PARISC_LAZYSWAP
)
4233 strcat (buf
, ", lazyswap");
4238 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
4239 strcat (buf
, ", new calling convention");
4241 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
4242 strcat (buf
, ", gnu calling convention");
4246 if ((e_flags
& EF_IA_64_ABI64
))
4247 strcat (buf
, ", 64-bit");
4249 strcat (buf
, ", 32-bit");
4250 if ((e_flags
& EF_IA_64_REDUCEDFP
))
4251 strcat (buf
, ", reduced fp model");
4252 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
4253 strcat (buf
, ", no function descriptors, constant gp");
4254 else if ((e_flags
& EF_IA_64_CONS_GP
))
4255 strcat (buf
, ", constant gp");
4256 if ((e_flags
& EF_IA_64_ABSOLUTE
))
4257 strcat (buf
, ", absolute");
4258 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
4260 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
4261 strcat (buf
, ", vms_linkages");
4262 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
4264 case EF_IA_64_VMS_COMCOD_SUCCESS
:
4266 case EF_IA_64_VMS_COMCOD_WARNING
:
4267 strcat (buf
, ", warning");
4269 case EF_IA_64_VMS_COMCOD_ERROR
:
4270 strcat (buf
, ", error");
4272 case EF_IA_64_VMS_COMCOD_ABORT
:
4273 strcat (buf
, ", abort");
4276 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
4277 e_flags
& EF_IA_64_VMS_COMCOD
);
4278 strcat (buf
, ", <unknown>");
4284 if ((e_flags
& EF_VAX_NONPIC
))
4285 strcat (buf
, ", non-PIC");
4286 if ((e_flags
& EF_VAX_DFLOAT
))
4287 strcat (buf
, ", D-Float");
4288 if ((e_flags
& EF_VAX_GFLOAT
))
4289 strcat (buf
, ", G-Float");
4293 if (e_flags
& EF_VISIUM_ARCH_MCM
)
4294 strcat (buf
, ", mcm");
4295 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
4296 strcat (buf
, ", mcm24");
4297 if (e_flags
& EF_VISIUM_ARCH_GR6
)
4298 strcat (buf
, ", gr6");
4302 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
4304 case E_FLAG_RL78_ANY_CPU
: break;
4305 case E_FLAG_RL78_G10
: strcat (buf
, ", G10"); break;
4306 case E_FLAG_RL78_G13
: strcat (buf
, ", G13"); break;
4307 case E_FLAG_RL78_G14
: strcat (buf
, ", G14"); break;
4309 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
4310 strcat (buf
, ", 64-bit doubles");
4314 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
4315 strcat (buf
, ", 64-bit doubles");
4316 if (e_flags
& E_FLAG_RX_DSP
)
4317 strcat (buf
, ", dsp");
4318 if (e_flags
& E_FLAG_RX_PID
)
4319 strcat (buf
, ", pid");
4320 if (e_flags
& E_FLAG_RX_ABI
)
4321 strcat (buf
, ", RX ABI");
4322 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
4323 strcat (buf
, e_flags
& E_FLAG_RX_SINSNS_YES
4324 ? ", uses String instructions" : ", bans String instructions");
4325 if (e_flags
& E_FLAG_RX_V2
)
4326 strcat (buf
, ", V2");
4327 if (e_flags
& E_FLAG_RX_V3
)
4328 strcat (buf
, ", V3");
4332 if (e_flags
& EF_S390_HIGH_GPRS
)
4333 strcat (buf
, ", highgprs");
4337 if ((e_flags
& EF_C6000_REL
))
4338 strcat (buf
, ", relocatable module");
4342 strcat (buf
, _(": architecture variant: "));
4343 switch (e_flags
& EF_MSP430_MACH
)
4345 case E_MSP430_MACH_MSP430x11
: strcat (buf
, "MSP430x11"); break;
4346 case E_MSP430_MACH_MSP430x11x1
: strcat (buf
, "MSP430x11x1 "); break;
4347 case E_MSP430_MACH_MSP430x12
: strcat (buf
, "MSP430x12"); break;
4348 case E_MSP430_MACH_MSP430x13
: strcat (buf
, "MSP430x13"); break;
4349 case E_MSP430_MACH_MSP430x14
: strcat (buf
, "MSP430x14"); break;
4350 case E_MSP430_MACH_MSP430x15
: strcat (buf
, "MSP430x15"); break;
4351 case E_MSP430_MACH_MSP430x16
: strcat (buf
, "MSP430x16"); break;
4352 case E_MSP430_MACH_MSP430x31
: strcat (buf
, "MSP430x31"); break;
4353 case E_MSP430_MACH_MSP430x32
: strcat (buf
, "MSP430x32"); break;
4354 case E_MSP430_MACH_MSP430x33
: strcat (buf
, "MSP430x33"); break;
4355 case E_MSP430_MACH_MSP430x41
: strcat (buf
, "MSP430x41"); break;
4356 case E_MSP430_MACH_MSP430x42
: strcat (buf
, "MSP430x42"); break;
4357 case E_MSP430_MACH_MSP430x43
: strcat (buf
, "MSP430x43"); break;
4358 case E_MSP430_MACH_MSP430x44
: strcat (buf
, "MSP430x44"); break;
4359 case E_MSP430_MACH_MSP430X
: strcat (buf
, "MSP430X"); break;
4361 strcat (buf
, _(": unknown")); break;
4364 if (e_flags
& ~ EF_MSP430_MACH
)
4365 strcat (buf
, _(": unknown extra flag bits also present"));
4369 switch (e_flags
& EF_Z80_MACH_MSK
)
4371 case EF_Z80_MACH_Z80
: strcat (buf
, ", Z80"); break;
4372 case EF_Z80_MACH_Z180
: strcat (buf
, ", Z180"); break;
4373 case EF_Z80_MACH_R800
: strcat (buf
, ", R800"); break;
4374 case EF_Z80_MACH_EZ80_Z80
: strcat (buf
, ", EZ80"); break;
4375 case EF_Z80_MACH_EZ80_ADL
: strcat (buf
, ", EZ80, ADL"); break;
4376 case EF_Z80_MACH_GBZ80
: strcat (buf
, ", GBZ80"); break;
4377 case EF_Z80_MACH_Z80N
: strcat (buf
, ", Z80N"); break;
4379 strcat (buf
, _(", unknown")); break;
4383 if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags
))
4384 strcat (buf
, ", SOFT-FLOAT");
4385 else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags
))
4386 strcat (buf
, ", SINGLE-FLOAT");
4387 else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags
))
4388 strcat (buf
, ", DOUBLE-FLOAT");
4390 if (EF_LOONGARCH_IS_OBJ_V0 (e_flags
))
4391 strcat (buf
, ", OBJ-v0");
4392 else if (EF_LOONGARCH_IS_OBJ_V1 (e_flags
))
4393 strcat (buf
, ", OBJ-v1");
4403 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
4405 static char buff
[32];
4409 case ELFOSABI_NONE
: return "UNIX - System V";
4410 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
4411 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
4412 case ELFOSABI_GNU
: return "UNIX - GNU";
4413 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
4414 case ELFOSABI_AIX
: return "UNIX - AIX";
4415 case ELFOSABI_IRIX
: return "UNIX - IRIX";
4416 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
4417 case ELFOSABI_TRU64
: return "UNIX - TRU64";
4418 case ELFOSABI_MODESTO
: return "Novell - Modesto";
4419 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
4420 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
4421 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
4422 case ELFOSABI_AROS
: return "AROS";
4423 case ELFOSABI_FENIXOS
: return "FenixOS";
4424 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
4425 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
4428 switch (filedata
->file_header
.e_machine
)
4433 case ELFOSABI_AMDGPU_HSA
: return "AMD HSA";
4434 case ELFOSABI_AMDGPU_PAL
: return "AMD PAL";
4435 case ELFOSABI_AMDGPU_MESA3D
: return "AMD Mesa3D";
4444 case ELFOSABI_ARM
: return "ARM";
4445 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
4456 case ELFOSABI_STANDALONE
: return _("Standalone App");
4465 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
4466 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
4475 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
4481 get_aarch64_segment_type (unsigned long type
)
4485 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
4486 case PT_AARCH64_MEMTAG_MTE
: return "AARCH64_MEMTAG_MTE";
4487 default: return NULL
;
4492 get_arm_segment_type (unsigned long type
)
4496 case PT_ARM_EXIDX
: return "EXIDX";
4497 default: return NULL
;
4502 get_s390_segment_type (unsigned long type
)
4506 case PT_S390_PGSTE
: return "S390_PGSTE";
4507 default: return NULL
;
4512 get_mips_segment_type (unsigned long type
)
4516 case PT_MIPS_REGINFO
: return "REGINFO";
4517 case PT_MIPS_RTPROC
: return "RTPROC";
4518 case PT_MIPS_OPTIONS
: return "OPTIONS";
4519 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
4520 default: return NULL
;
4525 get_parisc_segment_type (unsigned long type
)
4529 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
4530 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
4531 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
4532 default: return NULL
;
4537 get_ia64_segment_type (unsigned long type
)
4541 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
4542 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
4543 default: return NULL
;
4548 get_tic6x_segment_type (unsigned long type
)
4552 case PT_C6000_PHATTR
: return "C6000_PHATTR";
4553 default: return NULL
;
4558 get_riscv_segment_type (unsigned long type
)
4562 case PT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4563 default: return NULL
;
4568 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
4570 if (e_machine
== EM_PARISC
)
4573 case PT_HP_TLS
: return "HP_TLS";
4574 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
4575 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
4576 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
4577 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
4578 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
4579 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
4580 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
4581 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
4582 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
4583 case PT_HP_PARALLEL
: return "HP_PARALLEL";
4584 case PT_HP_FASTBIND
: return "HP_FASTBIND";
4585 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
4586 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
4587 case PT_HP_STACK
: return "HP_STACK";
4588 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
4589 default: return NULL
;
4592 if (e_machine
== EM_IA_64
)
4595 case PT_HP_TLS
: return "HP_TLS";
4596 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
4597 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
4598 case PT_IA_64_HP_STACK
: return "HP_STACK";
4599 default: return NULL
;
4606 get_solaris_segment_type (unsigned long type
)
4610 case 0x6464e550: return "PT_SUNW_UNWIND";
4611 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4612 case 0x6ffffff7: return "PT_LOSUNW";
4613 case 0x6ffffffa: return "PT_SUNWBSS";
4614 case 0x6ffffffb: return "PT_SUNWSTACK";
4615 case 0x6ffffffc: return "PT_SUNWDTRACE";
4616 case 0x6ffffffd: return "PT_SUNWCAP";
4617 case 0x6fffffff: return "PT_HISUNW";
4618 default: return NULL
;
4623 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4625 static char buff
[32];
4629 case PT_NULL
: return "NULL";
4630 case PT_LOAD
: return "LOAD";
4631 case PT_DYNAMIC
: return "DYNAMIC";
4632 case PT_INTERP
: return "INTERP";
4633 case PT_NOTE
: return "NOTE";
4634 case PT_SHLIB
: return "SHLIB";
4635 case PT_PHDR
: return "PHDR";
4636 case PT_TLS
: return "TLS";
4637 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4638 case PT_GNU_STACK
: return "GNU_STACK";
4639 case PT_GNU_RELRO
: return "GNU_RELRO";
4640 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4641 case PT_GNU_SFRAME
: return "GNU_SFRAME";
4643 case PT_OPENBSD_MUTABLE
: return "OPENBSD_MUTABLE";
4644 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
4645 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
4646 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
4649 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4651 const char * result
;
4653 switch (filedata
->file_header
.e_machine
)
4656 result
= get_aarch64_segment_type (p_type
);
4659 result
= get_arm_segment_type (p_type
);
4662 case EM_MIPS_RS3_LE
:
4663 result
= get_mips_segment_type (p_type
);
4666 result
= get_parisc_segment_type (p_type
);
4669 result
= get_ia64_segment_type (p_type
);
4672 result
= get_tic6x_segment_type (p_type
);
4676 result
= get_s390_segment_type (p_type
);
4679 result
= get_riscv_segment_type (p_type
);
4689 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4691 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4693 const char * result
= NULL
;
4695 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4698 case ELFOSABI_FREEBSD
:
4699 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4701 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4706 result
= get_hpux_segment_type (p_type
,
4707 filedata
->file_header
.e_machine
);
4709 case ELFOSABI_SOLARIS
:
4710 result
= get_solaris_segment_type (p_type
);
4718 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4721 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4728 get_arc_section_type_name (unsigned int sh_type
)
4732 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4740 get_mips_section_type_name (unsigned int sh_type
)
4744 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4745 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4746 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4747 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4748 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4749 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4750 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4751 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4752 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4753 case SHT_MIPS_RELD
: return "MIPS_RELD";
4754 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4755 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4756 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4757 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4758 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4759 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4760 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4761 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4762 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4763 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4764 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4765 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4766 case SHT_MIPS_LINE
: return "MIPS_LINE";
4767 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4768 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4769 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4770 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4771 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4772 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4773 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4774 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4775 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4776 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4777 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4778 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4779 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4780 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4781 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4782 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4783 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4784 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4792 get_parisc_section_type_name (unsigned int sh_type
)
4796 case SHT_PARISC_EXT
: return "PARISC_EXT";
4797 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4798 case SHT_PARISC_DOC
: return "PARISC_DOC";
4799 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4800 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4801 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4802 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4803 default: return NULL
;
4808 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4810 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4811 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4812 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4816 case SHT_IA_64_EXT
: return "IA_64_EXT";
4817 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4818 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4819 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4820 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4821 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4822 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4823 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4824 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4825 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4833 get_x86_64_section_type_name (unsigned int sh_type
)
4837 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4838 default: return NULL
;
4843 get_aarch64_section_type_name (unsigned int sh_type
)
4847 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4848 default: return NULL
;
4853 get_arm_section_type_name (unsigned int sh_type
)
4857 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4858 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4859 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4860 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4861 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4862 default: return NULL
;
4867 get_tic6x_section_type_name (unsigned int sh_type
)
4871 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4872 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4873 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4874 case SHT_TI_ICODE
: return "TI_ICODE";
4875 case SHT_TI_XREF
: return "TI_XREF";
4876 case SHT_TI_HANDLER
: return "TI_HANDLER";
4877 case SHT_TI_INITINFO
: return "TI_INITINFO";
4878 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4879 default: return NULL
;
4884 get_msp430_section_type_name (unsigned int sh_type
)
4888 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4889 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4890 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4891 default: return NULL
;
4896 get_nfp_section_type_name (unsigned int sh_type
)
4900 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4901 case SHT_NFP_INITREG
: return "NFP_INITREG";
4902 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4903 default: return NULL
;
4908 get_v850_section_type_name (unsigned int sh_type
)
4912 case SHT_V850_SCOMMON
: return "V850 Small Common";
4913 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4914 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4915 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4916 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4917 default: return NULL
;
4922 get_riscv_section_type_name (unsigned int sh_type
)
4926 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4927 default: return NULL
;
4932 get_csky_section_type_name (unsigned int sh_type
)
4936 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
4937 default: return NULL
;
4942 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4944 static char buff
[32];
4945 const char * result
;
4949 case SHT_NULL
: return "NULL";
4950 case SHT_PROGBITS
: return "PROGBITS";
4951 case SHT_SYMTAB
: return "SYMTAB";
4952 case SHT_STRTAB
: return "STRTAB";
4953 case SHT_RELA
: return "RELA";
4954 case SHT_RELR
: return "RELR";
4955 case SHT_HASH
: return "HASH";
4956 case SHT_DYNAMIC
: return "DYNAMIC";
4957 case SHT_NOTE
: return "NOTE";
4958 case SHT_NOBITS
: return "NOBITS";
4959 case SHT_REL
: return "REL";
4960 case SHT_SHLIB
: return "SHLIB";
4961 case SHT_DYNSYM
: return "DYNSYM";
4962 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4963 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4964 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4965 case SHT_GNU_HASH
: return "GNU_HASH";
4966 case SHT_GROUP
: return "GROUP";
4967 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4968 case SHT_GNU_verdef
: return "VERDEF";
4969 case SHT_GNU_verneed
: return "VERNEED";
4970 case SHT_GNU_versym
: return "VERSYM";
4971 case 0x6ffffff0: return "VERSYM";
4972 case 0x6ffffffc: return "VERDEF";
4973 case 0x7ffffffd: return "AUXILIARY";
4974 case 0x7fffffff: return "FILTER";
4975 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4978 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4980 switch (filedata
->file_header
.e_machine
)
4983 case EM_ARC_COMPACT
:
4984 case EM_ARC_COMPACT2
:
4985 result
= get_arc_section_type_name (sh_type
);
4988 case EM_MIPS_RS3_LE
:
4989 result
= get_mips_section_type_name (sh_type
);
4992 result
= get_parisc_section_type_name (sh_type
);
4995 result
= get_ia64_section_type_name (filedata
, sh_type
);
5000 result
= get_x86_64_section_type_name (sh_type
);
5003 result
= get_aarch64_section_type_name (sh_type
);
5006 result
= get_arm_section_type_name (sh_type
);
5009 result
= get_tic6x_section_type_name (sh_type
);
5012 result
= get_msp430_section_type_name (sh_type
);
5015 result
= get_nfp_section_type_name (sh_type
);
5019 case EM_CYGNUS_V850
:
5020 result
= get_v850_section_type_name (sh_type
);
5023 result
= get_riscv_section_type_name (sh_type
);
5026 result
= get_csky_section_type_name (sh_type
);
5036 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
5038 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
5040 switch (filedata
->file_header
.e_machine
)
5043 result
= get_ia64_section_type_name (filedata
, sh_type
);
5046 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
5047 result
= get_solaris_section_type (sh_type
);
5052 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
5053 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
5054 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
5055 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
5067 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
5069 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
5071 switch (filedata
->file_header
.e_machine
)
5075 case EM_CYGNUS_V850
:
5076 result
= get_v850_section_type_name (sh_type
);
5086 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
5089 /* This message is probably going to be displayed in a 15
5090 character wide field, so put the hex value first. */
5091 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
5097 enum long_option_values
5099 OPTION_DEBUG_DUMP
= 512,
5110 OPTION_WITH_SYMBOL_VERSIONS
,
5111 OPTION_RECURSE_LIMIT
,
5112 OPTION_NO_RECURSE_LIMIT
,
5113 OPTION_NO_DEMANGLING
,
5117 static struct option options
[] =
5119 /* Note - This table is alpha-sorted on the 'val'
5120 field in order to make adding new options easier. */
5121 {"arch-specific", no_argument
, 0, 'A'},
5122 {"all", no_argument
, 0, 'a'},
5123 {"demangle", optional_argument
, 0, 'C'},
5124 {"archive-index", no_argument
, 0, 'c'},
5125 {"use-dynamic", no_argument
, 0, 'D'},
5126 {"dynamic", no_argument
, 0, 'd'},
5127 {"headers", no_argument
, 0, 'e'},
5128 {"section-groups", no_argument
, 0, 'g'},
5129 {"help", no_argument
, 0, 'H'},
5130 {"file-header", no_argument
, 0, 'h'},
5131 {"histogram", no_argument
, 0, 'I'},
5132 {"lint", no_argument
, 0, 'L'},
5133 {"enable-checks", no_argument
, 0, 'L'},
5134 {"program-headers", no_argument
, 0, 'l'},
5135 {"segments", no_argument
, 0, 'l'},
5136 {"full-section-name",no_argument
, 0, 'N'},
5137 {"notes", no_argument
, 0, 'n'},
5138 {"process-links", no_argument
, 0, 'P'},
5139 {"string-dump", required_argument
, 0, 'p'},
5140 {"relocated-dump", required_argument
, 0, 'R'},
5141 {"relocs", no_argument
, 0, 'r'},
5142 {"section-headers", no_argument
, 0, 'S'},
5143 {"sections", no_argument
, 0, 'S'},
5144 {"symbols", no_argument
, 0, 's'},
5145 {"syms", no_argument
, 0, 's'},
5146 {"silent-truncation",no_argument
, 0, 'T'},
5147 {"section-details", no_argument
, 0, 't'},
5148 {"unicode", required_argument
, NULL
, 'U'},
5149 {"unwind", no_argument
, 0, 'u'},
5150 {"version-info", no_argument
, 0, 'V'},
5151 {"version", no_argument
, 0, 'v'},
5152 {"wide", no_argument
, 0, 'W'},
5153 {"hex-dump", required_argument
, 0, 'x'},
5154 {"decompress", no_argument
, 0, 'z'},
5156 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
5157 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
5158 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5159 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5160 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
5161 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
5162 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
5163 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
5164 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
5165 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
5166 #ifdef ENABLE_LIBCTF
5167 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
5168 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
5169 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
5170 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
5172 {"sframe", optional_argument
, 0, OPTION_SFRAME_DUMP
},
5173 {"sym-base", optional_argument
, 0, OPTION_SYM_BASE
},
5175 {0, no_argument
, 0, 0}
5179 usage (FILE * stream
)
5181 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
5182 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
5183 fprintf (stream
, _(" Options are:\n"));
5184 fprintf (stream
, _("\
5185 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
5186 fprintf (stream
, _("\
5187 -h --file-header Display the ELF file header\n"));
5188 fprintf (stream
, _("\
5189 -l --program-headers Display the program headers\n"));
5190 fprintf (stream
, _("\
5191 --segments An alias for --program-headers\n"));
5192 fprintf (stream
, _("\
5193 -S --section-headers Display the sections' header\n"));
5194 fprintf (stream
, _("\
5195 --sections An alias for --section-headers\n"));
5196 fprintf (stream
, _("\
5197 -g --section-groups Display the section groups\n"));
5198 fprintf (stream
, _("\
5199 -t --section-details Display the section details\n"));
5200 fprintf (stream
, _("\
5201 -e --headers Equivalent to: -h -l -S\n"));
5202 fprintf (stream
, _("\
5203 -s --syms Display the symbol table\n"));
5204 fprintf (stream
, _("\
5205 --symbols An alias for --syms\n"));
5206 fprintf (stream
, _("\
5207 --dyn-syms Display the dynamic symbol table\n"));
5208 fprintf (stream
, _("\
5209 --lto-syms Display LTO symbol tables\n"));
5210 fprintf (stream
, _("\
5211 --sym-base=[0|8|10|16] \n\
5212 Force base for symbol sizes. The options are \n\
5213 mixed (the default), octal, decimal, hexadecimal.\n"));
5214 fprintf (stream
, _("\
5215 -C --demangle[=STYLE] Decode mangled/processed symbol names\n"));
5216 display_demangler_styles (stream
, _("\
5218 fprintf (stream
, _("\
5219 --no-demangle Do not demangle low-level symbol names. (default)\n"));
5220 fprintf (stream
, _("\
5221 --recurse-limit Enable a demangling recursion limit. (default)\n"));
5222 fprintf (stream
, _("\
5223 --no-recurse-limit Disable a demangling recursion limit\n"));
5224 fprintf (stream
, _("\
5225 -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\
5226 Display unicode characters as determined by the current locale\n\
5227 (default), escape sequences, \"<hex sequences>\", highlighted\n\
5228 escape sequences, or treat them as invalid and display as\n\
5229 \"{hex sequences}\"\n"));
5230 fprintf (stream
, _("\
5231 -n --notes Display the core notes (if present)\n"));
5232 fprintf (stream
, _("\
5233 -r --relocs Display the relocations (if present)\n"));
5234 fprintf (stream
, _("\
5235 -u --unwind Display the unwind info (if present)\n"));
5236 fprintf (stream
, _("\
5237 -d --dynamic Display the dynamic section (if present)\n"));
5238 fprintf (stream
, _("\
5239 -V --version-info Display the version sections (if present)\n"));
5240 fprintf (stream
, _("\
5241 -A --arch-specific Display architecture specific information (if any)\n"));
5242 fprintf (stream
, _("\
5243 -c --archive-index Display the symbol/file index in an archive\n"));
5244 fprintf (stream
, _("\
5245 -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
5246 fprintf (stream
, _("\
5247 -L --lint|--enable-checks\n\
5248 Display warning messages for possible problems\n"));
5249 fprintf (stream
, _("\
5250 -x --hex-dump=<number|name>\n\
5251 Dump the contents of section <number|name> as bytes\n"));
5252 fprintf (stream
, _("\
5253 -p --string-dump=<number|name>\n\
5254 Dump the contents of section <number|name> as strings\n"));
5255 fprintf (stream
, _("\
5256 -R --relocated-dump=<number|name>\n\
5257 Dump the relocated contents of section <number|name>\n"));
5258 fprintf (stream
, _("\
5259 -z --decompress Decompress section before dumping it\n"));
5260 fprintf (stream
, _("\
5261 -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
5262 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
5263 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
5264 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
5266 Display the contents of DWARF debug sections\n"));
5267 fprintf (stream
, _("\
5268 -wk --debug-dump=links Display the contents of sections that link to separate\n\
5269 debuginfo files\n"));
5270 fprintf (stream
, _("\
5271 -P --process-links Display the contents of non-debug sections in separate\n\
5272 debuginfo files. (Implies -wK)\n"));
5273 #if DEFAULT_FOR_FOLLOW_LINKS
5274 fprintf (stream
, _("\
5275 -wK --debug-dump=follow-links\n\
5276 Follow links to separate debug info files (default)\n"));
5277 fprintf (stream
, _("\
5278 -wN --debug-dump=no-follow-links\n\
5279 Do not follow links to separate debug info files\n"));
5281 fprintf (stream
, _("\
5282 -wK --debug-dump=follow-links\n\
5283 Follow links to separate debug info files\n"));
5284 fprintf (stream
, _("\
5285 -wN --debug-dump=no-follow-links\n\
5286 Do not follow links to separate debug info files\n\
5289 #if HAVE_LIBDEBUGINFOD
5290 fprintf (stream
, _("\
5291 -wD --debug-dump=use-debuginfod\n\
5292 When following links, also query debuginfod servers (default)\n"));
5293 fprintf (stream
, _("\
5294 -wE --debug-dump=do-not-use-debuginfod\n\
5295 When following links, do not query debuginfod servers\n"));
5297 fprintf (stream
, _("\
5298 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
5299 fprintf (stream
, _("\
5300 --dwarf-start=N Display DIEs starting at offset N\n"));
5301 #ifdef ENABLE_LIBCTF
5302 fprintf (stream
, _("\
5303 --ctf=<number|name> Display CTF info from section <number|name>\n"));
5304 fprintf (stream
, _("\
5305 --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
5306 fprintf (stream
, _("\
5307 --ctf-symbols=<number|name>\n\
5308 Use section <number|name> as the CTF external symtab\n"));
5309 fprintf (stream
, _("\
5310 --ctf-strings=<number|name>\n\
5311 Use section <number|name> as the CTF external strtab\n"));
5313 fprintf (stream
, _("\
5314 --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n"));
5316 #ifdef SUPPORT_DISASSEMBLY
5317 fprintf (stream
, _("\
5318 -i --instruction-dump=<number|name>\n\
5319 Disassemble the contents of section <number|name>\n"));
5321 fprintf (stream
, _("\
5322 -I --histogram Display histogram of bucket list lengths\n"));
5323 fprintf (stream
, _("\
5324 -W --wide Allow output width to exceed 80 characters\n"));
5325 fprintf (stream
, _("\
5326 -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
5327 fprintf (stream
, _("\
5328 @<file> Read options from <file>\n"));
5329 fprintf (stream
, _("\
5330 -H --help Display this information\n"));
5331 fprintf (stream
, _("\
5332 -v --version Display the version number of readelf\n"));
5334 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
5335 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
5337 exit (stream
== stdout
? 0 : 1);
5340 /* Record the fact that the user wants the contents of section number
5341 SECTION to be displayed using the method(s) encoded as flags bits
5342 in TYPE. Note, TYPE can be zero if we are creating the array for
5346 request_dump_bynumber (struct dump_data
*dumpdata
,
5347 unsigned int section
, dump_type type
)
5349 if (section
>= dumpdata
->num_dump_sects
)
5351 dump_type
* new_dump_sects
;
5353 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
5354 sizeof (* new_dump_sects
));
5356 if (new_dump_sects
== NULL
)
5357 error (_("Out of memory allocating dump request table.\n"));
5360 if (dumpdata
->dump_sects
)
5362 /* Copy current flag settings. */
5363 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
5364 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
5366 free (dumpdata
->dump_sects
);
5369 dumpdata
->dump_sects
= new_dump_sects
;
5370 dumpdata
->num_dump_sects
= section
+ 1;
5374 if (dumpdata
->dump_sects
)
5375 dumpdata
->dump_sects
[section
] |= type
;
5378 /* Request a dump by section name. */
5381 request_dump_byname (const char * section
, dump_type type
)
5383 struct dump_list_entry
* new_request
;
5385 new_request
= (struct dump_list_entry
*)
5386 malloc (sizeof (struct dump_list_entry
));
5388 error (_("Out of memory allocating dump request table.\n"));
5390 new_request
->name
= strdup (section
);
5391 if (!new_request
->name
)
5392 error (_("Out of memory allocating dump request table.\n"));
5394 new_request
->type
= type
;
5396 new_request
->next
= dump_sects_byname
;
5397 dump_sects_byname
= new_request
;
5401 request_dump (struct dump_data
*dumpdata
, dump_type type
)
5407 section
= strtoul (optarg
, & cp
, 0);
5409 if (! *cp
&& section
>= 0)
5410 request_dump_bynumber (dumpdata
, section
, type
);
5412 request_dump_byname (optarg
, type
);
5416 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
5423 while ((c
= getopt_long
5424 (argc
, argv
, "ACDHILNPR:STU:VWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
5442 do_section_groups
= true;
5445 do_histogram
= true;
5451 do_section_groups
= true;
5456 do_section_details
= true;
5467 do_using_dynamic
= true;
5491 do_histogram
= true;
5497 do_archive_index
= true;
5503 process_links
= true;
5504 do_follow_links
= true;
5505 dump_any_debugging
= true;
5508 request_dump (dumpdata
, HEX_DUMP
);
5511 request_dump (dumpdata
, STRING_DUMP
);
5514 request_dump (dumpdata
, RELOC_DUMP
);
5517 decompress_dumps
= true;
5522 do_debugging
= true;
5524 dump_any_debugging
= true;
5525 dwarf_select_sections_all ();
5529 do_debugging
= false;
5530 if (dwarf_select_sections_by_letters (optarg
))
5533 dump_any_debugging
= true;
5537 case OPTION_DEBUG_DUMP
:
5541 do_debugging
= true;
5542 dump_any_debugging
= true;
5543 dwarf_select_sections_all ();
5547 do_debugging
= false;
5548 if (dwarf_select_sections_by_names (optarg
))
5551 dump_any_debugging
= true;
5555 case OPTION_DWARF_DEPTH
:
5559 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5562 case OPTION_DWARF_START
:
5566 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5569 case OPTION_DWARF_CHECK
:
5572 case OPTION_CTF_DUMP
:
5574 request_dump (dumpdata
, CTF_DUMP
);
5576 case OPTION_CTF_SYMBOLS
:
5577 free (dump_ctf_symtab_name
);
5578 dump_ctf_symtab_name
= strdup (optarg
);
5580 case OPTION_CTF_STRINGS
:
5581 free (dump_ctf_strtab_name
);
5582 dump_ctf_strtab_name
= strdup (optarg
);
5584 case OPTION_CTF_PARENT
:
5585 free (dump_ctf_parent_name
);
5586 dump_ctf_parent_name
= strdup (optarg
);
5588 case OPTION_SFRAME_DUMP
:
5590 /* Providing section name is optional. request_dump (), however,
5591 thrives on non NULL optarg. Handle it explicitly here. */
5593 request_dump (dumpdata
, SFRAME_DUMP
);
5597 const char *sframe_sec_name
= strdup (".sframe");
5598 request_dump_byname (sframe_sec_name
, SFRAME_DUMP
);
5601 case OPTION_DYN_SYMS
:
5604 case OPTION_LTO_SYMS
:
5607 #ifdef SUPPORT_DISASSEMBLY
5609 request_dump (dumpdata
, DISASS_DUMP
);
5613 print_version (program_name
);
5622 do_not_show_symbol_truncation
= true;
5628 enum demangling_styles style
;
5630 style
= cplus_demangle_name_to_style (optarg
);
5631 if (style
== unknown_demangling
)
5632 error (_("unknown demangling style `%s'"), optarg
);
5634 cplus_demangle_set_style (style
);
5637 case OPTION_NO_DEMANGLING
:
5638 do_demangle
= false;
5640 case OPTION_RECURSE_LIMIT
:
5641 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5643 case OPTION_NO_RECURSE_LIMIT
:
5644 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5646 case OPTION_WITH_SYMBOL_VERSIONS
:
5647 /* Ignored for backward compatibility. */
5652 error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
5653 else if (streq (optarg
, "default") || streq (optarg
, "d"))
5654 unicode_display
= unicode_default
;
5655 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
5656 unicode_display
= unicode_locale
;
5657 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
5658 unicode_display
= unicode_escape
;
5659 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
5660 unicode_display
= unicode_invalid
;
5661 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
5662 unicode_display
= unicode_hex
;
5663 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
5664 unicode_display
= unicode_highlight
;
5666 error (_("invalid argument to -U/--unicode: %s"), optarg
);
5669 case OPTION_SYM_BASE
:
5673 sym_base
= strtoul (optarg
, NULL
, 0);
5690 /* xgettext:c-format */
5691 error (_("Invalid option '-%c'\n"), c
);
5698 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
5699 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
5700 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
5701 && !do_section_groups
&& !do_archive_index
5702 && !do_dyn_syms
&& !do_lto_syms
)
5707 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
5708 do_segments
= do_header
= do_dump
= do_version
= true;
5709 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
5710 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
5719 get_elf_class (unsigned int elf_class
)
5721 static char buff
[32];
5725 case ELFCLASSNONE
: return _("none");
5726 case ELFCLASS32
: return "ELF32";
5727 case ELFCLASS64
: return "ELF64";
5729 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
5735 get_data_encoding (unsigned int encoding
)
5737 static char buff
[32];
5741 case ELFDATANONE
: return _("none");
5742 case ELFDATA2LSB
: return _("2's complement, little endian");
5743 case ELFDATA2MSB
: return _("2's complement, big endian");
5745 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
5751 check_magic_number (Filedata
* filedata
, Elf_Internal_Ehdr
* header
)
5753 if (header
->e_ident
[EI_MAG0
] == ELFMAG0
5754 && header
->e_ident
[EI_MAG1
] == ELFMAG1
5755 && header
->e_ident
[EI_MAG2
] == ELFMAG2
5756 && header
->e_ident
[EI_MAG3
] == ELFMAG3
)
5759 /* Some compilers produce object files that are not in the ELF file format.
5760 As an aid to users of readelf, try to identify these cases and suggest
5763 FIXME: It is not clear if all four bytes are used as constant magic
5764 valus by all compilers. It may be necessary to recode this function if
5765 different tools use different length sequences. */
5769 unsigned char magic
[4];
5770 const char * obj_message
;
5771 const char * ar_message
;
5775 { { 'B', 'C', 0xc0, 0xde },
5776 N_("This is a LLVM bitcode file - try using llvm-bcanalyzer\n"),
5777 N_("This is a LLVM bitcode file - try extracing and then using llvm-bcanalyzer\n")
5779 { { 'g', 'o', ' ', 'o' },
5780 N_("This is a GO binary file - try using 'go tool objdump' or 'go tool nm'\n"),
5786 for (i
= ARRAY_SIZE (known_magic
); i
--;)
5788 if (header
->e_ident
[EI_MAG0
] == known_magic
[i
].magic
[0]
5789 && header
->e_ident
[EI_MAG1
] == known_magic
[i
].magic
[1]
5790 && header
->e_ident
[EI_MAG2
] == known_magic
[i
].magic
[2]
5791 && header
->e_ident
[EI_MAG3
] == known_magic
[i
].magic
[3])
5793 /* Some compiler's analyzer tools do not handle archives,
5794 so we provide two different kinds of error message. */
5795 if (filedata
->archive_file_size
> 0
5796 && known_magic
[i
].ar_message
!= NULL
)
5797 error ("%s", known_magic
[i
].ar_message
);
5799 error ("%s", known_magic
[i
].obj_message
);
5804 error (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
5808 /* Decode the data held in 'filedata->file_header'. */
5811 process_file_header (Filedata
* filedata
)
5813 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
5815 if (! check_magic_number (filedata
, header
))
5818 if (! filedata
->is_separate
)
5819 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
5825 if (filedata
->is_separate
)
5826 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
5828 printf (_("ELF Header:\n"));
5829 printf (_(" Magic: "));
5830 for (i
= 0; i
< EI_NIDENT
; i
++)
5831 printf ("%2.2x ", header
->e_ident
[i
]);
5833 printf (_(" Class: %s\n"),
5834 get_elf_class (header
->e_ident
[EI_CLASS
]));
5835 printf (_(" Data: %s\n"),
5836 get_data_encoding (header
->e_ident
[EI_DATA
]));
5837 printf (_(" Version: %d%s\n"),
5838 header
->e_ident
[EI_VERSION
],
5839 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
5841 : (header
->e_ident
[EI_VERSION
] != EV_NONE
5844 printf (_(" OS/ABI: %s\n"),
5845 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
5846 printf (_(" ABI Version: %d\n"),
5847 header
->e_ident
[EI_ABIVERSION
]);
5848 printf (_(" Type: %s\n"),
5849 get_file_type (filedata
));
5850 printf (_(" Machine: %s\n"),
5851 get_machine_name (header
->e_machine
));
5852 printf (_(" Version: 0x%lx\n"),
5855 printf (_(" Entry point address: "));
5856 print_vma (header
->e_entry
, PREFIX_HEX
);
5857 printf (_("\n Start of program headers: "));
5858 print_vma (header
->e_phoff
, DEC
);
5859 printf (_(" (bytes into file)\n Start of section headers: "));
5860 print_vma (header
->e_shoff
, DEC
);
5861 printf (_(" (bytes into file)\n"));
5863 printf (_(" Flags: 0x%lx%s\n"),
5865 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
5866 printf (_(" Size of this header: %u (bytes)\n"),
5868 printf (_(" Size of program headers: %u (bytes)\n"),
5869 header
->e_phentsize
);
5870 printf (_(" Number of program headers: %u"),
5872 if (filedata
->section_headers
!= NULL
5873 && header
->e_phnum
== PN_XNUM
5874 && filedata
->section_headers
[0].sh_info
!= 0)
5875 printf (" (%u)", filedata
->section_headers
[0].sh_info
);
5876 putc ('\n', stdout
);
5877 printf (_(" Size of section headers: %u (bytes)\n"),
5878 header
->e_shentsize
);
5879 printf (_(" Number of section headers: %u"),
5881 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
5883 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5884 printf (" (%u)", header
->e_shnum
);
5886 putc ('\n', stdout
);
5887 printf (_(" Section header string table index: %u"),
5888 header
->e_shstrndx
);
5889 if (filedata
->section_headers
!= NULL
5890 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5892 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5893 printf (" (%u)", header
->e_shstrndx
);
5895 if (header
->e_shstrndx
!= SHN_UNDEF
5896 && header
->e_shstrndx
>= header
->e_shnum
)
5898 header
->e_shstrndx
= SHN_UNDEF
;
5899 printf (_(" <corrupt: out of range>"));
5901 putc ('\n', stdout
);
5904 if (filedata
->section_headers
!= NULL
)
5906 if (header
->e_phnum
== PN_XNUM
5907 && filedata
->section_headers
[0].sh_info
!= 0)
5909 /* Throw away any cached read of PN_XNUM headers. */
5910 free (filedata
->program_headers
);
5911 filedata
->program_headers
= NULL
;
5912 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5914 if (header
->e_shnum
== SHN_UNDEF
)
5915 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5916 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5917 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5918 if (header
->e_shstrndx
>= header
->e_shnum
)
5919 header
->e_shstrndx
= SHN_UNDEF
;
5925 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5926 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5929 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5931 Elf32_External_Phdr
* phdrs
;
5932 Elf32_External_Phdr
* external
;
5933 Elf_Internal_Phdr
* internal
;
5935 unsigned int size
= filedata
->file_header
.e_phentsize
;
5936 unsigned int num
= filedata
->file_header
.e_phnum
;
5938 /* PR binutils/17531: Cope with unexpected section header sizes. */
5939 if (size
== 0 || num
== 0)
5941 if (size
< sizeof * phdrs
)
5943 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5946 if (size
> sizeof * phdrs
)
5947 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5949 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5950 size
, num
, _("program headers"));
5954 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5955 i
< filedata
->file_header
.e_phnum
;
5956 i
++, internal
++, external
++)
5958 internal
->p_type
= BYTE_GET (external
->p_type
);
5959 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5960 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5961 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5962 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5963 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5964 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5965 internal
->p_align
= BYTE_GET (external
->p_align
);
5972 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5973 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5976 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5978 Elf64_External_Phdr
* phdrs
;
5979 Elf64_External_Phdr
* external
;
5980 Elf_Internal_Phdr
* internal
;
5982 unsigned int size
= filedata
->file_header
.e_phentsize
;
5983 unsigned int num
= filedata
->file_header
.e_phnum
;
5985 /* PR binutils/17531: Cope with unexpected section header sizes. */
5986 if (size
== 0 || num
== 0)
5988 if (size
< sizeof * phdrs
)
5990 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5993 if (size
> sizeof * phdrs
)
5994 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5996 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5997 size
, num
, _("program headers"));
6001 for (i
= 0, internal
= pheaders
, external
= phdrs
;
6002 i
< filedata
->file_header
.e_phnum
;
6003 i
++, internal
++, external
++)
6005 internal
->p_type
= BYTE_GET (external
->p_type
);
6006 internal
->p_flags
= BYTE_GET (external
->p_flags
);
6007 internal
->p_offset
= BYTE_GET (external
->p_offset
);
6008 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
6009 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
6010 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
6011 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
6012 internal
->p_align
= BYTE_GET (external
->p_align
);
6019 /* Returns TRUE if the program headers were read into `program_headers'. */
6022 get_program_headers (Filedata
* filedata
)
6024 Elf_Internal_Phdr
* phdrs
;
6026 /* Check cache of prior read. */
6027 if (filedata
->program_headers
!= NULL
)
6030 /* Be kind to memory checkers by looking for
6031 e_phnum values which we know must be invalid. */
6032 if (filedata
->file_header
.e_phnum
6033 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
6034 >= filedata
->file_size
)
6036 error (_("Too many program headers - %#x - the file is not that big\n"),
6037 filedata
->file_header
.e_phnum
);
6041 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
6042 sizeof (Elf_Internal_Phdr
));
6045 error (_("Out of memory reading %u program headers\n"),
6046 filedata
->file_header
.e_phnum
);
6051 ? get_32bit_program_headers (filedata
, phdrs
)
6052 : get_64bit_program_headers (filedata
, phdrs
))
6054 filedata
->program_headers
= phdrs
;
6062 /* Print program header info and locate dynamic section. */
6065 process_program_headers (Filedata
* filedata
)
6067 Elf_Internal_Phdr
* segment
;
6069 Elf_Internal_Phdr
* previous_load
= NULL
;
6071 if (filedata
->file_header
.e_phnum
== 0)
6073 /* PR binutils/12467. */
6074 if (filedata
->file_header
.e_phoff
!= 0)
6075 warn (_("possibly corrupt ELF header - it has a non-zero program"
6076 " header offset, but no program headers\n"));
6077 else if (do_segments
)
6079 if (filedata
->is_separate
)
6080 printf (_("\nThere are no program headers in linked file '%s'.\n"),
6081 filedata
->file_name
);
6083 printf (_("\nThere are no program headers in this file.\n"));
6088 if (do_segments
&& !do_header
)
6090 if (filedata
->is_separate
)
6091 printf ("\nIn linked file '%s' the ELF file type is %s\n",
6092 filedata
->file_name
, get_file_type (filedata
));
6094 printf (_("\nElf file type is %s\n"), get_file_type (filedata
));
6095 printf (_("Entry point 0x%" PRIx64
"\n"),
6096 filedata
->file_header
.e_entry
);
6097 printf (ngettext ("There is %d program header,"
6098 " starting at offset %" PRIu64
"\n",
6099 "There are %d program headers,"
6100 " starting at offset %" PRIu64
"\n",
6101 filedata
->file_header
.e_phnum
),
6102 filedata
->file_header
.e_phnum
,
6103 filedata
->file_header
.e_phoff
);
6106 if (! get_program_headers (filedata
))
6111 if (filedata
->file_header
.e_phnum
> 1)
6112 printf (_("\nProgram Headers:\n"));
6114 printf (_("\nProgram Headers:\n"));
6118 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6121 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6125 (_(" Type Offset VirtAddr PhysAddr\n"));
6127 (_(" FileSiz MemSiz Flags Align\n"));
6131 uint64_t dynamic_addr
= 0;
6132 uint64_t dynamic_size
= 0;
6133 for (i
= 0, segment
= filedata
->program_headers
;
6134 i
< filedata
->file_header
.e_phnum
;
6139 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
6143 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6144 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
6145 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
6146 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
6147 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
6149 (segment
->p_flags
& PF_R
? 'R' : ' '),
6150 (segment
->p_flags
& PF_W
? 'W' : ' '),
6151 (segment
->p_flags
& PF_X
? 'E' : ' '));
6152 printf ("%#lx", (unsigned long) segment
->p_align
);
6156 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
6157 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6160 print_vma (segment
->p_offset
, FULL_HEX
);
6164 print_vma (segment
->p_vaddr
, FULL_HEX
);
6166 print_vma (segment
->p_paddr
, FULL_HEX
);
6169 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
6170 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
6173 print_vma (segment
->p_filesz
, FULL_HEX
);
6177 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
6178 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
6181 print_vma (segment
->p_memsz
, FULL_HEX
);
6185 (segment
->p_flags
& PF_R
? 'R' : ' '),
6186 (segment
->p_flags
& PF_W
? 'W' : ' '),
6187 (segment
->p_flags
& PF_X
? 'E' : ' '));
6189 if ((unsigned long) segment
->p_align
== segment
->p_align
)
6190 printf ("%#lx", (unsigned long) segment
->p_align
);
6193 print_vma (segment
->p_align
, PREFIX_HEX
);
6198 print_vma (segment
->p_offset
, FULL_HEX
);
6200 print_vma (segment
->p_vaddr
, FULL_HEX
);
6202 print_vma (segment
->p_paddr
, FULL_HEX
);
6204 print_vma (segment
->p_filesz
, FULL_HEX
);
6206 print_vma (segment
->p_memsz
, FULL_HEX
);
6208 (segment
->p_flags
& PF_R
? 'R' : ' '),
6209 (segment
->p_flags
& PF_W
? 'W' : ' '),
6210 (segment
->p_flags
& PF_X
? 'E' : ' '));
6211 print_vma (segment
->p_align
, PREFIX_HEX
);
6214 putc ('\n', stdout
);
6217 switch (segment
->p_type
)
6220 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
6221 required by the ELF standard, several programs, including the Linux
6222 kernel, make use of non-ordered segments. */
6224 && previous_load
->p_vaddr
> segment
->p_vaddr
)
6225 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
6227 if (segment
->p_memsz
< segment
->p_filesz
)
6228 error (_("the segment's file size is larger than its memory size\n"));
6229 previous_load
= segment
;
6233 /* PR 20815 - Verify that the program header is loaded into memory. */
6234 if (i
> 0 && previous_load
!= NULL
)
6235 error (_("the PHDR segment must occur before any LOAD segment\n"));
6236 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
6240 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
6242 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
6243 if (load
->p_type
== PT_LOAD
6244 && load
->p_offset
<= segment
->p_offset
6245 && (load
->p_offset
+ load
->p_filesz
6246 >= segment
->p_offset
+ segment
->p_filesz
)
6247 && load
->p_vaddr
<= segment
->p_vaddr
6248 && (load
->p_vaddr
+ load
->p_filesz
6249 >= segment
->p_vaddr
+ segment
->p_filesz
))
6252 if (j
== filedata
->file_header
.e_phnum
)
6253 error (_("the PHDR segment is not covered by a LOAD segment\n"));
6259 error (_("more than one dynamic segment\n"));
6261 /* By default, assume that the .dynamic section is the first
6262 section in the DYNAMIC segment. */
6263 dynamic_addr
= segment
->p_offset
;
6264 dynamic_size
= segment
->p_filesz
;
6266 /* Try to locate the .dynamic section. If there is
6267 a section header table, we can easily locate it. */
6268 if (filedata
->section_headers
!= NULL
)
6270 Elf_Internal_Shdr
* sec
;
6272 sec
= find_section (filedata
, ".dynamic");
6273 if (sec
== NULL
|| sec
->sh_size
== 0)
6275 /* A corresponding .dynamic section is expected, but on
6276 IA-64/OpenVMS it is OK for it to be missing. */
6277 if (!is_ia64_vms (filedata
))
6278 error (_("no .dynamic section in the dynamic segment\n"));
6282 if (sec
->sh_type
== SHT_NOBITS
)
6289 dynamic_addr
= sec
->sh_offset
;
6290 dynamic_size
= sec
->sh_size
;
6292 /* The PT_DYNAMIC segment, which is used by the run-time
6293 loader, should exactly match the .dynamic section. */
6295 && (dynamic_addr
!= segment
->p_offset
6296 || dynamic_size
!= segment
->p_filesz
))
6298 the .dynamic section is not the same as the dynamic segment\n"));
6301 /* PR binutils/17512: Avoid corrupt dynamic section info in the
6302 segment. Check this after matching against the section headers
6303 so we don't warn on debuginfo file (which have NOBITS .dynamic
6305 if (dynamic_addr
> filedata
->file_size
6306 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
6308 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
6315 if (segment
->p_offset
>= filedata
->file_size
6316 || segment
->p_filesz
> filedata
->file_size
- segment
->p_offset
6317 || segment
->p_filesz
- 1 >= (size_t) -2
6318 || fseek64 (filedata
->handle
,
6319 filedata
->archive_file_offset
+ segment
->p_offset
,
6321 error (_("Unable to find program interpreter name\n"));
6324 size_t len
= segment
->p_filesz
;
6325 free (filedata
->program_interpreter
);
6326 filedata
->program_interpreter
= xmalloc (len
+ 1);
6327 len
= fread (filedata
->program_interpreter
, 1, len
,
6329 filedata
->program_interpreter
[len
] = 0;
6332 printf (_(" [Requesting program interpreter: %s]\n"),
6333 filedata
->program_interpreter
);
6340 && filedata
->section_headers
!= NULL
6341 && filedata
->string_table
!= NULL
)
6343 printf (_("\n Section to Segment mapping:\n"));
6344 printf (_(" Segment Sections...\n"));
6346 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
6349 Elf_Internal_Shdr
* section
;
6351 segment
= filedata
->program_headers
+ i
;
6352 section
= filedata
->section_headers
+ 1;
6354 printf (" %2.2d ", i
);
6356 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
6358 if (!ELF_TBSS_SPECIAL (section
, segment
)
6359 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
6360 printf ("%s ", printable_section_name (filedata
, section
));
6367 filedata
->dynamic_addr
= dynamic_addr
;
6368 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
6372 filedata
->dynamic_addr
= 0;
6373 filedata
->dynamic_size
= 1;
6377 /* Find the file offset corresponding to VMA by using the program headers. */
6380 offset_from_vma (Filedata
* filedata
, uint64_t vma
, uint64_t size
)
6382 Elf_Internal_Phdr
* seg
;
6384 if (! get_program_headers (filedata
))
6386 warn (_("Cannot interpret virtual addresses without program headers.\n"));
6390 for (seg
= filedata
->program_headers
;
6391 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
6394 if (seg
->p_type
!= PT_LOAD
)
6397 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
6398 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
6399 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
6402 warn (_("Virtual address %#" PRIx64
6403 " not located in any PT_LOAD segment.\n"), vma
);
6408 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
6409 If PROBE is true, this is just a probe and we do not generate any error
6410 messages if the load fails. */
6413 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
6415 Elf32_External_Shdr
* shdrs
;
6416 Elf_Internal_Shdr
* internal
;
6418 unsigned int size
= filedata
->file_header
.e_shentsize
;
6419 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6421 /* PR binutils/17531: Cope with unexpected section header sizes. */
6422 if (size
== 0 || num
== 0)
6425 /* The section header cannot be at the start of the file - that is
6426 where the ELF file header is located. A file with absolutely no
6427 sections in it will use a shoff of 0. */
6428 if (filedata
->file_header
.e_shoff
== 0)
6431 if (size
< sizeof * shdrs
)
6434 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6437 if (!probe
&& size
> sizeof * shdrs
)
6438 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6440 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
6442 probe
? NULL
: _("section headers"));
6446 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6447 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6448 if (filedata
->section_headers
== NULL
)
6451 error (_("Out of memory reading %u section headers\n"), num
);
6456 for (i
= 0, internal
= filedata
->section_headers
;
6460 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6461 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6462 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6463 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6464 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6465 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6466 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6467 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6468 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6469 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6470 if (!probe
&& internal
->sh_link
> num
)
6471 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6472 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6473 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6480 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
6483 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
6485 Elf64_External_Shdr
* shdrs
;
6486 Elf_Internal_Shdr
* internal
;
6488 unsigned int size
= filedata
->file_header
.e_shentsize
;
6489 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6491 /* PR binutils/17531: Cope with unexpected section header sizes. */
6492 if (size
== 0 || num
== 0)
6495 /* The section header cannot be at the start of the file - that is
6496 where the ELF file header is located. A file with absolutely no
6497 sections in it will use a shoff of 0. */
6498 if (filedata
->file_header
.e_shoff
== 0)
6501 if (size
< sizeof * shdrs
)
6504 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6508 if (! probe
&& size
> sizeof * shdrs
)
6509 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6511 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
6512 filedata
->file_header
.e_shoff
,
6514 probe
? NULL
: _("section headers"));
6518 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6519 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6520 if (filedata
->section_headers
== NULL
)
6523 error (_("Out of memory reading %u section headers\n"), num
);
6528 for (i
= 0, internal
= filedata
->section_headers
;
6532 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6533 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6534 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6535 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6536 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6537 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6538 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6539 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6540 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6541 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6542 if (!probe
&& internal
->sh_link
> num
)
6543 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6544 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6545 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6553 get_section_headers (Filedata
*filedata
, bool probe
)
6555 if (filedata
->section_headers
!= NULL
)
6559 return get_32bit_section_headers (filedata
, probe
);
6561 return get_64bit_section_headers (filedata
, probe
);
6564 static Elf_Internal_Sym
*
6565 get_32bit_elf_symbols (Filedata
*filedata
,
6566 Elf_Internal_Shdr
*section
,
6567 uint64_t *num_syms_return
)
6569 uint64_t number
= 0;
6570 Elf32_External_Sym
* esyms
= NULL
;
6571 Elf_External_Sym_Shndx
* shndx
= NULL
;
6572 Elf_Internal_Sym
* isyms
= NULL
;
6573 Elf_Internal_Sym
* psym
;
6575 elf_section_list
* entry
;
6577 if (section
->sh_size
== 0)
6579 if (num_syms_return
!= NULL
)
6580 * num_syms_return
= 0;
6584 /* Run some sanity checks first. */
6585 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6587 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
6588 printable_section_name (filedata
, section
),
6589 section
->sh_entsize
);
6593 if (section
->sh_size
> filedata
->file_size
)
6595 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
6596 printable_section_name (filedata
, section
),
6601 number
= section
->sh_size
/ section
->sh_entsize
;
6603 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
6605 error (_("Size (%#" PRIx64
") of section %s "
6606 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
6608 printable_section_name (filedata
, section
),
6609 section
->sh_entsize
);
6613 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6614 section
->sh_size
, _("symbols"));
6619 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6621 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
6626 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6630 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6631 entry
->hdr
->sh_offset
,
6632 1, entry
->hdr
->sh_size
,
6633 _("symbol table section indices"));
6637 /* PR17531: file: heap-buffer-overflow */
6638 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6640 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
6641 printable_section_name (filedata
, entry
->hdr
),
6642 entry
->hdr
->sh_size
,
6648 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6652 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
6656 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6658 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6659 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6660 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6661 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6662 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6664 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6665 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6666 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6667 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6668 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6675 if (num_syms_return
!= NULL
)
6676 * num_syms_return
= isyms
== NULL
? 0 : number
;
6681 static Elf_Internal_Sym
*
6682 get_64bit_elf_symbols (Filedata
*filedata
,
6683 Elf_Internal_Shdr
*section
,
6684 uint64_t *num_syms_return
)
6686 uint64_t number
= 0;
6687 Elf64_External_Sym
* esyms
= NULL
;
6688 Elf_External_Sym_Shndx
* shndx
= NULL
;
6689 Elf_Internal_Sym
* isyms
= NULL
;
6690 Elf_Internal_Sym
* psym
;
6692 elf_section_list
* entry
;
6694 if (section
->sh_size
== 0)
6696 if (num_syms_return
!= NULL
)
6697 * num_syms_return
= 0;
6701 /* Run some sanity checks first. */
6702 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6704 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
6705 printable_section_name (filedata
, section
),
6706 section
->sh_entsize
);
6710 if (section
->sh_size
> filedata
->file_size
)
6712 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
6713 printable_section_name (filedata
, section
),
6718 number
= section
->sh_size
/ section
->sh_entsize
;
6720 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
6722 error (_("Size (%#" PRIx64
") of section %s "
6723 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
6725 printable_section_name (filedata
, section
),
6726 section
->sh_entsize
);
6730 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6731 section
->sh_size
, _("symbols"));
6736 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6738 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
6743 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6747 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6748 entry
->hdr
->sh_offset
,
6749 1, entry
->hdr
->sh_size
,
6750 _("symbol table section indices"));
6754 /* PR17531: file: heap-buffer-overflow */
6755 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6757 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
6758 printable_section_name (filedata
, entry
->hdr
),
6759 entry
->hdr
->sh_size
,
6765 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6769 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
6773 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6775 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6776 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6777 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6778 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6780 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6782 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6783 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6784 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6786 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6787 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6794 if (num_syms_return
!= NULL
)
6795 * num_syms_return
= isyms
== NULL
? 0 : number
;
6800 static Elf_Internal_Sym
*
6801 get_elf_symbols (Filedata
*filedata
,
6802 Elf_Internal_Shdr
*section
,
6803 uint64_t *num_syms_return
)
6806 return get_32bit_elf_symbols (filedata
, section
, num_syms_return
);
6808 return get_64bit_elf_symbols (filedata
, section
, num_syms_return
);
6812 get_elf_section_flags (Filedata
* filedata
, uint64_t sh_flags
)
6814 static char buff
[1024];
6816 unsigned int field_size
= is_32bit_elf
? 8 : 16;
6818 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
6819 uint64_t os_flags
= 0;
6820 uint64_t proc_flags
= 0;
6821 uint64_t unknown_flags
= 0;
6829 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
6830 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
6831 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
6832 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
6833 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
6834 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
6835 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
6836 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
6837 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
6838 /* 9 */ { STRING_COMMA_LEN ("TLS") },
6839 /* IA-64 specific. */
6840 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
6841 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
6842 /* IA-64 OpenVMS specific. */
6843 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
6844 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
6845 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
6846 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
6847 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
6848 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
6850 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
6851 /* SPARC specific. */
6852 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
6853 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
6855 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
6856 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
6857 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
6859 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
6861 /* 25 */ { STRING_COMMA_LEN ("VLE") },
6863 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
6866 if (do_section_details
)
6868 sprintf (buff
, "[%*.*lx]: ",
6869 field_size
, field_size
, (unsigned long) sh_flags
);
6870 p
+= field_size
+ 4;
6877 flag
= sh_flags
& - sh_flags
;
6880 if (do_section_details
)
6884 case SHF_WRITE
: sindex
= 0; break;
6885 case SHF_ALLOC
: sindex
= 1; break;
6886 case SHF_EXECINSTR
: sindex
= 2; break;
6887 case SHF_MERGE
: sindex
= 3; break;
6888 case SHF_STRINGS
: sindex
= 4; break;
6889 case SHF_INFO_LINK
: sindex
= 5; break;
6890 case SHF_LINK_ORDER
: sindex
= 6; break;
6891 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
6892 case SHF_GROUP
: sindex
= 8; break;
6893 case SHF_TLS
: sindex
= 9; break;
6894 case SHF_EXCLUDE
: sindex
= 18; break;
6895 case SHF_COMPRESSED
: sindex
= 20; break;
6899 switch (filedata
->file_header
.e_machine
)
6902 if (flag
== SHF_IA_64_SHORT
)
6904 else if (flag
== SHF_IA_64_NORECOV
)
6906 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
6909 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
6910 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
6911 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
6912 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
6913 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
6914 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
6924 case EM_OLD_SPARCV9
:
6925 case EM_SPARC32PLUS
:
6928 if (flag
== SHF_ORDERED
)
6935 case SHF_ENTRYSECT
: sindex
= 21; break;
6936 case SHF_ARM_PURECODE
: sindex
= 22; break;
6937 case SHF_COMDEF
: sindex
= 23; break;
6942 if (flag
== SHF_PPC_VLE
)
6949 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6952 case ELFOSABI_FREEBSD
:
6953 if (flag
== SHF_GNU_RETAIN
)
6957 if (flag
== SHF_GNU_MBIND
)
6958 /* We should not recognize SHF_GNU_MBIND for
6959 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6960 not set the EI_OSABI header byte. */
6971 if (p
!= buff
+ field_size
+ 4)
6973 if (size
< (10 + 2))
6975 warn (_("Internal error: not enough buffer room for section flag info"));
6976 return _("<unknown>");
6983 size
-= flags
[sindex
].len
;
6984 p
= stpcpy (p
, flags
[sindex
].str
);
6986 else if (flag
& SHF_MASKOS
)
6988 else if (flag
& SHF_MASKPROC
)
6991 unknown_flags
|= flag
;
6997 case SHF_WRITE
: *p
= 'W'; break;
6998 case SHF_ALLOC
: *p
= 'A'; break;
6999 case SHF_EXECINSTR
: *p
= 'X'; break;
7000 case SHF_MERGE
: *p
= 'M'; break;
7001 case SHF_STRINGS
: *p
= 'S'; break;
7002 case SHF_INFO_LINK
: *p
= 'I'; break;
7003 case SHF_LINK_ORDER
: *p
= 'L'; break;
7004 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
7005 case SHF_GROUP
: *p
= 'G'; break;
7006 case SHF_TLS
: *p
= 'T'; break;
7007 case SHF_EXCLUDE
: *p
= 'E'; break;
7008 case SHF_COMPRESSED
: *p
= 'C'; break;
7011 if ((filedata
->file_header
.e_machine
== EM_X86_64
7012 || filedata
->file_header
.e_machine
== EM_L1OM
7013 || filedata
->file_header
.e_machine
== EM_K1OM
)
7014 && flag
== SHF_X86_64_LARGE
)
7016 else if (filedata
->file_header
.e_machine
== EM_ARM
7017 && flag
== SHF_ARM_PURECODE
)
7019 else if (filedata
->file_header
.e_machine
== EM_PPC
7020 && flag
== SHF_PPC_VLE
)
7022 else if (flag
& SHF_MASKOS
)
7024 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7027 case ELFOSABI_FREEBSD
:
7028 if (flag
== SHF_GNU_RETAIN
)
7035 if (flag
== SHF_GNU_MBIND
)
7037 /* We should not recognize SHF_GNU_MBIND for
7038 ELFOSABI_NONE, but binutils as of 2019-07-23 did
7039 not set the EI_OSABI header byte. */
7046 sh_flags
&= ~SHF_MASKOS
;
7050 else if (flag
& SHF_MASKPROC
)
7053 sh_flags
&= ~ SHF_MASKPROC
;
7063 if (do_section_details
)
7067 size
-= 5 + field_size
;
7068 if (p
!= buff
+ field_size
+ 4)
7072 warn (_("Internal error: not enough buffer room for section flag info"));
7073 return _("<unknown>");
7079 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
7080 (unsigned long) os_flags
);
7081 p
+= 5 + field_size
;
7085 size
-= 7 + field_size
;
7086 if (p
!= buff
+ field_size
+ 4)
7090 warn (_("Internal error: not enough buffer room for section flag info"));
7091 return _("<unknown>");
7097 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
7098 (unsigned long) proc_flags
);
7099 p
+= 7 + field_size
;
7103 size
-= 10 + field_size
;
7104 if (p
!= buff
+ field_size
+ 4)
7108 warn (_("Internal error: not enough buffer room for section flag info"));
7109 return _("<unknown>");
7115 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
7116 (unsigned long) unknown_flags
);
7117 p
+= 10 + field_size
;
7125 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
7126 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
,
7131 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
7133 if (size
< sizeof (* echdr
))
7135 error (_("Compressed section is too small even for a compression header\n"));
7139 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7140 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7141 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7142 return sizeof (*echdr
);
7146 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
7148 if (size
< sizeof (* echdr
))
7150 error (_("Compressed section is too small even for a compression header\n"));
7154 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7155 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7156 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7157 return sizeof (*echdr
);
7162 process_section_headers (Filedata
* filedata
)
7164 Elf_Internal_Shdr
* section
;
7167 if (filedata
->file_header
.e_shnum
== 0)
7169 /* PR binutils/12467. */
7170 if (filedata
->file_header
.e_shoff
!= 0)
7172 warn (_("possibly corrupt ELF file header - it has a non-zero"
7173 " section header offset, but no section headers\n"));
7176 else if (do_sections
)
7177 printf (_("\nThere are no sections in this file.\n"));
7182 if (do_sections
&& !do_header
)
7184 if (filedata
->is_separate
&& process_links
)
7185 printf (_("In linked file '%s': "), filedata
->file_name
);
7186 if (! filedata
->is_separate
|| process_links
)
7187 printf (ngettext ("There is %d section header, "
7188 "starting at offset %#" PRIx64
":\n",
7189 "There are %d section headers, "
7190 "starting at offset %#" PRIx64
":\n",
7191 filedata
->file_header
.e_shnum
),
7192 filedata
->file_header
.e_shnum
,
7193 filedata
->file_header
.e_shoff
);
7196 if (!get_section_headers (filedata
, false))
7199 /* Read in the string table, so that we have names to display. */
7200 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
7201 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
7203 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
7205 if (section
->sh_size
!= 0)
7207 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7208 1, section
->sh_size
,
7211 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
7215 /* Scan the sections for the dynamic symbol table
7216 and dynamic string table and debug sections. */
7217 eh_addr_size
= is_32bit_elf
? 4 : 8;
7218 switch (filedata
->file_header
.e_machine
)
7221 case EM_MIPS_RS3_LE
:
7222 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
7223 FDE addresses. However, the ABI also has a semi-official ILP32
7224 variant for which the normal FDE address size rules apply.
7226 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
7227 section, where XX is the size of longs in bits. Unfortunately,
7228 earlier compilers provided no way of distinguishing ILP32 objects
7229 from LP64 objects, so if there's any doubt, we should assume that
7230 the official LP64 form is being used. */
7231 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
7232 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
7238 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
7240 case E_H8_MACH_H8300
:
7241 case E_H8_MACH_H8300HN
:
7242 case E_H8_MACH_H8300SN
:
7243 case E_H8_MACH_H8300SXN
:
7246 case E_H8_MACH_H8300H
:
7247 case E_H8_MACH_H8300S
:
7248 case E_H8_MACH_H8300SX
:
7256 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
7258 case EF_M32C_CPU_M16C
:
7265 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
7268 uint64_t expected_entsize = is_32bit_elf ? size32 : size64; \
7269 if (section->sh_entsize != expected_entsize) \
7271 error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \
7272 i, section->sh_entsize); \
7273 error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \
7274 expected_entsize); \
7275 section->sh_entsize = expected_entsize; \
7280 #define CHECK_ENTSIZE(section, i, type) \
7281 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
7282 sizeof (Elf64_External_##type))
7284 for (i
= 0, section
= filedata
->section_headers
;
7285 i
< filedata
->file_header
.e_shnum
;
7288 const char *name
= section_name_print (filedata
, section
);
7290 /* Run some sanity checks on the headers and
7291 possibly fill in some file data as well. */
7292 switch (section
->sh_type
)
7295 if (filedata
->dynamic_symbols
!= NULL
)
7297 error (_("File contains multiple dynamic symbol tables\n"));
7301 CHECK_ENTSIZE (section
, i
, Sym
);
7302 filedata
->dynamic_symbols
7303 = get_elf_symbols (filedata
, section
, &filedata
->num_dynamic_syms
);
7304 filedata
->dynamic_symtab_section
= section
;
7308 if (streq (name
, ".dynstr"))
7310 if (filedata
->dynamic_strings
!= NULL
)
7312 error (_("File contains multiple dynamic string tables\n"));
7316 filedata
->dynamic_strings
7317 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7318 1, section
->sh_size
, _("dynamic strings"));
7319 filedata
->dynamic_strings_length
7320 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
7321 filedata
->dynamic_strtab_section
= section
;
7325 case SHT_SYMTAB_SHNDX
:
7327 elf_section_list
* entry
= xmalloc (sizeof * entry
);
7329 entry
->hdr
= section
;
7330 entry
->next
= filedata
->symtab_shndx_list
;
7331 filedata
->symtab_shndx_list
= entry
;
7336 CHECK_ENTSIZE (section
, i
, Sym
);
7340 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
7344 CHECK_ENTSIZE (section
, i
, Rel
);
7345 if (do_checks
&& section
->sh_size
== 0)
7346 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7350 CHECK_ENTSIZE (section
, i
, Rela
);
7351 if (do_checks
&& section
->sh_size
== 0)
7352 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7356 CHECK_ENTSIZE (section
, i
, Relr
);
7361 /* Having a zero sized section is not illegal according to the
7362 ELF standard, but it might be an indication that something
7363 is wrong. So issue a warning if we are running in lint mode. */
7364 if (do_checks
&& section
->sh_size
== 0)
7365 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
7372 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
7373 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
7374 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
7375 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
7377 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
7378 && (startswith (name
, ".debug_")
7379 || startswith (name
, ".zdebug_")))
7382 name
+= sizeof (".zdebug_") - 1;
7384 name
+= sizeof (".debug_") - 1;
7387 || (do_debug_info
&& startswith (name
, "info"))
7388 || (do_debug_info
&& startswith (name
, "types"))
7389 || (do_debug_abbrevs
&& startswith (name
, "abbrev"))
7390 || (do_debug_lines
&& strcmp (name
, "line") == 0)
7391 || (do_debug_lines
&& startswith (name
, "line."))
7392 || (do_debug_pubnames
&& startswith (name
, "pubnames"))
7393 || (do_debug_pubtypes
&& startswith (name
, "pubtypes"))
7394 || (do_debug_pubnames
&& startswith (name
, "gnu_pubnames"))
7395 || (do_debug_pubtypes
&& startswith (name
, "gnu_pubtypes"))
7396 || (do_debug_aranges
&& startswith (name
, "aranges"))
7397 || (do_debug_ranges
&& startswith (name
, "ranges"))
7398 || (do_debug_ranges
&& startswith (name
, "rnglists"))
7399 || (do_debug_frames
&& startswith (name
, "frame"))
7400 || (do_debug_macinfo
&& startswith (name
, "macinfo"))
7401 || (do_debug_macinfo
&& startswith (name
, "macro"))
7402 || (do_debug_str
&& startswith (name
, "str"))
7403 || (do_debug_links
&& startswith (name
, "sup"))
7404 || (do_debug_str_offsets
&& startswith (name
, "str_offsets"))
7405 || (do_debug_loc
&& startswith (name
, "loc"))
7406 || (do_debug_loc
&& startswith (name
, "loclists"))
7407 || (do_debug_addr
&& startswith (name
, "addr"))
7408 || (do_debug_cu_index
&& startswith (name
, "cu_index"))
7409 || (do_debug_cu_index
&& startswith (name
, "tu_index"))
7411 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7413 /* Linkonce section to be combined with .debug_info at link time. */
7414 else if ((do_debugging
|| do_debug_info
)
7415 && startswith (name
, ".gnu.linkonce.wi."))
7416 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7417 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
7418 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7419 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
7420 || streq (name
, ".debug_names")))
7421 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7422 /* Trace sections for Itanium VMS. */
7423 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
7424 || do_trace_aranges
)
7425 && startswith (name
, ".trace_"))
7427 name
+= sizeof (".trace_") - 1;
7430 || (do_trace_info
&& streq (name
, "info"))
7431 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
7432 || (do_trace_aranges
&& streq (name
, "aranges"))
7434 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7436 else if ((do_debugging
|| do_debug_links
)
7437 && (startswith (name
, ".gnu_debuglink")
7438 || startswith (name
, ".gnu_debugaltlink")))
7439 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7445 if (filedata
->is_separate
&& ! process_links
)
7448 if (filedata
->is_separate
)
7449 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
7450 else if (filedata
->file_header
.e_shnum
> 1)
7451 printf (_("\nSection Headers:\n"));
7453 printf (_("\nSection Header:\n"));
7457 if (do_section_details
)
7459 printf (_(" [Nr] Name\n"));
7460 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
7464 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
7468 if (do_section_details
)
7470 printf (_(" [Nr] Name\n"));
7471 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
7475 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
7479 if (do_section_details
)
7481 printf (_(" [Nr] Name\n"));
7482 printf (_(" Type Address Offset Link\n"));
7483 printf (_(" Size EntSize Info Align\n"));
7487 printf (_(" [Nr] Name Type Address Offset\n"));
7488 printf (_(" Size EntSize Flags Link Info Align\n"));
7492 if (do_section_details
)
7493 printf (_(" Flags\n"));
7495 for (i
= 0, section
= filedata
->section_headers
;
7496 i
< filedata
->file_header
.e_shnum
;
7499 /* Run some sanity checks on the section header. */
7501 /* Check the sh_link field. */
7502 switch (section
->sh_type
)
7506 if (section
->sh_link
== 0
7507 && (filedata
->file_header
.e_type
== ET_EXEC
7508 || filedata
->file_header
.e_type
== ET_DYN
))
7509 /* A dynamic relocation section where all entries use a
7510 zero symbol index need not specify a symtab section. */
7513 case SHT_SYMTAB_SHNDX
:
7517 case SHT_GNU_versym
:
7518 if (section
->sh_link
== 0
7519 || section
->sh_link
>= filedata
->file_header
.e_shnum
7520 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
7521 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
7522 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
7523 i
, section
->sh_link
);
7529 case SHT_GNU_verneed
:
7530 case SHT_GNU_verdef
:
7531 case SHT_GNU_LIBLIST
:
7532 if (section
->sh_link
== 0
7533 || section
->sh_link
>= filedata
->file_header
.e_shnum
7534 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
7535 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
7536 i
, section
->sh_link
);
7539 case SHT_INIT_ARRAY
:
7540 case SHT_FINI_ARRAY
:
7541 case SHT_PREINIT_ARRAY
:
7542 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7543 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7544 i
, section
->sh_link
);
7548 /* FIXME: Add support for target specific section types. */
7549 #if 0 /* Currently we do not check other section types as there are too
7550 many special cases. Stab sections for example have a type
7551 of SHT_PROGBITS but an sh_link field that links to the .stabstr
7553 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7554 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7555 i
, section
->sh_link
);
7560 /* Check the sh_info field. */
7561 switch (section
->sh_type
)
7565 if (section
->sh_info
== 0
7566 && (filedata
->file_header
.e_type
== ET_EXEC
7567 || filedata
->file_header
.e_type
== ET_DYN
))
7568 /* Dynamic relocations apply to segments, so they do not
7569 need to specify the section they relocate. */
7571 if (section
->sh_info
== 0
7572 || section
->sh_info
>= filedata
->file_header
.e_shnum
7573 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
7574 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
7575 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
7576 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
7577 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
7578 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
7579 /* FIXME: Are other section types valid ? */
7580 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
7581 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
7582 i
, section
->sh_info
);
7587 case SHT_SYMTAB_SHNDX
:
7588 case SHT_INIT_ARRAY
:
7589 case SHT_FINI_ARRAY
:
7590 case SHT_PREINIT_ARRAY
:
7591 if (section
->sh_info
!= 0)
7592 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7593 i
, section
->sh_info
);
7599 /* A symbol index - we assume that it is valid. */
7603 /* FIXME: Add support for target specific section types. */
7604 if (section
->sh_type
== SHT_NOBITS
)
7605 /* NOBITS section headers with non-zero sh_info fields can be
7606 created when a binary is stripped of everything but its debug
7607 information. The stripped sections have their headers
7608 preserved but their types set to SHT_NOBITS. So do not check
7609 this type of section. */
7611 else if (section
->sh_flags
& SHF_INFO_LINK
)
7613 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
7614 warn (_("[%2u]: Expected link to another section in info field"), i
);
7616 else if (section
->sh_type
< SHT_LOOS
7617 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
7618 && section
->sh_info
!= 0)
7619 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7620 i
, section
->sh_info
);
7624 /* Check the sh_size field. */
7625 if (section
->sh_size
> filedata
->file_size
7626 && section
->sh_type
!= SHT_NOBITS
7627 && section
->sh_type
!= SHT_NULL
7628 && section
->sh_type
< SHT_LOOS
)
7629 warn (_("Size of section %u is larger than the entire file!\n"), i
);
7631 printf (" [%2u] ", i
);
7632 if (do_section_details
)
7633 printf ("%s\n ", printable_section_name (filedata
, section
));
7635 print_symbol (-17, section_name_print (filedata
, section
));
7637 printf (do_wide
? " %-15s " : " %-15.15s ",
7638 get_section_type_name (filedata
, section
->sh_type
));
7642 const char * link_too_big
= NULL
;
7644 print_vma (section
->sh_addr
, LONG_HEX
);
7646 printf ( " %6.6lx %6.6lx %2.2lx",
7647 (unsigned long) section
->sh_offset
,
7648 (unsigned long) section
->sh_size
,
7649 (unsigned long) section
->sh_entsize
);
7651 if (do_section_details
)
7652 fputs (" ", stdout
);
7654 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7656 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
7659 /* The sh_link value is out of range. Normally this indicates
7660 an error but it can have special values in Solaris binaries. */
7661 switch (filedata
->file_header
.e_machine
)
7668 case EM_OLD_SPARCV9
:
7669 case EM_SPARC32PLUS
:
7672 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
7673 link_too_big
= "BEFORE";
7674 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
7675 link_too_big
= "AFTER";
7682 if (do_section_details
)
7684 if (link_too_big
!= NULL
&& * link_too_big
)
7685 printf ("<%s> ", link_too_big
);
7687 printf ("%2u ", section
->sh_link
);
7688 printf ("%3u %2lu\n", section
->sh_info
,
7689 (unsigned long) section
->sh_addralign
);
7692 printf ("%2u %3u %2lu\n",
7695 (unsigned long) section
->sh_addralign
);
7697 if (link_too_big
&& ! * link_too_big
)
7698 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
7699 i
, section
->sh_link
);
7703 print_vma (section
->sh_addr
, LONG_HEX
);
7705 if ((long) section
->sh_offset
== section
->sh_offset
)
7706 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
7710 print_vma (section
->sh_offset
, LONG_HEX
);
7713 if ((unsigned long) section
->sh_size
== section
->sh_size
)
7714 printf (" %6.6lx", (unsigned long) section
->sh_size
);
7718 print_vma (section
->sh_size
, LONG_HEX
);
7721 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
7722 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
7726 print_vma (section
->sh_entsize
, LONG_HEX
);
7729 if (do_section_details
)
7730 fputs (" ", stdout
);
7732 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7734 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
7736 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
7737 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
7740 print_vma (section
->sh_addralign
, DEC
);
7744 else if (do_section_details
)
7747 print_vma (section
->sh_addr
, LONG_HEX
);
7748 if ((long) section
->sh_offset
== section
->sh_offset
)
7749 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
7753 print_vma (section
->sh_offset
, LONG_HEX
);
7755 printf (" %u\n ", section
->sh_link
);
7756 print_vma (section
->sh_size
, LONG_HEX
);
7758 print_vma (section
->sh_entsize
, LONG_HEX
);
7760 printf (" %-16u %lu\n",
7762 (unsigned long) section
->sh_addralign
);
7767 print_vma (section
->sh_addr
, LONG_HEX
);
7768 if ((long) section
->sh_offset
== section
->sh_offset
)
7769 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
7773 print_vma (section
->sh_offset
, LONG_HEX
);
7776 print_vma (section
->sh_size
, LONG_HEX
);
7778 print_vma (section
->sh_entsize
, LONG_HEX
);
7780 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7782 printf (" %2u %3u %lu\n",
7785 (unsigned long) section
->sh_addralign
);
7788 if (do_section_details
)
7790 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
7791 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
7793 /* Minimum section size is 12 bytes for 32-bit compression
7794 header + 12 bytes for compressed data header. */
7795 unsigned char buf
[24];
7797 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
7798 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
7799 sizeof (buf
), _("compression header")))
7801 Elf_Internal_Chdr chdr
;
7803 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
7804 printf (_(" [<corrupt>]\n"));
7807 if (chdr
.ch_type
== ch_compress_zlib
)
7809 else if (chdr
.ch_type
== ch_compress_zstd
)
7812 printf (_(" [<unknown>: 0x%x], "),
7814 print_vma (chdr
.ch_size
, LONG_HEX
);
7815 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
7822 if (!do_section_details
)
7824 /* The ordering of the letters shown here matches the ordering of the
7825 corresponding SHF_xxx values, and hence the order in which these
7826 letters will be displayed to the user. */
7827 printf (_("Key to Flags:\n\
7828 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
7829 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
7830 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
7831 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7834 case ELFOSABI_FREEBSD
:
7835 printf (_("R (retain), "));
7838 printf (_("D (mbind), "));
7843 if (filedata
->file_header
.e_machine
== EM_X86_64
7844 || filedata
->file_header
.e_machine
== EM_L1OM
7845 || filedata
->file_header
.e_machine
== EM_K1OM
)
7846 printf (_("l (large), "));
7847 else if (filedata
->file_header
.e_machine
== EM_ARM
)
7848 printf (_("y (purecode), "));
7849 else if (filedata
->file_header
.e_machine
== EM_PPC
)
7850 printf (_("v (VLE), "));
7851 printf ("p (processor specific)\n");
7858 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
7859 Elf_Internal_Sym
**symtab
, uint64_t *nsyms
,
7860 char **strtab
, uint64_t *strtablen
)
7864 *symtab
= get_elf_symbols (filedata
, symsec
, nsyms
);
7866 if (*symtab
== NULL
)
7869 if (symsec
->sh_link
!= 0)
7871 Elf_Internal_Shdr
*strsec
;
7873 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
7875 error (_("Bad sh_link in symbol table section\n"));
7882 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
7884 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7885 1, strsec
->sh_size
, _("string table"));
7886 if (*strtab
== NULL
)
7893 *strtablen
= strsec
->sh_size
;
7899 get_group_flags (unsigned int flags
)
7901 static char buff
[128];
7905 else if (flags
== GRP_COMDAT
)
7908 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
7910 flags
& GRP_MASKOS
? _("<OS specific>") : "",
7911 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
7912 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
7913 ? _("<unknown>") : ""));
7919 process_section_groups (Filedata
* filedata
)
7921 Elf_Internal_Shdr
* section
;
7923 struct group
* group
;
7924 Elf_Internal_Shdr
* symtab_sec
;
7925 Elf_Internal_Shdr
* strtab_sec
;
7926 Elf_Internal_Sym
* symtab
;
7931 /* Don't process section groups unless needed. */
7932 if (!do_unwind
&& !do_section_groups
)
7935 if (filedata
->file_header
.e_shnum
== 0)
7937 if (do_section_groups
)
7939 if (filedata
->is_separate
)
7940 printf (_("\nThere are no sections group in linked file '%s'.\n"),
7941 filedata
->file_name
);
7943 printf (_("\nThere are no section groups in this file.\n"));
7948 if (filedata
->section_headers
== NULL
)
7950 error (_("Section headers are not available!\n"));
7951 /* PR 13622: This can happen with a corrupt ELF header. */
7955 filedata
->section_headers_groups
7956 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
7957 sizeof (struct group
*));
7959 if (filedata
->section_headers_groups
== NULL
)
7961 error (_("Out of memory reading %u section group headers\n"),
7962 filedata
->file_header
.e_shnum
);
7966 /* Scan the sections for the group section. */
7967 filedata
->group_count
= 0;
7968 for (i
= 0, section
= filedata
->section_headers
;
7969 i
< filedata
->file_header
.e_shnum
;
7971 if (section
->sh_type
== SHT_GROUP
)
7972 filedata
->group_count
++;
7974 if (filedata
->group_count
== 0)
7976 if (do_section_groups
)
7978 if (filedata
->is_separate
)
7979 printf (_("\nThere are no section groups in linked file '%s'.\n"),
7980 filedata
->file_name
);
7982 printf (_("\nThere are no section groups in this file.\n"));
7988 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
7989 sizeof (struct group
));
7991 if (filedata
->section_groups
== NULL
)
7993 error (_("Out of memory reading %zu groups\n"), filedata
->group_count
);
8004 if (filedata
->is_separate
)
8005 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
8007 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
8008 i
< filedata
->file_header
.e_shnum
;
8011 if (section
->sh_type
== SHT_GROUP
)
8013 const char * name
= printable_section_name (filedata
, section
);
8014 const char * group_name
;
8015 unsigned char * start
;
8016 unsigned char * indices
;
8017 unsigned int entry
, j
, size
;
8018 Elf_Internal_Shdr
* sec
;
8019 Elf_Internal_Sym
* sym
;
8021 /* Get the symbol table. */
8022 if (section
->sh_link
>= filedata
->file_header
.e_shnum
8023 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
8026 error (_("Bad sh_link in group section `%s'\n"), name
);
8030 if (symtab_sec
!= sec
)
8034 symtab
= get_elf_symbols (filedata
, symtab_sec
, & num_syms
);
8039 error (_("Corrupt header in group section `%s'\n"), name
);
8043 if (section
->sh_info
>= num_syms
)
8045 error (_("Bad sh_info in group section `%s'\n"), name
);
8049 sym
= symtab
+ section
->sh_info
;
8051 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8053 if (sym
->st_shndx
== 0
8054 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
8056 error (_("Bad sh_info in group section `%s'\n"), name
);
8060 group_name
= section_name_print (filedata
,
8061 filedata
->section_headers
8070 /* Get the string table. */
8071 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
8079 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
8084 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
8085 1, strtab_sec
->sh_size
,
8087 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
8089 group_name
= sym
->st_name
< strtab_size
8090 ? strtab
+ sym
->st_name
: _("<corrupt>");
8093 /* PR 17531: file: loop. */
8094 if (section
->sh_entsize
> section
->sh_size
)
8096 error (_("Section %s has sh_entsize (%#" PRIx64
")"
8097 " which is larger than its size (%#" PRIx64
")\n"),
8098 printable_section_name (filedata
, section
),
8099 section
->sh_entsize
,
8104 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
8105 1, section
->sh_size
,
8111 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
8112 entry
= byte_get (indices
, 4);
8115 if (do_section_groups
)
8117 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
8118 get_group_flags (entry
), i
, name
, group_name
, size
);
8120 printf (_(" [Index] Name\n"));
8123 group
->group_index
= i
;
8125 for (j
= 0; j
< size
; j
++)
8127 struct group_list
* g
;
8129 entry
= byte_get (indices
, 4);
8132 if (entry
>= filedata
->file_header
.e_shnum
)
8134 static unsigned num_group_errors
= 0;
8136 if (num_group_errors
++ < 10)
8138 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
8139 entry
, i
, filedata
->file_header
.e_shnum
- 1);
8140 if (num_group_errors
== 10)
8141 warn (_("Further error messages about overlarge group section indices suppressed\n"));
8146 if (filedata
->section_headers_groups
[entry
] != NULL
)
8150 static unsigned num_errs
= 0;
8152 if (num_errs
++ < 10)
8154 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
8156 filedata
->section_headers_groups
[entry
]->group_index
);
8158 warn (_("Further error messages about already contained group sections suppressed\n"));
8164 /* Intel C/C++ compiler may put section 0 in a
8165 section group. We just warn it the first time
8166 and ignore it afterwards. */
8167 static bool warned
= false;
8170 error (_("section 0 in group section [%5u]\n"),
8171 filedata
->section_headers_groups
[entry
]->group_index
);
8177 filedata
->section_headers_groups
[entry
] = group
;
8179 if (do_section_groups
)
8181 sec
= filedata
->section_headers
+ entry
;
8182 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
8185 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
8186 g
->section_index
= entry
;
8187 g
->next
= group
->root
;
8202 /* Data used to display dynamic fixups. */
8204 struct ia64_vms_dynfixup
8206 uint64_t needed_ident
; /* Library ident number. */
8207 uint64_t needed
; /* Index in the dstrtab of the library name. */
8208 uint64_t fixup_needed
; /* Index of the library. */
8209 uint64_t fixup_rela_cnt
; /* Number of fixups. */
8210 uint64_t fixup_rela_off
; /* Fixups offset in the dynamic segment. */
8213 /* Data used to display dynamic relocations. */
8215 struct ia64_vms_dynimgrela
8217 uint64_t img_rela_cnt
; /* Number of relocations. */
8218 uint64_t img_rela_off
; /* Reloc offset in the dynamic segment. */
8221 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
8225 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
8226 struct ia64_vms_dynfixup
* fixup
,
8227 const char * strtab
,
8228 unsigned int strtab_sz
)
8230 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
8232 const char * lib_name
;
8234 imfs
= get_data (NULL
, filedata
,
8235 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
8236 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
8237 _("dynamic section image fixups"));
8241 if (fixup
->needed
< strtab_sz
)
8242 lib_name
= strtab
+ fixup
->needed
;
8245 warn (_("corrupt library name index of %#" PRIx64
8246 " found in dynamic entry"), fixup
->needed
);
8250 printf (_("\nImage fixups for needed library #%" PRId64
8251 ": %s - ident: %" PRIx64
"\n"),
8252 fixup
->fixup_needed
, lib_name
, fixup
->needed_ident
);
8254 (_("Seg Offset Type SymVec DataType\n"));
8256 for (i
= 0; i
< (size_t) fixup
->fixup_rela_cnt
; i
++)
8261 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
8262 printf ("%016" PRIx64
" ", BYTE_GET (imfs
[i
].fixup_offset
));
8263 type
= BYTE_GET (imfs
[i
].type
);
8264 rtype
= elf_ia64_reloc_type (type
);
8266 printf ("0x%08x ", type
);
8268 printf ("%-32s ", rtype
);
8269 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
8270 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
8277 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
8280 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
8282 Elf64_External_VMS_IMAGE_RELA
*imrs
;
8285 imrs
= get_data (NULL
, filedata
,
8286 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
8287 sizeof (*imrs
), imgrela
->img_rela_cnt
,
8288 _("dynamic section image relocations"));
8292 printf (_("\nImage relocs\n"));
8294 (_("Seg Offset Type Addend Seg Sym Off\n"));
8296 for (i
= 0; i
< (size_t) imgrela
->img_rela_cnt
; i
++)
8301 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
8302 printf ("%08" PRIx64
" ", BYTE_GET (imrs
[i
].rela_offset
));
8303 type
= BYTE_GET (imrs
[i
].type
);
8304 rtype
= elf_ia64_reloc_type (type
);
8306 printf ("0x%08x ", type
);
8308 printf ("%-31s ", rtype
);
8309 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
8310 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
8311 printf ("%08" PRIx64
"\n", BYTE_GET (imrs
[i
].sym_offset
));
8318 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
8321 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
8323 struct ia64_vms_dynfixup fixup
;
8324 struct ia64_vms_dynimgrela imgrela
;
8325 Elf_Internal_Dyn
*entry
;
8326 uint64_t strtab_off
= 0;
8327 uint64_t strtab_sz
= 0;
8328 char *strtab
= NULL
;
8331 memset (&fixup
, 0, sizeof (fixup
));
8332 memset (&imgrela
, 0, sizeof (imgrela
));
8334 /* Note: the order of the entries is specified by the OpenVMS specs. */
8335 for (entry
= filedata
->dynamic_section
;
8336 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
8339 switch (entry
->d_tag
)
8341 case DT_IA_64_VMS_STRTAB_OFFSET
:
8342 strtab_off
= entry
->d_un
.d_val
;
8345 strtab_sz
= entry
->d_un
.d_val
;
8347 strtab
= get_data (NULL
, filedata
,
8348 filedata
->dynamic_addr
+ strtab_off
,
8349 1, strtab_sz
, _("dynamic string section"));
8354 case DT_IA_64_VMS_NEEDED_IDENT
:
8355 fixup
.needed_ident
= entry
->d_un
.d_val
;
8358 fixup
.needed
= entry
->d_un
.d_val
;
8360 case DT_IA_64_VMS_FIXUP_NEEDED
:
8361 fixup
.fixup_needed
= entry
->d_un
.d_val
;
8363 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
8364 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
8366 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
8367 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
8368 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
8371 case DT_IA_64_VMS_IMG_RELA_CNT
:
8372 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
8374 case DT_IA_64_VMS_IMG_RELA_OFF
:
8375 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
8376 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
8395 relocation_type rel_type
;
8397 dynamic_relocations
[] =
8399 { "REL", DT_REL
, DT_RELSZ
, reltype_rel
},
8400 { "RELA", DT_RELA
, DT_RELASZ
, reltype_rela
},
8401 { "RELR", DT_RELR
, DT_RELRSZ
, reltype_relr
},
8402 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, reltype_unknown
}
8405 /* Process the reloc section. */
8408 process_relocs (Filedata
* filedata
)
8411 uint64_t rel_offset
;
8416 if (do_using_dynamic
)
8418 relocation_type rel_type
;
8420 bool has_dynamic_reloc
;
8423 has_dynamic_reloc
= false;
8425 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8427 rel_type
= dynamic_relocations
[i
].rel_type
;
8428 name
= dynamic_relocations
[i
].name
;
8429 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
8430 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
8433 has_dynamic_reloc
= true;
8435 if (rel_type
== reltype_unknown
)
8437 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
8438 switch (filedata
->dynamic_info
[DT_PLTREL
])
8441 rel_type
= reltype_rel
;
8444 rel_type
= reltype_rela
;
8451 if (filedata
->is_separate
)
8453 (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64
8454 " contains %" PRId64
" bytes:\n"),
8455 filedata
->file_name
, name
, rel_offset
, rel_size
);
8458 (_("\n'%s' relocation section at offset %#" PRIx64
8459 " contains %" PRId64
" bytes:\n"),
8460 name
, rel_offset
, rel_size
);
8462 dump_relocations (filedata
,
8463 offset_from_vma (filedata
, rel_offset
, rel_size
),
8465 filedata
->dynamic_symbols
,
8466 filedata
->num_dynamic_syms
,
8467 filedata
->dynamic_strings
,
8468 filedata
->dynamic_strings_length
,
8469 rel_type
, true /* is_dynamic */);
8473 if (is_ia64_vms (filedata
))
8474 if (process_ia64_vms_dynamic_relocs (filedata
))
8475 has_dynamic_reloc
= true;
8477 if (! has_dynamic_reloc
)
8479 if (filedata
->is_separate
)
8480 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
8481 filedata
->file_name
);
8483 printf (_("\nThere are no dynamic relocations in this file.\n"));
8488 Elf_Internal_Shdr
* section
;
8492 for (i
= 0, section
= filedata
->section_headers
;
8493 i
< filedata
->file_header
.e_shnum
;
8496 if ( section
->sh_type
!= SHT_RELA
8497 && section
->sh_type
!= SHT_REL
8498 && section
->sh_type
!= SHT_RELR
)
8501 rel_offset
= section
->sh_offset
;
8502 rel_size
= section
->sh_size
;
8506 relocation_type rel_type
;
8509 if (filedata
->is_separate
)
8510 printf (_("\nIn linked file '%s' relocation section "),
8511 filedata
->file_name
);
8513 printf (_("\nRelocation section "));
8515 if (filedata
->string_table
== NULL
)
8516 printf ("%d", section
->sh_name
);
8518 printf ("'%s'", printable_section_name (filedata
, section
));
8520 num_rela
= rel_size
/ section
->sh_entsize
;
8521 printf (ngettext (" at offset %#" PRIx64
8522 " contains %" PRIu64
" entry:\n",
8523 " at offset %#" PRIx64
8524 " contains %" PRId64
" entries:\n",
8526 rel_offset
, num_rela
);
8528 rel_type
= section
->sh_type
== SHT_RELA
? reltype_rela
:
8529 section
->sh_type
== SHT_REL
? reltype_rel
: reltype_relr
;
8531 if (section
->sh_link
!= 0
8532 && section
->sh_link
< filedata
->file_header
.e_shnum
)
8534 Elf_Internal_Shdr
*symsec
;
8535 Elf_Internal_Sym
*symtab
;
8537 uint64_t strtablen
= 0;
8538 char *strtab
= NULL
;
8540 symsec
= filedata
->section_headers
+ section
->sh_link
;
8541 if (symsec
->sh_type
!= SHT_SYMTAB
8542 && symsec
->sh_type
!= SHT_DYNSYM
)
8545 if (!get_symtab (filedata
, symsec
,
8546 &symtab
, &nsyms
, &strtab
, &strtablen
))
8549 dump_relocations (filedata
, rel_offset
, rel_size
,
8550 symtab
, nsyms
, strtab
, strtablen
,
8552 symsec
->sh_type
== SHT_DYNSYM
);
8557 dump_relocations (filedata
, rel_offset
, rel_size
,
8558 NULL
, 0, NULL
, 0, rel_type
, false /* is_dynamic */);
8566 /* Users sometimes forget the -D option, so try to be helpful. */
8567 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8569 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
8571 if (filedata
->is_separate
)
8572 printf (_("\nThere are no static relocations in linked file '%s'."),
8573 filedata
->file_name
);
8575 printf (_("\nThere are no static relocations in this file."));
8576 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
8581 if (i
== ARRAY_SIZE (dynamic_relocations
))
8583 if (filedata
->is_separate
)
8584 printf (_("\nThere are no relocations in linked file '%s'.\n"),
8585 filedata
->file_name
);
8587 printf (_("\nThere are no relocations in this file.\n"));
8595 /* An absolute address consists of a section and an offset. If the
8596 section is NULL, the offset itself is the address, otherwise, the
8597 address equals to LOAD_ADDRESS(section) + offset. */
8601 unsigned short section
;
8605 /* Find the nearest symbol at or below ADDR. Returns the symbol
8606 name, if found, and the offset from the symbol to ADDR. */
8609 find_symbol_for_address (Filedata
*filedata
,
8610 Elf_Internal_Sym
*symtab
,
8613 uint64_t strtab_size
,
8614 struct absaddr addr
,
8615 const char **symname
,
8618 uint64_t dist
= 0x100000;
8619 Elf_Internal_Sym
* sym
;
8620 Elf_Internal_Sym
* beg
;
8621 Elf_Internal_Sym
* end
;
8622 Elf_Internal_Sym
* best
= NULL
;
8624 REMOVE_ARCH_BITS (addr
.offset
);
8626 end
= symtab
+ nsyms
;
8632 sym
= beg
+ (end
- beg
) / 2;
8634 value
= sym
->st_value
;
8635 REMOVE_ARCH_BITS (value
);
8637 if (sym
->st_name
!= 0
8638 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
8639 && addr
.offset
>= value
8640 && addr
.offset
- value
< dist
)
8643 dist
= addr
.offset
- value
;
8648 if (addr
.offset
< value
)
8656 *symname
= (best
->st_name
>= strtab_size
8657 ? _("<corrupt>") : strtab
+ best
->st_name
);
8663 *offset
= addr
.offset
;
8666 static /* signed */ int
8667 symcmp (const void *p
, const void *q
)
8669 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
8670 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
8672 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
8675 /* Process the unwind section. */
8677 #include "unwind-ia64.h"
8679 struct ia64_unw_table_entry
8681 struct absaddr start
;
8683 struct absaddr info
;
8686 struct ia64_unw_aux_info
8688 struct ia64_unw_table_entry
* table
; /* Unwind table. */
8689 uint64_t table_len
; /* Length of unwind table. */
8690 unsigned char * info
; /* Unwind info. */
8691 uint64_t info_size
; /* Size of unwind info. */
8692 uint64_t info_addr
; /* Starting address of unwind info. */
8693 uint64_t seg_base
; /* Starting address of segment. */
8694 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8695 uint64_t nsyms
; /* Number of symbols. */
8696 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8697 uint64_t nfuns
; /* Number of entries in funtab. */
8698 char * strtab
; /* The string table. */
8699 uint64_t strtab_size
; /* Size of string table. */
8703 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
8705 struct ia64_unw_table_entry
* tp
;
8710 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8711 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8712 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8713 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8715 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8717 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8721 const unsigned char * dp
;
8722 const unsigned char * head
;
8723 const unsigned char * end
;
8724 const char * procname
;
8726 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8727 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
8729 fputs ("\n<", stdout
);
8733 fputs (procname
, stdout
);
8736 printf ("+%" PRIx64
, offset
);
8739 fputs (">: [", stdout
);
8740 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8741 fputc ('-', stdout
);
8742 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8743 printf ("], info at +0x%" PRIx64
"\n",
8744 tp
->info
.offset
- aux
->seg_base
);
8746 /* PR 17531: file: 86232b32. */
8747 if (aux
->info
== NULL
)
8750 offset
= tp
->info
.offset
;
8751 if (tp
->info
.section
)
8753 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
8755 warn (_("Invalid section %u in table entry %td\n"),
8756 tp
->info
.section
, tp
- aux
->table
);
8760 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
8762 offset
-= aux
->info_addr
;
8763 /* PR 17531: file: 0997b4d1. */
8764 if (offset
>= aux
->info_size
8765 || aux
->info_size
- offset
< 8)
8767 warn (_("Invalid offset %" PRIx64
" in table entry %td\n"),
8768 tp
->info
.offset
, tp
- aux
->table
);
8773 head
= aux
->info
+ offset
;
8774 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
8776 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
8777 (unsigned) UNW_VER (stamp
),
8778 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
8779 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
8780 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
8781 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
8783 if (UNW_VER (stamp
) != 1)
8785 printf (_("\tUnknown version.\n"));
8790 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
8791 /* PR 17531: file: 16ceda89. */
8792 if (end
> aux
->info
+ aux
->info_size
)
8793 end
= aux
->info
+ aux
->info_size
;
8794 for (dp
= head
+ 8; dp
< end
;)
8795 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
8804 slurp_ia64_unwind_table (Filedata
* filedata
,
8805 struct ia64_unw_aux_info
* aux
,
8806 Elf_Internal_Shdr
* sec
)
8808 uint64_t size
, nrelas
, i
;
8809 Elf_Internal_Phdr
* seg
;
8810 struct ia64_unw_table_entry
* tep
;
8811 Elf_Internal_Shdr
* relsec
;
8812 Elf_Internal_Rela
* rela
;
8813 Elf_Internal_Rela
* rp
;
8814 unsigned char * table
;
8816 Elf_Internal_Sym
* sym
;
8817 const char * relname
;
8821 /* First, find the starting address of the segment that includes
8824 if (filedata
->file_header
.e_phnum
)
8826 if (! get_program_headers (filedata
))
8829 for (seg
= filedata
->program_headers
;
8830 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8833 if (seg
->p_type
!= PT_LOAD
)
8836 if (sec
->sh_addr
>= seg
->p_vaddr
8837 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8839 aux
->seg_base
= seg
->p_vaddr
;
8845 /* Second, build the unwind table from the contents of the unwind section: */
8846 size
= sec
->sh_size
;
8847 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8852 aux
->table_len
= size
/ (3 * eh_addr_size
);
8853 aux
->table
= (struct ia64_unw_table_entry
*)
8854 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
8857 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
8859 tep
->start
.section
= SHN_UNDEF
;
8860 tep
->end
.section
= SHN_UNDEF
;
8861 tep
->info
.section
= SHN_UNDEF
;
8862 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8863 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8864 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8865 tep
->start
.offset
+= aux
->seg_base
;
8866 tep
->end
.offset
+= aux
->seg_base
;
8867 tep
->info
.offset
+= aux
->seg_base
;
8871 /* Third, apply any relocations to the unwind table: */
8872 for (relsec
= filedata
->section_headers
;
8873 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8876 if (relsec
->sh_type
!= SHT_RELA
8877 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8878 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8881 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8890 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8892 unsigned int sym_ndx
;
8893 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8894 relname
= elf_ia64_reloc_type (r_type
);
8896 /* PR 17531: file: 9fa67536. */
8897 if (relname
== NULL
)
8899 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8903 if (! startswith (relname
, "R_IA64_SEGREL"))
8905 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8909 i
= rp
->r_offset
/ (3 * eh_addr_size
);
8911 /* PR 17531: file: 5bc8d9bf. */
8912 if (i
>= aux
->table_len
)
8914 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
8919 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8920 if (sym_ndx
>= aux
->nsyms
)
8922 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8926 sym
= aux
->symtab
+ sym_ndx
;
8928 switch (rp
->r_offset
/ eh_addr_size
% 3)
8931 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8932 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
8935 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8936 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
8939 aux
->table
[i
].info
.section
= sym
->st_shndx
;
8940 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
8954 ia64_process_unwind (Filedata
* filedata
)
8956 Elf_Internal_Shdr
* sec
;
8957 Elf_Internal_Shdr
* unwsec
= NULL
;
8958 uint64_t i
, unwcount
= 0, unwstart
= 0;
8959 struct ia64_unw_aux_info aux
;
8962 memset (& aux
, 0, sizeof (aux
));
8964 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8966 if (sec
->sh_type
== SHT_SYMTAB
)
8970 error (_("Multiple symbol tables encountered\n"));
8976 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8977 &aux
.strtab
, &aux
.strtab_size
))
8980 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8985 printf (_("\nThere are no unwind sections in this file.\n"));
8987 while (unwcount
-- > 0)
8992 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
8993 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8994 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8999 /* We have already counted the number of SHT_IA64_UNWIND
9000 sections so the loop above should never fail. */
9001 assert (unwsec
!= NULL
);
9004 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
9006 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
9008 /* We need to find which section group it is in. */
9009 struct group_list
* g
;
9011 if (filedata
->section_headers_groups
== NULL
9012 || filedata
->section_headers_groups
[i
] == NULL
)
9013 i
= filedata
->file_header
.e_shnum
;
9016 g
= filedata
->section_headers_groups
[i
]->root
;
9018 for (; g
!= NULL
; g
= g
->next
)
9020 sec
= filedata
->section_headers
+ g
->section_index
;
9022 if (section_name_valid (filedata
, sec
)
9023 && streq (section_name (filedata
, sec
),
9024 ELF_STRING_ia64_unwind_info
))
9029 i
= filedata
->file_header
.e_shnum
;
9032 else if (section_name_valid (filedata
, unwsec
)
9033 && startswith (section_name (filedata
, unwsec
),
9034 ELF_STRING_ia64_unwind_once
))
9036 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
9037 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
9038 suffix
= section_name (filedata
, unwsec
) + len
;
9039 for (i
= 0, sec
= filedata
->section_headers
;
9040 i
< filedata
->file_header
.e_shnum
;
9042 if (section_name_valid (filedata
, sec
)
9043 && startswith (section_name (filedata
, sec
),
9044 ELF_STRING_ia64_unwind_info_once
)
9045 && streq (section_name (filedata
, sec
) + len2
, suffix
))
9050 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
9051 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
9052 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
9053 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
9055 if (section_name_valid (filedata
, unwsec
)
9056 && startswith (section_name (filedata
, unwsec
),
9057 ELF_STRING_ia64_unwind
))
9058 suffix
= section_name (filedata
, unwsec
) + len
;
9059 for (i
= 0, sec
= filedata
->section_headers
;
9060 i
< filedata
->file_header
.e_shnum
;
9062 if (section_name_valid (filedata
, sec
)
9063 && startswith (section_name (filedata
, sec
),
9064 ELF_STRING_ia64_unwind_info
)
9065 && streq (section_name (filedata
, sec
) + len2
, suffix
))
9069 if (i
== filedata
->file_header
.e_shnum
)
9071 printf (_("\nCould not find unwind info section for "));
9073 if (filedata
->string_table
== NULL
)
9074 printf ("%d", unwsec
->sh_name
);
9076 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9080 aux
.info_addr
= sec
->sh_addr
;
9081 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
9084 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
9086 printf (_("\nUnwind section "));
9088 if (filedata
->string_table
== NULL
)
9089 printf ("%d", unwsec
->sh_name
);
9091 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9093 printf (_(" at offset %#" PRIx64
" contains %" PRIu64
" entries:\n"),
9095 unwsec
->sh_size
/ (3 * eh_addr_size
));
9097 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
9098 && aux
.table_len
> 0)
9099 dump_ia64_unwind (filedata
, & aux
);
9101 free ((char *) aux
.table
);
9102 free ((char *) aux
.info
);
9109 free ((char *) aux
.strtab
);
9114 struct hppa_unw_table_entry
9116 struct absaddr start
;
9118 unsigned int Cannot_unwind
:1; /* 0 */
9119 unsigned int Millicode
:1; /* 1 */
9120 unsigned int Millicode_save_sr0
:1; /* 2 */
9121 unsigned int Region_description
:2; /* 3..4 */
9122 unsigned int reserved1
:1; /* 5 */
9123 unsigned int Entry_SR
:1; /* 6 */
9124 unsigned int Entry_FR
:4; /* Number saved 7..10 */
9125 unsigned int Entry_GR
:5; /* Number saved 11..15 */
9126 unsigned int Args_stored
:1; /* 16 */
9127 unsigned int Variable_Frame
:1; /* 17 */
9128 unsigned int Separate_Package_Body
:1; /* 18 */
9129 unsigned int Frame_Extension_Millicode
:1; /* 19 */
9130 unsigned int Stack_Overflow_Check
:1; /* 20 */
9131 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
9132 unsigned int Ada_Region
:1; /* 22 */
9133 unsigned int cxx_info
:1; /* 23 */
9134 unsigned int cxx_try_catch
:1; /* 24 */
9135 unsigned int sched_entry_seq
:1; /* 25 */
9136 unsigned int reserved2
:1; /* 26 */
9137 unsigned int Save_SP
:1; /* 27 */
9138 unsigned int Save_RP
:1; /* 28 */
9139 unsigned int Save_MRP_in_frame
:1; /* 29 */
9140 unsigned int extn_ptr_defined
:1; /* 30 */
9141 unsigned int Cleanup_defined
:1; /* 31 */
9143 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
9144 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
9145 unsigned int Large_frame
:1; /* 2 */
9146 unsigned int Pseudo_SP_Set
:1; /* 3 */
9147 unsigned int reserved4
:1; /* 4 */
9148 unsigned int Total_frame_size
:27; /* 5..31 */
9151 struct hppa_unw_aux_info
9153 struct hppa_unw_table_entry
* table
; /* Unwind table. */
9154 uint64_t table_len
; /* Length of unwind table. */
9155 uint64_t seg_base
; /* Starting address of segment. */
9156 Elf_Internal_Sym
* symtab
; /* The symbol table. */
9157 uint64_t nsyms
; /* Number of symbols. */
9158 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9159 uint64_t nfuns
; /* Number of entries in funtab. */
9160 char * strtab
; /* The string table. */
9161 uint64_t strtab_size
; /* Size of string table. */
9165 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
9167 struct hppa_unw_table_entry
* tp
;
9171 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9172 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9173 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9174 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9176 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9178 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
9181 const char * procname
;
9183 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9184 aux
->strtab_size
, tp
->start
, &procname
,
9187 fputs ("\n<", stdout
);
9191 fputs (procname
, stdout
);
9194 printf ("+%" PRIx64
, offset
);
9197 fputs (">: [", stdout
);
9198 print_vma (tp
->start
.offset
, PREFIX_HEX
);
9199 fputc ('-', stdout
);
9200 print_vma (tp
->end
.offset
, PREFIX_HEX
);
9203 #define PF(_m) if (tp->_m) printf (#_m " ");
9204 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
9207 PF(Millicode_save_sr0
);
9208 /* PV(Region_description); */
9214 PF(Separate_Package_Body
);
9215 PF(Frame_Extension_Millicode
);
9216 PF(Stack_Overflow_Check
);
9217 PF(Two_Instruction_SP_Increment
);
9221 PF(sched_entry_seq
);
9224 PF(Save_MRP_in_frame
);
9225 PF(extn_ptr_defined
);
9226 PF(Cleanup_defined
);
9227 PF(MPE_XL_interrupt_marker
);
9228 PF(HP_UX_interrupt_marker
);
9231 PV(Total_frame_size
);
9244 slurp_hppa_unwind_table (Filedata
* filedata
,
9245 struct hppa_unw_aux_info
* aux
,
9246 Elf_Internal_Shdr
* sec
)
9248 uint64_t size
, unw_ent_size
, nentries
, nrelas
, i
;
9249 Elf_Internal_Phdr
* seg
;
9250 struct hppa_unw_table_entry
* tep
;
9251 Elf_Internal_Shdr
* relsec
;
9252 Elf_Internal_Rela
* rela
;
9253 Elf_Internal_Rela
* rp
;
9254 unsigned char * table
;
9256 Elf_Internal_Sym
* sym
;
9257 const char * relname
;
9259 /* First, find the starting address of the segment that includes
9261 if (filedata
->file_header
.e_phnum
)
9263 if (! get_program_headers (filedata
))
9266 for (seg
= filedata
->program_headers
;
9267 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
9270 if (seg
->p_type
!= PT_LOAD
)
9273 if (sec
->sh_addr
>= seg
->p_vaddr
9274 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
9276 aux
->seg_base
= seg
->p_vaddr
;
9282 /* Second, build the unwind table from the contents of the unwind
9284 size
= sec
->sh_size
;
9285 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
9291 nentries
= size
/ unw_ent_size
;
9292 size
= unw_ent_size
* nentries
;
9294 aux
->table_len
= nentries
;
9295 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
9296 xcmalloc (nentries
, sizeof (aux
->table
[0]));
9298 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
9300 unsigned int tmp1
, tmp2
;
9302 tep
->start
.section
= SHN_UNDEF
;
9303 tep
->end
.section
= SHN_UNDEF
;
9305 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
9306 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
9307 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
9308 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
9310 tep
->start
.offset
+= aux
->seg_base
;
9311 tep
->end
.offset
+= aux
->seg_base
;
9313 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
9314 tep
->Millicode
= (tmp1
>> 30) & 0x1;
9315 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
9316 tep
->Region_description
= (tmp1
>> 27) & 0x3;
9317 tep
->reserved1
= (tmp1
>> 26) & 0x1;
9318 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
9319 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
9320 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
9321 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
9322 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
9323 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
9324 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
9325 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
9326 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
9327 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
9328 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
9329 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
9330 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
9331 tep
->reserved2
= (tmp1
>> 5) & 0x1;
9332 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
9333 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
9334 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
9335 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
9336 tep
->Cleanup_defined
= tmp1
& 0x1;
9338 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
9339 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
9340 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
9341 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
9342 tep
->reserved4
= (tmp2
>> 27) & 0x1;
9343 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
9347 /* Third, apply any relocations to the unwind table. */
9348 for (relsec
= filedata
->section_headers
;
9349 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9352 if (relsec
->sh_type
!= SHT_RELA
9353 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
9354 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
9357 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
9361 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
9363 unsigned int sym_ndx
;
9364 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
9365 relname
= elf_hppa_reloc_type (r_type
);
9367 if (relname
== NULL
)
9369 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
9373 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
9374 if (! startswith (relname
, "R_PARISC_SEGREL"))
9376 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
9380 i
= rp
->r_offset
/ unw_ent_size
;
9381 if (i
>= aux
->table_len
)
9383 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
9388 sym_ndx
= get_reloc_symindex (rp
->r_info
);
9389 if (sym_ndx
>= aux
->nsyms
)
9391 warn (_("Skipping reloc with invalid symbol index: %u\n"),
9395 sym
= aux
->symtab
+ sym_ndx
;
9397 switch ((rp
->r_offset
% unw_ent_size
) / 4)
9400 aux
->table
[i
].start
.section
= sym
->st_shndx
;
9401 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
9404 aux
->table
[i
].end
.section
= sym
->st_shndx
;
9405 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
9419 hppa_process_unwind (Filedata
* filedata
)
9421 struct hppa_unw_aux_info aux
;
9422 Elf_Internal_Shdr
* unwsec
= NULL
;
9423 Elf_Internal_Shdr
* sec
;
9427 if (filedata
->string_table
== NULL
)
9430 memset (& aux
, 0, sizeof (aux
));
9432 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9434 if (sec
->sh_type
== SHT_SYMTAB
)
9438 error (_("Multiple symbol tables encountered\n"));
9444 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9445 &aux
.strtab
, &aux
.strtab_size
))
9448 else if (section_name_valid (filedata
, sec
)
9449 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9454 printf (_("\nThere are no unwind sections in this file.\n"));
9456 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9458 if (section_name_valid (filedata
, sec
)
9459 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9461 uint64_t num_unwind
= sec
->sh_size
/ 16;
9463 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
9464 "contains %" PRIu64
" entry:\n",
9465 "\nUnwind section '%s' at offset %#" PRIx64
" "
9466 "contains %" PRIu64
" entries:\n",
9468 printable_section_name (filedata
, sec
),
9472 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
9475 if (res
&& aux
.table_len
> 0)
9477 if (! dump_hppa_unwind (filedata
, &aux
))
9481 free ((char *) aux
.table
);
9487 free ((char *) aux
.strtab
);
9494 unsigned char * data
; /* The unwind data. */
9495 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
9496 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
9497 uint64_t nrelas
; /* The number of relocations. */
9498 unsigned int rel_type
; /* REL or RELA ? */
9499 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
9502 struct arm_unw_aux_info
9504 Filedata
* filedata
; /* The file containing the unwind sections. */
9505 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
9506 uint64_t nsyms
; /* Number of symbols. */
9507 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9508 uint64_t nfuns
; /* Number of these symbols. */
9509 char * strtab
; /* The file's string table. */
9510 uint64_t strtab_size
; /* Size of string table. */
9514 arm_print_vma_and_name (Filedata
* filedata
,
9515 struct arm_unw_aux_info
* aux
,
9517 struct absaddr addr
)
9519 const char *procname
;
9520 uint64_t sym_offset
;
9522 if (addr
.section
== SHN_UNDEF
)
9525 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9526 aux
->strtab_size
, addr
, &procname
,
9529 print_vma (fn
, PREFIX_HEX
);
9533 fputs (" <", stdout
);
9534 fputs (procname
, stdout
);
9537 printf ("+0x%" PRIx64
, sym_offset
);
9538 fputc ('>', stdout
);
9545 arm_free_section (struct arm_section
*arm_sec
)
9547 free (arm_sec
->data
);
9548 free (arm_sec
->rela
);
9551 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
9552 cached section and install SEC instead.
9553 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
9554 and return its valued in * WORDP, relocating if necessary.
9555 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
9556 relocation's offset in ADDR.
9557 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
9558 into the string table of the symbol associated with the reloc. If no
9559 reloc was applied store -1 there.
9560 5) Return TRUE upon success, FALSE otherwise. */
9563 get_unwind_section_word (Filedata
* filedata
,
9564 struct arm_unw_aux_info
* aux
,
9565 struct arm_section
* arm_sec
,
9566 Elf_Internal_Shdr
* sec
,
9567 uint64_t word_offset
,
9568 unsigned int * wordp
,
9569 struct absaddr
* addr
,
9570 uint64_t * sym_name
)
9572 Elf_Internal_Rela
*rp
;
9573 Elf_Internal_Sym
*sym
;
9574 const char * relname
;
9578 if (sec
== NULL
|| arm_sec
== NULL
)
9581 addr
->section
= SHN_UNDEF
;
9584 if (sym_name
!= NULL
)
9585 *sym_name
= (uint64_t) -1;
9587 /* If necessary, update the section cache. */
9588 if (sec
!= arm_sec
->sec
)
9590 Elf_Internal_Shdr
*relsec
;
9592 arm_free_section (arm_sec
);
9595 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
9596 sec
->sh_size
, _("unwind data"));
9597 arm_sec
->rela
= NULL
;
9598 arm_sec
->nrelas
= 0;
9600 for (relsec
= filedata
->section_headers
;
9601 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9604 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
9605 || filedata
->section_headers
+ relsec
->sh_info
!= sec
9606 /* PR 15745: Check the section type as well. */
9607 || (relsec
->sh_type
!= SHT_REL
9608 && relsec
->sh_type
!= SHT_RELA
))
9611 arm_sec
->rel_type
= relsec
->sh_type
;
9612 if (relsec
->sh_type
== SHT_REL
)
9614 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
9616 & arm_sec
->rela
, & arm_sec
->nrelas
))
9619 else /* relsec->sh_type == SHT_RELA */
9621 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
9623 & arm_sec
->rela
, & arm_sec
->nrelas
))
9629 arm_sec
->next_rela
= arm_sec
->rela
;
9632 /* If there is no unwind data we can do nothing. */
9633 if (arm_sec
->data
== NULL
)
9636 /* If the offset is invalid then fail. */
9637 if (/* PR 21343 *//* PR 18879 */
9639 || word_offset
> sec
->sh_size
- 4)
9642 /* Get the word at the required offset. */
9643 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
9645 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
9646 if (arm_sec
->rela
== NULL
)
9652 /* Look through the relocs to find the one that applies to the provided offset. */
9654 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
9656 uint64_t prelval
, offset
;
9658 if (rp
->r_offset
> word_offset
&& !wrapped
)
9663 if (rp
->r_offset
> word_offset
)
9666 if (rp
->r_offset
& 3)
9668 warn (_("Skipping unexpected relocation at offset %#" PRIx64
"\n"),
9673 if (rp
->r_offset
< word_offset
)
9676 /* PR 17531: file: 027-161405-0.004 */
9677 if (aux
->symtab
== NULL
)
9680 if (arm_sec
->rel_type
== SHT_REL
)
9682 offset
= word
& 0x7fffffff;
9683 if (offset
& 0x40000000)
9684 offset
|= ~ (uint64_t) 0x7fffffff;
9686 else if (arm_sec
->rel_type
== SHT_RELA
)
9687 offset
= rp
->r_addend
;
9690 error (_("Unknown section relocation type %d encountered\n"),
9695 /* PR 17531 file: 027-1241568-0.004. */
9696 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
9698 error (_("Bad symbol index in unwind relocation "
9699 "(%" PRIu64
" > %" PRIu64
")\n"),
9700 ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
9704 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
9705 offset
+= sym
->st_value
;
9706 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
9708 /* Check that we are processing the expected reloc type. */
9709 if (filedata
->file_header
.e_machine
== EM_ARM
)
9711 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9712 if (relname
== NULL
)
9714 warn (_("Skipping unknown ARM relocation type: %d\n"),
9715 (int) ELF32_R_TYPE (rp
->r_info
));
9719 if (streq (relname
, "R_ARM_NONE"))
9722 if (! streq (relname
, "R_ARM_PREL31"))
9724 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
9728 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9730 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9731 if (relname
== NULL
)
9733 warn (_("Skipping unknown C6000 relocation type: %d\n"),
9734 (int) ELF32_R_TYPE (rp
->r_info
));
9738 if (streq (relname
, "R_C6000_NONE"))
9741 if (! streq (relname
, "R_C6000_PREL31"))
9743 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
9751 /* This function currently only supports ARM and TI unwinders. */
9752 warn (_("Only TI and ARM unwinders are currently supported\n"));
9756 word
= (word
& ~ (uint64_t) 0x7fffffff) | (prelval
& 0x7fffffff);
9757 addr
->section
= sym
->st_shndx
;
9758 addr
->offset
= offset
;
9761 * sym_name
= sym
->st_name
;
9766 arm_sec
->next_rela
= rp
;
9771 static const char *tic6x_unwind_regnames
[16] =
9773 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
9774 "A14", "A13", "A12", "A11", "A10",
9775 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
9779 decode_tic6x_unwind_regmask (unsigned int mask
)
9783 for (i
= 12; mask
; mask
>>= 1, i
--)
9787 fputs (tic6x_unwind_regnames
[i
], stdout
);
9789 fputs (", ", stdout
);
9795 if (remaining == 0 && more_words) \
9798 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
9799 data_offset, & word, & addr, NULL)) \
9805 #define GET_OP(OP) \
9810 (OP) = word >> 24; \
9815 printf (_("[Truncated opcode]\n")); \
9818 printf ("0x%02x ", OP)
9821 decode_arm_unwind_bytecode (Filedata
* filedata
,
9822 struct arm_unw_aux_info
* aux
,
9824 unsigned int remaining
,
9825 unsigned int more_words
,
9826 uint64_t data_offset
,
9827 Elf_Internal_Shdr
* data_sec
,
9828 struct arm_section
* data_arm_sec
)
9830 struct absaddr addr
;
9833 /* Decode the unwinding instructions. */
9836 unsigned int op
, op2
;
9845 printf (" 0x%02x ", op
);
9847 if ((op
& 0xc0) == 0x00)
9849 int offset
= ((op
& 0x3f) << 2) + 4;
9851 printf (" vsp = vsp + %d", offset
);
9853 else if ((op
& 0xc0) == 0x40)
9855 int offset
= ((op
& 0x3f) << 2) + 4;
9857 printf (" vsp = vsp - %d", offset
);
9859 else if ((op
& 0xf0) == 0x80)
9862 if (op
== 0x80 && op2
== 0)
9863 printf (_("Refuse to unwind"));
9866 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
9871 for (i
= 0; i
< 12; i
++)
9872 if (mask
& (1 << i
))
9878 printf ("r%d", 4 + i
);
9883 else if ((op
& 0xf0) == 0x90)
9885 if (op
== 0x9d || op
== 0x9f)
9886 printf (_(" [Reserved]"));
9888 printf (" vsp = r%d", op
& 0x0f);
9890 else if ((op
& 0xf0) == 0xa0)
9892 int end
= 4 + (op
& 0x07);
9897 for (i
= 4; i
<= end
; i
++)
9913 else if (op
== 0xb0)
9914 printf (_(" finish"));
9915 else if (op
== 0xb1)
9918 if (op2
== 0 || (op2
& 0xf0) != 0)
9919 printf (_("[Spare]"));
9922 unsigned int mask
= op2
& 0x0f;
9927 for (i
= 0; i
< 12; i
++)
9928 if (mask
& (1 << i
))
9939 else if (op
== 0xb2)
9941 unsigned char buf
[9];
9942 unsigned int i
, len
;
9945 for (i
= 0; i
< sizeof (buf
); i
++)
9948 if ((buf
[i
] & 0x80) == 0)
9951 if (i
== sizeof (buf
))
9953 error (_("corrupt change to vsp\n"));
9958 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
9959 assert (len
== i
+ 1);
9960 offset
= offset
* 4 + 0x204;
9961 printf ("vsp = vsp + %" PRId64
, offset
);
9964 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
9966 unsigned int first
, last
;
9973 printf ("pop {D%d", first
);
9975 printf ("-D%d", first
+ last
);
9978 else if (op
== 0xb4)
9979 printf (_(" pop {ra_auth_code}"));
9980 else if (op
== 0xb5)
9981 printf (_(" vsp as modifier for PAC validation"));
9982 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
9984 unsigned int count
= op
& 0x07;
9988 printf ("-D%d", 8 + count
);
9991 else if (op
>= 0xc0 && op
<= 0xc5)
9993 unsigned int count
= op
& 0x07;
9995 printf (" pop {wR10");
9997 printf ("-wR%d", 10 + count
);
10000 else if (op
== 0xc6)
10002 unsigned int first
, last
;
10007 printf ("pop {wR%d", first
);
10009 printf ("-wR%d", first
+ last
);
10012 else if (op
== 0xc7)
10015 if (op2
== 0 || (op2
& 0xf0) != 0)
10016 printf (_("[Spare]"));
10019 unsigned int mask
= op2
& 0x0f;
10024 for (i
= 0; i
< 4; i
++)
10025 if (mask
& (1 << i
))
10031 printf ("wCGR%d", i
);
10038 printf (_(" [unsupported opcode]"));
10049 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
10050 struct arm_unw_aux_info
* aux
,
10052 unsigned int remaining
,
10053 unsigned int more_words
,
10054 uint64_t data_offset
,
10055 Elf_Internal_Shdr
* data_sec
,
10056 struct arm_section
* data_arm_sec
)
10058 struct absaddr addr
;
10060 /* Decode the unwinding instructions. */
10063 unsigned int op
, op2
;
10066 if (remaining
== 0)
10072 printf (" 0x%02x ", op
);
10074 if ((op
& 0xc0) == 0x00)
10076 int offset
= ((op
& 0x3f) << 3) + 8;
10077 printf (" sp = sp + %d", offset
);
10079 else if ((op
& 0xc0) == 0x80)
10082 if (op
== 0x80 && op2
== 0)
10083 printf (_("Refuse to unwind"));
10086 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
10088 printf ("pop compact {");
10092 decode_tic6x_unwind_regmask (mask
);
10096 else if ((op
& 0xf0) == 0xc0)
10099 unsigned int nregs
;
10104 unsigned int offset
;
10108 /* Scan entire instruction first so that GET_OP output is not
10109 interleaved with disassembly. */
10111 for (i
= 0; nregs
< (op
& 0xf); i
++)
10117 regpos
[nregs
].offset
= i
* 2;
10118 regpos
[nregs
].reg
= reg
;
10125 regpos
[nregs
].offset
= i
* 2 + 1;
10126 regpos
[nregs
].reg
= reg
;
10131 printf (_("pop frame {"));
10134 printf (_("*corrupt* - no registers specified"));
10139 for (i
= i
* 2; i
> 0; i
--)
10141 if (regpos
[reg
].offset
== i
- 1)
10143 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
10150 fputs (name
, stdout
);
10158 else if (op
== 0xd0)
10159 printf (" MOV FP, SP");
10160 else if (op
== 0xd1)
10161 printf (" __c6xabi_pop_rts");
10162 else if (op
== 0xd2)
10164 unsigned char buf
[9];
10165 unsigned int i
, len
;
10168 for (i
= 0; i
< sizeof (buf
); i
++)
10171 if ((buf
[i
] & 0x80) == 0)
10174 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
10175 if (i
== sizeof (buf
))
10177 warn (_("Corrupt stack pointer adjustment detected\n"));
10181 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
10182 assert (len
== i
+ 1);
10183 offset
= offset
* 8 + 0x408;
10184 printf (_("sp = sp + %" PRId64
), offset
);
10186 else if ((op
& 0xf0) == 0xe0)
10188 if ((op
& 0x0f) == 7)
10189 printf (" RETURN");
10191 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
10195 printf (_(" [unsupported opcode]"));
10204 arm_expand_prel31 (Filedata
* filedata
, uint64_t word
, uint64_t where
)
10208 offset
= word
& 0x7fffffff;
10209 if (offset
& 0x40000000)
10210 offset
|= ~ (uint64_t) 0x7fffffff;
10212 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
10215 return offset
+ where
;
10219 decode_arm_unwind (Filedata
* filedata
,
10220 struct arm_unw_aux_info
* aux
,
10222 unsigned int remaining
,
10223 uint64_t data_offset
,
10224 Elf_Internal_Shdr
* data_sec
,
10225 struct arm_section
* data_arm_sec
)
10228 unsigned int more_words
= 0;
10229 struct absaddr addr
;
10230 uint64_t sym_name
= (uint64_t) -1;
10233 if (remaining
== 0)
10235 /* Fetch the first word.
10236 Note - when decoding an object file the address extracted
10237 here will always be 0. So we also pass in the sym_name
10238 parameter so that we can find the symbol associated with
10239 the personality routine. */
10240 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
10241 & word
, & addr
, & sym_name
))
10248 addr
.section
= SHN_UNDEF
;
10252 if ((word
& 0x80000000) == 0)
10254 /* Expand prel31 for personality routine. */
10256 const char *procname
;
10258 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
10259 printf (_(" Personality routine: "));
10261 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
10262 && sym_name
!= (uint64_t) -1 && sym_name
< aux
->strtab_size
)
10264 procname
= aux
->strtab
+ sym_name
;
10265 print_vma (fn
, PREFIX_HEX
);
10268 fputs (" <", stdout
);
10269 fputs (procname
, stdout
);
10270 fputc ('>', stdout
);
10274 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
10275 fputc ('\n', stdout
);
10277 /* The GCC personality routines use the standard compact
10278 encoding, starting with one byte giving the number of
10280 if (procname
!= NULL
10281 && (startswith (procname
, "__gcc_personality_v0")
10282 || startswith (procname
, "__gxx_personality_v0")
10283 || startswith (procname
, "__gcj_personality_v0")
10284 || startswith (procname
, "__gnu_objc_personality_v0")))
10291 printf (_(" [Truncated data]\n"));
10294 more_words
= word
>> 24;
10304 /* ARM EHABI Section 6.3:
10306 An exception-handling table entry for the compact model looks like:
10308 31 30-28 27-24 23-0
10309 -- ----- ----- ----
10310 1 0 index Data for personalityRoutine[index] */
10312 if (filedata
->file_header
.e_machine
== EM_ARM
10313 && (word
& 0x70000000))
10315 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
10319 per_index
= (word
>> 24) & 0x7f;
10320 printf (_(" Compact model index: %d\n"), per_index
);
10321 if (per_index
== 0)
10327 else if (per_index
< 3)
10329 more_words
= (word
>> 16) & 0xff;
10335 switch (filedata
->file_header
.e_machine
)
10340 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10341 data_offset
, data_sec
, data_arm_sec
))
10346 warn (_("Unknown ARM compact model index encountered\n"));
10347 printf (_(" [reserved]\n"));
10355 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10356 data_offset
, data_sec
, data_arm_sec
))
10359 else if (per_index
< 5)
10361 if (((word
>> 17) & 0x7f) == 0x7f)
10362 printf (_(" Restore stack from frame pointer\n"));
10364 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
10365 printf (_(" Registers restored: "));
10366 if (per_index
== 4)
10367 printf (" (compact) ");
10368 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
10370 printf (_(" Return register: %s\n"),
10371 tic6x_unwind_regnames
[word
& 0xf]);
10374 printf (_(" [reserved (%d)]\n"), per_index
);
10378 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
10379 filedata
->file_header
.e_machine
);
10383 /* Decode the descriptors. Not implemented. */
10389 dump_arm_unwind (Filedata
* filedata
,
10390 struct arm_unw_aux_info
* aux
,
10391 Elf_Internal_Shdr
* exidx_sec
)
10393 struct arm_section exidx_arm_sec
, extab_arm_sec
;
10394 unsigned int i
, exidx_len
;
10398 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
10399 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
10400 exidx_len
= exidx_sec
->sh_size
/ 8;
10402 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
10403 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
10404 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
10405 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
10406 aux
->nfuns
= nfuns
;
10407 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
10409 for (i
= 0; i
< exidx_len
; i
++)
10411 unsigned int exidx_fn
, exidx_entry
;
10412 struct absaddr fn_addr
, entry_addr
;
10415 fputc ('\n', stdout
);
10417 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10418 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
10419 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10420 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
10422 free (aux
->funtab
);
10423 arm_free_section (& exidx_arm_sec
);
10424 arm_free_section (& extab_arm_sec
);
10428 /* ARM EHABI, Section 5:
10429 An index table entry consists of 2 words.
10430 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
10431 if (exidx_fn
& 0x80000000)
10433 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
10437 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
10439 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
10440 fputs (": ", stdout
);
10442 if (exidx_entry
== 1)
10444 print_vma (exidx_entry
, PREFIX_HEX
);
10445 fputs (" [cantunwind]\n", stdout
);
10447 else if (exidx_entry
& 0x80000000)
10449 print_vma (exidx_entry
, PREFIX_HEX
);
10450 fputc ('\n', stdout
);
10451 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
10455 uint64_t table
, table_offset
= 0;
10456 Elf_Internal_Shdr
*table_sec
;
10458 fputs ("@", stdout
);
10459 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
10460 print_vma (table
, PREFIX_HEX
);
10463 /* Locate the matching .ARM.extab. */
10464 if (entry_addr
.section
!= SHN_UNDEF
10465 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
10467 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
10468 table_offset
= entry_addr
.offset
;
10470 if (table_offset
> table_sec
->sh_size
)
10472 warn (_("Unwind entry contains corrupt offset (%#" PRIx64
") into section %s\n"),
10474 printable_section_name (filedata
, table_sec
));
10481 table_sec
= find_section_by_address (filedata
, table
);
10482 if (table_sec
!= NULL
)
10483 table_offset
= table
- table_sec
->sh_addr
;
10486 if (table_sec
== NULL
)
10488 warn (_("Could not locate .ARM.extab section containing %#" PRIx64
".\n"),
10494 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
10502 free (aux
->funtab
);
10503 arm_free_section (&exidx_arm_sec
);
10504 arm_free_section (&extab_arm_sec
);
10509 /* Used for both ARM and C6X unwinding tables. */
10512 arm_process_unwind (Filedata
* filedata
)
10514 struct arm_unw_aux_info aux
;
10515 Elf_Internal_Shdr
*unwsec
= NULL
;
10516 Elf_Internal_Shdr
*sec
;
10518 unsigned int sec_type
;
10521 switch (filedata
->file_header
.e_machine
)
10524 sec_type
= SHT_ARM_EXIDX
;
10528 sec_type
= SHT_C6000_UNWIND
;
10532 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
10533 filedata
->file_header
.e_machine
);
10537 if (filedata
->string_table
== NULL
)
10540 memset (& aux
, 0, sizeof (aux
));
10541 aux
.filedata
= filedata
;
10543 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10545 if (sec
->sh_type
== SHT_SYMTAB
)
10549 error (_("Multiple symbol tables encountered\n"));
10555 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
10556 &aux
.strtab
, &aux
.strtab_size
))
10559 else if (sec
->sh_type
== sec_type
)
10563 if (unwsec
== NULL
)
10564 printf (_("\nThere are no unwind sections in this file.\n"));
10566 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10568 if (sec
->sh_type
== sec_type
)
10570 uint64_t num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
10571 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
10572 "contains %" PRIu64
" entry:\n",
10573 "\nUnwind section '%s' at offset %#" PRIx64
" "
10574 "contains %" PRIu64
" entries:\n",
10576 printable_section_name (filedata
, sec
),
10580 if (! dump_arm_unwind (filedata
, &aux
, sec
))
10586 free ((char *) aux
.strtab
);
10592 no_processor_specific_unwind (Filedata
* filedata ATTRIBUTE_UNUSED
)
10594 printf (_("No processor specific unwind information to decode\n"));
10599 process_unwind (Filedata
* filedata
)
10601 struct unwind_handler
10603 unsigned int machtype
;
10604 bool (* handler
)(Filedata
*);
10607 { EM_ARM
, arm_process_unwind
},
10608 { EM_IA_64
, ia64_process_unwind
},
10609 { EM_PARISC
, hppa_process_unwind
},
10610 { EM_TI_C6000
, arm_process_unwind
},
10611 { EM_386
, no_processor_specific_unwind
},
10612 { EM_X86_64
, no_processor_specific_unwind
},
10620 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
10621 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
10622 return handlers
[i
].handler (filedata
);
10624 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
10625 get_machine_name (filedata
->file_header
.e_machine
));
10630 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
10632 switch (entry
->d_tag
)
10634 case DT_AARCH64_BTI_PLT
:
10635 case DT_AARCH64_PAC_PLT
:
10638 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10645 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
10647 switch (entry
->d_tag
)
10649 case DT_MIPS_FLAGS
:
10650 if (entry
->d_un
.d_val
== 0)
10651 printf (_("NONE"));
10654 static const char * opts
[] =
10656 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
10657 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
10658 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
10659 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
10665 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
10666 if (entry
->d_un
.d_val
& (1 << cnt
))
10668 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
10674 case DT_MIPS_IVERSION
:
10675 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
10676 printf (_("Interface Version: %s"),
10677 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
10679 printf (_("Interface Version: <corrupt: %" PRIx64
">"),
10680 entry
->d_un
.d_ptr
);
10683 case DT_MIPS_TIME_STAMP
:
10687 time_t atime
= entry
->d_un
.d_val
;
10689 tmp
= gmtime (&atime
);
10690 /* PR 17531: file: 6accc532. */
10692 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
10694 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
10695 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10696 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10697 printf (_("Time Stamp: %s"), timebuf
);
10701 case DT_MIPS_RLD_VERSION
:
10702 case DT_MIPS_LOCAL_GOTNO
:
10703 case DT_MIPS_CONFLICTNO
:
10704 case DT_MIPS_LIBLISTNO
:
10705 case DT_MIPS_SYMTABNO
:
10706 case DT_MIPS_UNREFEXTNO
:
10707 case DT_MIPS_HIPAGENO
:
10708 case DT_MIPS_DELTA_CLASS_NO
:
10709 case DT_MIPS_DELTA_INSTANCE_NO
:
10710 case DT_MIPS_DELTA_RELOC_NO
:
10711 case DT_MIPS_DELTA_SYM_NO
:
10712 case DT_MIPS_DELTA_CLASSSYM_NO
:
10713 case DT_MIPS_COMPACT_SIZE
:
10714 print_vma (entry
->d_un
.d_val
, DEC
);
10717 case DT_MIPS_XHASH
:
10718 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10719 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10720 /* Falls through. */
10723 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10729 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
10731 switch (entry
->d_tag
)
10733 case DT_HP_DLD_FLAGS
:
10742 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
10743 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
10744 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
10745 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
10746 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
10747 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
10748 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
10749 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
10750 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
10751 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
10752 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
10753 { DT_HP_GST
, "HP_GST" },
10754 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
10755 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
10756 { DT_HP_NODELETE
, "HP_NODELETE" },
10757 { DT_HP_GROUP
, "HP_GROUP" },
10758 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
10762 uint64_t val
= entry
->d_un
.d_val
;
10764 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
10765 if (val
& flags
[cnt
].bit
)
10769 fputs (flags
[cnt
].str
, stdout
);
10771 val
^= flags
[cnt
].bit
;
10774 if (val
!= 0 || first
)
10778 print_vma (val
, HEX
);
10784 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10790 /* VMS vs Unix time offset and factor. */
10792 #define VMS_EPOCH_OFFSET 35067168000000000LL
10793 #define VMS_GRANULARITY_FACTOR 10000000
10795 #define INT64_MIN (-9223372036854775807LL - 1)
10798 /* Display a VMS time in a human readable format. */
10801 print_vms_time (int64_t vmstime
)
10803 struct tm
*tm
= NULL
;
10806 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
10808 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
10810 if (unxtime
== vmstime
)
10811 tm
= gmtime (&unxtime
);
10814 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
10815 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
10816 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
10820 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
10822 switch (entry
->d_tag
)
10824 case DT_IA_64_PLT_RESERVE
:
10825 /* First 3 slots reserved. */
10826 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10828 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
10831 case DT_IA_64_VMS_LINKTIME
:
10832 print_vms_time (entry
->d_un
.d_val
);
10835 case DT_IA_64_VMS_LNKFLAGS
:
10836 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10837 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
10838 printf (" CALL_DEBUG");
10839 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
10840 printf (" NOP0BUFS");
10841 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
10842 printf (" P0IMAGE");
10843 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
10844 printf (" MKTHREADS");
10845 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
10846 printf (" UPCALLS");
10847 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
10848 printf (" IMGSTA");
10849 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
10850 printf (" INITIALIZE");
10851 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
10853 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
10854 printf (" EXE_INIT");
10855 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
10856 printf (" TBK_IN_IMG");
10857 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
10858 printf (" DBG_IN_IMG");
10859 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
10860 printf (" TBK_IN_DSF");
10861 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
10862 printf (" DBG_IN_DSF");
10863 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
10864 printf (" SIGNATURES");
10865 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
10866 printf (" REL_SEG_OFF");
10870 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10877 get_32bit_dynamic_section (Filedata
* filedata
)
10879 Elf32_External_Dyn
* edyn
;
10880 Elf32_External_Dyn
* ext
;
10881 Elf_Internal_Dyn
* entry
;
10883 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
10884 filedata
->dynamic_addr
, 1,
10885 filedata
->dynamic_size
,
10886 _("dynamic section"));
10890 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10891 might not have the luxury of section headers. Look for the DT_NULL
10892 terminator to determine the number of entries. */
10893 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10894 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10897 filedata
->dynamic_nent
++;
10898 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10902 filedata
->dynamic_section
10903 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10904 if (filedata
->dynamic_section
== NULL
)
10906 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
10907 filedata
->dynamic_nent
);
10912 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10913 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10916 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10917 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10926 get_64bit_dynamic_section (Filedata
* filedata
)
10928 Elf64_External_Dyn
* edyn
;
10929 Elf64_External_Dyn
* ext
;
10930 Elf_Internal_Dyn
* entry
;
10932 /* Read in the data. */
10933 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
10934 filedata
->dynamic_addr
, 1,
10935 filedata
->dynamic_size
,
10936 _("dynamic section"));
10940 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10941 might not have the luxury of section headers. Look for the DT_NULL
10942 terminator to determine the number of entries. */
10943 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10944 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
10945 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10948 filedata
->dynamic_nent
++;
10949 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10953 filedata
->dynamic_section
10954 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10955 if (filedata
->dynamic_section
== NULL
)
10957 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
10958 filedata
->dynamic_nent
);
10963 /* Convert from external to internal formats. */
10964 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10965 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10968 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10969 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10978 get_dynamic_section (Filedata
*filedata
)
10980 if (filedata
->dynamic_section
)
10984 return get_32bit_dynamic_section (filedata
);
10986 return get_64bit_dynamic_section (filedata
);
10990 print_dynamic_flags (uint64_t flags
)
10998 flag
= flags
& - flags
;
11004 putc (' ', stdout
);
11008 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
11009 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
11010 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
11011 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
11012 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
11013 default: fputs (_("unknown"), stdout
); break;
11020 get_dynamic_data (Filedata
* filedata
, uint64_t number
, unsigned int ent_size
)
11022 unsigned char * e_data
;
11025 /* If size_t is smaller than uint64_t, eg because you are building
11026 on a 32-bit host, then make sure that when number is cast to
11027 size_t no information is lost. */
11028 if ((size_t) number
!= number
11029 || ent_size
* number
/ ent_size
!= number
)
11031 error (_("Size overflow prevents reading %" PRIu64
11032 " elements of size %u\n"),
11037 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
11038 attempting to allocate memory when the read is bound to fail. */
11039 if (ent_size
* number
> filedata
->file_size
)
11041 error (_("Invalid number of dynamic entries: %" PRIu64
"\n"),
11046 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
11047 if (e_data
== NULL
)
11049 error (_("Out of memory reading %" PRIu64
" dynamic entries\n"),
11054 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
11056 error (_("Unable to read in %" PRIu64
" bytes of dynamic data\n"),
11057 number
* ent_size
);
11062 i_data
= (uint64_t *) cmalloc ((size_t) number
, sizeof (*i_data
));
11063 if (i_data
== NULL
)
11065 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
11072 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
11080 get_num_dynamic_syms (Filedata
* filedata
)
11082 uint64_t num_of_syms
= 0;
11084 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
11085 return num_of_syms
;
11087 if (filedata
->dynamic_info
[DT_HASH
])
11089 unsigned char nb
[8];
11090 unsigned char nc
[8];
11091 unsigned int hash_ent_size
= 4;
11093 if ((filedata
->file_header
.e_machine
== EM_ALPHA
11094 || filedata
->file_header
.e_machine
== EM_S390
11095 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
11096 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
11099 if (fseek64 (filedata
->handle
,
11100 (filedata
->archive_file_offset
11101 + offset_from_vma (filedata
,
11102 filedata
->dynamic_info
[DT_HASH
],
11103 sizeof nb
+ sizeof nc
)),
11106 error (_("Unable to seek to start of dynamic information\n"));
11110 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
11112 error (_("Failed to read in number of buckets\n"));
11116 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
11118 error (_("Failed to read in number of chains\n"));
11122 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
11123 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
11125 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
11127 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
11129 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
11132 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
11133 num_of_syms
= filedata
->nchains
;
11136 if (num_of_syms
== 0)
11138 free (filedata
->buckets
);
11139 filedata
->buckets
= NULL
;
11140 free (filedata
->chains
);
11141 filedata
->chains
= NULL
;
11142 filedata
->nbuckets
= 0;
11146 if (filedata
->dynamic_info_DT_GNU_HASH
)
11148 unsigned char nb
[16];
11149 uint64_t i
, maxchain
= 0xffffffff, bitmaskwords
;
11150 uint64_t buckets_vma
;
11153 if (fseek64 (filedata
->handle
,
11154 (filedata
->archive_file_offset
11155 + offset_from_vma (filedata
,
11156 filedata
->dynamic_info_DT_GNU_HASH
,
11160 error (_("Unable to seek to start of dynamic information\n"));
11164 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
11166 error (_("Failed to read in number of buckets\n"));
11170 filedata
->ngnubuckets
= byte_get (nb
, 4);
11171 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
11172 bitmaskwords
= byte_get (nb
+ 8, 4);
11173 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
11175 buckets_vma
+= bitmaskwords
* 4;
11177 buckets_vma
+= bitmaskwords
* 8;
11179 if (fseek64 (filedata
->handle
,
11180 (filedata
->archive_file_offset
11181 + offset_from_vma (filedata
, buckets_vma
, 4)),
11184 error (_("Unable to seek to start of dynamic information\n"));
11188 filedata
->gnubuckets
11189 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
11191 if (filedata
->gnubuckets
== NULL
)
11194 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
11195 if (filedata
->gnubuckets
[i
] != 0)
11197 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
11200 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
11201 maxchain
= filedata
->gnubuckets
[i
];
11204 if (maxchain
== 0xffffffff)
11207 maxchain
-= filedata
->gnusymidx
;
11209 if (fseek64 (filedata
->handle
,
11210 (filedata
->archive_file_offset
11211 + offset_from_vma (filedata
,
11212 buckets_vma
+ 4 * (filedata
->ngnubuckets
11217 error (_("Unable to seek to start of dynamic information\n"));
11223 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
11225 error (_("Failed to determine last chain length\n"));
11229 if (maxchain
+ 1 == 0)
11234 while ((byte_get (nb
, 4) & 1) == 0);
11236 if (fseek64 (filedata
->handle
,
11237 (filedata
->archive_file_offset
11238 + offset_from_vma (filedata
, (buckets_vma
11239 + 4 * filedata
->ngnubuckets
),
11243 error (_("Unable to seek to start of dynamic information\n"));
11247 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
11248 filedata
->ngnuchains
= maxchain
;
11250 if (filedata
->gnuchains
== NULL
)
11253 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11255 if (fseek64 (filedata
->handle
,
11256 (filedata
->archive_file_offset
11257 + offset_from_vma (filedata
, (buckets_vma
11258 + 4 * (filedata
->ngnubuckets
11262 error (_("Unable to seek to start of dynamic information\n"));
11266 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
11267 if (filedata
->mipsxlat
== NULL
)
11271 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
11272 if (filedata
->gnubuckets
[hn
] != 0)
11274 uint64_t si
= filedata
->gnubuckets
[hn
];
11275 uint64_t off
= si
- filedata
->gnusymidx
;
11279 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11281 if (off
< filedata
->ngnuchains
11282 && filedata
->mipsxlat
[off
] >= num_of_syms
)
11283 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
11287 if (si
>= num_of_syms
)
11288 num_of_syms
= si
+ 1;
11292 while (off
< filedata
->ngnuchains
11293 && (filedata
->gnuchains
[off
++] & 1) == 0);
11296 if (num_of_syms
== 0)
11299 free (filedata
->mipsxlat
);
11300 filedata
->mipsxlat
= NULL
;
11301 free (filedata
->gnuchains
);
11302 filedata
->gnuchains
= NULL
;
11303 free (filedata
->gnubuckets
);
11304 filedata
->gnubuckets
= NULL
;
11305 filedata
->ngnubuckets
= 0;
11306 filedata
->ngnuchains
= 0;
11310 return num_of_syms
;
11313 /* Parse and display the contents of the dynamic section. */
11316 process_dynamic_section (Filedata
* filedata
)
11318 Elf_Internal_Dyn
* entry
;
11320 if (filedata
->dynamic_size
<= 1)
11324 if (filedata
->is_separate
)
11325 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
11326 filedata
->file_name
);
11328 printf (_("\nThere is no dynamic section in this file.\n"));
11334 if (!get_dynamic_section (filedata
))
11337 /* Find the appropriate symbol table. */
11338 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
11340 uint64_t num_of_syms
;
11342 for (entry
= filedata
->dynamic_section
;
11343 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11345 if (entry
->d_tag
== DT_SYMTAB
)
11346 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
11347 else if (entry
->d_tag
== DT_SYMENT
)
11348 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
11349 else if (entry
->d_tag
== DT_HASH
)
11350 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
11351 else if (entry
->d_tag
== DT_GNU_HASH
)
11352 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11353 else if ((filedata
->file_header
.e_machine
== EM_MIPS
11354 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
11355 && entry
->d_tag
== DT_MIPS_XHASH
)
11357 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
11358 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11361 num_of_syms
= get_num_dynamic_syms (filedata
);
11363 if (num_of_syms
!= 0
11364 && filedata
->dynamic_symbols
== NULL
11365 && filedata
->dynamic_info
[DT_SYMTAB
]
11366 && filedata
->dynamic_info
[DT_SYMENT
])
11368 Elf_Internal_Phdr
*seg
;
11369 uint64_t vma
= filedata
->dynamic_info
[DT_SYMTAB
];
11371 if (! get_program_headers (filedata
))
11373 error (_("Cannot interpret virtual addresses "
11374 "without program headers.\n"));
11378 for (seg
= filedata
->program_headers
;
11379 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
11382 if (seg
->p_type
!= PT_LOAD
)
11385 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
11387 /* See PR 21379 for a reproducer. */
11388 error (_("Invalid PT_LOAD entry\n"));
11392 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
11393 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
11395 /* Since we do not know how big the symbol table is,
11396 we default to reading in up to the end of PT_LOAD
11397 segment and processing that. This is overkill, I
11398 know, but it should work. */
11399 Elf_Internal_Shdr section
;
11400 section
.sh_offset
= (vma
- seg
->p_vaddr
11402 section
.sh_size
= (num_of_syms
11403 * filedata
->dynamic_info
[DT_SYMENT
]);
11404 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
11407 && filedata
->dynamic_symtab_section
!= NULL
11408 && ((filedata
->dynamic_symtab_section
->sh_offset
11409 != section
.sh_offset
)
11410 || (filedata
->dynamic_symtab_section
->sh_size
11411 != section
.sh_size
)
11412 || (filedata
->dynamic_symtab_section
->sh_entsize
11413 != section
.sh_entsize
)))
11415 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
11417 section
.sh_name
= filedata
->string_table_length
;
11418 filedata
->dynamic_symbols
11419 = get_elf_symbols (filedata
, §ion
,
11420 &filedata
->num_dynamic_syms
);
11421 if (filedata
->dynamic_symbols
== NULL
11422 || filedata
->num_dynamic_syms
!= num_of_syms
)
11424 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
11433 /* Similarly find a string table. */
11434 if (filedata
->dynamic_strings
== NULL
)
11435 for (entry
= filedata
->dynamic_section
;
11436 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11439 if (entry
->d_tag
== DT_STRTAB
)
11440 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
11442 if (entry
->d_tag
== DT_STRSZ
)
11443 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
11445 if (filedata
->dynamic_info
[DT_STRTAB
]
11446 && filedata
->dynamic_info
[DT_STRSZ
])
11449 uint64_t str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
11451 offset
= offset_from_vma (filedata
,
11452 filedata
->dynamic_info
[DT_STRTAB
],
11455 && filedata
->dynamic_strtab_section
11456 && ((filedata
->dynamic_strtab_section
->sh_offset
11457 != (file_ptr
) offset
)
11458 || (filedata
->dynamic_strtab_section
->sh_size
11461 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
11463 filedata
->dynamic_strings
11464 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
11465 _("dynamic string table"));
11466 if (filedata
->dynamic_strings
== NULL
)
11468 error (_("Corrupt DT_STRTAB dynamic entry\n"));
11472 filedata
->dynamic_strings_length
= str_tab_len
;
11477 /* And find the syminfo section if available. */
11478 if (filedata
->dynamic_syminfo
== NULL
)
11480 uint64_t syminsz
= 0;
11482 for (entry
= filedata
->dynamic_section
;
11483 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11486 if (entry
->d_tag
== DT_SYMINENT
)
11488 /* Note: these braces are necessary to avoid a syntax
11489 error from the SunOS4 C compiler. */
11490 /* PR binutils/17531: A corrupt file can trigger this test.
11491 So do not use an assert, instead generate an error message. */
11492 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
11493 error (_("Bad value (%d) for SYMINENT entry\n"),
11494 (int) entry
->d_un
.d_val
);
11496 else if (entry
->d_tag
== DT_SYMINSZ
)
11497 syminsz
= entry
->d_un
.d_val
;
11498 else if (entry
->d_tag
== DT_SYMINFO
)
11499 filedata
->dynamic_syminfo_offset
11500 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
11503 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
11505 Elf_External_Syminfo
* extsyminfo
;
11506 Elf_External_Syminfo
* extsym
;
11507 Elf_Internal_Syminfo
* syminfo
;
11509 /* There is a syminfo section. Read the data. */
11510 extsyminfo
= (Elf_External_Syminfo
*)
11511 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
11512 1, syminsz
, _("symbol information"));
11516 if (filedata
->dynamic_syminfo
!= NULL
)
11518 error (_("Multiple dynamic symbol information sections found\n"));
11519 free (filedata
->dynamic_syminfo
);
11521 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
11522 if (filedata
->dynamic_syminfo
== NULL
)
11524 error (_("Out of memory allocating %" PRIu64
11525 " bytes for dynamic symbol info\n"),
11530 filedata
->dynamic_syminfo_nent
11531 = syminsz
/ sizeof (Elf_External_Syminfo
);
11532 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
11533 syminfo
< (filedata
->dynamic_syminfo
11534 + filedata
->dynamic_syminfo_nent
);
11535 ++syminfo
, ++extsym
)
11537 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
11538 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
11545 if (do_dynamic
&& filedata
->dynamic_addr
)
11547 if (filedata
->is_separate
)
11548 printf (ngettext ("\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
11549 "\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
11550 filedata
->dynamic_nent
),
11551 filedata
->file_name
,
11552 filedata
->dynamic_addr
,
11553 filedata
->dynamic_nent
);
11555 printf (ngettext ("\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
11556 "\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
11557 filedata
->dynamic_nent
),
11558 filedata
->dynamic_addr
,
11559 filedata
->dynamic_nent
);
11562 printf (_(" Tag Type Name/Value\n"));
11564 for (entry
= filedata
->dynamic_section
;
11565 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11570 const char * dtype
;
11573 print_vma (entry
->d_tag
, FULL_HEX
);
11574 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
11575 printf (" (%s)%*s", dtype
,
11576 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
11579 switch (entry
->d_tag
)
11583 print_dynamic_flags (entry
->d_un
.d_val
);
11593 switch (entry
->d_tag
)
11596 printf (_("Auxiliary library"));
11600 printf (_("Filter library"));
11604 printf (_("Configuration file"));
11608 printf (_("Dependency audit library"));
11612 printf (_("Audit library"));
11616 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11617 printf (": [%s]\n",
11618 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
11622 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11631 printf (_("Flags:"));
11633 if (entry
->d_un
.d_val
== 0)
11634 printf (_(" None\n"));
11637 uint64_t val
= entry
->d_un
.d_val
;
11639 if (val
& DTF_1_PARINIT
)
11641 printf (" PARINIT");
11642 val
^= DTF_1_PARINIT
;
11644 if (val
& DTF_1_CONFEXP
)
11646 printf (" CONFEXP");
11647 val
^= DTF_1_CONFEXP
;
11650 printf (" %" PRIx64
, val
);
11659 printf (_("Flags:"));
11661 if (entry
->d_un
.d_val
== 0)
11662 printf (_(" None\n"));
11665 uint64_t val
= entry
->d_un
.d_val
;
11667 if (val
& DF_P1_LAZYLOAD
)
11669 printf (" LAZYLOAD");
11670 val
^= DF_P1_LAZYLOAD
;
11672 if (val
& DF_P1_GROUPPERM
)
11674 printf (" GROUPPERM");
11675 val
^= DF_P1_GROUPPERM
;
11678 printf (" %" PRIx64
, val
);
11687 printf (_("Flags:"));
11688 if (entry
->d_un
.d_val
== 0)
11689 printf (_(" None\n"));
11692 uint64_t val
= entry
->d_un
.d_val
;
11694 if (val
& DF_1_NOW
)
11699 if (val
& DF_1_GLOBAL
)
11701 printf (" GLOBAL");
11702 val
^= DF_1_GLOBAL
;
11704 if (val
& DF_1_GROUP
)
11709 if (val
& DF_1_NODELETE
)
11711 printf (" NODELETE");
11712 val
^= DF_1_NODELETE
;
11714 if (val
& DF_1_LOADFLTR
)
11716 printf (" LOADFLTR");
11717 val
^= DF_1_LOADFLTR
;
11719 if (val
& DF_1_INITFIRST
)
11721 printf (" INITFIRST");
11722 val
^= DF_1_INITFIRST
;
11724 if (val
& DF_1_NOOPEN
)
11726 printf (" NOOPEN");
11727 val
^= DF_1_NOOPEN
;
11729 if (val
& DF_1_ORIGIN
)
11731 printf (" ORIGIN");
11732 val
^= DF_1_ORIGIN
;
11734 if (val
& DF_1_DIRECT
)
11736 printf (" DIRECT");
11737 val
^= DF_1_DIRECT
;
11739 if (val
& DF_1_TRANS
)
11744 if (val
& DF_1_INTERPOSE
)
11746 printf (" INTERPOSE");
11747 val
^= DF_1_INTERPOSE
;
11749 if (val
& DF_1_NODEFLIB
)
11751 printf (" NODEFLIB");
11752 val
^= DF_1_NODEFLIB
;
11754 if (val
& DF_1_NODUMP
)
11756 printf (" NODUMP");
11757 val
^= DF_1_NODUMP
;
11759 if (val
& DF_1_CONFALT
)
11761 printf (" CONFALT");
11762 val
^= DF_1_CONFALT
;
11764 if (val
& DF_1_ENDFILTEE
)
11766 printf (" ENDFILTEE");
11767 val
^= DF_1_ENDFILTEE
;
11769 if (val
& DF_1_DISPRELDNE
)
11771 printf (" DISPRELDNE");
11772 val
^= DF_1_DISPRELDNE
;
11774 if (val
& DF_1_DISPRELPND
)
11776 printf (" DISPRELPND");
11777 val
^= DF_1_DISPRELPND
;
11779 if (val
& DF_1_NODIRECT
)
11781 printf (" NODIRECT");
11782 val
^= DF_1_NODIRECT
;
11784 if (val
& DF_1_IGNMULDEF
)
11786 printf (" IGNMULDEF");
11787 val
^= DF_1_IGNMULDEF
;
11789 if (val
& DF_1_NOKSYMS
)
11791 printf (" NOKSYMS");
11792 val
^= DF_1_NOKSYMS
;
11794 if (val
& DF_1_NOHDR
)
11799 if (val
& DF_1_EDITED
)
11801 printf (" EDITED");
11802 val
^= DF_1_EDITED
;
11804 if (val
& DF_1_NORELOC
)
11806 printf (" NORELOC");
11807 val
^= DF_1_NORELOC
;
11809 if (val
& DF_1_SYMINTPOSE
)
11811 printf (" SYMINTPOSE");
11812 val
^= DF_1_SYMINTPOSE
;
11814 if (val
& DF_1_GLOBAUDIT
)
11816 printf (" GLOBAUDIT");
11817 val
^= DF_1_GLOBAUDIT
;
11819 if (val
& DF_1_SINGLETON
)
11821 printf (" SINGLETON");
11822 val
^= DF_1_SINGLETON
;
11824 if (val
& DF_1_STUB
)
11829 if (val
& DF_1_PIE
)
11834 if (val
& DF_1_KMOD
)
11839 if (val
& DF_1_WEAKFILTER
)
11841 printf (" WEAKFILTER");
11842 val
^= DF_1_WEAKFILTER
;
11844 if (val
& DF_1_NOCOMMON
)
11846 printf (" NOCOMMON");
11847 val
^= DF_1_NOCOMMON
;
11850 printf (" %" PRIx64
, val
);
11857 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11859 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
11880 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11886 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11887 name
= get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11893 switch (entry
->d_tag
)
11896 printf (_("Shared library: [%s]"), name
);
11898 if (filedata
->program_interpreter
11899 && streq (name
, filedata
->program_interpreter
))
11900 printf (_(" program interpreter"));
11904 printf (_("Library soname: [%s]"), name
);
11908 printf (_("Library rpath: [%s]"), name
);
11912 printf (_("Library runpath: [%s]"), name
);
11916 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11921 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11936 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11937 /* Fall through. */
11941 case DT_PREINIT_ARRAYSZ
:
11942 case DT_INIT_ARRAYSZ
:
11943 case DT_FINI_ARRAYSZ
:
11944 case DT_GNU_CONFLICTSZ
:
11945 case DT_GNU_LIBLISTSZ
:
11948 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11949 printf (_(" (bytes)\n"));
11954 case DT_VERNEEDNUM
:
11959 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11968 case DT_INIT_ARRAY
:
11969 case DT_FINI_ARRAY
:
11972 if (entry
->d_tag
== DT_USED
11973 && valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11976 = get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11980 printf (_("Not needed object: [%s]\n"), name
);
11985 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11991 /* The value of this entry is ignored. */
11996 case DT_GNU_PRELINKED
:
12000 time_t atime
= entry
->d_un
.d_val
;
12002 tmp
= gmtime (&atime
);
12003 /* PR 17533 file: 041-1244816-0.004. */
12005 printf (_("<corrupt time val: %" PRIx64
),
12008 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
12009 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
12010 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
12016 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
12019 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12024 case DT_GNU_FLAGS_1
:
12027 printf (_("Flags:"));
12028 if (entry
->d_un
.d_val
== 0)
12029 printf (_(" None\n"));
12032 uint64_t val
= entry
->d_un
.d_val
;
12034 if (val
& DF_GNU_1_UNIQUE
)
12036 printf (" UNIQUE");
12037 val
^= DF_GNU_1_UNIQUE
;
12040 printf (" %" PRIx64
, val
);
12047 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
12048 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
12049 = entry
->d_un
.d_val
;
12053 switch (filedata
->file_header
.e_machine
)
12056 dynamic_section_aarch64_val (entry
);
12059 case EM_MIPS_RS3_LE
:
12060 dynamic_section_mips_val (filedata
, entry
);
12063 dynamic_section_parisc_val (entry
);
12066 dynamic_section_ia64_val (entry
);
12069 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12081 get_ver_flags (unsigned int flags
)
12083 static char buff
[128];
12090 if (flags
& VER_FLG_BASE
)
12091 strcat (buff
, "BASE");
12093 if (flags
& VER_FLG_WEAK
)
12095 if (flags
& VER_FLG_BASE
)
12096 strcat (buff
, " | ");
12098 strcat (buff
, "WEAK");
12101 if (flags
& VER_FLG_INFO
)
12103 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
12104 strcat (buff
, " | ");
12106 strcat (buff
, "INFO");
12109 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12111 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12112 strcat (buff
, " | ");
12114 strcat (buff
, _("<unknown>"));
12120 /* Display the contents of the version sections. */
12123 process_version_sections (Filedata
* filedata
)
12125 Elf_Internal_Shdr
* section
;
12127 bool found
= false;
12132 for (i
= 0, section
= filedata
->section_headers
;
12133 i
< filedata
->file_header
.e_shnum
;
12136 switch (section
->sh_type
)
12138 case SHT_GNU_verdef
:
12140 Elf_External_Verdef
* edefs
;
12147 if (filedata
->is_separate
)
12148 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
12149 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
12151 filedata
->file_name
,
12152 printable_section_name (filedata
, section
),
12155 printf (ngettext ("\nVersion definition section '%s' "
12156 "contains %u entry:\n",
12157 "\nVersion definition section '%s' "
12158 "contains %u entries:\n",
12160 printable_section_name (filedata
, section
),
12163 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12164 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12165 section
->sh_offset
, section
->sh_link
,
12166 printable_section_name_from_index (filedata
, section
->sh_link
));
12168 edefs
= (Elf_External_Verdef
*)
12169 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
12170 _("version definition section"));
12173 endbuf
= (char *) edefs
+ section
->sh_size
;
12175 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12178 Elf_External_Verdef
* edef
;
12179 Elf_Internal_Verdef ent
;
12180 Elf_External_Verdaux
* eaux
;
12181 Elf_Internal_Verdaux aux
;
12185 vstart
= ((char *) edefs
) + idx
;
12186 if (vstart
+ sizeof (*edef
) > endbuf
)
12189 edef
= (Elf_External_Verdef
*) vstart
;
12191 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
12192 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
12193 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
12194 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
12195 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
12196 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
12197 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
12199 printf (_(" %#06zx: Rev: %d Flags: %s"),
12200 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
12202 printf (_(" Index: %d Cnt: %d "),
12203 ent
.vd_ndx
, ent
.vd_cnt
);
12205 /* Check for overflow. */
12206 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
12209 vstart
+= ent
.vd_aux
;
12211 if (vstart
+ sizeof (*eaux
) > endbuf
)
12213 eaux
= (Elf_External_Verdaux
*) vstart
;
12215 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12216 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12218 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12219 printf (_("Name: %s\n"),
12220 get_dynamic_name (filedata
, aux
.vda_name
));
12222 printf (_("Name index: %ld\n"), aux
.vda_name
);
12224 isum
= idx
+ ent
.vd_aux
;
12226 for (j
= 1; j
< ent
.vd_cnt
; j
++)
12228 if (aux
.vda_next
< sizeof (*eaux
)
12229 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
12231 warn (_("Invalid vda_next field of %lx\n"),
12236 /* Check for overflow. */
12237 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
12240 isum
+= aux
.vda_next
;
12241 vstart
+= aux
.vda_next
;
12243 if (vstart
+ sizeof (*eaux
) > endbuf
)
12245 eaux
= (Elf_External_Verdaux
*) vstart
;
12247 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12248 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12250 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12251 printf (_(" %#06zx: Parent %d: %s\n"),
12253 get_dynamic_name (filedata
, aux
.vda_name
));
12255 printf (_(" %#06zx: Parent %d, name index: %ld\n"),
12256 isum
, j
, aux
.vda_name
);
12259 if (j
< ent
.vd_cnt
)
12260 printf (_(" Version def aux past end of section\n"));
12263 file: id:000001,src:000172+005151,op:splice,rep:2. */
12264 if (ent
.vd_next
< sizeof (*edef
)
12265 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
12267 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
12268 cnt
= section
->sh_info
;
12271 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
12274 idx
+= ent
.vd_next
;
12277 if (cnt
< section
->sh_info
)
12278 printf (_(" Version definition past end of section\n"));
12284 case SHT_GNU_verneed
:
12286 Elf_External_Verneed
* eneed
;
12293 if (filedata
->is_separate
)
12294 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
12295 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
12297 filedata
->file_name
,
12298 printable_section_name (filedata
, section
),
12301 printf (ngettext ("\nVersion needs section '%s' "
12302 "contains %u entry:\n",
12303 "\nVersion needs section '%s' "
12304 "contains %u entries:\n",
12306 printable_section_name (filedata
, section
),
12309 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12310 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12311 section
->sh_offset
, section
->sh_link
,
12312 printable_section_name_from_index (filedata
, section
->sh_link
));
12314 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
12315 section
->sh_offset
, 1,
12317 _("Version Needs section"));
12320 endbuf
= (char *) eneed
+ section
->sh_size
;
12322 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12324 Elf_External_Verneed
* entry
;
12325 Elf_Internal_Verneed ent
;
12330 vstart
= ((char *) eneed
) + idx
;
12331 if (vstart
+ sizeof (*entry
) > endbuf
)
12334 entry
= (Elf_External_Verneed
*) vstart
;
12336 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
12337 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
12338 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
12339 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
12340 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
12342 printf (_(" %#06zx: Version: %d"), idx
, ent
.vn_version
);
12344 if (valid_dynamic_name (filedata
, ent
.vn_file
))
12345 printf (_(" File: %s"),
12346 get_dynamic_name (filedata
, ent
.vn_file
));
12348 printf (_(" File: %lx"), ent
.vn_file
);
12350 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
12352 /* Check for overflow. */
12353 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
12355 vstart
+= ent
.vn_aux
;
12357 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
12359 Elf_External_Vernaux
* eaux
;
12360 Elf_Internal_Vernaux aux
;
12362 if (vstart
+ sizeof (*eaux
) > endbuf
)
12364 eaux
= (Elf_External_Vernaux
*) vstart
;
12366 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
12367 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
12368 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
12369 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
12370 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
12372 if (valid_dynamic_name (filedata
, aux
.vna_name
))
12373 printf (_(" %#06zx: Name: %s"),
12374 isum
, get_dynamic_name (filedata
, aux
.vna_name
));
12376 printf (_(" %#06zx: Name index: %lx"),
12377 isum
, aux
.vna_name
);
12379 printf (_(" Flags: %s Version: %d\n"),
12380 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
12382 if (aux
.vna_next
< sizeof (*eaux
)
12383 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
12385 warn (_("Invalid vna_next field of %lx\n"),
12390 /* Check for overflow. */
12391 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
12393 isum
+= aux
.vna_next
;
12394 vstart
+= aux
.vna_next
;
12397 if (j
< ent
.vn_cnt
)
12398 warn (_("Missing Version Needs auxiliary information\n"));
12400 if (ent
.vn_next
< sizeof (*entry
)
12401 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
12403 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
12404 cnt
= section
->sh_info
;
12407 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
12409 idx
+= ent
.vn_next
;
12412 if (cnt
< section
->sh_info
)
12413 warn (_("Missing Version Needs information\n"));
12419 case SHT_GNU_versym
:
12421 Elf_Internal_Shdr
* link_section
;
12424 unsigned char * edata
;
12425 unsigned short * data
;
12427 Elf_Internal_Sym
* symbols
;
12428 Elf_Internal_Shdr
* string_sec
;
12432 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
12435 link_section
= filedata
->section_headers
+ section
->sh_link
;
12436 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
12438 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
12443 symbols
= get_elf_symbols (filedata
, link_section
, & num_syms
);
12444 if (symbols
== NULL
)
12447 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
12449 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
12450 string_sec
->sh_size
,
12451 _("version string table"));
12458 if (filedata
->is_separate
)
12459 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entry:\n",
12460 "\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entries:\n",
12462 filedata
->file_name
,
12463 printable_section_name (filedata
, section
),
12466 printf (ngettext ("\nVersion symbols section '%s' "
12467 "contains %" PRIu64
" entry:\n",
12468 "\nVersion symbols section '%s' "
12469 "contains %" PRIu64
" entries:\n",
12471 printable_section_name (filedata
, section
),
12474 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12475 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12476 section
->sh_offset
, section
->sh_link
,
12477 printable_section_name (filedata
, link_section
));
12479 off
= offset_from_vma (filedata
,
12480 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12481 total
* sizeof (short));
12482 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
12483 sizeof (short), total
,
12484 _("version symbol data"));
12492 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
12494 for (cnt
= total
; cnt
--;)
12495 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
12500 for (cnt
= 0; cnt
< total
; cnt
+= 4)
12504 char *invalid
= _("*invalid*");
12506 printf (" %03x:", cnt
);
12508 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
12509 switch (data
[cnt
+ j
])
12512 fputs (_(" 0 (*local*) "), stdout
);
12516 fputs (_(" 1 (*global*) "), stdout
);
12520 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
12521 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
12523 /* If this index value is greater than the size of the symbols
12524 array, break to avoid an out-of-bounds read. */
12525 if (cnt
+ j
>= num_syms
)
12527 warn (_("invalid index into symbol array\n"));
12532 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12534 Elf_Internal_Verneed ivn
;
12537 offset
= offset_from_vma
12539 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12540 sizeof (Elf_External_Verneed
));
12544 Elf_Internal_Vernaux ivna
;
12545 Elf_External_Verneed evn
;
12546 Elf_External_Vernaux evna
;
12549 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12550 _("version need")) == NULL
)
12553 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12554 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12556 a_off
= offset
+ ivn
.vn_aux
;
12560 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
12561 1, _("version need aux (2)")) == NULL
)
12564 ivna
.vna_other
= 0;
12568 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12569 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12572 a_off
+= ivna
.vna_next
;
12574 while (ivna
.vna_other
!= data
[cnt
+ j
]
12575 && ivna
.vna_next
!= 0);
12577 if (ivna
.vna_other
== data
[cnt
+ j
])
12579 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12581 if (ivna
.vna_name
>= string_sec
->sh_size
)
12584 name
= strtab
+ ivna
.vna_name
;
12588 offset
+= ivn
.vn_next
;
12590 while (ivn
.vn_next
);
12593 if (data
[cnt
+ j
] != 0x8001
12594 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12596 Elf_Internal_Verdef ivd
;
12597 Elf_External_Verdef evd
;
12600 offset
= offset_from_vma
12602 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
12607 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
12608 _("version def")) == NULL
)
12611 /* PR 17531: file: 046-1082287-0.004. */
12612 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
12617 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12618 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12621 offset
+= ivd
.vd_next
;
12623 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
12624 && ivd
.vd_next
!= 0);
12626 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
12628 Elf_External_Verdaux evda
;
12629 Elf_Internal_Verdaux ivda
;
12631 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12633 if (get_data (&evda
, filedata
,
12634 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
12636 _("version def aux")) == NULL
)
12639 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12641 if (ivda
.vda_name
>= string_sec
->sh_size
)
12643 else if (name
!= NULL
&& name
!= invalid
)
12644 name
= _("*both*");
12646 name
= strtab
+ ivda
.vda_name
;
12650 nn
+= printf ("(%s%-*s",
12652 12 - (int) strlen (name
),
12656 printf ("%*c", 18 - nn
, ' ');
12675 if (filedata
->is_separate
)
12676 printf (_("\nNo version information found in linked file '%s'.\n"),
12677 filedata
->file_name
);
12679 printf (_("\nNo version information found in this file.\n"));
12685 static const char *
12686 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
12688 static char buff
[64];
12692 case STB_LOCAL
: return "LOCAL";
12693 case STB_GLOBAL
: return "GLOBAL";
12694 case STB_WEAK
: return "WEAK";
12696 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
12697 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
12699 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
12701 if (binding
== STB_GNU_UNIQUE
12702 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
12704 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
12707 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
12712 static const char *
12713 get_symbol_type (Filedata
* filedata
, unsigned int type
)
12715 static char buff
[64];
12719 case STT_NOTYPE
: return "NOTYPE";
12720 case STT_OBJECT
: return "OBJECT";
12721 case STT_FUNC
: return "FUNC";
12722 case STT_SECTION
: return "SECTION";
12723 case STT_FILE
: return "FILE";
12724 case STT_COMMON
: return "COMMON";
12725 case STT_TLS
: return "TLS";
12726 case STT_RELC
: return "RELC";
12727 case STT_SRELC
: return "SRELC";
12729 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
12731 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
12732 return "THUMB_FUNC";
12734 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
12737 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
12738 return "PARISC_MILLI";
12740 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
12742 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
12744 if (filedata
->file_header
.e_machine
== EM_PARISC
)
12746 if (type
== STT_HP_OPAQUE
)
12747 return "HP_OPAQUE";
12748 if (type
== STT_HP_STUB
)
12752 if (type
== STT_GNU_IFUNC
12753 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
12754 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
12757 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
12760 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
12765 static const char *
12766 get_symbol_visibility (unsigned int visibility
)
12768 switch (visibility
)
12770 case STV_DEFAULT
: return "DEFAULT";
12771 case STV_INTERNAL
: return "INTERNAL";
12772 case STV_HIDDEN
: return "HIDDEN";
12773 case STV_PROTECTED
: return "PROTECTED";
12775 error (_("Unrecognized visibility value: %u\n"), visibility
);
12776 return _("<unknown>");
12780 static const char *
12781 get_alpha_symbol_other (unsigned int other
)
12785 case STO_ALPHA_NOPV
: return "NOPV";
12786 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
12788 error (_("Unrecognized alpha specific other value: %u\n"), other
);
12789 return _("<unknown>");
12793 static const char *
12794 get_solaris_symbol_visibility (unsigned int visibility
)
12796 switch (visibility
)
12798 case 4: return "EXPORTED";
12799 case 5: return "SINGLETON";
12800 case 6: return "ELIMINATE";
12801 default: return get_symbol_visibility (visibility
);
12805 static const char *
12806 get_aarch64_symbol_other (unsigned int other
)
12808 static char buf
[32];
12810 if (other
& STO_AARCH64_VARIANT_PCS
)
12812 other
&= ~STO_AARCH64_VARIANT_PCS
;
12814 return "VARIANT_PCS";
12815 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
12821 static const char *
12822 get_mips_symbol_other (unsigned int other
)
12826 case STO_OPTIONAL
: return "OPTIONAL";
12827 case STO_MIPS_PLT
: return "MIPS PLT";
12828 case STO_MIPS_PIC
: return "MIPS PIC";
12829 case STO_MICROMIPS
: return "MICROMIPS";
12830 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
12831 case STO_MIPS16
: return "MIPS16";
12832 default: return NULL
;
12836 static const char *
12837 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
12839 if (is_ia64_vms (filedata
))
12841 static char res
[32];
12845 /* Function types is for images and .STB files only. */
12846 switch (filedata
->file_header
.e_type
)
12850 switch (VMS_ST_FUNC_TYPE (other
))
12852 case VMS_SFT_CODE_ADDR
:
12853 strcat (res
, " CA");
12855 case VMS_SFT_SYMV_IDX
:
12856 strcat (res
, " VEC");
12859 strcat (res
, " FD");
12861 case VMS_SFT_RESERVE
:
12862 strcat (res
, " RSV");
12865 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
12866 VMS_ST_FUNC_TYPE (other
));
12867 strcat (res
, " <unknown>");
12874 switch (VMS_ST_LINKAGE (other
))
12876 case VMS_STL_IGNORE
:
12877 strcat (res
, " IGN");
12879 case VMS_STL_RESERVE
:
12880 strcat (res
, " RSV");
12883 strcat (res
, " STD");
12886 strcat (res
, " LNK");
12889 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
12890 VMS_ST_LINKAGE (other
));
12891 strcat (res
, " <unknown>");
12903 static const char *
12904 get_ppc64_symbol_other (unsigned int other
)
12906 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
12909 other
>>= STO_PPC64_LOCAL_BIT
;
12912 static char buf
[64];
12914 other
= ppc64_decode_local_entry (other
);
12915 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
12921 static const char *
12922 get_riscv_symbol_other (unsigned int other
)
12924 static char buf
[32];
12927 if (other
& STO_RISCV_VARIANT_CC
)
12929 strcat (buf
, _(" VARIANT_CC"));
12930 other
&= ~STO_RISCV_VARIANT_CC
;
12934 snprintf (buf
, sizeof buf
, " %x", other
);
12943 static const char *
12944 get_symbol_other (Filedata
* filedata
, unsigned int other
)
12946 const char * result
= NULL
;
12947 static char buff
[64];
12952 switch (filedata
->file_header
.e_machine
)
12955 result
= get_alpha_symbol_other (other
);
12958 result
= get_aarch64_symbol_other (other
);
12961 result
= get_mips_symbol_other (other
);
12964 result
= get_ia64_symbol_other (filedata
, other
);
12967 result
= get_ppc64_symbol_other (other
);
12970 result
= get_riscv_symbol_other (other
);
12980 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
12984 static const char *
12985 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
12987 static char buff
[32];
12991 case SHN_UNDEF
: return "UND";
12992 case SHN_ABS
: return "ABS";
12993 case SHN_COMMON
: return "COM";
12995 if (type
== SHN_IA_64_ANSI_COMMON
12996 && filedata
->file_header
.e_machine
== EM_IA_64
12997 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
12999 else if ((filedata
->file_header
.e_machine
== EM_X86_64
13000 || filedata
->file_header
.e_machine
== EM_L1OM
13001 || filedata
->file_header
.e_machine
== EM_K1OM
)
13002 && type
== SHN_X86_64_LCOMMON
)
13003 return "LARGE_COM";
13004 else if ((type
== SHN_MIPS_SCOMMON
13005 && filedata
->file_header
.e_machine
== EM_MIPS
)
13006 || (type
== SHN_TIC6X_SCOMMON
13007 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
13009 else if (type
== SHN_MIPS_SUNDEFINED
13010 && filedata
->file_header
.e_machine
== EM_MIPS
)
13012 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
13013 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
13014 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
13015 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
13016 else if (type
>= SHN_LORESERVE
)
13017 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
13018 else if (filedata
->file_header
.e_shnum
!= 0
13019 && type
>= filedata
->file_header
.e_shnum
)
13020 sprintf (buff
, _("bad section index[%3d]"), type
);
13022 sprintf (buff
, "%3d", type
);
13029 static const char *
13030 get_symbol_version_string (Filedata
*filedata
,
13032 const char *strtab
,
13033 size_t strtab_size
,
13035 Elf_Internal_Sym
*psym
,
13036 enum versioned_symbol_info
*sym_info
,
13037 unsigned short *vna_other
)
13039 unsigned char data
[2];
13040 unsigned short vers_data
;
13042 unsigned short max_vd_ndx
;
13045 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
13048 offset
= offset_from_vma (filedata
,
13049 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
13050 sizeof data
+ si
* sizeof (vers_data
));
13052 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
13053 sizeof (data
), 1, _("version data")) == NULL
)
13056 vers_data
= byte_get (data
, 2);
13058 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
13061 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
13064 /* Usually we'd only see verdef for defined symbols, and verneed for
13065 undefined symbols. However, symbols defined by the linker in
13066 .dynbss for variables copied from a shared library in order to
13067 avoid text relocations are defined yet have verneed. We could
13068 use a heuristic to detect the special case, for example, check
13069 for verneed first on symbols defined in SHT_NOBITS sections, but
13070 it is simpler and more reliable to just look for both verdef and
13071 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
13073 if (psym
->st_shndx
!= SHN_UNDEF
13074 && vers_data
!= 0x8001
13075 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
13077 Elf_Internal_Verdef ivd
;
13078 Elf_Internal_Verdaux ivda
;
13079 Elf_External_Verdaux evda
;
13082 off
= offset_from_vma (filedata
,
13083 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
13084 sizeof (Elf_External_Verdef
));
13088 Elf_External_Verdef evd
;
13090 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
13091 _("version def")) == NULL
)
13100 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
13101 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
13102 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
13103 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
13106 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
13107 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
13109 off
+= ivd
.vd_next
;
13111 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
13113 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
13115 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
13118 off
-= ivd
.vd_next
;
13121 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
13122 _("version def aux")) != NULL
)
13124 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
13126 if (psym
->st_name
!= ivda
.vda_name
)
13127 return (ivda
.vda_name
< strtab_size
13128 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
13133 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
13135 Elf_External_Verneed evn
;
13136 Elf_Internal_Verneed ivn
;
13137 Elf_Internal_Vernaux ivna
;
13139 offset
= offset_from_vma (filedata
,
13140 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
13146 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
13147 _("version need")) == NULL
)
13150 ivna
.vna_other
= 0;
13155 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
13156 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
13158 vna_off
= offset
+ ivn
.vn_aux
;
13162 Elf_External_Vernaux evna
;
13164 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
13165 _("version need aux (3)")) == NULL
)
13168 ivna
.vna_other
= 0;
13173 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
13174 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
13175 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
13178 vna_off
+= ivna
.vna_next
;
13180 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
13182 if (ivna
.vna_other
== vers_data
)
13185 offset
+= ivn
.vn_next
;
13187 while (ivn
.vn_next
!= 0);
13189 if (ivna
.vna_other
== vers_data
)
13191 *sym_info
= symbol_undefined
;
13192 *vna_other
= ivna
.vna_other
;
13193 return (ivna
.vna_name
< strtab_size
13194 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
13196 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
13197 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
13198 return _("<corrupt>");
13203 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
13205 static unsigned int
13206 print_dynamic_symbol_size (uint64_t vma
, int base
)
13211 return print_vma (vma
, OCTAL_5
);
13214 return print_vma (vma
, UNSIGNED_5
);
13217 return print_vma (vma
, PREFIX_HEX_5
);
13221 return print_vma (vma
, DEC_5
);
13226 print_dynamic_symbol (Filedata
*filedata
, uint64_t si
,
13227 Elf_Internal_Sym
*symtab
,
13228 Elf_Internal_Shdr
*section
,
13229 char *strtab
, size_t strtab_size
)
13231 const char *version_string
;
13232 enum versioned_symbol_info sym_info
;
13233 unsigned short vna_other
;
13236 Elf_Internal_Sym
*psym
= symtab
+ si
;
13238 printf ("%6" PRId64
": ", si
);
13239 print_vma (psym
->st_value
, LONG_HEX
);
13241 print_dynamic_symbol_size (psym
->st_size
, sym_base
);
13242 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
13243 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
13244 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
13245 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
13248 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
13250 printf (" %-7s", get_symbol_visibility (vis
));
13251 /* Check to see if any other bits in the st_other field are set.
13252 Note - displaying this information disrupts the layout of the
13253 table being generated, but for the moment this case is very rare. */
13254 if (psym
->st_other
^ vis
)
13255 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
13257 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
13259 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
13260 && psym
->st_shndx
< filedata
->file_header
.e_shnum
13261 && filedata
->section_headers
!= NULL
13262 && psym
->st_name
== 0)
13265 = section_name_valid (filedata
,
13266 filedata
->section_headers
+ psym
->st_shndx
);
13268 section_name_print (filedata
,
13269 filedata
->section_headers
+ psym
->st_shndx
)
13274 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
13275 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
13279 = get_symbol_version_string (filedata
,
13281 || section
->sh_type
== SHT_DYNSYM
),
13282 strtab
, strtab_size
, si
,
13283 psym
, &sym_info
, &vna_other
);
13285 int len_avail
= 21;
13286 if (! do_wide
&& version_string
!= NULL
)
13290 len_avail
-= 1 + strlen (version_string
);
13292 if (sym_info
== symbol_undefined
)
13293 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
13294 else if (sym_info
!= symbol_hidden
)
13298 print_symbol (len_avail
, sstr
);
13300 if (version_string
)
13302 if (sym_info
== symbol_undefined
)
13303 printf ("@%s (%d)", version_string
, vna_other
);
13305 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
13311 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
13313 && si
>= section
->sh_info
13314 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
13315 && filedata
->file_header
.e_machine
!= EM_MIPS
13316 /* Solaris binaries have been found to violate this requirement as
13317 well. Not sure if this is a bug or an ABI requirement. */
13318 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
13319 warn (_("local symbol %" PRIu64
" found at index >= %s's sh_info value of %u\n"),
13320 si
, printable_section_name (filedata
, section
), section
->sh_info
);
13323 static const char *
13324 get_lto_kind (unsigned int kind
)
13328 case 0: return "DEF";
13329 case 1: return "WEAKDEF";
13330 case 2: return "UNDEF";
13331 case 3: return "WEAKUNDEF";
13332 case 4: return "COMMON";
13337 static char buffer
[30];
13338 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
13339 sprintf (buffer
, "<unknown: %u>", kind
);
13343 static const char *
13344 get_lto_visibility (unsigned int visibility
)
13346 switch (visibility
)
13348 case 0: return "DEFAULT";
13349 case 1: return "PROTECTED";
13350 case 2: return "INTERNAL";
13351 case 3: return "HIDDEN";
13356 static char buffer
[30];
13357 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
13358 sprintf (buffer
, "<unknown: %u>", visibility
);
13362 static const char *
13363 get_lto_sym_type (unsigned int sym_type
)
13367 case 0: return "UNKNOWN";
13368 case 1: return "FUNCTION";
13369 case 2: return "VARIABLE";
13374 static char buffer
[30];
13375 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
13376 sprintf (buffer
, "<unknown: %u>", sym_type
);
13380 /* Display an LTO format symbol table.
13381 FIXME: The format of LTO symbol tables is not formalized.
13382 So this code could need changing in the future. */
13385 display_lto_symtab (Filedata
* filedata
,
13386 Elf_Internal_Shdr
* section
)
13388 if (section
->sh_size
== 0)
13390 if (filedata
->is_separate
)
13391 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
13392 printable_section_name (filedata
, section
),
13393 filedata
->file_name
);
13395 printf (_("\nLTO Symbol table '%s' is empty!\n"),
13396 printable_section_name (filedata
, section
));
13401 if (section
->sh_size
> filedata
->file_size
)
13403 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
13404 printable_section_name (filedata
, section
),
13409 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
13410 section
->sh_size
, 1, _("LTO symbols"));
13411 if (alloced_data
== NULL
)
13414 /* Look for extended data for the symbol table. */
13415 Elf_Internal_Shdr
* ext
;
13416 void * ext_data_orig
= NULL
;
13417 char * ext_data
= NULL
;
13418 char * ext_data_end
= NULL
;
13419 char * ext_name
= NULL
;
13421 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
13422 (section_name (filedata
, section
)
13423 + sizeof (".gnu.lto_.symtab.") - 1)) > 0
13424 && ext_name
!= NULL
/* Paranoia. */
13425 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
13427 if (ext
->sh_size
< 3)
13428 error (_("LTO Symbol extension table '%s' is empty!\n"),
13429 printable_section_name (filedata
, ext
));
13432 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
13434 _("LTO ext symbol data"));
13435 if (ext_data
!= NULL
)
13437 ext_data_end
= ext_data
+ ext
->sh_size
;
13438 if (* ext_data
++ != 1)
13439 error (_("Unexpected version number in symbol extension table\n"));
13444 const unsigned char * data
= (const unsigned char *) alloced_data
;
13445 const unsigned char * end
= data
+ section
->sh_size
;
13447 if (filedata
->is_separate
)
13448 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
13452 if (ext_data_orig
!= NULL
)
13455 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
13456 printable_section_name (filedata
, section
),
13457 printable_section_name (filedata
, ext
));
13460 printf (_("LTO Symbol table '%s'\n"),
13461 printable_section_name (filedata
, section
));
13462 printf (_(" and extension table '%s' contain:\n"),
13463 printable_section_name (filedata
, ext
));
13467 printf (_("LTO Symbol table '%s' contains:\n"),
13468 printable_section_name (filedata
, section
));
13470 /* FIXME: Add a wide version. */
13471 if (ext_data_orig
!= NULL
)
13472 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
13474 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
13476 /* FIXME: We do not handle style prefixes. */
13480 const unsigned char * sym_name
= data
;
13481 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
13485 const unsigned char * comdat_key
= data
;
13486 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
13490 if (data
+ 2 + 8 + 4 > end
)
13493 unsigned int kind
= *data
++;
13494 unsigned int visibility
= *data
++;
13496 uint64_t size
= byte_get (data
, 8);
13499 uint64_t slot
= byte_get (data
, 4);
13502 if (ext_data
!= NULL
)
13504 if (ext_data
< (ext_data_end
- 1))
13506 unsigned int sym_type
= * ext_data
++;
13507 unsigned int sec_kind
= * ext_data
++;
13509 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" %9s %08x _",
13510 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13511 get_lto_kind (kind
),
13512 get_lto_visibility (visibility
),
13515 get_lto_sym_type (sym_type
),
13517 print_symbol (6, (const char *) sym_name
);
13521 error (_("Ran out of LTO symbol extension data\n"));
13523 /* FIXME: return FAIL result ? */
13528 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" _",
13529 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13530 get_lto_kind (kind
),
13531 get_lto_visibility (visibility
),
13534 print_symbol (21, (const char *) sym_name
);
13539 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
13541 error (_("Data remains in the LTO symbol extension table\n"));
13545 free (alloced_data
);
13546 free (ext_data_orig
);
13551 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
13552 free (alloced_data
);
13553 free (ext_data_orig
);
13558 /* Display LTO symbol tables. */
13561 process_lto_symbol_tables (Filedata
* filedata
)
13563 Elf_Internal_Shdr
* section
;
13570 if (filedata
->section_headers
== NULL
)
13573 for (i
= 0, section
= filedata
->section_headers
;
13574 i
< filedata
->file_header
.e_shnum
;
13576 if (section_name_valid (filedata
, section
)
13577 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
13578 res
&= display_lto_symtab (filedata
, section
);
13583 /* Dump the symbol table. */
13586 process_symbol_table (Filedata
* filedata
)
13588 Elf_Internal_Shdr
* section
;
13590 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
13593 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
13595 && do_using_dynamic
13596 && filedata
->dynamic_strings
!= NULL
13597 && filedata
->dynamic_symbols
!= NULL
)
13601 if (filedata
->is_separate
)
13603 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table"
13604 " contains %" PRIu64
" entry:\n",
13605 "\nIn linked file '%s' the dynamic symbol table"
13606 " contains %" PRIu64
" entries:\n",
13607 filedata
->num_dynamic_syms
),
13608 filedata
->file_name
,
13609 filedata
->num_dynamic_syms
);
13613 printf (ngettext ("\nSymbol table for image contains %" PRIu64
13615 "\nSymbol table for image contains %" PRIu64
13617 filedata
->num_dynamic_syms
),
13618 filedata
->num_dynamic_syms
);
13621 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13623 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13625 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
13626 print_dynamic_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
13627 filedata
->dynamic_strings
,
13628 filedata
->dynamic_strings_length
);
13630 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
13631 && filedata
->section_headers
!= NULL
)
13635 for (i
= 0, section
= filedata
->section_headers
;
13636 i
< filedata
->file_header
.e_shnum
;
13639 char * strtab
= NULL
;
13640 uint64_t strtab_size
= 0;
13641 Elf_Internal_Sym
* symtab
;
13642 uint64_t si
, num_syms
;
13644 if ((section
->sh_type
!= SHT_SYMTAB
13645 && section
->sh_type
!= SHT_DYNSYM
)
13647 && section
->sh_type
== SHT_SYMTAB
))
13650 if (section
->sh_entsize
== 0)
13652 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
13653 printable_section_name (filedata
, section
));
13657 num_syms
= section
->sh_size
/ section
->sh_entsize
;
13659 if (filedata
->is_separate
)
13660 printf (ngettext ("\nIn linked file '%s' symbol section '%s'"
13661 " contains %" PRIu64
" entry:\n",
13662 "\nIn linked file '%s' symbol section '%s'"
13663 " contains %" PRIu64
" entries:\n",
13665 filedata
->file_name
,
13666 printable_section_name (filedata
, section
),
13669 printf (ngettext ("\nSymbol table '%s' contains %" PRIu64
13671 "\nSymbol table '%s' contains %" PRIu64
13674 printable_section_name (filedata
, section
),
13678 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13680 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13682 symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
13683 if (symtab
== NULL
)
13686 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
13688 strtab
= filedata
->string_table
;
13689 strtab_size
= filedata
->string_table_length
;
13691 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
13693 Elf_Internal_Shdr
* string_sec
;
13695 string_sec
= filedata
->section_headers
+ section
->sh_link
;
13697 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
13698 1, string_sec
->sh_size
,
13699 _("string table"));
13700 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
13703 for (si
= 0; si
< num_syms
; si
++)
13704 print_dynamic_symbol (filedata
, si
, symtab
, section
,
13705 strtab
, strtab_size
);
13708 if (strtab
!= filedata
->string_table
)
13714 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
13716 if (do_histogram
&& filedata
->buckets
!= NULL
)
13722 uint64_t maxlength
= 0;
13723 uint64_t nzero_counts
= 0;
13724 uint64_t nsyms
= 0;
13727 printf (ngettext ("\nHistogram for bucket list length "
13728 "(total of %" PRIu64
" bucket):\n",
13729 "\nHistogram for bucket list length "
13730 "(total of %" PRIu64
" buckets):\n",
13731 filedata
->nbuckets
),
13732 filedata
->nbuckets
);
13734 lengths
= calloc (filedata
->nbuckets
, sizeof (*lengths
));
13735 if (lengths
== NULL
)
13737 error (_("Out of memory allocating space for histogram buckets\n"));
13740 visited
= xcmalloc (filedata
->nchains
, 1);
13741 memset (visited
, 0, filedata
->nchains
);
13743 printf (_(" Length Number %% of total Coverage\n"));
13744 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13746 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
13749 if (maxlength
< ++lengths
[hn
])
13751 if (si
>= filedata
->nchains
|| visited
[si
])
13753 error (_("histogram chain is corrupt\n"));
13761 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
13762 if (counts
== NULL
)
13765 error (_("Out of memory allocating space for histogram counts\n"));
13769 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13770 ++counts
[lengths
[hn
]];
13772 if (filedata
->nbuckets
> 0)
13775 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
13776 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
13777 for (i
= 1; i
<= maxlength
; ++i
)
13779 nzero_counts
+= counts
[i
] * i
;
13780 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
13781 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
13782 (nzero_counts
* 100.0) / nsyms
);
13790 free (filedata
->buckets
);
13791 filedata
->buckets
= NULL
;
13792 filedata
->nbuckets
= 0;
13793 free (filedata
->chains
);
13794 filedata
->chains
= NULL
;
13796 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
13801 uint64_t maxlength
= 0;
13802 uint64_t nzero_counts
= 0;
13803 uint64_t nsyms
= 0;
13805 printf (ngettext ("\nHistogram for `%s' bucket list length "
13806 "(total of %" PRIu64
" bucket):\n",
13807 "\nHistogram for `%s' bucket list length "
13808 "(total of %" PRIu64
" buckets):\n",
13809 filedata
->ngnubuckets
),
13810 GNU_HASH_SECTION_NAME (filedata
),
13811 filedata
->ngnubuckets
);
13813 lengths
= calloc (filedata
->ngnubuckets
, sizeof (*lengths
));
13814 if (lengths
== NULL
)
13816 error (_("Out of memory allocating space for gnu histogram buckets\n"));
13820 printf (_(" Length Number %% of total Coverage\n"));
13822 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13823 if (filedata
->gnubuckets
[hn
] != 0)
13825 uint64_t off
, length
= 1;
13827 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
13828 /* PR 17531 file: 010-77222-0.004. */
13829 off
< filedata
->ngnuchains
13830 && (filedata
->gnuchains
[off
] & 1) == 0;
13833 lengths
[hn
] = length
;
13834 if (length
> maxlength
)
13835 maxlength
= length
;
13839 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
13840 if (counts
== NULL
)
13843 error (_("Out of memory allocating space for gnu histogram counts\n"));
13847 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13848 ++counts
[lengths
[hn
]];
13850 if (filedata
->ngnubuckets
> 0)
13853 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
13854 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
13855 for (j
= 1; j
<= maxlength
; ++j
)
13857 nzero_counts
+= counts
[j
] * j
;
13858 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
13859 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
13860 (nzero_counts
* 100.0) / nsyms
);
13867 free (filedata
->gnubuckets
);
13868 filedata
->gnubuckets
= NULL
;
13869 filedata
->ngnubuckets
= 0;
13870 free (filedata
->gnuchains
);
13871 filedata
->gnuchains
= NULL
;
13872 filedata
->ngnuchains
= 0;
13873 free (filedata
->mipsxlat
);
13874 filedata
->mipsxlat
= NULL
;
13878 free (filedata
->gnubuckets
);
13879 filedata
->gnubuckets
= NULL
;
13880 filedata
->ngnubuckets
= 0;
13881 free (filedata
->gnuchains
);
13882 filedata
->gnuchains
= NULL
;
13883 filedata
->ngnuchains
= 0;
13884 free (filedata
->mipsxlat
);
13885 filedata
->mipsxlat
= NULL
;
13886 free (filedata
->buckets
);
13887 filedata
->buckets
= NULL
;
13888 filedata
->nbuckets
= 0;
13889 free (filedata
->chains
);
13890 filedata
->chains
= NULL
;
13895 process_syminfo (Filedata
* filedata
)
13899 if (filedata
->dynamic_syminfo
== NULL
13901 /* No syminfo, this is ok. */
13904 /* There better should be a dynamic symbol section. */
13905 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
13908 if (filedata
->is_separate
)
13909 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entry:\n",
13910 "\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entries:\n",
13911 filedata
->dynamic_syminfo_nent
),
13912 filedata
->file_name
,
13913 filedata
->dynamic_syminfo_offset
,
13914 filedata
->dynamic_syminfo_nent
);
13916 printf (ngettext ("\nDynamic info segment at offset %#" PRIx64
13917 " contains %d entry:\n",
13918 "\nDynamic info segment at offset %#" PRIx64
13919 " contains %d entries:\n",
13920 filedata
->dynamic_syminfo_nent
),
13921 filedata
->dynamic_syminfo_offset
,
13922 filedata
->dynamic_syminfo_nent
);
13924 printf (_(" Num: Name BoundTo Flags\n"));
13925 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
13927 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
13929 printf ("%4d: ", i
);
13930 if (i
>= filedata
->num_dynamic_syms
)
13931 printf (_("<corrupt index>"));
13932 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
13933 print_symbol (30, get_dynamic_name (filedata
,
13934 filedata
->dynamic_symbols
[i
].st_name
));
13936 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
13939 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
13941 case SYMINFO_BT_SELF
:
13942 fputs ("SELF ", stdout
);
13944 case SYMINFO_BT_PARENT
:
13945 fputs ("PARENT ", stdout
);
13948 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
13949 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
13950 && valid_dynamic_name (filedata
,
13951 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
13953 print_symbol (10, get_dynamic_name (filedata
,
13954 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
13958 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
13962 if (flags
& SYMINFO_FLG_DIRECT
)
13963 printf (" DIRECT");
13964 if (flags
& SYMINFO_FLG_PASSTHRU
)
13965 printf (" PASSTHRU");
13966 if (flags
& SYMINFO_FLG_COPY
)
13968 if (flags
& SYMINFO_FLG_LAZYLOAD
)
13969 printf (" LAZYLOAD");
13977 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
13978 is contained by the region START .. END. The types of ADDR, START
13979 and END should all be the same. Note both ADDR + NELEM and END
13980 point to just beyond the end of the regions that are being tested. */
13981 #define IN_RANGE(START,END,ADDR,NELEM) \
13982 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
13984 /* Check to see if the given reloc needs to be handled in a target specific
13985 manner. If so then process the reloc and return TRUE otherwise return
13988 If called with reloc == NULL, then this is a signal that reloc processing
13989 for the current section has finished, and any saved state should be
13993 target_specific_reloc_handling (Filedata
*filedata
,
13994 Elf_Internal_Rela
*reloc
,
13995 unsigned char *start
,
13996 unsigned char *end
,
13997 Elf_Internal_Sym
*symtab
,
14000 unsigned int reloc_type
= 0;
14001 uint64_t sym_index
= 0;
14005 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
14006 sym_index
= get_reloc_symindex (reloc
->r_info
);
14009 switch (filedata
->file_header
.e_machine
)
14012 case EM_MSP430_OLD
:
14014 static Elf_Internal_Sym
* saved_sym
= NULL
;
14022 switch (reloc_type
)
14024 case 10: /* R_MSP430_SYM_DIFF */
14025 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
14026 if (uses_msp430x_relocs (filedata
))
14028 /* Fall through. */
14029 case 21: /* R_MSP430X_SYM_DIFF */
14030 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
14032 if (sym_index
>= num_syms
)
14033 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index"
14034 " %" PRIu64
"\n"), sym_index
);
14036 saved_sym
= symtab
+ sym_index
;
14039 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
14040 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
14041 goto handle_sym_diff
;
14043 case 5: /* R_MSP430_16_BYTE */
14044 case 9: /* R_MSP430_8 */
14045 case 11: /* R_MSP430_GNU_SET_ULEB128 */
14046 if (uses_msp430x_relocs (filedata
))
14048 goto handle_sym_diff
;
14050 case 2: /* R_MSP430_ABS16 */
14051 case 15: /* R_MSP430X_ABS16 */
14052 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
14053 if (! uses_msp430x_relocs (filedata
))
14055 goto handle_sym_diff
;
14058 if (saved_sym
!= NULL
)
14061 unsigned int reloc_size
= 0;
14063 switch (reloc_type
)
14065 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
14068 case 11: /* R_MSP430_GNU_SET_ULEB128 */
14069 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
14070 if (reloc
->r_offset
< (size_t) (end
- start
))
14071 read_leb128 (start
+ reloc
->r_offset
, end
, false,
14072 &reloc_size
, &leb_ret
);
14079 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
14080 error (_("MSP430 ULEB128 field at %#" PRIx64
14081 " contains invalid ULEB128 value\n"),
14083 else if (sym_index
>= num_syms
)
14084 error (_("MSP430 reloc contains invalid symbol index "
14089 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14090 - saved_sym
->st_value
);
14092 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14093 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14096 error (_("MSP430 sym diff reloc contains invalid offset: "
14107 if (saved_sym
!= NULL
)
14108 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
14115 case EM_CYGNUS_MN10300
:
14117 static Elf_Internal_Sym
* saved_sym
= NULL
;
14125 switch (reloc_type
)
14127 case 34: /* R_MN10300_ALIGN */
14129 case 33: /* R_MN10300_SYM_DIFF */
14130 if (sym_index
>= num_syms
)
14131 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index "
14135 saved_sym
= symtab
+ sym_index
;
14138 case 1: /* R_MN10300_32 */
14139 case 2: /* R_MN10300_16 */
14140 if (saved_sym
!= NULL
)
14142 int reloc_size
= reloc_type
== 1 ? 4 : 2;
14145 if (sym_index
>= num_syms
)
14146 error (_("MN10300 reloc contains invalid symbol index "
14151 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14152 - saved_sym
->st_value
);
14154 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14155 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14157 error (_("MN10300 sym diff reloc contains invalid offset:"
14158 " %#" PRIx64
"\n"),
14167 if (saved_sym
!= NULL
)
14168 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
14176 static uint64_t saved_sym1
= 0;
14177 static uint64_t saved_sym2
= 0;
14178 static uint64_t value
;
14182 saved_sym1
= saved_sym2
= 0;
14186 switch (reloc_type
)
14188 case 0x80: /* R_RL78_SYM. */
14189 saved_sym1
= saved_sym2
;
14190 if (sym_index
>= num_syms
)
14191 error (_("RL78_SYM reloc contains invalid symbol index "
14192 "%" PRIu64
"\n"), sym_index
);
14195 saved_sym2
= symtab
[sym_index
].st_value
;
14196 saved_sym2
+= reloc
->r_addend
;
14200 case 0x83: /* R_RL78_OPsub. */
14201 value
= saved_sym1
- saved_sym2
;
14202 saved_sym2
= saved_sym1
= 0;
14206 case 0x41: /* R_RL78_ABS32. */
14207 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
14208 byte_put (start
+ reloc
->r_offset
, value
, 4);
14210 error (_("RL78 sym diff reloc contains invalid offset: "
14216 case 0x43: /* R_RL78_ABS16. */
14217 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
14218 byte_put (start
+ reloc
->r_offset
, value
, 2);
14220 error (_("RL78 sym diff reloc contains invalid offset: "
14236 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
14237 DWARF debug sections. This is a target specific test. Note - we do not
14238 go through the whole including-target-headers-multiple-times route, (as
14239 we have already done with <elf/h8.h>) because this would become very
14240 messy and even then this function would have to contain target specific
14241 information (the names of the relocs instead of their numeric values).
14242 FIXME: This is not the correct way to solve this problem. The proper way
14243 is to have target specific reloc sizing and typing functions created by
14244 the reloc-macros.h header, in the same way that it already creates the
14245 reloc naming functions. */
14248 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14250 /* Please keep this table alpha-sorted for ease of visual lookup. */
14251 switch (filedata
->file_header
.e_machine
)
14255 return reloc_type
== 1; /* R_386_32. */
14257 return reloc_type
== 1; /* R_68K_32. */
14259 return reloc_type
== 1; /* R_860_32. */
14261 return reloc_type
== 2; /* R_960_32. */
14263 return (reloc_type
== 258
14264 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
14266 return reloc_type
== 11; /* R_BPF_DATA_32 */
14267 case EM_ADAPTEVA_EPIPHANY
:
14268 return reloc_type
== 3;
14270 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
14272 return reloc_type
== 1; /* R_ARC_32. */
14273 case EM_ARC_COMPACT
:
14274 case EM_ARC_COMPACT2
:
14275 return reloc_type
== 4; /* R_ARC_32. */
14277 return reloc_type
== 2; /* R_ARM_ABS32 */
14280 return reloc_type
== 1;
14282 return reloc_type
== 0x12; /* R_byte4_data. */
14284 return reloc_type
== 3; /* R_CRIS_32. */
14286 return reloc_type
== 3; /* R_CR16_NUM32. */
14288 return reloc_type
== 15; /* R_CRX_NUM32. */
14290 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
14291 case EM_CYGNUS_FRV
:
14292 return reloc_type
== 1;
14293 case EM_CYGNUS_D10V
:
14295 return reloc_type
== 6; /* R_D10V_32. */
14296 case EM_CYGNUS_D30V
:
14298 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
14300 return reloc_type
== 3; /* R_DLX_RELOC_32. */
14301 case EM_CYGNUS_FR30
:
14303 return reloc_type
== 3; /* R_FR30_32. */
14305 return reloc_type
== 1; /* R_FT32_32. */
14309 return reloc_type
== 1; /* R_H8_DIR32. */
14311 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
14312 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
14313 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
14314 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
14317 return reloc_type
== 2; /* R_IP2K_32. */
14319 return reloc_type
== 2; /* R_IQ2000_32. */
14320 case EM_LATTICEMICO32
:
14321 return reloc_type
== 3; /* R_LM32_32. */
14323 return reloc_type
== 1; /* R_LARCH_32. */
14326 return reloc_type
== 3; /* R_M32C_32. */
14328 return reloc_type
== 34; /* R_M32R_32_RELA. */
14331 return reloc_type
== 6; /* R_M68HC11_32. */
14333 return reloc_type
== 7 || /* R_S12Z_EXT32 */
14334 reloc_type
== 6; /* R_S12Z_CW32. */
14336 return reloc_type
== 1; /* R_MCORE_ADDR32. */
14337 case EM_CYGNUS_MEP
:
14338 return reloc_type
== 4; /* R_MEP_32. */
14340 return reloc_type
== 2; /* R_METAG_ADDR32. */
14341 case EM_MICROBLAZE
:
14342 return reloc_type
== 1; /* R_MICROBLAZE_32. */
14344 return reloc_type
== 2; /* R_MIPS_32. */
14346 return reloc_type
== 4; /* R_MMIX_32. */
14347 case EM_CYGNUS_MN10200
:
14349 return reloc_type
== 1; /* R_MN10200_32. */
14350 case EM_CYGNUS_MN10300
:
14352 return reloc_type
== 1; /* R_MN10300_32. */
14354 return reloc_type
== 1; /* R_MOXIE_32. */
14355 case EM_MSP430_OLD
:
14357 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
14359 return reloc_type
== 2; /* R_MT_32. */
14361 return reloc_type
== 20; /* R_NDS32_32_RELA. */
14362 case EM_ALTERA_NIOS2
:
14363 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
14365 return reloc_type
== 1; /* R_NIOS_32. */
14367 return reloc_type
== 1; /* R_OR1K_32. */
14369 return (reloc_type
== 1 /* R_PARISC_DIR32. */
14370 || reloc_type
== 2 /* R_PARISC_DIR21L. */
14371 || reloc_type
== 41); /* R_PARISC_SECREL32. */
14374 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
14376 return reloc_type
== 1; /* R_PPC64_ADDR32. */
14378 return reloc_type
== 1; /* R_PPC_ADDR32. */
14380 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
14382 return reloc_type
== 1; /* R_RISCV_32. */
14384 return reloc_type
== 1; /* R_RL78_DIR32. */
14386 return reloc_type
== 1; /* R_RX_DIR32. */
14388 return reloc_type
== 1; /* R_I370_ADDR31. */
14391 return reloc_type
== 4; /* R_S390_32. */
14393 return reloc_type
== 8; /* R_SCORE_ABS32. */
14395 return reloc_type
== 1; /* R_SH_DIR32. */
14396 case EM_SPARC32PLUS
:
14399 return reloc_type
== 3 /* R_SPARC_32. */
14400 || reloc_type
== 23; /* R_SPARC_UA32. */
14402 return reloc_type
== 6; /* R_SPU_ADDR32 */
14404 return reloc_type
== 1; /* R_C6000_ABS32. */
14406 return reloc_type
== 2; /* R_TILEGX_32. */
14408 return reloc_type
== 1; /* R_TILEPRO_32. */
14409 case EM_CYGNUS_V850
:
14411 return reloc_type
== 6; /* R_V850_ABS32. */
14413 return reloc_type
== 0x33; /* R_V810_WORD. */
14415 return reloc_type
== 1; /* R_VAX_32. */
14417 return reloc_type
== 3; /* R_VISIUM_32. */
14418 case EM_WEBASSEMBLY
:
14419 return reloc_type
== 1; /* R_WASM32_32. */
14423 return reloc_type
== 10; /* R_X86_64_32. */
14425 return reloc_type
== 4; /* R_XGATE_32. */
14427 return reloc_type
== 1; /* R_XSTROMY16_32. */
14428 case EM_XTENSA_OLD
:
14430 return reloc_type
== 1; /* R_XTENSA_32. */
14432 return reloc_type
== 6; /* R_Z80_32. */
14435 static unsigned int prev_warn
= 0;
14437 /* Avoid repeating the same warning multiple times. */
14438 if (prev_warn
!= filedata
->file_header
.e_machine
)
14439 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
14440 filedata
->file_header
.e_machine
);
14441 prev_warn
= filedata
->file_header
.e_machine
;
14447 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14448 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
14451 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14453 switch (filedata
->file_header
.e_machine
)
14454 /* Please keep this table alpha-sorted for ease of visual lookup. */
14458 return reloc_type
== 2; /* R_386_PC32. */
14460 return reloc_type
== 4; /* R_68K_PC32. */
14462 return reloc_type
== 261; /* R_AARCH64_PREL32 */
14463 case EM_ADAPTEVA_EPIPHANY
:
14464 return reloc_type
== 6;
14466 return reloc_type
== 10; /* R_ALPHA_SREL32. */
14467 case EM_ARC_COMPACT
:
14468 case EM_ARC_COMPACT2
:
14469 return reloc_type
== 49; /* R_ARC_32_PCREL. */
14471 return reloc_type
== 3; /* R_ARM_REL32 */
14474 return reloc_type
== 36; /* R_AVR_32_PCREL. */
14476 return reloc_type
== 99; /* R_LARCH_32_PCREL. */
14477 case EM_MICROBLAZE
:
14478 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
14480 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
14482 return reloc_type
== 9; /* R_PARISC_PCREL32. */
14484 return reloc_type
== 26; /* R_PPC_REL32. */
14486 return reloc_type
== 26; /* R_PPC64_REL32. */
14488 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
14491 return reloc_type
== 5; /* R_390_PC32. */
14493 return reloc_type
== 2; /* R_SH_REL32. */
14494 case EM_SPARC32PLUS
:
14497 return reloc_type
== 6; /* R_SPARC_DISP32. */
14499 return reloc_type
== 13; /* R_SPU_REL32. */
14501 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
14503 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
14505 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
14509 return reloc_type
== 2; /* R_X86_64_PC32. */
14511 return reloc_type
== 4; /* R_VAX_PCREL32. */
14512 case EM_XTENSA_OLD
:
14514 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
14516 /* Do not abort or issue an error message here. Not all targets use
14517 pc-relative 32-bit relocs in their DWARF debug information and we
14518 have already tested for target coverage in is_32bit_abs_reloc. A
14519 more helpful warning message will be generated by apply_relocations
14520 anyway, so just return. */
14525 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14526 a 64-bit absolute RELA relocation used in DWARF debug sections. */
14529 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14531 switch (filedata
->file_header
.e_machine
)
14534 return reloc_type
== 257; /* R_AARCH64_ABS64. */
14536 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
14538 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
14539 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
14541 return reloc_type
== 2; /* R_LARCH_64 */
14543 return reloc_type
== 80; /* R_PARISC_DIR64. */
14545 return reloc_type
== 38; /* R_PPC64_ADDR64. */
14547 return reloc_type
== 2; /* R_RISCV_64. */
14548 case EM_SPARC32PLUS
:
14551 return reloc_type
== 32 /* R_SPARC_64. */
14552 || reloc_type
== 54; /* R_SPARC_UA64. */
14556 return reloc_type
== 1; /* R_X86_64_64. */
14559 return reloc_type
== 22; /* R_S390_64. */
14561 return reloc_type
== 1; /* R_TILEGX_64. */
14563 return reloc_type
== 18; /* R_MIPS_64. */
14569 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
14570 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
14573 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14575 switch (filedata
->file_header
.e_machine
)
14578 return reloc_type
== 260; /* R_AARCH64_PREL64. */
14580 return reloc_type
== 11; /* R_ALPHA_SREL64. */
14582 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
14583 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
14585 return reloc_type
== 72; /* R_PARISC_PCREL64. */
14587 return reloc_type
== 44; /* R_PPC64_REL64. */
14588 case EM_SPARC32PLUS
:
14591 return reloc_type
== 46; /* R_SPARC_DISP64. */
14595 return reloc_type
== 24; /* R_X86_64_PC64. */
14598 return reloc_type
== 23; /* R_S390_PC64. */
14600 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
14606 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14607 a 24-bit absolute RELA relocation used in DWARF debug sections. */
14610 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14612 switch (filedata
->file_header
.e_machine
)
14614 case EM_CYGNUS_MN10200
:
14616 return reloc_type
== 4; /* R_MN10200_24. */
14618 return reloc_type
== 5; /* R_FT32_20. */
14620 return reloc_type
== 5; /* R_Z80_24. */
14626 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14627 a 16-bit absolute RELA relocation used in DWARF debug sections. */
14630 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14632 /* Please keep this table alpha-sorted for ease of visual lookup. */
14633 switch (filedata
->file_header
.e_machine
)
14636 case EM_ARC_COMPACT
:
14637 case EM_ARC_COMPACT2
:
14638 return reloc_type
== 2; /* R_ARC_16. */
14639 case EM_ADAPTEVA_EPIPHANY
:
14640 return reloc_type
== 5;
14643 return reloc_type
== 4; /* R_AVR_16. */
14644 case EM_CYGNUS_D10V
:
14646 return reloc_type
== 3; /* R_D10V_16. */
14648 return reloc_type
== 2; /* R_FT32_16. */
14652 return reloc_type
== R_H8_DIR16
;
14655 return reloc_type
== 1; /* R_IP2K_16. */
14658 return reloc_type
== 1; /* R_M32C_16 */
14659 case EM_CYGNUS_MN10200
:
14661 return reloc_type
== 2; /* R_MN10200_16. */
14662 case EM_CYGNUS_MN10300
:
14664 return reloc_type
== 2; /* R_MN10300_16. */
14666 if (uses_msp430x_relocs (filedata
))
14667 return reloc_type
== 2; /* R_MSP430_ABS16. */
14668 /* Fall through. */
14669 case EM_MSP430_OLD
:
14670 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
14672 return reloc_type
== 19; /* R_NDS32_16_RELA. */
14673 case EM_ALTERA_NIOS2
:
14674 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
14676 return reloc_type
== 9; /* R_NIOS_16. */
14678 return reloc_type
== 2; /* R_OR1K_16. */
14680 return reloc_type
== 55; /* R_RISCV_SET16. */
14682 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
14684 return reloc_type
== 2; /* R_C6000_ABS16. */
14686 return reloc_type
== 2; /* R_VISIUM_16. */
14688 return reloc_type
== 3; /* R_XGATE_16. */
14690 return reloc_type
== 4; /* R_Z80_16. */
14696 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14697 a 8-bit absolute RELA relocation used in DWARF debug sections. */
14700 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14702 switch (filedata
->file_header
.e_machine
)
14705 return reloc_type
== 54; /* R_RISCV_SET8. */
14707 return reloc_type
== 1; /* R_Z80_8. */
14713 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14714 a 6-bit absolute RELA relocation used in DWARF debug sections. */
14717 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14719 switch (filedata
->file_header
.e_machine
)
14722 return reloc_type
== 53; /* R_RISCV_SET6. */
14728 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14729 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
14732 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14734 /* Please keep this table alpha-sorted for ease of visual lookup. */
14735 switch (filedata
->file_header
.e_machine
)
14738 return reloc_type
== 35; /* R_RISCV_ADD32. */
14744 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14745 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
14748 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14750 /* Please keep this table alpha-sorted for ease of visual lookup. */
14751 switch (filedata
->file_header
.e_machine
)
14754 return reloc_type
== 39; /* R_RISCV_SUB32. */
14760 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14761 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
14764 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14766 /* Please keep this table alpha-sorted for ease of visual lookup. */
14767 switch (filedata
->file_header
.e_machine
)
14770 return reloc_type
== 36; /* R_RISCV_ADD64. */
14776 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14777 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
14780 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14782 /* Please keep this table alpha-sorted for ease of visual lookup. */
14783 switch (filedata
->file_header
.e_machine
)
14786 return reloc_type
== 40; /* R_RISCV_SUB64. */
14792 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14793 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
14796 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14798 /* Please keep this table alpha-sorted for ease of visual lookup. */
14799 switch (filedata
->file_header
.e_machine
)
14802 return reloc_type
== 34; /* R_RISCV_ADD16. */
14808 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14809 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
14812 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14814 /* Please keep this table alpha-sorted for ease of visual lookup. */
14815 switch (filedata
->file_header
.e_machine
)
14818 return reloc_type
== 38; /* R_RISCV_SUB16. */
14824 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14825 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
14828 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14830 /* Please keep this table alpha-sorted for ease of visual lookup. */
14831 switch (filedata
->file_header
.e_machine
)
14834 return reloc_type
== 33; /* R_RISCV_ADD8. */
14840 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14841 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
14844 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14846 /* Please keep this table alpha-sorted for ease of visual lookup. */
14847 switch (filedata
->file_header
.e_machine
)
14850 return reloc_type
== 37; /* R_RISCV_SUB8. */
14856 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14857 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
14860 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14862 switch (filedata
->file_header
.e_machine
)
14865 return reloc_type
== 52; /* R_RISCV_SUB6. */
14871 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
14872 relocation entries (possibly formerly used for SHT_GROUP sections). */
14875 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14877 switch (filedata
->file_header
.e_machine
)
14879 case EM_386
: /* R_386_NONE. */
14880 case EM_68K
: /* R_68K_NONE. */
14881 case EM_ADAPTEVA_EPIPHANY
:
14882 case EM_ALPHA
: /* R_ALPHA_NONE. */
14883 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
14884 case EM_ARC
: /* R_ARC_NONE. */
14885 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
14886 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
14887 case EM_ARM
: /* R_ARM_NONE. */
14888 case EM_CRIS
: /* R_CRIS_NONE. */
14889 case EM_FT32
: /* R_FT32_NONE. */
14890 case EM_IA_64
: /* R_IA64_NONE. */
14891 case EM_K1OM
: /* R_X86_64_NONE. */
14892 case EM_L1OM
: /* R_X86_64_NONE. */
14893 case EM_M32R
: /* R_M32R_NONE. */
14894 case EM_MIPS
: /* R_MIPS_NONE. */
14895 case EM_MN10300
: /* R_MN10300_NONE. */
14896 case EM_MOXIE
: /* R_MOXIE_NONE. */
14897 case EM_NIOS32
: /* R_NIOS_NONE. */
14898 case EM_OR1K
: /* R_OR1K_NONE. */
14899 case EM_PARISC
: /* R_PARISC_NONE. */
14900 case EM_PPC64
: /* R_PPC64_NONE. */
14901 case EM_PPC
: /* R_PPC_NONE. */
14902 case EM_RISCV
: /* R_RISCV_NONE. */
14903 case EM_S390
: /* R_390_NONE. */
14905 case EM_SH
: /* R_SH_NONE. */
14906 case EM_SPARC32PLUS
:
14907 case EM_SPARC
: /* R_SPARC_NONE. */
14909 case EM_TILEGX
: /* R_TILEGX_NONE. */
14910 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
14911 case EM_TI_C6000
:/* R_C6000_NONE. */
14912 case EM_X86_64
: /* R_X86_64_NONE. */
14913 case EM_Z80
: /* R_Z80_NONE. */
14914 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
14915 return reloc_type
== 0;
14918 return reloc_type
== 0 || reloc_type
== 256;
14921 return (reloc_type
== 0 /* R_AVR_NONE. */
14922 || reloc_type
== 30 /* R_AVR_DIFF8. */
14923 || reloc_type
== 31 /* R_AVR_DIFF16. */
14924 || reloc_type
== 32 /* R_AVR_DIFF32. */);
14926 return reloc_type
== 3; /* R_METAG_NONE. */
14928 return (reloc_type
== 0 /* R_NDS32_NONE. */
14929 || reloc_type
== 205 /* R_NDS32_DIFF8. */
14930 || reloc_type
== 206 /* R_NDS32_DIFF16. */
14931 || reloc_type
== 207 /* R_NDS32_DIFF32. */
14932 || reloc_type
== 208 /* R_NDS32_DIFF_ULEB128. */);
14934 return (reloc_type
== 0 /* R_PRU_NONE. */
14935 || reloc_type
== 65 /* R_PRU_DIFF8. */
14936 || reloc_type
== 66 /* R_PRU_DIFF16. */
14937 || reloc_type
== 67 /* R_PRU_DIFF32. */);
14938 case EM_XTENSA_OLD
:
14940 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14941 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
14942 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
14943 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
14944 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
14945 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
14946 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
14947 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
14948 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
14949 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
14954 /* Returns TRUE if there is a relocation against
14955 section NAME at OFFSET bytes. */
14958 reloc_at (struct dwarf_section
* dsec
, uint64_t offset
)
14960 Elf_Internal_Rela
* relocs
;
14961 Elf_Internal_Rela
* rp
;
14963 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
14966 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
14968 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
14969 if (rp
->r_offset
== offset
)
14975 /* Apply relocations to a section.
14976 Returns TRUE upon success, FALSE otherwise.
14977 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
14978 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
14979 will be set to the number of relocs loaded.
14981 Note: So far support has been added only for those relocations
14982 which can be found in debug sections. FIXME: Add support for
14983 more relocations ? */
14986 apply_relocations (Filedata
*filedata
,
14987 const Elf_Internal_Shdr
*section
,
14988 unsigned char *start
,
14990 void **relocs_return
,
14991 uint64_t *num_relocs_return
)
14993 Elf_Internal_Shdr
* relsec
;
14994 unsigned char * end
= start
+ size
;
14996 if (relocs_return
!= NULL
)
14998 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
14999 * num_relocs_return
= 0;
15002 if (filedata
->file_header
.e_type
!= ET_REL
)
15003 /* No relocs to apply. */
15006 /* Find the reloc section associated with the section. */
15007 for (relsec
= filedata
->section_headers
;
15008 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15012 uint64_t num_relocs
;
15013 Elf_Internal_Rela
* relocs
;
15014 Elf_Internal_Rela
* rp
;
15015 Elf_Internal_Shdr
* symsec
;
15016 Elf_Internal_Sym
* symtab
;
15018 Elf_Internal_Sym
* sym
;
15020 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15021 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15022 || filedata
->section_headers
+ relsec
->sh_info
!= section
15023 || relsec
->sh_size
== 0
15024 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15027 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
15028 if (symsec
->sh_type
!= SHT_SYMTAB
15029 && symsec
->sh_type
!= SHT_DYNSYM
)
15032 is_rela
= relsec
->sh_type
== SHT_RELA
;
15036 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
15037 relsec
->sh_size
, & relocs
, & num_relocs
))
15042 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
15043 relsec
->sh_size
, & relocs
, & num_relocs
))
15047 /* SH uses RELA but uses in place value instead of the addend field. */
15048 if (filedata
->file_header
.e_machine
== EM_SH
)
15051 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
15053 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
15056 unsigned int reloc_type
;
15057 unsigned int reloc_size
;
15058 bool reloc_inplace
= false;
15059 bool reloc_subtract
= false;
15060 unsigned char *rloc
;
15061 uint64_t sym_index
;
15063 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
15065 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
15067 else if (is_none_reloc (filedata
, reloc_type
))
15069 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
15070 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
15072 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
15073 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15075 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
15077 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
15079 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
15080 || is_6bit_abs_reloc (filedata
, reloc_type
))
15082 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
15084 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
15087 reloc_inplace
= true;
15089 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
15091 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
15094 reloc_inplace
= true;
15096 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
15098 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
15101 reloc_inplace
= true;
15103 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
15105 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
15108 reloc_inplace
= true;
15110 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
15114 reloc_inplace
= true;
15118 static unsigned int prev_reloc
= 0;
15120 if (reloc_type
!= prev_reloc
)
15121 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
15122 reloc_type
, printable_section_name (filedata
, section
));
15123 prev_reloc
= reloc_type
;
15127 rloc
= start
+ rp
->r_offset
;
15128 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
15130 warn (_("skipping invalid relocation offset %#" PRIx64
15131 " in section %s\n"),
15133 printable_section_name (filedata
, section
));
15137 sym_index
= get_reloc_symindex (rp
->r_info
);
15138 if (sym_index
>= num_syms
)
15140 warn (_("skipping invalid relocation symbol index %#" PRIx64
15141 " in section %s\n"),
15142 sym_index
, printable_section_name (filedata
, section
));
15145 sym
= symtab
+ sym_index
;
15147 /* If the reloc has a symbol associated with it,
15148 make sure that it is of an appropriate type.
15150 Relocations against symbols without type can happen.
15151 Gcc -feliminate-dwarf2-dups may generate symbols
15152 without type for debug info.
15154 Icc generates relocations against function symbols
15155 instead of local labels.
15157 Relocations against object symbols can happen, eg when
15158 referencing a global array. For an example of this see
15159 the _clz.o binary in libgcc.a. */
15161 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
15162 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
15164 warn (_("skipping unexpected symbol type %s in section %s relocation %tu\n"),
15165 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
15166 printable_section_name (filedata
, relsec
),
15173 addend
+= rp
->r_addend
;
15174 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
15175 partial_inplace. */
15177 || (filedata
->file_header
.e_machine
== EM_XTENSA
15178 && reloc_type
== 1)
15179 || ((filedata
->file_header
.e_machine
== EM_PJ
15180 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
15181 && reloc_type
== 1)
15182 || ((filedata
->file_header
.e_machine
== EM_D30V
15183 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
15184 && reloc_type
== 12)
15187 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15188 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
15190 addend
+= byte_get (rloc
, reloc_size
);
15193 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
15194 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15196 /* On HPPA, all pc-relative relocations are biased by 8. */
15197 if (filedata
->file_header
.e_machine
== EM_PARISC
)
15199 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
15202 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
15203 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15205 if (reloc_subtract
)
15206 addend
-= sym
->st_value
;
15208 addend
+= sym
->st_value
;
15209 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
15210 byte_put (rloc
, addend
, reloc_size
);
15212 else if (reloc_subtract
)
15213 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
15215 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
15219 /* Let the target specific reloc processing code know that
15220 we have finished with these relocs. */
15221 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
15225 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
15226 * num_relocs_return
= num_relocs
;
15237 #ifdef SUPPORT_DISASSEMBLY
15239 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15241 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
15243 /* FIXME: XXX -- to be done --- XXX */
15249 /* Reads in the contents of SECTION from FILE, returning a pointer
15250 to a malloc'ed buffer or NULL if something went wrong. */
15253 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15255 uint64_t num_bytes
= section
->sh_size
;
15257 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
15259 printf (_("Section '%s' has no data to dump.\n"),
15260 printable_section_name (filedata
, section
));
15264 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
15265 _("section contents"));
15268 /* Uncompresses a section that was compressed using zlib/zstd, in place. */
15271 uncompress_section_contents (bool is_zstd
,
15272 unsigned char ** buffer
,
15273 uint64_t uncompressed_size
,
15275 uint64_t file_size
)
15277 uint64_t compressed_size
= *size
;
15278 unsigned char *compressed_buffer
= *buffer
;
15279 unsigned char *uncompressed_buffer
= NULL
;
15283 /* Similar to _bfd_section_size_insane() in the BFD library we expect an
15284 upper limit of ~10x compression. Any compression larger than that is
15285 thought to be due to fuzzing of the compression header. */
15286 if (uncompressed_size
> file_size
* 10)
15288 error (_("Uncompressed section size is suspiciously large: 0x%" PRIu64
"\n"),
15289 uncompressed_size
);
15293 uncompressed_buffer
= xmalloc (uncompressed_size
);
15298 size_t ret
= ZSTD_decompress (uncompressed_buffer
, uncompressed_size
,
15299 compressed_buffer
, compressed_size
);
15300 if (ZSTD_isError (ret
))
15306 /* It is possible the section consists of several compressed
15307 buffers concatenated together, so we uncompress in a loop. */
15308 /* PR 18313: The state field in the z_stream structure is supposed
15309 to be invisible to the user (ie us), but some compilers will
15310 still complain about it being used without initialisation. So
15311 we first zero the entire z_stream structure and then set the fields
15313 memset (&strm
, 0, sizeof strm
);
15314 strm
.avail_in
= compressed_size
;
15315 strm
.next_in
= (Bytef
*)compressed_buffer
;
15316 strm
.avail_out
= uncompressed_size
;
15318 rc
= inflateInit (&strm
);
15319 while (strm
.avail_in
> 0)
15323 strm
.next_out
= ((Bytef
*)uncompressed_buffer
15324 + (uncompressed_size
- strm
.avail_out
));
15325 rc
= inflate (&strm
, Z_FINISH
);
15326 if (rc
!= Z_STREAM_END
)
15328 rc
= inflateReset (&strm
);
15330 if (inflateEnd (&strm
) != Z_OK
|| rc
!= Z_OK
|| strm
.avail_out
!= 0)
15334 *buffer
= uncompressed_buffer
;
15335 *size
= uncompressed_size
;
15339 free (uncompressed_buffer
);
15340 /* Indicate decompression failure. */
15346 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15348 Elf_Internal_Shdr
*relsec
;
15349 uint64_t num_bytes
;
15350 unsigned char *data
;
15351 unsigned char *end
;
15352 unsigned char *real_start
;
15353 unsigned char *start
;
15354 bool some_strings_shown
;
15356 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
15358 /* PR 21820: Do not fail if the section was empty. */
15359 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
15361 num_bytes
= section
->sh_size
;
15363 if (filedata
->is_separate
)
15364 printf (_("\nString dump of section '%s' in linked file %s:\n"),
15365 printable_section_name (filedata
, section
),
15366 filedata
->file_name
);
15368 printf (_("\nString dump of section '%s':\n"),
15369 printable_section_name (filedata
, section
));
15371 if (decompress_dumps
)
15373 uint64_t new_size
= num_bytes
;
15374 uint64_t uncompressed_size
= 0;
15375 bool is_zstd
= false;
15377 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15379 Elf_Internal_Chdr chdr
;
15380 unsigned int compression_header_size
15381 = get_compression_header (& chdr
, (unsigned char *) start
,
15383 if (compression_header_size
== 0)
15384 /* An error message will have already been generated
15385 by get_compression_header. */
15388 if (chdr
.ch_type
== ch_compress_zlib
)
15391 else if (chdr
.ch_type
== ch_compress_zstd
)
15396 warn (_("section '%s' has unsupported compress type: %d\n"),
15397 printable_section_name (filedata
, section
), chdr
.ch_type
);
15400 uncompressed_size
= chdr
.ch_size
;
15401 start
+= compression_header_size
;
15402 new_size
-= compression_header_size
;
15404 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15406 /* Read the zlib header. In this case, it should be "ZLIB"
15407 followed by the uncompressed section size, 8 bytes in
15408 big-endian order. */
15409 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15410 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15411 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15412 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15413 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15414 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15415 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15416 uncompressed_size
+= start
[11];
15421 if (uncompressed_size
)
15423 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
15424 &new_size
, filedata
->file_size
))
15425 num_bytes
= new_size
;
15428 error (_("Unable to decompress section %s\n"),
15429 printable_section_name (filedata
, section
));
15434 start
= real_start
;
15437 /* If the section being dumped has relocations against it the user might
15438 be expecting these relocations to have been applied. Check for this
15439 case and issue a warning message in order to avoid confusion.
15440 FIXME: Maybe we ought to have an option that dumps a section with
15441 relocs applied ? */
15442 for (relsec
= filedata
->section_headers
;
15443 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15446 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15447 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15448 || filedata
->section_headers
+ relsec
->sh_info
!= section
15449 || relsec
->sh_size
== 0
15450 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15453 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
15458 end
= start
+ num_bytes
;
15459 some_strings_shown
= false;
15461 #ifdef HAVE_MBSTATE_T
15463 /* Initialise the multibyte conversion state. */
15464 memset (& state
, 0, sizeof (state
));
15467 bool continuing
= false;
15471 while (!ISPRINT (* data
))
15472 if (++ data
>= end
)
15477 size_t maxlen
= end
- data
;
15482 continuing
= false;
15486 printf (" [%6tx] ", data
- start
);
15500 /* PR 25543: Treat new-lines as string-ending characters. */
15509 /* Do not print control characters directly as they can affect terminal
15510 settings. Such characters usually appear in the names generated
15511 by the assembler for local labels. */
15514 printf ("^%c", c
+ 0x40);
15516 else if (ISPRINT (c
))
15523 #ifdef HAVE_MBSTATE_T
15526 /* Let printf do the hard work of displaying multibyte characters. */
15527 printf ("%.1s", data
- 1);
15528 #ifdef HAVE_MBSTATE_T
15529 /* Try to find out how many bytes made up the character that was
15530 just printed. Advance the symbol pointer past the bytes that
15532 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
15536 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
15546 printf (_("<corrupt>\n"));
15549 some_strings_shown
= true;
15553 if (! some_strings_shown
)
15554 printf (_(" No strings found in this section."));
15567 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
15568 Filedata
*filedata
,
15571 Elf_Internal_Shdr
*relsec
;
15573 uint64_t section_size
;
15575 unsigned char *data
;
15576 unsigned char *real_start
;
15577 unsigned char *start
;
15579 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
15581 /* PR 21820: Do not fail if the section was empty. */
15582 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
15584 section_size
= section
->sh_size
;
15586 if (filedata
->is_separate
)
15587 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
15588 printable_section_name (filedata
, section
),
15589 filedata
->file_name
);
15591 printf (_("\nHex dump of section '%s':\n"),
15592 printable_section_name (filedata
, section
));
15594 if (decompress_dumps
)
15596 uint64_t new_size
= section_size
;
15597 uint64_t uncompressed_size
= 0;
15598 bool is_zstd
= false;
15600 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15602 Elf_Internal_Chdr chdr
;
15603 unsigned int compression_header_size
15604 = get_compression_header (& chdr
, start
, section_size
);
15606 if (compression_header_size
== 0)
15607 /* An error message will have already been generated
15608 by get_compression_header. */
15611 if (chdr
.ch_type
== ch_compress_zlib
)
15614 else if (chdr
.ch_type
== ch_compress_zstd
)
15619 warn (_("section '%s' has unsupported compress type: %d\n"),
15620 printable_section_name (filedata
, section
), chdr
.ch_type
);
15623 uncompressed_size
= chdr
.ch_size
;
15624 start
+= compression_header_size
;
15625 new_size
-= compression_header_size
;
15627 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15629 /* Read the zlib header. In this case, it should be "ZLIB"
15630 followed by the uncompressed section size, 8 bytes in
15631 big-endian order. */
15632 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15633 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15634 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15635 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15636 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15637 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15638 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15639 uncompressed_size
+= start
[11];
15644 if (uncompressed_size
)
15646 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
15647 &new_size
, filedata
->file_size
))
15649 section_size
= new_size
;
15653 error (_("Unable to decompress section %s\n"),
15654 printable_section_name (filedata
, section
));
15655 /* FIXME: Print the section anyway ? */
15660 start
= real_start
;
15665 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
15670 /* If the section being dumped has relocations against it the user might
15671 be expecting these relocations to have been applied. Check for this
15672 case and issue a warning message in order to avoid confusion.
15673 FIXME: Maybe we ought to have an option that dumps a section with
15674 relocs applied ? */
15675 for (relsec
= filedata
->section_headers
;
15676 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15679 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15680 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15681 || filedata
->section_headers
+ relsec
->sh_info
!= section
15682 || relsec
->sh_size
== 0
15683 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15686 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
15691 addr
= section
->sh_addr
;
15692 bytes
= section_size
;
15701 lbytes
= (bytes
> 16 ? 16 : bytes
);
15703 printf (" 0x%8.8" PRIx64
" ", addr
);
15705 for (j
= 0; j
< 16; j
++)
15708 printf ("%2.2x", data
[j
]);
15716 for (j
= 0; j
< lbytes
; j
++)
15719 if (k
>= ' ' && k
< 0x7f)
15742 #ifdef ENABLE_LIBCTF
15743 static ctf_sect_t
*
15744 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
15746 buf
->cts_name
= section_name_print (filedata
, shdr
);
15747 buf
->cts_size
= shdr
->sh_size
;
15748 buf
->cts_entsize
= shdr
->sh_entsize
;
15753 /* Formatting callback function passed to ctf_dump. Returns either the pointer
15754 it is passed, or a pointer to newly-allocated storage, in which case
15755 dump_ctf() will free it when it no longer needs it. */
15758 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
15759 char *s
, void *arg
)
15761 const char *blanks
= arg
;
15764 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
15769 /* Dump CTF errors/warnings. */
15771 dump_ctf_errs (ctf_dict_t
*fp
)
15773 ctf_next_t
*it
= NULL
;
15778 /* Dump accumulated errors and warnings. */
15779 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
15781 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
15785 if (err
!= ECTF_NEXT_END
)
15786 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
15789 /* Dump one CTF archive member. */
15792 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
15795 const char *things
[] = {"Header", "Labels", "Data objects",
15796 "Function objects", "Variables", "Types", "Strings",
15798 const char **thing
;
15801 /* Don't print out the name of the default-named archive member if it appears
15802 first in the list. The name .ctf appears everywhere, even for things that
15803 aren't really archives, so printing it out is liable to be confusing; also,
15804 the common case by far is for only one archive member to exist, and hiding
15805 it in that case seems worthwhile. */
15807 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
15808 printf (_("\nCTF archive member: %s:\n"), name
);
15810 if (ctf_parent_name (ctf
) != NULL
)
15811 ctf_import (ctf
, parent
);
15813 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
15815 ctf_dump_state_t
*s
= NULL
;
15818 printf ("\n %s:\n", *thing
);
15819 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
15820 (void *) " ")) != NULL
)
15822 printf ("%s\n", item
);
15826 if (ctf_errno (ctf
))
15828 error (_("Iteration failed: %s, %s\n"), *thing
,
15829 ctf_errmsg (ctf_errno (ctf
)));
15834 dump_ctf_errs (ctf
);
15838 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15840 Elf_Internal_Shdr
* symtab_sec
= NULL
;
15841 Elf_Internal_Shdr
* strtab_sec
= NULL
;
15842 void * data
= NULL
;
15843 void * symdata
= NULL
;
15844 void * strdata
= NULL
;
15845 ctf_sect_t ctfsect
, symsect
, strsect
;
15846 ctf_sect_t
* symsectp
= NULL
;
15847 ctf_sect_t
* strsectp
= NULL
;
15848 ctf_archive_t
* ctfa
= NULL
;
15849 ctf_dict_t
* parent
= NULL
;
15852 ctf_next_t
*i
= NULL
;
15858 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
15859 data
= get_section_contents (section
, filedata
);
15860 ctfsect
.cts_data
= data
;
15862 if (!dump_ctf_symtab_name
)
15863 dump_ctf_symtab_name
= strdup (".dynsym");
15865 if (!dump_ctf_strtab_name
)
15866 dump_ctf_strtab_name
= strdup (".dynstr");
15868 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
15870 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
15872 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
15875 if ((symdata
= (void *) get_data (NULL
, filedata
,
15876 symtab_sec
->sh_offset
, 1,
15877 symtab_sec
->sh_size
,
15878 _("symbols"))) == NULL
)
15880 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
15881 symsect
.cts_data
= symdata
;
15884 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
15886 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
15888 error (_("No string table section named %s\n"),
15889 dump_ctf_strtab_name
);
15892 if ((strdata
= (void *) get_data (NULL
, filedata
,
15893 strtab_sec
->sh_offset
, 1,
15894 strtab_sec
->sh_size
,
15895 _("strings"))) == NULL
)
15897 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
15898 strsect
.cts_data
= strdata
;
15901 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
15902 libctf papers over the difference, so we can pretend it is always an
15905 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
15907 dump_ctf_errs (NULL
);
15908 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15912 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
15915 /* Preload the parent dict, since it will need to be imported into every
15917 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
15919 dump_ctf_errs (NULL
);
15920 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15926 if (filedata
->is_separate
)
15927 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
15928 printable_section_name (filedata
, section
),
15929 filedata
->file_name
);
15931 printf (_("\nDump of CTF section '%s':\n"),
15932 printable_section_name (filedata
, section
));
15934 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
15935 dump_ctf_archive_member (fp
, name
, parent
, member
++);
15936 if (err
!= ECTF_NEXT_END
)
15938 dump_ctf_errs (NULL
);
15939 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
15944 ctf_dict_close (parent
);
15954 dump_section_as_sframe (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15956 void * data
= NULL
;
15957 sframe_decoder_ctx
*sfd_ctx
= NULL
;
15958 const char *print_name
= printable_section_name (filedata
, section
);
15964 if (strcmp (print_name
, "") == 0)
15966 error (_("Section name must be provided \n"));
15971 data
= get_section_contents (section
, filedata
);
15972 sf_size
= section
->sh_size
;
15973 /* Decode the contents of the section. */
15974 sfd_ctx
= sframe_decode ((const char*)data
, sf_size
, &err
);
15978 error (_("SFrame decode failure: %s\n"), sframe_errmsg (err
));
15982 printf (_("Contents of the SFrame section %s:"), print_name
);
15983 /* Dump the contents as text. */
15984 dump_sframe (sfd_ctx
, section
->sh_addr
);
15992 load_specific_debug_section (enum dwarf_section_display_enum debug
,
15993 const Elf_Internal_Shdr
* sec
,
15996 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15998 Filedata
* filedata
= (Filedata
*) data
;
16000 if (section
->start
!= NULL
)
16002 /* If it is already loaded, do nothing. */
16003 if (streq (section
->filename
, filedata
->file_name
))
16005 free (section
->start
);
16008 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
16009 section
->address
= sec
->sh_addr
;
16010 section
->filename
= filedata
->file_name
;
16011 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
16013 sec
->sh_size
, buf
);
16014 if (section
->start
== NULL
)
16018 unsigned char *start
= section
->start
;
16019 uint64_t size
= sec
->sh_size
;
16020 uint64_t uncompressed_size
= 0;
16021 bool is_zstd
= false;
16023 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
16025 Elf_Internal_Chdr chdr
;
16026 unsigned int compression_header_size
;
16028 if (size
< (is_32bit_elf
16029 ? sizeof (Elf32_External_Chdr
)
16030 : sizeof (Elf64_External_Chdr
)))
16032 warn (_("compressed section %s is too small to contain a compression header\n"),
16037 compression_header_size
= get_compression_header (&chdr
, start
, size
);
16038 if (compression_header_size
== 0)
16039 /* An error message will have already been generated
16040 by get_compression_header. */
16043 if (chdr
.ch_type
== ch_compress_zlib
)
16046 else if (chdr
.ch_type
== ch_compress_zstd
)
16051 warn (_("section '%s' has unsupported compress type: %d\n"),
16052 section
->name
, chdr
.ch_type
);
16055 uncompressed_size
= chdr
.ch_size
;
16056 start
+= compression_header_size
;
16057 size
-= compression_header_size
;
16059 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
16061 /* Read the zlib header. In this case, it should be "ZLIB"
16062 followed by the uncompressed section size, 8 bytes in
16063 big-endian order. */
16064 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
16065 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
16066 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
16067 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
16068 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
16069 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
16070 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
16071 uncompressed_size
+= start
[11];
16076 if (uncompressed_size
)
16078 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
16079 &size
, filedata
->file_size
))
16081 /* Free the compressed buffer, update the section buffer
16082 and the section size if uncompress is successful. */
16083 free (section
->start
);
16084 section
->start
= start
;
16088 error (_("Unable to decompress section %s\n"),
16089 printable_section_name (filedata
, sec
));
16094 section
->size
= size
;
16097 if (section
->start
== NULL
)
16100 if (debug_displays
[debug
].relocate
)
16102 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
16103 & section
->reloc_info
, & section
->num_relocs
))
16108 section
->reloc_info
= NULL
;
16109 section
->num_relocs
= 0;
16115 #if HAVE_LIBDEBUGINFOD
16116 /* Return a hex string representation of the build-id. */
16118 get_build_id (void * data
)
16120 Filedata
* filedata
= (Filedata
*) data
;
16121 Elf_Internal_Shdr
* shdr
;
16124 /* Iterate through notes to find note.gnu.build-id.
16125 FIXME: Only the first note in any note section is examined. */
16126 for (i
= 0, shdr
= filedata
->section_headers
;
16127 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
16130 if (shdr
->sh_type
!= SHT_NOTE
)
16135 size_t data_remaining
;
16137 Elf_External_Note
* enote
;
16138 Elf_Internal_Note inote
;
16140 uint64_t offset
= shdr
->sh_offset
;
16141 uint64_t align
= shdr
->sh_addralign
;
16142 uint64_t length
= shdr
->sh_size
;
16144 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
16150 else if (align
!= 4 && align
!= 8)
16156 end
= (char *) enote
+ length
;
16157 data_remaining
= end
- (char *) enote
;
16159 if (!is_ia64_vms (filedata
))
16161 min_notesz
= offsetof (Elf_External_Note
, name
);
16162 if (data_remaining
< min_notesz
)
16165 malformed note encountered in section %s whilst scanning for build-id note\n"),
16166 printable_section_name (filedata
, shdr
));
16170 data_remaining
-= min_notesz
;
16172 inote
.type
= BYTE_GET (enote
->type
);
16173 inote
.namesz
= BYTE_GET (enote
->namesz
);
16174 inote
.namedata
= enote
->name
;
16175 inote
.descsz
= BYTE_GET (enote
->descsz
);
16176 inote
.descdata
= ((char *) enote
16177 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
16178 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16179 next
= ((char *) enote
16180 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
16184 Elf64_External_VMS_Note
*vms_enote
;
16186 /* PR binutils/15191
16187 Make sure that there is enough data to read. */
16188 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
16189 if (data_remaining
< min_notesz
)
16192 malformed note encountered in section %s whilst scanning for build-id note\n"),
16193 printable_section_name (filedata
, shdr
));
16197 data_remaining
-= min_notesz
;
16199 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
16200 inote
.type
= BYTE_GET (vms_enote
->type
);
16201 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
16202 inote
.namedata
= vms_enote
->name
;
16203 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
16204 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
16205 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16206 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
16209 /* Skip malformed notes. */
16210 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
16211 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
16212 || (size_t) (next
- inote
.descdata
) < inote
.descsz
16213 || ((size_t) (next
- inote
.descdata
)
16214 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
16217 malformed note encountered in section %s whilst scanning for build-id note\n"),
16218 printable_section_name (filedata
, shdr
));
16223 /* Check if this is the build-id note. If so then convert the build-id
16224 bytes to a hex string. */
16225 if (inote
.namesz
> 0
16226 && startswith (inote
.namedata
, "GNU")
16227 && inote
.type
== NT_GNU_BUILD_ID
)
16232 build_id
= malloc (inote
.descsz
* 2 + 1);
16233 if (build_id
== NULL
)
16239 for (j
= 0; j
< inote
.descsz
; ++j
)
16240 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
16241 build_id
[inote
.descsz
* 2] = '\0';
16244 return (unsigned char *) build_id
;
16251 #endif /* HAVE_LIBDEBUGINFOD */
16253 /* If this is not NULL, load_debug_section will only look for sections
16254 within the list of sections given here. */
16255 static unsigned int * section_subset
= NULL
;
16258 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
16260 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16261 Elf_Internal_Shdr
* sec
;
16262 Filedata
* filedata
= (Filedata
*) data
;
16264 if (!dump_any_debugging
)
16267 /* Without section headers we cannot find any sections. */
16268 if (filedata
->section_headers
== NULL
)
16271 if (filedata
->string_table
== NULL
16272 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
16273 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
16275 Elf_Internal_Shdr
* strs
;
16277 /* Read in the string table, so that we have section names to scan. */
16278 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
16280 if (strs
!= NULL
&& strs
->sh_size
!= 0)
16282 filedata
->string_table
16283 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
16284 1, strs
->sh_size
, _("string table"));
16286 filedata
->string_table_length
16287 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
16291 /* Locate the debug section. */
16292 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
16294 section
->name
= section
->uncompressed_name
;
16297 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
16299 section
->name
= section
->compressed_name
;
16304 /* If we're loading from a subset of sections, and we've loaded
16305 a section matching this name before, it's likely that it's a
16307 if (section_subset
!= NULL
)
16308 free_debug_section (debug
);
16310 return load_specific_debug_section (debug
, sec
, data
);
16314 free_debug_section (enum dwarf_section_display_enum debug
)
16316 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16318 if (section
->start
== NULL
)
16321 free ((char *) section
->start
);
16322 section
->start
= NULL
;
16323 section
->address
= 0;
16326 free (section
->reloc_info
);
16327 section
->reloc_info
= NULL
;
16328 section
->num_relocs
= 0;
16332 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16334 const char *name
= (section_name_valid (filedata
, section
)
16335 ? section_name (filedata
, section
) : "");
16336 const char *print_name
= printable_section_name (filedata
, section
);
16338 bool result
= true;
16341 length
= section
->sh_size
;
16344 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
16347 if (section
->sh_type
== SHT_NOBITS
)
16349 /* There is no point in dumping the contents of a debugging section
16350 which has the NOBITS type - the bits in the file will be random.
16351 This can happen when a file containing a .eh_frame section is
16352 stripped with the --only-keep-debug command line option. */
16353 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
16358 if (startswith (name
, ".gnu.linkonce.wi."))
16359 name
= ".debug_info";
16361 /* See if we know how to display the contents of this section. */
16362 for (i
= 0; i
< max
; i
++)
16364 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
16365 struct dwarf_section_display
* display
= debug_displays
+ i
;
16366 struct dwarf_section
* sec
= & display
->section
;
16368 if (streq (sec
->uncompressed_name
, name
)
16369 || (id
== line
&& startswith (name
, ".debug_line."))
16370 || streq (sec
->compressed_name
, name
))
16372 bool secondary
= (section
!= find_section (filedata
, name
));
16375 free_debug_section (id
);
16377 if (i
== line
&& startswith (name
, ".debug_line."))
16379 else if (streq (sec
->uncompressed_name
, name
))
16380 sec
->name
= sec
->uncompressed_name
;
16382 sec
->name
= sec
->compressed_name
;
16384 if (load_specific_debug_section (id
, section
, filedata
))
16386 /* If this debug section is part of a CU/TU set in a .dwp file,
16387 restrict load_debug_section to the sections in that set. */
16388 section_subset
= find_cu_tu_set (filedata
, shndx
);
16390 result
&= display
->display (sec
, filedata
);
16392 section_subset
= NULL
;
16394 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
16395 free_debug_section (id
);
16403 printf (_("Unrecognized debug section: %s\n"), print_name
);
16410 /* Set DUMP_SECTS for all sections where dumps were requested
16411 based on section name. */
16414 initialise_dumps_byname (Filedata
* filedata
)
16416 struct dump_list_entry
* cur
;
16418 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
16423 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
16424 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
16425 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
16428 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
16432 if (!any
&& !filedata
->is_separate
)
16433 warn (_("Section '%s' was not dumped because it does not exist\n"),
16439 process_section_contents (Filedata
* filedata
)
16441 Elf_Internal_Shdr
* section
;
16448 initialise_dumps_byname (filedata
);
16450 for (i
= 0, section
= filedata
->section_headers
;
16451 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
16454 dump_type dump
= filedata
->dump
.dump_sects
[i
];
16456 if (filedata
->is_separate
&& ! process_links
)
16457 dump
&= DEBUG_DUMP
;
16459 #ifdef SUPPORT_DISASSEMBLY
16460 if (dump
& DISASS_DUMP
)
16462 if (! disassemble_section (section
, filedata
))
16466 if (dump
& HEX_DUMP
)
16468 if (! dump_section_as_bytes (section
, filedata
, false))
16472 if (dump
& RELOC_DUMP
)
16474 if (! dump_section_as_bytes (section
, filedata
, true))
16478 if (dump
& STRING_DUMP
)
16480 if (! dump_section_as_strings (section
, filedata
))
16484 if (dump
& DEBUG_DUMP
)
16486 if (! display_debug_section (i
, section
, filedata
))
16490 #ifdef ENABLE_LIBCTF
16491 if (dump
& CTF_DUMP
)
16493 if (! dump_section_as_ctf (section
, filedata
))
16497 if (dump
& SFRAME_DUMP
)
16499 if (! dump_section_as_sframe (section
, filedata
))
16504 if (! filedata
->is_separate
)
16506 /* Check to see if the user requested a
16507 dump of a section that does not exist. */
16508 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
16509 if (filedata
->dump
.dump_sects
[i
])
16511 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
16520 process_mips_fpe_exception (int mask
)
16526 if (mask
& OEX_FPU_INEX
)
16527 fputs ("INEX", stdout
), first
= false;
16528 if (mask
& OEX_FPU_UFLO
)
16529 printf ("%sUFLO", first
? "" : "|"), first
= false;
16530 if (mask
& OEX_FPU_OFLO
)
16531 printf ("%sOFLO", first
? "" : "|"), first
= false;
16532 if (mask
& OEX_FPU_DIV0
)
16533 printf ("%sDIV0", first
? "" : "|"), first
= false;
16534 if (mask
& OEX_FPU_INVAL
)
16535 printf ("%sINVAL", first
? "" : "|");
16538 fputs ("0", stdout
);
16541 /* Display's the value of TAG at location P. If TAG is
16542 greater than 0 it is assumed to be an unknown tag, and
16543 a message is printed to this effect. Otherwise it is
16544 assumed that a message has already been printed.
16546 If the bottom bit of TAG is set it assumed to have a
16547 string value, otherwise it is assumed to have an integer
16550 Returns an updated P pointing to the first unread byte
16551 beyond the end of TAG's value.
16553 Reads at or beyond END will not be made. */
16555 static unsigned char *
16556 display_tag_value (signed int tag
,
16558 const unsigned char * const end
)
16563 printf (" Tag_unknown_%d: ", tag
);
16567 warn (_("<corrupt tag>\n"));
16571 /* PR 17531 file: 027-19978-0.004. */
16572 size_t maxlen
= (end
- p
) - 1;
16577 print_symbol ((int) maxlen
, (const char *) p
);
16578 p
+= strnlen ((char *) p
, maxlen
) + 1;
16582 printf (_("<corrupt string tag>"));
16583 p
= (unsigned char *) end
;
16589 READ_ULEB (val
, p
, end
);
16590 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
16597 /* ARC ABI attributes section. */
16599 static unsigned char *
16600 display_arc_attribute (unsigned char * p
,
16601 const unsigned char * const end
)
16606 READ_ULEB (tag
, p
, end
);
16610 case Tag_ARC_PCS_config
:
16611 READ_ULEB (val
, p
, end
);
16612 printf (" Tag_ARC_PCS_config: ");
16616 printf (_("Absent/Non standard\n"));
16619 printf (_("Bare metal/mwdt\n"));
16622 printf (_("Bare metal/newlib\n"));
16625 printf (_("Linux/uclibc\n"));
16628 printf (_("Linux/glibc\n"));
16631 printf (_("Unknown\n"));
16636 case Tag_ARC_CPU_base
:
16637 READ_ULEB (val
, p
, end
);
16638 printf (" Tag_ARC_CPU_base: ");
16643 printf (_("Absent\n"));
16645 case TAG_CPU_ARC6xx
:
16646 printf ("ARC6xx\n");
16648 case TAG_CPU_ARC7xx
:
16649 printf ("ARC7xx\n");
16651 case TAG_CPU_ARCEM
:
16652 printf ("ARCEM\n");
16654 case TAG_CPU_ARCHS
:
16655 printf ("ARCHS\n");
16660 case Tag_ARC_CPU_variation
:
16661 READ_ULEB (val
, p
, end
);
16662 printf (" Tag_ARC_CPU_variation: ");
16666 if (val
> 0 && val
< 16)
16667 printf ("Core%d\n", val
);
16669 printf ("Unknown\n");
16673 printf (_("Absent\n"));
16678 case Tag_ARC_CPU_name
:
16679 printf (" Tag_ARC_CPU_name: ");
16680 p
= display_tag_value (-1, p
, end
);
16683 case Tag_ARC_ABI_rf16
:
16684 READ_ULEB (val
, p
, end
);
16685 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
16688 case Tag_ARC_ABI_osver
:
16689 READ_ULEB (val
, p
, end
);
16690 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
16693 case Tag_ARC_ABI_pic
:
16694 case Tag_ARC_ABI_sda
:
16695 READ_ULEB (val
, p
, end
);
16696 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
16697 : " Tag_ARC_ABI_pic: ");
16701 printf (_("Absent\n"));
16710 printf (_("Unknown\n"));
16715 case Tag_ARC_ABI_tls
:
16716 READ_ULEB (val
, p
, end
);
16717 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
16720 case Tag_ARC_ABI_enumsize
:
16721 READ_ULEB (val
, p
, end
);
16722 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
16726 case Tag_ARC_ABI_exceptions
:
16727 READ_ULEB (val
, p
, end
);
16728 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
16732 case Tag_ARC_ABI_double_size
:
16733 READ_ULEB (val
, p
, end
);
16734 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
16737 case Tag_ARC_ISA_config
:
16738 printf (" Tag_ARC_ISA_config: ");
16739 p
= display_tag_value (-1, p
, end
);
16742 case Tag_ARC_ISA_apex
:
16743 printf (" Tag_ARC_ISA_apex: ");
16744 p
= display_tag_value (-1, p
, end
);
16747 case Tag_ARC_ISA_mpy_option
:
16748 READ_ULEB (val
, p
, end
);
16749 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
16752 case Tag_ARC_ATR_version
:
16753 READ_ULEB (val
, p
, end
);
16754 printf (" Tag_ARC_ATR_version: %d\n", val
);
16758 return display_tag_value (tag
& 1, p
, end
);
16764 /* ARM EABI attributes section. */
16769 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
16771 const char *const *table
;
16772 } arm_attr_public_tag
;
16774 static const char *const arm_attr_tag_CPU_arch
[] =
16775 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
16776 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
16777 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
16778 "v8.1-M.mainline", "v9"};
16779 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
16780 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
16781 {"No", "Thumb-1", "Thumb-2", "Yes"};
16782 static const char *const arm_attr_tag_FP_arch
[] =
16783 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
16784 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
16785 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
16786 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
16787 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
16788 "NEON for ARMv8.1"};
16789 static const char *const arm_attr_tag_PCS_config
[] =
16790 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
16791 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
16792 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
16793 {"V6", "SB", "TLS", "Unused"};
16794 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
16795 {"Absolute", "PC-relative", "SB-relative", "None"};
16796 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
16797 {"Absolute", "PC-relative", "None"};
16798 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
16799 {"None", "direct", "GOT-indirect"};
16800 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
16801 {"None", "??? 1", "2", "??? 3", "4"};
16802 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
16803 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
16804 {"Unused", "Needed", "Sign only"};
16805 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
16806 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
16807 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
16808 {"Unused", "Finite", "RTABI", "IEEE 754"};
16809 static const char *const arm_attr_tag_ABI_enum_size
[] =
16810 {"Unused", "small", "int", "forced to int"};
16811 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
16812 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
16813 static const char *const arm_attr_tag_ABI_VFP_args
[] =
16814 {"AAPCS", "VFP registers", "custom", "compatible"};
16815 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
16816 {"AAPCS", "WMMX registers", "custom"};
16817 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
16818 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16819 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
16820 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
16821 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16822 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
16823 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
16824 static const char *const arm_attr_tag_FP_HP_extension
[] =
16825 {"Not Allowed", "Allowed"};
16826 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
16827 {"None", "IEEE 754", "Alternative Format"};
16828 static const char *const arm_attr_tag_DSP_extension
[] =
16829 {"Follow architecture", "Allowed"};
16830 static const char *const arm_attr_tag_MPextension_use
[] =
16831 {"Not Allowed", "Allowed"};
16832 static const char *const arm_attr_tag_DIV_use
[] =
16833 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
16834 "Allowed in v7-A with integer division extension"};
16835 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
16836 static const char *const arm_attr_tag_Virtualization_use
[] =
16837 {"Not Allowed", "TrustZone", "Virtualization Extensions",
16838 "TrustZone and Virtualization Extensions"};
16839 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
16840 {"Not Allowed", "Allowed"};
16842 static const char *const arm_attr_tag_MVE_arch
[] =
16843 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
16845 static const char * arm_attr_tag_PAC_extension
[] =
16846 {"No PAC/AUT instructions",
16847 "PAC/AUT instructions permitted in the NOP space",
16848 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
16850 static const char * arm_attr_tag_BTI_extension
[] =
16851 {"BTI instructions not permitted",
16852 "BTI instructions permitted in the NOP space",
16853 "BTI instructions permitted in the NOP and in the non-NOP space"};
16855 static const char * arm_attr_tag_BTI_use
[] =
16856 {"Compiled without branch target enforcement",
16857 "Compiled with branch target enforcement"};
16859 static const char * arm_attr_tag_PACRET_use
[] =
16860 {"Compiled without return address signing and authentication",
16861 "Compiled with return address signing and authentication"};
16863 #define LOOKUP(id, name) \
16864 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
16865 static arm_attr_public_tag arm_attr_public_tags
[] =
16867 {4, "CPU_raw_name", 1, NULL
},
16868 {5, "CPU_name", 1, NULL
},
16869 LOOKUP(6, CPU_arch
),
16870 {7, "CPU_arch_profile", 0, NULL
},
16871 LOOKUP(8, ARM_ISA_use
),
16872 LOOKUP(9, THUMB_ISA_use
),
16873 LOOKUP(10, FP_arch
),
16874 LOOKUP(11, WMMX_arch
),
16875 LOOKUP(12, Advanced_SIMD_arch
),
16876 LOOKUP(13, PCS_config
),
16877 LOOKUP(14, ABI_PCS_R9_use
),
16878 LOOKUP(15, ABI_PCS_RW_data
),
16879 LOOKUP(16, ABI_PCS_RO_data
),
16880 LOOKUP(17, ABI_PCS_GOT_use
),
16881 LOOKUP(18, ABI_PCS_wchar_t
),
16882 LOOKUP(19, ABI_FP_rounding
),
16883 LOOKUP(20, ABI_FP_denormal
),
16884 LOOKUP(21, ABI_FP_exceptions
),
16885 LOOKUP(22, ABI_FP_user_exceptions
),
16886 LOOKUP(23, ABI_FP_number_model
),
16887 {24, "ABI_align_needed", 0, NULL
},
16888 {25, "ABI_align_preserved", 0, NULL
},
16889 LOOKUP(26, ABI_enum_size
),
16890 LOOKUP(27, ABI_HardFP_use
),
16891 LOOKUP(28, ABI_VFP_args
),
16892 LOOKUP(29, ABI_WMMX_args
),
16893 LOOKUP(30, ABI_optimization_goals
),
16894 LOOKUP(31, ABI_FP_optimization_goals
),
16895 {32, "compatibility", 0, NULL
},
16896 LOOKUP(34, CPU_unaligned_access
),
16897 LOOKUP(36, FP_HP_extension
),
16898 LOOKUP(38, ABI_FP_16bit_format
),
16899 LOOKUP(42, MPextension_use
),
16900 LOOKUP(44, DIV_use
),
16901 LOOKUP(46, DSP_extension
),
16902 LOOKUP(48, MVE_arch
),
16903 LOOKUP(50, PAC_extension
),
16904 LOOKUP(52, BTI_extension
),
16905 LOOKUP(74, BTI_use
),
16906 LOOKUP(76, PACRET_use
),
16907 {64, "nodefaults", 0, NULL
},
16908 {65, "also_compatible_with", 0, NULL
},
16909 LOOKUP(66, T2EE_use
),
16910 {67, "conformance", 1, NULL
},
16911 LOOKUP(68, Virtualization_use
),
16912 LOOKUP(70, MPextension_use_legacy
)
16916 static unsigned char *
16917 display_arm_attribute (unsigned char * p
,
16918 const unsigned char * const end
)
16922 arm_attr_public_tag
* attr
;
16926 READ_ULEB (tag
, p
, end
);
16928 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
16930 if (arm_attr_public_tags
[i
].tag
== tag
)
16932 attr
= &arm_attr_public_tags
[i
];
16939 printf (" Tag_%s: ", attr
->name
);
16940 switch (attr
->type
)
16945 case 7: /* Tag_CPU_arch_profile. */
16946 READ_ULEB (val
, p
, end
);
16949 case 0: printf (_("None\n")); break;
16950 case 'A': printf (_("Application\n")); break;
16951 case 'R': printf (_("Realtime\n")); break;
16952 case 'M': printf (_("Microcontroller\n")); break;
16953 case 'S': printf (_("Application or Realtime\n")); break;
16954 default: printf ("??? (%d)\n", val
); break;
16958 case 24: /* Tag_align_needed. */
16959 READ_ULEB (val
, p
, end
);
16962 case 0: printf (_("None\n")); break;
16963 case 1: printf (_("8-byte\n")); break;
16964 case 2: printf (_("4-byte\n")); break;
16965 case 3: printf ("??? 3\n"); break;
16968 printf (_("8-byte and up to %d-byte extended\n"),
16971 printf ("??? (%d)\n", val
);
16976 case 25: /* Tag_align_preserved. */
16977 READ_ULEB (val
, p
, end
);
16980 case 0: printf (_("None\n")); break;
16981 case 1: printf (_("8-byte, except leaf SP\n")); break;
16982 case 2: printf (_("8-byte\n")); break;
16983 case 3: printf ("??? 3\n"); break;
16986 printf (_("8-byte and up to %d-byte extended\n"),
16989 printf ("??? (%d)\n", val
);
16994 case 32: /* Tag_compatibility. */
16996 READ_ULEB (val
, p
, end
);
16997 printf (_("flag = %d, vendor = "), val
);
17000 size_t maxlen
= (end
- p
) - 1;
17002 print_symbol ((int) maxlen
, (const char *) p
);
17003 p
+= strnlen ((char *) p
, maxlen
) + 1;
17007 printf (_("<corrupt>"));
17008 p
= (unsigned char *) end
;
17014 case 64: /* Tag_nodefaults. */
17015 /* PR 17531: file: 001-505008-0.01. */
17018 printf (_("True\n"));
17021 case 65: /* Tag_also_compatible_with. */
17022 READ_ULEB (val
, p
, end
);
17023 if (val
== 6 /* Tag_CPU_arch. */)
17025 READ_ULEB (val
, p
, end
);
17026 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
17027 printf ("??? (%d)\n", val
);
17029 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
17033 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
17038 printf (_("<unknown: %d>\n"), tag
);
17044 return display_tag_value (-1, p
, end
);
17046 return display_tag_value (0, p
, end
);
17049 assert (attr
->type
& 0x80);
17050 READ_ULEB (val
, p
, end
);
17051 type
= attr
->type
& 0x7f;
17053 printf ("??? (%d)\n", val
);
17055 printf ("%s\n", attr
->table
[val
]);
17060 return display_tag_value (tag
, p
, end
);
17063 static unsigned char *
17064 display_gnu_attribute (unsigned char * p
,
17065 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
17066 const unsigned char * const end
)
17071 READ_ULEB (tag
, p
, end
);
17073 /* Tag_compatibility is the only generic GNU attribute defined at
17077 READ_ULEB (val
, p
, end
);
17079 printf (_("flag = %d, vendor = "), val
);
17082 printf (_("<corrupt>\n"));
17083 warn (_("corrupt vendor attribute\n"));
17089 size_t maxlen
= (end
- p
) - 1;
17091 print_symbol ((int) maxlen
, (const char *) p
);
17092 p
+= strnlen ((char *) p
, maxlen
) + 1;
17096 printf (_("<corrupt>"));
17097 p
= (unsigned char *) end
;
17104 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
17105 return display_proc_gnu_attribute (p
, tag
, end
);
17107 return display_tag_value (tag
, p
, end
);
17110 static unsigned char *
17111 display_m68k_gnu_attribute (unsigned char * p
,
17113 const unsigned char * const end
)
17117 if (tag
== Tag_GNU_M68K_ABI_FP
)
17119 printf (" Tag_GNU_M68K_ABI_FP: ");
17122 printf (_("<corrupt>\n"));
17125 READ_ULEB (val
, p
, end
);
17128 printf ("(%#x), ", val
);
17133 printf (_("unspecified hard/soft float\n"));
17136 printf (_("hard float\n"));
17139 printf (_("soft float\n"));
17145 return display_tag_value (tag
& 1, p
, end
);
17148 static unsigned char *
17149 display_power_gnu_attribute (unsigned char * p
,
17151 const unsigned char * const end
)
17155 if (tag
== Tag_GNU_Power_ABI_FP
)
17157 printf (" Tag_GNU_Power_ABI_FP: ");
17160 printf (_("<corrupt>\n"));
17163 READ_ULEB (val
, p
, end
);
17166 printf ("(%#x), ", val
);
17171 printf (_("unspecified hard/soft float, "));
17174 printf (_("hard float, "));
17177 printf (_("soft float, "));
17180 printf (_("single-precision hard float, "));
17187 printf (_("unspecified long double\n"));
17190 printf (_("128-bit IBM long double\n"));
17193 printf (_("64-bit long double\n"));
17196 printf (_("128-bit IEEE long double\n"));
17202 if (tag
== Tag_GNU_Power_ABI_Vector
)
17204 printf (" Tag_GNU_Power_ABI_Vector: ");
17207 printf (_("<corrupt>\n"));
17210 READ_ULEB (val
, p
, end
);
17213 printf ("(%#x), ", val
);
17218 printf (_("unspecified\n"));
17221 printf (_("generic\n"));
17224 printf ("AltiVec\n");
17233 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
17235 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
17238 printf (_("<corrupt>\n"));
17241 READ_ULEB (val
, p
, end
);
17244 printf ("(%#x), ", val
);
17249 printf (_("unspecified\n"));
17252 printf ("r3/r4\n");
17255 printf (_("memory\n"));
17264 return display_tag_value (tag
& 1, p
, end
);
17267 static unsigned char *
17268 display_s390_gnu_attribute (unsigned char * p
,
17270 const unsigned char * const end
)
17274 if (tag
== Tag_GNU_S390_ABI_Vector
)
17276 printf (" Tag_GNU_S390_ABI_Vector: ");
17277 READ_ULEB (val
, p
, end
);
17282 printf (_("any\n"));
17285 printf (_("software\n"));
17288 printf (_("hardware\n"));
17291 printf ("??? (%d)\n", val
);
17297 return display_tag_value (tag
& 1, p
, end
);
17301 display_sparc_hwcaps (unsigned int mask
)
17307 if (mask
& ELF_SPARC_HWCAP_MUL32
)
17308 fputs ("mul32", stdout
), first
= false;
17309 if (mask
& ELF_SPARC_HWCAP_DIV32
)
17310 printf ("%sdiv32", first
? "" : "|"), first
= false;
17311 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
17312 printf ("%sfsmuld", first
? "" : "|"), first
= false;
17313 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
17314 printf ("%sv8plus", first
? "" : "|"), first
= false;
17315 if (mask
& ELF_SPARC_HWCAP_POPC
)
17316 printf ("%spopc", first
? "" : "|"), first
= false;
17317 if (mask
& ELF_SPARC_HWCAP_VIS
)
17318 printf ("%svis", first
? "" : "|"), first
= false;
17319 if (mask
& ELF_SPARC_HWCAP_VIS2
)
17320 printf ("%svis2", first
? "" : "|"), first
= false;
17321 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
17322 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
17323 if (mask
& ELF_SPARC_HWCAP_FMAF
)
17324 printf ("%sfmaf", first
? "" : "|"), first
= false;
17325 if (mask
& ELF_SPARC_HWCAP_VIS3
)
17326 printf ("%svis3", first
? "" : "|"), first
= false;
17327 if (mask
& ELF_SPARC_HWCAP_HPC
)
17328 printf ("%shpc", first
? "" : "|"), first
= false;
17329 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
17330 printf ("%srandom", first
? "" : "|"), first
= false;
17331 if (mask
& ELF_SPARC_HWCAP_TRANS
)
17332 printf ("%strans", first
? "" : "|"), first
= false;
17333 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
17334 printf ("%sfjfmau", first
? "" : "|"), first
= false;
17335 if (mask
& ELF_SPARC_HWCAP_IMA
)
17336 printf ("%sima", first
? "" : "|"), first
= false;
17337 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
17338 printf ("%scspare", first
? "" : "|"), first
= false;
17341 fputc ('0', stdout
);
17342 fputc ('\n', stdout
);
17346 display_sparc_hwcaps2 (unsigned int mask
)
17352 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
17353 fputs ("fjathplus", stdout
), first
= false;
17354 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
17355 printf ("%svis3b", first
? "" : "|"), first
= false;
17356 if (mask
& ELF_SPARC_HWCAP2_ADP
)
17357 printf ("%sadp", first
? "" : "|"), first
= false;
17358 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
17359 printf ("%ssparc5", first
? "" : "|"), first
= false;
17360 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
17361 printf ("%smwait", first
? "" : "|"), first
= false;
17362 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
17363 printf ("%sxmpmul", first
? "" : "|"), first
= false;
17364 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
17365 printf ("%sxmont2", first
? "" : "|"), first
= false;
17366 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
17367 printf ("%snsec", first
? "" : "|"), first
= false;
17368 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
17369 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
17370 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
17371 printf ("%sfjdes", first
? "" : "|"), first
= false;
17372 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
17373 printf ("%sfjaes", first
? "" : "|"), first
= false;
17376 fputc ('0', stdout
);
17377 fputc ('\n', stdout
);
17380 static unsigned char *
17381 display_sparc_gnu_attribute (unsigned char * p
,
17383 const unsigned char * const end
)
17387 if (tag
== Tag_GNU_Sparc_HWCAPS
)
17389 READ_ULEB (val
, p
, end
);
17390 printf (" Tag_GNU_Sparc_HWCAPS: ");
17391 display_sparc_hwcaps (val
);
17394 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
17396 READ_ULEB (val
, p
, end
);
17397 printf (" Tag_GNU_Sparc_HWCAPS2: ");
17398 display_sparc_hwcaps2 (val
);
17402 return display_tag_value (tag
, p
, end
);
17406 print_mips_fp_abi_value (unsigned int val
)
17410 case Val_GNU_MIPS_ABI_FP_ANY
:
17411 printf (_("Hard or soft float\n"));
17413 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
17414 printf (_("Hard float (double precision)\n"));
17416 case Val_GNU_MIPS_ABI_FP_SINGLE
:
17417 printf (_("Hard float (single precision)\n"));
17419 case Val_GNU_MIPS_ABI_FP_SOFT
:
17420 printf (_("Soft float\n"));
17422 case Val_GNU_MIPS_ABI_FP_OLD_64
:
17423 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
17425 case Val_GNU_MIPS_ABI_FP_XX
:
17426 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
17428 case Val_GNU_MIPS_ABI_FP_64
:
17429 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
17431 case Val_GNU_MIPS_ABI_FP_64A
:
17432 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
17434 case Val_GNU_MIPS_ABI_FP_NAN2008
:
17435 printf (_("NaN 2008 compatibility\n"));
17438 printf ("??? (%d)\n", val
);
17443 static unsigned char *
17444 display_mips_gnu_attribute (unsigned char * p
,
17446 const unsigned char * const end
)
17448 if (tag
== Tag_GNU_MIPS_ABI_FP
)
17452 printf (" Tag_GNU_MIPS_ABI_FP: ");
17453 READ_ULEB (val
, p
, end
);
17454 print_mips_fp_abi_value (val
);
17458 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
17462 printf (" Tag_GNU_MIPS_ABI_MSA: ");
17463 READ_ULEB (val
, p
, end
);
17467 case Val_GNU_MIPS_ABI_MSA_ANY
:
17468 printf (_("Any MSA or not\n"));
17470 case Val_GNU_MIPS_ABI_MSA_128
:
17471 printf (_("128-bit MSA\n"));
17474 printf ("??? (%d)\n", val
);
17480 return display_tag_value (tag
& 1, p
, end
);
17483 static unsigned char *
17484 display_tic6x_attribute (unsigned char * p
,
17485 const unsigned char * const end
)
17490 READ_ULEB (tag
, p
, end
);
17495 printf (" Tag_ISA: ");
17496 READ_ULEB (val
, p
, end
);
17500 case C6XABI_Tag_ISA_none
:
17501 printf (_("None\n"));
17503 case C6XABI_Tag_ISA_C62X
:
17506 case C6XABI_Tag_ISA_C67X
:
17509 case C6XABI_Tag_ISA_C67XP
:
17510 printf ("C67x+\n");
17512 case C6XABI_Tag_ISA_C64X
:
17515 case C6XABI_Tag_ISA_C64XP
:
17516 printf ("C64x+\n");
17518 case C6XABI_Tag_ISA_C674X
:
17519 printf ("C674x\n");
17522 printf ("??? (%d)\n", val
);
17527 case Tag_ABI_wchar_t
:
17528 printf (" Tag_ABI_wchar_t: ");
17529 READ_ULEB (val
, p
, end
);
17533 printf (_("Not used\n"));
17536 printf (_("2 bytes\n"));
17539 printf (_("4 bytes\n"));
17542 printf ("??? (%d)\n", val
);
17547 case Tag_ABI_stack_align_needed
:
17548 printf (" Tag_ABI_stack_align_needed: ");
17549 READ_ULEB (val
, p
, end
);
17553 printf (_("8-byte\n"));
17556 printf (_("16-byte\n"));
17559 printf ("??? (%d)\n", val
);
17564 case Tag_ABI_stack_align_preserved
:
17565 READ_ULEB (val
, p
, end
);
17566 printf (" Tag_ABI_stack_align_preserved: ");
17570 printf (_("8-byte\n"));
17573 printf (_("16-byte\n"));
17576 printf ("??? (%d)\n", val
);
17582 READ_ULEB (val
, p
, end
);
17583 printf (" Tag_ABI_DSBT: ");
17587 printf (_("DSBT addressing not used\n"));
17590 printf (_("DSBT addressing used\n"));
17593 printf ("??? (%d)\n", val
);
17599 READ_ULEB (val
, p
, end
);
17600 printf (" Tag_ABI_PID: ");
17604 printf (_("Data addressing position-dependent\n"));
17607 printf (_("Data addressing position-independent, GOT near DP\n"));
17610 printf (_("Data addressing position-independent, GOT far from DP\n"));
17613 printf ("??? (%d)\n", val
);
17619 READ_ULEB (val
, p
, end
);
17620 printf (" Tag_ABI_PIC: ");
17624 printf (_("Code addressing position-dependent\n"));
17627 printf (_("Code addressing position-independent\n"));
17630 printf ("??? (%d)\n", val
);
17635 case Tag_ABI_array_object_alignment
:
17636 READ_ULEB (val
, p
, end
);
17637 printf (" Tag_ABI_array_object_alignment: ");
17641 printf (_("8-byte\n"));
17644 printf (_("4-byte\n"));
17647 printf (_("16-byte\n"));
17650 printf ("??? (%d)\n", val
);
17655 case Tag_ABI_array_object_align_expected
:
17656 READ_ULEB (val
, p
, end
);
17657 printf (" Tag_ABI_array_object_align_expected: ");
17661 printf (_("8-byte\n"));
17664 printf (_("4-byte\n"));
17667 printf (_("16-byte\n"));
17670 printf ("??? (%d)\n", val
);
17675 case Tag_ABI_compatibility
:
17677 READ_ULEB (val
, p
, end
);
17678 printf (" Tag_ABI_compatibility: ");
17679 printf (_("flag = %d, vendor = "), val
);
17682 size_t maxlen
= (end
- p
) - 1;
17684 print_symbol ((int) maxlen
, (const char *) p
);
17685 p
+= strnlen ((char *) p
, maxlen
) + 1;
17689 printf (_("<corrupt>"));
17690 p
= (unsigned char *) end
;
17696 case Tag_ABI_conformance
:
17698 printf (" Tag_ABI_conformance: \"");
17701 size_t maxlen
= (end
- p
) - 1;
17703 print_symbol ((int) maxlen
, (const char *) p
);
17704 p
+= strnlen ((char *) p
, maxlen
) + 1;
17708 printf (_("<corrupt>"));
17709 p
= (unsigned char *) end
;
17716 return display_tag_value (tag
, p
, end
);
17720 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
17723 size_t bytes
= end
- p
;
17730 int lbytes
= (bytes
> 16 ? 16 : bytes
);
17732 printf (" 0x%8.8" PRIx64
" ", addr
);
17734 for (j
= 0; j
< 16; j
++)
17737 printf ("%2.2x", p
[j
]);
17745 for (j
= 0; j
< lbytes
; j
++)
17748 if (k
>= ' ' && k
< 0x7f)
17764 static unsigned char *
17765 display_msp430_attribute (unsigned char * p
,
17766 const unsigned char * const end
)
17771 READ_ULEB (tag
, p
, end
);
17775 case OFBA_MSPABI_Tag_ISA
:
17776 printf (" Tag_ISA: ");
17777 READ_ULEB (val
, p
, end
);
17780 case 0: printf (_("None\n")); break;
17781 case 1: printf (_("MSP430\n")); break;
17782 case 2: printf (_("MSP430X\n")); break;
17783 default: printf ("??? (%" PRId64
")\n", val
); break;
17787 case OFBA_MSPABI_Tag_Code_Model
:
17788 printf (" Tag_Code_Model: ");
17789 READ_ULEB (val
, p
, end
);
17792 case 0: printf (_("None\n")); break;
17793 case 1: printf (_("Small\n")); break;
17794 case 2: printf (_("Large\n")); break;
17795 default: printf ("??? (%" PRId64
")\n", val
); break;
17799 case OFBA_MSPABI_Tag_Data_Model
:
17800 printf (" Tag_Data_Model: ");
17801 READ_ULEB (val
, p
, end
);
17804 case 0: printf (_("None\n")); break;
17805 case 1: printf (_("Small\n")); break;
17806 case 2: printf (_("Large\n")); break;
17807 case 3: printf (_("Restricted Large\n")); break;
17808 default: printf ("??? (%" PRId64
")\n", val
); break;
17813 printf (_(" <unknown tag %" PRId64
">: "), tag
);
17820 size_t maxlen
= (end
- p
) - 1;
17822 print_symbol ((int) maxlen
, (const char *) p
);
17823 p
+= strnlen ((char *) p
, maxlen
) + 1;
17827 printf (_("<corrupt>"));
17828 p
= (unsigned char *) end
;
17834 READ_ULEB (val
, p
, end
);
17835 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
17844 static unsigned char *
17845 display_msp430_gnu_attribute (unsigned char * p
,
17847 const unsigned char * const end
)
17849 if (tag
== Tag_GNU_MSP430_Data_Region
)
17853 printf (" Tag_GNU_MSP430_Data_Region: ");
17854 READ_ULEB (val
, p
, end
);
17858 case Val_GNU_MSP430_Data_Region_Any
:
17859 printf (_("Any Region\n"));
17861 case Val_GNU_MSP430_Data_Region_Lower
:
17862 printf (_("Lower Region Only\n"));
17865 printf ("??? (%" PRIu64
")\n", val
);
17869 return display_tag_value (tag
& 1, p
, end
);
17872 struct riscv_attr_tag_t
{
17877 static struct riscv_attr_tag_t riscv_attr_tag
[] =
17879 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
17882 T(priv_spec_minor
),
17883 T(priv_spec_revision
),
17884 T(unaligned_access
),
17889 static unsigned char *
17890 display_riscv_attribute (unsigned char *p
,
17891 const unsigned char * const end
)
17895 struct riscv_attr_tag_t
*attr
= NULL
;
17898 READ_ULEB (tag
, p
, end
);
17900 /* Find the name of attribute. */
17901 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
17903 if (riscv_attr_tag
[i
].tag
== tag
)
17905 attr
= &riscv_attr_tag
[i
];
17911 printf (" %s: ", attr
->name
);
17913 return display_tag_value (tag
, p
, end
);
17917 case Tag_RISCV_priv_spec
:
17918 case Tag_RISCV_priv_spec_minor
:
17919 case Tag_RISCV_priv_spec_revision
:
17920 READ_ULEB (val
, p
, end
);
17921 printf ("%" PRIu64
"\n", val
);
17923 case Tag_RISCV_unaligned_access
:
17924 READ_ULEB (val
, p
, end
);
17928 printf (_("No unaligned access\n"));
17931 printf (_("Unaligned access\n"));
17935 case Tag_RISCV_stack_align
:
17936 READ_ULEB (val
, p
, end
);
17937 printf (_("%" PRIu64
"-bytes\n"), val
);
17939 case Tag_RISCV_arch
:
17940 p
= display_tag_value (-1, p
, end
);
17943 return display_tag_value (tag
, p
, end
);
17949 static unsigned char *
17950 display_csky_attribute (unsigned char * p
,
17951 const unsigned char * const end
)
17955 READ_ULEB (tag
, p
, end
);
17957 if (tag
>= Tag_CSKY_MAX
)
17959 return display_tag_value (-1, p
, end
);
17964 case Tag_CSKY_ARCH_NAME
:
17965 printf (" Tag_CSKY_ARCH_NAME:\t\t");
17966 return display_tag_value (-1, p
, end
);
17967 case Tag_CSKY_CPU_NAME
:
17968 printf (" Tag_CSKY_CPU_NAME:\t\t");
17969 return display_tag_value (-1, p
, end
);
17971 case Tag_CSKY_ISA_FLAGS
:
17972 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
17973 return display_tag_value (0, p
, end
);
17974 case Tag_CSKY_ISA_EXT_FLAGS
:
17975 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
17976 return display_tag_value (0, p
, end
);
17978 case Tag_CSKY_DSP_VERSION
:
17979 printf (" Tag_CSKY_DSP_VERSION:\t\t");
17980 READ_ULEB (val
, p
, end
);
17981 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
17982 printf ("DSP Extension\n");
17983 else if (val
== VAL_CSKY_DSP_VERSION_2
)
17984 printf ("DSP 2.0\n");
17987 case Tag_CSKY_VDSP_VERSION
:
17988 printf (" Tag_CSKY_VDSP_VERSION:\t");
17989 READ_ULEB (val
, p
, end
);
17990 printf ("VDSP Version %" PRId64
"\n", val
);
17993 case Tag_CSKY_FPU_VERSION
:
17994 printf (" Tag_CSKY_FPU_VERSION:\t\t");
17995 READ_ULEB (val
, p
, end
);
17996 if (val
== VAL_CSKY_FPU_VERSION_1
)
17997 printf ("ABIV1 FPU Version 1\n");
17998 else if (val
== VAL_CSKY_FPU_VERSION_2
)
17999 printf ("FPU Version 2\n");
18002 case Tag_CSKY_FPU_ABI
:
18003 printf (" Tag_CSKY_FPU_ABI:\t\t");
18004 READ_ULEB (val
, p
, end
);
18005 if (val
== VAL_CSKY_FPU_ABI_HARD
)
18007 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
18008 printf ("SoftFP\n");
18009 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
18012 case Tag_CSKY_FPU_ROUNDING
:
18013 READ_ULEB (val
, p
, end
);
18016 printf (" Tag_CSKY_FPU_ROUNDING:\t");
18017 printf ("Needed\n");
18020 case Tag_CSKY_FPU_DENORMAL
:
18021 READ_ULEB (val
, p
, end
);
18024 printf (" Tag_CSKY_FPU_DENORMAL:\t");
18025 printf ("Needed\n");
18028 case Tag_CSKY_FPU_Exception
:
18029 READ_ULEB (val
, p
, end
);
18032 printf (" Tag_CSKY_FPU_Exception:\t");
18033 printf ("Needed\n");
18036 case Tag_CSKY_FPU_NUMBER_MODULE
:
18037 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
18038 return display_tag_value (-1, p
, end
);
18039 case Tag_CSKY_FPU_HARDFP
:
18040 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
18041 READ_ULEB (val
, p
, end
);
18042 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
18044 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
18045 printf (" Single");
18046 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
18047 printf (" Double");
18051 return display_tag_value (tag
, p
, end
);
18057 process_attributes (Filedata
* filedata
,
18058 const char * public_name
,
18059 unsigned int proc_type
,
18060 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
18061 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
18063 Elf_Internal_Shdr
* sect
;
18067 /* Find the section header so that we get the size. */
18068 for (i
= 0, sect
= filedata
->section_headers
;
18069 i
< filedata
->file_header
.e_shnum
;
18072 unsigned char * contents
;
18075 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
18078 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
18079 sect
->sh_size
, _("attributes"));
18080 if (contents
== NULL
)
18087 /* The first character is the version of the attributes.
18088 Currently only version 1, (aka 'A') is recognised here. */
18091 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
18096 uint64_t section_len
;
18098 section_len
= sect
->sh_size
- 1;
18101 while (section_len
> 0)
18104 unsigned int namelen
;
18105 bool public_section
;
18108 if (section_len
<= 4)
18110 error (_("Tag section ends prematurely\n"));
18114 attr_len
= byte_get (p
, 4);
18117 if (attr_len
> section_len
)
18119 error (_("Bad attribute length (%u > %u)\n"),
18120 (unsigned) attr_len
, (unsigned) section_len
);
18121 attr_len
= section_len
;
18124 /* PR 17531: file: 001-101425-0.004 */
18125 else if (attr_len
< 5)
18127 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
18132 section_len
-= attr_len
;
18135 namelen
= strnlen ((char *) p
, attr_len
) + 1;
18136 if (namelen
== 0 || namelen
>= attr_len
)
18138 error (_("Corrupt attribute section name\n"));
18143 printf (_("Attribute Section: "));
18144 print_symbol (INT_MAX
, (const char *) p
);
18147 if (public_name
&& streq ((char *) p
, public_name
))
18148 public_section
= true;
18150 public_section
= false;
18152 if (streq ((char *) p
, "gnu"))
18153 gnu_section
= true;
18155 gnu_section
= false;
18158 attr_len
-= namelen
;
18160 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
18165 unsigned char * end
;
18167 /* PR binutils/17531: Safe handling of corrupt files. */
18170 error (_("Unused bytes at end of section\n"));
18177 size
= byte_get (p
, 4);
18178 if (size
> attr_len
)
18180 error (_("Bad subsection length (%u > %u)\n"),
18181 (unsigned) size
, (unsigned) attr_len
);
18185 /* PR binutils/17531: Safe handling of corrupt files. */
18188 error (_("Bad subsection length (%u < 6)\n"),
18196 end
= p
+ size
- 1;
18197 assert (end
<= contents
+ sect
->sh_size
);
18203 printf (_("File Attributes\n"));
18206 printf (_("Section Attributes:"));
18209 printf (_("Symbol Attributes:"));
18210 /* Fall through. */
18214 READ_ULEB (val
, p
, end
);
18217 printf (" %d", val
);
18222 printf (_("Unknown tag: %d\n"), tag
);
18223 public_section
= false;
18227 if (public_section
&& display_pub_attribute
!= NULL
)
18230 p
= display_pub_attribute (p
, end
);
18233 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
18236 p
= display_gnu_attribute (p
,
18237 display_proc_gnu_attribute
,
18243 printf (_(" Unknown attribute:\n"));
18244 display_raw_attribute (p
, end
);
18259 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
18260 Print the Address, Access and Initial fields of an entry at VMA ADDR
18261 and return the VMA of the next entry, or -1 if there was a problem.
18262 Does not read from DATA_END or beyond. */
18265 print_mips_got_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
,
18266 unsigned char * data_end
)
18269 print_vma (addr
, LONG_HEX
);
18271 if (addr
< pltgot
+ 0xfff0)
18272 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
18274 printf ("%10s", "");
18277 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18281 unsigned char * from
= data
+ addr
- pltgot
;
18283 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
18285 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
18286 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
18287 return (uint64_t) -1;
18291 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18292 print_vma (entry
, LONG_HEX
);
18295 return addr
+ (is_32bit_elf
? 4 : 8);
18298 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
18299 PLTGOT. Print the Address and Initial fields of an entry at VMA
18300 ADDR and return the VMA of the next entry. */
18303 print_mips_pltgot_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
)
18306 print_vma (addr
, LONG_HEX
);
18309 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18314 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18315 print_vma (entry
, LONG_HEX
);
18317 return addr
+ (is_32bit_elf
? 4 : 8);
18321 print_mips_ases (unsigned int mask
)
18323 if (mask
& AFL_ASE_DSP
)
18324 fputs ("\n\tDSP ASE", stdout
);
18325 if (mask
& AFL_ASE_DSPR2
)
18326 fputs ("\n\tDSP R2 ASE", stdout
);
18327 if (mask
& AFL_ASE_DSPR3
)
18328 fputs ("\n\tDSP R3 ASE", stdout
);
18329 if (mask
& AFL_ASE_EVA
)
18330 fputs ("\n\tEnhanced VA Scheme", stdout
);
18331 if (mask
& AFL_ASE_MCU
)
18332 fputs ("\n\tMCU (MicroController) ASE", stdout
);
18333 if (mask
& AFL_ASE_MDMX
)
18334 fputs ("\n\tMDMX ASE", stdout
);
18335 if (mask
& AFL_ASE_MIPS3D
)
18336 fputs ("\n\tMIPS-3D ASE", stdout
);
18337 if (mask
& AFL_ASE_MT
)
18338 fputs ("\n\tMT ASE", stdout
);
18339 if (mask
& AFL_ASE_SMARTMIPS
)
18340 fputs ("\n\tSmartMIPS ASE", stdout
);
18341 if (mask
& AFL_ASE_VIRT
)
18342 fputs ("\n\tVZ ASE", stdout
);
18343 if (mask
& AFL_ASE_MSA
)
18344 fputs ("\n\tMSA ASE", stdout
);
18345 if (mask
& AFL_ASE_MIPS16
)
18346 fputs ("\n\tMIPS16 ASE", stdout
);
18347 if (mask
& AFL_ASE_MICROMIPS
)
18348 fputs ("\n\tMICROMIPS ASE", stdout
);
18349 if (mask
& AFL_ASE_XPA
)
18350 fputs ("\n\tXPA ASE", stdout
);
18351 if (mask
& AFL_ASE_MIPS16E2
)
18352 fputs ("\n\tMIPS16e2 ASE", stdout
);
18353 if (mask
& AFL_ASE_CRC
)
18354 fputs ("\n\tCRC ASE", stdout
);
18355 if (mask
& AFL_ASE_GINV
)
18356 fputs ("\n\tGINV ASE", stdout
);
18357 if (mask
& AFL_ASE_LOONGSON_MMI
)
18358 fputs ("\n\tLoongson MMI ASE", stdout
);
18359 if (mask
& AFL_ASE_LOONGSON_CAM
)
18360 fputs ("\n\tLoongson CAM ASE", stdout
);
18361 if (mask
& AFL_ASE_LOONGSON_EXT
)
18362 fputs ("\n\tLoongson EXT ASE", stdout
);
18363 if (mask
& AFL_ASE_LOONGSON_EXT2
)
18364 fputs ("\n\tLoongson EXT2 ASE", stdout
);
18366 fprintf (stdout
, "\n\t%s", _("None"));
18367 else if ((mask
& ~AFL_ASE_MASK
) != 0)
18368 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
18372 print_mips_isa_ext (unsigned int isa_ext
)
18377 fputs (_("None"), stdout
);
18380 fputs ("RMI XLR", stdout
);
18382 case AFL_EXT_OCTEON3
:
18383 fputs ("Cavium Networks Octeon3", stdout
);
18385 case AFL_EXT_OCTEON2
:
18386 fputs ("Cavium Networks Octeon2", stdout
);
18388 case AFL_EXT_OCTEONP
:
18389 fputs ("Cavium Networks OcteonP", stdout
);
18391 case AFL_EXT_OCTEON
:
18392 fputs ("Cavium Networks Octeon", stdout
);
18395 fputs ("Toshiba R5900", stdout
);
18398 fputs ("MIPS R4650", stdout
);
18401 fputs ("LSI R4010", stdout
);
18404 fputs ("NEC VR4100", stdout
);
18407 fputs ("Toshiba R3900", stdout
);
18409 case AFL_EXT_10000
:
18410 fputs ("MIPS R10000", stdout
);
18413 fputs ("Broadcom SB-1", stdout
);
18416 fputs ("NEC VR4111/VR4181", stdout
);
18419 fputs ("NEC VR4120", stdout
);
18422 fputs ("NEC VR5400", stdout
);
18425 fputs ("NEC VR5500", stdout
);
18427 case AFL_EXT_LOONGSON_2E
:
18428 fputs ("ST Microelectronics Loongson 2E", stdout
);
18430 case AFL_EXT_LOONGSON_2F
:
18431 fputs ("ST Microelectronics Loongson 2F", stdout
);
18433 case AFL_EXT_INTERAPTIV_MR2
:
18434 fputs ("Imagination interAptiv MR2", stdout
);
18437 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
18442 get_mips_reg_size (int reg_size
)
18444 return (reg_size
== AFL_REG_NONE
) ? 0
18445 : (reg_size
== AFL_REG_32
) ? 32
18446 : (reg_size
== AFL_REG_64
) ? 64
18447 : (reg_size
== AFL_REG_128
) ? 128
18452 process_mips_specific (Filedata
* filedata
)
18454 Elf_Internal_Dyn
* entry
;
18455 Elf_Internal_Shdr
*sect
= NULL
;
18456 size_t liblist_offset
= 0;
18457 size_t liblistno
= 0;
18458 size_t conflictsno
= 0;
18459 size_t options_offset
= 0;
18460 size_t conflicts_offset
= 0;
18461 size_t pltrelsz
= 0;
18463 uint64_t pltgot
= 0;
18464 uint64_t mips_pltgot
= 0;
18465 uint64_t jmprel
= 0;
18466 uint64_t local_gotno
= 0;
18467 uint64_t gotsym
= 0;
18468 uint64_t symtabno
= 0;
18471 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
18472 display_mips_gnu_attribute
))
18475 sect
= find_section (filedata
, ".MIPS.abiflags");
18479 Elf_External_ABIFlags_v0
*abiflags_ext
;
18480 Elf_Internal_ABIFlags_v0 abiflags_in
;
18482 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
18484 error (_("Corrupt MIPS ABI Flags section.\n"));
18489 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
18490 sect
->sh_size
, _("MIPS ABI Flags section"));
18493 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
18494 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
18495 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
18496 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
18497 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
18498 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
18499 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
18500 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
18501 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
18502 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
18503 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
18505 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
18506 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
18507 if (abiflags_in
.isa_rev
> 1)
18508 printf ("r%d", abiflags_in
.isa_rev
);
18509 printf ("\nGPR size: %d",
18510 get_mips_reg_size (abiflags_in
.gpr_size
));
18511 printf ("\nCPR1 size: %d",
18512 get_mips_reg_size (abiflags_in
.cpr1_size
));
18513 printf ("\nCPR2 size: %d",
18514 get_mips_reg_size (abiflags_in
.cpr2_size
));
18515 fputs ("\nFP ABI: ", stdout
);
18516 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
18517 fputs ("ISA Extension: ", stdout
);
18518 print_mips_isa_ext (abiflags_in
.isa_ext
);
18519 fputs ("\nASEs:", stdout
);
18520 print_mips_ases (abiflags_in
.ases
);
18521 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
18522 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
18523 fputc ('\n', stdout
);
18524 free (abiflags_ext
);
18529 /* We have a lot of special sections. Thanks SGI! */
18530 if (filedata
->dynamic_section
== NULL
)
18532 /* No dynamic information available. See if there is static GOT. */
18533 sect
= find_section (filedata
, ".got");
18536 unsigned char *data_end
;
18537 unsigned char *data
;
18541 pltgot
= sect
->sh_addr
;
18544 addr_size
= (is_32bit_elf
? 4 : 8);
18545 end
= pltgot
+ sect
->sh_size
;
18547 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
18549 _("Global Offset Table data"));
18550 /* PR 12855: Null data is handled gracefully throughout. */
18551 data_end
= data
+ (end
- pltgot
);
18553 printf (_("\nStatic GOT:\n"));
18554 printf (_(" Canonical gp value: "));
18555 print_vma (ent
+ 0x7ff0, LONG_HEX
);
18558 /* In a dynamic binary GOT[0] is reserved for the dynamic
18559 loader to store the lazy resolver pointer, however in
18560 a static binary it may well have been omitted and GOT
18561 reduced to a table of addresses.
18562 PR 21344: Check for the entry being fully available
18563 before fetching it. */
18565 && data
+ ent
- pltgot
+ addr_size
<= data_end
18566 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
18568 printf (_(" Reserved entries:\n"));
18569 printf (_(" %*s %10s %*s\n"),
18570 addr_size
* 2, _("Address"), _("Access"),
18571 addr_size
* 2, _("Value"));
18572 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18574 if (ent
== (uint64_t) -1)
18575 goto sgot_print_fail
;
18577 /* Check for the MSB of GOT[1] being set, identifying a
18578 GNU object. This entry will be used by some runtime
18579 loaders, to store the module pointer. Otherwise this
18580 is an ordinary local entry.
18581 PR 21344: Check for the entry being fully available
18582 before fetching it. */
18584 && data
+ ent
- pltgot
+ addr_size
<= data_end
18585 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18586 >> (addr_size
* 8 - 1)) != 0)
18588 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18590 if (ent
== (uint64_t) -1)
18591 goto sgot_print_fail
;
18596 if (data
!= NULL
&& ent
< end
)
18598 printf (_(" Local entries:\n"));
18599 printf (" %*s %10s %*s\n",
18600 addr_size
* 2, _("Address"), _("Access"),
18601 addr_size
* 2, _("Value"));
18604 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18606 if (ent
== (uint64_t) -1)
18607 goto sgot_print_fail
;
18618 for (entry
= filedata
->dynamic_section
;
18619 /* PR 17531 file: 012-50589-0.004. */
18620 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
18621 && entry
->d_tag
!= DT_NULL
);
18623 switch (entry
->d_tag
)
18625 case DT_MIPS_LIBLIST
:
18627 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
18628 liblistno
* sizeof (Elf32_External_Lib
));
18630 case DT_MIPS_LIBLISTNO
:
18631 liblistno
= entry
->d_un
.d_val
;
18633 case DT_MIPS_OPTIONS
:
18634 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
18636 case DT_MIPS_CONFLICT
:
18638 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
18639 conflictsno
* sizeof (Elf32_External_Conflict
));
18641 case DT_MIPS_CONFLICTNO
:
18642 conflictsno
= entry
->d_un
.d_val
;
18645 pltgot
= entry
->d_un
.d_ptr
;
18647 case DT_MIPS_LOCAL_GOTNO
:
18648 local_gotno
= entry
->d_un
.d_val
;
18650 case DT_MIPS_GOTSYM
:
18651 gotsym
= entry
->d_un
.d_val
;
18653 case DT_MIPS_SYMTABNO
:
18654 symtabno
= entry
->d_un
.d_val
;
18656 case DT_MIPS_PLTGOT
:
18657 mips_pltgot
= entry
->d_un
.d_ptr
;
18660 pltrel
= entry
->d_un
.d_val
;
18663 pltrelsz
= entry
->d_un
.d_val
;
18666 jmprel
= entry
->d_un
.d_ptr
;
18672 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
18674 Elf32_External_Lib
* elib
;
18677 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
18678 sizeof (Elf32_External_Lib
),
18680 _("liblist section data"));
18683 printf (ngettext ("\nSection '.liblist' contains %zu entry:\n",
18684 "\nSection '.liblist' contains %zu entries:\n",
18687 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
18690 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
18697 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18698 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18699 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18700 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18701 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18703 tmp
= gmtime (&atime
);
18704 snprintf (timebuf
, sizeof (timebuf
),
18705 "%04u-%02u-%02uT%02u:%02u:%02u",
18706 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18707 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18709 printf ("%3zu: ", cnt
);
18710 if (valid_dynamic_name (filedata
, liblist
.l_name
))
18711 print_symbol (20, get_dynamic_name (filedata
, liblist
.l_name
));
18713 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
18714 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
18715 liblist
.l_version
);
18717 if (liblist
.l_flags
== 0)
18721 static const struct
18728 { " EXACT_MATCH", LL_EXACT_MATCH
},
18729 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
18730 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
18731 { " EXPORTS", LL_EXPORTS
},
18732 { " DELAY_LOAD", LL_DELAY_LOAD
},
18733 { " DELTA", LL_DELTA
}
18735 int flags
= liblist
.l_flags
;
18738 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
18739 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
18741 fputs (l_flags_vals
[fcnt
].name
, stdout
);
18742 flags
^= l_flags_vals
[fcnt
].bit
;
18745 printf (" %#x", (unsigned int) flags
);
18757 if (options_offset
!= 0)
18759 Elf_External_Options
* eopt
;
18763 /* Find the section header so that we get the size. */
18764 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
18765 /* PR 17533 file: 012-277276-0.004. */
18768 error (_("No MIPS_OPTIONS header found\n"));
18772 if (sect
->sh_size
< sizeof (* eopt
))
18774 error (_("The MIPS options section is too small.\n"));
18778 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
18779 sect
->sh_size
, _("options"));
18782 Elf_Internal_Options option
;
18785 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
18787 Elf_External_Options
* eoption
;
18788 unsigned int optsize
;
18790 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18792 optsize
= BYTE_GET (eoption
->size
);
18794 /* PR 17531: file: ffa0fa3b. */
18795 if (optsize
< sizeof (* eopt
)
18796 || optsize
> sect
->sh_size
- offset
)
18798 error (_("Invalid size (%u) for MIPS option\n"),
18807 printf (ngettext ("\nSection '%s' contains %d entry:\n",
18808 "\nSection '%s' contains %d entries:\n",
18810 printable_section_name (filedata
, sect
), cnt
);
18816 Elf_External_Options
* eoption
;
18818 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18820 option
.kind
= BYTE_GET (eoption
->kind
);
18821 option
.size
= BYTE_GET (eoption
->size
);
18822 option
.section
= BYTE_GET (eoption
->section
);
18823 option
.info
= BYTE_GET (eoption
->info
);
18825 switch (option
.kind
)
18828 /* This shouldn't happen. */
18829 printf (" NULL %" PRId16
" %" PRIx32
,
18830 option
.section
, option
.info
);
18834 printf (" REGINFO ");
18835 if (filedata
->file_header
.e_machine
== EM_MIPS
)
18837 Elf32_External_RegInfo
* ereg
;
18838 Elf32_RegInfo reginfo
;
18841 if (option
.size
< (sizeof (Elf_External_Options
)
18842 + sizeof (Elf32_External_RegInfo
)))
18844 printf (_("<corrupt>\n"));
18845 error (_("Truncated MIPS REGINFO option\n"));
18850 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
18852 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18853 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18854 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18855 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18856 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18857 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18859 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
18860 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18862 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18863 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18864 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18865 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18870 Elf64_External_RegInfo
* ereg
;
18871 Elf64_Internal_RegInfo reginfo
;
18873 if (option
.size
< (sizeof (Elf_External_Options
)
18874 + sizeof (Elf64_External_RegInfo
)))
18876 printf (_("<corrupt>\n"));
18877 error (_("Truncated MIPS REGINFO option\n"));
18882 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
18883 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18884 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18885 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18886 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18887 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18888 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18890 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
18891 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18893 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18894 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18895 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18896 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18898 offset
+= option
.size
;
18901 case ODK_EXCEPTIONS
:
18902 fputs (" EXCEPTIONS fpe_min(", stdout
);
18903 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
18904 fputs (") fpe_max(", stdout
);
18905 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
18906 fputs (")", stdout
);
18908 if (option
.info
& OEX_PAGE0
)
18909 fputs (" PAGE0", stdout
);
18910 if (option
.info
& OEX_SMM
)
18911 fputs (" SMM", stdout
);
18912 if (option
.info
& OEX_FPDBUG
)
18913 fputs (" FPDBUG", stdout
);
18914 if (option
.info
& OEX_DISMISS
)
18915 fputs (" DISMISS", stdout
);
18919 fputs (" PAD ", stdout
);
18920 if (option
.info
& OPAD_PREFIX
)
18921 fputs (" PREFIX", stdout
);
18922 if (option
.info
& OPAD_POSTFIX
)
18923 fputs (" POSTFIX", stdout
);
18924 if (option
.info
& OPAD_SYMBOL
)
18925 fputs (" SYMBOL", stdout
);
18929 fputs (" HWPATCH ", stdout
);
18930 if (option
.info
& OHW_R4KEOP
)
18931 fputs (" R4KEOP", stdout
);
18932 if (option
.info
& OHW_R8KPFETCH
)
18933 fputs (" R8KPFETCH", stdout
);
18934 if (option
.info
& OHW_R5KEOP
)
18935 fputs (" R5KEOP", stdout
);
18936 if (option
.info
& OHW_R5KCVTL
)
18937 fputs (" R5KCVTL", stdout
);
18941 fputs (" FILL ", stdout
);
18942 /* XXX Print content of info word? */
18946 fputs (" TAGS ", stdout
);
18947 /* XXX Print content of info word? */
18951 fputs (" HWAND ", stdout
);
18952 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18953 fputs (" R4KEOP_CHECKED", stdout
);
18954 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18955 fputs (" R4KEOP_CLEAN", stdout
);
18959 fputs (" HWOR ", stdout
);
18960 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18961 fputs (" R4KEOP_CHECKED", stdout
);
18962 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18963 fputs (" R4KEOP_CLEAN", stdout
);
18967 printf (" GP_GROUP %#06x self-contained %#06x",
18968 option
.info
& OGP_GROUP
,
18969 (option
.info
& OGP_SELF
) >> 16);
18973 printf (" IDENT %#06x self-contained %#06x",
18974 option
.info
& OGP_GROUP
,
18975 (option
.info
& OGP_SELF
) >> 16);
18979 /* This shouldn't happen. */
18980 printf (" %3d ??? %" PRId16
" %" PRIx32
,
18981 option
.kind
, option
.section
, option
.info
);
18985 len
= sizeof (* eopt
);
18986 while (len
< option
.size
)
18988 unsigned char datum
= *((unsigned char *) eoption
+ len
);
18990 if (ISPRINT (datum
))
18991 printf ("%c", datum
);
18993 printf ("\\%03o", datum
);
18996 fputs ("\n", stdout
);
18998 offset
+= option
.size
;
19006 if (conflicts_offset
!= 0 && conflictsno
!= 0)
19008 Elf32_Conflict
* iconf
;
19011 if (filedata
->dynamic_symbols
== NULL
)
19013 error (_("conflict list found without a dynamic symbol table\n"));
19017 /* PR 21345 - print a slightly more helpful error message
19018 if we are sure that the cmalloc will fail. */
19019 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
19021 error (_("Overlarge number of conflicts detected: %zx\n"),
19026 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
19029 error (_("Out of memory allocating space for dynamic conflicts\n"));
19035 Elf32_External_Conflict
* econf32
;
19037 econf32
= (Elf32_External_Conflict
*)
19038 get_data (NULL
, filedata
, conflicts_offset
,
19039 sizeof (*econf32
), conflictsno
, _("conflict"));
19046 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19047 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
19053 Elf64_External_Conflict
* econf64
;
19055 econf64
= (Elf64_External_Conflict
*)
19056 get_data (NULL
, filedata
, conflicts_offset
,
19057 sizeof (*econf64
), conflictsno
, _("conflict"));
19064 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19065 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
19070 printf (ngettext ("\nSection '.conflict' contains %zu entry:\n",
19071 "\nSection '.conflict' contains %zu entries:\n",
19074 puts (_(" Num: Index Value Name"));
19076 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19078 printf ("%5zu: %8lu ", cnt
, iconf
[cnt
]);
19080 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
19081 printf (_("<corrupt symbol index>"));
19084 Elf_Internal_Sym
* psym
;
19086 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
19087 print_vma (psym
->st_value
, FULL_HEX
);
19089 if (valid_dynamic_name (filedata
, psym
->st_name
))
19090 print_symbol (25, get_dynamic_name (filedata
, psym
->st_name
));
19092 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19100 if (pltgot
!= 0 && local_gotno
!= 0)
19102 uint64_t ent
, local_end
, global_end
;
19104 unsigned char * data
;
19105 unsigned char * data_end
;
19109 addr_size
= (is_32bit_elf
? 4 : 8);
19110 local_end
= pltgot
+ local_gotno
* addr_size
;
19112 /* PR binutils/17533 file: 012-111227-0.004 */
19113 if (symtabno
< gotsym
)
19115 error (_("The GOT symbol offset (%" PRIu64
19116 ") is greater than the symbol table size (%" PRIu64
")\n"),
19121 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
19122 /* PR 17531: file: 54c91a34. */
19123 if (global_end
< local_end
)
19125 error (_("Too many GOT symbols: %" PRIu64
"\n"), symtabno
);
19129 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
19130 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
19131 global_end
- pltgot
, 1,
19132 _("Global Offset Table data"));
19133 /* PR 12855: Null data is handled gracefully throughout. */
19134 data_end
= data
+ (global_end
- pltgot
);
19136 printf (_("\nPrimary GOT:\n"));
19137 printf (_(" Canonical gp value: "));
19138 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
19141 printf (_(" Reserved entries:\n"));
19142 printf (_(" %*s %10s %*s Purpose\n"),
19143 addr_size
* 2, _("Address"), _("Access"),
19144 addr_size
* 2, _("Initial"));
19145 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19146 printf (_(" Lazy resolver\n"));
19147 if (ent
== (uint64_t) -1)
19148 goto got_print_fail
;
19150 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
19151 This entry will be used by some runtime loaders, to store the
19152 module pointer. Otherwise this is an ordinary local entry.
19153 PR 21344: Check for the entry being fully available before
19156 && data
+ ent
- pltgot
+ addr_size
<= data_end
19157 && (byte_get (data
+ ent
- pltgot
, addr_size
)
19158 >> (addr_size
* 8 - 1)) != 0)
19160 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19161 printf (_(" Module pointer (GNU extension)\n"));
19162 if (ent
== (uint64_t) -1)
19163 goto got_print_fail
;
19167 if (data
!= NULL
&& ent
< local_end
)
19169 printf (_(" Local entries:\n"));
19170 printf (" %*s %10s %*s\n",
19171 addr_size
* 2, _("Address"), _("Access"),
19172 addr_size
* 2, _("Initial"));
19173 while (ent
< local_end
)
19175 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19177 if (ent
== (uint64_t) -1)
19178 goto got_print_fail
;
19183 if (data
!= NULL
&& gotsym
< symtabno
)
19187 printf (_(" Global entries:\n"));
19188 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
19189 addr_size
* 2, _("Address"),
19191 addr_size
* 2, _("Initial"),
19192 addr_size
* 2, _("Sym.Val."),
19194 /* Note for translators: "Ndx" = abbreviated form of "Index". */
19195 _("Ndx"), _("Name"));
19197 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
19199 for (i
= gotsym
; i
< symtabno
; i
++)
19201 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19204 if (filedata
->dynamic_symbols
== NULL
)
19205 printf (_("<no dynamic symbols>"));
19206 else if (i
< filedata
->num_dynamic_syms
)
19208 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
19210 print_vma (psym
->st_value
, LONG_HEX
);
19211 printf (" %-7s %3s ",
19212 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19213 get_symbol_index_type (filedata
, psym
->st_shndx
));
19215 if (valid_dynamic_name (filedata
, psym
->st_name
))
19216 print_symbol (sym_width
,
19217 get_dynamic_name (filedata
, psym
->st_name
));
19219 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19222 printf (_("<symbol index %zu exceeds number of dynamic symbols>"),
19226 if (ent
== (uint64_t) -1)
19236 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
19239 uint64_t offset
, rel_offset
;
19241 unsigned char * data
;
19242 int addr_size
, sym_width
;
19243 Elf_Internal_Rela
* rels
;
19245 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
19246 if (pltrel
== DT_RELA
)
19248 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19253 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19258 addr_size
= (is_32bit_elf
? 4 : 8);
19259 end
= mips_pltgot
+ (2 + count
) * addr_size
;
19261 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
19262 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
19263 1, _("Procedure Linkage Table data"));
19270 printf ("\nPLT GOT:\n\n");
19271 printf (_(" Reserved entries:\n"));
19272 printf (_(" %*s %*s Purpose\n"),
19273 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
19274 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19275 printf (_(" PLT lazy resolver\n"));
19276 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19277 printf (_(" Module pointer\n"));
19280 printf (_(" Entries:\n"));
19281 printf (" %*s %*s %*s %-7s %3s %s\n",
19282 addr_size
* 2, _("Address"),
19283 addr_size
* 2, _("Initial"),
19284 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
19285 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
19286 for (i
= 0; i
< count
; i
++)
19288 uint64_t idx
= get_reloc_symindex (rels
[i
].r_info
);
19290 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19293 if (idx
>= filedata
->num_dynamic_syms
)
19294 printf (_("<corrupt symbol index: %" PRIu64
">"), idx
);
19297 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
19299 print_vma (psym
->st_value
, LONG_HEX
);
19300 printf (" %-7s %3s ",
19301 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19302 get_symbol_index_type (filedata
, psym
->st_shndx
));
19303 if (valid_dynamic_name (filedata
, psym
->st_name
))
19304 print_symbol (sym_width
,
19305 get_dynamic_name (filedata
, psym
->st_name
));
19307 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19321 process_nds32_specific (Filedata
* filedata
)
19323 Elf_Internal_Shdr
*sect
= NULL
;
19325 sect
= find_section (filedata
, ".nds32_e_flags");
19326 if (sect
!= NULL
&& sect
->sh_size
>= 4)
19328 unsigned char *buf
;
19331 printf ("\nNDS32 elf flags section:\n");
19332 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
19333 _("NDS32 elf flags section"));
19338 flag
= byte_get (buf
, 4);
19340 switch (flag
& 0x3)
19343 printf ("(VEC_SIZE):\tNo entry.\n");
19346 printf ("(VEC_SIZE):\t4 bytes\n");
19349 printf ("(VEC_SIZE):\t16 bytes\n");
19352 printf ("(VEC_SIZE):\treserved\n");
19361 process_gnu_liblist (Filedata
* filedata
)
19363 Elf_Internal_Shdr
* section
;
19364 Elf_Internal_Shdr
* string_sec
;
19365 Elf32_External_Lib
* elib
;
19367 size_t strtab_size
;
19369 uint64_t num_liblist
;
19376 for (i
= 0, section
= filedata
->section_headers
;
19377 i
< filedata
->file_header
.e_shnum
;
19380 switch (section
->sh_type
)
19382 case SHT_GNU_LIBLIST
:
19383 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
19386 elib
= (Elf32_External_Lib
*)
19387 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
19388 _("liblist section data"));
19396 string_sec
= filedata
->section_headers
+ section
->sh_link
;
19397 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
19398 string_sec
->sh_size
,
19399 _("liblist string table"));
19401 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
19408 strtab_size
= string_sec
->sh_size
;
19410 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
19411 printf (ngettext ("\nLibrary list section '%s' contains %" PRIu64
19413 "\nLibrary list section '%s' contains %" PRIu64
19416 printable_section_name (filedata
, section
),
19419 puts (_(" Library Time Stamp Checksum Version Flags"));
19421 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
19429 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
19430 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
19431 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
19432 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
19433 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
19435 tmp
= gmtime (&atime
);
19436 snprintf (timebuf
, sizeof (timebuf
),
19437 "%04u-%02u-%02uT%02u:%02u:%02u",
19438 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
19439 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
19441 printf ("%3zu: ", cnt
);
19443 printf ("%-20s", liblist
.l_name
< strtab_size
19444 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
19446 printf ("%-20.20s", liblist
.l_name
< strtab_size
19447 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
19448 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
19449 liblist
.l_version
, liblist
.l_flags
);
19460 static const char *
19461 get_note_type (Filedata
* filedata
, unsigned e_type
)
19463 static char buff
[64];
19465 if (filedata
->file_header
.e_type
== ET_CORE
)
19469 return _("NT_AUXV (auxiliary vector)");
19471 return _("NT_PRSTATUS (prstatus structure)");
19473 return _("NT_FPREGSET (floating point registers)");
19475 return _("NT_PRPSINFO (prpsinfo structure)");
19476 case NT_TASKSTRUCT
:
19477 return _("NT_TASKSTRUCT (task structure)");
19479 return _("NT_GDB_TDESC (GDB XML target description)");
19481 return _("NT_PRXFPREG (user_xfpregs structure)");
19483 return _("NT_PPC_VMX (ppc Altivec registers)");
19485 return _("NT_PPC_VSX (ppc VSX registers)");
19487 return _("NT_PPC_TAR (ppc TAR register)");
19489 return _("NT_PPC_PPR (ppc PPR register)");
19491 return _("NT_PPC_DSCR (ppc DSCR register)");
19493 return _("NT_PPC_EBB (ppc EBB registers)");
19495 return _("NT_PPC_PMU (ppc PMU registers)");
19496 case NT_PPC_TM_CGPR
:
19497 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
19498 case NT_PPC_TM_CFPR
:
19499 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
19500 case NT_PPC_TM_CVMX
:
19501 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
19502 case NT_PPC_TM_CVSX
:
19503 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
19504 case NT_PPC_TM_SPR
:
19505 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
19506 case NT_PPC_TM_CTAR
:
19507 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
19508 case NT_PPC_TM_CPPR
:
19509 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
19510 case NT_PPC_TM_CDSCR
:
19511 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
19513 return _("NT_386_TLS (x86 TLS information)");
19514 case NT_386_IOPERM
:
19515 return _("NT_386_IOPERM (x86 I/O permissions)");
19516 case NT_X86_XSTATE
:
19517 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
19519 return _("NT_X86_CET (x86 CET state)");
19520 case NT_S390_HIGH_GPRS
:
19521 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
19522 case NT_S390_TIMER
:
19523 return _("NT_S390_TIMER (s390 timer register)");
19524 case NT_S390_TODCMP
:
19525 return _("NT_S390_TODCMP (s390 TOD comparator register)");
19526 case NT_S390_TODPREG
:
19527 return _("NT_S390_TODPREG (s390 TOD programmable register)");
19529 return _("NT_S390_CTRS (s390 control registers)");
19530 case NT_S390_PREFIX
:
19531 return _("NT_S390_PREFIX (s390 prefix register)");
19532 case NT_S390_LAST_BREAK
:
19533 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
19534 case NT_S390_SYSTEM_CALL
:
19535 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
19537 return _("NT_S390_TDB (s390 transaction diagnostic block)");
19538 case NT_S390_VXRS_LOW
:
19539 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
19540 case NT_S390_VXRS_HIGH
:
19541 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
19542 case NT_S390_GS_CB
:
19543 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
19544 case NT_S390_GS_BC
:
19545 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
19547 return _("NT_ARM_VFP (arm VFP registers)");
19549 return _("NT_ARM_TLS (AArch TLS registers)");
19550 case NT_ARM_HW_BREAK
:
19551 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
19552 case NT_ARM_HW_WATCH
:
19553 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
19554 case NT_ARM_SYSTEM_CALL
:
19555 return _("NT_ARM_SYSTEM_CALL (AArch system call number)");
19557 return _("NT_ARM_SVE (AArch SVE registers)");
19558 case NT_ARM_PAC_MASK
:
19559 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
19560 case NT_ARM_PACA_KEYS
:
19561 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
19562 case NT_ARM_PACG_KEYS
:
19563 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
19564 case NT_ARM_TAGGED_ADDR_CTRL
:
19565 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
19567 return _("NT_ARM_SSVE (AArch64 streaming SVE registers)");
19569 return _("NT_ARM_ZA (AArch64 SME ZA register)");
19570 case NT_ARM_PAC_ENABLED_KEYS
:
19571 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
19573 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
19575 return _("NT_RISCV_CSR (RISC-V control and status registers)");
19577 return _("NT_PSTATUS (pstatus structure)");
19579 return _("NT_FPREGS (floating point registers)");
19581 return _("NT_PSINFO (psinfo structure)");
19583 return _("NT_LWPSTATUS (lwpstatus_t structure)");
19585 return _("NT_LWPSINFO (lwpsinfo_t structure)");
19586 case NT_WIN32PSTATUS
:
19587 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
19589 return _("NT_SIGINFO (siginfo_t data)");
19591 return _("NT_FILE (mapped files)");
19599 return _("NT_VERSION (version)");
19601 return _("NT_ARCH (architecture)");
19602 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
19604 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
19606 case NT_GO_BUILDID
:
19607 return _("GO BUILDID");
19608 case FDO_PACKAGING_METADATA
:
19609 return _("FDO_PACKAGING_METADATA");
19614 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19619 print_core_note (Elf_Internal_Note
*pnote
)
19621 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
19622 uint64_t count
, page_size
;
19623 unsigned char *descdata
, *filenames
, *descend
;
19625 if (pnote
->type
!= NT_FILE
)
19634 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
19635 /* Still "successful". */
19639 if (pnote
->descsz
< 2 * addr_size
)
19641 error (_(" Malformed note - too short for header\n"));
19645 descdata
= (unsigned char *) pnote
->descdata
;
19646 descend
= descdata
+ pnote
->descsz
;
19648 if (descdata
[pnote
->descsz
- 1] != '\0')
19650 error (_(" Malformed note - does not end with \\0\n"));
19654 count
= byte_get (descdata
, addr_size
);
19655 descdata
+= addr_size
;
19657 page_size
= byte_get (descdata
, addr_size
);
19658 descdata
+= addr_size
;
19660 if (count
> ((uint64_t) -1 - 2 * addr_size
) / (3 * addr_size
)
19661 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
19663 error (_(" Malformed note - too short for supplied file count\n"));
19667 printf (_(" Page size: "));
19668 print_vma (page_size
, DEC
);
19671 printf (_(" %*s%*s%*s\n"),
19672 (int) (2 + 2 * addr_size
), _("Start"),
19673 (int) (4 + 2 * addr_size
), _("End"),
19674 (int) (4 + 2 * addr_size
), _("Page Offset"));
19675 filenames
= descdata
+ count
* 3 * addr_size
;
19676 while (count
-- > 0)
19678 uint64_t start
, end
, file_ofs
;
19680 if (filenames
== descend
)
19682 error (_(" Malformed note - filenames end too early\n"));
19686 start
= byte_get (descdata
, addr_size
);
19687 descdata
+= addr_size
;
19688 end
= byte_get (descdata
, addr_size
);
19689 descdata
+= addr_size
;
19690 file_ofs
= byte_get (descdata
, addr_size
);
19691 descdata
+= addr_size
;
19694 print_vma (start
, FULL_HEX
);
19696 print_vma (end
, FULL_HEX
);
19698 print_vma (file_ofs
, FULL_HEX
);
19699 printf ("\n %s\n", filenames
);
19701 filenames
+= 1 + strlen ((char *) filenames
);
19707 static const char *
19708 get_gnu_elf_note_type (unsigned e_type
)
19710 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
19713 case NT_GNU_ABI_TAG
:
19714 return _("NT_GNU_ABI_TAG (ABI version tag)");
19716 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
19717 case NT_GNU_BUILD_ID
:
19718 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
19719 case NT_GNU_GOLD_VERSION
:
19720 return _("NT_GNU_GOLD_VERSION (gold version)");
19721 case NT_GNU_PROPERTY_TYPE_0
:
19722 return _("NT_GNU_PROPERTY_TYPE_0");
19723 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
19724 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
19725 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
19726 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
19729 static char buff
[64];
19731 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19738 decode_x86_compat_isa (unsigned int bitmask
)
19742 unsigned int bit
= bitmask
& (- bitmask
);
19747 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
19750 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
19753 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
19756 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
19759 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
19762 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
19765 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
19768 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
19771 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
19774 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
19777 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
19780 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
19781 printf ("AVX512F");
19783 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
19784 printf ("AVX512CD");
19786 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
19787 printf ("AVX512ER");
19789 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
19790 printf ("AVX512PF");
19792 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
19793 printf ("AVX512VL");
19795 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
19796 printf ("AVX512DQ");
19798 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
19799 printf ("AVX512BW");
19802 printf (_("<unknown: %x>"), bit
);
19811 decode_x86_compat_2_isa (unsigned int bitmask
)
19815 printf (_("<None>"));
19821 unsigned int bit
= bitmask
& (- bitmask
);
19826 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
19829 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
19832 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
19835 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
19838 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
19841 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
19844 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
19847 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
19850 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
19853 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
19856 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
19857 printf ("AVX512F");
19859 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
19860 printf ("AVX512CD");
19862 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
19863 printf ("AVX512ER");
19865 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
19866 printf ("AVX512PF");
19868 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
19869 printf ("AVX512VL");
19871 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
19872 printf ("AVX512DQ");
19874 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
19875 printf ("AVX512BW");
19877 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
19878 printf ("AVX512_4FMAPS");
19880 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
19881 printf ("AVX512_4VNNIW");
19883 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
19884 printf ("AVX512_BITALG");
19886 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
19887 printf ("AVX512_IFMA");
19889 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
19890 printf ("AVX512_VBMI");
19892 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
19893 printf ("AVX512_VBMI2");
19895 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
19896 printf ("AVX512_VNNI");
19898 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
19899 printf ("AVX512_BF16");
19902 printf (_("<unknown: %x>"), bit
);
19910 static const char *
19911 get_amdgpu_elf_note_type (unsigned int e_type
)
19915 case NT_AMDGPU_METADATA
:
19916 return _("NT_AMDGPU_METADATA (code object metadata)");
19919 static char buf
[64];
19920 snprintf (buf
, sizeof (buf
), _("Unknown note type: (0x%08x)"), e_type
);
19927 decode_x86_isa (unsigned int bitmask
)
19931 unsigned int bit
= bitmask
& (- bitmask
);
19936 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
19937 printf ("x86-64-baseline");
19939 case GNU_PROPERTY_X86_ISA_1_V2
:
19940 printf ("x86-64-v2");
19942 case GNU_PROPERTY_X86_ISA_1_V3
:
19943 printf ("x86-64-v3");
19945 case GNU_PROPERTY_X86_ISA_1_V4
:
19946 printf ("x86-64-v4");
19949 printf (_("<unknown: %x>"), bit
);
19958 decode_x86_feature_1 (unsigned int bitmask
)
19962 printf (_("<None>"));
19968 unsigned int bit
= bitmask
& (- bitmask
);
19973 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
19976 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
19979 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
19980 printf ("LAM_U48");
19982 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
19983 printf ("LAM_U57");
19986 printf (_("<unknown: %x>"), bit
);
19995 decode_x86_feature_2 (unsigned int bitmask
)
19999 printf (_("<None>"));
20005 unsigned int bit
= bitmask
& (- bitmask
);
20010 case GNU_PROPERTY_X86_FEATURE_2_X86
:
20013 case GNU_PROPERTY_X86_FEATURE_2_X87
:
20016 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
20019 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
20022 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
20025 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
20028 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
20031 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
20034 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
20037 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
20040 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
20041 printf ("XSAVEOPT");
20043 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
20047 printf (_("<unknown: %x>"), bit
);
20056 decode_aarch64_feature_1_and (unsigned int bitmask
)
20060 unsigned int bit
= bitmask
& (- bitmask
);
20065 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
20069 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
20074 printf (_("<unknown: %x>"), bit
);
20083 decode_1_needed (unsigned int bitmask
)
20087 unsigned int bit
= bitmask
& (- bitmask
);
20092 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
20093 printf ("indirect external access");
20096 printf (_("<unknown: %x>"), bit
);
20105 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
20107 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
20108 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
20109 unsigned int size
= is_32bit_elf
? 4 : 8;
20111 printf (_(" Properties: "));
20113 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
20115 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
20119 while (ptr
< ptr_end
)
20123 unsigned int datasz
;
20125 if ((size_t) (ptr_end
- ptr
) < 8)
20127 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
20131 type
= byte_get (ptr
, 4);
20132 datasz
= byte_get (ptr
+ 4, 4);
20136 if (datasz
> (size_t) (ptr_end
- ptr
))
20138 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
20143 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
20145 if (filedata
->file_header
.e_machine
== EM_X86_64
20146 || filedata
->file_header
.e_machine
== EM_IAMCU
20147 || filedata
->file_header
.e_machine
== EM_386
)
20149 unsigned int bitmask
;
20152 bitmask
= byte_get (ptr
, 4);
20158 case GNU_PROPERTY_X86_ISA_1_USED
:
20160 printf (_("x86 ISA used: <corrupt length: %#x> "),
20164 printf ("x86 ISA used: ");
20165 decode_x86_isa (bitmask
);
20169 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
20171 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20175 printf ("x86 ISA needed: ");
20176 decode_x86_isa (bitmask
);
20180 case GNU_PROPERTY_X86_FEATURE_1_AND
:
20182 printf (_("x86 feature: <corrupt length: %#x> "),
20186 printf ("x86 feature: ");
20187 decode_x86_feature_1 (bitmask
);
20191 case GNU_PROPERTY_X86_FEATURE_2_USED
:
20193 printf (_("x86 feature used: <corrupt length: %#x> "),
20197 printf ("x86 feature used: ");
20198 decode_x86_feature_2 (bitmask
);
20202 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
20204 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
20207 printf ("x86 feature needed: ");
20208 decode_x86_feature_2 (bitmask
);
20212 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
20214 printf (_("x86 ISA used: <corrupt length: %#x> "),
20218 printf ("x86 ISA used: ");
20219 decode_x86_compat_isa (bitmask
);
20223 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
20225 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20229 printf ("x86 ISA needed: ");
20230 decode_x86_compat_isa (bitmask
);
20234 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
20236 printf (_("x86 ISA used: <corrupt length: %#x> "),
20240 printf ("x86 ISA used: ");
20241 decode_x86_compat_2_isa (bitmask
);
20245 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
20247 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20251 printf ("x86 ISA needed: ");
20252 decode_x86_compat_2_isa (bitmask
);
20260 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
20262 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
20264 printf ("AArch64 feature: ");
20266 printf (_("<corrupt length: %#x> "), datasz
);
20268 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
20277 case GNU_PROPERTY_STACK_SIZE
:
20278 printf (_("stack size: "));
20279 if (datasz
!= size
)
20280 printf (_("<corrupt length: %#x> "), datasz
);
20282 printf ("%#" PRIx64
, byte_get (ptr
, size
));
20285 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
20286 printf ("no copy on protected ");
20288 printf (_("<corrupt length: %#x> "), datasz
);
20292 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
20293 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
20294 || (type
>= GNU_PROPERTY_UINT32_OR_LO
20295 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
20299 case GNU_PROPERTY_1_NEEDED
:
20301 printf (_("1_needed: <corrupt length: %#x> "),
20305 unsigned int bitmask
= byte_get (ptr
, 4);
20306 printf ("1_needed: ");
20307 decode_1_needed (bitmask
);
20314 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
20315 printf (_("UINT32_AND (%#x): "), type
);
20317 printf (_("UINT32_OR (%#x): "), type
);
20319 printf (_("<corrupt length: %#x> "), datasz
);
20321 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
20328 if (type
< GNU_PROPERTY_LOPROC
)
20329 printf (_("<unknown type %#x data: "), type
);
20330 else if (type
< GNU_PROPERTY_LOUSER
)
20331 printf (_("<processor-specific type %#x data: "), type
);
20333 printf (_("<application-specific type %#x data: "), type
);
20334 for (j
= 0; j
< datasz
; ++j
)
20335 printf ("%02x ", ptr
[j
] & 0xff);
20339 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
20340 if (ptr
== ptr_end
)
20353 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
20355 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
20356 switch (pnote
->type
)
20358 case NT_GNU_BUILD_ID
:
20362 printf (_(" Build ID: "));
20363 for (i
= 0; i
< pnote
->descsz
; ++i
)
20364 printf ("%02x", pnote
->descdata
[i
] & 0xff);
20369 case NT_GNU_ABI_TAG
:
20371 unsigned int os
, major
, minor
, subminor
;
20372 const char *osname
;
20374 /* PR 17531: file: 030-599401-0.004. */
20375 if (pnote
->descsz
< 16)
20377 printf (_(" <corrupt GNU_ABI_TAG>\n"));
20381 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20382 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20383 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
20384 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
20388 case GNU_ABI_TAG_LINUX
:
20391 case GNU_ABI_TAG_HURD
:
20394 case GNU_ABI_TAG_SOLARIS
:
20395 osname
= "Solaris";
20397 case GNU_ABI_TAG_FREEBSD
:
20398 osname
= "FreeBSD";
20400 case GNU_ABI_TAG_NETBSD
:
20403 case GNU_ABI_TAG_SYLLABLE
:
20404 osname
= "Syllable";
20406 case GNU_ABI_TAG_NACL
:
20410 osname
= "Unknown";
20414 printf (_(" OS: %s, ABI: %d.%d.%d\n"), osname
,
20415 major
, minor
, subminor
);
20419 case NT_GNU_GOLD_VERSION
:
20423 printf (_(" Version: "));
20424 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
20425 printf ("%c", pnote
->descdata
[i
]);
20432 unsigned int num_entries
, mask
;
20434 /* Hardware capabilities information. Word 0 is the number of entries.
20435 Word 1 is a bitmask of enabled entries. The rest of the descriptor
20436 is a series of entries, where each entry is a single byte followed
20437 by a nul terminated string. The byte gives the bit number to test
20438 if enabled in the bitmask. */
20439 printf (_(" Hardware Capabilities: "));
20440 if (pnote
->descsz
< 8)
20442 error (_("<corrupt GNU_HWCAP>\n"));
20445 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20446 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20447 printf (_("num entries: %d, enabled mask: %x\n"), num_entries
, mask
);
20448 /* FIXME: Add code to display the entries... */
20452 case NT_GNU_PROPERTY_TYPE_0
:
20453 print_gnu_property_note (filedata
, pnote
);
20457 /* Handle unrecognised types. An error message should have already been
20458 created by get_gnu_elf_note_type(), so all that we need to do is to
20459 display the data. */
20463 printf (_(" Description data: "));
20464 for (i
= 0; i
< pnote
->descsz
; ++i
)
20465 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
20474 static const char *
20475 get_v850_elf_note_type (enum v850_notes n_type
)
20477 static char buff
[64];
20481 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
20482 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
20483 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
20484 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
20485 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
20486 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
20488 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
20494 print_v850_note (Elf_Internal_Note
* pnote
)
20498 if (pnote
->descsz
!= 4)
20501 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
20505 printf (_("not set\n"));
20509 switch (pnote
->type
)
20511 case V850_NOTE_ALIGNMENT
:
20514 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
20515 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
20519 case V850_NOTE_DATA_SIZE
:
20522 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
20523 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
20527 case V850_NOTE_FPU_INFO
:
20530 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
20531 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
20535 case V850_NOTE_MMU_INFO
:
20536 case V850_NOTE_CACHE_INFO
:
20537 case V850_NOTE_SIMD_INFO
:
20538 if (val
== EF_RH850_SIMD
)
20540 printf (_("yes\n"));
20546 /* An 'unknown note type' message will already have been displayed. */
20550 printf (_("unknown value: %x\n"), val
);
20555 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
20557 unsigned int version
;
20559 switch (pnote
->type
)
20561 case NT_NETBSD_IDENT
:
20562 if (pnote
->descsz
< 1)
20564 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
20565 if ((version
/ 10000) % 100)
20566 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
20567 version
, version
/ 100000000, (version
/ 1000000) % 100,
20568 (version
/ 10000) % 100 > 26 ? "Z" : "",
20569 'A' + (version
/ 10000) % 26);
20571 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
20572 version
, version
/ 100000000, (version
/ 1000000) % 100,
20573 (version
/ 100) % 100);
20576 case NT_NETBSD_MARCH
:
20577 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
20581 case NT_NETBSD_PAX
:
20582 if (pnote
->descsz
< 1)
20584 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
20585 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
20586 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
20587 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
20588 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
20589 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
20590 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
20591 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
20595 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
20596 pnote
->descsz
, pnote
->type
);
20600 static const char *
20601 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20605 case NT_FREEBSD_THRMISC
:
20606 return _("NT_THRMISC (thrmisc structure)");
20607 case NT_FREEBSD_PROCSTAT_PROC
:
20608 return _("NT_PROCSTAT_PROC (proc data)");
20609 case NT_FREEBSD_PROCSTAT_FILES
:
20610 return _("NT_PROCSTAT_FILES (files data)");
20611 case NT_FREEBSD_PROCSTAT_VMMAP
:
20612 return _("NT_PROCSTAT_VMMAP (vmmap data)");
20613 case NT_FREEBSD_PROCSTAT_GROUPS
:
20614 return _("NT_PROCSTAT_GROUPS (groups data)");
20615 case NT_FREEBSD_PROCSTAT_UMASK
:
20616 return _("NT_PROCSTAT_UMASK (umask data)");
20617 case NT_FREEBSD_PROCSTAT_RLIMIT
:
20618 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
20619 case NT_FREEBSD_PROCSTAT_OSREL
:
20620 return _("NT_PROCSTAT_OSREL (osreldate data)");
20621 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
20622 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
20623 case NT_FREEBSD_PROCSTAT_AUXV
:
20624 return _("NT_PROCSTAT_AUXV (auxv data)");
20625 case NT_FREEBSD_PTLWPINFO
:
20626 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
20627 case NT_FREEBSD_X86_SEGBASES
:
20628 return _("NT_X86_SEGBASES (x86 segment base registers)");
20630 return get_note_type (filedata
, e_type
);
20633 static const char *
20634 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20636 static char buff
[64];
20640 case NT_NETBSDCORE_PROCINFO
:
20641 /* NetBSD core "procinfo" structure. */
20642 return _("NetBSD procinfo structure");
20644 case NT_NETBSDCORE_AUXV
:
20645 return _("NetBSD ELF auxiliary vector data");
20647 case NT_NETBSDCORE_LWPSTATUS
:
20648 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
20651 /* As of Jan 2020 there are no other machine-independent notes
20652 defined for NetBSD core files. If the note type is less
20653 than the start of the machine-dependent note types, we don't
20656 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
20658 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20664 switch (filedata
->file_header
.e_machine
)
20666 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
20667 and PT_GETFPREGS == mach+2. */
20672 case EM_SPARC32PLUS
:
20676 case NT_NETBSDCORE_FIRSTMACH
+ 0:
20677 return _("PT_GETREGS (reg structure)");
20678 case NT_NETBSDCORE_FIRSTMACH
+ 2:
20679 return _("PT_GETFPREGS (fpreg structure)");
20685 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
20686 There's also old PT___GETREGS40 == mach + 1 for old reg
20687 structure which lacks GBR. */
20691 case NT_NETBSDCORE_FIRSTMACH
+ 1:
20692 return _("PT___GETREGS40 (old reg structure)");
20693 case NT_NETBSDCORE_FIRSTMACH
+ 3:
20694 return _("PT_GETREGS (reg structure)");
20695 case NT_NETBSDCORE_FIRSTMACH
+ 5:
20696 return _("PT_GETFPREGS (fpreg structure)");
20702 /* On all other arch's, PT_GETREGS == mach+1 and
20703 PT_GETFPREGS == mach+3. */
20707 case NT_NETBSDCORE_FIRSTMACH
+ 1:
20708 return _("PT_GETREGS (reg structure)");
20709 case NT_NETBSDCORE_FIRSTMACH
+ 3:
20710 return _("PT_GETFPREGS (fpreg structure)");
20716 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
20717 e_type
- NT_NETBSDCORE_FIRSTMACH
);
20721 static const char *
20722 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20726 case NT_OPENBSD_PROCINFO
:
20727 return _("OpenBSD procinfo structure");
20728 case NT_OPENBSD_AUXV
:
20729 return _("OpenBSD ELF auxiliary vector data");
20730 case NT_OPENBSD_REGS
:
20731 return _("OpenBSD regular registers");
20732 case NT_OPENBSD_FPREGS
:
20733 return _("OpenBSD floating point registers");
20734 case NT_OPENBSD_WCOOKIE
:
20735 return _("OpenBSD window cookie");
20738 return get_note_type (filedata
, e_type
);
20741 static const char *
20742 get_qnx_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20746 case QNT_DEBUG_FULLPATH
:
20747 return _("QNX debug fullpath");
20748 case QNT_DEBUG_RELOC
:
20749 return _("QNX debug relocation");
20751 return _("QNX stack");
20752 case QNT_GENERATOR
:
20753 return _("QNX generator");
20754 case QNT_DEFAULT_LIB
:
20755 return _("QNX default library");
20756 case QNT_CORE_SYSINFO
:
20757 return _("QNX core sysinfo");
20758 case QNT_CORE_INFO
:
20759 return _("QNX core info");
20760 case QNT_CORE_STATUS
:
20761 return _("QNX core status");
20762 case QNT_CORE_GREG
:
20763 return _("QNX general registers");
20764 case QNT_CORE_FPREG
:
20765 return _("QNX floating point registers");
20767 return _("QNX link map");
20770 return get_note_type (filedata
, e_type
);
20773 static const char *
20774 get_stapsdt_note_type (unsigned e_type
)
20776 static char buff
[64];
20781 return _("NT_STAPSDT (SystemTap probe descriptors)");
20787 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20792 print_stapsdt_note (Elf_Internal_Note
*pnote
)
20794 size_t len
, maxlen
;
20795 size_t addr_size
= is_32bit_elf
? 4 : 8;
20796 char *data
= pnote
->descdata
;
20797 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
20798 uint64_t pc
, base_addr
, semaphore
;
20799 char *provider
, *probe
, *arg_fmt
;
20801 if (pnote
->descsz
< (addr_size
* 3))
20802 goto stapdt_note_too_small
;
20804 pc
= byte_get ((unsigned char *) data
, addr_size
);
20807 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
20810 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
20813 if (data
>= data_end
)
20814 goto stapdt_note_too_small
;
20815 maxlen
= data_end
- data
;
20816 len
= strnlen (data
, maxlen
);
20823 goto stapdt_note_too_small
;
20825 if (data
>= data_end
)
20826 goto stapdt_note_too_small
;
20827 maxlen
= data_end
- data
;
20828 len
= strnlen (data
, maxlen
);
20835 goto stapdt_note_too_small
;
20837 if (data
>= data_end
)
20838 goto stapdt_note_too_small
;
20839 maxlen
= data_end
- data
;
20840 len
= strnlen (data
, maxlen
);
20847 goto stapdt_note_too_small
;
20849 printf (_(" Provider: %s\n"), provider
);
20850 printf (_(" Name: %s\n"), probe
);
20851 printf (_(" Location: "));
20852 print_vma (pc
, FULL_HEX
);
20853 printf (_(", Base: "));
20854 print_vma (base_addr
, FULL_HEX
);
20855 printf (_(", Semaphore: "));
20856 print_vma (semaphore
, FULL_HEX
);
20858 printf (_(" Arguments: %s\n"), arg_fmt
);
20860 return data
== data_end
;
20862 stapdt_note_too_small
:
20863 printf (_(" <corrupt - note is too small>\n"));
20864 error (_("corrupt stapdt note - the data size is too small\n"));
20869 print_fdo_note (Elf_Internal_Note
* pnote
)
20871 if (pnote
->descsz
> 0 && pnote
->type
== FDO_PACKAGING_METADATA
)
20873 printf (_(" Packaging Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
20879 static const char *
20880 get_ia64_vms_note_type (unsigned e_type
)
20882 static char buff
[64];
20887 return _("NT_VMS_MHD (module header)");
20889 return _("NT_VMS_LNM (language name)");
20891 return _("NT_VMS_SRC (source files)");
20893 return "NT_VMS_TITLE";
20895 return _("NT_VMS_EIDC (consistency check)");
20896 case NT_VMS_FPMODE
:
20897 return _("NT_VMS_FPMODE (FP mode)");
20898 case NT_VMS_LINKTIME
:
20899 return "NT_VMS_LINKTIME";
20900 case NT_VMS_IMGNAM
:
20901 return _("NT_VMS_IMGNAM (image name)");
20903 return _("NT_VMS_IMGID (image id)");
20904 case NT_VMS_LINKID
:
20905 return _("NT_VMS_LINKID (link id)");
20906 case NT_VMS_IMGBID
:
20907 return _("NT_VMS_IMGBID (build id)");
20908 case NT_VMS_GSTNAM
:
20909 return _("NT_VMS_GSTNAM (sym table name)");
20910 case NT_VMS_ORIG_DYN
:
20911 return "NT_VMS_ORIG_DYN";
20912 case NT_VMS_PATCHTIME
:
20913 return "NT_VMS_PATCHTIME";
20915 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20921 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
20923 unsigned int maxlen
= pnote
->descsz
;
20925 if (maxlen
< 2 || maxlen
!= pnote
->descsz
)
20926 goto desc_size_fail
;
20928 switch (pnote
->type
)
20932 goto desc_size_fail
;
20934 size_t l
= strnlen (pnote
->descdata
+ 34, maxlen
- 34);
20936 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
20937 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
20938 if (l
+ 34 < maxlen
)
20940 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
20941 if (l
+ 35 < maxlen
)
20942 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
20944 printf (_(" Module version : <missing>\n"));
20948 printf (_(" Module name : <missing>\n"));
20949 printf (_(" Module version : <missing>\n"));
20954 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
20957 case NT_VMS_FPMODE
:
20958 printf (_(" Floating Point mode: "));
20960 goto desc_size_fail
;
20961 /* FIXME: Generate an error if descsz > 8 ? */
20963 printf ("0x%016" PRIx64
"\n",
20964 byte_get ((unsigned char *) pnote
->descdata
, 8));
20967 case NT_VMS_LINKTIME
:
20968 printf (_(" Link time: "));
20970 goto desc_size_fail
;
20971 /* FIXME: Generate an error if descsz > 8 ? */
20973 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
20977 case NT_VMS_PATCHTIME
:
20978 printf (_(" Patch time: "));
20980 goto desc_size_fail
;
20981 /* FIXME: Generate an error if descsz > 8 ? */
20983 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
20987 case NT_VMS_ORIG_DYN
:
20989 goto desc_size_fail
;
20991 printf (_(" Major id: %u, minor id: %u\n"),
20992 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4),
20993 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
20994 printf (_(" Last modified : "));
20995 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
+ 8, 8));
20996 printf (_("\n Link flags : "));
20997 printf ("0x%016" PRIx64
"\n",
20998 byte_get ((unsigned char *) pnote
->descdata
+ 16, 8));
20999 printf (_(" Header flags: 0x%08x\n"),
21000 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 24, 4));
21001 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
21004 case NT_VMS_IMGNAM
:
21005 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
21008 case NT_VMS_GSTNAM
:
21009 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
21013 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
21016 case NT_VMS_LINKID
:
21017 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
21027 printf (_(" <corrupt - data size is too small>\n"));
21028 error (_("corrupt IA64 note: data size is too small\n"));
21032 struct build_attr_cache
{
21033 Filedata
*filedata
;
21035 uint64_t strtablen
;
21036 Elf_Internal_Sym
*symtab
;
21040 /* Find the symbol associated with a build attribute that is attached
21041 to address OFFSET. If PNAME is non-NULL then store the name of
21042 the symbol (if found) in the provided pointer, Returns NULL if a
21043 symbol could not be found. */
21045 static Elf_Internal_Sym
*
21046 get_symbol_for_build_attribute (Filedata
*filedata
,
21049 const char **pname
)
21051 Elf_Internal_Sym
*saved_sym
= NULL
;
21052 Elf_Internal_Sym
*sym
;
21054 if (filedata
->section_headers
!= NULL
21055 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
21057 Elf_Internal_Shdr
* symsec
;
21059 free (ba_cache
.strtab
);
21060 ba_cache
.strtab
= NULL
;
21061 free (ba_cache
.symtab
);
21062 ba_cache
.symtab
= NULL
;
21064 /* Load the symbol and string sections. */
21065 for (symsec
= filedata
->section_headers
;
21066 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
21069 if (symsec
->sh_type
== SHT_SYMTAB
21070 && get_symtab (filedata
, symsec
,
21071 &ba_cache
.symtab
, &ba_cache
.nsyms
,
21072 &ba_cache
.strtab
, &ba_cache
.strtablen
))
21075 ba_cache
.filedata
= filedata
;
21078 if (ba_cache
.symtab
== NULL
)
21081 /* Find a symbol whose value matches offset. */
21082 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
21083 if (sym
->st_value
== offset
)
21085 if (sym
->st_name
>= ba_cache
.strtablen
)
21086 /* Huh ? This should not happen. */
21089 if (ba_cache
.strtab
[sym
->st_name
] == 0)
21092 /* The AArch64, ARM and RISC-V architectures define mapping symbols
21093 (eg $d, $x, $t) which we want to ignore. */
21094 if (ba_cache
.strtab
[sym
->st_name
] == '$'
21095 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
21096 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
21101 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
21102 and FILE or OBJECT symbols over NOTYPE symbols. We skip
21103 FUNC symbols entirely. */
21104 switch (ELF_ST_TYPE (sym
->st_info
))
21111 /* If the symbol has a size associated
21112 with it then we can stop searching. */
21113 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
21118 /* Ignore function symbols. */
21125 switch (ELF_ST_BIND (sym
->st_info
))
21128 if (saved_sym
== NULL
21129 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
21134 if (saved_sym
== NULL
)
21144 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
21152 if (saved_sym
&& pname
)
21153 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
21158 /* Returns true iff addr1 and addr2 are in the same section. */
21161 same_section (Filedata
* filedata
, uint64_t addr1
, uint64_t addr2
)
21163 Elf_Internal_Shdr
* a1
;
21164 Elf_Internal_Shdr
* a2
;
21166 a1
= find_section_by_address (filedata
, addr1
);
21167 a2
= find_section_by_address (filedata
, addr2
);
21169 return a1
== a2
&& a1
!= NULL
;
21173 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
21174 Filedata
* filedata
)
21176 static uint64_t global_offset
= 0;
21177 static uint64_t global_end
= 0;
21178 static uint64_t func_offset
= 0;
21179 static uint64_t func_end
= 0;
21181 Elf_Internal_Sym
*sym
;
21185 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
21187 switch (pnote
->descsz
)
21190 /* A zero-length description means that the range of
21191 the previous note of the same type should be used. */
21194 if (global_end
> global_offset
)
21195 printf (_(" Applies to region from %#" PRIx64
21196 " to %#" PRIx64
"\n"), global_offset
, global_end
);
21198 printf (_(" Applies to region from %#" PRIx64
21199 "\n"), global_offset
);
21203 if (func_end
> func_offset
)
21204 printf (_(" Applies to region from %#" PRIx64
21205 " to %#" PRIx64
"\n"), func_offset
, func_end
);
21207 printf (_(" Applies to region from %#" PRIx64
21208 "\n"), func_offset
);
21213 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21218 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21219 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
21223 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
21224 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
21228 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
21229 printf (_(" <invalid descsz>"));
21234 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
21235 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
21236 in order to avoid them being confused with the start address of the
21237 first function in the file... */
21238 if (sym
== NULL
&& is_open_attr
)
21239 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
21242 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
21243 end
= start
+ sym
->st_size
;
21247 /* FIXME: Need to properly allow for section alignment.
21248 16 is just the alignment used on x86_64. */
21250 && start
> BFD_ALIGN (global_end
, 16)
21251 /* Build notes are not guaranteed to be organised in order of
21252 increasing address, but we should find the all of the notes
21253 for one section in the same place. */
21254 && same_section (filedata
, start
, global_end
))
21255 warn (_("Gap in build notes detected from %#" PRIx64
21256 " to %#" PRIx64
"\n"),
21257 global_end
+ 1, start
- 1);
21259 printf (_(" Applies to region from %#" PRIx64
), start
);
21260 global_offset
= start
;
21264 printf (_(" to %#" PRIx64
), end
);
21270 printf (_(" Applies to region from %#" PRIx64
), start
);
21271 func_offset
= start
;
21275 printf (_(" to %#" PRIx64
), end
);
21281 printf (_(" (%s)"), name
);
21288 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
21290 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
21291 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
21292 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
21294 char name_attribute
;
21295 const char * expected_types
;
21296 const char * name
= pnote
->namedata
;
21300 if (name
== NULL
|| pnote
->namesz
< 2)
21302 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21303 print_symbol (-20, _(" <corrupt name>"));
21312 /* Version 2 of the spec adds a "GA" prefix to the name field. */
21313 if (name
[0] == 'G' && name
[1] == 'A')
21315 if (pnote
->namesz
< 4)
21317 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21318 print_symbol (-20, _(" <corrupt name>"));
21327 switch ((name_type
= * name
))
21329 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21330 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21331 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21332 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21333 printf ("%c", * name
);
21337 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
21338 print_symbol (-20, _("<unknown name type>"));
21345 switch ((name_attribute
= * name
))
21347 case GNU_BUILD_ATTRIBUTE_VERSION
:
21348 text
= _("<version>");
21349 expected_types
= string_expected
;
21352 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21353 text
= _("<stack prot>");
21354 expected_types
= "!+*";
21357 case GNU_BUILD_ATTRIBUTE_RELRO
:
21358 text
= _("<relro>");
21359 expected_types
= bool_expected
;
21362 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
21363 text
= _("<stack size>");
21364 expected_types
= number_expected
;
21367 case GNU_BUILD_ATTRIBUTE_TOOL
:
21368 text
= _("<tool>");
21369 expected_types
= string_expected
;
21372 case GNU_BUILD_ATTRIBUTE_ABI
:
21374 expected_types
= "$*";
21377 case GNU_BUILD_ATTRIBUTE_PIC
:
21379 expected_types
= number_expected
;
21382 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
21383 text
= _("<short enum>");
21384 expected_types
= bool_expected
;
21388 if (ISPRINT (* name
))
21390 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
21392 if (len
> left
&& ! do_wide
)
21394 printf ("%.*s:", len
, name
);
21400 static char tmpbuf
[128];
21402 error (_("unrecognised byte in name field: %d\n"), * name
);
21403 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
21407 expected_types
= "*$!+";
21412 left
-= printf ("%s", text
);
21414 if (strchr (expected_types
, name_type
) == NULL
)
21415 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
21417 if ((size_t) (name
- pnote
->namedata
) > pnote
->namesz
)
21419 error (_("corrupt name field: namesz: %lu but parsing gets to %td\n"),
21421 name
- pnote
->namedata
);
21425 if (left
< 1 && ! do_wide
)
21430 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21432 unsigned int bytes
;
21434 unsigned int shift
= 0;
21435 char *decoded
= NULL
;
21437 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
21439 /* The -1 is because the name field is always 0 terminated, and we
21440 want to be able to ensure that the shift in the while loop below
21441 will not overflow. */
21444 if (bytes
> sizeof (val
))
21446 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
21448 bytes
= sizeof (val
);
21450 /* We do not bother to warn if bytes == 0 as this can
21451 happen with some early versions of the gcc plugin. */
21455 uint64_t byte
= *name
++ & 0xff;
21457 val
|= byte
<< shift
;
21461 switch (name_attribute
)
21463 case GNU_BUILD_ATTRIBUTE_PIC
:
21466 case 0: decoded
= "static"; break;
21467 case 1: decoded
= "pic"; break;
21468 case 2: decoded
= "PIC"; break;
21469 case 3: decoded
= "pie"; break;
21470 case 4: decoded
= "PIE"; break;
21474 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21477 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
21478 case 0: decoded
= "off"; break;
21479 case 1: decoded
= "on"; break;
21480 case 2: decoded
= "all"; break;
21481 case 3: decoded
= "strong"; break;
21482 case 4: decoded
= "explicit"; break;
21490 if (decoded
!= NULL
)
21492 print_symbol (-left
, decoded
);
21503 left
-= printf ("0x%" PRIx64
, val
);
21505 left
-= printf ("0x%-.*" PRIx64
, left
, val
);
21509 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21510 left
-= print_symbol (- left
, name
);
21512 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21513 left
-= print_symbol (- left
, "true");
21515 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21516 left
-= print_symbol (- left
, "false");
21520 if (do_wide
&& left
> 0)
21521 printf ("%-*s", left
, " ");
21526 /* Print the contents of PNOTE as hex. */
21529 print_note_contents_hex (Elf_Internal_Note
*pnote
)
21535 printf (_(" description data: "));
21536 for (i
= 0; i
< pnote
->descsz
; i
++)
21537 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
21546 #if defined HAVE_MSGPACK
21549 print_indents (int n
)
21553 for (int i
= 0; i
< n
; i
++)
21557 /* Print OBJ in human-readable form. */
21560 dump_msgpack_obj (const msgpack_object
*obj
, int indent
)
21564 case MSGPACK_OBJECT_NIL
:
21568 case MSGPACK_OBJECT_BOOLEAN
:
21569 printf ("%s", obj
->via
.boolean
? "true" : "false");
21572 case MSGPACK_OBJECT_POSITIVE_INTEGER
:
21573 printf ("%" PRIu64
, obj
->via
.u64
);
21576 case MSGPACK_OBJECT_NEGATIVE_INTEGER
:
21577 printf ("%" PRIi64
, obj
->via
.i64
);
21580 case MSGPACK_OBJECT_FLOAT32
:
21581 case MSGPACK_OBJECT_FLOAT64
:
21582 printf ("%f", obj
->via
.f64
);
21585 case MSGPACK_OBJECT_STR
:
21586 printf ("\"%.*s\"", obj
->via
.str
.size
, obj
->via
.str
.ptr
);
21589 case MSGPACK_OBJECT_ARRAY
:
21591 const msgpack_object_array
*array
= &obj
->via
.array
;
21596 for (uint32_t i
= 0; i
< array
->size
; ++i
)
21598 const msgpack_object
*item
= &array
->ptr
[i
];
21600 print_indents (indent
);
21601 dump_msgpack_obj (item
, indent
);
21606 print_indents (indent
);
21612 case MSGPACK_OBJECT_MAP
:
21614 const msgpack_object_map
*map
= &obj
->via
.map
;
21619 for (uint32_t i
= 0; i
< map
->size
; ++i
)
21621 const msgpack_object_kv
*kv
= &map
->ptr
[i
];
21622 const msgpack_object
*key
= &kv
->key
;
21623 const msgpack_object
*val
= &kv
->val
;
21625 print_indents (indent
);
21626 dump_msgpack_obj (key
, indent
);
21628 dump_msgpack_obj (val
, indent
);
21634 print_indents (indent
);
21640 case MSGPACK_OBJECT_BIN
:
21644 case MSGPACK_OBJECT_EXT
:
21651 dump_msgpack (const msgpack_unpacked
*msg
)
21654 dump_msgpack_obj (&msg
->data
, 0);
21658 #endif /* defined HAVE_MSGPACK */
21661 print_amdgpu_note (Elf_Internal_Note
*pnote
)
21663 #if defined HAVE_MSGPACK
21664 /* If msgpack is available, decode and dump the note's content. */
21666 msgpack_unpacked msg
;
21667 msgpack_unpack_return msgpack_ret
;
21669 assert (pnote
->type
== NT_AMDGPU_METADATA
);
21671 msgpack_unpacked_init (&msg
);
21672 msgpack_ret
= msgpack_unpack_next (&msg
, pnote
->descdata
, pnote
->descsz
,
21675 switch (msgpack_ret
)
21677 case MSGPACK_UNPACK_SUCCESS
:
21678 dump_msgpack (&msg
);
21683 error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note"));
21688 msgpack_unpacked_destroy (&msg
);
21691 /* msgpack is not available, dump contents as hex. */
21692 print_note_contents_hex (pnote
);
21698 print_qnx_note (Elf_Internal_Note
*pnote
)
21700 switch (pnote
->type
)
21703 if (pnote
->descsz
!= 12)
21704 goto desc_size_fail
;
21706 printf (_(" Stack Size: 0x%" PRIx32
"\n"),
21707 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4));
21708 printf (_(" Stack allocated: %" PRIx32
"\n"),
21709 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
21710 printf (_(" Executable: %s\n"),
21711 ((unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 8, 1)) ? "no": "yes");
21715 print_note_contents_hex(pnote
);
21720 printf (_(" <corrupt - data size is too small>\n"));
21721 error (_("corrupt QNX note: data size is too small\n"));
21726 /* Note that by the ELF standard, the name field is already null byte
21727 terminated, and namesz includes the terminating null byte.
21728 I.E. the value of namesz for the name "FSF" is 4.
21730 If the value of namesz is zero, there is no name present. */
21733 process_note (Elf_Internal_Note
* pnote
,
21734 Filedata
* filedata
)
21736 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
21739 if (pnote
->namesz
== 0)
21740 /* If there is no note name, then use the default set of
21741 note type strings. */
21742 nt
= get_note_type (filedata
, pnote
->type
);
21744 else if (startswith (pnote
->namedata
, "GNU"))
21745 /* GNU-specific object file notes. */
21746 nt
= get_gnu_elf_note_type (pnote
->type
);
21748 else if (startswith (pnote
->namedata
, "AMDGPU"))
21749 /* AMDGPU-specific object file notes. */
21750 nt
= get_amdgpu_elf_note_type (pnote
->type
);
21752 else if (startswith (pnote
->namedata
, "FreeBSD"))
21753 /* FreeBSD-specific core file notes. */
21754 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
21756 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
21757 /* NetBSD-specific core file notes. */
21758 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
21760 else if (startswith (pnote
->namedata
, "NetBSD"))
21761 /* NetBSD-specific core file notes. */
21762 return process_netbsd_elf_note (pnote
);
21764 else if (startswith (pnote
->namedata
, "PaX"))
21765 /* NetBSD-specific core file notes. */
21766 return process_netbsd_elf_note (pnote
);
21768 else if (startswith (pnote
->namedata
, "OpenBSD"))
21769 /* OpenBSD-specific core file notes. */
21770 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
21772 else if (startswith (pnote
->namedata
, "QNX"))
21773 /* QNX-specific core file notes. */
21774 nt
= get_qnx_elfcore_note_type (filedata
, pnote
->type
);
21776 else if (startswith (pnote
->namedata
, "SPU/"))
21778 /* SPU-specific core file notes. */
21779 nt
= pnote
->namedata
+ 4;
21783 else if (startswith (pnote
->namedata
, "IPF/VMS"))
21784 /* VMS/ia64-specific file notes. */
21785 nt
= get_ia64_vms_note_type (pnote
->type
);
21787 else if (startswith (pnote
->namedata
, "stapsdt"))
21788 nt
= get_stapsdt_note_type (pnote
->type
);
21791 /* Don't recognize this note name; just use the default set of
21792 note type strings. */
21793 nt
= get_note_type (filedata
, pnote
->type
);
21797 if (((startswith (pnote
->namedata
, "GA")
21798 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
21799 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
21800 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
21801 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
21802 print_gnu_build_attribute_name (pnote
);
21804 print_symbol (-20, name
);
21807 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
21809 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
21811 if (startswith (pnote
->namedata
, "IPF/VMS"))
21812 return print_ia64_vms_note (pnote
);
21813 else if (startswith (pnote
->namedata
, "GNU"))
21814 return print_gnu_note (filedata
, pnote
);
21815 else if (startswith (pnote
->namedata
, "stapsdt"))
21816 return print_stapsdt_note (pnote
);
21817 else if (startswith (pnote
->namedata
, "CORE"))
21818 return print_core_note (pnote
);
21819 else if (startswith (pnote
->namedata
, "FDO"))
21820 return print_fdo_note (pnote
);
21821 else if (((startswith (pnote
->namedata
, "GA")
21822 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
21823 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
21824 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
21825 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
21826 return print_gnu_build_attribute_description (pnote
, filedata
);
21827 else if (startswith (pnote
->namedata
, "AMDGPU")
21828 && pnote
->type
== NT_AMDGPU_METADATA
)
21829 return print_amdgpu_note (pnote
);
21830 else if (startswith (pnote
->namedata
, "QNX"))
21831 return print_qnx_note (pnote
);
21833 print_note_contents_hex (pnote
);
21838 process_notes_at (Filedata
* filedata
,
21839 Elf_Internal_Shdr
* section
,
21844 Elf_External_Note
*pnotes
;
21845 Elf_External_Note
*external
;
21854 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
21857 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
21865 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
21868 if (pnotes
== NULL
)
21873 if (filedata
->is_separate
)
21874 printf (_("In linked file '%s': "), filedata
->file_name
);
21878 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
21880 printf (_("Displaying notes found at file offset 0x%08" PRIx64
21881 " with length 0x%08" PRIx64
":\n"),
21884 /* NB: Some note sections may have alignment value of 0 or 1. gABI
21885 specifies that notes should be aligned to 4 bytes in 32-bit
21886 objects and to 8 bytes in 64-bit objects. As a Linux extension,
21887 we also support 4 byte alignment in 64-bit objects. If section
21888 alignment is less than 4, we treate alignment as 4 bytes. */
21891 else if (align
!= 4 && align
!= 8)
21893 warn (_("Corrupt note: alignment %" PRId64
", expecting 4 or 8\n"),
21899 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
21901 end
= (char *) pnotes
+ length
;
21902 while ((char *) external
< end
)
21904 Elf_Internal_Note inote
;
21907 char * temp
= NULL
;
21908 size_t data_remaining
= end
- (char *) external
;
21910 if (!is_ia64_vms (filedata
))
21912 /* PR binutils/15191
21913 Make sure that there is enough data to read. */
21914 min_notesz
= offsetof (Elf_External_Note
, name
);
21915 if (data_remaining
< min_notesz
)
21917 warn (ngettext ("Corrupt note: only %zd byte remains, "
21918 "not enough for a full note\n",
21919 "Corrupt note: only %zd bytes remain, "
21920 "not enough for a full note\n",
21925 data_remaining
-= min_notesz
;
21927 inote
.type
= BYTE_GET (external
->type
);
21928 inote
.namesz
= BYTE_GET (external
->namesz
);
21929 inote
.namedata
= external
->name
;
21930 inote
.descsz
= BYTE_GET (external
->descsz
);
21931 inote
.descdata
= ((char *) external
21932 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
21933 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21934 next
= ((char *) external
21935 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
21939 Elf64_External_VMS_Note
*vms_external
;
21941 /* PR binutils/15191
21942 Make sure that there is enough data to read. */
21943 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
21944 if (data_remaining
< min_notesz
)
21946 warn (ngettext ("Corrupt note: only %zd byte remains, "
21947 "not enough for a full note\n",
21948 "Corrupt note: only %zd bytes remain, "
21949 "not enough for a full note\n",
21954 data_remaining
-= min_notesz
;
21956 vms_external
= (Elf64_External_VMS_Note
*) external
;
21957 inote
.type
= BYTE_GET (vms_external
->type
);
21958 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
21959 inote
.namedata
= vms_external
->name
;
21960 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
21961 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
21962 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21963 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
21966 /* PR 17531: file: 3443835e. */
21967 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
21968 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
21969 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
21970 || (size_t) (next
- inote
.descdata
) < inote
.descsz
21971 || ((size_t) (next
- inote
.descdata
)
21972 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
21974 warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"),
21975 (char *) external
- (char *) pnotes
);
21976 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"),
21977 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
21981 external
= (Elf_External_Note
*) next
;
21983 /* Verify that name is null terminated. It appears that at least
21984 one version of Linux (RedHat 6.0) generates corefiles that don't
21985 comply with the ELF spec by failing to include the null byte in
21987 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
21989 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
21991 temp
= (char *) malloc (inote
.namesz
+ 1);
21994 error (_("Out of memory allocating space for inote name\n"));
21999 memcpy (temp
, inote
.namedata
, inote
.namesz
);
22000 inote
.namedata
= temp
;
22002 inote
.namedata
[inote
.namesz
] = 0;
22005 if (! process_note (& inote
, filedata
))
22018 process_corefile_note_segments (Filedata
* filedata
)
22020 Elf_Internal_Phdr
*segment
;
22024 if (! get_program_headers (filedata
))
22027 for (i
= 0, segment
= filedata
->program_headers
;
22028 i
< filedata
->file_header
.e_phnum
;
22031 if (segment
->p_type
== PT_NOTE
)
22032 if (! process_notes_at (filedata
, NULL
, segment
->p_offset
,
22033 segment
->p_filesz
, segment
->p_align
))
22041 process_v850_notes (Filedata
* filedata
, uint64_t offset
, uint64_t length
)
22043 Elf_External_Note
* pnotes
;
22044 Elf_External_Note
* external
;
22051 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
22053 if (pnotes
== NULL
)
22057 end
= (char*) pnotes
+ length
;
22059 printf (_("\nDisplaying contents of Renesas V850 notes section at offset"
22060 " %#" PRIx64
" with length %#" PRIx64
":\n"),
22063 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
22065 Elf_External_Note
* next
;
22066 Elf_Internal_Note inote
;
22068 inote
.type
= BYTE_GET (external
->type
);
22069 inote
.namesz
= BYTE_GET (external
->namesz
);
22070 inote
.namedata
= external
->name
;
22071 inote
.descsz
= BYTE_GET (external
->descsz
);
22072 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
22073 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
22075 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
22077 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
22078 inote
.descdata
= inote
.namedata
;
22082 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
22084 if ( ((char *) next
> end
)
22085 || ((char *) next
< (char *) pnotes
))
22087 warn (_("corrupt descsz found in note at offset %#tx\n"),
22088 (char *) external
- (char *) pnotes
);
22089 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"),
22090 inote
.type
, inote
.namesz
, inote
.descsz
);
22096 /* Prevent out-of-bounds indexing. */
22097 if ( inote
.namedata
+ inote
.namesz
> end
22098 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
22100 warn (_("corrupt namesz found in note at offset %#zx\n"),
22101 (char *) external
- (char *) pnotes
);
22102 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"),
22103 inote
.type
, inote
.namesz
, inote
.descsz
);
22107 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
22109 if (! print_v850_note (& inote
))
22112 printf ("<corrupt sizes: namesz: %#lx, descsz: %#lx>\n",
22113 inote
.namesz
, inote
.descsz
);
22123 process_note_sections (Filedata
* filedata
)
22125 Elf_Internal_Shdr
*section
;
22127 unsigned int n
= 0;
22130 for (i
= 0, section
= filedata
->section_headers
;
22131 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
22134 if (section
->sh_type
== SHT_NOTE
)
22136 if (! process_notes_at (filedata
, section
, section
->sh_offset
,
22137 section
->sh_size
, section
->sh_addralign
))
22142 if (( filedata
->file_header
.e_machine
== EM_V800
22143 || filedata
->file_header
.e_machine
== EM_V850
22144 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
22145 && section
->sh_type
== SHT_RENESAS_INFO
)
22147 if (! process_v850_notes (filedata
, section
->sh_offset
,
22155 /* Try processing NOTE segments instead. */
22156 return process_corefile_note_segments (filedata
);
22162 process_notes (Filedata
* filedata
)
22164 /* If we have not been asked to display the notes then do nothing. */
22168 if (filedata
->file_header
.e_type
!= ET_CORE
)
22169 return process_note_sections (filedata
);
22171 /* No program headers means no NOTE segment. */
22172 if (filedata
->file_header
.e_phnum
> 0)
22173 return process_corefile_note_segments (filedata
);
22175 if (filedata
->is_separate
)
22176 printf (_("No notes found in linked file '%s'.\n"),
22177 filedata
->file_name
);
22179 printf (_("No notes found file.\n"));
22184 static unsigned char *
22185 display_public_gnu_attributes (unsigned char * start
,
22186 const unsigned char * const end
)
22188 printf (_(" Unknown GNU attribute: %s\n"), start
);
22190 start
+= strnlen ((char *) start
, end
- start
);
22191 display_raw_attribute (start
, end
);
22193 return (unsigned char *) end
;
22196 static unsigned char *
22197 display_generic_attribute (unsigned char * start
,
22199 const unsigned char * const end
)
22202 return (unsigned char *) end
;
22204 return display_tag_value (tag
, start
, end
);
22208 process_arch_specific (Filedata
* filedata
)
22213 switch (filedata
->file_header
.e_machine
)
22216 case EM_ARC_COMPACT
:
22217 case EM_ARC_COMPACT2
:
22218 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
22219 display_arc_attribute
,
22220 display_generic_attribute
);
22222 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
22223 display_arm_attribute
,
22224 display_generic_attribute
);
22227 case EM_MIPS_RS3_LE
:
22228 return process_mips_specific (filedata
);
22231 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
22232 display_msp430_attribute
,
22233 display_msp430_gnu_attribute
);
22236 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
22237 display_riscv_attribute
,
22238 display_generic_attribute
);
22241 return process_nds32_specific (filedata
);
22244 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22245 display_m68k_gnu_attribute
);
22249 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22250 display_power_gnu_attribute
);
22254 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22255 display_s390_gnu_attribute
);
22258 case EM_SPARC32PLUS
:
22260 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22261 display_sparc_gnu_attribute
);
22264 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
22265 display_tic6x_attribute
,
22266 display_generic_attribute
);
22269 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
22270 display_csky_attribute
, NULL
);
22273 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
22274 display_public_gnu_attributes
,
22275 display_generic_attribute
);
22280 get_file_header (Filedata
* filedata
)
22282 /* Read in the identity array. */
22283 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
22286 /* Determine how to read the rest of the header. */
22287 switch (filedata
->file_header
.e_ident
[EI_DATA
])
22292 byte_get
= byte_get_little_endian
;
22293 byte_put
= byte_put_little_endian
;
22296 byte_get
= byte_get_big_endian
;
22297 byte_put
= byte_put_big_endian
;
22301 /* For now we only support 32 bit and 64 bit ELF files. */
22302 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
22304 /* Read in the rest of the header. */
22307 Elf32_External_Ehdr ehdr32
;
22309 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22312 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
22313 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
22314 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
22315 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
22316 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
22317 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
22318 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
22319 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
22320 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
22321 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
22322 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
22323 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
22324 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
22328 Elf64_External_Ehdr ehdr64
;
22330 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22333 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
22334 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
22335 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
22336 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
22337 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
22338 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
22339 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
22340 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
22341 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
22342 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
22343 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
22344 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
22345 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
22352 free_filedata (Filedata
*filedata
)
22354 free (filedata
->program_interpreter
);
22355 free (filedata
->program_headers
);
22356 free (filedata
->section_headers
);
22357 free (filedata
->string_table
);
22358 free (filedata
->dump
.dump_sects
);
22359 free (filedata
->dynamic_strings
);
22360 free (filedata
->dynamic_symbols
);
22361 free (filedata
->dynamic_syminfo
);
22362 free (filedata
->dynamic_section
);
22364 while (filedata
->symtab_shndx_list
!= NULL
)
22366 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
22367 free (filedata
->symtab_shndx_list
);
22368 filedata
->symtab_shndx_list
= next
;
22371 free (filedata
->section_headers_groups
);
22373 if (filedata
->section_groups
)
22376 struct group_list
* g
;
22377 struct group_list
* next
;
22379 for (i
= 0; i
< filedata
->group_count
; i
++)
22381 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
22388 free (filedata
->section_groups
);
22390 memset (&filedata
->section_headers
, 0,
22391 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
22395 close_file (Filedata
* filedata
)
22399 if (filedata
->handle
)
22400 fclose (filedata
->handle
);
22406 close_debug_file (void * data
)
22408 free_filedata ((Filedata
*) data
);
22409 close_file ((Filedata
*) data
);
22413 open_file (const char * pathname
, bool is_separate
)
22415 struct stat statbuf
;
22416 Filedata
* filedata
= NULL
;
22418 if (stat (pathname
, & statbuf
) < 0
22419 || ! S_ISREG (statbuf
.st_mode
))
22422 filedata
= calloc (1, sizeof * filedata
);
22423 if (filedata
== NULL
)
22426 filedata
->handle
= fopen (pathname
, "rb");
22427 if (filedata
->handle
== NULL
)
22430 filedata
->file_size
= statbuf
.st_size
;
22431 filedata
->file_name
= pathname
;
22432 filedata
->is_separate
= is_separate
;
22434 if (! get_file_header (filedata
))
22437 if (!get_section_headers (filedata
, false))
22445 if (filedata
->handle
)
22446 fclose (filedata
->handle
);
22453 open_debug_file (const char * pathname
)
22455 return open_file (pathname
, true);
22459 initialise_dump_sects (Filedata
* filedata
)
22461 /* Initialise the dump_sects array from the cmdline_dump_sects array.
22462 Note we do this even if cmdline_dump_sects is empty because we
22463 must make sure that the dump_sets array is zeroed out before each
22464 object file is processed. */
22465 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
22466 memset (filedata
->dump
.dump_sects
, 0,
22467 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
22469 if (cmdline
.num_dump_sects
> 0)
22471 if (filedata
->dump
.num_dump_sects
== 0)
22472 /* A sneaky way of allocating the dump_sects array. */
22473 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
22475 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
22476 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
22477 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
22482 might_need_separate_debug_info (Filedata
* filedata
)
22484 /* Debuginfo files do not need further separate file loading. */
22485 if (filedata
->file_header
.e_shstrndx
== SHN_UNDEF
)
22488 /* Since do_follow_links might be enabled by default, only treat it as an
22489 indication that separate files should be loaded if setting it was a
22490 deliberate user action. */
22491 if (DEFAULT_FOR_FOLLOW_LINKS
== 0 && do_follow_links
)
22494 if (process_links
|| do_syms
|| do_unwind
22495 || dump_any_debugging
|| do_dump
|| do_debugging
)
22501 /* Process one ELF object file according to the command line options.
22502 This file may actually be stored in an archive. The file is
22503 positioned at the start of the ELF object. Returns TRUE if no
22504 problems were encountered, FALSE otherwise. */
22507 process_object (Filedata
* filedata
)
22509 bool have_separate_files
;
22513 if (! get_file_header (filedata
))
22515 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
22519 /* Initialise per file variables. */
22520 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
22521 filedata
->version_info
[i
] = 0;
22523 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
22524 filedata
->dynamic_info
[i
] = 0;
22525 filedata
->dynamic_info_DT_GNU_HASH
= 0;
22526 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
22528 /* Process the file. */
22530 printf (_("\nFile: %s\n"), filedata
->file_name
);
22532 initialise_dump_sects (filedata
);
22534 /* There may be some extensions in the first section header. Don't
22535 bomb if we can't read it. */
22536 get_section_headers (filedata
, true);
22538 if (! process_file_header (filedata
))
22544 /* Throw away the single section header read above, so that we
22545 re-read the entire set. */
22546 free (filedata
->section_headers
);
22547 filedata
->section_headers
= NULL
;
22549 if (! process_section_headers (filedata
))
22551 /* Without loaded section headers we cannot process lots of things. */
22552 do_unwind
= do_version
= do_dump
= do_arch
= false;
22554 if (! do_using_dynamic
)
22555 do_syms
= do_dyn_syms
= do_reloc
= false;
22558 if (! process_section_groups (filedata
))
22559 /* Without loaded section groups we cannot process unwind. */
22562 process_program_headers (filedata
);
22564 res
= process_dynamic_section (filedata
);
22566 if (! process_relocs (filedata
))
22569 if (! process_unwind (filedata
))
22572 if (! process_symbol_table (filedata
))
22575 if (! process_lto_symbol_tables (filedata
))
22578 if (! process_syminfo (filedata
))
22581 if (! process_version_sections (filedata
))
22584 if (might_need_separate_debug_info (filedata
))
22585 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
22587 have_separate_files
= false;
22589 if (! process_section_contents (filedata
))
22592 if (have_separate_files
)
22596 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
22598 initialise_dump_sects (d
->handle
);
22600 if (process_links
&& ! process_file_header (d
->handle
))
22602 else if (! process_section_headers (d
->handle
))
22604 else if (! process_section_contents (d
->handle
))
22606 else if (process_links
)
22608 if (! process_section_groups (d
->handle
))
22610 process_program_headers (d
->handle
);
22611 if (! process_dynamic_section (d
->handle
))
22613 if (! process_relocs (d
->handle
))
22615 if (! process_unwind (d
->handle
))
22617 if (! process_symbol_table (d
->handle
))
22619 if (! process_lto_symbol_tables (d
->handle
))
22621 if (! process_syminfo (d
->handle
))
22623 if (! process_version_sections (d
->handle
))
22625 if (! process_notes (d
->handle
))
22630 /* The file handles are closed by the call to free_debug_memory() below. */
22633 if (! process_notes (filedata
))
22636 if (! process_gnu_liblist (filedata
))
22639 if (! process_arch_specific (filedata
))
22643 free_filedata (filedata
);
22645 free_debug_memory ();
22650 /* Process an ELF archive.
22651 On entry the file is positioned just after the ARMAG string.
22652 Returns TRUE upon success, FALSE otherwise. */
22655 process_archive (Filedata
* filedata
, bool is_thin_archive
)
22657 struct archive_info arch
;
22658 struct archive_info nested_arch
;
22664 /* The ARCH structure is used to hold information about this archive. */
22665 arch
.file_name
= NULL
;
22667 arch
.index_array
= NULL
;
22668 arch
.sym_table
= NULL
;
22669 arch
.longnames
= NULL
;
22671 /* The NESTED_ARCH structure is used as a single-item cache of information
22672 about a nested archive (when members of a thin archive reside within
22673 another regular archive file). */
22674 nested_arch
.file_name
= NULL
;
22675 nested_arch
.file
= NULL
;
22676 nested_arch
.index_array
= NULL
;
22677 nested_arch
.sym_table
= NULL
;
22678 nested_arch
.longnames
= NULL
;
22680 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
22681 filedata
->file_size
, is_thin_archive
,
22682 do_archive_index
) != 0)
22688 if (do_archive_index
)
22690 if (arch
.sym_table
== NULL
)
22691 error (_("%s: unable to dump the index as none was found\n"),
22692 filedata
->file_name
);
22696 uint64_t current_pos
;
22698 printf (_("Index of archive %s: (%" PRIu64
" entries,"
22699 " %#" PRIx64
" bytes in the symbol table)\n"),
22700 filedata
->file_name
, arch
.index_num
,
22703 current_pos
= ftell (filedata
->handle
);
22705 for (i
= l
= 0; i
< arch
.index_num
; i
++)
22708 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
22711 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
22714 if (member_name
!= NULL
)
22716 char * qualified_name
22717 = make_qualified_name (&arch
, &nested_arch
,
22720 if (qualified_name
!= NULL
)
22722 printf (_("Contents of binary %s at offset "),
22724 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
22726 free (qualified_name
);
22728 free (member_name
);
22732 if (l
>= arch
.sym_size
)
22734 error (_("%s: end of the symbol table reached "
22735 "before the end of the index\n"),
22736 filedata
->file_name
);
22740 /* PR 17531: file: 0b6630b2. */
22741 printf ("\t%.*s\n",
22742 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
22743 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
22746 if (arch
.uses_64bit_indices
)
22751 if (l
< arch
.sym_size
)
22753 error (ngettext ("%s: %" PRId64
" byte remains in the symbol table, "
22754 "but without corresponding entries in "
22755 "the index table\n",
22756 "%s: %" PRId64
" bytes remain in the symbol table, "
22757 "but without corresponding entries in "
22758 "the index table\n",
22759 arch
.sym_size
- l
),
22760 filedata
->file_name
, arch
.sym_size
- l
);
22764 if (fseek64 (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
22766 error (_("%s: failed to seek back to start of object files "
22767 "in the archive\n"),
22768 filedata
->file_name
);
22774 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
22775 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
22776 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
22777 && !do_section_groups
&& !do_dyn_syms
)
22779 ret
= true; /* Archive index only. */
22788 char * qualified_name
;
22790 /* Read the next archive header. */
22791 if (fseek64 (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
22793 error (_("%s: failed to seek to next archive header\n"),
22798 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
22799 if (got
!= sizeof arch
.arhdr
)
22803 /* PR 24049 - we cannot use filedata->file_name as this will
22804 have already been freed. */
22805 error (_("%s: failed to read archive header\n"), arch
.file_name
);
22810 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
22812 error (_("%s: did not find a valid archive header\n"),
22818 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
22820 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
22822 name
= get_archive_member_name (&arch
, &nested_arch
);
22825 error (_("%s: bad archive file name\n"), arch
.file_name
);
22829 namelen
= strlen (name
);
22831 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
22832 if (qualified_name
== NULL
)
22834 error (_("%s: bad archive file name\n"), arch
.file_name
);
22840 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
22842 /* This is a proxy for an external member of a thin archive. */
22843 Filedata
* member_filedata
;
22844 char * member_file_name
= adjust_relative_path
22845 (filedata
->file_name
, name
, namelen
);
22848 if (member_file_name
== NULL
)
22850 free (qualified_name
);
22855 member_filedata
= open_file (member_file_name
, false);
22856 if (member_filedata
== NULL
)
22858 error (_("Input file '%s' is not readable.\n"), member_file_name
);
22859 free (member_file_name
);
22860 free (qualified_name
);
22865 filedata
->archive_file_offset
= arch
.nested_member_origin
;
22866 member_filedata
->file_name
= qualified_name
;
22868 /* The call to process_object() expects the file to be at the beginning. */
22869 rewind (member_filedata
->handle
);
22871 if (! process_object (member_filedata
))
22874 close_file (member_filedata
);
22875 free (member_file_name
);
22877 else if (is_thin_archive
)
22879 Filedata thin_filedata
;
22881 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
22883 /* PR 15140: Allow for corrupt thin archives. */
22884 if (nested_arch
.file
== NULL
)
22886 error (_("%s: contains corrupt thin archive: %s\n"),
22887 qualified_name
, name
);
22888 free (qualified_name
);
22895 /* This is a proxy for a member of a nested archive. */
22896 filedata
->archive_file_offset
22897 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
22899 /* The nested archive file will have been opened and setup by
22900 get_archive_member_name. */
22901 if (fseek64 (nested_arch
.file
, filedata
->archive_file_offset
,
22904 error (_("%s: failed to seek to archive member.\n"),
22905 nested_arch
.file_name
);
22906 free (qualified_name
);
22911 thin_filedata
.handle
= nested_arch
.file
;
22912 thin_filedata
.file_name
= qualified_name
;
22914 if (! process_object (& thin_filedata
))
22920 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
22921 filedata
->file_name
= qualified_name
;
22922 if (! process_object (filedata
))
22924 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
22925 /* Stop looping with "negative" archive_file_size. */
22926 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
22927 arch
.next_arhdr_offset
= -1ul;
22930 free (qualified_name
);
22934 if (nested_arch
.file
!= NULL
)
22935 fclose (nested_arch
.file
);
22936 release_archive (&nested_arch
);
22937 release_archive (&arch
);
22943 process_file (char * file_name
)
22945 Filedata
* filedata
= NULL
;
22946 struct stat statbuf
;
22947 char armag
[SARMAG
];
22950 if (stat (file_name
, &statbuf
) < 0)
22952 if (errno
== ENOENT
)
22953 error (_("'%s': No such file\n"), file_name
);
22955 error (_("Could not locate '%s'. System error message: %s\n"),
22956 file_name
, strerror (errno
));
22960 if (! S_ISREG (statbuf
.st_mode
))
22962 error (_("'%s' is not an ordinary file\n"), file_name
);
22966 filedata
= calloc (1, sizeof * filedata
);
22967 if (filedata
== NULL
)
22969 error (_("Out of memory allocating file data structure\n"));
22973 filedata
->file_name
= file_name
;
22974 filedata
->handle
= fopen (file_name
, "rb");
22975 if (filedata
->handle
== NULL
)
22977 error (_("Input file '%s' is not readable.\n"), file_name
);
22982 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
22984 error (_("%s: Failed to read file's magic number\n"), file_name
);
22985 fclose (filedata
->handle
);
22990 filedata
->file_size
= statbuf
.st_size
;
22991 filedata
->is_separate
= false;
22993 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
22995 if (! process_archive (filedata
, false))
22998 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
23000 if ( ! process_archive (filedata
, true))
23005 if (do_archive_index
&& !check_all
)
23006 error (_("File %s is not an archive so its index cannot be displayed.\n"),
23009 rewind (filedata
->handle
);
23010 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
23012 if (! process_object (filedata
))
23016 fclose (filedata
->handle
);
23017 free (filedata
->section_headers
);
23018 free (filedata
->program_headers
);
23019 free (filedata
->string_table
);
23020 free (filedata
->dump
.dump_sects
);
23023 free (ba_cache
.strtab
);
23024 ba_cache
.strtab
= NULL
;
23025 free (ba_cache
.symtab
);
23026 ba_cache
.symtab
= NULL
;
23027 ba_cache
.filedata
= NULL
;
23032 #ifdef SUPPORT_DISASSEMBLY
23033 /* Needed by the i386 disassembler. For extra credit, someone could
23034 fix this so that we insert symbolic addresses here, esp for GOT/PLT
23038 print_address (unsigned int addr
, FILE * outfile
)
23040 fprintf (outfile
,"0x%8.8x", addr
);
23043 /* Needed by the i386 disassembler. */
23046 db_task_printsym (unsigned int addr
)
23048 print_address (addr
, stderr
);
23053 main (int argc
, char ** argv
)
23057 #ifdef HAVE_LC_MESSAGES
23058 setlocale (LC_MESSAGES
, "");
23060 setlocale (LC_CTYPE
, "");
23061 bindtextdomain (PACKAGE
, LOCALEDIR
);
23062 textdomain (PACKAGE
);
23064 expandargv (&argc
, &argv
);
23066 parse_args (& cmdline
, argc
, argv
);
23068 if (optind
< (argc
- 1))
23069 /* When displaying information for more than one file,
23070 prefix the information with the file name. */
23072 else if (optind
>= argc
)
23074 /* Ensure that the warning is always displayed. */
23077 warn (_("Nothing to do.\n"));
23082 while (optind
< argc
)
23083 if (! process_file (argv
[optind
++]))
23086 free (cmdline
.dump_sects
);
23088 free (dump_ctf_symtab_name
);
23089 free (dump_ctf_strtab_name
);
23090 free (dump_ctf_parent_name
);
23092 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;