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_dynamic_type (Filedata
* filedata
, unsigned long type
)
2528 static char buff
[64];
2532 case DT_NULL
: return "NULL";
2533 case DT_NEEDED
: return "NEEDED";
2534 case DT_PLTRELSZ
: return "PLTRELSZ";
2535 case DT_PLTGOT
: return "PLTGOT";
2536 case DT_HASH
: return "HASH";
2537 case DT_STRTAB
: return "STRTAB";
2538 case DT_SYMTAB
: return "SYMTAB";
2539 case DT_RELA
: return "RELA";
2540 case DT_RELASZ
: return "RELASZ";
2541 case DT_RELAENT
: return "RELAENT";
2542 case DT_STRSZ
: return "STRSZ";
2543 case DT_SYMENT
: return "SYMENT";
2544 case DT_INIT
: return "INIT";
2545 case DT_FINI
: return "FINI";
2546 case DT_SONAME
: return "SONAME";
2547 case DT_RPATH
: return "RPATH";
2548 case DT_SYMBOLIC
: return "SYMBOLIC";
2549 case DT_REL
: return "REL";
2550 case DT_RELSZ
: return "RELSZ";
2551 case DT_RELENT
: return "RELENT";
2552 case DT_RELR
: return "RELR";
2553 case DT_RELRSZ
: return "RELRSZ";
2554 case DT_RELRENT
: return "RELRENT";
2555 case DT_PLTREL
: return "PLTREL";
2556 case DT_DEBUG
: return "DEBUG";
2557 case DT_TEXTREL
: return "TEXTREL";
2558 case DT_JMPREL
: return "JMPREL";
2559 case DT_BIND_NOW
: return "BIND_NOW";
2560 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2561 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2562 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2563 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2564 case DT_RUNPATH
: return "RUNPATH";
2565 case DT_FLAGS
: return "FLAGS";
2567 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2568 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2569 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2571 case DT_CHECKSUM
: return "CHECKSUM";
2572 case DT_PLTPADSZ
: return "PLTPADSZ";
2573 case DT_MOVEENT
: return "MOVEENT";
2574 case DT_MOVESZ
: return "MOVESZ";
2575 case DT_FEATURE
: return "FEATURE";
2576 case DT_POSFLAG_1
: return "POSFLAG_1";
2577 case DT_SYMINSZ
: return "SYMINSZ";
2578 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2580 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2581 case DT_CONFIG
: return "CONFIG";
2582 case DT_DEPAUDIT
: return "DEPAUDIT";
2583 case DT_AUDIT
: return "AUDIT";
2584 case DT_PLTPAD
: return "PLTPAD";
2585 case DT_MOVETAB
: return "MOVETAB";
2586 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2588 case DT_VERSYM
: return "VERSYM";
2590 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2591 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2592 case DT_RELACOUNT
: return "RELACOUNT";
2593 case DT_RELCOUNT
: return "RELCOUNT";
2594 case DT_FLAGS_1
: return "FLAGS_1";
2595 case DT_VERDEF
: return "VERDEF";
2596 case DT_VERDEFNUM
: return "VERDEFNUM";
2597 case DT_VERNEED
: return "VERNEED";
2598 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2600 case DT_AUXILIARY
: return "AUXILIARY";
2601 case DT_USED
: return "USED";
2602 case DT_FILTER
: return "FILTER";
2604 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2605 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2606 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2607 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2608 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2609 case DT_GNU_HASH
: return "GNU_HASH";
2610 case DT_GNU_FLAGS_1
: return "GNU_FLAGS_1";
2613 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2615 const char * result
;
2617 switch (filedata
->file_header
.e_machine
)
2620 result
= get_aarch64_dynamic_type (type
);
2623 case EM_MIPS_RS3_LE
:
2624 result
= get_mips_dynamic_type (type
);
2627 result
= get_sparc64_dynamic_type (type
);
2630 result
= get_ppc_dynamic_type (type
);
2633 result
= get_ppc64_dynamic_type (type
);
2636 result
= get_ia64_dynamic_type (type
);
2639 result
= get_alpha_dynamic_type (type
);
2642 result
= get_score_dynamic_type (type
);
2645 result
= get_tic6x_dynamic_type (type
);
2647 case EM_ALTERA_NIOS2
:
2648 result
= get_nios2_dynamic_type (type
);
2651 result
= get_riscv_dynamic_type (type
);
2654 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2655 result
= get_solaris_dynamic_type (type
);
2664 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2666 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2667 || (filedata
->file_header
.e_machine
== EM_PARISC
2668 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2670 const char * result
;
2672 switch (filedata
->file_header
.e_machine
)
2675 result
= get_parisc_dynamic_type (type
);
2678 result
= get_ia64_dynamic_type (type
);
2681 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2682 result
= get_solaris_dynamic_type (type
);
2691 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2695 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2701 static bool get_program_headers (Filedata
*);
2702 static bool get_dynamic_section (Filedata
*);
2705 locate_dynamic_section (Filedata
*filedata
)
2707 uint64_t dynamic_addr
= 0;
2708 uint64_t dynamic_size
= 0;
2710 if (filedata
->file_header
.e_phnum
!= 0
2711 && get_program_headers (filedata
))
2713 Elf_Internal_Phdr
*segment
;
2716 for (i
= 0, segment
= filedata
->program_headers
;
2717 i
< filedata
->file_header
.e_phnum
;
2720 if (segment
->p_type
== PT_DYNAMIC
)
2722 dynamic_addr
= segment
->p_offset
;
2723 dynamic_size
= segment
->p_filesz
;
2725 if (filedata
->section_headers
!= NULL
)
2727 Elf_Internal_Shdr
*sec
;
2729 sec
= find_section (filedata
, ".dynamic");
2732 if (sec
->sh_size
== 0
2733 || sec
->sh_type
== SHT_NOBITS
)
2740 dynamic_addr
= sec
->sh_offset
;
2741 dynamic_size
= sec
->sh_size
;
2746 if (dynamic_addr
> filedata
->file_size
2747 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
2756 filedata
->dynamic_addr
= dynamic_addr
;
2757 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
2761 is_pie (Filedata
*filedata
)
2763 Elf_Internal_Dyn
*entry
;
2765 if (filedata
->dynamic_size
== 0)
2766 locate_dynamic_section (filedata
);
2767 if (filedata
->dynamic_size
<= 1)
2770 if (!get_dynamic_section (filedata
))
2773 for (entry
= filedata
->dynamic_section
;
2774 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
2777 if (entry
->d_tag
== DT_FLAGS_1
)
2779 if ((entry
->d_un
.d_val
& DF_1_PIE
) != 0)
2788 get_file_type (Filedata
*filedata
)
2790 unsigned e_type
= filedata
->file_header
.e_type
;
2791 static char buff
[64];
2795 case ET_NONE
: return _("NONE (None)");
2796 case ET_REL
: return _("REL (Relocatable file)");
2797 case ET_EXEC
: return _("EXEC (Executable file)");
2799 if (is_pie (filedata
))
2800 return _("DYN (Position-Independent Executable file)");
2802 return _("DYN (Shared object file)");
2803 case ET_CORE
: return _("CORE (Core file)");
2806 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2807 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2808 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2809 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2811 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2817 get_machine_name (unsigned e_machine
)
2819 static char buff
[64]; /* XXX */
2823 /* Please keep this switch table sorted by increasing EM_ value. */
2825 case EM_NONE
: return _("None");
2826 case EM_M32
: return "WE32100";
2827 case EM_SPARC
: return "Sparc";
2828 case EM_386
: return "Intel 80386";
2829 case EM_68K
: return "MC68000";
2830 case EM_88K
: return "MC88000";
2831 case EM_IAMCU
: return "Intel MCU";
2832 case EM_860
: return "Intel 80860";
2833 case EM_MIPS
: return "MIPS R3000";
2834 case EM_S370
: return "IBM System/370";
2836 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2837 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2838 case EM_PARISC
: return "HPPA";
2839 case EM_VPP550
: return "Fujitsu VPP500";
2840 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2841 case EM_960
: return "Intel 80960";
2842 case EM_PPC
: return "PowerPC";
2844 case EM_PPC64
: return "PowerPC64";
2846 case EM_S390
: return "IBM S/390";
2847 case EM_SPU
: return "SPU";
2849 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2850 case EM_FR20
: return "Fujitsu FR20";
2851 case EM_RH32
: return "TRW RH32";
2852 case EM_MCORE
: return "MCORE";
2854 case EM_ARM
: return "ARM";
2855 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2856 case EM_SH
: return "Renesas / SuperH SH";
2857 case EM_SPARCV9
: return "Sparc v9";
2858 case EM_TRICORE
: return "Siemens Tricore";
2859 case EM_ARC
: return "ARC";
2860 case EM_H8_300
: return "Renesas H8/300";
2861 case EM_H8_300H
: return "Renesas H8/300H";
2862 case EM_H8S
: return "Renesas H8S";
2863 case EM_H8_500
: return "Renesas H8/500";
2865 case EM_IA_64
: return "Intel IA-64";
2866 case EM_MIPS_X
: return "Stanford MIPS-X";
2867 case EM_COLDFIRE
: return "Motorola Coldfire";
2868 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2869 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2870 case EM_PCP
: return "Siemens PCP";
2871 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2872 case EM_NDR1
: return "Denso NDR1 microprocessor";
2873 case EM_STARCORE
: return "Motorola Star*Core processor";
2874 case EM_ME16
: return "Toyota ME16 processor";
2876 case EM_ST100
: return "STMicroelectronics ST100 processor";
2877 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2878 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2879 case EM_PDSP
: return "Sony DSP processor";
2880 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2881 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2882 case EM_FX66
: return "Siemens FX66 microcontroller";
2883 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2884 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2885 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2887 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2888 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2889 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2890 case EM_SVX
: return "Silicon Graphics SVx";
2891 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2892 case EM_VAX
: return "Digital VAX";
2893 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2894 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2895 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2896 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2898 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2899 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2900 case EM_PRISM
: return "Vitesse Prism";
2902 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2903 case EM_CYGNUS_FR30
:
2904 case EM_FR30
: return "Fujitsu FR30";
2905 case EM_CYGNUS_D10V
:
2906 case EM_D10V
: return "d10v";
2907 case EM_CYGNUS_D30V
:
2908 case EM_D30V
: return "d30v";
2909 case EM_CYGNUS_V850
:
2910 case EM_V850
: return "Renesas V850";
2911 case EM_CYGNUS_M32R
:
2912 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2913 case EM_CYGNUS_MN10300
:
2914 case EM_MN10300
: return "mn10300";
2916 case EM_CYGNUS_MN10200
:
2917 case EM_MN10200
: return "mn10200";
2918 case EM_PJ
: return "picoJava";
2919 case EM_OR1K
: return "OpenRISC 1000";
2920 case EM_ARC_COMPACT
: return "ARCompact";
2922 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2923 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2924 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2925 case EM_NS32K
: return "National Semiconductor 32000 series";
2926 case EM_TPC
: return "Tenor Network TPC processor";
2927 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2929 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2931 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2932 case EM_MAX
: return "MAX Processor";
2933 case EM_CR
: return "National Semiconductor CompactRISC";
2934 case EM_F2MC16
: return "Fujitsu F2MC16";
2935 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2936 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2937 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2938 case EM_SEP
: return "Sharp embedded microprocessor";
2939 case EM_ARCA
: return "Arca RISC microprocessor";
2941 case EM_UNICORE
: return "Unicore";
2942 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2943 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2944 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2945 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2946 case EM_XGATE
: return "Motorola XGATE embedded processor";
2948 case EM_XC16X
: return "Infineon Technologies xc16x";
2949 case EM_M16C
: return "Renesas M16C series microprocessors";
2950 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2951 case EM_CE
: return "Freescale Communication Engine RISC core";
2953 case EM_M32C
: return "Renesas M32c";
2955 case EM_TSK3000
: return "Altium TSK3000 core";
2956 case EM_RS08
: return "Freescale RS08 embedded processor";
2957 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2958 case EM_SCORE
: return "SUNPLUS S+Core";
2959 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2960 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2961 case EM_LATTICEMICO32
: return "Lattice Mico32";
2962 case EM_SE_C17
: return "Seiko Epson C17 family";
2964 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2965 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2966 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2967 case EM_TI_PRU
: return "TI PRU I/O processor";
2969 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2970 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2971 case EM_R32C
: return "Renesas R32C series microprocessors";
2972 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2973 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2974 case EM_8051
: return "Intel 8051 and variants";
2975 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2976 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2977 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2978 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2980 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
2981 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
2982 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
2983 case EM_RX
: return "Renesas RX";
2984 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
2985 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
2986 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
2989 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
2990 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
2991 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
2993 case EM_L1OM
: return "Intel L1OM";
2994 case EM_K1OM
: return "Intel K1OM";
2995 case EM_INTEL182
: return "Intel (reserved)";
2996 case EM_AARCH64
: return "AArch64";
2997 case EM_ARM184
: return "ARM (reserved)";
2998 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
2999 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
3000 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
3001 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
3003 case EM_CUDA
: return "NVIDIA CUDA architecture";
3004 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
3005 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
3006 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
3007 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
3008 case EM_ARC_COMPACT2
: return "ARCv2";
3009 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
3010 case EM_RL78
: return "Renesas RL78";
3011 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
3012 case EM_78K0R
: return "Renesas 78K0R";
3014 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
3015 case EM_BA1
: return "Beyond BA1 CPU architecture";
3016 case EM_BA2
: return "Beyond BA2 CPU architecture";
3017 case EM_XCORE
: return "XMOS xCORE processor family";
3018 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
3019 case EM_INTELGT
: return "Intel Graphics Technology";
3021 case EM_KM32
: return "KM211 KM32 32-bit processor";
3022 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
3023 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
3024 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
3025 case EM_KVARC
: return "KM211 KVARC processor";
3026 case EM_CDP
: return "Paneve CDP architecture family";
3027 case EM_COGE
: return "Cognitive Smart Memory Processor";
3028 case EM_COOL
: return "Bluechip Systems CoolEngine";
3029 case EM_NORC
: return "Nanoradio Optimized RISC";
3030 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
3032 case EM_Z80
: return "Zilog Z80";
3033 case EM_VISIUM
: return "CDS VISIUMcore processor";
3034 case EM_FT32
: return "FTDI Chip FT32";
3035 case EM_MOXIE
: return "Moxie";
3036 case EM_AMDGPU
: return "AMD GPU";
3037 /* 230 (all reserved) */
3039 case EM_RISCV
: return "RISC-V";
3040 case EM_LANAI
: return "Lanai 32-bit processor";
3041 case EM_CEVA
: return "CEVA Processor Architecture Family";
3042 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
3043 case EM_BPF
: return "Linux BPF";
3044 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
3045 case EM_IMG1
: return "Imagination Technologies";
3047 case EM_NFP
: return "Netronome Flow Processor";
3048 case EM_VE
: return "NEC Vector Engine";
3049 case EM_CSKY
: return "C-SKY";
3050 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv3 64-bit processor";
3051 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
3052 case EM_ARC_COMPACT3
: return "Synopsys ARCv3 32-bit processor";
3053 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
3054 case EM_65816
: return "WDC 65816/65C816";
3055 case EM_LOONGARCH
: return "LoongArch";
3056 case EM_KF32
: return "ChipON KungFu32";
3058 /* Large numbers... */
3059 case EM_MT
: return "Morpho Techologies MT processor";
3060 case EM_ALPHA
: return "Alpha";
3061 case EM_WEBASSEMBLY
: return "Web Assembly";
3062 case EM_DLX
: return "OpenDLX";
3063 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
3064 case EM_IQ2000
: return "Vitesse IQ2000";
3066 case EM_NIOS32
: return "Altera Nios";
3067 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
3068 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
3069 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
3070 case EM_S12Z
: return "Freescale S12Z";
3073 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
3079 decode_ARC_machine_flags (char *out
, unsigned e_flags
, unsigned e_machine
)
3081 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
3082 other compilers don't specify an architecture type in the e_flags, and
3083 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
3084 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
3087 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
3088 but also sets a specific architecture type in the e_flags field.
3090 However, when decoding the flags we don't worry if we see an
3091 unexpected pairing, for example EM_ARC_COMPACT machine type, with
3092 ARCEM architecture type. */
3094 switch (e_flags
& EF_ARC_MACH_MSK
)
3096 /* We only expect these to occur for EM_ARC_COMPACT2. */
3097 case EF_ARC_CPU_ARCV2EM
:
3098 out
= stpcpy (out
, ", ARC EM");
3100 case EF_ARC_CPU_ARCV2HS
:
3101 out
= stpcpy (out
, ", ARC HS");
3104 /* We only expect these to occur for EM_ARC_COMPACT. */
3105 case E_ARC_MACH_ARC600
:
3106 out
= stpcpy (out
, ", ARC600");
3108 case E_ARC_MACH_ARC601
:
3109 out
= stpcpy (out
, ", ARC601");
3111 case E_ARC_MACH_ARC700
:
3112 out
= stpcpy (out
, ", ARC700");
3115 /* The only times we should end up here are (a) A corrupt ELF, (b) A
3116 new ELF with new architecture being read by an old version of
3117 readelf, or (c) An ELF built with non-GNU compiler that does not
3118 set the architecture in the e_flags. */
3120 if (e_machine
== EM_ARC_COMPACT
)
3121 out
= stpcpy (out
, ", Unknown ARCompact");
3123 out
= stpcpy (out
, ", Unknown ARC");
3127 switch (e_flags
& EF_ARC_OSABI_MSK
)
3129 case E_ARC_OSABI_ORIG
:
3130 out
= stpcpy (out
, ", (ABI:legacy)");
3132 case E_ARC_OSABI_V2
:
3133 out
= stpcpy (out
, ", (ABI:v2)");
3135 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
3136 case E_ARC_OSABI_V3
:
3137 out
= stpcpy (out
, ", v3 no-legacy-syscalls ABI");
3139 case E_ARC_OSABI_V4
:
3140 out
= stpcpy (out
, ", v4 ABI");
3143 out
= stpcpy (out
, ", unrecognised ARC OSABI flag");
3150 decode_ARM_machine_flags (char *out
, unsigned e_flags
)
3153 bool unknown
= false;
3155 eabi
= EF_ARM_EABI_VERSION (e_flags
);
3156 e_flags
&= ~ EF_ARM_EABIMASK
;
3158 /* Handle "generic" ARM flags. */
3159 if (e_flags
& EF_ARM_RELEXEC
)
3161 out
= stpcpy (out
, ", relocatable executable");
3162 e_flags
&= ~ EF_ARM_RELEXEC
;
3165 if (e_flags
& EF_ARM_PIC
)
3167 out
= stpcpy (out
, ", position independent");
3168 e_flags
&= ~ EF_ARM_PIC
;
3171 /* Now handle EABI specific flags. */
3175 out
= stpcpy (out
, ", <unrecognized EABI>");
3180 case EF_ARM_EABI_VER1
:
3181 out
= stpcpy (out
, ", Version1 EABI");
3186 /* Process flags one bit at a time. */
3187 flag
= e_flags
& - e_flags
;
3192 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3193 out
= stpcpy (out
, ", sorted symbol tables");
3203 case EF_ARM_EABI_VER2
:
3204 out
= stpcpy (out
, ", Version2 EABI");
3209 /* Process flags one bit at a time. */
3210 flag
= e_flags
& - e_flags
;
3215 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3216 out
= stpcpy (out
, ", sorted symbol tables");
3219 case EF_ARM_DYNSYMSUSESEGIDX
:
3220 out
= stpcpy (out
, ", dynamic symbols use segment index");
3223 case EF_ARM_MAPSYMSFIRST
:
3224 out
= stpcpy (out
, ", mapping symbols precede others");
3234 case EF_ARM_EABI_VER3
:
3235 out
= stpcpy (out
, ", Version3 EABI");
3238 case EF_ARM_EABI_VER4
:
3239 out
= stpcpy (out
, ", Version4 EABI");
3244 /* Process flags one bit at a time. */
3245 flag
= e_flags
& - e_flags
;
3251 out
= stpcpy (out
, ", BE8");
3255 out
= stpcpy (out
, ", LE8");
3265 case EF_ARM_EABI_VER5
:
3266 out
= stpcpy (out
, ", Version5 EABI");
3271 /* Process flags one bit at a time. */
3272 flag
= e_flags
& - e_flags
;
3278 out
= stpcpy (out
, ", BE8");
3282 out
= stpcpy (out
, ", LE8");
3285 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
3286 out
= stpcpy (out
, ", soft-float ABI");
3289 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
3290 out
= stpcpy (out
, ", hard-float ABI");
3300 case EF_ARM_EABI_UNKNOWN
:
3301 out
= stpcpy (out
, ", GNU EABI");
3306 /* Process flags one bit at a time. */
3307 flag
= e_flags
& - e_flags
;
3312 case EF_ARM_INTERWORK
:
3313 out
= stpcpy (out
, ", interworking enabled");
3316 case EF_ARM_APCS_26
:
3317 out
= stpcpy (out
, ", uses APCS/26");
3320 case EF_ARM_APCS_FLOAT
:
3321 out
= stpcpy (out
, ", uses APCS/float");
3325 out
= stpcpy (out
, ", position independent");
3329 out
= stpcpy (out
, ", 8 bit structure alignment");
3332 case EF_ARM_NEW_ABI
:
3333 out
= stpcpy (out
, ", uses new ABI");
3336 case EF_ARM_OLD_ABI
:
3337 out
= stpcpy (out
, ", uses old ABI");
3340 case EF_ARM_SOFT_FLOAT
:
3341 out
= stpcpy (out
, ", software FP");
3344 case EF_ARM_VFP_FLOAT
:
3345 out
= stpcpy (out
, ", VFP");
3348 case EF_ARM_MAVERICK_FLOAT
:
3349 out
= stpcpy (out
, ", Maverick FP");
3360 out
= stpcpy (out
,_(", <unknown>"));
3365 decode_AVR_machine_flags (char *out
, unsigned e_flags
)
3367 switch (e_flags
& EF_AVR_MACH
)
3369 case E_AVR_MACH_AVR1
:
3370 out
= stpcpy (out
, ", avr:1");
3372 case E_AVR_MACH_AVR2
:
3373 out
= stpcpy (out
, ", avr:2");
3375 case E_AVR_MACH_AVR25
:
3376 out
= stpcpy (out
, ", avr:25");
3378 case E_AVR_MACH_AVR3
:
3379 out
= stpcpy (out
, ", avr:3");
3381 case E_AVR_MACH_AVR31
:
3382 out
= stpcpy (out
, ", avr:31");
3384 case E_AVR_MACH_AVR35
:
3385 out
= stpcpy (out
, ", avr:35");
3387 case E_AVR_MACH_AVR4
:
3388 out
= stpcpy (out
, ", avr:4");
3390 case E_AVR_MACH_AVR5
:
3391 out
= stpcpy (out
, ", avr:5");
3393 case E_AVR_MACH_AVR51
:
3394 out
= stpcpy (out
, ", avr:51");
3396 case E_AVR_MACH_AVR6
:
3397 out
= stpcpy (out
, ", avr:6");
3399 case E_AVR_MACH_AVRTINY
:
3400 out
= stpcpy (out
, ", avr:100");
3402 case E_AVR_MACH_XMEGA1
:
3403 out
= stpcpy (out
, ", avr:101");
3405 case E_AVR_MACH_XMEGA2
:
3406 out
= stpcpy (out
, ", avr:102");
3408 case E_AVR_MACH_XMEGA3
:
3409 out
= stpcpy (out
, ", avr:103");
3411 case E_AVR_MACH_XMEGA4
:
3412 out
= stpcpy (out
, ", avr:104");
3414 case E_AVR_MACH_XMEGA5
:
3415 out
= stpcpy (out
, ", avr:105");
3417 case E_AVR_MACH_XMEGA6
:
3418 out
= stpcpy (out
, ", avr:106");
3420 case E_AVR_MACH_XMEGA7
:
3421 out
= stpcpy (out
, ", avr:107");
3424 out
= stpcpy (out
, ", avr:<unknown>");
3428 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
3429 out
= stpcpy (out
, ", link-relax");
3434 decode_BLACKFIN_machine_flags (char *out
, unsigned e_flags
)
3436 if (e_flags
& EF_BFIN_PIC
)
3437 out
= stpcpy (out
, ", PIC");
3439 if (e_flags
& EF_BFIN_FDPIC
)
3440 out
= stpcpy (out
, ", FDPIC");
3442 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3443 out
= stpcpy (out
, ", code in L1");
3445 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3446 out
= stpcpy (out
, ", data in L1");
3451 decode_FRV_machine_flags (char *out
, unsigned e_flags
)
3453 switch (e_flags
& EF_FRV_CPU_MASK
)
3455 case EF_FRV_CPU_GENERIC
:
3459 out
= stpcpy (out
, ", fr???");
3462 case EF_FRV_CPU_FR300
:
3463 out
= stpcpy (out
, ", fr300");
3466 case EF_FRV_CPU_FR400
:
3467 out
= stpcpy (out
, ", fr400");
3469 case EF_FRV_CPU_FR405
:
3470 out
= stpcpy (out
, ", fr405");
3473 case EF_FRV_CPU_FR450
:
3474 out
= stpcpy (out
, ", fr450");
3477 case EF_FRV_CPU_FR500
:
3478 out
= stpcpy (out
, ", fr500");
3480 case EF_FRV_CPU_FR550
:
3481 out
= stpcpy (out
, ", fr550");
3484 case EF_FRV_CPU_SIMPLE
:
3485 out
= stpcpy (out
, ", simple");
3487 case EF_FRV_CPU_TOMCAT
:
3488 out
= stpcpy (out
, ", tomcat");
3495 decode_IA64_machine_flags (char *out
, unsigned e_flags
, Filedata
*filedata
)
3497 if ((e_flags
& EF_IA_64_ABI64
))
3498 out
= stpcpy (out
, ", 64-bit");
3500 out
= stpcpy (out
, ", 32-bit");
3501 if ((e_flags
& EF_IA_64_REDUCEDFP
))
3502 out
= stpcpy (out
, ", reduced fp model");
3503 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
3504 out
= stpcpy (out
, ", no function descriptors, constant gp");
3505 else if ((e_flags
& EF_IA_64_CONS_GP
))
3506 out
= stpcpy (out
, ", constant gp");
3507 if ((e_flags
& EF_IA_64_ABSOLUTE
))
3508 out
= stpcpy (out
, ", absolute");
3509 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3511 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
3512 out
= stpcpy (out
, ", vms_linkages");
3513 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
3515 case EF_IA_64_VMS_COMCOD_SUCCESS
:
3517 case EF_IA_64_VMS_COMCOD_WARNING
:
3518 out
= stpcpy (out
, ", warning");
3520 case EF_IA_64_VMS_COMCOD_ERROR
:
3521 out
= stpcpy (out
, ", error");
3523 case EF_IA_64_VMS_COMCOD_ABORT
:
3524 out
= stpcpy (out
, ", abort");
3527 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3528 e_flags
& EF_IA_64_VMS_COMCOD
);
3529 out
= stpcpy (out
, ", <unknown>");
3536 decode_LOONGARCH_machine_flags (char *out
, unsigned int e_flags
)
3538 if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags
))
3539 out
= stpcpy (out
, ", SOFT-FLOAT");
3540 else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags
))
3541 out
= stpcpy (out
, ", SINGLE-FLOAT");
3542 else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags
))
3543 out
= stpcpy (out
, ", DOUBLE-FLOAT");
3545 if (EF_LOONGARCH_IS_OBJ_V0 (e_flags
))
3546 out
= stpcpy (out
, ", OBJ-v0");
3547 else if (EF_LOONGARCH_IS_OBJ_V1 (e_flags
))
3548 out
= stpcpy (out
, ", OBJ-v1");
3553 decode_M68K_machine_flags (char *out
, unsigned int e_flags
)
3555 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3556 out
= stpcpy (out
, ", m68000");
3557 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3558 out
= stpcpy (out
, ", cpu32");
3559 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3560 out
= stpcpy (out
, ", fido_a");
3563 char const *isa
= _("unknown");
3564 char const *mac
= _("unknown mac");
3565 char const *additional
= NULL
;
3567 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3569 case EF_M68K_CF_ISA_A_NODIV
:
3571 additional
= ", nodiv";
3573 case EF_M68K_CF_ISA_A
:
3576 case EF_M68K_CF_ISA_A_PLUS
:
3579 case EF_M68K_CF_ISA_B_NOUSP
:
3581 additional
= ", nousp";
3583 case EF_M68K_CF_ISA_B
:
3586 case EF_M68K_CF_ISA_C
:
3589 case EF_M68K_CF_ISA_C_NODIV
:
3591 additional
= ", nodiv";
3594 out
= stpcpy (out
, ", cf, isa ");
3595 out
= stpcpy (out
, isa
);
3597 out
= stpcpy (out
, additional
);
3598 if (e_flags
& EF_M68K_CF_FLOAT
)
3599 out
= stpcpy (out
, ", float");
3600 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3605 case EF_M68K_CF_MAC
:
3608 case EF_M68K_CF_EMAC
:
3611 case EF_M68K_CF_EMAC_B
:
3617 out
= stpcpy (out
, ", ");
3618 out
= stpcpy (out
, mac
);
3625 decode_MeP_machine_flags (char *out
, unsigned int e_flags
)
3627 switch (e_flags
& EF_MEP_CPU_MASK
)
3629 case EF_MEP_CPU_MEP
:
3630 out
= stpcpy (out
, ", generic MeP");
3633 out
= stpcpy (out
, ", MeP C2");
3636 out
= stpcpy (out
, ", MeP C3");
3639 out
= stpcpy (out
, ", MeP C4");
3642 out
= stpcpy (out
, ", MeP C5");
3645 out
= stpcpy (out
, ", MeP H1");
3648 out
= stpcpy (out
, _(", <unknown MeP cpu type>"));
3652 switch (e_flags
& EF_MEP_COP_MASK
)
3654 case EF_MEP_COP_NONE
:
3656 case EF_MEP_COP_AVC
:
3657 out
= stpcpy (out
, ", AVC coprocessor");
3659 case EF_MEP_COP_AVC2
:
3660 out
= stpcpy (out
, ", AVC2 coprocessor");
3662 case EF_MEP_COP_FMAX
:
3663 out
= stpcpy (out
, ", FMAX coprocessor");
3665 case EF_MEP_COP_IVC2
:
3666 out
= stpcpy (out
, ", IVC2 coprocessor");
3669 out
= stpcpy (out
, _("<unknown MeP copro type>"));
3673 if (e_flags
& EF_MEP_LIBRARY
)
3674 out
= stpcpy (out
, ", Built for Library");
3676 if (e_flags
& EF_MEP_INDEX_MASK
)
3677 out
+= sprintf (out
, ", Configuration Index: %#x",
3678 e_flags
& EF_MEP_INDEX_MASK
);
3680 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3681 out
+= sprintf (out
, _(", unknown flags bits: %#x"),
3682 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3687 decode_MIPS_machine_flags (char *out
, unsigned int e_flags
)
3689 if (e_flags
& EF_MIPS_NOREORDER
)
3690 out
= stpcpy (out
, ", noreorder");
3692 if (e_flags
& EF_MIPS_PIC
)
3693 out
= stpcpy (out
, ", pic");
3695 if (e_flags
& EF_MIPS_CPIC
)
3696 out
= stpcpy (out
, ", cpic");
3698 if (e_flags
& EF_MIPS_UCODE
)
3699 out
= stpcpy (out
, ", ugen_reserved");
3701 if (e_flags
& EF_MIPS_ABI2
)
3702 out
= stpcpy (out
, ", abi2");
3704 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
3705 out
= stpcpy (out
, ", odk first");
3707 if (e_flags
& EF_MIPS_32BITMODE
)
3708 out
= stpcpy (out
, ", 32bitmode");
3710 if (e_flags
& EF_MIPS_NAN2008
)
3711 out
= stpcpy (out
, ", nan2008");
3713 if (e_flags
& EF_MIPS_FP64
)
3714 out
= stpcpy (out
, ", fp64");
3716 switch ((e_flags
& EF_MIPS_MACH
))
3718 case E_MIPS_MACH_3900
:
3719 out
= stpcpy (out
, ", 3900");
3721 case E_MIPS_MACH_4010
:
3722 out
= stpcpy (out
, ", 4010");
3724 case E_MIPS_MACH_4100
:
3725 out
= stpcpy (out
, ", 4100");
3727 case E_MIPS_MACH_4111
:
3728 out
= stpcpy (out
, ", 4111");
3730 case E_MIPS_MACH_4120
:
3731 out
= stpcpy (out
, ", 4120");
3733 case E_MIPS_MACH_4650
:
3734 out
= stpcpy (out
, ", 4650");
3736 case E_MIPS_MACH_5400
:
3737 out
= stpcpy (out
, ", 5400");
3739 case E_MIPS_MACH_5500
:
3740 out
= stpcpy (out
, ", 5500");
3742 case E_MIPS_MACH_5900
:
3743 out
= stpcpy (out
, ", 5900");
3745 case E_MIPS_MACH_SB1
:
3746 out
= stpcpy (out
, ", sb1");
3748 case E_MIPS_MACH_9000
:
3749 out
= stpcpy (out
, ", 9000");
3751 case E_MIPS_MACH_LS2E
:
3752 out
= stpcpy (out
, ", loongson-2e");
3754 case E_MIPS_MACH_LS2F
:
3755 out
= stpcpy (out
, ", loongson-2f");
3757 case E_MIPS_MACH_GS464
:
3758 out
= stpcpy (out
, ", gs464");
3760 case E_MIPS_MACH_GS464E
:
3761 out
= stpcpy (out
, ", gs464e");
3763 case E_MIPS_MACH_GS264E
:
3764 out
= stpcpy (out
, ", gs264e");
3766 case E_MIPS_MACH_OCTEON
:
3767 out
= stpcpy (out
, ", octeon");
3769 case E_MIPS_MACH_OCTEON2
:
3770 out
= stpcpy (out
, ", octeon2");
3772 case E_MIPS_MACH_OCTEON3
:
3773 out
= stpcpy (out
, ", octeon3");
3775 case E_MIPS_MACH_XLR
:
3776 out
= stpcpy (out
, ", xlr");
3778 case E_MIPS_MACH_IAMR2
:
3779 out
= stpcpy (out
, ", interaptiv-mr2");
3781 case E_MIPS_MACH_ALLEGREX
:
3782 out
= stpcpy (out
, ", allegrex");
3785 /* We simply ignore the field in this case to avoid confusion:
3786 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3790 out
= stpcpy (out
, _(", unknown CPU"));
3794 switch ((e_flags
& EF_MIPS_ABI
))
3796 case E_MIPS_ABI_O32
:
3797 out
= stpcpy (out
, ", o32");
3799 case E_MIPS_ABI_O64
:
3800 out
= stpcpy (out
, ", o64");
3802 case E_MIPS_ABI_EABI32
:
3803 out
= stpcpy (out
, ", eabi32");
3805 case E_MIPS_ABI_EABI64
:
3806 out
= stpcpy (out
, ", eabi64");
3809 /* We simply ignore the field in this case to avoid confusion:
3810 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3811 This means it is likely to be an o32 file, but not for
3815 out
= stpcpy (out
, _(", unknown ABI"));
3819 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
3820 out
= stpcpy (out
, ", mdmx");
3822 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
3823 out
= stpcpy (out
, ", mips16");
3825 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
3826 out
= stpcpy (out
, ", micromips");
3828 switch ((e_flags
& EF_MIPS_ARCH
))
3831 out
= stpcpy (out
, ", mips1");
3834 out
= stpcpy (out
, ", mips2");
3837 out
= stpcpy (out
, ", mips3");
3840 out
= stpcpy (out
, ", mips4");
3843 out
= stpcpy (out
, ", mips5");
3845 case E_MIPS_ARCH_32
:
3846 out
= stpcpy (out
, ", mips32");
3848 case E_MIPS_ARCH_32R2
:
3849 out
= stpcpy (out
, ", mips32r2");
3851 case E_MIPS_ARCH_32R6
:
3852 out
= stpcpy (out
, ", mips32r6");
3854 case E_MIPS_ARCH_64
:
3855 out
= stpcpy (out
, ", mips64");
3857 case E_MIPS_ARCH_64R2
:
3858 out
= stpcpy (out
, ", mips64r2");
3860 case E_MIPS_ARCH_64R6
:
3861 out
= stpcpy (out
, ", mips64r6");
3864 out
= stpcpy (out
, _(", unknown ISA"));
3871 decode_MSP430_machine_flags (char *out
, unsigned e_flags
)
3873 out
= stpcpy (out
, _(": architecture variant: "));
3874 switch (e_flags
& EF_MSP430_MACH
)
3876 case E_MSP430_MACH_MSP430x11
:
3877 out
= stpcpy (out
, "MSP430x11");
3879 case E_MSP430_MACH_MSP430x11x1
:
3880 out
= stpcpy (out
, "MSP430x11x1 ");
3882 case E_MSP430_MACH_MSP430x12
:
3883 out
= stpcpy (out
, "MSP430x12");
3885 case E_MSP430_MACH_MSP430x13
:
3886 out
= stpcpy (out
, "MSP430x13");
3888 case E_MSP430_MACH_MSP430x14
:
3889 out
= stpcpy (out
, "MSP430x14");
3891 case E_MSP430_MACH_MSP430x15
:
3892 out
= stpcpy (out
, "MSP430x15");
3894 case E_MSP430_MACH_MSP430x16
:
3895 out
= stpcpy (out
, "MSP430x16");
3897 case E_MSP430_MACH_MSP430x31
:
3898 out
= stpcpy (out
, "MSP430x31");
3900 case E_MSP430_MACH_MSP430x32
:
3901 out
= stpcpy (out
, "MSP430x32");
3903 case E_MSP430_MACH_MSP430x33
:
3904 out
= stpcpy (out
, "MSP430x33");
3906 case E_MSP430_MACH_MSP430x41
:
3907 out
= stpcpy (out
, "MSP430x41");
3909 case E_MSP430_MACH_MSP430x42
:
3910 out
= stpcpy (out
, "MSP430x42");
3912 case E_MSP430_MACH_MSP430x43
:
3913 out
= stpcpy (out
, "MSP430x43");
3915 case E_MSP430_MACH_MSP430x44
:
3916 out
= stpcpy (out
, "MSP430x44");
3918 case E_MSP430_MACH_MSP430X
:
3919 out
= stpcpy (out
, "MSP430X");
3922 out
= stpcpy (out
, _(": unknown"));
3926 if (e_flags
& ~ EF_MSP430_MACH
)
3927 out
= stpcpy (out
, _(": unknown extra flag bits also present"));
3932 decode_NDS32_machine_flags (char *out
, unsigned e_flags
)
3938 bool has_fpu
= false;
3940 static const char *ABI_STRINGS
[] =
3942 "ABI v0", /* use r5 as return register; only used in N1213HC */
3943 "ABI v1", /* use r0 as return register */
3944 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
3945 "ABI v2fp", /* for FPU */
3949 static const char *VER_STRINGS
[] =
3951 "Andes ELF V1.3 or older",
3955 static const char *ARCH_STRINGS
[] =
3964 abi
= EF_NDS_ABI
& e_flags
;
3965 arch
= EF_NDS_ARCH
& e_flags
;
3966 config
= EF_NDS_INST
& e_flags
;
3967 version
= EF_NDS32_ELF_VERSION
& e_flags
;
3974 case E_NDS_ABI_V2FP
:
3975 case E_NDS_ABI_AABI
:
3976 case E_NDS_ABI_V2FP_PLUS
:
3977 /* In case there are holes in the array. */
3978 out
+= sprintf (out
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
3982 out
= stpcpy (out
, ", <unrecognized ABI>");
3988 case E_NDS32_ELF_VER_1_2
:
3989 case E_NDS32_ELF_VER_1_3
:
3990 case E_NDS32_ELF_VER_1_4
:
3991 out
+= sprintf (out
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
3995 out
= stpcpy (out
, ", <unrecognized ELF version number>");
3999 if (E_NDS_ABI_V0
== abi
)
4001 /* OLD ABI; only used in N1213HC, has performance extension 1. */
4002 out
= stpcpy (out
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
4003 if (arch
== E_NDS_ARCH_STAR_V1_0
)
4004 out
= stpcpy (out
, ", 16b"); /* has 16-bit instructions */
4010 case E_NDS_ARCH_STAR_V1_0
:
4011 case E_NDS_ARCH_STAR_V2_0
:
4012 case E_NDS_ARCH_STAR_V3_0
:
4013 case E_NDS_ARCH_STAR_V3_M
:
4014 out
+= sprintf (out
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
4018 out
= stpcpy (out
, ", <unrecognized architecture>");
4019 /* ARCH version determines how the e_flags are interpreted.
4020 If it is unknown, we cannot proceed. */
4024 /* Newer ABI; Now handle architecture specific flags. */
4025 if (arch
== E_NDS_ARCH_STAR_V1_0
)
4027 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
4028 out
= stpcpy (out
, ", MFUSR_PC");
4030 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
4031 out
= stpcpy (out
, ", MAC");
4033 if (config
& E_NDS32_HAS_DIV_INST
)
4034 out
= stpcpy (out
, ", DIV");
4036 if (config
& E_NDS32_HAS_16BIT_INST
)
4037 out
= stpcpy (out
, ", 16b");
4041 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
4043 if (version
<= E_NDS32_ELF_VER_1_3
)
4044 out
= stpcpy (out
, ", [B8]");
4046 out
= stpcpy (out
, ", EX9");
4049 if (config
& E_NDS32_HAS_MAC_DX_INST
)
4050 out
= stpcpy (out
, ", MAC_DX");
4052 if (config
& E_NDS32_HAS_DIV_DX_INST
)
4053 out
= stpcpy (out
, ", DIV_DX");
4055 if (config
& E_NDS32_HAS_16BIT_INST
)
4057 if (version
<= E_NDS32_ELF_VER_1_3
)
4058 out
= stpcpy (out
, ", 16b");
4060 out
= stpcpy (out
, ", IFC");
4064 if (config
& E_NDS32_HAS_EXT_INST
)
4065 out
= stpcpy (out
, ", PERF1");
4067 if (config
& E_NDS32_HAS_EXT2_INST
)
4068 out
= stpcpy (out
, ", PERF2");
4070 if (config
& E_NDS32_HAS_FPU_INST
)
4073 out
= stpcpy (out
, ", FPU_SP");
4076 if (config
& E_NDS32_HAS_FPU_DP_INST
)
4079 out
= stpcpy (out
, ", FPU_DP");
4082 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
4085 out
= stpcpy (out
, ", FPU_MAC");
4090 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
4092 case E_NDS32_FPU_REG_8SP_4DP
:
4093 out
= stpcpy (out
, ", FPU_REG:8/4");
4095 case E_NDS32_FPU_REG_16SP_8DP
:
4096 out
= stpcpy (out
, ", FPU_REG:16/8");
4098 case E_NDS32_FPU_REG_32SP_16DP
:
4099 out
= stpcpy (out
, ", FPU_REG:32/16");
4101 case E_NDS32_FPU_REG_32SP_32DP
:
4102 out
= stpcpy (out
, ", FPU_REG:32/32");
4107 if (config
& E_NDS32_HAS_AUDIO_INST
)
4108 out
= stpcpy (out
, ", AUDIO");
4110 if (config
& E_NDS32_HAS_STRING_INST
)
4111 out
= stpcpy (out
, ", STR");
4113 if (config
& E_NDS32_HAS_REDUCED_REGS
)
4114 out
= stpcpy (out
, ", 16REG");
4116 if (config
& E_NDS32_HAS_VIDEO_INST
)
4118 if (version
<= E_NDS32_ELF_VER_1_3
)
4119 out
= stpcpy (out
, ", VIDEO");
4121 out
= stpcpy (out
, ", SATURATION");
4124 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
4125 out
= stpcpy (out
, ", ENCRP");
4127 if (config
& E_NDS32_HAS_L2C_INST
)
4128 out
= stpcpy (out
, ", L2C");
4134 decode_PARISC_machine_flags (char *out
, unsigned e_flags
)
4136 switch (e_flags
& EF_PARISC_ARCH
)
4138 case EFA_PARISC_1_0
:
4139 out
= stpcpy (out
, ", PA-RISC 1.0");
4141 case EFA_PARISC_1_1
:
4142 out
= stpcpy (out
, ", PA-RISC 1.1");
4144 case EFA_PARISC_2_0
:
4145 out
= stpcpy (out
, ", PA-RISC 2.0");
4150 if (e_flags
& EF_PARISC_TRAPNIL
)
4151 out
= stpcpy (out
, ", trapnil");
4152 if (e_flags
& EF_PARISC_EXT
)
4153 out
= stpcpy (out
, ", ext");
4154 if (e_flags
& EF_PARISC_LSB
)
4155 out
= stpcpy (out
, ", lsb");
4156 if (e_flags
& EF_PARISC_WIDE
)
4157 out
= stpcpy (out
, ", wide");
4158 if (e_flags
& EF_PARISC_NO_KABP
)
4159 out
= stpcpy (out
, ", no kabp");
4160 if (e_flags
& EF_PARISC_LAZYSWAP
)
4161 out
= stpcpy (out
, ", lazyswap");
4166 decode_RISCV_machine_flags (char *out
, unsigned e_flags
)
4168 if (e_flags
& EF_RISCV_RVC
)
4169 out
= stpcpy (out
, ", RVC");
4171 if (e_flags
& EF_RISCV_RVE
)
4172 out
= stpcpy (out
, ", RVE");
4174 if (e_flags
& EF_RISCV_TSO
)
4175 out
= stpcpy (out
, ", TSO");
4177 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
4179 case EF_RISCV_FLOAT_ABI_SOFT
:
4180 out
= stpcpy (out
, ", soft-float ABI");
4183 case EF_RISCV_FLOAT_ABI_SINGLE
:
4184 out
= stpcpy (out
, ", single-float ABI");
4187 case EF_RISCV_FLOAT_ABI_DOUBLE
:
4188 out
= stpcpy (out
, ", double-float ABI");
4191 case EF_RISCV_FLOAT_ABI_QUAD
:
4192 out
= stpcpy (out
, ", quad-float ABI");
4199 decode_RL78_machine_flags (char *out
, unsigned e_flags
)
4201 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
4203 case E_FLAG_RL78_ANY_CPU
:
4205 case E_FLAG_RL78_G10
:
4206 out
= stpcpy (out
, ", G10");
4208 case E_FLAG_RL78_G13
:
4209 out
= stpcpy (out
, ", G13");
4211 case E_FLAG_RL78_G14
:
4212 out
= stpcpy (out
, ", G14");
4215 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
4216 out
= stpcpy (out
, ", 64-bit doubles");
4221 decode_RX_machine_flags (char *out
, unsigned e_flags
)
4223 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
4224 out
= stpcpy (out
, ", 64-bit doubles");
4225 if (e_flags
& E_FLAG_RX_DSP
)
4226 out
= stpcpy (out
, ", dsp");
4227 if (e_flags
& E_FLAG_RX_PID
)
4228 out
= stpcpy (out
, ", pid");
4229 if (e_flags
& E_FLAG_RX_ABI
)
4230 out
= stpcpy (out
, ", RX ABI");
4231 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
4232 out
= stpcpy (out
, (e_flags
& E_FLAG_RX_SINSNS_YES
4233 ? ", uses String instructions"
4234 : ", bans String instructions"));
4235 if (e_flags
& E_FLAG_RX_V2
)
4236 out
= stpcpy (out
, ", V2");
4237 if (e_flags
& E_FLAG_RX_V3
)
4238 out
= stpcpy (out
, ", V3");
4243 decode_SH_machine_flags (char *out
, unsigned e_flags
)
4245 switch ((e_flags
& EF_SH_MACH_MASK
))
4248 out
= stpcpy (out
, ", sh1");
4251 out
= stpcpy (out
, ", sh2");
4254 out
= stpcpy (out
, ", sh3");
4257 out
= stpcpy (out
, ", sh-dsp");
4260 out
= stpcpy (out
, ", sh3-dsp");
4263 out
= stpcpy (out
, ", sh4al-dsp");
4266 out
= stpcpy (out
, ", sh3e");
4269 out
= stpcpy (out
, ", sh4");
4272 out
= stpcpy (out
, ", sh5");
4275 out
= stpcpy (out
, ", sh2e");
4278 out
= stpcpy (out
, ", sh4a");
4281 out
= stpcpy (out
, ", sh2a");
4284 out
= stpcpy (out
, ", sh4-nofpu");
4287 out
= stpcpy (out
, ", sh4a-nofpu");
4290 out
= stpcpy (out
, ", sh2a-nofpu");
4293 out
= stpcpy (out
, ", sh3-nommu");
4295 case EF_SH4_NOMMU_NOFPU
:
4296 out
= stpcpy (out
, ", sh4-nommu-nofpu");
4298 case EF_SH2A_SH4_NOFPU
:
4299 out
= stpcpy (out
, ", sh2a-nofpu-or-sh4-nommu-nofpu");
4301 case EF_SH2A_SH3_NOFPU
:
4302 out
= stpcpy (out
, ", sh2a-nofpu-or-sh3-nommu");
4305 out
= stpcpy (out
, ", sh2a-or-sh4");
4308 out
= stpcpy (out
, ", sh2a-or-sh3e");
4311 out
= stpcpy (out
, _(", unknown ISA"));
4315 if (e_flags
& EF_SH_PIC
)
4316 out
= stpcpy (out
, ", pic");
4318 if (e_flags
& EF_SH_FDPIC
)
4319 out
= stpcpy (out
, ", fdpic");
4324 decode_SPARC_machine_flags (char *out
, unsigned e_flags
)
4326 if (e_flags
& EF_SPARC_32PLUS
)
4327 out
= stpcpy (out
, ", v8+");
4329 if (e_flags
& EF_SPARC_SUN_US1
)
4330 out
= stpcpy (out
, ", ultrasparcI");
4332 if (e_flags
& EF_SPARC_SUN_US3
)
4333 out
= stpcpy (out
, ", ultrasparcIII");
4335 if (e_flags
& EF_SPARC_HAL_R1
)
4336 out
= stpcpy (out
, ", halr1");
4338 if (e_flags
& EF_SPARC_LEDATA
)
4339 out
= stpcpy (out
, ", ledata");
4341 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
4342 out
= stpcpy (out
, ", tso");
4344 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
4345 out
= stpcpy (out
, ", pso");
4347 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
4348 out
= stpcpy (out
, ", rmo");
4353 decode_V800_machine_flags (char *out
, unsigned int e_flags
)
4355 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
4356 out
= stpcpy (out
, ", RH850 ABI");
4358 if (e_flags
& EF_V800_850E3
)
4359 out
= stpcpy (out
, ", V3 architecture");
4361 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
4362 out
= stpcpy (out
, ", FPU not used");
4364 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
4365 out
= stpcpy (out
, ", regmode: COMMON");
4367 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
4368 out
= stpcpy (out
, ", r4 not used");
4370 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
4371 out
= stpcpy (out
, ", r30 not used");
4373 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
4374 out
= stpcpy (out
, ", r5 not used");
4376 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
4377 out
= stpcpy (out
, ", r2 not used");
4379 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
4381 switch (e_flags
& - e_flags
)
4383 case EF_RH850_FPU_DOUBLE
:
4384 out
= stpcpy (out
, ", double precision FPU");
4386 case EF_RH850_FPU_SINGLE
:
4387 out
= stpcpy (out
, ", single precision FPU");
4389 case EF_RH850_REGMODE22
:
4390 out
= stpcpy (out
, ", regmode:22");
4392 case EF_RH850_REGMODE32
:
4393 out
= stpcpy (out
, ", regmode:23");
4395 case EF_RH850_GP_FIX
:
4396 out
= stpcpy (out
, ", r4 fixed");
4398 case EF_RH850_GP_NOFIX
:
4399 out
= stpcpy (out
, ", r4 free");
4401 case EF_RH850_EP_FIX
:
4402 out
= stpcpy (out
, ", r30 fixed");
4404 case EF_RH850_EP_NOFIX
:
4405 out
= stpcpy (out
, ", r30 free");
4407 case EF_RH850_TP_FIX
:
4408 out
= stpcpy (out
, ", r5 fixed");
4410 case EF_RH850_TP_NOFIX
:
4411 out
= stpcpy (out
, ", r5 free");
4413 case EF_RH850_REG2_RESERVE
:
4414 out
= stpcpy (out
, ", r2 fixed");
4416 case EF_RH850_REG2_NORESERVE
:
4417 out
= stpcpy (out
, ", r2 free");
4427 decode_V850_machine_flags (char *out
, unsigned int e_flags
)
4429 switch (e_flags
& EF_V850_ARCH
)
4431 case E_V850E3V5_ARCH
:
4432 out
= stpcpy (out
, ", v850e3v5");
4434 case E_V850E2V3_ARCH
:
4435 out
= stpcpy (out
, ", v850e2v3");
4438 out
= stpcpy (out
, ", v850e2");
4441 out
= stpcpy (out
, ", v850e1");
4444 out
= stpcpy (out
, ", v850e");
4447 out
= stpcpy (out
, ", v850");
4450 out
= stpcpy (out
, _(", unknown v850 architecture variant"));
4457 decode_Z80_machine_flags (char *out
, unsigned int e_flags
)
4459 switch (e_flags
& EF_Z80_MACH_MSK
)
4461 case EF_Z80_MACH_Z80
:
4462 out
= stpcpy (out
, ", Z80");
4464 case EF_Z80_MACH_Z180
:
4465 out
= stpcpy (out
, ", Z180");
4467 case EF_Z80_MACH_R800
:
4468 out
= stpcpy (out
, ", R800");
4470 case EF_Z80_MACH_EZ80_Z80
:
4471 out
= stpcpy (out
, ", EZ80");
4473 case EF_Z80_MACH_EZ80_ADL
:
4474 out
= stpcpy (out
, ", EZ80, ADL");
4476 case EF_Z80_MACH_GBZ80
:
4477 out
= stpcpy (out
, ", GBZ80");
4479 case EF_Z80_MACH_Z80N
:
4480 out
= stpcpy (out
, ", Z80N");
4483 out
= stpcpy (out
, _(", unknown"));
4490 decode_AMDGPU_machine_flags (char *out
, unsigned int e_flags
, Filedata
*filedata
)
4492 unsigned char *e_ident
= filedata
->file_header
.e_ident
;
4493 unsigned char osabi
= e_ident
[EI_OSABI
];
4494 unsigned char abiversion
= e_ident
[EI_ABIVERSION
];
4497 /* HSA OS ABI v2 used a different encoding, but we don't need to support it,
4498 it has been deprecated for a while.
4500 The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time
4501 of writing, they use the same flags as HSA v3, so the code below uses that
4503 if (osabi
== ELFOSABI_AMDGPU_HSA
&& abiversion
< ELFABIVERSION_AMDGPU_HSA_V3
)
4506 mach
= e_flags
& EF_AMDGPU_MACH
;
4509 #define AMDGPU_CASE(code, string) \
4510 case code: out = stpcpy (out, ", " string); break;
4511 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600
, "gfx600")
4512 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601
, "gfx601")
4513 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700
, "gfx700")
4514 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701
, "gfx701")
4515 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702
, "gfx702")
4516 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703
, "gfx703")
4517 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704
, "gfx704")
4518 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801
, "gfx801")
4519 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802
, "gfx802")
4520 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803
, "gfx803")
4521 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810
, "gfx810")
4522 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900
, "gfx900")
4523 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902
, "gfx902")
4524 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904
, "gfx904")
4525 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906
, "gfx906")
4526 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908
, "gfx908")
4527 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909
, "gfx909")
4528 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C
, "gfx90c")
4529 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010
, "gfx1010")
4530 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011
, "gfx1011")
4531 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012
, "gfx1012")
4532 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030
, "gfx1030")
4533 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031
, "gfx1031")
4534 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032
, "gfx1032")
4535 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033
, "gfx1033")
4536 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602
, "gfx602")
4537 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705
, "gfx705")
4538 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805
, "gfx805")
4539 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035
, "gfx1035")
4540 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034
, "gfx1034")
4541 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A
, "gfx90a")
4542 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940
, "gfx940")
4543 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013
, "gfx1013")
4544 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036
, "gfx1036")
4546 out
+= sprintf (out
, _(", <unknown AMDGPU GPU type: %#x>"), mach
);
4551 e_flags
&= ~EF_AMDGPU_MACH
;
4553 if ((osabi
== ELFOSABI_AMDGPU_HSA
4554 && abiversion
== ELFABIVERSION_AMDGPU_HSA_V3
)
4555 || osabi
!= ELFOSABI_AMDGPU_HSA
)
4557 /* For HSA v3 and other OS ABIs. */
4558 if (e_flags
& EF_AMDGPU_FEATURE_XNACK_V3
)
4560 out
= stpcpy (out
, ", xnack on");
4561 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V3
;
4564 if (e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V3
)
4566 out
= stpcpy (out
, ", sramecc on");
4567 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V3
;
4575 xnack
= e_flags
& EF_AMDGPU_FEATURE_XNACK_V4
;
4578 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
:
4581 case EF_AMDGPU_FEATURE_XNACK_ANY_V4
:
4582 out
= stpcpy (out
, ", xnack any");
4585 case EF_AMDGPU_FEATURE_XNACK_OFF_V4
:
4586 out
= stpcpy (out
, ", xnack off");
4589 case EF_AMDGPU_FEATURE_XNACK_ON_V4
:
4590 out
= stpcpy (out
, ", xnack on");
4594 out
+= sprintf (out
, _(", <unknown xnack value: %#x>"), xnack
);
4598 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V4
;
4600 sramecc
= e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V4
;
4603 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
:
4606 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
:
4607 out
= stpcpy (out
, ", sramecc any");
4610 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
:
4611 out
= stpcpy (out
, ", sramecc off");
4614 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4
:
4615 out
= stpcpy (out
, ", sramecc on");
4619 out
+= sprintf (out
, _(", <unknown sramecc value: %#x>"), sramecc
);
4623 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V4
;
4627 out
+= sprintf (out
, _(", unknown flags bits: %#x"), e_flags
);
4632 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
4634 static char buf
[1024];
4646 case EM_ARC_COMPACT3
:
4647 out
= stpcpy (out
, ", HS5x");
4650 case EM_ARC_COMPACT3_64
:
4651 out
= stpcpy (out
, ", HS6x");
4654 case EM_ARC_COMPACT2
:
4655 case EM_ARC_COMPACT
:
4656 out
= decode_ARC_machine_flags (out
, e_flags
, e_machine
);
4660 out
= decode_ARM_machine_flags (out
, e_flags
);
4664 out
= decode_AVR_machine_flags (out
, e_flags
);
4668 out
= decode_BLACKFIN_machine_flags (out
, e_flags
);
4672 out
= decode_FRV_machine_flags (out
, e_flags
);
4676 out
= decode_M68K_machine_flags (out
, e_flags
);
4680 out
= decode_AMDGPU_machine_flags (out
, e_flags
, filedata
);
4684 out
= decode_MeP_machine_flags (out
, e_flags
);
4688 if (e_flags
& EF_PPC_EMB
)
4689 out
= stpcpy (out
, ", emb");
4691 if (e_flags
& EF_PPC_RELOCATABLE
)
4692 out
= stpcpy (out
, _(", relocatable"));
4694 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
4695 out
= stpcpy (out
, _(", relocatable-lib"));
4699 if (e_flags
& EF_PPC64_ABI
)
4700 out
+= sprintf (out
, ", abiv%d", e_flags
& EF_PPC64_ABI
);
4704 out
= decode_V800_machine_flags (out
, e_flags
);
4708 case EM_CYGNUS_V850
:
4709 out
= decode_V850_machine_flags (out
, e_flags
);
4713 case EM_CYGNUS_M32R
:
4714 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
4715 out
= stpcpy (out
, ", m32r");
4719 case EM_MIPS_RS3_LE
:
4720 out
= decode_MIPS_machine_flags (out
, e_flags
);
4724 out
= decode_NDS32_machine_flags (out
, e_flags
);
4728 switch (EF_NFP_MACH (e_flags
))
4730 case E_NFP_MACH_3200
:
4731 out
= stpcpy (out
, ", NFP-32xx");
4733 case E_NFP_MACH_6000
:
4734 out
= stpcpy (out
, ", NFP-6xxx");
4740 out
= decode_RISCV_machine_flags (out
, e_flags
);
4744 out
= decode_SH_machine_flags (out
, e_flags
);
4748 if (e_flags
& EF_OR1K_NODELAY
)
4749 out
= stpcpy (out
, ", no delay");
4753 out
+= sprintf (out
, ", CPU Version: %u", e_flags
& EF_BPF_CPUVER
);
4757 out
= decode_SPARC_machine_flags (out
, e_flags
);
4761 out
= decode_PARISC_machine_flags (out
, e_flags
);
4766 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
4767 out
= stpcpy (out
, ", new calling convention");
4769 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
4770 out
= stpcpy (out
, ", gnu calling convention");
4774 out
= decode_IA64_machine_flags (out
, e_flags
, filedata
);
4778 if ((e_flags
& EF_VAX_NONPIC
))
4779 out
= stpcpy (out
, ", non-PIC");
4780 if ((e_flags
& EF_VAX_DFLOAT
))
4781 out
= stpcpy (out
, ", D-Float");
4782 if ((e_flags
& EF_VAX_GFLOAT
))
4783 out
= stpcpy (out
, ", G-Float");
4787 if (e_flags
& EF_VISIUM_ARCH_MCM
)
4788 out
= stpcpy (out
, ", mcm");
4789 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
4790 out
= stpcpy (out
, ", mcm24");
4791 if (e_flags
& EF_VISIUM_ARCH_GR6
)
4792 out
= stpcpy (out
, ", gr6");
4796 out
= decode_RL78_machine_flags (out
, e_flags
);
4800 out
= decode_RX_machine_flags (out
, e_flags
);
4804 if (e_flags
& EF_S390_HIGH_GPRS
)
4805 out
= stpcpy (out
, ", highgprs");
4809 if ((e_flags
& EF_C6000_REL
))
4810 out
= stpcpy (out
, ", relocatable module");
4814 if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV3_1
)
4815 strcat (buf
, ", Kalray VLIW kv3-1");
4816 else if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV3_2
)
4817 strcat (buf
, ", Kalray VLIW kv3-2");
4818 else if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV4_1
)
4819 strcat (buf
, ", Kalray VLIW kv4-1");
4821 strcat (buf
, ", unknown KVX MPPA");
4825 out
= decode_MSP430_machine_flags (out
, e_flags
);
4829 out
= decode_Z80_machine_flags (out
, e_flags
);
4833 out
= decode_LOONGARCH_machine_flags (out
, e_flags
);
4842 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
4844 static char buff
[32];
4848 case ELFOSABI_NONE
: return "UNIX - System V";
4849 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
4850 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
4851 case ELFOSABI_GNU
: return "UNIX - GNU";
4852 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
4853 case ELFOSABI_AIX
: return "UNIX - AIX";
4854 case ELFOSABI_IRIX
: return "UNIX - IRIX";
4855 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
4856 case ELFOSABI_TRU64
: return "UNIX - TRU64";
4857 case ELFOSABI_MODESTO
: return "Novell - Modesto";
4858 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
4859 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
4860 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
4861 case ELFOSABI_AROS
: return "AROS";
4862 case ELFOSABI_FENIXOS
: return "FenixOS";
4863 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
4864 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
4867 switch (filedata
->file_header
.e_machine
)
4872 case ELFOSABI_AMDGPU_HSA
: return "AMD HSA";
4873 case ELFOSABI_AMDGPU_PAL
: return "AMD PAL";
4874 case ELFOSABI_AMDGPU_MESA3D
: return "AMD Mesa3D";
4883 case ELFOSABI_ARM
: return "ARM";
4884 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
4895 case ELFOSABI_STANDALONE
: return _("Standalone App");
4904 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
4905 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
4914 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
4920 get_aarch64_segment_type (unsigned long type
)
4924 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
4925 case PT_AARCH64_MEMTAG_MTE
: return "AARCH64_MEMTAG_MTE";
4926 default: return NULL
;
4931 get_arm_segment_type (unsigned long type
)
4935 case PT_ARM_EXIDX
: return "EXIDX";
4936 default: return NULL
;
4941 get_s390_segment_type (unsigned long type
)
4945 case PT_S390_PGSTE
: return "S390_PGSTE";
4946 default: return NULL
;
4951 get_mips_segment_type (unsigned long type
)
4955 case PT_MIPS_REGINFO
: return "REGINFO";
4956 case PT_MIPS_RTPROC
: return "RTPROC";
4957 case PT_MIPS_OPTIONS
: return "OPTIONS";
4958 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
4959 default: return NULL
;
4964 get_parisc_segment_type (unsigned long type
)
4968 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
4969 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
4970 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
4971 default: return NULL
;
4976 get_ia64_segment_type (unsigned long type
)
4980 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
4981 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
4982 default: return NULL
;
4987 get_tic6x_segment_type (unsigned long type
)
4991 case PT_C6000_PHATTR
: return "C6000_PHATTR";
4992 default: return NULL
;
4997 get_riscv_segment_type (unsigned long type
)
5001 case PT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
5002 default: return NULL
;
5007 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
5009 if (e_machine
== EM_PARISC
)
5012 case PT_HP_TLS
: return "HP_TLS";
5013 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
5014 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
5015 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
5016 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
5017 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
5018 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
5019 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
5020 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
5021 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
5022 case PT_HP_PARALLEL
: return "HP_PARALLEL";
5023 case PT_HP_FASTBIND
: return "HP_FASTBIND";
5024 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
5025 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
5026 case PT_HP_STACK
: return "HP_STACK";
5027 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
5028 default: return NULL
;
5031 if (e_machine
== EM_IA_64
)
5034 case PT_HP_TLS
: return "HP_TLS";
5035 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
5036 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
5037 case PT_IA_64_HP_STACK
: return "HP_STACK";
5038 default: return NULL
;
5045 get_solaris_segment_type (unsigned long type
)
5049 case 0x6464e550: return "PT_SUNW_UNWIND";
5050 case 0x6474e550: return "PT_SUNW_EH_FRAME";
5051 case 0x6ffffff7: return "PT_LOSUNW";
5052 case 0x6ffffffa: return "PT_SUNWBSS";
5053 case 0x6ffffffb: return "PT_SUNWSTACK";
5054 case 0x6ffffffc: return "PT_SUNWDTRACE";
5055 case 0x6ffffffd: return "PT_SUNWCAP";
5056 case 0x6fffffff: return "PT_HISUNW";
5057 default: return NULL
;
5062 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
5064 static char buff
[32];
5068 case PT_NULL
: return "NULL";
5069 case PT_LOAD
: return "LOAD";
5070 case PT_DYNAMIC
: return "DYNAMIC";
5071 case PT_INTERP
: return "INTERP";
5072 case PT_NOTE
: return "NOTE";
5073 case PT_SHLIB
: return "SHLIB";
5074 case PT_PHDR
: return "PHDR";
5075 case PT_TLS
: return "TLS";
5076 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
5077 case PT_GNU_STACK
: return "GNU_STACK";
5078 case PT_GNU_RELRO
: return "GNU_RELRO";
5079 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
5080 case PT_GNU_SFRAME
: return "GNU_SFRAME";
5082 case PT_OPENBSD_MUTABLE
: return "OPENBSD_MUTABLE";
5083 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
5084 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
5085 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
5088 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
5090 const char * result
;
5092 switch (filedata
->file_header
.e_machine
)
5095 result
= get_aarch64_segment_type (p_type
);
5098 result
= get_arm_segment_type (p_type
);
5101 case EM_MIPS_RS3_LE
:
5102 result
= get_mips_segment_type (p_type
);
5105 result
= get_parisc_segment_type (p_type
);
5108 result
= get_ia64_segment_type (p_type
);
5111 result
= get_tic6x_segment_type (p_type
);
5115 result
= get_s390_segment_type (p_type
);
5118 result
= get_riscv_segment_type (p_type
);
5128 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
5130 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
5132 const char * result
= NULL
;
5134 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
5137 case ELFOSABI_FREEBSD
:
5138 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
5140 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
5145 result
= get_hpux_segment_type (p_type
,
5146 filedata
->file_header
.e_machine
);
5148 case ELFOSABI_SOLARIS
:
5149 result
= get_solaris_segment_type (p_type
);
5157 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
5160 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
5167 get_arc_section_type_name (unsigned int sh_type
)
5171 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
5179 get_mips_section_type_name (unsigned int sh_type
)
5183 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
5184 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
5185 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
5186 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
5187 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
5188 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
5189 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
5190 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
5191 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
5192 case SHT_MIPS_RELD
: return "MIPS_RELD";
5193 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
5194 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
5195 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
5196 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
5197 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
5198 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
5199 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
5200 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
5201 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
5202 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
5203 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
5204 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
5205 case SHT_MIPS_LINE
: return "MIPS_LINE";
5206 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
5207 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
5208 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
5209 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
5210 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
5211 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
5212 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
5213 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
5214 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
5215 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
5216 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
5217 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
5218 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
5219 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
5220 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
5221 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
5222 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
5223 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
5231 get_parisc_section_type_name (unsigned int sh_type
)
5235 case SHT_PARISC_EXT
: return "PARISC_EXT";
5236 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
5237 case SHT_PARISC_DOC
: return "PARISC_DOC";
5238 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
5239 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
5240 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
5241 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
5242 default: return NULL
;
5247 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
5249 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
5250 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
5251 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
5255 case SHT_IA_64_EXT
: return "IA_64_EXT";
5256 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
5257 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
5258 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
5259 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
5260 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
5261 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
5262 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
5263 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
5264 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
5272 get_x86_64_section_type_name (unsigned int sh_type
)
5276 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
5277 default: return NULL
;
5282 get_aarch64_section_type_name (unsigned int sh_type
)
5286 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
5287 default: return NULL
;
5292 get_arm_section_type_name (unsigned int sh_type
)
5296 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
5297 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
5298 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
5299 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
5300 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
5301 default: return NULL
;
5306 get_tic6x_section_type_name (unsigned int sh_type
)
5310 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
5311 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
5312 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
5313 case SHT_TI_ICODE
: return "TI_ICODE";
5314 case SHT_TI_XREF
: return "TI_XREF";
5315 case SHT_TI_HANDLER
: return "TI_HANDLER";
5316 case SHT_TI_INITINFO
: return "TI_INITINFO";
5317 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
5318 default: return NULL
;
5323 get_msp430_section_type_name (unsigned int sh_type
)
5327 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
5328 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
5329 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
5330 default: return NULL
;
5335 get_nfp_section_type_name (unsigned int sh_type
)
5339 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
5340 case SHT_NFP_INITREG
: return "NFP_INITREG";
5341 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
5342 default: return NULL
;
5347 get_v850_section_type_name (unsigned int sh_type
)
5351 case SHT_V850_SCOMMON
: return "V850 Small Common";
5352 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
5353 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
5354 case SHT_RENESAS_IOP
: return "RENESAS IOP";
5355 case SHT_RENESAS_INFO
: return "RENESAS INFO";
5356 default: return NULL
;
5361 get_riscv_section_type_name (unsigned int sh_type
)
5365 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
5366 default: return NULL
;
5371 get_csky_section_type_name (unsigned int sh_type
)
5375 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
5376 default: return NULL
;
5381 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
5383 static char buff
[32];
5384 const char * result
;
5388 case SHT_NULL
: return "NULL";
5389 case SHT_PROGBITS
: return "PROGBITS";
5390 case SHT_SYMTAB
: return "SYMTAB";
5391 case SHT_STRTAB
: return "STRTAB";
5392 case SHT_RELA
: return "RELA";
5393 case SHT_RELR
: return "RELR";
5394 case SHT_HASH
: return "HASH";
5395 case SHT_DYNAMIC
: return "DYNAMIC";
5396 case SHT_NOTE
: return "NOTE";
5397 case SHT_NOBITS
: return "NOBITS";
5398 case SHT_REL
: return "REL";
5399 case SHT_SHLIB
: return "SHLIB";
5400 case SHT_DYNSYM
: return "DYNSYM";
5401 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
5402 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
5403 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
5404 case SHT_GNU_HASH
: return "GNU_HASH";
5405 case SHT_GROUP
: return "GROUP";
5406 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
5407 case SHT_GNU_verdef
: return "VERDEF";
5408 case SHT_GNU_verneed
: return "VERNEED";
5409 case SHT_GNU_versym
: return "VERSYM";
5410 case 0x6ffffff0: return "VERSYM";
5411 case 0x6ffffffc: return "VERDEF";
5412 case 0x7ffffffd: return "AUXILIARY";
5413 case 0x7fffffff: return "FILTER";
5414 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
5417 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
5419 switch (filedata
->file_header
.e_machine
)
5422 case EM_ARC_COMPACT
:
5423 case EM_ARC_COMPACT2
:
5424 case EM_ARC_COMPACT3
:
5425 case EM_ARC_COMPACT3_64
:
5426 result
= get_arc_section_type_name (sh_type
);
5429 case EM_MIPS_RS3_LE
:
5430 result
= get_mips_section_type_name (sh_type
);
5433 result
= get_parisc_section_type_name (sh_type
);
5436 result
= get_ia64_section_type_name (filedata
, sh_type
);
5441 result
= get_x86_64_section_type_name (sh_type
);
5444 result
= get_aarch64_section_type_name (sh_type
);
5447 result
= get_arm_section_type_name (sh_type
);
5450 result
= get_tic6x_section_type_name (sh_type
);
5453 result
= get_msp430_section_type_name (sh_type
);
5456 result
= get_nfp_section_type_name (sh_type
);
5460 case EM_CYGNUS_V850
:
5461 result
= get_v850_section_type_name (sh_type
);
5464 result
= get_riscv_section_type_name (sh_type
);
5467 result
= get_csky_section_type_name (sh_type
);
5477 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
5479 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
5481 switch (filedata
->file_header
.e_machine
)
5484 result
= get_ia64_section_type_name (filedata
, sh_type
);
5487 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
5488 result
= get_solaris_section_type (sh_type
);
5493 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
5494 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
5495 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
5496 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
5508 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
5510 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
5512 switch (filedata
->file_header
.e_machine
)
5516 case EM_CYGNUS_V850
:
5517 result
= get_v850_section_type_name (sh_type
);
5527 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
5530 /* This message is probably going to be displayed in a 15
5531 character wide field, so put the hex value first. */
5532 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
5538 enum long_option_values
5540 OPTION_DEBUG_DUMP
= 512,
5551 OPTION_WITH_SYMBOL_VERSIONS
,
5552 OPTION_RECURSE_LIMIT
,
5553 OPTION_NO_RECURSE_LIMIT
,
5554 OPTION_NO_DEMANGLING
,
5555 OPTION_NO_EXTRA_SYM_INFO
,
5559 static struct option options
[] =
5561 /* Note - This table is alpha-sorted on the 'val'
5562 field in order to make adding new options easier. */
5563 {"arch-specific", no_argument
, 0, 'A'},
5564 {"all", no_argument
, 0, 'a'},
5565 {"demangle", optional_argument
, 0, 'C'},
5566 {"archive-index", no_argument
, 0, 'c'},
5567 {"use-dynamic", no_argument
, 0, 'D'},
5568 {"dynamic", no_argument
, 0, 'd'},
5569 {"headers", no_argument
, 0, 'e'},
5570 {"section-groups", no_argument
, 0, 'g'},
5571 {"help", no_argument
, 0, 'H'},
5572 {"file-header", no_argument
, 0, 'h'},
5573 {"histogram", no_argument
, 0, 'I'},
5574 {"lint", no_argument
, 0, 'L'},
5575 {"enable-checks", no_argument
, 0, 'L'},
5576 {"program-headers", no_argument
, 0, 'l'},
5577 {"segments", no_argument
, 0, 'l'},
5578 {"full-section-name",no_argument
, 0, 'N'},
5579 {"notes", no_argument
, 0, 'n'},
5580 {"process-links", no_argument
, 0, 'P'},
5581 {"string-dump", required_argument
, 0, 'p'},
5582 {"relocated-dump", required_argument
, 0, 'R'},
5583 {"relocs", no_argument
, 0, 'r'},
5584 {"section-headers", no_argument
, 0, 'S'},
5585 {"sections", no_argument
, 0, 'S'},
5586 {"symbols", no_argument
, 0, 's'},
5587 {"syms", no_argument
, 0, 's'},
5588 {"silent-truncation",no_argument
, 0, 'T'},
5589 {"section-details", no_argument
, 0, 't'},
5590 {"unicode", required_argument
, NULL
, 'U'},
5591 {"unwind", no_argument
, 0, 'u'},
5592 {"version-info", no_argument
, 0, 'V'},
5593 {"version", no_argument
, 0, 'v'},
5594 {"wide", no_argument
, 0, 'W'},
5595 {"extra-sym-info", no_argument
, 0, 'X'},
5596 {"hex-dump", required_argument
, 0, 'x'},
5597 {"decompress", no_argument
, 0, 'z'},
5599 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
5600 {"no-extra-sym-info",no_argument
, 0, OPTION_NO_EXTRA_SYM_INFO
},
5601 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
5602 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5603 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5604 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
5605 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
5606 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
5607 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
5608 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
5609 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
5610 #ifdef ENABLE_LIBCTF
5611 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
5612 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
5613 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
5614 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
5616 {"sframe", optional_argument
, 0, OPTION_SFRAME_DUMP
},
5617 {"sym-base", optional_argument
, 0, OPTION_SYM_BASE
},
5619 {0, no_argument
, 0, 0}
5623 usage (FILE * stream
)
5625 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
5626 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
5627 fprintf (stream
, _(" Options are:\n"));
5628 fprintf (stream
, _("\
5629 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
5630 fprintf (stream
, _("\
5631 -h --file-header Display the ELF file header\n"));
5632 fprintf (stream
, _("\
5633 -l --program-headers Display the program headers\n"));
5634 fprintf (stream
, _("\
5635 --segments An alias for --program-headers\n"));
5636 fprintf (stream
, _("\
5637 -S --section-headers Display the sections' header\n"));
5638 fprintf (stream
, _("\
5639 --sections An alias for --section-headers\n"));
5640 fprintf (stream
, _("\
5641 -g --section-groups Display the section groups\n"));
5642 fprintf (stream
, _("\
5643 -t --section-details Display the section details\n"));
5644 fprintf (stream
, _("\
5645 -e --headers Equivalent to: -h -l -S\n"));
5646 fprintf (stream
, _("\
5647 -s --syms Display the symbol table\n"));
5648 fprintf (stream
, _("\
5649 --symbols An alias for --syms\n"));
5650 fprintf (stream
, _("\
5651 --dyn-syms Display the dynamic symbol table\n"));
5652 fprintf (stream
, _("\
5653 --lto-syms Display LTO symbol tables\n"));
5654 fprintf (stream
, _("\
5655 --sym-base=[0|8|10|16] \n\
5656 Force base for symbol sizes. The options are \n\
5657 mixed (the default), octal, decimal, hexadecimal.\n"));
5658 fprintf (stream
, _("\
5659 -C --demangle[=STYLE] Decode mangled/processed symbol names\n"));
5660 display_demangler_styles (stream
, _("\
5662 fprintf (stream
, _("\
5663 --no-demangle Do not demangle low-level symbol names. (default)\n"));
5664 fprintf (stream
, _("\
5665 --recurse-limit Enable a demangling recursion limit. (default)\n"));
5666 fprintf (stream
, _("\
5667 --no-recurse-limit Disable a demangling recursion limit\n"));
5668 fprintf (stream
, _("\
5669 -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\
5670 Display unicode characters as determined by the current locale\n\
5671 (default), escape sequences, \"<hex sequences>\", highlighted\n\
5672 escape sequences, or treat them as invalid and display as\n\
5673 \"{hex sequences}\"\n"));
5674 fprintf (stream
, _("\
5675 -X --extra-sym-info Display extra information when showing symbols\n"));
5676 fprintf (stream
, _("\
5677 --no-extra-sym-info Do not display extra information when showing symbols (default)\n"));
5678 fprintf (stream
, _("\
5679 -n --notes Display the contents of note sections (if present)\n"));
5680 fprintf (stream
, _("\
5681 -r --relocs Display the relocations (if present)\n"));
5682 fprintf (stream
, _("\
5683 -u --unwind Display the unwind info (if present)\n"));
5684 fprintf (stream
, _("\
5685 -d --dynamic Display the dynamic section (if present)\n"));
5686 fprintf (stream
, _("\
5687 -V --version-info Display the version sections (if present)\n"));
5688 fprintf (stream
, _("\
5689 -A --arch-specific Display architecture specific information (if any)\n"));
5690 fprintf (stream
, _("\
5691 -c --archive-index Display the symbol/file index in an archive\n"));
5692 fprintf (stream
, _("\
5693 -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
5694 fprintf (stream
, _("\
5695 -L --lint|--enable-checks\n\
5696 Display warning messages for possible problems\n"));
5697 fprintf (stream
, _("\
5698 -x --hex-dump=<number|name>\n\
5699 Dump the contents of section <number|name> as bytes\n"));
5700 fprintf (stream
, _("\
5701 -p --string-dump=<number|name>\n\
5702 Dump the contents of section <number|name> as strings\n"));
5703 fprintf (stream
, _("\
5704 -R --relocated-dump=<number|name>\n\
5705 Dump the relocated contents of section <number|name>\n"));
5706 fprintf (stream
, _("\
5707 -z --decompress Decompress section before dumping it\n"));
5708 fprintf (stream
, _("\
5709 -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
5710 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
5711 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
5712 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
5714 Display the contents of DWARF debug sections\n"));
5715 fprintf (stream
, _("\
5716 -wk --debug-dump=links Display the contents of sections that link to separate\n\
5717 debuginfo files\n"));
5718 fprintf (stream
, _("\
5719 -P --process-links Display the contents of non-debug sections in separate\n\
5720 debuginfo files. (Implies -wK)\n"));
5721 #if DEFAULT_FOR_FOLLOW_LINKS
5722 fprintf (stream
, _("\
5723 -wK --debug-dump=follow-links\n\
5724 Follow links to separate debug info files (default)\n"));
5725 fprintf (stream
, _("\
5726 -wN --debug-dump=no-follow-links\n\
5727 Do not follow links to separate debug info files\n"));
5729 fprintf (stream
, _("\
5730 -wK --debug-dump=follow-links\n\
5731 Follow links to separate debug info files\n"));
5732 fprintf (stream
, _("\
5733 -wN --debug-dump=no-follow-links\n\
5734 Do not follow links to separate debug info files\n\
5737 #if HAVE_LIBDEBUGINFOD
5738 fprintf (stream
, _("\
5739 -wD --debug-dump=use-debuginfod\n\
5740 When following links, also query debuginfod servers (default)\n"));
5741 fprintf (stream
, _("\
5742 -wE --debug-dump=do-not-use-debuginfod\n\
5743 When following links, do not query debuginfod servers\n"));
5745 fprintf (stream
, _("\
5746 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
5747 fprintf (stream
, _("\
5748 --dwarf-start=N Display DIEs starting at offset N\n"));
5749 #ifdef ENABLE_LIBCTF
5750 fprintf (stream
, _("\
5751 --ctf=<number|name> Display CTF info from section <number|name>\n"));
5752 fprintf (stream
, _("\
5753 --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
5754 fprintf (stream
, _("\
5755 --ctf-symbols=<number|name>\n\
5756 Use section <number|name> as the CTF external symtab\n"));
5757 fprintf (stream
, _("\
5758 --ctf-strings=<number|name>\n\
5759 Use section <number|name> as the CTF external strtab\n"));
5761 fprintf (stream
, _("\
5762 --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n"));
5764 #ifdef SUPPORT_DISASSEMBLY
5765 fprintf (stream
, _("\
5766 -i --instruction-dump=<number|name>\n\
5767 Disassemble the contents of section <number|name>\n"));
5769 fprintf (stream
, _("\
5770 -I --histogram Display histogram of bucket list lengths\n"));
5771 fprintf (stream
, _("\
5772 -W --wide Allow output width to exceed 80 characters\n"));
5773 fprintf (stream
, _("\
5774 -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
5775 fprintf (stream
, _("\
5776 @<file> Read options from <file>\n"));
5777 fprintf (stream
, _("\
5778 -H --help Display this information\n"));
5779 fprintf (stream
, _("\
5780 -v --version Display the version number of readelf\n"));
5782 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
5783 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
5785 exit (stream
== stdout
? 0 : 1);
5788 /* Record the fact that the user wants the contents of section number
5789 SECTION to be displayed using the method(s) encoded as flags bits
5790 in TYPE. Note, TYPE can be zero if we are creating the array for
5794 request_dump_bynumber (struct dump_data
*dumpdata
,
5795 unsigned int section
, dump_type type
)
5797 if (section
>= dumpdata
->num_dump_sects
)
5799 dump_type
* new_dump_sects
;
5801 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
5802 sizeof (* new_dump_sects
));
5804 if (new_dump_sects
== NULL
)
5805 error (_("Out of memory allocating dump request table.\n"));
5808 if (dumpdata
->dump_sects
)
5810 /* Copy current flag settings. */
5811 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
5812 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
5814 free (dumpdata
->dump_sects
);
5817 dumpdata
->dump_sects
= new_dump_sects
;
5818 dumpdata
->num_dump_sects
= section
+ 1;
5822 if (dumpdata
->dump_sects
)
5823 dumpdata
->dump_sects
[section
] |= type
;
5826 /* Request a dump by section name. */
5829 request_dump_byname (const char * section
, dump_type type
)
5831 struct dump_list_entry
* new_request
;
5833 new_request
= (struct dump_list_entry
*)
5834 malloc (sizeof (struct dump_list_entry
));
5836 error (_("Out of memory allocating dump request table.\n"));
5838 new_request
->name
= strdup (section
);
5839 if (!new_request
->name
)
5840 error (_("Out of memory allocating dump request table.\n"));
5842 new_request
->type
= type
;
5844 new_request
->next
= dump_sects_byname
;
5845 dump_sects_byname
= new_request
;
5849 request_dump (struct dump_data
*dumpdata
, dump_type type
)
5855 section
= strtoul (optarg
, & cp
, 0);
5857 if (! *cp
&& section
>= 0)
5858 request_dump_bynumber (dumpdata
, section
, type
);
5860 request_dump_byname (optarg
, type
);
5864 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
5871 while ((c
= getopt_long
5872 (argc
, argv
, "ACDHILNPR:STU:VWXacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
5890 do_section_groups
= true;
5893 do_histogram
= true;
5899 do_section_groups
= true;
5904 do_section_details
= true;
5915 do_using_dynamic
= true;
5939 do_histogram
= true;
5945 do_archive_index
= true;
5951 process_links
= true;
5952 do_follow_links
= true;
5953 dump_any_debugging
= true;
5956 request_dump (dumpdata
, HEX_DUMP
);
5959 request_dump (dumpdata
, STRING_DUMP
);
5962 request_dump (dumpdata
, RELOC_DUMP
);
5965 decompress_dumps
= true;
5970 do_debugging
= true;
5972 dump_any_debugging
= true;
5973 dwarf_select_sections_all ();
5977 do_debugging
= false;
5978 if (dwarf_select_sections_by_letters (optarg
))
5981 dump_any_debugging
= true;
5985 case OPTION_DEBUG_DUMP
:
5989 do_debugging
= true;
5990 dump_any_debugging
= true;
5991 dwarf_select_sections_all ();
5995 do_debugging
= false;
5996 if (dwarf_select_sections_by_names (optarg
))
5999 dump_any_debugging
= true;
6003 case OPTION_DWARF_DEPTH
:
6007 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
6010 case OPTION_DWARF_START
:
6014 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
6017 case OPTION_DWARF_CHECK
:
6020 case OPTION_CTF_DUMP
:
6022 request_dump (dumpdata
, CTF_DUMP
);
6024 case OPTION_CTF_SYMBOLS
:
6025 free (dump_ctf_symtab_name
);
6026 dump_ctf_symtab_name
= strdup (optarg
);
6028 case OPTION_CTF_STRINGS
:
6029 free (dump_ctf_strtab_name
);
6030 dump_ctf_strtab_name
= strdup (optarg
);
6032 case OPTION_CTF_PARENT
:
6033 free (dump_ctf_parent_name
);
6034 dump_ctf_parent_name
= strdup (optarg
);
6036 case OPTION_SFRAME_DUMP
:
6038 /* Providing section name is optional. request_dump (), however,
6039 thrives on non NULL optarg. Handle it explicitly here. */
6041 request_dump (dumpdata
, SFRAME_DUMP
);
6045 const char *sframe_sec_name
= strdup (".sframe");
6046 request_dump_byname (sframe_sec_name
, SFRAME_DUMP
);
6049 case OPTION_DYN_SYMS
:
6052 case OPTION_LTO_SYMS
:
6056 extra_sym_info
= true;
6058 case OPTION_NO_EXTRA_SYM_INFO
:
6059 extra_sym_info
= false;
6062 #ifdef SUPPORT_DISASSEMBLY
6064 request_dump (dumpdata
, DISASS_DUMP
);
6068 print_version (program_name
);
6077 do_not_show_symbol_truncation
= true;
6083 enum demangling_styles style
;
6085 style
= cplus_demangle_name_to_style (optarg
);
6086 if (style
== unknown_demangling
)
6087 error (_("unknown demangling style `%s'"), optarg
);
6089 cplus_demangle_set_style (style
);
6092 case OPTION_NO_DEMANGLING
:
6093 do_demangle
= false;
6095 case OPTION_RECURSE_LIMIT
:
6096 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
6098 case OPTION_NO_RECURSE_LIMIT
:
6099 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
6101 case OPTION_WITH_SYMBOL_VERSIONS
:
6102 /* Ignored for backward compatibility. */
6107 error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
6108 else if (streq (optarg
, "default") || streq (optarg
, "d"))
6109 unicode_display
= unicode_default
;
6110 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
6111 unicode_display
= unicode_locale
;
6112 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
6113 unicode_display
= unicode_escape
;
6114 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
6115 unicode_display
= unicode_invalid
;
6116 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
6117 unicode_display
= unicode_hex
;
6118 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
6119 unicode_display
= unicode_highlight
;
6121 error (_("invalid argument to -U/--unicode: %s"), optarg
);
6124 case OPTION_SYM_BASE
:
6128 sym_base
= strtoul (optarg
, NULL
, 0);
6145 /* xgettext:c-format */
6146 error (_("Invalid option '-%c'\n"), c
);
6153 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
6154 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
6155 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
6156 && !do_section_groups
&& !do_archive_index
6157 && !do_dyn_syms
&& !do_lto_syms
)
6162 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
6163 do_segments
= do_header
= do_dump
= do_version
= true;
6164 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
6165 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
6174 get_elf_class (unsigned int elf_class
)
6176 static char buff
[32];
6180 case ELFCLASSNONE
: return _("none");
6181 case ELFCLASS32
: return "ELF32";
6182 case ELFCLASS64
: return "ELF64";
6184 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
6190 get_data_encoding (unsigned int encoding
)
6192 static char buff
[32];
6196 case ELFDATANONE
: return _("none");
6197 case ELFDATA2LSB
: return _("2's complement, little endian");
6198 case ELFDATA2MSB
: return _("2's complement, big endian");
6200 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
6206 check_magic_number (Filedata
* filedata
, Elf_Internal_Ehdr
* header
)
6208 if (header
->e_ident
[EI_MAG0
] == ELFMAG0
6209 && header
->e_ident
[EI_MAG1
] == ELFMAG1
6210 && header
->e_ident
[EI_MAG2
] == ELFMAG2
6211 && header
->e_ident
[EI_MAG3
] == ELFMAG3
)
6214 /* Some compilers produce object files that are not in the ELF file format.
6215 As an aid to users of readelf, try to identify these cases and suggest
6218 FIXME: It is not clear if all four bytes are used as constant magic
6219 valus by all compilers. It may be necessary to recode this function if
6220 different tools use different length sequences. */
6224 unsigned char magic
[4];
6225 const char * obj_message
;
6226 const char * ar_message
;
6230 { { 'B', 'C', 0xc0, 0xde },
6231 N_("This is a LLVM bitcode file - try using llvm-bcanalyzer\n"),
6232 N_("This is a LLVM bitcode file - try extracting and then using llvm-bcanalyzer\n")
6234 { { 'g', 'o', ' ', 'o' },
6235 N_("This is a GO binary file - try using 'go tool objdump' or 'go tool nm'\n"),
6241 for (i
= ARRAY_SIZE (known_magic
); i
--;)
6243 if (header
->e_ident
[EI_MAG0
] == known_magic
[i
].magic
[0]
6244 && header
->e_ident
[EI_MAG1
] == known_magic
[i
].magic
[1]
6245 && header
->e_ident
[EI_MAG2
] == known_magic
[i
].magic
[2]
6246 && header
->e_ident
[EI_MAG3
] == known_magic
[i
].magic
[3])
6248 /* Some compiler's analyzer tools do not handle archives,
6249 so we provide two different kinds of error message. */
6250 if (filedata
->archive_file_size
> 0
6251 && known_magic
[i
].ar_message
!= NULL
)
6252 error ("%s", known_magic
[i
].ar_message
);
6254 error ("%s", known_magic
[i
].obj_message
);
6259 error (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
6263 /* Decode the data held in 'filedata->file_header'. */
6266 process_file_header (Filedata
* filedata
)
6268 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
6270 if (! check_magic_number (filedata
, header
))
6273 if (! filedata
->is_separate
)
6274 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
6280 if (filedata
->is_separate
)
6281 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
6283 printf (_("ELF Header:\n"));
6284 printf (_(" Magic: "));
6285 for (i
= 0; i
< EI_NIDENT
; i
++)
6286 printf ("%2.2x ", header
->e_ident
[i
]);
6288 printf (_(" Class: %s\n"),
6289 get_elf_class (header
->e_ident
[EI_CLASS
]));
6290 printf (_(" Data: %s\n"),
6291 get_data_encoding (header
->e_ident
[EI_DATA
]));
6292 printf (_(" Version: %d%s\n"),
6293 header
->e_ident
[EI_VERSION
],
6294 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
6296 : (header
->e_ident
[EI_VERSION
] != EV_NONE
6299 printf (_(" OS/ABI: %s\n"),
6300 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
6301 printf (_(" ABI Version: %d\n"),
6302 header
->e_ident
[EI_ABIVERSION
]);
6303 printf (_(" Type: %s\n"),
6304 get_file_type (filedata
));
6305 printf (_(" Machine: %s\n"),
6306 get_machine_name (header
->e_machine
));
6307 printf (_(" Version: 0x%lx\n"),
6310 printf (_(" Entry point address: "));
6311 print_vma (header
->e_entry
, PREFIX_HEX
);
6312 printf (_("\n Start of program headers: "));
6313 print_vma (header
->e_phoff
, DEC
);
6314 printf (_(" (bytes into file)\n Start of section headers: "));
6315 print_vma (header
->e_shoff
, DEC
);
6316 printf (_(" (bytes into file)\n"));
6318 printf (_(" Flags: 0x%lx%s\n"),
6320 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
6321 printf (_(" Size of this header: %u (bytes)\n"),
6323 printf (_(" Size of program headers: %u (bytes)\n"),
6324 header
->e_phentsize
);
6325 printf (_(" Number of program headers: %u"),
6327 if (filedata
->section_headers
!= NULL
6328 && header
->e_phnum
== PN_XNUM
6329 && filedata
->section_headers
[0].sh_info
!= 0)
6330 printf (" (%u)", filedata
->section_headers
[0].sh_info
);
6331 putc ('\n', stdout
);
6332 printf (_(" Size of section headers: %u (bytes)\n"),
6333 header
->e_shentsize
);
6334 printf (_(" Number of section headers: %u"),
6336 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
6338 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
6339 printf (" (%u)", header
->e_shnum
);
6341 putc ('\n', stdout
);
6342 printf (_(" Section header string table index: %u"),
6343 header
->e_shstrndx
);
6344 if (filedata
->section_headers
!= NULL
6345 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
6347 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
6348 printf (" (%u)", header
->e_shstrndx
);
6350 if (header
->e_shstrndx
!= SHN_UNDEF
6351 && header
->e_shstrndx
>= header
->e_shnum
)
6353 header
->e_shstrndx
= SHN_UNDEF
;
6354 printf (_(" <corrupt: out of range>"));
6356 putc ('\n', stdout
);
6359 if (filedata
->section_headers
!= NULL
)
6361 if (header
->e_phnum
== PN_XNUM
6362 && filedata
->section_headers
[0].sh_info
!= 0)
6364 /* Throw away any cached read of PN_XNUM headers. */
6365 free (filedata
->program_headers
);
6366 filedata
->program_headers
= NULL
;
6367 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
6369 if (header
->e_shnum
== SHN_UNDEF
)
6370 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
6371 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
6372 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
6373 if (header
->e_shstrndx
>= header
->e_shnum
)
6374 header
->e_shstrndx
= SHN_UNDEF
;
6380 /* Read in the program headers from FILEDATA and store them in PHEADERS.
6381 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
6384 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
6386 Elf32_External_Phdr
* phdrs
;
6387 Elf32_External_Phdr
* external
;
6388 Elf_Internal_Phdr
* internal
;
6390 unsigned int size
= filedata
->file_header
.e_phentsize
;
6391 unsigned int num
= filedata
->file_header
.e_phnum
;
6393 /* PR binutils/17531: Cope with unexpected section header sizes. */
6394 if (size
== 0 || num
== 0)
6396 if (size
< sizeof * phdrs
)
6398 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
6401 if (size
> sizeof * phdrs
)
6402 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
6404 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
6405 size
, num
, _("program headers"));
6409 for (i
= 0, internal
= pheaders
, external
= phdrs
;
6410 i
< filedata
->file_header
.e_phnum
;
6411 i
++, internal
++, external
++)
6413 internal
->p_type
= BYTE_GET (external
->p_type
);
6414 internal
->p_offset
= BYTE_GET (external
->p_offset
);
6415 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
6416 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
6417 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
6418 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
6419 internal
->p_flags
= BYTE_GET (external
->p_flags
);
6420 internal
->p_align
= BYTE_GET (external
->p_align
);
6427 /* Read in the program headers from FILEDATA and store them in PHEADERS.
6428 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
6431 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
6433 Elf64_External_Phdr
* phdrs
;
6434 Elf64_External_Phdr
* external
;
6435 Elf_Internal_Phdr
* internal
;
6437 unsigned int size
= filedata
->file_header
.e_phentsize
;
6438 unsigned int num
= filedata
->file_header
.e_phnum
;
6440 /* PR binutils/17531: Cope with unexpected section header sizes. */
6441 if (size
== 0 || num
== 0)
6443 if (size
< sizeof * phdrs
)
6445 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
6448 if (size
> sizeof * phdrs
)
6449 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
6451 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
6452 size
, num
, _("program headers"));
6456 for (i
= 0, internal
= pheaders
, external
= phdrs
;
6457 i
< filedata
->file_header
.e_phnum
;
6458 i
++, internal
++, external
++)
6460 internal
->p_type
= BYTE_GET (external
->p_type
);
6461 internal
->p_flags
= BYTE_GET (external
->p_flags
);
6462 internal
->p_offset
= BYTE_GET (external
->p_offset
);
6463 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
6464 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
6465 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
6466 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
6467 internal
->p_align
= BYTE_GET (external
->p_align
);
6474 /* Returns TRUE if the program headers were read into `program_headers'. */
6477 get_program_headers (Filedata
* filedata
)
6479 Elf_Internal_Phdr
* phdrs
;
6481 /* Check cache of prior read. */
6482 if (filedata
->program_headers
!= NULL
)
6485 /* Be kind to memory checkers by looking for
6486 e_phnum values which we know must be invalid. */
6487 if (filedata
->file_header
.e_phnum
6488 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
6489 >= filedata
->file_size
)
6491 error (_("Too many program headers - %#x - the file is not that big\n"),
6492 filedata
->file_header
.e_phnum
);
6496 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
6497 sizeof (Elf_Internal_Phdr
));
6500 error (_("Out of memory reading %u program headers\n"),
6501 filedata
->file_header
.e_phnum
);
6506 ? get_32bit_program_headers (filedata
, phdrs
)
6507 : get_64bit_program_headers (filedata
, phdrs
))
6509 filedata
->program_headers
= phdrs
;
6517 /* Print program header info and locate dynamic section. */
6520 process_program_headers (Filedata
* filedata
)
6522 Elf_Internal_Phdr
* segment
;
6524 Elf_Internal_Phdr
* previous_load
= NULL
;
6526 if (filedata
->file_header
.e_phnum
== 0)
6528 /* PR binutils/12467. */
6529 if (filedata
->file_header
.e_phoff
!= 0)
6530 warn (_("possibly corrupt ELF header - it has a non-zero program"
6531 " header offset, but no program headers\n"));
6532 else if (do_segments
)
6534 if (filedata
->is_separate
)
6535 printf (_("\nThere are no program headers in linked file '%s'.\n"),
6536 filedata
->file_name
);
6538 printf (_("\nThere are no program headers in this file.\n"));
6543 if (do_segments
&& !do_header
)
6545 if (filedata
->is_separate
)
6546 printf ("\nIn linked file '%s' the ELF file type is %s\n",
6547 filedata
->file_name
, get_file_type (filedata
));
6549 printf (_("\nElf file type is %s\n"), get_file_type (filedata
));
6550 printf (_("Entry point 0x%" PRIx64
"\n"),
6551 filedata
->file_header
.e_entry
);
6552 printf (ngettext ("There is %d program header,"
6553 " starting at offset %" PRIu64
"\n",
6554 "There are %d program headers,"
6555 " starting at offset %" PRIu64
"\n",
6556 filedata
->file_header
.e_phnum
),
6557 filedata
->file_header
.e_phnum
,
6558 filedata
->file_header
.e_phoff
);
6561 if (! get_program_headers (filedata
))
6566 if (filedata
->file_header
.e_phnum
> 1)
6567 printf (_("\nProgram Headers:\n"));
6569 printf (_("\nProgram Headers:\n"));
6573 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6576 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6580 (_(" Type Offset VirtAddr PhysAddr\n"));
6582 (_(" FileSiz MemSiz Flags Align\n"));
6586 uint64_t dynamic_addr
= 0;
6587 uint64_t dynamic_size
= 0;
6588 for (i
= 0, segment
= filedata
->program_headers
;
6589 i
< filedata
->file_header
.e_phnum
;
6594 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
6598 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6599 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
6600 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
6601 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
6602 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
6604 (segment
->p_flags
& PF_R
? 'R' : ' '),
6605 (segment
->p_flags
& PF_W
? 'W' : ' '),
6606 (segment
->p_flags
& PF_X
? 'E' : ' '));
6607 printf ("%#lx", (unsigned long) segment
->p_align
);
6611 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
6612 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6615 print_vma (segment
->p_offset
, FULL_HEX
);
6619 print_vma (segment
->p_vaddr
, FULL_HEX
);
6621 print_vma (segment
->p_paddr
, FULL_HEX
);
6624 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
6625 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
6628 print_vma (segment
->p_filesz
, FULL_HEX
);
6632 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
6633 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
6636 print_vma (segment
->p_memsz
, FULL_HEX
);
6640 (segment
->p_flags
& PF_R
? 'R' : ' '),
6641 (segment
->p_flags
& PF_W
? 'W' : ' '),
6642 (segment
->p_flags
& PF_X
? 'E' : ' '));
6644 if ((unsigned long) segment
->p_align
== segment
->p_align
)
6645 printf ("%#lx", (unsigned long) segment
->p_align
);
6648 print_vma (segment
->p_align
, PREFIX_HEX
);
6653 print_vma (segment
->p_offset
, FULL_HEX
);
6655 print_vma (segment
->p_vaddr
, FULL_HEX
);
6657 print_vma (segment
->p_paddr
, FULL_HEX
);
6659 print_vma (segment
->p_filesz
, FULL_HEX
);
6661 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' : ' '));
6666 print_vma (segment
->p_align
, PREFIX_HEX
);
6669 putc ('\n', stdout
);
6672 switch (segment
->p_type
)
6675 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
6676 required by the ELF standard, several programs, including the Linux
6677 kernel, make use of non-ordered segments. */
6679 && previous_load
->p_vaddr
> segment
->p_vaddr
)
6680 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
6682 if (segment
->p_memsz
< segment
->p_filesz
)
6683 error (_("the segment's file size is larger than its memory size\n"));
6684 previous_load
= segment
;
6688 /* PR 20815 - Verify that the program header is loaded into memory. */
6689 if (i
> 0 && previous_load
!= NULL
)
6690 error (_("the PHDR segment must occur before any LOAD segment\n"));
6691 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
6695 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
6697 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
6698 if (load
->p_type
== PT_LOAD
6699 && load
->p_offset
<= segment
->p_offset
6700 && (load
->p_offset
+ load
->p_filesz
6701 >= segment
->p_offset
+ segment
->p_filesz
)
6702 && load
->p_vaddr
<= segment
->p_vaddr
6703 && (load
->p_vaddr
+ load
->p_filesz
6704 >= segment
->p_vaddr
+ segment
->p_filesz
))
6707 if (j
== filedata
->file_header
.e_phnum
)
6708 error (_("the PHDR segment is not covered by a LOAD segment\n"));
6714 error (_("more than one dynamic segment\n"));
6716 /* By default, assume that the .dynamic section is the first
6717 section in the DYNAMIC segment. */
6718 dynamic_addr
= segment
->p_offset
;
6719 dynamic_size
= segment
->p_filesz
;
6721 /* Try to locate the .dynamic section. If there is
6722 a section header table, we can easily locate it. */
6723 if (filedata
->section_headers
!= NULL
)
6725 Elf_Internal_Shdr
* sec
;
6727 sec
= find_section (filedata
, ".dynamic");
6728 if (sec
== NULL
|| sec
->sh_size
== 0)
6730 /* A corresponding .dynamic section is expected, but on
6731 IA-64/OpenVMS it is OK for it to be missing. */
6732 if (!is_ia64_vms (filedata
))
6733 error (_("no .dynamic section in the dynamic segment\n"));
6737 if (sec
->sh_type
== SHT_NOBITS
)
6744 dynamic_addr
= sec
->sh_offset
;
6745 dynamic_size
= sec
->sh_size
;
6747 /* The PT_DYNAMIC segment, which is used by the run-time
6748 loader, should exactly match the .dynamic section. */
6750 && (dynamic_addr
!= segment
->p_offset
6751 || dynamic_size
!= segment
->p_filesz
))
6753 the .dynamic section is not the same as the dynamic segment\n"));
6756 /* PR binutils/17512: Avoid corrupt dynamic section info in the
6757 segment. Check this after matching against the section headers
6758 so we don't warn on debuginfo file (which have NOBITS .dynamic
6760 if (dynamic_addr
> filedata
->file_size
6761 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
6763 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
6770 if (segment
->p_offset
>= filedata
->file_size
6771 || segment
->p_filesz
> filedata
->file_size
- segment
->p_offset
6772 || segment
->p_filesz
- 1 >= (size_t) -2
6773 || fseek64 (filedata
->handle
,
6774 filedata
->archive_file_offset
+ segment
->p_offset
,
6776 error (_("Unable to find program interpreter name\n"));
6779 size_t len
= segment
->p_filesz
;
6780 free (filedata
->program_interpreter
);
6781 filedata
->program_interpreter
= xmalloc (len
+ 1);
6782 len
= fread (filedata
->program_interpreter
, 1, len
,
6784 filedata
->program_interpreter
[len
] = 0;
6787 printf (_(" [Requesting program interpreter: %s]\n"),
6788 filedata
->program_interpreter
);
6795 && filedata
->section_headers
!= NULL
6796 && filedata
->string_table
!= NULL
)
6798 printf (_("\n Section to Segment mapping:\n"));
6799 printf (_(" Segment Sections...\n"));
6801 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
6804 Elf_Internal_Shdr
* section
;
6806 segment
= filedata
->program_headers
+ i
;
6807 section
= filedata
->section_headers
+ 1;
6809 printf (" %2.2d ", i
);
6811 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
6813 if (!ELF_TBSS_SPECIAL (section
, segment
)
6814 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
6815 printf ("%s ", printable_section_name (filedata
, section
));
6822 filedata
->dynamic_addr
= dynamic_addr
;
6823 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
6827 filedata
->dynamic_addr
= 0;
6828 filedata
->dynamic_size
= 1;
6832 /* Find the file offset corresponding to VMA by using the program headers. */
6835 offset_from_vma (Filedata
* filedata
, uint64_t vma
, uint64_t size
)
6837 Elf_Internal_Phdr
* seg
;
6839 if (! get_program_headers (filedata
))
6841 warn (_("Cannot interpret virtual addresses without program headers.\n"));
6845 for (seg
= filedata
->program_headers
;
6846 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
6849 if (seg
->p_type
!= PT_LOAD
)
6852 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
6853 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
6854 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
6857 warn (_("Virtual address %#" PRIx64
6858 " not located in any PT_LOAD segment.\n"), vma
);
6863 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
6864 If PROBE is true, this is just a probe and we do not generate any error
6865 messages if the load fails. */
6868 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
6870 Elf32_External_Shdr
* shdrs
;
6871 Elf_Internal_Shdr
* internal
;
6873 unsigned int size
= filedata
->file_header
.e_shentsize
;
6874 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6876 /* PR binutils/17531: Cope with unexpected section header sizes. */
6877 if (size
== 0 || num
== 0)
6880 /* The section header cannot be at the start of the file - that is
6881 where the ELF file header is located. A file with absolutely no
6882 sections in it will use a shoff of 0. */
6883 if (filedata
->file_header
.e_shoff
== 0)
6886 if (size
< sizeof * shdrs
)
6889 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6892 if (!probe
&& size
> sizeof * shdrs
)
6893 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6895 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
6897 probe
? NULL
: _("section headers"));
6901 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6902 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6903 if (filedata
->section_headers
== NULL
)
6906 error (_("Out of memory reading %u section headers\n"), num
);
6911 for (i
= 0, internal
= filedata
->section_headers
;
6915 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6916 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6917 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6918 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6919 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6920 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6921 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6922 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6923 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6924 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6925 if (!probe
&& internal
->sh_link
> num
)
6926 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6927 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6928 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6935 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
6938 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
6940 Elf64_External_Shdr
* shdrs
;
6941 Elf_Internal_Shdr
* internal
;
6943 unsigned int size
= filedata
->file_header
.e_shentsize
;
6944 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6946 /* PR binutils/17531: Cope with unexpected section header sizes. */
6947 if (size
== 0 || num
== 0)
6950 /* The section header cannot be at the start of the file - that is
6951 where the ELF file header is located. A file with absolutely no
6952 sections in it will use a shoff of 0. */
6953 if (filedata
->file_header
.e_shoff
== 0)
6956 if (size
< sizeof * shdrs
)
6959 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6963 if (! probe
&& size
> sizeof * shdrs
)
6964 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6966 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
6967 filedata
->file_header
.e_shoff
,
6969 probe
? NULL
: _("section headers"));
6973 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6974 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6975 if (filedata
->section_headers
== NULL
)
6978 error (_("Out of memory reading %u section headers\n"), num
);
6983 for (i
= 0, internal
= filedata
->section_headers
;
6987 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6988 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6989 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6990 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6991 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6992 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6993 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6994 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6995 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6996 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6997 if (!probe
&& internal
->sh_link
> num
)
6998 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6999 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
7000 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
7008 get_section_headers (Filedata
*filedata
, bool probe
)
7010 if (filedata
->section_headers
!= NULL
)
7014 return get_32bit_section_headers (filedata
, probe
);
7016 return get_64bit_section_headers (filedata
, probe
);
7019 static Elf_Internal_Sym
*
7020 get_32bit_elf_symbols (Filedata
*filedata
,
7021 Elf_Internal_Shdr
*section
,
7022 uint64_t *num_syms_return
)
7024 uint64_t number
= 0;
7025 Elf32_External_Sym
* esyms
= NULL
;
7026 Elf_External_Sym_Shndx
* shndx
= NULL
;
7027 Elf_Internal_Sym
* isyms
= NULL
;
7028 Elf_Internal_Sym
* psym
;
7030 elf_section_list
* entry
;
7032 if (section
->sh_size
== 0)
7034 if (num_syms_return
!= NULL
)
7035 * num_syms_return
= 0;
7039 /* Run some sanity checks first. */
7040 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
7042 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
7043 printable_section_name (filedata
, section
),
7044 section
->sh_entsize
);
7048 if (section
->sh_size
> filedata
->file_size
)
7050 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
7051 printable_section_name (filedata
, section
),
7056 number
= section
->sh_size
/ section
->sh_entsize
;
7058 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
7060 error (_("Size (%#" PRIx64
") of section %s "
7061 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
7063 printable_section_name (filedata
, section
),
7064 section
->sh_entsize
);
7068 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
7069 section
->sh_size
, _("symbols"));
7074 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
7076 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
7081 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
7085 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
7086 entry
->hdr
->sh_offset
,
7087 1, entry
->hdr
->sh_size
,
7088 _("symbol table section indices"));
7092 /* PR17531: file: heap-buffer-overflow */
7093 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
7095 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
7096 printable_section_name (filedata
, entry
->hdr
),
7097 entry
->hdr
->sh_size
,
7103 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
7107 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
7111 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
7113 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
7114 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
7115 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
7116 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
7117 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
7119 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
7120 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
7121 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
7122 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
7123 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
7130 if (num_syms_return
!= NULL
)
7131 * num_syms_return
= isyms
== NULL
? 0 : number
;
7136 static Elf_Internal_Sym
*
7137 get_64bit_elf_symbols (Filedata
*filedata
,
7138 Elf_Internal_Shdr
*section
,
7139 uint64_t *num_syms_return
)
7141 uint64_t number
= 0;
7142 Elf64_External_Sym
* esyms
= NULL
;
7143 Elf_External_Sym_Shndx
* shndx
= NULL
;
7144 Elf_Internal_Sym
* isyms
= NULL
;
7145 Elf_Internal_Sym
* psym
;
7147 elf_section_list
* entry
;
7149 if (section
->sh_size
== 0)
7151 if (num_syms_return
!= NULL
)
7152 * num_syms_return
= 0;
7156 /* Run some sanity checks first. */
7157 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
7159 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
7160 printable_section_name (filedata
, section
),
7161 section
->sh_entsize
);
7165 if (section
->sh_size
> filedata
->file_size
)
7167 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
7168 printable_section_name (filedata
, section
),
7173 number
= section
->sh_size
/ section
->sh_entsize
;
7175 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
7177 error (_("Size (%#" PRIx64
") of section %s "
7178 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
7180 printable_section_name (filedata
, section
),
7181 section
->sh_entsize
);
7185 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
7186 section
->sh_size
, _("symbols"));
7191 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
7193 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
7198 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
7202 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
7203 entry
->hdr
->sh_offset
,
7204 1, entry
->hdr
->sh_size
,
7205 _("symbol table section indices"));
7209 /* PR17531: file: heap-buffer-overflow */
7210 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
7212 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
7213 printable_section_name (filedata
, entry
->hdr
),
7214 entry
->hdr
->sh_size
,
7220 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
7224 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
7228 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
7230 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
7231 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
7232 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
7233 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
7235 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
7237 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
7238 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
7239 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
7241 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
7242 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
7249 if (num_syms_return
!= NULL
)
7250 * num_syms_return
= isyms
== NULL
? 0 : number
;
7255 static Elf_Internal_Sym
*
7256 get_elf_symbols (Filedata
*filedata
,
7257 Elf_Internal_Shdr
*section
,
7258 uint64_t *num_syms_return
)
7261 return get_32bit_elf_symbols (filedata
, section
, num_syms_return
);
7263 return get_64bit_elf_symbols (filedata
, section
, num_syms_return
);
7267 get_elf_section_flags (Filedata
* filedata
, uint64_t sh_flags
)
7269 static char buff
[1024];
7271 unsigned int field_size
= is_32bit_elf
? 8 : 16;
7273 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
7274 uint64_t os_flags
= 0;
7275 uint64_t proc_flags
= 0;
7276 uint64_t unknown_flags
= 0;
7284 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
7285 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
7286 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
7287 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
7288 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
7289 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
7290 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
7291 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
7292 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
7293 /* 9 */ { STRING_COMMA_LEN ("TLS") },
7294 /* IA-64 specific. */
7295 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
7296 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
7297 /* IA-64 OpenVMS specific. */
7298 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
7299 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
7300 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
7301 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
7302 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
7303 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
7305 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
7306 /* SPARC specific. */
7307 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
7308 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
7310 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
7311 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
7312 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
7314 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
7316 /* 25 */ { STRING_COMMA_LEN ("VLE") },
7318 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
7321 if (do_section_details
)
7322 p
+= sprintf (p
, "[%*.*lx]: ",
7323 field_size
, field_size
, (unsigned long) sh_flags
);
7329 flag
= sh_flags
& - sh_flags
;
7332 if (do_section_details
)
7336 case SHF_WRITE
: sindex
= 0; break;
7337 case SHF_ALLOC
: sindex
= 1; break;
7338 case SHF_EXECINSTR
: sindex
= 2; break;
7339 case SHF_MERGE
: sindex
= 3; break;
7340 case SHF_STRINGS
: sindex
= 4; break;
7341 case SHF_INFO_LINK
: sindex
= 5; break;
7342 case SHF_LINK_ORDER
: sindex
= 6; break;
7343 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
7344 case SHF_GROUP
: sindex
= 8; break;
7345 case SHF_TLS
: sindex
= 9; break;
7346 case SHF_EXCLUDE
: sindex
= 18; break;
7347 case SHF_COMPRESSED
: sindex
= 20; break;
7351 switch (filedata
->file_header
.e_machine
)
7354 if (flag
== SHF_IA_64_SHORT
)
7356 else if (flag
== SHF_IA_64_NORECOV
)
7358 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
7361 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
7362 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
7363 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
7364 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
7365 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
7366 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
7376 case EM_OLD_SPARCV9
:
7377 case EM_SPARC32PLUS
:
7380 if (flag
== SHF_ORDERED
)
7387 case SHF_ENTRYSECT
: sindex
= 21; break;
7388 case SHF_ARM_PURECODE
: sindex
= 22; break;
7389 case SHF_COMDEF
: sindex
= 23; break;
7394 if (flag
== SHF_PPC_VLE
)
7401 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7404 case ELFOSABI_FREEBSD
:
7405 if (flag
== SHF_GNU_RETAIN
)
7409 if (flag
== SHF_GNU_MBIND
)
7410 /* We should not recognize SHF_GNU_MBIND for
7411 ELFOSABI_NONE, but binutils as of 2019-07-23 did
7412 not set the EI_OSABI header byte. */
7423 if (p
!= buff
+ field_size
+ 4)
7425 if (size
< (10 + 2))
7427 warn (_("Internal error: not enough buffer room for section flag info"));
7428 return _("<unknown>");
7435 size
-= flags
[sindex
].len
;
7436 p
= stpcpy (p
, flags
[sindex
].str
);
7438 else if (flag
& SHF_MASKOS
)
7440 else if (flag
& SHF_MASKPROC
)
7443 unknown_flags
|= flag
;
7449 case SHF_WRITE
: *p
= 'W'; break;
7450 case SHF_ALLOC
: *p
= 'A'; break;
7451 case SHF_EXECINSTR
: *p
= 'X'; break;
7452 case SHF_MERGE
: *p
= 'M'; break;
7453 case SHF_STRINGS
: *p
= 'S'; break;
7454 case SHF_INFO_LINK
: *p
= 'I'; break;
7455 case SHF_LINK_ORDER
: *p
= 'L'; break;
7456 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
7457 case SHF_GROUP
: *p
= 'G'; break;
7458 case SHF_TLS
: *p
= 'T'; break;
7459 case SHF_EXCLUDE
: *p
= 'E'; break;
7460 case SHF_COMPRESSED
: *p
= 'C'; break;
7463 if ((filedata
->file_header
.e_machine
== EM_X86_64
7464 || filedata
->file_header
.e_machine
== EM_L1OM
7465 || filedata
->file_header
.e_machine
== EM_K1OM
)
7466 && flag
== SHF_X86_64_LARGE
)
7468 else if (filedata
->file_header
.e_machine
== EM_ARM
7469 && flag
== SHF_ARM_PURECODE
)
7471 else if (filedata
->file_header
.e_machine
== EM_PPC
7472 && flag
== SHF_PPC_VLE
)
7474 else if (flag
& SHF_MASKOS
)
7476 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7479 case ELFOSABI_FREEBSD
:
7480 if (flag
== SHF_GNU_RETAIN
)
7487 if (flag
== SHF_GNU_MBIND
)
7489 /* We should not recognize SHF_GNU_MBIND for
7490 ELFOSABI_NONE, but binutils as of 2019-07-23 did
7491 not set the EI_OSABI header byte. */
7498 sh_flags
&= ~SHF_MASKOS
;
7502 else if (flag
& SHF_MASKPROC
)
7505 sh_flags
&= ~ SHF_MASKPROC
;
7515 if (do_section_details
)
7519 if (p
!= buff
+ field_size
+ 4)
7521 if (size
< 2 + 5 + field_size
+ 1)
7523 warn (_("Internal error: not enough buffer room for section flag info"));
7524 return _("<unknown>");
7530 size
-= 5 + field_size
;
7531 p
+= sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
7532 (unsigned long) os_flags
);
7536 if (p
!= buff
+ field_size
+ 4)
7538 if (size
< 2 + 7 + field_size
+ 1)
7540 warn (_("Internal error: not enough buffer room for section flag info"));
7541 return _("<unknown>");
7547 size
-= 7 + field_size
;
7548 p
+= sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
7549 (unsigned long) proc_flags
);
7553 if (p
!= buff
+ field_size
+ 4)
7555 if (size
< 2 + 10 + field_size
+ 1)
7557 warn (_("Internal error: not enough buffer room for section flag info"));
7558 return _("<unknown>");
7564 size
-= 10 + field_size
;
7565 p
+= sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
7566 (unsigned long) unknown_flags
);
7574 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
7575 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
,
7580 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
7582 if (size
< sizeof (* echdr
))
7584 error (_("Compressed section is too small even for a compression header\n"));
7588 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7589 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7590 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7591 return sizeof (*echdr
);
7595 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
7597 if (size
< sizeof (* echdr
))
7599 error (_("Compressed section is too small even for a compression header\n"));
7603 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7604 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7605 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7606 return sizeof (*echdr
);
7611 process_section_headers (Filedata
* filedata
)
7613 Elf_Internal_Shdr
* section
;
7616 if (filedata
->file_header
.e_shnum
== 0)
7618 /* PR binutils/12467. */
7619 if (filedata
->file_header
.e_shoff
!= 0)
7621 warn (_("possibly corrupt ELF file header - it has a non-zero"
7622 " section header offset, but no section headers\n"));
7625 else if (do_sections
)
7626 printf (_("\nThere are no sections in this file.\n"));
7631 if (do_sections
&& !do_header
)
7633 if (filedata
->is_separate
&& process_links
)
7634 printf (_("In linked file '%s': "), filedata
->file_name
);
7635 if (! filedata
->is_separate
|| process_links
)
7636 printf (ngettext ("There is %d section header, "
7637 "starting at offset %#" PRIx64
":\n",
7638 "There are %d section headers, "
7639 "starting at offset %#" PRIx64
":\n",
7640 filedata
->file_header
.e_shnum
),
7641 filedata
->file_header
.e_shnum
,
7642 filedata
->file_header
.e_shoff
);
7645 if (!get_section_headers (filedata
, false))
7648 /* Read in the string table, so that we have names to display. */
7649 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
7650 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
7652 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
7654 if (section
->sh_size
!= 0)
7656 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7657 1, section
->sh_size
,
7660 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
7664 /* Scan the sections for the dynamic symbol table
7665 and dynamic string table and debug sections. */
7666 eh_addr_size
= is_32bit_elf
? 4 : 8;
7667 switch (filedata
->file_header
.e_machine
)
7670 case EM_MIPS_RS3_LE
:
7671 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
7672 FDE addresses. However, the ABI also has a semi-official ILP32
7673 variant for which the normal FDE address size rules apply.
7675 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
7676 section, where XX is the size of longs in bits. Unfortunately,
7677 earlier compilers provided no way of distinguishing ILP32 objects
7678 from LP64 objects, so if there's any doubt, we should assume that
7679 the official LP64 form is being used. */
7680 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
7681 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
7687 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
7689 case E_H8_MACH_H8300
:
7690 case E_H8_MACH_H8300HN
:
7691 case E_H8_MACH_H8300SN
:
7692 case E_H8_MACH_H8300SXN
:
7695 case E_H8_MACH_H8300H
:
7696 case E_H8_MACH_H8300S
:
7697 case E_H8_MACH_H8300SX
:
7705 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
7707 case EF_M32C_CPU_M16C
:
7714 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
7717 uint64_t expected_entsize = is_32bit_elf ? size32 : size64; \
7718 if (section->sh_entsize != expected_entsize) \
7720 error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \
7721 i, section->sh_entsize); \
7722 error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \
7723 expected_entsize); \
7724 section->sh_entsize = expected_entsize; \
7729 #define CHECK_ENTSIZE(section, i, type) \
7730 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
7731 sizeof (Elf64_External_##type))
7733 for (i
= 0, section
= filedata
->section_headers
;
7734 i
< filedata
->file_header
.e_shnum
;
7737 const char *name
= printable_section_name (filedata
, section
);
7739 /* Run some sanity checks on the headers and
7740 possibly fill in some file data as well. */
7741 switch (section
->sh_type
)
7744 if (filedata
->dynamic_symbols
!= NULL
)
7746 error (_("File contains multiple dynamic symbol tables\n"));
7750 CHECK_ENTSIZE (section
, i
, Sym
);
7751 filedata
->dynamic_symbols
7752 = get_elf_symbols (filedata
, section
, &filedata
->num_dynamic_syms
);
7753 filedata
->dynamic_symtab_section
= section
;
7757 if (streq (name
, ".dynstr"))
7759 if (filedata
->dynamic_strings
!= NULL
)
7761 error (_("File contains multiple dynamic string tables\n"));
7765 filedata
->dynamic_strings
7766 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7767 1, section
->sh_size
, _("dynamic strings"));
7768 filedata
->dynamic_strings_length
7769 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
7770 filedata
->dynamic_strtab_section
= section
;
7774 case SHT_SYMTAB_SHNDX
:
7776 elf_section_list
* entry
= xmalloc (sizeof * entry
);
7778 entry
->hdr
= section
;
7779 entry
->next
= filedata
->symtab_shndx_list
;
7780 filedata
->symtab_shndx_list
= entry
;
7785 CHECK_ENTSIZE (section
, i
, Sym
);
7789 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
7793 CHECK_ENTSIZE (section
, i
, Rel
);
7794 if (do_checks
&& section
->sh_size
== 0)
7795 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7799 CHECK_ENTSIZE (section
, i
, Rela
);
7800 if (do_checks
&& section
->sh_size
== 0)
7801 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7805 CHECK_ENTSIZE (section
, i
, Relr
);
7810 /* Having a zero sized section is not illegal according to the
7811 ELF standard, but it might be an indication that something
7812 is wrong. So issue a warning if we are running in lint mode. */
7813 if (do_checks
&& section
->sh_size
== 0)
7814 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
7821 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
7822 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
7823 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
7824 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
7826 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
7827 && (startswith (name
, ".debug_")
7828 || startswith (name
, ".zdebug_")))
7831 name
+= sizeof (".zdebug_") - 1;
7833 name
+= sizeof (".debug_") - 1;
7836 || (do_debug_info
&& startswith (name
, "info"))
7837 || (do_debug_info
&& startswith (name
, "types"))
7838 || (do_debug_abbrevs
&& startswith (name
, "abbrev"))
7839 || (do_debug_lines
&& strcmp (name
, "line") == 0)
7840 || (do_debug_lines
&& startswith (name
, "line."))
7841 || (do_debug_pubnames
&& startswith (name
, "pubnames"))
7842 || (do_debug_pubtypes
&& startswith (name
, "pubtypes"))
7843 || (do_debug_pubnames
&& startswith (name
, "gnu_pubnames"))
7844 || (do_debug_pubtypes
&& startswith (name
, "gnu_pubtypes"))
7845 || (do_debug_aranges
&& startswith (name
, "aranges"))
7846 || (do_debug_ranges
&& startswith (name
, "ranges"))
7847 || (do_debug_ranges
&& startswith (name
, "rnglists"))
7848 || (do_debug_frames
&& startswith (name
, "frame"))
7849 || (do_debug_macinfo
&& startswith (name
, "macinfo"))
7850 || (do_debug_macinfo
&& startswith (name
, "macro"))
7851 || (do_debug_str
&& startswith (name
, "str"))
7852 || (do_debug_links
&& startswith (name
, "sup"))
7853 || (do_debug_str_offsets
&& startswith (name
, "str_offsets"))
7854 || (do_debug_loc
&& startswith (name
, "loc"))
7855 || (do_debug_loc
&& startswith (name
, "loclists"))
7856 || (do_debug_addr
&& startswith (name
, "addr"))
7857 || (do_debug_cu_index
&& startswith (name
, "cu_index"))
7858 || (do_debug_cu_index
&& startswith (name
, "tu_index"))
7860 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7862 /* Linkonce section to be combined with .debug_info at link time. */
7863 else if ((do_debugging
|| do_debug_info
)
7864 && startswith (name
, ".gnu.linkonce.wi."))
7865 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7866 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
7867 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7868 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
7869 || streq (name
, ".debug_names")))
7870 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7871 /* Trace sections for Itanium VMS. */
7872 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
7873 || do_trace_aranges
)
7874 && startswith (name
, ".trace_"))
7876 name
+= sizeof (".trace_") - 1;
7879 || (do_trace_info
&& streq (name
, "info"))
7880 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
7881 || (do_trace_aranges
&& streq (name
, "aranges"))
7883 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7885 else if ((do_debugging
|| do_debug_links
)
7886 && (startswith (name
, ".gnu_debuglink")
7887 || startswith (name
, ".gnu_debugaltlink")))
7888 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7894 if (filedata
->is_separate
&& ! process_links
)
7897 if (filedata
->is_separate
)
7898 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
7899 else if (filedata
->file_header
.e_shnum
> 1)
7900 printf (_("\nSection Headers:\n"));
7902 printf (_("\nSection Header:\n"));
7906 if (do_section_details
)
7908 printf (_(" [Nr] Name\n"));
7909 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
7913 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
7917 if (do_section_details
)
7919 printf (_(" [Nr] Name\n"));
7920 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
7924 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
7928 if (do_section_details
)
7930 printf (_(" [Nr] Name\n"));
7931 printf (_(" Type Address Offset Link\n"));
7932 printf (_(" Size EntSize Info Align\n"));
7936 printf (_(" [Nr] Name Type Address Offset\n"));
7937 printf (_(" Size EntSize Flags Link Info Align\n"));
7941 if (do_section_details
)
7942 printf (_(" Flags\n"));
7944 for (i
= 0, section
= filedata
->section_headers
;
7945 i
< filedata
->file_header
.e_shnum
;
7948 /* Run some sanity checks on the section header. */
7950 /* Check the sh_link field. */
7951 switch (section
->sh_type
)
7955 if (section
->sh_link
== 0
7956 && (filedata
->file_header
.e_type
== ET_EXEC
7957 || filedata
->file_header
.e_type
== ET_DYN
))
7958 /* A dynamic relocation section where all entries use a
7959 zero symbol index need not specify a symtab section. */
7962 case SHT_SYMTAB_SHNDX
:
7966 case SHT_GNU_versym
:
7967 if (section
->sh_link
== 0
7968 || section
->sh_link
>= filedata
->file_header
.e_shnum
7969 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
7970 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
7971 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
7972 i
, section
->sh_link
);
7978 case SHT_GNU_verneed
:
7979 case SHT_GNU_verdef
:
7980 case SHT_GNU_LIBLIST
:
7981 if (section
->sh_link
== 0
7982 || section
->sh_link
>= filedata
->file_header
.e_shnum
7983 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
7984 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
7985 i
, section
->sh_link
);
7988 case SHT_INIT_ARRAY
:
7989 case SHT_FINI_ARRAY
:
7990 case SHT_PREINIT_ARRAY
:
7991 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7992 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7993 i
, section
->sh_link
);
7997 /* FIXME: Add support for target specific section types. */
7998 #if 0 /* Currently we do not check other section types as there are too
7999 many special cases. Stab sections for example have a type
8000 of SHT_PROGBITS but an sh_link field that links to the .stabstr
8002 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
8003 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
8004 i
, section
->sh_link
);
8009 /* Check the sh_info field. */
8010 switch (section
->sh_type
)
8014 if (section
->sh_info
== 0
8015 && (filedata
->file_header
.e_type
== ET_EXEC
8016 || filedata
->file_header
.e_type
== ET_DYN
))
8017 /* Dynamic relocations apply to segments, so they do not
8018 need to specify the section they relocate. */
8020 if (section
->sh_info
== 0
8021 || section
->sh_info
>= filedata
->file_header
.e_shnum
8022 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
8023 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
8024 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
8025 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
8026 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
8027 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
8028 /* FIXME: Are other section types valid ? */
8029 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
8030 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
8031 i
, section
->sh_info
);
8036 case SHT_SYMTAB_SHNDX
:
8037 case SHT_INIT_ARRAY
:
8038 case SHT_FINI_ARRAY
:
8039 case SHT_PREINIT_ARRAY
:
8040 if (section
->sh_info
!= 0)
8041 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
8042 i
, section
->sh_info
);
8048 /* A symbol index - we assume that it is valid. */
8052 /* FIXME: Add support for target specific section types. */
8053 if (section
->sh_type
== SHT_NOBITS
)
8054 /* NOBITS section headers with non-zero sh_info fields can be
8055 created when a binary is stripped of everything but its debug
8056 information. The stripped sections have their headers
8057 preserved but their types set to SHT_NOBITS. So do not check
8058 this type of section. */
8060 else if (section
->sh_flags
& SHF_INFO_LINK
)
8062 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
8063 warn (_("[%2u]: Expected link to another section in info field"), i
);
8065 else if (section
->sh_type
< SHT_LOOS
8066 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
8067 && section
->sh_info
!= 0)
8068 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
8069 i
, section
->sh_info
);
8073 /* Check the sh_size field. */
8074 if (section
->sh_size
> filedata
->file_size
8075 && section
->sh_type
!= SHT_NOBITS
8076 && section
->sh_type
!= SHT_NULL
8077 && section
->sh_type
< SHT_LOOS
)
8078 warn (_("Size of section %u is larger than the entire file!\n"), i
);
8080 printf (" [%2u] ", i
);
8081 if (do_section_details
)
8082 printf ("%s\n ", printable_section_name (filedata
, section
));
8084 print_symbol_name (-17, printable_section_name (filedata
, section
));
8086 printf (do_wide
? " %-15s " : " %-15.15s ",
8087 get_section_type_name (filedata
, section
->sh_type
));
8091 const char * link_too_big
= NULL
;
8093 print_vma (section
->sh_addr
, LONG_HEX
);
8095 printf ( " %6.6lx %6.6lx %2.2lx",
8096 (unsigned long) section
->sh_offset
,
8097 (unsigned long) section
->sh_size
,
8098 (unsigned long) section
->sh_entsize
);
8100 if (do_section_details
)
8101 fputs (" ", stdout
);
8103 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
8105 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
8108 /* The sh_link value is out of range. Normally this indicates
8109 an error but it can have special values in Solaris binaries. */
8110 switch (filedata
->file_header
.e_machine
)
8117 case EM_OLD_SPARCV9
:
8118 case EM_SPARC32PLUS
:
8121 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
8122 link_too_big
= "BEFORE";
8123 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
8124 link_too_big
= "AFTER";
8131 if (do_section_details
)
8133 if (link_too_big
!= NULL
&& * link_too_big
)
8134 printf ("<%s> ", link_too_big
);
8136 printf ("%2u ", section
->sh_link
);
8137 printf ("%3u %2lu\n", section
->sh_info
,
8138 (unsigned long) section
->sh_addralign
);
8141 printf ("%2u %3u %2lu\n",
8144 (unsigned long) section
->sh_addralign
);
8146 if (link_too_big
&& ! * link_too_big
)
8147 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
8148 i
, section
->sh_link
);
8152 print_vma (section
->sh_addr
, LONG_HEX
);
8154 if ((long) section
->sh_offset
== section
->sh_offset
)
8155 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
8159 print_vma (section
->sh_offset
, LONG_HEX
);
8162 if ((unsigned long) section
->sh_size
== section
->sh_size
)
8163 printf (" %6.6lx", (unsigned long) section
->sh_size
);
8167 print_vma (section
->sh_size
, LONG_HEX
);
8170 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
8171 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
8175 print_vma (section
->sh_entsize
, LONG_HEX
);
8178 if (do_section_details
)
8179 fputs (" ", stdout
);
8181 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
8183 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
8185 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
8186 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
8189 print_vma (section
->sh_addralign
, DEC
);
8193 else if (do_section_details
)
8196 print_vma (section
->sh_addr
, LONG_HEX
);
8197 if ((long) section
->sh_offset
== section
->sh_offset
)
8198 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
8202 print_vma (section
->sh_offset
, LONG_HEX
);
8204 printf (" %u\n ", section
->sh_link
);
8205 print_vma (section
->sh_size
, LONG_HEX
);
8207 print_vma (section
->sh_entsize
, LONG_HEX
);
8209 printf (" %-16u %lu\n",
8211 (unsigned long) section
->sh_addralign
);
8216 print_vma (section
->sh_addr
, LONG_HEX
);
8217 if ((long) section
->sh_offset
== section
->sh_offset
)
8218 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
8222 print_vma (section
->sh_offset
, LONG_HEX
);
8225 print_vma (section
->sh_size
, LONG_HEX
);
8227 print_vma (section
->sh_entsize
, LONG_HEX
);
8229 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
8231 printf (" %2u %3u %lu\n",
8234 (unsigned long) section
->sh_addralign
);
8237 if (do_section_details
)
8239 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
8240 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
8242 /* Minimum section size is 12 bytes for 32-bit compression
8243 header + 12 bytes for compressed data header. */
8244 unsigned char buf
[24];
8246 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
8247 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
8248 sizeof (buf
), _("compression header")))
8250 Elf_Internal_Chdr chdr
;
8252 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
8253 printf (_(" [<corrupt>]\n"));
8256 if (chdr
.ch_type
== ch_compress_zlib
)
8258 else if (chdr
.ch_type
== ch_compress_zstd
)
8261 printf (_(" [<unknown>: 0x%x], "),
8263 print_vma (chdr
.ch_size
, LONG_HEX
);
8264 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
8271 if (!do_section_details
)
8273 /* The ordering of the letters shown here matches the ordering of the
8274 corresponding SHF_xxx values, and hence the order in which these
8275 letters will be displayed to the user. */
8276 printf (_("Key to Flags:\n\
8277 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
8278 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
8279 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
8280 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
8283 case ELFOSABI_FREEBSD
:
8284 printf (_("R (retain), "));
8287 printf (_("D (mbind), "));
8292 if (filedata
->file_header
.e_machine
== EM_X86_64
8293 || filedata
->file_header
.e_machine
== EM_L1OM
8294 || filedata
->file_header
.e_machine
== EM_K1OM
)
8295 printf (_("l (large), "));
8296 else if (filedata
->file_header
.e_machine
== EM_ARM
)
8297 printf (_("y (purecode), "));
8298 else if (filedata
->file_header
.e_machine
== EM_PPC
)
8299 printf (_("v (VLE), "));
8300 printf ("p (processor specific)\n");
8307 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
8308 Elf_Internal_Sym
**symtab
, uint64_t *nsyms
,
8309 char **strtab
, uint64_t *strtablen
)
8313 *symtab
= get_elf_symbols (filedata
, symsec
, nsyms
);
8315 if (*symtab
== NULL
)
8318 if (symsec
->sh_link
!= 0)
8320 Elf_Internal_Shdr
*strsec
;
8322 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
8324 error (_("Bad sh_link in symbol table section\n"));
8331 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
8333 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
8334 1, strsec
->sh_size
, _("string table"));
8335 if (*strtab
== NULL
)
8342 *strtablen
= strsec
->sh_size
;
8348 get_group_flags (unsigned int flags
)
8350 static char buff
[128];
8354 else if (flags
== GRP_COMDAT
)
8357 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
8359 flags
& GRP_MASKOS
? _("<OS specific>") : "",
8360 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
8361 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
8362 ? _("<unknown>") : ""));
8368 process_section_groups (Filedata
* filedata
)
8370 Elf_Internal_Shdr
* section
;
8372 struct group
* group
;
8373 Elf_Internal_Shdr
* symtab_sec
;
8374 Elf_Internal_Shdr
* strtab_sec
;
8375 Elf_Internal_Sym
* symtab
;
8380 /* Don't process section groups unless needed. */
8381 if (!do_unwind
&& !do_section_groups
)
8384 if (filedata
->file_header
.e_shnum
== 0)
8386 if (do_section_groups
)
8388 if (filedata
->is_separate
)
8389 printf (_("\nThere are no sections group in linked file '%s'.\n"),
8390 filedata
->file_name
);
8392 printf (_("\nThere are no section groups in this file.\n"));
8397 if (filedata
->section_headers
== NULL
)
8399 error (_("Section headers are not available!\n"));
8400 /* PR 13622: This can happen with a corrupt ELF header. */
8404 filedata
->section_headers_groups
8405 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
8406 sizeof (struct group
*));
8408 if (filedata
->section_headers_groups
== NULL
)
8410 error (_("Out of memory reading %u section group headers\n"),
8411 filedata
->file_header
.e_shnum
);
8415 /* Scan the sections for the group section. */
8416 filedata
->group_count
= 0;
8417 for (i
= 0, section
= filedata
->section_headers
;
8418 i
< filedata
->file_header
.e_shnum
;
8420 if (section
->sh_type
== SHT_GROUP
)
8421 filedata
->group_count
++;
8423 if (filedata
->group_count
== 0)
8425 if (do_section_groups
)
8427 if (filedata
->is_separate
)
8428 printf (_("\nThere are no section groups in linked file '%s'.\n"),
8429 filedata
->file_name
);
8431 printf (_("\nThere are no section groups in this file.\n"));
8437 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
8438 sizeof (struct group
));
8440 if (filedata
->section_groups
== NULL
)
8442 error (_("Out of memory reading %zu groups\n"), filedata
->group_count
);
8453 if (filedata
->is_separate
)
8454 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
8456 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
8457 i
< filedata
->file_header
.e_shnum
;
8460 if (section
->sh_type
== SHT_GROUP
)
8462 const char * name
= printable_section_name (filedata
, section
);
8463 const char * group_name
;
8464 unsigned char * start
;
8465 unsigned char * indices
;
8466 unsigned int entry
, j
, size
;
8467 Elf_Internal_Shdr
* sec
;
8468 Elf_Internal_Sym
* sym
;
8470 /* Get the symbol table. */
8471 if (section
->sh_link
>= filedata
->file_header
.e_shnum
8472 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
8475 error (_("Bad sh_link in group section `%s'\n"), name
);
8479 if (symtab_sec
!= sec
)
8483 symtab
= get_elf_symbols (filedata
, symtab_sec
, & num_syms
);
8488 error (_("Corrupt header in group section `%s'\n"), name
);
8492 if (section
->sh_info
>= num_syms
)
8494 error (_("Bad sh_info in group section `%s'\n"), name
);
8498 sym
= symtab
+ section
->sh_info
;
8500 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8502 if (sym
->st_shndx
== 0
8503 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
8505 error (_("Bad sh_info in group section `%s'\n"), name
);
8509 group_name
= printable_section_name (filedata
,
8510 filedata
->section_headers
8519 /* Get the string table. */
8520 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
8528 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
8533 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
8534 1, strtab_sec
->sh_size
,
8536 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
8538 group_name
= sym
->st_name
< strtab_size
8539 ? strtab
+ sym
->st_name
: _("<corrupt>");
8542 /* PR 17531: file: loop. */
8543 if (section
->sh_entsize
> section
->sh_size
)
8545 error (_("Section %s has sh_entsize (%#" PRIx64
")"
8546 " which is larger than its size (%#" PRIx64
")\n"),
8547 printable_section_name (filedata
, section
),
8548 section
->sh_entsize
,
8553 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
8554 1, section
->sh_size
,
8560 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
8561 entry
= byte_get (indices
, 4);
8564 if (do_section_groups
)
8566 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
8567 get_group_flags (entry
), i
, name
, group_name
, size
);
8569 printf (_(" [Index] Name\n"));
8572 group
->group_index
= i
;
8574 for (j
= 0; j
< size
; j
++)
8576 struct group_list
* g
;
8578 entry
= byte_get (indices
, 4);
8581 if (entry
>= filedata
->file_header
.e_shnum
)
8583 static unsigned num_group_errors
= 0;
8585 if (num_group_errors
++ < 10)
8587 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
8588 entry
, i
, filedata
->file_header
.e_shnum
- 1);
8589 if (num_group_errors
== 10)
8590 warn (_("Further error messages about overlarge group section indices suppressed\n"));
8595 if (filedata
->section_headers_groups
[entry
] != NULL
)
8599 static unsigned num_errs
= 0;
8601 if (num_errs
++ < 10)
8603 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
8605 filedata
->section_headers_groups
[entry
]->group_index
);
8607 warn (_("Further error messages about already contained group sections suppressed\n"));
8613 /* Intel C/C++ compiler may put section 0 in a
8614 section group. We just warn it the first time
8615 and ignore it afterwards. */
8616 static bool warned
= false;
8619 error (_("section 0 in group section [%5u]\n"),
8620 filedata
->section_headers_groups
[entry
]->group_index
);
8626 filedata
->section_headers_groups
[entry
] = group
;
8628 if (do_section_groups
)
8630 sec
= filedata
->section_headers
+ entry
;
8631 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
8634 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
8635 g
->section_index
= entry
;
8636 g
->next
= group
->root
;
8651 /* Data used to display dynamic fixups. */
8653 struct ia64_vms_dynfixup
8655 uint64_t needed_ident
; /* Library ident number. */
8656 uint64_t needed
; /* Index in the dstrtab of the library name. */
8657 uint64_t fixup_needed
; /* Index of the library. */
8658 uint64_t fixup_rela_cnt
; /* Number of fixups. */
8659 uint64_t fixup_rela_off
; /* Fixups offset in the dynamic segment. */
8662 /* Data used to display dynamic relocations. */
8664 struct ia64_vms_dynimgrela
8666 uint64_t img_rela_cnt
; /* Number of relocations. */
8667 uint64_t img_rela_off
; /* Reloc offset in the dynamic segment. */
8670 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
8674 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
8675 struct ia64_vms_dynfixup
* fixup
,
8676 const char * strtab
,
8677 unsigned int strtab_sz
)
8679 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
8681 const char * lib_name
;
8683 imfs
= get_data (NULL
, filedata
,
8684 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
8685 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
8686 _("dynamic section image fixups"));
8690 if (fixup
->needed
< strtab_sz
)
8691 lib_name
= strtab
+ fixup
->needed
;
8694 warn (_("corrupt library name index of %#" PRIx64
8695 " found in dynamic entry"), fixup
->needed
);
8699 printf (_("\nImage fixups for needed library #%" PRId64
8700 ": %s - ident: %" PRIx64
"\n"),
8701 fixup
->fixup_needed
, lib_name
, fixup
->needed_ident
);
8703 (_("Seg Offset Type SymVec DataType\n"));
8705 for (i
= 0; i
< (size_t) fixup
->fixup_rela_cnt
; i
++)
8710 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
8711 printf ("%016" PRIx64
" ", BYTE_GET (imfs
[i
].fixup_offset
));
8712 type
= BYTE_GET (imfs
[i
].type
);
8713 rtype
= elf_ia64_reloc_type (type
);
8715 printf ("0x%08x ", type
);
8717 printf ("%-32s ", rtype
);
8718 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
8719 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
8726 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
8729 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
8731 Elf64_External_VMS_IMAGE_RELA
*imrs
;
8734 imrs
= get_data (NULL
, filedata
,
8735 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
8736 sizeof (*imrs
), imgrela
->img_rela_cnt
,
8737 _("dynamic section image relocations"));
8741 printf (_("\nImage relocs\n"));
8743 (_("Seg Offset Type Addend Seg Sym Off\n"));
8745 for (i
= 0; i
< (size_t) imgrela
->img_rela_cnt
; i
++)
8750 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
8751 printf ("%08" PRIx64
" ", BYTE_GET (imrs
[i
].rela_offset
));
8752 type
= BYTE_GET (imrs
[i
].type
);
8753 rtype
= elf_ia64_reloc_type (type
);
8755 printf ("0x%08x ", type
);
8757 printf ("%-31s ", rtype
);
8758 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
8759 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
8760 printf ("%08" PRIx64
"\n", BYTE_GET (imrs
[i
].sym_offset
));
8767 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
8770 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
8772 struct ia64_vms_dynfixup fixup
;
8773 struct ia64_vms_dynimgrela imgrela
;
8774 Elf_Internal_Dyn
*entry
;
8775 uint64_t strtab_off
= 0;
8776 uint64_t strtab_sz
= 0;
8777 char *strtab
= NULL
;
8780 memset (&fixup
, 0, sizeof (fixup
));
8781 memset (&imgrela
, 0, sizeof (imgrela
));
8783 /* Note: the order of the entries is specified by the OpenVMS specs. */
8784 for (entry
= filedata
->dynamic_section
;
8785 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
8788 switch (entry
->d_tag
)
8790 case DT_IA_64_VMS_STRTAB_OFFSET
:
8791 strtab_off
= entry
->d_un
.d_val
;
8794 strtab_sz
= entry
->d_un
.d_val
;
8796 strtab
= get_data (NULL
, filedata
,
8797 filedata
->dynamic_addr
+ strtab_off
,
8798 1, strtab_sz
, _("dynamic string section"));
8803 case DT_IA_64_VMS_NEEDED_IDENT
:
8804 fixup
.needed_ident
= entry
->d_un
.d_val
;
8807 fixup
.needed
= entry
->d_un
.d_val
;
8809 case DT_IA_64_VMS_FIXUP_NEEDED
:
8810 fixup
.fixup_needed
= entry
->d_un
.d_val
;
8812 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
8813 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
8815 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
8816 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
8817 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
8820 case DT_IA_64_VMS_IMG_RELA_CNT
:
8821 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
8823 case DT_IA_64_VMS_IMG_RELA_OFF
:
8824 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
8825 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
8844 relocation_type rel_type
;
8846 dynamic_relocations
[] =
8848 { "REL", DT_REL
, DT_RELSZ
, reltype_rel
},
8849 { "RELA", DT_RELA
, DT_RELASZ
, reltype_rela
},
8850 { "RELR", DT_RELR
, DT_RELRSZ
, reltype_relr
},
8851 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, reltype_unknown
}
8854 /* Process the reloc section. */
8857 process_relocs (Filedata
* filedata
)
8860 uint64_t rel_offset
;
8865 if (do_using_dynamic
)
8867 relocation_type rel_type
;
8869 bool has_dynamic_reloc
;
8872 has_dynamic_reloc
= false;
8874 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8876 rel_type
= dynamic_relocations
[i
].rel_type
;
8877 name
= dynamic_relocations
[i
].name
;
8878 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
8879 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
8882 has_dynamic_reloc
= true;
8884 if (rel_type
== reltype_unknown
)
8886 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
8887 switch (filedata
->dynamic_info
[DT_PLTREL
])
8890 rel_type
= reltype_rel
;
8893 rel_type
= reltype_rela
;
8900 if (filedata
->is_separate
)
8902 (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64
8903 " contains %" PRId64
" bytes:\n"),
8904 filedata
->file_name
, name
, rel_offset
, rel_size
);
8907 (_("\n'%s' relocation section at offset %#" PRIx64
8908 " contains %" PRId64
" bytes:\n"),
8909 name
, rel_offset
, rel_size
);
8911 dump_relocations (filedata
,
8912 offset_from_vma (filedata
, rel_offset
, rel_size
),
8914 filedata
->dynamic_symbols
,
8915 filedata
->num_dynamic_syms
,
8916 filedata
->dynamic_strings
,
8917 filedata
->dynamic_strings_length
,
8918 rel_type
, true /* is_dynamic */);
8922 if (is_ia64_vms (filedata
))
8923 if (process_ia64_vms_dynamic_relocs (filedata
))
8924 has_dynamic_reloc
= true;
8926 if (! has_dynamic_reloc
)
8928 if (filedata
->is_separate
)
8929 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
8930 filedata
->file_name
);
8932 printf (_("\nThere are no dynamic relocations in this file.\n"));
8937 Elf_Internal_Shdr
* section
;
8941 for (i
= 0, section
= filedata
->section_headers
;
8942 i
< filedata
->file_header
.e_shnum
;
8945 if ( section
->sh_type
!= SHT_RELA
8946 && section
->sh_type
!= SHT_REL
8947 && section
->sh_type
!= SHT_RELR
)
8950 rel_offset
= section
->sh_offset
;
8951 rel_size
= section
->sh_size
;
8955 relocation_type rel_type
;
8958 if (filedata
->is_separate
)
8959 printf (_("\nIn linked file '%s' relocation section "),
8960 filedata
->file_name
);
8962 printf (_("\nRelocation section "));
8964 if (filedata
->string_table
== NULL
)
8965 printf ("%d", section
->sh_name
);
8967 printf ("'%s'", printable_section_name (filedata
, section
));
8969 num_rela
= rel_size
/ section
->sh_entsize
;
8970 printf (ngettext (" at offset %#" PRIx64
8971 " contains %" PRIu64
" entry:\n",
8972 " at offset %#" PRIx64
8973 " contains %" PRId64
" entries:\n",
8975 rel_offset
, num_rela
);
8977 rel_type
= section
->sh_type
== SHT_RELA
? reltype_rela
:
8978 section
->sh_type
== SHT_REL
? reltype_rel
: reltype_relr
;
8980 if (section
->sh_link
!= 0
8981 && section
->sh_link
< filedata
->file_header
.e_shnum
)
8983 Elf_Internal_Shdr
*symsec
;
8984 Elf_Internal_Sym
*symtab
;
8986 uint64_t strtablen
= 0;
8987 char *strtab
= NULL
;
8989 symsec
= filedata
->section_headers
+ section
->sh_link
;
8990 if (symsec
->sh_type
!= SHT_SYMTAB
8991 && symsec
->sh_type
!= SHT_DYNSYM
)
8994 if (!get_symtab (filedata
, symsec
,
8995 &symtab
, &nsyms
, &strtab
, &strtablen
))
8998 dump_relocations (filedata
, rel_offset
, rel_size
,
8999 symtab
, nsyms
, strtab
, strtablen
,
9001 symsec
->sh_type
== SHT_DYNSYM
);
9006 dump_relocations (filedata
, rel_offset
, rel_size
,
9007 NULL
, 0, NULL
, 0, rel_type
, false /* is_dynamic */);
9015 /* Users sometimes forget the -D option, so try to be helpful. */
9016 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
9018 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
9020 if (filedata
->is_separate
)
9021 printf (_("\nThere are no static relocations in linked file '%s'."),
9022 filedata
->file_name
);
9024 printf (_("\nThere are no static relocations in this file."));
9025 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
9030 if (i
== ARRAY_SIZE (dynamic_relocations
))
9032 if (filedata
->is_separate
)
9033 printf (_("\nThere are no relocations in linked file '%s'.\n"),
9034 filedata
->file_name
);
9036 printf (_("\nThere are no relocations in this file.\n"));
9044 /* An absolute address consists of a section and an offset. If the
9045 section is NULL, the offset itself is the address, otherwise, the
9046 address equals to LOAD_ADDRESS(section) + offset. */
9050 unsigned short section
;
9054 /* Find the nearest symbol at or below ADDR. Returns the symbol
9055 name, if found, and the offset from the symbol to ADDR. */
9058 find_symbol_for_address (Filedata
*filedata
,
9059 Elf_Internal_Sym
*symtab
,
9062 uint64_t strtab_size
,
9063 struct absaddr addr
,
9064 const char **symname
,
9067 uint64_t dist
= 0x100000;
9068 Elf_Internal_Sym
* sym
;
9069 Elf_Internal_Sym
* beg
;
9070 Elf_Internal_Sym
* end
;
9071 Elf_Internal_Sym
* best
= NULL
;
9073 REMOVE_ARCH_BITS (addr
.offset
);
9075 end
= symtab
+ nsyms
;
9081 sym
= beg
+ (end
- beg
) / 2;
9083 value
= sym
->st_value
;
9084 REMOVE_ARCH_BITS (value
);
9086 if (sym
->st_name
!= 0
9087 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
9088 && addr
.offset
>= value
9089 && addr
.offset
- value
< dist
)
9092 dist
= addr
.offset
- value
;
9097 if (addr
.offset
< value
)
9105 *symname
= (best
->st_name
>= strtab_size
9106 ? _("<corrupt>") : strtab
+ best
->st_name
);
9112 *offset
= addr
.offset
;
9115 static /* signed */ int
9116 symcmp (const void *p
, const void *q
)
9118 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
9119 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
9121 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
9124 /* Process the unwind section. */
9126 #include "unwind-ia64.h"
9128 struct ia64_unw_table_entry
9130 struct absaddr start
;
9132 struct absaddr info
;
9135 struct ia64_unw_aux_info
9137 struct ia64_unw_table_entry
* table
; /* Unwind table. */
9138 uint64_t table_len
; /* Length of unwind table. */
9139 unsigned char * info
; /* Unwind info. */
9140 uint64_t info_size
; /* Size of unwind info. */
9141 uint64_t info_addr
; /* Starting address of unwind info. */
9142 uint64_t seg_base
; /* Starting address of segment. */
9143 Elf_Internal_Sym
* symtab
; /* The symbol table. */
9144 uint64_t nsyms
; /* Number of symbols. */
9145 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9146 uint64_t nfuns
; /* Number of entries in funtab. */
9147 char * strtab
; /* The string table. */
9148 uint64_t strtab_size
; /* Size of string table. */
9152 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
9154 struct ia64_unw_table_entry
* tp
;
9159 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9160 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9161 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9162 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9164 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9166 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
9170 const unsigned char * dp
;
9171 const unsigned char * head
;
9172 const unsigned char * end
;
9173 const char * procname
;
9175 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9176 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
9178 fputs ("\n<", stdout
);
9182 fputs (procname
, stdout
);
9185 printf ("+%" PRIx64
, offset
);
9188 fputs (">: [", stdout
);
9189 print_vma (tp
->start
.offset
, PREFIX_HEX
);
9190 fputc ('-', stdout
);
9191 print_vma (tp
->end
.offset
, PREFIX_HEX
);
9192 printf ("], info at +0x%" PRIx64
"\n",
9193 tp
->info
.offset
- aux
->seg_base
);
9195 /* PR 17531: file: 86232b32. */
9196 if (aux
->info
== NULL
)
9199 offset
= tp
->info
.offset
;
9200 if (tp
->info
.section
)
9202 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
9204 warn (_("Invalid section %u in table entry %td\n"),
9205 tp
->info
.section
, tp
- aux
->table
);
9209 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
9211 offset
-= aux
->info_addr
;
9212 /* PR 17531: file: 0997b4d1. */
9213 if (offset
>= aux
->info_size
9214 || aux
->info_size
- offset
< 8)
9216 warn (_("Invalid offset %" PRIx64
" in table entry %td\n"),
9217 tp
->info
.offset
, tp
- aux
->table
);
9222 head
= aux
->info
+ offset
;
9223 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
9225 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
9226 (unsigned) UNW_VER (stamp
),
9227 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
9228 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
9229 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
9230 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
9232 if (UNW_VER (stamp
) != 1)
9234 printf (_("\tUnknown version.\n"));
9239 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
9240 /* PR 17531: file: 16ceda89. */
9241 if (end
> aux
->info
+ aux
->info_size
)
9242 end
= aux
->info
+ aux
->info_size
;
9243 for (dp
= head
+ 8; dp
< end
;)
9244 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
9253 slurp_ia64_unwind_table (Filedata
* filedata
,
9254 struct ia64_unw_aux_info
* aux
,
9255 Elf_Internal_Shdr
* sec
)
9257 uint64_t size
, nrelas
, i
;
9258 Elf_Internal_Phdr
* seg
;
9259 struct ia64_unw_table_entry
* tep
;
9260 Elf_Internal_Shdr
* relsec
;
9261 Elf_Internal_Rela
* rela
;
9262 Elf_Internal_Rela
* rp
;
9263 unsigned char * table
;
9265 Elf_Internal_Sym
* sym
;
9266 const char * relname
;
9270 /* First, find the starting address of the segment that includes
9273 if (filedata
->file_header
.e_phnum
)
9275 if (! get_program_headers (filedata
))
9278 for (seg
= filedata
->program_headers
;
9279 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
9282 if (seg
->p_type
!= PT_LOAD
)
9285 if (sec
->sh_addr
>= seg
->p_vaddr
9286 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
9288 aux
->seg_base
= seg
->p_vaddr
;
9294 /* Second, build the unwind table from the contents of the unwind section: */
9295 size
= sec
->sh_size
;
9296 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
9301 aux
->table_len
= size
/ (3 * eh_addr_size
);
9302 aux
->table
= (struct ia64_unw_table_entry
*)
9303 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
9306 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
9308 tep
->start
.section
= SHN_UNDEF
;
9309 tep
->end
.section
= SHN_UNDEF
;
9310 tep
->info
.section
= SHN_UNDEF
;
9311 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
9312 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
9313 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
9314 tep
->start
.offset
+= aux
->seg_base
;
9315 tep
->end
.offset
+= aux
->seg_base
;
9316 tep
->info
.offset
+= aux
->seg_base
;
9320 /* Third, apply any relocations to the unwind table: */
9321 for (relsec
= filedata
->section_headers
;
9322 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9325 if (relsec
->sh_type
!= SHT_RELA
9326 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
9327 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
9330 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
9339 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
9341 unsigned int sym_ndx
;
9342 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
9343 relname
= elf_ia64_reloc_type (r_type
);
9345 /* PR 17531: file: 9fa67536. */
9346 if (relname
== NULL
)
9348 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
9352 if (! startswith (relname
, "R_IA64_SEGREL"))
9354 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
9358 i
= rp
->r_offset
/ (3 * eh_addr_size
);
9360 /* PR 17531: file: 5bc8d9bf. */
9361 if (i
>= aux
->table_len
)
9363 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
9368 sym_ndx
= get_reloc_symindex (rp
->r_info
);
9369 if (sym_ndx
>= aux
->nsyms
)
9371 warn (_("Skipping reloc with invalid symbol index: %u\n"),
9375 sym
= aux
->symtab
+ sym_ndx
;
9377 switch (rp
->r_offset
/ eh_addr_size
% 3)
9380 aux
->table
[i
].start
.section
= sym
->st_shndx
;
9381 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
9384 aux
->table
[i
].end
.section
= sym
->st_shndx
;
9385 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
9388 aux
->table
[i
].info
.section
= sym
->st_shndx
;
9389 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
9403 ia64_process_unwind (Filedata
* filedata
)
9405 Elf_Internal_Shdr
* sec
;
9406 Elf_Internal_Shdr
* unwsec
= NULL
;
9407 uint64_t i
, unwcount
= 0, unwstart
= 0;
9408 struct ia64_unw_aux_info aux
;
9411 memset (& aux
, 0, sizeof (aux
));
9413 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9415 if (sec
->sh_type
== SHT_SYMTAB
)
9419 error (_("Multiple symbol tables encountered\n"));
9425 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9426 &aux
.strtab
, &aux
.strtab_size
))
9429 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
9434 printf (_("\nThere are no unwind sections in this file.\n"));
9436 while (unwcount
-- > 0)
9441 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
9442 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9443 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
9448 /* We have already counted the number of SHT_IA64_UNWIND
9449 sections so the loop above should never fail. */
9450 assert (unwsec
!= NULL
);
9453 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
9455 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
9457 /* We need to find which section group it is in. */
9458 struct group_list
* g
;
9460 if (filedata
->section_headers_groups
== NULL
9461 || filedata
->section_headers_groups
[i
] == NULL
)
9462 i
= filedata
->file_header
.e_shnum
;
9465 g
= filedata
->section_headers_groups
[i
]->root
;
9467 for (; g
!= NULL
; g
= g
->next
)
9469 sec
= filedata
->section_headers
+ g
->section_index
;
9471 if (section_name_valid (filedata
, sec
)
9472 && streq (section_name (filedata
, sec
),
9473 ELF_STRING_ia64_unwind_info
))
9478 i
= filedata
->file_header
.e_shnum
;
9481 else if (section_name_valid (filedata
, unwsec
)
9482 && startswith (section_name (filedata
, unwsec
),
9483 ELF_STRING_ia64_unwind_once
))
9485 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
9486 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
9487 suffix
= section_name (filedata
, unwsec
) + len
;
9488 for (i
= 0, sec
= filedata
->section_headers
;
9489 i
< filedata
->file_header
.e_shnum
;
9491 if (section_name_valid (filedata
, sec
)
9492 && startswith (section_name (filedata
, sec
),
9493 ELF_STRING_ia64_unwind_info_once
)
9494 && streq (section_name (filedata
, sec
) + len2
, suffix
))
9499 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
9500 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
9501 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
9502 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
9504 if (section_name_valid (filedata
, unwsec
)
9505 && startswith (section_name (filedata
, unwsec
),
9506 ELF_STRING_ia64_unwind
))
9507 suffix
= section_name (filedata
, unwsec
) + len
;
9508 for (i
= 0, sec
= filedata
->section_headers
;
9509 i
< filedata
->file_header
.e_shnum
;
9511 if (section_name_valid (filedata
, sec
)
9512 && startswith (section_name (filedata
, sec
),
9513 ELF_STRING_ia64_unwind_info
)
9514 && streq (section_name (filedata
, sec
) + len2
, suffix
))
9518 if (i
== filedata
->file_header
.e_shnum
)
9520 printf (_("\nCould not find unwind info section for "));
9522 if (filedata
->string_table
== NULL
)
9523 printf ("%d", unwsec
->sh_name
);
9525 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9529 aux
.info_addr
= sec
->sh_addr
;
9530 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
9533 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
9535 printf (_("\nUnwind section "));
9537 if (filedata
->string_table
== NULL
)
9538 printf ("%d", unwsec
->sh_name
);
9540 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9542 printf (_(" at offset %#" PRIx64
" contains %" PRIu64
" entries:\n"),
9544 unwsec
->sh_size
/ (3 * eh_addr_size
));
9546 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
9547 && aux
.table_len
> 0)
9548 dump_ia64_unwind (filedata
, & aux
);
9550 free ((char *) aux
.table
);
9551 free ((char *) aux
.info
);
9558 free ((char *) aux
.strtab
);
9563 struct hppa_unw_table_entry
9565 struct absaddr start
;
9567 unsigned int Cannot_unwind
:1; /* 0 */
9568 unsigned int Millicode
:1; /* 1 */
9569 unsigned int Millicode_save_sr0
:1; /* 2 */
9570 unsigned int Region_description
:2; /* 3..4 */
9571 unsigned int reserved1
:1; /* 5 */
9572 unsigned int Entry_SR
:1; /* 6 */
9573 unsigned int Entry_FR
:4; /* Number saved 7..10 */
9574 unsigned int Entry_GR
:5; /* Number saved 11..15 */
9575 unsigned int Args_stored
:1; /* 16 */
9576 unsigned int Variable_Frame
:1; /* 17 */
9577 unsigned int Separate_Package_Body
:1; /* 18 */
9578 unsigned int Frame_Extension_Millicode
:1; /* 19 */
9579 unsigned int Stack_Overflow_Check
:1; /* 20 */
9580 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
9581 unsigned int Ada_Region
:1; /* 22 */
9582 unsigned int cxx_info
:1; /* 23 */
9583 unsigned int cxx_try_catch
:1; /* 24 */
9584 unsigned int sched_entry_seq
:1; /* 25 */
9585 unsigned int reserved2
:1; /* 26 */
9586 unsigned int Save_SP
:1; /* 27 */
9587 unsigned int Save_RP
:1; /* 28 */
9588 unsigned int Save_MRP_in_frame
:1; /* 29 */
9589 unsigned int extn_ptr_defined
:1; /* 30 */
9590 unsigned int Cleanup_defined
:1; /* 31 */
9592 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
9593 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
9594 unsigned int Large_frame
:1; /* 2 */
9595 unsigned int Pseudo_SP_Set
:1; /* 3 */
9596 unsigned int reserved4
:1; /* 4 */
9597 unsigned int Total_frame_size
:27; /* 5..31 */
9600 struct hppa_unw_aux_info
9602 struct hppa_unw_table_entry
* table
; /* Unwind table. */
9603 uint64_t table_len
; /* Length of unwind table. */
9604 uint64_t seg_base
; /* Starting address of segment. */
9605 Elf_Internal_Sym
* symtab
; /* The symbol table. */
9606 uint64_t nsyms
; /* Number of symbols. */
9607 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9608 uint64_t nfuns
; /* Number of entries in funtab. */
9609 char * strtab
; /* The string table. */
9610 uint64_t strtab_size
; /* Size of string table. */
9614 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
9616 struct hppa_unw_table_entry
* tp
;
9620 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9621 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9622 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9623 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9625 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9627 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
9630 const char * procname
;
9632 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9633 aux
->strtab_size
, tp
->start
, &procname
,
9636 fputs ("\n<", stdout
);
9640 fputs (procname
, stdout
);
9643 printf ("+%" PRIx64
, offset
);
9646 fputs (">: [", stdout
);
9647 print_vma (tp
->start
.offset
, PREFIX_HEX
);
9648 fputc ('-', stdout
);
9649 print_vma (tp
->end
.offset
, PREFIX_HEX
);
9652 #define PF(_m) if (tp->_m) printf (#_m " ");
9653 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
9656 PF(Millicode_save_sr0
);
9657 /* PV(Region_description); */
9663 PF(Separate_Package_Body
);
9664 PF(Frame_Extension_Millicode
);
9665 PF(Stack_Overflow_Check
);
9666 PF(Two_Instruction_SP_Increment
);
9670 PF(sched_entry_seq
);
9673 PF(Save_MRP_in_frame
);
9674 PF(extn_ptr_defined
);
9675 PF(Cleanup_defined
);
9676 PF(MPE_XL_interrupt_marker
);
9677 PF(HP_UX_interrupt_marker
);
9680 PV(Total_frame_size
);
9693 slurp_hppa_unwind_table (Filedata
* filedata
,
9694 struct hppa_unw_aux_info
* aux
,
9695 Elf_Internal_Shdr
* sec
)
9697 uint64_t size
, unw_ent_size
, nentries
, nrelas
, i
;
9698 Elf_Internal_Phdr
* seg
;
9699 struct hppa_unw_table_entry
* tep
;
9700 Elf_Internal_Shdr
* relsec
;
9701 Elf_Internal_Rela
* rela
;
9702 Elf_Internal_Rela
* rp
;
9703 unsigned char * table
;
9705 Elf_Internal_Sym
* sym
;
9706 const char * relname
;
9708 /* First, find the starting address of the segment that includes
9710 if (filedata
->file_header
.e_phnum
)
9712 if (! get_program_headers (filedata
))
9715 for (seg
= filedata
->program_headers
;
9716 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
9719 if (seg
->p_type
!= PT_LOAD
)
9722 if (sec
->sh_addr
>= seg
->p_vaddr
9723 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
9725 aux
->seg_base
= seg
->p_vaddr
;
9731 /* Second, build the unwind table from the contents of the unwind
9733 size
= sec
->sh_size
;
9734 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
9740 nentries
= size
/ unw_ent_size
;
9741 size
= unw_ent_size
* nentries
;
9743 aux
->table_len
= nentries
;
9744 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
9745 xcmalloc (nentries
, sizeof (aux
->table
[0]));
9747 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
9749 unsigned int tmp1
, tmp2
;
9751 tep
->start
.section
= SHN_UNDEF
;
9752 tep
->end
.section
= SHN_UNDEF
;
9754 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
9755 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
9756 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
9757 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
9759 tep
->start
.offset
+= aux
->seg_base
;
9760 tep
->end
.offset
+= aux
->seg_base
;
9762 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
9763 tep
->Millicode
= (tmp1
>> 30) & 0x1;
9764 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
9765 tep
->Region_description
= (tmp1
>> 27) & 0x3;
9766 tep
->reserved1
= (tmp1
>> 26) & 0x1;
9767 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
9768 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
9769 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
9770 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
9771 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
9772 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
9773 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
9774 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
9775 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
9776 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
9777 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
9778 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
9779 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
9780 tep
->reserved2
= (tmp1
>> 5) & 0x1;
9781 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
9782 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
9783 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
9784 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
9785 tep
->Cleanup_defined
= tmp1
& 0x1;
9787 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
9788 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
9789 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
9790 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
9791 tep
->reserved4
= (tmp2
>> 27) & 0x1;
9792 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
9796 /* Third, apply any relocations to the unwind table. */
9797 for (relsec
= filedata
->section_headers
;
9798 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9801 if (relsec
->sh_type
!= SHT_RELA
9802 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
9803 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
9806 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
9810 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
9812 unsigned int sym_ndx
;
9813 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
9814 relname
= elf_hppa_reloc_type (r_type
);
9816 if (relname
== NULL
)
9818 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
9822 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
9823 if (! startswith (relname
, "R_PARISC_SEGREL"))
9825 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
9829 i
= rp
->r_offset
/ unw_ent_size
;
9830 if (i
>= aux
->table_len
)
9832 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
9837 sym_ndx
= get_reloc_symindex (rp
->r_info
);
9838 if (sym_ndx
>= aux
->nsyms
)
9840 warn (_("Skipping reloc with invalid symbol index: %u\n"),
9844 sym
= aux
->symtab
+ sym_ndx
;
9846 switch ((rp
->r_offset
% unw_ent_size
) / 4)
9849 aux
->table
[i
].start
.section
= sym
->st_shndx
;
9850 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
9853 aux
->table
[i
].end
.section
= sym
->st_shndx
;
9854 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
9868 hppa_process_unwind (Filedata
* filedata
)
9870 struct hppa_unw_aux_info aux
;
9871 Elf_Internal_Shdr
* unwsec
= NULL
;
9872 Elf_Internal_Shdr
* sec
;
9876 if (filedata
->string_table
== NULL
)
9879 memset (& aux
, 0, sizeof (aux
));
9881 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9883 if (sec
->sh_type
== SHT_SYMTAB
)
9887 error (_("Multiple symbol tables encountered\n"));
9893 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9894 &aux
.strtab
, &aux
.strtab_size
))
9897 else if (section_name_valid (filedata
, sec
)
9898 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9903 printf (_("\nThere are no unwind sections in this file.\n"));
9905 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9907 if (section_name_valid (filedata
, sec
)
9908 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9910 uint64_t num_unwind
= sec
->sh_size
/ 16;
9912 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
9913 "contains %" PRIu64
" entry:\n",
9914 "\nUnwind section '%s' at offset %#" PRIx64
" "
9915 "contains %" PRIu64
" entries:\n",
9917 printable_section_name (filedata
, sec
),
9921 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
9924 if (res
&& aux
.table_len
> 0)
9926 if (! dump_hppa_unwind (filedata
, &aux
))
9930 free ((char *) aux
.table
);
9936 free ((char *) aux
.strtab
);
9943 unsigned char * data
; /* The unwind data. */
9944 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
9945 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
9946 uint64_t nrelas
; /* The number of relocations. */
9947 unsigned int rel_type
; /* REL or RELA ? */
9948 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
9951 struct arm_unw_aux_info
9953 Filedata
* filedata
; /* The file containing the unwind sections. */
9954 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
9955 uint64_t nsyms
; /* Number of symbols. */
9956 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9957 uint64_t nfuns
; /* Number of these symbols. */
9958 char * strtab
; /* The file's string table. */
9959 uint64_t strtab_size
; /* Size of string table. */
9963 arm_print_vma_and_name (Filedata
* filedata
,
9964 struct arm_unw_aux_info
* aux
,
9966 struct absaddr addr
)
9968 const char *procname
;
9969 uint64_t sym_offset
;
9971 if (addr
.section
== SHN_UNDEF
)
9974 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9975 aux
->strtab_size
, addr
, &procname
,
9978 print_vma (fn
, PREFIX_HEX
);
9982 fputs (" <", stdout
);
9983 fputs (procname
, stdout
);
9986 printf ("+0x%" PRIx64
, sym_offset
);
9987 fputc ('>', stdout
);
9994 arm_free_section (struct arm_section
*arm_sec
)
9996 free (arm_sec
->data
);
9997 free (arm_sec
->rela
);
10000 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
10001 cached section and install SEC instead.
10002 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
10003 and return its valued in * WORDP, relocating if necessary.
10004 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
10005 relocation's offset in ADDR.
10006 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
10007 into the string table of the symbol associated with the reloc. If no
10008 reloc was applied store -1 there.
10009 5) Return TRUE upon success, FALSE otherwise. */
10012 get_unwind_section_word (Filedata
* filedata
,
10013 struct arm_unw_aux_info
* aux
,
10014 struct arm_section
* arm_sec
,
10015 Elf_Internal_Shdr
* sec
,
10016 uint64_t word_offset
,
10017 unsigned int * wordp
,
10018 struct absaddr
* addr
,
10019 uint64_t * sym_name
)
10021 Elf_Internal_Rela
*rp
;
10022 Elf_Internal_Sym
*sym
;
10023 const char * relname
;
10027 if (sec
== NULL
|| arm_sec
== NULL
)
10030 addr
->section
= SHN_UNDEF
;
10033 if (sym_name
!= NULL
)
10034 *sym_name
= (uint64_t) -1;
10036 /* If necessary, update the section cache. */
10037 if (sec
!= arm_sec
->sec
)
10039 Elf_Internal_Shdr
*relsec
;
10041 arm_free_section (arm_sec
);
10043 arm_sec
->sec
= sec
;
10044 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
10045 sec
->sh_size
, _("unwind data"));
10046 arm_sec
->rela
= NULL
;
10047 arm_sec
->nrelas
= 0;
10049 for (relsec
= filedata
->section_headers
;
10050 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
10053 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
10054 || filedata
->section_headers
+ relsec
->sh_info
!= sec
10055 /* PR 15745: Check the section type as well. */
10056 || (relsec
->sh_type
!= SHT_REL
10057 && relsec
->sh_type
!= SHT_RELA
))
10060 arm_sec
->rel_type
= relsec
->sh_type
;
10061 if (relsec
->sh_type
== SHT_REL
)
10063 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
10065 & arm_sec
->rela
, & arm_sec
->nrelas
))
10068 else /* relsec->sh_type == SHT_RELA */
10070 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
10072 & arm_sec
->rela
, & arm_sec
->nrelas
))
10078 arm_sec
->next_rela
= arm_sec
->rela
;
10081 /* If there is no unwind data we can do nothing. */
10082 if (arm_sec
->data
== NULL
)
10085 /* If the offset is invalid then fail. */
10086 if (/* PR 21343 *//* PR 18879 */
10088 || word_offset
> sec
->sh_size
- 4)
10091 /* Get the word at the required offset. */
10092 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
10094 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
10095 if (arm_sec
->rela
== NULL
)
10101 /* Look through the relocs to find the one that applies to the provided offset. */
10103 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
10105 uint64_t prelval
, offset
;
10107 if (rp
->r_offset
> word_offset
&& !wrapped
)
10109 rp
= arm_sec
->rela
;
10112 if (rp
->r_offset
> word_offset
)
10115 if (rp
->r_offset
& 3)
10117 warn (_("Skipping unexpected relocation at offset %#" PRIx64
"\n"),
10122 if (rp
->r_offset
< word_offset
)
10125 /* PR 17531: file: 027-161405-0.004 */
10126 if (aux
->symtab
== NULL
)
10129 if (arm_sec
->rel_type
== SHT_REL
)
10131 offset
= word
& 0x7fffffff;
10132 if (offset
& 0x40000000)
10133 offset
|= ~ (uint64_t) 0x7fffffff;
10135 else if (arm_sec
->rel_type
== SHT_RELA
)
10136 offset
= rp
->r_addend
;
10139 error (_("Unknown section relocation type %d encountered\n"),
10140 arm_sec
->rel_type
);
10144 /* PR 17531 file: 027-1241568-0.004. */
10145 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
10147 error (_("Bad symbol index in unwind relocation "
10148 "(%" PRIu64
" > %" PRIu64
")\n"),
10149 ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
10153 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
10154 offset
+= sym
->st_value
;
10155 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
10157 /* Check that we are processing the expected reloc type. */
10158 if (filedata
->file_header
.e_machine
== EM_ARM
)
10160 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
10161 if (relname
== NULL
)
10163 warn (_("Skipping unknown ARM relocation type: %d\n"),
10164 (int) ELF32_R_TYPE (rp
->r_info
));
10168 if (streq (relname
, "R_ARM_NONE"))
10171 if (! streq (relname
, "R_ARM_PREL31"))
10173 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
10177 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
10179 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
10180 if (relname
== NULL
)
10182 warn (_("Skipping unknown C6000 relocation type: %d\n"),
10183 (int) ELF32_R_TYPE (rp
->r_info
));
10187 if (streq (relname
, "R_C6000_NONE"))
10190 if (! streq (relname
, "R_C6000_PREL31"))
10192 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
10200 /* This function currently only supports ARM and TI unwinders. */
10201 warn (_("Only TI and ARM unwinders are currently supported\n"));
10205 word
= (word
& ~ (uint64_t) 0x7fffffff) | (prelval
& 0x7fffffff);
10206 addr
->section
= sym
->st_shndx
;
10207 addr
->offset
= offset
;
10210 * sym_name
= sym
->st_name
;
10215 arm_sec
->next_rela
= rp
;
10220 static const char *tic6x_unwind_regnames
[16] =
10222 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
10223 "A14", "A13", "A12", "A11", "A10",
10224 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
10228 decode_tic6x_unwind_regmask (unsigned int mask
)
10232 for (i
= 12; mask
; mask
>>= 1, i
--)
10236 fputs (tic6x_unwind_regnames
[i
], stdout
);
10238 fputs (", ", stdout
);
10244 if (remaining == 0 && more_words) \
10246 data_offset += 4; \
10247 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
10248 data_offset, & word, & addr, NULL)) \
10254 #define GET_OP(OP) \
10259 (OP) = word >> 24; \
10264 printf (_("[Truncated opcode]\n")); \
10267 printf ("0x%02x ", OP)
10270 decode_arm_unwind_bytecode (Filedata
* filedata
,
10271 struct arm_unw_aux_info
* aux
,
10273 unsigned int remaining
,
10274 unsigned int more_words
,
10275 uint64_t data_offset
,
10276 Elf_Internal_Shdr
* data_sec
,
10277 struct arm_section
* data_arm_sec
)
10279 struct absaddr addr
;
10282 /* Decode the unwinding instructions. */
10285 unsigned int op
, op2
;
10288 if (remaining
== 0)
10294 printf (" 0x%02x ", op
);
10296 if ((op
& 0xc0) == 0x00)
10298 int offset
= ((op
& 0x3f) << 2) + 4;
10300 printf (" vsp = vsp + %d", offset
);
10302 else if ((op
& 0xc0) == 0x40)
10304 int offset
= ((op
& 0x3f) << 2) + 4;
10306 printf (" vsp = vsp - %d", offset
);
10308 else if ((op
& 0xf0) == 0x80)
10311 if (op
== 0x80 && op2
== 0)
10312 printf (_("Refuse to unwind"));
10315 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
10320 for (i
= 0; i
< 12; i
++)
10321 if (mask
& (1 << i
))
10327 printf ("r%d", 4 + i
);
10332 else if ((op
& 0xf0) == 0x90)
10334 if (op
== 0x9d || op
== 0x9f)
10335 printf (_(" [Reserved]"));
10337 printf (" vsp = r%d", op
& 0x0f);
10339 else if ((op
& 0xf0) == 0xa0)
10341 int end
= 4 + (op
& 0x07);
10346 for (i
= 4; i
<= end
; i
++)
10362 else if (op
== 0xb0)
10363 printf (_(" finish"));
10364 else if (op
== 0xb1)
10367 if (op2
== 0 || (op2
& 0xf0) != 0)
10368 printf (_("[Spare]"));
10371 unsigned int mask
= op2
& 0x0f;
10376 for (i
= 0; i
< 12; i
++)
10377 if (mask
& (1 << i
))
10388 else if (op
== 0xb2)
10390 unsigned char buf
[9];
10391 unsigned int i
, len
;
10394 for (i
= 0; i
< sizeof (buf
); i
++)
10397 if ((buf
[i
] & 0x80) == 0)
10400 if (i
== sizeof (buf
))
10402 error (_("corrupt change to vsp\n"));
10407 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
10408 assert (len
== i
+ 1);
10409 offset
= offset
* 4 + 0x204;
10410 printf ("vsp = vsp + %" PRId64
, offset
);
10413 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
10415 unsigned int first
, last
;
10421 first
= first
+ 16;
10422 printf ("pop {D%d", first
);
10424 printf ("-D%d", first
+ last
);
10427 else if (op
== 0xb4)
10428 printf (_(" pop {ra_auth_code}"));
10429 else if (op
== 0xb5)
10430 printf (_(" vsp as modifier for PAC validation"));
10431 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
10433 unsigned int count
= op
& 0x07;
10435 printf ("pop {D8");
10437 printf ("-D%d", 8 + count
);
10440 else if (op
>= 0xc0 && op
<= 0xc5)
10442 unsigned int count
= op
& 0x07;
10444 printf (" pop {wR10");
10446 printf ("-wR%d", 10 + count
);
10449 else if (op
== 0xc6)
10451 unsigned int first
, last
;
10456 printf ("pop {wR%d", first
);
10458 printf ("-wR%d", first
+ last
);
10461 else if (op
== 0xc7)
10464 if (op2
== 0 || (op2
& 0xf0) != 0)
10465 printf (_("[Spare]"));
10468 unsigned int mask
= op2
& 0x0f;
10473 for (i
= 0; i
< 4; i
++)
10474 if (mask
& (1 << i
))
10480 printf ("wCGR%d", i
);
10487 printf (_(" [unsupported opcode]"));
10498 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
10499 struct arm_unw_aux_info
* aux
,
10501 unsigned int remaining
,
10502 unsigned int more_words
,
10503 uint64_t data_offset
,
10504 Elf_Internal_Shdr
* data_sec
,
10505 struct arm_section
* data_arm_sec
)
10507 struct absaddr addr
;
10509 /* Decode the unwinding instructions. */
10512 unsigned int op
, op2
;
10515 if (remaining
== 0)
10521 printf (" 0x%02x ", op
);
10523 if ((op
& 0xc0) == 0x00)
10525 int offset
= ((op
& 0x3f) << 3) + 8;
10526 printf (" sp = sp + %d", offset
);
10528 else if ((op
& 0xc0) == 0x80)
10531 if (op
== 0x80 && op2
== 0)
10532 printf (_("Refuse to unwind"));
10535 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
10537 printf ("pop compact {");
10541 decode_tic6x_unwind_regmask (mask
);
10545 else if ((op
& 0xf0) == 0xc0)
10548 unsigned int nregs
;
10553 unsigned int offset
;
10557 /* Scan entire instruction first so that GET_OP output is not
10558 interleaved with disassembly. */
10560 for (i
= 0; nregs
< (op
& 0xf); i
++)
10566 regpos
[nregs
].offset
= i
* 2;
10567 regpos
[nregs
].reg
= reg
;
10574 regpos
[nregs
].offset
= i
* 2 + 1;
10575 regpos
[nregs
].reg
= reg
;
10580 printf (_("pop frame {"));
10583 printf (_("*corrupt* - no registers specified"));
10588 for (i
= i
* 2; i
> 0; i
--)
10590 if (regpos
[reg
].offset
== i
- 1)
10592 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
10599 fputs (name
, stdout
);
10607 else if (op
== 0xd0)
10608 printf (" MOV FP, SP");
10609 else if (op
== 0xd1)
10610 printf (" __c6xabi_pop_rts");
10611 else if (op
== 0xd2)
10613 unsigned char buf
[9];
10614 unsigned int i
, len
;
10617 for (i
= 0; i
< sizeof (buf
); i
++)
10620 if ((buf
[i
] & 0x80) == 0)
10623 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
10624 if (i
== sizeof (buf
))
10626 warn (_("Corrupt stack pointer adjustment detected\n"));
10630 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
10631 assert (len
== i
+ 1);
10632 offset
= offset
* 8 + 0x408;
10633 printf (_("sp = sp + %" PRId64
), offset
);
10635 else if ((op
& 0xf0) == 0xe0)
10637 if ((op
& 0x0f) == 7)
10638 printf (" RETURN");
10640 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
10644 printf (_(" [unsupported opcode]"));
10653 arm_expand_prel31 (Filedata
* filedata
, uint64_t word
, uint64_t where
)
10657 offset
= word
& 0x7fffffff;
10658 if (offset
& 0x40000000)
10659 offset
|= ~ (uint64_t) 0x7fffffff;
10661 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
10664 return offset
+ where
;
10668 decode_arm_unwind (Filedata
* filedata
,
10669 struct arm_unw_aux_info
* aux
,
10671 unsigned int remaining
,
10672 uint64_t data_offset
,
10673 Elf_Internal_Shdr
* data_sec
,
10674 struct arm_section
* data_arm_sec
)
10677 unsigned int more_words
= 0;
10678 struct absaddr addr
;
10679 uint64_t sym_name
= (uint64_t) -1;
10682 if (remaining
== 0)
10684 /* Fetch the first word.
10685 Note - when decoding an object file the address extracted
10686 here will always be 0. So we also pass in the sym_name
10687 parameter so that we can find the symbol associated with
10688 the personality routine. */
10689 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
10690 & word
, & addr
, & sym_name
))
10697 addr
.section
= SHN_UNDEF
;
10701 if ((word
& 0x80000000) == 0)
10703 /* Expand prel31 for personality routine. */
10705 const char *procname
;
10707 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
10708 printf (_(" Personality routine: "));
10710 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
10711 && sym_name
!= (uint64_t) -1 && sym_name
< aux
->strtab_size
)
10713 procname
= aux
->strtab
+ sym_name
;
10714 print_vma (fn
, PREFIX_HEX
);
10717 fputs (" <", stdout
);
10718 fputs (procname
, stdout
);
10719 fputc ('>', stdout
);
10723 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
10724 fputc ('\n', stdout
);
10726 /* The GCC personality routines use the standard compact
10727 encoding, starting with one byte giving the number of
10729 if (procname
!= NULL
10730 && (startswith (procname
, "__gcc_personality_v0")
10731 || startswith (procname
, "__gxx_personality_v0")
10732 || startswith (procname
, "__gcj_personality_v0")
10733 || startswith (procname
, "__gnu_objc_personality_v0")))
10740 printf (_(" [Truncated data]\n"));
10743 more_words
= word
>> 24;
10753 /* ARM EHABI Section 6.3:
10755 An exception-handling table entry for the compact model looks like:
10757 31 30-28 27-24 23-0
10758 -- ----- ----- ----
10759 1 0 index Data for personalityRoutine[index] */
10761 if (filedata
->file_header
.e_machine
== EM_ARM
10762 && (word
& 0x70000000))
10764 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
10768 per_index
= (word
>> 24) & 0x7f;
10769 printf (_(" Compact model index: %d\n"), per_index
);
10770 if (per_index
== 0)
10776 else if (per_index
< 3)
10778 more_words
= (word
>> 16) & 0xff;
10784 switch (filedata
->file_header
.e_machine
)
10789 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10790 data_offset
, data_sec
, data_arm_sec
))
10795 warn (_("Unknown ARM compact model index encountered\n"));
10796 printf (_(" [reserved]\n"));
10804 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10805 data_offset
, data_sec
, data_arm_sec
))
10808 else if (per_index
< 5)
10810 if (((word
>> 17) & 0x7f) == 0x7f)
10811 printf (_(" Restore stack from frame pointer\n"));
10813 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
10814 printf (_(" Registers restored: "));
10815 if (per_index
== 4)
10816 printf (" (compact) ");
10817 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
10819 printf (_(" Return register: %s\n"),
10820 tic6x_unwind_regnames
[word
& 0xf]);
10823 printf (_(" [reserved (%d)]\n"), per_index
);
10827 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
10828 filedata
->file_header
.e_machine
);
10832 /* Decode the descriptors. Not implemented. */
10838 dump_arm_unwind (Filedata
* filedata
,
10839 struct arm_unw_aux_info
* aux
,
10840 Elf_Internal_Shdr
* exidx_sec
)
10842 struct arm_section exidx_arm_sec
, extab_arm_sec
;
10843 unsigned int i
, exidx_len
;
10847 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
10848 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
10849 exidx_len
= exidx_sec
->sh_size
/ 8;
10851 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
10852 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
10853 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
10854 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
10855 aux
->nfuns
= nfuns
;
10856 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
10858 for (i
= 0; i
< exidx_len
; i
++)
10860 unsigned int exidx_fn
, exidx_entry
;
10861 struct absaddr fn_addr
, entry_addr
;
10864 fputc ('\n', stdout
);
10866 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10867 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
10868 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10869 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
10871 free (aux
->funtab
);
10872 arm_free_section (& exidx_arm_sec
);
10873 arm_free_section (& extab_arm_sec
);
10877 /* ARM EHABI, Section 5:
10878 An index table entry consists of 2 words.
10879 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
10880 if (exidx_fn
& 0x80000000)
10882 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
10886 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
10888 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
10889 fputs (": ", stdout
);
10891 if (exidx_entry
== 1)
10893 print_vma (exidx_entry
, PREFIX_HEX
);
10894 fputs (" [cantunwind]\n", stdout
);
10896 else if (exidx_entry
& 0x80000000)
10898 print_vma (exidx_entry
, PREFIX_HEX
);
10899 fputc ('\n', stdout
);
10900 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
10904 uint64_t table
, table_offset
= 0;
10905 Elf_Internal_Shdr
*table_sec
;
10907 fputs ("@", stdout
);
10908 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
10909 print_vma (table
, PREFIX_HEX
);
10912 /* Locate the matching .ARM.extab. */
10913 if (entry_addr
.section
!= SHN_UNDEF
10914 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
10916 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
10917 table_offset
= entry_addr
.offset
;
10919 if (table_offset
> table_sec
->sh_size
)
10921 warn (_("Unwind entry contains corrupt offset (%#" PRIx64
") into section %s\n"),
10923 printable_section_name (filedata
, table_sec
));
10930 table_sec
= find_section_by_address (filedata
, table
);
10931 if (table_sec
!= NULL
)
10932 table_offset
= table
- table_sec
->sh_addr
;
10935 if (table_sec
== NULL
)
10937 warn (_("Could not locate .ARM.extab section containing %#" PRIx64
".\n"),
10943 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
10951 free (aux
->funtab
);
10952 arm_free_section (&exidx_arm_sec
);
10953 arm_free_section (&extab_arm_sec
);
10958 /* Used for both ARM and C6X unwinding tables. */
10961 arm_process_unwind (Filedata
* filedata
)
10963 struct arm_unw_aux_info aux
;
10964 Elf_Internal_Shdr
*unwsec
= NULL
;
10965 Elf_Internal_Shdr
*sec
;
10967 unsigned int sec_type
;
10970 switch (filedata
->file_header
.e_machine
)
10973 sec_type
= SHT_ARM_EXIDX
;
10977 sec_type
= SHT_C6000_UNWIND
;
10981 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
10982 filedata
->file_header
.e_machine
);
10986 if (filedata
->string_table
== NULL
)
10989 memset (& aux
, 0, sizeof (aux
));
10990 aux
.filedata
= filedata
;
10992 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10994 if (sec
->sh_type
== SHT_SYMTAB
)
10998 error (_("Multiple symbol tables encountered\n"));
11004 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
11005 &aux
.strtab
, &aux
.strtab_size
))
11008 else if (sec
->sh_type
== sec_type
)
11012 if (unwsec
== NULL
)
11013 printf (_("\nThere are no unwind sections in this file.\n"));
11015 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
11017 if (sec
->sh_type
== sec_type
)
11019 uint64_t num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
11020 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
11021 "contains %" PRIu64
" entry:\n",
11022 "\nUnwind section '%s' at offset %#" PRIx64
" "
11023 "contains %" PRIu64
" entries:\n",
11025 printable_section_name (filedata
, sec
),
11029 if (! dump_arm_unwind (filedata
, &aux
, sec
))
11035 free ((char *) aux
.strtab
);
11041 no_processor_specific_unwind (Filedata
* filedata ATTRIBUTE_UNUSED
)
11043 printf (_("No processor specific unwind information to decode\n"));
11048 process_unwind (Filedata
* filedata
)
11050 struct unwind_handler
11052 unsigned int machtype
;
11053 bool (* handler
)(Filedata
*);
11056 { EM_ARM
, arm_process_unwind
},
11057 { EM_IA_64
, ia64_process_unwind
},
11058 { EM_PARISC
, hppa_process_unwind
},
11059 { EM_TI_C6000
, arm_process_unwind
},
11060 { EM_386
, no_processor_specific_unwind
},
11061 { EM_X86_64
, no_processor_specific_unwind
},
11069 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
11070 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
11071 return handlers
[i
].handler (filedata
);
11073 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
11074 get_machine_name (filedata
->file_header
.e_machine
));
11079 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
11081 switch (entry
->d_tag
)
11083 case DT_AARCH64_BTI_PLT
:
11084 case DT_AARCH64_PAC_PLT
:
11087 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11094 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
11096 switch (entry
->d_tag
)
11098 case DT_MIPS_FLAGS
:
11099 if (entry
->d_un
.d_val
== 0)
11100 printf (_("NONE"));
11103 static const char * opts
[] =
11105 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
11106 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
11107 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
11108 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
11114 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
11115 if (entry
->d_un
.d_val
& (1 << cnt
))
11117 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
11123 case DT_MIPS_IVERSION
:
11124 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11125 printf (_("Interface Version: %s"),
11126 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
11128 printf (_("Interface Version: <corrupt: %" PRIx64
">"),
11129 entry
->d_un
.d_ptr
);
11132 case DT_MIPS_TIME_STAMP
:
11136 time_t atime
= entry
->d_un
.d_val
;
11138 tmp
= gmtime (&atime
);
11139 /* PR 17531: file: 6accc532. */
11141 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
11143 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
11144 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11145 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11146 printf (_("Time Stamp: %s"), timebuf
);
11150 case DT_MIPS_RLD_VERSION
:
11151 case DT_MIPS_LOCAL_GOTNO
:
11152 case DT_MIPS_CONFLICTNO
:
11153 case DT_MIPS_LIBLISTNO
:
11154 case DT_MIPS_SYMTABNO
:
11155 case DT_MIPS_UNREFEXTNO
:
11156 case DT_MIPS_HIPAGENO
:
11157 case DT_MIPS_DELTA_CLASS_NO
:
11158 case DT_MIPS_DELTA_INSTANCE_NO
:
11159 case DT_MIPS_DELTA_RELOC_NO
:
11160 case DT_MIPS_DELTA_SYM_NO
:
11161 case DT_MIPS_DELTA_CLASSSYM_NO
:
11162 case DT_MIPS_COMPACT_SIZE
:
11163 print_vma (entry
->d_un
.d_val
, DEC
);
11166 case DT_MIPS_XHASH
:
11167 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
11168 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11169 /* Falls through. */
11172 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11178 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
11180 switch (entry
->d_tag
)
11182 case DT_HP_DLD_FLAGS
:
11191 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
11192 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
11193 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
11194 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
11195 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
11196 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
11197 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
11198 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
11199 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
11200 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
11201 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
11202 { DT_HP_GST
, "HP_GST" },
11203 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
11204 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
11205 { DT_HP_NODELETE
, "HP_NODELETE" },
11206 { DT_HP_GROUP
, "HP_GROUP" },
11207 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
11211 uint64_t val
= entry
->d_un
.d_val
;
11213 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
11214 if (val
& flags
[cnt
].bit
)
11218 fputs (flags
[cnt
].str
, stdout
);
11220 val
^= flags
[cnt
].bit
;
11223 if (val
!= 0 || first
)
11227 print_vma (val
, HEX
);
11233 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11239 /* VMS vs Unix time offset and factor. */
11241 #define VMS_EPOCH_OFFSET 35067168000000000LL
11242 #define VMS_GRANULARITY_FACTOR 10000000
11244 #define INT64_MIN (-9223372036854775807LL - 1)
11247 /* Display a VMS time in a human readable format. */
11250 print_vms_time (int64_t vmstime
)
11252 struct tm
*tm
= NULL
;
11255 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
11257 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
11259 if (unxtime
== vmstime
)
11260 tm
= gmtime (&unxtime
);
11263 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
11264 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
11265 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
11269 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
11271 switch (entry
->d_tag
)
11273 case DT_IA_64_PLT_RESERVE
:
11274 /* First 3 slots reserved. */
11275 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11277 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
11280 case DT_IA_64_VMS_LINKTIME
:
11281 print_vms_time (entry
->d_un
.d_val
);
11284 case DT_IA_64_VMS_LNKFLAGS
:
11285 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11286 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
11287 printf (" CALL_DEBUG");
11288 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
11289 printf (" NOP0BUFS");
11290 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
11291 printf (" P0IMAGE");
11292 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
11293 printf (" MKTHREADS");
11294 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
11295 printf (" UPCALLS");
11296 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
11297 printf (" IMGSTA");
11298 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
11299 printf (" INITIALIZE");
11300 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
11302 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
11303 printf (" EXE_INIT");
11304 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
11305 printf (" TBK_IN_IMG");
11306 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
11307 printf (" DBG_IN_IMG");
11308 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
11309 printf (" TBK_IN_DSF");
11310 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
11311 printf (" DBG_IN_DSF");
11312 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
11313 printf (" SIGNATURES");
11314 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
11315 printf (" REL_SEG_OFF");
11319 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
11326 get_32bit_dynamic_section (Filedata
* filedata
)
11328 Elf32_External_Dyn
* edyn
;
11329 Elf32_External_Dyn
* ext
;
11330 Elf_Internal_Dyn
* entry
;
11332 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
11333 filedata
->dynamic_addr
, 1,
11334 filedata
->dynamic_size
,
11335 _("dynamic section"));
11339 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
11340 might not have the luxury of section headers. Look for the DT_NULL
11341 terminator to determine the number of entries. */
11342 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
11343 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
11346 filedata
->dynamic_nent
++;
11347 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
11351 filedata
->dynamic_section
11352 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
11353 if (filedata
->dynamic_section
== NULL
)
11355 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
11356 filedata
->dynamic_nent
);
11361 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
11362 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11365 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
11366 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
11375 get_64bit_dynamic_section (Filedata
* filedata
)
11377 Elf64_External_Dyn
* edyn
;
11378 Elf64_External_Dyn
* ext
;
11379 Elf_Internal_Dyn
* entry
;
11381 /* Read in the data. */
11382 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
11383 filedata
->dynamic_addr
, 1,
11384 filedata
->dynamic_size
,
11385 _("dynamic section"));
11389 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
11390 might not have the luxury of section headers. Look for the DT_NULL
11391 terminator to determine the number of entries. */
11392 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
11393 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
11394 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
11397 filedata
->dynamic_nent
++;
11398 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
11402 filedata
->dynamic_section
11403 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
11404 if (filedata
->dynamic_section
== NULL
)
11406 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
11407 filedata
->dynamic_nent
);
11412 /* Convert from external to internal formats. */
11413 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
11414 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11417 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
11418 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
11427 get_dynamic_section (Filedata
*filedata
)
11429 if (filedata
->dynamic_section
)
11433 return get_32bit_dynamic_section (filedata
);
11435 return get_64bit_dynamic_section (filedata
);
11439 print_dynamic_flags (uint64_t flags
)
11447 flag
= flags
& - flags
;
11453 putc (' ', stdout
);
11457 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
11458 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
11459 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
11460 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
11461 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
11462 default: fputs (_("unknown"), stdout
); break;
11469 get_dynamic_data (Filedata
* filedata
, uint64_t number
, unsigned int ent_size
)
11471 unsigned char * e_data
;
11474 /* If size_t is smaller than uint64_t, eg because you are building
11475 on a 32-bit host, then make sure that when number is cast to
11476 size_t no information is lost. */
11477 if ((size_t) number
!= number
11478 || ent_size
* number
/ ent_size
!= number
)
11480 error (_("Size overflow prevents reading %" PRIu64
11481 " elements of size %u\n"),
11486 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
11487 attempting to allocate memory when the read is bound to fail. */
11488 if (ent_size
* number
> filedata
->file_size
)
11490 error (_("Invalid number of dynamic entries: %" PRIu64
"\n"),
11495 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
11496 if (e_data
== NULL
)
11498 error (_("Out of memory reading %" PRIu64
" dynamic entries\n"),
11503 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
11505 error (_("Unable to read in %" PRIu64
" bytes of dynamic data\n"),
11506 number
* ent_size
);
11511 i_data
= (uint64_t *) cmalloc ((size_t) number
, sizeof (*i_data
));
11512 if (i_data
== NULL
)
11514 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
11521 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
11529 get_num_dynamic_syms (Filedata
* filedata
)
11531 uint64_t num_of_syms
= 0;
11533 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
11534 return num_of_syms
;
11536 if (filedata
->dynamic_info
[DT_HASH
])
11538 unsigned char nb
[8];
11539 unsigned char nc
[8];
11540 unsigned int hash_ent_size
= 4;
11542 if ((filedata
->file_header
.e_machine
== EM_ALPHA
11543 || filedata
->file_header
.e_machine
== EM_S390
11544 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
11545 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
11548 if (fseek64 (filedata
->handle
,
11549 (filedata
->archive_file_offset
11550 + offset_from_vma (filedata
,
11551 filedata
->dynamic_info
[DT_HASH
],
11552 sizeof nb
+ sizeof nc
)),
11555 error (_("Unable to seek to start of dynamic information\n"));
11559 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
11561 error (_("Failed to read in number of buckets\n"));
11565 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
11567 error (_("Failed to read in number of chains\n"));
11571 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
11572 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
11574 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
11576 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
11578 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
11581 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
11582 num_of_syms
= filedata
->nchains
;
11585 if (num_of_syms
== 0)
11587 free (filedata
->buckets
);
11588 filedata
->buckets
= NULL
;
11589 free (filedata
->chains
);
11590 filedata
->chains
= NULL
;
11591 filedata
->nbuckets
= 0;
11595 if (filedata
->dynamic_info_DT_GNU_HASH
)
11597 unsigned char nb
[16];
11598 uint64_t i
, maxchain
= 0xffffffff, bitmaskwords
;
11599 uint64_t buckets_vma
;
11602 if (fseek64 (filedata
->handle
,
11603 (filedata
->archive_file_offset
11604 + offset_from_vma (filedata
,
11605 filedata
->dynamic_info_DT_GNU_HASH
,
11609 error (_("Unable to seek to start of dynamic information\n"));
11613 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
11615 error (_("Failed to read in number of buckets\n"));
11619 filedata
->ngnubuckets
= byte_get (nb
, 4);
11620 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
11621 bitmaskwords
= byte_get (nb
+ 8, 4);
11622 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
11624 buckets_vma
+= bitmaskwords
* 4;
11626 buckets_vma
+= bitmaskwords
* 8;
11628 if (fseek64 (filedata
->handle
,
11629 (filedata
->archive_file_offset
11630 + offset_from_vma (filedata
, buckets_vma
, 4)),
11633 error (_("Unable to seek to start of dynamic information\n"));
11637 filedata
->gnubuckets
11638 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
11640 if (filedata
->gnubuckets
== NULL
)
11643 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
11644 if (filedata
->gnubuckets
[i
] != 0)
11646 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
11649 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
11650 maxchain
= filedata
->gnubuckets
[i
];
11653 if (maxchain
== 0xffffffff)
11656 maxchain
-= filedata
->gnusymidx
;
11658 if (fseek64 (filedata
->handle
,
11659 (filedata
->archive_file_offset
11660 + offset_from_vma (filedata
,
11661 buckets_vma
+ 4 * (filedata
->ngnubuckets
11666 error (_("Unable to seek to start of dynamic information\n"));
11672 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
11674 error (_("Failed to determine last chain length\n"));
11678 if (maxchain
+ 1 == 0)
11683 while ((byte_get (nb
, 4) & 1) == 0);
11685 if (fseek64 (filedata
->handle
,
11686 (filedata
->archive_file_offset
11687 + offset_from_vma (filedata
, (buckets_vma
11688 + 4 * filedata
->ngnubuckets
),
11692 error (_("Unable to seek to start of dynamic information\n"));
11696 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
11697 filedata
->ngnuchains
= maxchain
;
11699 if (filedata
->gnuchains
== NULL
)
11702 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11704 if (fseek64 (filedata
->handle
,
11705 (filedata
->archive_file_offset
11706 + offset_from_vma (filedata
, (buckets_vma
11707 + 4 * (filedata
->ngnubuckets
11711 error (_("Unable to seek to start of dynamic information\n"));
11715 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
11716 if (filedata
->mipsxlat
== NULL
)
11720 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
11721 if (filedata
->gnubuckets
[hn
] != 0)
11723 uint64_t si
= filedata
->gnubuckets
[hn
];
11724 uint64_t off
= si
- filedata
->gnusymidx
;
11728 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11730 if (off
< filedata
->ngnuchains
11731 && filedata
->mipsxlat
[off
] >= num_of_syms
)
11732 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
11736 if (si
>= num_of_syms
)
11737 num_of_syms
= si
+ 1;
11741 while (off
< filedata
->ngnuchains
11742 && (filedata
->gnuchains
[off
++] & 1) == 0);
11745 if (num_of_syms
== 0)
11748 free (filedata
->mipsxlat
);
11749 filedata
->mipsxlat
= NULL
;
11750 free (filedata
->gnuchains
);
11751 filedata
->gnuchains
= NULL
;
11752 free (filedata
->gnubuckets
);
11753 filedata
->gnubuckets
= NULL
;
11754 filedata
->ngnubuckets
= 0;
11755 filedata
->ngnuchains
= 0;
11759 return num_of_syms
;
11762 /* Parse and display the contents of the dynamic section. */
11765 process_dynamic_section (Filedata
* filedata
)
11767 Elf_Internal_Dyn
* entry
;
11769 if (filedata
->dynamic_size
<= 1)
11773 if (filedata
->is_separate
)
11774 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
11775 filedata
->file_name
);
11777 printf (_("\nThere is no dynamic section in this file.\n"));
11783 if (!get_dynamic_section (filedata
))
11786 /* Find the appropriate symbol table. */
11787 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
11789 uint64_t num_of_syms
;
11791 for (entry
= filedata
->dynamic_section
;
11792 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11794 if (entry
->d_tag
== DT_SYMTAB
)
11795 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
11796 else if (entry
->d_tag
== DT_SYMENT
)
11797 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
11798 else if (entry
->d_tag
== DT_HASH
)
11799 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
11800 else if (entry
->d_tag
== DT_GNU_HASH
)
11801 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11802 else if ((filedata
->file_header
.e_machine
== EM_MIPS
11803 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
11804 && entry
->d_tag
== DT_MIPS_XHASH
)
11806 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
11807 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11810 num_of_syms
= get_num_dynamic_syms (filedata
);
11812 if (num_of_syms
!= 0
11813 && filedata
->dynamic_symbols
== NULL
11814 && filedata
->dynamic_info
[DT_SYMTAB
]
11815 && filedata
->dynamic_info
[DT_SYMENT
])
11817 Elf_Internal_Phdr
*seg
;
11818 uint64_t vma
= filedata
->dynamic_info
[DT_SYMTAB
];
11820 if (! get_program_headers (filedata
))
11822 error (_("Cannot interpret virtual addresses "
11823 "without program headers.\n"));
11827 for (seg
= filedata
->program_headers
;
11828 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
11831 if (seg
->p_type
!= PT_LOAD
)
11834 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
11836 /* See PR 21379 for a reproducer. */
11837 error (_("Invalid PT_LOAD entry\n"));
11841 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
11842 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
11844 /* Since we do not know how big the symbol table is,
11845 we default to reading in up to the end of PT_LOAD
11846 segment and processing that. This is overkill, I
11847 know, but it should work. */
11848 Elf_Internal_Shdr section
;
11849 section
.sh_offset
= (vma
- seg
->p_vaddr
11851 section
.sh_size
= (num_of_syms
11852 * filedata
->dynamic_info
[DT_SYMENT
]);
11853 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
11856 && filedata
->dynamic_symtab_section
!= NULL
11857 && ((filedata
->dynamic_symtab_section
->sh_offset
11858 != section
.sh_offset
)
11859 || (filedata
->dynamic_symtab_section
->sh_size
11860 != section
.sh_size
)
11861 || (filedata
->dynamic_symtab_section
->sh_entsize
11862 != section
.sh_entsize
)))
11864 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
11866 section
.sh_name
= filedata
->string_table_length
;
11867 filedata
->dynamic_symbols
11868 = get_elf_symbols (filedata
, §ion
,
11869 &filedata
->num_dynamic_syms
);
11870 if (filedata
->dynamic_symbols
== NULL
11871 || filedata
->num_dynamic_syms
!= num_of_syms
)
11873 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
11882 /* Similarly find a string table. */
11883 if (filedata
->dynamic_strings
== NULL
)
11884 for (entry
= filedata
->dynamic_section
;
11885 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11888 if (entry
->d_tag
== DT_STRTAB
)
11889 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
11891 if (entry
->d_tag
== DT_STRSZ
)
11892 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
11894 if (filedata
->dynamic_info
[DT_STRTAB
]
11895 && filedata
->dynamic_info
[DT_STRSZ
])
11898 uint64_t str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
11900 offset
= offset_from_vma (filedata
,
11901 filedata
->dynamic_info
[DT_STRTAB
],
11904 && filedata
->dynamic_strtab_section
11905 && ((filedata
->dynamic_strtab_section
->sh_offset
11906 != (file_ptr
) offset
)
11907 || (filedata
->dynamic_strtab_section
->sh_size
11910 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
11912 filedata
->dynamic_strings
11913 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
11914 _("dynamic string table"));
11915 if (filedata
->dynamic_strings
== NULL
)
11917 error (_("Corrupt DT_STRTAB dynamic entry\n"));
11921 filedata
->dynamic_strings_length
= str_tab_len
;
11926 /* And find the syminfo section if available. */
11927 if (filedata
->dynamic_syminfo
== NULL
)
11929 uint64_t syminsz
= 0;
11931 for (entry
= filedata
->dynamic_section
;
11932 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11935 if (entry
->d_tag
== DT_SYMINENT
)
11937 /* Note: these braces are necessary to avoid a syntax
11938 error from the SunOS4 C compiler. */
11939 /* PR binutils/17531: A corrupt file can trigger this test.
11940 So do not use an assert, instead generate an error message. */
11941 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
11942 error (_("Bad value (%d) for SYMINENT entry\n"),
11943 (int) entry
->d_un
.d_val
);
11945 else if (entry
->d_tag
== DT_SYMINSZ
)
11946 syminsz
= entry
->d_un
.d_val
;
11947 else if (entry
->d_tag
== DT_SYMINFO
)
11948 filedata
->dynamic_syminfo_offset
11949 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
11952 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
11954 Elf_External_Syminfo
* extsyminfo
;
11955 Elf_External_Syminfo
* extsym
;
11956 Elf_Internal_Syminfo
* syminfo
;
11958 /* There is a syminfo section. Read the data. */
11959 extsyminfo
= (Elf_External_Syminfo
*)
11960 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
11961 1, syminsz
, _("symbol information"));
11965 if (filedata
->dynamic_syminfo
!= NULL
)
11967 error (_("Multiple dynamic symbol information sections found\n"));
11968 free (filedata
->dynamic_syminfo
);
11970 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
11971 if (filedata
->dynamic_syminfo
== NULL
)
11973 error (_("Out of memory allocating %" PRIu64
11974 " bytes for dynamic symbol info\n"),
11979 filedata
->dynamic_syminfo_nent
11980 = syminsz
/ sizeof (Elf_External_Syminfo
);
11981 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
11982 syminfo
< (filedata
->dynamic_syminfo
11983 + filedata
->dynamic_syminfo_nent
);
11984 ++syminfo
, ++extsym
)
11986 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
11987 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
11994 if (do_dynamic
&& filedata
->dynamic_addr
)
11996 if (filedata
->is_separate
)
11997 printf (ngettext ("\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
11998 "\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
11999 filedata
->dynamic_nent
),
12000 filedata
->file_name
,
12001 filedata
->dynamic_addr
,
12002 filedata
->dynamic_nent
);
12004 printf (ngettext ("\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
12005 "\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
12006 filedata
->dynamic_nent
),
12007 filedata
->dynamic_addr
,
12008 filedata
->dynamic_nent
);
12011 printf (_(" Tag Type Name/Value\n"));
12013 for (entry
= filedata
->dynamic_section
;
12014 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
12019 const char * dtype
;
12022 print_vma (entry
->d_tag
, FULL_HEX
);
12023 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
12024 printf (" (%s)%*s", dtype
,
12025 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
12028 switch (entry
->d_tag
)
12032 print_dynamic_flags (entry
->d_un
.d_val
);
12042 switch (entry
->d_tag
)
12045 printf (_("Auxiliary library"));
12049 printf (_("Filter library"));
12053 printf (_("Configuration file"));
12057 printf (_("Dependency audit library"));
12061 printf (_("Audit library"));
12065 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
12066 printf (": [%s]\n",
12067 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
12071 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12080 printf (_("Flags:"));
12082 if (entry
->d_un
.d_val
== 0)
12083 printf (_(" None\n"));
12086 uint64_t val
= entry
->d_un
.d_val
;
12088 if (val
& DTF_1_PARINIT
)
12090 printf (" PARINIT");
12091 val
^= DTF_1_PARINIT
;
12093 if (val
& DTF_1_CONFEXP
)
12095 printf (" CONFEXP");
12096 val
^= DTF_1_CONFEXP
;
12099 printf (" %" PRIx64
, val
);
12108 printf (_("Flags:"));
12110 if (entry
->d_un
.d_val
== 0)
12111 printf (_(" None\n"));
12114 uint64_t val
= entry
->d_un
.d_val
;
12116 if (val
& DF_P1_LAZYLOAD
)
12118 printf (" LAZYLOAD");
12119 val
^= DF_P1_LAZYLOAD
;
12121 if (val
& DF_P1_GROUPPERM
)
12123 printf (" GROUPPERM");
12124 val
^= DF_P1_GROUPPERM
;
12127 printf (" %" PRIx64
, val
);
12136 printf (_("Flags:"));
12137 if (entry
->d_un
.d_val
== 0)
12138 printf (_(" None\n"));
12141 uint64_t val
= entry
->d_un
.d_val
;
12143 if (val
& DF_1_NOW
)
12148 if (val
& DF_1_GLOBAL
)
12150 printf (" GLOBAL");
12151 val
^= DF_1_GLOBAL
;
12153 if (val
& DF_1_GROUP
)
12158 if (val
& DF_1_NODELETE
)
12160 printf (" NODELETE");
12161 val
^= DF_1_NODELETE
;
12163 if (val
& DF_1_LOADFLTR
)
12165 printf (" LOADFLTR");
12166 val
^= DF_1_LOADFLTR
;
12168 if (val
& DF_1_INITFIRST
)
12170 printf (" INITFIRST");
12171 val
^= DF_1_INITFIRST
;
12173 if (val
& DF_1_NOOPEN
)
12175 printf (" NOOPEN");
12176 val
^= DF_1_NOOPEN
;
12178 if (val
& DF_1_ORIGIN
)
12180 printf (" ORIGIN");
12181 val
^= DF_1_ORIGIN
;
12183 if (val
& DF_1_DIRECT
)
12185 printf (" DIRECT");
12186 val
^= DF_1_DIRECT
;
12188 if (val
& DF_1_TRANS
)
12193 if (val
& DF_1_INTERPOSE
)
12195 printf (" INTERPOSE");
12196 val
^= DF_1_INTERPOSE
;
12198 if (val
& DF_1_NODEFLIB
)
12200 printf (" NODEFLIB");
12201 val
^= DF_1_NODEFLIB
;
12203 if (val
& DF_1_NODUMP
)
12205 printf (" NODUMP");
12206 val
^= DF_1_NODUMP
;
12208 if (val
& DF_1_CONFALT
)
12210 printf (" CONFALT");
12211 val
^= DF_1_CONFALT
;
12213 if (val
& DF_1_ENDFILTEE
)
12215 printf (" ENDFILTEE");
12216 val
^= DF_1_ENDFILTEE
;
12218 if (val
& DF_1_DISPRELDNE
)
12220 printf (" DISPRELDNE");
12221 val
^= DF_1_DISPRELDNE
;
12223 if (val
& DF_1_DISPRELPND
)
12225 printf (" DISPRELPND");
12226 val
^= DF_1_DISPRELPND
;
12228 if (val
& DF_1_NODIRECT
)
12230 printf (" NODIRECT");
12231 val
^= DF_1_NODIRECT
;
12233 if (val
& DF_1_IGNMULDEF
)
12235 printf (" IGNMULDEF");
12236 val
^= DF_1_IGNMULDEF
;
12238 if (val
& DF_1_NOKSYMS
)
12240 printf (" NOKSYMS");
12241 val
^= DF_1_NOKSYMS
;
12243 if (val
& DF_1_NOHDR
)
12248 if (val
& DF_1_EDITED
)
12250 printf (" EDITED");
12251 val
^= DF_1_EDITED
;
12253 if (val
& DF_1_NORELOC
)
12255 printf (" NORELOC");
12256 val
^= DF_1_NORELOC
;
12258 if (val
& DF_1_SYMINTPOSE
)
12260 printf (" SYMINTPOSE");
12261 val
^= DF_1_SYMINTPOSE
;
12263 if (val
& DF_1_GLOBAUDIT
)
12265 printf (" GLOBAUDIT");
12266 val
^= DF_1_GLOBAUDIT
;
12268 if (val
& DF_1_SINGLETON
)
12270 printf (" SINGLETON");
12271 val
^= DF_1_SINGLETON
;
12273 if (val
& DF_1_STUB
)
12278 if (val
& DF_1_PIE
)
12283 if (val
& DF_1_KMOD
)
12288 if (val
& DF_1_WEAKFILTER
)
12290 printf (" WEAKFILTER");
12291 val
^= DF_1_WEAKFILTER
;
12293 if (val
& DF_1_NOCOMMON
)
12295 printf (" NOCOMMON");
12296 val
^= DF_1_NOCOMMON
;
12299 printf (" %" PRIx64
, val
);
12306 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
12308 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
12329 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
12335 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
12336 name
= get_dynamic_name (filedata
, entry
->d_un
.d_val
);
12342 switch (entry
->d_tag
)
12345 printf (_("Shared library: [%s]"), name
);
12347 if (filedata
->program_interpreter
12348 && streq (name
, filedata
->program_interpreter
))
12349 printf (_(" program interpreter"));
12353 printf (_("Library soname: [%s]"), name
);
12357 printf (_("Library rpath: [%s]"), name
);
12361 printf (_("Library runpath: [%s]"), name
);
12365 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12370 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12385 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
12386 /* Fall through. */
12390 case DT_PREINIT_ARRAYSZ
:
12391 case DT_INIT_ARRAYSZ
:
12392 case DT_FINI_ARRAYSZ
:
12393 case DT_GNU_CONFLICTSZ
:
12394 case DT_GNU_LIBLISTSZ
:
12397 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
12398 printf (_(" (bytes)\n"));
12403 case DT_VERNEEDNUM
:
12408 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
12417 case DT_INIT_ARRAY
:
12418 case DT_FINI_ARRAY
:
12421 if (entry
->d_tag
== DT_USED
12422 && valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
12425 = get_dynamic_name (filedata
, entry
->d_un
.d_val
);
12429 printf (_("Not needed object: [%s]\n"), name
);
12434 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12440 /* The value of this entry is ignored. */
12445 case DT_GNU_PRELINKED
:
12449 time_t atime
= entry
->d_un
.d_val
;
12451 tmp
= gmtime (&atime
);
12452 /* PR 17533 file: 041-1244816-0.004. */
12454 printf (_("<corrupt time val: %" PRIx64
),
12457 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
12458 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
12459 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
12465 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
12468 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12473 case DT_GNU_FLAGS_1
:
12476 printf (_("Flags:"));
12477 if (entry
->d_un
.d_val
== 0)
12478 printf (_(" None\n"));
12481 uint64_t val
= entry
->d_un
.d_val
;
12483 if (val
& DF_GNU_1_UNIQUE
)
12485 printf (" UNIQUE");
12486 val
^= DF_GNU_1_UNIQUE
;
12489 printf (" %" PRIx64
, val
);
12496 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
12497 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
12498 = entry
->d_un
.d_val
;
12502 switch (filedata
->file_header
.e_machine
)
12505 dynamic_section_aarch64_val (entry
);
12508 case EM_MIPS_RS3_LE
:
12509 dynamic_section_mips_val (filedata
, entry
);
12512 dynamic_section_parisc_val (entry
);
12515 dynamic_section_ia64_val (entry
);
12518 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12530 get_ver_flags (unsigned int flags
)
12532 static char buff
[128];
12539 if (flags
& VER_FLG_BASE
)
12540 strcat (buff
, "BASE");
12542 if (flags
& VER_FLG_WEAK
)
12544 if (flags
& VER_FLG_BASE
)
12545 strcat (buff
, " | ");
12547 strcat (buff
, "WEAK");
12550 if (flags
& VER_FLG_INFO
)
12552 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
12553 strcat (buff
, " | ");
12555 strcat (buff
, "INFO");
12558 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12560 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12561 strcat (buff
, " | ");
12563 strcat (buff
, _("<unknown>"));
12569 /* Display the contents of the version sections. */
12572 process_version_sections (Filedata
* filedata
)
12574 Elf_Internal_Shdr
* section
;
12576 bool found
= false;
12581 for (i
= 0, section
= filedata
->section_headers
;
12582 i
< filedata
->file_header
.e_shnum
;
12585 switch (section
->sh_type
)
12587 case SHT_GNU_verdef
:
12589 Elf_External_Verdef
* edefs
;
12596 if (filedata
->is_separate
)
12597 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
12598 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
12600 filedata
->file_name
,
12601 printable_section_name (filedata
, section
),
12604 printf (ngettext ("\nVersion definition section '%s' "
12605 "contains %u entry:\n",
12606 "\nVersion definition section '%s' "
12607 "contains %u entries:\n",
12609 printable_section_name (filedata
, section
),
12612 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12613 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12614 section
->sh_offset
, section
->sh_link
,
12615 printable_section_name_from_index (filedata
, section
->sh_link
, NULL
));
12617 edefs
= (Elf_External_Verdef
*)
12618 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
12619 _("version definition section"));
12622 endbuf
= (char *) edefs
+ section
->sh_size
;
12624 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12627 Elf_External_Verdef
* edef
;
12628 Elf_Internal_Verdef ent
;
12629 Elf_External_Verdaux
* eaux
;
12630 Elf_Internal_Verdaux aux
;
12634 vstart
= ((char *) edefs
) + idx
;
12635 if (vstart
+ sizeof (*edef
) > endbuf
)
12638 edef
= (Elf_External_Verdef
*) vstart
;
12640 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
12641 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
12642 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
12643 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
12644 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
12645 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
12646 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
12648 printf (_(" %#06zx: Rev: %d Flags: %s"),
12649 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
12651 printf (_(" Index: %d Cnt: %d "),
12652 ent
.vd_ndx
, ent
.vd_cnt
);
12654 /* Check for overflow. */
12655 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
12658 vstart
+= ent
.vd_aux
;
12660 if (vstart
+ sizeof (*eaux
) > endbuf
)
12662 eaux
= (Elf_External_Verdaux
*) vstart
;
12664 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12665 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12667 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12668 printf (_("Name: %s\n"),
12669 get_dynamic_name (filedata
, aux
.vda_name
));
12671 printf (_("Name index: %ld\n"), aux
.vda_name
);
12673 isum
= idx
+ ent
.vd_aux
;
12675 for (j
= 1; j
< ent
.vd_cnt
; j
++)
12677 if (aux
.vda_next
< sizeof (*eaux
)
12678 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
12680 warn (_("Invalid vda_next field of %lx\n"),
12685 /* Check for overflow. */
12686 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
12689 isum
+= aux
.vda_next
;
12690 vstart
+= aux
.vda_next
;
12692 if (vstart
+ sizeof (*eaux
) > endbuf
)
12694 eaux
= (Elf_External_Verdaux
*) vstart
;
12696 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12697 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12699 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12700 printf (_(" %#06zx: Parent %d: %s\n"),
12702 get_dynamic_name (filedata
, aux
.vda_name
));
12704 printf (_(" %#06zx: Parent %d, name index: %ld\n"),
12705 isum
, j
, aux
.vda_name
);
12708 if (j
< ent
.vd_cnt
)
12709 printf (_(" Version def aux past end of section\n"));
12712 file: id:000001,src:000172+005151,op:splice,rep:2. */
12713 if (ent
.vd_next
< sizeof (*edef
)
12714 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
12716 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
12717 cnt
= section
->sh_info
;
12720 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
12723 idx
+= ent
.vd_next
;
12726 if (cnt
< section
->sh_info
)
12727 printf (_(" Version definition past end of section\n"));
12733 case SHT_GNU_verneed
:
12735 Elf_External_Verneed
* eneed
;
12742 if (filedata
->is_separate
)
12743 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
12744 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
12746 filedata
->file_name
,
12747 printable_section_name (filedata
, section
),
12750 printf (ngettext ("\nVersion needs section '%s' "
12751 "contains %u entry:\n",
12752 "\nVersion needs section '%s' "
12753 "contains %u entries:\n",
12755 printable_section_name (filedata
, section
),
12758 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12759 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12760 section
->sh_offset
, section
->sh_link
,
12761 printable_section_name_from_index (filedata
, section
->sh_link
, NULL
));
12763 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
12764 section
->sh_offset
, 1,
12766 _("Version Needs section"));
12769 endbuf
= (char *) eneed
+ section
->sh_size
;
12771 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12773 Elf_External_Verneed
* entry
;
12774 Elf_Internal_Verneed ent
;
12779 vstart
= ((char *) eneed
) + idx
;
12780 if (vstart
+ sizeof (*entry
) > endbuf
)
12783 entry
= (Elf_External_Verneed
*) vstart
;
12785 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
12786 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
12787 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
12788 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
12789 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
12791 printf (_(" %#06zx: Version: %d"), idx
, ent
.vn_version
);
12793 if (valid_dynamic_name (filedata
, ent
.vn_file
))
12794 printf (_(" File: %s"),
12795 get_dynamic_name (filedata
, ent
.vn_file
));
12797 printf (_(" File: %lx"), ent
.vn_file
);
12799 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
12801 /* Check for overflow. */
12802 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
12804 vstart
+= ent
.vn_aux
;
12806 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
12808 Elf_External_Vernaux
* eaux
;
12809 Elf_Internal_Vernaux aux
;
12811 if (vstart
+ sizeof (*eaux
) > endbuf
)
12813 eaux
= (Elf_External_Vernaux
*) vstart
;
12815 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
12816 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
12817 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
12818 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
12819 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
12821 if (valid_dynamic_name (filedata
, aux
.vna_name
))
12822 printf (_(" %#06zx: Name: %s"),
12823 isum
, get_dynamic_name (filedata
, aux
.vna_name
));
12825 printf (_(" %#06zx: Name index: %lx"),
12826 isum
, aux
.vna_name
);
12828 printf (_(" Flags: %s Version: %d\n"),
12829 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
12831 if (aux
.vna_next
< sizeof (*eaux
)
12832 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
12834 warn (_("Invalid vna_next field of %lx\n"),
12839 /* Check for overflow. */
12840 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
12842 isum
+= aux
.vna_next
;
12843 vstart
+= aux
.vna_next
;
12846 if (j
< ent
.vn_cnt
)
12847 warn (_("Missing Version Needs auxiliary information\n"));
12849 if (ent
.vn_next
< sizeof (*entry
)
12850 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
12852 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
12853 cnt
= section
->sh_info
;
12856 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
12858 idx
+= ent
.vn_next
;
12861 if (cnt
< section
->sh_info
)
12862 warn (_("Missing Version Needs information\n"));
12868 case SHT_GNU_versym
:
12870 Elf_Internal_Shdr
* link_section
;
12873 unsigned char * edata
;
12874 unsigned short * data
;
12876 Elf_Internal_Sym
* symbols
;
12877 Elf_Internal_Shdr
* string_sec
;
12881 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
12884 link_section
= filedata
->section_headers
+ section
->sh_link
;
12885 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
12887 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
12892 symbols
= get_elf_symbols (filedata
, link_section
, & num_syms
);
12893 if (symbols
== NULL
)
12896 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
12898 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
12899 string_sec
->sh_size
,
12900 _("version string table"));
12907 if (filedata
->is_separate
)
12908 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entry:\n",
12909 "\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entries:\n",
12911 filedata
->file_name
,
12912 printable_section_name (filedata
, section
),
12915 printf (ngettext ("\nVersion symbols section '%s' "
12916 "contains %" PRIu64
" entry:\n",
12917 "\nVersion symbols section '%s' "
12918 "contains %" PRIu64
" entries:\n",
12920 printable_section_name (filedata
, section
),
12923 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
12924 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
12925 section
->sh_offset
, section
->sh_link
,
12926 printable_section_name (filedata
, link_section
));
12928 off
= offset_from_vma (filedata
,
12929 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12930 total
* sizeof (short));
12931 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
12932 sizeof (short), total
,
12933 _("version symbol data"));
12941 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
12943 for (cnt
= total
; cnt
--;)
12944 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
12949 for (cnt
= 0; cnt
< total
; cnt
+= 4)
12953 char *invalid
= _("*invalid*");
12955 printf (" %03x:", cnt
);
12957 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
12958 switch (data
[cnt
+ j
])
12961 fputs (_(" 0 (*local*) "), stdout
);
12965 fputs (_(" 1 (*global*) "), stdout
);
12969 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
12970 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
12972 /* If this index value is greater than the size of the symbols
12973 array, break to avoid an out-of-bounds read. */
12974 if (cnt
+ j
>= num_syms
)
12976 warn (_("invalid index into symbol array\n"));
12981 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12983 Elf_Internal_Verneed ivn
;
12986 offset
= offset_from_vma
12988 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12989 sizeof (Elf_External_Verneed
));
12993 Elf_Internal_Vernaux ivna
;
12994 Elf_External_Verneed evn
;
12995 Elf_External_Vernaux evna
;
12998 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12999 _("version need")) == NULL
)
13002 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
13003 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
13005 a_off
= offset
+ ivn
.vn_aux
;
13009 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
13010 1, _("version need aux (2)")) == NULL
)
13013 ivna
.vna_other
= 0;
13017 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
13018 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
13021 a_off
+= ivna
.vna_next
;
13023 while (ivna
.vna_other
!= data
[cnt
+ j
]
13024 && ivna
.vna_next
!= 0);
13026 if (ivna
.vna_other
== data
[cnt
+ j
])
13028 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
13030 if (ivna
.vna_name
>= string_sec
->sh_size
)
13033 name
= strtab
+ ivna
.vna_name
;
13037 offset
+= ivn
.vn_next
;
13039 while (ivn
.vn_next
);
13042 if (data
[cnt
+ j
] != 0x8001
13043 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
13045 Elf_Internal_Verdef ivd
;
13046 Elf_External_Verdef evd
;
13049 offset
= offset_from_vma
13051 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
13056 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
13057 _("version def")) == NULL
)
13060 /* PR 17531: file: 046-1082287-0.004. */
13061 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
13066 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
13067 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
13070 offset
+= ivd
.vd_next
;
13072 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
13073 && ivd
.vd_next
!= 0);
13075 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
13077 Elf_External_Verdaux evda
;
13078 Elf_Internal_Verdaux ivda
;
13080 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
13082 if (get_data (&evda
, filedata
,
13083 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
13085 _("version def aux")) == NULL
)
13088 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
13090 if (ivda
.vda_name
>= string_sec
->sh_size
)
13092 else if (name
!= NULL
&& name
!= invalid
)
13093 name
= _("*both*");
13095 name
= strtab
+ ivda
.vda_name
;
13099 nn
+= printf ("(%s%-*s",
13101 12 - (int) strlen (name
),
13105 printf ("%*c", 18 - nn
, ' ');
13124 if (filedata
->is_separate
)
13125 printf (_("\nNo version information found in linked file '%s'.\n"),
13126 filedata
->file_name
);
13128 printf (_("\nNo version information found in this file.\n"));
13134 static const char *
13135 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
13137 static char buff
[64];
13141 case STB_LOCAL
: return "LOCAL";
13142 case STB_GLOBAL
: return "GLOBAL";
13143 case STB_WEAK
: return "WEAK";
13145 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
13146 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
13148 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
13150 if (binding
== STB_GNU_UNIQUE
13151 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
13153 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
13156 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
13161 static const char *
13162 get_symbol_type (Filedata
* filedata
, unsigned int type
)
13164 static char buff
[64];
13168 case STT_NOTYPE
: return "NOTYPE";
13169 case STT_OBJECT
: return "OBJECT";
13170 case STT_FUNC
: return "FUNC";
13171 case STT_SECTION
: return "SECTION";
13172 case STT_FILE
: return "FILE";
13173 case STT_COMMON
: return "COMMON";
13174 case STT_TLS
: return "TLS";
13175 case STT_RELC
: return "RELC";
13176 case STT_SRELC
: return "SRELC";
13178 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
13180 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
13181 return "THUMB_FUNC";
13183 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
13186 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
13187 return "PARISC_MILLI";
13189 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
13191 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
13193 if (filedata
->file_header
.e_machine
== EM_PARISC
)
13195 if (type
== STT_HP_OPAQUE
)
13196 return "HP_OPAQUE";
13197 if (type
== STT_HP_STUB
)
13201 if (type
== STT_GNU_IFUNC
13202 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
13203 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
13206 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
13209 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
13214 static const char *
13215 get_symbol_visibility (unsigned int visibility
)
13217 switch (visibility
)
13219 case STV_DEFAULT
: return "DEFAULT";
13220 case STV_INTERNAL
: return "INTERNAL";
13221 case STV_HIDDEN
: return "HIDDEN";
13222 case STV_PROTECTED
: return "PROTECTED";
13224 error (_("Unrecognized visibility value: %u\n"), visibility
);
13225 return _("<unknown>");
13229 static const char *
13230 get_alpha_symbol_other (unsigned int other
)
13234 case STO_ALPHA_NOPV
: return "NOPV";
13235 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
13237 error (_("Unrecognized alpha specific other value: %u\n"), other
);
13238 return _("<unknown>");
13242 static const char *
13243 get_solaris_symbol_visibility (unsigned int visibility
)
13245 switch (visibility
)
13247 case 4: return "EXPORTED";
13248 case 5: return "SINGLETON";
13249 case 6: return "ELIMINATE";
13250 default: return get_symbol_visibility (visibility
);
13254 static const char *
13255 get_aarch64_symbol_other (unsigned int other
)
13257 static char buf
[32];
13259 if (other
& STO_AARCH64_VARIANT_PCS
)
13261 other
&= ~STO_AARCH64_VARIANT_PCS
;
13263 return "VARIANT_PCS";
13264 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
13270 static const char *
13271 get_mips_symbol_other (unsigned int other
)
13275 case STO_OPTIONAL
: return "OPTIONAL";
13276 case STO_MIPS_PLT
: return "MIPS PLT";
13277 case STO_MIPS_PIC
: return "MIPS PIC";
13278 case STO_MICROMIPS
: return "MICROMIPS";
13279 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
13280 case STO_MIPS16
: return "MIPS16";
13281 default: return NULL
;
13285 static const char *
13286 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
13288 if (is_ia64_vms (filedata
))
13290 static char res
[32];
13294 /* Function types is for images and .STB files only. */
13295 switch (filedata
->file_header
.e_type
)
13299 switch (VMS_ST_FUNC_TYPE (other
))
13301 case VMS_SFT_CODE_ADDR
:
13302 strcat (res
, " CA");
13304 case VMS_SFT_SYMV_IDX
:
13305 strcat (res
, " VEC");
13308 strcat (res
, " FD");
13310 case VMS_SFT_RESERVE
:
13311 strcat (res
, " RSV");
13314 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
13315 VMS_ST_FUNC_TYPE (other
));
13316 strcat (res
, " <unknown>");
13323 switch (VMS_ST_LINKAGE (other
))
13325 case VMS_STL_IGNORE
:
13326 strcat (res
, " IGN");
13328 case VMS_STL_RESERVE
:
13329 strcat (res
, " RSV");
13332 strcat (res
, " STD");
13335 strcat (res
, " LNK");
13338 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
13339 VMS_ST_LINKAGE (other
));
13340 strcat (res
, " <unknown>");
13352 static const char *
13353 get_ppc64_symbol_other (unsigned int other
)
13355 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
13358 other
>>= STO_PPC64_LOCAL_BIT
;
13361 static char buf
[64];
13363 other
= ppc64_decode_local_entry (other
);
13364 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
13370 static const char *
13371 get_riscv_symbol_other (unsigned int other
)
13373 static char buf
[32];
13376 if (other
& STO_RISCV_VARIANT_CC
)
13378 strcat (buf
, _(" VARIANT_CC"));
13379 other
&= ~STO_RISCV_VARIANT_CC
;
13383 snprintf (buf
, sizeof buf
, " %x", other
);
13392 static const char *
13393 get_symbol_other (Filedata
* filedata
, unsigned int other
)
13395 const char * result
= NULL
;
13396 static char buff
[64];
13401 switch (filedata
->file_header
.e_machine
)
13404 result
= get_alpha_symbol_other (other
);
13407 result
= get_aarch64_symbol_other (other
);
13410 result
= get_mips_symbol_other (other
);
13413 result
= get_ia64_symbol_other (filedata
, other
);
13416 result
= get_ppc64_symbol_other (other
);
13419 result
= get_riscv_symbol_other (other
);
13429 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
13433 static const char *
13434 get_symbol_version_string (Filedata
*filedata
,
13436 const char *strtab
,
13437 size_t strtab_size
,
13439 Elf_Internal_Sym
*psym
,
13440 enum versioned_symbol_info
*sym_info
,
13441 unsigned short *vna_other
)
13443 unsigned char data
[2];
13444 unsigned short vers_data
;
13446 unsigned short max_vd_ndx
;
13449 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
13452 offset
= offset_from_vma (filedata
,
13453 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
13454 sizeof data
+ si
* sizeof (vers_data
));
13456 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
13457 sizeof (data
), 1, _("version data")) == NULL
)
13460 vers_data
= byte_get (data
, 2);
13462 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
13465 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
13468 /* Usually we'd only see verdef for defined symbols, and verneed for
13469 undefined symbols. However, symbols defined by the linker in
13470 .dynbss for variables copied from a shared library in order to
13471 avoid text relocations are defined yet have verneed. We could
13472 use a heuristic to detect the special case, for example, check
13473 for verneed first on symbols defined in SHT_NOBITS sections, but
13474 it is simpler and more reliable to just look for both verdef and
13475 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
13477 if (psym
->st_shndx
!= SHN_UNDEF
13478 && vers_data
!= 0x8001
13479 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
13481 Elf_Internal_Verdef ivd
;
13482 Elf_Internal_Verdaux ivda
;
13483 Elf_External_Verdaux evda
;
13486 off
= offset_from_vma (filedata
,
13487 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
13488 sizeof (Elf_External_Verdef
));
13492 Elf_External_Verdef evd
;
13494 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
13495 _("version def")) == NULL
)
13504 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
13505 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
13506 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
13507 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
13510 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
13511 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
13513 off
+= ivd
.vd_next
;
13515 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
13517 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
13519 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
13522 off
-= ivd
.vd_next
;
13525 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
13526 _("version def aux")) != NULL
)
13528 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
13530 if (psym
->st_name
!= ivda
.vda_name
)
13531 return (ivda
.vda_name
< strtab_size
13532 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
13537 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
13539 Elf_External_Verneed evn
;
13540 Elf_Internal_Verneed ivn
;
13541 Elf_Internal_Vernaux ivna
;
13543 offset
= offset_from_vma (filedata
,
13544 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
13550 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
13551 _("version need")) == NULL
)
13554 ivna
.vna_other
= 0;
13559 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
13560 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
13562 vna_off
= offset
+ ivn
.vn_aux
;
13566 Elf_External_Vernaux evna
;
13568 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
13569 _("version need aux (3)")) == NULL
)
13572 ivna
.vna_other
= 0;
13577 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
13578 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
13579 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
13582 vna_off
+= ivna
.vna_next
;
13584 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
13586 if (ivna
.vna_other
== vers_data
)
13589 offset
+= ivn
.vn_next
;
13591 while (ivn
.vn_next
!= 0);
13593 if (ivna
.vna_other
== vers_data
)
13595 *sym_info
= symbol_undefined
;
13596 *vna_other
= ivna
.vna_other
;
13597 return (ivna
.vna_name
< strtab_size
13598 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
13600 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
13601 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
13602 return _("<corrupt>");
13607 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
13609 static unsigned int
13610 print_symbol_size (uint64_t vma
, int base
)
13615 return print_vma (vma
, OCTAL_5
);
13618 return print_vma (vma
, UNSIGNED_5
);
13621 return print_vma (vma
, PREFIX_HEX_5
);
13625 return print_vma (vma
, DEC_5
);
13629 /* Print information on a single symbol. */
13632 print_symbol (Filedata
* filedata
,
13633 uint64_t symbol_index
,
13634 Elf_Internal_Sym
* symtab
,
13635 Elf_Internal_Shdr
* section
,
13637 size_t strtab_size
)
13639 const char *version_string
;
13640 enum versioned_symbol_info sym_info
;
13641 unsigned short vna_other
;
13643 Elf_Internal_Sym
*psym
= symtab
+ symbol_index
;
13645 /* FIXME: We should have a table of field widths,
13646 rather than using hard coded constants. */
13647 printf ("%6" PRId64
": ", symbol_index
);
13648 print_vma (psym
->st_value
, LONG_HEX
);
13650 print_symbol_size (psym
->st_size
, sym_base
);
13651 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
13652 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
13653 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
13654 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
13657 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
13659 printf (" %-7s", get_symbol_visibility (vis
));
13661 /* Check to see if any other bits in the st_other field are set.
13662 FIXME: Displaying this information here disrupts the layout
13663 of the table being generated. */
13664 if (psym
->st_other
^ vis
)
13665 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
13670 sstr
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
13672 /* Print the symbol's section index. If the index is special
13673 then print the index's name rather than its number. */
13678 /* Special case: If there are no section headers, and the printable
13679 name is "<section 0x...." then just display the section number
13680 as a decimal. This happens when objcopy --strip -section-headers
13682 if (filedata
->file_header
.e_shnum
== 0 && startswith (sstr
, "<section"))
13683 printed
= printf (" %4d ", psym
->st_shndx
);
13685 printed
= printf (" %4s ", sstr
);
13687 if (extra_sym_info
&& printed
< 16)
13688 printf ("%*s", 16 - printed
, "");
13692 printf (" %4u ", psym
->st_shndx
);
13694 if (extra_sym_info
)
13696 /* Display the section name referenced by the section index. */
13697 int printed
= printf ("(%s) ", sstr
);
13699 printf ("%*s", 10 - printed
, "");
13703 /* Get the symbol's name. For section symbols without a
13704 specific name use the (already computed) section name. */
13705 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
13706 && section_index_real (filedata
, psym
->st_shndx
)
13707 && psym
->st_name
== 0)
13715 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
13716 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
13720 = get_symbol_version_string (filedata
,
13722 || section
->sh_type
== SHT_DYNSYM
),
13723 strtab
, strtab_size
, symbol_index
,
13724 psym
, &sym_info
, &vna_other
);
13726 int len_avail
= 21;
13727 if (! do_wide
&& version_string
!= NULL
)
13731 len_avail
-= 1 + strlen (version_string
);
13733 if (sym_info
== symbol_undefined
)
13734 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
13735 else if (sym_info
!= symbol_hidden
)
13739 print_symbol_name (len_avail
, sstr
);
13741 if (version_string
)
13743 if (sym_info
== symbol_undefined
)
13744 printf ("@%s (%d)", version_string
, vna_other
);
13746 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
13752 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
13754 && symbol_index
>= section
->sh_info
13755 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
13756 && filedata
->file_header
.e_machine
!= EM_MIPS
13757 /* Solaris binaries have been found to violate this requirement as
13758 well. Not sure if this is a bug or an ABI requirement. */
13759 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
13760 warn (_("local symbol %" PRIu64
" found at index >= %s's sh_info value of %u\n"),
13761 symbol_index
, printable_section_name (filedata
, section
), section
->sh_info
);
13764 static const char *
13765 get_lto_kind (unsigned int kind
)
13769 case 0: return "DEF";
13770 case 1: return "WEAKDEF";
13771 case 2: return "UNDEF";
13772 case 3: return "WEAKUNDEF";
13773 case 4: return "COMMON";
13778 static char buffer
[30];
13779 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
13780 sprintf (buffer
, "<unknown: %u>", kind
);
13784 static const char *
13785 get_lto_visibility (unsigned int visibility
)
13787 switch (visibility
)
13789 case 0: return "DEFAULT";
13790 case 1: return "PROTECTED";
13791 case 2: return "INTERNAL";
13792 case 3: return "HIDDEN";
13797 static char buffer
[30];
13798 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
13799 sprintf (buffer
, "<unknown: %u>", visibility
);
13803 static const char *
13804 get_lto_sym_type (unsigned int sym_type
)
13808 case 0: return "UNKNOWN";
13809 case 1: return "FUNCTION";
13810 case 2: return "VARIABLE";
13815 static char buffer
[30];
13816 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
13817 sprintf (buffer
, "<unknown: %u>", sym_type
);
13821 /* Display an LTO format symbol table.
13822 FIXME: The format of LTO symbol tables is not formalized.
13823 So this code could need changing in the future. */
13826 display_lto_symtab (Filedata
* filedata
,
13827 Elf_Internal_Shdr
* section
)
13829 if (section
->sh_size
== 0)
13831 if (filedata
->is_separate
)
13832 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
13833 printable_section_name (filedata
, section
),
13834 filedata
->file_name
);
13836 printf (_("\nLTO Symbol table '%s' is empty!\n"),
13837 printable_section_name (filedata
, section
));
13842 if (section
->sh_size
> filedata
->file_size
)
13844 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
13845 printable_section_name (filedata
, section
),
13850 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
13851 section
->sh_size
, 1, _("LTO symbols"));
13852 if (alloced_data
== NULL
)
13855 /* Look for extended data for the symbol table. */
13856 Elf_Internal_Shdr
* ext
;
13857 void * ext_data_orig
= NULL
;
13858 char * ext_data
= NULL
;
13859 char * ext_data_end
= NULL
;
13860 char * ext_name
= NULL
;
13862 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
13863 (section_name (filedata
, section
)
13864 + sizeof (".gnu.lto_.symtab.") - 1)) > 0
13865 && ext_name
!= NULL
/* Paranoia. */
13866 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
13868 if (ext
->sh_size
< 3)
13869 error (_("LTO Symbol extension table '%s' is empty!\n"),
13870 printable_section_name (filedata
, ext
));
13873 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
13875 _("LTO ext symbol data"));
13876 if (ext_data
!= NULL
)
13878 ext_data_end
= ext_data
+ ext
->sh_size
;
13879 if (* ext_data
++ != 1)
13880 error (_("Unexpected version number in symbol extension table\n"));
13885 const unsigned char * data
= (const unsigned char *) alloced_data
;
13886 const unsigned char * end
= data
+ section
->sh_size
;
13888 if (filedata
->is_separate
)
13889 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
13893 if (ext_data_orig
!= NULL
)
13896 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
13897 printable_section_name (filedata
, section
),
13898 printable_section_name (filedata
, ext
));
13901 printf (_("LTO Symbol table '%s'\n"),
13902 printable_section_name (filedata
, section
));
13903 printf (_(" and extension table '%s' contain:\n"),
13904 printable_section_name (filedata
, ext
));
13908 printf (_("LTO Symbol table '%s' contains:\n"),
13909 printable_section_name (filedata
, section
));
13911 /* FIXME: Add a wide version. */
13912 if (ext_data_orig
!= NULL
)
13913 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
13915 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
13917 /* FIXME: We do not handle style prefixes. */
13921 const unsigned char * sym_name
= data
;
13922 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
13926 const unsigned char * comdat_key
= data
;
13927 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
13931 if (data
+ 2 + 8 + 4 > end
)
13934 unsigned int kind
= *data
++;
13935 unsigned int visibility
= *data
++;
13937 uint64_t size
= byte_get (data
, 8);
13940 uint64_t slot
= byte_get (data
, 4);
13943 if (ext_data
!= NULL
)
13945 if (ext_data
< (ext_data_end
- 1))
13947 unsigned int sym_type
= * ext_data
++;
13948 unsigned int sec_kind
= * ext_data
++;
13950 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" %9s %08x _",
13951 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13952 get_lto_kind (kind
),
13953 get_lto_visibility (visibility
),
13956 get_lto_sym_type (sym_type
),
13958 print_symbol_name (6, (const char *) sym_name
);
13962 error (_("Ran out of LTO symbol extension data\n"));
13964 /* FIXME: return FAIL result ? */
13969 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" _",
13970 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13971 get_lto_kind (kind
),
13972 get_lto_visibility (visibility
),
13975 print_symbol_name (21, (const char *) sym_name
);
13980 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
13982 error (_("Data remains in the LTO symbol extension table\n"));
13986 free (alloced_data
);
13987 free (ext_data_orig
);
13992 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
13993 free (alloced_data
);
13994 free (ext_data_orig
);
13999 /* Display LTO symbol tables. */
14002 process_lto_symbol_tables (Filedata
* filedata
)
14004 Elf_Internal_Shdr
* section
;
14011 if (filedata
->section_headers
== NULL
)
14014 for (i
= 0, section
= filedata
->section_headers
;
14015 i
< filedata
->file_header
.e_shnum
;
14017 if (section_name_valid (filedata
, section
)
14018 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
14019 res
&= display_lto_symtab (filedata
, section
);
14025 print_symbol_table_heading (void)
14027 /* FIXME: We should store the size of each field in the display in a table and
14028 then use the values inside print_symbol(), instead of that function using
14029 hard coded constants. */
14032 if (extra_sym_info
)
14034 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
14035 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |---8--| |----13.....| |........... */
14036 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 (.text) get_sections */
14040 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14041 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
14042 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
14046 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14047 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |------------29-------------| */
14048 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
14053 if (extra_sym_info
)
14055 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
14056 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-------14---| |..... */
14057 /* eg: 2: 0000000000000000 0 FUNC LOCAL DEFAULT 1 (.text) .very_long_function_name */
14062 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14063 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
14064 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_function_name */
14068 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
14069 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |--------21---------| */
14070 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_functi[...] */
14075 /* Dump the symbol table. */
14078 process_symbol_table (Filedata
* filedata
)
14080 Elf_Internal_Shdr
* section
;
14082 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
14085 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
14087 && do_using_dynamic
14088 && filedata
->dynamic_strings
!= NULL
14089 && filedata
->dynamic_symbols
!= NULL
)
14093 if (filedata
->is_separate
)
14095 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table"
14096 " contains %" PRIu64
" entry:\n",
14097 "\nIn linked file '%s' the dynamic symbol table"
14098 " contains %" PRIu64
" entries:\n",
14099 filedata
->num_dynamic_syms
),
14100 filedata
->file_name
,
14101 filedata
->num_dynamic_syms
);
14105 printf (ngettext ("\nSymbol table for image contains %" PRIu64
14107 "\nSymbol table for image contains %" PRIu64
14109 filedata
->num_dynamic_syms
),
14110 filedata
->num_dynamic_syms
);
14113 print_symbol_table_heading ();
14115 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
14116 print_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
14117 filedata
->dynamic_strings
,
14118 filedata
->dynamic_strings_length
);
14120 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
14121 && filedata
->section_headers
!= NULL
)
14125 for (i
= 0, section
= filedata
->section_headers
;
14126 i
< filedata
->file_header
.e_shnum
;
14129 char * strtab
= NULL
;
14130 uint64_t strtab_size
= 0;
14131 Elf_Internal_Sym
* symtab
;
14132 uint64_t si
, num_syms
;
14134 if ((section
->sh_type
!= SHT_SYMTAB
14135 && section
->sh_type
!= SHT_DYNSYM
)
14137 && section
->sh_type
== SHT_SYMTAB
))
14140 if (section
->sh_entsize
== 0)
14142 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
14143 printable_section_name (filedata
, section
));
14147 num_syms
= section
->sh_size
/ section
->sh_entsize
;
14149 if (filedata
->is_separate
)
14150 printf (ngettext ("\nIn linked file '%s' symbol section '%s'"
14151 " contains %" PRIu64
" entry:\n",
14152 "\nIn linked file '%s' symbol section '%s'"
14153 " contains %" PRIu64
" entries:\n",
14155 filedata
->file_name
,
14156 printable_section_name (filedata
, section
),
14159 printf (ngettext ("\nSymbol table '%s' contains %" PRIu64
14161 "\nSymbol table '%s' contains %" PRIu64
14164 printable_section_name (filedata
, section
),
14167 print_symbol_table_heading ();
14169 symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
14170 if (symtab
== NULL
)
14173 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
14175 strtab
= filedata
->string_table
;
14176 strtab_size
= filedata
->string_table_length
;
14178 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
14180 Elf_Internal_Shdr
* string_sec
;
14182 string_sec
= filedata
->section_headers
+ section
->sh_link
;
14184 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
14185 1, string_sec
->sh_size
,
14186 _("string table"));
14187 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
14190 for (si
= 0; si
< num_syms
; si
++)
14191 print_symbol (filedata
, si
, symtab
, section
,
14192 strtab
, strtab_size
);
14195 if (strtab
!= filedata
->string_table
)
14201 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
14203 if (do_histogram
&& filedata
->buckets
!= NULL
)
14209 uint64_t maxlength
= 0;
14210 uint64_t nzero_counts
= 0;
14211 uint64_t nsyms
= 0;
14214 printf (ngettext ("\nHistogram for bucket list length "
14215 "(total of %" PRIu64
" bucket):\n",
14216 "\nHistogram for bucket list length "
14217 "(total of %" PRIu64
" buckets):\n",
14218 filedata
->nbuckets
),
14219 filedata
->nbuckets
);
14221 lengths
= calloc (filedata
->nbuckets
, sizeof (*lengths
));
14222 if (lengths
== NULL
)
14224 error (_("Out of memory allocating space for histogram buckets\n"));
14227 visited
= xcmalloc (filedata
->nchains
, 1);
14228 memset (visited
, 0, filedata
->nchains
);
14230 printf (_(" Length Number %% of total Coverage\n"));
14231 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
14233 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
14236 if (maxlength
< ++lengths
[hn
])
14238 if (si
>= filedata
->nchains
|| visited
[si
])
14240 error (_("histogram chain is corrupt\n"));
14248 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
14249 if (counts
== NULL
)
14252 error (_("Out of memory allocating space for histogram counts\n"));
14256 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
14257 ++counts
[lengths
[hn
]];
14259 if (filedata
->nbuckets
> 0)
14262 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
14263 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
14264 for (i
= 1; i
<= maxlength
; ++i
)
14266 nzero_counts
+= counts
[i
] * i
;
14267 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
14268 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
14269 (nzero_counts
* 100.0) / nsyms
);
14277 free (filedata
->buckets
);
14278 filedata
->buckets
= NULL
;
14279 filedata
->nbuckets
= 0;
14280 free (filedata
->chains
);
14281 filedata
->chains
= NULL
;
14283 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
14288 uint64_t maxlength
= 0;
14289 uint64_t nzero_counts
= 0;
14290 uint64_t nsyms
= 0;
14292 printf (ngettext ("\nHistogram for `%s' bucket list length "
14293 "(total of %" PRIu64
" bucket):\n",
14294 "\nHistogram for `%s' bucket list length "
14295 "(total of %" PRIu64
" buckets):\n",
14296 filedata
->ngnubuckets
),
14297 GNU_HASH_SECTION_NAME (filedata
),
14298 filedata
->ngnubuckets
);
14300 lengths
= calloc (filedata
->ngnubuckets
, sizeof (*lengths
));
14301 if (lengths
== NULL
)
14303 error (_("Out of memory allocating space for gnu histogram buckets\n"));
14307 printf (_(" Length Number %% of total Coverage\n"));
14309 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
14310 if (filedata
->gnubuckets
[hn
] != 0)
14312 uint64_t off
, length
= 1;
14314 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
14315 /* PR 17531 file: 010-77222-0.004. */
14316 off
< filedata
->ngnuchains
14317 && (filedata
->gnuchains
[off
] & 1) == 0;
14320 lengths
[hn
] = length
;
14321 if (length
> maxlength
)
14322 maxlength
= length
;
14326 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
14327 if (counts
== NULL
)
14330 error (_("Out of memory allocating space for gnu histogram counts\n"));
14334 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
14335 ++counts
[lengths
[hn
]];
14337 if (filedata
->ngnubuckets
> 0)
14340 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
14341 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
14342 for (j
= 1; j
<= maxlength
; ++j
)
14344 nzero_counts
+= counts
[j
] * j
;
14345 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
14346 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
14347 (nzero_counts
* 100.0) / nsyms
);
14354 free (filedata
->gnubuckets
);
14355 filedata
->gnubuckets
= NULL
;
14356 filedata
->ngnubuckets
= 0;
14357 free (filedata
->gnuchains
);
14358 filedata
->gnuchains
= NULL
;
14359 filedata
->ngnuchains
= 0;
14360 free (filedata
->mipsxlat
);
14361 filedata
->mipsxlat
= NULL
;
14365 free (filedata
->gnubuckets
);
14366 filedata
->gnubuckets
= NULL
;
14367 filedata
->ngnubuckets
= 0;
14368 free (filedata
->gnuchains
);
14369 filedata
->gnuchains
= NULL
;
14370 filedata
->ngnuchains
= 0;
14371 free (filedata
->mipsxlat
);
14372 filedata
->mipsxlat
= NULL
;
14373 free (filedata
->buckets
);
14374 filedata
->buckets
= NULL
;
14375 filedata
->nbuckets
= 0;
14376 free (filedata
->chains
);
14377 filedata
->chains
= NULL
;
14382 process_syminfo (Filedata
* filedata
)
14386 if (filedata
->dynamic_syminfo
== NULL
14388 /* No syminfo, this is ok. */
14391 /* There better should be a dynamic symbol section. */
14392 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
14395 if (filedata
->is_separate
)
14396 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entry:\n",
14397 "\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entries:\n",
14398 filedata
->dynamic_syminfo_nent
),
14399 filedata
->file_name
,
14400 filedata
->dynamic_syminfo_offset
,
14401 filedata
->dynamic_syminfo_nent
);
14403 printf (ngettext ("\nDynamic info segment at offset %#" PRIx64
14404 " contains %d entry:\n",
14405 "\nDynamic info segment at offset %#" PRIx64
14406 " contains %d entries:\n",
14407 filedata
->dynamic_syminfo_nent
),
14408 filedata
->dynamic_syminfo_offset
,
14409 filedata
->dynamic_syminfo_nent
);
14411 printf (_(" Num: Name BoundTo Flags\n"));
14412 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
14414 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
14416 printf ("%4d: ", i
);
14417 if (i
>= filedata
->num_dynamic_syms
)
14418 printf (_("<corrupt index>"));
14419 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
14420 print_symbol_name (30, get_dynamic_name (filedata
,
14421 filedata
->dynamic_symbols
[i
].st_name
));
14423 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
14426 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
14428 case SYMINFO_BT_SELF
:
14429 fputs ("SELF ", stdout
);
14431 case SYMINFO_BT_PARENT
:
14432 fputs ("PARENT ", stdout
);
14435 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
14436 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
14437 && valid_dynamic_name (filedata
,
14438 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
14440 print_symbol_name (10, get_dynamic_name (filedata
,
14441 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
14445 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
14449 if (flags
& SYMINFO_FLG_DIRECT
)
14450 printf (" DIRECT");
14451 if (flags
& SYMINFO_FLG_PASSTHRU
)
14452 printf (" PASSTHRU");
14453 if (flags
& SYMINFO_FLG_COPY
)
14455 if (flags
& SYMINFO_FLG_LAZYLOAD
)
14456 printf (" LAZYLOAD");
14464 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
14465 is contained by the region START .. END. The types of ADDR, START
14466 and END should all be the same. Note both ADDR + NELEM and END
14467 point to just beyond the end of the regions that are being tested. */
14468 #define IN_RANGE(START,END,ADDR,NELEM) \
14469 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
14471 /* Check to see if the given reloc needs to be handled in a target specific
14472 manner. If so then process the reloc and return TRUE otherwise return
14475 If called with reloc == NULL, then this is a signal that reloc processing
14476 for the current section has finished, and any saved state should be
14480 target_specific_reloc_handling (Filedata
*filedata
,
14481 Elf_Internal_Rela
*reloc
,
14482 unsigned char *start
,
14483 unsigned char *end
,
14484 Elf_Internal_Sym
*symtab
,
14487 unsigned int reloc_type
= 0;
14488 uint64_t sym_index
= 0;
14492 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
14493 sym_index
= get_reloc_symindex (reloc
->r_info
);
14496 switch (filedata
->file_header
.e_machine
)
14500 switch (reloc_type
)
14502 /* For .uleb128 .LFE1-.LFB1, loongarch write 0 to object file
14503 at assembly time. */
14504 case 107: /* R_LARCH_ADD_ULEB128. */
14505 case 108: /* R_LARCH_SUB_ULEB128. */
14507 uint64_t value
= 0;
14508 unsigned int reloc_size
= 0;
14511 if (reloc
->r_offset
< (size_t) (end
- start
))
14512 value
= read_leb128 (start
+ reloc
->r_offset
, end
, false,
14513 &reloc_size
, &leb_ret
);
14514 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
14515 error (_("LoongArch ULEB128 field at 0x%lx contains invalid "
14516 "ULEB128 value\n"),
14517 (long) reloc
->r_offset
);
14519 else if (sym_index
>= num_syms
)
14520 error (_("%s reloc contains invalid symbol index "
14523 ? "R_LARCH_ADD_ULEB128"
14524 : "R_LARCH_SUB_ULEB128"),
14528 if (reloc_type
== 107)
14529 value
+= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
14531 value
-= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
14533 /* Write uleb128 value to p. */
14534 bfd_byte
*p
= start
+ reloc
->r_offset
;
14537 bfd_byte c
= value
& 0x7f;
14539 if (--reloc_size
!= 0)
14543 while (reloc_size
);
14553 case EM_MSP430_OLD
:
14555 static Elf_Internal_Sym
* saved_sym
= NULL
;
14563 switch (reloc_type
)
14565 case 10: /* R_MSP430_SYM_DIFF */
14566 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
14567 if (uses_msp430x_relocs (filedata
))
14569 /* Fall through. */
14570 case 21: /* R_MSP430X_SYM_DIFF */
14571 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
14573 if (sym_index
>= num_syms
)
14574 error (_("%s reloc contains invalid symbol index "
14575 "%" PRIu64
"\n"), "MSP430 SYM_DIFF", sym_index
);
14577 saved_sym
= symtab
+ sym_index
;
14580 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
14581 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
14582 goto handle_sym_diff
;
14584 case 5: /* R_MSP430_16_BYTE */
14585 case 9: /* R_MSP430_8 */
14586 case 11: /* R_MSP430_GNU_SET_ULEB128 */
14587 if (uses_msp430x_relocs (filedata
))
14589 goto handle_sym_diff
;
14591 case 2: /* R_MSP430_ABS16 */
14592 case 15: /* R_MSP430X_ABS16 */
14593 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
14594 if (! uses_msp430x_relocs (filedata
))
14596 goto handle_sym_diff
;
14599 if (saved_sym
!= NULL
)
14602 unsigned int reloc_size
= 0;
14604 switch (reloc_type
)
14606 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
14609 case 11: /* R_MSP430_GNU_SET_ULEB128 */
14610 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
14611 if (reloc
->r_offset
< (size_t) (end
- start
))
14612 read_leb128 (start
+ reloc
->r_offset
, end
, false,
14613 &reloc_size
, &leb_ret
);
14620 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
14621 error (_("MSP430 ULEB128 field at %#" PRIx64
14622 " contains invalid ULEB128 value\n"),
14624 else if (sym_index
>= num_syms
)
14625 error (_("%s reloc contains invalid symbol index "
14626 "%" PRIu64
"\n"), "MSP430", sym_index
);
14629 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14630 - saved_sym
->st_value
);
14632 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14633 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14636 error (_("MSP430 sym diff reloc contains invalid offset: "
14647 if (saved_sym
!= NULL
)
14648 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
14655 case EM_CYGNUS_MN10300
:
14657 static Elf_Internal_Sym
* saved_sym
= NULL
;
14665 switch (reloc_type
)
14667 case 34: /* R_MN10300_ALIGN */
14669 case 33: /* R_MN10300_SYM_DIFF */
14670 if (sym_index
>= num_syms
)
14671 error (_("%s reloc contains invalid symbol index "
14672 "%" PRIu64
"\n"), "MN10300_SYM_DIFF", sym_index
);
14674 saved_sym
= symtab
+ sym_index
;
14677 case 1: /* R_MN10300_32 */
14678 case 2: /* R_MN10300_16 */
14679 if (saved_sym
!= NULL
)
14681 int reloc_size
= reloc_type
== 1 ? 4 : 2;
14684 if (sym_index
>= num_syms
)
14685 error (_("%s reloc contains invalid symbol index "
14686 "%" PRIu64
"\n"), "MN10300", sym_index
);
14689 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14690 - saved_sym
->st_value
);
14692 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14693 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14695 error (_("MN10300 sym diff reloc contains invalid offset:"
14696 " %#" PRIx64
"\n"),
14705 if (saved_sym
!= NULL
)
14706 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
14714 static uint64_t saved_sym1
= 0;
14715 static uint64_t saved_sym2
= 0;
14716 static uint64_t value
;
14720 saved_sym1
= saved_sym2
= 0;
14724 switch (reloc_type
)
14726 case 0x80: /* R_RL78_SYM. */
14727 saved_sym1
= saved_sym2
;
14728 if (sym_index
>= num_syms
)
14729 error (_("%s reloc contains invalid symbol index "
14730 "%" PRIu64
"\n"), "RL78_SYM", sym_index
);
14733 saved_sym2
= symtab
[sym_index
].st_value
;
14734 saved_sym2
+= reloc
->r_addend
;
14738 case 0x83: /* R_RL78_OPsub. */
14739 value
= saved_sym1
- saved_sym2
;
14740 saved_sym2
= saved_sym1
= 0;
14744 case 0x41: /* R_RL78_ABS32. */
14745 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
14746 byte_put (start
+ reloc
->r_offset
, value
, 4);
14748 error (_("RL78 sym diff reloc contains invalid offset: "
14754 case 0x43: /* R_RL78_ABS16. */
14755 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
14756 byte_put (start
+ reloc
->r_offset
, value
, 2);
14758 error (_("RL78 sym diff reloc contains invalid offset: "
14774 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
14775 DWARF debug sections. This is a target specific test. Note - we do not
14776 go through the whole including-target-headers-multiple-times route, (as
14777 we have already done with <elf/h8.h>) because this would become very
14778 messy and even then this function would have to contain target specific
14779 information (the names of the relocs instead of their numeric values).
14780 FIXME: This is not the correct way to solve this problem. The proper way
14781 is to have target specific reloc sizing and typing functions created by
14782 the reloc-macros.h header, in the same way that it already creates the
14783 reloc naming functions. */
14786 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14788 /* Please keep this table alpha-sorted for ease of visual lookup. */
14789 switch (filedata
->file_header
.e_machine
)
14793 return reloc_type
== 1; /* R_386_32. */
14795 return reloc_type
== 1; /* R_68K_32. */
14797 return reloc_type
== 1; /* R_860_32. */
14799 return reloc_type
== 2; /* R_960_32. */
14801 return (reloc_type
== 258
14802 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
14804 return reloc_type
== 11; /* R_BPF_DATA_32 */
14805 case EM_ADAPTEVA_EPIPHANY
:
14806 return reloc_type
== 3;
14808 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
14810 return reloc_type
== 1; /* R_ARC_32. */
14811 case EM_ARC_COMPACT
:
14812 case EM_ARC_COMPACT2
:
14813 case EM_ARC_COMPACT3
:
14814 case EM_ARC_COMPACT3_64
:
14815 return reloc_type
== 4; /* R_ARC_32. */
14817 return reloc_type
== 2; /* R_ARM_ABS32 */
14820 return reloc_type
== 1;
14822 return reloc_type
== 0x12; /* R_byte4_data. */
14824 return reloc_type
== 3; /* R_CRIS_32. */
14826 return reloc_type
== 3; /* R_CR16_NUM32. */
14828 return reloc_type
== 15; /* R_CRX_NUM32. */
14830 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
14831 case EM_CYGNUS_FRV
:
14832 return reloc_type
== 1;
14833 case EM_CYGNUS_D10V
:
14835 return reloc_type
== 6; /* R_D10V_32. */
14836 case EM_CYGNUS_D30V
:
14838 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
14840 return reloc_type
== 3; /* R_DLX_RELOC_32. */
14841 case EM_CYGNUS_FR30
:
14843 return reloc_type
== 3; /* R_FR30_32. */
14845 return reloc_type
== 1; /* R_FT32_32. */
14849 return reloc_type
== 1; /* R_H8_DIR32. */
14851 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
14852 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
14853 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
14854 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
14857 return reloc_type
== 2; /* R_IP2K_32. */
14859 return reloc_type
== 2; /* R_IQ2000_32. */
14861 return reloc_type
== 2; /* R_KVX_32. */
14862 case EM_LATTICEMICO32
:
14863 return reloc_type
== 3; /* R_LM32_32. */
14865 return reloc_type
== 1; /* R_LARCH_32. */
14868 return reloc_type
== 3; /* R_M32C_32. */
14870 return reloc_type
== 34; /* R_M32R_32_RELA. */
14873 return reloc_type
== 6; /* R_M68HC11_32. */
14875 return reloc_type
== 7 || /* R_S12Z_EXT32 */
14876 reloc_type
== 6; /* R_S12Z_CW32. */
14878 return reloc_type
== 1; /* R_MCORE_ADDR32. */
14879 case EM_CYGNUS_MEP
:
14880 return reloc_type
== 4; /* R_MEP_32. */
14882 return reloc_type
== 2; /* R_METAG_ADDR32. */
14883 case EM_MICROBLAZE
:
14884 return reloc_type
== 1; /* R_MICROBLAZE_32. */
14886 return reloc_type
== 2; /* R_MIPS_32. */
14888 return reloc_type
== 4; /* R_MMIX_32. */
14889 case EM_CYGNUS_MN10200
:
14891 return reloc_type
== 1; /* R_MN10200_32. */
14892 case EM_CYGNUS_MN10300
:
14894 return reloc_type
== 1; /* R_MN10300_32. */
14896 return reloc_type
== 1; /* R_MOXIE_32. */
14897 case EM_MSP430_OLD
:
14899 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
14901 return reloc_type
== 2; /* R_MT_32. */
14903 return reloc_type
== 20; /* R_NDS32_32_RELA. */
14904 case EM_ALTERA_NIOS2
:
14905 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
14907 return reloc_type
== 1; /* R_NIOS_32. */
14909 return reloc_type
== 1; /* R_OR1K_32. */
14911 return (reloc_type
== 1 /* R_PARISC_DIR32. */
14912 || reloc_type
== 2 /* R_PARISC_DIR21L. */
14913 || reloc_type
== 41); /* R_PARISC_SECREL32. */
14916 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
14918 return reloc_type
== 1; /* R_PPC64_ADDR32. */
14920 return reloc_type
== 1; /* R_PPC_ADDR32. */
14922 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
14924 return reloc_type
== 1; /* R_RISCV_32. */
14926 return reloc_type
== 1; /* R_RL78_DIR32. */
14928 return reloc_type
== 1; /* R_RX_DIR32. */
14930 return reloc_type
== 1; /* R_I370_ADDR31. */
14933 return reloc_type
== 4; /* R_S390_32. */
14935 return reloc_type
== 8; /* R_SCORE_ABS32. */
14937 return reloc_type
== 1; /* R_SH_DIR32. */
14938 case EM_SPARC32PLUS
:
14941 return reloc_type
== 3 /* R_SPARC_32. */
14942 || reloc_type
== 23; /* R_SPARC_UA32. */
14944 return reloc_type
== 6; /* R_SPU_ADDR32 */
14946 return reloc_type
== 1; /* R_C6000_ABS32. */
14948 return reloc_type
== 2; /* R_TILEGX_32. */
14950 return reloc_type
== 1; /* R_TILEPRO_32. */
14951 case EM_CYGNUS_V850
:
14953 return reloc_type
== 6; /* R_V850_ABS32. */
14955 return reloc_type
== 0x33; /* R_V810_WORD. */
14957 return reloc_type
== 1; /* R_VAX_32. */
14959 return reloc_type
== 3; /* R_VISIUM_32. */
14960 case EM_WEBASSEMBLY
:
14961 return reloc_type
== 1; /* R_WASM32_32. */
14965 return reloc_type
== 10; /* R_X86_64_32. */
14967 return reloc_type
== 4; /* R_XGATE_32. */
14969 return reloc_type
== 1; /* R_XSTROMY16_32. */
14970 case EM_XTENSA_OLD
:
14972 return reloc_type
== 1; /* R_XTENSA_32. */
14974 return reloc_type
== 6; /* R_Z80_32. */
14977 static unsigned int prev_warn
= 0;
14979 /* Avoid repeating the same warning multiple times. */
14980 if (prev_warn
!= filedata
->file_header
.e_machine
)
14981 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
14982 filedata
->file_header
.e_machine
);
14983 prev_warn
= filedata
->file_header
.e_machine
;
14989 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14990 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
14993 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14995 switch (filedata
->file_header
.e_machine
)
14996 /* Please keep this table alpha-sorted for ease of visual lookup. */
15000 return reloc_type
== 2; /* R_386_PC32. */
15002 return reloc_type
== 4; /* R_68K_PC32. */
15004 return reloc_type
== 261; /* R_AARCH64_PREL32 */
15005 case EM_ADAPTEVA_EPIPHANY
:
15006 return reloc_type
== 6;
15008 return reloc_type
== 10; /* R_ALPHA_SREL32. */
15009 case EM_ARC_COMPACT
:
15010 case EM_ARC_COMPACT2
:
15011 case EM_ARC_COMPACT3
:
15012 case EM_ARC_COMPACT3_64
:
15013 return reloc_type
== 49; /* R_ARC_32_PCREL. */
15015 return reloc_type
== 3; /* R_ARM_REL32 */
15018 return reloc_type
== 36; /* R_AVR_32_PCREL. */
15020 return reloc_type
== 99; /* R_LARCH_32_PCREL. */
15021 case EM_MICROBLAZE
:
15022 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
15024 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
15026 return reloc_type
== 9; /* R_PARISC_PCREL32. */
15028 return reloc_type
== 26; /* R_PPC_REL32. */
15030 return reloc_type
== 26; /* R_PPC64_REL32. */
15032 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
15035 return reloc_type
== 5; /* R_390_PC32. */
15037 return reloc_type
== 2; /* R_SH_REL32. */
15038 case EM_SPARC32PLUS
:
15041 return reloc_type
== 6; /* R_SPARC_DISP32. */
15043 return reloc_type
== 13; /* R_SPU_REL32. */
15045 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
15047 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
15049 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
15053 return reloc_type
== 2; /* R_X86_64_PC32. */
15055 return reloc_type
== 4; /* R_VAX_PCREL32. */
15056 case EM_XTENSA_OLD
:
15058 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
15060 return reloc_type
== 7; /* R_KVX_32_PCREL */
15062 /* Do not abort or issue an error message here. Not all targets use
15063 pc-relative 32-bit relocs in their DWARF debug information and we
15064 have already tested for target coverage in is_32bit_abs_reloc. A
15065 more helpful warning message will be generated by apply_relocations
15066 anyway, so just return. */
15071 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15072 a 64-bit absolute RELA relocation used in DWARF debug sections. */
15075 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15077 switch (filedata
->file_header
.e_machine
)
15080 return reloc_type
== 257; /* R_AARCH64_ABS64. */
15081 case EM_ARC_COMPACT3_64
:
15082 return reloc_type
== 5; /* R_ARC_64. */
15084 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
15086 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
15087 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
15089 return reloc_type
== 2; /* R_LARCH_64 */
15091 return reloc_type
== 80; /* R_PARISC_DIR64. */
15093 return reloc_type
== 38; /* R_PPC64_ADDR64. */
15095 return reloc_type
== 2; /* R_RISCV_64. */
15096 case EM_SPARC32PLUS
:
15099 return reloc_type
== 32 /* R_SPARC_64. */
15100 || reloc_type
== 54; /* R_SPARC_UA64. */
15104 return reloc_type
== 1; /* R_X86_64_64. */
15107 return reloc_type
== 22; /* R_S390_64. */
15109 return reloc_type
== 1; /* R_TILEGX_64. */
15111 return reloc_type
== 18; /* R_MIPS_64. */
15113 return reloc_type
== 3; /* R_KVX_64 */
15119 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
15120 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
15123 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15125 switch (filedata
->file_header
.e_machine
)
15128 return reloc_type
== 260; /* R_AARCH64_PREL64. */
15130 return reloc_type
== 11; /* R_ALPHA_SREL64. */
15132 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
15133 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
15135 return reloc_type
== 72; /* R_PARISC_PCREL64. */
15137 return reloc_type
== 44; /* R_PPC64_REL64. */
15138 case EM_SPARC32PLUS
:
15141 return reloc_type
== 46; /* R_SPARC_DISP64. */
15145 return reloc_type
== 24; /* R_X86_64_PC64. */
15148 return reloc_type
== 23; /* R_S390_PC64. */
15150 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
15156 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15157 a 24-bit absolute RELA relocation used in DWARF debug sections. */
15160 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15162 switch (filedata
->file_header
.e_machine
)
15164 case EM_CYGNUS_MN10200
:
15166 return reloc_type
== 4; /* R_MN10200_24. */
15168 return reloc_type
== 5; /* R_FT32_20. */
15170 return reloc_type
== 5; /* R_Z80_24. */
15176 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15177 a 16-bit absolute RELA relocation used in DWARF debug sections. */
15180 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15182 /* Please keep this table alpha-sorted for ease of visual lookup. */
15183 switch (filedata
->file_header
.e_machine
)
15186 case EM_ARC_COMPACT
:
15187 case EM_ARC_COMPACT2
:
15188 case EM_ARC_COMPACT3
:
15189 case EM_ARC_COMPACT3_64
:
15190 return reloc_type
== 2; /* R_ARC_16. */
15191 case EM_ADAPTEVA_EPIPHANY
:
15192 return reloc_type
== 5;
15195 return reloc_type
== 4; /* R_AVR_16. */
15196 case EM_CYGNUS_D10V
:
15198 return reloc_type
== 3; /* R_D10V_16. */
15200 return reloc_type
== 2; /* R_FT32_16. */
15204 return reloc_type
== R_H8_DIR16
;
15207 return reloc_type
== 1; /* R_IP2K_16. */
15210 return reloc_type
== 1; /* R_M32C_16 */
15211 case EM_CYGNUS_MN10200
:
15213 return reloc_type
== 2; /* R_MN10200_16. */
15214 case EM_CYGNUS_MN10300
:
15216 return reloc_type
== 2; /* R_MN10300_16. */
15218 return reloc_type
== 1; /* R_KVX_16 */
15220 if (uses_msp430x_relocs (filedata
))
15221 return reloc_type
== 2; /* R_MSP430_ABS16. */
15222 /* Fall through. */
15223 case EM_MSP430_OLD
:
15224 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
15226 return reloc_type
== 19; /* R_NDS32_16_RELA. */
15227 case EM_ALTERA_NIOS2
:
15228 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
15230 return reloc_type
== 9; /* R_NIOS_16. */
15232 return reloc_type
== 2; /* R_OR1K_16. */
15234 return reloc_type
== 55; /* R_RISCV_SET16. */
15236 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
15238 return reloc_type
== 2; /* R_C6000_ABS16. */
15240 return reloc_type
== 2; /* R_VISIUM_16. */
15242 return reloc_type
== 3; /* R_XGATE_16. */
15244 return reloc_type
== 4; /* R_Z80_16. */
15250 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15251 a 8-bit absolute RELA relocation used in DWARF debug sections. */
15254 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15256 switch (filedata
->file_header
.e_machine
)
15259 return reloc_type
== 54; /* R_RISCV_SET8. */
15261 return reloc_type
== 1; /* R_Z80_8. */
15267 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15268 a 6-bit absolute RELA relocation used in DWARF debug sections. */
15271 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15273 switch (filedata
->file_header
.e_machine
)
15276 return reloc_type
== 53; /* R_RISCV_SET6. */
15282 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15283 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
15286 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15288 /* Please keep this table alpha-sorted for ease of visual lookup. */
15289 switch (filedata
->file_header
.e_machine
)
15292 return reloc_type
== 50; /* R_LARCH_ADD32. */
15294 return reloc_type
== 35; /* R_RISCV_ADD32. */
15300 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15301 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
15304 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15306 /* Please keep this table alpha-sorted for ease of visual lookup. */
15307 switch (filedata
->file_header
.e_machine
)
15310 return reloc_type
== 55; /* R_LARCH_SUB32. */
15312 return reloc_type
== 39; /* R_RISCV_SUB32. */
15318 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15319 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
15322 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15324 /* Please keep this table alpha-sorted for ease of visual lookup. */
15325 switch (filedata
->file_header
.e_machine
)
15328 return reloc_type
== 51; /* R_LARCH_ADD64. */
15330 return reloc_type
== 36; /* R_RISCV_ADD64. */
15336 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15337 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
15340 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15342 /* Please keep this table alpha-sorted for ease of visual lookup. */
15343 switch (filedata
->file_header
.e_machine
)
15346 return reloc_type
== 56; /* R_LARCH_SUB64. */
15348 return reloc_type
== 40; /* R_RISCV_SUB64. */
15354 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15355 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
15358 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15360 /* Please keep this table alpha-sorted for ease of visual lookup. */
15361 switch (filedata
->file_header
.e_machine
)
15364 return reloc_type
== 48; /* R_LARCH_ADD16. */
15366 return reloc_type
== 34; /* R_RISCV_ADD16. */
15372 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15373 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
15376 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15378 /* Please keep this table alpha-sorted for ease of visual lookup. */
15379 switch (filedata
->file_header
.e_machine
)
15382 return reloc_type
== 53; /* R_LARCH_SUB16. */
15384 return reloc_type
== 38; /* R_RISCV_SUB16. */
15390 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15391 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
15394 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15396 /* Please keep this table alpha-sorted for ease of visual lookup. */
15397 switch (filedata
->file_header
.e_machine
)
15400 return reloc_type
== 47; /* R_LARCH_ADD8. */
15402 return reloc_type
== 33; /* R_RISCV_ADD8. */
15408 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15409 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
15412 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15414 /* Please keep this table alpha-sorted for ease of visual lookup. */
15415 switch (filedata
->file_header
.e_machine
)
15418 return reloc_type
== 52; /* R_LARCH_SUB8. */
15420 return reloc_type
== 37; /* R_RISCV_SUB8. */
15426 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15427 a 6-bit inplace add RELA relocation used in DWARF debug sections. */
15430 is_6bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15432 switch (filedata
->file_header
.e_machine
)
15435 return reloc_type
== 105; /* R_LARCH_ADD6. */
15441 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
15442 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
15445 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15447 switch (filedata
->file_header
.e_machine
)
15450 return reloc_type
== 106; /* R_LARCH_SUB6. */
15452 return reloc_type
== 52; /* R_RISCV_SUB6. */
15458 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
15459 relocation entries (possibly formerly used for SHT_GROUP sections). */
15462 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15464 switch (filedata
->file_header
.e_machine
)
15466 case EM_386
: /* R_386_NONE. */
15467 case EM_68K
: /* R_68K_NONE. */
15468 case EM_ADAPTEVA_EPIPHANY
:
15469 case EM_ALPHA
: /* R_ALPHA_NONE. */
15470 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
15471 case EM_ARC
: /* R_ARC_NONE. */
15472 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
15473 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
15474 case EM_ARC_COMPACT3
: /* R_ARC_NONE. */
15475 case EM_ARC_COMPACT3_64
: /* R_ARC_NONE. */
15476 case EM_ARM
: /* R_ARM_NONE. */
15477 case EM_CRIS
: /* R_CRIS_NONE. */
15478 case EM_FT32
: /* R_FT32_NONE. */
15479 case EM_IA_64
: /* R_IA64_NONE. */
15480 case EM_K1OM
: /* R_X86_64_NONE. */
15481 case EM_KVX
: /* R_KVX_NONE. */
15482 case EM_L1OM
: /* R_X86_64_NONE. */
15483 case EM_M32R
: /* R_M32R_NONE. */
15484 case EM_MIPS
: /* R_MIPS_NONE. */
15485 case EM_MN10300
: /* R_MN10300_NONE. */
15486 case EM_MOXIE
: /* R_MOXIE_NONE. */
15487 case EM_NIOS32
: /* R_NIOS_NONE. */
15488 case EM_OR1K
: /* R_OR1K_NONE. */
15489 case EM_PARISC
: /* R_PARISC_NONE. */
15490 case EM_PPC64
: /* R_PPC64_NONE. */
15491 case EM_PPC
: /* R_PPC_NONE. */
15492 case EM_RISCV
: /* R_RISCV_NONE. */
15493 case EM_S390
: /* R_390_NONE. */
15495 case EM_SH
: /* R_SH_NONE. */
15496 case EM_SPARC32PLUS
:
15497 case EM_SPARC
: /* R_SPARC_NONE. */
15499 case EM_TILEGX
: /* R_TILEGX_NONE. */
15500 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
15501 case EM_TI_C6000
:/* R_C6000_NONE. */
15502 case EM_X86_64
: /* R_X86_64_NONE. */
15503 case EM_Z80
: /* R_Z80_NONE. */
15504 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
15505 return reloc_type
== 0;
15508 return reloc_type
== 0 || reloc_type
== 256;
15511 return (reloc_type
== 0 /* R_AVR_NONE. */
15512 || reloc_type
== 30 /* R_AVR_DIFF8. */
15513 || reloc_type
== 31 /* R_AVR_DIFF16. */
15514 || reloc_type
== 32 /* R_AVR_DIFF32. */);
15516 return reloc_type
== 3; /* R_METAG_NONE. */
15518 return (reloc_type
== 0 /* R_NDS32_NONE. */
15519 || reloc_type
== 205 /* R_NDS32_DIFF8. */
15520 || reloc_type
== 206 /* R_NDS32_DIFF16. */
15521 || reloc_type
== 207 /* R_NDS32_DIFF32. */
15522 || reloc_type
== 208 /* R_NDS32_DIFF_ULEB128. */);
15524 return (reloc_type
== 0 /* R_PRU_NONE. */
15525 || reloc_type
== 65 /* R_PRU_DIFF8. */
15526 || reloc_type
== 66 /* R_PRU_DIFF16. */
15527 || reloc_type
== 67 /* R_PRU_DIFF32. */);
15528 case EM_XTENSA_OLD
:
15530 return (reloc_type
== 0 /* R_XTENSA_NONE. */
15531 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
15532 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
15533 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
15534 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
15535 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
15536 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
15537 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
15538 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
15539 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
15544 /* Returns TRUE if there is a relocation against
15545 section NAME at OFFSET bytes. */
15548 reloc_at (struct dwarf_section
* dsec
, uint64_t offset
)
15550 Elf_Internal_Rela
* relocs
;
15551 Elf_Internal_Rela
* rp
;
15553 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
15556 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
15558 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
15559 if (rp
->r_offset
== offset
)
15565 /* Apply relocations to a section.
15566 Returns TRUE upon success, FALSE otherwise.
15567 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
15568 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
15569 will be set to the number of relocs loaded.
15571 Note: So far support has been added only for those relocations
15572 which can be found in debug sections. FIXME: Add support for
15573 more relocations ? */
15576 apply_relocations (Filedata
*filedata
,
15577 const Elf_Internal_Shdr
*section
,
15578 unsigned char *start
,
15580 void **relocs_return
,
15581 uint64_t *num_relocs_return
)
15583 Elf_Internal_Shdr
* relsec
;
15584 unsigned char * end
= start
+ size
;
15586 if (relocs_return
!= NULL
)
15588 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
15589 * num_relocs_return
= 0;
15592 if (filedata
->file_header
.e_type
!= ET_REL
)
15593 /* No relocs to apply. */
15596 /* Find the reloc section associated with the section. */
15597 for (relsec
= filedata
->section_headers
;
15598 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15602 uint64_t num_relocs
;
15603 Elf_Internal_Rela
* relocs
;
15604 Elf_Internal_Rela
* rp
;
15605 Elf_Internal_Shdr
* symsec
;
15606 Elf_Internal_Sym
* symtab
;
15608 Elf_Internal_Sym
* sym
;
15610 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15611 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15612 || filedata
->section_headers
+ relsec
->sh_info
!= section
15613 || relsec
->sh_size
== 0
15614 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15617 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
15618 if (symsec
->sh_type
!= SHT_SYMTAB
15619 && symsec
->sh_type
!= SHT_DYNSYM
)
15622 is_rela
= relsec
->sh_type
== SHT_RELA
;
15626 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
15627 relsec
->sh_size
, & relocs
, & num_relocs
))
15632 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
15633 relsec
->sh_size
, & relocs
, & num_relocs
))
15637 /* SH uses RELA but uses in place value instead of the addend field. */
15638 if (filedata
->file_header
.e_machine
== EM_SH
)
15641 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
15643 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
15646 unsigned int reloc_type
;
15647 unsigned int reloc_size
;
15648 bool reloc_inplace
= false;
15649 bool reloc_subtract
= false;
15650 unsigned char *rloc
;
15651 uint64_t sym_index
;
15653 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
15655 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
15657 else if (is_none_reloc (filedata
, reloc_type
))
15659 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
15660 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
15662 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
15663 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15665 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
15667 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
15669 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
15670 || is_6bit_abs_reloc (filedata
, reloc_type
))
15672 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
15674 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
15677 reloc_inplace
= true;
15679 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
15681 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
15684 reloc_inplace
= true;
15686 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
15688 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
15691 reloc_inplace
= true;
15693 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
15695 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
15698 reloc_inplace
= true;
15700 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
15702 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
15705 reloc_inplace
= true;
15709 static unsigned int prev_reloc
= 0;
15711 if (reloc_type
!= prev_reloc
)
15712 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
15713 reloc_type
, printable_section_name (filedata
, section
));
15714 prev_reloc
= reloc_type
;
15718 rloc
= start
+ rp
->r_offset
;
15719 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
15721 warn (_("skipping invalid relocation offset %#" PRIx64
15722 " in section %s\n"),
15724 printable_section_name (filedata
, section
));
15728 sym_index
= get_reloc_symindex (rp
->r_info
);
15729 if (sym_index
>= num_syms
)
15731 warn (_("skipping invalid relocation symbol index %#" PRIx64
15732 " in section %s\n"),
15733 sym_index
, printable_section_name (filedata
, section
));
15736 sym
= symtab
+ sym_index
;
15738 /* If the reloc has a symbol associated with it,
15739 make sure that it is of an appropriate type.
15741 Relocations against symbols without type can happen.
15742 Gcc -feliminate-dwarf2-dups may generate symbols
15743 without type for debug info.
15745 Icc generates relocations against function symbols
15746 instead of local labels.
15748 Relocations against object symbols can happen, eg when
15749 referencing a global array. For an example of this see
15750 the _clz.o binary in libgcc.a. */
15752 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
15753 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
15755 warn (_("skipping unexpected symbol type %s in section %s relocation %tu\n"),
15756 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
15757 printable_section_name (filedata
, relsec
),
15764 addend
+= rp
->r_addend
;
15765 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
15766 partial_inplace. */
15768 || (filedata
->file_header
.e_machine
== EM_XTENSA
15769 && reloc_type
== 1)
15770 || ((filedata
->file_header
.e_machine
== EM_PJ
15771 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
15772 && reloc_type
== 1)
15773 || ((filedata
->file_header
.e_machine
== EM_D30V
15774 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
15775 && reloc_type
== 12)
15778 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15779 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
15781 addend
+= byte_get (rloc
, reloc_size
);
15784 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
15785 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15787 /* On HPPA, all pc-relative relocations are biased by 8. */
15788 if (filedata
->file_header
.e_machine
== EM_PARISC
)
15790 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
15793 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
15794 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
)
15795 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
15797 if (reloc_subtract
)
15798 addend
-= sym
->st_value
;
15800 addend
+= sym
->st_value
;
15801 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
15802 byte_put (rloc
, addend
, reloc_size
);
15804 else if (reloc_subtract
)
15805 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
15807 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
15811 /* Let the target specific reloc processing code know that
15812 we have finished with these relocs. */
15813 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
15817 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
15818 * num_relocs_return
= num_relocs
;
15829 #ifdef SUPPORT_DISASSEMBLY
15831 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15833 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
15835 /* FIXME: XXX -- to be done --- XXX */
15841 /* Reads in the contents of SECTION from FILE, returning a pointer
15842 to a malloc'ed buffer or NULL if something went wrong. */
15845 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15847 uint64_t num_bytes
= section
->sh_size
;
15849 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
15851 printf (_("Section '%s' has no data to dump.\n"),
15852 printable_section_name (filedata
, section
));
15856 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
15857 _("section contents"));
15860 /* Uncompresses a section that was compressed using zlib/zstd, in place. */
15863 uncompress_section_contents (bool is_zstd
,
15864 unsigned char ** buffer
,
15865 uint64_t uncompressed_size
,
15867 uint64_t file_size
)
15869 uint64_t compressed_size
= *size
;
15870 unsigned char *compressed_buffer
= *buffer
;
15871 unsigned char *uncompressed_buffer
= NULL
;
15875 /* Similar to _bfd_section_size_insane() in the BFD library we expect an
15876 upper limit of ~10x compression. Any compression larger than that is
15877 thought to be due to fuzzing of the compression header. */
15878 if (uncompressed_size
> file_size
* 10)
15880 error (_("Uncompressed section size is suspiciously large: 0x%" PRIu64
"\n"),
15881 uncompressed_size
);
15885 uncompressed_buffer
= xmalloc (uncompressed_size
);
15890 size_t ret
= ZSTD_decompress (uncompressed_buffer
, uncompressed_size
,
15891 compressed_buffer
, compressed_size
);
15892 if (ZSTD_isError (ret
))
15898 /* It is possible the section consists of several compressed
15899 buffers concatenated together, so we uncompress in a loop. */
15900 /* PR 18313: The state field in the z_stream structure is supposed
15901 to be invisible to the user (ie us), but some compilers will
15902 still complain about it being used without initialisation. So
15903 we first zero the entire z_stream structure and then set the fields
15905 memset (&strm
, 0, sizeof strm
);
15906 strm
.avail_in
= compressed_size
;
15907 strm
.next_in
= (Bytef
*)compressed_buffer
;
15908 strm
.avail_out
= uncompressed_size
;
15910 rc
= inflateInit (&strm
);
15911 while (strm
.avail_in
> 0)
15915 strm
.next_out
= ((Bytef
*)uncompressed_buffer
15916 + (uncompressed_size
- strm
.avail_out
));
15917 rc
= inflate (&strm
, Z_FINISH
);
15918 if (rc
!= Z_STREAM_END
)
15920 rc
= inflateReset (&strm
);
15922 if (inflateEnd (&strm
) != Z_OK
|| rc
!= Z_OK
|| strm
.avail_out
!= 0)
15926 *buffer
= uncompressed_buffer
;
15927 *size
= uncompressed_size
;
15931 free (uncompressed_buffer
);
15932 /* Indicate decompression failure. */
15938 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15940 Elf_Internal_Shdr
*relsec
;
15941 uint64_t num_bytes
;
15942 unsigned char *data
;
15943 unsigned char *end
;
15944 unsigned char *real_start
;
15945 unsigned char *start
;
15946 bool some_strings_shown
;
15948 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
15950 /* PR 21820: Do not fail if the section was empty. */
15951 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
15953 num_bytes
= section
->sh_size
;
15955 if (filedata
->is_separate
)
15956 printf (_("\nString dump of section '%s' in linked file %s:\n"),
15957 printable_section_name (filedata
, section
),
15958 filedata
->file_name
);
15960 printf (_("\nString dump of section '%s':\n"),
15961 printable_section_name (filedata
, section
));
15963 if (decompress_dumps
)
15965 uint64_t new_size
= num_bytes
;
15966 uint64_t uncompressed_size
= 0;
15967 bool is_zstd
= false;
15969 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15971 Elf_Internal_Chdr chdr
;
15972 unsigned int compression_header_size
15973 = get_compression_header (& chdr
, (unsigned char *) start
,
15975 if (compression_header_size
== 0)
15976 /* An error message will have already been generated
15977 by get_compression_header. */
15980 if (chdr
.ch_type
== ch_compress_zlib
)
15983 else if (chdr
.ch_type
== ch_compress_zstd
)
15988 warn (_("section '%s' has unsupported compress type: %d\n"),
15989 printable_section_name (filedata
, section
), chdr
.ch_type
);
15992 uncompressed_size
= chdr
.ch_size
;
15993 start
+= compression_header_size
;
15994 new_size
-= compression_header_size
;
15996 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15998 /* Read the zlib header. In this case, it should be "ZLIB"
15999 followed by the uncompressed section size, 8 bytes in
16000 big-endian order. */
16001 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
16002 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
16003 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
16004 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
16005 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
16006 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
16007 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
16008 uncompressed_size
+= start
[11];
16013 if (uncompressed_size
)
16015 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
16016 &new_size
, filedata
->file_size
))
16017 num_bytes
= new_size
;
16020 error (_("Unable to decompress section %s\n"),
16021 printable_section_name (filedata
, section
));
16026 start
= real_start
;
16029 /* If the section being dumped has relocations against it the user might
16030 be expecting these relocations to have been applied. Check for this
16031 case and issue a warning message in order to avoid confusion.
16032 FIXME: Maybe we ought to have an option that dumps a section with
16033 relocs applied ? */
16034 for (relsec
= filedata
->section_headers
;
16035 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
16038 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
16039 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
16040 || filedata
->section_headers
+ relsec
->sh_info
!= section
16041 || relsec
->sh_size
== 0
16042 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
16045 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
16050 end
= start
+ num_bytes
;
16051 some_strings_shown
= false;
16053 #ifdef HAVE_MBSTATE_T
16055 /* Initialise the multibyte conversion state. */
16056 memset (& state
, 0, sizeof (state
));
16059 bool continuing
= false;
16063 while (!ISPRINT (* data
))
16064 if (++ data
>= end
)
16069 size_t maxlen
= end
- data
;
16074 continuing
= false;
16078 printf (" [%6tx] ", data
- start
);
16092 /* PR 25543: Treat new-lines as string-ending characters. */
16101 /* Do not print control characters directly as they can affect terminal
16102 settings. Such characters usually appear in the names generated
16103 by the assembler for local labels. */
16106 printf ("^%c", c
+ 0x40);
16108 else if (ISPRINT (c
))
16115 #ifdef HAVE_MBSTATE_T
16118 /* Let printf do the hard work of displaying multibyte characters. */
16119 printf ("%.1s", data
- 1);
16120 #ifdef HAVE_MBSTATE_T
16121 /* Try to find out how many bytes made up the character that was
16122 just printed. Advance the symbol pointer past the bytes that
16124 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
16128 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
16138 printf (_("<corrupt>\n"));
16141 some_strings_shown
= true;
16145 if (! some_strings_shown
)
16146 printf (_(" No strings found in this section."));
16159 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
16160 Filedata
*filedata
,
16163 Elf_Internal_Shdr
*relsec
;
16165 uint64_t section_size
;
16167 unsigned char *data
;
16168 unsigned char *real_start
;
16169 unsigned char *start
;
16171 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
16173 /* PR 21820: Do not fail if the section was empty. */
16174 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
16176 section_size
= section
->sh_size
;
16178 if (filedata
->is_separate
)
16179 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
16180 printable_section_name (filedata
, section
),
16181 filedata
->file_name
);
16183 printf (_("\nHex dump of section '%s':\n"),
16184 printable_section_name (filedata
, section
));
16186 if (decompress_dumps
)
16188 uint64_t new_size
= section_size
;
16189 uint64_t uncompressed_size
= 0;
16190 bool is_zstd
= false;
16192 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
16194 Elf_Internal_Chdr chdr
;
16195 unsigned int compression_header_size
16196 = get_compression_header (& chdr
, start
, section_size
);
16198 if (compression_header_size
== 0)
16199 /* An error message will have already been generated
16200 by get_compression_header. */
16203 if (chdr
.ch_type
== ch_compress_zlib
)
16206 else if (chdr
.ch_type
== ch_compress_zstd
)
16211 warn (_("section '%s' has unsupported compress type: %d\n"),
16212 printable_section_name (filedata
, section
), chdr
.ch_type
);
16215 uncompressed_size
= chdr
.ch_size
;
16216 start
+= compression_header_size
;
16217 new_size
-= compression_header_size
;
16219 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
16221 /* Read the zlib header. In this case, it should be "ZLIB"
16222 followed by the uncompressed section size, 8 bytes in
16223 big-endian order. */
16224 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
16225 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
16226 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
16227 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
16228 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
16229 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
16230 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
16231 uncompressed_size
+= start
[11];
16236 if (uncompressed_size
)
16238 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
16239 &new_size
, filedata
->file_size
))
16241 section_size
= new_size
;
16245 error (_("Unable to decompress section %s\n"),
16246 printable_section_name (filedata
, section
));
16247 /* FIXME: Print the section anyway ? */
16252 start
= real_start
;
16257 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
16262 /* If the section being dumped has relocations against it the user might
16263 be expecting these relocations to have been applied. Check for this
16264 case and issue a warning message in order to avoid confusion.
16265 FIXME: Maybe we ought to have an option that dumps a section with
16266 relocs applied ? */
16267 for (relsec
= filedata
->section_headers
;
16268 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
16271 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
16272 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
16273 || filedata
->section_headers
+ relsec
->sh_info
!= section
16274 || relsec
->sh_size
== 0
16275 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
16278 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
16283 addr
= section
->sh_addr
;
16284 bytes
= section_size
;
16293 lbytes
= (bytes
> 16 ? 16 : bytes
);
16295 printf (" 0x%8.8" PRIx64
" ", addr
);
16297 for (j
= 0; j
< 16; j
++)
16300 printf ("%2.2x", data
[j
]);
16308 for (j
= 0; j
< lbytes
; j
++)
16311 if (k
>= ' ' && k
< 0x7f)
16334 #ifdef ENABLE_LIBCTF
16335 static ctf_sect_t
*
16336 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
16338 buf
->cts_name
= printable_section_name (filedata
, shdr
);
16339 buf
->cts_size
= shdr
->sh_size
;
16340 buf
->cts_entsize
= shdr
->sh_entsize
;
16345 /* Formatting callback function passed to ctf_dump. Returns either the pointer
16346 it is passed, or a pointer to newly-allocated storage, in which case
16347 dump_ctf() will free it when it no longer needs it. */
16350 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
16351 char *s
, void *arg
)
16353 const char *blanks
= arg
;
16356 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
16361 /* Dump CTF errors/warnings. */
16363 dump_ctf_errs (ctf_dict_t
*fp
)
16365 ctf_next_t
*it
= NULL
;
16370 /* Dump accumulated errors and warnings. */
16371 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
16373 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
16377 if (err
!= ECTF_NEXT_END
)
16378 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
16381 /* Dump one CTF archive member. */
16384 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
16387 const char *things
[] = {"Header", "Labels", "Data objects",
16388 "Function objects", "Variables", "Types", "Strings",
16390 const char **thing
;
16393 /* Don't print out the name of the default-named archive member if it appears
16394 first in the list. The name .ctf appears everywhere, even for things that
16395 aren't really archives, so printing it out is liable to be confusing; also,
16396 the common case by far is for only one archive member to exist, and hiding
16397 it in that case seems worthwhile. */
16399 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
16400 printf (_("\nCTF archive member: %s:\n"), name
);
16402 if (ctf_parent_name (ctf
) != NULL
)
16403 ctf_import (ctf
, parent
);
16405 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
16407 ctf_dump_state_t
*s
= NULL
;
16410 printf ("\n %s:\n", *thing
);
16411 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
16412 (void *) " ")) != NULL
)
16414 printf ("%s\n", item
);
16418 if (ctf_errno (ctf
))
16420 error (_("Iteration failed: %s, %s\n"), *thing
,
16421 ctf_errmsg (ctf_errno (ctf
)));
16426 dump_ctf_errs (ctf
);
16430 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16432 Elf_Internal_Shdr
* symtab_sec
= NULL
;
16433 Elf_Internal_Shdr
* strtab_sec
= NULL
;
16434 void * data
= NULL
;
16435 void * symdata
= NULL
;
16436 void * strdata
= NULL
;
16437 ctf_sect_t ctfsect
, symsect
, strsect
;
16438 ctf_sect_t
* symsectp
= NULL
;
16439 ctf_sect_t
* strsectp
= NULL
;
16440 ctf_archive_t
* ctfa
= NULL
;
16441 ctf_dict_t
* parent
= NULL
;
16444 ctf_next_t
*i
= NULL
;
16450 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
16451 data
= get_section_contents (section
, filedata
);
16452 ctfsect
.cts_data
= data
;
16454 if (!dump_ctf_symtab_name
)
16455 dump_ctf_symtab_name
= strdup (".dynsym");
16457 if (!dump_ctf_strtab_name
)
16458 dump_ctf_strtab_name
= strdup (".dynstr");
16460 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
16462 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
16464 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
16467 if ((symdata
= (void *) get_data (NULL
, filedata
,
16468 symtab_sec
->sh_offset
, 1,
16469 symtab_sec
->sh_size
,
16470 _("symbols"))) == NULL
)
16472 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
16473 symsect
.cts_data
= symdata
;
16476 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
16478 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
16480 error (_("No string table section named %s\n"),
16481 dump_ctf_strtab_name
);
16484 if ((strdata
= (void *) get_data (NULL
, filedata
,
16485 strtab_sec
->sh_offset
, 1,
16486 strtab_sec
->sh_size
,
16487 _("strings"))) == NULL
)
16489 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
16490 strsect
.cts_data
= strdata
;
16493 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
16494 libctf papers over the difference, so we can pretend it is always an
16497 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
16499 dump_ctf_errs (NULL
);
16500 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
16504 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
16507 /* Preload the parent dict, since it will need to be imported into every
16509 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
16511 dump_ctf_errs (NULL
);
16512 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
16518 if (filedata
->is_separate
)
16519 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
16520 printable_section_name (filedata
, section
),
16521 filedata
->file_name
);
16523 printf (_("\nDump of CTF section '%s':\n"),
16524 printable_section_name (filedata
, section
));
16526 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
16527 dump_ctf_archive_member (fp
, name
, parent
, member
++);
16528 if (err
!= ECTF_NEXT_END
)
16530 dump_ctf_errs (NULL
);
16531 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
16536 ctf_dict_close (parent
);
16546 dump_section_as_sframe (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16548 void * data
= NULL
;
16549 sframe_decoder_ctx
*sfd_ctx
= NULL
;
16550 const char *print_name
= printable_section_name (filedata
, section
);
16556 if (strcmp (print_name
, "") == 0)
16558 error (_("Section name must be provided \n"));
16563 data
= get_section_contents (section
, filedata
);
16564 sf_size
= section
->sh_size
;
16565 /* Decode the contents of the section. */
16566 sfd_ctx
= sframe_decode ((const char*)data
, sf_size
, &err
);
16570 error (_("SFrame decode failure: %s\n"), sframe_errmsg (err
));
16574 printf (_("Contents of the SFrame section %s:"), print_name
);
16575 /* Dump the contents as text. */
16576 dump_sframe (sfd_ctx
, section
->sh_addr
);
16584 load_specific_debug_section (enum dwarf_section_display_enum debug
,
16585 const Elf_Internal_Shdr
* sec
,
16588 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16590 Filedata
* filedata
= (Filedata
*) data
;
16592 if (section
->start
!= NULL
)
16594 /* If it is already loaded, do nothing. */
16595 if (streq (section
->filename
, filedata
->file_name
))
16597 free (section
->start
);
16600 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
16601 section
->address
= sec
->sh_addr
;
16602 section
->filename
= filedata
->file_name
;
16603 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
16605 sec
->sh_size
, buf
);
16606 if (section
->start
== NULL
)
16610 unsigned char *start
= section
->start
;
16611 uint64_t size
= sec
->sh_size
;
16612 uint64_t uncompressed_size
= 0;
16613 bool is_zstd
= false;
16615 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
16617 Elf_Internal_Chdr chdr
;
16618 unsigned int compression_header_size
;
16620 if (size
< (is_32bit_elf
16621 ? sizeof (Elf32_External_Chdr
)
16622 : sizeof (Elf64_External_Chdr
)))
16624 warn (_("compressed section %s is too small to contain a compression header\n"),
16629 compression_header_size
= get_compression_header (&chdr
, start
, size
);
16630 if (compression_header_size
== 0)
16631 /* An error message will have already been generated
16632 by get_compression_header. */
16635 if (chdr
.ch_type
== ch_compress_zlib
)
16638 else if (chdr
.ch_type
== ch_compress_zstd
)
16643 warn (_("section '%s' has unsupported compress type: %d\n"),
16644 section
->name
, chdr
.ch_type
);
16647 uncompressed_size
= chdr
.ch_size
;
16648 start
+= compression_header_size
;
16649 size
-= compression_header_size
;
16651 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
16653 /* Read the zlib header. In this case, it should be "ZLIB"
16654 followed by the uncompressed section size, 8 bytes in
16655 big-endian order. */
16656 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
16657 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
16658 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
16659 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
16660 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
16661 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
16662 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
16663 uncompressed_size
+= start
[11];
16668 if (uncompressed_size
)
16670 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
16671 &size
, filedata
->file_size
))
16673 /* Free the compressed buffer, update the section buffer
16674 and the section size if uncompress is successful. */
16675 free (section
->start
);
16676 section
->start
= start
;
16680 error (_("Unable to decompress section %s\n"),
16681 printable_section_name (filedata
, sec
));
16686 section
->size
= size
;
16689 if (section
->start
== NULL
)
16692 if (debug_displays
[debug
].relocate
)
16694 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
16695 & section
->reloc_info
, & section
->num_relocs
))
16700 section
->reloc_info
= NULL
;
16701 section
->num_relocs
= 0;
16707 #if HAVE_LIBDEBUGINFOD
16708 /* Return a hex string representation of the build-id. */
16710 get_build_id (void * data
)
16712 Filedata
* filedata
= (Filedata
*) data
;
16713 Elf_Internal_Shdr
* shdr
;
16716 /* Iterate through notes to find note.gnu.build-id.
16717 FIXME: Only the first note in any note section is examined. */
16718 for (i
= 0, shdr
= filedata
->section_headers
;
16719 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
16722 if (shdr
->sh_type
!= SHT_NOTE
)
16727 size_t data_remaining
;
16729 Elf_External_Note
* enote
;
16730 Elf_Internal_Note inote
;
16732 uint64_t offset
= shdr
->sh_offset
;
16733 uint64_t align
= shdr
->sh_addralign
;
16734 uint64_t length
= shdr
->sh_size
;
16736 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
16742 else if (align
!= 4 && align
!= 8)
16748 end
= (char *) enote
+ length
;
16749 data_remaining
= end
- (char *) enote
;
16751 if (!is_ia64_vms (filedata
))
16753 min_notesz
= offsetof (Elf_External_Note
, name
);
16754 if (data_remaining
< min_notesz
)
16757 malformed note encountered in section %s whilst scanning for build-id note\n"),
16758 printable_section_name (filedata
, shdr
));
16762 data_remaining
-= min_notesz
;
16764 inote
.type
= BYTE_GET (enote
->type
);
16765 inote
.namesz
= BYTE_GET (enote
->namesz
);
16766 inote
.namedata
= enote
->name
;
16767 inote
.descsz
= BYTE_GET (enote
->descsz
);
16768 inote
.descdata
= ((char *) enote
16769 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
16770 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16771 next
= ((char *) enote
16772 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
16776 Elf64_External_VMS_Note
*vms_enote
;
16778 /* PR binutils/15191
16779 Make sure that there is enough data to read. */
16780 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
16781 if (data_remaining
< min_notesz
)
16784 malformed note encountered in section %s whilst scanning for build-id note\n"),
16785 printable_section_name (filedata
, shdr
));
16789 data_remaining
-= min_notesz
;
16791 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
16792 inote
.type
= BYTE_GET (vms_enote
->type
);
16793 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
16794 inote
.namedata
= vms_enote
->name
;
16795 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
16796 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
16797 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16798 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
16801 /* Skip malformed notes. */
16802 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
16803 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
16804 || (size_t) (next
- inote
.descdata
) < inote
.descsz
16805 || ((size_t) (next
- inote
.descdata
)
16806 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
16809 malformed note encountered in section %s whilst scanning for build-id note\n"),
16810 printable_section_name (filedata
, shdr
));
16815 /* Check if this is the build-id note. If so then convert the build-id
16816 bytes to a hex string. */
16817 if (inote
.namesz
> 0
16818 && startswith (inote
.namedata
, "GNU")
16819 && inote
.type
== NT_GNU_BUILD_ID
)
16824 build_id
= malloc (inote
.descsz
* 2 + 1);
16825 if (build_id
== NULL
)
16831 for (j
= 0; j
< inote
.descsz
; ++j
)
16832 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
16833 build_id
[inote
.descsz
* 2] = '\0';
16836 return (unsigned char *) build_id
;
16843 #endif /* HAVE_LIBDEBUGINFOD */
16845 /* If this is not NULL, load_debug_section will only look for sections
16846 within the list of sections given here. */
16847 static unsigned int * section_subset
= NULL
;
16850 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
16852 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16853 Elf_Internal_Shdr
* sec
;
16854 Filedata
* filedata
= (Filedata
*) data
;
16856 if (!dump_any_debugging
)
16859 /* Without section headers we cannot find any sections. */
16860 if (filedata
->section_headers
== NULL
)
16863 if (filedata
->string_table
== NULL
16864 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
16865 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
16867 Elf_Internal_Shdr
* strs
;
16869 /* Read in the string table, so that we have section names to scan. */
16870 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
16872 if (strs
!= NULL
&& strs
->sh_size
!= 0)
16874 filedata
->string_table
16875 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
16876 1, strs
->sh_size
, _("string table"));
16878 filedata
->string_table_length
16879 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
16883 /* Locate the debug section. */
16884 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
16886 section
->name
= section
->uncompressed_name
;
16889 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
16891 section
->name
= section
->compressed_name
;
16896 /* If we're loading from a subset of sections, and we've loaded
16897 a section matching this name before, it's likely that it's a
16899 if (section_subset
!= NULL
)
16900 free_debug_section (debug
);
16902 return load_specific_debug_section (debug
, sec
, data
);
16906 free_debug_section (enum dwarf_section_display_enum debug
)
16908 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16910 if (section
->start
== NULL
)
16913 free ((char *) section
->start
);
16914 section
->start
= NULL
;
16915 section
->address
= 0;
16918 free (section
->reloc_info
);
16919 section
->reloc_info
= NULL
;
16920 section
->num_relocs
= 0;
16924 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16926 const char *name
= (section_name_valid (filedata
, section
)
16927 ? section_name (filedata
, section
) : "");
16928 const char *print_name
= printable_section_name (filedata
, section
);
16930 bool result
= true;
16933 length
= section
->sh_size
;
16936 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
16939 if (section
->sh_type
== SHT_NOBITS
)
16941 /* There is no point in dumping the contents of a debugging section
16942 which has the NOBITS type - the bits in the file will be random.
16943 This can happen when a file containing a .eh_frame section is
16944 stripped with the --only-keep-debug command line option. */
16945 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
16950 if (startswith (name
, ".gnu.linkonce.wi."))
16951 name
= ".debug_info";
16953 /* See if we know how to display the contents of this section. */
16954 for (i
= 0; i
< max
; i
++)
16956 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
16957 struct dwarf_section_display
* display
= debug_displays
+ i
;
16958 struct dwarf_section
* sec
= & display
->section
;
16960 if (streq (sec
->uncompressed_name
, name
)
16961 || (id
== line
&& startswith (name
, ".debug_line."))
16962 || streq (sec
->compressed_name
, name
))
16964 bool secondary
= (section
!= find_section (filedata
, name
));
16967 free_debug_section (id
);
16969 if (i
== line
&& startswith (name
, ".debug_line."))
16971 else if (streq (sec
->uncompressed_name
, name
))
16972 sec
->name
= sec
->uncompressed_name
;
16974 sec
->name
= sec
->compressed_name
;
16976 if (load_specific_debug_section (id
, section
, filedata
))
16978 /* If this debug section is part of a CU/TU set in a .dwp file,
16979 restrict load_debug_section to the sections in that set. */
16980 section_subset
= find_cu_tu_set (filedata
, shndx
);
16982 result
&= display
->display (sec
, filedata
);
16984 section_subset
= NULL
;
16986 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
16987 free_debug_section (id
);
16995 printf (_("Unrecognized debug section: %s\n"), print_name
);
17002 /* Set DUMP_SECTS for all sections where dumps were requested
17003 based on section name. */
17006 initialise_dumps_byname (Filedata
* filedata
)
17008 struct dump_list_entry
* cur
;
17010 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
17015 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
17016 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
17017 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
17020 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
17024 if (!any
&& !filedata
->is_separate
)
17025 warn (_("Section '%s' was not dumped because it does not exist\n"),
17031 process_section_contents (Filedata
* filedata
)
17033 Elf_Internal_Shdr
* section
;
17040 initialise_dumps_byname (filedata
);
17042 for (i
= 0, section
= filedata
->section_headers
;
17043 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
17046 dump_type dump
= filedata
->dump
.dump_sects
[i
];
17048 if (filedata
->is_separate
&& ! process_links
)
17049 dump
&= DEBUG_DUMP
;
17051 #ifdef SUPPORT_DISASSEMBLY
17052 if (dump
& DISASS_DUMP
)
17054 if (! disassemble_section (section
, filedata
))
17058 if (dump
& HEX_DUMP
)
17060 if (! dump_section_as_bytes (section
, filedata
, false))
17064 if (dump
& RELOC_DUMP
)
17066 if (! dump_section_as_bytes (section
, filedata
, true))
17070 if (dump
& STRING_DUMP
)
17072 if (! dump_section_as_strings (section
, filedata
))
17076 if (dump
& DEBUG_DUMP
)
17078 if (! display_debug_section (i
, section
, filedata
))
17082 #ifdef ENABLE_LIBCTF
17083 if (dump
& CTF_DUMP
)
17085 if (! dump_section_as_ctf (section
, filedata
))
17089 if (dump
& SFRAME_DUMP
)
17091 if (! dump_section_as_sframe (section
, filedata
))
17096 if (! filedata
->is_separate
)
17098 /* Check to see if the user requested a
17099 dump of a section that does not exist. */
17100 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
17101 if (filedata
->dump
.dump_sects
[i
])
17103 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
17112 process_mips_fpe_exception (int mask
)
17118 if (mask
& OEX_FPU_INEX
)
17119 fputs ("INEX", stdout
), first
= false;
17120 if (mask
& OEX_FPU_UFLO
)
17121 printf ("%sUFLO", first
? "" : "|"), first
= false;
17122 if (mask
& OEX_FPU_OFLO
)
17123 printf ("%sOFLO", first
? "" : "|"), first
= false;
17124 if (mask
& OEX_FPU_DIV0
)
17125 printf ("%sDIV0", first
? "" : "|"), first
= false;
17126 if (mask
& OEX_FPU_INVAL
)
17127 printf ("%sINVAL", first
? "" : "|");
17130 fputs ("0", stdout
);
17133 /* Display's the value of TAG at location P. If TAG is
17134 greater than 0 it is assumed to be an unknown tag, and
17135 a message is printed to this effect. Otherwise it is
17136 assumed that a message has already been printed.
17138 If the bottom bit of TAG is set it assumed to have a
17139 string value, otherwise it is assumed to have an integer
17142 Returns an updated P pointing to the first unread byte
17143 beyond the end of TAG's value.
17145 Reads at or beyond END will not be made. */
17147 static unsigned char *
17148 display_tag_value (signed int tag
,
17150 const unsigned char * const end
)
17155 printf (" Tag_unknown_%d: ", tag
);
17159 warn (_("<corrupt tag>\n"));
17163 /* PR 17531 file: 027-19978-0.004. */
17164 size_t maxlen
= (end
- p
) - 1;
17169 print_symbol_name ((int) maxlen
, (const char *) p
);
17170 p
+= strnlen ((char *) p
, maxlen
) + 1;
17174 printf (_("<corrupt string tag>"));
17175 p
= (unsigned char *) end
;
17181 READ_ULEB (val
, p
, end
);
17182 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
17189 /* ARC ABI attributes section. */
17191 static unsigned char *
17192 display_arc_attribute (unsigned char * p
,
17193 const unsigned char * const end
)
17198 READ_ULEB (tag
, p
, end
);
17202 case Tag_ARC_PCS_config
:
17203 READ_ULEB (val
, p
, end
);
17204 printf (" Tag_ARC_PCS_config: ");
17208 printf (_("Absent/Non standard\n"));
17211 printf (_("Bare metal/mwdt\n"));
17214 printf (_("Bare metal/newlib\n"));
17217 printf (_("Linux/uclibc\n"));
17220 printf (_("Linux/glibc\n"));
17223 printf (_("Unknown\n"));
17228 case Tag_ARC_CPU_base
:
17229 READ_ULEB (val
, p
, end
);
17230 printf (" Tag_ARC_CPU_base: ");
17235 printf (_("Absent\n"));
17237 case TAG_CPU_ARC6xx
:
17238 printf ("ARC6xx\n");
17240 case TAG_CPU_ARC7xx
:
17241 printf ("ARC7xx\n");
17243 case TAG_CPU_ARCEM
:
17244 printf ("ARCEM\n");
17246 case TAG_CPU_ARCHS
:
17247 printf ("ARCHS\n");
17252 case Tag_ARC_CPU_variation
:
17253 READ_ULEB (val
, p
, end
);
17254 printf (" Tag_ARC_CPU_variation: ");
17258 if (val
> 0 && val
< 16)
17259 printf ("Core%d\n", val
);
17261 printf ("Unknown\n");
17265 printf (_("Absent\n"));
17270 case Tag_ARC_CPU_name
:
17271 printf (" Tag_ARC_CPU_name: ");
17272 p
= display_tag_value (-1, p
, end
);
17275 case Tag_ARC_ABI_rf16
:
17276 READ_ULEB (val
, p
, end
);
17277 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
17280 case Tag_ARC_ABI_osver
:
17281 READ_ULEB (val
, p
, end
);
17282 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
17285 case Tag_ARC_ABI_pic
:
17286 case Tag_ARC_ABI_sda
:
17287 READ_ULEB (val
, p
, end
);
17288 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
17289 : " Tag_ARC_ABI_pic: ");
17293 printf (_("Absent\n"));
17302 printf (_("Unknown\n"));
17307 case Tag_ARC_ABI_tls
:
17308 READ_ULEB (val
, p
, end
);
17309 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
17312 case Tag_ARC_ABI_enumsize
:
17313 READ_ULEB (val
, p
, end
);
17314 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
17318 case Tag_ARC_ABI_exceptions
:
17319 READ_ULEB (val
, p
, end
);
17320 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
17324 case Tag_ARC_ABI_double_size
:
17325 READ_ULEB (val
, p
, end
);
17326 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
17329 case Tag_ARC_ISA_config
:
17330 printf (" Tag_ARC_ISA_config: ");
17331 p
= display_tag_value (-1, p
, end
);
17334 case Tag_ARC_ISA_apex
:
17335 printf (" Tag_ARC_ISA_apex: ");
17336 p
= display_tag_value (-1, p
, end
);
17339 case Tag_ARC_ISA_mpy_option
:
17340 READ_ULEB (val
, p
, end
);
17341 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
17344 case Tag_ARC_ATR_version
:
17345 READ_ULEB (val
, p
, end
);
17346 printf (" Tag_ARC_ATR_version: %d\n", val
);
17350 return display_tag_value (tag
& 1, p
, end
);
17356 /* ARM EABI attributes section. */
17361 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
17363 const char *const *table
;
17364 } arm_attr_public_tag
;
17366 static const char *const arm_attr_tag_CPU_arch
[] =
17367 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
17368 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
17369 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
17370 "v8.1-M.mainline", "v9"};
17371 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
17372 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
17373 {"No", "Thumb-1", "Thumb-2", "Yes"};
17374 static const char *const arm_attr_tag_FP_arch
[] =
17375 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
17376 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
17377 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
17378 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
17379 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
17380 "NEON for ARMv8.1"};
17381 static const char *const arm_attr_tag_PCS_config
[] =
17382 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
17383 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
17384 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
17385 {"V6", "SB", "TLS", "Unused"};
17386 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
17387 {"Absolute", "PC-relative", "SB-relative", "None"};
17388 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
17389 {"Absolute", "PC-relative", "None"};
17390 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
17391 {"None", "direct", "GOT-indirect"};
17392 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
17393 {"None", "??? 1", "2", "??? 3", "4"};
17394 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
17395 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
17396 {"Unused", "Needed", "Sign only"};
17397 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
17398 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
17399 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
17400 {"Unused", "Finite", "RTABI", "IEEE 754"};
17401 static const char *const arm_attr_tag_ABI_enum_size
[] =
17402 {"Unused", "small", "int", "forced to int"};
17403 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
17404 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
17405 static const char *const arm_attr_tag_ABI_VFP_args
[] =
17406 {"AAPCS", "VFP registers", "custom", "compatible"};
17407 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
17408 {"AAPCS", "WMMX registers", "custom"};
17409 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
17410 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
17411 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
17412 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
17413 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
17414 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
17415 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
17416 static const char *const arm_attr_tag_FP_HP_extension
[] =
17417 {"Not Allowed", "Allowed"};
17418 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
17419 {"None", "IEEE 754", "Alternative Format"};
17420 static const char *const arm_attr_tag_DSP_extension
[] =
17421 {"Follow architecture", "Allowed"};
17422 static const char *const arm_attr_tag_MPextension_use
[] =
17423 {"Not Allowed", "Allowed"};
17424 static const char *const arm_attr_tag_DIV_use
[] =
17425 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
17426 "Allowed in v7-A with integer division extension"};
17427 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
17428 static const char *const arm_attr_tag_Virtualization_use
[] =
17429 {"Not Allowed", "TrustZone", "Virtualization Extensions",
17430 "TrustZone and Virtualization Extensions"};
17431 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
17432 {"Not Allowed", "Allowed"};
17434 static const char *const arm_attr_tag_MVE_arch
[] =
17435 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
17437 static const char * arm_attr_tag_PAC_extension
[] =
17438 {"No PAC/AUT instructions",
17439 "PAC/AUT instructions permitted in the NOP space",
17440 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
17442 static const char * arm_attr_tag_BTI_extension
[] =
17443 {"BTI instructions not permitted",
17444 "BTI instructions permitted in the NOP space",
17445 "BTI instructions permitted in the NOP and in the non-NOP space"};
17447 static const char * arm_attr_tag_BTI_use
[] =
17448 {"Compiled without branch target enforcement",
17449 "Compiled with branch target enforcement"};
17451 static const char * arm_attr_tag_PACRET_use
[] =
17452 {"Compiled without return address signing and authentication",
17453 "Compiled with return address signing and authentication"};
17455 #define LOOKUP(id, name) \
17456 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
17457 static arm_attr_public_tag arm_attr_public_tags
[] =
17459 {4, "CPU_raw_name", 1, NULL
},
17460 {5, "CPU_name", 1, NULL
},
17461 LOOKUP(6, CPU_arch
),
17462 {7, "CPU_arch_profile", 0, NULL
},
17463 LOOKUP(8, ARM_ISA_use
),
17464 LOOKUP(9, THUMB_ISA_use
),
17465 LOOKUP(10, FP_arch
),
17466 LOOKUP(11, WMMX_arch
),
17467 LOOKUP(12, Advanced_SIMD_arch
),
17468 LOOKUP(13, PCS_config
),
17469 LOOKUP(14, ABI_PCS_R9_use
),
17470 LOOKUP(15, ABI_PCS_RW_data
),
17471 LOOKUP(16, ABI_PCS_RO_data
),
17472 LOOKUP(17, ABI_PCS_GOT_use
),
17473 LOOKUP(18, ABI_PCS_wchar_t
),
17474 LOOKUP(19, ABI_FP_rounding
),
17475 LOOKUP(20, ABI_FP_denormal
),
17476 LOOKUP(21, ABI_FP_exceptions
),
17477 LOOKUP(22, ABI_FP_user_exceptions
),
17478 LOOKUP(23, ABI_FP_number_model
),
17479 {24, "ABI_align_needed", 0, NULL
},
17480 {25, "ABI_align_preserved", 0, NULL
},
17481 LOOKUP(26, ABI_enum_size
),
17482 LOOKUP(27, ABI_HardFP_use
),
17483 LOOKUP(28, ABI_VFP_args
),
17484 LOOKUP(29, ABI_WMMX_args
),
17485 LOOKUP(30, ABI_optimization_goals
),
17486 LOOKUP(31, ABI_FP_optimization_goals
),
17487 {32, "compatibility", 0, NULL
},
17488 LOOKUP(34, CPU_unaligned_access
),
17489 LOOKUP(36, FP_HP_extension
),
17490 LOOKUP(38, ABI_FP_16bit_format
),
17491 LOOKUP(42, MPextension_use
),
17492 LOOKUP(44, DIV_use
),
17493 LOOKUP(46, DSP_extension
),
17494 LOOKUP(48, MVE_arch
),
17495 LOOKUP(50, PAC_extension
),
17496 LOOKUP(52, BTI_extension
),
17497 LOOKUP(74, BTI_use
),
17498 LOOKUP(76, PACRET_use
),
17499 {64, "nodefaults", 0, NULL
},
17500 {65, "also_compatible_with", 0, NULL
},
17501 LOOKUP(66, T2EE_use
),
17502 {67, "conformance", 1, NULL
},
17503 LOOKUP(68, Virtualization_use
),
17504 LOOKUP(70, MPextension_use_legacy
)
17508 static unsigned char *
17509 display_arm_attribute (unsigned char * p
,
17510 const unsigned char * const end
)
17514 arm_attr_public_tag
* attr
;
17518 READ_ULEB (tag
, p
, end
);
17520 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
17522 if (arm_attr_public_tags
[i
].tag
== tag
)
17524 attr
= &arm_attr_public_tags
[i
];
17531 printf (" Tag_%s: ", attr
->name
);
17532 switch (attr
->type
)
17537 case 7: /* Tag_CPU_arch_profile. */
17538 READ_ULEB (val
, p
, end
);
17541 case 0: printf (_("None\n")); break;
17542 case 'A': printf (_("Application\n")); break;
17543 case 'R': printf (_("Realtime\n")); break;
17544 case 'M': printf (_("Microcontroller\n")); break;
17545 case 'S': printf (_("Application or Realtime\n")); break;
17546 default: printf ("??? (%d)\n", val
); break;
17550 case 24: /* Tag_align_needed. */
17551 READ_ULEB (val
, p
, end
);
17554 case 0: printf (_("None\n")); break;
17555 case 1: printf (_("8-byte\n")); break;
17556 case 2: printf (_("4-byte\n")); break;
17557 case 3: printf ("??? 3\n"); break;
17560 printf (_("8-byte and up to %d-byte extended\n"),
17563 printf ("??? (%d)\n", val
);
17568 case 25: /* Tag_align_preserved. */
17569 READ_ULEB (val
, p
, end
);
17572 case 0: printf (_("None\n")); break;
17573 case 1: printf (_("8-byte, except leaf SP\n")); break;
17574 case 2: printf (_("8-byte\n")); break;
17575 case 3: printf ("??? 3\n"); break;
17578 printf (_("8-byte and up to %d-byte extended\n"),
17581 printf ("??? (%d)\n", val
);
17586 case 32: /* Tag_compatibility. */
17588 READ_ULEB (val
, p
, end
);
17589 printf (_("flag = %d, vendor = "), val
);
17592 size_t maxlen
= (end
- p
) - 1;
17594 print_symbol_name ((int) maxlen
, (const char *) p
);
17595 p
+= strnlen ((char *) p
, maxlen
) + 1;
17599 printf (_("<corrupt>"));
17600 p
= (unsigned char *) end
;
17606 case 64: /* Tag_nodefaults. */
17607 /* PR 17531: file: 001-505008-0.01. */
17610 printf (_("True\n"));
17613 case 65: /* Tag_also_compatible_with. */
17614 READ_ULEB (val
, p
, end
);
17615 if (val
== 6 /* Tag_CPU_arch. */)
17617 READ_ULEB (val
, p
, end
);
17618 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
17619 printf ("??? (%d)\n", val
);
17621 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
17625 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
17630 printf (_("<unknown: %d>\n"), tag
);
17636 return display_tag_value (-1, p
, end
);
17638 return display_tag_value (0, p
, end
);
17641 assert (attr
->type
& 0x80);
17642 READ_ULEB (val
, p
, end
);
17643 type
= attr
->type
& 0x7f;
17645 printf ("??? (%d)\n", val
);
17647 printf ("%s\n", attr
->table
[val
]);
17652 return display_tag_value (tag
, p
, end
);
17655 static unsigned char *
17656 display_gnu_attribute (unsigned char * p
,
17657 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
17658 const unsigned char * const end
)
17663 READ_ULEB (tag
, p
, end
);
17665 /* Tag_compatibility is the only generic GNU attribute defined at
17669 READ_ULEB (val
, p
, end
);
17671 printf (_("flag = %d, vendor = "), val
);
17674 printf (_("<corrupt>\n"));
17675 warn (_("corrupt vendor attribute\n"));
17681 size_t maxlen
= (end
- p
) - 1;
17683 print_symbol_name ((int) maxlen
, (const char *) p
);
17684 p
+= strnlen ((char *) p
, maxlen
) + 1;
17688 printf (_("<corrupt>"));
17689 p
= (unsigned char *) end
;
17696 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
17697 return display_proc_gnu_attribute (p
, tag
, end
);
17699 return display_tag_value (tag
, p
, end
);
17702 static unsigned char *
17703 display_m68k_gnu_attribute (unsigned char * p
,
17705 const unsigned char * const end
)
17709 if (tag
== Tag_GNU_M68K_ABI_FP
)
17711 printf (" Tag_GNU_M68K_ABI_FP: ");
17714 printf (_("<corrupt>\n"));
17717 READ_ULEB (val
, p
, end
);
17720 printf ("(%#x), ", val
);
17725 printf (_("unspecified hard/soft float\n"));
17728 printf (_("hard float\n"));
17731 printf (_("soft float\n"));
17737 return display_tag_value (tag
& 1, p
, end
);
17740 static unsigned char *
17741 display_power_gnu_attribute (unsigned char * p
,
17743 const unsigned char * const end
)
17747 if (tag
== Tag_GNU_Power_ABI_FP
)
17749 printf (" Tag_GNU_Power_ABI_FP: ");
17752 printf (_("<corrupt>\n"));
17755 READ_ULEB (val
, p
, end
);
17758 printf ("(%#x), ", val
);
17763 printf (_("unspecified hard/soft float, "));
17766 printf (_("hard float, "));
17769 printf (_("soft float, "));
17772 printf (_("single-precision hard float, "));
17779 printf (_("unspecified long double\n"));
17782 printf (_("128-bit IBM long double\n"));
17785 printf (_("64-bit long double\n"));
17788 printf (_("128-bit IEEE long double\n"));
17794 if (tag
== Tag_GNU_Power_ABI_Vector
)
17796 printf (" Tag_GNU_Power_ABI_Vector: ");
17799 printf (_("<corrupt>\n"));
17802 READ_ULEB (val
, p
, end
);
17805 printf ("(%#x), ", val
);
17810 printf (_("unspecified\n"));
17813 printf (_("generic\n"));
17816 printf ("AltiVec\n");
17825 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
17827 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
17830 printf (_("<corrupt>\n"));
17833 READ_ULEB (val
, p
, end
);
17836 printf ("(%#x), ", val
);
17841 printf (_("unspecified\n"));
17844 printf ("r3/r4\n");
17847 printf (_("memory\n"));
17856 return display_tag_value (tag
& 1, p
, end
);
17859 static unsigned char *
17860 display_s390_gnu_attribute (unsigned char * p
,
17862 const unsigned char * const end
)
17866 if (tag
== Tag_GNU_S390_ABI_Vector
)
17868 printf (" Tag_GNU_S390_ABI_Vector: ");
17869 READ_ULEB (val
, p
, end
);
17874 printf (_("any\n"));
17877 printf (_("software\n"));
17880 printf (_("hardware\n"));
17883 printf ("??? (%d)\n", val
);
17889 return display_tag_value (tag
& 1, p
, end
);
17893 display_sparc_hwcaps (unsigned int mask
)
17899 if (mask
& ELF_SPARC_HWCAP_MUL32
)
17900 fputs ("mul32", stdout
), first
= false;
17901 if (mask
& ELF_SPARC_HWCAP_DIV32
)
17902 printf ("%sdiv32", first
? "" : "|"), first
= false;
17903 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
17904 printf ("%sfsmuld", first
? "" : "|"), first
= false;
17905 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
17906 printf ("%sv8plus", first
? "" : "|"), first
= false;
17907 if (mask
& ELF_SPARC_HWCAP_POPC
)
17908 printf ("%spopc", first
? "" : "|"), first
= false;
17909 if (mask
& ELF_SPARC_HWCAP_VIS
)
17910 printf ("%svis", first
? "" : "|"), first
= false;
17911 if (mask
& ELF_SPARC_HWCAP_VIS2
)
17912 printf ("%svis2", first
? "" : "|"), first
= false;
17913 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
17914 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
17915 if (mask
& ELF_SPARC_HWCAP_FMAF
)
17916 printf ("%sfmaf", first
? "" : "|"), first
= false;
17917 if (mask
& ELF_SPARC_HWCAP_VIS3
)
17918 printf ("%svis3", first
? "" : "|"), first
= false;
17919 if (mask
& ELF_SPARC_HWCAP_HPC
)
17920 printf ("%shpc", first
? "" : "|"), first
= false;
17921 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
17922 printf ("%srandom", first
? "" : "|"), first
= false;
17923 if (mask
& ELF_SPARC_HWCAP_TRANS
)
17924 printf ("%strans", first
? "" : "|"), first
= false;
17925 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
17926 printf ("%sfjfmau", first
? "" : "|"), first
= false;
17927 if (mask
& ELF_SPARC_HWCAP_IMA
)
17928 printf ("%sima", first
? "" : "|"), first
= false;
17929 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
17930 printf ("%scspare", first
? "" : "|"), first
= false;
17933 fputc ('0', stdout
);
17934 fputc ('\n', stdout
);
17938 display_sparc_hwcaps2 (unsigned int mask
)
17944 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
17945 fputs ("fjathplus", stdout
), first
= false;
17946 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
17947 printf ("%svis3b", first
? "" : "|"), first
= false;
17948 if (mask
& ELF_SPARC_HWCAP2_ADP
)
17949 printf ("%sadp", first
? "" : "|"), first
= false;
17950 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
17951 printf ("%ssparc5", first
? "" : "|"), first
= false;
17952 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
17953 printf ("%smwait", first
? "" : "|"), first
= false;
17954 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
17955 printf ("%sxmpmul", first
? "" : "|"), first
= false;
17956 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
17957 printf ("%sxmont2", first
? "" : "|"), first
= false;
17958 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
17959 printf ("%snsec", first
? "" : "|"), first
= false;
17960 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
17961 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
17962 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
17963 printf ("%sfjdes", first
? "" : "|"), first
= false;
17964 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
17965 printf ("%sfjaes", first
? "" : "|"), first
= false;
17968 fputc ('0', stdout
);
17969 fputc ('\n', stdout
);
17972 static unsigned char *
17973 display_sparc_gnu_attribute (unsigned char * p
,
17975 const unsigned char * const end
)
17979 if (tag
== Tag_GNU_Sparc_HWCAPS
)
17981 READ_ULEB (val
, p
, end
);
17982 printf (" Tag_GNU_Sparc_HWCAPS: ");
17983 display_sparc_hwcaps (val
);
17986 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
17988 READ_ULEB (val
, p
, end
);
17989 printf (" Tag_GNU_Sparc_HWCAPS2: ");
17990 display_sparc_hwcaps2 (val
);
17994 return display_tag_value (tag
, p
, end
);
17998 print_mips_fp_abi_value (unsigned int val
)
18002 case Val_GNU_MIPS_ABI_FP_ANY
:
18003 printf (_("Hard or soft float\n"));
18005 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
18006 printf (_("Hard float (double precision)\n"));
18008 case Val_GNU_MIPS_ABI_FP_SINGLE
:
18009 printf (_("Hard float (single precision)\n"));
18011 case Val_GNU_MIPS_ABI_FP_SOFT
:
18012 printf (_("Soft float\n"));
18014 case Val_GNU_MIPS_ABI_FP_OLD_64
:
18015 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
18017 case Val_GNU_MIPS_ABI_FP_XX
:
18018 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
18020 case Val_GNU_MIPS_ABI_FP_64
:
18021 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
18023 case Val_GNU_MIPS_ABI_FP_64A
:
18024 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
18026 case Val_GNU_MIPS_ABI_FP_NAN2008
:
18027 printf (_("NaN 2008 compatibility\n"));
18030 printf ("??? (%d)\n", val
);
18035 static unsigned char *
18036 display_mips_gnu_attribute (unsigned char * p
,
18038 const unsigned char * const end
)
18040 if (tag
== Tag_GNU_MIPS_ABI_FP
)
18044 printf (" Tag_GNU_MIPS_ABI_FP: ");
18045 READ_ULEB (val
, p
, end
);
18046 print_mips_fp_abi_value (val
);
18050 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
18054 printf (" Tag_GNU_MIPS_ABI_MSA: ");
18055 READ_ULEB (val
, p
, end
);
18059 case Val_GNU_MIPS_ABI_MSA_ANY
:
18060 printf (_("Any MSA or not\n"));
18062 case Val_GNU_MIPS_ABI_MSA_128
:
18063 printf (_("128-bit MSA\n"));
18066 printf ("??? (%d)\n", val
);
18072 return display_tag_value (tag
& 1, p
, end
);
18075 static unsigned char *
18076 display_tic6x_attribute (unsigned char * p
,
18077 const unsigned char * const end
)
18082 READ_ULEB (tag
, p
, end
);
18087 printf (" Tag_ISA: ");
18088 READ_ULEB (val
, p
, end
);
18092 case C6XABI_Tag_ISA_none
:
18093 printf (_("None\n"));
18095 case C6XABI_Tag_ISA_C62X
:
18098 case C6XABI_Tag_ISA_C67X
:
18101 case C6XABI_Tag_ISA_C67XP
:
18102 printf ("C67x+\n");
18104 case C6XABI_Tag_ISA_C64X
:
18107 case C6XABI_Tag_ISA_C64XP
:
18108 printf ("C64x+\n");
18110 case C6XABI_Tag_ISA_C674X
:
18111 printf ("C674x\n");
18114 printf ("??? (%d)\n", val
);
18119 case Tag_ABI_wchar_t
:
18120 printf (" Tag_ABI_wchar_t: ");
18121 READ_ULEB (val
, p
, end
);
18125 printf (_("Not used\n"));
18128 printf (_("2 bytes\n"));
18131 printf (_("4 bytes\n"));
18134 printf ("??? (%d)\n", val
);
18139 case Tag_ABI_stack_align_needed
:
18140 printf (" Tag_ABI_stack_align_needed: ");
18141 READ_ULEB (val
, p
, end
);
18145 printf (_("8-byte\n"));
18148 printf (_("16-byte\n"));
18151 printf ("??? (%d)\n", val
);
18156 case Tag_ABI_stack_align_preserved
:
18157 READ_ULEB (val
, p
, end
);
18158 printf (" Tag_ABI_stack_align_preserved: ");
18162 printf (_("8-byte\n"));
18165 printf (_("16-byte\n"));
18168 printf ("??? (%d)\n", val
);
18174 READ_ULEB (val
, p
, end
);
18175 printf (" Tag_ABI_DSBT: ");
18179 printf (_("DSBT addressing not used\n"));
18182 printf (_("DSBT addressing used\n"));
18185 printf ("??? (%d)\n", val
);
18191 READ_ULEB (val
, p
, end
);
18192 printf (" Tag_ABI_PID: ");
18196 printf (_("Data addressing position-dependent\n"));
18199 printf (_("Data addressing position-independent, GOT near DP\n"));
18202 printf (_("Data addressing position-independent, GOT far from DP\n"));
18205 printf ("??? (%d)\n", val
);
18211 READ_ULEB (val
, p
, end
);
18212 printf (" Tag_ABI_PIC: ");
18216 printf (_("Code addressing position-dependent\n"));
18219 printf (_("Code addressing position-independent\n"));
18222 printf ("??? (%d)\n", val
);
18227 case Tag_ABI_array_object_alignment
:
18228 READ_ULEB (val
, p
, end
);
18229 printf (" Tag_ABI_array_object_alignment: ");
18233 printf (_("8-byte\n"));
18236 printf (_("4-byte\n"));
18239 printf (_("16-byte\n"));
18242 printf ("??? (%d)\n", val
);
18247 case Tag_ABI_array_object_align_expected
:
18248 READ_ULEB (val
, p
, end
);
18249 printf (" Tag_ABI_array_object_align_expected: ");
18253 printf (_("8-byte\n"));
18256 printf (_("4-byte\n"));
18259 printf (_("16-byte\n"));
18262 printf ("??? (%d)\n", val
);
18267 case Tag_ABI_compatibility
:
18269 READ_ULEB (val
, p
, end
);
18270 printf (" Tag_ABI_compatibility: ");
18271 printf (_("flag = %d, vendor = "), val
);
18274 size_t maxlen
= (end
- p
) - 1;
18276 print_symbol_name ((int) maxlen
, (const char *) p
);
18277 p
+= strnlen ((char *) p
, maxlen
) + 1;
18281 printf (_("<corrupt>"));
18282 p
= (unsigned char *) end
;
18288 case Tag_ABI_conformance
:
18290 printf (" Tag_ABI_conformance: \"");
18293 size_t maxlen
= (end
- p
) - 1;
18295 print_symbol_name ((int) maxlen
, (const char *) p
);
18296 p
+= strnlen ((char *) p
, maxlen
) + 1;
18300 printf (_("<corrupt>"));
18301 p
= (unsigned char *) end
;
18308 return display_tag_value (tag
, p
, end
);
18312 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
18315 size_t bytes
= end
- p
;
18322 int lbytes
= (bytes
> 16 ? 16 : bytes
);
18324 printf (" 0x%8.8" PRIx64
" ", addr
);
18326 for (j
= 0; j
< 16; j
++)
18329 printf ("%2.2x", p
[j
]);
18337 for (j
= 0; j
< lbytes
; j
++)
18340 if (k
>= ' ' && k
< 0x7f)
18356 static unsigned char *
18357 display_msp430_attribute (unsigned char * p
,
18358 const unsigned char * const end
)
18363 READ_ULEB (tag
, p
, end
);
18367 case OFBA_MSPABI_Tag_ISA
:
18368 printf (" Tag_ISA: ");
18369 READ_ULEB (val
, p
, end
);
18372 case 0: printf (_("None\n")); break;
18373 case 1: printf (_("MSP430\n")); break;
18374 case 2: printf (_("MSP430X\n")); break;
18375 default: printf ("??? (%" PRId64
")\n", val
); break;
18379 case OFBA_MSPABI_Tag_Code_Model
:
18380 printf (" Tag_Code_Model: ");
18381 READ_ULEB (val
, p
, end
);
18384 case 0: printf (_("None\n")); break;
18385 case 1: printf (_("Small\n")); break;
18386 case 2: printf (_("Large\n")); break;
18387 default: printf ("??? (%" PRId64
")\n", val
); break;
18391 case OFBA_MSPABI_Tag_Data_Model
:
18392 printf (" Tag_Data_Model: ");
18393 READ_ULEB (val
, p
, end
);
18396 case 0: printf (_("None\n")); break;
18397 case 1: printf (_("Small\n")); break;
18398 case 2: printf (_("Large\n")); break;
18399 case 3: printf (_("Restricted Large\n")); break;
18400 default: printf ("??? (%" PRId64
")\n", val
); break;
18405 printf (_(" <unknown tag %" PRId64
">: "), tag
);
18412 size_t maxlen
= (end
- p
) - 1;
18414 print_symbol_name ((int) maxlen
, (const char *) p
);
18415 p
+= strnlen ((char *) p
, maxlen
) + 1;
18419 printf (_("<corrupt>"));
18420 p
= (unsigned char *) end
;
18426 READ_ULEB (val
, p
, end
);
18427 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
18436 static unsigned char *
18437 display_msp430_gnu_attribute (unsigned char * p
,
18439 const unsigned char * const end
)
18441 if (tag
== Tag_GNU_MSP430_Data_Region
)
18445 printf (" Tag_GNU_MSP430_Data_Region: ");
18446 READ_ULEB (val
, p
, end
);
18450 case Val_GNU_MSP430_Data_Region_Any
:
18451 printf (_("Any Region\n"));
18453 case Val_GNU_MSP430_Data_Region_Lower
:
18454 printf (_("Lower Region Only\n"));
18457 printf ("??? (%" PRIu64
")\n", val
);
18461 return display_tag_value (tag
& 1, p
, end
);
18464 struct riscv_attr_tag_t
{
18469 static struct riscv_attr_tag_t riscv_attr_tag
[] =
18471 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
18474 T(priv_spec_minor
),
18475 T(priv_spec_revision
),
18476 T(unaligned_access
),
18481 static unsigned char *
18482 display_riscv_attribute (unsigned char *p
,
18483 const unsigned char * const end
)
18487 struct riscv_attr_tag_t
*attr
= NULL
;
18490 READ_ULEB (tag
, p
, end
);
18492 /* Find the name of attribute. */
18493 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
18495 if (riscv_attr_tag
[i
].tag
== tag
)
18497 attr
= &riscv_attr_tag
[i
];
18503 printf (" %s: ", attr
->name
);
18505 return display_tag_value (tag
, p
, end
);
18509 case Tag_RISCV_priv_spec
:
18510 case Tag_RISCV_priv_spec_minor
:
18511 case Tag_RISCV_priv_spec_revision
:
18512 READ_ULEB (val
, p
, end
);
18513 printf ("%" PRIu64
"\n", val
);
18515 case Tag_RISCV_unaligned_access
:
18516 READ_ULEB (val
, p
, end
);
18520 printf (_("No unaligned access\n"));
18523 printf (_("Unaligned access\n"));
18527 case Tag_RISCV_stack_align
:
18528 READ_ULEB (val
, p
, end
);
18529 printf (_("%" PRIu64
"-bytes\n"), val
);
18531 case Tag_RISCV_arch
:
18532 p
= display_tag_value (-1, p
, end
);
18535 return display_tag_value (tag
, p
, end
);
18541 static unsigned char *
18542 display_csky_attribute (unsigned char * p
,
18543 const unsigned char * const end
)
18547 READ_ULEB (tag
, p
, end
);
18549 if (tag
>= Tag_CSKY_MAX
)
18551 return display_tag_value (-1, p
, end
);
18556 case Tag_CSKY_ARCH_NAME
:
18557 printf (" Tag_CSKY_ARCH_NAME:\t\t");
18558 return display_tag_value (-1, p
, end
);
18559 case Tag_CSKY_CPU_NAME
:
18560 printf (" Tag_CSKY_CPU_NAME:\t\t");
18561 return display_tag_value (-1, p
, end
);
18563 case Tag_CSKY_ISA_FLAGS
:
18564 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
18565 return display_tag_value (0, p
, end
);
18566 case Tag_CSKY_ISA_EXT_FLAGS
:
18567 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
18568 return display_tag_value (0, p
, end
);
18570 case Tag_CSKY_DSP_VERSION
:
18571 printf (" Tag_CSKY_DSP_VERSION:\t\t");
18572 READ_ULEB (val
, p
, end
);
18573 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
18574 printf ("DSP Extension\n");
18575 else if (val
== VAL_CSKY_DSP_VERSION_2
)
18576 printf ("DSP 2.0\n");
18579 case Tag_CSKY_VDSP_VERSION
:
18580 printf (" Tag_CSKY_VDSP_VERSION:\t");
18581 READ_ULEB (val
, p
, end
);
18582 printf ("VDSP Version %" PRId64
"\n", val
);
18585 case Tag_CSKY_FPU_VERSION
:
18586 printf (" Tag_CSKY_FPU_VERSION:\t\t");
18587 READ_ULEB (val
, p
, end
);
18588 if (val
== VAL_CSKY_FPU_VERSION_1
)
18589 printf ("ABIV1 FPU Version 1\n");
18590 else if (val
== VAL_CSKY_FPU_VERSION_2
)
18591 printf ("FPU Version 2\n");
18594 case Tag_CSKY_FPU_ABI
:
18595 printf (" Tag_CSKY_FPU_ABI:\t\t");
18596 READ_ULEB (val
, p
, end
);
18597 if (val
== VAL_CSKY_FPU_ABI_HARD
)
18599 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
18600 printf ("SoftFP\n");
18601 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
18604 case Tag_CSKY_FPU_ROUNDING
:
18605 READ_ULEB (val
, p
, end
);
18608 printf (" Tag_CSKY_FPU_ROUNDING:\t");
18609 printf ("Needed\n");
18612 case Tag_CSKY_FPU_DENORMAL
:
18613 READ_ULEB (val
, p
, end
);
18616 printf (" Tag_CSKY_FPU_DENORMAL:\t");
18617 printf ("Needed\n");
18620 case Tag_CSKY_FPU_Exception
:
18621 READ_ULEB (val
, p
, end
);
18624 printf (" Tag_CSKY_FPU_Exception:\t");
18625 printf ("Needed\n");
18628 case Tag_CSKY_FPU_NUMBER_MODULE
:
18629 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
18630 return display_tag_value (-1, p
, end
);
18631 case Tag_CSKY_FPU_HARDFP
:
18632 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
18633 READ_ULEB (val
, p
, end
);
18634 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
18636 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
18637 printf (" Single");
18638 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
18639 printf (" Double");
18643 return display_tag_value (tag
, p
, end
);
18649 process_attributes (Filedata
* filedata
,
18650 const char * public_name
,
18651 unsigned int proc_type
,
18652 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
18653 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
18655 Elf_Internal_Shdr
* sect
;
18659 /* Find the section header so that we get the size. */
18660 for (i
= 0, sect
= filedata
->section_headers
;
18661 i
< filedata
->file_header
.e_shnum
;
18664 unsigned char * contents
;
18667 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
18670 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
18671 sect
->sh_size
, _("attributes"));
18672 if (contents
== NULL
)
18679 /* The first character is the version of the attributes.
18680 Currently only version 1, (aka 'A') is recognised here. */
18683 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
18688 uint64_t section_len
;
18690 section_len
= sect
->sh_size
- 1;
18693 while (section_len
> 0)
18696 unsigned int namelen
;
18697 bool public_section
;
18700 if (section_len
<= 4)
18702 error (_("Tag section ends prematurely\n"));
18706 attr_len
= byte_get (p
, 4);
18709 if (attr_len
> section_len
)
18711 error (_("Bad attribute length (%u > %u)\n"),
18712 (unsigned) attr_len
, (unsigned) section_len
);
18713 attr_len
= section_len
;
18716 /* PR 17531: file: 001-101425-0.004 */
18717 else if (attr_len
< 5)
18719 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
18724 section_len
-= attr_len
;
18727 namelen
= strnlen ((char *) p
, attr_len
) + 1;
18728 if (namelen
== 0 || namelen
>= attr_len
)
18730 error (_("Corrupt attribute section name\n"));
18735 printf (_("Attribute Section: "));
18736 print_symbol_name (INT_MAX
, (const char *) p
);
18739 if (public_name
&& streq ((char *) p
, public_name
))
18740 public_section
= true;
18742 public_section
= false;
18744 if (streq ((char *) p
, "gnu"))
18745 gnu_section
= true;
18747 gnu_section
= false;
18750 attr_len
-= namelen
;
18752 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
18757 unsigned char * end
;
18759 /* PR binutils/17531: Safe handling of corrupt files. */
18762 error (_("Unused bytes at end of section\n"));
18769 size
= byte_get (p
, 4);
18770 if (size
> attr_len
)
18772 error (_("Bad subsection length (%u > %u)\n"),
18773 (unsigned) size
, (unsigned) attr_len
);
18777 /* PR binutils/17531: Safe handling of corrupt files. */
18780 error (_("Bad subsection length (%u < 6)\n"),
18788 end
= p
+ size
- 1;
18789 assert (end
<= contents
+ sect
->sh_size
);
18795 printf (_("File Attributes\n"));
18798 printf (_("Section Attributes:"));
18801 printf (_("Symbol Attributes:"));
18802 /* Fall through. */
18806 READ_ULEB (val
, p
, end
);
18809 printf (" %d", val
);
18814 printf (_("Unknown tag: %d\n"), tag
);
18815 public_section
= false;
18819 if (public_section
&& display_pub_attribute
!= NULL
)
18822 p
= display_pub_attribute (p
, end
);
18825 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
18828 p
= display_gnu_attribute (p
,
18829 display_proc_gnu_attribute
,
18835 printf (_(" Unknown attribute:\n"));
18836 display_raw_attribute (p
, end
);
18851 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
18852 Print the Address, Access and Initial fields of an entry at VMA ADDR
18853 and return the VMA of the next entry, or -1 if there was a problem.
18854 Does not read from DATA_END or beyond. */
18857 print_mips_got_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
,
18858 unsigned char * data_end
)
18861 print_vma (addr
, LONG_HEX
);
18863 if (addr
< pltgot
+ 0xfff0)
18864 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
18866 printf ("%10s", "");
18869 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18873 unsigned char * from
= data
+ addr
- pltgot
;
18875 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
18877 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
18878 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
18879 return (uint64_t) -1;
18883 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18884 print_vma (entry
, LONG_HEX
);
18887 return addr
+ (is_32bit_elf
? 4 : 8);
18890 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
18891 PLTGOT. Print the Address and Initial fields of an entry at VMA
18892 ADDR and return the VMA of the next entry. */
18895 print_mips_pltgot_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
)
18898 print_vma (addr
, LONG_HEX
);
18901 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18906 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18907 print_vma (entry
, LONG_HEX
);
18909 return addr
+ (is_32bit_elf
? 4 : 8);
18913 print_mips_ases (unsigned int mask
)
18915 if (mask
& AFL_ASE_DSP
)
18916 fputs ("\n\tDSP ASE", stdout
);
18917 if (mask
& AFL_ASE_DSPR2
)
18918 fputs ("\n\tDSP R2 ASE", stdout
);
18919 if (mask
& AFL_ASE_DSPR3
)
18920 fputs ("\n\tDSP R3 ASE", stdout
);
18921 if (mask
& AFL_ASE_EVA
)
18922 fputs ("\n\tEnhanced VA Scheme", stdout
);
18923 if (mask
& AFL_ASE_MCU
)
18924 fputs ("\n\tMCU (MicroController) ASE", stdout
);
18925 if (mask
& AFL_ASE_MDMX
)
18926 fputs ("\n\tMDMX ASE", stdout
);
18927 if (mask
& AFL_ASE_MIPS3D
)
18928 fputs ("\n\tMIPS-3D ASE", stdout
);
18929 if (mask
& AFL_ASE_MT
)
18930 fputs ("\n\tMT ASE", stdout
);
18931 if (mask
& AFL_ASE_SMARTMIPS
)
18932 fputs ("\n\tSmartMIPS ASE", stdout
);
18933 if (mask
& AFL_ASE_VIRT
)
18934 fputs ("\n\tVZ ASE", stdout
);
18935 if (mask
& AFL_ASE_MSA
)
18936 fputs ("\n\tMSA ASE", stdout
);
18937 if (mask
& AFL_ASE_MIPS16
)
18938 fputs ("\n\tMIPS16 ASE", stdout
);
18939 if (mask
& AFL_ASE_MICROMIPS
)
18940 fputs ("\n\tMICROMIPS ASE", stdout
);
18941 if (mask
& AFL_ASE_XPA
)
18942 fputs ("\n\tXPA ASE", stdout
);
18943 if (mask
& AFL_ASE_MIPS16E2
)
18944 fputs ("\n\tMIPS16e2 ASE", stdout
);
18945 if (mask
& AFL_ASE_CRC
)
18946 fputs ("\n\tCRC ASE", stdout
);
18947 if (mask
& AFL_ASE_GINV
)
18948 fputs ("\n\tGINV ASE", stdout
);
18949 if (mask
& AFL_ASE_LOONGSON_MMI
)
18950 fputs ("\n\tLoongson MMI ASE", stdout
);
18951 if (mask
& AFL_ASE_LOONGSON_CAM
)
18952 fputs ("\n\tLoongson CAM ASE", stdout
);
18953 if (mask
& AFL_ASE_LOONGSON_EXT
)
18954 fputs ("\n\tLoongson EXT ASE", stdout
);
18955 if (mask
& AFL_ASE_LOONGSON_EXT2
)
18956 fputs ("\n\tLoongson EXT2 ASE", stdout
);
18958 fprintf (stdout
, "\n\t%s", _("None"));
18959 else if ((mask
& ~AFL_ASE_MASK
) != 0)
18960 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
18964 print_mips_isa_ext (unsigned int isa_ext
)
18969 fputs (_("None"), stdout
);
18972 fputs ("RMI XLR", stdout
);
18974 case AFL_EXT_OCTEON3
:
18975 fputs ("Cavium Networks Octeon3", stdout
);
18977 case AFL_EXT_OCTEON2
:
18978 fputs ("Cavium Networks Octeon2", stdout
);
18980 case AFL_EXT_OCTEONP
:
18981 fputs ("Cavium Networks OcteonP", stdout
);
18983 case AFL_EXT_OCTEON
:
18984 fputs ("Cavium Networks Octeon", stdout
);
18987 fputs ("Toshiba R5900", stdout
);
18990 fputs ("MIPS R4650", stdout
);
18993 fputs ("LSI R4010", stdout
);
18996 fputs ("NEC VR4100", stdout
);
18999 fputs ("Toshiba R3900", stdout
);
19001 case AFL_EXT_10000
:
19002 fputs ("MIPS R10000", stdout
);
19005 fputs ("Broadcom SB-1", stdout
);
19008 fputs ("NEC VR4111/VR4181", stdout
);
19011 fputs ("NEC VR4120", stdout
);
19014 fputs ("NEC VR5400", stdout
);
19017 fputs ("NEC VR5500", stdout
);
19019 case AFL_EXT_LOONGSON_2E
:
19020 fputs ("ST Microelectronics Loongson 2E", stdout
);
19022 case AFL_EXT_LOONGSON_2F
:
19023 fputs ("ST Microelectronics Loongson 2F", stdout
);
19025 case AFL_EXT_INTERAPTIV_MR2
:
19026 fputs ("Imagination interAptiv MR2", stdout
);
19029 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
19034 get_mips_reg_size (int reg_size
)
19036 return (reg_size
== AFL_REG_NONE
) ? 0
19037 : (reg_size
== AFL_REG_32
) ? 32
19038 : (reg_size
== AFL_REG_64
) ? 64
19039 : (reg_size
== AFL_REG_128
) ? 128
19044 process_mips_specific (Filedata
* filedata
)
19046 Elf_Internal_Dyn
* entry
;
19047 Elf_Internal_Shdr
*sect
= NULL
;
19048 size_t liblist_offset
= 0;
19049 size_t liblistno
= 0;
19050 size_t conflictsno
= 0;
19051 size_t options_offset
= 0;
19052 size_t conflicts_offset
= 0;
19053 size_t pltrelsz
= 0;
19055 uint64_t pltgot
= 0;
19056 uint64_t mips_pltgot
= 0;
19057 uint64_t jmprel
= 0;
19058 uint64_t local_gotno
= 0;
19059 uint64_t gotsym
= 0;
19060 uint64_t symtabno
= 0;
19063 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
19064 display_mips_gnu_attribute
))
19067 sect
= find_section (filedata
, ".MIPS.abiflags");
19071 Elf_External_ABIFlags_v0
*abiflags_ext
;
19072 Elf_Internal_ABIFlags_v0 abiflags_in
;
19074 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
19076 error (_("Corrupt MIPS ABI Flags section.\n"));
19081 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
19082 sect
->sh_size
, _("MIPS ABI Flags section"));
19085 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
19086 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
19087 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
19088 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
19089 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
19090 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
19091 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
19092 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
19093 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
19094 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
19095 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
19097 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
19098 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
19099 if (abiflags_in
.isa_rev
> 1)
19100 printf ("r%d", abiflags_in
.isa_rev
);
19101 printf ("\nGPR size: %d",
19102 get_mips_reg_size (abiflags_in
.gpr_size
));
19103 printf ("\nCPR1 size: %d",
19104 get_mips_reg_size (abiflags_in
.cpr1_size
));
19105 printf ("\nCPR2 size: %d",
19106 get_mips_reg_size (abiflags_in
.cpr2_size
));
19107 fputs ("\nFP ABI: ", stdout
);
19108 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
19109 fputs ("ISA Extension: ", stdout
);
19110 print_mips_isa_ext (abiflags_in
.isa_ext
);
19111 fputs ("\nASEs:", stdout
);
19112 print_mips_ases (abiflags_in
.ases
);
19113 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
19114 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
19115 fputc ('\n', stdout
);
19116 free (abiflags_ext
);
19121 /* We have a lot of special sections. Thanks SGI! */
19122 if (filedata
->dynamic_section
== NULL
)
19124 /* No dynamic information available. See if there is static GOT. */
19125 sect
= find_section (filedata
, ".got");
19128 unsigned char *data_end
;
19129 unsigned char *data
;
19133 pltgot
= sect
->sh_addr
;
19136 addr_size
= (is_32bit_elf
? 4 : 8);
19137 end
= pltgot
+ sect
->sh_size
;
19139 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
19141 _("Global Offset Table data"));
19142 /* PR 12855: Null data is handled gracefully throughout. */
19143 data_end
= data
+ (end
- pltgot
);
19145 printf (_("\nStatic GOT:\n"));
19146 printf (_(" Canonical gp value: "));
19147 print_vma (ent
+ 0x7ff0, LONG_HEX
);
19150 /* In a dynamic binary GOT[0] is reserved for the dynamic
19151 loader to store the lazy resolver pointer, however in
19152 a static binary it may well have been omitted and GOT
19153 reduced to a table of addresses.
19154 PR 21344: Check for the entry being fully available
19155 before fetching it. */
19157 && data
+ ent
- pltgot
+ addr_size
<= data_end
19158 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
19160 printf (_(" Reserved entries:\n"));
19161 printf (_(" %*s %10s %*s\n"),
19162 addr_size
* 2, _("Address"), _("Access"),
19163 addr_size
* 2, _("Value"));
19164 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19166 if (ent
== (uint64_t) -1)
19167 goto sgot_print_fail
;
19169 /* Check for the MSB of GOT[1] being set, identifying a
19170 GNU object. This entry will be used by some runtime
19171 loaders, to store the module pointer. Otherwise this
19172 is an ordinary local entry.
19173 PR 21344: Check for the entry being fully available
19174 before fetching it. */
19176 && data
+ ent
- pltgot
+ addr_size
<= data_end
19177 && (byte_get (data
+ ent
- pltgot
, addr_size
)
19178 >> (addr_size
* 8 - 1)) != 0)
19180 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19182 if (ent
== (uint64_t) -1)
19183 goto sgot_print_fail
;
19188 if (data
!= NULL
&& ent
< end
)
19190 printf (_(" Local entries:\n"));
19191 printf (" %*s %10s %*s\n",
19192 addr_size
* 2, _("Address"), _("Access"),
19193 addr_size
* 2, _("Value"));
19196 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19198 if (ent
== (uint64_t) -1)
19199 goto sgot_print_fail
;
19210 for (entry
= filedata
->dynamic_section
;
19211 /* PR 17531 file: 012-50589-0.004. */
19212 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
19213 && entry
->d_tag
!= DT_NULL
);
19215 switch (entry
->d_tag
)
19217 case DT_MIPS_LIBLIST
:
19219 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
19220 liblistno
* sizeof (Elf32_External_Lib
));
19222 case DT_MIPS_LIBLISTNO
:
19223 liblistno
= entry
->d_un
.d_val
;
19225 case DT_MIPS_OPTIONS
:
19226 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
19228 case DT_MIPS_CONFLICT
:
19230 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
19231 conflictsno
* sizeof (Elf32_External_Conflict
));
19233 case DT_MIPS_CONFLICTNO
:
19234 conflictsno
= entry
->d_un
.d_val
;
19237 pltgot
= entry
->d_un
.d_ptr
;
19239 case DT_MIPS_LOCAL_GOTNO
:
19240 local_gotno
= entry
->d_un
.d_val
;
19242 case DT_MIPS_GOTSYM
:
19243 gotsym
= entry
->d_un
.d_val
;
19245 case DT_MIPS_SYMTABNO
:
19246 symtabno
= entry
->d_un
.d_val
;
19248 case DT_MIPS_PLTGOT
:
19249 mips_pltgot
= entry
->d_un
.d_ptr
;
19252 pltrel
= entry
->d_un
.d_val
;
19255 pltrelsz
= entry
->d_un
.d_val
;
19258 jmprel
= entry
->d_un
.d_ptr
;
19264 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
19266 Elf32_External_Lib
* elib
;
19269 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
19270 sizeof (Elf32_External_Lib
),
19272 _("liblist section data"));
19275 printf (ngettext ("\nSection '.liblist' contains %zu entry:\n",
19276 "\nSection '.liblist' contains %zu entries:\n",
19279 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
19282 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
19289 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
19290 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
19291 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
19292 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
19293 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
19295 tmp
= gmtime (&atime
);
19296 snprintf (timebuf
, sizeof (timebuf
),
19297 "%04u-%02u-%02uT%02u:%02u:%02u",
19298 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
19299 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
19301 printf ("%3zu: ", cnt
);
19302 if (valid_dynamic_name (filedata
, liblist
.l_name
))
19303 print_symbol_name (20, get_dynamic_name (filedata
, liblist
.l_name
));
19305 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
19306 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
19307 liblist
.l_version
);
19309 if (liblist
.l_flags
== 0)
19313 static const struct
19320 { " EXACT_MATCH", LL_EXACT_MATCH
},
19321 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
19322 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
19323 { " EXPORTS", LL_EXPORTS
},
19324 { " DELAY_LOAD", LL_DELAY_LOAD
},
19325 { " DELTA", LL_DELTA
}
19327 int flags
= liblist
.l_flags
;
19330 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
19331 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
19333 fputs (l_flags_vals
[fcnt
].name
, stdout
);
19334 flags
^= l_flags_vals
[fcnt
].bit
;
19337 printf (" %#x", (unsigned int) flags
);
19349 if (options_offset
!= 0)
19351 Elf_External_Options
* eopt
;
19355 /* Find the section header so that we get the size. */
19356 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
19357 /* PR 17533 file: 012-277276-0.004. */
19360 error (_("No MIPS_OPTIONS header found\n"));
19364 if (sect
->sh_size
< sizeof (* eopt
))
19366 error (_("The MIPS options section is too small.\n"));
19370 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
19371 sect
->sh_size
, _("options"));
19374 Elf_Internal_Options option
;
19377 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
19379 Elf_External_Options
* eoption
;
19380 unsigned int optsize
;
19382 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
19384 optsize
= BYTE_GET (eoption
->size
);
19386 /* PR 17531: file: ffa0fa3b. */
19387 if (optsize
< sizeof (* eopt
)
19388 || optsize
> sect
->sh_size
- offset
)
19390 error (_("Invalid size (%u) for MIPS option\n"),
19399 printf (ngettext ("\nSection '%s' contains %d entry:\n",
19400 "\nSection '%s' contains %d entries:\n",
19402 printable_section_name (filedata
, sect
), cnt
);
19408 Elf_External_Options
* eoption
;
19410 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
19412 option
.kind
= BYTE_GET (eoption
->kind
);
19413 option
.size
= BYTE_GET (eoption
->size
);
19414 option
.section
= BYTE_GET (eoption
->section
);
19415 option
.info
= BYTE_GET (eoption
->info
);
19417 switch (option
.kind
)
19420 /* This shouldn't happen. */
19421 printf (" NULL %" PRId16
" %" PRIx32
,
19422 option
.section
, option
.info
);
19426 printf (" REGINFO ");
19427 if (filedata
->file_header
.e_machine
== EM_MIPS
)
19429 Elf32_External_RegInfo
* ereg
;
19430 Elf32_RegInfo reginfo
;
19433 if (option
.size
< (sizeof (Elf_External_Options
)
19434 + sizeof (Elf32_External_RegInfo
)))
19436 printf (_("<corrupt>\n"));
19437 error (_("Truncated MIPS REGINFO option\n"));
19442 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
19444 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
19445 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
19446 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
19447 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
19448 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
19449 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
19451 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
19452 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
19454 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
19455 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
19456 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
19457 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
19462 Elf64_External_RegInfo
* ereg
;
19463 Elf64_Internal_RegInfo reginfo
;
19465 if (option
.size
< (sizeof (Elf_External_Options
)
19466 + sizeof (Elf64_External_RegInfo
)))
19468 printf (_("<corrupt>\n"));
19469 error (_("Truncated MIPS REGINFO option\n"));
19474 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
19475 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
19476 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
19477 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
19478 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
19479 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
19480 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
19482 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
19483 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
19485 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
19486 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
19487 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
19488 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
19490 offset
+= option
.size
;
19493 case ODK_EXCEPTIONS
:
19494 fputs (" EXCEPTIONS fpe_min(", stdout
);
19495 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
19496 fputs (") fpe_max(", stdout
);
19497 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
19498 fputs (")", stdout
);
19500 if (option
.info
& OEX_PAGE0
)
19501 fputs (" PAGE0", stdout
);
19502 if (option
.info
& OEX_SMM
)
19503 fputs (" SMM", stdout
);
19504 if (option
.info
& OEX_FPDBUG
)
19505 fputs (" FPDBUG", stdout
);
19506 if (option
.info
& OEX_DISMISS
)
19507 fputs (" DISMISS", stdout
);
19511 fputs (" PAD ", stdout
);
19512 if (option
.info
& OPAD_PREFIX
)
19513 fputs (" PREFIX", stdout
);
19514 if (option
.info
& OPAD_POSTFIX
)
19515 fputs (" POSTFIX", stdout
);
19516 if (option
.info
& OPAD_SYMBOL
)
19517 fputs (" SYMBOL", stdout
);
19521 fputs (" HWPATCH ", stdout
);
19522 if (option
.info
& OHW_R4KEOP
)
19523 fputs (" R4KEOP", stdout
);
19524 if (option
.info
& OHW_R8KPFETCH
)
19525 fputs (" R8KPFETCH", stdout
);
19526 if (option
.info
& OHW_R5KEOP
)
19527 fputs (" R5KEOP", stdout
);
19528 if (option
.info
& OHW_R5KCVTL
)
19529 fputs (" R5KCVTL", stdout
);
19533 fputs (" FILL ", stdout
);
19534 /* XXX Print content of info word? */
19538 fputs (" TAGS ", stdout
);
19539 /* XXX Print content of info word? */
19543 fputs (" HWAND ", stdout
);
19544 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
19545 fputs (" R4KEOP_CHECKED", stdout
);
19546 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
19547 fputs (" R4KEOP_CLEAN", stdout
);
19551 fputs (" HWOR ", stdout
);
19552 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
19553 fputs (" R4KEOP_CHECKED", stdout
);
19554 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
19555 fputs (" R4KEOP_CLEAN", stdout
);
19559 printf (" GP_GROUP %#06x self-contained %#06x",
19560 option
.info
& OGP_GROUP
,
19561 (option
.info
& OGP_SELF
) >> 16);
19565 printf (" IDENT %#06x self-contained %#06x",
19566 option
.info
& OGP_GROUP
,
19567 (option
.info
& OGP_SELF
) >> 16);
19571 /* This shouldn't happen. */
19572 printf (" %3d ??? %" PRId16
" %" PRIx32
,
19573 option
.kind
, option
.section
, option
.info
);
19577 len
= sizeof (* eopt
);
19578 while (len
< option
.size
)
19580 unsigned char datum
= *((unsigned char *) eoption
+ len
);
19582 if (ISPRINT (datum
))
19583 printf ("%c", datum
);
19585 printf ("\\%03o", datum
);
19588 fputs ("\n", stdout
);
19590 offset
+= option
.size
;
19598 if (conflicts_offset
!= 0 && conflictsno
!= 0)
19600 Elf32_Conflict
* iconf
;
19603 if (filedata
->dynamic_symbols
== NULL
)
19605 error (_("conflict list found without a dynamic symbol table\n"));
19609 /* PR 21345 - print a slightly more helpful error message
19610 if we are sure that the cmalloc will fail. */
19611 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
19613 error (_("Overlarge number of conflicts detected: %zx\n"),
19618 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
19621 error (_("Out of memory allocating space for dynamic conflicts\n"));
19627 Elf32_External_Conflict
* econf32
;
19629 econf32
= (Elf32_External_Conflict
*)
19630 get_data (NULL
, filedata
, conflicts_offset
,
19631 sizeof (*econf32
), conflictsno
, _("conflict"));
19638 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19639 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
19645 Elf64_External_Conflict
* econf64
;
19647 econf64
= (Elf64_External_Conflict
*)
19648 get_data (NULL
, filedata
, conflicts_offset
,
19649 sizeof (*econf64
), conflictsno
, _("conflict"));
19656 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19657 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
19662 printf (ngettext ("\nSection '.conflict' contains %zu entry:\n",
19663 "\nSection '.conflict' contains %zu entries:\n",
19666 puts (_(" Num: Index Value Name"));
19668 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
19670 printf ("%5zu: %8lu ", cnt
, iconf
[cnt
]);
19672 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
19673 printf (_("<corrupt symbol index>"));
19676 Elf_Internal_Sym
* psym
;
19678 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
19679 print_vma (psym
->st_value
, FULL_HEX
);
19681 if (valid_dynamic_name (filedata
, psym
->st_name
))
19682 print_symbol_name (25, get_dynamic_name (filedata
, psym
->st_name
));
19684 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19692 if (pltgot
!= 0 && local_gotno
!= 0)
19694 uint64_t ent
, local_end
, global_end
;
19696 unsigned char * data
;
19697 unsigned char * data_end
;
19701 addr_size
= (is_32bit_elf
? 4 : 8);
19702 local_end
= pltgot
+ local_gotno
* addr_size
;
19704 /* PR binutils/17533 file: 012-111227-0.004 */
19705 if (symtabno
< gotsym
)
19707 error (_("The GOT symbol offset (%" PRIu64
19708 ") is greater than the symbol table size (%" PRIu64
")\n"),
19713 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
19714 /* PR 17531: file: 54c91a34. */
19715 if (global_end
< local_end
)
19717 error (_("Too many GOT symbols: %" PRIu64
"\n"), symtabno
);
19721 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
19722 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
19723 global_end
- pltgot
, 1,
19724 _("Global Offset Table data"));
19725 /* PR 12855: Null data is handled gracefully throughout. */
19726 data_end
= data
+ (global_end
- pltgot
);
19728 printf (_("\nPrimary GOT:\n"));
19729 printf (_(" Canonical gp value: "));
19730 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
19733 printf (_(" Reserved entries:\n"));
19734 printf (_(" %*s %10s %*s Purpose\n"),
19735 addr_size
* 2, _("Address"), _("Access"),
19736 addr_size
* 2, _("Initial"));
19737 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19738 printf (_(" Lazy resolver\n"));
19739 if (ent
== (uint64_t) -1)
19740 goto got_print_fail
;
19742 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
19743 This entry will be used by some runtime loaders, to store the
19744 module pointer. Otherwise this is an ordinary local entry.
19745 PR 21344: Check for the entry being fully available before
19748 && data
+ ent
- pltgot
+ addr_size
<= data_end
19749 && (byte_get (data
+ ent
- pltgot
, addr_size
)
19750 >> (addr_size
* 8 - 1)) != 0)
19752 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19753 printf (_(" Module pointer (GNU extension)\n"));
19754 if (ent
== (uint64_t) -1)
19755 goto got_print_fail
;
19759 if (data
!= NULL
&& ent
< local_end
)
19761 printf (_(" Local entries:\n"));
19762 printf (" %*s %10s %*s\n",
19763 addr_size
* 2, _("Address"), _("Access"),
19764 addr_size
* 2, _("Initial"));
19765 while (ent
< local_end
)
19767 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19769 if (ent
== (uint64_t) -1)
19770 goto got_print_fail
;
19775 if (data
!= NULL
&& gotsym
< symtabno
)
19779 printf (_(" Global entries:\n"));
19780 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
19781 addr_size
* 2, _("Address"),
19783 addr_size
* 2, _("Initial"),
19784 addr_size
* 2, _("Sym.Val."),
19786 /* Note for translators: "Ndx" = abbreviated form of "Index". */
19787 _("Ndx"), _("Name"));
19789 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
19791 for (i
= gotsym
; i
< symtabno
; i
++)
19793 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19796 if (filedata
->dynamic_symbols
== NULL
)
19797 printf (_("<no dynamic symbols>"));
19798 else if (i
< filedata
->num_dynamic_syms
)
19800 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
19802 print_vma (psym
->st_value
, LONG_HEX
);
19803 printf (" %-7s ", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
19806 const char * s
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
19808 printf ("%3s ", s
);
19810 printf ("%3u ", psym
->st_shndx
);
19812 if (valid_dynamic_name (filedata
, psym
->st_name
))
19813 print_symbol_name (sym_width
,
19814 get_dynamic_name (filedata
, psym
->st_name
));
19816 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19819 printf (_("<symbol index %zu exceeds number of dynamic symbols>"),
19823 if (ent
== (uint64_t) -1)
19833 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
19836 uint64_t offset
, rel_offset
;
19838 unsigned char * data
;
19839 int addr_size
, sym_width
;
19840 Elf_Internal_Rela
* rels
;
19842 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
19843 if (pltrel
== DT_RELA
)
19845 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19850 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19855 addr_size
= (is_32bit_elf
? 4 : 8);
19856 end
= mips_pltgot
+ (2 + count
) * addr_size
;
19858 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
19859 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
19860 1, _("Procedure Linkage Table data"));
19867 printf ("\nPLT GOT:\n\n");
19868 printf (_(" Reserved entries:\n"));
19869 printf (_(" %*s %*s Purpose\n"),
19870 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
19871 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19872 printf (_(" PLT lazy resolver\n"));
19873 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19874 printf (_(" Module pointer\n"));
19877 printf (_(" Entries:\n"));
19878 printf (" %*s %*s %*s %-7s %3s %s\n",
19879 addr_size
* 2, _("Address"),
19880 addr_size
* 2, _("Initial"),
19881 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
19882 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
19883 for (i
= 0; i
< count
; i
++)
19885 uint64_t idx
= get_reloc_symindex (rels
[i
].r_info
);
19887 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19890 if (idx
>= filedata
->num_dynamic_syms
)
19891 printf (_("<corrupt symbol index: %" PRIu64
">"), idx
);
19894 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
19896 print_vma (psym
->st_value
, LONG_HEX
);
19897 printf (" %-7s %3s ",
19898 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19899 printable_section_name_from_index (filedata
, psym
->st_shndx
, NULL
));
19900 if (valid_dynamic_name (filedata
, psym
->st_name
))
19901 print_symbol_name (sym_width
,
19902 get_dynamic_name (filedata
, psym
->st_name
));
19904 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19918 process_nds32_specific (Filedata
* filedata
)
19920 Elf_Internal_Shdr
*sect
= NULL
;
19922 sect
= find_section (filedata
, ".nds32_e_flags");
19923 if (sect
!= NULL
&& sect
->sh_size
>= 4)
19925 unsigned char *buf
;
19928 printf ("\nNDS32 elf flags section:\n");
19929 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
19930 _("NDS32 elf flags section"));
19935 flag
= byte_get (buf
, 4);
19937 switch (flag
& 0x3)
19940 printf ("(VEC_SIZE):\tNo entry.\n");
19943 printf ("(VEC_SIZE):\t4 bytes\n");
19946 printf ("(VEC_SIZE):\t16 bytes\n");
19949 printf ("(VEC_SIZE):\treserved\n");
19958 process_gnu_liblist (Filedata
* filedata
)
19960 Elf_Internal_Shdr
* section
;
19961 Elf_Internal_Shdr
* string_sec
;
19962 Elf32_External_Lib
* elib
;
19964 size_t strtab_size
;
19966 uint64_t num_liblist
;
19973 for (i
= 0, section
= filedata
->section_headers
;
19974 i
< filedata
->file_header
.e_shnum
;
19977 switch (section
->sh_type
)
19979 case SHT_GNU_LIBLIST
:
19980 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
19983 elib
= (Elf32_External_Lib
*)
19984 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
19985 _("liblist section data"));
19993 string_sec
= filedata
->section_headers
+ section
->sh_link
;
19994 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
19995 string_sec
->sh_size
,
19996 _("liblist string table"));
19998 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
20005 strtab_size
= string_sec
->sh_size
;
20007 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
20008 printf (ngettext ("\nLibrary list section '%s' contains %" PRIu64
20010 "\nLibrary list section '%s' contains %" PRIu64
20013 printable_section_name (filedata
, section
),
20016 puts (_(" Library Time Stamp Checksum Version Flags"));
20018 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
20026 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
20027 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
20028 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
20029 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
20030 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
20032 tmp
= gmtime (&atime
);
20033 snprintf (timebuf
, sizeof (timebuf
),
20034 "%04u-%02u-%02uT%02u:%02u:%02u",
20035 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
20036 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
20038 printf ("%3zu: ", cnt
);
20040 printf ("%-20s", liblist
.l_name
< strtab_size
20041 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
20043 printf ("%-20.20s", liblist
.l_name
< strtab_size
20044 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
20045 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
20046 liblist
.l_version
, liblist
.l_flags
);
20057 static const char *
20058 get_note_type (Filedata
* filedata
, unsigned e_type
)
20060 static char buff
[64];
20062 if (filedata
->file_header
.e_type
== ET_CORE
)
20066 return _("NT_AUXV (auxiliary vector)");
20068 return _("NT_PRSTATUS (prstatus structure)");
20070 return _("NT_FPREGSET (floating point registers)");
20072 return _("NT_PRPSINFO (prpsinfo structure)");
20073 case NT_TASKSTRUCT
:
20074 return _("NT_TASKSTRUCT (task structure)");
20076 return _("NT_GDB_TDESC (GDB XML target description)");
20078 return _("NT_PRXFPREG (user_xfpregs structure)");
20080 return _("NT_PPC_VMX (ppc Altivec registers)");
20082 return _("NT_PPC_VSX (ppc VSX registers)");
20084 return _("NT_PPC_TAR (ppc TAR register)");
20086 return _("NT_PPC_PPR (ppc PPR register)");
20088 return _("NT_PPC_DSCR (ppc DSCR register)");
20090 return _("NT_PPC_EBB (ppc EBB registers)");
20092 return _("NT_PPC_PMU (ppc PMU registers)");
20093 case NT_PPC_TM_CGPR
:
20094 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
20095 case NT_PPC_TM_CFPR
:
20096 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
20097 case NT_PPC_TM_CVMX
:
20098 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
20099 case NT_PPC_TM_CVSX
:
20100 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
20101 case NT_PPC_TM_SPR
:
20102 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
20103 case NT_PPC_TM_CTAR
:
20104 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
20105 case NT_PPC_TM_CPPR
:
20106 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
20107 case NT_PPC_TM_CDSCR
:
20108 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
20110 return _("NT_386_TLS (x86 TLS information)");
20111 case NT_386_IOPERM
:
20112 return _("NT_386_IOPERM (x86 I/O permissions)");
20113 case NT_X86_XSTATE
:
20114 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
20116 return _("NT_X86_CET (x86 CET state)");
20117 case NT_S390_HIGH_GPRS
:
20118 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
20119 case NT_S390_TIMER
:
20120 return _("NT_S390_TIMER (s390 timer register)");
20121 case NT_S390_TODCMP
:
20122 return _("NT_S390_TODCMP (s390 TOD comparator register)");
20123 case NT_S390_TODPREG
:
20124 return _("NT_S390_TODPREG (s390 TOD programmable register)");
20126 return _("NT_S390_CTRS (s390 control registers)");
20127 case NT_S390_PREFIX
:
20128 return _("NT_S390_PREFIX (s390 prefix register)");
20129 case NT_S390_LAST_BREAK
:
20130 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
20131 case NT_S390_SYSTEM_CALL
:
20132 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
20134 return _("NT_S390_TDB (s390 transaction diagnostic block)");
20135 case NT_S390_VXRS_LOW
:
20136 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
20137 case NT_S390_VXRS_HIGH
:
20138 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
20139 case NT_S390_GS_CB
:
20140 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
20141 case NT_S390_GS_BC
:
20142 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
20144 return _("NT_ARM_VFP (arm VFP registers)");
20146 return _("NT_ARM_TLS (AArch TLS registers)");
20147 case NT_ARM_HW_BREAK
:
20148 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
20149 case NT_ARM_HW_WATCH
:
20150 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
20151 case NT_ARM_SYSTEM_CALL
:
20152 return _("NT_ARM_SYSTEM_CALL (AArch system call number)");
20154 return _("NT_ARM_SVE (AArch SVE registers)");
20155 case NT_ARM_PAC_MASK
:
20156 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
20157 case NT_ARM_PACA_KEYS
:
20158 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
20159 case NT_ARM_PACG_KEYS
:
20160 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
20161 case NT_ARM_TAGGED_ADDR_CTRL
:
20162 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
20164 return _("NT_ARM_SSVE (AArch64 streaming SVE registers)");
20166 return _("NT_ARM_ZA (AArch64 SME ZA register)");
20168 return _("NT_ARM_ZT (AArch64 SME2 ZT registers)");
20169 case NT_ARM_PAC_ENABLED_KEYS
:
20170 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
20172 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
20174 return _("NT_RISCV_CSR (RISC-V control and status registers)");
20176 return _("NT_PSTATUS (pstatus structure)");
20178 return _("NT_FPREGS (floating point registers)");
20180 return _("NT_PSINFO (psinfo structure)");
20182 return _("NT_LWPSTATUS (lwpstatus_t structure)");
20184 return _("NT_LWPSINFO (lwpsinfo_t structure)");
20185 case NT_WIN32PSTATUS
:
20186 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
20188 return _("NT_SIGINFO (siginfo_t data)");
20190 return _("NT_FILE (mapped files)");
20198 return _("NT_VERSION (version)");
20200 return _("NT_ARCH (architecture)");
20201 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
20203 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
20205 case NT_GO_BUILDID
:
20206 return _("GO BUILDID");
20207 case FDO_PACKAGING_METADATA
:
20208 return _("FDO_PACKAGING_METADATA");
20213 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20218 print_core_note (Elf_Internal_Note
*pnote
)
20220 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
20221 uint64_t count
, page_size
;
20222 unsigned char *descdata
, *filenames
, *descend
;
20224 if (pnote
->type
!= NT_FILE
)
20233 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
20234 /* Still "successful". */
20238 if (pnote
->descsz
< 2 * addr_size
)
20240 error (_(" Malformed note - too short for header\n"));
20244 descdata
= (unsigned char *) pnote
->descdata
;
20245 descend
= descdata
+ pnote
->descsz
;
20247 if (descdata
[pnote
->descsz
- 1] != '\0')
20249 error (_(" Malformed note - does not end with \\0\n"));
20253 count
= byte_get (descdata
, addr_size
);
20254 descdata
+= addr_size
;
20256 page_size
= byte_get (descdata
, addr_size
);
20257 descdata
+= addr_size
;
20259 if (count
> ((uint64_t) -1 - 2 * addr_size
) / (3 * addr_size
)
20260 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
20262 error (_(" Malformed note - too short for supplied file count\n"));
20266 printf (_(" Page size: "));
20267 print_vma (page_size
, DEC
);
20270 printf (_(" %*s%*s%*s\n"),
20271 (int) (2 + 2 * addr_size
), _("Start"),
20272 (int) (4 + 2 * addr_size
), _("End"),
20273 (int) (4 + 2 * addr_size
), _("Page Offset"));
20274 filenames
= descdata
+ count
* 3 * addr_size
;
20275 while (count
-- > 0)
20277 uint64_t start
, end
, file_ofs
;
20279 if (filenames
== descend
)
20281 error (_(" Malformed note - filenames end too early\n"));
20285 start
= byte_get (descdata
, addr_size
);
20286 descdata
+= addr_size
;
20287 end
= byte_get (descdata
, addr_size
);
20288 descdata
+= addr_size
;
20289 file_ofs
= byte_get (descdata
, addr_size
);
20290 descdata
+= addr_size
;
20293 print_vma (start
, FULL_HEX
);
20295 print_vma (end
, FULL_HEX
);
20297 print_vma (file_ofs
, FULL_HEX
);
20298 printf ("\n %s\n", filenames
);
20300 filenames
+= 1 + strlen ((char *) filenames
);
20306 static const char *
20307 get_gnu_elf_note_type (unsigned e_type
)
20309 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
20312 case NT_GNU_ABI_TAG
:
20313 return _("NT_GNU_ABI_TAG (ABI version tag)");
20315 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
20316 case NT_GNU_BUILD_ID
:
20317 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
20318 case NT_GNU_GOLD_VERSION
:
20319 return _("NT_GNU_GOLD_VERSION (gold version)");
20320 case NT_GNU_PROPERTY_TYPE_0
:
20321 return _("NT_GNU_PROPERTY_TYPE_0");
20322 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
20323 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
20324 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
20325 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
20328 static char buff
[64];
20330 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20337 decode_x86_compat_isa (unsigned int bitmask
)
20341 unsigned int bit
= bitmask
& (- bitmask
);
20346 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
20349 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
20352 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
20355 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
20358 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
20361 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
20364 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
20367 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
20370 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
20373 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
20376 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
20379 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
20380 printf ("AVX512F");
20382 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
20383 printf ("AVX512CD");
20385 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
20386 printf ("AVX512ER");
20388 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
20389 printf ("AVX512PF");
20391 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
20392 printf ("AVX512VL");
20394 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
20395 printf ("AVX512DQ");
20397 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
20398 printf ("AVX512BW");
20401 printf (_("<unknown: %x>"), bit
);
20410 decode_x86_compat_2_isa (unsigned int bitmask
)
20414 printf (_("<None>"));
20420 unsigned int bit
= bitmask
& (- bitmask
);
20425 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
20428 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
20431 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
20434 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
20437 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
20440 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
20443 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
20446 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
20449 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
20452 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
20455 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
20456 printf ("AVX512F");
20458 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
20459 printf ("AVX512CD");
20461 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
20462 printf ("AVX512ER");
20464 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
20465 printf ("AVX512PF");
20467 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
20468 printf ("AVX512VL");
20470 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
20471 printf ("AVX512DQ");
20473 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
20474 printf ("AVX512BW");
20476 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
20477 printf ("AVX512_4FMAPS");
20479 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
20480 printf ("AVX512_4VNNIW");
20482 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
20483 printf ("AVX512_BITALG");
20485 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
20486 printf ("AVX512_IFMA");
20488 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
20489 printf ("AVX512_VBMI");
20491 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
20492 printf ("AVX512_VBMI2");
20494 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
20495 printf ("AVX512_VNNI");
20497 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
20498 printf ("AVX512_BF16");
20501 printf (_("<unknown: %x>"), bit
);
20509 static const char *
20510 get_amdgpu_elf_note_type (unsigned int e_type
)
20514 case NT_AMDGPU_METADATA
:
20515 return _("NT_AMDGPU_METADATA (code object metadata)");
20518 static char buf
[64];
20519 snprintf (buf
, sizeof (buf
), _("Unknown note type: (0x%08x)"), e_type
);
20526 decode_x86_isa (unsigned int bitmask
)
20530 unsigned int bit
= bitmask
& (- bitmask
);
20535 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
20536 printf ("x86-64-baseline");
20538 case GNU_PROPERTY_X86_ISA_1_V2
:
20539 printf ("x86-64-v2");
20541 case GNU_PROPERTY_X86_ISA_1_V3
:
20542 printf ("x86-64-v3");
20544 case GNU_PROPERTY_X86_ISA_1_V4
:
20545 printf ("x86-64-v4");
20548 printf (_("<unknown: %x>"), bit
);
20557 decode_x86_feature_1 (unsigned int bitmask
)
20561 printf (_("<None>"));
20567 unsigned int bit
= bitmask
& (- bitmask
);
20572 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
20575 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
20578 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
20579 printf ("LAM_U48");
20581 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
20582 printf ("LAM_U57");
20585 printf (_("<unknown: %x>"), bit
);
20594 decode_x86_feature_2 (unsigned int bitmask
)
20598 printf (_("<None>"));
20604 unsigned int bit
= bitmask
& (- bitmask
);
20609 case GNU_PROPERTY_X86_FEATURE_2_X86
:
20612 case GNU_PROPERTY_X86_FEATURE_2_X87
:
20615 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
20618 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
20621 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
20624 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
20627 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
20630 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
20633 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
20636 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
20639 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
20640 printf ("XSAVEOPT");
20642 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
20646 printf (_("<unknown: %x>"), bit
);
20655 decode_aarch64_feature_1_and (unsigned int bitmask
)
20659 unsigned int bit
= bitmask
& (- bitmask
);
20664 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
20668 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
20673 printf (_("<unknown: %x>"), bit
);
20682 decode_1_needed (unsigned int bitmask
)
20686 unsigned int bit
= bitmask
& (- bitmask
);
20691 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
20692 printf ("indirect external access");
20695 printf (_("<unknown: %x>"), bit
);
20704 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
20706 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
20707 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
20708 unsigned int size
= is_32bit_elf
? 4 : 8;
20710 printf (_(" Properties: "));
20712 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
20714 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
20718 while (ptr
< ptr_end
)
20722 unsigned int datasz
;
20724 if ((size_t) (ptr_end
- ptr
) < 8)
20726 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
20730 type
= byte_get (ptr
, 4);
20731 datasz
= byte_get (ptr
+ 4, 4);
20735 if (datasz
> (size_t) (ptr_end
- ptr
))
20737 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
20742 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
20744 if (filedata
->file_header
.e_machine
== EM_X86_64
20745 || filedata
->file_header
.e_machine
== EM_IAMCU
20746 || filedata
->file_header
.e_machine
== EM_386
)
20748 unsigned int bitmask
;
20751 bitmask
= byte_get (ptr
, 4);
20757 case GNU_PROPERTY_X86_ISA_1_USED
:
20759 printf (_("x86 ISA used: <corrupt length: %#x> "),
20763 printf ("x86 ISA used: ");
20764 decode_x86_isa (bitmask
);
20768 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
20770 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20774 printf ("x86 ISA needed: ");
20775 decode_x86_isa (bitmask
);
20779 case GNU_PROPERTY_X86_FEATURE_1_AND
:
20781 printf (_("x86 feature: <corrupt length: %#x> "),
20785 printf ("x86 feature: ");
20786 decode_x86_feature_1 (bitmask
);
20790 case GNU_PROPERTY_X86_FEATURE_2_USED
:
20792 printf (_("x86 feature used: <corrupt length: %#x> "),
20796 printf ("x86 feature used: ");
20797 decode_x86_feature_2 (bitmask
);
20801 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
20803 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
20806 printf ("x86 feature needed: ");
20807 decode_x86_feature_2 (bitmask
);
20811 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
20813 printf (_("x86 ISA used: <corrupt length: %#x> "),
20817 printf ("x86 ISA used: ");
20818 decode_x86_compat_isa (bitmask
);
20822 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
20824 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20828 printf ("x86 ISA needed: ");
20829 decode_x86_compat_isa (bitmask
);
20833 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
20835 printf (_("x86 ISA used: <corrupt length: %#x> "),
20839 printf ("x86 ISA used: ");
20840 decode_x86_compat_2_isa (bitmask
);
20844 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
20846 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20850 printf ("x86 ISA needed: ");
20851 decode_x86_compat_2_isa (bitmask
);
20859 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
20861 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
20863 printf ("AArch64 feature: ");
20865 printf (_("<corrupt length: %#x> "), datasz
);
20867 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
20876 case GNU_PROPERTY_STACK_SIZE
:
20877 printf (_("stack size: "));
20878 if (datasz
!= size
)
20879 printf (_("<corrupt length: %#x> "), datasz
);
20881 printf ("%#" PRIx64
, byte_get (ptr
, size
));
20884 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
20885 printf ("no copy on protected ");
20887 printf (_("<corrupt length: %#x> "), datasz
);
20891 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
20892 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
20893 || (type
>= GNU_PROPERTY_UINT32_OR_LO
20894 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
20898 case GNU_PROPERTY_1_NEEDED
:
20900 printf (_("1_needed: <corrupt length: %#x> "),
20904 unsigned int bitmask
= byte_get (ptr
, 4);
20905 printf ("1_needed: ");
20906 decode_1_needed (bitmask
);
20913 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
20914 printf (_("UINT32_AND (%#x): "), type
);
20916 printf (_("UINT32_OR (%#x): "), type
);
20918 printf (_("<corrupt length: %#x> "), datasz
);
20920 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
20927 if (type
< GNU_PROPERTY_LOPROC
)
20928 printf (_("<unknown type %#x data: "), type
);
20929 else if (type
< GNU_PROPERTY_LOUSER
)
20930 printf (_("<processor-specific type %#x data: "), type
);
20932 printf (_("<application-specific type %#x data: "), type
);
20933 for (j
= 0; j
< datasz
; ++j
)
20934 printf ("%02x ", ptr
[j
] & 0xff);
20938 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
20939 if (ptr
== ptr_end
)
20952 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
20954 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
20955 switch (pnote
->type
)
20957 case NT_GNU_BUILD_ID
:
20961 printf (_(" Build ID: "));
20962 for (i
= 0; i
< pnote
->descsz
; ++i
)
20963 printf ("%02x", pnote
->descdata
[i
] & 0xff);
20968 case NT_GNU_ABI_TAG
:
20970 unsigned int os
, major
, minor
, subminor
;
20971 const char *osname
;
20973 /* PR 17531: file: 030-599401-0.004. */
20974 if (pnote
->descsz
< 16)
20976 printf (_(" <corrupt GNU_ABI_TAG>\n"));
20980 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20981 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20982 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
20983 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
20987 case GNU_ABI_TAG_LINUX
:
20990 case GNU_ABI_TAG_HURD
:
20993 case GNU_ABI_TAG_SOLARIS
:
20994 osname
= "Solaris";
20996 case GNU_ABI_TAG_FREEBSD
:
20997 osname
= "FreeBSD";
20999 case GNU_ABI_TAG_NETBSD
:
21002 case GNU_ABI_TAG_SYLLABLE
:
21003 osname
= "Syllable";
21005 case GNU_ABI_TAG_NACL
:
21009 osname
= "Unknown";
21013 printf (_(" OS: %s, ABI: %d.%d.%d\n"), osname
,
21014 major
, minor
, subminor
);
21018 case NT_GNU_GOLD_VERSION
:
21022 printf (_(" Version: "));
21023 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
21024 printf ("%c", pnote
->descdata
[i
]);
21031 unsigned int num_entries
, mask
;
21033 /* Hardware capabilities information. Word 0 is the number of entries.
21034 Word 1 is a bitmask of enabled entries. The rest of the descriptor
21035 is a series of entries, where each entry is a single byte followed
21036 by a nul terminated string. The byte gives the bit number to test
21037 if enabled in the bitmask. */
21038 printf (_(" Hardware Capabilities: "));
21039 if (pnote
->descsz
< 8)
21041 error (_("<corrupt GNU_HWCAP>\n"));
21044 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21045 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
21046 printf (_("num entries: %d, enabled mask: %x\n"), num_entries
, mask
);
21047 /* FIXME: Add code to display the entries... */
21051 case NT_GNU_PROPERTY_TYPE_0
:
21052 print_gnu_property_note (filedata
, pnote
);
21056 /* Handle unrecognised types. An error message should have already been
21057 created by get_gnu_elf_note_type(), so all that we need to do is to
21058 display the data. */
21062 printf (_(" Description data: "));
21063 for (i
= 0; i
< pnote
->descsz
; ++i
)
21064 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
21073 static const char *
21074 get_v850_elf_note_type (enum v850_notes n_type
)
21076 static char buff
[64];
21080 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
21081 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
21082 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
21083 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
21084 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
21085 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
21087 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
21093 print_v850_note (Elf_Internal_Note
* pnote
)
21097 if (pnote
->descsz
!= 4)
21100 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
21104 printf (_("not set\n"));
21108 switch (pnote
->type
)
21110 case V850_NOTE_ALIGNMENT
:
21113 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
21114 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
21118 case V850_NOTE_DATA_SIZE
:
21121 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
21122 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
21126 case V850_NOTE_FPU_INFO
:
21129 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
21130 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
21134 case V850_NOTE_MMU_INFO
:
21135 case V850_NOTE_CACHE_INFO
:
21136 case V850_NOTE_SIMD_INFO
:
21137 if (val
== EF_RH850_SIMD
)
21139 printf (_("yes\n"));
21145 /* An 'unknown note type' message will already have been displayed. */
21149 printf (_("unknown value: %x\n"), val
);
21154 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
21156 unsigned int version
;
21158 switch (pnote
->type
)
21160 case NT_NETBSD_IDENT
:
21161 if (pnote
->descsz
< 1)
21163 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
21164 if ((version
/ 10000) % 100)
21165 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
21166 version
, version
/ 100000000, (version
/ 1000000) % 100,
21167 (version
/ 10000) % 100 > 26 ? "Z" : "",
21168 'A' + (version
/ 10000) % 26);
21170 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
21171 version
, version
/ 100000000, (version
/ 1000000) % 100,
21172 (version
/ 100) % 100);
21175 case NT_NETBSD_MARCH
:
21176 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
21180 case NT_NETBSD_PAX
:
21181 if (pnote
->descsz
< 1)
21183 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
21184 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
21185 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
21186 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
21187 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
21188 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
21189 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
21190 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
21194 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
21195 pnote
->descsz
, pnote
->type
);
21199 static const char *
21200 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21204 case NT_FREEBSD_THRMISC
:
21205 return _("NT_THRMISC (thrmisc structure)");
21206 case NT_FREEBSD_PROCSTAT_PROC
:
21207 return _("NT_PROCSTAT_PROC (proc data)");
21208 case NT_FREEBSD_PROCSTAT_FILES
:
21209 return _("NT_PROCSTAT_FILES (files data)");
21210 case NT_FREEBSD_PROCSTAT_VMMAP
:
21211 return _("NT_PROCSTAT_VMMAP (vmmap data)");
21212 case NT_FREEBSD_PROCSTAT_GROUPS
:
21213 return _("NT_PROCSTAT_GROUPS (groups data)");
21214 case NT_FREEBSD_PROCSTAT_UMASK
:
21215 return _("NT_PROCSTAT_UMASK (umask data)");
21216 case NT_FREEBSD_PROCSTAT_RLIMIT
:
21217 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
21218 case NT_FREEBSD_PROCSTAT_OSREL
:
21219 return _("NT_PROCSTAT_OSREL (osreldate data)");
21220 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
21221 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
21222 case NT_FREEBSD_PROCSTAT_AUXV
:
21223 return _("NT_PROCSTAT_AUXV (auxv data)");
21224 case NT_FREEBSD_PTLWPINFO
:
21225 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
21226 case NT_FREEBSD_X86_SEGBASES
:
21227 return _("NT_X86_SEGBASES (x86 segment base registers)");
21229 return get_note_type (filedata
, e_type
);
21232 static const char *
21233 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21235 static char buff
[64];
21239 case NT_NETBSDCORE_PROCINFO
:
21240 /* NetBSD core "procinfo" structure. */
21241 return _("NetBSD procinfo structure");
21243 case NT_NETBSDCORE_AUXV
:
21244 return _("NetBSD ELF auxiliary vector data");
21246 case NT_NETBSDCORE_LWPSTATUS
:
21247 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
21250 /* As of Jan 2020 there are no other machine-independent notes
21251 defined for NetBSD core files. If the note type is less
21252 than the start of the machine-dependent note types, we don't
21255 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
21257 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21263 switch (filedata
->file_header
.e_machine
)
21265 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
21266 and PT_GETFPREGS == mach+2. */
21271 case EM_SPARC32PLUS
:
21275 case NT_NETBSDCORE_FIRSTMACH
+ 0:
21276 return _("PT_GETREGS (reg structure)");
21277 case NT_NETBSDCORE_FIRSTMACH
+ 2:
21278 return _("PT_GETFPREGS (fpreg structure)");
21284 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
21285 There's also old PT___GETREGS40 == mach + 1 for old reg
21286 structure which lacks GBR. */
21290 case NT_NETBSDCORE_FIRSTMACH
+ 1:
21291 return _("PT___GETREGS40 (old reg structure)");
21292 case NT_NETBSDCORE_FIRSTMACH
+ 3:
21293 return _("PT_GETREGS (reg structure)");
21294 case NT_NETBSDCORE_FIRSTMACH
+ 5:
21295 return _("PT_GETFPREGS (fpreg structure)");
21301 /* On all other arch's, PT_GETREGS == mach+1 and
21302 PT_GETFPREGS == mach+3. */
21306 case NT_NETBSDCORE_FIRSTMACH
+ 1:
21307 return _("PT_GETREGS (reg structure)");
21308 case NT_NETBSDCORE_FIRSTMACH
+ 3:
21309 return _("PT_GETFPREGS (fpreg structure)");
21315 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
21316 e_type
- NT_NETBSDCORE_FIRSTMACH
);
21320 static const char *
21321 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21325 case NT_OPENBSD_PROCINFO
:
21326 return _("OpenBSD procinfo structure");
21327 case NT_OPENBSD_AUXV
:
21328 return _("OpenBSD ELF auxiliary vector data");
21329 case NT_OPENBSD_REGS
:
21330 return _("OpenBSD regular registers");
21331 case NT_OPENBSD_FPREGS
:
21332 return _("OpenBSD floating point registers");
21333 case NT_OPENBSD_WCOOKIE
:
21334 return _("OpenBSD window cookie");
21337 return get_note_type (filedata
, e_type
);
21340 static const char *
21341 get_qnx_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
21345 case QNT_DEBUG_FULLPATH
:
21346 return _("QNX debug fullpath");
21347 case QNT_DEBUG_RELOC
:
21348 return _("QNX debug relocation");
21350 return _("QNX stack");
21351 case QNT_GENERATOR
:
21352 return _("QNX generator");
21353 case QNT_DEFAULT_LIB
:
21354 return _("QNX default library");
21355 case QNT_CORE_SYSINFO
:
21356 return _("QNX core sysinfo");
21357 case QNT_CORE_INFO
:
21358 return _("QNX core info");
21359 case QNT_CORE_STATUS
:
21360 return _("QNX core status");
21361 case QNT_CORE_GREG
:
21362 return _("QNX general registers");
21363 case QNT_CORE_FPREG
:
21364 return _("QNX floating point registers");
21366 return _("QNX link map");
21369 return get_note_type (filedata
, e_type
);
21372 static const char *
21373 get_stapsdt_note_type (unsigned e_type
)
21375 static char buff
[64];
21380 return _("NT_STAPSDT (SystemTap probe descriptors)");
21386 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21391 print_stapsdt_note (Elf_Internal_Note
*pnote
)
21393 size_t len
, maxlen
;
21394 size_t addr_size
= is_32bit_elf
? 4 : 8;
21395 char *data
= pnote
->descdata
;
21396 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
21397 uint64_t pc
, base_addr
, semaphore
;
21398 char *provider
, *probe
, *arg_fmt
;
21400 if (pnote
->descsz
< (addr_size
* 3))
21401 goto stapdt_note_too_small
;
21403 pc
= byte_get ((unsigned char *) data
, addr_size
);
21406 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
21409 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
21412 if (data
>= data_end
)
21413 goto stapdt_note_too_small
;
21414 maxlen
= data_end
- data
;
21415 len
= strnlen (data
, maxlen
);
21422 goto stapdt_note_too_small
;
21424 if (data
>= data_end
)
21425 goto stapdt_note_too_small
;
21426 maxlen
= data_end
- data
;
21427 len
= strnlen (data
, maxlen
);
21434 goto stapdt_note_too_small
;
21436 if (data
>= data_end
)
21437 goto stapdt_note_too_small
;
21438 maxlen
= data_end
- data
;
21439 len
= strnlen (data
, maxlen
);
21446 goto stapdt_note_too_small
;
21448 printf (_(" Provider: %s\n"), provider
);
21449 printf (_(" Name: %s\n"), probe
);
21450 printf (_(" Location: "));
21451 print_vma (pc
, FULL_HEX
);
21452 printf (_(", Base: "));
21453 print_vma (base_addr
, FULL_HEX
);
21454 printf (_(", Semaphore: "));
21455 print_vma (semaphore
, FULL_HEX
);
21457 printf (_(" Arguments: %s\n"), arg_fmt
);
21459 return data
== data_end
;
21461 stapdt_note_too_small
:
21462 printf (_(" <corrupt - note is too small>\n"));
21463 error (_("corrupt stapdt note - the data size is too small\n"));
21468 print_fdo_note (Elf_Internal_Note
* pnote
)
21470 if (pnote
->descsz
> 0 && pnote
->type
== FDO_PACKAGING_METADATA
)
21472 printf (_(" Packaging Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
21478 static const char *
21479 get_ia64_vms_note_type (unsigned e_type
)
21481 static char buff
[64];
21486 return _("NT_VMS_MHD (module header)");
21488 return _("NT_VMS_LNM (language name)");
21490 return _("NT_VMS_SRC (source files)");
21492 return "NT_VMS_TITLE";
21494 return _("NT_VMS_EIDC (consistency check)");
21495 case NT_VMS_FPMODE
:
21496 return _("NT_VMS_FPMODE (FP mode)");
21497 case NT_VMS_LINKTIME
:
21498 return "NT_VMS_LINKTIME";
21499 case NT_VMS_IMGNAM
:
21500 return _("NT_VMS_IMGNAM (image name)");
21502 return _("NT_VMS_IMGID (image id)");
21503 case NT_VMS_LINKID
:
21504 return _("NT_VMS_LINKID (link id)");
21505 case NT_VMS_IMGBID
:
21506 return _("NT_VMS_IMGBID (build id)");
21507 case NT_VMS_GSTNAM
:
21508 return _("NT_VMS_GSTNAM (sym table name)");
21509 case NT_VMS_ORIG_DYN
:
21510 return "NT_VMS_ORIG_DYN";
21511 case NT_VMS_PATCHTIME
:
21512 return "NT_VMS_PATCHTIME";
21514 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21520 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
21522 unsigned int maxlen
= pnote
->descsz
;
21524 if (maxlen
< 2 || maxlen
!= pnote
->descsz
)
21525 goto desc_size_fail
;
21527 switch (pnote
->type
)
21531 goto desc_size_fail
;
21533 size_t l
= strnlen (pnote
->descdata
+ 34, maxlen
- 34);
21535 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
21536 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
21537 if (l
+ 34 < maxlen
)
21539 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
21540 if (l
+ 35 < maxlen
)
21541 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
21543 printf (_(" Module version : <missing>\n"));
21547 printf (_(" Module name : <missing>\n"));
21548 printf (_(" Module version : <missing>\n"));
21553 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
21556 case NT_VMS_FPMODE
:
21557 printf (_(" Floating Point mode: "));
21559 goto desc_size_fail
;
21560 /* FIXME: Generate an error if descsz > 8 ? */
21562 printf ("0x%016" PRIx64
"\n",
21563 byte_get ((unsigned char *) pnote
->descdata
, 8));
21566 case NT_VMS_LINKTIME
:
21567 printf (_(" Link time: "));
21569 goto desc_size_fail
;
21570 /* FIXME: Generate an error if descsz > 8 ? */
21572 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
21576 case NT_VMS_PATCHTIME
:
21577 printf (_(" Patch time: "));
21579 goto desc_size_fail
;
21580 /* FIXME: Generate an error if descsz > 8 ? */
21582 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
21586 case NT_VMS_ORIG_DYN
:
21588 goto desc_size_fail
;
21590 printf (_(" Major id: %u, minor id: %u\n"),
21591 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4),
21592 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
21593 printf (_(" Last modified : "));
21594 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
+ 8, 8));
21595 printf (_("\n Link flags : "));
21596 printf ("0x%016" PRIx64
"\n",
21597 byte_get ((unsigned char *) pnote
->descdata
+ 16, 8));
21598 printf (_(" Header flags: 0x%08x\n"),
21599 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 24, 4));
21600 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
21603 case NT_VMS_IMGNAM
:
21604 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
21607 case NT_VMS_GSTNAM
:
21608 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
21612 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
21615 case NT_VMS_LINKID
:
21616 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
21626 printf (_(" <corrupt - data size is too small>\n"));
21627 error (_("corrupt IA64 note: data size is too small\n"));
21631 struct build_attr_cache
{
21632 Filedata
*filedata
;
21634 uint64_t strtablen
;
21635 Elf_Internal_Sym
*symtab
;
21639 /* Find the symbol associated with a build attribute that is attached
21640 to address OFFSET. If PNAME is non-NULL then store the name of
21641 the symbol (if found) in the provided pointer, Returns NULL if a
21642 symbol could not be found. */
21644 static Elf_Internal_Sym
*
21645 get_symbol_for_build_attribute (Filedata
*filedata
,
21648 const char **pname
)
21650 Elf_Internal_Sym
*saved_sym
= NULL
;
21651 Elf_Internal_Sym
*sym
;
21653 if (filedata
->section_headers
!= NULL
21654 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
21656 Elf_Internal_Shdr
* symsec
;
21658 free (ba_cache
.strtab
);
21659 ba_cache
.strtab
= NULL
;
21660 free (ba_cache
.symtab
);
21661 ba_cache
.symtab
= NULL
;
21663 /* Load the symbol and string sections. */
21664 for (symsec
= filedata
->section_headers
;
21665 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
21668 if (symsec
->sh_type
== SHT_SYMTAB
21669 && get_symtab (filedata
, symsec
,
21670 &ba_cache
.symtab
, &ba_cache
.nsyms
,
21671 &ba_cache
.strtab
, &ba_cache
.strtablen
))
21674 ba_cache
.filedata
= filedata
;
21677 if (ba_cache
.symtab
== NULL
)
21680 /* Find a symbol whose value matches offset. */
21681 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
21682 if (sym
->st_value
== offset
)
21684 if (sym
->st_name
>= ba_cache
.strtablen
)
21685 /* Huh ? This should not happen. */
21688 if (ba_cache
.strtab
[sym
->st_name
] == 0)
21691 /* The AArch64, ARM and RISC-V architectures define mapping symbols
21692 (eg $d, $x, $t) which we want to ignore. */
21693 if (ba_cache
.strtab
[sym
->st_name
] == '$'
21694 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
21695 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
21700 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
21701 and FILE or OBJECT symbols over NOTYPE symbols. We skip
21702 FUNC symbols entirely. */
21703 switch (ELF_ST_TYPE (sym
->st_info
))
21710 /* If the symbol has a size associated
21711 with it then we can stop searching. */
21712 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
21717 /* Ignore function symbols. */
21724 switch (ELF_ST_BIND (sym
->st_info
))
21727 if (saved_sym
== NULL
21728 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
21733 if (saved_sym
== NULL
)
21743 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
21751 if (saved_sym
&& pname
)
21752 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
21757 /* Returns true iff addr1 and addr2 are in the same section. */
21760 same_section (Filedata
* filedata
, uint64_t addr1
, uint64_t addr2
)
21762 Elf_Internal_Shdr
* a1
;
21763 Elf_Internal_Shdr
* a2
;
21765 a1
= find_section_by_address (filedata
, addr1
);
21766 a2
= find_section_by_address (filedata
, addr2
);
21768 return a1
== a2
&& a1
!= NULL
;
21772 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
21773 Filedata
* filedata
)
21775 static uint64_t global_offset
= 0;
21776 static uint64_t global_end
= 0;
21777 static uint64_t func_offset
= 0;
21778 static uint64_t func_end
= 0;
21780 Elf_Internal_Sym
*sym
;
21784 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
21786 switch (pnote
->descsz
)
21789 /* A zero-length description means that the range of
21790 the previous note of the same type should be used. */
21793 if (global_end
> global_offset
)
21794 printf (_(" Applies to region from %#" PRIx64
21795 " to %#" PRIx64
"\n"), global_offset
, global_end
);
21797 printf (_(" Applies to region from %#" PRIx64
21798 "\n"), global_offset
);
21802 if (func_end
> func_offset
)
21803 printf (_(" Applies to region from %#" PRIx64
21804 " to %#" PRIx64
"\n"), func_offset
, func_end
);
21806 printf (_(" Applies to region from %#" PRIx64
21807 "\n"), func_offset
);
21812 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21817 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21818 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
21822 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
21823 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
21827 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
21828 printf (_(" <invalid descsz>"));
21833 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
21834 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
21835 in order to avoid them being confused with the start address of the
21836 first function in the file... */
21837 if (sym
== NULL
&& is_open_attr
)
21838 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
21841 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
21842 end
= start
+ sym
->st_size
;
21846 /* FIXME: Need to properly allow for section alignment.
21847 16 is just the alignment used on x86_64. */
21849 && start
> BFD_ALIGN (global_end
, 16)
21850 /* Build notes are not guaranteed to be organised in order of
21851 increasing address, but we should find the all of the notes
21852 for one section in the same place. */
21853 && same_section (filedata
, start
, global_end
))
21854 warn (_("Gap in build notes detected from %#" PRIx64
21855 " to %#" PRIx64
"\n"),
21856 global_end
+ 1, start
- 1);
21858 printf (_(" Applies to region from %#" PRIx64
), start
);
21859 global_offset
= start
;
21863 printf (_(" to %#" PRIx64
), end
);
21869 printf (_(" Applies to region from %#" PRIx64
), start
);
21870 func_offset
= start
;
21874 printf (_(" to %#" PRIx64
), end
);
21880 printf (_(" (%s)"), name
);
21887 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
21889 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
21890 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
21891 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
21893 char name_attribute
;
21894 const char * expected_types
;
21895 const char * name
= pnote
->namedata
;
21899 if (name
== NULL
|| pnote
->namesz
< 2)
21901 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21902 print_symbol_name (-20, _(" <corrupt name>"));
21911 /* Version 2 of the spec adds a "GA" prefix to the name field. */
21912 if (name
[0] == 'G' && name
[1] == 'A')
21914 if (pnote
->namesz
< 4)
21916 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21917 print_symbol_name (-20, _(" <corrupt name>"));
21926 switch ((name_type
= * name
))
21928 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21929 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21930 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21931 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21932 printf ("%c", * name
);
21936 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
21937 print_symbol_name (-20, _("<unknown name type>"));
21944 switch ((name_attribute
= * name
))
21946 case GNU_BUILD_ATTRIBUTE_VERSION
:
21947 text
= _("<version>");
21948 expected_types
= string_expected
;
21951 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21952 text
= _("<stack prot>");
21953 expected_types
= "!+*";
21956 case GNU_BUILD_ATTRIBUTE_RELRO
:
21957 text
= _("<relro>");
21958 expected_types
= bool_expected
;
21961 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
21962 text
= _("<stack size>");
21963 expected_types
= number_expected
;
21966 case GNU_BUILD_ATTRIBUTE_TOOL
:
21967 text
= _("<tool>");
21968 expected_types
= string_expected
;
21971 case GNU_BUILD_ATTRIBUTE_ABI
:
21973 expected_types
= "$*";
21976 case GNU_BUILD_ATTRIBUTE_PIC
:
21978 expected_types
= number_expected
;
21981 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
21982 text
= _("<short enum>");
21983 expected_types
= bool_expected
;
21987 if (ISPRINT (* name
))
21989 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
21991 if (len
> left
&& ! do_wide
)
21993 printf ("%.*s:", len
, name
);
21999 static char tmpbuf
[128];
22001 error (_("unrecognised byte in name field: %d\n"), * name
);
22002 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
22006 expected_types
= "*$!+";
22011 left
-= printf ("%s", text
);
22013 if (strchr (expected_types
, name_type
) == NULL
)
22014 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
22016 if ((size_t) (name
- pnote
->namedata
) > pnote
->namesz
)
22018 error (_("corrupt name field: namesz: %lu but parsing gets to %td\n"),
22020 name
- pnote
->namedata
);
22024 if (left
< 1 && ! do_wide
)
22029 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
22031 unsigned int bytes
;
22033 unsigned int shift
= 0;
22034 char *decoded
= NULL
;
22036 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
22038 /* The -1 is because the name field is always 0 terminated, and we
22039 want to be able to ensure that the shift in the while loop below
22040 will not overflow. */
22043 if (bytes
> sizeof (val
))
22045 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
22047 bytes
= sizeof (val
);
22049 /* We do not bother to warn if bytes == 0 as this can
22050 happen with some early versions of the gcc plugin. */
22054 uint64_t byte
= *name
++ & 0xff;
22056 val
|= byte
<< shift
;
22060 switch (name_attribute
)
22062 case GNU_BUILD_ATTRIBUTE_PIC
:
22065 case 0: decoded
= "static"; break;
22066 case 1: decoded
= "pic"; break;
22067 case 2: decoded
= "PIC"; break;
22068 case 3: decoded
= "pie"; break;
22069 case 4: decoded
= "PIE"; break;
22073 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
22076 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
22077 case 0: decoded
= "off"; break;
22078 case 1: decoded
= "on"; break;
22079 case 2: decoded
= "all"; break;
22080 case 3: decoded
= "strong"; break;
22081 case 4: decoded
= "explicit"; break;
22089 if (decoded
!= NULL
)
22091 print_symbol_name (-left
, decoded
);
22102 left
-= printf ("0x%" PRIx64
, val
);
22104 left
-= printf ("0x%-.*" PRIx64
, left
, val
);
22108 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
22109 left
-= print_symbol_name (- left
, name
);
22111 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
22112 left
-= print_symbol_name (- left
, "true");
22114 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
22115 left
-= print_symbol_name (- left
, "false");
22119 if (do_wide
&& left
> 0)
22120 printf ("%-*s", left
, " ");
22125 /* Print the contents of PNOTE as hex. */
22128 print_note_contents_hex (Elf_Internal_Note
*pnote
)
22134 printf (_(" description data: "));
22135 for (i
= 0; i
< pnote
->descsz
; i
++)
22136 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
22145 #if defined HAVE_MSGPACK
22148 print_indents (int n
)
22152 for (int i
= 0; i
< n
; i
++)
22156 /* Print OBJ in human-readable form. */
22159 dump_msgpack_obj (const msgpack_object
*obj
, int indent
)
22163 case MSGPACK_OBJECT_NIL
:
22167 case MSGPACK_OBJECT_BOOLEAN
:
22168 printf ("%s", obj
->via
.boolean
? "true" : "false");
22171 case MSGPACK_OBJECT_POSITIVE_INTEGER
:
22172 printf ("%" PRIu64
, obj
->via
.u64
);
22175 case MSGPACK_OBJECT_NEGATIVE_INTEGER
:
22176 printf ("%" PRIi64
, obj
->via
.i64
);
22179 case MSGPACK_OBJECT_FLOAT32
:
22180 case MSGPACK_OBJECT_FLOAT64
:
22181 printf ("%f", obj
->via
.f64
);
22184 case MSGPACK_OBJECT_STR
:
22185 printf ("\"%.*s\"", obj
->via
.str
.size
, obj
->via
.str
.ptr
);
22188 case MSGPACK_OBJECT_ARRAY
:
22190 const msgpack_object_array
*array
= &obj
->via
.array
;
22195 for (uint32_t i
= 0; i
< array
->size
; ++i
)
22197 const msgpack_object
*item
= &array
->ptr
[i
];
22199 print_indents (indent
);
22200 dump_msgpack_obj (item
, indent
);
22205 print_indents (indent
);
22211 case MSGPACK_OBJECT_MAP
:
22213 const msgpack_object_map
*map
= &obj
->via
.map
;
22218 for (uint32_t i
= 0; i
< map
->size
; ++i
)
22220 const msgpack_object_kv
*kv
= &map
->ptr
[i
];
22221 const msgpack_object
*key
= &kv
->key
;
22222 const msgpack_object
*val
= &kv
->val
;
22224 print_indents (indent
);
22225 dump_msgpack_obj (key
, indent
);
22227 dump_msgpack_obj (val
, indent
);
22233 print_indents (indent
);
22239 case MSGPACK_OBJECT_BIN
:
22243 case MSGPACK_OBJECT_EXT
:
22250 dump_msgpack (const msgpack_unpacked
*msg
)
22253 dump_msgpack_obj (&msg
->data
, 0);
22257 #endif /* defined HAVE_MSGPACK */
22260 print_amdgpu_note (Elf_Internal_Note
*pnote
)
22262 #if defined HAVE_MSGPACK
22263 /* If msgpack is available, decode and dump the note's content. */
22265 msgpack_unpacked msg
;
22266 msgpack_unpack_return msgpack_ret
;
22268 assert (pnote
->type
== NT_AMDGPU_METADATA
);
22270 msgpack_unpacked_init (&msg
);
22271 msgpack_ret
= msgpack_unpack_next (&msg
, pnote
->descdata
, pnote
->descsz
,
22274 switch (msgpack_ret
)
22276 case MSGPACK_UNPACK_SUCCESS
:
22277 dump_msgpack (&msg
);
22282 error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note"));
22287 msgpack_unpacked_destroy (&msg
);
22290 /* msgpack is not available, dump contents as hex. */
22291 print_note_contents_hex (pnote
);
22297 print_qnx_note (Elf_Internal_Note
*pnote
)
22299 switch (pnote
->type
)
22302 if (pnote
->descsz
!= 12)
22303 goto desc_size_fail
;
22305 printf (_(" Stack Size: 0x%" PRIx32
"\n"),
22306 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4));
22307 printf (_(" Stack allocated: %" PRIx32
"\n"),
22308 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
22309 printf (_(" Executable: %s\n"),
22310 ((unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 8, 1)) ? "no": "yes");
22314 print_note_contents_hex(pnote
);
22319 printf (_(" <corrupt - data size is too small>\n"));
22320 error (_("corrupt QNX note: data size is too small\n"));
22325 /* Note that by the ELF standard, the name field is already null byte
22326 terminated, and namesz includes the terminating null byte.
22327 I.E. the value of namesz for the name "FSF" is 4.
22329 If the value of namesz is zero, there is no name present. */
22332 process_note (Elf_Internal_Note
* pnote
,
22333 Filedata
* filedata
)
22335 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
22338 if (pnote
->namesz
== 0)
22339 /* If there is no note name, then use the default set of
22340 note type strings. */
22341 nt
= get_note_type (filedata
, pnote
->type
);
22343 else if (startswith (pnote
->namedata
, "GNU"))
22344 /* GNU-specific object file notes. */
22345 nt
= get_gnu_elf_note_type (pnote
->type
);
22347 else if (startswith (pnote
->namedata
, "AMDGPU"))
22348 /* AMDGPU-specific object file notes. */
22349 nt
= get_amdgpu_elf_note_type (pnote
->type
);
22351 else if (startswith (pnote
->namedata
, "FreeBSD"))
22352 /* FreeBSD-specific core file notes. */
22353 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
22355 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
22356 /* NetBSD-specific core file notes. */
22357 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
22359 else if (startswith (pnote
->namedata
, "NetBSD"))
22360 /* NetBSD-specific core file notes. */
22361 return process_netbsd_elf_note (pnote
);
22363 else if (startswith (pnote
->namedata
, "PaX"))
22364 /* NetBSD-specific core file notes. */
22365 return process_netbsd_elf_note (pnote
);
22367 else if (startswith (pnote
->namedata
, "OpenBSD"))
22368 /* OpenBSD-specific core file notes. */
22369 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
22371 else if (startswith (pnote
->namedata
, "QNX"))
22372 /* QNX-specific core file notes. */
22373 nt
= get_qnx_elfcore_note_type (filedata
, pnote
->type
);
22375 else if (startswith (pnote
->namedata
, "SPU/"))
22377 /* SPU-specific core file notes. */
22378 nt
= pnote
->namedata
+ 4;
22382 else if (startswith (pnote
->namedata
, "IPF/VMS"))
22383 /* VMS/ia64-specific file notes. */
22384 nt
= get_ia64_vms_note_type (pnote
->type
);
22386 else if (startswith (pnote
->namedata
, "stapsdt"))
22387 nt
= get_stapsdt_note_type (pnote
->type
);
22390 /* Don't recognize this note name; just use the default set of
22391 note type strings. */
22392 nt
= get_note_type (filedata
, pnote
->type
);
22396 if (((startswith (pnote
->namedata
, "GA")
22397 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
22398 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
22399 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
22400 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
22401 print_gnu_build_attribute_name (pnote
);
22403 print_symbol_name (-20, name
);
22406 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
22408 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
22410 if (startswith (pnote
->namedata
, "IPF/VMS"))
22411 return print_ia64_vms_note (pnote
);
22412 else if (startswith (pnote
->namedata
, "GNU"))
22413 return print_gnu_note (filedata
, pnote
);
22414 else if (startswith (pnote
->namedata
, "stapsdt"))
22415 return print_stapsdt_note (pnote
);
22416 else if (startswith (pnote
->namedata
, "CORE"))
22417 return print_core_note (pnote
);
22418 else if (startswith (pnote
->namedata
, "FDO"))
22419 return print_fdo_note (pnote
);
22420 else if (((startswith (pnote
->namedata
, "GA")
22421 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
22422 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
22423 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
22424 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
22425 return print_gnu_build_attribute_description (pnote
, filedata
);
22426 else if (startswith (pnote
->namedata
, "AMDGPU")
22427 && pnote
->type
== NT_AMDGPU_METADATA
)
22428 return print_amdgpu_note (pnote
);
22429 else if (startswith (pnote
->namedata
, "QNX"))
22430 return print_qnx_note (pnote
);
22432 print_note_contents_hex (pnote
);
22437 process_notes_at (Filedata
* filedata
,
22438 Elf_Internal_Shdr
* section
,
22443 Elf_External_Note
*pnotes
;
22444 Elf_External_Note
*external
;
22453 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
22456 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
22464 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
22467 if (pnotes
== NULL
)
22472 if (filedata
->is_separate
)
22473 printf (_("In linked file '%s': "), filedata
->file_name
);
22477 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
22479 printf (_("Displaying notes found at file offset 0x%08" PRIx64
22480 " with length 0x%08" PRIx64
":\n"),
22483 /* NB: Some note sections may have alignment value of 0 or 1. gABI
22484 specifies that notes should be aligned to 4 bytes in 32-bit
22485 objects and to 8 bytes in 64-bit objects. As a Linux extension,
22486 we also support 4 byte alignment in 64-bit objects. If section
22487 alignment is less than 4, we treate alignment as 4 bytes. */
22490 else if (align
!= 4 && align
!= 8)
22492 warn (_("Corrupt note: alignment %" PRId64
", expecting 4 or 8\n"),
22498 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
22500 end
= (char *) pnotes
+ length
;
22501 while ((char *) external
< end
)
22503 Elf_Internal_Note inote
;
22506 char * temp
= NULL
;
22507 size_t data_remaining
= end
- (char *) external
;
22509 if (!is_ia64_vms (filedata
))
22511 /* PR binutils/15191
22512 Make sure that there is enough data to read. */
22513 min_notesz
= offsetof (Elf_External_Note
, name
);
22514 if (data_remaining
< min_notesz
)
22516 warn (ngettext ("Corrupt note: only %zd byte remains, "
22517 "not enough for a full note\n",
22518 "Corrupt note: only %zd bytes remain, "
22519 "not enough for a full note\n",
22524 data_remaining
-= min_notesz
;
22526 inote
.type
= BYTE_GET (external
->type
);
22527 inote
.namesz
= BYTE_GET (external
->namesz
);
22528 inote
.namedata
= external
->name
;
22529 inote
.descsz
= BYTE_GET (external
->descsz
);
22530 inote
.descdata
= ((char *) external
22531 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
22532 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
22533 next
= ((char *) external
22534 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
22538 Elf64_External_VMS_Note
*vms_external
;
22540 /* PR binutils/15191
22541 Make sure that there is enough data to read. */
22542 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
22543 if (data_remaining
< min_notesz
)
22545 warn (ngettext ("Corrupt note: only %zd byte remains, "
22546 "not enough for a full note\n",
22547 "Corrupt note: only %zd bytes remain, "
22548 "not enough for a full note\n",
22553 data_remaining
-= min_notesz
;
22555 vms_external
= (Elf64_External_VMS_Note
*) external
;
22556 inote
.type
= BYTE_GET (vms_external
->type
);
22557 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
22558 inote
.namedata
= vms_external
->name
;
22559 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
22560 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
22561 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
22562 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
22565 /* PR 17531: file: 3443835e. */
22566 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
22567 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
22568 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
22569 || (size_t) (next
- inote
.descdata
) < inote
.descsz
22570 || ((size_t) (next
- inote
.descdata
)
22571 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
22573 warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"),
22574 (char *) external
- (char *) pnotes
);
22575 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"),
22576 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
22580 external
= (Elf_External_Note
*) next
;
22582 /* Verify that name is null terminated. It appears that at least
22583 one version of Linux (RedHat 6.0) generates corefiles that don't
22584 comply with the ELF spec by failing to include the null byte in
22586 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
22588 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
22590 temp
= (char *) malloc (inote
.namesz
+ 1);
22593 error (_("Out of memory allocating space for inote name\n"));
22598 memcpy (temp
, inote
.namedata
, inote
.namesz
);
22599 inote
.namedata
= temp
;
22601 inote
.namedata
[inote
.namesz
] = 0;
22604 if (! process_note (& inote
, filedata
))
22617 process_corefile_note_segments (Filedata
* filedata
)
22619 Elf_Internal_Phdr
*segment
;
22623 if (! get_program_headers (filedata
))
22626 for (i
= 0, segment
= filedata
->program_headers
;
22627 i
< filedata
->file_header
.e_phnum
;
22630 if (segment
->p_type
== PT_NOTE
)
22631 if (! process_notes_at (filedata
, NULL
, segment
->p_offset
,
22632 segment
->p_filesz
, segment
->p_align
))
22640 process_v850_notes (Filedata
* filedata
, uint64_t offset
, uint64_t length
)
22642 Elf_External_Note
* pnotes
;
22643 Elf_External_Note
* external
;
22650 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
22652 if (pnotes
== NULL
)
22656 end
= (char*) pnotes
+ length
;
22658 printf (_("\nDisplaying contents of Renesas V850 notes section at offset"
22659 " %#" PRIx64
" with length %#" PRIx64
":\n"),
22662 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
22664 Elf_External_Note
* next
;
22665 Elf_Internal_Note inote
;
22667 inote
.type
= BYTE_GET (external
->type
);
22668 inote
.namesz
= BYTE_GET (external
->namesz
);
22669 inote
.namedata
= external
->name
;
22670 inote
.descsz
= BYTE_GET (external
->descsz
);
22671 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
22672 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
22674 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
22676 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
22677 inote
.descdata
= inote
.namedata
;
22681 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
22683 if ( ((char *) next
> end
)
22684 || ((char *) next
< (char *) pnotes
))
22686 warn (_("corrupt descsz found in note at offset %#tx\n"),
22687 (char *) external
- (char *) pnotes
);
22688 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"),
22689 inote
.type
, inote
.namesz
, inote
.descsz
);
22695 /* Prevent out-of-bounds indexing. */
22696 if ( inote
.namedata
+ inote
.namesz
> end
22697 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
22699 warn (_("corrupt namesz found in note at offset %#zx\n"),
22700 (char *) external
- (char *) pnotes
);
22701 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"),
22702 inote
.type
, inote
.namesz
, inote
.descsz
);
22706 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
22708 if (! print_v850_note (& inote
))
22711 printf ("<corrupt sizes: namesz: %#lx, descsz: %#lx>\n",
22712 inote
.namesz
, inote
.descsz
);
22722 process_note_sections (Filedata
* filedata
)
22724 Elf_Internal_Shdr
*section
;
22726 unsigned int n
= 0;
22729 for (i
= 0, section
= filedata
->section_headers
;
22730 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
22733 if (section
->sh_type
== SHT_NOTE
)
22735 if (! process_notes_at (filedata
, section
, section
->sh_offset
,
22736 section
->sh_size
, section
->sh_addralign
))
22741 if (( filedata
->file_header
.e_machine
== EM_V800
22742 || filedata
->file_header
.e_machine
== EM_V850
22743 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
22744 && section
->sh_type
== SHT_RENESAS_INFO
)
22746 if (! process_v850_notes (filedata
, section
->sh_offset
,
22754 /* Try processing NOTE segments instead. */
22755 return process_corefile_note_segments (filedata
);
22761 process_notes (Filedata
* filedata
)
22763 /* If we have not been asked to display the notes then do nothing. */
22767 if (filedata
->file_header
.e_type
!= ET_CORE
)
22768 return process_note_sections (filedata
);
22770 /* No program headers means no NOTE segment. */
22771 if (filedata
->file_header
.e_phnum
> 0)
22772 return process_corefile_note_segments (filedata
);
22774 if (filedata
->is_separate
)
22775 printf (_("No notes found in linked file '%s'.\n"),
22776 filedata
->file_name
);
22778 printf (_("No notes found file.\n"));
22783 static unsigned char *
22784 display_public_gnu_attributes (unsigned char * start
,
22785 const unsigned char * const end
)
22787 printf (_(" Unknown GNU attribute: %s\n"), start
);
22789 start
+= strnlen ((char *) start
, end
- start
);
22790 display_raw_attribute (start
, end
);
22792 return (unsigned char *) end
;
22795 static unsigned char *
22796 display_generic_attribute (unsigned char * start
,
22798 const unsigned char * const end
)
22801 return (unsigned char *) end
;
22803 return display_tag_value (tag
, start
, end
);
22807 process_arch_specific (Filedata
* filedata
)
22812 switch (filedata
->file_header
.e_machine
)
22815 case EM_ARC_COMPACT
:
22816 case EM_ARC_COMPACT2
:
22817 case EM_ARC_COMPACT3
:
22818 case EM_ARC_COMPACT3_64
:
22819 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
22820 display_arc_attribute
,
22821 display_generic_attribute
);
22823 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
22824 display_arm_attribute
,
22825 display_generic_attribute
);
22828 case EM_MIPS_RS3_LE
:
22829 return process_mips_specific (filedata
);
22832 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
22833 display_msp430_attribute
,
22834 display_msp430_gnu_attribute
);
22837 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
22838 display_riscv_attribute
,
22839 display_generic_attribute
);
22842 return process_nds32_specific (filedata
);
22845 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22846 display_m68k_gnu_attribute
);
22850 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22851 display_power_gnu_attribute
);
22855 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22856 display_s390_gnu_attribute
);
22859 case EM_SPARC32PLUS
:
22861 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22862 display_sparc_gnu_attribute
);
22865 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
22866 display_tic6x_attribute
,
22867 display_generic_attribute
);
22870 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
22871 display_csky_attribute
, NULL
);
22874 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
22875 display_public_gnu_attributes
,
22876 display_generic_attribute
);
22881 get_file_header (Filedata
* filedata
)
22883 /* Read in the identity array. */
22884 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
22887 /* Determine how to read the rest of the header. */
22888 switch (filedata
->file_header
.e_ident
[EI_DATA
])
22893 byte_get
= byte_get_little_endian
;
22894 byte_put
= byte_put_little_endian
;
22897 byte_get
= byte_get_big_endian
;
22898 byte_put
= byte_put_big_endian
;
22902 /* For now we only support 32 bit and 64 bit ELF files. */
22903 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
22905 /* Read in the rest of the header. */
22908 Elf32_External_Ehdr ehdr32
;
22910 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22913 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
22914 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
22915 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
22916 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
22917 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
22918 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
22919 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
22920 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
22921 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
22922 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
22923 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
22924 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
22925 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
22929 Elf64_External_Ehdr ehdr64
;
22931 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22934 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
22935 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
22936 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
22937 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
22938 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
22939 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
22940 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
22941 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
22942 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
22943 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
22944 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
22945 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
22946 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
22953 free_filedata (Filedata
*filedata
)
22955 free (filedata
->program_interpreter
);
22956 free (filedata
->program_headers
);
22957 free (filedata
->section_headers
);
22958 free (filedata
->string_table
);
22959 free (filedata
->dump
.dump_sects
);
22960 free (filedata
->dynamic_strings
);
22961 free (filedata
->dynamic_symbols
);
22962 free (filedata
->dynamic_syminfo
);
22963 free (filedata
->dynamic_section
);
22965 while (filedata
->symtab_shndx_list
!= NULL
)
22967 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
22968 free (filedata
->symtab_shndx_list
);
22969 filedata
->symtab_shndx_list
= next
;
22972 free (filedata
->section_headers_groups
);
22974 if (filedata
->section_groups
)
22977 struct group_list
* g
;
22978 struct group_list
* next
;
22980 for (i
= 0; i
< filedata
->group_count
; i
++)
22982 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
22989 free (filedata
->section_groups
);
22991 memset (&filedata
->section_headers
, 0,
22992 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
22996 close_file (Filedata
* filedata
)
23000 if (filedata
->handle
)
23001 fclose (filedata
->handle
);
23007 close_debug_file (void * data
)
23009 free_filedata ((Filedata
*) data
);
23010 close_file ((Filedata
*) data
);
23014 open_file (const char * pathname
, bool is_separate
)
23016 struct stat statbuf
;
23017 Filedata
* filedata
= NULL
;
23019 if (stat (pathname
, & statbuf
) < 0
23020 || ! S_ISREG (statbuf
.st_mode
))
23023 filedata
= calloc (1, sizeof * filedata
);
23024 if (filedata
== NULL
)
23027 filedata
->handle
= fopen (pathname
, "rb");
23028 if (filedata
->handle
== NULL
)
23031 filedata
->file_size
= statbuf
.st_size
;
23032 filedata
->file_name
= pathname
;
23033 filedata
->is_separate
= is_separate
;
23035 if (! get_file_header (filedata
))
23038 if (!get_section_headers (filedata
, false))
23046 if (filedata
->handle
)
23047 fclose (filedata
->handle
);
23054 open_debug_file (const char * pathname
)
23056 return open_file (pathname
, true);
23060 initialise_dump_sects (Filedata
* filedata
)
23062 /* Initialise the dump_sects array from the cmdline_dump_sects array.
23063 Note we do this even if cmdline_dump_sects is empty because we
23064 must make sure that the dump_sets array is zeroed out before each
23065 object file is processed. */
23066 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
23067 memset (filedata
->dump
.dump_sects
, 0,
23068 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
23070 if (cmdline
.num_dump_sects
> 0)
23072 if (filedata
->dump
.num_dump_sects
== 0)
23073 /* A sneaky way of allocating the dump_sects array. */
23074 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
23076 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
23077 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
23078 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
23083 might_need_separate_debug_info (Filedata
* filedata
)
23085 /* Debuginfo files do not need further separate file loading. */
23086 if (filedata
->file_header
.e_shstrndx
== SHN_UNDEF
)
23089 /* Since do_follow_links might be enabled by default, only treat it as an
23090 indication that separate files should be loaded if setting it was a
23091 deliberate user action. */
23092 if (DEFAULT_FOR_FOLLOW_LINKS
== 0 && do_follow_links
)
23095 if (process_links
|| do_syms
|| do_unwind
23096 || dump_any_debugging
|| do_dump
|| do_debugging
)
23102 /* Process one ELF object file according to the command line options.
23103 This file may actually be stored in an archive. The file is
23104 positioned at the start of the ELF object. Returns TRUE if no
23105 problems were encountered, FALSE otherwise. */
23108 process_object (Filedata
* filedata
)
23110 bool have_separate_files
;
23114 if (! get_file_header (filedata
))
23116 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
23120 /* Initialise per file variables. */
23121 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
23122 filedata
->version_info
[i
] = 0;
23124 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
23125 filedata
->dynamic_info
[i
] = 0;
23126 filedata
->dynamic_info_DT_GNU_HASH
= 0;
23127 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
23129 /* Process the file. */
23131 printf (_("\nFile: %s\n"), filedata
->file_name
);
23133 initialise_dump_sects (filedata
);
23135 /* There may be some extensions in the first section header. Don't
23136 bomb if we can't read it. */
23137 get_section_headers (filedata
, true);
23139 if (! process_file_header (filedata
))
23145 /* Throw away the single section header read above, so that we
23146 re-read the entire set. */
23147 free (filedata
->section_headers
);
23148 filedata
->section_headers
= NULL
;
23150 if (! process_section_headers (filedata
))
23152 /* Without loaded section headers we cannot process lots of things. */
23153 do_unwind
= do_version
= do_dump
= do_arch
= false;
23155 if (! do_using_dynamic
)
23156 do_syms
= do_dyn_syms
= do_reloc
= false;
23159 if (! process_section_groups (filedata
))
23160 /* Without loaded section groups we cannot process unwind. */
23163 process_program_headers (filedata
);
23165 res
= process_dynamic_section (filedata
);
23167 if (! process_relocs (filedata
))
23170 if (! process_unwind (filedata
))
23173 if (! process_symbol_table (filedata
))
23176 if (! process_lto_symbol_tables (filedata
))
23179 if (! process_syminfo (filedata
))
23182 if (! process_version_sections (filedata
))
23185 if (might_need_separate_debug_info (filedata
))
23186 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
23188 have_separate_files
= false;
23190 if (! process_section_contents (filedata
))
23193 if (have_separate_files
)
23197 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
23199 initialise_dump_sects (d
->handle
);
23201 if (process_links
&& ! process_file_header (d
->handle
))
23203 else if (! process_section_headers (d
->handle
))
23205 else if (! process_section_contents (d
->handle
))
23207 else if (process_links
)
23209 if (! process_section_groups (d
->handle
))
23211 process_program_headers (d
->handle
);
23212 if (! process_dynamic_section (d
->handle
))
23214 if (! process_relocs (d
->handle
))
23216 if (! process_unwind (d
->handle
))
23218 if (! process_symbol_table (d
->handle
))
23220 if (! process_lto_symbol_tables (d
->handle
))
23222 if (! process_syminfo (d
->handle
))
23224 if (! process_version_sections (d
->handle
))
23226 if (! process_notes (d
->handle
))
23231 /* The file handles are closed by the call to free_debug_memory() below. */
23234 if (! process_notes (filedata
))
23237 if (! process_gnu_liblist (filedata
))
23240 if (! process_arch_specific (filedata
))
23244 free_filedata (filedata
);
23246 free_debug_memory ();
23251 /* Process an ELF archive.
23252 On entry the file is positioned just after the ARMAG string.
23253 Returns TRUE upon success, FALSE otherwise. */
23256 process_archive (Filedata
* filedata
, bool is_thin_archive
)
23258 struct archive_info arch
;
23259 struct archive_info nested_arch
;
23265 /* The ARCH structure is used to hold information about this archive. */
23266 arch
.file_name
= NULL
;
23268 arch
.index_array
= NULL
;
23269 arch
.sym_table
= NULL
;
23270 arch
.longnames
= NULL
;
23272 /* The NESTED_ARCH structure is used as a single-item cache of information
23273 about a nested archive (when members of a thin archive reside within
23274 another regular archive file). */
23275 nested_arch
.file_name
= NULL
;
23276 nested_arch
.file
= NULL
;
23277 nested_arch
.index_array
= NULL
;
23278 nested_arch
.sym_table
= NULL
;
23279 nested_arch
.longnames
= NULL
;
23281 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
23282 filedata
->file_size
, is_thin_archive
,
23283 do_archive_index
) != 0)
23289 if (do_archive_index
)
23291 if (arch
.sym_table
== NULL
)
23292 error (_("%s: unable to dump the index as none was found\n"),
23293 filedata
->file_name
);
23297 uint64_t current_pos
;
23299 printf (_("Index of archive %s: (%" PRIu64
" entries,"
23300 " %#" PRIx64
" bytes in the symbol table)\n"),
23301 filedata
->file_name
, arch
.index_num
,
23304 current_pos
= ftell (filedata
->handle
);
23306 for (i
= l
= 0; i
< arch
.index_num
; i
++)
23309 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
23312 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
23315 if (member_name
!= NULL
)
23317 char * qualified_name
23318 = make_qualified_name (&arch
, &nested_arch
,
23321 if (qualified_name
!= NULL
)
23323 printf (_("Contents of binary %s at offset "),
23325 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
23327 free (qualified_name
);
23329 free (member_name
);
23333 if (l
>= arch
.sym_size
)
23335 error (_("%s: end of the symbol table reached "
23336 "before the end of the index\n"),
23337 filedata
->file_name
);
23341 /* PR 17531: file: 0b6630b2. */
23342 printf ("\t%.*s\n",
23343 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
23344 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
23347 if (arch
.uses_64bit_indices
)
23352 if (l
< arch
.sym_size
)
23354 error (ngettext ("%s: %" PRId64
" byte remains in the symbol table, "
23355 "but without corresponding entries in "
23356 "the index table\n",
23357 "%s: %" PRId64
" bytes remain in the symbol table, "
23358 "but without corresponding entries in "
23359 "the index table\n",
23360 arch
.sym_size
- l
),
23361 filedata
->file_name
, arch
.sym_size
- l
);
23365 if (fseek64 (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
23367 error (_("%s: failed to seek back to start of object files "
23368 "in the archive\n"),
23369 filedata
->file_name
);
23375 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
23376 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
23377 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
23378 && !do_section_groups
&& !do_dyn_syms
)
23380 ret
= true; /* Archive index only. */
23389 char * qualified_name
;
23391 /* Read the next archive header. */
23392 if (fseek64 (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
23394 error (_("%s: failed to seek to next archive header\n"),
23399 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
23400 if (got
!= sizeof arch
.arhdr
)
23404 /* PR 24049 - we cannot use filedata->file_name as this will
23405 have already been freed. */
23406 error (_("%s: failed to read archive header\n"), arch
.file_name
);
23411 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
23413 error (_("%s: did not find a valid archive header\n"),
23419 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
23421 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
23423 name
= get_archive_member_name (&arch
, &nested_arch
);
23426 error (_("%s: bad archive file name\n"), arch
.file_name
);
23430 namelen
= strlen (name
);
23432 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
23433 if (qualified_name
== NULL
)
23435 error (_("%s: bad archive file name\n"), arch
.file_name
);
23441 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
23443 /* This is a proxy for an external member of a thin archive. */
23444 Filedata
* member_filedata
;
23445 char * member_file_name
= adjust_relative_path
23446 (filedata
->file_name
, name
, namelen
);
23449 if (member_file_name
== NULL
)
23451 free (qualified_name
);
23456 member_filedata
= open_file (member_file_name
, false);
23457 if (member_filedata
== NULL
)
23459 error (_("Input file '%s' is not readable.\n"), member_file_name
);
23460 free (member_file_name
);
23461 free (qualified_name
);
23466 filedata
->archive_file_offset
= arch
.nested_member_origin
;
23467 member_filedata
->file_name
= qualified_name
;
23469 /* The call to process_object() expects the file to be at the beginning. */
23470 rewind (member_filedata
->handle
);
23472 if (! process_object (member_filedata
))
23475 close_file (member_filedata
);
23476 free (member_file_name
);
23478 else if (is_thin_archive
)
23480 Filedata thin_filedata
;
23482 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
23484 /* PR 15140: Allow for corrupt thin archives. */
23485 if (nested_arch
.file
== NULL
)
23487 error (_("%s: contains corrupt thin archive: %s\n"),
23488 qualified_name
, name
);
23489 free (qualified_name
);
23496 /* This is a proxy for a member of a nested archive. */
23497 filedata
->archive_file_offset
23498 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
23500 /* The nested archive file will have been opened and setup by
23501 get_archive_member_name. */
23502 if (fseek64 (nested_arch
.file
, filedata
->archive_file_offset
,
23505 error (_("%s: failed to seek to archive member.\n"),
23506 nested_arch
.file_name
);
23507 free (qualified_name
);
23512 thin_filedata
.handle
= nested_arch
.file
;
23513 thin_filedata
.file_name
= qualified_name
;
23515 if (! process_object (& thin_filedata
))
23521 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
23522 filedata
->file_name
= qualified_name
;
23523 if (! process_object (filedata
))
23525 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
23526 /* Stop looping with "negative" archive_file_size. */
23527 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
23528 arch
.next_arhdr_offset
= -1ul;
23531 free (qualified_name
);
23535 if (nested_arch
.file
!= NULL
)
23536 fclose (nested_arch
.file
);
23537 release_archive (&nested_arch
);
23538 release_archive (&arch
);
23544 process_file (char * file_name
)
23546 Filedata
* filedata
= NULL
;
23547 struct stat statbuf
;
23548 char armag
[SARMAG
];
23551 if (stat (file_name
, &statbuf
) < 0)
23553 if (errno
== ENOENT
)
23554 error (_("'%s': No such file\n"), file_name
);
23556 error (_("Could not locate '%s'. System error message: %s\n"),
23557 file_name
, strerror (errno
));
23561 if (! S_ISREG (statbuf
.st_mode
))
23563 error (_("'%s' is not an ordinary file\n"), file_name
);
23567 filedata
= calloc (1, sizeof * filedata
);
23568 if (filedata
== NULL
)
23570 error (_("Out of memory allocating file data structure\n"));
23574 filedata
->file_name
= file_name
;
23575 filedata
->handle
= fopen (file_name
, "rb");
23576 if (filedata
->handle
== NULL
)
23578 error (_("Input file '%s' is not readable.\n"), file_name
);
23583 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
23585 error (_("%s: Failed to read file's magic number\n"), file_name
);
23586 fclose (filedata
->handle
);
23591 filedata
->file_size
= statbuf
.st_size
;
23592 filedata
->is_separate
= false;
23594 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
23596 if (! process_archive (filedata
, false))
23599 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
23601 if ( ! process_archive (filedata
, true))
23606 if (do_archive_index
&& !check_all
)
23607 error (_("File %s is not an archive so its index cannot be displayed.\n"),
23610 rewind (filedata
->handle
);
23611 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
23613 if (! process_object (filedata
))
23617 fclose (filedata
->handle
);
23618 free (filedata
->section_headers
);
23619 free (filedata
->program_headers
);
23620 free (filedata
->string_table
);
23621 free (filedata
->dump
.dump_sects
);
23624 free (ba_cache
.strtab
);
23625 ba_cache
.strtab
= NULL
;
23626 free (ba_cache
.symtab
);
23627 ba_cache
.symtab
= NULL
;
23628 ba_cache
.filedata
= NULL
;
23633 #ifdef SUPPORT_DISASSEMBLY
23634 /* Needed by the i386 disassembler. For extra credit, someone could
23635 fix this so that we insert symbolic addresses here, esp for GOT/PLT
23639 print_address (unsigned int addr
, FILE * outfile
)
23641 fprintf (outfile
,"0x%8.8x", addr
);
23644 /* Needed by the i386 disassembler. */
23647 db_task_printsym (unsigned int addr
)
23649 print_address (addr
, stderr
);
23654 main (int argc
, char ** argv
)
23658 #ifdef HAVE_LC_MESSAGES
23659 setlocale (LC_MESSAGES
, "");
23661 setlocale (LC_CTYPE
, "");
23662 bindtextdomain (PACKAGE
, LOCALEDIR
);
23663 textdomain (PACKAGE
);
23665 expandargv (&argc
, &argv
);
23667 parse_args (& cmdline
, argc
, argv
);
23669 if (optind
< (argc
- 1))
23670 /* When displaying information for more than one file,
23671 prefix the information with the file name. */
23673 else if (optind
>= argc
)
23675 /* Ensure that the warning is always displayed. */
23678 warn (_("Nothing to do.\n"));
23683 while (optind
< argc
)
23684 if (! process_file (argv
[optind
++]))
23687 free (cmdline
.dump_sects
);
23689 free (dump_ctf_symtab_name
);
23690 free (dump_ctf_strtab_name
);
23691 free (dump_ctf_parent_name
);
23693 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;