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"
125 #include "elf/lm32.h"
126 #include "elf/iq2000.h"
127 #include "elf/m32c.h"
128 #include "elf/m32r.h"
129 #include "elf/m68k.h"
130 #include "elf/m68hc11.h"
131 #include "elf/s12z.h"
132 #include "elf/mcore.h"
134 #include "elf/metag.h"
135 #include "elf/microblaze.h"
136 #include "elf/mips.h"
137 #include "elf/mmix.h"
138 #include "elf/mn10200.h"
139 #include "elf/mn10300.h"
140 #include "elf/moxie.h"
142 #include "elf/msp430.h"
143 #include "elf/nds32.h"
145 #include "elf/nios2.h"
146 #include "elf/or1k.h"
149 #include "elf/ppc64.h"
151 #include "elf/riscv.h"
152 #include "elf/rl78.h"
154 #include "elf/s390.h"
155 #include "elf/score.h"
157 #include "elf/sparc.h"
159 #include "elf/tic6x.h"
160 #include "elf/tilegx.h"
161 #include "elf/tilepro.h"
162 #include "elf/v850.h"
164 #include "elf/visium.h"
165 #include "elf/wasm32.h"
166 #include "elf/x86-64.h"
167 #include "elf/xgate.h"
168 #include "elf/xstormy16.h"
169 #include "elf/xtensa.h"
171 #include "elf/loongarch.h"
175 #include "libiberty.h"
176 #include "safe-ctype.h"
177 #include "filenames.h"
180 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
183 typedef struct elf_section_list
185 Elf_Internal_Shdr
* hdr
;
186 struct elf_section_list
* next
;
189 /* Flag bits indicating particular types of dump. */
190 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
191 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
192 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
193 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
194 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
195 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
196 #define SFRAME_DUMP (1 << 6) /* The --sframe command line switch. */
198 typedef unsigned char dump_type
;
200 /* A linked list of the section names for which dumps were requested. */
201 struct dump_list_entry
205 struct dump_list_entry
* next
;
208 /* A dynamic array of flags indicating for which sections a dump
209 has been requested via command line switches. */
212 dump_type
* dump_sects
;
213 unsigned int num_dump_sects
;
216 static struct dump_data cmdline
;
218 static struct dump_list_entry
* dump_sects_byname
;
220 char * program_name
= "readelf";
222 static bool show_name
= false;
223 static bool do_dynamic
= false;
224 static bool do_syms
= false;
225 static bool do_dyn_syms
= false;
226 static bool do_lto_syms
= false;
227 static bool do_reloc
= false;
228 static bool do_sections
= false;
229 static bool do_section_groups
= false;
230 static bool do_section_details
= false;
231 static bool do_segments
= false;
232 static bool do_unwind
= false;
233 static bool do_using_dynamic
= false;
234 static bool do_header
= false;
235 static bool do_dump
= false;
236 static bool do_version
= false;
237 static bool do_histogram
= false;
238 static bool do_debugging
= false;
239 static bool do_ctf
= false;
240 static bool do_sframe
= false;
241 static bool do_arch
= false;
242 static bool do_notes
= false;
243 static bool do_archive_index
= false;
244 static bool check_all
= false;
245 static bool is_32bit_elf
= false;
246 static bool decompress_dumps
= false;
247 static bool do_not_show_symbol_truncation
= false;
248 static bool do_demangle
= false; /* Pretty print C++ symbol names. */
249 static bool process_links
= false;
250 static bool dump_any_debugging
= false;
251 static bool extra_sym_info
= false;
252 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
253 static int sym_base
= 0;
255 static char *dump_ctf_parent_name
;
256 static char *dump_ctf_symtab_name
;
257 static char *dump_ctf_strtab_name
;
261 struct group_list
* next
;
262 unsigned int section_index
;
267 struct group_list
* root
;
268 unsigned int group_index
;
271 typedef struct filedata
273 const char * file_name
;
277 Elf_Internal_Ehdr file_header
;
278 uint64_t archive_file_offset
;
279 uint64_t archive_file_size
;
280 /* Everything below this point is cleared out by free_filedata. */
281 Elf_Internal_Shdr
* section_headers
;
282 Elf_Internal_Phdr
* program_headers
;
284 uint64_t string_table_length
;
285 uint64_t dynamic_addr
;
286 uint64_t dynamic_size
;
287 uint64_t dynamic_nent
;
288 Elf_Internal_Dyn
* dynamic_section
;
289 Elf_Internal_Shdr
* dynamic_strtab_section
;
290 char * dynamic_strings
;
291 uint64_t dynamic_strings_length
;
292 Elf_Internal_Shdr
* dynamic_symtab_section
;
293 uint64_t num_dynamic_syms
;
294 Elf_Internal_Sym
* dynamic_symbols
;
295 uint64_t version_info
[16];
296 unsigned int dynamic_syminfo_nent
;
297 Elf_Internal_Syminfo
* dynamic_syminfo
;
298 uint64_t dynamic_syminfo_offset
;
303 uint64_t ngnubuckets
;
305 uint64_t * gnubuckets
;
306 uint64_t * gnuchains
;
309 char * program_interpreter
;
310 uint64_t dynamic_info
[DT_RELRENT
+ 1];
311 uint64_t dynamic_info_DT_GNU_HASH
;
312 uint64_t dynamic_info_DT_MIPS_XHASH
;
313 elf_section_list
* symtab_shndx_list
;
315 struct group
* section_groups
;
316 struct group
** section_headers_groups
;
317 /* A dynamic array of flags indicating for which sections a dump of
318 some kind has been requested. It is reset on a per-object file
319 basis and then initialised from the cmdline_dump_sects array,
320 the results of interpreting the -w switch, and the
321 dump_sects_byname list. */
322 struct dump_data dump
;
325 /* How to print a vma value. */
326 typedef enum print_mode
343 typedef enum unicode_display_type
351 } unicode_display_type
;
353 static unicode_display_type unicode_display
= unicode_default
;
363 /* Versioned symbol info. */
364 enum versioned_symbol_info
372 fseek64 (FILE *stream
, int64_t offset
, int whence
)
374 #if defined (HAVE_FSEEKO64)
381 return fseeko64 (stream
, o
, whence
);
382 #elif defined (HAVE_FSEEKO)
389 return fseeko (stream
, o
, whence
);
397 return fseek (stream
, o
, whence
);
401 static const char * get_symbol_version_string
402 (Filedata
*, bool, const char *, size_t, unsigned,
403 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
407 static inline const char *
408 section_name (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
410 return filedata
->string_table
+ hdr
->sh_name
;
414 section_name_valid (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
416 return (filedata
!= NULL
418 && filedata
->string_table
!= NULL
419 && hdr
->sh_name
< filedata
->string_table_length
);
422 /* Returns true if the given index is real/valid. Note: "real" here
423 means "references a real section in the section header" and not
424 "is a valid section index as per the ELF standard". */
427 section_index_real (const Filedata
*filedata
, unsigned int ndx
)
429 return (filedata
!= NULL
430 && filedata
->section_headers
!= NULL
431 && ndx
< filedata
->file_header
.e_shnum
435 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
438 valid_symbol_name (const char *strtab
, size_t strtab_size
, uint64_t offset
)
440 return strtab
!= NULL
&& offset
< strtab_size
;
444 valid_dynamic_name (const Filedata
*filedata
, uint64_t offset
)
446 return valid_symbol_name (filedata
->dynamic_strings
,
447 filedata
->dynamic_strings_length
, offset
);
450 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
451 already been called and verified that the string exists. */
452 static inline const char *
453 get_dynamic_name (const Filedata
*filedata
, size_t offset
)
455 return filedata
->dynamic_strings
+ offset
;
458 #define REMOVE_ARCH_BITS(ADDR) \
461 if (filedata->file_header.e_machine == EM_ARM) \
466 /* Get the correct GNU hash section name. */
467 #define GNU_HASH_SECTION_NAME(filedata) \
468 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
470 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
471 OFFSET + the offset of the current archive member, if we are examining an
472 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
473 allocate a buffer using malloc and fill that. In either case return the
474 pointer to the start of the retrieved data or NULL if something went wrong.
475 If something does go wrong and REASON is not NULL then emit an error
476 message using REASON as part of the context. */
487 uint64_t amt
= size
* nmemb
;
489 if (size
== 0 || nmemb
== 0)
492 /* If size_t is smaller than uint64_t, eg because you are building
493 on a 32-bit host, then make sure that when the sizes are cast to
494 size_t no information is lost. */
495 if ((size_t) size
!= size
496 || (size_t) nmemb
!= nmemb
497 || (size_t) amt
!= amt
498 || amt
/ size
!= nmemb
499 || (size_t) amt
+ 1 == 0)
502 error (_("Size overflow prevents reading %" PRIu64
503 " elements of size %" PRIu64
" for %s\n"),
504 nmemb
, size
, reason
);
508 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
509 attempting to allocate memory when the read is bound to fail. */
510 if (filedata
->archive_file_offset
> filedata
->file_size
511 || offset
> filedata
->file_size
- filedata
->archive_file_offset
512 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
515 error (_("Reading %" PRIu64
" bytes extends past end of file for %s\n"),
520 if (fseek64 (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
524 error (_("Unable to seek to %#" PRIx64
" for %s\n"),
525 filedata
->archive_file_offset
+ offset
, reason
);
532 /* + 1 so that we can '\0' terminate invalid string table sections. */
533 mvar
= malloc ((size_t) amt
+ 1);
538 error (_("Out of memory allocating %" PRIu64
" bytes for %s\n"),
543 ((char *) mvar
)[amt
] = '\0';
546 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
549 error (_("Unable to read in %" PRIu64
" bytes of %s\n"),
559 /* Print a VMA value in the MODE specified.
560 Returns the number of characters displayed. */
563 print_vma (uint64_t vma
, print_mode mode
)
574 return nc
+ printf ("%16.16" PRIx64
, vma
);
575 return nc
+ printf ("%8.8" PRIx64
, vma
);
579 return printf ("%5" PRId64
, vma
);
585 return nc
+ printf ("%" PRIx64
, vma
);
591 return nc
+ printf ("%05" PRIx64
, vma
);
594 return printf ("%" PRId64
, vma
);
597 return printf ("%" PRIu64
, vma
);
600 return printf ("%5" PRIu64
, vma
);
603 return printf ("%" PRIo64
, vma
);
606 return printf ("%5" PRIo64
, vma
);
609 /* FIXME: Report unrecognised mode ? */
615 /* Display a symbol on stdout. Handles the display of control characters and
616 multibye characters (assuming the host environment supports them).
618 Display at most abs(WIDTH) characters, truncating as necessary,
619 unless do_wide or extra_sym_info is true.
621 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
622 abs(WIDTH) - 5 characters followed by "[...]".
624 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
625 padding as necessary.
627 Returns the number of emitted characters. */
630 print_symbol_name (signed int width
, const char * symbol
)
632 bool extra_padding
= false;
633 bool do_dots
= false;
634 signed int num_printed
= 0;
635 #ifdef HAVE_MBSTATE_T
638 unsigned int width_remaining
;
639 const void * alloced_symbol
= NULL
;
643 /* Keep the width positive. This helps the code below. */
645 extra_padding
= true;
650 if (do_wide
|| extra_sym_info
)
651 /* Set the remaining width to a very large value.
652 This simplifies the code below. */
653 width_remaining
= INT_MAX
;
656 width_remaining
= width
;
658 if (! do_not_show_symbol_truncation
659 && (int) strlen (symbol
) > width
)
661 width_remaining
-= 5;
662 if ((int) width_remaining
< 0)
668 #ifdef HAVE_MBSTATE_T
669 /* Initialise the multibyte conversion state. */
670 memset (& state
, 0, sizeof (state
));
673 if (do_demangle
&& *symbol
)
675 const char * res
= cplus_demangle (symbol
, demangle_flags
);
678 alloced_symbol
= symbol
= res
;
681 while (width_remaining
)
684 const char c
= *symbol
++;
695 else if (ISCNTRL (c
))
697 /* Do not print control characters directly as they can affect terminal
698 settings. Such characters usually appear in the names generated
699 by the assembler for local labels. */
701 if (width_remaining
< 2)
704 printf ("^%c", c
+ 0x40);
705 width_remaining
-= 2;
710 if (width_remaining
< 5)
713 width_remaining
-= 5;
716 else if (unicode_display
!= unicode_locale
717 && unicode_display
!= unicode_default
)
719 /* Display unicode characters as something else. */
720 unsigned char bytes
[4];
733 bytes
[1] = *symbol
++;
735 if ((bytes
[1] & 0xc0) != 0x80)
738 /* Do not consume this character. It may only
739 be the first byte in the sequence that was
744 else if ((bytes
[0] & 0x20) == 0)
751 bytes
[2] = *symbol
++;
753 if ((bytes
[2] & 0xc0) != 0x80)
759 else if ((bytes
[0] & 0x10) == 0)
766 bytes
[3] = *symbol
++;
770 if ((bytes
[3] & 0xc0) != 0x80)
782 if (unicode_display
== unicode_invalid
)
785 if (unicode_display
== unicode_hex
|| ! is_utf8
)
789 if (width_remaining
< (nbytes
* 2) + 2)
792 putchar (is_utf8
? '<' : '{');
794 for (i
= 0; i
< nbytes
; i
++)
795 printf ("%02x", bytes
[i
]);
796 putchar (is_utf8
? '>' : '}');
800 if (unicode_display
== unicode_highlight
&& isatty (1))
801 printf ("\x1B[31;47m"); /* Red. */
806 if (width_remaining
< 6)
808 printf ("\\u%02x%02x",
809 (bytes
[0] & 0x1c) >> 2,
810 ((bytes
[0] & 0x03) << 6) | (bytes
[1] & 0x3f));
813 if (width_remaining
< 6)
815 printf ("\\u%02x%02x",
816 ((bytes
[0] & 0x0f) << 4) | ((bytes
[1] & 0x3c) >> 2),
817 ((bytes
[1] & 0x03) << 6) | (bytes
[2] & 0x3f));
820 if (width_remaining
< 8)
822 printf ("\\u%02x%02x%02x",
823 ((bytes
[0] & 0x07) << 6) | ((bytes
[1] & 0x3c) >> 2),
824 ((bytes
[1] & 0x03) << 6) | ((bytes
[2] & 0x3c) >> 2),
825 ((bytes
[2] & 0x03) << 6) | (bytes
[3] & 0x3f));
833 if (unicode_display
== unicode_highlight
&& isatty (1))
834 printf ("\033[0m"); /* Default colour. */
837 if (bytes
[nbytes
- 1] == 0)
842 #ifdef HAVE_MBSTATE_T
845 /* Let printf do the hard work of displaying multibyte characters. */
846 printf ("%.1s", symbol
- 1);
850 #ifdef HAVE_MBSTATE_T
851 /* Try to find out how many bytes made up the character that was
852 just printed. Advance the symbol pointer past the bytes that
854 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
858 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
864 num_printed
+= printf ("[...]");
866 if (extra_padding
&& num_printed
< width
)
868 /* Fill in the remaining spaces. */
869 printf ("%-*s", width
- num_printed
, " ");
873 free ((void *) alloced_symbol
);
877 /* Returns a pointer to a static buffer containing a printable version of
878 the given section's name. Like print_symbol, except that it does not try
879 to print multibyte characters, it just interprets them as hex values. */
882 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
884 #define NUM_SEC_NAME_BUFS 5
885 #define MAX_PRINT_SEC_NAME_LEN 256
887 static int sec_name_buf_index
= 0;
888 /* We use a rotating array of static buffers, so that multiple successive calls
889 to printable_section_name() will still work. eg when used in a printf. */
890 static char sec_name_buf
[NUM_SEC_NAME_BUFS
][MAX_PRINT_SEC_NAME_LEN
+ 1];
896 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
898 /* Validate the input parameters. */
899 if (filedata
== NULL
)
900 return _("<internal error>");
903 if (filedata
->string_table
== NULL
)
904 return _("<no-strings>");
905 if (sec
->sh_name
>= filedata
->string_table_length
)
906 return _("<corrupt>");
908 /* Select a buffer to use. */
909 buf_start
= buf
= sec_name_buf
[sec_name_buf_index
];
910 if (++sec_name_buf_index
>= NUM_SEC_NAME_BUFS
)
911 sec_name_buf_index
= 0;
913 name
= section_name (filedata
, sec
);
915 while ((c
= * name
++) != 0)
926 else if (ISPRINT (c
))
933 static char hex
[17] = "0123456789ABCDEF";
938 * buf
++ = hex
[(c
& 0xf0) >> 4];
939 * buf
++ = hex
[c
& 0x0f];
952 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
953 This OS has so many departures from the ELF standard that we test it at
957 is_ia64_vms (Filedata
* filedata
)
959 return filedata
->file_header
.e_machine
== EM_IA_64
960 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
964 printable_section_name_from_index (Filedata
* filedata
,
968 if (is_special
!= NULL
)
973 case SHN_UNDEF
: return "UND";
974 case SHN_ABS
: return "ABS";
975 case SHN_COMMON
: return "COM";
979 if (filedata
!= NULL
)
981 switch (filedata
->file_header
.e_machine
)
984 if (ndx
== SHN_MIPS_SCOMMON
)
986 if (ndx
== SHN_MIPS_SUNDEFINED
)
991 if (ndx
== SHN_TIC6X_SCOMMON
)
998 if (ndx
== SHN_X86_64_LCOMMON
)
1003 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1004 && ndx
== SHN_IA_64_ANSI_COMMON
)
1007 if (is_ia64_vms (filedata
) && ndx
== SHN_IA_64_VMS_SYMVEC
)
1008 return "VMS_SYMVEC";
1015 if (filedata
->section_headers
!= NULL
1016 && ndx
< filedata
->file_header
.e_shnum
)
1020 res
= printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
1021 if (is_special
!= NULL
)
1022 * is_special
= (res
[0] == '<');
1028 static char name_buf
[40];
1029 unsigned int short_ndx
= (unsigned int) (ndx
& 0xffff);
1031 if (ndx
>= SHN_LOPROC
&& ndx
<= SHN_HIPROC
)
1032 sprintf (name_buf
, "PRC[0x%04x]", short_ndx
);
1033 else if (ndx
>= SHN_LOOS
&& ndx
<= SHN_HIOS
)
1034 sprintf (name_buf
, "OS [0x%04x]", short_ndx
);
1035 else if (ndx
>= SHN_LORESERVE
)
1036 sprintf (name_buf
, "RSV[0x%04x]", short_ndx
);
1037 else if (filedata
->file_header
.e_shnum
!= 0
1038 && ndx
>= filedata
->file_header
.e_shnum
)
1039 sprintf (name_buf
, _("BAD[0x%lx]"), (long) ndx
);
1041 sprintf (name_buf
, "<section 0x%lx>", (long) ndx
);
1046 /* Return a pointer to section NAME, or NULL if no such section exists. */
1048 static Elf_Internal_Shdr
*
1049 find_section (Filedata
* filedata
, const char * name
)
1053 if (filedata
->section_headers
== NULL
)
1056 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
1057 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
1058 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
1060 return filedata
->section_headers
+ i
;
1065 /* Return a pointer to a section containing ADDR, or NULL if no such
1068 static Elf_Internal_Shdr
*
1069 find_section_by_address (Filedata
* filedata
, uint64_t addr
)
1073 if (filedata
->section_headers
== NULL
)
1076 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
1078 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
1080 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
1087 static Elf_Internal_Shdr
*
1088 find_section_by_type (Filedata
* filedata
, unsigned int type
)
1092 if (filedata
->section_headers
== NULL
)
1095 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
1097 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
1099 if (sec
->sh_type
== type
)
1106 /* Return a pointer to section NAME, or NULL if no such section exists,
1107 restricted to the list of sections given in SET. */
1109 static Elf_Internal_Shdr
*
1110 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
1114 if (filedata
->section_headers
== NULL
)
1119 while ((i
= *set
++) > 0)
1121 /* See PR 21156 for a reproducer. */
1122 if (i
>= filedata
->file_header
.e_shnum
)
1123 continue; /* FIXME: Should we issue an error message ? */
1125 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
1126 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
1128 return filedata
->section_headers
+ i
;
1132 return find_section (filedata
, name
);
1135 /* Guess the relocation size commonly used by the specific machines. */
1138 guess_is_rela (unsigned int e_machine
)
1142 /* Targets that use REL relocations. */
1148 case EM_CYGNUS_D10V
:
1151 case EM_MIPS_RS3_LE
:
1152 case EM_CYGNUS_M32R
:
1159 /* Targets that use RELA relocations. */
1163 case EM_ADAPTEVA_EPIPHANY
:
1165 case EM_ALTERA_NIOS2
:
1167 case EM_ARC_COMPACT
:
1168 case EM_ARC_COMPACT2
:
1169 case EM_ARC_COMPACT3
:
1170 case EM_ARC_COMPACT3_64
:
1179 case EM_CYGNUS_D30V
:
1182 case EM_CYGNUS_FR30
:
1192 case EM_LATTICEMICO32
:
1201 case EM_CYGNUS_MN10200
:
1203 case EM_CYGNUS_MN10300
:
1221 case EM_SPARC32PLUS
:
1229 case EM_CYGNUS_V850
:
1239 case EM_MICROBLAZE_OLD
:
1240 case EM_WEBASSEMBLY
:
1261 warn (_("Don't know about relocations on this machine architecture\n"));
1266 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1267 Returns TRUE upon success, FALSE otherwise. If successful then a
1268 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
1269 and the number of relocs loaded is placed in *NRELASP. It is the caller's
1270 responsibility to free the allocated buffer. */
1273 slurp_rela_relocs (Filedata
*filedata
,
1274 uint64_t rel_offset
,
1276 Elf_Internal_Rela
**relasp
,
1279 Elf_Internal_Rela
* relas
;
1285 Elf32_External_Rela
* erelas
;
1287 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1288 rel_size
, _("32-bit relocation data"));
1292 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
1294 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1295 sizeof (Elf_Internal_Rela
));
1300 error (_("out of memory parsing relocs\n"));
1304 for (i
= 0; i
< nrelas
; i
++)
1306 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1307 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1308 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1315 Elf64_External_Rela
* erelas
;
1317 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1318 rel_size
, _("64-bit relocation data"));
1322 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1324 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1325 sizeof (Elf_Internal_Rela
));
1330 error (_("out of memory parsing relocs\n"));
1334 for (i
= 0; i
< nrelas
; i
++)
1336 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1337 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1338 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1340 if (filedata
->file_header
.e_machine
== EM_MIPS
1341 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1343 /* In little-endian objects, r_info isn't really a
1344 64-bit little-endian value: it has a 32-bit
1345 little-endian symbol index followed by four
1346 individual byte fields. Reorder INFO
1348 uint64_t inf
= relas
[i
].r_info
;
1349 inf
= (((inf
& 0xffffffff) << 32)
1350 | ((inf
>> 56) & 0xff)
1351 | ((inf
>> 40) & 0xff00)
1352 | ((inf
>> 24) & 0xff0000)
1353 | ((inf
>> 8) & 0xff000000));
1354 relas
[i
].r_info
= inf
;
1366 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1367 Returns TRUE upon success, FALSE otherwise. If successful then a
1368 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1369 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1370 responsibility to free the allocated buffer. */
1373 slurp_rel_relocs (Filedata
*filedata
,
1374 uint64_t rel_offset
,
1376 Elf_Internal_Rela
**relsp
,
1379 Elf_Internal_Rela
* rels
;
1385 Elf32_External_Rel
* erels
;
1387 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1388 rel_size
, _("32-bit relocation data"));
1392 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1394 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1399 error (_("out of memory parsing relocs\n"));
1403 for (i
= 0; i
< nrels
; i
++)
1405 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1406 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1407 rels
[i
].r_addend
= 0;
1414 Elf64_External_Rel
* erels
;
1416 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1417 rel_size
, _("64-bit relocation data"));
1421 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1423 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1428 error (_("out of memory parsing relocs\n"));
1432 for (i
= 0; i
< nrels
; i
++)
1434 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1435 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1436 rels
[i
].r_addend
= 0;
1438 if (filedata
->file_header
.e_machine
== EM_MIPS
1439 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1441 /* In little-endian objects, r_info isn't really a
1442 64-bit little-endian value: it has a 32-bit
1443 little-endian symbol index followed by four
1444 individual byte fields. Reorder INFO
1446 uint64_t inf
= rels
[i
].r_info
;
1447 inf
= (((inf
& 0xffffffff) << 32)
1448 | ((inf
>> 56) & 0xff)
1449 | ((inf
>> 40) & 0xff00)
1450 | ((inf
>> 24) & 0xff0000)
1451 | ((inf
>> 8) & 0xff000000));
1452 rels
[i
].r_info
= inf
;
1465 slurp_relr_relocs (Filedata
*filedata
,
1466 uint64_t relr_offset
,
1472 size_t size
= 0, nentries
, i
;
1473 uint64_t base
= 0, addr
, entry
;
1475 relrs
= get_data (NULL
, filedata
, relr_offset
, 1, relr_size
,
1476 _("RELR relocation data"));
1481 nentries
= relr_size
/ sizeof (Elf32_External_Relr
);
1483 nentries
= relr_size
/ sizeof (Elf64_External_Relr
);
1484 for (i
= 0; i
< nentries
; i
++)
1487 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1489 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1490 if ((entry
& 1) == 0)
1493 while ((entry
>>= 1) != 0)
1494 if ((entry
& 1) == 1)
1498 *relrsp
= malloc (size
* sizeof (**relrsp
));
1499 if (*relrsp
== NULL
)
1502 error (_("out of memory parsing relocs\n"));
1507 for (i
= 0; i
< nentries
; i
++)
1509 const uint64_t entry_bytes
= is_32bit_elf
? 4 : 8;
1512 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1514 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1515 if ((entry
& 1) == 0)
1517 (*relrsp
)[size
++] = entry
;
1518 base
= entry
+ entry_bytes
;
1522 for (addr
= base
; (entry
>>= 1) != 0; addr
+= entry_bytes
)
1523 if ((entry
& 1) != 0)
1524 (*relrsp
)[size
++] = addr
;
1525 base
+= entry_bytes
* (entry_bytes
* CHAR_BIT
- 1);
1534 /* Returns the reloc type extracted from the reloc info field. */
1537 get_reloc_type (Filedata
* filedata
, uint64_t reloc_info
)
1540 return ELF32_R_TYPE (reloc_info
);
1542 switch (filedata
->file_header
.e_machine
)
1545 /* Note: We assume that reloc_info has already been adjusted for us. */
1546 return ELF64_MIPS_R_TYPE (reloc_info
);
1549 return ELF64_R_TYPE_ID (reloc_info
);
1552 return ELF64_R_TYPE (reloc_info
);
1556 /* Return the symbol index extracted from the reloc info field. */
1559 get_reloc_symindex (uint64_t reloc_info
)
1561 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1565 uses_msp430x_relocs (Filedata
* filedata
)
1568 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1569 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1570 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1571 /* TI compiler uses ELFOSABI_NONE. */
1572 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1575 /* Display the contents of the relocation data found at the specified
1579 dump_relocations (Filedata
*filedata
,
1580 uint64_t rel_offset
,
1582 Elf_Internal_Sym
*symtab
,
1586 relocation_type rel_type
,
1590 Elf_Internal_Rela
* rels
;
1593 if (rel_type
== reltype_unknown
)
1594 rel_type
= guess_is_rela (filedata
->file_header
.e_machine
) ? reltype_rela
: reltype_rel
;
1596 if (rel_type
== reltype_rela
)
1598 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1601 else if (rel_type
== reltype_rel
)
1603 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1606 else if (rel_type
== reltype_relr
)
1610 = is_32bit_elf
? "%08" PRIx64
"\n" : "%016" PRIx64
"\n";
1612 if (!slurp_relr_relocs (filedata
, rel_offset
, rel_size
, &relrs
,
1616 printf (ngettext (" %" PRIu64
" offset\n",
1617 " %" PRIu64
" offsets\n", rel_size
),
1619 for (i
= 0; i
< rel_size
; i
++)
1620 printf (format
, relrs
[i
]);
1627 if (rel_type
== reltype_rela
)
1630 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1632 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1637 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1639 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1644 if (rel_type
== reltype_rela
)
1647 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1649 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1654 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1656 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1660 for (i
= 0; i
< rel_size
; i
++)
1665 uint64_t symtab_index
;
1668 offset
= rels
[i
].r_offset
;
1669 inf
= rels
[i
].r_info
;
1671 type
= get_reloc_type (filedata
, inf
);
1672 symtab_index
= get_reloc_symindex (inf
);
1676 printf ("%8.8lx %8.8lx ",
1677 (unsigned long) offset
& 0xffffffff,
1678 (unsigned long) inf
& 0xffffffff);
1683 ? "%16.16" PRIx64
" %16.16" PRIx64
" "
1684 : "%12.12" PRIx64
" %12.12" PRIx64
" ",
1688 switch (filedata
->file_header
.e_machine
)
1695 rtype
= elf_aarch64_reloc_type (type
);
1699 case EM_CYGNUS_M32R
:
1700 rtype
= elf_m32r_reloc_type (type
);
1705 rtype
= elf_i386_reloc_type (type
);
1710 rtype
= elf_m68hc11_reloc_type (type
);
1714 rtype
= elf_s12z_reloc_type (type
);
1718 rtype
= elf_m68k_reloc_type (type
);
1722 rtype
= elf_i960_reloc_type (type
);
1727 rtype
= elf_avr_reloc_type (type
);
1730 case EM_OLD_SPARCV9
:
1731 case EM_SPARC32PLUS
:
1734 rtype
= elf_sparc_reloc_type (type
);
1738 rtype
= elf_spu_reloc_type (type
);
1742 rtype
= v800_reloc_type (type
);
1745 case EM_CYGNUS_V850
:
1746 rtype
= v850_reloc_type (type
);
1750 case EM_CYGNUS_D10V
:
1751 rtype
= elf_d10v_reloc_type (type
);
1755 case EM_CYGNUS_D30V
:
1756 rtype
= elf_d30v_reloc_type (type
);
1760 rtype
= elf_dlx_reloc_type (type
);
1764 rtype
= elf_sh_reloc_type (type
);
1768 case EM_CYGNUS_MN10300
:
1769 rtype
= elf_mn10300_reloc_type (type
);
1773 case EM_CYGNUS_MN10200
:
1774 rtype
= elf_mn10200_reloc_type (type
);
1778 case EM_CYGNUS_FR30
:
1779 rtype
= elf_fr30_reloc_type (type
);
1783 rtype
= elf_frv_reloc_type (type
);
1787 rtype
= elf_csky_reloc_type (type
);
1791 rtype
= elf_ft32_reloc_type (type
);
1795 rtype
= elf_mcore_reloc_type (type
);
1799 rtype
= elf_mmix_reloc_type (type
);
1803 rtype
= elf_moxie_reloc_type (type
);
1807 if (uses_msp430x_relocs (filedata
))
1809 rtype
= elf_msp430x_reloc_type (type
);
1814 rtype
= elf_msp430_reloc_type (type
);
1818 rtype
= elf_nds32_reloc_type (type
);
1822 rtype
= elf_ppc_reloc_type (type
);
1826 rtype
= elf_ppc64_reloc_type (type
);
1830 case EM_MIPS_RS3_LE
:
1831 rtype
= elf_mips_reloc_type (type
);
1835 rtype
= elf_riscv_reloc_type (type
);
1839 rtype
= elf_alpha_reloc_type (type
);
1843 rtype
= elf_arm_reloc_type (type
);
1847 case EM_ARC_COMPACT
:
1848 case EM_ARC_COMPACT2
:
1849 case EM_ARC_COMPACT3
:
1850 case EM_ARC_COMPACT3_64
:
1851 rtype
= elf_arc_reloc_type (type
);
1855 rtype
= elf_hppa_reloc_type (type
);
1861 rtype
= elf_h8_reloc_type (type
);
1865 rtype
= elf_or1k_reloc_type (type
);
1870 rtype
= elf_pj_reloc_type (type
);
1873 rtype
= elf_ia64_reloc_type (type
);
1877 rtype
= elf_kvx_reloc_type (type
);
1881 rtype
= elf_cris_reloc_type (type
);
1885 rtype
= elf_i860_reloc_type (type
);
1891 rtype
= elf_x86_64_reloc_type (type
);
1895 rtype
= i370_reloc_type (type
);
1900 rtype
= elf_s390_reloc_type (type
);
1904 rtype
= elf_score_reloc_type (type
);
1908 rtype
= elf_xstormy16_reloc_type (type
);
1912 rtype
= elf_crx_reloc_type (type
);
1916 rtype
= elf_vax_reloc_type (type
);
1920 rtype
= elf_visium_reloc_type (type
);
1924 rtype
= elf_bpf_reloc_type (type
);
1927 case EM_ADAPTEVA_EPIPHANY
:
1928 rtype
= elf_epiphany_reloc_type (type
);
1933 rtype
= elf_ip2k_reloc_type (type
);
1937 rtype
= elf_iq2000_reloc_type (type
);
1942 rtype
= elf_xtensa_reloc_type (type
);
1945 case EM_LATTICEMICO32
:
1946 rtype
= elf_lm32_reloc_type (type
);
1951 rtype
= elf_m32c_reloc_type (type
);
1955 rtype
= elf_mt_reloc_type (type
);
1959 rtype
= elf_bfin_reloc_type (type
);
1963 rtype
= elf_mep_reloc_type (type
);
1967 rtype
= elf_cr16_reloc_type (type
);
1971 case EM_MICROBLAZE_OLD
:
1972 rtype
= elf_microblaze_reloc_type (type
);
1976 rtype
= elf_rl78_reloc_type (type
);
1980 rtype
= elf_rx_reloc_type (type
);
1984 rtype
= elf_metag_reloc_type (type
);
1988 rtype
= elf_tic6x_reloc_type (type
);
1992 rtype
= elf_tilegx_reloc_type (type
);
1996 rtype
= elf_tilepro_reloc_type (type
);
1999 case EM_WEBASSEMBLY
:
2000 rtype
= elf_wasm32_reloc_type (type
);
2004 rtype
= elf_xgate_reloc_type (type
);
2007 case EM_ALTERA_NIOS2
:
2008 rtype
= elf_nios2_reloc_type (type
);
2012 rtype
= elf_pru_reloc_type (type
);
2016 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
2017 rtype
= elf_nfp3200_reloc_type (type
);
2019 rtype
= elf_nfp_reloc_type (type
);
2023 rtype
= elf_z80_reloc_type (type
);
2027 rtype
= elf_loongarch_reloc_type (type
);
2031 rtype
= elf_amdgpu_reloc_type (type
);
2036 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
2038 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
2040 if (filedata
->file_header
.e_machine
== EM_ALPHA
2042 && streq (rtype
, "R_ALPHA_LITUSE")
2043 && rel_type
== reltype_rela
)
2045 switch (rels
[i
].r_addend
)
2047 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
2048 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
2049 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
2050 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
2051 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
2052 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
2053 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
2054 default: rtype
= NULL
;
2058 printf (" (%s)", rtype
);
2062 printf (_("<unknown addend: %" PRIx64
">"),
2067 else if (symtab_index
)
2069 if (symtab
== NULL
|| symtab_index
>= nsyms
)
2071 error (_(" bad symbol index: %08lx in reloc\n"),
2072 (unsigned long) symtab_index
);
2077 Elf_Internal_Sym
* psym
;
2078 const char * version_string
;
2079 enum versioned_symbol_info sym_info
;
2080 unsigned short vna_other
;
2082 psym
= symtab
+ symtab_index
;
2085 = get_symbol_version_string (filedata
, is_dynsym
,
2094 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
2098 unsigned int width
= is_32bit_elf
? 8 : 14;
2100 /* Relocations against GNU_IFUNC symbols do not use the value
2101 of the symbol as the address to relocate against. Instead
2102 they invoke the function named by the symbol and use its
2103 result as the address for relocation.
2105 To indicate this to the user, do not display the value of
2106 the symbol in the "Symbols's Value" field. Instead show
2107 its name followed by () as a hint that the symbol is
2111 || psym
->st_name
== 0
2112 || psym
->st_name
>= strtablen
)
2115 name
= strtab
+ psym
->st_name
;
2117 len
= print_symbol_name (width
, name
);
2119 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
2121 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
2125 print_vma (psym
->st_value
, LONG_HEX
);
2127 printf (is_32bit_elf
? " " : " ");
2130 if (psym
->st_name
== 0)
2132 const char * sec_name
= "<null>";
2134 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
2135 sec_name
= printable_section_name_from_index
2136 (filedata
, psym
->st_shndx
, NULL
);
2138 print_symbol_name (22, sec_name
);
2140 else if (strtab
== NULL
)
2141 printf (_("<string table index: %3ld>"), psym
->st_name
);
2142 else if (psym
->st_name
>= strtablen
)
2144 error (_("<corrupt string table index: %3ld>\n"),
2150 print_symbol_name (22, strtab
+ psym
->st_name
);
2152 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
2156 if (rel_type
== reltype_rela
)
2158 uint64_t off
= rels
[i
].r_addend
;
2160 if ((int64_t) off
< 0)
2161 printf (" - %" PRIx64
, -off
);
2163 printf (" + %" PRIx64
, off
);
2167 else if (rel_type
== reltype_rela
)
2169 uint64_t off
= rels
[i
].r_addend
;
2171 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
2172 if ((int64_t) off
< 0)
2173 printf ("-%" PRIx64
, -off
);
2175 printf ("%" PRIx64
, off
);
2178 if (filedata
->file_header
.e_machine
== EM_SPARCV9
2180 && streq (rtype
, "R_SPARC_OLO10"))
2181 printf (" + %" PRIx64
, ELF64_R_TYPE_DATA (inf
));
2185 if (! is_32bit_elf
&& filedata
->file_header
.e_machine
== EM_MIPS
)
2187 uint64_t type2
= ELF64_MIPS_R_TYPE2 (inf
);
2188 uint64_t type3
= ELF64_MIPS_R_TYPE3 (inf
);
2189 const char * rtype2
= elf_mips_reloc_type (type2
);
2190 const char * rtype3
= elf_mips_reloc_type (type3
);
2192 printf (" Type2: ");
2195 printf (_("unrecognized: %-7lx"),
2196 (unsigned long) type2
& 0xffffffff);
2198 printf ("%-17.17s", rtype2
);
2200 printf ("\n Type3: ");
2203 printf (_("unrecognized: %-7lx"),
2204 (unsigned long) type3
& 0xffffffff);
2206 printf ("%-17.17s", rtype3
);
2218 get_aarch64_dynamic_type (unsigned long type
)
2222 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
2223 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
2224 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
2231 get_mips_dynamic_type (unsigned long type
)
2235 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
2236 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
2237 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
2238 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
2239 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
2240 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
2241 case DT_MIPS_MSYM
: return "MIPS_MSYM";
2242 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2243 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2244 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
2245 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
2246 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
2247 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
2248 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
2249 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
2250 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
2251 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
2252 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
2253 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
2254 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
2255 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
2256 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
2257 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
2258 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
2259 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
2260 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
2261 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
2262 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
2263 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
2264 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
2265 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2266 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
2267 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
2268 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
2269 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
2270 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2271 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
2272 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
2273 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
2274 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
2275 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
2276 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
2277 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
2278 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
2279 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
2280 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
2281 case DT_MIPS_XHASH
: return "MIPS_XHASH";
2288 get_sparc64_dynamic_type (unsigned long type
)
2292 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
2299 get_ppc_dynamic_type (unsigned long type
)
2303 case DT_PPC_GOT
: return "PPC_GOT";
2304 case DT_PPC_OPT
: return "PPC_OPT";
2311 get_ppc64_dynamic_type (unsigned long type
)
2315 case DT_PPC64_GLINK
: return "PPC64_GLINK";
2316 case DT_PPC64_OPD
: return "PPC64_OPD";
2317 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
2318 case DT_PPC64_OPT
: return "PPC64_OPT";
2325 get_parisc_dynamic_type (unsigned long type
)
2329 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
2330 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
2331 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
2332 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
2333 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
2334 case DT_HP_PREINIT
: return "HP_PREINIT";
2335 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
2336 case DT_HP_NEEDED
: return "HP_NEEDED";
2337 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
2338 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
2339 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
2340 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
2341 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
2342 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
2343 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
2344 case DT_HP_FILTERED
: return "HP_FILTERED";
2345 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
2346 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
2347 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
2348 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
2349 case DT_PLT
: return "PLT";
2350 case DT_PLT_SIZE
: return "PLT_SIZE";
2351 case DT_DLT
: return "DLT";
2352 case DT_DLT_SIZE
: return "DLT_SIZE";
2359 get_ia64_dynamic_type (unsigned long type
)
2363 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
2364 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
2365 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
2366 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
2367 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
2368 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
2369 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
2370 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
2371 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
2372 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
2373 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
2374 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
2375 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
2376 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
2377 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
2378 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
2379 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
2380 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
2381 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
2382 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
2383 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
2384 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
2385 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
2386 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
2387 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
2388 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
2389 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
2390 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
2391 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
2392 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
2393 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
2400 get_solaris_section_type (unsigned long type
)
2404 case 0x6fffffee: return "SUNW_ancillary";
2405 case 0x6fffffef: return "SUNW_capchain";
2406 case 0x6ffffff0: return "SUNW_capinfo";
2407 case 0x6ffffff1: return "SUNW_symsort";
2408 case 0x6ffffff2: return "SUNW_tlssort";
2409 case 0x6ffffff3: return "SUNW_LDYNSYM";
2410 case 0x6ffffff4: return "SUNW_dof";
2411 case 0x6ffffff5: return "SUNW_cap";
2412 case 0x6ffffff6: return "SUNW_SIGNATURE";
2413 case 0x6ffffff7: return "SUNW_ANNOTATE";
2414 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2415 case 0x6ffffff9: return "SUNW_DEBUG";
2416 case 0x6ffffffa: return "SUNW_move";
2417 case 0x6ffffffb: return "SUNW_COMDAT";
2418 case 0x6ffffffc: return "SUNW_syminfo";
2419 case 0x6ffffffd: return "SUNW_verdef";
2420 case 0x6ffffffe: return "SUNW_verneed";
2421 case 0x6fffffff: return "SUNW_versym";
2422 case 0x70000000: return "SPARC_GOTDATA";
2423 default: return NULL
;
2428 get_alpha_dynamic_type (unsigned long type
)
2432 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
2433 default: return NULL
;
2438 get_score_dynamic_type (unsigned long type
)
2442 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
2443 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
2444 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
2445 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
2446 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
2447 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
2448 default: return NULL
;
2453 get_tic6x_dynamic_type (unsigned long type
)
2457 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
2458 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
2459 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
2460 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
2461 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
2462 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
2463 default: return NULL
;
2468 get_nios2_dynamic_type (unsigned long type
)
2472 case DT_NIOS2_GP
: return "NIOS2_GP";
2473 default: return NULL
;
2478 get_solaris_dynamic_type (unsigned long type
)
2482 case 0x6000000d: return "SUNW_AUXILIARY";
2483 case 0x6000000e: return "SUNW_RTLDINF";
2484 case 0x6000000f: return "SUNW_FILTER";
2485 case 0x60000010: return "SUNW_CAP";
2486 case 0x60000011: return "SUNW_SYMTAB";
2487 case 0x60000012: return "SUNW_SYMSZ";
2488 case 0x60000013: return "SUNW_SORTENT";
2489 case 0x60000014: return "SUNW_SYMSORT";
2490 case 0x60000015: return "SUNW_SYMSORTSZ";
2491 case 0x60000016: return "SUNW_TLSSORT";
2492 case 0x60000017: return "SUNW_TLSSORTSZ";
2493 case 0x60000018: return "SUNW_CAPINFO";
2494 case 0x60000019: return "SUNW_STRPAD";
2495 case 0x6000001a: return "SUNW_CAPCHAIN";
2496 case 0x6000001b: return "SUNW_LDMACH";
2497 case 0x6000001d: return "SUNW_CAPCHAINENT";
2498 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2499 case 0x60000021: return "SUNW_PARENT";
2500 case 0x60000023: return "SUNW_ASLR";
2501 case 0x60000025: return "SUNW_RELAX";
2502 case 0x60000029: return "SUNW_NXHEAP";
2503 case 0x6000002b: return "SUNW_NXSTACK";
2505 case 0x70000001: return "SPARC_REGISTER";
2506 case 0x7ffffffd: return "AUXILIARY";
2507 case 0x7ffffffe: return "USED";
2508 case 0x7fffffff: return "FILTER";
2510 default: return NULL
;
2515 get_riscv_dynamic_type (unsigned long type
)
2519 case DT_RISCV_VARIANT_CC
: return "RISCV_VARIANT_CC";
2526 get_x86_64_dynamic_type (unsigned long type
)
2531 return "DT_X86_64_PLT";
2532 case DT_X86_64_PLTSZ
:
2533 return "DT_X86_64_PLTSZ";
2534 case DT_X86_64_PLTENT
:
2535 return "DT_X86_64_PLTENT";
2542 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
2544 static char buff
[64];
2548 case DT_NULL
: return "NULL";
2549 case DT_NEEDED
: return "NEEDED";
2550 case DT_PLTRELSZ
: return "PLTRELSZ";
2551 case DT_PLTGOT
: return "PLTGOT";
2552 case DT_HASH
: return "HASH";
2553 case DT_STRTAB
: return "STRTAB";
2554 case DT_SYMTAB
: return "SYMTAB";
2555 case DT_RELA
: return "RELA";
2556 case DT_RELASZ
: return "RELASZ";
2557 case DT_RELAENT
: return "RELAENT";
2558 case DT_STRSZ
: return "STRSZ";
2559 case DT_SYMENT
: return "SYMENT";
2560 case DT_INIT
: return "INIT";
2561 case DT_FINI
: return "FINI";
2562 case DT_SONAME
: return "SONAME";
2563 case DT_RPATH
: return "RPATH";
2564 case DT_SYMBOLIC
: return "SYMBOLIC";
2565 case DT_REL
: return "REL";
2566 case DT_RELSZ
: return "RELSZ";
2567 case DT_RELENT
: return "RELENT";
2568 case DT_RELR
: return "RELR";
2569 case DT_RELRSZ
: return "RELRSZ";
2570 case DT_RELRENT
: return "RELRENT";
2571 case DT_PLTREL
: return "PLTREL";
2572 case DT_DEBUG
: return "DEBUG";
2573 case DT_TEXTREL
: return "TEXTREL";
2574 case DT_JMPREL
: return "JMPREL";
2575 case DT_BIND_NOW
: return "BIND_NOW";
2576 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2577 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2578 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2579 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2580 case DT_RUNPATH
: return "RUNPATH";
2581 case DT_FLAGS
: return "FLAGS";
2583 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2584 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2585 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2587 case DT_CHECKSUM
: return "CHECKSUM";
2588 case DT_PLTPADSZ
: return "PLTPADSZ";
2589 case DT_MOVEENT
: return "MOVEENT";
2590 case DT_MOVESZ
: return "MOVESZ";
2591 case DT_FEATURE
: return "FEATURE";
2592 case DT_POSFLAG_1
: return "POSFLAG_1";
2593 case DT_SYMINSZ
: return "SYMINSZ";
2594 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2596 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2597 case DT_CONFIG
: return "CONFIG";
2598 case DT_DEPAUDIT
: return "DEPAUDIT";
2599 case DT_AUDIT
: return "AUDIT";
2600 case DT_PLTPAD
: return "PLTPAD";
2601 case DT_MOVETAB
: return "MOVETAB";
2602 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2604 case DT_VERSYM
: return "VERSYM";
2606 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2607 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2608 case DT_RELACOUNT
: return "RELACOUNT";
2609 case DT_RELCOUNT
: return "RELCOUNT";
2610 case DT_FLAGS_1
: return "FLAGS_1";
2611 case DT_VERDEF
: return "VERDEF";
2612 case DT_VERDEFNUM
: return "VERDEFNUM";
2613 case DT_VERNEED
: return "VERNEED";
2614 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2616 case DT_AUXILIARY
: return "AUXILIARY";
2617 case DT_USED
: return "USED";
2618 case DT_FILTER
: return "FILTER";
2620 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2621 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2622 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2623 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2624 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2625 case DT_GNU_HASH
: return "GNU_HASH";
2626 case DT_GNU_FLAGS_1
: return "GNU_FLAGS_1";
2629 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2631 const char * result
;
2633 switch (filedata
->file_header
.e_machine
)
2636 result
= get_aarch64_dynamic_type (type
);
2639 case EM_MIPS_RS3_LE
:
2640 result
= get_mips_dynamic_type (type
);
2643 result
= get_sparc64_dynamic_type (type
);
2646 result
= get_ppc_dynamic_type (type
);
2649 result
= get_ppc64_dynamic_type (type
);
2652 result
= get_ia64_dynamic_type (type
);
2655 result
= get_alpha_dynamic_type (type
);
2658 result
= get_score_dynamic_type (type
);
2661 result
= get_tic6x_dynamic_type (type
);
2663 case EM_ALTERA_NIOS2
:
2664 result
= get_nios2_dynamic_type (type
);
2667 result
= get_riscv_dynamic_type (type
);
2670 result
= get_x86_64_dynamic_type (type
);
2673 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2674 result
= get_solaris_dynamic_type (type
);
2683 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2685 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2686 || (filedata
->file_header
.e_machine
== EM_PARISC
2687 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2689 const char * result
;
2691 switch (filedata
->file_header
.e_machine
)
2694 result
= get_parisc_dynamic_type (type
);
2697 result
= get_ia64_dynamic_type (type
);
2700 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2701 result
= get_solaris_dynamic_type (type
);
2710 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2714 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2720 static bool get_program_headers (Filedata
*);
2721 static bool get_dynamic_section (Filedata
*);
2724 locate_dynamic_section (Filedata
*filedata
)
2726 uint64_t dynamic_addr
= 0;
2727 uint64_t dynamic_size
= 0;
2729 if (filedata
->file_header
.e_phnum
!= 0
2730 && get_program_headers (filedata
))
2732 Elf_Internal_Phdr
*segment
;
2735 for (i
= 0, segment
= filedata
->program_headers
;
2736 i
< filedata
->file_header
.e_phnum
;
2739 if (segment
->p_type
== PT_DYNAMIC
)
2741 dynamic_addr
= segment
->p_offset
;
2742 dynamic_size
= segment
->p_filesz
;
2744 if (filedata
->section_headers
!= NULL
)
2746 Elf_Internal_Shdr
*sec
;
2748 sec
= find_section (filedata
, ".dynamic");
2751 if (sec
->sh_size
== 0
2752 || sec
->sh_type
== SHT_NOBITS
)
2759 dynamic_addr
= sec
->sh_offset
;
2760 dynamic_size
= sec
->sh_size
;
2765 if (dynamic_addr
> filedata
->file_size
2766 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
2775 filedata
->dynamic_addr
= dynamic_addr
;
2776 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
2780 is_pie (Filedata
*filedata
)
2782 Elf_Internal_Dyn
*entry
;
2784 if (filedata
->dynamic_size
== 0)
2785 locate_dynamic_section (filedata
);
2786 if (filedata
->dynamic_size
<= 1)
2789 if (!get_dynamic_section (filedata
))
2792 for (entry
= filedata
->dynamic_section
;
2793 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
2796 if (entry
->d_tag
== DT_FLAGS_1
)
2798 if ((entry
->d_un
.d_val
& DF_1_PIE
) != 0)
2807 get_file_type (Filedata
*filedata
)
2809 unsigned e_type
= filedata
->file_header
.e_type
;
2810 static char buff
[64];
2814 case ET_NONE
: return _("NONE (None)");
2815 case ET_REL
: return _("REL (Relocatable file)");
2816 case ET_EXEC
: return _("EXEC (Executable file)");
2818 if (is_pie (filedata
))
2819 return _("DYN (Position-Independent Executable file)");
2821 return _("DYN (Shared object file)");
2822 case ET_CORE
: return _("CORE (Core file)");
2825 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2826 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2827 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2828 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2830 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2836 get_machine_name (unsigned e_machine
)
2838 static char buff
[64]; /* XXX */
2842 /* Please keep this switch table sorted by increasing EM_ value. */
2844 case EM_NONE
: return _("None");
2845 case EM_M32
: return "WE32100";
2846 case EM_SPARC
: return "Sparc";
2847 case EM_386
: return "Intel 80386";
2848 case EM_68K
: return "MC68000";
2849 case EM_88K
: return "MC88000";
2850 case EM_IAMCU
: return "Intel MCU";
2851 case EM_860
: return "Intel 80860";
2852 case EM_MIPS
: return "MIPS R3000";
2853 case EM_S370
: return "IBM System/370";
2855 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2856 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2857 case EM_PARISC
: return "HPPA";
2858 case EM_VPP550
: return "Fujitsu VPP500";
2859 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2860 case EM_960
: return "Intel 80960";
2861 case EM_PPC
: return "PowerPC";
2863 case EM_PPC64
: return "PowerPC64";
2865 case EM_S390
: return "IBM S/390";
2866 case EM_SPU
: return "SPU";
2868 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2869 case EM_FR20
: return "Fujitsu FR20";
2870 case EM_RH32
: return "TRW RH32";
2871 case EM_MCORE
: return "MCORE";
2873 case EM_ARM
: return "ARM";
2874 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2875 case EM_SH
: return "Renesas / SuperH SH";
2876 case EM_SPARCV9
: return "Sparc v9";
2877 case EM_TRICORE
: return "Siemens Tricore";
2878 case EM_ARC
: return "ARC";
2879 case EM_H8_300
: return "Renesas H8/300";
2880 case EM_H8_300H
: return "Renesas H8/300H";
2881 case EM_H8S
: return "Renesas H8S";
2882 case EM_H8_500
: return "Renesas H8/500";
2884 case EM_IA_64
: return "Intel IA-64";
2885 case EM_MIPS_X
: return "Stanford MIPS-X";
2886 case EM_COLDFIRE
: return "Motorola Coldfire";
2887 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2888 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2889 case EM_PCP
: return "Siemens PCP";
2890 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2891 case EM_NDR1
: return "Denso NDR1 microprocessor";
2892 case EM_STARCORE
: return "Motorola Star*Core processor";
2893 case EM_ME16
: return "Toyota ME16 processor";
2895 case EM_ST100
: return "STMicroelectronics ST100 processor";
2896 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2897 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2898 case EM_PDSP
: return "Sony DSP processor";
2899 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2900 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2901 case EM_FX66
: return "Siemens FX66 microcontroller";
2902 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2903 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2904 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2906 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2907 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2908 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2909 case EM_SVX
: return "Silicon Graphics SVx";
2910 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2911 case EM_VAX
: return "Digital VAX";
2912 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2913 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2914 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2915 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2917 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2918 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2919 case EM_PRISM
: return "Vitesse Prism";
2921 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2922 case EM_CYGNUS_FR30
:
2923 case EM_FR30
: return "Fujitsu FR30";
2924 case EM_CYGNUS_D10V
:
2925 case EM_D10V
: return "d10v";
2926 case EM_CYGNUS_D30V
:
2927 case EM_D30V
: return "d30v";
2928 case EM_CYGNUS_V850
:
2929 case EM_V850
: return "Renesas V850";
2930 case EM_CYGNUS_M32R
:
2931 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2932 case EM_CYGNUS_MN10300
:
2933 case EM_MN10300
: return "mn10300";
2935 case EM_CYGNUS_MN10200
:
2936 case EM_MN10200
: return "mn10200";
2937 case EM_PJ
: return "picoJava";
2938 case EM_OR1K
: return "OpenRISC 1000";
2939 case EM_ARC_COMPACT
: return "ARCompact";
2941 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2942 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2943 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2944 case EM_NS32K
: return "National Semiconductor 32000 series";
2945 case EM_TPC
: return "Tenor Network TPC processor";
2946 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2948 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2950 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2951 case EM_MAX
: return "MAX Processor";
2952 case EM_CR
: return "National Semiconductor CompactRISC";
2953 case EM_F2MC16
: return "Fujitsu F2MC16";
2954 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2955 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2956 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2957 case EM_SEP
: return "Sharp embedded microprocessor";
2958 case EM_ARCA
: return "Arca RISC microprocessor";
2960 case EM_UNICORE
: return "Unicore";
2961 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2962 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2963 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2964 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2965 case EM_XGATE
: return "Motorola XGATE embedded processor";
2967 case EM_XC16X
: return "Infineon Technologies xc16x";
2968 case EM_M16C
: return "Renesas M16C series microprocessors";
2969 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2970 case EM_CE
: return "Freescale Communication Engine RISC core";
2972 case EM_M32C
: return "Renesas M32c";
2974 case EM_TSK3000
: return "Altium TSK3000 core";
2975 case EM_RS08
: return "Freescale RS08 embedded processor";
2976 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2977 case EM_SCORE
: return "SUNPLUS S+Core";
2978 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2979 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2980 case EM_LATTICEMICO32
: return "Lattice Mico32";
2981 case EM_SE_C17
: return "Seiko Epson C17 family";
2983 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2984 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2985 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2986 case EM_TI_PRU
: return "TI PRU I/O processor";
2988 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2989 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2990 case EM_R32C
: return "Renesas R32C series microprocessors";
2991 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2992 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2993 case EM_8051
: return "Intel 8051 and variants";
2994 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2995 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2996 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2997 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2999 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
3000 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
3001 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
3002 case EM_RX
: return "Renesas RX";
3003 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
3004 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
3005 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
3008 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
3009 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
3010 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
3012 case EM_L1OM
: return "Intel L1OM";
3013 case EM_K1OM
: return "Intel K1OM";
3014 case EM_INTEL182
: return "Intel (reserved)";
3015 case EM_AARCH64
: return "AArch64";
3016 case EM_ARM184
: return "ARM (reserved)";
3017 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
3018 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
3019 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
3020 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
3022 case EM_CUDA
: return "NVIDIA CUDA architecture";
3023 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
3024 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
3025 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
3026 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
3027 case EM_ARC_COMPACT2
: return "ARCv2";
3028 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
3029 case EM_RL78
: return "Renesas RL78";
3030 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
3031 case EM_78K0R
: return "Renesas 78K0R";
3033 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
3034 case EM_BA1
: return "Beyond BA1 CPU architecture";
3035 case EM_BA2
: return "Beyond BA2 CPU architecture";
3036 case EM_XCORE
: return "XMOS xCORE processor family";
3037 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
3038 case EM_INTELGT
: return "Intel Graphics Technology";
3040 case EM_KM32
: return "KM211 KM32 32-bit processor";
3041 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
3042 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
3043 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
3044 case EM_KVARC
: return "KM211 KVARC processor";
3045 case EM_CDP
: return "Paneve CDP architecture family";
3046 case EM_COGE
: return "Cognitive Smart Memory Processor";
3047 case EM_COOL
: return "Bluechip Systems CoolEngine";
3048 case EM_NORC
: return "Nanoradio Optimized RISC";
3049 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
3051 case EM_Z80
: return "Zilog Z80";
3052 case EM_VISIUM
: return "CDS VISIUMcore processor";
3053 case EM_FT32
: return "FTDI Chip FT32";
3054 case EM_MOXIE
: return "Moxie";
3055 case EM_AMDGPU
: return "AMD GPU";
3056 /* 230 (all reserved) */
3058 case EM_RISCV
: return "RISC-V";
3059 case EM_LANAI
: return "Lanai 32-bit processor";
3060 case EM_CEVA
: return "CEVA Processor Architecture Family";
3061 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
3062 case EM_BPF
: return "Linux BPF";
3063 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
3064 case EM_IMG1
: return "Imagination Technologies";
3066 case EM_NFP
: return "Netronome Flow Processor";
3067 case EM_VE
: return "NEC Vector Engine";
3068 case EM_CSKY
: return "C-SKY";
3069 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv3 64-bit processor";
3070 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
3071 case EM_ARC_COMPACT3
: return "Synopsys ARCv3 32-bit processor";
3072 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
3073 case EM_65816
: return "WDC 65816/65C816";
3074 case EM_LOONGARCH
: return "LoongArch";
3075 case EM_KF32
: return "ChipON KungFu32";
3077 /* Large numbers... */
3078 case EM_MT
: return "Morpho Techologies MT processor";
3079 case EM_ALPHA
: return "Alpha";
3080 case EM_WEBASSEMBLY
: return "Web Assembly";
3081 case EM_DLX
: return "OpenDLX";
3082 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
3083 case EM_IQ2000
: return "Vitesse IQ2000";
3085 case EM_NIOS32
: return "Altera Nios";
3086 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
3087 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
3088 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
3089 case EM_S12Z
: return "Freescale S12Z";
3092 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
3098 decode_ARC_machine_flags (char *out
, unsigned e_flags
, unsigned e_machine
)
3100 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
3101 other compilers don't specify an architecture type in the e_flags, and
3102 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
3103 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
3106 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
3107 but also sets a specific architecture type in the e_flags field.
3109 However, when decoding the flags we don't worry if we see an
3110 unexpected pairing, for example EM_ARC_COMPACT machine type, with
3111 ARCEM architecture type. */
3113 switch (e_flags
& EF_ARC_MACH_MSK
)
3115 /* We only expect these to occur for EM_ARC_COMPACT2. */
3116 case EF_ARC_CPU_ARCV2EM
:
3117 out
= stpcpy (out
, ", ARC EM");
3119 case EF_ARC_CPU_ARCV2HS
:
3120 out
= stpcpy (out
, ", ARC HS");
3123 /* We only expect these to occur for EM_ARC_COMPACT. */
3124 case E_ARC_MACH_ARC600
:
3125 out
= stpcpy (out
, ", ARC600");
3127 case E_ARC_MACH_ARC601
:
3128 out
= stpcpy (out
, ", ARC601");
3130 case E_ARC_MACH_ARC700
:
3131 out
= stpcpy (out
, ", ARC700");
3134 /* The only times we should end up here are (a) A corrupt ELF, (b) A
3135 new ELF with new architecture being read by an old version of
3136 readelf, or (c) An ELF built with non-GNU compiler that does not
3137 set the architecture in the e_flags. */
3139 if (e_machine
== EM_ARC_COMPACT
)
3140 out
= stpcpy (out
, ", Unknown ARCompact");
3142 out
= stpcpy (out
, ", Unknown ARC");
3146 switch (e_flags
& EF_ARC_OSABI_MSK
)
3148 case E_ARC_OSABI_ORIG
:
3149 out
= stpcpy (out
, ", (ABI:legacy)");
3151 case E_ARC_OSABI_V2
:
3152 out
= stpcpy (out
, ", (ABI:v2)");
3154 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
3155 case E_ARC_OSABI_V3
:
3156 out
= stpcpy (out
, ", v3 no-legacy-syscalls ABI");
3158 case E_ARC_OSABI_V4
:
3159 out
= stpcpy (out
, ", v4 ABI");
3162 out
= stpcpy (out
, ", unrecognised ARC OSABI flag");
3169 decode_ARM_machine_flags (char *out
, unsigned e_flags
)
3172 bool unknown
= false;
3174 eabi
= EF_ARM_EABI_VERSION (e_flags
);
3175 e_flags
&= ~ EF_ARM_EABIMASK
;
3177 /* Handle "generic" ARM flags. */
3178 if (e_flags
& EF_ARM_RELEXEC
)
3180 out
= stpcpy (out
, ", relocatable executable");
3181 e_flags
&= ~ EF_ARM_RELEXEC
;
3184 if (e_flags
& EF_ARM_PIC
)
3186 out
= stpcpy (out
, ", position independent");
3187 e_flags
&= ~ EF_ARM_PIC
;
3190 /* Now handle EABI specific flags. */
3194 out
= stpcpy (out
, ", <unrecognized EABI>");
3199 case EF_ARM_EABI_VER1
:
3200 out
= stpcpy (out
, ", Version1 EABI");
3205 /* Process flags one bit at a time. */
3206 flag
= e_flags
& - e_flags
;
3211 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3212 out
= stpcpy (out
, ", sorted symbol tables");
3222 case EF_ARM_EABI_VER2
:
3223 out
= stpcpy (out
, ", Version2 EABI");
3228 /* Process flags one bit at a time. */
3229 flag
= e_flags
& - e_flags
;
3234 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3235 out
= stpcpy (out
, ", sorted symbol tables");
3238 case EF_ARM_DYNSYMSUSESEGIDX
:
3239 out
= stpcpy (out
, ", dynamic symbols use segment index");
3242 case EF_ARM_MAPSYMSFIRST
:
3243 out
= stpcpy (out
, ", mapping symbols precede others");
3253 case EF_ARM_EABI_VER3
:
3254 out
= stpcpy (out
, ", Version3 EABI");
3257 case EF_ARM_EABI_VER4
:
3258 out
= stpcpy (out
, ", Version4 EABI");
3263 /* Process flags one bit at a time. */
3264 flag
= e_flags
& - e_flags
;
3270 out
= stpcpy (out
, ", BE8");
3274 out
= stpcpy (out
, ", LE8");
3284 case EF_ARM_EABI_VER5
:
3285 out
= stpcpy (out
, ", Version5 EABI");
3290 /* Process flags one bit at a time. */
3291 flag
= e_flags
& - e_flags
;
3297 out
= stpcpy (out
, ", BE8");
3301 out
= stpcpy (out
, ", LE8");
3304 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
3305 out
= stpcpy (out
, ", soft-float ABI");
3308 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
3309 out
= stpcpy (out
, ", hard-float ABI");
3319 case EF_ARM_EABI_UNKNOWN
:
3320 out
= stpcpy (out
, ", GNU EABI");
3325 /* Process flags one bit at a time. */
3326 flag
= e_flags
& - e_flags
;
3331 case EF_ARM_INTERWORK
:
3332 out
= stpcpy (out
, ", interworking enabled");
3335 case EF_ARM_APCS_26
:
3336 out
= stpcpy (out
, ", uses APCS/26");
3339 case EF_ARM_APCS_FLOAT
:
3340 out
= stpcpy (out
, ", uses APCS/float");
3344 out
= stpcpy (out
, ", position independent");
3348 out
= stpcpy (out
, ", 8 bit structure alignment");
3351 case EF_ARM_NEW_ABI
:
3352 out
= stpcpy (out
, ", uses new ABI");
3355 case EF_ARM_OLD_ABI
:
3356 out
= stpcpy (out
, ", uses old ABI");
3359 case EF_ARM_SOFT_FLOAT
:
3360 out
= stpcpy (out
, ", software FP");
3363 case EF_ARM_VFP_FLOAT
:
3364 out
= stpcpy (out
, ", VFP");
3367 case EF_ARM_MAVERICK_FLOAT
:
3368 out
= stpcpy (out
, ", Maverick FP");
3379 out
= stpcpy (out
,_(", <unknown>"));
3384 decode_AVR_machine_flags (char *out
, unsigned e_flags
)
3386 switch (e_flags
& EF_AVR_MACH
)
3388 case E_AVR_MACH_AVR1
:
3389 out
= stpcpy (out
, ", avr:1");
3391 case E_AVR_MACH_AVR2
:
3392 out
= stpcpy (out
, ", avr:2");
3394 case E_AVR_MACH_AVR25
:
3395 out
= stpcpy (out
, ", avr:25");
3397 case E_AVR_MACH_AVR3
:
3398 out
= stpcpy (out
, ", avr:3");
3400 case E_AVR_MACH_AVR31
:
3401 out
= stpcpy (out
, ", avr:31");
3403 case E_AVR_MACH_AVR35
:
3404 out
= stpcpy (out
, ", avr:35");
3406 case E_AVR_MACH_AVR4
:
3407 out
= stpcpy (out
, ", avr:4");
3409 case E_AVR_MACH_AVR5
:
3410 out
= stpcpy (out
, ", avr:5");
3412 case E_AVR_MACH_AVR51
:
3413 out
= stpcpy (out
, ", avr:51");
3415 case E_AVR_MACH_AVR6
:
3416 out
= stpcpy (out
, ", avr:6");
3418 case E_AVR_MACH_AVRTINY
:
3419 out
= stpcpy (out
, ", avr:100");
3421 case E_AVR_MACH_XMEGA1
:
3422 out
= stpcpy (out
, ", avr:101");
3424 case E_AVR_MACH_XMEGA2
:
3425 out
= stpcpy (out
, ", avr:102");
3427 case E_AVR_MACH_XMEGA3
:
3428 out
= stpcpy (out
, ", avr:103");
3430 case E_AVR_MACH_XMEGA4
:
3431 out
= stpcpy (out
, ", avr:104");
3433 case E_AVR_MACH_XMEGA5
:
3434 out
= stpcpy (out
, ", avr:105");
3436 case E_AVR_MACH_XMEGA6
:
3437 out
= stpcpy (out
, ", avr:106");
3439 case E_AVR_MACH_XMEGA7
:
3440 out
= stpcpy (out
, ", avr:107");
3443 out
= stpcpy (out
, ", avr:<unknown>");
3447 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
3448 out
= stpcpy (out
, ", link-relax");
3453 decode_BLACKFIN_machine_flags (char *out
, unsigned e_flags
)
3455 if (e_flags
& EF_BFIN_PIC
)
3456 out
= stpcpy (out
, ", PIC");
3458 if (e_flags
& EF_BFIN_FDPIC
)
3459 out
= stpcpy (out
, ", FDPIC");
3461 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3462 out
= stpcpy (out
, ", code in L1");
3464 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3465 out
= stpcpy (out
, ", data in L1");
3470 decode_FRV_machine_flags (char *out
, unsigned e_flags
)
3472 switch (e_flags
& EF_FRV_CPU_MASK
)
3474 case EF_FRV_CPU_GENERIC
:
3478 out
= stpcpy (out
, ", fr???");
3481 case EF_FRV_CPU_FR300
:
3482 out
= stpcpy (out
, ", fr300");
3485 case EF_FRV_CPU_FR400
:
3486 out
= stpcpy (out
, ", fr400");
3488 case EF_FRV_CPU_FR405
:
3489 out
= stpcpy (out
, ", fr405");
3492 case EF_FRV_CPU_FR450
:
3493 out
= stpcpy (out
, ", fr450");
3496 case EF_FRV_CPU_FR500
:
3497 out
= stpcpy (out
, ", fr500");
3499 case EF_FRV_CPU_FR550
:
3500 out
= stpcpy (out
, ", fr550");
3503 case EF_FRV_CPU_SIMPLE
:
3504 out
= stpcpy (out
, ", simple");
3506 case EF_FRV_CPU_TOMCAT
:
3507 out
= stpcpy (out
, ", tomcat");
3514 decode_IA64_machine_flags (char *out
, unsigned e_flags
, Filedata
*filedata
)
3516 if ((e_flags
& EF_IA_64_ABI64
))
3517 out
= stpcpy (out
, ", 64-bit");
3519 out
= stpcpy (out
, ", 32-bit");
3520 if ((e_flags
& EF_IA_64_REDUCEDFP
))
3521 out
= stpcpy (out
, ", reduced fp model");
3522 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
3523 out
= stpcpy (out
, ", no function descriptors, constant gp");
3524 else if ((e_flags
& EF_IA_64_CONS_GP
))
3525 out
= stpcpy (out
, ", constant gp");
3526 if ((e_flags
& EF_IA_64_ABSOLUTE
))
3527 out
= stpcpy (out
, ", absolute");
3528 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3530 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
3531 out
= stpcpy (out
, ", vms_linkages");
3532 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
3534 case EF_IA_64_VMS_COMCOD_SUCCESS
:
3536 case EF_IA_64_VMS_COMCOD_WARNING
:
3537 out
= stpcpy (out
, ", warning");
3539 case EF_IA_64_VMS_COMCOD_ERROR
:
3540 out
= stpcpy (out
, ", error");
3542 case EF_IA_64_VMS_COMCOD_ABORT
:
3543 out
= stpcpy (out
, ", abort");
3546 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3547 e_flags
& EF_IA_64_VMS_COMCOD
);
3548 out
= stpcpy (out
, ", <unknown>");
3555 decode_LOONGARCH_machine_flags (char *out
, unsigned int e_flags
)
3557 if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags
))
3558 out
= stpcpy (out
, ", SOFT-FLOAT");
3559 else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags
))
3560 out
= stpcpy (out
, ", SINGLE-FLOAT");
3561 else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags
))
3562 out
= stpcpy (out
, ", DOUBLE-FLOAT");
3564 if (EF_LOONGARCH_IS_OBJ_V0 (e_flags
))
3565 out
= stpcpy (out
, ", OBJ-v0");
3566 else if (EF_LOONGARCH_IS_OBJ_V1 (e_flags
))
3567 out
= stpcpy (out
, ", OBJ-v1");
3572 decode_M68K_machine_flags (char *out
, unsigned int e_flags
)
3574 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3575 out
= stpcpy (out
, ", m68000");
3576 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3577 out
= stpcpy (out
, ", cpu32");
3578 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3579 out
= stpcpy (out
, ", fido_a");
3582 char const *isa
= _("unknown");
3583 char const *mac
= _("unknown mac");
3584 char const *additional
= NULL
;
3586 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3588 case EF_M68K_CF_ISA_A_NODIV
:
3590 additional
= ", nodiv";
3592 case EF_M68K_CF_ISA_A
:
3595 case EF_M68K_CF_ISA_A_PLUS
:
3598 case EF_M68K_CF_ISA_B_NOUSP
:
3600 additional
= ", nousp";
3602 case EF_M68K_CF_ISA_B
:
3605 case EF_M68K_CF_ISA_C
:
3608 case EF_M68K_CF_ISA_C_NODIV
:
3610 additional
= ", nodiv";
3613 out
= stpcpy (out
, ", cf, isa ");
3614 out
= stpcpy (out
, isa
);
3616 out
= stpcpy (out
, additional
);
3617 if (e_flags
& EF_M68K_CF_FLOAT
)
3618 out
= stpcpy (out
, ", float");
3619 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3624 case EF_M68K_CF_MAC
:
3627 case EF_M68K_CF_EMAC
:
3630 case EF_M68K_CF_EMAC_B
:
3636 out
= stpcpy (out
, ", ");
3637 out
= stpcpy (out
, mac
);
3644 decode_MeP_machine_flags (char *out
, unsigned int e_flags
)
3646 switch (e_flags
& EF_MEP_CPU_MASK
)
3648 case EF_MEP_CPU_MEP
:
3649 out
= stpcpy (out
, ", generic MeP");
3652 out
= stpcpy (out
, ", MeP C2");
3655 out
= stpcpy (out
, ", MeP C3");
3658 out
= stpcpy (out
, ", MeP C4");
3661 out
= stpcpy (out
, ", MeP C5");
3664 out
= stpcpy (out
, ", MeP H1");
3667 out
= stpcpy (out
, _(", <unknown MeP cpu type>"));
3671 switch (e_flags
& EF_MEP_COP_MASK
)
3673 case EF_MEP_COP_NONE
:
3675 case EF_MEP_COP_AVC
:
3676 out
= stpcpy (out
, ", AVC coprocessor");
3678 case EF_MEP_COP_AVC2
:
3679 out
= stpcpy (out
, ", AVC2 coprocessor");
3681 case EF_MEP_COP_FMAX
:
3682 out
= stpcpy (out
, ", FMAX coprocessor");
3684 case EF_MEP_COP_IVC2
:
3685 out
= stpcpy (out
, ", IVC2 coprocessor");
3688 out
= stpcpy (out
, _("<unknown MeP copro type>"));
3692 if (e_flags
& EF_MEP_LIBRARY
)
3693 out
= stpcpy (out
, ", Built for Library");
3695 if (e_flags
& EF_MEP_INDEX_MASK
)
3696 out
+= sprintf (out
, ", Configuration Index: %#x",
3697 e_flags
& EF_MEP_INDEX_MASK
);
3699 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3700 out
+= sprintf (out
, _(", unknown flags bits: %#x"),
3701 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3706 decode_MIPS_machine_flags (char *out
, unsigned int e_flags
)
3708 if (e_flags
& EF_MIPS_NOREORDER
)
3709 out
= stpcpy (out
, ", noreorder");
3711 if (e_flags
& EF_MIPS_PIC
)
3712 out
= stpcpy (out
, ", pic");
3714 if (e_flags
& EF_MIPS_CPIC
)
3715 out
= stpcpy (out
, ", cpic");
3717 if (e_flags
& EF_MIPS_UCODE
)
3718 out
= stpcpy (out
, ", ugen_reserved");
3720 if (e_flags
& EF_MIPS_ABI2
)
3721 out
= stpcpy (out
, ", abi2");
3723 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
3724 out
= stpcpy (out
, ", odk first");
3726 if (e_flags
& EF_MIPS_32BITMODE
)
3727 out
= stpcpy (out
, ", 32bitmode");
3729 if (e_flags
& EF_MIPS_NAN2008
)
3730 out
= stpcpy (out
, ", nan2008");
3732 if (e_flags
& EF_MIPS_FP64
)
3733 out
= stpcpy (out
, ", fp64");
3735 switch ((e_flags
& EF_MIPS_MACH
))
3737 case EF_MIPS_MACH_3900
:
3738 out
= stpcpy (out
, ", 3900");
3740 case EF_MIPS_MACH_4010
:
3741 out
= stpcpy (out
, ", 4010");
3743 case EF_MIPS_MACH_4100
:
3744 out
= stpcpy (out
, ", 4100");
3746 case EF_MIPS_MACH_4111
:
3747 out
= stpcpy (out
, ", 4111");
3749 case EF_MIPS_MACH_4120
:
3750 out
= stpcpy (out
, ", 4120");
3752 case EF_MIPS_MACH_4650
:
3753 out
= stpcpy (out
, ", 4650");
3755 case EF_MIPS_MACH_5400
:
3756 out
= stpcpy (out
, ", 5400");
3758 case EF_MIPS_MACH_5500
:
3759 out
= stpcpy (out
, ", 5500");
3761 case EF_MIPS_MACH_5900
:
3762 out
= stpcpy (out
, ", 5900");
3764 case EF_MIPS_MACH_SB1
:
3765 out
= stpcpy (out
, ", sb1");
3767 case EF_MIPS_MACH_9000
:
3768 out
= stpcpy (out
, ", 9000");
3770 case EF_MIPS_MACH_LS2E
:
3771 out
= stpcpy (out
, ", loongson-2e");
3773 case EF_MIPS_MACH_LS2F
:
3774 out
= stpcpy (out
, ", loongson-2f");
3776 case EF_MIPS_MACH_GS464
:
3777 out
= stpcpy (out
, ", gs464");
3779 case EF_MIPS_MACH_GS464E
:
3780 out
= stpcpy (out
, ", gs464e");
3782 case EF_MIPS_MACH_GS264E
:
3783 out
= stpcpy (out
, ", gs264e");
3785 case EF_MIPS_MACH_OCTEON
:
3786 out
= stpcpy (out
, ", octeon");
3788 case EF_MIPS_MACH_OCTEON2
:
3789 out
= stpcpy (out
, ", octeon2");
3791 case EF_MIPS_MACH_OCTEON3
:
3792 out
= stpcpy (out
, ", octeon3");
3794 case EF_MIPS_MACH_XLR
:
3795 out
= stpcpy (out
, ", xlr");
3797 case EF_MIPS_MACH_IAMR2
:
3798 out
= stpcpy (out
, ", interaptiv-mr2");
3800 case EF_MIPS_MACH_ALLEGREX
:
3801 out
= stpcpy (out
, ", allegrex");
3804 /* We simply ignore the field in this case to avoid confusion:
3805 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3809 out
= stpcpy (out
, _(", unknown CPU"));
3813 switch ((e_flags
& EF_MIPS_ABI
))
3815 case EF_MIPS_ABI_O32
:
3816 out
= stpcpy (out
, ", o32");
3818 case EF_MIPS_ABI_O64
:
3819 out
= stpcpy (out
, ", o64");
3821 case EF_MIPS_ABI_EABI32
:
3822 out
= stpcpy (out
, ", eabi32");
3824 case EF_MIPS_ABI_EABI64
:
3825 out
= stpcpy (out
, ", eabi64");
3828 /* We simply ignore the field in this case to avoid confusion:
3829 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3830 This means it is likely to be an o32 file, but not for
3834 out
= stpcpy (out
, _(", unknown ABI"));
3838 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
3839 out
= stpcpy (out
, ", mdmx");
3841 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
3842 out
= stpcpy (out
, ", mips16");
3844 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
3845 out
= stpcpy (out
, ", micromips");
3847 switch ((e_flags
& EF_MIPS_ARCH
))
3849 case EF_MIPS_ARCH_1
:
3850 out
= stpcpy (out
, ", mips1");
3852 case EF_MIPS_ARCH_2
:
3853 out
= stpcpy (out
, ", mips2");
3855 case EF_MIPS_ARCH_3
:
3856 out
= stpcpy (out
, ", mips3");
3858 case EF_MIPS_ARCH_4
:
3859 out
= stpcpy (out
, ", mips4");
3861 case EF_MIPS_ARCH_5
:
3862 out
= stpcpy (out
, ", mips5");
3864 case EF_MIPS_ARCH_32
:
3865 out
= stpcpy (out
, ", mips32");
3867 case EF_MIPS_ARCH_32R2
:
3868 out
= stpcpy (out
, ", mips32r2");
3870 case EF_MIPS_ARCH_32R6
:
3871 out
= stpcpy (out
, ", mips32r6");
3873 case EF_MIPS_ARCH_64
:
3874 out
= stpcpy (out
, ", mips64");
3876 case EF_MIPS_ARCH_64R2
:
3877 out
= stpcpy (out
, ", mips64r2");
3879 case EF_MIPS_ARCH_64R6
:
3880 out
= stpcpy (out
, ", mips64r6");
3883 out
= stpcpy (out
, _(", unknown ISA"));
3890 decode_MSP430_machine_flags (char *out
, unsigned e_flags
)
3892 out
= stpcpy (out
, _(": architecture variant: "));
3893 switch (e_flags
& EF_MSP430_MACH
)
3895 case E_MSP430_MACH_MSP430x11
:
3896 out
= stpcpy (out
, "MSP430x11");
3898 case E_MSP430_MACH_MSP430x11x1
:
3899 out
= stpcpy (out
, "MSP430x11x1 ");
3901 case E_MSP430_MACH_MSP430x12
:
3902 out
= stpcpy (out
, "MSP430x12");
3904 case E_MSP430_MACH_MSP430x13
:
3905 out
= stpcpy (out
, "MSP430x13");
3907 case E_MSP430_MACH_MSP430x14
:
3908 out
= stpcpy (out
, "MSP430x14");
3910 case E_MSP430_MACH_MSP430x15
:
3911 out
= stpcpy (out
, "MSP430x15");
3913 case E_MSP430_MACH_MSP430x16
:
3914 out
= stpcpy (out
, "MSP430x16");
3916 case E_MSP430_MACH_MSP430x31
:
3917 out
= stpcpy (out
, "MSP430x31");
3919 case E_MSP430_MACH_MSP430x32
:
3920 out
= stpcpy (out
, "MSP430x32");
3922 case E_MSP430_MACH_MSP430x33
:
3923 out
= stpcpy (out
, "MSP430x33");
3925 case E_MSP430_MACH_MSP430x41
:
3926 out
= stpcpy (out
, "MSP430x41");
3928 case E_MSP430_MACH_MSP430x42
:
3929 out
= stpcpy (out
, "MSP430x42");
3931 case E_MSP430_MACH_MSP430x43
:
3932 out
= stpcpy (out
, "MSP430x43");
3934 case E_MSP430_MACH_MSP430x44
:
3935 out
= stpcpy (out
, "MSP430x44");
3937 case E_MSP430_MACH_MSP430X
:
3938 out
= stpcpy (out
, "MSP430X");
3941 out
= stpcpy (out
, _(": unknown"));
3945 if (e_flags
& ~ EF_MSP430_MACH
)
3946 out
= stpcpy (out
, _(": unknown extra flag bits also present"));
3951 decode_NDS32_machine_flags (char *out
, unsigned e_flags
)
3957 bool has_fpu
= false;
3959 static const char *ABI_STRINGS
[] =
3961 "ABI v0", /* use r5 as return register; only used in N1213HC */
3962 "ABI v1", /* use r0 as return register */
3963 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
3964 "ABI v2fp", /* for FPU */
3968 static const char *VER_STRINGS
[] =
3970 "Andes ELF V1.3 or older",
3974 static const char *ARCH_STRINGS
[] =
3983 abi
= EF_NDS_ABI
& e_flags
;
3984 arch
= EF_NDS_ARCH
& e_flags
;
3985 config
= EF_NDS_INST
& e_flags
;
3986 version
= EF_NDS32_ELF_VERSION
& e_flags
;
3993 case E_NDS_ABI_V2FP
:
3994 case E_NDS_ABI_AABI
:
3995 case E_NDS_ABI_V2FP_PLUS
:
3996 /* In case there are holes in the array. */
3997 out
+= sprintf (out
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
4001 out
= stpcpy (out
, ", <unrecognized ABI>");
4007 case E_NDS32_ELF_VER_1_2
:
4008 case E_NDS32_ELF_VER_1_3
:
4009 case E_NDS32_ELF_VER_1_4
:
4010 out
+= sprintf (out
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
4014 out
= stpcpy (out
, ", <unrecognized ELF version number>");
4018 if (E_NDS_ABI_V0
== abi
)
4020 /* OLD ABI; only used in N1213HC, has performance extension 1. */
4021 out
= stpcpy (out
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
4022 if (arch
== E_NDS_ARCH_STAR_V1_0
)
4023 out
= stpcpy (out
, ", 16b"); /* has 16-bit instructions */
4029 case E_NDS_ARCH_STAR_V1_0
:
4030 case E_NDS_ARCH_STAR_V2_0
:
4031 case E_NDS_ARCH_STAR_V3_0
:
4032 case E_NDS_ARCH_STAR_V3_M
:
4033 out
+= sprintf (out
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
4037 out
= stpcpy (out
, ", <unrecognized architecture>");
4038 /* ARCH version determines how the e_flags are interpreted.
4039 If it is unknown, we cannot proceed. */
4043 /* Newer ABI; Now handle architecture specific flags. */
4044 if (arch
== E_NDS_ARCH_STAR_V1_0
)
4046 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
4047 out
= stpcpy (out
, ", MFUSR_PC");
4049 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
4050 out
= stpcpy (out
, ", MAC");
4052 if (config
& E_NDS32_HAS_DIV_INST
)
4053 out
= stpcpy (out
, ", DIV");
4055 if (config
& E_NDS32_HAS_16BIT_INST
)
4056 out
= stpcpy (out
, ", 16b");
4060 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
4062 if (version
<= E_NDS32_ELF_VER_1_3
)
4063 out
= stpcpy (out
, ", [B8]");
4065 out
= stpcpy (out
, ", EX9");
4068 if (config
& E_NDS32_HAS_MAC_DX_INST
)
4069 out
= stpcpy (out
, ", MAC_DX");
4071 if (config
& E_NDS32_HAS_DIV_DX_INST
)
4072 out
= stpcpy (out
, ", DIV_DX");
4074 if (config
& E_NDS32_HAS_16BIT_INST
)
4076 if (version
<= E_NDS32_ELF_VER_1_3
)
4077 out
= stpcpy (out
, ", 16b");
4079 out
= stpcpy (out
, ", IFC");
4083 if (config
& E_NDS32_HAS_EXT_INST
)
4084 out
= stpcpy (out
, ", PERF1");
4086 if (config
& E_NDS32_HAS_EXT2_INST
)
4087 out
= stpcpy (out
, ", PERF2");
4089 if (config
& E_NDS32_HAS_FPU_INST
)
4092 out
= stpcpy (out
, ", FPU_SP");
4095 if (config
& E_NDS32_HAS_FPU_DP_INST
)
4098 out
= stpcpy (out
, ", FPU_DP");
4101 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
4104 out
= stpcpy (out
, ", FPU_MAC");
4109 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
4111 case E_NDS32_FPU_REG_8SP_4DP
:
4112 out
= stpcpy (out
, ", FPU_REG:8/4");
4114 case E_NDS32_FPU_REG_16SP_8DP
:
4115 out
= stpcpy (out
, ", FPU_REG:16/8");
4117 case E_NDS32_FPU_REG_32SP_16DP
:
4118 out
= stpcpy (out
, ", FPU_REG:32/16");
4120 case E_NDS32_FPU_REG_32SP_32DP
:
4121 out
= stpcpy (out
, ", FPU_REG:32/32");
4126 if (config
& E_NDS32_HAS_AUDIO_INST
)
4127 out
= stpcpy (out
, ", AUDIO");
4129 if (config
& E_NDS32_HAS_STRING_INST
)
4130 out
= stpcpy (out
, ", STR");
4132 if (config
& E_NDS32_HAS_REDUCED_REGS
)
4133 out
= stpcpy (out
, ", 16REG");
4135 if (config
& E_NDS32_HAS_VIDEO_INST
)
4137 if (version
<= E_NDS32_ELF_VER_1_3
)
4138 out
= stpcpy (out
, ", VIDEO");
4140 out
= stpcpy (out
, ", SATURATION");
4143 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
4144 out
= stpcpy (out
, ", ENCRP");
4146 if (config
& E_NDS32_HAS_L2C_INST
)
4147 out
= stpcpy (out
, ", L2C");
4153 decode_PARISC_machine_flags (char *out
, unsigned e_flags
)
4155 switch (e_flags
& EF_PARISC_ARCH
)
4157 case EFA_PARISC_1_0
:
4158 out
= stpcpy (out
, ", PA-RISC 1.0");
4160 case EFA_PARISC_1_1
:
4161 out
= stpcpy (out
, ", PA-RISC 1.1");
4163 case EFA_PARISC_2_0
:
4164 out
= stpcpy (out
, ", PA-RISC 2.0");
4169 if (e_flags
& EF_PARISC_TRAPNIL
)
4170 out
= stpcpy (out
, ", trapnil");
4171 if (e_flags
& EF_PARISC_EXT
)
4172 out
= stpcpy (out
, ", ext");
4173 if (e_flags
& EF_PARISC_LSB
)
4174 out
= stpcpy (out
, ", lsb");
4175 if (e_flags
& EF_PARISC_WIDE
)
4176 out
= stpcpy (out
, ", wide");
4177 if (e_flags
& EF_PARISC_NO_KABP
)
4178 out
= stpcpy (out
, ", no kabp");
4179 if (e_flags
& EF_PARISC_LAZYSWAP
)
4180 out
= stpcpy (out
, ", lazyswap");
4185 decode_RISCV_machine_flags (char *out
, unsigned e_flags
)
4187 if (e_flags
& EF_RISCV_RVC
)
4188 out
= stpcpy (out
, ", RVC");
4190 if (e_flags
& EF_RISCV_RVE
)
4191 out
= stpcpy (out
, ", RVE");
4193 if (e_flags
& EF_RISCV_TSO
)
4194 out
= stpcpy (out
, ", TSO");
4196 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
4198 case EF_RISCV_FLOAT_ABI_SOFT
:
4199 out
= stpcpy (out
, ", soft-float ABI");
4202 case EF_RISCV_FLOAT_ABI_SINGLE
:
4203 out
= stpcpy (out
, ", single-float ABI");
4206 case EF_RISCV_FLOAT_ABI_DOUBLE
:
4207 out
= stpcpy (out
, ", double-float ABI");
4210 case EF_RISCV_FLOAT_ABI_QUAD
:
4211 out
= stpcpy (out
, ", quad-float ABI");
4218 decode_RL78_machine_flags (char *out
, unsigned e_flags
)
4220 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
4222 case E_FLAG_RL78_ANY_CPU
:
4224 case E_FLAG_RL78_G10
:
4225 out
= stpcpy (out
, ", G10");
4227 case E_FLAG_RL78_G13
:
4228 out
= stpcpy (out
, ", G13");
4230 case E_FLAG_RL78_G14
:
4231 out
= stpcpy (out
, ", G14");
4234 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
4235 out
= stpcpy (out
, ", 64-bit doubles");
4240 decode_RX_machine_flags (char *out
, unsigned e_flags
)
4242 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
4243 out
= stpcpy (out
, ", 64-bit doubles");
4244 if (e_flags
& E_FLAG_RX_DSP
)
4245 out
= stpcpy (out
, ", dsp");
4246 if (e_flags
& E_FLAG_RX_PID
)
4247 out
= stpcpy (out
, ", pid");
4248 if (e_flags
& E_FLAG_RX_ABI
)
4249 out
= stpcpy (out
, ", RX ABI");
4250 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
4251 out
= stpcpy (out
, (e_flags
& E_FLAG_RX_SINSNS_YES
4252 ? ", uses String instructions"
4253 : ", bans String instructions"));
4254 if (e_flags
& E_FLAG_RX_V2
)
4255 out
= stpcpy (out
, ", V2");
4256 if (e_flags
& E_FLAG_RX_V3
)
4257 out
= stpcpy (out
, ", V3");
4262 decode_SH_machine_flags (char *out
, unsigned e_flags
)
4264 switch ((e_flags
& EF_SH_MACH_MASK
))
4267 out
= stpcpy (out
, ", sh1");
4270 out
= stpcpy (out
, ", sh2");
4273 out
= stpcpy (out
, ", sh3");
4276 out
= stpcpy (out
, ", sh-dsp");
4279 out
= stpcpy (out
, ", sh3-dsp");
4282 out
= stpcpy (out
, ", sh4al-dsp");
4285 out
= stpcpy (out
, ", sh3e");
4288 out
= stpcpy (out
, ", sh4");
4291 out
= stpcpy (out
, ", sh5");
4294 out
= stpcpy (out
, ", sh2e");
4297 out
= stpcpy (out
, ", sh4a");
4300 out
= stpcpy (out
, ", sh2a");
4303 out
= stpcpy (out
, ", sh4-nofpu");
4306 out
= stpcpy (out
, ", sh4a-nofpu");
4309 out
= stpcpy (out
, ", sh2a-nofpu");
4312 out
= stpcpy (out
, ", sh3-nommu");
4314 case EF_SH4_NOMMU_NOFPU
:
4315 out
= stpcpy (out
, ", sh4-nommu-nofpu");
4317 case EF_SH2A_SH4_NOFPU
:
4318 out
= stpcpy (out
, ", sh2a-nofpu-or-sh4-nommu-nofpu");
4320 case EF_SH2A_SH3_NOFPU
:
4321 out
= stpcpy (out
, ", sh2a-nofpu-or-sh3-nommu");
4324 out
= stpcpy (out
, ", sh2a-or-sh4");
4327 out
= stpcpy (out
, ", sh2a-or-sh3e");
4330 out
= stpcpy (out
, _(", unknown ISA"));
4334 if (e_flags
& EF_SH_PIC
)
4335 out
= stpcpy (out
, ", pic");
4337 if (e_flags
& EF_SH_FDPIC
)
4338 out
= stpcpy (out
, ", fdpic");
4343 decode_SPARC_machine_flags (char *out
, unsigned e_flags
)
4345 if (e_flags
& EF_SPARC_32PLUS
)
4346 out
= stpcpy (out
, ", v8+");
4348 if (e_flags
& EF_SPARC_SUN_US1
)
4349 out
= stpcpy (out
, ", ultrasparcI");
4351 if (e_flags
& EF_SPARC_SUN_US3
)
4352 out
= stpcpy (out
, ", ultrasparcIII");
4354 if (e_flags
& EF_SPARC_HAL_R1
)
4355 out
= stpcpy (out
, ", halr1");
4357 if (e_flags
& EF_SPARC_LEDATA
)
4358 out
= stpcpy (out
, ", ledata");
4360 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
4361 out
= stpcpy (out
, ", tso");
4363 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
4364 out
= stpcpy (out
, ", pso");
4366 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
4367 out
= stpcpy (out
, ", rmo");
4372 decode_V800_machine_flags (char *out
, unsigned int e_flags
)
4374 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
4375 out
= stpcpy (out
, ", RH850 ABI");
4377 if (e_flags
& EF_V800_850E3
)
4378 out
= stpcpy (out
, ", V3 architecture");
4380 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
4381 out
= stpcpy (out
, ", FPU not used");
4383 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
4384 out
= stpcpy (out
, ", regmode: COMMON");
4386 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
4387 out
= stpcpy (out
, ", r4 not used");
4389 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
4390 out
= stpcpy (out
, ", r30 not used");
4392 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
4393 out
= stpcpy (out
, ", r5 not used");
4395 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
4396 out
= stpcpy (out
, ", r2 not used");
4398 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
4400 switch (e_flags
& - e_flags
)
4402 case EF_RH850_FPU_DOUBLE
:
4403 out
= stpcpy (out
, ", double precision FPU");
4405 case EF_RH850_FPU_SINGLE
:
4406 out
= stpcpy (out
, ", single precision FPU");
4408 case EF_RH850_REGMODE22
:
4409 out
= stpcpy (out
, ", regmode:22");
4411 case EF_RH850_REGMODE32
:
4412 out
= stpcpy (out
, ", regmode:23");
4414 case EF_RH850_GP_FIX
:
4415 out
= stpcpy (out
, ", r4 fixed");
4417 case EF_RH850_GP_NOFIX
:
4418 out
= stpcpy (out
, ", r4 free");
4420 case EF_RH850_EP_FIX
:
4421 out
= stpcpy (out
, ", r30 fixed");
4423 case EF_RH850_EP_NOFIX
:
4424 out
= stpcpy (out
, ", r30 free");
4426 case EF_RH850_TP_FIX
:
4427 out
= stpcpy (out
, ", r5 fixed");
4429 case EF_RH850_TP_NOFIX
:
4430 out
= stpcpy (out
, ", r5 free");
4432 case EF_RH850_REG2_RESERVE
:
4433 out
= stpcpy (out
, ", r2 fixed");
4435 case EF_RH850_REG2_NORESERVE
:
4436 out
= stpcpy (out
, ", r2 free");
4446 decode_V850_machine_flags (char *out
, unsigned int e_flags
)
4448 switch (e_flags
& EF_V850_ARCH
)
4450 case E_V850E3V5_ARCH
:
4451 out
= stpcpy (out
, ", v850e3v5");
4453 case E_V850E2V3_ARCH
:
4454 out
= stpcpy (out
, ", v850e2v3");
4457 out
= stpcpy (out
, ", v850e2");
4460 out
= stpcpy (out
, ", v850e1");
4463 out
= stpcpy (out
, ", v850e");
4466 out
= stpcpy (out
, ", v850");
4469 out
= stpcpy (out
, _(", unknown v850 architecture variant"));
4476 decode_Z80_machine_flags (char *out
, unsigned int e_flags
)
4478 switch (e_flags
& EF_Z80_MACH_MSK
)
4480 case EF_Z80_MACH_Z80
:
4481 out
= stpcpy (out
, ", Z80");
4483 case EF_Z80_MACH_Z180
:
4484 out
= stpcpy (out
, ", Z180");
4486 case EF_Z80_MACH_R800
:
4487 out
= stpcpy (out
, ", R800");
4489 case EF_Z80_MACH_EZ80_Z80
:
4490 out
= stpcpy (out
, ", EZ80");
4492 case EF_Z80_MACH_EZ80_ADL
:
4493 out
= stpcpy (out
, ", EZ80, ADL");
4495 case EF_Z80_MACH_GBZ80
:
4496 out
= stpcpy (out
, ", GBZ80");
4498 case EF_Z80_MACH_Z80N
:
4499 out
= stpcpy (out
, ", Z80N");
4502 out
= stpcpy (out
, _(", unknown"));
4509 decode_AMDGPU_machine_flags (char *out
, unsigned int e_flags
, Filedata
*filedata
)
4511 unsigned char *e_ident
= filedata
->file_header
.e_ident
;
4512 unsigned char osabi
= e_ident
[EI_OSABI
];
4513 unsigned char abiversion
= e_ident
[EI_ABIVERSION
];
4516 /* HSA OS ABI v2 used a different encoding, but we don't need to support it,
4517 it has been deprecated for a while.
4519 The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time
4520 of writing, they use the same flags as HSA v3, so the code below uses that
4522 if (osabi
== ELFOSABI_AMDGPU_HSA
&& abiversion
< ELFABIVERSION_AMDGPU_HSA_V3
)
4525 mach
= e_flags
& EF_AMDGPU_MACH
;
4528 #define AMDGPU_CASE(code, string) \
4529 case code: out = stpcpy (out, ", " string); break;
4530 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600
, "gfx600")
4531 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601
, "gfx601")
4532 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700
, "gfx700")
4533 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701
, "gfx701")
4534 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702
, "gfx702")
4535 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703
, "gfx703")
4536 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704
, "gfx704")
4537 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801
, "gfx801")
4538 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802
, "gfx802")
4539 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803
, "gfx803")
4540 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810
, "gfx810")
4541 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900
, "gfx900")
4542 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902
, "gfx902")
4543 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904
, "gfx904")
4544 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906
, "gfx906")
4545 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908
, "gfx908")
4546 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909
, "gfx909")
4547 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C
, "gfx90c")
4548 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010
, "gfx1010")
4549 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011
, "gfx1011")
4550 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012
, "gfx1012")
4551 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030
, "gfx1030")
4552 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031
, "gfx1031")
4553 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032
, "gfx1032")
4554 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033
, "gfx1033")
4555 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1100
, "gfx1100")
4556 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1101
, "gfx1101")
4557 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1102
, "gfx1102")
4558 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602
, "gfx602")
4559 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705
, "gfx705")
4560 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805
, "gfx805")
4561 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035
, "gfx1035")
4562 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034
, "gfx1034")
4563 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A
, "gfx90a")
4564 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940
, "gfx940")
4565 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013
, "gfx1013")
4566 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036
, "gfx1036")
4568 out
+= sprintf (out
, _(", <unknown AMDGPU GPU type: %#x>"), mach
);
4573 e_flags
&= ~EF_AMDGPU_MACH
;
4575 if ((osabi
== ELFOSABI_AMDGPU_HSA
4576 && abiversion
== ELFABIVERSION_AMDGPU_HSA_V3
)
4577 || osabi
!= ELFOSABI_AMDGPU_HSA
)
4579 /* For HSA v3 and other OS ABIs. */
4580 if (e_flags
& EF_AMDGPU_FEATURE_XNACK_V3
)
4582 out
= stpcpy (out
, ", xnack on");
4583 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V3
;
4586 if (e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V3
)
4588 out
= stpcpy (out
, ", sramecc on");
4589 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V3
;
4597 xnack
= e_flags
& EF_AMDGPU_FEATURE_XNACK_V4
;
4600 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
:
4603 case EF_AMDGPU_FEATURE_XNACK_ANY_V4
:
4604 out
= stpcpy (out
, ", xnack any");
4607 case EF_AMDGPU_FEATURE_XNACK_OFF_V4
:
4608 out
= stpcpy (out
, ", xnack off");
4611 case EF_AMDGPU_FEATURE_XNACK_ON_V4
:
4612 out
= stpcpy (out
, ", xnack on");
4616 out
+= sprintf (out
, _(", <unknown xnack value: %#x>"), xnack
);
4620 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V4
;
4622 sramecc
= e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V4
;
4625 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
:
4628 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
:
4629 out
= stpcpy (out
, ", sramecc any");
4632 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
:
4633 out
= stpcpy (out
, ", sramecc off");
4636 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4
:
4637 out
= stpcpy (out
, ", sramecc on");
4641 out
+= sprintf (out
, _(", <unknown sramecc value: %#x>"), sramecc
);
4645 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V4
;
4649 out
+= sprintf (out
, _(", unknown flags bits: %#x"), e_flags
);
4654 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
4656 static char buf
[1024];
4668 case EM_ARC_COMPACT3
:
4669 out
= stpcpy (out
, ", HS5x");
4672 case EM_ARC_COMPACT3_64
:
4673 out
= stpcpy (out
, ", HS6x");
4676 case EM_ARC_COMPACT2
:
4677 case EM_ARC_COMPACT
:
4678 out
= decode_ARC_machine_flags (out
, e_flags
, e_machine
);
4682 out
= decode_ARM_machine_flags (out
, e_flags
);
4686 out
= decode_AVR_machine_flags (out
, e_flags
);
4690 out
= decode_BLACKFIN_machine_flags (out
, e_flags
);
4694 out
= decode_FRV_machine_flags (out
, e_flags
);
4698 out
= decode_M68K_machine_flags (out
, e_flags
);
4702 out
= decode_AMDGPU_machine_flags (out
, e_flags
, filedata
);
4706 out
= decode_MeP_machine_flags (out
, e_flags
);
4710 if (e_flags
& EF_PPC_EMB
)
4711 out
= stpcpy (out
, ", emb");
4713 if (e_flags
& EF_PPC_RELOCATABLE
)
4714 out
= stpcpy (out
, _(", relocatable"));
4716 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
4717 out
= stpcpy (out
, _(", relocatable-lib"));
4721 if (e_flags
& EF_PPC64_ABI
)
4722 out
+= sprintf (out
, ", abiv%d", e_flags
& EF_PPC64_ABI
);
4726 out
= decode_V800_machine_flags (out
, e_flags
);
4730 case EM_CYGNUS_V850
:
4731 out
= decode_V850_machine_flags (out
, e_flags
);
4735 case EM_CYGNUS_M32R
:
4736 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
4737 out
= stpcpy (out
, ", m32r");
4741 case EM_MIPS_RS3_LE
:
4742 out
= decode_MIPS_machine_flags (out
, e_flags
);
4746 out
= decode_NDS32_machine_flags (out
, e_flags
);
4750 switch (EF_NFP_MACH (e_flags
))
4752 case E_NFP_MACH_3200
:
4753 out
= stpcpy (out
, ", NFP-32xx");
4755 case E_NFP_MACH_6000
:
4756 out
= stpcpy (out
, ", NFP-6xxx");
4762 out
= decode_RISCV_machine_flags (out
, e_flags
);
4766 out
= decode_SH_machine_flags (out
, e_flags
);
4770 if (e_flags
& EF_OR1K_NODELAY
)
4771 out
= stpcpy (out
, ", no delay");
4775 out
+= sprintf (out
, ", CPU Version: %u", e_flags
& EF_BPF_CPUVER
);
4779 out
= decode_SPARC_machine_flags (out
, e_flags
);
4783 out
= decode_PARISC_machine_flags (out
, e_flags
);
4788 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
4789 out
= stpcpy (out
, ", new calling convention");
4791 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
4792 out
= stpcpy (out
, ", gnu calling convention");
4796 out
= decode_IA64_machine_flags (out
, e_flags
, filedata
);
4800 if ((e_flags
& EF_VAX_NONPIC
))
4801 out
= stpcpy (out
, ", non-PIC");
4802 if ((e_flags
& EF_VAX_DFLOAT
))
4803 out
= stpcpy (out
, ", D-Float");
4804 if ((e_flags
& EF_VAX_GFLOAT
))
4805 out
= stpcpy (out
, ", G-Float");
4809 if (e_flags
& EF_VISIUM_ARCH_MCM
)
4810 out
= stpcpy (out
, ", mcm");
4811 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
4812 out
= stpcpy (out
, ", mcm24");
4813 if (e_flags
& EF_VISIUM_ARCH_GR6
)
4814 out
= stpcpy (out
, ", gr6");
4818 out
= decode_RL78_machine_flags (out
, e_flags
);
4822 out
= decode_RX_machine_flags (out
, e_flags
);
4826 if (e_flags
& EF_S390_HIGH_GPRS
)
4827 out
= stpcpy (out
, ", highgprs");
4831 if ((e_flags
& EF_C6000_REL
))
4832 out
= stpcpy (out
, ", relocatable module");
4836 if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV3_1
)
4837 strcat (buf
, ", Kalray VLIW kv3-1");
4838 else if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV3_2
)
4839 strcat (buf
, ", Kalray VLIW kv3-2");
4840 else if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV4_1
)
4841 strcat (buf
, ", Kalray VLIW kv4-1");
4843 strcat (buf
, ", unknown KVX MPPA");
4847 out
= decode_MSP430_machine_flags (out
, e_flags
);
4851 out
= decode_Z80_machine_flags (out
, e_flags
);
4855 out
= decode_LOONGARCH_machine_flags (out
, e_flags
);
4864 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
4866 static char buff
[32];
4870 case ELFOSABI_NONE
: return "UNIX - System V";
4871 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
4872 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
4873 case ELFOSABI_GNU
: return "UNIX - GNU";
4874 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
4875 case ELFOSABI_AIX
: return "UNIX - AIX";
4876 case ELFOSABI_IRIX
: return "UNIX - IRIX";
4877 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
4878 case ELFOSABI_TRU64
: return "UNIX - TRU64";
4879 case ELFOSABI_MODESTO
: return "Novell - Modesto";
4880 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
4881 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
4882 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
4883 case ELFOSABI_AROS
: return "AROS";
4884 case ELFOSABI_FENIXOS
: return "FenixOS";
4885 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
4886 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
4889 switch (filedata
->file_header
.e_machine
)
4894 case ELFOSABI_AMDGPU_HSA
: return "AMD HSA";
4895 case ELFOSABI_AMDGPU_PAL
: return "AMD PAL";
4896 case ELFOSABI_AMDGPU_MESA3D
: return "AMD Mesa3D";
4905 case ELFOSABI_ARM
: return "ARM";
4906 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
4917 case ELFOSABI_STANDALONE
: return _("Standalone App");
4926 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
4927 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
4936 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
4942 get_aarch64_segment_type (unsigned long type
)
4946 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
4947 case PT_AARCH64_MEMTAG_MTE
: return "AARCH64_MEMTAG_MTE";
4948 default: return NULL
;
4953 get_arm_segment_type (unsigned long type
)
4957 case PT_ARM_EXIDX
: return "EXIDX";
4958 default: return NULL
;
4963 get_s390_segment_type (unsigned long type
)
4967 case PT_S390_PGSTE
: return "S390_PGSTE";
4968 default: return NULL
;
4973 get_mips_segment_type (unsigned long type
)
4977 case PT_MIPS_REGINFO
: return "REGINFO";
4978 case PT_MIPS_RTPROC
: return "RTPROC";
4979 case PT_MIPS_OPTIONS
: return "OPTIONS";
4980 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
4981 default: return NULL
;
4986 get_parisc_segment_type (unsigned long type
)
4990 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
4991 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
4992 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
4993 default: return NULL
;
4998 get_ia64_segment_type (unsigned long type
)
5002 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
5003 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
5004 default: return NULL
;
5009 get_tic6x_segment_type (unsigned long type
)
5013 case PT_C6000_PHATTR
: return "C6000_PHATTR";
5014 default: return NULL
;
5019 get_riscv_segment_type (unsigned long type
)
5023 case PT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
5024 default: return NULL
;
5029 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
5031 if (e_machine
== EM_PARISC
)
5034 case PT_HP_TLS
: return "HP_TLS";
5035 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
5036 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
5037 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
5038 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
5039 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
5040 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
5041 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
5042 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
5043 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
5044 case PT_HP_PARALLEL
: return "HP_PARALLEL";
5045 case PT_HP_FASTBIND
: return "HP_FASTBIND";
5046 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
5047 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
5048 case PT_HP_STACK
: return "HP_STACK";
5049 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
5050 default: return NULL
;
5053 if (e_machine
== EM_IA_64
)
5056 case PT_HP_TLS
: return "HP_TLS";
5057 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
5058 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
5059 case PT_IA_64_HP_STACK
: return "HP_STACK";
5060 default: return NULL
;
5067 get_solaris_segment_type (unsigned long type
)
5071 case 0x6464e550: return "PT_SUNW_UNWIND";
5072 case 0x6474e550: return "PT_SUNW_EH_FRAME";
5073 case 0x6ffffff7: return "PT_LOSUNW";
5074 case 0x6ffffffa: return "PT_SUNWBSS";
5075 case 0x6ffffffb: return "PT_SUNWSTACK";
5076 case 0x6ffffffc: return "PT_SUNWDTRACE";
5077 case 0x6ffffffd: return "PT_SUNWCAP";
5078 case 0x6fffffff: return "PT_HISUNW";
5079 default: return NULL
;
5084 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
5086 static char buff
[32];
5090 case PT_NULL
: return "NULL";
5091 case PT_LOAD
: return "LOAD";
5092 case PT_DYNAMIC
: return "DYNAMIC";
5093 case PT_INTERP
: return "INTERP";
5094 case PT_NOTE
: return "NOTE";
5095 case PT_SHLIB
: return "SHLIB";
5096 case PT_PHDR
: return "PHDR";
5097 case PT_TLS
: return "TLS";
5098 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
5099 case PT_GNU_STACK
: return "GNU_STACK";
5100 case PT_GNU_RELRO
: return "GNU_RELRO";
5101 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
5102 case PT_GNU_SFRAME
: return "GNU_SFRAME";
5104 case PT_OPENBSD_MUTABLE
: return "OPENBSD_MUTABLE";
5105 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
5106 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
5107 case PT_OPENBSD_NOBTCFI
: return "OPENBSD_NOBTCFI";
5108 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
5111 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
5113 const char * result
;
5115 switch (filedata
->file_header
.e_machine
)
5118 result
= get_aarch64_segment_type (p_type
);
5121 result
= get_arm_segment_type (p_type
);
5124 case EM_MIPS_RS3_LE
:
5125 result
= get_mips_segment_type (p_type
);
5128 result
= get_parisc_segment_type (p_type
);
5131 result
= get_ia64_segment_type (p_type
);
5134 result
= get_tic6x_segment_type (p_type
);
5138 result
= get_s390_segment_type (p_type
);
5141 result
= get_riscv_segment_type (p_type
);
5151 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
5153 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
5155 const char * result
= NULL
;
5157 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
5160 case ELFOSABI_FREEBSD
:
5161 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
5163 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
5168 result
= get_hpux_segment_type (p_type
,
5169 filedata
->file_header
.e_machine
);
5171 case ELFOSABI_SOLARIS
:
5172 result
= get_solaris_segment_type (p_type
);
5180 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
5183 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
5190 get_arc_section_type_name (unsigned int sh_type
)
5194 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
5202 get_mips_section_type_name (unsigned int sh_type
)
5206 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
5207 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
5208 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
5209 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
5210 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
5211 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
5212 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
5213 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
5214 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
5215 case SHT_MIPS_RELD
: return "MIPS_RELD";
5216 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
5217 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
5218 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
5219 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
5220 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
5221 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
5222 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
5223 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
5224 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
5225 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
5226 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
5227 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
5228 case SHT_MIPS_LINE
: return "MIPS_LINE";
5229 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
5230 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
5231 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
5232 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
5233 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
5234 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
5235 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
5236 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
5237 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
5238 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
5239 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
5240 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
5241 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
5242 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
5243 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
5244 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
5245 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
5246 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
5254 get_parisc_section_type_name (unsigned int sh_type
)
5258 case SHT_PARISC_EXT
: return "PARISC_EXT";
5259 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
5260 case SHT_PARISC_DOC
: return "PARISC_DOC";
5261 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
5262 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
5263 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
5264 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
5265 default: return NULL
;
5270 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
5272 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
5273 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
5274 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
5278 case SHT_IA_64_EXT
: return "IA_64_EXT";
5279 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
5280 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
5281 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
5282 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
5283 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
5284 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
5285 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
5286 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
5287 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
5295 get_x86_64_section_type_name (unsigned int sh_type
)
5299 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
5300 default: return NULL
;
5305 get_aarch64_section_type_name (unsigned int sh_type
)
5309 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
5310 default: return NULL
;
5315 get_arm_section_type_name (unsigned int sh_type
)
5319 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
5320 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
5321 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
5322 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
5323 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
5324 default: return NULL
;
5329 get_tic6x_section_type_name (unsigned int sh_type
)
5333 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
5334 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
5335 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
5336 case SHT_TI_ICODE
: return "TI_ICODE";
5337 case SHT_TI_XREF
: return "TI_XREF";
5338 case SHT_TI_HANDLER
: return "TI_HANDLER";
5339 case SHT_TI_INITINFO
: return "TI_INITINFO";
5340 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
5341 default: return NULL
;
5346 get_msp430_section_type_name (unsigned int sh_type
)
5350 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
5351 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
5352 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
5353 default: return NULL
;
5358 get_nfp_section_type_name (unsigned int sh_type
)
5362 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
5363 case SHT_NFP_INITREG
: return "NFP_INITREG";
5364 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
5365 default: return NULL
;
5370 get_v850_section_type_name (unsigned int sh_type
)
5374 case SHT_V850_SCOMMON
: return "V850 Small Common";
5375 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
5376 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
5377 case SHT_RENESAS_IOP
: return "RENESAS IOP";
5378 case SHT_RENESAS_INFO
: return "RENESAS INFO";
5379 default: return NULL
;
5384 get_riscv_section_type_name (unsigned int sh_type
)
5388 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
5389 default: return NULL
;
5394 get_csky_section_type_name (unsigned int sh_type
)
5398 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
5399 default: return NULL
;
5404 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
5406 static char buff
[32];
5407 const char * result
;
5411 case SHT_NULL
: return "NULL";
5412 case SHT_PROGBITS
: return "PROGBITS";
5413 case SHT_SYMTAB
: return "SYMTAB";
5414 case SHT_STRTAB
: return "STRTAB";
5415 case SHT_RELA
: return "RELA";
5416 case SHT_RELR
: return "RELR";
5417 case SHT_HASH
: return "HASH";
5418 case SHT_DYNAMIC
: return "DYNAMIC";
5419 case SHT_NOTE
: return "NOTE";
5420 case SHT_NOBITS
: return "NOBITS";
5421 case SHT_REL
: return "REL";
5422 case SHT_SHLIB
: return "SHLIB";
5423 case SHT_DYNSYM
: return "DYNSYM";
5424 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
5425 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
5426 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
5427 case SHT_GNU_HASH
: return "GNU_HASH";
5428 case SHT_GROUP
: return "GROUP";
5429 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
5430 case SHT_GNU_verdef
: return "VERDEF";
5431 case SHT_GNU_verneed
: return "VERNEED";
5432 case SHT_GNU_versym
: return "VERSYM";
5433 case 0x6ffffff0: return "VERSYM";
5434 case 0x6ffffffc: return "VERDEF";
5435 case 0x7ffffffd: return "AUXILIARY";
5436 case 0x7fffffff: return "FILTER";
5437 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
5440 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
5442 switch (filedata
->file_header
.e_machine
)
5445 case EM_ARC_COMPACT
:
5446 case EM_ARC_COMPACT2
:
5447 case EM_ARC_COMPACT3
:
5448 case EM_ARC_COMPACT3_64
:
5449 result
= get_arc_section_type_name (sh_type
);
5452 case EM_MIPS_RS3_LE
:
5453 result
= get_mips_section_type_name (sh_type
);
5456 result
= get_parisc_section_type_name (sh_type
);
5459 result
= get_ia64_section_type_name (filedata
, sh_type
);
5464 result
= get_x86_64_section_type_name (sh_type
);
5467 result
= get_aarch64_section_type_name (sh_type
);
5470 result
= get_arm_section_type_name (sh_type
);
5473 result
= get_tic6x_section_type_name (sh_type
);
5476 result
= get_msp430_section_type_name (sh_type
);
5479 result
= get_nfp_section_type_name (sh_type
);
5483 case EM_CYGNUS_V850
:
5484 result
= get_v850_section_type_name (sh_type
);
5487 result
= get_riscv_section_type_name (sh_type
);
5490 result
= get_csky_section_type_name (sh_type
);
5500 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
5502 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
5504 switch (filedata
->file_header
.e_machine
)
5507 result
= get_ia64_section_type_name (filedata
, sh_type
);
5510 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
5511 result
= get_solaris_section_type (sh_type
);
5516 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
5517 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
5518 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
5519 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
5531 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
5533 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
5535 switch (filedata
->file_header
.e_machine
)
5539 case EM_CYGNUS_V850
:
5540 result
= get_v850_section_type_name (sh_type
);
5550 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
5553 /* This message is probably going to be displayed in a 15
5554 character wide field, so put the hex value first. */
5555 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
5561 enum long_option_values
5563 OPTION_DEBUG_DUMP
= 512,
5574 OPTION_WITH_SYMBOL_VERSIONS
,
5575 OPTION_RECURSE_LIMIT
,
5576 OPTION_NO_RECURSE_LIMIT
,
5577 OPTION_NO_DEMANGLING
,
5578 OPTION_NO_EXTRA_SYM_INFO
,
5582 static struct option options
[] =
5584 /* Note - This table is alpha-sorted on the 'val'
5585 field in order to make adding new options easier. */
5586 {"arch-specific", no_argument
, 0, 'A'},
5587 {"all", no_argument
, 0, 'a'},
5588 {"demangle", optional_argument
, 0, 'C'},
5589 {"archive-index", no_argument
, 0, 'c'},
5590 {"use-dynamic", no_argument
, 0, 'D'},
5591 {"dynamic", no_argument
, 0, 'd'},
5592 {"headers", no_argument
, 0, 'e'},
5593 {"section-groups", no_argument
, 0, 'g'},
5594 {"help", no_argument
, 0, 'H'},
5595 {"file-header", no_argument
, 0, 'h'},
5596 {"histogram", no_argument
, 0, 'I'},
5597 {"lint", no_argument
, 0, 'L'},
5598 {"enable-checks", no_argument
, 0, 'L'},
5599 {"program-headers", no_argument
, 0, 'l'},
5600 {"segments", no_argument
, 0, 'l'},
5601 {"full-section-name",no_argument
, 0, 'N'},
5602 {"notes", no_argument
, 0, 'n'},
5603 {"process-links", no_argument
, 0, 'P'},
5604 {"string-dump", required_argument
, 0, 'p'},
5605 {"relocated-dump", required_argument
, 0, 'R'},
5606 {"relocs", no_argument
, 0, 'r'},
5607 {"section-headers", no_argument
, 0, 'S'},
5608 {"sections", no_argument
, 0, 'S'},
5609 {"symbols", no_argument
, 0, 's'},
5610 {"syms", no_argument
, 0, 's'},
5611 {"silent-truncation",no_argument
, 0, 'T'},
5612 {"section-details", no_argument
, 0, 't'},
5613 {"unicode", required_argument
, NULL
, 'U'},
5614 {"unwind", no_argument
, 0, 'u'},
5615 {"version-info", no_argument
, 0, 'V'},
5616 {"version", no_argument
, 0, 'v'},
5617 {"wide", no_argument
, 0, 'W'},
5618 {"extra-sym-info", no_argument
, 0, 'X'},
5619 {"hex-dump", required_argument
, 0, 'x'},
5620 {"decompress", no_argument
, 0, 'z'},
5622 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
5623 {"no-extra-sym-info",no_argument
, 0, OPTION_NO_EXTRA_SYM_INFO
},
5624 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
5625 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5626 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5627 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
5628 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
5629 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
5630 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
5631 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
5632 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
5633 #ifdef ENABLE_LIBCTF
5634 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
5635 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
5636 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
5637 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
5639 {"sframe", optional_argument
, 0, OPTION_SFRAME_DUMP
},
5640 {"sym-base", optional_argument
, 0, OPTION_SYM_BASE
},
5642 {0, no_argument
, 0, 0}
5646 usage (FILE * stream
)
5648 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
5649 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
5650 fprintf (stream
, _(" Options are:\n"));
5651 fprintf (stream
, _("\
5652 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
5653 fprintf (stream
, _("\
5654 -h --file-header Display the ELF file header\n"));
5655 fprintf (stream
, _("\
5656 -l --program-headers Display the program headers\n"));
5657 fprintf (stream
, _("\
5658 --segments An alias for --program-headers\n"));
5659 fprintf (stream
, _("\
5660 -S --section-headers Display the sections' header\n"));
5661 fprintf (stream
, _("\
5662 --sections An alias for --section-headers\n"));
5663 fprintf (stream
, _("\
5664 -g --section-groups Display the section groups\n"));
5665 fprintf (stream
, _("\
5666 -t --section-details Display the section details\n"));
5667 fprintf (stream
, _("\
5668 -e --headers Equivalent to: -h -l -S\n"));
5669 fprintf (stream
, _("\
5670 -s --syms Display the symbol table\n"));
5671 fprintf (stream
, _("\
5672 --symbols An alias for --syms\n"));
5673 fprintf (stream
, _("\
5674 --dyn-syms Display the dynamic symbol table\n"));
5675 fprintf (stream
, _("\
5676 --lto-syms Display LTO symbol tables\n"));
5677 fprintf (stream
, _("\
5678 --sym-base=[0|8|10|16] \n\
5679 Force base for symbol sizes. The options are \n\
5680 mixed (the default), octal, decimal, hexadecimal.\n"));
5681 fprintf (stream
, _("\
5682 -C --demangle[=STYLE] Decode mangled/processed symbol names\n"));
5683 display_demangler_styles (stream
, _("\
5685 fprintf (stream
, _("\
5686 --no-demangle Do not demangle low-level symbol names. (default)\n"));
5687 fprintf (stream
, _("\
5688 --recurse-limit Enable a demangling recursion limit. (default)\n"));
5689 fprintf (stream
, _("\
5690 --no-recurse-limit Disable a demangling recursion limit\n"));
5691 fprintf (stream
, _("\
5692 -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\
5693 Display unicode characters as determined by the current locale\n\
5694 (default), escape sequences, \"<hex sequences>\", highlighted\n\
5695 escape sequences, or treat them as invalid and display as\n\
5696 \"{hex sequences}\"\n"));
5697 fprintf (stream
, _("\
5698 -X --extra-sym-info Display extra information when showing symbols\n"));
5699 fprintf (stream
, _("\
5700 --no-extra-sym-info Do not display extra information when showing symbols (default)\n"));
5701 fprintf (stream
, _("\
5702 -n --notes Display the contents of note sections (if present)\n"));
5703 fprintf (stream
, _("\
5704 -r --relocs Display the relocations (if present)\n"));
5705 fprintf (stream
, _("\
5706 -u --unwind Display the unwind info (if present)\n"));
5707 fprintf (stream
, _("\
5708 -d --dynamic Display the dynamic section (if present)\n"));
5709 fprintf (stream
, _("\
5710 -V --version-info Display the version sections (if present)\n"));
5711 fprintf (stream
, _("\
5712 -A --arch-specific Display architecture specific information (if any)\n"));
5713 fprintf (stream
, _("\
5714 -c --archive-index Display the symbol/file index in an archive\n"));
5715 fprintf (stream
, _("\
5716 -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
5717 fprintf (stream
, _("\
5718 -L --lint|--enable-checks\n\
5719 Display warning messages for possible problems\n"));
5720 fprintf (stream
, _("\
5721 -x --hex-dump=<number|name>\n\
5722 Dump the contents of section <number|name> as bytes\n"));
5723 fprintf (stream
, _("\
5724 -p --string-dump=<number|name>\n\
5725 Dump the contents of section <number|name> as strings\n"));
5726 fprintf (stream
, _("\
5727 -R --relocated-dump=<number|name>\n\
5728 Dump the relocated contents of section <number|name>\n"));
5729 fprintf (stream
, _("\
5730 -z --decompress Decompress section before dumping it\n"));
5731 fprintf (stream
, _("\
5732 -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
5733 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
5734 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
5735 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
5737 Display the contents of DWARF debug sections\n"));
5738 fprintf (stream
, _("\
5739 -wk --debug-dump=links Display the contents of sections that link to separate\n\
5740 debuginfo files\n"));
5741 fprintf (stream
, _("\
5742 -P --process-links Display the contents of non-debug sections in separate\n\
5743 debuginfo files. (Implies -wK)\n"));
5744 #if DEFAULT_FOR_FOLLOW_LINKS
5745 fprintf (stream
, _("\
5746 -wK --debug-dump=follow-links\n\
5747 Follow links to separate debug info files (default)\n"));
5748 fprintf (stream
, _("\
5749 -wN --debug-dump=no-follow-links\n\
5750 Do not follow links to separate debug info files\n"));
5752 fprintf (stream
, _("\
5753 -wK --debug-dump=follow-links\n\
5754 Follow links to separate debug info files\n"));
5755 fprintf (stream
, _("\
5756 -wN --debug-dump=no-follow-links\n\
5757 Do not follow links to separate debug info files\n\
5760 #if HAVE_LIBDEBUGINFOD
5761 fprintf (stream
, _("\
5762 -wD --debug-dump=use-debuginfod\n\
5763 When following links, also query debuginfod servers (default)\n"));
5764 fprintf (stream
, _("\
5765 -wE --debug-dump=do-not-use-debuginfod\n\
5766 When following links, do not query debuginfod servers\n"));
5768 fprintf (stream
, _("\
5769 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
5770 fprintf (stream
, _("\
5771 --dwarf-start=N Display DIEs starting at offset N\n"));
5772 #ifdef ENABLE_LIBCTF
5773 fprintf (stream
, _("\
5774 --ctf=<number|name> Display CTF info from section <number|name>\n"));
5775 fprintf (stream
, _("\
5776 --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
5777 fprintf (stream
, _("\
5778 --ctf-symbols=<number|name>\n\
5779 Use section <number|name> as the CTF external symtab\n"));
5780 fprintf (stream
, _("\
5781 --ctf-strings=<number|name>\n\
5782 Use section <number|name> as the CTF external strtab\n"));
5784 fprintf (stream
, _("\
5785 --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n"));
5787 #ifdef SUPPORT_DISASSEMBLY
5788 fprintf (stream
, _("\
5789 -i --instruction-dump=<number|name>\n\
5790 Disassemble the contents of section <number|name>\n"));
5792 fprintf (stream
, _("\
5793 -I --histogram Display histogram of bucket list lengths\n"));
5794 fprintf (stream
, _("\
5795 -W --wide Allow output width to exceed 80 characters\n"));
5796 fprintf (stream
, _("\
5797 -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
5798 fprintf (stream
, _("\
5799 @<file> Read options from <file>\n"));
5800 fprintf (stream
, _("\
5801 -H --help Display this information\n"));
5802 fprintf (stream
, _("\
5803 -v --version Display the version number of readelf\n"));
5805 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
5806 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
5808 exit (stream
== stdout
? 0 : 1);
5811 /* Record the fact that the user wants the contents of section number
5812 SECTION to be displayed using the method(s) encoded as flags bits
5813 in TYPE. Note, TYPE can be zero if we are creating the array for
5817 request_dump_bynumber (struct dump_data
*dumpdata
,
5818 unsigned int section
, dump_type type
)
5820 if (section
>= dumpdata
->num_dump_sects
)
5822 dump_type
* new_dump_sects
;
5824 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
5825 sizeof (* new_dump_sects
));
5827 if (new_dump_sects
== NULL
)
5828 error (_("Out of memory allocating dump request table.\n"));
5831 if (dumpdata
->dump_sects
)
5833 /* Copy current flag settings. */
5834 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
5835 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
5837 free (dumpdata
->dump_sects
);
5840 dumpdata
->dump_sects
= new_dump_sects
;
5841 dumpdata
->num_dump_sects
= section
+ 1;
5845 if (dumpdata
->dump_sects
)
5846 dumpdata
->dump_sects
[section
] |= type
;
5849 /* Request a dump by section name. */
5852 request_dump_byname (const char * section
, dump_type type
)
5854 struct dump_list_entry
* new_request
;
5856 new_request
= (struct dump_list_entry
*)
5857 malloc (sizeof (struct dump_list_entry
));
5859 error (_("Out of memory allocating dump request table.\n"));
5861 new_request
->name
= strdup (section
);
5862 if (!new_request
->name
)
5863 error (_("Out of memory allocating dump request table.\n"));
5865 new_request
->type
= type
;
5867 new_request
->next
= dump_sects_byname
;
5868 dump_sects_byname
= new_request
;
5872 request_dump (struct dump_data
*dumpdata
, dump_type type
)
5878 section
= strtoul (optarg
, & cp
, 0);
5880 if (! *cp
&& section
>= 0)
5881 request_dump_bynumber (dumpdata
, section
, type
);
5883 request_dump_byname (optarg
, type
);
5887 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
5894 while ((c
= getopt_long
5895 (argc
, argv
, "ACDHILNPR:STU:VWXacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
5913 do_section_groups
= true;
5916 do_histogram
= true;
5922 do_section_groups
= true;
5927 do_section_details
= true;
5938 do_using_dynamic
= true;
5962 do_histogram
= true;
5968 do_archive_index
= true;
5974 process_links
= true;
5975 do_follow_links
= true;
5976 dump_any_debugging
= true;
5979 request_dump (dumpdata
, HEX_DUMP
);
5982 request_dump (dumpdata
, STRING_DUMP
);
5985 request_dump (dumpdata
, RELOC_DUMP
);
5988 decompress_dumps
= true;
5993 do_debugging
= true;
5995 dump_any_debugging
= true;
5996 dwarf_select_sections_all ();
6000 do_debugging
= false;
6001 if (dwarf_select_sections_by_letters (optarg
))
6004 dump_any_debugging
= true;
6008 case OPTION_DEBUG_DUMP
:
6012 do_debugging
= true;
6013 dump_any_debugging
= true;
6014 dwarf_select_sections_all ();
6018 do_debugging
= false;
6019 if (dwarf_select_sections_by_names (optarg
))
6022 dump_any_debugging
= true;
6026 case OPTION_DWARF_DEPTH
:
6030 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
6033 case OPTION_DWARF_START
:
6037 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
6040 case OPTION_DWARF_CHECK
:
6043 case OPTION_CTF_DUMP
:
6045 request_dump (dumpdata
, CTF_DUMP
);
6047 case OPTION_CTF_SYMBOLS
:
6048 free (dump_ctf_symtab_name
);
6049 dump_ctf_symtab_name
= strdup (optarg
);
6051 case OPTION_CTF_STRINGS
:
6052 free (dump_ctf_strtab_name
);
6053 dump_ctf_strtab_name
= strdup (optarg
);
6055 case OPTION_CTF_PARENT
:
6056 free (dump_ctf_parent_name
);
6057 dump_ctf_parent_name
= strdup (optarg
);
6059 case OPTION_SFRAME_DUMP
:
6061 /* Providing section name is optional. request_dump (), however,
6062 thrives on non NULL optarg. Handle it explicitly here. */
6064 request_dump (dumpdata
, SFRAME_DUMP
);
6068 const char *sframe_sec_name
= strdup (".sframe");
6069 request_dump_byname (sframe_sec_name
, SFRAME_DUMP
);
6072 case OPTION_DYN_SYMS
:
6075 case OPTION_LTO_SYMS
:
6079 extra_sym_info
= true;
6081 case OPTION_NO_EXTRA_SYM_INFO
:
6082 extra_sym_info
= false;
6085 #ifdef SUPPORT_DISASSEMBLY
6087 request_dump (dumpdata
, DISASS_DUMP
);
6091 print_version (program_name
);
6100 do_not_show_symbol_truncation
= true;
6106 enum demangling_styles style
;
6108 style
= cplus_demangle_name_to_style (optarg
);
6109 if (style
== unknown_demangling
)
6110 error (_("unknown demangling style `%s'"), optarg
);
6112 cplus_demangle_set_style (style
);
6115 case OPTION_NO_DEMANGLING
:
6116 do_demangle
= false;
6118 case OPTION_RECURSE_LIMIT
:
6119 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
6121 case OPTION_NO_RECURSE_LIMIT
:
6122 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
6124 case OPTION_WITH_SYMBOL_VERSIONS
:
6125 /* Ignored for backward compatibility. */
6130 error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
6131 else if (streq (optarg
, "default") || streq (optarg
, "d"))
6132 unicode_display
= unicode_default
;
6133 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
6134 unicode_display
= unicode_locale
;
6135 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
6136 unicode_display
= unicode_escape
;
6137 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
6138 unicode_display
= unicode_invalid
;
6139 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
6140 unicode_display
= unicode_hex
;
6141 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
6142 unicode_display
= unicode_highlight
;
6144 error (_("invalid argument to -U/--unicode: %s"), optarg
);
6147 case OPTION_SYM_BASE
:
6151 sym_base
= strtoul (optarg
, NULL
, 0);
6168 /* xgettext:c-format */
6169 error (_("Invalid option '-%c'\n"), c
);
6176 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
6177 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
6178 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
6179 && !do_section_groups
&& !do_archive_index
6180 && !do_dyn_syms
&& !do_lto_syms
)
6185 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
6186 do_segments
= do_header
= do_dump
= do_version
= true;
6187 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
6188 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
6197 get_elf_class (unsigned int elf_class
)
6199 static char buff
[32];
6203 case ELFCLASSNONE
: return _("none");
6204 case ELFCLASS32
: return "ELF32";
6205 case ELFCLASS64
: return "ELF64";
6207 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
6213 get_data_encoding (unsigned int encoding
)
6215 static char buff
[32];
6219 case ELFDATANONE
: return _("none");
6220 case ELFDATA2LSB
: return _("2's complement, little endian");
6221 case ELFDATA2MSB
: return _("2's complement, big endian");
6223 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
6229 check_magic_number (Filedata
* filedata
, Elf_Internal_Ehdr
* header
)
6231 if (header
->e_ident
[EI_MAG0
] == ELFMAG0
6232 && header
->e_ident
[EI_MAG1
] == ELFMAG1
6233 && header
->e_ident
[EI_MAG2
] == ELFMAG2
6234 && header
->e_ident
[EI_MAG3
] == ELFMAG3
)
6237 /* Some compilers produce object files that are not in the ELF file format.
6238 As an aid to users of readelf, try to identify these cases and suggest
6241 FIXME: It is not clear if all four bytes are used as constant magic
6242 valus by all compilers. It may be necessary to recode this function if
6243 different tools use different length sequences. */
6247 unsigned char magic
[4];
6248 const char * obj_message
;
6249 const char * ar_message
;
6253 { { 'B', 'C', 0xc0, 0xde },
6254 N_("This is a LLVM bitcode file - try using llvm-bcanalyzer\n"),
6255 N_("This is a LLVM bitcode file - try extracting and then using llvm-bcanalyzer\n")
6257 { { 'g', 'o', ' ', 'o' },
6258 N_("This is a GO binary file - try using 'go tool objdump' or 'go tool nm'\n"),
6264 for (i
= ARRAY_SIZE (known_magic
); i
--;)
6266 if (header
->e_ident
[EI_MAG0
] == known_magic
[i
].magic
[0]
6267 && header
->e_ident
[EI_MAG1
] == known_magic
[i
].magic
[1]
6268 && header
->e_ident
[EI_MAG2
] == known_magic
[i
].magic
[2]
6269 && header
->e_ident
[EI_MAG3
] == known_magic
[i
].magic
[3])
6271 /* Some compiler's analyzer tools do not handle archives,
6272 so we provide two different kinds of error message. */
6273 if (filedata
->archive_file_size
> 0
6274 && known_magic
[i
].ar_message
!= NULL
)
6275 error ("%s", known_magic
[i
].ar_message
);
6277 error ("%s", known_magic
[i
].obj_message
);
6282 error (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
6286 /* Decode the data held in 'filedata->file_header'. */
6289 process_file_header (Filedata
* filedata
)
6291 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
6293 if (! check_magic_number (filedata
, header
))
6296 if (! filedata
->is_separate
)
6297 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
6303 if (filedata
->is_separate
)
6304 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
6306 printf (_("ELF Header:\n"));
6307 printf (_(" Magic: "));
6308 for (i
= 0; i
< EI_NIDENT
; i
++)
6309 printf ("%2.2x ", header
->e_ident
[i
]);
6311 printf (_(" Class: %s\n"),
6312 get_elf_class (header
->e_ident
[EI_CLASS
]));
6313 printf (_(" Data: %s\n"),
6314 get_data_encoding (header
->e_ident
[EI_DATA
]));
6315 printf (_(" Version: %d%s\n"),
6316 header
->e_ident
[EI_VERSION
],
6317 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
6319 : (header
->e_ident
[EI_VERSION
] != EV_NONE
6322 printf (_(" OS/ABI: %s\n"),
6323 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
6324 printf (_(" ABI Version: %d\n"),
6325 header
->e_ident
[EI_ABIVERSION
]);
6326 printf (_(" Type: %s\n"),
6327 get_file_type (filedata
));
6328 printf (_(" Machine: %s\n"),
6329 get_machine_name (header
->e_machine
));
6330 printf (_(" Version: 0x%lx\n"),
6333 printf (_(" Entry point address: "));
6334 print_vma (header
->e_entry
, PREFIX_HEX
);
6335 printf (_("\n Start of program headers: "));
6336 print_vma (header
->e_phoff
, DEC
);
6337 printf (_(" (bytes into file)\n Start of section headers: "));
6338 print_vma (header
->e_shoff
, DEC
);
6339 printf (_(" (bytes into file)\n"));
6341 printf (_(" Flags: 0x%lx%s\n"),
6343 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
6344 printf (_(" Size of this header: %u (bytes)\n"),
6346 printf (_(" Size of program headers: %u (bytes)\n"),
6347 header
->e_phentsize
);
6348 printf (_(" Number of program headers: %u"),
6350 if (filedata
->section_headers
!= NULL
6351 && header
->e_phnum
== PN_XNUM
6352 && filedata
->section_headers
[0].sh_info
!= 0)
6353 printf (" (%u)", filedata
->section_headers
[0].sh_info
);
6354 putc ('\n', stdout
);
6355 printf (_(" Size of section headers: %u (bytes)\n"),
6356 header
->e_shentsize
);
6357 printf (_(" Number of section headers: %u"),
6359 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
6361 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
6362 printf (" (%u)", header
->e_shnum
);
6364 putc ('\n', stdout
);
6365 printf (_(" Section header string table index: %u"),
6366 header
->e_shstrndx
);
6367 if (filedata
->section_headers
!= NULL
6368 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
6370 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
6371 printf (" (%u)", header
->e_shstrndx
);
6373 if (header
->e_shstrndx
!= SHN_UNDEF
6374 && header
->e_shstrndx
>= header
->e_shnum
)
6376 header
->e_shstrndx
= SHN_UNDEF
;
6377 printf (_(" <corrupt: out of range>"));
6379 putc ('\n', stdout
);
6382 if (filedata
->section_headers
!= NULL
)
6384 if (header
->e_phnum
== PN_XNUM
6385 && filedata
->section_headers
[0].sh_info
!= 0)
6387 /* Throw away any cached read of PN_XNUM headers. */
6388 free (filedata
->program_headers
);
6389 filedata
->program_headers
= NULL
;
6390 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
6392 if (header
->e_shnum
== SHN_UNDEF
)
6393 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
6394 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
6395 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
6396 if (header
->e_shstrndx
>= header
->e_shnum
)
6397 header
->e_shstrndx
= SHN_UNDEF
;
6403 /* Read in the program headers from FILEDATA and store them in PHEADERS.
6404 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
6407 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
6409 Elf32_External_Phdr
* phdrs
;
6410 Elf32_External_Phdr
* external
;
6411 Elf_Internal_Phdr
* internal
;
6413 unsigned int size
= filedata
->file_header
.e_phentsize
;
6414 unsigned int num
= filedata
->file_header
.e_phnum
;
6416 /* PR binutils/17531: Cope with unexpected section header sizes. */
6417 if (size
== 0 || num
== 0)
6419 if (size
< sizeof * phdrs
)
6421 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
6424 if (size
> sizeof * phdrs
)
6425 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
6427 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
6428 size
, num
, _("program headers"));
6432 for (i
= 0, internal
= pheaders
, external
= phdrs
;
6433 i
< filedata
->file_header
.e_phnum
;
6434 i
++, internal
++, external
++)
6436 internal
->p_type
= BYTE_GET (external
->p_type
);
6437 internal
->p_offset
= BYTE_GET (external
->p_offset
);
6438 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
6439 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
6440 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
6441 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
6442 internal
->p_flags
= BYTE_GET (external
->p_flags
);
6443 internal
->p_align
= BYTE_GET (external
->p_align
);
6450 /* Read in the program headers from FILEDATA and store them in PHEADERS.
6451 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
6454 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
6456 Elf64_External_Phdr
* phdrs
;
6457 Elf64_External_Phdr
* external
;
6458 Elf_Internal_Phdr
* internal
;
6460 unsigned int size
= filedata
->file_header
.e_phentsize
;
6461 unsigned int num
= filedata
->file_header
.e_phnum
;
6463 /* PR binutils/17531: Cope with unexpected section header sizes. */
6464 if (size
== 0 || num
== 0)
6466 if (size
< sizeof * phdrs
)
6468 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
6471 if (size
> sizeof * phdrs
)
6472 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
6474 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
6475 size
, num
, _("program headers"));
6479 for (i
= 0, internal
= pheaders
, external
= phdrs
;
6480 i
< filedata
->file_header
.e_phnum
;
6481 i
++, internal
++, external
++)
6483 internal
->p_type
= BYTE_GET (external
->p_type
);
6484 internal
->p_flags
= BYTE_GET (external
->p_flags
);
6485 internal
->p_offset
= BYTE_GET (external
->p_offset
);
6486 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
6487 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
6488 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
6489 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
6490 internal
->p_align
= BYTE_GET (external
->p_align
);
6497 /* Returns TRUE if the program headers were read into `program_headers'. */
6500 get_program_headers (Filedata
* filedata
)
6502 Elf_Internal_Phdr
* phdrs
;
6504 /* Check cache of prior read. */
6505 if (filedata
->program_headers
!= NULL
)
6508 /* Be kind to memory checkers by looking for
6509 e_phnum values which we know must be invalid. */
6510 if (filedata
->file_header
.e_phnum
6511 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
6512 >= filedata
->file_size
)
6514 error (_("Too many program headers - %#x - the file is not that big\n"),
6515 filedata
->file_header
.e_phnum
);
6519 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
6520 sizeof (Elf_Internal_Phdr
));
6523 error (_("Out of memory reading %u program headers\n"),
6524 filedata
->file_header
.e_phnum
);
6529 ? get_32bit_program_headers (filedata
, phdrs
)
6530 : get_64bit_program_headers (filedata
, phdrs
))
6532 filedata
->program_headers
= phdrs
;
6540 /* Print program header info and locate dynamic section. */
6543 process_program_headers (Filedata
* filedata
)
6545 Elf_Internal_Phdr
* segment
;
6547 Elf_Internal_Phdr
* previous_load
= NULL
;
6549 if (filedata
->file_header
.e_phnum
== 0)
6551 /* PR binutils/12467. */
6552 if (filedata
->file_header
.e_phoff
!= 0)
6553 warn (_("possibly corrupt ELF header - it has a non-zero program"
6554 " header offset, but no program headers\n"));
6555 else if (do_segments
)
6557 if (filedata
->is_separate
)
6558 printf (_("\nThere are no program headers in linked file '%s'.\n"),
6559 filedata
->file_name
);
6561 printf (_("\nThere are no program headers in this file.\n"));
6566 if (do_segments
&& !do_header
)
6568 if (filedata
->is_separate
)
6569 printf ("\nIn linked file '%s' the ELF file type is %s\n",
6570 filedata
->file_name
, get_file_type (filedata
));
6572 printf (_("\nElf file type is %s\n"), get_file_type (filedata
));
6573 printf (_("Entry point 0x%" PRIx64
"\n"),
6574 filedata
->file_header
.e_entry
);
6575 printf (ngettext ("There is %d program header,"
6576 " starting at offset %" PRIu64
"\n",
6577 "There are %d program headers,"
6578 " starting at offset %" PRIu64
"\n",
6579 filedata
->file_header
.e_phnum
),
6580 filedata
->file_header
.e_phnum
,
6581 filedata
->file_header
.e_phoff
);
6584 if (! get_program_headers (filedata
))
6589 if (filedata
->file_header
.e_phnum
> 1)
6590 printf (_("\nProgram Headers:\n"));
6592 printf (_("\nProgram Headers:\n"));
6596 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6599 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6603 (_(" Type Offset VirtAddr PhysAddr\n"));
6605 (_(" FileSiz MemSiz Flags Align\n"));
6609 uint64_t dynamic_addr
= 0;
6610 uint64_t dynamic_size
= 0;
6611 for (i
= 0, segment
= filedata
->program_headers
;
6612 i
< filedata
->file_header
.e_phnum
;
6617 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
6621 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6622 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
6623 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
6624 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
6625 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
6627 (segment
->p_flags
& PF_R
? 'R' : ' '),
6628 (segment
->p_flags
& PF_W
? 'W' : ' '),
6629 (segment
->p_flags
& PF_X
? 'E' : ' '));
6630 printf ("%#lx", (unsigned long) segment
->p_align
);
6634 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
6635 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6638 print_vma (segment
->p_offset
, FULL_HEX
);
6642 print_vma (segment
->p_vaddr
, FULL_HEX
);
6644 print_vma (segment
->p_paddr
, FULL_HEX
);
6647 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
6648 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
6651 print_vma (segment
->p_filesz
, FULL_HEX
);
6655 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
6656 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
6659 print_vma (segment
->p_memsz
, FULL_HEX
);
6663 (segment
->p_flags
& PF_R
? 'R' : ' '),
6664 (segment
->p_flags
& PF_W
? 'W' : ' '),
6665 (segment
->p_flags
& PF_X
? 'E' : ' '));
6667 if ((unsigned long) segment
->p_align
== segment
->p_align
)
6668 printf ("%#lx", (unsigned long) segment
->p_align
);
6671 print_vma (segment
->p_align
, PREFIX_HEX
);
6676 print_vma (segment
->p_offset
, FULL_HEX
);
6678 print_vma (segment
->p_vaddr
, FULL_HEX
);
6680 print_vma (segment
->p_paddr
, FULL_HEX
);
6682 print_vma (segment
->p_filesz
, FULL_HEX
);
6684 print_vma (segment
->p_memsz
, FULL_HEX
);
6686 (segment
->p_flags
& PF_R
? 'R' : ' '),
6687 (segment
->p_flags
& PF_W
? 'W' : ' '),
6688 (segment
->p_flags
& PF_X
? 'E' : ' '));
6689 print_vma (segment
->p_align
, PREFIX_HEX
);
6692 putc ('\n', stdout
);
6695 switch (segment
->p_type
)
6698 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
6699 required by the ELF standard, several programs, including the Linux
6700 kernel, make use of non-ordered segments. */
6702 && previous_load
->p_vaddr
> segment
->p_vaddr
)
6703 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
6705 if (segment
->p_memsz
< segment
->p_filesz
)
6706 error (_("the segment's file size is larger than its memory size\n"));
6707 previous_load
= segment
;
6711 /* PR 20815 - Verify that the program header is loaded into memory. */
6712 if (i
> 0 && previous_load
!= NULL
)
6713 error (_("the PHDR segment must occur before any LOAD segment\n"));
6714 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
6718 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
6720 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
6721 if (load
->p_type
== PT_LOAD
6722 && load
->p_offset
<= segment
->p_offset
6723 && (load
->p_offset
+ load
->p_filesz
6724 >= segment
->p_offset
+ segment
->p_filesz
)
6725 && load
->p_vaddr
<= segment
->p_vaddr
6726 && (load
->p_vaddr
+ load
->p_filesz
6727 >= segment
->p_vaddr
+ segment
->p_filesz
))
6730 if (j
== filedata
->file_header
.e_phnum
)
6731 error (_("the PHDR segment is not covered by a LOAD segment\n"));
6737 error (_("more than one dynamic segment\n"));
6739 /* By default, assume that the .dynamic section is the first
6740 section in the DYNAMIC segment. */
6741 dynamic_addr
= segment
->p_offset
;
6742 dynamic_size
= segment
->p_filesz
;
6744 /* Try to locate the .dynamic section. If there is
6745 a section header table, we can easily locate it. */
6746 if (filedata
->section_headers
!= NULL
)
6748 Elf_Internal_Shdr
* sec
;
6750 sec
= find_section (filedata
, ".dynamic");
6751 if (sec
== NULL
|| sec
->sh_size
== 0)
6753 /* A corresponding .dynamic section is expected, but on
6754 IA-64/OpenVMS it is OK for it to be missing. */
6755 if (!is_ia64_vms (filedata
))
6756 error (_("no .dynamic section in the dynamic segment\n"));
6760 if (sec
->sh_type
== SHT_NOBITS
)
6767 dynamic_addr
= sec
->sh_offset
;
6768 dynamic_size
= sec
->sh_size
;
6770 /* The PT_DYNAMIC segment, which is used by the run-time
6771 loader, should exactly match the .dynamic section. */
6773 && (dynamic_addr
!= segment
->p_offset
6774 || dynamic_size
!= segment
->p_filesz
))
6776 the .dynamic section is not the same as the dynamic segment\n"));
6779 /* PR binutils/17512: Avoid corrupt dynamic section info in the
6780 segment. Check this after matching against the section headers
6781 so we don't warn on debuginfo file (which have NOBITS .dynamic
6783 if (dynamic_addr
> filedata
->file_size
6784 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
6786 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
6793 if (segment
->p_offset
>= filedata
->file_size
6794 || segment
->p_filesz
> filedata
->file_size
- segment
->p_offset
6795 || segment
->p_filesz
- 1 >= (size_t) -2
6796 || fseek64 (filedata
->handle
,
6797 filedata
->archive_file_offset
+ segment
->p_offset
,
6799 error (_("Unable to find program interpreter name\n"));
6802 size_t len
= segment
->p_filesz
;
6803 free (filedata
->program_interpreter
);
6804 filedata
->program_interpreter
= xmalloc (len
+ 1);
6805 len
= fread (filedata
->program_interpreter
, 1, len
,
6807 filedata
->program_interpreter
[len
] = 0;
6810 printf (_(" [Requesting program interpreter: %s]\n"),
6811 filedata
->program_interpreter
);
6818 && filedata
->section_headers
!= NULL
6819 && filedata
->string_table
!= NULL
)
6821 printf (_("\n Section to Segment mapping:\n"));
6822 printf (_(" Segment Sections...\n"));
6824 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
6827 Elf_Internal_Shdr
* section
;
6829 segment
= filedata
->program_headers
+ i
;
6830 section
= filedata
->section_headers
+ 1;
6832 printf (" %2.2d ", i
);
6834 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
6836 if (!ELF_TBSS_SPECIAL (section
, segment
)
6837 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
6838 printf ("%s ", printable_section_name (filedata
, section
));
6845 filedata
->dynamic_addr
= dynamic_addr
;
6846 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
6850 filedata
->dynamic_addr
= 0;
6851 filedata
->dynamic_size
= 1;
6855 /* Find the file offset corresponding to VMA by using the program headers. */
6858 offset_from_vma (Filedata
* filedata
, uint64_t vma
, uint64_t size
)
6860 Elf_Internal_Phdr
* seg
;
6862 if (! get_program_headers (filedata
))
6864 warn (_("Cannot interpret virtual addresses without program headers.\n"));
6868 for (seg
= filedata
->program_headers
;
6869 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
6872 if (seg
->p_type
!= PT_LOAD
)
6875 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
6876 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
6877 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
6880 warn (_("Virtual address %#" PRIx64
6881 " not located in any PT_LOAD segment.\n"), vma
);
6886 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
6887 If PROBE is true, this is just a probe and we do not generate any error
6888 messages if the load fails. */
6891 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
6893 Elf32_External_Shdr
* shdrs
;
6894 Elf_Internal_Shdr
* internal
;
6896 unsigned int size
= filedata
->file_header
.e_shentsize
;
6897 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6899 /* PR binutils/17531: Cope with unexpected section header sizes. */
6900 if (size
== 0 || num
== 0)
6903 /* The section header cannot be at the start of the file - that is
6904 where the ELF file header is located. A file with absolutely no
6905 sections in it will use a shoff of 0. */
6906 if (filedata
->file_header
.e_shoff
== 0)
6909 if (size
< sizeof * shdrs
)
6912 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6915 if (!probe
&& size
> sizeof * shdrs
)
6916 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6918 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
6920 probe
? NULL
: _("section headers"));
6924 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6925 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6926 if (filedata
->section_headers
== NULL
)
6929 error (_("Out of memory reading %u section headers\n"), num
);
6934 for (i
= 0, internal
= filedata
->section_headers
;
6938 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6939 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6940 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6941 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6942 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6943 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6944 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6945 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6946 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6947 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6948 if (!probe
&& internal
->sh_link
> num
)
6949 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6950 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6951 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6958 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
6961 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
6963 Elf64_External_Shdr
* shdrs
;
6964 Elf_Internal_Shdr
* internal
;
6966 unsigned int size
= filedata
->file_header
.e_shentsize
;
6967 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6969 /* PR binutils/17531: Cope with unexpected section header sizes. */
6970 if (size
== 0 || num
== 0)
6973 /* The section header cannot be at the start of the file - that is
6974 where the ELF file header is located. A file with absolutely no
6975 sections in it will use a shoff of 0. */
6976 if (filedata
->file_header
.e_shoff
== 0)
6979 if (size
< sizeof * shdrs
)
6982 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6986 if (! probe
&& size
> sizeof * shdrs
)
6987 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6989 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
6990 filedata
->file_header
.e_shoff
,
6992 probe
? NULL
: _("section headers"));
6996 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6997 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6998 if (filedata
->section_headers
== NULL
)
7001 error (_("Out of memory reading %u section headers\n"), num
);
7006 for (i
= 0, internal
= filedata
->section_headers
;
7010 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
7011 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
7012 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
7013 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
7014 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
7015 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
7016 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
7017 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
7018 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
7019 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
7020 if (!probe
&& internal
->sh_link
> num
)
7021 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
7022 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
7023 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
7031 get_section_headers (Filedata
*filedata
, bool probe
)
7033 if (filedata
->section_headers
!= NULL
)
7037 return get_32bit_section_headers (filedata
, probe
);
7039 return get_64bit_section_headers (filedata
, probe
);
7042 static Elf_Internal_Sym
*
7043 get_32bit_elf_symbols (Filedata
*filedata
,
7044 Elf_Internal_Shdr
*section
,
7045 uint64_t *num_syms_return
)
7047 uint64_t number
= 0;
7048 Elf32_External_Sym
* esyms
= NULL
;
7049 Elf_External_Sym_Shndx
* shndx
= NULL
;
7050 Elf_Internal_Sym
* isyms
= NULL
;
7051 Elf_Internal_Sym
* psym
;
7053 elf_section_list
* entry
;
7055 if (section
->sh_size
== 0)
7057 if (num_syms_return
!= NULL
)
7058 * num_syms_return
= 0;
7062 /* Run some sanity checks first. */
7063 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
7065 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
7066 printable_section_name (filedata
, section
),
7067 section
->sh_entsize
);
7071 if (section
->sh_size
> filedata
->file_size
)
7073 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
7074 printable_section_name (filedata
, section
),
7079 number
= section
->sh_size
/ section
->sh_entsize
;
7081 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
7083 error (_("Size (%#" PRIx64
") of section %s "
7084 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
7086 printable_section_name (filedata
, section
),
7087 section
->sh_entsize
);
7091 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
7092 section
->sh_size
, _("symbols"));
7097 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
7099 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
7104 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
7108 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
7109 entry
->hdr
->sh_offset
,
7110 1, entry
->hdr
->sh_size
,
7111 _("symbol table section indices"));
7115 /* PR17531: file: heap-buffer-overflow */
7116 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
7118 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
7119 printable_section_name (filedata
, entry
->hdr
),
7120 entry
->hdr
->sh_size
,
7126 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
7130 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
7134 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
7136 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
7137 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
7138 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
7139 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
7140 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
7142 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
7143 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
7144 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
7145 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
7146 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
7153 if (num_syms_return
!= NULL
)
7154 * num_syms_return
= isyms
== NULL
? 0 : number
;
7159 static Elf_Internal_Sym
*
7160 get_64bit_elf_symbols (Filedata
*filedata
,
7161 Elf_Internal_Shdr
*section
,
7162 uint64_t *num_syms_return
)
7164 uint64_t number
= 0;
7165 Elf64_External_Sym
* esyms
= NULL
;
7166 Elf_External_Sym_Shndx
* shndx
= NULL
;
7167 Elf_Internal_Sym
* isyms
= NULL
;
7168 Elf_Internal_Sym
* psym
;
7170 elf_section_list
* entry
;
7172 if (section
->sh_size
== 0)
7174 if (num_syms_return
!= NULL
)
7175 * num_syms_return
= 0;
7179 /* Run some sanity checks first. */
7180 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
7182 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
7183 printable_section_name (filedata
, section
),
7184 section
->sh_entsize
);
7188 if (section
->sh_size
> filedata
->file_size
)
7190 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
7191 printable_section_name (filedata
, section
),
7196 number
= section
->sh_size
/ section
->sh_entsize
;
7198 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
7200 error (_("Size (%#" PRIx64
") of section %s "
7201 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
7203 printable_section_name (filedata
, section
),
7204 section
->sh_entsize
);
7208 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
7209 section
->sh_size
, _("symbols"));
7214 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
7216 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
7221 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
7225 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
7226 entry
->hdr
->sh_offset
,
7227 1, entry
->hdr
->sh_size
,
7228 _("symbol table section indices"));
7232 /* PR17531: file: heap-buffer-overflow */
7233 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
7235 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
7236 printable_section_name (filedata
, entry
->hdr
),
7237 entry
->hdr
->sh_size
,
7243 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
7247 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
7251 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
7253 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
7254 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
7255 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
7256 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
7258 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
7260 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
7261 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
7262 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
7264 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
7265 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
7272 if (num_syms_return
!= NULL
)
7273 * num_syms_return
= isyms
== NULL
? 0 : number
;
7278 static Elf_Internal_Sym
*
7279 get_elf_symbols (Filedata
*filedata
,
7280 Elf_Internal_Shdr
*section
,
7281 uint64_t *num_syms_return
)
7284 return get_32bit_elf_symbols (filedata
, section
, num_syms_return
);
7286 return get_64bit_elf_symbols (filedata
, section
, num_syms_return
);
7290 get_elf_section_flags (Filedata
* filedata
, uint64_t sh_flags
)
7292 static char buff
[1024];
7294 unsigned int field_size
= is_32bit_elf
? 8 : 16;
7296 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
7297 uint64_t os_flags
= 0;
7298 uint64_t proc_flags
= 0;
7299 uint64_t unknown_flags
= 0;
7307 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
7308 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
7309 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
7310 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
7311 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
7312 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
7313 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
7314 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
7315 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
7316 /* 9 */ { STRING_COMMA_LEN ("TLS") },
7317 /* IA-64 specific. */
7318 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
7319 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
7320 /* IA-64 OpenVMS specific. */
7321 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
7322 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
7323 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
7324 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
7325 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
7326 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
7328 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
7329 /* SPARC specific. */
7330 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
7331 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
7333 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
7334 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
7335 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
7337 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
7339 /* 25 */ { STRING_COMMA_LEN ("VLE") },
7341 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
7344 if (do_section_details
)
7345 p
+= sprintf (p
, "[%*.*lx]: ",
7346 field_size
, field_size
, (unsigned long) sh_flags
);
7352 flag
= sh_flags
& - sh_flags
;
7355 if (do_section_details
)
7359 case SHF_WRITE
: sindex
= 0; break;
7360 case SHF_ALLOC
: sindex
= 1; break;
7361 case SHF_EXECINSTR
: sindex
= 2; break;
7362 case SHF_MERGE
: sindex
= 3; break;
7363 case SHF_STRINGS
: sindex
= 4; break;
7364 case SHF_INFO_LINK
: sindex
= 5; break;
7365 case SHF_LINK_ORDER
: sindex
= 6; break;
7366 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
7367 case SHF_GROUP
: sindex
= 8; break;
7368 case SHF_TLS
: sindex
= 9; break;
7369 case SHF_EXCLUDE
: sindex
= 18; break;
7370 case SHF_COMPRESSED
: sindex
= 20; break;
7374 switch (filedata
->file_header
.e_machine
)
7377 if (flag
== SHF_IA_64_SHORT
)
7379 else if (flag
== SHF_IA_64_NORECOV
)
7381 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
7384 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
7385 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
7386 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
7387 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
7388 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
7389 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
7399 case EM_OLD_SPARCV9
:
7400 case EM_SPARC32PLUS
:
7403 if (flag
== SHF_ORDERED
)
7410 case SHF_ENTRYSECT
: sindex
= 21; break;
7411 case SHF_ARM_PURECODE
: sindex
= 22; break;
7412 case SHF_COMDEF
: sindex
= 23; break;
7417 if (flag
== SHF_PPC_VLE
)
7424 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7427 case ELFOSABI_FREEBSD
:
7428 if (flag
== SHF_GNU_RETAIN
)
7432 if (flag
== SHF_GNU_MBIND
)
7433 /* We should not recognize SHF_GNU_MBIND for
7434 ELFOSABI_NONE, but binutils as of 2019-07-23 did
7435 not set the EI_OSABI header byte. */
7446 if (p
!= buff
+ field_size
+ 4)
7448 if (size
< (10 + 2))
7450 warn (_("Internal error: not enough buffer room for section flag info"));
7451 return _("<unknown>");
7458 size
-= flags
[sindex
].len
;
7459 p
= stpcpy (p
, flags
[sindex
].str
);
7461 else if (flag
& SHF_MASKOS
)
7463 else if (flag
& SHF_MASKPROC
)
7466 unknown_flags
|= flag
;
7472 case SHF_WRITE
: *p
= 'W'; break;
7473 case SHF_ALLOC
: *p
= 'A'; break;
7474 case SHF_EXECINSTR
: *p
= 'X'; break;
7475 case SHF_MERGE
: *p
= 'M'; break;
7476 case SHF_STRINGS
: *p
= 'S'; break;
7477 case SHF_INFO_LINK
: *p
= 'I'; break;
7478 case SHF_LINK_ORDER
: *p
= 'L'; break;
7479 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
7480 case SHF_GROUP
: *p
= 'G'; break;
7481 case SHF_TLS
: *p
= 'T'; break;
7482 case SHF_EXCLUDE
: *p
= 'E'; break;
7483 case SHF_COMPRESSED
: *p
= 'C'; break;
7486 if ((filedata
->file_header
.e_machine
== EM_X86_64
7487 || filedata
->file_header
.e_machine
== EM_L1OM
7488 || filedata
->file_header
.e_machine
== EM_K1OM
)
7489 && flag
== SHF_X86_64_LARGE
)
7491 else if (filedata
->file_header
.e_machine
== EM_ARM
7492 && flag
== SHF_ARM_PURECODE
)
7494 else if (filedata
->file_header
.e_machine
== EM_PPC
7495 && flag
== SHF_PPC_VLE
)
7497 else if (flag
& SHF_MASKOS
)
7499 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7502 case ELFOSABI_FREEBSD
:
7503 if (flag
== SHF_GNU_RETAIN
)
7510 if (flag
== SHF_GNU_MBIND
)
7512 /* We should not recognize SHF_GNU_MBIND for
7513 ELFOSABI_NONE, but binutils as of 2019-07-23 did
7514 not set the EI_OSABI header byte. */
7521 sh_flags
&= ~SHF_MASKOS
;
7525 else if (flag
& SHF_MASKPROC
)
7528 sh_flags
&= ~ SHF_MASKPROC
;
7538 if (do_section_details
)
7542 if (p
!= buff
+ field_size
+ 4)
7544 if (size
< 2 + 5 + field_size
+ 1)
7546 warn (_("Internal error: not enough buffer room for section flag info"));
7547 return _("<unknown>");
7553 size
-= 5 + field_size
;
7554 p
+= sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
7555 (unsigned long) os_flags
);
7559 if (p
!= buff
+ field_size
+ 4)
7561 if (size
< 2 + 7 + field_size
+ 1)
7563 warn (_("Internal error: not enough buffer room for section flag info"));
7564 return _("<unknown>");
7570 size
-= 7 + field_size
;
7571 p
+= sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
7572 (unsigned long) proc_flags
);
7576 if (p
!= buff
+ field_size
+ 4)
7578 if (size
< 2 + 10 + field_size
+ 1)
7580 warn (_("Internal error: not enough buffer room for section flag info"));
7581 return _("<unknown>");
7587 size
-= 10 + field_size
;
7588 p
+= sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
7589 (unsigned long) unknown_flags
);
7597 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
7598 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
,
7603 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
7605 if (size
< sizeof (* echdr
))
7607 error (_("Compressed section is too small even for a compression header\n"));
7611 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7612 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7613 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7614 return sizeof (*echdr
);
7618 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
7620 if (size
< sizeof (* echdr
))
7622 error (_("Compressed section is too small even for a compression header\n"));
7626 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7627 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7628 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7629 return sizeof (*echdr
);
7634 process_section_headers (Filedata
* filedata
)
7636 Elf_Internal_Shdr
* section
;
7639 if (filedata
->file_header
.e_shnum
== 0)
7641 /* PR binutils/12467. */
7642 if (filedata
->file_header
.e_shoff
!= 0)
7644 warn (_("possibly corrupt ELF file header - it has a non-zero"
7645 " section header offset, but no section headers\n"));
7648 else if (do_sections
)
7649 printf (_("\nThere are no sections in this file.\n"));
7654 if (do_sections
&& !do_header
)
7656 if (filedata
->is_separate
&& process_links
)
7657 printf (_("In linked file '%s': "), filedata
->file_name
);
7658 if (! filedata
->is_separate
|| process_links
)
7659 printf (ngettext ("There is %d section header, "
7660 "starting at offset %#" PRIx64
":\n",
7661 "There are %d section headers, "
7662 "starting at offset %#" PRIx64
":\n",
7663 filedata
->file_header
.e_shnum
),
7664 filedata
->file_header
.e_shnum
,
7665 filedata
->file_header
.e_shoff
);
7668 if (!get_section_headers (filedata
, false))
7671 /* Read in the string table, so that we have names to display. */
7672 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
7673 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
7675 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
7677 if (section
->sh_size
!= 0)
7679 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7680 1, section
->sh_size
,
7683 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
7687 /* Scan the sections for the dynamic symbol table
7688 and dynamic string table and debug sections. */
7689 eh_addr_size
= is_32bit_elf
? 4 : 8;
7690 switch (filedata
->file_header
.e_machine
)
7693 case EM_MIPS_RS3_LE
:
7694 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
7695 FDE addresses. However, the ABI also has a semi-official ILP32
7696 variant for which the normal FDE address size rules apply.
7698 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
7699 section, where XX is the size of longs in bits. Unfortunately,
7700 earlier compilers provided no way of distinguishing ILP32 objects
7701 from LP64 objects, so if there's any doubt, we should assume that
7702 the official LP64 form is being used. */
7703 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == EF_MIPS_ABI_EABI64
7704 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
7710 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
7712 case E_H8_MACH_H8300
:
7713 case E_H8_MACH_H8300HN
:
7714 case E_H8_MACH_H8300SN
:
7715 case E_H8_MACH_H8300SXN
:
7718 case E_H8_MACH_H8300H
:
7719 case E_H8_MACH_H8300S
:
7720 case E_H8_MACH_H8300SX
:
7728 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
7730 case EF_M32C_CPU_M16C
:
7737 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
7740 uint64_t expected_entsize = is_32bit_elf ? size32 : size64; \
7741 if (section->sh_entsize != expected_entsize) \
7743 error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \
7744 i, section->sh_entsize); \
7745 error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \
7746 expected_entsize); \
7747 section->sh_entsize = expected_entsize; \
7752 #define CHECK_ENTSIZE(section, i, type) \
7753 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
7754 sizeof (Elf64_External_##type))
7756 for (i
= 0, section
= filedata
->section_headers
;
7757 i
< filedata
->file_header
.e_shnum
;
7760 const char *name
= printable_section_name (filedata
, section
);
7762 /* Run some sanity checks on the headers and
7763 possibly fill in some file data as well. */
7764 switch (section
->sh_type
)
7767 if (filedata
->dynamic_symbols
!= NULL
)
7769 error (_("File contains multiple dynamic symbol tables\n"));
7773 CHECK_ENTSIZE (section
, i
, Sym
);
7774 filedata
->dynamic_symbols
7775 = get_elf_symbols (filedata
, section
, &filedata
->num_dynamic_syms
);
7776 filedata
->dynamic_symtab_section
= section
;
7780 if (streq (name
, ".dynstr"))
7782 if (filedata
->dynamic_strings
!= NULL
)
7784 error (_("File contains multiple dynamic string tables\n"));
7788 filedata
->dynamic_strings
7789 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7790 1, section
->sh_size
, _("dynamic strings"));
7791 filedata
->dynamic_strings_length
7792 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
7793 filedata
->dynamic_strtab_section
= section
;
7797 case SHT_SYMTAB_SHNDX
:
7799 elf_section_list
* entry
= xmalloc (sizeof * entry
);
7801 entry
->hdr
= section
;
7802 entry
->next
= filedata
->symtab_shndx_list
;
7803 filedata
->symtab_shndx_list
= entry
;
7808 CHECK_ENTSIZE (section
, i
, Sym
);
7812 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
7816 CHECK_ENTSIZE (section
, i
, Rel
);
7817 if (do_checks
&& section
->sh_size
== 0)
7818 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7822 CHECK_ENTSIZE (section
, i
, Rela
);
7823 if (do_checks
&& section
->sh_size
== 0)
7824 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7828 CHECK_ENTSIZE (section
, i
, Relr
);
7833 /* Having a zero sized section is not illegal according to the
7834 ELF standard, but it might be an indication that something
7835 is wrong. So issue a warning if we are running in lint mode. */
7836 if (do_checks
&& section
->sh_size
== 0)
7837 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
7844 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
7845 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
7846 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
7847 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
7849 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
7850 && (startswith (name
, ".debug_")
7851 || startswith (name
, ".zdebug_")))
7854 name
+= sizeof (".zdebug_") - 1;
7856 name
+= sizeof (".debug_") - 1;
7859 || (do_debug_info
&& startswith (name
, "info"))
7860 || (do_debug_info
&& startswith (name
, "types"))
7861 || (do_debug_abbrevs
&& startswith (name
, "abbrev"))
7862 || (do_debug_lines
&& strcmp (name
, "line") == 0)
7863 || (do_debug_lines
&& startswith (name
, "line."))
7864 || (do_debug_pubnames
&& startswith (name
, "pubnames"))
7865 || (do_debug_pubtypes
&& startswith (name
, "pubtypes"))
7866 || (do_debug_pubnames
&& startswith (name
, "gnu_pubnames"))
7867 || (do_debug_pubtypes
&& startswith (name
, "gnu_pubtypes"))
7868 || (do_debug_aranges
&& startswith (name
, "aranges"))
7869 || (do_debug_ranges
&& startswith (name
, "ranges"))
7870 || (do_debug_ranges
&& startswith (name
, "rnglists"))
7871 || (do_debug_frames
&& startswith (name
, "frame"))
7872 || (do_debug_macinfo
&& startswith (name
, "macinfo"))
7873 || (do_debug_macinfo
&& startswith (name
, "macro"))
7874 || (do_debug_str
&& startswith (name
, "str"))
7875 || (do_debug_links
&& startswith (name
, "sup"))
7876 || (do_debug_str_offsets
&& startswith (name
, "str_offsets"))
7877 || (do_debug_loc
&& startswith (name
, "loc"))
7878 || (do_debug_loc
&& startswith (name
, "loclists"))
7879 || (do_debug_addr
&& startswith (name
, "addr"))
7880 || (do_debug_cu_index
&& startswith (name
, "cu_index"))
7881 || (do_debug_cu_index
&& startswith (name
, "tu_index"))
7883 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7885 /* Linkonce section to be combined with .debug_info at link time. */
7886 else if ((do_debugging
|| do_debug_info
)
7887 && startswith (name
, ".gnu.linkonce.wi."))
7888 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7889 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
7890 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7891 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
7892 || streq (name
, ".debug_names")))
7893 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7894 /* Trace sections for Itanium VMS. */
7895 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
7896 || do_trace_aranges
)
7897 && startswith (name
, ".trace_"))
7899 name
+= sizeof (".trace_") - 1;
7902 || (do_trace_info
&& streq (name
, "info"))
7903 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
7904 || (do_trace_aranges
&& streq (name
, "aranges"))
7906 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7908 else if ((do_debugging
|| do_debug_links
)
7909 && (startswith (name
, ".gnu_debuglink")
7910 || startswith (name
, ".gnu_debugaltlink")))
7911 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7917 if (filedata
->is_separate
&& ! process_links
)
7920 if (filedata
->is_separate
)
7921 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
7922 else if (filedata
->file_header
.e_shnum
> 1)
7923 printf (_("\nSection Headers:\n"));
7925 printf (_("\nSection Header:\n"));
7929 if (do_section_details
)
7931 printf (_(" [Nr] Name\n"));
7932 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
7936 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
7940 if (do_section_details
)
7942 printf (_(" [Nr] Name\n"));
7943 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
7947 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
7951 if (do_section_details
)
7953 printf (_(" [Nr] Name\n"));
7954 printf (_(" Type Address Offset Link\n"));
7955 printf (_(" Size EntSize Info Align\n"));
7959 printf (_(" [Nr] Name Type Address Offset\n"));
7960 printf (_(" Size EntSize Flags Link Info Align\n"));
7964 if (do_section_details
)
7965 printf (_(" Flags\n"));
7967 for (i
= 0, section
= filedata
->section_headers
;
7968 i
< filedata
->file_header
.e_shnum
;
7971 /* Run some sanity checks on the section header. */
7973 /* Check the sh_link field. */
7974 switch (section
->sh_type
)
7978 if (section
->sh_link
== 0
7979 && (filedata
->file_header
.e_type
== ET_EXEC
7980 || filedata
->file_header
.e_type
== ET_DYN
))
7981 /* A dynamic relocation section where all entries use a
7982 zero symbol index need not specify a symtab section. */
7985 case SHT_SYMTAB_SHNDX
:
7989 case SHT_GNU_versym
:
7990 if (section
->sh_link
== 0
7991 || section
->sh_link
>= filedata
->file_header
.e_shnum
7992 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
7993 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
7994 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
7995 i
, section
->sh_link
);
8001 case SHT_GNU_verneed
:
8002 case SHT_GNU_verdef
:
8003 case SHT_GNU_LIBLIST
:
8004 if (section
->sh_link
== 0
8005 || section
->sh_link
>= filedata
->file_header
.e_shnum
8006 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
8007 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
8008 i
, section
->sh_link
);
8011 case SHT_INIT_ARRAY
:
8012 case SHT_FINI_ARRAY
:
8013 case SHT_PREINIT_ARRAY
:
8014 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
8015 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
8016 i
, section
->sh_link
);
8020 /* FIXME: Add support for target specific section types. */
8021 #if 0 /* Currently we do not check other section types as there are too
8022 many special cases. Stab sections for example have a type
8023 of SHT_PROGBITS but an sh_link field that links to the .stabstr
8025 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
8026 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
8027 i
, section
->sh_link
);
8032 /* Check the sh_info field. */
8033 switch (section
->sh_type
)
8037 if (section
->sh_info
== 0
8038 && (filedata
->file_header
.e_type
== ET_EXEC
8039 || filedata
->file_header
.e_type
== ET_DYN
))
8040 /* Dynamic relocations apply to segments, so they do not
8041 need to specify the section they relocate. */
8043 if (section
->sh_info
== 0
8044 || section
->sh_info
>= filedata
->file_header
.e_shnum
8045 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
8046 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
8047 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
8048 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
8049 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
8050 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
8051 /* FIXME: Are other section types valid ? */
8052 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
8053 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
8054 i
, section
->sh_info
);
8059 case SHT_SYMTAB_SHNDX
:
8060 case SHT_INIT_ARRAY
:
8061 case SHT_FINI_ARRAY
:
8062 case SHT_PREINIT_ARRAY
:
8063 if (section
->sh_info
!= 0)
8064 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
8065 i
, section
->sh_info
);
8071 /* A symbol index - we assume that it is valid. */
8075 /* FIXME: Add support for target specific section types. */
8076 if (section
->sh_type
== SHT_NOBITS
)
8077 /* NOBITS section headers with non-zero sh_info fields can be
8078 created when a binary is stripped of everything but its debug
8079 information. The stripped sections have their headers
8080 preserved but their types set to SHT_NOBITS. So do not check
8081 this type of section. */
8083 else if (section
->sh_flags
& SHF_INFO_LINK
)
8085 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
8086 warn (_("[%2u]: Expected link to another section in info field"), i
);
8088 else if (section
->sh_type
< SHT_LOOS
8089 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
8090 && section
->sh_info
!= 0)
8091 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
8092 i
, section
->sh_info
);
8096 /* Check the sh_size field. */
8097 if (section
->sh_size
> filedata
->file_size
8098 && section
->sh_type
!= SHT_NOBITS
8099 && section
->sh_type
!= SHT_NULL
8100 && section
->sh_type
< SHT_LOOS
)
8101 warn (_("Size of section %u is larger than the entire file!\n"), i
);
8103 printf (" [%2u] ", i
);
8104 if (do_section_details
)
8105 printf ("%s\n ", printable_section_name (filedata
, section
));
8107 print_symbol_name (-17, printable_section_name (filedata
, section
));
8109 printf (do_wide
? " %-15s " : " %-15.15s ",
8110 get_section_type_name (filedata
, section
->sh_type
));
8114 const char * link_too_big
= NULL
;
8116 print_vma (section
->sh_addr
, LONG_HEX
);
8118 printf ( " %6.6lx %6.6lx %2.2lx",
8119 (unsigned long) section
->sh_offset
,
8120 (unsigned long) section
->sh_size
,
8121 (unsigned long) section
->sh_entsize
);
8123 if (do_section_details
)
8124 fputs (" ", stdout
);
8126 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
8128 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
8131 /* The sh_link value is out of range. Normally this indicates
8132 an error but it can have special values in Solaris binaries. */
8133 switch (filedata
->file_header
.e_machine
)
8140 case EM_OLD_SPARCV9
:
8141 case EM_SPARC32PLUS
:
8144 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
8145 link_too_big
= "BEFORE";
8146 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
8147 link_too_big
= "AFTER";
8154 if (do_section_details
)
8156 if (link_too_big
!= NULL
&& * link_too_big
)
8157 printf ("<%s> ", link_too_big
);
8159 printf ("%2u ", section
->sh_link
);
8160 printf ("%3u %2lu\n", section
->sh_info
,
8161 (unsigned long) section
->sh_addralign
);
8164 printf ("%2u %3u %2lu\n",
8167 (unsigned long) section
->sh_addralign
);
8169 if (link_too_big
&& ! * link_too_big
)
8170 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
8171 i
, section
->sh_link
);
8175 print_vma (section
->sh_addr
, LONG_HEX
);
8177 if ((long) section
->sh_offset
== section
->sh_offset
)
8178 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
8182 print_vma (section
->sh_offset
, LONG_HEX
);
8185 if ((unsigned long) section
->sh_size
== section
->sh_size
)
8186 printf (" %6.6lx", (unsigned long) section
->sh_size
);
8190 print_vma (section
->sh_size
, LONG_HEX
);
8193 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
8194 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
8198 print_vma (section
->sh_entsize
, LONG_HEX
);
8201 if (do_section_details
)
8202 fputs (" ", stdout
);
8204 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
8206 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
8208 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
8209 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
8212 print_vma (section
->sh_addralign
, DEC
);
8216 else if (do_section_details
)
8219 print_vma (section
->sh_addr
, LONG_HEX
);
8220 if ((long) section
->sh_offset
== section
->sh_offset
)
8221 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
8225 print_vma (section
->sh_offset
, LONG_HEX
);
8227 printf (" %u\n ", section
->sh_link
);
8228 print_vma (section
->sh_size
, LONG_HEX
);
8230 print_vma (section
->sh_entsize
, LONG_HEX
);
8232 printf (" %-16u %lu\n",
8234 (unsigned long) section
->sh_addralign
);
8239 print_vma (section
->sh_addr
, LONG_HEX
);
8240 if ((long) section
->sh_offset
== section
->sh_offset
)
8241 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
8245 print_vma (section
->sh_offset
, LONG_HEX
);
8248 print_vma (section
->sh_size
, LONG_HEX
);
8250 print_vma (section
->sh_entsize
, LONG_HEX
);
8252 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
8254 printf (" %2u %3u %lu\n",
8257 (unsigned long) section
->sh_addralign
);
8260 if (do_section_details
)
8262 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
8263 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
8265 /* Minimum section size is 12 bytes for 32-bit compression
8266 header + 12 bytes for compressed data header. */
8267 unsigned char buf
[24];
8269 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
8270 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
8271 sizeof (buf
), _("compression header")))
8273 Elf_Internal_Chdr chdr
;
8275 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
8276 printf (_(" [<corrupt>]\n"));
8279 if (chdr
.ch_type
== ch_compress_zlib
)
8281 else if (chdr
.ch_type
== ch_compress_zstd
)
8284 printf (_(" [<unknown>: 0x%x], "),
8286 print_vma (chdr
.ch_size
, LONG_HEX
);
8287 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
8294 if (!do_section_details
)
8296 /* The ordering of the letters shown here matches the ordering of the
8297 corresponding SHF_xxx values, and hence the order in which these
8298 letters will be displayed to the user. */
8299 printf (_("Key to Flags:\n\
8300 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
8301 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
8302 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
8303 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
8306 case ELFOSABI_FREEBSD
:
8307 printf (_("R (retain), "));
8310 printf (_("D (mbind), "));
8315 if (filedata
->file_header
.e_machine
== EM_X86_64
8316 || filedata
->file_header
.e_machine
== EM_L1OM
8317 || filedata
->file_header
.e_machine
== EM_K1OM
)
8318 printf (_("l (large), "));
8319 else if (filedata
->file_header
.e_machine
== EM_ARM
)
8320 printf (_("y (purecode), "));
8321 else if (filedata
->file_header
.e_machine
== EM_PPC
)
8322 printf (_("v (VLE), "));
8323 printf ("p (processor specific)\n");
8330 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
8331 Elf_Internal_Sym
**symtab
, uint64_t *nsyms
,
8332 char **strtab
, uint64_t *strtablen
)
8336 *symtab
= get_elf_symbols (filedata
, symsec
, nsyms
);
8338 if (*symtab
== NULL
)
8341 if (symsec
->sh_link
!= 0)
8343 Elf_Internal_Shdr
*strsec
;
8345 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
8347 error (_("Bad sh_link in symbol table section\n"));
8354 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
8356 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
8357 1, strsec
->sh_size
, _("string table"));
8358 if (*strtab
== NULL
)
8365 *strtablen
= strsec
->sh_size
;
8371 get_group_flags (unsigned int flags
)
8373 static char buff
[128];
8377 else if (flags
== GRP_COMDAT
)
8380 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
8382 flags
& GRP_MASKOS
? _("<OS specific>") : "",
8383 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
8384 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
8385 ? _("<unknown>") : ""));
8391 process_section_groups (Filedata
* filedata
)
8393 Elf_Internal_Shdr
* section
;
8395 struct group
* group
;
8396 Elf_Internal_Shdr
* symtab_sec
;
8397 Elf_Internal_Shdr
* strtab_sec
;
8398 Elf_Internal_Sym
* symtab
;
8403 /* Don't process section groups unless needed. */
8404 if (!do_unwind
&& !do_section_groups
)
8407 if (filedata
->file_header
.e_shnum
== 0)
8409 if (do_section_groups
)
8411 if (filedata
->is_separate
)
8412 printf (_("\nThere are no sections group in linked file '%s'.\n"),
8413 filedata
->file_name
);
8415 printf (_("\nThere are no section groups in this file.\n"));
8420 if (filedata
->section_headers
== NULL
)
8422 error (_("Section headers are not available!\n"));
8423 /* PR 13622: This can happen with a corrupt ELF header. */
8427 filedata
->section_headers_groups
8428 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
8429 sizeof (struct group
*));
8431 if (filedata
->section_headers_groups
== NULL
)
8433 error (_("Out of memory reading %u section group headers\n"),
8434 filedata
->file_header
.e_shnum
);
8438 /* Scan the sections for the group section. */
8439 filedata
->group_count
= 0;
8440 for (i
= 0, section
= filedata
->section_headers
;
8441 i
< filedata
->file_header
.e_shnum
;
8443 if (section
->sh_type
== SHT_GROUP
)
8444 filedata
->group_count
++;
8446 if (filedata
->group_count
== 0)
8448 if (do_section_groups
)
8450 if (filedata
->is_separate
)
8451 printf (_("\nThere are no section groups in linked file '%s'.\n"),
8452 filedata
->file_name
);
8454 printf (_("\nThere are no section groups in this file.\n"));
8460 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
8461 sizeof (struct group
));
8463 if (filedata
->section_groups
== NULL
)
8465 error (_("Out of memory reading %zu groups\n"), filedata
->group_count
);
8476 if (filedata
->is_separate
)
8477 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
8479 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
8480 i
< filedata
->file_header
.e_shnum
;
8483 if (section
->sh_type
== SHT_GROUP
)
8485 const char * name
= printable_section_name (filedata
, section
);
8486 const char * group_name
;
8487 unsigned char * start
;
8488 unsigned char * indices
;
8489 unsigned int entry
, j
, size
;
8490 Elf_Internal_Shdr
* sec
;
8491 Elf_Internal_Sym
* sym
;
8493 /* Get the symbol table. */
8494 if (section
->sh_link
>= filedata
->file_header
.e_shnum
8495 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
8498 error (_("Bad sh_link in group section `%s'\n"), name
);
8502 if (symtab_sec
!= sec
)
8506 symtab
= get_elf_symbols (filedata
, symtab_sec
, & num_syms
);
8511 error (_("Corrupt header in group section `%s'\n"), name
);
8515 if (section
->sh_info
>= num_syms
)
8517 error (_("Bad sh_info in group section `%s'\n"), name
);
8521 sym
= symtab
+ section
->sh_info
;
8523 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8525 if (sym
->st_shndx
== 0
8526 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
8528 error (_("Bad sh_info in group section `%s'\n"), name
);
8532 group_name
= printable_section_name (filedata
,
8533 filedata
->section_headers
8542 /* Get the string table. */
8543 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
8551 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
8556 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
8557 1, strtab_sec
->sh_size
,
8559 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
8561 group_name
= sym
->st_name
< strtab_size
8562 ? strtab
+ sym
->st_name
: _("<corrupt>");
8565 /* PR 17531: file: loop. */
8566 if (section
->sh_entsize
> section
->sh_size
)
8568 error (_("Section %s has sh_entsize (%#" PRIx64
")"
8569 " which is larger than its size (%#" PRIx64
")\n"),
8570 printable_section_name (filedata
, section
),
8571 section
->sh_entsize
,
8576 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
8577 1, section
->sh_size
,
8583 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
8584 entry
= byte_get (indices
, 4);
8587 if (do_section_groups
)
8589 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
8590 get_group_flags (entry
), i
, name
, group_name
, size
);
8592 printf (_(" [Index] Name\n"));
8595 group
->group_index
= i
;
8597 for (j
= 0; j
< size
; j
++)
8599 struct group_list
* g
;
8601 entry
= byte_get (indices
, 4);
8604 if (entry
>= filedata
->file_header
.e_shnum
)
8606 static unsigned num_group_errors
= 0;
8608 if (num_group_errors
++ < 10)
8610 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
8611 entry
, i
, filedata
->file_header
.e_shnum
- 1);
8612 if (num_group_errors
== 10)
8613 warn (_("Further error messages about overlarge group section indices suppressed\n"));
8618 if (filedata
->section_headers_groups
[entry
] != NULL
)
8622 static unsigned num_errs
= 0;
8624 if (num_errs
++ < 10)
8626 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
8628 filedata
->section_headers_groups
[entry
]->group_index
);
8630 warn (_("Further error messages about already contained group sections suppressed\n"));
8636 /* Intel C/C++ compiler may put section 0 in a
8637 section group. We just warn it the first time
8638 and ignore it afterwards. */
8639 static bool warned
= false;
8642 error (_("section 0 in group section [%5u]\n"),
8643 filedata
->section_headers_groups
[entry
]->group_index
);
8649 filedata
->section_headers_groups
[entry
] = group
;
8651 if (do_section_groups
)
8653 sec
= filedata
->section_headers
+ entry
;
8654 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
8657 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
8658 g
->section_index
= entry
;
8659 g
->next
= group
->root
;
8674 /* Data used to display dynamic fixups. */
8676 struct ia64_vms_dynfixup
8678 uint64_t needed_ident
; /* Library ident number. */
8679 uint64_t needed
; /* Index in the dstrtab of the library name. */
8680 uint64_t fixup_needed
; /* Index of the library. */
8681 uint64_t fixup_rela_cnt
; /* Number of fixups. */
8682 uint64_t fixup_rela_off
; /* Fixups offset in the dynamic segment. */
8685 /* Data used to display dynamic relocations. */
8687 struct ia64_vms_dynimgrela
8689 uint64_t img_rela_cnt
; /* Number of relocations. */
8690 uint64_t img_rela_off
; /* Reloc offset in the dynamic segment. */
8693 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
8697 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
8698 struct ia64_vms_dynfixup
* fixup
,
8699 const char * strtab
,
8700 unsigned int strtab_sz
)
8702 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
8704 const char * lib_name
;
8706 imfs
= get_data (NULL
, filedata
,
8707 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
8708 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
8709 _("dynamic section image fixups"));
8713 if (fixup
->needed
< strtab_sz
)
8714 lib_name
= strtab
+ fixup
->needed
;
8717 warn (_("corrupt library name index of %#" PRIx64
8718 " found in dynamic entry"), fixup
->needed
);
8722 printf (_("\nImage fixups for needed library #%" PRId64
8723 ": %s - ident: %" PRIx64
"\n"),
8724 fixup
->fixup_needed
, lib_name
, fixup
->needed_ident
);
8726 (_("Seg Offset Type SymVec DataType\n"));
8728 for (i
= 0; i
< (size_t) fixup
->fixup_rela_cnt
; i
++)
8733 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
8734 printf ("%016" PRIx64
" ", BYTE_GET (imfs
[i
].fixup_offset
));
8735 type
= BYTE_GET (imfs
[i
].type
);
8736 rtype
= elf_ia64_reloc_type (type
);
8738 printf ("0x%08x ", type
);
8740 printf ("%-32s ", rtype
);
8741 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
8742 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
8749 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
8752 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
8754 Elf64_External_VMS_IMAGE_RELA
*imrs
;
8757 imrs
= get_data (NULL
, filedata
,
8758 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
8759 sizeof (*imrs
), imgrela
->img_rela_cnt
,
8760 _("dynamic section image relocations"));
8764 printf (_("\nImage relocs\n"));
8766 (_("Seg Offset Type Addend Seg Sym Off\n"));
8768 for (i
= 0; i
< (size_t) imgrela
->img_rela_cnt
; i
++)
8773 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
8774 printf ("%08" PRIx64
" ", BYTE_GET (imrs
[i
].rela_offset
));
8775 type
= BYTE_GET (imrs
[i
].type
);
8776 rtype
= elf_ia64_reloc_type (type
);
8778 printf ("0x%08x ", type
);
8780 printf ("%-31s ", rtype
);
8781 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
8782 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
8783 printf ("%08" PRIx64
"\n", BYTE_GET (imrs
[i
].sym_offset
));
8790 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
8793 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
8795 struct ia64_vms_dynfixup fixup
;
8796 struct ia64_vms_dynimgrela imgrela
;
8797 Elf_Internal_Dyn
*entry
;
8798 uint64_t strtab_off
= 0;
8799 uint64_t strtab_sz
= 0;
8800 char *strtab
= NULL
;
8803 memset (&fixup
, 0, sizeof (fixup
));
8804 memset (&imgrela
, 0, sizeof (imgrela
));
8806 /* Note: the order of the entries is specified by the OpenVMS specs. */
8807 for (entry
= filedata
->dynamic_section
;
8808 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
8811 switch (entry
->d_tag
)
8813 case DT_IA_64_VMS_STRTAB_OFFSET
:
8814 strtab_off
= entry
->d_un
.d_val
;
8817 strtab_sz
= entry
->d_un
.d_val
;
8819 strtab
= get_data (NULL
, filedata
,
8820 filedata
->dynamic_addr
+ strtab_off
,
8821 1, strtab_sz
, _("dynamic string section"));
8826 case DT_IA_64_VMS_NEEDED_IDENT
:
8827 fixup
.needed_ident
= entry
->d_un
.d_val
;
8830 fixup
.needed
= entry
->d_un
.d_val
;
8832 case DT_IA_64_VMS_FIXUP_NEEDED
:
8833 fixup
.fixup_needed
= entry
->d_un
.d_val
;
8835 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
8836 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
8838 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
8839 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
8840 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
8843 case DT_IA_64_VMS_IMG_RELA_CNT
:
8844 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
8846 case DT_IA_64_VMS_IMG_RELA_OFF
:
8847 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
8848 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
8867 relocation_type rel_type
;
8869 dynamic_relocations
[] =
8871 { "REL", DT_REL
, DT_RELSZ
, reltype_rel
},
8872 { "RELA", DT_RELA
, DT_RELASZ
, reltype_rela
},
8873 { "RELR", DT_RELR
, DT_RELRSZ
, reltype_relr
},
8874 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, reltype_unknown
}
8877 /* Process the reloc section. */
8880 process_relocs (Filedata
* filedata
)
8883 uint64_t rel_offset
;
8888 if (do_using_dynamic
)
8890 relocation_type rel_type
;
8892 bool has_dynamic_reloc
;
8895 has_dynamic_reloc
= false;
8897 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8899 rel_type
= dynamic_relocations
[i
].rel_type
;
8900 name
= dynamic_relocations
[i
].name
;
8901 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
8902 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
8905 has_dynamic_reloc
= true;
8907 if (rel_type
== reltype_unknown
)
8909 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
8910 switch (filedata
->dynamic_info
[DT_PLTREL
])
8913 rel_type
= reltype_rel
;
8916 rel_type
= reltype_rela
;
8923 if (filedata
->is_separate
)
8925 (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64
8926 " contains %" PRId64
" bytes:\n"),
8927 filedata
->file_name
, name
, rel_offset
, rel_size
);
8930 (_("\n'%s' relocation section at offset %#" PRIx64
8931 " contains %" PRId64
" bytes:\n"),
8932 name
, rel_offset
, rel_size
);
8934 dump_relocations (filedata
,
8935 offset_from_vma (filedata
, rel_offset
, rel_size
),
8937 filedata
->dynamic_symbols
,
8938 filedata
->num_dynamic_syms
,
8939 filedata
->dynamic_strings
,
8940 filedata
->dynamic_strings_length
,
8941 rel_type
, true /* is_dynamic */);
8945 if (is_ia64_vms (filedata
))
8946 if (process_ia64_vms_dynamic_relocs (filedata
))
8947 has_dynamic_reloc
= true;
8949 if (! has_dynamic_reloc
)
8951 if (filedata
->is_separate
)
8952 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
8953 filedata
->file_name
);
8955 printf (_("\nThere are no dynamic relocations in this file.\n"));
8960 Elf_Internal_Shdr
* section
;
8964 for (i
= 0, section
= filedata
->section_headers
;
8965 i
< filedata
->file_header
.e_shnum
;
8968 if ( section
->sh_type
!= SHT_RELA
8969 && section
->sh_type
!= SHT_REL
8970 && section
->sh_type
!= SHT_RELR
)
8973 rel_offset
= section
->sh_offset
;
8974 rel_size
= section
->sh_size
;
8978 relocation_type rel_type
;
8981 if (filedata
->is_separate
)
8982 printf (_("\nIn linked file '%s' relocation section "),
8983 filedata
->file_name
);
8985 printf (_("\nRelocation section "));
8987 if (filedata
->string_table
== NULL
)
8988 printf ("%d", section
->sh_name
);
8990 printf ("'%s'", printable_section_name (filedata
, section
));
8992 num_rela
= rel_size
/ section
->sh_entsize
;
8993 printf (ngettext (" at offset %#" PRIx64
8994 " contains %" PRIu64
" entry:\n",
8995 " at offset %#" PRIx64
8996 " contains %" PRId64
" entries:\n",
8998 rel_offset
, num_rela
);
9000 rel_type
= section
->sh_type
== SHT_RELA
? reltype_rela
:
9001 section
->sh_type
== SHT_REL
? reltype_rel
: reltype_relr
;
9003 if (section
->sh_link
!= 0
9004 && section
->sh_link
< filedata
->file_header
.e_shnum
)
9006 Elf_Internal_Shdr
*symsec
;
9007 Elf_Internal_Sym
*symtab
;
9009 uint64_t strtablen
= 0;
9010 char *strtab
= NULL
;
9012 symsec
= filedata
->section_headers
+ section
->sh_link
;
9013 if (symsec
->sh_type
!= SHT_SYMTAB
9014 && symsec
->sh_type
!= SHT_DYNSYM
)
9017 if (!get_symtab (filedata
, symsec
,
9018 &symtab
, &nsyms
, &strtab
, &strtablen
))
9021 dump_relocations (filedata
, rel_offset
, rel_size
,
9022 symtab
, nsyms
, strtab
, strtablen
,
9024 symsec
->sh_type
== SHT_DYNSYM
);
9029 dump_relocations (filedata
, rel_offset
, rel_size
,
9030 NULL
, 0, NULL
, 0, rel_type
, false /* is_dynamic */);
9038 /* Users sometimes forget the -D option, so try to be helpful. */
9039 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
9041 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
9043 if (filedata
->is_separate
)
9044 printf (_("\nThere are no static relocations in linked file '%s'."),
9045 filedata
->file_name
);
9047 printf (_("\nThere are no static relocations in this file."));
9048 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
9053 if (i
== ARRAY_SIZE (dynamic_relocations
))
9055 if (filedata
->is_separate
)
9056 printf (_("\nThere are no relocations in linked file '%s'.\n"),
9057 filedata
->file_name
);
9059 printf (_("\nThere are no relocations in this file.\n"));
9067 /* An absolute address consists of a section and an offset. If the
9068 section is NULL, the offset itself is the address, otherwise, the
9069 address equals to LOAD_ADDRESS(section) + offset. */
9073 unsigned short section
;
9077 /* Find the nearest symbol at or below ADDR. Returns the symbol
9078 name, if found, and the offset from the symbol to ADDR. */
9081 find_symbol_for_address (Filedata
*filedata
,
9082 Elf_Internal_Sym
*symtab
,
9085 uint64_t strtab_size
,
9086 struct absaddr addr
,
9087 const char **symname
,
9090 uint64_t dist
= 0x100000;
9091 Elf_Internal_Sym
* sym
;
9092 Elf_Internal_Sym
* beg
;
9093 Elf_Internal_Sym
* end
;
9094 Elf_Internal_Sym
* best
= NULL
;
9096 REMOVE_ARCH_BITS (addr
.offset
);
9098 end
= symtab
+ nsyms
;
9104 sym
= beg
+ (end
- beg
) / 2;
9106 value
= sym
->st_value
;
9107 REMOVE_ARCH_BITS (value
);
9109 if (sym
->st_name
!= 0
9110 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
9111 && addr
.offset
>= value
9112 && addr
.offset
- value
< dist
)
9115 dist
= addr
.offset
- value
;
9120 if (addr
.offset
< value
)
9128 *symname
= (best
->st_name
>= strtab_size
9129 ? _("<corrupt>") : strtab
+ best
->st_name
);
9135 *offset
= addr
.offset
;
9138 static /* signed */ int
9139 symcmp (const void *p
, const void *q
)
9141 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
9142 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
9144 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
9147 /* Process the unwind section. */
9149 #include "unwind-ia64.h"
9151 struct ia64_unw_table_entry
9153 struct absaddr start
;
9155 struct absaddr info
;
9158 struct ia64_unw_aux_info
9160 struct ia64_unw_table_entry
* table
; /* Unwind table. */
9161 uint64_t table_len
; /* Length of unwind table. */
9162 unsigned char * info
; /* Unwind info. */
9163 uint64_t info_size
; /* Size of unwind info. */
9164 uint64_t info_addr
; /* Starting address of unwind info. */
9165 uint64_t seg_base
; /* Starting address of segment. */
9166 Elf_Internal_Sym
* symtab
; /* The symbol table. */
9167 uint64_t nsyms
; /* Number of symbols. */
9168 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9169 uint64_t nfuns
; /* Number of entries in funtab. */
9170 char * strtab
; /* The string table. */
9171 uint64_t strtab_size
; /* Size of string table. */
9175 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
9177 struct ia64_unw_table_entry
* tp
;
9182 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9183 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9184 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9185 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9187 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9189 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
9193 const unsigned char * dp
;
9194 const unsigned char * head
;
9195 const unsigned char * end
;
9196 const char * procname
;
9198 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9199 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
9201 fputs ("\n<", stdout
);
9205 fputs (procname
, stdout
);
9208 printf ("+%" PRIx64
, offset
);
9211 fputs (">: [", stdout
);
9212 print_vma (tp
->start
.offset
, PREFIX_HEX
);
9213 fputc ('-', stdout
);
9214 print_vma (tp
->end
.offset
, PREFIX_HEX
);
9215 printf ("], info at +0x%" PRIx64
"\n",
9216 tp
->info
.offset
- aux
->seg_base
);
9218 /* PR 17531: file: 86232b32. */
9219 if (aux
->info
== NULL
)
9222 offset
= tp
->info
.offset
;
9223 if (tp
->info
.section
)
9225 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
9227 warn (_("Invalid section %u in table entry %td\n"),
9228 tp
->info
.section
, tp
- aux
->table
);
9232 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
9234 offset
-= aux
->info_addr
;
9235 /* PR 17531: file: 0997b4d1. */
9236 if (offset
>= aux
->info_size
9237 || aux
->info_size
- offset
< 8)
9239 warn (_("Invalid offset %" PRIx64
" in table entry %td\n"),
9240 tp
->info
.offset
, tp
- aux
->table
);
9245 head
= aux
->info
+ offset
;
9246 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
9248 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
9249 (unsigned) UNW_VER (stamp
),
9250 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
9251 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
9252 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
9253 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
9255 if (UNW_VER (stamp
) != 1)
9257 printf (_("\tUnknown version.\n"));
9262 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
9263 /* PR 17531: file: 16ceda89. */
9264 if (end
> aux
->info
+ aux
->info_size
)
9265 end
= aux
->info
+ aux
->info_size
;
9266 for (dp
= head
+ 8; dp
< end
;)
9267 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
9276 slurp_ia64_unwind_table (Filedata
* filedata
,
9277 struct ia64_unw_aux_info
* aux
,
9278 Elf_Internal_Shdr
* sec
)
9280 uint64_t size
, nrelas
, i
;
9281 Elf_Internal_Phdr
* seg
;
9282 struct ia64_unw_table_entry
* tep
;
9283 Elf_Internal_Shdr
* relsec
;
9284 Elf_Internal_Rela
* rela
;
9285 Elf_Internal_Rela
* rp
;
9286 unsigned char * table
;
9288 Elf_Internal_Sym
* sym
;
9289 const char * relname
;
9293 /* First, find the starting address of the segment that includes
9296 if (filedata
->file_header
.e_phnum
)
9298 if (! get_program_headers (filedata
))
9301 for (seg
= filedata
->program_headers
;
9302 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
9305 if (seg
->p_type
!= PT_LOAD
)
9308 if (sec
->sh_addr
>= seg
->p_vaddr
9309 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
9311 aux
->seg_base
= seg
->p_vaddr
;
9317 /* Second, build the unwind table from the contents of the unwind section: */
9318 size
= sec
->sh_size
;
9319 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
9324 aux
->table_len
= size
/ (3 * eh_addr_size
);
9325 aux
->table
= (struct ia64_unw_table_entry
*)
9326 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
9329 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
9331 tep
->start
.section
= SHN_UNDEF
;
9332 tep
->end
.section
= SHN_UNDEF
;
9333 tep
->info
.section
= SHN_UNDEF
;
9334 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
9335 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
9336 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
9337 tep
->start
.offset
+= aux
->seg_base
;
9338 tep
->end
.offset
+= aux
->seg_base
;
9339 tep
->info
.offset
+= aux
->seg_base
;
9343 /* Third, apply any relocations to the unwind table: */
9344 for (relsec
= filedata
->section_headers
;
9345 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9348 if (relsec
->sh_type
!= SHT_RELA
9349 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
9350 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
9353 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
9362 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
9364 unsigned int sym_ndx
;
9365 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
9366 relname
= elf_ia64_reloc_type (r_type
);
9368 /* PR 17531: file: 9fa67536. */
9369 if (relname
== NULL
)
9371 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
9375 if (! startswith (relname
, "R_IA64_SEGREL"))
9377 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
9381 i
= rp
->r_offset
/ (3 * eh_addr_size
);
9383 /* PR 17531: file: 5bc8d9bf. */
9384 if (i
>= aux
->table_len
)
9386 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
9391 sym_ndx
= get_reloc_symindex (rp
->r_info
);
9392 if (sym_ndx
>= aux
->nsyms
)
9394 warn (_("Skipping reloc with invalid symbol index: %u\n"),
9398 sym
= aux
->symtab
+ sym_ndx
;
9400 switch (rp
->r_offset
/ eh_addr_size
% 3)
9403 aux
->table
[i
].start
.section
= sym
->st_shndx
;
9404 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
9407 aux
->table
[i
].end
.section
= sym
->st_shndx
;
9408 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
9411 aux
->table
[i
].info
.section
= sym
->st_shndx
;
9412 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
9426 ia64_process_unwind (Filedata
* filedata
)
9428 Elf_Internal_Shdr
* sec
;
9429 Elf_Internal_Shdr
* unwsec
= NULL
;
9430 uint64_t i
, unwcount
= 0, unwstart
= 0;
9431 struct ia64_unw_aux_info aux
;
9434 memset (& aux
, 0, sizeof (aux
));
9436 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9438 if (sec
->sh_type
== SHT_SYMTAB
)
9442 error (_("Multiple symbol tables encountered\n"));
9448 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9449 &aux
.strtab
, &aux
.strtab_size
))
9452 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
9457 printf (_("\nThere are no unwind sections in this file.\n"));
9459 while (unwcount
-- > 0)
9464 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
9465 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9466 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
9471 /* We have already counted the number of SHT_IA64_UNWIND
9472 sections so the loop above should never fail. */
9473 assert (unwsec
!= NULL
);
9476 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
9478 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
9480 /* We need to find which section group it is in. */
9481 struct group_list
* g
;
9483 if (filedata
->section_headers_groups
== NULL
9484 || filedata
->section_headers_groups
[i
] == NULL
)
9485 i
= filedata
->file_header
.e_shnum
;
9488 g
= filedata
->section_headers_groups
[i
]->root
;
9490 for (; g
!= NULL
; g
= g
->next
)
9492 sec
= filedata
->section_headers
+ g
->section_index
;
9494 if (section_name_valid (filedata
, sec
)
9495 && streq (section_name (filedata
, sec
),
9496 ELF_STRING_ia64_unwind_info
))
9501 i
= filedata
->file_header
.e_shnum
;
9504 else if (section_name_valid (filedata
, unwsec
)
9505 && startswith (section_name (filedata
, unwsec
),
9506 ELF_STRING_ia64_unwind_once
))
9508 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
9509 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
9510 suffix
= section_name (filedata
, unwsec
) + len
;
9511 for (i
= 0, sec
= filedata
->section_headers
;
9512 i
< filedata
->file_header
.e_shnum
;
9514 if (section_name_valid (filedata
, sec
)
9515 && startswith (section_name (filedata
, sec
),
9516 ELF_STRING_ia64_unwind_info_once
)
9517 && streq (section_name (filedata
, sec
) + len2
, suffix
))
9522 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
9523 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
9524 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
9525 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
9527 if (section_name_valid (filedata
, unwsec
)
9528 && startswith (section_name (filedata
, unwsec
),
9529 ELF_STRING_ia64_unwind
))
9530 suffix
= section_name (filedata
, unwsec
) + len
;
9531 for (i
= 0, sec
= filedata
->section_headers
;
9532 i
< filedata
->file_header
.e_shnum
;
9534 if (section_name_valid (filedata
, sec
)
9535 && startswith (section_name (filedata
, sec
),
9536 ELF_STRING_ia64_unwind_info
)
9537 && streq (section_name (filedata
, sec
) + len2
, suffix
))
9541 if (i
== filedata
->file_header
.e_shnum
)
9543 printf (_("\nCould not find unwind info section for "));
9545 if (filedata
->string_table
== NULL
)
9546 printf ("%d", unwsec
->sh_name
);
9548 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9552 aux
.info_addr
= sec
->sh_addr
;
9553 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
9556 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
9558 printf (_("\nUnwind section "));
9560 if (filedata
->string_table
== NULL
)
9561 printf ("%d", unwsec
->sh_name
);
9563 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9565 printf (_(" at offset %#" PRIx64
" contains %" PRIu64
" entries:\n"),
9567 unwsec
->sh_size
/ (3 * eh_addr_size
));
9569 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
9570 && aux
.table_len
> 0)
9571 dump_ia64_unwind (filedata
, & aux
);
9573 free ((char *) aux
.table
);
9574 free ((char *) aux
.info
);
9581 free ((char *) aux
.strtab
);
9586 struct hppa_unw_table_entry
9588 struct absaddr start
;
9590 unsigned int Cannot_unwind
:1; /* 0 */
9591 unsigned int Millicode
:1; /* 1 */
9592 unsigned int Millicode_save_sr0
:1; /* 2 */
9593 unsigned int Region_description
:2; /* 3..4 */
9594 unsigned int reserved1
:1; /* 5 */
9595 unsigned int Entry_SR
:1; /* 6 */
9596 unsigned int Entry_FR
:4; /* Number saved 7..10 */
9597 unsigned int Entry_GR
:5; /* Number saved 11..15 */
9598 unsigned int Args_stored
:1; /* 16 */
9599 unsigned int Variable_Frame
:1; /* 17 */
9600 unsigned int Separate_Package_Body
:1; /* 18 */
9601 unsigned int Frame_Extension_Millicode
:1; /* 19 */
9602 unsigned int Stack_Overflow_Check
:1; /* 20 */
9603 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
9604 unsigned int Ada_Region
:1; /* 22 */
9605 unsigned int cxx_info
:1; /* 23 */
9606 unsigned int cxx_try_catch
:1; /* 24 */
9607 unsigned int sched_entry_seq
:1; /* 25 */
9608 unsigned int reserved2
:1; /* 26 */
9609 unsigned int Save_SP
:1; /* 27 */
9610 unsigned int Save_RP
:1; /* 28 */
9611 unsigned int Save_MRP_in_frame
:1; /* 29 */
9612 unsigned int extn_ptr_defined
:1; /* 30 */
9613 unsigned int Cleanup_defined
:1; /* 31 */
9615 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
9616 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
9617 unsigned int Large_frame
:1; /* 2 */
9618 unsigned int Pseudo_SP_Set
:1; /* 3 */
9619 unsigned int reserved4
:1; /* 4 */
9620 unsigned int Total_frame_size
:27; /* 5..31 */
9623 struct hppa_unw_aux_info
9625 struct hppa_unw_table_entry
* table
; /* Unwind table. */
9626 uint64_t table_len
; /* Length of unwind table. */
9627 uint64_t seg_base
; /* Starting address of segment. */
9628 Elf_Internal_Sym
* symtab
; /* The symbol table. */
9629 uint64_t nsyms
; /* Number of symbols. */
9630 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9631 uint64_t nfuns
; /* Number of entries in funtab. */
9632 char * strtab
; /* The string table. */
9633 uint64_t strtab_size
; /* Size of string table. */
9637 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
9639 struct hppa_unw_table_entry
* tp
;
9643 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9644 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9645 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9646 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9648 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9650 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
9653 const char * procname
;
9655 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9656 aux
->strtab_size
, tp
->start
, &procname
,
9659 fputs ("\n<", stdout
);
9663 fputs (procname
, stdout
);
9666 printf ("+%" PRIx64
, offset
);
9669 fputs (">: [", stdout
);
9670 print_vma (tp
->start
.offset
, PREFIX_HEX
);
9671 fputc ('-', stdout
);
9672 print_vma (tp
->end
.offset
, PREFIX_HEX
);
9675 #define PF(_m) if (tp->_m) printf (#_m " ");
9676 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
9679 PF(Millicode_save_sr0
);
9680 /* PV(Region_description); */
9686 PF(Separate_Package_Body
);
9687 PF(Frame_Extension_Millicode
);
9688 PF(Stack_Overflow_Check
);
9689 PF(Two_Instruction_SP_Increment
);
9693 PF(sched_entry_seq
);
9696 PF(Save_MRP_in_frame
);
9697 PF(extn_ptr_defined
);
9698 PF(Cleanup_defined
);
9699 PF(MPE_XL_interrupt_marker
);
9700 PF(HP_UX_interrupt_marker
);
9703 PV(Total_frame_size
);
9716 slurp_hppa_unwind_table (Filedata
* filedata
,
9717 struct hppa_unw_aux_info
* aux
,
9718 Elf_Internal_Shdr
* sec
)
9720 uint64_t size
, unw_ent_size
, nentries
, nrelas
, i
;
9721 Elf_Internal_Phdr
* seg
;
9722 struct hppa_unw_table_entry
* tep
;
9723 Elf_Internal_Shdr
* relsec
;
9724 Elf_Internal_Rela
* rela
;
9725 Elf_Internal_Rela
* rp
;
9726 unsigned char * table
;
9728 Elf_Internal_Sym
* sym
;
9729 const char * relname
;
9731 /* First, find the starting address of the segment that includes
9733 if (filedata
->file_header
.e_phnum
)
9735 if (! get_program_headers (filedata
))
9738 for (seg
= filedata
->program_headers
;
9739 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
9742 if (seg
->p_type
!= PT_LOAD
)
9745 if (sec
->sh_addr
>= seg
->p_vaddr
9746 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
9748 aux
->seg_base
= seg
->p_vaddr
;
9754 /* Second, build the unwind table from the contents of the unwind
9756 size
= sec
->sh_size
;
9757 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
9763 nentries
= size
/ unw_ent_size
;
9764 size
= unw_ent_size
* nentries
;
9766 aux
->table_len
= nentries
;
9767 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
9768 xcmalloc (nentries
, sizeof (aux
->table
[0]));
9770 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
9772 unsigned int tmp1
, tmp2
;
9774 tep
->start
.section
= SHN_UNDEF
;
9775 tep
->end
.section
= SHN_UNDEF
;
9777 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
9778 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
9779 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
9780 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
9782 tep
->start
.offset
+= aux
->seg_base
;
9783 tep
->end
.offset
+= aux
->seg_base
;
9785 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
9786 tep
->Millicode
= (tmp1
>> 30) & 0x1;
9787 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
9788 tep
->Region_description
= (tmp1
>> 27) & 0x3;
9789 tep
->reserved1
= (tmp1
>> 26) & 0x1;
9790 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
9791 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
9792 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
9793 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
9794 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
9795 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
9796 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
9797 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
9798 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
9799 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
9800 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
9801 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
9802 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
9803 tep
->reserved2
= (tmp1
>> 5) & 0x1;
9804 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
9805 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
9806 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
9807 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
9808 tep
->Cleanup_defined
= tmp1
& 0x1;
9810 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
9811 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
9812 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
9813 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
9814 tep
->reserved4
= (tmp2
>> 27) & 0x1;
9815 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
9819 /* Third, apply any relocations to the unwind table. */
9820 for (relsec
= filedata
->section_headers
;
9821 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9824 if (relsec
->sh_type
!= SHT_RELA
9825 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
9826 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
9829 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
9833 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
9835 unsigned int sym_ndx
;
9836 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
9837 relname
= elf_hppa_reloc_type (r_type
);
9839 if (relname
== NULL
)
9841 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
9845 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
9846 if (! startswith (relname
, "R_PARISC_SEGREL"))
9848 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
9852 i
= rp
->r_offset
/ unw_ent_size
;
9853 if (i
>= aux
->table_len
)
9855 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
9860 sym_ndx
= get_reloc_symindex (rp
->r_info
);
9861 if (sym_ndx
>= aux
->nsyms
)
9863 warn (_("Skipping reloc with invalid symbol index: %u\n"),
9867 sym
= aux
->symtab
+ sym_ndx
;
9869 switch ((rp
->r_offset
% unw_ent_size
) / 4)
9872 aux
->table
[i
].start
.section
= sym
->st_shndx
;
9873 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
9876 aux
->table
[i
].end
.section
= sym
->st_shndx
;
9877 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
9891 hppa_process_unwind (Filedata
* filedata
)
9893 struct hppa_unw_aux_info aux
;
9894 Elf_Internal_Shdr
* unwsec
= NULL
;
9895 Elf_Internal_Shdr
* sec
;
9899 if (filedata
->string_table
== NULL
)
9902 memset (& aux
, 0, sizeof (aux
));
9904 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9906 if (sec
->sh_type
== SHT_SYMTAB
)
9910 error (_("Multiple symbol tables encountered\n"));
9916 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9917 &aux
.strtab
, &aux
.strtab_size
))
9920 else if (section_name_valid (filedata
, sec
)
9921 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9926 printf (_("\nThere are no unwind sections in this file.\n"));
9928 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9930 if (section_name_valid (filedata
, sec
)
9931 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9933 uint64_t num_unwind
= sec
->sh_size
/ 16;
9935 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
9936 "contains %" PRIu64
" entry:\n",
9937 "\nUnwind section '%s' at offset %#" PRIx64
" "
9938 "contains %" PRIu64
" entries:\n",
9940 printable_section_name (filedata
, sec
),
9944 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
9947 if (res
&& aux
.table_len
> 0)
9949 if (! dump_hppa_unwind (filedata
, &aux
))
9953 free ((char *) aux
.table
);
9959 free ((char *) aux
.strtab
);
9966 unsigned char * data
; /* The unwind data. */
9967 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
9968 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
9969 uint64_t nrelas
; /* The number of relocations. */
9970 unsigned int rel_type
; /* REL or RELA ? */
9971 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
9974 struct arm_unw_aux_info
9976 Filedata
* filedata
; /* The file containing the unwind sections. */
9977 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
9978 uint64_t nsyms
; /* Number of symbols. */
9979 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9980 uint64_t nfuns
; /* Number of these symbols. */
9981 char * strtab
; /* The file's string table. */
9982 uint64_t strtab_size
; /* Size of string table. */
9986 arm_print_vma_and_name (Filedata
* filedata
,
9987 struct arm_unw_aux_info
* aux
,
9989 struct absaddr addr
)
9991 const char *procname
;
9992 uint64_t sym_offset
;
9994 if (addr
.section
== SHN_UNDEF
)
9997 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9998 aux
->strtab_size
, addr
, &procname
,
10001 print_vma (fn
, PREFIX_HEX
);
10005 fputs (" <", stdout
);
10006 fputs (procname
, stdout
);
10009 printf ("+0x%" PRIx64
, sym_offset
);
10010 fputc ('>', stdout
);
10017 arm_free_section (struct arm_section
*arm_sec
)
10019 free (arm_sec
->data
);
10020 free (arm_sec
->rela
);
10023 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
10024 cached section and install SEC instead.
10025 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
10026 and return its valued in * WORDP, relocating if necessary.
10027 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
10028 relocation's offset in ADDR.
10029 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
10030 into the string table of the symbol associated with the reloc. If no
10031 reloc was applied store -1 there.
10032 5) Return TRUE upon success, FALSE otherwise. */
10035 get_unwind_section_word (Filedata
* filedata
,
10036 struct arm_unw_aux_info
* aux
,
10037 struct arm_section
* arm_sec
,
10038 Elf_Internal_Shdr
* sec
,
10039 uint64_t word_offset
,
10040 unsigned int * wordp
,
10041 struct absaddr
* addr
,
10042 uint64_t * sym_name
)
10044 Elf_Internal_Rela
*rp
;
10045 Elf_Internal_Sym
*sym
;
10046 const char * relname
;
10050 if (sec
== NULL
|| arm_sec
== NULL
)
10053 addr
->section
= SHN_UNDEF
;
10056 if (sym_name
!= NULL
)
10057 *sym_name
= (uint64_t) -1;
10059 /* If necessary, update the section cache. */
10060 if (sec
!= arm_sec
->sec
)
10062 Elf_Internal_Shdr
*relsec
;
10064 arm_free_section (arm_sec
);
10066 arm_sec
->sec
= sec
;
10067 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
10068 sec
->sh_size
, _("unwind data"));
10069 arm_sec
->rela
= NULL
;
10070 arm_sec
->nrelas
= 0;
10072 for (relsec
= filedata
->section_headers
;
10073 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
10076 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
10077 || filedata
->section_headers
+ relsec
->sh_info
!= sec
10078 /* PR 15745: Check the section type as well. */
10079 || (relsec
->sh_type
!= SHT_REL
10080 && relsec
->sh_type
!= SHT_RELA
))
10083 arm_sec
->rel_type
= relsec
->sh_type
;
10084 if (relsec
->sh_type
== SHT_REL
)
10086 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
10088 & arm_sec
->rela
, & arm_sec
->nrelas
))
10091 else /* relsec->sh_type == SHT_RELA */
10093 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
10095 & arm_sec
->rela
, & arm_sec
->nrelas
))
10101 arm_sec
->next_rela
= arm_sec
->rela
;
10104 /* If there is no unwind data we can do nothing. */
10105 if (arm_sec
->data
== NULL
)
10108 /* If the offset is invalid then fail. */
10109 if (/* PR 21343 *//* PR 18879 */
10111 || word_offset
> sec
->sh_size
- 4)
10114 /* Get the word at the required offset. */
10115 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
10117 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
10118 if (arm_sec
->rela
== NULL
)
10124 /* Look through the relocs to find the one that applies to the provided offset. */
10126 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
10128 uint64_t prelval
, offset
;
10130 if (rp
->r_offset
> word_offset
&& !wrapped
)
10132 rp
= arm_sec
->rela
;
10135 if (rp
->r_offset
> word_offset
)
10138 if (rp
->r_offset
& 3)
10140 warn (_("Skipping unexpected relocation at offset %#" PRIx64
"\n"),
10145 if (rp
->r_offset
< word_offset
)
10148 /* PR 17531: file: 027-161405-0.004 */
10149 if (aux
->symtab
== NULL
)
10152 if (arm_sec
->rel_type
== SHT_REL
)
10154 offset
= word
& 0x7fffffff;
10155 if (offset
& 0x40000000)
10156 offset
|= ~ (uint64_t) 0x7fffffff;
10158 else if (arm_sec
->rel_type
== SHT_RELA
)
10159 offset
= rp
->r_addend
;
10162 error (_("Unknown section relocation type %d encountered\n"),
10163 arm_sec
->rel_type
);
10167 /* PR 17531 file: 027-1241568-0.004. */
10168 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
10170 error (_("Bad symbol index in unwind relocation "
10171 "(%" PRIu64
" > %" PRIu64
")\n"),
10172 ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
10176 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
10177 offset
+= sym
->st_value
;
10178 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
10180 /* Check that we are processing the expected reloc type. */
10181 if (filedata
->file_header
.e_machine
== EM_ARM
)
10183 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
10184 if (relname
== NULL
)
10186 warn (_("Skipping unknown ARM relocation type: %d\n"),
10187 (int) ELF32_R_TYPE (rp
->r_info
));
10191 if (streq (relname
, "R_ARM_NONE"))
10194 if (! streq (relname
, "R_ARM_PREL31"))
10196 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
10200 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
10202 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
10203 if (relname
== NULL
)
10205 warn (_("Skipping unknown C6000 relocation type: %d\n"),
10206 (int) ELF32_R_TYPE (rp
->r_info
));
10210 if (streq (relname
, "R_C6000_NONE"))
10213 if (! streq (relname
, "R_C6000_PREL31"))
10215 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
10223 /* This function currently only supports ARM and TI unwinders. */
10224 warn (_("Only TI and ARM unwinders are currently supported\n"));
10228 word
= (word
& ~ (uint64_t) 0x7fffffff) | (prelval
& 0x7fffffff);
10229 addr
->section
= sym
->st_shndx
;
10230 addr
->offset
= offset
;
10233 * sym_name
= sym
->st_name
;
10238 arm_sec
->next_rela
= rp
;
10243 static const char *tic6x_unwind_regnames
[16] =
10245 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
10246 "A14", "A13", "A12", "A11", "A10",
10247 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
10251 decode_tic6x_unwind_regmask (unsigned int mask
)
10255 for (i
= 12; mask
; mask
>>= 1, i
--)
10259 fputs (tic6x_unwind_regnames
[i
], stdout
);
10261 fputs (", ", stdout
);
10267 if (remaining == 0 && more_words) \
10269 data_offset += 4; \
10270 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
10271 data_offset, & word, & addr, NULL)) \
10277 #define GET_OP(OP) \
10282 (OP) = word >> 24; \
10287 printf (_("[Truncated opcode]\n")); \
10290 printf ("0x%02x ", OP)
10293 decode_arm_unwind_bytecode (Filedata
* filedata
,
10294 struct arm_unw_aux_info
* aux
,
10296 unsigned int remaining
,
10297 unsigned int more_words
,
10298 uint64_t data_offset
,
10299 Elf_Internal_Shdr
* data_sec
,
10300 struct arm_section
* data_arm_sec
)
10302 struct absaddr addr
;
10305 /* Decode the unwinding instructions. */
10308 unsigned int op
, op2
;
10311 if (remaining
== 0)
10317 printf (" 0x%02x ", op
);
10319 if ((op
& 0xc0) == 0x00)
10321 int offset
= ((op
& 0x3f) << 2) + 4;
10323 printf (" vsp = vsp + %d", offset
);
10325 else if ((op
& 0xc0) == 0x40)
10327 int offset
= ((op
& 0x3f) << 2) + 4;
10329 printf (" vsp = vsp - %d", offset
);
10331 else if ((op
& 0xf0) == 0x80)
10334 if (op
== 0x80 && op2
== 0)
10335 printf (_("Refuse to unwind"));
10338 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
10343 for (i
= 0; i
< 12; i
++)
10344 if (mask
& (1 << i
))
10350 printf ("r%d", 4 + i
);
10355 else if ((op
& 0xf0) == 0x90)
10357 if (op
== 0x9d || op
== 0x9f)
10358 printf (_(" [Reserved]"));
10360 printf (" vsp = r%d", op
& 0x0f);
10362 else if ((op
& 0xf0) == 0xa0)
10364 int end
= 4 + (op
& 0x07);
10369 for (i
= 4; i
<= end
; i
++)
10385 else if (op
== 0xb0)
10386 printf (_(" finish"));
10387 else if (op
== 0xb1)
10390 if (op2
== 0 || (op2
& 0xf0) != 0)
10391 printf (_("[Spare]"));
10394 unsigned int mask
= op2
& 0x0f;
10399 for (i
= 0; i
< 12; i
++)
10400 if (mask
& (1 << i
))
10411 else if (op
== 0xb2)
10413 unsigned char buf
[9];
10414 unsigned int i
, len
;
10417 for (i
= 0; i
< sizeof (buf
); i
++)
10420 if ((buf
[i
] & 0x80) == 0)
10423 if (i
== sizeof (buf
))
10425 error (_("corrupt change to vsp\n"));
10430 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
10431 assert (len
== i
+ 1);
10432 offset
= offset
* 4 + 0x204;
10433 printf ("vsp = vsp + %" PRId64
, offset
);
10436 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
10438 unsigned int first
, last
;
10444 first
= first
+ 16;
10445 printf ("pop {D%d", first
);
10447 printf ("-D%d", first
+ last
);
10450 else if (op
== 0xb4)
10451 printf (_(" pop {ra_auth_code}"));
10452 else if (op
== 0xb5)
10453 printf (_(" vsp as modifier for PAC validation"));
10454 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
10456 unsigned int count
= op
& 0x07;
10458 printf ("pop {D8");
10460 printf ("-D%d", 8 + count
);
10463 else if (op
>= 0xc0 && op
<= 0xc5)
10465 unsigned int count
= op
& 0x07;
10467 printf (" pop {wR10");
10469 printf ("-wR%d", 10 + count
);
10472 else if (op
== 0xc6)
10474 unsigned int first
, last
;
10479 printf ("pop {wR%d", first
);
10481 printf ("-wR%d", first
+ last
);
10484 else if (op
== 0xc7)
10487 if (op2
== 0 || (op2
& 0xf0) != 0)
10488 printf (_("[Spare]"));
10491 unsigned int mask
= op2
& 0x0f;
10496 for (i
= 0; i
< 4; i
++)
10497 if (mask
& (1 << i
))
10503 printf ("wCGR%d", i
);
10510 printf (_(" [unsupported opcode]"));
10521 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
10522 struct arm_unw_aux_info
* aux
,
10524 unsigned int remaining
,
10525 unsigned int more_words
,
10526 uint64_t data_offset
,
10527 Elf_Internal_Shdr
* data_sec
,
10528 struct arm_section
* data_arm_sec
)
10530 struct absaddr addr
;
10532 /* Decode the unwinding instructions. */
10535 unsigned int op
, op2
;
10538 if (remaining
== 0)
10544 printf (" 0x%02x ", op
);
10546 if ((op
& 0xc0) == 0x00)
10548 int offset
= ((op
& 0x3f) << 3) + 8;
10549 printf (" sp = sp + %d", offset
);
10551 else if ((op
& 0xc0) == 0x80)
10554 if (op
== 0x80 && op2
== 0)
10555 printf (_("Refuse to unwind"));
10558 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
10560 printf ("pop compact {");
10564 decode_tic6x_unwind_regmask (mask
);
10568 else if ((op
& 0xf0) == 0xc0)
10571 unsigned int nregs
;
10576 unsigned int offset
;
10580 /* Scan entire instruction first so that GET_OP output is not
10581 interleaved with disassembly. */
10583 for (i
= 0; nregs
< (op
& 0xf); i
++)
10589 regpos
[nregs
].offset
= i
* 2;
10590 regpos
[nregs
].reg
= reg
;
10597 regpos
[nregs
].offset
= i
* 2 + 1;
10598 regpos
[nregs
].reg
= reg
;
10603 printf (_("pop frame {"));
10606 printf (_("*corrupt* - no registers specified"));
10611 for (i
= i
* 2; i
> 0; i
--)
10613 if (regpos
[reg
].offset
== i
- 1)
10615 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
10622 fputs (name
, stdout
);
10630 else if (op
== 0xd0)
10631 printf (" MOV FP, SP");
10632 else if (op
== 0xd1)
10633 printf (" __c6xabi_pop_rts");
10634 else if (op
== 0xd2)
10636 unsigned char buf
[9];
10637 unsigned int i
, len
;
10640 for (i
= 0; i
< sizeof (buf
); i
++)
10643 if ((buf
[i
] & 0x80) == 0)
10646 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
10647 if (i
== sizeof (buf
))
10649 warn (_("Corrupt stack pointer adjustment detected\n"));
10653 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
10654 assert (len
== i
+ 1);
10655 offset
= offset
* 8 + 0x408;
10656 printf (_("sp = sp + %" PRId64
), offset
);
10658 else if ((op
& 0xf0) == 0xe0)
10660 if ((op
& 0x0f) == 7)
10661 printf (" RETURN");
10663 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
10667 printf (_(" [unsupported opcode]"));
10676 arm_expand_prel31 (Filedata
* filedata
, uint64_t word
, uint64_t where
)
10680 offset
= word
& 0x7fffffff;
10681 if (offset
& 0x40000000)
10682 offset
|= ~ (uint64_t) 0x7fffffff;
10684 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
10687 return offset
+ where
;
10691 decode_arm_unwind (Filedata
* filedata
,
10692 struct arm_unw_aux_info
* aux
,
10694 unsigned int remaining
,
10695 uint64_t data_offset
,
10696 Elf_Internal_Shdr
* data_sec
,
10697 struct arm_section
* data_arm_sec
)
10700 unsigned int more_words
= 0;
10701 struct absaddr addr
;
10702 uint64_t sym_name
= (uint64_t) -1;
10705 if (remaining
== 0)
10707 /* Fetch the first word.
10708 Note - when decoding an object file the address extracted
10709 here will always be 0. So we also pass in the sym_name
10710 parameter so that we can find the symbol associated with
10711 the personality routine. */
10712 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
10713 & word
, & addr
, & sym_name
))
10720 addr
.section
= SHN_UNDEF
;
10724 if ((word
& 0x80000000) == 0)
10726 /* Expand prel31 for personality routine. */
10728 const char *procname
;
10730 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
10731 printf (_(" Personality routine: "));
10733 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
10734 && sym_name
!= (uint64_t) -1 && sym_name
< aux
->strtab_size
)
10736 procname
= aux
->strtab
+ sym_name
;
10737 print_vma (fn
, PREFIX_HEX
);
10740 fputs (" <", stdout
);
10741 fputs (procname
, stdout
);
10742 fputc ('>', stdout
);
10746 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
10747 fputc ('\n', stdout
);
10749 /* The GCC personality routines use the standard compact
10750 encoding, starting with one byte giving the number of
10752 if (procname
!= NULL
10753 && (startswith (procname
, "__gcc_personality_v0")
10754 || startswith (procname
, "__gxx_personality_v0")
10755 || startswith (procname
, "__gcj_personality_v0")
10756 || startswith (procname
, "__gnu_objc_personality_v0")))
10763 printf (_(" [Truncated data]\n"));
10766 more_words
= word
>> 24;
10776 /* ARM EHABI Section 6.3:
10778 An exception-handling table entry for the compact model looks like:
10780 31 30-28 27-24 23-0
10781 -- ----- ----- ----
10782 1 0 index Data for personalityRoutine[index] */
10784 if (filedata
->file_header
.e_machine
== EM_ARM
10785 && (word
& 0x70000000))
10787 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
10791 per_index
= (word
>> 24) & 0x7f;
10792 printf (_(" Compact model index: %d\n"), per_index
);
10793 if (per_index
== 0)
10799 else if (per_index
< 3)
10801 more_words
= (word
>> 16) & 0xff;
10807 switch (filedata
->file_header
.e_machine
)
10812 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10813 data_offset
, data_sec
, data_arm_sec
))
10818 warn (_("Unknown ARM compact model index encountered\n"));
10819 printf (_(" [reserved]\n"));
10827 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10828 data_offset
, data_sec
, data_arm_sec
))
10831 else if (per_index
< 5)
10833 if (((word
>> 17) & 0x7f) == 0x7f)
10834 printf (_(" Restore stack from frame pointer\n"));
10836 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
10837 printf (_(" Registers restored: "));
10838 if (per_index
== 4)
10839 printf (" (compact) ");
10840 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
10842 printf (_(" Return register: %s\n"),
10843 tic6x_unwind_regnames
[word
& 0xf]);
10846 printf (_(" [reserved (%d)]\n"), per_index
);
10850 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
10851 filedata
->file_header
.e_machine
);
10855 /* Decode the descriptors. Not implemented. */
10861 dump_arm_unwind (Filedata
* filedata
,
10862 struct arm_unw_aux_info
* aux
,
10863 Elf_Internal_Shdr
* exidx_sec
)
10865 struct arm_section exidx_arm_sec
, extab_arm_sec
;
10866 unsigned int i
, exidx_len
;
10870 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
10871 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
10872 exidx_len
= exidx_sec
->sh_size
/ 8;
10874 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
10875 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
10876 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
10877 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
10878 aux
->nfuns
= nfuns
;
10879 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
10881 for (i
= 0; i
< exidx_len
; i
++)
10883 unsigned int exidx_fn
, exidx_entry
;
10884 struct absaddr fn_addr
, entry_addr
;
10887 fputc ('\n', stdout
);
10889 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10890 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
10891 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10892 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
10894 free (aux
->funtab
);
10895 arm_free_section (& exidx_arm_sec
);
10896 arm_free_section (& extab_arm_sec
);
10900 /* ARM EHABI, Section 5:
10901 An index table entry consists of 2 words.
10902 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
10903 if (exidx_fn
& 0x80000000)
10905 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
10909 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
10911 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
10912 fputs (": ", stdout
);
10914 if (exidx_entry
== 1)
10916 print_vma (exidx_entry
, PREFIX_HEX
);
10917 fputs (" [cantunwind]\n", stdout
);
10919 else if (exidx_entry
& 0x80000000)
10921 print_vma (exidx_entry
, PREFIX_HEX
);
10922 fputc ('\n', stdout
);
10923 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
10927 uint64_t table
, table_offset
= 0;
10928 Elf_Internal_Shdr
*table_sec
;
10930 fputs ("@", stdout
);
10931 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
10932 print_vma (table
, PREFIX_HEX
);
10935 /* Locate the matching .ARM.extab. */
10936 if (entry_addr
.section
!= SHN_UNDEF
10937 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
10939 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
10940 table_offset
= entry_addr
.offset
;
10942 if (table_offset
> table_sec
->sh_size
)
10944 warn (_("Unwind entry contains corrupt offset (%#" PRIx64
") into section %s\n"),
10946 printable_section_name (filedata
, table_sec
));
10953 table_sec
= find_section_by_address (filedata
, table
);
10954 if (table_sec
!= NULL
)
10955 table_offset
= table
- table_sec
->sh_addr
;
10958 if (table_sec
== NULL
)
10960 warn (_("Could not locate .ARM.extab section containing %#" PRIx64
".\n"),
10966 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
10974 free (aux
->funtab
);
10975 arm_free_section (&exidx_arm_sec
);
10976 arm_free_section (&extab_arm_sec
);
10981 /* Used for both ARM and C6X unwinding tables. */
10984 arm_process_unwind (Filedata
* filedata
)
10986 struct arm_unw_aux_info aux
;
10987 Elf_Internal_Shdr
*unwsec
= NULL
;
10988 Elf_Internal_Shdr
*sec
;
10990 unsigned int sec_type
;
10993 switch (filedata
->file_header
.e_machine
)
10996 sec_type
= SHT_ARM_EXIDX
;
11000 sec_type
= SHT_C6000_UNWIND
;
11004 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
11005 filedata
->file_header
.e_machine
);
11009 if (filedata
->string_table
== NULL
)
11012 memset (& aux
, 0, sizeof (aux
));
11013 aux
.filedata
= filedata
;
11015 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
11017 if (sec
->sh_type
== SHT_SYMTAB
)
11021 error (_("Multiple symbol tables encountered\n"));
11027 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
11028 &aux
.strtab
, &aux
.strtab_size
))
11031 else if (sec
->sh_type
== sec_type
)
11035 if (unwsec
== NULL
)
11036 printf (_("\nThere are no unwind sections in this file.\n"));
11038 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
11040 if (sec
->sh_type
== sec_type
)
11042 uint64_t num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
11043 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
11044 "contains %" PRIu64
" entry:\n",
11045 "\nUnwind section '%s' at offset %#" PRIx64
" "
11046 "contains %" PRIu64
" entries:\n",
11048 printable_section_name (filedata
, sec
),
11052 if (! dump_arm_unwind (filedata
, &aux
, sec
))
11058 free ((char *) aux
.strtab
);
11064 no_processor_specific_unwind (Filedata
* filedata ATTRIBUTE_UNUSED
)
11066 printf (_("No processor specific unwind information to decode\n"));
11071 process_unwind (Filedata
* filedata
)
11073 struct unwind_handler
11075 unsigned int machtype
;
11076 bool (* handler
)(Filedata
*);
11079 { EM_ARM
, arm_process_unwind
},
11080 { EM_IA_64
, ia64_process_unwind
},
11081 { EM_PARISC
, hppa_process_unwind
},
11082 { EM_TI_C6000
, arm_process_unwind
},
11083 { EM_386
, no_processor_specific_unwind
},
11084 { EM_X86_64
, no_processor_specific_unwind
},
11092 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
11093 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
11094 return handlers
[i
].handler (filedata
);
11096 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
11097 get_machine_name (filedata
->file_header
.e_machine
));
11102 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
11104 switch (entry
->d_tag
)
11106 case DT_AARCH64_BTI_PLT
:
11107 case DT_AARCH64_PAC_PLT
:
11110 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11117 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
11119 switch (entry
->d_tag
)
11121 case DT_MIPS_FLAGS
:
11122 if (entry
->d_un
.d_val
== 0)
11123 printf (_("NONE"));
11126 static const char * opts
[] =
11128 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
11129 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
11130 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
11131 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
11137 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
11138 if (entry
->d_un
.d_val
& (1 << cnt
))
11140 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
11146 case DT_MIPS_IVERSION
:
11147 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11148 printf (_("Interface Version: %s"),
11149 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
11151 printf (_("Interface Version: <corrupt: %" PRIx64
">"),
11152 entry
->d_un
.d_ptr
);
11155 case DT_MIPS_TIME_STAMP
:
11159 time_t atime
= entry
->d_un
.d_val
;
11161 tmp
= gmtime (&atime
);
11162 /* PR 17531: file: 6accc532. */
11164 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
11166 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
11167 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11168 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11169 printf (_("Time Stamp: %s"), timebuf
);
11173 case DT_MIPS_RLD_VERSION
:
11174 case DT_MIPS_LOCAL_GOTNO
:
11175 case DT_MIPS_CONFLICTNO
:
11176 case DT_MIPS_LIBLISTNO
:
11177 case DT_MIPS_SYMTABNO
:
11178 case DT_MIPS_UNREFEXTNO
:
11179 case DT_MIPS_HIPAGENO
:
11180 case DT_MIPS_DELTA_CLASS_NO
:
11181 case DT_MIPS_DELTA_INSTANCE_NO
:
11182 case DT_MIPS_DELTA_RELOC_NO
:
11183 case DT_MIPS_DELTA_SYM_NO
:
11184 case DT_MIPS_DELTA_CLASSSYM_NO
:
11185 case DT_MIPS_COMPACT_SIZE
:
11186 print_vma (entry
->d_un
.d_val
, DEC
);
11189 case DT_MIPS_XHASH
:
11190 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
11191 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11192 /* Falls through. */
11195 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11201 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
11203 switch (entry
->d_tag
)
11205 case DT_HP_DLD_FLAGS
:
11214 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
11215 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
11216 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
11217 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
11218 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
11219 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
11220 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
11221 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
11222 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
11223 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
11224 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
11225 { DT_HP_GST
, "HP_GST" },
11226 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
11227 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
11228 { DT_HP_NODELETE
, "HP_NODELETE" },
11229 { DT_HP_GROUP
, "HP_GROUP" },
11230 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
11234 uint64_t val
= entry
->d_un
.d_val
;
11236 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
11237 if (val
& flags
[cnt
].bit
)
11241 fputs (flags
[cnt
].str
, stdout
);
11243 val
^= flags
[cnt
].bit
;
11246 if (val
!= 0 || first
)
11250 print_vma (val
, HEX
);
11256 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11262 /* VMS vs Unix time offset and factor. */
11264 #define VMS_EPOCH_OFFSET 35067168000000000LL
11265 #define VMS_GRANULARITY_FACTOR 10000000
11267 #define INT64_MIN (-9223372036854775807LL - 1)
11270 /* Display a VMS time in a human readable format. */
11273 print_vms_time (int64_t vmstime
)
11275 struct tm
*tm
= NULL
;
11278 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
11280 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
11282 if (unxtime
== vmstime
)
11283 tm
= gmtime (&unxtime
);
11286 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
11287 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
11288 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
11292 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
11294 switch (entry
->d_tag
)
11296 case DT_IA_64_PLT_RESERVE
:
11297 /* First 3 slots reserved. */
11298 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11300 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
11303 case DT_IA_64_VMS_LINKTIME
:
11304 print_vms_time (entry
->d_un
.d_val
);
11307 case DT_IA_64_VMS_LNKFLAGS
:
11308 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11309 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
11310 printf (" CALL_DEBUG");
11311 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
11312 printf (" NOP0BUFS");
11313 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
11314 printf (" P0IMAGE");
11315 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
11316 printf (" MKTHREADS");
11317 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
11318 printf (" UPCALLS");
11319 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
11320 printf (" IMGSTA");
11321 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
11322 printf (" INITIALIZE");
11323 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
11325 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
11326 printf (" EXE_INIT");
11327 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
11328 printf (" TBK_IN_IMG");
11329 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
11330 printf (" DBG_IN_IMG");
11331 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
11332 printf (" TBK_IN_DSF");
11333 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
11334 printf (" DBG_IN_DSF");
11335 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
11336 printf (" SIGNATURES");
11337 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
11338 printf (" REL_SEG_OFF");
11342 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11349 get_32bit_dynamic_section (Filedata
* filedata
)
11351 Elf32_External_Dyn
* edyn
;
11352 Elf32_External_Dyn
* ext
;
11353 Elf_Internal_Dyn
* entry
;
11355 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
11356 filedata
->dynamic_addr
, 1,
11357 filedata
->dynamic_size
,
11358 _("dynamic section"));
11362 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
11363 might not have the luxury of section headers. Look for the DT_NULL
11364 terminator to determine the number of entries. */
11365 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
11366 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
11369 filedata
->dynamic_nent
++;
11370 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
11374 filedata
->dynamic_section
11375 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
11376 if (filedata
->dynamic_section
== NULL
)
11378 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
11379 filedata
->dynamic_nent
);
11384 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
11385 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11388 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
11389 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
11398 get_64bit_dynamic_section (Filedata
* filedata
)
11400 Elf64_External_Dyn
* edyn
;
11401 Elf64_External_Dyn
* ext
;
11402 Elf_Internal_Dyn
* entry
;
11404 /* Read in the data. */
11405 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
11406 filedata
->dynamic_addr
, 1,
11407 filedata
->dynamic_size
,
11408 _("dynamic section"));
11412 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
11413 might not have the luxury of section headers. Look for the DT_NULL
11414 terminator to determine the number of entries. */
11415 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
11416 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
11417 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
11420 filedata
->dynamic_nent
++;
11421 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
11425 filedata
->dynamic_section
11426 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
11427 if (filedata
->dynamic_section
== NULL
)
11429 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
11430 filedata
->dynamic_nent
);
11435 /* Convert from external to internal formats. */
11436 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
11437 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11440 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
11441 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
11450 get_dynamic_section (Filedata
*filedata
)
11452 if (filedata
->dynamic_section
)
11456 return get_32bit_dynamic_section (filedata
);
11458 return get_64bit_dynamic_section (filedata
);
11462 print_dynamic_flags (uint64_t flags
)
11470 flag
= flags
& - flags
;
11476 putc (' ', stdout
);
11480 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
11481 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
11482 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
11483 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
11484 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
11485 default: fputs (_("unknown"), stdout
); break;
11492 get_dynamic_data (Filedata
* filedata
, uint64_t number
, unsigned int ent_size
)
11494 unsigned char * e_data
;
11497 /* If size_t is smaller than uint64_t, eg because you are building
11498 on a 32-bit host, then make sure that when number is cast to
11499 size_t no information is lost. */
11500 if ((size_t) number
!= number
11501 || ent_size
* number
/ ent_size
!= number
)
11503 error (_("Size overflow prevents reading %" PRIu64
11504 " elements of size %u\n"),
11509 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
11510 attempting to allocate memory when the read is bound to fail. */
11511 if (ent_size
* number
> filedata
->file_size
)
11513 error (_("Invalid number of dynamic entries: %" PRIu64
"\n"),
11518 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
11519 if (e_data
== NULL
)
11521 error (_("Out of memory reading %" PRIu64
" dynamic entries\n"),
11526 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
11528 error (_("Unable to read in %" PRIu64
" bytes of dynamic data\n"),
11529 number
* ent_size
);
11534 i_data
= (uint64_t *) cmalloc ((size_t) number
, sizeof (*i_data
));
11535 if (i_data
== NULL
)
11537 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
11544 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
11552 get_num_dynamic_syms (Filedata
* filedata
)
11554 uint64_t num_of_syms
= 0;
11556 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
11557 return num_of_syms
;
11559 if (filedata
->dynamic_info
[DT_HASH
])
11561 unsigned char nb
[8];
11562 unsigned char nc
[8];
11563 unsigned int hash_ent_size
= 4;
11565 if ((filedata
->file_header
.e_machine
== EM_ALPHA
11566 || filedata
->file_header
.e_machine
== EM_S390
11567 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
11568 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
11571 if (fseek64 (filedata
->handle
,
11572 (filedata
->archive_file_offset
11573 + offset_from_vma (filedata
,
11574 filedata
->dynamic_info
[DT_HASH
],
11575 sizeof nb
+ sizeof nc
)),
11578 error (_("Unable to seek to start of dynamic information\n"));
11582 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
11584 error (_("Failed to read in number of buckets\n"));
11588 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
11590 error (_("Failed to read in number of chains\n"));
11594 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
11595 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
11597 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
11599 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
11601 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
11604 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
11605 num_of_syms
= filedata
->nchains
;
11608 if (num_of_syms
== 0)
11610 free (filedata
->buckets
);
11611 filedata
->buckets
= NULL
;
11612 free (filedata
->chains
);
11613 filedata
->chains
= NULL
;
11614 filedata
->nbuckets
= 0;
11618 if (filedata
->dynamic_info_DT_GNU_HASH
)
11620 unsigned char nb
[16];
11621 uint64_t i
, maxchain
= 0xffffffff, bitmaskwords
;
11622 uint64_t buckets_vma
;
11625 if (fseek64 (filedata
->handle
,
11626 (filedata
->archive_file_offset
11627 + offset_from_vma (filedata
,
11628 filedata
->dynamic_info_DT_GNU_HASH
,
11632 error (_("Unable to seek to start of dynamic information\n"));
11636 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
11638 error (_("Failed to read in number of buckets\n"));
11642 filedata
->ngnubuckets
= byte_get (nb
, 4);
11643 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
11644 bitmaskwords
= byte_get (nb
+ 8, 4);
11645 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
11647 buckets_vma
+= bitmaskwords
* 4;
11649 buckets_vma
+= bitmaskwords
* 8;
11651 if (fseek64 (filedata
->handle
,
11652 (filedata
->archive_file_offset
11653 + offset_from_vma (filedata
, buckets_vma
, 4)),
11656 error (_("Unable to seek to start of dynamic information\n"));
11660 filedata
->gnubuckets
11661 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
11663 if (filedata
->gnubuckets
== NULL
)
11666 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
11667 if (filedata
->gnubuckets
[i
] != 0)
11669 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
11672 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
11673 maxchain
= filedata
->gnubuckets
[i
];
11676 if (maxchain
== 0xffffffff)
11679 maxchain
-= filedata
->gnusymidx
;
11681 if (fseek64 (filedata
->handle
,
11682 (filedata
->archive_file_offset
11683 + offset_from_vma (filedata
,
11684 buckets_vma
+ 4 * (filedata
->ngnubuckets
11689 error (_("Unable to seek to start of dynamic information\n"));
11695 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
11697 error (_("Failed to determine last chain length\n"));
11701 if (maxchain
+ 1 == 0)
11706 while ((byte_get (nb
, 4) & 1) == 0);
11708 if (fseek64 (filedata
->handle
,
11709 (filedata
->archive_file_offset
11710 + offset_from_vma (filedata
, (buckets_vma
11711 + 4 * filedata
->ngnubuckets
),
11715 error (_("Unable to seek to start of dynamic information\n"));
11719 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
11720 filedata
->ngnuchains
= maxchain
;
11722 if (filedata
->gnuchains
== NULL
)
11725 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11727 if (fseek64 (filedata
->handle
,
11728 (filedata
->archive_file_offset
11729 + offset_from_vma (filedata
, (buckets_vma
11730 + 4 * (filedata
->ngnubuckets
11734 error (_("Unable to seek to start of dynamic information\n"));
11738 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
11739 if (filedata
->mipsxlat
== NULL
)
11743 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
11744 if (filedata
->gnubuckets
[hn
] != 0)
11746 uint64_t si
= filedata
->gnubuckets
[hn
];
11747 uint64_t off
= si
- filedata
->gnusymidx
;
11751 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11753 if (off
< filedata
->ngnuchains
11754 && filedata
->mipsxlat
[off
] >= num_of_syms
)
11755 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
11759 if (si
>= num_of_syms
)
11760 num_of_syms
= si
+ 1;
11764 while (off
< filedata
->ngnuchains
11765 && (filedata
->gnuchains
[off
++] & 1) == 0);
11768 if (num_of_syms
== 0)
11771 free (filedata
->mipsxlat
);
11772 filedata
->mipsxlat
= NULL
;
11773 free (filedata
->gnuchains
);
11774 filedata
->gnuchains
= NULL
;
11775 free (filedata
->gnubuckets
);
11776 filedata
->gnubuckets
= NULL
;
11777 filedata
->ngnubuckets
= 0;
11778 filedata
->ngnuchains
= 0;
11782 return num_of_syms
;
11785 /* Parse and display the contents of the dynamic section. */
11788 process_dynamic_section (Filedata
* filedata
)
11790 Elf_Internal_Dyn
* entry
;
11792 if (filedata
->dynamic_size
<= 1)
11796 if (filedata
->is_separate
)
11797 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
11798 filedata
->file_name
);
11800 printf (_("\nThere is no dynamic section in this file.\n"));
11806 if (!get_dynamic_section (filedata
))
11809 /* Find the appropriate symbol table. */
11810 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
11812 uint64_t num_of_syms
;
11814 for (entry
= filedata
->dynamic_section
;
11815 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11817 if (entry
->d_tag
== DT_SYMTAB
)
11818 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
11819 else if (entry
->d_tag
== DT_SYMENT
)
11820 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
11821 else if (entry
->d_tag
== DT_HASH
)
11822 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
11823 else if (entry
->d_tag
== DT_GNU_HASH
)
11824 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11825 else if ((filedata
->file_header
.e_machine
== EM_MIPS
11826 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
11827 && entry
->d_tag
== DT_MIPS_XHASH
)
11829 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
11830 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11833 num_of_syms
= get_num_dynamic_syms (filedata
);
11835 if (num_of_syms
!= 0
11836 && filedata
->dynamic_symbols
== NULL
11837 && filedata
->dynamic_info
[DT_SYMTAB
]
11838 && filedata
->dynamic_info
[DT_SYMENT
])
11840 Elf_Internal_Phdr
*seg
;
11841 uint64_t vma
= filedata
->dynamic_info
[DT_SYMTAB
];
11843 if (! get_program_headers (filedata
))
11845 error (_("Cannot interpret virtual addresses "
11846 "without program headers.\n"));
11850 for (seg
= filedata
->program_headers
;
11851 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
11854 if (seg
->p_type
!= PT_LOAD
)
11857 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
11859 /* See PR 21379 for a reproducer. */
11860 error (_("Invalid PT_LOAD entry\n"));
11864 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
11865 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
11867 /* Since we do not know how big the symbol table is,
11868 we default to reading in up to the end of PT_LOAD
11869 segment and processing that. This is overkill, I
11870 know, but it should work. */
11871 Elf_Internal_Shdr section
;
11872 section
.sh_offset
= (vma
- seg
->p_vaddr
11874 section
.sh_size
= (num_of_syms
11875 * filedata
->dynamic_info
[DT_SYMENT
]);
11876 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
11879 && filedata
->dynamic_symtab_section
!= NULL
11880 && ((filedata
->dynamic_symtab_section
->sh_offset
11881 != section
.sh_offset
)
11882 || (filedata
->dynamic_symtab_section
->sh_size
11883 != section
.sh_size
)
11884 || (filedata
->dynamic_symtab_section
->sh_entsize
11885 != section
.sh_entsize
)))
11887 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
11889 section
.sh_name
= filedata
->string_table_length
;
11890 filedata
->dynamic_symbols
11891 = get_elf_symbols (filedata
, §ion
,
11892 &filedata
->num_dynamic_syms
);
11893 if (filedata
->dynamic_symbols
== NULL
11894 || filedata
->num_dynamic_syms
!= num_of_syms
)
11896 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
11905 /* Similarly find a string table. */
11906 if (filedata
->dynamic_strings
== NULL
)
11907 for (entry
= filedata
->dynamic_section
;
11908 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11911 if (entry
->d_tag
== DT_STRTAB
)
11912 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
11914 if (entry
->d_tag
== DT_STRSZ
)
11915 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
11917 if (filedata
->dynamic_info
[DT_STRTAB
]
11918 && filedata
->dynamic_info
[DT_STRSZ
])
11921 uint64_t str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
11923 offset
= offset_from_vma (filedata
,
11924 filedata
->dynamic_info
[DT_STRTAB
],
11927 && filedata
->dynamic_strtab_section
11928 && ((filedata
->dynamic_strtab_section
->sh_offset
11929 != (file_ptr
) offset
)
11930 || (filedata
->dynamic_strtab_section
->sh_size
11933 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
11935 filedata
->dynamic_strings
11936 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
11937 _("dynamic string table"));
11938 if (filedata
->dynamic_strings
== NULL
)
11940 error (_("Corrupt DT_STRTAB dynamic entry\n"));
11944 filedata
->dynamic_strings_length
= str_tab_len
;
11949 /* And find the syminfo section if available. */
11950 if (filedata
->dynamic_syminfo
== NULL
)
11952 uint64_t syminsz
= 0;
11954 for (entry
= filedata
->dynamic_section
;
11955 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11958 if (entry
->d_tag
== DT_SYMINENT
)
11960 /* Note: these braces are necessary to avoid a syntax
11961 error from the SunOS4 C compiler. */
11962 /* PR binutils/17531: A corrupt file can trigger this test.
11963 So do not use an assert, instead generate an error message. */
11964 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
11965 error (_("Bad value (%d) for SYMINENT entry\n"),
11966 (int) entry
->d_un
.d_val
);
11968 else if (entry
->d_tag
== DT_SYMINSZ
)
11969 syminsz
= entry
->d_un
.d_val
;
11970 else if (entry
->d_tag
== DT_SYMINFO
)
11971 filedata
->dynamic_syminfo_offset
11972 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
11975 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
11977 Elf_External_Syminfo
* extsyminfo
;
11978 Elf_External_Syminfo
* extsym
;
11979 Elf_Internal_Syminfo
* syminfo
;
11981 /* There is a syminfo section. Read the data. */
11982 extsyminfo
= (Elf_External_Syminfo
*)
11983 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
11984 1, syminsz
, _("symbol information"));
11988 if (filedata
->dynamic_syminfo
!= NULL
)
11990 error (_("Multiple dynamic symbol information sections found\n"));
11991 free (filedata
->dynamic_syminfo
);
11993 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
11994 if (filedata
->dynamic_syminfo
== NULL
)
11996 error (_("Out of memory allocating %" PRIu64
11997 " bytes for dynamic symbol info\n"),
12002 filedata
->dynamic_syminfo_nent
12003 = syminsz
/ sizeof (Elf_External_Syminfo
);
12004 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
12005 syminfo
< (filedata
->dynamic_syminfo
12006 + filedata
->dynamic_syminfo_nent
);
12007 ++syminfo
, ++extsym
)
12009 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
12010 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
12017 if (do_dynamic
&& filedata
->dynamic_addr
)
12019 if (filedata
->is_separate
)
12020 printf (ngettext ("\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
12021 "\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
12022 filedata
->dynamic_nent
),
12023 filedata
->file_name
,
12024 filedata
->dynamic_addr
,
12025 filedata
->dynamic_nent
);
12027 printf (ngettext ("\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
12028 "\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
12029 filedata
->dynamic_nent
),
12030 filedata
->dynamic_addr
,
12031 filedata
->dynamic_nent
);
12034 printf (_(" Tag Type Name/Value\n"));
12036 for (entry
= filedata
->dynamic_section
;
12037 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
12042 const char * dtype
;
12045 print_vma (entry
->d_tag
, FULL_HEX
);
12046 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
12047 printf (" (%s)%*s", dtype
,
12048 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
12051 switch (entry
->d_tag
)
12055 print_dynamic_flags (entry
->d_un
.d_val
);
12065 switch (entry
->d_tag
)
12068 printf (_("Auxiliary library"));
12072 printf (_("Filter library"));
12076 printf (_("Configuration file"));
12080 printf (_("Dependency audit library"));
12084 printf (_("Audit library"));
12088 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
12089 printf (": [%s]\n",
12090 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
12094 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12103 printf (_("Flags:"));
12105 if (entry
->d_un
.d_val
== 0)
12106 printf (_(" None\n"));
12109 uint64_t val
= entry
->d_un
.d_val
;
12111 if (val
& DTF_1_PARINIT
)
12113 printf (" PARINIT");
12114 val
^= DTF_1_PARINIT
;
12116 if (val
& DTF_1_CONFEXP
)
12118 printf (" CONFEXP");
12119 val
^= DTF_1_CONFEXP
;
12122 printf (" %" PRIx64
, val
);
12131 printf (_("Flags:"));
12133 if (entry
->d_un
.d_val
== 0)
12134 printf (_(" None\n"));
12137 uint64_t val
= entry
->d_un
.d_val
;
12139 if (val
& DF_P1_LAZYLOAD
)
12141 printf (" LAZYLOAD");
12142 val
^= DF_P1_LAZYLOAD
;
12144 if (val
& DF_P1_GROUPPERM
)
12146 printf (" GROUPPERM");
12147 val
^= DF_P1_GROUPPERM
;
12150 printf (" %" PRIx64
, val
);
12159 printf (_("Flags:"));
12160 if (entry
->d_un
.d_val
== 0)
12161 printf (_(" None\n"));
12164 uint64_t val
= entry
->d_un
.d_val
;
12166 if (val
& DF_1_NOW
)
12171 if (val
& DF_1_GLOBAL
)
12173 printf (" GLOBAL");
12174 val
^= DF_1_GLOBAL
;
12176 if (val
& DF_1_GROUP
)
12181 if (val
& DF_1_NODELETE
)
12183 printf (" NODELETE");
12184 val
^= DF_1_NODELETE
;
12186 if (val
& DF_1_LOADFLTR
)
12188 printf (" LOADFLTR");
12189 val
^= DF_1_LOADFLTR
;
12191 if (val
& DF_1_INITFIRST
)
12193 printf (" INITFIRST");
12194 val
^= DF_1_INITFIRST
;
12196 if (val
& DF_1_NOOPEN
)
12198 printf (" NOOPEN");
12199 val
^= DF_1_NOOPEN
;
12201 if (val
& DF_1_ORIGIN
)
12203 printf (" ORIGIN");
12204 val
^= DF_1_ORIGIN
;
12206 if (val
& DF_1_DIRECT
)
12208 printf (" DIRECT");
12209 val
^= DF_1_DIRECT
;
12211 if (val
& DF_1_TRANS
)
12216 if (val
& DF_1_INTERPOSE
)
12218 printf (" INTERPOSE");
12219 val
^= DF_1_INTERPOSE
;
12221 if (val
& DF_1_NODEFLIB
)
12223 printf (" NODEFLIB");
12224 val
^= DF_1_NODEFLIB
;
12226 if (val
& DF_1_NODUMP
)
12228 printf (" NODUMP");
12229 val
^= DF_1_NODUMP
;
12231 if (val
& DF_1_CONFALT
)
12233 printf (" CONFALT");
12234 val
^= DF_1_CONFALT
;
12236 if (val
& DF_1_ENDFILTEE
)
12238 printf (" ENDFILTEE");
12239 val
^= DF_1_ENDFILTEE
;
12241 if (val
& DF_1_DISPRELDNE
)
12243 printf (" DISPRELDNE");
12244 val
^= DF_1_DISPRELDNE
;
12246 if (val
& DF_1_DISPRELPND
)
12248 printf (" DISPRELPND");
12249 val
^= DF_1_DISPRELPND
;
12251 if (val
& DF_1_NODIRECT
)
12253 printf (" NODIRECT");
12254 val
^= DF_1_NODIRECT
;
12256 if (val
& DF_1_IGNMULDEF
)
12258 printf (" IGNMULDEF");
12259 val
^= DF_1_IGNMULDEF
;
12261 if (val
& DF_1_NOKSYMS
)
12263 printf (" NOKSYMS");
12264 val
^= DF_1_NOKSYMS
;
12266 if (val
& DF_1_NOHDR
)
12271 if (val
& DF_1_EDITED
)
12273 printf (" EDITED");
12274 val
^= DF_1_EDITED
;
12276 if (val
& DF_1_NORELOC
)
12278 printf (" NORELOC");
12279 val
^= DF_1_NORELOC
;
12281 if (val
& DF_1_SYMINTPOSE
)
12283 printf (" SYMINTPOSE");
12284 val
^= DF_1_SYMINTPOSE
;
12286 if (val
& DF_1_GLOBAUDIT
)
12288 printf (" GLOBAUDIT");
12289 val
^= DF_1_GLOBAUDIT
;
12291 if (val
& DF_1_SINGLETON
)
12293 printf (" SINGLETON");
12294 val
^= DF_1_SINGLETON
;
12296 if (val
& DF_1_STUB
)
12301 if (val
& DF_1_PIE
)
12306 if (val
& DF_1_KMOD
)
12311 if (val
& DF_1_WEAKFILTER
)
12313 printf (" WEAKFILTER");
12314 val
^= DF_1_WEAKFILTER
;
12316 if (val
& DF_1_NOCOMMON
)
12318 printf (" NOCOMMON");
12319 val
^= DF_1_NOCOMMON
;
12322 printf (" %" PRIx64
, val
);
12329 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
12331 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
12352 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
12358 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
12359 name
= get_dynamic_name (filedata
, entry
->d_un
.d_val
);
12365 switch (entry
->d_tag
)
12368 printf (_("Shared library: [%s]"), name
);
12370 if (filedata
->program_interpreter
12371 && streq (name
, filedata
->program_interpreter
))
12372 printf (_(" program interpreter"));
12376 printf (_("Library soname: [%s]"), name
);
12380 printf (_("Library rpath: [%s]"), name
);
12384 printf (_("Library runpath: [%s]"), name
);
12388 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12393 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12408 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
12409 /* Fall through. */
12413 case DT_PREINIT_ARRAYSZ
:
12414 case DT_INIT_ARRAYSZ
:
12415 case DT_FINI_ARRAYSZ
:
12416 case DT_GNU_CONFLICTSZ
:
12417 case DT_GNU_LIBLISTSZ
:
12420 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
12421 printf (_(" (bytes)\n"));
12426 case DT_VERNEEDNUM
:
12431 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
12440 case DT_INIT_ARRAY
:
12441 case DT_FINI_ARRAY
:
12444 if (entry
->d_tag
== DT_USED
12445 && valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
12448 = get_dynamic_name (filedata
, entry
->d_un
.d_val
);
12452 printf (_("Not needed object: [%s]\n"), name
);
12457 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12463 /* The value of this entry is ignored. */
12468 case DT_GNU_PRELINKED
:
12472 time_t atime
= entry
->d_un
.d_val
;
12474 tmp
= gmtime (&atime
);
12475 /* PR 17533 file: 041-1244816-0.004. */
12477 printf (_("<corrupt time val: %" PRIx64
),
12480 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
12481 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
12482 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
12488 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
12491 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12496 case DT_GNU_FLAGS_1
:
12499 printf (_("Flags:"));
12500 if (entry
->d_un
.d_val
== 0)
12501 printf (_(" None\n"));
12504 uint64_t val
= entry
->d_un
.d_val
;
12506 if (val
& DF_GNU_1_UNIQUE
)
12508 printf (" UNIQUE");
12509 val
^= DF_GNU_1_UNIQUE
;
12512 printf (" %" PRIx64
, val
);
12519 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
12520 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
12521 = entry
->d_un
.d_val
;
12525 switch (filedata
->file_header
.e_machine
)
12528 dynamic_section_aarch64_val (entry
);
12531 case EM_MIPS_RS3_LE
:
12532 dynamic_section_mips_val (filedata
, entry
);
12535 dynamic_section_parisc_val (entry
);
12538 dynamic_section_ia64_val (entry
);
12541 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12553 get_ver_flags (unsigned int flags
)
12555 static char buff
[128];
12562 if (flags
& VER_FLG_BASE
)
12563 strcat (buff
, "BASE");
12565 if (flags
& VER_FLG_WEAK
)
12567 if (flags
& VER_FLG_BASE
)
12568 strcat (buff
, " | ");
12570 strcat (buff
, "WEAK");
12573 if (flags
& VER_FLG_INFO
)
12575 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
12576 strcat (buff
, " | ");
12578 strcat (buff
, "INFO");
12581 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12583 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12584 strcat (buff
, " | ");
12586 strcat (buff
, _("<unknown>"));
12592 /* Display the contents of the version sections. */
12595 process_version_sections (Filedata
* filedata
)
12597 Elf_Internal_Shdr
* section
;
12599 bool found
= false;
12604 for (i
= 0, section
= filedata
->section_headers
;
12605 i
< filedata
->file_header
.e_shnum
;
12608 switch (section
->sh_type
)
12610 case SHT_GNU_verdef
:
12612 Elf_External_Verdef
* edefs
;
12619 if (filedata
->is_separate
)
12620 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
12621 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
12623 filedata
->file_name
,
12624 printable_section_name (filedata
, section
),
12627 printf (ngettext ("\nVersion definition section '%s' "
12628 "contains %u entry:\n",
12629 "\nVersion definition section '%s' "
12630 "contains %u entries:\n",
12632 printable_section_name (filedata
, section
),
12635 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12636 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12637 section
->sh_offset
, section
->sh_link
,
12638 printable_section_name_from_index (filedata
, section
->sh_link
, NULL
));
12640 edefs
= (Elf_External_Verdef
*)
12641 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
12642 _("version definition section"));
12645 endbuf
= (char *) edefs
+ section
->sh_size
;
12647 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12650 Elf_External_Verdef
* edef
;
12651 Elf_Internal_Verdef ent
;
12652 Elf_External_Verdaux
* eaux
;
12653 Elf_Internal_Verdaux aux
;
12657 vstart
= ((char *) edefs
) + idx
;
12658 if (vstart
+ sizeof (*edef
) > endbuf
)
12661 edef
= (Elf_External_Verdef
*) vstart
;
12663 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
12664 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
12665 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
12666 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
12667 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
12668 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
12669 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
12671 printf (_(" %#06zx: Rev: %d Flags: %s"),
12672 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
12674 printf (_(" Index: %d Cnt: %d "),
12675 ent
.vd_ndx
, ent
.vd_cnt
);
12677 /* Check for overflow. */
12678 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
12681 vstart
+= ent
.vd_aux
;
12683 if (vstart
+ sizeof (*eaux
) > endbuf
)
12685 eaux
= (Elf_External_Verdaux
*) vstart
;
12687 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12688 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12690 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12691 printf (_("Name: %s\n"),
12692 get_dynamic_name (filedata
, aux
.vda_name
));
12694 printf (_("Name index: %ld\n"), aux
.vda_name
);
12696 isum
= idx
+ ent
.vd_aux
;
12698 for (j
= 1; j
< ent
.vd_cnt
; j
++)
12700 if (aux
.vda_next
< sizeof (*eaux
)
12701 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
12703 warn (_("Invalid vda_next field of %lx\n"),
12708 /* Check for overflow. */
12709 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
12712 isum
+= aux
.vda_next
;
12713 vstart
+= aux
.vda_next
;
12715 if (vstart
+ sizeof (*eaux
) > endbuf
)
12717 eaux
= (Elf_External_Verdaux
*) vstart
;
12719 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12720 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12722 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12723 printf (_(" %#06zx: Parent %d: %s\n"),
12725 get_dynamic_name (filedata
, aux
.vda_name
));
12727 printf (_(" %#06zx: Parent %d, name index: %ld\n"),
12728 isum
, j
, aux
.vda_name
);
12731 if (j
< ent
.vd_cnt
)
12732 printf (_(" Version def aux past end of section\n"));
12735 file: id:000001,src:000172+005151,op:splice,rep:2. */
12736 if (ent
.vd_next
< sizeof (*edef
)
12737 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
12739 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
12740 cnt
= section
->sh_info
;
12743 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
12746 idx
+= ent
.vd_next
;
12749 if (cnt
< section
->sh_info
)
12750 printf (_(" Version definition past end of section\n"));
12756 case SHT_GNU_verneed
:
12758 Elf_External_Verneed
* eneed
;
12765 if (filedata
->is_separate
)
12766 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
12767 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
12769 filedata
->file_name
,
12770 printable_section_name (filedata
, section
),
12773 printf (ngettext ("\nVersion needs section '%s' "
12774 "contains %u entry:\n",
12775 "\nVersion needs section '%s' "
12776 "contains %u entries:\n",
12778 printable_section_name (filedata
, section
),
12781 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12782 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12783 section
->sh_offset
, section
->sh_link
,
12784 printable_section_name_from_index (filedata
, section
->sh_link
, NULL
));
12786 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
12787 section
->sh_offset
, 1,
12789 _("Version Needs section"));
12792 endbuf
= (char *) eneed
+ section
->sh_size
;
12794 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12796 Elf_External_Verneed
* entry
;
12797 Elf_Internal_Verneed ent
;
12802 vstart
= ((char *) eneed
) + idx
;
12803 if (vstart
+ sizeof (*entry
) > endbuf
)
12806 entry
= (Elf_External_Verneed
*) vstart
;
12808 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
12809 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
12810 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
12811 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
12812 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
12814 printf (_(" %#06zx: Version: %d"), idx
, ent
.vn_version
);
12816 if (valid_dynamic_name (filedata
, ent
.vn_file
))
12817 printf (_(" File: %s"),
12818 get_dynamic_name (filedata
, ent
.vn_file
));
12820 printf (_(" File: %lx"), ent
.vn_file
);
12822 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
12824 /* Check for overflow. */
12825 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
12827 vstart
+= ent
.vn_aux
;
12829 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
12831 Elf_External_Vernaux
* eaux
;
12832 Elf_Internal_Vernaux aux
;
12834 if (vstart
+ sizeof (*eaux
) > endbuf
)
12836 eaux
= (Elf_External_Vernaux
*) vstart
;
12838 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
12839 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
12840 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
12841 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
12842 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
12844 if (valid_dynamic_name (filedata
, aux
.vna_name
))
12845 printf (_(" %#06zx: Name: %s"),
12846 isum
, get_dynamic_name (filedata
, aux
.vna_name
));
12848 printf (_(" %#06zx: Name index: %lx"),
12849 isum
, aux
.vna_name
);
12851 printf (_(" Flags: %s Version: %d\n"),
12852 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
12854 if (aux
.vna_next
< sizeof (*eaux
)
12855 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
12857 warn (_("Invalid vna_next field of %lx\n"),
12862 /* Check for overflow. */
12863 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
12865 isum
+= aux
.vna_next
;
12866 vstart
+= aux
.vna_next
;
12869 if (j
< ent
.vn_cnt
)
12870 warn (_("Missing Version Needs auxiliary information\n"));
12872 if (ent
.vn_next
< sizeof (*entry
)
12873 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
12875 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
12876 cnt
= section
->sh_info
;
12879 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
12881 idx
+= ent
.vn_next
;
12884 if (cnt
< section
->sh_info
)
12885 warn (_("Missing Version Needs information\n"));
12891 case SHT_GNU_versym
:
12893 Elf_Internal_Shdr
* link_section
;
12896 unsigned char * edata
;
12897 unsigned short * data
;
12899 Elf_Internal_Sym
* symbols
;
12900 Elf_Internal_Shdr
* string_sec
;
12904 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
12907 link_section
= filedata
->section_headers
+ section
->sh_link
;
12908 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
12910 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
12915 symbols
= get_elf_symbols (filedata
, link_section
, & num_syms
);
12916 if (symbols
== NULL
)
12919 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
12921 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
12922 string_sec
->sh_size
,
12923 _("version string table"));
12930 if (filedata
->is_separate
)
12931 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entry:\n",
12932 "\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entries:\n",
12934 filedata
->file_name
,
12935 printable_section_name (filedata
, section
),
12938 printf (ngettext ("\nVersion symbols section '%s' "
12939 "contains %" PRIu64
" entry:\n",
12940 "\nVersion symbols section '%s' "
12941 "contains %" PRIu64
" entries:\n",
12943 printable_section_name (filedata
, section
),
12946 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12947 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12948 section
->sh_offset
, section
->sh_link
,
12949 printable_section_name (filedata
, link_section
));
12951 off
= offset_from_vma (filedata
,
12952 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12953 total
* sizeof (short));
12954 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
12955 sizeof (short), total
,
12956 _("version symbol data"));
12964 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
12966 for (cnt
= total
; cnt
--;)
12967 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
12972 for (cnt
= 0; cnt
< total
; cnt
+= 4)
12976 char *invalid
= _("*invalid*");
12978 printf (" %03x:", cnt
);
12980 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
12981 switch (data
[cnt
+ j
])
12984 fputs (_(" 0 (*local*) "), stdout
);
12988 fputs (_(" 1 (*global*) "), stdout
);
12992 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
12993 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
12995 /* If this index value is greater than the size of the symbols
12996 array, break to avoid an out-of-bounds read. */
12997 if (cnt
+ j
>= num_syms
)
12999 warn (_("invalid index into symbol array\n"));
13004 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
13006 Elf_Internal_Verneed ivn
;
13009 offset
= offset_from_vma
13011 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
13012 sizeof (Elf_External_Verneed
));
13016 Elf_Internal_Vernaux ivna
;
13017 Elf_External_Verneed evn
;
13018 Elf_External_Vernaux evna
;
13021 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
13022 _("version need")) == NULL
)
13025 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
13026 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
13028 a_off
= offset
+ ivn
.vn_aux
;
13032 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
13033 1, _("version need aux (2)")) == NULL
)
13036 ivna
.vna_other
= 0;
13040 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
13041 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
13044 a_off
+= ivna
.vna_next
;
13046 while (ivna
.vna_other
!= data
[cnt
+ j
]
13047 && ivna
.vna_next
!= 0);
13049 if (ivna
.vna_other
== data
[cnt
+ j
])
13051 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
13053 if (ivna
.vna_name
>= string_sec
->sh_size
)
13056 name
= strtab
+ ivna
.vna_name
;
13060 offset
+= ivn
.vn_next
;
13062 while (ivn
.vn_next
);
13065 if (data
[cnt
+ j
] != 0x8001
13066 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
13068 Elf_Internal_Verdef ivd
;
13069 Elf_External_Verdef evd
;
13072 offset
= offset_from_vma
13074 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
13079 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
13080 _("version def")) == NULL
)
13083 /* PR 17531: file: 046-1082287-0.004. */
13084 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
13089 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
13090 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
13093 offset
+= ivd
.vd_next
;
13095 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
13096 && ivd
.vd_next
!= 0);
13098 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
13100 Elf_External_Verdaux evda
;
13101 Elf_Internal_Verdaux ivda
;
13103 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
13105 if (get_data (&evda
, filedata
,
13106 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
13108 _("version def aux")) == NULL
)
13111 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
13113 if (ivda
.vda_name
>= string_sec
->sh_size
)
13115 else if (name
!= NULL
&& name
!= invalid
)
13116 name
= _("*both*");
13118 name
= strtab
+ ivda
.vda_name
;
13122 nn
+= printf ("(%s%-*s",
13124 12 - (int) strlen (name
),
13128 printf ("%*c", 18 - nn
, ' ');
13147 if (filedata
->is_separate
)
13148 printf (_("\nNo version information found in linked file '%s'.\n"),
13149 filedata
->file_name
);
13151 printf (_("\nNo version information found in this file.\n"));
13157 static const char *
13158 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
13160 static char buff
[64];
13164 case STB_LOCAL
: return "LOCAL";
13165 case STB_GLOBAL
: return "GLOBAL";
13166 case STB_WEAK
: return "WEAK";
13168 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
13169 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
13171 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
13173 if (binding
== STB_GNU_UNIQUE
13174 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
13176 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
13179 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
13184 static const char *
13185 get_symbol_type (Filedata
* filedata
, unsigned int type
)
13187 static char buff
[64];
13191 case STT_NOTYPE
: return "NOTYPE";
13192 case STT_OBJECT
: return "OBJECT";
13193 case STT_FUNC
: return "FUNC";
13194 case STT_SECTION
: return "SECTION";
13195 case STT_FILE
: return "FILE";
13196 case STT_COMMON
: return "COMMON";
13197 case STT_TLS
: return "TLS";
13198 case STT_RELC
: return "RELC";
13199 case STT_SRELC
: return "SRELC";
13201 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
13203 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
13204 return "THUMB_FUNC";
13206 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
13209 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
13210 return "PARISC_MILLI";
13212 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
13214 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
13216 if (filedata
->file_header
.e_machine
== EM_PARISC
)
13218 if (type
== STT_HP_OPAQUE
)
13219 return "HP_OPAQUE";
13220 if (type
== STT_HP_STUB
)
13224 if (type
== STT_GNU_IFUNC
13225 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
13226 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
13229 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
13232 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
13237 static const char *
13238 get_symbol_visibility (unsigned int visibility
)
13240 switch (visibility
)
13242 case STV_DEFAULT
: return "DEFAULT";
13243 case STV_INTERNAL
: return "INTERNAL";
13244 case STV_HIDDEN
: return "HIDDEN";
13245 case STV_PROTECTED
: return "PROTECTED";
13247 error (_("Unrecognized visibility value: %u\n"), visibility
);
13248 return _("<unknown>");
13252 static const char *
13253 get_alpha_symbol_other (unsigned int other
)
13257 case STO_ALPHA_NOPV
: return "NOPV";
13258 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
13260 error (_("Unrecognized alpha specific other value: %u\n"), other
);
13261 return _("<unknown>");
13265 static const char *
13266 get_solaris_symbol_visibility (unsigned int visibility
)
13268 switch (visibility
)
13270 case 4: return "EXPORTED";
13271 case 5: return "SINGLETON";
13272 case 6: return "ELIMINATE";
13273 default: return get_symbol_visibility (visibility
);
13277 static const char *
13278 get_aarch64_symbol_other (unsigned int other
)
13280 static char buf
[32];
13282 if (other
& STO_AARCH64_VARIANT_PCS
)
13284 other
&= ~STO_AARCH64_VARIANT_PCS
;
13286 return "VARIANT_PCS";
13287 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
13293 static const char *
13294 get_mips_symbol_other (unsigned int other
)
13298 case STO_OPTIONAL
: return "OPTIONAL";
13299 case STO_MIPS_PLT
: return "MIPS PLT";
13300 case STO_MIPS_PIC
: return "MIPS PIC";
13301 case STO_MICROMIPS
: return "MICROMIPS";
13302 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
13303 case STO_MIPS16
: return "MIPS16";
13304 default: return NULL
;
13308 static const char *
13309 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
13311 if (is_ia64_vms (filedata
))
13313 static char res
[32];
13317 /* Function types is for images and .STB files only. */
13318 switch (filedata
->file_header
.e_type
)
13322 switch (VMS_ST_FUNC_TYPE (other
))
13324 case VMS_SFT_CODE_ADDR
:
13325 strcat (res
, " CA");
13327 case VMS_SFT_SYMV_IDX
:
13328 strcat (res
, " VEC");
13331 strcat (res
, " FD");
13333 case VMS_SFT_RESERVE
:
13334 strcat (res
, " RSV");
13337 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
13338 VMS_ST_FUNC_TYPE (other
));
13339 strcat (res
, " <unknown>");
13346 switch (VMS_ST_LINKAGE (other
))
13348 case VMS_STL_IGNORE
:
13349 strcat (res
, " IGN");
13351 case VMS_STL_RESERVE
:
13352 strcat (res
, " RSV");
13355 strcat (res
, " STD");
13358 strcat (res
, " LNK");
13361 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
13362 VMS_ST_LINKAGE (other
));
13363 strcat (res
, " <unknown>");
13375 static const char *
13376 get_ppc64_symbol_other (unsigned int other
)
13378 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
13381 other
>>= STO_PPC64_LOCAL_BIT
;
13384 static char buf
[64];
13386 other
= ppc64_decode_local_entry (other
);
13387 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
13393 static const char *
13394 get_riscv_symbol_other (unsigned int other
)
13396 static char buf
[32];
13399 if (other
& STO_RISCV_VARIANT_CC
)
13401 strcat (buf
, _(" VARIANT_CC"));
13402 other
&= ~STO_RISCV_VARIANT_CC
;
13406 snprintf (buf
, sizeof buf
, " %x", other
);
13415 static const char *
13416 get_symbol_other (Filedata
* filedata
, unsigned int other
)
13418 const char * result
= NULL
;
13419 static char buff
[64];
13424 switch (filedata
->file_header
.e_machine
)
13427 result
= get_alpha_symbol_other (other
);
13430 result
= get_aarch64_symbol_other (other
);
13433 result
= get_mips_symbol_other (other
);
13436 result
= get_ia64_symbol_other (filedata
, other
);
13439 result
= get_ppc64_symbol_other (other
);
13442 result
= get_riscv_symbol_other (other
);
13452 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
13456 static const char *
13457 get_symbol_version_string (Filedata
*filedata
,
13459 const char *strtab
,
13460 size_t strtab_size
,
13462 Elf_Internal_Sym
*psym
,
13463 enum versioned_symbol_info
*sym_info
,
13464 unsigned short *vna_other
)
13466 unsigned char data
[2];
13467 unsigned short vers_data
;
13469 unsigned short max_vd_ndx
;
13472 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
13475 offset
= offset_from_vma (filedata
,
13476 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
13477 sizeof data
+ si
* sizeof (vers_data
));
13479 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
13480 sizeof (data
), 1, _("version data")) == NULL
)
13483 vers_data
= byte_get (data
, 2);
13485 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
13488 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
13491 /* Usually we'd only see verdef for defined symbols, and verneed for
13492 undefined symbols. However, symbols defined by the linker in
13493 .dynbss for variables copied from a shared library in order to
13494 avoid text relocations are defined yet have verneed. We could
13495 use a heuristic to detect the special case, for example, check
13496 for verneed first on symbols defined in SHT_NOBITS sections, but
13497 it is simpler and more reliable to just look for both verdef and
13498 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
13500 if (psym
->st_shndx
!= SHN_UNDEF
13501 && vers_data
!= 0x8001
13502 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
13504 Elf_Internal_Verdef ivd
;
13505 Elf_Internal_Verdaux ivda
;
13506 Elf_External_Verdaux evda
;
13509 off
= offset_from_vma (filedata
,
13510 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
13511 sizeof (Elf_External_Verdef
));
13515 Elf_External_Verdef evd
;
13517 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
13518 _("version def")) == NULL
)
13527 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
13528 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
13529 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
13530 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
13533 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
13534 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
13536 off
+= ivd
.vd_next
;
13538 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
13540 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
13542 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
13545 off
-= ivd
.vd_next
;
13548 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
13549 _("version def aux")) != NULL
)
13551 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
13553 if (psym
->st_name
!= ivda
.vda_name
)
13554 return (ivda
.vda_name
< strtab_size
13555 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
13560 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
13562 Elf_External_Verneed evn
;
13563 Elf_Internal_Verneed ivn
;
13564 Elf_Internal_Vernaux ivna
;
13566 offset
= offset_from_vma (filedata
,
13567 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
13573 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
13574 _("version need")) == NULL
)
13577 ivna
.vna_other
= 0;
13582 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
13583 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
13585 vna_off
= offset
+ ivn
.vn_aux
;
13589 Elf_External_Vernaux evna
;
13591 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
13592 _("version need aux (3)")) == NULL
)
13595 ivna
.vna_other
= 0;
13600 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
13601 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
13602 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
13605 vna_off
+= ivna
.vna_next
;
13607 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
13609 if (ivna
.vna_other
== vers_data
)
13612 offset
+= ivn
.vn_next
;
13614 while (ivn
.vn_next
!= 0);
13616 if (ivna
.vna_other
== vers_data
)
13618 *sym_info
= symbol_undefined
;
13619 *vna_other
= ivna
.vna_other
;
13620 return (ivna
.vna_name
< strtab_size
13621 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
13623 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
13624 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
13625 return _("<corrupt>");
13630 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
13632 static unsigned int
13633 print_symbol_size (uint64_t vma
, int base
)
13638 return print_vma (vma
, OCTAL_5
);
13641 return print_vma (vma
, UNSIGNED_5
);
13644 return print_vma (vma
, PREFIX_HEX_5
);
13648 return print_vma (vma
, DEC_5
);
13652 /* Print information on a single symbol. */
13655 print_symbol (Filedata
* filedata
,
13656 uint64_t symbol_index
,
13657 Elf_Internal_Sym
* symtab
,
13658 Elf_Internal_Shdr
* section
,
13660 size_t strtab_size
)
13662 const char *version_string
;
13663 enum versioned_symbol_info sym_info
;
13664 unsigned short vna_other
;
13666 Elf_Internal_Sym
*psym
= symtab
+ symbol_index
;
13668 /* FIXME: We should have a table of field widths,
13669 rather than using hard coded constants. */
13670 printf ("%6" PRId64
": ", symbol_index
);
13671 print_vma (psym
->st_value
, LONG_HEX
);
13673 print_symbol_size (psym
->st_size
, sym_base
);
13674 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
13675 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
13676 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
13677 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
13680 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
13682 printf (" %-7s", get_symbol_visibility (vis
));
13684 /* Check to see if any other bits in the st_other field are set.
13685 FIXME: Displaying this information here disrupts the layout
13686 of the table being generated. */
13687 if (psym
->st_other
^ vis
)
13688 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
13693 sstr
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
13695 /* Print the symbol's section index. If the index is special
13696 then print the index's name rather than its number. */
13701 /* Special case: If there are no section headers, and the printable
13702 name is "<section 0x...." then just display the section number
13703 as a decimal. This happens when objcopy --strip -section-headers
13705 if (filedata
->file_header
.e_shnum
== 0 && startswith (sstr
, "<section"))
13706 printed
= printf (" %4d ", psym
->st_shndx
);
13708 printed
= printf (" %4s ", sstr
);
13710 if (extra_sym_info
&& printed
< 16)
13711 printf ("%*s", 16 - printed
, "");
13715 printf (" %4u ", psym
->st_shndx
);
13717 if (extra_sym_info
)
13719 /* Display the section name referenced by the section index. */
13720 int printed
= printf ("(%s) ", sstr
);
13722 printf ("%*s", 10 - printed
, "");
13726 /* Get the symbol's name. For section symbols without a
13727 specific name use the (already computed) section name. */
13728 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
13729 && section_index_real (filedata
, psym
->st_shndx
)
13730 && psym
->st_name
== 0)
13738 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
13739 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
13743 = get_symbol_version_string (filedata
,
13745 || section
->sh_type
== SHT_DYNSYM
),
13746 strtab
, strtab_size
, symbol_index
,
13747 psym
, &sym_info
, &vna_other
);
13749 int len_avail
= 21;
13750 if (! do_wide
&& version_string
!= NULL
)
13754 len_avail
-= 1 + strlen (version_string
);
13756 if (sym_info
== symbol_undefined
)
13757 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
13758 else if (sym_info
!= symbol_hidden
)
13762 print_symbol_name (len_avail
, sstr
);
13764 if (version_string
)
13766 if (sym_info
== symbol_undefined
)
13767 printf ("@%s (%d)", version_string
, vna_other
);
13769 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
13775 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
13777 && symbol_index
>= section
->sh_info
13778 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
13779 && filedata
->file_header
.e_machine
!= EM_MIPS
13780 /* Solaris binaries have been found to violate this requirement as
13781 well. Not sure if this is a bug or an ABI requirement. */
13782 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
13783 warn (_("local symbol %" PRIu64
" found at index >= %s's sh_info value of %u\n"),
13784 symbol_index
, printable_section_name (filedata
, section
), section
->sh_info
);
13787 static const char *
13788 get_lto_kind (unsigned int kind
)
13792 case 0: return "DEF";
13793 case 1: return "WEAKDEF";
13794 case 2: return "UNDEF";
13795 case 3: return "WEAKUNDEF";
13796 case 4: return "COMMON";
13801 static char buffer
[30];
13802 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
13803 sprintf (buffer
, "<unknown: %u>", kind
);
13807 static const char *
13808 get_lto_visibility (unsigned int visibility
)
13810 switch (visibility
)
13812 case 0: return "DEFAULT";
13813 case 1: return "PROTECTED";
13814 case 2: return "INTERNAL";
13815 case 3: return "HIDDEN";
13820 static char buffer
[30];
13821 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
13822 sprintf (buffer
, "<unknown: %u>", visibility
);
13826 static const char *
13827 get_lto_sym_type (unsigned int sym_type
)
13831 case 0: return "UNKNOWN";
13832 case 1: return "FUNCTION";
13833 case 2: return "VARIABLE";
13838 static char buffer
[30];
13839 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
13840 sprintf (buffer
, "<unknown: %u>", sym_type
);
13844 /* Display an LTO format symbol table.
13845 FIXME: The format of LTO symbol tables is not formalized.
13846 So this code could need changing in the future. */
13849 display_lto_symtab (Filedata
* filedata
,
13850 Elf_Internal_Shdr
* section
)
13852 if (section
->sh_size
== 0)
13854 if (filedata
->is_separate
)
13855 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
13856 printable_section_name (filedata
, section
),
13857 filedata
->file_name
);
13859 printf (_("\nLTO Symbol table '%s' is empty!\n"),
13860 printable_section_name (filedata
, section
));
13865 if (section
->sh_size
> filedata
->file_size
)
13867 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
13868 printable_section_name (filedata
, section
),
13873 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
13874 section
->sh_size
, 1, _("LTO symbols"));
13875 if (alloced_data
== NULL
)
13878 /* Look for extended data for the symbol table. */
13879 Elf_Internal_Shdr
* ext
= NULL
;
13880 void * ext_data_orig
= NULL
;
13881 char * ext_data
= NULL
;
13882 char * ext_data_end
= NULL
;
13883 char * ext_name
= NULL
;
13885 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
13886 (section_name (filedata
, section
)
13887 + sizeof (".gnu.lto_.symtab.") - 1)) > 0
13888 && ext_name
!= NULL
/* Paranoia. */
13889 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
13891 if (ext
->sh_size
< 3)
13892 error (_("LTO Symbol extension table '%s' is empty!\n"),
13893 printable_section_name (filedata
, ext
));
13896 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
13898 _("LTO ext symbol data"));
13899 if (ext_data
!= NULL
)
13901 ext_data_end
= ext_data
+ ext
->sh_size
;
13902 if (* ext_data
++ != 1)
13903 error (_("Unexpected version number in symbol extension table\n"));
13908 const unsigned char * data
= (const unsigned char *) alloced_data
;
13909 const unsigned char * end
= data
+ section
->sh_size
;
13911 if (filedata
->is_separate
)
13912 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
13916 if (ext_data_orig
!= NULL
)
13919 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
13920 printable_section_name (filedata
, section
),
13921 printable_section_name (filedata
, ext
));
13924 printf (_("LTO Symbol table '%s'\n"),
13925 printable_section_name (filedata
, section
));
13926 printf (_(" and extension table '%s' contain:\n"),
13927 printable_section_name (filedata
, ext
));
13931 printf (_("LTO Symbol table '%s' contains:\n"),
13932 printable_section_name (filedata
, section
));
13934 /* FIXME: Add a wide version. */
13935 if (ext_data_orig
!= NULL
)
13936 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
13938 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
13940 /* FIXME: We do not handle style prefixes. */
13944 const unsigned char * sym_name
= data
;
13945 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
13949 const unsigned char * comdat_key
= data
;
13950 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
13954 if (data
+ 2 + 8 + 4 > end
)
13957 unsigned int kind
= *data
++;
13958 unsigned int visibility
= *data
++;
13960 uint64_t size
= byte_get (data
, 8);
13963 uint64_t slot
= byte_get (data
, 4);
13966 if (ext_data
!= NULL
)
13968 if (ext_data
< (ext_data_end
- 1))
13970 unsigned int sym_type
= * ext_data
++;
13971 unsigned int sec_kind
= * ext_data
++;
13973 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" %9s %08x _",
13974 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13975 get_lto_kind (kind
),
13976 get_lto_visibility (visibility
),
13979 get_lto_sym_type (sym_type
),
13981 print_symbol_name (6, (const char *) sym_name
);
13985 error (_("Ran out of LTO symbol extension data\n"));
13987 /* FIXME: return FAIL result ? */
13992 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" _",
13993 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13994 get_lto_kind (kind
),
13995 get_lto_visibility (visibility
),
13998 print_symbol_name (21, (const char *) sym_name
);
14003 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
14005 error (_("Data remains in the LTO symbol extension table\n"));
14009 free (alloced_data
);
14010 free (ext_data_orig
);
14015 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
14016 free (alloced_data
);
14017 free (ext_data_orig
);
14022 /* Display LTO symbol tables. */
14025 process_lto_symbol_tables (Filedata
* filedata
)
14027 Elf_Internal_Shdr
* section
;
14034 if (filedata
->section_headers
== NULL
)
14037 for (i
= 0, section
= filedata
->section_headers
;
14038 i
< filedata
->file_header
.e_shnum
;
14040 if (section_name_valid (filedata
, section
)
14041 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
14042 res
&= display_lto_symtab (filedata
, section
);
14048 print_symbol_table_heading (void)
14050 /* FIXME: We should store the size of each field in the display in a table and
14051 then use the values inside print_symbol(), instead of that function using
14052 hard coded constants. */
14055 if (extra_sym_info
)
14057 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
14058 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |---8--| |----13.....| |........... */
14059 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 (.text) get_sections */
14063 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14064 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
14065 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
14069 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14070 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |------------29-------------| */
14071 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
14076 if (extra_sym_info
)
14078 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
14079 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-------14---| |..... */
14080 /* eg: 2: 0000000000000000 0 FUNC LOCAL DEFAULT 1 (.text) .very_long_function_name */
14085 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14086 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
14087 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_function_name */
14091 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14092 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |--------21---------| */
14093 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_functi[...] */
14098 /* Dump the symbol table. */
14101 process_symbol_table (Filedata
* filedata
)
14103 Elf_Internal_Shdr
* section
;
14105 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
14108 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
14110 && do_using_dynamic
14111 && filedata
->dynamic_strings
!= NULL
14112 && filedata
->dynamic_symbols
!= NULL
)
14116 if (filedata
->is_separate
)
14118 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table"
14119 " contains %" PRIu64
" entry:\n",
14120 "\nIn linked file '%s' the dynamic symbol table"
14121 " contains %" PRIu64
" entries:\n",
14122 filedata
->num_dynamic_syms
),
14123 filedata
->file_name
,
14124 filedata
->num_dynamic_syms
);
14128 printf (ngettext ("\nSymbol table for image contains %" PRIu64
14130 "\nSymbol table for image contains %" PRIu64
14132 filedata
->num_dynamic_syms
),
14133 filedata
->num_dynamic_syms
);
14136 print_symbol_table_heading ();
14138 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
14139 print_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
14140 filedata
->dynamic_strings
,
14141 filedata
->dynamic_strings_length
);
14143 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
14144 && filedata
->section_headers
!= NULL
)
14148 for (i
= 0, section
= filedata
->section_headers
;
14149 i
< filedata
->file_header
.e_shnum
;
14152 char * strtab
= NULL
;
14153 uint64_t strtab_size
= 0;
14154 Elf_Internal_Sym
* symtab
;
14155 uint64_t si
, num_syms
;
14157 if ((section
->sh_type
!= SHT_SYMTAB
14158 && section
->sh_type
!= SHT_DYNSYM
)
14160 && section
->sh_type
== SHT_SYMTAB
))
14163 if (section
->sh_entsize
== 0)
14165 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
14166 printable_section_name (filedata
, section
));
14170 num_syms
= section
->sh_size
/ section
->sh_entsize
;
14172 if (filedata
->is_separate
)
14173 printf (ngettext ("\nIn linked file '%s' symbol section '%s'"
14174 " contains %" PRIu64
" entry:\n",
14175 "\nIn linked file '%s' symbol section '%s'"
14176 " contains %" PRIu64
" entries:\n",
14178 filedata
->file_name
,
14179 printable_section_name (filedata
, section
),
14182 printf (ngettext ("\nSymbol table '%s' contains %" PRIu64
14184 "\nSymbol table '%s' contains %" PRIu64
14187 printable_section_name (filedata
, section
),
14190 print_symbol_table_heading ();
14192 symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
14193 if (symtab
== NULL
)
14196 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
14198 strtab
= filedata
->string_table
;
14199 strtab_size
= filedata
->string_table_length
;
14201 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
14203 Elf_Internal_Shdr
* string_sec
;
14205 string_sec
= filedata
->section_headers
+ section
->sh_link
;
14207 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
14208 1, string_sec
->sh_size
,
14209 _("string table"));
14210 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
14213 for (si
= 0; si
< num_syms
; si
++)
14214 print_symbol (filedata
, si
, symtab
, section
,
14215 strtab
, strtab_size
);
14218 if (strtab
!= filedata
->string_table
)
14224 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
14226 if (do_histogram
&& filedata
->buckets
!= NULL
)
14232 uint64_t maxlength
= 0;
14233 uint64_t nzero_counts
= 0;
14234 uint64_t nsyms
= 0;
14237 printf (ngettext ("\nHistogram for bucket list length "
14238 "(total of %" PRIu64
" bucket):\n",
14239 "\nHistogram for bucket list length "
14240 "(total of %" PRIu64
" buckets):\n",
14241 filedata
->nbuckets
),
14242 filedata
->nbuckets
);
14244 lengths
= calloc (filedata
->nbuckets
, sizeof (*lengths
));
14245 if (lengths
== NULL
)
14247 error (_("Out of memory allocating space for histogram buckets\n"));
14250 visited
= xcmalloc (filedata
->nchains
, 1);
14251 memset (visited
, 0, filedata
->nchains
);
14253 printf (_(" Length Number %% of total Coverage\n"));
14254 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
14256 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
14259 if (maxlength
< ++lengths
[hn
])
14261 if (si
>= filedata
->nchains
|| visited
[si
])
14263 error (_("histogram chain is corrupt\n"));
14271 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
14272 if (counts
== NULL
)
14275 error (_("Out of memory allocating space for histogram counts\n"));
14279 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
14280 ++counts
[lengths
[hn
]];
14282 if (filedata
->nbuckets
> 0)
14285 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
14286 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
14287 for (i
= 1; i
<= maxlength
; ++i
)
14289 nzero_counts
+= counts
[i
] * i
;
14290 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
14291 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
14292 (nzero_counts
* 100.0) / nsyms
);
14300 free (filedata
->buckets
);
14301 filedata
->buckets
= NULL
;
14302 filedata
->nbuckets
= 0;
14303 free (filedata
->chains
);
14304 filedata
->chains
= NULL
;
14306 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
14311 uint64_t maxlength
= 0;
14312 uint64_t nzero_counts
= 0;
14313 uint64_t nsyms
= 0;
14315 printf (ngettext ("\nHistogram for `%s' bucket list length "
14316 "(total of %" PRIu64
" bucket):\n",
14317 "\nHistogram for `%s' bucket list length "
14318 "(total of %" PRIu64
" buckets):\n",
14319 filedata
->ngnubuckets
),
14320 GNU_HASH_SECTION_NAME (filedata
),
14321 filedata
->ngnubuckets
);
14323 lengths
= calloc (filedata
->ngnubuckets
, sizeof (*lengths
));
14324 if (lengths
== NULL
)
14326 error (_("Out of memory allocating space for gnu histogram buckets\n"));
14330 printf (_(" Length Number %% of total Coverage\n"));
14332 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
14333 if (filedata
->gnubuckets
[hn
] != 0)
14335 uint64_t off
, length
= 1;
14337 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
14338 /* PR 17531 file: 010-77222-0.004. */
14339 off
< filedata
->ngnuchains
14340 && (filedata
->gnuchains
[off
] & 1) == 0;
14343 lengths
[hn
] = length
;
14344 if (length
> maxlength
)
14345 maxlength
= length
;
14349 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
14350 if (counts
== NULL
)
14353 error (_("Out of memory allocating space for gnu histogram counts\n"));
14357 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
14358 ++counts
[lengths
[hn
]];
14360 if (filedata
->ngnubuckets
> 0)
14363 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
14364 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
14365 for (j
= 1; j
<= maxlength
; ++j
)
14367 nzero_counts
+= counts
[j
] * j
;
14368 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
14369 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
14370 (nzero_counts
* 100.0) / nsyms
);
14377 free (filedata
->gnubuckets
);
14378 filedata
->gnubuckets
= NULL
;
14379 filedata
->ngnubuckets
= 0;
14380 free (filedata
->gnuchains
);
14381 filedata
->gnuchains
= NULL
;
14382 filedata
->ngnuchains
= 0;
14383 free (filedata
->mipsxlat
);
14384 filedata
->mipsxlat
= NULL
;
14388 free (filedata
->gnubuckets
);
14389 filedata
->gnubuckets
= NULL
;
14390 filedata
->ngnubuckets
= 0;
14391 free (filedata
->gnuchains
);
14392 filedata
->gnuchains
= NULL
;
14393 filedata
->ngnuchains
= 0;
14394 free (filedata
->mipsxlat
);
14395 filedata
->mipsxlat
= NULL
;
14396 free (filedata
->buckets
);
14397 filedata
->buckets
= NULL
;
14398 filedata
->nbuckets
= 0;
14399 free (filedata
->chains
);
14400 filedata
->chains
= NULL
;
14405 process_syminfo (Filedata
* filedata
)
14409 if (filedata
->dynamic_syminfo
== NULL
14411 /* No syminfo, this is ok. */
14414 /* There better should be a dynamic symbol section. */
14415 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
14418 if (filedata
->is_separate
)
14419 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entry:\n",
14420 "\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entries:\n",
14421 filedata
->dynamic_syminfo_nent
),
14422 filedata
->file_name
,
14423 filedata
->dynamic_syminfo_offset
,
14424 filedata
->dynamic_syminfo_nent
);
14426 printf (ngettext ("\nDynamic info segment at offset %#" PRIx64
14427 " contains %d entry:\n",
14428 "\nDynamic info segment at offset %#" PRIx64
14429 " contains %d entries:\n",
14430 filedata
->dynamic_syminfo_nent
),
14431 filedata
->dynamic_syminfo_offset
,
14432 filedata
->dynamic_syminfo_nent
);
14434 printf (_(" Num: Name BoundTo Flags\n"));
14435 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
14437 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
14439 printf ("%4d: ", i
);
14440 if (i
>= filedata
->num_dynamic_syms
)
14441 printf (_("<corrupt index>"));
14442 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
14443 print_symbol_name (30, get_dynamic_name (filedata
,
14444 filedata
->dynamic_symbols
[i
].st_name
));
14446 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
14449 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
14451 case SYMINFO_BT_SELF
:
14452 fputs ("SELF ", stdout
);
14454 case SYMINFO_BT_PARENT
:
14455 fputs ("PARENT ", stdout
);
14458 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
14459 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
14460 && valid_dynamic_name (filedata
,
14461 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
14463 print_symbol_name (10, get_dynamic_name (filedata
,
14464 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
14468 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
14472 if (flags
& SYMINFO_FLG_DIRECT
)
14473 printf (" DIRECT");
14474 if (flags
& SYMINFO_FLG_PASSTHRU
)
14475 printf (" PASSTHRU");
14476 if (flags
& SYMINFO_FLG_COPY
)
14478 if (flags
& SYMINFO_FLG_LAZYLOAD
)
14479 printf (" LAZYLOAD");
14487 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
14488 is contained by the region START .. END. The types of ADDR, START
14489 and END should all be the same. Note both ADDR + NELEM and END
14490 point to just beyond the end of the regions that are being tested. */
14491 #define IN_RANGE(START,END,ADDR,NELEM) \
14492 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
14494 /* Check to see if the given reloc needs to be handled in a target specific
14495 manner. If so then process the reloc and return TRUE otherwise return
14498 If called with reloc == NULL, then this is a signal that reloc processing
14499 for the current section has finished, and any saved state should be
14503 target_specific_reloc_handling (Filedata
*filedata
,
14504 Elf_Internal_Rela
*reloc
,
14505 unsigned char *start
,
14506 unsigned char *end
,
14507 Elf_Internal_Sym
*symtab
,
14510 unsigned int reloc_type
= 0;
14511 uint64_t sym_index
= 0;
14515 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
14516 sym_index
= get_reloc_symindex (reloc
->r_info
);
14519 switch (filedata
->file_header
.e_machine
)
14523 switch (reloc_type
)
14525 /* For .uleb128 .LFE1-.LFB1, loongarch write 0 to object file
14526 at assembly time. */
14527 case 107: /* R_LARCH_ADD_ULEB128. */
14528 case 108: /* R_LARCH_SUB_ULEB128. */
14530 uint64_t value
= 0;
14531 unsigned int reloc_size
= 0;
14534 if (reloc
->r_offset
< (size_t) (end
- start
))
14535 value
= read_leb128 (start
+ reloc
->r_offset
, end
, false,
14536 &reloc_size
, &leb_ret
);
14537 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
14538 error (_("LoongArch ULEB128 field at 0x%lx contains invalid "
14539 "ULEB128 value\n"),
14540 (long) reloc
->r_offset
);
14542 else if (sym_index
>= num_syms
)
14543 error (_("%s reloc contains invalid symbol index "
14546 ? "R_LARCH_ADD_ULEB128"
14547 : "R_LARCH_SUB_ULEB128"),
14551 if (reloc_type
== 107)
14552 value
+= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
14554 value
-= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
14556 /* Write uleb128 value to p. */
14557 bfd_byte
*p
= start
+ reloc
->r_offset
;
14560 bfd_byte c
= value
& 0x7f;
14562 if (--reloc_size
!= 0)
14566 while (reloc_size
);
14576 case EM_MSP430_OLD
:
14578 static Elf_Internal_Sym
* saved_sym
= NULL
;
14586 switch (reloc_type
)
14588 case 10: /* R_MSP430_SYM_DIFF */
14589 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
14590 if (uses_msp430x_relocs (filedata
))
14592 /* Fall through. */
14593 case 21: /* R_MSP430X_SYM_DIFF */
14594 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
14596 if (sym_index
>= num_syms
)
14597 error (_("%s reloc contains invalid symbol index "
14598 "%" PRIu64
"\n"), "MSP430 SYM_DIFF", sym_index
);
14600 saved_sym
= symtab
+ sym_index
;
14603 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
14604 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
14605 goto handle_sym_diff
;
14607 case 5: /* R_MSP430_16_BYTE */
14608 case 9: /* R_MSP430_8 */
14609 case 11: /* R_MSP430_GNU_SET_ULEB128 */
14610 if (uses_msp430x_relocs (filedata
))
14612 goto handle_sym_diff
;
14614 case 2: /* R_MSP430_ABS16 */
14615 case 15: /* R_MSP430X_ABS16 */
14616 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
14617 if (! uses_msp430x_relocs (filedata
))
14619 goto handle_sym_diff
;
14622 if (saved_sym
!= NULL
)
14625 unsigned int reloc_size
= 0;
14627 switch (reloc_type
)
14629 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
14632 case 11: /* R_MSP430_GNU_SET_ULEB128 */
14633 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
14634 if (reloc
->r_offset
< (size_t) (end
- start
))
14635 read_leb128 (start
+ reloc
->r_offset
, end
, false,
14636 &reloc_size
, &leb_ret
);
14643 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
14644 error (_("MSP430 ULEB128 field at %#" PRIx64
14645 " contains invalid ULEB128 value\n"),
14647 else if (sym_index
>= num_syms
)
14648 error (_("%s reloc contains invalid symbol index "
14649 "%" PRIu64
"\n"), "MSP430", sym_index
);
14652 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14653 - saved_sym
->st_value
);
14655 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14656 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14659 error (_("MSP430 sym diff reloc contains invalid offset: "
14670 if (saved_sym
!= NULL
)
14671 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
14678 case EM_CYGNUS_MN10300
:
14680 static Elf_Internal_Sym
* saved_sym
= NULL
;
14688 switch (reloc_type
)
14690 case 34: /* R_MN10300_ALIGN */
14692 case 33: /* R_MN10300_SYM_DIFF */
14693 if (sym_index
>= num_syms
)
14694 error (_("%s reloc contains invalid symbol index "
14695 "%" PRIu64
"\n"), "MN10300_SYM_DIFF", sym_index
);
14697 saved_sym
= symtab
+ sym_index
;
14700 case 1: /* R_MN10300_32 */
14701 case 2: /* R_MN10300_16 */
14702 if (saved_sym
!= NULL
)
14704 int reloc_size
= reloc_type
== 1 ? 4 : 2;
14707 if (sym_index
>= num_syms
)
14708 error (_("%s reloc contains invalid symbol index "
14709 "%" PRIu64
"\n"), "MN10300", sym_index
);
14712 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14713 - saved_sym
->st_value
);
14715 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14716 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14718 error (_("MN10300 sym diff reloc contains invalid offset:"
14719 " %#" PRIx64
"\n"),
14728 if (saved_sym
!= NULL
)
14729 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
14737 static uint64_t saved_sym1
= 0;
14738 static uint64_t saved_sym2
= 0;
14739 static uint64_t value
;
14743 saved_sym1
= saved_sym2
= 0;
14747 switch (reloc_type
)
14749 case 0x80: /* R_RL78_SYM. */
14750 saved_sym1
= saved_sym2
;
14751 if (sym_index
>= num_syms
)
14752 error (_("%s reloc contains invalid symbol index "
14753 "%" PRIu64
"\n"), "RL78_SYM", sym_index
);
14756 saved_sym2
= symtab
[sym_index
].st_value
;
14757 saved_sym2
+= reloc
->r_addend
;
14761 case 0x83: /* R_RL78_OPsub. */
14762 value
= saved_sym1
- saved_sym2
;
14763 saved_sym2
= saved_sym1
= 0;
14767 case 0x41: /* R_RL78_ABS32. */
14768 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
14769 byte_put (start
+ reloc
->r_offset
, value
, 4);
14771 error (_("RL78 sym diff reloc contains invalid offset: "
14777 case 0x43: /* R_RL78_ABS16. */
14778 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
14779 byte_put (start
+ reloc
->r_offset
, value
, 2);
14781 error (_("RL78 sym diff reloc contains invalid offset: "
14797 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
14798 DWARF debug sections. This is a target specific test. Note - we do not
14799 go through the whole including-target-headers-multiple-times route, (as
14800 we have already done with <elf/h8.h>) because this would become very
14801 messy and even then this function would have to contain target specific
14802 information (the names of the relocs instead of their numeric values).
14803 FIXME: This is not the correct way to solve this problem. The proper way
14804 is to have target specific reloc sizing and typing functions created by
14805 the reloc-macros.h header, in the same way that it already creates the
14806 reloc naming functions. */
14809 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14811 /* Please keep this table alpha-sorted for ease of visual lookup. */
14812 switch (filedata
->file_header
.e_machine
)
14816 return reloc_type
== 1; /* R_386_32. */
14818 return reloc_type
== 1; /* R_68K_32. */
14820 return reloc_type
== 1; /* R_860_32. */
14822 return reloc_type
== 2; /* R_960_32. */
14824 return (reloc_type
== 258
14825 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
14827 return reloc_type
== 11; /* R_BPF_DATA_32 */
14828 case EM_ADAPTEVA_EPIPHANY
:
14829 return reloc_type
== 3;
14831 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
14833 return reloc_type
== 1; /* R_ARC_32. */
14834 case EM_ARC_COMPACT
:
14835 case EM_ARC_COMPACT2
:
14836 case EM_ARC_COMPACT3
:
14837 case EM_ARC_COMPACT3_64
:
14838 return reloc_type
== 4; /* R_ARC_32. */
14840 return reloc_type
== 2; /* R_ARM_ABS32 */
14843 return reloc_type
== 1;
14845 return reloc_type
== 0x12; /* R_byte4_data. */
14847 return reloc_type
== 3; /* R_CRIS_32. */
14849 return reloc_type
== 3; /* R_CR16_NUM32. */
14851 return reloc_type
== 15; /* R_CRX_NUM32. */
14853 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
14854 case EM_CYGNUS_FRV
:
14855 return reloc_type
== 1;
14856 case EM_CYGNUS_D10V
:
14858 return reloc_type
== 6; /* R_D10V_32. */
14859 case EM_CYGNUS_D30V
:
14861 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
14863 return reloc_type
== 3; /* R_DLX_RELOC_32. */
14864 case EM_CYGNUS_FR30
:
14866 return reloc_type
== 3; /* R_FR30_32. */
14868 return reloc_type
== 1; /* R_FT32_32. */
14872 return reloc_type
== 1; /* R_H8_DIR32. */
14874 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
14875 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
14876 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
14877 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
14880 return reloc_type
== 2; /* R_IP2K_32. */
14882 return reloc_type
== 2; /* R_IQ2000_32. */
14884 return reloc_type
== 2; /* R_KVX_32. */
14885 case EM_LATTICEMICO32
:
14886 return reloc_type
== 3; /* R_LM32_32. */
14888 return reloc_type
== 1; /* R_LARCH_32. */
14891 return reloc_type
== 3; /* R_M32C_32. */
14893 return reloc_type
== 34; /* R_M32R_32_RELA. */
14896 return reloc_type
== 6; /* R_M68HC11_32. */
14898 return reloc_type
== 7 || /* R_S12Z_EXT32 */
14899 reloc_type
== 6; /* R_S12Z_CW32. */
14901 return reloc_type
== 1; /* R_MCORE_ADDR32. */
14902 case EM_CYGNUS_MEP
:
14903 return reloc_type
== 4; /* R_MEP_32. */
14905 return reloc_type
== 2; /* R_METAG_ADDR32. */
14906 case EM_MICROBLAZE
:
14907 return reloc_type
== 1; /* R_MICROBLAZE_32. */
14909 return reloc_type
== 2; /* R_MIPS_32. */
14911 return reloc_type
== 4; /* R_MMIX_32. */
14912 case EM_CYGNUS_MN10200
:
14914 return reloc_type
== 1; /* R_MN10200_32. */
14915 case EM_CYGNUS_MN10300
:
14917 return reloc_type
== 1; /* R_MN10300_32. */
14919 return reloc_type
== 1; /* R_MOXIE_32. */
14920 case EM_MSP430_OLD
:
14922 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
14924 return reloc_type
== 2; /* R_MT_32. */
14926 return reloc_type
== 20; /* R_NDS32_32_RELA. */
14927 case EM_ALTERA_NIOS2
:
14928 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
14930 return reloc_type
== 1; /* R_NIOS_32. */
14932 return reloc_type
== 1; /* R_OR1K_32. */
14934 return (reloc_type
== 1 /* R_PARISC_DIR32. */
14935 || reloc_type
== 2 /* R_PARISC_DIR21L. */
14936 || reloc_type
== 41); /* R_PARISC_SECREL32. */
14939 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
14941 return reloc_type
== 1; /* R_PPC64_ADDR32. */
14943 return reloc_type
== 1; /* R_PPC_ADDR32. */
14945 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
14947 return reloc_type
== 1; /* R_RISCV_32. */
14949 return reloc_type
== 1; /* R_RL78_DIR32. */
14951 return reloc_type
== 1; /* R_RX_DIR32. */
14953 return reloc_type
== 1; /* R_I370_ADDR31. */
14956 return reloc_type
== 4; /* R_S390_32. */
14958 return reloc_type
== 8; /* R_SCORE_ABS32. */
14960 return reloc_type
== 1; /* R_SH_DIR32. */
14961 case EM_SPARC32PLUS
:
14964 return reloc_type
== 3 /* R_SPARC_32. */
14965 || reloc_type
== 23; /* R_SPARC_UA32. */
14967 return reloc_type
== 6; /* R_SPU_ADDR32 */
14969 return reloc_type
== 1; /* R_C6000_ABS32. */
14971 return reloc_type
== 2; /* R_TILEGX_32. */
14973 return reloc_type
== 1; /* R_TILEPRO_32. */
14974 case EM_CYGNUS_V850
:
14976 return reloc_type
== 6; /* R_V850_ABS32. */
14978 return reloc_type
== 0x33; /* R_V810_WORD. */
14980 return reloc_type
== 1; /* R_VAX_32. */
14982 return reloc_type
== 3; /* R_VISIUM_32. */
14983 case EM_WEBASSEMBLY
:
14984 return reloc_type
== 1; /* R_WASM32_32. */
14988 return reloc_type
== 10; /* R_X86_64_32. */
14990 return reloc_type
== 4; /* R_XGATE_32. */
14992 return reloc_type
== 1; /* R_XSTROMY16_32. */
14993 case EM_XTENSA_OLD
:
14995 return reloc_type
== 1; /* R_XTENSA_32. */
14997 return reloc_type
== 6; /* R_Z80_32. */
15000 static unsigned int prev_warn
= 0;
15002 /* Avoid repeating the same warning multiple times. */
15003 if (prev_warn
!= filedata
->file_header
.e_machine
)
15004 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
15005 filedata
->file_header
.e_machine
);
15006 prev_warn
= filedata
->file_header
.e_machine
;
15012 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15013 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
15016 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15018 switch (filedata
->file_header
.e_machine
)
15019 /* Please keep this table alpha-sorted for ease of visual lookup. */
15023 return reloc_type
== 2; /* R_386_PC32. */
15025 return reloc_type
== 4; /* R_68K_PC32. */
15027 return reloc_type
== 261; /* R_AARCH64_PREL32 */
15028 case EM_ADAPTEVA_EPIPHANY
:
15029 return reloc_type
== 6;
15031 return reloc_type
== 10; /* R_ALPHA_SREL32. */
15032 case EM_ARC_COMPACT
:
15033 case EM_ARC_COMPACT2
:
15034 case EM_ARC_COMPACT3
:
15035 case EM_ARC_COMPACT3_64
:
15036 return reloc_type
== 49; /* R_ARC_32_PCREL. */
15038 return reloc_type
== 3; /* R_ARM_REL32 */
15041 return reloc_type
== 36; /* R_AVR_32_PCREL. */
15043 return reloc_type
== 99; /* R_LARCH_32_PCREL. */
15044 case EM_MICROBLAZE
:
15045 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
15047 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
15049 return reloc_type
== 9; /* R_PARISC_PCREL32. */
15051 return reloc_type
== 26; /* R_PPC_REL32. */
15053 return reloc_type
== 26; /* R_PPC64_REL32. */
15055 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
15058 return reloc_type
== 5; /* R_390_PC32. */
15060 return reloc_type
== 2; /* R_SH_REL32. */
15061 case EM_SPARC32PLUS
:
15064 return reloc_type
== 6; /* R_SPARC_DISP32. */
15066 return reloc_type
== 13; /* R_SPU_REL32. */
15068 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
15070 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
15072 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
15076 return reloc_type
== 2; /* R_X86_64_PC32. */
15078 return reloc_type
== 4; /* R_VAX_PCREL32. */
15079 case EM_XTENSA_OLD
:
15081 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
15083 return reloc_type
== 7; /* R_KVX_32_PCREL */
15085 /* Do not abort or issue an error message here. Not all targets use
15086 pc-relative 32-bit relocs in their DWARF debug information and we
15087 have already tested for target coverage in is_32bit_abs_reloc. A
15088 more helpful warning message will be generated by apply_relocations
15089 anyway, so just return. */
15094 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15095 a 64-bit absolute RELA relocation used in DWARF debug sections. */
15098 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15100 switch (filedata
->file_header
.e_machine
)
15103 return reloc_type
== 257; /* R_AARCH64_ABS64. */
15104 case EM_ARC_COMPACT3_64
:
15105 return reloc_type
== 5; /* R_ARC_64. */
15107 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
15109 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
15110 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
15112 return reloc_type
== 2; /* R_LARCH_64 */
15114 return reloc_type
== 80; /* R_PARISC_DIR64. */
15116 return reloc_type
== 38; /* R_PPC64_ADDR64. */
15118 return reloc_type
== 2; /* R_RISCV_64. */
15119 case EM_SPARC32PLUS
:
15122 return reloc_type
== 32 /* R_SPARC_64. */
15123 || reloc_type
== 54; /* R_SPARC_UA64. */
15127 return reloc_type
== 1; /* R_X86_64_64. */
15130 return reloc_type
== 22; /* R_S390_64. */
15132 return reloc_type
== 1; /* R_TILEGX_64. */
15134 return reloc_type
== 18; /* R_MIPS_64. */
15136 return reloc_type
== 3; /* R_KVX_64 */
15142 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
15143 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
15146 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15148 switch (filedata
->file_header
.e_machine
)
15151 return reloc_type
== 260; /* R_AARCH64_PREL64. */
15153 return reloc_type
== 11; /* R_ALPHA_SREL64. */
15155 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
15156 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
15158 return reloc_type
== 72; /* R_PARISC_PCREL64. */
15160 return reloc_type
== 44; /* R_PPC64_REL64. */
15161 case EM_SPARC32PLUS
:
15164 return reloc_type
== 46; /* R_SPARC_DISP64. */
15168 return reloc_type
== 24; /* R_X86_64_PC64. */
15171 return reloc_type
== 23; /* R_S390_PC64. */
15173 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
15179 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15180 a 24-bit absolute RELA relocation used in DWARF debug sections. */
15183 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15185 switch (filedata
->file_header
.e_machine
)
15187 case EM_CYGNUS_MN10200
:
15189 return reloc_type
== 4; /* R_MN10200_24. */
15191 return reloc_type
== 5; /* R_FT32_20. */
15193 return reloc_type
== 5; /* R_Z80_24. */
15199 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15200 a 16-bit absolute RELA relocation used in DWARF debug sections. */
15203 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15205 /* Please keep this table alpha-sorted for ease of visual lookup. */
15206 switch (filedata
->file_header
.e_machine
)
15209 case EM_ARC_COMPACT
:
15210 case EM_ARC_COMPACT2
:
15211 case EM_ARC_COMPACT3
:
15212 case EM_ARC_COMPACT3_64
:
15213 return reloc_type
== 2; /* R_ARC_16. */
15214 case EM_ADAPTEVA_EPIPHANY
:
15215 return reloc_type
== 5;
15218 return reloc_type
== 4; /* R_AVR_16. */
15219 case EM_CYGNUS_D10V
:
15221 return reloc_type
== 3; /* R_D10V_16. */
15223 return reloc_type
== 2; /* R_FT32_16. */
15227 return reloc_type
== R_H8_DIR16
;
15230 return reloc_type
== 1; /* R_IP2K_16. */
15233 return reloc_type
== 1; /* R_M32C_16 */
15234 case EM_CYGNUS_MN10200
:
15236 return reloc_type
== 2; /* R_MN10200_16. */
15237 case EM_CYGNUS_MN10300
:
15239 return reloc_type
== 2; /* R_MN10300_16. */
15241 return reloc_type
== 1; /* R_KVX_16 */
15243 if (uses_msp430x_relocs (filedata
))
15244 return reloc_type
== 2; /* R_MSP430_ABS16. */
15245 /* Fall through. */
15246 case EM_MSP430_OLD
:
15247 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
15249 return reloc_type
== 19; /* R_NDS32_16_RELA. */
15250 case EM_ALTERA_NIOS2
:
15251 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
15253 return reloc_type
== 9; /* R_NIOS_16. */
15255 return reloc_type
== 2; /* R_OR1K_16. */
15257 return reloc_type
== 55; /* R_RISCV_SET16. */
15259 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
15261 return reloc_type
== 2; /* R_C6000_ABS16. */
15263 return reloc_type
== 2; /* R_VISIUM_16. */
15265 return reloc_type
== 3; /* R_XGATE_16. */
15267 return reloc_type
== 4; /* R_Z80_16. */
15273 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15274 a 8-bit absolute RELA relocation used in DWARF debug sections. */
15277 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15279 switch (filedata
->file_header
.e_machine
)
15282 return reloc_type
== 54; /* R_RISCV_SET8. */
15284 return reloc_type
== 1; /* R_Z80_8. */
15285 case EM_MICROBLAZE
:
15286 return (reloc_type
== 33 /* R_MICROBLAZE_32_NONE. */
15287 || reloc_type
== 0 /* R_MICROBLAZE_NONE. */
15288 || reloc_type
== 9 /* R_MICROBLAZE_64_NONE. */);
15294 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15295 a 6-bit absolute RELA relocation used in DWARF debug sections. */
15298 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15300 switch (filedata
->file_header
.e_machine
)
15303 return reloc_type
== 53; /* R_RISCV_SET6. */
15309 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15310 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
15313 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15315 /* Please keep this table alpha-sorted for ease of visual lookup. */
15316 switch (filedata
->file_header
.e_machine
)
15319 return reloc_type
== 50; /* R_LARCH_ADD32. */
15321 return reloc_type
== 35; /* R_RISCV_ADD32. */
15327 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15328 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
15331 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15333 /* Please keep this table alpha-sorted for ease of visual lookup. */
15334 switch (filedata
->file_header
.e_machine
)
15337 return reloc_type
== 55; /* R_LARCH_SUB32. */
15339 return reloc_type
== 39; /* R_RISCV_SUB32. */
15345 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15346 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
15349 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15351 /* Please keep this table alpha-sorted for ease of visual lookup. */
15352 switch (filedata
->file_header
.e_machine
)
15355 return reloc_type
== 51; /* R_LARCH_ADD64. */
15357 return reloc_type
== 36; /* R_RISCV_ADD64. */
15363 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15364 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
15367 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15369 /* Please keep this table alpha-sorted for ease of visual lookup. */
15370 switch (filedata
->file_header
.e_machine
)
15373 return reloc_type
== 56; /* R_LARCH_SUB64. */
15375 return reloc_type
== 40; /* R_RISCV_SUB64. */
15381 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15382 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
15385 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15387 /* Please keep this table alpha-sorted for ease of visual lookup. */
15388 switch (filedata
->file_header
.e_machine
)
15391 return reloc_type
== 48; /* R_LARCH_ADD16. */
15393 return reloc_type
== 34; /* R_RISCV_ADD16. */
15399 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15400 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
15403 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15405 /* Please keep this table alpha-sorted for ease of visual lookup. */
15406 switch (filedata
->file_header
.e_machine
)
15409 return reloc_type
== 53; /* R_LARCH_SUB16. */
15411 return reloc_type
== 38; /* R_RISCV_SUB16. */
15417 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15418 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
15421 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15423 /* Please keep this table alpha-sorted for ease of visual lookup. */
15424 switch (filedata
->file_header
.e_machine
)
15427 return reloc_type
== 47; /* R_LARCH_ADD8. */
15429 return reloc_type
== 33; /* R_RISCV_ADD8. */
15435 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15436 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
15439 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15441 /* Please keep this table alpha-sorted for ease of visual lookup. */
15442 switch (filedata
->file_header
.e_machine
)
15445 return reloc_type
== 52; /* R_LARCH_SUB8. */
15447 return reloc_type
== 37; /* R_RISCV_SUB8. */
15453 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15454 a 6-bit inplace add RELA relocation used in DWARF debug sections. */
15457 is_6bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15459 switch (filedata
->file_header
.e_machine
)
15462 return reloc_type
== 105; /* R_LARCH_ADD6. */
15468 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15469 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
15472 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15474 switch (filedata
->file_header
.e_machine
)
15477 return reloc_type
== 106; /* R_LARCH_SUB6. */
15479 return reloc_type
== 52; /* R_RISCV_SUB6. */
15485 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
15486 relocation entries (possibly formerly used for SHT_GROUP sections). */
15489 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15491 switch (filedata
->file_header
.e_machine
)
15493 case EM_386
: /* R_386_NONE. */
15494 case EM_68K
: /* R_68K_NONE. */
15495 case EM_ADAPTEVA_EPIPHANY
:
15496 case EM_ALPHA
: /* R_ALPHA_NONE. */
15497 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
15498 case EM_ARC
: /* R_ARC_NONE. */
15499 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
15500 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
15501 case EM_ARC_COMPACT3
: /* R_ARC_NONE. */
15502 case EM_ARC_COMPACT3_64
: /* R_ARC_NONE. */
15503 case EM_ARM
: /* R_ARM_NONE. */
15504 case EM_CRIS
: /* R_CRIS_NONE. */
15505 case EM_FT32
: /* R_FT32_NONE. */
15506 case EM_IA_64
: /* R_IA64_NONE. */
15507 case EM_K1OM
: /* R_X86_64_NONE. */
15508 case EM_KVX
: /* R_KVX_NONE. */
15509 case EM_L1OM
: /* R_X86_64_NONE. */
15510 case EM_M32R
: /* R_M32R_NONE. */
15511 case EM_MIPS
: /* R_MIPS_NONE. */
15512 case EM_MN10300
: /* R_MN10300_NONE. */
15513 case EM_MOXIE
: /* R_MOXIE_NONE. */
15514 case EM_NIOS32
: /* R_NIOS_NONE. */
15515 case EM_OR1K
: /* R_OR1K_NONE. */
15516 case EM_PARISC
: /* R_PARISC_NONE. */
15517 case EM_PPC64
: /* R_PPC64_NONE. */
15518 case EM_PPC
: /* R_PPC_NONE. */
15519 case EM_RISCV
: /* R_RISCV_NONE. */
15520 case EM_S390
: /* R_390_NONE. */
15522 case EM_SH
: /* R_SH_NONE. */
15523 case EM_SPARC32PLUS
:
15524 case EM_SPARC
: /* R_SPARC_NONE. */
15526 case EM_TILEGX
: /* R_TILEGX_NONE. */
15527 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
15528 case EM_TI_C6000
:/* R_C6000_NONE. */
15529 case EM_X86_64
: /* R_X86_64_NONE. */
15530 case EM_Z80
: /* R_Z80_NONE. */
15531 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
15532 return reloc_type
== 0;
15535 return reloc_type
== 0 || reloc_type
== 256;
15538 return (reloc_type
== 0 /* R_AVR_NONE. */
15539 || reloc_type
== 30 /* R_AVR_DIFF8. */
15540 || reloc_type
== 31 /* R_AVR_DIFF16. */
15541 || reloc_type
== 32 /* R_AVR_DIFF32. */);
15543 return reloc_type
== 3; /* R_METAG_NONE. */
15545 return (reloc_type
== 0 /* R_NDS32_NONE. */
15546 || reloc_type
== 205 /* R_NDS32_DIFF8. */
15547 || reloc_type
== 206 /* R_NDS32_DIFF16. */
15548 || reloc_type
== 207 /* R_NDS32_DIFF32. */
15549 || reloc_type
== 208 /* R_NDS32_DIFF_ULEB128. */);
15551 return (reloc_type
== 0 /* R_PRU_NONE. */
15552 || reloc_type
== 65 /* R_PRU_DIFF8. */
15553 || reloc_type
== 66 /* R_PRU_DIFF16. */
15554 || reloc_type
== 67 /* R_PRU_DIFF32. */);
15555 case EM_XTENSA_OLD
:
15557 return (reloc_type
== 0 /* R_XTENSA_NONE. */
15558 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
15559 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
15560 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
15561 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
15562 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
15563 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
15564 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
15565 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
15566 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
15571 /* Returns TRUE if there is a relocation against
15572 section NAME at OFFSET bytes. */
15575 reloc_at (struct dwarf_section
* dsec
, uint64_t offset
)
15577 Elf_Internal_Rela
* relocs
;
15578 Elf_Internal_Rela
* rp
;
15580 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
15583 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
15585 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
15586 if (rp
->r_offset
== offset
)
15592 /* Apply relocations to a section.
15593 Returns TRUE upon success, FALSE otherwise.
15594 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
15595 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
15596 will be set to the number of relocs loaded.
15598 Note: So far support has been added only for those relocations
15599 which can be found in debug sections. FIXME: Add support for
15600 more relocations ? */
15603 apply_relocations (Filedata
*filedata
,
15604 const Elf_Internal_Shdr
*section
,
15605 unsigned char *start
,
15607 void **relocs_return
,
15608 uint64_t *num_relocs_return
)
15610 Elf_Internal_Shdr
* relsec
;
15611 unsigned char * end
= start
+ size
;
15613 if (relocs_return
!= NULL
)
15615 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
15616 * num_relocs_return
= 0;
15619 if (filedata
->file_header
.e_type
!= ET_REL
)
15620 /* No relocs to apply. */
15623 /* Find the reloc section associated with the section. */
15624 for (relsec
= filedata
->section_headers
;
15625 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15629 uint64_t num_relocs
;
15630 Elf_Internal_Rela
* relocs
;
15631 Elf_Internal_Rela
* rp
;
15632 Elf_Internal_Shdr
* symsec
;
15633 Elf_Internal_Sym
* symtab
;
15635 Elf_Internal_Sym
* sym
;
15637 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15638 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15639 || filedata
->section_headers
+ relsec
->sh_info
!= section
15640 || relsec
->sh_size
== 0
15641 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15644 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
15645 if (symsec
->sh_type
!= SHT_SYMTAB
15646 && symsec
->sh_type
!= SHT_DYNSYM
)
15649 is_rela
= relsec
->sh_type
== SHT_RELA
;
15653 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
15654 relsec
->sh_size
, & relocs
, & num_relocs
))
15659 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
15660 relsec
->sh_size
, & relocs
, & num_relocs
))
15664 /* SH uses RELA but uses in place value instead of the addend field. */
15665 if (filedata
->file_header
.e_machine
== EM_SH
)
15668 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
15670 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
15673 unsigned int reloc_type
;
15674 unsigned int reloc_size
;
15675 bool reloc_inplace
= false;
15676 bool reloc_subtract
= false;
15677 unsigned char *rloc
;
15678 uint64_t sym_index
;
15680 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
15682 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
15684 else if (is_none_reloc (filedata
, reloc_type
))
15686 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
15687 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
15689 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
15690 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15692 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
15694 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
15696 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
15697 || is_6bit_abs_reloc (filedata
, reloc_type
))
15699 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
15701 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
15704 reloc_inplace
= true;
15706 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
15708 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
15711 reloc_inplace
= true;
15713 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
15715 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
15718 reloc_inplace
= true;
15720 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
15722 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
15725 reloc_inplace
= true;
15727 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
15729 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
15732 reloc_inplace
= true;
15736 static unsigned int prev_reloc
= 0;
15738 if (reloc_type
!= prev_reloc
)
15739 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
15740 reloc_type
, printable_section_name (filedata
, section
));
15741 prev_reloc
= reloc_type
;
15745 rloc
= start
+ rp
->r_offset
;
15746 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
15748 warn (_("skipping invalid relocation offset %#" PRIx64
15749 " in section %s\n"),
15751 printable_section_name (filedata
, section
));
15755 sym_index
= get_reloc_symindex (rp
->r_info
);
15756 if (sym_index
>= num_syms
)
15758 warn (_("skipping invalid relocation symbol index %#" PRIx64
15759 " in section %s\n"),
15760 sym_index
, printable_section_name (filedata
, section
));
15763 sym
= symtab
+ sym_index
;
15765 /* If the reloc has a symbol associated with it,
15766 make sure that it is of an appropriate type.
15768 Relocations against symbols without type can happen.
15769 Gcc -feliminate-dwarf2-dups may generate symbols
15770 without type for debug info.
15772 Icc generates relocations against function symbols
15773 instead of local labels.
15775 Relocations against object symbols can happen, eg when
15776 referencing a global array. For an example of this see
15777 the _clz.o binary in libgcc.a. */
15779 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
15780 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
15782 warn (_("skipping unexpected symbol type %s in section %s relocation %tu\n"),
15783 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
15784 printable_section_name (filedata
, relsec
),
15791 addend
+= rp
->r_addend
;
15792 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
15793 partial_inplace. */
15795 || (filedata
->file_header
.e_machine
== EM_XTENSA
15796 && reloc_type
== 1)
15797 || ((filedata
->file_header
.e_machine
== EM_PJ
15798 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
15799 && reloc_type
== 1)
15800 || ((filedata
->file_header
.e_machine
== EM_D30V
15801 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
15802 && reloc_type
== 12)
15805 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15806 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
15808 addend
+= byte_get (rloc
, reloc_size
);
15811 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
15812 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15814 /* On HPPA, all pc-relative relocations are biased by 8. */
15815 if (filedata
->file_header
.e_machine
== EM_PARISC
)
15817 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
15820 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
15821 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
)
15822 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
15824 if (reloc_subtract
)
15825 addend
-= sym
->st_value
;
15827 addend
+= sym
->st_value
;
15828 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
15829 byte_put (rloc
, addend
, reloc_size
);
15831 else if (reloc_subtract
)
15832 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
15834 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
15838 /* Let the target specific reloc processing code know that
15839 we have finished with these relocs. */
15840 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
15844 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
15845 * num_relocs_return
= num_relocs
;
15856 #ifdef SUPPORT_DISASSEMBLY
15858 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15860 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
15862 /* FIXME: XXX -- to be done --- XXX */
15868 /* Reads in the contents of SECTION from FILE, returning a pointer
15869 to a malloc'ed buffer or NULL if something went wrong. */
15872 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15874 uint64_t num_bytes
= section
->sh_size
;
15876 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
15878 printf (_("Section '%s' has no data to dump.\n"),
15879 printable_section_name (filedata
, section
));
15883 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
15884 _("section contents"));
15887 /* Uncompresses a section that was compressed using zlib/zstd, in place. */
15890 uncompress_section_contents (bool is_zstd
,
15891 unsigned char ** buffer
,
15892 uint64_t uncompressed_size
,
15894 uint64_t file_size
)
15896 uint64_t compressed_size
= *size
;
15897 unsigned char *compressed_buffer
= *buffer
;
15898 unsigned char *uncompressed_buffer
= NULL
;
15902 /* Similar to _bfd_section_size_insane() in the BFD library we expect an
15903 upper limit of ~10x compression. Any compression larger than that is
15904 thought to be due to fuzzing of the compression header. */
15905 if (uncompressed_size
> file_size
* 10)
15907 error (_("Uncompressed section size is suspiciously large: 0x%" PRIu64
"\n"),
15908 uncompressed_size
);
15912 uncompressed_buffer
= xmalloc (uncompressed_size
);
15917 size_t ret
= ZSTD_decompress (uncompressed_buffer
, uncompressed_size
,
15918 compressed_buffer
, compressed_size
);
15919 if (ZSTD_isError (ret
))
15925 /* It is possible the section consists of several compressed
15926 buffers concatenated together, so we uncompress in a loop. */
15927 /* PR 18313: The state field in the z_stream structure is supposed
15928 to be invisible to the user (ie us), but some compilers will
15929 still complain about it being used without initialisation. So
15930 we first zero the entire z_stream structure and then set the fields
15932 memset (&strm
, 0, sizeof strm
);
15933 strm
.avail_in
= compressed_size
;
15934 strm
.next_in
= (Bytef
*)compressed_buffer
;
15935 strm
.avail_out
= uncompressed_size
;
15937 rc
= inflateInit (&strm
);
15938 while (strm
.avail_in
> 0)
15942 strm
.next_out
= ((Bytef
*)uncompressed_buffer
15943 + (uncompressed_size
- strm
.avail_out
));
15944 rc
= inflate (&strm
, Z_FINISH
);
15945 if (rc
!= Z_STREAM_END
)
15947 rc
= inflateReset (&strm
);
15949 if (inflateEnd (&strm
) != Z_OK
|| rc
!= Z_OK
|| strm
.avail_out
!= 0)
15953 *buffer
= uncompressed_buffer
;
15954 *size
= uncompressed_size
;
15958 free (uncompressed_buffer
);
15959 /* Indicate decompression failure. */
15965 maybe_expand_or_relocate_section (Elf_Internal_Shdr
* section
,
15966 Filedata
* filedata
,
15967 unsigned char ** start_ptr
,
15970 uint64_t section_size
= section
->sh_size
;
15971 unsigned char * start
= * start_ptr
;
15973 if (decompress_dumps
)
15975 uint64_t new_size
= section_size
;
15976 uint64_t uncompressed_size
= 0;
15977 bool is_zstd
= false;
15979 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15981 Elf_Internal_Chdr chdr
;
15982 unsigned int compression_header_size
15983 = get_compression_header (& chdr
, start
, section_size
);
15985 if (compression_header_size
== 0)
15986 /* An error message will have already been generated
15987 by get_compression_header. */
15988 return (uint64_t) -1;
15990 if (chdr
.ch_type
== ch_compress_zlib
)
15993 else if (chdr
.ch_type
== ch_compress_zstd
)
15998 warn (_("section '%s' has unsupported compress type: %d\n"),
15999 printable_section_name (filedata
, section
), chdr
.ch_type
);
16000 return (uint64_t) -1;
16003 uncompressed_size
= chdr
.ch_size
;
16004 start
+= compression_header_size
;
16005 new_size
-= compression_header_size
;
16007 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
16009 /* Read the zlib header. In this case, it should be "ZLIB"
16010 followed by the uncompressed section size, 8 bytes in
16011 big-endian order. */
16012 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
16013 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
16014 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
16015 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
16016 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
16017 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
16018 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
16019 uncompressed_size
+= start
[11];
16024 if (uncompressed_size
)
16026 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
16027 &new_size
, filedata
->file_size
))
16028 section_size
= new_size
;
16031 error (_("Unable to decompress section %s\n"),
16032 printable_section_name (filedata
, section
));
16033 return (uint64_t) -1;
16037 start
= * start_ptr
;
16039 else if (((section
->sh_flags
& SHF_COMPRESSED
) != 0)
16040 || (section_size
> 12 && streq ((char *) start
, "ZLIB")))
16042 printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n"));
16047 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
16048 return (uint64_t) -1;
16052 Elf_Internal_Shdr
*relsec
;
16054 /* If the section being dumped has relocations against it the user might
16055 be expecting these relocations to have been applied. Check for this
16056 case and issue a warning message in order to avoid confusion.
16057 FIXME: Maybe we ought to have an option that dumps a section with
16058 relocs applied ? */
16059 for (relsec
= filedata
->section_headers
;
16060 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
16063 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
16064 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
16065 || filedata
->section_headers
+ relsec
->sh_info
!= section
16066 || relsec
->sh_size
== 0
16067 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
16070 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
16075 * start_ptr
= start
;
16076 return section_size
;
16080 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16082 uint64_t num_bytes
;
16083 unsigned char *data
;
16084 unsigned char *end
;
16085 unsigned char *real_start
;
16086 unsigned char *start
;
16087 bool some_strings_shown
;
16089 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
16091 /* PR 21820: Do not fail if the section was empty. */
16092 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
16094 num_bytes
= section
->sh_size
;
16096 if (filedata
->is_separate
)
16097 printf (_("\nString dump of section '%s' in linked file %s:\n"),
16098 printable_section_name (filedata
, section
),
16099 filedata
->file_name
);
16101 printf (_("\nString dump of section '%s':\n"),
16102 printable_section_name (filedata
, section
));
16104 num_bytes
= maybe_expand_or_relocate_section (section
, filedata
, & start
, false);
16105 if (num_bytes
== (uint64_t) -1)
16109 end
= start
+ num_bytes
;
16110 some_strings_shown
= false;
16112 #ifdef HAVE_MBSTATE_T
16114 /* Initialise the multibyte conversion state. */
16115 memset (& state
, 0, sizeof (state
));
16118 bool continuing
= false;
16122 while (!ISPRINT (* data
))
16123 if (++ data
>= end
)
16128 size_t maxlen
= end
- data
;
16133 continuing
= false;
16137 printf (" [%6tx] ", data
- start
);
16151 /* PR 25543: Treat new-lines as string-ending characters. */
16160 /* Do not print control characters directly as they can affect terminal
16161 settings. Such characters usually appear in the names generated
16162 by the assembler for local labels. */
16165 printf ("^%c", c
+ 0x40);
16167 else if (ISPRINT (c
))
16174 #ifdef HAVE_MBSTATE_T
16177 /* Let printf do the hard work of displaying multibyte characters. */
16178 printf ("%.1s", data
- 1);
16179 #ifdef HAVE_MBSTATE_T
16180 /* Try to find out how many bytes made up the character that was
16181 just printed. Advance the symbol pointer past the bytes that
16183 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
16187 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
16197 printf (_("<corrupt>\n"));
16200 some_strings_shown
= true;
16204 if (! some_strings_shown
)
16205 printf (_(" No strings found in this section."));
16218 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
16219 Filedata
*filedata
,
16223 uint64_t section_size
;
16225 unsigned char *data
;
16226 unsigned char *real_start
;
16227 unsigned char *start
;
16229 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
16231 /* PR 21820: Do not fail if the section was empty. */
16232 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
16234 section_size
= section
->sh_size
;
16236 if (filedata
->is_separate
)
16237 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
16238 printable_section_name (filedata
, section
),
16239 filedata
->file_name
);
16241 printf (_("\nHex dump of section '%s':\n"),
16242 printable_section_name (filedata
, section
));
16244 section_size
= maybe_expand_or_relocate_section (section
, filedata
, & start
, relocate
);
16245 if (section_size
== (uint64_t) -1)
16248 addr
= section
->sh_addr
;
16249 bytes
= section_size
;
16258 lbytes
= (bytes
> 16 ? 16 : bytes
);
16260 printf (" 0x%8.8" PRIx64
" ", addr
);
16262 for (j
= 0; j
< 16; j
++)
16265 printf ("%2.2x", data
[j
]);
16273 for (j
= 0; j
< lbytes
; j
++)
16276 if (k
>= ' ' && k
< 0x7f)
16299 #ifdef ENABLE_LIBCTF
16300 static ctf_sect_t
*
16301 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
16303 buf
->cts_name
= printable_section_name (filedata
, shdr
);
16304 buf
->cts_size
= shdr
->sh_size
;
16305 buf
->cts_entsize
= shdr
->sh_entsize
;
16310 /* Formatting callback function passed to ctf_dump. Returns either the pointer
16311 it is passed, or a pointer to newly-allocated storage, in which case
16312 dump_ctf() will free it when it no longer needs it. */
16315 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
16316 char *s
, void *arg
)
16318 const char *blanks
= arg
;
16321 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
16326 /* Dump CTF errors/warnings. */
16328 dump_ctf_errs (ctf_dict_t
*fp
)
16330 ctf_next_t
*it
= NULL
;
16335 /* Dump accumulated errors and warnings. */
16336 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
16338 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
16342 if (err
!= ECTF_NEXT_END
)
16343 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
16346 /* Dump one CTF archive member. */
16349 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
16352 const char *things
[] = {"Header", "Labels", "Data objects",
16353 "Function objects", "Variables", "Types", "Strings",
16355 const char **thing
;
16358 /* Don't print out the name of the default-named archive member if it appears
16359 first in the list. The name .ctf appears everywhere, even for things that
16360 aren't really archives, so printing it out is liable to be confusing; also,
16361 the common case by far is for only one archive member to exist, and hiding
16362 it in that case seems worthwhile. */
16364 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
16365 printf (_("\nCTF archive member: %s:\n"), name
);
16367 if (ctf_parent_name (ctf
) != NULL
)
16368 ctf_import (ctf
, parent
);
16370 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
16372 ctf_dump_state_t
*s
= NULL
;
16375 printf ("\n %s:\n", *thing
);
16376 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
16377 (void *) " ")) != NULL
)
16379 printf ("%s\n", item
);
16383 if (ctf_errno (ctf
))
16385 error (_("Iteration failed: %s, %s\n"), *thing
,
16386 ctf_errmsg (ctf_errno (ctf
)));
16391 dump_ctf_errs (ctf
);
16395 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16397 Elf_Internal_Shdr
* symtab_sec
= NULL
;
16398 Elf_Internal_Shdr
* strtab_sec
= NULL
;
16399 void * data
= NULL
;
16400 void * symdata
= NULL
;
16401 void * strdata
= NULL
;
16402 ctf_sect_t ctfsect
, symsect
, strsect
;
16403 ctf_sect_t
* symsectp
= NULL
;
16404 ctf_sect_t
* strsectp
= NULL
;
16405 ctf_archive_t
* ctfa
= NULL
;
16406 ctf_dict_t
* parent
= NULL
;
16409 ctf_next_t
*i
= NULL
;
16415 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
16416 data
= get_section_contents (section
, filedata
);
16417 ctfsect
.cts_data
= data
;
16419 if (!dump_ctf_symtab_name
)
16420 dump_ctf_symtab_name
= strdup (".dynsym");
16422 if (!dump_ctf_strtab_name
)
16423 dump_ctf_strtab_name
= strdup (".dynstr");
16425 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
16427 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
16429 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
16432 if ((symdata
= (void *) get_data (NULL
, filedata
,
16433 symtab_sec
->sh_offset
, 1,
16434 symtab_sec
->sh_size
,
16435 _("symbols"))) == NULL
)
16437 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
16438 symsect
.cts_data
= symdata
;
16441 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
16443 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
16445 error (_("No string table section named %s\n"),
16446 dump_ctf_strtab_name
);
16449 if ((strdata
= (void *) get_data (NULL
, filedata
,
16450 strtab_sec
->sh_offset
, 1,
16451 strtab_sec
->sh_size
,
16452 _("strings"))) == NULL
)
16454 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
16455 strsect
.cts_data
= strdata
;
16458 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
16459 libctf papers over the difference, so we can pretend it is always an
16462 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
16464 dump_ctf_errs (NULL
);
16465 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
16469 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
16472 /* Preload the parent dict, since it will need to be imported into every
16474 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
16476 dump_ctf_errs (NULL
);
16477 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
16483 if (filedata
->is_separate
)
16484 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
16485 printable_section_name (filedata
, section
),
16486 filedata
->file_name
);
16488 printf (_("\nDump of CTF section '%s':\n"),
16489 printable_section_name (filedata
, section
));
16491 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
16492 dump_ctf_archive_member (fp
, name
, parent
, member
++);
16493 if (err
!= ECTF_NEXT_END
)
16495 dump_ctf_errs (NULL
);
16496 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
16501 ctf_dict_close (parent
);
16511 dump_section_as_sframe (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16513 void * data
= NULL
;
16514 sframe_decoder_ctx
*sfd_ctx
= NULL
;
16515 const char *print_name
= printable_section_name (filedata
, section
);
16521 if (strcmp (print_name
, "") == 0)
16523 error (_("Section name must be provided \n"));
16528 data
= get_section_contents (section
, filedata
);
16529 sf_size
= section
->sh_size
;
16530 /* Decode the contents of the section. */
16531 sfd_ctx
= sframe_decode ((const char*)data
, sf_size
, &err
);
16535 error (_("SFrame decode failure: %s\n"), sframe_errmsg (err
));
16539 printf (_("Contents of the SFrame section %s:"), print_name
);
16540 /* Dump the contents as text. */
16541 dump_sframe (sfd_ctx
, section
->sh_addr
);
16549 load_specific_debug_section (enum dwarf_section_display_enum debug
,
16550 const Elf_Internal_Shdr
* sec
,
16553 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16555 Filedata
* filedata
= (Filedata
*) data
;
16557 if (section
->start
!= NULL
)
16559 /* If it is already loaded, do nothing. */
16560 if (streq (section
->filename
, filedata
->file_name
))
16562 free (section
->start
);
16565 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
16566 section
->address
= sec
->sh_addr
;
16567 section
->filename
= filedata
->file_name
;
16568 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
16570 sec
->sh_size
, buf
);
16571 if (section
->start
== NULL
)
16575 unsigned char *start
= section
->start
;
16576 uint64_t size
= sec
->sh_size
;
16577 uint64_t uncompressed_size
= 0;
16578 bool is_zstd
= false;
16580 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
16582 Elf_Internal_Chdr chdr
;
16583 unsigned int compression_header_size
;
16585 if (size
< (is_32bit_elf
16586 ? sizeof (Elf32_External_Chdr
)
16587 : sizeof (Elf64_External_Chdr
)))
16589 warn (_("compressed section %s is too small to contain a compression header\n"),
16594 compression_header_size
= get_compression_header (&chdr
, start
, size
);
16595 if (compression_header_size
== 0)
16596 /* An error message will have already been generated
16597 by get_compression_header. */
16600 if (chdr
.ch_type
== ch_compress_zlib
)
16603 else if (chdr
.ch_type
== ch_compress_zstd
)
16608 warn (_("section '%s' has unsupported compress type: %d\n"),
16609 section
->name
, chdr
.ch_type
);
16612 uncompressed_size
= chdr
.ch_size
;
16613 start
+= compression_header_size
;
16614 size
-= compression_header_size
;
16616 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
16618 /* Read the zlib header. In this case, it should be "ZLIB"
16619 followed by the uncompressed section size, 8 bytes in
16620 big-endian order. */
16621 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
16622 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
16623 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
16624 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
16625 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
16626 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
16627 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
16628 uncompressed_size
+= start
[11];
16633 if (uncompressed_size
)
16635 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
16636 &size
, filedata
->file_size
))
16638 /* Free the compressed buffer, update the section buffer
16639 and the section size if uncompress is successful. */
16640 free (section
->start
);
16641 section
->start
= start
;
16645 error (_("Unable to decompress section %s\n"),
16646 printable_section_name (filedata
, sec
));
16651 section
->size
= size
;
16654 if (section
->start
== NULL
)
16657 if (debug_displays
[debug
].relocate
)
16659 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
16660 & section
->reloc_info
, & section
->num_relocs
))
16665 section
->reloc_info
= NULL
;
16666 section
->num_relocs
= 0;
16672 #if HAVE_LIBDEBUGINFOD
16673 /* Return a hex string representation of the build-id. */
16675 get_build_id (void * data
)
16677 Filedata
* filedata
= (Filedata
*) data
;
16678 Elf_Internal_Shdr
* shdr
;
16681 /* Iterate through notes to find note.gnu.build-id.
16682 FIXME: Only the first note in any note section is examined. */
16683 for (i
= 0, shdr
= filedata
->section_headers
;
16684 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
16687 if (shdr
->sh_type
!= SHT_NOTE
)
16692 size_t data_remaining
;
16694 Elf_External_Note
* enote
;
16695 Elf_Internal_Note inote
;
16697 uint64_t offset
= shdr
->sh_offset
;
16698 uint64_t align
= shdr
->sh_addralign
;
16699 uint64_t length
= shdr
->sh_size
;
16701 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
16707 else if (align
!= 4 && align
!= 8)
16713 end
= (char *) enote
+ length
;
16714 data_remaining
= end
- (char *) enote
;
16716 if (!is_ia64_vms (filedata
))
16718 min_notesz
= offsetof (Elf_External_Note
, name
);
16719 if (data_remaining
< min_notesz
)
16722 malformed note encountered in section %s whilst scanning for build-id note\n"),
16723 printable_section_name (filedata
, shdr
));
16727 data_remaining
-= min_notesz
;
16729 inote
.type
= BYTE_GET (enote
->type
);
16730 inote
.namesz
= BYTE_GET (enote
->namesz
);
16731 inote
.namedata
= enote
->name
;
16732 inote
.descsz
= BYTE_GET (enote
->descsz
);
16733 inote
.descdata
= ((char *) enote
16734 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
16735 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16736 next
= ((char *) enote
16737 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
16741 Elf64_External_VMS_Note
*vms_enote
;
16743 /* PR binutils/15191
16744 Make sure that there is enough data to read. */
16745 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
16746 if (data_remaining
< min_notesz
)
16749 malformed note encountered in section %s whilst scanning for build-id note\n"),
16750 printable_section_name (filedata
, shdr
));
16754 data_remaining
-= min_notesz
;
16756 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
16757 inote
.type
= BYTE_GET (vms_enote
->type
);
16758 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
16759 inote
.namedata
= vms_enote
->name
;
16760 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
16761 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
16762 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16763 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
16766 /* Skip malformed notes. */
16767 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
16768 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
16769 || (size_t) (next
- inote
.descdata
) < inote
.descsz
16770 || ((size_t) (next
- inote
.descdata
)
16771 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
16774 malformed note encountered in section %s whilst scanning for build-id note\n"),
16775 printable_section_name (filedata
, shdr
));
16780 /* Check if this is the build-id note. If so then convert the build-id
16781 bytes to a hex string. */
16782 if (inote
.namesz
> 0
16783 && startswith (inote
.namedata
, "GNU")
16784 && inote
.type
== NT_GNU_BUILD_ID
)
16789 build_id
= malloc (inote
.descsz
* 2 + 1);
16790 if (build_id
== NULL
)
16796 for (j
= 0; j
< inote
.descsz
; ++j
)
16797 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
16798 build_id
[inote
.descsz
* 2] = '\0';
16801 return (unsigned char *) build_id
;
16808 #endif /* HAVE_LIBDEBUGINFOD */
16810 /* If this is not NULL, load_debug_section will only look for sections
16811 within the list of sections given here. */
16812 static unsigned int * section_subset
= NULL
;
16815 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
16817 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16818 Elf_Internal_Shdr
* sec
;
16819 Filedata
* filedata
= (Filedata
*) data
;
16821 if (!dump_any_debugging
)
16824 /* Without section headers we cannot find any sections. */
16825 if (filedata
->section_headers
== NULL
)
16828 if (filedata
->string_table
== NULL
16829 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
16830 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
16832 Elf_Internal_Shdr
* strs
;
16834 /* Read in the string table, so that we have section names to scan. */
16835 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
16837 if (strs
!= NULL
&& strs
->sh_size
!= 0)
16839 filedata
->string_table
16840 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
16841 1, strs
->sh_size
, _("string table"));
16843 filedata
->string_table_length
16844 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
16848 /* Locate the debug section. */
16849 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
16851 section
->name
= section
->uncompressed_name
;
16854 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
16856 section
->name
= section
->compressed_name
;
16861 /* If we're loading from a subset of sections, and we've loaded
16862 a section matching this name before, it's likely that it's a
16864 if (section_subset
!= NULL
)
16865 free_debug_section (debug
);
16867 return load_specific_debug_section (debug
, sec
, data
);
16871 free_debug_section (enum dwarf_section_display_enum debug
)
16873 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16875 if (section
->start
== NULL
)
16878 free ((char *) section
->start
);
16879 section
->start
= NULL
;
16880 section
->address
= 0;
16883 free (section
->reloc_info
);
16884 section
->reloc_info
= NULL
;
16885 section
->num_relocs
= 0;
16889 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16891 const char *name
= (section_name_valid (filedata
, section
)
16892 ? section_name (filedata
, section
) : "");
16893 const char *print_name
= printable_section_name (filedata
, section
);
16895 bool result
= true;
16898 length
= section
->sh_size
;
16901 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
16904 if (section
->sh_type
== SHT_NOBITS
)
16906 /* There is no point in dumping the contents of a debugging section
16907 which has the NOBITS type - the bits in the file will be random.
16908 This can happen when a file containing a .eh_frame section is
16909 stripped with the --only-keep-debug command line option. */
16910 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
16915 if (startswith (name
, ".gnu.linkonce.wi."))
16916 name
= ".debug_info";
16918 /* See if we know how to display the contents of this section. */
16919 for (i
= 0; i
< max
; i
++)
16921 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
16922 struct dwarf_section_display
* display
= debug_displays
+ i
;
16923 struct dwarf_section
* sec
= & display
->section
;
16925 if (streq (sec
->uncompressed_name
, name
)
16926 || (id
== line
&& startswith (name
, ".debug_line."))
16927 || streq (sec
->compressed_name
, name
))
16929 bool secondary
= (section
!= find_section (filedata
, name
));
16932 free_debug_section (id
);
16934 if (i
== line
&& startswith (name
, ".debug_line."))
16936 else if (streq (sec
->uncompressed_name
, name
))
16937 sec
->name
= sec
->uncompressed_name
;
16939 sec
->name
= sec
->compressed_name
;
16941 if (load_specific_debug_section (id
, section
, filedata
))
16943 /* If this debug section is part of a CU/TU set in a .dwp file,
16944 restrict load_debug_section to the sections in that set. */
16945 section_subset
= find_cu_tu_set (filedata
, shndx
);
16947 result
&= display
->display (sec
, filedata
);
16949 section_subset
= NULL
;
16951 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
16952 free_debug_section (id
);
16960 printf (_("Unrecognized debug section: %s\n"), print_name
);
16967 /* Set DUMP_SECTS for all sections where dumps were requested
16968 based on section name. */
16971 initialise_dumps_byname (Filedata
* filedata
)
16973 struct dump_list_entry
* cur
;
16975 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
16980 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
16981 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
16982 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
16985 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
16989 if (!any
&& !filedata
->is_separate
)
16990 warn (_("Section '%s' was not dumped because it does not exist\n"),
16996 process_section_contents (Filedata
* filedata
)
16998 Elf_Internal_Shdr
* section
;
17005 initialise_dumps_byname (filedata
);
17007 for (i
= 0, section
= filedata
->section_headers
;
17008 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
17011 dump_type dump
= filedata
->dump
.dump_sects
[i
];
17013 if (filedata
->is_separate
&& ! process_links
)
17014 dump
&= DEBUG_DUMP
;
17016 #ifdef SUPPORT_DISASSEMBLY
17017 if (dump
& DISASS_DUMP
)
17019 if (! disassemble_section (section
, filedata
))
17023 if (dump
& HEX_DUMP
)
17025 if (! dump_section_as_bytes (section
, filedata
, false))
17029 if (dump
& RELOC_DUMP
)
17031 if (! dump_section_as_bytes (section
, filedata
, true))
17035 if (dump
& STRING_DUMP
)
17037 if (! dump_section_as_strings (section
, filedata
))
17041 if (dump
& DEBUG_DUMP
)
17043 if (! display_debug_section (i
, section
, filedata
))
17047 #ifdef ENABLE_LIBCTF
17048 if (dump
& CTF_DUMP
)
17050 if (! dump_section_as_ctf (section
, filedata
))
17054 if (dump
& SFRAME_DUMP
)
17056 if (! dump_section_as_sframe (section
, filedata
))
17061 if (! filedata
->is_separate
)
17063 /* Check to see if the user requested a
17064 dump of a section that does not exist. */
17065 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
17066 if (filedata
->dump
.dump_sects
[i
])
17068 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
17077 process_mips_fpe_exception (int mask
)
17083 if (mask
& OEX_FPU_INEX
)
17084 fputs ("INEX", stdout
), first
= false;
17085 if (mask
& OEX_FPU_UFLO
)
17086 printf ("%sUFLO", first
? "" : "|"), first
= false;
17087 if (mask
& OEX_FPU_OFLO
)
17088 printf ("%sOFLO", first
? "" : "|"), first
= false;
17089 if (mask
& OEX_FPU_DIV0
)
17090 printf ("%sDIV0", first
? "" : "|"), first
= false;
17091 if (mask
& OEX_FPU_INVAL
)
17092 printf ("%sINVAL", first
? "" : "|");
17095 fputs ("0", stdout
);
17098 /* Display's the value of TAG at location P. If TAG is
17099 greater than 0 it is assumed to be an unknown tag, and
17100 a message is printed to this effect. Otherwise it is
17101 assumed that a message has already been printed.
17103 If the bottom bit of TAG is set it assumed to have a
17104 string value, otherwise it is assumed to have an integer
17107 Returns an updated P pointing to the first unread byte
17108 beyond the end of TAG's value.
17110 Reads at or beyond END will not be made. */
17112 static unsigned char *
17113 display_tag_value (signed int tag
,
17115 const unsigned char * const end
)
17120 printf (" Tag_unknown_%d: ", tag
);
17124 warn (_("<corrupt tag>\n"));
17128 /* PR 17531 file: 027-19978-0.004. */
17129 size_t maxlen
= (end
- p
) - 1;
17134 print_symbol_name ((int) maxlen
, (const char *) p
);
17135 p
+= strnlen ((char *) p
, maxlen
) + 1;
17139 printf (_("<corrupt string tag>"));
17140 p
= (unsigned char *) end
;
17146 READ_ULEB (val
, p
, end
);
17147 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
17154 /* ARC ABI attributes section. */
17156 static unsigned char *
17157 display_arc_attribute (unsigned char * p
,
17158 const unsigned char * const end
)
17163 READ_ULEB (tag
, p
, end
);
17167 case Tag_ARC_PCS_config
:
17168 READ_ULEB (val
, p
, end
);
17169 printf (" Tag_ARC_PCS_config: ");
17173 printf (_("Absent/Non standard\n"));
17176 printf (_("Bare metal/mwdt\n"));
17179 printf (_("Bare metal/newlib\n"));
17182 printf (_("Linux/uclibc\n"));
17185 printf (_("Linux/glibc\n"));
17188 printf (_("Unknown\n"));
17193 case Tag_ARC_CPU_base
:
17194 READ_ULEB (val
, p
, end
);
17195 printf (" Tag_ARC_CPU_base: ");
17200 printf (_("Absent\n"));
17202 case TAG_CPU_ARC6xx
:
17203 printf ("ARC6xx\n");
17205 case TAG_CPU_ARC7xx
:
17206 printf ("ARC7xx\n");
17208 case TAG_CPU_ARCEM
:
17209 printf ("ARCEM\n");
17211 case TAG_CPU_ARCHS
:
17212 printf ("ARCHS\n");
17217 case Tag_ARC_CPU_variation
:
17218 READ_ULEB (val
, p
, end
);
17219 printf (" Tag_ARC_CPU_variation: ");
17223 if (val
> 0 && val
< 16)
17224 printf ("Core%d\n", val
);
17226 printf ("Unknown\n");
17230 printf (_("Absent\n"));
17235 case Tag_ARC_CPU_name
:
17236 printf (" Tag_ARC_CPU_name: ");
17237 p
= display_tag_value (-1, p
, end
);
17240 case Tag_ARC_ABI_rf16
:
17241 READ_ULEB (val
, p
, end
);
17242 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
17245 case Tag_ARC_ABI_osver
:
17246 READ_ULEB (val
, p
, end
);
17247 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
17250 case Tag_ARC_ABI_pic
:
17251 case Tag_ARC_ABI_sda
:
17252 READ_ULEB (val
, p
, end
);
17253 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
17254 : " Tag_ARC_ABI_pic: ");
17258 printf (_("Absent\n"));
17267 printf (_("Unknown\n"));
17272 case Tag_ARC_ABI_tls
:
17273 READ_ULEB (val
, p
, end
);
17274 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
17277 case Tag_ARC_ABI_enumsize
:
17278 READ_ULEB (val
, p
, end
);
17279 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
17283 case Tag_ARC_ABI_exceptions
:
17284 READ_ULEB (val
, p
, end
);
17285 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
17289 case Tag_ARC_ABI_double_size
:
17290 READ_ULEB (val
, p
, end
);
17291 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
17294 case Tag_ARC_ISA_config
:
17295 printf (" Tag_ARC_ISA_config: ");
17296 p
= display_tag_value (-1, p
, end
);
17299 case Tag_ARC_ISA_apex
:
17300 printf (" Tag_ARC_ISA_apex: ");
17301 p
= display_tag_value (-1, p
, end
);
17304 case Tag_ARC_ISA_mpy_option
:
17305 READ_ULEB (val
, p
, end
);
17306 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
17309 case Tag_ARC_ATR_version
:
17310 READ_ULEB (val
, p
, end
);
17311 printf (" Tag_ARC_ATR_version: %d\n", val
);
17315 return display_tag_value (tag
& 1, p
, end
);
17321 /* ARM EABI attributes section. */
17326 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
17328 const char *const *table
;
17329 } arm_attr_public_tag
;
17331 static const char *const arm_attr_tag_CPU_arch
[] =
17332 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
17333 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
17334 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
17335 "v8.1-M.mainline", "v9"};
17336 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
17337 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
17338 {"No", "Thumb-1", "Thumb-2", "Yes"};
17339 static const char *const arm_attr_tag_FP_arch
[] =
17340 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
17341 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
17342 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
17343 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
17344 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
17345 "NEON for ARMv8.1"};
17346 static const char *const arm_attr_tag_PCS_config
[] =
17347 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
17348 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
17349 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
17350 {"V6", "SB", "TLS", "Unused"};
17351 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
17352 {"Absolute", "PC-relative", "SB-relative", "None"};
17353 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
17354 {"Absolute", "PC-relative", "None"};
17355 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
17356 {"None", "direct", "GOT-indirect"};
17357 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
17358 {"None", "??? 1", "2", "??? 3", "4"};
17359 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
17360 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
17361 {"Unused", "Needed", "Sign only"};
17362 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
17363 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
17364 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
17365 {"Unused", "Finite", "RTABI", "IEEE 754"};
17366 static const char *const arm_attr_tag_ABI_enum_size
[] =
17367 {"Unused", "small", "int", "forced to int"};
17368 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
17369 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
17370 static const char *const arm_attr_tag_ABI_VFP_args
[] =
17371 {"AAPCS", "VFP registers", "custom", "compatible"};
17372 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
17373 {"AAPCS", "WMMX registers", "custom"};
17374 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
17375 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
17376 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
17377 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
17378 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
17379 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
17380 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
17381 static const char *const arm_attr_tag_FP_HP_extension
[] =
17382 {"Not Allowed", "Allowed"};
17383 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
17384 {"None", "IEEE 754", "Alternative Format"};
17385 static const char *const arm_attr_tag_DSP_extension
[] =
17386 {"Follow architecture", "Allowed"};
17387 static const char *const arm_attr_tag_MPextension_use
[] =
17388 {"Not Allowed", "Allowed"};
17389 static const char *const arm_attr_tag_DIV_use
[] =
17390 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
17391 "Allowed in v7-A with integer division extension"};
17392 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
17393 static const char *const arm_attr_tag_Virtualization_use
[] =
17394 {"Not Allowed", "TrustZone", "Virtualization Extensions",
17395 "TrustZone and Virtualization Extensions"};
17396 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
17397 {"Not Allowed", "Allowed"};
17399 static const char *const arm_attr_tag_MVE_arch
[] =
17400 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
17402 static const char * arm_attr_tag_PAC_extension
[] =
17403 {"No PAC/AUT instructions",
17404 "PAC/AUT instructions permitted in the NOP space",
17405 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
17407 static const char * arm_attr_tag_BTI_extension
[] =
17408 {"BTI instructions not permitted",
17409 "BTI instructions permitted in the NOP space",
17410 "BTI instructions permitted in the NOP and in the non-NOP space"};
17412 static const char * arm_attr_tag_BTI_use
[] =
17413 {"Compiled without branch target enforcement",
17414 "Compiled with branch target enforcement"};
17416 static const char * arm_attr_tag_PACRET_use
[] =
17417 {"Compiled without return address signing and authentication",
17418 "Compiled with return address signing and authentication"};
17420 #define LOOKUP(id, name) \
17421 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
17422 static arm_attr_public_tag arm_attr_public_tags
[] =
17424 {4, "CPU_raw_name", 1, NULL
},
17425 {5, "CPU_name", 1, NULL
},
17426 LOOKUP(6, CPU_arch
),
17427 {7, "CPU_arch_profile", 0, NULL
},
17428 LOOKUP(8, ARM_ISA_use
),
17429 LOOKUP(9, THUMB_ISA_use
),
17430 LOOKUP(10, FP_arch
),
17431 LOOKUP(11, WMMX_arch
),
17432 LOOKUP(12, Advanced_SIMD_arch
),
17433 LOOKUP(13, PCS_config
),
17434 LOOKUP(14, ABI_PCS_R9_use
),
17435 LOOKUP(15, ABI_PCS_RW_data
),
17436 LOOKUP(16, ABI_PCS_RO_data
),
17437 LOOKUP(17, ABI_PCS_GOT_use
),
17438 LOOKUP(18, ABI_PCS_wchar_t
),
17439 LOOKUP(19, ABI_FP_rounding
),
17440 LOOKUP(20, ABI_FP_denormal
),
17441 LOOKUP(21, ABI_FP_exceptions
),
17442 LOOKUP(22, ABI_FP_user_exceptions
),
17443 LOOKUP(23, ABI_FP_number_model
),
17444 {24, "ABI_align_needed", 0, NULL
},
17445 {25, "ABI_align_preserved", 0, NULL
},
17446 LOOKUP(26, ABI_enum_size
),
17447 LOOKUP(27, ABI_HardFP_use
),
17448 LOOKUP(28, ABI_VFP_args
),
17449 LOOKUP(29, ABI_WMMX_args
),
17450 LOOKUP(30, ABI_optimization_goals
),
17451 LOOKUP(31, ABI_FP_optimization_goals
),
17452 {32, "compatibility", 0, NULL
},
17453 LOOKUP(34, CPU_unaligned_access
),
17454 LOOKUP(36, FP_HP_extension
),
17455 LOOKUP(38, ABI_FP_16bit_format
),
17456 LOOKUP(42, MPextension_use
),
17457 LOOKUP(44, DIV_use
),
17458 LOOKUP(46, DSP_extension
),
17459 LOOKUP(48, MVE_arch
),
17460 LOOKUP(50, PAC_extension
),
17461 LOOKUP(52, BTI_extension
),
17462 LOOKUP(74, BTI_use
),
17463 LOOKUP(76, PACRET_use
),
17464 {64, "nodefaults", 0, NULL
},
17465 {65, "also_compatible_with", 0, NULL
},
17466 LOOKUP(66, T2EE_use
),
17467 {67, "conformance", 1, NULL
},
17468 LOOKUP(68, Virtualization_use
),
17469 LOOKUP(70, MPextension_use_legacy
)
17473 static unsigned char *
17474 display_arm_attribute (unsigned char * p
,
17475 const unsigned char * const end
)
17479 arm_attr_public_tag
* attr
;
17483 READ_ULEB (tag
, p
, end
);
17485 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
17487 if (arm_attr_public_tags
[i
].tag
== tag
)
17489 attr
= &arm_attr_public_tags
[i
];
17496 printf (" Tag_%s: ", attr
->name
);
17497 switch (attr
->type
)
17502 case 7: /* Tag_CPU_arch_profile. */
17503 READ_ULEB (val
, p
, end
);
17506 case 0: printf (_("None\n")); break;
17507 case 'A': printf (_("Application\n")); break;
17508 case 'R': printf (_("Realtime\n")); break;
17509 case 'M': printf (_("Microcontroller\n")); break;
17510 case 'S': printf (_("Application or Realtime\n")); break;
17511 default: printf ("??? (%d)\n", val
); break;
17515 case 24: /* Tag_align_needed. */
17516 READ_ULEB (val
, p
, end
);
17519 case 0: printf (_("None\n")); break;
17520 case 1: printf (_("8-byte\n")); break;
17521 case 2: printf (_("4-byte\n")); break;
17522 case 3: printf ("??? 3\n"); break;
17525 printf (_("8-byte and up to %d-byte extended\n"),
17528 printf ("??? (%d)\n", val
);
17533 case 25: /* Tag_align_preserved. */
17534 READ_ULEB (val
, p
, end
);
17537 case 0: printf (_("None\n")); break;
17538 case 1: printf (_("8-byte, except leaf SP\n")); break;
17539 case 2: printf (_("8-byte\n")); break;
17540 case 3: printf ("??? 3\n"); break;
17543 printf (_("8-byte and up to %d-byte extended\n"),
17546 printf ("??? (%d)\n", val
);
17551 case 32: /* Tag_compatibility. */
17553 READ_ULEB (val
, p
, end
);
17554 printf (_("flag = %d, vendor = "), val
);
17557 size_t maxlen
= (end
- p
) - 1;
17559 print_symbol_name ((int) maxlen
, (const char *) p
);
17560 p
+= strnlen ((char *) p
, maxlen
) + 1;
17564 printf (_("<corrupt>"));
17565 p
= (unsigned char *) end
;
17571 case 64: /* Tag_nodefaults. */
17572 /* PR 17531: file: 001-505008-0.01. */
17575 printf (_("True\n"));
17578 case 65: /* Tag_also_compatible_with. */
17579 READ_ULEB (val
, p
, end
);
17580 if (val
== 6 /* Tag_CPU_arch. */)
17582 READ_ULEB (val
, p
, end
);
17583 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
17584 printf ("??? (%d)\n", val
);
17586 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
17590 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
17595 printf (_("<unknown: %d>\n"), tag
);
17601 return display_tag_value (-1, p
, end
);
17603 return display_tag_value (0, p
, end
);
17606 assert (attr
->type
& 0x80);
17607 READ_ULEB (val
, p
, end
);
17608 type
= attr
->type
& 0x7f;
17610 printf ("??? (%d)\n", val
);
17612 printf ("%s\n", attr
->table
[val
]);
17617 return display_tag_value (tag
, p
, end
);
17620 static unsigned char *
17621 display_gnu_attribute (unsigned char * p
,
17622 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
17623 const unsigned char * const end
)
17628 READ_ULEB (tag
, p
, end
);
17630 /* Tag_compatibility is the only generic GNU attribute defined at
17634 READ_ULEB (val
, p
, end
);
17636 printf (_("flag = %d, vendor = "), val
);
17639 printf (_("<corrupt>\n"));
17640 warn (_("corrupt vendor attribute\n"));
17646 size_t maxlen
= (end
- p
) - 1;
17648 print_symbol_name ((int) maxlen
, (const char *) p
);
17649 p
+= strnlen ((char *) p
, maxlen
) + 1;
17653 printf (_("<corrupt>"));
17654 p
= (unsigned char *) end
;
17661 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
17662 return display_proc_gnu_attribute (p
, tag
, end
);
17664 return display_tag_value (tag
, p
, end
);
17667 static unsigned char *
17668 display_m68k_gnu_attribute (unsigned char * p
,
17670 const unsigned char * const end
)
17674 if (tag
== Tag_GNU_M68K_ABI_FP
)
17676 printf (" Tag_GNU_M68K_ABI_FP: ");
17679 printf (_("<corrupt>\n"));
17682 READ_ULEB (val
, p
, end
);
17685 printf ("(%#x), ", val
);
17690 printf (_("unspecified hard/soft float\n"));
17693 printf (_("hard float\n"));
17696 printf (_("soft float\n"));
17702 return display_tag_value (tag
& 1, p
, end
);
17705 static unsigned char *
17706 display_power_gnu_attribute (unsigned char * p
,
17708 const unsigned char * const end
)
17712 if (tag
== Tag_GNU_Power_ABI_FP
)
17714 printf (" Tag_GNU_Power_ABI_FP: ");
17717 printf (_("<corrupt>\n"));
17720 READ_ULEB (val
, p
, end
);
17723 printf ("(%#x), ", val
);
17728 printf (_("unspecified hard/soft float, "));
17731 printf (_("hard float, "));
17734 printf (_("soft float, "));
17737 printf (_("single-precision hard float, "));
17744 printf (_("unspecified long double\n"));
17747 printf (_("128-bit IBM long double\n"));
17750 printf (_("64-bit long double\n"));
17753 printf (_("128-bit IEEE long double\n"));
17759 if (tag
== Tag_GNU_Power_ABI_Vector
)
17761 printf (" Tag_GNU_Power_ABI_Vector: ");
17764 printf (_("<corrupt>\n"));
17767 READ_ULEB (val
, p
, end
);
17770 printf ("(%#x), ", val
);
17775 printf (_("unspecified\n"));
17778 printf (_("generic\n"));
17781 printf ("AltiVec\n");
17790 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
17792 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
17795 printf (_("<corrupt>\n"));
17798 READ_ULEB (val
, p
, end
);
17801 printf ("(%#x), ", val
);
17806 printf (_("unspecified\n"));
17809 printf ("r3/r4\n");
17812 printf (_("memory\n"));
17821 return display_tag_value (tag
& 1, p
, end
);
17824 static unsigned char *
17825 display_s390_gnu_attribute (unsigned char * p
,
17827 const unsigned char * const end
)
17831 if (tag
== Tag_GNU_S390_ABI_Vector
)
17833 printf (" Tag_GNU_S390_ABI_Vector: ");
17834 READ_ULEB (val
, p
, end
);
17839 printf (_("any\n"));
17842 printf (_("software\n"));
17845 printf (_("hardware\n"));
17848 printf ("??? (%d)\n", val
);
17854 return display_tag_value (tag
& 1, p
, end
);
17858 display_sparc_hwcaps (unsigned int mask
)
17864 if (mask
& ELF_SPARC_HWCAP_MUL32
)
17865 fputs ("mul32", stdout
), first
= false;
17866 if (mask
& ELF_SPARC_HWCAP_DIV32
)
17867 printf ("%sdiv32", first
? "" : "|"), first
= false;
17868 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
17869 printf ("%sfsmuld", first
? "" : "|"), first
= false;
17870 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
17871 printf ("%sv8plus", first
? "" : "|"), first
= false;
17872 if (mask
& ELF_SPARC_HWCAP_POPC
)
17873 printf ("%spopc", first
? "" : "|"), first
= false;
17874 if (mask
& ELF_SPARC_HWCAP_VIS
)
17875 printf ("%svis", first
? "" : "|"), first
= false;
17876 if (mask
& ELF_SPARC_HWCAP_VIS2
)
17877 printf ("%svis2", first
? "" : "|"), first
= false;
17878 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
17879 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
17880 if (mask
& ELF_SPARC_HWCAP_FMAF
)
17881 printf ("%sfmaf", first
? "" : "|"), first
= false;
17882 if (mask
& ELF_SPARC_HWCAP_VIS3
)
17883 printf ("%svis3", first
? "" : "|"), first
= false;
17884 if (mask
& ELF_SPARC_HWCAP_HPC
)
17885 printf ("%shpc", first
? "" : "|"), first
= false;
17886 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
17887 printf ("%srandom", first
? "" : "|"), first
= false;
17888 if (mask
& ELF_SPARC_HWCAP_TRANS
)
17889 printf ("%strans", first
? "" : "|"), first
= false;
17890 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
17891 printf ("%sfjfmau", first
? "" : "|"), first
= false;
17892 if (mask
& ELF_SPARC_HWCAP_IMA
)
17893 printf ("%sima", first
? "" : "|"), first
= false;
17894 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
17895 printf ("%scspare", first
? "" : "|"), first
= false;
17898 fputc ('0', stdout
);
17899 fputc ('\n', stdout
);
17903 display_sparc_hwcaps2 (unsigned int mask
)
17909 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
17910 fputs ("fjathplus", stdout
), first
= false;
17911 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
17912 printf ("%svis3b", first
? "" : "|"), first
= false;
17913 if (mask
& ELF_SPARC_HWCAP2_ADP
)
17914 printf ("%sadp", first
? "" : "|"), first
= false;
17915 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
17916 printf ("%ssparc5", first
? "" : "|"), first
= false;
17917 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
17918 printf ("%smwait", first
? "" : "|"), first
= false;
17919 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
17920 printf ("%sxmpmul", first
? "" : "|"), first
= false;
17921 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
17922 printf ("%sxmont2", first
? "" : "|"), first
= false;
17923 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
17924 printf ("%snsec", first
? "" : "|"), first
= false;
17925 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
17926 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
17927 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
17928 printf ("%sfjdes", first
? "" : "|"), first
= false;
17929 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
17930 printf ("%sfjaes", first
? "" : "|"), first
= false;
17933 fputc ('0', stdout
);
17934 fputc ('\n', stdout
);
17937 static unsigned char *
17938 display_sparc_gnu_attribute (unsigned char * p
,
17940 const unsigned char * const end
)
17944 if (tag
== Tag_GNU_Sparc_HWCAPS
)
17946 READ_ULEB (val
, p
, end
);
17947 printf (" Tag_GNU_Sparc_HWCAPS: ");
17948 display_sparc_hwcaps (val
);
17951 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
17953 READ_ULEB (val
, p
, end
);
17954 printf (" Tag_GNU_Sparc_HWCAPS2: ");
17955 display_sparc_hwcaps2 (val
);
17959 return display_tag_value (tag
, p
, end
);
17963 print_mips_fp_abi_value (unsigned int val
)
17967 case Val_GNU_MIPS_ABI_FP_ANY
:
17968 printf (_("Hard or soft float\n"));
17970 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
17971 printf (_("Hard float (double precision)\n"));
17973 case Val_GNU_MIPS_ABI_FP_SINGLE
:
17974 printf (_("Hard float (single precision)\n"));
17976 case Val_GNU_MIPS_ABI_FP_SOFT
:
17977 printf (_("Soft float\n"));
17979 case Val_GNU_MIPS_ABI_FP_OLD_64
:
17980 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
17982 case Val_GNU_MIPS_ABI_FP_XX
:
17983 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
17985 case Val_GNU_MIPS_ABI_FP_64
:
17986 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
17988 case Val_GNU_MIPS_ABI_FP_64A
:
17989 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
17991 case Val_GNU_MIPS_ABI_FP_NAN2008
:
17992 printf (_("NaN 2008 compatibility\n"));
17995 printf ("??? (%d)\n", val
);
18000 static unsigned char *
18001 display_mips_gnu_attribute (unsigned char * p
,
18003 const unsigned char * const end
)
18005 if (tag
== Tag_GNU_MIPS_ABI_FP
)
18009 printf (" Tag_GNU_MIPS_ABI_FP: ");
18010 READ_ULEB (val
, p
, end
);
18011 print_mips_fp_abi_value (val
);
18015 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
18019 printf (" Tag_GNU_MIPS_ABI_MSA: ");
18020 READ_ULEB (val
, p
, end
);
18024 case Val_GNU_MIPS_ABI_MSA_ANY
:
18025 printf (_("Any MSA or not\n"));
18027 case Val_GNU_MIPS_ABI_MSA_128
:
18028 printf (_("128-bit MSA\n"));
18031 printf ("??? (%d)\n", val
);
18037 return display_tag_value (tag
& 1, p
, end
);
18040 static unsigned char *
18041 display_tic6x_attribute (unsigned char * p
,
18042 const unsigned char * const end
)
18047 READ_ULEB (tag
, p
, end
);
18052 printf (" Tag_ISA: ");
18053 READ_ULEB (val
, p
, end
);
18057 case C6XABI_Tag_ISA_none
:
18058 printf (_("None\n"));
18060 case C6XABI_Tag_ISA_C62X
:
18063 case C6XABI_Tag_ISA_C67X
:
18066 case C6XABI_Tag_ISA_C67XP
:
18067 printf ("C67x+\n");
18069 case C6XABI_Tag_ISA_C64X
:
18072 case C6XABI_Tag_ISA_C64XP
:
18073 printf ("C64x+\n");
18075 case C6XABI_Tag_ISA_C674X
:
18076 printf ("C674x\n");
18079 printf ("??? (%d)\n", val
);
18084 case Tag_ABI_wchar_t
:
18085 printf (" Tag_ABI_wchar_t: ");
18086 READ_ULEB (val
, p
, end
);
18090 printf (_("Not used\n"));
18093 printf (_("2 bytes\n"));
18096 printf (_("4 bytes\n"));
18099 printf ("??? (%d)\n", val
);
18104 case Tag_ABI_stack_align_needed
:
18105 printf (" Tag_ABI_stack_align_needed: ");
18106 READ_ULEB (val
, p
, end
);
18110 printf (_("8-byte\n"));
18113 printf (_("16-byte\n"));
18116 printf ("??? (%d)\n", val
);
18121 case Tag_ABI_stack_align_preserved
:
18122 READ_ULEB (val
, p
, end
);
18123 printf (" Tag_ABI_stack_align_preserved: ");
18127 printf (_("8-byte\n"));
18130 printf (_("16-byte\n"));
18133 printf ("??? (%d)\n", val
);
18139 READ_ULEB (val
, p
, end
);
18140 printf (" Tag_ABI_DSBT: ");
18144 printf (_("DSBT addressing not used\n"));
18147 printf (_("DSBT addressing used\n"));
18150 printf ("??? (%d)\n", val
);
18156 READ_ULEB (val
, p
, end
);
18157 printf (" Tag_ABI_PID: ");
18161 printf (_("Data addressing position-dependent\n"));
18164 printf (_("Data addressing position-independent, GOT near DP\n"));
18167 printf (_("Data addressing position-independent, GOT far from DP\n"));
18170 printf ("??? (%d)\n", val
);
18176 READ_ULEB (val
, p
, end
);
18177 printf (" Tag_ABI_PIC: ");
18181 printf (_("Code addressing position-dependent\n"));
18184 printf (_("Code addressing position-independent\n"));
18187 printf ("??? (%d)\n", val
);
18192 case Tag_ABI_array_object_alignment
:
18193 READ_ULEB (val
, p
, end
);
18194 printf (" Tag_ABI_array_object_alignment: ");
18198 printf (_("8-byte\n"));
18201 printf (_("4-byte\n"));
18204 printf (_("16-byte\n"));
18207 printf ("??? (%d)\n", val
);
18212 case Tag_ABI_array_object_align_expected
:
18213 READ_ULEB (val
, p
, end
);
18214 printf (" Tag_ABI_array_object_align_expected: ");
18218 printf (_("8-byte\n"));
18221 printf (_("4-byte\n"));
18224 printf (_("16-byte\n"));
18227 printf ("??? (%d)\n", val
);
18232 case Tag_ABI_compatibility
:
18234 READ_ULEB (val
, p
, end
);
18235 printf (" Tag_ABI_compatibility: ");
18236 printf (_("flag = %d, vendor = "), val
);
18239 size_t maxlen
= (end
- p
) - 1;
18241 print_symbol_name ((int) maxlen
, (const char *) p
);
18242 p
+= strnlen ((char *) p
, maxlen
) + 1;
18246 printf (_("<corrupt>"));
18247 p
= (unsigned char *) end
;
18253 case Tag_ABI_conformance
:
18255 printf (" Tag_ABI_conformance: \"");
18258 size_t maxlen
= (end
- p
) - 1;
18260 print_symbol_name ((int) maxlen
, (const char *) p
);
18261 p
+= strnlen ((char *) p
, maxlen
) + 1;
18265 printf (_("<corrupt>"));
18266 p
= (unsigned char *) end
;
18273 return display_tag_value (tag
, p
, end
);
18277 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
18280 size_t bytes
= end
- p
;
18287 int lbytes
= (bytes
> 16 ? 16 : bytes
);
18289 printf (" 0x%8.8" PRIx64
" ", addr
);
18291 for (j
= 0; j
< 16; j
++)
18294 printf ("%2.2x", p
[j
]);
18302 for (j
= 0; j
< lbytes
; j
++)
18305 if (k
>= ' ' && k
< 0x7f)
18321 static unsigned char *
18322 display_msp430_attribute (unsigned char * p
,
18323 const unsigned char * const end
)
18328 READ_ULEB (tag
, p
, end
);
18332 case OFBA_MSPABI_Tag_ISA
:
18333 printf (" Tag_ISA: ");
18334 READ_ULEB (val
, p
, end
);
18337 case 0: printf (_("None\n")); break;
18338 case 1: printf (_("MSP430\n")); break;
18339 case 2: printf (_("MSP430X\n")); break;
18340 default: printf ("??? (%" PRId64
")\n", val
); break;
18344 case OFBA_MSPABI_Tag_Code_Model
:
18345 printf (" Tag_Code_Model: ");
18346 READ_ULEB (val
, p
, end
);
18349 case 0: printf (_("None\n")); break;
18350 case 1: printf (_("Small\n")); break;
18351 case 2: printf (_("Large\n")); break;
18352 default: printf ("??? (%" PRId64
")\n", val
); break;
18356 case OFBA_MSPABI_Tag_Data_Model
:
18357 printf (" Tag_Data_Model: ");
18358 READ_ULEB (val
, p
, end
);
18361 case 0: printf (_("None\n")); break;
18362 case 1: printf (_("Small\n")); break;
18363 case 2: printf (_("Large\n")); break;
18364 case 3: printf (_("Restricted Large\n")); break;
18365 default: printf ("??? (%" PRId64
")\n", val
); break;
18370 printf (_(" <unknown tag %" PRId64
">: "), tag
);
18377 size_t maxlen
= (end
- p
) - 1;
18379 print_symbol_name ((int) maxlen
, (const char *) p
);
18380 p
+= strnlen ((char *) p
, maxlen
) + 1;
18384 printf (_("<corrupt>"));
18385 p
= (unsigned char *) end
;
18391 READ_ULEB (val
, p
, end
);
18392 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
18401 static unsigned char *
18402 display_msp430_gnu_attribute (unsigned char * p
,
18404 const unsigned char * const end
)
18406 if (tag
== Tag_GNU_MSP430_Data_Region
)
18410 printf (" Tag_GNU_MSP430_Data_Region: ");
18411 READ_ULEB (val
, p
, end
);
18415 case Val_GNU_MSP430_Data_Region_Any
:
18416 printf (_("Any Region\n"));
18418 case Val_GNU_MSP430_Data_Region_Lower
:
18419 printf (_("Lower Region Only\n"));
18422 printf ("??? (%" PRIu64
")\n", val
);
18426 return display_tag_value (tag
& 1, p
, end
);
18429 struct riscv_attr_tag_t
{
18434 static struct riscv_attr_tag_t riscv_attr_tag
[] =
18436 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
18439 T(priv_spec_minor
),
18440 T(priv_spec_revision
),
18441 T(unaligned_access
),
18446 static unsigned char *
18447 display_riscv_attribute (unsigned char *p
,
18448 const unsigned char * const end
)
18452 struct riscv_attr_tag_t
*attr
= NULL
;
18455 READ_ULEB (tag
, p
, end
);
18457 /* Find the name of attribute. */
18458 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
18460 if (riscv_attr_tag
[i
].tag
== tag
)
18462 attr
= &riscv_attr_tag
[i
];
18468 printf (" %s: ", attr
->name
);
18470 return display_tag_value (tag
, p
, end
);
18474 case Tag_RISCV_priv_spec
:
18475 case Tag_RISCV_priv_spec_minor
:
18476 case Tag_RISCV_priv_spec_revision
:
18477 READ_ULEB (val
, p
, end
);
18478 printf ("%" PRIu64
"\n", val
);
18480 case Tag_RISCV_unaligned_access
:
18481 READ_ULEB (val
, p
, end
);
18485 printf (_("No unaligned access\n"));
18488 printf (_("Unaligned access\n"));
18492 case Tag_RISCV_stack_align
:
18493 READ_ULEB (val
, p
, end
);
18494 printf (_("%" PRIu64
"-bytes\n"), val
);
18496 case Tag_RISCV_arch
:
18497 p
= display_tag_value (-1, p
, end
);
18500 return display_tag_value (tag
, p
, end
);
18506 static unsigned char *
18507 display_csky_attribute (unsigned char * p
,
18508 const unsigned char * const end
)
18512 READ_ULEB (tag
, p
, end
);
18514 if (tag
>= Tag_CSKY_MAX
)
18516 return display_tag_value (-1, p
, end
);
18521 case Tag_CSKY_ARCH_NAME
:
18522 printf (" Tag_CSKY_ARCH_NAME:\t\t");
18523 return display_tag_value (-1, p
, end
);
18524 case Tag_CSKY_CPU_NAME
:
18525 printf (" Tag_CSKY_CPU_NAME:\t\t");
18526 return display_tag_value (-1, p
, end
);
18528 case Tag_CSKY_ISA_FLAGS
:
18529 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
18530 return display_tag_value (0, p
, end
);
18531 case Tag_CSKY_ISA_EXT_FLAGS
:
18532 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
18533 return display_tag_value (0, p
, end
);
18535 case Tag_CSKY_DSP_VERSION
:
18536 printf (" Tag_CSKY_DSP_VERSION:\t\t");
18537 READ_ULEB (val
, p
, end
);
18538 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
18539 printf ("DSP Extension\n");
18540 else if (val
== VAL_CSKY_DSP_VERSION_2
)
18541 printf ("DSP 2.0\n");
18544 case Tag_CSKY_VDSP_VERSION
:
18545 printf (" Tag_CSKY_VDSP_VERSION:\t");
18546 READ_ULEB (val
, p
, end
);
18547 printf ("VDSP Version %" PRId64
"\n", val
);
18550 case Tag_CSKY_FPU_VERSION
:
18551 printf (" Tag_CSKY_FPU_VERSION:\t\t");
18552 READ_ULEB (val
, p
, end
);
18553 if (val
== VAL_CSKY_FPU_VERSION_1
)
18554 printf ("ABIV1 FPU Version 1\n");
18555 else if (val
== VAL_CSKY_FPU_VERSION_2
)
18556 printf ("FPU Version 2\n");
18559 case Tag_CSKY_FPU_ABI
:
18560 printf (" Tag_CSKY_FPU_ABI:\t\t");
18561 READ_ULEB (val
, p
, end
);
18562 if (val
== VAL_CSKY_FPU_ABI_HARD
)
18564 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
18565 printf ("SoftFP\n");
18566 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
18569 case Tag_CSKY_FPU_ROUNDING
:
18570 READ_ULEB (val
, p
, end
);
18573 printf (" Tag_CSKY_FPU_ROUNDING:\t");
18574 printf ("Needed\n");
18577 case Tag_CSKY_FPU_DENORMAL
:
18578 READ_ULEB (val
, p
, end
);
18581 printf (" Tag_CSKY_FPU_DENORMAL:\t");
18582 printf ("Needed\n");
18585 case Tag_CSKY_FPU_Exception
:
18586 READ_ULEB (val
, p
, end
);
18589 printf (" Tag_CSKY_FPU_Exception:\t");
18590 printf ("Needed\n");
18593 case Tag_CSKY_FPU_NUMBER_MODULE
:
18594 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
18595 return display_tag_value (-1, p
, end
);
18596 case Tag_CSKY_FPU_HARDFP
:
18597 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
18598 READ_ULEB (val
, p
, end
);
18599 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
18601 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
18602 printf (" Single");
18603 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
18604 printf (" Double");
18608 return display_tag_value (tag
, p
, end
);
18614 process_attributes (Filedata
* filedata
,
18615 const char * public_name
,
18616 unsigned int proc_type
,
18617 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
18618 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
18620 Elf_Internal_Shdr
* sect
;
18624 /* Find the section header so that we get the size. */
18625 for (i
= 0, sect
= filedata
->section_headers
;
18626 i
< filedata
->file_header
.e_shnum
;
18629 unsigned char * contents
;
18632 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
18635 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
18636 sect
->sh_size
, _("attributes"));
18637 if (contents
== NULL
)
18644 /* The first character is the version of the attributes.
18645 Currently only version 1, (aka 'A') is recognised here. */
18648 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
18653 uint64_t section_len
;
18655 section_len
= sect
->sh_size
- 1;
18658 while (section_len
> 0)
18661 unsigned int namelen
;
18662 bool public_section
;
18665 if (section_len
<= 4)
18667 error (_("Tag section ends prematurely\n"));
18671 attr_len
= byte_get (p
, 4);
18674 if (attr_len
> section_len
)
18676 error (_("Bad attribute length (%u > %u)\n"),
18677 (unsigned) attr_len
, (unsigned) section_len
);
18678 attr_len
= section_len
;
18681 /* PR 17531: file: 001-101425-0.004 */
18682 else if (attr_len
< 5)
18684 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
18689 section_len
-= attr_len
;
18692 namelen
= strnlen ((char *) p
, attr_len
) + 1;
18693 if (namelen
== 0 || namelen
>= attr_len
)
18695 error (_("Corrupt attribute section name\n"));
18700 printf (_("Attribute Section: "));
18701 print_symbol_name (INT_MAX
, (const char *) p
);
18704 if (public_name
&& streq ((char *) p
, public_name
))
18705 public_section
= true;
18707 public_section
= false;
18709 if (streq ((char *) p
, "gnu"))
18710 gnu_section
= true;
18712 gnu_section
= false;
18715 attr_len
-= namelen
;
18717 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
18722 unsigned char * end
;
18724 /* PR binutils/17531: Safe handling of corrupt files. */
18727 error (_("Unused bytes at end of section\n"));
18734 size
= byte_get (p
, 4);
18735 if (size
> attr_len
)
18737 error (_("Bad subsection length (%u > %u)\n"),
18738 (unsigned) size
, (unsigned) attr_len
);
18742 /* PR binutils/17531: Safe handling of corrupt files. */
18745 error (_("Bad subsection length (%u < 6)\n"),
18753 end
= p
+ size
- 1;
18754 assert (end
<= contents
+ sect
->sh_size
);
18760 printf (_("File Attributes\n"));
18763 printf (_("Section Attributes:"));
18766 printf (_("Symbol Attributes:"));
18767 /* Fall through. */
18771 READ_ULEB (val
, p
, end
);
18774 printf (" %d", val
);
18779 printf (_("Unknown tag: %d\n"), tag
);
18780 public_section
= false;
18784 if (public_section
&& display_pub_attribute
!= NULL
)
18787 p
= display_pub_attribute (p
, end
);
18790 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
18793 p
= display_gnu_attribute (p
,
18794 display_proc_gnu_attribute
,
18800 printf (_(" Unknown attribute:\n"));
18801 display_raw_attribute (p
, end
);
18816 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
18817 Print the Address, Access and Initial fields of an entry at VMA ADDR
18818 and return the VMA of the next entry, or -1 if there was a problem.
18819 Does not read from DATA_END or beyond. */
18822 print_mips_got_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
,
18823 unsigned char * data_end
)
18826 print_vma (addr
, LONG_HEX
);
18828 if (addr
< pltgot
+ 0xfff0)
18829 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
18831 printf ("%10s", "");
18834 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18838 unsigned char * from
= data
+ addr
- pltgot
;
18840 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
18842 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
18843 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
18844 return (uint64_t) -1;
18848 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18849 print_vma (entry
, LONG_HEX
);
18852 return addr
+ (is_32bit_elf
? 4 : 8);
18855 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
18856 PLTGOT. Print the Address and Initial fields of an entry at VMA
18857 ADDR and return the VMA of the next entry. */
18860 print_mips_pltgot_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
)
18863 print_vma (addr
, LONG_HEX
);
18866 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18871 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18872 print_vma (entry
, LONG_HEX
);
18874 return addr
+ (is_32bit_elf
? 4 : 8);
18878 print_mips_ases (unsigned int mask
)
18880 if (mask
& AFL_ASE_DSP
)
18881 fputs ("\n\tDSP ASE", stdout
);
18882 if (mask
& AFL_ASE_DSPR2
)
18883 fputs ("\n\tDSP R2 ASE", stdout
);
18884 if (mask
& AFL_ASE_DSPR3
)
18885 fputs ("\n\tDSP R3 ASE", stdout
);
18886 if (mask
& AFL_ASE_EVA
)
18887 fputs ("\n\tEnhanced VA Scheme", stdout
);
18888 if (mask
& AFL_ASE_MCU
)
18889 fputs ("\n\tMCU (MicroController) ASE", stdout
);
18890 if (mask
& AFL_ASE_MDMX
)
18891 fputs ("\n\tMDMX ASE", stdout
);
18892 if (mask
& AFL_ASE_MIPS3D
)
18893 fputs ("\n\tMIPS-3D ASE", stdout
);
18894 if (mask
& AFL_ASE_MT
)
18895 fputs ("\n\tMT ASE", stdout
);
18896 if (mask
& AFL_ASE_SMARTMIPS
)
18897 fputs ("\n\tSmartMIPS ASE", stdout
);
18898 if (mask
& AFL_ASE_VIRT
)
18899 fputs ("\n\tVZ ASE", stdout
);
18900 if (mask
& AFL_ASE_MSA
)
18901 fputs ("\n\tMSA ASE", stdout
);
18902 if (mask
& AFL_ASE_MIPS16
)
18903 fputs ("\n\tMIPS16 ASE", stdout
);
18904 if (mask
& AFL_ASE_MICROMIPS
)
18905 fputs ("\n\tMICROMIPS ASE", stdout
);
18906 if (mask
& AFL_ASE_XPA
)
18907 fputs ("\n\tXPA ASE", stdout
);
18908 if (mask
& AFL_ASE_MIPS16E2
)
18909 fputs ("\n\tMIPS16e2 ASE", stdout
);
18910 if (mask
& AFL_ASE_CRC
)
18911 fputs ("\n\tCRC ASE", stdout
);
18912 if (mask
& AFL_ASE_GINV
)
18913 fputs ("\n\tGINV ASE", stdout
);
18914 if (mask
& AFL_ASE_LOONGSON_MMI
)
18915 fputs ("\n\tLoongson MMI ASE", stdout
);
18916 if (mask
& AFL_ASE_LOONGSON_CAM
)
18917 fputs ("\n\tLoongson CAM ASE", stdout
);
18918 if (mask
& AFL_ASE_LOONGSON_EXT
)
18919 fputs ("\n\tLoongson EXT ASE", stdout
);
18920 if (mask
& AFL_ASE_LOONGSON_EXT2
)
18921 fputs ("\n\tLoongson EXT2 ASE", stdout
);
18923 fprintf (stdout
, "\n\t%s", _("None"));
18924 else if ((mask
& ~AFL_ASE_MASK
) != 0)
18925 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
18929 print_mips_isa_ext (unsigned int isa_ext
)
18934 fputs (_("None"), stdout
);
18937 fputs ("RMI XLR", stdout
);
18939 case AFL_EXT_OCTEON3
:
18940 fputs ("Cavium Networks Octeon3", stdout
);
18942 case AFL_EXT_OCTEON2
:
18943 fputs ("Cavium Networks Octeon2", stdout
);
18945 case AFL_EXT_OCTEONP
:
18946 fputs ("Cavium Networks OcteonP", stdout
);
18948 case AFL_EXT_OCTEON
:
18949 fputs ("Cavium Networks Octeon", stdout
);
18952 fputs ("Toshiba R5900", stdout
);
18955 fputs ("MIPS R4650", stdout
);
18958 fputs ("LSI R4010", stdout
);
18961 fputs ("NEC VR4100", stdout
);
18964 fputs ("Toshiba R3900", stdout
);
18966 case AFL_EXT_10000
:
18967 fputs ("MIPS R10000", stdout
);
18970 fputs ("Broadcom SB-1", stdout
);
18973 fputs ("NEC VR4111/VR4181", stdout
);
18976 fputs ("NEC VR4120", stdout
);
18979 fputs ("NEC VR5400", stdout
);
18982 fputs ("NEC VR5500", stdout
);
18984 case AFL_EXT_LOONGSON_2E
:
18985 fputs ("ST Microelectronics Loongson 2E", stdout
);
18987 case AFL_EXT_LOONGSON_2F
:
18988 fputs ("ST Microelectronics Loongson 2F", stdout
);
18990 case AFL_EXT_INTERAPTIV_MR2
:
18991 fputs ("Imagination interAptiv MR2", stdout
);
18994 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
18999 get_mips_reg_size (int reg_size
)
19001 return (reg_size
== AFL_REG_NONE
) ? 0
19002 : (reg_size
== AFL_REG_32
) ? 32
19003 : (reg_size
== AFL_REG_64
) ? 64
19004 : (reg_size
== AFL_REG_128
) ? 128
19009 process_mips_specific (Filedata
* filedata
)
19011 Elf_Internal_Dyn
* entry
;
19012 Elf_Internal_Shdr
*sect
= NULL
;
19013 size_t liblist_offset
= 0;
19014 size_t liblistno
= 0;
19015 size_t conflictsno
= 0;
19016 size_t options_offset
= 0;
19017 size_t conflicts_offset
= 0;
19018 size_t pltrelsz
= 0;
19020 uint64_t pltgot
= 0;
19021 uint64_t mips_pltgot
= 0;
19022 uint64_t jmprel
= 0;
19023 uint64_t local_gotno
= 0;
19024 uint64_t gotsym
= 0;
19025 uint64_t symtabno
= 0;
19028 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
19029 display_mips_gnu_attribute
))
19032 sect
= find_section (filedata
, ".MIPS.abiflags");
19036 Elf_External_ABIFlags_v0
*abiflags_ext
;
19037 Elf_Internal_ABIFlags_v0 abiflags_in
;
19039 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
19041 error (_("Corrupt MIPS ABI Flags section.\n"));
19046 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
19047 sect
->sh_size
, _("MIPS ABI Flags section"));
19050 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
19051 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
19052 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
19053 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
19054 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
19055 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
19056 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
19057 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
19058 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
19059 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
19060 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
19062 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
19063 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
19064 if (abiflags_in
.isa_rev
> 1)
19065 printf ("r%d", abiflags_in
.isa_rev
);
19066 printf ("\nGPR size: %d",
19067 get_mips_reg_size (abiflags_in
.gpr_size
));
19068 printf ("\nCPR1 size: %d",
19069 get_mips_reg_size (abiflags_in
.cpr1_size
));
19070 printf ("\nCPR2 size: %d",
19071 get_mips_reg_size (abiflags_in
.cpr2_size
));
19072 fputs ("\nFP ABI: ", stdout
);
19073 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
19074 fputs ("ISA Extension: ", stdout
);
19075 print_mips_isa_ext (abiflags_in
.isa_ext
);
19076 fputs ("\nASEs:", stdout
);
19077 print_mips_ases (abiflags_in
.ases
);
19078 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
19079 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
19080 fputc ('\n', stdout
);
19081 free (abiflags_ext
);
19086 /* We have a lot of special sections. Thanks SGI! */
19087 if (filedata
->dynamic_section
== NULL
)
19089 /* No dynamic information available. See if there is static GOT. */
19090 sect
= find_section (filedata
, ".got");
19093 unsigned char *data_end
;
19094 unsigned char *data
;
19098 pltgot
= sect
->sh_addr
;
19101 addr_size
= (is_32bit_elf
? 4 : 8);
19102 end
= pltgot
+ sect
->sh_size
;
19104 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
19106 _("Global Offset Table data"));
19107 /* PR 12855: Null data is handled gracefully throughout. */
19108 data_end
= data
+ (end
- pltgot
);
19110 printf (_("\nStatic GOT:\n"));
19111 printf (_(" Canonical gp value: "));
19112 print_vma (ent
+ 0x7ff0, LONG_HEX
);
19115 /* In a dynamic binary GOT[0] is reserved for the dynamic
19116 loader to store the lazy resolver pointer, however in
19117 a static binary it may well have been omitted and GOT
19118 reduced to a table of addresses.
19119 PR 21344: Check for the entry being fully available
19120 before fetching it. */
19122 && data
+ ent
- pltgot
+ addr_size
<= data_end
19123 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
19125 printf (_(" Reserved entries:\n"));
19126 printf (_(" %*s %10s %*s\n"),
19127 addr_size
* 2, _("Address"), _("Access"),
19128 addr_size
* 2, _("Value"));
19129 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19131 if (ent
== (uint64_t) -1)
19132 goto sgot_print_fail
;
19134 /* Check for the MSB of GOT[1] being set, identifying a
19135 GNU object. This entry will be used by some runtime
19136 loaders, to store the module pointer. Otherwise this
19137 is an ordinary local entry.
19138 PR 21344: Check for the entry being fully available
19139 before fetching it. */
19141 && data
+ ent
- pltgot
+ addr_size
<= data_end
19142 && (byte_get (data
+ ent
- pltgot
, addr_size
)
19143 >> (addr_size
* 8 - 1)) != 0)
19145 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19147 if (ent
== (uint64_t) -1)
19148 goto sgot_print_fail
;
19153 if (data
!= NULL
&& ent
< end
)
19155 printf (_(" Local entries:\n"));
19156 printf (" %*s %10s %*s\n",
19157 addr_size
* 2, _("Address"), _("Access"),
19158 addr_size
* 2, _("Value"));
19161 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19163 if (ent
== (uint64_t) -1)
19164 goto sgot_print_fail
;
19175 for (entry
= filedata
->dynamic_section
;
19176 /* PR 17531 file: 012-50589-0.004. */
19177 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
19178 && entry
->d_tag
!= DT_NULL
);
19180 switch (entry
->d_tag
)
19182 case DT_MIPS_LIBLIST
:
19184 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
19185 liblistno
* sizeof (Elf32_External_Lib
));
19187 case DT_MIPS_LIBLISTNO
:
19188 liblistno
= entry
->d_un
.d_val
;
19190 case DT_MIPS_OPTIONS
:
19191 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
19193 case DT_MIPS_CONFLICT
:
19195 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
19196 conflictsno
* sizeof (Elf32_External_Conflict
));
19198 case DT_MIPS_CONFLICTNO
:
19199 conflictsno
= entry
->d_un
.d_val
;
19202 pltgot
= entry
->d_un
.d_ptr
;
19204 case DT_MIPS_LOCAL_GOTNO
:
19205 local_gotno
= entry
->d_un
.d_val
;
19207 case DT_MIPS_GOTSYM
:
19208 gotsym
= entry
->d_un
.d_val
;
19210 case DT_MIPS_SYMTABNO
:
19211 symtabno
= entry
->d_un
.d_val
;
19213 case DT_MIPS_PLTGOT
:
19214 mips_pltgot
= entry
->d_un
.d_ptr
;
19217 pltrel
= entry
->d_un
.d_val
;
19220 pltrelsz
= entry
->d_un
.d_val
;
19223 jmprel
= entry
->d_un
.d_ptr
;
19229 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
19231 Elf32_External_Lib
* elib
;
19234 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
19235 sizeof (Elf32_External_Lib
),
19237 _("liblist section data"));
19240 printf (ngettext ("\nSection '.liblist' contains %zu entry:\n",
19241 "\nSection '.liblist' contains %zu entries:\n",
19244 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
19247 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
19254 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
19255 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
19256 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
19257 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
19258 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
19260 tmp
= gmtime (&atime
);
19261 snprintf (timebuf
, sizeof (timebuf
),
19262 "%04u-%02u-%02uT%02u:%02u:%02u",
19263 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
19264 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
19266 printf ("%3zu: ", cnt
);
19267 if (valid_dynamic_name (filedata
, liblist
.l_name
))
19268 print_symbol_name (20, get_dynamic_name (filedata
, liblist
.l_name
));
19270 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
19271 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
19272 liblist
.l_version
);
19274 if (liblist
.l_flags
== 0)
19278 static const struct
19285 { " EXACT_MATCH", LL_EXACT_MATCH
},
19286 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
19287 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
19288 { " EXPORTS", LL_EXPORTS
},
19289 { " DELAY_LOAD", LL_DELAY_LOAD
},
19290 { " DELTA", LL_DELTA
}
19292 int flags
= liblist
.l_flags
;
19295 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
19296 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
19298 fputs (l_flags_vals
[fcnt
].name
, stdout
);
19299 flags
^= l_flags_vals
[fcnt
].bit
;
19302 printf (" %#x", (unsigned int) flags
);
19314 if (options_offset
!= 0)
19316 Elf_External_Options
* eopt
;
19320 /* Find the section header so that we get the size. */
19321 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
19322 /* PR 17533 file: 012-277276-0.004. */
19325 error (_("No MIPS_OPTIONS header found\n"));
19329 if (sect
->sh_size
< sizeof (* eopt
))
19331 error (_("The MIPS options section is too small.\n"));
19335 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
19336 sect
->sh_size
, _("options"));
19339 Elf_Internal_Options option
;
19342 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
19344 Elf_External_Options
* eoption
;
19345 unsigned int optsize
;
19347 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
19349 optsize
= BYTE_GET (eoption
->size
);
19351 /* PR 17531: file: ffa0fa3b. */
19352 if (optsize
< sizeof (* eopt
)
19353 || optsize
> sect
->sh_size
- offset
)
19355 error (_("Invalid size (%u) for MIPS option\n"),
19364 printf (ngettext ("\nSection '%s' contains %d entry:\n",
19365 "\nSection '%s' contains %d entries:\n",
19367 printable_section_name (filedata
, sect
), cnt
);
19373 Elf_External_Options
* eoption
;
19375 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
19377 option
.kind
= BYTE_GET (eoption
->kind
);
19378 option
.size
= BYTE_GET (eoption
->size
);
19379 option
.section
= BYTE_GET (eoption
->section
);
19380 option
.info
= BYTE_GET (eoption
->info
);
19382 switch (option
.kind
)
19385 /* This shouldn't happen. */
19386 printf (" NULL %" PRId16
" %" PRIx32
,
19387 option
.section
, option
.info
);
19391 printf (" REGINFO ");
19392 if (filedata
->file_header
.e_machine
== EM_MIPS
)
19394 Elf32_External_RegInfo
* ereg
;
19395 Elf32_RegInfo reginfo
;
19398 if (option
.size
< (sizeof (Elf_External_Options
)
19399 + sizeof (Elf32_External_RegInfo
)))
19401 printf (_("<corrupt>\n"));
19402 error (_("Truncated MIPS REGINFO option\n"));
19407 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
19409 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
19410 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
19411 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
19412 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
19413 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
19414 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
19416 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
19417 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
19419 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
19420 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
19421 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
19422 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
19427 Elf64_External_RegInfo
* ereg
;
19428 Elf64_Internal_RegInfo reginfo
;
19430 if (option
.size
< (sizeof (Elf_External_Options
)
19431 + sizeof (Elf64_External_RegInfo
)))
19433 printf (_("<corrupt>\n"));
19434 error (_("Truncated MIPS REGINFO option\n"));
19439 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
19440 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
19441 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
19442 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
19443 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
19444 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
19445 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
19447 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
19448 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
19450 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
19451 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
19452 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
19453 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
19455 offset
+= option
.size
;
19458 case ODK_EXCEPTIONS
:
19459 fputs (" EXCEPTIONS fpe_min(", stdout
);
19460 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
19461 fputs (") fpe_max(", stdout
);
19462 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
19463 fputs (")", stdout
);
19465 if (option
.info
& OEX_PAGE0
)
19466 fputs (" PAGE0", stdout
);
19467 if (option
.info
& OEX_SMM
)
19468 fputs (" SMM", stdout
);
19469 if (option
.info
& OEX_FPDBUG
)
19470 fputs (" FPDBUG", stdout
);
19471 if (option
.info
& OEX_DISMISS
)
19472 fputs (" DISMISS", stdout
);
19476 fputs (" PAD ", stdout
);
19477 if (option
.info
& OPAD_PREFIX
)
19478 fputs (" PREFIX", stdout
);
19479 if (option
.info
& OPAD_POSTFIX
)
19480 fputs (" POSTFIX", stdout
);
19481 if (option
.info
& OPAD_SYMBOL
)
19482 fputs (" SYMBOL", stdout
);
19486 fputs (" HWPATCH ", stdout
);
19487 if (option
.info
& OHW_R4KEOP
)
19488 fputs (" R4KEOP", stdout
);
19489 if (option
.info
& OHW_R8KPFETCH
)
19490 fputs (" R8KPFETCH", stdout
);
19491 if (option
.info
& OHW_R5KEOP
)
19492 fputs (" R5KEOP", stdout
);
19493 if (option
.info
& OHW_R5KCVTL
)
19494 fputs (" R5KCVTL", stdout
);
19498 fputs (" FILL ", stdout
);
19499 /* XXX Print content of info word? */
19503 fputs (" TAGS ", stdout
);
19504 /* XXX Print content of info word? */
19508 fputs (" HWAND ", stdout
);
19509 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
19510 fputs (" R4KEOP_CHECKED", stdout
);
19511 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
19512 fputs (" R4KEOP_CLEAN", stdout
);
19516 fputs (" HWOR ", stdout
);
19517 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
19518 fputs (" R4KEOP_CHECKED", stdout
);
19519 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
19520 fputs (" R4KEOP_CLEAN", stdout
);
19524 printf (" GP_GROUP %#06x self-contained %#06x",
19525 option
.info
& OGP_GROUP
,
19526 (option
.info
& OGP_SELF
) >> 16);
19530 printf (" IDENT %#06x self-contained %#06x",
19531 option
.info
& OGP_GROUP
,
19532 (option
.info
& OGP_SELF
) >> 16);
19536 /* This shouldn't happen. */
19537 printf (" %3d ??? %" PRId16
" %" PRIx32
,
19538 option
.kind
, option
.section
, option
.info
);
19542 len
= sizeof (* eopt
);
19543 while (len
< option
.size
)
19545 unsigned char datum
= *((unsigned char *) eoption
+ len
);
19547 if (ISPRINT (datum
))
19548 printf ("%c", datum
);
19550 printf ("\\%03o", datum
);
19553 fputs ("\n", stdout
);
19555 offset
+= option
.size
;
19563 if (conflicts_offset
!= 0 && conflictsno
!= 0)
19565 Elf32_Conflict
* iconf
;
19568 if (filedata
->dynamic_symbols
== NULL
)
19570 error (_("conflict list found without a dynamic symbol table\n"));
19574 /* PR 21345 - print a slightly more helpful error message
19575 if we are sure that the cmalloc will fail. */
19576 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
19578 error (_("Overlarge number of conflicts detected: %zx\n"),
19583 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
19586 error (_("Out of memory allocating space for dynamic conflicts\n"));
19592 Elf32_External_Conflict
* econf32
;
19594 econf32
= (Elf32_External_Conflict
*)
19595 get_data (NULL
, filedata
, conflicts_offset
,
19596 sizeof (*econf32
), conflictsno
, _("conflict"));
19603 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19604 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
19610 Elf64_External_Conflict
* econf64
;
19612 econf64
= (Elf64_External_Conflict
*)
19613 get_data (NULL
, filedata
, conflicts_offset
,
19614 sizeof (*econf64
), conflictsno
, _("conflict"));
19621 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19622 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
19627 printf (ngettext ("\nSection '.conflict' contains %zu entry:\n",
19628 "\nSection '.conflict' contains %zu entries:\n",
19631 puts (_(" Num: Index Value Name"));
19633 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19635 printf ("%5zu: %8lu ", cnt
, iconf
[cnt
]);
19637 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
19638 printf (_("<corrupt symbol index>"));
19641 Elf_Internal_Sym
* psym
;
19643 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
19644 print_vma (psym
->st_value
, FULL_HEX
);
19646 if (valid_dynamic_name (filedata
, psym
->st_name
))
19647 print_symbol_name (25, get_dynamic_name (filedata
, psym
->st_name
));
19649 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19657 if (pltgot
!= 0 && local_gotno
!= 0)
19659 uint64_t ent
, local_end
, global_end
;
19661 unsigned char * data
;
19662 unsigned char * data_end
;
19666 addr_size
= (is_32bit_elf
? 4 : 8);
19667 local_end
= pltgot
+ local_gotno
* addr_size
;
19669 /* PR binutils/17533 file: 012-111227-0.004 */
19670 if (symtabno
< gotsym
)
19672 error (_("The GOT symbol offset (%" PRIu64
19673 ") is greater than the symbol table size (%" PRIu64
")\n"),
19678 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
19679 /* PR 17531: file: 54c91a34. */
19680 if (global_end
< local_end
)
19682 error (_("Too many GOT symbols: %" PRIu64
"\n"), symtabno
);
19686 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
19687 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
19688 global_end
- pltgot
, 1,
19689 _("Global Offset Table data"));
19690 /* PR 12855: Null data is handled gracefully throughout. */
19691 data_end
= data
+ (global_end
- pltgot
);
19693 printf (_("\nPrimary GOT:\n"));
19694 printf (_(" Canonical gp value: "));
19695 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
19698 printf (_(" Reserved entries:\n"));
19699 printf (_(" %*s %10s %*s Purpose\n"),
19700 addr_size
* 2, _("Address"), _("Access"),
19701 addr_size
* 2, _("Initial"));
19702 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19703 printf (_(" Lazy resolver\n"));
19704 if (ent
== (uint64_t) -1)
19705 goto got_print_fail
;
19707 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
19708 This entry will be used by some runtime loaders, to store the
19709 module pointer. Otherwise this is an ordinary local entry.
19710 PR 21344: Check for the entry being fully available before
19713 && data
+ ent
- pltgot
+ addr_size
<= data_end
19714 && (byte_get (data
+ ent
- pltgot
, addr_size
)
19715 >> (addr_size
* 8 - 1)) != 0)
19717 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19718 printf (_(" Module pointer (GNU extension)\n"));
19719 if (ent
== (uint64_t) -1)
19720 goto got_print_fail
;
19724 if (data
!= NULL
&& ent
< local_end
)
19726 printf (_(" Local entries:\n"));
19727 printf (" %*s %10s %*s\n",
19728 addr_size
* 2, _("Address"), _("Access"),
19729 addr_size
* 2, _("Initial"));
19730 while (ent
< local_end
)
19732 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19734 if (ent
== (uint64_t) -1)
19735 goto got_print_fail
;
19740 if (data
!= NULL
&& gotsym
< symtabno
)
19744 printf (_(" Global entries:\n"));
19745 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
19746 addr_size
* 2, _("Address"),
19748 addr_size
* 2, _("Initial"),
19749 addr_size
* 2, _("Sym.Val."),
19751 /* Note for translators: "Ndx" = abbreviated form of "Index". */
19752 _("Ndx"), _("Name"));
19754 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
19756 for (i
= gotsym
; i
< symtabno
; i
++)
19758 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19761 if (filedata
->dynamic_symbols
== NULL
)
19762 printf (_("<no dynamic symbols>"));
19763 else if (i
< filedata
->num_dynamic_syms
)
19765 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
19767 print_vma (psym
->st_value
, LONG_HEX
);
19768 printf (" %-7s ", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
19771 const char * s
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
19773 printf ("%3s ", s
);
19775 printf ("%3u ", psym
->st_shndx
);
19777 if (valid_dynamic_name (filedata
, psym
->st_name
))
19778 print_symbol_name (sym_width
,
19779 get_dynamic_name (filedata
, psym
->st_name
));
19781 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19784 printf (_("<symbol index %zu exceeds number of dynamic symbols>"),
19788 if (ent
== (uint64_t) -1)
19798 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
19801 uint64_t offset
, rel_offset
;
19803 unsigned char * data
;
19804 int addr_size
, sym_width
;
19805 Elf_Internal_Rela
* rels
;
19807 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
19808 if (pltrel
== DT_RELA
)
19810 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19815 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19820 addr_size
= (is_32bit_elf
? 4 : 8);
19821 end
= mips_pltgot
+ (2 + count
) * addr_size
;
19823 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
19824 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
19825 1, _("Procedure Linkage Table data"));
19832 printf ("\nPLT GOT:\n\n");
19833 printf (_(" Reserved entries:\n"));
19834 printf (_(" %*s %*s Purpose\n"),
19835 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
19836 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19837 printf (_(" PLT lazy resolver\n"));
19838 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19839 printf (_(" Module pointer\n"));
19842 printf (_(" Entries:\n"));
19843 printf (" %*s %*s %*s %-7s %3s %s\n",
19844 addr_size
* 2, _("Address"),
19845 addr_size
* 2, _("Initial"),
19846 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
19847 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
19848 for (i
= 0; i
< count
; i
++)
19850 uint64_t idx
= get_reloc_symindex (rels
[i
].r_info
);
19852 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19855 if (idx
>= filedata
->num_dynamic_syms
)
19856 printf (_("<corrupt symbol index: %" PRIu64
">"), idx
);
19859 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
19861 print_vma (psym
->st_value
, LONG_HEX
);
19862 printf (" %-7s %3s ",
19863 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19864 printable_section_name_from_index (filedata
, psym
->st_shndx
, NULL
));
19865 if (valid_dynamic_name (filedata
, psym
->st_name
))
19866 print_symbol_name (sym_width
,
19867 get_dynamic_name (filedata
, psym
->st_name
));
19869 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19883 process_nds32_specific (Filedata
* filedata
)
19885 Elf_Internal_Shdr
*sect
= NULL
;
19887 sect
= find_section (filedata
, ".nds32_e_flags");
19888 if (sect
!= NULL
&& sect
->sh_size
>= 4)
19890 unsigned char *buf
;
19893 printf ("\nNDS32 elf flags section:\n");
19894 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
19895 _("NDS32 elf flags section"));
19900 flag
= byte_get (buf
, 4);
19902 switch (flag
& 0x3)
19905 printf ("(VEC_SIZE):\tNo entry.\n");
19908 printf ("(VEC_SIZE):\t4 bytes\n");
19911 printf ("(VEC_SIZE):\t16 bytes\n");
19914 printf ("(VEC_SIZE):\treserved\n");
19923 process_gnu_liblist (Filedata
* filedata
)
19925 Elf_Internal_Shdr
* section
;
19926 Elf_Internal_Shdr
* string_sec
;
19927 Elf32_External_Lib
* elib
;
19929 size_t strtab_size
;
19931 uint64_t num_liblist
;
19938 for (i
= 0, section
= filedata
->section_headers
;
19939 i
< filedata
->file_header
.e_shnum
;
19942 switch (section
->sh_type
)
19944 case SHT_GNU_LIBLIST
:
19945 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
19948 elib
= (Elf32_External_Lib
*)
19949 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
19950 _("liblist section data"));
19958 string_sec
= filedata
->section_headers
+ section
->sh_link
;
19959 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
19960 string_sec
->sh_size
,
19961 _("liblist string table"));
19963 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
19970 strtab_size
= string_sec
->sh_size
;
19972 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
19973 printf (ngettext ("\nLibrary list section '%s' contains %" PRIu64
19975 "\nLibrary list section '%s' contains %" PRIu64
19978 printable_section_name (filedata
, section
),
19981 puts (_(" Library Time Stamp Checksum Version Flags"));
19983 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
19991 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
19992 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
19993 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
19994 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
19995 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
19997 tmp
= gmtime (&atime
);
19998 snprintf (timebuf
, sizeof (timebuf
),
19999 "%04u-%02u-%02uT%02u:%02u:%02u",
20000 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
20001 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
20003 printf ("%3zu: ", cnt
);
20005 printf ("%-20s", liblist
.l_name
< strtab_size
20006 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
20008 printf ("%-20.20s", liblist
.l_name
< strtab_size
20009 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
20010 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
20011 liblist
.l_version
, liblist
.l_flags
);
20022 static const char *
20023 get_note_type (Filedata
* filedata
, unsigned e_type
)
20025 static char buff
[64];
20027 if (filedata
->file_header
.e_type
== ET_CORE
)
20031 return _("NT_AUXV (auxiliary vector)");
20033 return _("NT_PRSTATUS (prstatus structure)");
20035 return _("NT_FPREGSET (floating point registers)");
20037 return _("NT_PRPSINFO (prpsinfo structure)");
20038 case NT_TASKSTRUCT
:
20039 return _("NT_TASKSTRUCT (task structure)");
20041 return _("NT_GDB_TDESC (GDB XML target description)");
20043 return _("NT_PRXFPREG (user_xfpregs structure)");
20045 return _("NT_PPC_VMX (ppc Altivec registers)");
20047 return _("NT_PPC_VSX (ppc VSX registers)");
20049 return _("NT_PPC_TAR (ppc TAR register)");
20051 return _("NT_PPC_PPR (ppc PPR register)");
20053 return _("NT_PPC_DSCR (ppc DSCR register)");
20055 return _("NT_PPC_EBB (ppc EBB registers)");
20057 return _("NT_PPC_PMU (ppc PMU registers)");
20058 case NT_PPC_TM_CGPR
:
20059 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
20060 case NT_PPC_TM_CFPR
:
20061 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
20062 case NT_PPC_TM_CVMX
:
20063 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
20064 case NT_PPC_TM_CVSX
:
20065 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
20066 case NT_PPC_TM_SPR
:
20067 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
20068 case NT_PPC_TM_CTAR
:
20069 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
20070 case NT_PPC_TM_CPPR
:
20071 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
20072 case NT_PPC_TM_CDSCR
:
20073 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
20075 return _("NT_386_TLS (x86 TLS information)");
20076 case NT_386_IOPERM
:
20077 return _("NT_386_IOPERM (x86 I/O permissions)");
20078 case NT_X86_XSTATE
:
20079 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
20081 return _("NT_X86_CET (x86 CET state)");
20082 case NT_S390_HIGH_GPRS
:
20083 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
20084 case NT_S390_TIMER
:
20085 return _("NT_S390_TIMER (s390 timer register)");
20086 case NT_S390_TODCMP
:
20087 return _("NT_S390_TODCMP (s390 TOD comparator register)");
20088 case NT_S390_TODPREG
:
20089 return _("NT_S390_TODPREG (s390 TOD programmable register)");
20091 return _("NT_S390_CTRS (s390 control registers)");
20092 case NT_S390_PREFIX
:
20093 return _("NT_S390_PREFIX (s390 prefix register)");
20094 case NT_S390_LAST_BREAK
:
20095 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
20096 case NT_S390_SYSTEM_CALL
:
20097 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
20099 return _("NT_S390_TDB (s390 transaction diagnostic block)");
20100 case NT_S390_VXRS_LOW
:
20101 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
20102 case NT_S390_VXRS_HIGH
:
20103 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
20104 case NT_S390_GS_CB
:
20105 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
20106 case NT_S390_GS_BC
:
20107 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
20109 return _("NT_ARM_VFP (arm VFP registers)");
20111 return _("NT_ARM_TLS (AArch TLS registers)");
20112 case NT_ARM_HW_BREAK
:
20113 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
20114 case NT_ARM_HW_WATCH
:
20115 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
20116 case NT_ARM_SYSTEM_CALL
:
20117 return _("NT_ARM_SYSTEM_CALL (AArch system call number)");
20119 return _("NT_ARM_SVE (AArch SVE registers)");
20120 case NT_ARM_PAC_MASK
:
20121 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
20122 case NT_ARM_PACA_KEYS
:
20123 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
20124 case NT_ARM_PACG_KEYS
:
20125 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
20126 case NT_ARM_TAGGED_ADDR_CTRL
:
20127 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
20129 return _("NT_ARM_SSVE (AArch64 streaming SVE registers)");
20131 return _("NT_ARM_ZA (AArch64 SME ZA register)");
20133 return _("NT_ARM_ZT (AArch64 SME2 ZT registers)");
20134 case NT_ARM_PAC_ENABLED_KEYS
:
20135 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
20137 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
20139 return _("NT_RISCV_CSR (RISC-V control and status registers)");
20141 return _("NT_PSTATUS (pstatus structure)");
20143 return _("NT_FPREGS (floating point registers)");
20145 return _("NT_PSINFO (psinfo structure)");
20147 return _("NT_LWPSTATUS (lwpstatus_t structure)");
20149 return _("NT_LWPSINFO (lwpsinfo_t structure)");
20150 case NT_WIN32PSTATUS
:
20151 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
20153 return _("NT_SIGINFO (siginfo_t data)");
20155 return _("NT_FILE (mapped files)");
20163 return _("NT_VERSION (version)");
20165 return _("NT_ARCH (architecture)");
20166 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
20168 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
20170 case NT_GO_BUILDID
:
20171 return _("GO BUILDID");
20172 case FDO_PACKAGING_METADATA
:
20173 return _("FDO_PACKAGING_METADATA");
20178 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20183 print_core_note (Elf_Internal_Note
*pnote
)
20185 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
20186 uint64_t count
, page_size
;
20187 unsigned char *descdata
, *filenames
, *descend
;
20189 if (pnote
->type
!= NT_FILE
)
20198 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
20199 /* Still "successful". */
20203 if (pnote
->descsz
< 2 * addr_size
)
20205 error (_(" Malformed note - too short for header\n"));
20209 descdata
= (unsigned char *) pnote
->descdata
;
20210 descend
= descdata
+ pnote
->descsz
;
20212 if (descdata
[pnote
->descsz
- 1] != '\0')
20214 error (_(" Malformed note - does not end with \\0\n"));
20218 count
= byte_get (descdata
, addr_size
);
20219 descdata
+= addr_size
;
20221 page_size
= byte_get (descdata
, addr_size
);
20222 descdata
+= addr_size
;
20224 if (count
> ((uint64_t) -1 - 2 * addr_size
) / (3 * addr_size
)
20225 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
20227 error (_(" Malformed note - too short for supplied file count\n"));
20231 printf (_(" Page size: "));
20232 print_vma (page_size
, DEC
);
20235 printf (_(" %*s%*s%*s\n"),
20236 (int) (2 + 2 * addr_size
), _("Start"),
20237 (int) (4 + 2 * addr_size
), _("End"),
20238 (int) (4 + 2 * addr_size
), _("Page Offset"));
20239 filenames
= descdata
+ count
* 3 * addr_size
;
20240 while (count
-- > 0)
20242 uint64_t start
, end
, file_ofs
;
20244 if (filenames
== descend
)
20246 error (_(" Malformed note - filenames end too early\n"));
20250 start
= byte_get (descdata
, addr_size
);
20251 descdata
+= addr_size
;
20252 end
= byte_get (descdata
, addr_size
);
20253 descdata
+= addr_size
;
20254 file_ofs
= byte_get (descdata
, addr_size
);
20255 descdata
+= addr_size
;
20258 print_vma (start
, FULL_HEX
);
20260 print_vma (end
, FULL_HEX
);
20262 print_vma (file_ofs
, FULL_HEX
);
20263 printf ("\n %s\n", filenames
);
20265 filenames
+= 1 + strlen ((char *) filenames
);
20271 static const char *
20272 get_gnu_elf_note_type (unsigned e_type
)
20274 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
20277 case NT_GNU_ABI_TAG
:
20278 return _("NT_GNU_ABI_TAG (ABI version tag)");
20280 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
20281 case NT_GNU_BUILD_ID
:
20282 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
20283 case NT_GNU_GOLD_VERSION
:
20284 return _("NT_GNU_GOLD_VERSION (gold version)");
20285 case NT_GNU_PROPERTY_TYPE_0
:
20286 return _("NT_GNU_PROPERTY_TYPE_0");
20287 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
20288 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
20289 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
20290 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
20293 static char buff
[64];
20295 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20302 decode_x86_compat_isa (unsigned int bitmask
)
20306 unsigned int bit
= bitmask
& (- bitmask
);
20311 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
20314 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
20317 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
20320 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
20323 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
20326 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
20329 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
20332 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
20335 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
20338 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
20341 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
20344 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
20345 printf ("AVX512F");
20347 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
20348 printf ("AVX512CD");
20350 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
20351 printf ("AVX512ER");
20353 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
20354 printf ("AVX512PF");
20356 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
20357 printf ("AVX512VL");
20359 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
20360 printf ("AVX512DQ");
20362 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
20363 printf ("AVX512BW");
20366 printf (_("<unknown: %x>"), bit
);
20375 decode_x86_compat_2_isa (unsigned int bitmask
)
20379 printf (_("<None>"));
20385 unsigned int bit
= bitmask
& (- bitmask
);
20390 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
20393 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
20396 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
20399 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
20402 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
20405 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
20408 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
20411 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
20414 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
20417 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
20420 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
20421 printf ("AVX512F");
20423 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
20424 printf ("AVX512CD");
20426 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
20427 printf ("AVX512ER");
20429 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
20430 printf ("AVX512PF");
20432 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
20433 printf ("AVX512VL");
20435 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
20436 printf ("AVX512DQ");
20438 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
20439 printf ("AVX512BW");
20441 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
20442 printf ("AVX512_4FMAPS");
20444 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
20445 printf ("AVX512_4VNNIW");
20447 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
20448 printf ("AVX512_BITALG");
20450 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
20451 printf ("AVX512_IFMA");
20453 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
20454 printf ("AVX512_VBMI");
20456 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
20457 printf ("AVX512_VBMI2");
20459 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
20460 printf ("AVX512_VNNI");
20462 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
20463 printf ("AVX512_BF16");
20466 printf (_("<unknown: %x>"), bit
);
20474 static const char *
20475 get_amdgpu_elf_note_type (unsigned int e_type
)
20479 case NT_AMDGPU_METADATA
:
20480 return _("NT_AMDGPU_METADATA (code object metadata)");
20483 static char buf
[64];
20484 snprintf (buf
, sizeof (buf
), _("Unknown note type: (0x%08x)"), e_type
);
20491 decode_x86_isa (unsigned int bitmask
)
20495 unsigned int bit
= bitmask
& (- bitmask
);
20500 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
20501 printf ("x86-64-baseline");
20503 case GNU_PROPERTY_X86_ISA_1_V2
:
20504 printf ("x86-64-v2");
20506 case GNU_PROPERTY_X86_ISA_1_V3
:
20507 printf ("x86-64-v3");
20509 case GNU_PROPERTY_X86_ISA_1_V4
:
20510 printf ("x86-64-v4");
20513 printf (_("<unknown: %x>"), bit
);
20522 decode_x86_feature_1 (unsigned int bitmask
)
20526 printf (_("<None>"));
20532 unsigned int bit
= bitmask
& (- bitmask
);
20537 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
20540 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
20543 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
20544 printf ("LAM_U48");
20546 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
20547 printf ("LAM_U57");
20550 printf (_("<unknown: %x>"), bit
);
20559 decode_x86_feature_2 (unsigned int bitmask
)
20563 printf (_("<None>"));
20569 unsigned int bit
= bitmask
& (- bitmask
);
20574 case GNU_PROPERTY_X86_FEATURE_2_X86
:
20577 case GNU_PROPERTY_X86_FEATURE_2_X87
:
20580 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
20583 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
20586 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
20589 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
20592 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
20595 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
20598 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
20601 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
20604 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
20605 printf ("XSAVEOPT");
20607 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
20611 printf (_("<unknown: %x>"), bit
);
20620 decode_aarch64_feature_1_and (unsigned int bitmask
)
20624 unsigned int bit
= bitmask
& (- bitmask
);
20629 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
20633 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
20638 printf (_("<unknown: %x>"), bit
);
20647 decode_1_needed (unsigned int bitmask
)
20651 unsigned int bit
= bitmask
& (- bitmask
);
20656 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
20657 printf ("indirect external access");
20660 printf (_("<unknown: %x>"), bit
);
20669 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
20671 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
20672 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
20673 unsigned int size
= is_32bit_elf
? 4 : 8;
20675 printf (_(" Properties: "));
20677 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
20679 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
20683 while (ptr
< ptr_end
)
20687 unsigned int datasz
;
20689 if ((size_t) (ptr_end
- ptr
) < 8)
20691 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
20695 type
= byte_get (ptr
, 4);
20696 datasz
= byte_get (ptr
+ 4, 4);
20700 if (datasz
> (size_t) (ptr_end
- ptr
))
20702 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
20707 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
20709 if (filedata
->file_header
.e_machine
== EM_X86_64
20710 || filedata
->file_header
.e_machine
== EM_IAMCU
20711 || filedata
->file_header
.e_machine
== EM_386
)
20713 unsigned int bitmask
;
20716 bitmask
= byte_get (ptr
, 4);
20722 case GNU_PROPERTY_X86_ISA_1_USED
:
20724 printf (_("x86 ISA used: <corrupt length: %#x> "),
20728 printf ("x86 ISA used: ");
20729 decode_x86_isa (bitmask
);
20733 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
20735 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20739 printf ("x86 ISA needed: ");
20740 decode_x86_isa (bitmask
);
20744 case GNU_PROPERTY_X86_FEATURE_1_AND
:
20746 printf (_("x86 feature: <corrupt length: %#x> "),
20750 printf ("x86 feature: ");
20751 decode_x86_feature_1 (bitmask
);
20755 case GNU_PROPERTY_X86_FEATURE_2_USED
:
20757 printf (_("x86 feature used: <corrupt length: %#x> "),
20761 printf ("x86 feature used: ");
20762 decode_x86_feature_2 (bitmask
);
20766 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
20768 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
20771 printf ("x86 feature needed: ");
20772 decode_x86_feature_2 (bitmask
);
20776 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
20778 printf (_("x86 ISA used: <corrupt length: %#x> "),
20782 printf ("x86 ISA used: ");
20783 decode_x86_compat_isa (bitmask
);
20787 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
20789 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20793 printf ("x86 ISA needed: ");
20794 decode_x86_compat_isa (bitmask
);
20798 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
20800 printf (_("x86 ISA used: <corrupt length: %#x> "),
20804 printf ("x86 ISA used: ");
20805 decode_x86_compat_2_isa (bitmask
);
20809 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
20811 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20815 printf ("x86 ISA needed: ");
20816 decode_x86_compat_2_isa (bitmask
);
20824 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
20826 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
20828 printf ("AArch64 feature: ");
20830 printf (_("<corrupt length: %#x> "), datasz
);
20832 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
20841 case GNU_PROPERTY_STACK_SIZE
:
20842 printf (_("stack size: "));
20843 if (datasz
!= size
)
20844 printf (_("<corrupt length: %#x> "), datasz
);
20846 printf ("%#" PRIx64
, byte_get (ptr
, size
));
20849 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
20850 printf ("no copy on protected ");
20852 printf (_("<corrupt length: %#x> "), datasz
);
20856 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
20857 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
20858 || (type
>= GNU_PROPERTY_UINT32_OR_LO
20859 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
20863 case GNU_PROPERTY_1_NEEDED
:
20865 printf (_("1_needed: <corrupt length: %#x> "),
20869 unsigned int bitmask
= byte_get (ptr
, 4);
20870 printf ("1_needed: ");
20871 decode_1_needed (bitmask
);
20878 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
20879 printf (_("UINT32_AND (%#x): "), type
);
20881 printf (_("UINT32_OR (%#x): "), type
);
20883 printf (_("<corrupt length: %#x> "), datasz
);
20885 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
20892 if (type
< GNU_PROPERTY_LOPROC
)
20893 printf (_("<unknown type %#x data: "), type
);
20894 else if (type
< GNU_PROPERTY_LOUSER
)
20895 printf (_("<processor-specific type %#x data: "), type
);
20897 printf (_("<application-specific type %#x data: "), type
);
20898 for (j
= 0; j
< datasz
; ++j
)
20899 printf ("%02x ", ptr
[j
] & 0xff);
20903 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
20904 if (ptr
== ptr_end
)
20917 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
20919 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
20920 switch (pnote
->type
)
20922 case NT_GNU_BUILD_ID
:
20926 printf (_(" Build ID: "));
20927 for (i
= 0; i
< pnote
->descsz
; ++i
)
20928 printf ("%02x", pnote
->descdata
[i
] & 0xff);
20933 case NT_GNU_ABI_TAG
:
20935 unsigned int os
, major
, minor
, subminor
;
20936 const char *osname
;
20938 /* PR 17531: file: 030-599401-0.004. */
20939 if (pnote
->descsz
< 16)
20941 printf (_(" <corrupt GNU_ABI_TAG>\n"));
20945 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20946 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20947 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
20948 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
20952 case GNU_ABI_TAG_LINUX
:
20955 case GNU_ABI_TAG_HURD
:
20958 case GNU_ABI_TAG_SOLARIS
:
20959 osname
= "Solaris";
20961 case GNU_ABI_TAG_FREEBSD
:
20962 osname
= "FreeBSD";
20964 case GNU_ABI_TAG_NETBSD
:
20967 case GNU_ABI_TAG_SYLLABLE
:
20968 osname
= "Syllable";
20970 case GNU_ABI_TAG_NACL
:
20974 osname
= "Unknown";
20978 printf (_(" OS: %s, ABI: %d.%d.%d\n"), osname
,
20979 major
, minor
, subminor
);
20983 case NT_GNU_GOLD_VERSION
:
20987 printf (_(" Version: "));
20988 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
20989 printf ("%c", pnote
->descdata
[i
]);
20996 unsigned int num_entries
, mask
;
20998 /* Hardware capabilities information. Word 0 is the number of entries.
20999 Word 1 is a bitmask of enabled entries. The rest of the descriptor
21000 is a series of entries, where each entry is a single byte followed
21001 by a nul terminated string. The byte gives the bit number to test
21002 if enabled in the bitmask. */
21003 printf (_(" Hardware Capabilities: "));
21004 if (pnote
->descsz
< 8)
21006 error (_("<corrupt GNU_HWCAP>\n"));
21009 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21010 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
21011 printf (_("num entries: %d, enabled mask: %x\n"), num_entries
, mask
);
21012 /* FIXME: Add code to display the entries... */
21016 case NT_GNU_PROPERTY_TYPE_0
:
21017 print_gnu_property_note (filedata
, pnote
);
21021 /* Handle unrecognised types. An error message should have already been
21022 created by get_gnu_elf_note_type(), so all that we need to do is to
21023 display the data. */
21027 printf (_(" Description data: "));
21028 for (i
= 0; i
< pnote
->descsz
; ++i
)
21029 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
21038 static const char *
21039 get_v850_elf_note_type (enum v850_notes n_type
)
21041 static char buff
[64];
21045 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
21046 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
21047 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
21048 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
21049 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
21050 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
21052 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
21058 print_v850_note (Elf_Internal_Note
* pnote
)
21062 if (pnote
->descsz
!= 4)
21065 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
21069 printf (_("not set\n"));
21073 switch (pnote
->type
)
21075 case V850_NOTE_ALIGNMENT
:
21078 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
21079 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
21083 case V850_NOTE_DATA_SIZE
:
21086 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
21087 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
21091 case V850_NOTE_FPU_INFO
:
21094 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
21095 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
21099 case V850_NOTE_MMU_INFO
:
21100 case V850_NOTE_CACHE_INFO
:
21101 case V850_NOTE_SIMD_INFO
:
21102 if (val
== EF_RH850_SIMD
)
21104 printf (_("yes\n"));
21110 /* An 'unknown note type' message will already have been displayed. */
21114 printf (_("unknown value: %x\n"), val
);
21119 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
21121 unsigned int version
;
21123 switch (pnote
->type
)
21125 case NT_NETBSD_IDENT
:
21126 if (pnote
->descsz
< 1)
21128 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
21129 if ((version
/ 10000) % 100)
21130 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
21131 version
, version
/ 100000000, (version
/ 1000000) % 100,
21132 (version
/ 10000) % 100 > 26 ? "Z" : "",
21133 'A' + (version
/ 10000) % 26);
21135 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
21136 version
, version
/ 100000000, (version
/ 1000000) % 100,
21137 (version
/ 100) % 100);
21140 case NT_NETBSD_MARCH
:
21141 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
21145 case NT_NETBSD_PAX
:
21146 if (pnote
->descsz
< 1)
21148 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
21149 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
21150 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
21151 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
21152 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
21153 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
21154 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
21155 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
21159 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
21160 pnote
->descsz
, pnote
->type
);
21164 static const char *
21165 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21169 case NT_FREEBSD_THRMISC
:
21170 return _("NT_THRMISC (thrmisc structure)");
21171 case NT_FREEBSD_PROCSTAT_PROC
:
21172 return _("NT_PROCSTAT_PROC (proc data)");
21173 case NT_FREEBSD_PROCSTAT_FILES
:
21174 return _("NT_PROCSTAT_FILES (files data)");
21175 case NT_FREEBSD_PROCSTAT_VMMAP
:
21176 return _("NT_PROCSTAT_VMMAP (vmmap data)");
21177 case NT_FREEBSD_PROCSTAT_GROUPS
:
21178 return _("NT_PROCSTAT_GROUPS (groups data)");
21179 case NT_FREEBSD_PROCSTAT_UMASK
:
21180 return _("NT_PROCSTAT_UMASK (umask data)");
21181 case NT_FREEBSD_PROCSTAT_RLIMIT
:
21182 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
21183 case NT_FREEBSD_PROCSTAT_OSREL
:
21184 return _("NT_PROCSTAT_OSREL (osreldate data)");
21185 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
21186 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
21187 case NT_FREEBSD_PROCSTAT_AUXV
:
21188 return _("NT_PROCSTAT_AUXV (auxv data)");
21189 case NT_FREEBSD_PTLWPINFO
:
21190 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
21191 case NT_FREEBSD_X86_SEGBASES
:
21192 return _("NT_X86_SEGBASES (x86 segment base registers)");
21194 return get_note_type (filedata
, e_type
);
21197 static const char *
21198 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21200 static char buff
[64];
21204 case NT_NETBSDCORE_PROCINFO
:
21205 /* NetBSD core "procinfo" structure. */
21206 return _("NetBSD procinfo structure");
21208 case NT_NETBSDCORE_AUXV
:
21209 return _("NetBSD ELF auxiliary vector data");
21211 case NT_NETBSDCORE_LWPSTATUS
:
21212 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
21215 /* As of Jan 2020 there are no other machine-independent notes
21216 defined for NetBSD core files. If the note type is less
21217 than the start of the machine-dependent note types, we don't
21220 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
21222 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21228 switch (filedata
->file_header
.e_machine
)
21230 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
21231 and PT_GETFPREGS == mach+2. */
21236 case EM_SPARC32PLUS
:
21240 case NT_NETBSDCORE_FIRSTMACH
+ 0:
21241 return _("PT_GETREGS (reg structure)");
21242 case NT_NETBSDCORE_FIRSTMACH
+ 2:
21243 return _("PT_GETFPREGS (fpreg structure)");
21249 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
21250 There's also old PT___GETREGS40 == mach + 1 for old reg
21251 structure which lacks GBR. */
21255 case NT_NETBSDCORE_FIRSTMACH
+ 1:
21256 return _("PT___GETREGS40 (old reg structure)");
21257 case NT_NETBSDCORE_FIRSTMACH
+ 3:
21258 return _("PT_GETREGS (reg structure)");
21259 case NT_NETBSDCORE_FIRSTMACH
+ 5:
21260 return _("PT_GETFPREGS (fpreg structure)");
21266 /* On all other arch's, PT_GETREGS == mach+1 and
21267 PT_GETFPREGS == mach+3. */
21271 case NT_NETBSDCORE_FIRSTMACH
+ 1:
21272 return _("PT_GETREGS (reg structure)");
21273 case NT_NETBSDCORE_FIRSTMACH
+ 3:
21274 return _("PT_GETFPREGS (fpreg structure)");
21280 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
21281 e_type
- NT_NETBSDCORE_FIRSTMACH
);
21285 static const char *
21286 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21290 case NT_OPENBSD_PROCINFO
:
21291 return _("OpenBSD procinfo structure");
21292 case NT_OPENBSD_AUXV
:
21293 return _("OpenBSD ELF auxiliary vector data");
21294 case NT_OPENBSD_REGS
:
21295 return _("OpenBSD regular registers");
21296 case NT_OPENBSD_FPREGS
:
21297 return _("OpenBSD floating point registers");
21298 case NT_OPENBSD_WCOOKIE
:
21299 return _("OpenBSD window cookie");
21302 return get_note_type (filedata
, e_type
);
21305 static const char *
21306 get_qnx_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21310 case QNT_DEBUG_FULLPATH
:
21311 return _("QNX debug fullpath");
21312 case QNT_DEBUG_RELOC
:
21313 return _("QNX debug relocation");
21315 return _("QNX stack");
21316 case QNT_GENERATOR
:
21317 return _("QNX generator");
21318 case QNT_DEFAULT_LIB
:
21319 return _("QNX default library");
21320 case QNT_CORE_SYSINFO
:
21321 return _("QNX core sysinfo");
21322 case QNT_CORE_INFO
:
21323 return _("QNX core info");
21324 case QNT_CORE_STATUS
:
21325 return _("QNX core status");
21326 case QNT_CORE_GREG
:
21327 return _("QNX general registers");
21328 case QNT_CORE_FPREG
:
21329 return _("QNX floating point registers");
21331 return _("QNX link map");
21334 return get_note_type (filedata
, e_type
);
21337 static const char *
21338 get_stapsdt_note_type (unsigned e_type
)
21340 static char buff
[64];
21345 return _("NT_STAPSDT (SystemTap probe descriptors)");
21351 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21356 print_stapsdt_note (Elf_Internal_Note
*pnote
)
21358 size_t len
, maxlen
;
21359 size_t addr_size
= is_32bit_elf
? 4 : 8;
21360 char *data
= pnote
->descdata
;
21361 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
21362 uint64_t pc
, base_addr
, semaphore
;
21363 char *provider
, *probe
, *arg_fmt
;
21365 if (pnote
->descsz
< (addr_size
* 3))
21366 goto stapdt_note_too_small
;
21368 pc
= byte_get ((unsigned char *) data
, addr_size
);
21371 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
21374 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
21377 if (data
>= data_end
)
21378 goto stapdt_note_too_small
;
21379 maxlen
= data_end
- data
;
21380 len
= strnlen (data
, maxlen
);
21387 goto stapdt_note_too_small
;
21389 if (data
>= data_end
)
21390 goto stapdt_note_too_small
;
21391 maxlen
= data_end
- data
;
21392 len
= strnlen (data
, maxlen
);
21399 goto stapdt_note_too_small
;
21401 if (data
>= data_end
)
21402 goto stapdt_note_too_small
;
21403 maxlen
= data_end
- data
;
21404 len
= strnlen (data
, maxlen
);
21411 goto stapdt_note_too_small
;
21413 printf (_(" Provider: %s\n"), provider
);
21414 printf (_(" Name: %s\n"), probe
);
21415 printf (_(" Location: "));
21416 print_vma (pc
, FULL_HEX
);
21417 printf (_(", Base: "));
21418 print_vma (base_addr
, FULL_HEX
);
21419 printf (_(", Semaphore: "));
21420 print_vma (semaphore
, FULL_HEX
);
21422 printf (_(" Arguments: %s\n"), arg_fmt
);
21424 return data
== data_end
;
21426 stapdt_note_too_small
:
21427 printf (_(" <corrupt - note is too small>\n"));
21428 error (_("corrupt stapdt note - the data size is too small\n"));
21433 print_fdo_note (Elf_Internal_Note
* pnote
)
21435 if (pnote
->descsz
> 0 && pnote
->type
== FDO_PACKAGING_METADATA
)
21437 printf (_(" Packaging Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
21443 static const char *
21444 get_ia64_vms_note_type (unsigned e_type
)
21446 static char buff
[64];
21451 return _("NT_VMS_MHD (module header)");
21453 return _("NT_VMS_LNM (language name)");
21455 return _("NT_VMS_SRC (source files)");
21457 return "NT_VMS_TITLE";
21459 return _("NT_VMS_EIDC (consistency check)");
21460 case NT_VMS_FPMODE
:
21461 return _("NT_VMS_FPMODE (FP mode)");
21462 case NT_VMS_LINKTIME
:
21463 return "NT_VMS_LINKTIME";
21464 case NT_VMS_IMGNAM
:
21465 return _("NT_VMS_IMGNAM (image name)");
21467 return _("NT_VMS_IMGID (image id)");
21468 case NT_VMS_LINKID
:
21469 return _("NT_VMS_LINKID (link id)");
21470 case NT_VMS_IMGBID
:
21471 return _("NT_VMS_IMGBID (build id)");
21472 case NT_VMS_GSTNAM
:
21473 return _("NT_VMS_GSTNAM (sym table name)");
21474 case NT_VMS_ORIG_DYN
:
21475 return "NT_VMS_ORIG_DYN";
21476 case NT_VMS_PATCHTIME
:
21477 return "NT_VMS_PATCHTIME";
21479 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21485 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
21487 unsigned int maxlen
= pnote
->descsz
;
21489 if (maxlen
< 2 || maxlen
!= pnote
->descsz
)
21490 goto desc_size_fail
;
21492 switch (pnote
->type
)
21496 goto desc_size_fail
;
21498 size_t l
= strnlen (pnote
->descdata
+ 34, maxlen
- 34);
21500 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
21501 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
21502 if (l
+ 34 < maxlen
)
21504 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
21505 if (l
+ 35 < maxlen
)
21506 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
21508 printf (_(" Module version : <missing>\n"));
21512 printf (_(" Module name : <missing>\n"));
21513 printf (_(" Module version : <missing>\n"));
21518 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
21521 case NT_VMS_FPMODE
:
21522 printf (_(" Floating Point mode: "));
21524 goto desc_size_fail
;
21525 /* FIXME: Generate an error if descsz > 8 ? */
21527 printf ("0x%016" PRIx64
"\n",
21528 byte_get ((unsigned char *) pnote
->descdata
, 8));
21531 case NT_VMS_LINKTIME
:
21532 printf (_(" Link time: "));
21534 goto desc_size_fail
;
21535 /* FIXME: Generate an error if descsz > 8 ? */
21537 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
21541 case NT_VMS_PATCHTIME
:
21542 printf (_(" Patch time: "));
21544 goto desc_size_fail
;
21545 /* FIXME: Generate an error if descsz > 8 ? */
21547 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
21551 case NT_VMS_ORIG_DYN
:
21553 goto desc_size_fail
;
21555 printf (_(" Major id: %u, minor id: %u\n"),
21556 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4),
21557 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
21558 printf (_(" Last modified : "));
21559 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
+ 8, 8));
21560 printf (_("\n Link flags : "));
21561 printf ("0x%016" PRIx64
"\n",
21562 byte_get ((unsigned char *) pnote
->descdata
+ 16, 8));
21563 printf (_(" Header flags: 0x%08x\n"),
21564 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 24, 4));
21565 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
21568 case NT_VMS_IMGNAM
:
21569 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
21572 case NT_VMS_GSTNAM
:
21573 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
21577 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
21580 case NT_VMS_LINKID
:
21581 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
21591 printf (_(" <corrupt - data size is too small>\n"));
21592 error (_("corrupt IA64 note: data size is too small\n"));
21596 struct build_attr_cache
{
21597 Filedata
*filedata
;
21599 uint64_t strtablen
;
21600 Elf_Internal_Sym
*symtab
;
21604 /* Find the symbol associated with a build attribute that is attached
21605 to address OFFSET. If PNAME is non-NULL then store the name of
21606 the symbol (if found) in the provided pointer, Returns NULL if a
21607 symbol could not be found. */
21609 static Elf_Internal_Sym
*
21610 get_symbol_for_build_attribute (Filedata
*filedata
,
21613 const char **pname
)
21615 Elf_Internal_Sym
*saved_sym
= NULL
;
21616 Elf_Internal_Sym
*sym
;
21618 if (filedata
->section_headers
!= NULL
21619 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
21621 Elf_Internal_Shdr
* symsec
;
21623 free (ba_cache
.strtab
);
21624 ba_cache
.strtab
= NULL
;
21625 free (ba_cache
.symtab
);
21626 ba_cache
.symtab
= NULL
;
21628 /* Load the symbol and string sections. */
21629 for (symsec
= filedata
->section_headers
;
21630 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
21633 if (symsec
->sh_type
== SHT_SYMTAB
21634 && get_symtab (filedata
, symsec
,
21635 &ba_cache
.symtab
, &ba_cache
.nsyms
,
21636 &ba_cache
.strtab
, &ba_cache
.strtablen
))
21639 ba_cache
.filedata
= filedata
;
21642 if (ba_cache
.symtab
== NULL
)
21645 /* Find a symbol whose value matches offset. */
21646 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
21647 if (sym
->st_value
== offset
)
21649 if (sym
->st_name
>= ba_cache
.strtablen
)
21650 /* Huh ? This should not happen. */
21653 if (ba_cache
.strtab
[sym
->st_name
] == 0)
21656 /* The AArch64, ARM and RISC-V architectures define mapping symbols
21657 (eg $d, $x, $t) which we want to ignore. */
21658 if (ba_cache
.strtab
[sym
->st_name
] == '$'
21659 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
21660 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
21665 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
21666 and FILE or OBJECT symbols over NOTYPE symbols. We skip
21667 FUNC symbols entirely. */
21668 switch (ELF_ST_TYPE (sym
->st_info
))
21675 /* If the symbol has a size associated
21676 with it then we can stop searching. */
21677 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
21682 /* Ignore function symbols. */
21689 switch (ELF_ST_BIND (sym
->st_info
))
21692 if (saved_sym
== NULL
21693 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
21698 if (saved_sym
== NULL
)
21708 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
21716 if (saved_sym
&& pname
)
21717 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
21722 /* Returns true iff addr1 and addr2 are in the same section. */
21725 same_section (Filedata
* filedata
, uint64_t addr1
, uint64_t addr2
)
21727 Elf_Internal_Shdr
* a1
;
21728 Elf_Internal_Shdr
* a2
;
21730 a1
= find_section_by_address (filedata
, addr1
);
21731 a2
= find_section_by_address (filedata
, addr2
);
21733 return a1
== a2
&& a1
!= NULL
;
21737 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
21738 Filedata
* filedata
)
21740 static uint64_t global_offset
= 0;
21741 static uint64_t global_end
= 0;
21742 static uint64_t func_offset
= 0;
21743 static uint64_t func_end
= 0;
21745 Elf_Internal_Sym
*sym
;
21749 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
21751 switch (pnote
->descsz
)
21754 /* A zero-length description means that the range of
21755 the previous note of the same type should be used. */
21758 if (global_end
> global_offset
)
21759 printf (_(" Applies to region from %#" PRIx64
21760 " to %#" PRIx64
"\n"), global_offset
, global_end
);
21762 printf (_(" Applies to region from %#" PRIx64
21763 "\n"), global_offset
);
21767 if (func_end
> func_offset
)
21768 printf (_(" Applies to region from %#" PRIx64
21769 " to %#" PRIx64
"\n"), func_offset
, func_end
);
21771 printf (_(" Applies to region from %#" PRIx64
21772 "\n"), func_offset
);
21777 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21782 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21783 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
21787 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
21788 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
21792 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
21793 printf (_(" <invalid descsz>"));
21798 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
21799 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
21800 in order to avoid them being confused with the start address of the
21801 first function in the file... */
21802 if (sym
== NULL
&& is_open_attr
)
21803 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
21806 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
21807 end
= start
+ sym
->st_size
;
21811 /* FIXME: Need to properly allow for section alignment.
21812 16 is just the alignment used on x86_64. */
21814 && start
> BFD_ALIGN (global_end
, 16)
21815 /* Build notes are not guaranteed to be organised in order of
21816 increasing address, but we should find the all of the notes
21817 for one section in the same place. */
21818 && same_section (filedata
, start
, global_end
))
21819 warn (_("Gap in build notes detected from %#" PRIx64
21820 " to %#" PRIx64
"\n"),
21821 global_end
+ 1, start
- 1);
21823 printf (_(" Applies to region from %#" PRIx64
), start
);
21824 global_offset
= start
;
21828 printf (_(" to %#" PRIx64
), end
);
21834 printf (_(" Applies to region from %#" PRIx64
), start
);
21835 func_offset
= start
;
21839 printf (_(" to %#" PRIx64
), end
);
21845 printf (_(" (%s)"), name
);
21852 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
21854 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
21855 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
21856 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
21858 char name_attribute
;
21859 const char * expected_types
;
21860 const char * name
= pnote
->namedata
;
21864 if (name
== NULL
|| pnote
->namesz
< 2)
21866 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21867 print_symbol_name (-20, _(" <corrupt name>"));
21876 /* Version 2 of the spec adds a "GA" prefix to the name field. */
21877 if (name
[0] == 'G' && name
[1] == 'A')
21879 if (pnote
->namesz
< 4)
21881 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21882 print_symbol_name (-20, _(" <corrupt name>"));
21891 switch ((name_type
= * name
))
21893 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21894 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21895 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21896 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21897 printf ("%c", * name
);
21901 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
21902 print_symbol_name (-20, _("<unknown name type>"));
21909 switch ((name_attribute
= * name
))
21911 case GNU_BUILD_ATTRIBUTE_VERSION
:
21912 text
= _("<version>");
21913 expected_types
= string_expected
;
21916 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21917 text
= _("<stack prot>");
21918 expected_types
= "!+*";
21921 case GNU_BUILD_ATTRIBUTE_RELRO
:
21922 text
= _("<relro>");
21923 expected_types
= bool_expected
;
21926 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
21927 text
= _("<stack size>");
21928 expected_types
= number_expected
;
21931 case GNU_BUILD_ATTRIBUTE_TOOL
:
21932 text
= _("<tool>");
21933 expected_types
= string_expected
;
21936 case GNU_BUILD_ATTRIBUTE_ABI
:
21938 expected_types
= "$*";
21941 case GNU_BUILD_ATTRIBUTE_PIC
:
21943 expected_types
= number_expected
;
21946 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
21947 text
= _("<short enum>");
21948 expected_types
= bool_expected
;
21952 if (ISPRINT (* name
))
21954 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
21956 if (len
> left
&& ! do_wide
)
21958 printf ("%.*s:", len
, name
);
21964 static char tmpbuf
[128];
21966 error (_("unrecognised byte in name field: %d\n"), * name
);
21967 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
21971 expected_types
= "*$!+";
21976 left
-= printf ("%s", text
);
21978 if (strchr (expected_types
, name_type
) == NULL
)
21979 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
21981 if ((size_t) (name
- pnote
->namedata
) > pnote
->namesz
)
21983 error (_("corrupt name field: namesz: %lu but parsing gets to %td\n"),
21985 name
- pnote
->namedata
);
21989 if (left
< 1 && ! do_wide
)
21994 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21996 unsigned int bytes
;
21998 unsigned int shift
= 0;
21999 char *decoded
= NULL
;
22001 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
22003 /* The -1 is because the name field is always 0 terminated, and we
22004 want to be able to ensure that the shift in the while loop below
22005 will not overflow. */
22008 if (bytes
> sizeof (val
))
22010 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
22012 bytes
= sizeof (val
);
22014 /* We do not bother to warn if bytes == 0 as this can
22015 happen with some early versions of the gcc plugin. */
22019 uint64_t byte
= *name
++ & 0xff;
22021 val
|= byte
<< shift
;
22025 switch (name_attribute
)
22027 case GNU_BUILD_ATTRIBUTE_PIC
:
22030 case 0: decoded
= "static"; break;
22031 case 1: decoded
= "pic"; break;
22032 case 2: decoded
= "PIC"; break;
22033 case 3: decoded
= "pie"; break;
22034 case 4: decoded
= "PIE"; break;
22038 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
22041 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
22042 case 0: decoded
= "off"; break;
22043 case 1: decoded
= "on"; break;
22044 case 2: decoded
= "all"; break;
22045 case 3: decoded
= "strong"; break;
22046 case 4: decoded
= "explicit"; break;
22054 if (decoded
!= NULL
)
22056 print_symbol_name (-left
, decoded
);
22067 left
-= printf ("0x%" PRIx64
, val
);
22069 left
-= printf ("0x%-.*" PRIx64
, left
, val
);
22073 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
22074 left
-= print_symbol_name (- left
, name
);
22076 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
22077 left
-= print_symbol_name (- left
, "true");
22079 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
22080 left
-= print_symbol_name (- left
, "false");
22084 if (do_wide
&& left
> 0)
22085 printf ("%-*s", left
, " ");
22090 /* Print the contents of PNOTE as hex. */
22093 print_note_contents_hex (Elf_Internal_Note
*pnote
)
22099 printf (_(" description data: "));
22100 for (i
= 0; i
< pnote
->descsz
; i
++)
22101 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
22110 #if defined HAVE_MSGPACK
22113 print_indents (int n
)
22117 for (int i
= 0; i
< n
; i
++)
22121 /* Print OBJ in human-readable form. */
22124 dump_msgpack_obj (const msgpack_object
*obj
, int indent
)
22128 case MSGPACK_OBJECT_NIL
:
22132 case MSGPACK_OBJECT_BOOLEAN
:
22133 printf ("%s", obj
->via
.boolean
? "true" : "false");
22136 case MSGPACK_OBJECT_POSITIVE_INTEGER
:
22137 printf ("%" PRIu64
, obj
->via
.u64
);
22140 case MSGPACK_OBJECT_NEGATIVE_INTEGER
:
22141 printf ("%" PRIi64
, obj
->via
.i64
);
22144 case MSGPACK_OBJECT_FLOAT32
:
22145 case MSGPACK_OBJECT_FLOAT64
:
22146 printf ("%f", obj
->via
.f64
);
22149 case MSGPACK_OBJECT_STR
:
22150 printf ("\"%.*s\"", obj
->via
.str
.size
, obj
->via
.str
.ptr
);
22153 case MSGPACK_OBJECT_ARRAY
:
22155 const msgpack_object_array
*array
= &obj
->via
.array
;
22160 for (uint32_t i
= 0; i
< array
->size
; ++i
)
22162 const msgpack_object
*item
= &array
->ptr
[i
];
22164 print_indents (indent
);
22165 dump_msgpack_obj (item
, indent
);
22170 print_indents (indent
);
22176 case MSGPACK_OBJECT_MAP
:
22178 const msgpack_object_map
*map
= &obj
->via
.map
;
22183 for (uint32_t i
= 0; i
< map
->size
; ++i
)
22185 const msgpack_object_kv
*kv
= &map
->ptr
[i
];
22186 const msgpack_object
*key
= &kv
->key
;
22187 const msgpack_object
*val
= &kv
->val
;
22189 print_indents (indent
);
22190 dump_msgpack_obj (key
, indent
);
22192 dump_msgpack_obj (val
, indent
);
22198 print_indents (indent
);
22204 case MSGPACK_OBJECT_BIN
:
22208 case MSGPACK_OBJECT_EXT
:
22215 dump_msgpack (const msgpack_unpacked
*msg
)
22218 dump_msgpack_obj (&msg
->data
, 0);
22222 #endif /* defined HAVE_MSGPACK */
22225 print_amdgpu_note (Elf_Internal_Note
*pnote
)
22227 #if defined HAVE_MSGPACK
22228 /* If msgpack is available, decode and dump the note's content. */
22230 msgpack_unpacked msg
;
22231 msgpack_unpack_return msgpack_ret
;
22233 assert (pnote
->type
== NT_AMDGPU_METADATA
);
22235 msgpack_unpacked_init (&msg
);
22236 msgpack_ret
= msgpack_unpack_next (&msg
, pnote
->descdata
, pnote
->descsz
,
22239 switch (msgpack_ret
)
22241 case MSGPACK_UNPACK_SUCCESS
:
22242 dump_msgpack (&msg
);
22247 error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note"));
22252 msgpack_unpacked_destroy (&msg
);
22255 /* msgpack is not available, dump contents as hex. */
22256 print_note_contents_hex (pnote
);
22262 print_qnx_note (Elf_Internal_Note
*pnote
)
22264 switch (pnote
->type
)
22267 if (pnote
->descsz
!= 12)
22268 goto desc_size_fail
;
22270 printf (_(" Stack Size: 0x%" PRIx32
"\n"),
22271 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4));
22272 printf (_(" Stack allocated: %" PRIx32
"\n"),
22273 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
22274 printf (_(" Executable: %s\n"),
22275 ((unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 8, 1)) ? "no": "yes");
22279 print_note_contents_hex(pnote
);
22284 printf (_(" <corrupt - data size is too small>\n"));
22285 error (_("corrupt QNX note: data size is too small\n"));
22290 /* Note that by the ELF standard, the name field is already null byte
22291 terminated, and namesz includes the terminating null byte.
22292 I.E. the value of namesz for the name "FSF" is 4.
22294 If the value of namesz is zero, there is no name present. */
22297 process_note (Elf_Internal_Note
* pnote
,
22298 Filedata
* filedata
)
22300 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
22303 if (pnote
->namesz
== 0)
22304 /* If there is no note name, then use the default set of
22305 note type strings. */
22306 nt
= get_note_type (filedata
, pnote
->type
);
22308 else if (startswith (pnote
->namedata
, "GNU"))
22309 /* GNU-specific object file notes. */
22310 nt
= get_gnu_elf_note_type (pnote
->type
);
22312 else if (startswith (pnote
->namedata
, "AMDGPU"))
22313 /* AMDGPU-specific object file notes. */
22314 nt
= get_amdgpu_elf_note_type (pnote
->type
);
22316 else if (startswith (pnote
->namedata
, "FreeBSD"))
22317 /* FreeBSD-specific core file notes. */
22318 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
22320 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
22321 /* NetBSD-specific core file notes. */
22322 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
22324 else if (startswith (pnote
->namedata
, "NetBSD"))
22325 /* NetBSD-specific core file notes. */
22326 return process_netbsd_elf_note (pnote
);
22328 else if (startswith (pnote
->namedata
, "PaX"))
22329 /* NetBSD-specific core file notes. */
22330 return process_netbsd_elf_note (pnote
);
22332 else if (startswith (pnote
->namedata
, "OpenBSD"))
22333 /* OpenBSD-specific core file notes. */
22334 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
22336 else if (startswith (pnote
->namedata
, "QNX"))
22337 /* QNX-specific core file notes. */
22338 nt
= get_qnx_elfcore_note_type (filedata
, pnote
->type
);
22340 else if (startswith (pnote
->namedata
, "SPU/"))
22342 /* SPU-specific core file notes. */
22343 nt
= pnote
->namedata
+ 4;
22347 else if (startswith (pnote
->namedata
, "IPF/VMS"))
22348 /* VMS/ia64-specific file notes. */
22349 nt
= get_ia64_vms_note_type (pnote
->type
);
22351 else if (startswith (pnote
->namedata
, "stapsdt"))
22352 nt
= get_stapsdt_note_type (pnote
->type
);
22355 /* Don't recognize this note name; just use the default set of
22356 note type strings. */
22357 nt
= get_note_type (filedata
, pnote
->type
);
22361 if (((startswith (pnote
->namedata
, "GA")
22362 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
22363 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
22364 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
22365 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
22366 print_gnu_build_attribute_name (pnote
);
22368 print_symbol_name (-20, name
);
22371 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
22373 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
22375 if (startswith (pnote
->namedata
, "IPF/VMS"))
22376 return print_ia64_vms_note (pnote
);
22377 else if (startswith (pnote
->namedata
, "GNU"))
22378 return print_gnu_note (filedata
, pnote
);
22379 else if (startswith (pnote
->namedata
, "stapsdt"))
22380 return print_stapsdt_note (pnote
);
22381 else if (startswith (pnote
->namedata
, "CORE"))
22382 return print_core_note (pnote
);
22383 else if (startswith (pnote
->namedata
, "FDO"))
22384 return print_fdo_note (pnote
);
22385 else if (((startswith (pnote
->namedata
, "GA")
22386 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
22387 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
22388 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
22389 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
22390 return print_gnu_build_attribute_description (pnote
, filedata
);
22391 else if (startswith (pnote
->namedata
, "AMDGPU")
22392 && pnote
->type
== NT_AMDGPU_METADATA
)
22393 return print_amdgpu_note (pnote
);
22394 else if (startswith (pnote
->namedata
, "QNX"))
22395 return print_qnx_note (pnote
);
22397 print_note_contents_hex (pnote
);
22402 process_notes_at (Filedata
* filedata
,
22403 Elf_Internal_Shdr
* section
,
22408 Elf_External_Note
*pnotes
;
22409 Elf_External_Note
*external
;
22418 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
22421 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
22429 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
22432 if (pnotes
== NULL
)
22437 if (filedata
->is_separate
)
22438 printf (_("In linked file '%s': "), filedata
->file_name
);
22442 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
22444 printf (_("Displaying notes found at file offset 0x%08" PRIx64
22445 " with length 0x%08" PRIx64
":\n"),
22448 /* NB: Some note sections may have alignment value of 0 or 1. gABI
22449 specifies that notes should be aligned to 4 bytes in 32-bit
22450 objects and to 8 bytes in 64-bit objects. As a Linux extension,
22451 we also support 4 byte alignment in 64-bit objects. If section
22452 alignment is less than 4, we treate alignment as 4 bytes. */
22455 else if (align
!= 4 && align
!= 8)
22457 warn (_("Corrupt note: alignment %" PRId64
", expecting 4 or 8\n"),
22463 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
22465 end
= (char *) pnotes
+ length
;
22466 while ((char *) external
< end
)
22468 Elf_Internal_Note inote
;
22471 char * temp
= NULL
;
22472 size_t data_remaining
= end
- (char *) external
;
22474 if (!is_ia64_vms (filedata
))
22476 /* PR binutils/15191
22477 Make sure that there is enough data to read. */
22478 min_notesz
= offsetof (Elf_External_Note
, name
);
22479 if (data_remaining
< min_notesz
)
22481 warn (ngettext ("Corrupt note: only %zd byte remains, "
22482 "not enough for a full note\n",
22483 "Corrupt note: only %zd bytes remain, "
22484 "not enough for a full note\n",
22489 data_remaining
-= min_notesz
;
22491 inote
.type
= BYTE_GET (external
->type
);
22492 inote
.namesz
= BYTE_GET (external
->namesz
);
22493 inote
.namedata
= external
->name
;
22494 inote
.descsz
= BYTE_GET (external
->descsz
);
22495 inote
.descdata
= ((char *) external
22496 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
22497 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
22498 next
= ((char *) external
22499 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
22503 Elf64_External_VMS_Note
*vms_external
;
22505 /* PR binutils/15191
22506 Make sure that there is enough data to read. */
22507 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
22508 if (data_remaining
< min_notesz
)
22510 warn (ngettext ("Corrupt note: only %zd byte remains, "
22511 "not enough for a full note\n",
22512 "Corrupt note: only %zd bytes remain, "
22513 "not enough for a full note\n",
22518 data_remaining
-= min_notesz
;
22520 vms_external
= (Elf64_External_VMS_Note
*) external
;
22521 inote
.type
= BYTE_GET (vms_external
->type
);
22522 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
22523 inote
.namedata
= vms_external
->name
;
22524 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
22525 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
22526 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
22527 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
22530 /* PR 17531: file: 3443835e. */
22531 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
22532 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
22533 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
22534 || (size_t) (next
- inote
.descdata
) < inote
.descsz
22535 || ((size_t) (next
- inote
.descdata
)
22536 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
22538 warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"),
22539 (char *) external
- (char *) pnotes
);
22540 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"),
22541 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
22545 external
= (Elf_External_Note
*) next
;
22547 /* Verify that name is null terminated. It appears that at least
22548 one version of Linux (RedHat 6.0) generates corefiles that don't
22549 comply with the ELF spec by failing to include the null byte in
22551 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
22553 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
22555 temp
= (char *) malloc (inote
.namesz
+ 1);
22558 error (_("Out of memory allocating space for inote name\n"));
22563 memcpy (temp
, inote
.namedata
, inote
.namesz
);
22564 inote
.namedata
= temp
;
22566 inote
.namedata
[inote
.namesz
] = 0;
22569 if (! process_note (& inote
, filedata
))
22582 process_corefile_note_segments (Filedata
* filedata
)
22584 Elf_Internal_Phdr
*segment
;
22588 if (! get_program_headers (filedata
))
22591 for (i
= 0, segment
= filedata
->program_headers
;
22592 i
< filedata
->file_header
.e_phnum
;
22595 if (segment
->p_type
== PT_NOTE
)
22596 if (! process_notes_at (filedata
, NULL
, segment
->p_offset
,
22597 segment
->p_filesz
, segment
->p_align
))
22605 process_v850_notes (Filedata
* filedata
, uint64_t offset
, uint64_t length
)
22607 Elf_External_Note
* pnotes
;
22608 Elf_External_Note
* external
;
22615 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
22617 if (pnotes
== NULL
)
22621 end
= (char*) pnotes
+ length
;
22623 printf (_("\nDisplaying contents of Renesas V850 notes section at offset"
22624 " %#" PRIx64
" with length %#" PRIx64
":\n"),
22627 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
22629 Elf_External_Note
* next
;
22630 Elf_Internal_Note inote
;
22632 inote
.type
= BYTE_GET (external
->type
);
22633 inote
.namesz
= BYTE_GET (external
->namesz
);
22634 inote
.namedata
= external
->name
;
22635 inote
.descsz
= BYTE_GET (external
->descsz
);
22636 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
22637 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
22639 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
22641 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
22642 inote
.descdata
= inote
.namedata
;
22646 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
22648 if ( ((char *) next
> end
)
22649 || ((char *) next
< (char *) pnotes
))
22651 warn (_("corrupt descsz found in note at offset %#tx\n"),
22652 (char *) external
- (char *) pnotes
);
22653 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"),
22654 inote
.type
, inote
.namesz
, inote
.descsz
);
22660 /* Prevent out-of-bounds indexing. */
22661 if ( inote
.namedata
+ inote
.namesz
> end
22662 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
22664 warn (_("corrupt namesz found in note at offset %#zx\n"),
22665 (char *) external
- (char *) pnotes
);
22666 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"),
22667 inote
.type
, inote
.namesz
, inote
.descsz
);
22671 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
22673 if (! print_v850_note (& inote
))
22676 printf ("<corrupt sizes: namesz: %#lx, descsz: %#lx>\n",
22677 inote
.namesz
, inote
.descsz
);
22687 process_note_sections (Filedata
* filedata
)
22689 Elf_Internal_Shdr
*section
;
22691 unsigned int n
= 0;
22694 for (i
= 0, section
= filedata
->section_headers
;
22695 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
22698 if (section
->sh_type
== SHT_NOTE
)
22700 if (! process_notes_at (filedata
, section
, section
->sh_offset
,
22701 section
->sh_size
, section
->sh_addralign
))
22706 if (( filedata
->file_header
.e_machine
== EM_V800
22707 || filedata
->file_header
.e_machine
== EM_V850
22708 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
22709 && section
->sh_type
== SHT_RENESAS_INFO
)
22711 if (! process_v850_notes (filedata
, section
->sh_offset
,
22719 /* Try processing NOTE segments instead. */
22720 return process_corefile_note_segments (filedata
);
22726 process_notes (Filedata
* filedata
)
22728 /* If we have not been asked to display the notes then do nothing. */
22732 if (filedata
->file_header
.e_type
!= ET_CORE
)
22733 return process_note_sections (filedata
);
22735 /* No program headers means no NOTE segment. */
22736 if (filedata
->file_header
.e_phnum
> 0)
22737 return process_corefile_note_segments (filedata
);
22739 if (filedata
->is_separate
)
22740 printf (_("No notes found in linked file '%s'.\n"),
22741 filedata
->file_name
);
22743 printf (_("No notes found file.\n"));
22748 static unsigned char *
22749 display_public_gnu_attributes (unsigned char * start
,
22750 const unsigned char * const end
)
22752 printf (_(" Unknown GNU attribute: %s\n"), start
);
22754 start
+= strnlen ((char *) start
, end
- start
);
22755 display_raw_attribute (start
, end
);
22757 return (unsigned char *) end
;
22760 static unsigned char *
22761 display_generic_attribute (unsigned char * start
,
22763 const unsigned char * const end
)
22766 return (unsigned char *) end
;
22768 return display_tag_value (tag
, start
, end
);
22772 process_arch_specific (Filedata
* filedata
)
22777 switch (filedata
->file_header
.e_machine
)
22780 case EM_ARC_COMPACT
:
22781 case EM_ARC_COMPACT2
:
22782 case EM_ARC_COMPACT3
:
22783 case EM_ARC_COMPACT3_64
:
22784 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
22785 display_arc_attribute
,
22786 display_generic_attribute
);
22788 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
22789 display_arm_attribute
,
22790 display_generic_attribute
);
22793 case EM_MIPS_RS3_LE
:
22794 return process_mips_specific (filedata
);
22797 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
22798 display_msp430_attribute
,
22799 display_msp430_gnu_attribute
);
22802 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
22803 display_riscv_attribute
,
22804 display_generic_attribute
);
22807 return process_nds32_specific (filedata
);
22810 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22811 display_m68k_gnu_attribute
);
22815 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22816 display_power_gnu_attribute
);
22820 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22821 display_s390_gnu_attribute
);
22824 case EM_SPARC32PLUS
:
22826 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22827 display_sparc_gnu_attribute
);
22830 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
22831 display_tic6x_attribute
,
22832 display_generic_attribute
);
22835 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
22836 display_csky_attribute
, NULL
);
22839 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
22840 display_public_gnu_attributes
,
22841 display_generic_attribute
);
22846 get_file_header (Filedata
* filedata
)
22848 /* Read in the identity array. */
22849 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
22852 /* Determine how to read the rest of the header. */
22853 switch (filedata
->file_header
.e_ident
[EI_DATA
])
22858 byte_get
= byte_get_little_endian
;
22859 byte_put
= byte_put_little_endian
;
22862 byte_get
= byte_get_big_endian
;
22863 byte_put
= byte_put_big_endian
;
22867 /* For now we only support 32 bit and 64 bit ELF files. */
22868 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
22870 /* Read in the rest of the header. */
22873 Elf32_External_Ehdr ehdr32
;
22875 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22878 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
22879 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
22880 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
22881 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
22882 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
22883 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
22884 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
22885 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
22886 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
22887 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
22888 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
22889 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
22890 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
22894 Elf64_External_Ehdr ehdr64
;
22896 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22899 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
22900 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
22901 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
22902 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
22903 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
22904 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
22905 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
22906 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
22907 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
22908 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
22909 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
22910 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
22911 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
22918 free_filedata (Filedata
*filedata
)
22920 free (filedata
->program_interpreter
);
22921 free (filedata
->program_headers
);
22922 free (filedata
->section_headers
);
22923 free (filedata
->string_table
);
22924 free (filedata
->dump
.dump_sects
);
22925 free (filedata
->dynamic_strings
);
22926 free (filedata
->dynamic_symbols
);
22927 free (filedata
->dynamic_syminfo
);
22928 free (filedata
->dynamic_section
);
22930 while (filedata
->symtab_shndx_list
!= NULL
)
22932 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
22933 free (filedata
->symtab_shndx_list
);
22934 filedata
->symtab_shndx_list
= next
;
22937 free (filedata
->section_headers_groups
);
22939 if (filedata
->section_groups
)
22942 struct group_list
* g
;
22943 struct group_list
* next
;
22945 for (i
= 0; i
< filedata
->group_count
; i
++)
22947 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
22954 free (filedata
->section_groups
);
22956 memset (&filedata
->section_headers
, 0,
22957 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
22961 close_file (Filedata
* filedata
)
22965 if (filedata
->handle
)
22966 fclose (filedata
->handle
);
22972 close_debug_file (void * data
)
22974 free_filedata ((Filedata
*) data
);
22975 close_file ((Filedata
*) data
);
22979 open_file (const char * pathname
, bool is_separate
)
22981 struct stat statbuf
;
22982 Filedata
* filedata
= NULL
;
22984 if (stat (pathname
, & statbuf
) < 0
22985 || ! S_ISREG (statbuf
.st_mode
))
22988 filedata
= calloc (1, sizeof * filedata
);
22989 if (filedata
== NULL
)
22992 filedata
->handle
= fopen (pathname
, "rb");
22993 if (filedata
->handle
== NULL
)
22996 filedata
->file_size
= statbuf
.st_size
;
22997 filedata
->file_name
= pathname
;
22998 filedata
->is_separate
= is_separate
;
23000 if (! get_file_header (filedata
))
23003 if (!get_section_headers (filedata
, false))
23011 if (filedata
->handle
)
23012 fclose (filedata
->handle
);
23019 open_debug_file (const char * pathname
)
23021 return open_file (pathname
, true);
23025 initialise_dump_sects (Filedata
* filedata
)
23027 /* Initialise the dump_sects array from the cmdline_dump_sects array.
23028 Note we do this even if cmdline_dump_sects is empty because we
23029 must make sure that the dump_sets array is zeroed out before each
23030 object file is processed. */
23031 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
23032 memset (filedata
->dump
.dump_sects
, 0,
23033 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
23035 if (cmdline
.num_dump_sects
> 0)
23037 if (filedata
->dump
.num_dump_sects
== 0)
23038 /* A sneaky way of allocating the dump_sects array. */
23039 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
23041 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
23042 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
23043 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
23048 might_need_separate_debug_info (Filedata
* filedata
)
23050 /* Debuginfo files do not need further separate file loading. */
23051 if (filedata
->file_header
.e_shstrndx
== SHN_UNDEF
)
23054 /* Since do_follow_links might be enabled by default, only treat it as an
23055 indication that separate files should be loaded if setting it was a
23056 deliberate user action. */
23057 if (DEFAULT_FOR_FOLLOW_LINKS
== 0 && do_follow_links
)
23060 if (process_links
|| do_syms
|| do_unwind
23061 || dump_any_debugging
|| do_dump
|| do_debugging
)
23067 /* Process one ELF object file according to the command line options.
23068 This file may actually be stored in an archive. The file is
23069 positioned at the start of the ELF object. Returns TRUE if no
23070 problems were encountered, FALSE otherwise. */
23073 process_object (Filedata
* filedata
)
23075 bool have_separate_files
;
23079 if (! get_file_header (filedata
))
23081 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
23085 /* Initialise per file variables. */
23086 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
23087 filedata
->version_info
[i
] = 0;
23089 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
23090 filedata
->dynamic_info
[i
] = 0;
23091 filedata
->dynamic_info_DT_GNU_HASH
= 0;
23092 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
23094 /* Process the file. */
23096 printf (_("\nFile: %s\n"), filedata
->file_name
);
23098 initialise_dump_sects (filedata
);
23100 /* There may be some extensions in the first section header. Don't
23101 bomb if we can't read it. */
23102 get_section_headers (filedata
, true);
23104 if (! process_file_header (filedata
))
23110 /* Throw away the single section header read above, so that we
23111 re-read the entire set. */
23112 free (filedata
->section_headers
);
23113 filedata
->section_headers
= NULL
;
23115 if (! process_section_headers (filedata
))
23117 /* Without loaded section headers we cannot process lots of things. */
23118 do_unwind
= do_version
= do_dump
= do_arch
= false;
23120 if (! do_using_dynamic
)
23121 do_syms
= do_dyn_syms
= do_reloc
= false;
23124 if (! process_section_groups (filedata
))
23125 /* Without loaded section groups we cannot process unwind. */
23128 process_program_headers (filedata
);
23130 res
= process_dynamic_section (filedata
);
23132 if (! process_relocs (filedata
))
23135 if (! process_unwind (filedata
))
23138 if (! process_symbol_table (filedata
))
23141 if (! process_lto_symbol_tables (filedata
))
23144 if (! process_syminfo (filedata
))
23147 if (! process_version_sections (filedata
))
23150 if (might_need_separate_debug_info (filedata
))
23151 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
23153 have_separate_files
= false;
23155 if (! process_section_contents (filedata
))
23158 if (have_separate_files
)
23162 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
23164 initialise_dump_sects (d
->handle
);
23166 if (process_links
&& ! process_file_header (d
->handle
))
23168 else if (! process_section_headers (d
->handle
))
23170 else if (! process_section_contents (d
->handle
))
23172 else if (process_links
)
23174 if (! process_section_groups (d
->handle
))
23176 process_program_headers (d
->handle
);
23177 if (! process_dynamic_section (d
->handle
))
23179 if (! process_relocs (d
->handle
))
23181 if (! process_unwind (d
->handle
))
23183 if (! process_symbol_table (d
->handle
))
23185 if (! process_lto_symbol_tables (d
->handle
))
23187 if (! process_syminfo (d
->handle
))
23189 if (! process_version_sections (d
->handle
))
23191 if (! process_notes (d
->handle
))
23196 /* The file handles are closed by the call to free_debug_memory() below. */
23199 if (! process_notes (filedata
))
23202 if (! process_gnu_liblist (filedata
))
23205 if (! process_arch_specific (filedata
))
23209 free_filedata (filedata
);
23211 free_debug_memory ();
23216 /* Process an ELF archive.
23217 On entry the file is positioned just after the ARMAG string.
23218 Returns TRUE upon success, FALSE otherwise. */
23221 process_archive (Filedata
* filedata
, bool is_thin_archive
)
23223 struct archive_info arch
;
23224 struct archive_info nested_arch
;
23230 /* The ARCH structure is used to hold information about this archive. */
23231 arch
.file_name
= NULL
;
23233 arch
.index_array
= NULL
;
23234 arch
.sym_table
= NULL
;
23235 arch
.longnames
= NULL
;
23237 /* The NESTED_ARCH structure is used as a single-item cache of information
23238 about a nested archive (when members of a thin archive reside within
23239 another regular archive file). */
23240 nested_arch
.file_name
= NULL
;
23241 nested_arch
.file
= NULL
;
23242 nested_arch
.index_array
= NULL
;
23243 nested_arch
.sym_table
= NULL
;
23244 nested_arch
.longnames
= NULL
;
23246 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
23247 filedata
->file_size
, is_thin_archive
,
23248 do_archive_index
) != 0)
23254 if (do_archive_index
)
23256 if (arch
.sym_table
== NULL
)
23257 error (_("%s: unable to dump the index as none was found\n"),
23258 filedata
->file_name
);
23262 uint64_t current_pos
;
23264 printf (_("Index of archive %s: (%" PRIu64
" entries,"
23265 " %#" PRIx64
" bytes in the symbol table)\n"),
23266 filedata
->file_name
, arch
.index_num
,
23269 current_pos
= ftell (filedata
->handle
);
23271 for (i
= l
= 0; i
< arch
.index_num
; i
++)
23274 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
23277 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
23280 if (member_name
!= NULL
)
23282 char * qualified_name
23283 = make_qualified_name (&arch
, &nested_arch
,
23286 if (qualified_name
!= NULL
)
23288 printf (_("Contents of binary %s at offset "),
23290 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
23292 free (qualified_name
);
23294 free (member_name
);
23298 if (l
>= arch
.sym_size
)
23300 error (_("%s: end of the symbol table reached "
23301 "before the end of the index\n"),
23302 filedata
->file_name
);
23306 /* PR 17531: file: 0b6630b2. */
23307 printf ("\t%.*s\n",
23308 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
23309 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
23312 if (arch
.uses_64bit_indices
)
23317 if (l
< arch
.sym_size
)
23319 error (ngettext ("%s: %" PRId64
" byte remains in the symbol table, "
23320 "but without corresponding entries in "
23321 "the index table\n",
23322 "%s: %" PRId64
" bytes remain in the symbol table, "
23323 "but without corresponding entries in "
23324 "the index table\n",
23325 arch
.sym_size
- l
),
23326 filedata
->file_name
, arch
.sym_size
- l
);
23330 if (fseek64 (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
23332 error (_("%s: failed to seek back to start of object files "
23333 "in the archive\n"),
23334 filedata
->file_name
);
23340 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
23341 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
23342 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
23343 && !do_section_groups
&& !do_dyn_syms
)
23345 ret
= true; /* Archive index only. */
23354 char * qualified_name
;
23356 /* Read the next archive header. */
23357 if (fseek64 (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
23359 error (_("%s: failed to seek to next archive header\n"),
23364 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
23365 if (got
!= sizeof arch
.arhdr
)
23369 /* PR 24049 - we cannot use filedata->file_name as this will
23370 have already been freed. */
23371 error (_("%s: failed to read archive header\n"), arch
.file_name
);
23376 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
23378 error (_("%s: did not find a valid archive header\n"),
23384 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
23386 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
23388 name
= get_archive_member_name (&arch
, &nested_arch
);
23391 error (_("%s: bad archive file name\n"), arch
.file_name
);
23395 namelen
= strlen (name
);
23397 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
23398 if (qualified_name
== NULL
)
23400 error (_("%s: bad archive file name\n"), arch
.file_name
);
23406 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
23408 /* This is a proxy for an external member of a thin archive. */
23409 Filedata
* member_filedata
;
23410 char * member_file_name
= adjust_relative_path
23411 (filedata
->file_name
, name
, namelen
);
23414 if (member_file_name
== NULL
)
23416 free (qualified_name
);
23421 member_filedata
= open_file (member_file_name
, false);
23422 if (member_filedata
== NULL
)
23424 error (_("Input file '%s' is not readable.\n"), member_file_name
);
23425 free (member_file_name
);
23426 free (qualified_name
);
23431 filedata
->archive_file_offset
= arch
.nested_member_origin
;
23432 member_filedata
->file_name
= qualified_name
;
23434 /* The call to process_object() expects the file to be at the beginning. */
23435 rewind (member_filedata
->handle
);
23437 if (! process_object (member_filedata
))
23440 close_file (member_filedata
);
23441 free (member_file_name
);
23443 else if (is_thin_archive
)
23445 Filedata thin_filedata
;
23447 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
23449 /* PR 15140: Allow for corrupt thin archives. */
23450 if (nested_arch
.file
== NULL
)
23452 error (_("%s: contains corrupt thin archive: %s\n"),
23453 qualified_name
, name
);
23454 free (qualified_name
);
23461 /* This is a proxy for a member of a nested archive. */
23462 filedata
->archive_file_offset
23463 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
23465 /* The nested archive file will have been opened and setup by
23466 get_archive_member_name. */
23467 if (fseek64 (nested_arch
.file
, filedata
->archive_file_offset
,
23470 error (_("%s: failed to seek to archive member.\n"),
23471 nested_arch
.file_name
);
23472 free (qualified_name
);
23477 thin_filedata
.handle
= nested_arch
.file
;
23478 thin_filedata
.file_name
= qualified_name
;
23480 if (! process_object (& thin_filedata
))
23486 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
23487 filedata
->file_name
= qualified_name
;
23488 if (! process_object (filedata
))
23490 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
23491 /* Stop looping with "negative" archive_file_size. */
23492 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
23493 arch
.next_arhdr_offset
= -1ul;
23496 free (qualified_name
);
23500 if (nested_arch
.file
!= NULL
)
23501 fclose (nested_arch
.file
);
23502 release_archive (&nested_arch
);
23503 release_archive (&arch
);
23509 process_file (char * file_name
)
23511 Filedata
* filedata
= NULL
;
23512 struct stat statbuf
;
23513 char armag
[SARMAG
];
23516 if (stat (file_name
, &statbuf
) < 0)
23518 if (errno
== ENOENT
)
23519 error (_("'%s': No such file\n"), file_name
);
23521 error (_("Could not locate '%s'. System error message: %s\n"),
23522 file_name
, strerror (errno
));
23526 if (! S_ISREG (statbuf
.st_mode
))
23528 error (_("'%s' is not an ordinary file\n"), file_name
);
23532 filedata
= calloc (1, sizeof * filedata
);
23533 if (filedata
== NULL
)
23535 error (_("Out of memory allocating file data structure\n"));
23539 filedata
->file_name
= file_name
;
23540 filedata
->handle
= fopen (file_name
, "rb");
23541 if (filedata
->handle
== NULL
)
23543 error (_("Input file '%s' is not readable.\n"), file_name
);
23548 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
23550 error (_("%s: Failed to read file's magic number\n"), file_name
);
23551 fclose (filedata
->handle
);
23556 filedata
->file_size
= statbuf
.st_size
;
23557 filedata
->is_separate
= false;
23559 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
23561 if (! process_archive (filedata
, false))
23564 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
23566 if ( ! process_archive (filedata
, true))
23571 if (do_archive_index
&& !check_all
)
23572 error (_("File %s is not an archive so its index cannot be displayed.\n"),
23575 rewind (filedata
->handle
);
23576 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
23578 if (! process_object (filedata
))
23582 fclose (filedata
->handle
);
23583 free (filedata
->section_headers
);
23584 free (filedata
->program_headers
);
23585 free (filedata
->string_table
);
23586 free (filedata
->dump
.dump_sects
);
23589 free (ba_cache
.strtab
);
23590 ba_cache
.strtab
= NULL
;
23591 free (ba_cache
.symtab
);
23592 ba_cache
.symtab
= NULL
;
23593 ba_cache
.filedata
= NULL
;
23598 #ifdef SUPPORT_DISASSEMBLY
23599 /* Needed by the i386 disassembler. For extra credit, someone could
23600 fix this so that we insert symbolic addresses here, esp for GOT/PLT
23604 print_address (unsigned int addr
, FILE * outfile
)
23606 fprintf (outfile
,"0x%8.8x", addr
);
23609 /* Needed by the i386 disassembler. */
23612 db_task_printsym (unsigned int addr
)
23614 print_address (addr
, stderr
);
23619 main (int argc
, char ** argv
)
23623 #ifdef HAVE_LC_MESSAGES
23624 setlocale (LC_MESSAGES
, "");
23626 setlocale (LC_CTYPE
, "");
23627 bindtextdomain (PACKAGE
, LOCALEDIR
);
23628 textdomain (PACKAGE
);
23630 expandargv (&argc
, &argv
);
23632 parse_args (& cmdline
, argc
, argv
);
23634 if (optind
< (argc
- 1))
23635 /* When displaying information for more than one file,
23636 prefix the information with the file name. */
23638 else if (optind
>= argc
)
23640 /* Ensure that the warning is always displayed. */
23643 warn (_("Nothing to do.\n"));
23648 while (optind
< argc
)
23649 if (! process_file (argv
[optind
++]))
23652 free (cmdline
.dump_sects
);
23654 free (dump_ctf_symtab_name
);
23655 free (dump_ctf_strtab_name
);
23656 free (dump_ctf_parent_name
);
23658 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;